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 redisplay_other_windows ();
628 fset_redisplay (struct frame
*f
)
630 redisplay_other_windows ();
635 bset_redisplay (struct buffer
*b
)
637 int count
= buffer_window_count (b
);
640 /* ... it's visible in other window than selected, */
641 if (count
> 1 || b
!= XBUFFER (XWINDOW (selected_window
)->contents
))
642 redisplay_other_windows ();
643 /* Even if we don't set windows_or_buffers_changed, do set `redisplay'
644 so that if we later set windows_or_buffers_changed, this buffer will
646 b
->text
->redisplay
= true;
651 bset_update_mode_line (struct buffer
*b
)
653 if (!update_mode_lines
)
654 update_mode_lines
= REDISPLAY_SOME
;
655 b
->text
->redisplay
= true;
660 /* Non-zero means print traces of redisplay if compiled with
661 GLYPH_DEBUG defined. */
663 int trace_redisplay_p
;
665 #endif /* GLYPH_DEBUG */
667 #ifdef DEBUG_TRACE_MOVE
668 /* Non-zero means trace with TRACE_MOVE to stderr. */
671 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
673 #define TRACE_MOVE(x) (void) 0
676 static Lisp_Object Qauto_hscroll_mode
;
678 /* Buffer being redisplayed -- for redisplay_window_error. */
680 static struct buffer
*displayed_buffer
;
682 /* Value returned from text property handlers (see below). */
687 HANDLED_RECOMPUTE_PROPS
,
688 HANDLED_OVERLAY_STRING_CONSUMED
,
692 /* A description of text properties that redisplay is interested
697 /* The name of the property. */
700 /* A unique index for the property. */
703 /* A handler function called to set up iterator IT from the property
704 at IT's current position. Value is used to steer handle_stop. */
705 enum prop_handled (*handler
) (struct it
*it
);
708 static enum prop_handled
handle_face_prop (struct it
*);
709 static enum prop_handled
handle_invisible_prop (struct it
*);
710 static enum prop_handled
handle_display_prop (struct it
*);
711 static enum prop_handled
handle_composition_prop (struct it
*);
712 static enum prop_handled
handle_overlay_change (struct it
*);
713 static enum prop_handled
handle_fontified_prop (struct it
*);
715 /* Properties handled by iterators. */
717 static struct props it_props
[] =
719 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
720 /* Handle `face' before `display' because some sub-properties of
721 `display' need to know the face. */
722 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
723 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
724 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
725 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
729 /* Value is the position described by X. If X is a marker, value is
730 the marker_position of X. Otherwise, value is X. */
732 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
734 /* Enumeration returned by some move_it_.* functions internally. */
738 /* Not used. Undefined value. */
741 /* Move ended at the requested buffer position or ZV. */
742 MOVE_POS_MATCH_OR_ZV
,
744 /* Move ended at the requested X pixel position. */
747 /* Move within a line ended at the end of a line that must be
751 /* Move within a line ended at the end of a line that would
752 be displayed truncated. */
755 /* Move within a line ended at a line end. */
759 /* This counter is used to clear the face cache every once in a while
760 in redisplay_internal. It is incremented for each redisplay.
761 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
764 #define CLEAR_FACE_CACHE_COUNT 500
765 static int clear_face_cache_count
;
767 /* Similarly for the image cache. */
769 #ifdef HAVE_WINDOW_SYSTEM
770 #define CLEAR_IMAGE_CACHE_COUNT 101
771 static int clear_image_cache_count
;
773 /* Null glyph slice */
774 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
777 /* True while redisplay_internal is in progress. */
781 static Lisp_Object Qinhibit_free_realized_faces
;
782 static Lisp_Object Qmode_line_default_help_echo
;
784 /* If a string, XTread_socket generates an event to display that string.
785 (The display is done in read_char.) */
787 Lisp_Object help_echo_string
;
788 Lisp_Object help_echo_window
;
789 Lisp_Object help_echo_object
;
790 ptrdiff_t help_echo_pos
;
792 /* Temporary variable for XTread_socket. */
794 Lisp_Object previous_help_echo_string
;
796 /* Platform-independent portion of hourglass implementation. */
798 #ifdef HAVE_WINDOW_SYSTEM
800 /* Non-zero means an hourglass cursor is currently shown. */
801 bool hourglass_shown_p
;
803 /* If non-null, an asynchronous timer that, when it expires, displays
804 an hourglass cursor on all frames. */
805 struct atimer
*hourglass_atimer
;
807 #endif /* HAVE_WINDOW_SYSTEM */
809 /* Name of the face used to display glyphless characters. */
810 static Lisp_Object Qglyphless_char
;
812 /* Symbol for the purpose of Vglyphless_char_display. */
813 static Lisp_Object Qglyphless_char_display
;
815 /* Method symbols for Vglyphless_char_display. */
816 static Lisp_Object Qhex_code
, Qempty_box
, Qthin_space
, Qzero_width
;
818 /* Default number of seconds to wait before displaying an hourglass
820 #define DEFAULT_HOURGLASS_DELAY 1
822 #ifdef HAVE_WINDOW_SYSTEM
824 /* Default pixel width of `thin-space' display method. */
825 #define THIN_SPACE_WIDTH 1
827 #endif /* HAVE_WINDOW_SYSTEM */
829 /* Function prototypes. */
831 static void setup_for_ellipsis (struct it
*, int);
832 static void set_iterator_to_next (struct it
*, int);
833 static void mark_window_display_accurate_1 (struct window
*, int);
834 static int single_display_spec_string_p (Lisp_Object
, Lisp_Object
);
835 static int display_prop_string_p (Lisp_Object
, Lisp_Object
);
836 static int row_for_charpos_p (struct glyph_row
*, ptrdiff_t);
837 static int cursor_row_p (struct glyph_row
*);
838 static int redisplay_mode_lines (Lisp_Object
, bool);
839 static char *decode_mode_spec_coding (Lisp_Object
, char *, int);
841 static Lisp_Object
get_it_property (struct it
*it
, Lisp_Object prop
);
843 static void handle_line_prefix (struct it
*);
845 static void pint2str (char *, int, ptrdiff_t);
846 static void pint2hrstr (char *, int, ptrdiff_t);
847 static struct text_pos
run_window_scroll_functions (Lisp_Object
,
849 static int text_outside_line_unchanged_p (struct window
*,
850 ptrdiff_t, ptrdiff_t);
851 static void store_mode_line_noprop_char (char);
852 static int store_mode_line_noprop (const char *, int, int);
853 static void handle_stop (struct it
*);
854 static void handle_stop_backwards (struct it
*, ptrdiff_t);
855 static void vmessage (const char *, va_list) ATTRIBUTE_FORMAT_PRINTF (1, 0);
856 static void ensure_echo_area_buffers (void);
857 static void unwind_with_echo_area_buffer (Lisp_Object
);
858 static Lisp_Object
with_echo_area_buffer_unwind_data (struct window
*);
859 static int with_echo_area_buffer (struct window
*, int,
860 int (*) (ptrdiff_t, Lisp_Object
),
861 ptrdiff_t, Lisp_Object
);
862 static void clear_garbaged_frames (void);
863 static int current_message_1 (ptrdiff_t, Lisp_Object
);
864 static int truncate_message_1 (ptrdiff_t, Lisp_Object
);
865 static void set_message (Lisp_Object
);
866 static int set_message_1 (ptrdiff_t, Lisp_Object
);
867 static int display_echo_area (struct window
*);
868 static int display_echo_area_1 (ptrdiff_t, Lisp_Object
);
869 static int resize_mini_window_1 (ptrdiff_t, Lisp_Object
);
870 static void unwind_redisplay (void);
871 static int string_char_and_length (const unsigned char *, int *);
872 static struct text_pos
display_prop_end (struct it
*, Lisp_Object
,
874 static int compute_window_start_on_continuation_line (struct window
*);
875 static void insert_left_trunc_glyphs (struct it
*);
876 static struct glyph_row
*get_overlay_arrow_glyph_row (struct window
*,
878 static void extend_face_to_end_of_line (struct it
*);
879 static int append_space_for_newline (struct it
*, int);
880 static int cursor_row_fully_visible_p (struct window
*, int, int);
881 static int try_scrolling (Lisp_Object
, int, ptrdiff_t, ptrdiff_t, int, int);
882 static int try_cursor_movement (Lisp_Object
, struct text_pos
, int *);
883 static int trailing_whitespace_p (ptrdiff_t);
884 static intmax_t message_log_check_duplicate (ptrdiff_t, ptrdiff_t);
885 static void push_it (struct it
*, struct text_pos
*);
886 static void iterate_out_of_display_property (struct it
*);
887 static void pop_it (struct it
*);
888 static void sync_frame_with_window_matrix_rows (struct window
*);
889 static void redisplay_internal (void);
890 static int echo_area_display (int);
891 static void redisplay_windows (Lisp_Object
);
892 static void redisplay_window (Lisp_Object
, bool);
893 static Lisp_Object
redisplay_window_error (Lisp_Object
);
894 static Lisp_Object
redisplay_window_0 (Lisp_Object
);
895 static Lisp_Object
redisplay_window_1 (Lisp_Object
);
896 static int set_cursor_from_row (struct window
*, struct glyph_row
*,
897 struct glyph_matrix
*, ptrdiff_t, ptrdiff_t,
899 static int update_menu_bar (struct frame
*, int, int);
900 static int try_window_reusing_current_matrix (struct window
*);
901 static int try_window_id (struct window
*);
902 static int display_line (struct it
*);
903 static int display_mode_lines (struct window
*);
904 static int display_mode_line (struct window
*, enum face_id
, Lisp_Object
);
905 static int display_mode_element (struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int);
906 static int store_mode_line_string (const char *, Lisp_Object
, int, int, int, Lisp_Object
);
907 static const char *decode_mode_spec (struct window
*, int, int, Lisp_Object
*);
908 static void display_menu_bar (struct window
*);
909 static ptrdiff_t display_count_lines (ptrdiff_t, ptrdiff_t, ptrdiff_t,
911 static int display_string (const char *, Lisp_Object
, Lisp_Object
,
912 ptrdiff_t, ptrdiff_t, struct it
*, int, int, int, int);
913 static void compute_line_metrics (struct it
*);
914 static void run_redisplay_end_trigger_hook (struct it
*);
915 static int get_overlay_strings (struct it
*, ptrdiff_t);
916 static int get_overlay_strings_1 (struct it
*, ptrdiff_t, int);
917 static void next_overlay_string (struct it
*);
918 static void reseat (struct it
*, struct text_pos
, int);
919 static void reseat_1 (struct it
*, struct text_pos
, int);
920 static void back_to_previous_visible_line_start (struct it
*);
921 static void reseat_at_next_visible_line_start (struct it
*, int);
922 static int next_element_from_ellipsis (struct it
*);
923 static int next_element_from_display_vector (struct it
*);
924 static int next_element_from_string (struct it
*);
925 static int next_element_from_c_string (struct it
*);
926 static int next_element_from_buffer (struct it
*);
927 static int next_element_from_composition (struct it
*);
928 static int next_element_from_image (struct it
*);
929 static int next_element_from_stretch (struct it
*);
930 static void load_overlay_strings (struct it
*, ptrdiff_t);
931 static int init_from_display_pos (struct it
*, struct window
*,
932 struct display_pos
*);
933 static void reseat_to_string (struct it
*, const char *,
934 Lisp_Object
, ptrdiff_t, ptrdiff_t, int, int);
935 static int get_next_display_element (struct it
*);
936 static enum move_it_result
937 move_it_in_display_line_to (struct it
*, ptrdiff_t, int,
938 enum move_operation_enum
);
939 static void get_visually_first_element (struct it
*);
940 static void init_to_row_start (struct it
*, struct window
*,
942 static int init_to_row_end (struct it
*, struct window
*,
944 static void back_to_previous_line_start (struct it
*);
945 static int forward_to_next_line_start (struct it
*, int *, struct bidi_it
*);
946 static struct text_pos
string_pos_nchars_ahead (struct text_pos
,
947 Lisp_Object
, ptrdiff_t);
948 static struct text_pos
string_pos (ptrdiff_t, Lisp_Object
);
949 static struct text_pos
c_string_pos (ptrdiff_t, const char *, bool);
950 static ptrdiff_t number_of_chars (const char *, bool);
951 static void compute_stop_pos (struct it
*);
952 static void compute_string_pos (struct text_pos
*, struct text_pos
,
954 static int face_before_or_after_it_pos (struct it
*, int);
955 static ptrdiff_t next_overlay_change (ptrdiff_t);
956 static int handle_display_spec (struct it
*, Lisp_Object
, Lisp_Object
,
957 Lisp_Object
, struct text_pos
*, ptrdiff_t, int);
958 static int handle_single_display_spec (struct it
*, Lisp_Object
,
959 Lisp_Object
, Lisp_Object
,
960 struct text_pos
*, ptrdiff_t, int, int);
961 static int underlying_face_id (struct it
*);
962 static int in_ellipses_for_invisible_text_p (struct display_pos
*,
965 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
966 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
968 #ifdef HAVE_WINDOW_SYSTEM
970 static void x_consider_frame_title (Lisp_Object
);
971 static void update_tool_bar (struct frame
*, int);
972 static int redisplay_tool_bar (struct frame
*);
973 static void notice_overwritten_cursor (struct window
*,
976 static void append_stretch_glyph (struct it
*, Lisp_Object
,
980 #endif /* HAVE_WINDOW_SYSTEM */
982 static void produce_special_glyphs (struct it
*, enum display_element_type
);
983 static void show_mouse_face (Mouse_HLInfo
*, enum draw_glyphs_face
);
984 static int coords_in_mouse_face_p (struct window
*, int, int);
988 /***********************************************************************
989 Window display dimensions
990 ***********************************************************************/
992 /* Return the bottom boundary y-position for text lines in window W.
993 This is the first y position at which a line cannot start.
994 It is relative to the top of the window.
996 This is the height of W minus the height of a mode line, if any. */
999 window_text_bottom_y (struct window
*w
)
1001 int height
= WINDOW_PIXEL_HEIGHT (w
);
1003 height
-= WINDOW_BOTTOM_DIVIDER_WIDTH (w
);
1005 if (WINDOW_WANTS_MODELINE_P (w
))
1006 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
1011 /* Return the pixel width of display area AREA of window W.
1012 ANY_AREA means return the total width of W, not including
1013 fringes to the left and right of the window. */
1016 window_box_width (struct window
*w
, enum glyph_row_area area
)
1018 int pixels
= w
->pixel_width
;
1020 if (!w
->pseudo_window_p
)
1022 pixels
-= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
1023 pixels
-= WINDOW_RIGHT_DIVIDER_WIDTH (w
);
1025 if (area
== TEXT_AREA
)
1026 pixels
-= (WINDOW_MARGINS_WIDTH (w
)
1027 + WINDOW_FRINGES_WIDTH (w
));
1028 else if (area
== LEFT_MARGIN_AREA
)
1029 pixels
= WINDOW_LEFT_MARGIN_WIDTH (w
);
1030 else if (area
== RIGHT_MARGIN_AREA
)
1031 pixels
= WINDOW_RIGHT_MARGIN_WIDTH (w
);
1038 /* Return the pixel height of the display area of window W, not
1039 including mode lines of W, if any. */
1042 window_box_height (struct window
*w
)
1044 struct frame
*f
= XFRAME (w
->frame
);
1045 int height
= WINDOW_PIXEL_HEIGHT (w
);
1047 eassert (height
>= 0);
1049 height
-= WINDOW_BOTTOM_DIVIDER_WIDTH (w
);
1051 /* Note: the code below that determines the mode-line/header-line
1052 height is essentially the same as that contained in the macro
1053 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1054 the appropriate glyph row has its `mode_line_p' flag set,
1055 and if it doesn't, uses estimate_mode_line_height instead. */
1057 if (WINDOW_WANTS_MODELINE_P (w
))
1059 struct glyph_row
*ml_row
1060 = (w
->current_matrix
&& w
->current_matrix
->rows
1061 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1063 if (ml_row
&& ml_row
->mode_line_p
)
1064 height
-= ml_row
->height
;
1066 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1069 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1071 struct glyph_row
*hl_row
1072 = (w
->current_matrix
&& w
->current_matrix
->rows
1073 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1075 if (hl_row
&& hl_row
->mode_line_p
)
1076 height
-= hl_row
->height
;
1078 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1081 /* With a very small font and a mode-line that's taller than
1082 default, we might end up with a negative height. */
1083 return max (0, height
);
1086 /* Return the window-relative coordinate of the left edge of display
1087 area AREA of window W. ANY_AREA means return the left edge of the
1088 whole window, to the right of the left fringe of W. */
1091 window_box_left_offset (struct window
*w
, enum glyph_row_area area
)
1095 if (w
->pseudo_window_p
)
1098 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1100 if (area
== TEXT_AREA
)
1101 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1102 + window_box_width (w
, LEFT_MARGIN_AREA
));
1103 else if (area
== RIGHT_MARGIN_AREA
)
1104 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1105 + window_box_width (w
, LEFT_MARGIN_AREA
)
1106 + window_box_width (w
, TEXT_AREA
)
1107 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1109 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1110 else if (area
== LEFT_MARGIN_AREA
1111 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1112 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1118 /* Return the window-relative coordinate of the right edge of display
1119 area AREA of window W. ANY_AREA means return the right edge of the
1120 whole window, to the left of the right fringe of W. */
1123 window_box_right_offset (struct window
*w
, enum glyph_row_area area
)
1125 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1128 /* Return the frame-relative coordinate of the left edge of display
1129 area AREA of window W. ANY_AREA means return the left edge of the
1130 whole window, to the right of the left fringe of W. */
1133 window_box_left (struct window
*w
, enum glyph_row_area area
)
1135 struct frame
*f
= XFRAME (w
->frame
);
1138 if (w
->pseudo_window_p
)
1139 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1141 x
= (WINDOW_LEFT_EDGE_X (w
)
1142 + window_box_left_offset (w
, area
));
1148 /* Return the frame-relative coordinate of the right edge of display
1149 area AREA of window W. ANY_AREA means return the right edge of the
1150 whole window, to the left of the right fringe of W. */
1153 window_box_right (struct window
*w
, enum glyph_row_area area
)
1155 return window_box_left (w
, area
) + window_box_width (w
, area
);
1158 /* Get the bounding box of the display area AREA of window W, without
1159 mode lines, in frame-relative coordinates. ANY_AREA means the
1160 whole window, not including the left and right fringes of
1161 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1162 coordinates of the upper-left corner of the box. Return in
1163 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1166 window_box (struct window
*w
, enum glyph_row_area area
, int *box_x
,
1167 int *box_y
, int *box_width
, int *box_height
)
1170 *box_width
= window_box_width (w
, area
);
1172 *box_height
= window_box_height (w
);
1174 *box_x
= window_box_left (w
, area
);
1177 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1178 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1179 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1183 #ifdef HAVE_WINDOW_SYSTEM
1185 /* Get the bounding box of the display area AREA of window W, without
1186 mode lines and both fringes of the window. Return in *TOP_LEFT_X
1187 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1188 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1189 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1193 window_box_edges (struct window
*w
, int *top_left_x
, int *top_left_y
,
1194 int *bottom_right_x
, int *bottom_right_y
)
1196 window_box (w
, ANY_AREA
, top_left_x
, top_left_y
,
1197 bottom_right_x
, bottom_right_y
);
1198 *bottom_right_x
+= *top_left_x
;
1199 *bottom_right_y
+= *top_left_y
;
1202 #endif /* HAVE_WINDOW_SYSTEM */
1204 /***********************************************************************
1206 ***********************************************************************/
1208 /* Return the bottom y-position of the line the iterator IT is in.
1209 This can modify IT's settings. */
1212 line_bottom_y (struct it
*it
)
1214 int line_height
= it
->max_ascent
+ it
->max_descent
;
1215 int line_top_y
= it
->current_y
;
1217 if (line_height
== 0)
1220 line_height
= last_height
;
1221 else if (IT_CHARPOS (*it
) < ZV
)
1223 move_it_by_lines (it
, 1);
1224 line_height
= (it
->max_ascent
|| it
->max_descent
1225 ? it
->max_ascent
+ it
->max_descent
1230 struct glyph_row
*row
= it
->glyph_row
;
1232 /* Use the default character height. */
1233 it
->glyph_row
= NULL
;
1234 it
->what
= IT_CHARACTER
;
1237 PRODUCE_GLYPHS (it
);
1238 line_height
= it
->ascent
+ it
->descent
;
1239 it
->glyph_row
= row
;
1243 return line_top_y
+ line_height
;
1246 DEFUN ("line-pixel-height", Fline_pixel_height
,
1247 Sline_pixel_height
, 0, 0, 0,
1248 doc
: /* Return height in pixels of text line in the selected window.
1250 Value is the height in pixels of the line at point. */)
1255 struct window
*w
= XWINDOW (selected_window
);
1257 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
1258 start_display (&it
, w
, pt
);
1259 it
.vpos
= it
.current_y
= 0;
1261 return make_number (line_bottom_y (&it
));
1264 /* Return the default pixel height of text lines in window W. The
1265 value is the canonical height of the W frame's default font, plus
1266 any extra space required by the line-spacing variable or frame
1269 Implementation note: this ignores any line-spacing text properties
1270 put on the newline characters. This is because those properties
1271 only affect the _screen_ line ending in the newline (i.e., in a
1272 continued line, only the last screen line will be affected), which
1273 means only a small number of lines in a buffer can ever use this
1274 feature. Since this function is used to compute the default pixel
1275 equivalent of text lines in a window, we can safely ignore those
1276 few lines. For the same reasons, we ignore the line-height
1279 default_line_pixel_height (struct window
*w
)
1281 struct frame
*f
= WINDOW_XFRAME (w
);
1282 int height
= FRAME_LINE_HEIGHT (f
);
1284 if (!FRAME_INITIAL_P (f
) && BUFFERP (w
->contents
))
1286 struct buffer
*b
= XBUFFER (w
->contents
);
1287 Lisp_Object val
= BVAR (b
, extra_line_spacing
);
1290 val
= BVAR (&buffer_defaults
, extra_line_spacing
);
1293 if (RANGED_INTEGERP (0, val
, INT_MAX
))
1294 height
+= XFASTINT (val
);
1295 else if (FLOATP (val
))
1297 int addon
= XFLOAT_DATA (val
) * height
+ 0.5;
1304 height
+= f
->extra_line_spacing
;
1310 /* Subroutine of pos_visible_p below. Extracts a display string, if
1311 any, from the display spec given as its argument. */
1313 string_from_display_spec (Lisp_Object spec
)
1317 while (CONSP (spec
))
1319 if (STRINGP (XCAR (spec
)))
1324 else if (VECTORP (spec
))
1328 for (i
= 0; i
< ASIZE (spec
); i
++)
1330 if (STRINGP (AREF (spec
, i
)))
1331 return AREF (spec
, i
);
1340 /* Limit insanely large values of W->hscroll on frame F to the largest
1341 value that will still prevent first_visible_x and last_visible_x of
1342 'struct it' from overflowing an int. */
1344 window_hscroll_limited (struct window
*w
, struct frame
*f
)
1346 ptrdiff_t window_hscroll
= w
->hscroll
;
1347 int window_text_width
= window_box_width (w
, TEXT_AREA
);
1348 int colwidth
= FRAME_COLUMN_WIDTH (f
);
1350 if (window_hscroll
> (INT_MAX
- window_text_width
) / colwidth
- 1)
1351 window_hscroll
= (INT_MAX
- window_text_width
) / colwidth
- 1;
1353 return window_hscroll
;
1356 /* Return 1 if position CHARPOS is visible in window W.
1357 CHARPOS < 0 means return info about WINDOW_END position.
1358 If visible, set *X and *Y to pixel coordinates of top left corner.
1359 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1360 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1363 pos_visible_p (struct window
*w
, ptrdiff_t charpos
, int *x
, int *y
,
1364 int *rtop
, int *rbot
, int *rowh
, int *vpos
)
1367 void *itdata
= bidi_shelve_cache ();
1368 struct text_pos top
;
1370 struct buffer
*old_buffer
= NULL
;
1372 if (FRAME_INITIAL_P (XFRAME (WINDOW_FRAME (w
))))
1375 if (XBUFFER (w
->contents
) != current_buffer
)
1377 old_buffer
= current_buffer
;
1378 set_buffer_internal_1 (XBUFFER (w
->contents
));
1381 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1382 /* Scrolling a minibuffer window via scroll bar when the echo area
1383 shows long text sometimes resets the minibuffer contents behind
1385 if (CHARPOS (top
) > ZV
)
1386 SET_TEXT_POS (top
, BEGV
, BEGV_BYTE
);
1388 /* Compute exact mode line heights. */
1389 if (WINDOW_WANTS_MODELINE_P (w
))
1391 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1392 BVAR (current_buffer
, mode_line_format
));
1394 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1395 w
->header_line_height
1396 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1397 BVAR (current_buffer
, header_line_format
));
1399 start_display (&it
, w
, top
);
1400 move_it_to (&it
, charpos
, -1, it
.last_visible_y
- 1, -1,
1401 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1404 && (((!it
.bidi_p
|| it
.bidi_it
.scan_dir
== 1)
1405 && IT_CHARPOS (it
) >= charpos
)
1406 /* When scanning backwards under bidi iteration, move_it_to
1407 stops at or _before_ CHARPOS, because it stops at or to
1408 the _right_ of the character at CHARPOS. */
1409 || (it
.bidi_p
&& it
.bidi_it
.scan_dir
== -1
1410 && IT_CHARPOS (it
) <= charpos
)))
1412 /* We have reached CHARPOS, or passed it. How the call to
1413 move_it_to can overshoot: (i) If CHARPOS is on invisible text
1414 or covered by a display property, move_it_to stops at the end
1415 of the invisible text, to the right of CHARPOS. (ii) If
1416 CHARPOS is in a display vector, move_it_to stops on its last
1418 int top_x
= it
.current_x
;
1419 int top_y
= it
.current_y
;
1420 /* Calling line_bottom_y may change it.method, it.position, etc. */
1421 enum it_method it_method
= it
.method
;
1422 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1423 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1425 if (top_y
< window_top_y
)
1426 visible_p
= bottom_y
> window_top_y
;
1427 else if (top_y
< it
.last_visible_y
)
1429 if (bottom_y
>= it
.last_visible_y
1430 && it
.bidi_p
&& it
.bidi_it
.scan_dir
== -1
1431 && IT_CHARPOS (it
) < charpos
)
1433 /* When the last line of the window is scanned backwards
1434 under bidi iteration, we could be duped into thinking
1435 that we have passed CHARPOS, when in fact move_it_to
1436 simply stopped short of CHARPOS because it reached
1437 last_visible_y. To see if that's what happened, we call
1438 move_it_to again with a slightly larger vertical limit,
1439 and see if it actually moved vertically; if it did, we
1440 didn't really reach CHARPOS, which is beyond window end. */
1441 struct it save_it
= it
;
1442 /* Why 10? because we don't know how many canonical lines
1443 will the height of the next line(s) be. So we guess. */
1444 int ten_more_lines
= 10 * default_line_pixel_height (w
);
1446 move_it_to (&it
, charpos
, -1, bottom_y
+ ten_more_lines
, -1,
1447 MOVE_TO_POS
| MOVE_TO_Y
);
1448 if (it
.current_y
> top_y
)
1455 if (it_method
== GET_FROM_DISPLAY_VECTOR
)
1457 /* We stopped on the last glyph of a display vector.
1458 Try and recompute. Hack alert! */
1459 if (charpos
< 2 || top
.charpos
>= charpos
)
1460 top_x
= it
.glyph_row
->x
;
1463 struct it it2
, it2_prev
;
1464 /* The idea is to get to the previous buffer
1465 position, consume the character there, and use
1466 the pixel coordinates we get after that. But if
1467 the previous buffer position is also displayed
1468 from a display vector, we need to consume all of
1469 the glyphs from that display vector. */
1470 start_display (&it2
, w
, top
);
1471 move_it_to (&it2
, charpos
- 1, -1, -1, -1, MOVE_TO_POS
);
1472 /* If we didn't get to CHARPOS - 1, there's some
1473 replacing display property at that position, and
1474 we stopped after it. That is exactly the place
1475 whose coordinates we want. */
1476 if (IT_CHARPOS (it2
) != charpos
- 1)
1480 /* Iterate until we get out of the display
1481 vector that displays the character at
1484 get_next_display_element (&it2
);
1485 PRODUCE_GLYPHS (&it2
);
1487 set_iterator_to_next (&it2
, 1);
1488 } while (it2
.method
== GET_FROM_DISPLAY_VECTOR
1489 && IT_CHARPOS (it2
) < charpos
);
1491 if (ITERATOR_AT_END_OF_LINE_P (&it2_prev
)
1492 || it2_prev
.current_x
> it2_prev
.last_visible_x
)
1493 top_x
= it
.glyph_row
->x
;
1496 top_x
= it2_prev
.current_x
;
1497 top_y
= it2_prev
.current_y
;
1501 else if (IT_CHARPOS (it
) != charpos
)
1503 Lisp_Object cpos
= make_number (charpos
);
1504 Lisp_Object spec
= Fget_char_property (cpos
, Qdisplay
, Qnil
);
1505 Lisp_Object string
= string_from_display_spec (spec
);
1506 struct text_pos tpos
;
1507 int replacing_spec_p
;
1508 bool newline_in_string
1510 && memchr (SDATA (string
), '\n', SBYTES (string
)));
1512 SET_TEXT_POS (tpos
, charpos
, CHAR_TO_BYTE (charpos
));
1515 && handle_display_spec (NULL
, spec
, Qnil
, Qnil
, &tpos
,
1516 charpos
, FRAME_WINDOW_P (it
.f
)));
1517 /* The tricky code below is needed because there's a
1518 discrepancy between move_it_to and how we set cursor
1519 when PT is at the beginning of a portion of text
1520 covered by a display property or an overlay with a
1521 display property, or the display line ends in a
1522 newline from a display string. move_it_to will stop
1523 _after_ such display strings, whereas
1524 set_cursor_from_row conspires with cursor_row_p to
1525 place the cursor on the first glyph produced from the
1528 /* We have overshoot PT because it is covered by a
1529 display property that replaces the text it covers.
1530 If the string includes embedded newlines, we are also
1531 in the wrong display line. Backtrack to the correct
1532 line, where the display property begins. */
1533 if (replacing_spec_p
)
1535 Lisp_Object startpos
, endpos
;
1536 EMACS_INT start
, end
;
1540 /* Find the first and the last buffer positions
1541 covered by the display string. */
1543 Fnext_single_char_property_change (cpos
, Qdisplay
,
1546 Fprevious_single_char_property_change (endpos
, Qdisplay
,
1548 start
= XFASTINT (startpos
);
1549 end
= XFASTINT (endpos
);
1550 /* Move to the last buffer position before the
1551 display property. */
1552 start_display (&it3
, w
, top
);
1553 move_it_to (&it3
, start
- 1, -1, -1, -1, MOVE_TO_POS
);
1554 /* Move forward one more line if the position before
1555 the display string is a newline or if it is the
1556 rightmost character on a line that is
1557 continued or word-wrapped. */
1558 if (it3
.method
== GET_FROM_BUFFER
1560 || FETCH_BYTE (IT_BYTEPOS (it3
)) == '\n'))
1561 move_it_by_lines (&it3
, 1);
1562 else if (move_it_in_display_line_to (&it3
, -1,
1566 == MOVE_LINE_CONTINUED
)
1568 move_it_by_lines (&it3
, 1);
1569 /* When we are under word-wrap, the #$@%!
1570 move_it_by_lines moves 2 lines, so we need to
1572 if (it3
.line_wrap
== WORD_WRAP
)
1573 move_it_by_lines (&it3
, -1);
1576 /* Record the vertical coordinate of the display
1577 line where we wound up. */
1578 top_y
= it3
.current_y
;
1581 /* When characters are reordered for display,
1582 the character displayed to the left of the
1583 display string could be _after_ the display
1584 property in the logical order. Use the
1585 smallest vertical position of these two. */
1586 start_display (&it3
, w
, top
);
1587 move_it_to (&it3
, end
+ 1, -1, -1, -1, MOVE_TO_POS
);
1588 if (it3
.current_y
< top_y
)
1589 top_y
= it3
.current_y
;
1591 /* Move from the top of the window to the beginning
1592 of the display line where the display string
1594 start_display (&it3
, w
, top
);
1595 move_it_to (&it3
, -1, 0, top_y
, -1, MOVE_TO_X
| MOVE_TO_Y
);
1596 /* If it3_moved stays zero after the 'while' loop
1597 below, that means we already were at a newline
1598 before the loop (e.g., the display string begins
1599 with a newline), so we don't need to (and cannot)
1600 inspect the glyphs of it3.glyph_row, because
1601 PRODUCE_GLYPHS will not produce anything for a
1602 newline, and thus it3.glyph_row stays at its
1603 stale content it got at top of the window. */
1605 /* Finally, advance the iterator until we hit the
1606 first display element whose character position is
1607 CHARPOS, or until the first newline from the
1608 display string, which signals the end of the
1610 while (get_next_display_element (&it3
))
1612 PRODUCE_GLYPHS (&it3
);
1613 if (IT_CHARPOS (it3
) == charpos
1614 || ITERATOR_AT_END_OF_LINE_P (&it3
))
1617 set_iterator_to_next (&it3
, 0);
1619 top_x
= it3
.current_x
- it3
.pixel_width
;
1620 /* Normally, we would exit the above loop because we
1621 found the display element whose character
1622 position is CHARPOS. For the contingency that we
1623 didn't, and stopped at the first newline from the
1624 display string, move back over the glyphs
1625 produced from the string, until we find the
1626 rightmost glyph not from the string. */
1628 && newline_in_string
1629 && IT_CHARPOS (it3
) != charpos
&& EQ (it3
.object
, string
))
1631 struct glyph
*g
= it3
.glyph_row
->glyphs
[TEXT_AREA
]
1632 + it3
.glyph_row
->used
[TEXT_AREA
];
1634 while (EQ ((g
- 1)->object
, string
))
1637 top_x
-= g
->pixel_width
;
1639 eassert (g
< it3
.glyph_row
->glyphs
[TEXT_AREA
]
1640 + it3
.glyph_row
->used
[TEXT_AREA
]);
1646 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1647 *rtop
= max (0, window_top_y
- top_y
);
1648 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1649 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1650 - max (top_y
, window_top_y
)));
1656 /* We were asked to provide info about WINDOW_END. */
1658 void *it2data
= NULL
;
1660 SAVE_IT (it2
, it
, it2data
);
1661 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1662 move_it_by_lines (&it
, 1);
1663 if (charpos
< IT_CHARPOS (it
)
1664 || (it
.what
== IT_EOB
&& charpos
== IT_CHARPOS (it
)))
1667 RESTORE_IT (&it2
, &it2
, it2data
);
1668 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1670 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1671 *rtop
= max (0, -it2
.current_y
);
1672 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1673 - it
.last_visible_y
));
1674 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1676 - max (it2
.current_y
,
1677 WINDOW_HEADER_LINE_HEIGHT (w
))));
1681 bidi_unshelve_cache (it2data
, 1);
1683 bidi_unshelve_cache (itdata
, 0);
1686 set_buffer_internal_1 (old_buffer
);
1688 if (visible_p
&& w
->hscroll
> 0)
1690 window_hscroll_limited (w
, WINDOW_XFRAME (w
))
1691 * WINDOW_FRAME_COLUMN_WIDTH (w
);
1694 /* Debugging code. */
1696 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1697 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1699 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1706 /* Return the next character from STR. Return in *LEN the length of
1707 the character. This is like STRING_CHAR_AND_LENGTH but never
1708 returns an invalid character. If we find one, we return a `?', but
1709 with the length of the invalid character. */
1712 string_char_and_length (const unsigned char *str
, int *len
)
1716 c
= STRING_CHAR_AND_LENGTH (str
, *len
);
1717 if (!CHAR_VALID_P (c
))
1718 /* We may not change the length here because other places in Emacs
1719 don't use this function, i.e. they silently accept invalid
1728 /* Given a position POS containing a valid character and byte position
1729 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1731 static struct text_pos
1732 string_pos_nchars_ahead (struct text_pos pos
, Lisp_Object string
, ptrdiff_t nchars
)
1734 eassert (STRINGP (string
) && nchars
>= 0);
1736 if (STRING_MULTIBYTE (string
))
1738 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1743 string_char_and_length (p
, &len
);
1746 BYTEPOS (pos
) += len
;
1750 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1756 /* Value is the text position, i.e. character and byte position,
1757 for character position CHARPOS in STRING. */
1759 static struct text_pos
1760 string_pos (ptrdiff_t charpos
, Lisp_Object string
)
1762 struct text_pos pos
;
1763 eassert (STRINGP (string
));
1764 eassert (charpos
>= 0);
1765 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1770 /* Value is a text position, i.e. character and byte position, for
1771 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1772 means recognize multibyte characters. */
1774 static struct text_pos
1775 c_string_pos (ptrdiff_t charpos
, const char *s
, bool multibyte_p
)
1777 struct text_pos pos
;
1779 eassert (s
!= NULL
);
1780 eassert (charpos
>= 0);
1786 SET_TEXT_POS (pos
, 0, 0);
1789 string_char_and_length ((const unsigned char *) s
, &len
);
1792 BYTEPOS (pos
) += len
;
1796 SET_TEXT_POS (pos
, charpos
, charpos
);
1802 /* Value is the number of characters in C string S. MULTIBYTE_P
1803 non-zero means recognize multibyte characters. */
1806 number_of_chars (const char *s
, bool multibyte_p
)
1812 ptrdiff_t rest
= strlen (s
);
1814 const unsigned char *p
= (const unsigned char *) s
;
1816 for (nchars
= 0; rest
> 0; ++nchars
)
1818 string_char_and_length (p
, &len
);
1819 rest
-= len
, p
+= len
;
1823 nchars
= strlen (s
);
1829 /* Compute byte position NEWPOS->bytepos corresponding to
1830 NEWPOS->charpos. POS is a known position in string STRING.
1831 NEWPOS->charpos must be >= POS.charpos. */
1834 compute_string_pos (struct text_pos
*newpos
, struct text_pos pos
, Lisp_Object string
)
1836 eassert (STRINGP (string
));
1837 eassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1839 if (STRING_MULTIBYTE (string
))
1840 *newpos
= string_pos_nchars_ahead (pos
, string
,
1841 CHARPOS (*newpos
) - CHARPOS (pos
));
1843 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1847 Return an estimation of the pixel height of mode or header lines on
1848 frame F. FACE_ID specifies what line's height to estimate. */
1851 estimate_mode_line_height (struct frame
*f
, enum face_id face_id
)
1853 #ifdef HAVE_WINDOW_SYSTEM
1854 if (FRAME_WINDOW_P (f
))
1856 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1858 /* This function is called so early when Emacs starts that the face
1859 cache and mode line face are not yet initialized. */
1860 if (FRAME_FACE_CACHE (f
))
1862 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1866 height
= FONT_HEIGHT (face
->font
);
1867 if (face
->box_line_width
> 0)
1868 height
+= 2 * face
->box_line_width
;
1879 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1880 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1881 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1882 not force the value into range. */
1885 pixel_to_glyph_coords (struct frame
*f
, register int pix_x
, register int pix_y
,
1886 int *x
, int *y
, NativeRectangle
*bounds
, int noclip
)
1889 #ifdef HAVE_WINDOW_SYSTEM
1890 if (FRAME_WINDOW_P (f
))
1892 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1893 even for negative values. */
1895 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1897 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1899 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1900 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1903 STORE_NATIVE_RECT (*bounds
,
1904 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1905 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1906 FRAME_COLUMN_WIDTH (f
) - 1,
1907 FRAME_LINE_HEIGHT (f
) - 1);
1909 /* PXW: Should we clip pixelized before converting to
1915 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1916 pix_x
= FRAME_TOTAL_COLS (f
);
1920 else if (pix_y
> FRAME_LINES (f
))
1921 pix_y
= FRAME_LINES (f
);
1931 /* Find the glyph under window-relative coordinates X/Y in window W.
1932 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1933 strings. Return in *HPOS and *VPOS the row and column number of
1934 the glyph found. Return in *AREA the glyph area containing X.
1935 Value is a pointer to the glyph found or null if X/Y is not on
1936 text, or we can't tell because W's current matrix is not up to
1939 static struct glyph
*
1940 x_y_to_hpos_vpos (struct window
*w
, int x
, int y
, int *hpos
, int *vpos
,
1941 int *dx
, int *dy
, int *area
)
1943 struct glyph
*glyph
, *end
;
1944 struct glyph_row
*row
= NULL
;
1947 /* Find row containing Y. Give up if some row is not enabled. */
1948 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1950 row
= MATRIX_ROW (w
->current_matrix
, i
);
1951 if (!row
->enabled_p
)
1953 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1960 /* Give up if Y is not in the window. */
1961 if (i
== w
->current_matrix
->nrows
)
1964 /* Get the glyph area containing X. */
1965 if (w
->pseudo_window_p
)
1972 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1974 *area
= LEFT_MARGIN_AREA
;
1975 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1977 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1980 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1984 *area
= RIGHT_MARGIN_AREA
;
1985 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1989 /* Find glyph containing X. */
1990 glyph
= row
->glyphs
[*area
];
1991 end
= glyph
+ row
->used
[*area
];
1993 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1995 x
-= glyph
->pixel_width
;
2005 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
2008 *hpos
= glyph
- row
->glyphs
[*area
];
2012 /* Convert frame-relative x/y to coordinates relative to window W.
2013 Takes pseudo-windows into account. */
2016 frame_to_window_pixel_xy (struct window
*w
, int *x
, int *y
)
2018 if (w
->pseudo_window_p
)
2020 /* A pseudo-window is always full-width, and starts at the
2021 left edge of the frame, plus a frame border. */
2022 struct frame
*f
= XFRAME (w
->frame
);
2023 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
2024 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
2028 *x
-= WINDOW_LEFT_EDGE_X (w
);
2029 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
2033 #ifdef HAVE_WINDOW_SYSTEM
2036 Return in RECTS[] at most N clipping rectangles for glyph string S.
2037 Return the number of stored rectangles. */
2040 get_glyph_string_clip_rects (struct glyph_string
*s
, NativeRectangle
*rects
, int n
)
2047 if (s
->row
->full_width_p
)
2049 /* Draw full-width. X coordinates are relative to S->w->left_col. */
2050 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
2051 if (s
->row
->mode_line_p
)
2052 r
.width
= WINDOW_PIXEL_WIDTH (s
->w
) - WINDOW_RIGHT_DIVIDER_WIDTH (s
->w
);
2054 r
.width
= WINDOW_PIXEL_WIDTH (s
->w
);
2056 /* Unless displaying a mode or menu bar line, which are always
2057 fully visible, clip to the visible part of the row. */
2058 if (s
->w
->pseudo_window_p
)
2059 r
.height
= s
->row
->visible_height
;
2061 r
.height
= s
->height
;
2065 /* This is a text line that may be partially visible. */
2066 r
.x
= window_box_left (s
->w
, s
->area
);
2067 r
.width
= window_box_width (s
->w
, s
->area
);
2068 r
.height
= s
->row
->visible_height
;
2072 if (r
.x
< s
->clip_head
->x
)
2074 if (r
.width
>= s
->clip_head
->x
- r
.x
)
2075 r
.width
-= s
->clip_head
->x
- r
.x
;
2078 r
.x
= s
->clip_head
->x
;
2081 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
2083 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
2084 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
2089 /* If S draws overlapping rows, it's sufficient to use the top and
2090 bottom of the window for clipping because this glyph string
2091 intentionally draws over other lines. */
2092 if (s
->for_overlaps
)
2094 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
2095 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
2097 /* Alas, the above simple strategy does not work for the
2098 environments with anti-aliased text: if the same text is
2099 drawn onto the same place multiple times, it gets thicker.
2100 If the overlap we are processing is for the erased cursor, we
2101 take the intersection with the rectangle of the cursor. */
2102 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
2104 XRectangle rc
, r_save
= r
;
2106 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
2107 rc
.y
= s
->w
->phys_cursor
.y
;
2108 rc
.width
= s
->w
->phys_cursor_width
;
2109 rc
.height
= s
->w
->phys_cursor_height
;
2111 x_intersect_rectangles (&r_save
, &rc
, &r
);
2116 /* Don't use S->y for clipping because it doesn't take partially
2117 visible lines into account. For example, it can be negative for
2118 partially visible lines at the top of a window. */
2119 if (!s
->row
->full_width_p
2120 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
2121 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
2123 r
.y
= max (0, s
->row
->y
);
2126 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
2128 /* If drawing the cursor, don't let glyph draw outside its
2129 advertised boundaries. Cleartype does this under some circumstances. */
2130 if (s
->hl
== DRAW_CURSOR
)
2132 struct glyph
*glyph
= s
->first_glyph
;
2137 r
.width
-= s
->x
- r
.x
;
2140 r
.width
= min (r
.width
, glyph
->pixel_width
);
2142 /* If r.y is below window bottom, ensure that we still see a cursor. */
2143 height
= min (glyph
->ascent
+ glyph
->descent
,
2144 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
2145 max_y
= window_text_bottom_y (s
->w
) - height
;
2146 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
2147 if (s
->ybase
- glyph
->ascent
> max_y
)
2154 /* Don't draw cursor glyph taller than our actual glyph. */
2155 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
2156 if (height
< r
.height
)
2158 max_y
= r
.y
+ r
.height
;
2159 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
2160 r
.height
= min (max_y
- r
.y
, height
);
2167 XRectangle r_save
= r
;
2169 if (! x_intersect_rectangles (&r_save
, s
->row
->clip
, &r
))
2173 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
2174 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
2176 #ifdef CONVERT_FROM_XRECT
2177 CONVERT_FROM_XRECT (r
, *rects
);
2185 /* If we are processing overlapping and allowed to return
2186 multiple clipping rectangles, we exclude the row of the glyph
2187 string from the clipping rectangle. This is to avoid drawing
2188 the same text on the environment with anti-aliasing. */
2189 #ifdef CONVERT_FROM_XRECT
2192 XRectangle
*rs
= rects
;
2194 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
2196 if (s
->for_overlaps
& OVERLAPS_PRED
)
2199 if (r
.y
+ r
.height
> row_y
)
2202 rs
[i
].height
= row_y
- r
.y
;
2208 if (s
->for_overlaps
& OVERLAPS_SUCC
)
2211 if (r
.y
< row_y
+ s
->row
->visible_height
)
2213 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
2215 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
2216 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
2225 #ifdef CONVERT_FROM_XRECT
2226 for (i
= 0; i
< n
; i
++)
2227 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
2234 Return in *NR the clipping rectangle for glyph string S. */
2237 get_glyph_string_clip_rect (struct glyph_string
*s
, NativeRectangle
*nr
)
2239 get_glyph_string_clip_rects (s
, nr
, 1);
2244 Return the position and height of the phys cursor in window W.
2245 Set w->phys_cursor_width to width of phys cursor.
2249 get_phys_cursor_geometry (struct window
*w
, struct glyph_row
*row
,
2250 struct glyph
*glyph
, int *xp
, int *yp
, int *heightp
)
2252 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2253 int x
, y
, wd
, h
, h0
, y0
;
2255 /* Compute the width of the rectangle to draw. If on a stretch
2256 glyph, and `x-stretch-block-cursor' is nil, don't draw a
2257 rectangle as wide as the glyph, but use a canonical character
2259 wd
= glyph
->pixel_width
- 1;
2260 #if defined (HAVE_NTGUI) || defined (HAVE_NS)
2264 x
= w
->phys_cursor
.x
;
2271 if (glyph
->type
== STRETCH_GLYPH
2272 && !x_stretch_cursor_p
)
2273 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2274 w
->phys_cursor_width
= wd
;
2276 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
2278 /* If y is below window bottom, ensure that we still see a cursor. */
2279 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2281 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
2282 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
2284 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2287 h
= max (h
- (y0
- y
) + 1, h0
);
2292 y0
= window_text_bottom_y (w
) - h0
;
2300 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
2301 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2306 * Remember which glyph the mouse is over.
2310 remember_mouse_glyph (struct frame
*f
, int gx
, int gy
, NativeRectangle
*rect
)
2314 struct glyph_row
*r
, *gr
, *end_row
;
2315 enum window_part part
;
2316 enum glyph_row_area area
;
2317 int x
, y
, width
, height
;
2319 /* Try to determine frame pixel position and size of the glyph under
2320 frame pixel coordinates X/Y on frame F. */
2322 if (window_resize_pixelwise
)
2327 else if (!f
->glyphs_initialized_p
2328 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, 0),
2331 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2332 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2336 w
= XWINDOW (window
);
2337 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2338 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2340 x
= window_relative_x_coord (w
, part
, gx
);
2341 y
= gy
- WINDOW_TOP_EDGE_Y (w
);
2343 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2344 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2346 if (w
->pseudo_window_p
)
2349 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2355 case ON_LEFT_MARGIN
:
2356 area
= LEFT_MARGIN_AREA
;
2359 case ON_RIGHT_MARGIN
:
2360 area
= RIGHT_MARGIN_AREA
;
2363 case ON_HEADER_LINE
:
2365 gr
= (part
== ON_HEADER_LINE
2366 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2367 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2370 goto text_glyph_row_found
;
2377 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2378 if (r
->y
+ r
->height
> y
)
2384 text_glyph_row_found
:
2387 struct glyph
*g
= gr
->glyphs
[area
];
2388 struct glyph
*end
= g
+ gr
->used
[area
];
2390 height
= gr
->height
;
2391 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2392 if (gx
+ g
->pixel_width
> x
)
2397 if (g
->type
== IMAGE_GLYPH
)
2399 /* Don't remember when mouse is over image, as
2400 image may have hot-spots. */
2401 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2404 width
= g
->pixel_width
;
2408 /* Use nominal char spacing at end of line. */
2410 gx
+= (x
/ width
) * width
;
2413 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2414 gx
+= window_box_left_offset (w
, area
);
2418 /* Use nominal line height at end of window. */
2419 gx
= (x
/ width
) * width
;
2421 gy
+= (y
/ height
) * height
;
2425 case ON_LEFT_FRINGE
:
2426 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2427 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2428 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2429 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2432 case ON_RIGHT_FRINGE
:
2433 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2434 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2435 : window_box_right_offset (w
, TEXT_AREA
));
2436 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2440 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2442 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2443 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2444 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2446 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2450 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2451 if (r
->y
+ r
->height
> y
)
2458 height
= gr
->height
;
2461 /* Use nominal line height at end of window. */
2463 gy
+= (y
/ height
) * height
;
2470 /* If there is no glyph under the mouse, then we divide the screen
2471 into a grid of the smallest glyph in the frame, and use that
2474 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2475 round down even for negative values. */
2481 gx
= (gx
/ width
) * width
;
2482 gy
= (gy
/ height
) * height
;
2488 gx
+= WINDOW_LEFT_EDGE_X (w
);
2489 gy
+= WINDOW_TOP_EDGE_Y (w
);
2492 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2494 /* Visible feedback for debugging. */
2497 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2498 f
->output_data
.x
->normal_gc
,
2499 gx
, gy
, width
, height
);
2505 #endif /* HAVE_WINDOW_SYSTEM */
2508 adjust_window_ends (struct window
*w
, struct glyph_row
*row
, bool current
)
2511 w
->window_end_pos
= Z
- MATRIX_ROW_END_CHARPOS (row
);
2512 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
2514 = MATRIX_ROW_VPOS (row
, current
? w
->current_matrix
: w
->desired_matrix
);
2517 /***********************************************************************
2518 Lisp form evaluation
2519 ***********************************************************************/
2521 /* Error handler for safe_eval and safe_call. */
2524 safe_eval_handler (Lisp_Object arg
, ptrdiff_t nargs
, Lisp_Object
*args
)
2526 add_to_log ("Error during redisplay: %S signaled %S",
2527 Flist (nargs
, args
), arg
);
2531 /* Call function FUNC with the rest of NARGS - 1 arguments
2532 following. Return the result, or nil if something went
2533 wrong. Prevent redisplay during the evaluation. */
2536 safe_call (ptrdiff_t nargs
, Lisp_Object func
, ...)
2540 if (inhibit_eval_during_redisplay
)
2546 ptrdiff_t count
= SPECPDL_INDEX ();
2547 struct gcpro gcpro1
;
2548 Lisp_Object
*args
= alloca (nargs
* word_size
);
2551 va_start (ap
, func
);
2552 for (i
= 1; i
< nargs
; i
++)
2553 args
[i
] = va_arg (ap
, Lisp_Object
);
2557 gcpro1
.nvars
= nargs
;
2558 specbind (Qinhibit_redisplay
, Qt
);
2559 /* Use Qt to ensure debugger does not run,
2560 so there is no possibility of wanting to redisplay. */
2561 val
= internal_condition_case_n (Ffuncall
, nargs
, args
, Qt
,
2564 val
= unbind_to (count
, val
);
2571 /* Call function FN with one argument ARG.
2572 Return the result, or nil if something went wrong. */
2575 safe_call1 (Lisp_Object fn
, Lisp_Object arg
)
2577 return safe_call (2, fn
, arg
);
2580 static Lisp_Object Qeval
;
2583 safe_eval (Lisp_Object sexpr
)
2585 return safe_call1 (Qeval
, sexpr
);
2588 /* Call function FN with two arguments ARG1 and ARG2.
2589 Return the result, or nil if something went wrong. */
2592 safe_call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2594 return safe_call (3, fn
, arg1
, arg2
);
2599 /***********************************************************************
2601 ***********************************************************************/
2605 /* Define CHECK_IT to perform sanity checks on iterators.
2606 This is for debugging. It is too slow to do unconditionally. */
2609 check_it (struct it
*it
)
2611 if (it
->method
== GET_FROM_STRING
)
2613 eassert (STRINGP (it
->string
));
2614 eassert (IT_STRING_CHARPOS (*it
) >= 0);
2618 eassert (IT_STRING_CHARPOS (*it
) < 0);
2619 if (it
->method
== GET_FROM_BUFFER
)
2621 /* Check that character and byte positions agree. */
2622 eassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2627 eassert (it
->current
.dpvec_index
>= 0);
2629 eassert (it
->current
.dpvec_index
< 0);
2632 #define CHECK_IT(IT) check_it ((IT))
2636 #define CHECK_IT(IT) (void) 0
2641 #if defined GLYPH_DEBUG && defined ENABLE_CHECKING
2643 /* Check that the window end of window W is what we expect it
2644 to be---the last row in the current matrix displaying text. */
2647 check_window_end (struct window
*w
)
2649 if (!MINI_WINDOW_P (w
) && w
->window_end_valid
)
2651 struct glyph_row
*row
;
2652 eassert ((row
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
),
2654 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2655 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2659 #define CHECK_WINDOW_END(W) check_window_end ((W))
2663 #define CHECK_WINDOW_END(W) (void) 0
2665 #endif /* GLYPH_DEBUG and ENABLE_CHECKING */
2667 /***********************************************************************
2668 Iterator initialization
2669 ***********************************************************************/
2671 /* Initialize IT for displaying current_buffer in window W, starting
2672 at character position CHARPOS. CHARPOS < 0 means that no buffer
2673 position is specified which is useful when the iterator is assigned
2674 a position later. BYTEPOS is the byte position corresponding to
2677 If ROW is not null, calls to produce_glyphs with IT as parameter
2678 will produce glyphs in that row.
2680 BASE_FACE_ID is the id of a base face to use. It must be one of
2681 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2682 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2683 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2685 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2686 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2687 will be initialized to use the corresponding mode line glyph row of
2688 the desired matrix of W. */
2691 init_iterator (struct it
*it
, struct window
*w
,
2692 ptrdiff_t charpos
, ptrdiff_t bytepos
,
2693 struct glyph_row
*row
, enum face_id base_face_id
)
2695 enum face_id remapped_base_face_id
= base_face_id
;
2697 /* Some precondition checks. */
2698 eassert (w
!= NULL
&& it
!= NULL
);
2699 eassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2702 /* If face attributes have been changed since the last redisplay,
2703 free realized faces now because they depend on face definitions
2704 that might have changed. Don't free faces while there might be
2705 desired matrices pending which reference these faces. */
2706 if (face_change_count
&& !inhibit_free_realized_faces
)
2708 face_change_count
= 0;
2709 free_all_realized_faces (Qnil
);
2712 /* Perhaps remap BASE_FACE_ID to a user-specified alternative. */
2713 if (! NILP (Vface_remapping_alist
))
2714 remapped_base_face_id
2715 = lookup_basic_face (XFRAME (w
->frame
), base_face_id
);
2717 /* Use one of the mode line rows of W's desired matrix if
2721 if (base_face_id
== MODE_LINE_FACE_ID
2722 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2723 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2724 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2725 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2729 memset (it
, 0, sizeof *it
);
2730 it
->current
.overlay_string_index
= -1;
2731 it
->current
.dpvec_index
= -1;
2732 it
->base_face_id
= remapped_base_face_id
;
2734 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2735 it
->paragraph_embedding
= L2R
;
2736 it
->bidi_it
.string
.lstring
= Qnil
;
2737 it
->bidi_it
.string
.s
= NULL
;
2738 it
->bidi_it
.string
.bufpos
= 0;
2741 /* The window in which we iterate over current_buffer: */
2742 XSETWINDOW (it
->window
, w
);
2744 it
->f
= XFRAME (w
->frame
);
2748 /* Extra space between lines (on window systems only). */
2749 if (base_face_id
== DEFAULT_FACE_ID
2750 && FRAME_WINDOW_P (it
->f
))
2752 if (NATNUMP (BVAR (current_buffer
, extra_line_spacing
)))
2753 it
->extra_line_spacing
= XFASTINT (BVAR (current_buffer
, extra_line_spacing
));
2754 else if (FLOATP (BVAR (current_buffer
, extra_line_spacing
)))
2755 it
->extra_line_spacing
= (XFLOAT_DATA (BVAR (current_buffer
, extra_line_spacing
))
2756 * FRAME_LINE_HEIGHT (it
->f
));
2757 else if (it
->f
->extra_line_spacing
> 0)
2758 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2759 it
->max_extra_line_spacing
= 0;
2762 /* If realized faces have been removed, e.g. because of face
2763 attribute changes of named faces, recompute them. When running
2764 in batch mode, the face cache of the initial frame is null. If
2765 we happen to get called, make a dummy face cache. */
2766 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2767 init_frame_faces (it
->f
);
2768 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2769 recompute_basic_faces (it
->f
);
2771 /* Current value of the `slice', `space-width', and 'height' properties. */
2772 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2773 it
->space_width
= Qnil
;
2774 it
->font_height
= Qnil
;
2775 it
->override_ascent
= -1;
2777 /* Are control characters displayed as `^C'? */
2778 it
->ctl_arrow_p
= !NILP (BVAR (current_buffer
, ctl_arrow
));
2780 /* -1 means everything between a CR and the following line end
2781 is invisible. >0 means lines indented more than this value are
2783 it
->selective
= (INTEGERP (BVAR (current_buffer
, selective_display
))
2785 (-1, XINT (BVAR (current_buffer
, selective_display
)),
2787 : (!NILP (BVAR (current_buffer
, selective_display
))
2789 it
->selective_display_ellipsis_p
2790 = !NILP (BVAR (current_buffer
, selective_display_ellipses
));
2792 /* Display table to use. */
2793 it
->dp
= window_display_table (w
);
2795 /* Are multibyte characters enabled in current_buffer? */
2796 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
2798 /* Get the position at which the redisplay_end_trigger hook should
2799 be run, if it is to be run at all. */
2800 if (MARKERP (w
->redisplay_end_trigger
)
2801 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2802 it
->redisplay_end_trigger_charpos
2803 = marker_position (w
->redisplay_end_trigger
);
2804 else if (INTEGERP (w
->redisplay_end_trigger
))
2805 it
->redisplay_end_trigger_charpos
=
2806 clip_to_bounds (PTRDIFF_MIN
, XINT (w
->redisplay_end_trigger
), PTRDIFF_MAX
);
2808 it
->tab_width
= SANE_TAB_WIDTH (current_buffer
);
2810 /* Are lines in the display truncated? */
2811 if (base_face_id
!= DEFAULT_FACE_ID
2813 || (! WINDOW_FULL_WIDTH_P (it
->w
)
2814 && ((!NILP (Vtruncate_partial_width_windows
)
2815 && !INTEGERP (Vtruncate_partial_width_windows
))
2816 || (INTEGERP (Vtruncate_partial_width_windows
)
2817 /* PXW: Shall we do something about this ? */
2818 && (WINDOW_TOTAL_COLS (it
->w
)
2819 < XINT (Vtruncate_partial_width_windows
))))))
2820 it
->line_wrap
= TRUNCATE
;
2821 else if (NILP (BVAR (current_buffer
, truncate_lines
)))
2822 it
->line_wrap
= NILP (BVAR (current_buffer
, word_wrap
))
2823 ? WINDOW_WRAP
: WORD_WRAP
;
2825 it
->line_wrap
= TRUNCATE
;
2827 /* Get dimensions of truncation and continuation glyphs. These are
2828 displayed as fringe bitmaps under X, but we need them for such
2829 frames when the fringes are turned off. But leave the dimensions
2830 zero for tooltip frames, as these glyphs look ugly there and also
2831 sabotage calculations of tooltip dimensions in x-show-tip. */
2832 #ifdef HAVE_WINDOW_SYSTEM
2833 if (!(FRAME_WINDOW_P (it
->f
)
2834 && FRAMEP (tip_frame
)
2835 && it
->f
== XFRAME (tip_frame
)))
2838 if (it
->line_wrap
== TRUNCATE
)
2840 /* We will need the truncation glyph. */
2841 eassert (it
->glyph_row
== NULL
);
2842 produce_special_glyphs (it
, IT_TRUNCATION
);
2843 it
->truncation_pixel_width
= it
->pixel_width
;
2847 /* We will need the continuation glyph. */
2848 eassert (it
->glyph_row
== NULL
);
2849 produce_special_glyphs (it
, IT_CONTINUATION
);
2850 it
->continuation_pixel_width
= it
->pixel_width
;
2854 /* Reset these values to zero because the produce_special_glyphs
2855 above has changed them. */
2856 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2857 it
->phys_ascent
= it
->phys_descent
= 0;
2859 /* Set this after getting the dimensions of truncation and
2860 continuation glyphs, so that we don't produce glyphs when calling
2861 produce_special_glyphs, above. */
2862 it
->glyph_row
= row
;
2863 it
->area
= TEXT_AREA
;
2865 /* Forget any previous info about this row being reversed. */
2867 it
->glyph_row
->reversed_p
= 0;
2869 /* Get the dimensions of the display area. The display area
2870 consists of the visible window area plus a horizontally scrolled
2871 part to the left of the window. All x-values are relative to the
2872 start of this total display area. */
2873 if (base_face_id
!= DEFAULT_FACE_ID
)
2875 /* Mode lines, menu bar in terminal frames. */
2876 it
->first_visible_x
= 0;
2877 it
->last_visible_x
= WINDOW_PIXEL_WIDTH (w
);
2882 = window_hscroll_limited (it
->w
, it
->f
) * FRAME_COLUMN_WIDTH (it
->f
);
2883 it
->last_visible_x
= (it
->first_visible_x
2884 + window_box_width (w
, TEXT_AREA
));
2886 /* If we truncate lines, leave room for the truncation glyph(s) at
2887 the right margin. Otherwise, leave room for the continuation
2888 glyph(s). Done only if the window has no fringes. Since we
2889 don't know at this point whether there will be any R2L lines in
2890 the window, we reserve space for truncation/continuation glyphs
2891 even if only one of the fringes is absent. */
2892 if (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0
2893 || (it
->bidi_p
&& WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0))
2895 if (it
->line_wrap
== TRUNCATE
)
2896 it
->last_visible_x
-= it
->truncation_pixel_width
;
2898 it
->last_visible_x
-= it
->continuation_pixel_width
;
2901 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2902 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2905 /* Leave room for a border glyph. */
2906 if (!FRAME_WINDOW_P (it
->f
)
2907 && !WINDOW_RIGHTMOST_P (it
->w
))
2908 it
->last_visible_x
-= 1;
2910 it
->last_visible_y
= window_text_bottom_y (w
);
2912 /* For mode lines and alike, arrange for the first glyph having a
2913 left box line if the face specifies a box. */
2914 if (base_face_id
!= DEFAULT_FACE_ID
)
2918 it
->face_id
= remapped_base_face_id
;
2920 /* If we have a boxed mode line, make the first character appear
2921 with a left box line. */
2922 face
= FACE_FROM_ID (it
->f
, remapped_base_face_id
);
2923 if (face
->box
!= FACE_NO_BOX
)
2924 it
->start_of_box_run_p
= true;
2927 /* If a buffer position was specified, set the iterator there,
2928 getting overlays and face properties from that position. */
2929 if (charpos
>= BUF_BEG (current_buffer
))
2931 it
->end_charpos
= ZV
;
2932 eassert (charpos
== BYTE_TO_CHAR (bytepos
));
2933 IT_CHARPOS (*it
) = charpos
;
2934 IT_BYTEPOS (*it
) = bytepos
;
2936 /* We will rely on `reseat' to set this up properly, via
2937 handle_face_prop. */
2938 it
->face_id
= it
->base_face_id
;
2940 it
->start
= it
->current
;
2941 /* Do we need to reorder bidirectional text? Not if this is a
2942 unibyte buffer: by definition, none of the single-byte
2943 characters are strong R2L, so no reordering is needed. And
2944 bidi.c doesn't support unibyte buffers anyway. Also, don't
2945 reorder while we are loading loadup.el, since the tables of
2946 character properties needed for reordering are not yet
2950 && !NILP (BVAR (current_buffer
, bidi_display_reordering
))
2953 /* If we are to reorder bidirectional text, init the bidi
2957 /* Note the paragraph direction that this buffer wants to
2959 if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2961 it
->paragraph_embedding
= L2R
;
2962 else if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2964 it
->paragraph_embedding
= R2L
;
2966 it
->paragraph_embedding
= NEUTRAL_DIR
;
2967 bidi_unshelve_cache (NULL
, 0);
2968 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
2972 /* Compute faces etc. */
2973 reseat (it
, it
->current
.pos
, 1);
2980 /* Initialize IT for the display of window W with window start POS. */
2983 start_display (struct it
*it
, struct window
*w
, struct text_pos pos
)
2985 struct glyph_row
*row
;
2986 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2988 row
= w
->desired_matrix
->rows
+ first_vpos
;
2989 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2990 it
->first_vpos
= first_vpos
;
2992 /* Don't reseat to previous visible line start if current start
2993 position is in a string or image. */
2994 if (it
->method
== GET_FROM_BUFFER
&& it
->line_wrap
!= TRUNCATE
)
2996 int start_at_line_beg_p
;
2997 int first_y
= it
->current_y
;
2999 /* If window start is not at a line start, skip forward to POS to
3000 get the correct continuation lines width. */
3001 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
3002 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
3003 if (!start_at_line_beg_p
)
3007 reseat_at_previous_visible_line_start (it
);
3008 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
3010 new_x
= it
->current_x
+ it
->pixel_width
;
3012 /* If lines are continued, this line may end in the middle
3013 of a multi-glyph character (e.g. a control character
3014 displayed as \003, or in the middle of an overlay
3015 string). In this case move_it_to above will not have
3016 taken us to the start of the continuation line but to the
3017 end of the continued line. */
3018 if (it
->current_x
> 0
3019 && it
->line_wrap
!= TRUNCATE
/* Lines are continued. */
3020 && (/* And glyph doesn't fit on the line. */
3021 new_x
> it
->last_visible_x
3022 /* Or it fits exactly and we're on a window
3024 || (new_x
== it
->last_visible_x
3025 && FRAME_WINDOW_P (it
->f
)
3026 && ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
3027 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
3028 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
3030 if ((it
->current
.dpvec_index
>= 0
3031 || it
->current
.overlay_string_index
>= 0)
3032 /* If we are on a newline from a display vector or
3033 overlay string, then we are already at the end of
3034 a screen line; no need to go to the next line in
3035 that case, as this line is not really continued.
3036 (If we do go to the next line, C-e will not DTRT.) */
3039 set_iterator_to_next (it
, 1);
3040 move_it_in_display_line_to (it
, -1, -1, 0);
3043 it
->continuation_lines_width
+= it
->current_x
;
3045 /* If the character at POS is displayed via a display
3046 vector, move_it_to above stops at the final glyph of
3047 IT->dpvec. To make the caller redisplay that character
3048 again (a.k.a. start at POS), we need to reset the
3049 dpvec_index to the beginning of IT->dpvec. */
3050 else if (it
->current
.dpvec_index
>= 0)
3051 it
->current
.dpvec_index
= 0;
3053 /* We're starting a new display line, not affected by the
3054 height of the continued line, so clear the appropriate
3055 fields in the iterator structure. */
3056 it
->max_ascent
= it
->max_descent
= 0;
3057 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
3059 it
->current_y
= first_y
;
3061 it
->current_x
= it
->hpos
= 0;
3067 /* Return 1 if POS is a position in ellipses displayed for invisible
3068 text. W is the window we display, for text property lookup. */
3071 in_ellipses_for_invisible_text_p (struct display_pos
*pos
, struct window
*w
)
3073 Lisp_Object prop
, window
;
3075 ptrdiff_t charpos
= CHARPOS (pos
->pos
);
3077 /* If POS specifies a position in a display vector, this might
3078 be for an ellipsis displayed for invisible text. We won't
3079 get the iterator set up for delivering that ellipsis unless
3080 we make sure that it gets aware of the invisible text. */
3081 if (pos
->dpvec_index
>= 0
3082 && pos
->overlay_string_index
< 0
3083 && CHARPOS (pos
->string_pos
) < 0
3085 && (XSETWINDOW (window
, w
),
3086 prop
= Fget_char_property (make_number (charpos
),
3087 Qinvisible
, window
),
3088 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
3090 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
3092 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
3099 /* Initialize IT for stepping through current_buffer in window W,
3100 starting at position POS that includes overlay string and display
3101 vector/ control character translation position information. Value
3102 is zero if there are overlay strings with newlines at POS. */
3105 init_from_display_pos (struct it
*it
, struct window
*w
, struct display_pos
*pos
)
3107 ptrdiff_t charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
3108 int i
, overlay_strings_with_newlines
= 0;
3110 /* If POS specifies a position in a display vector, this might
3111 be for an ellipsis displayed for invisible text. We won't
3112 get the iterator set up for delivering that ellipsis unless
3113 we make sure that it gets aware of the invisible text. */
3114 if (in_ellipses_for_invisible_text_p (pos
, w
))
3120 /* Keep in mind: the call to reseat in init_iterator skips invisible
3121 text, so we might end up at a position different from POS. This
3122 is only a problem when POS is a row start after a newline and an
3123 overlay starts there with an after-string, and the overlay has an
3124 invisible property. Since we don't skip invisible text in
3125 display_line and elsewhere immediately after consuming the
3126 newline before the row start, such a POS will not be in a string,
3127 but the call to init_iterator below will move us to the
3129 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
3131 /* This only scans the current chunk -- it should scan all chunks.
3132 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
3133 to 16 in 22.1 to make this a lesser problem. */
3134 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
3136 const char *s
= SSDATA (it
->overlay_strings
[i
]);
3137 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
3139 while (s
< e
&& *s
!= '\n')
3144 overlay_strings_with_newlines
= 1;
3149 /* If position is within an overlay string, set up IT to the right
3151 if (pos
->overlay_string_index
>= 0)
3155 /* If the first overlay string happens to have a `display'
3156 property for an image, the iterator will be set up for that
3157 image, and we have to undo that setup first before we can
3158 correct the overlay string index. */
3159 if (it
->method
== GET_FROM_IMAGE
)
3162 /* We already have the first chunk of overlay strings in
3163 IT->overlay_strings. Load more until the one for
3164 pos->overlay_string_index is in IT->overlay_strings. */
3165 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
3167 ptrdiff_t n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
3168 it
->current
.overlay_string_index
= 0;
3171 load_overlay_strings (it
, 0);
3172 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
3176 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
3177 relative_index
= (it
->current
.overlay_string_index
3178 % OVERLAY_STRING_CHUNK_SIZE
);
3179 it
->string
= it
->overlay_strings
[relative_index
];
3180 eassert (STRINGP (it
->string
));
3181 it
->current
.string_pos
= pos
->string_pos
;
3182 it
->method
= GET_FROM_STRING
;
3183 it
->end_charpos
= SCHARS (it
->string
);
3184 /* Set up the bidi iterator for this overlay string. */
3187 it
->bidi_it
.string
.lstring
= it
->string
;
3188 it
->bidi_it
.string
.s
= NULL
;
3189 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
3190 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
3191 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
3192 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
3193 it
->bidi_it
.w
= it
->w
;
3194 bidi_init_it (IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
),
3195 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
3197 /* Synchronize the state of the bidi iterator with
3198 pos->string_pos. For any string position other than
3199 zero, this will be done automagically when we resume
3200 iteration over the string and get_visually_first_element
3201 is called. But if string_pos is zero, and the string is
3202 to be reordered for display, we need to resync manually,
3203 since it could be that the iteration state recorded in
3204 pos ended at string_pos of 0 moving backwards in string. */
3205 if (CHARPOS (pos
->string_pos
) == 0)
3207 get_visually_first_element (it
);
3208 if (IT_STRING_CHARPOS (*it
) != 0)
3211 eassert (it
->bidi_it
.charpos
< it
->bidi_it
.string
.schars
);
3212 bidi_move_to_visually_next (&it
->bidi_it
);
3213 } while (it
->bidi_it
.charpos
!= 0);
3215 eassert (IT_STRING_CHARPOS (*it
) == it
->bidi_it
.charpos
3216 && IT_STRING_BYTEPOS (*it
) == it
->bidi_it
.bytepos
);
3220 if (CHARPOS (pos
->string_pos
) >= 0)
3222 /* Recorded position is not in an overlay string, but in another
3223 string. This can only be a string from a `display' property.
3224 IT should already be filled with that string. */
3225 it
->current
.string_pos
= pos
->string_pos
;
3226 eassert (STRINGP (it
->string
));
3228 bidi_init_it (IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
),
3229 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
3232 /* Restore position in display vector translations, control
3233 character translations or ellipses. */
3234 if (pos
->dpvec_index
>= 0)
3236 if (it
->dpvec
== NULL
)
3237 get_next_display_element (it
);
3238 eassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
3239 it
->current
.dpvec_index
= pos
->dpvec_index
;
3243 return !overlay_strings_with_newlines
;
3247 /* Initialize IT for stepping through current_buffer in window W
3248 starting at ROW->start. */
3251 init_to_row_start (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3253 init_from_display_pos (it
, w
, &row
->start
);
3254 it
->start
= row
->start
;
3255 it
->continuation_lines_width
= row
->continuation_lines_width
;
3260 /* Initialize IT for stepping through current_buffer in window W
3261 starting in the line following ROW, i.e. starting at ROW->end.
3262 Value is zero if there are overlay strings with newlines at ROW's
3266 init_to_row_end (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3270 if (init_from_display_pos (it
, w
, &row
->end
))
3272 if (row
->continued_p
)
3273 it
->continuation_lines_width
3274 = row
->continuation_lines_width
+ row
->pixel_width
;
3285 /***********************************************************************
3287 ***********************************************************************/
3289 /* Called when IT reaches IT->stop_charpos. Handle text property and
3290 overlay changes. Set IT->stop_charpos to the next position where
3294 handle_stop (struct it
*it
)
3296 enum prop_handled handled
;
3297 int handle_overlay_change_p
;
3301 it
->current
.dpvec_index
= -1;
3302 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3303 it
->ignore_overlay_strings_at_pos_p
= 0;
3306 /* Use face of preceding text for ellipsis (if invisible) */
3307 if (it
->selective_display_ellipsis_p
)
3308 it
->saved_face_id
= it
->face_id
;
3312 handled
= HANDLED_NORMALLY
;
3314 /* Call text property handlers. */
3315 for (p
= it_props
; p
->handler
; ++p
)
3317 handled
= p
->handler (it
);
3319 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3321 else if (handled
== HANDLED_RETURN
)
3323 /* We still want to show before and after strings from
3324 overlays even if the actual buffer text is replaced. */
3325 if (!handle_overlay_change_p
3327 /* Don't call get_overlay_strings_1 if we already
3328 have overlay strings loaded, because doing so
3329 will load them again and push the iterator state
3330 onto the stack one more time, which is not
3331 expected by the rest of the code that processes
3333 || (it
->current
.overlay_string_index
< 0
3334 ? !get_overlay_strings_1 (it
, 0, 0)
3338 setup_for_ellipsis (it
, 0);
3339 /* When handling a display spec, we might load an
3340 empty string. In that case, discard it here. We
3341 used to discard it in handle_single_display_spec,
3342 but that causes get_overlay_strings_1, above, to
3343 ignore overlay strings that we must check. */
3344 if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3348 else if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3352 it
->ignore_overlay_strings_at_pos_p
= true;
3353 it
->string_from_display_prop_p
= 0;
3354 it
->from_disp_prop_p
= 0;
3355 handle_overlay_change_p
= 0;
3357 handled
= HANDLED_RECOMPUTE_PROPS
;
3360 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3361 handle_overlay_change_p
= 0;
3364 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3366 /* Don't check for overlay strings below when set to deliver
3367 characters from a display vector. */
3368 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3369 handle_overlay_change_p
= 0;
3371 /* Handle overlay changes.
3372 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
3373 if it finds overlays. */
3374 if (handle_overlay_change_p
)
3375 handled
= handle_overlay_change (it
);
3380 setup_for_ellipsis (it
, 0);
3384 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3386 /* Determine where to stop next. */
3387 if (handled
== HANDLED_NORMALLY
)
3388 compute_stop_pos (it
);
3392 /* Compute IT->stop_charpos from text property and overlay change
3393 information for IT's current position. */
3396 compute_stop_pos (struct it
*it
)
3398 register INTERVAL iv
, next_iv
;
3399 Lisp_Object object
, limit
, position
;
3400 ptrdiff_t charpos
, bytepos
;
3402 if (STRINGP (it
->string
))
3404 /* Strings are usually short, so don't limit the search for
3406 it
->stop_charpos
= it
->end_charpos
;
3407 object
= it
->string
;
3409 charpos
= IT_STRING_CHARPOS (*it
);
3410 bytepos
= IT_STRING_BYTEPOS (*it
);
3416 /* If end_charpos is out of range for some reason, such as a
3417 misbehaving display function, rationalize it (Bug#5984). */
3418 if (it
->end_charpos
> ZV
)
3419 it
->end_charpos
= ZV
;
3420 it
->stop_charpos
= it
->end_charpos
;
3422 /* If next overlay change is in front of the current stop pos
3423 (which is IT->end_charpos), stop there. Note: value of
3424 next_overlay_change is point-max if no overlay change
3426 charpos
= IT_CHARPOS (*it
);
3427 bytepos
= IT_BYTEPOS (*it
);
3428 pos
= next_overlay_change (charpos
);
3429 if (pos
< it
->stop_charpos
)
3430 it
->stop_charpos
= pos
;
3432 /* Set up variables for computing the stop position from text
3433 property changes. */
3434 XSETBUFFER (object
, current_buffer
);
3435 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3438 /* Get the interval containing IT's position. Value is a null
3439 interval if there isn't such an interval. */
3440 position
= make_number (charpos
);
3441 iv
= validate_interval_range (object
, &position
, &position
, 0);
3444 Lisp_Object values_here
[LAST_PROP_IDX
];
3447 /* Get properties here. */
3448 for (p
= it_props
; p
->handler
; ++p
)
3449 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3451 /* Look for an interval following iv that has different
3453 for (next_iv
= next_interval (iv
);
3456 || XFASTINT (limit
) > next_iv
->position
));
3457 next_iv
= next_interval (next_iv
))
3459 for (p
= it_props
; p
->handler
; ++p
)
3461 Lisp_Object new_value
;
3463 new_value
= textget (next_iv
->plist
, *p
->name
);
3464 if (!EQ (values_here
[p
->idx
], new_value
))
3474 if (INTEGERP (limit
)
3475 && next_iv
->position
>= XFASTINT (limit
))
3476 /* No text property change up to limit. */
3477 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3479 /* Text properties change in next_iv. */
3480 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3484 if (it
->cmp_it
.id
< 0)
3486 ptrdiff_t stoppos
= it
->end_charpos
;
3488 if (it
->bidi_p
&& it
->bidi_it
.scan_dir
< 0)
3490 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
,
3491 stoppos
, it
->string
);
3494 eassert (STRINGP (it
->string
)
3495 || (it
->stop_charpos
>= BEGV
3496 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3500 /* Return the position of the next overlay change after POS in
3501 current_buffer. Value is point-max if no overlay change
3502 follows. This is like `next-overlay-change' but doesn't use
3506 next_overlay_change (ptrdiff_t pos
)
3508 ptrdiff_t i
, noverlays
;
3510 Lisp_Object
*overlays
;
3512 /* Get all overlays at the given position. */
3513 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3515 /* If any of these overlays ends before endpos,
3516 use its ending point instead. */
3517 for (i
= 0; i
< noverlays
; ++i
)
3522 oend
= OVERLAY_END (overlays
[i
]);
3523 oendpos
= OVERLAY_POSITION (oend
);
3524 endpos
= min (endpos
, oendpos
);
3530 /* How many characters forward to search for a display property or
3531 display string. Searching too far forward makes the bidi display
3532 sluggish, especially in small windows. */
3533 #define MAX_DISP_SCAN 250
3535 /* Return the character position of a display string at or after
3536 position specified by POSITION. If no display string exists at or
3537 after POSITION, return ZV. A display string is either an overlay
3538 with `display' property whose value is a string, or a `display'
3539 text property whose value is a string. STRING is data about the
3540 string to iterate; if STRING->lstring is nil, we are iterating a
3541 buffer. FRAME_WINDOW_P is non-zero when we are displaying a window
3542 on a GUI frame. DISP_PROP is set to zero if we searched
3543 MAX_DISP_SCAN characters forward without finding any display
3544 strings, non-zero otherwise. It is set to 2 if the display string
3545 uses any kind of `(space ...)' spec that will produce a stretch of
3546 white space in the text area. */
3548 compute_display_string_pos (struct text_pos
*position
,
3549 struct bidi_string_data
*string
,
3551 int frame_window_p
, int *disp_prop
)
3553 /* OBJECT = nil means current buffer. */
3554 Lisp_Object object
, object1
;
3555 Lisp_Object pos
, spec
, limpos
;
3556 int string_p
= (string
&& (STRINGP (string
->lstring
) || string
->s
));
3557 ptrdiff_t eob
= string_p
? string
->schars
: ZV
;
3558 ptrdiff_t begb
= string_p
? 0 : BEGV
;
3559 ptrdiff_t bufpos
, charpos
= CHARPOS (*position
);
3561 (charpos
< eob
- MAX_DISP_SCAN
) ? charpos
+ MAX_DISP_SCAN
: eob
;
3562 struct text_pos tpos
;
3565 if (string
&& STRINGP (string
->lstring
))
3566 object1
= object
= string
->lstring
;
3567 else if (w
&& !string_p
)
3569 XSETWINDOW (object
, w
);
3573 object1
= object
= Qnil
;
3578 /* We don't support display properties whose values are strings
3579 that have display string properties. */
3580 || string
->from_disp_str
3581 /* C strings cannot have display properties. */
3582 || (string
->s
&& !STRINGP (object
)))
3588 /* If the character at CHARPOS is where the display string begins,
3590 pos
= make_number (charpos
);
3591 if (STRINGP (object
))
3592 bufpos
= string
->bufpos
;
3596 if (!NILP (spec
= Fget_char_property (pos
, Qdisplay
, object
))
3598 || !EQ (Fget_char_property (make_number (charpos
- 1), Qdisplay
,
3601 && (rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
, bufpos
,
3609 /* Look forward for the first character with a `display' property
3610 that will replace the underlying text when displayed. */
3611 limpos
= make_number (lim
);
3613 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object1
, limpos
);
3614 CHARPOS (tpos
) = XFASTINT (pos
);
3615 if (CHARPOS (tpos
) >= lim
)
3620 if (STRINGP (object
))
3621 BYTEPOS (tpos
) = string_char_to_byte (object
, CHARPOS (tpos
));
3623 BYTEPOS (tpos
) = CHAR_TO_BYTE (CHARPOS (tpos
));
3624 spec
= Fget_char_property (pos
, Qdisplay
, object
);
3625 if (!STRINGP (object
))
3626 bufpos
= CHARPOS (tpos
);
3627 } while (NILP (spec
)
3628 || !(rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
,
3629 bufpos
, frame_window_p
)));
3633 return CHARPOS (tpos
);
3636 /* Return the character position of the end of the display string that
3637 started at CHARPOS. If there's no display string at CHARPOS,
3638 return -1. A display string is either an overlay with `display'
3639 property whose value is a string or a `display' text property whose
3640 value is a string. */
3642 compute_display_string_end (ptrdiff_t charpos
, struct bidi_string_data
*string
)
3644 /* OBJECT = nil means current buffer. */
3645 Lisp_Object object
=
3646 (string
&& STRINGP (string
->lstring
)) ? string
->lstring
: Qnil
;
3647 Lisp_Object pos
= make_number (charpos
);
3649 (STRINGP (object
) || (string
&& string
->s
)) ? string
->schars
: ZV
;
3651 if (charpos
>= eob
|| (string
->s
&& !STRINGP (object
)))
3654 /* It could happen that the display property or overlay was removed
3655 since we found it in compute_display_string_pos above. One way
3656 this can happen is if JIT font-lock was called (through
3657 handle_fontified_prop), and jit-lock-functions remove text
3658 properties or overlays from the portion of buffer that includes
3659 CHARPOS. Muse mode is known to do that, for example. In this
3660 case, we return -1 to the caller, to signal that no display
3661 string is actually present at CHARPOS. See bidi_fetch_char for
3662 how this is handled.
3664 An alternative would be to never look for display properties past
3665 it->stop_charpos. But neither compute_display_string_pos nor
3666 bidi_fetch_char that calls it know or care where the next
3668 if (NILP (Fget_char_property (pos
, Qdisplay
, object
)))
3671 /* Look forward for the first character where the `display' property
3673 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, Qnil
);
3675 return XFASTINT (pos
);
3680 /***********************************************************************
3682 ***********************************************************************/
3684 /* Handle changes in the `fontified' property of the current buffer by
3685 calling hook functions from Qfontification_functions to fontify
3688 static enum prop_handled
3689 handle_fontified_prop (struct it
*it
)
3691 Lisp_Object prop
, pos
;
3692 enum prop_handled handled
= HANDLED_NORMALLY
;
3694 if (!NILP (Vmemory_full
))
3697 /* Get the value of the `fontified' property at IT's current buffer
3698 position. (The `fontified' property doesn't have a special
3699 meaning in strings.) If the value is nil, call functions from
3700 Qfontification_functions. */
3701 if (!STRINGP (it
->string
)
3703 && !NILP (Vfontification_functions
)
3704 && !NILP (Vrun_hooks
)
3705 && (pos
= make_number (IT_CHARPOS (*it
)),
3706 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3707 /* Ignore the special cased nil value always present at EOB since
3708 no amount of fontifying will be able to change it. */
3709 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3711 ptrdiff_t count
= SPECPDL_INDEX ();
3713 struct buffer
*obuf
= current_buffer
;
3714 ptrdiff_t begv
= BEGV
, zv
= ZV
;
3715 bool old_clip_changed
= current_buffer
->clip_changed
;
3717 val
= Vfontification_functions
;
3718 specbind (Qfontification_functions
, Qnil
);
3720 eassert (it
->end_charpos
== ZV
);
3722 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3723 safe_call1 (val
, pos
);
3726 Lisp_Object fns
, fn
;
3727 struct gcpro gcpro1
, gcpro2
;
3732 for (; CONSP (val
); val
= XCDR (val
))
3738 /* A value of t indicates this hook has a local
3739 binding; it means to run the global binding too.
3740 In a global value, t should not occur. If it
3741 does, we must ignore it to avoid an endless
3743 for (fns
= Fdefault_value (Qfontification_functions
);
3749 safe_call1 (fn
, pos
);
3753 safe_call1 (fn
, pos
);
3759 unbind_to (count
, Qnil
);
3761 /* Fontification functions routinely call `save-restriction'.
3762 Normally, this tags clip_changed, which can confuse redisplay
3763 (see discussion in Bug#6671). Since we don't perform any
3764 special handling of fontification changes in the case where
3765 `save-restriction' isn't called, there's no point doing so in
3766 this case either. So, if the buffer's restrictions are
3767 actually left unchanged, reset clip_changed. */
3768 if (obuf
== current_buffer
)
3770 if (begv
== BEGV
&& zv
== ZV
)
3771 current_buffer
->clip_changed
= old_clip_changed
;
3773 /* There isn't much we can reasonably do to protect against
3774 misbehaving fontification, but here's a fig leaf. */
3775 else if (BUFFER_LIVE_P (obuf
))
3776 set_buffer_internal_1 (obuf
);
3778 /* The fontification code may have added/removed text.
3779 It could do even a lot worse, but let's at least protect against
3780 the most obvious case where only the text past `pos' gets changed',
3781 as is/was done in grep.el where some escapes sequences are turned
3782 into face properties (bug#7876). */
3783 it
->end_charpos
= ZV
;
3785 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3786 something. This avoids an endless loop if they failed to
3787 fontify the text for which reason ever. */
3788 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3789 handled
= HANDLED_RECOMPUTE_PROPS
;
3797 /***********************************************************************
3799 ***********************************************************************/
3801 /* Set up iterator IT from face properties at its current position.
3802 Called from handle_stop. */
3804 static enum prop_handled
3805 handle_face_prop (struct it
*it
)
3808 ptrdiff_t next_stop
;
3810 if (!STRINGP (it
->string
))
3813 = face_at_buffer_position (it
->w
,
3817 + TEXT_PROP_DISTANCE_LIMIT
),
3818 0, it
->base_face_id
);
3820 /* Is this a start of a run of characters with box face?
3821 Caveat: this can be called for a freshly initialized
3822 iterator; face_id is -1 in this case. We know that the new
3823 face will not change until limit, i.e. if the new face has a
3824 box, all characters up to limit will have one. But, as
3825 usual, we don't know whether limit is really the end. */
3826 if (new_face_id
!= it
->face_id
)
3828 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3829 /* If it->face_id is -1, old_face below will be NULL, see
3830 the definition of FACE_FROM_ID. This will happen if this
3831 is the initial call that gets the face. */
3832 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3834 /* If the value of face_id of the iterator is -1, we have to
3835 look in front of IT's position and see whether there is a
3836 face there that's different from new_face_id. */
3837 if (!old_face
&& IT_CHARPOS (*it
) > BEG
)
3839 int prev_face_id
= face_before_it_pos (it
);
3841 old_face
= FACE_FROM_ID (it
->f
, prev_face_id
);
3844 /* If the new face has a box, but the old face does not,
3845 this is the start of a run of characters with box face,
3846 i.e. this character has a shadow on the left side. */
3847 it
->start_of_box_run_p
= (new_face
->box
!= FACE_NO_BOX
3848 && (old_face
== NULL
|| !old_face
->box
));
3849 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3857 Lisp_Object from_overlay
3858 = (it
->current
.overlay_string_index
>= 0
3859 ? it
->string_overlays
[it
->current
.overlay_string_index
3860 % OVERLAY_STRING_CHUNK_SIZE
]
3863 /* See if we got to this string directly or indirectly from
3864 an overlay property. That includes the before-string or
3865 after-string of an overlay, strings in display properties
3866 provided by an overlay, their text properties, etc.
3868 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3869 if (! NILP (from_overlay
))
3870 for (i
= it
->sp
- 1; i
>= 0; i
--)
3872 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3874 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
3875 % OVERLAY_STRING_CHUNK_SIZE
];
3876 else if (! NILP (it
->stack
[i
].from_overlay
))
3877 from_overlay
= it
->stack
[i
].from_overlay
;
3879 if (!NILP (from_overlay
))
3883 if (! NILP (from_overlay
))
3885 bufpos
= IT_CHARPOS (*it
);
3886 /* For a string from an overlay, the base face depends
3887 only on text properties and ignores overlays. */
3889 = face_for_overlay_string (it
->w
,
3893 + TEXT_PROP_DISTANCE_LIMIT
),
3901 /* For strings from a `display' property, use the face at
3902 IT's current buffer position as the base face to merge
3903 with, so that overlay strings appear in the same face as
3904 surrounding text, unless they specify their own faces.
3905 For strings from wrap-prefix and line-prefix properties,
3906 use the default face, possibly remapped via
3907 Vface_remapping_alist. */
3908 base_face_id
= it
->string_from_prefix_prop_p
3909 ? (!NILP (Vface_remapping_alist
)
3910 ? lookup_basic_face (it
->f
, DEFAULT_FACE_ID
)
3912 : underlying_face_id (it
);
3915 new_face_id
= face_at_string_position (it
->w
,
3917 IT_STRING_CHARPOS (*it
),
3922 /* Is this a start of a run of characters with box? Caveat:
3923 this can be called for a freshly allocated iterator; face_id
3924 is -1 is this case. We know that the new face will not
3925 change until the next check pos, i.e. if the new face has a
3926 box, all characters up to that position will have a
3927 box. But, as usual, we don't know whether that position
3928 is really the end. */
3929 if (new_face_id
!= it
->face_id
)
3931 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3932 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3934 /* If new face has a box but old face hasn't, this is the
3935 start of a run of characters with box, i.e. it has a
3936 shadow on the left side. */
3937 it
->start_of_box_run_p
3938 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3939 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3943 it
->face_id
= new_face_id
;
3944 return HANDLED_NORMALLY
;
3948 /* Return the ID of the face ``underlying'' IT's current position,
3949 which is in a string. If the iterator is associated with a
3950 buffer, return the face at IT's current buffer position.
3951 Otherwise, use the iterator's base_face_id. */
3954 underlying_face_id (struct it
*it
)
3956 int face_id
= it
->base_face_id
, i
;
3958 eassert (STRINGP (it
->string
));
3960 for (i
= it
->sp
- 1; i
>= 0; --i
)
3961 if (NILP (it
->stack
[i
].string
))
3962 face_id
= it
->stack
[i
].face_id
;
3968 /* Compute the face one character before or after the current position
3969 of IT, in the visual order. BEFORE_P non-zero means get the face
3970 in front (to the left in L2R paragraphs, to the right in R2L
3971 paragraphs) of IT's screen position. Value is the ID of the face. */
3974 face_before_or_after_it_pos (struct it
*it
, int before_p
)
3977 ptrdiff_t next_check_charpos
;
3979 void *it_copy_data
= NULL
;
3981 eassert (it
->s
== NULL
);
3983 if (STRINGP (it
->string
))
3985 ptrdiff_t bufpos
, charpos
;
3988 /* No face change past the end of the string (for the case
3989 we are padding with spaces). No face change before the
3991 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3992 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3997 /* Set charpos to the position before or after IT's current
3998 position, in the logical order, which in the non-bidi
3999 case is the same as the visual order. */
4001 charpos
= IT_STRING_CHARPOS (*it
) - 1;
4002 else if (it
->what
== IT_COMPOSITION
)
4003 /* For composition, we must check the character after the
4005 charpos
= IT_STRING_CHARPOS (*it
) + it
->cmp_it
.nchars
;
4007 charpos
= IT_STRING_CHARPOS (*it
) + 1;
4013 /* With bidi iteration, the character before the current
4014 in the visual order cannot be found by simple
4015 iteration, because "reverse" reordering is not
4016 supported. Instead, we need to use the move_it_*
4017 family of functions. */
4018 /* Ignore face changes before the first visible
4019 character on this display line. */
4020 if (it
->current_x
<= it
->first_visible_x
)
4022 SAVE_IT (it_copy
, *it
, it_copy_data
);
4023 /* Implementation note: Since move_it_in_display_line
4024 works in the iterator geometry, and thinks the first
4025 character is always the leftmost, even in R2L lines,
4026 we don't need to distinguish between the R2L and L2R
4028 move_it_in_display_line (&it_copy
, SCHARS (it_copy
.string
),
4029 it_copy
.current_x
- 1, MOVE_TO_X
);
4030 charpos
= IT_STRING_CHARPOS (it_copy
);
4031 RESTORE_IT (it
, it
, it_copy_data
);
4035 /* Set charpos to the string position of the character
4036 that comes after IT's current position in the visual
4038 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
4042 bidi_move_to_visually_next (&it_copy
.bidi_it
);
4044 charpos
= it_copy
.bidi_it
.charpos
;
4047 eassert (0 <= charpos
&& charpos
<= SCHARS (it
->string
));
4049 if (it
->current
.overlay_string_index
>= 0)
4050 bufpos
= IT_CHARPOS (*it
);
4054 base_face_id
= underlying_face_id (it
);
4056 /* Get the face for ASCII, or unibyte. */
4057 face_id
= face_at_string_position (it
->w
,
4061 &next_check_charpos
,
4064 /* Correct the face for charsets different from ASCII. Do it
4065 for the multibyte case only. The face returned above is
4066 suitable for unibyte text if IT->string is unibyte. */
4067 if (STRING_MULTIBYTE (it
->string
))
4069 struct text_pos pos1
= string_pos (charpos
, it
->string
);
4070 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos1
);
4072 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
4074 c
= string_char_and_length (p
, &len
);
4075 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, charpos
, it
->string
);
4080 struct text_pos pos
;
4082 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
4083 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
4086 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
4087 pos
= it
->current
.pos
;
4092 DEC_TEXT_POS (pos
, it
->multibyte_p
);
4095 if (it
->what
== IT_COMPOSITION
)
4097 /* For composition, we must check the position after
4099 pos
.charpos
+= it
->cmp_it
.nchars
;
4100 pos
.bytepos
+= it
->len
;
4103 INC_TEXT_POS (pos
, it
->multibyte_p
);
4110 /* With bidi iteration, the character before the current
4111 in the visual order cannot be found by simple
4112 iteration, because "reverse" reordering is not
4113 supported. Instead, we need to use the move_it_*
4114 family of functions. */
4115 /* Ignore face changes before the first visible
4116 character on this display line. */
4117 if (it
->current_x
<= it
->first_visible_x
)
4119 SAVE_IT (it_copy
, *it
, it_copy_data
);
4120 /* Implementation note: Since move_it_in_display_line
4121 works in the iterator geometry, and thinks the first
4122 character is always the leftmost, even in R2L lines,
4123 we don't need to distinguish between the R2L and L2R
4125 move_it_in_display_line (&it_copy
, ZV
,
4126 it_copy
.current_x
- 1, MOVE_TO_X
);
4127 pos
= it_copy
.current
.pos
;
4128 RESTORE_IT (it
, it
, it_copy_data
);
4132 /* Set charpos to the buffer position of the character
4133 that comes after IT's current position in the visual
4135 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
4139 bidi_move_to_visually_next (&it_copy
.bidi_it
);
4142 it_copy
.bidi_it
.charpos
, it_copy
.bidi_it
.bytepos
);
4145 eassert (BEGV
<= CHARPOS (pos
) && CHARPOS (pos
) <= ZV
);
4147 /* Determine face for CHARSET_ASCII, or unibyte. */
4148 face_id
= face_at_buffer_position (it
->w
,
4150 &next_check_charpos
,
4153 /* Correct the face for charsets different from ASCII. Do it
4154 for the multibyte case only. The face returned above is
4155 suitable for unibyte text if current_buffer is unibyte. */
4156 if (it
->multibyte_p
)
4158 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
4159 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
4160 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
4169 /***********************************************************************
4171 ***********************************************************************/
4173 /* Set up iterator IT from invisible properties at its current
4174 position. Called from handle_stop. */
4176 static enum prop_handled
4177 handle_invisible_prop (struct it
*it
)
4179 enum prop_handled handled
= HANDLED_NORMALLY
;
4183 if (STRINGP (it
->string
))
4185 Lisp_Object end_charpos
, limit
, charpos
;
4187 /* Get the value of the invisible text property at the
4188 current position. Value will be nil if there is no such
4190 charpos
= make_number (IT_STRING_CHARPOS (*it
));
4191 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
4192 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4194 if (invis_p
&& IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
4196 /* Record whether we have to display an ellipsis for the
4198 int display_ellipsis_p
= (invis_p
== 2);
4199 ptrdiff_t len
, endpos
;
4201 handled
= HANDLED_RECOMPUTE_PROPS
;
4203 /* Get the position at which the next visible text can be
4204 found in IT->string, if any. */
4205 endpos
= len
= SCHARS (it
->string
);
4206 XSETINT (limit
, len
);
4209 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
4211 if (INTEGERP (end_charpos
))
4213 endpos
= XFASTINT (end_charpos
);
4214 prop
= Fget_text_property (end_charpos
, Qinvisible
, it
->string
);
4215 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4217 display_ellipsis_p
= true;
4220 while (invis_p
&& endpos
< len
);
4222 if (display_ellipsis_p
)
4223 it
->ellipsis_p
= true;
4227 /* Text at END_CHARPOS is visible. Move IT there. */
4228 struct text_pos old
;
4231 old
= it
->current
.string_pos
;
4232 oldpos
= CHARPOS (old
);
4235 if (it
->bidi_it
.first_elt
4236 && it
->bidi_it
.charpos
< SCHARS (it
->string
))
4237 bidi_paragraph_init (it
->paragraph_embedding
,
4239 /* Bidi-iterate out of the invisible text. */
4242 bidi_move_to_visually_next (&it
->bidi_it
);
4244 while (oldpos
<= it
->bidi_it
.charpos
4245 && it
->bidi_it
.charpos
< endpos
);
4247 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4248 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4249 if (IT_CHARPOS (*it
) >= endpos
)
4250 it
->prev_stop
= endpos
;
4254 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
4255 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
4260 /* The rest of the string is invisible. If this is an
4261 overlay string, proceed with the next overlay string
4262 or whatever comes and return a character from there. */
4263 if (it
->current
.overlay_string_index
>= 0
4264 && !display_ellipsis_p
)
4266 next_overlay_string (it
);
4267 /* Don't check for overlay strings when we just
4268 finished processing them. */
4269 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
4273 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
4274 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
4281 ptrdiff_t newpos
, next_stop
, start_charpos
, tem
;
4282 Lisp_Object pos
, overlay
;
4284 /* First of all, is there invisible text at this position? */
4285 tem
= start_charpos
= IT_CHARPOS (*it
);
4286 pos
= make_number (tem
);
4287 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
4289 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4291 /* If we are on invisible text, skip over it. */
4292 if (invis_p
&& start_charpos
< it
->end_charpos
)
4294 /* Record whether we have to display an ellipsis for the
4296 int display_ellipsis_p
= invis_p
== 2;
4298 handled
= HANDLED_RECOMPUTE_PROPS
;
4300 /* Loop skipping over invisible text. The loop is left at
4301 ZV or with IT on the first char being visible again. */
4304 /* Try to skip some invisible text. Return value is the
4305 position reached which can be equal to where we start
4306 if there is nothing invisible there. This skips both
4307 over invisible text properties and overlays with
4308 invisible property. */
4309 newpos
= skip_invisible (tem
, &next_stop
, ZV
, it
->window
);
4311 /* If we skipped nothing at all we weren't at invisible
4312 text in the first place. If everything to the end of
4313 the buffer was skipped, end the loop. */
4314 if (newpos
== tem
|| newpos
>= ZV
)
4318 /* We skipped some characters but not necessarily
4319 all there are. Check if we ended up on visible
4320 text. Fget_char_property returns the property of
4321 the char before the given position, i.e. if we
4322 get invis_p = 0, this means that the char at
4323 newpos is visible. */
4324 pos
= make_number (newpos
);
4325 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
4326 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4329 /* If we ended up on invisible text, proceed to
4330 skip starting with next_stop. */
4334 /* If there are adjacent invisible texts, don't lose the
4335 second one's ellipsis. */
4337 display_ellipsis_p
= true;
4341 /* The position newpos is now either ZV or on visible text. */
4344 ptrdiff_t bpos
= CHAR_TO_BYTE (newpos
);
4346 = bpos
== ZV_BYTE
|| FETCH_BYTE (bpos
) == '\n';
4348 = newpos
<= BEGV
|| FETCH_BYTE (bpos
- 1) == '\n';
4350 /* If the invisible text ends on a newline or on a
4351 character after a newline, we can avoid the costly,
4352 character by character, bidi iteration to NEWPOS, and
4353 instead simply reseat the iterator there. That's
4354 because all bidi reordering information is tossed at
4355 the newline. This is a big win for modes that hide
4356 complete lines, like Outline, Org, etc. */
4357 if (on_newline
|| after_newline
)
4359 struct text_pos tpos
;
4360 bidi_dir_t pdir
= it
->bidi_it
.paragraph_dir
;
4362 SET_TEXT_POS (tpos
, newpos
, bpos
);
4363 reseat_1 (it
, tpos
, 0);
4364 /* If we reseat on a newline/ZV, we need to prep the
4365 bidi iterator for advancing to the next character
4366 after the newline/EOB, keeping the current paragraph
4367 direction (so that PRODUCE_GLYPHS does TRT wrt
4368 prepending/appending glyphs to a glyph row). */
4371 it
->bidi_it
.first_elt
= 0;
4372 it
->bidi_it
.paragraph_dir
= pdir
;
4373 it
->bidi_it
.ch
= (bpos
== ZV_BYTE
) ? -1 : '\n';
4374 it
->bidi_it
.nchars
= 1;
4375 it
->bidi_it
.ch_len
= 1;
4378 else /* Must use the slow method. */
4380 /* With bidi iteration, the region of invisible text
4381 could start and/or end in the middle of a
4382 non-base embedding level. Therefore, we need to
4383 skip invisible text using the bidi iterator,
4384 starting at IT's current position, until we find
4385 ourselves outside of the invisible text.
4386 Skipping invisible text _after_ bidi iteration
4387 avoids affecting the visual order of the
4388 displayed text when invisible properties are
4389 added or removed. */
4390 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< ZV
)
4392 /* If we were `reseat'ed to a new paragraph,
4393 determine the paragraph base direction. We
4394 need to do it now because
4395 next_element_from_buffer may not have a
4396 chance to do it, if we are going to skip any
4397 text at the beginning, which resets the
4399 bidi_paragraph_init (it
->paragraph_embedding
,
4404 bidi_move_to_visually_next (&it
->bidi_it
);
4406 while (it
->stop_charpos
<= it
->bidi_it
.charpos
4407 && it
->bidi_it
.charpos
< newpos
);
4408 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4409 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4410 /* If we overstepped NEWPOS, record its position in
4411 the iterator, so that we skip invisible text if
4412 later the bidi iteration lands us in the
4413 invisible region again. */
4414 if (IT_CHARPOS (*it
) >= newpos
)
4415 it
->prev_stop
= newpos
;
4420 IT_CHARPOS (*it
) = newpos
;
4421 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
4424 /* If there are before-strings at the start of invisible
4425 text, and the text is invisible because of a text
4426 property, arrange to show before-strings because 20.x did
4427 it that way. (If the text is invisible because of an
4428 overlay property instead of a text property, this is
4429 already handled in the overlay code.) */
4431 && get_overlay_strings (it
, it
->stop_charpos
))
4433 handled
= HANDLED_RECOMPUTE_PROPS
;
4434 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
4436 else if (display_ellipsis_p
)
4438 /* Make sure that the glyphs of the ellipsis will get
4439 correct `charpos' values. If we would not update
4440 it->position here, the glyphs would belong to the
4441 last visible character _before_ the invisible
4442 text, which confuses `set_cursor_from_row'.
4444 We use the last invisible position instead of the
4445 first because this way the cursor is always drawn on
4446 the first "." of the ellipsis, whenever PT is inside
4447 the invisible text. Otherwise the cursor would be
4448 placed _after_ the ellipsis when the point is after the
4449 first invisible character. */
4450 if (!STRINGP (it
->object
))
4452 it
->position
.charpos
= newpos
- 1;
4453 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
4455 it
->ellipsis_p
= true;
4456 /* Let the ellipsis display before
4457 considering any properties of the following char.
4458 Fixes jasonr@gnu.org 01 Oct 07 bug. */
4459 handled
= HANDLED_RETURN
;
4468 /* Make iterator IT return `...' next.
4469 Replaces LEN characters from buffer. */
4472 setup_for_ellipsis (struct it
*it
, int len
)
4474 /* Use the display table definition for `...'. Invalid glyphs
4475 will be handled by the method returning elements from dpvec. */
4476 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
4478 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
4479 it
->dpvec
= v
->contents
;
4480 it
->dpend
= v
->contents
+ v
->header
.size
;
4484 /* Default `...'. */
4485 it
->dpvec
= default_invis_vector
;
4486 it
->dpend
= default_invis_vector
+ 3;
4489 it
->dpvec_char_len
= len
;
4490 it
->current
.dpvec_index
= 0;
4491 it
->dpvec_face_id
= -1;
4493 /* Remember the current face id in case glyphs specify faces.
4494 IT's face is restored in set_iterator_to_next.
4495 saved_face_id was set to preceding char's face in handle_stop. */
4496 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
4497 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
4499 it
->method
= GET_FROM_DISPLAY_VECTOR
;
4500 it
->ellipsis_p
= true;
4505 /***********************************************************************
4507 ***********************************************************************/
4509 /* Set up iterator IT from `display' property at its current position.
4510 Called from handle_stop.
4511 We return HANDLED_RETURN if some part of the display property
4512 overrides the display of the buffer text itself.
4513 Otherwise we return HANDLED_NORMALLY. */
4515 static enum prop_handled
4516 handle_display_prop (struct it
*it
)
4518 Lisp_Object propval
, object
, overlay
;
4519 struct text_pos
*position
;
4521 /* Nonzero if some property replaces the display of the text itself. */
4522 int display_replaced_p
= 0;
4524 if (STRINGP (it
->string
))
4526 object
= it
->string
;
4527 position
= &it
->current
.string_pos
;
4528 bufpos
= CHARPOS (it
->current
.pos
);
4532 XSETWINDOW (object
, it
->w
);
4533 position
= &it
->current
.pos
;
4534 bufpos
= CHARPOS (*position
);
4537 /* Reset those iterator values set from display property values. */
4538 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
4539 it
->space_width
= Qnil
;
4540 it
->font_height
= Qnil
;
4543 /* We don't support recursive `display' properties, i.e. string
4544 values that have a string `display' property, that have a string
4545 `display' property etc. */
4546 if (!it
->string_from_display_prop_p
)
4547 it
->area
= TEXT_AREA
;
4549 propval
= get_char_property_and_overlay (make_number (position
->charpos
),
4550 Qdisplay
, object
, &overlay
);
4552 return HANDLED_NORMALLY
;
4553 /* Now OVERLAY is the overlay that gave us this property, or nil
4554 if it was a text property. */
4556 if (!STRINGP (it
->string
))
4557 object
= it
->w
->contents
;
4559 display_replaced_p
= handle_display_spec (it
, propval
, object
, overlay
,
4561 FRAME_WINDOW_P (it
->f
));
4563 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
4566 /* Subroutine of handle_display_prop. Returns non-zero if the display
4567 specification in SPEC is a replacing specification, i.e. it would
4568 replace the text covered by `display' property with something else,
4569 such as an image or a display string. If SPEC includes any kind or
4570 `(space ...) specification, the value is 2; this is used by
4571 compute_display_string_pos, which see.
4573 See handle_single_display_spec for documentation of arguments.
4574 frame_window_p is non-zero if the window being redisplayed is on a
4575 GUI frame; this argument is used only if IT is NULL, see below.
4577 IT can be NULL, if this is called by the bidi reordering code
4578 through compute_display_string_pos, which see. In that case, this
4579 function only examines SPEC, but does not otherwise "handle" it, in
4580 the sense that it doesn't set up members of IT from the display
4583 handle_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4584 Lisp_Object overlay
, struct text_pos
*position
,
4585 ptrdiff_t bufpos
, int frame_window_p
)
4587 int replacing_p
= 0;
4591 /* Simple specifications. */
4592 && !EQ (XCAR (spec
), Qimage
)
4593 && !EQ (XCAR (spec
), Qspace
)
4594 && !EQ (XCAR (spec
), Qwhen
)
4595 && !EQ (XCAR (spec
), Qslice
)
4596 && !EQ (XCAR (spec
), Qspace_width
)
4597 && !EQ (XCAR (spec
), Qheight
)
4598 && !EQ (XCAR (spec
), Qraise
)
4599 /* Marginal area specifications. */
4600 && !(CONSP (XCAR (spec
)) && EQ (XCAR (XCAR (spec
)), Qmargin
))
4601 && !EQ (XCAR (spec
), Qleft_fringe
)
4602 && !EQ (XCAR (spec
), Qright_fringe
)
4603 && !NILP (XCAR (spec
)))
4605 for (; CONSP (spec
); spec
= XCDR (spec
))
4607 if ((rv
= handle_single_display_spec (it
, XCAR (spec
), object
,
4608 overlay
, position
, bufpos
,
4609 replacing_p
, frame_window_p
)))
4612 /* If some text in a string is replaced, `position' no
4613 longer points to the position of `object'. */
4614 if (!it
|| STRINGP (object
))
4619 else if (VECTORP (spec
))
4622 for (i
= 0; i
< ASIZE (spec
); ++i
)
4623 if ((rv
= handle_single_display_spec (it
, AREF (spec
, i
), object
,
4624 overlay
, position
, bufpos
,
4625 replacing_p
, frame_window_p
)))
4628 /* If some text in a string is replaced, `position' no
4629 longer points to the position of `object'. */
4630 if (!it
|| STRINGP (object
))
4636 if ((rv
= handle_single_display_spec (it
, spec
, object
, overlay
,
4637 position
, bufpos
, 0,
4645 /* Value is the position of the end of the `display' property starting
4646 at START_POS in OBJECT. */
4648 static struct text_pos
4649 display_prop_end (struct it
*it
, Lisp_Object object
, struct text_pos start_pos
)
4652 struct text_pos end_pos
;
4654 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
4655 Qdisplay
, object
, Qnil
);
4656 CHARPOS (end_pos
) = XFASTINT (end
);
4657 if (STRINGP (object
))
4658 compute_string_pos (&end_pos
, start_pos
, it
->string
);
4660 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
4666 /* Set up IT from a single `display' property specification SPEC. OBJECT
4667 is the object in which the `display' property was found. *POSITION
4668 is the position in OBJECT at which the `display' property was found.
4669 BUFPOS is the buffer position of OBJECT (different from POSITION if
4670 OBJECT is not a buffer). DISPLAY_REPLACED_P non-zero means that we
4671 previously saw a display specification which already replaced text
4672 display with something else, for example an image; we ignore such
4673 properties after the first one has been processed.
4675 OVERLAY is the overlay this `display' property came from,
4676 or nil if it was a text property.
4678 If SPEC is a `space' or `image' specification, and in some other
4679 cases too, set *POSITION to the position where the `display'
4682 If IT is NULL, only examine the property specification in SPEC, but
4683 don't set up IT. In that case, FRAME_WINDOW_P non-zero means SPEC
4684 is intended to be displayed in a window on a GUI frame.
4686 Value is non-zero if something was found which replaces the display
4687 of buffer or string text. */
4690 handle_single_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4691 Lisp_Object overlay
, struct text_pos
*position
,
4692 ptrdiff_t bufpos
, int display_replaced_p
,
4696 Lisp_Object location
, value
;
4697 struct text_pos start_pos
= *position
;
4700 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
4701 If the result is non-nil, use VALUE instead of SPEC. */
4703 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4712 if (!NILP (form
) && !EQ (form
, Qt
))
4714 ptrdiff_t count
= SPECPDL_INDEX ();
4715 struct gcpro gcpro1
;
4717 /* Bind `object' to the object having the `display' property, a
4718 buffer or string. Bind `position' to the position in the
4719 object where the property was found, and `buffer-position'
4720 to the current position in the buffer. */
4723 XSETBUFFER (object
, current_buffer
);
4724 specbind (Qobject
, object
);
4725 specbind (Qposition
, make_number (CHARPOS (*position
)));
4726 specbind (Qbuffer_position
, make_number (bufpos
));
4728 form
= safe_eval (form
);
4730 unbind_to (count
, Qnil
);
4736 /* Handle `(height HEIGHT)' specifications. */
4738 && EQ (XCAR (spec
), Qheight
)
4739 && CONSP (XCDR (spec
)))
4743 if (!FRAME_WINDOW_P (it
->f
))
4746 it
->font_height
= XCAR (XCDR (spec
));
4747 if (!NILP (it
->font_height
))
4749 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4750 int new_height
= -1;
4752 if (CONSP (it
->font_height
)
4753 && (EQ (XCAR (it
->font_height
), Qplus
)
4754 || EQ (XCAR (it
->font_height
), Qminus
))
4755 && CONSP (XCDR (it
->font_height
))
4756 && RANGED_INTEGERP (0, XCAR (XCDR (it
->font_height
)), INT_MAX
))
4758 /* `(+ N)' or `(- N)' where N is an integer. */
4759 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4760 if (EQ (XCAR (it
->font_height
), Qplus
))
4762 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4764 else if (FUNCTIONP (it
->font_height
))
4766 /* Call function with current height as argument.
4767 Value is the new height. */
4769 height
= safe_call1 (it
->font_height
,
4770 face
->lface
[LFACE_HEIGHT_INDEX
]);
4771 if (NUMBERP (height
))
4772 new_height
= XFLOATINT (height
);
4774 else if (NUMBERP (it
->font_height
))
4776 /* Value is a multiple of the canonical char height. */
4779 f
= FACE_FROM_ID (it
->f
,
4780 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4781 new_height
= (XFLOATINT (it
->font_height
)
4782 * XINT (f
->lface
[LFACE_HEIGHT_INDEX
]));
4786 /* Evaluate IT->font_height with `height' bound to the
4787 current specified height to get the new height. */
4788 ptrdiff_t count
= SPECPDL_INDEX ();
4790 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4791 value
= safe_eval (it
->font_height
);
4792 unbind_to (count
, Qnil
);
4794 if (NUMBERP (value
))
4795 new_height
= XFLOATINT (value
);
4799 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4806 /* Handle `(space-width WIDTH)'. */
4808 && EQ (XCAR (spec
), Qspace_width
)
4809 && CONSP (XCDR (spec
)))
4813 if (!FRAME_WINDOW_P (it
->f
))
4816 value
= XCAR (XCDR (spec
));
4817 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4818 it
->space_width
= value
;
4824 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4826 && EQ (XCAR (spec
), Qslice
))
4832 if (!FRAME_WINDOW_P (it
->f
))
4835 if (tem
= XCDR (spec
), CONSP (tem
))
4837 it
->slice
.x
= XCAR (tem
);
4838 if (tem
= XCDR (tem
), CONSP (tem
))
4840 it
->slice
.y
= XCAR (tem
);
4841 if (tem
= XCDR (tem
), CONSP (tem
))
4843 it
->slice
.width
= XCAR (tem
);
4844 if (tem
= XCDR (tem
), CONSP (tem
))
4845 it
->slice
.height
= XCAR (tem
);
4854 /* Handle `(raise FACTOR)'. */
4856 && EQ (XCAR (spec
), Qraise
)
4857 && CONSP (XCDR (spec
)))
4861 if (!FRAME_WINDOW_P (it
->f
))
4864 #ifdef HAVE_WINDOW_SYSTEM
4865 value
= XCAR (XCDR (spec
));
4866 if (NUMBERP (value
))
4868 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4869 it
->voffset
= - (XFLOATINT (value
)
4870 * (FONT_HEIGHT (face
->font
)));
4872 #endif /* HAVE_WINDOW_SYSTEM */
4878 /* Don't handle the other kinds of display specifications
4879 inside a string that we got from a `display' property. */
4880 if (it
&& it
->string_from_display_prop_p
)
4883 /* Characters having this form of property are not displayed, so
4884 we have to find the end of the property. */
4887 start_pos
= *position
;
4888 *position
= display_prop_end (it
, object
, start_pos
);
4892 /* Stop the scan at that end position--we assume that all
4893 text properties change there. */
4895 it
->stop_charpos
= position
->charpos
;
4897 /* Handle `(left-fringe BITMAP [FACE])'
4898 and `(right-fringe BITMAP [FACE])'. */
4900 && (EQ (XCAR (spec
), Qleft_fringe
)
4901 || EQ (XCAR (spec
), Qright_fringe
))
4902 && CONSP (XCDR (spec
)))
4908 if (!FRAME_WINDOW_P (it
->f
))
4909 /* If we return here, POSITION has been advanced
4910 across the text with this property. */
4912 /* Synchronize the bidi iterator with POSITION. This is
4913 needed because we are not going to push the iterator
4914 on behalf of this display property, so there will be
4915 no pop_it call to do this synchronization for us. */
4918 it
->position
= *position
;
4919 iterate_out_of_display_property (it
);
4920 *position
= it
->position
;
4925 else if (!frame_window_p
)
4928 #ifdef HAVE_WINDOW_SYSTEM
4929 value
= XCAR (XCDR (spec
));
4930 if (!SYMBOLP (value
)
4931 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4932 /* If we return here, POSITION has been advanced
4933 across the text with this property. */
4935 if (it
&& it
->bidi_p
)
4937 it
->position
= *position
;
4938 iterate_out_of_display_property (it
);
4939 *position
= it
->position
;
4946 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);;
4948 if (CONSP (XCDR (XCDR (spec
))))
4950 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4951 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4957 /* Save current settings of IT so that we can restore them
4958 when we are finished with the glyph property value. */
4959 push_it (it
, position
);
4961 it
->area
= TEXT_AREA
;
4962 it
->what
= IT_IMAGE
;
4963 it
->image_id
= -1; /* no image */
4964 it
->position
= start_pos
;
4965 it
->object
= NILP (object
) ? it
->w
->contents
: object
;
4966 it
->method
= GET_FROM_IMAGE
;
4967 it
->from_overlay
= Qnil
;
4968 it
->face_id
= face_id
;
4969 it
->from_disp_prop_p
= true;
4971 /* Say that we haven't consumed the characters with
4972 `display' property yet. The call to pop_it in
4973 set_iterator_to_next will clean this up. */
4974 *position
= start_pos
;
4976 if (EQ (XCAR (spec
), Qleft_fringe
))
4978 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4979 it
->left_user_fringe_face_id
= face_id
;
4983 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4984 it
->right_user_fringe_face_id
= face_id
;
4987 #endif /* HAVE_WINDOW_SYSTEM */
4991 /* Prepare to handle `((margin left-margin) ...)',
4992 `((margin right-margin) ...)' and `((margin nil) ...)'
4993 prefixes for display specifications. */
4994 location
= Qunbound
;
4995 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4999 value
= XCDR (spec
);
5001 value
= XCAR (value
);
5004 if (EQ (XCAR (tem
), Qmargin
)
5005 && (tem
= XCDR (tem
),
5006 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
5008 || EQ (tem
, Qleft_margin
)
5009 || EQ (tem
, Qright_margin
))))
5013 if (EQ (location
, Qunbound
))
5019 /* After this point, VALUE is the property after any
5020 margin prefix has been stripped. It must be a string,
5021 an image specification, or `(space ...)'.
5023 LOCATION specifies where to display: `left-margin',
5024 `right-margin' or nil. */
5026 valid_p
= (STRINGP (value
)
5027 #ifdef HAVE_WINDOW_SYSTEM
5028 || ((it
? FRAME_WINDOW_P (it
->f
) : frame_window_p
)
5029 && valid_image_p (value
))
5030 #endif /* not HAVE_WINDOW_SYSTEM */
5031 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
5033 if (valid_p
&& !display_replaced_p
)
5039 /* Callers need to know whether the display spec is any kind
5040 of `(space ...)' spec that is about to affect text-area
5042 if (CONSP (value
) && EQ (XCAR (value
), Qspace
) && NILP (location
))
5047 /* Save current settings of IT so that we can restore them
5048 when we are finished with the glyph property value. */
5049 push_it (it
, position
);
5050 it
->from_overlay
= overlay
;
5051 it
->from_disp_prop_p
= true;
5053 if (NILP (location
))
5054 it
->area
= TEXT_AREA
;
5055 else if (EQ (location
, Qleft_margin
))
5056 it
->area
= LEFT_MARGIN_AREA
;
5058 it
->area
= RIGHT_MARGIN_AREA
;
5060 if (STRINGP (value
))
5063 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5064 it
->current
.overlay_string_index
= -1;
5065 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5066 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
5067 it
->method
= GET_FROM_STRING
;
5068 it
->stop_charpos
= 0;
5070 it
->base_level_stop
= 0;
5071 it
->string_from_display_prop_p
= true;
5072 /* Say that we haven't consumed the characters with
5073 `display' property yet. The call to pop_it in
5074 set_iterator_to_next will clean this up. */
5075 if (BUFFERP (object
))
5076 *position
= start_pos
;
5078 /* Force paragraph direction to be that of the parent
5079 object. If the parent object's paragraph direction is
5080 not yet determined, default to L2R. */
5081 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
5082 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5084 it
->paragraph_embedding
= L2R
;
5086 /* Set up the bidi iterator for this display string. */
5089 it
->bidi_it
.string
.lstring
= it
->string
;
5090 it
->bidi_it
.string
.s
= NULL
;
5091 it
->bidi_it
.string
.schars
= it
->end_charpos
;
5092 it
->bidi_it
.string
.bufpos
= bufpos
;
5093 it
->bidi_it
.string
.from_disp_str
= 1;
5094 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5095 it
->bidi_it
.w
= it
->w
;
5096 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5099 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
5101 it
->method
= GET_FROM_STRETCH
;
5103 *position
= it
->position
= start_pos
;
5104 retval
= 1 + (it
->area
== TEXT_AREA
);
5106 #ifdef HAVE_WINDOW_SYSTEM
5109 it
->what
= IT_IMAGE
;
5110 it
->image_id
= lookup_image (it
->f
, value
);
5111 it
->position
= start_pos
;
5112 it
->object
= NILP (object
) ? it
->w
->contents
: object
;
5113 it
->method
= GET_FROM_IMAGE
;
5115 /* Say that we haven't consumed the characters with
5116 `display' property yet. The call to pop_it in
5117 set_iterator_to_next will clean this up. */
5118 *position
= start_pos
;
5120 #endif /* HAVE_WINDOW_SYSTEM */
5125 /* Invalid property or property not supported. Restore
5126 POSITION to what it was before. */
5127 *position
= start_pos
;
5131 /* Check if PROP is a display property value whose text should be
5132 treated as intangible. OVERLAY is the overlay from which PROP
5133 came, or nil if it came from a text property. CHARPOS and BYTEPOS
5134 specify the buffer position covered by PROP. */
5137 display_prop_intangible_p (Lisp_Object prop
, Lisp_Object overlay
,
5138 ptrdiff_t charpos
, ptrdiff_t bytepos
)
5140 int frame_window_p
= FRAME_WINDOW_P (XFRAME (selected_frame
));
5141 struct text_pos position
;
5143 SET_TEXT_POS (position
, charpos
, bytepos
);
5144 return handle_display_spec (NULL
, prop
, Qnil
, overlay
,
5145 &position
, charpos
, frame_window_p
);
5149 /* Return 1 if PROP is a display sub-property value containing STRING.
5151 Implementation note: this and the following function are really
5152 special cases of handle_display_spec and
5153 handle_single_display_spec, and should ideally use the same code.
5154 Until they do, these two pairs must be consistent and must be
5155 modified in sync. */
5158 single_display_spec_string_p (Lisp_Object prop
, Lisp_Object string
)
5160 if (EQ (string
, prop
))
5163 /* Skip over `when FORM'. */
5164 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
5169 /* Actually, the condition following `when' should be eval'ed,
5170 like handle_single_display_spec does, and we should return
5171 zero if it evaluates to nil. However, this function is
5172 called only when the buffer was already displayed and some
5173 glyph in the glyph matrix was found to come from a display
5174 string. Therefore, the condition was already evaluated, and
5175 the result was non-nil, otherwise the display string wouldn't
5176 have been displayed and we would have never been called for
5177 this property. Thus, we can skip the evaluation and assume
5178 its result is non-nil. */
5183 /* Skip over `margin LOCATION'. */
5184 if (EQ (XCAR (prop
), Qmargin
))
5195 return EQ (prop
, string
) || (CONSP (prop
) && EQ (XCAR (prop
), string
));
5199 /* Return 1 if STRING appears in the `display' property PROP. */
5202 display_prop_string_p (Lisp_Object prop
, Lisp_Object string
)
5205 && !EQ (XCAR (prop
), Qwhen
)
5206 && !(CONSP (XCAR (prop
)) && EQ (Qmargin
, XCAR (XCAR (prop
)))))
5208 /* A list of sub-properties. */
5209 while (CONSP (prop
))
5211 if (single_display_spec_string_p (XCAR (prop
), string
))
5216 else if (VECTORP (prop
))
5218 /* A vector of sub-properties. */
5220 for (i
= 0; i
< ASIZE (prop
); ++i
)
5221 if (single_display_spec_string_p (AREF (prop
, i
), string
))
5225 return single_display_spec_string_p (prop
, string
);
5230 /* Look for STRING in overlays and text properties in the current
5231 buffer, between character positions FROM and TO (excluding TO).
5232 BACK_P non-zero means look back (in this case, TO is supposed to be
5234 Value is the first character position where STRING was found, or
5235 zero if it wasn't found before hitting TO.
5237 This function may only use code that doesn't eval because it is
5238 called asynchronously from note_mouse_highlight. */
5241 string_buffer_position_lim (Lisp_Object string
,
5242 ptrdiff_t from
, ptrdiff_t to
, int back_p
)
5244 Lisp_Object limit
, prop
, pos
;
5247 pos
= make_number (max (from
, BEGV
));
5249 if (!back_p
) /* looking forward */
5251 limit
= make_number (min (to
, ZV
));
5252 while (!found
&& !EQ (pos
, limit
))
5254 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5255 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5258 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
,
5262 else /* looking back */
5264 limit
= make_number (max (to
, BEGV
));
5265 while (!found
&& !EQ (pos
, limit
))
5267 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5268 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5271 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
5276 return found
? XINT (pos
) : 0;
5279 /* Determine which buffer position in current buffer STRING comes from.
5280 AROUND_CHARPOS is an approximate position where it could come from.
5281 Value is the buffer position or 0 if it couldn't be determined.
5283 This function is necessary because we don't record buffer positions
5284 in glyphs generated from strings (to keep struct glyph small).
5285 This function may only use code that doesn't eval because it is
5286 called asynchronously from note_mouse_highlight. */
5289 string_buffer_position (Lisp_Object string
, ptrdiff_t around_charpos
)
5291 const int MAX_DISTANCE
= 1000;
5292 ptrdiff_t found
= string_buffer_position_lim (string
, around_charpos
,
5293 around_charpos
+ MAX_DISTANCE
,
5297 found
= string_buffer_position_lim (string
, around_charpos
,
5298 around_charpos
- MAX_DISTANCE
, 1);
5304 /***********************************************************************
5305 `composition' property
5306 ***********************************************************************/
5308 /* Set up iterator IT from `composition' property at its current
5309 position. Called from handle_stop. */
5311 static enum prop_handled
5312 handle_composition_prop (struct it
*it
)
5314 Lisp_Object prop
, string
;
5315 ptrdiff_t pos
, pos_byte
, start
, end
;
5317 if (STRINGP (it
->string
))
5321 pos
= IT_STRING_CHARPOS (*it
);
5322 pos_byte
= IT_STRING_BYTEPOS (*it
);
5323 string
= it
->string
;
5324 s
= SDATA (string
) + pos_byte
;
5325 it
->c
= STRING_CHAR (s
);
5329 pos
= IT_CHARPOS (*it
);
5330 pos_byte
= IT_BYTEPOS (*it
);
5332 it
->c
= FETCH_CHAR (pos_byte
);
5335 /* If there's a valid composition and point is not inside of the
5336 composition (in the case that the composition is from the current
5337 buffer), draw a glyph composed from the composition components. */
5338 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
5339 && composition_valid_p (start
, end
, prop
)
5340 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
5343 /* As we can't handle this situation (perhaps font-lock added
5344 a new composition), we just return here hoping that next
5345 redisplay will detect this composition much earlier. */
5346 return HANDLED_NORMALLY
;
5349 if (STRINGP (it
->string
))
5350 pos_byte
= string_char_to_byte (it
->string
, start
);
5352 pos_byte
= CHAR_TO_BYTE (start
);
5354 it
->cmp_it
.id
= get_composition_id (start
, pos_byte
, end
- start
,
5357 if (it
->cmp_it
.id
>= 0)
5360 it
->cmp_it
.nchars
= COMPOSITION_LENGTH (prop
);
5361 it
->cmp_it
.nglyphs
= -1;
5365 return HANDLED_NORMALLY
;
5370 /***********************************************************************
5372 ***********************************************************************/
5374 /* The following structure is used to record overlay strings for
5375 later sorting in load_overlay_strings. */
5377 struct overlay_entry
5379 Lisp_Object overlay
;
5386 /* Set up iterator IT from overlay strings at its current position.
5387 Called from handle_stop. */
5389 static enum prop_handled
5390 handle_overlay_change (struct it
*it
)
5392 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
5393 return HANDLED_RECOMPUTE_PROPS
;
5395 return HANDLED_NORMALLY
;
5399 /* Set up the next overlay string for delivery by IT, if there is an
5400 overlay string to deliver. Called by set_iterator_to_next when the
5401 end of the current overlay string is reached. If there are more
5402 overlay strings to display, IT->string and
5403 IT->current.overlay_string_index are set appropriately here.
5404 Otherwise IT->string is set to nil. */
5407 next_overlay_string (struct it
*it
)
5409 ++it
->current
.overlay_string_index
;
5410 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
5412 /* No more overlay strings. Restore IT's settings to what
5413 they were before overlay strings were processed, and
5414 continue to deliver from current_buffer. */
5416 it
->ellipsis_p
= (it
->stack
[it
->sp
- 1].display_ellipsis_p
!= 0);
5419 || (NILP (it
->string
)
5420 && it
->method
== GET_FROM_BUFFER
5421 && it
->stop_charpos
>= BEGV
5422 && it
->stop_charpos
<= it
->end_charpos
));
5423 it
->current
.overlay_string_index
= -1;
5424 it
->n_overlay_strings
= 0;
5425 it
->overlay_strings_charpos
= -1;
5426 /* If there's an empty display string on the stack, pop the
5427 stack, to resync the bidi iterator with IT's position. Such
5428 empty strings are pushed onto the stack in
5429 get_overlay_strings_1. */
5430 if (it
->sp
> 0 && STRINGP (it
->string
) && !SCHARS (it
->string
))
5433 /* If we're at the end of the buffer, record that we have
5434 processed the overlay strings there already, so that
5435 next_element_from_buffer doesn't try it again. */
5436 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
5437 it
->overlay_strings_at_end_processed_p
= true;
5441 /* There are more overlay strings to process. If
5442 IT->current.overlay_string_index has advanced to a position
5443 where we must load IT->overlay_strings with more strings, do
5444 it. We must load at the IT->overlay_strings_charpos where
5445 IT->n_overlay_strings was originally computed; when invisible
5446 text is present, this might not be IT_CHARPOS (Bug#7016). */
5447 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
5449 if (it
->current
.overlay_string_index
&& i
== 0)
5450 load_overlay_strings (it
, it
->overlay_strings_charpos
);
5452 /* Initialize IT to deliver display elements from the overlay
5454 it
->string
= it
->overlay_strings
[i
];
5455 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5456 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
5457 it
->method
= GET_FROM_STRING
;
5458 it
->stop_charpos
= 0;
5459 it
->end_charpos
= SCHARS (it
->string
);
5460 if (it
->cmp_it
.stop_pos
>= 0)
5461 it
->cmp_it
.stop_pos
= 0;
5463 it
->base_level_stop
= 0;
5465 /* Set up the bidi iterator for this overlay string. */
5468 it
->bidi_it
.string
.lstring
= it
->string
;
5469 it
->bidi_it
.string
.s
= NULL
;
5470 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5471 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
5472 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5473 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5474 it
->bidi_it
.w
= it
->w
;
5475 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5483 /* Compare two overlay_entry structures E1 and E2. Used as a
5484 comparison function for qsort in load_overlay_strings. Overlay
5485 strings for the same position are sorted so that
5487 1. All after-strings come in front of before-strings, except
5488 when they come from the same overlay.
5490 2. Within after-strings, strings are sorted so that overlay strings
5491 from overlays with higher priorities come first.
5493 2. Within before-strings, strings are sorted so that overlay
5494 strings from overlays with higher priorities come last.
5496 Value is analogous to strcmp. */
5500 compare_overlay_entries (const void *e1
, const void *e2
)
5502 struct overlay_entry
const *entry1
= e1
;
5503 struct overlay_entry
const *entry2
= e2
;
5506 if (entry1
->after_string_p
!= entry2
->after_string_p
)
5508 /* Let after-strings appear in front of before-strings if
5509 they come from different overlays. */
5510 if (EQ (entry1
->overlay
, entry2
->overlay
))
5511 result
= entry1
->after_string_p
? 1 : -1;
5513 result
= entry1
->after_string_p
? -1 : 1;
5515 else if (entry1
->priority
!= entry2
->priority
)
5517 if (entry1
->after_string_p
)
5518 /* After-strings sorted in order of decreasing priority. */
5519 result
= entry2
->priority
< entry1
->priority
? -1 : 1;
5521 /* Before-strings sorted in order of increasing priority. */
5522 result
= entry1
->priority
< entry2
->priority
? -1 : 1;
5531 /* Load the vector IT->overlay_strings with overlay strings from IT's
5532 current buffer position, or from CHARPOS if that is > 0. Set
5533 IT->n_overlays to the total number of overlay strings found.
5535 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
5536 a time. On entry into load_overlay_strings,
5537 IT->current.overlay_string_index gives the number of overlay
5538 strings that have already been loaded by previous calls to this
5541 IT->add_overlay_start contains an additional overlay start
5542 position to consider for taking overlay strings from, if non-zero.
5543 This position comes into play when the overlay has an `invisible'
5544 property, and both before and after-strings. When we've skipped to
5545 the end of the overlay, because of its `invisible' property, we
5546 nevertheless want its before-string to appear.
5547 IT->add_overlay_start will contain the overlay start position
5550 Overlay strings are sorted so that after-string strings come in
5551 front of before-string strings. Within before and after-strings,
5552 strings are sorted by overlay priority. See also function
5553 compare_overlay_entries. */
5556 load_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5558 Lisp_Object overlay
, window
, str
, invisible
;
5559 struct Lisp_Overlay
*ov
;
5560 ptrdiff_t start
, end
;
5561 ptrdiff_t size
= 20;
5562 ptrdiff_t n
= 0, i
, j
;
5564 struct overlay_entry
*entries
= alloca (size
* sizeof *entries
);
5568 charpos
= IT_CHARPOS (*it
);
5570 /* Append the overlay string STRING of overlay OVERLAY to vector
5571 `entries' which has size `size' and currently contains `n'
5572 elements. AFTER_P non-zero means STRING is an after-string of
5574 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
5577 Lisp_Object priority; \
5581 struct overlay_entry *old = entries; \
5582 SAFE_NALLOCA (entries, 2, size); \
5583 memcpy (entries, old, size * sizeof *entries); \
5587 entries[n].string = (STRING); \
5588 entries[n].overlay = (OVERLAY); \
5589 priority = Foverlay_get ((OVERLAY), Qpriority); \
5590 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
5591 entries[n].after_string_p = (AFTER_P); \
5596 /* Process overlay before the overlay center. */
5597 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
5599 XSETMISC (overlay
, ov
);
5600 eassert (OVERLAYP (overlay
));
5601 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5602 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5607 /* Skip this overlay if it doesn't start or end at IT's current
5609 if (end
!= charpos
&& start
!= charpos
)
5612 /* Skip this overlay if it doesn't apply to IT->w. */
5613 window
= Foverlay_get (overlay
, Qwindow
);
5614 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5617 /* If the text ``under'' the overlay is invisible, both before-
5618 and after-strings from this overlay are visible; start and
5619 end position are indistinguishable. */
5620 invisible
= Foverlay_get (overlay
, Qinvisible
);
5621 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5623 /* If overlay has a non-empty before-string, record it. */
5624 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5625 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5627 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5629 /* If overlay has a non-empty after-string, record it. */
5630 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5631 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5633 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5636 /* Process overlays after the overlay center. */
5637 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
5639 XSETMISC (overlay
, ov
);
5640 eassert (OVERLAYP (overlay
));
5641 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5642 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5644 if (start
> charpos
)
5647 /* Skip this overlay if it doesn't start or end at IT's current
5649 if (end
!= charpos
&& start
!= charpos
)
5652 /* Skip this overlay if it doesn't apply to IT->w. */
5653 window
= Foverlay_get (overlay
, Qwindow
);
5654 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5657 /* If the text ``under'' the overlay is invisible, it has a zero
5658 dimension, and both before- and after-strings apply. */
5659 invisible
= Foverlay_get (overlay
, Qinvisible
);
5660 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5662 /* If overlay has a non-empty before-string, record it. */
5663 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5664 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5666 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5668 /* If overlay has a non-empty after-string, record it. */
5669 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5670 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5672 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5675 #undef RECORD_OVERLAY_STRING
5679 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
5681 /* Record number of overlay strings, and where we computed it. */
5682 it
->n_overlay_strings
= n
;
5683 it
->overlay_strings_charpos
= charpos
;
5685 /* IT->current.overlay_string_index is the number of overlay strings
5686 that have already been consumed by IT. Copy some of the
5687 remaining overlay strings to IT->overlay_strings. */
5689 j
= it
->current
.overlay_string_index
;
5690 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
5692 it
->overlay_strings
[i
] = entries
[j
].string
;
5693 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
5701 /* Get the first chunk of overlay strings at IT's current buffer
5702 position, or at CHARPOS if that is > 0. Value is non-zero if at
5703 least one overlay string was found. */
5706 get_overlay_strings_1 (struct it
*it
, ptrdiff_t charpos
, int compute_stop_p
)
5708 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5709 process. This fills IT->overlay_strings with strings, and sets
5710 IT->n_overlay_strings to the total number of strings to process.
5711 IT->pos.overlay_string_index has to be set temporarily to zero
5712 because load_overlay_strings needs this; it must be set to -1
5713 when no overlay strings are found because a zero value would
5714 indicate a position in the first overlay string. */
5715 it
->current
.overlay_string_index
= 0;
5716 load_overlay_strings (it
, charpos
);
5718 /* If we found overlay strings, set up IT to deliver display
5719 elements from the first one. Otherwise set up IT to deliver
5720 from current_buffer. */
5721 if (it
->n_overlay_strings
)
5723 /* Make sure we know settings in current_buffer, so that we can
5724 restore meaningful values when we're done with the overlay
5727 compute_stop_pos (it
);
5728 eassert (it
->face_id
>= 0);
5730 /* Save IT's settings. They are restored after all overlay
5731 strings have been processed. */
5732 eassert (!compute_stop_p
|| it
->sp
== 0);
5734 /* When called from handle_stop, there might be an empty display
5735 string loaded. In that case, don't bother saving it. But
5736 don't use this optimization with the bidi iterator, since we
5737 need the corresponding pop_it call to resync the bidi
5738 iterator's position with IT's position, after we are done
5739 with the overlay strings. (The corresponding call to pop_it
5740 in case of an empty display string is in
5741 next_overlay_string.) */
5743 && STRINGP (it
->string
) && !SCHARS (it
->string
)))
5746 /* Set up IT to deliver display elements from the first overlay
5748 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5749 it
->string
= it
->overlay_strings
[0];
5750 it
->from_overlay
= Qnil
;
5751 it
->stop_charpos
= 0;
5752 eassert (STRINGP (it
->string
));
5753 it
->end_charpos
= SCHARS (it
->string
);
5755 it
->base_level_stop
= 0;
5756 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5757 it
->method
= GET_FROM_STRING
;
5758 it
->from_disp_prop_p
= 0;
5760 /* Force paragraph direction to be that of the parent
5762 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
5763 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5765 it
->paragraph_embedding
= L2R
;
5767 /* Set up the bidi iterator for this overlay string. */
5770 ptrdiff_t pos
= (charpos
> 0 ? charpos
: IT_CHARPOS (*it
));
5772 it
->bidi_it
.string
.lstring
= it
->string
;
5773 it
->bidi_it
.string
.s
= NULL
;
5774 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5775 it
->bidi_it
.string
.bufpos
= pos
;
5776 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5777 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5778 it
->bidi_it
.w
= it
->w
;
5779 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5784 it
->current
.overlay_string_index
= -1;
5789 get_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5792 it
->method
= GET_FROM_BUFFER
;
5794 (void) get_overlay_strings_1 (it
, charpos
, 1);
5798 /* Value is non-zero if we found at least one overlay string. */
5799 return STRINGP (it
->string
);
5804 /***********************************************************************
5805 Saving and restoring state
5806 ***********************************************************************/
5808 /* Save current settings of IT on IT->stack. Called, for example,
5809 before setting up IT for an overlay string, to be able to restore
5810 IT's settings to what they were after the overlay string has been
5811 processed. If POSITION is non-NULL, it is the position to save on
5812 the stack instead of IT->position. */
5815 push_it (struct it
*it
, struct text_pos
*position
)
5817 struct iterator_stack_entry
*p
;
5819 eassert (it
->sp
< IT_STACK_SIZE
);
5820 p
= it
->stack
+ it
->sp
;
5822 p
->stop_charpos
= it
->stop_charpos
;
5823 p
->prev_stop
= it
->prev_stop
;
5824 p
->base_level_stop
= it
->base_level_stop
;
5825 p
->cmp_it
= it
->cmp_it
;
5826 eassert (it
->face_id
>= 0);
5827 p
->face_id
= it
->face_id
;
5828 p
->string
= it
->string
;
5829 p
->method
= it
->method
;
5830 p
->from_overlay
= it
->from_overlay
;
5833 case GET_FROM_IMAGE
:
5834 p
->u
.image
.object
= it
->object
;
5835 p
->u
.image
.image_id
= it
->image_id
;
5836 p
->u
.image
.slice
= it
->slice
;
5838 case GET_FROM_STRETCH
:
5839 p
->u
.stretch
.object
= it
->object
;
5842 p
->position
= position
? *position
: it
->position
;
5843 p
->current
= it
->current
;
5844 p
->end_charpos
= it
->end_charpos
;
5845 p
->string_nchars
= it
->string_nchars
;
5847 p
->multibyte_p
= it
->multibyte_p
;
5848 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
5849 p
->space_width
= it
->space_width
;
5850 p
->font_height
= it
->font_height
;
5851 p
->voffset
= it
->voffset
;
5852 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5853 p
->string_from_prefix_prop_p
= it
->string_from_prefix_prop_p
;
5854 p
->display_ellipsis_p
= 0;
5855 p
->line_wrap
= it
->line_wrap
;
5856 p
->bidi_p
= it
->bidi_p
;
5857 p
->paragraph_embedding
= it
->paragraph_embedding
;
5858 p
->from_disp_prop_p
= it
->from_disp_prop_p
;
5861 /* Save the state of the bidi iterator as well. */
5863 bidi_push_it (&it
->bidi_it
);
5867 iterate_out_of_display_property (struct it
*it
)
5869 int buffer_p
= !STRINGP (it
->string
);
5870 ptrdiff_t eob
= (buffer_p
? ZV
: it
->end_charpos
);
5871 ptrdiff_t bob
= (buffer_p
? BEGV
: 0);
5873 eassert (eob
>= CHARPOS (it
->position
) && CHARPOS (it
->position
) >= bob
);
5875 /* Maybe initialize paragraph direction. If we are at the beginning
5876 of a new paragraph, next_element_from_buffer may not have a
5877 chance to do that. */
5878 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< eob
)
5879 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
5880 /* prev_stop can be zero, so check against BEGV as well. */
5881 while (it
->bidi_it
.charpos
>= bob
5882 && it
->prev_stop
<= it
->bidi_it
.charpos
5883 && it
->bidi_it
.charpos
< CHARPOS (it
->position
)
5884 && it
->bidi_it
.charpos
< eob
)
5885 bidi_move_to_visually_next (&it
->bidi_it
);
5886 /* Record the stop_pos we just crossed, for when we cross it
5888 if (it
->bidi_it
.charpos
> CHARPOS (it
->position
))
5889 it
->prev_stop
= CHARPOS (it
->position
);
5890 /* If we ended up not where pop_it put us, resync IT's
5891 positional members with the bidi iterator. */
5892 if (it
->bidi_it
.charpos
!= CHARPOS (it
->position
))
5893 SET_TEXT_POS (it
->position
, it
->bidi_it
.charpos
, it
->bidi_it
.bytepos
);
5895 it
->current
.pos
= it
->position
;
5897 it
->current
.string_pos
= it
->position
;
5900 /* Restore IT's settings from IT->stack. Called, for example, when no
5901 more overlay strings must be processed, and we return to delivering
5902 display elements from a buffer, or when the end of a string from a
5903 `display' property is reached and we return to delivering display
5904 elements from an overlay string, or from a buffer. */
5907 pop_it (struct it
*it
)
5909 struct iterator_stack_entry
*p
;
5910 int from_display_prop
= it
->from_disp_prop_p
;
5912 eassert (it
->sp
> 0);
5914 p
= it
->stack
+ it
->sp
;
5915 it
->stop_charpos
= p
->stop_charpos
;
5916 it
->prev_stop
= p
->prev_stop
;
5917 it
->base_level_stop
= p
->base_level_stop
;
5918 it
->cmp_it
= p
->cmp_it
;
5919 it
->face_id
= p
->face_id
;
5920 it
->current
= p
->current
;
5921 it
->position
= p
->position
;
5922 it
->string
= p
->string
;
5923 it
->from_overlay
= p
->from_overlay
;
5924 if (NILP (it
->string
))
5925 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5926 it
->method
= p
->method
;
5929 case GET_FROM_IMAGE
:
5930 it
->image_id
= p
->u
.image
.image_id
;
5931 it
->object
= p
->u
.image
.object
;
5932 it
->slice
= p
->u
.image
.slice
;
5934 case GET_FROM_STRETCH
:
5935 it
->object
= p
->u
.stretch
.object
;
5937 case GET_FROM_BUFFER
:
5938 it
->object
= it
->w
->contents
;
5940 case GET_FROM_STRING
:
5941 it
->object
= it
->string
;
5943 case GET_FROM_DISPLAY_VECTOR
:
5945 it
->method
= GET_FROM_C_STRING
;
5946 else if (STRINGP (it
->string
))
5947 it
->method
= GET_FROM_STRING
;
5950 it
->method
= GET_FROM_BUFFER
;
5951 it
->object
= it
->w
->contents
;
5954 it
->end_charpos
= p
->end_charpos
;
5955 it
->string_nchars
= p
->string_nchars
;
5957 it
->multibyte_p
= p
->multibyte_p
;
5958 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
5959 it
->space_width
= p
->space_width
;
5960 it
->font_height
= p
->font_height
;
5961 it
->voffset
= p
->voffset
;
5962 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5963 it
->string_from_prefix_prop_p
= p
->string_from_prefix_prop_p
;
5964 it
->line_wrap
= p
->line_wrap
;
5965 it
->bidi_p
= p
->bidi_p
;
5966 it
->paragraph_embedding
= p
->paragraph_embedding
;
5967 it
->from_disp_prop_p
= p
->from_disp_prop_p
;
5970 bidi_pop_it (&it
->bidi_it
);
5971 /* Bidi-iterate until we get out of the portion of text, if any,
5972 covered by a `display' text property or by an overlay with
5973 `display' property. (We cannot just jump there, because the
5974 internal coherency of the bidi iterator state can not be
5975 preserved across such jumps.) We also must determine the
5976 paragraph base direction if the overlay we just processed is
5977 at the beginning of a new paragraph. */
5978 if (from_display_prop
5979 && (it
->method
== GET_FROM_BUFFER
|| it
->method
== GET_FROM_STRING
))
5980 iterate_out_of_display_property (it
);
5982 eassert ((BUFFERP (it
->object
)
5983 && IT_CHARPOS (*it
) == it
->bidi_it
.charpos
5984 && IT_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
5985 || (STRINGP (it
->object
)
5986 && IT_STRING_CHARPOS (*it
) == it
->bidi_it
.charpos
5987 && IT_STRING_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
5988 || (CONSP (it
->object
) && it
->method
== GET_FROM_STRETCH
));
5994 /***********************************************************************
5996 ***********************************************************************/
5998 /* Set IT's current position to the previous line start. */
6001 back_to_previous_line_start (struct it
*it
)
6003 ptrdiff_t cp
= IT_CHARPOS (*it
), bp
= IT_BYTEPOS (*it
);
6006 IT_CHARPOS (*it
) = find_newline_no_quit (cp
, bp
, -1, &IT_BYTEPOS (*it
));
6010 /* Move IT to the next line start.
6012 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
6013 we skipped over part of the text (as opposed to moving the iterator
6014 continuously over the text). Otherwise, don't change the value
6017 If BIDI_IT_PREV is non-NULL, store into it the state of the bidi
6018 iterator on the newline, if it was found.
6020 Newlines may come from buffer text, overlay strings, or strings
6021 displayed via the `display' property. That's the reason we can't
6022 simply use find_newline_no_quit.
6024 Note that this function may not skip over invisible text that is so
6025 because of text properties and immediately follows a newline. If
6026 it would, function reseat_at_next_visible_line_start, when called
6027 from set_iterator_to_next, would effectively make invisible
6028 characters following a newline part of the wrong glyph row, which
6029 leads to wrong cursor motion. */
6032 forward_to_next_line_start (struct it
*it
, int *skipped_p
,
6033 struct bidi_it
*bidi_it_prev
)
6035 ptrdiff_t old_selective
;
6036 int newline_found_p
, n
;
6037 const int MAX_NEWLINE_DISTANCE
= 500;
6039 /* If already on a newline, just consume it to avoid unintended
6040 skipping over invisible text below. */
6041 if (it
->what
== IT_CHARACTER
6043 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
6045 if (it
->bidi_p
&& bidi_it_prev
)
6046 *bidi_it_prev
= it
->bidi_it
;
6047 set_iterator_to_next (it
, 0);
6052 /* Don't handle selective display in the following. It's (a)
6053 unnecessary because it's done by the caller, and (b) leads to an
6054 infinite recursion because next_element_from_ellipsis indirectly
6055 calls this function. */
6056 old_selective
= it
->selective
;
6059 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
6060 from buffer text. */
6061 for (n
= newline_found_p
= 0;
6062 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
6063 n
+= STRINGP (it
->string
) ? 0 : 1)
6065 if (!get_next_display_element (it
))
6067 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
6068 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
6069 *bidi_it_prev
= it
->bidi_it
;
6070 set_iterator_to_next (it
, 0);
6073 /* If we didn't find a newline near enough, see if we can use a
6075 if (!newline_found_p
)
6077 ptrdiff_t bytepos
, start
= IT_CHARPOS (*it
);
6078 ptrdiff_t limit
= find_newline_no_quit (start
, IT_BYTEPOS (*it
),
6082 eassert (!STRINGP (it
->string
));
6084 /* If there isn't any `display' property in sight, and no
6085 overlays, we can just use the position of the newline in
6087 if (it
->stop_charpos
>= limit
6088 || ((pos
= Fnext_single_property_change (make_number (start
),
6090 make_number (limit
)),
6092 && next_overlay_change (start
) == ZV
))
6096 IT_CHARPOS (*it
) = limit
;
6097 IT_BYTEPOS (*it
) = bytepos
;
6101 struct bidi_it bprev
;
6103 /* Help bidi.c avoid expensive searches for display
6104 properties and overlays, by telling it that there are
6105 none up to `limit'. */
6106 if (it
->bidi_it
.disp_pos
< limit
)
6108 it
->bidi_it
.disp_pos
= limit
;
6109 it
->bidi_it
.disp_prop
= 0;
6112 bprev
= it
->bidi_it
;
6113 bidi_move_to_visually_next (&it
->bidi_it
);
6114 } while (it
->bidi_it
.charpos
!= limit
);
6115 IT_CHARPOS (*it
) = limit
;
6116 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6118 *bidi_it_prev
= bprev
;
6120 *skipped_p
= newline_found_p
= true;
6124 while (get_next_display_element (it
)
6125 && !newline_found_p
)
6127 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
6128 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
6129 *bidi_it_prev
= it
->bidi_it
;
6130 set_iterator_to_next (it
, 0);
6135 it
->selective
= old_selective
;
6136 return newline_found_p
;
6140 /* Set IT's current position to the previous visible line start. Skip
6141 invisible text that is so either due to text properties or due to
6142 selective display. Caution: this does not change IT->current_x and
6146 back_to_previous_visible_line_start (struct it
*it
)
6148 while (IT_CHARPOS (*it
) > BEGV
)
6150 back_to_previous_line_start (it
);
6152 if (IT_CHARPOS (*it
) <= BEGV
)
6155 /* If selective > 0, then lines indented more than its value are
6157 if (it
->selective
> 0
6158 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6162 /* Check the newline before point for invisibility. */
6165 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
6166 Qinvisible
, it
->window
);
6167 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
6171 if (IT_CHARPOS (*it
) <= BEGV
)
6176 void *it2data
= NULL
;
6179 Lisp_Object val
, overlay
;
6181 SAVE_IT (it2
, *it
, it2data
);
6183 /* If newline is part of a composition, continue from start of composition */
6184 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
6185 && beg
< IT_CHARPOS (*it
))
6188 /* If newline is replaced by a display property, find start of overlay
6189 or interval and continue search from that point. */
6190 pos
= --IT_CHARPOS (it2
);
6193 bidi_unshelve_cache (NULL
, 0);
6194 it2
.string_from_display_prop_p
= 0;
6195 it2
.from_disp_prop_p
= 0;
6196 if (handle_display_prop (&it2
) == HANDLED_RETURN
6197 && !NILP (val
= get_char_property_and_overlay
6198 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
6199 && (OVERLAYP (overlay
)
6200 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
6201 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
6203 RESTORE_IT (it
, it
, it2data
);
6207 /* Newline is not replaced by anything -- so we are done. */
6208 RESTORE_IT (it
, it
, it2data
);
6214 IT_CHARPOS (*it
) = beg
;
6215 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
6219 it
->continuation_lines_width
= 0;
6221 eassert (IT_CHARPOS (*it
) >= BEGV
);
6222 eassert (IT_CHARPOS (*it
) == BEGV
6223 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6228 /* Reseat iterator IT at the previous visible line start. Skip
6229 invisible text that is so either due to text properties or due to
6230 selective display. At the end, update IT's overlay information,
6231 face information etc. */
6234 reseat_at_previous_visible_line_start (struct it
*it
)
6236 back_to_previous_visible_line_start (it
);
6237 reseat (it
, it
->current
.pos
, 1);
6242 /* Reseat iterator IT on the next visible line start in the current
6243 buffer. ON_NEWLINE_P non-zero means position IT on the newline
6244 preceding the line start. Skip over invisible text that is so
6245 because of selective display. Compute faces, overlays etc at the
6246 new position. Note that this function does not skip over text that
6247 is invisible because of text properties. */
6250 reseat_at_next_visible_line_start (struct it
*it
, int on_newline_p
)
6252 int newline_found_p
, skipped_p
= 0;
6253 struct bidi_it bidi_it_prev
;
6255 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6257 /* Skip over lines that are invisible because they are indented
6258 more than the value of IT->selective. */
6259 if (it
->selective
> 0)
6260 while (IT_CHARPOS (*it
) < ZV
6261 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6264 eassert (IT_BYTEPOS (*it
) == BEGV
6265 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6267 forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6270 /* Position on the newline if that's what's requested. */
6271 if (on_newline_p
&& newline_found_p
)
6273 if (STRINGP (it
->string
))
6275 if (IT_STRING_CHARPOS (*it
) > 0)
6279 --IT_STRING_CHARPOS (*it
);
6280 --IT_STRING_BYTEPOS (*it
);
6284 /* We need to restore the bidi iterator to the state
6285 it had on the newline, and resync the IT's
6286 position with that. */
6287 it
->bidi_it
= bidi_it_prev
;
6288 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6289 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6293 else if (IT_CHARPOS (*it
) > BEGV
)
6302 /* We need to restore the bidi iterator to the state it
6303 had on the newline and resync IT with that. */
6304 it
->bidi_it
= bidi_it_prev
;
6305 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6306 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6308 reseat (it
, it
->current
.pos
, 0);
6312 reseat (it
, it
->current
.pos
, 0);
6319 /***********************************************************************
6320 Changing an iterator's position
6321 ***********************************************************************/
6323 /* Change IT's current position to POS in current_buffer. If FORCE_P
6324 is non-zero, always check for text properties at the new position.
6325 Otherwise, text properties are only looked up if POS >=
6326 IT->check_charpos of a property. */
6329 reseat (struct it
*it
, struct text_pos pos
, int force_p
)
6331 ptrdiff_t original_pos
= IT_CHARPOS (*it
);
6333 reseat_1 (it
, pos
, 0);
6335 /* Determine where to check text properties. Avoid doing it
6336 where possible because text property lookup is very expensive. */
6338 || CHARPOS (pos
) > it
->stop_charpos
6339 || CHARPOS (pos
) < original_pos
)
6343 /* For bidi iteration, we need to prime prev_stop and
6344 base_level_stop with our best estimations. */
6345 /* Implementation note: Of course, POS is not necessarily a
6346 stop position, so assigning prev_pos to it is a lie; we
6347 should have called compute_stop_backwards. However, if
6348 the current buffer does not include any R2L characters,
6349 that call would be a waste of cycles, because the
6350 iterator will never move back, and thus never cross this
6351 "fake" stop position. So we delay that backward search
6352 until the time we really need it, in next_element_from_buffer. */
6353 if (CHARPOS (pos
) != it
->prev_stop
)
6354 it
->prev_stop
= CHARPOS (pos
);
6355 if (CHARPOS (pos
) < it
->base_level_stop
)
6356 it
->base_level_stop
= 0; /* meaning it's unknown */
6362 it
->prev_stop
= it
->base_level_stop
= 0;
6371 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
6372 IT->stop_pos to POS, also. */
6375 reseat_1 (struct it
*it
, struct text_pos pos
, int set_stop_p
)
6377 /* Don't call this function when scanning a C string. */
6378 eassert (it
->s
== NULL
);
6380 /* POS must be a reasonable value. */
6381 eassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
6383 it
->current
.pos
= it
->position
= pos
;
6384 it
->end_charpos
= ZV
;
6386 it
->current
.dpvec_index
= -1;
6387 it
->current
.overlay_string_index
= -1;
6388 IT_STRING_CHARPOS (*it
) = -1;
6389 IT_STRING_BYTEPOS (*it
) = -1;
6391 it
->method
= GET_FROM_BUFFER
;
6392 it
->object
= it
->w
->contents
;
6393 it
->area
= TEXT_AREA
;
6394 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
6396 it
->string_from_display_prop_p
= 0;
6397 it
->string_from_prefix_prop_p
= 0;
6399 it
->from_disp_prop_p
= 0;
6400 it
->face_before_selective_p
= 0;
6403 bidi_init_it (IT_CHARPOS (*it
), IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6405 bidi_unshelve_cache (NULL
, 0);
6406 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6407 it
->bidi_it
.string
.s
= NULL
;
6408 it
->bidi_it
.string
.lstring
= Qnil
;
6409 it
->bidi_it
.string
.bufpos
= 0;
6410 it
->bidi_it
.string
.unibyte
= 0;
6411 it
->bidi_it
.w
= it
->w
;
6416 it
->stop_charpos
= CHARPOS (pos
);
6417 it
->base_level_stop
= CHARPOS (pos
);
6419 /* This make the information stored in it->cmp_it invalidate. */
6424 /* Set up IT for displaying a string, starting at CHARPOS in window W.
6425 If S is non-null, it is a C string to iterate over. Otherwise,
6426 STRING gives a Lisp string to iterate over.
6428 If PRECISION > 0, don't return more then PRECISION number of
6429 characters from the string.
6431 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
6432 characters have been returned. FIELD_WIDTH < 0 means an infinite
6435 MULTIBYTE = 0 means disable processing of multibyte characters,
6436 MULTIBYTE > 0 means enable it,
6437 MULTIBYTE < 0 means use IT->multibyte_p.
6439 IT must be initialized via a prior call to init_iterator before
6440 calling this function. */
6443 reseat_to_string (struct it
*it
, const char *s
, Lisp_Object string
,
6444 ptrdiff_t charpos
, ptrdiff_t precision
, int field_width
,
6447 /* No text property checks performed by default, but see below. */
6448 it
->stop_charpos
= -1;
6450 /* Set iterator position and end position. */
6451 memset (&it
->current
, 0, sizeof it
->current
);
6452 it
->current
.overlay_string_index
= -1;
6453 it
->current
.dpvec_index
= -1;
6454 eassert (charpos
>= 0);
6456 /* If STRING is specified, use its multibyteness, otherwise use the
6457 setting of MULTIBYTE, if specified. */
6459 it
->multibyte_p
= multibyte
> 0;
6461 /* Bidirectional reordering of strings is controlled by the default
6462 value of bidi-display-reordering. Don't try to reorder while
6463 loading loadup.el, as the necessary character property tables are
6464 not yet available. */
6467 && !NILP (BVAR (&buffer_defaults
, bidi_display_reordering
));
6471 eassert (STRINGP (string
));
6472 it
->string
= string
;
6474 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
6475 it
->method
= GET_FROM_STRING
;
6476 it
->current
.string_pos
= string_pos (charpos
, string
);
6480 it
->bidi_it
.string
.lstring
= string
;
6481 it
->bidi_it
.string
.s
= NULL
;
6482 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6483 it
->bidi_it
.string
.bufpos
= 0;
6484 it
->bidi_it
.string
.from_disp_str
= 0;
6485 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6486 it
->bidi_it
.w
= it
->w
;
6487 bidi_init_it (charpos
, IT_STRING_BYTEPOS (*it
),
6488 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
6493 it
->s
= (const unsigned char *) s
;
6496 /* Note that we use IT->current.pos, not it->current.string_pos,
6497 for displaying C strings. */
6498 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
6499 if (it
->multibyte_p
)
6501 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
6502 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
6506 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
6507 it
->end_charpos
= it
->string_nchars
= strlen (s
);
6512 it
->bidi_it
.string
.lstring
= Qnil
;
6513 it
->bidi_it
.string
.s
= (const unsigned char *) s
;
6514 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6515 it
->bidi_it
.string
.bufpos
= 0;
6516 it
->bidi_it
.string
.from_disp_str
= 0;
6517 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6518 it
->bidi_it
.w
= it
->w
;
6519 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6522 it
->method
= GET_FROM_C_STRING
;
6525 /* PRECISION > 0 means don't return more than PRECISION characters
6527 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
6529 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
6531 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6534 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
6535 characters have been returned. FIELD_WIDTH == 0 means don't pad,
6536 FIELD_WIDTH < 0 means infinite field width. This is useful for
6537 padding with `-' at the end of a mode line. */
6538 if (field_width
< 0)
6539 field_width
= INFINITY
;
6540 /* Implementation note: We deliberately don't enlarge
6541 it->bidi_it.string.schars here to fit it->end_charpos, because
6542 the bidi iterator cannot produce characters out of thin air. */
6543 if (field_width
> it
->end_charpos
- charpos
)
6544 it
->end_charpos
= charpos
+ field_width
;
6546 /* Use the standard display table for displaying strings. */
6547 if (DISP_TABLE_P (Vstandard_display_table
))
6548 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
6550 it
->stop_charpos
= charpos
;
6551 it
->prev_stop
= charpos
;
6552 it
->base_level_stop
= 0;
6555 it
->bidi_it
.first_elt
= 1;
6556 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6557 it
->bidi_it
.disp_pos
= -1;
6559 if (s
== NULL
&& it
->multibyte_p
)
6561 ptrdiff_t endpos
= SCHARS (it
->string
);
6562 if (endpos
> it
->end_charpos
)
6563 endpos
= it
->end_charpos
;
6564 composition_compute_stop_pos (&it
->cmp_it
, charpos
, -1, endpos
,
6572 /***********************************************************************
6574 ***********************************************************************/
6576 /* Map enum it_method value to corresponding next_element_from_* function. */
6578 static int (* get_next_element
[NUM_IT_METHODS
]) (struct it
*it
) =
6580 next_element_from_buffer
,
6581 next_element_from_display_vector
,
6582 next_element_from_string
,
6583 next_element_from_c_string
,
6584 next_element_from_image
,
6585 next_element_from_stretch
6588 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
6591 /* Return 1 iff a character at CHARPOS (and BYTEPOS) is composed
6592 (possibly with the following characters). */
6594 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS,END_CHARPOS) \
6595 ((IT)->cmp_it.id >= 0 \
6596 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
6597 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
6598 END_CHARPOS, (IT)->w, \
6599 FACE_FROM_ID ((IT)->f, (IT)->face_id), \
6603 /* Lookup the char-table Vglyphless_char_display for character C (-1
6604 if we want information for no-font case), and return the display
6605 method symbol. By side-effect, update it->what and
6606 it->glyphless_method. This function is called from
6607 get_next_display_element for each character element, and from
6608 x_produce_glyphs when no suitable font was found. */
6611 lookup_glyphless_char_display (int c
, struct it
*it
)
6613 Lisp_Object glyphless_method
= Qnil
;
6615 if (CHAR_TABLE_P (Vglyphless_char_display
)
6616 && CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
)) >= 1)
6620 glyphless_method
= CHAR_TABLE_REF (Vglyphless_char_display
, c
);
6621 if (CONSP (glyphless_method
))
6622 glyphless_method
= FRAME_WINDOW_P (it
->f
)
6623 ? XCAR (glyphless_method
)
6624 : XCDR (glyphless_method
);
6627 glyphless_method
= XCHAR_TABLE (Vglyphless_char_display
)->extras
[0];
6631 if (NILP (glyphless_method
))
6634 /* The default is to display the character by a proper font. */
6636 /* The default for the no-font case is to display an empty box. */
6637 glyphless_method
= Qempty_box
;
6639 if (EQ (glyphless_method
, Qzero_width
))
6642 return glyphless_method
;
6643 /* This method can't be used for the no-font case. */
6644 glyphless_method
= Qempty_box
;
6646 if (EQ (glyphless_method
, Qthin_space
))
6647 it
->glyphless_method
= GLYPHLESS_DISPLAY_THIN_SPACE
;
6648 else if (EQ (glyphless_method
, Qempty_box
))
6649 it
->glyphless_method
= GLYPHLESS_DISPLAY_EMPTY_BOX
;
6650 else if (EQ (glyphless_method
, Qhex_code
))
6651 it
->glyphless_method
= GLYPHLESS_DISPLAY_HEX_CODE
;
6652 else if (STRINGP (glyphless_method
))
6653 it
->glyphless_method
= GLYPHLESS_DISPLAY_ACRONYM
;
6656 /* Invalid value. We use the default method. */
6657 glyphless_method
= Qnil
;
6660 it
->what
= IT_GLYPHLESS
;
6661 return glyphless_method
;
6664 /* Merge escape glyph face and cache the result. */
6666 static struct frame
*last_escape_glyph_frame
= NULL
;
6667 static int last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
6668 static int last_escape_glyph_merged_face_id
= 0;
6671 merge_escape_glyph_face (struct it
*it
)
6675 if (it
->f
== last_escape_glyph_frame
6676 && it
->face_id
== last_escape_glyph_face_id
)
6677 face_id
= last_escape_glyph_merged_face_id
;
6680 /* Merge the `escape-glyph' face into the current face. */
6681 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0, it
->face_id
);
6682 last_escape_glyph_frame
= it
->f
;
6683 last_escape_glyph_face_id
= it
->face_id
;
6684 last_escape_glyph_merged_face_id
= face_id
;
6689 /* Likewise for glyphless glyph face. */
6691 static struct frame
*last_glyphless_glyph_frame
= NULL
;
6692 static int last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
6693 static int last_glyphless_glyph_merged_face_id
= 0;
6696 merge_glyphless_glyph_face (struct it
*it
)
6700 if (it
->f
== last_glyphless_glyph_frame
6701 && it
->face_id
== last_glyphless_glyph_face_id
)
6702 face_id
= last_glyphless_glyph_merged_face_id
;
6705 /* Merge the `glyphless-char' face into the current face. */
6706 face_id
= merge_faces (it
->f
, Qglyphless_char
, 0, it
->face_id
);
6707 last_glyphless_glyph_frame
= it
->f
;
6708 last_glyphless_glyph_face_id
= it
->face_id
;
6709 last_glyphless_glyph_merged_face_id
= face_id
;
6714 /* Load IT's display element fields with information about the next
6715 display element from the current position of IT. Value is zero if
6716 end of buffer (or C string) is reached. */
6719 get_next_display_element (struct it
*it
)
6721 /* Non-zero means that we found a display element. Zero means that
6722 we hit the end of what we iterate over. Performance note: the
6723 function pointer `method' used here turns out to be faster than
6724 using a sequence of if-statements. */
6728 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6730 if (it
->what
== IT_CHARACTER
)
6732 /* UAX#9, L4: "A character is depicted by a mirrored glyph if
6733 and only if (a) the resolved directionality of that character
6735 /* FIXME: Do we need an exception for characters from display
6737 if (it
->bidi_p
&& it
->bidi_it
.type
== STRONG_R
)
6738 it
->c
= bidi_mirror_char (it
->c
);
6739 /* Map via display table or translate control characters.
6740 IT->c, IT->len etc. have been set to the next character by
6741 the function call above. If we have a display table, and it
6742 contains an entry for IT->c, translate it. Don't do this if
6743 IT->c itself comes from a display table, otherwise we could
6744 end up in an infinite recursion. (An alternative could be to
6745 count the recursion depth of this function and signal an
6746 error when a certain maximum depth is reached.) Is it worth
6748 if (success_p
&& it
->dpvec
== NULL
)
6751 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
6752 int nonascii_space_p
= 0;
6753 int nonascii_hyphen_p
= 0;
6754 int c
= it
->c
; /* This is the character to display. */
6756 if (! it
->multibyte_p
&& ! ASCII_CHAR_P (c
))
6758 eassert (SINGLE_BYTE_CHAR_P (c
));
6759 if (unibyte_display_via_language_environment
)
6761 c
= DECODE_CHAR (unibyte
, c
);
6763 c
= BYTE8_TO_CHAR (it
->c
);
6766 c
= BYTE8_TO_CHAR (it
->c
);
6770 && (dv
= DISP_CHAR_VECTOR (it
->dp
, c
),
6773 struct Lisp_Vector
*v
= XVECTOR (dv
);
6775 /* Return the first character from the display table
6776 entry, if not empty. If empty, don't display the
6777 current character. */
6780 it
->dpvec_char_len
= it
->len
;
6781 it
->dpvec
= v
->contents
;
6782 it
->dpend
= v
->contents
+ v
->header
.size
;
6783 it
->current
.dpvec_index
= 0;
6784 it
->dpvec_face_id
= -1;
6785 it
->saved_face_id
= it
->face_id
;
6786 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6791 set_iterator_to_next (it
, 0);
6796 if (! NILP (lookup_glyphless_char_display (c
, it
)))
6798 if (it
->what
== IT_GLYPHLESS
)
6800 /* Don't display this character. */
6801 set_iterator_to_next (it
, 0);
6805 /* If `nobreak-char-display' is non-nil, we display
6806 non-ASCII spaces and hyphens specially. */
6807 if (! ASCII_CHAR_P (c
) && ! NILP (Vnobreak_char_display
))
6810 nonascii_space_p
= true;
6811 else if (c
== 0xAD || c
== 0x2010 || c
== 0x2011)
6812 nonascii_hyphen_p
= true;
6815 /* Translate control characters into `\003' or `^C' form.
6816 Control characters coming from a display table entry are
6817 currently not translated because we use IT->dpvec to hold
6818 the translation. This could easily be changed but I
6819 don't believe that it is worth doing.
6821 The characters handled by `nobreak-char-display' must be
6824 Non-printable characters and raw-byte characters are also
6825 translated to octal form. */
6826 if (((c
< ' ' || c
== 127) /* ASCII control chars. */
6827 ? (it
->area
!= TEXT_AREA
6828 /* In mode line, treat \n, \t like other crl chars. */
6831 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
6832 || (c
!= '\n' && c
!= '\t'))
6834 || nonascii_hyphen_p
6836 || ! CHAR_PRINTABLE_P (c
))))
6838 /* C is a control character, non-ASCII space/hyphen,
6839 raw-byte, or a non-printable character which must be
6840 displayed either as '\003' or as `^C' where the '\\'
6841 and '^' can be defined in the display table. Fill
6842 IT->ctl_chars with glyphs for what we have to
6843 display. Then, set IT->dpvec to these glyphs. */
6850 /* Handle control characters with ^. */
6852 if (ASCII_CHAR_P (c
) && it
->ctl_arrow_p
)
6856 g
= '^'; /* default glyph for Control */
6857 /* Set IT->ctl_chars[0] to the glyph for `^'. */
6859 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
6861 g
= GLYPH_CODE_CHAR (gc
);
6862 lface_id
= GLYPH_CODE_FACE (gc
);
6866 ? merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
)
6867 : merge_escape_glyph_face (it
));
6869 XSETINT (it
->ctl_chars
[0], g
);
6870 XSETINT (it
->ctl_chars
[1], c
^ 0100);
6872 goto display_control
;
6875 /* Handle non-ascii space in the mode where it only gets
6878 if (nonascii_space_p
&& EQ (Vnobreak_char_display
, Qt
))
6880 /* Merge `nobreak-space' into the current face. */
6881 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
6883 XSETINT (it
->ctl_chars
[0], ' ');
6885 goto display_control
;
6888 /* Handle sequences that start with the "escape glyph". */
6890 /* the default escape glyph is \. */
6891 escape_glyph
= '\\';
6894 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
6896 escape_glyph
= GLYPH_CODE_CHAR (gc
);
6897 lface_id
= GLYPH_CODE_FACE (gc
);
6901 ? merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
)
6902 : merge_escape_glyph_face (it
));
6904 /* Draw non-ASCII hyphen with just highlighting: */
6906 if (nonascii_hyphen_p
&& EQ (Vnobreak_char_display
, Qt
))
6908 XSETINT (it
->ctl_chars
[0], '-');
6910 goto display_control
;
6913 /* Draw non-ASCII space/hyphen with escape glyph: */
6915 if (nonascii_space_p
|| nonascii_hyphen_p
)
6917 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6918 XSETINT (it
->ctl_chars
[1], nonascii_space_p
? ' ' : '-');
6920 goto display_control
;
6927 if (CHAR_BYTE8_P (c
))
6928 /* Display \200 instead of \17777600. */
6929 c
= CHAR_TO_BYTE8 (c
);
6930 len
= sprintf (str
, "%03o", c
);
6932 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6933 for (i
= 0; i
< len
; i
++)
6934 XSETINT (it
->ctl_chars
[i
+ 1], str
[i
]);
6939 /* Set up IT->dpvec and return first character from it. */
6940 it
->dpvec_char_len
= it
->len
;
6941 it
->dpvec
= it
->ctl_chars
;
6942 it
->dpend
= it
->dpvec
+ ctl_len
;
6943 it
->current
.dpvec_index
= 0;
6944 it
->dpvec_face_id
= face_id
;
6945 it
->saved_face_id
= it
->face_id
;
6946 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6950 it
->char_to_display
= c
;
6954 it
->char_to_display
= it
->c
;
6958 #ifdef HAVE_WINDOW_SYSTEM
6959 /* Adjust face id for a multibyte character. There are no multibyte
6960 character in unibyte text. */
6961 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
6964 && FRAME_WINDOW_P (it
->f
))
6966 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
6968 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
6970 /* Automatic composition with glyph-string. */
6971 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
6973 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
6977 ptrdiff_t pos
= (it
->s
? -1
6978 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
6979 : IT_CHARPOS (*it
));
6982 if (it
->what
== IT_CHARACTER
)
6983 c
= it
->char_to_display
;
6986 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
6990 for (i
= 0; i
< cmp
->glyph_len
; i
++)
6991 /* TAB in a composition means display glyphs with
6992 padding space on the left or right. */
6993 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
6996 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, pos
, it
->string
);
6999 #endif /* HAVE_WINDOW_SYSTEM */
7002 /* Is this character the last one of a run of characters with
7003 box? If yes, set IT->end_of_box_run_p to 1. */
7007 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
7009 int face_id
= underlying_face_id (it
);
7010 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
7014 if (face
->box
== FACE_NO_BOX
)
7016 /* If the box comes from face properties in a
7017 display string, check faces in that string. */
7018 int string_face_id
= face_after_it_pos (it
);
7019 it
->end_of_box_run_p
7020 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
7023 /* Otherwise, the box comes from the underlying face.
7024 If this is the last string character displayed, check
7025 the next buffer location. */
7026 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
7027 && (it
->current
.overlay_string_index
7028 == it
->n_overlay_strings
- 1))
7032 struct text_pos pos
= it
->current
.pos
;
7033 INC_TEXT_POS (pos
, it
->multibyte_p
);
7035 next_face_id
= face_at_buffer_position
7036 (it
->w
, CHARPOS (pos
), &ignore
,
7037 (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
), 0,
7039 it
->end_of_box_run_p
7040 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
7045 /* next_element_from_display_vector sets this flag according to
7046 faces of the display vector glyphs, see there. */
7047 else if (it
->method
!= GET_FROM_DISPLAY_VECTOR
)
7049 int face_id
= face_after_it_pos (it
);
7050 it
->end_of_box_run_p
7051 = (face_id
!= it
->face_id
7052 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
7055 /* If we reached the end of the object we've been iterating (e.g., a
7056 display string or an overlay string), and there's something on
7057 IT->stack, proceed with what's on the stack. It doesn't make
7058 sense to return zero if there's unprocessed stuff on the stack,
7059 because otherwise that stuff will never be displayed. */
7060 if (!success_p
&& it
->sp
> 0)
7062 set_iterator_to_next (it
, 0);
7063 success_p
= get_next_display_element (it
);
7066 /* Value is 0 if end of buffer or string reached. */
7071 /* Move IT to the next display element.
7073 RESEAT_P non-zero means if called on a newline in buffer text,
7074 skip to the next visible line start.
7076 Functions get_next_display_element and set_iterator_to_next are
7077 separate because I find this arrangement easier to handle than a
7078 get_next_display_element function that also increments IT's
7079 position. The way it is we can first look at an iterator's current
7080 display element, decide whether it fits on a line, and if it does,
7081 increment the iterator position. The other way around we probably
7082 would either need a flag indicating whether the iterator has to be
7083 incremented the next time, or we would have to implement a
7084 decrement position function which would not be easy to write. */
7087 set_iterator_to_next (struct it
*it
, int reseat_p
)
7089 /* Reset flags indicating start and end of a sequence of characters
7090 with box. Reset them at the start of this function because
7091 moving the iterator to a new position might set them. */
7092 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
7096 case GET_FROM_BUFFER
:
7097 /* The current display element of IT is a character from
7098 current_buffer. Advance in the buffer, and maybe skip over
7099 invisible lines that are so because of selective display. */
7100 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
7101 reseat_at_next_visible_line_start (it
, 0);
7102 else if (it
->cmp_it
.id
>= 0)
7104 /* We are currently getting glyphs from a composition. */
7109 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7110 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7111 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7113 it
->cmp_it
.from
= it
->cmp_it
.to
;
7118 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7120 it
->end_charpos
, Qnil
);
7123 else if (! it
->cmp_it
.reversed_p
)
7125 /* Composition created while scanning forward. */
7126 /* Update IT's char/byte positions to point to the first
7127 character of the next grapheme cluster, or to the
7128 character visually after the current composition. */
7129 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7130 bidi_move_to_visually_next (&it
->bidi_it
);
7131 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7132 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7134 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7136 /* Proceed to the next grapheme cluster. */
7137 it
->cmp_it
.from
= it
->cmp_it
.to
;
7141 /* No more grapheme clusters in this composition.
7142 Find the next stop position. */
7143 ptrdiff_t stop
= it
->end_charpos
;
7144 if (it
->bidi_it
.scan_dir
< 0)
7145 /* Now we are scanning backward and don't know
7148 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7149 IT_BYTEPOS (*it
), stop
, Qnil
);
7154 /* Composition created while scanning backward. */
7155 /* Update IT's char/byte positions to point to the last
7156 character of the previous grapheme cluster, or the
7157 character visually after the current composition. */
7158 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7159 bidi_move_to_visually_next (&it
->bidi_it
);
7160 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7161 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7162 if (it
->cmp_it
.from
> 0)
7164 /* Proceed to the previous grapheme cluster. */
7165 it
->cmp_it
.to
= it
->cmp_it
.from
;
7169 /* No more grapheme clusters in this composition.
7170 Find the next stop position. */
7171 ptrdiff_t stop
= it
->end_charpos
;
7172 if (it
->bidi_it
.scan_dir
< 0)
7173 /* Now we are scanning backward and don't know
7176 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7177 IT_BYTEPOS (*it
), stop
, Qnil
);
7183 eassert (it
->len
!= 0);
7187 IT_BYTEPOS (*it
) += it
->len
;
7188 IT_CHARPOS (*it
) += 1;
7192 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7193 /* If this is a new paragraph, determine its base
7194 direction (a.k.a. its base embedding level). */
7195 if (it
->bidi_it
.new_paragraph
)
7196 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
7197 bidi_move_to_visually_next (&it
->bidi_it
);
7198 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7199 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7200 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7202 /* As the scan direction was changed, we must
7203 re-compute the stop position for composition. */
7204 ptrdiff_t stop
= it
->end_charpos
;
7205 if (it
->bidi_it
.scan_dir
< 0)
7207 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7208 IT_BYTEPOS (*it
), stop
, Qnil
);
7211 eassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
7215 case GET_FROM_C_STRING
:
7216 /* Current display element of IT is from a C string. */
7218 /* If the string position is beyond string's end, it means
7219 next_element_from_c_string is padding the string with
7220 blanks, in which case we bypass the bidi iterator,
7221 because it cannot deal with such virtual characters. */
7222 || IT_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7224 IT_BYTEPOS (*it
) += it
->len
;
7225 IT_CHARPOS (*it
) += 1;
7229 bidi_move_to_visually_next (&it
->bidi_it
);
7230 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7231 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7235 case GET_FROM_DISPLAY_VECTOR
:
7236 /* Current display element of IT is from a display table entry.
7237 Advance in the display table definition. Reset it to null if
7238 end reached, and continue with characters from buffers/
7240 ++it
->current
.dpvec_index
;
7242 /* Restore face of the iterator to what they were before the
7243 display vector entry (these entries may contain faces). */
7244 it
->face_id
= it
->saved_face_id
;
7246 if (it
->dpvec
+ it
->current
.dpvec_index
>= it
->dpend
)
7248 int recheck_faces
= it
->ellipsis_p
;
7251 it
->method
= GET_FROM_C_STRING
;
7252 else if (STRINGP (it
->string
))
7253 it
->method
= GET_FROM_STRING
;
7256 it
->method
= GET_FROM_BUFFER
;
7257 it
->object
= it
->w
->contents
;
7261 it
->current
.dpvec_index
= -1;
7263 /* Skip over characters which were displayed via IT->dpvec. */
7264 if (it
->dpvec_char_len
< 0)
7265 reseat_at_next_visible_line_start (it
, 1);
7266 else if (it
->dpvec_char_len
> 0)
7268 if (it
->method
== GET_FROM_STRING
7269 && it
->current
.overlay_string_index
>= 0
7270 && it
->n_overlay_strings
> 0)
7271 it
->ignore_overlay_strings_at_pos_p
= true;
7272 it
->len
= it
->dpvec_char_len
;
7273 set_iterator_to_next (it
, reseat_p
);
7276 /* Maybe recheck faces after display vector. */
7278 it
->stop_charpos
= IT_CHARPOS (*it
);
7282 case GET_FROM_STRING
:
7283 /* Current display element is a character from a Lisp string. */
7284 eassert (it
->s
== NULL
&& STRINGP (it
->string
));
7285 /* Don't advance past string end. These conditions are true
7286 when set_iterator_to_next is called at the end of
7287 get_next_display_element, in which case the Lisp string is
7288 already exhausted, and all we want is pop the iterator
7290 if (it
->current
.overlay_string_index
>= 0)
7292 /* This is an overlay string, so there's no padding with
7293 spaces, and the number of characters in the string is
7294 where the string ends. */
7295 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7296 goto consider_string_end
;
7300 /* Not an overlay string. There could be padding, so test
7301 against it->end_charpos. */
7302 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7303 goto consider_string_end
;
7305 if (it
->cmp_it
.id
>= 0)
7311 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7312 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7313 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7314 it
->cmp_it
.from
= it
->cmp_it
.to
;
7318 composition_compute_stop_pos (&it
->cmp_it
,
7319 IT_STRING_CHARPOS (*it
),
7320 IT_STRING_BYTEPOS (*it
),
7321 it
->end_charpos
, it
->string
);
7324 else if (! it
->cmp_it
.reversed_p
)
7326 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7327 bidi_move_to_visually_next (&it
->bidi_it
);
7328 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7329 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7331 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7332 it
->cmp_it
.from
= it
->cmp_it
.to
;
7335 ptrdiff_t stop
= it
->end_charpos
;
7336 if (it
->bidi_it
.scan_dir
< 0)
7338 composition_compute_stop_pos (&it
->cmp_it
,
7339 IT_STRING_CHARPOS (*it
),
7340 IT_STRING_BYTEPOS (*it
), stop
,
7346 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7347 bidi_move_to_visually_next (&it
->bidi_it
);
7348 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7349 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7350 if (it
->cmp_it
.from
> 0)
7351 it
->cmp_it
.to
= it
->cmp_it
.from
;
7354 ptrdiff_t stop
= it
->end_charpos
;
7355 if (it
->bidi_it
.scan_dir
< 0)
7357 composition_compute_stop_pos (&it
->cmp_it
,
7358 IT_STRING_CHARPOS (*it
),
7359 IT_STRING_BYTEPOS (*it
), stop
,
7367 /* If the string position is beyond string's end, it
7368 means next_element_from_string is padding the string
7369 with blanks, in which case we bypass the bidi
7370 iterator, because it cannot deal with such virtual
7372 || IT_STRING_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7374 IT_STRING_BYTEPOS (*it
) += it
->len
;
7375 IT_STRING_CHARPOS (*it
) += 1;
7379 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7381 bidi_move_to_visually_next (&it
->bidi_it
);
7382 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7383 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7384 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7386 ptrdiff_t stop
= it
->end_charpos
;
7388 if (it
->bidi_it
.scan_dir
< 0)
7390 composition_compute_stop_pos (&it
->cmp_it
,
7391 IT_STRING_CHARPOS (*it
),
7392 IT_STRING_BYTEPOS (*it
), stop
,
7398 consider_string_end
:
7400 if (it
->current
.overlay_string_index
>= 0)
7402 /* IT->string is an overlay string. Advance to the
7403 next, if there is one. */
7404 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7407 next_overlay_string (it
);
7409 setup_for_ellipsis (it
, 0);
7414 /* IT->string is not an overlay string. If we reached
7415 its end, and there is something on IT->stack, proceed
7416 with what is on the stack. This can be either another
7417 string, this time an overlay string, or a buffer. */
7418 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
7422 if (it
->method
== GET_FROM_STRING
)
7423 goto consider_string_end
;
7428 case GET_FROM_IMAGE
:
7429 case GET_FROM_STRETCH
:
7430 /* The position etc with which we have to proceed are on
7431 the stack. The position may be at the end of a string,
7432 if the `display' property takes up the whole string. */
7433 eassert (it
->sp
> 0);
7435 if (it
->method
== GET_FROM_STRING
)
7436 goto consider_string_end
;
7440 /* There are no other methods defined, so this should be a bug. */
7444 eassert (it
->method
!= GET_FROM_STRING
7445 || (STRINGP (it
->string
)
7446 && IT_STRING_CHARPOS (*it
) >= 0));
7449 /* Load IT's display element fields with information about the next
7450 display element which comes from a display table entry or from the
7451 result of translating a control character to one of the forms `^C'
7454 IT->dpvec holds the glyphs to return as characters.
7455 IT->saved_face_id holds the face id before the display vector--it
7456 is restored into IT->face_id in set_iterator_to_next. */
7459 next_element_from_display_vector (struct it
*it
)
7462 int prev_face_id
= it
->face_id
;
7466 eassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
7468 it
->face_id
= it
->saved_face_id
;
7470 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
7471 That seemed totally bogus - so I changed it... */
7472 gc
= it
->dpvec
[it
->current
.dpvec_index
];
7474 if (GLYPH_CODE_P (gc
))
7476 struct face
*this_face
, *prev_face
, *next_face
;
7478 it
->c
= GLYPH_CODE_CHAR (gc
);
7479 it
->len
= CHAR_BYTES (it
->c
);
7481 /* The entry may contain a face id to use. Such a face id is
7482 the id of a Lisp face, not a realized face. A face id of
7483 zero means no face is specified. */
7484 if (it
->dpvec_face_id
>= 0)
7485 it
->face_id
= it
->dpvec_face_id
;
7488 int lface_id
= GLYPH_CODE_FACE (gc
);
7490 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
7494 /* Glyphs in the display vector could have the box face, so we
7495 need to set the related flags in the iterator, as
7497 this_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
7498 prev_face
= FACE_FROM_ID (it
->f
, prev_face_id
);
7500 /* Is this character the first character of a box-face run? */
7501 it
->start_of_box_run_p
= (this_face
&& this_face
->box
!= FACE_NO_BOX
7503 || prev_face
->box
== FACE_NO_BOX
));
7505 /* For the last character of the box-face run, we need to look
7506 either at the next glyph from the display vector, or at the
7507 face we saw before the display vector. */
7508 next_face_id
= it
->saved_face_id
;
7509 if (it
->current
.dpvec_index
< it
->dpend
- it
->dpvec
- 1)
7511 if (it
->dpvec_face_id
>= 0)
7512 next_face_id
= it
->dpvec_face_id
;
7516 GLYPH_CODE_FACE (it
->dpvec
[it
->current
.dpvec_index
+ 1]);
7519 next_face_id
= merge_faces (it
->f
, Qt
, lface_id
,
7523 next_face
= FACE_FROM_ID (it
->f
, next_face_id
);
7524 it
->end_of_box_run_p
= (this_face
&& this_face
->box
!= FACE_NO_BOX
7526 || next_face
->box
== FACE_NO_BOX
));
7527 it
->face_box_p
= this_face
&& this_face
->box
!= FACE_NO_BOX
;
7530 /* Display table entry is invalid. Return a space. */
7531 it
->c
= ' ', it
->len
= 1;
7533 /* Don't change position and object of the iterator here. They are
7534 still the values of the character that had this display table
7535 entry or was translated, and that's what we want. */
7536 it
->what
= IT_CHARACTER
;
7540 /* Get the first element of string/buffer in the visual order, after
7541 being reseated to a new position in a string or a buffer. */
7543 get_visually_first_element (struct it
*it
)
7545 int string_p
= STRINGP (it
->string
) || it
->s
;
7546 ptrdiff_t eob
= (string_p
? it
->bidi_it
.string
.schars
: ZV
);
7547 ptrdiff_t bob
= (string_p
? 0 : BEGV
);
7549 if (STRINGP (it
->string
))
7551 it
->bidi_it
.charpos
= IT_STRING_CHARPOS (*it
);
7552 it
->bidi_it
.bytepos
= IT_STRING_BYTEPOS (*it
);
7556 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
7557 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
7560 if (it
->bidi_it
.charpos
== eob
)
7562 /* Nothing to do, but reset the FIRST_ELT flag, like
7563 bidi_paragraph_init does, because we are not going to
7565 it
->bidi_it
.first_elt
= 0;
7567 else if (it
->bidi_it
.charpos
== bob
7569 && (FETCH_CHAR (it
->bidi_it
.bytepos
- 1) == '\n'
7570 || FETCH_CHAR (it
->bidi_it
.bytepos
) == '\n')))
7572 /* If we are at the beginning of a line/string, we can produce
7573 the next element right away. */
7574 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7575 bidi_move_to_visually_next (&it
->bidi_it
);
7579 ptrdiff_t orig_bytepos
= it
->bidi_it
.bytepos
;
7581 /* We need to prime the bidi iterator starting at the line's or
7582 string's beginning, before we will be able to produce the
7585 it
->bidi_it
.charpos
= it
->bidi_it
.bytepos
= 0;
7587 it
->bidi_it
.charpos
= find_newline_no_quit (IT_CHARPOS (*it
),
7588 IT_BYTEPOS (*it
), -1,
7589 &it
->bidi_it
.bytepos
);
7590 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7593 /* Now return to buffer/string position where we were asked
7594 to get the next display element, and produce that. */
7595 bidi_move_to_visually_next (&it
->bidi_it
);
7597 while (it
->bidi_it
.bytepos
!= orig_bytepos
7598 && it
->bidi_it
.charpos
< eob
);
7601 /* Adjust IT's position information to where we ended up. */
7602 if (STRINGP (it
->string
))
7604 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7605 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7609 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7610 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7613 if (STRINGP (it
->string
) || !it
->s
)
7615 ptrdiff_t stop
, charpos
, bytepos
;
7617 if (STRINGP (it
->string
))
7620 stop
= SCHARS (it
->string
);
7621 if (stop
> it
->end_charpos
)
7622 stop
= it
->end_charpos
;
7623 charpos
= IT_STRING_CHARPOS (*it
);
7624 bytepos
= IT_STRING_BYTEPOS (*it
);
7628 stop
= it
->end_charpos
;
7629 charpos
= IT_CHARPOS (*it
);
7630 bytepos
= IT_BYTEPOS (*it
);
7632 if (it
->bidi_it
.scan_dir
< 0)
7634 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
, stop
,
7639 /* Load IT with the next display element from Lisp string IT->string.
7640 IT->current.string_pos is the current position within the string.
7641 If IT->current.overlay_string_index >= 0, the Lisp string is an
7645 next_element_from_string (struct it
*it
)
7647 struct text_pos position
;
7649 eassert (STRINGP (it
->string
));
7650 eassert (!it
->bidi_p
|| EQ (it
->string
, it
->bidi_it
.string
.lstring
));
7651 eassert (IT_STRING_CHARPOS (*it
) >= 0);
7652 position
= it
->current
.string_pos
;
7654 /* With bidi reordering, the character to display might not be the
7655 character at IT_STRING_CHARPOS. BIDI_IT.FIRST_ELT non-zero means
7656 that we were reseat()ed to a new string, whose paragraph
7657 direction is not known. */
7658 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7660 get_visually_first_element (it
);
7661 SET_TEXT_POS (position
, IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
));
7664 /* Time to check for invisible text? */
7665 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
7667 if (IT_STRING_CHARPOS (*it
) >= it
->stop_charpos
)
7670 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7671 || IT_STRING_CHARPOS (*it
) == it
->stop_charpos
))
7673 /* With bidi non-linear iteration, we could find
7674 ourselves far beyond the last computed stop_charpos,
7675 with several other stop positions in between that we
7676 missed. Scan them all now, in buffer's logical
7677 order, until we find and handle the last stop_charpos
7678 that precedes our current position. */
7679 handle_stop_backwards (it
, it
->stop_charpos
);
7680 return GET_NEXT_DISPLAY_ELEMENT (it
);
7686 /* Take note of the stop position we just moved
7687 across, for when we will move back across it. */
7688 it
->prev_stop
= it
->stop_charpos
;
7689 /* If we are at base paragraph embedding level, take
7690 note of the last stop position seen at this
7692 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7693 it
->base_level_stop
= it
->stop_charpos
;
7697 /* Since a handler may have changed IT->method, we must
7699 return GET_NEXT_DISPLAY_ELEMENT (it
);
7703 /* If we are before prev_stop, we may have overstepped
7704 on our way backwards a stop_pos, and if so, we need
7705 to handle that stop_pos. */
7706 && IT_STRING_CHARPOS (*it
) < it
->prev_stop
7707 /* We can sometimes back up for reasons that have nothing
7708 to do with bidi reordering. E.g., compositions. The
7709 code below is only needed when we are above the base
7710 embedding level, so test for that explicitly. */
7711 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7713 /* If we lost track of base_level_stop, we have no better
7714 place for handle_stop_backwards to start from than string
7715 beginning. This happens, e.g., when we were reseated to
7716 the previous screenful of text by vertical-motion. */
7717 if (it
->base_level_stop
<= 0
7718 || IT_STRING_CHARPOS (*it
) < it
->base_level_stop
)
7719 it
->base_level_stop
= 0;
7720 handle_stop_backwards (it
, it
->base_level_stop
);
7721 return GET_NEXT_DISPLAY_ELEMENT (it
);
7725 if (it
->current
.overlay_string_index
>= 0)
7727 /* Get the next character from an overlay string. In overlay
7728 strings, there is no field width or padding with spaces to
7730 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7735 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7736 IT_STRING_BYTEPOS (*it
),
7737 it
->bidi_it
.scan_dir
< 0
7739 : SCHARS (it
->string
))
7740 && next_element_from_composition (it
))
7744 else if (STRING_MULTIBYTE (it
->string
))
7746 const unsigned char *s
= (SDATA (it
->string
)
7747 + IT_STRING_BYTEPOS (*it
));
7748 it
->c
= string_char_and_length (s
, &it
->len
);
7752 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7758 /* Get the next character from a Lisp string that is not an
7759 overlay string. Such strings come from the mode line, for
7760 example. We may have to pad with spaces, or truncate the
7761 string. See also next_element_from_c_string. */
7762 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7767 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
7769 /* Pad with spaces. */
7770 it
->c
= ' ', it
->len
= 1;
7771 CHARPOS (position
) = BYTEPOS (position
) = -1;
7773 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7774 IT_STRING_BYTEPOS (*it
),
7775 it
->bidi_it
.scan_dir
< 0
7777 : it
->string_nchars
)
7778 && next_element_from_composition (it
))
7782 else if (STRING_MULTIBYTE (it
->string
))
7784 const unsigned char *s
= (SDATA (it
->string
)
7785 + IT_STRING_BYTEPOS (*it
));
7786 it
->c
= string_char_and_length (s
, &it
->len
);
7790 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7795 /* Record what we have and where it came from. */
7796 it
->what
= IT_CHARACTER
;
7797 it
->object
= it
->string
;
7798 it
->position
= position
;
7803 /* Load IT with next display element from C string IT->s.
7804 IT->string_nchars is the maximum number of characters to return
7805 from the string. IT->end_charpos may be greater than
7806 IT->string_nchars when this function is called, in which case we
7807 may have to return padding spaces. Value is zero if end of string
7808 reached, including padding spaces. */
7811 next_element_from_c_string (struct it
*it
)
7813 bool success_p
= true;
7816 eassert (!it
->bidi_p
|| it
->s
== it
->bidi_it
.string
.s
);
7817 it
->what
= IT_CHARACTER
;
7818 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
7821 /* With bidi reordering, the character to display might not be the
7822 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7823 we were reseated to a new string, whose paragraph direction is
7825 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7826 get_visually_first_element (it
);
7828 /* IT's position can be greater than IT->string_nchars in case a
7829 field width or precision has been specified when the iterator was
7831 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7833 /* End of the game. */
7837 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
7839 /* Pad with spaces. */
7840 it
->c
= ' ', it
->len
= 1;
7841 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
7843 else if (it
->multibyte_p
)
7844 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
), &it
->len
);
7846 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
7852 /* Set up IT to return characters from an ellipsis, if appropriate.
7853 The definition of the ellipsis glyphs may come from a display table
7854 entry. This function fills IT with the first glyph from the
7855 ellipsis if an ellipsis is to be displayed. */
7858 next_element_from_ellipsis (struct it
*it
)
7860 if (it
->selective_display_ellipsis_p
)
7861 setup_for_ellipsis (it
, it
->len
);
7864 /* The face at the current position may be different from the
7865 face we find after the invisible text. Remember what it
7866 was in IT->saved_face_id, and signal that it's there by
7867 setting face_before_selective_p. */
7868 it
->saved_face_id
= it
->face_id
;
7869 it
->method
= GET_FROM_BUFFER
;
7870 it
->object
= it
->w
->contents
;
7871 reseat_at_next_visible_line_start (it
, 1);
7872 it
->face_before_selective_p
= true;
7875 return GET_NEXT_DISPLAY_ELEMENT (it
);
7879 /* Deliver an image display element. The iterator IT is already
7880 filled with image information (done in handle_display_prop). Value
7885 next_element_from_image (struct it
*it
)
7887 it
->what
= IT_IMAGE
;
7888 it
->ignore_overlay_strings_at_pos_p
= 0;
7893 /* Fill iterator IT with next display element from a stretch glyph
7894 property. IT->object is the value of the text property. Value is
7898 next_element_from_stretch (struct it
*it
)
7900 it
->what
= IT_STRETCH
;
7904 /* Scan backwards from IT's current position until we find a stop
7905 position, or until BEGV. This is called when we find ourself
7906 before both the last known prev_stop and base_level_stop while
7907 reordering bidirectional text. */
7910 compute_stop_pos_backwards (struct it
*it
)
7912 const int SCAN_BACK_LIMIT
= 1000;
7913 struct text_pos pos
;
7914 struct display_pos save_current
= it
->current
;
7915 struct text_pos save_position
= it
->position
;
7916 ptrdiff_t charpos
= IT_CHARPOS (*it
);
7917 ptrdiff_t where_we_are
= charpos
;
7918 ptrdiff_t save_stop_pos
= it
->stop_charpos
;
7919 ptrdiff_t save_end_pos
= it
->end_charpos
;
7921 eassert (NILP (it
->string
) && !it
->s
);
7922 eassert (it
->bidi_p
);
7926 it
->end_charpos
= min (charpos
+ 1, ZV
);
7927 charpos
= max (charpos
- SCAN_BACK_LIMIT
, BEGV
);
7928 SET_TEXT_POS (pos
, charpos
, CHAR_TO_BYTE (charpos
));
7929 reseat_1 (it
, pos
, 0);
7930 compute_stop_pos (it
);
7931 /* We must advance forward, right? */
7932 if (it
->stop_charpos
<= charpos
)
7935 while (charpos
> BEGV
&& it
->stop_charpos
>= it
->end_charpos
);
7937 if (it
->stop_charpos
<= where_we_are
)
7938 it
->prev_stop
= it
->stop_charpos
;
7940 it
->prev_stop
= BEGV
;
7942 it
->current
= save_current
;
7943 it
->position
= save_position
;
7944 it
->stop_charpos
= save_stop_pos
;
7945 it
->end_charpos
= save_end_pos
;
7948 /* Scan forward from CHARPOS in the current buffer/string, until we
7949 find a stop position > current IT's position. Then handle the stop
7950 position before that. This is called when we bump into a stop
7951 position while reordering bidirectional text. CHARPOS should be
7952 the last previously processed stop_pos (or BEGV/0, if none were
7953 processed yet) whose position is less that IT's current
7957 handle_stop_backwards (struct it
*it
, ptrdiff_t charpos
)
7959 int bufp
= !STRINGP (it
->string
);
7960 ptrdiff_t where_we_are
= (bufp
? IT_CHARPOS (*it
) : IT_STRING_CHARPOS (*it
));
7961 struct display_pos save_current
= it
->current
;
7962 struct text_pos save_position
= it
->position
;
7963 struct text_pos pos1
;
7964 ptrdiff_t next_stop
;
7966 /* Scan in strict logical order. */
7967 eassert (it
->bidi_p
);
7971 it
->prev_stop
= charpos
;
7974 SET_TEXT_POS (pos1
, charpos
, CHAR_TO_BYTE (charpos
));
7975 reseat_1 (it
, pos1
, 0);
7978 it
->current
.string_pos
= string_pos (charpos
, it
->string
);
7979 compute_stop_pos (it
);
7980 /* We must advance forward, right? */
7981 if (it
->stop_charpos
<= it
->prev_stop
)
7983 charpos
= it
->stop_charpos
;
7985 while (charpos
<= where_we_are
);
7988 it
->current
= save_current
;
7989 it
->position
= save_position
;
7990 next_stop
= it
->stop_charpos
;
7991 it
->stop_charpos
= it
->prev_stop
;
7993 it
->stop_charpos
= next_stop
;
7996 /* Load IT with the next display element from current_buffer. Value
7997 is zero if end of buffer reached. IT->stop_charpos is the next
7998 position at which to stop and check for text properties or buffer
8002 next_element_from_buffer (struct it
*it
)
8004 bool success_p
= true;
8006 eassert (IT_CHARPOS (*it
) >= BEGV
);
8007 eassert (NILP (it
->string
) && !it
->s
);
8008 eassert (!it
->bidi_p
8009 || (EQ (it
->bidi_it
.string
.lstring
, Qnil
)
8010 && it
->bidi_it
.string
.s
== NULL
));
8012 /* With bidi reordering, the character to display might not be the
8013 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
8014 we were reseat()ed to a new buffer position, which is potentially
8015 a different paragraph. */
8016 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
8018 get_visually_first_element (it
);
8019 SET_TEXT_POS (it
->position
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8022 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
8024 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
8026 int overlay_strings_follow_p
;
8028 /* End of the game, except when overlay strings follow that
8029 haven't been returned yet. */
8030 if (it
->overlay_strings_at_end_processed_p
)
8031 overlay_strings_follow_p
= 0;
8034 it
->overlay_strings_at_end_processed_p
= true;
8035 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
8038 if (overlay_strings_follow_p
)
8039 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
8043 it
->position
= it
->current
.pos
;
8047 else if (!(!it
->bidi_p
8048 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
8049 || IT_CHARPOS (*it
) == it
->stop_charpos
))
8051 /* With bidi non-linear iteration, we could find ourselves
8052 far beyond the last computed stop_charpos, with several
8053 other stop positions in between that we missed. Scan
8054 them all now, in buffer's logical order, until we find
8055 and handle the last stop_charpos that precedes our
8056 current position. */
8057 handle_stop_backwards (it
, it
->stop_charpos
);
8058 return GET_NEXT_DISPLAY_ELEMENT (it
);
8064 /* Take note of the stop position we just moved across,
8065 for when we will move back across it. */
8066 it
->prev_stop
= it
->stop_charpos
;
8067 /* If we are at base paragraph embedding level, take
8068 note of the last stop position seen at this
8070 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8071 it
->base_level_stop
= it
->stop_charpos
;
8074 return GET_NEXT_DISPLAY_ELEMENT (it
);
8078 /* If we are before prev_stop, we may have overstepped on
8079 our way backwards a stop_pos, and if so, we need to
8080 handle that stop_pos. */
8081 && IT_CHARPOS (*it
) < it
->prev_stop
8082 /* We can sometimes back up for reasons that have nothing
8083 to do with bidi reordering. E.g., compositions. The
8084 code below is only needed when we are above the base
8085 embedding level, so test for that explicitly. */
8086 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8088 if (it
->base_level_stop
<= 0
8089 || IT_CHARPOS (*it
) < it
->base_level_stop
)
8091 /* If we lost track of base_level_stop, we need to find
8092 prev_stop by looking backwards. This happens, e.g., when
8093 we were reseated to the previous screenful of text by
8095 it
->base_level_stop
= BEGV
;
8096 compute_stop_pos_backwards (it
);
8097 handle_stop_backwards (it
, it
->prev_stop
);
8100 handle_stop_backwards (it
, it
->base_level_stop
);
8101 return GET_NEXT_DISPLAY_ELEMENT (it
);
8105 /* No face changes, overlays etc. in sight, so just return a
8106 character from current_buffer. */
8110 /* Maybe run the redisplay end trigger hook. Performance note:
8111 This doesn't seem to cost measurable time. */
8112 if (it
->redisplay_end_trigger_charpos
8114 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
8115 run_redisplay_end_trigger_hook (it
);
8117 stop
= it
->bidi_it
.scan_dir
< 0 ? -1 : it
->end_charpos
;
8118 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
8120 && next_element_from_composition (it
))
8125 /* Get the next character, maybe multibyte. */
8126 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
8127 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
8128 it
->c
= STRING_CHAR_AND_LENGTH (p
, it
->len
);
8130 it
->c
= *p
, it
->len
= 1;
8132 /* Record what we have and where it came from. */
8133 it
->what
= IT_CHARACTER
;
8134 it
->object
= it
->w
->contents
;
8135 it
->position
= it
->current
.pos
;
8137 /* Normally we return the character found above, except when we
8138 really want to return an ellipsis for selective display. */
8143 /* A value of selective > 0 means hide lines indented more
8144 than that number of columns. */
8145 if (it
->selective
> 0
8146 && IT_CHARPOS (*it
) + 1 < ZV
8147 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
8148 IT_BYTEPOS (*it
) + 1,
8151 success_p
= next_element_from_ellipsis (it
);
8152 it
->dpvec_char_len
= -1;
8155 else if (it
->c
== '\r' && it
->selective
== -1)
8157 /* A value of selective == -1 means that everything from the
8158 CR to the end of the line is invisible, with maybe an
8159 ellipsis displayed for it. */
8160 success_p
= next_element_from_ellipsis (it
);
8161 it
->dpvec_char_len
= -1;
8166 /* Value is zero if end of buffer reached. */
8167 eassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
8172 /* Run the redisplay end trigger hook for IT. */
8175 run_redisplay_end_trigger_hook (struct it
*it
)
8177 Lisp_Object args
[3];
8179 /* IT->glyph_row should be non-null, i.e. we should be actually
8180 displaying something, or otherwise we should not run the hook. */
8181 eassert (it
->glyph_row
);
8183 /* Set up hook arguments. */
8184 args
[0] = Qredisplay_end_trigger_functions
;
8185 args
[1] = it
->window
;
8186 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
8187 it
->redisplay_end_trigger_charpos
= 0;
8189 /* Since we are *trying* to run these functions, don't try to run
8190 them again, even if they get an error. */
8191 wset_redisplay_end_trigger (it
->w
, Qnil
);
8192 Frun_hook_with_args (3, args
);
8194 /* Notice if it changed the face of the character we are on. */
8195 handle_face_prop (it
);
8199 /* Deliver a composition display element. Unlike the other
8200 next_element_from_XXX, this function is not registered in the array
8201 get_next_element[]. It is called from next_element_from_buffer and
8202 next_element_from_string when necessary. */
8205 next_element_from_composition (struct it
*it
)
8207 it
->what
= IT_COMPOSITION
;
8208 it
->len
= it
->cmp_it
.nbytes
;
8209 if (STRINGP (it
->string
))
8213 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
8214 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
8217 it
->position
= it
->current
.string_pos
;
8218 it
->object
= it
->string
;
8219 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
8220 IT_STRING_BYTEPOS (*it
), it
->string
);
8226 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
8227 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
8230 if (it
->bidi_it
.new_paragraph
)
8231 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
8232 /* Resync the bidi iterator with IT's new position.
8233 FIXME: this doesn't support bidirectional text. */
8234 while (it
->bidi_it
.charpos
< IT_CHARPOS (*it
))
8235 bidi_move_to_visually_next (&it
->bidi_it
);
8239 it
->position
= it
->current
.pos
;
8240 it
->object
= it
->w
->contents
;
8241 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
8242 IT_BYTEPOS (*it
), Qnil
);
8249 /***********************************************************************
8250 Moving an iterator without producing glyphs
8251 ***********************************************************************/
8253 /* Check if iterator is at a position corresponding to a valid buffer
8254 position after some move_it_ call. */
8256 #define IT_POS_VALID_AFTER_MOVE_P(it) \
8257 ((it)->method == GET_FROM_STRING \
8258 ? IT_STRING_CHARPOS (*it) == 0 \
8262 /* Move iterator IT to a specified buffer or X position within one
8263 line on the display without producing glyphs.
8265 OP should be a bit mask including some or all of these bits:
8266 MOVE_TO_X: Stop upon reaching x-position TO_X.
8267 MOVE_TO_POS: Stop upon reaching buffer or string position TO_CHARPOS.
8268 Regardless of OP's value, stop upon reaching the end of the display line.
8270 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
8271 This means, in particular, that TO_X includes window's horizontal
8274 The return value has several possible values that
8275 say what condition caused the scan to stop:
8277 MOVE_POS_MATCH_OR_ZV
8278 - when TO_POS or ZV was reached.
8281 -when TO_X was reached before TO_POS or ZV were reached.
8284 - when we reached the end of the display area and the line must
8288 - when we reached the end of the display area and the line is
8292 - when we stopped at a line end, i.e. a newline or a CR and selective
8295 static enum move_it_result
8296 move_it_in_display_line_to (struct it
*it
,
8297 ptrdiff_t to_charpos
, int to_x
,
8298 enum move_operation_enum op
)
8300 enum move_it_result result
= MOVE_UNDEFINED
;
8301 struct glyph_row
*saved_glyph_row
;
8302 struct it wrap_it
, atpos_it
, atx_it
, ppos_it
;
8303 void *wrap_data
= NULL
, *atpos_data
= NULL
, *atx_data
= NULL
;
8304 void *ppos_data
= NULL
;
8306 enum it_method prev_method
= it
->method
;
8307 ptrdiff_t prev_pos
= IT_CHARPOS (*it
);
8308 int saw_smaller_pos
= prev_pos
< to_charpos
;
8310 /* Don't produce glyphs in produce_glyphs. */
8311 saved_glyph_row
= it
->glyph_row
;
8312 it
->glyph_row
= NULL
;
8314 /* Use wrap_it to save a copy of IT wherever a word wrap could
8315 occur. Use atpos_it to save a copy of IT at the desired buffer
8316 position, if found, so that we can scan ahead and check if the
8317 word later overshoots the window edge. Use atx_it similarly, for
8323 /* Use ppos_it under bidi reordering to save a copy of IT for the
8324 position > CHARPOS that is the closest to CHARPOS. We restore
8325 that position in IT when we have scanned the entire display line
8326 without finding a match for CHARPOS and all the character
8327 positions are greater than CHARPOS. */
8330 SAVE_IT (ppos_it
, *it
, ppos_data
);
8331 SET_TEXT_POS (ppos_it
.current
.pos
, ZV
, ZV_BYTE
);
8332 if ((op
& MOVE_TO_POS
) && IT_CHARPOS (*it
) >= to_charpos
)
8333 SAVE_IT (ppos_it
, *it
, ppos_data
);
8336 #define BUFFER_POS_REACHED_P() \
8337 ((op & MOVE_TO_POS) != 0 \
8338 && BUFFERP (it->object) \
8339 && (IT_CHARPOS (*it) == to_charpos \
8341 || BIDI_AT_BASE_LEVEL (it->bidi_it)) \
8342 && IT_CHARPOS (*it) > to_charpos) \
8343 || (it->what == IT_COMPOSITION \
8344 && ((IT_CHARPOS (*it) > to_charpos \
8345 && to_charpos >= it->cmp_it.charpos) \
8346 || (IT_CHARPOS (*it) < to_charpos \
8347 && to_charpos <= it->cmp_it.charpos)))) \
8348 && (it->method == GET_FROM_BUFFER \
8349 || (it->method == GET_FROM_DISPLAY_VECTOR \
8350 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
8352 /* If there's a line-/wrap-prefix, handle it. */
8353 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
8354 && it
->current_y
< it
->last_visible_y
)
8355 handle_line_prefix (it
);
8357 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8358 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8362 int x
, i
, ascent
= 0, descent
= 0;
8364 /* Utility macro to reset an iterator with x, ascent, and descent. */
8365 #define IT_RESET_X_ASCENT_DESCENT(IT) \
8366 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
8367 (IT)->max_descent = descent)
8369 /* Stop if we move beyond TO_CHARPOS (after an image or a
8370 display string or stretch glyph). */
8371 if ((op
& MOVE_TO_POS
) != 0
8372 && BUFFERP (it
->object
)
8373 && it
->method
== GET_FROM_BUFFER
8375 /* When the iterator is at base embedding level, we
8376 are guaranteed that characters are delivered for
8377 display in strictly increasing order of their
8378 buffer positions. */
8379 || BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8380 && IT_CHARPOS (*it
) > to_charpos
)
8382 && (prev_method
== GET_FROM_IMAGE
8383 || prev_method
== GET_FROM_STRETCH
8384 || prev_method
== GET_FROM_STRING
)
8385 /* Passed TO_CHARPOS from left to right. */
8386 && ((prev_pos
< to_charpos
8387 && IT_CHARPOS (*it
) > to_charpos
)
8388 /* Passed TO_CHARPOS from right to left. */
8389 || (prev_pos
> to_charpos
8390 && IT_CHARPOS (*it
) < to_charpos
)))))
8392 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8394 result
= MOVE_POS_MATCH_OR_ZV
;
8397 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8398 /* If wrap_it is valid, the current position might be in a
8399 word that is wrapped. So, save the iterator in
8400 atpos_it and continue to see if wrapping happens. */
8401 SAVE_IT (atpos_it
, *it
, atpos_data
);
8404 /* Stop when ZV reached.
8405 We used to stop here when TO_CHARPOS reached as well, but that is
8406 too soon if this glyph does not fit on this line. So we handle it
8407 explicitly below. */
8408 if (!get_next_display_element (it
))
8410 result
= MOVE_POS_MATCH_OR_ZV
;
8414 if (it
->line_wrap
== TRUNCATE
)
8416 if (BUFFER_POS_REACHED_P ())
8418 result
= MOVE_POS_MATCH_OR_ZV
;
8424 if (it
->line_wrap
== WORD_WRAP
)
8426 if (IT_DISPLAYING_WHITESPACE (it
))
8430 /* We have reached a glyph that follows one or more
8431 whitespace characters. If the position is
8432 already found, we are done. */
8433 if (atpos_it
.sp
>= 0)
8435 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8436 result
= MOVE_POS_MATCH_OR_ZV
;
8441 RESTORE_IT (it
, &atx_it
, atx_data
);
8442 result
= MOVE_X_REACHED
;
8445 /* Otherwise, we can wrap here. */
8446 SAVE_IT (wrap_it
, *it
, wrap_data
);
8452 /* Remember the line height for the current line, in case
8453 the next element doesn't fit on the line. */
8454 ascent
= it
->max_ascent
;
8455 descent
= it
->max_descent
;
8457 /* The call to produce_glyphs will get the metrics of the
8458 display element IT is loaded with. Record the x-position
8459 before this display element, in case it doesn't fit on the
8463 PRODUCE_GLYPHS (it
);
8465 if (it
->area
!= TEXT_AREA
)
8467 prev_method
= it
->method
;
8468 if (it
->method
== GET_FROM_BUFFER
)
8469 prev_pos
= IT_CHARPOS (*it
);
8470 set_iterator_to_next (it
, 1);
8471 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8472 SET_TEXT_POS (this_line_min_pos
,
8473 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8475 && (op
& MOVE_TO_POS
)
8476 && IT_CHARPOS (*it
) > to_charpos
8477 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8478 SAVE_IT (ppos_it
, *it
, ppos_data
);
8482 /* The number of glyphs we get back in IT->nglyphs will normally
8483 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
8484 character on a terminal frame, or (iii) a line end. For the
8485 second case, IT->nglyphs - 1 padding glyphs will be present.
8486 (On X frames, there is only one glyph produced for a
8487 composite character.)
8489 The behavior implemented below means, for continuation lines,
8490 that as many spaces of a TAB as fit on the current line are
8491 displayed there. For terminal frames, as many glyphs of a
8492 multi-glyph character are displayed in the current line, too.
8493 This is what the old redisplay code did, and we keep it that
8494 way. Under X, the whole shape of a complex character must
8495 fit on the line or it will be completely displayed in the
8498 Note that both for tabs and padding glyphs, all glyphs have
8502 /* More than one glyph or glyph doesn't fit on line. All
8503 glyphs have the same width. */
8504 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
8506 int x_before_this_char
= x
;
8507 int hpos_before_this_char
= it
->hpos
;
8509 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
8511 new_x
= x
+ single_glyph_width
;
8513 /* We want to leave anything reaching TO_X to the caller. */
8514 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
8516 if (BUFFER_POS_REACHED_P ())
8518 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8519 goto buffer_pos_reached
;
8520 if (atpos_it
.sp
< 0)
8522 SAVE_IT (atpos_it
, *it
, atpos_data
);
8523 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8528 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8531 result
= MOVE_X_REACHED
;
8536 SAVE_IT (atx_it
, *it
, atx_data
);
8537 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
8542 if (/* Lines are continued. */
8543 it
->line_wrap
!= TRUNCATE
8544 && (/* And glyph doesn't fit on the line. */
8545 new_x
> it
->last_visible_x
8546 /* Or it fits exactly and we're on a window
8548 || (new_x
== it
->last_visible_x
8549 && FRAME_WINDOW_P (it
->f
)
8550 && ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
8551 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8552 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
8554 if (/* IT->hpos == 0 means the very first glyph
8555 doesn't fit on the line, e.g. a wide image. */
8557 || (new_x
== it
->last_visible_x
8558 && FRAME_WINDOW_P (it
->f
)))
8561 it
->current_x
= new_x
;
8563 /* The character's last glyph just barely fits
8565 if (i
== it
->nglyphs
- 1)
8567 /* If this is the destination position,
8568 return a position *before* it in this row,
8569 now that we know it fits in this row. */
8570 if (BUFFER_POS_REACHED_P ())
8572 if (it
->line_wrap
!= WORD_WRAP
8575 it
->hpos
= hpos_before_this_char
;
8576 it
->current_x
= x_before_this_char
;
8577 result
= MOVE_POS_MATCH_OR_ZV
;
8580 if (it
->line_wrap
== WORD_WRAP
8583 SAVE_IT (atpos_it
, *it
, atpos_data
);
8584 atpos_it
.current_x
= x_before_this_char
;
8585 atpos_it
.hpos
= hpos_before_this_char
;
8589 prev_method
= it
->method
;
8590 if (it
->method
== GET_FROM_BUFFER
)
8591 prev_pos
= IT_CHARPOS (*it
);
8592 set_iterator_to_next (it
, 1);
8593 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8594 SET_TEXT_POS (this_line_min_pos
,
8595 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8596 /* On graphical terminals, newlines may
8597 "overflow" into the fringe if
8598 overflow-newline-into-fringe is non-nil.
8599 On text terminals, and on graphical
8600 terminals with no right margin, newlines
8601 may overflow into the last glyph on the
8603 if (!FRAME_WINDOW_P (it
->f
)
8605 && it
->bidi_it
.paragraph_dir
== R2L
)
8606 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8607 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0
8608 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8610 if (!get_next_display_element (it
))
8612 result
= MOVE_POS_MATCH_OR_ZV
;
8615 if (BUFFER_POS_REACHED_P ())
8617 if (ITERATOR_AT_END_OF_LINE_P (it
))
8618 result
= MOVE_POS_MATCH_OR_ZV
;
8620 result
= MOVE_LINE_CONTINUED
;
8623 if (ITERATOR_AT_END_OF_LINE_P (it
)
8624 && (it
->line_wrap
!= WORD_WRAP
8627 result
= MOVE_NEWLINE_OR_CR
;
8634 IT_RESET_X_ASCENT_DESCENT (it
);
8636 if (wrap_it
.sp
>= 0)
8638 RESTORE_IT (it
, &wrap_it
, wrap_data
);
8643 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
8645 result
= MOVE_LINE_CONTINUED
;
8649 if (BUFFER_POS_REACHED_P ())
8651 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8652 goto buffer_pos_reached
;
8653 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8655 SAVE_IT (atpos_it
, *it
, atpos_data
);
8656 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8660 if (new_x
> it
->first_visible_x
)
8662 /* Glyph is visible. Increment number of glyphs that
8663 would be displayed. */
8668 if (result
!= MOVE_UNDEFINED
)
8671 else if (BUFFER_POS_REACHED_P ())
8674 IT_RESET_X_ASCENT_DESCENT (it
);
8675 result
= MOVE_POS_MATCH_OR_ZV
;
8678 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
8680 /* Stop when TO_X specified and reached. This check is
8681 necessary here because of lines consisting of a line end,
8682 only. The line end will not produce any glyphs and we
8683 would never get MOVE_X_REACHED. */
8684 eassert (it
->nglyphs
== 0);
8685 result
= MOVE_X_REACHED
;
8689 /* Is this a line end? If yes, we're done. */
8690 if (ITERATOR_AT_END_OF_LINE_P (it
))
8692 /* If we are past TO_CHARPOS, but never saw any character
8693 positions smaller than TO_CHARPOS, return
8694 MOVE_POS_MATCH_OR_ZV, like the unidirectional display
8696 if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0)
8698 if (!saw_smaller_pos
&& IT_CHARPOS (*it
) > to_charpos
)
8700 if (IT_CHARPOS (ppos_it
) < ZV
)
8702 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8703 result
= MOVE_POS_MATCH_OR_ZV
;
8706 goto buffer_pos_reached
;
8708 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
>= 0
8709 && IT_CHARPOS (*it
) > to_charpos
)
8710 goto buffer_pos_reached
;
8712 result
= MOVE_NEWLINE_OR_CR
;
8715 result
= MOVE_NEWLINE_OR_CR
;
8719 prev_method
= it
->method
;
8720 if (it
->method
== GET_FROM_BUFFER
)
8721 prev_pos
= IT_CHARPOS (*it
);
8722 /* The current display element has been consumed. Advance
8724 set_iterator_to_next (it
, 1);
8725 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8726 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8727 if (IT_CHARPOS (*it
) < to_charpos
)
8728 saw_smaller_pos
= 1;
8730 && (op
& MOVE_TO_POS
)
8731 && IT_CHARPOS (*it
) >= to_charpos
8732 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8733 SAVE_IT (ppos_it
, *it
, ppos_data
);
8735 /* Stop if lines are truncated and IT's current x-position is
8736 past the right edge of the window now. */
8737 if (it
->line_wrap
== TRUNCATE
8738 && it
->current_x
>= it
->last_visible_x
)
8740 if (!FRAME_WINDOW_P (it
->f
)
8741 || ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
8742 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8743 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0
8744 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8748 if ((at_eob_p
= !get_next_display_element (it
))
8749 || BUFFER_POS_REACHED_P ()
8750 /* If we are past TO_CHARPOS, but never saw any
8751 character positions smaller than TO_CHARPOS,
8752 return MOVE_POS_MATCH_OR_ZV, like the
8753 unidirectional display did. */
8754 || (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8756 && IT_CHARPOS (*it
) > to_charpos
))
8759 && !at_eob_p
&& IT_CHARPOS (ppos_it
) < ZV
)
8760 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8761 result
= MOVE_POS_MATCH_OR_ZV
;
8764 if (ITERATOR_AT_END_OF_LINE_P (it
))
8766 result
= MOVE_NEWLINE_OR_CR
;
8770 else if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8772 && IT_CHARPOS (*it
) > to_charpos
)
8774 if (IT_CHARPOS (ppos_it
) < ZV
)
8775 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8776 result
= MOVE_POS_MATCH_OR_ZV
;
8779 result
= MOVE_LINE_TRUNCATED
;
8782 #undef IT_RESET_X_ASCENT_DESCENT
8785 #undef BUFFER_POS_REACHED_P
8787 /* If we scanned beyond to_pos and didn't find a point to wrap at,
8788 restore the saved iterator. */
8789 if (atpos_it
.sp
>= 0)
8790 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8791 else if (atx_it
.sp
>= 0)
8792 RESTORE_IT (it
, &atx_it
, atx_data
);
8797 bidi_unshelve_cache (atpos_data
, 1);
8799 bidi_unshelve_cache (atx_data
, 1);
8801 bidi_unshelve_cache (wrap_data
, 1);
8803 bidi_unshelve_cache (ppos_data
, 1);
8805 /* Restore the iterator settings altered at the beginning of this
8807 it
->glyph_row
= saved_glyph_row
;
8811 /* For external use. */
8813 move_it_in_display_line (struct it
*it
,
8814 ptrdiff_t to_charpos
, int to_x
,
8815 enum move_operation_enum op
)
8817 if (it
->line_wrap
== WORD_WRAP
8818 && (op
& MOVE_TO_X
))
8821 void *save_data
= NULL
;
8824 SAVE_IT (save_it
, *it
, save_data
);
8825 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8826 /* When word-wrap is on, TO_X may lie past the end
8827 of a wrapped line. Then it->current is the
8828 character on the next line, so backtrack to the
8829 space before the wrap point. */
8830 if (skip
== MOVE_LINE_CONTINUED
)
8832 int prev_x
= max (it
->current_x
- 1, 0);
8833 RESTORE_IT (it
, &save_it
, save_data
);
8834 move_it_in_display_line_to
8835 (it
, -1, prev_x
, MOVE_TO_X
);
8838 bidi_unshelve_cache (save_data
, 1);
8841 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8845 /* Move IT forward until it satisfies one or more of the criteria in
8846 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
8848 OP is a bit-mask that specifies where to stop, and in particular,
8849 which of those four position arguments makes a difference. See the
8850 description of enum move_operation_enum.
8852 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
8853 screen line, this function will set IT to the next position that is
8854 displayed to the right of TO_CHARPOS on the screen.
8856 Return the maximum pixel length of any line scanned but never more
8857 than it.last_visible_x. */
8860 move_it_to (struct it
*it
, ptrdiff_t to_charpos
, int to_x
, int to_y
, int to_vpos
, int op
)
8862 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
8863 int line_height
, line_start_x
= 0, reached
= 0;
8864 int max_current_x
= 0;
8865 void *backup_data
= NULL
;
8869 if (op
& MOVE_TO_VPOS
)
8871 /* If no TO_CHARPOS and no TO_X specified, stop at the
8872 start of the line TO_VPOS. */
8873 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
8875 if (it
->vpos
== to_vpos
)
8881 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
8885 /* TO_VPOS >= 0 means stop at TO_X in the line at
8886 TO_VPOS, or at TO_POS, whichever comes first. */
8887 if (it
->vpos
== to_vpos
)
8893 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8895 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
8900 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
8902 /* We have reached TO_X but not in the line we want. */
8903 skip
= move_it_in_display_line_to (it
, to_charpos
,
8905 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8913 else if (op
& MOVE_TO_Y
)
8915 struct it it_backup
;
8917 if (it
->line_wrap
== WORD_WRAP
)
8918 SAVE_IT (it_backup
, *it
, backup_data
);
8920 /* TO_Y specified means stop at TO_X in the line containing
8921 TO_Y---or at TO_CHARPOS if this is reached first. The
8922 problem is that we can't really tell whether the line
8923 contains TO_Y before we have completely scanned it, and
8924 this may skip past TO_X. What we do is to first scan to
8927 If TO_X is not specified, use a TO_X of zero. The reason
8928 is to make the outcome of this function more predictable.
8929 If we didn't use TO_X == 0, we would stop at the end of
8930 the line which is probably not what a caller would expect
8932 skip
= move_it_in_display_line_to
8933 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
8934 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
8936 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
8937 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8939 else if (skip
== MOVE_X_REACHED
)
8941 /* If TO_X was reached, we want to know whether TO_Y is
8942 in the line. We know this is the case if the already
8943 scanned glyphs make the line tall enough. Otherwise,
8944 we must check by scanning the rest of the line. */
8945 line_height
= it
->max_ascent
+ it
->max_descent
;
8946 if (to_y
>= it
->current_y
8947 && to_y
< it
->current_y
+ line_height
)
8952 SAVE_IT (it_backup
, *it
, backup_data
);
8953 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
8954 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
8956 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
8957 line_height
= it
->max_ascent
+ it
->max_descent
;
8958 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8960 if (to_y
>= it
->current_y
8961 && to_y
< it
->current_y
+ line_height
)
8963 /* If TO_Y is in this line and TO_X was reached
8964 above, we scanned too far. We have to restore
8965 IT's settings to the ones before skipping. But
8966 keep the more accurate values of max_ascent and
8967 max_descent we've found while skipping the rest
8968 of the line, for the sake of callers, such as
8969 pos_visible_p, that need to know the line
8971 int max_ascent
= it
->max_ascent
;
8972 int max_descent
= it
->max_descent
;
8974 RESTORE_IT (it
, &it_backup
, backup_data
);
8975 it
->max_ascent
= max_ascent
;
8976 it
->max_descent
= max_descent
;
8982 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8988 /* Check whether TO_Y is in this line. */
8989 line_height
= it
->max_ascent
+ it
->max_descent
;
8990 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8992 if (to_y
>= it
->current_y
8993 && to_y
< it
->current_y
+ line_height
)
8995 if (to_y
> it
->current_y
)
8996 max_current_x
= max (it
->current_x
, max_current_x
);
8998 /* When word-wrap is on, TO_X may lie past the end
8999 of a wrapped line. Then it->current is the
9000 character on the next line, so backtrack to the
9001 space before the wrap point. */
9002 if (skip
== MOVE_LINE_CONTINUED
9003 && it
->line_wrap
== WORD_WRAP
)
9005 int prev_x
= max (it
->current_x
- 1, 0);
9006 RESTORE_IT (it
, &it_backup
, backup_data
);
9007 skip
= move_it_in_display_line_to
9008 (it
, -1, prev_x
, MOVE_TO_X
);
9017 max_current_x
= max (it
->current_x
, max_current_x
);
9021 else if (BUFFERP (it
->object
)
9022 && (it
->method
== GET_FROM_BUFFER
9023 || it
->method
== GET_FROM_STRETCH
)
9024 && IT_CHARPOS (*it
) >= to_charpos
9025 /* Under bidi iteration, a call to set_iterator_to_next
9026 can scan far beyond to_charpos if the initial
9027 portion of the next line needs to be reordered. In
9028 that case, give move_it_in_display_line_to another
9031 && it
->bidi_it
.scan_dir
== -1))
9032 skip
= MOVE_POS_MATCH_OR_ZV
;
9034 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
9038 case MOVE_POS_MATCH_OR_ZV
:
9039 max_current_x
= max (it
->current_x
, max_current_x
);
9043 case MOVE_NEWLINE_OR_CR
:
9044 max_current_x
= max (it
->current_x
, max_current_x
);
9045 set_iterator_to_next (it
, 1);
9046 it
->continuation_lines_width
= 0;
9049 case MOVE_LINE_TRUNCATED
:
9050 max_current_x
= it
->last_visible_x
;
9051 it
->continuation_lines_width
= 0;
9052 reseat_at_next_visible_line_start (it
, 0);
9053 if ((op
& MOVE_TO_POS
) != 0
9054 && IT_CHARPOS (*it
) > to_charpos
)
9061 case MOVE_LINE_CONTINUED
:
9062 max_current_x
= it
->last_visible_x
;
9063 /* For continued lines ending in a tab, some of the glyphs
9064 associated with the tab are displayed on the current
9065 line. Since it->current_x does not include these glyphs,
9066 we use it->last_visible_x instead. */
9069 it
->continuation_lines_width
+= it
->last_visible_x
;
9070 /* When moving by vpos, ensure that the iterator really
9071 advances to the next line (bug#847, bug#969). Fixme:
9072 do we need to do this in other circumstances? */
9073 if (it
->current_x
!= it
->last_visible_x
9074 && (op
& MOVE_TO_VPOS
)
9075 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
9077 line_start_x
= it
->current_x
+ it
->pixel_width
9078 - it
->last_visible_x
;
9079 set_iterator_to_next (it
, 0);
9083 it
->continuation_lines_width
+= it
->current_x
;
9090 /* Reset/increment for the next run. */
9091 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
9092 it
->current_x
= line_start_x
;
9095 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
9097 last_height
= it
->max_ascent
+ it
->max_descent
;
9098 last_max_ascent
= it
->max_ascent
;
9099 it
->max_ascent
= it
->max_descent
= 0;
9104 /* On text terminals, we may stop at the end of a line in the middle
9105 of a multi-character glyph. If the glyph itself is continued,
9106 i.e. it is actually displayed on the next line, don't treat this
9107 stopping point as valid; move to the next line instead (unless
9108 that brings us offscreen). */
9109 if (!FRAME_WINDOW_P (it
->f
)
9111 && IT_CHARPOS (*it
) == to_charpos
9112 && it
->what
== IT_CHARACTER
9114 && it
->line_wrap
== WINDOW_WRAP
9115 && it
->current_x
== it
->last_visible_x
- 1
9118 && it
->vpos
< it
->w
->window_end_vpos
)
9120 it
->continuation_lines_width
+= it
->current_x
;
9121 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
9122 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
9124 last_height
= it
->max_ascent
+ it
->max_descent
;
9125 last_max_ascent
= it
->max_ascent
;
9129 bidi_unshelve_cache (backup_data
, 1);
9131 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
9133 return max_current_x
;
9137 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
9139 If DY > 0, move IT backward at least that many pixels. DY = 0
9140 means move IT backward to the preceding line start or BEGV. This
9141 function may move over more than DY pixels if IT->current_y - DY
9142 ends up in the middle of a line; in this case IT->current_y will be
9143 set to the top of the line moved to. */
9146 move_it_vertically_backward (struct it
*it
, int dy
)
9150 void *it2data
= NULL
, *it3data
= NULL
;
9151 ptrdiff_t start_pos
;
9153 = (it
->last_visible_x
- it
->first_visible_x
) / FRAME_COLUMN_WIDTH (it
->f
);
9154 ptrdiff_t pos_limit
;
9159 start_pos
= IT_CHARPOS (*it
);
9161 /* Estimate how many newlines we must move back. */
9162 nlines
= max (1, dy
/ default_line_pixel_height (it
->w
));
9163 if (it
->line_wrap
== TRUNCATE
)
9166 pos_limit
= max (start_pos
- nlines
* nchars_per_row
, BEGV
);
9168 /* Set the iterator's position that many lines back. But don't go
9169 back more than NLINES full screen lines -- this wins a day with
9170 buffers which have very long lines. */
9171 while (nlines
-- && IT_CHARPOS (*it
) > pos_limit
)
9172 back_to_previous_visible_line_start (it
);
9174 /* Reseat the iterator here. When moving backward, we don't want
9175 reseat to skip forward over invisible text, set up the iterator
9176 to deliver from overlay strings at the new position etc. So,
9177 use reseat_1 here. */
9178 reseat_1 (it
, it
->current
.pos
, 1);
9180 /* We are now surely at a line start. */
9181 it
->current_x
= it
->hpos
= 0; /* FIXME: this is incorrect when bidi
9182 reordering is in effect. */
9183 it
->continuation_lines_width
= 0;
9185 /* Move forward and see what y-distance we moved. First move to the
9186 start of the next line so that we get its height. We need this
9187 height to be able to tell whether we reached the specified
9189 SAVE_IT (it2
, *it
, it2data
);
9190 it2
.max_ascent
= it2
.max_descent
= 0;
9193 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
9194 MOVE_TO_POS
| MOVE_TO_VPOS
);
9196 while (!(IT_POS_VALID_AFTER_MOVE_P (&it2
)
9197 /* If we are in a display string which starts at START_POS,
9198 and that display string includes a newline, and we are
9199 right after that newline (i.e. at the beginning of a
9200 display line), exit the loop, because otherwise we will
9201 infloop, since move_it_to will see that it is already at
9202 START_POS and will not move. */
9203 || (it2
.method
== GET_FROM_STRING
9204 && IT_CHARPOS (it2
) == start_pos
9205 && SREF (it2
.string
, IT_STRING_BYTEPOS (it2
) - 1) == '\n')));
9206 eassert (IT_CHARPOS (*it
) >= BEGV
);
9207 SAVE_IT (it3
, it2
, it3data
);
9209 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
9210 eassert (IT_CHARPOS (*it
) >= BEGV
);
9211 /* H is the actual vertical distance from the position in *IT
9212 and the starting position. */
9213 h
= it2
.current_y
- it
->current_y
;
9214 /* NLINES is the distance in number of lines. */
9215 nlines
= it2
.vpos
- it
->vpos
;
9217 /* Correct IT's y and vpos position
9218 so that they are relative to the starting point. */
9224 /* DY == 0 means move to the start of the screen line. The
9225 value of nlines is > 0 if continuation lines were involved,
9226 or if the original IT position was at start of a line. */
9227 RESTORE_IT (it
, it
, it2data
);
9229 move_it_by_lines (it
, nlines
);
9230 /* The above code moves us to some position NLINES down,
9231 usually to its first glyph (leftmost in an L2R line), but
9232 that's not necessarily the start of the line, under bidi
9233 reordering. We want to get to the character position
9234 that is immediately after the newline of the previous
9237 && !it
->continuation_lines_width
9238 && !STRINGP (it
->string
)
9239 && IT_CHARPOS (*it
) > BEGV
9240 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9242 ptrdiff_t cp
= IT_CHARPOS (*it
), bp
= IT_BYTEPOS (*it
);
9245 cp
= find_newline_no_quit (cp
, bp
, -1, NULL
);
9246 move_it_to (it
, cp
, -1, -1, -1, MOVE_TO_POS
);
9248 bidi_unshelve_cache (it3data
, 1);
9252 /* The y-position we try to reach, relative to *IT.
9253 Note that H has been subtracted in front of the if-statement. */
9254 int target_y
= it
->current_y
+ h
- dy
;
9255 int y0
= it3
.current_y
;
9259 RESTORE_IT (&it3
, &it3
, it3data
);
9260 y1
= line_bottom_y (&it3
);
9261 line_height
= y1
- y0
;
9262 RESTORE_IT (it
, it
, it2data
);
9263 /* If we did not reach target_y, try to move further backward if
9264 we can. If we moved too far backward, try to move forward. */
9265 if (target_y
< it
->current_y
9266 /* This is heuristic. In a window that's 3 lines high, with
9267 a line height of 13 pixels each, recentering with point
9268 on the bottom line will try to move -39/2 = 19 pixels
9269 backward. Try to avoid moving into the first line. */
9270 && (it
->current_y
- target_y
9271 > min (window_box_height (it
->w
), line_height
* 2 / 3))
9272 && IT_CHARPOS (*it
) > BEGV
)
9274 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
9275 target_y
- it
->current_y
));
9276 dy
= it
->current_y
- target_y
;
9277 goto move_further_back
;
9279 else if (target_y
>= it
->current_y
+ line_height
9280 && IT_CHARPOS (*it
) < ZV
)
9282 /* Should move forward by at least one line, maybe more.
9284 Note: Calling move_it_by_lines can be expensive on
9285 terminal frames, where compute_motion is used (via
9286 vmotion) to do the job, when there are very long lines
9287 and truncate-lines is nil. That's the reason for
9288 treating terminal frames specially here. */
9290 if (!FRAME_WINDOW_P (it
->f
))
9291 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
9296 move_it_by_lines (it
, 1);
9298 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
9305 /* Move IT by a specified amount of pixel lines DY. DY negative means
9306 move backwards. DY = 0 means move to start of screen line. At the
9307 end, IT will be on the start of a screen line. */
9310 move_it_vertically (struct it
*it
, int dy
)
9313 move_it_vertically_backward (it
, -dy
);
9316 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
9317 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
9318 MOVE_TO_POS
| MOVE_TO_Y
);
9319 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
9321 /* If buffer ends in ZV without a newline, move to the start of
9322 the line to satisfy the post-condition. */
9323 if (IT_CHARPOS (*it
) == ZV
9325 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9326 move_it_by_lines (it
, 0);
9331 /* Move iterator IT past the end of the text line it is in. */
9334 move_it_past_eol (struct it
*it
)
9336 enum move_it_result rc
;
9338 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
9339 if (rc
== MOVE_NEWLINE_OR_CR
)
9340 set_iterator_to_next (it
, 0);
9344 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
9345 negative means move up. DVPOS == 0 means move to the start of the
9348 Optimization idea: If we would know that IT->f doesn't use
9349 a face with proportional font, we could be faster for
9350 truncate-lines nil. */
9353 move_it_by_lines (struct it
*it
, ptrdiff_t dvpos
)
9356 /* The commented-out optimization uses vmotion on terminals. This
9357 gives bad results, because elements like it->what, on which
9358 callers such as pos_visible_p rely, aren't updated. */
9359 /* struct position pos;
9360 if (!FRAME_WINDOW_P (it->f))
9362 struct text_pos textpos;
9364 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
9365 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
9366 reseat (it, textpos, 1);
9367 it->vpos += pos.vpos;
9368 it->current_y += pos.vpos;
9374 /* DVPOS == 0 means move to the start of the screen line. */
9375 move_it_vertically_backward (it
, 0);
9376 /* Let next call to line_bottom_y calculate real line height. */
9381 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
9382 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
9384 /* Only move to the next buffer position if we ended up in a
9385 string from display property, not in an overlay string
9386 (before-string or after-string). That is because the
9387 latter don't conceal the underlying buffer position, so
9388 we can ask to move the iterator to the exact position we
9389 are interested in. Note that, even if we are already at
9390 IT_CHARPOS (*it), the call below is not a no-op, as it
9391 will detect that we are at the end of the string, pop the
9392 iterator, and compute it->current_x and it->hpos
9394 move_it_to (it
, IT_CHARPOS (*it
) + it
->string_from_display_prop_p
,
9395 -1, -1, -1, MOVE_TO_POS
);
9401 void *it2data
= NULL
;
9402 ptrdiff_t start_charpos
, i
;
9404 = (it
->last_visible_x
- it
->first_visible_x
) / FRAME_COLUMN_WIDTH (it
->f
);
9405 ptrdiff_t pos_limit
;
9407 /* Start at the beginning of the screen line containing IT's
9408 position. This may actually move vertically backwards,
9409 in case of overlays, so adjust dvpos accordingly. */
9411 move_it_vertically_backward (it
, 0);
9414 /* Go back -DVPOS buffer lines, but no farther than -DVPOS full
9415 screen lines, and reseat the iterator there. */
9416 start_charpos
= IT_CHARPOS (*it
);
9417 if (it
->line_wrap
== TRUNCATE
)
9420 pos_limit
= max (start_charpos
+ dvpos
* nchars_per_row
, BEGV
);
9421 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > pos_limit
; --i
)
9422 back_to_previous_visible_line_start (it
);
9423 reseat (it
, it
->current
.pos
, 1);
9425 /* Move further back if we end up in a string or an image. */
9426 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
9428 /* First try to move to start of display line. */
9430 move_it_vertically_backward (it
, 0);
9432 if (IT_POS_VALID_AFTER_MOVE_P (it
))
9434 /* If start of line is still in string or image,
9435 move further back. */
9436 back_to_previous_visible_line_start (it
);
9437 reseat (it
, it
->current
.pos
, 1);
9441 it
->current_x
= it
->hpos
= 0;
9443 /* Above call may have moved too far if continuation lines
9444 are involved. Scan forward and see if it did. */
9445 SAVE_IT (it2
, *it
, it2data
);
9446 it2
.vpos
= it2
.current_y
= 0;
9447 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
9448 it
->vpos
-= it2
.vpos
;
9449 it
->current_y
-= it2
.current_y
;
9450 it
->current_x
= it
->hpos
= 0;
9452 /* If we moved too far back, move IT some lines forward. */
9453 if (it2
.vpos
> -dvpos
)
9455 int delta
= it2
.vpos
+ dvpos
;
9457 RESTORE_IT (&it2
, &it2
, it2data
);
9458 SAVE_IT (it2
, *it
, it2data
);
9459 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
9460 /* Move back again if we got too far ahead. */
9461 if (IT_CHARPOS (*it
) >= start_charpos
)
9462 RESTORE_IT (it
, &it2
, it2data
);
9464 bidi_unshelve_cache (it2data
, 1);
9467 RESTORE_IT (it
, it
, it2data
);
9471 /* Return 1 if IT points into the middle of a display vector. */
9474 in_display_vector_p (struct it
*it
)
9476 return (it
->method
== GET_FROM_DISPLAY_VECTOR
9477 && it
->current
.dpvec_index
> 0
9478 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
9481 DEFUN ("window-text-pixel-size", Fwindow_text_pixel_size
, Swindow_text_pixel_size
, 0, 6, 0,
9482 doc
: /* Return the size of the text of WINDOW's buffer in pixels.
9483 WINDOW must be a live window and defaults to the selected one. The
9484 return value is a cons of the maximum pixel-width of any text line and
9485 the maximum pixel-height of all text lines.
9487 The optional argument FROM, if non-nil, specifies the first text
9488 position and defaults to the minimum accessible position of the buffer.
9489 If FROM is t, use the minimum accessible position that is not a newline
9490 character. TO, if non-nil, specifies the last text position and
9491 defaults to the maximum accessible position of the buffer. If TO is t,
9492 use the maximum accessible position that is not a newline character.
9494 The optional argument X_LIMIT, if non-nil, specifies the maximum text
9495 width that can be returned. X_LIMIT nil or omitted, means to use the
9496 pixel-width of WINDOW's body; use this if you do not intend to change
9497 the width of WINDOW. Use the maximum width WINDOW may assume if you
9498 intend to change WINDOW's width.
9500 The optional argument Y_LIMIT, if non-nil, specifies the maximum text
9501 height that can be returned. Text lines whose y-coordinate is beyond
9502 Y_LIMIT are ignored. Since calculating the text height of a large
9503 buffer can take some time, it makes sense to specify this argument if
9504 the size of the buffer is unknown.
9506 Optional argument MODE_AND_HEADER_LINE nil or omitted means do not
9507 include the height of the mode- or header-line of WINDOW in the return
9508 value. If it is either the symbol `mode-line' or `header-line', include
9509 only the height of that line, if present, in the return value. If t,
9510 include the height of any of these lines in the return value. */)
9511 (Lisp_Object window
, Lisp_Object from
, Lisp_Object to
, Lisp_Object x_limit
, Lisp_Object y_limit
,
9512 Lisp_Object mode_and_header_line
)
9514 struct window
*w
= decode_live_window (window
);
9515 Lisp_Object buf
, value
;
9518 struct buffer
*old_buffer
= NULL
;
9519 ptrdiff_t start
, end
, pos
;
9520 struct text_pos startp
, endp
;
9521 void *itdata
= NULL
;
9522 int c
, max_y
= -1, x
= 0, y
= 0;
9528 if (b
!= current_buffer
)
9530 old_buffer
= current_buffer
;
9531 set_buffer_internal (b
);
9536 else if (EQ (from
, Qt
))
9539 while ((pos
++ < ZV
) && (c
= FETCH_CHAR (pos
))
9540 && (c
== ' ' || c
== '\t' || c
== '\n' || c
== '\r'))
9542 while ((pos
-- > BEGV
) && (c
= FETCH_CHAR (pos
)) && (c
== ' ' || c
== '\t'))
9547 CHECK_NUMBER_COERCE_MARKER (from
);
9548 start
= min (max (XINT (from
), BEGV
), ZV
);
9553 else if (EQ (to
, Qt
))
9556 while ((pos
-- > BEGV
) && (c
= FETCH_CHAR (pos
))
9557 && (c
== ' ' || c
== '\t' || c
== '\n' || c
== '\r'))
9559 while ((pos
++ < ZV
) && (c
= FETCH_CHAR (pos
)) && (c
== ' ' || c
== '\t'))
9564 CHECK_NUMBER_COERCE_MARKER (to
);
9565 end
= max (start
, min (XINT (to
), ZV
));
9568 if (!NILP (y_limit
))
9570 CHECK_NUMBER (y_limit
);
9571 max_y
= XINT (y_limit
);
9574 itdata
= bidi_shelve_cache ();
9575 SET_TEXT_POS (startp
, start
, CHAR_TO_BYTE (start
));
9576 start_display (&it
, w
, startp
);
9578 /** move_it_vertically_backward (&it, 0); **/
9580 x
= move_it_to (&it
, end
, -1, max_y
, -1, MOVE_TO_POS
| MOVE_TO_Y
);
9583 CHECK_NUMBER (x_limit
);
9584 it
.last_visible_x
= XINT (x_limit
);
9585 /* Actually, we never want move_it_to stop at to_x. But to make
9586 sure that move_it_in_display_line_to always moves far enough,
9587 we set it to INT_MAX and specify MOVE_TO_X. */
9588 x
= move_it_to (&it
, end
, INT_MAX
, max_y
, -1,
9589 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9596 /* Count last line. */
9598 y
= line_bottom_y (&it
); /* - y; */
9601 if (!EQ (mode_and_header_line
, Qheader_line
)
9602 && !EQ (mode_and_header_line
, Qt
))
9603 /* Do not count the header-line which was counted automatically by
9605 y
= y
- WINDOW_HEADER_LINE_HEIGHT (w
);
9607 if (EQ (mode_and_header_line
, Qmode_line
)
9608 || EQ (mode_and_header_line
, Qt
))
9609 /* Do count the mode-line which is not included automatically by
9611 y
= y
+ WINDOW_MODE_LINE_HEIGHT (w
);
9613 bidi_unshelve_cache (itdata
, 0);
9616 set_buffer_internal (old_buffer
);
9618 return Fcons (make_number (x
), make_number (y
));
9621 /***********************************************************************
9623 ***********************************************************************/
9626 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
9630 add_to_log (const char *format
, Lisp_Object arg1
, Lisp_Object arg2
)
9632 Lisp_Object args
[3];
9633 Lisp_Object msg
, fmt
;
9636 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
9640 GCPRO4 (fmt
, msg
, arg1
, arg2
);
9642 args
[0] = fmt
= build_string (format
);
9645 msg
= Fformat (3, args
);
9647 len
= SBYTES (msg
) + 1;
9648 buffer
= SAFE_ALLOCA (len
);
9649 memcpy (buffer
, SDATA (msg
), len
);
9651 message_dolog (buffer
, len
- 1, 1, 0);
9658 /* Output a newline in the *Messages* buffer if "needs" one. */
9661 message_log_maybe_newline (void)
9663 if (message_log_need_newline
)
9664 message_dolog ("", 0, 1, 0);
9668 /* Add a string M of length NBYTES to the message log, optionally
9669 terminated with a newline when NLFLAG is true. MULTIBYTE, if
9670 true, means interpret the contents of M as multibyte. This
9671 function calls low-level routines in order to bypass text property
9672 hooks, etc. which might not be safe to run.
9674 This may GC (insert may run before/after change hooks),
9675 so the buffer M must NOT point to a Lisp string. */
9678 message_dolog (const char *m
, ptrdiff_t nbytes
, bool nlflag
, bool multibyte
)
9680 const unsigned char *msg
= (const unsigned char *) m
;
9682 if (!NILP (Vmemory_full
))
9685 if (!NILP (Vmessage_log_max
))
9687 struct buffer
*oldbuf
;
9688 Lisp_Object oldpoint
, oldbegv
, oldzv
;
9689 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
9690 ptrdiff_t point_at_end
= 0;
9691 ptrdiff_t zv_at_end
= 0;
9692 Lisp_Object old_deactivate_mark
;
9693 struct gcpro gcpro1
;
9695 old_deactivate_mark
= Vdeactivate_mark
;
9696 oldbuf
= current_buffer
;
9698 /* Ensure the Messages buffer exists, and switch to it.
9699 If we created it, set the major-mode. */
9702 if (NILP (Fget_buffer (Vmessages_buffer_name
))) newbuffer
= 1;
9704 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
9707 && !NILP (Ffboundp (intern ("messages-buffer-mode"))))
9708 call0 (intern ("messages-buffer-mode"));
9711 bset_undo_list (current_buffer
, Qt
);
9712 bset_cache_long_scans (current_buffer
, Qnil
);
9714 oldpoint
= message_dolog_marker1
;
9715 set_marker_restricted_both (oldpoint
, Qnil
, PT
, PT_BYTE
);
9716 oldbegv
= message_dolog_marker2
;
9717 set_marker_restricted_both (oldbegv
, Qnil
, BEGV
, BEGV_BYTE
);
9718 oldzv
= message_dolog_marker3
;
9719 set_marker_restricted_both (oldzv
, Qnil
, ZV
, ZV_BYTE
);
9720 GCPRO1 (old_deactivate_mark
);
9728 BEGV_BYTE
= BEG_BYTE
;
9731 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9733 /* Insert the string--maybe converting multibyte to single byte
9734 or vice versa, so that all the text fits the buffer. */
9736 && NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9742 /* Convert a multibyte string to single-byte
9743 for the *Message* buffer. */
9744 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
9746 c
= string_char_and_length (msg
+ i
, &char_bytes
);
9747 work
[0] = (ASCII_CHAR_P (c
)
9749 : multibyte_char_to_unibyte (c
));
9750 insert_1_both (work
, 1, 1, 1, 0, 0);
9753 else if (! multibyte
9754 && ! NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9758 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9759 /* Convert a single-byte string to multibyte
9760 for the *Message* buffer. */
9761 for (i
= 0; i
< nbytes
; i
++)
9764 MAKE_CHAR_MULTIBYTE (c
);
9765 char_bytes
= CHAR_STRING (c
, str
);
9766 insert_1_both ((char *) str
, 1, char_bytes
, 1, 0, 0);
9770 insert_1_both (m
, chars_in_text (msg
, nbytes
), nbytes
, 1, 0, 0);
9774 ptrdiff_t this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
;
9777 insert_1_both ("\n", 1, 1, 1, 0, 0);
9779 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9781 this_bol_byte
= PT_BYTE
;
9783 /* See if this line duplicates the previous one.
9784 If so, combine duplicates. */
9787 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9789 prev_bol_byte
= PT_BYTE
;
9791 dups
= message_log_check_duplicate (prev_bol_byte
,
9795 del_range_both (prev_bol
, prev_bol_byte
,
9796 this_bol
, this_bol_byte
, 0);
9799 char dupstr
[sizeof " [ times]"
9800 + INT_STRLEN_BOUND (printmax_t
)];
9802 /* If you change this format, don't forget to also
9803 change message_log_check_duplicate. */
9804 int duplen
= sprintf (dupstr
, " [%"pMd
" times]", dups
);
9805 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
9806 insert_1_both (dupstr
, duplen
, duplen
, 1, 0, 1);
9811 /* If we have more than the desired maximum number of lines
9812 in the *Messages* buffer now, delete the oldest ones.
9813 This is safe because we don't have undo in this buffer. */
9815 if (NATNUMP (Vmessage_log_max
))
9817 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
9818 -XFASTINT (Vmessage_log_max
) - 1, 0);
9819 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
9822 BEGV
= marker_position (oldbegv
);
9823 BEGV_BYTE
= marker_byte_position (oldbegv
);
9832 ZV
= marker_position (oldzv
);
9833 ZV_BYTE
= marker_byte_position (oldzv
);
9837 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9839 /* We can't do Fgoto_char (oldpoint) because it will run some
9841 TEMP_SET_PT_BOTH (marker_position (oldpoint
),
9842 marker_byte_position (oldpoint
));
9845 unchain_marker (XMARKER (oldpoint
));
9846 unchain_marker (XMARKER (oldbegv
));
9847 unchain_marker (XMARKER (oldzv
));
9849 /* We called insert_1_both above with its 5th argument (PREPARE)
9850 zero, which prevents insert_1_both from calling
9851 prepare_to_modify_buffer, which in turns prevents us from
9852 incrementing windows_or_buffers_changed even if *Messages* is
9853 shown in some window. So we must manually set
9854 windows_or_buffers_changed here to make up for that. */
9855 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
9856 bset_redisplay (current_buffer
);
9858 set_buffer_internal (oldbuf
);
9860 message_log_need_newline
= !nlflag
;
9861 Vdeactivate_mark
= old_deactivate_mark
;
9866 /* We are at the end of the buffer after just having inserted a newline.
9867 (Note: We depend on the fact we won't be crossing the gap.)
9868 Check to see if the most recent message looks a lot like the previous one.
9869 Return 0 if different, 1 if the new one should just replace it, or a
9870 value N > 1 if we should also append " [N times]". */
9873 message_log_check_duplicate (ptrdiff_t prev_bol_byte
, ptrdiff_t this_bol_byte
)
9876 ptrdiff_t len
= Z_BYTE
- 1 - this_bol_byte
;
9878 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
9879 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
9881 for (i
= 0; i
< len
; i
++)
9883 if (i
>= 3 && p1
[i
- 3] == '.' && p1
[i
- 2] == '.' && p1
[i
- 1] == '.')
9891 if (*p1
++ == ' ' && *p1
++ == '[')
9894 intmax_t n
= strtoimax ((char *) p1
, &pend
, 10);
9895 if (0 < n
&& n
< INTMAX_MAX
&& strncmp (pend
, " times]\n", 8) == 0)
9902 /* Display an echo area message M with a specified length of NBYTES
9903 bytes. The string may include null characters. If M is not a
9904 string, clear out any existing message, and let the mini-buffer
9907 This function cancels echoing. */
9910 message3 (Lisp_Object m
)
9912 struct gcpro gcpro1
;
9915 clear_message (true, true);
9918 /* First flush out any partial line written with print. */
9919 message_log_maybe_newline ();
9922 ptrdiff_t nbytes
= SBYTES (m
);
9923 bool multibyte
= STRING_MULTIBYTE (m
);
9925 char *buffer
= SAFE_ALLOCA (nbytes
);
9926 memcpy (buffer
, SDATA (m
), nbytes
);
9927 message_dolog (buffer
, nbytes
, 1, multibyte
);
9936 /* The non-logging version of message3.
9937 This does not cancel echoing, because it is used for echoing.
9938 Perhaps we need to make a separate function for echoing
9939 and make this cancel echoing. */
9942 message3_nolog (Lisp_Object m
)
9944 struct frame
*sf
= SELECTED_FRAME ();
9946 if (FRAME_INITIAL_P (sf
))
9948 if (noninteractive_need_newline
)
9949 putc ('\n', stderr
);
9950 noninteractive_need_newline
= 0;
9953 Lisp_Object s
= ENCODE_SYSTEM (m
);
9955 fwrite (SDATA (s
), SBYTES (s
), 1, stderr
);
9957 if (cursor_in_echo_area
== 0)
9958 fprintf (stderr
, "\n");
9961 /* Error messages get reported properly by cmd_error, so this must be just an
9962 informative message; if the frame hasn't really been initialized yet, just
9964 else if (INTERACTIVE
&& sf
->glyphs_initialized_p
)
9966 /* Get the frame containing the mini-buffer
9967 that the selected frame is using. */
9968 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9969 Lisp_Object frame
= XWINDOW (mini_window
)->frame
;
9970 struct frame
*f
= XFRAME (frame
);
9972 if (FRAME_VISIBLE_P (sf
) && !FRAME_VISIBLE_P (f
))
9973 Fmake_frame_visible (frame
);
9975 if (STRINGP (m
) && SCHARS (m
) > 0)
9978 if (minibuffer_auto_raise
)
9979 Fraise_frame (frame
);
9980 /* Assume we are not echoing.
9981 (If we are, echo_now will override this.) */
9982 echo_message_buffer
= Qnil
;
9985 clear_message (true, true);
9987 do_pending_window_change (0);
9988 echo_area_display (1);
9989 do_pending_window_change (0);
9990 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
9991 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
9996 /* Display a null-terminated echo area message M. If M is 0, clear
9997 out any existing message, and let the mini-buffer text show through.
9999 The buffer M must continue to exist until after the echo area gets
10000 cleared or some other message gets displayed there. Do not pass
10001 text that is stored in a Lisp string. Do not pass text in a buffer
10002 that was alloca'd. */
10005 message1 (const char *m
)
10007 message3 (m
? build_unibyte_string (m
) : Qnil
);
10011 /* The non-logging counterpart of message1. */
10014 message1_nolog (const char *m
)
10016 message3_nolog (m
? build_unibyte_string (m
) : Qnil
);
10019 /* Display a message M which contains a single %s
10020 which gets replaced with STRING. */
10023 message_with_string (const char *m
, Lisp_Object string
, int log
)
10025 CHECK_STRING (string
);
10027 if (noninteractive
)
10031 /* ENCODE_SYSTEM below can GC and/or relocate the Lisp
10032 String whose data pointer might be passed to us in M. So
10033 we use a local copy. */
10034 char *fmt
= xstrdup (m
);
10036 if (noninteractive_need_newline
)
10037 putc ('\n', stderr
);
10038 noninteractive_need_newline
= 0;
10039 fprintf (stderr
, fmt
, SDATA (ENCODE_SYSTEM (string
)));
10040 if (!cursor_in_echo_area
)
10041 fprintf (stderr
, "\n");
10046 else if (INTERACTIVE
)
10048 /* The frame whose minibuffer we're going to display the message on.
10049 It may be larger than the selected frame, so we need
10050 to use its buffer, not the selected frame's buffer. */
10051 Lisp_Object mini_window
;
10052 struct frame
*f
, *sf
= SELECTED_FRAME ();
10054 /* Get the frame containing the minibuffer
10055 that the selected frame is using. */
10056 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10057 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
10059 /* Error messages get reported properly by cmd_error, so this must be
10060 just an informative message; if the frame hasn't really been
10061 initialized yet, just toss it. */
10062 if (f
->glyphs_initialized_p
)
10064 Lisp_Object args
[2], msg
;
10065 struct gcpro gcpro1
, gcpro2
;
10067 args
[0] = build_string (m
);
10068 args
[1] = msg
= string
;
10069 GCPRO2 (args
[0], msg
);
10072 msg
= Fformat (2, args
);
10077 message3_nolog (msg
);
10081 /* Print should start at the beginning of the message
10082 buffer next time. */
10083 message_buf_print
= 0;
10089 /* Dump an informative message to the minibuf. If M is 0, clear out
10090 any existing message, and let the mini-buffer text show through. */
10093 vmessage (const char *m
, va_list ap
)
10095 if (noninteractive
)
10099 if (noninteractive_need_newline
)
10100 putc ('\n', stderr
);
10101 noninteractive_need_newline
= 0;
10102 vfprintf (stderr
, m
, ap
);
10103 if (cursor_in_echo_area
== 0)
10104 fprintf (stderr
, "\n");
10108 else if (INTERACTIVE
)
10110 /* The frame whose mini-buffer we're going to display the message
10111 on. It may be larger than the selected frame, so we need to
10112 use its buffer, not the selected frame's buffer. */
10113 Lisp_Object mini_window
;
10114 struct frame
*f
, *sf
= SELECTED_FRAME ();
10116 /* Get the frame containing the mini-buffer
10117 that the selected frame is using. */
10118 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10119 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
10121 /* Error messages get reported properly by cmd_error, so this must be
10122 just an informative message; if the frame hasn't really been
10123 initialized yet, just toss it. */
10124 if (f
->glyphs_initialized_p
)
10129 ptrdiff_t maxsize
= FRAME_MESSAGE_BUF_SIZE (f
);
10130 char *message_buf
= alloca (maxsize
+ 1);
10132 len
= doprnt (message_buf
, maxsize
, m
, 0, ap
);
10134 message3 (make_string (message_buf
, len
));
10139 /* Print should start at the beginning of the message
10140 buffer next time. */
10141 message_buf_print
= 0;
10147 message (const char *m
, ...)
10157 /* The non-logging version of message. */
10160 message_nolog (const char *m
, ...)
10162 Lisp_Object old_log_max
;
10165 old_log_max
= Vmessage_log_max
;
10166 Vmessage_log_max
= Qnil
;
10168 Vmessage_log_max
= old_log_max
;
10174 /* Display the current message in the current mini-buffer. This is
10175 only called from error handlers in process.c, and is not time
10179 update_echo_area (void)
10181 if (!NILP (echo_area_buffer
[0]))
10183 Lisp_Object string
;
10184 string
= Fcurrent_message ();
10190 /* Make sure echo area buffers in `echo_buffers' are live.
10191 If they aren't, make new ones. */
10194 ensure_echo_area_buffers (void)
10198 for (i
= 0; i
< 2; ++i
)
10199 if (!BUFFERP (echo_buffer
[i
])
10200 || !BUFFER_LIVE_P (XBUFFER (echo_buffer
[i
])))
10203 Lisp_Object old_buffer
;
10206 old_buffer
= echo_buffer
[i
];
10207 echo_buffer
[i
] = Fget_buffer_create
10208 (make_formatted_string (name
, " *Echo Area %d*", i
));
10209 bset_truncate_lines (XBUFFER (echo_buffer
[i
]), Qnil
);
10210 /* to force word wrap in echo area -
10211 it was decided to postpone this*/
10212 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
10214 for (j
= 0; j
< 2; ++j
)
10215 if (EQ (old_buffer
, echo_area_buffer
[j
]))
10216 echo_area_buffer
[j
] = echo_buffer
[i
];
10221 /* Call FN with args A1..A2 with either the current or last displayed
10222 echo_area_buffer as current buffer.
10224 WHICH zero means use the current message buffer
10225 echo_area_buffer[0]. If that is nil, choose a suitable buffer
10226 from echo_buffer[] and clear it.
10228 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
10229 suitable buffer from echo_buffer[] and clear it.
10231 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
10232 that the current message becomes the last displayed one, make
10233 choose a suitable buffer for echo_area_buffer[0], and clear it.
10235 Value is what FN returns. */
10238 with_echo_area_buffer (struct window
*w
, int which
,
10239 int (*fn
) (ptrdiff_t, Lisp_Object
),
10240 ptrdiff_t a1
, Lisp_Object a2
)
10242 Lisp_Object buffer
;
10243 int this_one
, the_other
, clear_buffer_p
, rc
;
10244 ptrdiff_t count
= SPECPDL_INDEX ();
10246 /* If buffers aren't live, make new ones. */
10247 ensure_echo_area_buffers ();
10249 clear_buffer_p
= 0;
10252 this_one
= 0, the_other
= 1;
10253 else if (which
> 0)
10254 this_one
= 1, the_other
= 0;
10257 this_one
= 0, the_other
= 1;
10258 clear_buffer_p
= true;
10260 /* We need a fresh one in case the current echo buffer equals
10261 the one containing the last displayed echo area message. */
10262 if (!NILP (echo_area_buffer
[this_one
])
10263 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
10264 echo_area_buffer
[this_one
] = Qnil
;
10267 /* Choose a suitable buffer from echo_buffer[] is we don't
10269 if (NILP (echo_area_buffer
[this_one
]))
10271 echo_area_buffer
[this_one
]
10272 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
10273 ? echo_buffer
[the_other
]
10274 : echo_buffer
[this_one
]);
10275 clear_buffer_p
= true;
10278 buffer
= echo_area_buffer
[this_one
];
10280 /* Don't get confused by reusing the buffer used for echoing
10281 for a different purpose. */
10282 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
10285 record_unwind_protect (unwind_with_echo_area_buffer
,
10286 with_echo_area_buffer_unwind_data (w
));
10288 /* Make the echo area buffer current. Note that for display
10289 purposes, it is not necessary that the displayed window's buffer
10290 == current_buffer, except for text property lookup. So, let's
10291 only set that buffer temporarily here without doing a full
10292 Fset_window_buffer. We must also change w->pointm, though,
10293 because otherwise an assertions in unshow_buffer fails, and Emacs
10295 set_buffer_internal_1 (XBUFFER (buffer
));
10298 wset_buffer (w
, buffer
);
10299 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
10302 bset_undo_list (current_buffer
, Qt
);
10303 bset_read_only (current_buffer
, Qnil
);
10304 specbind (Qinhibit_read_only
, Qt
);
10305 specbind (Qinhibit_modification_hooks
, Qt
);
10307 if (clear_buffer_p
&& Z
> BEG
)
10308 del_range (BEG
, Z
);
10310 eassert (BEGV
>= BEG
);
10311 eassert (ZV
<= Z
&& ZV
>= BEGV
);
10315 eassert (BEGV
>= BEG
);
10316 eassert (ZV
<= Z
&& ZV
>= BEGV
);
10318 unbind_to (count
, Qnil
);
10323 /* Save state that should be preserved around the call to the function
10324 FN called in with_echo_area_buffer. */
10327 with_echo_area_buffer_unwind_data (struct window
*w
)
10330 Lisp_Object vector
, tmp
;
10332 /* Reduce consing by keeping one vector in
10333 Vwith_echo_area_save_vector. */
10334 vector
= Vwith_echo_area_save_vector
;
10335 Vwith_echo_area_save_vector
= Qnil
;
10338 vector
= Fmake_vector (make_number (9), Qnil
);
10340 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
10341 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
10342 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
10346 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
10347 ASET (vector
, i
, w
->contents
); ++i
;
10348 ASET (vector
, i
, make_number (marker_position (w
->pointm
))); ++i
;
10349 ASET (vector
, i
, make_number (marker_byte_position (w
->pointm
))); ++i
;
10350 ASET (vector
, i
, make_number (marker_position (w
->start
))); ++i
;
10351 ASET (vector
, i
, make_number (marker_byte_position (w
->start
))); ++i
;
10356 for (; i
< end
; ++i
)
10357 ASET (vector
, i
, Qnil
);
10360 eassert (i
== ASIZE (vector
));
10365 /* Restore global state from VECTOR which was created by
10366 with_echo_area_buffer_unwind_data. */
10369 unwind_with_echo_area_buffer (Lisp_Object vector
)
10371 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
10372 Vdeactivate_mark
= AREF (vector
, 1);
10373 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
10375 if (WINDOWP (AREF (vector
, 3)))
10378 Lisp_Object buffer
;
10380 w
= XWINDOW (AREF (vector
, 3));
10381 buffer
= AREF (vector
, 4);
10383 wset_buffer (w
, buffer
);
10384 set_marker_both (w
->pointm
, buffer
,
10385 XFASTINT (AREF (vector
, 5)),
10386 XFASTINT (AREF (vector
, 6)));
10387 set_marker_both (w
->start
, buffer
,
10388 XFASTINT (AREF (vector
, 7)),
10389 XFASTINT (AREF (vector
, 8)));
10392 Vwith_echo_area_save_vector
= vector
;
10396 /* Set up the echo area for use by print functions. MULTIBYTE_P
10397 non-zero means we will print multibyte. */
10400 setup_echo_area_for_printing (int multibyte_p
)
10402 /* If we can't find an echo area any more, exit. */
10403 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
10404 Fkill_emacs (Qnil
);
10406 ensure_echo_area_buffers ();
10408 if (!message_buf_print
)
10410 /* A message has been output since the last time we printed.
10411 Choose a fresh echo area buffer. */
10412 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10413 echo_area_buffer
[0] = echo_buffer
[1];
10415 echo_area_buffer
[0] = echo_buffer
[0];
10417 /* Switch to that buffer and clear it. */
10418 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10419 bset_truncate_lines (current_buffer
, Qnil
);
10423 ptrdiff_t count
= SPECPDL_INDEX ();
10424 specbind (Qinhibit_read_only
, Qt
);
10425 /* Note that undo recording is always disabled. */
10426 del_range (BEG
, Z
);
10427 unbind_to (count
, Qnil
);
10429 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10431 /* Set up the buffer for the multibyteness we need. */
10433 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10434 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
10436 /* Raise the frame containing the echo area. */
10437 if (minibuffer_auto_raise
)
10439 struct frame
*sf
= SELECTED_FRAME ();
10440 Lisp_Object mini_window
;
10441 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10442 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
10445 message_log_maybe_newline ();
10446 message_buf_print
= 1;
10450 if (NILP (echo_area_buffer
[0]))
10452 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10453 echo_area_buffer
[0] = echo_buffer
[1];
10455 echo_area_buffer
[0] = echo_buffer
[0];
10458 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
10460 /* Someone switched buffers between print requests. */
10461 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10462 bset_truncate_lines (current_buffer
, Qnil
);
10468 /* Display an echo area message in window W. Value is non-zero if W's
10469 height is changed. If display_last_displayed_message_p is
10470 non-zero, display the message that was last displayed, otherwise
10471 display the current message. */
10474 display_echo_area (struct window
*w
)
10476 int i
, no_message_p
, window_height_changed_p
;
10478 /* Temporarily disable garbage collections while displaying the echo
10479 area. This is done because a GC can print a message itself.
10480 That message would modify the echo area buffer's contents while a
10481 redisplay of the buffer is going on, and seriously confuse
10483 ptrdiff_t count
= inhibit_garbage_collection ();
10485 /* If there is no message, we must call display_echo_area_1
10486 nevertheless because it resizes the window. But we will have to
10487 reset the echo_area_buffer in question to nil at the end because
10488 with_echo_area_buffer will sets it to an empty buffer. */
10489 i
= display_last_displayed_message_p
? 1 : 0;
10490 no_message_p
= NILP (echo_area_buffer
[i
]);
10492 window_height_changed_p
10493 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
10494 display_echo_area_1
,
10495 (intptr_t) w
, Qnil
);
10498 echo_area_buffer
[i
] = Qnil
;
10500 unbind_to (count
, Qnil
);
10501 return window_height_changed_p
;
10505 /* Helper for display_echo_area. Display the current buffer which
10506 contains the current echo area message in window W, a mini-window,
10507 a pointer to which is passed in A1. A2..A4 are currently not used.
10508 Change the height of W so that all of the message is displayed.
10509 Value is non-zero if height of W was changed. */
10512 display_echo_area_1 (ptrdiff_t a1
, Lisp_Object a2
)
10515 struct window
*w
= (struct window
*) i1
;
10516 Lisp_Object window
;
10517 struct text_pos start
;
10518 int window_height_changed_p
= 0;
10520 /* Do this before displaying, so that we have a large enough glyph
10521 matrix for the display. If we can't get enough space for the
10522 whole text, display the last N lines. That works by setting w->start. */
10523 window_height_changed_p
= resize_mini_window (w
, 0);
10525 /* Use the starting position chosen by resize_mini_window. */
10526 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
10529 clear_glyph_matrix (w
->desired_matrix
);
10530 XSETWINDOW (window
, w
);
10531 try_window (window
, start
, 0);
10533 return window_height_changed_p
;
10537 /* Resize the echo area window to exactly the size needed for the
10538 currently displayed message, if there is one. If a mini-buffer
10539 is active, don't shrink it. */
10542 resize_echo_area_exactly (void)
10544 if (BUFFERP (echo_area_buffer
[0])
10545 && WINDOWP (echo_area_window
))
10547 struct window
*w
= XWINDOW (echo_area_window
);
10548 Lisp_Object resize_exactly
= (minibuf_level
== 0 ? Qt
: Qnil
);
10549 int resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
10550 (intptr_t) w
, resize_exactly
);
10553 windows_or_buffers_changed
= 42;
10554 update_mode_lines
= 30;
10555 redisplay_internal ();
10561 /* Callback function for with_echo_area_buffer, when used from
10562 resize_echo_area_exactly. A1 contains a pointer to the window to
10563 resize, EXACTLY non-nil means resize the mini-window exactly to the
10564 size of the text displayed. A3 and A4 are not used. Value is what
10565 resize_mini_window returns. */
10568 resize_mini_window_1 (ptrdiff_t a1
, Lisp_Object exactly
)
10571 return resize_mini_window ((struct window
*) i1
, !NILP (exactly
));
10575 /* Resize mini-window W to fit the size of its contents. EXACT_P
10576 means size the window exactly to the size needed. Otherwise, it's
10577 only enlarged until W's buffer is empty.
10579 Set W->start to the right place to begin display. If the whole
10580 contents fit, start at the beginning. Otherwise, start so as
10581 to make the end of the contents appear. This is particularly
10582 important for y-or-n-p, but seems desirable generally.
10584 Value is non-zero if the window height has been changed. */
10587 resize_mini_window (struct window
*w
, int exact_p
)
10589 struct frame
*f
= XFRAME (w
->frame
);
10590 int window_height_changed_p
= 0;
10592 eassert (MINI_WINDOW_P (w
));
10594 /* By default, start display at the beginning. */
10595 set_marker_both (w
->start
, w
->contents
,
10596 BUF_BEGV (XBUFFER (w
->contents
)),
10597 BUF_BEGV_BYTE (XBUFFER (w
->contents
)));
10599 /* Don't resize windows while redisplaying a window; it would
10600 confuse redisplay functions when the size of the window they are
10601 displaying changes from under them. Such a resizing can happen,
10602 for instance, when which-func prints a long message while
10603 we are running fontification-functions. We're running these
10604 functions with safe_call which binds inhibit-redisplay to t. */
10605 if (!NILP (Vinhibit_redisplay
))
10608 /* Nil means don't try to resize. */
10609 if (NILP (Vresize_mini_windows
)
10610 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
10613 if (!FRAME_MINIBUF_ONLY_P (f
))
10616 int total_height
= (WINDOW_PIXEL_HEIGHT (XWINDOW (FRAME_ROOT_WINDOW (f
)))
10617 + WINDOW_PIXEL_HEIGHT (w
));
10618 int unit
= FRAME_LINE_HEIGHT (f
);
10619 int height
, max_height
;
10620 struct text_pos start
;
10621 struct buffer
*old_current_buffer
= NULL
;
10623 if (current_buffer
!= XBUFFER (w
->contents
))
10625 old_current_buffer
= current_buffer
;
10626 set_buffer_internal (XBUFFER (w
->contents
));
10629 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10631 /* Compute the max. number of lines specified by the user. */
10632 if (FLOATP (Vmax_mini_window_height
))
10633 max_height
= XFLOATINT (Vmax_mini_window_height
) * total_height
;
10634 else if (INTEGERP (Vmax_mini_window_height
))
10635 max_height
= XINT (Vmax_mini_window_height
) * unit
;
10637 max_height
= total_height
/ 4;
10639 /* Correct that max. height if it's bogus. */
10640 max_height
= clip_to_bounds (unit
, max_height
, total_height
);
10642 /* Find out the height of the text in the window. */
10643 if (it
.line_wrap
== TRUNCATE
)
10648 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
10649 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
10650 height
= it
.current_y
+ last_height
;
10652 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
10653 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
10656 /* Compute a suitable window start. */
10657 if (height
> max_height
)
10659 height
= max_height
;
10660 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10661 move_it_vertically_backward (&it
, height
);
10662 start
= it
.current
.pos
;
10665 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
10666 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
10668 if (EQ (Vresize_mini_windows
, Qgrow_only
))
10670 /* Let it grow only, until we display an empty message, in which
10671 case the window shrinks again. */
10672 if (height
> WINDOW_PIXEL_HEIGHT (w
))
10674 int old_height
= WINDOW_PIXEL_HEIGHT (w
);
10676 FRAME_WINDOWS_FROZEN (f
) = 1;
10677 grow_mini_window (w
, height
- WINDOW_PIXEL_HEIGHT (w
), 1);
10678 window_height_changed_p
= WINDOW_PIXEL_HEIGHT (w
) != old_height
;
10680 else if (height
< WINDOW_PIXEL_HEIGHT (w
)
10681 && (exact_p
|| BEGV
== ZV
))
10683 int old_height
= WINDOW_PIXEL_HEIGHT (w
);
10685 FRAME_WINDOWS_FROZEN (f
) = 0;
10686 shrink_mini_window (w
, 1);
10687 window_height_changed_p
= WINDOW_PIXEL_HEIGHT (w
) != old_height
;
10692 /* Always resize to exact size needed. */
10693 if (height
> WINDOW_PIXEL_HEIGHT (w
))
10695 int old_height
= WINDOW_PIXEL_HEIGHT (w
);
10697 FRAME_WINDOWS_FROZEN (f
) = 1;
10698 grow_mini_window (w
, height
- WINDOW_PIXEL_HEIGHT (w
), 1);
10699 window_height_changed_p
= WINDOW_PIXEL_HEIGHT (w
) != old_height
;
10701 else if (height
< WINDOW_PIXEL_HEIGHT (w
))
10703 int old_height
= WINDOW_PIXEL_HEIGHT (w
);
10705 FRAME_WINDOWS_FROZEN (f
) = 0;
10706 shrink_mini_window (w
, 1);
10710 FRAME_WINDOWS_FROZEN (f
) = 1;
10711 grow_mini_window (w
, height
- WINDOW_PIXEL_HEIGHT (w
), 1);
10714 window_height_changed_p
= WINDOW_PIXEL_HEIGHT (w
) != old_height
;
10718 if (old_current_buffer
)
10719 set_buffer_internal (old_current_buffer
);
10722 return window_height_changed_p
;
10726 /* Value is the current message, a string, or nil if there is no
10727 current message. */
10730 current_message (void)
10734 if (!BUFFERP (echo_area_buffer
[0]))
10738 with_echo_area_buffer (0, 0, current_message_1
,
10739 (intptr_t) &msg
, Qnil
);
10741 echo_area_buffer
[0] = Qnil
;
10749 current_message_1 (ptrdiff_t a1
, Lisp_Object a2
)
10752 Lisp_Object
*msg
= (Lisp_Object
*) i1
;
10755 *msg
= make_buffer_string (BEG
, Z
, 1);
10762 /* Push the current message on Vmessage_stack for later restoration
10763 by restore_message. Value is non-zero if the current message isn't
10764 empty. This is a relatively infrequent operation, so it's not
10765 worth optimizing. */
10768 push_message (void)
10770 Lisp_Object msg
= current_message ();
10771 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
10772 return STRINGP (msg
);
10776 /* Restore message display from the top of Vmessage_stack. */
10779 restore_message (void)
10781 eassert (CONSP (Vmessage_stack
));
10782 message3_nolog (XCAR (Vmessage_stack
));
10786 /* Handler for unwind-protect calling pop_message. */
10789 pop_message_unwind (void)
10791 /* Pop the top-most entry off Vmessage_stack. */
10792 eassert (CONSP (Vmessage_stack
));
10793 Vmessage_stack
= XCDR (Vmessage_stack
);
10797 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
10798 exits. If the stack is not empty, we have a missing pop_message
10802 check_message_stack (void)
10804 if (!NILP (Vmessage_stack
))
10809 /* Truncate to NCHARS what will be displayed in the echo area the next
10810 time we display it---but don't redisplay it now. */
10813 truncate_echo_area (ptrdiff_t nchars
)
10816 echo_area_buffer
[0] = Qnil
;
10817 else if (!noninteractive
10819 && !NILP (echo_area_buffer
[0]))
10821 struct frame
*sf
= SELECTED_FRAME ();
10822 /* Error messages get reported properly by cmd_error, so this must be
10823 just an informative message; if the frame hasn't really been
10824 initialized yet, just toss it. */
10825 if (sf
->glyphs_initialized_p
)
10826 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
);
10831 /* Helper function for truncate_echo_area. Truncate the current
10832 message to at most NCHARS characters. */
10835 truncate_message_1 (ptrdiff_t nchars
, Lisp_Object a2
)
10837 if (BEG
+ nchars
< Z
)
10838 del_range (BEG
+ nchars
, Z
);
10840 echo_area_buffer
[0] = Qnil
;
10844 /* Set the current message to STRING. */
10847 set_message (Lisp_Object string
)
10849 eassert (STRINGP (string
));
10851 message_enable_multibyte
= STRING_MULTIBYTE (string
);
10853 with_echo_area_buffer (0, -1, set_message_1
, 0, string
);
10854 message_buf_print
= 0;
10855 help_echo_showing_p
= 0;
10857 if (STRINGP (Vdebug_on_message
)
10858 && STRINGP (string
)
10859 && fast_string_match (Vdebug_on_message
, string
) >= 0)
10860 call_debugger (list2 (Qerror
, string
));
10864 /* Helper function for set_message. First argument is ignored and second
10865 argument has the same meaning as for set_message.
10866 This function is called with the echo area buffer being current. */
10869 set_message_1 (ptrdiff_t a1
, Lisp_Object string
)
10871 eassert (STRINGP (string
));
10873 /* Change multibyteness of the echo buffer appropriately. */
10874 if (message_enable_multibyte
10875 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10876 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
10878 bset_truncate_lines (current_buffer
, message_truncate_lines
? Qt
: Qnil
);
10879 if (!NILP (BVAR (current_buffer
, bidi_display_reordering
)))
10880 bset_bidi_paragraph_direction (current_buffer
, Qleft_to_right
);
10882 /* Insert new message at BEG. */
10883 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10885 /* This function takes care of single/multibyte conversion.
10886 We just have to ensure that the echo area buffer has the right
10887 setting of enable_multibyte_characters. */
10888 insert_from_string (string
, 0, 0, SCHARS (string
), SBYTES (string
), 1);
10894 /* Clear messages. CURRENT_P non-zero means clear the current
10895 message. LAST_DISPLAYED_P non-zero means clear the message
10899 clear_message (bool current_p
, bool last_displayed_p
)
10903 echo_area_buffer
[0] = Qnil
;
10904 message_cleared_p
= true;
10907 if (last_displayed_p
)
10908 echo_area_buffer
[1] = Qnil
;
10910 message_buf_print
= 0;
10913 /* Clear garbaged frames.
10915 This function is used where the old redisplay called
10916 redraw_garbaged_frames which in turn called redraw_frame which in
10917 turn called clear_frame. The call to clear_frame was a source of
10918 flickering. I believe a clear_frame is not necessary. It should
10919 suffice in the new redisplay to invalidate all current matrices,
10920 and ensure a complete redisplay of all windows. */
10923 clear_garbaged_frames (void)
10925 if (frame_garbaged
)
10927 Lisp_Object tail
, frame
;
10929 FOR_EACH_FRAME (tail
, frame
)
10931 struct frame
*f
= XFRAME (frame
);
10933 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
10938 clear_current_matrices (f
);
10939 fset_redisplay (f
);
10940 f
->garbaged
= false;
10941 f
->resized_p
= false;
10945 frame_garbaged
= false;
10950 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
10951 is non-zero update selected_frame. Value is non-zero if the
10952 mini-windows height has been changed. */
10955 echo_area_display (int update_frame_p
)
10957 Lisp_Object mini_window
;
10960 int window_height_changed_p
= 0;
10961 struct frame
*sf
= SELECTED_FRAME ();
10963 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10964 w
= XWINDOW (mini_window
);
10965 f
= XFRAME (WINDOW_FRAME (w
));
10967 /* Don't display if frame is invisible or not yet initialized. */
10968 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
10971 #ifdef HAVE_WINDOW_SYSTEM
10972 /* When Emacs starts, selected_frame may be the initial terminal
10973 frame. If we let this through, a message would be displayed on
10975 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
10977 #endif /* HAVE_WINDOW_SYSTEM */
10979 /* Redraw garbaged frames. */
10980 clear_garbaged_frames ();
10982 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
10984 echo_area_window
= mini_window
;
10985 window_height_changed_p
= display_echo_area (w
);
10986 w
->must_be_updated_p
= true;
10988 /* Update the display, unless called from redisplay_internal.
10989 Also don't update the screen during redisplay itself. The
10990 update will happen at the end of redisplay, and an update
10991 here could cause confusion. */
10992 if (update_frame_p
&& !redisplaying_p
)
10996 /* If the display update has been interrupted by pending
10997 input, update mode lines in the frame. Due to the
10998 pending input, it might have been that redisplay hasn't
10999 been called, so that mode lines above the echo area are
11000 garbaged. This looks odd, so we prevent it here. */
11001 if (!display_completed
)
11002 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), false);
11004 if (window_height_changed_p
11005 /* Don't do this if Emacs is shutting down. Redisplay
11006 needs to run hooks. */
11007 && !NILP (Vrun_hooks
))
11009 /* Must update other windows. Likewise as in other
11010 cases, don't let this update be interrupted by
11012 ptrdiff_t count
= SPECPDL_INDEX ();
11013 specbind (Qredisplay_dont_pause
, Qt
);
11014 windows_or_buffers_changed
= 44;
11015 redisplay_internal ();
11016 unbind_to (count
, Qnil
);
11018 else if (FRAME_WINDOW_P (f
) && n
== 0)
11020 /* Window configuration is the same as before.
11021 Can do with a display update of the echo area,
11022 unless we displayed some mode lines. */
11023 update_single_window (w
, 1);
11027 update_frame (f
, 1, 1);
11029 /* If cursor is in the echo area, make sure that the next
11030 redisplay displays the minibuffer, so that the cursor will
11031 be replaced with what the minibuffer wants. */
11032 if (cursor_in_echo_area
)
11033 wset_redisplay (XWINDOW (mini_window
));
11036 else if (!EQ (mini_window
, selected_window
))
11037 wset_redisplay (XWINDOW (mini_window
));
11039 /* Last displayed message is now the current message. */
11040 echo_area_buffer
[1] = echo_area_buffer
[0];
11041 /* Inform read_char that we're not echoing. */
11042 echo_message_buffer
= Qnil
;
11044 /* Prevent redisplay optimization in redisplay_internal by resetting
11045 this_line_start_pos. This is done because the mini-buffer now
11046 displays the message instead of its buffer text. */
11047 if (EQ (mini_window
, selected_window
))
11048 CHARPOS (this_line_start_pos
) = 0;
11050 return window_height_changed_p
;
11053 /* Nonzero if W's buffer was changed but not saved. */
11056 window_buffer_changed (struct window
*w
)
11058 struct buffer
*b
= XBUFFER (w
->contents
);
11060 eassert (BUFFER_LIVE_P (b
));
11062 return (((BUF_SAVE_MODIFF (b
) < BUF_MODIFF (b
)) != w
->last_had_star
));
11065 /* Nonzero if W has %c in its mode line and mode line should be updated. */
11068 mode_line_update_needed (struct window
*w
)
11070 return (w
->column_number_displayed
!= -1
11071 && !(PT
== w
->last_point
&& !window_outdated (w
))
11072 && (w
->column_number_displayed
!= current_column ()));
11075 /* Nonzero if window start of W is frozen and may not be changed during
11079 window_frozen_p (struct window
*w
)
11081 if (FRAME_WINDOWS_FROZEN (XFRAME (WINDOW_FRAME (w
))))
11083 Lisp_Object window
;
11085 XSETWINDOW (window
, w
);
11086 if (MINI_WINDOW_P (w
))
11088 else if (EQ (window
, selected_window
))
11090 else if (MINI_WINDOW_P (XWINDOW (selected_window
))
11091 && EQ (window
, Vminibuf_scroll_window
))
11092 /* This special window can't be frozen too. */
11100 /***********************************************************************
11101 Mode Lines and Frame Titles
11102 ***********************************************************************/
11104 /* A buffer for constructing non-propertized mode-line strings and
11105 frame titles in it; allocated from the heap in init_xdisp and
11106 resized as needed in store_mode_line_noprop_char. */
11108 static char *mode_line_noprop_buf
;
11110 /* The buffer's end, and a current output position in it. */
11112 static char *mode_line_noprop_buf_end
;
11113 static char *mode_line_noprop_ptr
;
11115 #define MODE_LINE_NOPROP_LEN(start) \
11116 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
11119 MODE_LINE_DISPLAY
= 0,
11123 } mode_line_target
;
11125 /* Alist that caches the results of :propertize.
11126 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
11127 static Lisp_Object mode_line_proptrans_alist
;
11129 /* List of strings making up the mode-line. */
11130 static Lisp_Object mode_line_string_list
;
11132 /* Base face property when building propertized mode line string. */
11133 static Lisp_Object mode_line_string_face
;
11134 static Lisp_Object mode_line_string_face_prop
;
11137 /* Unwind data for mode line strings */
11139 static Lisp_Object Vmode_line_unwind_vector
;
11142 format_mode_line_unwind_data (struct frame
*target_frame
,
11143 struct buffer
*obuf
,
11145 int save_proptrans
)
11147 Lisp_Object vector
, tmp
;
11149 /* Reduce consing by keeping one vector in
11150 Vwith_echo_area_save_vector. */
11151 vector
= Vmode_line_unwind_vector
;
11152 Vmode_line_unwind_vector
= Qnil
;
11155 vector
= Fmake_vector (make_number (10), Qnil
);
11157 ASET (vector
, 0, make_number (mode_line_target
));
11158 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
11159 ASET (vector
, 2, mode_line_string_list
);
11160 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
11161 ASET (vector
, 4, mode_line_string_face
);
11162 ASET (vector
, 5, mode_line_string_face_prop
);
11165 XSETBUFFER (tmp
, obuf
);
11168 ASET (vector
, 6, tmp
);
11169 ASET (vector
, 7, owin
);
11172 /* Similarly to `with-selected-window', if the operation selects
11173 a window on another frame, we must restore that frame's
11174 selected window, and (for a tty) the top-frame. */
11175 ASET (vector
, 8, target_frame
->selected_window
);
11176 if (FRAME_TERMCAP_P (target_frame
))
11177 ASET (vector
, 9, FRAME_TTY (target_frame
)->top_frame
);
11184 unwind_format_mode_line (Lisp_Object vector
)
11186 Lisp_Object old_window
= AREF (vector
, 7);
11187 Lisp_Object target_frame_window
= AREF (vector
, 8);
11188 Lisp_Object old_top_frame
= AREF (vector
, 9);
11190 mode_line_target
= XINT (AREF (vector
, 0));
11191 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
11192 mode_line_string_list
= AREF (vector
, 2);
11193 if (! EQ (AREF (vector
, 3), Qt
))
11194 mode_line_proptrans_alist
= AREF (vector
, 3);
11195 mode_line_string_face
= AREF (vector
, 4);
11196 mode_line_string_face_prop
= AREF (vector
, 5);
11198 /* Select window before buffer, since it may change the buffer. */
11199 if (!NILP (old_window
))
11201 /* If the operation that we are unwinding had selected a window
11202 on a different frame, reset its frame-selected-window. For a
11203 text terminal, reset its top-frame if necessary. */
11204 if (!NILP (target_frame_window
))
11207 = WINDOW_FRAME (XWINDOW (target_frame_window
));
11209 if (!EQ (frame
, WINDOW_FRAME (XWINDOW (old_window
))))
11210 Fselect_window (target_frame_window
, Qt
);
11212 if (!NILP (old_top_frame
) && !EQ (old_top_frame
, frame
))
11213 Fselect_frame (old_top_frame
, Qt
);
11216 Fselect_window (old_window
, Qt
);
11219 if (!NILP (AREF (vector
, 6)))
11221 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
11222 ASET (vector
, 6, Qnil
);
11225 Vmode_line_unwind_vector
= vector
;
11229 /* Store a single character C for the frame title in mode_line_noprop_buf.
11230 Re-allocate mode_line_noprop_buf if necessary. */
11233 store_mode_line_noprop_char (char c
)
11235 /* If output position has reached the end of the allocated buffer,
11236 increase the buffer's size. */
11237 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
11239 ptrdiff_t len
= MODE_LINE_NOPROP_LEN (0);
11240 ptrdiff_t size
= len
;
11241 mode_line_noprop_buf
=
11242 xpalloc (mode_line_noprop_buf
, &size
, 1, STRING_BYTES_BOUND
, 1);
11243 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
11244 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
11247 *mode_line_noprop_ptr
++ = c
;
11251 /* Store part of a frame title in mode_line_noprop_buf, beginning at
11252 mode_line_noprop_ptr. STRING is the string to store. Do not copy
11253 characters that yield more columns than PRECISION; PRECISION <= 0
11254 means copy the whole string. Pad with spaces until FIELD_WIDTH
11255 number of characters have been copied; FIELD_WIDTH <= 0 means don't
11256 pad. Called from display_mode_element when it is used to build a
11260 store_mode_line_noprop (const char *string
, int field_width
, int precision
)
11262 const unsigned char *str
= (const unsigned char *) string
;
11264 ptrdiff_t dummy
, nbytes
;
11266 /* Copy at most PRECISION chars from STR. */
11267 nbytes
= strlen (string
);
11268 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
11270 store_mode_line_noprop_char (*str
++);
11272 /* Fill up with spaces until FIELD_WIDTH reached. */
11273 while (field_width
> 0
11274 && n
< field_width
)
11276 store_mode_line_noprop_char (' ');
11283 /***********************************************************************
11285 ***********************************************************************/
11287 #ifdef HAVE_WINDOW_SYSTEM
11289 /* Set the title of FRAME, if it has changed. The title format is
11290 Vicon_title_format if FRAME is iconified, otherwise it is
11291 frame_title_format. */
11294 x_consider_frame_title (Lisp_Object frame
)
11296 struct frame
*f
= XFRAME (frame
);
11298 if (FRAME_WINDOW_P (f
)
11299 || FRAME_MINIBUF_ONLY_P (f
)
11300 || f
->explicit_name
)
11302 /* Do we have more than one visible frame on this X display? */
11303 Lisp_Object tail
, other_frame
, fmt
;
11304 ptrdiff_t title_start
;
11308 ptrdiff_t count
= SPECPDL_INDEX ();
11310 FOR_EACH_FRAME (tail
, other_frame
)
11312 struct frame
*tf
= XFRAME (other_frame
);
11315 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
11316 && !FRAME_MINIBUF_ONLY_P (tf
)
11317 && !EQ (other_frame
, tip_frame
)
11318 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
11322 /* Set global variable indicating that multiple frames exist. */
11323 multiple_frames
= CONSP (tail
);
11325 /* Switch to the buffer of selected window of the frame. Set up
11326 mode_line_target so that display_mode_element will output into
11327 mode_line_noprop_buf; then display the title. */
11328 record_unwind_protect (unwind_format_mode_line
,
11329 format_mode_line_unwind_data
11330 (f
, current_buffer
, selected_window
, 0));
11332 Fselect_window (f
->selected_window
, Qt
);
11333 set_buffer_internal_1
11334 (XBUFFER (XWINDOW (f
->selected_window
)->contents
));
11335 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
11337 mode_line_target
= MODE_LINE_TITLE
;
11338 title_start
= MODE_LINE_NOPROP_LEN (0);
11339 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
11340 NULL
, DEFAULT_FACE_ID
);
11341 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
11342 len
= MODE_LINE_NOPROP_LEN (title_start
);
11343 title
= mode_line_noprop_buf
+ title_start
;
11344 unbind_to (count
, Qnil
);
11346 /* Set the title only if it's changed. This avoids consing in
11347 the common case where it hasn't. (If it turns out that we've
11348 already wasted too much time by walking through the list with
11349 display_mode_element, then we might need to optimize at a
11350 higher level than this.) */
11351 if (! STRINGP (f
->name
)
11352 || SBYTES (f
->name
) != len
11353 || memcmp (title
, SDATA (f
->name
), len
) != 0)
11354 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
11358 #endif /* not HAVE_WINDOW_SYSTEM */
11361 /***********************************************************************
11363 ***********************************************************************/
11365 /* Non-zero if we will not redisplay all visible windows. */
11366 #define REDISPLAY_SOME_P() \
11367 ((windows_or_buffers_changed == 0 \
11368 || windows_or_buffers_changed == REDISPLAY_SOME) \
11369 && (update_mode_lines == 0 \
11370 || update_mode_lines == REDISPLAY_SOME))
11372 /* Prepare for redisplay by updating menu-bar item lists when
11373 appropriate. This can call eval. */
11376 prepare_menu_bars (void)
11378 bool all_windows
= windows_or_buffers_changed
|| update_mode_lines
;
11379 bool some_windows
= REDISPLAY_SOME_P ();
11380 struct gcpro gcpro1
, gcpro2
;
11381 Lisp_Object tooltip_frame
;
11383 #ifdef HAVE_WINDOW_SYSTEM
11384 tooltip_frame
= tip_frame
;
11386 tooltip_frame
= Qnil
;
11389 if (FUNCTIONP (Vpre_redisplay_function
))
11391 Lisp_Object windows
= all_windows
? Qt
: Qnil
;
11392 if (all_windows
&& some_windows
)
11394 Lisp_Object ws
= window_list ();
11395 for (windows
= Qnil
; CONSP (ws
); ws
= XCDR (ws
))
11397 Lisp_Object
this = XCAR (ws
);
11398 struct window
*w
= XWINDOW (this);
11400 || XFRAME (w
->frame
)->redisplay
11401 || XBUFFER (w
->contents
)->text
->redisplay
)
11403 windows
= Fcons (this, windows
);
11407 safe_call1 (Vpre_redisplay_function
, windows
);
11410 /* Update all frame titles based on their buffer names, etc. We do
11411 this before the menu bars so that the buffer-menu will show the
11412 up-to-date frame titles. */
11413 #ifdef HAVE_WINDOW_SYSTEM
11416 Lisp_Object tail
, frame
;
11418 FOR_EACH_FRAME (tail
, frame
)
11420 struct frame
*f
= XFRAME (frame
);
11421 struct window
*w
= XWINDOW (FRAME_SELECTED_WINDOW (f
));
11425 && !XBUFFER (w
->contents
)->text
->redisplay
)
11428 if (!EQ (frame
, tooltip_frame
)
11429 && (FRAME_ICONIFIED_P (f
)
11430 || FRAME_VISIBLE_P (f
) == 1
11431 /* Exclude TTY frames that are obscured because they
11432 are not the top frame on their console. This is
11433 because x_consider_frame_title actually switches
11434 to the frame, which for TTY frames means it is
11435 marked as garbaged, and will be completely
11436 redrawn on the next redisplay cycle. This causes
11437 TTY frames to be completely redrawn, when there
11438 are more than one of them, even though nothing
11439 should be changed on display. */
11440 || (FRAME_VISIBLE_P (f
) == 2 && FRAME_WINDOW_P (f
))))
11441 x_consider_frame_title (frame
);
11444 #endif /* HAVE_WINDOW_SYSTEM */
11446 /* Update the menu bar item lists, if appropriate. This has to be
11447 done before any actual redisplay or generation of display lines. */
11451 Lisp_Object tail
, frame
;
11452 ptrdiff_t count
= SPECPDL_INDEX ();
11453 /* 1 means that update_menu_bar has run its hooks
11454 so any further calls to update_menu_bar shouldn't do so again. */
11455 int menu_bar_hooks_run
= 0;
11457 record_unwind_save_match_data ();
11459 FOR_EACH_FRAME (tail
, frame
)
11461 struct frame
*f
= XFRAME (frame
);
11462 struct window
*w
= XWINDOW (FRAME_SELECTED_WINDOW (f
));
11464 /* Ignore tooltip frame. */
11465 if (EQ (frame
, tooltip_frame
))
11471 && !XBUFFER (w
->contents
)->text
->redisplay
)
11474 /* If a window on this frame changed size, report that to
11475 the user and clear the size-change flag. */
11476 if (FRAME_WINDOW_SIZES_CHANGED (f
))
11478 Lisp_Object functions
;
11480 /* Clear flag first in case we get an error below. */
11481 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
11482 functions
= Vwindow_size_change_functions
;
11483 GCPRO2 (tail
, functions
);
11485 while (CONSP (functions
))
11487 if (!EQ (XCAR (functions
), Qt
))
11488 call1 (XCAR (functions
), frame
);
11489 functions
= XCDR (functions
);
11495 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
11496 #ifdef HAVE_WINDOW_SYSTEM
11497 update_tool_bar (f
, 0);
11500 if (windows_or_buffers_changed
11503 (f
, Fbuffer_modified_p (XWINDOW (f
->selected_window
)->contents
));
11508 unbind_to (count
, Qnil
);
11512 struct frame
*sf
= SELECTED_FRAME ();
11513 update_menu_bar (sf
, 1, 0);
11514 #ifdef HAVE_WINDOW_SYSTEM
11515 update_tool_bar (sf
, 1);
11521 /* Update the menu bar item list for frame F. This has to be done
11522 before we start to fill in any display lines, because it can call
11525 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
11527 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
11528 already ran the menu bar hooks for this redisplay, so there
11529 is no need to run them again. The return value is the
11530 updated value of this flag, to pass to the next call. */
11533 update_menu_bar (struct frame
*f
, int save_match_data
, int hooks_run
)
11535 Lisp_Object window
;
11536 register struct window
*w
;
11538 /* If called recursively during a menu update, do nothing. This can
11539 happen when, for instance, an activate-menubar-hook causes a
11541 if (inhibit_menubar_update
)
11544 window
= FRAME_SELECTED_WINDOW (f
);
11545 w
= XWINDOW (window
);
11547 if (FRAME_WINDOW_P (f
)
11549 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11550 || defined (HAVE_NS) || defined (USE_GTK)
11551 FRAME_EXTERNAL_MENU_BAR (f
)
11553 FRAME_MENU_BAR_LINES (f
) > 0
11555 : FRAME_MENU_BAR_LINES (f
) > 0)
11557 /* If the user has switched buffers or windows, we need to
11558 recompute to reflect the new bindings. But we'll
11559 recompute when update_mode_lines is set too; that means
11560 that people can use force-mode-line-update to request
11561 that the menu bar be recomputed. The adverse effect on
11562 the rest of the redisplay algorithm is about the same as
11563 windows_or_buffers_changed anyway. */
11564 if (windows_or_buffers_changed
11565 /* This used to test w->update_mode_line, but we believe
11566 there is no need to recompute the menu in that case. */
11567 || update_mode_lines
11568 || window_buffer_changed (w
))
11570 struct buffer
*prev
= current_buffer
;
11571 ptrdiff_t count
= SPECPDL_INDEX ();
11573 specbind (Qinhibit_menubar_update
, Qt
);
11575 set_buffer_internal_1 (XBUFFER (w
->contents
));
11576 if (save_match_data
)
11577 record_unwind_save_match_data ();
11578 if (NILP (Voverriding_local_map_menu_flag
))
11580 specbind (Qoverriding_terminal_local_map
, Qnil
);
11581 specbind (Qoverriding_local_map
, Qnil
);
11586 /* Run the Lucid hook. */
11587 safe_run_hooks (Qactivate_menubar_hook
);
11589 /* If it has changed current-menubar from previous value,
11590 really recompute the menu-bar from the value. */
11591 if (! NILP (Vlucid_menu_bar_dirty_flag
))
11592 call0 (Qrecompute_lucid_menubar
);
11594 safe_run_hooks (Qmenu_bar_update_hook
);
11599 XSETFRAME (Vmenu_updating_frame
, f
);
11600 fset_menu_bar_items (f
, menu_bar_items (FRAME_MENU_BAR_ITEMS (f
)));
11602 /* Redisplay the menu bar in case we changed it. */
11603 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11604 || defined (HAVE_NS) || defined (USE_GTK)
11605 if (FRAME_WINDOW_P (f
))
11607 #if defined (HAVE_NS)
11608 /* All frames on Mac OS share the same menubar. So only
11609 the selected frame should be allowed to set it. */
11610 if (f
== SELECTED_FRAME ())
11612 set_frame_menubar (f
, 0, 0);
11615 /* On a terminal screen, the menu bar is an ordinary screen
11616 line, and this makes it get updated. */
11617 w
->update_mode_line
= 1;
11618 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11619 /* In the non-toolkit version, the menu bar is an ordinary screen
11620 line, and this makes it get updated. */
11621 w
->update_mode_line
= 1;
11622 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11624 unbind_to (count
, Qnil
);
11625 set_buffer_internal_1 (prev
);
11632 /***********************************************************************
11634 ***********************************************************************/
11636 #ifdef HAVE_WINDOW_SYSTEM
11638 /* Tool-bar item index of the item on which a mouse button was pressed
11641 int last_tool_bar_item
;
11643 /* Select `frame' temporarily without running all the code in
11645 FIXME: Maybe do_switch_frame should be trimmed down similarly
11646 when `norecord' is set. */
11648 fast_set_selected_frame (Lisp_Object frame
)
11650 if (!EQ (selected_frame
, frame
))
11652 selected_frame
= frame
;
11653 selected_window
= XFRAME (frame
)->selected_window
;
11657 /* Update the tool-bar item list for frame F. This has to be done
11658 before we start to fill in any display lines. Called from
11659 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
11660 and restore it here. */
11663 update_tool_bar (struct frame
*f
, int save_match_data
)
11665 #if defined (USE_GTK) || defined (HAVE_NS)
11666 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
11668 int do_update
= (WINDOWP (f
->tool_bar_window
)
11669 && WINDOW_PIXEL_HEIGHT (XWINDOW (f
->tool_bar_window
)) > 0);
11674 Lisp_Object window
;
11677 window
= FRAME_SELECTED_WINDOW (f
);
11678 w
= XWINDOW (window
);
11680 /* If the user has switched buffers or windows, we need to
11681 recompute to reflect the new bindings. But we'll
11682 recompute when update_mode_lines is set too; that means
11683 that people can use force-mode-line-update to request
11684 that the menu bar be recomputed. The adverse effect on
11685 the rest of the redisplay algorithm is about the same as
11686 windows_or_buffers_changed anyway. */
11687 if (windows_or_buffers_changed
11688 || w
->update_mode_line
11689 || update_mode_lines
11690 || window_buffer_changed (w
))
11692 struct buffer
*prev
= current_buffer
;
11693 ptrdiff_t count
= SPECPDL_INDEX ();
11694 Lisp_Object frame
, new_tool_bar
;
11695 int new_n_tool_bar
;
11696 struct gcpro gcpro1
;
11698 /* Set current_buffer to the buffer of the selected
11699 window of the frame, so that we get the right local
11701 set_buffer_internal_1 (XBUFFER (w
->contents
));
11703 /* Save match data, if we must. */
11704 if (save_match_data
)
11705 record_unwind_save_match_data ();
11707 /* Make sure that we don't accidentally use bogus keymaps. */
11708 if (NILP (Voverriding_local_map_menu_flag
))
11710 specbind (Qoverriding_terminal_local_map
, Qnil
);
11711 specbind (Qoverriding_local_map
, Qnil
);
11714 GCPRO1 (new_tool_bar
);
11716 /* We must temporarily set the selected frame to this frame
11717 before calling tool_bar_items, because the calculation of
11718 the tool-bar keymap uses the selected frame (see
11719 `tool-bar-make-keymap' in tool-bar.el). */
11720 eassert (EQ (selected_window
,
11721 /* Since we only explicitly preserve selected_frame,
11722 check that selected_window would be redundant. */
11723 XFRAME (selected_frame
)->selected_window
));
11724 record_unwind_protect (fast_set_selected_frame
, selected_frame
);
11725 XSETFRAME (frame
, f
);
11726 fast_set_selected_frame (frame
);
11728 /* Build desired tool-bar items from keymaps. */
11730 = tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
11733 /* Redisplay the tool-bar if we changed it. */
11734 if (new_n_tool_bar
!= f
->n_tool_bar_items
11735 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
11737 /* Redisplay that happens asynchronously due to an expose event
11738 may access f->tool_bar_items. Make sure we update both
11739 variables within BLOCK_INPUT so no such event interrupts. */
11741 fset_tool_bar_items (f
, new_tool_bar
);
11742 f
->n_tool_bar_items
= new_n_tool_bar
;
11743 w
->update_mode_line
= 1;
11749 unbind_to (count
, Qnil
);
11750 set_buffer_internal_1 (prev
);
11755 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
11757 /* Set F->desired_tool_bar_string to a Lisp string representing frame
11758 F's desired tool-bar contents. F->tool_bar_items must have
11759 been set up previously by calling prepare_menu_bars. */
11762 build_desired_tool_bar_string (struct frame
*f
)
11764 int i
, size
, size_needed
;
11765 struct gcpro gcpro1
, gcpro2
, gcpro3
;
11766 Lisp_Object image
, plist
, props
;
11768 image
= plist
= props
= Qnil
;
11769 GCPRO3 (image
, plist
, props
);
11771 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
11772 Otherwise, make a new string. */
11774 /* The size of the string we might be able to reuse. */
11775 size
= (STRINGP (f
->desired_tool_bar_string
)
11776 ? SCHARS (f
->desired_tool_bar_string
)
11779 /* We need one space in the string for each image. */
11780 size_needed
= f
->n_tool_bar_items
;
11782 /* Reuse f->desired_tool_bar_string, if possible. */
11783 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
11784 fset_desired_tool_bar_string
11785 (f
, Fmake_string (make_number (size_needed
), make_number (' ')));
11788 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
11789 Fremove_text_properties (make_number (0), make_number (size
),
11790 props
, f
->desired_tool_bar_string
);
11793 /* Put a `display' property on the string for the images to display,
11794 put a `menu_item' property on tool-bar items with a value that
11795 is the index of the item in F's tool-bar item vector. */
11796 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
11798 #define PROP(IDX) \
11799 AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
11801 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
11802 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
11803 int hmargin
, vmargin
, relief
, idx
, end
;
11805 /* If image is a vector, choose the image according to the
11807 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
11808 if (VECTORP (image
))
11812 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
11813 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
11816 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
11817 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
11819 eassert (ASIZE (image
) >= idx
);
11820 image
= AREF (image
, idx
);
11825 /* Ignore invalid image specifications. */
11826 if (!valid_image_p (image
))
11829 /* Display the tool-bar button pressed, or depressed. */
11830 plist
= Fcopy_sequence (XCDR (image
));
11832 /* Compute margin and relief to draw. */
11833 relief
= (tool_bar_button_relief
>= 0
11834 ? tool_bar_button_relief
11835 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
11836 hmargin
= vmargin
= relief
;
11838 if (RANGED_INTEGERP (1, Vtool_bar_button_margin
,
11839 INT_MAX
- max (hmargin
, vmargin
)))
11841 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
11842 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
11844 else if (CONSP (Vtool_bar_button_margin
))
11846 if (RANGED_INTEGERP (1, XCAR (Vtool_bar_button_margin
),
11847 INT_MAX
- hmargin
))
11848 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
11850 if (RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin
),
11851 INT_MAX
- vmargin
))
11852 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
11855 if (auto_raise_tool_bar_buttons_p
)
11857 /* Add a `:relief' property to the image spec if the item is
11861 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
11868 /* If image is selected, display it pressed, i.e. with a
11869 negative relief. If it's not selected, display it with a
11871 plist
= Fplist_put (plist
, QCrelief
,
11873 ? make_number (-relief
)
11874 : make_number (relief
)));
11879 /* Put a margin around the image. */
11880 if (hmargin
|| vmargin
)
11882 if (hmargin
== vmargin
)
11883 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
11885 plist
= Fplist_put (plist
, QCmargin
,
11886 Fcons (make_number (hmargin
),
11887 make_number (vmargin
)));
11890 /* If button is not enabled, and we don't have special images
11891 for the disabled state, make the image appear disabled by
11892 applying an appropriate algorithm to it. */
11893 if (!enabled_p
&& idx
< 0)
11894 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
11896 /* Put a `display' text property on the string for the image to
11897 display. Put a `menu-item' property on the string that gives
11898 the start of this item's properties in the tool-bar items
11900 image
= Fcons (Qimage
, plist
);
11901 props
= list4 (Qdisplay
, image
,
11902 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
11904 /* Let the last image hide all remaining spaces in the tool bar
11905 string. The string can be longer than needed when we reuse a
11906 previous string. */
11907 if (i
+ 1 == f
->n_tool_bar_items
)
11908 end
= SCHARS (f
->desired_tool_bar_string
);
11911 Fadd_text_properties (make_number (i
), make_number (end
),
11912 props
, f
->desired_tool_bar_string
);
11920 /* Display one line of the tool-bar of frame IT->f.
11922 HEIGHT specifies the desired height of the tool-bar line.
11923 If the actual height of the glyph row is less than HEIGHT, the
11924 row's height is increased to HEIGHT, and the icons are centered
11925 vertically in the new height.
11927 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
11928 count a final empty row in case the tool-bar width exactly matches
11933 display_tool_bar_line (struct it
*it
, int height
)
11935 struct glyph_row
*row
= it
->glyph_row
;
11936 int max_x
= it
->last_visible_x
;
11937 struct glyph
*last
;
11939 prepare_desired_row (row
);
11940 row
->y
= it
->current_y
;
11942 /* Note that this isn't made use of if the face hasn't a box,
11943 so there's no need to check the face here. */
11944 it
->start_of_box_run_p
= 1;
11946 while (it
->current_x
< max_x
)
11948 int x
, n_glyphs_before
, i
, nglyphs
;
11949 struct it it_before
;
11951 /* Get the next display element. */
11952 if (!get_next_display_element (it
))
11954 /* Don't count empty row if we are counting needed tool-bar lines. */
11955 if (height
< 0 && !it
->hpos
)
11960 /* Produce glyphs. */
11961 n_glyphs_before
= row
->used
[TEXT_AREA
];
11964 PRODUCE_GLYPHS (it
);
11966 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
11968 x
= it_before
.current_x
;
11969 while (i
< nglyphs
)
11971 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
11973 if (x
+ glyph
->pixel_width
> max_x
)
11975 /* Glyph doesn't fit on line. Backtrack. */
11976 row
->used
[TEXT_AREA
] = n_glyphs_before
;
11978 /* If this is the only glyph on this line, it will never fit on the
11979 tool-bar, so skip it. But ensure there is at least one glyph,
11980 so we don't accidentally disable the tool-bar. */
11981 if (n_glyphs_before
== 0
11982 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
11988 x
+= glyph
->pixel_width
;
11992 /* Stop at line end. */
11993 if (ITERATOR_AT_END_OF_LINE_P (it
))
11996 set_iterator_to_next (it
, 1);
12001 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
12003 /* Use default face for the border below the tool bar.
12005 FIXME: When auto-resize-tool-bars is grow-only, there is
12006 no additional border below the possibly empty tool-bar lines.
12007 So to make the extra empty lines look "normal", we have to
12008 use the tool-bar face for the border too. */
12009 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12010 && !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
12011 it
->face_id
= DEFAULT_FACE_ID
;
12013 extend_face_to_end_of_line (it
);
12014 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
12015 last
->right_box_line_p
= 1;
12016 if (last
== row
->glyphs
[TEXT_AREA
])
12017 last
->left_box_line_p
= 1;
12019 /* Make line the desired height and center it vertically. */
12020 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
12022 /* Don't add more than one line height. */
12023 height
%= FRAME_LINE_HEIGHT (it
->f
);
12024 it
->max_ascent
+= height
/ 2;
12025 it
->max_descent
+= (height
+ 1) / 2;
12028 compute_line_metrics (it
);
12030 /* If line is empty, make it occupy the rest of the tool-bar. */
12031 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12033 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
12034 row
->visible_height
= row
->height
;
12035 row
->ascent
= row
->phys_ascent
= 0;
12036 row
->extra_line_spacing
= 0;
12039 row
->full_width_p
= 1;
12040 row
->continued_p
= 0;
12041 row
->truncated_on_left_p
= 0;
12042 row
->truncated_on_right_p
= 0;
12044 it
->current_x
= it
->hpos
= 0;
12045 it
->current_y
+= row
->height
;
12051 /* Max tool-bar height. Basically, this is what makes all other windows
12052 disappear when the frame gets too small. Rethink this! */
12054 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
12055 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
12057 /* Value is the number of screen lines needed to make all tool-bar
12058 items of frame F visible. The number of actual rows needed is
12059 returned in *N_ROWS if non-NULL. */
12062 tool_bar_height (struct frame
*f
, int *n_rows
, bool pixelwise
)
12064 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12066 /* tool_bar_height is called from redisplay_tool_bar after building
12067 the desired matrix, so use (unused) mode-line row as temporary row to
12068 avoid destroying the first tool-bar row. */
12069 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
12071 /* Initialize an iterator for iteration over
12072 F->desired_tool_bar_string in the tool-bar window of frame F. */
12073 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
12074 it
.first_visible_x
= 0;
12075 /* PXW: Use FRAME_PIXEL_WIDTH (f) here ? */
12076 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
12077 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
12078 it
.paragraph_embedding
= L2R
;
12080 while (!ITERATOR_AT_END_P (&it
))
12082 clear_glyph_row (temp_row
);
12083 it
.glyph_row
= temp_row
;
12084 display_tool_bar_line (&it
, -1);
12086 clear_glyph_row (temp_row
);
12088 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
12090 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
12093 return it
.current_y
;
12095 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
12098 #endif /* !USE_GTK && !HAVE_NS */
12100 #if defined USE_GTK || defined HAVE_NS
12101 EXFUN (Ftool_bar_lines_needed
, 1) ATTRIBUTE_CONST
;
12104 DEFUN ("tool-bar-height", Ftool_bar_height
, Stool_bar_height
,
12106 doc
: /* Return the number of lines occupied by the tool bar of FRAME.
12107 If FRAME is nil or omitted, use the selected frame. Optional argument
12108 PIXELWISE non-nil means return the height of the tool bar inpixels. */)
12109 (Lisp_Object frame
, Lisp_Object pixelwise
)
12111 struct frame
*f
= decode_any_frame (frame
);
12114 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
12115 if (WINDOWP (f
->tool_bar_window
)
12116 && WINDOW_PIXEL_HEIGHT (XWINDOW (f
->tool_bar_window
)) > 0)
12118 update_tool_bar (f
, 1);
12119 if (f
->n_tool_bar_items
)
12121 build_desired_tool_bar_string (f
);
12122 height
= tool_bar_height (f
, NULL
, NILP (pixelwise
) ? 0 : 1);
12127 return make_number (height
);
12131 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
12132 height should be changed. */
12135 redisplay_tool_bar (struct frame
*f
)
12137 #if defined (USE_GTK) || defined (HAVE_NS)
12139 if (FRAME_EXTERNAL_TOOL_BAR (f
))
12140 update_frame_tool_bar (f
);
12143 #else /* !USE_GTK && !HAVE_NS */
12147 struct glyph_row
*row
;
12149 /* If frame hasn't a tool-bar window or if it is zero-height, don't
12150 do anything. This means you must start with tool-bar-lines
12151 non-zero to get the auto-sizing effect. Or in other words, you
12152 can turn off tool-bars by specifying tool-bar-lines zero. */
12153 if (!WINDOWP (f
->tool_bar_window
)
12154 || (w
= XWINDOW (f
->tool_bar_window
),
12155 WINDOW_PIXEL_HEIGHT (w
) == 0))
12158 /* Set up an iterator for the tool-bar window. */
12159 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
12160 it
.first_visible_x
= 0;
12161 it
.last_visible_x
= WINDOW_PIXEL_WIDTH (w
);
12162 row
= it
.glyph_row
;
12164 /* Build a string that represents the contents of the tool-bar. */
12165 build_desired_tool_bar_string (f
);
12166 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
12167 /* FIXME: This should be controlled by a user option. But it
12168 doesn't make sense to have an R2L tool bar if the menu bar cannot
12169 be drawn also R2L, and making the menu bar R2L is tricky due
12170 toolkit-specific code that implements it. If an R2L tool bar is
12171 ever supported, display_tool_bar_line should also be augmented to
12172 call unproduce_glyphs like display_line and display_string
12174 it
.paragraph_embedding
= L2R
;
12176 if (f
->n_tool_bar_rows
== 0)
12178 int new_height
= tool_bar_height (f
, &f
->n_tool_bar_rows
, 1);
12180 if (new_height
!= WINDOW_PIXEL_HEIGHT (w
))
12183 int new_lines
= ((new_height
+ FRAME_LINE_HEIGHT (f
) - 1)
12184 / FRAME_LINE_HEIGHT (f
));
12186 XSETFRAME (frame
, f
);
12187 Fmodify_frame_parameters (frame
,
12188 list1 (Fcons (Qtool_bar_lines
,
12189 make_number (new_lines
))));
12190 /* Always do that now. */
12191 clear_glyph_matrix (w
->desired_matrix
);
12192 f
->fonts_changed
= 1;
12197 /* Display as many lines as needed to display all tool-bar items. */
12199 if (f
->n_tool_bar_rows
> 0)
12201 int border
, rows
, height
, extra
;
12203 if (TYPE_RANGED_INTEGERP (int, Vtool_bar_border
))
12204 border
= XINT (Vtool_bar_border
);
12205 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
12206 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
12207 else if (EQ (Vtool_bar_border
, Qborder_width
))
12208 border
= f
->border_width
;
12214 rows
= f
->n_tool_bar_rows
;
12215 height
= max (1, (it
.last_visible_y
- border
) / rows
);
12216 extra
= it
.last_visible_y
- border
- height
* rows
;
12218 while (it
.current_y
< it
.last_visible_y
)
12221 if (extra
> 0 && rows
-- > 0)
12223 h
= (extra
+ rows
- 1) / rows
;
12226 display_tool_bar_line (&it
, height
+ h
);
12231 while (it
.current_y
< it
.last_visible_y
)
12232 display_tool_bar_line (&it
, 0);
12235 /* It doesn't make much sense to try scrolling in the tool-bar
12236 window, so don't do it. */
12237 w
->desired_matrix
->no_scrolling_p
= 1;
12238 w
->must_be_updated_p
= 1;
12240 if (!NILP (Vauto_resize_tool_bars
))
12242 /* Do we really allow the toolbar to occupy the whole frame? */
12243 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
12244 int change_height_p
= 0;
12246 /* If we couldn't display everything, change the tool-bar's
12247 height if there is room for more. */
12248 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
12249 && it
.current_y
< max_tool_bar_height
)
12250 change_height_p
= 1;
12252 row
= it
.glyph_row
- 1;
12254 /* If there are blank lines at the end, except for a partially
12255 visible blank line at the end that is smaller than
12256 FRAME_LINE_HEIGHT, change the tool-bar's height. */
12257 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12258 && row
->height
>= FRAME_LINE_HEIGHT (f
))
12259 change_height_p
= 1;
12261 /* If row displays tool-bar items, but is partially visible,
12262 change the tool-bar's height. */
12263 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12264 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
12265 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
12266 change_height_p
= 1;
12268 /* Resize windows as needed by changing the `tool-bar-lines'
12269 frame parameter. */
12270 if (change_height_p
)
12274 int new_height
= tool_bar_height (f
, &nrows
, 1);
12276 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
12277 && !f
->minimize_tool_bar_window_p
)
12278 ? (new_height
> WINDOW_PIXEL_HEIGHT (w
))
12279 : (new_height
!= WINDOW_PIXEL_HEIGHT (w
)));
12280 f
->minimize_tool_bar_window_p
= 0;
12282 if (change_height_p
)
12284 int new_lines
= ((new_height
+ FRAME_LINE_HEIGHT (f
) - 1)
12285 / FRAME_LINE_HEIGHT (f
));
12287 XSETFRAME (frame
, f
);
12288 Fmodify_frame_parameters (frame
,
12289 list1 (Fcons (Qtool_bar_lines
,
12290 make_number (new_lines
))));
12291 /* Always do that now. */
12292 clear_glyph_matrix (w
->desired_matrix
);
12293 f
->n_tool_bar_rows
= nrows
;
12294 f
->fonts_changed
= 1;
12300 f
->minimize_tool_bar_window_p
= 0;
12303 #endif /* USE_GTK || HAVE_NS */
12306 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
12308 /* Get information about the tool-bar item which is displayed in GLYPH
12309 on frame F. Return in *PROP_IDX the index where tool-bar item
12310 properties start in F->tool_bar_items. Value is zero if
12311 GLYPH doesn't display a tool-bar item. */
12314 tool_bar_item_info (struct frame
*f
, struct glyph
*glyph
, int *prop_idx
)
12320 /* This function can be called asynchronously, which means we must
12321 exclude any possibility that Fget_text_property signals an
12323 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
12324 charpos
= max (0, charpos
);
12326 /* Get the text property `menu-item' at pos. The value of that
12327 property is the start index of this item's properties in
12328 F->tool_bar_items. */
12329 prop
= Fget_text_property (make_number (charpos
),
12330 Qmenu_item
, f
->current_tool_bar_string
);
12331 if (INTEGERP (prop
))
12333 *prop_idx
= XINT (prop
);
12343 /* Get information about the tool-bar item at position X/Y on frame F.
12344 Return in *GLYPH a pointer to the glyph of the tool-bar item in
12345 the current matrix of the tool-bar window of F, or NULL if not
12346 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
12347 item in F->tool_bar_items. Value is
12349 -1 if X/Y is not on a tool-bar item
12350 0 if X/Y is on the same item that was highlighted before.
12354 get_tool_bar_item (struct frame
*f
, int x
, int y
, struct glyph
**glyph
,
12355 int *hpos
, int *vpos
, int *prop_idx
)
12357 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12358 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12361 /* Find the glyph under X/Y. */
12362 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
12363 if (*glyph
== NULL
)
12366 /* Get the start of this tool-bar item's properties in
12367 f->tool_bar_items. */
12368 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
12371 /* Is mouse on the highlighted item? */
12372 if (EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
)
12373 && *vpos
>= hlinfo
->mouse_face_beg_row
12374 && *vpos
<= hlinfo
->mouse_face_end_row
12375 && (*vpos
> hlinfo
->mouse_face_beg_row
12376 || *hpos
>= hlinfo
->mouse_face_beg_col
)
12377 && (*vpos
< hlinfo
->mouse_face_end_row
12378 || *hpos
< hlinfo
->mouse_face_end_col
12379 || hlinfo
->mouse_face_past_end
))
12387 Handle mouse button event on the tool-bar of frame F, at
12388 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
12389 0 for button release. MODIFIERS is event modifiers for button
12393 handle_tool_bar_click (struct frame
*f
, int x
, int y
, int down_p
,
12396 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12397 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12398 int hpos
, vpos
, prop_idx
;
12399 struct glyph
*glyph
;
12400 Lisp_Object enabled_p
;
12403 /* If not on the highlighted tool-bar item, and mouse-highlight is
12404 non-nil, return. This is so we generate the tool-bar button
12405 click only when the mouse button is released on the same item as
12406 where it was pressed. However, when mouse-highlight is disabled,
12407 generate the click when the button is released regardless of the
12408 highlight, since tool-bar items are not highlighted in that
12410 frame_to_window_pixel_xy (w
, &x
, &y
);
12411 ts
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
12413 || (ts
!= 0 && !NILP (Vmouse_highlight
)))
12416 /* When mouse-highlight is off, generate the click for the item
12417 where the button was pressed, disregarding where it was
12419 if (NILP (Vmouse_highlight
) && !down_p
)
12420 prop_idx
= last_tool_bar_item
;
12422 /* If item is disabled, do nothing. */
12423 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12424 if (NILP (enabled_p
))
12429 /* Show item in pressed state. */
12430 if (!NILP (Vmouse_highlight
))
12431 show_mouse_face (hlinfo
, DRAW_IMAGE_SUNKEN
);
12432 last_tool_bar_item
= prop_idx
;
12436 Lisp_Object key
, frame
;
12437 struct input_event event
;
12438 EVENT_INIT (event
);
12440 /* Show item in released state. */
12441 if (!NILP (Vmouse_highlight
))
12442 show_mouse_face (hlinfo
, DRAW_IMAGE_RAISED
);
12444 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
12446 XSETFRAME (frame
, f
);
12447 event
.kind
= TOOL_BAR_EVENT
;
12448 event
.frame_or_window
= frame
;
12450 kbd_buffer_store_event (&event
);
12452 event
.kind
= TOOL_BAR_EVENT
;
12453 event
.frame_or_window
= frame
;
12455 event
.modifiers
= modifiers
;
12456 kbd_buffer_store_event (&event
);
12457 last_tool_bar_item
= -1;
12462 /* Possibly highlight a tool-bar item on frame F when mouse moves to
12463 tool-bar window-relative coordinates X/Y. Called from
12464 note_mouse_highlight. */
12467 note_tool_bar_highlight (struct frame
*f
, int x
, int y
)
12469 Lisp_Object window
= f
->tool_bar_window
;
12470 struct window
*w
= XWINDOW (window
);
12471 Display_Info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
12472 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12474 struct glyph
*glyph
;
12475 struct glyph_row
*row
;
12477 Lisp_Object enabled_p
;
12479 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
12480 int mouse_down_p
, rc
;
12482 /* Function note_mouse_highlight is called with negative X/Y
12483 values when mouse moves outside of the frame. */
12484 if (x
<= 0 || y
<= 0)
12486 clear_mouse_face (hlinfo
);
12490 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
12493 /* Not on tool-bar item. */
12494 clear_mouse_face (hlinfo
);
12498 /* On same tool-bar item as before. */
12499 goto set_help_echo
;
12501 clear_mouse_face (hlinfo
);
12503 /* Mouse is down, but on different tool-bar item? */
12504 mouse_down_p
= (x_mouse_grabbed (dpyinfo
)
12505 && f
== dpyinfo
->last_mouse_frame
);
12508 && last_tool_bar_item
!= prop_idx
)
12511 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
12513 /* If tool-bar item is not enabled, don't highlight it. */
12514 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12515 if (!NILP (enabled_p
) && !NILP (Vmouse_highlight
))
12517 /* Compute the x-position of the glyph. In front and past the
12518 image is a space. We include this in the highlighted area. */
12519 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
12520 for (i
= x
= 0; i
< hpos
; ++i
)
12521 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
12523 /* Record this as the current active region. */
12524 hlinfo
->mouse_face_beg_col
= hpos
;
12525 hlinfo
->mouse_face_beg_row
= vpos
;
12526 hlinfo
->mouse_face_beg_x
= x
;
12527 hlinfo
->mouse_face_past_end
= 0;
12529 hlinfo
->mouse_face_end_col
= hpos
+ 1;
12530 hlinfo
->mouse_face_end_row
= vpos
;
12531 hlinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
12532 hlinfo
->mouse_face_window
= window
;
12533 hlinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
12535 /* Display it as active. */
12536 show_mouse_face (hlinfo
, draw
);
12541 /* Set help_echo_string to a help string to display for this tool-bar item.
12542 XTread_socket does the rest. */
12543 help_echo_object
= help_echo_window
= Qnil
;
12544 help_echo_pos
= -1;
12545 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
12546 if (NILP (help_echo_string
))
12547 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
12550 #endif /* !USE_GTK && !HAVE_NS */
12552 #endif /* HAVE_WINDOW_SYSTEM */
12556 /************************************************************************
12557 Horizontal scrolling
12558 ************************************************************************/
12560 static int hscroll_window_tree (Lisp_Object
);
12561 static int hscroll_windows (Lisp_Object
);
12563 /* For all leaf windows in the window tree rooted at WINDOW, set their
12564 hscroll value so that PT is (i) visible in the window, and (ii) so
12565 that it is not within a certain margin at the window's left and
12566 right border. Value is non-zero if any window's hscroll has been
12570 hscroll_window_tree (Lisp_Object window
)
12572 int hscrolled_p
= 0;
12573 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
12574 int hscroll_step_abs
= 0;
12575 double hscroll_step_rel
= 0;
12577 if (hscroll_relative_p
)
12579 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
12580 if (hscroll_step_rel
< 0)
12582 hscroll_relative_p
= 0;
12583 hscroll_step_abs
= 0;
12586 else if (TYPE_RANGED_INTEGERP (int, Vhscroll_step
))
12588 hscroll_step_abs
= XINT (Vhscroll_step
);
12589 if (hscroll_step_abs
< 0)
12590 hscroll_step_abs
= 0;
12593 hscroll_step_abs
= 0;
12595 while (WINDOWP (window
))
12597 struct window
*w
= XWINDOW (window
);
12599 if (WINDOWP (w
->contents
))
12600 hscrolled_p
|= hscroll_window_tree (w
->contents
);
12601 else if (w
->cursor
.vpos
>= 0)
12604 int text_area_width
;
12605 struct glyph_row
*current_cursor_row
12606 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
12607 struct glyph_row
*desired_cursor_row
12608 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
12609 struct glyph_row
*cursor_row
12610 = (desired_cursor_row
->enabled_p
12611 ? desired_cursor_row
12612 : current_cursor_row
);
12613 int row_r2l_p
= cursor_row
->reversed_p
;
12615 text_area_width
= window_box_width (w
, TEXT_AREA
);
12617 /* Scroll when cursor is inside this scroll margin. */
12618 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
12620 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->contents
))
12621 /* For left-to-right rows, hscroll when cursor is either
12622 (i) inside the right hscroll margin, or (ii) if it is
12623 inside the left margin and the window is already
12627 && w
->cursor
.x
<= h_margin
)
12628 || (cursor_row
->enabled_p
12629 && cursor_row
->truncated_on_right_p
12630 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
12631 /* For right-to-left rows, the logic is similar,
12632 except that rules for scrolling to left and right
12633 are reversed. E.g., if cursor.x <= h_margin, we
12634 need to hscroll "to the right" unconditionally,
12635 and that will scroll the screen to the left so as
12636 to reveal the next portion of the row. */
12638 && ((cursor_row
->enabled_p
12639 /* FIXME: It is confusing to set the
12640 truncated_on_right_p flag when R2L rows
12641 are actually truncated on the left. */
12642 && cursor_row
->truncated_on_right_p
12643 && w
->cursor
.x
<= h_margin
)
12645 && (w
->cursor
.x
>= text_area_width
- h_margin
))))))
12649 struct buffer
*saved_current_buffer
;
12653 /* Find point in a display of infinite width. */
12654 saved_current_buffer
= current_buffer
;
12655 current_buffer
= XBUFFER (w
->contents
);
12657 if (w
== XWINDOW (selected_window
))
12660 pt
= clip_to_bounds (BEGV
, marker_position (w
->pointm
), ZV
);
12662 /* Move iterator to pt starting at cursor_row->start in
12663 a line with infinite width. */
12664 init_to_row_start (&it
, w
, cursor_row
);
12665 it
.last_visible_x
= INFINITY
;
12666 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
12667 current_buffer
= saved_current_buffer
;
12669 /* Position cursor in window. */
12670 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
12671 hscroll
= max (0, (it
.current_x
12672 - (ITERATOR_AT_END_OF_LINE_P (&it
)
12673 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
12674 : (text_area_width
/ 2))))
12675 / FRAME_COLUMN_WIDTH (it
.f
);
12676 else if ((!row_r2l_p
12677 && w
->cursor
.x
>= text_area_width
- h_margin
)
12678 || (row_r2l_p
&& w
->cursor
.x
<= h_margin
))
12680 if (hscroll_relative_p
)
12681 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
12684 wanted_x
= text_area_width
12685 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12688 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12692 if (hscroll_relative_p
)
12693 wanted_x
= text_area_width
* hscroll_step_rel
12696 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12699 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12701 hscroll
= max (hscroll
, w
->min_hscroll
);
12703 /* Don't prevent redisplay optimizations if hscroll
12704 hasn't changed, as it will unnecessarily slow down
12706 if (w
->hscroll
!= hscroll
)
12708 XBUFFER (w
->contents
)->prevent_redisplay_optimizations_p
= 1;
12709 w
->hscroll
= hscroll
;
12718 /* Value is non-zero if hscroll of any leaf window has been changed. */
12719 return hscrolled_p
;
12723 /* Set hscroll so that cursor is visible and not inside horizontal
12724 scroll margins for all windows in the tree rooted at WINDOW. See
12725 also hscroll_window_tree above. Value is non-zero if any window's
12726 hscroll has been changed. If it has, desired matrices on the frame
12727 of WINDOW are cleared. */
12730 hscroll_windows (Lisp_Object window
)
12732 int hscrolled_p
= hscroll_window_tree (window
);
12734 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
12735 return hscrolled_p
;
12740 /************************************************************************
12742 ************************************************************************/
12744 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
12745 to a non-zero value. This is sometimes handy to have in a debugger
12750 /* First and last unchanged row for try_window_id. */
12752 static int debug_first_unchanged_at_end_vpos
;
12753 static int debug_last_unchanged_at_beg_vpos
;
12755 /* Delta vpos and y. */
12757 static int debug_dvpos
, debug_dy
;
12759 /* Delta in characters and bytes for try_window_id. */
12761 static ptrdiff_t debug_delta
, debug_delta_bytes
;
12763 /* Values of window_end_pos and window_end_vpos at the end of
12766 static ptrdiff_t debug_end_vpos
;
12768 /* Append a string to W->desired_matrix->method. FMT is a printf
12769 format string. If trace_redisplay_p is non-zero also printf the
12770 resulting string to stderr. */
12772 static void debug_method_add (struct window
*, char const *, ...)
12773 ATTRIBUTE_FORMAT_PRINTF (2, 3);
12776 debug_method_add (struct window
*w
, char const *fmt
, ...)
12779 char *method
= w
->desired_matrix
->method
;
12780 int len
= strlen (method
);
12781 int size
= sizeof w
->desired_matrix
->method
;
12782 int remaining
= size
- len
- 1;
12785 if (len
&& remaining
)
12788 --remaining
, ++len
;
12791 va_start (ap
, fmt
);
12792 vsnprintf (method
+ len
, remaining
+ 1, fmt
, ap
);
12795 if (trace_redisplay_p
)
12796 fprintf (stderr
, "%p (%s): %s\n",
12798 ((BUFFERP (w
->contents
)
12799 && STRINGP (BVAR (XBUFFER (w
->contents
), name
)))
12800 ? SSDATA (BVAR (XBUFFER (w
->contents
), name
))
12805 #endif /* GLYPH_DEBUG */
12808 /* Value is non-zero if all changes in window W, which displays
12809 current_buffer, are in the text between START and END. START is a
12810 buffer position, END is given as a distance from Z. Used in
12811 redisplay_internal for display optimization. */
12814 text_outside_line_unchanged_p (struct window
*w
,
12815 ptrdiff_t start
, ptrdiff_t end
)
12817 int unchanged_p
= 1;
12819 /* If text or overlays have changed, see where. */
12820 if (window_outdated (w
))
12822 /* Gap in the line? */
12823 if (GPT
< start
|| Z
- GPT
< end
)
12826 /* Changes start in front of the line, or end after it? */
12828 && (BEG_UNCHANGED
< start
- 1
12829 || END_UNCHANGED
< end
))
12832 /* If selective display, can't optimize if changes start at the
12833 beginning of the line. */
12835 && INTEGERP (BVAR (current_buffer
, selective_display
))
12836 && XINT (BVAR (current_buffer
, selective_display
)) > 0
12837 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
12840 /* If there are overlays at the start or end of the line, these
12841 may have overlay strings with newlines in them. A change at
12842 START, for instance, may actually concern the display of such
12843 overlay strings as well, and they are displayed on different
12844 lines. So, quickly rule out this case. (For the future, it
12845 might be desirable to implement something more telling than
12846 just BEG/END_UNCHANGED.) */
12849 if (BEG
+ BEG_UNCHANGED
== start
12850 && overlay_touches_p (start
))
12852 if (END_UNCHANGED
== end
12853 && overlay_touches_p (Z
- end
))
12857 /* Under bidi reordering, adding or deleting a character in the
12858 beginning of a paragraph, before the first strong directional
12859 character, can change the base direction of the paragraph (unless
12860 the buffer specifies a fixed paragraph direction), which will
12861 require to redisplay the whole paragraph. It might be worthwhile
12862 to find the paragraph limits and widen the range of redisplayed
12863 lines to that, but for now just give up this optimization. */
12864 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
12865 && NILP (BVAR (XBUFFER (w
->contents
), bidi_paragraph_direction
)))
12869 return unchanged_p
;
12873 /* Do a frame update, taking possible shortcuts into account. This is
12874 the main external entry point for redisplay.
12876 If the last redisplay displayed an echo area message and that message
12877 is no longer requested, we clear the echo area or bring back the
12878 mini-buffer if that is in use. */
12883 redisplay_internal ();
12888 overlay_arrow_string_or_property (Lisp_Object var
)
12892 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
12895 return Voverlay_arrow_string
;
12898 /* Return 1 if there are any overlay-arrows in current_buffer. */
12900 overlay_arrow_in_current_buffer_p (void)
12904 for (vlist
= Voverlay_arrow_variable_list
;
12906 vlist
= XCDR (vlist
))
12908 Lisp_Object var
= XCAR (vlist
);
12911 if (!SYMBOLP (var
))
12913 val
= find_symbol_value (var
);
12915 && current_buffer
== XMARKER (val
)->buffer
)
12922 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
12926 overlay_arrows_changed_p (void)
12930 for (vlist
= Voverlay_arrow_variable_list
;
12932 vlist
= XCDR (vlist
))
12934 Lisp_Object var
= XCAR (vlist
);
12935 Lisp_Object val
, pstr
;
12937 if (!SYMBOLP (var
))
12939 val
= find_symbol_value (var
);
12940 if (!MARKERP (val
))
12942 if (! EQ (COERCE_MARKER (val
),
12943 Fget (var
, Qlast_arrow_position
))
12944 || ! (pstr
= overlay_arrow_string_or_property (var
),
12945 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
12951 /* Mark overlay arrows to be updated on next redisplay. */
12954 update_overlay_arrows (int up_to_date
)
12958 for (vlist
= Voverlay_arrow_variable_list
;
12960 vlist
= XCDR (vlist
))
12962 Lisp_Object var
= XCAR (vlist
);
12964 if (!SYMBOLP (var
))
12967 if (up_to_date
> 0)
12969 Lisp_Object val
= find_symbol_value (var
);
12970 Fput (var
, Qlast_arrow_position
,
12971 COERCE_MARKER (val
));
12972 Fput (var
, Qlast_arrow_string
,
12973 overlay_arrow_string_or_property (var
));
12975 else if (up_to_date
< 0
12976 || !NILP (Fget (var
, Qlast_arrow_position
)))
12978 Fput (var
, Qlast_arrow_position
, Qt
);
12979 Fput (var
, Qlast_arrow_string
, Qt
);
12985 /* Return overlay arrow string to display at row.
12986 Return integer (bitmap number) for arrow bitmap in left fringe.
12987 Return nil if no overlay arrow. */
12990 overlay_arrow_at_row (struct it
*it
, struct glyph_row
*row
)
12994 for (vlist
= Voverlay_arrow_variable_list
;
12996 vlist
= XCDR (vlist
))
12998 Lisp_Object var
= XCAR (vlist
);
13001 if (!SYMBOLP (var
))
13004 val
= find_symbol_value (var
);
13007 && current_buffer
== XMARKER (val
)->buffer
13008 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
13010 if (FRAME_WINDOW_P (it
->f
)
13011 /* FIXME: if ROW->reversed_p is set, this should test
13012 the right fringe, not the left one. */
13013 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
13015 #ifdef HAVE_WINDOW_SYSTEM
13016 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
13019 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
13020 return make_number (fringe_bitmap
);
13023 return make_number (-1); /* Use default arrow bitmap. */
13025 return overlay_arrow_string_or_property (var
);
13032 /* Return 1 if point moved out of or into a composition. Otherwise
13033 return 0. PREV_BUF and PREV_PT are the last point buffer and
13034 position. BUF and PT are the current point buffer and position. */
13037 check_point_in_composition (struct buffer
*prev_buf
, ptrdiff_t prev_pt
,
13038 struct buffer
*buf
, ptrdiff_t pt
)
13040 ptrdiff_t start
, end
;
13042 Lisp_Object buffer
;
13044 XSETBUFFER (buffer
, buf
);
13045 /* Check a composition at the last point if point moved within the
13047 if (prev_buf
== buf
)
13050 /* Point didn't move. */
13053 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
13054 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
13055 && composition_valid_p (start
, end
, prop
)
13056 && start
< prev_pt
&& end
> prev_pt
)
13057 /* The last point was within the composition. Return 1 iff
13058 point moved out of the composition. */
13059 return (pt
<= start
|| pt
>= end
);
13062 /* Check a composition at the current point. */
13063 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
13064 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
13065 && composition_valid_p (start
, end
, prop
)
13066 && start
< pt
&& end
> pt
);
13069 /* Reconsider the clip changes of buffer which is displayed in W. */
13072 reconsider_clip_changes (struct window
*w
)
13074 struct buffer
*b
= XBUFFER (w
->contents
);
13076 if (b
->clip_changed
13077 && w
->window_end_valid
13078 && w
->current_matrix
->buffer
== b
13079 && w
->current_matrix
->zv
== BUF_ZV (b
)
13080 && w
->current_matrix
->begv
== BUF_BEGV (b
))
13081 b
->clip_changed
= 0;
13083 /* If display wasn't paused, and W is not a tool bar window, see if
13084 point has been moved into or out of a composition. In that case,
13085 we set b->clip_changed to 1 to force updating the screen. If
13086 b->clip_changed has already been set to 1, we can skip this
13088 if (!b
->clip_changed
&& w
->window_end_valid
)
13090 ptrdiff_t pt
= (w
== XWINDOW (selected_window
)
13091 ? PT
: marker_position (w
->pointm
));
13093 if ((w
->current_matrix
->buffer
!= b
|| pt
!= w
->last_point
)
13094 && check_point_in_composition (w
->current_matrix
->buffer
,
13095 w
->last_point
, b
, pt
))
13096 b
->clip_changed
= 1;
13101 propagate_buffer_redisplay (void)
13102 { /* Resetting b->text->redisplay is problematic!
13103 We can't just reset it in the case that some window that displays
13104 it has not been redisplayed; and such a window can stay
13105 unredisplayed for a long time if it's currently invisible.
13106 But we do want to reset it at the end of redisplay otherwise
13107 its displayed windows will keep being redisplayed over and over
13109 So we copy all b->text->redisplay flags up to their windows here,
13110 such that mark_window_display_accurate can safely reset
13111 b->text->redisplay. */
13112 Lisp_Object ws
= window_list ();
13113 for (; CONSP (ws
); ws
= XCDR (ws
))
13115 struct window
*thisw
= XWINDOW (XCAR (ws
));
13116 struct buffer
*thisb
= XBUFFER (thisw
->contents
);
13117 if (thisb
->text
->redisplay
)
13118 thisw
->redisplay
= true;
13122 #define STOP_POLLING \
13123 do { if (! polling_stopped_here) stop_polling (); \
13124 polling_stopped_here = 1; } while (0)
13126 #define RESUME_POLLING \
13127 do { if (polling_stopped_here) start_polling (); \
13128 polling_stopped_here = 0; } while (0)
13131 /* Perhaps in the future avoid recentering windows if it
13132 is not necessary; currently that causes some problems. */
13135 redisplay_internal (void)
13137 struct window
*w
= XWINDOW (selected_window
);
13141 bool must_finish
= 0, match_p
;
13142 struct text_pos tlbufpos
, tlendpos
;
13143 int number_of_visible_frames
;
13146 int polling_stopped_here
= 0;
13147 Lisp_Object tail
, frame
;
13149 /* True means redisplay has to consider all windows on all
13150 frames. False, only selected_window is considered. */
13151 bool consider_all_windows_p
;
13153 /* True means redisplay has to redisplay the miniwindow. */
13154 bool update_miniwindow_p
= false;
13156 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
13158 /* No redisplay if running in batch mode or frame is not yet fully
13159 initialized, or redisplay is explicitly turned off by setting
13160 Vinhibit_redisplay. */
13161 if (FRAME_INITIAL_P (SELECTED_FRAME ())
13162 || !NILP (Vinhibit_redisplay
))
13165 /* Don't examine these until after testing Vinhibit_redisplay.
13166 When Emacs is shutting down, perhaps because its connection to
13167 X has dropped, we should not look at them at all. */
13168 fr
= XFRAME (w
->frame
);
13169 sf
= SELECTED_FRAME ();
13171 if (!fr
->glyphs_initialized_p
)
13174 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
13175 if (popup_activated ())
13179 /* I don't think this happens but let's be paranoid. */
13180 if (redisplaying_p
)
13183 /* Record a function that clears redisplaying_p
13184 when we leave this function. */
13185 count
= SPECPDL_INDEX ();
13186 record_unwind_protect_void (unwind_redisplay
);
13187 redisplaying_p
= 1;
13188 specbind (Qinhibit_free_realized_faces
, Qnil
);
13190 /* Record this function, so it appears on the profiler's backtraces. */
13191 record_in_backtrace (Qredisplay_internal
, &Qnil
, 0);
13193 FOR_EACH_FRAME (tail
, frame
)
13194 XFRAME (frame
)->already_hscrolled_p
= 0;
13197 /* Remember the currently selected window. */
13201 last_escape_glyph_frame
= NULL
;
13202 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
13203 last_glyphless_glyph_frame
= NULL
;
13204 last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
13206 /* If face_change_count is non-zero, init_iterator will free all
13207 realized faces, which includes the faces referenced from current
13208 matrices. So, we can't reuse current matrices in this case. */
13209 if (face_change_count
)
13210 windows_or_buffers_changed
= 47;
13212 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
13213 && FRAME_TTY (sf
)->previous_frame
!= sf
)
13215 /* Since frames on a single ASCII terminal share the same
13216 display area, displaying a different frame means redisplay
13217 the whole thing. */
13218 SET_FRAME_GARBAGED (sf
);
13220 set_tty_color_mode (FRAME_TTY (sf
), sf
);
13222 FRAME_TTY (sf
)->previous_frame
= sf
;
13225 /* Set the visible flags for all frames. Do this before checking for
13226 resized or garbaged frames; they want to know if their frames are
13227 visible. See the comment in frame.h for FRAME_SAMPLE_VISIBILITY. */
13228 number_of_visible_frames
= 0;
13230 FOR_EACH_FRAME (tail
, frame
)
13232 struct frame
*f
= XFRAME (frame
);
13234 if (FRAME_VISIBLE_P (f
))
13236 ++number_of_visible_frames
;
13237 /* Adjust matrices for visible frames only. */
13238 if (f
->fonts_changed
)
13240 adjust_frame_glyphs (f
);
13241 f
->fonts_changed
= 0;
13243 /* If cursor type has been changed on the frame
13244 other than selected, consider all frames. */
13245 if (f
!= sf
&& f
->cursor_type_changed
)
13246 update_mode_lines
= 31;
13248 clear_desired_matrices (f
);
13251 /* Notice any pending interrupt request to change frame size. */
13252 do_pending_window_change (1);
13254 /* do_pending_window_change could change the selected_window due to
13255 frame resizing which makes the selected window too small. */
13256 if (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
)
13259 /* Clear frames marked as garbaged. */
13260 clear_garbaged_frames ();
13262 /* Build menubar and tool-bar items. */
13263 if (NILP (Vmemory_full
))
13264 prepare_menu_bars ();
13266 reconsider_clip_changes (w
);
13268 /* In most cases selected window displays current buffer. */
13269 match_p
= XBUFFER (w
->contents
) == current_buffer
;
13272 /* Detect case that we need to write or remove a star in the mode line. */
13273 if ((SAVE_MODIFF
< MODIFF
) != w
->last_had_star
)
13274 w
->update_mode_line
= 1;
13276 if (mode_line_update_needed (w
))
13277 w
->update_mode_line
= 1;
13280 /* Normally the message* functions will have already displayed and
13281 updated the echo area, but the frame may have been trashed, or
13282 the update may have been preempted, so display the echo area
13283 again here. Checking message_cleared_p captures the case that
13284 the echo area should be cleared. */
13285 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
13286 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
13287 || (message_cleared_p
13288 && minibuf_level
== 0
13289 /* If the mini-window is currently selected, this means the
13290 echo-area doesn't show through. */
13291 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
13293 int window_height_changed_p
= echo_area_display (0);
13295 if (message_cleared_p
)
13296 update_miniwindow_p
= true;
13300 /* If we don't display the current message, don't clear the
13301 message_cleared_p flag, because, if we did, we wouldn't clear
13302 the echo area in the next redisplay which doesn't preserve
13304 if (!display_last_displayed_message_p
)
13305 message_cleared_p
= 0;
13307 if (window_height_changed_p
)
13309 windows_or_buffers_changed
= 50;
13311 /* If window configuration was changed, frames may have been
13312 marked garbaged. Clear them or we will experience
13313 surprises wrt scrolling. */
13314 clear_garbaged_frames ();
13317 else if (EQ (selected_window
, minibuf_window
)
13318 && (current_buffer
->clip_changed
|| window_outdated (w
))
13319 && resize_mini_window (w
, 0))
13321 /* Resized active mini-window to fit the size of what it is
13322 showing if its contents might have changed. */
13325 /* If window configuration was changed, frames may have been
13326 marked garbaged. Clear them or we will experience
13327 surprises wrt scrolling. */
13328 clear_garbaged_frames ();
13331 if (windows_or_buffers_changed
&& !update_mode_lines
)
13332 /* Code that sets windows_or_buffers_changed doesn't distinguish whether
13333 only the windows's contents needs to be refreshed, or whether the
13334 mode-lines also need a refresh. */
13335 update_mode_lines
= (windows_or_buffers_changed
== REDISPLAY_SOME
13336 ? REDISPLAY_SOME
: 32);
13338 /* If specs for an arrow have changed, do thorough redisplay
13339 to ensure we remove any arrow that should no longer exist. */
13340 if (overlay_arrows_changed_p ())
13341 /* Apparently, this is the only case where we update other windows,
13342 without updating other mode-lines. */
13343 windows_or_buffers_changed
= 49;
13345 consider_all_windows_p
= (update_mode_lines
13346 || windows_or_buffers_changed
);
13348 #define AINC(a,i) \
13349 if (VECTORP (a) && i >= 0 && i < ASIZE (a) && INTEGERP (AREF (a, i))) \
13350 ASET (a, i, make_number (1 + XINT (AREF (a, i))))
13352 AINC (Vredisplay__all_windows_cause
, windows_or_buffers_changed
);
13353 AINC (Vredisplay__mode_lines_cause
, update_mode_lines
);
13355 /* Optimize the case that only the line containing the cursor in the
13356 selected window has changed. Variables starting with this_ are
13357 set in display_line and record information about the line
13358 containing the cursor. */
13359 tlbufpos
= this_line_start_pos
;
13360 tlendpos
= this_line_end_pos
;
13361 if (!consider_all_windows_p
13362 && CHARPOS (tlbufpos
) > 0
13363 && !w
->update_mode_line
13364 && !current_buffer
->clip_changed
13365 && !current_buffer
->prevent_redisplay_optimizations_p
13366 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
13367 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
13368 && !XFRAME (w
->frame
)->cursor_type_changed
13369 /* Make sure recorded data applies to current buffer, etc. */
13370 && this_line_buffer
== current_buffer
13373 && !w
->optional_new_start
13374 /* Point must be on the line that we have info recorded about. */
13375 && PT
>= CHARPOS (tlbufpos
)
13376 && PT
<= Z
- CHARPOS (tlendpos
)
13377 /* All text outside that line, including its final newline,
13378 must be unchanged. */
13379 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
13380 CHARPOS (tlendpos
)))
13382 if (CHARPOS (tlbufpos
) > BEGV
13383 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
13384 && (CHARPOS (tlbufpos
) == ZV
13385 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
13386 /* Former continuation line has disappeared by becoming empty. */
13388 else if (window_outdated (w
) || MINI_WINDOW_P (w
))
13390 /* We have to handle the case of continuation around a
13391 wide-column character (see the comment in indent.c around
13394 For instance, in the following case:
13396 -------- Insert --------
13397 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
13398 J_I_ ==> J_I_ `^^' are cursors.
13402 As we have to redraw the line above, we cannot use this
13406 int line_height_before
= this_line_pixel_height
;
13408 /* Note that start_display will handle the case that the
13409 line starting at tlbufpos is a continuation line. */
13410 start_display (&it
, w
, tlbufpos
);
13412 /* Implementation note: It this still necessary? */
13413 if (it
.current_x
!= this_line_start_x
)
13416 TRACE ((stderr
, "trying display optimization 1\n"));
13417 w
->cursor
.vpos
= -1;
13418 overlay_arrow_seen
= 0;
13419 it
.vpos
= this_line_vpos
;
13420 it
.current_y
= this_line_y
;
13421 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
13422 display_line (&it
);
13424 /* If line contains point, is not continued,
13425 and ends at same distance from eob as before, we win. */
13426 if (w
->cursor
.vpos
>= 0
13427 /* Line is not continued, otherwise this_line_start_pos
13428 would have been set to 0 in display_line. */
13429 && CHARPOS (this_line_start_pos
)
13430 /* Line ends as before. */
13431 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
13432 /* Line has same height as before. Otherwise other lines
13433 would have to be shifted up or down. */
13434 && this_line_pixel_height
== line_height_before
)
13436 /* If this is not the window's last line, we must adjust
13437 the charstarts of the lines below. */
13438 if (it
.current_y
< it
.last_visible_y
)
13440 struct glyph_row
*row
13441 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
13442 ptrdiff_t delta
, delta_bytes
;
13444 /* We used to distinguish between two cases here,
13445 conditioned by Z - CHARPOS (tlendpos) == ZV, for
13446 when the line ends in a newline or the end of the
13447 buffer's accessible portion. But both cases did
13448 the same, so they were collapsed. */
13450 - CHARPOS (tlendpos
)
13451 - MATRIX_ROW_START_CHARPOS (row
));
13452 delta_bytes
= (Z_BYTE
13453 - BYTEPOS (tlendpos
)
13454 - MATRIX_ROW_START_BYTEPOS (row
));
13456 increment_matrix_positions (w
->current_matrix
,
13457 this_line_vpos
+ 1,
13458 w
->current_matrix
->nrows
,
13459 delta
, delta_bytes
);
13462 /* If this row displays text now but previously didn't,
13463 or vice versa, w->window_end_vpos may have to be
13465 if (MATRIX_ROW_DISPLAYS_TEXT_P (it
.glyph_row
- 1))
13467 if (w
->window_end_vpos
< this_line_vpos
)
13468 w
->window_end_vpos
= this_line_vpos
;
13470 else if (w
->window_end_vpos
== this_line_vpos
13471 && this_line_vpos
> 0)
13472 w
->window_end_vpos
= this_line_vpos
- 1;
13473 w
->window_end_valid
= 0;
13475 /* Update hint: No need to try to scroll in update_window. */
13476 w
->desired_matrix
->no_scrolling_p
= 1;
13479 *w
->desired_matrix
->method
= 0;
13480 debug_method_add (w
, "optimization 1");
13482 #ifdef HAVE_WINDOW_SYSTEM
13483 update_window_fringes (w
, 0);
13490 else if (/* Cursor position hasn't changed. */
13491 PT
== w
->last_point
13492 /* Make sure the cursor was last displayed
13493 in this window. Otherwise we have to reposition it. */
13495 /* PXW: Must be pixelized, probably. */
13496 && 0 <= w
->cursor
.vpos
13497 && w
->cursor
.vpos
< WINDOW_TOTAL_LINES (w
))
13501 do_pending_window_change (1);
13502 /* If selected_window changed, redisplay again. */
13503 if (WINDOWP (selected_window
)
13504 && (w
= XWINDOW (selected_window
)) != sw
)
13507 /* We used to always goto end_of_redisplay here, but this
13508 isn't enough if we have a blinking cursor. */
13509 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
13510 goto end_of_redisplay
;
13514 /* If highlighting the region, or if the cursor is in the echo area,
13515 then we can't just move the cursor. */
13516 else if (NILP (Vshow_trailing_whitespace
)
13517 && !cursor_in_echo_area
)
13520 struct glyph_row
*row
;
13522 /* Skip from tlbufpos to PT and see where it is. Note that
13523 PT may be in invisible text. If so, we will end at the
13524 next visible position. */
13525 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
13526 NULL
, DEFAULT_FACE_ID
);
13527 it
.current_x
= this_line_start_x
;
13528 it
.current_y
= this_line_y
;
13529 it
.vpos
= this_line_vpos
;
13531 /* The call to move_it_to stops in front of PT, but
13532 moves over before-strings. */
13533 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
13535 if (it
.vpos
== this_line_vpos
13536 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
13539 eassert (this_line_vpos
== it
.vpos
);
13540 eassert (this_line_y
== it
.current_y
);
13541 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13543 *w
->desired_matrix
->method
= 0;
13544 debug_method_add (w
, "optimization 3");
13553 /* Text changed drastically or point moved off of line. */
13554 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
13557 CHARPOS (this_line_start_pos
) = 0;
13558 ++clear_face_cache_count
;
13559 #ifdef HAVE_WINDOW_SYSTEM
13560 ++clear_image_cache_count
;
13563 /* Build desired matrices, and update the display. If
13564 consider_all_windows_p is non-zero, do it for all windows on all
13565 frames. Otherwise do it for selected_window, only. */
13567 if (consider_all_windows_p
)
13569 FOR_EACH_FRAME (tail
, frame
)
13570 XFRAME (frame
)->updated_p
= 0;
13572 propagate_buffer_redisplay ();
13574 FOR_EACH_FRAME (tail
, frame
)
13576 struct frame
*f
= XFRAME (frame
);
13578 /* We don't have to do anything for unselected terminal
13580 if ((FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
13581 && !EQ (FRAME_TTY (f
)->top_frame
, frame
))
13586 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
13589 /* Only GC scollbars when we redisplay the whole frame. */
13590 = f
->redisplay
|| !REDISPLAY_SOME_P ();
13591 /* Mark all the scroll bars to be removed; we'll redeem
13592 the ones we want when we redisplay their windows. */
13593 if (gcscrollbars
&& FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
13594 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
13596 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13597 redisplay_windows (FRAME_ROOT_WINDOW (f
));
13598 /* Remember that the invisible frames need to be redisplayed next
13599 time they're visible. */
13600 else if (!REDISPLAY_SOME_P ())
13601 f
->redisplay
= true;
13603 /* The X error handler may have deleted that frame. */
13604 if (!FRAME_LIVE_P (f
))
13607 /* Any scroll bars which redisplay_windows should have
13608 nuked should now go away. */
13609 if (gcscrollbars
&& FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
13610 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
13612 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13614 /* If fonts changed on visible frame, display again. */
13615 if (f
->fonts_changed
)
13617 adjust_frame_glyphs (f
);
13618 f
->fonts_changed
= 0;
13622 /* See if we have to hscroll. */
13623 if (!f
->already_hscrolled_p
)
13625 f
->already_hscrolled_p
= 1;
13626 if (hscroll_windows (f
->root_window
))
13630 /* Prevent various kinds of signals during display
13631 update. stdio is not robust about handling
13632 signals, which can cause an apparent I/O error. */
13633 if (interrupt_input
)
13634 unrequest_sigio ();
13637 pending
|= update_frame (f
, 0, 0);
13638 f
->cursor_type_changed
= 0;
13644 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
13648 /* Do the mark_window_display_accurate after all windows have
13649 been redisplayed because this call resets flags in buffers
13650 which are needed for proper redisplay. */
13651 FOR_EACH_FRAME (tail
, frame
)
13653 struct frame
*f
= XFRAME (frame
);
13656 f
->redisplay
= false;
13657 mark_window_display_accurate (f
->root_window
, 1);
13658 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
13659 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
13664 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13666 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13667 struct frame
*mini_frame
;
13669 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->contents
);
13670 /* Use list_of_error, not Qerror, so that
13671 we catch only errors and don't run the debugger. */
13672 internal_condition_case_1 (redisplay_window_1
, selected_window
,
13674 redisplay_window_error
);
13675 if (update_miniwindow_p
)
13676 internal_condition_case_1 (redisplay_window_1
, mini_window
,
13678 redisplay_window_error
);
13680 /* Compare desired and current matrices, perform output. */
13683 /* If fonts changed, display again. */
13684 if (sf
->fonts_changed
)
13687 /* Prevent various kinds of signals during display update.
13688 stdio is not robust about handling signals,
13689 which can cause an apparent I/O error. */
13690 if (interrupt_input
)
13691 unrequest_sigio ();
13694 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13696 if (hscroll_windows (selected_window
))
13699 XWINDOW (selected_window
)->must_be_updated_p
= true;
13700 pending
= update_frame (sf
, 0, 0);
13701 sf
->cursor_type_changed
= 0;
13704 /* We may have called echo_area_display at the top of this
13705 function. If the echo area is on another frame, that may
13706 have put text on a frame other than the selected one, so the
13707 above call to update_frame would not have caught it. Catch
13709 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13710 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
13712 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
13714 XWINDOW (mini_window
)->must_be_updated_p
= true;
13715 pending
|= update_frame (mini_frame
, 0, 0);
13716 mini_frame
->cursor_type_changed
= 0;
13717 if (!pending
&& hscroll_windows (mini_window
))
13722 /* If display was paused because of pending input, make sure we do a
13723 thorough update the next time. */
13726 /* Prevent the optimization at the beginning of
13727 redisplay_internal that tries a single-line update of the
13728 line containing the cursor in the selected window. */
13729 CHARPOS (this_line_start_pos
) = 0;
13731 /* Let the overlay arrow be updated the next time. */
13732 update_overlay_arrows (0);
13734 /* If we pause after scrolling, some rows in the current
13735 matrices of some windows are not valid. */
13736 if (!WINDOW_FULL_WIDTH_P (w
)
13737 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
13738 update_mode_lines
= 36;
13742 if (!consider_all_windows_p
)
13744 /* This has already been done above if
13745 consider_all_windows_p is set. */
13746 if (XBUFFER (w
->contents
)->text
->redisplay
13747 && buffer_window_count (XBUFFER (w
->contents
)) > 1)
13748 /* This can happen if b->text->redisplay was set during
13750 propagate_buffer_redisplay ();
13751 mark_window_display_accurate_1 (w
, 1);
13753 /* Say overlay arrows are up to date. */
13754 update_overlay_arrows (1);
13756 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
13757 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
13760 update_mode_lines
= 0;
13761 windows_or_buffers_changed
= 0;
13764 /* Start SIGIO interrupts coming again. Having them off during the
13765 code above makes it less likely one will discard output, but not
13766 impossible, since there might be stuff in the system buffer here.
13767 But it is much hairier to try to do anything about that. */
13768 if (interrupt_input
)
13772 /* If a frame has become visible which was not before, redisplay
13773 again, so that we display it. Expose events for such a frame
13774 (which it gets when becoming visible) don't call the parts of
13775 redisplay constructing glyphs, so simply exposing a frame won't
13776 display anything in this case. So, we have to display these
13777 frames here explicitly. */
13782 FOR_EACH_FRAME (tail
, frame
)
13784 if (XFRAME (frame
)->visible
)
13788 if (new_count
!= number_of_visible_frames
)
13789 windows_or_buffers_changed
= 52;
13792 /* Change frame size now if a change is pending. */
13793 do_pending_window_change (1);
13795 /* If we just did a pending size change, or have additional
13796 visible frames, or selected_window changed, redisplay again. */
13797 if ((windows_or_buffers_changed
&& !pending
)
13798 || (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
))
13801 /* Clear the face and image caches.
13803 We used to do this only if consider_all_windows_p. But the cache
13804 needs to be cleared if a timer creates images in the current
13805 buffer (e.g. the test case in Bug#6230). */
13807 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
13809 clear_face_cache (0);
13810 clear_face_cache_count
= 0;
13813 #ifdef HAVE_WINDOW_SYSTEM
13814 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
13816 clear_image_caches (Qnil
);
13817 clear_image_cache_count
= 0;
13819 #endif /* HAVE_WINDOW_SYSTEM */
13822 unbind_to (count
, Qnil
);
13827 /* Redisplay, but leave alone any recent echo area message unless
13828 another message has been requested in its place.
13830 This is useful in situations where you need to redisplay but no
13831 user action has occurred, making it inappropriate for the message
13832 area to be cleared. See tracking_off and
13833 wait_reading_process_output for examples of these situations.
13835 FROM_WHERE is an integer saying from where this function was
13836 called. This is useful for debugging. */
13839 redisplay_preserve_echo_area (int from_where
)
13841 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
13843 if (!NILP (echo_area_buffer
[1]))
13845 /* We have a previously displayed message, but no current
13846 message. Redisplay the previous message. */
13847 display_last_displayed_message_p
= 1;
13848 redisplay_internal ();
13849 display_last_displayed_message_p
= 0;
13852 redisplay_internal ();
13854 flush_frame (SELECTED_FRAME ());
13858 /* Function registered with record_unwind_protect in redisplay_internal. */
13861 unwind_redisplay (void)
13863 redisplaying_p
= 0;
13867 /* Mark the display of leaf window W as accurate or inaccurate.
13868 If ACCURATE_P is non-zero mark display of W as accurate. If
13869 ACCURATE_P is zero, arrange for W to be redisplayed the next
13870 time redisplay_internal is called. */
13873 mark_window_display_accurate_1 (struct window
*w
, int accurate_p
)
13875 struct buffer
*b
= XBUFFER (w
->contents
);
13877 w
->last_modified
= accurate_p
? BUF_MODIFF (b
) : 0;
13878 w
->last_overlay_modified
= accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0;
13879 w
->last_had_star
= BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
);
13883 b
->clip_changed
= false;
13884 b
->prevent_redisplay_optimizations_p
= false;
13885 eassert (buffer_window_count (b
) > 0);
13886 /* Resetting b->text->redisplay is problematic!
13887 In order to make it safer to do it here, redisplay_internal must
13888 have copied all b->text->redisplay to their respective windows. */
13889 b
->text
->redisplay
= false;
13891 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
13892 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
13893 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
13894 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
13896 w
->current_matrix
->buffer
= b
;
13897 w
->current_matrix
->begv
= BUF_BEGV (b
);
13898 w
->current_matrix
->zv
= BUF_ZV (b
);
13900 w
->last_cursor_vpos
= w
->cursor
.vpos
;
13901 w
->last_cursor_off_p
= w
->cursor_off_p
;
13903 if (w
== XWINDOW (selected_window
))
13904 w
->last_point
= BUF_PT (b
);
13906 w
->last_point
= marker_position (w
->pointm
);
13908 w
->window_end_valid
= true;
13909 w
->update_mode_line
= false;
13912 w
->redisplay
= !accurate_p
;
13916 /* Mark the display of windows in the window tree rooted at WINDOW as
13917 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
13918 windows as accurate. If ACCURATE_P is zero, arrange for windows to
13919 be redisplayed the next time redisplay_internal is called. */
13922 mark_window_display_accurate (Lisp_Object window
, int accurate_p
)
13926 for (; !NILP (window
); window
= w
->next
)
13928 w
= XWINDOW (window
);
13929 if (WINDOWP (w
->contents
))
13930 mark_window_display_accurate (w
->contents
, accurate_p
);
13932 mark_window_display_accurate_1 (w
, accurate_p
);
13936 update_overlay_arrows (1);
13938 /* Force a thorough redisplay the next time by setting
13939 last_arrow_position and last_arrow_string to t, which is
13940 unequal to any useful value of Voverlay_arrow_... */
13941 update_overlay_arrows (-1);
13945 /* Return value in display table DP (Lisp_Char_Table *) for character
13946 C. Since a display table doesn't have any parent, we don't have to
13947 follow parent. Do not call this function directly but use the
13948 macro DISP_CHAR_VECTOR. */
13951 disp_char_vector (struct Lisp_Char_Table
*dp
, int c
)
13955 if (ASCII_CHAR_P (c
))
13958 if (SUB_CHAR_TABLE_P (val
))
13959 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
13965 XSETCHAR_TABLE (table
, dp
);
13966 val
= char_table_ref (table
, c
);
13975 /***********************************************************************
13977 ***********************************************************************/
13979 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
13982 redisplay_windows (Lisp_Object window
)
13984 while (!NILP (window
))
13986 struct window
*w
= XWINDOW (window
);
13988 if (WINDOWP (w
->contents
))
13989 redisplay_windows (w
->contents
);
13990 else if (BUFFERP (w
->contents
))
13992 displayed_buffer
= XBUFFER (w
->contents
);
13993 /* Use list_of_error, not Qerror, so that
13994 we catch only errors and don't run the debugger. */
13995 internal_condition_case_1 (redisplay_window_0
, window
,
13997 redisplay_window_error
);
14005 redisplay_window_error (Lisp_Object ignore
)
14007 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
14012 redisplay_window_0 (Lisp_Object window
)
14014 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
14015 redisplay_window (window
, false);
14020 redisplay_window_1 (Lisp_Object window
)
14022 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
14023 redisplay_window (window
, true);
14028 /* Set cursor position of W. PT is assumed to be displayed in ROW.
14029 DELTA and DELTA_BYTES are the numbers of characters and bytes by
14030 which positions recorded in ROW differ from current buffer
14033 Return 0 if cursor is not on this row, 1 otherwise. */
14036 set_cursor_from_row (struct window
*w
, struct glyph_row
*row
,
14037 struct glyph_matrix
*matrix
,
14038 ptrdiff_t delta
, ptrdiff_t delta_bytes
,
14041 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
14042 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
14043 struct glyph
*cursor
= NULL
;
14044 /* The last known character position in row. */
14045 ptrdiff_t last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
14047 ptrdiff_t pt_old
= PT
- delta
;
14048 ptrdiff_t pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
14049 ptrdiff_t pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
14050 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
14051 /* A glyph beyond the edge of TEXT_AREA which we should never
14053 struct glyph
*glyphs_end
= end
;
14054 /* Non-zero means we've found a match for cursor position, but that
14055 glyph has the avoid_cursor_p flag set. */
14056 int match_with_avoid_cursor
= 0;
14057 /* Non-zero means we've seen at least one glyph that came from a
14059 int string_seen
= 0;
14060 /* Largest and smallest buffer positions seen so far during scan of
14062 ptrdiff_t bpos_max
= pos_before
;
14063 ptrdiff_t bpos_min
= pos_after
;
14064 /* Last buffer position covered by an overlay string with an integer
14065 `cursor' property. */
14066 ptrdiff_t bpos_covered
= 0;
14067 /* Non-zero means the display string on which to display the cursor
14068 comes from a text property, not from an overlay. */
14069 int string_from_text_prop
= 0;
14071 /* Don't even try doing anything if called for a mode-line or
14072 header-line row, since the rest of the code isn't prepared to
14073 deal with such calamities. */
14074 eassert (!row
->mode_line_p
);
14075 if (row
->mode_line_p
)
14078 /* Skip over glyphs not having an object at the start and the end of
14079 the row. These are special glyphs like truncation marks on
14080 terminal frames. */
14081 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14083 if (!row
->reversed_p
)
14086 && INTEGERP (glyph
->object
)
14087 && glyph
->charpos
< 0)
14089 x
+= glyph
->pixel_width
;
14093 && INTEGERP ((end
- 1)->object
)
14094 /* CHARPOS is zero for blanks and stretch glyphs
14095 inserted by extend_face_to_end_of_line. */
14096 && (end
- 1)->charpos
<= 0)
14098 glyph_before
= glyph
- 1;
14105 /* If the glyph row is reversed, we need to process it from back
14106 to front, so swap the edge pointers. */
14107 glyphs_end
= end
= glyph
- 1;
14108 glyph
+= row
->used
[TEXT_AREA
] - 1;
14110 while (glyph
> end
+ 1
14111 && INTEGERP (glyph
->object
)
14112 && glyph
->charpos
< 0)
14115 x
-= glyph
->pixel_width
;
14117 if (INTEGERP (glyph
->object
) && glyph
->charpos
< 0)
14119 /* By default, in reversed rows we put the cursor on the
14120 rightmost (first in the reading order) glyph. */
14121 for (g
= end
+ 1; g
< glyph
; g
++)
14122 x
+= g
->pixel_width
;
14124 && INTEGERP ((end
+ 1)->object
)
14125 && (end
+ 1)->charpos
<= 0)
14127 glyph_before
= glyph
+ 1;
14131 else if (row
->reversed_p
)
14133 /* In R2L rows that don't display text, put the cursor on the
14134 rightmost glyph. Case in point: an empty last line that is
14135 part of an R2L paragraph. */
14137 /* Avoid placing the cursor on the last glyph of the row, where
14138 on terminal frames we hold the vertical border between
14139 adjacent windows. */
14140 if (!FRAME_WINDOW_P (WINDOW_XFRAME (w
))
14141 && !WINDOW_RIGHTMOST_P (w
)
14142 && cursor
== row
->glyphs
[LAST_AREA
] - 1)
14144 x
= -1; /* will be computed below, at label compute_x */
14147 /* Step 1: Try to find the glyph whose character position
14148 corresponds to point. If that's not possible, find 2 glyphs
14149 whose character positions are the closest to point, one before
14150 point, the other after it. */
14151 if (!row
->reversed_p
)
14152 while (/* not marched to end of glyph row */
14154 /* glyph was not inserted by redisplay for internal purposes */
14155 && !INTEGERP (glyph
->object
))
14157 if (BUFFERP (glyph
->object
))
14159 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
14161 if (glyph
->charpos
> bpos_max
)
14162 bpos_max
= glyph
->charpos
;
14163 if (glyph
->charpos
< bpos_min
)
14164 bpos_min
= glyph
->charpos
;
14165 if (!glyph
->avoid_cursor_p
)
14167 /* If we hit point, we've found the glyph on which to
14168 display the cursor. */
14171 match_with_avoid_cursor
= 0;
14174 /* See if we've found a better approximation to
14175 POS_BEFORE or to POS_AFTER. */
14176 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
14178 pos_before
= glyph
->charpos
;
14179 glyph_before
= glyph
;
14181 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
14183 pos_after
= glyph
->charpos
;
14184 glyph_after
= glyph
;
14187 else if (dpos
== 0)
14188 match_with_avoid_cursor
= 1;
14190 else if (STRINGP (glyph
->object
))
14192 Lisp_Object chprop
;
14193 ptrdiff_t glyph_pos
= glyph
->charpos
;
14195 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
14197 if (!NILP (chprop
))
14199 /* If the string came from a `display' text property,
14200 look up the buffer position of that property and
14201 use that position to update bpos_max, as if we
14202 actually saw such a position in one of the row's
14203 glyphs. This helps with supporting integer values
14204 of `cursor' property on the display string in
14205 situations where most or all of the row's buffer
14206 text is completely covered by display properties,
14207 so that no glyph with valid buffer positions is
14208 ever seen in the row. */
14209 ptrdiff_t prop_pos
=
14210 string_buffer_position_lim (glyph
->object
, pos_before
,
14213 if (prop_pos
>= pos_before
)
14214 bpos_max
= prop_pos
- 1;
14216 if (INTEGERP (chprop
))
14218 bpos_covered
= bpos_max
+ XINT (chprop
);
14219 /* If the `cursor' property covers buffer positions up
14220 to and including point, we should display cursor on
14221 this glyph. Note that, if a `cursor' property on one
14222 of the string's characters has an integer value, we
14223 will break out of the loop below _before_ we get to
14224 the position match above. IOW, integer values of
14225 the `cursor' property override the "exact match for
14226 point" strategy of positioning the cursor. */
14227 /* Implementation note: bpos_max == pt_old when, e.g.,
14228 we are in an empty line, where bpos_max is set to
14229 MATRIX_ROW_START_CHARPOS, see above. */
14230 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14239 x
+= glyph
->pixel_width
;
14242 else if (glyph
> end
) /* row is reversed */
14243 while (!INTEGERP (glyph
->object
))
14245 if (BUFFERP (glyph
->object
))
14247 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
14249 if (glyph
->charpos
> bpos_max
)
14250 bpos_max
= glyph
->charpos
;
14251 if (glyph
->charpos
< bpos_min
)
14252 bpos_min
= glyph
->charpos
;
14253 if (!glyph
->avoid_cursor_p
)
14257 match_with_avoid_cursor
= 0;
14260 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
14262 pos_before
= glyph
->charpos
;
14263 glyph_before
= glyph
;
14265 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
14267 pos_after
= glyph
->charpos
;
14268 glyph_after
= glyph
;
14271 else if (dpos
== 0)
14272 match_with_avoid_cursor
= 1;
14274 else if (STRINGP (glyph
->object
))
14276 Lisp_Object chprop
;
14277 ptrdiff_t glyph_pos
= glyph
->charpos
;
14279 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
14281 if (!NILP (chprop
))
14283 ptrdiff_t prop_pos
=
14284 string_buffer_position_lim (glyph
->object
, pos_before
,
14287 if (prop_pos
>= pos_before
)
14288 bpos_max
= prop_pos
- 1;
14290 if (INTEGERP (chprop
))
14292 bpos_covered
= bpos_max
+ XINT (chprop
);
14293 /* If the `cursor' property covers buffer positions up
14294 to and including point, we should display cursor on
14296 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14305 if (glyph
== glyphs_end
) /* don't dereference outside TEXT_AREA */
14307 x
--; /* can't use any pixel_width */
14310 x
-= glyph
->pixel_width
;
14313 /* Step 2: If we didn't find an exact match for point, we need to
14314 look for a proper place to put the cursor among glyphs between
14315 GLYPH_BEFORE and GLYPH_AFTER. */
14316 if (!((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14317 && BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14318 && !(bpos_max
< pt_old
&& pt_old
<= bpos_covered
))
14320 /* An empty line has a single glyph whose OBJECT is zero and
14321 whose CHARPOS is the position of a newline on that line.
14322 Note that on a TTY, there are more glyphs after that, which
14323 were produced by extend_face_to_end_of_line, but their
14324 CHARPOS is zero or negative. */
14326 (row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14327 && INTEGERP (glyph
->object
) && glyph
->charpos
> 0
14328 /* On a TTY, continued and truncated rows also have a glyph at
14329 their end whose OBJECT is zero and whose CHARPOS is
14330 positive (the continuation and truncation glyphs), but such
14331 rows are obviously not "empty". */
14332 && !(row
->continued_p
|| row
->truncated_on_right_p
);
14334 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
14336 ptrdiff_t ellipsis_pos
;
14338 /* Scan back over the ellipsis glyphs. */
14339 if (!row
->reversed_p
)
14341 ellipsis_pos
= (glyph
- 1)->charpos
;
14342 while (glyph
> row
->glyphs
[TEXT_AREA
]
14343 && (glyph
- 1)->charpos
== ellipsis_pos
)
14344 glyph
--, x
-= glyph
->pixel_width
;
14345 /* That loop always goes one position too far, including
14346 the glyph before the ellipsis. So scan forward over
14348 x
+= glyph
->pixel_width
;
14351 else /* row is reversed */
14353 ellipsis_pos
= (glyph
+ 1)->charpos
;
14354 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14355 && (glyph
+ 1)->charpos
== ellipsis_pos
)
14356 glyph
++, x
+= glyph
->pixel_width
;
14357 x
-= glyph
->pixel_width
;
14361 else if (match_with_avoid_cursor
)
14363 cursor
= glyph_after
;
14366 else if (string_seen
)
14368 int incr
= row
->reversed_p
? -1 : +1;
14370 /* Need to find the glyph that came out of a string which is
14371 present at point. That glyph is somewhere between
14372 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
14373 positioned between POS_BEFORE and POS_AFTER in the
14375 struct glyph
*start
, *stop
;
14376 ptrdiff_t pos
= pos_before
;
14380 /* If the row ends in a newline from a display string,
14381 reordering could have moved the glyphs belonging to the
14382 string out of the [GLYPH_BEFORE..GLYPH_AFTER] range. So
14383 in this case we extend the search to the last glyph in
14384 the row that was not inserted by redisplay. */
14385 if (row
->ends_in_newline_from_string_p
)
14388 pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
14391 /* GLYPH_BEFORE and GLYPH_AFTER are the glyphs that
14392 correspond to POS_BEFORE and POS_AFTER, respectively. We
14393 need START and STOP in the order that corresponds to the
14394 row's direction as given by its reversed_p flag. If the
14395 directionality of characters between POS_BEFORE and
14396 POS_AFTER is the opposite of the row's base direction,
14397 these characters will have been reordered for display,
14398 and we need to reverse START and STOP. */
14399 if (!row
->reversed_p
)
14401 start
= min (glyph_before
, glyph_after
);
14402 stop
= max (glyph_before
, glyph_after
);
14406 start
= max (glyph_before
, glyph_after
);
14407 stop
= min (glyph_before
, glyph_after
);
14409 for (glyph
= start
+ incr
;
14410 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
14413 /* Any glyphs that come from the buffer are here because
14414 of bidi reordering. Skip them, and only pay
14415 attention to glyphs that came from some string. */
14416 if (STRINGP (glyph
->object
))
14420 /* If the display property covers the newline, we
14421 need to search for it one position farther. */
14422 ptrdiff_t lim
= pos_after
14423 + (pos_after
== MATRIX_ROW_END_CHARPOS (row
) + delta
);
14425 string_from_text_prop
= 0;
14426 str
= glyph
->object
;
14427 tem
= string_buffer_position_lim (str
, pos
, lim
, 0);
14428 if (tem
== 0 /* from overlay */
14431 /* If the string from which this glyph came is
14432 found in the buffer at point, or at position
14433 that is closer to point than pos_after, then
14434 we've found the glyph we've been looking for.
14435 If it comes from an overlay (tem == 0), and
14436 it has the `cursor' property on one of its
14437 glyphs, record that glyph as a candidate for
14438 displaying the cursor. (As in the
14439 unidirectional version, we will display the
14440 cursor on the last candidate we find.) */
14443 || (tem
- pt_old
> 0 && tem
< pos_after
))
14445 /* The glyphs from this string could have
14446 been reordered. Find the one with the
14447 smallest string position. Or there could
14448 be a character in the string with the
14449 `cursor' property, which means display
14450 cursor on that character's glyph. */
14451 ptrdiff_t strpos
= glyph
->charpos
;
14456 string_from_text_prop
= 1;
14459 (row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14460 && EQ (glyph
->object
, str
);
14464 ptrdiff_t gpos
= glyph
->charpos
;
14466 cprop
= Fget_char_property (make_number (gpos
),
14474 if (tem
&& glyph
->charpos
< strpos
)
14476 strpos
= glyph
->charpos
;
14482 || (tem
- pt_old
> 0 && tem
< pos_after
))
14486 pos
= tem
+ 1; /* don't find previous instances */
14488 /* This string is not what we want; skip all of the
14489 glyphs that came from it. */
14490 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14491 && EQ (glyph
->object
, str
))
14498 /* If we reached the end of the line, and END was from a string,
14499 the cursor is not on this line. */
14501 && (row
->reversed_p
? glyph
<= end
: glyph
>= end
)
14502 && (row
->reversed_p
? end
> glyphs_end
: end
< glyphs_end
)
14503 && STRINGP (end
->object
)
14504 && row
->continued_p
)
14507 /* A truncated row may not include PT among its character positions.
14508 Setting the cursor inside the scroll margin will trigger
14509 recalculation of hscroll in hscroll_window_tree. But if a
14510 display string covers point, defer to the string-handling
14511 code below to figure this out. */
14512 else if (row
->truncated_on_left_p
&& pt_old
< bpos_min
)
14514 cursor
= glyph_before
;
14517 else if ((row
->truncated_on_right_p
&& pt_old
> bpos_max
)
14518 /* Zero-width characters produce no glyphs. */
14520 && (row
->reversed_p
14521 ? glyph_after
> glyphs_end
14522 : glyph_after
< glyphs_end
)))
14524 cursor
= glyph_after
;
14530 if (cursor
!= NULL
)
14532 else if (glyph
== glyphs_end
14533 && pos_before
== pos_after
14534 && STRINGP ((row
->reversed_p
14535 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14536 : row
->glyphs
[TEXT_AREA
])->object
))
14538 /* If all the glyphs of this row came from strings, put the
14539 cursor on the first glyph of the row. This avoids having the
14540 cursor outside of the text area in this very rare and hard
14544 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14545 : row
->glyphs
[TEXT_AREA
];
14551 /* Need to compute x that corresponds to GLYPH. */
14552 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
14554 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
14556 x
+= g
->pixel_width
;
14560 /* ROW could be part of a continued line, which, under bidi
14561 reordering, might have other rows whose start and end charpos
14562 occlude point. Only set w->cursor if we found a better
14563 approximation to the cursor position than we have from previously
14564 examined candidate rows belonging to the same continued line. */
14565 if (/* We already have a candidate row. */
14566 w
->cursor
.vpos
>= 0
14567 /* That candidate is not the row we are processing. */
14568 && MATRIX_ROW (matrix
, w
->cursor
.vpos
) != row
14569 /* Make sure cursor.vpos specifies a row whose start and end
14570 charpos occlude point, and it is valid candidate for being a
14571 cursor-row. This is because some callers of this function
14572 leave cursor.vpos at the row where the cursor was displayed
14573 during the last redisplay cycle. */
14574 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)) <= pt_old
14575 && pt_old
<= MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14576 && cursor_row_p (MATRIX_ROW (matrix
, w
->cursor
.vpos
)))
14579 = MATRIX_ROW_GLYPH_START (matrix
, w
->cursor
.vpos
) + w
->cursor
.hpos
;
14581 /* Don't consider glyphs that are outside TEXT_AREA. */
14582 if (!(row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
))
14584 /* Keep the candidate whose buffer position is the closest to
14585 point or has the `cursor' property. */
14586 if (/* Previous candidate is a glyph in TEXT_AREA of that row. */
14587 w
->cursor
.hpos
>= 0
14588 && w
->cursor
.hpos
< MATRIX_ROW_USED (matrix
, w
->cursor
.vpos
)
14589 && ((BUFFERP (g1
->object
)
14590 && (g1
->charpos
== pt_old
/* An exact match always wins. */
14591 || (BUFFERP (glyph
->object
)
14592 && eabs (g1
->charpos
- pt_old
)
14593 < eabs (glyph
->charpos
- pt_old
))))
14594 /* Previous candidate is a glyph from a string that has
14595 a non-nil `cursor' property. */
14596 || (STRINGP (g1
->object
)
14597 && (!NILP (Fget_char_property (make_number (g1
->charpos
),
14598 Qcursor
, g1
->object
))
14599 /* Previous candidate is from the same display
14600 string as this one, and the display string
14601 came from a text property. */
14602 || (EQ (g1
->object
, glyph
->object
)
14603 && string_from_text_prop
)
14604 /* this candidate is from newline and its
14605 position is not an exact match */
14606 || (INTEGERP (glyph
->object
)
14607 && glyph
->charpos
!= pt_old
)))))
14609 /* If this candidate gives an exact match, use that. */
14610 if (!((BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14611 /* If this candidate is a glyph created for the
14612 terminating newline of a line, and point is on that
14613 newline, it wins because it's an exact match. */
14614 || (!row
->continued_p
14615 && INTEGERP (glyph
->object
)
14616 && glyph
->charpos
== 0
14617 && pt_old
== MATRIX_ROW_END_CHARPOS (row
) - 1))
14618 /* Otherwise, keep the candidate that comes from a row
14619 spanning less buffer positions. This may win when one or
14620 both candidate positions are on glyphs that came from
14621 display strings, for which we cannot compare buffer
14623 && MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14624 - MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14625 < MATRIX_ROW_END_CHARPOS (row
) - MATRIX_ROW_START_CHARPOS (row
))
14628 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
14630 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
14631 w
->cursor
.y
= row
->y
+ dy
;
14633 if (w
== XWINDOW (selected_window
))
14635 if (!row
->continued_p
14636 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
14639 this_line_buffer
= XBUFFER (w
->contents
);
14641 CHARPOS (this_line_start_pos
)
14642 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
14643 BYTEPOS (this_line_start_pos
)
14644 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
14646 CHARPOS (this_line_end_pos
)
14647 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
14648 BYTEPOS (this_line_end_pos
)
14649 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
14651 this_line_y
= w
->cursor
.y
;
14652 this_line_pixel_height
= row
->height
;
14653 this_line_vpos
= w
->cursor
.vpos
;
14654 this_line_start_x
= row
->x
;
14657 CHARPOS (this_line_start_pos
) = 0;
14664 /* Run window scroll functions, if any, for WINDOW with new window
14665 start STARTP. Sets the window start of WINDOW to that position.
14667 We assume that the window's buffer is really current. */
14669 static struct text_pos
14670 run_window_scroll_functions (Lisp_Object window
, struct text_pos startp
)
14672 struct window
*w
= XWINDOW (window
);
14673 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
14675 eassert (current_buffer
== XBUFFER (w
->contents
));
14677 if (!NILP (Vwindow_scroll_functions
))
14679 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
14680 make_number (CHARPOS (startp
)));
14681 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14682 /* In case the hook functions switch buffers. */
14683 set_buffer_internal (XBUFFER (w
->contents
));
14690 /* Make sure the line containing the cursor is fully visible.
14691 A value of 1 means there is nothing to be done.
14692 (Either the line is fully visible, or it cannot be made so,
14693 or we cannot tell.)
14695 If FORCE_P is non-zero, return 0 even if partial visible cursor row
14696 is higher than window.
14698 A value of 0 means the caller should do scrolling
14699 as if point had gone off the screen. */
14702 cursor_row_fully_visible_p (struct window
*w
, int force_p
, int current_matrix_p
)
14704 struct glyph_matrix
*matrix
;
14705 struct glyph_row
*row
;
14708 if (!make_cursor_line_fully_visible_p
)
14711 /* It's not always possible to find the cursor, e.g, when a window
14712 is full of overlay strings. Don't do anything in that case. */
14713 if (w
->cursor
.vpos
< 0)
14716 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
14717 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
14719 /* If the cursor row is not partially visible, there's nothing to do. */
14720 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
14723 /* If the row the cursor is in is taller than the window's height,
14724 it's not clear what to do, so do nothing. */
14725 window_height
= window_box_height (w
);
14726 if (row
->height
>= window_height
)
14728 if (!force_p
|| MINI_WINDOW_P (w
)
14729 || w
->vscroll
|| w
->cursor
.vpos
== 0)
14736 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
14737 non-zero means only WINDOW is redisplayed in redisplay_internal.
14738 TEMP_SCROLL_STEP has the same meaning as emacs_scroll_step, and is used
14739 in redisplay_window to bring a partially visible line into view in
14740 the case that only the cursor has moved.
14742 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
14743 last screen line's vertical height extends past the end of the screen.
14747 1 if scrolling succeeded
14749 0 if scrolling didn't find point.
14751 -1 if new fonts have been loaded so that we must interrupt
14752 redisplay, adjust glyph matrices, and try again. */
14758 SCROLLING_NEED_LARGER_MATRICES
14761 /* If scroll-conservatively is more than this, never recenter.
14763 If you change this, don't forget to update the doc string of
14764 `scroll-conservatively' and the Emacs manual. */
14765 #define SCROLL_LIMIT 100
14768 try_scrolling (Lisp_Object window
, int just_this_one_p
,
14769 ptrdiff_t arg_scroll_conservatively
, ptrdiff_t scroll_step
,
14770 int temp_scroll_step
, int last_line_misfit
)
14772 struct window
*w
= XWINDOW (window
);
14773 struct frame
*f
= XFRAME (w
->frame
);
14774 struct text_pos pos
, startp
;
14776 int this_scroll_margin
, scroll_max
, rc
, height
;
14777 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
14778 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
14779 Lisp_Object aggressive
;
14780 /* We will never try scrolling more than this number of lines. */
14781 int scroll_limit
= SCROLL_LIMIT
;
14782 int frame_line_height
= default_line_pixel_height (w
);
14783 int window_total_lines
14784 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
14787 debug_method_add (w
, "try_scrolling");
14790 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14792 /* Compute scroll margin height in pixels. We scroll when point is
14793 within this distance from the top or bottom of the window. */
14794 if (scroll_margin
> 0)
14795 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4)
14796 * frame_line_height
;
14798 this_scroll_margin
= 0;
14800 /* Force arg_scroll_conservatively to have a reasonable value, to
14801 avoid scrolling too far away with slow move_it_* functions. Note
14802 that the user can supply scroll-conservatively equal to
14803 `most-positive-fixnum', which can be larger than INT_MAX. */
14804 if (arg_scroll_conservatively
> scroll_limit
)
14806 arg_scroll_conservatively
= scroll_limit
+ 1;
14807 scroll_max
= scroll_limit
* frame_line_height
;
14809 else if (scroll_step
|| arg_scroll_conservatively
|| temp_scroll_step
)
14810 /* Compute how much we should try to scroll maximally to bring
14811 point into view. */
14812 scroll_max
= (max (scroll_step
,
14813 max (arg_scroll_conservatively
, temp_scroll_step
))
14814 * frame_line_height
);
14815 else if (NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
))
14816 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
)))
14817 /* We're trying to scroll because of aggressive scrolling but no
14818 scroll_step is set. Choose an arbitrary one. */
14819 scroll_max
= 10 * frame_line_height
;
14825 /* Decide whether to scroll down. */
14826 if (PT
> CHARPOS (startp
))
14828 int scroll_margin_y
;
14830 /* Compute the pixel ypos of the scroll margin, then move IT to
14831 either that ypos or PT, whichever comes first. */
14832 start_display (&it
, w
, startp
);
14833 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
14834 - frame_line_height
* extra_scroll_margin_lines
;
14835 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
14836 (MOVE_TO_POS
| MOVE_TO_Y
));
14838 if (PT
> CHARPOS (it
.current
.pos
))
14840 int y0
= line_bottom_y (&it
);
14841 /* Compute how many pixels below window bottom to stop searching
14842 for PT. This avoids costly search for PT that is far away if
14843 the user limited scrolling by a small number of lines, but
14844 always finds PT if scroll_conservatively is set to a large
14845 number, such as most-positive-fixnum. */
14846 int slack
= max (scroll_max
, 10 * frame_line_height
);
14847 int y_to_move
= it
.last_visible_y
+ slack
;
14849 /* Compute the distance from the scroll margin to PT or to
14850 the scroll limit, whichever comes first. This should
14851 include the height of the cursor line, to make that line
14853 move_it_to (&it
, PT
, -1, y_to_move
,
14854 -1, MOVE_TO_POS
| MOVE_TO_Y
);
14855 dy
= line_bottom_y (&it
) - y0
;
14857 if (dy
> scroll_max
)
14858 return SCROLLING_FAILED
;
14867 /* Point is in or below the bottom scroll margin, so move the
14868 window start down. If scrolling conservatively, move it just
14869 enough down to make point visible. If scroll_step is set,
14870 move it down by scroll_step. */
14871 if (arg_scroll_conservatively
)
14873 = min (max (dy
, frame_line_height
),
14874 frame_line_height
* arg_scroll_conservatively
);
14875 else if (scroll_step
|| temp_scroll_step
)
14876 amount_to_scroll
= scroll_max
;
14879 aggressive
= BVAR (current_buffer
, scroll_up_aggressively
);
14880 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14881 if (NUMBERP (aggressive
))
14883 double float_amount
= XFLOATINT (aggressive
) * height
;
14884 int aggressive_scroll
= float_amount
;
14885 if (aggressive_scroll
== 0 && float_amount
> 0)
14886 aggressive_scroll
= 1;
14887 /* Don't let point enter the scroll margin near top of
14888 the window. This could happen if the value of
14889 scroll_up_aggressively is too large and there are
14890 non-zero margins, because scroll_up_aggressively
14891 means put point that fraction of window height
14892 _from_the_bottom_margin_. */
14893 if (aggressive_scroll
+ 2*this_scroll_margin
> height
)
14894 aggressive_scroll
= height
- 2*this_scroll_margin
;
14895 amount_to_scroll
= dy
+ aggressive_scroll
;
14899 if (amount_to_scroll
<= 0)
14900 return SCROLLING_FAILED
;
14902 start_display (&it
, w
, startp
);
14903 if (arg_scroll_conservatively
<= scroll_limit
)
14904 move_it_vertically (&it
, amount_to_scroll
);
14907 /* Extra precision for users who set scroll-conservatively
14908 to a large number: make sure the amount we scroll
14909 the window start is never less than amount_to_scroll,
14910 which was computed as distance from window bottom to
14911 point. This matters when lines at window top and lines
14912 below window bottom have different height. */
14914 void *it1data
= NULL
;
14915 /* We use a temporary it1 because line_bottom_y can modify
14916 its argument, if it moves one line down; see there. */
14919 SAVE_IT (it1
, it
, it1data
);
14920 start_y
= line_bottom_y (&it1
);
14922 RESTORE_IT (&it
, &it
, it1data
);
14923 move_it_by_lines (&it
, 1);
14924 SAVE_IT (it1
, it
, it1data
);
14925 } while (line_bottom_y (&it1
) - start_y
< amount_to_scroll
);
14928 /* If STARTP is unchanged, move it down another screen line. */
14929 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
14930 move_it_by_lines (&it
, 1);
14931 startp
= it
.current
.pos
;
14935 struct text_pos scroll_margin_pos
= startp
;
14938 /* See if point is inside the scroll margin at the top of the
14940 if (this_scroll_margin
)
14944 start_display (&it
, w
, startp
);
14945 y_start
= it
.current_y
;
14946 move_it_vertically (&it
, this_scroll_margin
);
14947 scroll_margin_pos
= it
.current
.pos
;
14948 /* If we didn't move enough before hitting ZV, request
14949 additional amount of scroll, to move point out of the
14951 if (IT_CHARPOS (it
) == ZV
14952 && it
.current_y
- y_start
< this_scroll_margin
)
14953 y_offset
= this_scroll_margin
- (it
.current_y
- y_start
);
14956 if (PT
< CHARPOS (scroll_margin_pos
))
14958 /* Point is in the scroll margin at the top of the window or
14959 above what is displayed in the window. */
14962 /* Compute the vertical distance from PT to the scroll
14963 margin position. Move as far as scroll_max allows, or
14964 one screenful, or 10 screen lines, whichever is largest.
14965 Give up if distance is greater than scroll_max or if we
14966 didn't reach the scroll margin position. */
14967 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
14968 start_display (&it
, w
, pos
);
14970 y_to_move
= max (it
.last_visible_y
,
14971 max (scroll_max
, 10 * frame_line_height
));
14972 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
14974 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
14975 dy
= it
.current_y
- y0
;
14976 if (dy
> scroll_max
14977 || IT_CHARPOS (it
) < CHARPOS (scroll_margin_pos
))
14978 return SCROLLING_FAILED
;
14980 /* Additional scroll for when ZV was too close to point. */
14983 /* Compute new window start. */
14984 start_display (&it
, w
, startp
);
14986 if (arg_scroll_conservatively
)
14987 amount_to_scroll
= max (dy
, frame_line_height
*
14988 max (scroll_step
, temp_scroll_step
));
14989 else if (scroll_step
|| temp_scroll_step
)
14990 amount_to_scroll
= scroll_max
;
14993 aggressive
= BVAR (current_buffer
, scroll_down_aggressively
);
14994 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14995 if (NUMBERP (aggressive
))
14997 double float_amount
= XFLOATINT (aggressive
) * height
;
14998 int aggressive_scroll
= float_amount
;
14999 if (aggressive_scroll
== 0 && float_amount
> 0)
15000 aggressive_scroll
= 1;
15001 /* Don't let point enter the scroll margin near
15002 bottom of the window, if the value of
15003 scroll_down_aggressively happens to be too
15005 if (aggressive_scroll
+ 2*this_scroll_margin
> height
)
15006 aggressive_scroll
= height
- 2*this_scroll_margin
;
15007 amount_to_scroll
= dy
+ aggressive_scroll
;
15011 if (amount_to_scroll
<= 0)
15012 return SCROLLING_FAILED
;
15014 move_it_vertically_backward (&it
, amount_to_scroll
);
15015 startp
= it
.current
.pos
;
15019 /* Run window scroll functions. */
15020 startp
= run_window_scroll_functions (window
, startp
);
15022 /* Display the window. Give up if new fonts are loaded, or if point
15024 if (!try_window (window
, startp
, 0))
15025 rc
= SCROLLING_NEED_LARGER_MATRICES
;
15026 else if (w
->cursor
.vpos
< 0)
15028 clear_glyph_matrix (w
->desired_matrix
);
15029 rc
= SCROLLING_FAILED
;
15033 /* Maybe forget recorded base line for line number display. */
15034 if (!just_this_one_p
15035 || current_buffer
->clip_changed
15036 || BEG_UNCHANGED
< CHARPOS (startp
))
15037 w
->base_line_number
= 0;
15039 /* If cursor ends up on a partially visible line,
15040 treat that as being off the bottom of the screen. */
15041 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0)
15042 /* It's possible that the cursor is on the first line of the
15043 buffer, which is partially obscured due to a vscroll
15044 (Bug#7537). In that case, avoid looping forever . */
15045 && extra_scroll_margin_lines
< w
->desired_matrix
->nrows
- 1)
15047 clear_glyph_matrix (w
->desired_matrix
);
15048 ++extra_scroll_margin_lines
;
15051 rc
= SCROLLING_SUCCESS
;
15058 /* Compute a suitable window start for window W if display of W starts
15059 on a continuation line. Value is non-zero if a new window start
15062 The new window start will be computed, based on W's width, starting
15063 from the start of the continued line. It is the start of the
15064 screen line with the minimum distance from the old start W->start. */
15067 compute_window_start_on_continuation_line (struct window
*w
)
15069 struct text_pos pos
, start_pos
;
15070 int window_start_changed_p
= 0;
15072 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
15074 /* If window start is on a continuation line... Window start may be
15075 < BEGV in case there's invisible text at the start of the
15076 buffer (M-x rmail, for example). */
15077 if (CHARPOS (start_pos
) > BEGV
15078 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
15081 struct glyph_row
*row
;
15083 /* Handle the case that the window start is out of range. */
15084 if (CHARPOS (start_pos
) < BEGV
)
15085 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
15086 else if (CHARPOS (start_pos
) > ZV
)
15087 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
15089 /* Find the start of the continued line. This should be fast
15090 because find_newline is fast (newline cache). */
15091 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
15092 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
15093 row
, DEFAULT_FACE_ID
);
15094 reseat_at_previous_visible_line_start (&it
);
15096 /* If the line start is "too far" away from the window start,
15097 say it takes too much time to compute a new window start. */
15098 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
15099 /* PXW: Do we need upper bounds here ? */
15100 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
15102 int min_distance
, distance
;
15104 /* Move forward by display lines to find the new window
15105 start. If window width was enlarged, the new start can
15106 be expected to be > the old start. If window width was
15107 decreased, the new window start will be < the old start.
15108 So, we're looking for the display line start with the
15109 minimum distance from the old window start. */
15110 pos
= it
.current
.pos
;
15111 min_distance
= INFINITY
;
15112 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
15113 distance
< min_distance
)
15115 min_distance
= distance
;
15116 pos
= it
.current
.pos
;
15117 if (it
.line_wrap
== WORD_WRAP
)
15119 /* Under WORD_WRAP, move_it_by_lines is likely to
15120 overshoot and stop not at the first, but the
15121 second character from the left margin. So in
15122 that case, we need a more tight control on the X
15123 coordinate of the iterator than move_it_by_lines
15124 promises in its contract. The method is to first
15125 go to the last (rightmost) visible character of a
15126 line, then move to the leftmost character on the
15127 next line in a separate call. */
15128 move_it_to (&it
, ZV
, it
.last_visible_x
, it
.current_y
, -1,
15129 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15130 move_it_to (&it
, ZV
, 0,
15131 it
.current_y
+ it
.max_ascent
+ it
.max_descent
, -1,
15132 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15135 move_it_by_lines (&it
, 1);
15138 /* Set the window start there. */
15139 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
15140 window_start_changed_p
= 1;
15144 return window_start_changed_p
;
15148 /* Try cursor movement in case text has not changed in window WINDOW,
15149 with window start STARTP. Value is
15151 CURSOR_MOVEMENT_SUCCESS if successful
15153 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
15155 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
15156 display. *SCROLL_STEP is set to 1, under certain circumstances, if
15157 we want to scroll as if scroll-step were set to 1. See the code.
15159 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
15160 which case we have to abort this redisplay, and adjust matrices
15165 CURSOR_MOVEMENT_SUCCESS
,
15166 CURSOR_MOVEMENT_CANNOT_BE_USED
,
15167 CURSOR_MOVEMENT_MUST_SCROLL
,
15168 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
15172 try_cursor_movement (Lisp_Object window
, struct text_pos startp
, int *scroll_step
)
15174 struct window
*w
= XWINDOW (window
);
15175 struct frame
*f
= XFRAME (w
->frame
);
15176 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
15179 if (inhibit_try_cursor_movement
)
15183 /* Previously, there was a check for Lisp integer in the
15184 if-statement below. Now, this field is converted to
15185 ptrdiff_t, thus zero means invalid position in a buffer. */
15186 eassert (w
->last_point
> 0);
15187 /* Likewise there was a check whether window_end_vpos is nil or larger
15188 than the window. Now window_end_vpos is int and so never nil, but
15189 let's leave eassert to check whether it fits in the window. */
15190 eassert (w
->window_end_vpos
< w
->current_matrix
->nrows
);
15192 /* Handle case where text has not changed, only point, and it has
15193 not moved off the frame. */
15194 if (/* Point may be in this window. */
15195 PT
>= CHARPOS (startp
)
15196 /* Selective display hasn't changed. */
15197 && !current_buffer
->clip_changed
15198 /* Function force-mode-line-update is used to force a thorough
15199 redisplay. It sets either windows_or_buffers_changed or
15200 update_mode_lines. So don't take a shortcut here for these
15202 && !update_mode_lines
15203 && !windows_or_buffers_changed
15204 && !f
->cursor_type_changed
15205 && NILP (Vshow_trailing_whitespace
)
15206 /* This code is not used for mini-buffer for the sake of the case
15207 of redisplaying to replace an echo area message; since in
15208 that case the mini-buffer contents per se are usually
15209 unchanged. This code is of no real use in the mini-buffer
15210 since the handling of this_line_start_pos, etc., in redisplay
15211 handles the same cases. */
15212 && !EQ (window
, minibuf_window
)
15213 && (FRAME_WINDOW_P (f
)
15214 || !overlay_arrow_in_current_buffer_p ()))
15216 int this_scroll_margin
, top_scroll_margin
;
15217 struct glyph_row
*row
= NULL
;
15218 int frame_line_height
= default_line_pixel_height (w
);
15219 int window_total_lines
15220 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
15223 debug_method_add (w
, "cursor movement");
15226 /* Scroll if point within this distance from the top or bottom
15227 of the window. This is a pixel value. */
15228 if (scroll_margin
> 0)
15230 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4);
15231 this_scroll_margin
*= frame_line_height
;
15234 this_scroll_margin
= 0;
15236 top_scroll_margin
= this_scroll_margin
;
15237 if (WINDOW_WANTS_HEADER_LINE_P (w
))
15238 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
15240 /* Start with the row the cursor was displayed during the last
15241 not paused redisplay. Give up if that row is not valid. */
15242 if (w
->last_cursor_vpos
< 0
15243 || w
->last_cursor_vpos
>= w
->current_matrix
->nrows
)
15244 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15247 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor_vpos
);
15248 if (row
->mode_line_p
)
15250 if (!row
->enabled_p
)
15251 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15254 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
15256 int scroll_p
= 0, must_scroll
= 0;
15257 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
15259 if (PT
> w
->last_point
)
15261 /* Point has moved forward. */
15262 while (MATRIX_ROW_END_CHARPOS (row
) < PT
15263 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
15265 eassert (row
->enabled_p
);
15269 /* If the end position of a row equals the start
15270 position of the next row, and PT is at that position,
15271 we would rather display cursor in the next line. */
15272 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15273 && MATRIX_ROW_END_CHARPOS (row
) == PT
15274 && row
< MATRIX_MODE_LINE_ROW (w
->current_matrix
)
15275 && MATRIX_ROW_START_CHARPOS (row
+1) == PT
15276 && !cursor_row_p (row
))
15279 /* If within the scroll margin, scroll. Note that
15280 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
15281 the next line would be drawn, and that
15282 this_scroll_margin can be zero. */
15283 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
15284 || PT
> MATRIX_ROW_END_CHARPOS (row
)
15285 /* Line is completely visible last line in window
15286 and PT is to be set in the next line. */
15287 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
15288 && PT
== MATRIX_ROW_END_CHARPOS (row
)
15289 && !row
->ends_at_zv_p
15290 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
15293 else if (PT
< w
->last_point
)
15295 /* Cursor has to be moved backward. Note that PT >=
15296 CHARPOS (startp) because of the outer if-statement. */
15297 while (!row
->mode_line_p
15298 && (MATRIX_ROW_START_CHARPOS (row
) > PT
15299 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15300 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
15301 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
15302 row
> w
->current_matrix
->rows
15303 && (row
-1)->ends_in_newline_from_string_p
))))
15304 && (row
->y
> top_scroll_margin
15305 || CHARPOS (startp
) == BEGV
))
15307 eassert (row
->enabled_p
);
15311 /* Consider the following case: Window starts at BEGV,
15312 there is invisible, intangible text at BEGV, so that
15313 display starts at some point START > BEGV. It can
15314 happen that we are called with PT somewhere between
15315 BEGV and START. Try to handle that case. */
15316 if (row
< w
->current_matrix
->rows
15317 || row
->mode_line_p
)
15319 row
= w
->current_matrix
->rows
;
15320 if (row
->mode_line_p
)
15324 /* Due to newlines in overlay strings, we may have to
15325 skip forward over overlay strings. */
15326 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15327 && MATRIX_ROW_END_CHARPOS (row
) == PT
15328 && !cursor_row_p (row
))
15331 /* If within the scroll margin, scroll. */
15332 if (row
->y
< top_scroll_margin
15333 && CHARPOS (startp
) != BEGV
)
15338 /* Cursor did not move. So don't scroll even if cursor line
15339 is partially visible, as it was so before. */
15340 rc
= CURSOR_MOVEMENT_SUCCESS
;
15343 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
15344 || PT
> MATRIX_ROW_END_CHARPOS (row
))
15346 /* if PT is not in the glyph row, give up. */
15347 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15350 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15351 && !NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
15353 struct glyph_row
*row1
;
15355 /* If rows are bidi-reordered and point moved, back up
15356 until we find a row that does not belong to a
15357 continuation line. This is because we must consider
15358 all rows of a continued line as candidates for the
15359 new cursor positioning, since row start and end
15360 positions change non-linearly with vertical position
15362 /* FIXME: Revisit this when glyph ``spilling'' in
15363 continuation lines' rows is implemented for
15364 bidi-reordered rows. */
15365 for (row1
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15366 MATRIX_ROW_CONTINUATION_LINE_P (row
);
15369 /* If we hit the beginning of the displayed portion
15370 without finding the first row of a continued
15374 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15377 eassert (row
->enabled_p
);
15382 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15383 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
15384 /* Make sure this isn't a header line by any chance, since
15385 then MATRIX_ROW_PARTIALLY_VISIBLE_P might yield non-zero. */
15386 && !row
->mode_line_p
15387 && make_cursor_line_fully_visible_p
)
15389 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
15390 && !row
->ends_at_zv_p
15391 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15392 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15393 else if (row
->height
> window_box_height (w
))
15395 /* If we end up in a partially visible line, let's
15396 make it fully visible, except when it's taller
15397 than the window, in which case we can't do much
15400 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15404 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15405 if (!cursor_row_fully_visible_p (w
, 0, 1))
15406 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15408 rc
= CURSOR_MOVEMENT_SUCCESS
;
15412 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15413 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15414 && !NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
15416 /* With bidi-reordered rows, there could be more than
15417 one candidate row whose start and end positions
15418 occlude point. We need to let set_cursor_from_row
15419 find the best candidate. */
15420 /* FIXME: Revisit this when glyph ``spilling'' in
15421 continuation lines' rows is implemented for
15422 bidi-reordered rows. */
15427 int at_zv_p
= 0, exact_match_p
= 0;
15429 if (MATRIX_ROW_START_CHARPOS (row
) <= PT
15430 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
15431 && cursor_row_p (row
))
15432 rv
|= set_cursor_from_row (w
, row
, w
->current_matrix
,
15434 /* As soon as we've found the exact match for point,
15435 or the first suitable row whose ends_at_zv_p flag
15436 is set, we are done. */
15438 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
)->ends_at_zv_p
;
15440 && w
->cursor
.hpos
>= 0
15441 && w
->cursor
.hpos
< MATRIX_ROW_USED (w
->current_matrix
,
15444 struct glyph_row
*candidate
=
15445 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
15447 candidate
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
15448 ptrdiff_t endpos
= MATRIX_ROW_END_CHARPOS (candidate
);
15451 (BUFFERP (g
->object
) && g
->charpos
== PT
)
15452 || (INTEGERP (g
->object
)
15453 && (g
->charpos
== PT
15454 || (g
->charpos
== 0 && endpos
- 1 == PT
)));
15456 if (rv
&& (at_zv_p
|| exact_match_p
))
15458 rc
= CURSOR_MOVEMENT_SUCCESS
;
15461 if (MATRIX_ROW_BOTTOM_Y (row
) == last_y
)
15465 while (((MATRIX_ROW_CONTINUATION_LINE_P (row
)
15466 || row
->continued_p
)
15467 && MATRIX_ROW_BOTTOM_Y (row
) <= last_y
)
15468 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15469 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
));
15470 /* If we didn't find any candidate rows, or exited the
15471 loop before all the candidates were examined, signal
15472 to the caller that this method failed. */
15473 if (rc
!= CURSOR_MOVEMENT_SUCCESS
15475 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
15476 && !row
->continued_p
))
15477 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15479 rc
= CURSOR_MOVEMENT_SUCCESS
;
15485 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
15487 rc
= CURSOR_MOVEMENT_SUCCESS
;
15492 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15493 && MATRIX_ROW_START_CHARPOS (row
) == PT
15494 && cursor_row_p (row
));
15502 #if !defined USE_TOOLKIT_SCROLL_BARS || defined USE_GTK
15506 set_vertical_scroll_bar (struct window
*w
)
15508 ptrdiff_t start
, end
, whole
;
15510 /* Calculate the start and end positions for the current window.
15511 At some point, it would be nice to choose between scrollbars
15512 which reflect the whole buffer size, with special markers
15513 indicating narrowing, and scrollbars which reflect only the
15516 Note that mini-buffers sometimes aren't displaying any text. */
15517 if (!MINI_WINDOW_P (w
)
15518 || (w
== XWINDOW (minibuf_window
)
15519 && NILP (echo_area_buffer
[0])))
15521 struct buffer
*buf
= XBUFFER (w
->contents
);
15522 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
15523 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
15524 /* I don't think this is guaranteed to be right. For the
15525 moment, we'll pretend it is. */
15526 end
= BUF_Z (buf
) - w
->window_end_pos
- BUF_BEGV (buf
);
15530 if (whole
< (end
- start
))
15531 whole
= end
- start
;
15534 start
= end
= whole
= 0;
15536 /* Indicate what this scroll bar ought to be displaying now. */
15537 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15538 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15539 (w
, end
- start
, whole
, start
);
15543 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
15544 selected_window is redisplayed.
15546 We can return without actually redisplaying the window if fonts has been
15547 changed on window's frame. In that case, redisplay_internal will retry. */
15550 redisplay_window (Lisp_Object window
, bool just_this_one_p
)
15552 struct window
*w
= XWINDOW (window
);
15553 struct frame
*f
= XFRAME (w
->frame
);
15554 struct buffer
*buffer
= XBUFFER (w
->contents
);
15555 struct buffer
*old
= current_buffer
;
15556 struct text_pos lpoint
, opoint
, startp
;
15557 int update_mode_line
;
15560 /* Record it now because it's overwritten. */
15561 bool current_matrix_up_to_date_p
= false;
15562 bool used_current_matrix_p
= false;
15563 /* This is less strict than current_matrix_up_to_date_p.
15564 It indicates that the buffer contents and narrowing are unchanged. */
15565 bool buffer_unchanged_p
= false;
15566 int temp_scroll_step
= 0;
15567 ptrdiff_t count
= SPECPDL_INDEX ();
15569 int centering_position
= -1;
15570 int last_line_misfit
= 0;
15571 ptrdiff_t beg_unchanged
, end_unchanged
;
15572 int frame_line_height
;
15574 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15578 *w
->desired_matrix
->method
= 0;
15581 if (!just_this_one_p
15582 && REDISPLAY_SOME_P ()
15585 && !buffer
->text
->redisplay
)
15588 /* Make sure that both W's markers are valid. */
15589 eassert (XMARKER (w
->start
)->buffer
== buffer
);
15590 eassert (XMARKER (w
->pointm
)->buffer
== buffer
);
15593 reconsider_clip_changes (w
);
15594 frame_line_height
= default_line_pixel_height (w
);
15596 /* Has the mode line to be updated? */
15597 update_mode_line
= (w
->update_mode_line
15598 || update_mode_lines
15599 || buffer
->clip_changed
15600 || buffer
->prevent_redisplay_optimizations_p
);
15602 if (!just_this_one_p
)
15603 /* If `just_this_one_p' is set, we apparently set must_be_updated_p more
15604 cleverly elsewhere. */
15605 w
->must_be_updated_p
= true;
15607 if (MINI_WINDOW_P (w
))
15609 if (w
== XWINDOW (echo_area_window
)
15610 && !NILP (echo_area_buffer
[0]))
15612 if (update_mode_line
)
15613 /* We may have to update a tty frame's menu bar or a
15614 tool-bar. Example `M-x C-h C-h C-g'. */
15615 goto finish_menu_bars
;
15617 /* We've already displayed the echo area glyphs in this window. */
15618 goto finish_scroll_bars
;
15620 else if ((w
!= XWINDOW (minibuf_window
)
15621 || minibuf_level
== 0)
15622 /* When buffer is nonempty, redisplay window normally. */
15623 && BUF_Z (XBUFFER (w
->contents
)) == BUF_BEG (XBUFFER (w
->contents
))
15624 /* Quail displays non-mini buffers in minibuffer window.
15625 In that case, redisplay the window normally. */
15626 && !NILP (Fmemq (w
->contents
, Vminibuffer_list
)))
15628 /* W is a mini-buffer window, but it's not active, so clear
15630 int yb
= window_text_bottom_y (w
);
15631 struct glyph_row
*row
;
15634 for (y
= 0, row
= w
->desired_matrix
->rows
;
15636 y
+= row
->height
, ++row
)
15637 blank_row (w
, row
, y
);
15638 goto finish_scroll_bars
;
15641 clear_glyph_matrix (w
->desired_matrix
);
15644 /* Otherwise set up data on this window; select its buffer and point
15646 /* Really select the buffer, for the sake of buffer-local
15648 set_buffer_internal_1 (XBUFFER (w
->contents
));
15650 current_matrix_up_to_date_p
15651 = (w
->window_end_valid
15652 && !current_buffer
->clip_changed
15653 && !current_buffer
->prevent_redisplay_optimizations_p
15654 && !window_outdated (w
));
15656 /* Run the window-bottom-change-functions
15657 if it is possible that the text on the screen has changed
15658 (either due to modification of the text, or any other reason). */
15659 if (!current_matrix_up_to_date_p
15660 && !NILP (Vwindow_text_change_functions
))
15662 safe_run_hooks (Qwindow_text_change_functions
);
15666 beg_unchanged
= BEG_UNCHANGED
;
15667 end_unchanged
= END_UNCHANGED
;
15669 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
15671 specbind (Qinhibit_point_motion_hooks
, Qt
);
15674 = (w
->window_end_valid
15675 && !current_buffer
->clip_changed
15676 && !window_outdated (w
));
15678 /* When windows_or_buffers_changed is non-zero, we can't rely
15679 on the window end being valid, so set it to zero there. */
15680 if (windows_or_buffers_changed
)
15682 /* If window starts on a continuation line, maybe adjust the
15683 window start in case the window's width changed. */
15684 if (XMARKER (w
->start
)->buffer
== current_buffer
)
15685 compute_window_start_on_continuation_line (w
);
15687 w
->window_end_valid
= false;
15688 /* If so, we also can't rely on current matrix
15689 and should not fool try_cursor_movement below. */
15690 current_matrix_up_to_date_p
= false;
15693 /* Some sanity checks. */
15694 CHECK_WINDOW_END (w
);
15695 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
15697 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
15700 if (mode_line_update_needed (w
))
15701 update_mode_line
= 1;
15703 /* Point refers normally to the selected window. For any other
15704 window, set up appropriate value. */
15705 if (!EQ (window
, selected_window
))
15707 ptrdiff_t new_pt
= marker_position (w
->pointm
);
15708 ptrdiff_t new_pt_byte
= marker_byte_position (w
->pointm
);
15712 new_pt_byte
= BEGV_BYTE
;
15713 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
15715 else if (new_pt
> (ZV
- 1))
15718 new_pt_byte
= ZV_BYTE
;
15719 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
15722 /* We don't use SET_PT so that the point-motion hooks don't run. */
15723 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
15726 /* If any of the character widths specified in the display table
15727 have changed, invalidate the width run cache. It's true that
15728 this may be a bit late to catch such changes, but the rest of
15729 redisplay goes (non-fatally) haywire when the display table is
15730 changed, so why should we worry about doing any better? */
15731 if (current_buffer
->width_run_cache
)
15733 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
15735 if (! disptab_matches_widthtab
15736 (disptab
, XVECTOR (BVAR (current_buffer
, width_table
))))
15738 invalidate_region_cache (current_buffer
,
15739 current_buffer
->width_run_cache
,
15741 recompute_width_table (current_buffer
, disptab
);
15745 /* If window-start is screwed up, choose a new one. */
15746 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
15749 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15751 /* If someone specified a new starting point but did not insist,
15752 check whether it can be used. */
15753 if (w
->optional_new_start
15754 && CHARPOS (startp
) >= BEGV
15755 && CHARPOS (startp
) <= ZV
)
15757 w
->optional_new_start
= 0;
15758 start_display (&it
, w
, startp
);
15759 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
15760 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15761 if (IT_CHARPOS (it
) == PT
)
15762 w
->force_start
= 1;
15763 /* IT may overshoot PT if text at PT is invisible. */
15764 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
15765 w
->force_start
= 1;
15770 /* Handle case where place to start displaying has been specified,
15771 unless the specified location is outside the accessible range. */
15772 if (w
->force_start
|| window_frozen_p (w
))
15774 /* We set this later on if we have to adjust point. */
15777 w
->force_start
= 0;
15779 w
->window_end_valid
= 0;
15781 /* Forget any recorded base line for line number display. */
15782 if (!buffer_unchanged_p
)
15783 w
->base_line_number
= 0;
15785 /* Redisplay the mode line. Select the buffer properly for that.
15786 Also, run the hook window-scroll-functions
15787 because we have scrolled. */
15788 /* Note, we do this after clearing force_start because
15789 if there's an error, it is better to forget about force_start
15790 than to get into an infinite loop calling the hook functions
15791 and having them get more errors. */
15792 if (!update_mode_line
15793 || ! NILP (Vwindow_scroll_functions
))
15795 update_mode_line
= 1;
15796 w
->update_mode_line
= 1;
15797 startp
= run_window_scroll_functions (window
, startp
);
15800 if (CHARPOS (startp
) < BEGV
)
15801 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
15802 else if (CHARPOS (startp
) > ZV
)
15803 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
15805 /* Redisplay, then check if cursor has been set during the
15806 redisplay. Give up if new fonts were loaded. */
15807 /* We used to issue a CHECK_MARGINS argument to try_window here,
15808 but this causes scrolling to fail when point begins inside
15809 the scroll margin (bug#148) -- cyd */
15810 if (!try_window (window
, startp
, 0))
15812 w
->force_start
= 1;
15813 clear_glyph_matrix (w
->desired_matrix
);
15814 goto need_larger_matrices
;
15817 if (w
->cursor
.vpos
< 0 && !window_frozen_p (w
))
15819 /* If point does not appear, try to move point so it does
15820 appear. The desired matrix has been built above, so we
15821 can use it here. */
15822 new_vpos
= window_box_height (w
) / 2;
15825 if (!cursor_row_fully_visible_p (w
, 0, 0))
15827 /* Point does appear, but on a line partly visible at end of window.
15828 Move it back to a fully-visible line. */
15829 new_vpos
= window_box_height (w
);
15831 else if (w
->cursor
.vpos
>= 0)
15833 /* Some people insist on not letting point enter the scroll
15834 margin, even though this part handles windows that didn't
15836 int window_total_lines
15837 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
15838 int margin
= min (scroll_margin
, window_total_lines
/ 4);
15839 int pixel_margin
= margin
* frame_line_height
;
15840 bool header_line
= WINDOW_WANTS_HEADER_LINE_P (w
);
15842 /* Note: We add an extra FRAME_LINE_HEIGHT, because the loop
15843 below, which finds the row to move point to, advances by
15844 the Y coordinate of the _next_ row, see the definition of
15845 MATRIX_ROW_BOTTOM_Y. */
15846 if (w
->cursor
.vpos
< margin
+ header_line
)
15848 w
->cursor
.vpos
= -1;
15849 clear_glyph_matrix (w
->desired_matrix
);
15850 goto try_to_scroll
;
15854 int window_height
= window_box_height (w
);
15857 window_height
+= CURRENT_HEADER_LINE_HEIGHT (w
);
15858 if (w
->cursor
.y
>= window_height
- pixel_margin
)
15860 w
->cursor
.vpos
= -1;
15861 clear_glyph_matrix (w
->desired_matrix
);
15862 goto try_to_scroll
;
15867 /* If we need to move point for either of the above reasons,
15868 now actually do it. */
15871 struct glyph_row
*row
;
15873 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
15874 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
15877 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
15878 MATRIX_ROW_START_BYTEPOS (row
));
15880 if (w
!= XWINDOW (selected_window
))
15881 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
15882 else if (current_buffer
== old
)
15883 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15885 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
15887 /* If we are highlighting the region, then we just changed
15888 the region, so redisplay to show it. */
15889 /* FIXME: We need to (re)run pre-redisplay-function! */
15890 /* if (markpos_of_region () >= 0)
15892 clear_glyph_matrix (w->desired_matrix);
15893 if (!try_window (window, startp, 0))
15894 goto need_larger_matrices;
15900 debug_method_add (w
, "forced window start");
15905 /* Handle case where text has not changed, only point, and it has
15906 not moved off the frame, and we are not retrying after hscroll.
15907 (current_matrix_up_to_date_p is nonzero when retrying.) */
15908 if (current_matrix_up_to_date_p
15909 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
15910 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
15914 case CURSOR_MOVEMENT_SUCCESS
:
15915 used_current_matrix_p
= 1;
15918 case CURSOR_MOVEMENT_MUST_SCROLL
:
15919 goto try_to_scroll
;
15925 /* If current starting point was originally the beginning of a line
15926 but no longer is, find a new starting point. */
15927 else if (w
->start_at_line_beg
15928 && !(CHARPOS (startp
) <= BEGV
15929 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
15932 debug_method_add (w
, "recenter 1");
15937 /* Try scrolling with try_window_id. Value is > 0 if update has
15938 been done, it is -1 if we know that the same window start will
15939 not work. It is 0 if unsuccessful for some other reason. */
15940 else if ((tem
= try_window_id (w
)) != 0)
15943 debug_method_add (w
, "try_window_id %d", tem
);
15946 if (f
->fonts_changed
)
15947 goto need_larger_matrices
;
15951 /* Otherwise try_window_id has returned -1 which means that we
15952 don't want the alternative below this comment to execute. */
15954 else if (CHARPOS (startp
) >= BEGV
15955 && CHARPOS (startp
) <= ZV
15956 && PT
>= CHARPOS (startp
)
15957 && (CHARPOS (startp
) < ZV
15958 /* Avoid starting at end of buffer. */
15959 || CHARPOS (startp
) == BEGV
15960 || !window_outdated (w
)))
15962 int d1
, d2
, d3
, d4
, d5
, d6
;
15964 /* If first window line is a continuation line, and window start
15965 is inside the modified region, but the first change is before
15966 current window start, we must select a new window start.
15968 However, if this is the result of a down-mouse event (e.g. by
15969 extending the mouse-drag-overlay), we don't want to select a
15970 new window start, since that would change the position under
15971 the mouse, resulting in an unwanted mouse-movement rather
15972 than a simple mouse-click. */
15973 if (!w
->start_at_line_beg
15974 && NILP (do_mouse_tracking
)
15975 && CHARPOS (startp
) > BEGV
15976 && CHARPOS (startp
) > BEG
+ beg_unchanged
15977 && CHARPOS (startp
) <= Z
- end_unchanged
15978 /* Even if w->start_at_line_beg is nil, a new window may
15979 start at a line_beg, since that's how set_buffer_window
15980 sets it. So, we need to check the return value of
15981 compute_window_start_on_continuation_line. (See also
15983 && XMARKER (w
->start
)->buffer
== current_buffer
15984 && compute_window_start_on_continuation_line (w
)
15985 /* It doesn't make sense to force the window start like we
15986 do at label force_start if it is already known that point
15987 will not be visible in the resulting window, because
15988 doing so will move point from its correct position
15989 instead of scrolling the window to bring point into view.
15991 && pos_visible_p (w
, PT
, &d1
, &d2
, &d3
, &d4
, &d5
, &d6
))
15993 w
->force_start
= 1;
15994 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15999 debug_method_add (w
, "same window start");
16002 /* Try to redisplay starting at same place as before.
16003 If point has not moved off frame, accept the results. */
16004 if (!current_matrix_up_to_date_p
16005 /* Don't use try_window_reusing_current_matrix in this case
16006 because a window scroll function can have changed the
16008 || !NILP (Vwindow_scroll_functions
)
16009 || MINI_WINDOW_P (w
)
16010 || !(used_current_matrix_p
16011 = try_window_reusing_current_matrix (w
)))
16013 IF_DEBUG (debug_method_add (w
, "1"));
16014 if (try_window (window
, startp
, TRY_WINDOW_CHECK_MARGINS
) < 0)
16015 /* -1 means we need to scroll.
16016 0 means we need new matrices, but fonts_changed
16017 is set in that case, so we will detect it below. */
16018 goto try_to_scroll
;
16021 if (f
->fonts_changed
)
16022 goto need_larger_matrices
;
16024 if (w
->cursor
.vpos
>= 0)
16026 if (!just_this_one_p
16027 || current_buffer
->clip_changed
16028 || BEG_UNCHANGED
< CHARPOS (startp
))
16029 /* Forget any recorded base line for line number display. */
16030 w
->base_line_number
= 0;
16032 if (!cursor_row_fully_visible_p (w
, 1, 0))
16034 clear_glyph_matrix (w
->desired_matrix
);
16035 last_line_misfit
= 1;
16037 /* Drop through and scroll. */
16042 clear_glyph_matrix (w
->desired_matrix
);
16047 /* Redisplay the mode line. Select the buffer properly for that. */
16048 if (!update_mode_line
)
16050 update_mode_line
= 1;
16051 w
->update_mode_line
= 1;
16054 /* Try to scroll by specified few lines. */
16055 if ((scroll_conservatively
16056 || emacs_scroll_step
16057 || temp_scroll_step
16058 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
))
16059 || NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
)))
16060 && CHARPOS (startp
) >= BEGV
16061 && CHARPOS (startp
) <= ZV
)
16063 /* The function returns -1 if new fonts were loaded, 1 if
16064 successful, 0 if not successful. */
16065 int ss
= try_scrolling (window
, just_this_one_p
,
16066 scroll_conservatively
,
16068 temp_scroll_step
, last_line_misfit
);
16071 case SCROLLING_SUCCESS
:
16074 case SCROLLING_NEED_LARGER_MATRICES
:
16075 goto need_larger_matrices
;
16077 case SCROLLING_FAILED
:
16085 /* Finally, just choose a place to start which positions point
16086 according to user preferences. */
16091 debug_method_add (w
, "recenter");
16094 /* Forget any previously recorded base line for line number display. */
16095 if (!buffer_unchanged_p
)
16096 w
->base_line_number
= 0;
16098 /* Determine the window start relative to point. */
16099 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
16100 it
.current_y
= it
.last_visible_y
;
16101 if (centering_position
< 0)
16103 int window_total_lines
16104 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
16107 ? min (scroll_margin
, window_total_lines
/ 4)
16109 ptrdiff_t margin_pos
= CHARPOS (startp
);
16110 Lisp_Object aggressive
;
16113 /* If there is a scroll margin at the top of the window, find
16114 its character position. */
16116 /* Cannot call start_display if startp is not in the
16117 accessible region of the buffer. This can happen when we
16118 have just switched to a different buffer and/or changed
16119 its restriction. In that case, startp is initialized to
16120 the character position 1 (BEGV) because we did not yet
16121 have chance to display the buffer even once. */
16122 && BEGV
<= CHARPOS (startp
) && CHARPOS (startp
) <= ZV
)
16125 void *it1data
= NULL
;
16127 SAVE_IT (it1
, it
, it1data
);
16128 start_display (&it1
, w
, startp
);
16129 move_it_vertically (&it1
, margin
* frame_line_height
);
16130 margin_pos
= IT_CHARPOS (it1
);
16131 RESTORE_IT (&it
, &it
, it1data
);
16133 scrolling_up
= PT
> margin_pos
;
16136 ? BVAR (current_buffer
, scroll_up_aggressively
)
16137 : BVAR (current_buffer
, scroll_down_aggressively
);
16139 if (!MINI_WINDOW_P (w
)
16140 && (scroll_conservatively
> SCROLL_LIMIT
|| NUMBERP (aggressive
)))
16144 /* Setting scroll-conservatively overrides
16145 scroll-*-aggressively. */
16146 if (!scroll_conservatively
&& NUMBERP (aggressive
))
16148 double float_amount
= XFLOATINT (aggressive
);
16150 pt_offset
= float_amount
* WINDOW_BOX_TEXT_HEIGHT (w
);
16151 if (pt_offset
== 0 && float_amount
> 0)
16153 if (pt_offset
&& margin
> 0)
16156 /* Compute how much to move the window start backward from
16157 point so that point will be displayed where the user
16161 centering_position
= it
.last_visible_y
;
16163 centering_position
-= pt_offset
;
16164 centering_position
-=
16165 frame_line_height
* (1 + margin
+ (last_line_misfit
!= 0))
16166 + WINDOW_HEADER_LINE_HEIGHT (w
);
16167 /* Don't let point enter the scroll margin near top of
16169 if (centering_position
< margin
* frame_line_height
)
16170 centering_position
= margin
* frame_line_height
;
16173 centering_position
= margin
* frame_line_height
+ pt_offset
;
16176 /* Set the window start half the height of the window backward
16178 centering_position
= window_box_height (w
) / 2;
16180 move_it_vertically_backward (&it
, centering_position
);
16182 eassert (IT_CHARPOS (it
) >= BEGV
);
16184 /* The function move_it_vertically_backward may move over more
16185 than the specified y-distance. If it->w is small, e.g. a
16186 mini-buffer window, we may end up in front of the window's
16187 display area. Start displaying at the start of the line
16188 containing PT in this case. */
16189 if (it
.current_y
<= 0)
16191 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
16192 move_it_vertically_backward (&it
, 0);
16196 it
.current_x
= it
.hpos
= 0;
16198 /* Set the window start position here explicitly, to avoid an
16199 infinite loop in case the functions in window-scroll-functions
16201 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
16203 /* Run scroll hooks. */
16204 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
16206 /* Redisplay the window. */
16207 if (!current_matrix_up_to_date_p
16208 || windows_or_buffers_changed
16209 || f
->cursor_type_changed
16210 /* Don't use try_window_reusing_current_matrix in this case
16211 because it can have changed the buffer. */
16212 || !NILP (Vwindow_scroll_functions
)
16213 || !just_this_one_p
16214 || MINI_WINDOW_P (w
)
16215 || !(used_current_matrix_p
16216 = try_window_reusing_current_matrix (w
)))
16217 try_window (window
, startp
, 0);
16219 /* If new fonts have been loaded (due to fontsets), give up. We
16220 have to start a new redisplay since we need to re-adjust glyph
16222 if (f
->fonts_changed
)
16223 goto need_larger_matrices
;
16225 /* If cursor did not appear assume that the middle of the window is
16226 in the first line of the window. Do it again with the next line.
16227 (Imagine a window of height 100, displaying two lines of height
16228 60. Moving back 50 from it->last_visible_y will end in the first
16230 if (w
->cursor
.vpos
< 0)
16232 if (w
->window_end_valid
&& PT
>= Z
- w
->window_end_pos
)
16234 clear_glyph_matrix (w
->desired_matrix
);
16235 move_it_by_lines (&it
, 1);
16236 try_window (window
, it
.current
.pos
, 0);
16238 else if (PT
< IT_CHARPOS (it
))
16240 clear_glyph_matrix (w
->desired_matrix
);
16241 move_it_by_lines (&it
, -1);
16242 try_window (window
, it
.current
.pos
, 0);
16246 /* Not much we can do about it. */
16250 /* Consider the following case: Window starts at BEGV, there is
16251 invisible, intangible text at BEGV, so that display starts at
16252 some point START > BEGV. It can happen that we are called with
16253 PT somewhere between BEGV and START. Try to handle that case. */
16254 if (w
->cursor
.vpos
< 0)
16256 struct glyph_row
*row
= w
->current_matrix
->rows
;
16257 if (row
->mode_line_p
)
16259 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
16262 if (!cursor_row_fully_visible_p (w
, 0, 0))
16264 /* If vscroll is enabled, disable it and try again. */
16268 clear_glyph_matrix (w
->desired_matrix
);
16272 /* Users who set scroll-conservatively to a large number want
16273 point just above/below the scroll margin. If we ended up
16274 with point's row partially visible, move the window start to
16275 make that row fully visible and out of the margin. */
16276 if (scroll_conservatively
> SCROLL_LIMIT
)
16278 int window_total_lines
16279 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) * frame_line_height
;
16282 ? min (scroll_margin
, window_total_lines
/ 4)
16284 int move_down
= w
->cursor
.vpos
>= window_total_lines
/ 2;
16286 move_it_by_lines (&it
, move_down
? margin
+ 1 : -(margin
+ 1));
16287 clear_glyph_matrix (w
->desired_matrix
);
16288 if (1 == try_window (window
, it
.current
.pos
,
16289 TRY_WINDOW_CHECK_MARGINS
))
16293 /* If centering point failed to make the whole line visible,
16294 put point at the top instead. That has to make the whole line
16295 visible, if it can be done. */
16296 if (centering_position
== 0)
16299 clear_glyph_matrix (w
->desired_matrix
);
16300 centering_position
= 0;
16306 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
16307 w
->start_at_line_beg
= (CHARPOS (startp
) == BEGV
16308 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n');
16310 /* Display the mode line, if we must. */
16311 if ((update_mode_line
16312 /* If window not full width, must redo its mode line
16313 if (a) the window to its side is being redone and
16314 (b) we do a frame-based redisplay. This is a consequence
16315 of how inverted lines are drawn in frame-based redisplay. */
16316 || (!just_this_one_p
16317 && !FRAME_WINDOW_P (f
)
16318 && !WINDOW_FULL_WIDTH_P (w
))
16319 /* Line number to display. */
16320 || w
->base_line_pos
> 0
16321 /* Column number is displayed and different from the one displayed. */
16322 || (w
->column_number_displayed
!= -1
16323 && (w
->column_number_displayed
!= current_column ())))
16324 /* This means that the window has a mode line. */
16325 && (WINDOW_WANTS_MODELINE_P (w
)
16326 || WINDOW_WANTS_HEADER_LINE_P (w
)))
16329 display_mode_lines (w
);
16331 /* If mode line height has changed, arrange for a thorough
16332 immediate redisplay using the correct mode line height. */
16333 if (WINDOW_WANTS_MODELINE_P (w
)
16334 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
16336 f
->fonts_changed
= 1;
16337 w
->mode_line_height
= -1;
16338 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
16339 = DESIRED_MODE_LINE_HEIGHT (w
);
16342 /* If header line height has changed, arrange for a thorough
16343 immediate redisplay using the correct header line height. */
16344 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16345 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
16347 f
->fonts_changed
= 1;
16348 w
->header_line_height
= -1;
16349 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
16350 = DESIRED_HEADER_LINE_HEIGHT (w
);
16353 if (f
->fonts_changed
)
16354 goto need_larger_matrices
;
16357 if (!line_number_displayed
&& w
->base_line_pos
!= -1)
16359 w
->base_line_pos
= 0;
16360 w
->base_line_number
= 0;
16365 /* When we reach a frame's selected window, redo the frame's menu bar. */
16366 if (update_mode_line
16367 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
16369 int redisplay_menu_p
= 0;
16371 if (FRAME_WINDOW_P (f
))
16373 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
16374 || defined (HAVE_NS) || defined (USE_GTK)
16375 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
16377 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16381 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16383 if (redisplay_menu_p
)
16384 display_menu_bar (w
);
16386 #ifdef HAVE_WINDOW_SYSTEM
16387 if (FRAME_WINDOW_P (f
))
16389 #if defined (USE_GTK) || defined (HAVE_NS)
16390 if (FRAME_EXTERNAL_TOOL_BAR (f
))
16391 redisplay_tool_bar (f
);
16393 if (WINDOWP (f
->tool_bar_window
)
16394 && (FRAME_TOOL_BAR_HEIGHT (f
) > 0
16395 || !NILP (Vauto_resize_tool_bars
))
16396 && redisplay_tool_bar (f
))
16397 ignore_mouse_drag_p
= 1;
16403 #ifdef HAVE_WINDOW_SYSTEM
16404 if (FRAME_WINDOW_P (f
)
16405 && update_window_fringes (w
, (just_this_one_p
16406 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
16407 || w
->pseudo_window_p
)))
16411 if (draw_window_fringes (w
, 1))
16413 if (WINDOW_RIGHT_DIVIDER_WIDTH (w
))
16414 x_draw_right_divider (w
);
16416 x_draw_vertical_border (w
);
16422 if (WINDOW_BOTTOM_DIVIDER_WIDTH (w
))
16423 x_draw_bottom_divider (w
);
16424 #endif /* HAVE_WINDOW_SYSTEM */
16426 /* We go to this label, with fonts_changed set, if it is
16427 necessary to try again using larger glyph matrices.
16428 We have to redeem the scroll bar even in this case,
16429 because the loop in redisplay_internal expects that. */
16430 need_larger_matrices
:
16432 finish_scroll_bars
:
16434 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
16436 /* Set the thumb's position and size. */
16437 set_vertical_scroll_bar (w
);
16439 /* Note that we actually used the scroll bar attached to this
16440 window, so it shouldn't be deleted at the end of redisplay. */
16441 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
16442 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
16445 /* Restore current_buffer and value of point in it. The window
16446 update may have changed the buffer, so first make sure `opoint'
16447 is still valid (Bug#6177). */
16448 if (CHARPOS (opoint
) < BEGV
)
16449 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
16450 else if (CHARPOS (opoint
) > ZV
)
16451 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
16453 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
16455 set_buffer_internal_1 (old
);
16456 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
16457 shorter. This can be caused by log truncation in *Messages*. */
16458 if (CHARPOS (lpoint
) <= ZV
)
16459 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
16461 unbind_to (count
, Qnil
);
16465 /* Build the complete desired matrix of WINDOW with a window start
16466 buffer position POS.
16468 Value is 1 if successful. It is zero if fonts were loaded during
16469 redisplay which makes re-adjusting glyph matrices necessary, and -1
16470 if point would appear in the scroll margins.
16471 (We check the former only if TRY_WINDOW_IGNORE_FONTS_CHANGE is
16472 unset in FLAGS, and the latter only if TRY_WINDOW_CHECK_MARGINS is
16476 try_window (Lisp_Object window
, struct text_pos pos
, int flags
)
16478 struct window
*w
= XWINDOW (window
);
16480 struct glyph_row
*last_text_row
= NULL
;
16481 struct frame
*f
= XFRAME (w
->frame
);
16482 int frame_line_height
= default_line_pixel_height (w
);
16484 /* Make POS the new window start. */
16485 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
16487 /* Mark cursor position as unknown. No overlay arrow seen. */
16488 w
->cursor
.vpos
= -1;
16489 overlay_arrow_seen
= 0;
16491 /* Initialize iterator and info to start at POS. */
16492 start_display (&it
, w
, pos
);
16494 /* Display all lines of W. */
16495 while (it
.current_y
< it
.last_visible_y
)
16497 if (display_line (&it
))
16498 last_text_row
= it
.glyph_row
- 1;
16499 if (f
->fonts_changed
&& !(flags
& TRY_WINDOW_IGNORE_FONTS_CHANGE
))
16503 /* Don't let the cursor end in the scroll margins. */
16504 if ((flags
& TRY_WINDOW_CHECK_MARGINS
)
16505 && !MINI_WINDOW_P (w
))
16507 int this_scroll_margin
;
16508 int window_total_lines
16509 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
16511 if (scroll_margin
> 0)
16513 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4);
16514 this_scroll_margin
*= frame_line_height
;
16517 this_scroll_margin
= 0;
16519 if ((w
->cursor
.y
>= 0 /* not vscrolled */
16520 && w
->cursor
.y
< this_scroll_margin
16521 && CHARPOS (pos
) > BEGV
16522 && IT_CHARPOS (it
) < ZV
)
16523 /* rms: considering make_cursor_line_fully_visible_p here
16524 seems to give wrong results. We don't want to recenter
16525 when the last line is partly visible, we want to allow
16526 that case to be handled in the usual way. */
16527 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
16529 w
->cursor
.vpos
= -1;
16530 clear_glyph_matrix (w
->desired_matrix
);
16535 /* If bottom moved off end of frame, change mode line percentage. */
16536 if (w
->window_end_pos
<= 0 && Z
!= IT_CHARPOS (it
))
16537 w
->update_mode_line
= 1;
16539 /* Set window_end_pos to the offset of the last character displayed
16540 on the window from the end of current_buffer. Set
16541 window_end_vpos to its row number. */
16544 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
16545 adjust_window_ends (w
, last_text_row
, 0);
16547 (MATRIX_ROW_DISPLAYS_TEXT_P (MATRIX_ROW (w
->desired_matrix
,
16548 w
->window_end_vpos
)));
16552 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16553 w
->window_end_pos
= Z
- ZV
;
16554 w
->window_end_vpos
= 0;
16557 /* But that is not valid info until redisplay finishes. */
16558 w
->window_end_valid
= 0;
16564 /************************************************************************
16565 Window redisplay reusing current matrix when buffer has not changed
16566 ************************************************************************/
16568 /* Try redisplay of window W showing an unchanged buffer with a
16569 different window start than the last time it was displayed by
16570 reusing its current matrix. Value is non-zero if successful.
16571 W->start is the new window start. */
16574 try_window_reusing_current_matrix (struct window
*w
)
16576 struct frame
*f
= XFRAME (w
->frame
);
16577 struct glyph_row
*bottom_row
;
16580 struct text_pos start
, new_start
;
16581 int nrows_scrolled
, i
;
16582 struct glyph_row
*last_text_row
;
16583 struct glyph_row
*last_reused_text_row
;
16584 struct glyph_row
*start_row
;
16585 int start_vpos
, min_y
, max_y
;
16588 if (inhibit_try_window_reusing
)
16592 if (/* This function doesn't handle terminal frames. */
16593 !FRAME_WINDOW_P (f
)
16594 /* Don't try to reuse the display if windows have been split
16596 || windows_or_buffers_changed
16597 || f
->cursor_type_changed
)
16600 /* Can't do this if showing trailing whitespace. */
16601 if (!NILP (Vshow_trailing_whitespace
))
16604 /* If top-line visibility has changed, give up. */
16605 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16606 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
16609 /* Give up if old or new display is scrolled vertically. We could
16610 make this function handle this, but right now it doesn't. */
16611 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16612 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
16615 /* The variable new_start now holds the new window start. The old
16616 start `start' can be determined from the current matrix. */
16617 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
16618 start
= start_row
->minpos
;
16619 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16621 /* Clear the desired matrix for the display below. */
16622 clear_glyph_matrix (w
->desired_matrix
);
16624 if (CHARPOS (new_start
) <= CHARPOS (start
))
16626 /* Don't use this method if the display starts with an ellipsis
16627 displayed for invisible text. It's not easy to handle that case
16628 below, and it's certainly not worth the effort since this is
16629 not a frequent case. */
16630 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
16633 IF_DEBUG (debug_method_add (w
, "twu1"));
16635 /* Display up to a row that can be reused. The variable
16636 last_text_row is set to the last row displayed that displays
16637 text. Note that it.vpos == 0 if or if not there is a
16638 header-line; it's not the same as the MATRIX_ROW_VPOS! */
16639 start_display (&it
, w
, new_start
);
16640 w
->cursor
.vpos
= -1;
16641 last_text_row
= last_reused_text_row
= NULL
;
16643 while (it
.current_y
< it
.last_visible_y
&& !f
->fonts_changed
)
16645 /* If we have reached into the characters in the START row,
16646 that means the line boundaries have changed. So we
16647 can't start copying with the row START. Maybe it will
16648 work to start copying with the following row. */
16649 while (IT_CHARPOS (it
) > CHARPOS (start
))
16651 /* Advance to the next row as the "start". */
16653 start
= start_row
->minpos
;
16654 /* If there are no more rows to try, or just one, give up. */
16655 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
16656 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
16657 || CHARPOS (start
) == ZV
)
16659 clear_glyph_matrix (w
->desired_matrix
);
16663 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16665 /* If we have reached alignment, we can copy the rest of the
16667 if (IT_CHARPOS (it
) == CHARPOS (start
)
16668 /* Don't accept "alignment" inside a display vector,
16669 since start_row could have started in the middle of
16670 that same display vector (thus their character
16671 positions match), and we have no way of telling if
16672 that is the case. */
16673 && it
.current
.dpvec_index
< 0)
16676 if (display_line (&it
))
16677 last_text_row
= it
.glyph_row
- 1;
16681 /* A value of current_y < last_visible_y means that we stopped
16682 at the previous window start, which in turn means that we
16683 have at least one reusable row. */
16684 if (it
.current_y
< it
.last_visible_y
)
16686 struct glyph_row
*row
;
16688 /* IT.vpos always starts from 0; it counts text lines. */
16689 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
16691 /* Find PT if not already found in the lines displayed. */
16692 if (w
->cursor
.vpos
< 0)
16694 int dy
= it
.current_y
- start_row
->y
;
16696 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16697 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
16699 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
16700 dy
, nrows_scrolled
);
16703 clear_glyph_matrix (w
->desired_matrix
);
16708 /* Scroll the display. Do it before the current matrix is
16709 changed. The problem here is that update has not yet
16710 run, i.e. part of the current matrix is not up to date.
16711 scroll_run_hook will clear the cursor, and use the
16712 current matrix to get the height of the row the cursor is
16714 run
.current_y
= start_row
->y
;
16715 run
.desired_y
= it
.current_y
;
16716 run
.height
= it
.last_visible_y
- it
.current_y
;
16718 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
16721 FRAME_RIF (f
)->update_window_begin_hook (w
);
16722 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16723 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16724 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16728 /* Shift current matrix down by nrows_scrolled lines. */
16729 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16730 rotate_matrix (w
->current_matrix
,
16732 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16735 /* Disable lines that must be updated. */
16736 for (i
= 0; i
< nrows_scrolled
; ++i
)
16737 (start_row
+ i
)->enabled_p
= 0;
16739 /* Re-compute Y positions. */
16740 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16741 max_y
= it
.last_visible_y
;
16742 for (row
= start_row
+ nrows_scrolled
;
16746 row
->y
= it
.current_y
;
16747 row
->visible_height
= row
->height
;
16749 if (row
->y
< min_y
)
16750 row
->visible_height
-= min_y
- row
->y
;
16751 if (row
->y
+ row
->height
> max_y
)
16752 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16753 if (row
->fringe_bitmap_periodic_p
)
16754 row
->redraw_fringe_bitmaps_p
= 1;
16756 it
.current_y
+= row
->height
;
16758 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16759 last_reused_text_row
= row
;
16760 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
16764 /* Disable lines in the current matrix which are now
16765 below the window. */
16766 for (++row
; row
< bottom_row
; ++row
)
16767 row
->enabled_p
= row
->mode_line_p
= 0;
16770 /* Update window_end_pos etc.; last_reused_text_row is the last
16771 reused row from the current matrix containing text, if any.
16772 The value of last_text_row is the last displayed line
16773 containing text. */
16774 if (last_reused_text_row
)
16775 adjust_window_ends (w
, last_reused_text_row
, 1);
16776 else if (last_text_row
)
16777 adjust_window_ends (w
, last_text_row
, 0);
16780 /* This window must be completely empty. */
16781 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16782 w
->window_end_pos
= Z
- ZV
;
16783 w
->window_end_vpos
= 0;
16785 w
->window_end_valid
= 0;
16787 /* Update hint: don't try scrolling again in update_window. */
16788 w
->desired_matrix
->no_scrolling_p
= 1;
16791 debug_method_add (w
, "try_window_reusing_current_matrix 1");
16795 else if (CHARPOS (new_start
) > CHARPOS (start
))
16797 struct glyph_row
*pt_row
, *row
;
16798 struct glyph_row
*first_reusable_row
;
16799 struct glyph_row
*first_row_to_display
;
16801 int yb
= window_text_bottom_y (w
);
16803 /* Find the row starting at new_start, if there is one. Don't
16804 reuse a partially visible line at the end. */
16805 first_reusable_row
= start_row
;
16806 while (first_reusable_row
->enabled_p
16807 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
16808 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16809 < CHARPOS (new_start
)))
16810 ++first_reusable_row
;
16812 /* Give up if there is no row to reuse. */
16813 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
16814 || !first_reusable_row
->enabled_p
16815 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16816 != CHARPOS (new_start
)))
16819 /* We can reuse fully visible rows beginning with
16820 first_reusable_row to the end of the window. Set
16821 first_row_to_display to the first row that cannot be reused.
16822 Set pt_row to the row containing point, if there is any. */
16824 for (first_row_to_display
= first_reusable_row
;
16825 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
16826 ++first_row_to_display
)
16828 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
16829 && (PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16830 || (PT
== MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16831 && first_row_to_display
->ends_at_zv_p
16832 && pt_row
== NULL
)))
16833 pt_row
= first_row_to_display
;
16836 /* Start displaying at the start of first_row_to_display. */
16837 eassert (first_row_to_display
->y
< yb
);
16838 init_to_row_start (&it
, w
, first_row_to_display
);
16840 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
16842 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
16844 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
16845 + WINDOW_HEADER_LINE_HEIGHT (w
));
16847 /* Display lines beginning with first_row_to_display in the
16848 desired matrix. Set last_text_row to the last row displayed
16849 that displays text. */
16850 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
16851 if (pt_row
== NULL
)
16852 w
->cursor
.vpos
= -1;
16853 last_text_row
= NULL
;
16854 while (it
.current_y
< it
.last_visible_y
&& !f
->fonts_changed
)
16855 if (display_line (&it
))
16856 last_text_row
= it
.glyph_row
- 1;
16858 /* If point is in a reused row, adjust y and vpos of the cursor
16862 w
->cursor
.vpos
-= nrows_scrolled
;
16863 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
16866 /* Give up if point isn't in a row displayed or reused. (This
16867 also handles the case where w->cursor.vpos < nrows_scrolled
16868 after the calls to display_line, which can happen with scroll
16869 margins. See bug#1295.) */
16870 if (w
->cursor
.vpos
< 0)
16872 clear_glyph_matrix (w
->desired_matrix
);
16876 /* Scroll the display. */
16877 run
.current_y
= first_reusable_row
->y
;
16878 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16879 run
.height
= it
.last_visible_y
- run
.current_y
;
16880 dy
= run
.current_y
- run
.desired_y
;
16885 FRAME_RIF (f
)->update_window_begin_hook (w
);
16886 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16887 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16888 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16892 /* Adjust Y positions of reused rows. */
16893 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16894 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16895 max_y
= it
.last_visible_y
;
16896 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
16899 row
->visible_height
= row
->height
;
16900 if (row
->y
< min_y
)
16901 row
->visible_height
-= min_y
- row
->y
;
16902 if (row
->y
+ row
->height
> max_y
)
16903 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16904 if (row
->fringe_bitmap_periodic_p
)
16905 row
->redraw_fringe_bitmaps_p
= 1;
16908 /* Scroll the current matrix. */
16909 eassert (nrows_scrolled
> 0);
16910 rotate_matrix (w
->current_matrix
,
16912 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16915 /* Disable rows not reused. */
16916 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
16917 row
->enabled_p
= 0;
16919 /* Point may have moved to a different line, so we cannot assume that
16920 the previous cursor position is valid; locate the correct row. */
16923 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
16925 && PT
>= MATRIX_ROW_END_CHARPOS (row
)
16926 && !row
->ends_at_zv_p
;
16930 w
->cursor
.y
= row
->y
;
16932 if (row
< bottom_row
)
16934 /* Can't simply scan the row for point with
16935 bidi-reordered glyph rows. Let set_cursor_from_row
16936 figure out where to put the cursor, and if it fails,
16938 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
16940 if (!set_cursor_from_row (w
, row
, w
->current_matrix
,
16943 clear_glyph_matrix (w
->desired_matrix
);
16949 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
16950 struct glyph
*end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16953 && (!BUFFERP (glyph
->object
)
16954 || glyph
->charpos
< PT
);
16958 w
->cursor
.x
+= glyph
->pixel_width
;
16964 /* Adjust window end. A null value of last_text_row means that
16965 the window end is in reused rows which in turn means that
16966 only its vpos can have changed. */
16968 adjust_window_ends (w
, last_text_row
, 0);
16970 w
->window_end_vpos
-= nrows_scrolled
;
16972 w
->window_end_valid
= 0;
16973 w
->desired_matrix
->no_scrolling_p
= 1;
16976 debug_method_add (w
, "try_window_reusing_current_matrix 2");
16986 /************************************************************************
16987 Window redisplay reusing current matrix when buffer has changed
16988 ************************************************************************/
16990 static struct glyph_row
*find_last_unchanged_at_beg_row (struct window
*);
16991 static struct glyph_row
*find_first_unchanged_at_end_row (struct window
*,
16992 ptrdiff_t *, ptrdiff_t *);
16993 static struct glyph_row
*
16994 find_last_row_displaying_text (struct glyph_matrix
*, struct it
*,
16995 struct glyph_row
*);
16998 /* Return the last row in MATRIX displaying text. If row START is
16999 non-null, start searching with that row. IT gives the dimensions
17000 of the display. Value is null if matrix is empty; otherwise it is
17001 a pointer to the row found. */
17003 static struct glyph_row
*
17004 find_last_row_displaying_text (struct glyph_matrix
*matrix
, struct it
*it
,
17005 struct glyph_row
*start
)
17007 struct glyph_row
*row
, *row_found
;
17009 /* Set row_found to the last row in IT->w's current matrix
17010 displaying text. The loop looks funny but think of partially
17013 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
17014 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
17016 eassert (row
->enabled_p
);
17018 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
17027 /* Return the last row in the current matrix of W that is not affected
17028 by changes at the start of current_buffer that occurred since W's
17029 current matrix was built. Value is null if no such row exists.
17031 BEG_UNCHANGED us the number of characters unchanged at the start of
17032 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
17033 first changed character in current_buffer. Characters at positions <
17034 BEG + BEG_UNCHANGED are at the same buffer positions as they were
17035 when the current matrix was built. */
17037 static struct glyph_row
*
17038 find_last_unchanged_at_beg_row (struct window
*w
)
17040 ptrdiff_t first_changed_pos
= BEG
+ BEG_UNCHANGED
;
17041 struct glyph_row
*row
;
17042 struct glyph_row
*row_found
= NULL
;
17043 int yb
= window_text_bottom_y (w
);
17045 /* Find the last row displaying unchanged text. */
17046 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
17047 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
17048 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
17051 if (/* If row ends before first_changed_pos, it is unchanged,
17052 except in some case. */
17053 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
17054 /* When row ends in ZV and we write at ZV it is not
17056 && !row
->ends_at_zv_p
17057 /* When first_changed_pos is the end of a continued line,
17058 row is not unchanged because it may be no longer
17060 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
17061 && (row
->continued_p
17062 || row
->exact_window_width_line_p
))
17063 /* If ROW->end is beyond ZV, then ROW->end is outdated and
17064 needs to be recomputed, so don't consider this row as
17065 unchanged. This happens when the last line was
17066 bidi-reordered and was killed immediately before this
17067 redisplay cycle. In that case, ROW->end stores the
17068 buffer position of the first visual-order character of
17069 the killed text, which is now beyond ZV. */
17070 && CHARPOS (row
->end
.pos
) <= ZV
)
17073 /* Stop if last visible row. */
17074 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
17082 /* Find the first glyph row in the current matrix of W that is not
17083 affected by changes at the end of current_buffer since the
17084 time W's current matrix was built.
17086 Return in *DELTA the number of chars by which buffer positions in
17087 unchanged text at the end of current_buffer must be adjusted.
17089 Return in *DELTA_BYTES the corresponding number of bytes.
17091 Value is null if no such row exists, i.e. all rows are affected by
17094 static struct glyph_row
*
17095 find_first_unchanged_at_end_row (struct window
*w
,
17096 ptrdiff_t *delta
, ptrdiff_t *delta_bytes
)
17098 struct glyph_row
*row
;
17099 struct glyph_row
*row_found
= NULL
;
17101 *delta
= *delta_bytes
= 0;
17103 /* Display must not have been paused, otherwise the current matrix
17104 is not up to date. */
17105 eassert (w
->window_end_valid
);
17107 /* A value of window_end_pos >= END_UNCHANGED means that the window
17108 end is in the range of changed text. If so, there is no
17109 unchanged row at the end of W's current matrix. */
17110 if (w
->window_end_pos
>= END_UNCHANGED
)
17113 /* Set row to the last row in W's current matrix displaying text. */
17114 row
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
17116 /* If matrix is entirely empty, no unchanged row exists. */
17117 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
17119 /* The value of row is the last glyph row in the matrix having a
17120 meaningful buffer position in it. The end position of row
17121 corresponds to window_end_pos. This allows us to translate
17122 buffer positions in the current matrix to current buffer
17123 positions for characters not in changed text. */
17125 MATRIX_ROW_END_CHARPOS (row
) + w
->window_end_pos
;
17126 ptrdiff_t Z_BYTE_old
=
17127 MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
17128 ptrdiff_t last_unchanged_pos
, last_unchanged_pos_old
;
17129 struct glyph_row
*first_text_row
17130 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
17132 *delta
= Z
- Z_old
;
17133 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
17135 /* Set last_unchanged_pos to the buffer position of the last
17136 character in the buffer that has not been changed. Z is the
17137 index + 1 of the last character in current_buffer, i.e. by
17138 subtracting END_UNCHANGED we get the index of the last
17139 unchanged character, and we have to add BEG to get its buffer
17141 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
17142 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
17144 /* Search backward from ROW for a row displaying a line that
17145 starts at a minimum position >= last_unchanged_pos_old. */
17146 for (; row
> first_text_row
; --row
)
17148 /* This used to abort, but it can happen.
17149 It is ok to just stop the search instead here. KFS. */
17150 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
17153 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
17158 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
17164 /* Make sure that glyph rows in the current matrix of window W
17165 reference the same glyph memory as corresponding rows in the
17166 frame's frame matrix. This function is called after scrolling W's
17167 current matrix on a terminal frame in try_window_id and
17168 try_window_reusing_current_matrix. */
17171 sync_frame_with_window_matrix_rows (struct window
*w
)
17173 struct frame
*f
= XFRAME (w
->frame
);
17174 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
17176 /* Preconditions: W must be a leaf window and full-width. Its frame
17177 must have a frame matrix. */
17178 eassert (BUFFERP (w
->contents
));
17179 eassert (WINDOW_FULL_WIDTH_P (w
));
17180 eassert (!FRAME_WINDOW_P (f
));
17182 /* If W is a full-width window, glyph pointers in W's current matrix
17183 have, by definition, to be the same as glyph pointers in the
17184 corresponding frame matrix. Note that frame matrices have no
17185 marginal areas (see build_frame_matrix). */
17186 window_row
= w
->current_matrix
->rows
;
17187 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
17188 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
17189 while (window_row
< window_row_end
)
17191 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
17192 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
17194 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
17195 frame_row
->glyphs
[TEXT_AREA
] = start
;
17196 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
17197 frame_row
->glyphs
[LAST_AREA
] = end
;
17199 /* Disable frame rows whose corresponding window rows have
17200 been disabled in try_window_id. */
17201 if (!window_row
->enabled_p
)
17202 frame_row
->enabled_p
= 0;
17204 ++window_row
, ++frame_row
;
17209 /* Find the glyph row in window W containing CHARPOS. Consider all
17210 rows between START and END (not inclusive). END null means search
17211 all rows to the end of the display area of W. Value is the row
17212 containing CHARPOS or null. */
17215 row_containing_pos (struct window
*w
, ptrdiff_t charpos
,
17216 struct glyph_row
*start
, struct glyph_row
*end
, int dy
)
17218 struct glyph_row
*row
= start
;
17219 struct glyph_row
*best_row
= NULL
;
17220 ptrdiff_t mindif
= BUF_ZV (XBUFFER (w
->contents
)) + 1;
17223 /* If we happen to start on a header-line, skip that. */
17224 if (row
->mode_line_p
)
17227 if ((end
&& row
>= end
) || !row
->enabled_p
)
17230 last_y
= window_text_bottom_y (w
) - dy
;
17234 /* Give up if we have gone too far. */
17235 if (end
&& row
>= end
)
17237 /* This formerly returned if they were equal.
17238 I think that both quantities are of a "last plus one" type;
17239 if so, when they are equal, the row is within the screen. -- rms. */
17240 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
17243 /* If it is in this row, return this row. */
17244 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
17245 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
17246 /* The end position of a row equals the start
17247 position of the next row. If CHARPOS is there, we
17248 would rather consider it displayed in the next
17249 line, except when this line ends in ZV. */
17250 && !row_for_charpos_p (row
, charpos
)))
17251 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
17255 if (NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
17256 || (!best_row
&& !row
->continued_p
))
17258 /* In bidi-reordered rows, there could be several rows whose
17259 edges surround CHARPOS, all of these rows belonging to
17260 the same continued line. We need to find the row which
17261 fits CHARPOS the best. */
17262 for (g
= row
->glyphs
[TEXT_AREA
];
17263 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
17266 if (!STRINGP (g
->object
))
17268 if (g
->charpos
> 0 && eabs (g
->charpos
- charpos
) < mindif
)
17270 mindif
= eabs (g
->charpos
- charpos
);
17272 /* Exact match always wins. */
17279 else if (best_row
&& !row
->continued_p
)
17286 /* Try to redisplay window W by reusing its existing display. W's
17287 current matrix must be up to date when this function is called,
17288 i.e. window_end_valid must be nonzero.
17292 1 if display has been updated
17293 0 if otherwise unsuccessful
17294 -1 if redisplay with same window start is known not to succeed
17296 The following steps are performed:
17298 1. Find the last row in the current matrix of W that is not
17299 affected by changes at the start of current_buffer. If no such row
17302 2. Find the first row in W's current matrix that is not affected by
17303 changes at the end of current_buffer. Maybe there is no such row.
17305 3. Display lines beginning with the row + 1 found in step 1 to the
17306 row found in step 2 or, if step 2 didn't find a row, to the end of
17309 4. If cursor is not known to appear on the window, give up.
17311 5. If display stopped at the row found in step 2, scroll the
17312 display and current matrix as needed.
17314 6. Maybe display some lines at the end of W, if we must. This can
17315 happen under various circumstances, like a partially visible line
17316 becoming fully visible, or because newly displayed lines are displayed
17317 in smaller font sizes.
17319 7. Update W's window end information. */
17322 try_window_id (struct window
*w
)
17324 struct frame
*f
= XFRAME (w
->frame
);
17325 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
17326 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
17327 struct glyph_row
*last_unchanged_at_beg_row
;
17328 struct glyph_row
*first_unchanged_at_end_row
;
17329 struct glyph_row
*row
;
17330 struct glyph_row
*bottom_row
;
17333 ptrdiff_t delta
= 0, delta_bytes
= 0, stop_pos
;
17335 struct text_pos start_pos
;
17337 int first_unchanged_at_end_vpos
= 0;
17338 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
17339 struct text_pos start
;
17340 ptrdiff_t first_changed_charpos
, last_changed_charpos
;
17343 if (inhibit_try_window_id
)
17347 /* This is handy for debugging. */
17349 #define GIVE_UP(X) \
17351 fprintf (stderr, "try_window_id give up %d\n", (X)); \
17355 #define GIVE_UP(X) return 0
17358 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
17360 /* Don't use this for mini-windows because these can show
17361 messages and mini-buffers, and we don't handle that here. */
17362 if (MINI_WINDOW_P (w
))
17365 /* This flag is used to prevent redisplay optimizations. */
17366 if (windows_or_buffers_changed
|| f
->cursor_type_changed
)
17369 /* Verify that narrowing has not changed.
17370 Also verify that we were not told to prevent redisplay optimizations.
17371 It would be nice to further
17372 reduce the number of cases where this prevents try_window_id. */
17373 if (current_buffer
->clip_changed
17374 || current_buffer
->prevent_redisplay_optimizations_p
)
17377 /* Window must either use window-based redisplay or be full width. */
17378 if (!FRAME_WINDOW_P (f
)
17379 && (!FRAME_LINE_INS_DEL_OK (f
)
17380 || !WINDOW_FULL_WIDTH_P (w
)))
17383 /* Give up if point is known NOT to appear in W. */
17384 if (PT
< CHARPOS (start
))
17387 /* Another way to prevent redisplay optimizations. */
17388 if (w
->last_modified
== 0)
17391 /* Verify that window is not hscrolled. */
17392 if (w
->hscroll
!= 0)
17395 /* Verify that display wasn't paused. */
17396 if (!w
->window_end_valid
)
17399 /* Likewise if highlighting trailing whitespace. */
17400 if (!NILP (Vshow_trailing_whitespace
))
17403 /* Can't use this if overlay arrow position and/or string have
17405 if (overlay_arrows_changed_p ())
17408 /* When word-wrap is on, adding a space to the first word of a
17409 wrapped line can change the wrap position, altering the line
17410 above it. It might be worthwhile to handle this more
17411 intelligently, but for now just redisplay from scratch. */
17412 if (!NILP (BVAR (XBUFFER (w
->contents
), word_wrap
)))
17415 /* Under bidi reordering, adding or deleting a character in the
17416 beginning of a paragraph, before the first strong directional
17417 character, can change the base direction of the paragraph (unless
17418 the buffer specifies a fixed paragraph direction), which will
17419 require to redisplay the whole paragraph. It might be worthwhile
17420 to find the paragraph limits and widen the range of redisplayed
17421 lines to that, but for now just give up this optimization and
17422 redisplay from scratch. */
17423 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
17424 && NILP (BVAR (XBUFFER (w
->contents
), bidi_paragraph_direction
)))
17427 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
17428 only if buffer has really changed. The reason is that the gap is
17429 initially at Z for freshly visited files. The code below would
17430 set end_unchanged to 0 in that case. */
17431 if (MODIFF
> SAVE_MODIFF
17432 /* This seems to happen sometimes after saving a buffer. */
17433 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
17435 if (GPT
- BEG
< BEG_UNCHANGED
)
17436 BEG_UNCHANGED
= GPT
- BEG
;
17437 if (Z
- GPT
< END_UNCHANGED
)
17438 END_UNCHANGED
= Z
- GPT
;
17441 /* The position of the first and last character that has been changed. */
17442 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
17443 last_changed_charpos
= Z
- END_UNCHANGED
;
17445 /* If window starts after a line end, and the last change is in
17446 front of that newline, then changes don't affect the display.
17447 This case happens with stealth-fontification. Note that although
17448 the display is unchanged, glyph positions in the matrix have to
17449 be adjusted, of course. */
17450 row
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
17451 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
17452 && ((last_changed_charpos
< CHARPOS (start
)
17453 && CHARPOS (start
) == BEGV
)
17454 || (last_changed_charpos
< CHARPOS (start
) - 1
17455 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
17457 ptrdiff_t Z_old
, Z_delta
, Z_BYTE_old
, Z_delta_bytes
;
17458 struct glyph_row
*r0
;
17460 /* Compute how many chars/bytes have been added to or removed
17461 from the buffer. */
17462 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + w
->window_end_pos
;
17463 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
17464 Z_delta
= Z
- Z_old
;
17465 Z_delta_bytes
= Z_BYTE
- Z_BYTE_old
;
17467 /* Give up if PT is not in the window. Note that it already has
17468 been checked at the start of try_window_id that PT is not in
17469 front of the window start. */
17470 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + Z_delta
)
17473 /* If window start is unchanged, we can reuse the whole matrix
17474 as is, after adjusting glyph positions. No need to compute
17475 the window end again, since its offset from Z hasn't changed. */
17476 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17477 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + Z_delta
17478 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + Z_delta_bytes
17479 /* PT must not be in a partially visible line. */
17480 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + Z_delta
17481 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17483 /* Adjust positions in the glyph matrix. */
17484 if (Z_delta
|| Z_delta_bytes
)
17486 struct glyph_row
*r1
17487 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17488 increment_matrix_positions (w
->current_matrix
,
17489 MATRIX_ROW_VPOS (r0
, current_matrix
),
17490 MATRIX_ROW_VPOS (r1
, current_matrix
),
17491 Z_delta
, Z_delta_bytes
);
17494 /* Set the cursor. */
17495 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17497 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17502 /* Handle the case that changes are all below what is displayed in
17503 the window, and that PT is in the window. This shortcut cannot
17504 be taken if ZV is visible in the window, and text has been added
17505 there that is visible in the window. */
17506 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
17507 /* ZV is not visible in the window, or there are no
17508 changes at ZV, actually. */
17509 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
17510 || first_changed_charpos
== last_changed_charpos
))
17512 struct glyph_row
*r0
;
17514 /* Give up if PT is not in the window. Note that it already has
17515 been checked at the start of try_window_id that PT is not in
17516 front of the window start. */
17517 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
17520 /* If window start is unchanged, we can reuse the whole matrix
17521 as is, without changing glyph positions since no text has
17522 been added/removed in front of the window end. */
17523 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17524 if (TEXT_POS_EQUAL_P (start
, r0
->minpos
)
17525 /* PT must not be in a partially visible line. */
17526 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
17527 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17529 /* We have to compute the window end anew since text
17530 could have been added/removed after it. */
17531 w
->window_end_pos
= Z
- MATRIX_ROW_END_CHARPOS (row
);
17532 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17534 /* Set the cursor. */
17535 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17537 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17542 /* Give up if window start is in the changed area.
17544 The condition used to read
17546 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
17548 but why that was tested escapes me at the moment. */
17549 if (CHARPOS (start
) >= first_changed_charpos
17550 && CHARPOS (start
) <= last_changed_charpos
)
17553 /* Check that window start agrees with the start of the first glyph
17554 row in its current matrix. Check this after we know the window
17555 start is not in changed text, otherwise positions would not be
17557 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17558 if (!TEXT_POS_EQUAL_P (start
, row
->minpos
))
17561 /* Give up if the window ends in strings. Overlay strings
17562 at the end are difficult to handle, so don't try. */
17563 row
= MATRIX_ROW (current_matrix
, w
->window_end_vpos
);
17564 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
17567 /* Compute the position at which we have to start displaying new
17568 lines. Some of the lines at the top of the window might be
17569 reusable because they are not displaying changed text. Find the
17570 last row in W's current matrix not affected by changes at the
17571 start of current_buffer. Value is null if changes start in the
17572 first line of window. */
17573 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
17574 if (last_unchanged_at_beg_row
)
17576 /* Avoid starting to display in the middle of a character, a TAB
17577 for instance. This is easier than to set up the iterator
17578 exactly, and it's not a frequent case, so the additional
17579 effort wouldn't really pay off. */
17580 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
17581 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
17582 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
17583 --last_unchanged_at_beg_row
;
17585 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
17588 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
17590 start_pos
= it
.current
.pos
;
17592 /* Start displaying new lines in the desired matrix at the same
17593 vpos we would use in the current matrix, i.e. below
17594 last_unchanged_at_beg_row. */
17595 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
17597 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17598 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
17600 eassert (it
.hpos
== 0 && it
.current_x
== 0);
17604 /* There are no reusable lines at the start of the window.
17605 Start displaying in the first text line. */
17606 start_display (&it
, w
, start
);
17607 it
.vpos
= it
.first_vpos
;
17608 start_pos
= it
.current
.pos
;
17611 /* Find the first row that is not affected by changes at the end of
17612 the buffer. Value will be null if there is no unchanged row, in
17613 which case we must redisplay to the end of the window. delta
17614 will be set to the value by which buffer positions beginning with
17615 first_unchanged_at_end_row have to be adjusted due to text
17617 first_unchanged_at_end_row
17618 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
17619 IF_DEBUG (debug_delta
= delta
);
17620 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
17622 /* Set stop_pos to the buffer position up to which we will have to
17623 display new lines. If first_unchanged_at_end_row != NULL, this
17624 is the buffer position of the start of the line displayed in that
17625 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
17626 that we don't stop at a buffer position. */
17628 if (first_unchanged_at_end_row
)
17630 eassert (last_unchanged_at_beg_row
== NULL
17631 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
17633 /* If this is a continuation line, move forward to the next one
17634 that isn't. Changes in lines above affect this line.
17635 Caution: this may move first_unchanged_at_end_row to a row
17636 not displaying text. */
17637 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
17638 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17639 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17640 < it
.last_visible_y
))
17641 ++first_unchanged_at_end_row
;
17643 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17644 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17645 >= it
.last_visible_y
))
17646 first_unchanged_at_end_row
= NULL
;
17649 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
17651 first_unchanged_at_end_vpos
17652 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
17653 eassert (stop_pos
>= Z
- END_UNCHANGED
);
17656 else if (last_unchanged_at_beg_row
== NULL
)
17662 /* Either there is no unchanged row at the end, or the one we have
17663 now displays text. This is a necessary condition for the window
17664 end pos calculation at the end of this function. */
17665 eassert (first_unchanged_at_end_row
== NULL
17666 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
17668 debug_last_unchanged_at_beg_vpos
17669 = (last_unchanged_at_beg_row
17670 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
17672 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
17674 #endif /* GLYPH_DEBUG */
17677 /* Display new lines. Set last_text_row to the last new line
17678 displayed which has text on it, i.e. might end up as being the
17679 line where the window_end_vpos is. */
17680 w
->cursor
.vpos
= -1;
17681 last_text_row
= NULL
;
17682 overlay_arrow_seen
= 0;
17683 while (it
.current_y
< it
.last_visible_y
17684 && !f
->fonts_changed
17685 && (first_unchanged_at_end_row
== NULL
17686 || IT_CHARPOS (it
) < stop_pos
))
17688 if (display_line (&it
))
17689 last_text_row
= it
.glyph_row
- 1;
17692 if (f
->fonts_changed
)
17696 /* Compute differences in buffer positions, y-positions etc. for
17697 lines reused at the bottom of the window. Compute what we can
17699 if (first_unchanged_at_end_row
17700 /* No lines reused because we displayed everything up to the
17701 bottom of the window. */
17702 && it
.current_y
< it
.last_visible_y
)
17705 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
17707 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
17708 run
.current_y
= first_unchanged_at_end_row
->y
;
17709 run
.desired_y
= run
.current_y
+ dy
;
17710 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
17714 delta
= delta_bytes
= dvpos
= dy
17715 = run
.current_y
= run
.desired_y
= run
.height
= 0;
17716 first_unchanged_at_end_row
= NULL
;
17718 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
17721 /* Find the cursor if not already found. We have to decide whether
17722 PT will appear on this window (it sometimes doesn't, but this is
17723 not a very frequent case.) This decision has to be made before
17724 the current matrix is altered. A value of cursor.vpos < 0 means
17725 that PT is either in one of the lines beginning at
17726 first_unchanged_at_end_row or below the window. Don't care for
17727 lines that might be displayed later at the window end; as
17728 mentioned, this is not a frequent case. */
17729 if (w
->cursor
.vpos
< 0)
17731 /* Cursor in unchanged rows at the top? */
17732 if (PT
< CHARPOS (start_pos
)
17733 && last_unchanged_at_beg_row
)
17735 row
= row_containing_pos (w
, PT
,
17736 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
17737 last_unchanged_at_beg_row
+ 1, 0);
17739 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
17742 /* Start from first_unchanged_at_end_row looking for PT. */
17743 else if (first_unchanged_at_end_row
)
17745 row
= row_containing_pos (w
, PT
- delta
,
17746 first_unchanged_at_end_row
, NULL
, 0);
17748 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
17749 delta_bytes
, dy
, dvpos
);
17752 /* Give up if cursor was not found. */
17753 if (w
->cursor
.vpos
< 0)
17755 clear_glyph_matrix (w
->desired_matrix
);
17760 /* Don't let the cursor end in the scroll margins. */
17762 int this_scroll_margin
, cursor_height
;
17763 int frame_line_height
= default_line_pixel_height (w
);
17764 int window_total_lines
17765 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (it
.f
) / frame_line_height
;
17767 this_scroll_margin
=
17768 max (0, min (scroll_margin
, window_total_lines
/ 4));
17769 this_scroll_margin
*= frame_line_height
;
17770 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
17772 if ((w
->cursor
.y
< this_scroll_margin
17773 && CHARPOS (start
) > BEGV
)
17774 /* Old redisplay didn't take scroll margin into account at the bottom,
17775 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
17776 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
17777 ? cursor_height
+ this_scroll_margin
17778 : 1)) > it
.last_visible_y
)
17780 w
->cursor
.vpos
= -1;
17781 clear_glyph_matrix (w
->desired_matrix
);
17786 /* Scroll the display. Do it before changing the current matrix so
17787 that xterm.c doesn't get confused about where the cursor glyph is
17789 if (dy
&& run
.height
)
17793 if (FRAME_WINDOW_P (f
))
17795 FRAME_RIF (f
)->update_window_begin_hook (w
);
17796 FRAME_RIF (f
)->clear_window_mouse_face (w
);
17797 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
17798 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
17802 /* Terminal frame. In this case, dvpos gives the number of
17803 lines to scroll by; dvpos < 0 means scroll up. */
17805 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
17806 int from
= WINDOW_TOP_EDGE_LINE (w
) + from_vpos
;
17807 int end
= (WINDOW_TOP_EDGE_LINE (w
)
17808 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
17809 + window_internal_height (w
));
17811 #if defined (HAVE_GPM) || defined (MSDOS)
17812 x_clear_window_mouse_face (w
);
17814 /* Perform the operation on the screen. */
17817 /* Scroll last_unchanged_at_beg_row to the end of the
17818 window down dvpos lines. */
17819 set_terminal_window (f
, end
);
17821 /* On dumb terminals delete dvpos lines at the end
17822 before inserting dvpos empty lines. */
17823 if (!FRAME_SCROLL_REGION_OK (f
))
17824 ins_del_lines (f
, end
- dvpos
, -dvpos
);
17826 /* Insert dvpos empty lines in front of
17827 last_unchanged_at_beg_row. */
17828 ins_del_lines (f
, from
, dvpos
);
17830 else if (dvpos
< 0)
17832 /* Scroll up last_unchanged_at_beg_vpos to the end of
17833 the window to last_unchanged_at_beg_vpos - |dvpos|. */
17834 set_terminal_window (f
, end
);
17836 /* Delete dvpos lines in front of
17837 last_unchanged_at_beg_vpos. ins_del_lines will set
17838 the cursor to the given vpos and emit |dvpos| delete
17840 ins_del_lines (f
, from
+ dvpos
, dvpos
);
17842 /* On a dumb terminal insert dvpos empty lines at the
17844 if (!FRAME_SCROLL_REGION_OK (f
))
17845 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
17848 set_terminal_window (f
, 0);
17854 /* Shift reused rows of the current matrix to the right position.
17855 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
17857 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17858 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
17861 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
17862 bottom_vpos
, dvpos
);
17863 clear_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
17866 else if (dvpos
> 0)
17868 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
17869 bottom_vpos
, dvpos
);
17870 clear_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
17871 first_unchanged_at_end_vpos
+ dvpos
);
17874 /* For frame-based redisplay, make sure that current frame and window
17875 matrix are in sync with respect to glyph memory. */
17876 if (!FRAME_WINDOW_P (f
))
17877 sync_frame_with_window_matrix_rows (w
);
17879 /* Adjust buffer positions in reused rows. */
17880 if (delta
|| delta_bytes
)
17881 increment_matrix_positions (current_matrix
,
17882 first_unchanged_at_end_vpos
+ dvpos
,
17883 bottom_vpos
, delta
, delta_bytes
);
17885 /* Adjust Y positions. */
17887 shift_glyph_matrix (w
, current_matrix
,
17888 first_unchanged_at_end_vpos
+ dvpos
,
17891 if (first_unchanged_at_end_row
)
17893 first_unchanged_at_end_row
+= dvpos
;
17894 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
17895 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
17896 first_unchanged_at_end_row
= NULL
;
17899 /* If scrolling up, there may be some lines to display at the end of
17901 last_text_row_at_end
= NULL
;
17904 /* Scrolling up can leave for example a partially visible line
17905 at the end of the window to be redisplayed. */
17906 /* Set last_row to the glyph row in the current matrix where the
17907 window end line is found. It has been moved up or down in
17908 the matrix by dvpos. */
17909 int last_vpos
= w
->window_end_vpos
+ dvpos
;
17910 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
17912 /* If last_row is the window end line, it should display text. */
17913 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_row
));
17915 /* If window end line was partially visible before, begin
17916 displaying at that line. Otherwise begin displaying with the
17917 line following it. */
17918 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
17920 init_to_row_start (&it
, w
, last_row
);
17921 it
.vpos
= last_vpos
;
17922 it
.current_y
= last_row
->y
;
17926 init_to_row_end (&it
, w
, last_row
);
17927 it
.vpos
= 1 + last_vpos
;
17928 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
17932 /* We may start in a continuation line. If so, we have to
17933 get the right continuation_lines_width and current_x. */
17934 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
17935 it
.hpos
= it
.current_x
= 0;
17937 /* Display the rest of the lines at the window end. */
17938 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17939 while (it
.current_y
< it
.last_visible_y
&& !f
->fonts_changed
)
17941 /* Is it always sure that the display agrees with lines in
17942 the current matrix? I don't think so, so we mark rows
17943 displayed invalid in the current matrix by setting their
17944 enabled_p flag to zero. */
17945 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
17946 if (display_line (&it
))
17947 last_text_row_at_end
= it
.glyph_row
- 1;
17951 /* Update window_end_pos and window_end_vpos. */
17952 if (first_unchanged_at_end_row
&& !last_text_row_at_end
)
17954 /* Window end line if one of the preserved rows from the current
17955 matrix. Set row to the last row displaying text in current
17956 matrix starting at first_unchanged_at_end_row, after
17958 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
17959 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
17960 first_unchanged_at_end_row
);
17961 eassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
17962 adjust_window_ends (w
, row
, 1);
17963 eassert (w
->window_end_bytepos
>= 0);
17964 IF_DEBUG (debug_method_add (w
, "A"));
17966 else if (last_text_row_at_end
)
17968 adjust_window_ends (w
, last_text_row_at_end
, 0);
17969 eassert (w
->window_end_bytepos
>= 0);
17970 IF_DEBUG (debug_method_add (w
, "B"));
17972 else if (last_text_row
)
17974 /* We have displayed either to the end of the window or at the
17975 end of the window, i.e. the last row with text is to be found
17976 in the desired matrix. */
17977 adjust_window_ends (w
, last_text_row
, 0);
17978 eassert (w
->window_end_bytepos
>= 0);
17980 else if (first_unchanged_at_end_row
== NULL
17981 && last_text_row
== NULL
17982 && last_text_row_at_end
== NULL
)
17984 /* Displayed to end of window, but no line containing text was
17985 displayed. Lines were deleted at the end of the window. */
17986 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
17987 int vpos
= w
->window_end_vpos
;
17988 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
17989 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
17992 row
== NULL
&& vpos
>= first_vpos
;
17993 --vpos
, --current_row
, --desired_row
)
17995 if (desired_row
->enabled_p
)
17997 if (MATRIX_ROW_DISPLAYS_TEXT_P (desired_row
))
18000 else if (MATRIX_ROW_DISPLAYS_TEXT_P (current_row
))
18004 eassert (row
!= NULL
);
18005 w
->window_end_vpos
= vpos
+ 1;
18006 w
->window_end_pos
= Z
- MATRIX_ROW_END_CHARPOS (row
);
18007 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
18008 eassert (w
->window_end_bytepos
>= 0);
18009 IF_DEBUG (debug_method_add (w
, "C"));
18014 IF_DEBUG (debug_end_pos
= w
->window_end_pos
;
18015 debug_end_vpos
= w
->window_end_vpos
);
18017 /* Record that display has not been completed. */
18018 w
->window_end_valid
= 0;
18019 w
->desired_matrix
->no_scrolling_p
= 1;
18027 /***********************************************************************
18028 More debugging support
18029 ***********************************************************************/
18033 void dump_glyph_row (struct glyph_row
*, int, int) EXTERNALLY_VISIBLE
;
18034 void dump_glyph_matrix (struct glyph_matrix
*, int) EXTERNALLY_VISIBLE
;
18035 void dump_glyph (struct glyph_row
*, struct glyph
*, int) EXTERNALLY_VISIBLE
;
18038 /* Dump the contents of glyph matrix MATRIX on stderr.
18040 GLYPHS 0 means don't show glyph contents.
18041 GLYPHS 1 means show glyphs in short form
18042 GLYPHS > 1 means show glyphs in long form. */
18045 dump_glyph_matrix (struct glyph_matrix
*matrix
, int glyphs
)
18048 for (i
= 0; i
< matrix
->nrows
; ++i
)
18049 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
18053 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
18054 the glyph row and area where the glyph comes from. */
18057 dump_glyph (struct glyph_row
*row
, struct glyph
*glyph
, int area
)
18059 if (glyph
->type
== CHAR_GLYPH
18060 || glyph
->type
== GLYPHLESS_GLYPH
)
18063 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
18064 glyph
- row
->glyphs
[TEXT_AREA
],
18065 (glyph
->type
== CHAR_GLYPH
18069 (BUFFERP (glyph
->object
)
18071 : (STRINGP (glyph
->object
)
18073 : (INTEGERP (glyph
->object
)
18076 glyph
->pixel_width
,
18078 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
18082 glyph
->left_box_line_p
,
18083 glyph
->right_box_line_p
);
18085 else if (glyph
->type
== STRETCH_GLYPH
)
18088 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
18089 glyph
- row
->glyphs
[TEXT_AREA
],
18092 (BUFFERP (glyph
->object
)
18094 : (STRINGP (glyph
->object
)
18096 : (INTEGERP (glyph
->object
)
18099 glyph
->pixel_width
,
18103 glyph
->left_box_line_p
,
18104 glyph
->right_box_line_p
);
18106 else if (glyph
->type
== IMAGE_GLYPH
)
18109 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
18110 glyph
- row
->glyphs
[TEXT_AREA
],
18113 (BUFFERP (glyph
->object
)
18115 : (STRINGP (glyph
->object
)
18117 : (INTEGERP (glyph
->object
)
18120 glyph
->pixel_width
,
18124 glyph
->left_box_line_p
,
18125 glyph
->right_box_line_p
);
18127 else if (glyph
->type
== COMPOSITE_GLYPH
)
18130 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x",
18131 glyph
- row
->glyphs
[TEXT_AREA
],
18134 (BUFFERP (glyph
->object
)
18136 : (STRINGP (glyph
->object
)
18138 : (INTEGERP (glyph
->object
)
18141 glyph
->pixel_width
,
18143 if (glyph
->u
.cmp
.automatic
)
18146 glyph
->slice
.cmp
.from
, glyph
->slice
.cmp
.to
);
18147 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
18149 glyph
->left_box_line_p
,
18150 glyph
->right_box_line_p
);
18155 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
18156 GLYPHS 0 means don't show glyph contents.
18157 GLYPHS 1 means show glyphs in short form
18158 GLYPHS > 1 means show glyphs in long form. */
18161 dump_glyph_row (struct glyph_row
*row
, int vpos
, int glyphs
)
18165 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
18166 fprintf (stderr
, "==============================================================================\n");
18168 fprintf (stderr
, "%3d %9"pI
"d %9"pI
"d %4d %1.1d%1.1d%1.1d%1.1d\
18169 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
18171 MATRIX_ROW_START_CHARPOS (row
),
18172 MATRIX_ROW_END_CHARPOS (row
),
18173 row
->used
[TEXT_AREA
],
18174 row
->contains_overlapping_glyphs_p
,
18176 row
->truncated_on_left_p
,
18177 row
->truncated_on_right_p
,
18179 MATRIX_ROW_CONTINUATION_LINE_P (row
),
18180 MATRIX_ROW_DISPLAYS_TEXT_P (row
),
18183 row
->ends_in_middle_of_char_p
,
18184 row
->starts_in_middle_of_char_p
,
18190 row
->visible_height
,
18193 /* The next 3 lines should align to "Start" in the header. */
18194 fprintf (stderr
, " %9"pD
"d %9"pD
"d\t%5d\n", row
->start
.overlay_string_index
,
18195 row
->end
.overlay_string_index
,
18196 row
->continuation_lines_width
);
18197 fprintf (stderr
, " %9"pI
"d %9"pI
"d\n",
18198 CHARPOS (row
->start
.string_pos
),
18199 CHARPOS (row
->end
.string_pos
));
18200 fprintf (stderr
, " %9d %9d\n", row
->start
.dpvec_index
,
18201 row
->end
.dpvec_index
);
18208 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18210 struct glyph
*glyph
= row
->glyphs
[area
];
18211 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
18213 /* Glyph for a line end in text. */
18214 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
18217 if (glyph
< glyph_end
)
18218 fprintf (stderr
, " Glyph# Type Pos O W Code C Face LR\n");
18220 for (; glyph
< glyph_end
; ++glyph
)
18221 dump_glyph (row
, glyph
, area
);
18224 else if (glyphs
== 1)
18228 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18230 char *s
= alloca (row
->used
[area
] + 4);
18233 for (i
= 0; i
< row
->used
[area
]; ++i
)
18235 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
18236 if (i
== row
->used
[area
] - 1
18237 && area
== TEXT_AREA
18238 && INTEGERP (glyph
->object
)
18239 && glyph
->type
== CHAR_GLYPH
18240 && glyph
->u
.ch
== ' ')
18242 strcpy (&s
[i
], "[\\n]");
18245 else if (glyph
->type
== CHAR_GLYPH
18246 && glyph
->u
.ch
< 0x80
18247 && glyph
->u
.ch
>= ' ')
18248 s
[i
] = glyph
->u
.ch
;
18254 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
18260 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
18261 Sdump_glyph_matrix
, 0, 1, "p",
18262 doc
: /* Dump the current matrix of the selected window to stderr.
18263 Shows contents of glyph row structures. With non-nil
18264 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
18265 glyphs in short form, otherwise show glyphs in long form. */)
18266 (Lisp_Object glyphs
)
18268 struct window
*w
= XWINDOW (selected_window
);
18269 struct buffer
*buffer
= XBUFFER (w
->contents
);
18271 fprintf (stderr
, "PT = %"pI
"d, BEGV = %"pI
"d. ZV = %"pI
"d\n",
18272 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
18273 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
18274 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
18275 fprintf (stderr
, "=============================================\n");
18276 dump_glyph_matrix (w
->current_matrix
,
18277 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 0);
18282 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
18283 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
18286 struct frame
*f
= XFRAME (selected_frame
);
18287 dump_glyph_matrix (f
->current_matrix
, 1);
18292 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
18293 doc
: /* Dump glyph row ROW to stderr.
18294 GLYPH 0 means don't dump glyphs.
18295 GLYPH 1 means dump glyphs in short form.
18296 GLYPH > 1 or omitted means dump glyphs in long form. */)
18297 (Lisp_Object row
, Lisp_Object glyphs
)
18299 struct glyph_matrix
*matrix
;
18302 CHECK_NUMBER (row
);
18303 matrix
= XWINDOW (selected_window
)->current_matrix
;
18305 if (vpos
>= 0 && vpos
< matrix
->nrows
)
18306 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
18308 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18313 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
18314 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
18315 GLYPH 0 means don't dump glyphs.
18316 GLYPH 1 means dump glyphs in short form.
18317 GLYPH > 1 or omitted means dump glyphs in long form.
18319 If there's no tool-bar, or if the tool-bar is not drawn by Emacs,
18321 (Lisp_Object row
, Lisp_Object glyphs
)
18323 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
18324 struct frame
*sf
= SELECTED_FRAME ();
18325 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
18328 CHECK_NUMBER (row
);
18330 if (vpos
>= 0 && vpos
< m
->nrows
)
18331 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
18332 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18338 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
18339 doc
: /* Toggle tracing of redisplay.
18340 With ARG, turn tracing on if and only if ARG is positive. */)
18344 trace_redisplay_p
= !trace_redisplay_p
;
18347 arg
= Fprefix_numeric_value (arg
);
18348 trace_redisplay_p
= XINT (arg
) > 0;
18355 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
18356 doc
: /* Like `format', but print result to stderr.
18357 usage: (trace-to-stderr STRING &rest OBJECTS) */)
18358 (ptrdiff_t nargs
, Lisp_Object
*args
)
18360 Lisp_Object s
= Fformat (nargs
, args
);
18361 fprintf (stderr
, "%s", SDATA (s
));
18365 #endif /* GLYPH_DEBUG */
18369 /***********************************************************************
18370 Building Desired Matrix Rows
18371 ***********************************************************************/
18373 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
18374 Used for non-window-redisplay windows, and for windows w/o left fringe. */
18376 static struct glyph_row
*
18377 get_overlay_arrow_glyph_row (struct window
*w
, Lisp_Object overlay_arrow_string
)
18379 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18380 struct buffer
*buffer
= XBUFFER (w
->contents
);
18381 struct buffer
*old
= current_buffer
;
18382 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
18383 int arrow_len
= SCHARS (overlay_arrow_string
);
18384 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
18385 const unsigned char *p
;
18388 int n_glyphs_before
;
18390 set_buffer_temp (buffer
);
18391 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
18392 it
.glyph_row
->used
[TEXT_AREA
] = 0;
18393 SET_TEXT_POS (it
.position
, 0, 0);
18395 multibyte_p
= !NILP (BVAR (buffer
, enable_multibyte_characters
));
18397 while (p
< arrow_end
)
18399 Lisp_Object face
, ilisp
;
18401 /* Get the next character. */
18403 it
.c
= it
.char_to_display
= string_char_and_length (p
, &it
.len
);
18406 it
.c
= it
.char_to_display
= *p
, it
.len
= 1;
18407 if (! ASCII_CHAR_P (it
.c
))
18408 it
.char_to_display
= BYTE8_TO_CHAR (it
.c
);
18412 /* Get its face. */
18413 ilisp
= make_number (p
- arrow_string
);
18414 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
18415 it
.face_id
= compute_char_face (f
, it
.char_to_display
, face
);
18417 /* Compute its width, get its glyphs. */
18418 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
18419 SET_TEXT_POS (it
.position
, -1, -1);
18420 PRODUCE_GLYPHS (&it
);
18422 /* If this character doesn't fit any more in the line, we have
18423 to remove some glyphs. */
18424 if (it
.current_x
> it
.last_visible_x
)
18426 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
18431 set_buffer_temp (old
);
18432 return it
.glyph_row
;
18436 /* Insert truncation glyphs at the start of IT->glyph_row. Which
18437 glyphs to insert is determined by produce_special_glyphs. */
18440 insert_left_trunc_glyphs (struct it
*it
)
18442 struct it truncate_it
;
18443 struct glyph
*from
, *end
, *to
, *toend
;
18445 eassert (!FRAME_WINDOW_P (it
->f
)
18446 || (!it
->glyph_row
->reversed_p
18447 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0)
18448 || (it
->glyph_row
->reversed_p
18449 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0));
18451 /* Get the truncation glyphs. */
18453 truncate_it
.current_x
= 0;
18454 truncate_it
.face_id
= DEFAULT_FACE_ID
;
18455 truncate_it
.glyph_row
= &scratch_glyph_row
;
18456 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
18457 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
18458 truncate_it
.object
= make_number (0);
18459 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
18461 /* Overwrite glyphs from IT with truncation glyphs. */
18462 if (!it
->glyph_row
->reversed_p
)
18464 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
18466 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18467 end
= from
+ tused
;
18468 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18469 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
18470 if (FRAME_WINDOW_P (it
->f
))
18472 /* On GUI frames, when variable-size fonts are displayed,
18473 the truncation glyphs may need more pixels than the row's
18474 glyphs they overwrite. We overwrite more glyphs to free
18475 enough screen real estate, and enlarge the stretch glyph
18476 on the right (see display_line), if there is one, to
18477 preserve the screen position of the truncation glyphs on
18480 struct glyph
*g
= to
;
18483 /* The first glyph could be partially visible, in which case
18484 it->glyph_row->x will be negative. But we want the left
18485 truncation glyphs to be aligned at the left margin of the
18486 window, so we override the x coordinate at which the row
18488 it
->glyph_row
->x
= 0;
18489 while (g
< toend
&& w
< it
->truncation_pixel_width
)
18491 w
+= g
->pixel_width
;
18494 if (g
- to
- tused
> 0)
18496 memmove (to
+ tused
, g
, (toend
- g
) * sizeof(*g
));
18497 it
->glyph_row
->used
[TEXT_AREA
] -= g
- to
- tused
;
18499 used
= it
->glyph_row
->used
[TEXT_AREA
];
18500 if (it
->glyph_row
->truncated_on_right_p
18501 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0
18502 && it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].type
18505 int extra
= w
- it
->truncation_pixel_width
;
18507 it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].pixel_width
+= extra
;
18514 /* There may be padding glyphs left over. Overwrite them too. */
18515 if (!FRAME_WINDOW_P (it
->f
))
18517 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
18519 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18526 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
18530 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
18532 /* In R2L rows, overwrite the last (rightmost) glyphs, and do
18533 that back to front. */
18534 end
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18535 from
= end
+ truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18536 toend
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18537 to
= toend
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18538 if (FRAME_WINDOW_P (it
->f
))
18541 struct glyph
*g
= to
;
18543 while (g
>= toend
&& w
< it
->truncation_pixel_width
)
18545 w
+= g
->pixel_width
;
18548 if (to
- g
- tused
> 0)
18550 if (it
->glyph_row
->truncated_on_right_p
18551 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0
18552 && it
->glyph_row
->glyphs
[TEXT_AREA
][1].type
== STRETCH_GLYPH
)
18554 int extra
= w
- it
->truncation_pixel_width
;
18556 it
->glyph_row
->glyphs
[TEXT_AREA
][1].pixel_width
+= extra
;
18560 while (from
>= end
&& to
>= toend
)
18562 if (!FRAME_WINDOW_P (it
->f
))
18564 while (to
>= toend
&& CHAR_GLYPH_PADDING_P (*to
))
18567 truncate_it
.glyph_row
->glyphs
[TEXT_AREA
]
18568 + truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18569 while (from
>= end
&& to
>= toend
)
18575 /* Need to free some room before prepending additional
18577 int move_by
= from
- end
+ 1;
18578 struct glyph
*g0
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18579 struct glyph
*g
= g0
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18581 for ( ; g
>= g0
; g
--)
18583 while (from
>= end
)
18585 it
->glyph_row
->used
[TEXT_AREA
] += move_by
;
18590 /* Compute the hash code for ROW. */
18592 row_hash (struct glyph_row
*row
)
18595 unsigned hashval
= 0;
18597 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18598 for (k
= 0; k
< row
->used
[area
]; ++k
)
18599 hashval
= ((((hashval
<< 4) + (hashval
>> 24)) & 0x0fffffff)
18600 + row
->glyphs
[area
][k
].u
.val
18601 + row
->glyphs
[area
][k
].face_id
18602 + row
->glyphs
[area
][k
].padding_p
18603 + (row
->glyphs
[area
][k
].type
<< 2));
18608 /* Compute the pixel height and width of IT->glyph_row.
18610 Most of the time, ascent and height of a display line will be equal
18611 to the max_ascent and max_height values of the display iterator
18612 structure. This is not the case if
18614 1. We hit ZV without displaying anything. In this case, max_ascent
18615 and max_height will be zero.
18617 2. We have some glyphs that don't contribute to the line height.
18618 (The glyph row flag contributes_to_line_height_p is for future
18619 pixmap extensions).
18621 The first case is easily covered by using default values because in
18622 these cases, the line height does not really matter, except that it
18623 must not be zero. */
18626 compute_line_metrics (struct it
*it
)
18628 struct glyph_row
*row
= it
->glyph_row
;
18630 if (FRAME_WINDOW_P (it
->f
))
18632 int i
, min_y
, max_y
;
18634 /* The line may consist of one space only, that was added to
18635 place the cursor on it. If so, the row's height hasn't been
18637 if (row
->height
== 0)
18639 if (it
->max_ascent
+ it
->max_descent
== 0)
18640 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
18641 row
->ascent
= it
->max_ascent
;
18642 row
->height
= it
->max_ascent
+ it
->max_descent
;
18643 row
->phys_ascent
= it
->max_phys_ascent
;
18644 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18645 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18648 /* Compute the width of this line. */
18649 row
->pixel_width
= row
->x
;
18650 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
18651 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
18653 eassert (row
->pixel_width
>= 0);
18654 eassert (row
->ascent
>= 0 && row
->height
> 0);
18656 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
18657 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
18659 /* If first line's physical ascent is larger than its logical
18660 ascent, use the physical ascent, and make the row taller.
18661 This makes accented characters fully visible. */
18662 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
18663 && row
->phys_ascent
> row
->ascent
)
18665 row
->height
+= row
->phys_ascent
- row
->ascent
;
18666 row
->ascent
= row
->phys_ascent
;
18669 /* Compute how much of the line is visible. */
18670 row
->visible_height
= row
->height
;
18672 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
18673 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
18675 if (row
->y
< min_y
)
18676 row
->visible_height
-= min_y
- row
->y
;
18677 if (row
->y
+ row
->height
> max_y
)
18678 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
18682 row
->pixel_width
= row
->used
[TEXT_AREA
];
18683 if (row
->continued_p
)
18684 row
->pixel_width
-= it
->continuation_pixel_width
;
18685 else if (row
->truncated_on_right_p
)
18686 row
->pixel_width
-= it
->truncation_pixel_width
;
18687 row
->ascent
= row
->phys_ascent
= 0;
18688 row
->height
= row
->phys_height
= row
->visible_height
= 1;
18689 row
->extra_line_spacing
= 0;
18692 /* Compute a hash code for this row. */
18693 row
->hash
= row_hash (row
);
18695 it
->max_ascent
= it
->max_descent
= 0;
18696 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
18700 /* Append one space to the glyph row of iterator IT if doing a
18701 window-based redisplay. The space has the same face as
18702 IT->face_id. Value is non-zero if a space was added.
18704 This function is called to make sure that there is always one glyph
18705 at the end of a glyph row that the cursor can be set on under
18706 window-systems. (If there weren't such a glyph we would not know
18707 how wide and tall a box cursor should be displayed).
18709 At the same time this space let's a nicely handle clearing to the
18710 end of the line if the row ends in italic text. */
18713 append_space_for_newline (struct it
*it
, int default_face_p
)
18715 if (FRAME_WINDOW_P (it
->f
))
18717 int n
= it
->glyph_row
->used
[TEXT_AREA
];
18719 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
18720 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
18722 /* Save some values that must not be changed.
18723 Must save IT->c and IT->len because otherwise
18724 ITERATOR_AT_END_P wouldn't work anymore after
18725 append_space_for_newline has been called. */
18726 enum display_element_type saved_what
= it
->what
;
18727 int saved_c
= it
->c
, saved_len
= it
->len
;
18728 int saved_char_to_display
= it
->char_to_display
;
18729 int saved_x
= it
->current_x
;
18730 int saved_face_id
= it
->face_id
;
18731 int saved_box_end
= it
->end_of_box_run_p
;
18732 struct text_pos saved_pos
;
18733 Lisp_Object saved_object
;
18736 saved_object
= it
->object
;
18737 saved_pos
= it
->position
;
18739 it
->what
= IT_CHARACTER
;
18740 memset (&it
->position
, 0, sizeof it
->position
);
18741 it
->object
= make_number (0);
18742 it
->c
= it
->char_to_display
= ' ';
18745 /* If the default face was remapped, be sure to use the
18746 remapped face for the appended newline. */
18747 if (default_face_p
)
18748 it
->face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
18749 else if (it
->face_before_selective_p
)
18750 it
->face_id
= it
->saved_face_id
;
18751 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18752 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
18753 /* In R2L rows, we will prepend a stretch glyph that will
18754 have the end_of_box_run_p flag set for it, so there's no
18755 need for the appended newline glyph to have that flag
18757 if (it
->glyph_row
->reversed_p
18758 /* But if the appended newline glyph goes all the way to
18759 the end of the row, there will be no stretch glyph,
18760 so leave the box flag set. */
18761 && saved_x
+ FRAME_COLUMN_WIDTH (it
->f
) < it
->last_visible_x
)
18762 it
->end_of_box_run_p
= 0;
18764 PRODUCE_GLYPHS (it
);
18766 it
->override_ascent
= -1;
18767 it
->constrain_row_ascent_descent_p
= 0;
18768 it
->current_x
= saved_x
;
18769 it
->object
= saved_object
;
18770 it
->position
= saved_pos
;
18771 it
->what
= saved_what
;
18772 it
->face_id
= saved_face_id
;
18773 it
->len
= saved_len
;
18775 it
->char_to_display
= saved_char_to_display
;
18776 it
->end_of_box_run_p
= saved_box_end
;
18785 /* Extend the face of the last glyph in the text area of IT->glyph_row
18786 to the end of the display line. Called from display_line. If the
18787 glyph row is empty, add a space glyph to it so that we know the
18788 face to draw. Set the glyph row flag fill_line_p. If the glyph
18789 row is R2L, prepend a stretch glyph to cover the empty space to the
18790 left of the leftmost glyph. */
18793 extend_face_to_end_of_line (struct it
*it
)
18795 struct face
*face
, *default_face
;
18796 struct frame
*f
= it
->f
;
18798 /* If line is already filled, do nothing. Non window-system frames
18799 get a grace of one more ``pixel'' because their characters are
18800 1-``pixel'' wide, so they hit the equality too early. This grace
18801 is needed only for R2L rows that are not continued, to produce
18802 one extra blank where we could display the cursor. */
18803 if (it
->current_x
>= it
->last_visible_x
18804 + (!FRAME_WINDOW_P (f
)
18805 && it
->glyph_row
->reversed_p
18806 && !it
->glyph_row
->continued_p
))
18809 /* The default face, possibly remapped. */
18810 default_face
= FACE_FROM_ID (f
, lookup_basic_face (f
, DEFAULT_FACE_ID
));
18812 /* Face extension extends the background and box of IT->face_id
18813 to the end of the line. If the background equals the background
18814 of the frame, we don't have to do anything. */
18815 if (it
->face_before_selective_p
)
18816 face
= FACE_FROM_ID (f
, it
->saved_face_id
);
18818 face
= FACE_FROM_ID (f
, it
->face_id
);
18820 if (FRAME_WINDOW_P (f
)
18821 && MATRIX_ROW_DISPLAYS_TEXT_P (it
->glyph_row
)
18822 && face
->box
== FACE_NO_BOX
18823 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
18824 #ifdef HAVE_WINDOW_SYSTEM
18827 && !it
->glyph_row
->reversed_p
)
18830 /* Set the glyph row flag indicating that the face of the last glyph
18831 in the text area has to be drawn to the end of the text area. */
18832 it
->glyph_row
->fill_line_p
= 1;
18834 /* If current character of IT is not ASCII, make sure we have the
18835 ASCII face. This will be automatically undone the next time
18836 get_next_display_element returns a multibyte character. Note
18837 that the character will always be single byte in unibyte
18839 if (!ASCII_CHAR_P (it
->c
))
18841 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
18844 if (FRAME_WINDOW_P (f
))
18846 /* If the row is empty, add a space with the current face of IT,
18847 so that we know which face to draw. */
18848 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
18850 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
18851 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= face
->id
;
18852 it
->glyph_row
->used
[TEXT_AREA
] = 1;
18854 #ifdef HAVE_WINDOW_SYSTEM
18855 if (it
->glyph_row
->reversed_p
)
18857 /* Prepend a stretch glyph to the row, such that the
18858 rightmost glyph will be drawn flushed all the way to the
18859 right margin of the window. The stretch glyph that will
18860 occupy the empty space, if any, to the left of the
18862 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (f
);
18863 struct glyph
*row_start
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18864 struct glyph
*row_end
= row_start
+ it
->glyph_row
->used
[TEXT_AREA
];
18866 int row_width
, stretch_ascent
, stretch_width
;
18867 struct text_pos saved_pos
;
18868 int saved_face_id
, saved_avoid_cursor
, saved_box_start
;
18870 for (row_width
= 0, g
= row_start
; g
< row_end
; g
++)
18871 row_width
+= g
->pixel_width
;
18872 stretch_width
= window_box_width (it
->w
, TEXT_AREA
) - row_width
;
18873 if (stretch_width
> 0)
18876 (((it
->ascent
+ it
->descent
)
18877 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
18878 saved_pos
= it
->position
;
18879 memset (&it
->position
, 0, sizeof it
->position
);
18880 saved_avoid_cursor
= it
->avoid_cursor_p
;
18881 it
->avoid_cursor_p
= 1;
18882 saved_face_id
= it
->face_id
;
18883 saved_box_start
= it
->start_of_box_run_p
;
18884 /* The last row's stretch glyph should get the default
18885 face, to avoid painting the rest of the window with
18886 the region face, if the region ends at ZV. */
18887 if (it
->glyph_row
->ends_at_zv_p
)
18888 it
->face_id
= default_face
->id
;
18890 it
->face_id
= face
->id
;
18891 it
->start_of_box_run_p
= 0;
18892 append_stretch_glyph (it
, make_number (0), stretch_width
,
18893 it
->ascent
+ it
->descent
, stretch_ascent
);
18894 it
->position
= saved_pos
;
18895 it
->avoid_cursor_p
= saved_avoid_cursor
;
18896 it
->face_id
= saved_face_id
;
18897 it
->start_of_box_run_p
= saved_box_start
;
18900 #endif /* HAVE_WINDOW_SYSTEM */
18904 /* Save some values that must not be changed. */
18905 int saved_x
= it
->current_x
;
18906 struct text_pos saved_pos
;
18907 Lisp_Object saved_object
;
18908 enum display_element_type saved_what
= it
->what
;
18909 int saved_face_id
= it
->face_id
;
18911 saved_object
= it
->object
;
18912 saved_pos
= it
->position
;
18914 it
->what
= IT_CHARACTER
;
18915 memset (&it
->position
, 0, sizeof it
->position
);
18916 it
->object
= make_number (0);
18917 it
->c
= it
->char_to_display
= ' ';
18919 /* The last row's blank glyphs should get the default face, to
18920 avoid painting the rest of the window with the region face,
18921 if the region ends at ZV. */
18922 if (it
->glyph_row
->ends_at_zv_p
)
18923 it
->face_id
= default_face
->id
;
18925 it
->face_id
= face
->id
;
18927 PRODUCE_GLYPHS (it
);
18929 while (it
->current_x
<= it
->last_visible_x
)
18930 PRODUCE_GLYPHS (it
);
18932 /* Don't count these blanks really. It would let us insert a left
18933 truncation glyph below and make us set the cursor on them, maybe. */
18934 it
->current_x
= saved_x
;
18935 it
->object
= saved_object
;
18936 it
->position
= saved_pos
;
18937 it
->what
= saved_what
;
18938 it
->face_id
= saved_face_id
;
18943 /* Value is non-zero if text starting at CHARPOS in current_buffer is
18944 trailing whitespace. */
18947 trailing_whitespace_p (ptrdiff_t charpos
)
18949 ptrdiff_t bytepos
= CHAR_TO_BYTE (charpos
);
18952 while (bytepos
< ZV_BYTE
18953 && (c
= FETCH_CHAR (bytepos
),
18954 c
== ' ' || c
== '\t'))
18957 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
18959 if (bytepos
!= PT_BYTE
)
18966 /* Highlight trailing whitespace, if any, in ROW. */
18969 highlight_trailing_whitespace (struct frame
*f
, struct glyph_row
*row
)
18971 int used
= row
->used
[TEXT_AREA
];
18975 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
18976 struct glyph
*glyph
= start
+ used
- 1;
18978 if (row
->reversed_p
)
18980 /* Right-to-left rows need to be processed in the opposite
18981 direction, so swap the edge pointers. */
18983 start
= row
->glyphs
[TEXT_AREA
] + used
- 1;
18986 /* Skip over glyphs inserted to display the cursor at the
18987 end of a line, for extending the face of the last glyph
18988 to the end of the line on terminals, and for truncation
18989 and continuation glyphs. */
18990 if (!row
->reversed_p
)
18992 while (glyph
>= start
18993 && glyph
->type
== CHAR_GLYPH
18994 && INTEGERP (glyph
->object
))
18999 while (glyph
<= start
19000 && glyph
->type
== CHAR_GLYPH
19001 && INTEGERP (glyph
->object
))
19005 /* If last glyph is a space or stretch, and it's trailing
19006 whitespace, set the face of all trailing whitespace glyphs in
19007 IT->glyph_row to `trailing-whitespace'. */
19008 if ((row
->reversed_p
? glyph
<= start
: glyph
>= start
)
19009 && BUFFERP (glyph
->object
)
19010 && (glyph
->type
== STRETCH_GLYPH
19011 || (glyph
->type
== CHAR_GLYPH
19012 && glyph
->u
.ch
== ' '))
19013 && trailing_whitespace_p (glyph
->charpos
))
19015 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
19019 if (!row
->reversed_p
)
19021 while (glyph
>= start
19022 && BUFFERP (glyph
->object
)
19023 && (glyph
->type
== STRETCH_GLYPH
19024 || (glyph
->type
== CHAR_GLYPH
19025 && glyph
->u
.ch
== ' ')))
19026 (glyph
--)->face_id
= face_id
;
19030 while (glyph
<= start
19031 && BUFFERP (glyph
->object
)
19032 && (glyph
->type
== STRETCH_GLYPH
19033 || (glyph
->type
== CHAR_GLYPH
19034 && glyph
->u
.ch
== ' ')))
19035 (glyph
++)->face_id
= face_id
;
19042 /* Value is non-zero if glyph row ROW should be
19043 considered to hold the buffer position CHARPOS. */
19046 row_for_charpos_p (struct glyph_row
*row
, ptrdiff_t charpos
)
19050 if (charpos
== CHARPOS (row
->end
.pos
)
19051 || charpos
== MATRIX_ROW_END_CHARPOS (row
))
19053 /* Suppose the row ends on a string.
19054 Unless the row is continued, that means it ends on a newline
19055 in the string. If it's anything other than a display string
19056 (e.g., a before-string from an overlay), we don't want the
19057 cursor there. (This heuristic seems to give the optimal
19058 behavior for the various types of multi-line strings.)
19059 One exception: if the string has `cursor' property on one of
19060 its characters, we _do_ want the cursor there. */
19061 if (CHARPOS (row
->end
.string_pos
) >= 0)
19063 if (row
->continued_p
)
19067 /* Check for `display' property. */
19068 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
19069 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
19070 struct glyph
*glyph
;
19073 for (glyph
= end
; glyph
>= beg
; --glyph
)
19074 if (STRINGP (glyph
->object
))
19077 = Fget_char_property (make_number (charpos
),
19081 && display_prop_string_p (prop
, glyph
->object
));
19082 /* If there's a `cursor' property on one of the
19083 string's characters, this row is a cursor row,
19084 even though this is not a display string. */
19087 Lisp_Object s
= glyph
->object
;
19089 for ( ; glyph
>= beg
&& EQ (glyph
->object
, s
); --glyph
)
19091 ptrdiff_t gpos
= glyph
->charpos
;
19093 if (!NILP (Fget_char_property (make_number (gpos
),
19105 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
19107 /* If the row ends in middle of a real character,
19108 and the line is continued, we want the cursor here.
19109 That's because CHARPOS (ROW->end.pos) would equal
19110 PT if PT is before the character. */
19111 if (!row
->ends_in_ellipsis_p
)
19112 result
= row
->continued_p
;
19114 /* If the row ends in an ellipsis, then
19115 CHARPOS (ROW->end.pos) will equal point after the
19116 invisible text. We want that position to be displayed
19117 after the ellipsis. */
19120 /* If the row ends at ZV, display the cursor at the end of that
19121 row instead of at the start of the row below. */
19122 else if (row
->ends_at_zv_p
)
19131 /* Value is non-zero if glyph row ROW should be
19132 used to hold the cursor. */
19135 cursor_row_p (struct glyph_row
*row
)
19137 return row_for_charpos_p (row
, PT
);
19142 /* Push the property PROP so that it will be rendered at the current
19143 position in IT. Return 1 if PROP was successfully pushed, 0
19144 otherwise. Called from handle_line_prefix to handle the
19145 `line-prefix' and `wrap-prefix' properties. */
19148 push_prefix_prop (struct it
*it
, Lisp_Object prop
)
19150 struct text_pos pos
=
19151 STRINGP (it
->string
) ? it
->current
.string_pos
: it
->current
.pos
;
19153 eassert (it
->method
== GET_FROM_BUFFER
19154 || it
->method
== GET_FROM_DISPLAY_VECTOR
19155 || it
->method
== GET_FROM_STRING
);
19157 /* We need to save the current buffer/string position, so it will be
19158 restored by pop_it, because iterate_out_of_display_property
19159 depends on that being set correctly, but some situations leave
19160 it->position not yet set when this function is called. */
19161 push_it (it
, &pos
);
19163 if (STRINGP (prop
))
19165 if (SCHARS (prop
) == 0)
19172 it
->string_from_prefix_prop_p
= 1;
19173 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
19174 it
->current
.overlay_string_index
= -1;
19175 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
19176 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
19177 it
->method
= GET_FROM_STRING
;
19178 it
->stop_charpos
= 0;
19180 it
->base_level_stop
= 0;
19182 /* Force paragraph direction to be that of the parent
19184 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
19185 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
19187 it
->paragraph_embedding
= L2R
;
19189 /* Set up the bidi iterator for this display string. */
19192 it
->bidi_it
.string
.lstring
= it
->string
;
19193 it
->bidi_it
.string
.s
= NULL
;
19194 it
->bidi_it
.string
.schars
= it
->end_charpos
;
19195 it
->bidi_it
.string
.bufpos
= IT_CHARPOS (*it
);
19196 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
19197 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
19198 it
->bidi_it
.w
= it
->w
;
19199 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
19202 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
19204 it
->method
= GET_FROM_STRETCH
;
19207 #ifdef HAVE_WINDOW_SYSTEM
19208 else if (IMAGEP (prop
))
19210 it
->what
= IT_IMAGE
;
19211 it
->image_id
= lookup_image (it
->f
, prop
);
19212 it
->method
= GET_FROM_IMAGE
;
19214 #endif /* HAVE_WINDOW_SYSTEM */
19217 pop_it (it
); /* bogus display property, give up */
19224 /* Return the character-property PROP at the current position in IT. */
19227 get_it_property (struct it
*it
, Lisp_Object prop
)
19229 Lisp_Object position
, object
= it
->object
;
19231 if (STRINGP (object
))
19232 position
= make_number (IT_STRING_CHARPOS (*it
));
19233 else if (BUFFERP (object
))
19235 position
= make_number (IT_CHARPOS (*it
));
19236 object
= it
->window
;
19241 return Fget_char_property (position
, prop
, object
);
19244 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
19247 handle_line_prefix (struct it
*it
)
19249 Lisp_Object prefix
;
19251 if (it
->continuation_lines_width
> 0)
19253 prefix
= get_it_property (it
, Qwrap_prefix
);
19255 prefix
= Vwrap_prefix
;
19259 prefix
= get_it_property (it
, Qline_prefix
);
19261 prefix
= Vline_prefix
;
19263 if (! NILP (prefix
) && push_prefix_prop (it
, prefix
))
19265 /* If the prefix is wider than the window, and we try to wrap
19266 it, it would acquire its own wrap prefix, and so on till the
19267 iterator stack overflows. So, don't wrap the prefix. */
19268 it
->line_wrap
= TRUNCATE
;
19269 it
->avoid_cursor_p
= 1;
19275 /* Remove N glyphs at the start of a reversed IT->glyph_row. Called
19276 only for R2L lines from display_line and display_string, when they
19277 decide that too many glyphs were produced by PRODUCE_GLYPHS, and
19278 the line/string needs to be continued on the next glyph row. */
19280 unproduce_glyphs (struct it
*it
, int n
)
19282 struct glyph
*glyph
, *end
;
19284 eassert (it
->glyph_row
);
19285 eassert (it
->glyph_row
->reversed_p
);
19286 eassert (it
->area
== TEXT_AREA
);
19287 eassert (n
<= it
->glyph_row
->used
[TEXT_AREA
]);
19289 if (n
> it
->glyph_row
->used
[TEXT_AREA
])
19290 n
= it
->glyph_row
->used
[TEXT_AREA
];
19291 glyph
= it
->glyph_row
->glyphs
[TEXT_AREA
] + n
;
19292 end
= it
->glyph_row
->glyphs
[TEXT_AREA
] + it
->glyph_row
->used
[TEXT_AREA
];
19293 for ( ; glyph
< end
; glyph
++)
19294 glyph
[-n
] = *glyph
;
19297 /* Find the positions in a bidi-reordered ROW to serve as ROW->minpos
19298 and ROW->maxpos. */
19300 find_row_edges (struct it
*it
, struct glyph_row
*row
,
19301 ptrdiff_t min_pos
, ptrdiff_t min_bpos
,
19302 ptrdiff_t max_pos
, ptrdiff_t max_bpos
)
19304 /* FIXME: Revisit this when glyph ``spilling'' in continuation
19305 lines' rows is implemented for bidi-reordered rows. */
19307 /* ROW->minpos is the value of min_pos, the minimal buffer position
19308 we have in ROW, or ROW->start.pos if that is smaller. */
19309 if (min_pos
<= ZV
&& min_pos
< row
->start
.pos
.charpos
)
19310 SET_TEXT_POS (row
->minpos
, min_pos
, min_bpos
);
19312 /* We didn't find buffer positions smaller than ROW->start, or
19313 didn't find _any_ valid buffer positions in any of the glyphs,
19314 so we must trust the iterator's computed positions. */
19315 row
->minpos
= row
->start
.pos
;
19318 max_pos
= CHARPOS (it
->current
.pos
);
19319 max_bpos
= BYTEPOS (it
->current
.pos
);
19322 /* Here are the various use-cases for ending the row, and the
19323 corresponding values for ROW->maxpos:
19325 Line ends in a newline from buffer eol_pos + 1
19326 Line is continued from buffer max_pos + 1
19327 Line is truncated on right it->current.pos
19328 Line ends in a newline from string max_pos + 1(*)
19329 (*) + 1 only when line ends in a forward scan
19330 Line is continued from string max_pos
19331 Line is continued from display vector max_pos
19332 Line is entirely from a string min_pos == max_pos
19333 Line is entirely from a display vector min_pos == max_pos
19334 Line that ends at ZV ZV
19336 If you discover other use-cases, please add them here as
19338 if (row
->ends_at_zv_p
)
19339 row
->maxpos
= it
->current
.pos
;
19340 else if (row
->used
[TEXT_AREA
])
19342 int seen_this_string
= 0;
19343 struct glyph_row
*r1
= row
- 1;
19345 /* Did we see the same display string on the previous row? */
19346 if (STRINGP (it
->object
)
19347 /* this is not the first row */
19348 && row
> it
->w
->desired_matrix
->rows
19349 /* previous row is not the header line */
19350 && !r1
->mode_line_p
19351 /* previous row also ends in a newline from a string */
19352 && r1
->ends_in_newline_from_string_p
)
19354 struct glyph
*start
, *end
;
19356 /* Search for the last glyph of the previous row that came
19357 from buffer or string. Depending on whether the row is
19358 L2R or R2L, we need to process it front to back or the
19359 other way round. */
19360 if (!r1
->reversed_p
)
19362 start
= r1
->glyphs
[TEXT_AREA
];
19363 end
= start
+ r1
->used
[TEXT_AREA
];
19364 /* Glyphs inserted by redisplay have an integer (zero)
19365 as their object. */
19367 && INTEGERP ((end
- 1)->object
)
19368 && (end
- 1)->charpos
<= 0)
19372 if (EQ ((end
- 1)->object
, it
->object
))
19373 seen_this_string
= 1;
19376 /* If all the glyphs of the previous row were inserted
19377 by redisplay, it means the previous row was
19378 produced from a single newline, which is only
19379 possible if that newline came from the same string
19380 as the one which produced this ROW. */
19381 seen_this_string
= 1;
19385 end
= r1
->glyphs
[TEXT_AREA
] - 1;
19386 start
= end
+ r1
->used
[TEXT_AREA
];
19388 && INTEGERP ((end
+ 1)->object
)
19389 && (end
+ 1)->charpos
<= 0)
19393 if (EQ ((end
+ 1)->object
, it
->object
))
19394 seen_this_string
= 1;
19397 seen_this_string
= 1;
19400 /* Take note of each display string that covers a newline only
19401 once, the first time we see it. This is for when a display
19402 string includes more than one newline in it. */
19403 if (row
->ends_in_newline_from_string_p
&& !seen_this_string
)
19405 /* If we were scanning the buffer forward when we displayed
19406 the string, we want to account for at least one buffer
19407 position that belongs to this row (position covered by
19408 the display string), so that cursor positioning will
19409 consider this row as a candidate when point is at the end
19410 of the visual line represented by this row. This is not
19411 required when scanning back, because max_pos will already
19412 have a much larger value. */
19413 if (CHARPOS (row
->end
.pos
) > max_pos
)
19414 INC_BOTH (max_pos
, max_bpos
);
19415 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19417 else if (CHARPOS (it
->eol_pos
) > 0)
19418 SET_TEXT_POS (row
->maxpos
,
19419 CHARPOS (it
->eol_pos
) + 1, BYTEPOS (it
->eol_pos
) + 1);
19420 else if (row
->continued_p
)
19422 /* If max_pos is different from IT's current position, it
19423 means IT->method does not belong to the display element
19424 at max_pos. However, it also means that the display
19425 element at max_pos was displayed in its entirety on this
19426 line, which is equivalent to saying that the next line
19427 starts at the next buffer position. */
19428 if (IT_CHARPOS (*it
) == max_pos
&& it
->method
!= GET_FROM_BUFFER
)
19429 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19432 INC_BOTH (max_pos
, max_bpos
);
19433 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19436 else if (row
->truncated_on_right_p
)
19437 /* display_line already called reseat_at_next_visible_line_start,
19438 which puts the iterator at the beginning of the next line, in
19439 the logical order. */
19440 row
->maxpos
= it
->current
.pos
;
19441 else if (max_pos
== min_pos
&& it
->method
!= GET_FROM_BUFFER
)
19442 /* A line that is entirely from a string/image/stretch... */
19443 row
->maxpos
= row
->minpos
;
19448 row
->maxpos
= it
->current
.pos
;
19451 /* Construct the glyph row IT->glyph_row in the desired matrix of
19452 IT->w from text at the current position of IT. See dispextern.h
19453 for an overview of struct it. Value is non-zero if
19454 IT->glyph_row displays text, as opposed to a line displaying ZV
19458 display_line (struct it
*it
)
19460 struct glyph_row
*row
= it
->glyph_row
;
19461 Lisp_Object overlay_arrow_string
;
19463 void *wrap_data
= NULL
;
19464 int may_wrap
= 0, wrap_x
IF_LINT (= 0);
19465 int wrap_row_used
= -1;
19466 int wrap_row_ascent
IF_LINT (= 0), wrap_row_height
IF_LINT (= 0);
19467 int wrap_row_phys_ascent
IF_LINT (= 0), wrap_row_phys_height
IF_LINT (= 0);
19468 int wrap_row_extra_line_spacing
IF_LINT (= 0);
19469 ptrdiff_t wrap_row_min_pos
IF_LINT (= 0), wrap_row_min_bpos
IF_LINT (= 0);
19470 ptrdiff_t wrap_row_max_pos
IF_LINT (= 0), wrap_row_max_bpos
IF_LINT (= 0);
19472 ptrdiff_t min_pos
= ZV
+ 1, max_pos
= 0;
19473 ptrdiff_t min_bpos
IF_LINT (= 0), max_bpos
IF_LINT (= 0);
19475 /* We always start displaying at hpos zero even if hscrolled. */
19476 eassert (it
->hpos
== 0 && it
->current_x
== 0);
19478 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
19479 >= it
->w
->desired_matrix
->nrows
)
19481 it
->w
->nrows_scale_factor
++;
19482 it
->f
->fonts_changed
= 1;
19486 /* Clear the result glyph row and enable it. */
19487 prepare_desired_row (row
);
19489 row
->y
= it
->current_y
;
19490 row
->start
= it
->start
;
19491 row
->continuation_lines_width
= it
->continuation_lines_width
;
19492 row
->displays_text_p
= 1;
19493 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
19494 it
->starts_in_middle_of_char_p
= 0;
19496 /* Arrange the overlays nicely for our purposes. Usually, we call
19497 display_line on only one line at a time, in which case this
19498 can't really hurt too much, or we call it on lines which appear
19499 one after another in the buffer, in which case all calls to
19500 recenter_overlay_lists but the first will be pretty cheap. */
19501 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
19503 /* Move over display elements that are not visible because we are
19504 hscrolled. This may stop at an x-position < IT->first_visible_x
19505 if the first glyph is partially visible or if we hit a line end. */
19506 if (it
->current_x
< it
->first_visible_x
)
19508 enum move_it_result move_result
;
19510 this_line_min_pos
= row
->start
.pos
;
19511 move_result
= move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
19512 MOVE_TO_POS
| MOVE_TO_X
);
19513 /* If we are under a large hscroll, move_it_in_display_line_to
19514 could hit the end of the line without reaching
19515 it->first_visible_x. Pretend that we did reach it. This is
19516 especially important on a TTY, where we will call
19517 extend_face_to_end_of_line, which needs to know how many
19518 blank glyphs to produce. */
19519 if (it
->current_x
< it
->first_visible_x
19520 && (move_result
== MOVE_NEWLINE_OR_CR
19521 || move_result
== MOVE_POS_MATCH_OR_ZV
))
19522 it
->current_x
= it
->first_visible_x
;
19524 /* Record the smallest positions seen while we moved over
19525 display elements that are not visible. This is needed by
19526 redisplay_internal for optimizing the case where the cursor
19527 stays inside the same line. The rest of this function only
19528 considers positions that are actually displayed, so
19529 RECORD_MAX_MIN_POS will not otherwise record positions that
19530 are hscrolled to the left of the left edge of the window. */
19531 min_pos
= CHARPOS (this_line_min_pos
);
19532 min_bpos
= BYTEPOS (this_line_min_pos
);
19536 /* We only do this when not calling `move_it_in_display_line_to'
19537 above, because move_it_in_display_line_to calls
19538 handle_line_prefix itself. */
19539 handle_line_prefix (it
);
19542 /* Get the initial row height. This is either the height of the
19543 text hscrolled, if there is any, or zero. */
19544 row
->ascent
= it
->max_ascent
;
19545 row
->height
= it
->max_ascent
+ it
->max_descent
;
19546 row
->phys_ascent
= it
->max_phys_ascent
;
19547 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
19548 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
19550 /* Utility macro to record max and min buffer positions seen until now. */
19551 #define RECORD_MAX_MIN_POS(IT) \
19554 int composition_p = !STRINGP ((IT)->string) \
19555 && ((IT)->what == IT_COMPOSITION); \
19556 ptrdiff_t current_pos = \
19557 composition_p ? (IT)->cmp_it.charpos \
19558 : IT_CHARPOS (*(IT)); \
19559 ptrdiff_t current_bpos = \
19560 composition_p ? CHAR_TO_BYTE (current_pos) \
19561 : IT_BYTEPOS (*(IT)); \
19562 if (current_pos < min_pos) \
19564 min_pos = current_pos; \
19565 min_bpos = current_bpos; \
19567 if (IT_CHARPOS (*it) > max_pos) \
19569 max_pos = IT_CHARPOS (*it); \
19570 max_bpos = IT_BYTEPOS (*it); \
19575 /* Loop generating characters. The loop is left with IT on the next
19576 character to display. */
19579 int n_glyphs_before
, hpos_before
, x_before
;
19581 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
19583 /* Retrieve the next thing to display. Value is zero if end of
19585 if (!get_next_display_element (it
))
19587 /* Maybe add a space at the end of this line that is used to
19588 display the cursor there under X. Set the charpos of the
19589 first glyph of blank lines not corresponding to any text
19591 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19592 row
->exact_window_width_line_p
= 1;
19593 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
19594 || row
->used
[TEXT_AREA
] == 0)
19596 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
19597 row
->displays_text_p
= 0;
19599 if (!NILP (BVAR (XBUFFER (it
->w
->contents
), indicate_empty_lines
))
19600 && (!MINI_WINDOW_P (it
->w
)
19601 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
19602 row
->indicate_empty_line_p
= 1;
19605 it
->continuation_lines_width
= 0;
19606 row
->ends_at_zv_p
= 1;
19607 /* A row that displays right-to-left text must always have
19608 its last face extended all the way to the end of line,
19609 even if this row ends in ZV, because we still write to
19610 the screen left to right. We also need to extend the
19611 last face if the default face is remapped to some
19612 different face, otherwise the functions that clear
19613 portions of the screen will clear with the default face's
19614 background color. */
19615 if (row
->reversed_p
19616 || lookup_basic_face (it
->f
, DEFAULT_FACE_ID
) != DEFAULT_FACE_ID
)
19617 extend_face_to_end_of_line (it
);
19621 /* Now, get the metrics of what we want to display. This also
19622 generates glyphs in `row' (which is IT->glyph_row). */
19623 n_glyphs_before
= row
->used
[TEXT_AREA
];
19626 /* Remember the line height so far in case the next element doesn't
19627 fit on the line. */
19628 if (it
->line_wrap
!= TRUNCATE
)
19630 ascent
= it
->max_ascent
;
19631 descent
= it
->max_descent
;
19632 phys_ascent
= it
->max_phys_ascent
;
19633 phys_descent
= it
->max_phys_descent
;
19635 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
19637 if (IT_DISPLAYING_WHITESPACE (it
))
19641 SAVE_IT (wrap_it
, *it
, wrap_data
);
19643 wrap_row_used
= row
->used
[TEXT_AREA
];
19644 wrap_row_ascent
= row
->ascent
;
19645 wrap_row_height
= row
->height
;
19646 wrap_row_phys_ascent
= row
->phys_ascent
;
19647 wrap_row_phys_height
= row
->phys_height
;
19648 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
19649 wrap_row_min_pos
= min_pos
;
19650 wrap_row_min_bpos
= min_bpos
;
19651 wrap_row_max_pos
= max_pos
;
19652 wrap_row_max_bpos
= max_bpos
;
19658 PRODUCE_GLYPHS (it
);
19660 /* If this display element was in marginal areas, continue with
19662 if (it
->area
!= TEXT_AREA
)
19664 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19665 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19666 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19667 row
->phys_height
= max (row
->phys_height
,
19668 it
->max_phys_ascent
+ it
->max_phys_descent
);
19669 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19670 it
->max_extra_line_spacing
);
19671 set_iterator_to_next (it
, 1);
19675 /* Does the display element fit on the line? If we truncate
19676 lines, we should draw past the right edge of the window. If
19677 we don't truncate, we want to stop so that we can display the
19678 continuation glyph before the right margin. If lines are
19679 continued, there are two possible strategies for characters
19680 resulting in more than 1 glyph (e.g. tabs): Display as many
19681 glyphs as possible in this line and leave the rest for the
19682 continuation line, or display the whole element in the next
19683 line. Original redisplay did the former, so we do it also. */
19684 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
19685 hpos_before
= it
->hpos
;
19688 if (/* Not a newline. */
19690 /* Glyphs produced fit entirely in the line. */
19691 && it
->current_x
< it
->last_visible_x
)
19693 it
->hpos
+= nglyphs
;
19694 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19695 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19696 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19697 row
->phys_height
= max (row
->phys_height
,
19698 it
->max_phys_ascent
+ it
->max_phys_descent
);
19699 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19700 it
->max_extra_line_spacing
);
19701 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
19702 row
->x
= x
- it
->first_visible_x
;
19703 /* Record the maximum and minimum buffer positions seen so
19704 far in glyphs that will be displayed by this row. */
19706 RECORD_MAX_MIN_POS (it
);
19711 struct glyph
*glyph
;
19713 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
19715 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
19716 new_x
= x
+ glyph
->pixel_width
;
19718 if (/* Lines are continued. */
19719 it
->line_wrap
!= TRUNCATE
19720 && (/* Glyph doesn't fit on the line. */
19721 new_x
> it
->last_visible_x
19722 /* Or it fits exactly on a window system frame. */
19723 || (new_x
== it
->last_visible_x
19724 && FRAME_WINDOW_P (it
->f
)
19725 && (row
->reversed_p
19726 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19727 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
19729 /* End of a continued line. */
19732 || (new_x
== it
->last_visible_x
19733 && FRAME_WINDOW_P (it
->f
)
19734 && (row
->reversed_p
19735 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19736 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
))))
19738 /* Current glyph is the only one on the line or
19739 fits exactly on the line. We must continue
19740 the line because we can't draw the cursor
19741 after the glyph. */
19742 row
->continued_p
= 1;
19743 it
->current_x
= new_x
;
19744 it
->continuation_lines_width
+= new_x
;
19746 if (i
== nglyphs
- 1)
19748 /* If line-wrap is on, check if a previous
19749 wrap point was found. */
19750 if (wrap_row_used
> 0
19751 /* Even if there is a previous wrap
19752 point, continue the line here as
19753 usual, if (i) the previous character
19754 was a space or tab AND (ii) the
19755 current character is not. */
19757 || IT_DISPLAYING_WHITESPACE (it
)))
19760 /* Record the maximum and minimum buffer
19761 positions seen so far in glyphs that will be
19762 displayed by this row. */
19764 RECORD_MAX_MIN_POS (it
);
19765 set_iterator_to_next (it
, 1);
19766 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19768 if (!get_next_display_element (it
))
19770 row
->exact_window_width_line_p
= 1;
19771 it
->continuation_lines_width
= 0;
19772 row
->continued_p
= 0;
19773 row
->ends_at_zv_p
= 1;
19775 else if (ITERATOR_AT_END_OF_LINE_P (it
))
19777 row
->continued_p
= 0;
19778 row
->exact_window_width_line_p
= 1;
19782 else if (it
->bidi_p
)
19783 RECORD_MAX_MIN_POS (it
);
19785 else if (CHAR_GLYPH_PADDING_P (*glyph
)
19786 && !FRAME_WINDOW_P (it
->f
))
19788 /* A padding glyph that doesn't fit on this line.
19789 This means the whole character doesn't fit
19791 if (row
->reversed_p
)
19792 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19793 - n_glyphs_before
);
19794 row
->used
[TEXT_AREA
] = n_glyphs_before
;
19796 /* Fill the rest of the row with continuation
19797 glyphs like in 20.x. */
19798 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
19799 < row
->glyphs
[1 + TEXT_AREA
])
19800 produce_special_glyphs (it
, IT_CONTINUATION
);
19802 row
->continued_p
= 1;
19803 it
->current_x
= x_before
;
19804 it
->continuation_lines_width
+= x_before
;
19806 /* Restore the height to what it was before the
19807 element not fitting on the line. */
19808 it
->max_ascent
= ascent
;
19809 it
->max_descent
= descent
;
19810 it
->max_phys_ascent
= phys_ascent
;
19811 it
->max_phys_descent
= phys_descent
;
19813 else if (wrap_row_used
> 0)
19816 if (row
->reversed_p
)
19817 unproduce_glyphs (it
,
19818 row
->used
[TEXT_AREA
] - wrap_row_used
);
19819 RESTORE_IT (it
, &wrap_it
, wrap_data
);
19820 it
->continuation_lines_width
+= wrap_x
;
19821 row
->used
[TEXT_AREA
] = wrap_row_used
;
19822 row
->ascent
= wrap_row_ascent
;
19823 row
->height
= wrap_row_height
;
19824 row
->phys_ascent
= wrap_row_phys_ascent
;
19825 row
->phys_height
= wrap_row_phys_height
;
19826 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
19827 min_pos
= wrap_row_min_pos
;
19828 min_bpos
= wrap_row_min_bpos
;
19829 max_pos
= wrap_row_max_pos
;
19830 max_bpos
= wrap_row_max_bpos
;
19831 row
->continued_p
= 1;
19832 row
->ends_at_zv_p
= 0;
19833 row
->exact_window_width_line_p
= 0;
19834 it
->continuation_lines_width
+= x
;
19836 /* Make sure that a non-default face is extended
19837 up to the right margin of the window. */
19838 extend_face_to_end_of_line (it
);
19840 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
19842 /* A TAB that extends past the right edge of the
19843 window. This produces a single glyph on
19844 window system frames. We leave the glyph in
19845 this row and let it fill the row, but don't
19846 consume the TAB. */
19847 if ((row
->reversed_p
19848 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19849 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19850 produce_special_glyphs (it
, IT_CONTINUATION
);
19851 it
->continuation_lines_width
+= it
->last_visible_x
;
19852 row
->ends_in_middle_of_char_p
= 1;
19853 row
->continued_p
= 1;
19854 glyph
->pixel_width
= it
->last_visible_x
- x
;
19855 it
->starts_in_middle_of_char_p
= 1;
19859 /* Something other than a TAB that draws past
19860 the right edge of the window. Restore
19861 positions to values before the element. */
19862 if (row
->reversed_p
)
19863 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19864 - (n_glyphs_before
+ i
));
19865 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
19867 /* Display continuation glyphs. */
19868 it
->current_x
= x_before
;
19869 it
->continuation_lines_width
+= x
;
19870 if (!FRAME_WINDOW_P (it
->f
)
19871 || (row
->reversed_p
19872 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19873 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19874 produce_special_glyphs (it
, IT_CONTINUATION
);
19875 row
->continued_p
= 1;
19877 extend_face_to_end_of_line (it
);
19879 if (nglyphs
> 1 && i
> 0)
19881 row
->ends_in_middle_of_char_p
= 1;
19882 it
->starts_in_middle_of_char_p
= 1;
19885 /* Restore the height to what it was before the
19886 element not fitting on the line. */
19887 it
->max_ascent
= ascent
;
19888 it
->max_descent
= descent
;
19889 it
->max_phys_ascent
= phys_ascent
;
19890 it
->max_phys_descent
= phys_descent
;
19895 else if (new_x
> it
->first_visible_x
)
19897 /* Increment number of glyphs actually displayed. */
19900 /* Record the maximum and minimum buffer positions
19901 seen so far in glyphs that will be displayed by
19904 RECORD_MAX_MIN_POS (it
);
19906 if (x
< it
->first_visible_x
)
19907 /* Glyph is partially visible, i.e. row starts at
19908 negative X position. */
19909 row
->x
= x
- it
->first_visible_x
;
19913 /* Glyph is completely off the left margin of the
19914 window. This should not happen because of the
19915 move_it_in_display_line at the start of this
19916 function, unless the text display area of the
19917 window is empty. */
19918 eassert (it
->first_visible_x
<= it
->last_visible_x
);
19921 /* Even if this display element produced no glyphs at all,
19922 we want to record its position. */
19923 if (it
->bidi_p
&& nglyphs
== 0)
19924 RECORD_MAX_MIN_POS (it
);
19926 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19927 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19928 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19929 row
->phys_height
= max (row
->phys_height
,
19930 it
->max_phys_ascent
+ it
->max_phys_descent
);
19931 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19932 it
->max_extra_line_spacing
);
19934 /* End of this display line if row is continued. */
19935 if (row
->continued_p
|| row
->ends_at_zv_p
)
19940 /* Is this a line end? If yes, we're also done, after making
19941 sure that a non-default face is extended up to the right
19942 margin of the window. */
19943 if (ITERATOR_AT_END_OF_LINE_P (it
))
19945 int used_before
= row
->used
[TEXT_AREA
];
19947 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
19949 /* Add a space at the end of the line that is used to
19950 display the cursor there. */
19951 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19952 append_space_for_newline (it
, 0);
19954 /* Extend the face to the end of the line. */
19955 extend_face_to_end_of_line (it
);
19957 /* Make sure we have the position. */
19958 if (used_before
== 0)
19959 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
19961 /* Record the position of the newline, for use in
19963 it
->eol_pos
= it
->current
.pos
;
19965 /* Consume the line end. This skips over invisible lines. */
19966 set_iterator_to_next (it
, 1);
19967 it
->continuation_lines_width
= 0;
19971 /* Proceed with next display element. Note that this skips
19972 over lines invisible because of selective display. */
19973 set_iterator_to_next (it
, 1);
19975 /* If we truncate lines, we are done when the last displayed
19976 glyphs reach past the right margin of the window. */
19977 if (it
->line_wrap
== TRUNCATE
19978 && (FRAME_WINDOW_P (it
->f
) && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
19979 ? (it
->current_x
>= it
->last_visible_x
)
19980 : (it
->current_x
> it
->last_visible_x
)))
19982 /* Maybe add truncation glyphs. */
19983 if (!FRAME_WINDOW_P (it
->f
)
19984 || (row
->reversed_p
19985 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19986 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19990 if (!row
->reversed_p
)
19992 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
19993 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19998 for (i
= 0; i
< row
->used
[TEXT_AREA
]; i
++)
19999 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
20001 /* Remove any padding glyphs at the front of ROW, to
20002 make room for the truncation glyphs we will be
20003 adding below. The loop below always inserts at
20004 least one truncation glyph, so also remove the
20005 last glyph added to ROW. */
20006 unproduce_glyphs (it
, i
+ 1);
20007 /* Adjust i for the loop below. */
20008 i
= row
->used
[TEXT_AREA
] - (i
+ 1);
20011 it
->current_x
= x_before
;
20012 if (!FRAME_WINDOW_P (it
->f
))
20014 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
20016 row
->used
[TEXT_AREA
] = i
;
20017 produce_special_glyphs (it
, IT_TRUNCATION
);
20022 row
->used
[TEXT_AREA
] = i
;
20023 produce_special_glyphs (it
, IT_TRUNCATION
);
20026 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
20028 /* Don't truncate if we can overflow newline into fringe. */
20029 if (!get_next_display_element (it
))
20031 it
->continuation_lines_width
= 0;
20032 row
->ends_at_zv_p
= 1;
20033 row
->exact_window_width_line_p
= 1;
20036 if (ITERATOR_AT_END_OF_LINE_P (it
))
20038 row
->exact_window_width_line_p
= 1;
20039 goto at_end_of_line
;
20041 it
->current_x
= x_before
;
20044 row
->truncated_on_right_p
= 1;
20045 it
->continuation_lines_width
= 0;
20046 reseat_at_next_visible_line_start (it
, 0);
20047 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
20048 it
->hpos
= hpos_before
;
20054 bidi_unshelve_cache (wrap_data
, 1);
20056 /* If line is not empty and hscrolled, maybe insert truncation glyphs
20057 at the left window margin. */
20058 if (it
->first_visible_x
20059 && IT_CHARPOS (*it
) != CHARPOS (row
->start
.pos
))
20061 if (!FRAME_WINDOW_P (it
->f
)
20062 || (row
->reversed_p
20063 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
20064 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
20065 insert_left_trunc_glyphs (it
);
20066 row
->truncated_on_left_p
= 1;
20069 /* Remember the position at which this line ends.
20071 BIDI Note: any code that needs MATRIX_ROW_START/END_CHARPOS
20072 cannot be before the call to find_row_edges below, since that is
20073 where these positions are determined. */
20074 row
->end
= it
->current
;
20077 row
->minpos
= row
->start
.pos
;
20078 row
->maxpos
= row
->end
.pos
;
20082 /* ROW->minpos and ROW->maxpos must be the smallest and
20083 `1 + the largest' buffer positions in ROW. But if ROW was
20084 bidi-reordered, these two positions can be anywhere in the
20085 row, so we must determine them now. */
20086 find_row_edges (it
, row
, min_pos
, min_bpos
, max_pos
, max_bpos
);
20089 /* If the start of this line is the overlay arrow-position, then
20090 mark this glyph row as the one containing the overlay arrow.
20091 This is clearly a mess with variable size fonts. It would be
20092 better to let it be displayed like cursors under X. */
20093 if ((MATRIX_ROW_DISPLAYS_TEXT_P (row
) || !overlay_arrow_seen
)
20094 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
20095 !NILP (overlay_arrow_string
)))
20097 /* Overlay arrow in window redisplay is a fringe bitmap. */
20098 if (STRINGP (overlay_arrow_string
))
20100 struct glyph_row
*arrow_row
20101 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
20102 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
20103 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
20104 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
20105 struct glyph
*p2
, *end
;
20107 /* Copy the arrow glyphs. */
20108 while (glyph
< arrow_end
)
20111 /* Throw away padding glyphs. */
20113 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
20114 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
20120 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
20125 eassert (INTEGERP (overlay_arrow_string
));
20126 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
20128 overlay_arrow_seen
= 1;
20131 /* Highlight trailing whitespace. */
20132 if (!NILP (Vshow_trailing_whitespace
))
20133 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
20135 /* Compute pixel dimensions of this line. */
20136 compute_line_metrics (it
);
20138 /* Implementation note: No changes in the glyphs of ROW or in their
20139 faces can be done past this point, because compute_line_metrics
20140 computes ROW's hash value and stores it within the glyph_row
20143 /* Record whether this row ends inside an ellipsis. */
20144 row
->ends_in_ellipsis_p
20145 = (it
->method
== GET_FROM_DISPLAY_VECTOR
20146 && it
->ellipsis_p
);
20148 /* Save fringe bitmaps in this row. */
20149 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
20150 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
20151 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
20152 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
20154 it
->left_user_fringe_bitmap
= 0;
20155 it
->left_user_fringe_face_id
= 0;
20156 it
->right_user_fringe_bitmap
= 0;
20157 it
->right_user_fringe_face_id
= 0;
20159 /* Maybe set the cursor. */
20160 cvpos
= it
->w
->cursor
.vpos
;
20162 /* In bidi-reordered rows, keep checking for proper cursor
20163 position even if one has been found already, because buffer
20164 positions in such rows change non-linearly with ROW->VPOS,
20165 when a line is continued. One exception: when we are at ZV,
20166 display cursor on the first suitable glyph row, since all
20167 the empty rows after that also have their position set to ZV. */
20168 /* FIXME: Revisit this when glyph ``spilling'' in continuation
20169 lines' rows is implemented for bidi-reordered rows. */
20171 && !MATRIX_ROW (it
->w
->desired_matrix
, cvpos
)->ends_at_zv_p
))
20172 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
20173 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
20174 && cursor_row_p (row
))
20175 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
20177 /* Prepare for the next line. This line starts horizontally at (X
20178 HPOS) = (0 0). Vertical positions are incremented. As a
20179 convenience for the caller, IT->glyph_row is set to the next
20181 it
->current_x
= it
->hpos
= 0;
20182 it
->current_y
+= row
->height
;
20183 SET_TEXT_POS (it
->eol_pos
, 0, 0);
20186 /* The next row should by default use the same value of the
20187 reversed_p flag as this one. set_iterator_to_next decides when
20188 it's a new paragraph, and PRODUCE_GLYPHS recomputes the value of
20189 the flag accordingly. */
20190 if (it
->glyph_row
< MATRIX_BOTTOM_TEXT_ROW (it
->w
->desired_matrix
, it
->w
))
20191 it
->glyph_row
->reversed_p
= row
->reversed_p
;
20192 it
->start
= row
->end
;
20193 return MATRIX_ROW_DISPLAYS_TEXT_P (row
);
20195 #undef RECORD_MAX_MIN_POS
20198 DEFUN ("current-bidi-paragraph-direction", Fcurrent_bidi_paragraph_direction
,
20199 Scurrent_bidi_paragraph_direction
, 0, 1, 0,
20200 doc
: /* Return paragraph direction at point in BUFFER.
20201 Value is either `left-to-right' or `right-to-left'.
20202 If BUFFER is omitted or nil, it defaults to the current buffer.
20204 Paragraph direction determines how the text in the paragraph is displayed.
20205 In left-to-right paragraphs, text begins at the left margin of the window
20206 and the reading direction is generally left to right. In right-to-left
20207 paragraphs, text begins at the right margin and is read from right to left.
20209 See also `bidi-paragraph-direction'. */)
20210 (Lisp_Object buffer
)
20212 struct buffer
*buf
= current_buffer
;
20213 struct buffer
*old
= buf
;
20215 if (! NILP (buffer
))
20217 CHECK_BUFFER (buffer
);
20218 buf
= XBUFFER (buffer
);
20221 if (NILP (BVAR (buf
, bidi_display_reordering
))
20222 || NILP (BVAR (buf
, enable_multibyte_characters
))
20223 /* When we are loading loadup.el, the character property tables
20224 needed for bidi iteration are not yet available. */
20225 || !NILP (Vpurify_flag
))
20226 return Qleft_to_right
;
20227 else if (!NILP (BVAR (buf
, bidi_paragraph_direction
)))
20228 return BVAR (buf
, bidi_paragraph_direction
);
20231 /* Determine the direction from buffer text. We could try to
20232 use current_matrix if it is up to date, but this seems fast
20233 enough as it is. */
20234 struct bidi_it itb
;
20235 ptrdiff_t pos
= BUF_PT (buf
);
20236 ptrdiff_t bytepos
= BUF_PT_BYTE (buf
);
20238 void *itb_data
= bidi_shelve_cache ();
20240 set_buffer_temp (buf
);
20241 /* bidi_paragraph_init finds the base direction of the paragraph
20242 by searching forward from paragraph start. We need the base
20243 direction of the current or _previous_ paragraph, so we need
20244 to make sure we are within that paragraph. To that end, find
20245 the previous non-empty line. */
20246 if (pos
>= ZV
&& pos
> BEGV
)
20247 DEC_BOTH (pos
, bytepos
);
20248 if (fast_looking_at (build_string ("[\f\t ]*\n"),
20249 pos
, bytepos
, ZV
, ZV_BYTE
, Qnil
) > 0)
20251 while ((c
= FETCH_BYTE (bytepos
)) == '\n'
20252 || c
== ' ' || c
== '\t' || c
== '\f')
20254 if (bytepos
<= BEGV_BYTE
)
20259 while (!CHAR_HEAD_P (FETCH_BYTE (bytepos
)))
20262 bidi_init_it (pos
, bytepos
, FRAME_WINDOW_P (SELECTED_FRAME ()), &itb
);
20263 itb
.paragraph_dir
= NEUTRAL_DIR
;
20264 itb
.string
.s
= NULL
;
20265 itb
.string
.lstring
= Qnil
;
20266 itb
.string
.bufpos
= 0;
20267 itb
.string
.unibyte
= 0;
20268 /* We have no window to use here for ignoring window-specific
20269 overlays. Using NULL for window pointer will cause
20270 compute_display_string_pos to use the current buffer. */
20272 bidi_paragraph_init (NEUTRAL_DIR
, &itb
, 1);
20273 bidi_unshelve_cache (itb_data
, 0);
20274 set_buffer_temp (old
);
20275 switch (itb
.paragraph_dir
)
20278 return Qleft_to_right
;
20281 return Qright_to_left
;
20289 DEFUN ("move-point-visually", Fmove_point_visually
,
20290 Smove_point_visually
, 1, 1, 0,
20291 doc
: /* Move point in the visual order in the specified DIRECTION.
20292 DIRECTION can be 1, meaning move to the right, or -1, which moves to the
20295 Value is the new character position of point. */)
20296 (Lisp_Object direction
)
20298 struct window
*w
= XWINDOW (selected_window
);
20299 struct buffer
*b
= XBUFFER (w
->contents
);
20300 struct glyph_row
*row
;
20302 Lisp_Object paragraph_dir
;
20304 #define ROW_GLYPH_NEWLINE_P(ROW,GLYPH) \
20305 (!(ROW)->continued_p \
20306 && INTEGERP ((GLYPH)->object) \
20307 && (GLYPH)->type == CHAR_GLYPH \
20308 && (GLYPH)->u.ch == ' ' \
20309 && (GLYPH)->charpos >= 0 \
20310 && !(GLYPH)->avoid_cursor_p)
20312 CHECK_NUMBER (direction
);
20313 dir
= XINT (direction
);
20319 /* If current matrix is up-to-date, we can use the information
20320 recorded in the glyphs, at least as long as the goal is on the
20322 if (w
->window_end_valid
20323 && !windows_or_buffers_changed
20325 && !b
->clip_changed
20326 && !b
->prevent_redisplay_optimizations_p
20327 && !window_outdated (w
)
20328 && w
->cursor
.vpos
>= 0
20329 && w
->cursor
.vpos
< w
->current_matrix
->nrows
20330 && (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
))->enabled_p
)
20332 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
20333 struct glyph
*e
= dir
> 0 ? g
+ row
->used
[TEXT_AREA
] : g
- 1;
20334 struct glyph
*gpt
= g
+ w
->cursor
.hpos
;
20336 for (g
= gpt
+ dir
; (dir
> 0 ? g
< e
: g
> e
); g
+= dir
)
20338 if (BUFFERP (g
->object
) && g
->charpos
!= PT
)
20340 SET_PT (g
->charpos
);
20341 w
->cursor
.vpos
= -1;
20342 return make_number (PT
);
20344 else if (!INTEGERP (g
->object
) && !EQ (g
->object
, gpt
->object
))
20348 if (BUFFERP (gpt
->object
))
20351 if ((gpt
->resolved_level
- row
->reversed_p
) % 2 == 0)
20352 new_pos
+= (row
->reversed_p
? -dir
: dir
);
20354 new_pos
-= (row
->reversed_p
? -dir
: dir
);;
20356 else if (BUFFERP (g
->object
))
20357 new_pos
= g
->charpos
;
20361 w
->cursor
.vpos
= -1;
20362 return make_number (PT
);
20364 else if (ROW_GLYPH_NEWLINE_P (row
, g
))
20366 /* Glyphs inserted at the end of a non-empty line for
20367 positioning the cursor have zero charpos, so we must
20368 deduce the value of point by other means. */
20369 if (g
->charpos
> 0)
20370 SET_PT (g
->charpos
);
20371 else if (row
->ends_at_zv_p
&& PT
!= ZV
)
20373 else if (PT
!= MATRIX_ROW_END_CHARPOS (row
) - 1)
20374 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
20377 w
->cursor
.vpos
= -1;
20378 return make_number (PT
);
20381 if (g
== e
|| INTEGERP (g
->object
))
20383 if (row
->truncated_on_left_p
|| row
->truncated_on_right_p
)
20384 goto simulate_display
;
20385 if (!row
->reversed_p
)
20389 if (row
< MATRIX_FIRST_TEXT_ROW (w
->current_matrix
)
20390 || row
> MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
20391 goto simulate_display
;
20395 if (row
->reversed_p
&& !row
->continued_p
)
20397 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
20398 w
->cursor
.vpos
= -1;
20399 return make_number (PT
);
20401 g
= row
->glyphs
[TEXT_AREA
];
20402 e
= g
+ row
->used
[TEXT_AREA
];
20403 for ( ; g
< e
; g
++)
20405 if (BUFFERP (g
->object
)
20406 /* Empty lines have only one glyph, which stands
20407 for the newline, and whose charpos is the
20408 buffer position of the newline. */
20409 || ROW_GLYPH_NEWLINE_P (row
, g
)
20410 /* When the buffer ends in a newline, the line at
20411 EOB also has one glyph, but its charpos is -1. */
20412 || (row
->ends_at_zv_p
20413 && !row
->reversed_p
20414 && INTEGERP (g
->object
)
20415 && g
->type
== CHAR_GLYPH
20416 && g
->u
.ch
== ' '))
20418 if (g
->charpos
> 0)
20419 SET_PT (g
->charpos
);
20420 else if (!row
->reversed_p
20421 && row
->ends_at_zv_p
20426 w
->cursor
.vpos
= -1;
20427 return make_number (PT
);
20433 if (!row
->reversed_p
&& !row
->continued_p
)
20435 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
20436 w
->cursor
.vpos
= -1;
20437 return make_number (PT
);
20439 e
= row
->glyphs
[TEXT_AREA
];
20440 g
= e
+ row
->used
[TEXT_AREA
] - 1;
20441 for ( ; g
>= e
; g
--)
20443 if (BUFFERP (g
->object
)
20444 || (ROW_GLYPH_NEWLINE_P (row
, g
)
20446 /* Empty R2L lines on GUI frames have the buffer
20447 position of the newline stored in the stretch
20449 || g
->type
== STRETCH_GLYPH
20450 || (row
->ends_at_zv_p
20452 && INTEGERP (g
->object
)
20453 && g
->type
== CHAR_GLYPH
20454 && g
->u
.ch
== ' '))
20456 if (g
->charpos
> 0)
20457 SET_PT (g
->charpos
);
20458 else if (row
->reversed_p
20459 && row
->ends_at_zv_p
20464 w
->cursor
.vpos
= -1;
20465 return make_number (PT
);
20474 /* If we wind up here, we failed to move by using the glyphs, so we
20475 need to simulate display instead. */
20478 paragraph_dir
= Fcurrent_bidi_paragraph_direction (w
->contents
);
20480 paragraph_dir
= Qleft_to_right
;
20481 if (EQ (paragraph_dir
, Qright_to_left
))
20483 if (PT
<= BEGV
&& dir
< 0)
20484 xsignal0 (Qbeginning_of_buffer
);
20485 else if (PT
>= ZV
&& dir
> 0)
20486 xsignal0 (Qend_of_buffer
);
20489 struct text_pos pt
;
20491 int pt_x
, target_x
, pixel_width
, pt_vpos
;
20493 bool overshoot_expected
= false;
20494 bool target_is_eol_p
= false;
20496 /* Setup the arena. */
20497 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
20498 start_display (&it
, w
, pt
);
20500 if (it
.cmp_it
.id
< 0
20501 && it
.method
== GET_FROM_STRING
20502 && it
.area
== TEXT_AREA
20503 && it
.string_from_display_prop_p
20504 && (it
.sp
> 0 && it
.stack
[it
.sp
- 1].method
== GET_FROM_BUFFER
))
20505 overshoot_expected
= true;
20507 /* Find the X coordinate of point. We start from the beginning
20508 of this or previous line to make sure we are before point in
20509 the logical order (since the move_it_* functions can only
20511 reseat_at_previous_visible_line_start (&it
);
20512 it
.current_x
= it
.hpos
= it
.current_y
= it
.vpos
= 0;
20513 if (IT_CHARPOS (it
) != PT
)
20514 move_it_to (&it
, overshoot_expected
? PT
- 1 : PT
,
20515 -1, -1, -1, MOVE_TO_POS
);
20516 pt_x
= it
.current_x
;
20518 if (dir
> 0 || overshoot_expected
)
20520 struct glyph_row
*row
= it
.glyph_row
;
20522 /* When point is at beginning of line, we don't have
20523 information about the glyph there loaded into struct
20524 it. Calling get_next_display_element fixes that. */
20526 get_next_display_element (&it
);
20527 at_eol_p
= ITERATOR_AT_END_OF_LINE_P (&it
);
20528 it
.glyph_row
= NULL
;
20529 PRODUCE_GLYPHS (&it
); /* compute it.pixel_width */
20530 it
.glyph_row
= row
;
20531 /* PRODUCE_GLYPHS advances it.current_x, so we must restore
20532 it, lest it will become out of sync with it's buffer
20534 it
.current_x
= pt_x
;
20537 at_eol_p
= ITERATOR_AT_END_OF_LINE_P (&it
);
20538 pixel_width
= it
.pixel_width
;
20539 if (overshoot_expected
&& at_eol_p
)
20541 else if (pixel_width
<= 0)
20544 /* If there's a display string at point, we are actually at the
20545 glyph to the left of point, so we need to correct the X
20547 if (overshoot_expected
)
20548 pt_x
+= pixel_width
;
20550 /* Compute target X coordinate, either to the left or to the
20551 right of point. On TTY frames, all characters have the same
20552 pixel width of 1, so we can use that. On GUI frames we don't
20553 have an easy way of getting at the pixel width of the
20554 character to the left of point, so we use a different method
20555 of getting to that place. */
20557 target_x
= pt_x
+ pixel_width
;
20559 target_x
= pt_x
- (!FRAME_WINDOW_P (it
.f
)) * pixel_width
;
20561 /* Target X coordinate could be one line above or below the line
20562 of point, in which case we need to adjust the target X
20563 coordinate. Also, if moving to the left, we need to begin at
20564 the left edge of the point's screen line. */
20569 start_display (&it
, w
, pt
);
20570 reseat_at_previous_visible_line_start (&it
);
20571 it
.current_x
= it
.current_y
= it
.hpos
= 0;
20573 move_it_by_lines (&it
, pt_vpos
);
20577 move_it_by_lines (&it
, -1);
20578 target_x
= it
.last_visible_x
- !FRAME_WINDOW_P (it
.f
);
20579 target_is_eol_p
= true;
20585 || (target_x
>= it
.last_visible_x
20586 && it
.line_wrap
!= TRUNCATE
))
20589 move_it_by_lines (&it
, 0);
20590 move_it_by_lines (&it
, 1);
20595 /* Move to the target X coordinate. */
20596 #ifdef HAVE_WINDOW_SYSTEM
20597 /* On GUI frames, as we don't know the X coordinate of the
20598 character to the left of point, moving point to the left
20599 requires walking, one grapheme cluster at a time, until we
20600 find ourself at a place immediately to the left of the
20601 character at point. */
20602 if (FRAME_WINDOW_P (it
.f
) && dir
< 0)
20604 struct text_pos new_pos
= it
.current
.pos
;
20605 enum move_it_result rc
= MOVE_X_REACHED
;
20607 while (it
.current_x
+ it
.pixel_width
<= target_x
20608 && rc
== MOVE_X_REACHED
)
20610 int new_x
= it
.current_x
+ it
.pixel_width
;
20612 new_pos
= it
.current
.pos
;
20613 if (new_x
== it
.current_x
)
20615 rc
= move_it_in_display_line_to (&it
, ZV
, new_x
,
20616 MOVE_TO_POS
| MOVE_TO_X
);
20617 if (ITERATOR_AT_END_OF_LINE_P (&it
) && !target_is_eol_p
)
20620 /* If we ended up on a composed character inside
20621 bidi-reordered text (e.g., Hebrew text with diacritics),
20622 the iterator gives us the buffer position of the last (in
20623 logical order) character of the composed grapheme cluster,
20624 which is not what we want. So we cheat: we compute the
20625 character position of the character that follows (in the
20626 logical order) the one where the above loop stopped. That
20627 character will appear on display to the left of point. */
20629 && it
.bidi_it
.scan_dir
== -1
20630 && new_pos
.charpos
- IT_CHARPOS (it
) > 1)
20632 new_pos
.charpos
= IT_CHARPOS (it
) + 1;
20633 new_pos
.bytepos
= CHAR_TO_BYTE (new_pos
.charpos
);
20635 it
.current
.pos
= new_pos
;
20639 if (it
.current_x
!= target_x
)
20640 move_it_in_display_line_to (&it
, ZV
, target_x
, MOVE_TO_POS
| MOVE_TO_X
);
20642 /* When lines are truncated, the above loop will stop at the
20643 window edge. But we want to get to the end of line, even if
20644 it is beyond the window edge; automatic hscroll will then
20645 scroll the window to show point as appropriate. */
20646 if (target_is_eol_p
&& it
.line_wrap
== TRUNCATE
20647 && get_next_display_element (&it
))
20649 struct text_pos new_pos
= it
.current
.pos
;
20651 while (!ITERATOR_AT_END_OF_LINE_P (&it
))
20653 set_iterator_to_next (&it
, 0);
20654 if (it
.method
== GET_FROM_BUFFER
)
20655 new_pos
= it
.current
.pos
;
20656 if (!get_next_display_element (&it
))
20660 it
.current
.pos
= new_pos
;
20663 /* If we ended up in a display string that covers point, move to
20664 buffer position to the right in the visual order. */
20667 while (IT_CHARPOS (it
) == PT
)
20669 set_iterator_to_next (&it
, 0);
20670 if (!get_next_display_element (&it
))
20675 /* Move point to that position. */
20676 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
20679 return make_number (PT
);
20681 #undef ROW_GLYPH_NEWLINE_P
20685 /***********************************************************************
20687 ***********************************************************************/
20689 /* Redisplay the menu bar in the frame for window W.
20691 The menu bar of X frames that don't have X toolkit support is
20692 displayed in a special window W->frame->menu_bar_window.
20694 The menu bar of terminal frames is treated specially as far as
20695 glyph matrices are concerned. Menu bar lines are not part of
20696 windows, so the update is done directly on the frame matrix rows
20697 for the menu bar. */
20700 display_menu_bar (struct window
*w
)
20702 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20707 /* Don't do all this for graphical frames. */
20709 if (FRAME_W32_P (f
))
20712 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
20718 if (FRAME_NS_P (f
))
20720 #endif /* HAVE_NS */
20722 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
20723 eassert (!FRAME_WINDOW_P (f
));
20724 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
20725 it
.first_visible_x
= 0;
20726 /* PXW: Use FRAME_PIXEL_WIDTH (f) here ? */
20727 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
20728 #elif defined (HAVE_X_WINDOWS) /* X without toolkit. */
20729 if (FRAME_WINDOW_P (f
))
20731 /* Menu bar lines are displayed in the desired matrix of the
20732 dummy window menu_bar_window. */
20733 struct window
*menu_w
;
20734 menu_w
= XWINDOW (f
->menu_bar_window
);
20735 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
20737 it
.first_visible_x
= 0;
20738 /* PXW: Use FRAME_PIXEL_WIDTH (f) here ? */
20739 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
20742 #endif /* not USE_X_TOOLKIT and not USE_GTK */
20744 /* This is a TTY frame, i.e. character hpos/vpos are used as
20746 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
20748 it
.first_visible_x
= 0;
20749 it
.last_visible_x
= FRAME_COLS (f
);
20752 /* FIXME: This should be controlled by a user option. See the
20753 comments in redisplay_tool_bar and display_mode_line about
20755 it
.paragraph_embedding
= L2R
;
20757 /* Clear all rows of the menu bar. */
20758 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
20760 struct glyph_row
*row
= it
.glyph_row
+ i
;
20761 clear_glyph_row (row
);
20762 row
->enabled_p
= 1;
20763 row
->full_width_p
= 1;
20766 /* Display all items of the menu bar. */
20767 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
20768 for (i
= 0; i
< ASIZE (items
); i
+= 4)
20770 Lisp_Object string
;
20772 /* Stop at nil string. */
20773 string
= AREF (items
, i
+ 1);
20777 /* Remember where item was displayed. */
20778 ASET (items
, i
+ 3, make_number (it
.hpos
));
20780 /* Display the item, pad with one space. */
20781 if (it
.current_x
< it
.last_visible_x
)
20782 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
20783 SCHARS (string
) + 1, 0, 0, -1);
20786 /* Fill out the line with spaces. */
20787 if (it
.current_x
< it
.last_visible_x
)
20788 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
20790 /* Compute the total height of the lines. */
20791 compute_line_metrics (&it
);
20794 /* Deep copy of a glyph row, including the glyphs. */
20796 deep_copy_glyph_row (struct glyph_row
*to
, struct glyph_row
*from
)
20798 struct glyph
*pointers
[1 + LAST_AREA
];
20799 int to_used
= to
->used
[TEXT_AREA
];
20801 /* Save glyph pointers of TO. */
20802 memcpy (pointers
, to
->glyphs
, sizeof to
->glyphs
);
20804 /* Do a structure assignment. */
20807 /* Restore original glyph pointers of TO. */
20808 memcpy (to
->glyphs
, pointers
, sizeof to
->glyphs
);
20810 /* Copy the glyphs. */
20811 memcpy (to
->glyphs
[TEXT_AREA
], from
->glyphs
[TEXT_AREA
],
20812 min (from
->used
[TEXT_AREA
], to_used
) * sizeof (struct glyph
));
20814 /* If we filled only part of the TO row, fill the rest with
20815 space_glyph (which will display as empty space). */
20816 if (to_used
> from
->used
[TEXT_AREA
])
20817 fill_up_frame_row_with_spaces (to
, to_used
);
20820 /* Display one menu item on a TTY, by overwriting the glyphs in the
20821 frame F's desired glyph matrix with glyphs produced from the menu
20822 item text. Called from term.c to display TTY drop-down menus one
20825 ITEM_TEXT is the menu item text as a C string.
20827 FACE_ID is the face ID to be used for this menu item. FACE_ID
20828 could specify one of 3 faces: a face for an enabled item, a face
20829 for a disabled item, or a face for a selected item.
20831 X and Y are coordinates of the first glyph in the frame's desired
20832 matrix to be overwritten by the menu item. Since this is a TTY, Y
20833 is the zero-based number of the glyph row and X is the zero-based
20834 glyph number in the row, starting from left, where to start
20835 displaying the item.
20837 SUBMENU non-zero means this menu item drops down a submenu, which
20838 should be indicated by displaying a proper visual cue after the
20842 display_tty_menu_item (const char *item_text
, int width
, int face_id
,
20843 int x
, int y
, int submenu
)
20846 struct frame
*f
= SELECTED_FRAME ();
20847 struct window
*w
= XWINDOW (f
->selected_window
);
20848 int saved_used
, saved_truncated
, saved_width
, saved_reversed
;
20849 struct glyph_row
*row
;
20850 size_t item_len
= strlen (item_text
);
20852 eassert (FRAME_TERMCAP_P (f
));
20854 /* Don't write beyond the matrix's last row. This can happen for
20855 TTY screens that are not high enough to show the entire menu.
20856 (This is actually a bit of defensive programming, as
20857 tty_menu_display already limits the number of menu items to one
20858 less than the number of screen lines.) */
20859 if (y
>= f
->desired_matrix
->nrows
)
20862 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
+ y
, MENU_FACE_ID
);
20863 it
.first_visible_x
= 0;
20864 it
.last_visible_x
= FRAME_COLS (f
) - 1;
20865 row
= it
.glyph_row
;
20866 /* Start with the row contents from the current matrix. */
20867 deep_copy_glyph_row (row
, f
->current_matrix
->rows
+ y
);
20868 saved_width
= row
->full_width_p
;
20869 row
->full_width_p
= 1;
20870 saved_reversed
= row
->reversed_p
;
20871 row
->reversed_p
= 0;
20872 row
->enabled_p
= 1;
20874 /* Arrange for the menu item glyphs to start at (X,Y) and have the
20876 eassert (x
< f
->desired_matrix
->matrix_w
);
20877 it
.current_x
= it
.hpos
= x
;
20878 it
.current_y
= it
.vpos
= y
;
20879 saved_used
= row
->used
[TEXT_AREA
];
20880 saved_truncated
= row
->truncated_on_right_p
;
20881 row
->used
[TEXT_AREA
] = x
;
20882 it
.face_id
= face_id
;
20883 it
.line_wrap
= TRUNCATE
;
20885 /* FIXME: This should be controlled by a user option. See the
20886 comments in redisplay_tool_bar and display_mode_line about this.
20887 Also, if paragraph_embedding could ever be R2L, changes will be
20888 needed to avoid shifting to the right the row characters in
20889 term.c:append_glyph. */
20890 it
.paragraph_embedding
= L2R
;
20892 /* Pad with a space on the left. */
20893 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 1, 0, FRAME_COLS (f
) - 1, -1);
20895 /* Display the menu item, pad with spaces to WIDTH. */
20898 display_string (item_text
, Qnil
, Qnil
, 0, 0, &it
,
20899 item_len
, 0, FRAME_COLS (f
) - 1, -1);
20901 /* Indicate with " >" that there's a submenu. */
20902 display_string (" >", Qnil
, Qnil
, 0, 0, &it
, width
, 0,
20903 FRAME_COLS (f
) - 1, -1);
20906 display_string (item_text
, Qnil
, Qnil
, 0, 0, &it
,
20907 width
, 0, FRAME_COLS (f
) - 1, -1);
20909 row
->used
[TEXT_AREA
] = max (saved_used
, row
->used
[TEXT_AREA
]);
20910 row
->truncated_on_right_p
= saved_truncated
;
20911 row
->hash
= row_hash (row
);
20912 row
->full_width_p
= saved_width
;
20913 row
->reversed_p
= saved_reversed
;
20916 /***********************************************************************
20918 ***********************************************************************/
20920 /* Redisplay mode lines in the window tree whose root is WINDOW. If
20921 FORCE is non-zero, redisplay mode lines unconditionally.
20922 Otherwise, redisplay only mode lines that are garbaged. Value is
20923 the number of windows whose mode lines were redisplayed. */
20926 redisplay_mode_lines (Lisp_Object window
, bool force
)
20930 while (!NILP (window
))
20932 struct window
*w
= XWINDOW (window
);
20934 if (WINDOWP (w
->contents
))
20935 nwindows
+= redisplay_mode_lines (w
->contents
, force
);
20937 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
20938 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
20940 struct text_pos lpoint
;
20941 struct buffer
*old
= current_buffer
;
20943 /* Set the window's buffer for the mode line display. */
20944 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
20945 set_buffer_internal_1 (XBUFFER (w
->contents
));
20947 /* Point refers normally to the selected window. For any
20948 other window, set up appropriate value. */
20949 if (!EQ (window
, selected_window
))
20951 struct text_pos pt
;
20953 CLIP_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
20954 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
20957 /* Display mode lines. */
20958 clear_glyph_matrix (w
->desired_matrix
);
20959 if (display_mode_lines (w
))
20962 /* Restore old settings. */
20963 set_buffer_internal_1 (old
);
20964 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
20974 /* Display the mode and/or header line of window W. Value is the
20975 sum number of mode lines and header lines displayed. */
20978 display_mode_lines (struct window
*w
)
20980 Lisp_Object old_selected_window
= selected_window
;
20981 Lisp_Object old_selected_frame
= selected_frame
;
20982 Lisp_Object new_frame
= w
->frame
;
20983 Lisp_Object old_frame_selected_window
= XFRAME (new_frame
)->selected_window
;
20986 selected_frame
= new_frame
;
20987 /* FIXME: If we were to allow the mode-line's computation changing the buffer
20988 or window's point, then we'd need select_window_1 here as well. */
20989 XSETWINDOW (selected_window
, w
);
20990 XFRAME (new_frame
)->selected_window
= selected_window
;
20992 /* These will be set while the mode line specs are processed. */
20993 line_number_displayed
= 0;
20994 w
->column_number_displayed
= -1;
20996 if (WINDOW_WANTS_MODELINE_P (w
))
20998 struct window
*sel_w
= XWINDOW (old_selected_window
);
21000 /* Select mode line face based on the real selected window. */
21001 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
21002 BVAR (current_buffer
, mode_line_format
));
21006 if (WINDOW_WANTS_HEADER_LINE_P (w
))
21008 display_mode_line (w
, HEADER_LINE_FACE_ID
,
21009 BVAR (current_buffer
, header_line_format
));
21013 XFRAME (new_frame
)->selected_window
= old_frame_selected_window
;
21014 selected_frame
= old_selected_frame
;
21015 selected_window
= old_selected_window
;
21017 w
->must_be_updated_p
= true;
21022 /* Display mode or header line of window W. FACE_ID specifies which
21023 line to display; it is either MODE_LINE_FACE_ID or
21024 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
21025 display. Value is the pixel height of the mode/header line
21029 display_mode_line (struct window
*w
, enum face_id face_id
, Lisp_Object format
)
21033 ptrdiff_t count
= SPECPDL_INDEX ();
21035 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
21036 /* Don't extend on a previously drawn mode-line.
21037 This may happen if called from pos_visible_p. */
21038 it
.glyph_row
->enabled_p
= 0;
21039 prepare_desired_row (it
.glyph_row
);
21041 it
.glyph_row
->mode_line_p
= 1;
21043 /* FIXME: This should be controlled by a user option. But
21044 supporting such an option is not trivial, since the mode line is
21045 made up of many separate strings. */
21046 it
.paragraph_embedding
= L2R
;
21048 record_unwind_protect (unwind_format_mode_line
,
21049 format_mode_line_unwind_data (NULL
, NULL
, Qnil
, 0));
21051 mode_line_target
= MODE_LINE_DISPLAY
;
21053 /* Temporarily make frame's keyboard the current kboard so that
21054 kboard-local variables in the mode_line_format will get the right
21056 push_kboard (FRAME_KBOARD (it
.f
));
21057 record_unwind_save_match_data ();
21058 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
21061 unbind_to (count
, Qnil
);
21063 /* Fill up with spaces. */
21064 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
21066 compute_line_metrics (&it
);
21067 it
.glyph_row
->full_width_p
= 1;
21068 it
.glyph_row
->continued_p
= 0;
21069 it
.glyph_row
->truncated_on_left_p
= 0;
21070 it
.glyph_row
->truncated_on_right_p
= 0;
21072 /* Make a 3D mode-line have a shadow at its right end. */
21073 face
= FACE_FROM_ID (it
.f
, face_id
);
21074 extend_face_to_end_of_line (&it
);
21075 if (face
->box
!= FACE_NO_BOX
)
21077 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
21078 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
21079 last
->right_box_line_p
= 1;
21082 return it
.glyph_row
->height
;
21085 /* Move element ELT in LIST to the front of LIST.
21086 Return the updated list. */
21089 move_elt_to_front (Lisp_Object elt
, Lisp_Object list
)
21091 register Lisp_Object tail
, prev
;
21092 register Lisp_Object tem
;
21096 while (CONSP (tail
))
21102 /* Splice out the link TAIL. */
21104 list
= XCDR (tail
);
21106 Fsetcdr (prev
, XCDR (tail
));
21108 /* Now make it the first. */
21109 Fsetcdr (tail
, list
);
21114 tail
= XCDR (tail
);
21118 /* Not found--return unchanged LIST. */
21122 /* Contribute ELT to the mode line for window IT->w. How it
21123 translates into text depends on its data type.
21125 IT describes the display environment in which we display, as usual.
21127 DEPTH is the depth in recursion. It is used to prevent
21128 infinite recursion here.
21130 FIELD_WIDTH is the number of characters the display of ELT should
21131 occupy in the mode line, and PRECISION is the maximum number of
21132 characters to display from ELT's representation. See
21133 display_string for details.
21135 Returns the hpos of the end of the text generated by ELT.
21137 PROPS is a property list to add to any string we encounter.
21139 If RISKY is nonzero, remove (disregard) any properties in any string
21140 we encounter, and ignore :eval and :propertize.
21142 The global variable `mode_line_target' determines whether the
21143 output is passed to `store_mode_line_noprop',
21144 `store_mode_line_string', or `display_string'. */
21147 display_mode_element (struct it
*it
, int depth
, int field_width
, int precision
,
21148 Lisp_Object elt
, Lisp_Object props
, int risky
)
21150 int n
= 0, field
, prec
;
21155 elt
= build_string ("*too-deep*");
21159 switch (XTYPE (elt
))
21163 /* A string: output it and check for %-constructs within it. */
21165 ptrdiff_t offset
= 0;
21167 if (SCHARS (elt
) > 0
21168 && (!NILP (props
) || risky
))
21170 Lisp_Object oprops
, aelt
;
21171 oprops
= Ftext_properties_at (make_number (0), elt
);
21173 /* If the starting string's properties are not what
21174 we want, translate the string. Also, if the string
21175 is risky, do that anyway. */
21177 if (NILP (Fequal (props
, oprops
)) || risky
)
21179 /* If the starting string has properties,
21180 merge the specified ones onto the existing ones. */
21181 if (! NILP (oprops
) && !risky
)
21185 oprops
= Fcopy_sequence (oprops
);
21187 while (CONSP (tem
))
21189 oprops
= Fplist_put (oprops
, XCAR (tem
),
21190 XCAR (XCDR (tem
)));
21191 tem
= XCDR (XCDR (tem
));
21196 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
21197 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
21199 /* AELT is what we want. Move it to the front
21200 without consing. */
21202 mode_line_proptrans_alist
21203 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
21209 /* If AELT has the wrong props, it is useless.
21210 so get rid of it. */
21212 mode_line_proptrans_alist
21213 = Fdelq (aelt
, mode_line_proptrans_alist
);
21215 elt
= Fcopy_sequence (elt
);
21216 Fset_text_properties (make_number (0), Flength (elt
),
21218 /* Add this item to mode_line_proptrans_alist. */
21219 mode_line_proptrans_alist
21220 = Fcons (Fcons (elt
, props
),
21221 mode_line_proptrans_alist
);
21222 /* Truncate mode_line_proptrans_alist
21223 to at most 50 elements. */
21224 tem
= Fnthcdr (make_number (50),
21225 mode_line_proptrans_alist
);
21227 XSETCDR (tem
, Qnil
);
21236 prec
= precision
- n
;
21237 switch (mode_line_target
)
21239 case MODE_LINE_NOPROP
:
21240 case MODE_LINE_TITLE
:
21241 n
+= store_mode_line_noprop (SSDATA (elt
), -1, prec
);
21243 case MODE_LINE_STRING
:
21244 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
21246 case MODE_LINE_DISPLAY
:
21247 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
21248 0, prec
, 0, STRING_MULTIBYTE (elt
));
21255 /* Handle the non-literal case. */
21257 while ((precision
<= 0 || n
< precision
)
21258 && SREF (elt
, offset
) != 0
21259 && (mode_line_target
!= MODE_LINE_DISPLAY
21260 || it
->current_x
< it
->last_visible_x
))
21262 ptrdiff_t last_offset
= offset
;
21264 /* Advance to end of string or next format specifier. */
21265 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
21268 if (offset
- 1 != last_offset
)
21270 ptrdiff_t nchars
, nbytes
;
21272 /* Output to end of string or up to '%'. Field width
21273 is length of string. Don't output more than
21274 PRECISION allows us. */
21277 prec
= c_string_width (SDATA (elt
) + last_offset
,
21278 offset
- last_offset
, precision
- n
,
21281 switch (mode_line_target
)
21283 case MODE_LINE_NOPROP
:
21284 case MODE_LINE_TITLE
:
21285 n
+= store_mode_line_noprop (SSDATA (elt
) + last_offset
, 0, prec
);
21287 case MODE_LINE_STRING
:
21289 ptrdiff_t bytepos
= last_offset
;
21290 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
21291 ptrdiff_t endpos
= (precision
<= 0
21292 ? string_byte_to_char (elt
, offset
)
21293 : charpos
+ nchars
);
21295 n
+= store_mode_line_string (NULL
,
21296 Fsubstring (elt
, make_number (charpos
),
21297 make_number (endpos
)),
21301 case MODE_LINE_DISPLAY
:
21303 ptrdiff_t bytepos
= last_offset
;
21304 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
21306 if (precision
<= 0)
21307 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
21308 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
21310 STRING_MULTIBYTE (elt
));
21315 else /* c == '%' */
21317 ptrdiff_t percent_position
= offset
;
21319 /* Get the specified minimum width. Zero means
21322 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
21323 field
= field
* 10 + c
- '0';
21325 /* Don't pad beyond the total padding allowed. */
21326 if (field_width
- n
> 0 && field
> field_width
- n
)
21327 field
= field_width
- n
;
21329 /* Note that either PRECISION <= 0 or N < PRECISION. */
21330 prec
= precision
- n
;
21333 n
+= display_mode_element (it
, depth
, field
, prec
,
21334 Vglobal_mode_string
, props
,
21339 ptrdiff_t bytepos
, charpos
;
21341 Lisp_Object string
;
21343 bytepos
= percent_position
;
21344 charpos
= (STRING_MULTIBYTE (elt
)
21345 ? string_byte_to_char (elt
, bytepos
)
21347 spec
= decode_mode_spec (it
->w
, c
, field
, &string
);
21348 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
21350 switch (mode_line_target
)
21352 case MODE_LINE_NOPROP
:
21353 case MODE_LINE_TITLE
:
21354 n
+= store_mode_line_noprop (spec
, field
, prec
);
21356 case MODE_LINE_STRING
:
21358 Lisp_Object tem
= build_string (spec
);
21359 props
= Ftext_properties_at (make_number (charpos
), elt
);
21360 /* Should only keep face property in props */
21361 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
21364 case MODE_LINE_DISPLAY
:
21366 int nglyphs_before
, nwritten
;
21368 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
21369 nwritten
= display_string (spec
, string
, elt
,
21374 /* Assign to the glyphs written above the
21375 string where the `%x' came from, position
21379 struct glyph
*glyph
21380 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
21384 for (i
= 0; i
< nwritten
; ++i
)
21386 glyph
[i
].object
= elt
;
21387 glyph
[i
].charpos
= charpos
;
21404 /* A symbol: process the value of the symbol recursively
21405 as if it appeared here directly. Avoid error if symbol void.
21406 Special case: if value of symbol is a string, output the string
21409 register Lisp_Object tem
;
21411 /* If the variable is not marked as risky to set
21412 then its contents are risky to use. */
21413 if (NILP (Fget (elt
, Qrisky_local_variable
)))
21416 tem
= Fboundp (elt
);
21419 tem
= Fsymbol_value (elt
);
21420 /* If value is a string, output that string literally:
21421 don't check for % within it. */
21425 if (!EQ (tem
, elt
))
21427 /* Give up right away for nil or t. */
21437 register Lisp_Object car
, tem
;
21439 /* A cons cell: five distinct cases.
21440 If first element is :eval or :propertize, do something special.
21441 If first element is a string or a cons, process all the elements
21442 and effectively concatenate them.
21443 If first element is a negative number, truncate displaying cdr to
21444 at most that many characters. If positive, pad (with spaces)
21445 to at least that many characters.
21446 If first element is a symbol, process the cadr or caddr recursively
21447 according to whether the symbol's value is non-nil or nil. */
21449 if (EQ (car
, QCeval
))
21451 /* An element of the form (:eval FORM) means evaluate FORM
21452 and use the result as mode line elements. */
21457 if (CONSP (XCDR (elt
)))
21460 spec
= safe_eval (XCAR (XCDR (elt
)));
21461 n
+= display_mode_element (it
, depth
, field_width
- n
,
21462 precision
- n
, spec
, props
,
21466 else if (EQ (car
, QCpropertize
))
21468 /* An element of the form (:propertize ELT PROPS...)
21469 means display ELT but applying properties PROPS. */
21474 if (CONSP (XCDR (elt
)))
21475 n
+= display_mode_element (it
, depth
, field_width
- n
,
21476 precision
- n
, XCAR (XCDR (elt
)),
21477 XCDR (XCDR (elt
)), risky
);
21479 else if (SYMBOLP (car
))
21481 tem
= Fboundp (car
);
21485 /* elt is now the cdr, and we know it is a cons cell.
21486 Use its car if CAR has a non-nil value. */
21489 tem
= Fsymbol_value (car
);
21496 /* Symbol's value is nil (or symbol is unbound)
21497 Get the cddr of the original list
21498 and if possible find the caddr and use that. */
21502 else if (!CONSP (elt
))
21507 else if (INTEGERP (car
))
21509 register int lim
= XINT (car
);
21513 /* Negative int means reduce maximum width. */
21514 if (precision
<= 0)
21517 precision
= min (precision
, -lim
);
21521 /* Padding specified. Don't let it be more than
21522 current maximum. */
21524 lim
= min (precision
, lim
);
21526 /* If that's more padding than already wanted, queue it.
21527 But don't reduce padding already specified even if
21528 that is beyond the current truncation point. */
21529 field_width
= max (lim
, field_width
);
21533 else if (STRINGP (car
) || CONSP (car
))
21535 Lisp_Object halftail
= elt
;
21539 && (precision
<= 0 || n
< precision
))
21541 n
+= display_mode_element (it
, depth
,
21542 /* Do padding only after the last
21543 element in the list. */
21544 (! CONSP (XCDR (elt
))
21547 precision
- n
, XCAR (elt
),
21551 if ((len
& 1) == 0)
21552 halftail
= XCDR (halftail
);
21553 /* Check for cycle. */
21554 if (EQ (halftail
, elt
))
21563 elt
= build_string ("*invalid*");
21567 /* Pad to FIELD_WIDTH. */
21568 if (field_width
> 0 && n
< field_width
)
21570 switch (mode_line_target
)
21572 case MODE_LINE_NOPROP
:
21573 case MODE_LINE_TITLE
:
21574 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
21576 case MODE_LINE_STRING
:
21577 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
21579 case MODE_LINE_DISPLAY
:
21580 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
21589 /* Store a mode-line string element in mode_line_string_list.
21591 If STRING is non-null, display that C string. Otherwise, the Lisp
21592 string LISP_STRING is displayed.
21594 FIELD_WIDTH is the minimum number of output glyphs to produce.
21595 If STRING has fewer characters than FIELD_WIDTH, pad to the right
21596 with spaces. FIELD_WIDTH <= 0 means don't pad.
21598 PRECISION is the maximum number of characters to output from
21599 STRING. PRECISION <= 0 means don't truncate the string.
21601 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
21602 properties to the string.
21604 PROPS are the properties to add to the string.
21605 The mode_line_string_face face property is always added to the string.
21609 store_mode_line_string (const char *string
, Lisp_Object lisp_string
, int copy_string
,
21610 int field_width
, int precision
, Lisp_Object props
)
21615 if (string
!= NULL
)
21617 len
= strlen (string
);
21618 if (precision
> 0 && len
> precision
)
21620 lisp_string
= make_string (string
, len
);
21622 props
= mode_line_string_face_prop
;
21623 else if (!NILP (mode_line_string_face
))
21625 Lisp_Object face
= Fplist_get (props
, Qface
);
21626 props
= Fcopy_sequence (props
);
21628 face
= mode_line_string_face
;
21630 face
= list2 (face
, mode_line_string_face
);
21631 props
= Fplist_put (props
, Qface
, face
);
21633 Fadd_text_properties (make_number (0), make_number (len
),
21634 props
, lisp_string
);
21638 len
= XFASTINT (Flength (lisp_string
));
21639 if (precision
> 0 && len
> precision
)
21642 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
21645 if (!NILP (mode_line_string_face
))
21649 props
= Ftext_properties_at (make_number (0), lisp_string
);
21650 face
= Fplist_get (props
, Qface
);
21652 face
= mode_line_string_face
;
21654 face
= list2 (face
, mode_line_string_face
);
21655 props
= list2 (Qface
, face
);
21657 lisp_string
= Fcopy_sequence (lisp_string
);
21660 Fadd_text_properties (make_number (0), make_number (len
),
21661 props
, lisp_string
);
21666 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
21670 if (field_width
> len
)
21672 field_width
-= len
;
21673 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
21675 Fadd_text_properties (make_number (0), make_number (field_width
),
21676 props
, lisp_string
);
21677 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
21685 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
21687 doc
: /* Format a string out of a mode line format specification.
21688 First arg FORMAT specifies the mode line format (see `mode-line-format'
21689 for details) to use.
21691 By default, the format is evaluated for the currently selected window.
21693 Optional second arg FACE specifies the face property to put on all
21694 characters for which no face is specified. The value nil means the
21695 default face. The value t means whatever face the window's mode line
21696 currently uses (either `mode-line' or `mode-line-inactive',
21697 depending on whether the window is the selected window or not).
21698 An integer value means the value string has no text
21701 Optional third and fourth args WINDOW and BUFFER specify the window
21702 and buffer to use as the context for the formatting (defaults
21703 are the selected window and the WINDOW's buffer). */)
21704 (Lisp_Object format
, Lisp_Object face
,
21705 Lisp_Object window
, Lisp_Object buffer
)
21710 struct buffer
*old_buffer
= NULL
;
21712 int no_props
= INTEGERP (face
);
21713 ptrdiff_t count
= SPECPDL_INDEX ();
21715 int string_start
= 0;
21717 w
= decode_any_window (window
);
21718 XSETWINDOW (window
, w
);
21721 buffer
= w
->contents
;
21722 CHECK_BUFFER (buffer
);
21724 /* Make formatting the modeline a non-op when noninteractive, otherwise
21725 there will be problems later caused by a partially initialized frame. */
21726 if (NILP (format
) || noninteractive
)
21727 return empty_unibyte_string
;
21732 face_id
= (NILP (face
) || EQ (face
, Qdefault
)) ? DEFAULT_FACE_ID
21733 : EQ (face
, Qt
) ? (EQ (window
, selected_window
)
21734 ? MODE_LINE_FACE_ID
: MODE_LINE_INACTIVE_FACE_ID
)
21735 : EQ (face
, Qmode_line
) ? MODE_LINE_FACE_ID
21736 : EQ (face
, Qmode_line_inactive
) ? MODE_LINE_INACTIVE_FACE_ID
21737 : EQ (face
, Qheader_line
) ? HEADER_LINE_FACE_ID
21738 : EQ (face
, Qtool_bar
) ? TOOL_BAR_FACE_ID
21741 old_buffer
= current_buffer
;
21743 /* Save things including mode_line_proptrans_alist,
21744 and set that to nil so that we don't alter the outer value. */
21745 record_unwind_protect (unwind_format_mode_line
,
21746 format_mode_line_unwind_data
21747 (XFRAME (WINDOW_FRAME (w
)),
21748 old_buffer
, selected_window
, 1));
21749 mode_line_proptrans_alist
= Qnil
;
21751 Fselect_window (window
, Qt
);
21752 set_buffer_internal_1 (XBUFFER (buffer
));
21754 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
21758 mode_line_target
= MODE_LINE_NOPROP
;
21759 mode_line_string_face_prop
= Qnil
;
21760 mode_line_string_list
= Qnil
;
21761 string_start
= MODE_LINE_NOPROP_LEN (0);
21765 mode_line_target
= MODE_LINE_STRING
;
21766 mode_line_string_list
= Qnil
;
21767 mode_line_string_face
= face
;
21768 mode_line_string_face_prop
21769 = NILP (face
) ? Qnil
: list2 (Qface
, face
);
21772 push_kboard (FRAME_KBOARD (it
.f
));
21773 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
21778 len
= MODE_LINE_NOPROP_LEN (string_start
);
21779 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
21783 mode_line_string_list
= Fnreverse (mode_line_string_list
);
21784 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
21785 empty_unibyte_string
);
21788 unbind_to (count
, Qnil
);
21792 /* Write a null-terminated, right justified decimal representation of
21793 the positive integer D to BUF using a minimal field width WIDTH. */
21796 pint2str (register char *buf
, register int width
, register ptrdiff_t d
)
21798 register char *p
= buf
;
21806 *p
++ = d
% 10 + '0';
21811 for (width
-= (int) (p
- buf
); width
> 0; --width
)
21822 /* Write a null-terminated, right justified decimal and "human
21823 readable" representation of the nonnegative integer D to BUF using
21824 a minimal field width WIDTH. D should be smaller than 999.5e24. */
21826 static const char power_letter
[] =
21840 pint2hrstr (char *buf
, int width
, ptrdiff_t d
)
21842 /* We aim to represent the nonnegative integer D as
21843 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
21844 ptrdiff_t quotient
= d
;
21846 /* -1 means: do not use TENTHS. */
21850 /* Length of QUOTIENT.TENTHS as a string. */
21856 if (quotient
>= 1000)
21858 /* Scale to the appropriate EXPONENT. */
21861 remainder
= quotient
% 1000;
21865 while (quotient
>= 1000);
21867 /* Round to nearest and decide whether to use TENTHS or not. */
21870 tenths
= remainder
/ 100;
21871 if (remainder
% 100 >= 50)
21878 if (quotient
== 10)
21886 if (remainder
>= 500)
21888 if (quotient
< 999)
21899 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
21900 if (tenths
== -1 && quotient
<= 99)
21907 p
= psuffix
= buf
+ max (width
, length
);
21909 /* Print EXPONENT. */
21910 *psuffix
++ = power_letter
[exponent
];
21913 /* Print TENTHS. */
21916 *--p
= '0' + tenths
;
21920 /* Print QUOTIENT. */
21923 int digit
= quotient
% 10;
21924 *--p
= '0' + digit
;
21926 while ((quotient
/= 10) != 0);
21928 /* Print leading spaces. */
21933 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
21934 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
21935 type of CODING_SYSTEM. Return updated pointer into BUF. */
21937 static unsigned char invalid_eol_type
[] = "(*invalid*)";
21940 decode_mode_spec_coding (Lisp_Object coding_system
, register char *buf
, int eol_flag
)
21943 bool multibyte
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
21944 const unsigned char *eol_str
;
21946 /* The EOL conversion we are using. */
21947 Lisp_Object eoltype
;
21949 val
= CODING_SYSTEM_SPEC (coding_system
);
21952 if (!VECTORP (val
)) /* Not yet decided. */
21954 *buf
++ = multibyte
? '-' : ' ';
21956 eoltype
= eol_mnemonic_undecided
;
21957 /* Don't mention EOL conversion if it isn't decided. */
21962 Lisp_Object eolvalue
;
21964 attrs
= AREF (val
, 0);
21965 eolvalue
= AREF (val
, 2);
21968 ? XFASTINT (CODING_ATTR_MNEMONIC (attrs
))
21973 /* The EOL conversion that is normal on this system. */
21975 if (NILP (eolvalue
)) /* Not yet decided. */
21976 eoltype
= eol_mnemonic_undecided
;
21977 else if (VECTORP (eolvalue
)) /* Not yet decided. */
21978 eoltype
= eol_mnemonic_undecided
;
21979 else /* eolvalue is Qunix, Qdos, or Qmac. */
21980 eoltype
= (EQ (eolvalue
, Qunix
)
21981 ? eol_mnemonic_unix
21982 : (EQ (eolvalue
, Qdos
) == 1
21983 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
21989 /* Mention the EOL conversion if it is not the usual one. */
21990 if (STRINGP (eoltype
))
21992 eol_str
= SDATA (eoltype
);
21993 eol_str_len
= SBYTES (eoltype
);
21995 else if (CHARACTERP (eoltype
))
21997 unsigned char *tmp
= alloca (MAX_MULTIBYTE_LENGTH
);
21998 int c
= XFASTINT (eoltype
);
21999 eol_str_len
= CHAR_STRING (c
, tmp
);
22004 eol_str
= invalid_eol_type
;
22005 eol_str_len
= sizeof (invalid_eol_type
) - 1;
22007 memcpy (buf
, eol_str
, eol_str_len
);
22008 buf
+= eol_str_len
;
22014 /* Return a string for the output of a mode line %-spec for window W,
22015 generated by character C. FIELD_WIDTH > 0 means pad the string
22016 returned with spaces to that value. Return a Lisp string in
22017 *STRING if the resulting string is taken from that Lisp string.
22019 Note we operate on the current buffer for most purposes. */
22021 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
22023 static const char *
22024 decode_mode_spec (struct window
*w
, register int c
, int field_width
,
22025 Lisp_Object
*string
)
22028 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
22029 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
22030 /* We are going to use f->decode_mode_spec_buffer as the buffer to
22031 produce strings from numerical values, so limit preposterously
22032 large values of FIELD_WIDTH to avoid overrunning the buffer's
22033 end. The size of the buffer is enough for FRAME_MESSAGE_BUF_SIZE
22034 bytes plus the terminating null. */
22035 int width
= min (field_width
, FRAME_MESSAGE_BUF_SIZE (f
));
22036 struct buffer
*b
= current_buffer
;
22044 if (!NILP (BVAR (b
, read_only
)))
22046 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
22051 /* This differs from %* only for a modified read-only buffer. */
22052 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
22054 if (!NILP (BVAR (b
, read_only
)))
22059 /* This differs from %* in ignoring read-only-ness. */
22060 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
22072 if (command_loop_level
> 5)
22074 p
= decode_mode_spec_buf
;
22075 for (i
= 0; i
< command_loop_level
; i
++)
22078 return decode_mode_spec_buf
;
22086 if (command_loop_level
> 5)
22088 p
= decode_mode_spec_buf
;
22089 for (i
= 0; i
< command_loop_level
; i
++)
22092 return decode_mode_spec_buf
;
22099 /* Let lots_of_dashes be a string of infinite length. */
22100 if (mode_line_target
== MODE_LINE_NOPROP
22101 || mode_line_target
== MODE_LINE_STRING
)
22103 if (field_width
<= 0
22104 || field_width
> sizeof (lots_of_dashes
))
22106 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
22107 decode_mode_spec_buf
[i
] = '-';
22108 decode_mode_spec_buf
[i
] = '\0';
22109 return decode_mode_spec_buf
;
22112 return lots_of_dashes
;
22116 obj
= BVAR (b
, name
);
22120 /* %c and %l are ignored in `frame-title-format'.
22121 (In redisplay_internal, the frame title is drawn _before_ the
22122 windows are updated, so the stuff which depends on actual
22123 window contents (such as %l) may fail to render properly, or
22124 even crash emacs.) */
22125 if (mode_line_target
== MODE_LINE_TITLE
)
22129 ptrdiff_t col
= current_column ();
22130 w
->column_number_displayed
= col
;
22131 pint2str (decode_mode_spec_buf
, width
, col
);
22132 return decode_mode_spec_buf
;
22136 #ifndef SYSTEM_MALLOC
22138 if (NILP (Vmemory_full
))
22141 return "!MEM FULL! ";
22148 /* %F displays the frame name. */
22149 if (!NILP (f
->title
))
22150 return SSDATA (f
->title
);
22151 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
22152 return SSDATA (f
->name
);
22156 obj
= BVAR (b
, filename
);
22161 ptrdiff_t size
= ZV
- BEGV
;
22162 pint2str (decode_mode_spec_buf
, width
, size
);
22163 return decode_mode_spec_buf
;
22168 ptrdiff_t size
= ZV
- BEGV
;
22169 pint2hrstr (decode_mode_spec_buf
, width
, size
);
22170 return decode_mode_spec_buf
;
22175 ptrdiff_t startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
22176 ptrdiff_t topline
, nlines
, height
;
22179 /* %c and %l are ignored in `frame-title-format'. */
22180 if (mode_line_target
== MODE_LINE_TITLE
)
22183 startpos
= marker_position (w
->start
);
22184 startpos_byte
= marker_byte_position (w
->start
);
22185 height
= WINDOW_TOTAL_LINES (w
);
22187 /* If we decided that this buffer isn't suitable for line numbers,
22188 don't forget that too fast. */
22189 if (w
->base_line_pos
== -1)
22192 /* If the buffer is very big, don't waste time. */
22193 if (INTEGERP (Vline_number_display_limit
)
22194 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
22196 w
->base_line_pos
= 0;
22197 w
->base_line_number
= 0;
22201 if (w
->base_line_number
> 0
22202 && w
->base_line_pos
> 0
22203 && w
->base_line_pos
<= startpos
)
22205 line
= w
->base_line_number
;
22206 linepos
= w
->base_line_pos
;
22207 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
22212 linepos
= BUF_BEGV (b
);
22213 linepos_byte
= BUF_BEGV_BYTE (b
);
22216 /* Count lines from base line to window start position. */
22217 nlines
= display_count_lines (linepos_byte
,
22221 topline
= nlines
+ line
;
22223 /* Determine a new base line, if the old one is too close
22224 or too far away, or if we did not have one.
22225 "Too close" means it's plausible a scroll-down would
22226 go back past it. */
22227 if (startpos
== BUF_BEGV (b
))
22229 w
->base_line_number
= topline
;
22230 w
->base_line_pos
= BUF_BEGV (b
);
22232 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
22233 || linepos
== BUF_BEGV (b
))
22235 ptrdiff_t limit
= BUF_BEGV (b
);
22236 ptrdiff_t limit_byte
= BUF_BEGV_BYTE (b
);
22237 ptrdiff_t position
;
22238 ptrdiff_t distance
=
22239 (height
* 2 + 30) * line_number_display_limit_width
;
22241 if (startpos
- distance
> limit
)
22243 limit
= startpos
- distance
;
22244 limit_byte
= CHAR_TO_BYTE (limit
);
22247 nlines
= display_count_lines (startpos_byte
,
22249 - (height
* 2 + 30),
22251 /* If we couldn't find the lines we wanted within
22252 line_number_display_limit_width chars per line,
22253 give up on line numbers for this window. */
22254 if (position
== limit_byte
&& limit
== startpos
- distance
)
22256 w
->base_line_pos
= -1;
22257 w
->base_line_number
= 0;
22261 w
->base_line_number
= topline
- nlines
;
22262 w
->base_line_pos
= BYTE_TO_CHAR (position
);
22265 /* Now count lines from the start pos to point. */
22266 nlines
= display_count_lines (startpos_byte
,
22267 PT_BYTE
, PT
, &junk
);
22269 /* Record that we did display the line number. */
22270 line_number_displayed
= 1;
22272 /* Make the string to show. */
22273 pint2str (decode_mode_spec_buf
, width
, topline
+ nlines
);
22274 return decode_mode_spec_buf
;
22277 char* p
= decode_mode_spec_buf
;
22278 int pad
= width
- 2;
22284 return decode_mode_spec_buf
;
22290 obj
= BVAR (b
, mode_name
);
22294 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
22300 ptrdiff_t pos
= marker_position (w
->start
);
22301 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
22303 if (w
->window_end_pos
<= BUF_Z (b
) - BUF_ZV (b
))
22305 if (pos
<= BUF_BEGV (b
))
22310 else if (pos
<= BUF_BEGV (b
))
22314 if (total
> 1000000)
22315 /* Do it differently for a large value, to avoid overflow. */
22316 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
22318 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
22319 /* We can't normally display a 3-digit number,
22320 so get us a 2-digit number that is close. */
22323 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
22324 return decode_mode_spec_buf
;
22328 /* Display percentage of size above the bottom of the screen. */
22331 ptrdiff_t toppos
= marker_position (w
->start
);
22332 ptrdiff_t botpos
= BUF_Z (b
) - w
->window_end_pos
;
22333 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
22335 if (botpos
>= BUF_ZV (b
))
22337 if (toppos
<= BUF_BEGV (b
))
22344 if (total
> 1000000)
22345 /* Do it differently for a large value, to avoid overflow. */
22346 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
22348 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
22349 /* We can't normally display a 3-digit number,
22350 so get us a 2-digit number that is close. */
22353 if (toppos
<= BUF_BEGV (b
))
22354 sprintf (decode_mode_spec_buf
, "Top%2"pD
"d%%", total
);
22356 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
22357 return decode_mode_spec_buf
;
22362 /* status of process */
22363 obj
= Fget_buffer_process (Fcurrent_buffer ());
22365 return "no process";
22367 obj
= Fsymbol_name (Fprocess_status (obj
));
22373 ptrdiff_t count
= inhibit_garbage_collection ();
22374 Lisp_Object val
= call1 (intern ("file-remote-p"),
22375 BVAR (current_buffer
, directory
));
22376 unbind_to (count
, Qnil
);
22385 /* coding-system (not including end-of-line format) */
22387 /* coding-system (including end-of-line type) */
22389 int eol_flag
= (c
== 'Z');
22390 char *p
= decode_mode_spec_buf
;
22392 if (! FRAME_WINDOW_P (f
))
22394 /* No need to mention EOL here--the terminal never needs
22395 to do EOL conversion. */
22396 p
= decode_mode_spec_coding (CODING_ID_NAME
22397 (FRAME_KEYBOARD_CODING (f
)->id
),
22399 p
= decode_mode_spec_coding (CODING_ID_NAME
22400 (FRAME_TERMINAL_CODING (f
)->id
),
22403 p
= decode_mode_spec_coding (BVAR (b
, buffer_file_coding_system
),
22406 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
22407 #ifdef subprocesses
22408 obj
= Fget_buffer_process (Fcurrent_buffer ());
22409 if (PROCESSP (obj
))
22411 p
= decode_mode_spec_coding
22412 (XPROCESS (obj
)->decode_coding_system
, p
, eol_flag
);
22413 p
= decode_mode_spec_coding
22414 (XPROCESS (obj
)->encode_coding_system
, p
, eol_flag
);
22416 #endif /* subprocesses */
22419 return decode_mode_spec_buf
;
22426 return SSDATA (obj
);
22433 /* Count up to COUNT lines starting from START_BYTE. COUNT negative
22434 means count lines back from START_BYTE. But don't go beyond
22435 LIMIT_BYTE. Return the number of lines thus found (always
22438 Set *BYTE_POS_PTR to the byte position where we stopped. This is
22439 either the position COUNT lines after/before START_BYTE, if we
22440 found COUNT lines, or LIMIT_BYTE if we hit the limit before finding
22444 display_count_lines (ptrdiff_t start_byte
,
22445 ptrdiff_t limit_byte
, ptrdiff_t count
,
22446 ptrdiff_t *byte_pos_ptr
)
22448 register unsigned char *cursor
;
22449 unsigned char *base
;
22451 register ptrdiff_t ceiling
;
22452 register unsigned char *ceiling_addr
;
22453 ptrdiff_t orig_count
= count
;
22455 /* If we are not in selective display mode,
22456 check only for newlines. */
22457 int selective_display
= (!NILP (BVAR (current_buffer
, selective_display
))
22458 && !INTEGERP (BVAR (current_buffer
, selective_display
)));
22462 while (start_byte
< limit_byte
)
22464 ceiling
= BUFFER_CEILING_OF (start_byte
);
22465 ceiling
= min (limit_byte
- 1, ceiling
);
22466 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
22467 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
22471 if (selective_display
)
22473 while (*cursor
!= '\n' && *cursor
!= 015
22474 && ++cursor
!= ceiling_addr
)
22476 if (cursor
== ceiling_addr
)
22481 cursor
= memchr (cursor
, '\n', ceiling_addr
- cursor
);
22490 start_byte
+= cursor
- base
;
22491 *byte_pos_ptr
= start_byte
;
22495 while (cursor
< ceiling_addr
);
22497 start_byte
+= ceiling_addr
- base
;
22502 while (start_byte
> limit_byte
)
22504 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
22505 ceiling
= max (limit_byte
, ceiling
);
22506 ceiling_addr
= BYTE_POS_ADDR (ceiling
);
22507 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
22510 if (selective_display
)
22512 while (--cursor
>= ceiling_addr
22513 && *cursor
!= '\n' && *cursor
!= 015)
22515 if (cursor
< ceiling_addr
)
22520 cursor
= memrchr (ceiling_addr
, '\n', cursor
- ceiling_addr
);
22527 start_byte
+= cursor
- base
+ 1;
22528 *byte_pos_ptr
= start_byte
;
22529 /* When scanning backwards, we should
22530 not count the newline posterior to which we stop. */
22531 return - orig_count
- 1;
22534 start_byte
+= ceiling_addr
- base
;
22538 *byte_pos_ptr
= limit_byte
;
22541 return - orig_count
+ count
;
22542 return orig_count
- count
;
22548 /***********************************************************************
22550 ***********************************************************************/
22552 /* Display a NUL-terminated string, starting with index START.
22554 If STRING is non-null, display that C string. Otherwise, the Lisp
22555 string LISP_STRING is displayed. There's a case that STRING is
22556 non-null and LISP_STRING is not nil. It means STRING is a string
22557 data of LISP_STRING. In that case, we display LISP_STRING while
22558 ignoring its text properties.
22560 If FACE_STRING is not nil, FACE_STRING_POS is a position in
22561 FACE_STRING. Display STRING or LISP_STRING with the face at
22562 FACE_STRING_POS in FACE_STRING:
22564 Display the string in the environment given by IT, but use the
22565 standard display table, temporarily.
22567 FIELD_WIDTH is the minimum number of output glyphs to produce.
22568 If STRING has fewer characters than FIELD_WIDTH, pad to the right
22569 with spaces. If STRING has more characters, more than FIELD_WIDTH
22570 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
22572 PRECISION is the maximum number of characters to output from
22573 STRING. PRECISION < 0 means don't truncate the string.
22575 This is roughly equivalent to printf format specifiers:
22577 FIELD_WIDTH PRECISION PRINTF
22578 ----------------------------------------
22584 MULTIBYTE zero means do not display multibyte chars, > 0 means do
22585 display them, and < 0 means obey the current buffer's value of
22586 enable_multibyte_characters.
22588 Value is the number of columns displayed. */
22591 display_string (const char *string
, Lisp_Object lisp_string
, Lisp_Object face_string
,
22592 ptrdiff_t face_string_pos
, ptrdiff_t start
, struct it
*it
,
22593 int field_width
, int precision
, int max_x
, int multibyte
)
22595 int hpos_at_start
= it
->hpos
;
22596 int saved_face_id
= it
->face_id
;
22597 struct glyph_row
*row
= it
->glyph_row
;
22598 ptrdiff_t it_charpos
;
22600 /* Initialize the iterator IT for iteration over STRING beginning
22601 with index START. */
22602 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
22603 precision
, field_width
, multibyte
);
22604 if (string
&& STRINGP (lisp_string
))
22605 /* LISP_STRING is the one returned by decode_mode_spec. We should
22606 ignore its text properties. */
22607 it
->stop_charpos
= it
->end_charpos
;
22609 /* If displaying STRING, set up the face of the iterator from
22610 FACE_STRING, if that's given. */
22611 if (STRINGP (face_string
))
22617 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
22618 0, &endptr
, it
->base_face_id
, 0);
22619 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22620 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
22623 /* Set max_x to the maximum allowed X position. Don't let it go
22624 beyond the right edge of the window. */
22626 max_x
= it
->last_visible_x
;
22628 max_x
= min (max_x
, it
->last_visible_x
);
22630 /* Skip over display elements that are not visible. because IT->w is
22632 if (it
->current_x
< it
->first_visible_x
)
22633 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
22634 MOVE_TO_POS
| MOVE_TO_X
);
22636 row
->ascent
= it
->max_ascent
;
22637 row
->height
= it
->max_ascent
+ it
->max_descent
;
22638 row
->phys_ascent
= it
->max_phys_ascent
;
22639 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
22640 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
22642 if (STRINGP (it
->string
))
22643 it_charpos
= IT_STRING_CHARPOS (*it
);
22645 it_charpos
= IT_CHARPOS (*it
);
22647 /* This condition is for the case that we are called with current_x
22648 past last_visible_x. */
22649 while (it
->current_x
< max_x
)
22651 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
22653 /* Get the next display element. */
22654 if (!get_next_display_element (it
))
22657 /* Produce glyphs. */
22658 x_before
= it
->current_x
;
22659 n_glyphs_before
= row
->used
[TEXT_AREA
];
22660 PRODUCE_GLYPHS (it
);
22662 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
22665 while (i
< nglyphs
)
22667 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
22669 if (it
->line_wrap
!= TRUNCATE
22670 && x
+ glyph
->pixel_width
> max_x
)
22672 /* End of continued line or max_x reached. */
22673 if (CHAR_GLYPH_PADDING_P (*glyph
))
22675 /* A wide character is unbreakable. */
22676 if (row
->reversed_p
)
22677 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
22678 - n_glyphs_before
);
22679 row
->used
[TEXT_AREA
] = n_glyphs_before
;
22680 it
->current_x
= x_before
;
22684 if (row
->reversed_p
)
22685 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
22686 - (n_glyphs_before
+ i
));
22687 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
22692 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
22694 /* Glyph is at least partially visible. */
22696 if (x
< it
->first_visible_x
)
22697 row
->x
= x
- it
->first_visible_x
;
22701 /* Glyph is off the left margin of the display area.
22702 Should not happen. */
22706 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
22707 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
22708 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
22709 row
->phys_height
= max (row
->phys_height
,
22710 it
->max_phys_ascent
+ it
->max_phys_descent
);
22711 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
22712 it
->max_extra_line_spacing
);
22713 x
+= glyph
->pixel_width
;
22717 /* Stop if max_x reached. */
22721 /* Stop at line ends. */
22722 if (ITERATOR_AT_END_OF_LINE_P (it
))
22724 it
->continuation_lines_width
= 0;
22728 set_iterator_to_next (it
, 1);
22729 if (STRINGP (it
->string
))
22730 it_charpos
= IT_STRING_CHARPOS (*it
);
22732 it_charpos
= IT_CHARPOS (*it
);
22734 /* Stop if truncating at the right edge. */
22735 if (it
->line_wrap
== TRUNCATE
22736 && it
->current_x
>= it
->last_visible_x
)
22738 /* Add truncation mark, but don't do it if the line is
22739 truncated at a padding space. */
22740 if (it_charpos
< it
->string_nchars
)
22742 if (!FRAME_WINDOW_P (it
->f
))
22746 if (it
->current_x
> it
->last_visible_x
)
22748 if (!row
->reversed_p
)
22750 for (ii
= row
->used
[TEXT_AREA
] - 1; ii
> 0; --ii
)
22751 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
22756 for (ii
= 0; ii
< row
->used
[TEXT_AREA
]; ii
++)
22757 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
22759 unproduce_glyphs (it
, ii
+ 1);
22760 ii
= row
->used
[TEXT_AREA
] - (ii
+ 1);
22762 for (n
= row
->used
[TEXT_AREA
]; ii
< n
; ++ii
)
22764 row
->used
[TEXT_AREA
] = ii
;
22765 produce_special_glyphs (it
, IT_TRUNCATION
);
22768 produce_special_glyphs (it
, IT_TRUNCATION
);
22770 row
->truncated_on_right_p
= 1;
22776 /* Maybe insert a truncation at the left. */
22777 if (it
->first_visible_x
22780 if (!FRAME_WINDOW_P (it
->f
)
22781 || (row
->reversed_p
22782 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
22783 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
22784 insert_left_trunc_glyphs (it
);
22785 row
->truncated_on_left_p
= 1;
22788 it
->face_id
= saved_face_id
;
22790 /* Value is number of columns displayed. */
22791 return it
->hpos
- hpos_at_start
;
22796 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
22797 appears as an element of LIST or as the car of an element of LIST.
22798 If PROPVAL is a list, compare each element against LIST in that
22799 way, and return 1/2 if any element of PROPVAL is found in LIST.
22800 Otherwise return 0. This function cannot quit.
22801 The return value is 2 if the text is invisible but with an ellipsis
22802 and 1 if it's invisible and without an ellipsis. */
22805 invisible_p (register Lisp_Object propval
, Lisp_Object list
)
22807 register Lisp_Object tail
, proptail
;
22809 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
22811 register Lisp_Object tem
;
22813 if (EQ (propval
, tem
))
22815 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
22816 return NILP (XCDR (tem
)) ? 1 : 2;
22819 if (CONSP (propval
))
22821 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
22823 Lisp_Object propelt
;
22824 propelt
= XCAR (proptail
);
22825 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
22827 register Lisp_Object tem
;
22829 if (EQ (propelt
, tem
))
22831 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
22832 return NILP (XCDR (tem
)) ? 1 : 2;
22840 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
22841 doc
: /* Non-nil if the property makes the text invisible.
22842 POS-OR-PROP can be a marker or number, in which case it is taken to be
22843 a position in the current buffer and the value of the `invisible' property
22844 is checked; or it can be some other value, which is then presumed to be the
22845 value of the `invisible' property of the text of interest.
22846 The non-nil value returned can be t for truly invisible text or something
22847 else if the text is replaced by an ellipsis. */)
22848 (Lisp_Object pos_or_prop
)
22851 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
22852 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
22854 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
22855 return (invis
== 0 ? Qnil
22857 : make_number (invis
));
22860 /* Calculate a width or height in pixels from a specification using
22861 the following elements:
22864 NUM - a (fractional) multiple of the default font width/height
22865 (NUM) - specifies exactly NUM pixels
22866 UNIT - a fixed number of pixels, see below.
22867 ELEMENT - size of a display element in pixels, see below.
22868 (NUM . SPEC) - equals NUM * SPEC
22869 (+ SPEC SPEC ...) - add pixel values
22870 (- SPEC SPEC ...) - subtract pixel values
22871 (- SPEC) - negate pixel value
22874 INT or FLOAT - a number constant
22875 SYMBOL - use symbol's (buffer local) variable binding.
22878 in - pixels per inch *)
22879 mm - pixels per 1/1000 meter *)
22880 cm - pixels per 1/100 meter *)
22881 width - width of current font in pixels.
22882 height - height of current font in pixels.
22884 *) using the ratio(s) defined in display-pixels-per-inch.
22888 left-fringe - left fringe width in pixels
22889 right-fringe - right fringe width in pixels
22891 left-margin - left margin width in pixels
22892 right-margin - right margin width in pixels
22894 scroll-bar - scroll-bar area width in pixels
22898 Pixels corresponding to 5 inches:
22901 Total width of non-text areas on left side of window (if scroll-bar is on left):
22902 '(space :width (+ left-fringe left-margin scroll-bar))
22904 Align to first text column (in header line):
22905 '(space :align-to 0)
22907 Align to middle of text area minus half the width of variable `my-image'
22908 containing a loaded image:
22909 '(space :align-to (0.5 . (- text my-image)))
22911 Width of left margin minus width of 1 character in the default font:
22912 '(space :width (- left-margin 1))
22914 Width of left margin minus width of 2 characters in the current font:
22915 '(space :width (- left-margin (2 . width)))
22917 Center 1 character over left-margin (in header line):
22918 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
22920 Different ways to express width of left fringe plus left margin minus one pixel:
22921 '(space :width (- (+ left-fringe left-margin) (1)))
22922 '(space :width (+ left-fringe left-margin (- (1))))
22923 '(space :width (+ left-fringe left-margin (-1)))
22928 calc_pixel_width_or_height (double *res
, struct it
*it
, Lisp_Object prop
,
22929 struct font
*font
, int width_p
, int *align_to
)
22933 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
22934 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
22937 return OK_PIXELS (0);
22939 eassert (FRAME_LIVE_P (it
->f
));
22941 if (SYMBOLP (prop
))
22943 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
22945 char *unit
= SSDATA (SYMBOL_NAME (prop
));
22947 if (unit
[0] == 'i' && unit
[1] == 'n')
22949 else if (unit
[0] == 'm' && unit
[1] == 'm')
22951 else if (unit
[0] == 'c' && unit
[1] == 'm')
22957 double ppi
= (width_p
? FRAME_RES_X (it
->f
)
22958 : FRAME_RES_Y (it
->f
));
22961 return OK_PIXELS (ppi
/ pixels
);
22966 #ifdef HAVE_WINDOW_SYSTEM
22967 if (EQ (prop
, Qheight
))
22968 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
22969 if (EQ (prop
, Qwidth
))
22970 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
22972 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
22973 return OK_PIXELS (1);
22976 if (EQ (prop
, Qtext
))
22977 return OK_PIXELS (width_p
22978 ? window_box_width (it
->w
, TEXT_AREA
)
22979 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
22981 if (align_to
&& *align_to
< 0)
22984 if (EQ (prop
, Qleft
))
22985 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
22986 if (EQ (prop
, Qright
))
22987 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
22988 if (EQ (prop
, Qcenter
))
22989 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
22990 + window_box_width (it
->w
, TEXT_AREA
) / 2);
22991 if (EQ (prop
, Qleft_fringe
))
22992 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22993 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
22994 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
22995 if (EQ (prop
, Qright_fringe
))
22996 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22997 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
22998 : window_box_right_offset (it
->w
, TEXT_AREA
));
22999 if (EQ (prop
, Qleft_margin
))
23000 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
23001 if (EQ (prop
, Qright_margin
))
23002 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
23003 if (EQ (prop
, Qscroll_bar
))
23004 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
23006 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
23007 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
23008 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
23013 if (EQ (prop
, Qleft_fringe
))
23014 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
23015 if (EQ (prop
, Qright_fringe
))
23016 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
23017 if (EQ (prop
, Qleft_margin
))
23018 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
23019 if (EQ (prop
, Qright_margin
))
23020 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
23021 if (EQ (prop
, Qscroll_bar
))
23022 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
23025 prop
= buffer_local_value_1 (prop
, it
->w
->contents
);
23026 if (EQ (prop
, Qunbound
))
23030 if (INTEGERP (prop
) || FLOATP (prop
))
23032 int base_unit
= (width_p
23033 ? FRAME_COLUMN_WIDTH (it
->f
)
23034 : FRAME_LINE_HEIGHT (it
->f
));
23035 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
23040 Lisp_Object car
= XCAR (prop
);
23041 Lisp_Object cdr
= XCDR (prop
);
23045 #ifdef HAVE_WINDOW_SYSTEM
23046 if (FRAME_WINDOW_P (it
->f
)
23047 && valid_image_p (prop
))
23049 ptrdiff_t id
= lookup_image (it
->f
, prop
);
23050 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
23052 return OK_PIXELS (width_p
? img
->width
: img
->height
);
23055 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
23061 while (CONSP (cdr
))
23063 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
23064 font
, width_p
, align_to
))
23067 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
23072 if (EQ (car
, Qminus
))
23074 return OK_PIXELS (pixels
);
23077 car
= buffer_local_value_1 (car
, it
->w
->contents
);
23078 if (EQ (car
, Qunbound
))
23082 if (INTEGERP (car
) || FLOATP (car
))
23085 pixels
= XFLOATINT (car
);
23087 return OK_PIXELS (pixels
);
23088 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
23089 font
, width_p
, align_to
))
23090 return OK_PIXELS (pixels
* fact
);
23101 /***********************************************************************
23103 ***********************************************************************/
23105 #ifdef HAVE_WINDOW_SYSTEM
23110 dump_glyph_string (struct glyph_string
*s
)
23112 fprintf (stderr
, "glyph string\n");
23113 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
23114 s
->x
, s
->y
, s
->width
, s
->height
);
23115 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
23116 fprintf (stderr
, " hl = %d\n", s
->hl
);
23117 fprintf (stderr
, " left overhang = %d, right = %d\n",
23118 s
->left_overhang
, s
->right_overhang
);
23119 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
23120 fprintf (stderr
, " extends to end of line = %d\n",
23121 s
->extends_to_end_of_line_p
);
23122 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
23123 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
23126 #endif /* GLYPH_DEBUG */
23128 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
23129 of XChar2b structures for S; it can't be allocated in
23130 init_glyph_string because it must be allocated via `alloca'. W
23131 is the window on which S is drawn. ROW and AREA are the glyph row
23132 and area within the row from which S is constructed. START is the
23133 index of the first glyph structure covered by S. HL is a
23134 face-override for drawing S. */
23137 #define OPTIONAL_HDC(hdc) HDC hdc,
23138 #define DECLARE_HDC(hdc) HDC hdc;
23139 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
23140 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
23143 #ifndef OPTIONAL_HDC
23144 #define OPTIONAL_HDC(hdc)
23145 #define DECLARE_HDC(hdc)
23146 #define ALLOCATE_HDC(hdc, f)
23147 #define RELEASE_HDC(hdc, f)
23151 init_glyph_string (struct glyph_string
*s
,
23153 XChar2b
*char2b
, struct window
*w
, struct glyph_row
*row
,
23154 enum glyph_row_area area
, int start
, enum draw_glyphs_face hl
)
23156 memset (s
, 0, sizeof *s
);
23158 s
->f
= XFRAME (w
->frame
);
23162 s
->display
= FRAME_X_DISPLAY (s
->f
);
23163 s
->window
= FRAME_X_WINDOW (s
->f
);
23164 s
->char2b
= char2b
;
23168 s
->first_glyph
= row
->glyphs
[area
] + start
;
23169 s
->height
= row
->height
;
23170 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
23171 s
->ybase
= s
->y
+ row
->ascent
;
23175 /* Append the list of glyph strings with head H and tail T to the list
23176 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
23179 append_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
23180 struct glyph_string
*h
, struct glyph_string
*t
)
23194 /* Prepend the list of glyph strings with head H and tail T to the
23195 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
23199 prepend_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
23200 struct glyph_string
*h
, struct glyph_string
*t
)
23214 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
23215 Set *HEAD and *TAIL to the resulting list. */
23218 append_glyph_string (struct glyph_string
**head
, struct glyph_string
**tail
,
23219 struct glyph_string
*s
)
23221 s
->next
= s
->prev
= NULL
;
23222 append_glyph_string_lists (head
, tail
, s
, s
);
23226 /* Get face and two-byte form of character C in face FACE_ID on frame F.
23227 The encoding of C is returned in *CHAR2B. DISPLAY_P non-zero means
23228 make sure that X resources for the face returned are allocated.
23229 Value is a pointer to a realized face that is ready for display if
23230 DISPLAY_P is non-zero. */
23232 static struct face
*
23233 get_char_face_and_encoding (struct frame
*f
, int c
, int face_id
,
23234 XChar2b
*char2b
, int display_p
)
23236 struct face
*face
= FACE_FROM_ID (f
, face_id
);
23241 code
= face
->font
->driver
->encode_char (face
->font
, c
);
23243 if (code
== FONT_INVALID_CODE
)
23246 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
23248 /* Make sure X resources of the face are allocated. */
23249 #ifdef HAVE_X_WINDOWS
23253 eassert (face
!= NULL
);
23254 PREPARE_FACE_FOR_DISPLAY (f
, face
);
23261 /* Get face and two-byte form of character glyph GLYPH on frame F.
23262 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
23263 a pointer to a realized face that is ready for display. */
23265 static struct face
*
23266 get_glyph_face_and_encoding (struct frame
*f
, struct glyph
*glyph
,
23267 XChar2b
*char2b
, int *two_byte_p
)
23272 eassert (glyph
->type
== CHAR_GLYPH
);
23273 face
= FACE_FROM_ID (f
, glyph
->face_id
);
23275 /* Make sure X resources of the face are allocated. */
23276 eassert (face
!= NULL
);
23277 PREPARE_FACE_FOR_DISPLAY (f
, face
);
23284 if (CHAR_BYTE8_P (glyph
->u
.ch
))
23285 code
= CHAR_TO_BYTE8 (glyph
->u
.ch
);
23287 code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
23289 if (code
== FONT_INVALID_CODE
)
23293 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
23298 /* Get glyph code of character C in FONT in the two-byte form CHAR2B.
23299 Return 1 if FONT has a glyph for C, otherwise return 0. */
23302 get_char_glyph_code (int c
, struct font
*font
, XChar2b
*char2b
)
23306 if (CHAR_BYTE8_P (c
))
23307 code
= CHAR_TO_BYTE8 (c
);
23309 code
= font
->driver
->encode_char (font
, c
);
23311 if (code
== FONT_INVALID_CODE
)
23313 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
23318 /* Fill glyph string S with composition components specified by S->cmp.
23320 BASE_FACE is the base face of the composition.
23321 S->cmp_from is the index of the first component for S.
23323 OVERLAPS non-zero means S should draw the foreground only, and use
23324 its physical height for clipping. See also draw_glyphs.
23326 Value is the index of a component not in S. */
23329 fill_composite_glyph_string (struct glyph_string
*s
, struct face
*base_face
,
23333 /* For all glyphs of this composition, starting at the offset
23334 S->cmp_from, until we reach the end of the definition or encounter a
23335 glyph that requires the different face, add it to S. */
23340 s
->for_overlaps
= overlaps
;
23343 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
23345 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
23347 /* TAB in a composition means display glyphs with padding space
23348 on the left or right. */
23351 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
23354 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
23361 s
->font
= s
->face
->font
;
23363 else if (s
->face
!= face
)
23371 if (s
->face
== NULL
)
23373 s
->face
= base_face
->ascii_face
;
23374 s
->font
= s
->face
->font
;
23377 /* All glyph strings for the same composition has the same width,
23378 i.e. the width set for the first component of the composition. */
23379 s
->width
= s
->first_glyph
->pixel_width
;
23381 /* If the specified font could not be loaded, use the frame's
23382 default font, but record the fact that we couldn't load it in
23383 the glyph string so that we can draw rectangles for the
23384 characters of the glyph string. */
23385 if (s
->font
== NULL
)
23387 s
->font_not_found_p
= 1;
23388 s
->font
= FRAME_FONT (s
->f
);
23391 /* Adjust base line for subscript/superscript text. */
23392 s
->ybase
+= s
->first_glyph
->voffset
;
23394 /* This glyph string must always be drawn with 16-bit functions. */
23401 fill_gstring_glyph_string (struct glyph_string
*s
, int face_id
,
23402 int start
, int end
, int overlaps
)
23404 struct glyph
*glyph
, *last
;
23405 Lisp_Object lgstring
;
23408 s
->for_overlaps
= overlaps
;
23409 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23410 last
= s
->row
->glyphs
[s
->area
] + end
;
23411 s
->cmp_id
= glyph
->u
.cmp
.id
;
23412 s
->cmp_from
= glyph
->slice
.cmp
.from
;
23413 s
->cmp_to
= glyph
->slice
.cmp
.to
+ 1;
23414 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
23415 lgstring
= composition_gstring_from_id (s
->cmp_id
);
23416 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
23418 while (glyph
< last
23419 && glyph
->u
.cmp
.automatic
23420 && glyph
->u
.cmp
.id
== s
->cmp_id
23421 && s
->cmp_to
== glyph
->slice
.cmp
.from
)
23422 s
->cmp_to
= (glyph
++)->slice
.cmp
.to
+ 1;
23424 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
23426 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
23427 unsigned code
= LGLYPH_CODE (lglyph
);
23429 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
23431 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
23432 return glyph
- s
->row
->glyphs
[s
->area
];
23436 /* Fill glyph string S from a sequence glyphs for glyphless characters.
23437 See the comment of fill_glyph_string for arguments.
23438 Value is the index of the first glyph not in S. */
23442 fill_glyphless_glyph_string (struct glyph_string
*s
, int face_id
,
23443 int start
, int end
, int overlaps
)
23445 struct glyph
*glyph
, *last
;
23448 eassert (s
->first_glyph
->type
== GLYPHLESS_GLYPH
);
23449 s
->for_overlaps
= overlaps
;
23450 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23451 last
= s
->row
->glyphs
[s
->area
] + end
;
23452 voffset
= glyph
->voffset
;
23453 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
23454 s
->font
= s
->face
->font
? s
->face
->font
: FRAME_FONT (s
->f
);
23456 s
->width
= glyph
->pixel_width
;
23458 while (glyph
< last
23459 && glyph
->type
== GLYPHLESS_GLYPH
23460 && glyph
->voffset
== voffset
23461 && glyph
->face_id
== face_id
)
23464 s
->width
+= glyph
->pixel_width
;
23467 s
->ybase
+= voffset
;
23468 return glyph
- s
->row
->glyphs
[s
->area
];
23472 /* Fill glyph string S from a sequence of character glyphs.
23474 FACE_ID is the face id of the string. START is the index of the
23475 first glyph to consider, END is the index of the last + 1.
23476 OVERLAPS non-zero means S should draw the foreground only, and use
23477 its physical height for clipping. See also draw_glyphs.
23479 Value is the index of the first glyph not in S. */
23482 fill_glyph_string (struct glyph_string
*s
, int face_id
,
23483 int start
, int end
, int overlaps
)
23485 struct glyph
*glyph
, *last
;
23487 int glyph_not_available_p
;
23489 eassert (s
->f
== XFRAME (s
->w
->frame
));
23490 eassert (s
->nchars
== 0);
23491 eassert (start
>= 0 && end
> start
);
23493 s
->for_overlaps
= overlaps
;
23494 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23495 last
= s
->row
->glyphs
[s
->area
] + end
;
23496 voffset
= glyph
->voffset
;
23497 s
->padding_p
= glyph
->padding_p
;
23498 glyph_not_available_p
= glyph
->glyph_not_available_p
;
23500 while (glyph
< last
23501 && glyph
->type
== CHAR_GLYPH
23502 && glyph
->voffset
== voffset
23503 /* Same face id implies same font, nowadays. */
23504 && glyph
->face_id
== face_id
23505 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
23509 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
23510 s
->char2b
+ s
->nchars
,
23512 s
->two_byte_p
= two_byte_p
;
23514 eassert (s
->nchars
<= end
- start
);
23515 s
->width
+= glyph
->pixel_width
;
23516 if (glyph
++->padding_p
!= s
->padding_p
)
23520 s
->font
= s
->face
->font
;
23522 /* If the specified font could not be loaded, use the frame's font,
23523 but record the fact that we couldn't load it in
23524 S->font_not_found_p so that we can draw rectangles for the
23525 characters of the glyph string. */
23526 if (s
->font
== NULL
|| glyph_not_available_p
)
23528 s
->font_not_found_p
= 1;
23529 s
->font
= FRAME_FONT (s
->f
);
23532 /* Adjust base line for subscript/superscript text. */
23533 s
->ybase
+= voffset
;
23535 eassert (s
->face
&& s
->face
->gc
);
23536 return glyph
- s
->row
->glyphs
[s
->area
];
23540 /* Fill glyph string S from image glyph S->first_glyph. */
23543 fill_image_glyph_string (struct glyph_string
*s
)
23545 eassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
23546 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
23548 s
->slice
= s
->first_glyph
->slice
.img
;
23549 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
23550 s
->font
= s
->face
->font
;
23551 s
->width
= s
->first_glyph
->pixel_width
;
23553 /* Adjust base line for subscript/superscript text. */
23554 s
->ybase
+= s
->first_glyph
->voffset
;
23558 /* Fill glyph string S from a sequence of stretch glyphs.
23560 START is the index of the first glyph to consider,
23561 END is the index of the last + 1.
23563 Value is the index of the first glyph not in S. */
23566 fill_stretch_glyph_string (struct glyph_string
*s
, int start
, int end
)
23568 struct glyph
*glyph
, *last
;
23569 int voffset
, face_id
;
23571 eassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
23573 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23574 last
= s
->row
->glyphs
[s
->area
] + end
;
23575 face_id
= glyph
->face_id
;
23576 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
23577 s
->font
= s
->face
->font
;
23578 s
->width
= glyph
->pixel_width
;
23580 voffset
= glyph
->voffset
;
23584 && glyph
->type
== STRETCH_GLYPH
23585 && glyph
->voffset
== voffset
23586 && glyph
->face_id
== face_id
);
23588 s
->width
+= glyph
->pixel_width
;
23590 /* Adjust base line for subscript/superscript text. */
23591 s
->ybase
+= voffset
;
23593 /* The case that face->gc == 0 is handled when drawing the glyph
23594 string by calling PREPARE_FACE_FOR_DISPLAY. */
23596 return glyph
- s
->row
->glyphs
[s
->area
];
23599 static struct font_metrics
*
23600 get_per_char_metric (struct font
*font
, XChar2b
*char2b
)
23602 static struct font_metrics metrics
;
23607 code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
23608 if (code
== FONT_INVALID_CODE
)
23610 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
23615 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
23616 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
23617 assumed to be zero. */
23620 x_get_glyph_overhangs (struct glyph
*glyph
, struct frame
*f
, int *left
, int *right
)
23622 *left
= *right
= 0;
23624 if (glyph
->type
== CHAR_GLYPH
)
23628 struct font_metrics
*pcm
;
23630 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
23631 if (face
->font
&& (pcm
= get_per_char_metric (face
->font
, &char2b
)))
23633 if (pcm
->rbearing
> pcm
->width
)
23634 *right
= pcm
->rbearing
- pcm
->width
;
23635 if (pcm
->lbearing
< 0)
23636 *left
= -pcm
->lbearing
;
23639 else if (glyph
->type
== COMPOSITE_GLYPH
)
23641 if (! glyph
->u
.cmp
.automatic
)
23643 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
23645 if (cmp
->rbearing
> cmp
->pixel_width
)
23646 *right
= cmp
->rbearing
- cmp
->pixel_width
;
23647 if (cmp
->lbearing
< 0)
23648 *left
= - cmp
->lbearing
;
23652 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
23653 struct font_metrics metrics
;
23655 composition_gstring_width (gstring
, glyph
->slice
.cmp
.from
,
23656 glyph
->slice
.cmp
.to
+ 1, &metrics
);
23657 if (metrics
.rbearing
> metrics
.width
)
23658 *right
= metrics
.rbearing
- metrics
.width
;
23659 if (metrics
.lbearing
< 0)
23660 *left
= - metrics
.lbearing
;
23666 /* Return the index of the first glyph preceding glyph string S that
23667 is overwritten by S because of S's left overhang. Value is -1
23668 if no glyphs are overwritten. */
23671 left_overwritten (struct glyph_string
*s
)
23675 if (s
->left_overhang
)
23678 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23679 int first
= s
->first_glyph
- glyphs
;
23681 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
23682 x
-= glyphs
[i
].pixel_width
;
23693 /* Return the index of the first glyph preceding glyph string S that
23694 is overwriting S because of its right overhang. Value is -1 if no
23695 glyph in front of S overwrites S. */
23698 left_overwriting (struct glyph_string
*s
)
23701 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23702 int first
= s
->first_glyph
- glyphs
;
23706 for (i
= first
- 1; i
>= 0; --i
)
23709 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
23712 x
-= glyphs
[i
].pixel_width
;
23719 /* Return the index of the last glyph following glyph string S that is
23720 overwritten by S because of S's right overhang. Value is -1 if
23721 no such glyph is found. */
23724 right_overwritten (struct glyph_string
*s
)
23728 if (s
->right_overhang
)
23731 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23732 int first
= (s
->first_glyph
- glyphs
23733 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
23734 int end
= s
->row
->used
[s
->area
];
23736 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
23737 x
+= glyphs
[i
].pixel_width
;
23746 /* Return the index of the last glyph following glyph string S that
23747 overwrites S because of its left overhang. Value is negative
23748 if no such glyph is found. */
23751 right_overwriting (struct glyph_string
*s
)
23754 int end
= s
->row
->used
[s
->area
];
23755 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23756 int first
= (s
->first_glyph
- glyphs
23757 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
23761 for (i
= first
; i
< end
; ++i
)
23764 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
23767 x
+= glyphs
[i
].pixel_width
;
23774 /* Set background width of glyph string S. START is the index of the
23775 first glyph following S. LAST_X is the right-most x-position + 1
23776 in the drawing area. */
23779 set_glyph_string_background_width (struct glyph_string
*s
, int start
, int last_x
)
23781 /* If the face of this glyph string has to be drawn to the end of
23782 the drawing area, set S->extends_to_end_of_line_p. */
23784 if (start
== s
->row
->used
[s
->area
]
23785 && s
->area
== TEXT_AREA
23786 && ((s
->row
->fill_line_p
23787 && (s
->hl
== DRAW_NORMAL_TEXT
23788 || s
->hl
== DRAW_IMAGE_RAISED
23789 || s
->hl
== DRAW_IMAGE_SUNKEN
))
23790 || s
->hl
== DRAW_MOUSE_FACE
))
23791 s
->extends_to_end_of_line_p
= 1;
23793 /* If S extends its face to the end of the line, set its
23794 background_width to the distance to the right edge of the drawing
23796 if (s
->extends_to_end_of_line_p
)
23797 s
->background_width
= last_x
- s
->x
+ 1;
23799 s
->background_width
= s
->width
;
23803 /* Compute overhangs and x-positions for glyph string S and its
23804 predecessors, or successors. X is the starting x-position for S.
23805 BACKWARD_P non-zero means process predecessors. */
23808 compute_overhangs_and_x (struct glyph_string
*s
, int x
, int backward_p
)
23814 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
23815 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
23825 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
23826 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
23836 /* The following macros are only called from draw_glyphs below.
23837 They reference the following parameters of that function directly:
23838 `w', `row', `area', and `overlap_p'
23839 as well as the following local variables:
23840 `s', `f', and `hdc' (in W32) */
23843 /* On W32, silently add local `hdc' variable to argument list of
23844 init_glyph_string. */
23845 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
23846 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
23848 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
23849 init_glyph_string (s, char2b, w, row, area, start, hl)
23852 /* Add a glyph string for a stretch glyph to the list of strings
23853 between HEAD and TAIL. START is the index of the stretch glyph in
23854 row area AREA of glyph row ROW. END is the index of the last glyph
23855 in that glyph row area. X is the current output position assigned
23856 to the new glyph string constructed. HL overrides that face of the
23857 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
23858 is the right-most x-position of the drawing area. */
23860 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
23861 and below -- keep them on one line. */
23862 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23865 s = alloca (sizeof *s); \
23866 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23867 START = fill_stretch_glyph_string (s, START, END); \
23868 append_glyph_string (&HEAD, &TAIL, s); \
23874 /* Add a glyph string for an image glyph to the list of strings
23875 between HEAD and TAIL. START is the index of the image glyph in
23876 row area AREA of glyph row ROW. END is the index of the last glyph
23877 in that glyph row area. X is the current output position assigned
23878 to the new glyph string constructed. HL overrides that face of the
23879 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
23880 is the right-most x-position of the drawing area. */
23882 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23885 s = alloca (sizeof *s); \
23886 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23887 fill_image_glyph_string (s); \
23888 append_glyph_string (&HEAD, &TAIL, s); \
23895 /* Add a glyph string for a sequence of character glyphs to the list
23896 of strings between HEAD and TAIL. START is the index of the first
23897 glyph in row area AREA of glyph row ROW that is part of the new
23898 glyph string. END is the index of the last glyph in that glyph row
23899 area. X is the current output position assigned to the new glyph
23900 string constructed. HL overrides that face of the glyph; e.g. it
23901 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
23902 right-most x-position of the drawing area. */
23904 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
23910 face_id = (row)->glyphs[area][START].face_id; \
23912 s = alloca (sizeof *s); \
23913 char2b = alloca ((END - START) * sizeof *char2b); \
23914 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23915 append_glyph_string (&HEAD, &TAIL, s); \
23917 START = fill_glyph_string (s, face_id, START, END, overlaps); \
23922 /* Add a glyph string for a composite sequence to the list of strings
23923 between HEAD and TAIL. START is the index of the first glyph in
23924 row area AREA of glyph row ROW that is part of the new glyph
23925 string. END is the index of the last glyph in that glyph row area.
23926 X is the current output position assigned to the new glyph string
23927 constructed. HL overrides that face of the glyph; e.g. it is
23928 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
23929 x-position of the drawing area. */
23931 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23933 int face_id = (row)->glyphs[area][START].face_id; \
23934 struct face *base_face = FACE_FROM_ID (f, face_id); \
23935 ptrdiff_t cmp_id = (row)->glyphs[area][START].u.cmp.id; \
23936 struct composition *cmp = composition_table[cmp_id]; \
23938 struct glyph_string *first_s = NULL; \
23941 char2b = alloca (cmp->glyph_len * sizeof *char2b); \
23943 /* Make glyph_strings for each glyph sequence that is drawable by \
23944 the same face, and append them to HEAD/TAIL. */ \
23945 for (n = 0; n < cmp->glyph_len;) \
23947 s = alloca (sizeof *s); \
23948 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23949 append_glyph_string (&(HEAD), &(TAIL), s); \
23955 n = fill_composite_glyph_string (s, base_face, overlaps); \
23963 /* Add a glyph string for a glyph-string sequence to the list of strings
23964 between HEAD and TAIL. */
23966 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23970 Lisp_Object gstring; \
23972 face_id = (row)->glyphs[area][START].face_id; \
23973 gstring = (composition_gstring_from_id \
23974 ((row)->glyphs[area][START].u.cmp.id)); \
23975 s = alloca (sizeof *s); \
23976 char2b = alloca (LGSTRING_GLYPH_LEN (gstring) * sizeof *char2b); \
23977 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23978 append_glyph_string (&(HEAD), &(TAIL), s); \
23980 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
23984 /* Add a glyph string for a sequence of glyphless character's glyphs
23985 to the list of strings between HEAD and TAIL. The meanings of
23986 arguments are the same as those of BUILD_CHAR_GLYPH_STRINGS. */
23988 #define BUILD_GLYPHLESS_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23993 face_id = (row)->glyphs[area][START].face_id; \
23995 s = alloca (sizeof *s); \
23996 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23997 append_glyph_string (&HEAD, &TAIL, s); \
23999 START = fill_glyphless_glyph_string (s, face_id, START, END, \
24005 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
24006 of AREA of glyph row ROW on window W between indices START and END.
24007 HL overrides the face for drawing glyph strings, e.g. it is
24008 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
24009 x-positions of the drawing area.
24011 This is an ugly monster macro construct because we must use alloca
24012 to allocate glyph strings (because draw_glyphs can be called
24013 asynchronously). */
24015 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
24018 HEAD = TAIL = NULL; \
24019 while (START < END) \
24021 struct glyph *first_glyph = (row)->glyphs[area] + START; \
24022 switch (first_glyph->type) \
24025 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
24029 case COMPOSITE_GLYPH: \
24030 if (first_glyph->u.cmp.automatic) \
24031 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
24034 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
24038 case STRETCH_GLYPH: \
24039 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
24043 case IMAGE_GLYPH: \
24044 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
24048 case GLYPHLESS_GLYPH: \
24049 BUILD_GLYPHLESS_GLYPH_STRING (START, END, HEAD, TAIL, \
24059 set_glyph_string_background_width (s, START, LAST_X); \
24066 /* Draw glyphs between START and END in AREA of ROW on window W,
24067 starting at x-position X. X is relative to AREA in W. HL is a
24068 face-override with the following meaning:
24070 DRAW_NORMAL_TEXT draw normally
24071 DRAW_CURSOR draw in cursor face
24072 DRAW_MOUSE_FACE draw in mouse face.
24073 DRAW_INVERSE_VIDEO draw in mode line face
24074 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
24075 DRAW_IMAGE_RAISED draw an image with a raised relief around it
24077 If OVERLAPS is non-zero, draw only the foreground of characters and
24078 clip to the physical height of ROW. Non-zero value also defines
24079 the overlapping part to be drawn:
24081 OVERLAPS_PRED overlap with preceding rows
24082 OVERLAPS_SUCC overlap with succeeding rows
24083 OVERLAPS_BOTH overlap with both preceding/succeeding rows
24084 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
24086 Value is the x-position reached, relative to AREA of W. */
24089 draw_glyphs (struct window
*w
, int x
, struct glyph_row
*row
,
24090 enum glyph_row_area area
, ptrdiff_t start
, ptrdiff_t end
,
24091 enum draw_glyphs_face hl
, int overlaps
)
24093 struct glyph_string
*head
, *tail
;
24094 struct glyph_string
*s
;
24095 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
24096 int i
, j
, x_reached
, last_x
, area_left
= 0;
24097 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
24100 ALLOCATE_HDC (hdc
, f
);
24102 /* Let's rather be paranoid than getting a SEGV. */
24103 end
= min (end
, row
->used
[area
]);
24104 start
= clip_to_bounds (0, start
, end
);
24106 /* Translate X to frame coordinates. Set last_x to the right
24107 end of the drawing area. */
24108 if (row
->full_width_p
)
24110 /* X is relative to the left edge of W, without scroll bars
24112 area_left
= WINDOW_LEFT_EDGE_X (w
);
24113 last_x
= (WINDOW_LEFT_EDGE_X (w
) + WINDOW_PIXEL_WIDTH (w
)
24114 - (row
->mode_line_p
? WINDOW_RIGHT_DIVIDER_WIDTH (w
) : 0));
24118 area_left
= window_box_left (w
, area
);
24119 last_x
= area_left
+ window_box_width (w
, area
);
24123 /* Build a doubly-linked list of glyph_string structures between
24124 head and tail from what we have to draw. Note that the macro
24125 BUILD_GLYPH_STRINGS will modify its start parameter. That's
24126 the reason we use a separate variable `i'. */
24128 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
24130 x_reached
= tail
->x
+ tail
->background_width
;
24134 /* If there are any glyphs with lbearing < 0 or rbearing > width in
24135 the row, redraw some glyphs in front or following the glyph
24136 strings built above. */
24137 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
24139 struct glyph_string
*h
, *t
;
24140 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
24141 int mouse_beg_col
IF_LINT (= 0), mouse_end_col
IF_LINT (= 0);
24142 int check_mouse_face
= 0;
24145 /* If mouse highlighting is on, we may need to draw adjacent
24146 glyphs using mouse-face highlighting. */
24147 if (area
== TEXT_AREA
&& row
->mouse_face_p
24148 && hlinfo
->mouse_face_beg_row
>= 0
24149 && hlinfo
->mouse_face_end_row
>= 0)
24151 ptrdiff_t row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
24153 if (row_vpos
>= hlinfo
->mouse_face_beg_row
24154 && row_vpos
<= hlinfo
->mouse_face_end_row
)
24156 check_mouse_face
= 1;
24157 mouse_beg_col
= (row_vpos
== hlinfo
->mouse_face_beg_row
)
24158 ? hlinfo
->mouse_face_beg_col
: 0;
24159 mouse_end_col
= (row_vpos
== hlinfo
->mouse_face_end_row
)
24160 ? hlinfo
->mouse_face_end_col
24161 : row
->used
[TEXT_AREA
];
24165 /* Compute overhangs for all glyph strings. */
24166 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
24167 for (s
= head
; s
; s
= s
->next
)
24168 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
24170 /* Prepend glyph strings for glyphs in front of the first glyph
24171 string that are overwritten because of the first glyph
24172 string's left overhang. The background of all strings
24173 prepended must be drawn because the first glyph string
24175 i
= left_overwritten (head
);
24178 enum draw_glyphs_face overlap_hl
;
24180 /* If this row contains mouse highlighting, attempt to draw
24181 the overlapped glyphs with the correct highlight. This
24182 code fails if the overlap encompasses more than one glyph
24183 and mouse-highlight spans only some of these glyphs.
24184 However, making it work perfectly involves a lot more
24185 code, and I don't know if the pathological case occurs in
24186 practice, so we'll stick to this for now. --- cyd */
24187 if (check_mouse_face
24188 && mouse_beg_col
< start
&& mouse_end_col
> i
)
24189 overlap_hl
= DRAW_MOUSE_FACE
;
24191 overlap_hl
= DRAW_NORMAL_TEXT
;
24194 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
24195 overlap_hl
, dummy_x
, last_x
);
24197 compute_overhangs_and_x (t
, head
->x
, 1);
24198 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
24202 /* Prepend glyph strings for glyphs in front of the first glyph
24203 string that overwrite that glyph string because of their
24204 right overhang. For these strings, only the foreground must
24205 be drawn, because it draws over the glyph string at `head'.
24206 The background must not be drawn because this would overwrite
24207 right overhangs of preceding glyphs for which no glyph
24209 i
= left_overwriting (head
);
24212 enum draw_glyphs_face overlap_hl
;
24214 if (check_mouse_face
24215 && mouse_beg_col
< start
&& mouse_end_col
> i
)
24216 overlap_hl
= DRAW_MOUSE_FACE
;
24218 overlap_hl
= DRAW_NORMAL_TEXT
;
24221 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
24222 overlap_hl
, dummy_x
, last_x
);
24223 for (s
= h
; s
; s
= s
->next
)
24224 s
->background_filled_p
= 1;
24225 compute_overhangs_and_x (t
, head
->x
, 1);
24226 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
24229 /* Append glyphs strings for glyphs following the last glyph
24230 string tail that are overwritten by tail. The background of
24231 these strings has to be drawn because tail's foreground draws
24233 i
= right_overwritten (tail
);
24236 enum draw_glyphs_face overlap_hl
;
24238 if (check_mouse_face
24239 && mouse_beg_col
< i
&& mouse_end_col
> end
)
24240 overlap_hl
= DRAW_MOUSE_FACE
;
24242 overlap_hl
= DRAW_NORMAL_TEXT
;
24244 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
24245 overlap_hl
, x
, last_x
);
24246 /* Because BUILD_GLYPH_STRINGS updates the first argument,
24247 we don't have `end = i;' here. */
24248 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
24249 append_glyph_string_lists (&head
, &tail
, h
, t
);
24253 /* Append glyph strings for glyphs following the last glyph
24254 string tail that overwrite tail. The foreground of such
24255 glyphs has to be drawn because it writes into the background
24256 of tail. The background must not be drawn because it could
24257 paint over the foreground of following glyphs. */
24258 i
= right_overwriting (tail
);
24261 enum draw_glyphs_face overlap_hl
;
24262 if (check_mouse_face
24263 && mouse_beg_col
< i
&& mouse_end_col
> end
)
24264 overlap_hl
= DRAW_MOUSE_FACE
;
24266 overlap_hl
= DRAW_NORMAL_TEXT
;
24269 i
++; /* We must include the Ith glyph. */
24270 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
24271 overlap_hl
, x
, last_x
);
24272 for (s
= h
; s
; s
= s
->next
)
24273 s
->background_filled_p
= 1;
24274 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
24275 append_glyph_string_lists (&head
, &tail
, h
, t
);
24277 if (clip_head
|| clip_tail
)
24278 for (s
= head
; s
; s
= s
->next
)
24280 s
->clip_head
= clip_head
;
24281 s
->clip_tail
= clip_tail
;
24285 /* Draw all strings. */
24286 for (s
= head
; s
; s
= s
->next
)
24287 FRAME_RIF (f
)->draw_glyph_string (s
);
24290 /* When focus a sole frame and move horizontally, this sets on_p to 0
24291 causing a failure to erase prev cursor position. */
24292 if (area
== TEXT_AREA
24293 && !row
->full_width_p
24294 /* When drawing overlapping rows, only the glyph strings'
24295 foreground is drawn, which doesn't erase a cursor
24299 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
24300 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
24301 : (tail
? tail
->x
+ tail
->background_width
: x
));
24305 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
24306 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
24310 /* Value is the x-position up to which drawn, relative to AREA of W.
24311 This doesn't include parts drawn because of overhangs. */
24312 if (row
->full_width_p
)
24313 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
24315 x_reached
-= area_left
;
24317 RELEASE_HDC (hdc
, f
);
24322 /* Expand row matrix if too narrow. Don't expand if area
24325 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
24327 if (!it->f->fonts_changed \
24328 && (it->glyph_row->glyphs[area] \
24329 < it->glyph_row->glyphs[area + 1])) \
24331 it->w->ncols_scale_factor++; \
24332 it->f->fonts_changed = 1; \
24336 /* Store one glyph for IT->char_to_display in IT->glyph_row.
24337 Called from x_produce_glyphs when IT->glyph_row is non-null. */
24340 append_glyph (struct it
*it
)
24342 struct glyph
*glyph
;
24343 enum glyph_row_area area
= it
->area
;
24345 eassert (it
->glyph_row
);
24346 eassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
24348 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24349 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24351 /* If the glyph row is reversed, we need to prepend the glyph
24352 rather than append it. */
24353 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24357 /* Make room for the additional glyph. */
24358 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
24360 glyph
= it
->glyph_row
->glyphs
[area
];
24362 glyph
->charpos
= CHARPOS (it
->position
);
24363 glyph
->object
= it
->object
;
24364 if (it
->pixel_width
> 0)
24366 glyph
->pixel_width
= it
->pixel_width
;
24367 glyph
->padding_p
= 0;
24371 /* Assure at least 1-pixel width. Otherwise, cursor can't
24372 be displayed correctly. */
24373 glyph
->pixel_width
= 1;
24374 glyph
->padding_p
= 1;
24376 glyph
->ascent
= it
->ascent
;
24377 glyph
->descent
= it
->descent
;
24378 glyph
->voffset
= it
->voffset
;
24379 glyph
->type
= CHAR_GLYPH
;
24380 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24381 glyph
->multibyte_p
= it
->multibyte_p
;
24382 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24384 /* In R2L rows, the left and the right box edges need to be
24385 drawn in reverse direction. */
24386 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24387 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24391 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24392 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24394 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
24395 || it
->phys_descent
> it
->descent
);
24396 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
24397 glyph
->face_id
= it
->face_id
;
24398 glyph
->u
.ch
= it
->char_to_display
;
24399 glyph
->slice
.img
= null_glyph_slice
;
24400 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24403 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24404 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24406 glyph
->bidi_type
= it
->bidi_it
.type
;
24410 glyph
->resolved_level
= 0;
24411 glyph
->bidi_type
= UNKNOWN_BT
;
24413 ++it
->glyph_row
->used
[area
];
24416 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24419 /* Store one glyph for the composition IT->cmp_it.id in
24420 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
24424 append_composite_glyph (struct it
*it
)
24426 struct glyph
*glyph
;
24427 enum glyph_row_area area
= it
->area
;
24429 eassert (it
->glyph_row
);
24431 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24432 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24434 /* If the glyph row is reversed, we need to prepend the glyph
24435 rather than append it. */
24436 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
24440 /* Make room for the new glyph. */
24441 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
24443 glyph
= it
->glyph_row
->glyphs
[it
->area
];
24445 glyph
->charpos
= it
->cmp_it
.charpos
;
24446 glyph
->object
= it
->object
;
24447 glyph
->pixel_width
= it
->pixel_width
;
24448 glyph
->ascent
= it
->ascent
;
24449 glyph
->descent
= it
->descent
;
24450 glyph
->voffset
= it
->voffset
;
24451 glyph
->type
= COMPOSITE_GLYPH
;
24452 if (it
->cmp_it
.ch
< 0)
24454 glyph
->u
.cmp
.automatic
= 0;
24455 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
24456 glyph
->slice
.cmp
.from
= glyph
->slice
.cmp
.to
= 0;
24460 glyph
->u
.cmp
.automatic
= 1;
24461 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
24462 glyph
->slice
.cmp
.from
= it
->cmp_it
.from
;
24463 glyph
->slice
.cmp
.to
= it
->cmp_it
.to
- 1;
24465 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24466 glyph
->multibyte_p
= it
->multibyte_p
;
24467 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24469 /* In R2L rows, the left and the right box edges need to be
24470 drawn in reverse direction. */
24471 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24472 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24476 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24477 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24479 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
24480 || it
->phys_descent
> it
->descent
);
24481 glyph
->padding_p
= 0;
24482 glyph
->glyph_not_available_p
= 0;
24483 glyph
->face_id
= it
->face_id
;
24484 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24487 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24488 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24490 glyph
->bidi_type
= it
->bidi_it
.type
;
24492 ++it
->glyph_row
->used
[area
];
24495 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24499 /* Change IT->ascent and IT->height according to the setting of
24503 take_vertical_position_into_account (struct it
*it
)
24507 if (it
->voffset
< 0)
24508 /* Increase the ascent so that we can display the text higher
24510 it
->ascent
-= it
->voffset
;
24512 /* Increase the descent so that we can display the text lower
24514 it
->descent
+= it
->voffset
;
24519 /* Produce glyphs/get display metrics for the image IT is loaded with.
24520 See the description of struct display_iterator in dispextern.h for
24521 an overview of struct display_iterator. */
24524 produce_image_glyph (struct it
*it
)
24528 int glyph_ascent
, crop
;
24529 struct glyph_slice slice
;
24531 eassert (it
->what
== IT_IMAGE
);
24533 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24535 /* Make sure X resources of the face is loaded. */
24536 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24538 if (it
->image_id
< 0)
24540 /* Fringe bitmap. */
24541 it
->ascent
= it
->phys_ascent
= 0;
24542 it
->descent
= it
->phys_descent
= 0;
24543 it
->pixel_width
= 0;
24548 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
24550 /* Make sure X resources of the image is loaded. */
24551 prepare_image_for_display (it
->f
, img
);
24553 slice
.x
= slice
.y
= 0;
24554 slice
.width
= img
->width
;
24555 slice
.height
= img
->height
;
24557 if (INTEGERP (it
->slice
.x
))
24558 slice
.x
= XINT (it
->slice
.x
);
24559 else if (FLOATP (it
->slice
.x
))
24560 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
24562 if (INTEGERP (it
->slice
.y
))
24563 slice
.y
= XINT (it
->slice
.y
);
24564 else if (FLOATP (it
->slice
.y
))
24565 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
24567 if (INTEGERP (it
->slice
.width
))
24568 slice
.width
= XINT (it
->slice
.width
);
24569 else if (FLOATP (it
->slice
.width
))
24570 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
24572 if (INTEGERP (it
->slice
.height
))
24573 slice
.height
= XINT (it
->slice
.height
);
24574 else if (FLOATP (it
->slice
.height
))
24575 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
24577 if (slice
.x
>= img
->width
)
24578 slice
.x
= img
->width
;
24579 if (slice
.y
>= img
->height
)
24580 slice
.y
= img
->height
;
24581 if (slice
.x
+ slice
.width
>= img
->width
)
24582 slice
.width
= img
->width
- slice
.x
;
24583 if (slice
.y
+ slice
.height
> img
->height
)
24584 slice
.height
= img
->height
- slice
.y
;
24586 if (slice
.width
== 0 || slice
.height
== 0)
24589 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
24591 it
->descent
= slice
.height
- glyph_ascent
;
24593 it
->descent
+= img
->vmargin
;
24594 if (slice
.y
+ slice
.height
== img
->height
)
24595 it
->descent
+= img
->vmargin
;
24596 it
->phys_descent
= it
->descent
;
24598 it
->pixel_width
= slice
.width
;
24600 it
->pixel_width
+= img
->hmargin
;
24601 if (slice
.x
+ slice
.width
== img
->width
)
24602 it
->pixel_width
+= img
->hmargin
;
24604 /* It's quite possible for images to have an ascent greater than
24605 their height, so don't get confused in that case. */
24606 if (it
->descent
< 0)
24611 if (face
->box
!= FACE_NO_BOX
)
24613 if (face
->box_line_width
> 0)
24616 it
->ascent
+= face
->box_line_width
;
24617 if (slice
.y
+ slice
.height
== img
->height
)
24618 it
->descent
+= face
->box_line_width
;
24621 if (it
->start_of_box_run_p
&& slice
.x
== 0)
24622 it
->pixel_width
+= eabs (face
->box_line_width
);
24623 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
24624 it
->pixel_width
+= eabs (face
->box_line_width
);
24627 take_vertical_position_into_account (it
);
24629 /* Automatically crop wide image glyphs at right edge so we can
24630 draw the cursor on same display row. */
24631 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
24632 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
24634 it
->pixel_width
-= crop
;
24635 slice
.width
-= crop
;
24640 struct glyph
*glyph
;
24641 enum glyph_row_area area
= it
->area
;
24643 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24644 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24646 glyph
->charpos
= CHARPOS (it
->position
);
24647 glyph
->object
= it
->object
;
24648 glyph
->pixel_width
= it
->pixel_width
;
24649 glyph
->ascent
= glyph_ascent
;
24650 glyph
->descent
= it
->descent
;
24651 glyph
->voffset
= it
->voffset
;
24652 glyph
->type
= IMAGE_GLYPH
;
24653 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24654 glyph
->multibyte_p
= it
->multibyte_p
;
24655 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24657 /* In R2L rows, the left and the right box edges need to be
24658 drawn in reverse direction. */
24659 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24660 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24664 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24665 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24667 glyph
->overlaps_vertically_p
= 0;
24668 glyph
->padding_p
= 0;
24669 glyph
->glyph_not_available_p
= 0;
24670 glyph
->face_id
= it
->face_id
;
24671 glyph
->u
.img_id
= img
->id
;
24672 glyph
->slice
.img
= slice
;
24673 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24676 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24677 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24679 glyph
->bidi_type
= it
->bidi_it
.type
;
24681 ++it
->glyph_row
->used
[area
];
24684 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24689 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
24690 of the glyph, WIDTH and HEIGHT are the width and height of the
24691 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
24694 append_stretch_glyph (struct it
*it
, Lisp_Object object
,
24695 int width
, int height
, int ascent
)
24697 struct glyph
*glyph
;
24698 enum glyph_row_area area
= it
->area
;
24700 eassert (ascent
>= 0 && ascent
<= height
);
24702 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24703 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24705 /* If the glyph row is reversed, we need to prepend the glyph
24706 rather than append it. */
24707 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24711 /* Make room for the additional glyph. */
24712 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
24714 glyph
= it
->glyph_row
->glyphs
[area
];
24716 glyph
->charpos
= CHARPOS (it
->position
);
24717 glyph
->object
= object
;
24718 glyph
->pixel_width
= width
;
24719 glyph
->ascent
= ascent
;
24720 glyph
->descent
= height
- ascent
;
24721 glyph
->voffset
= it
->voffset
;
24722 glyph
->type
= STRETCH_GLYPH
;
24723 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24724 glyph
->multibyte_p
= it
->multibyte_p
;
24725 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24727 /* In R2L rows, the left and the right box edges need to be
24728 drawn in reverse direction. */
24729 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24730 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24734 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24735 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24737 glyph
->overlaps_vertically_p
= 0;
24738 glyph
->padding_p
= 0;
24739 glyph
->glyph_not_available_p
= 0;
24740 glyph
->face_id
= it
->face_id
;
24741 glyph
->u
.stretch
.ascent
= ascent
;
24742 glyph
->u
.stretch
.height
= height
;
24743 glyph
->slice
.img
= null_glyph_slice
;
24744 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24747 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24748 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24750 glyph
->bidi_type
= it
->bidi_it
.type
;
24754 glyph
->resolved_level
= 0;
24755 glyph
->bidi_type
= UNKNOWN_BT
;
24757 ++it
->glyph_row
->used
[area
];
24760 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24763 #endif /* HAVE_WINDOW_SYSTEM */
24765 /* Produce a stretch glyph for iterator IT. IT->object is the value
24766 of the glyph property displayed. The value must be a list
24767 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
24770 1. `:width WIDTH' specifies that the space should be WIDTH *
24771 canonical char width wide. WIDTH may be an integer or floating
24774 2. `:relative-width FACTOR' specifies that the width of the stretch
24775 should be computed from the width of the first character having the
24776 `glyph' property, and should be FACTOR times that width.
24778 3. `:align-to HPOS' specifies that the space should be wide enough
24779 to reach HPOS, a value in canonical character units.
24781 Exactly one of the above pairs must be present.
24783 4. `:height HEIGHT' specifies that the height of the stretch produced
24784 should be HEIGHT, measured in canonical character units.
24786 5. `:relative-height FACTOR' specifies that the height of the
24787 stretch should be FACTOR times the height of the characters having
24788 the glyph property.
24790 Either none or exactly one of 4 or 5 must be present.
24792 6. `:ascent ASCENT' specifies that ASCENT percent of the height
24793 of the stretch should be used for the ascent of the stretch.
24794 ASCENT must be in the range 0 <= ASCENT <= 100. */
24797 produce_stretch_glyph (struct it
*it
)
24799 /* (space :width WIDTH :height HEIGHT ...) */
24800 Lisp_Object prop
, plist
;
24801 int width
= 0, height
= 0, align_to
= -1;
24802 int zero_width_ok_p
= 0;
24804 struct font
*font
= NULL
;
24806 #ifdef HAVE_WINDOW_SYSTEM
24808 int zero_height_ok_p
= 0;
24810 if (FRAME_WINDOW_P (it
->f
))
24812 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24813 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24814 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24818 /* List should start with `space'. */
24819 eassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
24820 plist
= XCDR (it
->object
);
24822 /* Compute the width of the stretch. */
24823 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
24824 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
24826 /* Absolute width `:width WIDTH' specified and valid. */
24827 zero_width_ok_p
= 1;
24830 #ifdef HAVE_WINDOW_SYSTEM
24831 else if (FRAME_WINDOW_P (it
->f
)
24832 && (prop
= Fplist_get (plist
, QCrelative_width
), NUMVAL (prop
) > 0))
24834 /* Relative width `:relative-width FACTOR' specified and valid.
24835 Compute the width of the characters having the `glyph'
24838 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
24841 if (it
->multibyte_p
)
24842 it2
.c
= it2
.char_to_display
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
24845 it2
.c
= it2
.char_to_display
= *p
, it2
.len
= 1;
24846 if (! ASCII_CHAR_P (it2
.c
))
24847 it2
.char_to_display
= BYTE8_TO_CHAR (it2
.c
);
24850 it2
.glyph_row
= NULL
;
24851 it2
.what
= IT_CHARACTER
;
24852 x_produce_glyphs (&it2
);
24853 width
= NUMVAL (prop
) * it2
.pixel_width
;
24855 #endif /* HAVE_WINDOW_SYSTEM */
24856 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
24857 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
24859 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
24860 align_to
= (align_to
< 0
24862 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
24863 else if (align_to
< 0)
24864 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
24865 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
24866 zero_width_ok_p
= 1;
24869 /* Nothing specified -> width defaults to canonical char width. */
24870 width
= FRAME_COLUMN_WIDTH (it
->f
);
24872 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
24875 #ifdef HAVE_WINDOW_SYSTEM
24876 /* Compute height. */
24877 if (FRAME_WINDOW_P (it
->f
))
24879 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
24880 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
24883 zero_height_ok_p
= 1;
24885 else if (prop
= Fplist_get (plist
, QCrelative_height
),
24887 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
24889 height
= FONT_HEIGHT (font
);
24891 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
24894 /* Compute percentage of height used for ascent. If
24895 `:ascent ASCENT' is present and valid, use that. Otherwise,
24896 derive the ascent from the font in use. */
24897 if (prop
= Fplist_get (plist
, QCascent
),
24898 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
24899 ascent
= height
* NUMVAL (prop
) / 100.0;
24900 else if (!NILP (prop
)
24901 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
24902 ascent
= min (max (0, (int)tem
), height
);
24904 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
24907 #endif /* HAVE_WINDOW_SYSTEM */
24910 if (width
> 0 && it
->line_wrap
!= TRUNCATE
24911 && it
->current_x
+ width
> it
->last_visible_x
)
24913 width
= it
->last_visible_x
- it
->current_x
;
24914 #ifdef HAVE_WINDOW_SYSTEM
24915 /* Subtract one more pixel from the stretch width, but only on
24916 GUI frames, since on a TTY each glyph is one "pixel" wide. */
24917 width
-= FRAME_WINDOW_P (it
->f
);
24921 if (width
> 0 && height
> 0 && it
->glyph_row
)
24923 Lisp_Object o_object
= it
->object
;
24924 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
24927 if (!STRINGP (object
))
24928 object
= it
->w
->contents
;
24929 #ifdef HAVE_WINDOW_SYSTEM
24930 if (FRAME_WINDOW_P (it
->f
))
24931 append_stretch_glyph (it
, object
, width
, height
, ascent
);
24935 it
->object
= object
;
24936 it
->char_to_display
= ' ';
24937 it
->pixel_width
= it
->len
= 1;
24939 tty_append_glyph (it
);
24940 it
->object
= o_object
;
24944 it
->pixel_width
= width
;
24945 #ifdef HAVE_WINDOW_SYSTEM
24946 if (FRAME_WINDOW_P (it
->f
))
24948 it
->ascent
= it
->phys_ascent
= ascent
;
24949 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
24950 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
24951 take_vertical_position_into_account (it
);
24955 it
->nglyphs
= width
;
24958 /* Get information about special display element WHAT in an
24959 environment described by IT. WHAT is one of IT_TRUNCATION or
24960 IT_CONTINUATION. Maybe produce glyphs for WHAT if IT has a
24961 non-null glyph_row member. This function ensures that fields like
24962 face_id, c, len of IT are left untouched. */
24965 produce_special_glyphs (struct it
*it
, enum display_element_type what
)
24972 temp_it
.object
= make_number (0);
24973 memset (&temp_it
.current
, 0, sizeof temp_it
.current
);
24975 if (what
== IT_CONTINUATION
)
24977 /* Continuation glyph. For R2L lines, we mirror it by hand. */
24978 if (it
->bidi_it
.paragraph_dir
== R2L
)
24979 SET_GLYPH_FROM_CHAR (glyph
, '/');
24981 SET_GLYPH_FROM_CHAR (glyph
, '\\');
24983 && (gc
= DISP_CONTINUE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
24985 /* FIXME: Should we mirror GC for R2L lines? */
24986 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
24987 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
24990 else if (what
== IT_TRUNCATION
)
24992 /* Truncation glyph. */
24993 SET_GLYPH_FROM_CHAR (glyph
, '$');
24995 && (gc
= DISP_TRUNC_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
24997 /* FIXME: Should we mirror GC for R2L lines? */
24998 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
24999 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
25005 #ifdef HAVE_WINDOW_SYSTEM
25006 /* On a GUI frame, when the right fringe (left fringe for R2L rows)
25007 is turned off, we precede the truncation/continuation glyphs by a
25008 stretch glyph whose width is computed such that these special
25009 glyphs are aligned at the window margin, even when very different
25010 fonts are used in different glyph rows. */
25011 if (FRAME_WINDOW_P (temp_it
.f
)
25012 /* init_iterator calls this with it->glyph_row == NULL, and it
25013 wants only the pixel width of the truncation/continuation
25015 && temp_it
.glyph_row
25016 /* insert_left_trunc_glyphs calls us at the beginning of the
25017 row, and it has its own calculation of the stretch glyph
25019 && temp_it
.glyph_row
->used
[TEXT_AREA
] > 0
25020 && (temp_it
.glyph_row
->reversed_p
25021 ? WINDOW_LEFT_FRINGE_WIDTH (temp_it
.w
)
25022 : WINDOW_RIGHT_FRINGE_WIDTH (temp_it
.w
)) == 0)
25024 int stretch_width
= temp_it
.last_visible_x
- temp_it
.current_x
;
25026 if (stretch_width
> 0)
25028 struct face
*face
= FACE_FROM_ID (temp_it
.f
, temp_it
.face_id
);
25029 struct font
*font
=
25030 face
->font
? face
->font
: FRAME_FONT (temp_it
.f
);
25031 int stretch_ascent
=
25032 (((temp_it
.ascent
+ temp_it
.descent
)
25033 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
25035 append_stretch_glyph (&temp_it
, make_number (0), stretch_width
,
25036 temp_it
.ascent
+ temp_it
.descent
,
25043 temp_it
.what
= IT_CHARACTER
;
25045 temp_it
.c
= temp_it
.char_to_display
= GLYPH_CHAR (glyph
);
25046 temp_it
.face_id
= GLYPH_FACE (glyph
);
25047 temp_it
.len
= CHAR_BYTES (temp_it
.c
);
25049 PRODUCE_GLYPHS (&temp_it
);
25050 it
->pixel_width
= temp_it
.pixel_width
;
25051 it
->nglyphs
= temp_it
.pixel_width
;
25054 #ifdef HAVE_WINDOW_SYSTEM
25056 /* Calculate line-height and line-spacing properties.
25057 An integer value specifies explicit pixel value.
25058 A float value specifies relative value to current face height.
25059 A cons (float . face-name) specifies relative value to
25060 height of specified face font.
25062 Returns height in pixels, or nil. */
25066 calc_line_height_property (struct it
*it
, Lisp_Object val
, struct font
*font
,
25067 int boff
, int override
)
25069 Lisp_Object face_name
= Qnil
;
25070 int ascent
, descent
, height
;
25072 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
25077 face_name
= XCAR (val
);
25079 if (!NUMBERP (val
))
25080 val
= make_number (1);
25081 if (NILP (face_name
))
25083 height
= it
->ascent
+ it
->descent
;
25088 if (NILP (face_name
))
25090 font
= FRAME_FONT (it
->f
);
25091 boff
= FRAME_BASELINE_OFFSET (it
->f
);
25093 else if (EQ (face_name
, Qt
))
25102 face_id
= lookup_named_face (it
->f
, face_name
, 0);
25104 return make_number (-1);
25106 face
= FACE_FROM_ID (it
->f
, face_id
);
25109 return make_number (-1);
25110 boff
= font
->baseline_offset
;
25111 if (font
->vertical_centering
)
25112 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
25115 ascent
= FONT_BASE (font
) + boff
;
25116 descent
= FONT_DESCENT (font
) - boff
;
25120 it
->override_ascent
= ascent
;
25121 it
->override_descent
= descent
;
25122 it
->override_boff
= boff
;
25125 height
= ascent
+ descent
;
25129 height
= (int)(XFLOAT_DATA (val
) * height
);
25130 else if (INTEGERP (val
))
25131 height
*= XINT (val
);
25133 return make_number (height
);
25137 /* Append a glyph for a glyphless character to IT->glyph_row. FACE_ID
25138 is a face ID to be used for the glyph. FOR_NO_FONT is nonzero if
25139 and only if this is for a character for which no font was found.
25141 If the display method (it->glyphless_method) is
25142 GLYPHLESS_DISPLAY_ACRONYM or GLYPHLESS_DISPLAY_HEX_CODE, LEN is a
25143 length of the acronym or the hexadecimal string, UPPER_XOFF and
25144 UPPER_YOFF are pixel offsets for the upper part of the string,
25145 LOWER_XOFF and LOWER_YOFF are for the lower part.
25147 For the other display methods, LEN through LOWER_YOFF are zero. */
25150 append_glyphless_glyph (struct it
*it
, int face_id
, int for_no_font
, int len
,
25151 short upper_xoff
, short upper_yoff
,
25152 short lower_xoff
, short lower_yoff
)
25154 struct glyph
*glyph
;
25155 enum glyph_row_area area
= it
->area
;
25157 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
25158 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
25160 /* If the glyph row is reversed, we need to prepend the glyph
25161 rather than append it. */
25162 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
25166 /* Make room for the additional glyph. */
25167 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
25169 glyph
= it
->glyph_row
->glyphs
[area
];
25171 glyph
->charpos
= CHARPOS (it
->position
);
25172 glyph
->object
= it
->object
;
25173 glyph
->pixel_width
= it
->pixel_width
;
25174 glyph
->ascent
= it
->ascent
;
25175 glyph
->descent
= it
->descent
;
25176 glyph
->voffset
= it
->voffset
;
25177 glyph
->type
= GLYPHLESS_GLYPH
;
25178 glyph
->u
.glyphless
.method
= it
->glyphless_method
;
25179 glyph
->u
.glyphless
.for_no_font
= for_no_font
;
25180 glyph
->u
.glyphless
.len
= len
;
25181 glyph
->u
.glyphless
.ch
= it
->c
;
25182 glyph
->slice
.glyphless
.upper_xoff
= upper_xoff
;
25183 glyph
->slice
.glyphless
.upper_yoff
= upper_yoff
;
25184 glyph
->slice
.glyphless
.lower_xoff
= lower_xoff
;
25185 glyph
->slice
.glyphless
.lower_yoff
= lower_yoff
;
25186 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
25187 glyph
->multibyte_p
= it
->multibyte_p
;
25188 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
25190 /* In R2L rows, the left and the right box edges need to be
25191 drawn in reverse direction. */
25192 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
25193 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
25197 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
25198 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
25200 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
25201 || it
->phys_descent
> it
->descent
);
25202 glyph
->padding_p
= 0;
25203 glyph
->glyph_not_available_p
= 0;
25204 glyph
->face_id
= face_id
;
25205 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
25208 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
25209 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
25211 glyph
->bidi_type
= it
->bidi_it
.type
;
25213 ++it
->glyph_row
->used
[area
];
25216 IT_EXPAND_MATRIX_WIDTH (it
, area
);
25220 /* Produce a glyph for a glyphless character for iterator IT.
25221 IT->glyphless_method specifies which method to use for displaying
25222 the character. See the description of enum
25223 glyphless_display_method in dispextern.h for the detail.
25225 FOR_NO_FONT is nonzero if and only if this is for a character for
25226 which no font was found. ACRONYM, if non-nil, is an acronym string
25227 for the character. */
25230 produce_glyphless_glyph (struct it
*it
, int for_no_font
, Lisp_Object acronym
)
25235 int base_width
, base_height
, width
, height
;
25236 short upper_xoff
, upper_yoff
, lower_xoff
, lower_yoff
;
25239 /* Get the metrics of the base font. We always refer to the current
25241 face
= FACE_FROM_ID (it
->f
, it
->face_id
)->ascii_face
;
25242 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
25243 it
->ascent
= FONT_BASE (font
) + font
->baseline_offset
;
25244 it
->descent
= FONT_DESCENT (font
) - font
->baseline_offset
;
25245 base_height
= it
->ascent
+ it
->descent
;
25246 base_width
= font
->average_width
;
25248 face_id
= merge_glyphless_glyph_face (it
);
25250 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_THIN_SPACE
)
25252 it
->pixel_width
= THIN_SPACE_WIDTH
;
25254 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
25256 else if (it
->glyphless_method
== GLYPHLESS_DISPLAY_EMPTY_BOX
)
25258 width
= CHAR_WIDTH (it
->c
);
25261 else if (width
> 4)
25263 it
->pixel_width
= base_width
* width
;
25265 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
25271 unsigned int code
[6];
25273 int ascent
, descent
;
25274 struct font_metrics metrics_upper
, metrics_lower
;
25276 face
= FACE_FROM_ID (it
->f
, face_id
);
25277 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
25278 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
25280 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_ACRONYM
)
25282 if (! STRINGP (acronym
) && CHAR_TABLE_P (Vglyphless_char_display
))
25283 acronym
= CHAR_TABLE_REF (Vglyphless_char_display
, it
->c
);
25284 if (CONSP (acronym
))
25285 acronym
= XCAR (acronym
);
25286 str
= STRINGP (acronym
) ? SSDATA (acronym
) : "";
25290 eassert (it
->glyphless_method
== GLYPHLESS_DISPLAY_HEX_CODE
);
25291 sprintf (buf
, "%0*X", it
->c
< 0x10000 ? 4 : 6, it
->c
);
25294 for (len
= 0; str
[len
] && ASCII_BYTE_P (str
[len
]) && len
< 6; len
++)
25295 code
[len
] = font
->driver
->encode_char (font
, str
[len
]);
25296 upper_len
= (len
+ 1) / 2;
25297 font
->driver
->text_extents (font
, code
, upper_len
,
25299 font
->driver
->text_extents (font
, code
+ upper_len
, len
- upper_len
,
25304 /* +4 is for vertical bars of a box plus 1-pixel spaces at both side. */
25305 width
= max (metrics_upper
.width
, metrics_lower
.width
) + 4;
25306 upper_xoff
= upper_yoff
= 2; /* the typical case */
25307 if (base_width
>= width
)
25309 /* Align the upper to the left, the lower to the right. */
25310 it
->pixel_width
= base_width
;
25311 lower_xoff
= base_width
- 2 - metrics_lower
.width
;
25315 /* Center the shorter one. */
25316 it
->pixel_width
= width
;
25317 if (metrics_upper
.width
>= metrics_lower
.width
)
25318 lower_xoff
= (width
- metrics_lower
.width
) / 2;
25321 /* FIXME: This code doesn't look right. It formerly was
25322 missing the "lower_xoff = 0;", which couldn't have
25323 been right since it left lower_xoff uninitialized. */
25325 upper_xoff
= (width
- metrics_upper
.width
) / 2;
25329 /* +5 is for horizontal bars of a box plus 1-pixel spaces at
25330 top, bottom, and between upper and lower strings. */
25331 height
= (metrics_upper
.ascent
+ metrics_upper
.descent
25332 + metrics_lower
.ascent
+ metrics_lower
.descent
) + 5;
25333 /* Center vertically.
25334 H:base_height, D:base_descent
25335 h:height, ld:lower_descent, la:lower_ascent, ud:upper_descent
25337 ascent = - (D - H/2 - h/2 + 1); "+ 1" for rounding up
25338 descent = D - H/2 + h/2;
25339 lower_yoff = descent - 2 - ld;
25340 upper_yoff = lower_yoff - la - 1 - ud; */
25341 ascent
= - (it
->descent
- (base_height
+ height
+ 1) / 2);
25342 descent
= it
->descent
- (base_height
- height
) / 2;
25343 lower_yoff
= descent
- 2 - metrics_lower
.descent
;
25344 upper_yoff
= (lower_yoff
- metrics_lower
.ascent
- 1
25345 - metrics_upper
.descent
);
25346 /* Don't make the height shorter than the base height. */
25347 if (height
> base_height
)
25349 it
->ascent
= ascent
;
25350 it
->descent
= descent
;
25354 it
->phys_ascent
= it
->ascent
;
25355 it
->phys_descent
= it
->descent
;
25357 append_glyphless_glyph (it
, face_id
, for_no_font
, len
,
25358 upper_xoff
, upper_yoff
,
25359 lower_xoff
, lower_yoff
);
25361 take_vertical_position_into_account (it
);
25366 Produce glyphs/get display metrics for the display element IT is
25367 loaded with. See the description of struct it in dispextern.h
25368 for an overview of struct it. */
25371 x_produce_glyphs (struct it
*it
)
25373 int extra_line_spacing
= it
->extra_line_spacing
;
25375 it
->glyph_not_available_p
= 0;
25377 if (it
->what
== IT_CHARACTER
)
25380 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25381 struct font
*font
= face
->font
;
25382 struct font_metrics
*pcm
= NULL
;
25383 int boff
; /* Baseline offset. */
25387 /* When no suitable font is found, display this character by
25388 the method specified in the first extra slot of
25389 Vglyphless_char_display. */
25390 Lisp_Object acronym
= lookup_glyphless_char_display (-1, it
);
25392 eassert (it
->what
== IT_GLYPHLESS
);
25393 produce_glyphless_glyph (it
, 1, STRINGP (acronym
) ? acronym
: Qnil
);
25397 boff
= font
->baseline_offset
;
25398 if (font
->vertical_centering
)
25399 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
25401 if (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t')
25407 if (it
->override_ascent
>= 0)
25409 it
->ascent
= it
->override_ascent
;
25410 it
->descent
= it
->override_descent
;
25411 boff
= it
->override_boff
;
25415 it
->ascent
= FONT_BASE (font
) + boff
;
25416 it
->descent
= FONT_DESCENT (font
) - boff
;
25419 if (get_char_glyph_code (it
->char_to_display
, font
, &char2b
))
25421 pcm
= get_per_char_metric (font
, &char2b
);
25422 if (pcm
->width
== 0
25423 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
25429 it
->phys_ascent
= pcm
->ascent
+ boff
;
25430 it
->phys_descent
= pcm
->descent
- boff
;
25431 it
->pixel_width
= pcm
->width
;
25435 it
->glyph_not_available_p
= 1;
25436 it
->phys_ascent
= it
->ascent
;
25437 it
->phys_descent
= it
->descent
;
25438 it
->pixel_width
= font
->space_width
;
25441 if (it
->constrain_row_ascent_descent_p
)
25443 if (it
->descent
> it
->max_descent
)
25445 it
->ascent
+= it
->descent
- it
->max_descent
;
25446 it
->descent
= it
->max_descent
;
25448 if (it
->ascent
> it
->max_ascent
)
25450 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
25451 it
->ascent
= it
->max_ascent
;
25453 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
25454 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
25455 extra_line_spacing
= 0;
25458 /* If this is a space inside a region of text with
25459 `space-width' property, change its width. */
25460 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
25462 it
->pixel_width
*= XFLOATINT (it
->space_width
);
25464 /* If face has a box, add the box thickness to the character
25465 height. If character has a box line to the left and/or
25466 right, add the box line width to the character's width. */
25467 if (face
->box
!= FACE_NO_BOX
)
25469 int thick
= face
->box_line_width
;
25473 it
->ascent
+= thick
;
25474 it
->descent
+= thick
;
25479 if (it
->start_of_box_run_p
)
25480 it
->pixel_width
+= thick
;
25481 if (it
->end_of_box_run_p
)
25482 it
->pixel_width
+= thick
;
25485 /* If face has an overline, add the height of the overline
25486 (1 pixel) and a 1 pixel margin to the character height. */
25487 if (face
->overline_p
)
25488 it
->ascent
+= overline_margin
;
25490 if (it
->constrain_row_ascent_descent_p
)
25492 if (it
->ascent
> it
->max_ascent
)
25493 it
->ascent
= it
->max_ascent
;
25494 if (it
->descent
> it
->max_descent
)
25495 it
->descent
= it
->max_descent
;
25498 take_vertical_position_into_account (it
);
25500 /* If we have to actually produce glyphs, do it. */
25505 /* Translate a space with a `space-width' property
25506 into a stretch glyph. */
25507 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
25508 / FONT_HEIGHT (font
));
25509 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
25510 it
->ascent
+ it
->descent
, ascent
);
25515 /* If characters with lbearing or rbearing are displayed
25516 in this line, record that fact in a flag of the
25517 glyph row. This is used to optimize X output code. */
25518 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
25519 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25521 if (! stretched_p
&& it
->pixel_width
== 0)
25522 /* We assure that all visible glyphs have at least 1-pixel
25524 it
->pixel_width
= 1;
25526 else if (it
->char_to_display
== '\n')
25528 /* A newline has no width, but we need the height of the
25529 line. But if previous part of the line sets a height,
25530 don't increase that height. */
25532 Lisp_Object height
;
25533 Lisp_Object total_height
= Qnil
;
25535 it
->override_ascent
= -1;
25536 it
->pixel_width
= 0;
25539 height
= get_it_property (it
, Qline_height
);
25540 /* Split (line-height total-height) list. */
25542 && CONSP (XCDR (height
))
25543 && NILP (XCDR (XCDR (height
))))
25545 total_height
= XCAR (XCDR (height
));
25546 height
= XCAR (height
);
25548 height
= calc_line_height_property (it
, height
, font
, boff
, 1);
25550 if (it
->override_ascent
>= 0)
25552 it
->ascent
= it
->override_ascent
;
25553 it
->descent
= it
->override_descent
;
25554 boff
= it
->override_boff
;
25558 it
->ascent
= FONT_BASE (font
) + boff
;
25559 it
->descent
= FONT_DESCENT (font
) - boff
;
25562 if (EQ (height
, Qt
))
25564 if (it
->descent
> it
->max_descent
)
25566 it
->ascent
+= it
->descent
- it
->max_descent
;
25567 it
->descent
= it
->max_descent
;
25569 if (it
->ascent
> it
->max_ascent
)
25571 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
25572 it
->ascent
= it
->max_ascent
;
25574 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
25575 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
25576 it
->constrain_row_ascent_descent_p
= 1;
25577 extra_line_spacing
= 0;
25581 Lisp_Object spacing
;
25583 it
->phys_ascent
= it
->ascent
;
25584 it
->phys_descent
= it
->descent
;
25586 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
25587 && face
->box
!= FACE_NO_BOX
25588 && face
->box_line_width
> 0)
25590 it
->ascent
+= face
->box_line_width
;
25591 it
->descent
+= face
->box_line_width
;
25594 && XINT (height
) > it
->ascent
+ it
->descent
)
25595 it
->ascent
= XINT (height
) - it
->descent
;
25597 if (!NILP (total_height
))
25598 spacing
= calc_line_height_property (it
, total_height
, font
, boff
, 0);
25601 spacing
= get_it_property (it
, Qline_spacing
);
25602 spacing
= calc_line_height_property (it
, spacing
, font
, boff
, 0);
25604 if (INTEGERP (spacing
))
25606 extra_line_spacing
= XINT (spacing
);
25607 if (!NILP (total_height
))
25608 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
25612 else /* i.e. (it->char_to_display == '\t') */
25614 if (font
->space_width
> 0)
25616 int tab_width
= it
->tab_width
* font
->space_width
;
25617 int x
= it
->current_x
+ it
->continuation_lines_width
;
25618 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
25620 /* If the distance from the current position to the next tab
25621 stop is less than a space character width, use the
25622 tab stop after that. */
25623 if (next_tab_x
- x
< font
->space_width
)
25624 next_tab_x
+= tab_width
;
25626 it
->pixel_width
= next_tab_x
- x
;
25628 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
25629 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
25633 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
25634 it
->ascent
+ it
->descent
, it
->ascent
);
25639 it
->pixel_width
= 0;
25644 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
25646 /* A static composition.
25648 Note: A composition is represented as one glyph in the
25649 glyph matrix. There are no padding glyphs.
25651 Important note: pixel_width, ascent, and descent are the
25652 values of what is drawn by draw_glyphs (i.e. the values of
25653 the overall glyphs composed). */
25654 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25655 int boff
; /* baseline offset */
25656 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
25657 int glyph_len
= cmp
->glyph_len
;
25658 struct font
*font
= face
->font
;
25662 /* If we have not yet calculated pixel size data of glyphs of
25663 the composition for the current face font, calculate them
25664 now. Theoretically, we have to check all fonts for the
25665 glyphs, but that requires much time and memory space. So,
25666 here we check only the font of the first glyph. This may
25667 lead to incorrect display, but it's very rare, and C-l
25668 (recenter-top-bottom) can correct the display anyway. */
25669 if (! cmp
->font
|| cmp
->font
!= font
)
25671 /* Ascent and descent of the font of the first character
25672 of this composition (adjusted by baseline offset).
25673 Ascent and descent of overall glyphs should not be less
25674 than these, respectively. */
25675 int font_ascent
, font_descent
, font_height
;
25676 /* Bounding box of the overall glyphs. */
25677 int leftmost
, rightmost
, lowest
, highest
;
25678 int lbearing
, rbearing
;
25679 int i
, width
, ascent
, descent
;
25680 int left_padded
= 0, right_padded
= 0;
25681 int c
IF_LINT (= 0); /* cmp->glyph_len can't be zero; see Bug#8512 */
25683 struct font_metrics
*pcm
;
25684 int font_not_found_p
;
25687 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
25688 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
25690 if (glyph_len
< cmp
->glyph_len
)
25692 for (i
= 0; i
< glyph_len
; i
++)
25694 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
25696 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
25701 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
25702 : IT_CHARPOS (*it
));
25703 /* If no suitable font is found, use the default font. */
25704 font_not_found_p
= font
== NULL
;
25705 if (font_not_found_p
)
25707 face
= face
->ascii_face
;
25710 boff
= font
->baseline_offset
;
25711 if (font
->vertical_centering
)
25712 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
25713 font_ascent
= FONT_BASE (font
) + boff
;
25714 font_descent
= FONT_DESCENT (font
) - boff
;
25715 font_height
= FONT_HEIGHT (font
);
25720 if (! font_not_found_p
)
25722 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
25724 pcm
= get_per_char_metric (font
, &char2b
);
25727 /* Initialize the bounding box. */
25730 width
= cmp
->glyph_len
> 0 ? pcm
->width
: 0;
25731 ascent
= pcm
->ascent
;
25732 descent
= pcm
->descent
;
25733 lbearing
= pcm
->lbearing
;
25734 rbearing
= pcm
->rbearing
;
25738 width
= cmp
->glyph_len
> 0 ? font
->space_width
: 0;
25739 ascent
= FONT_BASE (font
);
25740 descent
= FONT_DESCENT (font
);
25747 lowest
= - descent
+ boff
;
25748 highest
= ascent
+ boff
;
25750 if (! font_not_found_p
25751 && font
->default_ascent
25752 && CHAR_TABLE_P (Vuse_default_ascent
)
25753 && !NILP (Faref (Vuse_default_ascent
,
25754 make_number (it
->char_to_display
))))
25755 highest
= font
->default_ascent
+ boff
;
25757 /* Draw the first glyph at the normal position. It may be
25758 shifted to right later if some other glyphs are drawn
25760 cmp
->offsets
[i
* 2] = 0;
25761 cmp
->offsets
[i
* 2 + 1] = boff
;
25762 cmp
->lbearing
= lbearing
;
25763 cmp
->rbearing
= rbearing
;
25765 /* Set cmp->offsets for the remaining glyphs. */
25766 for (i
++; i
< glyph_len
; i
++)
25768 int left
, right
, btm
, top
;
25769 int ch
= COMPOSITION_GLYPH (cmp
, i
);
25771 struct face
*this_face
;
25775 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
25776 this_face
= FACE_FROM_ID (it
->f
, face_id
);
25777 font
= this_face
->font
;
25783 get_char_face_and_encoding (it
->f
, ch
, face_id
,
25785 pcm
= get_per_char_metric (font
, &char2b
);
25788 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
25791 width
= pcm
->width
;
25792 ascent
= pcm
->ascent
;
25793 descent
= pcm
->descent
;
25794 lbearing
= pcm
->lbearing
;
25795 rbearing
= pcm
->rbearing
;
25796 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
25798 /* Relative composition with or without
25799 alternate chars. */
25800 left
= (leftmost
+ rightmost
- width
) / 2;
25801 btm
= - descent
+ boff
;
25802 if (font
->relative_compose
25803 && (! CHAR_TABLE_P (Vignore_relative_composition
)
25804 || NILP (Faref (Vignore_relative_composition
,
25805 make_number (ch
)))))
25808 if (- descent
>= font
->relative_compose
)
25809 /* One extra pixel between two glyphs. */
25811 else if (ascent
<= 0)
25812 /* One extra pixel between two glyphs. */
25813 btm
= lowest
- 1 - ascent
- descent
;
25818 /* A composition rule is specified by an integer
25819 value that encodes global and new reference
25820 points (GREF and NREF). GREF and NREF are
25821 specified by numbers as below:
25823 0---1---2 -- ascent
25827 9--10--11 -- center
25829 ---3---4---5--- baseline
25831 6---7---8 -- descent
25833 int rule
= COMPOSITION_RULE (cmp
, i
);
25834 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
25836 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
25837 grefx
= gref
% 3, nrefx
= nref
% 3;
25838 grefy
= gref
/ 3, nrefy
= nref
/ 3;
25840 xoff
= font_height
* (xoff
- 128) / 256;
25842 yoff
= font_height
* (yoff
- 128) / 256;
25845 + grefx
* (rightmost
- leftmost
) / 2
25846 - nrefx
* width
/ 2
25849 btm
= ((grefy
== 0 ? highest
25851 : grefy
== 2 ? lowest
25852 : (highest
+ lowest
) / 2)
25853 - (nrefy
== 0 ? ascent
+ descent
25854 : nrefy
== 1 ? descent
- boff
25856 : (ascent
+ descent
) / 2)
25860 cmp
->offsets
[i
* 2] = left
;
25861 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
25863 /* Update the bounding box of the overall glyphs. */
25866 right
= left
+ width
;
25867 if (left
< leftmost
)
25869 if (right
> rightmost
)
25872 top
= btm
+ descent
+ ascent
;
25878 if (cmp
->lbearing
> left
+ lbearing
)
25879 cmp
->lbearing
= left
+ lbearing
;
25880 if (cmp
->rbearing
< left
+ rbearing
)
25881 cmp
->rbearing
= left
+ rbearing
;
25885 /* If there are glyphs whose x-offsets are negative,
25886 shift all glyphs to the right and make all x-offsets
25890 for (i
= 0; i
< cmp
->glyph_len
; i
++)
25891 cmp
->offsets
[i
* 2] -= leftmost
;
25892 rightmost
-= leftmost
;
25893 cmp
->lbearing
-= leftmost
;
25894 cmp
->rbearing
-= leftmost
;
25897 if (left_padded
&& cmp
->lbearing
< 0)
25899 for (i
= 0; i
< cmp
->glyph_len
; i
++)
25900 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
25901 rightmost
-= cmp
->lbearing
;
25902 cmp
->rbearing
-= cmp
->lbearing
;
25905 if (right_padded
&& rightmost
< cmp
->rbearing
)
25907 rightmost
= cmp
->rbearing
;
25910 cmp
->pixel_width
= rightmost
;
25911 cmp
->ascent
= highest
;
25912 cmp
->descent
= - lowest
;
25913 if (cmp
->ascent
< font_ascent
)
25914 cmp
->ascent
= font_ascent
;
25915 if (cmp
->descent
< font_descent
)
25916 cmp
->descent
= font_descent
;
25920 && (cmp
->lbearing
< 0
25921 || cmp
->rbearing
> cmp
->pixel_width
))
25922 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25924 it
->pixel_width
= cmp
->pixel_width
;
25925 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
25926 it
->descent
= it
->phys_descent
= cmp
->descent
;
25927 if (face
->box
!= FACE_NO_BOX
)
25929 int thick
= face
->box_line_width
;
25933 it
->ascent
+= thick
;
25934 it
->descent
+= thick
;
25939 if (it
->start_of_box_run_p
)
25940 it
->pixel_width
+= thick
;
25941 if (it
->end_of_box_run_p
)
25942 it
->pixel_width
+= thick
;
25945 /* If face has an overline, add the height of the overline
25946 (1 pixel) and a 1 pixel margin to the character height. */
25947 if (face
->overline_p
)
25948 it
->ascent
+= overline_margin
;
25950 take_vertical_position_into_account (it
);
25951 if (it
->ascent
< 0)
25953 if (it
->descent
< 0)
25956 if (it
->glyph_row
&& cmp
->glyph_len
> 0)
25957 append_composite_glyph (it
);
25959 else if (it
->what
== IT_COMPOSITION
)
25961 /* A dynamic (automatic) composition. */
25962 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25963 Lisp_Object gstring
;
25964 struct font_metrics metrics
;
25968 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
25970 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
25973 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
25974 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25975 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
25976 it
->descent
= it
->phys_descent
= metrics
.descent
;
25977 if (face
->box
!= FACE_NO_BOX
)
25979 int thick
= face
->box_line_width
;
25983 it
->ascent
+= thick
;
25984 it
->descent
+= thick
;
25989 if (it
->start_of_box_run_p
)
25990 it
->pixel_width
+= thick
;
25991 if (it
->end_of_box_run_p
)
25992 it
->pixel_width
+= thick
;
25994 /* If face has an overline, add the height of the overline
25995 (1 pixel) and a 1 pixel margin to the character height. */
25996 if (face
->overline_p
)
25997 it
->ascent
+= overline_margin
;
25998 take_vertical_position_into_account (it
);
25999 if (it
->ascent
< 0)
26001 if (it
->descent
< 0)
26005 append_composite_glyph (it
);
26007 else if (it
->what
== IT_GLYPHLESS
)
26008 produce_glyphless_glyph (it
, 0, Qnil
);
26009 else if (it
->what
== IT_IMAGE
)
26010 produce_image_glyph (it
);
26011 else if (it
->what
== IT_STRETCH
)
26012 produce_stretch_glyph (it
);
26015 /* Accumulate dimensions. Note: can't assume that it->descent > 0
26016 because this isn't true for images with `:ascent 100'. */
26017 eassert (it
->ascent
>= 0 && it
->descent
>= 0);
26018 if (it
->area
== TEXT_AREA
)
26019 it
->current_x
+= it
->pixel_width
;
26021 if (extra_line_spacing
> 0)
26023 it
->descent
+= extra_line_spacing
;
26024 if (extra_line_spacing
> it
->max_extra_line_spacing
)
26025 it
->max_extra_line_spacing
= extra_line_spacing
;
26028 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
26029 it
->max_descent
= max (it
->max_descent
, it
->descent
);
26030 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
26031 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
26035 Output LEN glyphs starting at START at the nominal cursor position.
26036 Advance the nominal cursor over the text. UPDATED_ROW is the glyph row
26037 being updated, and UPDATED_AREA is the area of that row being updated. */
26040 x_write_glyphs (struct window
*w
, struct glyph_row
*updated_row
,
26041 struct glyph
*start
, enum glyph_row_area updated_area
, int len
)
26043 int x
, hpos
, chpos
= w
->phys_cursor
.hpos
;
26045 eassert (updated_row
);
26046 /* When the window is hscrolled, cursor hpos can legitimately be out
26047 of bounds, but we draw the cursor at the corresponding window
26048 margin in that case. */
26049 if (!updated_row
->reversed_p
&& chpos
< 0)
26051 if (updated_row
->reversed_p
&& chpos
>= updated_row
->used
[TEXT_AREA
])
26052 chpos
= updated_row
->used
[TEXT_AREA
] - 1;
26056 /* Write glyphs. */
26058 hpos
= start
- updated_row
->glyphs
[updated_area
];
26059 x
= draw_glyphs (w
, w
->output_cursor
.x
,
26060 updated_row
, updated_area
,
26062 DRAW_NORMAL_TEXT
, 0);
26064 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
26065 if (updated_area
== TEXT_AREA
26066 && w
->phys_cursor_on_p
26067 && w
->phys_cursor
.vpos
== w
->output_cursor
.vpos
26069 && chpos
< hpos
+ len
)
26070 w
->phys_cursor_on_p
= 0;
26074 /* Advance the output cursor. */
26075 w
->output_cursor
.hpos
+= len
;
26076 w
->output_cursor
.x
= x
;
26081 Insert LEN glyphs from START at the nominal cursor position. */
26084 x_insert_glyphs (struct window
*w
, struct glyph_row
*updated_row
,
26085 struct glyph
*start
, enum glyph_row_area updated_area
, int len
)
26088 int line_height
, shift_by_width
, shifted_region_width
;
26089 struct glyph_row
*row
;
26090 struct glyph
*glyph
;
26091 int frame_x
, frame_y
;
26094 eassert (updated_row
);
26096 f
= XFRAME (WINDOW_FRAME (w
));
26098 /* Get the height of the line we are in. */
26100 line_height
= row
->height
;
26102 /* Get the width of the glyphs to insert. */
26103 shift_by_width
= 0;
26104 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
26105 shift_by_width
+= glyph
->pixel_width
;
26107 /* Get the width of the region to shift right. */
26108 shifted_region_width
= (window_box_width (w
, updated_area
)
26109 - w
->output_cursor
.x
26113 frame_x
= window_box_left (w
, updated_area
) + w
->output_cursor
.x
;
26114 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, w
->output_cursor
.y
);
26116 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
26117 line_height
, shift_by_width
);
26119 /* Write the glyphs. */
26120 hpos
= start
- row
->glyphs
[updated_area
];
26121 draw_glyphs (w
, w
->output_cursor
.x
, row
, updated_area
,
26123 DRAW_NORMAL_TEXT
, 0);
26125 /* Advance the output cursor. */
26126 w
->output_cursor
.hpos
+= len
;
26127 w
->output_cursor
.x
+= shift_by_width
;
26133 Erase the current text line from the nominal cursor position
26134 (inclusive) to pixel column TO_X (exclusive). The idea is that
26135 everything from TO_X onward is already erased.
26137 TO_X is a pixel position relative to UPDATED_AREA of currently
26138 updated window W. TO_X == -1 means clear to the end of this area. */
26141 x_clear_end_of_line (struct window
*w
, struct glyph_row
*updated_row
,
26142 enum glyph_row_area updated_area
, int to_x
)
26145 int max_x
, min_y
, max_y
;
26146 int from_x
, from_y
, to_y
;
26148 eassert (updated_row
);
26149 f
= XFRAME (w
->frame
);
26151 if (updated_row
->full_width_p
)
26152 max_x
= (WINDOW_PIXEL_WIDTH (w
)
26153 - (updated_row
->mode_line_p
? WINDOW_RIGHT_DIVIDER_WIDTH (w
) : 0));
26155 max_x
= window_box_width (w
, updated_area
);
26156 max_y
= window_text_bottom_y (w
);
26158 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
26159 of window. For TO_X > 0, truncate to end of drawing area. */
26165 to_x
= min (to_x
, max_x
);
26167 to_y
= min (max_y
, w
->output_cursor
.y
+ updated_row
->height
);
26169 /* Notice if the cursor will be cleared by this operation. */
26170 if (!updated_row
->full_width_p
)
26171 notice_overwritten_cursor (w
, updated_area
,
26172 w
->output_cursor
.x
, -1,
26174 MATRIX_ROW_BOTTOM_Y (updated_row
));
26176 from_x
= w
->output_cursor
.x
;
26178 /* Translate to frame coordinates. */
26179 if (updated_row
->full_width_p
)
26181 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
26182 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
26186 int area_left
= window_box_left (w
, updated_area
);
26187 from_x
+= area_left
;
26191 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
26192 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, w
->output_cursor
.y
));
26193 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
26195 /* Prevent inadvertently clearing to end of the X window. */
26196 if (to_x
> from_x
&& to_y
> from_y
)
26199 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
26200 to_x
- from_x
, to_y
- from_y
);
26205 #endif /* HAVE_WINDOW_SYSTEM */
26209 /***********************************************************************
26211 ***********************************************************************/
26213 /* Value is the internal representation of the specified cursor type
26214 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
26215 of the bar cursor. */
26217 static enum text_cursor_kinds
26218 get_specified_cursor_type (Lisp_Object arg
, int *width
)
26220 enum text_cursor_kinds type
;
26225 if (EQ (arg
, Qbox
))
26226 return FILLED_BOX_CURSOR
;
26228 if (EQ (arg
, Qhollow
))
26229 return HOLLOW_BOX_CURSOR
;
26231 if (EQ (arg
, Qbar
))
26238 && EQ (XCAR (arg
), Qbar
)
26239 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
26241 *width
= XINT (XCDR (arg
));
26245 if (EQ (arg
, Qhbar
))
26248 return HBAR_CURSOR
;
26252 && EQ (XCAR (arg
), Qhbar
)
26253 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
26255 *width
= XINT (XCDR (arg
));
26256 return HBAR_CURSOR
;
26259 /* Treat anything unknown as "hollow box cursor".
26260 It was bad to signal an error; people have trouble fixing
26261 .Xdefaults with Emacs, when it has something bad in it. */
26262 type
= HOLLOW_BOX_CURSOR
;
26267 /* Set the default cursor types for specified frame. */
26269 set_frame_cursor_types (struct frame
*f
, Lisp_Object arg
)
26274 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
26275 FRAME_CURSOR_WIDTH (f
) = width
;
26277 /* By default, set up the blink-off state depending on the on-state. */
26279 tem
= Fassoc (arg
, Vblink_cursor_alist
);
26282 FRAME_BLINK_OFF_CURSOR (f
)
26283 = get_specified_cursor_type (XCDR (tem
), &width
);
26284 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
26287 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
26289 /* Make sure the cursor gets redrawn. */
26290 f
->cursor_type_changed
= 1;
26294 #ifdef HAVE_WINDOW_SYSTEM
26296 /* Return the cursor we want to be displayed in window W. Return
26297 width of bar/hbar cursor through WIDTH arg. Return with
26298 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
26299 (i.e. if the `system caret' should track this cursor).
26301 In a mini-buffer window, we want the cursor only to appear if we
26302 are reading input from this window. For the selected window, we
26303 want the cursor type given by the frame parameter or buffer local
26304 setting of cursor-type. If explicitly marked off, draw no cursor.
26305 In all other cases, we want a hollow box cursor. */
26307 static enum text_cursor_kinds
26308 get_window_cursor_type (struct window
*w
, struct glyph
*glyph
, int *width
,
26309 int *active_cursor
)
26311 struct frame
*f
= XFRAME (w
->frame
);
26312 struct buffer
*b
= XBUFFER (w
->contents
);
26313 int cursor_type
= DEFAULT_CURSOR
;
26314 Lisp_Object alt_cursor
;
26315 int non_selected
= 0;
26317 *active_cursor
= 1;
26320 if (cursor_in_echo_area
26321 && FRAME_HAS_MINIBUF_P (f
)
26322 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
26324 if (w
== XWINDOW (echo_area_window
))
26326 if (EQ (BVAR (b
, cursor_type
), Qt
) || NILP (BVAR (b
, cursor_type
)))
26328 *width
= FRAME_CURSOR_WIDTH (f
);
26329 return FRAME_DESIRED_CURSOR (f
);
26332 return get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
26335 *active_cursor
= 0;
26339 /* Detect a nonselected window or nonselected frame. */
26340 else if (w
!= XWINDOW (f
->selected_window
)
26341 || f
!= FRAME_DISPLAY_INFO (f
)->x_highlight_frame
)
26343 *active_cursor
= 0;
26345 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
26351 /* Never display a cursor in a window in which cursor-type is nil. */
26352 if (NILP (BVAR (b
, cursor_type
)))
26355 /* Get the normal cursor type for this window. */
26356 if (EQ (BVAR (b
, cursor_type
), Qt
))
26358 cursor_type
= FRAME_DESIRED_CURSOR (f
);
26359 *width
= FRAME_CURSOR_WIDTH (f
);
26362 cursor_type
= get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
26364 /* Use cursor-in-non-selected-windows instead
26365 for non-selected window or frame. */
26368 alt_cursor
= BVAR (b
, cursor_in_non_selected_windows
);
26369 if (!EQ (Qt
, alt_cursor
))
26370 return get_specified_cursor_type (alt_cursor
, width
);
26371 /* t means modify the normal cursor type. */
26372 if (cursor_type
== FILLED_BOX_CURSOR
)
26373 cursor_type
= HOLLOW_BOX_CURSOR
;
26374 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
26376 return cursor_type
;
26379 /* Use normal cursor if not blinked off. */
26380 if (!w
->cursor_off_p
)
26382 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
26384 if (cursor_type
== FILLED_BOX_CURSOR
)
26386 /* Using a block cursor on large images can be very annoying.
26387 So use a hollow cursor for "large" images.
26388 If image is not transparent (no mask), also use hollow cursor. */
26389 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
26390 if (img
!= NULL
&& IMAGEP (img
->spec
))
26392 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
26393 where N = size of default frame font size.
26394 This should cover most of the "tiny" icons people may use. */
26396 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
26397 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
26398 cursor_type
= HOLLOW_BOX_CURSOR
;
26401 else if (cursor_type
!= NO_CURSOR
)
26403 /* Display current only supports BOX and HOLLOW cursors for images.
26404 So for now, unconditionally use a HOLLOW cursor when cursor is
26405 not a solid box cursor. */
26406 cursor_type
= HOLLOW_BOX_CURSOR
;
26409 return cursor_type
;
26412 /* Cursor is blinked off, so determine how to "toggle" it. */
26414 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
26415 if ((alt_cursor
= Fassoc (BVAR (b
, cursor_type
), Vblink_cursor_alist
), !NILP (alt_cursor
)))
26416 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
26418 /* Then see if frame has specified a specific blink off cursor type. */
26419 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
26421 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
26422 return FRAME_BLINK_OFF_CURSOR (f
);
26426 /* Some people liked having a permanently visible blinking cursor,
26427 while others had very strong opinions against it. So it was
26428 decided to remove it. KFS 2003-09-03 */
26430 /* Finally perform built-in cursor blinking:
26431 filled box <-> hollow box
26432 wide [h]bar <-> narrow [h]bar
26433 narrow [h]bar <-> no cursor
26434 other type <-> no cursor */
26436 if (cursor_type
== FILLED_BOX_CURSOR
)
26437 return HOLLOW_BOX_CURSOR
;
26439 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
26442 return cursor_type
;
26450 /* Notice when the text cursor of window W has been completely
26451 overwritten by a drawing operation that outputs glyphs in AREA
26452 starting at X0 and ending at X1 in the line starting at Y0 and
26453 ending at Y1. X coordinates are area-relative. X1 < 0 means all
26454 the rest of the line after X0 has been written. Y coordinates
26455 are window-relative. */
26458 notice_overwritten_cursor (struct window
*w
, enum glyph_row_area area
,
26459 int x0
, int x1
, int y0
, int y1
)
26461 int cx0
, cx1
, cy0
, cy1
;
26462 struct glyph_row
*row
;
26464 if (!w
->phys_cursor_on_p
)
26466 if (area
!= TEXT_AREA
)
26469 if (w
->phys_cursor
.vpos
< 0
26470 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
26471 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
26472 !(row
->enabled_p
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
))))
26475 if (row
->cursor_in_fringe_p
)
26477 row
->cursor_in_fringe_p
= 0;
26478 draw_fringe_bitmap (w
, row
, row
->reversed_p
);
26479 w
->phys_cursor_on_p
= 0;
26483 cx0
= w
->phys_cursor
.x
;
26484 cx1
= cx0
+ w
->phys_cursor_width
;
26485 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
26488 /* The cursor image will be completely removed from the
26489 screen if the output area intersects the cursor area in
26490 y-direction. When we draw in [y0 y1[, and some part of
26491 the cursor is at y < y0, that part must have been drawn
26492 before. When scrolling, the cursor is erased before
26493 actually scrolling, so we don't come here. When not
26494 scrolling, the rows above the old cursor row must have
26495 changed, and in this case these rows must have written
26496 over the cursor image.
26498 Likewise if part of the cursor is below y1, with the
26499 exception of the cursor being in the first blank row at
26500 the buffer and window end because update_text_area
26501 doesn't draw that row. (Except when it does, but
26502 that's handled in update_text_area.) */
26504 cy0
= w
->phys_cursor
.y
;
26505 cy1
= cy0
+ w
->phys_cursor_height
;
26506 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
26509 w
->phys_cursor_on_p
= 0;
26512 #endif /* HAVE_WINDOW_SYSTEM */
26515 /************************************************************************
26517 ************************************************************************/
26519 #ifdef HAVE_WINDOW_SYSTEM
26522 Fix the display of area AREA of overlapping row ROW in window W
26523 with respect to the overlapping part OVERLAPS. */
26526 x_fix_overlapping_area (struct window
*w
, struct glyph_row
*row
,
26527 enum glyph_row_area area
, int overlaps
)
26534 for (i
= 0; i
< row
->used
[area
];)
26536 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
26538 int start
= i
, start_x
= x
;
26542 x
+= row
->glyphs
[area
][i
].pixel_width
;
26545 while (i
< row
->used
[area
]
26546 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
26548 draw_glyphs (w
, start_x
, row
, area
,
26550 DRAW_NORMAL_TEXT
, overlaps
);
26554 x
+= row
->glyphs
[area
][i
].pixel_width
;
26564 Draw the cursor glyph of window W in glyph row ROW. See the
26565 comment of draw_glyphs for the meaning of HL. */
26568 draw_phys_cursor_glyph (struct window
*w
, struct glyph_row
*row
,
26569 enum draw_glyphs_face hl
)
26571 /* If cursor hpos is out of bounds, don't draw garbage. This can
26572 happen in mini-buffer windows when switching between echo area
26573 glyphs and mini-buffer. */
26574 if ((row
->reversed_p
26575 ? (w
->phys_cursor
.hpos
>= 0)
26576 : (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])))
26578 int on_p
= w
->phys_cursor_on_p
;
26580 int hpos
= w
->phys_cursor
.hpos
;
26582 /* When the window is hscrolled, cursor hpos can legitimately be
26583 out of bounds, but we draw the cursor at the corresponding
26584 window margin in that case. */
26585 if (!row
->reversed_p
&& hpos
< 0)
26587 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26588 hpos
= row
->used
[TEXT_AREA
] - 1;
26590 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
, hpos
, hpos
+ 1,
26592 w
->phys_cursor_on_p
= on_p
;
26594 if (hl
== DRAW_CURSOR
)
26595 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
26596 /* When we erase the cursor, and ROW is overlapped by other
26597 rows, make sure that these overlapping parts of other rows
26599 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
26601 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
26603 if (row
> w
->current_matrix
->rows
26604 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
26605 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
26606 OVERLAPS_ERASED_CURSOR
);
26608 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
26609 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
26610 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
26611 OVERLAPS_ERASED_CURSOR
);
26617 /* Erase the image of a cursor of window W from the screen. */
26623 erase_phys_cursor (struct window
*w
)
26625 struct frame
*f
= XFRAME (w
->frame
);
26626 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
26627 int hpos
= w
->phys_cursor
.hpos
;
26628 int vpos
= w
->phys_cursor
.vpos
;
26629 int mouse_face_here_p
= 0;
26630 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
26631 struct glyph_row
*cursor_row
;
26632 struct glyph
*cursor_glyph
;
26633 enum draw_glyphs_face hl
;
26635 /* No cursor displayed or row invalidated => nothing to do on the
26637 if (w
->phys_cursor_type
== NO_CURSOR
)
26638 goto mark_cursor_off
;
26640 /* VPOS >= active_glyphs->nrows means that window has been resized.
26641 Don't bother to erase the cursor. */
26642 if (vpos
>= active_glyphs
->nrows
)
26643 goto mark_cursor_off
;
26645 /* If row containing cursor is marked invalid, there is nothing we
26647 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
26648 if (!cursor_row
->enabled_p
)
26649 goto mark_cursor_off
;
26651 /* If line spacing is > 0, old cursor may only be partially visible in
26652 window after split-window. So adjust visible height. */
26653 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
26654 window_text_bottom_y (w
) - cursor_row
->y
);
26656 /* If row is completely invisible, don't attempt to delete a cursor which
26657 isn't there. This can happen if cursor is at top of a window, and
26658 we switch to a buffer with a header line in that window. */
26659 if (cursor_row
->visible_height
<= 0)
26660 goto mark_cursor_off
;
26662 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
26663 if (cursor_row
->cursor_in_fringe_p
)
26665 cursor_row
->cursor_in_fringe_p
= 0;
26666 draw_fringe_bitmap (w
, cursor_row
, cursor_row
->reversed_p
);
26667 goto mark_cursor_off
;
26670 /* This can happen when the new row is shorter than the old one.
26671 In this case, either draw_glyphs or clear_end_of_line
26672 should have cleared the cursor. Note that we wouldn't be
26673 able to erase the cursor in this case because we don't have a
26674 cursor glyph at hand. */
26675 if ((cursor_row
->reversed_p
26676 ? (w
->phys_cursor
.hpos
< 0)
26677 : (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])))
26678 goto mark_cursor_off
;
26680 /* When the window is hscrolled, cursor hpos can legitimately be out
26681 of bounds, but we draw the cursor at the corresponding window
26682 margin in that case. */
26683 if (!cursor_row
->reversed_p
&& hpos
< 0)
26685 if (cursor_row
->reversed_p
&& hpos
>= cursor_row
->used
[TEXT_AREA
])
26686 hpos
= cursor_row
->used
[TEXT_AREA
] - 1;
26688 /* If the cursor is in the mouse face area, redisplay that when
26689 we clear the cursor. */
26690 if (! NILP (hlinfo
->mouse_face_window
)
26691 && coords_in_mouse_face_p (w
, hpos
, vpos
)
26692 /* Don't redraw the cursor's spot in mouse face if it is at the
26693 end of a line (on a newline). The cursor appears there, but
26694 mouse highlighting does not. */
26695 && cursor_row
->used
[TEXT_AREA
] > hpos
&& hpos
>= 0)
26696 mouse_face_here_p
= 1;
26698 /* Maybe clear the display under the cursor. */
26699 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
26702 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
26705 cursor_glyph
= get_phys_cursor_glyph (w
);
26706 if (cursor_glyph
== NULL
)
26707 goto mark_cursor_off
;
26709 width
= cursor_glyph
->pixel_width
;
26710 left_x
= window_box_left_offset (w
, TEXT_AREA
);
26711 x
= w
->phys_cursor
.x
;
26713 width
-= left_x
- x
;
26714 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
26715 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
26716 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
26719 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
26722 /* Erase the cursor by redrawing the character underneath it. */
26723 if (mouse_face_here_p
)
26724 hl
= DRAW_MOUSE_FACE
;
26726 hl
= DRAW_NORMAL_TEXT
;
26727 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
26730 w
->phys_cursor_on_p
= 0;
26731 w
->phys_cursor_type
= NO_CURSOR
;
26736 Display or clear cursor of window W. If ON is zero, clear the
26737 cursor. If it is non-zero, display the cursor. If ON is nonzero,
26738 where to put the cursor is specified by HPOS, VPOS, X and Y. */
26741 display_and_set_cursor (struct window
*w
, bool on
,
26742 int hpos
, int vpos
, int x
, int y
)
26744 struct frame
*f
= XFRAME (w
->frame
);
26745 int new_cursor_type
;
26746 int new_cursor_width
;
26748 struct glyph_row
*glyph_row
;
26749 struct glyph
*glyph
;
26751 /* This is pointless on invisible frames, and dangerous on garbaged
26752 windows and frames; in the latter case, the frame or window may
26753 be in the midst of changing its size, and x and y may be off the
26755 if (! FRAME_VISIBLE_P (f
)
26756 || FRAME_GARBAGED_P (f
)
26757 || vpos
>= w
->current_matrix
->nrows
26758 || hpos
>= w
->current_matrix
->matrix_w
)
26761 /* If cursor is off and we want it off, return quickly. */
26762 if (!on
&& !w
->phys_cursor_on_p
)
26765 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26766 /* If cursor row is not enabled, we don't really know where to
26767 display the cursor. */
26768 if (!glyph_row
->enabled_p
)
26770 w
->phys_cursor_on_p
= 0;
26775 if (!glyph_row
->exact_window_width_line_p
26776 || (0 <= hpos
&& hpos
< glyph_row
->used
[TEXT_AREA
]))
26777 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
26779 eassert (input_blocked_p ());
26781 /* Set new_cursor_type to the cursor we want to be displayed. */
26782 new_cursor_type
= get_window_cursor_type (w
, glyph
,
26783 &new_cursor_width
, &active_cursor
);
26785 /* If cursor is currently being shown and we don't want it to be or
26786 it is in the wrong place, or the cursor type is not what we want,
26788 if (w
->phys_cursor_on_p
26790 || w
->phys_cursor
.x
!= x
26791 || w
->phys_cursor
.y
!= y
26792 || new_cursor_type
!= w
->phys_cursor_type
26793 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
26794 && new_cursor_width
!= w
->phys_cursor_width
)))
26795 erase_phys_cursor (w
);
26797 /* Don't check phys_cursor_on_p here because that flag is only set
26798 to zero in some cases where we know that the cursor has been
26799 completely erased, to avoid the extra work of erasing the cursor
26800 twice. In other words, phys_cursor_on_p can be 1 and the cursor
26801 still not be visible, or it has only been partly erased. */
26804 w
->phys_cursor_ascent
= glyph_row
->ascent
;
26805 w
->phys_cursor_height
= glyph_row
->height
;
26807 /* Set phys_cursor_.* before x_draw_.* is called because some
26808 of them may need the information. */
26809 w
->phys_cursor
.x
= x
;
26810 w
->phys_cursor
.y
= glyph_row
->y
;
26811 w
->phys_cursor
.hpos
= hpos
;
26812 w
->phys_cursor
.vpos
= vpos
;
26815 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
26816 new_cursor_type
, new_cursor_width
,
26817 on
, active_cursor
);
26821 /* Switch the display of W's cursor on or off, according to the value
26825 update_window_cursor (struct window
*w
, bool on
)
26827 /* Don't update cursor in windows whose frame is in the process
26828 of being deleted. */
26829 if (w
->current_matrix
)
26831 int hpos
= w
->phys_cursor
.hpos
;
26832 int vpos
= w
->phys_cursor
.vpos
;
26833 struct glyph_row
*row
;
26835 if (vpos
>= w
->current_matrix
->nrows
26836 || hpos
>= w
->current_matrix
->matrix_w
)
26839 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26841 /* When the window is hscrolled, cursor hpos can legitimately be
26842 out of bounds, but we draw the cursor at the corresponding
26843 window margin in that case. */
26844 if (!row
->reversed_p
&& hpos
< 0)
26846 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26847 hpos
= row
->used
[TEXT_AREA
] - 1;
26850 display_and_set_cursor (w
, on
, hpos
, vpos
,
26851 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
26857 /* Call update_window_cursor with parameter ON_P on all leaf windows
26858 in the window tree rooted at W. */
26861 update_cursor_in_window_tree (struct window
*w
, bool on_p
)
26865 if (WINDOWP (w
->contents
))
26866 update_cursor_in_window_tree (XWINDOW (w
->contents
), on_p
);
26868 update_window_cursor (w
, on_p
);
26870 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
26876 Display the cursor on window W, or clear it, according to ON_P.
26877 Don't change the cursor's position. */
26880 x_update_cursor (struct frame
*f
, bool on_p
)
26882 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
26887 Clear the cursor of window W to background color, and mark the
26888 cursor as not shown. This is used when the text where the cursor
26889 is about to be rewritten. */
26892 x_clear_cursor (struct window
*w
)
26894 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
26895 update_window_cursor (w
, 0);
26898 #endif /* HAVE_WINDOW_SYSTEM */
26900 /* Implementation of draw_row_with_mouse_face for GUI sessions, GPM,
26903 draw_row_with_mouse_face (struct window
*w
, int start_x
, struct glyph_row
*row
,
26904 int start_hpos
, int end_hpos
,
26905 enum draw_glyphs_face draw
)
26907 #ifdef HAVE_WINDOW_SYSTEM
26908 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
26910 draw_glyphs (w
, start_x
, row
, TEXT_AREA
, start_hpos
, end_hpos
, draw
, 0);
26914 #if defined (HAVE_GPM) || defined (MSDOS) || defined (WINDOWSNT)
26915 tty_draw_row_with_mouse_face (w
, row
, start_hpos
, end_hpos
, draw
);
26919 /* Display the active region described by mouse_face_* according to DRAW. */
26922 show_mouse_face (Mouse_HLInfo
*hlinfo
, enum draw_glyphs_face draw
)
26924 struct window
*w
= XWINDOW (hlinfo
->mouse_face_window
);
26925 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
26927 if (/* If window is in the process of being destroyed, don't bother
26929 w
->current_matrix
!= NULL
26930 /* Don't update mouse highlight if hidden */
26931 && (draw
!= DRAW_MOUSE_FACE
|| !hlinfo
->mouse_face_hidden
)
26932 /* Recognize when we are called to operate on rows that don't exist
26933 anymore. This can happen when a window is split. */
26934 && hlinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
26936 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
26937 struct glyph_row
*row
, *first
, *last
;
26939 first
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
26940 last
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
26942 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
26944 int start_hpos
, end_hpos
, start_x
;
26946 /* For all but the first row, the highlight starts at column 0. */
26949 /* R2L rows have BEG and END in reversed order, but the
26950 screen drawing geometry is always left to right. So
26951 we need to mirror the beginning and end of the
26952 highlighted area in R2L rows. */
26953 if (!row
->reversed_p
)
26955 start_hpos
= hlinfo
->mouse_face_beg_col
;
26956 start_x
= hlinfo
->mouse_face_beg_x
;
26958 else if (row
== last
)
26960 start_hpos
= hlinfo
->mouse_face_end_col
;
26961 start_x
= hlinfo
->mouse_face_end_x
;
26969 else if (row
->reversed_p
&& row
== last
)
26971 start_hpos
= hlinfo
->mouse_face_end_col
;
26972 start_x
= hlinfo
->mouse_face_end_x
;
26982 if (!row
->reversed_p
)
26983 end_hpos
= hlinfo
->mouse_face_end_col
;
26984 else if (row
== first
)
26985 end_hpos
= hlinfo
->mouse_face_beg_col
;
26988 end_hpos
= row
->used
[TEXT_AREA
];
26989 if (draw
== DRAW_NORMAL_TEXT
)
26990 row
->fill_line_p
= 1; /* Clear to end of line */
26993 else if (row
->reversed_p
&& row
== first
)
26994 end_hpos
= hlinfo
->mouse_face_beg_col
;
26997 end_hpos
= row
->used
[TEXT_AREA
];
26998 if (draw
== DRAW_NORMAL_TEXT
)
26999 row
->fill_line_p
= 1; /* Clear to end of line */
27002 if (end_hpos
> start_hpos
)
27004 draw_row_with_mouse_face (w
, start_x
, row
,
27005 start_hpos
, end_hpos
, draw
);
27008 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
27012 #ifdef HAVE_WINDOW_SYSTEM
27013 /* When we've written over the cursor, arrange for it to
27014 be displayed again. */
27015 if (FRAME_WINDOW_P (f
)
27016 && phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
27018 int hpos
= w
->phys_cursor
.hpos
;
27020 /* When the window is hscrolled, cursor hpos can legitimately be
27021 out of bounds, but we draw the cursor at the corresponding
27022 window margin in that case. */
27023 if (!row
->reversed_p
&& hpos
< 0)
27025 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
27026 hpos
= row
->used
[TEXT_AREA
] - 1;
27029 display_and_set_cursor (w
, 1, hpos
, w
->phys_cursor
.vpos
,
27030 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
27033 #endif /* HAVE_WINDOW_SYSTEM */
27036 #ifdef HAVE_WINDOW_SYSTEM
27037 /* Change the mouse cursor. */
27038 if (FRAME_WINDOW_P (f
))
27040 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
27041 if (draw
== DRAW_NORMAL_TEXT
27042 && !EQ (hlinfo
->mouse_face_window
, f
->tool_bar_window
))
27043 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
27046 if (draw
== DRAW_MOUSE_FACE
)
27047 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
27049 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
27051 #endif /* HAVE_WINDOW_SYSTEM */
27055 Clear out the mouse-highlighted active region.
27056 Redraw it un-highlighted first. Value is non-zero if mouse
27057 face was actually drawn unhighlighted. */
27060 clear_mouse_face (Mouse_HLInfo
*hlinfo
)
27064 if (!hlinfo
->mouse_face_hidden
&& !NILP (hlinfo
->mouse_face_window
))
27066 show_mouse_face (hlinfo
, DRAW_NORMAL_TEXT
);
27070 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
27071 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
27072 hlinfo
->mouse_face_window
= Qnil
;
27073 hlinfo
->mouse_face_overlay
= Qnil
;
27077 /* Return non-zero if the coordinates HPOS and VPOS on windows W are
27078 within the mouse face on that window. */
27080 coords_in_mouse_face_p (struct window
*w
, int hpos
, int vpos
)
27082 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
27084 /* Quickly resolve the easy cases. */
27085 if (!(WINDOWP (hlinfo
->mouse_face_window
)
27086 && XWINDOW (hlinfo
->mouse_face_window
) == w
))
27088 if (vpos
< hlinfo
->mouse_face_beg_row
27089 || vpos
> hlinfo
->mouse_face_end_row
)
27091 if (vpos
> hlinfo
->mouse_face_beg_row
27092 && vpos
< hlinfo
->mouse_face_end_row
)
27095 if (!MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
)
27097 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
27099 if (hlinfo
->mouse_face_beg_col
<= hpos
&& hpos
< hlinfo
->mouse_face_end_col
)
27102 else if ((vpos
== hlinfo
->mouse_face_beg_row
27103 && hpos
>= hlinfo
->mouse_face_beg_col
)
27104 || (vpos
== hlinfo
->mouse_face_end_row
27105 && hpos
< hlinfo
->mouse_face_end_col
))
27110 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
27112 if (hlinfo
->mouse_face_end_col
< hpos
&& hpos
<= hlinfo
->mouse_face_beg_col
)
27115 else if ((vpos
== hlinfo
->mouse_face_beg_row
27116 && hpos
<= hlinfo
->mouse_face_beg_col
)
27117 || (vpos
== hlinfo
->mouse_face_end_row
27118 && hpos
> hlinfo
->mouse_face_end_col
))
27126 Non-zero if physical cursor of window W is within mouse face. */
27129 cursor_in_mouse_face_p (struct window
*w
)
27131 int hpos
= w
->phys_cursor
.hpos
;
27132 int vpos
= w
->phys_cursor
.vpos
;
27133 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
27135 /* When the window is hscrolled, cursor hpos can legitimately be out
27136 of bounds, but we draw the cursor at the corresponding window
27137 margin in that case. */
27138 if (!row
->reversed_p
&& hpos
< 0)
27140 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
27141 hpos
= row
->used
[TEXT_AREA
] - 1;
27143 return coords_in_mouse_face_p (w
, hpos
, vpos
);
27148 /* Find the glyph rows START_ROW and END_ROW of window W that display
27149 characters between buffer positions START_CHARPOS and END_CHARPOS
27150 (excluding END_CHARPOS). DISP_STRING is a display string that
27151 covers these buffer positions. This is similar to
27152 row_containing_pos, but is more accurate when bidi reordering makes
27153 buffer positions change non-linearly with glyph rows. */
27155 rows_from_pos_range (struct window
*w
,
27156 ptrdiff_t start_charpos
, ptrdiff_t end_charpos
,
27157 Lisp_Object disp_string
,
27158 struct glyph_row
**start
, struct glyph_row
**end
)
27160 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27161 int last_y
= window_text_bottom_y (w
);
27162 struct glyph_row
*row
;
27167 while (!first
->enabled_p
27168 && first
< MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
27171 /* Find the START row. */
27173 row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
;
27176 /* A row can potentially be the START row if the range of the
27177 characters it displays intersects the range
27178 [START_CHARPOS..END_CHARPOS). */
27179 if (! ((start_charpos
< MATRIX_ROW_START_CHARPOS (row
)
27180 && end_charpos
< MATRIX_ROW_START_CHARPOS (row
))
27181 /* See the commentary in row_containing_pos, for the
27182 explanation of the complicated way to check whether
27183 some position is beyond the end of the characters
27184 displayed by a row. */
27185 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (row
)
27186 || (start_charpos
== MATRIX_ROW_END_CHARPOS (row
)
27187 && !row
->ends_at_zv_p
27188 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
27189 && (end_charpos
> MATRIX_ROW_END_CHARPOS (row
)
27190 || (end_charpos
== MATRIX_ROW_END_CHARPOS (row
)
27191 && !row
->ends_at_zv_p
27192 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))))
27194 /* Found a candidate row. Now make sure at least one of the
27195 glyphs it displays has a charpos from the range
27196 [START_CHARPOS..END_CHARPOS).
27198 This is not obvious because bidi reordering could make
27199 buffer positions of a row be 1,2,3,102,101,100, and if we
27200 want to highlight characters in [50..60), we don't want
27201 this row, even though [50..60) does intersect [1..103),
27202 the range of character positions given by the row's start
27203 and end positions. */
27204 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
27205 struct glyph
*e
= g
+ row
->used
[TEXT_AREA
];
27209 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
27210 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
27211 /* A glyph that comes from DISP_STRING is by
27212 definition to be highlighted. */
27213 || EQ (g
->object
, disp_string
))
27222 /* Find the END row. */
27224 /* If the last row is partially visible, start looking for END
27225 from that row, instead of starting from FIRST. */
27226 && !(row
->enabled_p
27227 && row
->y
< last_y
&& MATRIX_ROW_BOTTOM_Y (row
) > last_y
))
27229 for ( ; row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
; row
++)
27231 struct glyph_row
*next
= row
+ 1;
27232 ptrdiff_t next_start
= MATRIX_ROW_START_CHARPOS (next
);
27234 if (!next
->enabled_p
27235 || next
>= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
)
27236 /* The first row >= START whose range of displayed characters
27237 does NOT intersect the range [START_CHARPOS..END_CHARPOS]
27238 is the row END + 1. */
27239 || (start_charpos
< next_start
27240 && end_charpos
< next_start
)
27241 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (next
)
27242 || (start_charpos
== MATRIX_ROW_END_CHARPOS (next
)
27243 && !next
->ends_at_zv_p
27244 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))
27245 && (end_charpos
> MATRIX_ROW_END_CHARPOS (next
)
27246 || (end_charpos
== MATRIX_ROW_END_CHARPOS (next
)
27247 && !next
->ends_at_zv_p
27248 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))))
27255 /* If the next row's edges intersect [START_CHARPOS..END_CHARPOS],
27256 but none of the characters it displays are in the range, it is
27258 struct glyph
*g
= next
->glyphs
[TEXT_AREA
];
27259 struct glyph
*s
= g
;
27260 struct glyph
*e
= g
+ next
->used
[TEXT_AREA
];
27264 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
27265 && ((start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
27266 /* If the buffer position of the first glyph in
27267 the row is equal to END_CHARPOS, it means
27268 the last character to be highlighted is the
27269 newline of ROW, and we must consider NEXT as
27271 || (((!next
->reversed_p
&& g
== s
)
27272 || (next
->reversed_p
&& g
== e
- 1))
27273 && (g
->charpos
== end_charpos
27274 /* Special case for when NEXT is an
27275 empty line at ZV. */
27276 || (g
->charpos
== -1
27277 && !row
->ends_at_zv_p
27278 && next_start
== end_charpos
)))))
27279 /* A glyph that comes from DISP_STRING is by
27280 definition to be highlighted. */
27281 || EQ (g
->object
, disp_string
))
27290 /* The first row that ends at ZV must be the last to be
27292 else if (next
->ends_at_zv_p
)
27301 /* This function sets the mouse_face_* elements of HLINFO, assuming
27302 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
27303 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
27304 for the overlay or run of text properties specifying the mouse
27305 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
27306 before-string and after-string that must also be highlighted.
27307 DISP_STRING, if non-nil, is a display string that may cover some
27308 or all of the highlighted text. */
27311 mouse_face_from_buffer_pos (Lisp_Object window
,
27312 Mouse_HLInfo
*hlinfo
,
27313 ptrdiff_t mouse_charpos
,
27314 ptrdiff_t start_charpos
,
27315 ptrdiff_t end_charpos
,
27316 Lisp_Object before_string
,
27317 Lisp_Object after_string
,
27318 Lisp_Object disp_string
)
27320 struct window
*w
= XWINDOW (window
);
27321 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27322 struct glyph_row
*r1
, *r2
;
27323 struct glyph
*glyph
, *end
;
27324 ptrdiff_t ignore
, pos
;
27327 eassert (NILP (disp_string
) || STRINGP (disp_string
));
27328 eassert (NILP (before_string
) || STRINGP (before_string
));
27329 eassert (NILP (after_string
) || STRINGP (after_string
));
27331 /* Find the rows corresponding to START_CHARPOS and END_CHARPOS. */
27332 rows_from_pos_range (w
, start_charpos
, end_charpos
, disp_string
, &r1
, &r2
);
27334 r1
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
27335 /* If the before-string or display-string contains newlines,
27336 rows_from_pos_range skips to its last row. Move back. */
27337 if (!NILP (before_string
) || !NILP (disp_string
))
27339 struct glyph_row
*prev
;
27340 while ((prev
= r1
- 1, prev
>= first
)
27341 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
27342 && prev
->used
[TEXT_AREA
] > 0)
27344 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
27345 glyph
= beg
+ prev
->used
[TEXT_AREA
];
27346 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
27348 || !(EQ (glyph
->object
, before_string
)
27349 || EQ (glyph
->object
, disp_string
)))
27356 r2
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
27357 hlinfo
->mouse_face_past_end
= 1;
27359 else if (!NILP (after_string
))
27361 /* If the after-string has newlines, advance to its last row. */
27362 struct glyph_row
*next
;
27363 struct glyph_row
*last
27364 = MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
27366 for (next
= r2
+ 1;
27368 && next
->used
[TEXT_AREA
] > 0
27369 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
27373 /* The rest of the display engine assumes that mouse_face_beg_row is
27374 either above mouse_face_end_row or identical to it. But with
27375 bidi-reordered continued lines, the row for START_CHARPOS could
27376 be below the row for END_CHARPOS. If so, swap the rows and store
27377 them in correct order. */
27380 struct glyph_row
*tem
= r2
;
27386 hlinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (r1
, w
->current_matrix
);
27387 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r2
, w
->current_matrix
);
27389 /* For a bidi-reordered row, the positions of BEFORE_STRING,
27390 AFTER_STRING, DISP_STRING, START_CHARPOS, and END_CHARPOS
27391 could be anywhere in the row and in any order. The strategy
27392 below is to find the leftmost and the rightmost glyph that
27393 belongs to either of these 3 strings, or whose position is
27394 between START_CHARPOS and END_CHARPOS, and highlight all the
27395 glyphs between those two. This may cover more than just the text
27396 between START_CHARPOS and END_CHARPOS if the range of characters
27397 strides the bidi level boundary, e.g. if the beginning is in R2L
27398 text while the end is in L2R text or vice versa. */
27399 if (!r1
->reversed_p
)
27401 /* This row is in a left to right paragraph. Scan it left to
27403 glyph
= r1
->glyphs
[TEXT_AREA
];
27404 end
= glyph
+ r1
->used
[TEXT_AREA
];
27407 /* Skip truncation glyphs at the start of the glyph row. */
27408 if (MATRIX_ROW_DISPLAYS_TEXT_P (r1
))
27410 && INTEGERP (glyph
->object
)
27411 && glyph
->charpos
< 0;
27413 x
+= glyph
->pixel_width
;
27415 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
27416 or DISP_STRING, and the first glyph from buffer whose
27417 position is between START_CHARPOS and END_CHARPOS. */
27419 && !INTEGERP (glyph
->object
)
27420 && !EQ (glyph
->object
, disp_string
)
27421 && !(BUFFERP (glyph
->object
)
27422 && (glyph
->charpos
>= start_charpos
27423 && glyph
->charpos
< end_charpos
));
27426 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27427 are present at buffer positions between START_CHARPOS and
27428 END_CHARPOS, or if they come from an overlay. */
27429 if (EQ (glyph
->object
, before_string
))
27431 pos
= string_buffer_position (before_string
,
27433 /* If pos == 0, it means before_string came from an
27434 overlay, not from a buffer position. */
27435 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27438 else if (EQ (glyph
->object
, after_string
))
27440 pos
= string_buffer_position (after_string
, end_charpos
);
27441 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27444 x
+= glyph
->pixel_width
;
27446 hlinfo
->mouse_face_beg_x
= x
;
27447 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
27451 /* This row is in a right to left paragraph. Scan it right to
27455 end
= r1
->glyphs
[TEXT_AREA
] - 1;
27456 glyph
= end
+ r1
->used
[TEXT_AREA
];
27458 /* Skip truncation glyphs at the start of the glyph row. */
27459 if (MATRIX_ROW_DISPLAYS_TEXT_P (r1
))
27461 && INTEGERP (glyph
->object
)
27462 && glyph
->charpos
< 0;
27466 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
27467 or DISP_STRING, and the first glyph from buffer whose
27468 position is between START_CHARPOS and END_CHARPOS. */
27470 && !INTEGERP (glyph
->object
)
27471 && !EQ (glyph
->object
, disp_string
)
27472 && !(BUFFERP (glyph
->object
)
27473 && (glyph
->charpos
>= start_charpos
27474 && glyph
->charpos
< end_charpos
));
27477 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27478 are present at buffer positions between START_CHARPOS and
27479 END_CHARPOS, or if they come from an overlay. */
27480 if (EQ (glyph
->object
, before_string
))
27482 pos
= string_buffer_position (before_string
, start_charpos
);
27483 /* If pos == 0, it means before_string came from an
27484 overlay, not from a buffer position. */
27485 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27488 else if (EQ (glyph
->object
, after_string
))
27490 pos
= string_buffer_position (after_string
, end_charpos
);
27491 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27496 glyph
++; /* first glyph to the right of the highlighted area */
27497 for (g
= r1
->glyphs
[TEXT_AREA
], x
= r1
->x
; g
< glyph
; g
++)
27498 x
+= g
->pixel_width
;
27499 hlinfo
->mouse_face_beg_x
= x
;
27500 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
27503 /* If the highlight ends in a different row, compute GLYPH and END
27504 for the end row. Otherwise, reuse the values computed above for
27505 the row where the highlight begins. */
27508 if (!r2
->reversed_p
)
27510 glyph
= r2
->glyphs
[TEXT_AREA
];
27511 end
= glyph
+ r2
->used
[TEXT_AREA
];
27516 end
= r2
->glyphs
[TEXT_AREA
] - 1;
27517 glyph
= end
+ r2
->used
[TEXT_AREA
];
27521 if (!r2
->reversed_p
)
27523 /* Skip truncation and continuation glyphs near the end of the
27524 row, and also blanks and stretch glyphs inserted by
27525 extend_face_to_end_of_line. */
27527 && INTEGERP ((end
- 1)->object
))
27529 /* Scan the rest of the glyph row from the end, looking for the
27530 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
27531 DISP_STRING, or whose position is between START_CHARPOS
27535 && !INTEGERP (end
->object
)
27536 && !EQ (end
->object
, disp_string
)
27537 && !(BUFFERP (end
->object
)
27538 && (end
->charpos
>= start_charpos
27539 && end
->charpos
< end_charpos
));
27542 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27543 are present at buffer positions between START_CHARPOS and
27544 END_CHARPOS, or if they come from an overlay. */
27545 if (EQ (end
->object
, before_string
))
27547 pos
= string_buffer_position (before_string
, start_charpos
);
27548 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27551 else if (EQ (end
->object
, after_string
))
27553 pos
= string_buffer_position (after_string
, end_charpos
);
27554 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27558 /* Find the X coordinate of the last glyph to be highlighted. */
27559 for (; glyph
<= end
; ++glyph
)
27560 x
+= glyph
->pixel_width
;
27562 hlinfo
->mouse_face_end_x
= x
;
27563 hlinfo
->mouse_face_end_col
= glyph
- r2
->glyphs
[TEXT_AREA
];
27567 /* Skip truncation and continuation glyphs near the end of the
27568 row, and also blanks and stretch glyphs inserted by
27569 extend_face_to_end_of_line. */
27573 && INTEGERP (end
->object
))
27575 x
+= end
->pixel_width
;
27578 /* Scan the rest of the glyph row from the end, looking for the
27579 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
27580 DISP_STRING, or whose position is between START_CHARPOS
27584 && !INTEGERP (end
->object
)
27585 && !EQ (end
->object
, disp_string
)
27586 && !(BUFFERP (end
->object
)
27587 && (end
->charpos
>= start_charpos
27588 && end
->charpos
< end_charpos
));
27591 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27592 are present at buffer positions between START_CHARPOS and
27593 END_CHARPOS, or if they come from an overlay. */
27594 if (EQ (end
->object
, before_string
))
27596 pos
= string_buffer_position (before_string
, start_charpos
);
27597 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27600 else if (EQ (end
->object
, after_string
))
27602 pos
= string_buffer_position (after_string
, end_charpos
);
27603 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27606 x
+= end
->pixel_width
;
27608 /* If we exited the above loop because we arrived at the last
27609 glyph of the row, and its buffer position is still not in
27610 range, it means the last character in range is the preceding
27611 newline. Bump the end column and x values to get past the
27614 && BUFFERP (end
->object
)
27615 && (end
->charpos
< start_charpos
27616 || end
->charpos
>= end_charpos
))
27618 x
+= end
->pixel_width
;
27621 hlinfo
->mouse_face_end_x
= x
;
27622 hlinfo
->mouse_face_end_col
= end
- r2
->glyphs
[TEXT_AREA
];
27625 hlinfo
->mouse_face_window
= window
;
27626 hlinfo
->mouse_face_face_id
27627 = face_at_buffer_position (w
, mouse_charpos
, &ignore
,
27629 !hlinfo
->mouse_face_hidden
, -1);
27630 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
27633 /* The following function is not used anymore (replaced with
27634 mouse_face_from_string_pos), but I leave it here for the time
27635 being, in case someone would. */
27637 #if 0 /* not used */
27639 /* Find the position of the glyph for position POS in OBJECT in
27640 window W's current matrix, and return in *X, *Y the pixel
27641 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
27643 RIGHT_P non-zero means return the position of the right edge of the
27644 glyph, RIGHT_P zero means return the left edge position.
27646 If no glyph for POS exists in the matrix, return the position of
27647 the glyph with the next smaller position that is in the matrix, if
27648 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
27649 exists in the matrix, return the position of the glyph with the
27650 next larger position in OBJECT.
27652 Value is non-zero if a glyph was found. */
27655 fast_find_string_pos (struct window
*w
, ptrdiff_t pos
, Lisp_Object object
,
27656 int *hpos
, int *vpos
, int *x
, int *y
, int right_p
)
27658 int yb
= window_text_bottom_y (w
);
27659 struct glyph_row
*r
;
27660 struct glyph
*best_glyph
= NULL
;
27661 struct glyph_row
*best_row
= NULL
;
27664 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27665 r
->enabled_p
&& r
->y
< yb
;
27668 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
27669 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
27672 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
27673 if (EQ (g
->object
, object
))
27675 if (g
->charpos
== pos
)
27682 else if (best_glyph
== NULL
27683 || ((eabs (g
->charpos
- pos
)
27684 < eabs (best_glyph
->charpos
- pos
))
27687 : g
->charpos
> pos
)))
27701 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
27705 *x
+= best_glyph
->pixel_width
;
27710 *vpos
= MATRIX_ROW_VPOS (best_row
, w
->current_matrix
);
27713 return best_glyph
!= NULL
;
27715 #endif /* not used */
27717 /* Find the positions of the first and the last glyphs in window W's
27718 current matrix that occlude positions [STARTPOS..ENDPOS) in OBJECT
27719 (assumed to be a string), and return in HLINFO's mouse_face_*
27720 members the pixel and column/row coordinates of those glyphs. */
27723 mouse_face_from_string_pos (struct window
*w
, Mouse_HLInfo
*hlinfo
,
27724 Lisp_Object object
,
27725 ptrdiff_t startpos
, ptrdiff_t endpos
)
27727 int yb
= window_text_bottom_y (w
);
27728 struct glyph_row
*r
;
27729 struct glyph
*g
, *e
;
27733 /* Find the glyph row with at least one position in the range
27734 [STARTPOS..ENDPOS), and the first glyph in that row whose
27735 position belongs to that range. */
27736 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27737 r
->enabled_p
&& r
->y
< yb
;
27740 if (!r
->reversed_p
)
27742 g
= r
->glyphs
[TEXT_AREA
];
27743 e
= g
+ r
->used
[TEXT_AREA
];
27744 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
27745 if (EQ (g
->object
, object
)
27746 && startpos
<= g
->charpos
&& g
->charpos
< endpos
)
27748 hlinfo
->mouse_face_beg_row
27749 = MATRIX_ROW_VPOS (r
, w
->current_matrix
);
27750 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
27751 hlinfo
->mouse_face_beg_x
= gx
;
27760 e
= r
->glyphs
[TEXT_AREA
];
27761 g
= e
+ r
->used
[TEXT_AREA
];
27762 for ( ; g
> e
; --g
)
27763 if (EQ ((g
-1)->object
, object
)
27764 && startpos
<= (g
-1)->charpos
&& (g
-1)->charpos
< endpos
)
27766 hlinfo
->mouse_face_beg_row
27767 = MATRIX_ROW_VPOS (r
, w
->current_matrix
);
27768 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
27769 for (gx
= r
->x
, g1
= r
->glyphs
[TEXT_AREA
]; g1
< g
; ++g1
)
27770 gx
+= g1
->pixel_width
;
27771 hlinfo
->mouse_face_beg_x
= gx
;
27783 /* Starting with the next row, look for the first row which does NOT
27784 include any glyphs whose positions are in the range. */
27785 for (++r
; r
->enabled_p
&& r
->y
< yb
; ++r
)
27787 g
= r
->glyphs
[TEXT_AREA
];
27788 e
= g
+ r
->used
[TEXT_AREA
];
27790 for ( ; g
< e
; ++g
)
27791 if (EQ (g
->object
, object
)
27792 && startpos
<= g
->charpos
&& g
->charpos
< endpos
)
27801 /* The highlighted region ends on the previous row. */
27804 /* Set the end row. */
27805 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r
, w
->current_matrix
);
27807 /* Compute and set the end column and the end column's horizontal
27808 pixel coordinate. */
27809 if (!r
->reversed_p
)
27811 g
= r
->glyphs
[TEXT_AREA
];
27812 e
= g
+ r
->used
[TEXT_AREA
];
27813 for ( ; e
> g
; --e
)
27814 if (EQ ((e
-1)->object
, object
)
27815 && startpos
<= (e
-1)->charpos
&& (e
-1)->charpos
< endpos
)
27817 hlinfo
->mouse_face_end_col
= e
- g
;
27819 for (gx
= r
->x
; g
< e
; ++g
)
27820 gx
+= g
->pixel_width
;
27821 hlinfo
->mouse_face_end_x
= gx
;
27825 e
= r
->glyphs
[TEXT_AREA
];
27826 g
= e
+ r
->used
[TEXT_AREA
];
27827 for (gx
= r
->x
; e
< g
; ++e
)
27829 if (EQ (e
->object
, object
)
27830 && startpos
<= e
->charpos
&& e
->charpos
< endpos
)
27832 gx
+= e
->pixel_width
;
27834 hlinfo
->mouse_face_end_col
= e
- r
->glyphs
[TEXT_AREA
];
27835 hlinfo
->mouse_face_end_x
= gx
;
27839 #ifdef HAVE_WINDOW_SYSTEM
27841 /* See if position X, Y is within a hot-spot of an image. */
27844 on_hot_spot_p (Lisp_Object hot_spot
, int x
, int y
)
27846 if (!CONSP (hot_spot
))
27849 if (EQ (XCAR (hot_spot
), Qrect
))
27851 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
27852 Lisp_Object rect
= XCDR (hot_spot
);
27856 if (!CONSP (XCAR (rect
)))
27858 if (!CONSP (XCDR (rect
)))
27860 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
27862 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
27864 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
27866 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
27870 else if (EQ (XCAR (hot_spot
), Qcircle
))
27872 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
27873 Lisp_Object circ
= XCDR (hot_spot
);
27874 Lisp_Object lr
, lx0
, ly0
;
27876 && CONSP (XCAR (circ
))
27877 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
27878 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
27879 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
27881 double r
= XFLOATINT (lr
);
27882 double dx
= XINT (lx0
) - x
;
27883 double dy
= XINT (ly0
) - y
;
27884 return (dx
* dx
+ dy
* dy
<= r
* r
);
27887 else if (EQ (XCAR (hot_spot
), Qpoly
))
27889 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
27890 if (VECTORP (XCDR (hot_spot
)))
27892 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
27893 Lisp_Object
*poly
= v
->contents
;
27894 ptrdiff_t n
= v
->header
.size
;
27897 Lisp_Object lx
, ly
;
27900 /* Need an even number of coordinates, and at least 3 edges. */
27901 if (n
< 6 || n
& 1)
27904 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
27905 If count is odd, we are inside polygon. Pixels on edges
27906 may or may not be included depending on actual geometry of the
27908 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
27909 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
27911 x0
= XINT (lx
), y0
= XINT (ly
);
27912 for (i
= 0; i
< n
; i
+= 2)
27914 int x1
= x0
, y1
= y0
;
27915 if ((lx
= poly
[i
], !INTEGERP (lx
))
27916 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
27918 x0
= XINT (lx
), y0
= XINT (ly
);
27920 /* Does this segment cross the X line? */
27928 if (y
> y0
&& y
> y1
)
27930 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
27940 find_hot_spot (Lisp_Object map
, int x
, int y
)
27942 while (CONSP (map
))
27944 if (CONSP (XCAR (map
))
27945 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
27953 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
27955 doc
: /* Lookup in image map MAP coordinates X and Y.
27956 An image map is an alist where each element has the format (AREA ID PLIST).
27957 An AREA is specified as either a rectangle, a circle, or a polygon:
27958 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
27959 pixel coordinates of the upper left and bottom right corners.
27960 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
27961 and the radius of the circle; r may be a float or integer.
27962 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
27963 vector describes one corner in the polygon.
27964 Returns the alist element for the first matching AREA in MAP. */)
27965 (Lisp_Object map
, Lisp_Object x
, Lisp_Object y
)
27973 return find_hot_spot (map
,
27974 clip_to_bounds (INT_MIN
, XINT (x
), INT_MAX
),
27975 clip_to_bounds (INT_MIN
, XINT (y
), INT_MAX
));
27979 /* Display frame CURSOR, optionally using shape defined by POINTER. */
27981 define_frame_cursor1 (struct frame
*f
, Cursor cursor
, Lisp_Object pointer
)
27983 /* Do not change cursor shape while dragging mouse. */
27984 if (!NILP (do_mouse_tracking
))
27987 if (!NILP (pointer
))
27989 if (EQ (pointer
, Qarrow
))
27990 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27991 else if (EQ (pointer
, Qhand
))
27992 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
27993 else if (EQ (pointer
, Qtext
))
27994 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
27995 else if (EQ (pointer
, intern ("hdrag")))
27996 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
27997 else if (EQ (pointer
, intern ("nhdrag")))
27998 cursor
= FRAME_X_OUTPUT (f
)->vertical_drag_cursor
;
27999 #ifdef HAVE_X_WINDOWS
28000 else if (EQ (pointer
, intern ("vdrag")))
28001 cursor
= FRAME_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
28003 else if (EQ (pointer
, intern ("hourglass")))
28004 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
28005 else if (EQ (pointer
, Qmodeline
))
28006 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
28008 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
28011 if (cursor
!= No_Cursor
)
28012 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
28015 #endif /* HAVE_WINDOW_SYSTEM */
28017 /* Take proper action when mouse has moved to the mode or header line
28018 or marginal area AREA of window W, x-position X and y-position Y.
28019 X is relative to the start of the text display area of W, so the
28020 width of bitmap areas and scroll bars must be subtracted to get a
28021 position relative to the start of the mode line. */
28024 note_mode_line_or_margin_highlight (Lisp_Object window
, int x
, int y
,
28025 enum window_part area
)
28027 struct window
*w
= XWINDOW (window
);
28028 struct frame
*f
= XFRAME (w
->frame
);
28029 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28030 #ifdef HAVE_WINDOW_SYSTEM
28031 Display_Info
*dpyinfo
;
28033 Cursor cursor
= No_Cursor
;
28034 Lisp_Object pointer
= Qnil
;
28035 int dx
, dy
, width
, height
;
28037 Lisp_Object string
, object
= Qnil
;
28038 Lisp_Object pos
IF_LINT (= Qnil
), help
;
28040 Lisp_Object mouse_face
;
28041 int original_x_pixel
= x
;
28042 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
28043 struct glyph_row
*row
IF_LINT (= 0);
28045 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
28050 /* Kludge alert: mode_line_string takes X/Y in pixels, but
28051 returns them in row/column units! */
28052 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
28053 &object
, &dx
, &dy
, &width
, &height
);
28055 row
= (area
== ON_MODE_LINE
28056 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
28057 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
28059 /* Find the glyph under the mouse pointer. */
28060 if (row
->mode_line_p
&& row
->enabled_p
)
28062 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
28063 end
= glyph
+ row
->used
[TEXT_AREA
];
28065 for (x0
= original_x_pixel
;
28066 glyph
< end
&& x0
>= glyph
->pixel_width
;
28068 x0
-= glyph
->pixel_width
;
28076 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
28077 /* Kludge alert: marginal_area_string takes X/Y in pixels, but
28078 returns them in row/column units! */
28079 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
28080 &object
, &dx
, &dy
, &width
, &height
);
28085 #ifdef HAVE_WINDOW_SYSTEM
28086 if (IMAGEP (object
))
28088 Lisp_Object image_map
, hotspot
;
28089 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
28091 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
28093 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
28097 /* Could check XCAR (hotspot) to see if we enter/leave this hot-spot.
28098 If so, we could look for mouse-enter, mouse-leave
28099 properties in PLIST (and do something...). */
28100 hotspot
= XCDR (hotspot
);
28101 if (CONSP (hotspot
)
28102 && (plist
= XCAR (hotspot
), CONSP (plist
)))
28104 pointer
= Fplist_get (plist
, Qpointer
);
28105 if (NILP (pointer
))
28107 help
= Fplist_get (plist
, Qhelp_echo
);
28110 help_echo_string
= help
;
28111 XSETWINDOW (help_echo_window
, w
);
28112 help_echo_object
= w
->contents
;
28113 help_echo_pos
= charpos
;
28117 if (NILP (pointer
))
28118 pointer
= Fplist_get (XCDR (object
), QCpointer
);
28120 #endif /* HAVE_WINDOW_SYSTEM */
28122 if (STRINGP (string
))
28123 pos
= make_number (charpos
);
28125 /* Set the help text and mouse pointer. If the mouse is on a part
28126 of the mode line without any text (e.g. past the right edge of
28127 the mode line text), use the default help text and pointer. */
28128 if (STRINGP (string
) || area
== ON_MODE_LINE
)
28130 /* Arrange to display the help by setting the global variables
28131 help_echo_string, help_echo_object, and help_echo_pos. */
28134 if (STRINGP (string
))
28135 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
28139 help_echo_string
= help
;
28140 XSETWINDOW (help_echo_window
, w
);
28141 help_echo_object
= string
;
28142 help_echo_pos
= charpos
;
28144 else if (area
== ON_MODE_LINE
)
28146 Lisp_Object default_help
28147 = buffer_local_value_1 (Qmode_line_default_help_echo
,
28150 if (STRINGP (default_help
))
28152 help_echo_string
= default_help
;
28153 XSETWINDOW (help_echo_window
, w
);
28154 help_echo_object
= Qnil
;
28155 help_echo_pos
= -1;
28160 #ifdef HAVE_WINDOW_SYSTEM
28161 /* Change the mouse pointer according to what is under it. */
28162 if (FRAME_WINDOW_P (f
))
28164 dpyinfo
= FRAME_DISPLAY_INFO (f
);
28165 if (STRINGP (string
))
28167 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
28169 if (NILP (pointer
))
28170 pointer
= Fget_text_property (pos
, Qpointer
, string
);
28172 /* Change the mouse pointer according to what is under X/Y. */
28174 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
28177 map
= Fget_text_property (pos
, Qlocal_map
, string
);
28178 if (!KEYMAPP (map
))
28179 map
= Fget_text_property (pos
, Qkeymap
, string
);
28180 if (!KEYMAPP (map
))
28181 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
28185 /* Default mode-line pointer. */
28186 cursor
= FRAME_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
28191 /* Change the mouse face according to what is under X/Y. */
28192 if (STRINGP (string
))
28194 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
28195 if (!NILP (Vmouse_highlight
) && !NILP (mouse_face
)
28196 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
28201 struct glyph
* tmp_glyph
;
28205 int total_pixel_width
;
28206 ptrdiff_t begpos
, endpos
, ignore
;
28210 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
28211 Qmouse_face
, string
, Qnil
);
28217 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
28219 endpos
= SCHARS (string
);
28223 /* Calculate the glyph position GPOS of GLYPH in the
28224 displayed string, relative to the beginning of the
28225 highlighted part of the string.
28227 Note: GPOS is different from CHARPOS. CHARPOS is the
28228 position of GLYPH in the internal string object. A mode
28229 line string format has structures which are converted to
28230 a flattened string by the Emacs Lisp interpreter. The
28231 internal string is an element of those structures. The
28232 displayed string is the flattened string. */
28233 tmp_glyph
= row_start_glyph
;
28234 while (tmp_glyph
< glyph
28235 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
28236 && begpos
<= tmp_glyph
->charpos
28237 && tmp_glyph
->charpos
< endpos
)))
28239 gpos
= glyph
- tmp_glyph
;
28241 /* Calculate the length GSEQ_LENGTH of the glyph sequence of
28242 the highlighted part of the displayed string to which
28243 GLYPH belongs. Note: GSEQ_LENGTH is different from
28244 SCHARS (STRING), because the latter returns the length of
28245 the internal string. */
28246 for (tmp_glyph
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
28248 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
28249 && begpos
<= tmp_glyph
->charpos
28250 && tmp_glyph
->charpos
< endpos
));
28253 gseq_length
= gpos
+ (tmp_glyph
- glyph
) + 1;
28255 /* Calculate the total pixel width of all the glyphs between
28256 the beginning of the highlighted area and GLYPH. */
28257 total_pixel_width
= 0;
28258 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
28259 total_pixel_width
+= tmp_glyph
->pixel_width
;
28261 /* Pre calculation of re-rendering position. Note: X is in
28262 column units here, after the call to mode_line_string or
28263 marginal_area_string. */
28265 vpos
= (area
== ON_MODE_LINE
28266 ? (w
->current_matrix
)->nrows
- 1
28269 /* If GLYPH's position is included in the region that is
28270 already drawn in mouse face, we have nothing to do. */
28271 if ( EQ (window
, hlinfo
->mouse_face_window
)
28272 && (!row
->reversed_p
28273 ? (hlinfo
->mouse_face_beg_col
<= hpos
28274 && hpos
< hlinfo
->mouse_face_end_col
)
28275 /* In R2L rows we swap BEG and END, see below. */
28276 : (hlinfo
->mouse_face_end_col
<= hpos
28277 && hpos
< hlinfo
->mouse_face_beg_col
))
28278 && hlinfo
->mouse_face_beg_row
== vpos
)
28281 if (clear_mouse_face (hlinfo
))
28282 cursor
= No_Cursor
;
28284 if (!row
->reversed_p
)
28286 hlinfo
->mouse_face_beg_col
= hpos
;
28287 hlinfo
->mouse_face_beg_x
= original_x_pixel
28288 - (total_pixel_width
+ dx
);
28289 hlinfo
->mouse_face_end_col
= hpos
+ gseq_length
;
28290 hlinfo
->mouse_face_end_x
= 0;
28294 /* In R2L rows, show_mouse_face expects BEG and END
28295 coordinates to be swapped. */
28296 hlinfo
->mouse_face_end_col
= hpos
;
28297 hlinfo
->mouse_face_end_x
= original_x_pixel
28298 - (total_pixel_width
+ dx
);
28299 hlinfo
->mouse_face_beg_col
= hpos
+ gseq_length
;
28300 hlinfo
->mouse_face_beg_x
= 0;
28303 hlinfo
->mouse_face_beg_row
= vpos
;
28304 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_beg_row
;
28305 hlinfo
->mouse_face_past_end
= 0;
28306 hlinfo
->mouse_face_window
= window
;
28308 hlinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
28313 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
28315 if (NILP (pointer
))
28318 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
28319 clear_mouse_face (hlinfo
);
28321 #ifdef HAVE_WINDOW_SYSTEM
28322 if (FRAME_WINDOW_P (f
))
28323 define_frame_cursor1 (f
, cursor
, pointer
);
28329 Take proper action when the mouse has moved to position X, Y on
28330 frame F with regards to highlighting portions of display that have
28331 mouse-face properties. Also de-highlight portions of display where
28332 the mouse was before, set the mouse pointer shape as appropriate
28333 for the mouse coordinates, and activate help echo (tooltips).
28334 X and Y can be negative or out of range. */
28337 note_mouse_highlight (struct frame
*f
, int x
, int y
)
28339 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28340 enum window_part part
= ON_NOTHING
;
28341 Lisp_Object window
;
28343 Cursor cursor
= No_Cursor
;
28344 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
28347 /* When a menu is active, don't highlight because this looks odd. */
28348 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (MSDOS)
28349 if (popup_activated ())
28353 if (!f
->glyphs_initialized_p
28354 || f
->pointer_invisible
)
28357 hlinfo
->mouse_face_mouse_x
= x
;
28358 hlinfo
->mouse_face_mouse_y
= y
;
28359 hlinfo
->mouse_face_mouse_frame
= f
;
28361 if (hlinfo
->mouse_face_defer
)
28364 /* Which window is that in? */
28365 window
= window_from_coordinates (f
, x
, y
, &part
, 1);
28367 /* If displaying active text in another window, clear that. */
28368 if (! EQ (window
, hlinfo
->mouse_face_window
)
28369 /* Also clear if we move out of text area in same window. */
28370 || (!NILP (hlinfo
->mouse_face_window
)
28373 && part
!= ON_MODE_LINE
28374 && part
!= ON_HEADER_LINE
))
28375 clear_mouse_face (hlinfo
);
28377 /* Not on a window -> return. */
28378 if (!WINDOWP (window
))
28381 /* Reset help_echo_string. It will get recomputed below. */
28382 help_echo_string
= Qnil
;
28384 /* Convert to window-relative pixel coordinates. */
28385 w
= XWINDOW (window
);
28386 frame_to_window_pixel_xy (w
, &x
, &y
);
28388 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
28389 /* Handle tool-bar window differently since it doesn't display a
28391 if (EQ (window
, f
->tool_bar_window
))
28393 note_tool_bar_highlight (f
, x
, y
);
28398 /* Mouse is on the mode, header line or margin? */
28399 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
28400 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
28402 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
28406 #ifdef HAVE_WINDOW_SYSTEM
28407 if (part
== ON_VERTICAL_BORDER
)
28409 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
28410 help_echo_string
= build_string ("drag-mouse-1: resize");
28412 else if (part
== ON_RIGHT_DIVIDER
)
28414 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
28415 help_echo_string
= build_string ("drag-mouse-1: resize");
28417 else if (part
== ON_BOTTOM_DIVIDER
)
28419 cursor
= FRAME_X_OUTPUT (f
)->vertical_drag_cursor
;
28420 help_echo_string
= build_string ("drag-mouse-1: resize");
28422 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
28423 || part
== ON_SCROLL_BAR
)
28424 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
28426 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
28429 /* Are we in a window whose display is up to date?
28430 And verify the buffer's text has not changed. */
28431 b
= XBUFFER (w
->contents
);
28432 if (part
== ON_TEXT
&& w
->window_end_valid
&& !window_outdated (w
))
28434 int hpos
, vpos
, dx
, dy
, area
= LAST_AREA
;
28436 struct glyph
*glyph
;
28437 Lisp_Object object
;
28438 Lisp_Object mouse_face
= Qnil
, position
;
28439 Lisp_Object
*overlay_vec
= NULL
;
28440 ptrdiff_t i
, noverlays
;
28441 struct buffer
*obuf
;
28442 ptrdiff_t obegv
, ozv
;
28445 /* Find the glyph under X/Y. */
28446 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
28448 #ifdef HAVE_WINDOW_SYSTEM
28449 /* Look for :pointer property on image. */
28450 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
28452 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
28453 if (img
!= NULL
&& IMAGEP (img
->spec
))
28455 Lisp_Object image_map
, hotspot
;
28456 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
28458 && (hotspot
= find_hot_spot (image_map
,
28459 glyph
->slice
.img
.x
+ dx
,
28460 glyph
->slice
.img
.y
+ dy
),
28462 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
28466 /* Could check XCAR (hotspot) to see if we enter/leave
28468 If so, we could look for mouse-enter, mouse-leave
28469 properties in PLIST (and do something...). */
28470 hotspot
= XCDR (hotspot
);
28471 if (CONSP (hotspot
)
28472 && (plist
= XCAR (hotspot
), CONSP (plist
)))
28474 pointer
= Fplist_get (plist
, Qpointer
);
28475 if (NILP (pointer
))
28477 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
28478 if (!NILP (help_echo_string
))
28480 help_echo_window
= window
;
28481 help_echo_object
= glyph
->object
;
28482 help_echo_pos
= glyph
->charpos
;
28486 if (NILP (pointer
))
28487 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
28490 #endif /* HAVE_WINDOW_SYSTEM */
28492 /* Clear mouse face if X/Y not over text. */
28494 || area
!= TEXT_AREA
28495 || !MATRIX_ROW_DISPLAYS_TEXT_P (MATRIX_ROW (w
->current_matrix
, vpos
))
28496 /* Glyph's OBJECT is an integer for glyphs inserted by the
28497 display engine for its internal purposes, like truncation
28498 and continuation glyphs and blanks beyond the end of
28499 line's text on text terminals. If we are over such a
28500 glyph, we are not over any text. */
28501 || INTEGERP (glyph
->object
)
28502 /* R2L rows have a stretch glyph at their front, which
28503 stands for no text, whereas L2R rows have no glyphs at
28504 all beyond the end of text. Treat such stretch glyphs
28505 like we do with NULL glyphs in L2R rows. */
28506 || (MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
28507 && glyph
== MATRIX_ROW_GLYPH_START (w
->current_matrix
, vpos
)
28508 && glyph
->type
== STRETCH_GLYPH
28509 && glyph
->avoid_cursor_p
))
28511 if (clear_mouse_face (hlinfo
))
28512 cursor
= No_Cursor
;
28513 #ifdef HAVE_WINDOW_SYSTEM
28514 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
28516 if (area
!= TEXT_AREA
)
28517 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
28519 pointer
= Vvoid_text_area_pointer
;
28525 pos
= glyph
->charpos
;
28526 object
= glyph
->object
;
28527 if (!STRINGP (object
) && !BUFFERP (object
))
28530 /* If we get an out-of-range value, return now; avoid an error. */
28531 if (BUFFERP (object
) && pos
> BUF_Z (b
))
28534 /* Make the window's buffer temporarily current for
28535 overlays_at and compute_char_face. */
28536 obuf
= current_buffer
;
28537 current_buffer
= b
;
28543 /* Is this char mouse-active or does it have help-echo? */
28544 position
= make_number (pos
);
28546 if (BUFFERP (object
))
28548 /* Put all the overlays we want in a vector in overlay_vec. */
28549 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
28550 /* Sort overlays into increasing priority order. */
28551 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
28556 if (NILP (Vmouse_highlight
))
28558 clear_mouse_face (hlinfo
);
28559 goto check_help_echo
;
28562 same_region
= coords_in_mouse_face_p (w
, hpos
, vpos
);
28565 cursor
= No_Cursor
;
28567 /* Check mouse-face highlighting. */
28569 /* If there exists an overlay with mouse-face overlapping
28570 the one we are currently highlighting, we have to
28571 check if we enter the overlapping overlay, and then
28572 highlight only that. */
28573 || (OVERLAYP (hlinfo
->mouse_face_overlay
)
28574 && mouse_face_overlay_overlaps (hlinfo
->mouse_face_overlay
)))
28576 /* Find the highest priority overlay with a mouse-face. */
28577 Lisp_Object overlay
= Qnil
;
28578 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
28580 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
28581 if (!NILP (mouse_face
))
28582 overlay
= overlay_vec
[i
];
28585 /* If we're highlighting the same overlay as before, there's
28586 no need to do that again. */
28587 if (!NILP (overlay
) && EQ (overlay
, hlinfo
->mouse_face_overlay
))
28588 goto check_help_echo
;
28589 hlinfo
->mouse_face_overlay
= overlay
;
28591 /* Clear the display of the old active region, if any. */
28592 if (clear_mouse_face (hlinfo
))
28593 cursor
= No_Cursor
;
28595 /* If no overlay applies, get a text property. */
28596 if (NILP (overlay
))
28597 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
28599 /* Next, compute the bounds of the mouse highlighting and
28601 if (!NILP (mouse_face
) && STRINGP (object
))
28603 /* The mouse-highlighting comes from a display string
28604 with a mouse-face. */
28608 s
= Fprevious_single_property_change
28609 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
28610 e
= Fnext_single_property_change
28611 (position
, Qmouse_face
, object
, Qnil
);
28613 s
= make_number (0);
28615 e
= make_number (SCHARS (object
));
28616 mouse_face_from_string_pos (w
, hlinfo
, object
,
28617 XINT (s
), XINT (e
));
28618 hlinfo
->mouse_face_past_end
= 0;
28619 hlinfo
->mouse_face_window
= window
;
28620 hlinfo
->mouse_face_face_id
28621 = face_at_string_position (w
, object
, pos
, 0, &ignore
,
28622 glyph
->face_id
, 1);
28623 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
28624 cursor
= No_Cursor
;
28628 /* The mouse-highlighting, if any, comes from an overlay
28629 or text property in the buffer. */
28630 Lisp_Object buffer
IF_LINT (= Qnil
);
28631 Lisp_Object disp_string
IF_LINT (= Qnil
);
28633 if (STRINGP (object
))
28635 /* If we are on a display string with no mouse-face,
28636 check if the text under it has one. */
28637 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
28638 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28639 pos
= string_buffer_position (object
, start
);
28642 mouse_face
= get_char_property_and_overlay
28643 (make_number (pos
), Qmouse_face
, w
->contents
, &overlay
);
28644 buffer
= w
->contents
;
28645 disp_string
= object
;
28651 disp_string
= Qnil
;
28654 if (!NILP (mouse_face
))
28656 Lisp_Object before
, after
;
28657 Lisp_Object before_string
, after_string
;
28658 /* To correctly find the limits of mouse highlight
28659 in a bidi-reordered buffer, we must not use the
28660 optimization of limiting the search in
28661 previous-single-property-change and
28662 next-single-property-change, because
28663 rows_from_pos_range needs the real start and end
28664 positions to DTRT in this case. That's because
28665 the first row visible in a window does not
28666 necessarily display the character whose position
28667 is the smallest. */
28669 = NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
28670 ? Fmarker_position (w
->start
)
28673 = NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
28674 ? make_number (BUF_Z (XBUFFER (buffer
))
28675 - w
->window_end_pos
)
28678 if (NILP (overlay
))
28680 /* Handle the text property case. */
28681 before
= Fprevious_single_property_change
28682 (make_number (pos
+ 1), Qmouse_face
, buffer
, lim1
);
28683 after
= Fnext_single_property_change
28684 (make_number (pos
), Qmouse_face
, buffer
, lim2
);
28685 before_string
= after_string
= Qnil
;
28689 /* Handle the overlay case. */
28690 before
= Foverlay_start (overlay
);
28691 after
= Foverlay_end (overlay
);
28692 before_string
= Foverlay_get (overlay
, Qbefore_string
);
28693 after_string
= Foverlay_get (overlay
, Qafter_string
);
28695 if (!STRINGP (before_string
)) before_string
= Qnil
;
28696 if (!STRINGP (after_string
)) after_string
= Qnil
;
28699 mouse_face_from_buffer_pos (window
, hlinfo
, pos
,
28702 : XFASTINT (before
),
28704 ? BUF_Z (XBUFFER (buffer
))
28705 : XFASTINT (after
),
28706 before_string
, after_string
,
28708 cursor
= No_Cursor
;
28715 /* Look for a `help-echo' property. */
28716 if (NILP (help_echo_string
)) {
28717 Lisp_Object help
, overlay
;
28719 /* Check overlays first. */
28720 help
= overlay
= Qnil
;
28721 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
28723 overlay
= overlay_vec
[i
];
28724 help
= Foverlay_get (overlay
, Qhelp_echo
);
28729 help_echo_string
= help
;
28730 help_echo_window
= window
;
28731 help_echo_object
= overlay
;
28732 help_echo_pos
= pos
;
28736 Lisp_Object obj
= glyph
->object
;
28737 ptrdiff_t charpos
= glyph
->charpos
;
28739 /* Try text properties. */
28742 && charpos
< SCHARS (obj
))
28744 help
= Fget_text_property (make_number (charpos
),
28748 /* If the string itself doesn't specify a help-echo,
28749 see if the buffer text ``under'' it does. */
28750 struct glyph_row
*r
28751 = MATRIX_ROW (w
->current_matrix
, vpos
);
28752 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28753 ptrdiff_t p
= string_buffer_position (obj
, start
);
28756 help
= Fget_char_property (make_number (p
),
28757 Qhelp_echo
, w
->contents
);
28766 else if (BUFFERP (obj
)
28769 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
28774 help_echo_string
= help
;
28775 help_echo_window
= window
;
28776 help_echo_object
= obj
;
28777 help_echo_pos
= charpos
;
28782 #ifdef HAVE_WINDOW_SYSTEM
28783 /* Look for a `pointer' property. */
28784 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
28786 /* Check overlays first. */
28787 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
28788 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
28790 if (NILP (pointer
))
28792 Lisp_Object obj
= glyph
->object
;
28793 ptrdiff_t charpos
= glyph
->charpos
;
28795 /* Try text properties. */
28798 && charpos
< SCHARS (obj
))
28800 pointer
= Fget_text_property (make_number (charpos
),
28802 if (NILP (pointer
))
28804 /* If the string itself doesn't specify a pointer,
28805 see if the buffer text ``under'' it does. */
28806 struct glyph_row
*r
28807 = MATRIX_ROW (w
->current_matrix
, vpos
);
28808 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28809 ptrdiff_t p
= string_buffer_position (obj
, start
);
28811 pointer
= Fget_char_property (make_number (p
),
28812 Qpointer
, w
->contents
);
28815 else if (BUFFERP (obj
)
28818 pointer
= Fget_text_property (make_number (charpos
),
28822 #endif /* HAVE_WINDOW_SYSTEM */
28826 current_buffer
= obuf
;
28831 #ifdef HAVE_WINDOW_SYSTEM
28832 if (FRAME_WINDOW_P (f
))
28833 define_frame_cursor1 (f
, cursor
, pointer
);
28835 /* This is here to prevent a compiler error, about "label at end of
28836 compound statement". */
28843 Clear any mouse-face on window W. This function is part of the
28844 redisplay interface, and is called from try_window_id and similar
28845 functions to ensure the mouse-highlight is off. */
28848 x_clear_window_mouse_face (struct window
*w
)
28850 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
28851 Lisp_Object window
;
28854 XSETWINDOW (window
, w
);
28855 if (EQ (window
, hlinfo
->mouse_face_window
))
28856 clear_mouse_face (hlinfo
);
28862 Just discard the mouse face information for frame F, if any.
28863 This is used when the size of F is changed. */
28866 cancel_mouse_face (struct frame
*f
)
28868 Lisp_Object window
;
28869 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28871 window
= hlinfo
->mouse_face_window
;
28872 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
28873 reset_mouse_highlight (hlinfo
);
28878 /***********************************************************************
28880 ***********************************************************************/
28882 #ifdef HAVE_WINDOW_SYSTEM
28884 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
28885 which intersects rectangle R. R is in window-relative coordinates. */
28888 expose_area (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
,
28889 enum glyph_row_area area
)
28891 struct glyph
*first
= row
->glyphs
[area
];
28892 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
28893 struct glyph
*last
;
28894 int first_x
, start_x
, x
;
28896 if (area
== TEXT_AREA
&& row
->fill_line_p
)
28897 /* If row extends face to end of line write the whole line. */
28898 draw_glyphs (w
, 0, row
, area
,
28899 0, row
->used
[area
],
28900 DRAW_NORMAL_TEXT
, 0);
28903 /* Set START_X to the window-relative start position for drawing glyphs of
28904 AREA. The first glyph of the text area can be partially visible.
28905 The first glyphs of other areas cannot. */
28906 start_x
= window_box_left_offset (w
, area
);
28908 if (area
== TEXT_AREA
)
28911 /* Find the first glyph that must be redrawn. */
28913 && x
+ first
->pixel_width
< r
->x
)
28915 x
+= first
->pixel_width
;
28919 /* Find the last one. */
28923 && x
< r
->x
+ r
->width
)
28925 x
+= last
->pixel_width
;
28931 draw_glyphs (w
, first_x
- start_x
, row
, area
,
28932 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
28933 DRAW_NORMAL_TEXT
, 0);
28938 /* Redraw the parts of the glyph row ROW on window W intersecting
28939 rectangle R. R is in window-relative coordinates. Value is
28940 non-zero if mouse-face was overwritten. */
28943 expose_line (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
)
28945 eassert (row
->enabled_p
);
28947 if (row
->mode_line_p
|| w
->pseudo_window_p
)
28948 draw_glyphs (w
, 0, row
, TEXT_AREA
,
28949 0, row
->used
[TEXT_AREA
],
28950 DRAW_NORMAL_TEXT
, 0);
28953 if (row
->used
[LEFT_MARGIN_AREA
])
28954 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
28955 if (row
->used
[TEXT_AREA
])
28956 expose_area (w
, row
, r
, TEXT_AREA
);
28957 if (row
->used
[RIGHT_MARGIN_AREA
])
28958 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
28959 draw_row_fringe_bitmaps (w
, row
);
28962 return row
->mouse_face_p
;
28966 /* Redraw those parts of glyphs rows during expose event handling that
28967 overlap other rows. Redrawing of an exposed line writes over parts
28968 of lines overlapping that exposed line; this function fixes that.
28970 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
28971 row in W's current matrix that is exposed and overlaps other rows.
28972 LAST_OVERLAPPING_ROW is the last such row. */
28975 expose_overlaps (struct window
*w
,
28976 struct glyph_row
*first_overlapping_row
,
28977 struct glyph_row
*last_overlapping_row
,
28980 struct glyph_row
*row
;
28982 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
28983 if (row
->overlapping_p
)
28985 eassert (row
->enabled_p
&& !row
->mode_line_p
);
28988 if (row
->used
[LEFT_MARGIN_AREA
])
28989 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
28991 if (row
->used
[TEXT_AREA
])
28992 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
28994 if (row
->used
[RIGHT_MARGIN_AREA
])
28995 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
29001 /* Return non-zero if W's cursor intersects rectangle R. */
29004 phys_cursor_in_rect_p (struct window
*w
, XRectangle
*r
)
29006 XRectangle cr
, result
;
29007 struct glyph
*cursor_glyph
;
29008 struct glyph_row
*row
;
29010 if (w
->phys_cursor
.vpos
>= 0
29011 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
29012 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
29014 && row
->cursor_in_fringe_p
)
29016 /* Cursor is in the fringe. */
29017 cr
.x
= window_box_right_offset (w
,
29018 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
29019 ? RIGHT_MARGIN_AREA
29022 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
29023 cr
.height
= row
->height
;
29024 return x_intersect_rectangles (&cr
, r
, &result
);
29027 cursor_glyph
= get_phys_cursor_glyph (w
);
29030 /* r is relative to W's box, but w->phys_cursor.x is relative
29031 to left edge of W's TEXT area. Adjust it. */
29032 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
29033 cr
.y
= w
->phys_cursor
.y
;
29034 cr
.width
= cursor_glyph
->pixel_width
;
29035 cr
.height
= w
->phys_cursor_height
;
29036 /* ++KFS: W32 version used W32-specific IntersectRect here, but
29037 I assume the effect is the same -- and this is portable. */
29038 return x_intersect_rectangles (&cr
, r
, &result
);
29040 /* If we don't understand the format, pretend we're not in the hot-spot. */
29046 Draw a vertical window border to the right of window W if W doesn't
29047 have vertical scroll bars. */
29050 x_draw_vertical_border (struct window
*w
)
29052 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
29054 /* We could do better, if we knew what type of scroll-bar the adjacent
29055 windows (on either side) have... But we don't :-(
29056 However, I think this works ok. ++KFS 2003-04-25 */
29058 /* Redraw borders between horizontally adjacent windows. Don't
29059 do it for frames with vertical scroll bars because either the
29060 right scroll bar of a window, or the left scroll bar of its
29061 neighbor will suffice as a border. */
29062 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
) || FRAME_RIGHT_DIVIDER_WIDTH (f
))
29065 /* Note: It is necessary to redraw both the left and the right
29066 borders, for when only this single window W is being
29068 if (!WINDOW_RIGHTMOST_P (w
)
29069 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
29071 int x0
, x1
, y0
, y1
;
29073 window_box_edges (w
, &x0
, &y0
, &x1
, &y1
);
29076 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
29079 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
29082 if (!WINDOW_LEFTMOST_P (w
)
29083 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
29085 int x0
, x1
, y0
, y1
;
29087 window_box_edges (w
, &x0
, &y0
, &x1
, &y1
);
29090 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
29093 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
29098 /* Draw window dividers for window W. */
29101 x_draw_right_divider (struct window
*w
)
29103 struct frame
*f
= WINDOW_XFRAME (w
);
29105 if (w
->mini
|| w
->pseudo_window_p
)
29107 else if (WINDOW_RIGHT_DIVIDER_WIDTH (w
))
29109 int x0
= WINDOW_RIGHT_EDGE_X (w
) - WINDOW_RIGHT_DIVIDER_WIDTH (w
);
29110 int x1
= WINDOW_RIGHT_EDGE_X (w
);
29111 int y0
= WINDOW_TOP_EDGE_Y (w
);
29112 int y1
= WINDOW_BOTTOM_EDGE_Y (w
);
29114 FRAME_RIF (f
)->draw_window_divider (w
, x0
, x1
, y0
, y1
);
29119 x_draw_bottom_divider (struct window
*w
)
29121 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
29123 if (w
->mini
|| w
->pseudo_window_p
)
29125 else if (WINDOW_BOTTOM_DIVIDER_WIDTH (w
))
29127 int x0
= WINDOW_LEFT_EDGE_X (w
);
29128 int x1
= WINDOW_RIGHT_EDGE_X (w
);
29129 int y0
= WINDOW_BOTTOM_EDGE_Y (w
) - WINDOW_BOTTOM_DIVIDER_WIDTH (w
);
29130 int y1
= WINDOW_BOTTOM_EDGE_Y (w
);
29132 FRAME_RIF (f
)->draw_window_divider (w
, x0
, x1
, y0
, y1
);
29136 /* Redraw the part of window W intersection rectangle FR. Pixel
29137 coordinates in FR are frame-relative. Call this function with
29138 input blocked. Value is non-zero if the exposure overwrites
29142 expose_window (struct window
*w
, XRectangle
*fr
)
29144 struct frame
*f
= XFRAME (w
->frame
);
29146 int mouse_face_overwritten_p
= 0;
29148 /* If window is not yet fully initialized, do nothing. This can
29149 happen when toolkit scroll bars are used and a window is split.
29150 Reconfiguring the scroll bar will generate an expose for a newly
29152 if (w
->current_matrix
== NULL
)
29155 /* When we're currently updating the window, display and current
29156 matrix usually don't agree. Arrange for a thorough display
29158 if (w
->must_be_updated_p
)
29160 SET_FRAME_GARBAGED (f
);
29164 /* Frame-relative pixel rectangle of W. */
29165 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
29166 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
29167 wr
.width
= WINDOW_PIXEL_WIDTH (w
);
29168 wr
.height
= WINDOW_PIXEL_HEIGHT (w
);
29170 if (x_intersect_rectangles (fr
, &wr
, &r
))
29172 int yb
= window_text_bottom_y (w
);
29173 struct glyph_row
*row
;
29174 int cursor_cleared_p
, phys_cursor_on_p
;
29175 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
29177 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
29178 r
.x
, r
.y
, r
.width
, r
.height
));
29180 /* Convert to window coordinates. */
29181 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
29182 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
29184 /* Turn off the cursor. */
29185 if (!w
->pseudo_window_p
29186 && phys_cursor_in_rect_p (w
, &r
))
29188 x_clear_cursor (w
);
29189 cursor_cleared_p
= 1;
29192 cursor_cleared_p
= 0;
29194 /* If the row containing the cursor extends face to end of line,
29195 then expose_area might overwrite the cursor outside the
29196 rectangle and thus notice_overwritten_cursor might clear
29197 w->phys_cursor_on_p. We remember the original value and
29198 check later if it is changed. */
29199 phys_cursor_on_p
= w
->phys_cursor_on_p
;
29201 /* Update lines intersecting rectangle R. */
29202 first_overlapping_row
= last_overlapping_row
= NULL
;
29203 for (row
= w
->current_matrix
->rows
;
29208 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
29210 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
29211 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
29212 || (r
.y
>= y0
&& r
.y
< y1
)
29213 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
29215 /* A header line may be overlapping, but there is no need
29216 to fix overlapping areas for them. KFS 2005-02-12 */
29217 if (row
->overlapping_p
&& !row
->mode_line_p
)
29219 if (first_overlapping_row
== NULL
)
29220 first_overlapping_row
= row
;
29221 last_overlapping_row
= row
;
29225 if (expose_line (w
, row
, &r
))
29226 mouse_face_overwritten_p
= 1;
29229 else if (row
->overlapping_p
)
29231 /* We must redraw a row overlapping the exposed area. */
29233 ? y0
+ row
->phys_height
> r
.y
29234 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
29236 if (first_overlapping_row
== NULL
)
29237 first_overlapping_row
= row
;
29238 last_overlapping_row
= row
;
29246 /* Display the mode line if there is one. */
29247 if (WINDOW_WANTS_MODELINE_P (w
)
29248 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
29250 && row
->y
< r
.y
+ r
.height
)
29252 if (expose_line (w
, row
, &r
))
29253 mouse_face_overwritten_p
= 1;
29256 if (!w
->pseudo_window_p
)
29258 /* Fix the display of overlapping rows. */
29259 if (first_overlapping_row
)
29260 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
29263 /* Draw border between windows. */
29264 if (WINDOW_RIGHT_DIVIDER_WIDTH (w
))
29265 x_draw_right_divider (w
);
29267 x_draw_vertical_border (w
);
29269 if (WINDOW_BOTTOM_DIVIDER_WIDTH (w
))
29270 x_draw_bottom_divider (w
);
29272 /* Turn the cursor on again. */
29273 if (cursor_cleared_p
29274 || (phys_cursor_on_p
&& !w
->phys_cursor_on_p
))
29275 update_window_cursor (w
, 1);
29279 return mouse_face_overwritten_p
;
29284 /* Redraw (parts) of all windows in the window tree rooted at W that
29285 intersect R. R contains frame pixel coordinates. Value is
29286 non-zero if the exposure overwrites mouse-face. */
29289 expose_window_tree (struct window
*w
, XRectangle
*r
)
29291 struct frame
*f
= XFRAME (w
->frame
);
29292 int mouse_face_overwritten_p
= 0;
29294 while (w
&& !FRAME_GARBAGED_P (f
))
29296 if (WINDOWP (w
->contents
))
29297 mouse_face_overwritten_p
29298 |= expose_window_tree (XWINDOW (w
->contents
), r
);
29300 mouse_face_overwritten_p
|= expose_window (w
, r
);
29302 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
29305 return mouse_face_overwritten_p
;
29310 Redisplay an exposed area of frame F. X and Y are the upper-left
29311 corner of the exposed rectangle. W and H are width and height of
29312 the exposed area. All are pixel values. W or H zero means redraw
29313 the entire frame. */
29316 expose_frame (struct frame
*f
, int x
, int y
, int w
, int h
)
29319 int mouse_face_overwritten_p
= 0;
29321 TRACE ((stderr
, "expose_frame "));
29323 /* No need to redraw if frame will be redrawn soon. */
29324 if (FRAME_GARBAGED_P (f
))
29326 TRACE ((stderr
, " garbaged\n"));
29330 /* If basic faces haven't been realized yet, there is no point in
29331 trying to redraw anything. This can happen when we get an expose
29332 event while Emacs is starting, e.g. by moving another window. */
29333 if (FRAME_FACE_CACHE (f
) == NULL
29334 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
29336 TRACE ((stderr
, " no faces\n"));
29340 if (w
== 0 || h
== 0)
29343 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
29344 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
29354 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
29355 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
29357 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
29358 if (WINDOWP (f
->tool_bar_window
))
29359 mouse_face_overwritten_p
29360 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
29363 #ifdef HAVE_X_WINDOWS
29365 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
29366 if (WINDOWP (f
->menu_bar_window
))
29367 mouse_face_overwritten_p
29368 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
29369 #endif /* not USE_X_TOOLKIT and not USE_GTK */
29373 /* Some window managers support a focus-follows-mouse style with
29374 delayed raising of frames. Imagine a partially obscured frame,
29375 and moving the mouse into partially obscured mouse-face on that
29376 frame. The visible part of the mouse-face will be highlighted,
29377 then the WM raises the obscured frame. With at least one WM, KDE
29378 2.1, Emacs is not getting any event for the raising of the frame
29379 (even tried with SubstructureRedirectMask), only Expose events.
29380 These expose events will draw text normally, i.e. not
29381 highlighted. Which means we must redo the highlight here.
29382 Subsume it under ``we love X''. --gerd 2001-08-15 */
29383 /* Included in Windows version because Windows most likely does not
29384 do the right thing if any third party tool offers
29385 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
29386 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
29388 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
29389 if (f
== hlinfo
->mouse_face_mouse_frame
)
29391 int mouse_x
= hlinfo
->mouse_face_mouse_x
;
29392 int mouse_y
= hlinfo
->mouse_face_mouse_y
;
29393 clear_mouse_face (hlinfo
);
29394 note_mouse_highlight (f
, mouse_x
, mouse_y
);
29401 Determine the intersection of two rectangles R1 and R2. Return
29402 the intersection in *RESULT. Value is non-zero if RESULT is not
29406 x_intersect_rectangles (XRectangle
*r1
, XRectangle
*r2
, XRectangle
*result
)
29408 XRectangle
*left
, *right
;
29409 XRectangle
*upper
, *lower
;
29410 int intersection_p
= 0;
29412 /* Rearrange so that R1 is the left-most rectangle. */
29414 left
= r1
, right
= r2
;
29416 left
= r2
, right
= r1
;
29418 /* X0 of the intersection is right.x0, if this is inside R1,
29419 otherwise there is no intersection. */
29420 if (right
->x
<= left
->x
+ left
->width
)
29422 result
->x
= right
->x
;
29424 /* The right end of the intersection is the minimum of
29425 the right ends of left and right. */
29426 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
29429 /* Same game for Y. */
29431 upper
= r1
, lower
= r2
;
29433 upper
= r2
, lower
= r1
;
29435 /* The upper end of the intersection is lower.y0, if this is inside
29436 of upper. Otherwise, there is no intersection. */
29437 if (lower
->y
<= upper
->y
+ upper
->height
)
29439 result
->y
= lower
->y
;
29441 /* The lower end of the intersection is the minimum of the lower
29442 ends of upper and lower. */
29443 result
->height
= (min (lower
->y
+ lower
->height
,
29444 upper
->y
+ upper
->height
)
29446 intersection_p
= 1;
29450 return intersection_p
;
29453 #endif /* HAVE_WINDOW_SYSTEM */
29456 /***********************************************************************
29458 ***********************************************************************/
29461 syms_of_xdisp (void)
29463 Vwith_echo_area_save_vector
= Qnil
;
29464 staticpro (&Vwith_echo_area_save_vector
);
29466 Vmessage_stack
= Qnil
;
29467 staticpro (&Vmessage_stack
);
29469 DEFSYM (Qinhibit_redisplay
, "inhibit-redisplay");
29470 DEFSYM (Qredisplay_internal
, "redisplay_internal (C function)");
29472 message_dolog_marker1
= Fmake_marker ();
29473 staticpro (&message_dolog_marker1
);
29474 message_dolog_marker2
= Fmake_marker ();
29475 staticpro (&message_dolog_marker2
);
29476 message_dolog_marker3
= Fmake_marker ();
29477 staticpro (&message_dolog_marker3
);
29480 defsubr (&Sdump_frame_glyph_matrix
);
29481 defsubr (&Sdump_glyph_matrix
);
29482 defsubr (&Sdump_glyph_row
);
29483 defsubr (&Sdump_tool_bar_row
);
29484 defsubr (&Strace_redisplay
);
29485 defsubr (&Strace_to_stderr
);
29487 #ifdef HAVE_WINDOW_SYSTEM
29488 defsubr (&Stool_bar_height
);
29489 defsubr (&Slookup_image_map
);
29491 defsubr (&Sline_pixel_height
);
29492 defsubr (&Sformat_mode_line
);
29493 defsubr (&Sinvisible_p
);
29494 defsubr (&Scurrent_bidi_paragraph_direction
);
29495 defsubr (&Swindow_text_pixel_size
);
29496 defsubr (&Smove_point_visually
);
29498 DEFSYM (Qmenu_bar_update_hook
, "menu-bar-update-hook");
29499 DEFSYM (Qoverriding_terminal_local_map
, "overriding-terminal-local-map");
29500 DEFSYM (Qoverriding_local_map
, "overriding-local-map");
29501 DEFSYM (Qwindow_scroll_functions
, "window-scroll-functions");
29502 DEFSYM (Qwindow_text_change_functions
, "window-text-change-functions");
29503 DEFSYM (Qredisplay_end_trigger_functions
, "redisplay-end-trigger-functions");
29504 DEFSYM (Qinhibit_point_motion_hooks
, "inhibit-point-motion-hooks");
29505 DEFSYM (Qeval
, "eval");
29506 DEFSYM (QCdata
, ":data");
29507 DEFSYM (Qdisplay
, "display");
29508 DEFSYM (Qspace_width
, "space-width");
29509 DEFSYM (Qraise
, "raise");
29510 DEFSYM (Qslice
, "slice");
29511 DEFSYM (Qspace
, "space");
29512 DEFSYM (Qmargin
, "margin");
29513 DEFSYM (Qpointer
, "pointer");
29514 DEFSYM (Qleft_margin
, "left-margin");
29515 DEFSYM (Qright_margin
, "right-margin");
29516 DEFSYM (Qcenter
, "center");
29517 DEFSYM (Qline_height
, "line-height");
29518 DEFSYM (QCalign_to
, ":align-to");
29519 DEFSYM (QCrelative_width
, ":relative-width");
29520 DEFSYM (QCrelative_height
, ":relative-height");
29521 DEFSYM (QCeval
, ":eval");
29522 DEFSYM (QCpropertize
, ":propertize");
29523 DEFSYM (QCfile
, ":file");
29524 DEFSYM (Qfontified
, "fontified");
29525 DEFSYM (Qfontification_functions
, "fontification-functions");
29526 DEFSYM (Qtrailing_whitespace
, "trailing-whitespace");
29527 DEFSYM (Qescape_glyph
, "escape-glyph");
29528 DEFSYM (Qnobreak_space
, "nobreak-space");
29529 DEFSYM (Qimage
, "image");
29530 DEFSYM (Qtext
, "text");
29531 DEFSYM (Qboth
, "both");
29532 DEFSYM (Qboth_horiz
, "both-horiz");
29533 DEFSYM (Qtext_image_horiz
, "text-image-horiz");
29534 DEFSYM (QCmap
, ":map");
29535 DEFSYM (QCpointer
, ":pointer");
29536 DEFSYM (Qrect
, "rect");
29537 DEFSYM (Qcircle
, "circle");
29538 DEFSYM (Qpoly
, "poly");
29539 DEFSYM (Qmessage_truncate_lines
, "message-truncate-lines");
29540 DEFSYM (Qgrow_only
, "grow-only");
29541 DEFSYM (Qinhibit_menubar_update
, "inhibit-menubar-update");
29542 DEFSYM (Qinhibit_eval_during_redisplay
, "inhibit-eval-during-redisplay");
29543 DEFSYM (Qposition
, "position");
29544 DEFSYM (Qbuffer_position
, "buffer-position");
29545 DEFSYM (Qobject
, "object");
29546 DEFSYM (Qbar
, "bar");
29547 DEFSYM (Qhbar
, "hbar");
29548 DEFSYM (Qbox
, "box");
29549 DEFSYM (Qhollow
, "hollow");
29550 DEFSYM (Qhand
, "hand");
29551 DEFSYM (Qarrow
, "arrow");
29552 DEFSYM (Qinhibit_free_realized_faces
, "inhibit-free-realized-faces");
29554 list_of_error
= list1 (list2 (intern_c_string ("error"),
29555 intern_c_string ("void-variable")));
29556 staticpro (&list_of_error
);
29558 DEFSYM (Qlast_arrow_position
, "last-arrow-position");
29559 DEFSYM (Qlast_arrow_string
, "last-arrow-string");
29560 DEFSYM (Qoverlay_arrow_string
, "overlay-arrow-string");
29561 DEFSYM (Qoverlay_arrow_bitmap
, "overlay-arrow-bitmap");
29563 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
29564 staticpro (&echo_buffer
[0]);
29565 staticpro (&echo_buffer
[1]);
29567 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
29568 staticpro (&echo_area_buffer
[0]);
29569 staticpro (&echo_area_buffer
[1]);
29571 Vmessages_buffer_name
= build_pure_c_string ("*Messages*");
29572 staticpro (&Vmessages_buffer_name
);
29574 mode_line_proptrans_alist
= Qnil
;
29575 staticpro (&mode_line_proptrans_alist
);
29576 mode_line_string_list
= Qnil
;
29577 staticpro (&mode_line_string_list
);
29578 mode_line_string_face
= Qnil
;
29579 staticpro (&mode_line_string_face
);
29580 mode_line_string_face_prop
= Qnil
;
29581 staticpro (&mode_line_string_face_prop
);
29582 Vmode_line_unwind_vector
= Qnil
;
29583 staticpro (&Vmode_line_unwind_vector
);
29585 DEFSYM (Qmode_line_default_help_echo
, "mode-line-default-help-echo");
29587 help_echo_string
= Qnil
;
29588 staticpro (&help_echo_string
);
29589 help_echo_object
= Qnil
;
29590 staticpro (&help_echo_object
);
29591 help_echo_window
= Qnil
;
29592 staticpro (&help_echo_window
);
29593 previous_help_echo_string
= Qnil
;
29594 staticpro (&previous_help_echo_string
);
29595 help_echo_pos
= -1;
29597 DEFSYM (Qright_to_left
, "right-to-left");
29598 DEFSYM (Qleft_to_right
, "left-to-right");
29600 #ifdef HAVE_WINDOW_SYSTEM
29601 DEFVAR_BOOL ("x-stretch-cursor", x_stretch_cursor_p
,
29602 doc
: /* Non-nil means draw block cursor as wide as the glyph under it.
29603 For example, if a block cursor is over a tab, it will be drawn as
29604 wide as that tab on the display. */);
29605 x_stretch_cursor_p
= 0;
29608 DEFVAR_LISP ("show-trailing-whitespace", Vshow_trailing_whitespace
,
29609 doc
: /* Non-nil means highlight trailing whitespace.
29610 The face used for trailing whitespace is `trailing-whitespace'. */);
29611 Vshow_trailing_whitespace
= Qnil
;
29613 DEFVAR_LISP ("nobreak-char-display", Vnobreak_char_display
,
29614 doc
: /* Control highlighting of non-ASCII space and hyphen chars.
29615 If the value is t, Emacs highlights non-ASCII chars which have the
29616 same appearance as an ASCII space or hyphen, using the `nobreak-space'
29617 or `escape-glyph' face respectively.
29619 U+00A0 (no-break space), U+00AD (soft hyphen), U+2010 (hyphen), and
29620 U+2011 (non-breaking hyphen) are affected.
29622 Any other non-nil value means to display these characters as a escape
29623 glyph followed by an ordinary space or hyphen.
29625 A value of nil means no special handling of these characters. */);
29626 Vnobreak_char_display
= Qt
;
29628 DEFVAR_LISP ("void-text-area-pointer", Vvoid_text_area_pointer
,
29629 doc
: /* The pointer shape to show in void text areas.
29630 A value of nil means to show the text pointer. Other options are `arrow',
29631 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
29632 Vvoid_text_area_pointer
= Qarrow
;
29634 DEFVAR_LISP ("inhibit-redisplay", Vinhibit_redisplay
,
29635 doc
: /* Non-nil means don't actually do any redisplay.
29636 This is used for internal purposes. */);
29637 Vinhibit_redisplay
= Qnil
;
29639 DEFVAR_LISP ("global-mode-string", Vglobal_mode_string
,
29640 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
29641 Vglobal_mode_string
= Qnil
;
29643 DEFVAR_LISP ("overlay-arrow-position", Voverlay_arrow_position
,
29644 doc
: /* Marker for where to display an arrow on top of the buffer text.
29645 This must be the beginning of a line in order to work.
29646 See also `overlay-arrow-string'. */);
29647 Voverlay_arrow_position
= Qnil
;
29649 DEFVAR_LISP ("overlay-arrow-string", Voverlay_arrow_string
,
29650 doc
: /* String to display as an arrow in non-window frames.
29651 See also `overlay-arrow-position'. */);
29652 Voverlay_arrow_string
= build_pure_c_string ("=>");
29654 DEFVAR_LISP ("overlay-arrow-variable-list", Voverlay_arrow_variable_list
,
29655 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
29656 The symbols on this list are examined during redisplay to determine
29657 where to display overlay arrows. */);
29658 Voverlay_arrow_variable_list
29659 = list1 (intern_c_string ("overlay-arrow-position"));
29661 DEFVAR_INT ("scroll-step", emacs_scroll_step
,
29662 doc
: /* The number of lines to try scrolling a window by when point moves out.
29663 If that fails to bring point back on frame, point is centered instead.
29664 If this is zero, point is always centered after it moves off frame.
29665 If you want scrolling to always be a line at a time, you should set
29666 `scroll-conservatively' to a large value rather than set this to 1. */);
29668 DEFVAR_INT ("scroll-conservatively", scroll_conservatively
,
29669 doc
: /* Scroll up to this many lines, to bring point back on screen.
29670 If point moves off-screen, redisplay will scroll by up to
29671 `scroll-conservatively' lines in order to bring point just barely
29672 onto the screen again. If that cannot be done, then redisplay
29673 recenters point as usual.
29675 If the value is greater than 100, redisplay will never recenter point,
29676 but will always scroll just enough text to bring point into view, even
29677 if you move far away.
29679 A value of zero means always recenter point if it moves off screen. */);
29680 scroll_conservatively
= 0;
29682 DEFVAR_INT ("scroll-margin", scroll_margin
,
29683 doc
: /* Number of lines of margin at the top and bottom of a window.
29684 Recenter the window whenever point gets within this many lines
29685 of the top or bottom of the window. */);
29688 DEFVAR_LISP ("display-pixels-per-inch", Vdisplay_pixels_per_inch
,
29689 doc
: /* Pixels per inch value for non-window system displays.
29690 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
29691 Vdisplay_pixels_per_inch
= make_float (72.0);
29694 DEFVAR_INT ("debug-end-pos", debug_end_pos
, doc
: /* Don't ask. */);
29697 DEFVAR_LISP ("truncate-partial-width-windows",
29698 Vtruncate_partial_width_windows
,
29699 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
29700 For an integer value, truncate lines in each window narrower than the
29701 full frame width, provided the window width is less than that integer;
29702 otherwise, respect the value of `truncate-lines'.
29704 For any other non-nil value, truncate lines in all windows that do
29705 not span the full frame width.
29707 A value of nil means to respect the value of `truncate-lines'.
29709 If `word-wrap' is enabled, you might want to reduce this. */);
29710 Vtruncate_partial_width_windows
= make_number (50);
29712 DEFVAR_LISP ("line-number-display-limit", Vline_number_display_limit
,
29713 doc
: /* Maximum buffer size for which line number should be displayed.
29714 If the buffer is bigger than this, the line number does not appear
29715 in the mode line. A value of nil means no limit. */);
29716 Vline_number_display_limit
= Qnil
;
29718 DEFVAR_INT ("line-number-display-limit-width",
29719 line_number_display_limit_width
,
29720 doc
: /* Maximum line width (in characters) for line number display.
29721 If the average length of the lines near point is bigger than this, then the
29722 line number may be omitted from the mode line. */);
29723 line_number_display_limit_width
= 200;
29725 DEFVAR_BOOL ("highlight-nonselected-windows", highlight_nonselected_windows
,
29726 doc
: /* Non-nil means highlight region even in nonselected windows. */);
29727 highlight_nonselected_windows
= 0;
29729 DEFVAR_BOOL ("multiple-frames", multiple_frames
,
29730 doc
: /* Non-nil if more than one frame is visible on this display.
29731 Minibuffer-only frames don't count, but iconified frames do.
29732 This variable is not guaranteed to be accurate except while processing
29733 `frame-title-format' and `icon-title-format'. */);
29735 DEFVAR_LISP ("frame-title-format", Vframe_title_format
,
29736 doc
: /* Template for displaying the title bar of visible frames.
29737 \(Assuming the window manager supports this feature.)
29739 This variable has the same structure as `mode-line-format', except that
29740 the %c and %l constructs are ignored. It is used only on frames for
29741 which no explicit name has been set \(see `modify-frame-parameters'). */);
29743 DEFVAR_LISP ("icon-title-format", Vicon_title_format
,
29744 doc
: /* Template for displaying the title bar of an iconified frame.
29745 \(Assuming the window manager supports this feature.)
29746 This variable has the same structure as `mode-line-format' (which see),
29747 and is used only on frames for which no explicit name has been set
29748 \(see `modify-frame-parameters'). */);
29750 = Vframe_title_format
29751 = listn (CONSTYPE_PURE
, 3,
29752 intern_c_string ("multiple-frames"),
29753 build_pure_c_string ("%b"),
29754 listn (CONSTYPE_PURE
, 4,
29755 empty_unibyte_string
,
29756 intern_c_string ("invocation-name"),
29757 build_pure_c_string ("@"),
29758 intern_c_string ("system-name")));
29760 DEFVAR_LISP ("message-log-max", Vmessage_log_max
,
29761 doc
: /* Maximum number of lines to keep in the message log buffer.
29762 If nil, disable message logging. If t, log messages but don't truncate
29763 the buffer when it becomes large. */);
29764 Vmessage_log_max
= make_number (1000);
29766 DEFVAR_LISP ("window-size-change-functions", Vwindow_size_change_functions
,
29767 doc
: /* Functions called before redisplay, if window sizes have changed.
29768 The value should be a list of functions that take one argument.
29769 Just before redisplay, for each frame, if any of its windows have changed
29770 size since the last redisplay, or have been split or deleted,
29771 all the functions in the list are called, with the frame as argument. */);
29772 Vwindow_size_change_functions
= Qnil
;
29774 DEFVAR_LISP ("window-scroll-functions", Vwindow_scroll_functions
,
29775 doc
: /* List of functions to call before redisplaying a window with scrolling.
29776 Each function is called with two arguments, the window and its new
29777 display-start position. Note that these functions are also called by
29778 `set-window-buffer'. Also note that the value of `window-end' is not
29779 valid when these functions are called.
29781 Warning: Do not use this feature to alter the way the window
29782 is scrolled. It is not designed for that, and such use probably won't
29784 Vwindow_scroll_functions
= Qnil
;
29786 DEFVAR_LISP ("window-text-change-functions",
29787 Vwindow_text_change_functions
,
29788 doc
: /* Functions to call in redisplay when text in the window might change. */);
29789 Vwindow_text_change_functions
= Qnil
;
29791 DEFVAR_LISP ("redisplay-end-trigger-functions", Vredisplay_end_trigger_functions
,
29792 doc
: /* Functions called when redisplay of a window reaches the end trigger.
29793 Each function is called with two arguments, the window and the end trigger value.
29794 See `set-window-redisplay-end-trigger'. */);
29795 Vredisplay_end_trigger_functions
= Qnil
;
29797 DEFVAR_LISP ("mouse-autoselect-window", Vmouse_autoselect_window
,
29798 doc
: /* Non-nil means autoselect window with mouse pointer.
29799 If nil, do not autoselect windows.
29800 A positive number means delay autoselection by that many seconds: a
29801 window is autoselected only after the mouse has remained in that
29802 window for the duration of the delay.
29803 A negative number has a similar effect, but causes windows to be
29804 autoselected only after the mouse has stopped moving. \(Because of
29805 the way Emacs compares mouse events, you will occasionally wait twice
29806 that time before the window gets selected.\)
29807 Any other value means to autoselect window instantaneously when the
29808 mouse pointer enters it.
29810 Autoselection selects the minibuffer only if it is active, and never
29811 unselects the minibuffer if it is active.
29813 When customizing this variable make sure that the actual value of
29814 `focus-follows-mouse' matches the behavior of your window manager. */);
29815 Vmouse_autoselect_window
= Qnil
;
29817 DEFVAR_LISP ("auto-resize-tool-bars", Vauto_resize_tool_bars
,
29818 doc
: /* Non-nil means automatically resize tool-bars.
29819 This dynamically changes the tool-bar's height to the minimum height
29820 that is needed to make all tool-bar items visible.
29821 If value is `grow-only', the tool-bar's height is only increased
29822 automatically; to decrease the tool-bar height, use \\[recenter]. */);
29823 Vauto_resize_tool_bars
= Qt
;
29825 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", auto_raise_tool_bar_buttons_p
,
29826 doc
: /* Non-nil means raise tool-bar buttons when the mouse moves over them. */);
29827 auto_raise_tool_bar_buttons_p
= 1;
29829 DEFVAR_BOOL ("make-cursor-line-fully-visible", make_cursor_line_fully_visible_p
,
29830 doc
: /* Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
29831 make_cursor_line_fully_visible_p
= 1;
29833 DEFVAR_LISP ("tool-bar-border", Vtool_bar_border
,
29834 doc
: /* Border below tool-bar in pixels.
29835 If an integer, use it as the height of the border.
29836 If it is one of `internal-border-width' or `border-width', use the
29837 value of the corresponding frame parameter.
29838 Otherwise, no border is added below the tool-bar. */);
29839 Vtool_bar_border
= Qinternal_border_width
;
29841 DEFVAR_LISP ("tool-bar-button-margin", Vtool_bar_button_margin
,
29842 doc
: /* Margin around tool-bar buttons in pixels.
29843 If an integer, use that for both horizontal and vertical margins.
29844 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
29845 HORZ specifying the horizontal margin, and VERT specifying the
29846 vertical margin. */);
29847 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
29849 DEFVAR_INT ("tool-bar-button-relief", tool_bar_button_relief
,
29850 doc
: /* Relief thickness of tool-bar buttons. */);
29851 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
29853 DEFVAR_LISP ("tool-bar-style", Vtool_bar_style
,
29854 doc
: /* Tool bar style to use.
29856 image - show images only
29857 text - show text only
29858 both - show both, text below image
29859 both-horiz - show text to the right of the image
29860 text-image-horiz - show text to the left of the image
29861 any other - use system default or image if no system default.
29863 This variable only affects the GTK+ toolkit version of Emacs. */);
29864 Vtool_bar_style
= Qnil
;
29866 DEFVAR_INT ("tool-bar-max-label-size", tool_bar_max_label_size
,
29867 doc
: /* Maximum number of characters a label can have to be shown.
29868 The tool bar style must also show labels for this to have any effect, see
29869 `tool-bar-style'. */);
29870 tool_bar_max_label_size
= DEFAULT_TOOL_BAR_LABEL_SIZE
;
29872 DEFVAR_LISP ("fontification-functions", Vfontification_functions
,
29873 doc
: /* List of functions to call to fontify regions of text.
29874 Each function is called with one argument POS. Functions must
29875 fontify a region starting at POS in the current buffer, and give
29876 fontified regions the property `fontified'. */);
29877 Vfontification_functions
= Qnil
;
29878 Fmake_variable_buffer_local (Qfontification_functions
);
29880 DEFVAR_BOOL ("unibyte-display-via-language-environment",
29881 unibyte_display_via_language_environment
,
29882 doc
: /* Non-nil means display unibyte text according to language environment.
29883 Specifically, this means that raw bytes in the range 160-255 decimal
29884 are displayed by converting them to the equivalent multibyte characters
29885 according to the current language environment. As a result, they are
29886 displayed according to the current fontset.
29888 Note that this variable affects only how these bytes are displayed,
29889 but does not change the fact they are interpreted as raw bytes. */);
29890 unibyte_display_via_language_environment
= 0;
29892 DEFVAR_LISP ("max-mini-window-height", Vmax_mini_window_height
,
29893 doc
: /* Maximum height for resizing mini-windows (the minibuffer and the echo area).
29894 If a float, it specifies a fraction of the mini-window frame's height.
29895 If an integer, it specifies a number of lines. */);
29896 Vmax_mini_window_height
= make_float (0.25);
29898 DEFVAR_LISP ("resize-mini-windows", Vresize_mini_windows
,
29899 doc
: /* How to resize mini-windows (the minibuffer and the echo area).
29900 A value of nil means don't automatically resize mini-windows.
29901 A value of t means resize them to fit the text displayed in them.
29902 A value of `grow-only', the default, means let mini-windows grow only;
29903 they return to their normal size when the minibuffer is closed, or the
29904 echo area becomes empty. */);
29905 Vresize_mini_windows
= Qgrow_only
;
29907 DEFVAR_LISP ("blink-cursor-alist", Vblink_cursor_alist
,
29908 doc
: /* Alist specifying how to blink the cursor off.
29909 Each element has the form (ON-STATE . OFF-STATE). Whenever the
29910 `cursor-type' frame-parameter or variable equals ON-STATE,
29911 comparing using `equal', Emacs uses OFF-STATE to specify
29912 how to blink it off. ON-STATE and OFF-STATE are values for
29913 the `cursor-type' frame parameter.
29915 If a frame's ON-STATE has no entry in this list,
29916 the frame's other specifications determine how to blink the cursor off. */);
29917 Vblink_cursor_alist
= Qnil
;
29919 DEFVAR_BOOL ("auto-hscroll-mode", automatic_hscrolling_p
,
29920 doc
: /* Allow or disallow automatic horizontal scrolling of windows.
29921 If non-nil, windows are automatically scrolled horizontally to make
29922 point visible. */);
29923 automatic_hscrolling_p
= 1;
29924 DEFSYM (Qauto_hscroll_mode
, "auto-hscroll-mode");
29926 DEFVAR_INT ("hscroll-margin", hscroll_margin
,
29927 doc
: /* How many columns away from the window edge point is allowed to get
29928 before automatic hscrolling will horizontally scroll the window. */);
29929 hscroll_margin
= 5;
29931 DEFVAR_LISP ("hscroll-step", Vhscroll_step
,
29932 doc
: /* How many columns to scroll the window when point gets too close to the edge.
29933 When point is less than `hscroll-margin' columns from the window
29934 edge, automatic hscrolling will scroll the window by the amount of columns
29935 determined by this variable. If its value is a positive integer, scroll that
29936 many columns. If it's a positive floating-point number, it specifies the
29937 fraction of the window's width to scroll. If it's nil or zero, point will be
29938 centered horizontally after the scroll. Any other value, including negative
29939 numbers, are treated as if the value were zero.
29941 Automatic hscrolling always moves point outside the scroll margin, so if
29942 point was more than scroll step columns inside the margin, the window will
29943 scroll more than the value given by the scroll step.
29945 Note that the lower bound for automatic hscrolling specified by `scroll-left'
29946 and `scroll-right' overrides this variable's effect. */);
29947 Vhscroll_step
= make_number (0);
29949 DEFVAR_BOOL ("message-truncate-lines", message_truncate_lines
,
29950 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
29951 Bind this around calls to `message' to let it take effect. */);
29952 message_truncate_lines
= 0;
29954 DEFVAR_LISP ("menu-bar-update-hook", Vmenu_bar_update_hook
,
29955 doc
: /* Normal hook run to update the menu bar definitions.
29956 Redisplay runs this hook before it redisplays the menu bar.
29957 This is used to update submenus such as Buffers,
29958 whose contents depend on various data. */);
29959 Vmenu_bar_update_hook
= Qnil
;
29961 DEFVAR_LISP ("menu-updating-frame", Vmenu_updating_frame
,
29962 doc
: /* Frame for which we are updating a menu.
29963 The enable predicate for a menu binding should check this variable. */);
29964 Vmenu_updating_frame
= Qnil
;
29966 DEFVAR_BOOL ("inhibit-menubar-update", inhibit_menubar_update
,
29967 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
29968 inhibit_menubar_update
= 0;
29970 DEFVAR_LISP ("wrap-prefix", Vwrap_prefix
,
29971 doc
: /* Prefix prepended to all continuation lines at display time.
29972 The value may be a string, an image, or a stretch-glyph; it is
29973 interpreted in the same way as the value of a `display' text property.
29975 This variable is overridden by any `wrap-prefix' text or overlay
29978 To add a prefix to non-continuation lines, use `line-prefix'. */);
29979 Vwrap_prefix
= Qnil
;
29980 DEFSYM (Qwrap_prefix
, "wrap-prefix");
29981 Fmake_variable_buffer_local (Qwrap_prefix
);
29983 DEFVAR_LISP ("line-prefix", Vline_prefix
,
29984 doc
: /* Prefix prepended to all non-continuation lines at display time.
29985 The value may be a string, an image, or a stretch-glyph; it is
29986 interpreted in the same way as the value of a `display' text property.
29988 This variable is overridden by any `line-prefix' text or overlay
29991 To add a prefix to continuation lines, use `wrap-prefix'. */);
29992 Vline_prefix
= Qnil
;
29993 DEFSYM (Qline_prefix
, "line-prefix");
29994 Fmake_variable_buffer_local (Qline_prefix
);
29996 DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay
,
29997 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
29998 inhibit_eval_during_redisplay
= 0;
30000 DEFVAR_BOOL ("inhibit-free-realized-faces", inhibit_free_realized_faces
,
30001 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
30002 inhibit_free_realized_faces
= 0;
30005 DEFVAR_BOOL ("inhibit-try-window-id", inhibit_try_window_id
,
30006 doc
: /* Inhibit try_window_id display optimization. */);
30007 inhibit_try_window_id
= 0;
30009 DEFVAR_BOOL ("inhibit-try-window-reusing", inhibit_try_window_reusing
,
30010 doc
: /* Inhibit try_window_reusing display optimization. */);
30011 inhibit_try_window_reusing
= 0;
30013 DEFVAR_BOOL ("inhibit-try-cursor-movement", inhibit_try_cursor_movement
,
30014 doc
: /* Inhibit try_cursor_movement display optimization. */);
30015 inhibit_try_cursor_movement
= 0;
30016 #endif /* GLYPH_DEBUG */
30018 DEFVAR_INT ("overline-margin", overline_margin
,
30019 doc
: /* Space between overline and text, in pixels.
30020 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
30021 margin to the character height. */);
30022 overline_margin
= 2;
30024 DEFVAR_INT ("underline-minimum-offset",
30025 underline_minimum_offset
,
30026 doc
: /* Minimum distance between baseline and underline.
30027 This can improve legibility of underlined text at small font sizes,
30028 particularly when using variable `x-use-underline-position-properties'
30029 with fonts that specify an UNDERLINE_POSITION relatively close to the
30030 baseline. The default value is 1. */);
30031 underline_minimum_offset
= 1;
30033 DEFVAR_BOOL ("display-hourglass", display_hourglass_p
,
30034 doc
: /* Non-nil means show an hourglass pointer, when Emacs is busy.
30035 This feature only works when on a window system that can change
30036 cursor shapes. */);
30037 display_hourglass_p
= 1;
30039 DEFVAR_LISP ("hourglass-delay", Vhourglass_delay
,
30040 doc
: /* Seconds to wait before displaying an hourglass pointer when Emacs is busy. */);
30041 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
30043 #ifdef HAVE_WINDOW_SYSTEM
30044 hourglass_atimer
= NULL
;
30045 hourglass_shown_p
= 0;
30046 #endif /* HAVE_WINDOW_SYSTEM */
30048 DEFSYM (Qglyphless_char
, "glyphless-char");
30049 DEFSYM (Qhex_code
, "hex-code");
30050 DEFSYM (Qempty_box
, "empty-box");
30051 DEFSYM (Qthin_space
, "thin-space");
30052 DEFSYM (Qzero_width
, "zero-width");
30054 DEFVAR_LISP ("pre-redisplay-function", Vpre_redisplay_function
,
30055 doc
: /* Function run just before redisplay.
30056 It is called with one argument, which is the set of windows that are to
30057 be redisplayed. This set can be nil (meaning, only the selected window),
30058 or t (meaning all windows). */);
30059 Vpre_redisplay_function
= intern ("ignore");
30061 DEFSYM (Qglyphless_char_display
, "glyphless-char-display");
30062 Fput (Qglyphless_char_display
, Qchar_table_extra_slots
, make_number (1));
30064 DEFVAR_LISP ("glyphless-char-display", Vglyphless_char_display
,
30065 doc
: /* Char-table defining glyphless characters.
30066 Each element, if non-nil, should be one of the following:
30067 an ASCII acronym string: display this string in a box
30068 `hex-code': display the hexadecimal code of a character in a box
30069 `empty-box': display as an empty box
30070 `thin-space': display as 1-pixel width space
30071 `zero-width': don't display
30072 An element may also be a cons cell (GRAPHICAL . TEXT), which specifies the
30073 display method for graphical terminals and text terminals respectively.
30074 GRAPHICAL and TEXT should each have one of the values listed above.
30076 The char-table has one extra slot to control the display of a character for
30077 which no font is found. This slot only takes effect on graphical terminals.
30078 Its value should be an ASCII acronym string, `hex-code', `empty-box', or
30079 `thin-space'. The default is `empty-box'.
30081 If a character has a non-nil entry in an active display table, the
30082 display table takes effect; in this case, Emacs does not consult
30083 `glyphless-char-display' at all. */);
30084 Vglyphless_char_display
= Fmake_char_table (Qglyphless_char_display
, Qnil
);
30085 Fset_char_table_extra_slot (Vglyphless_char_display
, make_number (0),
30088 DEFVAR_LISP ("debug-on-message", Vdebug_on_message
,
30089 doc
: /* If non-nil, debug if a message matching this regexp is displayed. */);
30090 Vdebug_on_message
= Qnil
;
30092 DEFVAR_LISP ("redisplay--all-windows-cause", Vredisplay__all_windows_cause
,
30094 Vredisplay__all_windows_cause
30095 = Fmake_vector (make_number (100), make_number (0));
30097 DEFVAR_LISP ("redisplay--mode-lines-cause", Vredisplay__mode_lines_cause
,
30099 Vredisplay__mode_lines_cause
30100 = Fmake_vector (make_number (100), make_number (0));
30104 /* Initialize this module when Emacs starts. */
30109 CHARPOS (this_line_start_pos
) = 0;
30111 if (!noninteractive
)
30113 struct window
*m
= XWINDOW (minibuf_window
);
30114 Lisp_Object frame
= m
->frame
;
30115 struct frame
*f
= XFRAME (frame
);
30116 Lisp_Object root
= FRAME_ROOT_WINDOW (f
);
30117 struct window
*r
= XWINDOW (root
);
30120 echo_area_window
= minibuf_window
;
30122 r
->top_line
= FRAME_TOP_MARGIN (f
);
30123 r
->pixel_top
= r
->top_line
* FRAME_LINE_HEIGHT (f
);
30124 r
->total_cols
= FRAME_COLS (f
);
30125 r
->pixel_width
= r
->total_cols
* FRAME_COLUMN_WIDTH (f
);
30126 r
->total_lines
= FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
);
30127 r
->pixel_height
= r
->total_lines
* FRAME_LINE_HEIGHT (f
);
30129 m
->top_line
= FRAME_LINES (f
) - 1;
30130 m
->pixel_top
= m
->top_line
* FRAME_LINE_HEIGHT (f
);
30131 m
->total_cols
= FRAME_COLS (f
);
30132 m
->pixel_width
= m
->total_cols
* FRAME_COLUMN_WIDTH (f
);
30133 m
->total_lines
= 1;
30134 m
->pixel_height
= m
->total_lines
* FRAME_LINE_HEIGHT (f
);
30136 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
30137 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
30138 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
30140 /* The default ellipsis glyphs `...'. */
30141 for (i
= 0; i
< 3; ++i
)
30142 default_invis_vector
[i
] = make_number ('.');
30146 /* Allocate the buffer for frame titles.
30147 Also used for `format-mode-line'. */
30149 mode_line_noprop_buf
= xmalloc (size
);
30150 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
30151 mode_line_noprop_ptr
= mode_line_noprop_buf
;
30152 mode_line_target
= MODE_LINE_DISPLAY
;
30155 help_echo_showing_p
= 0;
30158 #ifdef HAVE_WINDOW_SYSTEM
30160 /* Platform-independent portion of hourglass implementation. */
30162 /* Cancel a currently active hourglass timer, and start a new one. */
30164 start_hourglass (void)
30166 struct timespec delay
;
30168 cancel_hourglass ();
30170 if (INTEGERP (Vhourglass_delay
)
30171 && XINT (Vhourglass_delay
) > 0)
30172 delay
= make_timespec (min (XINT (Vhourglass_delay
),
30173 TYPE_MAXIMUM (time_t)),
30175 else if (FLOATP (Vhourglass_delay
)
30176 && XFLOAT_DATA (Vhourglass_delay
) > 0)
30177 delay
= dtotimespec (XFLOAT_DATA (Vhourglass_delay
));
30179 delay
= make_timespec (DEFAULT_HOURGLASS_DELAY
, 0);
30183 extern void w32_note_current_window (void);
30184 w32_note_current_window ();
30186 #endif /* HAVE_NTGUI */
30188 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
30189 show_hourglass
, NULL
);
30193 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
30196 cancel_hourglass (void)
30198 if (hourglass_atimer
)
30200 cancel_atimer (hourglass_atimer
);
30201 hourglass_atimer
= NULL
;
30204 if (hourglass_shown_p
)
30208 #endif /* HAVE_WINDOW_SYSTEM */