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
;
2487 gx
+= WINDOW_LEFT_EDGE_X (w
);
2488 gy
+= WINDOW_TOP_EDGE_Y (w
);
2491 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2493 /* Visible feedback for debugging. */
2496 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2497 f
->output_data
.x
->normal_gc
,
2498 gx
, gy
, width
, height
);
2504 #endif /* HAVE_WINDOW_SYSTEM */
2507 adjust_window_ends (struct window
*w
, struct glyph_row
*row
, bool current
)
2510 w
->window_end_pos
= Z
- MATRIX_ROW_END_CHARPOS (row
);
2511 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
2513 = MATRIX_ROW_VPOS (row
, current
? w
->current_matrix
: w
->desired_matrix
);
2516 /***********************************************************************
2517 Lisp form evaluation
2518 ***********************************************************************/
2520 /* Error handler for safe_eval and safe_call. */
2523 safe_eval_handler (Lisp_Object arg
, ptrdiff_t nargs
, Lisp_Object
*args
)
2525 add_to_log ("Error during redisplay: %S signaled %S",
2526 Flist (nargs
, args
), arg
);
2530 /* Call function FUNC with the rest of NARGS - 1 arguments
2531 following. Return the result, or nil if something went
2532 wrong. Prevent redisplay during the evaluation. */
2535 safe_call (ptrdiff_t nargs
, Lisp_Object func
, ...)
2539 if (inhibit_eval_during_redisplay
)
2545 ptrdiff_t count
= SPECPDL_INDEX ();
2546 struct gcpro gcpro1
;
2547 Lisp_Object
*args
= alloca (nargs
* word_size
);
2550 va_start (ap
, func
);
2551 for (i
= 1; i
< nargs
; i
++)
2552 args
[i
] = va_arg (ap
, Lisp_Object
);
2556 gcpro1
.nvars
= nargs
;
2557 specbind (Qinhibit_redisplay
, Qt
);
2558 /* Use Qt to ensure debugger does not run,
2559 so there is no possibility of wanting to redisplay. */
2560 val
= internal_condition_case_n (Ffuncall
, nargs
, args
, Qt
,
2563 val
= unbind_to (count
, val
);
2570 /* Call function FN with one argument ARG.
2571 Return the result, or nil if something went wrong. */
2574 safe_call1 (Lisp_Object fn
, Lisp_Object arg
)
2576 return safe_call (2, fn
, arg
);
2579 static Lisp_Object Qeval
;
2582 safe_eval (Lisp_Object sexpr
)
2584 return safe_call1 (Qeval
, sexpr
);
2587 /* Call function FN with two arguments ARG1 and ARG2.
2588 Return the result, or nil if something went wrong. */
2591 safe_call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2593 return safe_call (3, fn
, arg1
, arg2
);
2598 /***********************************************************************
2600 ***********************************************************************/
2604 /* Define CHECK_IT to perform sanity checks on iterators.
2605 This is for debugging. It is too slow to do unconditionally. */
2608 check_it (struct it
*it
)
2610 if (it
->method
== GET_FROM_STRING
)
2612 eassert (STRINGP (it
->string
));
2613 eassert (IT_STRING_CHARPOS (*it
) >= 0);
2617 eassert (IT_STRING_CHARPOS (*it
) < 0);
2618 if (it
->method
== GET_FROM_BUFFER
)
2620 /* Check that character and byte positions agree. */
2621 eassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2626 eassert (it
->current
.dpvec_index
>= 0);
2628 eassert (it
->current
.dpvec_index
< 0);
2631 #define CHECK_IT(IT) check_it ((IT))
2635 #define CHECK_IT(IT) (void) 0
2640 #if defined GLYPH_DEBUG && defined ENABLE_CHECKING
2642 /* Check that the window end of window W is what we expect it
2643 to be---the last row in the current matrix displaying text. */
2646 check_window_end (struct window
*w
)
2648 if (!MINI_WINDOW_P (w
) && w
->window_end_valid
)
2650 struct glyph_row
*row
;
2651 eassert ((row
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
),
2653 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2654 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2658 #define CHECK_WINDOW_END(W) check_window_end ((W))
2662 #define CHECK_WINDOW_END(W) (void) 0
2664 #endif /* GLYPH_DEBUG and ENABLE_CHECKING */
2666 /***********************************************************************
2667 Iterator initialization
2668 ***********************************************************************/
2670 /* Initialize IT for displaying current_buffer in window W, starting
2671 at character position CHARPOS. CHARPOS < 0 means that no buffer
2672 position is specified which is useful when the iterator is assigned
2673 a position later. BYTEPOS is the byte position corresponding to
2676 If ROW is not null, calls to produce_glyphs with IT as parameter
2677 will produce glyphs in that row.
2679 BASE_FACE_ID is the id of a base face to use. It must be one of
2680 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2681 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2682 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2684 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2685 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2686 will be initialized to use the corresponding mode line glyph row of
2687 the desired matrix of W. */
2690 init_iterator (struct it
*it
, struct window
*w
,
2691 ptrdiff_t charpos
, ptrdiff_t bytepos
,
2692 struct glyph_row
*row
, enum face_id base_face_id
)
2694 enum face_id remapped_base_face_id
= base_face_id
;
2696 /* Some precondition checks. */
2697 eassert (w
!= NULL
&& it
!= NULL
);
2698 eassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2701 /* If face attributes have been changed since the last redisplay,
2702 free realized faces now because they depend on face definitions
2703 that might have changed. Don't free faces while there might be
2704 desired matrices pending which reference these faces. */
2705 if (face_change_count
&& !inhibit_free_realized_faces
)
2707 face_change_count
= 0;
2708 free_all_realized_faces (Qnil
);
2711 /* Perhaps remap BASE_FACE_ID to a user-specified alternative. */
2712 if (! NILP (Vface_remapping_alist
))
2713 remapped_base_face_id
2714 = lookup_basic_face (XFRAME (w
->frame
), base_face_id
);
2716 /* Use one of the mode line rows of W's desired matrix if
2720 if (base_face_id
== MODE_LINE_FACE_ID
2721 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2722 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2723 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2724 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2728 memset (it
, 0, sizeof *it
);
2729 it
->current
.overlay_string_index
= -1;
2730 it
->current
.dpvec_index
= -1;
2731 it
->base_face_id
= remapped_base_face_id
;
2733 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2734 it
->paragraph_embedding
= L2R
;
2735 it
->bidi_it
.string
.lstring
= Qnil
;
2736 it
->bidi_it
.string
.s
= NULL
;
2737 it
->bidi_it
.string
.bufpos
= 0;
2740 /* The window in which we iterate over current_buffer: */
2741 XSETWINDOW (it
->window
, w
);
2743 it
->f
= XFRAME (w
->frame
);
2747 /* Extra space between lines (on window systems only). */
2748 if (base_face_id
== DEFAULT_FACE_ID
2749 && FRAME_WINDOW_P (it
->f
))
2751 if (NATNUMP (BVAR (current_buffer
, extra_line_spacing
)))
2752 it
->extra_line_spacing
= XFASTINT (BVAR (current_buffer
, extra_line_spacing
));
2753 else if (FLOATP (BVAR (current_buffer
, extra_line_spacing
)))
2754 it
->extra_line_spacing
= (XFLOAT_DATA (BVAR (current_buffer
, extra_line_spacing
))
2755 * FRAME_LINE_HEIGHT (it
->f
));
2756 else if (it
->f
->extra_line_spacing
> 0)
2757 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2758 it
->max_extra_line_spacing
= 0;
2761 /* If realized faces have been removed, e.g. because of face
2762 attribute changes of named faces, recompute them. When running
2763 in batch mode, the face cache of the initial frame is null. If
2764 we happen to get called, make a dummy face cache. */
2765 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2766 init_frame_faces (it
->f
);
2767 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2768 recompute_basic_faces (it
->f
);
2770 /* Current value of the `slice', `space-width', and 'height' properties. */
2771 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2772 it
->space_width
= Qnil
;
2773 it
->font_height
= Qnil
;
2774 it
->override_ascent
= -1;
2776 /* Are control characters displayed as `^C'? */
2777 it
->ctl_arrow_p
= !NILP (BVAR (current_buffer
, ctl_arrow
));
2779 /* -1 means everything between a CR and the following line end
2780 is invisible. >0 means lines indented more than this value are
2782 it
->selective
= (INTEGERP (BVAR (current_buffer
, selective_display
))
2784 (-1, XINT (BVAR (current_buffer
, selective_display
)),
2786 : (!NILP (BVAR (current_buffer
, selective_display
))
2788 it
->selective_display_ellipsis_p
2789 = !NILP (BVAR (current_buffer
, selective_display_ellipses
));
2791 /* Display table to use. */
2792 it
->dp
= window_display_table (w
);
2794 /* Are multibyte characters enabled in current_buffer? */
2795 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
2797 /* Get the position at which the redisplay_end_trigger hook should
2798 be run, if it is to be run at all. */
2799 if (MARKERP (w
->redisplay_end_trigger
)
2800 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2801 it
->redisplay_end_trigger_charpos
2802 = marker_position (w
->redisplay_end_trigger
);
2803 else if (INTEGERP (w
->redisplay_end_trigger
))
2804 it
->redisplay_end_trigger_charpos
=
2805 clip_to_bounds (PTRDIFF_MIN
, XINT (w
->redisplay_end_trigger
), PTRDIFF_MAX
);
2807 it
->tab_width
= SANE_TAB_WIDTH (current_buffer
);
2809 /* Are lines in the display truncated? */
2810 if (base_face_id
!= DEFAULT_FACE_ID
2812 || (! WINDOW_FULL_WIDTH_P (it
->w
)
2813 && ((!NILP (Vtruncate_partial_width_windows
)
2814 && !INTEGERP (Vtruncate_partial_width_windows
))
2815 || (INTEGERP (Vtruncate_partial_width_windows
)
2816 /* PXW: Shall we do something about this ? */
2817 && (WINDOW_TOTAL_COLS (it
->w
)
2818 < XINT (Vtruncate_partial_width_windows
))))))
2819 it
->line_wrap
= TRUNCATE
;
2820 else if (NILP (BVAR (current_buffer
, truncate_lines
)))
2821 it
->line_wrap
= NILP (BVAR (current_buffer
, word_wrap
))
2822 ? WINDOW_WRAP
: WORD_WRAP
;
2824 it
->line_wrap
= TRUNCATE
;
2826 /* Get dimensions of truncation and continuation glyphs. These are
2827 displayed as fringe bitmaps under X, but we need them for such
2828 frames when the fringes are turned off. But leave the dimensions
2829 zero for tooltip frames, as these glyphs look ugly there and also
2830 sabotage calculations of tooltip dimensions in x-show-tip. */
2831 #ifdef HAVE_WINDOW_SYSTEM
2832 if (!(FRAME_WINDOW_P (it
->f
)
2833 && FRAMEP (tip_frame
)
2834 && it
->f
== XFRAME (tip_frame
)))
2837 if (it
->line_wrap
== TRUNCATE
)
2839 /* We will need the truncation glyph. */
2840 eassert (it
->glyph_row
== NULL
);
2841 produce_special_glyphs (it
, IT_TRUNCATION
);
2842 it
->truncation_pixel_width
= it
->pixel_width
;
2846 /* We will need the continuation glyph. */
2847 eassert (it
->glyph_row
== NULL
);
2848 produce_special_glyphs (it
, IT_CONTINUATION
);
2849 it
->continuation_pixel_width
= it
->pixel_width
;
2853 /* Reset these values to zero because the produce_special_glyphs
2854 above has changed them. */
2855 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2856 it
->phys_ascent
= it
->phys_descent
= 0;
2858 /* Set this after getting the dimensions of truncation and
2859 continuation glyphs, so that we don't produce glyphs when calling
2860 produce_special_glyphs, above. */
2861 it
->glyph_row
= row
;
2862 it
->area
= TEXT_AREA
;
2864 /* Forget any previous info about this row being reversed. */
2866 it
->glyph_row
->reversed_p
= 0;
2868 /* Get the dimensions of the display area. The display area
2869 consists of the visible window area plus a horizontally scrolled
2870 part to the left of the window. All x-values are relative to the
2871 start of this total display area. */
2872 if (base_face_id
!= DEFAULT_FACE_ID
)
2874 /* Mode lines, menu bar in terminal frames. */
2875 it
->first_visible_x
= 0;
2876 it
->last_visible_x
= WINDOW_PIXEL_WIDTH (w
);
2881 = window_hscroll_limited (it
->w
, it
->f
) * FRAME_COLUMN_WIDTH (it
->f
);
2882 it
->last_visible_x
= (it
->first_visible_x
2883 + window_box_width (w
, TEXT_AREA
));
2885 /* If we truncate lines, leave room for the truncation glyph(s) at
2886 the right margin. Otherwise, leave room for the continuation
2887 glyph(s). Done only if the window has no fringes. Since we
2888 don't know at this point whether there will be any R2L lines in
2889 the window, we reserve space for truncation/continuation glyphs
2890 even if only one of the fringes is absent. */
2891 if (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0
2892 || (it
->bidi_p
&& WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0))
2894 if (it
->line_wrap
== TRUNCATE
)
2895 it
->last_visible_x
-= it
->truncation_pixel_width
;
2897 it
->last_visible_x
-= it
->continuation_pixel_width
;
2900 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2901 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2904 /* Leave room for a border glyph. */
2905 if (!FRAME_WINDOW_P (it
->f
)
2906 && !WINDOW_RIGHTMOST_P (it
->w
))
2907 it
->last_visible_x
-= 1;
2909 it
->last_visible_y
= window_text_bottom_y (w
);
2911 /* For mode lines and alike, arrange for the first glyph having a
2912 left box line if the face specifies a box. */
2913 if (base_face_id
!= DEFAULT_FACE_ID
)
2917 it
->face_id
= remapped_base_face_id
;
2919 /* If we have a boxed mode line, make the first character appear
2920 with a left box line. */
2921 face
= FACE_FROM_ID (it
->f
, remapped_base_face_id
);
2922 if (face
->box
!= FACE_NO_BOX
)
2923 it
->start_of_box_run_p
= true;
2926 /* If a buffer position was specified, set the iterator there,
2927 getting overlays and face properties from that position. */
2928 if (charpos
>= BUF_BEG (current_buffer
))
2930 it
->end_charpos
= ZV
;
2931 eassert (charpos
== BYTE_TO_CHAR (bytepos
));
2932 IT_CHARPOS (*it
) = charpos
;
2933 IT_BYTEPOS (*it
) = bytepos
;
2935 /* We will rely on `reseat' to set this up properly, via
2936 handle_face_prop. */
2937 it
->face_id
= it
->base_face_id
;
2939 it
->start
= it
->current
;
2940 /* Do we need to reorder bidirectional text? Not if this is a
2941 unibyte buffer: by definition, none of the single-byte
2942 characters are strong R2L, so no reordering is needed. And
2943 bidi.c doesn't support unibyte buffers anyway. Also, don't
2944 reorder while we are loading loadup.el, since the tables of
2945 character properties needed for reordering are not yet
2949 && !NILP (BVAR (current_buffer
, bidi_display_reordering
))
2952 /* If we are to reorder bidirectional text, init the bidi
2956 /* Note the paragraph direction that this buffer wants to
2958 if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2960 it
->paragraph_embedding
= L2R
;
2961 else if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2963 it
->paragraph_embedding
= R2L
;
2965 it
->paragraph_embedding
= NEUTRAL_DIR
;
2966 bidi_unshelve_cache (NULL
, 0);
2967 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
2971 /* Compute faces etc. */
2972 reseat (it
, it
->current
.pos
, 1);
2979 /* Initialize IT for the display of window W with window start POS. */
2982 start_display (struct it
*it
, struct window
*w
, struct text_pos pos
)
2984 struct glyph_row
*row
;
2985 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2987 row
= w
->desired_matrix
->rows
+ first_vpos
;
2988 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2989 it
->first_vpos
= first_vpos
;
2991 /* Don't reseat to previous visible line start if current start
2992 position is in a string or image. */
2993 if (it
->method
== GET_FROM_BUFFER
&& it
->line_wrap
!= TRUNCATE
)
2995 int start_at_line_beg_p
;
2996 int first_y
= it
->current_y
;
2998 /* If window start is not at a line start, skip forward to POS to
2999 get the correct continuation lines width. */
3000 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
3001 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
3002 if (!start_at_line_beg_p
)
3006 reseat_at_previous_visible_line_start (it
);
3007 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
3009 new_x
= it
->current_x
+ it
->pixel_width
;
3011 /* If lines are continued, this line may end in the middle
3012 of a multi-glyph character (e.g. a control character
3013 displayed as \003, or in the middle of an overlay
3014 string). In this case move_it_to above will not have
3015 taken us to the start of the continuation line but to the
3016 end of the continued line. */
3017 if (it
->current_x
> 0
3018 && it
->line_wrap
!= TRUNCATE
/* Lines are continued. */
3019 && (/* And glyph doesn't fit on the line. */
3020 new_x
> it
->last_visible_x
3021 /* Or it fits exactly and we're on a window
3023 || (new_x
== it
->last_visible_x
3024 && FRAME_WINDOW_P (it
->f
)
3025 && ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
3026 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
3027 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
3029 if ((it
->current
.dpvec_index
>= 0
3030 || it
->current
.overlay_string_index
>= 0)
3031 /* If we are on a newline from a display vector or
3032 overlay string, then we are already at the end of
3033 a screen line; no need to go to the next line in
3034 that case, as this line is not really continued.
3035 (If we do go to the next line, C-e will not DTRT.) */
3038 set_iterator_to_next (it
, 1);
3039 move_it_in_display_line_to (it
, -1, -1, 0);
3042 it
->continuation_lines_width
+= it
->current_x
;
3044 /* If the character at POS is displayed via a display
3045 vector, move_it_to above stops at the final glyph of
3046 IT->dpvec. To make the caller redisplay that character
3047 again (a.k.a. start at POS), we need to reset the
3048 dpvec_index to the beginning of IT->dpvec. */
3049 else if (it
->current
.dpvec_index
>= 0)
3050 it
->current
.dpvec_index
= 0;
3052 /* We're starting a new display line, not affected by the
3053 height of the continued line, so clear the appropriate
3054 fields in the iterator structure. */
3055 it
->max_ascent
= it
->max_descent
= 0;
3056 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
3058 it
->current_y
= first_y
;
3060 it
->current_x
= it
->hpos
= 0;
3066 /* Return 1 if POS is a position in ellipses displayed for invisible
3067 text. W is the window we display, for text property lookup. */
3070 in_ellipses_for_invisible_text_p (struct display_pos
*pos
, struct window
*w
)
3072 Lisp_Object prop
, window
;
3074 ptrdiff_t charpos
= CHARPOS (pos
->pos
);
3076 /* If POS specifies a position in a display vector, this might
3077 be for an ellipsis displayed for invisible text. We won't
3078 get the iterator set up for delivering that ellipsis unless
3079 we make sure that it gets aware of the invisible text. */
3080 if (pos
->dpvec_index
>= 0
3081 && pos
->overlay_string_index
< 0
3082 && CHARPOS (pos
->string_pos
) < 0
3084 && (XSETWINDOW (window
, w
),
3085 prop
= Fget_char_property (make_number (charpos
),
3086 Qinvisible
, window
),
3087 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
3089 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
3091 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
3098 /* Initialize IT for stepping through current_buffer in window W,
3099 starting at position POS that includes overlay string and display
3100 vector/ control character translation position information. Value
3101 is zero if there are overlay strings with newlines at POS. */
3104 init_from_display_pos (struct it
*it
, struct window
*w
, struct display_pos
*pos
)
3106 ptrdiff_t charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
3107 int i
, overlay_strings_with_newlines
= 0;
3109 /* If POS specifies a position in a display vector, this might
3110 be for an ellipsis displayed for invisible text. We won't
3111 get the iterator set up for delivering that ellipsis unless
3112 we make sure that it gets aware of the invisible text. */
3113 if (in_ellipses_for_invisible_text_p (pos
, w
))
3119 /* Keep in mind: the call to reseat in init_iterator skips invisible
3120 text, so we might end up at a position different from POS. This
3121 is only a problem when POS is a row start after a newline and an
3122 overlay starts there with an after-string, and the overlay has an
3123 invisible property. Since we don't skip invisible text in
3124 display_line and elsewhere immediately after consuming the
3125 newline before the row start, such a POS will not be in a string,
3126 but the call to init_iterator below will move us to the
3128 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
3130 /* This only scans the current chunk -- it should scan all chunks.
3131 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
3132 to 16 in 22.1 to make this a lesser problem. */
3133 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
3135 const char *s
= SSDATA (it
->overlay_strings
[i
]);
3136 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
3138 while (s
< e
&& *s
!= '\n')
3143 overlay_strings_with_newlines
= 1;
3148 /* If position is within an overlay string, set up IT to the right
3150 if (pos
->overlay_string_index
>= 0)
3154 /* If the first overlay string happens to have a `display'
3155 property for an image, the iterator will be set up for that
3156 image, and we have to undo that setup first before we can
3157 correct the overlay string index. */
3158 if (it
->method
== GET_FROM_IMAGE
)
3161 /* We already have the first chunk of overlay strings in
3162 IT->overlay_strings. Load more until the one for
3163 pos->overlay_string_index is in IT->overlay_strings. */
3164 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
3166 ptrdiff_t n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
3167 it
->current
.overlay_string_index
= 0;
3170 load_overlay_strings (it
, 0);
3171 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
3175 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
3176 relative_index
= (it
->current
.overlay_string_index
3177 % OVERLAY_STRING_CHUNK_SIZE
);
3178 it
->string
= it
->overlay_strings
[relative_index
];
3179 eassert (STRINGP (it
->string
));
3180 it
->current
.string_pos
= pos
->string_pos
;
3181 it
->method
= GET_FROM_STRING
;
3182 it
->end_charpos
= SCHARS (it
->string
);
3183 /* Set up the bidi iterator for this overlay string. */
3186 it
->bidi_it
.string
.lstring
= it
->string
;
3187 it
->bidi_it
.string
.s
= NULL
;
3188 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
3189 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
3190 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
3191 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
3192 it
->bidi_it
.w
= it
->w
;
3193 bidi_init_it (IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
),
3194 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
3196 /* Synchronize the state of the bidi iterator with
3197 pos->string_pos. For any string position other than
3198 zero, this will be done automagically when we resume
3199 iteration over the string and get_visually_first_element
3200 is called. But if string_pos is zero, and the string is
3201 to be reordered for display, we need to resync manually,
3202 since it could be that the iteration state recorded in
3203 pos ended at string_pos of 0 moving backwards in string. */
3204 if (CHARPOS (pos
->string_pos
) == 0)
3206 get_visually_first_element (it
);
3207 if (IT_STRING_CHARPOS (*it
) != 0)
3210 eassert (it
->bidi_it
.charpos
< it
->bidi_it
.string
.schars
);
3211 bidi_move_to_visually_next (&it
->bidi_it
);
3212 } while (it
->bidi_it
.charpos
!= 0);
3214 eassert (IT_STRING_CHARPOS (*it
) == it
->bidi_it
.charpos
3215 && IT_STRING_BYTEPOS (*it
) == it
->bidi_it
.bytepos
);
3219 if (CHARPOS (pos
->string_pos
) >= 0)
3221 /* Recorded position is not in an overlay string, but in another
3222 string. This can only be a string from a `display' property.
3223 IT should already be filled with that string. */
3224 it
->current
.string_pos
= pos
->string_pos
;
3225 eassert (STRINGP (it
->string
));
3227 bidi_init_it (IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
),
3228 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
3231 /* Restore position in display vector translations, control
3232 character translations or ellipses. */
3233 if (pos
->dpvec_index
>= 0)
3235 if (it
->dpvec
== NULL
)
3236 get_next_display_element (it
);
3237 eassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
3238 it
->current
.dpvec_index
= pos
->dpvec_index
;
3242 return !overlay_strings_with_newlines
;
3246 /* Initialize IT for stepping through current_buffer in window W
3247 starting at ROW->start. */
3250 init_to_row_start (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3252 init_from_display_pos (it
, w
, &row
->start
);
3253 it
->start
= row
->start
;
3254 it
->continuation_lines_width
= row
->continuation_lines_width
;
3259 /* Initialize IT for stepping through current_buffer in window W
3260 starting in the line following ROW, i.e. starting at ROW->end.
3261 Value is zero if there are overlay strings with newlines at ROW's
3265 init_to_row_end (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3269 if (init_from_display_pos (it
, w
, &row
->end
))
3271 if (row
->continued_p
)
3272 it
->continuation_lines_width
3273 = row
->continuation_lines_width
+ row
->pixel_width
;
3284 /***********************************************************************
3286 ***********************************************************************/
3288 /* Called when IT reaches IT->stop_charpos. Handle text property and
3289 overlay changes. Set IT->stop_charpos to the next position where
3293 handle_stop (struct it
*it
)
3295 enum prop_handled handled
;
3296 int handle_overlay_change_p
;
3300 it
->current
.dpvec_index
= -1;
3301 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3302 it
->ignore_overlay_strings_at_pos_p
= 0;
3305 /* Use face of preceding text for ellipsis (if invisible) */
3306 if (it
->selective_display_ellipsis_p
)
3307 it
->saved_face_id
= it
->face_id
;
3311 handled
= HANDLED_NORMALLY
;
3313 /* Call text property handlers. */
3314 for (p
= it_props
; p
->handler
; ++p
)
3316 handled
= p
->handler (it
);
3318 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3320 else if (handled
== HANDLED_RETURN
)
3322 /* We still want to show before and after strings from
3323 overlays even if the actual buffer text is replaced. */
3324 if (!handle_overlay_change_p
3326 /* Don't call get_overlay_strings_1 if we already
3327 have overlay strings loaded, because doing so
3328 will load them again and push the iterator state
3329 onto the stack one more time, which is not
3330 expected by the rest of the code that processes
3332 || (it
->current
.overlay_string_index
< 0
3333 ? !get_overlay_strings_1 (it
, 0, 0)
3337 setup_for_ellipsis (it
, 0);
3338 /* When handling a display spec, we might load an
3339 empty string. In that case, discard it here. We
3340 used to discard it in handle_single_display_spec,
3341 but that causes get_overlay_strings_1, above, to
3342 ignore overlay strings that we must check. */
3343 if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3347 else if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3351 it
->ignore_overlay_strings_at_pos_p
= true;
3352 it
->string_from_display_prop_p
= 0;
3353 it
->from_disp_prop_p
= 0;
3354 handle_overlay_change_p
= 0;
3356 handled
= HANDLED_RECOMPUTE_PROPS
;
3359 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3360 handle_overlay_change_p
= 0;
3363 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3365 /* Don't check for overlay strings below when set to deliver
3366 characters from a display vector. */
3367 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3368 handle_overlay_change_p
= 0;
3370 /* Handle overlay changes.
3371 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
3372 if it finds overlays. */
3373 if (handle_overlay_change_p
)
3374 handled
= handle_overlay_change (it
);
3379 setup_for_ellipsis (it
, 0);
3383 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3385 /* Determine where to stop next. */
3386 if (handled
== HANDLED_NORMALLY
)
3387 compute_stop_pos (it
);
3391 /* Compute IT->stop_charpos from text property and overlay change
3392 information for IT's current position. */
3395 compute_stop_pos (struct it
*it
)
3397 register INTERVAL iv
, next_iv
;
3398 Lisp_Object object
, limit
, position
;
3399 ptrdiff_t charpos
, bytepos
;
3401 if (STRINGP (it
->string
))
3403 /* Strings are usually short, so don't limit the search for
3405 it
->stop_charpos
= it
->end_charpos
;
3406 object
= it
->string
;
3408 charpos
= IT_STRING_CHARPOS (*it
);
3409 bytepos
= IT_STRING_BYTEPOS (*it
);
3415 /* If end_charpos is out of range for some reason, such as a
3416 misbehaving display function, rationalize it (Bug#5984). */
3417 if (it
->end_charpos
> ZV
)
3418 it
->end_charpos
= ZV
;
3419 it
->stop_charpos
= it
->end_charpos
;
3421 /* If next overlay change is in front of the current stop pos
3422 (which is IT->end_charpos), stop there. Note: value of
3423 next_overlay_change is point-max if no overlay change
3425 charpos
= IT_CHARPOS (*it
);
3426 bytepos
= IT_BYTEPOS (*it
);
3427 pos
= next_overlay_change (charpos
);
3428 if (pos
< it
->stop_charpos
)
3429 it
->stop_charpos
= pos
;
3431 /* Set up variables for computing the stop position from text
3432 property changes. */
3433 XSETBUFFER (object
, current_buffer
);
3434 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3437 /* Get the interval containing IT's position. Value is a null
3438 interval if there isn't such an interval. */
3439 position
= make_number (charpos
);
3440 iv
= validate_interval_range (object
, &position
, &position
, 0);
3443 Lisp_Object values_here
[LAST_PROP_IDX
];
3446 /* Get properties here. */
3447 for (p
= it_props
; p
->handler
; ++p
)
3448 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3450 /* Look for an interval following iv that has different
3452 for (next_iv
= next_interval (iv
);
3455 || XFASTINT (limit
) > next_iv
->position
));
3456 next_iv
= next_interval (next_iv
))
3458 for (p
= it_props
; p
->handler
; ++p
)
3460 Lisp_Object new_value
;
3462 new_value
= textget (next_iv
->plist
, *p
->name
);
3463 if (!EQ (values_here
[p
->idx
], new_value
))
3473 if (INTEGERP (limit
)
3474 && next_iv
->position
>= XFASTINT (limit
))
3475 /* No text property change up to limit. */
3476 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3478 /* Text properties change in next_iv. */
3479 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3483 if (it
->cmp_it
.id
< 0)
3485 ptrdiff_t stoppos
= it
->end_charpos
;
3487 if (it
->bidi_p
&& it
->bidi_it
.scan_dir
< 0)
3489 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
,
3490 stoppos
, it
->string
);
3493 eassert (STRINGP (it
->string
)
3494 || (it
->stop_charpos
>= BEGV
3495 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3499 /* Return the position of the next overlay change after POS in
3500 current_buffer. Value is point-max if no overlay change
3501 follows. This is like `next-overlay-change' but doesn't use
3505 next_overlay_change (ptrdiff_t pos
)
3507 ptrdiff_t i
, noverlays
;
3509 Lisp_Object
*overlays
;
3511 /* Get all overlays at the given position. */
3512 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3514 /* If any of these overlays ends before endpos,
3515 use its ending point instead. */
3516 for (i
= 0; i
< noverlays
; ++i
)
3521 oend
= OVERLAY_END (overlays
[i
]);
3522 oendpos
= OVERLAY_POSITION (oend
);
3523 endpos
= min (endpos
, oendpos
);
3529 /* How many characters forward to search for a display property or
3530 display string. Searching too far forward makes the bidi display
3531 sluggish, especially in small windows. */
3532 #define MAX_DISP_SCAN 250
3534 /* Return the character position of a display string at or after
3535 position specified by POSITION. If no display string exists at or
3536 after POSITION, return ZV. A display string is either an overlay
3537 with `display' property whose value is a string, or a `display'
3538 text property whose value is a string. STRING is data about the
3539 string to iterate; if STRING->lstring is nil, we are iterating a
3540 buffer. FRAME_WINDOW_P is non-zero when we are displaying a window
3541 on a GUI frame. DISP_PROP is set to zero if we searched
3542 MAX_DISP_SCAN characters forward without finding any display
3543 strings, non-zero otherwise. It is set to 2 if the display string
3544 uses any kind of `(space ...)' spec that will produce a stretch of
3545 white space in the text area. */
3547 compute_display_string_pos (struct text_pos
*position
,
3548 struct bidi_string_data
*string
,
3550 int frame_window_p
, int *disp_prop
)
3552 /* OBJECT = nil means current buffer. */
3553 Lisp_Object object
, object1
;
3554 Lisp_Object pos
, spec
, limpos
;
3555 int string_p
= (string
&& (STRINGP (string
->lstring
) || string
->s
));
3556 ptrdiff_t eob
= string_p
? string
->schars
: ZV
;
3557 ptrdiff_t begb
= string_p
? 0 : BEGV
;
3558 ptrdiff_t bufpos
, charpos
= CHARPOS (*position
);
3560 (charpos
< eob
- MAX_DISP_SCAN
) ? charpos
+ MAX_DISP_SCAN
: eob
;
3561 struct text_pos tpos
;
3564 if (string
&& STRINGP (string
->lstring
))
3565 object1
= object
= string
->lstring
;
3566 else if (w
&& !string_p
)
3568 XSETWINDOW (object
, w
);
3572 object1
= object
= Qnil
;
3577 /* We don't support display properties whose values are strings
3578 that have display string properties. */
3579 || string
->from_disp_str
3580 /* C strings cannot have display properties. */
3581 || (string
->s
&& !STRINGP (object
)))
3587 /* If the character at CHARPOS is where the display string begins,
3589 pos
= make_number (charpos
);
3590 if (STRINGP (object
))
3591 bufpos
= string
->bufpos
;
3595 if (!NILP (spec
= Fget_char_property (pos
, Qdisplay
, object
))
3597 || !EQ (Fget_char_property (make_number (charpos
- 1), Qdisplay
,
3600 && (rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
, bufpos
,
3608 /* Look forward for the first character with a `display' property
3609 that will replace the underlying text when displayed. */
3610 limpos
= make_number (lim
);
3612 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object1
, limpos
);
3613 CHARPOS (tpos
) = XFASTINT (pos
);
3614 if (CHARPOS (tpos
) >= lim
)
3619 if (STRINGP (object
))
3620 BYTEPOS (tpos
) = string_char_to_byte (object
, CHARPOS (tpos
));
3622 BYTEPOS (tpos
) = CHAR_TO_BYTE (CHARPOS (tpos
));
3623 spec
= Fget_char_property (pos
, Qdisplay
, object
);
3624 if (!STRINGP (object
))
3625 bufpos
= CHARPOS (tpos
);
3626 } while (NILP (spec
)
3627 || !(rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
,
3628 bufpos
, frame_window_p
)));
3632 return CHARPOS (tpos
);
3635 /* Return the character position of the end of the display string that
3636 started at CHARPOS. If there's no display string at CHARPOS,
3637 return -1. A display string is either an overlay with `display'
3638 property whose value is a string or a `display' text property whose
3639 value is a string. */
3641 compute_display_string_end (ptrdiff_t charpos
, struct bidi_string_data
*string
)
3643 /* OBJECT = nil means current buffer. */
3644 Lisp_Object object
=
3645 (string
&& STRINGP (string
->lstring
)) ? string
->lstring
: Qnil
;
3646 Lisp_Object pos
= make_number (charpos
);
3648 (STRINGP (object
) || (string
&& string
->s
)) ? string
->schars
: ZV
;
3650 if (charpos
>= eob
|| (string
->s
&& !STRINGP (object
)))
3653 /* It could happen that the display property or overlay was removed
3654 since we found it in compute_display_string_pos above. One way
3655 this can happen is if JIT font-lock was called (through
3656 handle_fontified_prop), and jit-lock-functions remove text
3657 properties or overlays from the portion of buffer that includes
3658 CHARPOS. Muse mode is known to do that, for example. In this
3659 case, we return -1 to the caller, to signal that no display
3660 string is actually present at CHARPOS. See bidi_fetch_char for
3661 how this is handled.
3663 An alternative would be to never look for display properties past
3664 it->stop_charpos. But neither compute_display_string_pos nor
3665 bidi_fetch_char that calls it know or care where the next
3667 if (NILP (Fget_char_property (pos
, Qdisplay
, object
)))
3670 /* Look forward for the first character where the `display' property
3672 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, Qnil
);
3674 return XFASTINT (pos
);
3679 /***********************************************************************
3681 ***********************************************************************/
3683 /* Handle changes in the `fontified' property of the current buffer by
3684 calling hook functions from Qfontification_functions to fontify
3687 static enum prop_handled
3688 handle_fontified_prop (struct it
*it
)
3690 Lisp_Object prop
, pos
;
3691 enum prop_handled handled
= HANDLED_NORMALLY
;
3693 if (!NILP (Vmemory_full
))
3696 /* Get the value of the `fontified' property at IT's current buffer
3697 position. (The `fontified' property doesn't have a special
3698 meaning in strings.) If the value is nil, call functions from
3699 Qfontification_functions. */
3700 if (!STRINGP (it
->string
)
3702 && !NILP (Vfontification_functions
)
3703 && !NILP (Vrun_hooks
)
3704 && (pos
= make_number (IT_CHARPOS (*it
)),
3705 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3706 /* Ignore the special cased nil value always present at EOB since
3707 no amount of fontifying will be able to change it. */
3708 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3710 ptrdiff_t count
= SPECPDL_INDEX ();
3712 struct buffer
*obuf
= current_buffer
;
3713 ptrdiff_t begv
= BEGV
, zv
= ZV
;
3714 bool old_clip_changed
= current_buffer
->clip_changed
;
3716 val
= Vfontification_functions
;
3717 specbind (Qfontification_functions
, Qnil
);
3719 eassert (it
->end_charpos
== ZV
);
3721 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3722 safe_call1 (val
, pos
);
3725 Lisp_Object fns
, fn
;
3726 struct gcpro gcpro1
, gcpro2
;
3731 for (; CONSP (val
); val
= XCDR (val
))
3737 /* A value of t indicates this hook has a local
3738 binding; it means to run the global binding too.
3739 In a global value, t should not occur. If it
3740 does, we must ignore it to avoid an endless
3742 for (fns
= Fdefault_value (Qfontification_functions
);
3748 safe_call1 (fn
, pos
);
3752 safe_call1 (fn
, pos
);
3758 unbind_to (count
, Qnil
);
3760 /* Fontification functions routinely call `save-restriction'.
3761 Normally, this tags clip_changed, which can confuse redisplay
3762 (see discussion in Bug#6671). Since we don't perform any
3763 special handling of fontification changes in the case where
3764 `save-restriction' isn't called, there's no point doing so in
3765 this case either. So, if the buffer's restrictions are
3766 actually left unchanged, reset clip_changed. */
3767 if (obuf
== current_buffer
)
3769 if (begv
== BEGV
&& zv
== ZV
)
3770 current_buffer
->clip_changed
= old_clip_changed
;
3772 /* There isn't much we can reasonably do to protect against
3773 misbehaving fontification, but here's a fig leaf. */
3774 else if (BUFFER_LIVE_P (obuf
))
3775 set_buffer_internal_1 (obuf
);
3777 /* The fontification code may have added/removed text.
3778 It could do even a lot worse, but let's at least protect against
3779 the most obvious case where only the text past `pos' gets changed',
3780 as is/was done in grep.el where some escapes sequences are turned
3781 into face properties (bug#7876). */
3782 it
->end_charpos
= ZV
;
3784 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3785 something. This avoids an endless loop if they failed to
3786 fontify the text for which reason ever. */
3787 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3788 handled
= HANDLED_RECOMPUTE_PROPS
;
3796 /***********************************************************************
3798 ***********************************************************************/
3800 /* Set up iterator IT from face properties at its current position.
3801 Called from handle_stop. */
3803 static enum prop_handled
3804 handle_face_prop (struct it
*it
)
3807 ptrdiff_t next_stop
;
3809 if (!STRINGP (it
->string
))
3812 = face_at_buffer_position (it
->w
,
3816 + TEXT_PROP_DISTANCE_LIMIT
),
3817 0, it
->base_face_id
);
3819 /* Is this a start of a run of characters with box face?
3820 Caveat: this can be called for a freshly initialized
3821 iterator; face_id is -1 in this case. We know that the new
3822 face will not change until limit, i.e. if the new face has a
3823 box, all characters up to limit will have one. But, as
3824 usual, we don't know whether limit is really the end. */
3825 if (new_face_id
!= it
->face_id
)
3827 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3828 /* If it->face_id is -1, old_face below will be NULL, see
3829 the definition of FACE_FROM_ID. This will happen if this
3830 is the initial call that gets the face. */
3831 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3833 /* If the value of face_id of the iterator is -1, we have to
3834 look in front of IT's position and see whether there is a
3835 face there that's different from new_face_id. */
3836 if (!old_face
&& IT_CHARPOS (*it
) > BEG
)
3838 int prev_face_id
= face_before_it_pos (it
);
3840 old_face
= FACE_FROM_ID (it
->f
, prev_face_id
);
3843 /* If the new face has a box, but the old face does not,
3844 this is the start of a run of characters with box face,
3845 i.e. this character has a shadow on the left side. */
3846 it
->start_of_box_run_p
= (new_face
->box
!= FACE_NO_BOX
3847 && (old_face
== NULL
|| !old_face
->box
));
3848 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3856 Lisp_Object from_overlay
3857 = (it
->current
.overlay_string_index
>= 0
3858 ? it
->string_overlays
[it
->current
.overlay_string_index
3859 % OVERLAY_STRING_CHUNK_SIZE
]
3862 /* See if we got to this string directly or indirectly from
3863 an overlay property. That includes the before-string or
3864 after-string of an overlay, strings in display properties
3865 provided by an overlay, their text properties, etc.
3867 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3868 if (! NILP (from_overlay
))
3869 for (i
= it
->sp
- 1; i
>= 0; i
--)
3871 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3873 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
3874 % OVERLAY_STRING_CHUNK_SIZE
];
3875 else if (! NILP (it
->stack
[i
].from_overlay
))
3876 from_overlay
= it
->stack
[i
].from_overlay
;
3878 if (!NILP (from_overlay
))
3882 if (! NILP (from_overlay
))
3884 bufpos
= IT_CHARPOS (*it
);
3885 /* For a string from an overlay, the base face depends
3886 only on text properties and ignores overlays. */
3888 = face_for_overlay_string (it
->w
,
3892 + TEXT_PROP_DISTANCE_LIMIT
),
3900 /* For strings from a `display' property, use the face at
3901 IT's current buffer position as the base face to merge
3902 with, so that overlay strings appear in the same face as
3903 surrounding text, unless they specify their own faces.
3904 For strings from wrap-prefix and line-prefix properties,
3905 use the default face, possibly remapped via
3906 Vface_remapping_alist. */
3907 base_face_id
= it
->string_from_prefix_prop_p
3908 ? (!NILP (Vface_remapping_alist
)
3909 ? lookup_basic_face (it
->f
, DEFAULT_FACE_ID
)
3911 : underlying_face_id (it
);
3914 new_face_id
= face_at_string_position (it
->w
,
3916 IT_STRING_CHARPOS (*it
),
3921 /* Is this a start of a run of characters with box? Caveat:
3922 this can be called for a freshly allocated iterator; face_id
3923 is -1 is this case. We know that the new face will not
3924 change until the next check pos, i.e. if the new face has a
3925 box, all characters up to that position will have a
3926 box. But, as usual, we don't know whether that position
3927 is really the end. */
3928 if (new_face_id
!= it
->face_id
)
3930 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3931 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3933 /* If new face has a box but old face hasn't, this is the
3934 start of a run of characters with box, i.e. it has a
3935 shadow on the left side. */
3936 it
->start_of_box_run_p
3937 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3938 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3942 it
->face_id
= new_face_id
;
3943 return HANDLED_NORMALLY
;
3947 /* Return the ID of the face ``underlying'' IT's current position,
3948 which is in a string. If the iterator is associated with a
3949 buffer, return the face at IT's current buffer position.
3950 Otherwise, use the iterator's base_face_id. */
3953 underlying_face_id (struct it
*it
)
3955 int face_id
= it
->base_face_id
, i
;
3957 eassert (STRINGP (it
->string
));
3959 for (i
= it
->sp
- 1; i
>= 0; --i
)
3960 if (NILP (it
->stack
[i
].string
))
3961 face_id
= it
->stack
[i
].face_id
;
3967 /* Compute the face one character before or after the current position
3968 of IT, in the visual order. BEFORE_P non-zero means get the face
3969 in front (to the left in L2R paragraphs, to the right in R2L
3970 paragraphs) of IT's screen position. Value is the ID of the face. */
3973 face_before_or_after_it_pos (struct it
*it
, int before_p
)
3976 ptrdiff_t next_check_charpos
;
3978 void *it_copy_data
= NULL
;
3980 eassert (it
->s
== NULL
);
3982 if (STRINGP (it
->string
))
3984 ptrdiff_t bufpos
, charpos
;
3987 /* No face change past the end of the string (for the case
3988 we are padding with spaces). No face change before the
3990 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3991 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3996 /* Set charpos to the position before or after IT's current
3997 position, in the logical order, which in the non-bidi
3998 case is the same as the visual order. */
4000 charpos
= IT_STRING_CHARPOS (*it
) - 1;
4001 else if (it
->what
== IT_COMPOSITION
)
4002 /* For composition, we must check the character after the
4004 charpos
= IT_STRING_CHARPOS (*it
) + it
->cmp_it
.nchars
;
4006 charpos
= IT_STRING_CHARPOS (*it
) + 1;
4012 /* With bidi iteration, the character before the current
4013 in the visual order cannot be found by simple
4014 iteration, because "reverse" reordering is not
4015 supported. Instead, we need to use the move_it_*
4016 family of functions. */
4017 /* Ignore face changes before the first visible
4018 character on this display line. */
4019 if (it
->current_x
<= it
->first_visible_x
)
4021 SAVE_IT (it_copy
, *it
, it_copy_data
);
4022 /* Implementation note: Since move_it_in_display_line
4023 works in the iterator geometry, and thinks the first
4024 character is always the leftmost, even in R2L lines,
4025 we don't need to distinguish between the R2L and L2R
4027 move_it_in_display_line (&it_copy
, SCHARS (it_copy
.string
),
4028 it_copy
.current_x
- 1, MOVE_TO_X
);
4029 charpos
= IT_STRING_CHARPOS (it_copy
);
4030 RESTORE_IT (it
, it
, it_copy_data
);
4034 /* Set charpos to the string position of the character
4035 that comes after IT's current position in the visual
4037 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
4041 bidi_move_to_visually_next (&it_copy
.bidi_it
);
4043 charpos
= it_copy
.bidi_it
.charpos
;
4046 eassert (0 <= charpos
&& charpos
<= SCHARS (it
->string
));
4048 if (it
->current
.overlay_string_index
>= 0)
4049 bufpos
= IT_CHARPOS (*it
);
4053 base_face_id
= underlying_face_id (it
);
4055 /* Get the face for ASCII, or unibyte. */
4056 face_id
= face_at_string_position (it
->w
,
4060 &next_check_charpos
,
4063 /* Correct the face for charsets different from ASCII. Do it
4064 for the multibyte case only. The face returned above is
4065 suitable for unibyte text if IT->string is unibyte. */
4066 if (STRING_MULTIBYTE (it
->string
))
4068 struct text_pos pos1
= string_pos (charpos
, it
->string
);
4069 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos1
);
4071 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
4073 c
= string_char_and_length (p
, &len
);
4074 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, charpos
, it
->string
);
4079 struct text_pos pos
;
4081 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
4082 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
4085 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
4086 pos
= it
->current
.pos
;
4091 DEC_TEXT_POS (pos
, it
->multibyte_p
);
4094 if (it
->what
== IT_COMPOSITION
)
4096 /* For composition, we must check the position after
4098 pos
.charpos
+= it
->cmp_it
.nchars
;
4099 pos
.bytepos
+= it
->len
;
4102 INC_TEXT_POS (pos
, it
->multibyte_p
);
4109 /* With bidi iteration, the character before the current
4110 in the visual order cannot be found by simple
4111 iteration, because "reverse" reordering is not
4112 supported. Instead, we need to use the move_it_*
4113 family of functions. */
4114 /* Ignore face changes before the first visible
4115 character on this display line. */
4116 if (it
->current_x
<= it
->first_visible_x
)
4118 SAVE_IT (it_copy
, *it
, it_copy_data
);
4119 /* Implementation note: Since move_it_in_display_line
4120 works in the iterator geometry, and thinks the first
4121 character is always the leftmost, even in R2L lines,
4122 we don't need to distinguish between the R2L and L2R
4124 move_it_in_display_line (&it_copy
, ZV
,
4125 it_copy
.current_x
- 1, MOVE_TO_X
);
4126 pos
= it_copy
.current
.pos
;
4127 RESTORE_IT (it
, it
, it_copy_data
);
4131 /* Set charpos to the buffer position of the character
4132 that comes after IT's current position in the visual
4134 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
4138 bidi_move_to_visually_next (&it_copy
.bidi_it
);
4141 it_copy
.bidi_it
.charpos
, it_copy
.bidi_it
.bytepos
);
4144 eassert (BEGV
<= CHARPOS (pos
) && CHARPOS (pos
) <= ZV
);
4146 /* Determine face for CHARSET_ASCII, or unibyte. */
4147 face_id
= face_at_buffer_position (it
->w
,
4149 &next_check_charpos
,
4152 /* Correct the face for charsets different from ASCII. Do it
4153 for the multibyte case only. The face returned above is
4154 suitable for unibyte text if current_buffer is unibyte. */
4155 if (it
->multibyte_p
)
4157 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
4158 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
4159 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
4168 /***********************************************************************
4170 ***********************************************************************/
4172 /* Set up iterator IT from invisible properties at its current
4173 position. Called from handle_stop. */
4175 static enum prop_handled
4176 handle_invisible_prop (struct it
*it
)
4178 enum prop_handled handled
= HANDLED_NORMALLY
;
4182 if (STRINGP (it
->string
))
4184 Lisp_Object end_charpos
, limit
, charpos
;
4186 /* Get the value of the invisible text property at the
4187 current position. Value will be nil if there is no such
4189 charpos
= make_number (IT_STRING_CHARPOS (*it
));
4190 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
4191 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4193 if (invis_p
&& IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
4195 /* Record whether we have to display an ellipsis for the
4197 int display_ellipsis_p
= (invis_p
== 2);
4198 ptrdiff_t len
, endpos
;
4200 handled
= HANDLED_RECOMPUTE_PROPS
;
4202 /* Get the position at which the next visible text can be
4203 found in IT->string, if any. */
4204 endpos
= len
= SCHARS (it
->string
);
4205 XSETINT (limit
, len
);
4208 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
4210 if (INTEGERP (end_charpos
))
4212 endpos
= XFASTINT (end_charpos
);
4213 prop
= Fget_text_property (end_charpos
, Qinvisible
, it
->string
);
4214 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4216 display_ellipsis_p
= true;
4219 while (invis_p
&& endpos
< len
);
4221 if (display_ellipsis_p
)
4222 it
->ellipsis_p
= true;
4226 /* Text at END_CHARPOS is visible. Move IT there. */
4227 struct text_pos old
;
4230 old
= it
->current
.string_pos
;
4231 oldpos
= CHARPOS (old
);
4234 if (it
->bidi_it
.first_elt
4235 && it
->bidi_it
.charpos
< SCHARS (it
->string
))
4236 bidi_paragraph_init (it
->paragraph_embedding
,
4238 /* Bidi-iterate out of the invisible text. */
4241 bidi_move_to_visually_next (&it
->bidi_it
);
4243 while (oldpos
<= it
->bidi_it
.charpos
4244 && it
->bidi_it
.charpos
< endpos
);
4246 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4247 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4248 if (IT_CHARPOS (*it
) >= endpos
)
4249 it
->prev_stop
= endpos
;
4253 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
4254 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
4259 /* The rest of the string is invisible. If this is an
4260 overlay string, proceed with the next overlay string
4261 or whatever comes and return a character from there. */
4262 if (it
->current
.overlay_string_index
>= 0
4263 && !display_ellipsis_p
)
4265 next_overlay_string (it
);
4266 /* Don't check for overlay strings when we just
4267 finished processing them. */
4268 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
4272 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
4273 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
4280 ptrdiff_t newpos
, next_stop
, start_charpos
, tem
;
4281 Lisp_Object pos
, overlay
;
4283 /* First of all, is there invisible text at this position? */
4284 tem
= start_charpos
= IT_CHARPOS (*it
);
4285 pos
= make_number (tem
);
4286 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
4288 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4290 /* If we are on invisible text, skip over it. */
4291 if (invis_p
&& start_charpos
< it
->end_charpos
)
4293 /* Record whether we have to display an ellipsis for the
4295 int display_ellipsis_p
= invis_p
== 2;
4297 handled
= HANDLED_RECOMPUTE_PROPS
;
4299 /* Loop skipping over invisible text. The loop is left at
4300 ZV or with IT on the first char being visible again. */
4303 /* Try to skip some invisible text. Return value is the
4304 position reached which can be equal to where we start
4305 if there is nothing invisible there. This skips both
4306 over invisible text properties and overlays with
4307 invisible property. */
4308 newpos
= skip_invisible (tem
, &next_stop
, ZV
, it
->window
);
4310 /* If we skipped nothing at all we weren't at invisible
4311 text in the first place. If everything to the end of
4312 the buffer was skipped, end the loop. */
4313 if (newpos
== tem
|| newpos
>= ZV
)
4317 /* We skipped some characters but not necessarily
4318 all there are. Check if we ended up on visible
4319 text. Fget_char_property returns the property of
4320 the char before the given position, i.e. if we
4321 get invis_p = 0, this means that the char at
4322 newpos is visible. */
4323 pos
= make_number (newpos
);
4324 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
4325 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4328 /* If we ended up on invisible text, proceed to
4329 skip starting with next_stop. */
4333 /* If there are adjacent invisible texts, don't lose the
4334 second one's ellipsis. */
4336 display_ellipsis_p
= true;
4340 /* The position newpos is now either ZV or on visible text. */
4343 ptrdiff_t bpos
= CHAR_TO_BYTE (newpos
);
4345 = bpos
== ZV_BYTE
|| FETCH_BYTE (bpos
) == '\n';
4347 = newpos
<= BEGV
|| FETCH_BYTE (bpos
- 1) == '\n';
4349 /* If the invisible text ends on a newline or on a
4350 character after a newline, we can avoid the costly,
4351 character by character, bidi iteration to NEWPOS, and
4352 instead simply reseat the iterator there. That's
4353 because all bidi reordering information is tossed at
4354 the newline. This is a big win for modes that hide
4355 complete lines, like Outline, Org, etc. */
4356 if (on_newline
|| after_newline
)
4358 struct text_pos tpos
;
4359 bidi_dir_t pdir
= it
->bidi_it
.paragraph_dir
;
4361 SET_TEXT_POS (tpos
, newpos
, bpos
);
4362 reseat_1 (it
, tpos
, 0);
4363 /* If we reseat on a newline/ZV, we need to prep the
4364 bidi iterator for advancing to the next character
4365 after the newline/EOB, keeping the current paragraph
4366 direction (so that PRODUCE_GLYPHS does TRT wrt
4367 prepending/appending glyphs to a glyph row). */
4370 it
->bidi_it
.first_elt
= 0;
4371 it
->bidi_it
.paragraph_dir
= pdir
;
4372 it
->bidi_it
.ch
= (bpos
== ZV_BYTE
) ? -1 : '\n';
4373 it
->bidi_it
.nchars
= 1;
4374 it
->bidi_it
.ch_len
= 1;
4377 else /* Must use the slow method. */
4379 /* With bidi iteration, the region of invisible text
4380 could start and/or end in the middle of a
4381 non-base embedding level. Therefore, we need to
4382 skip invisible text using the bidi iterator,
4383 starting at IT's current position, until we find
4384 ourselves outside of the invisible text.
4385 Skipping invisible text _after_ bidi iteration
4386 avoids affecting the visual order of the
4387 displayed text when invisible properties are
4388 added or removed. */
4389 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< ZV
)
4391 /* If we were `reseat'ed to a new paragraph,
4392 determine the paragraph base direction. We
4393 need to do it now because
4394 next_element_from_buffer may not have a
4395 chance to do it, if we are going to skip any
4396 text at the beginning, which resets the
4398 bidi_paragraph_init (it
->paragraph_embedding
,
4403 bidi_move_to_visually_next (&it
->bidi_it
);
4405 while (it
->stop_charpos
<= it
->bidi_it
.charpos
4406 && it
->bidi_it
.charpos
< newpos
);
4407 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4408 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4409 /* If we overstepped NEWPOS, record its position in
4410 the iterator, so that we skip invisible text if
4411 later the bidi iteration lands us in the
4412 invisible region again. */
4413 if (IT_CHARPOS (*it
) >= newpos
)
4414 it
->prev_stop
= newpos
;
4419 IT_CHARPOS (*it
) = newpos
;
4420 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
4423 /* If there are before-strings at the start of invisible
4424 text, and the text is invisible because of a text
4425 property, arrange to show before-strings because 20.x did
4426 it that way. (If the text is invisible because of an
4427 overlay property instead of a text property, this is
4428 already handled in the overlay code.) */
4430 && get_overlay_strings (it
, it
->stop_charpos
))
4432 handled
= HANDLED_RECOMPUTE_PROPS
;
4433 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
4435 else if (display_ellipsis_p
)
4437 /* Make sure that the glyphs of the ellipsis will get
4438 correct `charpos' values. If we would not update
4439 it->position here, the glyphs would belong to the
4440 last visible character _before_ the invisible
4441 text, which confuses `set_cursor_from_row'.
4443 We use the last invisible position instead of the
4444 first because this way the cursor is always drawn on
4445 the first "." of the ellipsis, whenever PT is inside
4446 the invisible text. Otherwise the cursor would be
4447 placed _after_ the ellipsis when the point is after the
4448 first invisible character. */
4449 if (!STRINGP (it
->object
))
4451 it
->position
.charpos
= newpos
- 1;
4452 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
4454 it
->ellipsis_p
= true;
4455 /* Let the ellipsis display before
4456 considering any properties of the following char.
4457 Fixes jasonr@gnu.org 01 Oct 07 bug. */
4458 handled
= HANDLED_RETURN
;
4467 /* Make iterator IT return `...' next.
4468 Replaces LEN characters from buffer. */
4471 setup_for_ellipsis (struct it
*it
, int len
)
4473 /* Use the display table definition for `...'. Invalid glyphs
4474 will be handled by the method returning elements from dpvec. */
4475 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
4477 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
4478 it
->dpvec
= v
->contents
;
4479 it
->dpend
= v
->contents
+ v
->header
.size
;
4483 /* Default `...'. */
4484 it
->dpvec
= default_invis_vector
;
4485 it
->dpend
= default_invis_vector
+ 3;
4488 it
->dpvec_char_len
= len
;
4489 it
->current
.dpvec_index
= 0;
4490 it
->dpvec_face_id
= -1;
4492 /* Remember the current face id in case glyphs specify faces.
4493 IT's face is restored in set_iterator_to_next.
4494 saved_face_id was set to preceding char's face in handle_stop. */
4495 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
4496 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
4498 it
->method
= GET_FROM_DISPLAY_VECTOR
;
4499 it
->ellipsis_p
= true;
4504 /***********************************************************************
4506 ***********************************************************************/
4508 /* Set up iterator IT from `display' property at its current position.
4509 Called from handle_stop.
4510 We return HANDLED_RETURN if some part of the display property
4511 overrides the display of the buffer text itself.
4512 Otherwise we return HANDLED_NORMALLY. */
4514 static enum prop_handled
4515 handle_display_prop (struct it
*it
)
4517 Lisp_Object propval
, object
, overlay
;
4518 struct text_pos
*position
;
4520 /* Nonzero if some property replaces the display of the text itself. */
4521 int display_replaced_p
= 0;
4523 if (STRINGP (it
->string
))
4525 object
= it
->string
;
4526 position
= &it
->current
.string_pos
;
4527 bufpos
= CHARPOS (it
->current
.pos
);
4531 XSETWINDOW (object
, it
->w
);
4532 position
= &it
->current
.pos
;
4533 bufpos
= CHARPOS (*position
);
4536 /* Reset those iterator values set from display property values. */
4537 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
4538 it
->space_width
= Qnil
;
4539 it
->font_height
= Qnil
;
4542 /* We don't support recursive `display' properties, i.e. string
4543 values that have a string `display' property, that have a string
4544 `display' property etc. */
4545 if (!it
->string_from_display_prop_p
)
4546 it
->area
= TEXT_AREA
;
4548 propval
= get_char_property_and_overlay (make_number (position
->charpos
),
4549 Qdisplay
, object
, &overlay
);
4551 return HANDLED_NORMALLY
;
4552 /* Now OVERLAY is the overlay that gave us this property, or nil
4553 if it was a text property. */
4555 if (!STRINGP (it
->string
))
4556 object
= it
->w
->contents
;
4558 display_replaced_p
= handle_display_spec (it
, propval
, object
, overlay
,
4560 FRAME_WINDOW_P (it
->f
));
4562 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
4565 /* Subroutine of handle_display_prop. Returns non-zero if the display
4566 specification in SPEC is a replacing specification, i.e. it would
4567 replace the text covered by `display' property with something else,
4568 such as an image or a display string. If SPEC includes any kind or
4569 `(space ...) specification, the value is 2; this is used by
4570 compute_display_string_pos, which see.
4572 See handle_single_display_spec for documentation of arguments.
4573 frame_window_p is non-zero if the window being redisplayed is on a
4574 GUI frame; this argument is used only if IT is NULL, see below.
4576 IT can be NULL, if this is called by the bidi reordering code
4577 through compute_display_string_pos, which see. In that case, this
4578 function only examines SPEC, but does not otherwise "handle" it, in
4579 the sense that it doesn't set up members of IT from the display
4582 handle_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4583 Lisp_Object overlay
, struct text_pos
*position
,
4584 ptrdiff_t bufpos
, int frame_window_p
)
4586 int replacing_p
= 0;
4590 /* Simple specifications. */
4591 && !EQ (XCAR (spec
), Qimage
)
4592 && !EQ (XCAR (spec
), Qspace
)
4593 && !EQ (XCAR (spec
), Qwhen
)
4594 && !EQ (XCAR (spec
), Qslice
)
4595 && !EQ (XCAR (spec
), Qspace_width
)
4596 && !EQ (XCAR (spec
), Qheight
)
4597 && !EQ (XCAR (spec
), Qraise
)
4598 /* Marginal area specifications. */
4599 && !(CONSP (XCAR (spec
)) && EQ (XCAR (XCAR (spec
)), Qmargin
))
4600 && !EQ (XCAR (spec
), Qleft_fringe
)
4601 && !EQ (XCAR (spec
), Qright_fringe
)
4602 && !NILP (XCAR (spec
)))
4604 for (; CONSP (spec
); spec
= XCDR (spec
))
4606 if ((rv
= handle_single_display_spec (it
, XCAR (spec
), object
,
4607 overlay
, position
, bufpos
,
4608 replacing_p
, frame_window_p
)))
4611 /* If some text in a string is replaced, `position' no
4612 longer points to the position of `object'. */
4613 if (!it
|| STRINGP (object
))
4618 else if (VECTORP (spec
))
4621 for (i
= 0; i
< ASIZE (spec
); ++i
)
4622 if ((rv
= handle_single_display_spec (it
, AREF (spec
, i
), object
,
4623 overlay
, position
, bufpos
,
4624 replacing_p
, frame_window_p
)))
4627 /* If some text in a string is replaced, `position' no
4628 longer points to the position of `object'. */
4629 if (!it
|| STRINGP (object
))
4635 if ((rv
= handle_single_display_spec (it
, spec
, object
, overlay
,
4636 position
, bufpos
, 0,
4644 /* Value is the position of the end of the `display' property starting
4645 at START_POS in OBJECT. */
4647 static struct text_pos
4648 display_prop_end (struct it
*it
, Lisp_Object object
, struct text_pos start_pos
)
4651 struct text_pos end_pos
;
4653 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
4654 Qdisplay
, object
, Qnil
);
4655 CHARPOS (end_pos
) = XFASTINT (end
);
4656 if (STRINGP (object
))
4657 compute_string_pos (&end_pos
, start_pos
, it
->string
);
4659 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
4665 /* Set up IT from a single `display' property specification SPEC. OBJECT
4666 is the object in which the `display' property was found. *POSITION
4667 is the position in OBJECT at which the `display' property was found.
4668 BUFPOS is the buffer position of OBJECT (different from POSITION if
4669 OBJECT is not a buffer). DISPLAY_REPLACED_P non-zero means that we
4670 previously saw a display specification which already replaced text
4671 display with something else, for example an image; we ignore such
4672 properties after the first one has been processed.
4674 OVERLAY is the overlay this `display' property came from,
4675 or nil if it was a text property.
4677 If SPEC is a `space' or `image' specification, and in some other
4678 cases too, set *POSITION to the position where the `display'
4681 If IT is NULL, only examine the property specification in SPEC, but
4682 don't set up IT. In that case, FRAME_WINDOW_P non-zero means SPEC
4683 is intended to be displayed in a window on a GUI frame.
4685 Value is non-zero if something was found which replaces the display
4686 of buffer or string text. */
4689 handle_single_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4690 Lisp_Object overlay
, struct text_pos
*position
,
4691 ptrdiff_t bufpos
, int display_replaced_p
,
4695 Lisp_Object location
, value
;
4696 struct text_pos start_pos
= *position
;
4699 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
4700 If the result is non-nil, use VALUE instead of SPEC. */
4702 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4711 if (!NILP (form
) && !EQ (form
, Qt
))
4713 ptrdiff_t count
= SPECPDL_INDEX ();
4714 struct gcpro gcpro1
;
4716 /* Bind `object' to the object having the `display' property, a
4717 buffer or string. Bind `position' to the position in the
4718 object where the property was found, and `buffer-position'
4719 to the current position in the buffer. */
4722 XSETBUFFER (object
, current_buffer
);
4723 specbind (Qobject
, object
);
4724 specbind (Qposition
, make_number (CHARPOS (*position
)));
4725 specbind (Qbuffer_position
, make_number (bufpos
));
4727 form
= safe_eval (form
);
4729 unbind_to (count
, Qnil
);
4735 /* Handle `(height HEIGHT)' specifications. */
4737 && EQ (XCAR (spec
), Qheight
)
4738 && CONSP (XCDR (spec
)))
4742 if (!FRAME_WINDOW_P (it
->f
))
4745 it
->font_height
= XCAR (XCDR (spec
));
4746 if (!NILP (it
->font_height
))
4748 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4749 int new_height
= -1;
4751 if (CONSP (it
->font_height
)
4752 && (EQ (XCAR (it
->font_height
), Qplus
)
4753 || EQ (XCAR (it
->font_height
), Qminus
))
4754 && CONSP (XCDR (it
->font_height
))
4755 && RANGED_INTEGERP (0, XCAR (XCDR (it
->font_height
)), INT_MAX
))
4757 /* `(+ N)' or `(- N)' where N is an integer. */
4758 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4759 if (EQ (XCAR (it
->font_height
), Qplus
))
4761 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4763 else if (FUNCTIONP (it
->font_height
))
4765 /* Call function with current height as argument.
4766 Value is the new height. */
4768 height
= safe_call1 (it
->font_height
,
4769 face
->lface
[LFACE_HEIGHT_INDEX
]);
4770 if (NUMBERP (height
))
4771 new_height
= XFLOATINT (height
);
4773 else if (NUMBERP (it
->font_height
))
4775 /* Value is a multiple of the canonical char height. */
4778 f
= FACE_FROM_ID (it
->f
,
4779 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4780 new_height
= (XFLOATINT (it
->font_height
)
4781 * XINT (f
->lface
[LFACE_HEIGHT_INDEX
]));
4785 /* Evaluate IT->font_height with `height' bound to the
4786 current specified height to get the new height. */
4787 ptrdiff_t count
= SPECPDL_INDEX ();
4789 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4790 value
= safe_eval (it
->font_height
);
4791 unbind_to (count
, Qnil
);
4793 if (NUMBERP (value
))
4794 new_height
= XFLOATINT (value
);
4798 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4805 /* Handle `(space-width WIDTH)'. */
4807 && EQ (XCAR (spec
), Qspace_width
)
4808 && CONSP (XCDR (spec
)))
4812 if (!FRAME_WINDOW_P (it
->f
))
4815 value
= XCAR (XCDR (spec
));
4816 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4817 it
->space_width
= value
;
4823 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4825 && EQ (XCAR (spec
), Qslice
))
4831 if (!FRAME_WINDOW_P (it
->f
))
4834 if (tem
= XCDR (spec
), CONSP (tem
))
4836 it
->slice
.x
= XCAR (tem
);
4837 if (tem
= XCDR (tem
), CONSP (tem
))
4839 it
->slice
.y
= XCAR (tem
);
4840 if (tem
= XCDR (tem
), CONSP (tem
))
4842 it
->slice
.width
= XCAR (tem
);
4843 if (tem
= XCDR (tem
), CONSP (tem
))
4844 it
->slice
.height
= XCAR (tem
);
4853 /* Handle `(raise FACTOR)'. */
4855 && EQ (XCAR (spec
), Qraise
)
4856 && CONSP (XCDR (spec
)))
4860 if (!FRAME_WINDOW_P (it
->f
))
4863 #ifdef HAVE_WINDOW_SYSTEM
4864 value
= XCAR (XCDR (spec
));
4865 if (NUMBERP (value
))
4867 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4868 it
->voffset
= - (XFLOATINT (value
)
4869 * (FONT_HEIGHT (face
->font
)));
4871 #endif /* HAVE_WINDOW_SYSTEM */
4877 /* Don't handle the other kinds of display specifications
4878 inside a string that we got from a `display' property. */
4879 if (it
&& it
->string_from_display_prop_p
)
4882 /* Characters having this form of property are not displayed, so
4883 we have to find the end of the property. */
4886 start_pos
= *position
;
4887 *position
= display_prop_end (it
, object
, start_pos
);
4891 /* Stop the scan at that end position--we assume that all
4892 text properties change there. */
4894 it
->stop_charpos
= position
->charpos
;
4896 /* Handle `(left-fringe BITMAP [FACE])'
4897 and `(right-fringe BITMAP [FACE])'. */
4899 && (EQ (XCAR (spec
), Qleft_fringe
)
4900 || EQ (XCAR (spec
), Qright_fringe
))
4901 && CONSP (XCDR (spec
)))
4907 if (!FRAME_WINDOW_P (it
->f
))
4908 /* If we return here, POSITION has been advanced
4909 across the text with this property. */
4911 /* Synchronize the bidi iterator with POSITION. This is
4912 needed because we are not going to push the iterator
4913 on behalf of this display property, so there will be
4914 no pop_it call to do this synchronization for us. */
4917 it
->position
= *position
;
4918 iterate_out_of_display_property (it
);
4919 *position
= it
->position
;
4924 else if (!frame_window_p
)
4927 #ifdef HAVE_WINDOW_SYSTEM
4928 value
= XCAR (XCDR (spec
));
4929 if (!SYMBOLP (value
)
4930 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4931 /* If we return here, POSITION has been advanced
4932 across the text with this property. */
4934 if (it
&& it
->bidi_p
)
4936 it
->position
= *position
;
4937 iterate_out_of_display_property (it
);
4938 *position
= it
->position
;
4945 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);;
4947 if (CONSP (XCDR (XCDR (spec
))))
4949 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4950 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4956 /* Save current settings of IT so that we can restore them
4957 when we are finished with the glyph property value. */
4958 push_it (it
, position
);
4960 it
->area
= TEXT_AREA
;
4961 it
->what
= IT_IMAGE
;
4962 it
->image_id
= -1; /* no image */
4963 it
->position
= start_pos
;
4964 it
->object
= NILP (object
) ? it
->w
->contents
: object
;
4965 it
->method
= GET_FROM_IMAGE
;
4966 it
->from_overlay
= Qnil
;
4967 it
->face_id
= face_id
;
4968 it
->from_disp_prop_p
= true;
4970 /* Say that we haven't consumed the characters with
4971 `display' property yet. The call to pop_it in
4972 set_iterator_to_next will clean this up. */
4973 *position
= start_pos
;
4975 if (EQ (XCAR (spec
), Qleft_fringe
))
4977 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4978 it
->left_user_fringe_face_id
= face_id
;
4982 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4983 it
->right_user_fringe_face_id
= face_id
;
4986 #endif /* HAVE_WINDOW_SYSTEM */
4990 /* Prepare to handle `((margin left-margin) ...)',
4991 `((margin right-margin) ...)' and `((margin nil) ...)'
4992 prefixes for display specifications. */
4993 location
= Qunbound
;
4994 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4998 value
= XCDR (spec
);
5000 value
= XCAR (value
);
5003 if (EQ (XCAR (tem
), Qmargin
)
5004 && (tem
= XCDR (tem
),
5005 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
5007 || EQ (tem
, Qleft_margin
)
5008 || EQ (tem
, Qright_margin
))))
5012 if (EQ (location
, Qunbound
))
5018 /* After this point, VALUE is the property after any
5019 margin prefix has been stripped. It must be a string,
5020 an image specification, or `(space ...)'.
5022 LOCATION specifies where to display: `left-margin',
5023 `right-margin' or nil. */
5025 valid_p
= (STRINGP (value
)
5026 #ifdef HAVE_WINDOW_SYSTEM
5027 || ((it
? FRAME_WINDOW_P (it
->f
) : frame_window_p
)
5028 && valid_image_p (value
))
5029 #endif /* not HAVE_WINDOW_SYSTEM */
5030 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
5032 if (valid_p
&& !display_replaced_p
)
5038 /* Callers need to know whether the display spec is any kind
5039 of `(space ...)' spec that is about to affect text-area
5041 if (CONSP (value
) && EQ (XCAR (value
), Qspace
) && NILP (location
))
5046 /* Save current settings of IT so that we can restore them
5047 when we are finished with the glyph property value. */
5048 push_it (it
, position
);
5049 it
->from_overlay
= overlay
;
5050 it
->from_disp_prop_p
= true;
5052 if (NILP (location
))
5053 it
->area
= TEXT_AREA
;
5054 else if (EQ (location
, Qleft_margin
))
5055 it
->area
= LEFT_MARGIN_AREA
;
5057 it
->area
= RIGHT_MARGIN_AREA
;
5059 if (STRINGP (value
))
5062 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5063 it
->current
.overlay_string_index
= -1;
5064 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5065 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
5066 it
->method
= GET_FROM_STRING
;
5067 it
->stop_charpos
= 0;
5069 it
->base_level_stop
= 0;
5070 it
->string_from_display_prop_p
= true;
5071 /* Say that we haven't consumed the characters with
5072 `display' property yet. The call to pop_it in
5073 set_iterator_to_next will clean this up. */
5074 if (BUFFERP (object
))
5075 *position
= start_pos
;
5077 /* Force paragraph direction to be that of the parent
5078 object. If the parent object's paragraph direction is
5079 not yet determined, default to L2R. */
5080 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
5081 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5083 it
->paragraph_embedding
= L2R
;
5085 /* Set up the bidi iterator for this display string. */
5088 it
->bidi_it
.string
.lstring
= it
->string
;
5089 it
->bidi_it
.string
.s
= NULL
;
5090 it
->bidi_it
.string
.schars
= it
->end_charpos
;
5091 it
->bidi_it
.string
.bufpos
= bufpos
;
5092 it
->bidi_it
.string
.from_disp_str
= 1;
5093 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5094 it
->bidi_it
.w
= it
->w
;
5095 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5098 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
5100 it
->method
= GET_FROM_STRETCH
;
5102 *position
= it
->position
= start_pos
;
5103 retval
= 1 + (it
->area
== TEXT_AREA
);
5105 #ifdef HAVE_WINDOW_SYSTEM
5108 it
->what
= IT_IMAGE
;
5109 it
->image_id
= lookup_image (it
->f
, value
);
5110 it
->position
= start_pos
;
5111 it
->object
= NILP (object
) ? it
->w
->contents
: object
;
5112 it
->method
= GET_FROM_IMAGE
;
5114 /* Say that we haven't consumed the characters with
5115 `display' property yet. The call to pop_it in
5116 set_iterator_to_next will clean this up. */
5117 *position
= start_pos
;
5119 #endif /* HAVE_WINDOW_SYSTEM */
5124 /* Invalid property or property not supported. Restore
5125 POSITION to what it was before. */
5126 *position
= start_pos
;
5130 /* Check if PROP is a display property value whose text should be
5131 treated as intangible. OVERLAY is the overlay from which PROP
5132 came, or nil if it came from a text property. CHARPOS and BYTEPOS
5133 specify the buffer position covered by PROP. */
5136 display_prop_intangible_p (Lisp_Object prop
, Lisp_Object overlay
,
5137 ptrdiff_t charpos
, ptrdiff_t bytepos
)
5139 int frame_window_p
= FRAME_WINDOW_P (XFRAME (selected_frame
));
5140 struct text_pos position
;
5142 SET_TEXT_POS (position
, charpos
, bytepos
);
5143 return handle_display_spec (NULL
, prop
, Qnil
, overlay
,
5144 &position
, charpos
, frame_window_p
);
5148 /* Return 1 if PROP is a display sub-property value containing STRING.
5150 Implementation note: this and the following function are really
5151 special cases of handle_display_spec and
5152 handle_single_display_spec, and should ideally use the same code.
5153 Until they do, these two pairs must be consistent and must be
5154 modified in sync. */
5157 single_display_spec_string_p (Lisp_Object prop
, Lisp_Object string
)
5159 if (EQ (string
, prop
))
5162 /* Skip over `when FORM'. */
5163 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
5168 /* Actually, the condition following `when' should be eval'ed,
5169 like handle_single_display_spec does, and we should return
5170 zero if it evaluates to nil. However, this function is
5171 called only when the buffer was already displayed and some
5172 glyph in the glyph matrix was found to come from a display
5173 string. Therefore, the condition was already evaluated, and
5174 the result was non-nil, otherwise the display string wouldn't
5175 have been displayed and we would have never been called for
5176 this property. Thus, we can skip the evaluation and assume
5177 its result is non-nil. */
5182 /* Skip over `margin LOCATION'. */
5183 if (EQ (XCAR (prop
), Qmargin
))
5194 return EQ (prop
, string
) || (CONSP (prop
) && EQ (XCAR (prop
), string
));
5198 /* Return 1 if STRING appears in the `display' property PROP. */
5201 display_prop_string_p (Lisp_Object prop
, Lisp_Object string
)
5204 && !EQ (XCAR (prop
), Qwhen
)
5205 && !(CONSP (XCAR (prop
)) && EQ (Qmargin
, XCAR (XCAR (prop
)))))
5207 /* A list of sub-properties. */
5208 while (CONSP (prop
))
5210 if (single_display_spec_string_p (XCAR (prop
), string
))
5215 else if (VECTORP (prop
))
5217 /* A vector of sub-properties. */
5219 for (i
= 0; i
< ASIZE (prop
); ++i
)
5220 if (single_display_spec_string_p (AREF (prop
, i
), string
))
5224 return single_display_spec_string_p (prop
, string
);
5229 /* Look for STRING in overlays and text properties in the current
5230 buffer, between character positions FROM and TO (excluding TO).
5231 BACK_P non-zero means look back (in this case, TO is supposed to be
5233 Value is the first character position where STRING was found, or
5234 zero if it wasn't found before hitting TO.
5236 This function may only use code that doesn't eval because it is
5237 called asynchronously from note_mouse_highlight. */
5240 string_buffer_position_lim (Lisp_Object string
,
5241 ptrdiff_t from
, ptrdiff_t to
, int back_p
)
5243 Lisp_Object limit
, prop
, pos
;
5246 pos
= make_number (max (from
, BEGV
));
5248 if (!back_p
) /* looking forward */
5250 limit
= make_number (min (to
, ZV
));
5251 while (!found
&& !EQ (pos
, limit
))
5253 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5254 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5257 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
,
5261 else /* looking back */
5263 limit
= make_number (max (to
, BEGV
));
5264 while (!found
&& !EQ (pos
, limit
))
5266 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5267 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5270 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
5275 return found
? XINT (pos
) : 0;
5278 /* Determine which buffer position in current buffer STRING comes from.
5279 AROUND_CHARPOS is an approximate position where it could come from.
5280 Value is the buffer position or 0 if it couldn't be determined.
5282 This function is necessary because we don't record buffer positions
5283 in glyphs generated from strings (to keep struct glyph small).
5284 This function may only use code that doesn't eval because it is
5285 called asynchronously from note_mouse_highlight. */
5288 string_buffer_position (Lisp_Object string
, ptrdiff_t around_charpos
)
5290 const int MAX_DISTANCE
= 1000;
5291 ptrdiff_t found
= string_buffer_position_lim (string
, around_charpos
,
5292 around_charpos
+ MAX_DISTANCE
,
5296 found
= string_buffer_position_lim (string
, around_charpos
,
5297 around_charpos
- MAX_DISTANCE
, 1);
5303 /***********************************************************************
5304 `composition' property
5305 ***********************************************************************/
5307 /* Set up iterator IT from `composition' property at its current
5308 position. Called from handle_stop. */
5310 static enum prop_handled
5311 handle_composition_prop (struct it
*it
)
5313 Lisp_Object prop
, string
;
5314 ptrdiff_t pos
, pos_byte
, start
, end
;
5316 if (STRINGP (it
->string
))
5320 pos
= IT_STRING_CHARPOS (*it
);
5321 pos_byte
= IT_STRING_BYTEPOS (*it
);
5322 string
= it
->string
;
5323 s
= SDATA (string
) + pos_byte
;
5324 it
->c
= STRING_CHAR (s
);
5328 pos
= IT_CHARPOS (*it
);
5329 pos_byte
= IT_BYTEPOS (*it
);
5331 it
->c
= FETCH_CHAR (pos_byte
);
5334 /* If there's a valid composition and point is not inside of the
5335 composition (in the case that the composition is from the current
5336 buffer), draw a glyph composed from the composition components. */
5337 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
5338 && composition_valid_p (start
, end
, prop
)
5339 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
5342 /* As we can't handle this situation (perhaps font-lock added
5343 a new composition), we just return here hoping that next
5344 redisplay will detect this composition much earlier. */
5345 return HANDLED_NORMALLY
;
5348 if (STRINGP (it
->string
))
5349 pos_byte
= string_char_to_byte (it
->string
, start
);
5351 pos_byte
= CHAR_TO_BYTE (start
);
5353 it
->cmp_it
.id
= get_composition_id (start
, pos_byte
, end
- start
,
5356 if (it
->cmp_it
.id
>= 0)
5359 it
->cmp_it
.nchars
= COMPOSITION_LENGTH (prop
);
5360 it
->cmp_it
.nglyphs
= -1;
5364 return HANDLED_NORMALLY
;
5369 /***********************************************************************
5371 ***********************************************************************/
5373 /* The following structure is used to record overlay strings for
5374 later sorting in load_overlay_strings. */
5376 struct overlay_entry
5378 Lisp_Object overlay
;
5385 /* Set up iterator IT from overlay strings at its current position.
5386 Called from handle_stop. */
5388 static enum prop_handled
5389 handle_overlay_change (struct it
*it
)
5391 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
5392 return HANDLED_RECOMPUTE_PROPS
;
5394 return HANDLED_NORMALLY
;
5398 /* Set up the next overlay string for delivery by IT, if there is an
5399 overlay string to deliver. Called by set_iterator_to_next when the
5400 end of the current overlay string is reached. If there are more
5401 overlay strings to display, IT->string and
5402 IT->current.overlay_string_index are set appropriately here.
5403 Otherwise IT->string is set to nil. */
5406 next_overlay_string (struct it
*it
)
5408 ++it
->current
.overlay_string_index
;
5409 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
5411 /* No more overlay strings. Restore IT's settings to what
5412 they were before overlay strings were processed, and
5413 continue to deliver from current_buffer. */
5415 it
->ellipsis_p
= (it
->stack
[it
->sp
- 1].display_ellipsis_p
!= 0);
5418 || (NILP (it
->string
)
5419 && it
->method
== GET_FROM_BUFFER
5420 && it
->stop_charpos
>= BEGV
5421 && it
->stop_charpos
<= it
->end_charpos
));
5422 it
->current
.overlay_string_index
= -1;
5423 it
->n_overlay_strings
= 0;
5424 it
->overlay_strings_charpos
= -1;
5425 /* If there's an empty display string on the stack, pop the
5426 stack, to resync the bidi iterator with IT's position. Such
5427 empty strings are pushed onto the stack in
5428 get_overlay_strings_1. */
5429 if (it
->sp
> 0 && STRINGP (it
->string
) && !SCHARS (it
->string
))
5432 /* If we're at the end of the buffer, record that we have
5433 processed the overlay strings there already, so that
5434 next_element_from_buffer doesn't try it again. */
5435 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
5436 it
->overlay_strings_at_end_processed_p
= true;
5440 /* There are more overlay strings to process. If
5441 IT->current.overlay_string_index has advanced to a position
5442 where we must load IT->overlay_strings with more strings, do
5443 it. We must load at the IT->overlay_strings_charpos where
5444 IT->n_overlay_strings was originally computed; when invisible
5445 text is present, this might not be IT_CHARPOS (Bug#7016). */
5446 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
5448 if (it
->current
.overlay_string_index
&& i
== 0)
5449 load_overlay_strings (it
, it
->overlay_strings_charpos
);
5451 /* Initialize IT to deliver display elements from the overlay
5453 it
->string
= it
->overlay_strings
[i
];
5454 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5455 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
5456 it
->method
= GET_FROM_STRING
;
5457 it
->stop_charpos
= 0;
5458 it
->end_charpos
= SCHARS (it
->string
);
5459 if (it
->cmp_it
.stop_pos
>= 0)
5460 it
->cmp_it
.stop_pos
= 0;
5462 it
->base_level_stop
= 0;
5464 /* Set up the bidi iterator for this overlay string. */
5467 it
->bidi_it
.string
.lstring
= it
->string
;
5468 it
->bidi_it
.string
.s
= NULL
;
5469 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5470 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
5471 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5472 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5473 it
->bidi_it
.w
= it
->w
;
5474 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5482 /* Compare two overlay_entry structures E1 and E2. Used as a
5483 comparison function for qsort in load_overlay_strings. Overlay
5484 strings for the same position are sorted so that
5486 1. All after-strings come in front of before-strings, except
5487 when they come from the same overlay.
5489 2. Within after-strings, strings are sorted so that overlay strings
5490 from overlays with higher priorities come first.
5492 2. Within before-strings, strings are sorted so that overlay
5493 strings from overlays with higher priorities come last.
5495 Value is analogous to strcmp. */
5499 compare_overlay_entries (const void *e1
, const void *e2
)
5501 struct overlay_entry
const *entry1
= e1
;
5502 struct overlay_entry
const *entry2
= e2
;
5505 if (entry1
->after_string_p
!= entry2
->after_string_p
)
5507 /* Let after-strings appear in front of before-strings if
5508 they come from different overlays. */
5509 if (EQ (entry1
->overlay
, entry2
->overlay
))
5510 result
= entry1
->after_string_p
? 1 : -1;
5512 result
= entry1
->after_string_p
? -1 : 1;
5514 else if (entry1
->priority
!= entry2
->priority
)
5516 if (entry1
->after_string_p
)
5517 /* After-strings sorted in order of decreasing priority. */
5518 result
= entry2
->priority
< entry1
->priority
? -1 : 1;
5520 /* Before-strings sorted in order of increasing priority. */
5521 result
= entry1
->priority
< entry2
->priority
? -1 : 1;
5530 /* Load the vector IT->overlay_strings with overlay strings from IT's
5531 current buffer position, or from CHARPOS if that is > 0. Set
5532 IT->n_overlays to the total number of overlay strings found.
5534 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
5535 a time. On entry into load_overlay_strings,
5536 IT->current.overlay_string_index gives the number of overlay
5537 strings that have already been loaded by previous calls to this
5540 IT->add_overlay_start contains an additional overlay start
5541 position to consider for taking overlay strings from, if non-zero.
5542 This position comes into play when the overlay has an `invisible'
5543 property, and both before and after-strings. When we've skipped to
5544 the end of the overlay, because of its `invisible' property, we
5545 nevertheless want its before-string to appear.
5546 IT->add_overlay_start will contain the overlay start position
5549 Overlay strings are sorted so that after-string strings come in
5550 front of before-string strings. Within before and after-strings,
5551 strings are sorted by overlay priority. See also function
5552 compare_overlay_entries. */
5555 load_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5557 Lisp_Object overlay
, window
, str
, invisible
;
5558 struct Lisp_Overlay
*ov
;
5559 ptrdiff_t start
, end
;
5560 ptrdiff_t size
= 20;
5561 ptrdiff_t n
= 0, i
, j
;
5563 struct overlay_entry
*entries
= alloca (size
* sizeof *entries
);
5567 charpos
= IT_CHARPOS (*it
);
5569 /* Append the overlay string STRING of overlay OVERLAY to vector
5570 `entries' which has size `size' and currently contains `n'
5571 elements. AFTER_P non-zero means STRING is an after-string of
5573 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
5576 Lisp_Object priority; \
5580 struct overlay_entry *old = entries; \
5581 SAFE_NALLOCA (entries, 2, size); \
5582 memcpy (entries, old, size * sizeof *entries); \
5586 entries[n].string = (STRING); \
5587 entries[n].overlay = (OVERLAY); \
5588 priority = Foverlay_get ((OVERLAY), Qpriority); \
5589 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
5590 entries[n].after_string_p = (AFTER_P); \
5595 /* Process overlay before the overlay center. */
5596 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
5598 XSETMISC (overlay
, ov
);
5599 eassert (OVERLAYP (overlay
));
5600 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5601 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5606 /* Skip this overlay if it doesn't start or end at IT's current
5608 if (end
!= charpos
&& start
!= charpos
)
5611 /* Skip this overlay if it doesn't apply to IT->w. */
5612 window
= Foverlay_get (overlay
, Qwindow
);
5613 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5616 /* If the text ``under'' the overlay is invisible, both before-
5617 and after-strings from this overlay are visible; start and
5618 end position are indistinguishable. */
5619 invisible
= Foverlay_get (overlay
, Qinvisible
);
5620 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5622 /* If overlay has a non-empty before-string, record it. */
5623 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5624 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5626 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5628 /* If overlay has a non-empty after-string, record it. */
5629 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5630 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5632 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5635 /* Process overlays after the overlay center. */
5636 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
5638 XSETMISC (overlay
, ov
);
5639 eassert (OVERLAYP (overlay
));
5640 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5641 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5643 if (start
> charpos
)
5646 /* Skip this overlay if it doesn't start or end at IT's current
5648 if (end
!= charpos
&& start
!= charpos
)
5651 /* Skip this overlay if it doesn't apply to IT->w. */
5652 window
= Foverlay_get (overlay
, Qwindow
);
5653 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5656 /* If the text ``under'' the overlay is invisible, it has a zero
5657 dimension, and both before- and after-strings apply. */
5658 invisible
= Foverlay_get (overlay
, Qinvisible
);
5659 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5661 /* If overlay has a non-empty before-string, record it. */
5662 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5663 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5665 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5667 /* If overlay has a non-empty after-string, record it. */
5668 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5669 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5671 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5674 #undef RECORD_OVERLAY_STRING
5678 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
5680 /* Record number of overlay strings, and where we computed it. */
5681 it
->n_overlay_strings
= n
;
5682 it
->overlay_strings_charpos
= charpos
;
5684 /* IT->current.overlay_string_index is the number of overlay strings
5685 that have already been consumed by IT. Copy some of the
5686 remaining overlay strings to IT->overlay_strings. */
5688 j
= it
->current
.overlay_string_index
;
5689 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
5691 it
->overlay_strings
[i
] = entries
[j
].string
;
5692 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
5700 /* Get the first chunk of overlay strings at IT's current buffer
5701 position, or at CHARPOS if that is > 0. Value is non-zero if at
5702 least one overlay string was found. */
5705 get_overlay_strings_1 (struct it
*it
, ptrdiff_t charpos
, int compute_stop_p
)
5707 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5708 process. This fills IT->overlay_strings with strings, and sets
5709 IT->n_overlay_strings to the total number of strings to process.
5710 IT->pos.overlay_string_index has to be set temporarily to zero
5711 because load_overlay_strings needs this; it must be set to -1
5712 when no overlay strings are found because a zero value would
5713 indicate a position in the first overlay string. */
5714 it
->current
.overlay_string_index
= 0;
5715 load_overlay_strings (it
, charpos
);
5717 /* If we found overlay strings, set up IT to deliver display
5718 elements from the first one. Otherwise set up IT to deliver
5719 from current_buffer. */
5720 if (it
->n_overlay_strings
)
5722 /* Make sure we know settings in current_buffer, so that we can
5723 restore meaningful values when we're done with the overlay
5726 compute_stop_pos (it
);
5727 eassert (it
->face_id
>= 0);
5729 /* Save IT's settings. They are restored after all overlay
5730 strings have been processed. */
5731 eassert (!compute_stop_p
|| it
->sp
== 0);
5733 /* When called from handle_stop, there might be an empty display
5734 string loaded. In that case, don't bother saving it. But
5735 don't use this optimization with the bidi iterator, since we
5736 need the corresponding pop_it call to resync the bidi
5737 iterator's position with IT's position, after we are done
5738 with the overlay strings. (The corresponding call to pop_it
5739 in case of an empty display string is in
5740 next_overlay_string.) */
5742 && STRINGP (it
->string
) && !SCHARS (it
->string
)))
5745 /* Set up IT to deliver display elements from the first overlay
5747 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5748 it
->string
= it
->overlay_strings
[0];
5749 it
->from_overlay
= Qnil
;
5750 it
->stop_charpos
= 0;
5751 eassert (STRINGP (it
->string
));
5752 it
->end_charpos
= SCHARS (it
->string
);
5754 it
->base_level_stop
= 0;
5755 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5756 it
->method
= GET_FROM_STRING
;
5757 it
->from_disp_prop_p
= 0;
5759 /* Force paragraph direction to be that of the parent
5761 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
5762 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5764 it
->paragraph_embedding
= L2R
;
5766 /* Set up the bidi iterator for this overlay string. */
5769 ptrdiff_t pos
= (charpos
> 0 ? charpos
: IT_CHARPOS (*it
));
5771 it
->bidi_it
.string
.lstring
= it
->string
;
5772 it
->bidi_it
.string
.s
= NULL
;
5773 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5774 it
->bidi_it
.string
.bufpos
= pos
;
5775 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5776 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5777 it
->bidi_it
.w
= it
->w
;
5778 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5783 it
->current
.overlay_string_index
= -1;
5788 get_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5791 it
->method
= GET_FROM_BUFFER
;
5793 (void) get_overlay_strings_1 (it
, charpos
, 1);
5797 /* Value is non-zero if we found at least one overlay string. */
5798 return STRINGP (it
->string
);
5803 /***********************************************************************
5804 Saving and restoring state
5805 ***********************************************************************/
5807 /* Save current settings of IT on IT->stack. Called, for example,
5808 before setting up IT for an overlay string, to be able to restore
5809 IT's settings to what they were after the overlay string has been
5810 processed. If POSITION is non-NULL, it is the position to save on
5811 the stack instead of IT->position. */
5814 push_it (struct it
*it
, struct text_pos
*position
)
5816 struct iterator_stack_entry
*p
;
5818 eassert (it
->sp
< IT_STACK_SIZE
);
5819 p
= it
->stack
+ it
->sp
;
5821 p
->stop_charpos
= it
->stop_charpos
;
5822 p
->prev_stop
= it
->prev_stop
;
5823 p
->base_level_stop
= it
->base_level_stop
;
5824 p
->cmp_it
= it
->cmp_it
;
5825 eassert (it
->face_id
>= 0);
5826 p
->face_id
= it
->face_id
;
5827 p
->string
= it
->string
;
5828 p
->method
= it
->method
;
5829 p
->from_overlay
= it
->from_overlay
;
5832 case GET_FROM_IMAGE
:
5833 p
->u
.image
.object
= it
->object
;
5834 p
->u
.image
.image_id
= it
->image_id
;
5835 p
->u
.image
.slice
= it
->slice
;
5837 case GET_FROM_STRETCH
:
5838 p
->u
.stretch
.object
= it
->object
;
5841 p
->position
= position
? *position
: it
->position
;
5842 p
->current
= it
->current
;
5843 p
->end_charpos
= it
->end_charpos
;
5844 p
->string_nchars
= it
->string_nchars
;
5846 p
->multibyte_p
= it
->multibyte_p
;
5847 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
5848 p
->space_width
= it
->space_width
;
5849 p
->font_height
= it
->font_height
;
5850 p
->voffset
= it
->voffset
;
5851 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5852 p
->string_from_prefix_prop_p
= it
->string_from_prefix_prop_p
;
5853 p
->display_ellipsis_p
= 0;
5854 p
->line_wrap
= it
->line_wrap
;
5855 p
->bidi_p
= it
->bidi_p
;
5856 p
->paragraph_embedding
= it
->paragraph_embedding
;
5857 p
->from_disp_prop_p
= it
->from_disp_prop_p
;
5860 /* Save the state of the bidi iterator as well. */
5862 bidi_push_it (&it
->bidi_it
);
5866 iterate_out_of_display_property (struct it
*it
)
5868 int buffer_p
= !STRINGP (it
->string
);
5869 ptrdiff_t eob
= (buffer_p
? ZV
: it
->end_charpos
);
5870 ptrdiff_t bob
= (buffer_p
? BEGV
: 0);
5872 eassert (eob
>= CHARPOS (it
->position
) && CHARPOS (it
->position
) >= bob
);
5874 /* Maybe initialize paragraph direction. If we are at the beginning
5875 of a new paragraph, next_element_from_buffer may not have a
5876 chance to do that. */
5877 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< eob
)
5878 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
5879 /* prev_stop can be zero, so check against BEGV as well. */
5880 while (it
->bidi_it
.charpos
>= bob
5881 && it
->prev_stop
<= it
->bidi_it
.charpos
5882 && it
->bidi_it
.charpos
< CHARPOS (it
->position
)
5883 && it
->bidi_it
.charpos
< eob
)
5884 bidi_move_to_visually_next (&it
->bidi_it
);
5885 /* Record the stop_pos we just crossed, for when we cross it
5887 if (it
->bidi_it
.charpos
> CHARPOS (it
->position
))
5888 it
->prev_stop
= CHARPOS (it
->position
);
5889 /* If we ended up not where pop_it put us, resync IT's
5890 positional members with the bidi iterator. */
5891 if (it
->bidi_it
.charpos
!= CHARPOS (it
->position
))
5892 SET_TEXT_POS (it
->position
, it
->bidi_it
.charpos
, it
->bidi_it
.bytepos
);
5894 it
->current
.pos
= it
->position
;
5896 it
->current
.string_pos
= it
->position
;
5899 /* Restore IT's settings from IT->stack. Called, for example, when no
5900 more overlay strings must be processed, and we return to delivering
5901 display elements from a buffer, or when the end of a string from a
5902 `display' property is reached and we return to delivering display
5903 elements from an overlay string, or from a buffer. */
5906 pop_it (struct it
*it
)
5908 struct iterator_stack_entry
*p
;
5909 int from_display_prop
= it
->from_disp_prop_p
;
5911 eassert (it
->sp
> 0);
5913 p
= it
->stack
+ it
->sp
;
5914 it
->stop_charpos
= p
->stop_charpos
;
5915 it
->prev_stop
= p
->prev_stop
;
5916 it
->base_level_stop
= p
->base_level_stop
;
5917 it
->cmp_it
= p
->cmp_it
;
5918 it
->face_id
= p
->face_id
;
5919 it
->current
= p
->current
;
5920 it
->position
= p
->position
;
5921 it
->string
= p
->string
;
5922 it
->from_overlay
= p
->from_overlay
;
5923 if (NILP (it
->string
))
5924 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5925 it
->method
= p
->method
;
5928 case GET_FROM_IMAGE
:
5929 it
->image_id
= p
->u
.image
.image_id
;
5930 it
->object
= p
->u
.image
.object
;
5931 it
->slice
= p
->u
.image
.slice
;
5933 case GET_FROM_STRETCH
:
5934 it
->object
= p
->u
.stretch
.object
;
5936 case GET_FROM_BUFFER
:
5937 it
->object
= it
->w
->contents
;
5939 case GET_FROM_STRING
:
5940 it
->object
= it
->string
;
5942 case GET_FROM_DISPLAY_VECTOR
:
5944 it
->method
= GET_FROM_C_STRING
;
5945 else if (STRINGP (it
->string
))
5946 it
->method
= GET_FROM_STRING
;
5949 it
->method
= GET_FROM_BUFFER
;
5950 it
->object
= it
->w
->contents
;
5953 it
->end_charpos
= p
->end_charpos
;
5954 it
->string_nchars
= p
->string_nchars
;
5956 it
->multibyte_p
= p
->multibyte_p
;
5957 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
5958 it
->space_width
= p
->space_width
;
5959 it
->font_height
= p
->font_height
;
5960 it
->voffset
= p
->voffset
;
5961 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5962 it
->string_from_prefix_prop_p
= p
->string_from_prefix_prop_p
;
5963 it
->line_wrap
= p
->line_wrap
;
5964 it
->bidi_p
= p
->bidi_p
;
5965 it
->paragraph_embedding
= p
->paragraph_embedding
;
5966 it
->from_disp_prop_p
= p
->from_disp_prop_p
;
5969 bidi_pop_it (&it
->bidi_it
);
5970 /* Bidi-iterate until we get out of the portion of text, if any,
5971 covered by a `display' text property or by an overlay with
5972 `display' property. (We cannot just jump there, because the
5973 internal coherency of the bidi iterator state can not be
5974 preserved across such jumps.) We also must determine the
5975 paragraph base direction if the overlay we just processed is
5976 at the beginning of a new paragraph. */
5977 if (from_display_prop
5978 && (it
->method
== GET_FROM_BUFFER
|| it
->method
== GET_FROM_STRING
))
5979 iterate_out_of_display_property (it
);
5981 eassert ((BUFFERP (it
->object
)
5982 && IT_CHARPOS (*it
) == it
->bidi_it
.charpos
5983 && IT_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
5984 || (STRINGP (it
->object
)
5985 && IT_STRING_CHARPOS (*it
) == it
->bidi_it
.charpos
5986 && IT_STRING_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
5987 || (CONSP (it
->object
) && it
->method
== GET_FROM_STRETCH
));
5993 /***********************************************************************
5995 ***********************************************************************/
5997 /* Set IT's current position to the previous line start. */
6000 back_to_previous_line_start (struct it
*it
)
6002 ptrdiff_t cp
= IT_CHARPOS (*it
), bp
= IT_BYTEPOS (*it
);
6005 IT_CHARPOS (*it
) = find_newline_no_quit (cp
, bp
, -1, &IT_BYTEPOS (*it
));
6009 /* Move IT to the next line start.
6011 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
6012 we skipped over part of the text (as opposed to moving the iterator
6013 continuously over the text). Otherwise, don't change the value
6016 If BIDI_IT_PREV is non-NULL, store into it the state of the bidi
6017 iterator on the newline, if it was found.
6019 Newlines may come from buffer text, overlay strings, or strings
6020 displayed via the `display' property. That's the reason we can't
6021 simply use find_newline_no_quit.
6023 Note that this function may not skip over invisible text that is so
6024 because of text properties and immediately follows a newline. If
6025 it would, function reseat_at_next_visible_line_start, when called
6026 from set_iterator_to_next, would effectively make invisible
6027 characters following a newline part of the wrong glyph row, which
6028 leads to wrong cursor motion. */
6031 forward_to_next_line_start (struct it
*it
, int *skipped_p
,
6032 struct bidi_it
*bidi_it_prev
)
6034 ptrdiff_t old_selective
;
6035 int newline_found_p
, n
;
6036 const int MAX_NEWLINE_DISTANCE
= 500;
6038 /* If already on a newline, just consume it to avoid unintended
6039 skipping over invisible text below. */
6040 if (it
->what
== IT_CHARACTER
6042 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
6044 if (it
->bidi_p
&& bidi_it_prev
)
6045 *bidi_it_prev
= it
->bidi_it
;
6046 set_iterator_to_next (it
, 0);
6051 /* Don't handle selective display in the following. It's (a)
6052 unnecessary because it's done by the caller, and (b) leads to an
6053 infinite recursion because next_element_from_ellipsis indirectly
6054 calls this function. */
6055 old_selective
= it
->selective
;
6058 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
6059 from buffer text. */
6060 for (n
= newline_found_p
= 0;
6061 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
6062 n
+= STRINGP (it
->string
) ? 0 : 1)
6064 if (!get_next_display_element (it
))
6066 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
6067 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
6068 *bidi_it_prev
= it
->bidi_it
;
6069 set_iterator_to_next (it
, 0);
6072 /* If we didn't find a newline near enough, see if we can use a
6074 if (!newline_found_p
)
6076 ptrdiff_t bytepos
, start
= IT_CHARPOS (*it
);
6077 ptrdiff_t limit
= find_newline_no_quit (start
, IT_BYTEPOS (*it
),
6081 eassert (!STRINGP (it
->string
));
6083 /* If there isn't any `display' property in sight, and no
6084 overlays, we can just use the position of the newline in
6086 if (it
->stop_charpos
>= limit
6087 || ((pos
= Fnext_single_property_change (make_number (start
),
6089 make_number (limit
)),
6091 && next_overlay_change (start
) == ZV
))
6095 IT_CHARPOS (*it
) = limit
;
6096 IT_BYTEPOS (*it
) = bytepos
;
6100 struct bidi_it bprev
;
6102 /* Help bidi.c avoid expensive searches for display
6103 properties and overlays, by telling it that there are
6104 none up to `limit'. */
6105 if (it
->bidi_it
.disp_pos
< limit
)
6107 it
->bidi_it
.disp_pos
= limit
;
6108 it
->bidi_it
.disp_prop
= 0;
6111 bprev
= it
->bidi_it
;
6112 bidi_move_to_visually_next (&it
->bidi_it
);
6113 } while (it
->bidi_it
.charpos
!= limit
);
6114 IT_CHARPOS (*it
) = limit
;
6115 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6117 *bidi_it_prev
= bprev
;
6119 *skipped_p
= newline_found_p
= true;
6123 while (get_next_display_element (it
)
6124 && !newline_found_p
)
6126 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
6127 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
6128 *bidi_it_prev
= it
->bidi_it
;
6129 set_iterator_to_next (it
, 0);
6134 it
->selective
= old_selective
;
6135 return newline_found_p
;
6139 /* Set IT's current position to the previous visible line start. Skip
6140 invisible text that is so either due to text properties or due to
6141 selective display. Caution: this does not change IT->current_x and
6145 back_to_previous_visible_line_start (struct it
*it
)
6147 while (IT_CHARPOS (*it
) > BEGV
)
6149 back_to_previous_line_start (it
);
6151 if (IT_CHARPOS (*it
) <= BEGV
)
6154 /* If selective > 0, then lines indented more than its value are
6156 if (it
->selective
> 0
6157 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6161 /* Check the newline before point for invisibility. */
6164 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
6165 Qinvisible
, it
->window
);
6166 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
6170 if (IT_CHARPOS (*it
) <= BEGV
)
6175 void *it2data
= NULL
;
6178 Lisp_Object val
, overlay
;
6180 SAVE_IT (it2
, *it
, it2data
);
6182 /* If newline is part of a composition, continue from start of composition */
6183 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
6184 && beg
< IT_CHARPOS (*it
))
6187 /* If newline is replaced by a display property, find start of overlay
6188 or interval and continue search from that point. */
6189 pos
= --IT_CHARPOS (it2
);
6192 bidi_unshelve_cache (NULL
, 0);
6193 it2
.string_from_display_prop_p
= 0;
6194 it2
.from_disp_prop_p
= 0;
6195 if (handle_display_prop (&it2
) == HANDLED_RETURN
6196 && !NILP (val
= get_char_property_and_overlay
6197 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
6198 && (OVERLAYP (overlay
)
6199 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
6200 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
6202 RESTORE_IT (it
, it
, it2data
);
6206 /* Newline is not replaced by anything -- so we are done. */
6207 RESTORE_IT (it
, it
, it2data
);
6213 IT_CHARPOS (*it
) = beg
;
6214 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
6218 it
->continuation_lines_width
= 0;
6220 eassert (IT_CHARPOS (*it
) >= BEGV
);
6221 eassert (IT_CHARPOS (*it
) == BEGV
6222 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6227 /* Reseat iterator IT at the previous visible line start. Skip
6228 invisible text that is so either due to text properties or due to
6229 selective display. At the end, update IT's overlay information,
6230 face information etc. */
6233 reseat_at_previous_visible_line_start (struct it
*it
)
6235 back_to_previous_visible_line_start (it
);
6236 reseat (it
, it
->current
.pos
, 1);
6241 /* Reseat iterator IT on the next visible line start in the current
6242 buffer. ON_NEWLINE_P non-zero means position IT on the newline
6243 preceding the line start. Skip over invisible text that is so
6244 because of selective display. Compute faces, overlays etc at the
6245 new position. Note that this function does not skip over text that
6246 is invisible because of text properties. */
6249 reseat_at_next_visible_line_start (struct it
*it
, int on_newline_p
)
6251 int newline_found_p
, skipped_p
= 0;
6252 struct bidi_it bidi_it_prev
;
6254 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6256 /* Skip over lines that are invisible because they are indented
6257 more than the value of IT->selective. */
6258 if (it
->selective
> 0)
6259 while (IT_CHARPOS (*it
) < ZV
6260 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6263 eassert (IT_BYTEPOS (*it
) == BEGV
6264 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6266 forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6269 /* Position on the newline if that's what's requested. */
6270 if (on_newline_p
&& newline_found_p
)
6272 if (STRINGP (it
->string
))
6274 if (IT_STRING_CHARPOS (*it
) > 0)
6278 --IT_STRING_CHARPOS (*it
);
6279 --IT_STRING_BYTEPOS (*it
);
6283 /* We need to restore the bidi iterator to the state
6284 it had on the newline, and resync the IT's
6285 position with that. */
6286 it
->bidi_it
= bidi_it_prev
;
6287 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6288 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6292 else if (IT_CHARPOS (*it
) > BEGV
)
6301 /* We need to restore the bidi iterator to the state it
6302 had on the newline and resync IT with that. */
6303 it
->bidi_it
= bidi_it_prev
;
6304 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6305 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6307 reseat (it
, it
->current
.pos
, 0);
6311 reseat (it
, it
->current
.pos
, 0);
6318 /***********************************************************************
6319 Changing an iterator's position
6320 ***********************************************************************/
6322 /* Change IT's current position to POS in current_buffer. If FORCE_P
6323 is non-zero, always check for text properties at the new position.
6324 Otherwise, text properties are only looked up if POS >=
6325 IT->check_charpos of a property. */
6328 reseat (struct it
*it
, struct text_pos pos
, int force_p
)
6330 ptrdiff_t original_pos
= IT_CHARPOS (*it
);
6332 reseat_1 (it
, pos
, 0);
6334 /* Determine where to check text properties. Avoid doing it
6335 where possible because text property lookup is very expensive. */
6337 || CHARPOS (pos
) > it
->stop_charpos
6338 || CHARPOS (pos
) < original_pos
)
6342 /* For bidi iteration, we need to prime prev_stop and
6343 base_level_stop with our best estimations. */
6344 /* Implementation note: Of course, POS is not necessarily a
6345 stop position, so assigning prev_pos to it is a lie; we
6346 should have called compute_stop_backwards. However, if
6347 the current buffer does not include any R2L characters,
6348 that call would be a waste of cycles, because the
6349 iterator will never move back, and thus never cross this
6350 "fake" stop position. So we delay that backward search
6351 until the time we really need it, in next_element_from_buffer. */
6352 if (CHARPOS (pos
) != it
->prev_stop
)
6353 it
->prev_stop
= CHARPOS (pos
);
6354 if (CHARPOS (pos
) < it
->base_level_stop
)
6355 it
->base_level_stop
= 0; /* meaning it's unknown */
6361 it
->prev_stop
= it
->base_level_stop
= 0;
6370 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
6371 IT->stop_pos to POS, also. */
6374 reseat_1 (struct it
*it
, struct text_pos pos
, int set_stop_p
)
6376 /* Don't call this function when scanning a C string. */
6377 eassert (it
->s
== NULL
);
6379 /* POS must be a reasonable value. */
6380 eassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
6382 it
->current
.pos
= it
->position
= pos
;
6383 it
->end_charpos
= ZV
;
6385 it
->current
.dpvec_index
= -1;
6386 it
->current
.overlay_string_index
= -1;
6387 IT_STRING_CHARPOS (*it
) = -1;
6388 IT_STRING_BYTEPOS (*it
) = -1;
6390 it
->method
= GET_FROM_BUFFER
;
6391 it
->object
= it
->w
->contents
;
6392 it
->area
= TEXT_AREA
;
6393 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
6395 it
->string_from_display_prop_p
= 0;
6396 it
->string_from_prefix_prop_p
= 0;
6398 it
->from_disp_prop_p
= 0;
6399 it
->face_before_selective_p
= 0;
6402 bidi_init_it (IT_CHARPOS (*it
), IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6404 bidi_unshelve_cache (NULL
, 0);
6405 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6406 it
->bidi_it
.string
.s
= NULL
;
6407 it
->bidi_it
.string
.lstring
= Qnil
;
6408 it
->bidi_it
.string
.bufpos
= 0;
6409 it
->bidi_it
.string
.unibyte
= 0;
6410 it
->bidi_it
.w
= it
->w
;
6415 it
->stop_charpos
= CHARPOS (pos
);
6416 it
->base_level_stop
= CHARPOS (pos
);
6418 /* This make the information stored in it->cmp_it invalidate. */
6423 /* Set up IT for displaying a string, starting at CHARPOS in window W.
6424 If S is non-null, it is a C string to iterate over. Otherwise,
6425 STRING gives a Lisp string to iterate over.
6427 If PRECISION > 0, don't return more then PRECISION number of
6428 characters from the string.
6430 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
6431 characters have been returned. FIELD_WIDTH < 0 means an infinite
6434 MULTIBYTE = 0 means disable processing of multibyte characters,
6435 MULTIBYTE > 0 means enable it,
6436 MULTIBYTE < 0 means use IT->multibyte_p.
6438 IT must be initialized via a prior call to init_iterator before
6439 calling this function. */
6442 reseat_to_string (struct it
*it
, const char *s
, Lisp_Object string
,
6443 ptrdiff_t charpos
, ptrdiff_t precision
, int field_width
,
6446 /* No text property checks performed by default, but see below. */
6447 it
->stop_charpos
= -1;
6449 /* Set iterator position and end position. */
6450 memset (&it
->current
, 0, sizeof it
->current
);
6451 it
->current
.overlay_string_index
= -1;
6452 it
->current
.dpvec_index
= -1;
6453 eassert (charpos
>= 0);
6455 /* If STRING is specified, use its multibyteness, otherwise use the
6456 setting of MULTIBYTE, if specified. */
6458 it
->multibyte_p
= multibyte
> 0;
6460 /* Bidirectional reordering of strings is controlled by the default
6461 value of bidi-display-reordering. Don't try to reorder while
6462 loading loadup.el, as the necessary character property tables are
6463 not yet available. */
6466 && !NILP (BVAR (&buffer_defaults
, bidi_display_reordering
));
6470 eassert (STRINGP (string
));
6471 it
->string
= string
;
6473 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
6474 it
->method
= GET_FROM_STRING
;
6475 it
->current
.string_pos
= string_pos (charpos
, string
);
6479 it
->bidi_it
.string
.lstring
= string
;
6480 it
->bidi_it
.string
.s
= NULL
;
6481 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6482 it
->bidi_it
.string
.bufpos
= 0;
6483 it
->bidi_it
.string
.from_disp_str
= 0;
6484 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6485 it
->bidi_it
.w
= it
->w
;
6486 bidi_init_it (charpos
, IT_STRING_BYTEPOS (*it
),
6487 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
6492 it
->s
= (const unsigned char *) s
;
6495 /* Note that we use IT->current.pos, not it->current.string_pos,
6496 for displaying C strings. */
6497 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
6498 if (it
->multibyte_p
)
6500 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
6501 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
6505 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
6506 it
->end_charpos
= it
->string_nchars
= strlen (s
);
6511 it
->bidi_it
.string
.lstring
= Qnil
;
6512 it
->bidi_it
.string
.s
= (const unsigned char *) s
;
6513 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6514 it
->bidi_it
.string
.bufpos
= 0;
6515 it
->bidi_it
.string
.from_disp_str
= 0;
6516 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6517 it
->bidi_it
.w
= it
->w
;
6518 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6521 it
->method
= GET_FROM_C_STRING
;
6524 /* PRECISION > 0 means don't return more than PRECISION characters
6526 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
6528 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
6530 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6533 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
6534 characters have been returned. FIELD_WIDTH == 0 means don't pad,
6535 FIELD_WIDTH < 0 means infinite field width. This is useful for
6536 padding with `-' at the end of a mode line. */
6537 if (field_width
< 0)
6538 field_width
= INFINITY
;
6539 /* Implementation note: We deliberately don't enlarge
6540 it->bidi_it.string.schars here to fit it->end_charpos, because
6541 the bidi iterator cannot produce characters out of thin air. */
6542 if (field_width
> it
->end_charpos
- charpos
)
6543 it
->end_charpos
= charpos
+ field_width
;
6545 /* Use the standard display table for displaying strings. */
6546 if (DISP_TABLE_P (Vstandard_display_table
))
6547 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
6549 it
->stop_charpos
= charpos
;
6550 it
->prev_stop
= charpos
;
6551 it
->base_level_stop
= 0;
6554 it
->bidi_it
.first_elt
= 1;
6555 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6556 it
->bidi_it
.disp_pos
= -1;
6558 if (s
== NULL
&& it
->multibyte_p
)
6560 ptrdiff_t endpos
= SCHARS (it
->string
);
6561 if (endpos
> it
->end_charpos
)
6562 endpos
= it
->end_charpos
;
6563 composition_compute_stop_pos (&it
->cmp_it
, charpos
, -1, endpos
,
6571 /***********************************************************************
6573 ***********************************************************************/
6575 /* Map enum it_method value to corresponding next_element_from_* function. */
6577 static int (* get_next_element
[NUM_IT_METHODS
]) (struct it
*it
) =
6579 next_element_from_buffer
,
6580 next_element_from_display_vector
,
6581 next_element_from_string
,
6582 next_element_from_c_string
,
6583 next_element_from_image
,
6584 next_element_from_stretch
6587 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
6590 /* Return 1 iff a character at CHARPOS (and BYTEPOS) is composed
6591 (possibly with the following characters). */
6593 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS,END_CHARPOS) \
6594 ((IT)->cmp_it.id >= 0 \
6595 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
6596 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
6597 END_CHARPOS, (IT)->w, \
6598 FACE_FROM_ID ((IT)->f, (IT)->face_id), \
6602 /* Lookup the char-table Vglyphless_char_display for character C (-1
6603 if we want information for no-font case), and return the display
6604 method symbol. By side-effect, update it->what and
6605 it->glyphless_method. This function is called from
6606 get_next_display_element for each character element, and from
6607 x_produce_glyphs when no suitable font was found. */
6610 lookup_glyphless_char_display (int c
, struct it
*it
)
6612 Lisp_Object glyphless_method
= Qnil
;
6614 if (CHAR_TABLE_P (Vglyphless_char_display
)
6615 && CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
)) >= 1)
6619 glyphless_method
= CHAR_TABLE_REF (Vglyphless_char_display
, c
);
6620 if (CONSP (glyphless_method
))
6621 glyphless_method
= FRAME_WINDOW_P (it
->f
)
6622 ? XCAR (glyphless_method
)
6623 : XCDR (glyphless_method
);
6626 glyphless_method
= XCHAR_TABLE (Vglyphless_char_display
)->extras
[0];
6630 if (NILP (glyphless_method
))
6633 /* The default is to display the character by a proper font. */
6635 /* The default for the no-font case is to display an empty box. */
6636 glyphless_method
= Qempty_box
;
6638 if (EQ (glyphless_method
, Qzero_width
))
6641 return glyphless_method
;
6642 /* This method can't be used for the no-font case. */
6643 glyphless_method
= Qempty_box
;
6645 if (EQ (glyphless_method
, Qthin_space
))
6646 it
->glyphless_method
= GLYPHLESS_DISPLAY_THIN_SPACE
;
6647 else if (EQ (glyphless_method
, Qempty_box
))
6648 it
->glyphless_method
= GLYPHLESS_DISPLAY_EMPTY_BOX
;
6649 else if (EQ (glyphless_method
, Qhex_code
))
6650 it
->glyphless_method
= GLYPHLESS_DISPLAY_HEX_CODE
;
6651 else if (STRINGP (glyphless_method
))
6652 it
->glyphless_method
= GLYPHLESS_DISPLAY_ACRONYM
;
6655 /* Invalid value. We use the default method. */
6656 glyphless_method
= Qnil
;
6659 it
->what
= IT_GLYPHLESS
;
6660 return glyphless_method
;
6663 /* Merge escape glyph face and cache the result. */
6665 static struct frame
*last_escape_glyph_frame
= NULL
;
6666 static int last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
6667 static int last_escape_glyph_merged_face_id
= 0;
6670 merge_escape_glyph_face (struct it
*it
)
6674 if (it
->f
== last_escape_glyph_frame
6675 && it
->face_id
== last_escape_glyph_face_id
)
6676 face_id
= last_escape_glyph_merged_face_id
;
6679 /* Merge the `escape-glyph' face into the current face. */
6680 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0, it
->face_id
);
6681 last_escape_glyph_frame
= it
->f
;
6682 last_escape_glyph_face_id
= it
->face_id
;
6683 last_escape_glyph_merged_face_id
= face_id
;
6688 /* Likewise for glyphless glyph face. */
6690 static struct frame
*last_glyphless_glyph_frame
= NULL
;
6691 static int last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
6692 static int last_glyphless_glyph_merged_face_id
= 0;
6695 merge_glyphless_glyph_face (struct it
*it
)
6699 if (it
->f
== last_glyphless_glyph_frame
6700 && it
->face_id
== last_glyphless_glyph_face_id
)
6701 face_id
= last_glyphless_glyph_merged_face_id
;
6704 /* Merge the `glyphless-char' face into the current face. */
6705 face_id
= merge_faces (it
->f
, Qglyphless_char
, 0, it
->face_id
);
6706 last_glyphless_glyph_frame
= it
->f
;
6707 last_glyphless_glyph_face_id
= it
->face_id
;
6708 last_glyphless_glyph_merged_face_id
= face_id
;
6713 /* Load IT's display element fields with information about the next
6714 display element from the current position of IT. Value is zero if
6715 end of buffer (or C string) is reached. */
6718 get_next_display_element (struct it
*it
)
6720 /* Non-zero means that we found a display element. Zero means that
6721 we hit the end of what we iterate over. Performance note: the
6722 function pointer `method' used here turns out to be faster than
6723 using a sequence of if-statements. */
6727 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6729 if (it
->what
== IT_CHARACTER
)
6731 /* UAX#9, L4: "A character is depicted by a mirrored glyph if
6732 and only if (a) the resolved directionality of that character
6734 /* FIXME: Do we need an exception for characters from display
6736 if (it
->bidi_p
&& it
->bidi_it
.type
== STRONG_R
)
6737 it
->c
= bidi_mirror_char (it
->c
);
6738 /* Map via display table or translate control characters.
6739 IT->c, IT->len etc. have been set to the next character by
6740 the function call above. If we have a display table, and it
6741 contains an entry for IT->c, translate it. Don't do this if
6742 IT->c itself comes from a display table, otherwise we could
6743 end up in an infinite recursion. (An alternative could be to
6744 count the recursion depth of this function and signal an
6745 error when a certain maximum depth is reached.) Is it worth
6747 if (success_p
&& it
->dpvec
== NULL
)
6750 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
6751 int nonascii_space_p
= 0;
6752 int nonascii_hyphen_p
= 0;
6753 int c
= it
->c
; /* This is the character to display. */
6755 if (! it
->multibyte_p
&& ! ASCII_CHAR_P (c
))
6757 eassert (SINGLE_BYTE_CHAR_P (c
));
6758 if (unibyte_display_via_language_environment
)
6760 c
= DECODE_CHAR (unibyte
, c
);
6762 c
= BYTE8_TO_CHAR (it
->c
);
6765 c
= BYTE8_TO_CHAR (it
->c
);
6769 && (dv
= DISP_CHAR_VECTOR (it
->dp
, c
),
6772 struct Lisp_Vector
*v
= XVECTOR (dv
);
6774 /* Return the first character from the display table
6775 entry, if not empty. If empty, don't display the
6776 current character. */
6779 it
->dpvec_char_len
= it
->len
;
6780 it
->dpvec
= v
->contents
;
6781 it
->dpend
= v
->contents
+ v
->header
.size
;
6782 it
->current
.dpvec_index
= 0;
6783 it
->dpvec_face_id
= -1;
6784 it
->saved_face_id
= it
->face_id
;
6785 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6790 set_iterator_to_next (it
, 0);
6795 if (! NILP (lookup_glyphless_char_display (c
, it
)))
6797 if (it
->what
== IT_GLYPHLESS
)
6799 /* Don't display this character. */
6800 set_iterator_to_next (it
, 0);
6804 /* If `nobreak-char-display' is non-nil, we display
6805 non-ASCII spaces and hyphens specially. */
6806 if (! ASCII_CHAR_P (c
) && ! NILP (Vnobreak_char_display
))
6809 nonascii_space_p
= true;
6810 else if (c
== 0xAD || c
== 0x2010 || c
== 0x2011)
6811 nonascii_hyphen_p
= true;
6814 /* Translate control characters into `\003' or `^C' form.
6815 Control characters coming from a display table entry are
6816 currently not translated because we use IT->dpvec to hold
6817 the translation. This could easily be changed but I
6818 don't believe that it is worth doing.
6820 The characters handled by `nobreak-char-display' must be
6823 Non-printable characters and raw-byte characters are also
6824 translated to octal form. */
6825 if (((c
< ' ' || c
== 127) /* ASCII control chars. */
6826 ? (it
->area
!= TEXT_AREA
6827 /* In mode line, treat \n, \t like other crl chars. */
6830 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
6831 || (c
!= '\n' && c
!= '\t'))
6833 || nonascii_hyphen_p
6835 || ! CHAR_PRINTABLE_P (c
))))
6837 /* C is a control character, non-ASCII space/hyphen,
6838 raw-byte, or a non-printable character which must be
6839 displayed either as '\003' or as `^C' where the '\\'
6840 and '^' can be defined in the display table. Fill
6841 IT->ctl_chars with glyphs for what we have to
6842 display. Then, set IT->dpvec to these glyphs. */
6849 /* Handle control characters with ^. */
6851 if (ASCII_CHAR_P (c
) && it
->ctl_arrow_p
)
6855 g
= '^'; /* default glyph for Control */
6856 /* Set IT->ctl_chars[0] to the glyph for `^'. */
6858 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
6860 g
= GLYPH_CODE_CHAR (gc
);
6861 lface_id
= GLYPH_CODE_FACE (gc
);
6865 ? merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
)
6866 : merge_escape_glyph_face (it
));
6868 XSETINT (it
->ctl_chars
[0], g
);
6869 XSETINT (it
->ctl_chars
[1], c
^ 0100);
6871 goto display_control
;
6874 /* Handle non-ascii space in the mode where it only gets
6877 if (nonascii_space_p
&& EQ (Vnobreak_char_display
, Qt
))
6879 /* Merge `nobreak-space' into the current face. */
6880 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
6882 XSETINT (it
->ctl_chars
[0], ' ');
6884 goto display_control
;
6887 /* Handle sequences that start with the "escape glyph". */
6889 /* the default escape glyph is \. */
6890 escape_glyph
= '\\';
6893 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
6895 escape_glyph
= GLYPH_CODE_CHAR (gc
);
6896 lface_id
= GLYPH_CODE_FACE (gc
);
6900 ? merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
)
6901 : merge_escape_glyph_face (it
));
6903 /* Draw non-ASCII hyphen with just highlighting: */
6905 if (nonascii_hyphen_p
&& EQ (Vnobreak_char_display
, Qt
))
6907 XSETINT (it
->ctl_chars
[0], '-');
6909 goto display_control
;
6912 /* Draw non-ASCII space/hyphen with escape glyph: */
6914 if (nonascii_space_p
|| nonascii_hyphen_p
)
6916 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6917 XSETINT (it
->ctl_chars
[1], nonascii_space_p
? ' ' : '-');
6919 goto display_control
;
6926 if (CHAR_BYTE8_P (c
))
6927 /* Display \200 instead of \17777600. */
6928 c
= CHAR_TO_BYTE8 (c
);
6929 len
= sprintf (str
, "%03o", c
);
6931 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6932 for (i
= 0; i
< len
; i
++)
6933 XSETINT (it
->ctl_chars
[i
+ 1], str
[i
]);
6938 /* Set up IT->dpvec and return first character from it. */
6939 it
->dpvec_char_len
= it
->len
;
6940 it
->dpvec
= it
->ctl_chars
;
6941 it
->dpend
= it
->dpvec
+ ctl_len
;
6942 it
->current
.dpvec_index
= 0;
6943 it
->dpvec_face_id
= face_id
;
6944 it
->saved_face_id
= it
->face_id
;
6945 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6949 it
->char_to_display
= c
;
6953 it
->char_to_display
= it
->c
;
6957 #ifdef HAVE_WINDOW_SYSTEM
6958 /* Adjust face id for a multibyte character. There are no multibyte
6959 character in unibyte text. */
6960 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
6963 && FRAME_WINDOW_P (it
->f
))
6965 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
6967 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
6969 /* Automatic composition with glyph-string. */
6970 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
6972 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
6976 ptrdiff_t pos
= (it
->s
? -1
6977 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
6978 : IT_CHARPOS (*it
));
6981 if (it
->what
== IT_CHARACTER
)
6982 c
= it
->char_to_display
;
6985 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
6989 for (i
= 0; i
< cmp
->glyph_len
; i
++)
6990 /* TAB in a composition means display glyphs with
6991 padding space on the left or right. */
6992 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
6995 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, pos
, it
->string
);
6998 #endif /* HAVE_WINDOW_SYSTEM */
7001 /* Is this character the last one of a run of characters with
7002 box? If yes, set IT->end_of_box_run_p to 1. */
7006 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
7008 int face_id
= underlying_face_id (it
);
7009 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
7013 if (face
->box
== FACE_NO_BOX
)
7015 /* If the box comes from face properties in a
7016 display string, check faces in that string. */
7017 int string_face_id
= face_after_it_pos (it
);
7018 it
->end_of_box_run_p
7019 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
7022 /* Otherwise, the box comes from the underlying face.
7023 If this is the last string character displayed, check
7024 the next buffer location. */
7025 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
7026 && (it
->current
.overlay_string_index
7027 == it
->n_overlay_strings
- 1))
7031 struct text_pos pos
= it
->current
.pos
;
7032 INC_TEXT_POS (pos
, it
->multibyte_p
);
7034 next_face_id
= face_at_buffer_position
7035 (it
->w
, CHARPOS (pos
), &ignore
,
7036 (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
), 0,
7038 it
->end_of_box_run_p
7039 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
7044 /* next_element_from_display_vector sets this flag according to
7045 faces of the display vector glyphs, see there. */
7046 else if (it
->method
!= GET_FROM_DISPLAY_VECTOR
)
7048 int face_id
= face_after_it_pos (it
);
7049 it
->end_of_box_run_p
7050 = (face_id
!= it
->face_id
7051 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
7054 /* If we reached the end of the object we've been iterating (e.g., a
7055 display string or an overlay string), and there's something on
7056 IT->stack, proceed with what's on the stack. It doesn't make
7057 sense to return zero if there's unprocessed stuff on the stack,
7058 because otherwise that stuff will never be displayed. */
7059 if (!success_p
&& it
->sp
> 0)
7061 set_iterator_to_next (it
, 0);
7062 success_p
= get_next_display_element (it
);
7065 /* Value is 0 if end of buffer or string reached. */
7070 /* Move IT to the next display element.
7072 RESEAT_P non-zero means if called on a newline in buffer text,
7073 skip to the next visible line start.
7075 Functions get_next_display_element and set_iterator_to_next are
7076 separate because I find this arrangement easier to handle than a
7077 get_next_display_element function that also increments IT's
7078 position. The way it is we can first look at an iterator's current
7079 display element, decide whether it fits on a line, and if it does,
7080 increment the iterator position. The other way around we probably
7081 would either need a flag indicating whether the iterator has to be
7082 incremented the next time, or we would have to implement a
7083 decrement position function which would not be easy to write. */
7086 set_iterator_to_next (struct it
*it
, int reseat_p
)
7088 /* Reset flags indicating start and end of a sequence of characters
7089 with box. Reset them at the start of this function because
7090 moving the iterator to a new position might set them. */
7091 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
7095 case GET_FROM_BUFFER
:
7096 /* The current display element of IT is a character from
7097 current_buffer. Advance in the buffer, and maybe skip over
7098 invisible lines that are so because of selective display. */
7099 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
7100 reseat_at_next_visible_line_start (it
, 0);
7101 else if (it
->cmp_it
.id
>= 0)
7103 /* We are currently getting glyphs from a composition. */
7108 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7109 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7110 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7112 it
->cmp_it
.from
= it
->cmp_it
.to
;
7117 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7119 it
->end_charpos
, Qnil
);
7122 else if (! it
->cmp_it
.reversed_p
)
7124 /* Composition created while scanning forward. */
7125 /* Update IT's char/byte positions to point to the first
7126 character of the next grapheme cluster, or to the
7127 character visually after the current composition. */
7128 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7129 bidi_move_to_visually_next (&it
->bidi_it
);
7130 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7131 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7133 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7135 /* Proceed to the next grapheme cluster. */
7136 it
->cmp_it
.from
= it
->cmp_it
.to
;
7140 /* No more grapheme clusters in this composition.
7141 Find the next stop position. */
7142 ptrdiff_t stop
= it
->end_charpos
;
7143 if (it
->bidi_it
.scan_dir
< 0)
7144 /* Now we are scanning backward and don't know
7147 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7148 IT_BYTEPOS (*it
), stop
, Qnil
);
7153 /* Composition created while scanning backward. */
7154 /* Update IT's char/byte positions to point to the last
7155 character of the previous grapheme cluster, or the
7156 character visually after the current composition. */
7157 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7158 bidi_move_to_visually_next (&it
->bidi_it
);
7159 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7160 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7161 if (it
->cmp_it
.from
> 0)
7163 /* Proceed to the previous grapheme cluster. */
7164 it
->cmp_it
.to
= it
->cmp_it
.from
;
7168 /* No more grapheme clusters in this composition.
7169 Find the next stop position. */
7170 ptrdiff_t stop
= it
->end_charpos
;
7171 if (it
->bidi_it
.scan_dir
< 0)
7172 /* Now we are scanning backward and don't know
7175 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7176 IT_BYTEPOS (*it
), stop
, Qnil
);
7182 eassert (it
->len
!= 0);
7186 IT_BYTEPOS (*it
) += it
->len
;
7187 IT_CHARPOS (*it
) += 1;
7191 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7192 /* If this is a new paragraph, determine its base
7193 direction (a.k.a. its base embedding level). */
7194 if (it
->bidi_it
.new_paragraph
)
7195 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
7196 bidi_move_to_visually_next (&it
->bidi_it
);
7197 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7198 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7199 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7201 /* As the scan direction was changed, we must
7202 re-compute the stop position for composition. */
7203 ptrdiff_t stop
= it
->end_charpos
;
7204 if (it
->bidi_it
.scan_dir
< 0)
7206 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7207 IT_BYTEPOS (*it
), stop
, Qnil
);
7210 eassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
7214 case GET_FROM_C_STRING
:
7215 /* Current display element of IT is from a C string. */
7217 /* If the string position is beyond string's end, it means
7218 next_element_from_c_string is padding the string with
7219 blanks, in which case we bypass the bidi iterator,
7220 because it cannot deal with such virtual characters. */
7221 || IT_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7223 IT_BYTEPOS (*it
) += it
->len
;
7224 IT_CHARPOS (*it
) += 1;
7228 bidi_move_to_visually_next (&it
->bidi_it
);
7229 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7230 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7234 case GET_FROM_DISPLAY_VECTOR
:
7235 /* Current display element of IT is from a display table entry.
7236 Advance in the display table definition. Reset it to null if
7237 end reached, and continue with characters from buffers/
7239 ++it
->current
.dpvec_index
;
7241 /* Restore face of the iterator to what they were before the
7242 display vector entry (these entries may contain faces). */
7243 it
->face_id
= it
->saved_face_id
;
7245 if (it
->dpvec
+ it
->current
.dpvec_index
>= it
->dpend
)
7247 int recheck_faces
= it
->ellipsis_p
;
7250 it
->method
= GET_FROM_C_STRING
;
7251 else if (STRINGP (it
->string
))
7252 it
->method
= GET_FROM_STRING
;
7255 it
->method
= GET_FROM_BUFFER
;
7256 it
->object
= it
->w
->contents
;
7260 it
->current
.dpvec_index
= -1;
7262 /* Skip over characters which were displayed via IT->dpvec. */
7263 if (it
->dpvec_char_len
< 0)
7264 reseat_at_next_visible_line_start (it
, 1);
7265 else if (it
->dpvec_char_len
> 0)
7267 if (it
->method
== GET_FROM_STRING
7268 && it
->current
.overlay_string_index
>= 0
7269 && it
->n_overlay_strings
> 0)
7270 it
->ignore_overlay_strings_at_pos_p
= true;
7271 it
->len
= it
->dpvec_char_len
;
7272 set_iterator_to_next (it
, reseat_p
);
7275 /* Maybe recheck faces after display vector. */
7277 it
->stop_charpos
= IT_CHARPOS (*it
);
7281 case GET_FROM_STRING
:
7282 /* Current display element is a character from a Lisp string. */
7283 eassert (it
->s
== NULL
&& STRINGP (it
->string
));
7284 /* Don't advance past string end. These conditions are true
7285 when set_iterator_to_next is called at the end of
7286 get_next_display_element, in which case the Lisp string is
7287 already exhausted, and all we want is pop the iterator
7289 if (it
->current
.overlay_string_index
>= 0)
7291 /* This is an overlay string, so there's no padding with
7292 spaces, and the number of characters in the string is
7293 where the string ends. */
7294 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7295 goto consider_string_end
;
7299 /* Not an overlay string. There could be padding, so test
7300 against it->end_charpos. */
7301 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7302 goto consider_string_end
;
7304 if (it
->cmp_it
.id
>= 0)
7310 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7311 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7312 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7313 it
->cmp_it
.from
= it
->cmp_it
.to
;
7317 composition_compute_stop_pos (&it
->cmp_it
,
7318 IT_STRING_CHARPOS (*it
),
7319 IT_STRING_BYTEPOS (*it
),
7320 it
->end_charpos
, it
->string
);
7323 else if (! it
->cmp_it
.reversed_p
)
7325 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7326 bidi_move_to_visually_next (&it
->bidi_it
);
7327 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7328 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7330 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7331 it
->cmp_it
.from
= it
->cmp_it
.to
;
7334 ptrdiff_t stop
= it
->end_charpos
;
7335 if (it
->bidi_it
.scan_dir
< 0)
7337 composition_compute_stop_pos (&it
->cmp_it
,
7338 IT_STRING_CHARPOS (*it
),
7339 IT_STRING_BYTEPOS (*it
), stop
,
7345 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7346 bidi_move_to_visually_next (&it
->bidi_it
);
7347 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7348 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7349 if (it
->cmp_it
.from
> 0)
7350 it
->cmp_it
.to
= it
->cmp_it
.from
;
7353 ptrdiff_t stop
= it
->end_charpos
;
7354 if (it
->bidi_it
.scan_dir
< 0)
7356 composition_compute_stop_pos (&it
->cmp_it
,
7357 IT_STRING_CHARPOS (*it
),
7358 IT_STRING_BYTEPOS (*it
), stop
,
7366 /* If the string position is beyond string's end, it
7367 means next_element_from_string is padding the string
7368 with blanks, in which case we bypass the bidi
7369 iterator, because it cannot deal with such virtual
7371 || IT_STRING_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7373 IT_STRING_BYTEPOS (*it
) += it
->len
;
7374 IT_STRING_CHARPOS (*it
) += 1;
7378 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7380 bidi_move_to_visually_next (&it
->bidi_it
);
7381 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7382 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7383 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7385 ptrdiff_t stop
= it
->end_charpos
;
7387 if (it
->bidi_it
.scan_dir
< 0)
7389 composition_compute_stop_pos (&it
->cmp_it
,
7390 IT_STRING_CHARPOS (*it
),
7391 IT_STRING_BYTEPOS (*it
), stop
,
7397 consider_string_end
:
7399 if (it
->current
.overlay_string_index
>= 0)
7401 /* IT->string is an overlay string. Advance to the
7402 next, if there is one. */
7403 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7406 next_overlay_string (it
);
7408 setup_for_ellipsis (it
, 0);
7413 /* IT->string is not an overlay string. If we reached
7414 its end, and there is something on IT->stack, proceed
7415 with what is on the stack. This can be either another
7416 string, this time an overlay string, or a buffer. */
7417 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
7421 if (it
->method
== GET_FROM_STRING
)
7422 goto consider_string_end
;
7427 case GET_FROM_IMAGE
:
7428 case GET_FROM_STRETCH
:
7429 /* The position etc with which we have to proceed are on
7430 the stack. The position may be at the end of a string,
7431 if the `display' property takes up the whole string. */
7432 eassert (it
->sp
> 0);
7434 if (it
->method
== GET_FROM_STRING
)
7435 goto consider_string_end
;
7439 /* There are no other methods defined, so this should be a bug. */
7443 eassert (it
->method
!= GET_FROM_STRING
7444 || (STRINGP (it
->string
)
7445 && IT_STRING_CHARPOS (*it
) >= 0));
7448 /* Load IT's display element fields with information about the next
7449 display element which comes from a display table entry or from the
7450 result of translating a control character to one of the forms `^C'
7453 IT->dpvec holds the glyphs to return as characters.
7454 IT->saved_face_id holds the face id before the display vector--it
7455 is restored into IT->face_id in set_iterator_to_next. */
7458 next_element_from_display_vector (struct it
*it
)
7461 int prev_face_id
= it
->face_id
;
7465 eassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
7467 it
->face_id
= it
->saved_face_id
;
7469 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
7470 That seemed totally bogus - so I changed it... */
7471 gc
= it
->dpvec
[it
->current
.dpvec_index
];
7473 if (GLYPH_CODE_P (gc
))
7475 struct face
*this_face
, *prev_face
, *next_face
;
7477 it
->c
= GLYPH_CODE_CHAR (gc
);
7478 it
->len
= CHAR_BYTES (it
->c
);
7480 /* The entry may contain a face id to use. Such a face id is
7481 the id of a Lisp face, not a realized face. A face id of
7482 zero means no face is specified. */
7483 if (it
->dpvec_face_id
>= 0)
7484 it
->face_id
= it
->dpvec_face_id
;
7487 int lface_id
= GLYPH_CODE_FACE (gc
);
7489 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
7493 /* Glyphs in the display vector could have the box face, so we
7494 need to set the related flags in the iterator, as
7496 this_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
7497 prev_face
= FACE_FROM_ID (it
->f
, prev_face_id
);
7499 /* Is this character the first character of a box-face run? */
7500 it
->start_of_box_run_p
= (this_face
&& this_face
->box
!= FACE_NO_BOX
7502 || prev_face
->box
== FACE_NO_BOX
));
7504 /* For the last character of the box-face run, we need to look
7505 either at the next glyph from the display vector, or at the
7506 face we saw before the display vector. */
7507 next_face_id
= it
->saved_face_id
;
7508 if (it
->current
.dpvec_index
< it
->dpend
- it
->dpvec
- 1)
7510 if (it
->dpvec_face_id
>= 0)
7511 next_face_id
= it
->dpvec_face_id
;
7515 GLYPH_CODE_FACE (it
->dpvec
[it
->current
.dpvec_index
+ 1]);
7518 next_face_id
= merge_faces (it
->f
, Qt
, lface_id
,
7522 next_face
= FACE_FROM_ID (it
->f
, next_face_id
);
7523 it
->end_of_box_run_p
= (this_face
&& this_face
->box
!= FACE_NO_BOX
7525 || next_face
->box
== FACE_NO_BOX
));
7526 it
->face_box_p
= this_face
&& this_face
->box
!= FACE_NO_BOX
;
7529 /* Display table entry is invalid. Return a space. */
7530 it
->c
= ' ', it
->len
= 1;
7532 /* Don't change position and object of the iterator here. They are
7533 still the values of the character that had this display table
7534 entry or was translated, and that's what we want. */
7535 it
->what
= IT_CHARACTER
;
7539 /* Get the first element of string/buffer in the visual order, after
7540 being reseated to a new position in a string or a buffer. */
7542 get_visually_first_element (struct it
*it
)
7544 int string_p
= STRINGP (it
->string
) || it
->s
;
7545 ptrdiff_t eob
= (string_p
? it
->bidi_it
.string
.schars
: ZV
);
7546 ptrdiff_t bob
= (string_p
? 0 : BEGV
);
7548 if (STRINGP (it
->string
))
7550 it
->bidi_it
.charpos
= IT_STRING_CHARPOS (*it
);
7551 it
->bidi_it
.bytepos
= IT_STRING_BYTEPOS (*it
);
7555 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
7556 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
7559 if (it
->bidi_it
.charpos
== eob
)
7561 /* Nothing to do, but reset the FIRST_ELT flag, like
7562 bidi_paragraph_init does, because we are not going to
7564 it
->bidi_it
.first_elt
= 0;
7566 else if (it
->bidi_it
.charpos
== bob
7568 && (FETCH_CHAR (it
->bidi_it
.bytepos
- 1) == '\n'
7569 || FETCH_CHAR (it
->bidi_it
.bytepos
) == '\n')))
7571 /* If we are at the beginning of a line/string, we can produce
7572 the next element right away. */
7573 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7574 bidi_move_to_visually_next (&it
->bidi_it
);
7578 ptrdiff_t orig_bytepos
= it
->bidi_it
.bytepos
;
7580 /* We need to prime the bidi iterator starting at the line's or
7581 string's beginning, before we will be able to produce the
7584 it
->bidi_it
.charpos
= it
->bidi_it
.bytepos
= 0;
7586 it
->bidi_it
.charpos
= find_newline_no_quit (IT_CHARPOS (*it
),
7587 IT_BYTEPOS (*it
), -1,
7588 &it
->bidi_it
.bytepos
);
7589 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7592 /* Now return to buffer/string position where we were asked
7593 to get the next display element, and produce that. */
7594 bidi_move_to_visually_next (&it
->bidi_it
);
7596 while (it
->bidi_it
.bytepos
!= orig_bytepos
7597 && it
->bidi_it
.charpos
< eob
);
7600 /* Adjust IT's position information to where we ended up. */
7601 if (STRINGP (it
->string
))
7603 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7604 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7608 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7609 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7612 if (STRINGP (it
->string
) || !it
->s
)
7614 ptrdiff_t stop
, charpos
, bytepos
;
7616 if (STRINGP (it
->string
))
7619 stop
= SCHARS (it
->string
);
7620 if (stop
> it
->end_charpos
)
7621 stop
= it
->end_charpos
;
7622 charpos
= IT_STRING_CHARPOS (*it
);
7623 bytepos
= IT_STRING_BYTEPOS (*it
);
7627 stop
= it
->end_charpos
;
7628 charpos
= IT_CHARPOS (*it
);
7629 bytepos
= IT_BYTEPOS (*it
);
7631 if (it
->bidi_it
.scan_dir
< 0)
7633 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
, stop
,
7638 /* Load IT with the next display element from Lisp string IT->string.
7639 IT->current.string_pos is the current position within the string.
7640 If IT->current.overlay_string_index >= 0, the Lisp string is an
7644 next_element_from_string (struct it
*it
)
7646 struct text_pos position
;
7648 eassert (STRINGP (it
->string
));
7649 eassert (!it
->bidi_p
|| EQ (it
->string
, it
->bidi_it
.string
.lstring
));
7650 eassert (IT_STRING_CHARPOS (*it
) >= 0);
7651 position
= it
->current
.string_pos
;
7653 /* With bidi reordering, the character to display might not be the
7654 character at IT_STRING_CHARPOS. BIDI_IT.FIRST_ELT non-zero means
7655 that we were reseat()ed to a new string, whose paragraph
7656 direction is not known. */
7657 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7659 get_visually_first_element (it
);
7660 SET_TEXT_POS (position
, IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
));
7663 /* Time to check for invisible text? */
7664 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
7666 if (IT_STRING_CHARPOS (*it
) >= it
->stop_charpos
)
7669 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7670 || IT_STRING_CHARPOS (*it
) == it
->stop_charpos
))
7672 /* With bidi non-linear iteration, we could find
7673 ourselves far beyond the last computed stop_charpos,
7674 with several other stop positions in between that we
7675 missed. Scan them all now, in buffer's logical
7676 order, until we find and handle the last stop_charpos
7677 that precedes our current position. */
7678 handle_stop_backwards (it
, it
->stop_charpos
);
7679 return GET_NEXT_DISPLAY_ELEMENT (it
);
7685 /* Take note of the stop position we just moved
7686 across, for when we will move back across it. */
7687 it
->prev_stop
= it
->stop_charpos
;
7688 /* If we are at base paragraph embedding level, take
7689 note of the last stop position seen at this
7691 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7692 it
->base_level_stop
= it
->stop_charpos
;
7696 /* Since a handler may have changed IT->method, we must
7698 return GET_NEXT_DISPLAY_ELEMENT (it
);
7702 /* If we are before prev_stop, we may have overstepped
7703 on our way backwards a stop_pos, and if so, we need
7704 to handle that stop_pos. */
7705 && IT_STRING_CHARPOS (*it
) < it
->prev_stop
7706 /* We can sometimes back up for reasons that have nothing
7707 to do with bidi reordering. E.g., compositions. The
7708 code below is only needed when we are above the base
7709 embedding level, so test for that explicitly. */
7710 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7712 /* If we lost track of base_level_stop, we have no better
7713 place for handle_stop_backwards to start from than string
7714 beginning. This happens, e.g., when we were reseated to
7715 the previous screenful of text by vertical-motion. */
7716 if (it
->base_level_stop
<= 0
7717 || IT_STRING_CHARPOS (*it
) < it
->base_level_stop
)
7718 it
->base_level_stop
= 0;
7719 handle_stop_backwards (it
, it
->base_level_stop
);
7720 return GET_NEXT_DISPLAY_ELEMENT (it
);
7724 if (it
->current
.overlay_string_index
>= 0)
7726 /* Get the next character from an overlay string. In overlay
7727 strings, there is no field width or padding with spaces to
7729 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7734 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7735 IT_STRING_BYTEPOS (*it
),
7736 it
->bidi_it
.scan_dir
< 0
7738 : SCHARS (it
->string
))
7739 && next_element_from_composition (it
))
7743 else if (STRING_MULTIBYTE (it
->string
))
7745 const unsigned char *s
= (SDATA (it
->string
)
7746 + IT_STRING_BYTEPOS (*it
));
7747 it
->c
= string_char_and_length (s
, &it
->len
);
7751 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7757 /* Get the next character from a Lisp string that is not an
7758 overlay string. Such strings come from the mode line, for
7759 example. We may have to pad with spaces, or truncate the
7760 string. See also next_element_from_c_string. */
7761 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7766 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
7768 /* Pad with spaces. */
7769 it
->c
= ' ', it
->len
= 1;
7770 CHARPOS (position
) = BYTEPOS (position
) = -1;
7772 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7773 IT_STRING_BYTEPOS (*it
),
7774 it
->bidi_it
.scan_dir
< 0
7776 : it
->string_nchars
)
7777 && next_element_from_composition (it
))
7781 else if (STRING_MULTIBYTE (it
->string
))
7783 const unsigned char *s
= (SDATA (it
->string
)
7784 + IT_STRING_BYTEPOS (*it
));
7785 it
->c
= string_char_and_length (s
, &it
->len
);
7789 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7794 /* Record what we have and where it came from. */
7795 it
->what
= IT_CHARACTER
;
7796 it
->object
= it
->string
;
7797 it
->position
= position
;
7802 /* Load IT with next display element from C string IT->s.
7803 IT->string_nchars is the maximum number of characters to return
7804 from the string. IT->end_charpos may be greater than
7805 IT->string_nchars when this function is called, in which case we
7806 may have to return padding spaces. Value is zero if end of string
7807 reached, including padding spaces. */
7810 next_element_from_c_string (struct it
*it
)
7812 bool success_p
= true;
7815 eassert (!it
->bidi_p
|| it
->s
== it
->bidi_it
.string
.s
);
7816 it
->what
= IT_CHARACTER
;
7817 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
7820 /* With bidi reordering, the character to display might not be the
7821 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7822 we were reseated to a new string, whose paragraph direction is
7824 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7825 get_visually_first_element (it
);
7827 /* IT's position can be greater than IT->string_nchars in case a
7828 field width or precision has been specified when the iterator was
7830 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7832 /* End of the game. */
7836 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
7838 /* Pad with spaces. */
7839 it
->c
= ' ', it
->len
= 1;
7840 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
7842 else if (it
->multibyte_p
)
7843 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
), &it
->len
);
7845 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
7851 /* Set up IT to return characters from an ellipsis, if appropriate.
7852 The definition of the ellipsis glyphs may come from a display table
7853 entry. This function fills IT with the first glyph from the
7854 ellipsis if an ellipsis is to be displayed. */
7857 next_element_from_ellipsis (struct it
*it
)
7859 if (it
->selective_display_ellipsis_p
)
7860 setup_for_ellipsis (it
, it
->len
);
7863 /* The face at the current position may be different from the
7864 face we find after the invisible text. Remember what it
7865 was in IT->saved_face_id, and signal that it's there by
7866 setting face_before_selective_p. */
7867 it
->saved_face_id
= it
->face_id
;
7868 it
->method
= GET_FROM_BUFFER
;
7869 it
->object
= it
->w
->contents
;
7870 reseat_at_next_visible_line_start (it
, 1);
7871 it
->face_before_selective_p
= true;
7874 return GET_NEXT_DISPLAY_ELEMENT (it
);
7878 /* Deliver an image display element. The iterator IT is already
7879 filled with image information (done in handle_display_prop). Value
7884 next_element_from_image (struct it
*it
)
7886 it
->what
= IT_IMAGE
;
7887 it
->ignore_overlay_strings_at_pos_p
= 0;
7892 /* Fill iterator IT with next display element from a stretch glyph
7893 property. IT->object is the value of the text property. Value is
7897 next_element_from_stretch (struct it
*it
)
7899 it
->what
= IT_STRETCH
;
7903 /* Scan backwards from IT's current position until we find a stop
7904 position, or until BEGV. This is called when we find ourself
7905 before both the last known prev_stop and base_level_stop while
7906 reordering bidirectional text. */
7909 compute_stop_pos_backwards (struct it
*it
)
7911 const int SCAN_BACK_LIMIT
= 1000;
7912 struct text_pos pos
;
7913 struct display_pos save_current
= it
->current
;
7914 struct text_pos save_position
= it
->position
;
7915 ptrdiff_t charpos
= IT_CHARPOS (*it
);
7916 ptrdiff_t where_we_are
= charpos
;
7917 ptrdiff_t save_stop_pos
= it
->stop_charpos
;
7918 ptrdiff_t save_end_pos
= it
->end_charpos
;
7920 eassert (NILP (it
->string
) && !it
->s
);
7921 eassert (it
->bidi_p
);
7925 it
->end_charpos
= min (charpos
+ 1, ZV
);
7926 charpos
= max (charpos
- SCAN_BACK_LIMIT
, BEGV
);
7927 SET_TEXT_POS (pos
, charpos
, CHAR_TO_BYTE (charpos
));
7928 reseat_1 (it
, pos
, 0);
7929 compute_stop_pos (it
);
7930 /* We must advance forward, right? */
7931 if (it
->stop_charpos
<= charpos
)
7934 while (charpos
> BEGV
&& it
->stop_charpos
>= it
->end_charpos
);
7936 if (it
->stop_charpos
<= where_we_are
)
7937 it
->prev_stop
= it
->stop_charpos
;
7939 it
->prev_stop
= BEGV
;
7941 it
->current
= save_current
;
7942 it
->position
= save_position
;
7943 it
->stop_charpos
= save_stop_pos
;
7944 it
->end_charpos
= save_end_pos
;
7947 /* Scan forward from CHARPOS in the current buffer/string, until we
7948 find a stop position > current IT's position. Then handle the stop
7949 position before that. This is called when we bump into a stop
7950 position while reordering bidirectional text. CHARPOS should be
7951 the last previously processed stop_pos (or BEGV/0, if none were
7952 processed yet) whose position is less that IT's current
7956 handle_stop_backwards (struct it
*it
, ptrdiff_t charpos
)
7958 int bufp
= !STRINGP (it
->string
);
7959 ptrdiff_t where_we_are
= (bufp
? IT_CHARPOS (*it
) : IT_STRING_CHARPOS (*it
));
7960 struct display_pos save_current
= it
->current
;
7961 struct text_pos save_position
= it
->position
;
7962 struct text_pos pos1
;
7963 ptrdiff_t next_stop
;
7965 /* Scan in strict logical order. */
7966 eassert (it
->bidi_p
);
7970 it
->prev_stop
= charpos
;
7973 SET_TEXT_POS (pos1
, charpos
, CHAR_TO_BYTE (charpos
));
7974 reseat_1 (it
, pos1
, 0);
7977 it
->current
.string_pos
= string_pos (charpos
, it
->string
);
7978 compute_stop_pos (it
);
7979 /* We must advance forward, right? */
7980 if (it
->stop_charpos
<= it
->prev_stop
)
7982 charpos
= it
->stop_charpos
;
7984 while (charpos
<= where_we_are
);
7987 it
->current
= save_current
;
7988 it
->position
= save_position
;
7989 next_stop
= it
->stop_charpos
;
7990 it
->stop_charpos
= it
->prev_stop
;
7992 it
->stop_charpos
= next_stop
;
7995 /* Load IT with the next display element from current_buffer. Value
7996 is zero if end of buffer reached. IT->stop_charpos is the next
7997 position at which to stop and check for text properties or buffer
8001 next_element_from_buffer (struct it
*it
)
8003 bool success_p
= true;
8005 eassert (IT_CHARPOS (*it
) >= BEGV
);
8006 eassert (NILP (it
->string
) && !it
->s
);
8007 eassert (!it
->bidi_p
8008 || (EQ (it
->bidi_it
.string
.lstring
, Qnil
)
8009 && it
->bidi_it
.string
.s
== NULL
));
8011 /* With bidi reordering, the character to display might not be the
8012 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
8013 we were reseat()ed to a new buffer position, which is potentially
8014 a different paragraph. */
8015 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
8017 get_visually_first_element (it
);
8018 SET_TEXT_POS (it
->position
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8021 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
8023 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
8025 int overlay_strings_follow_p
;
8027 /* End of the game, except when overlay strings follow that
8028 haven't been returned yet. */
8029 if (it
->overlay_strings_at_end_processed_p
)
8030 overlay_strings_follow_p
= 0;
8033 it
->overlay_strings_at_end_processed_p
= true;
8034 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
8037 if (overlay_strings_follow_p
)
8038 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
8042 it
->position
= it
->current
.pos
;
8046 else if (!(!it
->bidi_p
8047 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
8048 || IT_CHARPOS (*it
) == it
->stop_charpos
))
8050 /* With bidi non-linear iteration, we could find ourselves
8051 far beyond the last computed stop_charpos, with several
8052 other stop positions in between that we missed. Scan
8053 them all now, in buffer's logical order, until we find
8054 and handle the last stop_charpos that precedes our
8055 current position. */
8056 handle_stop_backwards (it
, it
->stop_charpos
);
8057 return GET_NEXT_DISPLAY_ELEMENT (it
);
8063 /* Take note of the stop position we just moved across,
8064 for when we will move back across it. */
8065 it
->prev_stop
= it
->stop_charpos
;
8066 /* If we are at base paragraph embedding level, take
8067 note of the last stop position seen at this
8069 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8070 it
->base_level_stop
= it
->stop_charpos
;
8073 return GET_NEXT_DISPLAY_ELEMENT (it
);
8077 /* If we are before prev_stop, we may have overstepped on
8078 our way backwards a stop_pos, and if so, we need to
8079 handle that stop_pos. */
8080 && IT_CHARPOS (*it
) < it
->prev_stop
8081 /* We can sometimes back up for reasons that have nothing
8082 to do with bidi reordering. E.g., compositions. The
8083 code below is only needed when we are above the base
8084 embedding level, so test for that explicitly. */
8085 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8087 if (it
->base_level_stop
<= 0
8088 || IT_CHARPOS (*it
) < it
->base_level_stop
)
8090 /* If we lost track of base_level_stop, we need to find
8091 prev_stop by looking backwards. This happens, e.g., when
8092 we were reseated to the previous screenful of text by
8094 it
->base_level_stop
= BEGV
;
8095 compute_stop_pos_backwards (it
);
8096 handle_stop_backwards (it
, it
->prev_stop
);
8099 handle_stop_backwards (it
, it
->base_level_stop
);
8100 return GET_NEXT_DISPLAY_ELEMENT (it
);
8104 /* No face changes, overlays etc. in sight, so just return a
8105 character from current_buffer. */
8109 /* Maybe run the redisplay end trigger hook. Performance note:
8110 This doesn't seem to cost measurable time. */
8111 if (it
->redisplay_end_trigger_charpos
8113 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
8114 run_redisplay_end_trigger_hook (it
);
8116 stop
= it
->bidi_it
.scan_dir
< 0 ? -1 : it
->end_charpos
;
8117 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
8119 && next_element_from_composition (it
))
8124 /* Get the next character, maybe multibyte. */
8125 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
8126 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
8127 it
->c
= STRING_CHAR_AND_LENGTH (p
, it
->len
);
8129 it
->c
= *p
, it
->len
= 1;
8131 /* Record what we have and where it came from. */
8132 it
->what
= IT_CHARACTER
;
8133 it
->object
= it
->w
->contents
;
8134 it
->position
= it
->current
.pos
;
8136 /* Normally we return the character found above, except when we
8137 really want to return an ellipsis for selective display. */
8142 /* A value of selective > 0 means hide lines indented more
8143 than that number of columns. */
8144 if (it
->selective
> 0
8145 && IT_CHARPOS (*it
) + 1 < ZV
8146 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
8147 IT_BYTEPOS (*it
) + 1,
8150 success_p
= next_element_from_ellipsis (it
);
8151 it
->dpvec_char_len
= -1;
8154 else if (it
->c
== '\r' && it
->selective
== -1)
8156 /* A value of selective == -1 means that everything from the
8157 CR to the end of the line is invisible, with maybe an
8158 ellipsis displayed for it. */
8159 success_p
= next_element_from_ellipsis (it
);
8160 it
->dpvec_char_len
= -1;
8165 /* Value is zero if end of buffer reached. */
8166 eassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
8171 /* Run the redisplay end trigger hook for IT. */
8174 run_redisplay_end_trigger_hook (struct it
*it
)
8176 Lisp_Object args
[3];
8178 /* IT->glyph_row should be non-null, i.e. we should be actually
8179 displaying something, or otherwise we should not run the hook. */
8180 eassert (it
->glyph_row
);
8182 /* Set up hook arguments. */
8183 args
[0] = Qredisplay_end_trigger_functions
;
8184 args
[1] = it
->window
;
8185 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
8186 it
->redisplay_end_trigger_charpos
= 0;
8188 /* Since we are *trying* to run these functions, don't try to run
8189 them again, even if they get an error. */
8190 wset_redisplay_end_trigger (it
->w
, Qnil
);
8191 Frun_hook_with_args (3, args
);
8193 /* Notice if it changed the face of the character we are on. */
8194 handle_face_prop (it
);
8198 /* Deliver a composition display element. Unlike the other
8199 next_element_from_XXX, this function is not registered in the array
8200 get_next_element[]. It is called from next_element_from_buffer and
8201 next_element_from_string when necessary. */
8204 next_element_from_composition (struct it
*it
)
8206 it
->what
= IT_COMPOSITION
;
8207 it
->len
= it
->cmp_it
.nbytes
;
8208 if (STRINGP (it
->string
))
8212 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
8213 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
8216 it
->position
= it
->current
.string_pos
;
8217 it
->object
= it
->string
;
8218 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
8219 IT_STRING_BYTEPOS (*it
), it
->string
);
8225 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
8226 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
8229 if (it
->bidi_it
.new_paragraph
)
8230 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
8231 /* Resync the bidi iterator with IT's new position.
8232 FIXME: this doesn't support bidirectional text. */
8233 while (it
->bidi_it
.charpos
< IT_CHARPOS (*it
))
8234 bidi_move_to_visually_next (&it
->bidi_it
);
8238 it
->position
= it
->current
.pos
;
8239 it
->object
= it
->w
->contents
;
8240 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
8241 IT_BYTEPOS (*it
), Qnil
);
8248 /***********************************************************************
8249 Moving an iterator without producing glyphs
8250 ***********************************************************************/
8252 /* Check if iterator is at a position corresponding to a valid buffer
8253 position after some move_it_ call. */
8255 #define IT_POS_VALID_AFTER_MOVE_P(it) \
8256 ((it)->method == GET_FROM_STRING \
8257 ? IT_STRING_CHARPOS (*it) == 0 \
8261 /* Move iterator IT to a specified buffer or X position within one
8262 line on the display without producing glyphs.
8264 OP should be a bit mask including some or all of these bits:
8265 MOVE_TO_X: Stop upon reaching x-position TO_X.
8266 MOVE_TO_POS: Stop upon reaching buffer or string position TO_CHARPOS.
8267 Regardless of OP's value, stop upon reaching the end of the display line.
8269 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
8270 This means, in particular, that TO_X includes window's horizontal
8273 The return value has several possible values that
8274 say what condition caused the scan to stop:
8276 MOVE_POS_MATCH_OR_ZV
8277 - when TO_POS or ZV was reached.
8280 -when TO_X was reached before TO_POS or ZV were reached.
8283 - when we reached the end of the display area and the line must
8287 - when we reached the end of the display area and the line is
8291 - when we stopped at a line end, i.e. a newline or a CR and selective
8294 static enum move_it_result
8295 move_it_in_display_line_to (struct it
*it
,
8296 ptrdiff_t to_charpos
, int to_x
,
8297 enum move_operation_enum op
)
8299 enum move_it_result result
= MOVE_UNDEFINED
;
8300 struct glyph_row
*saved_glyph_row
;
8301 struct it wrap_it
, atpos_it
, atx_it
, ppos_it
;
8302 void *wrap_data
= NULL
, *atpos_data
= NULL
, *atx_data
= NULL
;
8303 void *ppos_data
= NULL
;
8305 enum it_method prev_method
= it
->method
;
8306 ptrdiff_t prev_pos
= IT_CHARPOS (*it
);
8307 int saw_smaller_pos
= prev_pos
< to_charpos
;
8309 /* Don't produce glyphs in produce_glyphs. */
8310 saved_glyph_row
= it
->glyph_row
;
8311 it
->glyph_row
= NULL
;
8313 /* Use wrap_it to save a copy of IT wherever a word wrap could
8314 occur. Use atpos_it to save a copy of IT at the desired buffer
8315 position, if found, so that we can scan ahead and check if the
8316 word later overshoots the window edge. Use atx_it similarly, for
8322 /* Use ppos_it under bidi reordering to save a copy of IT for the
8323 position > CHARPOS that is the closest to CHARPOS. We restore
8324 that position in IT when we have scanned the entire display line
8325 without finding a match for CHARPOS and all the character
8326 positions are greater than CHARPOS. */
8329 SAVE_IT (ppos_it
, *it
, ppos_data
);
8330 SET_TEXT_POS (ppos_it
.current
.pos
, ZV
, ZV_BYTE
);
8331 if ((op
& MOVE_TO_POS
) && IT_CHARPOS (*it
) >= to_charpos
)
8332 SAVE_IT (ppos_it
, *it
, ppos_data
);
8335 #define BUFFER_POS_REACHED_P() \
8336 ((op & MOVE_TO_POS) != 0 \
8337 && BUFFERP (it->object) \
8338 && (IT_CHARPOS (*it) == to_charpos \
8340 || BIDI_AT_BASE_LEVEL (it->bidi_it)) \
8341 && IT_CHARPOS (*it) > to_charpos) \
8342 || (it->what == IT_COMPOSITION \
8343 && ((IT_CHARPOS (*it) > to_charpos \
8344 && to_charpos >= it->cmp_it.charpos) \
8345 || (IT_CHARPOS (*it) < to_charpos \
8346 && to_charpos <= it->cmp_it.charpos)))) \
8347 && (it->method == GET_FROM_BUFFER \
8348 || (it->method == GET_FROM_DISPLAY_VECTOR \
8349 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
8351 /* If there's a line-/wrap-prefix, handle it. */
8352 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
8353 && it
->current_y
< it
->last_visible_y
)
8354 handle_line_prefix (it
);
8356 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8357 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8361 int x
, i
, ascent
= 0, descent
= 0;
8363 /* Utility macro to reset an iterator with x, ascent, and descent. */
8364 #define IT_RESET_X_ASCENT_DESCENT(IT) \
8365 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
8366 (IT)->max_descent = descent)
8368 /* Stop if we move beyond TO_CHARPOS (after an image or a
8369 display string or stretch glyph). */
8370 if ((op
& MOVE_TO_POS
) != 0
8371 && BUFFERP (it
->object
)
8372 && it
->method
== GET_FROM_BUFFER
8374 /* When the iterator is at base embedding level, we
8375 are guaranteed that characters are delivered for
8376 display in strictly increasing order of their
8377 buffer positions. */
8378 || BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8379 && IT_CHARPOS (*it
) > to_charpos
)
8381 && (prev_method
== GET_FROM_IMAGE
8382 || prev_method
== GET_FROM_STRETCH
8383 || prev_method
== GET_FROM_STRING
)
8384 /* Passed TO_CHARPOS from left to right. */
8385 && ((prev_pos
< to_charpos
8386 && IT_CHARPOS (*it
) > to_charpos
)
8387 /* Passed TO_CHARPOS from right to left. */
8388 || (prev_pos
> to_charpos
8389 && IT_CHARPOS (*it
) < to_charpos
)))))
8391 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8393 result
= MOVE_POS_MATCH_OR_ZV
;
8396 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8397 /* If wrap_it is valid, the current position might be in a
8398 word that is wrapped. So, save the iterator in
8399 atpos_it and continue to see if wrapping happens. */
8400 SAVE_IT (atpos_it
, *it
, atpos_data
);
8403 /* Stop when ZV reached.
8404 We used to stop here when TO_CHARPOS reached as well, but that is
8405 too soon if this glyph does not fit on this line. So we handle it
8406 explicitly below. */
8407 if (!get_next_display_element (it
))
8409 result
= MOVE_POS_MATCH_OR_ZV
;
8413 if (it
->line_wrap
== TRUNCATE
)
8415 if (BUFFER_POS_REACHED_P ())
8417 result
= MOVE_POS_MATCH_OR_ZV
;
8423 if (it
->line_wrap
== WORD_WRAP
)
8425 if (IT_DISPLAYING_WHITESPACE (it
))
8429 /* We have reached a glyph that follows one or more
8430 whitespace characters. If the position is
8431 already found, we are done. */
8432 if (atpos_it
.sp
>= 0)
8434 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8435 result
= MOVE_POS_MATCH_OR_ZV
;
8440 RESTORE_IT (it
, &atx_it
, atx_data
);
8441 result
= MOVE_X_REACHED
;
8444 /* Otherwise, we can wrap here. */
8445 SAVE_IT (wrap_it
, *it
, wrap_data
);
8451 /* Remember the line height for the current line, in case
8452 the next element doesn't fit on the line. */
8453 ascent
= it
->max_ascent
;
8454 descent
= it
->max_descent
;
8456 /* The call to produce_glyphs will get the metrics of the
8457 display element IT is loaded with. Record the x-position
8458 before this display element, in case it doesn't fit on the
8462 PRODUCE_GLYPHS (it
);
8464 if (it
->area
!= TEXT_AREA
)
8466 prev_method
= it
->method
;
8467 if (it
->method
== GET_FROM_BUFFER
)
8468 prev_pos
= IT_CHARPOS (*it
);
8469 set_iterator_to_next (it
, 1);
8470 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8471 SET_TEXT_POS (this_line_min_pos
,
8472 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8474 && (op
& MOVE_TO_POS
)
8475 && IT_CHARPOS (*it
) > to_charpos
8476 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8477 SAVE_IT (ppos_it
, *it
, ppos_data
);
8481 /* The number of glyphs we get back in IT->nglyphs will normally
8482 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
8483 character on a terminal frame, or (iii) a line end. For the
8484 second case, IT->nglyphs - 1 padding glyphs will be present.
8485 (On X frames, there is only one glyph produced for a
8486 composite character.)
8488 The behavior implemented below means, for continuation lines,
8489 that as many spaces of a TAB as fit on the current line are
8490 displayed there. For terminal frames, as many glyphs of a
8491 multi-glyph character are displayed in the current line, too.
8492 This is what the old redisplay code did, and we keep it that
8493 way. Under X, the whole shape of a complex character must
8494 fit on the line or it will be completely displayed in the
8497 Note that both for tabs and padding glyphs, all glyphs have
8501 /* More than one glyph or glyph doesn't fit on line. All
8502 glyphs have the same width. */
8503 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
8505 int x_before_this_char
= x
;
8506 int hpos_before_this_char
= it
->hpos
;
8508 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
8510 new_x
= x
+ single_glyph_width
;
8512 /* We want to leave anything reaching TO_X to the caller. */
8513 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
8515 if (BUFFER_POS_REACHED_P ())
8517 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8518 goto buffer_pos_reached
;
8519 if (atpos_it
.sp
< 0)
8521 SAVE_IT (atpos_it
, *it
, atpos_data
);
8522 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8527 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8530 result
= MOVE_X_REACHED
;
8535 SAVE_IT (atx_it
, *it
, atx_data
);
8536 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
8541 if (/* Lines are continued. */
8542 it
->line_wrap
!= TRUNCATE
8543 && (/* And glyph doesn't fit on the line. */
8544 new_x
> it
->last_visible_x
8545 /* Or it fits exactly and we're on a window
8547 || (new_x
== it
->last_visible_x
8548 && FRAME_WINDOW_P (it
->f
)
8549 && ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
8550 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8551 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
8553 if (/* IT->hpos == 0 means the very first glyph
8554 doesn't fit on the line, e.g. a wide image. */
8556 || (new_x
== it
->last_visible_x
8557 && FRAME_WINDOW_P (it
->f
)))
8560 it
->current_x
= new_x
;
8562 /* The character's last glyph just barely fits
8564 if (i
== it
->nglyphs
- 1)
8566 /* If this is the destination position,
8567 return a position *before* it in this row,
8568 now that we know it fits in this row. */
8569 if (BUFFER_POS_REACHED_P ())
8571 if (it
->line_wrap
!= WORD_WRAP
8574 it
->hpos
= hpos_before_this_char
;
8575 it
->current_x
= x_before_this_char
;
8576 result
= MOVE_POS_MATCH_OR_ZV
;
8579 if (it
->line_wrap
== WORD_WRAP
8582 SAVE_IT (atpos_it
, *it
, atpos_data
);
8583 atpos_it
.current_x
= x_before_this_char
;
8584 atpos_it
.hpos
= hpos_before_this_char
;
8588 prev_method
= it
->method
;
8589 if (it
->method
== GET_FROM_BUFFER
)
8590 prev_pos
= IT_CHARPOS (*it
);
8591 set_iterator_to_next (it
, 1);
8592 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8593 SET_TEXT_POS (this_line_min_pos
,
8594 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8595 /* On graphical terminals, newlines may
8596 "overflow" into the fringe if
8597 overflow-newline-into-fringe is non-nil.
8598 On text terminals, and on graphical
8599 terminals with no right margin, newlines
8600 may overflow into the last glyph on the
8602 if (!FRAME_WINDOW_P (it
->f
)
8604 && it
->bidi_it
.paragraph_dir
== R2L
)
8605 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8606 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0
8607 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8609 if (!get_next_display_element (it
))
8611 result
= MOVE_POS_MATCH_OR_ZV
;
8614 if (BUFFER_POS_REACHED_P ())
8616 if (ITERATOR_AT_END_OF_LINE_P (it
))
8617 result
= MOVE_POS_MATCH_OR_ZV
;
8619 result
= MOVE_LINE_CONTINUED
;
8622 if (ITERATOR_AT_END_OF_LINE_P (it
)
8623 && (it
->line_wrap
!= WORD_WRAP
8626 result
= MOVE_NEWLINE_OR_CR
;
8633 IT_RESET_X_ASCENT_DESCENT (it
);
8635 if (wrap_it
.sp
>= 0)
8637 RESTORE_IT (it
, &wrap_it
, wrap_data
);
8642 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
8644 result
= MOVE_LINE_CONTINUED
;
8648 if (BUFFER_POS_REACHED_P ())
8650 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8651 goto buffer_pos_reached
;
8652 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8654 SAVE_IT (atpos_it
, *it
, atpos_data
);
8655 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8659 if (new_x
> it
->first_visible_x
)
8661 /* Glyph is visible. Increment number of glyphs that
8662 would be displayed. */
8667 if (result
!= MOVE_UNDEFINED
)
8670 else if (BUFFER_POS_REACHED_P ())
8673 IT_RESET_X_ASCENT_DESCENT (it
);
8674 result
= MOVE_POS_MATCH_OR_ZV
;
8677 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
8679 /* Stop when TO_X specified and reached. This check is
8680 necessary here because of lines consisting of a line end,
8681 only. The line end will not produce any glyphs and we
8682 would never get MOVE_X_REACHED. */
8683 eassert (it
->nglyphs
== 0);
8684 result
= MOVE_X_REACHED
;
8688 /* Is this a line end? If yes, we're done. */
8689 if (ITERATOR_AT_END_OF_LINE_P (it
))
8691 /* If we are past TO_CHARPOS, but never saw any character
8692 positions smaller than TO_CHARPOS, return
8693 MOVE_POS_MATCH_OR_ZV, like the unidirectional display
8695 if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0)
8697 if (!saw_smaller_pos
&& IT_CHARPOS (*it
) > to_charpos
)
8699 if (IT_CHARPOS (ppos_it
) < ZV
)
8701 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8702 result
= MOVE_POS_MATCH_OR_ZV
;
8705 goto buffer_pos_reached
;
8707 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
>= 0
8708 && IT_CHARPOS (*it
) > to_charpos
)
8709 goto buffer_pos_reached
;
8711 result
= MOVE_NEWLINE_OR_CR
;
8714 result
= MOVE_NEWLINE_OR_CR
;
8718 prev_method
= it
->method
;
8719 if (it
->method
== GET_FROM_BUFFER
)
8720 prev_pos
= IT_CHARPOS (*it
);
8721 /* The current display element has been consumed. Advance
8723 set_iterator_to_next (it
, 1);
8724 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8725 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8726 if (IT_CHARPOS (*it
) < to_charpos
)
8727 saw_smaller_pos
= 1;
8729 && (op
& MOVE_TO_POS
)
8730 && IT_CHARPOS (*it
) >= to_charpos
8731 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8732 SAVE_IT (ppos_it
, *it
, ppos_data
);
8734 /* Stop if lines are truncated and IT's current x-position is
8735 past the right edge of the window now. */
8736 if (it
->line_wrap
== TRUNCATE
8737 && it
->current_x
>= it
->last_visible_x
)
8739 if (!FRAME_WINDOW_P (it
->f
)
8740 || ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
8741 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8742 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0
8743 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8747 if ((at_eob_p
= !get_next_display_element (it
))
8748 || BUFFER_POS_REACHED_P ()
8749 /* If we are past TO_CHARPOS, but never saw any
8750 character positions smaller than TO_CHARPOS,
8751 return MOVE_POS_MATCH_OR_ZV, like the
8752 unidirectional display did. */
8753 || (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8755 && IT_CHARPOS (*it
) > to_charpos
))
8758 && !at_eob_p
&& IT_CHARPOS (ppos_it
) < ZV
)
8759 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8760 result
= MOVE_POS_MATCH_OR_ZV
;
8763 if (ITERATOR_AT_END_OF_LINE_P (it
))
8765 result
= MOVE_NEWLINE_OR_CR
;
8769 else if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8771 && IT_CHARPOS (*it
) > to_charpos
)
8773 if (IT_CHARPOS (ppos_it
) < ZV
)
8774 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8775 result
= MOVE_POS_MATCH_OR_ZV
;
8778 result
= MOVE_LINE_TRUNCATED
;
8781 #undef IT_RESET_X_ASCENT_DESCENT
8784 #undef BUFFER_POS_REACHED_P
8786 /* If we scanned beyond to_pos and didn't find a point to wrap at,
8787 restore the saved iterator. */
8788 if (atpos_it
.sp
>= 0)
8789 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8790 else if (atx_it
.sp
>= 0)
8791 RESTORE_IT (it
, &atx_it
, atx_data
);
8796 bidi_unshelve_cache (atpos_data
, 1);
8798 bidi_unshelve_cache (atx_data
, 1);
8800 bidi_unshelve_cache (wrap_data
, 1);
8802 bidi_unshelve_cache (ppos_data
, 1);
8804 /* Restore the iterator settings altered at the beginning of this
8806 it
->glyph_row
= saved_glyph_row
;
8810 /* For external use. */
8812 move_it_in_display_line (struct it
*it
,
8813 ptrdiff_t to_charpos
, int to_x
,
8814 enum move_operation_enum op
)
8816 if (it
->line_wrap
== WORD_WRAP
8817 && (op
& MOVE_TO_X
))
8820 void *save_data
= NULL
;
8823 SAVE_IT (save_it
, *it
, save_data
);
8824 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8825 /* When word-wrap is on, TO_X may lie past the end
8826 of a wrapped line. Then it->current is the
8827 character on the next line, so backtrack to the
8828 space before the wrap point. */
8829 if (skip
== MOVE_LINE_CONTINUED
)
8831 int prev_x
= max (it
->current_x
- 1, 0);
8832 RESTORE_IT (it
, &save_it
, save_data
);
8833 move_it_in_display_line_to
8834 (it
, -1, prev_x
, MOVE_TO_X
);
8837 bidi_unshelve_cache (save_data
, 1);
8840 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8844 /* Move IT forward until it satisfies one or more of the criteria in
8845 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
8847 OP is a bit-mask that specifies where to stop, and in particular,
8848 which of those four position arguments makes a difference. See the
8849 description of enum move_operation_enum.
8851 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
8852 screen line, this function will set IT to the next position that is
8853 displayed to the right of TO_CHARPOS on the screen.
8855 Return the maximum pixel length of any line scanned but never more
8856 than it.last_visible_x. */
8859 move_it_to (struct it
*it
, ptrdiff_t to_charpos
, int to_x
, int to_y
, int to_vpos
, int op
)
8861 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
8862 int line_height
, line_start_x
= 0, reached
= 0;
8863 int max_current_x
= 0;
8864 void *backup_data
= NULL
;
8868 if (op
& MOVE_TO_VPOS
)
8870 /* If no TO_CHARPOS and no TO_X specified, stop at the
8871 start of the line TO_VPOS. */
8872 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
8874 if (it
->vpos
== to_vpos
)
8880 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
8884 /* TO_VPOS >= 0 means stop at TO_X in the line at
8885 TO_VPOS, or at TO_POS, whichever comes first. */
8886 if (it
->vpos
== to_vpos
)
8892 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8894 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
8899 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
8901 /* We have reached TO_X but not in the line we want. */
8902 skip
= move_it_in_display_line_to (it
, to_charpos
,
8904 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8912 else if (op
& MOVE_TO_Y
)
8914 struct it it_backup
;
8916 if (it
->line_wrap
== WORD_WRAP
)
8917 SAVE_IT (it_backup
, *it
, backup_data
);
8919 /* TO_Y specified means stop at TO_X in the line containing
8920 TO_Y---or at TO_CHARPOS if this is reached first. The
8921 problem is that we can't really tell whether the line
8922 contains TO_Y before we have completely scanned it, and
8923 this may skip past TO_X. What we do is to first scan to
8926 If TO_X is not specified, use a TO_X of zero. The reason
8927 is to make the outcome of this function more predictable.
8928 If we didn't use TO_X == 0, we would stop at the end of
8929 the line which is probably not what a caller would expect
8931 skip
= move_it_in_display_line_to
8932 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
8933 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
8935 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
8936 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8938 else if (skip
== MOVE_X_REACHED
)
8940 /* If TO_X was reached, we want to know whether TO_Y is
8941 in the line. We know this is the case if the already
8942 scanned glyphs make the line tall enough. Otherwise,
8943 we must check by scanning the rest of the line. */
8944 line_height
= it
->max_ascent
+ it
->max_descent
;
8945 if (to_y
>= it
->current_y
8946 && to_y
< it
->current_y
+ line_height
)
8951 SAVE_IT (it_backup
, *it
, backup_data
);
8952 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
8953 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
8955 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
8956 line_height
= it
->max_ascent
+ it
->max_descent
;
8957 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8959 if (to_y
>= it
->current_y
8960 && to_y
< it
->current_y
+ line_height
)
8962 /* If TO_Y is in this line and TO_X was reached
8963 above, we scanned too far. We have to restore
8964 IT's settings to the ones before skipping. But
8965 keep the more accurate values of max_ascent and
8966 max_descent we've found while skipping the rest
8967 of the line, for the sake of callers, such as
8968 pos_visible_p, that need to know the line
8970 int max_ascent
= it
->max_ascent
;
8971 int max_descent
= it
->max_descent
;
8973 RESTORE_IT (it
, &it_backup
, backup_data
);
8974 it
->max_ascent
= max_ascent
;
8975 it
->max_descent
= max_descent
;
8981 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8987 /* Check whether TO_Y is in this line. */
8988 line_height
= it
->max_ascent
+ it
->max_descent
;
8989 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8991 if (to_y
>= it
->current_y
8992 && to_y
< it
->current_y
+ line_height
)
8994 if (to_y
> it
->current_y
)
8995 max_current_x
= max (it
->current_x
, max_current_x
);
8997 /* When word-wrap is on, TO_X may lie past the end
8998 of a wrapped line. Then it->current is the
8999 character on the next line, so backtrack to the
9000 space before the wrap point. */
9001 if (skip
== MOVE_LINE_CONTINUED
9002 && it
->line_wrap
== WORD_WRAP
)
9004 int prev_x
= max (it
->current_x
- 1, 0);
9005 RESTORE_IT (it
, &it_backup
, backup_data
);
9006 skip
= move_it_in_display_line_to
9007 (it
, -1, prev_x
, MOVE_TO_X
);
9016 max_current_x
= max (it
->current_x
, max_current_x
);
9020 else if (BUFFERP (it
->object
)
9021 && (it
->method
== GET_FROM_BUFFER
9022 || it
->method
== GET_FROM_STRETCH
)
9023 && IT_CHARPOS (*it
) >= to_charpos
9024 /* Under bidi iteration, a call to set_iterator_to_next
9025 can scan far beyond to_charpos if the initial
9026 portion of the next line needs to be reordered. In
9027 that case, give move_it_in_display_line_to another
9030 && it
->bidi_it
.scan_dir
== -1))
9031 skip
= MOVE_POS_MATCH_OR_ZV
;
9033 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
9037 case MOVE_POS_MATCH_OR_ZV
:
9038 max_current_x
= max (it
->current_x
, max_current_x
);
9042 case MOVE_NEWLINE_OR_CR
:
9043 max_current_x
= max (it
->current_x
, max_current_x
);
9044 set_iterator_to_next (it
, 1);
9045 it
->continuation_lines_width
= 0;
9048 case MOVE_LINE_TRUNCATED
:
9049 max_current_x
= it
->last_visible_x
;
9050 it
->continuation_lines_width
= 0;
9051 reseat_at_next_visible_line_start (it
, 0);
9052 if ((op
& MOVE_TO_POS
) != 0
9053 && IT_CHARPOS (*it
) > to_charpos
)
9060 case MOVE_LINE_CONTINUED
:
9061 max_current_x
= it
->last_visible_x
;
9062 /* For continued lines ending in a tab, some of the glyphs
9063 associated with the tab are displayed on the current
9064 line. Since it->current_x does not include these glyphs,
9065 we use it->last_visible_x instead. */
9068 it
->continuation_lines_width
+= it
->last_visible_x
;
9069 /* When moving by vpos, ensure that the iterator really
9070 advances to the next line (bug#847, bug#969). Fixme:
9071 do we need to do this in other circumstances? */
9072 if (it
->current_x
!= it
->last_visible_x
9073 && (op
& MOVE_TO_VPOS
)
9074 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
9076 line_start_x
= it
->current_x
+ it
->pixel_width
9077 - it
->last_visible_x
;
9078 set_iterator_to_next (it
, 0);
9082 it
->continuation_lines_width
+= it
->current_x
;
9089 /* Reset/increment for the next run. */
9090 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
9091 it
->current_x
= line_start_x
;
9094 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
9096 last_height
= it
->max_ascent
+ it
->max_descent
;
9097 last_max_ascent
= it
->max_ascent
;
9098 it
->max_ascent
= it
->max_descent
= 0;
9103 /* On text terminals, we may stop at the end of a line in the middle
9104 of a multi-character glyph. If the glyph itself is continued,
9105 i.e. it is actually displayed on the next line, don't treat this
9106 stopping point as valid; move to the next line instead (unless
9107 that brings us offscreen). */
9108 if (!FRAME_WINDOW_P (it
->f
)
9110 && IT_CHARPOS (*it
) == to_charpos
9111 && it
->what
== IT_CHARACTER
9113 && it
->line_wrap
== WINDOW_WRAP
9114 && it
->current_x
== it
->last_visible_x
- 1
9117 && it
->vpos
< it
->w
->window_end_vpos
)
9119 it
->continuation_lines_width
+= it
->current_x
;
9120 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
9121 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
9123 last_height
= it
->max_ascent
+ it
->max_descent
;
9124 last_max_ascent
= it
->max_ascent
;
9128 bidi_unshelve_cache (backup_data
, 1);
9130 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
9132 return max_current_x
;
9136 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
9138 If DY > 0, move IT backward at least that many pixels. DY = 0
9139 means move IT backward to the preceding line start or BEGV. This
9140 function may move over more than DY pixels if IT->current_y - DY
9141 ends up in the middle of a line; in this case IT->current_y will be
9142 set to the top of the line moved to. */
9145 move_it_vertically_backward (struct it
*it
, int dy
)
9149 void *it2data
= NULL
, *it3data
= NULL
;
9150 ptrdiff_t start_pos
;
9152 = (it
->last_visible_x
- it
->first_visible_x
) / FRAME_COLUMN_WIDTH (it
->f
);
9153 ptrdiff_t pos_limit
;
9158 start_pos
= IT_CHARPOS (*it
);
9160 /* Estimate how many newlines we must move back. */
9161 nlines
= max (1, dy
/ default_line_pixel_height (it
->w
));
9162 if (it
->line_wrap
== TRUNCATE
)
9165 pos_limit
= max (start_pos
- nlines
* nchars_per_row
, BEGV
);
9167 /* Set the iterator's position that many lines back. But don't go
9168 back more than NLINES full screen lines -- this wins a day with
9169 buffers which have very long lines. */
9170 while (nlines
-- && IT_CHARPOS (*it
) > pos_limit
)
9171 back_to_previous_visible_line_start (it
);
9173 /* Reseat the iterator here. When moving backward, we don't want
9174 reseat to skip forward over invisible text, set up the iterator
9175 to deliver from overlay strings at the new position etc. So,
9176 use reseat_1 here. */
9177 reseat_1 (it
, it
->current
.pos
, 1);
9179 /* We are now surely at a line start. */
9180 it
->current_x
= it
->hpos
= 0; /* FIXME: this is incorrect when bidi
9181 reordering is in effect. */
9182 it
->continuation_lines_width
= 0;
9184 /* Move forward and see what y-distance we moved. First move to the
9185 start of the next line so that we get its height. We need this
9186 height to be able to tell whether we reached the specified
9188 SAVE_IT (it2
, *it
, it2data
);
9189 it2
.max_ascent
= it2
.max_descent
= 0;
9192 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
9193 MOVE_TO_POS
| MOVE_TO_VPOS
);
9195 while (!(IT_POS_VALID_AFTER_MOVE_P (&it2
)
9196 /* If we are in a display string which starts at START_POS,
9197 and that display string includes a newline, and we are
9198 right after that newline (i.e. at the beginning of a
9199 display line), exit the loop, because otherwise we will
9200 infloop, since move_it_to will see that it is already at
9201 START_POS and will not move. */
9202 || (it2
.method
== GET_FROM_STRING
9203 && IT_CHARPOS (it2
) == start_pos
9204 && SREF (it2
.string
, IT_STRING_BYTEPOS (it2
) - 1) == '\n')));
9205 eassert (IT_CHARPOS (*it
) >= BEGV
);
9206 SAVE_IT (it3
, it2
, it3data
);
9208 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
9209 eassert (IT_CHARPOS (*it
) >= BEGV
);
9210 /* H is the actual vertical distance from the position in *IT
9211 and the starting position. */
9212 h
= it2
.current_y
- it
->current_y
;
9213 /* NLINES is the distance in number of lines. */
9214 nlines
= it2
.vpos
- it
->vpos
;
9216 /* Correct IT's y and vpos position
9217 so that they are relative to the starting point. */
9223 /* DY == 0 means move to the start of the screen line. The
9224 value of nlines is > 0 if continuation lines were involved,
9225 or if the original IT position was at start of a line. */
9226 RESTORE_IT (it
, it
, it2data
);
9228 move_it_by_lines (it
, nlines
);
9229 /* The above code moves us to some position NLINES down,
9230 usually to its first glyph (leftmost in an L2R line), but
9231 that's not necessarily the start of the line, under bidi
9232 reordering. We want to get to the character position
9233 that is immediately after the newline of the previous
9236 && !it
->continuation_lines_width
9237 && !STRINGP (it
->string
)
9238 && IT_CHARPOS (*it
) > BEGV
9239 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9241 ptrdiff_t cp
= IT_CHARPOS (*it
), bp
= IT_BYTEPOS (*it
);
9244 cp
= find_newline_no_quit (cp
, bp
, -1, NULL
);
9245 move_it_to (it
, cp
, -1, -1, -1, MOVE_TO_POS
);
9247 bidi_unshelve_cache (it3data
, 1);
9251 /* The y-position we try to reach, relative to *IT.
9252 Note that H has been subtracted in front of the if-statement. */
9253 int target_y
= it
->current_y
+ h
- dy
;
9254 int y0
= it3
.current_y
;
9258 RESTORE_IT (&it3
, &it3
, it3data
);
9259 y1
= line_bottom_y (&it3
);
9260 line_height
= y1
- y0
;
9261 RESTORE_IT (it
, it
, it2data
);
9262 /* If we did not reach target_y, try to move further backward if
9263 we can. If we moved too far backward, try to move forward. */
9264 if (target_y
< it
->current_y
9265 /* This is heuristic. In a window that's 3 lines high, with
9266 a line height of 13 pixels each, recentering with point
9267 on the bottom line will try to move -39/2 = 19 pixels
9268 backward. Try to avoid moving into the first line. */
9269 && (it
->current_y
- target_y
9270 > min (window_box_height (it
->w
), line_height
* 2 / 3))
9271 && IT_CHARPOS (*it
) > BEGV
)
9273 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
9274 target_y
- it
->current_y
));
9275 dy
= it
->current_y
- target_y
;
9276 goto move_further_back
;
9278 else if (target_y
>= it
->current_y
+ line_height
9279 && IT_CHARPOS (*it
) < ZV
)
9281 /* Should move forward by at least one line, maybe more.
9283 Note: Calling move_it_by_lines can be expensive on
9284 terminal frames, where compute_motion is used (via
9285 vmotion) to do the job, when there are very long lines
9286 and truncate-lines is nil. That's the reason for
9287 treating terminal frames specially here. */
9289 if (!FRAME_WINDOW_P (it
->f
))
9290 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
9295 move_it_by_lines (it
, 1);
9297 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
9304 /* Move IT by a specified amount of pixel lines DY. DY negative means
9305 move backwards. DY = 0 means move to start of screen line. At the
9306 end, IT will be on the start of a screen line. */
9309 move_it_vertically (struct it
*it
, int dy
)
9312 move_it_vertically_backward (it
, -dy
);
9315 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
9316 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
9317 MOVE_TO_POS
| MOVE_TO_Y
);
9318 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
9320 /* If buffer ends in ZV without a newline, move to the start of
9321 the line to satisfy the post-condition. */
9322 if (IT_CHARPOS (*it
) == ZV
9324 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9325 move_it_by_lines (it
, 0);
9330 /* Move iterator IT past the end of the text line it is in. */
9333 move_it_past_eol (struct it
*it
)
9335 enum move_it_result rc
;
9337 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
9338 if (rc
== MOVE_NEWLINE_OR_CR
)
9339 set_iterator_to_next (it
, 0);
9343 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
9344 negative means move up. DVPOS == 0 means move to the start of the
9347 Optimization idea: If we would know that IT->f doesn't use
9348 a face with proportional font, we could be faster for
9349 truncate-lines nil. */
9352 move_it_by_lines (struct it
*it
, ptrdiff_t dvpos
)
9355 /* The commented-out optimization uses vmotion on terminals. This
9356 gives bad results, because elements like it->what, on which
9357 callers such as pos_visible_p rely, aren't updated. */
9358 /* struct position pos;
9359 if (!FRAME_WINDOW_P (it->f))
9361 struct text_pos textpos;
9363 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
9364 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
9365 reseat (it, textpos, 1);
9366 it->vpos += pos.vpos;
9367 it->current_y += pos.vpos;
9373 /* DVPOS == 0 means move to the start of the screen line. */
9374 move_it_vertically_backward (it
, 0);
9375 /* Let next call to line_bottom_y calculate real line height. */
9380 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
9381 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
9383 /* Only move to the next buffer position if we ended up in a
9384 string from display property, not in an overlay string
9385 (before-string or after-string). That is because the
9386 latter don't conceal the underlying buffer position, so
9387 we can ask to move the iterator to the exact position we
9388 are interested in. Note that, even if we are already at
9389 IT_CHARPOS (*it), the call below is not a no-op, as it
9390 will detect that we are at the end of the string, pop the
9391 iterator, and compute it->current_x and it->hpos
9393 move_it_to (it
, IT_CHARPOS (*it
) + it
->string_from_display_prop_p
,
9394 -1, -1, -1, MOVE_TO_POS
);
9400 void *it2data
= NULL
;
9401 ptrdiff_t start_charpos
, i
;
9403 = (it
->last_visible_x
- it
->first_visible_x
) / FRAME_COLUMN_WIDTH (it
->f
);
9404 ptrdiff_t pos_limit
;
9406 /* Start at the beginning of the screen line containing IT's
9407 position. This may actually move vertically backwards,
9408 in case of overlays, so adjust dvpos accordingly. */
9410 move_it_vertically_backward (it
, 0);
9413 /* Go back -DVPOS buffer lines, but no farther than -DVPOS full
9414 screen lines, and reseat the iterator there. */
9415 start_charpos
= IT_CHARPOS (*it
);
9416 if (it
->line_wrap
== TRUNCATE
)
9419 pos_limit
= max (start_charpos
+ dvpos
* nchars_per_row
, BEGV
);
9420 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > pos_limit
; --i
)
9421 back_to_previous_visible_line_start (it
);
9422 reseat (it
, it
->current
.pos
, 1);
9424 /* Move further back if we end up in a string or an image. */
9425 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
9427 /* First try to move to start of display line. */
9429 move_it_vertically_backward (it
, 0);
9431 if (IT_POS_VALID_AFTER_MOVE_P (it
))
9433 /* If start of line is still in string or image,
9434 move further back. */
9435 back_to_previous_visible_line_start (it
);
9436 reseat (it
, it
->current
.pos
, 1);
9440 it
->current_x
= it
->hpos
= 0;
9442 /* Above call may have moved too far if continuation lines
9443 are involved. Scan forward and see if it did. */
9444 SAVE_IT (it2
, *it
, it2data
);
9445 it2
.vpos
= it2
.current_y
= 0;
9446 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
9447 it
->vpos
-= it2
.vpos
;
9448 it
->current_y
-= it2
.current_y
;
9449 it
->current_x
= it
->hpos
= 0;
9451 /* If we moved too far back, move IT some lines forward. */
9452 if (it2
.vpos
> -dvpos
)
9454 int delta
= it2
.vpos
+ dvpos
;
9456 RESTORE_IT (&it2
, &it2
, it2data
);
9457 SAVE_IT (it2
, *it
, it2data
);
9458 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
9459 /* Move back again if we got too far ahead. */
9460 if (IT_CHARPOS (*it
) >= start_charpos
)
9461 RESTORE_IT (it
, &it2
, it2data
);
9463 bidi_unshelve_cache (it2data
, 1);
9466 RESTORE_IT (it
, it
, it2data
);
9470 /* Return 1 if IT points into the middle of a display vector. */
9473 in_display_vector_p (struct it
*it
)
9475 return (it
->method
== GET_FROM_DISPLAY_VECTOR
9476 && it
->current
.dpvec_index
> 0
9477 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
9480 DEFUN ("window-text-pixel-size", Fwindow_text_pixel_size
, Swindow_text_pixel_size
, 0, 6, 0,
9481 doc
: /* Return the size of the text of WINDOW's buffer in pixels.
9482 WINDOW must be a live window and defaults to the selected one. The
9483 return value is a cons of the maximum pixel-width of any text line and
9484 the maximum pixel-height of all text lines.
9486 The optional argument FROM, if non-nil, specifies the first text
9487 position and defaults to the minimum accessible position of the buffer.
9488 If FROM is t, use the minimum accessible position that is not a newline
9489 character. TO, if non-nil, specifies the last text position and
9490 defaults to the maximum accessible position of the buffer. If TO is t,
9491 use the maximum accessible position that is not a newline character.
9493 The optional argument X_LIMIT, if non-nil, specifies the maximum text
9494 width that can be returned. X_LIMIT nil or omitted, means to use the
9495 pixel-width of WINDOW's body; use this if you do not intend to change
9496 the width of WINDOW. Use the maximum width WINDOW may assume if you
9497 intend to change WINDOW's width.
9499 The optional argument Y_LIMIT, if non-nil, specifies the maximum text
9500 height that can be returned. Text lines whose y-coordinate is beyond
9501 Y_LIMIT are ignored. Since calculating the text height of a large
9502 buffer can take some time, it makes sense to specify this argument if
9503 the size of the buffer is unknown.
9505 Optional argument MODE_AND_HEADER_LINE nil or omitted means do not
9506 include the height of the mode- or header-line of WINDOW in the return
9507 value. If it is either the symbol `mode-line' or `header-line', include
9508 only the height of that line, if present, in the return value. If t,
9509 include the height of any of these lines in the return value. */)
9510 (Lisp_Object window
, Lisp_Object from
, Lisp_Object to
, Lisp_Object x_limit
, Lisp_Object y_limit
,
9511 Lisp_Object mode_and_header_line
)
9513 struct window
*w
= decode_live_window (window
);
9517 struct buffer
*old_buffer
= NULL
;
9518 ptrdiff_t start
, end
, pos
;
9519 struct text_pos startp
;
9520 void *itdata
= NULL
;
9521 int c
, max_y
= -1, x
= 0, y
= 0;
9527 if (b
!= current_buffer
)
9529 old_buffer
= current_buffer
;
9530 set_buffer_internal (b
);
9535 else if (EQ (from
, Qt
))
9538 while ((pos
++ < ZV
) && (c
= FETCH_CHAR (pos
))
9539 && (c
== ' ' || c
== '\t' || c
== '\n' || c
== '\r'))
9541 while ((pos
-- > BEGV
) && (c
= FETCH_CHAR (pos
)) && (c
== ' ' || c
== '\t'))
9546 CHECK_NUMBER_COERCE_MARKER (from
);
9547 start
= min (max (XINT (from
), BEGV
), ZV
);
9552 else if (EQ (to
, Qt
))
9555 while ((pos
-- > BEGV
) && (c
= FETCH_CHAR (pos
))
9556 && (c
== ' ' || c
== '\t' || c
== '\n' || c
== '\r'))
9558 while ((pos
++ < ZV
) && (c
= FETCH_CHAR (pos
)) && (c
== ' ' || c
== '\t'))
9563 CHECK_NUMBER_COERCE_MARKER (to
);
9564 end
= max (start
, min (XINT (to
), ZV
));
9567 if (!NILP (y_limit
))
9569 CHECK_NUMBER (y_limit
);
9570 max_y
= XINT (y_limit
);
9573 itdata
= bidi_shelve_cache ();
9574 SET_TEXT_POS (startp
, start
, CHAR_TO_BYTE (start
));
9575 start_display (&it
, w
, startp
);
9577 /** move_it_vertically_backward (&it, 0); **/
9579 x
= move_it_to (&it
, end
, -1, max_y
, -1, MOVE_TO_POS
| MOVE_TO_Y
);
9582 CHECK_NUMBER (x_limit
);
9583 it
.last_visible_x
= XINT (x_limit
);
9584 /* Actually, we never want move_it_to stop at to_x. But to make
9585 sure that move_it_in_display_line_to always moves far enough,
9586 we set it to INT_MAX and specify MOVE_TO_X. */
9587 x
= move_it_to (&it
, end
, INT_MAX
, max_y
, -1,
9588 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9595 /* Count last line. */
9597 y
= line_bottom_y (&it
); /* - y; */
9600 if (!EQ (mode_and_header_line
, Qheader_line
)
9601 && !EQ (mode_and_header_line
, Qt
))
9602 /* Do not count the header-line which was counted automatically by
9604 y
= y
- WINDOW_HEADER_LINE_HEIGHT (w
);
9606 if (EQ (mode_and_header_line
, Qmode_line
)
9607 || EQ (mode_and_header_line
, Qt
))
9608 /* Do count the mode-line which is not included automatically by
9610 y
= y
+ WINDOW_MODE_LINE_HEIGHT (w
);
9612 bidi_unshelve_cache (itdata
, 0);
9615 set_buffer_internal (old_buffer
);
9617 return Fcons (make_number (x
), make_number (y
));
9620 /***********************************************************************
9622 ***********************************************************************/
9625 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
9629 add_to_log (const char *format
, Lisp_Object arg1
, Lisp_Object arg2
)
9631 Lisp_Object args
[3];
9632 Lisp_Object msg
, fmt
;
9635 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
9639 GCPRO4 (fmt
, msg
, arg1
, arg2
);
9641 args
[0] = fmt
= build_string (format
);
9644 msg
= Fformat (3, args
);
9646 len
= SBYTES (msg
) + 1;
9647 buffer
= SAFE_ALLOCA (len
);
9648 memcpy (buffer
, SDATA (msg
), len
);
9650 message_dolog (buffer
, len
- 1, 1, 0);
9657 /* Output a newline in the *Messages* buffer if "needs" one. */
9660 message_log_maybe_newline (void)
9662 if (message_log_need_newline
)
9663 message_dolog ("", 0, 1, 0);
9667 /* Add a string M of length NBYTES to the message log, optionally
9668 terminated with a newline when NLFLAG is true. MULTIBYTE, if
9669 true, means interpret the contents of M as multibyte. This
9670 function calls low-level routines in order to bypass text property
9671 hooks, etc. which might not be safe to run.
9673 This may GC (insert may run before/after change hooks),
9674 so the buffer M must NOT point to a Lisp string. */
9677 message_dolog (const char *m
, ptrdiff_t nbytes
, bool nlflag
, bool multibyte
)
9679 const unsigned char *msg
= (const unsigned char *) m
;
9681 if (!NILP (Vmemory_full
))
9684 if (!NILP (Vmessage_log_max
))
9686 struct buffer
*oldbuf
;
9687 Lisp_Object oldpoint
, oldbegv
, oldzv
;
9688 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
9689 ptrdiff_t point_at_end
= 0;
9690 ptrdiff_t zv_at_end
= 0;
9691 Lisp_Object old_deactivate_mark
;
9692 struct gcpro gcpro1
;
9694 old_deactivate_mark
= Vdeactivate_mark
;
9695 oldbuf
= current_buffer
;
9697 /* Ensure the Messages buffer exists, and switch to it.
9698 If we created it, set the major-mode. */
9701 if (NILP (Fget_buffer (Vmessages_buffer_name
))) newbuffer
= 1;
9703 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
9706 && !NILP (Ffboundp (intern ("messages-buffer-mode"))))
9707 call0 (intern ("messages-buffer-mode"));
9710 bset_undo_list (current_buffer
, Qt
);
9711 bset_cache_long_scans (current_buffer
, Qnil
);
9713 oldpoint
= message_dolog_marker1
;
9714 set_marker_restricted_both (oldpoint
, Qnil
, PT
, PT_BYTE
);
9715 oldbegv
= message_dolog_marker2
;
9716 set_marker_restricted_both (oldbegv
, Qnil
, BEGV
, BEGV_BYTE
);
9717 oldzv
= message_dolog_marker3
;
9718 set_marker_restricted_both (oldzv
, Qnil
, ZV
, ZV_BYTE
);
9719 GCPRO1 (old_deactivate_mark
);
9727 BEGV_BYTE
= BEG_BYTE
;
9730 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9732 /* Insert the string--maybe converting multibyte to single byte
9733 or vice versa, so that all the text fits the buffer. */
9735 && NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9741 /* Convert a multibyte string to single-byte
9742 for the *Message* buffer. */
9743 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
9745 c
= string_char_and_length (msg
+ i
, &char_bytes
);
9746 work
[0] = (ASCII_CHAR_P (c
)
9748 : multibyte_char_to_unibyte (c
));
9749 insert_1_both (work
, 1, 1, 1, 0, 0);
9752 else if (! multibyte
9753 && ! NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9757 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9758 /* Convert a single-byte string to multibyte
9759 for the *Message* buffer. */
9760 for (i
= 0; i
< nbytes
; i
++)
9763 MAKE_CHAR_MULTIBYTE (c
);
9764 char_bytes
= CHAR_STRING (c
, str
);
9765 insert_1_both ((char *) str
, 1, char_bytes
, 1, 0, 0);
9769 insert_1_both (m
, chars_in_text (msg
, nbytes
), nbytes
, 1, 0, 0);
9773 ptrdiff_t this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
;
9776 insert_1_both ("\n", 1, 1, 1, 0, 0);
9778 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9780 this_bol_byte
= PT_BYTE
;
9782 /* See if this line duplicates the previous one.
9783 If so, combine duplicates. */
9786 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9788 prev_bol_byte
= PT_BYTE
;
9790 dups
= message_log_check_duplicate (prev_bol_byte
,
9794 del_range_both (prev_bol
, prev_bol_byte
,
9795 this_bol
, this_bol_byte
, 0);
9798 char dupstr
[sizeof " [ times]"
9799 + INT_STRLEN_BOUND (printmax_t
)];
9801 /* If you change this format, don't forget to also
9802 change message_log_check_duplicate. */
9803 int duplen
= sprintf (dupstr
, " [%"pMd
" times]", dups
);
9804 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
9805 insert_1_both (dupstr
, duplen
, duplen
, 1, 0, 1);
9810 /* If we have more than the desired maximum number of lines
9811 in the *Messages* buffer now, delete the oldest ones.
9812 This is safe because we don't have undo in this buffer. */
9814 if (NATNUMP (Vmessage_log_max
))
9816 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
9817 -XFASTINT (Vmessage_log_max
) - 1, 0);
9818 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
9821 BEGV
= marker_position (oldbegv
);
9822 BEGV_BYTE
= marker_byte_position (oldbegv
);
9831 ZV
= marker_position (oldzv
);
9832 ZV_BYTE
= marker_byte_position (oldzv
);
9836 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9838 /* We can't do Fgoto_char (oldpoint) because it will run some
9840 TEMP_SET_PT_BOTH (marker_position (oldpoint
),
9841 marker_byte_position (oldpoint
));
9844 unchain_marker (XMARKER (oldpoint
));
9845 unchain_marker (XMARKER (oldbegv
));
9846 unchain_marker (XMARKER (oldzv
));
9848 /* We called insert_1_both above with its 5th argument (PREPARE)
9849 zero, which prevents insert_1_both from calling
9850 prepare_to_modify_buffer, which in turns prevents us from
9851 incrementing windows_or_buffers_changed even if *Messages* is
9852 shown in some window. So we must manually set
9853 windows_or_buffers_changed here to make up for that. */
9854 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
9855 bset_redisplay (current_buffer
);
9857 set_buffer_internal (oldbuf
);
9859 message_log_need_newline
= !nlflag
;
9860 Vdeactivate_mark
= old_deactivate_mark
;
9865 /* We are at the end of the buffer after just having inserted a newline.
9866 (Note: We depend on the fact we won't be crossing the gap.)
9867 Check to see if the most recent message looks a lot like the previous one.
9868 Return 0 if different, 1 if the new one should just replace it, or a
9869 value N > 1 if we should also append " [N times]". */
9872 message_log_check_duplicate (ptrdiff_t prev_bol_byte
, ptrdiff_t this_bol_byte
)
9875 ptrdiff_t len
= Z_BYTE
- 1 - this_bol_byte
;
9877 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
9878 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
9880 for (i
= 0; i
< len
; i
++)
9882 if (i
>= 3 && p1
[i
- 3] == '.' && p1
[i
- 2] == '.' && p1
[i
- 1] == '.')
9890 if (*p1
++ == ' ' && *p1
++ == '[')
9893 intmax_t n
= strtoimax ((char *) p1
, &pend
, 10);
9894 if (0 < n
&& n
< INTMAX_MAX
&& strncmp (pend
, " times]\n", 8) == 0)
9901 /* Display an echo area message M with a specified length of NBYTES
9902 bytes. The string may include null characters. If M is not a
9903 string, clear out any existing message, and let the mini-buffer
9906 This function cancels echoing. */
9909 message3 (Lisp_Object m
)
9911 struct gcpro gcpro1
;
9914 clear_message (true, true);
9917 /* First flush out any partial line written with print. */
9918 message_log_maybe_newline ();
9921 ptrdiff_t nbytes
= SBYTES (m
);
9922 bool multibyte
= STRING_MULTIBYTE (m
);
9924 char *buffer
= SAFE_ALLOCA (nbytes
);
9925 memcpy (buffer
, SDATA (m
), nbytes
);
9926 message_dolog (buffer
, nbytes
, 1, multibyte
);
9935 /* The non-logging version of message3.
9936 This does not cancel echoing, because it is used for echoing.
9937 Perhaps we need to make a separate function for echoing
9938 and make this cancel echoing. */
9941 message3_nolog (Lisp_Object m
)
9943 struct frame
*sf
= SELECTED_FRAME ();
9945 if (FRAME_INITIAL_P (sf
))
9947 if (noninteractive_need_newline
)
9948 putc ('\n', stderr
);
9949 noninteractive_need_newline
= 0;
9952 Lisp_Object s
= ENCODE_SYSTEM (m
);
9954 fwrite (SDATA (s
), SBYTES (s
), 1, stderr
);
9956 if (cursor_in_echo_area
== 0)
9957 fprintf (stderr
, "\n");
9960 /* Error messages get reported properly by cmd_error, so this must be just an
9961 informative message; if the frame hasn't really been initialized yet, just
9963 else if (INTERACTIVE
&& sf
->glyphs_initialized_p
)
9965 /* Get the frame containing the mini-buffer
9966 that the selected frame is using. */
9967 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9968 Lisp_Object frame
= XWINDOW (mini_window
)->frame
;
9969 struct frame
*f
= XFRAME (frame
);
9971 if (FRAME_VISIBLE_P (sf
) && !FRAME_VISIBLE_P (f
))
9972 Fmake_frame_visible (frame
);
9974 if (STRINGP (m
) && SCHARS (m
) > 0)
9977 if (minibuffer_auto_raise
)
9978 Fraise_frame (frame
);
9979 /* Assume we are not echoing.
9980 (If we are, echo_now will override this.) */
9981 echo_message_buffer
= Qnil
;
9984 clear_message (true, true);
9986 do_pending_window_change (0);
9987 echo_area_display (1);
9988 do_pending_window_change (0);
9989 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
9990 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
9995 /* Display a null-terminated echo area message M. If M is 0, clear
9996 out any existing message, and let the mini-buffer text show through.
9998 The buffer M must continue to exist until after the echo area gets
9999 cleared or some other message gets displayed there. Do not pass
10000 text that is stored in a Lisp string. Do not pass text in a buffer
10001 that was alloca'd. */
10004 message1 (const char *m
)
10006 message3 (m
? build_unibyte_string (m
) : Qnil
);
10010 /* The non-logging counterpart of message1. */
10013 message1_nolog (const char *m
)
10015 message3_nolog (m
? build_unibyte_string (m
) : Qnil
);
10018 /* Display a message M which contains a single %s
10019 which gets replaced with STRING. */
10022 message_with_string (const char *m
, Lisp_Object string
, int log
)
10024 CHECK_STRING (string
);
10026 if (noninteractive
)
10030 /* ENCODE_SYSTEM below can GC and/or relocate the Lisp
10031 String whose data pointer might be passed to us in M. So
10032 we use a local copy. */
10033 char *fmt
= xstrdup (m
);
10035 if (noninteractive_need_newline
)
10036 putc ('\n', stderr
);
10037 noninteractive_need_newline
= 0;
10038 fprintf (stderr
, fmt
, SDATA (ENCODE_SYSTEM (string
)));
10039 if (!cursor_in_echo_area
)
10040 fprintf (stderr
, "\n");
10045 else if (INTERACTIVE
)
10047 /* The frame whose minibuffer we're going to display the message on.
10048 It may be larger than the selected frame, so we need
10049 to use its buffer, not the selected frame's buffer. */
10050 Lisp_Object mini_window
;
10051 struct frame
*f
, *sf
= SELECTED_FRAME ();
10053 /* Get the frame containing the minibuffer
10054 that the selected frame is using. */
10055 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10056 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
10058 /* Error messages get reported properly by cmd_error, so this must be
10059 just an informative message; if the frame hasn't really been
10060 initialized yet, just toss it. */
10061 if (f
->glyphs_initialized_p
)
10063 Lisp_Object args
[2], msg
;
10064 struct gcpro gcpro1
, gcpro2
;
10066 args
[0] = build_string (m
);
10067 args
[1] = msg
= string
;
10068 GCPRO2 (args
[0], msg
);
10071 msg
= Fformat (2, args
);
10076 message3_nolog (msg
);
10080 /* Print should start at the beginning of the message
10081 buffer next time. */
10082 message_buf_print
= 0;
10088 /* Dump an informative message to the minibuf. If M is 0, clear out
10089 any existing message, and let the mini-buffer text show through. */
10092 vmessage (const char *m
, va_list ap
)
10094 if (noninteractive
)
10098 if (noninteractive_need_newline
)
10099 putc ('\n', stderr
);
10100 noninteractive_need_newline
= 0;
10101 vfprintf (stderr
, m
, ap
);
10102 if (cursor_in_echo_area
== 0)
10103 fprintf (stderr
, "\n");
10107 else if (INTERACTIVE
)
10109 /* The frame whose mini-buffer we're going to display the message
10110 on. It may be larger than the selected frame, so we need to
10111 use its buffer, not the selected frame's buffer. */
10112 Lisp_Object mini_window
;
10113 struct frame
*f
, *sf
= SELECTED_FRAME ();
10115 /* Get the frame containing the mini-buffer
10116 that the selected frame is using. */
10117 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10118 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
10120 /* Error messages get reported properly by cmd_error, so this must be
10121 just an informative message; if the frame hasn't really been
10122 initialized yet, just toss it. */
10123 if (f
->glyphs_initialized_p
)
10128 ptrdiff_t maxsize
= FRAME_MESSAGE_BUF_SIZE (f
);
10129 char *message_buf
= alloca (maxsize
+ 1);
10131 len
= doprnt (message_buf
, maxsize
, m
, 0, ap
);
10133 message3 (make_string (message_buf
, len
));
10138 /* Print should start at the beginning of the message
10139 buffer next time. */
10140 message_buf_print
= 0;
10146 message (const char *m
, ...)
10156 /* The non-logging version of message. */
10159 message_nolog (const char *m
, ...)
10161 Lisp_Object old_log_max
;
10164 old_log_max
= Vmessage_log_max
;
10165 Vmessage_log_max
= Qnil
;
10167 Vmessage_log_max
= old_log_max
;
10173 /* Display the current message in the current mini-buffer. This is
10174 only called from error handlers in process.c, and is not time
10178 update_echo_area (void)
10180 if (!NILP (echo_area_buffer
[0]))
10182 Lisp_Object string
;
10183 string
= Fcurrent_message ();
10189 /* Make sure echo area buffers in `echo_buffers' are live.
10190 If they aren't, make new ones. */
10193 ensure_echo_area_buffers (void)
10197 for (i
= 0; i
< 2; ++i
)
10198 if (!BUFFERP (echo_buffer
[i
])
10199 || !BUFFER_LIVE_P (XBUFFER (echo_buffer
[i
])))
10202 Lisp_Object old_buffer
;
10205 old_buffer
= echo_buffer
[i
];
10206 echo_buffer
[i
] = Fget_buffer_create
10207 (make_formatted_string (name
, " *Echo Area %d*", i
));
10208 bset_truncate_lines (XBUFFER (echo_buffer
[i
]), Qnil
);
10209 /* to force word wrap in echo area -
10210 it was decided to postpone this*/
10211 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
10213 for (j
= 0; j
< 2; ++j
)
10214 if (EQ (old_buffer
, echo_area_buffer
[j
]))
10215 echo_area_buffer
[j
] = echo_buffer
[i
];
10220 /* Call FN with args A1..A2 with either the current or last displayed
10221 echo_area_buffer as current buffer.
10223 WHICH zero means use the current message buffer
10224 echo_area_buffer[0]. If that is nil, choose a suitable buffer
10225 from echo_buffer[] and clear it.
10227 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
10228 suitable buffer from echo_buffer[] and clear it.
10230 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
10231 that the current message becomes the last displayed one, make
10232 choose a suitable buffer for echo_area_buffer[0], and clear it.
10234 Value is what FN returns. */
10237 with_echo_area_buffer (struct window
*w
, int which
,
10238 int (*fn
) (ptrdiff_t, Lisp_Object
),
10239 ptrdiff_t a1
, Lisp_Object a2
)
10241 Lisp_Object buffer
;
10242 int this_one
, the_other
, clear_buffer_p
, rc
;
10243 ptrdiff_t count
= SPECPDL_INDEX ();
10245 /* If buffers aren't live, make new ones. */
10246 ensure_echo_area_buffers ();
10248 clear_buffer_p
= 0;
10251 this_one
= 0, the_other
= 1;
10252 else if (which
> 0)
10253 this_one
= 1, the_other
= 0;
10256 this_one
= 0, the_other
= 1;
10257 clear_buffer_p
= true;
10259 /* We need a fresh one in case the current echo buffer equals
10260 the one containing the last displayed echo area message. */
10261 if (!NILP (echo_area_buffer
[this_one
])
10262 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
10263 echo_area_buffer
[this_one
] = Qnil
;
10266 /* Choose a suitable buffer from echo_buffer[] is we don't
10268 if (NILP (echo_area_buffer
[this_one
]))
10270 echo_area_buffer
[this_one
]
10271 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
10272 ? echo_buffer
[the_other
]
10273 : echo_buffer
[this_one
]);
10274 clear_buffer_p
= true;
10277 buffer
= echo_area_buffer
[this_one
];
10279 /* Don't get confused by reusing the buffer used for echoing
10280 for a different purpose. */
10281 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
10284 record_unwind_protect (unwind_with_echo_area_buffer
,
10285 with_echo_area_buffer_unwind_data (w
));
10287 /* Make the echo area buffer current. Note that for display
10288 purposes, it is not necessary that the displayed window's buffer
10289 == current_buffer, except for text property lookup. So, let's
10290 only set that buffer temporarily here without doing a full
10291 Fset_window_buffer. We must also change w->pointm, though,
10292 because otherwise an assertions in unshow_buffer fails, and Emacs
10294 set_buffer_internal_1 (XBUFFER (buffer
));
10297 wset_buffer (w
, buffer
);
10298 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
10301 bset_undo_list (current_buffer
, Qt
);
10302 bset_read_only (current_buffer
, Qnil
);
10303 specbind (Qinhibit_read_only
, Qt
);
10304 specbind (Qinhibit_modification_hooks
, Qt
);
10306 if (clear_buffer_p
&& Z
> BEG
)
10307 del_range (BEG
, Z
);
10309 eassert (BEGV
>= BEG
);
10310 eassert (ZV
<= Z
&& ZV
>= BEGV
);
10314 eassert (BEGV
>= BEG
);
10315 eassert (ZV
<= Z
&& ZV
>= BEGV
);
10317 unbind_to (count
, Qnil
);
10322 /* Save state that should be preserved around the call to the function
10323 FN called in with_echo_area_buffer. */
10326 with_echo_area_buffer_unwind_data (struct window
*w
)
10329 Lisp_Object vector
, tmp
;
10331 /* Reduce consing by keeping one vector in
10332 Vwith_echo_area_save_vector. */
10333 vector
= Vwith_echo_area_save_vector
;
10334 Vwith_echo_area_save_vector
= Qnil
;
10337 vector
= Fmake_vector (make_number (9), Qnil
);
10339 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
10340 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
10341 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
10345 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
10346 ASET (vector
, i
, w
->contents
); ++i
;
10347 ASET (vector
, i
, make_number (marker_position (w
->pointm
))); ++i
;
10348 ASET (vector
, i
, make_number (marker_byte_position (w
->pointm
))); ++i
;
10349 ASET (vector
, i
, make_number (marker_position (w
->start
))); ++i
;
10350 ASET (vector
, i
, make_number (marker_byte_position (w
->start
))); ++i
;
10355 for (; i
< end
; ++i
)
10356 ASET (vector
, i
, Qnil
);
10359 eassert (i
== ASIZE (vector
));
10364 /* Restore global state from VECTOR which was created by
10365 with_echo_area_buffer_unwind_data. */
10368 unwind_with_echo_area_buffer (Lisp_Object vector
)
10370 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
10371 Vdeactivate_mark
= AREF (vector
, 1);
10372 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
10374 if (WINDOWP (AREF (vector
, 3)))
10377 Lisp_Object buffer
;
10379 w
= XWINDOW (AREF (vector
, 3));
10380 buffer
= AREF (vector
, 4);
10382 wset_buffer (w
, buffer
);
10383 set_marker_both (w
->pointm
, buffer
,
10384 XFASTINT (AREF (vector
, 5)),
10385 XFASTINT (AREF (vector
, 6)));
10386 set_marker_both (w
->start
, buffer
,
10387 XFASTINT (AREF (vector
, 7)),
10388 XFASTINT (AREF (vector
, 8)));
10391 Vwith_echo_area_save_vector
= vector
;
10395 /* Set up the echo area for use by print functions. MULTIBYTE_P
10396 non-zero means we will print multibyte. */
10399 setup_echo_area_for_printing (int multibyte_p
)
10401 /* If we can't find an echo area any more, exit. */
10402 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
10403 Fkill_emacs (Qnil
);
10405 ensure_echo_area_buffers ();
10407 if (!message_buf_print
)
10409 /* A message has been output since the last time we printed.
10410 Choose a fresh echo area buffer. */
10411 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10412 echo_area_buffer
[0] = echo_buffer
[1];
10414 echo_area_buffer
[0] = echo_buffer
[0];
10416 /* Switch to that buffer and clear it. */
10417 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10418 bset_truncate_lines (current_buffer
, Qnil
);
10422 ptrdiff_t count
= SPECPDL_INDEX ();
10423 specbind (Qinhibit_read_only
, Qt
);
10424 /* Note that undo recording is always disabled. */
10425 del_range (BEG
, Z
);
10426 unbind_to (count
, Qnil
);
10428 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10430 /* Set up the buffer for the multibyteness we need. */
10432 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10433 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
10435 /* Raise the frame containing the echo area. */
10436 if (minibuffer_auto_raise
)
10438 struct frame
*sf
= SELECTED_FRAME ();
10439 Lisp_Object mini_window
;
10440 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10441 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
10444 message_log_maybe_newline ();
10445 message_buf_print
= 1;
10449 if (NILP (echo_area_buffer
[0]))
10451 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10452 echo_area_buffer
[0] = echo_buffer
[1];
10454 echo_area_buffer
[0] = echo_buffer
[0];
10457 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
10459 /* Someone switched buffers between print requests. */
10460 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10461 bset_truncate_lines (current_buffer
, Qnil
);
10467 /* Display an echo area message in window W. Value is non-zero if W's
10468 height is changed. If display_last_displayed_message_p is
10469 non-zero, display the message that was last displayed, otherwise
10470 display the current message. */
10473 display_echo_area (struct window
*w
)
10475 int i
, no_message_p
, window_height_changed_p
;
10477 /* Temporarily disable garbage collections while displaying the echo
10478 area. This is done because a GC can print a message itself.
10479 That message would modify the echo area buffer's contents while a
10480 redisplay of the buffer is going on, and seriously confuse
10482 ptrdiff_t count
= inhibit_garbage_collection ();
10484 /* If there is no message, we must call display_echo_area_1
10485 nevertheless because it resizes the window. But we will have to
10486 reset the echo_area_buffer in question to nil at the end because
10487 with_echo_area_buffer will sets it to an empty buffer. */
10488 i
= display_last_displayed_message_p
? 1 : 0;
10489 no_message_p
= NILP (echo_area_buffer
[i
]);
10491 window_height_changed_p
10492 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
10493 display_echo_area_1
,
10494 (intptr_t) w
, Qnil
);
10497 echo_area_buffer
[i
] = Qnil
;
10499 unbind_to (count
, Qnil
);
10500 return window_height_changed_p
;
10504 /* Helper for display_echo_area. Display the current buffer which
10505 contains the current echo area message in window W, a mini-window,
10506 a pointer to which is passed in A1. A2..A4 are currently not used.
10507 Change the height of W so that all of the message is displayed.
10508 Value is non-zero if height of W was changed. */
10511 display_echo_area_1 (ptrdiff_t a1
, Lisp_Object a2
)
10514 struct window
*w
= (struct window
*) i1
;
10515 Lisp_Object window
;
10516 struct text_pos start
;
10517 int window_height_changed_p
= 0;
10519 /* Do this before displaying, so that we have a large enough glyph
10520 matrix for the display. If we can't get enough space for the
10521 whole text, display the last N lines. That works by setting w->start. */
10522 window_height_changed_p
= resize_mini_window (w
, 0);
10524 /* Use the starting position chosen by resize_mini_window. */
10525 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
10528 clear_glyph_matrix (w
->desired_matrix
);
10529 XSETWINDOW (window
, w
);
10530 try_window (window
, start
, 0);
10532 return window_height_changed_p
;
10536 /* Resize the echo area window to exactly the size needed for the
10537 currently displayed message, if there is one. If a mini-buffer
10538 is active, don't shrink it. */
10541 resize_echo_area_exactly (void)
10543 if (BUFFERP (echo_area_buffer
[0])
10544 && WINDOWP (echo_area_window
))
10546 struct window
*w
= XWINDOW (echo_area_window
);
10547 Lisp_Object resize_exactly
= (minibuf_level
== 0 ? Qt
: Qnil
);
10548 int resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
10549 (intptr_t) w
, resize_exactly
);
10552 windows_or_buffers_changed
= 42;
10553 update_mode_lines
= 30;
10554 redisplay_internal ();
10560 /* Callback function for with_echo_area_buffer, when used from
10561 resize_echo_area_exactly. A1 contains a pointer to the window to
10562 resize, EXACTLY non-nil means resize the mini-window exactly to the
10563 size of the text displayed. A3 and A4 are not used. Value is what
10564 resize_mini_window returns. */
10567 resize_mini_window_1 (ptrdiff_t a1
, Lisp_Object exactly
)
10570 return resize_mini_window ((struct window
*) i1
, !NILP (exactly
));
10574 /* Resize mini-window W to fit the size of its contents. EXACT_P
10575 means size the window exactly to the size needed. Otherwise, it's
10576 only enlarged until W's buffer is empty.
10578 Set W->start to the right place to begin display. If the whole
10579 contents fit, start at the beginning. Otherwise, start so as
10580 to make the end of the contents appear. This is particularly
10581 important for y-or-n-p, but seems desirable generally.
10583 Value is non-zero if the window height has been changed. */
10586 resize_mini_window (struct window
*w
, int exact_p
)
10588 struct frame
*f
= XFRAME (w
->frame
);
10589 int window_height_changed_p
= 0;
10591 eassert (MINI_WINDOW_P (w
));
10593 /* By default, start display at the beginning. */
10594 set_marker_both (w
->start
, w
->contents
,
10595 BUF_BEGV (XBUFFER (w
->contents
)),
10596 BUF_BEGV_BYTE (XBUFFER (w
->contents
)));
10598 /* Don't resize windows while redisplaying a window; it would
10599 confuse redisplay functions when the size of the window they are
10600 displaying changes from under them. Such a resizing can happen,
10601 for instance, when which-func prints a long message while
10602 we are running fontification-functions. We're running these
10603 functions with safe_call which binds inhibit-redisplay to t. */
10604 if (!NILP (Vinhibit_redisplay
))
10607 /* Nil means don't try to resize. */
10608 if (NILP (Vresize_mini_windows
)
10609 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
10612 if (!FRAME_MINIBUF_ONLY_P (f
))
10615 int total_height
= (WINDOW_PIXEL_HEIGHT (XWINDOW (FRAME_ROOT_WINDOW (f
)))
10616 + WINDOW_PIXEL_HEIGHT (w
));
10617 int unit
= FRAME_LINE_HEIGHT (f
);
10618 int height
, max_height
;
10619 struct text_pos start
;
10620 struct buffer
*old_current_buffer
= NULL
;
10622 if (current_buffer
!= XBUFFER (w
->contents
))
10624 old_current_buffer
= current_buffer
;
10625 set_buffer_internal (XBUFFER (w
->contents
));
10628 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10630 /* Compute the max. number of lines specified by the user. */
10631 if (FLOATP (Vmax_mini_window_height
))
10632 max_height
= XFLOATINT (Vmax_mini_window_height
) * total_height
;
10633 else if (INTEGERP (Vmax_mini_window_height
))
10634 max_height
= XINT (Vmax_mini_window_height
) * unit
;
10636 max_height
= total_height
/ 4;
10638 /* Correct that max. height if it's bogus. */
10639 max_height
= clip_to_bounds (unit
, max_height
, total_height
);
10641 /* Find out the height of the text in the window. */
10642 if (it
.line_wrap
== TRUNCATE
)
10647 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
10648 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
10649 height
= it
.current_y
+ last_height
;
10651 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
10652 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
10655 /* Compute a suitable window start. */
10656 if (height
> max_height
)
10658 height
= max_height
;
10659 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10660 move_it_vertically_backward (&it
, height
);
10661 start
= it
.current
.pos
;
10664 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
10665 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
10667 if (EQ (Vresize_mini_windows
, Qgrow_only
))
10669 /* Let it grow only, until we display an empty message, in which
10670 case the window shrinks again. */
10671 if (height
> WINDOW_PIXEL_HEIGHT (w
))
10673 int old_height
= WINDOW_PIXEL_HEIGHT (w
);
10675 FRAME_WINDOWS_FROZEN (f
) = 1;
10676 grow_mini_window (w
, height
- WINDOW_PIXEL_HEIGHT (w
), 1);
10677 window_height_changed_p
= WINDOW_PIXEL_HEIGHT (w
) != old_height
;
10679 else if (height
< WINDOW_PIXEL_HEIGHT (w
)
10680 && (exact_p
|| BEGV
== ZV
))
10682 int old_height
= WINDOW_PIXEL_HEIGHT (w
);
10684 FRAME_WINDOWS_FROZEN (f
) = 0;
10685 shrink_mini_window (w
, 1);
10686 window_height_changed_p
= WINDOW_PIXEL_HEIGHT (w
) != old_height
;
10691 /* Always resize to exact size needed. */
10692 if (height
> WINDOW_PIXEL_HEIGHT (w
))
10694 int old_height
= WINDOW_PIXEL_HEIGHT (w
);
10696 FRAME_WINDOWS_FROZEN (f
) = 1;
10697 grow_mini_window (w
, height
- WINDOW_PIXEL_HEIGHT (w
), 1);
10698 window_height_changed_p
= WINDOW_PIXEL_HEIGHT (w
) != old_height
;
10700 else if (height
< WINDOW_PIXEL_HEIGHT (w
))
10702 int old_height
= WINDOW_PIXEL_HEIGHT (w
);
10704 FRAME_WINDOWS_FROZEN (f
) = 0;
10705 shrink_mini_window (w
, 1);
10709 FRAME_WINDOWS_FROZEN (f
) = 1;
10710 grow_mini_window (w
, height
- WINDOW_PIXEL_HEIGHT (w
), 1);
10713 window_height_changed_p
= WINDOW_PIXEL_HEIGHT (w
) != old_height
;
10717 if (old_current_buffer
)
10718 set_buffer_internal (old_current_buffer
);
10721 return window_height_changed_p
;
10725 /* Value is the current message, a string, or nil if there is no
10726 current message. */
10729 current_message (void)
10733 if (!BUFFERP (echo_area_buffer
[0]))
10737 with_echo_area_buffer (0, 0, current_message_1
,
10738 (intptr_t) &msg
, Qnil
);
10740 echo_area_buffer
[0] = Qnil
;
10748 current_message_1 (ptrdiff_t a1
, Lisp_Object a2
)
10751 Lisp_Object
*msg
= (Lisp_Object
*) i1
;
10754 *msg
= make_buffer_string (BEG
, Z
, 1);
10761 /* Push the current message on Vmessage_stack for later restoration
10762 by restore_message. Value is non-zero if the current message isn't
10763 empty. This is a relatively infrequent operation, so it's not
10764 worth optimizing. */
10767 push_message (void)
10769 Lisp_Object msg
= current_message ();
10770 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
10771 return STRINGP (msg
);
10775 /* Restore message display from the top of Vmessage_stack. */
10778 restore_message (void)
10780 eassert (CONSP (Vmessage_stack
));
10781 message3_nolog (XCAR (Vmessage_stack
));
10785 /* Handler for unwind-protect calling pop_message. */
10788 pop_message_unwind (void)
10790 /* Pop the top-most entry off Vmessage_stack. */
10791 eassert (CONSP (Vmessage_stack
));
10792 Vmessage_stack
= XCDR (Vmessage_stack
);
10796 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
10797 exits. If the stack is not empty, we have a missing pop_message
10801 check_message_stack (void)
10803 if (!NILP (Vmessage_stack
))
10808 /* Truncate to NCHARS what will be displayed in the echo area the next
10809 time we display it---but don't redisplay it now. */
10812 truncate_echo_area (ptrdiff_t nchars
)
10815 echo_area_buffer
[0] = Qnil
;
10816 else if (!noninteractive
10818 && !NILP (echo_area_buffer
[0]))
10820 struct frame
*sf
= SELECTED_FRAME ();
10821 /* Error messages get reported properly by cmd_error, so this must be
10822 just an informative message; if the frame hasn't really been
10823 initialized yet, just toss it. */
10824 if (sf
->glyphs_initialized_p
)
10825 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
);
10830 /* Helper function for truncate_echo_area. Truncate the current
10831 message to at most NCHARS characters. */
10834 truncate_message_1 (ptrdiff_t nchars
, Lisp_Object a2
)
10836 if (BEG
+ nchars
< Z
)
10837 del_range (BEG
+ nchars
, Z
);
10839 echo_area_buffer
[0] = Qnil
;
10843 /* Set the current message to STRING. */
10846 set_message (Lisp_Object string
)
10848 eassert (STRINGP (string
));
10850 message_enable_multibyte
= STRING_MULTIBYTE (string
);
10852 with_echo_area_buffer (0, -1, set_message_1
, 0, string
);
10853 message_buf_print
= 0;
10854 help_echo_showing_p
= 0;
10856 if (STRINGP (Vdebug_on_message
)
10857 && STRINGP (string
)
10858 && fast_string_match (Vdebug_on_message
, string
) >= 0)
10859 call_debugger (list2 (Qerror
, string
));
10863 /* Helper function for set_message. First argument is ignored and second
10864 argument has the same meaning as for set_message.
10865 This function is called with the echo area buffer being current. */
10868 set_message_1 (ptrdiff_t a1
, Lisp_Object string
)
10870 eassert (STRINGP (string
));
10872 /* Change multibyteness of the echo buffer appropriately. */
10873 if (message_enable_multibyte
10874 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10875 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
10877 bset_truncate_lines (current_buffer
, message_truncate_lines
? Qt
: Qnil
);
10878 if (!NILP (BVAR (current_buffer
, bidi_display_reordering
)))
10879 bset_bidi_paragraph_direction (current_buffer
, Qleft_to_right
);
10881 /* Insert new message at BEG. */
10882 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10884 /* This function takes care of single/multibyte conversion.
10885 We just have to ensure that the echo area buffer has the right
10886 setting of enable_multibyte_characters. */
10887 insert_from_string (string
, 0, 0, SCHARS (string
), SBYTES (string
), 1);
10893 /* Clear messages. CURRENT_P non-zero means clear the current
10894 message. LAST_DISPLAYED_P non-zero means clear the message
10898 clear_message (bool current_p
, bool last_displayed_p
)
10902 echo_area_buffer
[0] = Qnil
;
10903 message_cleared_p
= true;
10906 if (last_displayed_p
)
10907 echo_area_buffer
[1] = Qnil
;
10909 message_buf_print
= 0;
10912 /* Clear garbaged frames.
10914 This function is used where the old redisplay called
10915 redraw_garbaged_frames which in turn called redraw_frame which in
10916 turn called clear_frame. The call to clear_frame was a source of
10917 flickering. I believe a clear_frame is not necessary. It should
10918 suffice in the new redisplay to invalidate all current matrices,
10919 and ensure a complete redisplay of all windows. */
10922 clear_garbaged_frames (void)
10924 if (frame_garbaged
)
10926 Lisp_Object tail
, frame
;
10928 FOR_EACH_FRAME (tail
, frame
)
10930 struct frame
*f
= XFRAME (frame
);
10932 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
10937 clear_current_matrices (f
);
10938 fset_redisplay (f
);
10939 f
->garbaged
= false;
10940 f
->resized_p
= false;
10944 frame_garbaged
= false;
10949 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
10950 is non-zero update selected_frame. Value is non-zero if the
10951 mini-windows height has been changed. */
10954 echo_area_display (int update_frame_p
)
10956 Lisp_Object mini_window
;
10959 int window_height_changed_p
= 0;
10960 struct frame
*sf
= SELECTED_FRAME ();
10962 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10963 w
= XWINDOW (mini_window
);
10964 f
= XFRAME (WINDOW_FRAME (w
));
10966 /* Don't display if frame is invisible or not yet initialized. */
10967 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
10970 #ifdef HAVE_WINDOW_SYSTEM
10971 /* When Emacs starts, selected_frame may be the initial terminal
10972 frame. If we let this through, a message would be displayed on
10974 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
10976 #endif /* HAVE_WINDOW_SYSTEM */
10978 /* Redraw garbaged frames. */
10979 clear_garbaged_frames ();
10981 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
10983 echo_area_window
= mini_window
;
10984 window_height_changed_p
= display_echo_area (w
);
10985 w
->must_be_updated_p
= true;
10987 /* Update the display, unless called from redisplay_internal.
10988 Also don't update the screen during redisplay itself. The
10989 update will happen at the end of redisplay, and an update
10990 here could cause confusion. */
10991 if (update_frame_p
&& !redisplaying_p
)
10995 /* If the display update has been interrupted by pending
10996 input, update mode lines in the frame. Due to the
10997 pending input, it might have been that redisplay hasn't
10998 been called, so that mode lines above the echo area are
10999 garbaged. This looks odd, so we prevent it here. */
11000 if (!display_completed
)
11001 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), false);
11003 if (window_height_changed_p
11004 /* Don't do this if Emacs is shutting down. Redisplay
11005 needs to run hooks. */
11006 && !NILP (Vrun_hooks
))
11008 /* Must update other windows. Likewise as in other
11009 cases, don't let this update be interrupted by
11011 ptrdiff_t count
= SPECPDL_INDEX ();
11012 specbind (Qredisplay_dont_pause
, Qt
);
11013 windows_or_buffers_changed
= 44;
11014 redisplay_internal ();
11015 unbind_to (count
, Qnil
);
11017 else if (FRAME_WINDOW_P (f
) && n
== 0)
11019 /* Window configuration is the same as before.
11020 Can do with a display update of the echo area,
11021 unless we displayed some mode lines. */
11022 update_single_window (w
, 1);
11026 update_frame (f
, 1, 1);
11028 /* If cursor is in the echo area, make sure that the next
11029 redisplay displays the minibuffer, so that the cursor will
11030 be replaced with what the minibuffer wants. */
11031 if (cursor_in_echo_area
)
11032 wset_redisplay (XWINDOW (mini_window
));
11035 else if (!EQ (mini_window
, selected_window
))
11036 wset_redisplay (XWINDOW (mini_window
));
11038 /* Last displayed message is now the current message. */
11039 echo_area_buffer
[1] = echo_area_buffer
[0];
11040 /* Inform read_char that we're not echoing. */
11041 echo_message_buffer
= Qnil
;
11043 /* Prevent redisplay optimization in redisplay_internal by resetting
11044 this_line_start_pos. This is done because the mini-buffer now
11045 displays the message instead of its buffer text. */
11046 if (EQ (mini_window
, selected_window
))
11047 CHARPOS (this_line_start_pos
) = 0;
11049 return window_height_changed_p
;
11052 /* Nonzero if W's buffer was changed but not saved. */
11055 window_buffer_changed (struct window
*w
)
11057 struct buffer
*b
= XBUFFER (w
->contents
);
11059 eassert (BUFFER_LIVE_P (b
));
11061 return (((BUF_SAVE_MODIFF (b
) < BUF_MODIFF (b
)) != w
->last_had_star
));
11064 /* Nonzero if W has %c in its mode line and mode line should be updated. */
11067 mode_line_update_needed (struct window
*w
)
11069 return (w
->column_number_displayed
!= -1
11070 && !(PT
== w
->last_point
&& !window_outdated (w
))
11071 && (w
->column_number_displayed
!= current_column ()));
11074 /* Nonzero if window start of W is frozen and may not be changed during
11078 window_frozen_p (struct window
*w
)
11080 if (FRAME_WINDOWS_FROZEN (XFRAME (WINDOW_FRAME (w
))))
11082 Lisp_Object window
;
11084 XSETWINDOW (window
, w
);
11085 if (MINI_WINDOW_P (w
))
11087 else if (EQ (window
, selected_window
))
11089 else if (MINI_WINDOW_P (XWINDOW (selected_window
))
11090 && EQ (window
, Vminibuf_scroll_window
))
11091 /* This special window can't be frozen too. */
11099 /***********************************************************************
11100 Mode Lines and Frame Titles
11101 ***********************************************************************/
11103 /* A buffer for constructing non-propertized mode-line strings and
11104 frame titles in it; allocated from the heap in init_xdisp and
11105 resized as needed in store_mode_line_noprop_char. */
11107 static char *mode_line_noprop_buf
;
11109 /* The buffer's end, and a current output position in it. */
11111 static char *mode_line_noprop_buf_end
;
11112 static char *mode_line_noprop_ptr
;
11114 #define MODE_LINE_NOPROP_LEN(start) \
11115 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
11118 MODE_LINE_DISPLAY
= 0,
11122 } mode_line_target
;
11124 /* Alist that caches the results of :propertize.
11125 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
11126 static Lisp_Object mode_line_proptrans_alist
;
11128 /* List of strings making up the mode-line. */
11129 static Lisp_Object mode_line_string_list
;
11131 /* Base face property when building propertized mode line string. */
11132 static Lisp_Object mode_line_string_face
;
11133 static Lisp_Object mode_line_string_face_prop
;
11136 /* Unwind data for mode line strings */
11138 static Lisp_Object Vmode_line_unwind_vector
;
11141 format_mode_line_unwind_data (struct frame
*target_frame
,
11142 struct buffer
*obuf
,
11144 int save_proptrans
)
11146 Lisp_Object vector
, tmp
;
11148 /* Reduce consing by keeping one vector in
11149 Vwith_echo_area_save_vector. */
11150 vector
= Vmode_line_unwind_vector
;
11151 Vmode_line_unwind_vector
= Qnil
;
11154 vector
= Fmake_vector (make_number (10), Qnil
);
11156 ASET (vector
, 0, make_number (mode_line_target
));
11157 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
11158 ASET (vector
, 2, mode_line_string_list
);
11159 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
11160 ASET (vector
, 4, mode_line_string_face
);
11161 ASET (vector
, 5, mode_line_string_face_prop
);
11164 XSETBUFFER (tmp
, obuf
);
11167 ASET (vector
, 6, tmp
);
11168 ASET (vector
, 7, owin
);
11171 /* Similarly to `with-selected-window', if the operation selects
11172 a window on another frame, we must restore that frame's
11173 selected window, and (for a tty) the top-frame. */
11174 ASET (vector
, 8, target_frame
->selected_window
);
11175 if (FRAME_TERMCAP_P (target_frame
))
11176 ASET (vector
, 9, FRAME_TTY (target_frame
)->top_frame
);
11183 unwind_format_mode_line (Lisp_Object vector
)
11185 Lisp_Object old_window
= AREF (vector
, 7);
11186 Lisp_Object target_frame_window
= AREF (vector
, 8);
11187 Lisp_Object old_top_frame
= AREF (vector
, 9);
11189 mode_line_target
= XINT (AREF (vector
, 0));
11190 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
11191 mode_line_string_list
= AREF (vector
, 2);
11192 if (! EQ (AREF (vector
, 3), Qt
))
11193 mode_line_proptrans_alist
= AREF (vector
, 3);
11194 mode_line_string_face
= AREF (vector
, 4);
11195 mode_line_string_face_prop
= AREF (vector
, 5);
11197 /* Select window before buffer, since it may change the buffer. */
11198 if (!NILP (old_window
))
11200 /* If the operation that we are unwinding had selected a window
11201 on a different frame, reset its frame-selected-window. For a
11202 text terminal, reset its top-frame if necessary. */
11203 if (!NILP (target_frame_window
))
11206 = WINDOW_FRAME (XWINDOW (target_frame_window
));
11208 if (!EQ (frame
, WINDOW_FRAME (XWINDOW (old_window
))))
11209 Fselect_window (target_frame_window
, Qt
);
11211 if (!NILP (old_top_frame
) && !EQ (old_top_frame
, frame
))
11212 Fselect_frame (old_top_frame
, Qt
);
11215 Fselect_window (old_window
, Qt
);
11218 if (!NILP (AREF (vector
, 6)))
11220 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
11221 ASET (vector
, 6, Qnil
);
11224 Vmode_line_unwind_vector
= vector
;
11228 /* Store a single character C for the frame title in mode_line_noprop_buf.
11229 Re-allocate mode_line_noprop_buf if necessary. */
11232 store_mode_line_noprop_char (char c
)
11234 /* If output position has reached the end of the allocated buffer,
11235 increase the buffer's size. */
11236 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
11238 ptrdiff_t len
= MODE_LINE_NOPROP_LEN (0);
11239 ptrdiff_t size
= len
;
11240 mode_line_noprop_buf
=
11241 xpalloc (mode_line_noprop_buf
, &size
, 1, STRING_BYTES_BOUND
, 1);
11242 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
11243 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
11246 *mode_line_noprop_ptr
++ = c
;
11250 /* Store part of a frame title in mode_line_noprop_buf, beginning at
11251 mode_line_noprop_ptr. STRING is the string to store. Do not copy
11252 characters that yield more columns than PRECISION; PRECISION <= 0
11253 means copy the whole string. Pad with spaces until FIELD_WIDTH
11254 number of characters have been copied; FIELD_WIDTH <= 0 means don't
11255 pad. Called from display_mode_element when it is used to build a
11259 store_mode_line_noprop (const char *string
, int field_width
, int precision
)
11261 const unsigned char *str
= (const unsigned char *) string
;
11263 ptrdiff_t dummy
, nbytes
;
11265 /* Copy at most PRECISION chars from STR. */
11266 nbytes
= strlen (string
);
11267 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
11269 store_mode_line_noprop_char (*str
++);
11271 /* Fill up with spaces until FIELD_WIDTH reached. */
11272 while (field_width
> 0
11273 && n
< field_width
)
11275 store_mode_line_noprop_char (' ');
11282 /***********************************************************************
11284 ***********************************************************************/
11286 #ifdef HAVE_WINDOW_SYSTEM
11288 /* Set the title of FRAME, if it has changed. The title format is
11289 Vicon_title_format if FRAME is iconified, otherwise it is
11290 frame_title_format. */
11293 x_consider_frame_title (Lisp_Object frame
)
11295 struct frame
*f
= XFRAME (frame
);
11297 if (FRAME_WINDOW_P (f
)
11298 || FRAME_MINIBUF_ONLY_P (f
)
11299 || f
->explicit_name
)
11301 /* Do we have more than one visible frame on this X display? */
11302 Lisp_Object tail
, other_frame
, fmt
;
11303 ptrdiff_t title_start
;
11307 ptrdiff_t count
= SPECPDL_INDEX ();
11309 FOR_EACH_FRAME (tail
, other_frame
)
11311 struct frame
*tf
= XFRAME (other_frame
);
11314 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
11315 && !FRAME_MINIBUF_ONLY_P (tf
)
11316 && !EQ (other_frame
, tip_frame
)
11317 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
11321 /* Set global variable indicating that multiple frames exist. */
11322 multiple_frames
= CONSP (tail
);
11324 /* Switch to the buffer of selected window of the frame. Set up
11325 mode_line_target so that display_mode_element will output into
11326 mode_line_noprop_buf; then display the title. */
11327 record_unwind_protect (unwind_format_mode_line
,
11328 format_mode_line_unwind_data
11329 (f
, current_buffer
, selected_window
, 0));
11331 Fselect_window (f
->selected_window
, Qt
);
11332 set_buffer_internal_1
11333 (XBUFFER (XWINDOW (f
->selected_window
)->contents
));
11334 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
11336 mode_line_target
= MODE_LINE_TITLE
;
11337 title_start
= MODE_LINE_NOPROP_LEN (0);
11338 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
11339 NULL
, DEFAULT_FACE_ID
);
11340 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
11341 len
= MODE_LINE_NOPROP_LEN (title_start
);
11342 title
= mode_line_noprop_buf
+ title_start
;
11343 unbind_to (count
, Qnil
);
11345 /* Set the title only if it's changed. This avoids consing in
11346 the common case where it hasn't. (If it turns out that we've
11347 already wasted too much time by walking through the list with
11348 display_mode_element, then we might need to optimize at a
11349 higher level than this.) */
11350 if (! STRINGP (f
->name
)
11351 || SBYTES (f
->name
) != len
11352 || memcmp (title
, SDATA (f
->name
), len
) != 0)
11353 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
11357 #endif /* not HAVE_WINDOW_SYSTEM */
11360 /***********************************************************************
11362 ***********************************************************************/
11364 /* Non-zero if we will not redisplay all visible windows. */
11365 #define REDISPLAY_SOME_P() \
11366 ((windows_or_buffers_changed == 0 \
11367 || windows_or_buffers_changed == REDISPLAY_SOME) \
11368 && (update_mode_lines == 0 \
11369 || update_mode_lines == REDISPLAY_SOME))
11371 /* Prepare for redisplay by updating menu-bar item lists when
11372 appropriate. This can call eval. */
11375 prepare_menu_bars (void)
11377 bool all_windows
= windows_or_buffers_changed
|| update_mode_lines
;
11378 bool some_windows
= REDISPLAY_SOME_P ();
11379 struct gcpro gcpro1
, gcpro2
;
11380 Lisp_Object tooltip_frame
;
11382 #ifdef HAVE_WINDOW_SYSTEM
11383 tooltip_frame
= tip_frame
;
11385 tooltip_frame
= Qnil
;
11388 if (FUNCTIONP (Vpre_redisplay_function
))
11390 Lisp_Object windows
= all_windows
? Qt
: Qnil
;
11391 if (all_windows
&& some_windows
)
11393 Lisp_Object ws
= window_list ();
11394 for (windows
= Qnil
; CONSP (ws
); ws
= XCDR (ws
))
11396 Lisp_Object
this = XCAR (ws
);
11397 struct window
*w
= XWINDOW (this);
11399 || XFRAME (w
->frame
)->redisplay
11400 || XBUFFER (w
->contents
)->text
->redisplay
)
11402 windows
= Fcons (this, windows
);
11406 safe_call1 (Vpre_redisplay_function
, windows
);
11409 /* Update all frame titles based on their buffer names, etc. We do
11410 this before the menu bars so that the buffer-menu will show the
11411 up-to-date frame titles. */
11412 #ifdef HAVE_WINDOW_SYSTEM
11415 Lisp_Object tail
, frame
;
11417 FOR_EACH_FRAME (tail
, frame
)
11419 struct frame
*f
= XFRAME (frame
);
11420 struct window
*w
= XWINDOW (FRAME_SELECTED_WINDOW (f
));
11424 && !XBUFFER (w
->contents
)->text
->redisplay
)
11427 if (!EQ (frame
, tooltip_frame
)
11428 && (FRAME_ICONIFIED_P (f
)
11429 || FRAME_VISIBLE_P (f
) == 1
11430 /* Exclude TTY frames that are obscured because they
11431 are not the top frame on their console. This is
11432 because x_consider_frame_title actually switches
11433 to the frame, which for TTY frames means it is
11434 marked as garbaged, and will be completely
11435 redrawn on the next redisplay cycle. This causes
11436 TTY frames to be completely redrawn, when there
11437 are more than one of them, even though nothing
11438 should be changed on display. */
11439 || (FRAME_VISIBLE_P (f
) == 2 && FRAME_WINDOW_P (f
))))
11440 x_consider_frame_title (frame
);
11443 #endif /* HAVE_WINDOW_SYSTEM */
11445 /* Update the menu bar item lists, if appropriate. This has to be
11446 done before any actual redisplay or generation of display lines. */
11450 Lisp_Object tail
, frame
;
11451 ptrdiff_t count
= SPECPDL_INDEX ();
11452 /* 1 means that update_menu_bar has run its hooks
11453 so any further calls to update_menu_bar shouldn't do so again. */
11454 int menu_bar_hooks_run
= 0;
11456 record_unwind_save_match_data ();
11458 FOR_EACH_FRAME (tail
, frame
)
11460 struct frame
*f
= XFRAME (frame
);
11461 struct window
*w
= XWINDOW (FRAME_SELECTED_WINDOW (f
));
11463 /* Ignore tooltip frame. */
11464 if (EQ (frame
, tooltip_frame
))
11470 && !XBUFFER (w
->contents
)->text
->redisplay
)
11473 /* If a window on this frame changed size, report that to
11474 the user and clear the size-change flag. */
11475 if (FRAME_WINDOW_SIZES_CHANGED (f
))
11477 Lisp_Object functions
;
11479 /* Clear flag first in case we get an error below. */
11480 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
11481 functions
= Vwindow_size_change_functions
;
11482 GCPRO2 (tail
, functions
);
11484 while (CONSP (functions
))
11486 if (!EQ (XCAR (functions
), Qt
))
11487 call1 (XCAR (functions
), frame
);
11488 functions
= XCDR (functions
);
11494 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
11495 #ifdef HAVE_WINDOW_SYSTEM
11496 update_tool_bar (f
, 0);
11499 if (windows_or_buffers_changed
11502 (f
, Fbuffer_modified_p (XWINDOW (f
->selected_window
)->contents
));
11507 unbind_to (count
, Qnil
);
11511 struct frame
*sf
= SELECTED_FRAME ();
11512 update_menu_bar (sf
, 1, 0);
11513 #ifdef HAVE_WINDOW_SYSTEM
11514 update_tool_bar (sf
, 1);
11520 /* Update the menu bar item list for frame F. This has to be done
11521 before we start to fill in any display lines, because it can call
11524 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
11526 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
11527 already ran the menu bar hooks for this redisplay, so there
11528 is no need to run them again. The return value is the
11529 updated value of this flag, to pass to the next call. */
11532 update_menu_bar (struct frame
*f
, int save_match_data
, int hooks_run
)
11534 Lisp_Object window
;
11535 register struct window
*w
;
11537 /* If called recursively during a menu update, do nothing. This can
11538 happen when, for instance, an activate-menubar-hook causes a
11540 if (inhibit_menubar_update
)
11543 window
= FRAME_SELECTED_WINDOW (f
);
11544 w
= XWINDOW (window
);
11546 if (FRAME_WINDOW_P (f
)
11548 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11549 || defined (HAVE_NS) || defined (USE_GTK)
11550 FRAME_EXTERNAL_MENU_BAR (f
)
11552 FRAME_MENU_BAR_LINES (f
) > 0
11554 : FRAME_MENU_BAR_LINES (f
) > 0)
11556 /* If the user has switched buffers or windows, we need to
11557 recompute to reflect the new bindings. But we'll
11558 recompute when update_mode_lines is set too; that means
11559 that people can use force-mode-line-update to request
11560 that the menu bar be recomputed. The adverse effect on
11561 the rest of the redisplay algorithm is about the same as
11562 windows_or_buffers_changed anyway. */
11563 if (windows_or_buffers_changed
11564 /* This used to test w->update_mode_line, but we believe
11565 there is no need to recompute the menu in that case. */
11566 || update_mode_lines
11567 || window_buffer_changed (w
))
11569 struct buffer
*prev
= current_buffer
;
11570 ptrdiff_t count
= SPECPDL_INDEX ();
11572 specbind (Qinhibit_menubar_update
, Qt
);
11574 set_buffer_internal_1 (XBUFFER (w
->contents
));
11575 if (save_match_data
)
11576 record_unwind_save_match_data ();
11577 if (NILP (Voverriding_local_map_menu_flag
))
11579 specbind (Qoverriding_terminal_local_map
, Qnil
);
11580 specbind (Qoverriding_local_map
, Qnil
);
11585 /* Run the Lucid hook. */
11586 safe_run_hooks (Qactivate_menubar_hook
);
11588 /* If it has changed current-menubar from previous value,
11589 really recompute the menu-bar from the value. */
11590 if (! NILP (Vlucid_menu_bar_dirty_flag
))
11591 call0 (Qrecompute_lucid_menubar
);
11593 safe_run_hooks (Qmenu_bar_update_hook
);
11598 XSETFRAME (Vmenu_updating_frame
, f
);
11599 fset_menu_bar_items (f
, menu_bar_items (FRAME_MENU_BAR_ITEMS (f
)));
11601 /* Redisplay the menu bar in case we changed it. */
11602 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11603 || defined (HAVE_NS) || defined (USE_GTK)
11604 if (FRAME_WINDOW_P (f
))
11606 #if defined (HAVE_NS)
11607 /* All frames on Mac OS share the same menubar. So only
11608 the selected frame should be allowed to set it. */
11609 if (f
== SELECTED_FRAME ())
11611 set_frame_menubar (f
, 0, 0);
11614 /* On a terminal screen, the menu bar is an ordinary screen
11615 line, and this makes it get updated. */
11616 w
->update_mode_line
= 1;
11617 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11618 /* In the non-toolkit version, the menu bar is an ordinary screen
11619 line, and this makes it get updated. */
11620 w
->update_mode_line
= 1;
11621 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11623 unbind_to (count
, Qnil
);
11624 set_buffer_internal_1 (prev
);
11631 /***********************************************************************
11633 ***********************************************************************/
11635 #ifdef HAVE_WINDOW_SYSTEM
11637 /* Tool-bar item index of the item on which a mouse button was pressed
11640 int last_tool_bar_item
;
11642 /* Select `frame' temporarily without running all the code in
11644 FIXME: Maybe do_switch_frame should be trimmed down similarly
11645 when `norecord' is set. */
11647 fast_set_selected_frame (Lisp_Object frame
)
11649 if (!EQ (selected_frame
, frame
))
11651 selected_frame
= frame
;
11652 selected_window
= XFRAME (frame
)->selected_window
;
11656 /* Update the tool-bar item list for frame F. This has to be done
11657 before we start to fill in any display lines. Called from
11658 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
11659 and restore it here. */
11662 update_tool_bar (struct frame
*f
, int save_match_data
)
11664 #if defined (USE_GTK) || defined (HAVE_NS)
11665 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
11667 int do_update
= (WINDOWP (f
->tool_bar_window
)
11668 && WINDOW_PIXEL_HEIGHT (XWINDOW (f
->tool_bar_window
)) > 0);
11673 Lisp_Object window
;
11676 window
= FRAME_SELECTED_WINDOW (f
);
11677 w
= XWINDOW (window
);
11679 /* If the user has switched buffers or windows, we need to
11680 recompute to reflect the new bindings. But we'll
11681 recompute when update_mode_lines is set too; that means
11682 that people can use force-mode-line-update to request
11683 that the menu bar be recomputed. The adverse effect on
11684 the rest of the redisplay algorithm is about the same as
11685 windows_or_buffers_changed anyway. */
11686 if (windows_or_buffers_changed
11687 || w
->update_mode_line
11688 || update_mode_lines
11689 || window_buffer_changed (w
))
11691 struct buffer
*prev
= current_buffer
;
11692 ptrdiff_t count
= SPECPDL_INDEX ();
11693 Lisp_Object frame
, new_tool_bar
;
11694 int new_n_tool_bar
;
11695 struct gcpro gcpro1
;
11697 /* Set current_buffer to the buffer of the selected
11698 window of the frame, so that we get the right local
11700 set_buffer_internal_1 (XBUFFER (w
->contents
));
11702 /* Save match data, if we must. */
11703 if (save_match_data
)
11704 record_unwind_save_match_data ();
11706 /* Make sure that we don't accidentally use bogus keymaps. */
11707 if (NILP (Voverriding_local_map_menu_flag
))
11709 specbind (Qoverriding_terminal_local_map
, Qnil
);
11710 specbind (Qoverriding_local_map
, Qnil
);
11713 GCPRO1 (new_tool_bar
);
11715 /* We must temporarily set the selected frame to this frame
11716 before calling tool_bar_items, because the calculation of
11717 the tool-bar keymap uses the selected frame (see
11718 `tool-bar-make-keymap' in tool-bar.el). */
11719 eassert (EQ (selected_window
,
11720 /* Since we only explicitly preserve selected_frame,
11721 check that selected_window would be redundant. */
11722 XFRAME (selected_frame
)->selected_window
));
11723 record_unwind_protect (fast_set_selected_frame
, selected_frame
);
11724 XSETFRAME (frame
, f
);
11725 fast_set_selected_frame (frame
);
11727 /* Build desired tool-bar items from keymaps. */
11729 = tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
11732 /* Redisplay the tool-bar if we changed it. */
11733 if (new_n_tool_bar
!= f
->n_tool_bar_items
11734 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
11736 /* Redisplay that happens asynchronously due to an expose event
11737 may access f->tool_bar_items. Make sure we update both
11738 variables within BLOCK_INPUT so no such event interrupts. */
11740 fset_tool_bar_items (f
, new_tool_bar
);
11741 f
->n_tool_bar_items
= new_n_tool_bar
;
11742 w
->update_mode_line
= 1;
11748 unbind_to (count
, Qnil
);
11749 set_buffer_internal_1 (prev
);
11754 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
11756 /* Set F->desired_tool_bar_string to a Lisp string representing frame
11757 F's desired tool-bar contents. F->tool_bar_items must have
11758 been set up previously by calling prepare_menu_bars. */
11761 build_desired_tool_bar_string (struct frame
*f
)
11763 int i
, size
, size_needed
;
11764 struct gcpro gcpro1
, gcpro2
, gcpro3
;
11765 Lisp_Object image
, plist
, props
;
11767 image
= plist
= props
= Qnil
;
11768 GCPRO3 (image
, plist
, props
);
11770 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
11771 Otherwise, make a new string. */
11773 /* The size of the string we might be able to reuse. */
11774 size
= (STRINGP (f
->desired_tool_bar_string
)
11775 ? SCHARS (f
->desired_tool_bar_string
)
11778 /* We need one space in the string for each image. */
11779 size_needed
= f
->n_tool_bar_items
;
11781 /* Reuse f->desired_tool_bar_string, if possible. */
11782 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
11783 fset_desired_tool_bar_string
11784 (f
, Fmake_string (make_number (size_needed
), make_number (' ')));
11787 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
11788 Fremove_text_properties (make_number (0), make_number (size
),
11789 props
, f
->desired_tool_bar_string
);
11792 /* Put a `display' property on the string for the images to display,
11793 put a `menu_item' property on tool-bar items with a value that
11794 is the index of the item in F's tool-bar item vector. */
11795 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
11797 #define PROP(IDX) \
11798 AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
11800 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
11801 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
11802 int hmargin
, vmargin
, relief
, idx
, end
;
11804 /* If image is a vector, choose the image according to the
11806 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
11807 if (VECTORP (image
))
11811 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
11812 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
11815 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
11816 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
11818 eassert (ASIZE (image
) >= idx
);
11819 image
= AREF (image
, idx
);
11824 /* Ignore invalid image specifications. */
11825 if (!valid_image_p (image
))
11828 /* Display the tool-bar button pressed, or depressed. */
11829 plist
= Fcopy_sequence (XCDR (image
));
11831 /* Compute margin and relief to draw. */
11832 relief
= (tool_bar_button_relief
>= 0
11833 ? tool_bar_button_relief
11834 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
11835 hmargin
= vmargin
= relief
;
11837 if (RANGED_INTEGERP (1, Vtool_bar_button_margin
,
11838 INT_MAX
- max (hmargin
, vmargin
)))
11840 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
11841 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
11843 else if (CONSP (Vtool_bar_button_margin
))
11845 if (RANGED_INTEGERP (1, XCAR (Vtool_bar_button_margin
),
11846 INT_MAX
- hmargin
))
11847 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
11849 if (RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin
),
11850 INT_MAX
- vmargin
))
11851 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
11854 if (auto_raise_tool_bar_buttons_p
)
11856 /* Add a `:relief' property to the image spec if the item is
11860 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
11867 /* If image is selected, display it pressed, i.e. with a
11868 negative relief. If it's not selected, display it with a
11870 plist
= Fplist_put (plist
, QCrelief
,
11872 ? make_number (-relief
)
11873 : make_number (relief
)));
11878 /* Put a margin around the image. */
11879 if (hmargin
|| vmargin
)
11881 if (hmargin
== vmargin
)
11882 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
11884 plist
= Fplist_put (plist
, QCmargin
,
11885 Fcons (make_number (hmargin
),
11886 make_number (vmargin
)));
11889 /* If button is not enabled, and we don't have special images
11890 for the disabled state, make the image appear disabled by
11891 applying an appropriate algorithm to it. */
11892 if (!enabled_p
&& idx
< 0)
11893 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
11895 /* Put a `display' text property on the string for the image to
11896 display. Put a `menu-item' property on the string that gives
11897 the start of this item's properties in the tool-bar items
11899 image
= Fcons (Qimage
, plist
);
11900 props
= list4 (Qdisplay
, image
,
11901 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
11903 /* Let the last image hide all remaining spaces in the tool bar
11904 string. The string can be longer than needed when we reuse a
11905 previous string. */
11906 if (i
+ 1 == f
->n_tool_bar_items
)
11907 end
= SCHARS (f
->desired_tool_bar_string
);
11910 Fadd_text_properties (make_number (i
), make_number (end
),
11911 props
, f
->desired_tool_bar_string
);
11919 /* Display one line of the tool-bar of frame IT->f.
11921 HEIGHT specifies the desired height of the tool-bar line.
11922 If the actual height of the glyph row is less than HEIGHT, the
11923 row's height is increased to HEIGHT, and the icons are centered
11924 vertically in the new height.
11926 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
11927 count a final empty row in case the tool-bar width exactly matches
11932 display_tool_bar_line (struct it
*it
, int height
)
11934 struct glyph_row
*row
= it
->glyph_row
;
11935 int max_x
= it
->last_visible_x
;
11936 struct glyph
*last
;
11938 prepare_desired_row (row
);
11939 row
->y
= it
->current_y
;
11941 /* Note that this isn't made use of if the face hasn't a box,
11942 so there's no need to check the face here. */
11943 it
->start_of_box_run_p
= 1;
11945 while (it
->current_x
< max_x
)
11947 int x
, n_glyphs_before
, i
, nglyphs
;
11948 struct it it_before
;
11950 /* Get the next display element. */
11951 if (!get_next_display_element (it
))
11953 /* Don't count empty row if we are counting needed tool-bar lines. */
11954 if (height
< 0 && !it
->hpos
)
11959 /* Produce glyphs. */
11960 n_glyphs_before
= row
->used
[TEXT_AREA
];
11963 PRODUCE_GLYPHS (it
);
11965 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
11967 x
= it_before
.current_x
;
11968 while (i
< nglyphs
)
11970 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
11972 if (x
+ glyph
->pixel_width
> max_x
)
11974 /* Glyph doesn't fit on line. Backtrack. */
11975 row
->used
[TEXT_AREA
] = n_glyphs_before
;
11977 /* If this is the only glyph on this line, it will never fit on the
11978 tool-bar, so skip it. But ensure there is at least one glyph,
11979 so we don't accidentally disable the tool-bar. */
11980 if (n_glyphs_before
== 0
11981 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
11987 x
+= glyph
->pixel_width
;
11991 /* Stop at line end. */
11992 if (ITERATOR_AT_END_OF_LINE_P (it
))
11995 set_iterator_to_next (it
, 1);
12000 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
12002 /* Use default face for the border below the tool bar.
12004 FIXME: When auto-resize-tool-bars is grow-only, there is
12005 no additional border below the possibly empty tool-bar lines.
12006 So to make the extra empty lines look "normal", we have to
12007 use the tool-bar face for the border too. */
12008 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12009 && !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
12010 it
->face_id
= DEFAULT_FACE_ID
;
12012 extend_face_to_end_of_line (it
);
12013 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
12014 last
->right_box_line_p
= 1;
12015 if (last
== row
->glyphs
[TEXT_AREA
])
12016 last
->left_box_line_p
= 1;
12018 /* Make line the desired height and center it vertically. */
12019 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
12021 /* Don't add more than one line height. */
12022 height
%= FRAME_LINE_HEIGHT (it
->f
);
12023 it
->max_ascent
+= height
/ 2;
12024 it
->max_descent
+= (height
+ 1) / 2;
12027 compute_line_metrics (it
);
12029 /* If line is empty, make it occupy the rest of the tool-bar. */
12030 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12032 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
12033 row
->visible_height
= row
->height
;
12034 row
->ascent
= row
->phys_ascent
= 0;
12035 row
->extra_line_spacing
= 0;
12038 row
->full_width_p
= 1;
12039 row
->continued_p
= 0;
12040 row
->truncated_on_left_p
= 0;
12041 row
->truncated_on_right_p
= 0;
12043 it
->current_x
= it
->hpos
= 0;
12044 it
->current_y
+= row
->height
;
12050 /* Max tool-bar height. Basically, this is what makes all other windows
12051 disappear when the frame gets too small. Rethink this! */
12053 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
12054 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
12056 /* Value is the number of screen lines needed to make all tool-bar
12057 items of frame F visible. The number of actual rows needed is
12058 returned in *N_ROWS if non-NULL. */
12061 tool_bar_height (struct frame
*f
, int *n_rows
, bool pixelwise
)
12063 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12065 /* tool_bar_height is called from redisplay_tool_bar after building
12066 the desired matrix, so use (unused) mode-line row as temporary row to
12067 avoid destroying the first tool-bar row. */
12068 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
12070 /* Initialize an iterator for iteration over
12071 F->desired_tool_bar_string in the tool-bar window of frame F. */
12072 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
12073 it
.first_visible_x
= 0;
12074 /* PXW: Use FRAME_PIXEL_WIDTH (f) here ? */
12075 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
12076 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
12077 it
.paragraph_embedding
= L2R
;
12079 while (!ITERATOR_AT_END_P (&it
))
12081 clear_glyph_row (temp_row
);
12082 it
.glyph_row
= temp_row
;
12083 display_tool_bar_line (&it
, -1);
12085 clear_glyph_row (temp_row
);
12087 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
12089 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
12092 return it
.current_y
;
12094 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
12097 #endif /* !USE_GTK && !HAVE_NS */
12099 #if defined USE_GTK || defined HAVE_NS
12100 EXFUN (Ftool_bar_lines_needed
, 1) ATTRIBUTE_CONST
;
12103 DEFUN ("tool-bar-height", Ftool_bar_height
, Stool_bar_height
,
12105 doc
: /* Return the number of lines occupied by the tool bar of FRAME.
12106 If FRAME is nil or omitted, use the selected frame. Optional argument
12107 PIXELWISE non-nil means return the height of the tool bar inpixels. */)
12108 (Lisp_Object frame
, Lisp_Object pixelwise
)
12112 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
12113 struct frame
*f
= decode_any_frame (frame
);
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 if (interrupt_input
&& interrupts_deferred
)
13825 unbind_to (count
, Qnil
);
13830 /* Redisplay, but leave alone any recent echo area message unless
13831 another message has been requested in its place.
13833 This is useful in situations where you need to redisplay but no
13834 user action has occurred, making it inappropriate for the message
13835 area to be cleared. See tracking_off and
13836 wait_reading_process_output for examples of these situations.
13838 FROM_WHERE is an integer saying from where this function was
13839 called. This is useful for debugging. */
13842 redisplay_preserve_echo_area (int from_where
)
13844 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
13846 if (!NILP (echo_area_buffer
[1]))
13848 /* We have a previously displayed message, but no current
13849 message. Redisplay the previous message. */
13850 display_last_displayed_message_p
= 1;
13851 redisplay_internal ();
13852 display_last_displayed_message_p
= 0;
13855 redisplay_internal ();
13857 flush_frame (SELECTED_FRAME ());
13861 /* Function registered with record_unwind_protect in redisplay_internal. */
13864 unwind_redisplay (void)
13866 redisplaying_p
= 0;
13870 /* Mark the display of leaf window W as accurate or inaccurate.
13871 If ACCURATE_P is non-zero mark display of W as accurate. If
13872 ACCURATE_P is zero, arrange for W to be redisplayed the next
13873 time redisplay_internal is called. */
13876 mark_window_display_accurate_1 (struct window
*w
, int accurate_p
)
13878 struct buffer
*b
= XBUFFER (w
->contents
);
13880 w
->last_modified
= accurate_p
? BUF_MODIFF (b
) : 0;
13881 w
->last_overlay_modified
= accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0;
13882 w
->last_had_star
= BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
);
13886 b
->clip_changed
= false;
13887 b
->prevent_redisplay_optimizations_p
= false;
13888 eassert (buffer_window_count (b
) > 0);
13889 /* Resetting b->text->redisplay is problematic!
13890 In order to make it safer to do it here, redisplay_internal must
13891 have copied all b->text->redisplay to their respective windows. */
13892 b
->text
->redisplay
= false;
13894 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
13895 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
13896 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
13897 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
13899 w
->current_matrix
->buffer
= b
;
13900 w
->current_matrix
->begv
= BUF_BEGV (b
);
13901 w
->current_matrix
->zv
= BUF_ZV (b
);
13903 w
->last_cursor_vpos
= w
->cursor
.vpos
;
13904 w
->last_cursor_off_p
= w
->cursor_off_p
;
13906 if (w
== XWINDOW (selected_window
))
13907 w
->last_point
= BUF_PT (b
);
13909 w
->last_point
= marker_position (w
->pointm
);
13911 w
->window_end_valid
= true;
13912 w
->update_mode_line
= false;
13915 w
->redisplay
= !accurate_p
;
13919 /* Mark the display of windows in the window tree rooted at WINDOW as
13920 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
13921 windows as accurate. If ACCURATE_P is zero, arrange for windows to
13922 be redisplayed the next time redisplay_internal is called. */
13925 mark_window_display_accurate (Lisp_Object window
, int accurate_p
)
13929 for (; !NILP (window
); window
= w
->next
)
13931 w
= XWINDOW (window
);
13932 if (WINDOWP (w
->contents
))
13933 mark_window_display_accurate (w
->contents
, accurate_p
);
13935 mark_window_display_accurate_1 (w
, accurate_p
);
13939 update_overlay_arrows (1);
13941 /* Force a thorough redisplay the next time by setting
13942 last_arrow_position and last_arrow_string to t, which is
13943 unequal to any useful value of Voverlay_arrow_... */
13944 update_overlay_arrows (-1);
13948 /* Return value in display table DP (Lisp_Char_Table *) for character
13949 C. Since a display table doesn't have any parent, we don't have to
13950 follow parent. Do not call this function directly but use the
13951 macro DISP_CHAR_VECTOR. */
13954 disp_char_vector (struct Lisp_Char_Table
*dp
, int c
)
13958 if (ASCII_CHAR_P (c
))
13961 if (SUB_CHAR_TABLE_P (val
))
13962 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
13968 XSETCHAR_TABLE (table
, dp
);
13969 val
= char_table_ref (table
, c
);
13978 /***********************************************************************
13980 ***********************************************************************/
13982 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
13985 redisplay_windows (Lisp_Object window
)
13987 while (!NILP (window
))
13989 struct window
*w
= XWINDOW (window
);
13991 if (WINDOWP (w
->contents
))
13992 redisplay_windows (w
->contents
);
13993 else if (BUFFERP (w
->contents
))
13995 displayed_buffer
= XBUFFER (w
->contents
);
13996 /* Use list_of_error, not Qerror, so that
13997 we catch only errors and don't run the debugger. */
13998 internal_condition_case_1 (redisplay_window_0
, window
,
14000 redisplay_window_error
);
14008 redisplay_window_error (Lisp_Object ignore
)
14010 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
14015 redisplay_window_0 (Lisp_Object window
)
14017 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
14018 redisplay_window (window
, false);
14023 redisplay_window_1 (Lisp_Object window
)
14025 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
14026 redisplay_window (window
, true);
14031 /* Set cursor position of W. PT is assumed to be displayed in ROW.
14032 DELTA and DELTA_BYTES are the numbers of characters and bytes by
14033 which positions recorded in ROW differ from current buffer
14036 Return 0 if cursor is not on this row, 1 otherwise. */
14039 set_cursor_from_row (struct window
*w
, struct glyph_row
*row
,
14040 struct glyph_matrix
*matrix
,
14041 ptrdiff_t delta
, ptrdiff_t delta_bytes
,
14044 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
14045 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
14046 struct glyph
*cursor
= NULL
;
14047 /* The last known character position in row. */
14048 ptrdiff_t last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
14050 ptrdiff_t pt_old
= PT
- delta
;
14051 ptrdiff_t pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
14052 ptrdiff_t pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
14053 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
14054 /* A glyph beyond the edge of TEXT_AREA which we should never
14056 struct glyph
*glyphs_end
= end
;
14057 /* Non-zero means we've found a match for cursor position, but that
14058 glyph has the avoid_cursor_p flag set. */
14059 int match_with_avoid_cursor
= 0;
14060 /* Non-zero means we've seen at least one glyph that came from a
14062 int string_seen
= 0;
14063 /* Largest and smallest buffer positions seen so far during scan of
14065 ptrdiff_t bpos_max
= pos_before
;
14066 ptrdiff_t bpos_min
= pos_after
;
14067 /* Last buffer position covered by an overlay string with an integer
14068 `cursor' property. */
14069 ptrdiff_t bpos_covered
= 0;
14070 /* Non-zero means the display string on which to display the cursor
14071 comes from a text property, not from an overlay. */
14072 int string_from_text_prop
= 0;
14074 /* Don't even try doing anything if called for a mode-line or
14075 header-line row, since the rest of the code isn't prepared to
14076 deal with such calamities. */
14077 eassert (!row
->mode_line_p
);
14078 if (row
->mode_line_p
)
14081 /* Skip over glyphs not having an object at the start and the end of
14082 the row. These are special glyphs like truncation marks on
14083 terminal frames. */
14084 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14086 if (!row
->reversed_p
)
14089 && INTEGERP (glyph
->object
)
14090 && glyph
->charpos
< 0)
14092 x
+= glyph
->pixel_width
;
14096 && INTEGERP ((end
- 1)->object
)
14097 /* CHARPOS is zero for blanks and stretch glyphs
14098 inserted by extend_face_to_end_of_line. */
14099 && (end
- 1)->charpos
<= 0)
14101 glyph_before
= glyph
- 1;
14108 /* If the glyph row is reversed, we need to process it from back
14109 to front, so swap the edge pointers. */
14110 glyphs_end
= end
= glyph
- 1;
14111 glyph
+= row
->used
[TEXT_AREA
] - 1;
14113 while (glyph
> end
+ 1
14114 && INTEGERP (glyph
->object
)
14115 && glyph
->charpos
< 0)
14118 x
-= glyph
->pixel_width
;
14120 if (INTEGERP (glyph
->object
) && glyph
->charpos
< 0)
14122 /* By default, in reversed rows we put the cursor on the
14123 rightmost (first in the reading order) glyph. */
14124 for (g
= end
+ 1; g
< glyph
; g
++)
14125 x
+= g
->pixel_width
;
14127 && INTEGERP ((end
+ 1)->object
)
14128 && (end
+ 1)->charpos
<= 0)
14130 glyph_before
= glyph
+ 1;
14134 else if (row
->reversed_p
)
14136 /* In R2L rows that don't display text, put the cursor on the
14137 rightmost glyph. Case in point: an empty last line that is
14138 part of an R2L paragraph. */
14140 /* Avoid placing the cursor on the last glyph of the row, where
14141 on terminal frames we hold the vertical border between
14142 adjacent windows. */
14143 if (!FRAME_WINDOW_P (WINDOW_XFRAME (w
))
14144 && !WINDOW_RIGHTMOST_P (w
)
14145 && cursor
== row
->glyphs
[LAST_AREA
] - 1)
14147 x
= -1; /* will be computed below, at label compute_x */
14150 /* Step 1: Try to find the glyph whose character position
14151 corresponds to point. If that's not possible, find 2 glyphs
14152 whose character positions are the closest to point, one before
14153 point, the other after it. */
14154 if (!row
->reversed_p
)
14155 while (/* not marched to end of glyph row */
14157 /* glyph was not inserted by redisplay for internal purposes */
14158 && !INTEGERP (glyph
->object
))
14160 if (BUFFERP (glyph
->object
))
14162 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
14164 if (glyph
->charpos
> bpos_max
)
14165 bpos_max
= glyph
->charpos
;
14166 if (glyph
->charpos
< bpos_min
)
14167 bpos_min
= glyph
->charpos
;
14168 if (!glyph
->avoid_cursor_p
)
14170 /* If we hit point, we've found the glyph on which to
14171 display the cursor. */
14174 match_with_avoid_cursor
= 0;
14177 /* See if we've found a better approximation to
14178 POS_BEFORE or to POS_AFTER. */
14179 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
14181 pos_before
= glyph
->charpos
;
14182 glyph_before
= glyph
;
14184 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
14186 pos_after
= glyph
->charpos
;
14187 glyph_after
= glyph
;
14190 else if (dpos
== 0)
14191 match_with_avoid_cursor
= 1;
14193 else if (STRINGP (glyph
->object
))
14195 Lisp_Object chprop
;
14196 ptrdiff_t glyph_pos
= glyph
->charpos
;
14198 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
14200 if (!NILP (chprop
))
14202 /* If the string came from a `display' text property,
14203 look up the buffer position of that property and
14204 use that position to update bpos_max, as if we
14205 actually saw such a position in one of the row's
14206 glyphs. This helps with supporting integer values
14207 of `cursor' property on the display string in
14208 situations where most or all of the row's buffer
14209 text is completely covered by display properties,
14210 so that no glyph with valid buffer positions is
14211 ever seen in the row. */
14212 ptrdiff_t prop_pos
=
14213 string_buffer_position_lim (glyph
->object
, pos_before
,
14216 if (prop_pos
>= pos_before
)
14217 bpos_max
= prop_pos
- 1;
14219 if (INTEGERP (chprop
))
14221 bpos_covered
= bpos_max
+ XINT (chprop
);
14222 /* If the `cursor' property covers buffer positions up
14223 to and including point, we should display cursor on
14224 this glyph. Note that, if a `cursor' property on one
14225 of the string's characters has an integer value, we
14226 will break out of the loop below _before_ we get to
14227 the position match above. IOW, integer values of
14228 the `cursor' property override the "exact match for
14229 point" strategy of positioning the cursor. */
14230 /* Implementation note: bpos_max == pt_old when, e.g.,
14231 we are in an empty line, where bpos_max is set to
14232 MATRIX_ROW_START_CHARPOS, see above. */
14233 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14242 x
+= glyph
->pixel_width
;
14245 else if (glyph
> end
) /* row is reversed */
14246 while (!INTEGERP (glyph
->object
))
14248 if (BUFFERP (glyph
->object
))
14250 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
14252 if (glyph
->charpos
> bpos_max
)
14253 bpos_max
= glyph
->charpos
;
14254 if (glyph
->charpos
< bpos_min
)
14255 bpos_min
= glyph
->charpos
;
14256 if (!glyph
->avoid_cursor_p
)
14260 match_with_avoid_cursor
= 0;
14263 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
14265 pos_before
= glyph
->charpos
;
14266 glyph_before
= glyph
;
14268 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
14270 pos_after
= glyph
->charpos
;
14271 glyph_after
= glyph
;
14274 else if (dpos
== 0)
14275 match_with_avoid_cursor
= 1;
14277 else if (STRINGP (glyph
->object
))
14279 Lisp_Object chprop
;
14280 ptrdiff_t glyph_pos
= glyph
->charpos
;
14282 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
14284 if (!NILP (chprop
))
14286 ptrdiff_t prop_pos
=
14287 string_buffer_position_lim (glyph
->object
, pos_before
,
14290 if (prop_pos
>= pos_before
)
14291 bpos_max
= prop_pos
- 1;
14293 if (INTEGERP (chprop
))
14295 bpos_covered
= bpos_max
+ XINT (chprop
);
14296 /* If the `cursor' property covers buffer positions up
14297 to and including point, we should display cursor on
14299 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14308 if (glyph
== glyphs_end
) /* don't dereference outside TEXT_AREA */
14310 x
--; /* can't use any pixel_width */
14313 x
-= glyph
->pixel_width
;
14316 /* Step 2: If we didn't find an exact match for point, we need to
14317 look for a proper place to put the cursor among glyphs between
14318 GLYPH_BEFORE and GLYPH_AFTER. */
14319 if (!((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14320 && BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14321 && !(bpos_max
< pt_old
&& pt_old
<= bpos_covered
))
14323 /* An empty line has a single glyph whose OBJECT is zero and
14324 whose CHARPOS is the position of a newline on that line.
14325 Note that on a TTY, there are more glyphs after that, which
14326 were produced by extend_face_to_end_of_line, but their
14327 CHARPOS is zero or negative. */
14329 (row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14330 && INTEGERP (glyph
->object
) && glyph
->charpos
> 0
14331 /* On a TTY, continued and truncated rows also have a glyph at
14332 their end whose OBJECT is zero and whose CHARPOS is
14333 positive (the continuation and truncation glyphs), but such
14334 rows are obviously not "empty". */
14335 && !(row
->continued_p
|| row
->truncated_on_right_p
);
14337 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
14339 ptrdiff_t ellipsis_pos
;
14341 /* Scan back over the ellipsis glyphs. */
14342 if (!row
->reversed_p
)
14344 ellipsis_pos
= (glyph
- 1)->charpos
;
14345 while (glyph
> row
->glyphs
[TEXT_AREA
]
14346 && (glyph
- 1)->charpos
== ellipsis_pos
)
14347 glyph
--, x
-= glyph
->pixel_width
;
14348 /* That loop always goes one position too far, including
14349 the glyph before the ellipsis. So scan forward over
14351 x
+= glyph
->pixel_width
;
14354 else /* row is reversed */
14356 ellipsis_pos
= (glyph
+ 1)->charpos
;
14357 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14358 && (glyph
+ 1)->charpos
== ellipsis_pos
)
14359 glyph
++, x
+= glyph
->pixel_width
;
14360 x
-= glyph
->pixel_width
;
14364 else if (match_with_avoid_cursor
)
14366 cursor
= glyph_after
;
14369 else if (string_seen
)
14371 int incr
= row
->reversed_p
? -1 : +1;
14373 /* Need to find the glyph that came out of a string which is
14374 present at point. That glyph is somewhere between
14375 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
14376 positioned between POS_BEFORE and POS_AFTER in the
14378 struct glyph
*start
, *stop
;
14379 ptrdiff_t pos
= pos_before
;
14383 /* If the row ends in a newline from a display string,
14384 reordering could have moved the glyphs belonging to the
14385 string out of the [GLYPH_BEFORE..GLYPH_AFTER] range. So
14386 in this case we extend the search to the last glyph in
14387 the row that was not inserted by redisplay. */
14388 if (row
->ends_in_newline_from_string_p
)
14391 pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
14394 /* GLYPH_BEFORE and GLYPH_AFTER are the glyphs that
14395 correspond to POS_BEFORE and POS_AFTER, respectively. We
14396 need START and STOP in the order that corresponds to the
14397 row's direction as given by its reversed_p flag. If the
14398 directionality of characters between POS_BEFORE and
14399 POS_AFTER is the opposite of the row's base direction,
14400 these characters will have been reordered for display,
14401 and we need to reverse START and STOP. */
14402 if (!row
->reversed_p
)
14404 start
= min (glyph_before
, glyph_after
);
14405 stop
= max (glyph_before
, glyph_after
);
14409 start
= max (glyph_before
, glyph_after
);
14410 stop
= min (glyph_before
, glyph_after
);
14412 for (glyph
= start
+ incr
;
14413 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
14416 /* Any glyphs that come from the buffer are here because
14417 of bidi reordering. Skip them, and only pay
14418 attention to glyphs that came from some string. */
14419 if (STRINGP (glyph
->object
))
14423 /* If the display property covers the newline, we
14424 need to search for it one position farther. */
14425 ptrdiff_t lim
= pos_after
14426 + (pos_after
== MATRIX_ROW_END_CHARPOS (row
) + delta
);
14428 string_from_text_prop
= 0;
14429 str
= glyph
->object
;
14430 tem
= string_buffer_position_lim (str
, pos
, lim
, 0);
14431 if (tem
== 0 /* from overlay */
14434 /* If the string from which this glyph came is
14435 found in the buffer at point, or at position
14436 that is closer to point than pos_after, then
14437 we've found the glyph we've been looking for.
14438 If it comes from an overlay (tem == 0), and
14439 it has the `cursor' property on one of its
14440 glyphs, record that glyph as a candidate for
14441 displaying the cursor. (As in the
14442 unidirectional version, we will display the
14443 cursor on the last candidate we find.) */
14446 || (tem
- pt_old
> 0 && tem
< pos_after
))
14448 /* The glyphs from this string could have
14449 been reordered. Find the one with the
14450 smallest string position. Or there could
14451 be a character in the string with the
14452 `cursor' property, which means display
14453 cursor on that character's glyph. */
14454 ptrdiff_t strpos
= glyph
->charpos
;
14459 string_from_text_prop
= 1;
14462 (row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14463 && EQ (glyph
->object
, str
);
14467 ptrdiff_t gpos
= glyph
->charpos
;
14469 cprop
= Fget_char_property (make_number (gpos
),
14477 if (tem
&& glyph
->charpos
< strpos
)
14479 strpos
= glyph
->charpos
;
14485 || (tem
- pt_old
> 0 && tem
< pos_after
))
14489 pos
= tem
+ 1; /* don't find previous instances */
14491 /* This string is not what we want; skip all of the
14492 glyphs that came from it. */
14493 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14494 && EQ (glyph
->object
, str
))
14501 /* If we reached the end of the line, and END was from a string,
14502 the cursor is not on this line. */
14504 && (row
->reversed_p
? glyph
<= end
: glyph
>= end
)
14505 && (row
->reversed_p
? end
> glyphs_end
: end
< glyphs_end
)
14506 && STRINGP (end
->object
)
14507 && row
->continued_p
)
14510 /* A truncated row may not include PT among its character positions.
14511 Setting the cursor inside the scroll margin will trigger
14512 recalculation of hscroll in hscroll_window_tree. But if a
14513 display string covers point, defer to the string-handling
14514 code below to figure this out. */
14515 else if (row
->truncated_on_left_p
&& pt_old
< bpos_min
)
14517 cursor
= glyph_before
;
14520 else if ((row
->truncated_on_right_p
&& pt_old
> bpos_max
)
14521 /* Zero-width characters produce no glyphs. */
14523 && (row
->reversed_p
14524 ? glyph_after
> glyphs_end
14525 : glyph_after
< glyphs_end
)))
14527 cursor
= glyph_after
;
14533 if (cursor
!= NULL
)
14535 else if (glyph
== glyphs_end
14536 && pos_before
== pos_after
14537 && STRINGP ((row
->reversed_p
14538 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14539 : row
->glyphs
[TEXT_AREA
])->object
))
14541 /* If all the glyphs of this row came from strings, put the
14542 cursor on the first glyph of the row. This avoids having the
14543 cursor outside of the text area in this very rare and hard
14547 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14548 : row
->glyphs
[TEXT_AREA
];
14554 /* Need to compute x that corresponds to GLYPH. */
14555 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
14557 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
14559 x
+= g
->pixel_width
;
14563 /* ROW could be part of a continued line, which, under bidi
14564 reordering, might have other rows whose start and end charpos
14565 occlude point. Only set w->cursor if we found a better
14566 approximation to the cursor position than we have from previously
14567 examined candidate rows belonging to the same continued line. */
14568 if (/* We already have a candidate row. */
14569 w
->cursor
.vpos
>= 0
14570 /* That candidate is not the row we are processing. */
14571 && MATRIX_ROW (matrix
, w
->cursor
.vpos
) != row
14572 /* Make sure cursor.vpos specifies a row whose start and end
14573 charpos occlude point, and it is valid candidate for being a
14574 cursor-row. This is because some callers of this function
14575 leave cursor.vpos at the row where the cursor was displayed
14576 during the last redisplay cycle. */
14577 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)) <= pt_old
14578 && pt_old
<= MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14579 && cursor_row_p (MATRIX_ROW (matrix
, w
->cursor
.vpos
)))
14582 = MATRIX_ROW_GLYPH_START (matrix
, w
->cursor
.vpos
) + w
->cursor
.hpos
;
14584 /* Don't consider glyphs that are outside TEXT_AREA. */
14585 if (!(row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
))
14587 /* Keep the candidate whose buffer position is the closest to
14588 point or has the `cursor' property. */
14589 if (/* Previous candidate is a glyph in TEXT_AREA of that row. */
14590 w
->cursor
.hpos
>= 0
14591 && w
->cursor
.hpos
< MATRIX_ROW_USED (matrix
, w
->cursor
.vpos
)
14592 && ((BUFFERP (g1
->object
)
14593 && (g1
->charpos
== pt_old
/* An exact match always wins. */
14594 || (BUFFERP (glyph
->object
)
14595 && eabs (g1
->charpos
- pt_old
)
14596 < eabs (glyph
->charpos
- pt_old
))))
14597 /* Previous candidate is a glyph from a string that has
14598 a non-nil `cursor' property. */
14599 || (STRINGP (g1
->object
)
14600 && (!NILP (Fget_char_property (make_number (g1
->charpos
),
14601 Qcursor
, g1
->object
))
14602 /* Previous candidate is from the same display
14603 string as this one, and the display string
14604 came from a text property. */
14605 || (EQ (g1
->object
, glyph
->object
)
14606 && string_from_text_prop
)
14607 /* this candidate is from newline and its
14608 position is not an exact match */
14609 || (INTEGERP (glyph
->object
)
14610 && glyph
->charpos
!= pt_old
)))))
14612 /* If this candidate gives an exact match, use that. */
14613 if (!((BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14614 /* If this candidate is a glyph created for the
14615 terminating newline of a line, and point is on that
14616 newline, it wins because it's an exact match. */
14617 || (!row
->continued_p
14618 && INTEGERP (glyph
->object
)
14619 && glyph
->charpos
== 0
14620 && pt_old
== MATRIX_ROW_END_CHARPOS (row
) - 1))
14621 /* Otherwise, keep the candidate that comes from a row
14622 spanning less buffer positions. This may win when one or
14623 both candidate positions are on glyphs that came from
14624 display strings, for which we cannot compare buffer
14626 && MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14627 - MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14628 < MATRIX_ROW_END_CHARPOS (row
) - MATRIX_ROW_START_CHARPOS (row
))
14631 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
14633 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
14634 w
->cursor
.y
= row
->y
+ dy
;
14636 if (w
== XWINDOW (selected_window
))
14638 if (!row
->continued_p
14639 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
14642 this_line_buffer
= XBUFFER (w
->contents
);
14644 CHARPOS (this_line_start_pos
)
14645 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
14646 BYTEPOS (this_line_start_pos
)
14647 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
14649 CHARPOS (this_line_end_pos
)
14650 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
14651 BYTEPOS (this_line_end_pos
)
14652 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
14654 this_line_y
= w
->cursor
.y
;
14655 this_line_pixel_height
= row
->height
;
14656 this_line_vpos
= w
->cursor
.vpos
;
14657 this_line_start_x
= row
->x
;
14660 CHARPOS (this_line_start_pos
) = 0;
14667 /* Run window scroll functions, if any, for WINDOW with new window
14668 start STARTP. Sets the window start of WINDOW to that position.
14670 We assume that the window's buffer is really current. */
14672 static struct text_pos
14673 run_window_scroll_functions (Lisp_Object window
, struct text_pos startp
)
14675 struct window
*w
= XWINDOW (window
);
14676 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
14678 eassert (current_buffer
== XBUFFER (w
->contents
));
14680 if (!NILP (Vwindow_scroll_functions
))
14682 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
14683 make_number (CHARPOS (startp
)));
14684 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14685 /* In case the hook functions switch buffers. */
14686 set_buffer_internal (XBUFFER (w
->contents
));
14693 /* Make sure the line containing the cursor is fully visible.
14694 A value of 1 means there is nothing to be done.
14695 (Either the line is fully visible, or it cannot be made so,
14696 or we cannot tell.)
14698 If FORCE_P is non-zero, return 0 even if partial visible cursor row
14699 is higher than window.
14701 A value of 0 means the caller should do scrolling
14702 as if point had gone off the screen. */
14705 cursor_row_fully_visible_p (struct window
*w
, int force_p
, int current_matrix_p
)
14707 struct glyph_matrix
*matrix
;
14708 struct glyph_row
*row
;
14711 if (!make_cursor_line_fully_visible_p
)
14714 /* It's not always possible to find the cursor, e.g, when a window
14715 is full of overlay strings. Don't do anything in that case. */
14716 if (w
->cursor
.vpos
< 0)
14719 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
14720 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
14722 /* If the cursor row is not partially visible, there's nothing to do. */
14723 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
14726 /* If the row the cursor is in is taller than the window's height,
14727 it's not clear what to do, so do nothing. */
14728 window_height
= window_box_height (w
);
14729 if (row
->height
>= window_height
)
14731 if (!force_p
|| MINI_WINDOW_P (w
)
14732 || w
->vscroll
|| w
->cursor
.vpos
== 0)
14739 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
14740 non-zero means only WINDOW is redisplayed in redisplay_internal.
14741 TEMP_SCROLL_STEP has the same meaning as emacs_scroll_step, and is used
14742 in redisplay_window to bring a partially visible line into view in
14743 the case that only the cursor has moved.
14745 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
14746 last screen line's vertical height extends past the end of the screen.
14750 1 if scrolling succeeded
14752 0 if scrolling didn't find point.
14754 -1 if new fonts have been loaded so that we must interrupt
14755 redisplay, adjust glyph matrices, and try again. */
14761 SCROLLING_NEED_LARGER_MATRICES
14764 /* If scroll-conservatively is more than this, never recenter.
14766 If you change this, don't forget to update the doc string of
14767 `scroll-conservatively' and the Emacs manual. */
14768 #define SCROLL_LIMIT 100
14771 try_scrolling (Lisp_Object window
, int just_this_one_p
,
14772 ptrdiff_t arg_scroll_conservatively
, ptrdiff_t scroll_step
,
14773 int temp_scroll_step
, int last_line_misfit
)
14775 struct window
*w
= XWINDOW (window
);
14776 struct frame
*f
= XFRAME (w
->frame
);
14777 struct text_pos pos
, startp
;
14779 int this_scroll_margin
, scroll_max
, rc
, height
;
14780 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
14781 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
14782 Lisp_Object aggressive
;
14783 /* We will never try scrolling more than this number of lines. */
14784 int scroll_limit
= SCROLL_LIMIT
;
14785 int frame_line_height
= default_line_pixel_height (w
);
14786 int window_total_lines
14787 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
14790 debug_method_add (w
, "try_scrolling");
14793 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14795 /* Compute scroll margin height in pixels. We scroll when point is
14796 within this distance from the top or bottom of the window. */
14797 if (scroll_margin
> 0)
14798 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4)
14799 * frame_line_height
;
14801 this_scroll_margin
= 0;
14803 /* Force arg_scroll_conservatively to have a reasonable value, to
14804 avoid scrolling too far away with slow move_it_* functions. Note
14805 that the user can supply scroll-conservatively equal to
14806 `most-positive-fixnum', which can be larger than INT_MAX. */
14807 if (arg_scroll_conservatively
> scroll_limit
)
14809 arg_scroll_conservatively
= scroll_limit
+ 1;
14810 scroll_max
= scroll_limit
* frame_line_height
;
14812 else if (scroll_step
|| arg_scroll_conservatively
|| temp_scroll_step
)
14813 /* Compute how much we should try to scroll maximally to bring
14814 point into view. */
14815 scroll_max
= (max (scroll_step
,
14816 max (arg_scroll_conservatively
, temp_scroll_step
))
14817 * frame_line_height
);
14818 else if (NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
))
14819 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
)))
14820 /* We're trying to scroll because of aggressive scrolling but no
14821 scroll_step is set. Choose an arbitrary one. */
14822 scroll_max
= 10 * frame_line_height
;
14828 /* Decide whether to scroll down. */
14829 if (PT
> CHARPOS (startp
))
14831 int scroll_margin_y
;
14833 /* Compute the pixel ypos of the scroll margin, then move IT to
14834 either that ypos or PT, whichever comes first. */
14835 start_display (&it
, w
, startp
);
14836 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
14837 - frame_line_height
* extra_scroll_margin_lines
;
14838 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
14839 (MOVE_TO_POS
| MOVE_TO_Y
));
14841 if (PT
> CHARPOS (it
.current
.pos
))
14843 int y0
= line_bottom_y (&it
);
14844 /* Compute how many pixels below window bottom to stop searching
14845 for PT. This avoids costly search for PT that is far away if
14846 the user limited scrolling by a small number of lines, but
14847 always finds PT if scroll_conservatively is set to a large
14848 number, such as most-positive-fixnum. */
14849 int slack
= max (scroll_max
, 10 * frame_line_height
);
14850 int y_to_move
= it
.last_visible_y
+ slack
;
14852 /* Compute the distance from the scroll margin to PT or to
14853 the scroll limit, whichever comes first. This should
14854 include the height of the cursor line, to make that line
14856 move_it_to (&it
, PT
, -1, y_to_move
,
14857 -1, MOVE_TO_POS
| MOVE_TO_Y
);
14858 dy
= line_bottom_y (&it
) - y0
;
14860 if (dy
> scroll_max
)
14861 return SCROLLING_FAILED
;
14870 /* Point is in or below the bottom scroll margin, so move the
14871 window start down. If scrolling conservatively, move it just
14872 enough down to make point visible. If scroll_step is set,
14873 move it down by scroll_step. */
14874 if (arg_scroll_conservatively
)
14876 = min (max (dy
, frame_line_height
),
14877 frame_line_height
* arg_scroll_conservatively
);
14878 else if (scroll_step
|| temp_scroll_step
)
14879 amount_to_scroll
= scroll_max
;
14882 aggressive
= BVAR (current_buffer
, scroll_up_aggressively
);
14883 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14884 if (NUMBERP (aggressive
))
14886 double float_amount
= XFLOATINT (aggressive
) * height
;
14887 int aggressive_scroll
= float_amount
;
14888 if (aggressive_scroll
== 0 && float_amount
> 0)
14889 aggressive_scroll
= 1;
14890 /* Don't let point enter the scroll margin near top of
14891 the window. This could happen if the value of
14892 scroll_up_aggressively is too large and there are
14893 non-zero margins, because scroll_up_aggressively
14894 means put point that fraction of window height
14895 _from_the_bottom_margin_. */
14896 if (aggressive_scroll
+ 2*this_scroll_margin
> height
)
14897 aggressive_scroll
= height
- 2*this_scroll_margin
;
14898 amount_to_scroll
= dy
+ aggressive_scroll
;
14902 if (amount_to_scroll
<= 0)
14903 return SCROLLING_FAILED
;
14905 start_display (&it
, w
, startp
);
14906 if (arg_scroll_conservatively
<= scroll_limit
)
14907 move_it_vertically (&it
, amount_to_scroll
);
14910 /* Extra precision for users who set scroll-conservatively
14911 to a large number: make sure the amount we scroll
14912 the window start is never less than amount_to_scroll,
14913 which was computed as distance from window bottom to
14914 point. This matters when lines at window top and lines
14915 below window bottom have different height. */
14917 void *it1data
= NULL
;
14918 /* We use a temporary it1 because line_bottom_y can modify
14919 its argument, if it moves one line down; see there. */
14922 SAVE_IT (it1
, it
, it1data
);
14923 start_y
= line_bottom_y (&it1
);
14925 RESTORE_IT (&it
, &it
, it1data
);
14926 move_it_by_lines (&it
, 1);
14927 SAVE_IT (it1
, it
, it1data
);
14928 } while (line_bottom_y (&it1
) - start_y
< amount_to_scroll
);
14931 /* If STARTP is unchanged, move it down another screen line. */
14932 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
14933 move_it_by_lines (&it
, 1);
14934 startp
= it
.current
.pos
;
14938 struct text_pos scroll_margin_pos
= startp
;
14941 /* See if point is inside the scroll margin at the top of the
14943 if (this_scroll_margin
)
14947 start_display (&it
, w
, startp
);
14948 y_start
= it
.current_y
;
14949 move_it_vertically (&it
, this_scroll_margin
);
14950 scroll_margin_pos
= it
.current
.pos
;
14951 /* If we didn't move enough before hitting ZV, request
14952 additional amount of scroll, to move point out of the
14954 if (IT_CHARPOS (it
) == ZV
14955 && it
.current_y
- y_start
< this_scroll_margin
)
14956 y_offset
= this_scroll_margin
- (it
.current_y
- y_start
);
14959 if (PT
< CHARPOS (scroll_margin_pos
))
14961 /* Point is in the scroll margin at the top of the window or
14962 above what is displayed in the window. */
14965 /* Compute the vertical distance from PT to the scroll
14966 margin position. Move as far as scroll_max allows, or
14967 one screenful, or 10 screen lines, whichever is largest.
14968 Give up if distance is greater than scroll_max or if we
14969 didn't reach the scroll margin position. */
14970 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
14971 start_display (&it
, w
, pos
);
14973 y_to_move
= max (it
.last_visible_y
,
14974 max (scroll_max
, 10 * frame_line_height
));
14975 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
14977 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
14978 dy
= it
.current_y
- y0
;
14979 if (dy
> scroll_max
14980 || IT_CHARPOS (it
) < CHARPOS (scroll_margin_pos
))
14981 return SCROLLING_FAILED
;
14983 /* Additional scroll for when ZV was too close to point. */
14986 /* Compute new window start. */
14987 start_display (&it
, w
, startp
);
14989 if (arg_scroll_conservatively
)
14990 amount_to_scroll
= max (dy
, frame_line_height
*
14991 max (scroll_step
, temp_scroll_step
));
14992 else if (scroll_step
|| temp_scroll_step
)
14993 amount_to_scroll
= scroll_max
;
14996 aggressive
= BVAR (current_buffer
, scroll_down_aggressively
);
14997 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14998 if (NUMBERP (aggressive
))
15000 double float_amount
= XFLOATINT (aggressive
) * height
;
15001 int aggressive_scroll
= float_amount
;
15002 if (aggressive_scroll
== 0 && float_amount
> 0)
15003 aggressive_scroll
= 1;
15004 /* Don't let point enter the scroll margin near
15005 bottom of the window, if the value of
15006 scroll_down_aggressively happens to be too
15008 if (aggressive_scroll
+ 2*this_scroll_margin
> height
)
15009 aggressive_scroll
= height
- 2*this_scroll_margin
;
15010 amount_to_scroll
= dy
+ aggressive_scroll
;
15014 if (amount_to_scroll
<= 0)
15015 return SCROLLING_FAILED
;
15017 move_it_vertically_backward (&it
, amount_to_scroll
);
15018 startp
= it
.current
.pos
;
15022 /* Run window scroll functions. */
15023 startp
= run_window_scroll_functions (window
, startp
);
15025 /* Display the window. Give up if new fonts are loaded, or if point
15027 if (!try_window (window
, startp
, 0))
15028 rc
= SCROLLING_NEED_LARGER_MATRICES
;
15029 else if (w
->cursor
.vpos
< 0)
15031 clear_glyph_matrix (w
->desired_matrix
);
15032 rc
= SCROLLING_FAILED
;
15036 /* Maybe forget recorded base line for line number display. */
15037 if (!just_this_one_p
15038 || current_buffer
->clip_changed
15039 || BEG_UNCHANGED
< CHARPOS (startp
))
15040 w
->base_line_number
= 0;
15042 /* If cursor ends up on a partially visible line,
15043 treat that as being off the bottom of the screen. */
15044 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0)
15045 /* It's possible that the cursor is on the first line of the
15046 buffer, which is partially obscured due to a vscroll
15047 (Bug#7537). In that case, avoid looping forever . */
15048 && extra_scroll_margin_lines
< w
->desired_matrix
->nrows
- 1)
15050 clear_glyph_matrix (w
->desired_matrix
);
15051 ++extra_scroll_margin_lines
;
15054 rc
= SCROLLING_SUCCESS
;
15061 /* Compute a suitable window start for window W if display of W starts
15062 on a continuation line. Value is non-zero if a new window start
15065 The new window start will be computed, based on W's width, starting
15066 from the start of the continued line. It is the start of the
15067 screen line with the minimum distance from the old start W->start. */
15070 compute_window_start_on_continuation_line (struct window
*w
)
15072 struct text_pos pos
, start_pos
;
15073 int window_start_changed_p
= 0;
15075 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
15077 /* If window start is on a continuation line... Window start may be
15078 < BEGV in case there's invisible text at the start of the
15079 buffer (M-x rmail, for example). */
15080 if (CHARPOS (start_pos
) > BEGV
15081 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
15084 struct glyph_row
*row
;
15086 /* Handle the case that the window start is out of range. */
15087 if (CHARPOS (start_pos
) < BEGV
)
15088 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
15089 else if (CHARPOS (start_pos
) > ZV
)
15090 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
15092 /* Find the start of the continued line. This should be fast
15093 because find_newline is fast (newline cache). */
15094 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
15095 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
15096 row
, DEFAULT_FACE_ID
);
15097 reseat_at_previous_visible_line_start (&it
);
15099 /* If the line start is "too far" away from the window start,
15100 say it takes too much time to compute a new window start. */
15101 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
15102 /* PXW: Do we need upper bounds here ? */
15103 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
15105 int min_distance
, distance
;
15107 /* Move forward by display lines to find the new window
15108 start. If window width was enlarged, the new start can
15109 be expected to be > the old start. If window width was
15110 decreased, the new window start will be < the old start.
15111 So, we're looking for the display line start with the
15112 minimum distance from the old window start. */
15113 pos
= it
.current
.pos
;
15114 min_distance
= INFINITY
;
15115 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
15116 distance
< min_distance
)
15118 min_distance
= distance
;
15119 pos
= it
.current
.pos
;
15120 if (it
.line_wrap
== WORD_WRAP
)
15122 /* Under WORD_WRAP, move_it_by_lines is likely to
15123 overshoot and stop not at the first, but the
15124 second character from the left margin. So in
15125 that case, we need a more tight control on the X
15126 coordinate of the iterator than move_it_by_lines
15127 promises in its contract. The method is to first
15128 go to the last (rightmost) visible character of a
15129 line, then move to the leftmost character on the
15130 next line in a separate call. */
15131 move_it_to (&it
, ZV
, it
.last_visible_x
, it
.current_y
, -1,
15132 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15133 move_it_to (&it
, ZV
, 0,
15134 it
.current_y
+ it
.max_ascent
+ it
.max_descent
, -1,
15135 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15138 move_it_by_lines (&it
, 1);
15141 /* Set the window start there. */
15142 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
15143 window_start_changed_p
= 1;
15147 return window_start_changed_p
;
15151 /* Try cursor movement in case text has not changed in window WINDOW,
15152 with window start STARTP. Value is
15154 CURSOR_MOVEMENT_SUCCESS if successful
15156 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
15158 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
15159 display. *SCROLL_STEP is set to 1, under certain circumstances, if
15160 we want to scroll as if scroll-step were set to 1. See the code.
15162 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
15163 which case we have to abort this redisplay, and adjust matrices
15168 CURSOR_MOVEMENT_SUCCESS
,
15169 CURSOR_MOVEMENT_CANNOT_BE_USED
,
15170 CURSOR_MOVEMENT_MUST_SCROLL
,
15171 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
15175 try_cursor_movement (Lisp_Object window
, struct text_pos startp
, int *scroll_step
)
15177 struct window
*w
= XWINDOW (window
);
15178 struct frame
*f
= XFRAME (w
->frame
);
15179 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
15182 if (inhibit_try_cursor_movement
)
15186 /* Previously, there was a check for Lisp integer in the
15187 if-statement below. Now, this field is converted to
15188 ptrdiff_t, thus zero means invalid position in a buffer. */
15189 eassert (w
->last_point
> 0);
15190 /* Likewise there was a check whether window_end_vpos is nil or larger
15191 than the window. Now window_end_vpos is int and so never nil, but
15192 let's leave eassert to check whether it fits in the window. */
15193 eassert (w
->window_end_vpos
< w
->current_matrix
->nrows
);
15195 /* Handle case where text has not changed, only point, and it has
15196 not moved off the frame. */
15197 if (/* Point may be in this window. */
15198 PT
>= CHARPOS (startp
)
15199 /* Selective display hasn't changed. */
15200 && !current_buffer
->clip_changed
15201 /* Function force-mode-line-update is used to force a thorough
15202 redisplay. It sets either windows_or_buffers_changed or
15203 update_mode_lines. So don't take a shortcut here for these
15205 && !update_mode_lines
15206 && !windows_or_buffers_changed
15207 && !f
->cursor_type_changed
15208 && NILP (Vshow_trailing_whitespace
)
15209 /* This code is not used for mini-buffer for the sake of the case
15210 of redisplaying to replace an echo area message; since in
15211 that case the mini-buffer contents per se are usually
15212 unchanged. This code is of no real use in the mini-buffer
15213 since the handling of this_line_start_pos, etc., in redisplay
15214 handles the same cases. */
15215 && !EQ (window
, minibuf_window
)
15216 && (FRAME_WINDOW_P (f
)
15217 || !overlay_arrow_in_current_buffer_p ()))
15219 int this_scroll_margin
, top_scroll_margin
;
15220 struct glyph_row
*row
= NULL
;
15221 int frame_line_height
= default_line_pixel_height (w
);
15222 int window_total_lines
15223 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
15226 debug_method_add (w
, "cursor movement");
15229 /* Scroll if point within this distance from the top or bottom
15230 of the window. This is a pixel value. */
15231 if (scroll_margin
> 0)
15233 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4);
15234 this_scroll_margin
*= frame_line_height
;
15237 this_scroll_margin
= 0;
15239 top_scroll_margin
= this_scroll_margin
;
15240 if (WINDOW_WANTS_HEADER_LINE_P (w
))
15241 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
15243 /* Start with the row the cursor was displayed during the last
15244 not paused redisplay. Give up if that row is not valid. */
15245 if (w
->last_cursor_vpos
< 0
15246 || w
->last_cursor_vpos
>= w
->current_matrix
->nrows
)
15247 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15250 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor_vpos
);
15251 if (row
->mode_line_p
)
15253 if (!row
->enabled_p
)
15254 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15257 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
15259 int scroll_p
= 0, must_scroll
= 0;
15260 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
15262 if (PT
> w
->last_point
)
15264 /* Point has moved forward. */
15265 while (MATRIX_ROW_END_CHARPOS (row
) < PT
15266 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
15268 eassert (row
->enabled_p
);
15272 /* If the end position of a row equals the start
15273 position of the next row, and PT is at that position,
15274 we would rather display cursor in the next line. */
15275 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15276 && MATRIX_ROW_END_CHARPOS (row
) == PT
15277 && row
< MATRIX_MODE_LINE_ROW (w
->current_matrix
)
15278 && MATRIX_ROW_START_CHARPOS (row
+1) == PT
15279 && !cursor_row_p (row
))
15282 /* If within the scroll margin, scroll. Note that
15283 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
15284 the next line would be drawn, and that
15285 this_scroll_margin can be zero. */
15286 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
15287 || PT
> MATRIX_ROW_END_CHARPOS (row
)
15288 /* Line is completely visible last line in window
15289 and PT is to be set in the next line. */
15290 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
15291 && PT
== MATRIX_ROW_END_CHARPOS (row
)
15292 && !row
->ends_at_zv_p
15293 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
15296 else if (PT
< w
->last_point
)
15298 /* Cursor has to be moved backward. Note that PT >=
15299 CHARPOS (startp) because of the outer if-statement. */
15300 while (!row
->mode_line_p
15301 && (MATRIX_ROW_START_CHARPOS (row
) > PT
15302 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15303 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
15304 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
15305 row
> w
->current_matrix
->rows
15306 && (row
-1)->ends_in_newline_from_string_p
))))
15307 && (row
->y
> top_scroll_margin
15308 || CHARPOS (startp
) == BEGV
))
15310 eassert (row
->enabled_p
);
15314 /* Consider the following case: Window starts at BEGV,
15315 there is invisible, intangible text at BEGV, so that
15316 display starts at some point START > BEGV. It can
15317 happen that we are called with PT somewhere between
15318 BEGV and START. Try to handle that case. */
15319 if (row
< w
->current_matrix
->rows
15320 || row
->mode_line_p
)
15322 row
= w
->current_matrix
->rows
;
15323 if (row
->mode_line_p
)
15327 /* Due to newlines in overlay strings, we may have to
15328 skip forward over overlay strings. */
15329 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15330 && MATRIX_ROW_END_CHARPOS (row
) == PT
15331 && !cursor_row_p (row
))
15334 /* If within the scroll margin, scroll. */
15335 if (row
->y
< top_scroll_margin
15336 && CHARPOS (startp
) != BEGV
)
15341 /* Cursor did not move. So don't scroll even if cursor line
15342 is partially visible, as it was so before. */
15343 rc
= CURSOR_MOVEMENT_SUCCESS
;
15346 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
15347 || PT
> MATRIX_ROW_END_CHARPOS (row
))
15349 /* if PT is not in the glyph row, give up. */
15350 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15353 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15354 && !NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
15356 struct glyph_row
*row1
;
15358 /* If rows are bidi-reordered and point moved, back up
15359 until we find a row that does not belong to a
15360 continuation line. This is because we must consider
15361 all rows of a continued line as candidates for the
15362 new cursor positioning, since row start and end
15363 positions change non-linearly with vertical position
15365 /* FIXME: Revisit this when glyph ``spilling'' in
15366 continuation lines' rows is implemented for
15367 bidi-reordered rows. */
15368 for (row1
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15369 MATRIX_ROW_CONTINUATION_LINE_P (row
);
15372 /* If we hit the beginning of the displayed portion
15373 without finding the first row of a continued
15377 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15380 eassert (row
->enabled_p
);
15385 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15386 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
15387 /* Make sure this isn't a header line by any chance, since
15388 then MATRIX_ROW_PARTIALLY_VISIBLE_P might yield non-zero. */
15389 && !row
->mode_line_p
15390 && make_cursor_line_fully_visible_p
)
15392 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
15393 && !row
->ends_at_zv_p
15394 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15395 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15396 else if (row
->height
> window_box_height (w
))
15398 /* If we end up in a partially visible line, let's
15399 make it fully visible, except when it's taller
15400 than the window, in which case we can't do much
15403 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15407 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15408 if (!cursor_row_fully_visible_p (w
, 0, 1))
15409 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15411 rc
= CURSOR_MOVEMENT_SUCCESS
;
15415 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15416 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15417 && !NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
15419 /* With bidi-reordered rows, there could be more than
15420 one candidate row whose start and end positions
15421 occlude point. We need to let set_cursor_from_row
15422 find the best candidate. */
15423 /* FIXME: Revisit this when glyph ``spilling'' in
15424 continuation lines' rows is implemented for
15425 bidi-reordered rows. */
15430 int at_zv_p
= 0, exact_match_p
= 0;
15432 if (MATRIX_ROW_START_CHARPOS (row
) <= PT
15433 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
15434 && cursor_row_p (row
))
15435 rv
|= set_cursor_from_row (w
, row
, w
->current_matrix
,
15437 /* As soon as we've found the exact match for point,
15438 or the first suitable row whose ends_at_zv_p flag
15439 is set, we are done. */
15441 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
)->ends_at_zv_p
;
15443 && w
->cursor
.hpos
>= 0
15444 && w
->cursor
.hpos
< MATRIX_ROW_USED (w
->current_matrix
,
15447 struct glyph_row
*candidate
=
15448 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
15450 candidate
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
15451 ptrdiff_t endpos
= MATRIX_ROW_END_CHARPOS (candidate
);
15454 (BUFFERP (g
->object
) && g
->charpos
== PT
)
15455 || (INTEGERP (g
->object
)
15456 && (g
->charpos
== PT
15457 || (g
->charpos
== 0 && endpos
- 1 == PT
)));
15459 if (rv
&& (at_zv_p
|| exact_match_p
))
15461 rc
= CURSOR_MOVEMENT_SUCCESS
;
15464 if (MATRIX_ROW_BOTTOM_Y (row
) == last_y
)
15468 while (((MATRIX_ROW_CONTINUATION_LINE_P (row
)
15469 || row
->continued_p
)
15470 && MATRIX_ROW_BOTTOM_Y (row
) <= last_y
)
15471 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15472 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
));
15473 /* If we didn't find any candidate rows, or exited the
15474 loop before all the candidates were examined, signal
15475 to the caller that this method failed. */
15476 if (rc
!= CURSOR_MOVEMENT_SUCCESS
15478 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
15479 && !row
->continued_p
))
15480 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15482 rc
= CURSOR_MOVEMENT_SUCCESS
;
15488 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
15490 rc
= CURSOR_MOVEMENT_SUCCESS
;
15495 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15496 && MATRIX_ROW_START_CHARPOS (row
) == PT
15497 && cursor_row_p (row
));
15505 #if !defined USE_TOOLKIT_SCROLL_BARS || defined USE_GTK
15509 set_vertical_scroll_bar (struct window
*w
)
15511 ptrdiff_t start
, end
, whole
;
15513 /* Calculate the start and end positions for the current window.
15514 At some point, it would be nice to choose between scrollbars
15515 which reflect the whole buffer size, with special markers
15516 indicating narrowing, and scrollbars which reflect only the
15519 Note that mini-buffers sometimes aren't displaying any text. */
15520 if (!MINI_WINDOW_P (w
)
15521 || (w
== XWINDOW (minibuf_window
)
15522 && NILP (echo_area_buffer
[0])))
15524 struct buffer
*buf
= XBUFFER (w
->contents
);
15525 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
15526 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
15527 /* I don't think this is guaranteed to be right. For the
15528 moment, we'll pretend it is. */
15529 end
= BUF_Z (buf
) - w
->window_end_pos
- BUF_BEGV (buf
);
15533 if (whole
< (end
- start
))
15534 whole
= end
- start
;
15537 start
= end
= whole
= 0;
15539 /* Indicate what this scroll bar ought to be displaying now. */
15540 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15541 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15542 (w
, end
- start
, whole
, start
);
15546 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
15547 selected_window is redisplayed.
15549 We can return without actually redisplaying the window if fonts has been
15550 changed on window's frame. In that case, redisplay_internal will retry. */
15553 redisplay_window (Lisp_Object window
, bool just_this_one_p
)
15555 struct window
*w
= XWINDOW (window
);
15556 struct frame
*f
= XFRAME (w
->frame
);
15557 struct buffer
*buffer
= XBUFFER (w
->contents
);
15558 struct buffer
*old
= current_buffer
;
15559 struct text_pos lpoint
, opoint
, startp
;
15560 int update_mode_line
;
15563 /* Record it now because it's overwritten. */
15564 bool current_matrix_up_to_date_p
= false;
15565 bool used_current_matrix_p
= false;
15566 /* This is less strict than current_matrix_up_to_date_p.
15567 It indicates that the buffer contents and narrowing are unchanged. */
15568 bool buffer_unchanged_p
= false;
15569 int temp_scroll_step
= 0;
15570 ptrdiff_t count
= SPECPDL_INDEX ();
15572 int centering_position
= -1;
15573 int last_line_misfit
= 0;
15574 ptrdiff_t beg_unchanged
, end_unchanged
;
15575 int frame_line_height
;
15577 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15581 *w
->desired_matrix
->method
= 0;
15584 if (!just_this_one_p
15585 && REDISPLAY_SOME_P ()
15588 && !buffer
->text
->redisplay
)
15591 /* Make sure that both W's markers are valid. */
15592 eassert (XMARKER (w
->start
)->buffer
== buffer
);
15593 eassert (XMARKER (w
->pointm
)->buffer
== buffer
);
15596 reconsider_clip_changes (w
);
15597 frame_line_height
= default_line_pixel_height (w
);
15599 /* Has the mode line to be updated? */
15600 update_mode_line
= (w
->update_mode_line
15601 || update_mode_lines
15602 || buffer
->clip_changed
15603 || buffer
->prevent_redisplay_optimizations_p
);
15605 if (!just_this_one_p
)
15606 /* If `just_this_one_p' is set, we apparently set must_be_updated_p more
15607 cleverly elsewhere. */
15608 w
->must_be_updated_p
= true;
15610 if (MINI_WINDOW_P (w
))
15612 if (w
== XWINDOW (echo_area_window
)
15613 && !NILP (echo_area_buffer
[0]))
15615 if (update_mode_line
)
15616 /* We may have to update a tty frame's menu bar or a
15617 tool-bar. Example `M-x C-h C-h C-g'. */
15618 goto finish_menu_bars
;
15620 /* We've already displayed the echo area glyphs in this window. */
15621 goto finish_scroll_bars
;
15623 else if ((w
!= XWINDOW (minibuf_window
)
15624 || minibuf_level
== 0)
15625 /* When buffer is nonempty, redisplay window normally. */
15626 && BUF_Z (XBUFFER (w
->contents
)) == BUF_BEG (XBUFFER (w
->contents
))
15627 /* Quail displays non-mini buffers in minibuffer window.
15628 In that case, redisplay the window normally. */
15629 && !NILP (Fmemq (w
->contents
, Vminibuffer_list
)))
15631 /* W is a mini-buffer window, but it's not active, so clear
15633 int yb
= window_text_bottom_y (w
);
15634 struct glyph_row
*row
;
15637 for (y
= 0, row
= w
->desired_matrix
->rows
;
15639 y
+= row
->height
, ++row
)
15640 blank_row (w
, row
, y
);
15641 goto finish_scroll_bars
;
15644 clear_glyph_matrix (w
->desired_matrix
);
15647 /* Otherwise set up data on this window; select its buffer and point
15649 /* Really select the buffer, for the sake of buffer-local
15651 set_buffer_internal_1 (XBUFFER (w
->contents
));
15653 current_matrix_up_to_date_p
15654 = (w
->window_end_valid
15655 && !current_buffer
->clip_changed
15656 && !current_buffer
->prevent_redisplay_optimizations_p
15657 && !window_outdated (w
));
15659 /* Run the window-bottom-change-functions
15660 if it is possible that the text on the screen has changed
15661 (either due to modification of the text, or any other reason). */
15662 if (!current_matrix_up_to_date_p
15663 && !NILP (Vwindow_text_change_functions
))
15665 safe_run_hooks (Qwindow_text_change_functions
);
15669 beg_unchanged
= BEG_UNCHANGED
;
15670 end_unchanged
= END_UNCHANGED
;
15672 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
15674 specbind (Qinhibit_point_motion_hooks
, Qt
);
15677 = (w
->window_end_valid
15678 && !current_buffer
->clip_changed
15679 && !window_outdated (w
));
15681 /* When windows_or_buffers_changed is non-zero, we can't rely
15682 on the window end being valid, so set it to zero there. */
15683 if (windows_or_buffers_changed
)
15685 /* If window starts on a continuation line, maybe adjust the
15686 window start in case the window's width changed. */
15687 if (XMARKER (w
->start
)->buffer
== current_buffer
)
15688 compute_window_start_on_continuation_line (w
);
15690 w
->window_end_valid
= false;
15691 /* If so, we also can't rely on current matrix
15692 and should not fool try_cursor_movement below. */
15693 current_matrix_up_to_date_p
= false;
15696 /* Some sanity checks. */
15697 CHECK_WINDOW_END (w
);
15698 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
15700 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
15703 if (mode_line_update_needed (w
))
15704 update_mode_line
= 1;
15706 /* Point refers normally to the selected window. For any other
15707 window, set up appropriate value. */
15708 if (!EQ (window
, selected_window
))
15710 ptrdiff_t new_pt
= marker_position (w
->pointm
);
15711 ptrdiff_t new_pt_byte
= marker_byte_position (w
->pointm
);
15715 new_pt_byte
= BEGV_BYTE
;
15716 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
15718 else if (new_pt
> (ZV
- 1))
15721 new_pt_byte
= ZV_BYTE
;
15722 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
15725 /* We don't use SET_PT so that the point-motion hooks don't run. */
15726 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
15729 /* If any of the character widths specified in the display table
15730 have changed, invalidate the width run cache. It's true that
15731 this may be a bit late to catch such changes, but the rest of
15732 redisplay goes (non-fatally) haywire when the display table is
15733 changed, so why should we worry about doing any better? */
15734 if (current_buffer
->width_run_cache
)
15736 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
15738 if (! disptab_matches_widthtab
15739 (disptab
, XVECTOR (BVAR (current_buffer
, width_table
))))
15741 invalidate_region_cache (current_buffer
,
15742 current_buffer
->width_run_cache
,
15744 recompute_width_table (current_buffer
, disptab
);
15748 /* If window-start is screwed up, choose a new one. */
15749 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
15752 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15754 /* If someone specified a new starting point but did not insist,
15755 check whether it can be used. */
15756 if (w
->optional_new_start
15757 && CHARPOS (startp
) >= BEGV
15758 && CHARPOS (startp
) <= ZV
)
15760 w
->optional_new_start
= 0;
15761 start_display (&it
, w
, startp
);
15762 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
15763 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15764 if (IT_CHARPOS (it
) == PT
)
15765 w
->force_start
= 1;
15766 /* IT may overshoot PT if text at PT is invisible. */
15767 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
15768 w
->force_start
= 1;
15773 /* Handle case where place to start displaying has been specified,
15774 unless the specified location is outside the accessible range. */
15775 if (w
->force_start
|| window_frozen_p (w
))
15777 /* We set this later on if we have to adjust point. */
15780 w
->force_start
= 0;
15782 w
->window_end_valid
= 0;
15784 /* Forget any recorded base line for line number display. */
15785 if (!buffer_unchanged_p
)
15786 w
->base_line_number
= 0;
15788 /* Redisplay the mode line. Select the buffer properly for that.
15789 Also, run the hook window-scroll-functions
15790 because we have scrolled. */
15791 /* Note, we do this after clearing force_start because
15792 if there's an error, it is better to forget about force_start
15793 than to get into an infinite loop calling the hook functions
15794 and having them get more errors. */
15795 if (!update_mode_line
15796 || ! NILP (Vwindow_scroll_functions
))
15798 update_mode_line
= 1;
15799 w
->update_mode_line
= 1;
15800 startp
= run_window_scroll_functions (window
, startp
);
15803 if (CHARPOS (startp
) < BEGV
)
15804 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
15805 else if (CHARPOS (startp
) > ZV
)
15806 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
15808 /* Redisplay, then check if cursor has been set during the
15809 redisplay. Give up if new fonts were loaded. */
15810 /* We used to issue a CHECK_MARGINS argument to try_window here,
15811 but this causes scrolling to fail when point begins inside
15812 the scroll margin (bug#148) -- cyd */
15813 if (!try_window (window
, startp
, 0))
15815 w
->force_start
= 1;
15816 clear_glyph_matrix (w
->desired_matrix
);
15817 goto need_larger_matrices
;
15820 if (w
->cursor
.vpos
< 0 && !window_frozen_p (w
))
15822 /* If point does not appear, try to move point so it does
15823 appear. The desired matrix has been built above, so we
15824 can use it here. */
15825 new_vpos
= window_box_height (w
) / 2;
15828 if (!cursor_row_fully_visible_p (w
, 0, 0))
15830 /* Point does appear, but on a line partly visible at end of window.
15831 Move it back to a fully-visible line. */
15832 new_vpos
= window_box_height (w
);
15834 else if (w
->cursor
.vpos
>= 0)
15836 /* Some people insist on not letting point enter the scroll
15837 margin, even though this part handles windows that didn't
15839 int window_total_lines
15840 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
15841 int margin
= min (scroll_margin
, window_total_lines
/ 4);
15842 int pixel_margin
= margin
* frame_line_height
;
15843 bool header_line
= WINDOW_WANTS_HEADER_LINE_P (w
);
15845 /* Note: We add an extra FRAME_LINE_HEIGHT, because the loop
15846 below, which finds the row to move point to, advances by
15847 the Y coordinate of the _next_ row, see the definition of
15848 MATRIX_ROW_BOTTOM_Y. */
15849 if (w
->cursor
.vpos
< margin
+ header_line
)
15851 w
->cursor
.vpos
= -1;
15852 clear_glyph_matrix (w
->desired_matrix
);
15853 goto try_to_scroll
;
15857 int window_height
= window_box_height (w
);
15860 window_height
+= CURRENT_HEADER_LINE_HEIGHT (w
);
15861 if (w
->cursor
.y
>= window_height
- pixel_margin
)
15863 w
->cursor
.vpos
= -1;
15864 clear_glyph_matrix (w
->desired_matrix
);
15865 goto try_to_scroll
;
15870 /* If we need to move point for either of the above reasons,
15871 now actually do it. */
15874 struct glyph_row
*row
;
15876 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
15877 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
15880 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
15881 MATRIX_ROW_START_BYTEPOS (row
));
15883 if (w
!= XWINDOW (selected_window
))
15884 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
15885 else if (current_buffer
== old
)
15886 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15888 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
15890 /* If we are highlighting the region, then we just changed
15891 the region, so redisplay to show it. */
15892 /* FIXME: We need to (re)run pre-redisplay-function! */
15893 /* if (markpos_of_region () >= 0)
15895 clear_glyph_matrix (w->desired_matrix);
15896 if (!try_window (window, startp, 0))
15897 goto need_larger_matrices;
15903 debug_method_add (w
, "forced window start");
15908 /* Handle case where text has not changed, only point, and it has
15909 not moved off the frame, and we are not retrying after hscroll.
15910 (current_matrix_up_to_date_p is nonzero when retrying.) */
15911 if (current_matrix_up_to_date_p
15912 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
15913 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
15917 case CURSOR_MOVEMENT_SUCCESS
:
15918 used_current_matrix_p
= 1;
15921 case CURSOR_MOVEMENT_MUST_SCROLL
:
15922 goto try_to_scroll
;
15928 /* If current starting point was originally the beginning of a line
15929 but no longer is, find a new starting point. */
15930 else if (w
->start_at_line_beg
15931 && !(CHARPOS (startp
) <= BEGV
15932 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
15935 debug_method_add (w
, "recenter 1");
15940 /* Try scrolling with try_window_id. Value is > 0 if update has
15941 been done, it is -1 if we know that the same window start will
15942 not work. It is 0 if unsuccessful for some other reason. */
15943 else if ((tem
= try_window_id (w
)) != 0)
15946 debug_method_add (w
, "try_window_id %d", tem
);
15949 if (f
->fonts_changed
)
15950 goto need_larger_matrices
;
15954 /* Otherwise try_window_id has returned -1 which means that we
15955 don't want the alternative below this comment to execute. */
15957 else if (CHARPOS (startp
) >= BEGV
15958 && CHARPOS (startp
) <= ZV
15959 && PT
>= CHARPOS (startp
)
15960 && (CHARPOS (startp
) < ZV
15961 /* Avoid starting at end of buffer. */
15962 || CHARPOS (startp
) == BEGV
15963 || !window_outdated (w
)))
15965 int d1
, d2
, d3
, d4
, d5
, d6
;
15967 /* If first window line is a continuation line, and window start
15968 is inside the modified region, but the first change is before
15969 current window start, we must select a new window start.
15971 However, if this is the result of a down-mouse event (e.g. by
15972 extending the mouse-drag-overlay), we don't want to select a
15973 new window start, since that would change the position under
15974 the mouse, resulting in an unwanted mouse-movement rather
15975 than a simple mouse-click. */
15976 if (!w
->start_at_line_beg
15977 && NILP (do_mouse_tracking
)
15978 && CHARPOS (startp
) > BEGV
15979 && CHARPOS (startp
) > BEG
+ beg_unchanged
15980 && CHARPOS (startp
) <= Z
- end_unchanged
15981 /* Even if w->start_at_line_beg is nil, a new window may
15982 start at a line_beg, since that's how set_buffer_window
15983 sets it. So, we need to check the return value of
15984 compute_window_start_on_continuation_line. (See also
15986 && XMARKER (w
->start
)->buffer
== current_buffer
15987 && compute_window_start_on_continuation_line (w
)
15988 /* It doesn't make sense to force the window start like we
15989 do at label force_start if it is already known that point
15990 will not be visible in the resulting window, because
15991 doing so will move point from its correct position
15992 instead of scrolling the window to bring point into view.
15994 && pos_visible_p (w
, PT
, &d1
, &d2
, &d3
, &d4
, &d5
, &d6
))
15996 w
->force_start
= 1;
15997 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
16002 debug_method_add (w
, "same window start");
16005 /* Try to redisplay starting at same place as before.
16006 If point has not moved off frame, accept the results. */
16007 if (!current_matrix_up_to_date_p
16008 /* Don't use try_window_reusing_current_matrix in this case
16009 because a window scroll function can have changed the
16011 || !NILP (Vwindow_scroll_functions
)
16012 || MINI_WINDOW_P (w
)
16013 || !(used_current_matrix_p
16014 = try_window_reusing_current_matrix (w
)))
16016 IF_DEBUG (debug_method_add (w
, "1"));
16017 if (try_window (window
, startp
, TRY_WINDOW_CHECK_MARGINS
) < 0)
16018 /* -1 means we need to scroll.
16019 0 means we need new matrices, but fonts_changed
16020 is set in that case, so we will detect it below. */
16021 goto try_to_scroll
;
16024 if (f
->fonts_changed
)
16025 goto need_larger_matrices
;
16027 if (w
->cursor
.vpos
>= 0)
16029 if (!just_this_one_p
16030 || current_buffer
->clip_changed
16031 || BEG_UNCHANGED
< CHARPOS (startp
))
16032 /* Forget any recorded base line for line number display. */
16033 w
->base_line_number
= 0;
16035 if (!cursor_row_fully_visible_p (w
, 1, 0))
16037 clear_glyph_matrix (w
->desired_matrix
);
16038 last_line_misfit
= 1;
16040 /* Drop through and scroll. */
16045 clear_glyph_matrix (w
->desired_matrix
);
16050 /* Redisplay the mode line. Select the buffer properly for that. */
16051 if (!update_mode_line
)
16053 update_mode_line
= 1;
16054 w
->update_mode_line
= 1;
16057 /* Try to scroll by specified few lines. */
16058 if ((scroll_conservatively
16059 || emacs_scroll_step
16060 || temp_scroll_step
16061 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
))
16062 || NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
)))
16063 && CHARPOS (startp
) >= BEGV
16064 && CHARPOS (startp
) <= ZV
)
16066 /* The function returns -1 if new fonts were loaded, 1 if
16067 successful, 0 if not successful. */
16068 int ss
= try_scrolling (window
, just_this_one_p
,
16069 scroll_conservatively
,
16071 temp_scroll_step
, last_line_misfit
);
16074 case SCROLLING_SUCCESS
:
16077 case SCROLLING_NEED_LARGER_MATRICES
:
16078 goto need_larger_matrices
;
16080 case SCROLLING_FAILED
:
16088 /* Finally, just choose a place to start which positions point
16089 according to user preferences. */
16094 debug_method_add (w
, "recenter");
16097 /* Forget any previously recorded base line for line number display. */
16098 if (!buffer_unchanged_p
)
16099 w
->base_line_number
= 0;
16101 /* Determine the window start relative to point. */
16102 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
16103 it
.current_y
= it
.last_visible_y
;
16104 if (centering_position
< 0)
16106 int window_total_lines
16107 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
16110 ? min (scroll_margin
, window_total_lines
/ 4)
16112 ptrdiff_t margin_pos
= CHARPOS (startp
);
16113 Lisp_Object aggressive
;
16116 /* If there is a scroll margin at the top of the window, find
16117 its character position. */
16119 /* Cannot call start_display if startp is not in the
16120 accessible region of the buffer. This can happen when we
16121 have just switched to a different buffer and/or changed
16122 its restriction. In that case, startp is initialized to
16123 the character position 1 (BEGV) because we did not yet
16124 have chance to display the buffer even once. */
16125 && BEGV
<= CHARPOS (startp
) && CHARPOS (startp
) <= ZV
)
16128 void *it1data
= NULL
;
16130 SAVE_IT (it1
, it
, it1data
);
16131 start_display (&it1
, w
, startp
);
16132 move_it_vertically (&it1
, margin
* frame_line_height
);
16133 margin_pos
= IT_CHARPOS (it1
);
16134 RESTORE_IT (&it
, &it
, it1data
);
16136 scrolling_up
= PT
> margin_pos
;
16139 ? BVAR (current_buffer
, scroll_up_aggressively
)
16140 : BVAR (current_buffer
, scroll_down_aggressively
);
16142 if (!MINI_WINDOW_P (w
)
16143 && (scroll_conservatively
> SCROLL_LIMIT
|| NUMBERP (aggressive
)))
16147 /* Setting scroll-conservatively overrides
16148 scroll-*-aggressively. */
16149 if (!scroll_conservatively
&& NUMBERP (aggressive
))
16151 double float_amount
= XFLOATINT (aggressive
);
16153 pt_offset
= float_amount
* WINDOW_BOX_TEXT_HEIGHT (w
);
16154 if (pt_offset
== 0 && float_amount
> 0)
16156 if (pt_offset
&& margin
> 0)
16159 /* Compute how much to move the window start backward from
16160 point so that point will be displayed where the user
16164 centering_position
= it
.last_visible_y
;
16166 centering_position
-= pt_offset
;
16167 centering_position
-=
16168 frame_line_height
* (1 + margin
+ (last_line_misfit
!= 0))
16169 + WINDOW_HEADER_LINE_HEIGHT (w
);
16170 /* Don't let point enter the scroll margin near top of
16172 if (centering_position
< margin
* frame_line_height
)
16173 centering_position
= margin
* frame_line_height
;
16176 centering_position
= margin
* frame_line_height
+ pt_offset
;
16179 /* Set the window start half the height of the window backward
16181 centering_position
= window_box_height (w
) / 2;
16183 move_it_vertically_backward (&it
, centering_position
);
16185 eassert (IT_CHARPOS (it
) >= BEGV
);
16187 /* The function move_it_vertically_backward may move over more
16188 than the specified y-distance. If it->w is small, e.g. a
16189 mini-buffer window, we may end up in front of the window's
16190 display area. Start displaying at the start of the line
16191 containing PT in this case. */
16192 if (it
.current_y
<= 0)
16194 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
16195 move_it_vertically_backward (&it
, 0);
16199 it
.current_x
= it
.hpos
= 0;
16201 /* Set the window start position here explicitly, to avoid an
16202 infinite loop in case the functions in window-scroll-functions
16204 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
16206 /* Run scroll hooks. */
16207 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
16209 /* Redisplay the window. */
16210 if (!current_matrix_up_to_date_p
16211 || windows_or_buffers_changed
16212 || f
->cursor_type_changed
16213 /* Don't use try_window_reusing_current_matrix in this case
16214 because it can have changed the buffer. */
16215 || !NILP (Vwindow_scroll_functions
)
16216 || !just_this_one_p
16217 || MINI_WINDOW_P (w
)
16218 || !(used_current_matrix_p
16219 = try_window_reusing_current_matrix (w
)))
16220 try_window (window
, startp
, 0);
16222 /* If new fonts have been loaded (due to fontsets), give up. We
16223 have to start a new redisplay since we need to re-adjust glyph
16225 if (f
->fonts_changed
)
16226 goto need_larger_matrices
;
16228 /* If cursor did not appear assume that the middle of the window is
16229 in the first line of the window. Do it again with the next line.
16230 (Imagine a window of height 100, displaying two lines of height
16231 60. Moving back 50 from it->last_visible_y will end in the first
16233 if (w
->cursor
.vpos
< 0)
16235 if (w
->window_end_valid
&& PT
>= Z
- w
->window_end_pos
)
16237 clear_glyph_matrix (w
->desired_matrix
);
16238 move_it_by_lines (&it
, 1);
16239 try_window (window
, it
.current
.pos
, 0);
16241 else if (PT
< IT_CHARPOS (it
))
16243 clear_glyph_matrix (w
->desired_matrix
);
16244 move_it_by_lines (&it
, -1);
16245 try_window (window
, it
.current
.pos
, 0);
16249 /* Not much we can do about it. */
16253 /* Consider the following case: Window starts at BEGV, there is
16254 invisible, intangible text at BEGV, so that display starts at
16255 some point START > BEGV. It can happen that we are called with
16256 PT somewhere between BEGV and START. Try to handle that case. */
16257 if (w
->cursor
.vpos
< 0)
16259 struct glyph_row
*row
= w
->current_matrix
->rows
;
16260 if (row
->mode_line_p
)
16262 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
16265 if (!cursor_row_fully_visible_p (w
, 0, 0))
16267 /* If vscroll is enabled, disable it and try again. */
16271 clear_glyph_matrix (w
->desired_matrix
);
16275 /* Users who set scroll-conservatively to a large number want
16276 point just above/below the scroll margin. If we ended up
16277 with point's row partially visible, move the window start to
16278 make that row fully visible and out of the margin. */
16279 if (scroll_conservatively
> SCROLL_LIMIT
)
16281 int window_total_lines
16282 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) * frame_line_height
;
16285 ? min (scroll_margin
, window_total_lines
/ 4)
16287 int move_down
= w
->cursor
.vpos
>= window_total_lines
/ 2;
16289 move_it_by_lines (&it
, move_down
? margin
+ 1 : -(margin
+ 1));
16290 clear_glyph_matrix (w
->desired_matrix
);
16291 if (1 == try_window (window
, it
.current
.pos
,
16292 TRY_WINDOW_CHECK_MARGINS
))
16296 /* If centering point failed to make the whole line visible,
16297 put point at the top instead. That has to make the whole line
16298 visible, if it can be done. */
16299 if (centering_position
== 0)
16302 clear_glyph_matrix (w
->desired_matrix
);
16303 centering_position
= 0;
16309 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
16310 w
->start_at_line_beg
= (CHARPOS (startp
) == BEGV
16311 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n');
16313 /* Display the mode line, if we must. */
16314 if ((update_mode_line
16315 /* If window not full width, must redo its mode line
16316 if (a) the window to its side is being redone and
16317 (b) we do a frame-based redisplay. This is a consequence
16318 of how inverted lines are drawn in frame-based redisplay. */
16319 || (!just_this_one_p
16320 && !FRAME_WINDOW_P (f
)
16321 && !WINDOW_FULL_WIDTH_P (w
))
16322 /* Line number to display. */
16323 || w
->base_line_pos
> 0
16324 /* Column number is displayed and different from the one displayed. */
16325 || (w
->column_number_displayed
!= -1
16326 && (w
->column_number_displayed
!= current_column ())))
16327 /* This means that the window has a mode line. */
16328 && (WINDOW_WANTS_MODELINE_P (w
)
16329 || WINDOW_WANTS_HEADER_LINE_P (w
)))
16332 display_mode_lines (w
);
16334 /* If mode line height has changed, arrange for a thorough
16335 immediate redisplay using the correct mode line height. */
16336 if (WINDOW_WANTS_MODELINE_P (w
)
16337 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
16339 f
->fonts_changed
= 1;
16340 w
->mode_line_height
= -1;
16341 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
16342 = DESIRED_MODE_LINE_HEIGHT (w
);
16345 /* If header line height has changed, arrange for a thorough
16346 immediate redisplay using the correct header line height. */
16347 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16348 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
16350 f
->fonts_changed
= 1;
16351 w
->header_line_height
= -1;
16352 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
16353 = DESIRED_HEADER_LINE_HEIGHT (w
);
16356 if (f
->fonts_changed
)
16357 goto need_larger_matrices
;
16360 if (!line_number_displayed
&& w
->base_line_pos
!= -1)
16362 w
->base_line_pos
= 0;
16363 w
->base_line_number
= 0;
16368 /* When we reach a frame's selected window, redo the frame's menu bar. */
16369 if (update_mode_line
16370 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
16372 int redisplay_menu_p
= 0;
16374 if (FRAME_WINDOW_P (f
))
16376 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
16377 || defined (HAVE_NS) || defined (USE_GTK)
16378 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
16380 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16384 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16386 if (redisplay_menu_p
)
16387 display_menu_bar (w
);
16389 #ifdef HAVE_WINDOW_SYSTEM
16390 if (FRAME_WINDOW_P (f
))
16392 #if defined (USE_GTK) || defined (HAVE_NS)
16393 if (FRAME_EXTERNAL_TOOL_BAR (f
))
16394 redisplay_tool_bar (f
);
16396 if (WINDOWP (f
->tool_bar_window
)
16397 && (FRAME_TOOL_BAR_HEIGHT (f
) > 0
16398 || !NILP (Vauto_resize_tool_bars
))
16399 && redisplay_tool_bar (f
))
16400 ignore_mouse_drag_p
= 1;
16406 #ifdef HAVE_WINDOW_SYSTEM
16407 if (FRAME_WINDOW_P (f
)
16408 && update_window_fringes (w
, (just_this_one_p
16409 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
16410 || w
->pseudo_window_p
)))
16414 if (draw_window_fringes (w
, 1))
16416 if (WINDOW_RIGHT_DIVIDER_WIDTH (w
))
16417 x_draw_right_divider (w
);
16419 x_draw_vertical_border (w
);
16425 if (WINDOW_BOTTOM_DIVIDER_WIDTH (w
))
16426 x_draw_bottom_divider (w
);
16427 #endif /* HAVE_WINDOW_SYSTEM */
16429 /* We go to this label, with fonts_changed set, if it is
16430 necessary to try again using larger glyph matrices.
16431 We have to redeem the scroll bar even in this case,
16432 because the loop in redisplay_internal expects that. */
16433 need_larger_matrices
:
16435 finish_scroll_bars
:
16437 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
16439 /* Set the thumb's position and size. */
16440 set_vertical_scroll_bar (w
);
16442 /* Note that we actually used the scroll bar attached to this
16443 window, so it shouldn't be deleted at the end of redisplay. */
16444 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
16445 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
16448 /* Restore current_buffer and value of point in it. The window
16449 update may have changed the buffer, so first make sure `opoint'
16450 is still valid (Bug#6177). */
16451 if (CHARPOS (opoint
) < BEGV
)
16452 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
16453 else if (CHARPOS (opoint
) > ZV
)
16454 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
16456 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
16458 set_buffer_internal_1 (old
);
16459 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
16460 shorter. This can be caused by log truncation in *Messages*. */
16461 if (CHARPOS (lpoint
) <= ZV
)
16462 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
16464 unbind_to (count
, Qnil
);
16468 /* Build the complete desired matrix of WINDOW with a window start
16469 buffer position POS.
16471 Value is 1 if successful. It is zero if fonts were loaded during
16472 redisplay which makes re-adjusting glyph matrices necessary, and -1
16473 if point would appear in the scroll margins.
16474 (We check the former only if TRY_WINDOW_IGNORE_FONTS_CHANGE is
16475 unset in FLAGS, and the latter only if TRY_WINDOW_CHECK_MARGINS is
16479 try_window (Lisp_Object window
, struct text_pos pos
, int flags
)
16481 struct window
*w
= XWINDOW (window
);
16483 struct glyph_row
*last_text_row
= NULL
;
16484 struct frame
*f
= XFRAME (w
->frame
);
16485 int frame_line_height
= default_line_pixel_height (w
);
16487 /* Make POS the new window start. */
16488 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
16490 /* Mark cursor position as unknown. No overlay arrow seen. */
16491 w
->cursor
.vpos
= -1;
16492 overlay_arrow_seen
= 0;
16494 /* Initialize iterator and info to start at POS. */
16495 start_display (&it
, w
, pos
);
16497 /* Display all lines of W. */
16498 while (it
.current_y
< it
.last_visible_y
)
16500 if (display_line (&it
))
16501 last_text_row
= it
.glyph_row
- 1;
16502 if (f
->fonts_changed
&& !(flags
& TRY_WINDOW_IGNORE_FONTS_CHANGE
))
16506 /* Don't let the cursor end in the scroll margins. */
16507 if ((flags
& TRY_WINDOW_CHECK_MARGINS
)
16508 && !MINI_WINDOW_P (w
))
16510 int this_scroll_margin
;
16511 int window_total_lines
16512 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
16514 if (scroll_margin
> 0)
16516 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4);
16517 this_scroll_margin
*= frame_line_height
;
16520 this_scroll_margin
= 0;
16522 if ((w
->cursor
.y
>= 0 /* not vscrolled */
16523 && w
->cursor
.y
< this_scroll_margin
16524 && CHARPOS (pos
) > BEGV
16525 && IT_CHARPOS (it
) < ZV
)
16526 /* rms: considering make_cursor_line_fully_visible_p here
16527 seems to give wrong results. We don't want to recenter
16528 when the last line is partly visible, we want to allow
16529 that case to be handled in the usual way. */
16530 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
16532 w
->cursor
.vpos
= -1;
16533 clear_glyph_matrix (w
->desired_matrix
);
16538 /* If bottom moved off end of frame, change mode line percentage. */
16539 if (w
->window_end_pos
<= 0 && Z
!= IT_CHARPOS (it
))
16540 w
->update_mode_line
= 1;
16542 /* Set window_end_pos to the offset of the last character displayed
16543 on the window from the end of current_buffer. Set
16544 window_end_vpos to its row number. */
16547 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
16548 adjust_window_ends (w
, last_text_row
, 0);
16550 (MATRIX_ROW_DISPLAYS_TEXT_P (MATRIX_ROW (w
->desired_matrix
,
16551 w
->window_end_vpos
)));
16555 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16556 w
->window_end_pos
= Z
- ZV
;
16557 w
->window_end_vpos
= 0;
16560 /* But that is not valid info until redisplay finishes. */
16561 w
->window_end_valid
= 0;
16567 /************************************************************************
16568 Window redisplay reusing current matrix when buffer has not changed
16569 ************************************************************************/
16571 /* Try redisplay of window W showing an unchanged buffer with a
16572 different window start than the last time it was displayed by
16573 reusing its current matrix. Value is non-zero if successful.
16574 W->start is the new window start. */
16577 try_window_reusing_current_matrix (struct window
*w
)
16579 struct frame
*f
= XFRAME (w
->frame
);
16580 struct glyph_row
*bottom_row
;
16583 struct text_pos start
, new_start
;
16584 int nrows_scrolled
, i
;
16585 struct glyph_row
*last_text_row
;
16586 struct glyph_row
*last_reused_text_row
;
16587 struct glyph_row
*start_row
;
16588 int start_vpos
, min_y
, max_y
;
16591 if (inhibit_try_window_reusing
)
16595 if (/* This function doesn't handle terminal frames. */
16596 !FRAME_WINDOW_P (f
)
16597 /* Don't try to reuse the display if windows have been split
16599 || windows_or_buffers_changed
16600 || f
->cursor_type_changed
)
16603 /* Can't do this if showing trailing whitespace. */
16604 if (!NILP (Vshow_trailing_whitespace
))
16607 /* If top-line visibility has changed, give up. */
16608 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16609 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
16612 /* Give up if old or new display is scrolled vertically. We could
16613 make this function handle this, but right now it doesn't. */
16614 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16615 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
16618 /* The variable new_start now holds the new window start. The old
16619 start `start' can be determined from the current matrix. */
16620 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
16621 start
= start_row
->minpos
;
16622 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16624 /* Clear the desired matrix for the display below. */
16625 clear_glyph_matrix (w
->desired_matrix
);
16627 if (CHARPOS (new_start
) <= CHARPOS (start
))
16629 /* Don't use this method if the display starts with an ellipsis
16630 displayed for invisible text. It's not easy to handle that case
16631 below, and it's certainly not worth the effort since this is
16632 not a frequent case. */
16633 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
16636 IF_DEBUG (debug_method_add (w
, "twu1"));
16638 /* Display up to a row that can be reused. The variable
16639 last_text_row is set to the last row displayed that displays
16640 text. Note that it.vpos == 0 if or if not there is a
16641 header-line; it's not the same as the MATRIX_ROW_VPOS! */
16642 start_display (&it
, w
, new_start
);
16643 w
->cursor
.vpos
= -1;
16644 last_text_row
= last_reused_text_row
= NULL
;
16646 while (it
.current_y
< it
.last_visible_y
&& !f
->fonts_changed
)
16648 /* If we have reached into the characters in the START row,
16649 that means the line boundaries have changed. So we
16650 can't start copying with the row START. Maybe it will
16651 work to start copying with the following row. */
16652 while (IT_CHARPOS (it
) > CHARPOS (start
))
16654 /* Advance to the next row as the "start". */
16656 start
= start_row
->minpos
;
16657 /* If there are no more rows to try, or just one, give up. */
16658 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
16659 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
16660 || CHARPOS (start
) == ZV
)
16662 clear_glyph_matrix (w
->desired_matrix
);
16666 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16668 /* If we have reached alignment, we can copy the rest of the
16670 if (IT_CHARPOS (it
) == CHARPOS (start
)
16671 /* Don't accept "alignment" inside a display vector,
16672 since start_row could have started in the middle of
16673 that same display vector (thus their character
16674 positions match), and we have no way of telling if
16675 that is the case. */
16676 && it
.current
.dpvec_index
< 0)
16679 if (display_line (&it
))
16680 last_text_row
= it
.glyph_row
- 1;
16684 /* A value of current_y < last_visible_y means that we stopped
16685 at the previous window start, which in turn means that we
16686 have at least one reusable row. */
16687 if (it
.current_y
< it
.last_visible_y
)
16689 struct glyph_row
*row
;
16691 /* IT.vpos always starts from 0; it counts text lines. */
16692 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
16694 /* Find PT if not already found in the lines displayed. */
16695 if (w
->cursor
.vpos
< 0)
16697 int dy
= it
.current_y
- start_row
->y
;
16699 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16700 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
16702 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
16703 dy
, nrows_scrolled
);
16706 clear_glyph_matrix (w
->desired_matrix
);
16711 /* Scroll the display. Do it before the current matrix is
16712 changed. The problem here is that update has not yet
16713 run, i.e. part of the current matrix is not up to date.
16714 scroll_run_hook will clear the cursor, and use the
16715 current matrix to get the height of the row the cursor is
16717 run
.current_y
= start_row
->y
;
16718 run
.desired_y
= it
.current_y
;
16719 run
.height
= it
.last_visible_y
- it
.current_y
;
16721 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
16724 FRAME_RIF (f
)->update_window_begin_hook (w
);
16725 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16726 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16727 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16731 /* Shift current matrix down by nrows_scrolled lines. */
16732 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16733 rotate_matrix (w
->current_matrix
,
16735 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16738 /* Disable lines that must be updated. */
16739 for (i
= 0; i
< nrows_scrolled
; ++i
)
16740 (start_row
+ i
)->enabled_p
= 0;
16742 /* Re-compute Y positions. */
16743 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16744 max_y
= it
.last_visible_y
;
16745 for (row
= start_row
+ nrows_scrolled
;
16749 row
->y
= it
.current_y
;
16750 row
->visible_height
= row
->height
;
16752 if (row
->y
< min_y
)
16753 row
->visible_height
-= min_y
- row
->y
;
16754 if (row
->y
+ row
->height
> max_y
)
16755 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16756 if (row
->fringe_bitmap_periodic_p
)
16757 row
->redraw_fringe_bitmaps_p
= 1;
16759 it
.current_y
+= row
->height
;
16761 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16762 last_reused_text_row
= row
;
16763 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
16767 /* Disable lines in the current matrix which are now
16768 below the window. */
16769 for (++row
; row
< bottom_row
; ++row
)
16770 row
->enabled_p
= row
->mode_line_p
= 0;
16773 /* Update window_end_pos etc.; last_reused_text_row is the last
16774 reused row from the current matrix containing text, if any.
16775 The value of last_text_row is the last displayed line
16776 containing text. */
16777 if (last_reused_text_row
)
16778 adjust_window_ends (w
, last_reused_text_row
, 1);
16779 else if (last_text_row
)
16780 adjust_window_ends (w
, last_text_row
, 0);
16783 /* This window must be completely empty. */
16784 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16785 w
->window_end_pos
= Z
- ZV
;
16786 w
->window_end_vpos
= 0;
16788 w
->window_end_valid
= 0;
16790 /* Update hint: don't try scrolling again in update_window. */
16791 w
->desired_matrix
->no_scrolling_p
= 1;
16794 debug_method_add (w
, "try_window_reusing_current_matrix 1");
16798 else if (CHARPOS (new_start
) > CHARPOS (start
))
16800 struct glyph_row
*pt_row
, *row
;
16801 struct glyph_row
*first_reusable_row
;
16802 struct glyph_row
*first_row_to_display
;
16804 int yb
= window_text_bottom_y (w
);
16806 /* Find the row starting at new_start, if there is one. Don't
16807 reuse a partially visible line at the end. */
16808 first_reusable_row
= start_row
;
16809 while (first_reusable_row
->enabled_p
16810 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
16811 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16812 < CHARPOS (new_start
)))
16813 ++first_reusable_row
;
16815 /* Give up if there is no row to reuse. */
16816 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
16817 || !first_reusable_row
->enabled_p
16818 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16819 != CHARPOS (new_start
)))
16822 /* We can reuse fully visible rows beginning with
16823 first_reusable_row to the end of the window. Set
16824 first_row_to_display to the first row that cannot be reused.
16825 Set pt_row to the row containing point, if there is any. */
16827 for (first_row_to_display
= first_reusable_row
;
16828 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
16829 ++first_row_to_display
)
16831 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
16832 && (PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16833 || (PT
== MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16834 && first_row_to_display
->ends_at_zv_p
16835 && pt_row
== NULL
)))
16836 pt_row
= first_row_to_display
;
16839 /* Start displaying at the start of first_row_to_display. */
16840 eassert (first_row_to_display
->y
< yb
);
16841 init_to_row_start (&it
, w
, first_row_to_display
);
16843 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
16845 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
16847 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
16848 + WINDOW_HEADER_LINE_HEIGHT (w
));
16850 /* Display lines beginning with first_row_to_display in the
16851 desired matrix. Set last_text_row to the last row displayed
16852 that displays text. */
16853 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
16854 if (pt_row
== NULL
)
16855 w
->cursor
.vpos
= -1;
16856 last_text_row
= NULL
;
16857 while (it
.current_y
< it
.last_visible_y
&& !f
->fonts_changed
)
16858 if (display_line (&it
))
16859 last_text_row
= it
.glyph_row
- 1;
16861 /* If point is in a reused row, adjust y and vpos of the cursor
16865 w
->cursor
.vpos
-= nrows_scrolled
;
16866 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
16869 /* Give up if point isn't in a row displayed or reused. (This
16870 also handles the case where w->cursor.vpos < nrows_scrolled
16871 after the calls to display_line, which can happen with scroll
16872 margins. See bug#1295.) */
16873 if (w
->cursor
.vpos
< 0)
16875 clear_glyph_matrix (w
->desired_matrix
);
16879 /* Scroll the display. */
16880 run
.current_y
= first_reusable_row
->y
;
16881 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16882 run
.height
= it
.last_visible_y
- run
.current_y
;
16883 dy
= run
.current_y
- run
.desired_y
;
16888 FRAME_RIF (f
)->update_window_begin_hook (w
);
16889 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16890 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16891 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16895 /* Adjust Y positions of reused rows. */
16896 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16897 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16898 max_y
= it
.last_visible_y
;
16899 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
16902 row
->visible_height
= row
->height
;
16903 if (row
->y
< min_y
)
16904 row
->visible_height
-= min_y
- row
->y
;
16905 if (row
->y
+ row
->height
> max_y
)
16906 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16907 if (row
->fringe_bitmap_periodic_p
)
16908 row
->redraw_fringe_bitmaps_p
= 1;
16911 /* Scroll the current matrix. */
16912 eassert (nrows_scrolled
> 0);
16913 rotate_matrix (w
->current_matrix
,
16915 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16918 /* Disable rows not reused. */
16919 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
16920 row
->enabled_p
= 0;
16922 /* Point may have moved to a different line, so we cannot assume that
16923 the previous cursor position is valid; locate the correct row. */
16926 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
16928 && PT
>= MATRIX_ROW_END_CHARPOS (row
)
16929 && !row
->ends_at_zv_p
;
16933 w
->cursor
.y
= row
->y
;
16935 if (row
< bottom_row
)
16937 /* Can't simply scan the row for point with
16938 bidi-reordered glyph rows. Let set_cursor_from_row
16939 figure out where to put the cursor, and if it fails,
16941 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
16943 if (!set_cursor_from_row (w
, row
, w
->current_matrix
,
16946 clear_glyph_matrix (w
->desired_matrix
);
16952 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
16953 struct glyph
*end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16956 && (!BUFFERP (glyph
->object
)
16957 || glyph
->charpos
< PT
);
16961 w
->cursor
.x
+= glyph
->pixel_width
;
16967 /* Adjust window end. A null value of last_text_row means that
16968 the window end is in reused rows which in turn means that
16969 only its vpos can have changed. */
16971 adjust_window_ends (w
, last_text_row
, 0);
16973 w
->window_end_vpos
-= nrows_scrolled
;
16975 w
->window_end_valid
= 0;
16976 w
->desired_matrix
->no_scrolling_p
= 1;
16979 debug_method_add (w
, "try_window_reusing_current_matrix 2");
16989 /************************************************************************
16990 Window redisplay reusing current matrix when buffer has changed
16991 ************************************************************************/
16993 static struct glyph_row
*find_last_unchanged_at_beg_row (struct window
*);
16994 static struct glyph_row
*find_first_unchanged_at_end_row (struct window
*,
16995 ptrdiff_t *, ptrdiff_t *);
16996 static struct glyph_row
*
16997 find_last_row_displaying_text (struct glyph_matrix
*, struct it
*,
16998 struct glyph_row
*);
17001 /* Return the last row in MATRIX displaying text. If row START is
17002 non-null, start searching with that row. IT gives the dimensions
17003 of the display. Value is null if matrix is empty; otherwise it is
17004 a pointer to the row found. */
17006 static struct glyph_row
*
17007 find_last_row_displaying_text (struct glyph_matrix
*matrix
, struct it
*it
,
17008 struct glyph_row
*start
)
17010 struct glyph_row
*row
, *row_found
;
17012 /* Set row_found to the last row in IT->w's current matrix
17013 displaying text. The loop looks funny but think of partially
17016 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
17017 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
17019 eassert (row
->enabled_p
);
17021 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
17030 /* Return the last row in the current matrix of W that is not affected
17031 by changes at the start of current_buffer that occurred since W's
17032 current matrix was built. Value is null if no such row exists.
17034 BEG_UNCHANGED us the number of characters unchanged at the start of
17035 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
17036 first changed character in current_buffer. Characters at positions <
17037 BEG + BEG_UNCHANGED are at the same buffer positions as they were
17038 when the current matrix was built. */
17040 static struct glyph_row
*
17041 find_last_unchanged_at_beg_row (struct window
*w
)
17043 ptrdiff_t first_changed_pos
= BEG
+ BEG_UNCHANGED
;
17044 struct glyph_row
*row
;
17045 struct glyph_row
*row_found
= NULL
;
17046 int yb
= window_text_bottom_y (w
);
17048 /* Find the last row displaying unchanged text. */
17049 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
17050 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
17051 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
17054 if (/* If row ends before first_changed_pos, it is unchanged,
17055 except in some case. */
17056 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
17057 /* When row ends in ZV and we write at ZV it is not
17059 && !row
->ends_at_zv_p
17060 /* When first_changed_pos is the end of a continued line,
17061 row is not unchanged because it may be no longer
17063 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
17064 && (row
->continued_p
17065 || row
->exact_window_width_line_p
))
17066 /* If ROW->end is beyond ZV, then ROW->end is outdated and
17067 needs to be recomputed, so don't consider this row as
17068 unchanged. This happens when the last line was
17069 bidi-reordered and was killed immediately before this
17070 redisplay cycle. In that case, ROW->end stores the
17071 buffer position of the first visual-order character of
17072 the killed text, which is now beyond ZV. */
17073 && CHARPOS (row
->end
.pos
) <= ZV
)
17076 /* Stop if last visible row. */
17077 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
17085 /* Find the first glyph row in the current matrix of W that is not
17086 affected by changes at the end of current_buffer since the
17087 time W's current matrix was built.
17089 Return in *DELTA the number of chars by which buffer positions in
17090 unchanged text at the end of current_buffer must be adjusted.
17092 Return in *DELTA_BYTES the corresponding number of bytes.
17094 Value is null if no such row exists, i.e. all rows are affected by
17097 static struct glyph_row
*
17098 find_first_unchanged_at_end_row (struct window
*w
,
17099 ptrdiff_t *delta
, ptrdiff_t *delta_bytes
)
17101 struct glyph_row
*row
;
17102 struct glyph_row
*row_found
= NULL
;
17104 *delta
= *delta_bytes
= 0;
17106 /* Display must not have been paused, otherwise the current matrix
17107 is not up to date. */
17108 eassert (w
->window_end_valid
);
17110 /* A value of window_end_pos >= END_UNCHANGED means that the window
17111 end is in the range of changed text. If so, there is no
17112 unchanged row at the end of W's current matrix. */
17113 if (w
->window_end_pos
>= END_UNCHANGED
)
17116 /* Set row to the last row in W's current matrix displaying text. */
17117 row
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
17119 /* If matrix is entirely empty, no unchanged row exists. */
17120 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
17122 /* The value of row is the last glyph row in the matrix having a
17123 meaningful buffer position in it. The end position of row
17124 corresponds to window_end_pos. This allows us to translate
17125 buffer positions in the current matrix to current buffer
17126 positions for characters not in changed text. */
17128 MATRIX_ROW_END_CHARPOS (row
) + w
->window_end_pos
;
17129 ptrdiff_t Z_BYTE_old
=
17130 MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
17131 ptrdiff_t last_unchanged_pos
, last_unchanged_pos_old
;
17132 struct glyph_row
*first_text_row
17133 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
17135 *delta
= Z
- Z_old
;
17136 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
17138 /* Set last_unchanged_pos to the buffer position of the last
17139 character in the buffer that has not been changed. Z is the
17140 index + 1 of the last character in current_buffer, i.e. by
17141 subtracting END_UNCHANGED we get the index of the last
17142 unchanged character, and we have to add BEG to get its buffer
17144 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
17145 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
17147 /* Search backward from ROW for a row displaying a line that
17148 starts at a minimum position >= last_unchanged_pos_old. */
17149 for (; row
> first_text_row
; --row
)
17151 /* This used to abort, but it can happen.
17152 It is ok to just stop the search instead here. KFS. */
17153 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
17156 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
17161 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
17167 /* Make sure that glyph rows in the current matrix of window W
17168 reference the same glyph memory as corresponding rows in the
17169 frame's frame matrix. This function is called after scrolling W's
17170 current matrix on a terminal frame in try_window_id and
17171 try_window_reusing_current_matrix. */
17174 sync_frame_with_window_matrix_rows (struct window
*w
)
17176 struct frame
*f
= XFRAME (w
->frame
);
17177 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
17179 /* Preconditions: W must be a leaf window and full-width. Its frame
17180 must have a frame matrix. */
17181 eassert (BUFFERP (w
->contents
));
17182 eassert (WINDOW_FULL_WIDTH_P (w
));
17183 eassert (!FRAME_WINDOW_P (f
));
17185 /* If W is a full-width window, glyph pointers in W's current matrix
17186 have, by definition, to be the same as glyph pointers in the
17187 corresponding frame matrix. Note that frame matrices have no
17188 marginal areas (see build_frame_matrix). */
17189 window_row
= w
->current_matrix
->rows
;
17190 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
17191 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
17192 while (window_row
< window_row_end
)
17194 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
17195 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
17197 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
17198 frame_row
->glyphs
[TEXT_AREA
] = start
;
17199 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
17200 frame_row
->glyphs
[LAST_AREA
] = end
;
17202 /* Disable frame rows whose corresponding window rows have
17203 been disabled in try_window_id. */
17204 if (!window_row
->enabled_p
)
17205 frame_row
->enabled_p
= 0;
17207 ++window_row
, ++frame_row
;
17212 /* Find the glyph row in window W containing CHARPOS. Consider all
17213 rows between START and END (not inclusive). END null means search
17214 all rows to the end of the display area of W. Value is the row
17215 containing CHARPOS or null. */
17218 row_containing_pos (struct window
*w
, ptrdiff_t charpos
,
17219 struct glyph_row
*start
, struct glyph_row
*end
, int dy
)
17221 struct glyph_row
*row
= start
;
17222 struct glyph_row
*best_row
= NULL
;
17223 ptrdiff_t mindif
= BUF_ZV (XBUFFER (w
->contents
)) + 1;
17226 /* If we happen to start on a header-line, skip that. */
17227 if (row
->mode_line_p
)
17230 if ((end
&& row
>= end
) || !row
->enabled_p
)
17233 last_y
= window_text_bottom_y (w
) - dy
;
17237 /* Give up if we have gone too far. */
17238 if (end
&& row
>= end
)
17240 /* This formerly returned if they were equal.
17241 I think that both quantities are of a "last plus one" type;
17242 if so, when they are equal, the row is within the screen. -- rms. */
17243 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
17246 /* If it is in this row, return this row. */
17247 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
17248 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
17249 /* The end position of a row equals the start
17250 position of the next row. If CHARPOS is there, we
17251 would rather consider it displayed in the next
17252 line, except when this line ends in ZV. */
17253 && !row_for_charpos_p (row
, charpos
)))
17254 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
17258 if (NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
17259 || (!best_row
&& !row
->continued_p
))
17261 /* In bidi-reordered rows, there could be several rows whose
17262 edges surround CHARPOS, all of these rows belonging to
17263 the same continued line. We need to find the row which
17264 fits CHARPOS the best. */
17265 for (g
= row
->glyphs
[TEXT_AREA
];
17266 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
17269 if (!STRINGP (g
->object
))
17271 if (g
->charpos
> 0 && eabs (g
->charpos
- charpos
) < mindif
)
17273 mindif
= eabs (g
->charpos
- charpos
);
17275 /* Exact match always wins. */
17282 else if (best_row
&& !row
->continued_p
)
17289 /* Try to redisplay window W by reusing its existing display. W's
17290 current matrix must be up to date when this function is called,
17291 i.e. window_end_valid must be nonzero.
17295 1 if display has been updated
17296 0 if otherwise unsuccessful
17297 -1 if redisplay with same window start is known not to succeed
17299 The following steps are performed:
17301 1. Find the last row in the current matrix of W that is not
17302 affected by changes at the start of current_buffer. If no such row
17305 2. Find the first row in W's current matrix that is not affected by
17306 changes at the end of current_buffer. Maybe there is no such row.
17308 3. Display lines beginning with the row + 1 found in step 1 to the
17309 row found in step 2 or, if step 2 didn't find a row, to the end of
17312 4. If cursor is not known to appear on the window, give up.
17314 5. If display stopped at the row found in step 2, scroll the
17315 display and current matrix as needed.
17317 6. Maybe display some lines at the end of W, if we must. This can
17318 happen under various circumstances, like a partially visible line
17319 becoming fully visible, or because newly displayed lines are displayed
17320 in smaller font sizes.
17322 7. Update W's window end information. */
17325 try_window_id (struct window
*w
)
17327 struct frame
*f
= XFRAME (w
->frame
);
17328 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
17329 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
17330 struct glyph_row
*last_unchanged_at_beg_row
;
17331 struct glyph_row
*first_unchanged_at_end_row
;
17332 struct glyph_row
*row
;
17333 struct glyph_row
*bottom_row
;
17336 ptrdiff_t delta
= 0, delta_bytes
= 0, stop_pos
;
17338 struct text_pos start_pos
;
17340 int first_unchanged_at_end_vpos
= 0;
17341 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
17342 struct text_pos start
;
17343 ptrdiff_t first_changed_charpos
, last_changed_charpos
;
17346 if (inhibit_try_window_id
)
17350 /* This is handy for debugging. */
17352 #define GIVE_UP(X) \
17354 fprintf (stderr, "try_window_id give up %d\n", (X)); \
17358 #define GIVE_UP(X) return 0
17361 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
17363 /* Don't use this for mini-windows because these can show
17364 messages and mini-buffers, and we don't handle that here. */
17365 if (MINI_WINDOW_P (w
))
17368 /* This flag is used to prevent redisplay optimizations. */
17369 if (windows_or_buffers_changed
|| f
->cursor_type_changed
)
17372 /* Verify that narrowing has not changed.
17373 Also verify that we were not told to prevent redisplay optimizations.
17374 It would be nice to further
17375 reduce the number of cases where this prevents try_window_id. */
17376 if (current_buffer
->clip_changed
17377 || current_buffer
->prevent_redisplay_optimizations_p
)
17380 /* Window must either use window-based redisplay or be full width. */
17381 if (!FRAME_WINDOW_P (f
)
17382 && (!FRAME_LINE_INS_DEL_OK (f
)
17383 || !WINDOW_FULL_WIDTH_P (w
)))
17386 /* Give up if point is known NOT to appear in W. */
17387 if (PT
< CHARPOS (start
))
17390 /* Another way to prevent redisplay optimizations. */
17391 if (w
->last_modified
== 0)
17394 /* Verify that window is not hscrolled. */
17395 if (w
->hscroll
!= 0)
17398 /* Verify that display wasn't paused. */
17399 if (!w
->window_end_valid
)
17402 /* Likewise if highlighting trailing whitespace. */
17403 if (!NILP (Vshow_trailing_whitespace
))
17406 /* Can't use this if overlay arrow position and/or string have
17408 if (overlay_arrows_changed_p ())
17411 /* When word-wrap is on, adding a space to the first word of a
17412 wrapped line can change the wrap position, altering the line
17413 above it. It might be worthwhile to handle this more
17414 intelligently, but for now just redisplay from scratch. */
17415 if (!NILP (BVAR (XBUFFER (w
->contents
), word_wrap
)))
17418 /* Under bidi reordering, adding or deleting a character in the
17419 beginning of a paragraph, before the first strong directional
17420 character, can change the base direction of the paragraph (unless
17421 the buffer specifies a fixed paragraph direction), which will
17422 require to redisplay the whole paragraph. It might be worthwhile
17423 to find the paragraph limits and widen the range of redisplayed
17424 lines to that, but for now just give up this optimization and
17425 redisplay from scratch. */
17426 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
17427 && NILP (BVAR (XBUFFER (w
->contents
), bidi_paragraph_direction
)))
17430 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
17431 only if buffer has really changed. The reason is that the gap is
17432 initially at Z for freshly visited files. The code below would
17433 set end_unchanged to 0 in that case. */
17434 if (MODIFF
> SAVE_MODIFF
17435 /* This seems to happen sometimes after saving a buffer. */
17436 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
17438 if (GPT
- BEG
< BEG_UNCHANGED
)
17439 BEG_UNCHANGED
= GPT
- BEG
;
17440 if (Z
- GPT
< END_UNCHANGED
)
17441 END_UNCHANGED
= Z
- GPT
;
17444 /* The position of the first and last character that has been changed. */
17445 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
17446 last_changed_charpos
= Z
- END_UNCHANGED
;
17448 /* If window starts after a line end, and the last change is in
17449 front of that newline, then changes don't affect the display.
17450 This case happens with stealth-fontification. Note that although
17451 the display is unchanged, glyph positions in the matrix have to
17452 be adjusted, of course. */
17453 row
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
17454 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
17455 && ((last_changed_charpos
< CHARPOS (start
)
17456 && CHARPOS (start
) == BEGV
)
17457 || (last_changed_charpos
< CHARPOS (start
) - 1
17458 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
17460 ptrdiff_t Z_old
, Z_delta
, Z_BYTE_old
, Z_delta_bytes
;
17461 struct glyph_row
*r0
;
17463 /* Compute how many chars/bytes have been added to or removed
17464 from the buffer. */
17465 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + w
->window_end_pos
;
17466 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
17467 Z_delta
= Z
- Z_old
;
17468 Z_delta_bytes
= Z_BYTE
- Z_BYTE_old
;
17470 /* Give up if PT is not in the window. Note that it already has
17471 been checked at the start of try_window_id that PT is not in
17472 front of the window start. */
17473 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + Z_delta
)
17476 /* If window start is unchanged, we can reuse the whole matrix
17477 as is, after adjusting glyph positions. No need to compute
17478 the window end again, since its offset from Z hasn't changed. */
17479 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17480 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + Z_delta
17481 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + Z_delta_bytes
17482 /* PT must not be in a partially visible line. */
17483 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + Z_delta
17484 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17486 /* Adjust positions in the glyph matrix. */
17487 if (Z_delta
|| Z_delta_bytes
)
17489 struct glyph_row
*r1
17490 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17491 increment_matrix_positions (w
->current_matrix
,
17492 MATRIX_ROW_VPOS (r0
, current_matrix
),
17493 MATRIX_ROW_VPOS (r1
, current_matrix
),
17494 Z_delta
, Z_delta_bytes
);
17497 /* Set the cursor. */
17498 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17500 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17505 /* Handle the case that changes are all below what is displayed in
17506 the window, and that PT is in the window. This shortcut cannot
17507 be taken if ZV is visible in the window, and text has been added
17508 there that is visible in the window. */
17509 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
17510 /* ZV is not visible in the window, or there are no
17511 changes at ZV, actually. */
17512 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
17513 || first_changed_charpos
== last_changed_charpos
))
17515 struct glyph_row
*r0
;
17517 /* Give up if PT is not in the window. Note that it already has
17518 been checked at the start of try_window_id that PT is not in
17519 front of the window start. */
17520 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
17523 /* If window start is unchanged, we can reuse the whole matrix
17524 as is, without changing glyph positions since no text has
17525 been added/removed in front of the window end. */
17526 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17527 if (TEXT_POS_EQUAL_P (start
, r0
->minpos
)
17528 /* PT must not be in a partially visible line. */
17529 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
17530 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17532 /* We have to compute the window end anew since text
17533 could have been added/removed after it. */
17534 w
->window_end_pos
= Z
- MATRIX_ROW_END_CHARPOS (row
);
17535 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17537 /* Set the cursor. */
17538 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17540 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17545 /* Give up if window start is in the changed area.
17547 The condition used to read
17549 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
17551 but why that was tested escapes me at the moment. */
17552 if (CHARPOS (start
) >= first_changed_charpos
17553 && CHARPOS (start
) <= last_changed_charpos
)
17556 /* Check that window start agrees with the start of the first glyph
17557 row in its current matrix. Check this after we know the window
17558 start is not in changed text, otherwise positions would not be
17560 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17561 if (!TEXT_POS_EQUAL_P (start
, row
->minpos
))
17564 /* Give up if the window ends in strings. Overlay strings
17565 at the end are difficult to handle, so don't try. */
17566 row
= MATRIX_ROW (current_matrix
, w
->window_end_vpos
);
17567 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
17570 /* Compute the position at which we have to start displaying new
17571 lines. Some of the lines at the top of the window might be
17572 reusable because they are not displaying changed text. Find the
17573 last row in W's current matrix not affected by changes at the
17574 start of current_buffer. Value is null if changes start in the
17575 first line of window. */
17576 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
17577 if (last_unchanged_at_beg_row
)
17579 /* Avoid starting to display in the middle of a character, a TAB
17580 for instance. This is easier than to set up the iterator
17581 exactly, and it's not a frequent case, so the additional
17582 effort wouldn't really pay off. */
17583 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
17584 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
17585 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
17586 --last_unchanged_at_beg_row
;
17588 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
17591 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
17593 start_pos
= it
.current
.pos
;
17595 /* Start displaying new lines in the desired matrix at the same
17596 vpos we would use in the current matrix, i.e. below
17597 last_unchanged_at_beg_row. */
17598 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
17600 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17601 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
17603 eassert (it
.hpos
== 0 && it
.current_x
== 0);
17607 /* There are no reusable lines at the start of the window.
17608 Start displaying in the first text line. */
17609 start_display (&it
, w
, start
);
17610 it
.vpos
= it
.first_vpos
;
17611 start_pos
= it
.current
.pos
;
17614 /* Find the first row that is not affected by changes at the end of
17615 the buffer. Value will be null if there is no unchanged row, in
17616 which case we must redisplay to the end of the window. delta
17617 will be set to the value by which buffer positions beginning with
17618 first_unchanged_at_end_row have to be adjusted due to text
17620 first_unchanged_at_end_row
17621 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
17622 IF_DEBUG (debug_delta
= delta
);
17623 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
17625 /* Set stop_pos to the buffer position up to which we will have to
17626 display new lines. If first_unchanged_at_end_row != NULL, this
17627 is the buffer position of the start of the line displayed in that
17628 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
17629 that we don't stop at a buffer position. */
17631 if (first_unchanged_at_end_row
)
17633 eassert (last_unchanged_at_beg_row
== NULL
17634 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
17636 /* If this is a continuation line, move forward to the next one
17637 that isn't. Changes in lines above affect this line.
17638 Caution: this may move first_unchanged_at_end_row to a row
17639 not displaying text. */
17640 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
17641 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17642 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17643 < it
.last_visible_y
))
17644 ++first_unchanged_at_end_row
;
17646 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17647 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17648 >= it
.last_visible_y
))
17649 first_unchanged_at_end_row
= NULL
;
17652 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
17654 first_unchanged_at_end_vpos
17655 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
17656 eassert (stop_pos
>= Z
- END_UNCHANGED
);
17659 else if (last_unchanged_at_beg_row
== NULL
)
17665 /* Either there is no unchanged row at the end, or the one we have
17666 now displays text. This is a necessary condition for the window
17667 end pos calculation at the end of this function. */
17668 eassert (first_unchanged_at_end_row
== NULL
17669 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
17671 debug_last_unchanged_at_beg_vpos
17672 = (last_unchanged_at_beg_row
17673 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
17675 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
17677 #endif /* GLYPH_DEBUG */
17680 /* Display new lines. Set last_text_row to the last new line
17681 displayed which has text on it, i.e. might end up as being the
17682 line where the window_end_vpos is. */
17683 w
->cursor
.vpos
= -1;
17684 last_text_row
= NULL
;
17685 overlay_arrow_seen
= 0;
17686 while (it
.current_y
< it
.last_visible_y
17687 && !f
->fonts_changed
17688 && (first_unchanged_at_end_row
== NULL
17689 || IT_CHARPOS (it
) < stop_pos
))
17691 if (display_line (&it
))
17692 last_text_row
= it
.glyph_row
- 1;
17695 if (f
->fonts_changed
)
17699 /* Compute differences in buffer positions, y-positions etc. for
17700 lines reused at the bottom of the window. Compute what we can
17702 if (first_unchanged_at_end_row
17703 /* No lines reused because we displayed everything up to the
17704 bottom of the window. */
17705 && it
.current_y
< it
.last_visible_y
)
17708 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
17710 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
17711 run
.current_y
= first_unchanged_at_end_row
->y
;
17712 run
.desired_y
= run
.current_y
+ dy
;
17713 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
17717 delta
= delta_bytes
= dvpos
= dy
17718 = run
.current_y
= run
.desired_y
= run
.height
= 0;
17719 first_unchanged_at_end_row
= NULL
;
17721 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
17724 /* Find the cursor if not already found. We have to decide whether
17725 PT will appear on this window (it sometimes doesn't, but this is
17726 not a very frequent case.) This decision has to be made before
17727 the current matrix is altered. A value of cursor.vpos < 0 means
17728 that PT is either in one of the lines beginning at
17729 first_unchanged_at_end_row or below the window. Don't care for
17730 lines that might be displayed later at the window end; as
17731 mentioned, this is not a frequent case. */
17732 if (w
->cursor
.vpos
< 0)
17734 /* Cursor in unchanged rows at the top? */
17735 if (PT
< CHARPOS (start_pos
)
17736 && last_unchanged_at_beg_row
)
17738 row
= row_containing_pos (w
, PT
,
17739 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
17740 last_unchanged_at_beg_row
+ 1, 0);
17742 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
17745 /* Start from first_unchanged_at_end_row looking for PT. */
17746 else if (first_unchanged_at_end_row
)
17748 row
= row_containing_pos (w
, PT
- delta
,
17749 first_unchanged_at_end_row
, NULL
, 0);
17751 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
17752 delta_bytes
, dy
, dvpos
);
17755 /* Give up if cursor was not found. */
17756 if (w
->cursor
.vpos
< 0)
17758 clear_glyph_matrix (w
->desired_matrix
);
17763 /* Don't let the cursor end in the scroll margins. */
17765 int this_scroll_margin
, cursor_height
;
17766 int frame_line_height
= default_line_pixel_height (w
);
17767 int window_total_lines
17768 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (it
.f
) / frame_line_height
;
17770 this_scroll_margin
=
17771 max (0, min (scroll_margin
, window_total_lines
/ 4));
17772 this_scroll_margin
*= frame_line_height
;
17773 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
17775 if ((w
->cursor
.y
< this_scroll_margin
17776 && CHARPOS (start
) > BEGV
)
17777 /* Old redisplay didn't take scroll margin into account at the bottom,
17778 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
17779 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
17780 ? cursor_height
+ this_scroll_margin
17781 : 1)) > it
.last_visible_y
)
17783 w
->cursor
.vpos
= -1;
17784 clear_glyph_matrix (w
->desired_matrix
);
17789 /* Scroll the display. Do it before changing the current matrix so
17790 that xterm.c doesn't get confused about where the cursor glyph is
17792 if (dy
&& run
.height
)
17796 if (FRAME_WINDOW_P (f
))
17798 FRAME_RIF (f
)->update_window_begin_hook (w
);
17799 FRAME_RIF (f
)->clear_window_mouse_face (w
);
17800 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
17801 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
17805 /* Terminal frame. In this case, dvpos gives the number of
17806 lines to scroll by; dvpos < 0 means scroll up. */
17808 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
17809 int from
= WINDOW_TOP_EDGE_LINE (w
) + from_vpos
;
17810 int end
= (WINDOW_TOP_EDGE_LINE (w
)
17811 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
17812 + window_internal_height (w
));
17814 #if defined (HAVE_GPM) || defined (MSDOS)
17815 x_clear_window_mouse_face (w
);
17817 /* Perform the operation on the screen. */
17820 /* Scroll last_unchanged_at_beg_row to the end of the
17821 window down dvpos lines. */
17822 set_terminal_window (f
, end
);
17824 /* On dumb terminals delete dvpos lines at the end
17825 before inserting dvpos empty lines. */
17826 if (!FRAME_SCROLL_REGION_OK (f
))
17827 ins_del_lines (f
, end
- dvpos
, -dvpos
);
17829 /* Insert dvpos empty lines in front of
17830 last_unchanged_at_beg_row. */
17831 ins_del_lines (f
, from
, dvpos
);
17833 else if (dvpos
< 0)
17835 /* Scroll up last_unchanged_at_beg_vpos to the end of
17836 the window to last_unchanged_at_beg_vpos - |dvpos|. */
17837 set_terminal_window (f
, end
);
17839 /* Delete dvpos lines in front of
17840 last_unchanged_at_beg_vpos. ins_del_lines will set
17841 the cursor to the given vpos and emit |dvpos| delete
17843 ins_del_lines (f
, from
+ dvpos
, dvpos
);
17845 /* On a dumb terminal insert dvpos empty lines at the
17847 if (!FRAME_SCROLL_REGION_OK (f
))
17848 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
17851 set_terminal_window (f
, 0);
17857 /* Shift reused rows of the current matrix to the right position.
17858 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
17860 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17861 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
17864 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
17865 bottom_vpos
, dvpos
);
17866 clear_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
17869 else if (dvpos
> 0)
17871 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
17872 bottom_vpos
, dvpos
);
17873 clear_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
17874 first_unchanged_at_end_vpos
+ dvpos
);
17877 /* For frame-based redisplay, make sure that current frame and window
17878 matrix are in sync with respect to glyph memory. */
17879 if (!FRAME_WINDOW_P (f
))
17880 sync_frame_with_window_matrix_rows (w
);
17882 /* Adjust buffer positions in reused rows. */
17883 if (delta
|| delta_bytes
)
17884 increment_matrix_positions (current_matrix
,
17885 first_unchanged_at_end_vpos
+ dvpos
,
17886 bottom_vpos
, delta
, delta_bytes
);
17888 /* Adjust Y positions. */
17890 shift_glyph_matrix (w
, current_matrix
,
17891 first_unchanged_at_end_vpos
+ dvpos
,
17894 if (first_unchanged_at_end_row
)
17896 first_unchanged_at_end_row
+= dvpos
;
17897 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
17898 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
17899 first_unchanged_at_end_row
= NULL
;
17902 /* If scrolling up, there may be some lines to display at the end of
17904 last_text_row_at_end
= NULL
;
17907 /* Scrolling up can leave for example a partially visible line
17908 at the end of the window to be redisplayed. */
17909 /* Set last_row to the glyph row in the current matrix where the
17910 window end line is found. It has been moved up or down in
17911 the matrix by dvpos. */
17912 int last_vpos
= w
->window_end_vpos
+ dvpos
;
17913 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
17915 /* If last_row is the window end line, it should display text. */
17916 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_row
));
17918 /* If window end line was partially visible before, begin
17919 displaying at that line. Otherwise begin displaying with the
17920 line following it. */
17921 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
17923 init_to_row_start (&it
, w
, last_row
);
17924 it
.vpos
= last_vpos
;
17925 it
.current_y
= last_row
->y
;
17929 init_to_row_end (&it
, w
, last_row
);
17930 it
.vpos
= 1 + last_vpos
;
17931 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
17935 /* We may start in a continuation line. If so, we have to
17936 get the right continuation_lines_width and current_x. */
17937 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
17938 it
.hpos
= it
.current_x
= 0;
17940 /* Display the rest of the lines at the window end. */
17941 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17942 while (it
.current_y
< it
.last_visible_y
&& !f
->fonts_changed
)
17944 /* Is it always sure that the display agrees with lines in
17945 the current matrix? I don't think so, so we mark rows
17946 displayed invalid in the current matrix by setting their
17947 enabled_p flag to zero. */
17948 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
17949 if (display_line (&it
))
17950 last_text_row_at_end
= it
.glyph_row
- 1;
17954 /* Update window_end_pos and window_end_vpos. */
17955 if (first_unchanged_at_end_row
&& !last_text_row_at_end
)
17957 /* Window end line if one of the preserved rows from the current
17958 matrix. Set row to the last row displaying text in current
17959 matrix starting at first_unchanged_at_end_row, after
17961 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
17962 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
17963 first_unchanged_at_end_row
);
17964 eassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
17965 adjust_window_ends (w
, row
, 1);
17966 eassert (w
->window_end_bytepos
>= 0);
17967 IF_DEBUG (debug_method_add (w
, "A"));
17969 else if (last_text_row_at_end
)
17971 adjust_window_ends (w
, last_text_row_at_end
, 0);
17972 eassert (w
->window_end_bytepos
>= 0);
17973 IF_DEBUG (debug_method_add (w
, "B"));
17975 else if (last_text_row
)
17977 /* We have displayed either to the end of the window or at the
17978 end of the window, i.e. the last row with text is to be found
17979 in the desired matrix. */
17980 adjust_window_ends (w
, last_text_row
, 0);
17981 eassert (w
->window_end_bytepos
>= 0);
17983 else if (first_unchanged_at_end_row
== NULL
17984 && last_text_row
== NULL
17985 && last_text_row_at_end
== NULL
)
17987 /* Displayed to end of window, but no line containing text was
17988 displayed. Lines were deleted at the end of the window. */
17989 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
17990 int vpos
= w
->window_end_vpos
;
17991 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
17992 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
17995 row
== NULL
&& vpos
>= first_vpos
;
17996 --vpos
, --current_row
, --desired_row
)
17998 if (desired_row
->enabled_p
)
18000 if (MATRIX_ROW_DISPLAYS_TEXT_P (desired_row
))
18003 else if (MATRIX_ROW_DISPLAYS_TEXT_P (current_row
))
18007 eassert (row
!= NULL
);
18008 w
->window_end_vpos
= vpos
+ 1;
18009 w
->window_end_pos
= Z
- MATRIX_ROW_END_CHARPOS (row
);
18010 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
18011 eassert (w
->window_end_bytepos
>= 0);
18012 IF_DEBUG (debug_method_add (w
, "C"));
18017 IF_DEBUG (debug_end_pos
= w
->window_end_pos
;
18018 debug_end_vpos
= w
->window_end_vpos
);
18020 /* Record that display has not been completed. */
18021 w
->window_end_valid
= 0;
18022 w
->desired_matrix
->no_scrolling_p
= 1;
18030 /***********************************************************************
18031 More debugging support
18032 ***********************************************************************/
18036 void dump_glyph_row (struct glyph_row
*, int, int) EXTERNALLY_VISIBLE
;
18037 void dump_glyph_matrix (struct glyph_matrix
*, int) EXTERNALLY_VISIBLE
;
18038 void dump_glyph (struct glyph_row
*, struct glyph
*, int) EXTERNALLY_VISIBLE
;
18041 /* Dump the contents of glyph matrix MATRIX on stderr.
18043 GLYPHS 0 means don't show glyph contents.
18044 GLYPHS 1 means show glyphs in short form
18045 GLYPHS > 1 means show glyphs in long form. */
18048 dump_glyph_matrix (struct glyph_matrix
*matrix
, int glyphs
)
18051 for (i
= 0; i
< matrix
->nrows
; ++i
)
18052 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
18056 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
18057 the glyph row and area where the glyph comes from. */
18060 dump_glyph (struct glyph_row
*row
, struct glyph
*glyph
, int area
)
18062 if (glyph
->type
== CHAR_GLYPH
18063 || glyph
->type
== GLYPHLESS_GLYPH
)
18066 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
18067 glyph
- row
->glyphs
[TEXT_AREA
],
18068 (glyph
->type
== CHAR_GLYPH
18072 (BUFFERP (glyph
->object
)
18074 : (STRINGP (glyph
->object
)
18076 : (INTEGERP (glyph
->object
)
18079 glyph
->pixel_width
,
18081 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
18085 glyph
->left_box_line_p
,
18086 glyph
->right_box_line_p
);
18088 else if (glyph
->type
== STRETCH_GLYPH
)
18091 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
18092 glyph
- row
->glyphs
[TEXT_AREA
],
18095 (BUFFERP (glyph
->object
)
18097 : (STRINGP (glyph
->object
)
18099 : (INTEGERP (glyph
->object
)
18102 glyph
->pixel_width
,
18106 glyph
->left_box_line_p
,
18107 glyph
->right_box_line_p
);
18109 else if (glyph
->type
== IMAGE_GLYPH
)
18112 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
18113 glyph
- row
->glyphs
[TEXT_AREA
],
18116 (BUFFERP (glyph
->object
)
18118 : (STRINGP (glyph
->object
)
18120 : (INTEGERP (glyph
->object
)
18123 glyph
->pixel_width
,
18127 glyph
->left_box_line_p
,
18128 glyph
->right_box_line_p
);
18130 else if (glyph
->type
== COMPOSITE_GLYPH
)
18133 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x",
18134 glyph
- row
->glyphs
[TEXT_AREA
],
18137 (BUFFERP (glyph
->object
)
18139 : (STRINGP (glyph
->object
)
18141 : (INTEGERP (glyph
->object
)
18144 glyph
->pixel_width
,
18146 if (glyph
->u
.cmp
.automatic
)
18149 glyph
->slice
.cmp
.from
, glyph
->slice
.cmp
.to
);
18150 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
18152 glyph
->left_box_line_p
,
18153 glyph
->right_box_line_p
);
18158 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
18159 GLYPHS 0 means don't show glyph contents.
18160 GLYPHS 1 means show glyphs in short form
18161 GLYPHS > 1 means show glyphs in long form. */
18164 dump_glyph_row (struct glyph_row
*row
, int vpos
, int glyphs
)
18168 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
18169 fprintf (stderr
, "==============================================================================\n");
18171 fprintf (stderr
, "%3d %9"pI
"d %9"pI
"d %4d %1.1d%1.1d%1.1d%1.1d\
18172 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
18174 MATRIX_ROW_START_CHARPOS (row
),
18175 MATRIX_ROW_END_CHARPOS (row
),
18176 row
->used
[TEXT_AREA
],
18177 row
->contains_overlapping_glyphs_p
,
18179 row
->truncated_on_left_p
,
18180 row
->truncated_on_right_p
,
18182 MATRIX_ROW_CONTINUATION_LINE_P (row
),
18183 MATRIX_ROW_DISPLAYS_TEXT_P (row
),
18186 row
->ends_in_middle_of_char_p
,
18187 row
->starts_in_middle_of_char_p
,
18193 row
->visible_height
,
18196 /* The next 3 lines should align to "Start" in the header. */
18197 fprintf (stderr
, " %9"pD
"d %9"pD
"d\t%5d\n", row
->start
.overlay_string_index
,
18198 row
->end
.overlay_string_index
,
18199 row
->continuation_lines_width
);
18200 fprintf (stderr
, " %9"pI
"d %9"pI
"d\n",
18201 CHARPOS (row
->start
.string_pos
),
18202 CHARPOS (row
->end
.string_pos
));
18203 fprintf (stderr
, " %9d %9d\n", row
->start
.dpvec_index
,
18204 row
->end
.dpvec_index
);
18211 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18213 struct glyph
*glyph
= row
->glyphs
[area
];
18214 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
18216 /* Glyph for a line end in text. */
18217 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
18220 if (glyph
< glyph_end
)
18221 fprintf (stderr
, " Glyph# Type Pos O W Code C Face LR\n");
18223 for (; glyph
< glyph_end
; ++glyph
)
18224 dump_glyph (row
, glyph
, area
);
18227 else if (glyphs
== 1)
18231 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18233 char *s
= alloca (row
->used
[area
] + 4);
18236 for (i
= 0; i
< row
->used
[area
]; ++i
)
18238 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
18239 if (i
== row
->used
[area
] - 1
18240 && area
== TEXT_AREA
18241 && INTEGERP (glyph
->object
)
18242 && glyph
->type
== CHAR_GLYPH
18243 && glyph
->u
.ch
== ' ')
18245 strcpy (&s
[i
], "[\\n]");
18248 else if (glyph
->type
== CHAR_GLYPH
18249 && glyph
->u
.ch
< 0x80
18250 && glyph
->u
.ch
>= ' ')
18251 s
[i
] = glyph
->u
.ch
;
18257 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
18263 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
18264 Sdump_glyph_matrix
, 0, 1, "p",
18265 doc
: /* Dump the current matrix of the selected window to stderr.
18266 Shows contents of glyph row structures. With non-nil
18267 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
18268 glyphs in short form, otherwise show glyphs in long form. */)
18269 (Lisp_Object glyphs
)
18271 struct window
*w
= XWINDOW (selected_window
);
18272 struct buffer
*buffer
= XBUFFER (w
->contents
);
18274 fprintf (stderr
, "PT = %"pI
"d, BEGV = %"pI
"d. ZV = %"pI
"d\n",
18275 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
18276 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
18277 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
18278 fprintf (stderr
, "=============================================\n");
18279 dump_glyph_matrix (w
->current_matrix
,
18280 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 0);
18285 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
18286 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
18289 struct frame
*f
= XFRAME (selected_frame
);
18290 dump_glyph_matrix (f
->current_matrix
, 1);
18295 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
18296 doc
: /* Dump glyph row ROW to stderr.
18297 GLYPH 0 means don't dump glyphs.
18298 GLYPH 1 means dump glyphs in short form.
18299 GLYPH > 1 or omitted means dump glyphs in long form. */)
18300 (Lisp_Object row
, Lisp_Object glyphs
)
18302 struct glyph_matrix
*matrix
;
18305 CHECK_NUMBER (row
);
18306 matrix
= XWINDOW (selected_window
)->current_matrix
;
18308 if (vpos
>= 0 && vpos
< matrix
->nrows
)
18309 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
18311 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18316 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
18317 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
18318 GLYPH 0 means don't dump glyphs.
18319 GLYPH 1 means dump glyphs in short form.
18320 GLYPH > 1 or omitted means dump glyphs in long form.
18322 If there's no tool-bar, or if the tool-bar is not drawn by Emacs,
18324 (Lisp_Object row
, Lisp_Object glyphs
)
18326 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
18327 struct frame
*sf
= SELECTED_FRAME ();
18328 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
18331 CHECK_NUMBER (row
);
18333 if (vpos
>= 0 && vpos
< m
->nrows
)
18334 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
18335 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18341 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
18342 doc
: /* Toggle tracing of redisplay.
18343 With ARG, turn tracing on if and only if ARG is positive. */)
18347 trace_redisplay_p
= !trace_redisplay_p
;
18350 arg
= Fprefix_numeric_value (arg
);
18351 trace_redisplay_p
= XINT (arg
) > 0;
18358 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
18359 doc
: /* Like `format', but print result to stderr.
18360 usage: (trace-to-stderr STRING &rest OBJECTS) */)
18361 (ptrdiff_t nargs
, Lisp_Object
*args
)
18363 Lisp_Object s
= Fformat (nargs
, args
);
18364 fprintf (stderr
, "%s", SDATA (s
));
18368 #endif /* GLYPH_DEBUG */
18372 /***********************************************************************
18373 Building Desired Matrix Rows
18374 ***********************************************************************/
18376 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
18377 Used for non-window-redisplay windows, and for windows w/o left fringe. */
18379 static struct glyph_row
*
18380 get_overlay_arrow_glyph_row (struct window
*w
, Lisp_Object overlay_arrow_string
)
18382 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18383 struct buffer
*buffer
= XBUFFER (w
->contents
);
18384 struct buffer
*old
= current_buffer
;
18385 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
18386 int arrow_len
= SCHARS (overlay_arrow_string
);
18387 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
18388 const unsigned char *p
;
18391 int n_glyphs_before
;
18393 set_buffer_temp (buffer
);
18394 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
18395 it
.glyph_row
->used
[TEXT_AREA
] = 0;
18396 SET_TEXT_POS (it
.position
, 0, 0);
18398 multibyte_p
= !NILP (BVAR (buffer
, enable_multibyte_characters
));
18400 while (p
< arrow_end
)
18402 Lisp_Object face
, ilisp
;
18404 /* Get the next character. */
18406 it
.c
= it
.char_to_display
= string_char_and_length (p
, &it
.len
);
18409 it
.c
= it
.char_to_display
= *p
, it
.len
= 1;
18410 if (! ASCII_CHAR_P (it
.c
))
18411 it
.char_to_display
= BYTE8_TO_CHAR (it
.c
);
18415 /* Get its face. */
18416 ilisp
= make_number (p
- arrow_string
);
18417 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
18418 it
.face_id
= compute_char_face (f
, it
.char_to_display
, face
);
18420 /* Compute its width, get its glyphs. */
18421 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
18422 SET_TEXT_POS (it
.position
, -1, -1);
18423 PRODUCE_GLYPHS (&it
);
18425 /* If this character doesn't fit any more in the line, we have
18426 to remove some glyphs. */
18427 if (it
.current_x
> it
.last_visible_x
)
18429 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
18434 set_buffer_temp (old
);
18435 return it
.glyph_row
;
18439 /* Insert truncation glyphs at the start of IT->glyph_row. Which
18440 glyphs to insert is determined by produce_special_glyphs. */
18443 insert_left_trunc_glyphs (struct it
*it
)
18445 struct it truncate_it
;
18446 struct glyph
*from
, *end
, *to
, *toend
;
18448 eassert (!FRAME_WINDOW_P (it
->f
)
18449 || (!it
->glyph_row
->reversed_p
18450 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0)
18451 || (it
->glyph_row
->reversed_p
18452 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0));
18454 /* Get the truncation glyphs. */
18456 truncate_it
.current_x
= 0;
18457 truncate_it
.face_id
= DEFAULT_FACE_ID
;
18458 truncate_it
.glyph_row
= &scratch_glyph_row
;
18459 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
18460 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
18461 truncate_it
.object
= make_number (0);
18462 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
18464 /* Overwrite glyphs from IT with truncation glyphs. */
18465 if (!it
->glyph_row
->reversed_p
)
18467 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
18469 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18470 end
= from
+ tused
;
18471 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18472 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
18473 if (FRAME_WINDOW_P (it
->f
))
18475 /* On GUI frames, when variable-size fonts are displayed,
18476 the truncation glyphs may need more pixels than the row's
18477 glyphs they overwrite. We overwrite more glyphs to free
18478 enough screen real estate, and enlarge the stretch glyph
18479 on the right (see display_line), if there is one, to
18480 preserve the screen position of the truncation glyphs on
18483 struct glyph
*g
= to
;
18486 /* The first glyph could be partially visible, in which case
18487 it->glyph_row->x will be negative. But we want the left
18488 truncation glyphs to be aligned at the left margin of the
18489 window, so we override the x coordinate at which the row
18491 it
->glyph_row
->x
= 0;
18492 while (g
< toend
&& w
< it
->truncation_pixel_width
)
18494 w
+= g
->pixel_width
;
18497 if (g
- to
- tused
> 0)
18499 memmove (to
+ tused
, g
, (toend
- g
) * sizeof(*g
));
18500 it
->glyph_row
->used
[TEXT_AREA
] -= g
- to
- tused
;
18502 used
= it
->glyph_row
->used
[TEXT_AREA
];
18503 if (it
->glyph_row
->truncated_on_right_p
18504 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0
18505 && it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].type
18508 int extra
= w
- it
->truncation_pixel_width
;
18510 it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].pixel_width
+= extra
;
18517 /* There may be padding glyphs left over. Overwrite them too. */
18518 if (!FRAME_WINDOW_P (it
->f
))
18520 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
18522 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18529 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
18533 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
18535 /* In R2L rows, overwrite the last (rightmost) glyphs, and do
18536 that back to front. */
18537 end
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18538 from
= end
+ truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18539 toend
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18540 to
= toend
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18541 if (FRAME_WINDOW_P (it
->f
))
18544 struct glyph
*g
= to
;
18546 while (g
>= toend
&& w
< it
->truncation_pixel_width
)
18548 w
+= g
->pixel_width
;
18551 if (to
- g
- tused
> 0)
18553 if (it
->glyph_row
->truncated_on_right_p
18554 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0
18555 && it
->glyph_row
->glyphs
[TEXT_AREA
][1].type
== STRETCH_GLYPH
)
18557 int extra
= w
- it
->truncation_pixel_width
;
18559 it
->glyph_row
->glyphs
[TEXT_AREA
][1].pixel_width
+= extra
;
18563 while (from
>= end
&& to
>= toend
)
18565 if (!FRAME_WINDOW_P (it
->f
))
18567 while (to
>= toend
&& CHAR_GLYPH_PADDING_P (*to
))
18570 truncate_it
.glyph_row
->glyphs
[TEXT_AREA
]
18571 + truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18572 while (from
>= end
&& to
>= toend
)
18578 /* Need to free some room before prepending additional
18580 int move_by
= from
- end
+ 1;
18581 struct glyph
*g0
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18582 struct glyph
*g
= g0
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18584 for ( ; g
>= g0
; g
--)
18586 while (from
>= end
)
18588 it
->glyph_row
->used
[TEXT_AREA
] += move_by
;
18593 /* Compute the hash code for ROW. */
18595 row_hash (struct glyph_row
*row
)
18598 unsigned hashval
= 0;
18600 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18601 for (k
= 0; k
< row
->used
[area
]; ++k
)
18602 hashval
= ((((hashval
<< 4) + (hashval
>> 24)) & 0x0fffffff)
18603 + row
->glyphs
[area
][k
].u
.val
18604 + row
->glyphs
[area
][k
].face_id
18605 + row
->glyphs
[area
][k
].padding_p
18606 + (row
->glyphs
[area
][k
].type
<< 2));
18611 /* Compute the pixel height and width of IT->glyph_row.
18613 Most of the time, ascent and height of a display line will be equal
18614 to the max_ascent and max_height values of the display iterator
18615 structure. This is not the case if
18617 1. We hit ZV without displaying anything. In this case, max_ascent
18618 and max_height will be zero.
18620 2. We have some glyphs that don't contribute to the line height.
18621 (The glyph row flag contributes_to_line_height_p is for future
18622 pixmap extensions).
18624 The first case is easily covered by using default values because in
18625 these cases, the line height does not really matter, except that it
18626 must not be zero. */
18629 compute_line_metrics (struct it
*it
)
18631 struct glyph_row
*row
= it
->glyph_row
;
18633 if (FRAME_WINDOW_P (it
->f
))
18635 int i
, min_y
, max_y
;
18637 /* The line may consist of one space only, that was added to
18638 place the cursor on it. If so, the row's height hasn't been
18640 if (row
->height
== 0)
18642 if (it
->max_ascent
+ it
->max_descent
== 0)
18643 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
18644 row
->ascent
= it
->max_ascent
;
18645 row
->height
= it
->max_ascent
+ it
->max_descent
;
18646 row
->phys_ascent
= it
->max_phys_ascent
;
18647 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18648 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18651 /* Compute the width of this line. */
18652 row
->pixel_width
= row
->x
;
18653 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
18654 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
18656 eassert (row
->pixel_width
>= 0);
18657 eassert (row
->ascent
>= 0 && row
->height
> 0);
18659 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
18660 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
18662 /* If first line's physical ascent is larger than its logical
18663 ascent, use the physical ascent, and make the row taller.
18664 This makes accented characters fully visible. */
18665 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
18666 && row
->phys_ascent
> row
->ascent
)
18668 row
->height
+= row
->phys_ascent
- row
->ascent
;
18669 row
->ascent
= row
->phys_ascent
;
18672 /* Compute how much of the line is visible. */
18673 row
->visible_height
= row
->height
;
18675 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
18676 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
18678 if (row
->y
< min_y
)
18679 row
->visible_height
-= min_y
- row
->y
;
18680 if (row
->y
+ row
->height
> max_y
)
18681 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
18685 row
->pixel_width
= row
->used
[TEXT_AREA
];
18686 if (row
->continued_p
)
18687 row
->pixel_width
-= it
->continuation_pixel_width
;
18688 else if (row
->truncated_on_right_p
)
18689 row
->pixel_width
-= it
->truncation_pixel_width
;
18690 row
->ascent
= row
->phys_ascent
= 0;
18691 row
->height
= row
->phys_height
= row
->visible_height
= 1;
18692 row
->extra_line_spacing
= 0;
18695 /* Compute a hash code for this row. */
18696 row
->hash
= row_hash (row
);
18698 it
->max_ascent
= it
->max_descent
= 0;
18699 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
18703 /* Append one space to the glyph row of iterator IT if doing a
18704 window-based redisplay. The space has the same face as
18705 IT->face_id. Value is non-zero if a space was added.
18707 This function is called to make sure that there is always one glyph
18708 at the end of a glyph row that the cursor can be set on under
18709 window-systems. (If there weren't such a glyph we would not know
18710 how wide and tall a box cursor should be displayed).
18712 At the same time this space let's a nicely handle clearing to the
18713 end of the line if the row ends in italic text. */
18716 append_space_for_newline (struct it
*it
, int default_face_p
)
18718 if (FRAME_WINDOW_P (it
->f
))
18720 int n
= it
->glyph_row
->used
[TEXT_AREA
];
18722 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
18723 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
18725 /* Save some values that must not be changed.
18726 Must save IT->c and IT->len because otherwise
18727 ITERATOR_AT_END_P wouldn't work anymore after
18728 append_space_for_newline has been called. */
18729 enum display_element_type saved_what
= it
->what
;
18730 int saved_c
= it
->c
, saved_len
= it
->len
;
18731 int saved_char_to_display
= it
->char_to_display
;
18732 int saved_x
= it
->current_x
;
18733 int saved_face_id
= it
->face_id
;
18734 int saved_box_end
= it
->end_of_box_run_p
;
18735 struct text_pos saved_pos
;
18736 Lisp_Object saved_object
;
18739 saved_object
= it
->object
;
18740 saved_pos
= it
->position
;
18742 it
->what
= IT_CHARACTER
;
18743 memset (&it
->position
, 0, sizeof it
->position
);
18744 it
->object
= make_number (0);
18745 it
->c
= it
->char_to_display
= ' ';
18748 /* If the default face was remapped, be sure to use the
18749 remapped face for the appended newline. */
18750 if (default_face_p
)
18751 it
->face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
18752 else if (it
->face_before_selective_p
)
18753 it
->face_id
= it
->saved_face_id
;
18754 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18755 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
18756 /* In R2L rows, we will prepend a stretch glyph that will
18757 have the end_of_box_run_p flag set for it, so there's no
18758 need for the appended newline glyph to have that flag
18760 if (it
->glyph_row
->reversed_p
18761 /* But if the appended newline glyph goes all the way to
18762 the end of the row, there will be no stretch glyph,
18763 so leave the box flag set. */
18764 && saved_x
+ FRAME_COLUMN_WIDTH (it
->f
) < it
->last_visible_x
)
18765 it
->end_of_box_run_p
= 0;
18767 PRODUCE_GLYPHS (it
);
18769 it
->override_ascent
= -1;
18770 it
->constrain_row_ascent_descent_p
= 0;
18771 it
->current_x
= saved_x
;
18772 it
->object
= saved_object
;
18773 it
->position
= saved_pos
;
18774 it
->what
= saved_what
;
18775 it
->face_id
= saved_face_id
;
18776 it
->len
= saved_len
;
18778 it
->char_to_display
= saved_char_to_display
;
18779 it
->end_of_box_run_p
= saved_box_end
;
18788 /* Extend the face of the last glyph in the text area of IT->glyph_row
18789 to the end of the display line. Called from display_line. If the
18790 glyph row is empty, add a space glyph to it so that we know the
18791 face to draw. Set the glyph row flag fill_line_p. If the glyph
18792 row is R2L, prepend a stretch glyph to cover the empty space to the
18793 left of the leftmost glyph. */
18796 extend_face_to_end_of_line (struct it
*it
)
18798 struct face
*face
, *default_face
;
18799 struct frame
*f
= it
->f
;
18801 /* If line is already filled, do nothing. Non window-system frames
18802 get a grace of one more ``pixel'' because their characters are
18803 1-``pixel'' wide, so they hit the equality too early. This grace
18804 is needed only for R2L rows that are not continued, to produce
18805 one extra blank where we could display the cursor. */
18806 if (it
->current_x
>= it
->last_visible_x
18807 + (!FRAME_WINDOW_P (f
)
18808 && it
->glyph_row
->reversed_p
18809 && !it
->glyph_row
->continued_p
))
18812 /* The default face, possibly remapped. */
18813 default_face
= FACE_FROM_ID (f
, lookup_basic_face (f
, DEFAULT_FACE_ID
));
18815 /* Face extension extends the background and box of IT->face_id
18816 to the end of the line. If the background equals the background
18817 of the frame, we don't have to do anything. */
18818 if (it
->face_before_selective_p
)
18819 face
= FACE_FROM_ID (f
, it
->saved_face_id
);
18821 face
= FACE_FROM_ID (f
, it
->face_id
);
18823 if (FRAME_WINDOW_P (f
)
18824 && MATRIX_ROW_DISPLAYS_TEXT_P (it
->glyph_row
)
18825 && face
->box
== FACE_NO_BOX
18826 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
18827 #ifdef HAVE_WINDOW_SYSTEM
18830 && !it
->glyph_row
->reversed_p
)
18833 /* Set the glyph row flag indicating that the face of the last glyph
18834 in the text area has to be drawn to the end of the text area. */
18835 it
->glyph_row
->fill_line_p
= 1;
18837 /* If current character of IT is not ASCII, make sure we have the
18838 ASCII face. This will be automatically undone the next time
18839 get_next_display_element returns a multibyte character. Note
18840 that the character will always be single byte in unibyte
18842 if (!ASCII_CHAR_P (it
->c
))
18844 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
18847 if (FRAME_WINDOW_P (f
))
18849 /* If the row is empty, add a space with the current face of IT,
18850 so that we know which face to draw. */
18851 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
18853 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
18854 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= face
->id
;
18855 it
->glyph_row
->used
[TEXT_AREA
] = 1;
18857 #ifdef HAVE_WINDOW_SYSTEM
18858 if (it
->glyph_row
->reversed_p
)
18860 /* Prepend a stretch glyph to the row, such that the
18861 rightmost glyph will be drawn flushed all the way to the
18862 right margin of the window. The stretch glyph that will
18863 occupy the empty space, if any, to the left of the
18865 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (f
);
18866 struct glyph
*row_start
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18867 struct glyph
*row_end
= row_start
+ it
->glyph_row
->used
[TEXT_AREA
];
18869 int row_width
, stretch_ascent
, stretch_width
;
18870 struct text_pos saved_pos
;
18871 int saved_face_id
, saved_avoid_cursor
, saved_box_start
;
18873 for (row_width
= 0, g
= row_start
; g
< row_end
; g
++)
18874 row_width
+= g
->pixel_width
;
18875 stretch_width
= window_box_width (it
->w
, TEXT_AREA
) - row_width
;
18876 if (stretch_width
> 0)
18879 (((it
->ascent
+ it
->descent
)
18880 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
18881 saved_pos
= it
->position
;
18882 memset (&it
->position
, 0, sizeof it
->position
);
18883 saved_avoid_cursor
= it
->avoid_cursor_p
;
18884 it
->avoid_cursor_p
= 1;
18885 saved_face_id
= it
->face_id
;
18886 saved_box_start
= it
->start_of_box_run_p
;
18887 /* The last row's stretch glyph should get the default
18888 face, to avoid painting the rest of the window with
18889 the region face, if the region ends at ZV. */
18890 if (it
->glyph_row
->ends_at_zv_p
)
18891 it
->face_id
= default_face
->id
;
18893 it
->face_id
= face
->id
;
18894 it
->start_of_box_run_p
= 0;
18895 append_stretch_glyph (it
, make_number (0), stretch_width
,
18896 it
->ascent
+ it
->descent
, stretch_ascent
);
18897 it
->position
= saved_pos
;
18898 it
->avoid_cursor_p
= saved_avoid_cursor
;
18899 it
->face_id
= saved_face_id
;
18900 it
->start_of_box_run_p
= saved_box_start
;
18903 #endif /* HAVE_WINDOW_SYSTEM */
18907 /* Save some values that must not be changed. */
18908 int saved_x
= it
->current_x
;
18909 struct text_pos saved_pos
;
18910 Lisp_Object saved_object
;
18911 enum display_element_type saved_what
= it
->what
;
18912 int saved_face_id
= it
->face_id
;
18914 saved_object
= it
->object
;
18915 saved_pos
= it
->position
;
18917 it
->what
= IT_CHARACTER
;
18918 memset (&it
->position
, 0, sizeof it
->position
);
18919 it
->object
= make_number (0);
18920 it
->c
= it
->char_to_display
= ' ';
18922 /* The last row's blank glyphs should get the default face, to
18923 avoid painting the rest of the window with the region face,
18924 if the region ends at ZV. */
18925 if (it
->glyph_row
->ends_at_zv_p
)
18926 it
->face_id
= default_face
->id
;
18928 it
->face_id
= face
->id
;
18930 PRODUCE_GLYPHS (it
);
18932 while (it
->current_x
<= it
->last_visible_x
)
18933 PRODUCE_GLYPHS (it
);
18935 /* Don't count these blanks really. It would let us insert a left
18936 truncation glyph below and make us set the cursor on them, maybe. */
18937 it
->current_x
= saved_x
;
18938 it
->object
= saved_object
;
18939 it
->position
= saved_pos
;
18940 it
->what
= saved_what
;
18941 it
->face_id
= saved_face_id
;
18946 /* Value is non-zero if text starting at CHARPOS in current_buffer is
18947 trailing whitespace. */
18950 trailing_whitespace_p (ptrdiff_t charpos
)
18952 ptrdiff_t bytepos
= CHAR_TO_BYTE (charpos
);
18955 while (bytepos
< ZV_BYTE
18956 && (c
= FETCH_CHAR (bytepos
),
18957 c
== ' ' || c
== '\t'))
18960 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
18962 if (bytepos
!= PT_BYTE
)
18969 /* Highlight trailing whitespace, if any, in ROW. */
18972 highlight_trailing_whitespace (struct frame
*f
, struct glyph_row
*row
)
18974 int used
= row
->used
[TEXT_AREA
];
18978 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
18979 struct glyph
*glyph
= start
+ used
- 1;
18981 if (row
->reversed_p
)
18983 /* Right-to-left rows need to be processed in the opposite
18984 direction, so swap the edge pointers. */
18986 start
= row
->glyphs
[TEXT_AREA
] + used
- 1;
18989 /* Skip over glyphs inserted to display the cursor at the
18990 end of a line, for extending the face of the last glyph
18991 to the end of the line on terminals, and for truncation
18992 and continuation glyphs. */
18993 if (!row
->reversed_p
)
18995 while (glyph
>= start
18996 && glyph
->type
== CHAR_GLYPH
18997 && INTEGERP (glyph
->object
))
19002 while (glyph
<= start
19003 && glyph
->type
== CHAR_GLYPH
19004 && INTEGERP (glyph
->object
))
19008 /* If last glyph is a space or stretch, and it's trailing
19009 whitespace, set the face of all trailing whitespace glyphs in
19010 IT->glyph_row to `trailing-whitespace'. */
19011 if ((row
->reversed_p
? glyph
<= start
: glyph
>= start
)
19012 && BUFFERP (glyph
->object
)
19013 && (glyph
->type
== STRETCH_GLYPH
19014 || (glyph
->type
== CHAR_GLYPH
19015 && glyph
->u
.ch
== ' '))
19016 && trailing_whitespace_p (glyph
->charpos
))
19018 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
19022 if (!row
->reversed_p
)
19024 while (glyph
>= start
19025 && BUFFERP (glyph
->object
)
19026 && (glyph
->type
== STRETCH_GLYPH
19027 || (glyph
->type
== CHAR_GLYPH
19028 && glyph
->u
.ch
== ' ')))
19029 (glyph
--)->face_id
= face_id
;
19033 while (glyph
<= start
19034 && BUFFERP (glyph
->object
)
19035 && (glyph
->type
== STRETCH_GLYPH
19036 || (glyph
->type
== CHAR_GLYPH
19037 && glyph
->u
.ch
== ' ')))
19038 (glyph
++)->face_id
= face_id
;
19045 /* Value is non-zero if glyph row ROW should be
19046 considered to hold the buffer position CHARPOS. */
19049 row_for_charpos_p (struct glyph_row
*row
, ptrdiff_t charpos
)
19053 if (charpos
== CHARPOS (row
->end
.pos
)
19054 || charpos
== MATRIX_ROW_END_CHARPOS (row
))
19056 /* Suppose the row ends on a string.
19057 Unless the row is continued, that means it ends on a newline
19058 in the string. If it's anything other than a display string
19059 (e.g., a before-string from an overlay), we don't want the
19060 cursor there. (This heuristic seems to give the optimal
19061 behavior for the various types of multi-line strings.)
19062 One exception: if the string has `cursor' property on one of
19063 its characters, we _do_ want the cursor there. */
19064 if (CHARPOS (row
->end
.string_pos
) >= 0)
19066 if (row
->continued_p
)
19070 /* Check for `display' property. */
19071 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
19072 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
19073 struct glyph
*glyph
;
19076 for (glyph
= end
; glyph
>= beg
; --glyph
)
19077 if (STRINGP (glyph
->object
))
19080 = Fget_char_property (make_number (charpos
),
19084 && display_prop_string_p (prop
, glyph
->object
));
19085 /* If there's a `cursor' property on one of the
19086 string's characters, this row is a cursor row,
19087 even though this is not a display string. */
19090 Lisp_Object s
= glyph
->object
;
19092 for ( ; glyph
>= beg
&& EQ (glyph
->object
, s
); --glyph
)
19094 ptrdiff_t gpos
= glyph
->charpos
;
19096 if (!NILP (Fget_char_property (make_number (gpos
),
19108 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
19110 /* If the row ends in middle of a real character,
19111 and the line is continued, we want the cursor here.
19112 That's because CHARPOS (ROW->end.pos) would equal
19113 PT if PT is before the character. */
19114 if (!row
->ends_in_ellipsis_p
)
19115 result
= row
->continued_p
;
19117 /* If the row ends in an ellipsis, then
19118 CHARPOS (ROW->end.pos) will equal point after the
19119 invisible text. We want that position to be displayed
19120 after the ellipsis. */
19123 /* If the row ends at ZV, display the cursor at the end of that
19124 row instead of at the start of the row below. */
19125 else if (row
->ends_at_zv_p
)
19134 /* Value is non-zero if glyph row ROW should be
19135 used to hold the cursor. */
19138 cursor_row_p (struct glyph_row
*row
)
19140 return row_for_charpos_p (row
, PT
);
19145 /* Push the property PROP so that it will be rendered at the current
19146 position in IT. Return 1 if PROP was successfully pushed, 0
19147 otherwise. Called from handle_line_prefix to handle the
19148 `line-prefix' and `wrap-prefix' properties. */
19151 push_prefix_prop (struct it
*it
, Lisp_Object prop
)
19153 struct text_pos pos
=
19154 STRINGP (it
->string
) ? it
->current
.string_pos
: it
->current
.pos
;
19156 eassert (it
->method
== GET_FROM_BUFFER
19157 || it
->method
== GET_FROM_DISPLAY_VECTOR
19158 || it
->method
== GET_FROM_STRING
);
19160 /* We need to save the current buffer/string position, so it will be
19161 restored by pop_it, because iterate_out_of_display_property
19162 depends on that being set correctly, but some situations leave
19163 it->position not yet set when this function is called. */
19164 push_it (it
, &pos
);
19166 if (STRINGP (prop
))
19168 if (SCHARS (prop
) == 0)
19175 it
->string_from_prefix_prop_p
= 1;
19176 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
19177 it
->current
.overlay_string_index
= -1;
19178 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
19179 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
19180 it
->method
= GET_FROM_STRING
;
19181 it
->stop_charpos
= 0;
19183 it
->base_level_stop
= 0;
19185 /* Force paragraph direction to be that of the parent
19187 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
19188 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
19190 it
->paragraph_embedding
= L2R
;
19192 /* Set up the bidi iterator for this display string. */
19195 it
->bidi_it
.string
.lstring
= it
->string
;
19196 it
->bidi_it
.string
.s
= NULL
;
19197 it
->bidi_it
.string
.schars
= it
->end_charpos
;
19198 it
->bidi_it
.string
.bufpos
= IT_CHARPOS (*it
);
19199 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
19200 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
19201 it
->bidi_it
.w
= it
->w
;
19202 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
19205 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
19207 it
->method
= GET_FROM_STRETCH
;
19210 #ifdef HAVE_WINDOW_SYSTEM
19211 else if (IMAGEP (prop
))
19213 it
->what
= IT_IMAGE
;
19214 it
->image_id
= lookup_image (it
->f
, prop
);
19215 it
->method
= GET_FROM_IMAGE
;
19217 #endif /* HAVE_WINDOW_SYSTEM */
19220 pop_it (it
); /* bogus display property, give up */
19227 /* Return the character-property PROP at the current position in IT. */
19230 get_it_property (struct it
*it
, Lisp_Object prop
)
19232 Lisp_Object position
, object
= it
->object
;
19234 if (STRINGP (object
))
19235 position
= make_number (IT_STRING_CHARPOS (*it
));
19236 else if (BUFFERP (object
))
19238 position
= make_number (IT_CHARPOS (*it
));
19239 object
= it
->window
;
19244 return Fget_char_property (position
, prop
, object
);
19247 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
19250 handle_line_prefix (struct it
*it
)
19252 Lisp_Object prefix
;
19254 if (it
->continuation_lines_width
> 0)
19256 prefix
= get_it_property (it
, Qwrap_prefix
);
19258 prefix
= Vwrap_prefix
;
19262 prefix
= get_it_property (it
, Qline_prefix
);
19264 prefix
= Vline_prefix
;
19266 if (! NILP (prefix
) && push_prefix_prop (it
, prefix
))
19268 /* If the prefix is wider than the window, and we try to wrap
19269 it, it would acquire its own wrap prefix, and so on till the
19270 iterator stack overflows. So, don't wrap the prefix. */
19271 it
->line_wrap
= TRUNCATE
;
19272 it
->avoid_cursor_p
= 1;
19278 /* Remove N glyphs at the start of a reversed IT->glyph_row. Called
19279 only for R2L lines from display_line and display_string, when they
19280 decide that too many glyphs were produced by PRODUCE_GLYPHS, and
19281 the line/string needs to be continued on the next glyph row. */
19283 unproduce_glyphs (struct it
*it
, int n
)
19285 struct glyph
*glyph
, *end
;
19287 eassert (it
->glyph_row
);
19288 eassert (it
->glyph_row
->reversed_p
);
19289 eassert (it
->area
== TEXT_AREA
);
19290 eassert (n
<= it
->glyph_row
->used
[TEXT_AREA
]);
19292 if (n
> it
->glyph_row
->used
[TEXT_AREA
])
19293 n
= it
->glyph_row
->used
[TEXT_AREA
];
19294 glyph
= it
->glyph_row
->glyphs
[TEXT_AREA
] + n
;
19295 end
= it
->glyph_row
->glyphs
[TEXT_AREA
] + it
->glyph_row
->used
[TEXT_AREA
];
19296 for ( ; glyph
< end
; glyph
++)
19297 glyph
[-n
] = *glyph
;
19300 /* Find the positions in a bidi-reordered ROW to serve as ROW->minpos
19301 and ROW->maxpos. */
19303 find_row_edges (struct it
*it
, struct glyph_row
*row
,
19304 ptrdiff_t min_pos
, ptrdiff_t min_bpos
,
19305 ptrdiff_t max_pos
, ptrdiff_t max_bpos
)
19307 /* FIXME: Revisit this when glyph ``spilling'' in continuation
19308 lines' rows is implemented for bidi-reordered rows. */
19310 /* ROW->minpos is the value of min_pos, the minimal buffer position
19311 we have in ROW, or ROW->start.pos if that is smaller. */
19312 if (min_pos
<= ZV
&& min_pos
< row
->start
.pos
.charpos
)
19313 SET_TEXT_POS (row
->minpos
, min_pos
, min_bpos
);
19315 /* We didn't find buffer positions smaller than ROW->start, or
19316 didn't find _any_ valid buffer positions in any of the glyphs,
19317 so we must trust the iterator's computed positions. */
19318 row
->minpos
= row
->start
.pos
;
19321 max_pos
= CHARPOS (it
->current
.pos
);
19322 max_bpos
= BYTEPOS (it
->current
.pos
);
19325 /* Here are the various use-cases for ending the row, and the
19326 corresponding values for ROW->maxpos:
19328 Line ends in a newline from buffer eol_pos + 1
19329 Line is continued from buffer max_pos + 1
19330 Line is truncated on right it->current.pos
19331 Line ends in a newline from string max_pos + 1(*)
19332 (*) + 1 only when line ends in a forward scan
19333 Line is continued from string max_pos
19334 Line is continued from display vector max_pos
19335 Line is entirely from a string min_pos == max_pos
19336 Line is entirely from a display vector min_pos == max_pos
19337 Line that ends at ZV ZV
19339 If you discover other use-cases, please add them here as
19341 if (row
->ends_at_zv_p
)
19342 row
->maxpos
= it
->current
.pos
;
19343 else if (row
->used
[TEXT_AREA
])
19345 int seen_this_string
= 0;
19346 struct glyph_row
*r1
= row
- 1;
19348 /* Did we see the same display string on the previous row? */
19349 if (STRINGP (it
->object
)
19350 /* this is not the first row */
19351 && row
> it
->w
->desired_matrix
->rows
19352 /* previous row is not the header line */
19353 && !r1
->mode_line_p
19354 /* previous row also ends in a newline from a string */
19355 && r1
->ends_in_newline_from_string_p
)
19357 struct glyph
*start
, *end
;
19359 /* Search for the last glyph of the previous row that came
19360 from buffer or string. Depending on whether the row is
19361 L2R or R2L, we need to process it front to back or the
19362 other way round. */
19363 if (!r1
->reversed_p
)
19365 start
= r1
->glyphs
[TEXT_AREA
];
19366 end
= start
+ r1
->used
[TEXT_AREA
];
19367 /* Glyphs inserted by redisplay have an integer (zero)
19368 as their object. */
19370 && INTEGERP ((end
- 1)->object
)
19371 && (end
- 1)->charpos
<= 0)
19375 if (EQ ((end
- 1)->object
, it
->object
))
19376 seen_this_string
= 1;
19379 /* If all the glyphs of the previous row were inserted
19380 by redisplay, it means the previous row was
19381 produced from a single newline, which is only
19382 possible if that newline came from the same string
19383 as the one which produced this ROW. */
19384 seen_this_string
= 1;
19388 end
= r1
->glyphs
[TEXT_AREA
] - 1;
19389 start
= end
+ r1
->used
[TEXT_AREA
];
19391 && INTEGERP ((end
+ 1)->object
)
19392 && (end
+ 1)->charpos
<= 0)
19396 if (EQ ((end
+ 1)->object
, it
->object
))
19397 seen_this_string
= 1;
19400 seen_this_string
= 1;
19403 /* Take note of each display string that covers a newline only
19404 once, the first time we see it. This is for when a display
19405 string includes more than one newline in it. */
19406 if (row
->ends_in_newline_from_string_p
&& !seen_this_string
)
19408 /* If we were scanning the buffer forward when we displayed
19409 the string, we want to account for at least one buffer
19410 position that belongs to this row (position covered by
19411 the display string), so that cursor positioning will
19412 consider this row as a candidate when point is at the end
19413 of the visual line represented by this row. This is not
19414 required when scanning back, because max_pos will already
19415 have a much larger value. */
19416 if (CHARPOS (row
->end
.pos
) > max_pos
)
19417 INC_BOTH (max_pos
, max_bpos
);
19418 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19420 else if (CHARPOS (it
->eol_pos
) > 0)
19421 SET_TEXT_POS (row
->maxpos
,
19422 CHARPOS (it
->eol_pos
) + 1, BYTEPOS (it
->eol_pos
) + 1);
19423 else if (row
->continued_p
)
19425 /* If max_pos is different from IT's current position, it
19426 means IT->method does not belong to the display element
19427 at max_pos. However, it also means that the display
19428 element at max_pos was displayed in its entirety on this
19429 line, which is equivalent to saying that the next line
19430 starts at the next buffer position. */
19431 if (IT_CHARPOS (*it
) == max_pos
&& it
->method
!= GET_FROM_BUFFER
)
19432 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19435 INC_BOTH (max_pos
, max_bpos
);
19436 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19439 else if (row
->truncated_on_right_p
)
19440 /* display_line already called reseat_at_next_visible_line_start,
19441 which puts the iterator at the beginning of the next line, in
19442 the logical order. */
19443 row
->maxpos
= it
->current
.pos
;
19444 else if (max_pos
== min_pos
&& it
->method
!= GET_FROM_BUFFER
)
19445 /* A line that is entirely from a string/image/stretch... */
19446 row
->maxpos
= row
->minpos
;
19451 row
->maxpos
= it
->current
.pos
;
19454 /* Construct the glyph row IT->glyph_row in the desired matrix of
19455 IT->w from text at the current position of IT. See dispextern.h
19456 for an overview of struct it. Value is non-zero if
19457 IT->glyph_row displays text, as opposed to a line displaying ZV
19461 display_line (struct it
*it
)
19463 struct glyph_row
*row
= it
->glyph_row
;
19464 Lisp_Object overlay_arrow_string
;
19466 void *wrap_data
= NULL
;
19467 int may_wrap
= 0, wrap_x
IF_LINT (= 0);
19468 int wrap_row_used
= -1;
19469 int wrap_row_ascent
IF_LINT (= 0), wrap_row_height
IF_LINT (= 0);
19470 int wrap_row_phys_ascent
IF_LINT (= 0), wrap_row_phys_height
IF_LINT (= 0);
19471 int wrap_row_extra_line_spacing
IF_LINT (= 0);
19472 ptrdiff_t wrap_row_min_pos
IF_LINT (= 0), wrap_row_min_bpos
IF_LINT (= 0);
19473 ptrdiff_t wrap_row_max_pos
IF_LINT (= 0), wrap_row_max_bpos
IF_LINT (= 0);
19475 ptrdiff_t min_pos
= ZV
+ 1, max_pos
= 0;
19476 ptrdiff_t min_bpos
IF_LINT (= 0), max_bpos
IF_LINT (= 0);
19478 /* We always start displaying at hpos zero even if hscrolled. */
19479 eassert (it
->hpos
== 0 && it
->current_x
== 0);
19481 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
19482 >= it
->w
->desired_matrix
->nrows
)
19484 it
->w
->nrows_scale_factor
++;
19485 it
->f
->fonts_changed
= 1;
19489 /* Clear the result glyph row and enable it. */
19490 prepare_desired_row (row
);
19492 row
->y
= it
->current_y
;
19493 row
->start
= it
->start
;
19494 row
->continuation_lines_width
= it
->continuation_lines_width
;
19495 row
->displays_text_p
= 1;
19496 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
19497 it
->starts_in_middle_of_char_p
= 0;
19499 /* Arrange the overlays nicely for our purposes. Usually, we call
19500 display_line on only one line at a time, in which case this
19501 can't really hurt too much, or we call it on lines which appear
19502 one after another in the buffer, in which case all calls to
19503 recenter_overlay_lists but the first will be pretty cheap. */
19504 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
19506 /* Move over display elements that are not visible because we are
19507 hscrolled. This may stop at an x-position < IT->first_visible_x
19508 if the first glyph is partially visible or if we hit a line end. */
19509 if (it
->current_x
< it
->first_visible_x
)
19511 enum move_it_result move_result
;
19513 this_line_min_pos
= row
->start
.pos
;
19514 move_result
= move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
19515 MOVE_TO_POS
| MOVE_TO_X
);
19516 /* If we are under a large hscroll, move_it_in_display_line_to
19517 could hit the end of the line without reaching
19518 it->first_visible_x. Pretend that we did reach it. This is
19519 especially important on a TTY, where we will call
19520 extend_face_to_end_of_line, which needs to know how many
19521 blank glyphs to produce. */
19522 if (it
->current_x
< it
->first_visible_x
19523 && (move_result
== MOVE_NEWLINE_OR_CR
19524 || move_result
== MOVE_POS_MATCH_OR_ZV
))
19525 it
->current_x
= it
->first_visible_x
;
19527 /* Record the smallest positions seen while we moved over
19528 display elements that are not visible. This is needed by
19529 redisplay_internal for optimizing the case where the cursor
19530 stays inside the same line. The rest of this function only
19531 considers positions that are actually displayed, so
19532 RECORD_MAX_MIN_POS will not otherwise record positions that
19533 are hscrolled to the left of the left edge of the window. */
19534 min_pos
= CHARPOS (this_line_min_pos
);
19535 min_bpos
= BYTEPOS (this_line_min_pos
);
19539 /* We only do this when not calling `move_it_in_display_line_to'
19540 above, because move_it_in_display_line_to calls
19541 handle_line_prefix itself. */
19542 handle_line_prefix (it
);
19545 /* Get the initial row height. This is either the height of the
19546 text hscrolled, if there is any, or zero. */
19547 row
->ascent
= it
->max_ascent
;
19548 row
->height
= it
->max_ascent
+ it
->max_descent
;
19549 row
->phys_ascent
= it
->max_phys_ascent
;
19550 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
19551 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
19553 /* Utility macro to record max and min buffer positions seen until now. */
19554 #define RECORD_MAX_MIN_POS(IT) \
19557 int composition_p = !STRINGP ((IT)->string) \
19558 && ((IT)->what == IT_COMPOSITION); \
19559 ptrdiff_t current_pos = \
19560 composition_p ? (IT)->cmp_it.charpos \
19561 : IT_CHARPOS (*(IT)); \
19562 ptrdiff_t current_bpos = \
19563 composition_p ? CHAR_TO_BYTE (current_pos) \
19564 : IT_BYTEPOS (*(IT)); \
19565 if (current_pos < min_pos) \
19567 min_pos = current_pos; \
19568 min_bpos = current_bpos; \
19570 if (IT_CHARPOS (*it) > max_pos) \
19572 max_pos = IT_CHARPOS (*it); \
19573 max_bpos = IT_BYTEPOS (*it); \
19578 /* Loop generating characters. The loop is left with IT on the next
19579 character to display. */
19582 int n_glyphs_before
, hpos_before
, x_before
;
19584 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
19586 /* Retrieve the next thing to display. Value is zero if end of
19588 if (!get_next_display_element (it
))
19590 /* Maybe add a space at the end of this line that is used to
19591 display the cursor there under X. Set the charpos of the
19592 first glyph of blank lines not corresponding to any text
19594 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19595 row
->exact_window_width_line_p
= 1;
19596 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
19597 || row
->used
[TEXT_AREA
] == 0)
19599 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
19600 row
->displays_text_p
= 0;
19602 if (!NILP (BVAR (XBUFFER (it
->w
->contents
), indicate_empty_lines
))
19603 && (!MINI_WINDOW_P (it
->w
)
19604 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
19605 row
->indicate_empty_line_p
= 1;
19608 it
->continuation_lines_width
= 0;
19609 row
->ends_at_zv_p
= 1;
19610 /* A row that displays right-to-left text must always have
19611 its last face extended all the way to the end of line,
19612 even if this row ends in ZV, because we still write to
19613 the screen left to right. We also need to extend the
19614 last face if the default face is remapped to some
19615 different face, otherwise the functions that clear
19616 portions of the screen will clear with the default face's
19617 background color. */
19618 if (row
->reversed_p
19619 || lookup_basic_face (it
->f
, DEFAULT_FACE_ID
) != DEFAULT_FACE_ID
)
19620 extend_face_to_end_of_line (it
);
19624 /* Now, get the metrics of what we want to display. This also
19625 generates glyphs in `row' (which is IT->glyph_row). */
19626 n_glyphs_before
= row
->used
[TEXT_AREA
];
19629 /* Remember the line height so far in case the next element doesn't
19630 fit on the line. */
19631 if (it
->line_wrap
!= TRUNCATE
)
19633 ascent
= it
->max_ascent
;
19634 descent
= it
->max_descent
;
19635 phys_ascent
= it
->max_phys_ascent
;
19636 phys_descent
= it
->max_phys_descent
;
19638 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
19640 if (IT_DISPLAYING_WHITESPACE (it
))
19644 SAVE_IT (wrap_it
, *it
, wrap_data
);
19646 wrap_row_used
= row
->used
[TEXT_AREA
];
19647 wrap_row_ascent
= row
->ascent
;
19648 wrap_row_height
= row
->height
;
19649 wrap_row_phys_ascent
= row
->phys_ascent
;
19650 wrap_row_phys_height
= row
->phys_height
;
19651 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
19652 wrap_row_min_pos
= min_pos
;
19653 wrap_row_min_bpos
= min_bpos
;
19654 wrap_row_max_pos
= max_pos
;
19655 wrap_row_max_bpos
= max_bpos
;
19661 PRODUCE_GLYPHS (it
);
19663 /* If this display element was in marginal areas, continue with
19665 if (it
->area
!= TEXT_AREA
)
19667 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19668 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19669 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19670 row
->phys_height
= max (row
->phys_height
,
19671 it
->max_phys_ascent
+ it
->max_phys_descent
);
19672 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19673 it
->max_extra_line_spacing
);
19674 set_iterator_to_next (it
, 1);
19678 /* Does the display element fit on the line? If we truncate
19679 lines, we should draw past the right edge of the window. If
19680 we don't truncate, we want to stop so that we can display the
19681 continuation glyph before the right margin. If lines are
19682 continued, there are two possible strategies for characters
19683 resulting in more than 1 glyph (e.g. tabs): Display as many
19684 glyphs as possible in this line and leave the rest for the
19685 continuation line, or display the whole element in the next
19686 line. Original redisplay did the former, so we do it also. */
19687 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
19688 hpos_before
= it
->hpos
;
19691 if (/* Not a newline. */
19693 /* Glyphs produced fit entirely in the line. */
19694 && it
->current_x
< it
->last_visible_x
)
19696 it
->hpos
+= nglyphs
;
19697 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19698 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19699 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19700 row
->phys_height
= max (row
->phys_height
,
19701 it
->max_phys_ascent
+ it
->max_phys_descent
);
19702 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19703 it
->max_extra_line_spacing
);
19704 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
19705 row
->x
= x
- it
->first_visible_x
;
19706 /* Record the maximum and minimum buffer positions seen so
19707 far in glyphs that will be displayed by this row. */
19709 RECORD_MAX_MIN_POS (it
);
19714 struct glyph
*glyph
;
19716 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
19718 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
19719 new_x
= x
+ glyph
->pixel_width
;
19721 if (/* Lines are continued. */
19722 it
->line_wrap
!= TRUNCATE
19723 && (/* Glyph doesn't fit on the line. */
19724 new_x
> it
->last_visible_x
19725 /* Or it fits exactly on a window system frame. */
19726 || (new_x
== it
->last_visible_x
19727 && FRAME_WINDOW_P (it
->f
)
19728 && (row
->reversed_p
19729 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19730 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
19732 /* End of a continued line. */
19735 || (new_x
== it
->last_visible_x
19736 && FRAME_WINDOW_P (it
->f
)
19737 && (row
->reversed_p
19738 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19739 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
))))
19741 /* Current glyph is the only one on the line or
19742 fits exactly on the line. We must continue
19743 the line because we can't draw the cursor
19744 after the glyph. */
19745 row
->continued_p
= 1;
19746 it
->current_x
= new_x
;
19747 it
->continuation_lines_width
+= new_x
;
19749 if (i
== nglyphs
- 1)
19751 /* If line-wrap is on, check if a previous
19752 wrap point was found. */
19753 if (wrap_row_used
> 0
19754 /* Even if there is a previous wrap
19755 point, continue the line here as
19756 usual, if (i) the previous character
19757 was a space or tab AND (ii) the
19758 current character is not. */
19760 || IT_DISPLAYING_WHITESPACE (it
)))
19763 /* Record the maximum and minimum buffer
19764 positions seen so far in glyphs that will be
19765 displayed by this row. */
19767 RECORD_MAX_MIN_POS (it
);
19768 set_iterator_to_next (it
, 1);
19769 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19771 if (!get_next_display_element (it
))
19773 row
->exact_window_width_line_p
= 1;
19774 it
->continuation_lines_width
= 0;
19775 row
->continued_p
= 0;
19776 row
->ends_at_zv_p
= 1;
19778 else if (ITERATOR_AT_END_OF_LINE_P (it
))
19780 row
->continued_p
= 0;
19781 row
->exact_window_width_line_p
= 1;
19785 else if (it
->bidi_p
)
19786 RECORD_MAX_MIN_POS (it
);
19788 else if (CHAR_GLYPH_PADDING_P (*glyph
)
19789 && !FRAME_WINDOW_P (it
->f
))
19791 /* A padding glyph that doesn't fit on this line.
19792 This means the whole character doesn't fit
19794 if (row
->reversed_p
)
19795 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19796 - n_glyphs_before
);
19797 row
->used
[TEXT_AREA
] = n_glyphs_before
;
19799 /* Fill the rest of the row with continuation
19800 glyphs like in 20.x. */
19801 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
19802 < row
->glyphs
[1 + TEXT_AREA
])
19803 produce_special_glyphs (it
, IT_CONTINUATION
);
19805 row
->continued_p
= 1;
19806 it
->current_x
= x_before
;
19807 it
->continuation_lines_width
+= x_before
;
19809 /* Restore the height to what it was before the
19810 element not fitting on the line. */
19811 it
->max_ascent
= ascent
;
19812 it
->max_descent
= descent
;
19813 it
->max_phys_ascent
= phys_ascent
;
19814 it
->max_phys_descent
= phys_descent
;
19816 else if (wrap_row_used
> 0)
19819 if (row
->reversed_p
)
19820 unproduce_glyphs (it
,
19821 row
->used
[TEXT_AREA
] - wrap_row_used
);
19822 RESTORE_IT (it
, &wrap_it
, wrap_data
);
19823 it
->continuation_lines_width
+= wrap_x
;
19824 row
->used
[TEXT_AREA
] = wrap_row_used
;
19825 row
->ascent
= wrap_row_ascent
;
19826 row
->height
= wrap_row_height
;
19827 row
->phys_ascent
= wrap_row_phys_ascent
;
19828 row
->phys_height
= wrap_row_phys_height
;
19829 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
19830 min_pos
= wrap_row_min_pos
;
19831 min_bpos
= wrap_row_min_bpos
;
19832 max_pos
= wrap_row_max_pos
;
19833 max_bpos
= wrap_row_max_bpos
;
19834 row
->continued_p
= 1;
19835 row
->ends_at_zv_p
= 0;
19836 row
->exact_window_width_line_p
= 0;
19837 it
->continuation_lines_width
+= x
;
19839 /* Make sure that a non-default face is extended
19840 up to the right margin of the window. */
19841 extend_face_to_end_of_line (it
);
19843 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
19845 /* A TAB that extends past the right edge of the
19846 window. This produces a single glyph on
19847 window system frames. We leave the glyph in
19848 this row and let it fill the row, but don't
19849 consume the TAB. */
19850 if ((row
->reversed_p
19851 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19852 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19853 produce_special_glyphs (it
, IT_CONTINUATION
);
19854 it
->continuation_lines_width
+= it
->last_visible_x
;
19855 row
->ends_in_middle_of_char_p
= 1;
19856 row
->continued_p
= 1;
19857 glyph
->pixel_width
= it
->last_visible_x
- x
;
19858 it
->starts_in_middle_of_char_p
= 1;
19862 /* Something other than a TAB that draws past
19863 the right edge of the window. Restore
19864 positions to values before the element. */
19865 if (row
->reversed_p
)
19866 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19867 - (n_glyphs_before
+ i
));
19868 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
19870 /* Display continuation glyphs. */
19871 it
->current_x
= x_before
;
19872 it
->continuation_lines_width
+= x
;
19873 if (!FRAME_WINDOW_P (it
->f
)
19874 || (row
->reversed_p
19875 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19876 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19877 produce_special_glyphs (it
, IT_CONTINUATION
);
19878 row
->continued_p
= 1;
19880 extend_face_to_end_of_line (it
);
19882 if (nglyphs
> 1 && i
> 0)
19884 row
->ends_in_middle_of_char_p
= 1;
19885 it
->starts_in_middle_of_char_p
= 1;
19888 /* Restore the height to what it was before the
19889 element not fitting on the line. */
19890 it
->max_ascent
= ascent
;
19891 it
->max_descent
= descent
;
19892 it
->max_phys_ascent
= phys_ascent
;
19893 it
->max_phys_descent
= phys_descent
;
19898 else if (new_x
> it
->first_visible_x
)
19900 /* Increment number of glyphs actually displayed. */
19903 /* Record the maximum and minimum buffer positions
19904 seen so far in glyphs that will be displayed by
19907 RECORD_MAX_MIN_POS (it
);
19909 if (x
< it
->first_visible_x
)
19910 /* Glyph is partially visible, i.e. row starts at
19911 negative X position. */
19912 row
->x
= x
- it
->first_visible_x
;
19916 /* Glyph is completely off the left margin of the
19917 window. This should not happen because of the
19918 move_it_in_display_line at the start of this
19919 function, unless the text display area of the
19920 window is empty. */
19921 eassert (it
->first_visible_x
<= it
->last_visible_x
);
19924 /* Even if this display element produced no glyphs at all,
19925 we want to record its position. */
19926 if (it
->bidi_p
&& nglyphs
== 0)
19927 RECORD_MAX_MIN_POS (it
);
19929 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19930 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19931 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19932 row
->phys_height
= max (row
->phys_height
,
19933 it
->max_phys_ascent
+ it
->max_phys_descent
);
19934 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19935 it
->max_extra_line_spacing
);
19937 /* End of this display line if row is continued. */
19938 if (row
->continued_p
|| row
->ends_at_zv_p
)
19943 /* Is this a line end? If yes, we're also done, after making
19944 sure that a non-default face is extended up to the right
19945 margin of the window. */
19946 if (ITERATOR_AT_END_OF_LINE_P (it
))
19948 int used_before
= row
->used
[TEXT_AREA
];
19950 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
19952 /* Add a space at the end of the line that is used to
19953 display the cursor there. */
19954 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19955 append_space_for_newline (it
, 0);
19957 /* Extend the face to the end of the line. */
19958 extend_face_to_end_of_line (it
);
19960 /* Make sure we have the position. */
19961 if (used_before
== 0)
19962 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
19964 /* Record the position of the newline, for use in
19966 it
->eol_pos
= it
->current
.pos
;
19968 /* Consume the line end. This skips over invisible lines. */
19969 set_iterator_to_next (it
, 1);
19970 it
->continuation_lines_width
= 0;
19974 /* Proceed with next display element. Note that this skips
19975 over lines invisible because of selective display. */
19976 set_iterator_to_next (it
, 1);
19978 /* If we truncate lines, we are done when the last displayed
19979 glyphs reach past the right margin of the window. */
19980 if (it
->line_wrap
== TRUNCATE
19981 && (FRAME_WINDOW_P (it
->f
) && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
19982 ? (it
->current_x
>= it
->last_visible_x
)
19983 : (it
->current_x
> it
->last_visible_x
)))
19985 /* Maybe add truncation glyphs. */
19986 if (!FRAME_WINDOW_P (it
->f
)
19987 || (row
->reversed_p
19988 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19989 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19993 if (!row
->reversed_p
)
19995 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
19996 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
20001 for (i
= 0; i
< row
->used
[TEXT_AREA
]; i
++)
20002 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
20004 /* Remove any padding glyphs at the front of ROW, to
20005 make room for the truncation glyphs we will be
20006 adding below. The loop below always inserts at
20007 least one truncation glyph, so also remove the
20008 last glyph added to ROW. */
20009 unproduce_glyphs (it
, i
+ 1);
20010 /* Adjust i for the loop below. */
20011 i
= row
->used
[TEXT_AREA
] - (i
+ 1);
20014 it
->current_x
= x_before
;
20015 if (!FRAME_WINDOW_P (it
->f
))
20017 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
20019 row
->used
[TEXT_AREA
] = i
;
20020 produce_special_glyphs (it
, IT_TRUNCATION
);
20025 row
->used
[TEXT_AREA
] = i
;
20026 produce_special_glyphs (it
, IT_TRUNCATION
);
20029 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
20031 /* Don't truncate if we can overflow newline into fringe. */
20032 if (!get_next_display_element (it
))
20034 it
->continuation_lines_width
= 0;
20035 row
->ends_at_zv_p
= 1;
20036 row
->exact_window_width_line_p
= 1;
20039 if (ITERATOR_AT_END_OF_LINE_P (it
))
20041 row
->exact_window_width_line_p
= 1;
20042 goto at_end_of_line
;
20044 it
->current_x
= x_before
;
20047 row
->truncated_on_right_p
= 1;
20048 it
->continuation_lines_width
= 0;
20049 reseat_at_next_visible_line_start (it
, 0);
20050 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
20051 it
->hpos
= hpos_before
;
20057 bidi_unshelve_cache (wrap_data
, 1);
20059 /* If line is not empty and hscrolled, maybe insert truncation glyphs
20060 at the left window margin. */
20061 if (it
->first_visible_x
20062 && IT_CHARPOS (*it
) != CHARPOS (row
->start
.pos
))
20064 if (!FRAME_WINDOW_P (it
->f
)
20065 || (row
->reversed_p
20066 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
20067 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
20068 insert_left_trunc_glyphs (it
);
20069 row
->truncated_on_left_p
= 1;
20072 /* Remember the position at which this line ends.
20074 BIDI Note: any code that needs MATRIX_ROW_START/END_CHARPOS
20075 cannot be before the call to find_row_edges below, since that is
20076 where these positions are determined. */
20077 row
->end
= it
->current
;
20080 row
->minpos
= row
->start
.pos
;
20081 row
->maxpos
= row
->end
.pos
;
20085 /* ROW->minpos and ROW->maxpos must be the smallest and
20086 `1 + the largest' buffer positions in ROW. But if ROW was
20087 bidi-reordered, these two positions can be anywhere in the
20088 row, so we must determine them now. */
20089 find_row_edges (it
, row
, min_pos
, min_bpos
, max_pos
, max_bpos
);
20092 /* If the start of this line is the overlay arrow-position, then
20093 mark this glyph row as the one containing the overlay arrow.
20094 This is clearly a mess with variable size fonts. It would be
20095 better to let it be displayed like cursors under X. */
20096 if ((MATRIX_ROW_DISPLAYS_TEXT_P (row
) || !overlay_arrow_seen
)
20097 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
20098 !NILP (overlay_arrow_string
)))
20100 /* Overlay arrow in window redisplay is a fringe bitmap. */
20101 if (STRINGP (overlay_arrow_string
))
20103 struct glyph_row
*arrow_row
20104 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
20105 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
20106 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
20107 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
20108 struct glyph
*p2
, *end
;
20110 /* Copy the arrow glyphs. */
20111 while (glyph
< arrow_end
)
20114 /* Throw away padding glyphs. */
20116 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
20117 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
20123 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
20128 eassert (INTEGERP (overlay_arrow_string
));
20129 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
20131 overlay_arrow_seen
= 1;
20134 /* Highlight trailing whitespace. */
20135 if (!NILP (Vshow_trailing_whitespace
))
20136 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
20138 /* Compute pixel dimensions of this line. */
20139 compute_line_metrics (it
);
20141 /* Implementation note: No changes in the glyphs of ROW or in their
20142 faces can be done past this point, because compute_line_metrics
20143 computes ROW's hash value and stores it within the glyph_row
20146 /* Record whether this row ends inside an ellipsis. */
20147 row
->ends_in_ellipsis_p
20148 = (it
->method
== GET_FROM_DISPLAY_VECTOR
20149 && it
->ellipsis_p
);
20151 /* Save fringe bitmaps in this row. */
20152 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
20153 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
20154 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
20155 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
20157 it
->left_user_fringe_bitmap
= 0;
20158 it
->left_user_fringe_face_id
= 0;
20159 it
->right_user_fringe_bitmap
= 0;
20160 it
->right_user_fringe_face_id
= 0;
20162 /* Maybe set the cursor. */
20163 cvpos
= it
->w
->cursor
.vpos
;
20165 /* In bidi-reordered rows, keep checking for proper cursor
20166 position even if one has been found already, because buffer
20167 positions in such rows change non-linearly with ROW->VPOS,
20168 when a line is continued. One exception: when we are at ZV,
20169 display cursor on the first suitable glyph row, since all
20170 the empty rows after that also have their position set to ZV. */
20171 /* FIXME: Revisit this when glyph ``spilling'' in continuation
20172 lines' rows is implemented for bidi-reordered rows. */
20174 && !MATRIX_ROW (it
->w
->desired_matrix
, cvpos
)->ends_at_zv_p
))
20175 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
20176 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
20177 && cursor_row_p (row
))
20178 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
20180 /* Prepare for the next line. This line starts horizontally at (X
20181 HPOS) = (0 0). Vertical positions are incremented. As a
20182 convenience for the caller, IT->glyph_row is set to the next
20184 it
->current_x
= it
->hpos
= 0;
20185 it
->current_y
+= row
->height
;
20186 SET_TEXT_POS (it
->eol_pos
, 0, 0);
20189 /* The next row should by default use the same value of the
20190 reversed_p flag as this one. set_iterator_to_next decides when
20191 it's a new paragraph, and PRODUCE_GLYPHS recomputes the value of
20192 the flag accordingly. */
20193 if (it
->glyph_row
< MATRIX_BOTTOM_TEXT_ROW (it
->w
->desired_matrix
, it
->w
))
20194 it
->glyph_row
->reversed_p
= row
->reversed_p
;
20195 it
->start
= row
->end
;
20196 return MATRIX_ROW_DISPLAYS_TEXT_P (row
);
20198 #undef RECORD_MAX_MIN_POS
20201 DEFUN ("current-bidi-paragraph-direction", Fcurrent_bidi_paragraph_direction
,
20202 Scurrent_bidi_paragraph_direction
, 0, 1, 0,
20203 doc
: /* Return paragraph direction at point in BUFFER.
20204 Value is either `left-to-right' or `right-to-left'.
20205 If BUFFER is omitted or nil, it defaults to the current buffer.
20207 Paragraph direction determines how the text in the paragraph is displayed.
20208 In left-to-right paragraphs, text begins at the left margin of the window
20209 and the reading direction is generally left to right. In right-to-left
20210 paragraphs, text begins at the right margin and is read from right to left.
20212 See also `bidi-paragraph-direction'. */)
20213 (Lisp_Object buffer
)
20215 struct buffer
*buf
= current_buffer
;
20216 struct buffer
*old
= buf
;
20218 if (! NILP (buffer
))
20220 CHECK_BUFFER (buffer
);
20221 buf
= XBUFFER (buffer
);
20224 if (NILP (BVAR (buf
, bidi_display_reordering
))
20225 || NILP (BVAR (buf
, enable_multibyte_characters
))
20226 /* When we are loading loadup.el, the character property tables
20227 needed for bidi iteration are not yet available. */
20228 || !NILP (Vpurify_flag
))
20229 return Qleft_to_right
;
20230 else if (!NILP (BVAR (buf
, bidi_paragraph_direction
)))
20231 return BVAR (buf
, bidi_paragraph_direction
);
20234 /* Determine the direction from buffer text. We could try to
20235 use current_matrix if it is up to date, but this seems fast
20236 enough as it is. */
20237 struct bidi_it itb
;
20238 ptrdiff_t pos
= BUF_PT (buf
);
20239 ptrdiff_t bytepos
= BUF_PT_BYTE (buf
);
20241 void *itb_data
= bidi_shelve_cache ();
20243 set_buffer_temp (buf
);
20244 /* bidi_paragraph_init finds the base direction of the paragraph
20245 by searching forward from paragraph start. We need the base
20246 direction of the current or _previous_ paragraph, so we need
20247 to make sure we are within that paragraph. To that end, find
20248 the previous non-empty line. */
20249 if (pos
>= ZV
&& pos
> BEGV
)
20250 DEC_BOTH (pos
, bytepos
);
20251 if (fast_looking_at (build_string ("[\f\t ]*\n"),
20252 pos
, bytepos
, ZV
, ZV_BYTE
, Qnil
) > 0)
20254 while ((c
= FETCH_BYTE (bytepos
)) == '\n'
20255 || c
== ' ' || c
== '\t' || c
== '\f')
20257 if (bytepos
<= BEGV_BYTE
)
20262 while (!CHAR_HEAD_P (FETCH_BYTE (bytepos
)))
20265 bidi_init_it (pos
, bytepos
, FRAME_WINDOW_P (SELECTED_FRAME ()), &itb
);
20266 itb
.paragraph_dir
= NEUTRAL_DIR
;
20267 itb
.string
.s
= NULL
;
20268 itb
.string
.lstring
= Qnil
;
20269 itb
.string
.bufpos
= 0;
20270 itb
.string
.unibyte
= 0;
20271 /* We have no window to use here for ignoring window-specific
20272 overlays. Using NULL for window pointer will cause
20273 compute_display_string_pos to use the current buffer. */
20275 bidi_paragraph_init (NEUTRAL_DIR
, &itb
, 1);
20276 bidi_unshelve_cache (itb_data
, 0);
20277 set_buffer_temp (old
);
20278 switch (itb
.paragraph_dir
)
20281 return Qleft_to_right
;
20284 return Qright_to_left
;
20292 DEFUN ("move-point-visually", Fmove_point_visually
,
20293 Smove_point_visually
, 1, 1, 0,
20294 doc
: /* Move point in the visual order in the specified DIRECTION.
20295 DIRECTION can be 1, meaning move to the right, or -1, which moves to the
20298 Value is the new character position of point. */)
20299 (Lisp_Object direction
)
20301 struct window
*w
= XWINDOW (selected_window
);
20302 struct buffer
*b
= XBUFFER (w
->contents
);
20303 struct glyph_row
*row
;
20305 Lisp_Object paragraph_dir
;
20307 #define ROW_GLYPH_NEWLINE_P(ROW,GLYPH) \
20308 (!(ROW)->continued_p \
20309 && INTEGERP ((GLYPH)->object) \
20310 && (GLYPH)->type == CHAR_GLYPH \
20311 && (GLYPH)->u.ch == ' ' \
20312 && (GLYPH)->charpos >= 0 \
20313 && !(GLYPH)->avoid_cursor_p)
20315 CHECK_NUMBER (direction
);
20316 dir
= XINT (direction
);
20322 /* If current matrix is up-to-date, we can use the information
20323 recorded in the glyphs, at least as long as the goal is on the
20325 if (w
->window_end_valid
20326 && !windows_or_buffers_changed
20328 && !b
->clip_changed
20329 && !b
->prevent_redisplay_optimizations_p
20330 && !window_outdated (w
)
20331 && w
->cursor
.vpos
>= 0
20332 && w
->cursor
.vpos
< w
->current_matrix
->nrows
20333 && (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
))->enabled_p
)
20335 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
20336 struct glyph
*e
= dir
> 0 ? g
+ row
->used
[TEXT_AREA
] : g
- 1;
20337 struct glyph
*gpt
= g
+ w
->cursor
.hpos
;
20339 for (g
= gpt
+ dir
; (dir
> 0 ? g
< e
: g
> e
); g
+= dir
)
20341 if (BUFFERP (g
->object
) && g
->charpos
!= PT
)
20343 SET_PT (g
->charpos
);
20344 w
->cursor
.vpos
= -1;
20345 return make_number (PT
);
20347 else if (!INTEGERP (g
->object
) && !EQ (g
->object
, gpt
->object
))
20351 if (BUFFERP (gpt
->object
))
20354 if ((gpt
->resolved_level
- row
->reversed_p
) % 2 == 0)
20355 new_pos
+= (row
->reversed_p
? -dir
: dir
);
20357 new_pos
-= (row
->reversed_p
? -dir
: dir
);;
20359 else if (BUFFERP (g
->object
))
20360 new_pos
= g
->charpos
;
20364 w
->cursor
.vpos
= -1;
20365 return make_number (PT
);
20367 else if (ROW_GLYPH_NEWLINE_P (row
, g
))
20369 /* Glyphs inserted at the end of a non-empty line for
20370 positioning the cursor have zero charpos, so we must
20371 deduce the value of point by other means. */
20372 if (g
->charpos
> 0)
20373 SET_PT (g
->charpos
);
20374 else if (row
->ends_at_zv_p
&& PT
!= ZV
)
20376 else if (PT
!= MATRIX_ROW_END_CHARPOS (row
) - 1)
20377 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
20380 w
->cursor
.vpos
= -1;
20381 return make_number (PT
);
20384 if (g
== e
|| INTEGERP (g
->object
))
20386 if (row
->truncated_on_left_p
|| row
->truncated_on_right_p
)
20387 goto simulate_display
;
20388 if (!row
->reversed_p
)
20392 if (row
< MATRIX_FIRST_TEXT_ROW (w
->current_matrix
)
20393 || row
> MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
20394 goto simulate_display
;
20398 if (row
->reversed_p
&& !row
->continued_p
)
20400 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
20401 w
->cursor
.vpos
= -1;
20402 return make_number (PT
);
20404 g
= row
->glyphs
[TEXT_AREA
];
20405 e
= g
+ row
->used
[TEXT_AREA
];
20406 for ( ; g
< e
; g
++)
20408 if (BUFFERP (g
->object
)
20409 /* Empty lines have only one glyph, which stands
20410 for the newline, and whose charpos is the
20411 buffer position of the newline. */
20412 || ROW_GLYPH_NEWLINE_P (row
, g
)
20413 /* When the buffer ends in a newline, the line at
20414 EOB also has one glyph, but its charpos is -1. */
20415 || (row
->ends_at_zv_p
20416 && !row
->reversed_p
20417 && INTEGERP (g
->object
)
20418 && g
->type
== CHAR_GLYPH
20419 && g
->u
.ch
== ' '))
20421 if (g
->charpos
> 0)
20422 SET_PT (g
->charpos
);
20423 else if (!row
->reversed_p
20424 && row
->ends_at_zv_p
20429 w
->cursor
.vpos
= -1;
20430 return make_number (PT
);
20436 if (!row
->reversed_p
&& !row
->continued_p
)
20438 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
20439 w
->cursor
.vpos
= -1;
20440 return make_number (PT
);
20442 e
= row
->glyphs
[TEXT_AREA
];
20443 g
= e
+ row
->used
[TEXT_AREA
] - 1;
20444 for ( ; g
>= e
; g
--)
20446 if (BUFFERP (g
->object
)
20447 || (ROW_GLYPH_NEWLINE_P (row
, g
)
20449 /* Empty R2L lines on GUI frames have the buffer
20450 position of the newline stored in the stretch
20452 || g
->type
== STRETCH_GLYPH
20453 || (row
->ends_at_zv_p
20455 && INTEGERP (g
->object
)
20456 && g
->type
== CHAR_GLYPH
20457 && g
->u
.ch
== ' '))
20459 if (g
->charpos
> 0)
20460 SET_PT (g
->charpos
);
20461 else if (row
->reversed_p
20462 && row
->ends_at_zv_p
20467 w
->cursor
.vpos
= -1;
20468 return make_number (PT
);
20477 /* If we wind up here, we failed to move by using the glyphs, so we
20478 need to simulate display instead. */
20481 paragraph_dir
= Fcurrent_bidi_paragraph_direction (w
->contents
);
20483 paragraph_dir
= Qleft_to_right
;
20484 if (EQ (paragraph_dir
, Qright_to_left
))
20486 if (PT
<= BEGV
&& dir
< 0)
20487 xsignal0 (Qbeginning_of_buffer
);
20488 else if (PT
>= ZV
&& dir
> 0)
20489 xsignal0 (Qend_of_buffer
);
20492 struct text_pos pt
;
20494 int pt_x
, target_x
, pixel_width
, pt_vpos
;
20496 bool overshoot_expected
= false;
20497 bool target_is_eol_p
= false;
20499 /* Setup the arena. */
20500 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
20501 start_display (&it
, w
, pt
);
20503 if (it
.cmp_it
.id
< 0
20504 && it
.method
== GET_FROM_STRING
20505 && it
.area
== TEXT_AREA
20506 && it
.string_from_display_prop_p
20507 && (it
.sp
> 0 && it
.stack
[it
.sp
- 1].method
== GET_FROM_BUFFER
))
20508 overshoot_expected
= true;
20510 /* Find the X coordinate of point. We start from the beginning
20511 of this or previous line to make sure we are before point in
20512 the logical order (since the move_it_* functions can only
20514 reseat_at_previous_visible_line_start (&it
);
20515 it
.current_x
= it
.hpos
= it
.current_y
= it
.vpos
= 0;
20516 if (IT_CHARPOS (it
) != PT
)
20517 move_it_to (&it
, overshoot_expected
? PT
- 1 : PT
,
20518 -1, -1, -1, MOVE_TO_POS
);
20519 pt_x
= it
.current_x
;
20521 if (dir
> 0 || overshoot_expected
)
20523 struct glyph_row
*row
= it
.glyph_row
;
20525 /* When point is at beginning of line, we don't have
20526 information about the glyph there loaded into struct
20527 it. Calling get_next_display_element fixes that. */
20529 get_next_display_element (&it
);
20530 at_eol_p
= ITERATOR_AT_END_OF_LINE_P (&it
);
20531 it
.glyph_row
= NULL
;
20532 PRODUCE_GLYPHS (&it
); /* compute it.pixel_width */
20533 it
.glyph_row
= row
;
20534 /* PRODUCE_GLYPHS advances it.current_x, so we must restore
20535 it, lest it will become out of sync with it's buffer
20537 it
.current_x
= pt_x
;
20540 at_eol_p
= ITERATOR_AT_END_OF_LINE_P (&it
);
20541 pixel_width
= it
.pixel_width
;
20542 if (overshoot_expected
&& at_eol_p
)
20544 else if (pixel_width
<= 0)
20547 /* If there's a display string at point, we are actually at the
20548 glyph to the left of point, so we need to correct the X
20550 if (overshoot_expected
)
20551 pt_x
+= pixel_width
;
20553 /* Compute target X coordinate, either to the left or to the
20554 right of point. On TTY frames, all characters have the same
20555 pixel width of 1, so we can use that. On GUI frames we don't
20556 have an easy way of getting at the pixel width of the
20557 character to the left of point, so we use a different method
20558 of getting to that place. */
20560 target_x
= pt_x
+ pixel_width
;
20562 target_x
= pt_x
- (!FRAME_WINDOW_P (it
.f
)) * pixel_width
;
20564 /* Target X coordinate could be one line above or below the line
20565 of point, in which case we need to adjust the target X
20566 coordinate. Also, if moving to the left, we need to begin at
20567 the left edge of the point's screen line. */
20572 start_display (&it
, w
, pt
);
20573 reseat_at_previous_visible_line_start (&it
);
20574 it
.current_x
= it
.current_y
= it
.hpos
= 0;
20576 move_it_by_lines (&it
, pt_vpos
);
20580 move_it_by_lines (&it
, -1);
20581 target_x
= it
.last_visible_x
- !FRAME_WINDOW_P (it
.f
);
20582 target_is_eol_p
= true;
20588 || (target_x
>= it
.last_visible_x
20589 && it
.line_wrap
!= TRUNCATE
))
20592 move_it_by_lines (&it
, 0);
20593 move_it_by_lines (&it
, 1);
20598 /* Move to the target X coordinate. */
20599 #ifdef HAVE_WINDOW_SYSTEM
20600 /* On GUI frames, as we don't know the X coordinate of the
20601 character to the left of point, moving point to the left
20602 requires walking, one grapheme cluster at a time, until we
20603 find ourself at a place immediately to the left of the
20604 character at point. */
20605 if (FRAME_WINDOW_P (it
.f
) && dir
< 0)
20607 struct text_pos new_pos
= it
.current
.pos
;
20608 enum move_it_result rc
= MOVE_X_REACHED
;
20610 while (it
.current_x
+ it
.pixel_width
<= target_x
20611 && rc
== MOVE_X_REACHED
)
20613 int new_x
= it
.current_x
+ it
.pixel_width
;
20615 new_pos
= it
.current
.pos
;
20616 if (new_x
== it
.current_x
)
20618 rc
= move_it_in_display_line_to (&it
, ZV
, new_x
,
20619 MOVE_TO_POS
| MOVE_TO_X
);
20620 if (ITERATOR_AT_END_OF_LINE_P (&it
) && !target_is_eol_p
)
20623 /* If we ended up on a composed character inside
20624 bidi-reordered text (e.g., Hebrew text with diacritics),
20625 the iterator gives us the buffer position of the last (in
20626 logical order) character of the composed grapheme cluster,
20627 which is not what we want. So we cheat: we compute the
20628 character position of the character that follows (in the
20629 logical order) the one where the above loop stopped. That
20630 character will appear on display to the left of point. */
20632 && it
.bidi_it
.scan_dir
== -1
20633 && new_pos
.charpos
- IT_CHARPOS (it
) > 1)
20635 new_pos
.charpos
= IT_CHARPOS (it
) + 1;
20636 new_pos
.bytepos
= CHAR_TO_BYTE (new_pos
.charpos
);
20638 it
.current
.pos
= new_pos
;
20642 if (it
.current_x
!= target_x
)
20643 move_it_in_display_line_to (&it
, ZV
, target_x
, MOVE_TO_POS
| MOVE_TO_X
);
20645 /* When lines are truncated, the above loop will stop at the
20646 window edge. But we want to get to the end of line, even if
20647 it is beyond the window edge; automatic hscroll will then
20648 scroll the window to show point as appropriate. */
20649 if (target_is_eol_p
&& it
.line_wrap
== TRUNCATE
20650 && get_next_display_element (&it
))
20652 struct text_pos new_pos
= it
.current
.pos
;
20654 while (!ITERATOR_AT_END_OF_LINE_P (&it
))
20656 set_iterator_to_next (&it
, 0);
20657 if (it
.method
== GET_FROM_BUFFER
)
20658 new_pos
= it
.current
.pos
;
20659 if (!get_next_display_element (&it
))
20663 it
.current
.pos
= new_pos
;
20666 /* If we ended up in a display string that covers point, move to
20667 buffer position to the right in the visual order. */
20670 while (IT_CHARPOS (it
) == PT
)
20672 set_iterator_to_next (&it
, 0);
20673 if (!get_next_display_element (&it
))
20678 /* Move point to that position. */
20679 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
20682 return make_number (PT
);
20684 #undef ROW_GLYPH_NEWLINE_P
20688 /***********************************************************************
20690 ***********************************************************************/
20692 /* Redisplay the menu bar in the frame for window W.
20694 The menu bar of X frames that don't have X toolkit support is
20695 displayed in a special window W->frame->menu_bar_window.
20697 The menu bar of terminal frames is treated specially as far as
20698 glyph matrices are concerned. Menu bar lines are not part of
20699 windows, so the update is done directly on the frame matrix rows
20700 for the menu bar. */
20703 display_menu_bar (struct window
*w
)
20705 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20710 /* Don't do all this for graphical frames. */
20712 if (FRAME_W32_P (f
))
20715 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
20721 if (FRAME_NS_P (f
))
20723 #endif /* HAVE_NS */
20725 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
20726 eassert (!FRAME_WINDOW_P (f
));
20727 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
20728 it
.first_visible_x
= 0;
20729 /* PXW: Use FRAME_PIXEL_WIDTH (f) here ? */
20730 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
20731 #elif defined (HAVE_X_WINDOWS) /* X without toolkit. */
20732 if (FRAME_WINDOW_P (f
))
20734 /* Menu bar lines are displayed in the desired matrix of the
20735 dummy window menu_bar_window. */
20736 struct window
*menu_w
;
20737 menu_w
= XWINDOW (f
->menu_bar_window
);
20738 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
20740 it
.first_visible_x
= 0;
20741 /* PXW: Use FRAME_PIXEL_WIDTH (f) here ? */
20742 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
20745 #endif /* not USE_X_TOOLKIT and not USE_GTK */
20747 /* This is a TTY frame, i.e. character hpos/vpos are used as
20749 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
20751 it
.first_visible_x
= 0;
20752 it
.last_visible_x
= FRAME_COLS (f
);
20755 /* FIXME: This should be controlled by a user option. See the
20756 comments in redisplay_tool_bar and display_mode_line about
20758 it
.paragraph_embedding
= L2R
;
20760 /* Clear all rows of the menu bar. */
20761 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
20763 struct glyph_row
*row
= it
.glyph_row
+ i
;
20764 clear_glyph_row (row
);
20765 row
->enabled_p
= 1;
20766 row
->full_width_p
= 1;
20769 /* Display all items of the menu bar. */
20770 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
20771 for (i
= 0; i
< ASIZE (items
); i
+= 4)
20773 Lisp_Object string
;
20775 /* Stop at nil string. */
20776 string
= AREF (items
, i
+ 1);
20780 /* Remember where item was displayed. */
20781 ASET (items
, i
+ 3, make_number (it
.hpos
));
20783 /* Display the item, pad with one space. */
20784 if (it
.current_x
< it
.last_visible_x
)
20785 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
20786 SCHARS (string
) + 1, 0, 0, -1);
20789 /* Fill out the line with spaces. */
20790 if (it
.current_x
< it
.last_visible_x
)
20791 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
20793 /* Compute the total height of the lines. */
20794 compute_line_metrics (&it
);
20797 /* Deep copy of a glyph row, including the glyphs. */
20799 deep_copy_glyph_row (struct glyph_row
*to
, struct glyph_row
*from
)
20801 struct glyph
*pointers
[1 + LAST_AREA
];
20802 int to_used
= to
->used
[TEXT_AREA
];
20804 /* Save glyph pointers of TO. */
20805 memcpy (pointers
, to
->glyphs
, sizeof to
->glyphs
);
20807 /* Do a structure assignment. */
20810 /* Restore original glyph pointers of TO. */
20811 memcpy (to
->glyphs
, pointers
, sizeof to
->glyphs
);
20813 /* Copy the glyphs. */
20814 memcpy (to
->glyphs
[TEXT_AREA
], from
->glyphs
[TEXT_AREA
],
20815 min (from
->used
[TEXT_AREA
], to_used
) * sizeof (struct glyph
));
20817 /* If we filled only part of the TO row, fill the rest with
20818 space_glyph (which will display as empty space). */
20819 if (to_used
> from
->used
[TEXT_AREA
])
20820 fill_up_frame_row_with_spaces (to
, to_used
);
20823 /* Display one menu item on a TTY, by overwriting the glyphs in the
20824 frame F's desired glyph matrix with glyphs produced from the menu
20825 item text. Called from term.c to display TTY drop-down menus one
20828 ITEM_TEXT is the menu item text as a C string.
20830 FACE_ID is the face ID to be used for this menu item. FACE_ID
20831 could specify one of 3 faces: a face for an enabled item, a face
20832 for a disabled item, or a face for a selected item.
20834 X and Y are coordinates of the first glyph in the frame's desired
20835 matrix to be overwritten by the menu item. Since this is a TTY, Y
20836 is the zero-based number of the glyph row and X is the zero-based
20837 glyph number in the row, starting from left, where to start
20838 displaying the item.
20840 SUBMENU non-zero means this menu item drops down a submenu, which
20841 should be indicated by displaying a proper visual cue after the
20845 display_tty_menu_item (const char *item_text
, int width
, int face_id
,
20846 int x
, int y
, int submenu
)
20849 struct frame
*f
= SELECTED_FRAME ();
20850 struct window
*w
= XWINDOW (f
->selected_window
);
20851 int saved_used
, saved_truncated
, saved_width
, saved_reversed
;
20852 struct glyph_row
*row
;
20853 size_t item_len
= strlen (item_text
);
20855 eassert (FRAME_TERMCAP_P (f
));
20857 /* Don't write beyond the matrix's last row. This can happen for
20858 TTY screens that are not high enough to show the entire menu.
20859 (This is actually a bit of defensive programming, as
20860 tty_menu_display already limits the number of menu items to one
20861 less than the number of screen lines.) */
20862 if (y
>= f
->desired_matrix
->nrows
)
20865 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
+ y
, MENU_FACE_ID
);
20866 it
.first_visible_x
= 0;
20867 it
.last_visible_x
= FRAME_COLS (f
) - 1;
20868 row
= it
.glyph_row
;
20869 /* Start with the row contents from the current matrix. */
20870 deep_copy_glyph_row (row
, f
->current_matrix
->rows
+ y
);
20871 saved_width
= row
->full_width_p
;
20872 row
->full_width_p
= 1;
20873 saved_reversed
= row
->reversed_p
;
20874 row
->reversed_p
= 0;
20875 row
->enabled_p
= 1;
20877 /* Arrange for the menu item glyphs to start at (X,Y) and have the
20879 eassert (x
< f
->desired_matrix
->matrix_w
);
20880 it
.current_x
= it
.hpos
= x
;
20881 it
.current_y
= it
.vpos
= y
;
20882 saved_used
= row
->used
[TEXT_AREA
];
20883 saved_truncated
= row
->truncated_on_right_p
;
20884 row
->used
[TEXT_AREA
] = x
;
20885 it
.face_id
= face_id
;
20886 it
.line_wrap
= TRUNCATE
;
20888 /* FIXME: This should be controlled by a user option. See the
20889 comments in redisplay_tool_bar and display_mode_line about this.
20890 Also, if paragraph_embedding could ever be R2L, changes will be
20891 needed to avoid shifting to the right the row characters in
20892 term.c:append_glyph. */
20893 it
.paragraph_embedding
= L2R
;
20895 /* Pad with a space on the left. */
20896 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 1, 0, FRAME_COLS (f
) - 1, -1);
20898 /* Display the menu item, pad with spaces to WIDTH. */
20901 display_string (item_text
, Qnil
, Qnil
, 0, 0, &it
,
20902 item_len
, 0, FRAME_COLS (f
) - 1, -1);
20904 /* Indicate with " >" that there's a submenu. */
20905 display_string (" >", Qnil
, Qnil
, 0, 0, &it
, width
, 0,
20906 FRAME_COLS (f
) - 1, -1);
20909 display_string (item_text
, Qnil
, Qnil
, 0, 0, &it
,
20910 width
, 0, FRAME_COLS (f
) - 1, -1);
20912 row
->used
[TEXT_AREA
] = max (saved_used
, row
->used
[TEXT_AREA
]);
20913 row
->truncated_on_right_p
= saved_truncated
;
20914 row
->hash
= row_hash (row
);
20915 row
->full_width_p
= saved_width
;
20916 row
->reversed_p
= saved_reversed
;
20919 /***********************************************************************
20921 ***********************************************************************/
20923 /* Redisplay mode lines in the window tree whose root is WINDOW. If
20924 FORCE is non-zero, redisplay mode lines unconditionally.
20925 Otherwise, redisplay only mode lines that are garbaged. Value is
20926 the number of windows whose mode lines were redisplayed. */
20929 redisplay_mode_lines (Lisp_Object window
, bool force
)
20933 while (!NILP (window
))
20935 struct window
*w
= XWINDOW (window
);
20937 if (WINDOWP (w
->contents
))
20938 nwindows
+= redisplay_mode_lines (w
->contents
, force
);
20940 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
20941 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
20943 struct text_pos lpoint
;
20944 struct buffer
*old
= current_buffer
;
20946 /* Set the window's buffer for the mode line display. */
20947 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
20948 set_buffer_internal_1 (XBUFFER (w
->contents
));
20950 /* Point refers normally to the selected window. For any
20951 other window, set up appropriate value. */
20952 if (!EQ (window
, selected_window
))
20954 struct text_pos pt
;
20956 CLIP_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
20957 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
20960 /* Display mode lines. */
20961 clear_glyph_matrix (w
->desired_matrix
);
20962 if (display_mode_lines (w
))
20965 /* Restore old settings. */
20966 set_buffer_internal_1 (old
);
20967 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
20977 /* Display the mode and/or header line of window W. Value is the
20978 sum number of mode lines and header lines displayed. */
20981 display_mode_lines (struct window
*w
)
20983 Lisp_Object old_selected_window
= selected_window
;
20984 Lisp_Object old_selected_frame
= selected_frame
;
20985 Lisp_Object new_frame
= w
->frame
;
20986 Lisp_Object old_frame_selected_window
= XFRAME (new_frame
)->selected_window
;
20989 selected_frame
= new_frame
;
20990 /* FIXME: If we were to allow the mode-line's computation changing the buffer
20991 or window's point, then we'd need select_window_1 here as well. */
20992 XSETWINDOW (selected_window
, w
);
20993 XFRAME (new_frame
)->selected_window
= selected_window
;
20995 /* These will be set while the mode line specs are processed. */
20996 line_number_displayed
= 0;
20997 w
->column_number_displayed
= -1;
20999 if (WINDOW_WANTS_MODELINE_P (w
))
21001 struct window
*sel_w
= XWINDOW (old_selected_window
);
21003 /* Select mode line face based on the real selected window. */
21004 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
21005 BVAR (current_buffer
, mode_line_format
));
21009 if (WINDOW_WANTS_HEADER_LINE_P (w
))
21011 display_mode_line (w
, HEADER_LINE_FACE_ID
,
21012 BVAR (current_buffer
, header_line_format
));
21016 XFRAME (new_frame
)->selected_window
= old_frame_selected_window
;
21017 selected_frame
= old_selected_frame
;
21018 selected_window
= old_selected_window
;
21020 w
->must_be_updated_p
= true;
21025 /* Display mode or header line of window W. FACE_ID specifies which
21026 line to display; it is either MODE_LINE_FACE_ID or
21027 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
21028 display. Value is the pixel height of the mode/header line
21032 display_mode_line (struct window
*w
, enum face_id face_id
, Lisp_Object format
)
21036 ptrdiff_t count
= SPECPDL_INDEX ();
21038 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
21039 /* Don't extend on a previously drawn mode-line.
21040 This may happen if called from pos_visible_p. */
21041 it
.glyph_row
->enabled_p
= 0;
21042 prepare_desired_row (it
.glyph_row
);
21044 it
.glyph_row
->mode_line_p
= 1;
21046 /* FIXME: This should be controlled by a user option. But
21047 supporting such an option is not trivial, since the mode line is
21048 made up of many separate strings. */
21049 it
.paragraph_embedding
= L2R
;
21051 record_unwind_protect (unwind_format_mode_line
,
21052 format_mode_line_unwind_data (NULL
, NULL
, Qnil
, 0));
21054 mode_line_target
= MODE_LINE_DISPLAY
;
21056 /* Temporarily make frame's keyboard the current kboard so that
21057 kboard-local variables in the mode_line_format will get the right
21059 push_kboard (FRAME_KBOARD (it
.f
));
21060 record_unwind_save_match_data ();
21061 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
21064 unbind_to (count
, Qnil
);
21066 /* Fill up with spaces. */
21067 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
21069 compute_line_metrics (&it
);
21070 it
.glyph_row
->full_width_p
= 1;
21071 it
.glyph_row
->continued_p
= 0;
21072 it
.glyph_row
->truncated_on_left_p
= 0;
21073 it
.glyph_row
->truncated_on_right_p
= 0;
21075 /* Make a 3D mode-line have a shadow at its right end. */
21076 face
= FACE_FROM_ID (it
.f
, face_id
);
21077 extend_face_to_end_of_line (&it
);
21078 if (face
->box
!= FACE_NO_BOX
)
21080 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
21081 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
21082 last
->right_box_line_p
= 1;
21085 return it
.glyph_row
->height
;
21088 /* Move element ELT in LIST to the front of LIST.
21089 Return the updated list. */
21092 move_elt_to_front (Lisp_Object elt
, Lisp_Object list
)
21094 register Lisp_Object tail
, prev
;
21095 register Lisp_Object tem
;
21099 while (CONSP (tail
))
21105 /* Splice out the link TAIL. */
21107 list
= XCDR (tail
);
21109 Fsetcdr (prev
, XCDR (tail
));
21111 /* Now make it the first. */
21112 Fsetcdr (tail
, list
);
21117 tail
= XCDR (tail
);
21121 /* Not found--return unchanged LIST. */
21125 /* Contribute ELT to the mode line for window IT->w. How it
21126 translates into text depends on its data type.
21128 IT describes the display environment in which we display, as usual.
21130 DEPTH is the depth in recursion. It is used to prevent
21131 infinite recursion here.
21133 FIELD_WIDTH is the number of characters the display of ELT should
21134 occupy in the mode line, and PRECISION is the maximum number of
21135 characters to display from ELT's representation. See
21136 display_string for details.
21138 Returns the hpos of the end of the text generated by ELT.
21140 PROPS is a property list to add to any string we encounter.
21142 If RISKY is nonzero, remove (disregard) any properties in any string
21143 we encounter, and ignore :eval and :propertize.
21145 The global variable `mode_line_target' determines whether the
21146 output is passed to `store_mode_line_noprop',
21147 `store_mode_line_string', or `display_string'. */
21150 display_mode_element (struct it
*it
, int depth
, int field_width
, int precision
,
21151 Lisp_Object elt
, Lisp_Object props
, int risky
)
21153 int n
= 0, field
, prec
;
21158 elt
= build_string ("*too-deep*");
21162 switch (XTYPE (elt
))
21166 /* A string: output it and check for %-constructs within it. */
21168 ptrdiff_t offset
= 0;
21170 if (SCHARS (elt
) > 0
21171 && (!NILP (props
) || risky
))
21173 Lisp_Object oprops
, aelt
;
21174 oprops
= Ftext_properties_at (make_number (0), elt
);
21176 /* If the starting string's properties are not what
21177 we want, translate the string. Also, if the string
21178 is risky, do that anyway. */
21180 if (NILP (Fequal (props
, oprops
)) || risky
)
21182 /* If the starting string has properties,
21183 merge the specified ones onto the existing ones. */
21184 if (! NILP (oprops
) && !risky
)
21188 oprops
= Fcopy_sequence (oprops
);
21190 while (CONSP (tem
))
21192 oprops
= Fplist_put (oprops
, XCAR (tem
),
21193 XCAR (XCDR (tem
)));
21194 tem
= XCDR (XCDR (tem
));
21199 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
21200 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
21202 /* AELT is what we want. Move it to the front
21203 without consing. */
21205 mode_line_proptrans_alist
21206 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
21212 /* If AELT has the wrong props, it is useless.
21213 so get rid of it. */
21215 mode_line_proptrans_alist
21216 = Fdelq (aelt
, mode_line_proptrans_alist
);
21218 elt
= Fcopy_sequence (elt
);
21219 Fset_text_properties (make_number (0), Flength (elt
),
21221 /* Add this item to mode_line_proptrans_alist. */
21222 mode_line_proptrans_alist
21223 = Fcons (Fcons (elt
, props
),
21224 mode_line_proptrans_alist
);
21225 /* Truncate mode_line_proptrans_alist
21226 to at most 50 elements. */
21227 tem
= Fnthcdr (make_number (50),
21228 mode_line_proptrans_alist
);
21230 XSETCDR (tem
, Qnil
);
21239 prec
= precision
- n
;
21240 switch (mode_line_target
)
21242 case MODE_LINE_NOPROP
:
21243 case MODE_LINE_TITLE
:
21244 n
+= store_mode_line_noprop (SSDATA (elt
), -1, prec
);
21246 case MODE_LINE_STRING
:
21247 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
21249 case MODE_LINE_DISPLAY
:
21250 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
21251 0, prec
, 0, STRING_MULTIBYTE (elt
));
21258 /* Handle the non-literal case. */
21260 while ((precision
<= 0 || n
< precision
)
21261 && SREF (elt
, offset
) != 0
21262 && (mode_line_target
!= MODE_LINE_DISPLAY
21263 || it
->current_x
< it
->last_visible_x
))
21265 ptrdiff_t last_offset
= offset
;
21267 /* Advance to end of string or next format specifier. */
21268 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
21271 if (offset
- 1 != last_offset
)
21273 ptrdiff_t nchars
, nbytes
;
21275 /* Output to end of string or up to '%'. Field width
21276 is length of string. Don't output more than
21277 PRECISION allows us. */
21280 prec
= c_string_width (SDATA (elt
) + last_offset
,
21281 offset
- last_offset
, precision
- n
,
21284 switch (mode_line_target
)
21286 case MODE_LINE_NOPROP
:
21287 case MODE_LINE_TITLE
:
21288 n
+= store_mode_line_noprop (SSDATA (elt
) + last_offset
, 0, prec
);
21290 case MODE_LINE_STRING
:
21292 ptrdiff_t bytepos
= last_offset
;
21293 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
21294 ptrdiff_t endpos
= (precision
<= 0
21295 ? string_byte_to_char (elt
, offset
)
21296 : charpos
+ nchars
);
21298 n
+= store_mode_line_string (NULL
,
21299 Fsubstring (elt
, make_number (charpos
),
21300 make_number (endpos
)),
21304 case MODE_LINE_DISPLAY
:
21306 ptrdiff_t bytepos
= last_offset
;
21307 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
21309 if (precision
<= 0)
21310 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
21311 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
21313 STRING_MULTIBYTE (elt
));
21318 else /* c == '%' */
21320 ptrdiff_t percent_position
= offset
;
21322 /* Get the specified minimum width. Zero means
21325 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
21326 field
= field
* 10 + c
- '0';
21328 /* Don't pad beyond the total padding allowed. */
21329 if (field_width
- n
> 0 && field
> field_width
- n
)
21330 field
= field_width
- n
;
21332 /* Note that either PRECISION <= 0 or N < PRECISION. */
21333 prec
= precision
- n
;
21336 n
+= display_mode_element (it
, depth
, field
, prec
,
21337 Vglobal_mode_string
, props
,
21342 ptrdiff_t bytepos
, charpos
;
21344 Lisp_Object string
;
21346 bytepos
= percent_position
;
21347 charpos
= (STRING_MULTIBYTE (elt
)
21348 ? string_byte_to_char (elt
, bytepos
)
21350 spec
= decode_mode_spec (it
->w
, c
, field
, &string
);
21351 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
21353 switch (mode_line_target
)
21355 case MODE_LINE_NOPROP
:
21356 case MODE_LINE_TITLE
:
21357 n
+= store_mode_line_noprop (spec
, field
, prec
);
21359 case MODE_LINE_STRING
:
21361 Lisp_Object tem
= build_string (spec
);
21362 props
= Ftext_properties_at (make_number (charpos
), elt
);
21363 /* Should only keep face property in props */
21364 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
21367 case MODE_LINE_DISPLAY
:
21369 int nglyphs_before
, nwritten
;
21371 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
21372 nwritten
= display_string (spec
, string
, elt
,
21377 /* Assign to the glyphs written above the
21378 string where the `%x' came from, position
21382 struct glyph
*glyph
21383 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
21387 for (i
= 0; i
< nwritten
; ++i
)
21389 glyph
[i
].object
= elt
;
21390 glyph
[i
].charpos
= charpos
;
21407 /* A symbol: process the value of the symbol recursively
21408 as if it appeared here directly. Avoid error if symbol void.
21409 Special case: if value of symbol is a string, output the string
21412 register Lisp_Object tem
;
21414 /* If the variable is not marked as risky to set
21415 then its contents are risky to use. */
21416 if (NILP (Fget (elt
, Qrisky_local_variable
)))
21419 tem
= Fboundp (elt
);
21422 tem
= Fsymbol_value (elt
);
21423 /* If value is a string, output that string literally:
21424 don't check for % within it. */
21428 if (!EQ (tem
, elt
))
21430 /* Give up right away for nil or t. */
21440 register Lisp_Object car
, tem
;
21442 /* A cons cell: five distinct cases.
21443 If first element is :eval or :propertize, do something special.
21444 If first element is a string or a cons, process all the elements
21445 and effectively concatenate them.
21446 If first element is a negative number, truncate displaying cdr to
21447 at most that many characters. If positive, pad (with spaces)
21448 to at least that many characters.
21449 If first element is a symbol, process the cadr or caddr recursively
21450 according to whether the symbol's value is non-nil or nil. */
21452 if (EQ (car
, QCeval
))
21454 /* An element of the form (:eval FORM) means evaluate FORM
21455 and use the result as mode line elements. */
21460 if (CONSP (XCDR (elt
)))
21463 spec
= safe_eval (XCAR (XCDR (elt
)));
21464 n
+= display_mode_element (it
, depth
, field_width
- n
,
21465 precision
- n
, spec
, props
,
21469 else if (EQ (car
, QCpropertize
))
21471 /* An element of the form (:propertize ELT PROPS...)
21472 means display ELT but applying properties PROPS. */
21477 if (CONSP (XCDR (elt
)))
21478 n
+= display_mode_element (it
, depth
, field_width
- n
,
21479 precision
- n
, XCAR (XCDR (elt
)),
21480 XCDR (XCDR (elt
)), risky
);
21482 else if (SYMBOLP (car
))
21484 tem
= Fboundp (car
);
21488 /* elt is now the cdr, and we know it is a cons cell.
21489 Use its car if CAR has a non-nil value. */
21492 tem
= Fsymbol_value (car
);
21499 /* Symbol's value is nil (or symbol is unbound)
21500 Get the cddr of the original list
21501 and if possible find the caddr and use that. */
21505 else if (!CONSP (elt
))
21510 else if (INTEGERP (car
))
21512 register int lim
= XINT (car
);
21516 /* Negative int means reduce maximum width. */
21517 if (precision
<= 0)
21520 precision
= min (precision
, -lim
);
21524 /* Padding specified. Don't let it be more than
21525 current maximum. */
21527 lim
= min (precision
, lim
);
21529 /* If that's more padding than already wanted, queue it.
21530 But don't reduce padding already specified even if
21531 that is beyond the current truncation point. */
21532 field_width
= max (lim
, field_width
);
21536 else if (STRINGP (car
) || CONSP (car
))
21538 Lisp_Object halftail
= elt
;
21542 && (precision
<= 0 || n
< precision
))
21544 n
+= display_mode_element (it
, depth
,
21545 /* Do padding only after the last
21546 element in the list. */
21547 (! CONSP (XCDR (elt
))
21550 precision
- n
, XCAR (elt
),
21554 if ((len
& 1) == 0)
21555 halftail
= XCDR (halftail
);
21556 /* Check for cycle. */
21557 if (EQ (halftail
, elt
))
21566 elt
= build_string ("*invalid*");
21570 /* Pad to FIELD_WIDTH. */
21571 if (field_width
> 0 && n
< field_width
)
21573 switch (mode_line_target
)
21575 case MODE_LINE_NOPROP
:
21576 case MODE_LINE_TITLE
:
21577 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
21579 case MODE_LINE_STRING
:
21580 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
21582 case MODE_LINE_DISPLAY
:
21583 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
21592 /* Store a mode-line string element in mode_line_string_list.
21594 If STRING is non-null, display that C string. Otherwise, the Lisp
21595 string LISP_STRING is displayed.
21597 FIELD_WIDTH is the minimum number of output glyphs to produce.
21598 If STRING has fewer characters than FIELD_WIDTH, pad to the right
21599 with spaces. FIELD_WIDTH <= 0 means don't pad.
21601 PRECISION is the maximum number of characters to output from
21602 STRING. PRECISION <= 0 means don't truncate the string.
21604 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
21605 properties to the string.
21607 PROPS are the properties to add to the string.
21608 The mode_line_string_face face property is always added to the string.
21612 store_mode_line_string (const char *string
, Lisp_Object lisp_string
, int copy_string
,
21613 int field_width
, int precision
, Lisp_Object props
)
21618 if (string
!= NULL
)
21620 len
= strlen (string
);
21621 if (precision
> 0 && len
> precision
)
21623 lisp_string
= make_string (string
, len
);
21625 props
= mode_line_string_face_prop
;
21626 else if (!NILP (mode_line_string_face
))
21628 Lisp_Object face
= Fplist_get (props
, Qface
);
21629 props
= Fcopy_sequence (props
);
21631 face
= mode_line_string_face
;
21633 face
= list2 (face
, mode_line_string_face
);
21634 props
= Fplist_put (props
, Qface
, face
);
21636 Fadd_text_properties (make_number (0), make_number (len
),
21637 props
, lisp_string
);
21641 len
= XFASTINT (Flength (lisp_string
));
21642 if (precision
> 0 && len
> precision
)
21645 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
21648 if (!NILP (mode_line_string_face
))
21652 props
= Ftext_properties_at (make_number (0), lisp_string
);
21653 face
= Fplist_get (props
, Qface
);
21655 face
= mode_line_string_face
;
21657 face
= list2 (face
, mode_line_string_face
);
21658 props
= list2 (Qface
, face
);
21660 lisp_string
= Fcopy_sequence (lisp_string
);
21663 Fadd_text_properties (make_number (0), make_number (len
),
21664 props
, lisp_string
);
21669 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
21673 if (field_width
> len
)
21675 field_width
-= len
;
21676 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
21678 Fadd_text_properties (make_number (0), make_number (field_width
),
21679 props
, lisp_string
);
21680 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
21688 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
21690 doc
: /* Format a string out of a mode line format specification.
21691 First arg FORMAT specifies the mode line format (see `mode-line-format'
21692 for details) to use.
21694 By default, the format is evaluated for the currently selected window.
21696 Optional second arg FACE specifies the face property to put on all
21697 characters for which no face is specified. The value nil means the
21698 default face. The value t means whatever face the window's mode line
21699 currently uses (either `mode-line' or `mode-line-inactive',
21700 depending on whether the window is the selected window or not).
21701 An integer value means the value string has no text
21704 Optional third and fourth args WINDOW and BUFFER specify the window
21705 and buffer to use as the context for the formatting (defaults
21706 are the selected window and the WINDOW's buffer). */)
21707 (Lisp_Object format
, Lisp_Object face
,
21708 Lisp_Object window
, Lisp_Object buffer
)
21713 struct buffer
*old_buffer
= NULL
;
21715 int no_props
= INTEGERP (face
);
21716 ptrdiff_t count
= SPECPDL_INDEX ();
21718 int string_start
= 0;
21720 w
= decode_any_window (window
);
21721 XSETWINDOW (window
, w
);
21724 buffer
= w
->contents
;
21725 CHECK_BUFFER (buffer
);
21727 /* Make formatting the modeline a non-op when noninteractive, otherwise
21728 there will be problems later caused by a partially initialized frame. */
21729 if (NILP (format
) || noninteractive
)
21730 return empty_unibyte_string
;
21735 face_id
= (NILP (face
) || EQ (face
, Qdefault
)) ? DEFAULT_FACE_ID
21736 : EQ (face
, Qt
) ? (EQ (window
, selected_window
)
21737 ? MODE_LINE_FACE_ID
: MODE_LINE_INACTIVE_FACE_ID
)
21738 : EQ (face
, Qmode_line
) ? MODE_LINE_FACE_ID
21739 : EQ (face
, Qmode_line_inactive
) ? MODE_LINE_INACTIVE_FACE_ID
21740 : EQ (face
, Qheader_line
) ? HEADER_LINE_FACE_ID
21741 : EQ (face
, Qtool_bar
) ? TOOL_BAR_FACE_ID
21744 old_buffer
= current_buffer
;
21746 /* Save things including mode_line_proptrans_alist,
21747 and set that to nil so that we don't alter the outer value. */
21748 record_unwind_protect (unwind_format_mode_line
,
21749 format_mode_line_unwind_data
21750 (XFRAME (WINDOW_FRAME (w
)),
21751 old_buffer
, selected_window
, 1));
21752 mode_line_proptrans_alist
= Qnil
;
21754 Fselect_window (window
, Qt
);
21755 set_buffer_internal_1 (XBUFFER (buffer
));
21757 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
21761 mode_line_target
= MODE_LINE_NOPROP
;
21762 mode_line_string_face_prop
= Qnil
;
21763 mode_line_string_list
= Qnil
;
21764 string_start
= MODE_LINE_NOPROP_LEN (0);
21768 mode_line_target
= MODE_LINE_STRING
;
21769 mode_line_string_list
= Qnil
;
21770 mode_line_string_face
= face
;
21771 mode_line_string_face_prop
21772 = NILP (face
) ? Qnil
: list2 (Qface
, face
);
21775 push_kboard (FRAME_KBOARD (it
.f
));
21776 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
21781 len
= MODE_LINE_NOPROP_LEN (string_start
);
21782 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
21786 mode_line_string_list
= Fnreverse (mode_line_string_list
);
21787 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
21788 empty_unibyte_string
);
21791 unbind_to (count
, Qnil
);
21795 /* Write a null-terminated, right justified decimal representation of
21796 the positive integer D to BUF using a minimal field width WIDTH. */
21799 pint2str (register char *buf
, register int width
, register ptrdiff_t d
)
21801 register char *p
= buf
;
21809 *p
++ = d
% 10 + '0';
21814 for (width
-= (int) (p
- buf
); width
> 0; --width
)
21825 /* Write a null-terminated, right justified decimal and "human
21826 readable" representation of the nonnegative integer D to BUF using
21827 a minimal field width WIDTH. D should be smaller than 999.5e24. */
21829 static const char power_letter
[] =
21843 pint2hrstr (char *buf
, int width
, ptrdiff_t d
)
21845 /* We aim to represent the nonnegative integer D as
21846 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
21847 ptrdiff_t quotient
= d
;
21849 /* -1 means: do not use TENTHS. */
21853 /* Length of QUOTIENT.TENTHS as a string. */
21859 if (quotient
>= 1000)
21861 /* Scale to the appropriate EXPONENT. */
21864 remainder
= quotient
% 1000;
21868 while (quotient
>= 1000);
21870 /* Round to nearest and decide whether to use TENTHS or not. */
21873 tenths
= remainder
/ 100;
21874 if (remainder
% 100 >= 50)
21881 if (quotient
== 10)
21889 if (remainder
>= 500)
21891 if (quotient
< 999)
21902 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
21903 if (tenths
== -1 && quotient
<= 99)
21910 p
= psuffix
= buf
+ max (width
, length
);
21912 /* Print EXPONENT. */
21913 *psuffix
++ = power_letter
[exponent
];
21916 /* Print TENTHS. */
21919 *--p
= '0' + tenths
;
21923 /* Print QUOTIENT. */
21926 int digit
= quotient
% 10;
21927 *--p
= '0' + digit
;
21929 while ((quotient
/= 10) != 0);
21931 /* Print leading spaces. */
21936 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
21937 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
21938 type of CODING_SYSTEM. Return updated pointer into BUF. */
21940 static unsigned char invalid_eol_type
[] = "(*invalid*)";
21943 decode_mode_spec_coding (Lisp_Object coding_system
, register char *buf
, int eol_flag
)
21946 bool multibyte
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
21947 const unsigned char *eol_str
;
21949 /* The EOL conversion we are using. */
21950 Lisp_Object eoltype
;
21952 val
= CODING_SYSTEM_SPEC (coding_system
);
21955 if (!VECTORP (val
)) /* Not yet decided. */
21957 *buf
++ = multibyte
? '-' : ' ';
21959 eoltype
= eol_mnemonic_undecided
;
21960 /* Don't mention EOL conversion if it isn't decided. */
21965 Lisp_Object eolvalue
;
21967 attrs
= AREF (val
, 0);
21968 eolvalue
= AREF (val
, 2);
21971 ? XFASTINT (CODING_ATTR_MNEMONIC (attrs
))
21976 /* The EOL conversion that is normal on this system. */
21978 if (NILP (eolvalue
)) /* Not yet decided. */
21979 eoltype
= eol_mnemonic_undecided
;
21980 else if (VECTORP (eolvalue
)) /* Not yet decided. */
21981 eoltype
= eol_mnemonic_undecided
;
21982 else /* eolvalue is Qunix, Qdos, or Qmac. */
21983 eoltype
= (EQ (eolvalue
, Qunix
)
21984 ? eol_mnemonic_unix
21985 : (EQ (eolvalue
, Qdos
) == 1
21986 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
21992 /* Mention the EOL conversion if it is not the usual one. */
21993 if (STRINGP (eoltype
))
21995 eol_str
= SDATA (eoltype
);
21996 eol_str_len
= SBYTES (eoltype
);
21998 else if (CHARACTERP (eoltype
))
22000 unsigned char *tmp
= alloca (MAX_MULTIBYTE_LENGTH
);
22001 int c
= XFASTINT (eoltype
);
22002 eol_str_len
= CHAR_STRING (c
, tmp
);
22007 eol_str
= invalid_eol_type
;
22008 eol_str_len
= sizeof (invalid_eol_type
) - 1;
22010 memcpy (buf
, eol_str
, eol_str_len
);
22011 buf
+= eol_str_len
;
22017 /* Return a string for the output of a mode line %-spec for window W,
22018 generated by character C. FIELD_WIDTH > 0 means pad the string
22019 returned with spaces to that value. Return a Lisp string in
22020 *STRING if the resulting string is taken from that Lisp string.
22022 Note we operate on the current buffer for most purposes. */
22024 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
22026 static const char *
22027 decode_mode_spec (struct window
*w
, register int c
, int field_width
,
22028 Lisp_Object
*string
)
22031 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
22032 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
22033 /* We are going to use f->decode_mode_spec_buffer as the buffer to
22034 produce strings from numerical values, so limit preposterously
22035 large values of FIELD_WIDTH to avoid overrunning the buffer's
22036 end. The size of the buffer is enough for FRAME_MESSAGE_BUF_SIZE
22037 bytes plus the terminating null. */
22038 int width
= min (field_width
, FRAME_MESSAGE_BUF_SIZE (f
));
22039 struct buffer
*b
= current_buffer
;
22047 if (!NILP (BVAR (b
, read_only
)))
22049 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
22054 /* This differs from %* only for a modified read-only buffer. */
22055 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
22057 if (!NILP (BVAR (b
, read_only
)))
22062 /* This differs from %* in ignoring read-only-ness. */
22063 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
22075 if (command_loop_level
> 5)
22077 p
= decode_mode_spec_buf
;
22078 for (i
= 0; i
< command_loop_level
; i
++)
22081 return decode_mode_spec_buf
;
22089 if (command_loop_level
> 5)
22091 p
= decode_mode_spec_buf
;
22092 for (i
= 0; i
< command_loop_level
; i
++)
22095 return decode_mode_spec_buf
;
22102 /* Let lots_of_dashes be a string of infinite length. */
22103 if (mode_line_target
== MODE_LINE_NOPROP
22104 || mode_line_target
== MODE_LINE_STRING
)
22106 if (field_width
<= 0
22107 || field_width
> sizeof (lots_of_dashes
))
22109 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
22110 decode_mode_spec_buf
[i
] = '-';
22111 decode_mode_spec_buf
[i
] = '\0';
22112 return decode_mode_spec_buf
;
22115 return lots_of_dashes
;
22119 obj
= BVAR (b
, name
);
22123 /* %c and %l are ignored in `frame-title-format'.
22124 (In redisplay_internal, the frame title is drawn _before_ the
22125 windows are updated, so the stuff which depends on actual
22126 window contents (such as %l) may fail to render properly, or
22127 even crash emacs.) */
22128 if (mode_line_target
== MODE_LINE_TITLE
)
22132 ptrdiff_t col
= current_column ();
22133 w
->column_number_displayed
= col
;
22134 pint2str (decode_mode_spec_buf
, width
, col
);
22135 return decode_mode_spec_buf
;
22139 #ifndef SYSTEM_MALLOC
22141 if (NILP (Vmemory_full
))
22144 return "!MEM FULL! ";
22151 /* %F displays the frame name. */
22152 if (!NILP (f
->title
))
22153 return SSDATA (f
->title
);
22154 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
22155 return SSDATA (f
->name
);
22159 obj
= BVAR (b
, filename
);
22164 ptrdiff_t size
= ZV
- BEGV
;
22165 pint2str (decode_mode_spec_buf
, width
, size
);
22166 return decode_mode_spec_buf
;
22171 ptrdiff_t size
= ZV
- BEGV
;
22172 pint2hrstr (decode_mode_spec_buf
, width
, size
);
22173 return decode_mode_spec_buf
;
22178 ptrdiff_t startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
22179 ptrdiff_t topline
, nlines
, height
;
22182 /* %c and %l are ignored in `frame-title-format'. */
22183 if (mode_line_target
== MODE_LINE_TITLE
)
22186 startpos
= marker_position (w
->start
);
22187 startpos_byte
= marker_byte_position (w
->start
);
22188 height
= WINDOW_TOTAL_LINES (w
);
22190 /* If we decided that this buffer isn't suitable for line numbers,
22191 don't forget that too fast. */
22192 if (w
->base_line_pos
== -1)
22195 /* If the buffer is very big, don't waste time. */
22196 if (INTEGERP (Vline_number_display_limit
)
22197 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
22199 w
->base_line_pos
= 0;
22200 w
->base_line_number
= 0;
22204 if (w
->base_line_number
> 0
22205 && w
->base_line_pos
> 0
22206 && w
->base_line_pos
<= startpos
)
22208 line
= w
->base_line_number
;
22209 linepos
= w
->base_line_pos
;
22210 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
22215 linepos
= BUF_BEGV (b
);
22216 linepos_byte
= BUF_BEGV_BYTE (b
);
22219 /* Count lines from base line to window start position. */
22220 nlines
= display_count_lines (linepos_byte
,
22224 topline
= nlines
+ line
;
22226 /* Determine a new base line, if the old one is too close
22227 or too far away, or if we did not have one.
22228 "Too close" means it's plausible a scroll-down would
22229 go back past it. */
22230 if (startpos
== BUF_BEGV (b
))
22232 w
->base_line_number
= topline
;
22233 w
->base_line_pos
= BUF_BEGV (b
);
22235 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
22236 || linepos
== BUF_BEGV (b
))
22238 ptrdiff_t limit
= BUF_BEGV (b
);
22239 ptrdiff_t limit_byte
= BUF_BEGV_BYTE (b
);
22240 ptrdiff_t position
;
22241 ptrdiff_t distance
=
22242 (height
* 2 + 30) * line_number_display_limit_width
;
22244 if (startpos
- distance
> limit
)
22246 limit
= startpos
- distance
;
22247 limit_byte
= CHAR_TO_BYTE (limit
);
22250 nlines
= display_count_lines (startpos_byte
,
22252 - (height
* 2 + 30),
22254 /* If we couldn't find the lines we wanted within
22255 line_number_display_limit_width chars per line,
22256 give up on line numbers for this window. */
22257 if (position
== limit_byte
&& limit
== startpos
- distance
)
22259 w
->base_line_pos
= -1;
22260 w
->base_line_number
= 0;
22264 w
->base_line_number
= topline
- nlines
;
22265 w
->base_line_pos
= BYTE_TO_CHAR (position
);
22268 /* Now count lines from the start pos to point. */
22269 nlines
= display_count_lines (startpos_byte
,
22270 PT_BYTE
, PT
, &junk
);
22272 /* Record that we did display the line number. */
22273 line_number_displayed
= 1;
22275 /* Make the string to show. */
22276 pint2str (decode_mode_spec_buf
, width
, topline
+ nlines
);
22277 return decode_mode_spec_buf
;
22280 char* p
= decode_mode_spec_buf
;
22281 int pad
= width
- 2;
22287 return decode_mode_spec_buf
;
22293 obj
= BVAR (b
, mode_name
);
22297 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
22303 ptrdiff_t pos
= marker_position (w
->start
);
22304 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
22306 if (w
->window_end_pos
<= BUF_Z (b
) - BUF_ZV (b
))
22308 if (pos
<= BUF_BEGV (b
))
22313 else if (pos
<= BUF_BEGV (b
))
22317 if (total
> 1000000)
22318 /* Do it differently for a large value, to avoid overflow. */
22319 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
22321 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
22322 /* We can't normally display a 3-digit number,
22323 so get us a 2-digit number that is close. */
22326 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
22327 return decode_mode_spec_buf
;
22331 /* Display percentage of size above the bottom of the screen. */
22334 ptrdiff_t toppos
= marker_position (w
->start
);
22335 ptrdiff_t botpos
= BUF_Z (b
) - w
->window_end_pos
;
22336 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
22338 if (botpos
>= BUF_ZV (b
))
22340 if (toppos
<= BUF_BEGV (b
))
22347 if (total
> 1000000)
22348 /* Do it differently for a large value, to avoid overflow. */
22349 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
22351 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
22352 /* We can't normally display a 3-digit number,
22353 so get us a 2-digit number that is close. */
22356 if (toppos
<= BUF_BEGV (b
))
22357 sprintf (decode_mode_spec_buf
, "Top%2"pD
"d%%", total
);
22359 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
22360 return decode_mode_spec_buf
;
22365 /* status of process */
22366 obj
= Fget_buffer_process (Fcurrent_buffer ());
22368 return "no process";
22370 obj
= Fsymbol_name (Fprocess_status (obj
));
22376 ptrdiff_t count
= inhibit_garbage_collection ();
22377 Lisp_Object val
= call1 (intern ("file-remote-p"),
22378 BVAR (current_buffer
, directory
));
22379 unbind_to (count
, Qnil
);
22388 /* coding-system (not including end-of-line format) */
22390 /* coding-system (including end-of-line type) */
22392 int eol_flag
= (c
== 'Z');
22393 char *p
= decode_mode_spec_buf
;
22395 if (! FRAME_WINDOW_P (f
))
22397 /* No need to mention EOL here--the terminal never needs
22398 to do EOL conversion. */
22399 p
= decode_mode_spec_coding (CODING_ID_NAME
22400 (FRAME_KEYBOARD_CODING (f
)->id
),
22402 p
= decode_mode_spec_coding (CODING_ID_NAME
22403 (FRAME_TERMINAL_CODING (f
)->id
),
22406 p
= decode_mode_spec_coding (BVAR (b
, buffer_file_coding_system
),
22409 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
22410 #ifdef subprocesses
22411 obj
= Fget_buffer_process (Fcurrent_buffer ());
22412 if (PROCESSP (obj
))
22414 p
= decode_mode_spec_coding
22415 (XPROCESS (obj
)->decode_coding_system
, p
, eol_flag
);
22416 p
= decode_mode_spec_coding
22417 (XPROCESS (obj
)->encode_coding_system
, p
, eol_flag
);
22419 #endif /* subprocesses */
22422 return decode_mode_spec_buf
;
22429 return SSDATA (obj
);
22436 /* Count up to COUNT lines starting from START_BYTE. COUNT negative
22437 means count lines back from START_BYTE. But don't go beyond
22438 LIMIT_BYTE. Return the number of lines thus found (always
22441 Set *BYTE_POS_PTR to the byte position where we stopped. This is
22442 either the position COUNT lines after/before START_BYTE, if we
22443 found COUNT lines, or LIMIT_BYTE if we hit the limit before finding
22447 display_count_lines (ptrdiff_t start_byte
,
22448 ptrdiff_t limit_byte
, ptrdiff_t count
,
22449 ptrdiff_t *byte_pos_ptr
)
22451 register unsigned char *cursor
;
22452 unsigned char *base
;
22454 register ptrdiff_t ceiling
;
22455 register unsigned char *ceiling_addr
;
22456 ptrdiff_t orig_count
= count
;
22458 /* If we are not in selective display mode,
22459 check only for newlines. */
22460 int selective_display
= (!NILP (BVAR (current_buffer
, selective_display
))
22461 && !INTEGERP (BVAR (current_buffer
, selective_display
)));
22465 while (start_byte
< limit_byte
)
22467 ceiling
= BUFFER_CEILING_OF (start_byte
);
22468 ceiling
= min (limit_byte
- 1, ceiling
);
22469 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
22470 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
22474 if (selective_display
)
22476 while (*cursor
!= '\n' && *cursor
!= 015
22477 && ++cursor
!= ceiling_addr
)
22479 if (cursor
== ceiling_addr
)
22484 cursor
= memchr (cursor
, '\n', ceiling_addr
- cursor
);
22493 start_byte
+= cursor
- base
;
22494 *byte_pos_ptr
= start_byte
;
22498 while (cursor
< ceiling_addr
);
22500 start_byte
+= ceiling_addr
- base
;
22505 while (start_byte
> limit_byte
)
22507 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
22508 ceiling
= max (limit_byte
, ceiling
);
22509 ceiling_addr
= BYTE_POS_ADDR (ceiling
);
22510 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
22513 if (selective_display
)
22515 while (--cursor
>= ceiling_addr
22516 && *cursor
!= '\n' && *cursor
!= 015)
22518 if (cursor
< ceiling_addr
)
22523 cursor
= memrchr (ceiling_addr
, '\n', cursor
- ceiling_addr
);
22530 start_byte
+= cursor
- base
+ 1;
22531 *byte_pos_ptr
= start_byte
;
22532 /* When scanning backwards, we should
22533 not count the newline posterior to which we stop. */
22534 return - orig_count
- 1;
22537 start_byte
+= ceiling_addr
- base
;
22541 *byte_pos_ptr
= limit_byte
;
22544 return - orig_count
+ count
;
22545 return orig_count
- count
;
22551 /***********************************************************************
22553 ***********************************************************************/
22555 /* Display a NUL-terminated string, starting with index START.
22557 If STRING is non-null, display that C string. Otherwise, the Lisp
22558 string LISP_STRING is displayed. There's a case that STRING is
22559 non-null and LISP_STRING is not nil. It means STRING is a string
22560 data of LISP_STRING. In that case, we display LISP_STRING while
22561 ignoring its text properties.
22563 If FACE_STRING is not nil, FACE_STRING_POS is a position in
22564 FACE_STRING. Display STRING or LISP_STRING with the face at
22565 FACE_STRING_POS in FACE_STRING:
22567 Display the string in the environment given by IT, but use the
22568 standard display table, temporarily.
22570 FIELD_WIDTH is the minimum number of output glyphs to produce.
22571 If STRING has fewer characters than FIELD_WIDTH, pad to the right
22572 with spaces. If STRING has more characters, more than FIELD_WIDTH
22573 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
22575 PRECISION is the maximum number of characters to output from
22576 STRING. PRECISION < 0 means don't truncate the string.
22578 This is roughly equivalent to printf format specifiers:
22580 FIELD_WIDTH PRECISION PRINTF
22581 ----------------------------------------
22587 MULTIBYTE zero means do not display multibyte chars, > 0 means do
22588 display them, and < 0 means obey the current buffer's value of
22589 enable_multibyte_characters.
22591 Value is the number of columns displayed. */
22594 display_string (const char *string
, Lisp_Object lisp_string
, Lisp_Object face_string
,
22595 ptrdiff_t face_string_pos
, ptrdiff_t start
, struct it
*it
,
22596 int field_width
, int precision
, int max_x
, int multibyte
)
22598 int hpos_at_start
= it
->hpos
;
22599 int saved_face_id
= it
->face_id
;
22600 struct glyph_row
*row
= it
->glyph_row
;
22601 ptrdiff_t it_charpos
;
22603 /* Initialize the iterator IT for iteration over STRING beginning
22604 with index START. */
22605 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
22606 precision
, field_width
, multibyte
);
22607 if (string
&& STRINGP (lisp_string
))
22608 /* LISP_STRING is the one returned by decode_mode_spec. We should
22609 ignore its text properties. */
22610 it
->stop_charpos
= it
->end_charpos
;
22612 /* If displaying STRING, set up the face of the iterator from
22613 FACE_STRING, if that's given. */
22614 if (STRINGP (face_string
))
22620 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
22621 0, &endptr
, it
->base_face_id
, 0);
22622 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22623 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
22626 /* Set max_x to the maximum allowed X position. Don't let it go
22627 beyond the right edge of the window. */
22629 max_x
= it
->last_visible_x
;
22631 max_x
= min (max_x
, it
->last_visible_x
);
22633 /* Skip over display elements that are not visible. because IT->w is
22635 if (it
->current_x
< it
->first_visible_x
)
22636 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
22637 MOVE_TO_POS
| MOVE_TO_X
);
22639 row
->ascent
= it
->max_ascent
;
22640 row
->height
= it
->max_ascent
+ it
->max_descent
;
22641 row
->phys_ascent
= it
->max_phys_ascent
;
22642 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
22643 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
22645 if (STRINGP (it
->string
))
22646 it_charpos
= IT_STRING_CHARPOS (*it
);
22648 it_charpos
= IT_CHARPOS (*it
);
22650 /* This condition is for the case that we are called with current_x
22651 past last_visible_x. */
22652 while (it
->current_x
< max_x
)
22654 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
22656 /* Get the next display element. */
22657 if (!get_next_display_element (it
))
22660 /* Produce glyphs. */
22661 x_before
= it
->current_x
;
22662 n_glyphs_before
= row
->used
[TEXT_AREA
];
22663 PRODUCE_GLYPHS (it
);
22665 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
22668 while (i
< nglyphs
)
22670 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
22672 if (it
->line_wrap
!= TRUNCATE
22673 && x
+ glyph
->pixel_width
> max_x
)
22675 /* End of continued line or max_x reached. */
22676 if (CHAR_GLYPH_PADDING_P (*glyph
))
22678 /* A wide character is unbreakable. */
22679 if (row
->reversed_p
)
22680 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
22681 - n_glyphs_before
);
22682 row
->used
[TEXT_AREA
] = n_glyphs_before
;
22683 it
->current_x
= x_before
;
22687 if (row
->reversed_p
)
22688 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
22689 - (n_glyphs_before
+ i
));
22690 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
22695 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
22697 /* Glyph is at least partially visible. */
22699 if (x
< it
->first_visible_x
)
22700 row
->x
= x
- it
->first_visible_x
;
22704 /* Glyph is off the left margin of the display area.
22705 Should not happen. */
22709 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
22710 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
22711 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
22712 row
->phys_height
= max (row
->phys_height
,
22713 it
->max_phys_ascent
+ it
->max_phys_descent
);
22714 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
22715 it
->max_extra_line_spacing
);
22716 x
+= glyph
->pixel_width
;
22720 /* Stop if max_x reached. */
22724 /* Stop at line ends. */
22725 if (ITERATOR_AT_END_OF_LINE_P (it
))
22727 it
->continuation_lines_width
= 0;
22731 set_iterator_to_next (it
, 1);
22732 if (STRINGP (it
->string
))
22733 it_charpos
= IT_STRING_CHARPOS (*it
);
22735 it_charpos
= IT_CHARPOS (*it
);
22737 /* Stop if truncating at the right edge. */
22738 if (it
->line_wrap
== TRUNCATE
22739 && it
->current_x
>= it
->last_visible_x
)
22741 /* Add truncation mark, but don't do it if the line is
22742 truncated at a padding space. */
22743 if (it_charpos
< it
->string_nchars
)
22745 if (!FRAME_WINDOW_P (it
->f
))
22749 if (it
->current_x
> it
->last_visible_x
)
22751 if (!row
->reversed_p
)
22753 for (ii
= row
->used
[TEXT_AREA
] - 1; ii
> 0; --ii
)
22754 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
22759 for (ii
= 0; ii
< row
->used
[TEXT_AREA
]; ii
++)
22760 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
22762 unproduce_glyphs (it
, ii
+ 1);
22763 ii
= row
->used
[TEXT_AREA
] - (ii
+ 1);
22765 for (n
= row
->used
[TEXT_AREA
]; ii
< n
; ++ii
)
22767 row
->used
[TEXT_AREA
] = ii
;
22768 produce_special_glyphs (it
, IT_TRUNCATION
);
22771 produce_special_glyphs (it
, IT_TRUNCATION
);
22773 row
->truncated_on_right_p
= 1;
22779 /* Maybe insert a truncation at the left. */
22780 if (it
->first_visible_x
22783 if (!FRAME_WINDOW_P (it
->f
)
22784 || (row
->reversed_p
22785 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
22786 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
22787 insert_left_trunc_glyphs (it
);
22788 row
->truncated_on_left_p
= 1;
22791 it
->face_id
= saved_face_id
;
22793 /* Value is number of columns displayed. */
22794 return it
->hpos
- hpos_at_start
;
22799 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
22800 appears as an element of LIST or as the car of an element of LIST.
22801 If PROPVAL is a list, compare each element against LIST in that
22802 way, and return 1/2 if any element of PROPVAL is found in LIST.
22803 Otherwise return 0. This function cannot quit.
22804 The return value is 2 if the text is invisible but with an ellipsis
22805 and 1 if it's invisible and without an ellipsis. */
22808 invisible_p (register Lisp_Object propval
, Lisp_Object list
)
22810 register Lisp_Object tail
, proptail
;
22812 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
22814 register Lisp_Object tem
;
22816 if (EQ (propval
, tem
))
22818 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
22819 return NILP (XCDR (tem
)) ? 1 : 2;
22822 if (CONSP (propval
))
22824 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
22826 Lisp_Object propelt
;
22827 propelt
= XCAR (proptail
);
22828 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
22830 register Lisp_Object tem
;
22832 if (EQ (propelt
, tem
))
22834 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
22835 return NILP (XCDR (tem
)) ? 1 : 2;
22843 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
22844 doc
: /* Non-nil if the property makes the text invisible.
22845 POS-OR-PROP can be a marker or number, in which case it is taken to be
22846 a position in the current buffer and the value of the `invisible' property
22847 is checked; or it can be some other value, which is then presumed to be the
22848 value of the `invisible' property of the text of interest.
22849 The non-nil value returned can be t for truly invisible text or something
22850 else if the text is replaced by an ellipsis. */)
22851 (Lisp_Object pos_or_prop
)
22854 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
22855 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
22857 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
22858 return (invis
== 0 ? Qnil
22860 : make_number (invis
));
22863 /* Calculate a width or height in pixels from a specification using
22864 the following elements:
22867 NUM - a (fractional) multiple of the default font width/height
22868 (NUM) - specifies exactly NUM pixels
22869 UNIT - a fixed number of pixels, see below.
22870 ELEMENT - size of a display element in pixels, see below.
22871 (NUM . SPEC) - equals NUM * SPEC
22872 (+ SPEC SPEC ...) - add pixel values
22873 (- SPEC SPEC ...) - subtract pixel values
22874 (- SPEC) - negate pixel value
22877 INT or FLOAT - a number constant
22878 SYMBOL - use symbol's (buffer local) variable binding.
22881 in - pixels per inch *)
22882 mm - pixels per 1/1000 meter *)
22883 cm - pixels per 1/100 meter *)
22884 width - width of current font in pixels.
22885 height - height of current font in pixels.
22887 *) using the ratio(s) defined in display-pixels-per-inch.
22891 left-fringe - left fringe width in pixels
22892 right-fringe - right fringe width in pixels
22894 left-margin - left margin width in pixels
22895 right-margin - right margin width in pixels
22897 scroll-bar - scroll-bar area width in pixels
22901 Pixels corresponding to 5 inches:
22904 Total width of non-text areas on left side of window (if scroll-bar is on left):
22905 '(space :width (+ left-fringe left-margin scroll-bar))
22907 Align to first text column (in header line):
22908 '(space :align-to 0)
22910 Align to middle of text area minus half the width of variable `my-image'
22911 containing a loaded image:
22912 '(space :align-to (0.5 . (- text my-image)))
22914 Width of left margin minus width of 1 character in the default font:
22915 '(space :width (- left-margin 1))
22917 Width of left margin minus width of 2 characters in the current font:
22918 '(space :width (- left-margin (2 . width)))
22920 Center 1 character over left-margin (in header line):
22921 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
22923 Different ways to express width of left fringe plus left margin minus one pixel:
22924 '(space :width (- (+ left-fringe left-margin) (1)))
22925 '(space :width (+ left-fringe left-margin (- (1))))
22926 '(space :width (+ left-fringe left-margin (-1)))
22931 calc_pixel_width_or_height (double *res
, struct it
*it
, Lisp_Object prop
,
22932 struct font
*font
, int width_p
, int *align_to
)
22936 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
22937 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
22940 return OK_PIXELS (0);
22942 eassert (FRAME_LIVE_P (it
->f
));
22944 if (SYMBOLP (prop
))
22946 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
22948 char *unit
= SSDATA (SYMBOL_NAME (prop
));
22950 if (unit
[0] == 'i' && unit
[1] == 'n')
22952 else if (unit
[0] == 'm' && unit
[1] == 'm')
22954 else if (unit
[0] == 'c' && unit
[1] == 'm')
22960 double ppi
= (width_p
? FRAME_RES_X (it
->f
)
22961 : FRAME_RES_Y (it
->f
));
22964 return OK_PIXELS (ppi
/ pixels
);
22969 #ifdef HAVE_WINDOW_SYSTEM
22970 if (EQ (prop
, Qheight
))
22971 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
22972 if (EQ (prop
, Qwidth
))
22973 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
22975 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
22976 return OK_PIXELS (1);
22979 if (EQ (prop
, Qtext
))
22980 return OK_PIXELS (width_p
22981 ? window_box_width (it
->w
, TEXT_AREA
)
22982 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
22984 if (align_to
&& *align_to
< 0)
22987 if (EQ (prop
, Qleft
))
22988 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
22989 if (EQ (prop
, Qright
))
22990 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
22991 if (EQ (prop
, Qcenter
))
22992 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
22993 + window_box_width (it
->w
, TEXT_AREA
) / 2);
22994 if (EQ (prop
, Qleft_fringe
))
22995 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22996 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
22997 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
22998 if (EQ (prop
, Qright_fringe
))
22999 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
23000 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
23001 : window_box_right_offset (it
->w
, TEXT_AREA
));
23002 if (EQ (prop
, Qleft_margin
))
23003 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
23004 if (EQ (prop
, Qright_margin
))
23005 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
23006 if (EQ (prop
, Qscroll_bar
))
23007 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
23009 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
23010 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
23011 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
23016 if (EQ (prop
, Qleft_fringe
))
23017 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
23018 if (EQ (prop
, Qright_fringe
))
23019 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
23020 if (EQ (prop
, Qleft_margin
))
23021 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
23022 if (EQ (prop
, Qright_margin
))
23023 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
23024 if (EQ (prop
, Qscroll_bar
))
23025 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
23028 prop
= buffer_local_value_1 (prop
, it
->w
->contents
);
23029 if (EQ (prop
, Qunbound
))
23033 if (INTEGERP (prop
) || FLOATP (prop
))
23035 int base_unit
= (width_p
23036 ? FRAME_COLUMN_WIDTH (it
->f
)
23037 : FRAME_LINE_HEIGHT (it
->f
));
23038 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
23043 Lisp_Object car
= XCAR (prop
);
23044 Lisp_Object cdr
= XCDR (prop
);
23048 #ifdef HAVE_WINDOW_SYSTEM
23049 if (FRAME_WINDOW_P (it
->f
)
23050 && valid_image_p (prop
))
23052 ptrdiff_t id
= lookup_image (it
->f
, prop
);
23053 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
23055 return OK_PIXELS (width_p
? img
->width
: img
->height
);
23058 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
23064 while (CONSP (cdr
))
23066 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
23067 font
, width_p
, align_to
))
23070 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
23075 if (EQ (car
, Qminus
))
23077 return OK_PIXELS (pixels
);
23080 car
= buffer_local_value_1 (car
, it
->w
->contents
);
23081 if (EQ (car
, Qunbound
))
23085 if (INTEGERP (car
) || FLOATP (car
))
23088 pixels
= XFLOATINT (car
);
23090 return OK_PIXELS (pixels
);
23091 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
23092 font
, width_p
, align_to
))
23093 return OK_PIXELS (pixels
* fact
);
23104 /***********************************************************************
23106 ***********************************************************************/
23108 #ifdef HAVE_WINDOW_SYSTEM
23113 dump_glyph_string (struct glyph_string
*s
)
23115 fprintf (stderr
, "glyph string\n");
23116 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
23117 s
->x
, s
->y
, s
->width
, s
->height
);
23118 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
23119 fprintf (stderr
, " hl = %d\n", s
->hl
);
23120 fprintf (stderr
, " left overhang = %d, right = %d\n",
23121 s
->left_overhang
, s
->right_overhang
);
23122 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
23123 fprintf (stderr
, " extends to end of line = %d\n",
23124 s
->extends_to_end_of_line_p
);
23125 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
23126 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
23129 #endif /* GLYPH_DEBUG */
23131 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
23132 of XChar2b structures for S; it can't be allocated in
23133 init_glyph_string because it must be allocated via `alloca'. W
23134 is the window on which S is drawn. ROW and AREA are the glyph row
23135 and area within the row from which S is constructed. START is the
23136 index of the first glyph structure covered by S. HL is a
23137 face-override for drawing S. */
23140 #define OPTIONAL_HDC(hdc) HDC hdc,
23141 #define DECLARE_HDC(hdc) HDC hdc;
23142 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
23143 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
23146 #ifndef OPTIONAL_HDC
23147 #define OPTIONAL_HDC(hdc)
23148 #define DECLARE_HDC(hdc)
23149 #define ALLOCATE_HDC(hdc, f)
23150 #define RELEASE_HDC(hdc, f)
23154 init_glyph_string (struct glyph_string
*s
,
23156 XChar2b
*char2b
, struct window
*w
, struct glyph_row
*row
,
23157 enum glyph_row_area area
, int start
, enum draw_glyphs_face hl
)
23159 memset (s
, 0, sizeof *s
);
23161 s
->f
= XFRAME (w
->frame
);
23165 s
->display
= FRAME_X_DISPLAY (s
->f
);
23166 s
->window
= FRAME_X_WINDOW (s
->f
);
23167 s
->char2b
= char2b
;
23171 s
->first_glyph
= row
->glyphs
[area
] + start
;
23172 s
->height
= row
->height
;
23173 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
23174 s
->ybase
= s
->y
+ row
->ascent
;
23178 /* Append the list of glyph strings with head H and tail T to the list
23179 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
23182 append_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
23183 struct glyph_string
*h
, struct glyph_string
*t
)
23197 /* Prepend the list of glyph strings with head H and tail T to the
23198 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
23202 prepend_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
23203 struct glyph_string
*h
, struct glyph_string
*t
)
23217 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
23218 Set *HEAD and *TAIL to the resulting list. */
23221 append_glyph_string (struct glyph_string
**head
, struct glyph_string
**tail
,
23222 struct glyph_string
*s
)
23224 s
->next
= s
->prev
= NULL
;
23225 append_glyph_string_lists (head
, tail
, s
, s
);
23229 /* Get face and two-byte form of character C in face FACE_ID on frame F.
23230 The encoding of C is returned in *CHAR2B. DISPLAY_P non-zero means
23231 make sure that X resources for the face returned are allocated.
23232 Value is a pointer to a realized face that is ready for display if
23233 DISPLAY_P is non-zero. */
23235 static struct face
*
23236 get_char_face_and_encoding (struct frame
*f
, int c
, int face_id
,
23237 XChar2b
*char2b
, int display_p
)
23239 struct face
*face
= FACE_FROM_ID (f
, face_id
);
23244 code
= face
->font
->driver
->encode_char (face
->font
, c
);
23246 if (code
== FONT_INVALID_CODE
)
23249 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
23251 /* Make sure X resources of the face are allocated. */
23252 #ifdef HAVE_X_WINDOWS
23256 eassert (face
!= NULL
);
23257 PREPARE_FACE_FOR_DISPLAY (f
, face
);
23264 /* Get face and two-byte form of character glyph GLYPH on frame F.
23265 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
23266 a pointer to a realized face that is ready for display. */
23268 static struct face
*
23269 get_glyph_face_and_encoding (struct frame
*f
, struct glyph
*glyph
,
23270 XChar2b
*char2b
, int *two_byte_p
)
23275 eassert (glyph
->type
== CHAR_GLYPH
);
23276 face
= FACE_FROM_ID (f
, glyph
->face_id
);
23278 /* Make sure X resources of the face are allocated. */
23279 eassert (face
!= NULL
);
23280 PREPARE_FACE_FOR_DISPLAY (f
, face
);
23287 if (CHAR_BYTE8_P (glyph
->u
.ch
))
23288 code
= CHAR_TO_BYTE8 (glyph
->u
.ch
);
23290 code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
23292 if (code
== FONT_INVALID_CODE
)
23296 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
23301 /* Get glyph code of character C in FONT in the two-byte form CHAR2B.
23302 Return 1 if FONT has a glyph for C, otherwise return 0. */
23305 get_char_glyph_code (int c
, struct font
*font
, XChar2b
*char2b
)
23309 if (CHAR_BYTE8_P (c
))
23310 code
= CHAR_TO_BYTE8 (c
);
23312 code
= font
->driver
->encode_char (font
, c
);
23314 if (code
== FONT_INVALID_CODE
)
23316 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
23321 /* Fill glyph string S with composition components specified by S->cmp.
23323 BASE_FACE is the base face of the composition.
23324 S->cmp_from is the index of the first component for S.
23326 OVERLAPS non-zero means S should draw the foreground only, and use
23327 its physical height for clipping. See also draw_glyphs.
23329 Value is the index of a component not in S. */
23332 fill_composite_glyph_string (struct glyph_string
*s
, struct face
*base_face
,
23336 /* For all glyphs of this composition, starting at the offset
23337 S->cmp_from, until we reach the end of the definition or encounter a
23338 glyph that requires the different face, add it to S. */
23343 s
->for_overlaps
= overlaps
;
23346 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
23348 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
23350 /* TAB in a composition means display glyphs with padding space
23351 on the left or right. */
23354 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
23357 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
23364 s
->font
= s
->face
->font
;
23366 else if (s
->face
!= face
)
23374 if (s
->face
== NULL
)
23376 s
->face
= base_face
->ascii_face
;
23377 s
->font
= s
->face
->font
;
23380 /* All glyph strings for the same composition has the same width,
23381 i.e. the width set for the first component of the composition. */
23382 s
->width
= s
->first_glyph
->pixel_width
;
23384 /* If the specified font could not be loaded, use the frame's
23385 default font, but record the fact that we couldn't load it in
23386 the glyph string so that we can draw rectangles for the
23387 characters of the glyph string. */
23388 if (s
->font
== NULL
)
23390 s
->font_not_found_p
= 1;
23391 s
->font
= FRAME_FONT (s
->f
);
23394 /* Adjust base line for subscript/superscript text. */
23395 s
->ybase
+= s
->first_glyph
->voffset
;
23397 /* This glyph string must always be drawn with 16-bit functions. */
23404 fill_gstring_glyph_string (struct glyph_string
*s
, int face_id
,
23405 int start
, int end
, int overlaps
)
23407 struct glyph
*glyph
, *last
;
23408 Lisp_Object lgstring
;
23411 s
->for_overlaps
= overlaps
;
23412 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23413 last
= s
->row
->glyphs
[s
->area
] + end
;
23414 s
->cmp_id
= glyph
->u
.cmp
.id
;
23415 s
->cmp_from
= glyph
->slice
.cmp
.from
;
23416 s
->cmp_to
= glyph
->slice
.cmp
.to
+ 1;
23417 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
23418 lgstring
= composition_gstring_from_id (s
->cmp_id
);
23419 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
23421 while (glyph
< last
23422 && glyph
->u
.cmp
.automatic
23423 && glyph
->u
.cmp
.id
== s
->cmp_id
23424 && s
->cmp_to
== glyph
->slice
.cmp
.from
)
23425 s
->cmp_to
= (glyph
++)->slice
.cmp
.to
+ 1;
23427 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
23429 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
23430 unsigned code
= LGLYPH_CODE (lglyph
);
23432 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
23434 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
23435 return glyph
- s
->row
->glyphs
[s
->area
];
23439 /* Fill glyph string S from a sequence glyphs for glyphless characters.
23440 See the comment of fill_glyph_string for arguments.
23441 Value is the index of the first glyph not in S. */
23445 fill_glyphless_glyph_string (struct glyph_string
*s
, int face_id
,
23446 int start
, int end
, int overlaps
)
23448 struct glyph
*glyph
, *last
;
23451 eassert (s
->first_glyph
->type
== GLYPHLESS_GLYPH
);
23452 s
->for_overlaps
= overlaps
;
23453 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23454 last
= s
->row
->glyphs
[s
->area
] + end
;
23455 voffset
= glyph
->voffset
;
23456 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
23457 s
->font
= s
->face
->font
? s
->face
->font
: FRAME_FONT (s
->f
);
23459 s
->width
= glyph
->pixel_width
;
23461 while (glyph
< last
23462 && glyph
->type
== GLYPHLESS_GLYPH
23463 && glyph
->voffset
== voffset
23464 && glyph
->face_id
== face_id
)
23467 s
->width
+= glyph
->pixel_width
;
23470 s
->ybase
+= voffset
;
23471 return glyph
- s
->row
->glyphs
[s
->area
];
23475 /* Fill glyph string S from a sequence of character glyphs.
23477 FACE_ID is the face id of the string. START is the index of the
23478 first glyph to consider, END is the index of the last + 1.
23479 OVERLAPS non-zero means S should draw the foreground only, and use
23480 its physical height for clipping. See also draw_glyphs.
23482 Value is the index of the first glyph not in S. */
23485 fill_glyph_string (struct glyph_string
*s
, int face_id
,
23486 int start
, int end
, int overlaps
)
23488 struct glyph
*glyph
, *last
;
23490 int glyph_not_available_p
;
23492 eassert (s
->f
== XFRAME (s
->w
->frame
));
23493 eassert (s
->nchars
== 0);
23494 eassert (start
>= 0 && end
> start
);
23496 s
->for_overlaps
= overlaps
;
23497 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23498 last
= s
->row
->glyphs
[s
->area
] + end
;
23499 voffset
= glyph
->voffset
;
23500 s
->padding_p
= glyph
->padding_p
;
23501 glyph_not_available_p
= glyph
->glyph_not_available_p
;
23503 while (glyph
< last
23504 && glyph
->type
== CHAR_GLYPH
23505 && glyph
->voffset
== voffset
23506 /* Same face id implies same font, nowadays. */
23507 && glyph
->face_id
== face_id
23508 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
23512 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
23513 s
->char2b
+ s
->nchars
,
23515 s
->two_byte_p
= two_byte_p
;
23517 eassert (s
->nchars
<= end
- start
);
23518 s
->width
+= glyph
->pixel_width
;
23519 if (glyph
++->padding_p
!= s
->padding_p
)
23523 s
->font
= s
->face
->font
;
23525 /* If the specified font could not be loaded, use the frame's font,
23526 but record the fact that we couldn't load it in
23527 S->font_not_found_p so that we can draw rectangles for the
23528 characters of the glyph string. */
23529 if (s
->font
== NULL
|| glyph_not_available_p
)
23531 s
->font_not_found_p
= 1;
23532 s
->font
= FRAME_FONT (s
->f
);
23535 /* Adjust base line for subscript/superscript text. */
23536 s
->ybase
+= voffset
;
23538 eassert (s
->face
&& s
->face
->gc
);
23539 return glyph
- s
->row
->glyphs
[s
->area
];
23543 /* Fill glyph string S from image glyph S->first_glyph. */
23546 fill_image_glyph_string (struct glyph_string
*s
)
23548 eassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
23549 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
23551 s
->slice
= s
->first_glyph
->slice
.img
;
23552 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
23553 s
->font
= s
->face
->font
;
23554 s
->width
= s
->first_glyph
->pixel_width
;
23556 /* Adjust base line for subscript/superscript text. */
23557 s
->ybase
+= s
->first_glyph
->voffset
;
23561 /* Fill glyph string S from a sequence of stretch glyphs.
23563 START is the index of the first glyph to consider,
23564 END is the index of the last + 1.
23566 Value is the index of the first glyph not in S. */
23569 fill_stretch_glyph_string (struct glyph_string
*s
, int start
, int end
)
23571 struct glyph
*glyph
, *last
;
23572 int voffset
, face_id
;
23574 eassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
23576 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23577 last
= s
->row
->glyphs
[s
->area
] + end
;
23578 face_id
= glyph
->face_id
;
23579 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
23580 s
->font
= s
->face
->font
;
23581 s
->width
= glyph
->pixel_width
;
23583 voffset
= glyph
->voffset
;
23587 && glyph
->type
== STRETCH_GLYPH
23588 && glyph
->voffset
== voffset
23589 && glyph
->face_id
== face_id
);
23591 s
->width
+= glyph
->pixel_width
;
23593 /* Adjust base line for subscript/superscript text. */
23594 s
->ybase
+= voffset
;
23596 /* The case that face->gc == 0 is handled when drawing the glyph
23597 string by calling PREPARE_FACE_FOR_DISPLAY. */
23599 return glyph
- s
->row
->glyphs
[s
->area
];
23602 static struct font_metrics
*
23603 get_per_char_metric (struct font
*font
, XChar2b
*char2b
)
23605 static struct font_metrics metrics
;
23610 code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
23611 if (code
== FONT_INVALID_CODE
)
23613 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
23618 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
23619 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
23620 assumed to be zero. */
23623 x_get_glyph_overhangs (struct glyph
*glyph
, struct frame
*f
, int *left
, int *right
)
23625 *left
= *right
= 0;
23627 if (glyph
->type
== CHAR_GLYPH
)
23631 struct font_metrics
*pcm
;
23633 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
23634 if (face
->font
&& (pcm
= get_per_char_metric (face
->font
, &char2b
)))
23636 if (pcm
->rbearing
> pcm
->width
)
23637 *right
= pcm
->rbearing
- pcm
->width
;
23638 if (pcm
->lbearing
< 0)
23639 *left
= -pcm
->lbearing
;
23642 else if (glyph
->type
== COMPOSITE_GLYPH
)
23644 if (! glyph
->u
.cmp
.automatic
)
23646 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
23648 if (cmp
->rbearing
> cmp
->pixel_width
)
23649 *right
= cmp
->rbearing
- cmp
->pixel_width
;
23650 if (cmp
->lbearing
< 0)
23651 *left
= - cmp
->lbearing
;
23655 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
23656 struct font_metrics metrics
;
23658 composition_gstring_width (gstring
, glyph
->slice
.cmp
.from
,
23659 glyph
->slice
.cmp
.to
+ 1, &metrics
);
23660 if (metrics
.rbearing
> metrics
.width
)
23661 *right
= metrics
.rbearing
- metrics
.width
;
23662 if (metrics
.lbearing
< 0)
23663 *left
= - metrics
.lbearing
;
23669 /* Return the index of the first glyph preceding glyph string S that
23670 is overwritten by S because of S's left overhang. Value is -1
23671 if no glyphs are overwritten. */
23674 left_overwritten (struct glyph_string
*s
)
23678 if (s
->left_overhang
)
23681 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23682 int first
= s
->first_glyph
- glyphs
;
23684 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
23685 x
-= glyphs
[i
].pixel_width
;
23696 /* Return the index of the first glyph preceding glyph string S that
23697 is overwriting S because of its right overhang. Value is -1 if no
23698 glyph in front of S overwrites S. */
23701 left_overwriting (struct glyph_string
*s
)
23704 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23705 int first
= s
->first_glyph
- glyphs
;
23709 for (i
= first
- 1; i
>= 0; --i
)
23712 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
23715 x
-= glyphs
[i
].pixel_width
;
23722 /* Return the index of the last glyph following glyph string S that is
23723 overwritten by S because of S's right overhang. Value is -1 if
23724 no such glyph is found. */
23727 right_overwritten (struct glyph_string
*s
)
23731 if (s
->right_overhang
)
23734 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23735 int first
= (s
->first_glyph
- glyphs
23736 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
23737 int end
= s
->row
->used
[s
->area
];
23739 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
23740 x
+= glyphs
[i
].pixel_width
;
23749 /* Return the index of the last glyph following glyph string S that
23750 overwrites S because of its left overhang. Value is negative
23751 if no such glyph is found. */
23754 right_overwriting (struct glyph_string
*s
)
23757 int end
= s
->row
->used
[s
->area
];
23758 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23759 int first
= (s
->first_glyph
- glyphs
23760 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
23764 for (i
= first
; i
< end
; ++i
)
23767 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
23770 x
+= glyphs
[i
].pixel_width
;
23777 /* Set background width of glyph string S. START is the index of the
23778 first glyph following S. LAST_X is the right-most x-position + 1
23779 in the drawing area. */
23782 set_glyph_string_background_width (struct glyph_string
*s
, int start
, int last_x
)
23784 /* If the face of this glyph string has to be drawn to the end of
23785 the drawing area, set S->extends_to_end_of_line_p. */
23787 if (start
== s
->row
->used
[s
->area
]
23788 && s
->area
== TEXT_AREA
23789 && ((s
->row
->fill_line_p
23790 && (s
->hl
== DRAW_NORMAL_TEXT
23791 || s
->hl
== DRAW_IMAGE_RAISED
23792 || s
->hl
== DRAW_IMAGE_SUNKEN
))
23793 || s
->hl
== DRAW_MOUSE_FACE
))
23794 s
->extends_to_end_of_line_p
= 1;
23796 /* If S extends its face to the end of the line, set its
23797 background_width to the distance to the right edge of the drawing
23799 if (s
->extends_to_end_of_line_p
)
23800 s
->background_width
= last_x
- s
->x
+ 1;
23802 s
->background_width
= s
->width
;
23806 /* Compute overhangs and x-positions for glyph string S and its
23807 predecessors, or successors. X is the starting x-position for S.
23808 BACKWARD_P non-zero means process predecessors. */
23811 compute_overhangs_and_x (struct glyph_string
*s
, int x
, int backward_p
)
23817 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
23818 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
23828 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
23829 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
23839 /* The following macros are only called from draw_glyphs below.
23840 They reference the following parameters of that function directly:
23841 `w', `row', `area', and `overlap_p'
23842 as well as the following local variables:
23843 `s', `f', and `hdc' (in W32) */
23846 /* On W32, silently add local `hdc' variable to argument list of
23847 init_glyph_string. */
23848 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
23849 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
23851 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
23852 init_glyph_string (s, char2b, w, row, area, start, hl)
23855 /* Add a glyph string for a stretch glyph to the list of strings
23856 between HEAD and TAIL. START is the index of the stretch glyph in
23857 row area AREA of glyph row ROW. END is the index of the last glyph
23858 in that glyph row area. X is the current output position assigned
23859 to the new glyph string constructed. HL overrides that face of the
23860 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
23861 is the right-most x-position of the drawing area. */
23863 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
23864 and below -- keep them on one line. */
23865 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23868 s = alloca (sizeof *s); \
23869 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23870 START = fill_stretch_glyph_string (s, START, END); \
23871 append_glyph_string (&HEAD, &TAIL, s); \
23877 /* Add a glyph string for an image glyph to the list of strings
23878 between HEAD and TAIL. START is the index of the image glyph in
23879 row area AREA of glyph row ROW. END is the index of the last glyph
23880 in that glyph row area. X is the current output position assigned
23881 to the new glyph string constructed. HL overrides that face of the
23882 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
23883 is the right-most x-position of the drawing area. */
23885 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23888 s = alloca (sizeof *s); \
23889 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23890 fill_image_glyph_string (s); \
23891 append_glyph_string (&HEAD, &TAIL, s); \
23898 /* Add a glyph string for a sequence of character glyphs to the list
23899 of strings between HEAD and TAIL. START is the index of the first
23900 glyph in row area AREA of glyph row ROW that is part of the new
23901 glyph string. END is the index of the last glyph in that glyph row
23902 area. X is the current output position assigned to the new glyph
23903 string constructed. HL overrides that face of the glyph; e.g. it
23904 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
23905 right-most x-position of the drawing area. */
23907 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
23913 face_id = (row)->glyphs[area][START].face_id; \
23915 s = alloca (sizeof *s); \
23916 char2b = alloca ((END - START) * sizeof *char2b); \
23917 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23918 append_glyph_string (&HEAD, &TAIL, s); \
23920 START = fill_glyph_string (s, face_id, START, END, overlaps); \
23925 /* Add a glyph string for a composite sequence to the list of strings
23926 between HEAD and TAIL. START is the index of the first glyph in
23927 row area AREA of glyph row ROW that is part of the new glyph
23928 string. END is the index of the last glyph in that glyph row area.
23929 X is the current output position assigned to the new glyph string
23930 constructed. HL overrides that face of the glyph; e.g. it is
23931 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
23932 x-position of the drawing area. */
23934 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23936 int face_id = (row)->glyphs[area][START].face_id; \
23937 struct face *base_face = FACE_FROM_ID (f, face_id); \
23938 ptrdiff_t cmp_id = (row)->glyphs[area][START].u.cmp.id; \
23939 struct composition *cmp = composition_table[cmp_id]; \
23941 struct glyph_string *first_s = NULL; \
23944 char2b = alloca (cmp->glyph_len * sizeof *char2b); \
23946 /* Make glyph_strings for each glyph sequence that is drawable by \
23947 the same face, and append them to HEAD/TAIL. */ \
23948 for (n = 0; n < cmp->glyph_len;) \
23950 s = alloca (sizeof *s); \
23951 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23952 append_glyph_string (&(HEAD), &(TAIL), s); \
23958 n = fill_composite_glyph_string (s, base_face, overlaps); \
23966 /* Add a glyph string for a glyph-string sequence to the list of strings
23967 between HEAD and TAIL. */
23969 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23973 Lisp_Object gstring; \
23975 face_id = (row)->glyphs[area][START].face_id; \
23976 gstring = (composition_gstring_from_id \
23977 ((row)->glyphs[area][START].u.cmp.id)); \
23978 s = alloca (sizeof *s); \
23979 char2b = alloca (LGSTRING_GLYPH_LEN (gstring) * sizeof *char2b); \
23980 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23981 append_glyph_string (&(HEAD), &(TAIL), s); \
23983 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
23987 /* Add a glyph string for a sequence of glyphless character's glyphs
23988 to the list of strings between HEAD and TAIL. The meanings of
23989 arguments are the same as those of BUILD_CHAR_GLYPH_STRINGS. */
23991 #define BUILD_GLYPHLESS_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23996 face_id = (row)->glyphs[area][START].face_id; \
23998 s = alloca (sizeof *s); \
23999 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
24000 append_glyph_string (&HEAD, &TAIL, s); \
24002 START = fill_glyphless_glyph_string (s, face_id, START, END, \
24008 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
24009 of AREA of glyph row ROW on window W between indices START and END.
24010 HL overrides the face for drawing glyph strings, e.g. it is
24011 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
24012 x-positions of the drawing area.
24014 This is an ugly monster macro construct because we must use alloca
24015 to allocate glyph strings (because draw_glyphs can be called
24016 asynchronously). */
24018 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
24021 HEAD = TAIL = NULL; \
24022 while (START < END) \
24024 struct glyph *first_glyph = (row)->glyphs[area] + START; \
24025 switch (first_glyph->type) \
24028 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
24032 case COMPOSITE_GLYPH: \
24033 if (first_glyph->u.cmp.automatic) \
24034 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
24037 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
24041 case STRETCH_GLYPH: \
24042 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
24046 case IMAGE_GLYPH: \
24047 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
24051 case GLYPHLESS_GLYPH: \
24052 BUILD_GLYPHLESS_GLYPH_STRING (START, END, HEAD, TAIL, \
24062 set_glyph_string_background_width (s, START, LAST_X); \
24069 /* Draw glyphs between START and END in AREA of ROW on window W,
24070 starting at x-position X. X is relative to AREA in W. HL is a
24071 face-override with the following meaning:
24073 DRAW_NORMAL_TEXT draw normally
24074 DRAW_CURSOR draw in cursor face
24075 DRAW_MOUSE_FACE draw in mouse face.
24076 DRAW_INVERSE_VIDEO draw in mode line face
24077 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
24078 DRAW_IMAGE_RAISED draw an image with a raised relief around it
24080 If OVERLAPS is non-zero, draw only the foreground of characters and
24081 clip to the physical height of ROW. Non-zero value also defines
24082 the overlapping part to be drawn:
24084 OVERLAPS_PRED overlap with preceding rows
24085 OVERLAPS_SUCC overlap with succeeding rows
24086 OVERLAPS_BOTH overlap with both preceding/succeeding rows
24087 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
24089 Value is the x-position reached, relative to AREA of W. */
24092 draw_glyphs (struct window
*w
, int x
, struct glyph_row
*row
,
24093 enum glyph_row_area area
, ptrdiff_t start
, ptrdiff_t end
,
24094 enum draw_glyphs_face hl
, int overlaps
)
24096 struct glyph_string
*head
, *tail
;
24097 struct glyph_string
*s
;
24098 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
24099 int i
, j
, x_reached
, last_x
, area_left
= 0;
24100 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
24103 ALLOCATE_HDC (hdc
, f
);
24105 /* Let's rather be paranoid than getting a SEGV. */
24106 end
= min (end
, row
->used
[area
]);
24107 start
= clip_to_bounds (0, start
, end
);
24109 /* Translate X to frame coordinates. Set last_x to the right
24110 end of the drawing area. */
24111 if (row
->full_width_p
)
24113 /* X is relative to the left edge of W, without scroll bars
24115 area_left
= WINDOW_LEFT_EDGE_X (w
);
24116 last_x
= (WINDOW_LEFT_EDGE_X (w
) + WINDOW_PIXEL_WIDTH (w
)
24117 - (row
->mode_line_p
? WINDOW_RIGHT_DIVIDER_WIDTH (w
) : 0));
24121 area_left
= window_box_left (w
, area
);
24122 last_x
= area_left
+ window_box_width (w
, area
);
24126 /* Build a doubly-linked list of glyph_string structures between
24127 head and tail from what we have to draw. Note that the macro
24128 BUILD_GLYPH_STRINGS will modify its start parameter. That's
24129 the reason we use a separate variable `i'. */
24131 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
24133 x_reached
= tail
->x
+ tail
->background_width
;
24137 /* If there are any glyphs with lbearing < 0 or rbearing > width in
24138 the row, redraw some glyphs in front or following the glyph
24139 strings built above. */
24140 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
24142 struct glyph_string
*h
, *t
;
24143 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
24144 int mouse_beg_col
IF_LINT (= 0), mouse_end_col
IF_LINT (= 0);
24145 int check_mouse_face
= 0;
24148 /* If mouse highlighting is on, we may need to draw adjacent
24149 glyphs using mouse-face highlighting. */
24150 if (area
== TEXT_AREA
&& row
->mouse_face_p
24151 && hlinfo
->mouse_face_beg_row
>= 0
24152 && hlinfo
->mouse_face_end_row
>= 0)
24154 ptrdiff_t row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
24156 if (row_vpos
>= hlinfo
->mouse_face_beg_row
24157 && row_vpos
<= hlinfo
->mouse_face_end_row
)
24159 check_mouse_face
= 1;
24160 mouse_beg_col
= (row_vpos
== hlinfo
->mouse_face_beg_row
)
24161 ? hlinfo
->mouse_face_beg_col
: 0;
24162 mouse_end_col
= (row_vpos
== hlinfo
->mouse_face_end_row
)
24163 ? hlinfo
->mouse_face_end_col
24164 : row
->used
[TEXT_AREA
];
24168 /* Compute overhangs for all glyph strings. */
24169 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
24170 for (s
= head
; s
; s
= s
->next
)
24171 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
24173 /* Prepend glyph strings for glyphs in front of the first glyph
24174 string that are overwritten because of the first glyph
24175 string's left overhang. The background of all strings
24176 prepended must be drawn because the first glyph string
24178 i
= left_overwritten (head
);
24181 enum draw_glyphs_face overlap_hl
;
24183 /* If this row contains mouse highlighting, attempt to draw
24184 the overlapped glyphs with the correct highlight. This
24185 code fails if the overlap encompasses more than one glyph
24186 and mouse-highlight spans only some of these glyphs.
24187 However, making it work perfectly involves a lot more
24188 code, and I don't know if the pathological case occurs in
24189 practice, so we'll stick to this for now. --- cyd */
24190 if (check_mouse_face
24191 && mouse_beg_col
< start
&& mouse_end_col
> i
)
24192 overlap_hl
= DRAW_MOUSE_FACE
;
24194 overlap_hl
= DRAW_NORMAL_TEXT
;
24197 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
24198 overlap_hl
, dummy_x
, last_x
);
24200 compute_overhangs_and_x (t
, head
->x
, 1);
24201 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
24205 /* Prepend glyph strings for glyphs in front of the first glyph
24206 string that overwrite that glyph string because of their
24207 right overhang. For these strings, only the foreground must
24208 be drawn, because it draws over the glyph string at `head'.
24209 The background must not be drawn because this would overwrite
24210 right overhangs of preceding glyphs for which no glyph
24212 i
= left_overwriting (head
);
24215 enum draw_glyphs_face overlap_hl
;
24217 if (check_mouse_face
24218 && mouse_beg_col
< start
&& mouse_end_col
> i
)
24219 overlap_hl
= DRAW_MOUSE_FACE
;
24221 overlap_hl
= DRAW_NORMAL_TEXT
;
24224 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
24225 overlap_hl
, dummy_x
, last_x
);
24226 for (s
= h
; s
; s
= s
->next
)
24227 s
->background_filled_p
= 1;
24228 compute_overhangs_and_x (t
, head
->x
, 1);
24229 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
24232 /* Append glyphs strings for glyphs following the last glyph
24233 string tail that are overwritten by tail. The background of
24234 these strings has to be drawn because tail's foreground draws
24236 i
= right_overwritten (tail
);
24239 enum draw_glyphs_face overlap_hl
;
24241 if (check_mouse_face
24242 && mouse_beg_col
< i
&& mouse_end_col
> end
)
24243 overlap_hl
= DRAW_MOUSE_FACE
;
24245 overlap_hl
= DRAW_NORMAL_TEXT
;
24247 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
24248 overlap_hl
, x
, last_x
);
24249 /* Because BUILD_GLYPH_STRINGS updates the first argument,
24250 we don't have `end = i;' here. */
24251 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
24252 append_glyph_string_lists (&head
, &tail
, h
, t
);
24256 /* Append glyph strings for glyphs following the last glyph
24257 string tail that overwrite tail. The foreground of such
24258 glyphs has to be drawn because it writes into the background
24259 of tail. The background must not be drawn because it could
24260 paint over the foreground of following glyphs. */
24261 i
= right_overwriting (tail
);
24264 enum draw_glyphs_face overlap_hl
;
24265 if (check_mouse_face
24266 && mouse_beg_col
< i
&& mouse_end_col
> end
)
24267 overlap_hl
= DRAW_MOUSE_FACE
;
24269 overlap_hl
= DRAW_NORMAL_TEXT
;
24272 i
++; /* We must include the Ith glyph. */
24273 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
24274 overlap_hl
, x
, last_x
);
24275 for (s
= h
; s
; s
= s
->next
)
24276 s
->background_filled_p
= 1;
24277 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
24278 append_glyph_string_lists (&head
, &tail
, h
, t
);
24280 if (clip_head
|| clip_tail
)
24281 for (s
= head
; s
; s
= s
->next
)
24283 s
->clip_head
= clip_head
;
24284 s
->clip_tail
= clip_tail
;
24288 /* Draw all strings. */
24289 for (s
= head
; s
; s
= s
->next
)
24290 FRAME_RIF (f
)->draw_glyph_string (s
);
24293 /* When focus a sole frame and move horizontally, this sets on_p to 0
24294 causing a failure to erase prev cursor position. */
24295 if (area
== TEXT_AREA
24296 && !row
->full_width_p
24297 /* When drawing overlapping rows, only the glyph strings'
24298 foreground is drawn, which doesn't erase a cursor
24302 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
24303 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
24304 : (tail
? tail
->x
+ tail
->background_width
: x
));
24308 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
24309 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
24313 /* Value is the x-position up to which drawn, relative to AREA of W.
24314 This doesn't include parts drawn because of overhangs. */
24315 if (row
->full_width_p
)
24316 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
24318 x_reached
-= area_left
;
24320 RELEASE_HDC (hdc
, f
);
24325 /* Expand row matrix if too narrow. Don't expand if area
24328 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
24330 if (!it->f->fonts_changed \
24331 && (it->glyph_row->glyphs[area] \
24332 < it->glyph_row->glyphs[area + 1])) \
24334 it->w->ncols_scale_factor++; \
24335 it->f->fonts_changed = 1; \
24339 /* Store one glyph for IT->char_to_display in IT->glyph_row.
24340 Called from x_produce_glyphs when IT->glyph_row is non-null. */
24343 append_glyph (struct it
*it
)
24345 struct glyph
*glyph
;
24346 enum glyph_row_area area
= it
->area
;
24348 eassert (it
->glyph_row
);
24349 eassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
24351 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24352 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24354 /* If the glyph row is reversed, we need to prepend the glyph
24355 rather than append it. */
24356 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24360 /* Make room for the additional glyph. */
24361 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
24363 glyph
= it
->glyph_row
->glyphs
[area
];
24365 glyph
->charpos
= CHARPOS (it
->position
);
24366 glyph
->object
= it
->object
;
24367 if (it
->pixel_width
> 0)
24369 glyph
->pixel_width
= it
->pixel_width
;
24370 glyph
->padding_p
= 0;
24374 /* Assure at least 1-pixel width. Otherwise, cursor can't
24375 be displayed correctly. */
24376 glyph
->pixel_width
= 1;
24377 glyph
->padding_p
= 1;
24379 glyph
->ascent
= it
->ascent
;
24380 glyph
->descent
= it
->descent
;
24381 glyph
->voffset
= it
->voffset
;
24382 glyph
->type
= CHAR_GLYPH
;
24383 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24384 glyph
->multibyte_p
= it
->multibyte_p
;
24385 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24387 /* In R2L rows, the left and the right box edges need to be
24388 drawn in reverse direction. */
24389 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24390 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24394 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24395 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24397 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
24398 || it
->phys_descent
> it
->descent
);
24399 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
24400 glyph
->face_id
= it
->face_id
;
24401 glyph
->u
.ch
= it
->char_to_display
;
24402 glyph
->slice
.img
= null_glyph_slice
;
24403 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24406 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24407 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24409 glyph
->bidi_type
= it
->bidi_it
.type
;
24413 glyph
->resolved_level
= 0;
24414 glyph
->bidi_type
= UNKNOWN_BT
;
24416 ++it
->glyph_row
->used
[area
];
24419 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24422 /* Store one glyph for the composition IT->cmp_it.id in
24423 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
24427 append_composite_glyph (struct it
*it
)
24429 struct glyph
*glyph
;
24430 enum glyph_row_area area
= it
->area
;
24432 eassert (it
->glyph_row
);
24434 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24435 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24437 /* If the glyph row is reversed, we need to prepend the glyph
24438 rather than append it. */
24439 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
24443 /* Make room for the new glyph. */
24444 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
24446 glyph
= it
->glyph_row
->glyphs
[it
->area
];
24448 glyph
->charpos
= it
->cmp_it
.charpos
;
24449 glyph
->object
= it
->object
;
24450 glyph
->pixel_width
= it
->pixel_width
;
24451 glyph
->ascent
= it
->ascent
;
24452 glyph
->descent
= it
->descent
;
24453 glyph
->voffset
= it
->voffset
;
24454 glyph
->type
= COMPOSITE_GLYPH
;
24455 if (it
->cmp_it
.ch
< 0)
24457 glyph
->u
.cmp
.automatic
= 0;
24458 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
24459 glyph
->slice
.cmp
.from
= glyph
->slice
.cmp
.to
= 0;
24463 glyph
->u
.cmp
.automatic
= 1;
24464 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
24465 glyph
->slice
.cmp
.from
= it
->cmp_it
.from
;
24466 glyph
->slice
.cmp
.to
= it
->cmp_it
.to
- 1;
24468 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24469 glyph
->multibyte_p
= it
->multibyte_p
;
24470 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24472 /* In R2L rows, the left and the right box edges need to be
24473 drawn in reverse direction. */
24474 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24475 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24479 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24480 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24482 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
24483 || it
->phys_descent
> it
->descent
);
24484 glyph
->padding_p
= 0;
24485 glyph
->glyph_not_available_p
= 0;
24486 glyph
->face_id
= it
->face_id
;
24487 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24490 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24491 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24493 glyph
->bidi_type
= it
->bidi_it
.type
;
24495 ++it
->glyph_row
->used
[area
];
24498 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24502 /* Change IT->ascent and IT->height according to the setting of
24506 take_vertical_position_into_account (struct it
*it
)
24510 if (it
->voffset
< 0)
24511 /* Increase the ascent so that we can display the text higher
24513 it
->ascent
-= it
->voffset
;
24515 /* Increase the descent so that we can display the text lower
24517 it
->descent
+= it
->voffset
;
24522 /* Produce glyphs/get display metrics for the image IT is loaded with.
24523 See the description of struct display_iterator in dispextern.h for
24524 an overview of struct display_iterator. */
24527 produce_image_glyph (struct it
*it
)
24531 int glyph_ascent
, crop
;
24532 struct glyph_slice slice
;
24534 eassert (it
->what
== IT_IMAGE
);
24536 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24538 /* Make sure X resources of the face is loaded. */
24539 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24541 if (it
->image_id
< 0)
24543 /* Fringe bitmap. */
24544 it
->ascent
= it
->phys_ascent
= 0;
24545 it
->descent
= it
->phys_descent
= 0;
24546 it
->pixel_width
= 0;
24551 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
24553 /* Make sure X resources of the image is loaded. */
24554 prepare_image_for_display (it
->f
, img
);
24556 slice
.x
= slice
.y
= 0;
24557 slice
.width
= img
->width
;
24558 slice
.height
= img
->height
;
24560 if (INTEGERP (it
->slice
.x
))
24561 slice
.x
= XINT (it
->slice
.x
);
24562 else if (FLOATP (it
->slice
.x
))
24563 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
24565 if (INTEGERP (it
->slice
.y
))
24566 slice
.y
= XINT (it
->slice
.y
);
24567 else if (FLOATP (it
->slice
.y
))
24568 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
24570 if (INTEGERP (it
->slice
.width
))
24571 slice
.width
= XINT (it
->slice
.width
);
24572 else if (FLOATP (it
->slice
.width
))
24573 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
24575 if (INTEGERP (it
->slice
.height
))
24576 slice
.height
= XINT (it
->slice
.height
);
24577 else if (FLOATP (it
->slice
.height
))
24578 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
24580 if (slice
.x
>= img
->width
)
24581 slice
.x
= img
->width
;
24582 if (slice
.y
>= img
->height
)
24583 slice
.y
= img
->height
;
24584 if (slice
.x
+ slice
.width
>= img
->width
)
24585 slice
.width
= img
->width
- slice
.x
;
24586 if (slice
.y
+ slice
.height
> img
->height
)
24587 slice
.height
= img
->height
- slice
.y
;
24589 if (slice
.width
== 0 || slice
.height
== 0)
24592 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
24594 it
->descent
= slice
.height
- glyph_ascent
;
24596 it
->descent
+= img
->vmargin
;
24597 if (slice
.y
+ slice
.height
== img
->height
)
24598 it
->descent
+= img
->vmargin
;
24599 it
->phys_descent
= it
->descent
;
24601 it
->pixel_width
= slice
.width
;
24603 it
->pixel_width
+= img
->hmargin
;
24604 if (slice
.x
+ slice
.width
== img
->width
)
24605 it
->pixel_width
+= img
->hmargin
;
24607 /* It's quite possible for images to have an ascent greater than
24608 their height, so don't get confused in that case. */
24609 if (it
->descent
< 0)
24614 if (face
->box
!= FACE_NO_BOX
)
24616 if (face
->box_line_width
> 0)
24619 it
->ascent
+= face
->box_line_width
;
24620 if (slice
.y
+ slice
.height
== img
->height
)
24621 it
->descent
+= face
->box_line_width
;
24624 if (it
->start_of_box_run_p
&& slice
.x
== 0)
24625 it
->pixel_width
+= eabs (face
->box_line_width
);
24626 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
24627 it
->pixel_width
+= eabs (face
->box_line_width
);
24630 take_vertical_position_into_account (it
);
24632 /* Automatically crop wide image glyphs at right edge so we can
24633 draw the cursor on same display row. */
24634 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
24635 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
24637 it
->pixel_width
-= crop
;
24638 slice
.width
-= crop
;
24643 struct glyph
*glyph
;
24644 enum glyph_row_area area
= it
->area
;
24646 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24647 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24649 glyph
->charpos
= CHARPOS (it
->position
);
24650 glyph
->object
= it
->object
;
24651 glyph
->pixel_width
= it
->pixel_width
;
24652 glyph
->ascent
= glyph_ascent
;
24653 glyph
->descent
= it
->descent
;
24654 glyph
->voffset
= it
->voffset
;
24655 glyph
->type
= IMAGE_GLYPH
;
24656 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24657 glyph
->multibyte_p
= it
->multibyte_p
;
24658 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24660 /* In R2L rows, the left and the right box edges need to be
24661 drawn in reverse direction. */
24662 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24663 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24667 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24668 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24670 glyph
->overlaps_vertically_p
= 0;
24671 glyph
->padding_p
= 0;
24672 glyph
->glyph_not_available_p
= 0;
24673 glyph
->face_id
= it
->face_id
;
24674 glyph
->u
.img_id
= img
->id
;
24675 glyph
->slice
.img
= slice
;
24676 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24679 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24680 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24682 glyph
->bidi_type
= it
->bidi_it
.type
;
24684 ++it
->glyph_row
->used
[area
];
24687 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24692 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
24693 of the glyph, WIDTH and HEIGHT are the width and height of the
24694 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
24697 append_stretch_glyph (struct it
*it
, Lisp_Object object
,
24698 int width
, int height
, int ascent
)
24700 struct glyph
*glyph
;
24701 enum glyph_row_area area
= it
->area
;
24703 eassert (ascent
>= 0 && ascent
<= height
);
24705 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24706 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24708 /* If the glyph row is reversed, we need to prepend the glyph
24709 rather than append it. */
24710 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24714 /* Make room for the additional glyph. */
24715 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
24717 glyph
= it
->glyph_row
->glyphs
[area
];
24719 glyph
->charpos
= CHARPOS (it
->position
);
24720 glyph
->object
= object
;
24721 glyph
->pixel_width
= width
;
24722 glyph
->ascent
= ascent
;
24723 glyph
->descent
= height
- ascent
;
24724 glyph
->voffset
= it
->voffset
;
24725 glyph
->type
= STRETCH_GLYPH
;
24726 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24727 glyph
->multibyte_p
= it
->multibyte_p
;
24728 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24730 /* In R2L rows, the left and the right box edges need to be
24731 drawn in reverse direction. */
24732 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24733 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24737 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24738 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24740 glyph
->overlaps_vertically_p
= 0;
24741 glyph
->padding_p
= 0;
24742 glyph
->glyph_not_available_p
= 0;
24743 glyph
->face_id
= it
->face_id
;
24744 glyph
->u
.stretch
.ascent
= ascent
;
24745 glyph
->u
.stretch
.height
= height
;
24746 glyph
->slice
.img
= null_glyph_slice
;
24747 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24750 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24751 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24753 glyph
->bidi_type
= it
->bidi_it
.type
;
24757 glyph
->resolved_level
= 0;
24758 glyph
->bidi_type
= UNKNOWN_BT
;
24760 ++it
->glyph_row
->used
[area
];
24763 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24766 #endif /* HAVE_WINDOW_SYSTEM */
24768 /* Produce a stretch glyph for iterator IT. IT->object is the value
24769 of the glyph property displayed. The value must be a list
24770 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
24773 1. `:width WIDTH' specifies that the space should be WIDTH *
24774 canonical char width wide. WIDTH may be an integer or floating
24777 2. `:relative-width FACTOR' specifies that the width of the stretch
24778 should be computed from the width of the first character having the
24779 `glyph' property, and should be FACTOR times that width.
24781 3. `:align-to HPOS' specifies that the space should be wide enough
24782 to reach HPOS, a value in canonical character units.
24784 Exactly one of the above pairs must be present.
24786 4. `:height HEIGHT' specifies that the height of the stretch produced
24787 should be HEIGHT, measured in canonical character units.
24789 5. `:relative-height FACTOR' specifies that the height of the
24790 stretch should be FACTOR times the height of the characters having
24791 the glyph property.
24793 Either none or exactly one of 4 or 5 must be present.
24795 6. `:ascent ASCENT' specifies that ASCENT percent of the height
24796 of the stretch should be used for the ascent of the stretch.
24797 ASCENT must be in the range 0 <= ASCENT <= 100. */
24800 produce_stretch_glyph (struct it
*it
)
24802 /* (space :width WIDTH :height HEIGHT ...) */
24803 Lisp_Object prop
, plist
;
24804 int width
= 0, height
= 0, align_to
= -1;
24805 int zero_width_ok_p
= 0;
24807 struct font
*font
= NULL
;
24809 #ifdef HAVE_WINDOW_SYSTEM
24811 int zero_height_ok_p
= 0;
24813 if (FRAME_WINDOW_P (it
->f
))
24815 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24816 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24817 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24821 /* List should start with `space'. */
24822 eassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
24823 plist
= XCDR (it
->object
);
24825 /* Compute the width of the stretch. */
24826 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
24827 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
24829 /* Absolute width `:width WIDTH' specified and valid. */
24830 zero_width_ok_p
= 1;
24833 #ifdef HAVE_WINDOW_SYSTEM
24834 else if (FRAME_WINDOW_P (it
->f
)
24835 && (prop
= Fplist_get (plist
, QCrelative_width
), NUMVAL (prop
) > 0))
24837 /* Relative width `:relative-width FACTOR' specified and valid.
24838 Compute the width of the characters having the `glyph'
24841 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
24844 if (it
->multibyte_p
)
24845 it2
.c
= it2
.char_to_display
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
24848 it2
.c
= it2
.char_to_display
= *p
, it2
.len
= 1;
24849 if (! ASCII_CHAR_P (it2
.c
))
24850 it2
.char_to_display
= BYTE8_TO_CHAR (it2
.c
);
24853 it2
.glyph_row
= NULL
;
24854 it2
.what
= IT_CHARACTER
;
24855 x_produce_glyphs (&it2
);
24856 width
= NUMVAL (prop
) * it2
.pixel_width
;
24858 #endif /* HAVE_WINDOW_SYSTEM */
24859 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
24860 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
24862 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
24863 align_to
= (align_to
< 0
24865 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
24866 else if (align_to
< 0)
24867 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
24868 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
24869 zero_width_ok_p
= 1;
24872 /* Nothing specified -> width defaults to canonical char width. */
24873 width
= FRAME_COLUMN_WIDTH (it
->f
);
24875 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
24878 #ifdef HAVE_WINDOW_SYSTEM
24879 /* Compute height. */
24880 if (FRAME_WINDOW_P (it
->f
))
24882 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
24883 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
24886 zero_height_ok_p
= 1;
24888 else if (prop
= Fplist_get (plist
, QCrelative_height
),
24890 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
24892 height
= FONT_HEIGHT (font
);
24894 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
24897 /* Compute percentage of height used for ascent. If
24898 `:ascent ASCENT' is present and valid, use that. Otherwise,
24899 derive the ascent from the font in use. */
24900 if (prop
= Fplist_get (plist
, QCascent
),
24901 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
24902 ascent
= height
* NUMVAL (prop
) / 100.0;
24903 else if (!NILP (prop
)
24904 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
24905 ascent
= min (max (0, (int)tem
), height
);
24907 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
24910 #endif /* HAVE_WINDOW_SYSTEM */
24913 if (width
> 0 && it
->line_wrap
!= TRUNCATE
24914 && it
->current_x
+ width
> it
->last_visible_x
)
24916 width
= it
->last_visible_x
- it
->current_x
;
24917 #ifdef HAVE_WINDOW_SYSTEM
24918 /* Subtract one more pixel from the stretch width, but only on
24919 GUI frames, since on a TTY each glyph is one "pixel" wide. */
24920 width
-= FRAME_WINDOW_P (it
->f
);
24924 if (width
> 0 && height
> 0 && it
->glyph_row
)
24926 Lisp_Object o_object
= it
->object
;
24927 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
24930 if (!STRINGP (object
))
24931 object
= it
->w
->contents
;
24932 #ifdef HAVE_WINDOW_SYSTEM
24933 if (FRAME_WINDOW_P (it
->f
))
24934 append_stretch_glyph (it
, object
, width
, height
, ascent
);
24938 it
->object
= object
;
24939 it
->char_to_display
= ' ';
24940 it
->pixel_width
= it
->len
= 1;
24942 tty_append_glyph (it
);
24943 it
->object
= o_object
;
24947 it
->pixel_width
= width
;
24948 #ifdef HAVE_WINDOW_SYSTEM
24949 if (FRAME_WINDOW_P (it
->f
))
24951 it
->ascent
= it
->phys_ascent
= ascent
;
24952 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
24953 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
24954 take_vertical_position_into_account (it
);
24958 it
->nglyphs
= width
;
24961 /* Get information about special display element WHAT in an
24962 environment described by IT. WHAT is one of IT_TRUNCATION or
24963 IT_CONTINUATION. Maybe produce glyphs for WHAT if IT has a
24964 non-null glyph_row member. This function ensures that fields like
24965 face_id, c, len of IT are left untouched. */
24968 produce_special_glyphs (struct it
*it
, enum display_element_type what
)
24975 temp_it
.object
= make_number (0);
24976 memset (&temp_it
.current
, 0, sizeof temp_it
.current
);
24978 if (what
== IT_CONTINUATION
)
24980 /* Continuation glyph. For R2L lines, we mirror it by hand. */
24981 if (it
->bidi_it
.paragraph_dir
== R2L
)
24982 SET_GLYPH_FROM_CHAR (glyph
, '/');
24984 SET_GLYPH_FROM_CHAR (glyph
, '\\');
24986 && (gc
= DISP_CONTINUE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
24988 /* FIXME: Should we mirror GC for R2L lines? */
24989 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
24990 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
24993 else if (what
== IT_TRUNCATION
)
24995 /* Truncation glyph. */
24996 SET_GLYPH_FROM_CHAR (glyph
, '$');
24998 && (gc
= DISP_TRUNC_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
25000 /* FIXME: Should we mirror GC for R2L lines? */
25001 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
25002 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
25008 #ifdef HAVE_WINDOW_SYSTEM
25009 /* On a GUI frame, when the right fringe (left fringe for R2L rows)
25010 is turned off, we precede the truncation/continuation glyphs by a
25011 stretch glyph whose width is computed such that these special
25012 glyphs are aligned at the window margin, even when very different
25013 fonts are used in different glyph rows. */
25014 if (FRAME_WINDOW_P (temp_it
.f
)
25015 /* init_iterator calls this with it->glyph_row == NULL, and it
25016 wants only the pixel width of the truncation/continuation
25018 && temp_it
.glyph_row
25019 /* insert_left_trunc_glyphs calls us at the beginning of the
25020 row, and it has its own calculation of the stretch glyph
25022 && temp_it
.glyph_row
->used
[TEXT_AREA
] > 0
25023 && (temp_it
.glyph_row
->reversed_p
25024 ? WINDOW_LEFT_FRINGE_WIDTH (temp_it
.w
)
25025 : WINDOW_RIGHT_FRINGE_WIDTH (temp_it
.w
)) == 0)
25027 int stretch_width
= temp_it
.last_visible_x
- temp_it
.current_x
;
25029 if (stretch_width
> 0)
25031 struct face
*face
= FACE_FROM_ID (temp_it
.f
, temp_it
.face_id
);
25032 struct font
*font
=
25033 face
->font
? face
->font
: FRAME_FONT (temp_it
.f
);
25034 int stretch_ascent
=
25035 (((temp_it
.ascent
+ temp_it
.descent
)
25036 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
25038 append_stretch_glyph (&temp_it
, make_number (0), stretch_width
,
25039 temp_it
.ascent
+ temp_it
.descent
,
25046 temp_it
.what
= IT_CHARACTER
;
25048 temp_it
.c
= temp_it
.char_to_display
= GLYPH_CHAR (glyph
);
25049 temp_it
.face_id
= GLYPH_FACE (glyph
);
25050 temp_it
.len
= CHAR_BYTES (temp_it
.c
);
25052 PRODUCE_GLYPHS (&temp_it
);
25053 it
->pixel_width
= temp_it
.pixel_width
;
25054 it
->nglyphs
= temp_it
.pixel_width
;
25057 #ifdef HAVE_WINDOW_SYSTEM
25059 /* Calculate line-height and line-spacing properties.
25060 An integer value specifies explicit pixel value.
25061 A float value specifies relative value to current face height.
25062 A cons (float . face-name) specifies relative value to
25063 height of specified face font.
25065 Returns height in pixels, or nil. */
25069 calc_line_height_property (struct it
*it
, Lisp_Object val
, struct font
*font
,
25070 int boff
, int override
)
25072 Lisp_Object face_name
= Qnil
;
25073 int ascent
, descent
, height
;
25075 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
25080 face_name
= XCAR (val
);
25082 if (!NUMBERP (val
))
25083 val
= make_number (1);
25084 if (NILP (face_name
))
25086 height
= it
->ascent
+ it
->descent
;
25091 if (NILP (face_name
))
25093 font
= FRAME_FONT (it
->f
);
25094 boff
= FRAME_BASELINE_OFFSET (it
->f
);
25096 else if (EQ (face_name
, Qt
))
25105 face_id
= lookup_named_face (it
->f
, face_name
, 0);
25107 return make_number (-1);
25109 face
= FACE_FROM_ID (it
->f
, face_id
);
25112 return make_number (-1);
25113 boff
= font
->baseline_offset
;
25114 if (font
->vertical_centering
)
25115 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
25118 ascent
= FONT_BASE (font
) + boff
;
25119 descent
= FONT_DESCENT (font
) - boff
;
25123 it
->override_ascent
= ascent
;
25124 it
->override_descent
= descent
;
25125 it
->override_boff
= boff
;
25128 height
= ascent
+ descent
;
25132 height
= (int)(XFLOAT_DATA (val
) * height
);
25133 else if (INTEGERP (val
))
25134 height
*= XINT (val
);
25136 return make_number (height
);
25140 /* Append a glyph for a glyphless character to IT->glyph_row. FACE_ID
25141 is a face ID to be used for the glyph. FOR_NO_FONT is nonzero if
25142 and only if this is for a character for which no font was found.
25144 If the display method (it->glyphless_method) is
25145 GLYPHLESS_DISPLAY_ACRONYM or GLYPHLESS_DISPLAY_HEX_CODE, LEN is a
25146 length of the acronym or the hexadecimal string, UPPER_XOFF and
25147 UPPER_YOFF are pixel offsets for the upper part of the string,
25148 LOWER_XOFF and LOWER_YOFF are for the lower part.
25150 For the other display methods, LEN through LOWER_YOFF are zero. */
25153 append_glyphless_glyph (struct it
*it
, int face_id
, int for_no_font
, int len
,
25154 short upper_xoff
, short upper_yoff
,
25155 short lower_xoff
, short lower_yoff
)
25157 struct glyph
*glyph
;
25158 enum glyph_row_area area
= it
->area
;
25160 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
25161 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
25163 /* If the glyph row is reversed, we need to prepend the glyph
25164 rather than append it. */
25165 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
25169 /* Make room for the additional glyph. */
25170 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
25172 glyph
= it
->glyph_row
->glyphs
[area
];
25174 glyph
->charpos
= CHARPOS (it
->position
);
25175 glyph
->object
= it
->object
;
25176 glyph
->pixel_width
= it
->pixel_width
;
25177 glyph
->ascent
= it
->ascent
;
25178 glyph
->descent
= it
->descent
;
25179 glyph
->voffset
= it
->voffset
;
25180 glyph
->type
= GLYPHLESS_GLYPH
;
25181 glyph
->u
.glyphless
.method
= it
->glyphless_method
;
25182 glyph
->u
.glyphless
.for_no_font
= for_no_font
;
25183 glyph
->u
.glyphless
.len
= len
;
25184 glyph
->u
.glyphless
.ch
= it
->c
;
25185 glyph
->slice
.glyphless
.upper_xoff
= upper_xoff
;
25186 glyph
->slice
.glyphless
.upper_yoff
= upper_yoff
;
25187 glyph
->slice
.glyphless
.lower_xoff
= lower_xoff
;
25188 glyph
->slice
.glyphless
.lower_yoff
= lower_yoff
;
25189 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
25190 glyph
->multibyte_p
= it
->multibyte_p
;
25191 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
25193 /* In R2L rows, the left and the right box edges need to be
25194 drawn in reverse direction. */
25195 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
25196 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
25200 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
25201 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
25203 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
25204 || it
->phys_descent
> it
->descent
);
25205 glyph
->padding_p
= 0;
25206 glyph
->glyph_not_available_p
= 0;
25207 glyph
->face_id
= face_id
;
25208 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
25211 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
25212 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
25214 glyph
->bidi_type
= it
->bidi_it
.type
;
25216 ++it
->glyph_row
->used
[area
];
25219 IT_EXPAND_MATRIX_WIDTH (it
, area
);
25223 /* Produce a glyph for a glyphless character for iterator IT.
25224 IT->glyphless_method specifies which method to use for displaying
25225 the character. See the description of enum
25226 glyphless_display_method in dispextern.h for the detail.
25228 FOR_NO_FONT is nonzero if and only if this is for a character for
25229 which no font was found. ACRONYM, if non-nil, is an acronym string
25230 for the character. */
25233 produce_glyphless_glyph (struct it
*it
, int for_no_font
, Lisp_Object acronym
)
25238 int base_width
, base_height
, width
, height
;
25239 short upper_xoff
, upper_yoff
, lower_xoff
, lower_yoff
;
25242 /* Get the metrics of the base font. We always refer to the current
25244 face
= FACE_FROM_ID (it
->f
, it
->face_id
)->ascii_face
;
25245 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
25246 it
->ascent
= FONT_BASE (font
) + font
->baseline_offset
;
25247 it
->descent
= FONT_DESCENT (font
) - font
->baseline_offset
;
25248 base_height
= it
->ascent
+ it
->descent
;
25249 base_width
= font
->average_width
;
25251 face_id
= merge_glyphless_glyph_face (it
);
25253 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_THIN_SPACE
)
25255 it
->pixel_width
= THIN_SPACE_WIDTH
;
25257 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
25259 else if (it
->glyphless_method
== GLYPHLESS_DISPLAY_EMPTY_BOX
)
25261 width
= CHAR_WIDTH (it
->c
);
25264 else if (width
> 4)
25266 it
->pixel_width
= base_width
* width
;
25268 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
25274 unsigned int code
[6];
25276 int ascent
, descent
;
25277 struct font_metrics metrics_upper
, metrics_lower
;
25279 face
= FACE_FROM_ID (it
->f
, face_id
);
25280 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
25281 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
25283 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_ACRONYM
)
25285 if (! STRINGP (acronym
) && CHAR_TABLE_P (Vglyphless_char_display
))
25286 acronym
= CHAR_TABLE_REF (Vglyphless_char_display
, it
->c
);
25287 if (CONSP (acronym
))
25288 acronym
= XCAR (acronym
);
25289 str
= STRINGP (acronym
) ? SSDATA (acronym
) : "";
25293 eassert (it
->glyphless_method
== GLYPHLESS_DISPLAY_HEX_CODE
);
25294 sprintf (buf
, "%0*X", it
->c
< 0x10000 ? 4 : 6, it
->c
);
25297 for (len
= 0; str
[len
] && ASCII_BYTE_P (str
[len
]) && len
< 6; len
++)
25298 code
[len
] = font
->driver
->encode_char (font
, str
[len
]);
25299 upper_len
= (len
+ 1) / 2;
25300 font
->driver
->text_extents (font
, code
, upper_len
,
25302 font
->driver
->text_extents (font
, code
+ upper_len
, len
- upper_len
,
25307 /* +4 is for vertical bars of a box plus 1-pixel spaces at both side. */
25308 width
= max (metrics_upper
.width
, metrics_lower
.width
) + 4;
25309 upper_xoff
= upper_yoff
= 2; /* the typical case */
25310 if (base_width
>= width
)
25312 /* Align the upper to the left, the lower to the right. */
25313 it
->pixel_width
= base_width
;
25314 lower_xoff
= base_width
- 2 - metrics_lower
.width
;
25318 /* Center the shorter one. */
25319 it
->pixel_width
= width
;
25320 if (metrics_upper
.width
>= metrics_lower
.width
)
25321 lower_xoff
= (width
- metrics_lower
.width
) / 2;
25324 /* FIXME: This code doesn't look right. It formerly was
25325 missing the "lower_xoff = 0;", which couldn't have
25326 been right since it left lower_xoff uninitialized. */
25328 upper_xoff
= (width
- metrics_upper
.width
) / 2;
25332 /* +5 is for horizontal bars of a box plus 1-pixel spaces at
25333 top, bottom, and between upper and lower strings. */
25334 height
= (metrics_upper
.ascent
+ metrics_upper
.descent
25335 + metrics_lower
.ascent
+ metrics_lower
.descent
) + 5;
25336 /* Center vertically.
25337 H:base_height, D:base_descent
25338 h:height, ld:lower_descent, la:lower_ascent, ud:upper_descent
25340 ascent = - (D - H/2 - h/2 + 1); "+ 1" for rounding up
25341 descent = D - H/2 + h/2;
25342 lower_yoff = descent - 2 - ld;
25343 upper_yoff = lower_yoff - la - 1 - ud; */
25344 ascent
= - (it
->descent
- (base_height
+ height
+ 1) / 2);
25345 descent
= it
->descent
- (base_height
- height
) / 2;
25346 lower_yoff
= descent
- 2 - metrics_lower
.descent
;
25347 upper_yoff
= (lower_yoff
- metrics_lower
.ascent
- 1
25348 - metrics_upper
.descent
);
25349 /* Don't make the height shorter than the base height. */
25350 if (height
> base_height
)
25352 it
->ascent
= ascent
;
25353 it
->descent
= descent
;
25357 it
->phys_ascent
= it
->ascent
;
25358 it
->phys_descent
= it
->descent
;
25360 append_glyphless_glyph (it
, face_id
, for_no_font
, len
,
25361 upper_xoff
, upper_yoff
,
25362 lower_xoff
, lower_yoff
);
25364 take_vertical_position_into_account (it
);
25369 Produce glyphs/get display metrics for the display element IT is
25370 loaded with. See the description of struct it in dispextern.h
25371 for an overview of struct it. */
25374 x_produce_glyphs (struct it
*it
)
25376 int extra_line_spacing
= it
->extra_line_spacing
;
25378 it
->glyph_not_available_p
= 0;
25380 if (it
->what
== IT_CHARACTER
)
25383 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25384 struct font
*font
= face
->font
;
25385 struct font_metrics
*pcm
= NULL
;
25386 int boff
; /* Baseline offset. */
25390 /* When no suitable font is found, display this character by
25391 the method specified in the first extra slot of
25392 Vglyphless_char_display. */
25393 Lisp_Object acronym
= lookup_glyphless_char_display (-1, it
);
25395 eassert (it
->what
== IT_GLYPHLESS
);
25396 produce_glyphless_glyph (it
, 1, STRINGP (acronym
) ? acronym
: Qnil
);
25400 boff
= font
->baseline_offset
;
25401 if (font
->vertical_centering
)
25402 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
25404 if (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t')
25410 if (it
->override_ascent
>= 0)
25412 it
->ascent
= it
->override_ascent
;
25413 it
->descent
= it
->override_descent
;
25414 boff
= it
->override_boff
;
25418 it
->ascent
= FONT_BASE (font
) + boff
;
25419 it
->descent
= FONT_DESCENT (font
) - boff
;
25422 if (get_char_glyph_code (it
->char_to_display
, font
, &char2b
))
25424 pcm
= get_per_char_metric (font
, &char2b
);
25425 if (pcm
->width
== 0
25426 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
25432 it
->phys_ascent
= pcm
->ascent
+ boff
;
25433 it
->phys_descent
= pcm
->descent
- boff
;
25434 it
->pixel_width
= pcm
->width
;
25438 it
->glyph_not_available_p
= 1;
25439 it
->phys_ascent
= it
->ascent
;
25440 it
->phys_descent
= it
->descent
;
25441 it
->pixel_width
= font
->space_width
;
25444 if (it
->constrain_row_ascent_descent_p
)
25446 if (it
->descent
> it
->max_descent
)
25448 it
->ascent
+= it
->descent
- it
->max_descent
;
25449 it
->descent
= it
->max_descent
;
25451 if (it
->ascent
> it
->max_ascent
)
25453 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
25454 it
->ascent
= it
->max_ascent
;
25456 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
25457 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
25458 extra_line_spacing
= 0;
25461 /* If this is a space inside a region of text with
25462 `space-width' property, change its width. */
25463 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
25465 it
->pixel_width
*= XFLOATINT (it
->space_width
);
25467 /* If face has a box, add the box thickness to the character
25468 height. If character has a box line to the left and/or
25469 right, add the box line width to the character's width. */
25470 if (face
->box
!= FACE_NO_BOX
)
25472 int thick
= face
->box_line_width
;
25476 it
->ascent
+= thick
;
25477 it
->descent
+= thick
;
25482 if (it
->start_of_box_run_p
)
25483 it
->pixel_width
+= thick
;
25484 if (it
->end_of_box_run_p
)
25485 it
->pixel_width
+= thick
;
25488 /* If face has an overline, add the height of the overline
25489 (1 pixel) and a 1 pixel margin to the character height. */
25490 if (face
->overline_p
)
25491 it
->ascent
+= overline_margin
;
25493 if (it
->constrain_row_ascent_descent_p
)
25495 if (it
->ascent
> it
->max_ascent
)
25496 it
->ascent
= it
->max_ascent
;
25497 if (it
->descent
> it
->max_descent
)
25498 it
->descent
= it
->max_descent
;
25501 take_vertical_position_into_account (it
);
25503 /* If we have to actually produce glyphs, do it. */
25508 /* Translate a space with a `space-width' property
25509 into a stretch glyph. */
25510 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
25511 / FONT_HEIGHT (font
));
25512 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
25513 it
->ascent
+ it
->descent
, ascent
);
25518 /* If characters with lbearing or rbearing are displayed
25519 in this line, record that fact in a flag of the
25520 glyph row. This is used to optimize X output code. */
25521 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
25522 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25524 if (! stretched_p
&& it
->pixel_width
== 0)
25525 /* We assure that all visible glyphs have at least 1-pixel
25527 it
->pixel_width
= 1;
25529 else if (it
->char_to_display
== '\n')
25531 /* A newline has no width, but we need the height of the
25532 line. But if previous part of the line sets a height,
25533 don't increase that height. */
25535 Lisp_Object height
;
25536 Lisp_Object total_height
= Qnil
;
25538 it
->override_ascent
= -1;
25539 it
->pixel_width
= 0;
25542 height
= get_it_property (it
, Qline_height
);
25543 /* Split (line-height total-height) list. */
25545 && CONSP (XCDR (height
))
25546 && NILP (XCDR (XCDR (height
))))
25548 total_height
= XCAR (XCDR (height
));
25549 height
= XCAR (height
);
25551 height
= calc_line_height_property (it
, height
, font
, boff
, 1);
25553 if (it
->override_ascent
>= 0)
25555 it
->ascent
= it
->override_ascent
;
25556 it
->descent
= it
->override_descent
;
25557 boff
= it
->override_boff
;
25561 it
->ascent
= FONT_BASE (font
) + boff
;
25562 it
->descent
= FONT_DESCENT (font
) - boff
;
25565 if (EQ (height
, Qt
))
25567 if (it
->descent
> it
->max_descent
)
25569 it
->ascent
+= it
->descent
- it
->max_descent
;
25570 it
->descent
= it
->max_descent
;
25572 if (it
->ascent
> it
->max_ascent
)
25574 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
25575 it
->ascent
= it
->max_ascent
;
25577 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
25578 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
25579 it
->constrain_row_ascent_descent_p
= 1;
25580 extra_line_spacing
= 0;
25584 Lisp_Object spacing
;
25586 it
->phys_ascent
= it
->ascent
;
25587 it
->phys_descent
= it
->descent
;
25589 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
25590 && face
->box
!= FACE_NO_BOX
25591 && face
->box_line_width
> 0)
25593 it
->ascent
+= face
->box_line_width
;
25594 it
->descent
+= face
->box_line_width
;
25597 && XINT (height
) > it
->ascent
+ it
->descent
)
25598 it
->ascent
= XINT (height
) - it
->descent
;
25600 if (!NILP (total_height
))
25601 spacing
= calc_line_height_property (it
, total_height
, font
, boff
, 0);
25604 spacing
= get_it_property (it
, Qline_spacing
);
25605 spacing
= calc_line_height_property (it
, spacing
, font
, boff
, 0);
25607 if (INTEGERP (spacing
))
25609 extra_line_spacing
= XINT (spacing
);
25610 if (!NILP (total_height
))
25611 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
25615 else /* i.e. (it->char_to_display == '\t') */
25617 if (font
->space_width
> 0)
25619 int tab_width
= it
->tab_width
* font
->space_width
;
25620 int x
= it
->current_x
+ it
->continuation_lines_width
;
25621 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
25623 /* If the distance from the current position to the next tab
25624 stop is less than a space character width, use the
25625 tab stop after that. */
25626 if (next_tab_x
- x
< font
->space_width
)
25627 next_tab_x
+= tab_width
;
25629 it
->pixel_width
= next_tab_x
- x
;
25631 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
25632 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
25636 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
25637 it
->ascent
+ it
->descent
, it
->ascent
);
25642 it
->pixel_width
= 0;
25647 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
25649 /* A static composition.
25651 Note: A composition is represented as one glyph in the
25652 glyph matrix. There are no padding glyphs.
25654 Important note: pixel_width, ascent, and descent are the
25655 values of what is drawn by draw_glyphs (i.e. the values of
25656 the overall glyphs composed). */
25657 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25658 int boff
; /* baseline offset */
25659 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
25660 int glyph_len
= cmp
->glyph_len
;
25661 struct font
*font
= face
->font
;
25665 /* If we have not yet calculated pixel size data of glyphs of
25666 the composition for the current face font, calculate them
25667 now. Theoretically, we have to check all fonts for the
25668 glyphs, but that requires much time and memory space. So,
25669 here we check only the font of the first glyph. This may
25670 lead to incorrect display, but it's very rare, and C-l
25671 (recenter-top-bottom) can correct the display anyway. */
25672 if (! cmp
->font
|| cmp
->font
!= font
)
25674 /* Ascent and descent of the font of the first character
25675 of this composition (adjusted by baseline offset).
25676 Ascent and descent of overall glyphs should not be less
25677 than these, respectively. */
25678 int font_ascent
, font_descent
, font_height
;
25679 /* Bounding box of the overall glyphs. */
25680 int leftmost
, rightmost
, lowest
, highest
;
25681 int lbearing
, rbearing
;
25682 int i
, width
, ascent
, descent
;
25683 int left_padded
= 0, right_padded
= 0;
25684 int c
IF_LINT (= 0); /* cmp->glyph_len can't be zero; see Bug#8512 */
25686 struct font_metrics
*pcm
;
25687 int font_not_found_p
;
25690 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
25691 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
25693 if (glyph_len
< cmp
->glyph_len
)
25695 for (i
= 0; i
< glyph_len
; i
++)
25697 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
25699 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
25704 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
25705 : IT_CHARPOS (*it
));
25706 /* If no suitable font is found, use the default font. */
25707 font_not_found_p
= font
== NULL
;
25708 if (font_not_found_p
)
25710 face
= face
->ascii_face
;
25713 boff
= font
->baseline_offset
;
25714 if (font
->vertical_centering
)
25715 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
25716 font_ascent
= FONT_BASE (font
) + boff
;
25717 font_descent
= FONT_DESCENT (font
) - boff
;
25718 font_height
= FONT_HEIGHT (font
);
25723 if (! font_not_found_p
)
25725 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
25727 pcm
= get_per_char_metric (font
, &char2b
);
25730 /* Initialize the bounding box. */
25733 width
= cmp
->glyph_len
> 0 ? pcm
->width
: 0;
25734 ascent
= pcm
->ascent
;
25735 descent
= pcm
->descent
;
25736 lbearing
= pcm
->lbearing
;
25737 rbearing
= pcm
->rbearing
;
25741 width
= cmp
->glyph_len
> 0 ? font
->space_width
: 0;
25742 ascent
= FONT_BASE (font
);
25743 descent
= FONT_DESCENT (font
);
25750 lowest
= - descent
+ boff
;
25751 highest
= ascent
+ boff
;
25753 if (! font_not_found_p
25754 && font
->default_ascent
25755 && CHAR_TABLE_P (Vuse_default_ascent
)
25756 && !NILP (Faref (Vuse_default_ascent
,
25757 make_number (it
->char_to_display
))))
25758 highest
= font
->default_ascent
+ boff
;
25760 /* Draw the first glyph at the normal position. It may be
25761 shifted to right later if some other glyphs are drawn
25763 cmp
->offsets
[i
* 2] = 0;
25764 cmp
->offsets
[i
* 2 + 1] = boff
;
25765 cmp
->lbearing
= lbearing
;
25766 cmp
->rbearing
= rbearing
;
25768 /* Set cmp->offsets for the remaining glyphs. */
25769 for (i
++; i
< glyph_len
; i
++)
25771 int left
, right
, btm
, top
;
25772 int ch
= COMPOSITION_GLYPH (cmp
, i
);
25774 struct face
*this_face
;
25778 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
25779 this_face
= FACE_FROM_ID (it
->f
, face_id
);
25780 font
= this_face
->font
;
25786 get_char_face_and_encoding (it
->f
, ch
, face_id
,
25788 pcm
= get_per_char_metric (font
, &char2b
);
25791 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
25794 width
= pcm
->width
;
25795 ascent
= pcm
->ascent
;
25796 descent
= pcm
->descent
;
25797 lbearing
= pcm
->lbearing
;
25798 rbearing
= pcm
->rbearing
;
25799 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
25801 /* Relative composition with or without
25802 alternate chars. */
25803 left
= (leftmost
+ rightmost
- width
) / 2;
25804 btm
= - descent
+ boff
;
25805 if (font
->relative_compose
25806 && (! CHAR_TABLE_P (Vignore_relative_composition
)
25807 || NILP (Faref (Vignore_relative_composition
,
25808 make_number (ch
)))))
25811 if (- descent
>= font
->relative_compose
)
25812 /* One extra pixel between two glyphs. */
25814 else if (ascent
<= 0)
25815 /* One extra pixel between two glyphs. */
25816 btm
= lowest
- 1 - ascent
- descent
;
25821 /* A composition rule is specified by an integer
25822 value that encodes global and new reference
25823 points (GREF and NREF). GREF and NREF are
25824 specified by numbers as below:
25826 0---1---2 -- ascent
25830 9--10--11 -- center
25832 ---3---4---5--- baseline
25834 6---7---8 -- descent
25836 int rule
= COMPOSITION_RULE (cmp
, i
);
25837 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
25839 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
25840 grefx
= gref
% 3, nrefx
= nref
% 3;
25841 grefy
= gref
/ 3, nrefy
= nref
/ 3;
25843 xoff
= font_height
* (xoff
- 128) / 256;
25845 yoff
= font_height
* (yoff
- 128) / 256;
25848 + grefx
* (rightmost
- leftmost
) / 2
25849 - nrefx
* width
/ 2
25852 btm
= ((grefy
== 0 ? highest
25854 : grefy
== 2 ? lowest
25855 : (highest
+ lowest
) / 2)
25856 - (nrefy
== 0 ? ascent
+ descent
25857 : nrefy
== 1 ? descent
- boff
25859 : (ascent
+ descent
) / 2)
25863 cmp
->offsets
[i
* 2] = left
;
25864 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
25866 /* Update the bounding box of the overall glyphs. */
25869 right
= left
+ width
;
25870 if (left
< leftmost
)
25872 if (right
> rightmost
)
25875 top
= btm
+ descent
+ ascent
;
25881 if (cmp
->lbearing
> left
+ lbearing
)
25882 cmp
->lbearing
= left
+ lbearing
;
25883 if (cmp
->rbearing
< left
+ rbearing
)
25884 cmp
->rbearing
= left
+ rbearing
;
25888 /* If there are glyphs whose x-offsets are negative,
25889 shift all glyphs to the right and make all x-offsets
25893 for (i
= 0; i
< cmp
->glyph_len
; i
++)
25894 cmp
->offsets
[i
* 2] -= leftmost
;
25895 rightmost
-= leftmost
;
25896 cmp
->lbearing
-= leftmost
;
25897 cmp
->rbearing
-= leftmost
;
25900 if (left_padded
&& cmp
->lbearing
< 0)
25902 for (i
= 0; i
< cmp
->glyph_len
; i
++)
25903 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
25904 rightmost
-= cmp
->lbearing
;
25905 cmp
->rbearing
-= cmp
->lbearing
;
25908 if (right_padded
&& rightmost
< cmp
->rbearing
)
25910 rightmost
= cmp
->rbearing
;
25913 cmp
->pixel_width
= rightmost
;
25914 cmp
->ascent
= highest
;
25915 cmp
->descent
= - lowest
;
25916 if (cmp
->ascent
< font_ascent
)
25917 cmp
->ascent
= font_ascent
;
25918 if (cmp
->descent
< font_descent
)
25919 cmp
->descent
= font_descent
;
25923 && (cmp
->lbearing
< 0
25924 || cmp
->rbearing
> cmp
->pixel_width
))
25925 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25927 it
->pixel_width
= cmp
->pixel_width
;
25928 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
25929 it
->descent
= it
->phys_descent
= cmp
->descent
;
25930 if (face
->box
!= FACE_NO_BOX
)
25932 int thick
= face
->box_line_width
;
25936 it
->ascent
+= thick
;
25937 it
->descent
+= thick
;
25942 if (it
->start_of_box_run_p
)
25943 it
->pixel_width
+= thick
;
25944 if (it
->end_of_box_run_p
)
25945 it
->pixel_width
+= thick
;
25948 /* If face has an overline, add the height of the overline
25949 (1 pixel) and a 1 pixel margin to the character height. */
25950 if (face
->overline_p
)
25951 it
->ascent
+= overline_margin
;
25953 take_vertical_position_into_account (it
);
25954 if (it
->ascent
< 0)
25956 if (it
->descent
< 0)
25959 if (it
->glyph_row
&& cmp
->glyph_len
> 0)
25960 append_composite_glyph (it
);
25962 else if (it
->what
== IT_COMPOSITION
)
25964 /* A dynamic (automatic) composition. */
25965 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25966 Lisp_Object gstring
;
25967 struct font_metrics metrics
;
25971 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
25973 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
25976 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
25977 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25978 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
25979 it
->descent
= it
->phys_descent
= metrics
.descent
;
25980 if (face
->box
!= FACE_NO_BOX
)
25982 int thick
= face
->box_line_width
;
25986 it
->ascent
+= thick
;
25987 it
->descent
+= thick
;
25992 if (it
->start_of_box_run_p
)
25993 it
->pixel_width
+= thick
;
25994 if (it
->end_of_box_run_p
)
25995 it
->pixel_width
+= thick
;
25997 /* If face has an overline, add the height of the overline
25998 (1 pixel) and a 1 pixel margin to the character height. */
25999 if (face
->overline_p
)
26000 it
->ascent
+= overline_margin
;
26001 take_vertical_position_into_account (it
);
26002 if (it
->ascent
< 0)
26004 if (it
->descent
< 0)
26008 append_composite_glyph (it
);
26010 else if (it
->what
== IT_GLYPHLESS
)
26011 produce_glyphless_glyph (it
, 0, Qnil
);
26012 else if (it
->what
== IT_IMAGE
)
26013 produce_image_glyph (it
);
26014 else if (it
->what
== IT_STRETCH
)
26015 produce_stretch_glyph (it
);
26018 /* Accumulate dimensions. Note: can't assume that it->descent > 0
26019 because this isn't true for images with `:ascent 100'. */
26020 eassert (it
->ascent
>= 0 && it
->descent
>= 0);
26021 if (it
->area
== TEXT_AREA
)
26022 it
->current_x
+= it
->pixel_width
;
26024 if (extra_line_spacing
> 0)
26026 it
->descent
+= extra_line_spacing
;
26027 if (extra_line_spacing
> it
->max_extra_line_spacing
)
26028 it
->max_extra_line_spacing
= extra_line_spacing
;
26031 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
26032 it
->max_descent
= max (it
->max_descent
, it
->descent
);
26033 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
26034 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
26038 Output LEN glyphs starting at START at the nominal cursor position.
26039 Advance the nominal cursor over the text. UPDATED_ROW is the glyph row
26040 being updated, and UPDATED_AREA is the area of that row being updated. */
26043 x_write_glyphs (struct window
*w
, struct glyph_row
*updated_row
,
26044 struct glyph
*start
, enum glyph_row_area updated_area
, int len
)
26046 int x
, hpos
, chpos
= w
->phys_cursor
.hpos
;
26048 eassert (updated_row
);
26049 /* When the window is hscrolled, cursor hpos can legitimately be out
26050 of bounds, but we draw the cursor at the corresponding window
26051 margin in that case. */
26052 if (!updated_row
->reversed_p
&& chpos
< 0)
26054 if (updated_row
->reversed_p
&& chpos
>= updated_row
->used
[TEXT_AREA
])
26055 chpos
= updated_row
->used
[TEXT_AREA
] - 1;
26059 /* Write glyphs. */
26061 hpos
= start
- updated_row
->glyphs
[updated_area
];
26062 x
= draw_glyphs (w
, w
->output_cursor
.x
,
26063 updated_row
, updated_area
,
26065 DRAW_NORMAL_TEXT
, 0);
26067 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
26068 if (updated_area
== TEXT_AREA
26069 && w
->phys_cursor_on_p
26070 && w
->phys_cursor
.vpos
== w
->output_cursor
.vpos
26072 && chpos
< hpos
+ len
)
26073 w
->phys_cursor_on_p
= 0;
26077 /* Advance the output cursor. */
26078 w
->output_cursor
.hpos
+= len
;
26079 w
->output_cursor
.x
= x
;
26084 Insert LEN glyphs from START at the nominal cursor position. */
26087 x_insert_glyphs (struct window
*w
, struct glyph_row
*updated_row
,
26088 struct glyph
*start
, enum glyph_row_area updated_area
, int len
)
26091 int line_height
, shift_by_width
, shifted_region_width
;
26092 struct glyph_row
*row
;
26093 struct glyph
*glyph
;
26094 int frame_x
, frame_y
;
26097 eassert (updated_row
);
26099 f
= XFRAME (WINDOW_FRAME (w
));
26101 /* Get the height of the line we are in. */
26103 line_height
= row
->height
;
26105 /* Get the width of the glyphs to insert. */
26106 shift_by_width
= 0;
26107 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
26108 shift_by_width
+= glyph
->pixel_width
;
26110 /* Get the width of the region to shift right. */
26111 shifted_region_width
= (window_box_width (w
, updated_area
)
26112 - w
->output_cursor
.x
26116 frame_x
= window_box_left (w
, updated_area
) + w
->output_cursor
.x
;
26117 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, w
->output_cursor
.y
);
26119 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
26120 line_height
, shift_by_width
);
26122 /* Write the glyphs. */
26123 hpos
= start
- row
->glyphs
[updated_area
];
26124 draw_glyphs (w
, w
->output_cursor
.x
, row
, updated_area
,
26126 DRAW_NORMAL_TEXT
, 0);
26128 /* Advance the output cursor. */
26129 w
->output_cursor
.hpos
+= len
;
26130 w
->output_cursor
.x
+= shift_by_width
;
26136 Erase the current text line from the nominal cursor position
26137 (inclusive) to pixel column TO_X (exclusive). The idea is that
26138 everything from TO_X onward is already erased.
26140 TO_X is a pixel position relative to UPDATED_AREA of currently
26141 updated window W. TO_X == -1 means clear to the end of this area. */
26144 x_clear_end_of_line (struct window
*w
, struct glyph_row
*updated_row
,
26145 enum glyph_row_area updated_area
, int to_x
)
26148 int max_x
, min_y
, max_y
;
26149 int from_x
, from_y
, to_y
;
26151 eassert (updated_row
);
26152 f
= XFRAME (w
->frame
);
26154 if (updated_row
->full_width_p
)
26155 max_x
= (WINDOW_PIXEL_WIDTH (w
)
26156 - (updated_row
->mode_line_p
? WINDOW_RIGHT_DIVIDER_WIDTH (w
) : 0));
26158 max_x
= window_box_width (w
, updated_area
);
26159 max_y
= window_text_bottom_y (w
);
26161 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
26162 of window. For TO_X > 0, truncate to end of drawing area. */
26168 to_x
= min (to_x
, max_x
);
26170 to_y
= min (max_y
, w
->output_cursor
.y
+ updated_row
->height
);
26172 /* Notice if the cursor will be cleared by this operation. */
26173 if (!updated_row
->full_width_p
)
26174 notice_overwritten_cursor (w
, updated_area
,
26175 w
->output_cursor
.x
, -1,
26177 MATRIX_ROW_BOTTOM_Y (updated_row
));
26179 from_x
= w
->output_cursor
.x
;
26181 /* Translate to frame coordinates. */
26182 if (updated_row
->full_width_p
)
26184 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
26185 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
26189 int area_left
= window_box_left (w
, updated_area
);
26190 from_x
+= area_left
;
26194 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
26195 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, w
->output_cursor
.y
));
26196 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
26198 /* Prevent inadvertently clearing to end of the X window. */
26199 if (to_x
> from_x
&& to_y
> from_y
)
26202 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
26203 to_x
- from_x
, to_y
- from_y
);
26208 #endif /* HAVE_WINDOW_SYSTEM */
26212 /***********************************************************************
26214 ***********************************************************************/
26216 /* Value is the internal representation of the specified cursor type
26217 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
26218 of the bar cursor. */
26220 static enum text_cursor_kinds
26221 get_specified_cursor_type (Lisp_Object arg
, int *width
)
26223 enum text_cursor_kinds type
;
26228 if (EQ (arg
, Qbox
))
26229 return FILLED_BOX_CURSOR
;
26231 if (EQ (arg
, Qhollow
))
26232 return HOLLOW_BOX_CURSOR
;
26234 if (EQ (arg
, Qbar
))
26241 && EQ (XCAR (arg
), Qbar
)
26242 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
26244 *width
= XINT (XCDR (arg
));
26248 if (EQ (arg
, Qhbar
))
26251 return HBAR_CURSOR
;
26255 && EQ (XCAR (arg
), Qhbar
)
26256 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
26258 *width
= XINT (XCDR (arg
));
26259 return HBAR_CURSOR
;
26262 /* Treat anything unknown as "hollow box cursor".
26263 It was bad to signal an error; people have trouble fixing
26264 .Xdefaults with Emacs, when it has something bad in it. */
26265 type
= HOLLOW_BOX_CURSOR
;
26270 /* Set the default cursor types for specified frame. */
26272 set_frame_cursor_types (struct frame
*f
, Lisp_Object arg
)
26277 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
26278 FRAME_CURSOR_WIDTH (f
) = width
;
26280 /* By default, set up the blink-off state depending on the on-state. */
26282 tem
= Fassoc (arg
, Vblink_cursor_alist
);
26285 FRAME_BLINK_OFF_CURSOR (f
)
26286 = get_specified_cursor_type (XCDR (tem
), &width
);
26287 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
26290 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
26292 /* Make sure the cursor gets redrawn. */
26293 f
->cursor_type_changed
= 1;
26297 #ifdef HAVE_WINDOW_SYSTEM
26299 /* Return the cursor we want to be displayed in window W. Return
26300 width of bar/hbar cursor through WIDTH arg. Return with
26301 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
26302 (i.e. if the `system caret' should track this cursor).
26304 In a mini-buffer window, we want the cursor only to appear if we
26305 are reading input from this window. For the selected window, we
26306 want the cursor type given by the frame parameter or buffer local
26307 setting of cursor-type. If explicitly marked off, draw no cursor.
26308 In all other cases, we want a hollow box cursor. */
26310 static enum text_cursor_kinds
26311 get_window_cursor_type (struct window
*w
, struct glyph
*glyph
, int *width
,
26312 int *active_cursor
)
26314 struct frame
*f
= XFRAME (w
->frame
);
26315 struct buffer
*b
= XBUFFER (w
->contents
);
26316 int cursor_type
= DEFAULT_CURSOR
;
26317 Lisp_Object alt_cursor
;
26318 int non_selected
= 0;
26320 *active_cursor
= 1;
26323 if (cursor_in_echo_area
26324 && FRAME_HAS_MINIBUF_P (f
)
26325 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
26327 if (w
== XWINDOW (echo_area_window
))
26329 if (EQ (BVAR (b
, cursor_type
), Qt
) || NILP (BVAR (b
, cursor_type
)))
26331 *width
= FRAME_CURSOR_WIDTH (f
);
26332 return FRAME_DESIRED_CURSOR (f
);
26335 return get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
26338 *active_cursor
= 0;
26342 /* Detect a nonselected window or nonselected frame. */
26343 else if (w
!= XWINDOW (f
->selected_window
)
26344 || f
!= FRAME_DISPLAY_INFO (f
)->x_highlight_frame
)
26346 *active_cursor
= 0;
26348 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
26354 /* Never display a cursor in a window in which cursor-type is nil. */
26355 if (NILP (BVAR (b
, cursor_type
)))
26358 /* Get the normal cursor type for this window. */
26359 if (EQ (BVAR (b
, cursor_type
), Qt
))
26361 cursor_type
= FRAME_DESIRED_CURSOR (f
);
26362 *width
= FRAME_CURSOR_WIDTH (f
);
26365 cursor_type
= get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
26367 /* Use cursor-in-non-selected-windows instead
26368 for non-selected window or frame. */
26371 alt_cursor
= BVAR (b
, cursor_in_non_selected_windows
);
26372 if (!EQ (Qt
, alt_cursor
))
26373 return get_specified_cursor_type (alt_cursor
, width
);
26374 /* t means modify the normal cursor type. */
26375 if (cursor_type
== FILLED_BOX_CURSOR
)
26376 cursor_type
= HOLLOW_BOX_CURSOR
;
26377 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
26379 return cursor_type
;
26382 /* Use normal cursor if not blinked off. */
26383 if (!w
->cursor_off_p
)
26385 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
26387 if (cursor_type
== FILLED_BOX_CURSOR
)
26389 /* Using a block cursor on large images can be very annoying.
26390 So use a hollow cursor for "large" images.
26391 If image is not transparent (no mask), also use hollow cursor. */
26392 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
26393 if (img
!= NULL
&& IMAGEP (img
->spec
))
26395 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
26396 where N = size of default frame font size.
26397 This should cover most of the "tiny" icons people may use. */
26399 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
26400 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
26401 cursor_type
= HOLLOW_BOX_CURSOR
;
26404 else if (cursor_type
!= NO_CURSOR
)
26406 /* Display current only supports BOX and HOLLOW cursors for images.
26407 So for now, unconditionally use a HOLLOW cursor when cursor is
26408 not a solid box cursor. */
26409 cursor_type
= HOLLOW_BOX_CURSOR
;
26412 return cursor_type
;
26415 /* Cursor is blinked off, so determine how to "toggle" it. */
26417 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
26418 if ((alt_cursor
= Fassoc (BVAR (b
, cursor_type
), Vblink_cursor_alist
), !NILP (alt_cursor
)))
26419 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
26421 /* Then see if frame has specified a specific blink off cursor type. */
26422 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
26424 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
26425 return FRAME_BLINK_OFF_CURSOR (f
);
26429 /* Some people liked having a permanently visible blinking cursor,
26430 while others had very strong opinions against it. So it was
26431 decided to remove it. KFS 2003-09-03 */
26433 /* Finally perform built-in cursor blinking:
26434 filled box <-> hollow box
26435 wide [h]bar <-> narrow [h]bar
26436 narrow [h]bar <-> no cursor
26437 other type <-> no cursor */
26439 if (cursor_type
== FILLED_BOX_CURSOR
)
26440 return HOLLOW_BOX_CURSOR
;
26442 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
26445 return cursor_type
;
26453 /* Notice when the text cursor of window W has been completely
26454 overwritten by a drawing operation that outputs glyphs in AREA
26455 starting at X0 and ending at X1 in the line starting at Y0 and
26456 ending at Y1. X coordinates are area-relative. X1 < 0 means all
26457 the rest of the line after X0 has been written. Y coordinates
26458 are window-relative. */
26461 notice_overwritten_cursor (struct window
*w
, enum glyph_row_area area
,
26462 int x0
, int x1
, int y0
, int y1
)
26464 int cx0
, cx1
, cy0
, cy1
;
26465 struct glyph_row
*row
;
26467 if (!w
->phys_cursor_on_p
)
26469 if (area
!= TEXT_AREA
)
26472 if (w
->phys_cursor
.vpos
< 0
26473 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
26474 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
26475 !(row
->enabled_p
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
))))
26478 if (row
->cursor_in_fringe_p
)
26480 row
->cursor_in_fringe_p
= 0;
26481 draw_fringe_bitmap (w
, row
, row
->reversed_p
);
26482 w
->phys_cursor_on_p
= 0;
26486 cx0
= w
->phys_cursor
.x
;
26487 cx1
= cx0
+ w
->phys_cursor_width
;
26488 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
26491 /* The cursor image will be completely removed from the
26492 screen if the output area intersects the cursor area in
26493 y-direction. When we draw in [y0 y1[, and some part of
26494 the cursor is at y < y0, that part must have been drawn
26495 before. When scrolling, the cursor is erased before
26496 actually scrolling, so we don't come here. When not
26497 scrolling, the rows above the old cursor row must have
26498 changed, and in this case these rows must have written
26499 over the cursor image.
26501 Likewise if part of the cursor is below y1, with the
26502 exception of the cursor being in the first blank row at
26503 the buffer and window end because update_text_area
26504 doesn't draw that row. (Except when it does, but
26505 that's handled in update_text_area.) */
26507 cy0
= w
->phys_cursor
.y
;
26508 cy1
= cy0
+ w
->phys_cursor_height
;
26509 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
26512 w
->phys_cursor_on_p
= 0;
26515 #endif /* HAVE_WINDOW_SYSTEM */
26518 /************************************************************************
26520 ************************************************************************/
26522 #ifdef HAVE_WINDOW_SYSTEM
26525 Fix the display of area AREA of overlapping row ROW in window W
26526 with respect to the overlapping part OVERLAPS. */
26529 x_fix_overlapping_area (struct window
*w
, struct glyph_row
*row
,
26530 enum glyph_row_area area
, int overlaps
)
26537 for (i
= 0; i
< row
->used
[area
];)
26539 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
26541 int start
= i
, start_x
= x
;
26545 x
+= row
->glyphs
[area
][i
].pixel_width
;
26548 while (i
< row
->used
[area
]
26549 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
26551 draw_glyphs (w
, start_x
, row
, area
,
26553 DRAW_NORMAL_TEXT
, overlaps
);
26557 x
+= row
->glyphs
[area
][i
].pixel_width
;
26567 Draw the cursor glyph of window W in glyph row ROW. See the
26568 comment of draw_glyphs for the meaning of HL. */
26571 draw_phys_cursor_glyph (struct window
*w
, struct glyph_row
*row
,
26572 enum draw_glyphs_face hl
)
26574 /* If cursor hpos is out of bounds, don't draw garbage. This can
26575 happen in mini-buffer windows when switching between echo area
26576 glyphs and mini-buffer. */
26577 if ((row
->reversed_p
26578 ? (w
->phys_cursor
.hpos
>= 0)
26579 : (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])))
26581 int on_p
= w
->phys_cursor_on_p
;
26583 int hpos
= w
->phys_cursor
.hpos
;
26585 /* When the window is hscrolled, cursor hpos can legitimately be
26586 out of bounds, but we draw the cursor at the corresponding
26587 window margin in that case. */
26588 if (!row
->reversed_p
&& hpos
< 0)
26590 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26591 hpos
= row
->used
[TEXT_AREA
] - 1;
26593 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
, hpos
, hpos
+ 1,
26595 w
->phys_cursor_on_p
= on_p
;
26597 if (hl
== DRAW_CURSOR
)
26598 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
26599 /* When we erase the cursor, and ROW is overlapped by other
26600 rows, make sure that these overlapping parts of other rows
26602 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
26604 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
26606 if (row
> w
->current_matrix
->rows
26607 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
26608 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
26609 OVERLAPS_ERASED_CURSOR
);
26611 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
26612 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
26613 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
26614 OVERLAPS_ERASED_CURSOR
);
26620 /* Erase the image of a cursor of window W from the screen. */
26626 erase_phys_cursor (struct window
*w
)
26628 struct frame
*f
= XFRAME (w
->frame
);
26629 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
26630 int hpos
= w
->phys_cursor
.hpos
;
26631 int vpos
= w
->phys_cursor
.vpos
;
26632 int mouse_face_here_p
= 0;
26633 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
26634 struct glyph_row
*cursor_row
;
26635 struct glyph
*cursor_glyph
;
26636 enum draw_glyphs_face hl
;
26638 /* No cursor displayed or row invalidated => nothing to do on the
26640 if (w
->phys_cursor_type
== NO_CURSOR
)
26641 goto mark_cursor_off
;
26643 /* VPOS >= active_glyphs->nrows means that window has been resized.
26644 Don't bother to erase the cursor. */
26645 if (vpos
>= active_glyphs
->nrows
)
26646 goto mark_cursor_off
;
26648 /* If row containing cursor is marked invalid, there is nothing we
26650 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
26651 if (!cursor_row
->enabled_p
)
26652 goto mark_cursor_off
;
26654 /* If line spacing is > 0, old cursor may only be partially visible in
26655 window after split-window. So adjust visible height. */
26656 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
26657 window_text_bottom_y (w
) - cursor_row
->y
);
26659 /* If row is completely invisible, don't attempt to delete a cursor which
26660 isn't there. This can happen if cursor is at top of a window, and
26661 we switch to a buffer with a header line in that window. */
26662 if (cursor_row
->visible_height
<= 0)
26663 goto mark_cursor_off
;
26665 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
26666 if (cursor_row
->cursor_in_fringe_p
)
26668 cursor_row
->cursor_in_fringe_p
= 0;
26669 draw_fringe_bitmap (w
, cursor_row
, cursor_row
->reversed_p
);
26670 goto mark_cursor_off
;
26673 /* This can happen when the new row is shorter than the old one.
26674 In this case, either draw_glyphs or clear_end_of_line
26675 should have cleared the cursor. Note that we wouldn't be
26676 able to erase the cursor in this case because we don't have a
26677 cursor glyph at hand. */
26678 if ((cursor_row
->reversed_p
26679 ? (w
->phys_cursor
.hpos
< 0)
26680 : (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])))
26681 goto mark_cursor_off
;
26683 /* When the window is hscrolled, cursor hpos can legitimately be out
26684 of bounds, but we draw the cursor at the corresponding window
26685 margin in that case. */
26686 if (!cursor_row
->reversed_p
&& hpos
< 0)
26688 if (cursor_row
->reversed_p
&& hpos
>= cursor_row
->used
[TEXT_AREA
])
26689 hpos
= cursor_row
->used
[TEXT_AREA
] - 1;
26691 /* If the cursor is in the mouse face area, redisplay that when
26692 we clear the cursor. */
26693 if (! NILP (hlinfo
->mouse_face_window
)
26694 && coords_in_mouse_face_p (w
, hpos
, vpos
)
26695 /* Don't redraw the cursor's spot in mouse face if it is at the
26696 end of a line (on a newline). The cursor appears there, but
26697 mouse highlighting does not. */
26698 && cursor_row
->used
[TEXT_AREA
] > hpos
&& hpos
>= 0)
26699 mouse_face_here_p
= 1;
26701 /* Maybe clear the display under the cursor. */
26702 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
26705 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
26708 cursor_glyph
= get_phys_cursor_glyph (w
);
26709 if (cursor_glyph
== NULL
)
26710 goto mark_cursor_off
;
26712 width
= cursor_glyph
->pixel_width
;
26713 left_x
= window_box_left_offset (w
, TEXT_AREA
);
26714 x
= w
->phys_cursor
.x
;
26716 width
-= left_x
- x
;
26717 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
26718 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
26719 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
26722 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
26725 /* Erase the cursor by redrawing the character underneath it. */
26726 if (mouse_face_here_p
)
26727 hl
= DRAW_MOUSE_FACE
;
26729 hl
= DRAW_NORMAL_TEXT
;
26730 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
26733 w
->phys_cursor_on_p
= 0;
26734 w
->phys_cursor_type
= NO_CURSOR
;
26739 Display or clear cursor of window W. If ON is zero, clear the
26740 cursor. If it is non-zero, display the cursor. If ON is nonzero,
26741 where to put the cursor is specified by HPOS, VPOS, X and Y. */
26744 display_and_set_cursor (struct window
*w
, bool on
,
26745 int hpos
, int vpos
, int x
, int y
)
26747 struct frame
*f
= XFRAME (w
->frame
);
26748 int new_cursor_type
;
26749 int new_cursor_width
;
26751 struct glyph_row
*glyph_row
;
26752 struct glyph
*glyph
;
26754 /* This is pointless on invisible frames, and dangerous on garbaged
26755 windows and frames; in the latter case, the frame or window may
26756 be in the midst of changing its size, and x and y may be off the
26758 if (! FRAME_VISIBLE_P (f
)
26759 || FRAME_GARBAGED_P (f
)
26760 || vpos
>= w
->current_matrix
->nrows
26761 || hpos
>= w
->current_matrix
->matrix_w
)
26764 /* If cursor is off and we want it off, return quickly. */
26765 if (!on
&& !w
->phys_cursor_on_p
)
26768 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26769 /* If cursor row is not enabled, we don't really know where to
26770 display the cursor. */
26771 if (!glyph_row
->enabled_p
)
26773 w
->phys_cursor_on_p
= 0;
26778 if (!glyph_row
->exact_window_width_line_p
26779 || (0 <= hpos
&& hpos
< glyph_row
->used
[TEXT_AREA
]))
26780 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
26782 eassert (input_blocked_p ());
26784 /* Set new_cursor_type to the cursor we want to be displayed. */
26785 new_cursor_type
= get_window_cursor_type (w
, glyph
,
26786 &new_cursor_width
, &active_cursor
);
26788 /* If cursor is currently being shown and we don't want it to be or
26789 it is in the wrong place, or the cursor type is not what we want,
26791 if (w
->phys_cursor_on_p
26793 || w
->phys_cursor
.x
!= x
26794 || w
->phys_cursor
.y
!= y
26795 || new_cursor_type
!= w
->phys_cursor_type
26796 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
26797 && new_cursor_width
!= w
->phys_cursor_width
)))
26798 erase_phys_cursor (w
);
26800 /* Don't check phys_cursor_on_p here because that flag is only set
26801 to zero in some cases where we know that the cursor has been
26802 completely erased, to avoid the extra work of erasing the cursor
26803 twice. In other words, phys_cursor_on_p can be 1 and the cursor
26804 still not be visible, or it has only been partly erased. */
26807 w
->phys_cursor_ascent
= glyph_row
->ascent
;
26808 w
->phys_cursor_height
= glyph_row
->height
;
26810 /* Set phys_cursor_.* before x_draw_.* is called because some
26811 of them may need the information. */
26812 w
->phys_cursor
.x
= x
;
26813 w
->phys_cursor
.y
= glyph_row
->y
;
26814 w
->phys_cursor
.hpos
= hpos
;
26815 w
->phys_cursor
.vpos
= vpos
;
26818 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
26819 new_cursor_type
, new_cursor_width
,
26820 on
, active_cursor
);
26824 /* Switch the display of W's cursor on or off, according to the value
26828 update_window_cursor (struct window
*w
, bool on
)
26830 /* Don't update cursor in windows whose frame is in the process
26831 of being deleted. */
26832 if (w
->current_matrix
)
26834 int hpos
= w
->phys_cursor
.hpos
;
26835 int vpos
= w
->phys_cursor
.vpos
;
26836 struct glyph_row
*row
;
26838 if (vpos
>= w
->current_matrix
->nrows
26839 || hpos
>= w
->current_matrix
->matrix_w
)
26842 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26844 /* When the window is hscrolled, cursor hpos can legitimately be
26845 out of bounds, but we draw the cursor at the corresponding
26846 window margin in that case. */
26847 if (!row
->reversed_p
&& hpos
< 0)
26849 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26850 hpos
= row
->used
[TEXT_AREA
] - 1;
26853 display_and_set_cursor (w
, on
, hpos
, vpos
,
26854 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
26860 /* Call update_window_cursor with parameter ON_P on all leaf windows
26861 in the window tree rooted at W. */
26864 update_cursor_in_window_tree (struct window
*w
, bool on_p
)
26868 if (WINDOWP (w
->contents
))
26869 update_cursor_in_window_tree (XWINDOW (w
->contents
), on_p
);
26871 update_window_cursor (w
, on_p
);
26873 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
26879 Display the cursor on window W, or clear it, according to ON_P.
26880 Don't change the cursor's position. */
26883 x_update_cursor (struct frame
*f
, bool on_p
)
26885 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
26890 Clear the cursor of window W to background color, and mark the
26891 cursor as not shown. This is used when the text where the cursor
26892 is about to be rewritten. */
26895 x_clear_cursor (struct window
*w
)
26897 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
26898 update_window_cursor (w
, 0);
26901 #endif /* HAVE_WINDOW_SYSTEM */
26903 /* Implementation of draw_row_with_mouse_face for GUI sessions, GPM,
26906 draw_row_with_mouse_face (struct window
*w
, int start_x
, struct glyph_row
*row
,
26907 int start_hpos
, int end_hpos
,
26908 enum draw_glyphs_face draw
)
26910 #ifdef HAVE_WINDOW_SYSTEM
26911 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
26913 draw_glyphs (w
, start_x
, row
, TEXT_AREA
, start_hpos
, end_hpos
, draw
, 0);
26917 #if defined (HAVE_GPM) || defined (MSDOS) || defined (WINDOWSNT)
26918 tty_draw_row_with_mouse_face (w
, row
, start_hpos
, end_hpos
, draw
);
26922 /* Display the active region described by mouse_face_* according to DRAW. */
26925 show_mouse_face (Mouse_HLInfo
*hlinfo
, enum draw_glyphs_face draw
)
26927 struct window
*w
= XWINDOW (hlinfo
->mouse_face_window
);
26928 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
26930 if (/* If window is in the process of being destroyed, don't bother
26932 w
->current_matrix
!= NULL
26933 /* Don't update mouse highlight if hidden */
26934 && (draw
!= DRAW_MOUSE_FACE
|| !hlinfo
->mouse_face_hidden
)
26935 /* Recognize when we are called to operate on rows that don't exist
26936 anymore. This can happen when a window is split. */
26937 && hlinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
26939 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
26940 struct glyph_row
*row
, *first
, *last
;
26942 first
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
26943 last
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
26945 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
26947 int start_hpos
, end_hpos
, start_x
;
26949 /* For all but the first row, the highlight starts at column 0. */
26952 /* R2L rows have BEG and END in reversed order, but the
26953 screen drawing geometry is always left to right. So
26954 we need to mirror the beginning and end of the
26955 highlighted area in R2L rows. */
26956 if (!row
->reversed_p
)
26958 start_hpos
= hlinfo
->mouse_face_beg_col
;
26959 start_x
= hlinfo
->mouse_face_beg_x
;
26961 else if (row
== last
)
26963 start_hpos
= hlinfo
->mouse_face_end_col
;
26964 start_x
= hlinfo
->mouse_face_end_x
;
26972 else if (row
->reversed_p
&& row
== last
)
26974 start_hpos
= hlinfo
->mouse_face_end_col
;
26975 start_x
= hlinfo
->mouse_face_end_x
;
26985 if (!row
->reversed_p
)
26986 end_hpos
= hlinfo
->mouse_face_end_col
;
26987 else if (row
== first
)
26988 end_hpos
= hlinfo
->mouse_face_beg_col
;
26991 end_hpos
= row
->used
[TEXT_AREA
];
26992 if (draw
== DRAW_NORMAL_TEXT
)
26993 row
->fill_line_p
= 1; /* Clear to end of line */
26996 else if (row
->reversed_p
&& row
== first
)
26997 end_hpos
= hlinfo
->mouse_face_beg_col
;
27000 end_hpos
= row
->used
[TEXT_AREA
];
27001 if (draw
== DRAW_NORMAL_TEXT
)
27002 row
->fill_line_p
= 1; /* Clear to end of line */
27005 if (end_hpos
> start_hpos
)
27007 draw_row_with_mouse_face (w
, start_x
, row
,
27008 start_hpos
, end_hpos
, draw
);
27011 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
27015 #ifdef HAVE_WINDOW_SYSTEM
27016 /* When we've written over the cursor, arrange for it to
27017 be displayed again. */
27018 if (FRAME_WINDOW_P (f
)
27019 && phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
27021 int hpos
= w
->phys_cursor
.hpos
;
27023 /* When the window is hscrolled, cursor hpos can legitimately be
27024 out of bounds, but we draw the cursor at the corresponding
27025 window margin in that case. */
27026 if (!row
->reversed_p
&& hpos
< 0)
27028 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
27029 hpos
= row
->used
[TEXT_AREA
] - 1;
27032 display_and_set_cursor (w
, 1, hpos
, w
->phys_cursor
.vpos
,
27033 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
27036 #endif /* HAVE_WINDOW_SYSTEM */
27039 #ifdef HAVE_WINDOW_SYSTEM
27040 /* Change the mouse cursor. */
27041 if (FRAME_WINDOW_P (f
))
27043 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
27044 if (draw
== DRAW_NORMAL_TEXT
27045 && !EQ (hlinfo
->mouse_face_window
, f
->tool_bar_window
))
27046 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
27049 if (draw
== DRAW_MOUSE_FACE
)
27050 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
27052 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
27054 #endif /* HAVE_WINDOW_SYSTEM */
27058 Clear out the mouse-highlighted active region.
27059 Redraw it un-highlighted first. Value is non-zero if mouse
27060 face was actually drawn unhighlighted. */
27063 clear_mouse_face (Mouse_HLInfo
*hlinfo
)
27067 if (!hlinfo
->mouse_face_hidden
&& !NILP (hlinfo
->mouse_face_window
))
27069 show_mouse_face (hlinfo
, DRAW_NORMAL_TEXT
);
27073 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
27074 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
27075 hlinfo
->mouse_face_window
= Qnil
;
27076 hlinfo
->mouse_face_overlay
= Qnil
;
27080 /* Return non-zero if the coordinates HPOS and VPOS on windows W are
27081 within the mouse face on that window. */
27083 coords_in_mouse_face_p (struct window
*w
, int hpos
, int vpos
)
27085 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
27087 /* Quickly resolve the easy cases. */
27088 if (!(WINDOWP (hlinfo
->mouse_face_window
)
27089 && XWINDOW (hlinfo
->mouse_face_window
) == w
))
27091 if (vpos
< hlinfo
->mouse_face_beg_row
27092 || vpos
> hlinfo
->mouse_face_end_row
)
27094 if (vpos
> hlinfo
->mouse_face_beg_row
27095 && vpos
< hlinfo
->mouse_face_end_row
)
27098 if (!MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
)
27100 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
27102 if (hlinfo
->mouse_face_beg_col
<= hpos
&& hpos
< hlinfo
->mouse_face_end_col
)
27105 else if ((vpos
== hlinfo
->mouse_face_beg_row
27106 && hpos
>= hlinfo
->mouse_face_beg_col
)
27107 || (vpos
== hlinfo
->mouse_face_end_row
27108 && hpos
< hlinfo
->mouse_face_end_col
))
27113 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
27115 if (hlinfo
->mouse_face_end_col
< hpos
&& hpos
<= hlinfo
->mouse_face_beg_col
)
27118 else if ((vpos
== hlinfo
->mouse_face_beg_row
27119 && hpos
<= hlinfo
->mouse_face_beg_col
)
27120 || (vpos
== hlinfo
->mouse_face_end_row
27121 && hpos
> hlinfo
->mouse_face_end_col
))
27129 Non-zero if physical cursor of window W is within mouse face. */
27132 cursor_in_mouse_face_p (struct window
*w
)
27134 int hpos
= w
->phys_cursor
.hpos
;
27135 int vpos
= w
->phys_cursor
.vpos
;
27136 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
27138 /* When the window is hscrolled, cursor hpos can legitimately be out
27139 of bounds, but we draw the cursor at the corresponding window
27140 margin in that case. */
27141 if (!row
->reversed_p
&& hpos
< 0)
27143 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
27144 hpos
= row
->used
[TEXT_AREA
] - 1;
27146 return coords_in_mouse_face_p (w
, hpos
, vpos
);
27151 /* Find the glyph rows START_ROW and END_ROW of window W that display
27152 characters between buffer positions START_CHARPOS and END_CHARPOS
27153 (excluding END_CHARPOS). DISP_STRING is a display string that
27154 covers these buffer positions. This is similar to
27155 row_containing_pos, but is more accurate when bidi reordering makes
27156 buffer positions change non-linearly with glyph rows. */
27158 rows_from_pos_range (struct window
*w
,
27159 ptrdiff_t start_charpos
, ptrdiff_t end_charpos
,
27160 Lisp_Object disp_string
,
27161 struct glyph_row
**start
, struct glyph_row
**end
)
27163 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27164 int last_y
= window_text_bottom_y (w
);
27165 struct glyph_row
*row
;
27170 while (!first
->enabled_p
27171 && first
< MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
27174 /* Find the START row. */
27176 row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
;
27179 /* A row can potentially be the START row if the range of the
27180 characters it displays intersects the range
27181 [START_CHARPOS..END_CHARPOS). */
27182 if (! ((start_charpos
< MATRIX_ROW_START_CHARPOS (row
)
27183 && end_charpos
< MATRIX_ROW_START_CHARPOS (row
))
27184 /* See the commentary in row_containing_pos, for the
27185 explanation of the complicated way to check whether
27186 some position is beyond the end of the characters
27187 displayed by a row. */
27188 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (row
)
27189 || (start_charpos
== MATRIX_ROW_END_CHARPOS (row
)
27190 && !row
->ends_at_zv_p
27191 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
27192 && (end_charpos
> MATRIX_ROW_END_CHARPOS (row
)
27193 || (end_charpos
== MATRIX_ROW_END_CHARPOS (row
)
27194 && !row
->ends_at_zv_p
27195 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))))
27197 /* Found a candidate row. Now make sure at least one of the
27198 glyphs it displays has a charpos from the range
27199 [START_CHARPOS..END_CHARPOS).
27201 This is not obvious because bidi reordering could make
27202 buffer positions of a row be 1,2,3,102,101,100, and if we
27203 want to highlight characters in [50..60), we don't want
27204 this row, even though [50..60) does intersect [1..103),
27205 the range of character positions given by the row's start
27206 and end positions. */
27207 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
27208 struct glyph
*e
= g
+ row
->used
[TEXT_AREA
];
27212 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
27213 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
27214 /* A glyph that comes from DISP_STRING is by
27215 definition to be highlighted. */
27216 || EQ (g
->object
, disp_string
))
27225 /* Find the END row. */
27227 /* If the last row is partially visible, start looking for END
27228 from that row, instead of starting from FIRST. */
27229 && !(row
->enabled_p
27230 && row
->y
< last_y
&& MATRIX_ROW_BOTTOM_Y (row
) > last_y
))
27232 for ( ; row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
; row
++)
27234 struct glyph_row
*next
= row
+ 1;
27235 ptrdiff_t next_start
= MATRIX_ROW_START_CHARPOS (next
);
27237 if (!next
->enabled_p
27238 || next
>= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
)
27239 /* The first row >= START whose range of displayed characters
27240 does NOT intersect the range [START_CHARPOS..END_CHARPOS]
27241 is the row END + 1. */
27242 || (start_charpos
< next_start
27243 && end_charpos
< next_start
)
27244 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (next
)
27245 || (start_charpos
== MATRIX_ROW_END_CHARPOS (next
)
27246 && !next
->ends_at_zv_p
27247 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))
27248 && (end_charpos
> MATRIX_ROW_END_CHARPOS (next
)
27249 || (end_charpos
== MATRIX_ROW_END_CHARPOS (next
)
27250 && !next
->ends_at_zv_p
27251 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))))
27258 /* If the next row's edges intersect [START_CHARPOS..END_CHARPOS],
27259 but none of the characters it displays are in the range, it is
27261 struct glyph
*g
= next
->glyphs
[TEXT_AREA
];
27262 struct glyph
*s
= g
;
27263 struct glyph
*e
= g
+ next
->used
[TEXT_AREA
];
27267 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
27268 && ((start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
27269 /* If the buffer position of the first glyph in
27270 the row is equal to END_CHARPOS, it means
27271 the last character to be highlighted is the
27272 newline of ROW, and we must consider NEXT as
27274 || (((!next
->reversed_p
&& g
== s
)
27275 || (next
->reversed_p
&& g
== e
- 1))
27276 && (g
->charpos
== end_charpos
27277 /* Special case for when NEXT is an
27278 empty line at ZV. */
27279 || (g
->charpos
== -1
27280 && !row
->ends_at_zv_p
27281 && next_start
== end_charpos
)))))
27282 /* A glyph that comes from DISP_STRING is by
27283 definition to be highlighted. */
27284 || EQ (g
->object
, disp_string
))
27293 /* The first row that ends at ZV must be the last to be
27295 else if (next
->ends_at_zv_p
)
27304 /* This function sets the mouse_face_* elements of HLINFO, assuming
27305 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
27306 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
27307 for the overlay or run of text properties specifying the mouse
27308 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
27309 before-string and after-string that must also be highlighted.
27310 DISP_STRING, if non-nil, is a display string that may cover some
27311 or all of the highlighted text. */
27314 mouse_face_from_buffer_pos (Lisp_Object window
,
27315 Mouse_HLInfo
*hlinfo
,
27316 ptrdiff_t mouse_charpos
,
27317 ptrdiff_t start_charpos
,
27318 ptrdiff_t end_charpos
,
27319 Lisp_Object before_string
,
27320 Lisp_Object after_string
,
27321 Lisp_Object disp_string
)
27323 struct window
*w
= XWINDOW (window
);
27324 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27325 struct glyph_row
*r1
, *r2
;
27326 struct glyph
*glyph
, *end
;
27327 ptrdiff_t ignore
, pos
;
27330 eassert (NILP (disp_string
) || STRINGP (disp_string
));
27331 eassert (NILP (before_string
) || STRINGP (before_string
));
27332 eassert (NILP (after_string
) || STRINGP (after_string
));
27334 /* Find the rows corresponding to START_CHARPOS and END_CHARPOS. */
27335 rows_from_pos_range (w
, start_charpos
, end_charpos
, disp_string
, &r1
, &r2
);
27337 r1
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
27338 /* If the before-string or display-string contains newlines,
27339 rows_from_pos_range skips to its last row. Move back. */
27340 if (!NILP (before_string
) || !NILP (disp_string
))
27342 struct glyph_row
*prev
;
27343 while ((prev
= r1
- 1, prev
>= first
)
27344 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
27345 && prev
->used
[TEXT_AREA
] > 0)
27347 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
27348 glyph
= beg
+ prev
->used
[TEXT_AREA
];
27349 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
27351 || !(EQ (glyph
->object
, before_string
)
27352 || EQ (glyph
->object
, disp_string
)))
27359 r2
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
27360 hlinfo
->mouse_face_past_end
= 1;
27362 else if (!NILP (after_string
))
27364 /* If the after-string has newlines, advance to its last row. */
27365 struct glyph_row
*next
;
27366 struct glyph_row
*last
27367 = MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
27369 for (next
= r2
+ 1;
27371 && next
->used
[TEXT_AREA
] > 0
27372 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
27376 /* The rest of the display engine assumes that mouse_face_beg_row is
27377 either above mouse_face_end_row or identical to it. But with
27378 bidi-reordered continued lines, the row for START_CHARPOS could
27379 be below the row for END_CHARPOS. If so, swap the rows and store
27380 them in correct order. */
27383 struct glyph_row
*tem
= r2
;
27389 hlinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (r1
, w
->current_matrix
);
27390 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r2
, w
->current_matrix
);
27392 /* For a bidi-reordered row, the positions of BEFORE_STRING,
27393 AFTER_STRING, DISP_STRING, START_CHARPOS, and END_CHARPOS
27394 could be anywhere in the row and in any order. The strategy
27395 below is to find the leftmost and the rightmost glyph that
27396 belongs to either of these 3 strings, or whose position is
27397 between START_CHARPOS and END_CHARPOS, and highlight all the
27398 glyphs between those two. This may cover more than just the text
27399 between START_CHARPOS and END_CHARPOS if the range of characters
27400 strides the bidi level boundary, e.g. if the beginning is in R2L
27401 text while the end is in L2R text or vice versa. */
27402 if (!r1
->reversed_p
)
27404 /* This row is in a left to right paragraph. Scan it left to
27406 glyph
= r1
->glyphs
[TEXT_AREA
];
27407 end
= glyph
+ r1
->used
[TEXT_AREA
];
27410 /* Skip truncation glyphs at the start of the glyph row. */
27411 if (MATRIX_ROW_DISPLAYS_TEXT_P (r1
))
27413 && INTEGERP (glyph
->object
)
27414 && glyph
->charpos
< 0;
27416 x
+= glyph
->pixel_width
;
27418 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
27419 or DISP_STRING, and the first glyph from buffer whose
27420 position is between START_CHARPOS and END_CHARPOS. */
27422 && !INTEGERP (glyph
->object
)
27423 && !EQ (glyph
->object
, disp_string
)
27424 && !(BUFFERP (glyph
->object
)
27425 && (glyph
->charpos
>= start_charpos
27426 && glyph
->charpos
< end_charpos
));
27429 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27430 are present at buffer positions between START_CHARPOS and
27431 END_CHARPOS, or if they come from an overlay. */
27432 if (EQ (glyph
->object
, before_string
))
27434 pos
= string_buffer_position (before_string
,
27436 /* If pos == 0, it means before_string came from an
27437 overlay, not from a buffer position. */
27438 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27441 else if (EQ (glyph
->object
, after_string
))
27443 pos
= string_buffer_position (after_string
, end_charpos
);
27444 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27447 x
+= glyph
->pixel_width
;
27449 hlinfo
->mouse_face_beg_x
= x
;
27450 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
27454 /* This row is in a right to left paragraph. Scan it right to
27458 end
= r1
->glyphs
[TEXT_AREA
] - 1;
27459 glyph
= end
+ r1
->used
[TEXT_AREA
];
27461 /* Skip truncation glyphs at the start of the glyph row. */
27462 if (MATRIX_ROW_DISPLAYS_TEXT_P (r1
))
27464 && INTEGERP (glyph
->object
)
27465 && glyph
->charpos
< 0;
27469 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
27470 or DISP_STRING, and the first glyph from buffer whose
27471 position is between START_CHARPOS and END_CHARPOS. */
27473 && !INTEGERP (glyph
->object
)
27474 && !EQ (glyph
->object
, disp_string
)
27475 && !(BUFFERP (glyph
->object
)
27476 && (glyph
->charpos
>= start_charpos
27477 && glyph
->charpos
< end_charpos
));
27480 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27481 are present at buffer positions between START_CHARPOS and
27482 END_CHARPOS, or if they come from an overlay. */
27483 if (EQ (glyph
->object
, before_string
))
27485 pos
= string_buffer_position (before_string
, start_charpos
);
27486 /* If pos == 0, it means before_string came from an
27487 overlay, not from a buffer position. */
27488 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27491 else if (EQ (glyph
->object
, after_string
))
27493 pos
= string_buffer_position (after_string
, end_charpos
);
27494 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27499 glyph
++; /* first glyph to the right of the highlighted area */
27500 for (g
= r1
->glyphs
[TEXT_AREA
], x
= r1
->x
; g
< glyph
; g
++)
27501 x
+= g
->pixel_width
;
27502 hlinfo
->mouse_face_beg_x
= x
;
27503 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
27506 /* If the highlight ends in a different row, compute GLYPH and END
27507 for the end row. Otherwise, reuse the values computed above for
27508 the row where the highlight begins. */
27511 if (!r2
->reversed_p
)
27513 glyph
= r2
->glyphs
[TEXT_AREA
];
27514 end
= glyph
+ r2
->used
[TEXT_AREA
];
27519 end
= r2
->glyphs
[TEXT_AREA
] - 1;
27520 glyph
= end
+ r2
->used
[TEXT_AREA
];
27524 if (!r2
->reversed_p
)
27526 /* Skip truncation and continuation glyphs near the end of the
27527 row, and also blanks and stretch glyphs inserted by
27528 extend_face_to_end_of_line. */
27530 && INTEGERP ((end
- 1)->object
))
27532 /* Scan the rest of the glyph row from the end, looking for the
27533 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
27534 DISP_STRING, or whose position is between START_CHARPOS
27538 && !INTEGERP (end
->object
)
27539 && !EQ (end
->object
, disp_string
)
27540 && !(BUFFERP (end
->object
)
27541 && (end
->charpos
>= start_charpos
27542 && end
->charpos
< end_charpos
));
27545 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27546 are present at buffer positions between START_CHARPOS and
27547 END_CHARPOS, or if they come from an overlay. */
27548 if (EQ (end
->object
, before_string
))
27550 pos
= string_buffer_position (before_string
, start_charpos
);
27551 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27554 else if (EQ (end
->object
, after_string
))
27556 pos
= string_buffer_position (after_string
, end_charpos
);
27557 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27561 /* Find the X coordinate of the last glyph to be highlighted. */
27562 for (; glyph
<= end
; ++glyph
)
27563 x
+= glyph
->pixel_width
;
27565 hlinfo
->mouse_face_end_x
= x
;
27566 hlinfo
->mouse_face_end_col
= glyph
- r2
->glyphs
[TEXT_AREA
];
27570 /* Skip truncation and continuation glyphs near the end of the
27571 row, and also blanks and stretch glyphs inserted by
27572 extend_face_to_end_of_line. */
27576 && INTEGERP (end
->object
))
27578 x
+= end
->pixel_width
;
27581 /* Scan the rest of the glyph row from the end, looking for the
27582 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
27583 DISP_STRING, or whose position is between START_CHARPOS
27587 && !INTEGERP (end
->object
)
27588 && !EQ (end
->object
, disp_string
)
27589 && !(BUFFERP (end
->object
)
27590 && (end
->charpos
>= start_charpos
27591 && end
->charpos
< end_charpos
));
27594 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27595 are present at buffer positions between START_CHARPOS and
27596 END_CHARPOS, or if they come from an overlay. */
27597 if (EQ (end
->object
, before_string
))
27599 pos
= string_buffer_position (before_string
, start_charpos
);
27600 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27603 else if (EQ (end
->object
, after_string
))
27605 pos
= string_buffer_position (after_string
, end_charpos
);
27606 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27609 x
+= end
->pixel_width
;
27611 /* If we exited the above loop because we arrived at the last
27612 glyph of the row, and its buffer position is still not in
27613 range, it means the last character in range is the preceding
27614 newline. Bump the end column and x values to get past the
27617 && BUFFERP (end
->object
)
27618 && (end
->charpos
< start_charpos
27619 || end
->charpos
>= end_charpos
))
27621 x
+= end
->pixel_width
;
27624 hlinfo
->mouse_face_end_x
= x
;
27625 hlinfo
->mouse_face_end_col
= end
- r2
->glyphs
[TEXT_AREA
];
27628 hlinfo
->mouse_face_window
= window
;
27629 hlinfo
->mouse_face_face_id
27630 = face_at_buffer_position (w
, mouse_charpos
, &ignore
,
27632 !hlinfo
->mouse_face_hidden
, -1);
27633 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
27636 /* The following function is not used anymore (replaced with
27637 mouse_face_from_string_pos), but I leave it here for the time
27638 being, in case someone would. */
27640 #if 0 /* not used */
27642 /* Find the position of the glyph for position POS in OBJECT in
27643 window W's current matrix, and return in *X, *Y the pixel
27644 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
27646 RIGHT_P non-zero means return the position of the right edge of the
27647 glyph, RIGHT_P zero means return the left edge position.
27649 If no glyph for POS exists in the matrix, return the position of
27650 the glyph with the next smaller position that is in the matrix, if
27651 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
27652 exists in the matrix, return the position of the glyph with the
27653 next larger position in OBJECT.
27655 Value is non-zero if a glyph was found. */
27658 fast_find_string_pos (struct window
*w
, ptrdiff_t pos
, Lisp_Object object
,
27659 int *hpos
, int *vpos
, int *x
, int *y
, int right_p
)
27661 int yb
= window_text_bottom_y (w
);
27662 struct glyph_row
*r
;
27663 struct glyph
*best_glyph
= NULL
;
27664 struct glyph_row
*best_row
= NULL
;
27667 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27668 r
->enabled_p
&& r
->y
< yb
;
27671 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
27672 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
27675 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
27676 if (EQ (g
->object
, object
))
27678 if (g
->charpos
== pos
)
27685 else if (best_glyph
== NULL
27686 || ((eabs (g
->charpos
- pos
)
27687 < eabs (best_glyph
->charpos
- pos
))
27690 : g
->charpos
> pos
)))
27704 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
27708 *x
+= best_glyph
->pixel_width
;
27713 *vpos
= MATRIX_ROW_VPOS (best_row
, w
->current_matrix
);
27716 return best_glyph
!= NULL
;
27718 #endif /* not used */
27720 /* Find the positions of the first and the last glyphs in window W's
27721 current matrix that occlude positions [STARTPOS..ENDPOS) in OBJECT
27722 (assumed to be a string), and return in HLINFO's mouse_face_*
27723 members the pixel and column/row coordinates of those glyphs. */
27726 mouse_face_from_string_pos (struct window
*w
, Mouse_HLInfo
*hlinfo
,
27727 Lisp_Object object
,
27728 ptrdiff_t startpos
, ptrdiff_t endpos
)
27730 int yb
= window_text_bottom_y (w
);
27731 struct glyph_row
*r
;
27732 struct glyph
*g
, *e
;
27736 /* Find the glyph row with at least one position in the range
27737 [STARTPOS..ENDPOS), and the first glyph in that row whose
27738 position belongs to that range. */
27739 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27740 r
->enabled_p
&& r
->y
< yb
;
27743 if (!r
->reversed_p
)
27745 g
= r
->glyphs
[TEXT_AREA
];
27746 e
= g
+ r
->used
[TEXT_AREA
];
27747 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
27748 if (EQ (g
->object
, object
)
27749 && startpos
<= g
->charpos
&& g
->charpos
< endpos
)
27751 hlinfo
->mouse_face_beg_row
27752 = MATRIX_ROW_VPOS (r
, w
->current_matrix
);
27753 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
27754 hlinfo
->mouse_face_beg_x
= gx
;
27763 e
= r
->glyphs
[TEXT_AREA
];
27764 g
= e
+ r
->used
[TEXT_AREA
];
27765 for ( ; g
> e
; --g
)
27766 if (EQ ((g
-1)->object
, object
)
27767 && startpos
<= (g
-1)->charpos
&& (g
-1)->charpos
< endpos
)
27769 hlinfo
->mouse_face_beg_row
27770 = MATRIX_ROW_VPOS (r
, w
->current_matrix
);
27771 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
27772 for (gx
= r
->x
, g1
= r
->glyphs
[TEXT_AREA
]; g1
< g
; ++g1
)
27773 gx
+= g1
->pixel_width
;
27774 hlinfo
->mouse_face_beg_x
= gx
;
27786 /* Starting with the next row, look for the first row which does NOT
27787 include any glyphs whose positions are in the range. */
27788 for (++r
; r
->enabled_p
&& r
->y
< yb
; ++r
)
27790 g
= r
->glyphs
[TEXT_AREA
];
27791 e
= g
+ r
->used
[TEXT_AREA
];
27793 for ( ; g
< e
; ++g
)
27794 if (EQ (g
->object
, object
)
27795 && startpos
<= g
->charpos
&& g
->charpos
< endpos
)
27804 /* The highlighted region ends on the previous row. */
27807 /* Set the end row. */
27808 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r
, w
->current_matrix
);
27810 /* Compute and set the end column and the end column's horizontal
27811 pixel coordinate. */
27812 if (!r
->reversed_p
)
27814 g
= r
->glyphs
[TEXT_AREA
];
27815 e
= g
+ r
->used
[TEXT_AREA
];
27816 for ( ; e
> g
; --e
)
27817 if (EQ ((e
-1)->object
, object
)
27818 && startpos
<= (e
-1)->charpos
&& (e
-1)->charpos
< endpos
)
27820 hlinfo
->mouse_face_end_col
= e
- g
;
27822 for (gx
= r
->x
; g
< e
; ++g
)
27823 gx
+= g
->pixel_width
;
27824 hlinfo
->mouse_face_end_x
= gx
;
27828 e
= r
->glyphs
[TEXT_AREA
];
27829 g
= e
+ r
->used
[TEXT_AREA
];
27830 for (gx
= r
->x
; e
< g
; ++e
)
27832 if (EQ (e
->object
, object
)
27833 && startpos
<= e
->charpos
&& e
->charpos
< endpos
)
27835 gx
+= e
->pixel_width
;
27837 hlinfo
->mouse_face_end_col
= e
- r
->glyphs
[TEXT_AREA
];
27838 hlinfo
->mouse_face_end_x
= gx
;
27842 #ifdef HAVE_WINDOW_SYSTEM
27844 /* See if position X, Y is within a hot-spot of an image. */
27847 on_hot_spot_p (Lisp_Object hot_spot
, int x
, int y
)
27849 if (!CONSP (hot_spot
))
27852 if (EQ (XCAR (hot_spot
), Qrect
))
27854 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
27855 Lisp_Object rect
= XCDR (hot_spot
);
27859 if (!CONSP (XCAR (rect
)))
27861 if (!CONSP (XCDR (rect
)))
27863 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
27865 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
27867 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
27869 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
27873 else if (EQ (XCAR (hot_spot
), Qcircle
))
27875 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
27876 Lisp_Object circ
= XCDR (hot_spot
);
27877 Lisp_Object lr
, lx0
, ly0
;
27879 && CONSP (XCAR (circ
))
27880 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
27881 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
27882 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
27884 double r
= XFLOATINT (lr
);
27885 double dx
= XINT (lx0
) - x
;
27886 double dy
= XINT (ly0
) - y
;
27887 return (dx
* dx
+ dy
* dy
<= r
* r
);
27890 else if (EQ (XCAR (hot_spot
), Qpoly
))
27892 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
27893 if (VECTORP (XCDR (hot_spot
)))
27895 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
27896 Lisp_Object
*poly
= v
->contents
;
27897 ptrdiff_t n
= v
->header
.size
;
27900 Lisp_Object lx
, ly
;
27903 /* Need an even number of coordinates, and at least 3 edges. */
27904 if (n
< 6 || n
& 1)
27907 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
27908 If count is odd, we are inside polygon. Pixels on edges
27909 may or may not be included depending on actual geometry of the
27911 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
27912 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
27914 x0
= XINT (lx
), y0
= XINT (ly
);
27915 for (i
= 0; i
< n
; i
+= 2)
27917 int x1
= x0
, y1
= y0
;
27918 if ((lx
= poly
[i
], !INTEGERP (lx
))
27919 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
27921 x0
= XINT (lx
), y0
= XINT (ly
);
27923 /* Does this segment cross the X line? */
27931 if (y
> y0
&& y
> y1
)
27933 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
27943 find_hot_spot (Lisp_Object map
, int x
, int y
)
27945 while (CONSP (map
))
27947 if (CONSP (XCAR (map
))
27948 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
27956 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
27958 doc
: /* Lookup in image map MAP coordinates X and Y.
27959 An image map is an alist where each element has the format (AREA ID PLIST).
27960 An AREA is specified as either a rectangle, a circle, or a polygon:
27961 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
27962 pixel coordinates of the upper left and bottom right corners.
27963 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
27964 and the radius of the circle; r may be a float or integer.
27965 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
27966 vector describes one corner in the polygon.
27967 Returns the alist element for the first matching AREA in MAP. */)
27968 (Lisp_Object map
, Lisp_Object x
, Lisp_Object y
)
27976 return find_hot_spot (map
,
27977 clip_to_bounds (INT_MIN
, XINT (x
), INT_MAX
),
27978 clip_to_bounds (INT_MIN
, XINT (y
), INT_MAX
));
27982 /* Display frame CURSOR, optionally using shape defined by POINTER. */
27984 define_frame_cursor1 (struct frame
*f
, Cursor cursor
, Lisp_Object pointer
)
27986 /* Do not change cursor shape while dragging mouse. */
27987 if (!NILP (do_mouse_tracking
))
27990 if (!NILP (pointer
))
27992 if (EQ (pointer
, Qarrow
))
27993 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27994 else if (EQ (pointer
, Qhand
))
27995 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
27996 else if (EQ (pointer
, Qtext
))
27997 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
27998 else if (EQ (pointer
, intern ("hdrag")))
27999 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
28000 else if (EQ (pointer
, intern ("nhdrag")))
28001 cursor
= FRAME_X_OUTPUT (f
)->vertical_drag_cursor
;
28002 #ifdef HAVE_X_WINDOWS
28003 else if (EQ (pointer
, intern ("vdrag")))
28004 cursor
= FRAME_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
28006 else if (EQ (pointer
, intern ("hourglass")))
28007 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
28008 else if (EQ (pointer
, Qmodeline
))
28009 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
28011 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
28014 if (cursor
!= No_Cursor
)
28015 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
28018 #endif /* HAVE_WINDOW_SYSTEM */
28020 /* Take proper action when mouse has moved to the mode or header line
28021 or marginal area AREA of window W, x-position X and y-position Y.
28022 X is relative to the start of the text display area of W, so the
28023 width of bitmap areas and scroll bars must be subtracted to get a
28024 position relative to the start of the mode line. */
28027 note_mode_line_or_margin_highlight (Lisp_Object window
, int x
, int y
,
28028 enum window_part area
)
28030 struct window
*w
= XWINDOW (window
);
28031 struct frame
*f
= XFRAME (w
->frame
);
28032 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28033 #ifdef HAVE_WINDOW_SYSTEM
28034 Display_Info
*dpyinfo
;
28036 Cursor cursor
= No_Cursor
;
28037 Lisp_Object pointer
= Qnil
;
28038 int dx
, dy
, width
, height
;
28040 Lisp_Object string
, object
= Qnil
;
28041 Lisp_Object pos
IF_LINT (= Qnil
), help
;
28043 Lisp_Object mouse_face
;
28044 int original_x_pixel
= x
;
28045 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
28046 struct glyph_row
*row
IF_LINT (= 0);
28048 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
28053 /* Kludge alert: mode_line_string takes X/Y in pixels, but
28054 returns them in row/column units! */
28055 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
28056 &object
, &dx
, &dy
, &width
, &height
);
28058 row
= (area
== ON_MODE_LINE
28059 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
28060 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
28062 /* Find the glyph under the mouse pointer. */
28063 if (row
->mode_line_p
&& row
->enabled_p
)
28065 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
28066 end
= glyph
+ row
->used
[TEXT_AREA
];
28068 for (x0
= original_x_pixel
;
28069 glyph
< end
&& x0
>= glyph
->pixel_width
;
28071 x0
-= glyph
->pixel_width
;
28079 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
28080 /* Kludge alert: marginal_area_string takes X/Y in pixels, but
28081 returns them in row/column units! */
28082 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
28083 &object
, &dx
, &dy
, &width
, &height
);
28088 #ifdef HAVE_WINDOW_SYSTEM
28089 if (IMAGEP (object
))
28091 Lisp_Object image_map
, hotspot
;
28092 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
28094 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
28096 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
28100 /* Could check XCAR (hotspot) to see if we enter/leave this hot-spot.
28101 If so, we could look for mouse-enter, mouse-leave
28102 properties in PLIST (and do something...). */
28103 hotspot
= XCDR (hotspot
);
28104 if (CONSP (hotspot
)
28105 && (plist
= XCAR (hotspot
), CONSP (plist
)))
28107 pointer
= Fplist_get (plist
, Qpointer
);
28108 if (NILP (pointer
))
28110 help
= Fplist_get (plist
, Qhelp_echo
);
28113 help_echo_string
= help
;
28114 XSETWINDOW (help_echo_window
, w
);
28115 help_echo_object
= w
->contents
;
28116 help_echo_pos
= charpos
;
28120 if (NILP (pointer
))
28121 pointer
= Fplist_get (XCDR (object
), QCpointer
);
28123 #endif /* HAVE_WINDOW_SYSTEM */
28125 if (STRINGP (string
))
28126 pos
= make_number (charpos
);
28128 /* Set the help text and mouse pointer. If the mouse is on a part
28129 of the mode line without any text (e.g. past the right edge of
28130 the mode line text), use the default help text and pointer. */
28131 if (STRINGP (string
) || area
== ON_MODE_LINE
)
28133 /* Arrange to display the help by setting the global variables
28134 help_echo_string, help_echo_object, and help_echo_pos. */
28137 if (STRINGP (string
))
28138 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
28142 help_echo_string
= help
;
28143 XSETWINDOW (help_echo_window
, w
);
28144 help_echo_object
= string
;
28145 help_echo_pos
= charpos
;
28147 else if (area
== ON_MODE_LINE
)
28149 Lisp_Object default_help
28150 = buffer_local_value_1 (Qmode_line_default_help_echo
,
28153 if (STRINGP (default_help
))
28155 help_echo_string
= default_help
;
28156 XSETWINDOW (help_echo_window
, w
);
28157 help_echo_object
= Qnil
;
28158 help_echo_pos
= -1;
28163 #ifdef HAVE_WINDOW_SYSTEM
28164 /* Change the mouse pointer according to what is under it. */
28165 if (FRAME_WINDOW_P (f
))
28167 dpyinfo
= FRAME_DISPLAY_INFO (f
);
28168 if (STRINGP (string
))
28170 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
28172 if (NILP (pointer
))
28173 pointer
= Fget_text_property (pos
, Qpointer
, string
);
28175 /* Change the mouse pointer according to what is under X/Y. */
28177 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
28180 map
= Fget_text_property (pos
, Qlocal_map
, string
);
28181 if (!KEYMAPP (map
))
28182 map
= Fget_text_property (pos
, Qkeymap
, string
);
28183 if (!KEYMAPP (map
))
28184 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
28188 /* Default mode-line pointer. */
28189 cursor
= FRAME_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
28194 /* Change the mouse face according to what is under X/Y. */
28195 if (STRINGP (string
))
28197 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
28198 if (!NILP (Vmouse_highlight
) && !NILP (mouse_face
)
28199 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
28204 struct glyph
* tmp_glyph
;
28208 int total_pixel_width
;
28209 ptrdiff_t begpos
, endpos
, ignore
;
28213 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
28214 Qmouse_face
, string
, Qnil
);
28220 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
28222 endpos
= SCHARS (string
);
28226 /* Calculate the glyph position GPOS of GLYPH in the
28227 displayed string, relative to the beginning of the
28228 highlighted part of the string.
28230 Note: GPOS is different from CHARPOS. CHARPOS is the
28231 position of GLYPH in the internal string object. A mode
28232 line string format has structures which are converted to
28233 a flattened string by the Emacs Lisp interpreter. The
28234 internal string is an element of those structures. The
28235 displayed string is the flattened string. */
28236 tmp_glyph
= row_start_glyph
;
28237 while (tmp_glyph
< glyph
28238 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
28239 && begpos
<= tmp_glyph
->charpos
28240 && tmp_glyph
->charpos
< endpos
)))
28242 gpos
= glyph
- tmp_glyph
;
28244 /* Calculate the length GSEQ_LENGTH of the glyph sequence of
28245 the highlighted part of the displayed string to which
28246 GLYPH belongs. Note: GSEQ_LENGTH is different from
28247 SCHARS (STRING), because the latter returns the length of
28248 the internal string. */
28249 for (tmp_glyph
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
28251 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
28252 && begpos
<= tmp_glyph
->charpos
28253 && tmp_glyph
->charpos
< endpos
));
28256 gseq_length
= gpos
+ (tmp_glyph
- glyph
) + 1;
28258 /* Calculate the total pixel width of all the glyphs between
28259 the beginning of the highlighted area and GLYPH. */
28260 total_pixel_width
= 0;
28261 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
28262 total_pixel_width
+= tmp_glyph
->pixel_width
;
28264 /* Pre calculation of re-rendering position. Note: X is in
28265 column units here, after the call to mode_line_string or
28266 marginal_area_string. */
28268 vpos
= (area
== ON_MODE_LINE
28269 ? (w
->current_matrix
)->nrows
- 1
28272 /* If GLYPH's position is included in the region that is
28273 already drawn in mouse face, we have nothing to do. */
28274 if ( EQ (window
, hlinfo
->mouse_face_window
)
28275 && (!row
->reversed_p
28276 ? (hlinfo
->mouse_face_beg_col
<= hpos
28277 && hpos
< hlinfo
->mouse_face_end_col
)
28278 /* In R2L rows we swap BEG and END, see below. */
28279 : (hlinfo
->mouse_face_end_col
<= hpos
28280 && hpos
< hlinfo
->mouse_face_beg_col
))
28281 && hlinfo
->mouse_face_beg_row
== vpos
)
28284 if (clear_mouse_face (hlinfo
))
28285 cursor
= No_Cursor
;
28287 if (!row
->reversed_p
)
28289 hlinfo
->mouse_face_beg_col
= hpos
;
28290 hlinfo
->mouse_face_beg_x
= original_x_pixel
28291 - (total_pixel_width
+ dx
);
28292 hlinfo
->mouse_face_end_col
= hpos
+ gseq_length
;
28293 hlinfo
->mouse_face_end_x
= 0;
28297 /* In R2L rows, show_mouse_face expects BEG and END
28298 coordinates to be swapped. */
28299 hlinfo
->mouse_face_end_col
= hpos
;
28300 hlinfo
->mouse_face_end_x
= original_x_pixel
28301 - (total_pixel_width
+ dx
);
28302 hlinfo
->mouse_face_beg_col
= hpos
+ gseq_length
;
28303 hlinfo
->mouse_face_beg_x
= 0;
28306 hlinfo
->mouse_face_beg_row
= vpos
;
28307 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_beg_row
;
28308 hlinfo
->mouse_face_past_end
= 0;
28309 hlinfo
->mouse_face_window
= window
;
28311 hlinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
28316 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
28318 if (NILP (pointer
))
28321 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
28322 clear_mouse_face (hlinfo
);
28324 #ifdef HAVE_WINDOW_SYSTEM
28325 if (FRAME_WINDOW_P (f
))
28326 define_frame_cursor1 (f
, cursor
, pointer
);
28332 Take proper action when the mouse has moved to position X, Y on
28333 frame F with regards to highlighting portions of display that have
28334 mouse-face properties. Also de-highlight portions of display where
28335 the mouse was before, set the mouse pointer shape as appropriate
28336 for the mouse coordinates, and activate help echo (tooltips).
28337 X and Y can be negative or out of range. */
28340 note_mouse_highlight (struct frame
*f
, int x
, int y
)
28342 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28343 enum window_part part
= ON_NOTHING
;
28344 Lisp_Object window
;
28346 Cursor cursor
= No_Cursor
;
28347 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
28350 /* When a menu is active, don't highlight because this looks odd. */
28351 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (MSDOS)
28352 if (popup_activated ())
28356 if (!f
->glyphs_initialized_p
28357 || f
->pointer_invisible
)
28360 hlinfo
->mouse_face_mouse_x
= x
;
28361 hlinfo
->mouse_face_mouse_y
= y
;
28362 hlinfo
->mouse_face_mouse_frame
= f
;
28364 if (hlinfo
->mouse_face_defer
)
28367 /* Which window is that in? */
28368 window
= window_from_coordinates (f
, x
, y
, &part
, 1);
28370 /* If displaying active text in another window, clear that. */
28371 if (! EQ (window
, hlinfo
->mouse_face_window
)
28372 /* Also clear if we move out of text area in same window. */
28373 || (!NILP (hlinfo
->mouse_face_window
)
28376 && part
!= ON_MODE_LINE
28377 && part
!= ON_HEADER_LINE
))
28378 clear_mouse_face (hlinfo
);
28380 /* Not on a window -> return. */
28381 if (!WINDOWP (window
))
28384 /* Reset help_echo_string. It will get recomputed below. */
28385 help_echo_string
= Qnil
;
28387 /* Convert to window-relative pixel coordinates. */
28388 w
= XWINDOW (window
);
28389 frame_to_window_pixel_xy (w
, &x
, &y
);
28391 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
28392 /* Handle tool-bar window differently since it doesn't display a
28394 if (EQ (window
, f
->tool_bar_window
))
28396 note_tool_bar_highlight (f
, x
, y
);
28401 /* Mouse is on the mode, header line or margin? */
28402 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
28403 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
28405 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
28409 #ifdef HAVE_WINDOW_SYSTEM
28410 if (part
== ON_VERTICAL_BORDER
)
28412 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
28413 help_echo_string
= build_string ("drag-mouse-1: resize");
28415 else if (part
== ON_RIGHT_DIVIDER
)
28417 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
28418 help_echo_string
= build_string ("drag-mouse-1: resize");
28420 else if (part
== ON_BOTTOM_DIVIDER
)
28422 cursor
= FRAME_X_OUTPUT (f
)->vertical_drag_cursor
;
28423 help_echo_string
= build_string ("drag-mouse-1: resize");
28425 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
28426 || part
== ON_SCROLL_BAR
)
28427 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
28429 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
28432 /* Are we in a window whose display is up to date?
28433 And verify the buffer's text has not changed. */
28434 b
= XBUFFER (w
->contents
);
28435 if (part
== ON_TEXT
&& w
->window_end_valid
&& !window_outdated (w
))
28437 int hpos
, vpos
, dx
, dy
, area
= LAST_AREA
;
28439 struct glyph
*glyph
;
28440 Lisp_Object object
;
28441 Lisp_Object mouse_face
= Qnil
, position
;
28442 Lisp_Object
*overlay_vec
= NULL
;
28443 ptrdiff_t i
, noverlays
;
28444 struct buffer
*obuf
;
28445 ptrdiff_t obegv
, ozv
;
28448 /* Find the glyph under X/Y. */
28449 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
28451 #ifdef HAVE_WINDOW_SYSTEM
28452 /* Look for :pointer property on image. */
28453 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
28455 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
28456 if (img
!= NULL
&& IMAGEP (img
->spec
))
28458 Lisp_Object image_map
, hotspot
;
28459 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
28461 && (hotspot
= find_hot_spot (image_map
,
28462 glyph
->slice
.img
.x
+ dx
,
28463 glyph
->slice
.img
.y
+ dy
),
28465 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
28469 /* Could check XCAR (hotspot) to see if we enter/leave
28471 If so, we could look for mouse-enter, mouse-leave
28472 properties in PLIST (and do something...). */
28473 hotspot
= XCDR (hotspot
);
28474 if (CONSP (hotspot
)
28475 && (plist
= XCAR (hotspot
), CONSP (plist
)))
28477 pointer
= Fplist_get (plist
, Qpointer
);
28478 if (NILP (pointer
))
28480 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
28481 if (!NILP (help_echo_string
))
28483 help_echo_window
= window
;
28484 help_echo_object
= glyph
->object
;
28485 help_echo_pos
= glyph
->charpos
;
28489 if (NILP (pointer
))
28490 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
28493 #endif /* HAVE_WINDOW_SYSTEM */
28495 /* Clear mouse face if X/Y not over text. */
28497 || area
!= TEXT_AREA
28498 || !MATRIX_ROW_DISPLAYS_TEXT_P (MATRIX_ROW (w
->current_matrix
, vpos
))
28499 /* Glyph's OBJECT is an integer for glyphs inserted by the
28500 display engine for its internal purposes, like truncation
28501 and continuation glyphs and blanks beyond the end of
28502 line's text on text terminals. If we are over such a
28503 glyph, we are not over any text. */
28504 || INTEGERP (glyph
->object
)
28505 /* R2L rows have a stretch glyph at their front, which
28506 stands for no text, whereas L2R rows have no glyphs at
28507 all beyond the end of text. Treat such stretch glyphs
28508 like we do with NULL glyphs in L2R rows. */
28509 || (MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
28510 && glyph
== MATRIX_ROW_GLYPH_START (w
->current_matrix
, vpos
)
28511 && glyph
->type
== STRETCH_GLYPH
28512 && glyph
->avoid_cursor_p
))
28514 if (clear_mouse_face (hlinfo
))
28515 cursor
= No_Cursor
;
28516 #ifdef HAVE_WINDOW_SYSTEM
28517 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
28519 if (area
!= TEXT_AREA
)
28520 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
28522 pointer
= Vvoid_text_area_pointer
;
28528 pos
= glyph
->charpos
;
28529 object
= glyph
->object
;
28530 if (!STRINGP (object
) && !BUFFERP (object
))
28533 /* If we get an out-of-range value, return now; avoid an error. */
28534 if (BUFFERP (object
) && pos
> BUF_Z (b
))
28537 /* Make the window's buffer temporarily current for
28538 overlays_at and compute_char_face. */
28539 obuf
= current_buffer
;
28540 current_buffer
= b
;
28546 /* Is this char mouse-active or does it have help-echo? */
28547 position
= make_number (pos
);
28549 if (BUFFERP (object
))
28551 /* Put all the overlays we want in a vector in overlay_vec. */
28552 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
28553 /* Sort overlays into increasing priority order. */
28554 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
28559 if (NILP (Vmouse_highlight
))
28561 clear_mouse_face (hlinfo
);
28562 goto check_help_echo
;
28565 same_region
= coords_in_mouse_face_p (w
, hpos
, vpos
);
28568 cursor
= No_Cursor
;
28570 /* Check mouse-face highlighting. */
28572 /* If there exists an overlay with mouse-face overlapping
28573 the one we are currently highlighting, we have to
28574 check if we enter the overlapping overlay, and then
28575 highlight only that. */
28576 || (OVERLAYP (hlinfo
->mouse_face_overlay
)
28577 && mouse_face_overlay_overlaps (hlinfo
->mouse_face_overlay
)))
28579 /* Find the highest priority overlay with a mouse-face. */
28580 Lisp_Object overlay
= Qnil
;
28581 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
28583 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
28584 if (!NILP (mouse_face
))
28585 overlay
= overlay_vec
[i
];
28588 /* If we're highlighting the same overlay as before, there's
28589 no need to do that again. */
28590 if (!NILP (overlay
) && EQ (overlay
, hlinfo
->mouse_face_overlay
))
28591 goto check_help_echo
;
28592 hlinfo
->mouse_face_overlay
= overlay
;
28594 /* Clear the display of the old active region, if any. */
28595 if (clear_mouse_face (hlinfo
))
28596 cursor
= No_Cursor
;
28598 /* If no overlay applies, get a text property. */
28599 if (NILP (overlay
))
28600 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
28602 /* Next, compute the bounds of the mouse highlighting and
28604 if (!NILP (mouse_face
) && STRINGP (object
))
28606 /* The mouse-highlighting comes from a display string
28607 with a mouse-face. */
28611 s
= Fprevious_single_property_change
28612 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
28613 e
= Fnext_single_property_change
28614 (position
, Qmouse_face
, object
, Qnil
);
28616 s
= make_number (0);
28618 e
= make_number (SCHARS (object
));
28619 mouse_face_from_string_pos (w
, hlinfo
, object
,
28620 XINT (s
), XINT (e
));
28621 hlinfo
->mouse_face_past_end
= 0;
28622 hlinfo
->mouse_face_window
= window
;
28623 hlinfo
->mouse_face_face_id
28624 = face_at_string_position (w
, object
, pos
, 0, &ignore
,
28625 glyph
->face_id
, 1);
28626 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
28627 cursor
= No_Cursor
;
28631 /* The mouse-highlighting, if any, comes from an overlay
28632 or text property in the buffer. */
28633 Lisp_Object buffer
IF_LINT (= Qnil
);
28634 Lisp_Object disp_string
IF_LINT (= Qnil
);
28636 if (STRINGP (object
))
28638 /* If we are on a display string with no mouse-face,
28639 check if the text under it has one. */
28640 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
28641 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28642 pos
= string_buffer_position (object
, start
);
28645 mouse_face
= get_char_property_and_overlay
28646 (make_number (pos
), Qmouse_face
, w
->contents
, &overlay
);
28647 buffer
= w
->contents
;
28648 disp_string
= object
;
28654 disp_string
= Qnil
;
28657 if (!NILP (mouse_face
))
28659 Lisp_Object before
, after
;
28660 Lisp_Object before_string
, after_string
;
28661 /* To correctly find the limits of mouse highlight
28662 in a bidi-reordered buffer, we must not use the
28663 optimization of limiting the search in
28664 previous-single-property-change and
28665 next-single-property-change, because
28666 rows_from_pos_range needs the real start and end
28667 positions to DTRT in this case. That's because
28668 the first row visible in a window does not
28669 necessarily display the character whose position
28670 is the smallest. */
28672 = NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
28673 ? Fmarker_position (w
->start
)
28676 = NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
28677 ? make_number (BUF_Z (XBUFFER (buffer
))
28678 - w
->window_end_pos
)
28681 if (NILP (overlay
))
28683 /* Handle the text property case. */
28684 before
= Fprevious_single_property_change
28685 (make_number (pos
+ 1), Qmouse_face
, buffer
, lim1
);
28686 after
= Fnext_single_property_change
28687 (make_number (pos
), Qmouse_face
, buffer
, lim2
);
28688 before_string
= after_string
= Qnil
;
28692 /* Handle the overlay case. */
28693 before
= Foverlay_start (overlay
);
28694 after
= Foverlay_end (overlay
);
28695 before_string
= Foverlay_get (overlay
, Qbefore_string
);
28696 after_string
= Foverlay_get (overlay
, Qafter_string
);
28698 if (!STRINGP (before_string
)) before_string
= Qnil
;
28699 if (!STRINGP (after_string
)) after_string
= Qnil
;
28702 mouse_face_from_buffer_pos (window
, hlinfo
, pos
,
28705 : XFASTINT (before
),
28707 ? BUF_Z (XBUFFER (buffer
))
28708 : XFASTINT (after
),
28709 before_string
, after_string
,
28711 cursor
= No_Cursor
;
28718 /* Look for a `help-echo' property. */
28719 if (NILP (help_echo_string
)) {
28720 Lisp_Object help
, overlay
;
28722 /* Check overlays first. */
28723 help
= overlay
= Qnil
;
28724 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
28726 overlay
= overlay_vec
[i
];
28727 help
= Foverlay_get (overlay
, Qhelp_echo
);
28732 help_echo_string
= help
;
28733 help_echo_window
= window
;
28734 help_echo_object
= overlay
;
28735 help_echo_pos
= pos
;
28739 Lisp_Object obj
= glyph
->object
;
28740 ptrdiff_t charpos
= glyph
->charpos
;
28742 /* Try text properties. */
28745 && charpos
< SCHARS (obj
))
28747 help
= Fget_text_property (make_number (charpos
),
28751 /* If the string itself doesn't specify a help-echo,
28752 see if the buffer text ``under'' it does. */
28753 struct glyph_row
*r
28754 = MATRIX_ROW (w
->current_matrix
, vpos
);
28755 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28756 ptrdiff_t p
= string_buffer_position (obj
, start
);
28759 help
= Fget_char_property (make_number (p
),
28760 Qhelp_echo
, w
->contents
);
28769 else if (BUFFERP (obj
)
28772 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
28777 help_echo_string
= help
;
28778 help_echo_window
= window
;
28779 help_echo_object
= obj
;
28780 help_echo_pos
= charpos
;
28785 #ifdef HAVE_WINDOW_SYSTEM
28786 /* Look for a `pointer' property. */
28787 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
28789 /* Check overlays first. */
28790 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
28791 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
28793 if (NILP (pointer
))
28795 Lisp_Object obj
= glyph
->object
;
28796 ptrdiff_t charpos
= glyph
->charpos
;
28798 /* Try text properties. */
28801 && charpos
< SCHARS (obj
))
28803 pointer
= Fget_text_property (make_number (charpos
),
28805 if (NILP (pointer
))
28807 /* If the string itself doesn't specify a pointer,
28808 see if the buffer text ``under'' it does. */
28809 struct glyph_row
*r
28810 = MATRIX_ROW (w
->current_matrix
, vpos
);
28811 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28812 ptrdiff_t p
= string_buffer_position (obj
, start
);
28814 pointer
= Fget_char_property (make_number (p
),
28815 Qpointer
, w
->contents
);
28818 else if (BUFFERP (obj
)
28821 pointer
= Fget_text_property (make_number (charpos
),
28825 #endif /* HAVE_WINDOW_SYSTEM */
28829 current_buffer
= obuf
;
28834 #ifdef HAVE_WINDOW_SYSTEM
28835 if (FRAME_WINDOW_P (f
))
28836 define_frame_cursor1 (f
, cursor
, pointer
);
28838 /* This is here to prevent a compiler error, about "label at end of
28839 compound statement". */
28846 Clear any mouse-face on window W. This function is part of the
28847 redisplay interface, and is called from try_window_id and similar
28848 functions to ensure the mouse-highlight is off. */
28851 x_clear_window_mouse_face (struct window
*w
)
28853 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
28854 Lisp_Object window
;
28857 XSETWINDOW (window
, w
);
28858 if (EQ (window
, hlinfo
->mouse_face_window
))
28859 clear_mouse_face (hlinfo
);
28865 Just discard the mouse face information for frame F, if any.
28866 This is used when the size of F is changed. */
28869 cancel_mouse_face (struct frame
*f
)
28871 Lisp_Object window
;
28872 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28874 window
= hlinfo
->mouse_face_window
;
28875 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
28876 reset_mouse_highlight (hlinfo
);
28881 /***********************************************************************
28883 ***********************************************************************/
28885 #ifdef HAVE_WINDOW_SYSTEM
28887 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
28888 which intersects rectangle R. R is in window-relative coordinates. */
28891 expose_area (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
,
28892 enum glyph_row_area area
)
28894 struct glyph
*first
= row
->glyphs
[area
];
28895 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
28896 struct glyph
*last
;
28897 int first_x
, start_x
, x
;
28899 if (area
== TEXT_AREA
&& row
->fill_line_p
)
28900 /* If row extends face to end of line write the whole line. */
28901 draw_glyphs (w
, 0, row
, area
,
28902 0, row
->used
[area
],
28903 DRAW_NORMAL_TEXT
, 0);
28906 /* Set START_X to the window-relative start position for drawing glyphs of
28907 AREA. The first glyph of the text area can be partially visible.
28908 The first glyphs of other areas cannot. */
28909 start_x
= window_box_left_offset (w
, area
);
28911 if (area
== TEXT_AREA
)
28914 /* Find the first glyph that must be redrawn. */
28916 && x
+ first
->pixel_width
< r
->x
)
28918 x
+= first
->pixel_width
;
28922 /* Find the last one. */
28926 && x
< r
->x
+ r
->width
)
28928 x
+= last
->pixel_width
;
28934 draw_glyphs (w
, first_x
- start_x
, row
, area
,
28935 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
28936 DRAW_NORMAL_TEXT
, 0);
28941 /* Redraw the parts of the glyph row ROW on window W intersecting
28942 rectangle R. R is in window-relative coordinates. Value is
28943 non-zero if mouse-face was overwritten. */
28946 expose_line (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
)
28948 eassert (row
->enabled_p
);
28950 if (row
->mode_line_p
|| w
->pseudo_window_p
)
28951 draw_glyphs (w
, 0, row
, TEXT_AREA
,
28952 0, row
->used
[TEXT_AREA
],
28953 DRAW_NORMAL_TEXT
, 0);
28956 if (row
->used
[LEFT_MARGIN_AREA
])
28957 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
28958 if (row
->used
[TEXT_AREA
])
28959 expose_area (w
, row
, r
, TEXT_AREA
);
28960 if (row
->used
[RIGHT_MARGIN_AREA
])
28961 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
28962 draw_row_fringe_bitmaps (w
, row
);
28965 return row
->mouse_face_p
;
28969 /* Redraw those parts of glyphs rows during expose event handling that
28970 overlap other rows. Redrawing of an exposed line writes over parts
28971 of lines overlapping that exposed line; this function fixes that.
28973 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
28974 row in W's current matrix that is exposed and overlaps other rows.
28975 LAST_OVERLAPPING_ROW is the last such row. */
28978 expose_overlaps (struct window
*w
,
28979 struct glyph_row
*first_overlapping_row
,
28980 struct glyph_row
*last_overlapping_row
,
28983 struct glyph_row
*row
;
28985 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
28986 if (row
->overlapping_p
)
28988 eassert (row
->enabled_p
&& !row
->mode_line_p
);
28991 if (row
->used
[LEFT_MARGIN_AREA
])
28992 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
28994 if (row
->used
[TEXT_AREA
])
28995 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
28997 if (row
->used
[RIGHT_MARGIN_AREA
])
28998 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
29004 /* Return non-zero if W's cursor intersects rectangle R. */
29007 phys_cursor_in_rect_p (struct window
*w
, XRectangle
*r
)
29009 XRectangle cr
, result
;
29010 struct glyph
*cursor_glyph
;
29011 struct glyph_row
*row
;
29013 if (w
->phys_cursor
.vpos
>= 0
29014 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
29015 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
29017 && row
->cursor_in_fringe_p
)
29019 /* Cursor is in the fringe. */
29020 cr
.x
= window_box_right_offset (w
,
29021 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
29022 ? RIGHT_MARGIN_AREA
29025 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
29026 cr
.height
= row
->height
;
29027 return x_intersect_rectangles (&cr
, r
, &result
);
29030 cursor_glyph
= get_phys_cursor_glyph (w
);
29033 /* r is relative to W's box, but w->phys_cursor.x is relative
29034 to left edge of W's TEXT area. Adjust it. */
29035 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
29036 cr
.y
= w
->phys_cursor
.y
;
29037 cr
.width
= cursor_glyph
->pixel_width
;
29038 cr
.height
= w
->phys_cursor_height
;
29039 /* ++KFS: W32 version used W32-specific IntersectRect here, but
29040 I assume the effect is the same -- and this is portable. */
29041 return x_intersect_rectangles (&cr
, r
, &result
);
29043 /* If we don't understand the format, pretend we're not in the hot-spot. */
29049 Draw a vertical window border to the right of window W if W doesn't
29050 have vertical scroll bars. */
29053 x_draw_vertical_border (struct window
*w
)
29055 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
29057 /* We could do better, if we knew what type of scroll-bar the adjacent
29058 windows (on either side) have... But we don't :-(
29059 However, I think this works ok. ++KFS 2003-04-25 */
29061 /* Redraw borders between horizontally adjacent windows. Don't
29062 do it for frames with vertical scroll bars because either the
29063 right scroll bar of a window, or the left scroll bar of its
29064 neighbor will suffice as a border. */
29065 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
) || FRAME_RIGHT_DIVIDER_WIDTH (f
))
29068 /* Note: It is necessary to redraw both the left and the right
29069 borders, for when only this single window W is being
29071 if (!WINDOW_RIGHTMOST_P (w
)
29072 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
29074 int x0
, x1
, y0
, y1
;
29076 window_box_edges (w
, &x0
, &y0
, &x1
, &y1
);
29079 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
29082 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
29085 if (!WINDOW_LEFTMOST_P (w
)
29086 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
29088 int x0
, x1
, y0
, y1
;
29090 window_box_edges (w
, &x0
, &y0
, &x1
, &y1
);
29093 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
29096 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
29101 /* Draw window dividers for window W. */
29104 x_draw_right_divider (struct window
*w
)
29106 struct frame
*f
= WINDOW_XFRAME (w
);
29108 if (w
->mini
|| w
->pseudo_window_p
)
29110 else if (WINDOW_RIGHT_DIVIDER_WIDTH (w
))
29112 int x0
= WINDOW_RIGHT_EDGE_X (w
) - WINDOW_RIGHT_DIVIDER_WIDTH (w
);
29113 int x1
= WINDOW_RIGHT_EDGE_X (w
);
29114 int y0
= WINDOW_TOP_EDGE_Y (w
);
29115 int y1
= WINDOW_BOTTOM_EDGE_Y (w
);
29117 FRAME_RIF (f
)->draw_window_divider (w
, x0
, x1
, y0
, y1
);
29122 x_draw_bottom_divider (struct window
*w
)
29124 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
29126 if (w
->mini
|| w
->pseudo_window_p
)
29128 else if (WINDOW_BOTTOM_DIVIDER_WIDTH (w
))
29130 int x0
= WINDOW_LEFT_EDGE_X (w
);
29131 int x1
= WINDOW_RIGHT_EDGE_X (w
);
29132 int y0
= WINDOW_BOTTOM_EDGE_Y (w
) - WINDOW_BOTTOM_DIVIDER_WIDTH (w
);
29133 int y1
= WINDOW_BOTTOM_EDGE_Y (w
);
29135 FRAME_RIF (f
)->draw_window_divider (w
, x0
, x1
, y0
, y1
);
29139 /* Redraw the part of window W intersection rectangle FR. Pixel
29140 coordinates in FR are frame-relative. Call this function with
29141 input blocked. Value is non-zero if the exposure overwrites
29145 expose_window (struct window
*w
, XRectangle
*fr
)
29147 struct frame
*f
= XFRAME (w
->frame
);
29149 int mouse_face_overwritten_p
= 0;
29151 /* If window is not yet fully initialized, do nothing. This can
29152 happen when toolkit scroll bars are used and a window is split.
29153 Reconfiguring the scroll bar will generate an expose for a newly
29155 if (w
->current_matrix
== NULL
)
29158 /* When we're currently updating the window, display and current
29159 matrix usually don't agree. Arrange for a thorough display
29161 if (w
->must_be_updated_p
)
29163 SET_FRAME_GARBAGED (f
);
29167 /* Frame-relative pixel rectangle of W. */
29168 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
29169 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
29170 wr
.width
= WINDOW_PIXEL_WIDTH (w
);
29171 wr
.height
= WINDOW_PIXEL_HEIGHT (w
);
29173 if (x_intersect_rectangles (fr
, &wr
, &r
))
29175 int yb
= window_text_bottom_y (w
);
29176 struct glyph_row
*row
;
29177 int cursor_cleared_p
, phys_cursor_on_p
;
29178 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
29180 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
29181 r
.x
, r
.y
, r
.width
, r
.height
));
29183 /* Convert to window coordinates. */
29184 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
29185 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
29187 /* Turn off the cursor. */
29188 if (!w
->pseudo_window_p
29189 && phys_cursor_in_rect_p (w
, &r
))
29191 x_clear_cursor (w
);
29192 cursor_cleared_p
= 1;
29195 cursor_cleared_p
= 0;
29197 /* If the row containing the cursor extends face to end of line,
29198 then expose_area might overwrite the cursor outside the
29199 rectangle and thus notice_overwritten_cursor might clear
29200 w->phys_cursor_on_p. We remember the original value and
29201 check later if it is changed. */
29202 phys_cursor_on_p
= w
->phys_cursor_on_p
;
29204 /* Update lines intersecting rectangle R. */
29205 first_overlapping_row
= last_overlapping_row
= NULL
;
29206 for (row
= w
->current_matrix
->rows
;
29211 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
29213 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
29214 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
29215 || (r
.y
>= y0
&& r
.y
< y1
)
29216 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
29218 /* A header line may be overlapping, but there is no need
29219 to fix overlapping areas for them. KFS 2005-02-12 */
29220 if (row
->overlapping_p
&& !row
->mode_line_p
)
29222 if (first_overlapping_row
== NULL
)
29223 first_overlapping_row
= row
;
29224 last_overlapping_row
= row
;
29228 if (expose_line (w
, row
, &r
))
29229 mouse_face_overwritten_p
= 1;
29232 else if (row
->overlapping_p
)
29234 /* We must redraw a row overlapping the exposed area. */
29236 ? y0
+ row
->phys_height
> r
.y
29237 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
29239 if (first_overlapping_row
== NULL
)
29240 first_overlapping_row
= row
;
29241 last_overlapping_row
= row
;
29249 /* Display the mode line if there is one. */
29250 if (WINDOW_WANTS_MODELINE_P (w
)
29251 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
29253 && row
->y
< r
.y
+ r
.height
)
29255 if (expose_line (w
, row
, &r
))
29256 mouse_face_overwritten_p
= 1;
29259 if (!w
->pseudo_window_p
)
29261 /* Fix the display of overlapping rows. */
29262 if (first_overlapping_row
)
29263 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
29266 /* Draw border between windows. */
29267 if (WINDOW_RIGHT_DIVIDER_WIDTH (w
))
29268 x_draw_right_divider (w
);
29270 x_draw_vertical_border (w
);
29272 if (WINDOW_BOTTOM_DIVIDER_WIDTH (w
))
29273 x_draw_bottom_divider (w
);
29275 /* Turn the cursor on again. */
29276 if (cursor_cleared_p
29277 || (phys_cursor_on_p
&& !w
->phys_cursor_on_p
))
29278 update_window_cursor (w
, 1);
29282 return mouse_face_overwritten_p
;
29287 /* Redraw (parts) of all windows in the window tree rooted at W that
29288 intersect R. R contains frame pixel coordinates. Value is
29289 non-zero if the exposure overwrites mouse-face. */
29292 expose_window_tree (struct window
*w
, XRectangle
*r
)
29294 struct frame
*f
= XFRAME (w
->frame
);
29295 int mouse_face_overwritten_p
= 0;
29297 while (w
&& !FRAME_GARBAGED_P (f
))
29299 if (WINDOWP (w
->contents
))
29300 mouse_face_overwritten_p
29301 |= expose_window_tree (XWINDOW (w
->contents
), r
);
29303 mouse_face_overwritten_p
|= expose_window (w
, r
);
29305 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
29308 return mouse_face_overwritten_p
;
29313 Redisplay an exposed area of frame F. X and Y are the upper-left
29314 corner of the exposed rectangle. W and H are width and height of
29315 the exposed area. All are pixel values. W or H zero means redraw
29316 the entire frame. */
29319 expose_frame (struct frame
*f
, int x
, int y
, int w
, int h
)
29322 int mouse_face_overwritten_p
= 0;
29324 TRACE ((stderr
, "expose_frame "));
29326 /* No need to redraw if frame will be redrawn soon. */
29327 if (FRAME_GARBAGED_P (f
))
29329 TRACE ((stderr
, " garbaged\n"));
29333 /* If basic faces haven't been realized yet, there is no point in
29334 trying to redraw anything. This can happen when we get an expose
29335 event while Emacs is starting, e.g. by moving another window. */
29336 if (FRAME_FACE_CACHE (f
) == NULL
29337 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
29339 TRACE ((stderr
, " no faces\n"));
29343 if (w
== 0 || h
== 0)
29346 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
29347 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
29357 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
29358 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
29360 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
29361 if (WINDOWP (f
->tool_bar_window
))
29362 mouse_face_overwritten_p
29363 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
29366 #ifdef HAVE_X_WINDOWS
29368 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
29369 if (WINDOWP (f
->menu_bar_window
))
29370 mouse_face_overwritten_p
29371 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
29372 #endif /* not USE_X_TOOLKIT and not USE_GTK */
29376 /* Some window managers support a focus-follows-mouse style with
29377 delayed raising of frames. Imagine a partially obscured frame,
29378 and moving the mouse into partially obscured mouse-face on that
29379 frame. The visible part of the mouse-face will be highlighted,
29380 then the WM raises the obscured frame. With at least one WM, KDE
29381 2.1, Emacs is not getting any event for the raising of the frame
29382 (even tried with SubstructureRedirectMask), only Expose events.
29383 These expose events will draw text normally, i.e. not
29384 highlighted. Which means we must redo the highlight here.
29385 Subsume it under ``we love X''. --gerd 2001-08-15 */
29386 /* Included in Windows version because Windows most likely does not
29387 do the right thing if any third party tool offers
29388 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
29389 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
29391 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
29392 if (f
== hlinfo
->mouse_face_mouse_frame
)
29394 int mouse_x
= hlinfo
->mouse_face_mouse_x
;
29395 int mouse_y
= hlinfo
->mouse_face_mouse_y
;
29396 clear_mouse_face (hlinfo
);
29397 note_mouse_highlight (f
, mouse_x
, mouse_y
);
29404 Determine the intersection of two rectangles R1 and R2. Return
29405 the intersection in *RESULT. Value is non-zero if RESULT is not
29409 x_intersect_rectangles (XRectangle
*r1
, XRectangle
*r2
, XRectangle
*result
)
29411 XRectangle
*left
, *right
;
29412 XRectangle
*upper
, *lower
;
29413 int intersection_p
= 0;
29415 /* Rearrange so that R1 is the left-most rectangle. */
29417 left
= r1
, right
= r2
;
29419 left
= r2
, right
= r1
;
29421 /* X0 of the intersection is right.x0, if this is inside R1,
29422 otherwise there is no intersection. */
29423 if (right
->x
<= left
->x
+ left
->width
)
29425 result
->x
= right
->x
;
29427 /* The right end of the intersection is the minimum of
29428 the right ends of left and right. */
29429 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
29432 /* Same game for Y. */
29434 upper
= r1
, lower
= r2
;
29436 upper
= r2
, lower
= r1
;
29438 /* The upper end of the intersection is lower.y0, if this is inside
29439 of upper. Otherwise, there is no intersection. */
29440 if (lower
->y
<= upper
->y
+ upper
->height
)
29442 result
->y
= lower
->y
;
29444 /* The lower end of the intersection is the minimum of the lower
29445 ends of upper and lower. */
29446 result
->height
= (min (lower
->y
+ lower
->height
,
29447 upper
->y
+ upper
->height
)
29449 intersection_p
= 1;
29453 return intersection_p
;
29456 #endif /* HAVE_WINDOW_SYSTEM */
29459 /***********************************************************************
29461 ***********************************************************************/
29464 syms_of_xdisp (void)
29466 Vwith_echo_area_save_vector
= Qnil
;
29467 staticpro (&Vwith_echo_area_save_vector
);
29469 Vmessage_stack
= Qnil
;
29470 staticpro (&Vmessage_stack
);
29472 DEFSYM (Qinhibit_redisplay
, "inhibit-redisplay");
29473 DEFSYM (Qredisplay_internal
, "redisplay_internal (C function)");
29475 message_dolog_marker1
= Fmake_marker ();
29476 staticpro (&message_dolog_marker1
);
29477 message_dolog_marker2
= Fmake_marker ();
29478 staticpro (&message_dolog_marker2
);
29479 message_dolog_marker3
= Fmake_marker ();
29480 staticpro (&message_dolog_marker3
);
29483 defsubr (&Sdump_frame_glyph_matrix
);
29484 defsubr (&Sdump_glyph_matrix
);
29485 defsubr (&Sdump_glyph_row
);
29486 defsubr (&Sdump_tool_bar_row
);
29487 defsubr (&Strace_redisplay
);
29488 defsubr (&Strace_to_stderr
);
29490 #ifdef HAVE_WINDOW_SYSTEM
29491 defsubr (&Stool_bar_height
);
29492 defsubr (&Slookup_image_map
);
29494 defsubr (&Sline_pixel_height
);
29495 defsubr (&Sformat_mode_line
);
29496 defsubr (&Sinvisible_p
);
29497 defsubr (&Scurrent_bidi_paragraph_direction
);
29498 defsubr (&Swindow_text_pixel_size
);
29499 defsubr (&Smove_point_visually
);
29501 DEFSYM (Qmenu_bar_update_hook
, "menu-bar-update-hook");
29502 DEFSYM (Qoverriding_terminal_local_map
, "overriding-terminal-local-map");
29503 DEFSYM (Qoverriding_local_map
, "overriding-local-map");
29504 DEFSYM (Qwindow_scroll_functions
, "window-scroll-functions");
29505 DEFSYM (Qwindow_text_change_functions
, "window-text-change-functions");
29506 DEFSYM (Qredisplay_end_trigger_functions
, "redisplay-end-trigger-functions");
29507 DEFSYM (Qinhibit_point_motion_hooks
, "inhibit-point-motion-hooks");
29508 DEFSYM (Qeval
, "eval");
29509 DEFSYM (QCdata
, ":data");
29510 DEFSYM (Qdisplay
, "display");
29511 DEFSYM (Qspace_width
, "space-width");
29512 DEFSYM (Qraise
, "raise");
29513 DEFSYM (Qslice
, "slice");
29514 DEFSYM (Qspace
, "space");
29515 DEFSYM (Qmargin
, "margin");
29516 DEFSYM (Qpointer
, "pointer");
29517 DEFSYM (Qleft_margin
, "left-margin");
29518 DEFSYM (Qright_margin
, "right-margin");
29519 DEFSYM (Qcenter
, "center");
29520 DEFSYM (Qline_height
, "line-height");
29521 DEFSYM (QCalign_to
, ":align-to");
29522 DEFSYM (QCrelative_width
, ":relative-width");
29523 DEFSYM (QCrelative_height
, ":relative-height");
29524 DEFSYM (QCeval
, ":eval");
29525 DEFSYM (QCpropertize
, ":propertize");
29526 DEFSYM (QCfile
, ":file");
29527 DEFSYM (Qfontified
, "fontified");
29528 DEFSYM (Qfontification_functions
, "fontification-functions");
29529 DEFSYM (Qtrailing_whitespace
, "trailing-whitespace");
29530 DEFSYM (Qescape_glyph
, "escape-glyph");
29531 DEFSYM (Qnobreak_space
, "nobreak-space");
29532 DEFSYM (Qimage
, "image");
29533 DEFSYM (Qtext
, "text");
29534 DEFSYM (Qboth
, "both");
29535 DEFSYM (Qboth_horiz
, "both-horiz");
29536 DEFSYM (Qtext_image_horiz
, "text-image-horiz");
29537 DEFSYM (QCmap
, ":map");
29538 DEFSYM (QCpointer
, ":pointer");
29539 DEFSYM (Qrect
, "rect");
29540 DEFSYM (Qcircle
, "circle");
29541 DEFSYM (Qpoly
, "poly");
29542 DEFSYM (Qmessage_truncate_lines
, "message-truncate-lines");
29543 DEFSYM (Qgrow_only
, "grow-only");
29544 DEFSYM (Qinhibit_menubar_update
, "inhibit-menubar-update");
29545 DEFSYM (Qinhibit_eval_during_redisplay
, "inhibit-eval-during-redisplay");
29546 DEFSYM (Qposition
, "position");
29547 DEFSYM (Qbuffer_position
, "buffer-position");
29548 DEFSYM (Qobject
, "object");
29549 DEFSYM (Qbar
, "bar");
29550 DEFSYM (Qhbar
, "hbar");
29551 DEFSYM (Qbox
, "box");
29552 DEFSYM (Qhollow
, "hollow");
29553 DEFSYM (Qhand
, "hand");
29554 DEFSYM (Qarrow
, "arrow");
29555 DEFSYM (Qinhibit_free_realized_faces
, "inhibit-free-realized-faces");
29557 list_of_error
= list1 (list2 (intern_c_string ("error"),
29558 intern_c_string ("void-variable")));
29559 staticpro (&list_of_error
);
29561 DEFSYM (Qlast_arrow_position
, "last-arrow-position");
29562 DEFSYM (Qlast_arrow_string
, "last-arrow-string");
29563 DEFSYM (Qoverlay_arrow_string
, "overlay-arrow-string");
29564 DEFSYM (Qoverlay_arrow_bitmap
, "overlay-arrow-bitmap");
29566 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
29567 staticpro (&echo_buffer
[0]);
29568 staticpro (&echo_buffer
[1]);
29570 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
29571 staticpro (&echo_area_buffer
[0]);
29572 staticpro (&echo_area_buffer
[1]);
29574 Vmessages_buffer_name
= build_pure_c_string ("*Messages*");
29575 staticpro (&Vmessages_buffer_name
);
29577 mode_line_proptrans_alist
= Qnil
;
29578 staticpro (&mode_line_proptrans_alist
);
29579 mode_line_string_list
= Qnil
;
29580 staticpro (&mode_line_string_list
);
29581 mode_line_string_face
= Qnil
;
29582 staticpro (&mode_line_string_face
);
29583 mode_line_string_face_prop
= Qnil
;
29584 staticpro (&mode_line_string_face_prop
);
29585 Vmode_line_unwind_vector
= Qnil
;
29586 staticpro (&Vmode_line_unwind_vector
);
29588 DEFSYM (Qmode_line_default_help_echo
, "mode-line-default-help-echo");
29590 help_echo_string
= Qnil
;
29591 staticpro (&help_echo_string
);
29592 help_echo_object
= Qnil
;
29593 staticpro (&help_echo_object
);
29594 help_echo_window
= Qnil
;
29595 staticpro (&help_echo_window
);
29596 previous_help_echo_string
= Qnil
;
29597 staticpro (&previous_help_echo_string
);
29598 help_echo_pos
= -1;
29600 DEFSYM (Qright_to_left
, "right-to-left");
29601 DEFSYM (Qleft_to_right
, "left-to-right");
29603 #ifdef HAVE_WINDOW_SYSTEM
29604 DEFVAR_BOOL ("x-stretch-cursor", x_stretch_cursor_p
,
29605 doc
: /* Non-nil means draw block cursor as wide as the glyph under it.
29606 For example, if a block cursor is over a tab, it will be drawn as
29607 wide as that tab on the display. */);
29608 x_stretch_cursor_p
= 0;
29611 DEFVAR_LISP ("show-trailing-whitespace", Vshow_trailing_whitespace
,
29612 doc
: /* Non-nil means highlight trailing whitespace.
29613 The face used for trailing whitespace is `trailing-whitespace'. */);
29614 Vshow_trailing_whitespace
= Qnil
;
29616 DEFVAR_LISP ("nobreak-char-display", Vnobreak_char_display
,
29617 doc
: /* Control highlighting of non-ASCII space and hyphen chars.
29618 If the value is t, Emacs highlights non-ASCII chars which have the
29619 same appearance as an ASCII space or hyphen, using the `nobreak-space'
29620 or `escape-glyph' face respectively.
29622 U+00A0 (no-break space), U+00AD (soft hyphen), U+2010 (hyphen), and
29623 U+2011 (non-breaking hyphen) are affected.
29625 Any other non-nil value means to display these characters as a escape
29626 glyph followed by an ordinary space or hyphen.
29628 A value of nil means no special handling of these characters. */);
29629 Vnobreak_char_display
= Qt
;
29631 DEFVAR_LISP ("void-text-area-pointer", Vvoid_text_area_pointer
,
29632 doc
: /* The pointer shape to show in void text areas.
29633 A value of nil means to show the text pointer. Other options are `arrow',
29634 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
29635 Vvoid_text_area_pointer
= Qarrow
;
29637 DEFVAR_LISP ("inhibit-redisplay", Vinhibit_redisplay
,
29638 doc
: /* Non-nil means don't actually do any redisplay.
29639 This is used for internal purposes. */);
29640 Vinhibit_redisplay
= Qnil
;
29642 DEFVAR_LISP ("global-mode-string", Vglobal_mode_string
,
29643 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
29644 Vglobal_mode_string
= Qnil
;
29646 DEFVAR_LISP ("overlay-arrow-position", Voverlay_arrow_position
,
29647 doc
: /* Marker for where to display an arrow on top of the buffer text.
29648 This must be the beginning of a line in order to work.
29649 See also `overlay-arrow-string'. */);
29650 Voverlay_arrow_position
= Qnil
;
29652 DEFVAR_LISP ("overlay-arrow-string", Voverlay_arrow_string
,
29653 doc
: /* String to display as an arrow in non-window frames.
29654 See also `overlay-arrow-position'. */);
29655 Voverlay_arrow_string
= build_pure_c_string ("=>");
29657 DEFVAR_LISP ("overlay-arrow-variable-list", Voverlay_arrow_variable_list
,
29658 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
29659 The symbols on this list are examined during redisplay to determine
29660 where to display overlay arrows. */);
29661 Voverlay_arrow_variable_list
29662 = list1 (intern_c_string ("overlay-arrow-position"));
29664 DEFVAR_INT ("scroll-step", emacs_scroll_step
,
29665 doc
: /* The number of lines to try scrolling a window by when point moves out.
29666 If that fails to bring point back on frame, point is centered instead.
29667 If this is zero, point is always centered after it moves off frame.
29668 If you want scrolling to always be a line at a time, you should set
29669 `scroll-conservatively' to a large value rather than set this to 1. */);
29671 DEFVAR_INT ("scroll-conservatively", scroll_conservatively
,
29672 doc
: /* Scroll up to this many lines, to bring point back on screen.
29673 If point moves off-screen, redisplay will scroll by up to
29674 `scroll-conservatively' lines in order to bring point just barely
29675 onto the screen again. If that cannot be done, then redisplay
29676 recenters point as usual.
29678 If the value is greater than 100, redisplay will never recenter point,
29679 but will always scroll just enough text to bring point into view, even
29680 if you move far away.
29682 A value of zero means always recenter point if it moves off screen. */);
29683 scroll_conservatively
= 0;
29685 DEFVAR_INT ("scroll-margin", scroll_margin
,
29686 doc
: /* Number of lines of margin at the top and bottom of a window.
29687 Recenter the window whenever point gets within this many lines
29688 of the top or bottom of the window. */);
29691 DEFVAR_LISP ("display-pixels-per-inch", Vdisplay_pixels_per_inch
,
29692 doc
: /* Pixels per inch value for non-window system displays.
29693 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
29694 Vdisplay_pixels_per_inch
= make_float (72.0);
29697 DEFVAR_INT ("debug-end-pos", debug_end_pos
, doc
: /* Don't ask. */);
29700 DEFVAR_LISP ("truncate-partial-width-windows",
29701 Vtruncate_partial_width_windows
,
29702 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
29703 For an integer value, truncate lines in each window narrower than the
29704 full frame width, provided the window width is less than that integer;
29705 otherwise, respect the value of `truncate-lines'.
29707 For any other non-nil value, truncate lines in all windows that do
29708 not span the full frame width.
29710 A value of nil means to respect the value of `truncate-lines'.
29712 If `word-wrap' is enabled, you might want to reduce this. */);
29713 Vtruncate_partial_width_windows
= make_number (50);
29715 DEFVAR_LISP ("line-number-display-limit", Vline_number_display_limit
,
29716 doc
: /* Maximum buffer size for which line number should be displayed.
29717 If the buffer is bigger than this, the line number does not appear
29718 in the mode line. A value of nil means no limit. */);
29719 Vline_number_display_limit
= Qnil
;
29721 DEFVAR_INT ("line-number-display-limit-width",
29722 line_number_display_limit_width
,
29723 doc
: /* Maximum line width (in characters) for line number display.
29724 If the average length of the lines near point is bigger than this, then the
29725 line number may be omitted from the mode line. */);
29726 line_number_display_limit_width
= 200;
29728 DEFVAR_BOOL ("highlight-nonselected-windows", highlight_nonselected_windows
,
29729 doc
: /* Non-nil means highlight region even in nonselected windows. */);
29730 highlight_nonselected_windows
= 0;
29732 DEFVAR_BOOL ("multiple-frames", multiple_frames
,
29733 doc
: /* Non-nil if more than one frame is visible on this display.
29734 Minibuffer-only frames don't count, but iconified frames do.
29735 This variable is not guaranteed to be accurate except while processing
29736 `frame-title-format' and `icon-title-format'. */);
29738 DEFVAR_LISP ("frame-title-format", Vframe_title_format
,
29739 doc
: /* Template for displaying the title bar of visible frames.
29740 \(Assuming the window manager supports this feature.)
29742 This variable has the same structure as `mode-line-format', except that
29743 the %c and %l constructs are ignored. It is used only on frames for
29744 which no explicit name has been set \(see `modify-frame-parameters'). */);
29746 DEFVAR_LISP ("icon-title-format", Vicon_title_format
,
29747 doc
: /* Template for displaying the title bar of an iconified frame.
29748 \(Assuming the window manager supports this feature.)
29749 This variable has the same structure as `mode-line-format' (which see),
29750 and is used only on frames for which no explicit name has been set
29751 \(see `modify-frame-parameters'). */);
29753 = Vframe_title_format
29754 = listn (CONSTYPE_PURE
, 3,
29755 intern_c_string ("multiple-frames"),
29756 build_pure_c_string ("%b"),
29757 listn (CONSTYPE_PURE
, 4,
29758 empty_unibyte_string
,
29759 intern_c_string ("invocation-name"),
29760 build_pure_c_string ("@"),
29761 intern_c_string ("system-name")));
29763 DEFVAR_LISP ("message-log-max", Vmessage_log_max
,
29764 doc
: /* Maximum number of lines to keep in the message log buffer.
29765 If nil, disable message logging. If t, log messages but don't truncate
29766 the buffer when it becomes large. */);
29767 Vmessage_log_max
= make_number (1000);
29769 DEFVAR_LISP ("window-size-change-functions", Vwindow_size_change_functions
,
29770 doc
: /* Functions called before redisplay, if window sizes have changed.
29771 The value should be a list of functions that take one argument.
29772 Just before redisplay, for each frame, if any of its windows have changed
29773 size since the last redisplay, or have been split or deleted,
29774 all the functions in the list are called, with the frame as argument. */);
29775 Vwindow_size_change_functions
= Qnil
;
29777 DEFVAR_LISP ("window-scroll-functions", Vwindow_scroll_functions
,
29778 doc
: /* List of functions to call before redisplaying a window with scrolling.
29779 Each function is called with two arguments, the window and its new
29780 display-start position. Note that these functions are also called by
29781 `set-window-buffer'. Also note that the value of `window-end' is not
29782 valid when these functions are called.
29784 Warning: Do not use this feature to alter the way the window
29785 is scrolled. It is not designed for that, and such use probably won't
29787 Vwindow_scroll_functions
= Qnil
;
29789 DEFVAR_LISP ("window-text-change-functions",
29790 Vwindow_text_change_functions
,
29791 doc
: /* Functions to call in redisplay when text in the window might change. */);
29792 Vwindow_text_change_functions
= Qnil
;
29794 DEFVAR_LISP ("redisplay-end-trigger-functions", Vredisplay_end_trigger_functions
,
29795 doc
: /* Functions called when redisplay of a window reaches the end trigger.
29796 Each function is called with two arguments, the window and the end trigger value.
29797 See `set-window-redisplay-end-trigger'. */);
29798 Vredisplay_end_trigger_functions
= Qnil
;
29800 DEFVAR_LISP ("mouse-autoselect-window", Vmouse_autoselect_window
,
29801 doc
: /* Non-nil means autoselect window with mouse pointer.
29802 If nil, do not autoselect windows.
29803 A positive number means delay autoselection by that many seconds: a
29804 window is autoselected only after the mouse has remained in that
29805 window for the duration of the delay.
29806 A negative number has a similar effect, but causes windows to be
29807 autoselected only after the mouse has stopped moving. \(Because of
29808 the way Emacs compares mouse events, you will occasionally wait twice
29809 that time before the window gets selected.\)
29810 Any other value means to autoselect window instantaneously when the
29811 mouse pointer enters it.
29813 Autoselection selects the minibuffer only if it is active, and never
29814 unselects the minibuffer if it is active.
29816 When customizing this variable make sure that the actual value of
29817 `focus-follows-mouse' matches the behavior of your window manager. */);
29818 Vmouse_autoselect_window
= Qnil
;
29820 DEFVAR_LISP ("auto-resize-tool-bars", Vauto_resize_tool_bars
,
29821 doc
: /* Non-nil means automatically resize tool-bars.
29822 This dynamically changes the tool-bar's height to the minimum height
29823 that is needed to make all tool-bar items visible.
29824 If value is `grow-only', the tool-bar's height is only increased
29825 automatically; to decrease the tool-bar height, use \\[recenter]. */);
29826 Vauto_resize_tool_bars
= Qt
;
29828 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", auto_raise_tool_bar_buttons_p
,
29829 doc
: /* Non-nil means raise tool-bar buttons when the mouse moves over them. */);
29830 auto_raise_tool_bar_buttons_p
= 1;
29832 DEFVAR_BOOL ("make-cursor-line-fully-visible", make_cursor_line_fully_visible_p
,
29833 doc
: /* Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
29834 make_cursor_line_fully_visible_p
= 1;
29836 DEFVAR_LISP ("tool-bar-border", Vtool_bar_border
,
29837 doc
: /* Border below tool-bar in pixels.
29838 If an integer, use it as the height of the border.
29839 If it is one of `internal-border-width' or `border-width', use the
29840 value of the corresponding frame parameter.
29841 Otherwise, no border is added below the tool-bar. */);
29842 Vtool_bar_border
= Qinternal_border_width
;
29844 DEFVAR_LISP ("tool-bar-button-margin", Vtool_bar_button_margin
,
29845 doc
: /* Margin around tool-bar buttons in pixels.
29846 If an integer, use that for both horizontal and vertical margins.
29847 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
29848 HORZ specifying the horizontal margin, and VERT specifying the
29849 vertical margin. */);
29850 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
29852 DEFVAR_INT ("tool-bar-button-relief", tool_bar_button_relief
,
29853 doc
: /* Relief thickness of tool-bar buttons. */);
29854 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
29856 DEFVAR_LISP ("tool-bar-style", Vtool_bar_style
,
29857 doc
: /* Tool bar style to use.
29859 image - show images only
29860 text - show text only
29861 both - show both, text below image
29862 both-horiz - show text to the right of the image
29863 text-image-horiz - show text to the left of the image
29864 any other - use system default or image if no system default.
29866 This variable only affects the GTK+ toolkit version of Emacs. */);
29867 Vtool_bar_style
= Qnil
;
29869 DEFVAR_INT ("tool-bar-max-label-size", tool_bar_max_label_size
,
29870 doc
: /* Maximum number of characters a label can have to be shown.
29871 The tool bar style must also show labels for this to have any effect, see
29872 `tool-bar-style'. */);
29873 tool_bar_max_label_size
= DEFAULT_TOOL_BAR_LABEL_SIZE
;
29875 DEFVAR_LISP ("fontification-functions", Vfontification_functions
,
29876 doc
: /* List of functions to call to fontify regions of text.
29877 Each function is called with one argument POS. Functions must
29878 fontify a region starting at POS in the current buffer, and give
29879 fontified regions the property `fontified'. */);
29880 Vfontification_functions
= Qnil
;
29881 Fmake_variable_buffer_local (Qfontification_functions
);
29883 DEFVAR_BOOL ("unibyte-display-via-language-environment",
29884 unibyte_display_via_language_environment
,
29885 doc
: /* Non-nil means display unibyte text according to language environment.
29886 Specifically, this means that raw bytes in the range 160-255 decimal
29887 are displayed by converting them to the equivalent multibyte characters
29888 according to the current language environment. As a result, they are
29889 displayed according to the current fontset.
29891 Note that this variable affects only how these bytes are displayed,
29892 but does not change the fact they are interpreted as raw bytes. */);
29893 unibyte_display_via_language_environment
= 0;
29895 DEFVAR_LISP ("max-mini-window-height", Vmax_mini_window_height
,
29896 doc
: /* Maximum height for resizing mini-windows (the minibuffer and the echo area).
29897 If a float, it specifies a fraction of the mini-window frame's height.
29898 If an integer, it specifies a number of lines. */);
29899 Vmax_mini_window_height
= make_float (0.25);
29901 DEFVAR_LISP ("resize-mini-windows", Vresize_mini_windows
,
29902 doc
: /* How to resize mini-windows (the minibuffer and the echo area).
29903 A value of nil means don't automatically resize mini-windows.
29904 A value of t means resize them to fit the text displayed in them.
29905 A value of `grow-only', the default, means let mini-windows grow only;
29906 they return to their normal size when the minibuffer is closed, or the
29907 echo area becomes empty. */);
29908 Vresize_mini_windows
= Qgrow_only
;
29910 DEFVAR_LISP ("blink-cursor-alist", Vblink_cursor_alist
,
29911 doc
: /* Alist specifying how to blink the cursor off.
29912 Each element has the form (ON-STATE . OFF-STATE). Whenever the
29913 `cursor-type' frame-parameter or variable equals ON-STATE,
29914 comparing using `equal', Emacs uses OFF-STATE to specify
29915 how to blink it off. ON-STATE and OFF-STATE are values for
29916 the `cursor-type' frame parameter.
29918 If a frame's ON-STATE has no entry in this list,
29919 the frame's other specifications determine how to blink the cursor off. */);
29920 Vblink_cursor_alist
= Qnil
;
29922 DEFVAR_BOOL ("auto-hscroll-mode", automatic_hscrolling_p
,
29923 doc
: /* Allow or disallow automatic horizontal scrolling of windows.
29924 If non-nil, windows are automatically scrolled horizontally to make
29925 point visible. */);
29926 automatic_hscrolling_p
= 1;
29927 DEFSYM (Qauto_hscroll_mode
, "auto-hscroll-mode");
29929 DEFVAR_INT ("hscroll-margin", hscroll_margin
,
29930 doc
: /* How many columns away from the window edge point is allowed to get
29931 before automatic hscrolling will horizontally scroll the window. */);
29932 hscroll_margin
= 5;
29934 DEFVAR_LISP ("hscroll-step", Vhscroll_step
,
29935 doc
: /* How many columns to scroll the window when point gets too close to the edge.
29936 When point is less than `hscroll-margin' columns from the window
29937 edge, automatic hscrolling will scroll the window by the amount of columns
29938 determined by this variable. If its value is a positive integer, scroll that
29939 many columns. If it's a positive floating-point number, it specifies the
29940 fraction of the window's width to scroll. If it's nil or zero, point will be
29941 centered horizontally after the scroll. Any other value, including negative
29942 numbers, are treated as if the value were zero.
29944 Automatic hscrolling always moves point outside the scroll margin, so if
29945 point was more than scroll step columns inside the margin, the window will
29946 scroll more than the value given by the scroll step.
29948 Note that the lower bound for automatic hscrolling specified by `scroll-left'
29949 and `scroll-right' overrides this variable's effect. */);
29950 Vhscroll_step
= make_number (0);
29952 DEFVAR_BOOL ("message-truncate-lines", message_truncate_lines
,
29953 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
29954 Bind this around calls to `message' to let it take effect. */);
29955 message_truncate_lines
= 0;
29957 DEFVAR_LISP ("menu-bar-update-hook", Vmenu_bar_update_hook
,
29958 doc
: /* Normal hook run to update the menu bar definitions.
29959 Redisplay runs this hook before it redisplays the menu bar.
29960 This is used to update submenus such as Buffers,
29961 whose contents depend on various data. */);
29962 Vmenu_bar_update_hook
= Qnil
;
29964 DEFVAR_LISP ("menu-updating-frame", Vmenu_updating_frame
,
29965 doc
: /* Frame for which we are updating a menu.
29966 The enable predicate for a menu binding should check this variable. */);
29967 Vmenu_updating_frame
= Qnil
;
29969 DEFVAR_BOOL ("inhibit-menubar-update", inhibit_menubar_update
,
29970 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
29971 inhibit_menubar_update
= 0;
29973 DEFVAR_LISP ("wrap-prefix", Vwrap_prefix
,
29974 doc
: /* Prefix prepended to all continuation lines at display time.
29975 The value may be a string, an image, or a stretch-glyph; it is
29976 interpreted in the same way as the value of a `display' text property.
29978 This variable is overridden by any `wrap-prefix' text or overlay
29981 To add a prefix to non-continuation lines, use `line-prefix'. */);
29982 Vwrap_prefix
= Qnil
;
29983 DEFSYM (Qwrap_prefix
, "wrap-prefix");
29984 Fmake_variable_buffer_local (Qwrap_prefix
);
29986 DEFVAR_LISP ("line-prefix", Vline_prefix
,
29987 doc
: /* Prefix prepended to all non-continuation lines at display time.
29988 The value may be a string, an image, or a stretch-glyph; it is
29989 interpreted in the same way as the value of a `display' text property.
29991 This variable is overridden by any `line-prefix' text or overlay
29994 To add a prefix to continuation lines, use `wrap-prefix'. */);
29995 Vline_prefix
= Qnil
;
29996 DEFSYM (Qline_prefix
, "line-prefix");
29997 Fmake_variable_buffer_local (Qline_prefix
);
29999 DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay
,
30000 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
30001 inhibit_eval_during_redisplay
= 0;
30003 DEFVAR_BOOL ("inhibit-free-realized-faces", inhibit_free_realized_faces
,
30004 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
30005 inhibit_free_realized_faces
= 0;
30008 DEFVAR_BOOL ("inhibit-try-window-id", inhibit_try_window_id
,
30009 doc
: /* Inhibit try_window_id display optimization. */);
30010 inhibit_try_window_id
= 0;
30012 DEFVAR_BOOL ("inhibit-try-window-reusing", inhibit_try_window_reusing
,
30013 doc
: /* Inhibit try_window_reusing display optimization. */);
30014 inhibit_try_window_reusing
= 0;
30016 DEFVAR_BOOL ("inhibit-try-cursor-movement", inhibit_try_cursor_movement
,
30017 doc
: /* Inhibit try_cursor_movement display optimization. */);
30018 inhibit_try_cursor_movement
= 0;
30019 #endif /* GLYPH_DEBUG */
30021 DEFVAR_INT ("overline-margin", overline_margin
,
30022 doc
: /* Space between overline and text, in pixels.
30023 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
30024 margin to the character height. */);
30025 overline_margin
= 2;
30027 DEFVAR_INT ("underline-minimum-offset",
30028 underline_minimum_offset
,
30029 doc
: /* Minimum distance between baseline and underline.
30030 This can improve legibility of underlined text at small font sizes,
30031 particularly when using variable `x-use-underline-position-properties'
30032 with fonts that specify an UNDERLINE_POSITION relatively close to the
30033 baseline. The default value is 1. */);
30034 underline_minimum_offset
= 1;
30036 DEFVAR_BOOL ("display-hourglass", display_hourglass_p
,
30037 doc
: /* Non-nil means show an hourglass pointer, when Emacs is busy.
30038 This feature only works when on a window system that can change
30039 cursor shapes. */);
30040 display_hourglass_p
= 1;
30042 DEFVAR_LISP ("hourglass-delay", Vhourglass_delay
,
30043 doc
: /* Seconds to wait before displaying an hourglass pointer when Emacs is busy. */);
30044 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
30046 #ifdef HAVE_WINDOW_SYSTEM
30047 hourglass_atimer
= NULL
;
30048 hourglass_shown_p
= 0;
30049 #endif /* HAVE_WINDOW_SYSTEM */
30051 DEFSYM (Qglyphless_char
, "glyphless-char");
30052 DEFSYM (Qhex_code
, "hex-code");
30053 DEFSYM (Qempty_box
, "empty-box");
30054 DEFSYM (Qthin_space
, "thin-space");
30055 DEFSYM (Qzero_width
, "zero-width");
30057 DEFVAR_LISP ("pre-redisplay-function", Vpre_redisplay_function
,
30058 doc
: /* Function run just before redisplay.
30059 It is called with one argument, which is the set of windows that are to
30060 be redisplayed. This set can be nil (meaning, only the selected window),
30061 or t (meaning all windows). */);
30062 Vpre_redisplay_function
= intern ("ignore");
30064 DEFSYM (Qglyphless_char_display
, "glyphless-char-display");
30065 Fput (Qglyphless_char_display
, Qchar_table_extra_slots
, make_number (1));
30067 DEFVAR_LISP ("glyphless-char-display", Vglyphless_char_display
,
30068 doc
: /* Char-table defining glyphless characters.
30069 Each element, if non-nil, should be one of the following:
30070 an ASCII acronym string: display this string in a box
30071 `hex-code': display the hexadecimal code of a character in a box
30072 `empty-box': display as an empty box
30073 `thin-space': display as 1-pixel width space
30074 `zero-width': don't display
30075 An element may also be a cons cell (GRAPHICAL . TEXT), which specifies the
30076 display method for graphical terminals and text terminals respectively.
30077 GRAPHICAL and TEXT should each have one of the values listed above.
30079 The char-table has one extra slot to control the display of a character for
30080 which no font is found. This slot only takes effect on graphical terminals.
30081 Its value should be an ASCII acronym string, `hex-code', `empty-box', or
30082 `thin-space'. The default is `empty-box'.
30084 If a character has a non-nil entry in an active display table, the
30085 display table takes effect; in this case, Emacs does not consult
30086 `glyphless-char-display' at all. */);
30087 Vglyphless_char_display
= Fmake_char_table (Qglyphless_char_display
, Qnil
);
30088 Fset_char_table_extra_slot (Vglyphless_char_display
, make_number (0),
30091 DEFVAR_LISP ("debug-on-message", Vdebug_on_message
,
30092 doc
: /* If non-nil, debug if a message matching this regexp is displayed. */);
30093 Vdebug_on_message
= Qnil
;
30095 DEFVAR_LISP ("redisplay--all-windows-cause", Vredisplay__all_windows_cause
,
30097 Vredisplay__all_windows_cause
30098 = Fmake_vector (make_number (100), make_number (0));
30100 DEFVAR_LISP ("redisplay--mode-lines-cause", Vredisplay__mode_lines_cause
,
30102 Vredisplay__mode_lines_cause
30103 = Fmake_vector (make_number (100), make_number (0));
30107 /* Initialize this module when Emacs starts. */
30112 CHARPOS (this_line_start_pos
) = 0;
30114 if (!noninteractive
)
30116 struct window
*m
= XWINDOW (minibuf_window
);
30117 Lisp_Object frame
= m
->frame
;
30118 struct frame
*f
= XFRAME (frame
);
30119 Lisp_Object root
= FRAME_ROOT_WINDOW (f
);
30120 struct window
*r
= XWINDOW (root
);
30123 echo_area_window
= minibuf_window
;
30125 r
->top_line
= FRAME_TOP_MARGIN (f
);
30126 r
->pixel_top
= r
->top_line
* FRAME_LINE_HEIGHT (f
);
30127 r
->total_cols
= FRAME_COLS (f
);
30128 r
->pixel_width
= r
->total_cols
* FRAME_COLUMN_WIDTH (f
);
30129 r
->total_lines
= FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
);
30130 r
->pixel_height
= r
->total_lines
* FRAME_LINE_HEIGHT (f
);
30132 m
->top_line
= FRAME_LINES (f
) - 1;
30133 m
->pixel_top
= m
->top_line
* FRAME_LINE_HEIGHT (f
);
30134 m
->total_cols
= FRAME_COLS (f
);
30135 m
->pixel_width
= m
->total_cols
* FRAME_COLUMN_WIDTH (f
);
30136 m
->total_lines
= 1;
30137 m
->pixel_height
= m
->total_lines
* FRAME_LINE_HEIGHT (f
);
30139 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
30140 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
30141 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
30143 /* The default ellipsis glyphs `...'. */
30144 for (i
= 0; i
< 3; ++i
)
30145 default_invis_vector
[i
] = make_number ('.');
30149 /* Allocate the buffer for frame titles.
30150 Also used for `format-mode-line'. */
30152 mode_line_noprop_buf
= xmalloc (size
);
30153 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
30154 mode_line_noprop_ptr
= mode_line_noprop_buf
;
30155 mode_line_target
= MODE_LINE_DISPLAY
;
30158 help_echo_showing_p
= 0;
30161 #ifdef HAVE_WINDOW_SYSTEM
30163 /* Platform-independent portion of hourglass implementation. */
30165 /* Cancel a currently active hourglass timer, and start a new one. */
30167 start_hourglass (void)
30169 struct timespec delay
;
30171 cancel_hourglass ();
30173 if (INTEGERP (Vhourglass_delay
)
30174 && XINT (Vhourglass_delay
) > 0)
30175 delay
= make_timespec (min (XINT (Vhourglass_delay
),
30176 TYPE_MAXIMUM (time_t)),
30178 else if (FLOATP (Vhourglass_delay
)
30179 && XFLOAT_DATA (Vhourglass_delay
) > 0)
30180 delay
= dtotimespec (XFLOAT_DATA (Vhourglass_delay
));
30182 delay
= make_timespec (DEFAULT_HOURGLASS_DELAY
, 0);
30186 extern void w32_note_current_window (void);
30187 w32_note_current_window ();
30189 #endif /* HAVE_NTGUI */
30191 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
30192 show_hourglass
, NULL
);
30196 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
30199 cancel_hourglass (void)
30201 if (hourglass_atimer
)
30203 cancel_atimer (hourglass_atimer
);
30204 hourglass_atimer
= NULL
;
30207 if (hourglass_shown_p
)
30211 #endif /* HAVE_WINDOW_SYSTEM */