1 /* Display generation from window structure and buffer text.
3 Copyright (C) 1985-1988, 1993-1995, 1997-2012 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"
302 #ifdef HAVE_X_WINDOWS
319 #ifndef FRAME_X_OUTPUT
320 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
323 #define INFINITY 10000000
325 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
326 Lisp_Object Qwindow_scroll_functions
;
327 static Lisp_Object Qwindow_text_change_functions
;
328 static Lisp_Object Qredisplay_end_trigger_functions
;
329 Lisp_Object Qinhibit_point_motion_hooks
;
330 static Lisp_Object QCeval
, QCpropertize
;
331 Lisp_Object QCfile
, QCdata
;
332 static Lisp_Object Qfontified
;
333 static Lisp_Object Qgrow_only
;
334 static Lisp_Object Qinhibit_eval_during_redisplay
;
335 static Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
336 static Lisp_Object Qright_to_left
, Qleft_to_right
;
339 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
341 /* Pointer shapes. */
342 static Lisp_Object Qarrow
, Qhand
;
345 /* Holds the list (error). */
346 static Lisp_Object list_of_error
;
348 static Lisp_Object Qfontification_functions
;
350 static Lisp_Object Qwrap_prefix
;
351 static Lisp_Object Qline_prefix
;
352 static Lisp_Object Qredisplay_internal
;
354 /* Non-nil means don't actually do any redisplay. */
356 Lisp_Object Qinhibit_redisplay
;
358 /* Names of text properties relevant for redisplay. */
360 Lisp_Object Qdisplay
;
362 Lisp_Object Qspace
, QCalign_to
;
363 static Lisp_Object QCrelative_width
, QCrelative_height
;
364 Lisp_Object Qleft_margin
, Qright_margin
;
365 static Lisp_Object Qspace_width
, Qraise
;
366 static Lisp_Object Qslice
;
368 static Lisp_Object Qmargin
, Qpointer
;
369 static Lisp_Object Qline_height
;
371 /* These setters are used only in this file, so they can be private. */
373 wset_base_line_number (struct window
*w
, Lisp_Object val
)
375 w
->base_line_number
= val
;
378 wset_base_line_pos (struct window
*w
, Lisp_Object val
)
380 w
->base_line_pos
= val
;
383 wset_column_number_displayed (struct window
*w
, Lisp_Object val
)
385 w
->column_number_displayed
= val
;
388 wset_region_showing (struct window
*w
, Lisp_Object val
)
390 w
->region_showing
= val
;
393 #ifdef HAVE_WINDOW_SYSTEM
395 /* Test if overflow newline into fringe. Called with iterator IT
396 at or past right window margin, and with IT->current_x set. */
398 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(IT) \
399 (!NILP (Voverflow_newline_into_fringe) \
400 && FRAME_WINDOW_P ((IT)->f) \
401 && ((IT)->bidi_it.paragraph_dir == R2L \
402 ? (WINDOW_LEFT_FRINGE_WIDTH ((IT)->w) > 0) \
403 : (WINDOW_RIGHT_FRINGE_WIDTH ((IT)->w) > 0)) \
404 && (IT)->current_x == (IT)->last_visible_x \
405 && (IT)->line_wrap != WORD_WRAP)
407 #else /* !HAVE_WINDOW_SYSTEM */
408 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) 0
409 #endif /* HAVE_WINDOW_SYSTEM */
411 /* Test if the display element loaded in IT, or the underlying buffer
412 or string character, is a space or a TAB character. This is used
413 to determine where word wrapping can occur. */
415 #define IT_DISPLAYING_WHITESPACE(it) \
416 ((it->what == IT_CHARACTER && (it->c == ' ' || it->c == '\t')) \
417 || ((STRINGP (it->string) \
418 && (SREF (it->string, IT_STRING_BYTEPOS (*it)) == ' ' \
419 || SREF (it->string, IT_STRING_BYTEPOS (*it)) == '\t')) \
421 && (it->s[IT_BYTEPOS (*it)] == ' ' \
422 || it->s[IT_BYTEPOS (*it)] == '\t')) \
423 || (IT_BYTEPOS (*it) < ZV_BYTE \
424 && (*BYTE_POS_ADDR (IT_BYTEPOS (*it)) == ' ' \
425 || *BYTE_POS_ADDR (IT_BYTEPOS (*it)) == '\t')))) \
427 /* Name of the face used to highlight trailing whitespace. */
429 static Lisp_Object Qtrailing_whitespace
;
431 /* Name and number of the face used to highlight escape glyphs. */
433 static Lisp_Object Qescape_glyph
;
435 /* Name and number of the face used to highlight non-breaking spaces. */
437 static Lisp_Object Qnobreak_space
;
439 /* The symbol `image' which is the car of the lists used to represent
440 images in Lisp. Also a tool bar style. */
444 /* The image map types. */
446 static Lisp_Object QCpointer
;
447 static Lisp_Object Qrect
, Qcircle
, Qpoly
;
449 /* Tool bar styles */
450 Lisp_Object Qboth
, Qboth_horiz
, Qtext_image_horiz
;
452 /* Non-zero means print newline to stdout before next mini-buffer
455 int noninteractive_need_newline
;
457 /* Non-zero means print newline to message log before next message. */
459 static int message_log_need_newline
;
461 /* Three markers that message_dolog uses.
462 It could allocate them itself, but that causes trouble
463 in handling memory-full errors. */
464 static Lisp_Object message_dolog_marker1
;
465 static Lisp_Object message_dolog_marker2
;
466 static Lisp_Object message_dolog_marker3
;
468 /* The buffer position of the first character appearing entirely or
469 partially on the line of the selected window which contains the
470 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
471 redisplay optimization in redisplay_internal. */
473 static struct text_pos this_line_start_pos
;
475 /* Number of characters past the end of the line above, including the
476 terminating newline. */
478 static struct text_pos this_line_end_pos
;
480 /* The vertical positions and the height of this line. */
482 static int this_line_vpos
;
483 static int this_line_y
;
484 static int this_line_pixel_height
;
486 /* X position at which this display line starts. Usually zero;
487 negative if first character is partially visible. */
489 static int this_line_start_x
;
491 /* The smallest character position seen by move_it_* functions as they
492 move across display lines. Used to set MATRIX_ROW_START_CHARPOS of
493 hscrolled lines, see display_line. */
495 static struct text_pos this_line_min_pos
;
497 /* Buffer that this_line_.* variables are referring to. */
499 static struct buffer
*this_line_buffer
;
502 /* Values of those variables at last redisplay are stored as
503 properties on `overlay-arrow-position' symbol. However, if
504 Voverlay_arrow_position is a marker, last-arrow-position is its
505 numerical position. */
507 static Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
509 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
510 properties on a symbol in overlay-arrow-variable-list. */
512 static Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
514 Lisp_Object Qmenu_bar_update_hook
;
516 /* Nonzero if an overlay arrow has been displayed in this window. */
518 static int overlay_arrow_seen
;
520 /* Number of windows showing the buffer of the selected
521 window (or another buffer with the same base buffer). */
525 /* Vector containing glyphs for an ellipsis `...'. */
527 static Lisp_Object default_invis_vector
[3];
529 /* This is the window where the echo area message was displayed. It
530 is always a mini-buffer window, but it may not be the same window
531 currently active as a mini-buffer. */
533 Lisp_Object echo_area_window
;
535 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
536 pushes the current message and the value of
537 message_enable_multibyte on the stack, the function restore_message
538 pops the stack and displays MESSAGE again. */
540 static Lisp_Object Vmessage_stack
;
542 /* Nonzero means multibyte characters were enabled when the echo area
543 message was specified. */
545 static int message_enable_multibyte
;
547 /* Nonzero if we should redraw the mode lines on the next redisplay. */
549 int update_mode_lines
;
551 /* Nonzero if window sizes or contents have changed since last
552 redisplay that finished. */
554 int windows_or_buffers_changed
;
556 /* Nonzero means a frame's cursor type has been changed. */
558 int cursor_type_changed
;
560 /* Nonzero after display_mode_line if %l was used and it displayed a
563 static int line_number_displayed
;
565 /* The name of the *Messages* buffer, a string. */
567 static Lisp_Object Vmessages_buffer_name
;
569 /* Current, index 0, and last displayed echo area message. Either
570 buffers from echo_buffers, or nil to indicate no message. */
572 Lisp_Object echo_area_buffer
[2];
574 /* The buffers referenced from echo_area_buffer. */
576 static Lisp_Object echo_buffer
[2];
578 /* A vector saved used in with_area_buffer to reduce consing. */
580 static Lisp_Object Vwith_echo_area_save_vector
;
582 /* Non-zero means display_echo_area should display the last echo area
583 message again. Set by redisplay_preserve_echo_area. */
585 static int display_last_displayed_message_p
;
587 /* Nonzero if echo area is being used by print; zero if being used by
590 static int message_buf_print
;
592 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
594 static Lisp_Object Qinhibit_menubar_update
;
595 static Lisp_Object Qmessage_truncate_lines
;
597 /* Set to 1 in clear_message to make redisplay_internal aware
598 of an emptied echo area. */
600 static int message_cleared_p
;
602 /* A scratch glyph row with contents used for generating truncation
603 glyphs. Also used in direct_output_for_insert. */
605 #define MAX_SCRATCH_GLYPHS 100
606 static struct glyph_row scratch_glyph_row
;
607 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
609 /* Ascent and height of the last line processed by move_it_to. */
611 static int last_max_ascent
, last_height
;
613 /* Non-zero if there's a help-echo in the echo area. */
615 int help_echo_showing_p
;
617 /* If >= 0, computed, exact values of mode-line and header-line height
618 to use in the macros CURRENT_MODE_LINE_HEIGHT and
619 CURRENT_HEADER_LINE_HEIGHT. */
621 int current_mode_line_height
, current_header_line_height
;
623 /* The maximum distance to look ahead for text properties. Values
624 that are too small let us call compute_char_face and similar
625 functions too often which is expensive. Values that are too large
626 let us call compute_char_face and alike too often because we
627 might not be interested in text properties that far away. */
629 #define TEXT_PROP_DISTANCE_LIMIT 100
631 /* SAVE_IT and RESTORE_IT are called when we save a snapshot of the
632 iterator state and later restore it. This is needed because the
633 bidi iterator on bidi.c keeps a stacked cache of its states, which
634 is really a singleton. When we use scratch iterator objects to
635 move around the buffer, we can cause the bidi cache to be pushed or
636 popped, and therefore we need to restore the cache state when we
637 return to the original iterator. */
638 #define SAVE_IT(ITCOPY,ITORIG,CACHE) \
641 bidi_unshelve_cache (CACHE, 1); \
643 CACHE = bidi_shelve_cache (); \
646 #define RESTORE_IT(pITORIG,pITCOPY,CACHE) \
648 if (pITORIG != pITCOPY) \
649 *(pITORIG) = *(pITCOPY); \
650 bidi_unshelve_cache (CACHE, 0); \
656 /* Non-zero means print traces of redisplay if compiled with
657 GLYPH_DEBUG defined. */
659 int trace_redisplay_p
;
661 #endif /* GLYPH_DEBUG */
663 #ifdef DEBUG_TRACE_MOVE
664 /* Non-zero means trace with TRACE_MOVE to stderr. */
667 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
669 #define TRACE_MOVE(x) (void) 0
672 static Lisp_Object Qauto_hscroll_mode
;
674 /* Buffer being redisplayed -- for redisplay_window_error. */
676 static struct buffer
*displayed_buffer
;
678 /* Value returned from text property handlers (see below). */
683 HANDLED_RECOMPUTE_PROPS
,
684 HANDLED_OVERLAY_STRING_CONSUMED
,
688 /* A description of text properties that redisplay is interested
693 /* The name of the property. */
696 /* A unique index for the property. */
699 /* A handler function called to set up iterator IT from the property
700 at IT's current position. Value is used to steer handle_stop. */
701 enum prop_handled (*handler
) (struct it
*it
);
704 static enum prop_handled
handle_face_prop (struct it
*);
705 static enum prop_handled
handle_invisible_prop (struct it
*);
706 static enum prop_handled
handle_display_prop (struct it
*);
707 static enum prop_handled
handle_composition_prop (struct it
*);
708 static enum prop_handled
handle_overlay_change (struct it
*);
709 static enum prop_handled
handle_fontified_prop (struct it
*);
711 /* Properties handled by iterators. */
713 static struct props it_props
[] =
715 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
716 /* Handle `face' before `display' because some sub-properties of
717 `display' need to know the face. */
718 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
719 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
720 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
721 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
725 /* Value is the position described by X. If X is a marker, value is
726 the marker_position of X. Otherwise, value is X. */
728 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
730 /* Enumeration returned by some move_it_.* functions internally. */
734 /* Not used. Undefined value. */
737 /* Move ended at the requested buffer position or ZV. */
738 MOVE_POS_MATCH_OR_ZV
,
740 /* Move ended at the requested X pixel position. */
743 /* Move within a line ended at the end of a line that must be
747 /* Move within a line ended at the end of a line that would
748 be displayed truncated. */
751 /* Move within a line ended at a line end. */
755 /* This counter is used to clear the face cache every once in a while
756 in redisplay_internal. It is incremented for each redisplay.
757 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
760 #define CLEAR_FACE_CACHE_COUNT 500
761 static int clear_face_cache_count
;
763 /* Similarly for the image cache. */
765 #ifdef HAVE_WINDOW_SYSTEM
766 #define CLEAR_IMAGE_CACHE_COUNT 101
767 static int clear_image_cache_count
;
769 /* Null glyph slice */
770 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
773 /* True while redisplay_internal is in progress. */
777 static Lisp_Object Qinhibit_free_realized_faces
;
778 static Lisp_Object Qmode_line_default_help_echo
;
780 /* If a string, XTread_socket generates an event to display that string.
781 (The display is done in read_char.) */
783 Lisp_Object help_echo_string
;
784 Lisp_Object help_echo_window
;
785 Lisp_Object help_echo_object
;
786 ptrdiff_t help_echo_pos
;
788 /* Temporary variable for XTread_socket. */
790 Lisp_Object previous_help_echo_string
;
792 /* Platform-independent portion of hourglass implementation. */
794 /* Non-zero means an hourglass cursor is currently shown. */
795 int hourglass_shown_p
;
797 /* If non-null, an asynchronous timer that, when it expires, displays
798 an hourglass cursor on all frames. */
799 struct atimer
*hourglass_atimer
;
801 /* Name of the face used to display glyphless characters. */
802 Lisp_Object Qglyphless_char
;
804 /* Symbol for the purpose of Vglyphless_char_display. */
805 static Lisp_Object Qglyphless_char_display
;
807 /* Method symbols for Vglyphless_char_display. */
808 static Lisp_Object Qhex_code
, Qempty_box
, Qthin_space
, Qzero_width
;
810 /* Default pixel width of `thin-space' display method. */
811 #define THIN_SPACE_WIDTH 1
813 /* Default number of seconds to wait before displaying an hourglass
815 #define DEFAULT_HOURGLASS_DELAY 1
818 /* Function prototypes. */
820 static void setup_for_ellipsis (struct it
*, int);
821 static void set_iterator_to_next (struct it
*, int);
822 static void mark_window_display_accurate_1 (struct window
*, int);
823 static int single_display_spec_string_p (Lisp_Object
, Lisp_Object
);
824 static int display_prop_string_p (Lisp_Object
, Lisp_Object
);
825 static int cursor_row_p (struct glyph_row
*);
826 static int redisplay_mode_lines (Lisp_Object
, int);
827 static char *decode_mode_spec_coding (Lisp_Object
, char *, int);
829 static Lisp_Object
get_it_property (struct it
*it
, Lisp_Object prop
);
831 static void handle_line_prefix (struct it
*);
833 static void pint2str (char *, int, ptrdiff_t);
834 static void pint2hrstr (char *, int, ptrdiff_t);
835 static struct text_pos
run_window_scroll_functions (Lisp_Object
,
837 static void reconsider_clip_changes (struct window
*, struct buffer
*);
838 static int text_outside_line_unchanged_p (struct window
*,
839 ptrdiff_t, ptrdiff_t);
840 static void store_mode_line_noprop_char (char);
841 static int store_mode_line_noprop (const char *, int, int);
842 static void handle_stop (struct it
*);
843 static void handle_stop_backwards (struct it
*, ptrdiff_t);
844 static void vmessage (const char *, va_list) ATTRIBUTE_FORMAT_PRINTF (1, 0);
845 static void ensure_echo_area_buffers (void);
846 static Lisp_Object
unwind_with_echo_area_buffer (Lisp_Object
);
847 static Lisp_Object
with_echo_area_buffer_unwind_data (struct window
*);
848 static int with_echo_area_buffer (struct window
*, int,
849 int (*) (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t),
850 ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t);
851 static void clear_garbaged_frames (void);
852 static int current_message_1 (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t);
853 static void pop_message (void);
854 static int truncate_message_1 (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t);
855 static void set_message (const char *, Lisp_Object
, ptrdiff_t, int);
856 static int set_message_1 (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t);
857 static int display_echo_area (struct window
*);
858 static int display_echo_area_1 (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t);
859 static int resize_mini_window_1 (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t);
860 static Lisp_Object
unwind_redisplay (Lisp_Object
);
861 static int string_char_and_length (const unsigned char *, int *);
862 static struct text_pos
display_prop_end (struct it
*, Lisp_Object
,
864 static int compute_window_start_on_continuation_line (struct window
*);
865 static void insert_left_trunc_glyphs (struct it
*);
866 static struct glyph_row
*get_overlay_arrow_glyph_row (struct window
*,
868 static void extend_face_to_end_of_line (struct it
*);
869 static int append_space_for_newline (struct it
*, int);
870 static int cursor_row_fully_visible_p (struct window
*, int, int);
871 static int try_scrolling (Lisp_Object
, int, ptrdiff_t, ptrdiff_t, int, int);
872 static int try_cursor_movement (Lisp_Object
, struct text_pos
, int *);
873 static int trailing_whitespace_p (ptrdiff_t);
874 static intmax_t message_log_check_duplicate (ptrdiff_t, ptrdiff_t);
875 static void push_it (struct it
*, struct text_pos
*);
876 static void iterate_out_of_display_property (struct it
*);
877 static void pop_it (struct it
*);
878 static void sync_frame_with_window_matrix_rows (struct window
*);
879 static void select_frame_for_redisplay (Lisp_Object
);
880 static void redisplay_internal (void);
881 static int echo_area_display (int);
882 static void redisplay_windows (Lisp_Object
);
883 static void redisplay_window (Lisp_Object
, int);
884 static Lisp_Object
redisplay_window_error (Lisp_Object
);
885 static Lisp_Object
redisplay_window_0 (Lisp_Object
);
886 static Lisp_Object
redisplay_window_1 (Lisp_Object
);
887 static int set_cursor_from_row (struct window
*, struct glyph_row
*,
888 struct glyph_matrix
*, ptrdiff_t, ptrdiff_t,
890 static int update_menu_bar (struct frame
*, int, int);
891 static int try_window_reusing_current_matrix (struct window
*);
892 static int try_window_id (struct window
*);
893 static int display_line (struct it
*);
894 static int display_mode_lines (struct window
*);
895 static int display_mode_line (struct window
*, enum face_id
, Lisp_Object
);
896 static int display_mode_element (struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int);
897 static int store_mode_line_string (const char *, Lisp_Object
, int, int, int, Lisp_Object
);
898 static const char *decode_mode_spec (struct window
*, int, int, Lisp_Object
*);
899 static void display_menu_bar (struct window
*);
900 static ptrdiff_t display_count_lines (ptrdiff_t, ptrdiff_t, ptrdiff_t,
902 static int display_string (const char *, Lisp_Object
, Lisp_Object
,
903 ptrdiff_t, ptrdiff_t, struct it
*, int, int, int, int);
904 static void compute_line_metrics (struct it
*);
905 static void run_redisplay_end_trigger_hook (struct it
*);
906 static int get_overlay_strings (struct it
*, ptrdiff_t);
907 static int get_overlay_strings_1 (struct it
*, ptrdiff_t, int);
908 static void next_overlay_string (struct it
*);
909 static void reseat (struct it
*, struct text_pos
, int);
910 static void reseat_1 (struct it
*, struct text_pos
, int);
911 static void back_to_previous_visible_line_start (struct it
*);
912 void reseat_at_previous_visible_line_start (struct it
*);
913 static void reseat_at_next_visible_line_start (struct it
*, int);
914 static int next_element_from_ellipsis (struct it
*);
915 static int next_element_from_display_vector (struct it
*);
916 static int next_element_from_string (struct it
*);
917 static int next_element_from_c_string (struct it
*);
918 static int next_element_from_buffer (struct it
*);
919 static int next_element_from_composition (struct it
*);
920 static int next_element_from_image (struct it
*);
922 static int next_element_from_xwidget(struct it
*);
924 static int next_element_from_stretch (struct it
*);
925 static void load_overlay_strings (struct it
*, ptrdiff_t);
926 static int init_from_display_pos (struct it
*, struct window
*,
927 struct display_pos
*);
928 static void reseat_to_string (struct it
*, const char *,
929 Lisp_Object
, ptrdiff_t, ptrdiff_t, int, int);
930 static int get_next_display_element (struct it
*);
931 static enum move_it_result
932 move_it_in_display_line_to (struct it
*, ptrdiff_t, int,
933 enum move_operation_enum
);
934 void move_it_vertically_backward (struct it
*, int);
935 static void get_visually_first_element (struct it
*);
936 static void init_to_row_start (struct it
*, struct window
*,
938 static int init_to_row_end (struct it
*, struct window
*,
940 static void back_to_previous_line_start (struct it
*);
941 static int forward_to_next_line_start (struct it
*, int *, struct bidi_it
*);
942 static struct text_pos
string_pos_nchars_ahead (struct text_pos
,
943 Lisp_Object
, ptrdiff_t);
944 static struct text_pos
string_pos (ptrdiff_t, Lisp_Object
);
945 static struct text_pos
c_string_pos (ptrdiff_t, const char *, int);
946 static ptrdiff_t number_of_chars (const char *, int);
947 static void compute_stop_pos (struct it
*);
948 static void compute_string_pos (struct text_pos
*, struct text_pos
,
950 static int face_before_or_after_it_pos (struct it
*, int);
951 static ptrdiff_t next_overlay_change (ptrdiff_t);
952 static int handle_display_spec (struct it
*, Lisp_Object
, Lisp_Object
,
953 Lisp_Object
, struct text_pos
*, ptrdiff_t, int);
954 static int handle_single_display_spec (struct it
*, Lisp_Object
,
955 Lisp_Object
, Lisp_Object
,
956 struct text_pos
*, ptrdiff_t, int, int);
957 static int underlying_face_id (struct it
*);
958 static int in_ellipses_for_invisible_text_p (struct display_pos
*,
961 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
962 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
964 #ifdef HAVE_WINDOW_SYSTEM
966 static void x_consider_frame_title (Lisp_Object
);
967 static int tool_bar_lines_needed (struct frame
*, int *);
968 static void update_tool_bar (struct frame
*, int);
969 static void build_desired_tool_bar_string (struct frame
*f
);
970 static int redisplay_tool_bar (struct frame
*);
971 static void display_tool_bar_line (struct it
*, int);
972 static void notice_overwritten_cursor (struct window
*,
975 static void append_stretch_glyph (struct it
*, Lisp_Object
,
979 #endif /* HAVE_WINDOW_SYSTEM */
981 static void produce_special_glyphs (struct it
*, enum display_element_type
);
982 static void show_mouse_face (Mouse_HLInfo
*, enum draw_glyphs_face
);
983 static int coords_in_mouse_face_p (struct window
*, int, int);
987 /***********************************************************************
988 Window display dimensions
989 ***********************************************************************/
991 /* Return the bottom boundary y-position for text lines in window W.
992 This is the first y position at which a line cannot start.
993 It is relative to the top of the window.
995 This is the height of W minus the height of a mode line, if any. */
998 window_text_bottom_y (struct window
*w
)
1000 int height
= WINDOW_TOTAL_HEIGHT (w
);
1002 if (WINDOW_WANTS_MODELINE_P (w
))
1003 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
1007 /* Return the pixel width of display area AREA of window W. AREA < 0
1008 means return the total width of W, not including fringes to
1009 the left and right of the window. */
1012 window_box_width (struct window
*w
, int area
)
1014 int cols
= XFASTINT (w
->total_cols
);
1017 if (!w
->pseudo_window_p
)
1019 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
1021 if (area
== TEXT_AREA
)
1023 if (INTEGERP (w
->left_margin_cols
))
1024 cols
-= XFASTINT (w
->left_margin_cols
);
1025 if (INTEGERP (w
->right_margin_cols
))
1026 cols
-= XFASTINT (w
->right_margin_cols
);
1027 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
1029 else if (area
== LEFT_MARGIN_AREA
)
1031 cols
= (INTEGERP (w
->left_margin_cols
)
1032 ? XFASTINT (w
->left_margin_cols
) : 0);
1035 else if (area
== RIGHT_MARGIN_AREA
)
1037 cols
= (INTEGERP (w
->right_margin_cols
)
1038 ? XFASTINT (w
->right_margin_cols
) : 0);
1043 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1047 /* Return the pixel height of the display area of window W, not
1048 including mode lines of W, if any. */
1051 window_box_height (struct window
*w
)
1053 struct frame
*f
= XFRAME (w
->frame
);
1054 int height
= WINDOW_TOTAL_HEIGHT (w
);
1056 eassert (height
>= 0);
1058 /* Note: the code below that determines the mode-line/header-line
1059 height is essentially the same as that contained in the macro
1060 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1061 the appropriate glyph row has its `mode_line_p' flag set,
1062 and if it doesn't, uses estimate_mode_line_height instead. */
1064 if (WINDOW_WANTS_MODELINE_P (w
))
1066 struct glyph_row
*ml_row
1067 = (w
->current_matrix
&& w
->current_matrix
->rows
1068 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1070 if (ml_row
&& ml_row
->mode_line_p
)
1071 height
-= ml_row
->height
;
1073 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1076 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1078 struct glyph_row
*hl_row
1079 = (w
->current_matrix
&& w
->current_matrix
->rows
1080 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1082 if (hl_row
&& hl_row
->mode_line_p
)
1083 height
-= hl_row
->height
;
1085 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1088 /* With a very small font and a mode-line that's taller than
1089 default, we might end up with a negative height. */
1090 return max (0, height
);
1093 /* Return the window-relative coordinate of the left edge of display
1094 area AREA of window W. AREA < 0 means return the left edge of the
1095 whole window, to the right of the left fringe of W. */
1098 window_box_left_offset (struct window
*w
, int area
)
1102 if (w
->pseudo_window_p
)
1105 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1107 if (area
== TEXT_AREA
)
1108 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1109 + window_box_width (w
, LEFT_MARGIN_AREA
));
1110 else if (area
== RIGHT_MARGIN_AREA
)
1111 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1112 + window_box_width (w
, LEFT_MARGIN_AREA
)
1113 + window_box_width (w
, TEXT_AREA
)
1114 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1116 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1117 else if (area
== LEFT_MARGIN_AREA
1118 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1119 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1125 /* Return the window-relative coordinate of the right edge of display
1126 area AREA of window W. AREA < 0 means return the right edge of the
1127 whole window, to the left of the right fringe of W. */
1130 window_box_right_offset (struct window
*w
, int area
)
1132 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1135 /* Return the frame-relative coordinate of the left edge of display
1136 area AREA of window W. AREA < 0 means return the left edge of the
1137 whole window, to the right of the left fringe of W. */
1140 window_box_left (struct window
*w
, int area
)
1142 struct frame
*f
= XFRAME (w
->frame
);
1145 if (w
->pseudo_window_p
)
1146 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1148 x
= (WINDOW_LEFT_EDGE_X (w
)
1149 + window_box_left_offset (w
, area
));
1155 /* Return the frame-relative coordinate of the right edge of display
1156 area AREA of window W. AREA < 0 means return the right edge of the
1157 whole window, to the left of the right fringe of W. */
1160 window_box_right (struct window
*w
, int area
)
1162 return window_box_left (w
, area
) + window_box_width (w
, area
);
1165 /* Get the bounding box of the display area AREA of window W, without
1166 mode lines, in frame-relative coordinates. AREA < 0 means the
1167 whole window, not including the left and right fringes of
1168 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1169 coordinates of the upper-left corner of the box. Return in
1170 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1173 window_box (struct window
*w
, int area
, int *box_x
, int *box_y
,
1174 int *box_width
, int *box_height
)
1177 *box_width
= window_box_width (w
, area
);
1179 *box_height
= window_box_height (w
);
1181 *box_x
= window_box_left (w
, area
);
1184 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1185 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1186 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1191 /* Get the bounding box of the display area AREA of window W, without
1192 mode lines. AREA < 0 means the whole window, not including the
1193 left and right fringe of the window. Return in *TOP_LEFT_X
1194 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1195 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1196 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1200 window_box_edges (struct window
*w
, int area
, int *top_left_x
, int *top_left_y
,
1201 int *bottom_right_x
, int *bottom_right_y
)
1203 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1205 *bottom_right_x
+= *top_left_x
;
1206 *bottom_right_y
+= *top_left_y
;
1211 /***********************************************************************
1213 ***********************************************************************/
1215 /* Return the bottom y-position of the line the iterator IT is in.
1216 This can modify IT's settings. */
1219 line_bottom_y (struct it
*it
)
1221 int line_height
= it
->max_ascent
+ it
->max_descent
;
1222 int line_top_y
= it
->current_y
;
1224 if (line_height
== 0)
1227 line_height
= last_height
;
1228 else if (IT_CHARPOS (*it
) < ZV
)
1230 move_it_by_lines (it
, 1);
1231 line_height
= (it
->max_ascent
|| it
->max_descent
1232 ? it
->max_ascent
+ it
->max_descent
1237 struct glyph_row
*row
= it
->glyph_row
;
1239 /* Use the default character height. */
1240 it
->glyph_row
= NULL
;
1241 it
->what
= IT_CHARACTER
;
1244 PRODUCE_GLYPHS (it
);
1245 line_height
= it
->ascent
+ it
->descent
;
1246 it
->glyph_row
= row
;
1250 return line_top_y
+ line_height
;
1253 /* Subroutine of pos_visible_p below. Extracts a display string, if
1254 any, from the display spec given as its argument. */
1256 string_from_display_spec (Lisp_Object spec
)
1260 while (CONSP (spec
))
1262 if (STRINGP (XCAR (spec
)))
1267 else if (VECTORP (spec
))
1271 for (i
= 0; i
< ASIZE (spec
); i
++)
1273 if (STRINGP (AREF (spec
, i
)))
1274 return AREF (spec
, i
);
1283 /* Limit insanely large values of W->hscroll on frame F to the largest
1284 value that will still prevent first_visible_x and last_visible_x of
1285 'struct it' from overflowing an int. */
1287 window_hscroll_limited (struct window
*w
, struct frame
*f
)
1289 ptrdiff_t window_hscroll
= w
->hscroll
;
1290 int window_text_width
= window_box_width (w
, TEXT_AREA
);
1291 int colwidth
= FRAME_COLUMN_WIDTH (f
);
1293 if (window_hscroll
> (INT_MAX
- window_text_width
) / colwidth
- 1)
1294 window_hscroll
= (INT_MAX
- window_text_width
) / colwidth
- 1;
1296 return window_hscroll
;
1299 /* Return 1 if position CHARPOS is visible in window W.
1300 CHARPOS < 0 means return info about WINDOW_END position.
1301 If visible, set *X and *Y to pixel coordinates of top left corner.
1302 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1303 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1306 pos_visible_p (struct window
*w
, ptrdiff_t charpos
, int *x
, int *y
,
1307 int *rtop
, int *rbot
, int *rowh
, int *vpos
)
1310 void *itdata
= bidi_shelve_cache ();
1311 struct text_pos top
;
1313 struct buffer
*old_buffer
= NULL
;
1315 if (FRAME_INITIAL_P (XFRAME (WINDOW_FRAME (w
))))
1318 if (XBUFFER (w
->buffer
) != current_buffer
)
1320 old_buffer
= current_buffer
;
1321 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1324 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1325 /* Scrolling a minibuffer window via scroll bar when the echo area
1326 shows long text sometimes resets the minibuffer contents behind
1328 if (CHARPOS (top
) > ZV
)
1329 SET_TEXT_POS (top
, BEGV
, BEGV_BYTE
);
1331 /* Compute exact mode line heights. */
1332 if (WINDOW_WANTS_MODELINE_P (w
))
1333 current_mode_line_height
1334 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1335 BVAR (current_buffer
, mode_line_format
));
1337 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1338 current_header_line_height
1339 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1340 BVAR (current_buffer
, header_line_format
));
1342 start_display (&it
, w
, top
);
1343 move_it_to (&it
, charpos
, -1, it
.last_visible_y
-1, -1,
1344 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1347 && (((!it
.bidi_p
|| it
.bidi_it
.scan_dir
== 1)
1348 && IT_CHARPOS (it
) >= charpos
)
1349 /* When scanning backwards under bidi iteration, move_it_to
1350 stops at or _before_ CHARPOS, because it stops at or to
1351 the _right_ of the character at CHARPOS. */
1352 || (it
.bidi_p
&& it
.bidi_it
.scan_dir
== -1
1353 && IT_CHARPOS (it
) <= charpos
)))
1355 /* We have reached CHARPOS, or passed it. How the call to
1356 move_it_to can overshoot: (i) If CHARPOS is on invisible text
1357 or covered by a display property, move_it_to stops at the end
1358 of the invisible text, to the right of CHARPOS. (ii) If
1359 CHARPOS is in a display vector, move_it_to stops on its last
1361 int top_x
= it
.current_x
;
1362 int top_y
= it
.current_y
;
1363 /* Calling line_bottom_y may change it.method, it.position, etc. */
1364 enum it_method it_method
= it
.method
;
1365 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1366 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1368 if (top_y
< window_top_y
)
1369 visible_p
= bottom_y
> window_top_y
;
1370 else if (top_y
< it
.last_visible_y
)
1372 if (bottom_y
>= it
.last_visible_y
1373 && it
.bidi_p
&& it
.bidi_it
.scan_dir
== -1
1374 && IT_CHARPOS (it
) < charpos
)
1376 /* When the last line of the window is scanned backwards
1377 under bidi iteration, we could be duped into thinking
1378 that we have passed CHARPOS, when in fact move_it_to
1379 simply stopped short of CHARPOS because it reached
1380 last_visible_y. To see if that's what happened, we call
1381 move_it_to again with a slightly larger vertical limit,
1382 and see if it actually moved vertically; if it did, we
1383 didn't really reach CHARPOS, which is beyond window end. */
1384 struct it save_it
= it
;
1385 /* Why 10? because we don't know how many canonical lines
1386 will the height of the next line(s) be. So we guess. */
1387 int ten_more_lines
=
1388 10 * FRAME_LINE_HEIGHT (XFRAME (WINDOW_FRAME (w
)));
1390 move_it_to (&it
, charpos
, -1, bottom_y
+ ten_more_lines
, -1,
1391 MOVE_TO_POS
| MOVE_TO_Y
);
1392 if (it
.current_y
> top_y
)
1399 if (it_method
== GET_FROM_DISPLAY_VECTOR
)
1401 /* We stopped on the last glyph of a display vector.
1402 Try and recompute. Hack alert! */
1403 if (charpos
< 2 || top
.charpos
>= charpos
)
1404 top_x
= it
.glyph_row
->x
;
1408 start_display (&it2
, w
, top
);
1409 move_it_to (&it2
, charpos
- 1, -1, -1, -1, MOVE_TO_POS
);
1410 get_next_display_element (&it2
);
1411 PRODUCE_GLYPHS (&it2
);
1412 if (ITERATOR_AT_END_OF_LINE_P (&it2
)
1413 || it2
.current_x
> it2
.last_visible_x
)
1414 top_x
= it
.glyph_row
->x
;
1417 top_x
= it2
.current_x
;
1418 top_y
= it2
.current_y
;
1422 else if (IT_CHARPOS (it
) != charpos
)
1424 Lisp_Object cpos
= make_number (charpos
);
1425 Lisp_Object spec
= Fget_char_property (cpos
, Qdisplay
, Qnil
);
1426 Lisp_Object string
= string_from_display_spec (spec
);
1427 int newline_in_string
= 0;
1429 if (STRINGP (string
))
1431 const char *s
= SSDATA (string
);
1432 const char *e
= s
+ SBYTES (string
);
1437 newline_in_string
= 1;
1442 /* The tricky code below is needed because there's a
1443 discrepancy between move_it_to and how we set cursor
1444 when the display line ends in a newline from a
1445 display string. move_it_to will stop _after_ such
1446 display strings, whereas set_cursor_from_row
1447 conspires with cursor_row_p to place the cursor on
1448 the first glyph produced from the display string. */
1450 /* We have overshoot PT because it is covered by a
1451 display property whose value is a string. If the
1452 string includes embedded newlines, we are also in the
1453 wrong display line. Backtrack to the correct line,
1454 where the display string begins. */
1455 if (newline_in_string
)
1457 Lisp_Object startpos
, endpos
;
1458 EMACS_INT start
, end
;
1462 /* Find the first and the last buffer positions
1463 covered by the display string. */
1465 Fnext_single_char_property_change (cpos
, Qdisplay
,
1468 Fprevious_single_char_property_change (endpos
, Qdisplay
,
1470 start
= XFASTINT (startpos
);
1471 end
= XFASTINT (endpos
);
1472 /* Move to the last buffer position before the
1473 display property. */
1474 start_display (&it3
, w
, top
);
1475 move_it_to (&it3
, start
- 1, -1, -1, -1, MOVE_TO_POS
);
1476 /* Move forward one more line if the position before
1477 the display string is a newline or if it is the
1478 rightmost character on a line that is
1479 continued or word-wrapped. */
1480 if (it3
.method
== GET_FROM_BUFFER
1482 move_it_by_lines (&it3
, 1);
1483 else if (move_it_in_display_line_to (&it3
, -1,
1487 == MOVE_LINE_CONTINUED
)
1489 move_it_by_lines (&it3
, 1);
1490 /* When we are under word-wrap, the #$@%!
1491 move_it_by_lines moves 2 lines, so we need to
1493 if (it3
.line_wrap
== WORD_WRAP
)
1494 move_it_by_lines (&it3
, -1);
1497 /* Record the vertical coordinate of the display
1498 line where we wound up. */
1499 top_y
= it3
.current_y
;
1502 /* When characters are reordered for display,
1503 the character displayed to the left of the
1504 display string could be _after_ the display
1505 property in the logical order. Use the
1506 smallest vertical position of these two. */
1507 start_display (&it3
, w
, top
);
1508 move_it_to (&it3
, end
+ 1, -1, -1, -1, MOVE_TO_POS
);
1509 if (it3
.current_y
< top_y
)
1510 top_y
= it3
.current_y
;
1512 /* Move from the top of the window to the beginning
1513 of the display line where the display string
1515 start_display (&it3
, w
, top
);
1516 move_it_to (&it3
, -1, 0, top_y
, -1, MOVE_TO_X
| MOVE_TO_Y
);
1517 /* If it3_moved stays zero after the 'while' loop
1518 below, that means we already were at a newline
1519 before the loop (e.g., the display string begins
1520 with a newline), so we don't need to (and cannot)
1521 inspect the glyphs of it3.glyph_row, because
1522 PRODUCE_GLYPHS will not produce anything for a
1523 newline, and thus it3.glyph_row stays at its
1524 stale content it got at top of the window. */
1526 /* Finally, advance the iterator until we hit the
1527 first display element whose character position is
1528 CHARPOS, or until the first newline from the
1529 display string, which signals the end of the
1531 while (get_next_display_element (&it3
))
1533 PRODUCE_GLYPHS (&it3
);
1534 if (IT_CHARPOS (it3
) == charpos
1535 || ITERATOR_AT_END_OF_LINE_P (&it3
))
1538 set_iterator_to_next (&it3
, 0);
1540 top_x
= it3
.current_x
- it3
.pixel_width
;
1541 /* Normally, we would exit the above loop because we
1542 found the display element whose character
1543 position is CHARPOS. For the contingency that we
1544 didn't, and stopped at the first newline from the
1545 display string, move back over the glyphs
1546 produced from the string, until we find the
1547 rightmost glyph not from the string. */
1549 && IT_CHARPOS (it3
) != charpos
&& EQ (it3
.object
, string
))
1551 struct glyph
*g
= it3
.glyph_row
->glyphs
[TEXT_AREA
]
1552 + it3
.glyph_row
->used
[TEXT_AREA
];
1554 while (EQ ((g
- 1)->object
, string
))
1557 top_x
-= g
->pixel_width
;
1559 eassert (g
< it3
.glyph_row
->glyphs
[TEXT_AREA
]
1560 + it3
.glyph_row
->used
[TEXT_AREA
]);
1566 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1567 *rtop
= max (0, window_top_y
- top_y
);
1568 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1569 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1570 - max (top_y
, window_top_y
)));
1576 /* We were asked to provide info about WINDOW_END. */
1578 void *it2data
= NULL
;
1580 SAVE_IT (it2
, it
, it2data
);
1581 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1582 move_it_by_lines (&it
, 1);
1583 if (charpos
< IT_CHARPOS (it
)
1584 || (it
.what
== IT_EOB
&& charpos
== IT_CHARPOS (it
)))
1587 RESTORE_IT (&it2
, &it2
, it2data
);
1588 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1590 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1591 *rtop
= max (0, -it2
.current_y
);
1592 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1593 - it
.last_visible_y
));
1594 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1596 - max (it2
.current_y
,
1597 WINDOW_HEADER_LINE_HEIGHT (w
))));
1601 bidi_unshelve_cache (it2data
, 1);
1603 bidi_unshelve_cache (itdata
, 0);
1606 set_buffer_internal_1 (old_buffer
);
1608 current_header_line_height
= current_mode_line_height
= -1;
1610 if (visible_p
&& w
->hscroll
> 0)
1612 window_hscroll_limited (w
, WINDOW_XFRAME (w
))
1613 * WINDOW_FRAME_COLUMN_WIDTH (w
);
1616 /* Debugging code. */
1618 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1619 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1621 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1628 /* Return the next character from STR. Return in *LEN the length of
1629 the character. This is like STRING_CHAR_AND_LENGTH but never
1630 returns an invalid character. If we find one, we return a `?', but
1631 with the length of the invalid character. */
1634 string_char_and_length (const unsigned char *str
, int *len
)
1638 c
= STRING_CHAR_AND_LENGTH (str
, *len
);
1639 if (!CHAR_VALID_P (c
))
1640 /* We may not change the length here because other places in Emacs
1641 don't use this function, i.e. they silently accept invalid
1650 /* Given a position POS containing a valid character and byte position
1651 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1653 static struct text_pos
1654 string_pos_nchars_ahead (struct text_pos pos
, Lisp_Object string
, ptrdiff_t nchars
)
1656 eassert (STRINGP (string
) && nchars
>= 0);
1658 if (STRING_MULTIBYTE (string
))
1660 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1665 string_char_and_length (p
, &len
);
1668 BYTEPOS (pos
) += len
;
1672 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1678 /* Value is the text position, i.e. character and byte position,
1679 for character position CHARPOS in STRING. */
1681 static struct text_pos
1682 string_pos (ptrdiff_t charpos
, Lisp_Object string
)
1684 struct text_pos pos
;
1685 eassert (STRINGP (string
));
1686 eassert (charpos
>= 0);
1687 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1692 /* Value is a text position, i.e. character and byte position, for
1693 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1694 means recognize multibyte characters. */
1696 static struct text_pos
1697 c_string_pos (ptrdiff_t charpos
, const char *s
, int multibyte_p
)
1699 struct text_pos pos
;
1701 eassert (s
!= NULL
);
1702 eassert (charpos
>= 0);
1708 SET_TEXT_POS (pos
, 0, 0);
1711 string_char_and_length ((const unsigned char *) s
, &len
);
1714 BYTEPOS (pos
) += len
;
1718 SET_TEXT_POS (pos
, charpos
, charpos
);
1724 /* Value is the number of characters in C string S. MULTIBYTE_P
1725 non-zero means recognize multibyte characters. */
1728 number_of_chars (const char *s
, int multibyte_p
)
1734 ptrdiff_t rest
= strlen (s
);
1736 const unsigned char *p
= (const unsigned char *) s
;
1738 for (nchars
= 0; rest
> 0; ++nchars
)
1740 string_char_and_length (p
, &len
);
1741 rest
-= len
, p
+= len
;
1745 nchars
= strlen (s
);
1751 /* Compute byte position NEWPOS->bytepos corresponding to
1752 NEWPOS->charpos. POS is a known position in string STRING.
1753 NEWPOS->charpos must be >= POS.charpos. */
1756 compute_string_pos (struct text_pos
*newpos
, struct text_pos pos
, Lisp_Object string
)
1758 eassert (STRINGP (string
));
1759 eassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1761 if (STRING_MULTIBYTE (string
))
1762 *newpos
= string_pos_nchars_ahead (pos
, string
,
1763 CHARPOS (*newpos
) - CHARPOS (pos
));
1765 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1769 Return an estimation of the pixel height of mode or header lines on
1770 frame F. FACE_ID specifies what line's height to estimate. */
1773 estimate_mode_line_height (struct frame
*f
, enum face_id face_id
)
1775 #ifdef HAVE_WINDOW_SYSTEM
1776 if (FRAME_WINDOW_P (f
))
1778 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1780 /* This function is called so early when Emacs starts that the face
1781 cache and mode line face are not yet initialized. */
1782 if (FRAME_FACE_CACHE (f
))
1784 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1788 height
= FONT_HEIGHT (face
->font
);
1789 if (face
->box_line_width
> 0)
1790 height
+= 2 * face
->box_line_width
;
1801 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1802 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1803 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1804 not force the value into range. */
1807 pixel_to_glyph_coords (FRAME_PTR f
, register int pix_x
, register int pix_y
,
1808 int *x
, int *y
, NativeRectangle
*bounds
, int noclip
)
1811 #ifdef HAVE_WINDOW_SYSTEM
1812 if (FRAME_WINDOW_P (f
))
1814 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1815 even for negative values. */
1817 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1819 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1821 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1822 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1825 STORE_NATIVE_RECT (*bounds
,
1826 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1827 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1828 FRAME_COLUMN_WIDTH (f
) - 1,
1829 FRAME_LINE_HEIGHT (f
) - 1);
1835 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1836 pix_x
= FRAME_TOTAL_COLS (f
);
1840 else if (pix_y
> FRAME_LINES (f
))
1841 pix_y
= FRAME_LINES (f
);
1851 /* Find the glyph under window-relative coordinates X/Y in window W.
1852 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1853 strings. Return in *HPOS and *VPOS the row and column number of
1854 the glyph found. Return in *AREA the glyph area containing X.
1855 Value is a pointer to the glyph found or null if X/Y is not on
1856 text, or we can't tell because W's current matrix is not up to
1861 x_y_to_hpos_vpos (struct window
*w
, int x
, int y
, int *hpos
, int *vpos
,
1862 int *dx
, int *dy
, int *area
)
1864 struct glyph
*glyph
, *end
;
1865 struct glyph_row
*row
= NULL
;
1868 /* Find row containing Y. Give up if some row is not enabled. */
1869 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1871 row
= MATRIX_ROW (w
->current_matrix
, i
);
1872 if (!row
->enabled_p
)
1874 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1881 /* Give up if Y is not in the window. */
1882 if (i
== w
->current_matrix
->nrows
)
1885 /* Get the glyph area containing X. */
1886 if (w
->pseudo_window_p
)
1893 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1895 *area
= LEFT_MARGIN_AREA
;
1896 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1898 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1901 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1905 *area
= RIGHT_MARGIN_AREA
;
1906 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1910 /* Find glyph containing X. */
1911 glyph
= row
->glyphs
[*area
];
1912 end
= glyph
+ row
->used
[*area
];
1914 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1916 x
-= glyph
->pixel_width
;
1926 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1929 *hpos
= glyph
- row
->glyphs
[*area
];
1933 /* Convert frame-relative x/y to coordinates relative to window W.
1934 Takes pseudo-windows into account. */
1937 frame_to_window_pixel_xy (struct window
*w
, int *x
, int *y
)
1939 if (w
->pseudo_window_p
)
1941 /* A pseudo-window is always full-width, and starts at the
1942 left edge of the frame, plus a frame border. */
1943 struct frame
*f
= XFRAME (w
->frame
);
1944 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1945 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1949 *x
-= WINDOW_LEFT_EDGE_X (w
);
1950 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1954 #ifdef HAVE_WINDOW_SYSTEM
1957 Return in RECTS[] at most N clipping rectangles for glyph string S.
1958 Return the number of stored rectangles. */
1961 get_glyph_string_clip_rects (struct glyph_string
*s
, NativeRectangle
*rects
, int n
)
1968 if (s
->row
->full_width_p
)
1970 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1971 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1972 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1974 /* Unless displaying a mode or menu bar line, which are always
1975 fully visible, clip to the visible part of the row. */
1976 if (s
->w
->pseudo_window_p
)
1977 r
.height
= s
->row
->visible_height
;
1979 r
.height
= s
->height
;
1983 /* This is a text line that may be partially visible. */
1984 r
.x
= window_box_left (s
->w
, s
->area
);
1985 r
.width
= window_box_width (s
->w
, s
->area
);
1986 r
.height
= s
->row
->visible_height
;
1990 if (r
.x
< s
->clip_head
->x
)
1992 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1993 r
.width
-= s
->clip_head
->x
- r
.x
;
1996 r
.x
= s
->clip_head
->x
;
1999 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
2001 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
2002 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
2007 /* If S draws overlapping rows, it's sufficient to use the top and
2008 bottom of the window for clipping because this glyph string
2009 intentionally draws over other lines. */
2010 if (s
->for_overlaps
)
2012 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
2013 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
2015 /* Alas, the above simple strategy does not work for the
2016 environments with anti-aliased text: if the same text is
2017 drawn onto the same place multiple times, it gets thicker.
2018 If the overlap we are processing is for the erased cursor, we
2019 take the intersection with the rectangle of the cursor. */
2020 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
2022 XRectangle rc
, r_save
= r
;
2024 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
2025 rc
.y
= s
->w
->phys_cursor
.y
;
2026 rc
.width
= s
->w
->phys_cursor_width
;
2027 rc
.height
= s
->w
->phys_cursor_height
;
2029 x_intersect_rectangles (&r_save
, &rc
, &r
);
2034 /* Don't use S->y for clipping because it doesn't take partially
2035 visible lines into account. For example, it can be negative for
2036 partially visible lines at the top of a window. */
2037 if (!s
->row
->full_width_p
2038 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
2039 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
2041 r
.y
= max (0, s
->row
->y
);
2044 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
2046 /* If drawing the cursor, don't let glyph draw outside its
2047 advertised boundaries. Cleartype does this under some circumstances. */
2048 if (s
->hl
== DRAW_CURSOR
)
2050 struct glyph
*glyph
= s
->first_glyph
;
2055 r
.width
-= s
->x
- r
.x
;
2058 r
.width
= min (r
.width
, glyph
->pixel_width
);
2060 /* If r.y is below window bottom, ensure that we still see a cursor. */
2061 height
= min (glyph
->ascent
+ glyph
->descent
,
2062 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
2063 max_y
= window_text_bottom_y (s
->w
) - height
;
2064 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
2065 if (s
->ybase
- glyph
->ascent
> max_y
)
2072 /* Don't draw cursor glyph taller than our actual glyph. */
2073 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
2074 if (height
< r
.height
)
2076 max_y
= r
.y
+ r
.height
;
2077 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
2078 r
.height
= min (max_y
- r
.y
, height
);
2085 XRectangle r_save
= r
;
2087 if (! x_intersect_rectangles (&r_save
, s
->row
->clip
, &r
))
2091 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
2092 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
2094 #ifdef CONVERT_FROM_XRECT
2095 CONVERT_FROM_XRECT (r
, *rects
);
2103 /* If we are processing overlapping and allowed to return
2104 multiple clipping rectangles, we exclude the row of the glyph
2105 string from the clipping rectangle. This is to avoid drawing
2106 the same text on the environment with anti-aliasing. */
2107 #ifdef CONVERT_FROM_XRECT
2110 XRectangle
*rs
= rects
;
2112 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
2114 if (s
->for_overlaps
& OVERLAPS_PRED
)
2117 if (r
.y
+ r
.height
> row_y
)
2120 rs
[i
].height
= row_y
- r
.y
;
2126 if (s
->for_overlaps
& OVERLAPS_SUCC
)
2129 if (r
.y
< row_y
+ s
->row
->visible_height
)
2131 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
2133 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
2134 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
2143 #ifdef CONVERT_FROM_XRECT
2144 for (i
= 0; i
< n
; i
++)
2145 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
2152 Return in *NR the clipping rectangle for glyph string S. */
2155 get_glyph_string_clip_rect (struct glyph_string
*s
, NativeRectangle
*nr
)
2157 get_glyph_string_clip_rects (s
, nr
, 1);
2162 Return the position and height of the phys cursor in window W.
2163 Set w->phys_cursor_width to width of phys cursor.
2167 get_phys_cursor_geometry (struct window
*w
, struct glyph_row
*row
,
2168 struct glyph
*glyph
, int *xp
, int *yp
, int *heightp
)
2170 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2171 int x
, y
, wd
, h
, h0
, y0
;
2173 /* Compute the width of the rectangle to draw. If on a stretch
2174 glyph, and `x-stretch-block-cursor' is nil, don't draw a
2175 rectangle as wide as the glyph, but use a canonical character
2177 wd
= glyph
->pixel_width
- 1;
2178 #if defined (HAVE_NTGUI) || defined (HAVE_NS)
2182 x
= w
->phys_cursor
.x
;
2189 if (glyph
->type
== STRETCH_GLYPH
2190 && !x_stretch_cursor_p
)
2191 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2192 w
->phys_cursor_width
= wd
;
2194 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
2196 /* If y is below window bottom, ensure that we still see a cursor. */
2197 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2199 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
2200 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
2202 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2205 h
= max (h
- (y0
- y
) + 1, h0
);
2210 y0
= window_text_bottom_y (w
) - h0
;
2218 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
2219 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2224 * Remember which glyph the mouse is over.
2228 remember_mouse_glyph (struct frame
*f
, int gx
, int gy
, NativeRectangle
*rect
)
2232 struct glyph_row
*r
, *gr
, *end_row
;
2233 enum window_part part
;
2234 enum glyph_row_area area
;
2235 int x
, y
, width
, height
;
2237 /* Try to determine frame pixel position and size of the glyph under
2238 frame pixel coordinates X/Y on frame F. */
2240 if (!f
->glyphs_initialized_p
2241 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, 0),
2244 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2245 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2249 w
= XWINDOW (window
);
2250 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2251 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2253 x
= window_relative_x_coord (w
, part
, gx
);
2254 y
= gy
- WINDOW_TOP_EDGE_Y (w
);
2256 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2257 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2259 if (w
->pseudo_window_p
)
2262 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2268 case ON_LEFT_MARGIN
:
2269 area
= LEFT_MARGIN_AREA
;
2272 case ON_RIGHT_MARGIN
:
2273 area
= RIGHT_MARGIN_AREA
;
2276 case ON_HEADER_LINE
:
2278 gr
= (part
== ON_HEADER_LINE
2279 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2280 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2283 goto text_glyph_row_found
;
2290 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2291 if (r
->y
+ r
->height
> y
)
2297 text_glyph_row_found
:
2300 struct glyph
*g
= gr
->glyphs
[area
];
2301 struct glyph
*end
= g
+ gr
->used
[area
];
2303 height
= gr
->height
;
2304 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2305 if (gx
+ g
->pixel_width
> x
)
2310 if (g
->type
== IMAGE_GLYPH
)
2312 /* Don't remember when mouse is over image, as
2313 image may have hot-spots. */
2314 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2317 width
= g
->pixel_width
;
2321 /* Use nominal char spacing at end of line. */
2323 gx
+= (x
/ width
) * width
;
2326 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2327 gx
+= window_box_left_offset (w
, area
);
2331 /* Use nominal line height at end of window. */
2332 gx
= (x
/ width
) * width
;
2334 gy
+= (y
/ height
) * height
;
2338 case ON_LEFT_FRINGE
:
2339 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2340 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2341 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2342 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2345 case ON_RIGHT_FRINGE
:
2346 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2347 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2348 : window_box_right_offset (w
, TEXT_AREA
));
2349 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2353 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2355 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2356 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2357 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2359 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2363 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2364 if (r
->y
+ r
->height
> y
)
2371 height
= gr
->height
;
2374 /* Use nominal line height at end of window. */
2376 gy
+= (y
/ height
) * height
;
2383 /* If there is no glyph under the mouse, then we divide the screen
2384 into a grid of the smallest glyph in the frame, and use that
2387 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2388 round down even for negative values. */
2394 gx
= (gx
/ width
) * width
;
2395 gy
= (gy
/ height
) * height
;
2400 gx
+= WINDOW_LEFT_EDGE_X (w
);
2401 gy
+= WINDOW_TOP_EDGE_Y (w
);
2404 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2406 /* Visible feedback for debugging. */
2409 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2410 f
->output_data
.x
->normal_gc
,
2411 gx
, gy
, width
, height
);
2417 #endif /* HAVE_WINDOW_SYSTEM */
2420 /***********************************************************************
2421 Lisp form evaluation
2422 ***********************************************************************/
2424 /* Error handler for safe_eval and safe_call. */
2427 safe_eval_handler (Lisp_Object arg
, ptrdiff_t nargs
, Lisp_Object
*args
)
2429 add_to_log ("Error during redisplay: %S signaled %S",
2430 Flist (nargs
, args
), arg
);
2434 /* Call function FUNC with the rest of NARGS - 1 arguments
2435 following. Return the result, or nil if something went
2436 wrong. Prevent redisplay during the evaluation. */
2439 safe_call (ptrdiff_t nargs
, Lisp_Object func
, ...)
2443 if (inhibit_eval_during_redisplay
)
2449 ptrdiff_t count
= SPECPDL_INDEX ();
2450 struct gcpro gcpro1
;
2451 Lisp_Object
*args
= alloca (nargs
* word_size
);
2454 va_start (ap
, func
);
2455 for (i
= 1; i
< nargs
; i
++)
2456 args
[i
] = va_arg (ap
, Lisp_Object
);
2460 gcpro1
.nvars
= nargs
;
2461 specbind (Qinhibit_redisplay
, Qt
);
2462 /* Use Qt to ensure debugger does not run,
2463 so there is no possibility of wanting to redisplay. */
2464 val
= internal_condition_case_n (Ffuncall
, nargs
, args
, Qt
,
2467 val
= unbind_to (count
, val
);
2474 /* Call function FN with one argument ARG.
2475 Return the result, or nil if something went wrong. */
2478 safe_call1 (Lisp_Object fn
, Lisp_Object arg
)
2480 return safe_call (2, fn
, arg
);
2483 static Lisp_Object Qeval
;
2486 safe_eval (Lisp_Object sexpr
)
2488 return safe_call1 (Qeval
, sexpr
);
2491 /* Call function FN with two arguments ARG1 and ARG2.
2492 Return the result, or nil if something went wrong. */
2495 safe_call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2497 return safe_call (3, fn
, arg1
, arg2
);
2502 /***********************************************************************
2504 ***********************************************************************/
2508 /* Define CHECK_IT to perform sanity checks on iterators.
2509 This is for debugging. It is too slow to do unconditionally. */
2512 check_it (struct it
*it
)
2514 if (it
->method
== GET_FROM_STRING
)
2516 eassert (STRINGP (it
->string
));
2517 eassert (IT_STRING_CHARPOS (*it
) >= 0);
2521 eassert (IT_STRING_CHARPOS (*it
) < 0);
2522 if (it
->method
== GET_FROM_BUFFER
)
2524 /* Check that character and byte positions agree. */
2525 eassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2530 eassert (it
->current
.dpvec_index
>= 0);
2532 eassert (it
->current
.dpvec_index
< 0);
2535 #define CHECK_IT(IT) check_it ((IT))
2539 #define CHECK_IT(IT) (void) 0
2544 #if defined GLYPH_DEBUG && defined ENABLE_CHECKING
2546 /* Check that the window end of window W is what we expect it
2547 to be---the last row in the current matrix displaying text. */
2550 check_window_end (struct window
*w
)
2552 if (!MINI_WINDOW_P (w
)
2553 && !NILP (w
->window_end_valid
))
2555 struct glyph_row
*row
;
2556 eassert ((row
= MATRIX_ROW (w
->current_matrix
,
2557 XFASTINT (w
->window_end_vpos
)),
2559 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2560 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2564 #define CHECK_WINDOW_END(W) check_window_end ((W))
2568 #define CHECK_WINDOW_END(W) (void) 0
2570 #endif /* GLYPH_DEBUG and ENABLE_CHECKING */
2574 /***********************************************************************
2575 Iterator initialization
2576 ***********************************************************************/
2578 /* Initialize IT for displaying current_buffer in window W, starting
2579 at character position CHARPOS. CHARPOS < 0 means that no buffer
2580 position is specified which is useful when the iterator is assigned
2581 a position later. BYTEPOS is the byte position corresponding to
2582 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2584 If ROW is not null, calls to produce_glyphs with IT as parameter
2585 will produce glyphs in that row.
2587 BASE_FACE_ID is the id of a base face to use. It must be one of
2588 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2589 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2590 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2592 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2593 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2594 will be initialized to use the corresponding mode line glyph row of
2595 the desired matrix of W. */
2598 init_iterator (struct it
*it
, struct window
*w
,
2599 ptrdiff_t charpos
, ptrdiff_t bytepos
,
2600 struct glyph_row
*row
, enum face_id base_face_id
)
2602 int highlight_region_p
;
2603 enum face_id remapped_base_face_id
= base_face_id
;
2605 /* Some precondition checks. */
2606 eassert (w
!= NULL
&& it
!= NULL
);
2607 eassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2610 /* If face attributes have been changed since the last redisplay,
2611 free realized faces now because they depend on face definitions
2612 that might have changed. Don't free faces while there might be
2613 desired matrices pending which reference these faces. */
2614 if (face_change_count
&& !inhibit_free_realized_faces
)
2616 face_change_count
= 0;
2617 free_all_realized_faces (Qnil
);
2620 /* Perhaps remap BASE_FACE_ID to a user-specified alternative. */
2621 if (! NILP (Vface_remapping_alist
))
2622 remapped_base_face_id
2623 = lookup_basic_face (XFRAME (w
->frame
), base_face_id
);
2625 /* Use one of the mode line rows of W's desired matrix if
2629 if (base_face_id
== MODE_LINE_FACE_ID
2630 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2631 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2632 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2633 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2637 memset (it
, 0, sizeof *it
);
2638 it
->current
.overlay_string_index
= -1;
2639 it
->current
.dpvec_index
= -1;
2640 it
->base_face_id
= remapped_base_face_id
;
2642 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2643 it
->paragraph_embedding
= L2R
;
2644 it
->bidi_it
.string
.lstring
= Qnil
;
2645 it
->bidi_it
.string
.s
= NULL
;
2646 it
->bidi_it
.string
.bufpos
= 0;
2648 /* The window in which we iterate over current_buffer: */
2649 XSETWINDOW (it
->window
, w
);
2651 it
->f
= XFRAME (w
->frame
);
2655 /* Extra space between lines (on window systems only). */
2656 if (base_face_id
== DEFAULT_FACE_ID
2657 && FRAME_WINDOW_P (it
->f
))
2659 if (NATNUMP (BVAR (current_buffer
, extra_line_spacing
)))
2660 it
->extra_line_spacing
= XFASTINT (BVAR (current_buffer
, extra_line_spacing
));
2661 else if (FLOATP (BVAR (current_buffer
, extra_line_spacing
)))
2662 it
->extra_line_spacing
= (XFLOAT_DATA (BVAR (current_buffer
, extra_line_spacing
))
2663 * FRAME_LINE_HEIGHT (it
->f
));
2664 else if (it
->f
->extra_line_spacing
> 0)
2665 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2666 it
->max_extra_line_spacing
= 0;
2669 /* If realized faces have been removed, e.g. because of face
2670 attribute changes of named faces, recompute them. When running
2671 in batch mode, the face cache of the initial frame is null. If
2672 we happen to get called, make a dummy face cache. */
2673 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2674 init_frame_faces (it
->f
);
2675 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2676 recompute_basic_faces (it
->f
);
2678 /* Current value of the `slice', `space-width', and 'height' properties. */
2679 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2680 it
->space_width
= Qnil
;
2681 it
->font_height
= Qnil
;
2682 it
->override_ascent
= -1;
2684 /* Are control characters displayed as `^C'? */
2685 it
->ctl_arrow_p
= !NILP (BVAR (current_buffer
, ctl_arrow
));
2687 /* -1 means everything between a CR and the following line end
2688 is invisible. >0 means lines indented more than this value are
2690 it
->selective
= (INTEGERP (BVAR (current_buffer
, selective_display
))
2692 (-1, XINT (BVAR (current_buffer
, selective_display
)),
2694 : (!NILP (BVAR (current_buffer
, selective_display
))
2696 it
->selective_display_ellipsis_p
2697 = !NILP (BVAR (current_buffer
, selective_display_ellipses
));
2699 /* Display table to use. */
2700 it
->dp
= window_display_table (w
);
2702 /* Are multibyte characters enabled in current_buffer? */
2703 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
2705 /* Non-zero if we should highlight the region. */
2707 = (!NILP (Vtransient_mark_mode
)
2708 && !NILP (BVAR (current_buffer
, mark_active
))
2709 && XMARKER (BVAR (current_buffer
, mark
))->buffer
!= 0);
2711 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2712 start and end of a visible region in window IT->w. Set both to
2713 -1 to indicate no region. */
2714 if (highlight_region_p
2715 /* Maybe highlight only in selected window. */
2716 && (/* Either show region everywhere. */
2717 highlight_nonselected_windows
2718 /* Or show region in the selected window. */
2719 || w
== XWINDOW (selected_window
)
2720 /* Or show the region if we are in the mini-buffer and W is
2721 the window the mini-buffer refers to. */
2722 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2723 && WINDOWP (minibuf_selected_window
)
2724 && w
== XWINDOW (minibuf_selected_window
))))
2726 ptrdiff_t markpos
= marker_position (BVAR (current_buffer
, mark
));
2727 it
->region_beg_charpos
= min (PT
, markpos
);
2728 it
->region_end_charpos
= max (PT
, markpos
);
2731 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2733 /* Get the position at which the redisplay_end_trigger hook should
2734 be run, if it is to be run at all. */
2735 if (MARKERP (w
->redisplay_end_trigger
)
2736 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2737 it
->redisplay_end_trigger_charpos
2738 = marker_position (w
->redisplay_end_trigger
);
2739 else if (INTEGERP (w
->redisplay_end_trigger
))
2740 it
->redisplay_end_trigger_charpos
=
2741 clip_to_bounds (PTRDIFF_MIN
, XINT (w
->redisplay_end_trigger
), PTRDIFF_MAX
);
2743 it
->tab_width
= SANE_TAB_WIDTH (current_buffer
);
2745 /* Are lines in the display truncated? */
2746 if (base_face_id
!= DEFAULT_FACE_ID
2748 || (! WINDOW_FULL_WIDTH_P (it
->w
)
2749 && ((!NILP (Vtruncate_partial_width_windows
)
2750 && !INTEGERP (Vtruncate_partial_width_windows
))
2751 || (INTEGERP (Vtruncate_partial_width_windows
)
2752 && (WINDOW_TOTAL_COLS (it
->w
)
2753 < XINT (Vtruncate_partial_width_windows
))))))
2754 it
->line_wrap
= TRUNCATE
;
2755 else if (NILP (BVAR (current_buffer
, truncate_lines
)))
2756 it
->line_wrap
= NILP (BVAR (current_buffer
, word_wrap
))
2757 ? WINDOW_WRAP
: WORD_WRAP
;
2759 it
->line_wrap
= TRUNCATE
;
2761 /* Get dimensions of truncation and continuation glyphs. These are
2762 displayed as fringe bitmaps under X, but we need them for such
2763 frames when the fringes are turned off. But leave the dimensions
2764 zero for tooltip frames, as these glyphs look ugly there and also
2765 sabotage calculations of tooltip dimensions in x-show-tip. */
2766 #ifdef HAVE_WINDOW_SYSTEM
2767 if (!(FRAME_WINDOW_P (it
->f
)
2768 && FRAMEP (tip_frame
)
2769 && it
->f
== XFRAME (tip_frame
)))
2772 if (it
->line_wrap
== TRUNCATE
)
2774 /* We will need the truncation glyph. */
2775 eassert (it
->glyph_row
== NULL
);
2776 produce_special_glyphs (it
, IT_TRUNCATION
);
2777 it
->truncation_pixel_width
= it
->pixel_width
;
2781 /* We will need the continuation glyph. */
2782 eassert (it
->glyph_row
== NULL
);
2783 produce_special_glyphs (it
, IT_CONTINUATION
);
2784 it
->continuation_pixel_width
= it
->pixel_width
;
2788 /* Reset these values to zero because the produce_special_glyphs
2789 above has changed them. */
2790 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2791 it
->phys_ascent
= it
->phys_descent
= 0;
2793 /* Set this after getting the dimensions of truncation and
2794 continuation glyphs, so that we don't produce glyphs when calling
2795 produce_special_glyphs, above. */
2796 it
->glyph_row
= row
;
2797 it
->area
= TEXT_AREA
;
2799 /* Forget any previous info about this row being reversed. */
2801 it
->glyph_row
->reversed_p
= 0;
2803 /* Get the dimensions of the display area. The display area
2804 consists of the visible window area plus a horizontally scrolled
2805 part to the left of the window. All x-values are relative to the
2806 start of this total display area. */
2807 if (base_face_id
!= DEFAULT_FACE_ID
)
2809 /* Mode lines, menu bar in terminal frames. */
2810 it
->first_visible_x
= 0;
2811 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2815 it
->first_visible_x
=
2816 window_hscroll_limited (it
->w
, it
->f
) * FRAME_COLUMN_WIDTH (it
->f
);
2817 it
->last_visible_x
= (it
->first_visible_x
2818 + window_box_width (w
, TEXT_AREA
));
2820 /* If we truncate lines, leave room for the truncation glyph(s) at
2821 the right margin. Otherwise, leave room for the continuation
2822 glyph(s). Done only if the window has no fringes. Since we
2823 don't know at this point whether there will be any R2L lines in
2824 the window, we reserve space for truncation/continuation glyphs
2825 even if only one of the fringes is absent. */
2826 if (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0
2827 || (it
->bidi_p
&& WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0))
2829 if (it
->line_wrap
== TRUNCATE
)
2830 it
->last_visible_x
-= it
->truncation_pixel_width
;
2832 it
->last_visible_x
-= it
->continuation_pixel_width
;
2835 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2836 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2839 /* Leave room for a border glyph. */
2840 if (!FRAME_WINDOW_P (it
->f
)
2841 && !WINDOW_RIGHTMOST_P (it
->w
))
2842 it
->last_visible_x
-= 1;
2844 it
->last_visible_y
= window_text_bottom_y (w
);
2846 /* For mode lines and alike, arrange for the first glyph having a
2847 left box line if the face specifies a box. */
2848 if (base_face_id
!= DEFAULT_FACE_ID
)
2852 it
->face_id
= remapped_base_face_id
;
2854 /* If we have a boxed mode line, make the first character appear
2855 with a left box line. */
2856 face
= FACE_FROM_ID (it
->f
, remapped_base_face_id
);
2857 if (face
->box
!= FACE_NO_BOX
)
2858 it
->start_of_box_run_p
= 1;
2861 /* If a buffer position was specified, set the iterator there,
2862 getting overlays and face properties from that position. */
2863 if (charpos
>= BUF_BEG (current_buffer
))
2865 it
->end_charpos
= ZV
;
2866 IT_CHARPOS (*it
) = charpos
;
2868 /* We will rely on `reseat' to set this up properly, via
2869 handle_face_prop. */
2870 it
->face_id
= it
->base_face_id
;
2872 /* Compute byte position if not specified. */
2873 if (bytepos
< charpos
)
2874 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2876 IT_BYTEPOS (*it
) = bytepos
;
2878 it
->start
= it
->current
;
2879 /* Do we need to reorder bidirectional text? Not if this is a
2880 unibyte buffer: by definition, none of the single-byte
2881 characters are strong R2L, so no reordering is needed. And
2882 bidi.c doesn't support unibyte buffers anyway. Also, don't
2883 reorder while we are loading loadup.el, since the tables of
2884 character properties needed for reordering are not yet
2888 && !NILP (BVAR (current_buffer
, bidi_display_reordering
))
2891 /* If we are to reorder bidirectional text, init the bidi
2895 /* Note the paragraph direction that this buffer wants to
2897 if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2899 it
->paragraph_embedding
= L2R
;
2900 else if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2902 it
->paragraph_embedding
= R2L
;
2904 it
->paragraph_embedding
= NEUTRAL_DIR
;
2905 bidi_unshelve_cache (NULL
, 0);
2906 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
2910 /* Compute faces etc. */
2911 reseat (it
, it
->current
.pos
, 1);
2918 /* Initialize IT for the display of window W with window start POS. */
2921 start_display (struct it
*it
, struct window
*w
, struct text_pos pos
)
2923 struct glyph_row
*row
;
2924 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2926 row
= w
->desired_matrix
->rows
+ first_vpos
;
2927 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2928 it
->first_vpos
= first_vpos
;
2930 /* Don't reseat to previous visible line start if current start
2931 position is in a string or image. */
2932 if (it
->method
== GET_FROM_BUFFER
&& it
->line_wrap
!= TRUNCATE
)
2934 int start_at_line_beg_p
;
2935 int first_y
= it
->current_y
;
2937 /* If window start is not at a line start, skip forward to POS to
2938 get the correct continuation lines width. */
2939 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2940 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2941 if (!start_at_line_beg_p
)
2945 reseat_at_previous_visible_line_start (it
);
2946 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2948 new_x
= it
->current_x
+ it
->pixel_width
;
2950 /* If lines are continued, this line may end in the middle
2951 of a multi-glyph character (e.g. a control character
2952 displayed as \003, or in the middle of an overlay
2953 string). In this case move_it_to above will not have
2954 taken us to the start of the continuation line but to the
2955 end of the continued line. */
2956 if (it
->current_x
> 0
2957 && it
->line_wrap
!= TRUNCATE
/* Lines are continued. */
2958 && (/* And glyph doesn't fit on the line. */
2959 new_x
> it
->last_visible_x
2960 /* Or it fits exactly and we're on a window
2962 || (new_x
== it
->last_visible_x
2963 && FRAME_WINDOW_P (it
->f
)
2964 && ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
2965 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
2966 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
2968 if ((it
->current
.dpvec_index
>= 0
2969 || it
->current
.overlay_string_index
>= 0)
2970 /* If we are on a newline from a display vector or
2971 overlay string, then we are already at the end of
2972 a screen line; no need to go to the next line in
2973 that case, as this line is not really continued.
2974 (If we do go to the next line, C-e will not DTRT.) */
2977 set_iterator_to_next (it
, 1);
2978 move_it_in_display_line_to (it
, -1, -1, 0);
2981 it
->continuation_lines_width
+= it
->current_x
;
2983 /* If the character at POS is displayed via a display
2984 vector, move_it_to above stops at the final glyph of
2985 IT->dpvec. To make the caller redisplay that character
2986 again (a.k.a. start at POS), we need to reset the
2987 dpvec_index to the beginning of IT->dpvec. */
2988 else if (it
->current
.dpvec_index
>= 0)
2989 it
->current
.dpvec_index
= 0;
2991 /* We're starting a new display line, not affected by the
2992 height of the continued line, so clear the appropriate
2993 fields in the iterator structure. */
2994 it
->max_ascent
= it
->max_descent
= 0;
2995 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2997 it
->current_y
= first_y
;
2999 it
->current_x
= it
->hpos
= 0;
3005 /* Return 1 if POS is a position in ellipses displayed for invisible
3006 text. W is the window we display, for text property lookup. */
3009 in_ellipses_for_invisible_text_p (struct display_pos
*pos
, struct window
*w
)
3011 Lisp_Object prop
, window
;
3013 ptrdiff_t charpos
= CHARPOS (pos
->pos
);
3015 /* If POS specifies a position in a display vector, this might
3016 be for an ellipsis displayed for invisible text. We won't
3017 get the iterator set up for delivering that ellipsis unless
3018 we make sure that it gets aware of the invisible text. */
3019 if (pos
->dpvec_index
>= 0
3020 && pos
->overlay_string_index
< 0
3021 && CHARPOS (pos
->string_pos
) < 0
3023 && (XSETWINDOW (window
, w
),
3024 prop
= Fget_char_property (make_number (charpos
),
3025 Qinvisible
, window
),
3026 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
3028 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
3030 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
3037 /* Initialize IT for stepping through current_buffer in window W,
3038 starting at position POS that includes overlay string and display
3039 vector/ control character translation position information. Value
3040 is zero if there are overlay strings with newlines at POS. */
3043 init_from_display_pos (struct it
*it
, struct window
*w
, struct display_pos
*pos
)
3045 ptrdiff_t charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
3046 int i
, overlay_strings_with_newlines
= 0;
3048 /* If POS specifies a position in a display vector, this might
3049 be for an ellipsis displayed for invisible text. We won't
3050 get the iterator set up for delivering that ellipsis unless
3051 we make sure that it gets aware of the invisible text. */
3052 if (in_ellipses_for_invisible_text_p (pos
, w
))
3058 /* Keep in mind: the call to reseat in init_iterator skips invisible
3059 text, so we might end up at a position different from POS. This
3060 is only a problem when POS is a row start after a newline and an
3061 overlay starts there with an after-string, and the overlay has an
3062 invisible property. Since we don't skip invisible text in
3063 display_line and elsewhere immediately after consuming the
3064 newline before the row start, such a POS will not be in a string,
3065 but the call to init_iterator below will move us to the
3067 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
3069 /* This only scans the current chunk -- it should scan all chunks.
3070 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
3071 to 16 in 22.1 to make this a lesser problem. */
3072 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
3074 const char *s
= SSDATA (it
->overlay_strings
[i
]);
3075 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
3077 while (s
< e
&& *s
!= '\n')
3082 overlay_strings_with_newlines
= 1;
3087 /* If position is within an overlay string, set up IT to the right
3089 if (pos
->overlay_string_index
>= 0)
3093 /* If the first overlay string happens to have a `display'
3094 property for an image, the iterator will be set up for that
3095 image, and we have to undo that setup first before we can
3096 correct the overlay string index. */
3097 if (it
->method
== GET_FROM_IMAGE
)
3100 /* We already have the first chunk of overlay strings in
3101 IT->overlay_strings. Load more until the one for
3102 pos->overlay_string_index is in IT->overlay_strings. */
3103 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
3105 ptrdiff_t n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
3106 it
->current
.overlay_string_index
= 0;
3109 load_overlay_strings (it
, 0);
3110 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
3114 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
3115 relative_index
= (it
->current
.overlay_string_index
3116 % OVERLAY_STRING_CHUNK_SIZE
);
3117 it
->string
= it
->overlay_strings
[relative_index
];
3118 eassert (STRINGP (it
->string
));
3119 it
->current
.string_pos
= pos
->string_pos
;
3120 it
->method
= GET_FROM_STRING
;
3121 it
->end_charpos
= SCHARS (it
->string
);
3122 /* Set up the bidi iterator for this overlay string. */
3125 it
->bidi_it
.string
.lstring
= it
->string
;
3126 it
->bidi_it
.string
.s
= NULL
;
3127 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
3128 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
3129 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
3130 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
3131 bidi_init_it (IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
),
3132 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
3134 /* Synchronize the state of the bidi iterator with
3135 pos->string_pos. For any string position other than
3136 zero, this will be done automagically when we resume
3137 iteration over the string and get_visually_first_element
3138 is called. But if string_pos is zero, and the string is
3139 to be reordered for display, we need to resync manually,
3140 since it could be that the iteration state recorded in
3141 pos ended at string_pos of 0 moving backwards in string. */
3142 if (CHARPOS (pos
->string_pos
) == 0)
3144 get_visually_first_element (it
);
3145 if (IT_STRING_CHARPOS (*it
) != 0)
3148 eassert (it
->bidi_it
.charpos
< it
->bidi_it
.string
.schars
);
3149 bidi_move_to_visually_next (&it
->bidi_it
);
3150 } while (it
->bidi_it
.charpos
!= 0);
3152 eassert (IT_STRING_CHARPOS (*it
) == it
->bidi_it
.charpos
3153 && IT_STRING_BYTEPOS (*it
) == it
->bidi_it
.bytepos
);
3157 if (CHARPOS (pos
->string_pos
) >= 0)
3159 /* Recorded position is not in an overlay string, but in another
3160 string. This can only be a string from a `display' property.
3161 IT should already be filled with that string. */
3162 it
->current
.string_pos
= pos
->string_pos
;
3163 eassert (STRINGP (it
->string
));
3165 bidi_init_it (IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
),
3166 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
3169 /* Restore position in display vector translations, control
3170 character translations or ellipses. */
3171 if (pos
->dpvec_index
>= 0)
3173 if (it
->dpvec
== NULL
)
3174 get_next_display_element (it
);
3175 eassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
3176 it
->current
.dpvec_index
= pos
->dpvec_index
;
3180 return !overlay_strings_with_newlines
;
3184 /* Initialize IT for stepping through current_buffer in window W
3185 starting at ROW->start. */
3188 init_to_row_start (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3190 init_from_display_pos (it
, w
, &row
->start
);
3191 it
->start
= row
->start
;
3192 it
->continuation_lines_width
= row
->continuation_lines_width
;
3197 /* Initialize IT for stepping through current_buffer in window W
3198 starting in the line following ROW, i.e. starting at ROW->end.
3199 Value is zero if there are overlay strings with newlines at ROW's
3203 init_to_row_end (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3207 if (init_from_display_pos (it
, w
, &row
->end
))
3209 if (row
->continued_p
)
3210 it
->continuation_lines_width
3211 = row
->continuation_lines_width
+ row
->pixel_width
;
3222 /***********************************************************************
3224 ***********************************************************************/
3226 /* Called when IT reaches IT->stop_charpos. Handle text property and
3227 overlay changes. Set IT->stop_charpos to the next position where
3231 handle_stop (struct it
*it
)
3233 enum prop_handled handled
;
3234 int handle_overlay_change_p
;
3238 it
->current
.dpvec_index
= -1;
3239 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3240 it
->ignore_overlay_strings_at_pos_p
= 0;
3243 /* Use face of preceding text for ellipsis (if invisible) */
3244 if (it
->selective_display_ellipsis_p
)
3245 it
->saved_face_id
= it
->face_id
;
3249 handled
= HANDLED_NORMALLY
;
3251 /* Call text property handlers. */
3252 for (p
= it_props
; p
->handler
; ++p
)
3254 handled
= p
->handler (it
);
3256 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3258 else if (handled
== HANDLED_RETURN
)
3260 /* We still want to show before and after strings from
3261 overlays even if the actual buffer text is replaced. */
3262 if (!handle_overlay_change_p
3264 /* Don't call get_overlay_strings_1 if we already
3265 have overlay strings loaded, because doing so
3266 will load them again and push the iterator state
3267 onto the stack one more time, which is not
3268 expected by the rest of the code that processes
3270 || (it
->current
.overlay_string_index
< 0
3271 ? !get_overlay_strings_1 (it
, 0, 0)
3275 setup_for_ellipsis (it
, 0);
3276 /* When handling a display spec, we might load an
3277 empty string. In that case, discard it here. We
3278 used to discard it in handle_single_display_spec,
3279 but that causes get_overlay_strings_1, above, to
3280 ignore overlay strings that we must check. */
3281 if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3285 else if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3289 it
->ignore_overlay_strings_at_pos_p
= 1;
3290 it
->string_from_display_prop_p
= 0;
3291 it
->from_disp_prop_p
= 0;
3292 handle_overlay_change_p
= 0;
3294 handled
= HANDLED_RECOMPUTE_PROPS
;
3297 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3298 handle_overlay_change_p
= 0;
3301 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3303 /* Don't check for overlay strings below when set to deliver
3304 characters from a display vector. */
3305 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3306 handle_overlay_change_p
= 0;
3308 /* Handle overlay changes.
3309 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
3310 if it finds overlays. */
3311 if (handle_overlay_change_p
)
3312 handled
= handle_overlay_change (it
);
3317 setup_for_ellipsis (it
, 0);
3321 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3323 /* Determine where to stop next. */
3324 if (handled
== HANDLED_NORMALLY
)
3325 compute_stop_pos (it
);
3329 /* Compute IT->stop_charpos from text property and overlay change
3330 information for IT's current position. */
3333 compute_stop_pos (struct it
*it
)
3335 register INTERVAL iv
, next_iv
;
3336 Lisp_Object object
, limit
, position
;
3337 ptrdiff_t charpos
, bytepos
;
3339 if (STRINGP (it
->string
))
3341 /* Strings are usually short, so don't limit the search for
3343 it
->stop_charpos
= it
->end_charpos
;
3344 object
= it
->string
;
3346 charpos
= IT_STRING_CHARPOS (*it
);
3347 bytepos
= IT_STRING_BYTEPOS (*it
);
3353 /* If end_charpos is out of range for some reason, such as a
3354 misbehaving display function, rationalize it (Bug#5984). */
3355 if (it
->end_charpos
> ZV
)
3356 it
->end_charpos
= ZV
;
3357 it
->stop_charpos
= it
->end_charpos
;
3359 /* If next overlay change is in front of the current stop pos
3360 (which is IT->end_charpos), stop there. Note: value of
3361 next_overlay_change is point-max if no overlay change
3363 charpos
= IT_CHARPOS (*it
);
3364 bytepos
= IT_BYTEPOS (*it
);
3365 pos
= next_overlay_change (charpos
);
3366 if (pos
< it
->stop_charpos
)
3367 it
->stop_charpos
= pos
;
3369 /* If showing the region, we have to stop at the region
3370 start or end because the face might change there. */
3371 if (it
->region_beg_charpos
> 0)
3373 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
3374 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
3375 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
3376 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3379 /* Set up variables for computing the stop position from text
3380 property changes. */
3381 XSETBUFFER (object
, current_buffer
);
3382 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3385 /* Get the interval containing IT's position. Value is a null
3386 interval if there isn't such an interval. */
3387 position
= make_number (charpos
);
3388 iv
= validate_interval_range (object
, &position
, &position
, 0);
3391 Lisp_Object values_here
[LAST_PROP_IDX
];
3394 /* Get properties here. */
3395 for (p
= it_props
; p
->handler
; ++p
)
3396 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3398 /* Look for an interval following iv that has different
3400 for (next_iv
= next_interval (iv
);
3403 || XFASTINT (limit
) > next_iv
->position
));
3404 next_iv
= next_interval (next_iv
))
3406 for (p
= it_props
; p
->handler
; ++p
)
3408 Lisp_Object new_value
;
3410 new_value
= textget (next_iv
->plist
, *p
->name
);
3411 if (!EQ (values_here
[p
->idx
], new_value
))
3421 if (INTEGERP (limit
)
3422 && next_iv
->position
>= XFASTINT (limit
))
3423 /* No text property change up to limit. */
3424 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3426 /* Text properties change in next_iv. */
3427 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3431 if (it
->cmp_it
.id
< 0)
3433 ptrdiff_t stoppos
= it
->end_charpos
;
3435 if (it
->bidi_p
&& it
->bidi_it
.scan_dir
< 0)
3437 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
,
3438 stoppos
, it
->string
);
3441 eassert (STRINGP (it
->string
)
3442 || (it
->stop_charpos
>= BEGV
3443 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3447 /* Return the position of the next overlay change after POS in
3448 current_buffer. Value is point-max if no overlay change
3449 follows. This is like `next-overlay-change' but doesn't use
3453 next_overlay_change (ptrdiff_t pos
)
3455 ptrdiff_t i
, noverlays
;
3457 Lisp_Object
*overlays
;
3459 /* Get all overlays at the given position. */
3460 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3462 /* If any of these overlays ends before endpos,
3463 use its ending point instead. */
3464 for (i
= 0; i
< noverlays
; ++i
)
3469 oend
= OVERLAY_END (overlays
[i
]);
3470 oendpos
= OVERLAY_POSITION (oend
);
3471 endpos
= min (endpos
, oendpos
);
3477 /* How many characters forward to search for a display property or
3478 display string. Searching too far forward makes the bidi display
3479 sluggish, especially in small windows. */
3480 #define MAX_DISP_SCAN 250
3482 /* Return the character position of a display string at or after
3483 position specified by POSITION. If no display string exists at or
3484 after POSITION, return ZV. A display string is either an overlay
3485 with `display' property whose value is a string, or a `display'
3486 text property whose value is a string. STRING is data about the
3487 string to iterate; if STRING->lstring is nil, we are iterating a
3488 buffer. FRAME_WINDOW_P is non-zero when we are displaying a window
3489 on a GUI frame. DISP_PROP is set to zero if we searched
3490 MAX_DISP_SCAN characters forward without finding any display
3491 strings, non-zero otherwise. It is set to 2 if the display string
3492 uses any kind of `(space ...)' spec that will produce a stretch of
3493 white space in the text area. */
3495 compute_display_string_pos (struct text_pos
*position
,
3496 struct bidi_string_data
*string
,
3497 int frame_window_p
, int *disp_prop
)
3499 /* OBJECT = nil means current buffer. */
3500 Lisp_Object object
=
3501 (string
&& STRINGP (string
->lstring
)) ? string
->lstring
: Qnil
;
3502 Lisp_Object pos
, spec
, limpos
;
3503 int string_p
= (string
&& (STRINGP (string
->lstring
) || string
->s
));
3504 ptrdiff_t eob
= string_p
? string
->schars
: ZV
;
3505 ptrdiff_t begb
= string_p
? 0 : BEGV
;
3506 ptrdiff_t bufpos
, charpos
= CHARPOS (*position
);
3508 (charpos
< eob
- MAX_DISP_SCAN
) ? charpos
+ MAX_DISP_SCAN
: eob
;
3509 struct text_pos tpos
;
3515 /* We don't support display properties whose values are strings
3516 that have display string properties. */
3517 || string
->from_disp_str
3518 /* C strings cannot have display properties. */
3519 || (string
->s
&& !STRINGP (object
)))
3525 /* If the character at CHARPOS is where the display string begins,
3527 pos
= make_number (charpos
);
3528 if (STRINGP (object
))
3529 bufpos
= string
->bufpos
;
3533 if (!NILP (spec
= Fget_char_property (pos
, Qdisplay
, object
))
3535 || !EQ (Fget_char_property (make_number (charpos
- 1), Qdisplay
,
3538 && (rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
, bufpos
,
3546 /* Look forward for the first character with a `display' property
3547 that will replace the underlying text when displayed. */
3548 limpos
= make_number (lim
);
3550 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, limpos
);
3551 CHARPOS (tpos
) = XFASTINT (pos
);
3552 if (CHARPOS (tpos
) >= lim
)
3557 if (STRINGP (object
))
3558 BYTEPOS (tpos
) = string_char_to_byte (object
, CHARPOS (tpos
));
3560 BYTEPOS (tpos
) = CHAR_TO_BYTE (CHARPOS (tpos
));
3561 spec
= Fget_char_property (pos
, Qdisplay
, object
);
3562 if (!STRINGP (object
))
3563 bufpos
= CHARPOS (tpos
);
3564 } while (NILP (spec
)
3565 || !(rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
,
3566 bufpos
, frame_window_p
)));
3570 return CHARPOS (tpos
);
3573 /* Return the character position of the end of the display string that
3574 started at CHARPOS. If there's no display string at CHARPOS,
3575 return -1. A display string is either an overlay with `display'
3576 property whose value is a string or a `display' text property whose
3577 value is a string. */
3579 compute_display_string_end (ptrdiff_t charpos
, struct bidi_string_data
*string
)
3581 /* OBJECT = nil means current buffer. */
3582 Lisp_Object object
=
3583 (string
&& STRINGP (string
->lstring
)) ? string
->lstring
: Qnil
;
3584 Lisp_Object pos
= make_number (charpos
);
3586 (STRINGP (object
) || (string
&& string
->s
)) ? string
->schars
: ZV
;
3588 if (charpos
>= eob
|| (string
->s
&& !STRINGP (object
)))
3591 /* It could happen that the display property or overlay was removed
3592 since we found it in compute_display_string_pos above. One way
3593 this can happen is if JIT font-lock was called (through
3594 handle_fontified_prop), and jit-lock-functions remove text
3595 properties or overlays from the portion of buffer that includes
3596 CHARPOS. Muse mode is known to do that, for example. In this
3597 case, we return -1 to the caller, to signal that no display
3598 string is actually present at CHARPOS. See bidi_fetch_char for
3599 how this is handled.
3601 An alternative would be to never look for display properties past
3602 it->stop_charpos. But neither compute_display_string_pos nor
3603 bidi_fetch_char that calls it know or care where the next
3605 if (NILP (Fget_char_property (pos
, Qdisplay
, object
)))
3608 /* Look forward for the first character where the `display' property
3610 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, Qnil
);
3612 return XFASTINT (pos
);
3617 /***********************************************************************
3619 ***********************************************************************/
3621 /* Handle changes in the `fontified' property of the current buffer by
3622 calling hook functions from Qfontification_functions to fontify
3625 static enum prop_handled
3626 handle_fontified_prop (struct it
*it
)
3628 Lisp_Object prop
, pos
;
3629 enum prop_handled handled
= HANDLED_NORMALLY
;
3631 if (!NILP (Vmemory_full
))
3634 /* Get the value of the `fontified' property at IT's current buffer
3635 position. (The `fontified' property doesn't have a special
3636 meaning in strings.) If the value is nil, call functions from
3637 Qfontification_functions. */
3638 if (!STRINGP (it
->string
)
3640 && !NILP (Vfontification_functions
)
3641 && !NILP (Vrun_hooks
)
3642 && (pos
= make_number (IT_CHARPOS (*it
)),
3643 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3644 /* Ignore the special cased nil value always present at EOB since
3645 no amount of fontifying will be able to change it. */
3646 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3648 ptrdiff_t count
= SPECPDL_INDEX ();
3650 struct buffer
*obuf
= current_buffer
;
3651 int begv
= BEGV
, zv
= ZV
;
3652 int old_clip_changed
= current_buffer
->clip_changed
;
3654 val
= Vfontification_functions
;
3655 specbind (Qfontification_functions
, Qnil
);
3657 eassert (it
->end_charpos
== ZV
);
3659 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3660 safe_call1 (val
, pos
);
3663 Lisp_Object fns
, fn
;
3664 struct gcpro gcpro1
, gcpro2
;
3669 for (; CONSP (val
); val
= XCDR (val
))
3675 /* A value of t indicates this hook has a local
3676 binding; it means to run the global binding too.
3677 In a global value, t should not occur. If it
3678 does, we must ignore it to avoid an endless
3680 for (fns
= Fdefault_value (Qfontification_functions
);
3686 safe_call1 (fn
, pos
);
3690 safe_call1 (fn
, pos
);
3696 unbind_to (count
, Qnil
);
3698 /* Fontification functions routinely call `save-restriction'.
3699 Normally, this tags clip_changed, which can confuse redisplay
3700 (see discussion in Bug#6671). Since we don't perform any
3701 special handling of fontification changes in the case where
3702 `save-restriction' isn't called, there's no point doing so in
3703 this case either. So, if the buffer's restrictions are
3704 actually left unchanged, reset clip_changed. */
3705 if (obuf
== current_buffer
)
3707 if (begv
== BEGV
&& zv
== ZV
)
3708 current_buffer
->clip_changed
= old_clip_changed
;
3710 /* There isn't much we can reasonably do to protect against
3711 misbehaving fontification, but here's a fig leaf. */
3712 else if (BUFFER_LIVE_P (obuf
))
3713 set_buffer_internal_1 (obuf
);
3715 /* The fontification code may have added/removed text.
3716 It could do even a lot worse, but let's at least protect against
3717 the most obvious case where only the text past `pos' gets changed',
3718 as is/was done in grep.el where some escapes sequences are turned
3719 into face properties (bug#7876). */
3720 it
->end_charpos
= ZV
;
3722 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3723 something. This avoids an endless loop if they failed to
3724 fontify the text for which reason ever. */
3725 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3726 handled
= HANDLED_RECOMPUTE_PROPS
;
3734 /***********************************************************************
3736 ***********************************************************************/
3738 /* Set up iterator IT from face properties at its current position.
3739 Called from handle_stop. */
3741 static enum prop_handled
3742 handle_face_prop (struct it
*it
)
3745 ptrdiff_t next_stop
;
3747 if (!STRINGP (it
->string
))
3750 = face_at_buffer_position (it
->w
,
3752 it
->region_beg_charpos
,
3753 it
->region_end_charpos
,
3756 + TEXT_PROP_DISTANCE_LIMIT
),
3757 0, it
->base_face_id
);
3759 /* Is this a start of a run of characters with box face?
3760 Caveat: this can be called for a freshly initialized
3761 iterator; face_id is -1 in this case. We know that the new
3762 face will not change until limit, i.e. if the new face has a
3763 box, all characters up to limit will have one. But, as
3764 usual, we don't know whether limit is really the end. */
3765 if (new_face_id
!= it
->face_id
)
3767 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3769 /* If new face has a box but old face has not, this is
3770 the start of a run of characters with box, i.e. it has
3771 a shadow on the left side. The value of face_id of the
3772 iterator will be -1 if this is the initial call that gets
3773 the face. In this case, we have to look in front of IT's
3774 position and see whether there is a face != new_face_id. */
3775 it
->start_of_box_run_p
3776 = (new_face
->box
!= FACE_NO_BOX
3777 && (it
->face_id
>= 0
3778 || IT_CHARPOS (*it
) == BEG
3779 || new_face_id
!= face_before_it_pos (it
)));
3780 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3788 Lisp_Object from_overlay
3789 = (it
->current
.overlay_string_index
>= 0
3790 ? it
->string_overlays
[it
->current
.overlay_string_index
3791 % OVERLAY_STRING_CHUNK_SIZE
]
3794 /* See if we got to this string directly or indirectly from
3795 an overlay property. That includes the before-string or
3796 after-string of an overlay, strings in display properties
3797 provided by an overlay, their text properties, etc.
3799 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3800 if (! NILP (from_overlay
))
3801 for (i
= it
->sp
- 1; i
>= 0; i
--)
3803 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3805 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
3806 % OVERLAY_STRING_CHUNK_SIZE
];
3807 else if (! NILP (it
->stack
[i
].from_overlay
))
3808 from_overlay
= it
->stack
[i
].from_overlay
;
3810 if (!NILP (from_overlay
))
3814 if (! NILP (from_overlay
))
3816 bufpos
= IT_CHARPOS (*it
);
3817 /* For a string from an overlay, the base face depends
3818 only on text properties and ignores overlays. */
3820 = face_for_overlay_string (it
->w
,
3822 it
->region_beg_charpos
,
3823 it
->region_end_charpos
,
3826 + TEXT_PROP_DISTANCE_LIMIT
),
3834 /* For strings from a `display' property, use the face at
3835 IT's current buffer position as the base face to merge
3836 with, so that overlay strings appear in the same face as
3837 surrounding text, unless they specify their own
3839 base_face_id
= it
->string_from_prefix_prop_p
3841 : underlying_face_id (it
);
3844 new_face_id
= face_at_string_position (it
->w
,
3846 IT_STRING_CHARPOS (*it
),
3848 it
->region_beg_charpos
,
3849 it
->region_end_charpos
,
3853 /* Is this a start of a run of characters with box? Caveat:
3854 this can be called for a freshly allocated iterator; face_id
3855 is -1 is this case. We know that the new face will not
3856 change until the next check pos, i.e. if the new face has a
3857 box, all characters up to that position will have a
3858 box. But, as usual, we don't know whether that position
3859 is really the end. */
3860 if (new_face_id
!= it
->face_id
)
3862 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3863 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3865 /* If new face has a box but old face hasn't, this is the
3866 start of a run of characters with box, i.e. it has a
3867 shadow on the left side. */
3868 it
->start_of_box_run_p
3869 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3870 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3874 it
->face_id
= new_face_id
;
3875 return HANDLED_NORMALLY
;
3879 /* Return the ID of the face ``underlying'' IT's current position,
3880 which is in a string. If the iterator is associated with a
3881 buffer, return the face at IT's current buffer position.
3882 Otherwise, use the iterator's base_face_id. */
3885 underlying_face_id (struct it
*it
)
3887 int face_id
= it
->base_face_id
, i
;
3889 eassert (STRINGP (it
->string
));
3891 for (i
= it
->sp
- 1; i
>= 0; --i
)
3892 if (NILP (it
->stack
[i
].string
))
3893 face_id
= it
->stack
[i
].face_id
;
3899 /* Compute the face one character before or after the current position
3900 of IT, in the visual order. BEFORE_P non-zero means get the face
3901 in front (to the left in L2R paragraphs, to the right in R2L
3902 paragraphs) of IT's screen position. Value is the ID of the face. */
3905 face_before_or_after_it_pos (struct it
*it
, int before_p
)
3908 ptrdiff_t next_check_charpos
;
3910 void *it_copy_data
= NULL
;
3912 eassert (it
->s
== NULL
);
3914 if (STRINGP (it
->string
))
3916 ptrdiff_t bufpos
, charpos
;
3919 /* No face change past the end of the string (for the case
3920 we are padding with spaces). No face change before the
3922 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3923 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3928 /* Set charpos to the position before or after IT's current
3929 position, in the logical order, which in the non-bidi
3930 case is the same as the visual order. */
3932 charpos
= IT_STRING_CHARPOS (*it
) - 1;
3933 else if (it
->what
== IT_COMPOSITION
)
3934 /* For composition, we must check the character after the
3936 charpos
= IT_STRING_CHARPOS (*it
) + it
->cmp_it
.nchars
;
3938 charpos
= IT_STRING_CHARPOS (*it
) + 1;
3944 /* With bidi iteration, the character before the current
3945 in the visual order cannot be found by simple
3946 iteration, because "reverse" reordering is not
3947 supported. Instead, we need to use the move_it_*
3948 family of functions. */
3949 /* Ignore face changes before the first visible
3950 character on this display line. */
3951 if (it
->current_x
<= it
->first_visible_x
)
3953 SAVE_IT (it_copy
, *it
, it_copy_data
);
3954 /* Implementation note: Since move_it_in_display_line
3955 works in the iterator geometry, and thinks the first
3956 character is always the leftmost, even in R2L lines,
3957 we don't need to distinguish between the R2L and L2R
3959 move_it_in_display_line (&it_copy
, SCHARS (it_copy
.string
),
3960 it_copy
.current_x
- 1, MOVE_TO_X
);
3961 charpos
= IT_STRING_CHARPOS (it_copy
);
3962 RESTORE_IT (it
, it
, it_copy_data
);
3966 /* Set charpos to the string position of the character
3967 that comes after IT's current position in the visual
3969 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
3973 bidi_move_to_visually_next (&it_copy
.bidi_it
);
3975 charpos
= it_copy
.bidi_it
.charpos
;
3978 eassert (0 <= charpos
&& charpos
<= SCHARS (it
->string
));
3980 if (it
->current
.overlay_string_index
>= 0)
3981 bufpos
= IT_CHARPOS (*it
);
3985 base_face_id
= underlying_face_id (it
);
3987 /* Get the face for ASCII, or unibyte. */
3988 face_id
= face_at_string_position (it
->w
,
3992 it
->region_beg_charpos
,
3993 it
->region_end_charpos
,
3994 &next_check_charpos
,
3997 /* Correct the face for charsets different from ASCII. Do it
3998 for the multibyte case only. The face returned above is
3999 suitable for unibyte text if IT->string is unibyte. */
4000 if (STRING_MULTIBYTE (it
->string
))
4002 struct text_pos pos1
= string_pos (charpos
, it
->string
);
4003 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos1
);
4005 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
4007 c
= string_char_and_length (p
, &len
);
4008 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, charpos
, it
->string
);
4013 struct text_pos pos
;
4015 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
4016 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
4019 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
4020 pos
= it
->current
.pos
;
4025 DEC_TEXT_POS (pos
, it
->multibyte_p
);
4028 if (it
->what
== IT_COMPOSITION
)
4030 /* For composition, we must check the position after
4032 pos
.charpos
+= it
->cmp_it
.nchars
;
4033 pos
.bytepos
+= it
->len
;
4036 INC_TEXT_POS (pos
, it
->multibyte_p
);
4043 /* With bidi iteration, the character before the current
4044 in the visual order cannot be found by simple
4045 iteration, because "reverse" reordering is not
4046 supported. Instead, we need to use the move_it_*
4047 family of functions. */
4048 /* Ignore face changes before the first visible
4049 character on this display line. */
4050 if (it
->current_x
<= it
->first_visible_x
)
4052 SAVE_IT (it_copy
, *it
, it_copy_data
);
4053 /* Implementation note: Since move_it_in_display_line
4054 works in the iterator geometry, and thinks the first
4055 character is always the leftmost, even in R2L lines,
4056 we don't need to distinguish between the R2L and L2R
4058 move_it_in_display_line (&it_copy
, ZV
,
4059 it_copy
.current_x
- 1, MOVE_TO_X
);
4060 pos
= it_copy
.current
.pos
;
4061 RESTORE_IT (it
, it
, it_copy_data
);
4065 /* Set charpos to the buffer position of the character
4066 that comes after IT's current position in the visual
4068 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
4072 bidi_move_to_visually_next (&it_copy
.bidi_it
);
4075 it_copy
.bidi_it
.charpos
, it_copy
.bidi_it
.bytepos
);
4078 eassert (BEGV
<= CHARPOS (pos
) && CHARPOS (pos
) <= ZV
);
4080 /* Determine face for CHARSET_ASCII, or unibyte. */
4081 face_id
= face_at_buffer_position (it
->w
,
4083 it
->region_beg_charpos
,
4084 it
->region_end_charpos
,
4085 &next_check_charpos
,
4088 /* Correct the face for charsets different from ASCII. Do it
4089 for the multibyte case only. The face returned above is
4090 suitable for unibyte text if current_buffer is unibyte. */
4091 if (it
->multibyte_p
)
4093 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
4094 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
4095 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
4104 /***********************************************************************
4106 ***********************************************************************/
4108 /* Set up iterator IT from invisible properties at its current
4109 position. Called from handle_stop. */
4111 static enum prop_handled
4112 handle_invisible_prop (struct it
*it
)
4114 enum prop_handled handled
= HANDLED_NORMALLY
;
4118 if (STRINGP (it
->string
))
4120 Lisp_Object end_charpos
, limit
, charpos
;
4122 /* Get the value of the invisible text property at the
4123 current position. Value will be nil if there is no such
4125 charpos
= make_number (IT_STRING_CHARPOS (*it
));
4126 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
4127 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4129 if (invis_p
&& IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
4131 /* Record whether we have to display an ellipsis for the
4133 int display_ellipsis_p
= (invis_p
== 2);
4134 ptrdiff_t len
, endpos
;
4136 handled
= HANDLED_RECOMPUTE_PROPS
;
4138 /* Get the position at which the next visible text can be
4139 found in IT->string, if any. */
4140 endpos
= len
= SCHARS (it
->string
);
4141 XSETINT (limit
, len
);
4144 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
4146 if (INTEGERP (end_charpos
))
4148 endpos
= XFASTINT (end_charpos
);
4149 prop
= Fget_text_property (end_charpos
, Qinvisible
, it
->string
);
4150 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4152 display_ellipsis_p
= 1;
4155 while (invis_p
&& endpos
< len
);
4157 if (display_ellipsis_p
)
4162 /* Text at END_CHARPOS is visible. Move IT there. */
4163 struct text_pos old
;
4166 old
= it
->current
.string_pos
;
4167 oldpos
= CHARPOS (old
);
4170 if (it
->bidi_it
.first_elt
4171 && it
->bidi_it
.charpos
< SCHARS (it
->string
))
4172 bidi_paragraph_init (it
->paragraph_embedding
,
4174 /* Bidi-iterate out of the invisible text. */
4177 bidi_move_to_visually_next (&it
->bidi_it
);
4179 while (oldpos
<= it
->bidi_it
.charpos
4180 && it
->bidi_it
.charpos
< endpos
);
4182 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4183 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4184 if (IT_CHARPOS (*it
) >= endpos
)
4185 it
->prev_stop
= endpos
;
4189 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
4190 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
4195 /* The rest of the string is invisible. If this is an
4196 overlay string, proceed with the next overlay string
4197 or whatever comes and return a character from there. */
4198 if (it
->current
.overlay_string_index
>= 0
4199 && !display_ellipsis_p
)
4201 next_overlay_string (it
);
4202 /* Don't check for overlay strings when we just
4203 finished processing them. */
4204 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
4208 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
4209 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
4216 ptrdiff_t newpos
, next_stop
, start_charpos
, tem
;
4217 Lisp_Object pos
, overlay
;
4219 /* First of all, is there invisible text at this position? */
4220 tem
= start_charpos
= IT_CHARPOS (*it
);
4221 pos
= make_number (tem
);
4222 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
4224 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4226 /* If we are on invisible text, skip over it. */
4227 if (invis_p
&& start_charpos
< it
->end_charpos
)
4229 /* Record whether we have to display an ellipsis for the
4231 int display_ellipsis_p
= invis_p
== 2;
4233 handled
= HANDLED_RECOMPUTE_PROPS
;
4235 /* Loop skipping over invisible text. The loop is left at
4236 ZV or with IT on the first char being visible again. */
4239 /* Try to skip some invisible text. Return value is the
4240 position reached which can be equal to where we start
4241 if there is nothing invisible there. This skips both
4242 over invisible text properties and overlays with
4243 invisible property. */
4244 newpos
= skip_invisible (tem
, &next_stop
, ZV
, it
->window
);
4246 /* If we skipped nothing at all we weren't at invisible
4247 text in the first place. If everything to the end of
4248 the buffer was skipped, end the loop. */
4249 if (newpos
== tem
|| newpos
>= ZV
)
4253 /* We skipped some characters but not necessarily
4254 all there are. Check if we ended up on visible
4255 text. Fget_char_property returns the property of
4256 the char before the given position, i.e. if we
4257 get invis_p = 0, this means that the char at
4258 newpos is visible. */
4259 pos
= make_number (newpos
);
4260 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
4261 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4264 /* If we ended up on invisible text, proceed to
4265 skip starting with next_stop. */
4269 /* If there are adjacent invisible texts, don't lose the
4270 second one's ellipsis. */
4272 display_ellipsis_p
= 1;
4276 /* The position newpos is now either ZV or on visible text. */
4279 ptrdiff_t bpos
= CHAR_TO_BYTE (newpos
);
4281 bpos
== ZV_BYTE
|| FETCH_BYTE (bpos
) == '\n';
4283 newpos
<= BEGV
|| FETCH_BYTE (bpos
- 1) == '\n';
4285 /* If the invisible text ends on a newline or on a
4286 character after a newline, we can avoid the costly,
4287 character by character, bidi iteration to NEWPOS, and
4288 instead simply reseat the iterator there. That's
4289 because all bidi reordering information is tossed at
4290 the newline. This is a big win for modes that hide
4291 complete lines, like Outline, Org, etc. */
4292 if (on_newline
|| after_newline
)
4294 struct text_pos tpos
;
4295 bidi_dir_t pdir
= it
->bidi_it
.paragraph_dir
;
4297 SET_TEXT_POS (tpos
, newpos
, bpos
);
4298 reseat_1 (it
, tpos
, 0);
4299 /* If we reseat on a newline/ZV, we need to prep the
4300 bidi iterator for advancing to the next character
4301 after the newline/EOB, keeping the current paragraph
4302 direction (so that PRODUCE_GLYPHS does TRT wrt
4303 prepending/appending glyphs to a glyph row). */
4306 it
->bidi_it
.first_elt
= 0;
4307 it
->bidi_it
.paragraph_dir
= pdir
;
4308 it
->bidi_it
.ch
= (bpos
== ZV_BYTE
) ? -1 : '\n';
4309 it
->bidi_it
.nchars
= 1;
4310 it
->bidi_it
.ch_len
= 1;
4313 else /* Must use the slow method. */
4315 /* With bidi iteration, the region of invisible text
4316 could start and/or end in the middle of a
4317 non-base embedding level. Therefore, we need to
4318 skip invisible text using the bidi iterator,
4319 starting at IT's current position, until we find
4320 ourselves outside of the invisible text.
4321 Skipping invisible text _after_ bidi iteration
4322 avoids affecting the visual order of the
4323 displayed text when invisible properties are
4324 added or removed. */
4325 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< ZV
)
4327 /* If we were `reseat'ed to a new paragraph,
4328 determine the paragraph base direction. We
4329 need to do it now because
4330 next_element_from_buffer may not have a
4331 chance to do it, if we are going to skip any
4332 text at the beginning, which resets the
4334 bidi_paragraph_init (it
->paragraph_embedding
,
4339 bidi_move_to_visually_next (&it
->bidi_it
);
4341 while (it
->stop_charpos
<= it
->bidi_it
.charpos
4342 && it
->bidi_it
.charpos
< newpos
);
4343 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4344 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4345 /* If we overstepped NEWPOS, record its position in
4346 the iterator, so that we skip invisible text if
4347 later the bidi iteration lands us in the
4348 invisible region again. */
4349 if (IT_CHARPOS (*it
) >= newpos
)
4350 it
->prev_stop
= newpos
;
4355 IT_CHARPOS (*it
) = newpos
;
4356 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
4359 /* If there are before-strings at the start of invisible
4360 text, and the text is invisible because of a text
4361 property, arrange to show before-strings because 20.x did
4362 it that way. (If the text is invisible because of an
4363 overlay property instead of a text property, this is
4364 already handled in the overlay code.) */
4366 && get_overlay_strings (it
, it
->stop_charpos
))
4368 handled
= HANDLED_RECOMPUTE_PROPS
;
4369 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
4371 else if (display_ellipsis_p
)
4373 /* Make sure that the glyphs of the ellipsis will get
4374 correct `charpos' values. If we would not update
4375 it->position here, the glyphs would belong to the
4376 last visible character _before_ the invisible
4377 text, which confuses `set_cursor_from_row'.
4379 We use the last invisible position instead of the
4380 first because this way the cursor is always drawn on
4381 the first "." of the ellipsis, whenever PT is inside
4382 the invisible text. Otherwise the cursor would be
4383 placed _after_ the ellipsis when the point is after the
4384 first invisible character. */
4385 if (!STRINGP (it
->object
))
4387 it
->position
.charpos
= newpos
- 1;
4388 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
4391 /* Let the ellipsis display before
4392 considering any properties of the following char.
4393 Fixes jasonr@gnu.org 01 Oct 07 bug. */
4394 handled
= HANDLED_RETURN
;
4403 /* Make iterator IT return `...' next.
4404 Replaces LEN characters from buffer. */
4407 setup_for_ellipsis (struct it
*it
, int len
)
4409 /* Use the display table definition for `...'. Invalid glyphs
4410 will be handled by the method returning elements from dpvec. */
4411 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
4413 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
4414 it
->dpvec
= v
->contents
;
4415 it
->dpend
= v
->contents
+ v
->header
.size
;
4419 /* Default `...'. */
4420 it
->dpvec
= default_invis_vector
;
4421 it
->dpend
= default_invis_vector
+ 3;
4424 it
->dpvec_char_len
= len
;
4425 it
->current
.dpvec_index
= 0;
4426 it
->dpvec_face_id
= -1;
4428 /* Remember the current face id in case glyphs specify faces.
4429 IT's face is restored in set_iterator_to_next.
4430 saved_face_id was set to preceding char's face in handle_stop. */
4431 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
4432 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
4434 it
->method
= GET_FROM_DISPLAY_VECTOR
;
4440 /***********************************************************************
4442 ***********************************************************************/
4444 /* Set up iterator IT from `display' property at its current position.
4445 Called from handle_stop.
4446 We return HANDLED_RETURN if some part of the display property
4447 overrides the display of the buffer text itself.
4448 Otherwise we return HANDLED_NORMALLY. */
4450 static enum prop_handled
4451 handle_display_prop (struct it
*it
)
4453 Lisp_Object propval
, object
, overlay
;
4454 struct text_pos
*position
;
4456 /* Nonzero if some property replaces the display of the text itself. */
4457 int display_replaced_p
= 0;
4459 if (STRINGP (it
->string
))
4461 object
= it
->string
;
4462 position
= &it
->current
.string_pos
;
4463 bufpos
= CHARPOS (it
->current
.pos
);
4467 XSETWINDOW (object
, it
->w
);
4468 position
= &it
->current
.pos
;
4469 bufpos
= CHARPOS (*position
);
4472 /* Reset those iterator values set from display property values. */
4473 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
4474 it
->space_width
= Qnil
;
4475 it
->font_height
= Qnil
;
4478 /* We don't support recursive `display' properties, i.e. string
4479 values that have a string `display' property, that have a string
4480 `display' property etc. */
4481 if (!it
->string_from_display_prop_p
)
4482 it
->area
= TEXT_AREA
;
4484 propval
= get_char_property_and_overlay (make_number (position
->charpos
),
4485 Qdisplay
, object
, &overlay
);
4487 return HANDLED_NORMALLY
;
4488 /* Now OVERLAY is the overlay that gave us this property, or nil
4489 if it was a text property. */
4491 if (!STRINGP (it
->string
))
4492 object
= it
->w
->buffer
;
4494 display_replaced_p
= handle_display_spec (it
, propval
, object
, overlay
,
4496 FRAME_WINDOW_P (it
->f
));
4498 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
4501 /* Subroutine of handle_display_prop. Returns non-zero if the display
4502 specification in SPEC is a replacing specification, i.e. it would
4503 replace the text covered by `display' property with something else,
4504 such as an image or a display string. If SPEC includes any kind or
4505 `(space ...) specification, the value is 2; this is used by
4506 compute_display_string_pos, which see.
4508 See handle_single_display_spec for documentation of arguments.
4509 frame_window_p is non-zero if the window being redisplayed is on a
4510 GUI frame; this argument is used only if IT is NULL, see below.
4512 IT can be NULL, if this is called by the bidi reordering code
4513 through compute_display_string_pos, which see. In that case, this
4514 function only examines SPEC, but does not otherwise "handle" it, in
4515 the sense that it doesn't set up members of IT from the display
4518 handle_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4519 Lisp_Object overlay
, struct text_pos
*position
,
4520 ptrdiff_t bufpos
, int frame_window_p
)
4522 int replacing_p
= 0;
4526 /* Simple specifications. */
4527 && !EQ (XCAR (spec
), Qimage
)
4528 #ifdef HAVE_XWIDGETS
4529 && !EQ (XCAR (spec
), Qxwidget
)
4531 && !EQ (XCAR (spec
), Qspace
)
4532 && !EQ (XCAR (spec
), Qwhen
)
4533 && !EQ (XCAR (spec
), Qslice
)
4534 && !EQ (XCAR (spec
), Qspace_width
)
4535 && !EQ (XCAR (spec
), Qheight
)
4536 && !EQ (XCAR (spec
), Qraise
)
4537 /* Marginal area specifications. */
4538 && !(CONSP (XCAR (spec
)) && EQ (XCAR (XCAR (spec
)), Qmargin
))
4539 && !EQ (XCAR (spec
), Qleft_fringe
)
4540 && !EQ (XCAR (spec
), Qright_fringe
)
4541 && !NILP (XCAR (spec
)))
4543 for (; CONSP (spec
); spec
= XCDR (spec
))
4545 if ((rv
= handle_single_display_spec (it
, XCAR (spec
), object
,
4546 overlay
, position
, bufpos
,
4547 replacing_p
, frame_window_p
)))
4550 /* If some text in a string is replaced, `position' no
4551 longer points to the position of `object'. */
4552 if (!it
|| STRINGP (object
))
4557 else if (VECTORP (spec
))
4560 for (i
= 0; i
< ASIZE (spec
); ++i
)
4561 if ((rv
= handle_single_display_spec (it
, AREF (spec
, i
), object
,
4562 overlay
, position
, bufpos
,
4563 replacing_p
, frame_window_p
)))
4566 /* If some text in a string is replaced, `position' no
4567 longer points to the position of `object'. */
4568 if (!it
|| STRINGP (object
))
4574 if ((rv
= handle_single_display_spec (it
, spec
, object
, overlay
,
4575 position
, bufpos
, 0,
4583 /* Value is the position of the end of the `display' property starting
4584 at START_POS in OBJECT. */
4586 static struct text_pos
4587 display_prop_end (struct it
*it
, Lisp_Object object
, struct text_pos start_pos
)
4590 struct text_pos end_pos
;
4592 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
4593 Qdisplay
, object
, Qnil
);
4594 CHARPOS (end_pos
) = XFASTINT (end
);
4595 if (STRINGP (object
))
4596 compute_string_pos (&end_pos
, start_pos
, it
->string
);
4598 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
4604 /* Set up IT from a single `display' property specification SPEC. OBJECT
4605 is the object in which the `display' property was found. *POSITION
4606 is the position in OBJECT at which the `display' property was found.
4607 BUFPOS is the buffer position of OBJECT (different from POSITION if
4608 OBJECT is not a buffer). DISPLAY_REPLACED_P non-zero means that we
4609 previously saw a display specification which already replaced text
4610 display with something else, for example an image; we ignore such
4611 properties after the first one has been processed.
4613 OVERLAY is the overlay this `display' property came from,
4614 or nil if it was a text property.
4616 If SPEC is a `space' or `image' specification, and in some other
4617 cases too, set *POSITION to the position where the `display'
4620 If IT is NULL, only examine the property specification in SPEC, but
4621 don't set up IT. In that case, FRAME_WINDOW_P non-zero means SPEC
4622 is intended to be displayed in a window on a GUI frame.
4624 Value is non-zero if something was found which replaces the display
4625 of buffer or string text. */
4628 handle_single_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4629 Lisp_Object overlay
, struct text_pos
*position
,
4630 ptrdiff_t bufpos
, int display_replaced_p
,
4634 Lisp_Object location
, value
;
4635 struct text_pos start_pos
= *position
;
4638 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
4639 If the result is non-nil, use VALUE instead of SPEC. */
4641 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4650 if (!NILP (form
) && !EQ (form
, Qt
))
4652 ptrdiff_t count
= SPECPDL_INDEX ();
4653 struct gcpro gcpro1
;
4655 /* Bind `object' to the object having the `display' property, a
4656 buffer or string. Bind `position' to the position in the
4657 object where the property was found, and `buffer-position'
4658 to the current position in the buffer. */
4661 XSETBUFFER (object
, current_buffer
);
4662 specbind (Qobject
, object
);
4663 specbind (Qposition
, make_number (CHARPOS (*position
)));
4664 specbind (Qbuffer_position
, make_number (bufpos
));
4666 form
= safe_eval (form
);
4668 unbind_to (count
, Qnil
);
4674 /* Handle `(height HEIGHT)' specifications. */
4676 && EQ (XCAR (spec
), Qheight
)
4677 && CONSP (XCDR (spec
)))
4681 if (!FRAME_WINDOW_P (it
->f
))
4684 it
->font_height
= XCAR (XCDR (spec
));
4685 if (!NILP (it
->font_height
))
4687 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4688 int new_height
= -1;
4690 if (CONSP (it
->font_height
)
4691 && (EQ (XCAR (it
->font_height
), Qplus
)
4692 || EQ (XCAR (it
->font_height
), Qminus
))
4693 && CONSP (XCDR (it
->font_height
))
4694 && RANGED_INTEGERP (0, XCAR (XCDR (it
->font_height
)), INT_MAX
))
4696 /* `(+ N)' or `(- N)' where N is an integer. */
4697 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4698 if (EQ (XCAR (it
->font_height
), Qplus
))
4700 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4702 else if (FUNCTIONP (it
->font_height
))
4704 /* Call function with current height as argument.
4705 Value is the new height. */
4707 height
= safe_call1 (it
->font_height
,
4708 face
->lface
[LFACE_HEIGHT_INDEX
]);
4709 if (NUMBERP (height
))
4710 new_height
= XFLOATINT (height
);
4712 else if (NUMBERP (it
->font_height
))
4714 /* Value is a multiple of the canonical char height. */
4717 f
= FACE_FROM_ID (it
->f
,
4718 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4719 new_height
= (XFLOATINT (it
->font_height
)
4720 * XINT (f
->lface
[LFACE_HEIGHT_INDEX
]));
4724 /* Evaluate IT->font_height with `height' bound to the
4725 current specified height to get the new height. */
4726 ptrdiff_t count
= SPECPDL_INDEX ();
4728 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4729 value
= safe_eval (it
->font_height
);
4730 unbind_to (count
, Qnil
);
4732 if (NUMBERP (value
))
4733 new_height
= XFLOATINT (value
);
4737 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4744 /* Handle `(space-width WIDTH)'. */
4746 && EQ (XCAR (spec
), Qspace_width
)
4747 && CONSP (XCDR (spec
)))
4751 if (!FRAME_WINDOW_P (it
->f
))
4754 value
= XCAR (XCDR (spec
));
4755 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4756 it
->space_width
= value
;
4762 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4764 && EQ (XCAR (spec
), Qslice
))
4770 if (!FRAME_WINDOW_P (it
->f
))
4773 if (tem
= XCDR (spec
), CONSP (tem
))
4775 it
->slice
.x
= XCAR (tem
);
4776 if (tem
= XCDR (tem
), CONSP (tem
))
4778 it
->slice
.y
= XCAR (tem
);
4779 if (tem
= XCDR (tem
), CONSP (tem
))
4781 it
->slice
.width
= XCAR (tem
);
4782 if (tem
= XCDR (tem
), CONSP (tem
))
4783 it
->slice
.height
= XCAR (tem
);
4792 /* Handle `(raise FACTOR)'. */
4794 && EQ (XCAR (spec
), Qraise
)
4795 && CONSP (XCDR (spec
)))
4799 if (!FRAME_WINDOW_P (it
->f
))
4802 #ifdef HAVE_WINDOW_SYSTEM
4803 value
= XCAR (XCDR (spec
));
4804 if (NUMBERP (value
))
4806 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4807 it
->voffset
= - (XFLOATINT (value
)
4808 * (FONT_HEIGHT (face
->font
)));
4810 #endif /* HAVE_WINDOW_SYSTEM */
4816 /* Don't handle the other kinds of display specifications
4817 inside a string that we got from a `display' property. */
4818 if (it
&& it
->string_from_display_prop_p
)
4821 /* Characters having this form of property are not displayed, so
4822 we have to find the end of the property. */
4825 start_pos
= *position
;
4826 *position
= display_prop_end (it
, object
, start_pos
);
4830 /* Stop the scan at that end position--we assume that all
4831 text properties change there. */
4833 it
->stop_charpos
= position
->charpos
;
4835 /* Handle `(left-fringe BITMAP [FACE])'
4836 and `(right-fringe BITMAP [FACE])'. */
4838 && (EQ (XCAR (spec
), Qleft_fringe
)
4839 || EQ (XCAR (spec
), Qright_fringe
))
4840 && CONSP (XCDR (spec
)))
4846 if (!FRAME_WINDOW_P (it
->f
))
4847 /* If we return here, POSITION has been advanced
4848 across the text with this property. */
4850 /* Synchronize the bidi iterator with POSITION. This is
4851 needed because we are not going to push the iterator
4852 on behalf of this display property, so there will be
4853 no pop_it call to do this synchronization for us. */
4856 it
->position
= *position
;
4857 iterate_out_of_display_property (it
);
4858 *position
= it
->position
;
4863 else if (!frame_window_p
)
4866 #ifdef HAVE_WINDOW_SYSTEM
4867 value
= XCAR (XCDR (spec
));
4868 if (!SYMBOLP (value
)
4869 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4870 /* If we return here, POSITION has been advanced
4871 across the text with this property. */
4873 if (it
&& it
->bidi_p
)
4875 it
->position
= *position
;
4876 iterate_out_of_display_property (it
);
4877 *position
= it
->position
;
4884 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);;
4886 if (CONSP (XCDR (XCDR (spec
))))
4888 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4889 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4895 /* Save current settings of IT so that we can restore them
4896 when we are finished with the glyph property value. */
4897 push_it (it
, position
);
4899 it
->area
= TEXT_AREA
;
4900 it
->what
= IT_IMAGE
;
4901 it
->image_id
= -1; /* no image */
4902 it
->position
= start_pos
;
4903 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4904 it
->method
= GET_FROM_IMAGE
;
4905 it
->from_overlay
= Qnil
;
4906 it
->face_id
= face_id
;
4907 it
->from_disp_prop_p
= 1;
4909 /* Say that we haven't consumed the characters with
4910 `display' property yet. The call to pop_it in
4911 set_iterator_to_next will clean this up. */
4912 *position
= start_pos
;
4914 if (EQ (XCAR (spec
), Qleft_fringe
))
4916 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4917 it
->left_user_fringe_face_id
= face_id
;
4921 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4922 it
->right_user_fringe_face_id
= face_id
;
4925 #endif /* HAVE_WINDOW_SYSTEM */
4929 /* Prepare to handle `((margin left-margin) ...)',
4930 `((margin right-margin) ...)' and `((margin nil) ...)'
4931 prefixes for display specifications. */
4932 location
= Qunbound
;
4933 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4937 value
= XCDR (spec
);
4939 value
= XCAR (value
);
4942 if (EQ (XCAR (tem
), Qmargin
)
4943 && (tem
= XCDR (tem
),
4944 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4946 || EQ (tem
, Qleft_margin
)
4947 || EQ (tem
, Qright_margin
))))
4951 if (EQ (location
, Qunbound
))
4957 /* After this point, VALUE is the property after any
4958 margin prefix has been stripped. It must be a string,
4959 an image specification, or `(space ...)'.
4961 LOCATION specifies where to display: `left-margin',
4962 `right-margin' or nil. */
4964 valid_p
= (STRINGP (value
)
4965 #ifdef HAVE_WINDOW_SYSTEM
4966 || ((it
? FRAME_WINDOW_P (it
->f
) : frame_window_p
)
4967 && valid_image_p (value
))
4968 #endif /* not HAVE_WINDOW_SYSTEM */
4969 || (CONSP (value
) && EQ (XCAR (value
), Qspace
))
4970 #ifdef HAVE_XWIDGETS
4975 if (valid_p
&& !display_replaced_p
)
4981 /* Callers need to know whether the display spec is any kind
4982 of `(space ...)' spec that is about to affect text-area
4984 if (CONSP (value
) && EQ (XCAR (value
), Qspace
) && NILP (location
))
4989 /* Save current settings of IT so that we can restore them
4990 when we are finished with the glyph property value. */
4991 push_it (it
, position
);
4992 it
->from_overlay
= overlay
;
4993 it
->from_disp_prop_p
= 1;
4995 if (NILP (location
))
4996 it
->area
= TEXT_AREA
;
4997 else if (EQ (location
, Qleft_margin
))
4998 it
->area
= LEFT_MARGIN_AREA
;
5000 it
->area
= RIGHT_MARGIN_AREA
;
5002 if (STRINGP (value
))
5005 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5006 it
->current
.overlay_string_index
= -1;
5007 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5008 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
5009 it
->method
= GET_FROM_STRING
;
5010 it
->stop_charpos
= 0;
5012 it
->base_level_stop
= 0;
5013 it
->string_from_display_prop_p
= 1;
5014 /* Say that we haven't consumed the characters with
5015 `display' property yet. The call to pop_it in
5016 set_iterator_to_next will clean this up. */
5017 if (BUFFERP (object
))
5018 *position
= start_pos
;
5020 /* Force paragraph direction to be that of the parent
5021 object. If the parent object's paragraph direction is
5022 not yet determined, default to L2R. */
5023 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
5024 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5026 it
->paragraph_embedding
= L2R
;
5028 /* Set up the bidi iterator for this display string. */
5031 it
->bidi_it
.string
.lstring
= it
->string
;
5032 it
->bidi_it
.string
.s
= NULL
;
5033 it
->bidi_it
.string
.schars
= it
->end_charpos
;
5034 it
->bidi_it
.string
.bufpos
= bufpos
;
5035 it
->bidi_it
.string
.from_disp_str
= 1;
5036 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5037 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5040 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
5042 it
->method
= GET_FROM_STRETCH
;
5044 *position
= it
->position
= start_pos
;
5045 retval
= 1 + (it
->area
== TEXT_AREA
);
5047 #ifdef HAVE_XWIDGETS
5048 else if (XWIDGETP(value
))
5050 //printf("handle_single_display_spec: im an xwidget!!\n");
5051 it
->what
= IT_XWIDGET
;
5052 it
->method
= GET_FROM_XWIDGET
;
5053 it
->position
= start_pos
;
5054 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
5055 *position
= start_pos
;
5057 it
->xwidget
= lookup_xwidget(value
);
5060 #ifdef HAVE_WINDOW_SYSTEM
5063 it
->what
= IT_IMAGE
;
5064 it
->image_id
= lookup_image (it
->f
, value
);
5065 it
->position
= start_pos
;
5066 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
5067 it
->method
= GET_FROM_IMAGE
;
5069 /* Say that we haven't consumed the characters with
5070 `display' property yet. The call to pop_it in
5071 set_iterator_to_next will clean this up. */
5072 *position
= start_pos
;
5074 #endif /* HAVE_WINDOW_SYSTEM */
5079 /* Invalid property or property not supported. Restore
5080 POSITION to what it was before. */
5081 *position
= start_pos
;
5085 /* Check if PROP is a display property value whose text should be
5086 treated as intangible. OVERLAY is the overlay from which PROP
5087 came, or nil if it came from a text property. CHARPOS and BYTEPOS
5088 specify the buffer position covered by PROP. */
5091 display_prop_intangible_p (Lisp_Object prop
, Lisp_Object overlay
,
5092 ptrdiff_t charpos
, ptrdiff_t bytepos
)
5094 int frame_window_p
= FRAME_WINDOW_P (XFRAME (selected_frame
));
5095 struct text_pos position
;
5097 SET_TEXT_POS (position
, charpos
, bytepos
);
5098 return handle_display_spec (NULL
, prop
, Qnil
, overlay
,
5099 &position
, charpos
, frame_window_p
);
5103 /* Return 1 if PROP is a display sub-property value containing STRING.
5105 Implementation note: this and the following function are really
5106 special cases of handle_display_spec and
5107 handle_single_display_spec, and should ideally use the same code.
5108 Until they do, these two pairs must be consistent and must be
5109 modified in sync. */
5112 single_display_spec_string_p (Lisp_Object prop
, Lisp_Object string
)
5114 if (EQ (string
, prop
))
5117 /* Skip over `when FORM'. */
5118 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
5123 /* Actually, the condition following `when' should be eval'ed,
5124 like handle_single_display_spec does, and we should return
5125 zero if it evaluates to nil. However, this function is
5126 called only when the buffer was already displayed and some
5127 glyph in the glyph matrix was found to come from a display
5128 string. Therefore, the condition was already evaluated, and
5129 the result was non-nil, otherwise the display string wouldn't
5130 have been displayed and we would have never been called for
5131 this property. Thus, we can skip the evaluation and assume
5132 its result is non-nil. */
5137 /* Skip over `margin LOCATION'. */
5138 if (EQ (XCAR (prop
), Qmargin
))
5149 return EQ (prop
, string
) || (CONSP (prop
) && EQ (XCAR (prop
), string
));
5153 /* Return 1 if STRING appears in the `display' property PROP. */
5156 display_prop_string_p (Lisp_Object prop
, Lisp_Object string
)
5159 && !EQ (XCAR (prop
), Qwhen
)
5160 && !(CONSP (XCAR (prop
)) && EQ (Qmargin
, XCAR (XCAR (prop
)))))
5162 /* A list of sub-properties. */
5163 while (CONSP (prop
))
5165 if (single_display_spec_string_p (XCAR (prop
), string
))
5170 else if (VECTORP (prop
))
5172 /* A vector of sub-properties. */
5174 for (i
= 0; i
< ASIZE (prop
); ++i
)
5175 if (single_display_spec_string_p (AREF (prop
, i
), string
))
5179 return single_display_spec_string_p (prop
, string
);
5184 /* Look for STRING in overlays and text properties in the current
5185 buffer, between character positions FROM and TO (excluding TO).
5186 BACK_P non-zero means look back (in this case, TO is supposed to be
5188 Value is the first character position where STRING was found, or
5189 zero if it wasn't found before hitting TO.
5191 This function may only use code that doesn't eval because it is
5192 called asynchronously from note_mouse_highlight. */
5195 string_buffer_position_lim (Lisp_Object string
,
5196 ptrdiff_t from
, ptrdiff_t to
, int back_p
)
5198 Lisp_Object limit
, prop
, pos
;
5201 pos
= make_number (max (from
, BEGV
));
5203 if (!back_p
) /* looking forward */
5205 limit
= make_number (min (to
, ZV
));
5206 while (!found
&& !EQ (pos
, limit
))
5208 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5209 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5212 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
,
5216 else /* looking back */
5218 limit
= make_number (max (to
, BEGV
));
5219 while (!found
&& !EQ (pos
, limit
))
5221 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5222 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5225 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
5230 return found
? XINT (pos
) : 0;
5233 /* Determine which buffer position in current buffer STRING comes from.
5234 AROUND_CHARPOS is an approximate position where it could come from.
5235 Value is the buffer position or 0 if it couldn't be determined.
5237 This function is necessary because we don't record buffer positions
5238 in glyphs generated from strings (to keep struct glyph small).
5239 This function may only use code that doesn't eval because it is
5240 called asynchronously from note_mouse_highlight. */
5243 string_buffer_position (Lisp_Object string
, ptrdiff_t around_charpos
)
5245 const int MAX_DISTANCE
= 1000;
5246 ptrdiff_t found
= string_buffer_position_lim (string
, around_charpos
,
5247 around_charpos
+ MAX_DISTANCE
,
5251 found
= string_buffer_position_lim (string
, around_charpos
,
5252 around_charpos
- MAX_DISTANCE
, 1);
5258 /***********************************************************************
5259 `composition' property
5260 ***********************************************************************/
5262 /* Set up iterator IT from `composition' property at its current
5263 position. Called from handle_stop. */
5265 static enum prop_handled
5266 handle_composition_prop (struct it
*it
)
5268 Lisp_Object prop
, string
;
5269 ptrdiff_t pos
, pos_byte
, start
, end
;
5271 if (STRINGP (it
->string
))
5275 pos
= IT_STRING_CHARPOS (*it
);
5276 pos_byte
= IT_STRING_BYTEPOS (*it
);
5277 string
= it
->string
;
5278 s
= SDATA (string
) + pos_byte
;
5279 it
->c
= STRING_CHAR (s
);
5283 pos
= IT_CHARPOS (*it
);
5284 pos_byte
= IT_BYTEPOS (*it
);
5286 it
->c
= FETCH_CHAR (pos_byte
);
5289 /* If there's a valid composition and point is not inside of the
5290 composition (in the case that the composition is from the current
5291 buffer), draw a glyph composed from the composition components. */
5292 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
5293 && COMPOSITION_VALID_P (start
, end
, prop
)
5294 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
5297 /* As we can't handle this situation (perhaps font-lock added
5298 a new composition), we just return here hoping that next
5299 redisplay will detect this composition much earlier. */
5300 return HANDLED_NORMALLY
;
5303 if (STRINGP (it
->string
))
5304 pos_byte
= string_char_to_byte (it
->string
, start
);
5306 pos_byte
= CHAR_TO_BYTE (start
);
5308 it
->cmp_it
.id
= get_composition_id (start
, pos_byte
, end
- start
,
5311 if (it
->cmp_it
.id
>= 0)
5314 it
->cmp_it
.nchars
= COMPOSITION_LENGTH (prop
);
5315 it
->cmp_it
.nglyphs
= -1;
5319 return HANDLED_NORMALLY
;
5324 /***********************************************************************
5326 ***********************************************************************/
5328 /* The following structure is used to record overlay strings for
5329 later sorting in load_overlay_strings. */
5331 struct overlay_entry
5333 Lisp_Object overlay
;
5340 /* Set up iterator IT from overlay strings at its current position.
5341 Called from handle_stop. */
5343 static enum prop_handled
5344 handle_overlay_change (struct it
*it
)
5346 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
5347 return HANDLED_RECOMPUTE_PROPS
;
5349 return HANDLED_NORMALLY
;
5353 /* Set up the next overlay string for delivery by IT, if there is an
5354 overlay string to deliver. Called by set_iterator_to_next when the
5355 end of the current overlay string is reached. If there are more
5356 overlay strings to display, IT->string and
5357 IT->current.overlay_string_index are set appropriately here.
5358 Otherwise IT->string is set to nil. */
5361 next_overlay_string (struct it
*it
)
5363 ++it
->current
.overlay_string_index
;
5364 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
5366 /* No more overlay strings. Restore IT's settings to what
5367 they were before overlay strings were processed, and
5368 continue to deliver from current_buffer. */
5370 it
->ellipsis_p
= (it
->stack
[it
->sp
- 1].display_ellipsis_p
!= 0);
5373 || (NILP (it
->string
)
5374 && it
->method
== GET_FROM_BUFFER
5375 && it
->stop_charpos
>= BEGV
5376 && it
->stop_charpos
<= it
->end_charpos
));
5377 it
->current
.overlay_string_index
= -1;
5378 it
->n_overlay_strings
= 0;
5379 it
->overlay_strings_charpos
= -1;
5380 /* If there's an empty display string on the stack, pop the
5381 stack, to resync the bidi iterator with IT's position. Such
5382 empty strings are pushed onto the stack in
5383 get_overlay_strings_1. */
5384 if (it
->sp
> 0 && STRINGP (it
->string
) && !SCHARS (it
->string
))
5387 /* If we're at the end of the buffer, record that we have
5388 processed the overlay strings there already, so that
5389 next_element_from_buffer doesn't try it again. */
5390 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
5391 it
->overlay_strings_at_end_processed_p
= 1;
5395 /* There are more overlay strings to process. If
5396 IT->current.overlay_string_index has advanced to a position
5397 where we must load IT->overlay_strings with more strings, do
5398 it. We must load at the IT->overlay_strings_charpos where
5399 IT->n_overlay_strings was originally computed; when invisible
5400 text is present, this might not be IT_CHARPOS (Bug#7016). */
5401 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
5403 if (it
->current
.overlay_string_index
&& i
== 0)
5404 load_overlay_strings (it
, it
->overlay_strings_charpos
);
5406 /* Initialize IT to deliver display elements from the overlay
5408 it
->string
= it
->overlay_strings
[i
];
5409 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5410 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
5411 it
->method
= GET_FROM_STRING
;
5412 it
->stop_charpos
= 0;
5413 it
->end_charpos
= SCHARS (it
->string
);
5414 if (it
->cmp_it
.stop_pos
>= 0)
5415 it
->cmp_it
.stop_pos
= 0;
5417 it
->base_level_stop
= 0;
5419 /* Set up the bidi iterator for this overlay string. */
5422 it
->bidi_it
.string
.lstring
= it
->string
;
5423 it
->bidi_it
.string
.s
= NULL
;
5424 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5425 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
5426 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5427 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5428 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5436 /* Compare two overlay_entry structures E1 and E2. Used as a
5437 comparison function for qsort in load_overlay_strings. Overlay
5438 strings for the same position are sorted so that
5440 1. All after-strings come in front of before-strings, except
5441 when they come from the same overlay.
5443 2. Within after-strings, strings are sorted so that overlay strings
5444 from overlays with higher priorities come first.
5446 2. Within before-strings, strings are sorted so that overlay
5447 strings from overlays with higher priorities come last.
5449 Value is analogous to strcmp. */
5453 compare_overlay_entries (const void *e1
, const void *e2
)
5455 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
5456 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
5459 if (entry1
->after_string_p
!= entry2
->after_string_p
)
5461 /* Let after-strings appear in front of before-strings if
5462 they come from different overlays. */
5463 if (EQ (entry1
->overlay
, entry2
->overlay
))
5464 result
= entry1
->after_string_p
? 1 : -1;
5466 result
= entry1
->after_string_p
? -1 : 1;
5468 else if (entry1
->priority
!= entry2
->priority
)
5470 if (entry1
->after_string_p
)
5471 /* After-strings sorted in order of decreasing priority. */
5472 result
= entry2
->priority
< entry1
->priority
? -1 : 1;
5474 /* Before-strings sorted in order of increasing priority. */
5475 result
= entry1
->priority
< entry2
->priority
? -1 : 1;
5484 /* Load the vector IT->overlay_strings with overlay strings from IT's
5485 current buffer position, or from CHARPOS if that is > 0. Set
5486 IT->n_overlays to the total number of overlay strings found.
5488 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
5489 a time. On entry into load_overlay_strings,
5490 IT->current.overlay_string_index gives the number of overlay
5491 strings that have already been loaded by previous calls to this
5494 IT->add_overlay_start contains an additional overlay start
5495 position to consider for taking overlay strings from, if non-zero.
5496 This position comes into play when the overlay has an `invisible'
5497 property, and both before and after-strings. When we've skipped to
5498 the end of the overlay, because of its `invisible' property, we
5499 nevertheless want its before-string to appear.
5500 IT->add_overlay_start will contain the overlay start position
5503 Overlay strings are sorted so that after-string strings come in
5504 front of before-string strings. Within before and after-strings,
5505 strings are sorted by overlay priority. See also function
5506 compare_overlay_entries. */
5509 load_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5511 Lisp_Object overlay
, window
, str
, invisible
;
5512 struct Lisp_Overlay
*ov
;
5513 ptrdiff_t start
, end
;
5514 ptrdiff_t size
= 20;
5515 ptrdiff_t n
= 0, i
, j
;
5517 struct overlay_entry
*entries
= alloca (size
* sizeof *entries
);
5521 charpos
= IT_CHARPOS (*it
);
5523 /* Append the overlay string STRING of overlay OVERLAY to vector
5524 `entries' which has size `size' and currently contains `n'
5525 elements. AFTER_P non-zero means STRING is an after-string of
5527 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
5530 Lisp_Object priority; \
5534 struct overlay_entry *old = entries; \
5535 SAFE_NALLOCA (entries, 2, size); \
5536 memcpy (entries, old, size * sizeof *entries); \
5540 entries[n].string = (STRING); \
5541 entries[n].overlay = (OVERLAY); \
5542 priority = Foverlay_get ((OVERLAY), Qpriority); \
5543 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
5544 entries[n].after_string_p = (AFTER_P); \
5549 /* Process overlay before the overlay center. */
5550 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
5552 XSETMISC (overlay
, ov
);
5553 eassert (OVERLAYP (overlay
));
5554 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5555 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5560 /* Skip this overlay if it doesn't start or end at IT's current
5562 if (end
!= charpos
&& start
!= charpos
)
5565 /* Skip this overlay if it doesn't apply to IT->w. */
5566 window
= Foverlay_get (overlay
, Qwindow
);
5567 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5570 /* If the text ``under'' the overlay is invisible, both before-
5571 and after-strings from this overlay are visible; start and
5572 end position are indistinguishable. */
5573 invisible
= Foverlay_get (overlay
, Qinvisible
);
5574 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5576 /* If overlay has a non-empty before-string, record it. */
5577 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5578 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5580 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5582 /* If overlay has a non-empty after-string, record it. */
5583 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5584 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5586 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5589 /* Process overlays after the overlay center. */
5590 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
5592 XSETMISC (overlay
, ov
);
5593 eassert (OVERLAYP (overlay
));
5594 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5595 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5597 if (start
> charpos
)
5600 /* Skip this overlay if it doesn't start or end at IT's current
5602 if (end
!= charpos
&& start
!= charpos
)
5605 /* Skip this overlay if it doesn't apply to IT->w. */
5606 window
= Foverlay_get (overlay
, Qwindow
);
5607 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5610 /* If the text ``under'' the overlay is invisible, it has a zero
5611 dimension, and both before- and after-strings apply. */
5612 invisible
= Foverlay_get (overlay
, Qinvisible
);
5613 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5615 /* If overlay has a non-empty before-string, record it. */
5616 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5617 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5619 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5621 /* If overlay has a non-empty after-string, record it. */
5622 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5623 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5625 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5628 #undef RECORD_OVERLAY_STRING
5632 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
5634 /* Record number of overlay strings, and where we computed it. */
5635 it
->n_overlay_strings
= n
;
5636 it
->overlay_strings_charpos
= charpos
;
5638 /* IT->current.overlay_string_index is the number of overlay strings
5639 that have already been consumed by IT. Copy some of the
5640 remaining overlay strings to IT->overlay_strings. */
5642 j
= it
->current
.overlay_string_index
;
5643 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
5645 it
->overlay_strings
[i
] = entries
[j
].string
;
5646 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
5654 /* Get the first chunk of overlay strings at IT's current buffer
5655 position, or at CHARPOS if that is > 0. Value is non-zero if at
5656 least one overlay string was found. */
5659 get_overlay_strings_1 (struct it
*it
, ptrdiff_t charpos
, int compute_stop_p
)
5661 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5662 process. This fills IT->overlay_strings with strings, and sets
5663 IT->n_overlay_strings to the total number of strings to process.
5664 IT->pos.overlay_string_index has to be set temporarily to zero
5665 because load_overlay_strings needs this; it must be set to -1
5666 when no overlay strings are found because a zero value would
5667 indicate a position in the first overlay string. */
5668 it
->current
.overlay_string_index
= 0;
5669 load_overlay_strings (it
, charpos
);
5671 /* If we found overlay strings, set up IT to deliver display
5672 elements from the first one. Otherwise set up IT to deliver
5673 from current_buffer. */
5674 if (it
->n_overlay_strings
)
5676 /* Make sure we know settings in current_buffer, so that we can
5677 restore meaningful values when we're done with the overlay
5680 compute_stop_pos (it
);
5681 eassert (it
->face_id
>= 0);
5683 /* Save IT's settings. They are restored after all overlay
5684 strings have been processed. */
5685 eassert (!compute_stop_p
|| it
->sp
== 0);
5687 /* When called from handle_stop, there might be an empty display
5688 string loaded. In that case, don't bother saving it. But
5689 don't use this optimization with the bidi iterator, since we
5690 need the corresponding pop_it call to resync the bidi
5691 iterator's position with IT's position, after we are done
5692 with the overlay strings. (The corresponding call to pop_it
5693 in case of an empty display string is in
5694 next_overlay_string.) */
5696 && STRINGP (it
->string
) && !SCHARS (it
->string
)))
5699 /* Set up IT to deliver display elements from the first overlay
5701 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5702 it
->string
= it
->overlay_strings
[0];
5703 it
->from_overlay
= Qnil
;
5704 it
->stop_charpos
= 0;
5705 eassert (STRINGP (it
->string
));
5706 it
->end_charpos
= SCHARS (it
->string
);
5708 it
->base_level_stop
= 0;
5709 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5710 it
->method
= GET_FROM_STRING
;
5711 it
->from_disp_prop_p
= 0;
5713 /* Force paragraph direction to be that of the parent
5715 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
5716 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5718 it
->paragraph_embedding
= L2R
;
5720 /* Set up the bidi iterator for this overlay string. */
5723 ptrdiff_t pos
= (charpos
> 0 ? charpos
: IT_CHARPOS (*it
));
5725 it
->bidi_it
.string
.lstring
= it
->string
;
5726 it
->bidi_it
.string
.s
= NULL
;
5727 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5728 it
->bidi_it
.string
.bufpos
= pos
;
5729 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5730 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5731 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5736 it
->current
.overlay_string_index
= -1;
5741 get_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5744 it
->method
= GET_FROM_BUFFER
;
5746 (void) get_overlay_strings_1 (it
, charpos
, 1);
5750 /* Value is non-zero if we found at least one overlay string. */
5751 return STRINGP (it
->string
);
5756 /***********************************************************************
5757 Saving and restoring state
5758 ***********************************************************************/
5760 /* Save current settings of IT on IT->stack. Called, for example,
5761 before setting up IT for an overlay string, to be able to restore
5762 IT's settings to what they were after the overlay string has been
5763 processed. If POSITION is non-NULL, it is the position to save on
5764 the stack instead of IT->position. */
5767 push_it (struct it
*it
, struct text_pos
*position
)
5769 struct iterator_stack_entry
*p
;
5771 eassert (it
->sp
< IT_STACK_SIZE
);
5772 p
= it
->stack
+ it
->sp
;
5774 p
->stop_charpos
= it
->stop_charpos
;
5775 p
->prev_stop
= it
->prev_stop
;
5776 p
->base_level_stop
= it
->base_level_stop
;
5777 p
->cmp_it
= it
->cmp_it
;
5778 eassert (it
->face_id
>= 0);
5779 p
->face_id
= it
->face_id
;
5780 p
->string
= it
->string
;
5781 p
->method
= it
->method
;
5782 p
->from_overlay
= it
->from_overlay
;
5785 case GET_FROM_IMAGE
:
5786 p
->u
.image
.object
= it
->object
;
5787 p
->u
.image
.image_id
= it
->image_id
;
5788 p
->u
.image
.slice
= it
->slice
;
5790 case GET_FROM_STRETCH
:
5791 p
->u
.stretch
.object
= it
->object
;
5793 #ifdef HAVE_XWIDGETS
5794 case GET_FROM_XWIDGET
:
5795 p
->u
.xwidget
.object
= it
->object
;
5799 p
->position
= position
? *position
: it
->position
;
5800 p
->current
= it
->current
;
5801 p
->end_charpos
= it
->end_charpos
;
5802 p
->string_nchars
= it
->string_nchars
;
5804 p
->multibyte_p
= it
->multibyte_p
;
5805 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
5806 p
->space_width
= it
->space_width
;
5807 p
->font_height
= it
->font_height
;
5808 p
->voffset
= it
->voffset
;
5809 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5810 p
->string_from_prefix_prop_p
= it
->string_from_prefix_prop_p
;
5811 p
->display_ellipsis_p
= 0;
5812 p
->line_wrap
= it
->line_wrap
;
5813 p
->bidi_p
= it
->bidi_p
;
5814 p
->paragraph_embedding
= it
->paragraph_embedding
;
5815 p
->from_disp_prop_p
= it
->from_disp_prop_p
;
5818 /* Save the state of the bidi iterator as well. */
5820 bidi_push_it (&it
->bidi_it
);
5824 iterate_out_of_display_property (struct it
*it
)
5826 int buffer_p
= !STRINGP (it
->string
);
5827 ptrdiff_t eob
= (buffer_p
? ZV
: it
->end_charpos
);
5828 ptrdiff_t bob
= (buffer_p
? BEGV
: 0);
5830 eassert (eob
>= CHARPOS (it
->position
) && CHARPOS (it
->position
) >= bob
);
5832 /* Maybe initialize paragraph direction. If we are at the beginning
5833 of a new paragraph, next_element_from_buffer may not have a
5834 chance to do that. */
5835 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< eob
)
5836 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
5837 /* prev_stop can be zero, so check against BEGV as well. */
5838 while (it
->bidi_it
.charpos
>= bob
5839 && it
->prev_stop
<= it
->bidi_it
.charpos
5840 && it
->bidi_it
.charpos
< CHARPOS (it
->position
)
5841 && it
->bidi_it
.charpos
< eob
)
5842 bidi_move_to_visually_next (&it
->bidi_it
);
5843 /* Record the stop_pos we just crossed, for when we cross it
5845 if (it
->bidi_it
.charpos
> CHARPOS (it
->position
))
5846 it
->prev_stop
= CHARPOS (it
->position
);
5847 /* If we ended up not where pop_it put us, resync IT's
5848 positional members with the bidi iterator. */
5849 if (it
->bidi_it
.charpos
!= CHARPOS (it
->position
))
5850 SET_TEXT_POS (it
->position
, it
->bidi_it
.charpos
, it
->bidi_it
.bytepos
);
5852 it
->current
.pos
= it
->position
;
5854 it
->current
.string_pos
= it
->position
;
5857 /* Restore IT's settings from IT->stack. Called, for example, when no
5858 more overlay strings must be processed, and we return to delivering
5859 display elements from a buffer, or when the end of a string from a
5860 `display' property is reached and we return to delivering display
5861 elements from an overlay string, or from a buffer. */
5864 pop_it (struct it
*it
)
5866 struct iterator_stack_entry
*p
;
5867 int from_display_prop
= it
->from_disp_prop_p
;
5869 eassert (it
->sp
> 0);
5871 p
= it
->stack
+ it
->sp
;
5872 it
->stop_charpos
= p
->stop_charpos
;
5873 it
->prev_stop
= p
->prev_stop
;
5874 it
->base_level_stop
= p
->base_level_stop
;
5875 it
->cmp_it
= p
->cmp_it
;
5876 it
->face_id
= p
->face_id
;
5877 it
->current
= p
->current
;
5878 it
->position
= p
->position
;
5879 it
->string
= p
->string
;
5880 it
->from_overlay
= p
->from_overlay
;
5881 if (NILP (it
->string
))
5882 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5883 it
->method
= p
->method
;
5886 case GET_FROM_IMAGE
:
5887 it
->image_id
= p
->u
.image
.image_id
;
5888 it
->object
= p
->u
.image
.object
;
5889 it
->slice
= p
->u
.image
.slice
;
5891 #ifdef HAVE_XWIDGETS
5892 case GET_FROM_XWIDGET
:
5893 it
->object
= p
->u
.xwidget
.object
;
5896 case GET_FROM_STRETCH
:
5897 it
->object
= p
->u
.stretch
.object
;
5899 case GET_FROM_BUFFER
:
5900 it
->object
= it
->w
->buffer
;
5902 case GET_FROM_STRING
:
5903 it
->object
= it
->string
;
5905 case GET_FROM_DISPLAY_VECTOR
:
5907 it
->method
= GET_FROM_C_STRING
;
5908 else if (STRINGP (it
->string
))
5909 it
->method
= GET_FROM_STRING
;
5912 it
->method
= GET_FROM_BUFFER
;
5913 it
->object
= it
->w
->buffer
;
5916 it
->end_charpos
= p
->end_charpos
;
5917 it
->string_nchars
= p
->string_nchars
;
5919 it
->multibyte_p
= p
->multibyte_p
;
5920 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
5921 it
->space_width
= p
->space_width
;
5922 it
->font_height
= p
->font_height
;
5923 it
->voffset
= p
->voffset
;
5924 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5925 it
->string_from_prefix_prop_p
= p
->string_from_prefix_prop_p
;
5926 it
->line_wrap
= p
->line_wrap
;
5927 it
->bidi_p
= p
->bidi_p
;
5928 it
->paragraph_embedding
= p
->paragraph_embedding
;
5929 it
->from_disp_prop_p
= p
->from_disp_prop_p
;
5932 bidi_pop_it (&it
->bidi_it
);
5933 /* Bidi-iterate until we get out of the portion of text, if any,
5934 covered by a `display' text property or by an overlay with
5935 `display' property. (We cannot just jump there, because the
5936 internal coherency of the bidi iterator state can not be
5937 preserved across such jumps.) We also must determine the
5938 paragraph base direction if the overlay we just processed is
5939 at the beginning of a new paragraph. */
5940 if (from_display_prop
5941 && (it
->method
== GET_FROM_BUFFER
|| it
->method
== GET_FROM_STRING
))
5942 iterate_out_of_display_property (it
);
5944 eassert ((BUFFERP (it
->object
)
5945 && IT_CHARPOS (*it
) == it
->bidi_it
.charpos
5946 && IT_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
5947 || (STRINGP (it
->object
)
5948 && IT_STRING_CHARPOS (*it
) == it
->bidi_it
.charpos
5949 && IT_STRING_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
5950 || (CONSP (it
->object
) && it
->method
== GET_FROM_STRETCH
));
5956 /***********************************************************************
5958 ***********************************************************************/
5960 /* Set IT's current position to the previous line start. */
5963 back_to_previous_line_start (struct it
*it
)
5965 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
5966 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
5970 /* Move IT to the next line start.
5972 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5973 we skipped over part of the text (as opposed to moving the iterator
5974 continuously over the text). Otherwise, don't change the value
5977 If BIDI_IT_PREV is non-NULL, store into it the state of the bidi
5978 iterator on the newline, if it was found.
5980 Newlines may come from buffer text, overlay strings, or strings
5981 displayed via the `display' property. That's the reason we can't
5982 simply use find_next_newline_no_quit.
5984 Note that this function may not skip over invisible text that is so
5985 because of text properties and immediately follows a newline. If
5986 it would, function reseat_at_next_visible_line_start, when called
5987 from set_iterator_to_next, would effectively make invisible
5988 characters following a newline part of the wrong glyph row, which
5989 leads to wrong cursor motion. */
5992 forward_to_next_line_start (struct it
*it
, int *skipped_p
,
5993 struct bidi_it
*bidi_it_prev
)
5995 ptrdiff_t old_selective
;
5996 int newline_found_p
, n
;
5997 const int MAX_NEWLINE_DISTANCE
= 500;
5999 /* If already on a newline, just consume it to avoid unintended
6000 skipping over invisible text below. */
6001 if (it
->what
== IT_CHARACTER
6003 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
6005 if (it
->bidi_p
&& bidi_it_prev
)
6006 *bidi_it_prev
= it
->bidi_it
;
6007 set_iterator_to_next (it
, 0);
6012 /* Don't handle selective display in the following. It's (a)
6013 unnecessary because it's done by the caller, and (b) leads to an
6014 infinite recursion because next_element_from_ellipsis indirectly
6015 calls this function. */
6016 old_selective
= it
->selective
;
6019 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
6020 from buffer text. */
6021 for (n
= newline_found_p
= 0;
6022 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
6023 n
+= STRINGP (it
->string
) ? 0 : 1)
6025 if (!get_next_display_element (it
))
6027 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
6028 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
6029 *bidi_it_prev
= it
->bidi_it
;
6030 set_iterator_to_next (it
, 0);
6033 /* If we didn't find a newline near enough, see if we can use a
6035 if (!newline_found_p
)
6037 ptrdiff_t start
= IT_CHARPOS (*it
);
6038 ptrdiff_t limit
= find_next_newline_no_quit (start
, 1);
6041 eassert (!STRINGP (it
->string
));
6043 /* If there isn't any `display' property in sight, and no
6044 overlays, we can just use the position of the newline in
6046 if (it
->stop_charpos
>= limit
6047 || ((pos
= Fnext_single_property_change (make_number (start
),
6049 make_number (limit
)),
6051 && next_overlay_change (start
) == ZV
))
6055 IT_CHARPOS (*it
) = limit
;
6056 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
6060 struct bidi_it bprev
;
6062 /* Help bidi.c avoid expensive searches for display
6063 properties and overlays, by telling it that there are
6064 none up to `limit'. */
6065 if (it
->bidi_it
.disp_pos
< limit
)
6067 it
->bidi_it
.disp_pos
= limit
;
6068 it
->bidi_it
.disp_prop
= 0;
6071 bprev
= it
->bidi_it
;
6072 bidi_move_to_visually_next (&it
->bidi_it
);
6073 } while (it
->bidi_it
.charpos
!= limit
);
6074 IT_CHARPOS (*it
) = limit
;
6075 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6077 *bidi_it_prev
= bprev
;
6079 *skipped_p
= newline_found_p
= 1;
6083 while (get_next_display_element (it
)
6084 && !newline_found_p
)
6086 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
6087 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
6088 *bidi_it_prev
= it
->bidi_it
;
6089 set_iterator_to_next (it
, 0);
6094 it
->selective
= old_selective
;
6095 return newline_found_p
;
6099 /* Set IT's current position to the previous visible line start. Skip
6100 invisible text that is so either due to text properties or due to
6101 selective display. Caution: this does not change IT->current_x and
6105 back_to_previous_visible_line_start (struct it
*it
)
6107 while (IT_CHARPOS (*it
) > BEGV
)
6109 back_to_previous_line_start (it
);
6111 if (IT_CHARPOS (*it
) <= BEGV
)
6114 /* If selective > 0, then lines indented more than its value are
6116 if (it
->selective
> 0
6117 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6121 /* Check the newline before point for invisibility. */
6124 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
6125 Qinvisible
, it
->window
);
6126 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
6130 if (IT_CHARPOS (*it
) <= BEGV
)
6135 void *it2data
= NULL
;
6138 Lisp_Object val
, overlay
;
6140 SAVE_IT (it2
, *it
, it2data
);
6142 /* If newline is part of a composition, continue from start of composition */
6143 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
6144 && beg
< IT_CHARPOS (*it
))
6147 /* If newline is replaced by a display property, find start of overlay
6148 or interval and continue search from that point. */
6149 pos
= --IT_CHARPOS (it2
);
6152 bidi_unshelve_cache (NULL
, 0);
6153 it2
.string_from_display_prop_p
= 0;
6154 it2
.from_disp_prop_p
= 0;
6155 if (handle_display_prop (&it2
) == HANDLED_RETURN
6156 && !NILP (val
= get_char_property_and_overlay
6157 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
6158 && (OVERLAYP (overlay
)
6159 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
6160 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
6162 RESTORE_IT (it
, it
, it2data
);
6166 /* Newline is not replaced by anything -- so we are done. */
6167 RESTORE_IT (it
, it
, it2data
);
6173 IT_CHARPOS (*it
) = beg
;
6174 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
6178 it
->continuation_lines_width
= 0;
6180 eassert (IT_CHARPOS (*it
) >= BEGV
);
6181 eassert (IT_CHARPOS (*it
) == BEGV
6182 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6187 /* Reseat iterator IT at the previous visible line start. Skip
6188 invisible text that is so either due to text properties or due to
6189 selective display. At the end, update IT's overlay information,
6190 face information etc. */
6193 reseat_at_previous_visible_line_start (struct it
*it
)
6195 back_to_previous_visible_line_start (it
);
6196 reseat (it
, it
->current
.pos
, 1);
6201 /* Reseat iterator IT on the next visible line start in the current
6202 buffer. ON_NEWLINE_P non-zero means position IT on the newline
6203 preceding the line start. Skip over invisible text that is so
6204 because of selective display. Compute faces, overlays etc at the
6205 new position. Note that this function does not skip over text that
6206 is invisible because of text properties. */
6209 reseat_at_next_visible_line_start (struct it
*it
, int on_newline_p
)
6211 int newline_found_p
, skipped_p
= 0;
6212 struct bidi_it bidi_it_prev
;
6214 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6216 /* Skip over lines that are invisible because they are indented
6217 more than the value of IT->selective. */
6218 if (it
->selective
> 0)
6219 while (IT_CHARPOS (*it
) < ZV
6220 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6223 eassert (IT_BYTEPOS (*it
) == BEGV
6224 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6226 forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6229 /* Position on the newline if that's what's requested. */
6230 if (on_newline_p
&& newline_found_p
)
6232 if (STRINGP (it
->string
))
6234 if (IT_STRING_CHARPOS (*it
) > 0)
6238 --IT_STRING_CHARPOS (*it
);
6239 --IT_STRING_BYTEPOS (*it
);
6243 /* We need to restore the bidi iterator to the state
6244 it had on the newline, and resync the IT's
6245 position with that. */
6246 it
->bidi_it
= bidi_it_prev
;
6247 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6248 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6252 else if (IT_CHARPOS (*it
) > BEGV
)
6261 /* We need to restore the bidi iterator to the state it
6262 had on the newline and resync IT with that. */
6263 it
->bidi_it
= bidi_it_prev
;
6264 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6265 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6267 reseat (it
, it
->current
.pos
, 0);
6271 reseat (it
, it
->current
.pos
, 0);
6278 /***********************************************************************
6279 Changing an iterator's position
6280 ***********************************************************************/
6282 /* Change IT's current position to POS in current_buffer. If FORCE_P
6283 is non-zero, always check for text properties at the new position.
6284 Otherwise, text properties are only looked up if POS >=
6285 IT->check_charpos of a property. */
6288 reseat (struct it
*it
, struct text_pos pos
, int force_p
)
6290 ptrdiff_t original_pos
= IT_CHARPOS (*it
);
6292 reseat_1 (it
, pos
, 0);
6294 /* Determine where to check text properties. Avoid doing it
6295 where possible because text property lookup is very expensive. */
6297 || CHARPOS (pos
) > it
->stop_charpos
6298 || CHARPOS (pos
) < original_pos
)
6302 /* For bidi iteration, we need to prime prev_stop and
6303 base_level_stop with our best estimations. */
6304 /* Implementation note: Of course, POS is not necessarily a
6305 stop position, so assigning prev_pos to it is a lie; we
6306 should have called compute_stop_backwards. However, if
6307 the current buffer does not include any R2L characters,
6308 that call would be a waste of cycles, because the
6309 iterator will never move back, and thus never cross this
6310 "fake" stop position. So we delay that backward search
6311 until the time we really need it, in next_element_from_buffer. */
6312 if (CHARPOS (pos
) != it
->prev_stop
)
6313 it
->prev_stop
= CHARPOS (pos
);
6314 if (CHARPOS (pos
) < it
->base_level_stop
)
6315 it
->base_level_stop
= 0; /* meaning it's unknown */
6321 it
->prev_stop
= it
->base_level_stop
= 0;
6330 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
6331 IT->stop_pos to POS, also. */
6334 reseat_1 (struct it
*it
, struct text_pos pos
, int set_stop_p
)
6336 /* Don't call this function when scanning a C string. */
6337 eassert (it
->s
== NULL
);
6339 /* POS must be a reasonable value. */
6340 eassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
6342 it
->current
.pos
= it
->position
= pos
;
6343 it
->end_charpos
= ZV
;
6345 it
->current
.dpvec_index
= -1;
6346 it
->current
.overlay_string_index
= -1;
6347 IT_STRING_CHARPOS (*it
) = -1;
6348 IT_STRING_BYTEPOS (*it
) = -1;
6350 it
->method
= GET_FROM_BUFFER
;
6351 it
->object
= it
->w
->buffer
;
6352 it
->area
= TEXT_AREA
;
6353 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
6355 it
->string_from_display_prop_p
= 0;
6356 it
->string_from_prefix_prop_p
= 0;
6358 it
->from_disp_prop_p
= 0;
6359 it
->face_before_selective_p
= 0;
6362 bidi_init_it (IT_CHARPOS (*it
), IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6364 bidi_unshelve_cache (NULL
, 0);
6365 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6366 it
->bidi_it
.string
.s
= NULL
;
6367 it
->bidi_it
.string
.lstring
= Qnil
;
6368 it
->bidi_it
.string
.bufpos
= 0;
6369 it
->bidi_it
.string
.unibyte
= 0;
6374 it
->stop_charpos
= CHARPOS (pos
);
6375 it
->base_level_stop
= CHARPOS (pos
);
6377 /* This make the information stored in it->cmp_it invalidate. */
6382 /* Set up IT for displaying a string, starting at CHARPOS in window W.
6383 If S is non-null, it is a C string to iterate over. Otherwise,
6384 STRING gives a Lisp string to iterate over.
6386 If PRECISION > 0, don't return more then PRECISION number of
6387 characters from the string.
6389 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
6390 characters have been returned. FIELD_WIDTH < 0 means an infinite
6393 MULTIBYTE = 0 means disable processing of multibyte characters,
6394 MULTIBYTE > 0 means enable it,
6395 MULTIBYTE < 0 means use IT->multibyte_p.
6397 IT must be initialized via a prior call to init_iterator before
6398 calling this function. */
6401 reseat_to_string (struct it
*it
, const char *s
, Lisp_Object string
,
6402 ptrdiff_t charpos
, ptrdiff_t precision
, int field_width
,
6405 /* No region in strings. */
6406 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
6408 /* No text property checks performed by default, but see below. */
6409 it
->stop_charpos
= -1;
6411 /* Set iterator position and end position. */
6412 memset (&it
->current
, 0, sizeof it
->current
);
6413 it
->current
.overlay_string_index
= -1;
6414 it
->current
.dpvec_index
= -1;
6415 eassert (charpos
>= 0);
6417 /* If STRING is specified, use its multibyteness, otherwise use the
6418 setting of MULTIBYTE, if specified. */
6420 it
->multibyte_p
= multibyte
> 0;
6422 /* Bidirectional reordering of strings is controlled by the default
6423 value of bidi-display-reordering. Don't try to reorder while
6424 loading loadup.el, as the necessary character property tables are
6425 not yet available. */
6428 && !NILP (BVAR (&buffer_defaults
, bidi_display_reordering
));
6432 eassert (STRINGP (string
));
6433 it
->string
= string
;
6435 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
6436 it
->method
= GET_FROM_STRING
;
6437 it
->current
.string_pos
= string_pos (charpos
, string
);
6441 it
->bidi_it
.string
.lstring
= string
;
6442 it
->bidi_it
.string
.s
= NULL
;
6443 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6444 it
->bidi_it
.string
.bufpos
= 0;
6445 it
->bidi_it
.string
.from_disp_str
= 0;
6446 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6447 bidi_init_it (charpos
, IT_STRING_BYTEPOS (*it
),
6448 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
6453 it
->s
= (const unsigned char *) s
;
6456 /* Note that we use IT->current.pos, not it->current.string_pos,
6457 for displaying C strings. */
6458 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
6459 if (it
->multibyte_p
)
6461 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
6462 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
6466 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
6467 it
->end_charpos
= it
->string_nchars
= strlen (s
);
6472 it
->bidi_it
.string
.lstring
= Qnil
;
6473 it
->bidi_it
.string
.s
= (const unsigned char *) s
;
6474 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6475 it
->bidi_it
.string
.bufpos
= 0;
6476 it
->bidi_it
.string
.from_disp_str
= 0;
6477 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6478 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6481 it
->method
= GET_FROM_C_STRING
;
6484 /* PRECISION > 0 means don't return more than PRECISION characters
6486 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
6488 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
6490 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6493 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
6494 characters have been returned. FIELD_WIDTH == 0 means don't pad,
6495 FIELD_WIDTH < 0 means infinite field width. This is useful for
6496 padding with `-' at the end of a mode line. */
6497 if (field_width
< 0)
6498 field_width
= INFINITY
;
6499 /* Implementation note: We deliberately don't enlarge
6500 it->bidi_it.string.schars here to fit it->end_charpos, because
6501 the bidi iterator cannot produce characters out of thin air. */
6502 if (field_width
> it
->end_charpos
- charpos
)
6503 it
->end_charpos
= charpos
+ field_width
;
6505 /* Use the standard display table for displaying strings. */
6506 if (DISP_TABLE_P (Vstandard_display_table
))
6507 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
6509 it
->stop_charpos
= charpos
;
6510 it
->prev_stop
= charpos
;
6511 it
->base_level_stop
= 0;
6514 it
->bidi_it
.first_elt
= 1;
6515 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6516 it
->bidi_it
.disp_pos
= -1;
6518 if (s
== NULL
&& it
->multibyte_p
)
6520 ptrdiff_t endpos
= SCHARS (it
->string
);
6521 if (endpos
> it
->end_charpos
)
6522 endpos
= it
->end_charpos
;
6523 composition_compute_stop_pos (&it
->cmp_it
, charpos
, -1, endpos
,
6531 /***********************************************************************
6533 ***********************************************************************/
6535 /* Map enum it_method value to corresponding next_element_from_* function. */
6537 static int (* get_next_element
[NUM_IT_METHODS
]) (struct it
*it
) =
6539 next_element_from_buffer
,
6540 next_element_from_display_vector
,
6541 next_element_from_string
,
6542 next_element_from_c_string
,
6543 next_element_from_image
,
6544 next_element_from_stretch
6545 #ifdef HAVE_XWIDGETS
6546 ,next_element_from_xwidget
6550 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
6553 /* Return 1 iff a character at CHARPOS (and BYTEPOS) is composed
6554 (possibly with the following characters). */
6556 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS,END_CHARPOS) \
6557 ((IT)->cmp_it.id >= 0 \
6558 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
6559 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
6560 END_CHARPOS, (IT)->w, \
6561 FACE_FROM_ID ((IT)->f, (IT)->face_id), \
6565 /* Lookup the char-table Vglyphless_char_display for character C (-1
6566 if we want information for no-font case), and return the display
6567 method symbol. By side-effect, update it->what and
6568 it->glyphless_method. This function is called from
6569 get_next_display_element for each character element, and from
6570 x_produce_glyphs when no suitable font was found. */
6573 lookup_glyphless_char_display (int c
, struct it
*it
)
6575 Lisp_Object glyphless_method
= Qnil
;
6577 if (CHAR_TABLE_P (Vglyphless_char_display
)
6578 && CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
)) >= 1)
6582 glyphless_method
= CHAR_TABLE_REF (Vglyphless_char_display
, c
);
6583 if (CONSP (glyphless_method
))
6584 glyphless_method
= FRAME_WINDOW_P (it
->f
)
6585 ? XCAR (glyphless_method
)
6586 : XCDR (glyphless_method
);
6589 glyphless_method
= XCHAR_TABLE (Vglyphless_char_display
)->extras
[0];
6593 if (NILP (glyphless_method
))
6596 /* The default is to display the character by a proper font. */
6598 /* The default for the no-font case is to display an empty box. */
6599 glyphless_method
= Qempty_box
;
6601 if (EQ (glyphless_method
, Qzero_width
))
6604 return glyphless_method
;
6605 /* This method can't be used for the no-font case. */
6606 glyphless_method
= Qempty_box
;
6608 if (EQ (glyphless_method
, Qthin_space
))
6609 it
->glyphless_method
= GLYPHLESS_DISPLAY_THIN_SPACE
;
6610 else if (EQ (glyphless_method
, Qempty_box
))
6611 it
->glyphless_method
= GLYPHLESS_DISPLAY_EMPTY_BOX
;
6612 else if (EQ (glyphless_method
, Qhex_code
))
6613 it
->glyphless_method
= GLYPHLESS_DISPLAY_HEX_CODE
;
6614 else if (STRINGP (glyphless_method
))
6615 it
->glyphless_method
= GLYPHLESS_DISPLAY_ACRONYM
;
6618 /* Invalid value. We use the default method. */
6619 glyphless_method
= Qnil
;
6622 it
->what
= IT_GLYPHLESS
;
6623 return glyphless_method
;
6626 /* Load IT's display element fields with information about the next
6627 display element from the current position of IT. Value is zero if
6628 end of buffer (or C string) is reached. */
6630 static struct frame
*last_escape_glyph_frame
= NULL
;
6631 static int last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
6632 static int last_escape_glyph_merged_face_id
= 0;
6634 struct frame
*last_glyphless_glyph_frame
= NULL
;
6635 int last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
6636 int last_glyphless_glyph_merged_face_id
= 0;
6639 get_next_display_element (struct it
*it
)
6641 /* Non-zero means that we found a display element. Zero means that
6642 we hit the end of what we iterate over. Performance note: the
6643 function pointer `method' used here turns out to be faster than
6644 using a sequence of if-statements. */
6648 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6650 if (it
->what
== IT_CHARACTER
)
6652 /* UAX#9, L4: "A character is depicted by a mirrored glyph if
6653 and only if (a) the resolved directionality of that character
6655 /* FIXME: Do we need an exception for characters from display
6657 if (it
->bidi_p
&& it
->bidi_it
.type
== STRONG_R
)
6658 it
->c
= bidi_mirror_char (it
->c
);
6659 /* Map via display table or translate control characters.
6660 IT->c, IT->len etc. have been set to the next character by
6661 the function call above. If we have a display table, and it
6662 contains an entry for IT->c, translate it. Don't do this if
6663 IT->c itself comes from a display table, otherwise we could
6664 end up in an infinite recursion. (An alternative could be to
6665 count the recursion depth of this function and signal an
6666 error when a certain maximum depth is reached.) Is it worth
6668 if (success_p
&& it
->dpvec
== NULL
)
6671 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
6672 int nonascii_space_p
= 0;
6673 int nonascii_hyphen_p
= 0;
6674 int c
= it
->c
; /* This is the character to display. */
6676 if (! it
->multibyte_p
&& ! ASCII_CHAR_P (c
))
6678 eassert (SINGLE_BYTE_CHAR_P (c
));
6679 if (unibyte_display_via_language_environment
)
6681 c
= DECODE_CHAR (unibyte
, c
);
6683 c
= BYTE8_TO_CHAR (it
->c
);
6686 c
= BYTE8_TO_CHAR (it
->c
);
6690 && (dv
= DISP_CHAR_VECTOR (it
->dp
, c
),
6693 struct Lisp_Vector
*v
= XVECTOR (dv
);
6695 /* Return the first character from the display table
6696 entry, if not empty. If empty, don't display the
6697 current character. */
6700 it
->dpvec_char_len
= it
->len
;
6701 it
->dpvec
= v
->contents
;
6702 it
->dpend
= v
->contents
+ v
->header
.size
;
6703 it
->current
.dpvec_index
= 0;
6704 it
->dpvec_face_id
= -1;
6705 it
->saved_face_id
= it
->face_id
;
6706 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6711 set_iterator_to_next (it
, 0);
6716 if (! NILP (lookup_glyphless_char_display (c
, it
)))
6718 if (it
->what
== IT_GLYPHLESS
)
6720 /* Don't display this character. */
6721 set_iterator_to_next (it
, 0);
6725 /* If `nobreak-char-display' is non-nil, we display
6726 non-ASCII spaces and hyphens specially. */
6727 if (! ASCII_CHAR_P (c
) && ! NILP (Vnobreak_char_display
))
6730 nonascii_space_p
= 1;
6731 else if (c
== 0xAD || c
== 0x2010 || c
== 0x2011)
6732 nonascii_hyphen_p
= 1;
6735 /* Translate control characters into `\003' or `^C' form.
6736 Control characters coming from a display table entry are
6737 currently not translated because we use IT->dpvec to hold
6738 the translation. This could easily be changed but I
6739 don't believe that it is worth doing.
6741 The characters handled by `nobreak-char-display' must be
6744 Non-printable characters and raw-byte characters are also
6745 translated to octal form. */
6746 if (((c
< ' ' || c
== 127) /* ASCII control chars */
6747 ? (it
->area
!= TEXT_AREA
6748 /* In mode line, treat \n, \t like other crl chars. */
6751 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
6752 || (c
!= '\n' && c
!= '\t'))
6754 || nonascii_hyphen_p
6756 || ! CHAR_PRINTABLE_P (c
))))
6758 /* C is a control character, non-ASCII space/hyphen,
6759 raw-byte, or a non-printable character which must be
6760 displayed either as '\003' or as `^C' where the '\\'
6761 and '^' can be defined in the display table. Fill
6762 IT->ctl_chars with glyphs for what we have to
6763 display. Then, set IT->dpvec to these glyphs. */
6770 /* Handle control characters with ^. */
6772 if (ASCII_CHAR_P (c
) && it
->ctl_arrow_p
)
6776 g
= '^'; /* default glyph for Control */
6777 /* Set IT->ctl_chars[0] to the glyph for `^'. */
6779 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
6781 g
= GLYPH_CODE_CHAR (gc
);
6782 lface_id
= GLYPH_CODE_FACE (gc
);
6786 face_id
= merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
);
6788 else if (it
->f
== last_escape_glyph_frame
6789 && it
->face_id
== last_escape_glyph_face_id
)
6791 face_id
= last_escape_glyph_merged_face_id
;
6795 /* Merge the escape-glyph face into the current face. */
6796 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
6798 last_escape_glyph_frame
= it
->f
;
6799 last_escape_glyph_face_id
= it
->face_id
;
6800 last_escape_glyph_merged_face_id
= face_id
;
6803 XSETINT (it
->ctl_chars
[0], g
);
6804 XSETINT (it
->ctl_chars
[1], c
^ 0100);
6806 goto display_control
;
6809 /* Handle non-ascii space in the mode where it only gets
6812 if (nonascii_space_p
&& EQ (Vnobreak_char_display
, Qt
))
6814 /* Merge `nobreak-space' into the current face. */
6815 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
6817 XSETINT (it
->ctl_chars
[0], ' ');
6819 goto display_control
;
6822 /* Handle sequences that start with the "escape glyph". */
6824 /* the default escape glyph is \. */
6825 escape_glyph
= '\\';
6828 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
6830 escape_glyph
= GLYPH_CODE_CHAR (gc
);
6831 lface_id
= GLYPH_CODE_FACE (gc
);
6835 /* The display table specified a face.
6836 Merge it into face_id and also into escape_glyph. */
6837 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6840 else if (it
->f
== last_escape_glyph_frame
6841 && it
->face_id
== last_escape_glyph_face_id
)
6843 face_id
= last_escape_glyph_merged_face_id
;
6847 /* Merge the escape-glyph face into the current face. */
6848 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
6850 last_escape_glyph_frame
= it
->f
;
6851 last_escape_glyph_face_id
= it
->face_id
;
6852 last_escape_glyph_merged_face_id
= face_id
;
6855 /* Draw non-ASCII hyphen with just highlighting: */
6857 if (nonascii_hyphen_p
&& EQ (Vnobreak_char_display
, Qt
))
6859 XSETINT (it
->ctl_chars
[0], '-');
6861 goto display_control
;
6864 /* Draw non-ASCII space/hyphen with escape glyph: */
6866 if (nonascii_space_p
|| nonascii_hyphen_p
)
6868 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6869 XSETINT (it
->ctl_chars
[1], nonascii_space_p
? ' ' : '-');
6871 goto display_control
;
6878 if (CHAR_BYTE8_P (c
))
6879 /* Display \200 instead of \17777600. */
6880 c
= CHAR_TO_BYTE8 (c
);
6881 len
= sprintf (str
, "%03o", c
);
6883 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6884 for (i
= 0; i
< len
; i
++)
6885 XSETINT (it
->ctl_chars
[i
+ 1], str
[i
]);
6890 /* Set up IT->dpvec and return first character from it. */
6891 it
->dpvec_char_len
= it
->len
;
6892 it
->dpvec
= it
->ctl_chars
;
6893 it
->dpend
= it
->dpvec
+ ctl_len
;
6894 it
->current
.dpvec_index
= 0;
6895 it
->dpvec_face_id
= face_id
;
6896 it
->saved_face_id
= it
->face_id
;
6897 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6901 it
->char_to_display
= c
;
6905 it
->char_to_display
= it
->c
;
6909 /* Adjust face id for a multibyte character. There are no multibyte
6910 character in unibyte text. */
6911 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
6914 && FRAME_WINDOW_P (it
->f
))
6916 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
6918 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
6920 /* Automatic composition with glyph-string. */
6921 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
6923 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
6927 ptrdiff_t pos
= (it
->s
? -1
6928 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
6929 : IT_CHARPOS (*it
));
6932 if (it
->what
== IT_CHARACTER
)
6933 c
= it
->char_to_display
;
6936 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
6940 for (i
= 0; i
< cmp
->glyph_len
; i
++)
6941 /* TAB in a composition means display glyphs with
6942 padding space on the left or right. */
6943 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
6946 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, pos
, it
->string
);
6951 /* Is this character the last one of a run of characters with
6952 box? If yes, set IT->end_of_box_run_p to 1. */
6956 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
6958 int face_id
= underlying_face_id (it
);
6959 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
6963 if (face
->box
== FACE_NO_BOX
)
6965 /* If the box comes from face properties in a
6966 display string, check faces in that string. */
6967 int string_face_id
= face_after_it_pos (it
);
6968 it
->end_of_box_run_p
6969 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
6972 /* Otherwise, the box comes from the underlying face.
6973 If this is the last string character displayed, check
6974 the next buffer location. */
6975 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
6976 && (it
->current
.overlay_string_index
6977 == it
->n_overlay_strings
- 1))
6981 struct text_pos pos
= it
->current
.pos
;
6982 INC_TEXT_POS (pos
, it
->multibyte_p
);
6984 next_face_id
= face_at_buffer_position
6985 (it
->w
, CHARPOS (pos
), it
->region_beg_charpos
,
6986 it
->region_end_charpos
, &ignore
,
6987 (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
), 0,
6989 it
->end_of_box_run_p
6990 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
6997 int face_id
= face_after_it_pos (it
);
6998 it
->end_of_box_run_p
6999 = (face_id
!= it
->face_id
7000 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
7003 /* If we reached the end of the object we've been iterating (e.g., a
7004 display string or an overlay string), and there's something on
7005 IT->stack, proceed with what's on the stack. It doesn't make
7006 sense to return zero if there's unprocessed stuff on the stack,
7007 because otherwise that stuff will never be displayed. */
7008 if (!success_p
&& it
->sp
> 0)
7010 set_iterator_to_next (it
, 0);
7011 success_p
= get_next_display_element (it
);
7014 /* Value is 0 if end of buffer or string reached. */
7019 /* Move IT to the next display element.
7021 RESEAT_P non-zero means if called on a newline in buffer text,
7022 skip to the next visible line start.
7024 Functions get_next_display_element and set_iterator_to_next are
7025 separate because I find this arrangement easier to handle than a
7026 get_next_display_element function that also increments IT's
7027 position. The way it is we can first look at an iterator's current
7028 display element, decide whether it fits on a line, and if it does,
7029 increment the iterator position. The other way around we probably
7030 would either need a flag indicating whether the iterator has to be
7031 incremented the next time, or we would have to implement a
7032 decrement position function which would not be easy to write. */
7035 set_iterator_to_next (struct it
*it
, int reseat_p
)
7037 /* Reset flags indicating start and end of a sequence of characters
7038 with box. Reset them at the start of this function because
7039 moving the iterator to a new position might set them. */
7040 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
7044 case GET_FROM_BUFFER
:
7045 /* The current display element of IT is a character from
7046 current_buffer. Advance in the buffer, and maybe skip over
7047 invisible lines that are so because of selective display. */
7048 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
7049 reseat_at_next_visible_line_start (it
, 0);
7050 else if (it
->cmp_it
.id
>= 0)
7052 /* We are currently getting glyphs from a composition. */
7057 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7058 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7059 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7061 it
->cmp_it
.from
= it
->cmp_it
.to
;
7066 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7068 it
->end_charpos
, Qnil
);
7071 else if (! it
->cmp_it
.reversed_p
)
7073 /* Composition created while scanning forward. */
7074 /* Update IT's char/byte positions to point to the first
7075 character of the next grapheme cluster, or to the
7076 character visually after the current composition. */
7077 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7078 bidi_move_to_visually_next (&it
->bidi_it
);
7079 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7080 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7082 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7084 /* Proceed to the next grapheme cluster. */
7085 it
->cmp_it
.from
= it
->cmp_it
.to
;
7089 /* No more grapheme clusters in this composition.
7090 Find the next stop position. */
7091 ptrdiff_t stop
= it
->end_charpos
;
7092 if (it
->bidi_it
.scan_dir
< 0)
7093 /* Now we are scanning backward and don't know
7096 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7097 IT_BYTEPOS (*it
), stop
, Qnil
);
7102 /* Composition created while scanning backward. */
7103 /* Update IT's char/byte positions to point to the last
7104 character of the previous grapheme cluster, or the
7105 character visually after the current composition. */
7106 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7107 bidi_move_to_visually_next (&it
->bidi_it
);
7108 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7109 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7110 if (it
->cmp_it
.from
> 0)
7112 /* Proceed to the previous grapheme cluster. */
7113 it
->cmp_it
.to
= it
->cmp_it
.from
;
7117 /* No more grapheme clusters in this composition.
7118 Find the next stop position. */
7119 ptrdiff_t stop
= it
->end_charpos
;
7120 if (it
->bidi_it
.scan_dir
< 0)
7121 /* Now we are scanning backward and don't know
7124 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7125 IT_BYTEPOS (*it
), stop
, Qnil
);
7131 eassert (it
->len
!= 0);
7135 IT_BYTEPOS (*it
) += it
->len
;
7136 IT_CHARPOS (*it
) += 1;
7140 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7141 /* If this is a new paragraph, determine its base
7142 direction (a.k.a. its base embedding level). */
7143 if (it
->bidi_it
.new_paragraph
)
7144 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
7145 bidi_move_to_visually_next (&it
->bidi_it
);
7146 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7147 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7148 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7150 /* As the scan direction was changed, we must
7151 re-compute the stop position for composition. */
7152 ptrdiff_t stop
= it
->end_charpos
;
7153 if (it
->bidi_it
.scan_dir
< 0)
7155 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7156 IT_BYTEPOS (*it
), stop
, Qnil
);
7159 eassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
7163 case GET_FROM_C_STRING
:
7164 /* Current display element of IT is from a C string. */
7166 /* If the string position is beyond string's end, it means
7167 next_element_from_c_string is padding the string with
7168 blanks, in which case we bypass the bidi iterator,
7169 because it cannot deal with such virtual characters. */
7170 || IT_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7172 IT_BYTEPOS (*it
) += it
->len
;
7173 IT_CHARPOS (*it
) += 1;
7177 bidi_move_to_visually_next (&it
->bidi_it
);
7178 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7179 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7183 case GET_FROM_DISPLAY_VECTOR
:
7184 /* Current display element of IT is from a display table entry.
7185 Advance in the display table definition. Reset it to null if
7186 end reached, and continue with characters from buffers/
7188 ++it
->current
.dpvec_index
;
7190 /* Restore face of the iterator to what they were before the
7191 display vector entry (these entries may contain faces). */
7192 it
->face_id
= it
->saved_face_id
;
7194 if (it
->dpvec
+ it
->current
.dpvec_index
>= it
->dpend
)
7196 int recheck_faces
= it
->ellipsis_p
;
7199 it
->method
= GET_FROM_C_STRING
;
7200 else if (STRINGP (it
->string
))
7201 it
->method
= GET_FROM_STRING
;
7204 it
->method
= GET_FROM_BUFFER
;
7205 it
->object
= it
->w
->buffer
;
7209 it
->current
.dpvec_index
= -1;
7211 /* Skip over characters which were displayed via IT->dpvec. */
7212 if (it
->dpvec_char_len
< 0)
7213 reseat_at_next_visible_line_start (it
, 1);
7214 else if (it
->dpvec_char_len
> 0)
7216 if (it
->method
== GET_FROM_STRING
7217 && it
->n_overlay_strings
> 0)
7218 it
->ignore_overlay_strings_at_pos_p
= 1;
7219 it
->len
= it
->dpvec_char_len
;
7220 set_iterator_to_next (it
, reseat_p
);
7223 /* Maybe recheck faces after display vector */
7225 it
->stop_charpos
= IT_CHARPOS (*it
);
7229 case GET_FROM_STRING
:
7230 /* Current display element is a character from a Lisp string. */
7231 eassert (it
->s
== NULL
&& STRINGP (it
->string
));
7232 /* Don't advance past string end. These conditions are true
7233 when set_iterator_to_next is called at the end of
7234 get_next_display_element, in which case the Lisp string is
7235 already exhausted, and all we want is pop the iterator
7237 if (it
->current
.overlay_string_index
>= 0)
7239 /* This is an overlay string, so there's no padding with
7240 spaces, and the number of characters in the string is
7241 where the string ends. */
7242 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7243 goto consider_string_end
;
7247 /* Not an overlay string. There could be padding, so test
7248 against it->end_charpos . */
7249 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7250 goto consider_string_end
;
7252 if (it
->cmp_it
.id
>= 0)
7258 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7259 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7260 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7261 it
->cmp_it
.from
= it
->cmp_it
.to
;
7265 composition_compute_stop_pos (&it
->cmp_it
,
7266 IT_STRING_CHARPOS (*it
),
7267 IT_STRING_BYTEPOS (*it
),
7268 it
->end_charpos
, it
->string
);
7271 else if (! it
->cmp_it
.reversed_p
)
7273 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7274 bidi_move_to_visually_next (&it
->bidi_it
);
7275 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7276 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7278 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7279 it
->cmp_it
.from
= it
->cmp_it
.to
;
7282 ptrdiff_t stop
= it
->end_charpos
;
7283 if (it
->bidi_it
.scan_dir
< 0)
7285 composition_compute_stop_pos (&it
->cmp_it
,
7286 IT_STRING_CHARPOS (*it
),
7287 IT_STRING_BYTEPOS (*it
), stop
,
7293 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7294 bidi_move_to_visually_next (&it
->bidi_it
);
7295 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7296 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7297 if (it
->cmp_it
.from
> 0)
7298 it
->cmp_it
.to
= it
->cmp_it
.from
;
7301 ptrdiff_t stop
= it
->end_charpos
;
7302 if (it
->bidi_it
.scan_dir
< 0)
7304 composition_compute_stop_pos (&it
->cmp_it
,
7305 IT_STRING_CHARPOS (*it
),
7306 IT_STRING_BYTEPOS (*it
), stop
,
7314 /* If the string position is beyond string's end, it
7315 means next_element_from_string is padding the string
7316 with blanks, in which case we bypass the bidi
7317 iterator, because it cannot deal with such virtual
7319 || IT_STRING_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7321 IT_STRING_BYTEPOS (*it
) += it
->len
;
7322 IT_STRING_CHARPOS (*it
) += 1;
7326 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7328 bidi_move_to_visually_next (&it
->bidi_it
);
7329 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7330 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7331 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7333 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 consider_string_end
:
7347 if (it
->current
.overlay_string_index
>= 0)
7349 /* IT->string is an overlay string. Advance to the
7350 next, if there is one. */
7351 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7354 next_overlay_string (it
);
7356 setup_for_ellipsis (it
, 0);
7361 /* IT->string is not an overlay string. If we reached
7362 its end, and there is something on IT->stack, proceed
7363 with what is on the stack. This can be either another
7364 string, this time an overlay string, or a buffer. */
7365 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
7369 if (it
->method
== GET_FROM_STRING
)
7370 goto consider_string_end
;
7375 case GET_FROM_IMAGE
:
7376 case GET_FROM_STRETCH
:
7377 #ifdef HAVE_XWIDGETS
7378 case GET_FROM_XWIDGET
:
7380 /* The position etc with which we have to proceed are on
7381 the stack. The position may be at the end of a string,
7382 if the `display' property takes up the whole string. */
7383 eassert (it
->sp
> 0);
7385 if (it
->method
== GET_FROM_STRING
)
7386 goto consider_string_end
;
7390 /* There are no other methods defined, so this should be a bug. */
7394 eassert (it
->method
!= GET_FROM_STRING
7395 || (STRINGP (it
->string
)
7396 && IT_STRING_CHARPOS (*it
) >= 0));
7399 /* Load IT's display element fields with information about the next
7400 display element which comes from a display table entry or from the
7401 result of translating a control character to one of the forms `^C'
7404 IT->dpvec holds the glyphs to return as characters.
7405 IT->saved_face_id holds the face id before the display vector--it
7406 is restored into IT->face_id in set_iterator_to_next. */
7409 next_element_from_display_vector (struct it
*it
)
7414 eassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
7416 it
->face_id
= it
->saved_face_id
;
7418 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
7419 That seemed totally bogus - so I changed it... */
7420 gc
= it
->dpvec
[it
->current
.dpvec_index
];
7422 if (GLYPH_CODE_P (gc
))
7424 it
->c
= GLYPH_CODE_CHAR (gc
);
7425 it
->len
= CHAR_BYTES (it
->c
);
7427 /* The entry may contain a face id to use. Such a face id is
7428 the id of a Lisp face, not a realized face. A face id of
7429 zero means no face is specified. */
7430 if (it
->dpvec_face_id
>= 0)
7431 it
->face_id
= it
->dpvec_face_id
;
7434 int lface_id
= GLYPH_CODE_FACE (gc
);
7436 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
7441 /* Display table entry is invalid. Return a space. */
7442 it
->c
= ' ', it
->len
= 1;
7444 /* Don't change position and object of the iterator here. They are
7445 still the values of the character that had this display table
7446 entry or was translated, and that's what we want. */
7447 it
->what
= IT_CHARACTER
;
7451 /* Get the first element of string/buffer in the visual order, after
7452 being reseated to a new position in a string or a buffer. */
7454 get_visually_first_element (struct it
*it
)
7456 int string_p
= STRINGP (it
->string
) || it
->s
;
7457 ptrdiff_t eob
= (string_p
? it
->bidi_it
.string
.schars
: ZV
);
7458 ptrdiff_t bob
= (string_p
? 0 : BEGV
);
7460 if (STRINGP (it
->string
))
7462 it
->bidi_it
.charpos
= IT_STRING_CHARPOS (*it
);
7463 it
->bidi_it
.bytepos
= IT_STRING_BYTEPOS (*it
);
7467 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
7468 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
7471 if (it
->bidi_it
.charpos
== eob
)
7473 /* Nothing to do, but reset the FIRST_ELT flag, like
7474 bidi_paragraph_init does, because we are not going to
7476 it
->bidi_it
.first_elt
= 0;
7478 else if (it
->bidi_it
.charpos
== bob
7480 && (FETCH_CHAR (it
->bidi_it
.bytepos
- 1) == '\n'
7481 || FETCH_CHAR (it
->bidi_it
.bytepos
) == '\n')))
7483 /* If we are at the beginning of a line/string, we can produce
7484 the next element right away. */
7485 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7486 bidi_move_to_visually_next (&it
->bidi_it
);
7490 ptrdiff_t orig_bytepos
= it
->bidi_it
.bytepos
;
7492 /* We need to prime the bidi iterator starting at the line's or
7493 string's beginning, before we will be able to produce the
7496 it
->bidi_it
.charpos
= it
->bidi_it
.bytepos
= 0;
7499 it
->bidi_it
.charpos
= find_next_newline_no_quit (IT_CHARPOS (*it
),
7501 it
->bidi_it
.bytepos
= CHAR_TO_BYTE (it
->bidi_it
.charpos
);
7503 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7506 /* Now return to buffer/string position where we were asked
7507 to get the next display element, and produce that. */
7508 bidi_move_to_visually_next (&it
->bidi_it
);
7510 while (it
->bidi_it
.bytepos
!= orig_bytepos
7511 && it
->bidi_it
.charpos
< eob
);
7514 /* Adjust IT's position information to where we ended up. */
7515 if (STRINGP (it
->string
))
7517 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7518 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7522 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7523 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7526 if (STRINGP (it
->string
) || !it
->s
)
7528 ptrdiff_t stop
, charpos
, bytepos
;
7530 if (STRINGP (it
->string
))
7533 stop
= SCHARS (it
->string
);
7534 if (stop
> it
->end_charpos
)
7535 stop
= it
->end_charpos
;
7536 charpos
= IT_STRING_CHARPOS (*it
);
7537 bytepos
= IT_STRING_BYTEPOS (*it
);
7541 stop
= it
->end_charpos
;
7542 charpos
= IT_CHARPOS (*it
);
7543 bytepos
= IT_BYTEPOS (*it
);
7545 if (it
->bidi_it
.scan_dir
< 0)
7547 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
, stop
,
7552 /* Load IT with the next display element from Lisp string IT->string.
7553 IT->current.string_pos is the current position within the string.
7554 If IT->current.overlay_string_index >= 0, the Lisp string is an
7558 next_element_from_string (struct it
*it
)
7560 struct text_pos position
;
7562 eassert (STRINGP (it
->string
));
7563 eassert (!it
->bidi_p
|| EQ (it
->string
, it
->bidi_it
.string
.lstring
));
7564 eassert (IT_STRING_CHARPOS (*it
) >= 0);
7565 position
= it
->current
.string_pos
;
7567 /* With bidi reordering, the character to display might not be the
7568 character at IT_STRING_CHARPOS. BIDI_IT.FIRST_ELT non-zero means
7569 that we were reseat()ed to a new string, whose paragraph
7570 direction is not known. */
7571 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7573 get_visually_first_element (it
);
7574 SET_TEXT_POS (position
, IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
));
7577 /* Time to check for invisible text? */
7578 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
7580 if (IT_STRING_CHARPOS (*it
) >= it
->stop_charpos
)
7583 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7584 || IT_STRING_CHARPOS (*it
) == it
->stop_charpos
))
7586 /* With bidi non-linear iteration, we could find
7587 ourselves far beyond the last computed stop_charpos,
7588 with several other stop positions in between that we
7589 missed. Scan them all now, in buffer's logical
7590 order, until we find and handle the last stop_charpos
7591 that precedes our current position. */
7592 handle_stop_backwards (it
, it
->stop_charpos
);
7593 return GET_NEXT_DISPLAY_ELEMENT (it
);
7599 /* Take note of the stop position we just moved
7600 across, for when we will move back across it. */
7601 it
->prev_stop
= it
->stop_charpos
;
7602 /* If we are at base paragraph embedding level, take
7603 note of the last stop position seen at this
7605 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7606 it
->base_level_stop
= it
->stop_charpos
;
7610 /* Since a handler may have changed IT->method, we must
7612 return GET_NEXT_DISPLAY_ELEMENT (it
);
7616 /* If we are before prev_stop, we may have overstepped
7617 on our way backwards a stop_pos, and if so, we need
7618 to handle that stop_pos. */
7619 && IT_STRING_CHARPOS (*it
) < it
->prev_stop
7620 /* We can sometimes back up for reasons that have nothing
7621 to do with bidi reordering. E.g., compositions. The
7622 code below is only needed when we are above the base
7623 embedding level, so test for that explicitly. */
7624 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7626 /* If we lost track of base_level_stop, we have no better
7627 place for handle_stop_backwards to start from than string
7628 beginning. This happens, e.g., when we were reseated to
7629 the previous screenful of text by vertical-motion. */
7630 if (it
->base_level_stop
<= 0
7631 || IT_STRING_CHARPOS (*it
) < it
->base_level_stop
)
7632 it
->base_level_stop
= 0;
7633 handle_stop_backwards (it
, it
->base_level_stop
);
7634 return GET_NEXT_DISPLAY_ELEMENT (it
);
7638 if (it
->current
.overlay_string_index
>= 0)
7640 /* Get the next character from an overlay string. In overlay
7641 strings, there is no field width or padding with spaces to
7643 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7648 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7649 IT_STRING_BYTEPOS (*it
),
7650 it
->bidi_it
.scan_dir
< 0
7652 : SCHARS (it
->string
))
7653 && next_element_from_composition (it
))
7657 else if (STRING_MULTIBYTE (it
->string
))
7659 const unsigned char *s
= (SDATA (it
->string
)
7660 + IT_STRING_BYTEPOS (*it
));
7661 it
->c
= string_char_and_length (s
, &it
->len
);
7665 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7671 /* Get the next character from a Lisp string that is not an
7672 overlay string. Such strings come from the mode line, for
7673 example. We may have to pad with spaces, or truncate the
7674 string. See also next_element_from_c_string. */
7675 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7680 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
7682 /* Pad with spaces. */
7683 it
->c
= ' ', it
->len
= 1;
7684 CHARPOS (position
) = BYTEPOS (position
) = -1;
7686 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7687 IT_STRING_BYTEPOS (*it
),
7688 it
->bidi_it
.scan_dir
< 0
7690 : it
->string_nchars
)
7691 && next_element_from_composition (it
))
7695 else if (STRING_MULTIBYTE (it
->string
))
7697 const unsigned char *s
= (SDATA (it
->string
)
7698 + IT_STRING_BYTEPOS (*it
));
7699 it
->c
= string_char_and_length (s
, &it
->len
);
7703 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7708 /* Record what we have and where it came from. */
7709 it
->what
= IT_CHARACTER
;
7710 it
->object
= it
->string
;
7711 it
->position
= position
;
7716 /* Load IT with next display element from C string IT->s.
7717 IT->string_nchars is the maximum number of characters to return
7718 from the string. IT->end_charpos may be greater than
7719 IT->string_nchars when this function is called, in which case we
7720 may have to return padding spaces. Value is zero if end of string
7721 reached, including padding spaces. */
7724 next_element_from_c_string (struct it
*it
)
7729 eassert (!it
->bidi_p
|| it
->s
== it
->bidi_it
.string
.s
);
7730 it
->what
= IT_CHARACTER
;
7731 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
7734 /* With bidi reordering, the character to display might not be the
7735 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7736 we were reseated to a new string, whose paragraph direction is
7738 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7739 get_visually_first_element (it
);
7741 /* IT's position can be greater than IT->string_nchars in case a
7742 field width or precision has been specified when the iterator was
7744 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7746 /* End of the game. */
7750 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
7752 /* Pad with spaces. */
7753 it
->c
= ' ', it
->len
= 1;
7754 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
7756 else if (it
->multibyte_p
)
7757 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
), &it
->len
);
7759 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
7765 /* Set up IT to return characters from an ellipsis, if appropriate.
7766 The definition of the ellipsis glyphs may come from a display table
7767 entry. This function fills IT with the first glyph from the
7768 ellipsis if an ellipsis is to be displayed. */
7771 next_element_from_ellipsis (struct it
*it
)
7773 if (it
->selective_display_ellipsis_p
)
7774 setup_for_ellipsis (it
, it
->len
);
7777 /* The face at the current position may be different from the
7778 face we find after the invisible text. Remember what it
7779 was in IT->saved_face_id, and signal that it's there by
7780 setting face_before_selective_p. */
7781 it
->saved_face_id
= it
->face_id
;
7782 it
->method
= GET_FROM_BUFFER
;
7783 it
->object
= it
->w
->buffer
;
7784 reseat_at_next_visible_line_start (it
, 1);
7785 it
->face_before_selective_p
= 1;
7788 return GET_NEXT_DISPLAY_ELEMENT (it
);
7792 /* Deliver an image display element. The iterator IT is already
7793 filled with image information (done in handle_display_prop). Value
7798 next_element_from_image (struct it
*it
)
7800 it
->what
= IT_IMAGE
;
7801 it
->ignore_overlay_strings_at_pos_p
= 0;
7805 #ifdef HAVE_XWIDGETS
7806 /* im not sure about this FIXME JAVE*/
7808 next_element_from_xwidget (struct it
*it
)
7810 it
->what
= IT_XWIDGET
;
7811 //assert_valid_xwidget_id(it->xwidget_id,"next_element_from_xwidget");
7812 //this is shaky because why do we set "what" if we dont set the other parts??
7813 //printf("xwidget_id %d: in next_element_from_xwidget: FIXME \n", it->xwidget_id);
7819 /* Fill iterator IT with next display element from a stretch glyph
7820 property. IT->object is the value of the text property. Value is
7824 next_element_from_stretch (struct it
*it
)
7826 it
->what
= IT_STRETCH
;
7830 /* Scan backwards from IT's current position until we find a stop
7831 position, or until BEGV. This is called when we find ourself
7832 before both the last known prev_stop and base_level_stop while
7833 reordering bidirectional text. */
7836 compute_stop_pos_backwards (struct it
*it
)
7838 const int SCAN_BACK_LIMIT
= 1000;
7839 struct text_pos pos
;
7840 struct display_pos save_current
= it
->current
;
7841 struct text_pos save_position
= it
->position
;
7842 ptrdiff_t charpos
= IT_CHARPOS (*it
);
7843 ptrdiff_t where_we_are
= charpos
;
7844 ptrdiff_t save_stop_pos
= it
->stop_charpos
;
7845 ptrdiff_t save_end_pos
= it
->end_charpos
;
7847 eassert (NILP (it
->string
) && !it
->s
);
7848 eassert (it
->bidi_p
);
7852 it
->end_charpos
= min (charpos
+ 1, ZV
);
7853 charpos
= max (charpos
- SCAN_BACK_LIMIT
, BEGV
);
7854 SET_TEXT_POS (pos
, charpos
, CHAR_TO_BYTE (charpos
));
7855 reseat_1 (it
, pos
, 0);
7856 compute_stop_pos (it
);
7857 /* We must advance forward, right? */
7858 if (it
->stop_charpos
<= charpos
)
7861 while (charpos
> BEGV
&& it
->stop_charpos
>= it
->end_charpos
);
7863 if (it
->stop_charpos
<= where_we_are
)
7864 it
->prev_stop
= it
->stop_charpos
;
7866 it
->prev_stop
= BEGV
;
7868 it
->current
= save_current
;
7869 it
->position
= save_position
;
7870 it
->stop_charpos
= save_stop_pos
;
7871 it
->end_charpos
= save_end_pos
;
7874 /* Scan forward from CHARPOS in the current buffer/string, until we
7875 find a stop position > current IT's position. Then handle the stop
7876 position before that. This is called when we bump into a stop
7877 position while reordering bidirectional text. CHARPOS should be
7878 the last previously processed stop_pos (or BEGV/0, if none were
7879 processed yet) whose position is less that IT's current
7883 handle_stop_backwards (struct it
*it
, ptrdiff_t charpos
)
7885 int bufp
= !STRINGP (it
->string
);
7886 ptrdiff_t where_we_are
= (bufp
? IT_CHARPOS (*it
) : IT_STRING_CHARPOS (*it
));
7887 struct display_pos save_current
= it
->current
;
7888 struct text_pos save_position
= it
->position
;
7889 struct text_pos pos1
;
7890 ptrdiff_t next_stop
;
7892 /* Scan in strict logical order. */
7893 eassert (it
->bidi_p
);
7897 it
->prev_stop
= charpos
;
7900 SET_TEXT_POS (pos1
, charpos
, CHAR_TO_BYTE (charpos
));
7901 reseat_1 (it
, pos1
, 0);
7904 it
->current
.string_pos
= string_pos (charpos
, it
->string
);
7905 compute_stop_pos (it
);
7906 /* We must advance forward, right? */
7907 if (it
->stop_charpos
<= it
->prev_stop
)
7909 charpos
= it
->stop_charpos
;
7911 while (charpos
<= where_we_are
);
7914 it
->current
= save_current
;
7915 it
->position
= save_position
;
7916 next_stop
= it
->stop_charpos
;
7917 it
->stop_charpos
= it
->prev_stop
;
7919 it
->stop_charpos
= next_stop
;
7922 /* Load IT with the next display element from current_buffer. Value
7923 is zero if end of buffer reached. IT->stop_charpos is the next
7924 position at which to stop and check for text properties or buffer
7928 next_element_from_buffer (struct it
*it
)
7932 eassert (IT_CHARPOS (*it
) >= BEGV
);
7933 eassert (NILP (it
->string
) && !it
->s
);
7934 eassert (!it
->bidi_p
7935 || (EQ (it
->bidi_it
.string
.lstring
, Qnil
)
7936 && it
->bidi_it
.string
.s
== NULL
));
7938 /* With bidi reordering, the character to display might not be the
7939 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7940 we were reseat()ed to a new buffer position, which is potentially
7941 a different paragraph. */
7942 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7944 get_visually_first_element (it
);
7945 SET_TEXT_POS (it
->position
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7948 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
7950 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7952 int overlay_strings_follow_p
;
7954 /* End of the game, except when overlay strings follow that
7955 haven't been returned yet. */
7956 if (it
->overlay_strings_at_end_processed_p
)
7957 overlay_strings_follow_p
= 0;
7960 it
->overlay_strings_at_end_processed_p
= 1;
7961 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
7964 if (overlay_strings_follow_p
)
7965 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
7969 it
->position
= it
->current
.pos
;
7973 else if (!(!it
->bidi_p
7974 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7975 || IT_CHARPOS (*it
) == it
->stop_charpos
))
7977 /* With bidi non-linear iteration, we could find ourselves
7978 far beyond the last computed stop_charpos, with several
7979 other stop positions in between that we missed. Scan
7980 them all now, in buffer's logical order, until we find
7981 and handle the last stop_charpos that precedes our
7982 current position. */
7983 handle_stop_backwards (it
, it
->stop_charpos
);
7984 return GET_NEXT_DISPLAY_ELEMENT (it
);
7990 /* Take note of the stop position we just moved across,
7991 for when we will move back across it. */
7992 it
->prev_stop
= it
->stop_charpos
;
7993 /* If we are at base paragraph embedding level, take
7994 note of the last stop position seen at this
7996 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7997 it
->base_level_stop
= it
->stop_charpos
;
8000 return GET_NEXT_DISPLAY_ELEMENT (it
);
8004 /* If we are before prev_stop, we may have overstepped on
8005 our way backwards a stop_pos, and if so, we need to
8006 handle that stop_pos. */
8007 && IT_CHARPOS (*it
) < it
->prev_stop
8008 /* We can sometimes back up for reasons that have nothing
8009 to do with bidi reordering. E.g., compositions. The
8010 code below is only needed when we are above the base
8011 embedding level, so test for that explicitly. */
8012 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8014 if (it
->base_level_stop
<= 0
8015 || IT_CHARPOS (*it
) < it
->base_level_stop
)
8017 /* If we lost track of base_level_stop, we need to find
8018 prev_stop by looking backwards. This happens, e.g., when
8019 we were reseated to the previous screenful of text by
8021 it
->base_level_stop
= BEGV
;
8022 compute_stop_pos_backwards (it
);
8023 handle_stop_backwards (it
, it
->prev_stop
);
8026 handle_stop_backwards (it
, it
->base_level_stop
);
8027 return GET_NEXT_DISPLAY_ELEMENT (it
);
8031 /* No face changes, overlays etc. in sight, so just return a
8032 character from current_buffer. */
8036 /* Maybe run the redisplay end trigger hook. Performance note:
8037 This doesn't seem to cost measurable time. */
8038 if (it
->redisplay_end_trigger_charpos
8040 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
8041 run_redisplay_end_trigger_hook (it
);
8043 stop
= it
->bidi_it
.scan_dir
< 0 ? -1 : it
->end_charpos
;
8044 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
8046 && next_element_from_composition (it
))
8051 /* Get the next character, maybe multibyte. */
8052 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
8053 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
8054 it
->c
= STRING_CHAR_AND_LENGTH (p
, it
->len
);
8056 it
->c
= *p
, it
->len
= 1;
8058 /* Record what we have and where it came from. */
8059 it
->what
= IT_CHARACTER
;
8060 it
->object
= it
->w
->buffer
;
8061 it
->position
= it
->current
.pos
;
8063 /* Normally we return the character found above, except when we
8064 really want to return an ellipsis for selective display. */
8069 /* A value of selective > 0 means hide lines indented more
8070 than that number of columns. */
8071 if (it
->selective
> 0
8072 && IT_CHARPOS (*it
) + 1 < ZV
8073 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
8074 IT_BYTEPOS (*it
) + 1,
8077 success_p
= next_element_from_ellipsis (it
);
8078 it
->dpvec_char_len
= -1;
8081 else if (it
->c
== '\r' && it
->selective
== -1)
8083 /* A value of selective == -1 means that everything from the
8084 CR to the end of the line is invisible, with maybe an
8085 ellipsis displayed for it. */
8086 success_p
= next_element_from_ellipsis (it
);
8087 it
->dpvec_char_len
= -1;
8092 /* Value is zero if end of buffer reached. */
8093 eassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
8098 /* Run the redisplay end trigger hook for IT. */
8101 run_redisplay_end_trigger_hook (struct it
*it
)
8103 Lisp_Object args
[3];
8105 /* IT->glyph_row should be non-null, i.e. we should be actually
8106 displaying something, or otherwise we should not run the hook. */
8107 eassert (it
->glyph_row
);
8109 /* Set up hook arguments. */
8110 args
[0] = Qredisplay_end_trigger_functions
;
8111 args
[1] = it
->window
;
8112 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
8113 it
->redisplay_end_trigger_charpos
= 0;
8115 /* Since we are *trying* to run these functions, don't try to run
8116 them again, even if they get an error. */
8117 wset_redisplay_end_trigger (it
->w
, Qnil
);
8118 Frun_hook_with_args (3, args
);
8120 /* Notice if it changed the face of the character we are on. */
8121 handle_face_prop (it
);
8125 /* Deliver a composition display element. Unlike the other
8126 next_element_from_XXX, this function is not registered in the array
8127 get_next_element[]. It is called from next_element_from_buffer and
8128 next_element_from_string when necessary. */
8131 next_element_from_composition (struct it
*it
)
8133 it
->what
= IT_COMPOSITION
;
8134 it
->len
= it
->cmp_it
.nbytes
;
8135 if (STRINGP (it
->string
))
8139 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
8140 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
8143 it
->position
= it
->current
.string_pos
;
8144 it
->object
= it
->string
;
8145 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
8146 IT_STRING_BYTEPOS (*it
), it
->string
);
8152 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
8153 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
8156 if (it
->bidi_it
.new_paragraph
)
8157 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
8158 /* Resync the bidi iterator with IT's new position.
8159 FIXME: this doesn't support bidirectional text. */
8160 while (it
->bidi_it
.charpos
< IT_CHARPOS (*it
))
8161 bidi_move_to_visually_next (&it
->bidi_it
);
8165 it
->position
= it
->current
.pos
;
8166 it
->object
= it
->w
->buffer
;
8167 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
8168 IT_BYTEPOS (*it
), Qnil
);
8175 /***********************************************************************
8176 Moving an iterator without producing glyphs
8177 ***********************************************************************/
8179 /* Check if iterator is at a position corresponding to a valid buffer
8180 position after some move_it_ call. */
8182 #define IT_POS_VALID_AFTER_MOVE_P(it) \
8183 ((it)->method == GET_FROM_STRING \
8184 ? IT_STRING_CHARPOS (*it) == 0 \
8188 /* Move iterator IT to a specified buffer or X position within one
8189 line on the display without producing glyphs.
8191 OP should be a bit mask including some or all of these bits:
8192 MOVE_TO_X: Stop upon reaching x-position TO_X.
8193 MOVE_TO_POS: Stop upon reaching buffer or string position TO_CHARPOS.
8194 Regardless of OP's value, stop upon reaching the end of the display line.
8196 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
8197 This means, in particular, that TO_X includes window's horizontal
8200 The return value has several possible values that
8201 say what condition caused the scan to stop:
8203 MOVE_POS_MATCH_OR_ZV
8204 - when TO_POS or ZV was reached.
8207 -when TO_X was reached before TO_POS or ZV were reached.
8210 - when we reached the end of the display area and the line must
8214 - when we reached the end of the display area and the line is
8218 - when we stopped at a line end, i.e. a newline or a CR and selective
8221 static enum move_it_result
8222 move_it_in_display_line_to (struct it
*it
,
8223 ptrdiff_t to_charpos
, int to_x
,
8224 enum move_operation_enum op
)
8226 enum move_it_result result
= MOVE_UNDEFINED
;
8227 struct glyph_row
*saved_glyph_row
;
8228 struct it wrap_it
, atpos_it
, atx_it
, ppos_it
;
8229 void *wrap_data
= NULL
, *atpos_data
= NULL
, *atx_data
= NULL
;
8230 void *ppos_data
= NULL
;
8232 enum it_method prev_method
= it
->method
;
8233 ptrdiff_t prev_pos
= IT_CHARPOS (*it
);
8234 int saw_smaller_pos
= prev_pos
< to_charpos
;
8236 /* Don't produce glyphs in produce_glyphs. */
8237 saved_glyph_row
= it
->glyph_row
;
8238 it
->glyph_row
= NULL
;
8240 /* Use wrap_it to save a copy of IT wherever a word wrap could
8241 occur. Use atpos_it to save a copy of IT at the desired buffer
8242 position, if found, so that we can scan ahead and check if the
8243 word later overshoots the window edge. Use atx_it similarly, for
8249 /* Use ppos_it under bidi reordering to save a copy of IT for the
8250 position > CHARPOS that is the closest to CHARPOS. We restore
8251 that position in IT when we have scanned the entire display line
8252 without finding a match for CHARPOS and all the character
8253 positions are greater than CHARPOS. */
8256 SAVE_IT (ppos_it
, *it
, ppos_data
);
8257 SET_TEXT_POS (ppos_it
.current
.pos
, ZV
, ZV_BYTE
);
8258 if ((op
& MOVE_TO_POS
) && IT_CHARPOS (*it
) >= to_charpos
)
8259 SAVE_IT (ppos_it
, *it
, ppos_data
);
8262 #define BUFFER_POS_REACHED_P() \
8263 ((op & MOVE_TO_POS) != 0 \
8264 && BUFFERP (it->object) \
8265 && (IT_CHARPOS (*it) == to_charpos \
8267 || BIDI_AT_BASE_LEVEL (it->bidi_it)) \
8268 && IT_CHARPOS (*it) > to_charpos) \
8269 || (it->what == IT_COMPOSITION \
8270 && ((IT_CHARPOS (*it) > to_charpos \
8271 && to_charpos >= it->cmp_it.charpos) \
8272 || (IT_CHARPOS (*it) < to_charpos \
8273 && to_charpos <= it->cmp_it.charpos)))) \
8274 && (it->method == GET_FROM_BUFFER \
8275 || (it->method == GET_FROM_DISPLAY_VECTOR \
8276 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
8278 /* If there's a line-/wrap-prefix, handle it. */
8279 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
8280 && it
->current_y
< it
->last_visible_y
)
8281 handle_line_prefix (it
);
8283 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8284 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8288 int x
, i
, ascent
= 0, descent
= 0;
8290 /* Utility macro to reset an iterator with x, ascent, and descent. */
8291 #define IT_RESET_X_ASCENT_DESCENT(IT) \
8292 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
8293 (IT)->max_descent = descent)
8295 /* Stop if we move beyond TO_CHARPOS (after an image or a
8296 display string or stretch glyph). */
8297 if ((op
& MOVE_TO_POS
) != 0
8298 && BUFFERP (it
->object
)
8299 && it
->method
== GET_FROM_BUFFER
8301 /* When the iterator is at base embedding level, we
8302 are guaranteed that characters are delivered for
8303 display in strictly increasing order of their
8304 buffer positions. */
8305 || BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8306 && IT_CHARPOS (*it
) > to_charpos
)
8308 && (prev_method
== GET_FROM_IMAGE
8309 || prev_method
== GET_FROM_STRETCH
8310 || prev_method
== GET_FROM_STRING
)
8311 /* Passed TO_CHARPOS from left to right. */
8312 && ((prev_pos
< to_charpos
8313 && IT_CHARPOS (*it
) > to_charpos
)
8314 /* Passed TO_CHARPOS from right to left. */
8315 || (prev_pos
> to_charpos
8316 && IT_CHARPOS (*it
) < to_charpos
)))))
8318 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8320 result
= MOVE_POS_MATCH_OR_ZV
;
8323 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8324 /* If wrap_it is valid, the current position might be in a
8325 word that is wrapped. So, save the iterator in
8326 atpos_it and continue to see if wrapping happens. */
8327 SAVE_IT (atpos_it
, *it
, atpos_data
);
8330 /* Stop when ZV reached.
8331 We used to stop here when TO_CHARPOS reached as well, but that is
8332 too soon if this glyph does not fit on this line. So we handle it
8333 explicitly below. */
8334 if (!get_next_display_element (it
))
8336 result
= MOVE_POS_MATCH_OR_ZV
;
8340 if (it
->line_wrap
== TRUNCATE
)
8342 if (BUFFER_POS_REACHED_P ())
8344 result
= MOVE_POS_MATCH_OR_ZV
;
8350 if (it
->line_wrap
== WORD_WRAP
)
8352 if (IT_DISPLAYING_WHITESPACE (it
))
8356 /* We have reached a glyph that follows one or more
8357 whitespace characters. If the position is
8358 already found, we are done. */
8359 if (atpos_it
.sp
>= 0)
8361 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8362 result
= MOVE_POS_MATCH_OR_ZV
;
8367 RESTORE_IT (it
, &atx_it
, atx_data
);
8368 result
= MOVE_X_REACHED
;
8371 /* Otherwise, we can wrap here. */
8372 SAVE_IT (wrap_it
, *it
, wrap_data
);
8378 /* Remember the line height for the current line, in case
8379 the next element doesn't fit on the line. */
8380 ascent
= it
->max_ascent
;
8381 descent
= it
->max_descent
;
8383 /* The call to produce_glyphs will get the metrics of the
8384 display element IT is loaded with. Record the x-position
8385 before this display element, in case it doesn't fit on the
8389 PRODUCE_GLYPHS (it
);
8391 if (it
->area
!= TEXT_AREA
)
8393 prev_method
= it
->method
;
8394 if (it
->method
== GET_FROM_BUFFER
)
8395 prev_pos
= IT_CHARPOS (*it
);
8396 set_iterator_to_next (it
, 1);
8397 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8398 SET_TEXT_POS (this_line_min_pos
,
8399 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8401 && (op
& MOVE_TO_POS
)
8402 && IT_CHARPOS (*it
) > to_charpos
8403 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8404 SAVE_IT (ppos_it
, *it
, ppos_data
);
8408 /* The number of glyphs we get back in IT->nglyphs will normally
8409 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
8410 character on a terminal frame, or (iii) a line end. For the
8411 second case, IT->nglyphs - 1 padding glyphs will be present.
8412 (On X frames, there is only one glyph produced for a
8413 composite character.)
8415 The behavior implemented below means, for continuation lines,
8416 that as many spaces of a TAB as fit on the current line are
8417 displayed there. For terminal frames, as many glyphs of a
8418 multi-glyph character are displayed in the current line, too.
8419 This is what the old redisplay code did, and we keep it that
8420 way. Under X, the whole shape of a complex character must
8421 fit on the line or it will be completely displayed in the
8424 Note that both for tabs and padding glyphs, all glyphs have
8428 /* More than one glyph or glyph doesn't fit on line. All
8429 glyphs have the same width. */
8430 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
8432 int x_before_this_char
= x
;
8433 int hpos_before_this_char
= it
->hpos
;
8435 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
8437 new_x
= x
+ single_glyph_width
;
8439 /* We want to leave anything reaching TO_X to the caller. */
8440 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
8442 if (BUFFER_POS_REACHED_P ())
8444 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8445 goto buffer_pos_reached
;
8446 if (atpos_it
.sp
< 0)
8448 SAVE_IT (atpos_it
, *it
, atpos_data
);
8449 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8454 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8457 result
= MOVE_X_REACHED
;
8462 SAVE_IT (atx_it
, *it
, atx_data
);
8463 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
8468 if (/* Lines are continued. */
8469 it
->line_wrap
!= TRUNCATE
8470 && (/* And glyph doesn't fit on the line. */
8471 new_x
> it
->last_visible_x
8472 /* Or it fits exactly and we're on a window
8474 || (new_x
== it
->last_visible_x
8475 && FRAME_WINDOW_P (it
->f
)
8476 && ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
8477 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8478 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
8480 if (/* IT->hpos == 0 means the very first glyph
8481 doesn't fit on the line, e.g. a wide image. */
8483 || (new_x
== it
->last_visible_x
8484 && FRAME_WINDOW_P (it
->f
)))
8487 it
->current_x
= new_x
;
8489 /* The character's last glyph just barely fits
8491 if (i
== it
->nglyphs
- 1)
8493 /* If this is the destination position,
8494 return a position *before* it in this row,
8495 now that we know it fits in this row. */
8496 if (BUFFER_POS_REACHED_P ())
8498 if (it
->line_wrap
!= WORD_WRAP
8501 it
->hpos
= hpos_before_this_char
;
8502 it
->current_x
= x_before_this_char
;
8503 result
= MOVE_POS_MATCH_OR_ZV
;
8506 if (it
->line_wrap
== WORD_WRAP
8509 SAVE_IT (atpos_it
, *it
, atpos_data
);
8510 atpos_it
.current_x
= x_before_this_char
;
8511 atpos_it
.hpos
= hpos_before_this_char
;
8515 prev_method
= it
->method
;
8516 if (it
->method
== GET_FROM_BUFFER
)
8517 prev_pos
= IT_CHARPOS (*it
);
8518 set_iterator_to_next (it
, 1);
8519 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8520 SET_TEXT_POS (this_line_min_pos
,
8521 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8522 /* On graphical terminals, newlines may
8523 "overflow" into the fringe if
8524 overflow-newline-into-fringe is non-nil.
8525 On text terminals, and on graphical
8526 terminals with no right margin, newlines
8527 may overflow into the last glyph on the
8529 if (!FRAME_WINDOW_P (it
->f
)
8531 && it
->bidi_it
.paragraph_dir
== R2L
)
8532 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8533 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0
8534 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8536 if (!get_next_display_element (it
))
8538 result
= MOVE_POS_MATCH_OR_ZV
;
8541 if (BUFFER_POS_REACHED_P ())
8543 if (ITERATOR_AT_END_OF_LINE_P (it
))
8544 result
= MOVE_POS_MATCH_OR_ZV
;
8546 result
= MOVE_LINE_CONTINUED
;
8549 if (ITERATOR_AT_END_OF_LINE_P (it
))
8551 result
= MOVE_NEWLINE_OR_CR
;
8558 IT_RESET_X_ASCENT_DESCENT (it
);
8560 if (wrap_it
.sp
>= 0)
8562 RESTORE_IT (it
, &wrap_it
, wrap_data
);
8567 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
8569 result
= MOVE_LINE_CONTINUED
;
8573 if (BUFFER_POS_REACHED_P ())
8575 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8576 goto buffer_pos_reached
;
8577 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8579 SAVE_IT (atpos_it
, *it
, atpos_data
);
8580 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8584 if (new_x
> it
->first_visible_x
)
8586 /* Glyph is visible. Increment number of glyphs that
8587 would be displayed. */
8592 if (result
!= MOVE_UNDEFINED
)
8595 else if (BUFFER_POS_REACHED_P ())
8598 IT_RESET_X_ASCENT_DESCENT (it
);
8599 result
= MOVE_POS_MATCH_OR_ZV
;
8602 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
8604 /* Stop when TO_X specified and reached. This check is
8605 necessary here because of lines consisting of a line end,
8606 only. The line end will not produce any glyphs and we
8607 would never get MOVE_X_REACHED. */
8608 eassert (it
->nglyphs
== 0);
8609 result
= MOVE_X_REACHED
;
8613 /* Is this a line end? If yes, we're done. */
8614 if (ITERATOR_AT_END_OF_LINE_P (it
))
8616 /* If we are past TO_CHARPOS, but never saw any character
8617 positions smaller than TO_CHARPOS, return
8618 MOVE_POS_MATCH_OR_ZV, like the unidirectional display
8620 if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0)
8622 if (!saw_smaller_pos
&& IT_CHARPOS (*it
) > to_charpos
)
8624 if (IT_CHARPOS (ppos_it
) < ZV
)
8626 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8627 result
= MOVE_POS_MATCH_OR_ZV
;
8630 goto buffer_pos_reached
;
8632 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
>= 0
8633 && IT_CHARPOS (*it
) > to_charpos
)
8634 goto buffer_pos_reached
;
8636 result
= MOVE_NEWLINE_OR_CR
;
8639 result
= MOVE_NEWLINE_OR_CR
;
8643 prev_method
= it
->method
;
8644 if (it
->method
== GET_FROM_BUFFER
)
8645 prev_pos
= IT_CHARPOS (*it
);
8646 /* The current display element has been consumed. Advance
8648 set_iterator_to_next (it
, 1);
8649 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8650 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8651 if (IT_CHARPOS (*it
) < to_charpos
)
8652 saw_smaller_pos
= 1;
8654 && (op
& MOVE_TO_POS
)
8655 && IT_CHARPOS (*it
) >= to_charpos
8656 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8657 SAVE_IT (ppos_it
, *it
, ppos_data
);
8659 /* Stop if lines are truncated and IT's current x-position is
8660 past the right edge of the window now. */
8661 if (it
->line_wrap
== TRUNCATE
8662 && it
->current_x
>= it
->last_visible_x
)
8664 if (!FRAME_WINDOW_P (it
->f
)
8665 || ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
8666 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8667 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0
8668 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8672 if ((at_eob_p
= !get_next_display_element (it
))
8673 || BUFFER_POS_REACHED_P ()
8674 /* If we are past TO_CHARPOS, but never saw any
8675 character positions smaller than TO_CHARPOS,
8676 return MOVE_POS_MATCH_OR_ZV, like the
8677 unidirectional display did. */
8678 || (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8680 && IT_CHARPOS (*it
) > to_charpos
))
8683 && !at_eob_p
&& IT_CHARPOS (ppos_it
) < ZV
)
8684 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8685 result
= MOVE_POS_MATCH_OR_ZV
;
8688 if (ITERATOR_AT_END_OF_LINE_P (it
))
8690 result
= MOVE_NEWLINE_OR_CR
;
8694 else if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8696 && IT_CHARPOS (*it
) > to_charpos
)
8698 if (IT_CHARPOS (ppos_it
) < ZV
)
8699 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8700 result
= MOVE_POS_MATCH_OR_ZV
;
8703 result
= MOVE_LINE_TRUNCATED
;
8706 #undef IT_RESET_X_ASCENT_DESCENT
8709 #undef BUFFER_POS_REACHED_P
8711 /* If we scanned beyond to_pos and didn't find a point to wrap at,
8712 restore the saved iterator. */
8713 if (atpos_it
.sp
>= 0)
8714 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8715 else if (atx_it
.sp
>= 0)
8716 RESTORE_IT (it
, &atx_it
, atx_data
);
8721 bidi_unshelve_cache (atpos_data
, 1);
8723 bidi_unshelve_cache (atx_data
, 1);
8725 bidi_unshelve_cache (wrap_data
, 1);
8727 bidi_unshelve_cache (ppos_data
, 1);
8729 /* Restore the iterator settings altered at the beginning of this
8731 it
->glyph_row
= saved_glyph_row
;
8735 /* For external use. */
8737 move_it_in_display_line (struct it
*it
,
8738 ptrdiff_t to_charpos
, int to_x
,
8739 enum move_operation_enum op
)
8741 if (it
->line_wrap
== WORD_WRAP
8742 && (op
& MOVE_TO_X
))
8745 void *save_data
= NULL
;
8748 SAVE_IT (save_it
, *it
, save_data
);
8749 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8750 /* When word-wrap is on, TO_X may lie past the end
8751 of a wrapped line. Then it->current is the
8752 character on the next line, so backtrack to the
8753 space before the wrap point. */
8754 if (skip
== MOVE_LINE_CONTINUED
)
8756 int prev_x
= max (it
->current_x
- 1, 0);
8757 RESTORE_IT (it
, &save_it
, save_data
);
8758 move_it_in_display_line_to
8759 (it
, -1, prev_x
, MOVE_TO_X
);
8762 bidi_unshelve_cache (save_data
, 1);
8765 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8769 /* Move IT forward until it satisfies one or more of the criteria in
8770 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
8772 OP is a bit-mask that specifies where to stop, and in particular,
8773 which of those four position arguments makes a difference. See the
8774 description of enum move_operation_enum.
8776 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
8777 screen line, this function will set IT to the next position that is
8778 displayed to the right of TO_CHARPOS on the screen. */
8781 move_it_to (struct it
*it
, ptrdiff_t to_charpos
, int to_x
, int to_y
, int to_vpos
, int op
)
8783 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
8784 int line_height
, line_start_x
= 0, reached
= 0;
8785 void *backup_data
= NULL
;
8789 if (op
& MOVE_TO_VPOS
)
8791 /* If no TO_CHARPOS and no TO_X specified, stop at the
8792 start of the line TO_VPOS. */
8793 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
8795 if (it
->vpos
== to_vpos
)
8801 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
8805 /* TO_VPOS >= 0 means stop at TO_X in the line at
8806 TO_VPOS, or at TO_POS, whichever comes first. */
8807 if (it
->vpos
== to_vpos
)
8813 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8815 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
8820 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
8822 /* We have reached TO_X but not in the line we want. */
8823 skip
= move_it_in_display_line_to (it
, to_charpos
,
8825 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8833 else if (op
& MOVE_TO_Y
)
8835 struct it it_backup
;
8837 if (it
->line_wrap
== WORD_WRAP
)
8838 SAVE_IT (it_backup
, *it
, backup_data
);
8840 /* TO_Y specified means stop at TO_X in the line containing
8841 TO_Y---or at TO_CHARPOS if this is reached first. The
8842 problem is that we can't really tell whether the line
8843 contains TO_Y before we have completely scanned it, and
8844 this may skip past TO_X. What we do is to first scan to
8847 If TO_X is not specified, use a TO_X of zero. The reason
8848 is to make the outcome of this function more predictable.
8849 If we didn't use TO_X == 0, we would stop at the end of
8850 the line which is probably not what a caller would expect
8852 skip
= move_it_in_display_line_to
8853 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
8854 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
8856 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
8857 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8859 else if (skip
== MOVE_X_REACHED
)
8861 /* If TO_X was reached, we want to know whether TO_Y is
8862 in the line. We know this is the case if the already
8863 scanned glyphs make the line tall enough. Otherwise,
8864 we must check by scanning the rest of the line. */
8865 line_height
= it
->max_ascent
+ it
->max_descent
;
8866 if (to_y
>= it
->current_y
8867 && to_y
< it
->current_y
+ line_height
)
8872 SAVE_IT (it_backup
, *it
, backup_data
);
8873 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
8874 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
8876 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
8877 line_height
= it
->max_ascent
+ it
->max_descent
;
8878 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8880 if (to_y
>= it
->current_y
8881 && to_y
< it
->current_y
+ line_height
)
8883 /* If TO_Y is in this line and TO_X was reached
8884 above, we scanned too far. We have to restore
8885 IT's settings to the ones before skipping. But
8886 keep the more accurate values of max_ascent and
8887 max_descent we've found while skipping the rest
8888 of the line, for the sake of callers, such as
8889 pos_visible_p, that need to know the line
8891 int max_ascent
= it
->max_ascent
;
8892 int max_descent
= it
->max_descent
;
8894 RESTORE_IT (it
, &it_backup
, backup_data
);
8895 it
->max_ascent
= max_ascent
;
8896 it
->max_descent
= max_descent
;
8902 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8908 /* Check whether TO_Y is in this line. */
8909 line_height
= it
->max_ascent
+ it
->max_descent
;
8910 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8912 if (to_y
>= it
->current_y
8913 && to_y
< it
->current_y
+ line_height
)
8915 /* When word-wrap is on, TO_X may lie past the end
8916 of a wrapped line. Then it->current is the
8917 character on the next line, so backtrack to the
8918 space before the wrap point. */
8919 if (skip
== MOVE_LINE_CONTINUED
8920 && it
->line_wrap
== WORD_WRAP
)
8922 int prev_x
= max (it
->current_x
- 1, 0);
8923 RESTORE_IT (it
, &it_backup
, backup_data
);
8924 skip
= move_it_in_display_line_to
8925 (it
, -1, prev_x
, MOVE_TO_X
);
8934 else if (BUFFERP (it
->object
)
8935 && (it
->method
== GET_FROM_BUFFER
8936 || it
->method
== GET_FROM_STRETCH
)
8937 && IT_CHARPOS (*it
) >= to_charpos
8938 /* Under bidi iteration, a call to set_iterator_to_next
8939 can scan far beyond to_charpos if the initial
8940 portion of the next line needs to be reordered. In
8941 that case, give move_it_in_display_line_to another
8944 && it
->bidi_it
.scan_dir
== -1))
8945 skip
= MOVE_POS_MATCH_OR_ZV
;
8947 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
8951 case MOVE_POS_MATCH_OR_ZV
:
8955 case MOVE_NEWLINE_OR_CR
:
8956 set_iterator_to_next (it
, 1);
8957 it
->continuation_lines_width
= 0;
8960 case MOVE_LINE_TRUNCATED
:
8961 it
->continuation_lines_width
= 0;
8962 reseat_at_next_visible_line_start (it
, 0);
8963 if ((op
& MOVE_TO_POS
) != 0
8964 && IT_CHARPOS (*it
) > to_charpos
)
8971 case MOVE_LINE_CONTINUED
:
8972 /* For continued lines ending in a tab, some of the glyphs
8973 associated with the tab are displayed on the current
8974 line. Since it->current_x does not include these glyphs,
8975 we use it->last_visible_x instead. */
8978 it
->continuation_lines_width
+= it
->last_visible_x
;
8979 /* When moving by vpos, ensure that the iterator really
8980 advances to the next line (bug#847, bug#969). Fixme:
8981 do we need to do this in other circumstances? */
8982 if (it
->current_x
!= it
->last_visible_x
8983 && (op
& MOVE_TO_VPOS
)
8984 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
8986 line_start_x
= it
->current_x
+ it
->pixel_width
8987 - it
->last_visible_x
;
8988 set_iterator_to_next (it
, 0);
8992 it
->continuation_lines_width
+= it
->current_x
;
8999 /* Reset/increment for the next run. */
9000 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
9001 it
->current_x
= line_start_x
;
9004 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
9006 last_height
= it
->max_ascent
+ it
->max_descent
;
9007 last_max_ascent
= it
->max_ascent
;
9008 it
->max_ascent
= it
->max_descent
= 0;
9013 /* On text terminals, we may stop at the end of a line in the middle
9014 of a multi-character glyph. If the glyph itself is continued,
9015 i.e. it is actually displayed on the next line, don't treat this
9016 stopping point as valid; move to the next line instead (unless
9017 that brings us offscreen). */
9018 if (!FRAME_WINDOW_P (it
->f
)
9020 && IT_CHARPOS (*it
) == to_charpos
9021 && it
->what
== IT_CHARACTER
9023 && it
->line_wrap
== WINDOW_WRAP
9024 && it
->current_x
== it
->last_visible_x
- 1
9027 && it
->vpos
< XFASTINT (it
->w
->window_end_vpos
))
9029 it
->continuation_lines_width
+= it
->current_x
;
9030 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
9031 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
9033 last_height
= it
->max_ascent
+ it
->max_descent
;
9034 last_max_ascent
= it
->max_ascent
;
9038 bidi_unshelve_cache (backup_data
, 1);
9040 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
9044 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
9046 If DY > 0, move IT backward at least that many pixels. DY = 0
9047 means move IT backward to the preceding line start or BEGV. This
9048 function may move over more than DY pixels if IT->current_y - DY
9049 ends up in the middle of a line; in this case IT->current_y will be
9050 set to the top of the line moved to. */
9053 move_it_vertically_backward (struct it
*it
, int dy
)
9057 void *it2data
= NULL
, *it3data
= NULL
;
9058 ptrdiff_t start_pos
;
9063 start_pos
= IT_CHARPOS (*it
);
9065 /* Estimate how many newlines we must move back. */
9066 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
9068 /* Set the iterator's position that many lines back. */
9069 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
9070 back_to_previous_visible_line_start (it
);
9072 /* Reseat the iterator here. When moving backward, we don't want
9073 reseat to skip forward over invisible text, set up the iterator
9074 to deliver from overlay strings at the new position etc. So,
9075 use reseat_1 here. */
9076 reseat_1 (it
, it
->current
.pos
, 1);
9078 /* We are now surely at a line start. */
9079 it
->current_x
= it
->hpos
= 0; /* FIXME: this is incorrect when bidi
9080 reordering is in effect. */
9081 it
->continuation_lines_width
= 0;
9083 /* Move forward and see what y-distance we moved. First move to the
9084 start of the next line so that we get its height. We need this
9085 height to be able to tell whether we reached the specified
9087 SAVE_IT (it2
, *it
, it2data
);
9088 it2
.max_ascent
= it2
.max_descent
= 0;
9091 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
9092 MOVE_TO_POS
| MOVE_TO_VPOS
);
9094 while (!(IT_POS_VALID_AFTER_MOVE_P (&it2
)
9095 /* If we are in a display string which starts at START_POS,
9096 and that display string includes a newline, and we are
9097 right after that newline (i.e. at the beginning of a
9098 display line), exit the loop, because otherwise we will
9099 infloop, since move_it_to will see that it is already at
9100 START_POS and will not move. */
9101 || (it2
.method
== GET_FROM_STRING
9102 && IT_CHARPOS (it2
) == start_pos
9103 && SREF (it2
.string
, IT_STRING_BYTEPOS (it2
) - 1) == '\n')));
9104 eassert (IT_CHARPOS (*it
) >= BEGV
);
9105 SAVE_IT (it3
, it2
, it3data
);
9107 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
9108 eassert (IT_CHARPOS (*it
) >= BEGV
);
9109 /* H is the actual vertical distance from the position in *IT
9110 and the starting position. */
9111 h
= it2
.current_y
- it
->current_y
;
9112 /* NLINES is the distance in number of lines. */
9113 nlines
= it2
.vpos
- it
->vpos
;
9115 /* Correct IT's y and vpos position
9116 so that they are relative to the starting point. */
9122 /* DY == 0 means move to the start of the screen line. The
9123 value of nlines is > 0 if continuation lines were involved,
9124 or if the original IT position was at start of a line. */
9125 RESTORE_IT (it
, it
, it2data
);
9127 move_it_by_lines (it
, nlines
);
9128 /* The above code moves us to some position NLINES down,
9129 usually to its first glyph (leftmost in an L2R line), but
9130 that's not necessarily the start of the line, under bidi
9131 reordering. We want to get to the character position
9132 that is immediately after the newline of the previous
9135 && !it
->continuation_lines_width
9136 && !STRINGP (it
->string
)
9137 && IT_CHARPOS (*it
) > BEGV
9138 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9141 find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
9143 move_it_to (it
, nl_pos
, -1, -1, -1, MOVE_TO_POS
);
9145 bidi_unshelve_cache (it3data
, 1);
9149 /* The y-position we try to reach, relative to *IT.
9150 Note that H has been subtracted in front of the if-statement. */
9151 int target_y
= it
->current_y
+ h
- dy
;
9152 int y0
= it3
.current_y
;
9156 RESTORE_IT (&it3
, &it3
, it3data
);
9157 y1
= line_bottom_y (&it3
);
9158 line_height
= y1
- y0
;
9159 RESTORE_IT (it
, it
, it2data
);
9160 /* If we did not reach target_y, try to move further backward if
9161 we can. If we moved too far backward, try to move forward. */
9162 if (target_y
< it
->current_y
9163 /* This is heuristic. In a window that's 3 lines high, with
9164 a line height of 13 pixels each, recentering with point
9165 on the bottom line will try to move -39/2 = 19 pixels
9166 backward. Try to avoid moving into the first line. */
9167 && (it
->current_y
- target_y
9168 > min (window_box_height (it
->w
), line_height
* 2 / 3))
9169 && IT_CHARPOS (*it
) > BEGV
)
9171 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
9172 target_y
- it
->current_y
));
9173 dy
= it
->current_y
- target_y
;
9174 goto move_further_back
;
9176 else if (target_y
>= it
->current_y
+ line_height
9177 && IT_CHARPOS (*it
) < ZV
)
9179 /* Should move forward by at least one line, maybe more.
9181 Note: Calling move_it_by_lines can be expensive on
9182 terminal frames, where compute_motion is used (via
9183 vmotion) to do the job, when there are very long lines
9184 and truncate-lines is nil. That's the reason for
9185 treating terminal frames specially here. */
9187 if (!FRAME_WINDOW_P (it
->f
))
9188 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
9193 move_it_by_lines (it
, 1);
9195 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
9202 /* Move IT by a specified amount of pixel lines DY. DY negative means
9203 move backwards. DY = 0 means move to start of screen line. At the
9204 end, IT will be on the start of a screen line. */
9207 move_it_vertically (struct it
*it
, int dy
)
9210 move_it_vertically_backward (it
, -dy
);
9213 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
9214 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
9215 MOVE_TO_POS
| MOVE_TO_Y
);
9216 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
9218 /* If buffer ends in ZV without a newline, move to the start of
9219 the line to satisfy the post-condition. */
9220 if (IT_CHARPOS (*it
) == ZV
9222 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9223 move_it_by_lines (it
, 0);
9228 /* Move iterator IT past the end of the text line it is in. */
9231 move_it_past_eol (struct it
*it
)
9233 enum move_it_result rc
;
9235 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
9236 if (rc
== MOVE_NEWLINE_OR_CR
)
9237 set_iterator_to_next (it
, 0);
9241 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
9242 negative means move up. DVPOS == 0 means move to the start of the
9245 Optimization idea: If we would know that IT->f doesn't use
9246 a face with proportional font, we could be faster for
9247 truncate-lines nil. */
9250 move_it_by_lines (struct it
*it
, ptrdiff_t dvpos
)
9253 /* The commented-out optimization uses vmotion on terminals. This
9254 gives bad results, because elements like it->what, on which
9255 callers such as pos_visible_p rely, aren't updated. */
9256 /* struct position pos;
9257 if (!FRAME_WINDOW_P (it->f))
9259 struct text_pos textpos;
9261 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
9262 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
9263 reseat (it, textpos, 1);
9264 it->vpos += pos.vpos;
9265 it->current_y += pos.vpos;
9271 /* DVPOS == 0 means move to the start of the screen line. */
9272 move_it_vertically_backward (it
, 0);
9273 /* Let next call to line_bottom_y calculate real line height */
9278 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
9279 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
9281 /* Only move to the next buffer position if we ended up in a
9282 string from display property, not in an overlay string
9283 (before-string or after-string). That is because the
9284 latter don't conceal the underlying buffer position, so
9285 we can ask to move the iterator to the exact position we
9286 are interested in. Note that, even if we are already at
9287 IT_CHARPOS (*it), the call below is not a no-op, as it
9288 will detect that we are at the end of the string, pop the
9289 iterator, and compute it->current_x and it->hpos
9291 move_it_to (it
, IT_CHARPOS (*it
) + it
->string_from_display_prop_p
,
9292 -1, -1, -1, MOVE_TO_POS
);
9298 void *it2data
= NULL
;
9299 ptrdiff_t start_charpos
, i
;
9301 /* Start at the beginning of the screen line containing IT's
9302 position. This may actually move vertically backwards,
9303 in case of overlays, so adjust dvpos accordingly. */
9305 move_it_vertically_backward (it
, 0);
9308 /* Go back -DVPOS visible lines and reseat the iterator there. */
9309 start_charpos
= IT_CHARPOS (*it
);
9310 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
9311 back_to_previous_visible_line_start (it
);
9312 reseat (it
, it
->current
.pos
, 1);
9314 /* Move further back if we end up in a string or an image. */
9315 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
9317 /* First try to move to start of display line. */
9319 move_it_vertically_backward (it
, 0);
9321 if (IT_POS_VALID_AFTER_MOVE_P (it
))
9323 /* If start of line is still in string or image,
9324 move further back. */
9325 back_to_previous_visible_line_start (it
);
9326 reseat (it
, it
->current
.pos
, 1);
9330 it
->current_x
= it
->hpos
= 0;
9332 /* Above call may have moved too far if continuation lines
9333 are involved. Scan forward and see if it did. */
9334 SAVE_IT (it2
, *it
, it2data
);
9335 it2
.vpos
= it2
.current_y
= 0;
9336 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
9337 it
->vpos
-= it2
.vpos
;
9338 it
->current_y
-= it2
.current_y
;
9339 it
->current_x
= it
->hpos
= 0;
9341 /* If we moved too far back, move IT some lines forward. */
9342 if (it2
.vpos
> -dvpos
)
9344 int delta
= it2
.vpos
+ dvpos
;
9346 RESTORE_IT (&it2
, &it2
, it2data
);
9347 SAVE_IT (it2
, *it
, it2data
);
9348 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
9349 /* Move back again if we got too far ahead. */
9350 if (IT_CHARPOS (*it
) >= start_charpos
)
9351 RESTORE_IT (it
, &it2
, it2data
);
9353 bidi_unshelve_cache (it2data
, 1);
9356 RESTORE_IT (it
, it
, it2data
);
9360 /* Return 1 if IT points into the middle of a display vector. */
9363 in_display_vector_p (struct it
*it
)
9365 return (it
->method
== GET_FROM_DISPLAY_VECTOR
9366 && it
->current
.dpvec_index
> 0
9367 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
9371 /***********************************************************************
9373 ***********************************************************************/
9376 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
9380 add_to_log (const char *format
, Lisp_Object arg1
, Lisp_Object arg2
)
9382 Lisp_Object args
[3];
9383 Lisp_Object msg
, fmt
;
9386 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
9390 GCPRO4 (fmt
, msg
, arg1
, arg2
);
9392 args
[0] = fmt
= build_string (format
);
9395 msg
= Fformat (3, args
);
9397 len
= SBYTES (msg
) + 1;
9398 buffer
= SAFE_ALLOCA (len
);
9399 memcpy (buffer
, SDATA (msg
), len
);
9401 message_dolog (buffer
, len
- 1, 1, 0);
9408 /* Output a newline in the *Messages* buffer if "needs" one. */
9411 message_log_maybe_newline (void)
9413 if (message_log_need_newline
)
9414 message_dolog ("", 0, 1, 0);
9418 /* Add a string M of length NBYTES to the message log, optionally
9419 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
9420 nonzero, means interpret the contents of M as multibyte. This
9421 function calls low-level routines in order to bypass text property
9422 hooks, etc. which might not be safe to run.
9424 This may GC (insert may run before/after change hooks),
9425 so the buffer M must NOT point to a Lisp string. */
9428 message_dolog (const char *m
, ptrdiff_t nbytes
, int nlflag
, int multibyte
)
9430 const unsigned char *msg
= (const unsigned char *) m
;
9432 if (!NILP (Vmemory_full
))
9435 if (!NILP (Vmessage_log_max
))
9437 struct buffer
*oldbuf
;
9438 Lisp_Object oldpoint
, oldbegv
, oldzv
;
9439 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
9440 ptrdiff_t point_at_end
= 0;
9441 ptrdiff_t zv_at_end
= 0;
9442 Lisp_Object old_deactivate_mark
, tem
;
9443 struct gcpro gcpro1
;
9445 old_deactivate_mark
= Vdeactivate_mark
;
9446 oldbuf
= current_buffer
;
9447 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
9448 bset_undo_list (current_buffer
, Qt
);
9450 oldpoint
= message_dolog_marker1
;
9451 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
9452 oldbegv
= message_dolog_marker2
;
9453 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
9454 oldzv
= message_dolog_marker3
;
9455 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
9456 GCPRO1 (old_deactivate_mark
);
9464 BEGV_BYTE
= BEG_BYTE
;
9467 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9469 /* Insert the string--maybe converting multibyte to single byte
9470 or vice versa, so that all the text fits the buffer. */
9472 && NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9478 /* Convert a multibyte string to single-byte
9479 for the *Message* buffer. */
9480 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
9482 c
= string_char_and_length (msg
+ i
, &char_bytes
);
9483 work
[0] = (ASCII_CHAR_P (c
)
9485 : multibyte_char_to_unibyte (c
));
9486 insert_1_both (work
, 1, 1, 1, 0, 0);
9489 else if (! multibyte
9490 && ! NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9494 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9495 /* Convert a single-byte string to multibyte
9496 for the *Message* buffer. */
9497 for (i
= 0; i
< nbytes
; i
++)
9500 MAKE_CHAR_MULTIBYTE (c
);
9501 char_bytes
= CHAR_STRING (c
, str
);
9502 insert_1_both ((char *) str
, 1, char_bytes
, 1, 0, 0);
9506 insert_1 (m
, nbytes
, 1, 0, 0);
9510 ptrdiff_t this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
;
9512 insert_1 ("\n", 1, 1, 0, 0);
9514 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9516 this_bol_byte
= PT_BYTE
;
9518 /* See if this line duplicates the previous one.
9519 If so, combine duplicates. */
9522 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9524 prev_bol_byte
= PT_BYTE
;
9526 dups
= message_log_check_duplicate (prev_bol_byte
,
9530 del_range_both (prev_bol
, prev_bol_byte
,
9531 this_bol
, this_bol_byte
, 0);
9534 char dupstr
[sizeof " [ times]"
9535 + INT_STRLEN_BOUND (printmax_t
)];
9537 /* If you change this format, don't forget to also
9538 change message_log_check_duplicate. */
9539 int duplen
= sprintf (dupstr
, " [%"pMd
" times]", dups
);
9540 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
9541 insert_1 (dupstr
, duplen
, 1, 0, 1);
9546 /* If we have more than the desired maximum number of lines
9547 in the *Messages* buffer now, delete the oldest ones.
9548 This is safe because we don't have undo in this buffer. */
9550 if (NATNUMP (Vmessage_log_max
))
9552 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
9553 -XFASTINT (Vmessage_log_max
) - 1, 0);
9554 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
9557 BEGV
= XMARKER (oldbegv
)->charpos
;
9558 BEGV_BYTE
= marker_byte_position (oldbegv
);
9567 ZV
= XMARKER (oldzv
)->charpos
;
9568 ZV_BYTE
= marker_byte_position (oldzv
);
9572 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9574 /* We can't do Fgoto_char (oldpoint) because it will run some
9576 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
9577 XMARKER (oldpoint
)->bytepos
);
9580 unchain_marker (XMARKER (oldpoint
));
9581 unchain_marker (XMARKER (oldbegv
));
9582 unchain_marker (XMARKER (oldzv
));
9584 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
9585 set_buffer_internal (oldbuf
);
9587 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
9588 message_log_need_newline
= !nlflag
;
9589 Vdeactivate_mark
= old_deactivate_mark
;
9594 /* We are at the end of the buffer after just having inserted a newline.
9595 (Note: We depend on the fact we won't be crossing the gap.)
9596 Check to see if the most recent message looks a lot like the previous one.
9597 Return 0 if different, 1 if the new one should just replace it, or a
9598 value N > 1 if we should also append " [N times]". */
9601 message_log_check_duplicate (ptrdiff_t prev_bol_byte
, ptrdiff_t this_bol_byte
)
9604 ptrdiff_t len
= Z_BYTE
- 1 - this_bol_byte
;
9606 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
9607 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
9609 for (i
= 0; i
< len
; i
++)
9611 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
9619 if (*p1
++ == ' ' && *p1
++ == '[')
9622 intmax_t n
= strtoimax ((char *) p1
, &pend
, 10);
9623 if (0 < n
&& n
< INTMAX_MAX
&& strncmp (pend
, " times]\n", 8) == 0)
9630 /* Display an echo area message M with a specified length of NBYTES
9631 bytes. The string may include null characters. If M is 0, clear
9632 out any existing message, and let the mini-buffer text show
9635 This may GC, so the buffer M must NOT point to a Lisp string. */
9638 message2 (const char *m
, ptrdiff_t nbytes
, int multibyte
)
9640 /* First flush out any partial line written with print. */
9641 message_log_maybe_newline ();
9643 message_dolog (m
, nbytes
, 1, multibyte
);
9644 message2_nolog (m
, nbytes
, multibyte
);
9648 /* The non-logging counterpart of message2. */
9651 message2_nolog (const char *m
, ptrdiff_t nbytes
, int multibyte
)
9653 struct frame
*sf
= SELECTED_FRAME ();
9654 message_enable_multibyte
= multibyte
;
9656 if (FRAME_INITIAL_P (sf
))
9658 if (noninteractive_need_newline
)
9659 putc ('\n', stderr
);
9660 noninteractive_need_newline
= 0;
9662 fwrite (m
, nbytes
, 1, stderr
);
9663 if (cursor_in_echo_area
== 0)
9664 fprintf (stderr
, "\n");
9667 /* A null message buffer means that the frame hasn't really been
9668 initialized yet. Error messages get reported properly by
9669 cmd_error, so this must be just an informative message; toss it. */
9670 else if (INTERACTIVE
9671 && sf
->glyphs_initialized_p
9672 && FRAME_MESSAGE_BUF (sf
))
9674 Lisp_Object mini_window
;
9677 /* Get the frame containing the mini-buffer
9678 that the selected frame is using. */
9679 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9680 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9682 FRAME_SAMPLE_VISIBILITY (f
);
9683 if (FRAME_VISIBLE_P (sf
)
9684 && ! FRAME_VISIBLE_P (f
))
9685 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
9689 set_message (m
, Qnil
, nbytes
, multibyte
);
9690 if (minibuffer_auto_raise
)
9691 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
9694 clear_message (1, 1);
9696 do_pending_window_change (0);
9697 echo_area_display (1);
9698 do_pending_window_change (0);
9699 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
9700 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
9705 /* Display an echo area message M with a specified length of NBYTES
9706 bytes. The string may include null characters. If M is not a
9707 string, clear out any existing message, and let the mini-buffer
9710 This function cancels echoing. */
9713 message3 (Lisp_Object m
, ptrdiff_t nbytes
, int multibyte
)
9715 struct gcpro gcpro1
;
9718 clear_message (1,1);
9721 /* First flush out any partial line written with print. */
9722 message_log_maybe_newline ();
9726 char *buffer
= SAFE_ALLOCA (nbytes
);
9727 memcpy (buffer
, SDATA (m
), nbytes
);
9728 message_dolog (buffer
, nbytes
, 1, multibyte
);
9731 message3_nolog (m
, nbytes
, multibyte
);
9737 /* The non-logging version of message3.
9738 This does not cancel echoing, because it is used for echoing.
9739 Perhaps we need to make a separate function for echoing
9740 and make this cancel echoing. */
9743 message3_nolog (Lisp_Object m
, ptrdiff_t nbytes
, int multibyte
)
9745 struct frame
*sf
= SELECTED_FRAME ();
9746 message_enable_multibyte
= multibyte
;
9748 if (FRAME_INITIAL_P (sf
))
9750 if (noninteractive_need_newline
)
9751 putc ('\n', stderr
);
9752 noninteractive_need_newline
= 0;
9754 fwrite (SDATA (m
), nbytes
, 1, stderr
);
9755 if (cursor_in_echo_area
== 0)
9756 fprintf (stderr
, "\n");
9759 /* A null message buffer means that the frame hasn't really been
9760 initialized yet. Error messages get reported properly by
9761 cmd_error, so this must be just an informative message; toss it. */
9762 else if (INTERACTIVE
9763 && sf
->glyphs_initialized_p
9764 && FRAME_MESSAGE_BUF (sf
))
9766 Lisp_Object mini_window
;
9770 /* Get the frame containing the mini-buffer
9771 that the selected frame is using. */
9772 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9773 frame
= XWINDOW (mini_window
)->frame
;
9776 FRAME_SAMPLE_VISIBILITY (f
);
9777 if (FRAME_VISIBLE_P (sf
)
9778 && !FRAME_VISIBLE_P (f
))
9779 Fmake_frame_visible (frame
);
9781 if (STRINGP (m
) && SCHARS (m
) > 0)
9783 set_message (NULL
, m
, nbytes
, multibyte
);
9784 if (minibuffer_auto_raise
)
9785 Fraise_frame (frame
);
9786 /* Assume we are not echoing.
9787 (If we are, echo_now will override this.) */
9788 echo_message_buffer
= Qnil
;
9791 clear_message (1, 1);
9793 do_pending_window_change (0);
9794 echo_area_display (1);
9795 do_pending_window_change (0);
9796 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
9797 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
9802 /* Display a null-terminated echo area message M. If M is 0, clear
9803 out any existing message, and let the mini-buffer text show through.
9805 The buffer M must continue to exist until after the echo area gets
9806 cleared or some other message gets displayed there. Do not pass
9807 text that is stored in a Lisp string. Do not pass text in a buffer
9808 that was alloca'd. */
9811 message1 (const char *m
)
9813 message2 (m
, (m
? strlen (m
) : 0), 0);
9817 /* The non-logging counterpart of message1. */
9820 message1_nolog (const char *m
)
9822 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
9825 /* Display a message M which contains a single %s
9826 which gets replaced with STRING. */
9829 message_with_string (const char *m
, Lisp_Object string
, int log
)
9831 CHECK_STRING (string
);
9837 if (noninteractive_need_newline
)
9838 putc ('\n', stderr
);
9839 noninteractive_need_newline
= 0;
9840 fprintf (stderr
, m
, SDATA (string
));
9841 if (!cursor_in_echo_area
)
9842 fprintf (stderr
, "\n");
9846 else if (INTERACTIVE
)
9848 /* The frame whose minibuffer we're going to display the message on.
9849 It may be larger than the selected frame, so we need
9850 to use its buffer, not the selected frame's buffer. */
9851 Lisp_Object mini_window
;
9852 struct frame
*f
, *sf
= SELECTED_FRAME ();
9854 /* Get the frame containing the minibuffer
9855 that the selected frame is using. */
9856 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9857 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9859 /* A null message buffer means that the frame hasn't really been
9860 initialized yet. Error messages get reported properly by
9861 cmd_error, so this must be just an informative message; toss it. */
9862 if (FRAME_MESSAGE_BUF (f
))
9864 Lisp_Object args
[2], msg
;
9865 struct gcpro gcpro1
, gcpro2
;
9867 args
[0] = build_string (m
);
9868 args
[1] = msg
= string
;
9869 GCPRO2 (args
[0], msg
);
9872 msg
= Fformat (2, args
);
9875 message3 (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
9877 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
9881 /* Print should start at the beginning of the message
9882 buffer next time. */
9883 message_buf_print
= 0;
9889 /* Dump an informative message to the minibuf. If M is 0, clear out
9890 any existing message, and let the mini-buffer text show through. */
9893 vmessage (const char *m
, va_list ap
)
9899 if (noninteractive_need_newline
)
9900 putc ('\n', stderr
);
9901 noninteractive_need_newline
= 0;
9902 vfprintf (stderr
, m
, ap
);
9903 if (cursor_in_echo_area
== 0)
9904 fprintf (stderr
, "\n");
9908 else if (INTERACTIVE
)
9910 /* The frame whose mini-buffer we're going to display the message
9911 on. It may be larger than the selected frame, so we need to
9912 use its buffer, not the selected frame's buffer. */
9913 Lisp_Object mini_window
;
9914 struct frame
*f
, *sf
= SELECTED_FRAME ();
9916 /* Get the frame containing the mini-buffer
9917 that the selected frame is using. */
9918 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9919 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9921 /* A null message buffer means that the frame hasn't really been
9922 initialized yet. Error messages get reported properly by
9923 cmd_error, so this must be just an informative message; toss
9925 if (FRAME_MESSAGE_BUF (f
))
9931 len
= doprnt (FRAME_MESSAGE_BUF (f
),
9932 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, ap
);
9934 message2 (FRAME_MESSAGE_BUF (f
), len
, 1);
9939 /* Print should start at the beginning of the message
9940 buffer next time. */
9941 message_buf_print
= 0;
9947 message (const char *m
, ...)
9957 /* The non-logging version of message. */
9960 message_nolog (const char *m
, ...)
9962 Lisp_Object old_log_max
;
9965 old_log_max
= Vmessage_log_max
;
9966 Vmessage_log_max
= Qnil
;
9968 Vmessage_log_max
= old_log_max
;
9974 /* Display the current message in the current mini-buffer. This is
9975 only called from error handlers in process.c, and is not time
9979 update_echo_area (void)
9981 if (!NILP (echo_area_buffer
[0]))
9984 string
= Fcurrent_message ();
9985 message3 (string
, SBYTES (string
),
9986 !NILP (BVAR (current_buffer
, enable_multibyte_characters
)));
9991 /* Make sure echo area buffers in `echo_buffers' are live.
9992 If they aren't, make new ones. */
9995 ensure_echo_area_buffers (void)
9999 for (i
= 0; i
< 2; ++i
)
10000 if (!BUFFERP (echo_buffer
[i
])
10001 || !BUFFER_LIVE_P (XBUFFER (echo_buffer
[i
])))
10004 Lisp_Object old_buffer
;
10007 old_buffer
= echo_buffer
[i
];
10008 echo_buffer
[i
] = Fget_buffer_create
10009 (make_formatted_string (name
, " *Echo Area %d*", i
));
10010 bset_truncate_lines (XBUFFER (echo_buffer
[i
]), Qnil
);
10011 /* to force word wrap in echo area -
10012 it was decided to postpone this*/
10013 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
10015 for (j
= 0; j
< 2; ++j
)
10016 if (EQ (old_buffer
, echo_area_buffer
[j
]))
10017 echo_area_buffer
[j
] = echo_buffer
[i
];
10022 /* Call FN with args A1..A4 with either the current or last displayed
10023 echo_area_buffer as current buffer.
10025 WHICH zero means use the current message buffer
10026 echo_area_buffer[0]. If that is nil, choose a suitable buffer
10027 from echo_buffer[] and clear it.
10029 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
10030 suitable buffer from echo_buffer[] and clear it.
10032 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
10033 that the current message becomes the last displayed one, make
10034 choose a suitable buffer for echo_area_buffer[0], and clear it.
10036 Value is what FN returns. */
10039 with_echo_area_buffer (struct window
*w
, int which
,
10040 int (*fn
) (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t),
10041 ptrdiff_t a1
, Lisp_Object a2
, ptrdiff_t a3
, ptrdiff_t a4
)
10043 Lisp_Object buffer
;
10044 int this_one
, the_other
, clear_buffer_p
, rc
;
10045 ptrdiff_t count
= SPECPDL_INDEX ();
10047 /* If buffers aren't live, make new ones. */
10048 ensure_echo_area_buffers ();
10050 clear_buffer_p
= 0;
10053 this_one
= 0, the_other
= 1;
10054 else if (which
> 0)
10055 this_one
= 1, the_other
= 0;
10058 this_one
= 0, the_other
= 1;
10059 clear_buffer_p
= 1;
10061 /* We need a fresh one in case the current echo buffer equals
10062 the one containing the last displayed echo area message. */
10063 if (!NILP (echo_area_buffer
[this_one
])
10064 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
10065 echo_area_buffer
[this_one
] = Qnil
;
10068 /* Choose a suitable buffer from echo_buffer[] is we don't
10070 if (NILP (echo_area_buffer
[this_one
]))
10072 echo_area_buffer
[this_one
]
10073 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
10074 ? echo_buffer
[the_other
]
10075 : echo_buffer
[this_one
]);
10076 clear_buffer_p
= 1;
10079 buffer
= echo_area_buffer
[this_one
];
10081 /* Don't get confused by reusing the buffer used for echoing
10082 for a different purpose. */
10083 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
10086 record_unwind_protect (unwind_with_echo_area_buffer
,
10087 with_echo_area_buffer_unwind_data (w
));
10089 /* Make the echo area buffer current. Note that for display
10090 purposes, it is not necessary that the displayed window's buffer
10091 == current_buffer, except for text property lookup. So, let's
10092 only set that buffer temporarily here without doing a full
10093 Fset_window_buffer. We must also change w->pointm, though,
10094 because otherwise an assertions in unshow_buffer fails, and Emacs
10096 set_buffer_internal_1 (XBUFFER (buffer
));
10099 wset_buffer (w
, buffer
);
10100 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
10103 bset_undo_list (current_buffer
, Qt
);
10104 bset_read_only (current_buffer
, Qnil
);
10105 specbind (Qinhibit_read_only
, Qt
);
10106 specbind (Qinhibit_modification_hooks
, Qt
);
10108 if (clear_buffer_p
&& Z
> BEG
)
10109 del_range (BEG
, Z
);
10111 eassert (BEGV
>= BEG
);
10112 eassert (ZV
<= Z
&& ZV
>= BEGV
);
10114 rc
= fn (a1
, a2
, a3
, a4
);
10116 eassert (BEGV
>= BEG
);
10117 eassert (ZV
<= Z
&& ZV
>= BEGV
);
10119 unbind_to (count
, Qnil
);
10124 /* Save state that should be preserved around the call to the function
10125 FN called in with_echo_area_buffer. */
10128 with_echo_area_buffer_unwind_data (struct window
*w
)
10131 Lisp_Object vector
, tmp
;
10133 /* Reduce consing by keeping one vector in
10134 Vwith_echo_area_save_vector. */
10135 vector
= Vwith_echo_area_save_vector
;
10136 Vwith_echo_area_save_vector
= Qnil
;
10139 vector
= Fmake_vector (make_number (7), Qnil
);
10141 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
10142 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
10143 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
10147 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
10148 ASET (vector
, i
, w
->buffer
); ++i
;
10149 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->charpos
)); ++i
;
10150 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->bytepos
)); ++i
;
10155 for (; i
< end
; ++i
)
10156 ASET (vector
, i
, Qnil
);
10159 eassert (i
== ASIZE (vector
));
10164 /* Restore global state from VECTOR which was created by
10165 with_echo_area_buffer_unwind_data. */
10168 unwind_with_echo_area_buffer (Lisp_Object vector
)
10170 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
10171 Vdeactivate_mark
= AREF (vector
, 1);
10172 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
10174 if (WINDOWP (AREF (vector
, 3)))
10177 Lisp_Object buffer
, charpos
, bytepos
;
10179 w
= XWINDOW (AREF (vector
, 3));
10180 buffer
= AREF (vector
, 4);
10181 charpos
= AREF (vector
, 5);
10182 bytepos
= AREF (vector
, 6);
10184 wset_buffer (w
, buffer
);
10185 set_marker_both (w
->pointm
, buffer
,
10186 XFASTINT (charpos
), XFASTINT (bytepos
));
10189 Vwith_echo_area_save_vector
= vector
;
10194 /* Set up the echo area for use by print functions. MULTIBYTE_P
10195 non-zero means we will print multibyte. */
10198 setup_echo_area_for_printing (int multibyte_p
)
10200 /* If we can't find an echo area any more, exit. */
10201 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
10202 Fkill_emacs (Qnil
);
10204 ensure_echo_area_buffers ();
10206 if (!message_buf_print
)
10208 /* A message has been output since the last time we printed.
10209 Choose a fresh echo area buffer. */
10210 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10211 echo_area_buffer
[0] = echo_buffer
[1];
10213 echo_area_buffer
[0] = echo_buffer
[0];
10215 /* Switch to that buffer and clear it. */
10216 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10217 bset_truncate_lines (current_buffer
, Qnil
);
10221 ptrdiff_t count
= SPECPDL_INDEX ();
10222 specbind (Qinhibit_read_only
, Qt
);
10223 /* Note that undo recording is always disabled. */
10224 del_range (BEG
, Z
);
10225 unbind_to (count
, Qnil
);
10227 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10229 /* Set up the buffer for the multibyteness we need. */
10231 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10232 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
10234 /* Raise the frame containing the echo area. */
10235 if (minibuffer_auto_raise
)
10237 struct frame
*sf
= SELECTED_FRAME ();
10238 Lisp_Object mini_window
;
10239 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10240 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
10243 message_log_maybe_newline ();
10244 message_buf_print
= 1;
10248 if (NILP (echo_area_buffer
[0]))
10250 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10251 echo_area_buffer
[0] = echo_buffer
[1];
10253 echo_area_buffer
[0] = echo_buffer
[0];
10256 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
10258 /* Someone switched buffers between print requests. */
10259 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10260 bset_truncate_lines (current_buffer
, Qnil
);
10266 /* Display an echo area message in window W. Value is non-zero if W's
10267 height is changed. If display_last_displayed_message_p is
10268 non-zero, display the message that was last displayed, otherwise
10269 display the current message. */
10272 display_echo_area (struct window
*w
)
10274 int i
, no_message_p
, window_height_changed_p
;
10276 /* Temporarily disable garbage collections while displaying the echo
10277 area. This is done because a GC can print a message itself.
10278 That message would modify the echo area buffer's contents while a
10279 redisplay of the buffer is going on, and seriously confuse
10281 ptrdiff_t count
= inhibit_garbage_collection ();
10283 /* If there is no message, we must call display_echo_area_1
10284 nevertheless because it resizes the window. But we will have to
10285 reset the echo_area_buffer in question to nil at the end because
10286 with_echo_area_buffer will sets it to an empty buffer. */
10287 i
= display_last_displayed_message_p
? 1 : 0;
10288 no_message_p
= NILP (echo_area_buffer
[i
]);
10290 window_height_changed_p
10291 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
10292 display_echo_area_1
,
10293 (intptr_t) w
, Qnil
, 0, 0);
10296 echo_area_buffer
[i
] = Qnil
;
10298 unbind_to (count
, Qnil
);
10299 return window_height_changed_p
;
10303 /* Helper for display_echo_area. Display the current buffer which
10304 contains the current echo area message in window W, a mini-window,
10305 a pointer to which is passed in A1. A2..A4 are currently not used.
10306 Change the height of W so that all of the message is displayed.
10307 Value is non-zero if height of W was changed. */
10310 display_echo_area_1 (ptrdiff_t a1
, Lisp_Object a2
, ptrdiff_t a3
, ptrdiff_t a4
)
10313 struct window
*w
= (struct window
*) i1
;
10314 Lisp_Object window
;
10315 struct text_pos start
;
10316 int window_height_changed_p
= 0;
10318 /* Do this before displaying, so that we have a large enough glyph
10319 matrix for the display. If we can't get enough space for the
10320 whole text, display the last N lines. That works by setting w->start. */
10321 window_height_changed_p
= resize_mini_window (w
, 0);
10323 /* Use the starting position chosen by resize_mini_window. */
10324 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
10327 clear_glyph_matrix (w
->desired_matrix
);
10328 XSETWINDOW (window
, w
);
10329 try_window (window
, start
, 0);
10331 return window_height_changed_p
;
10335 /* Resize the echo area window to exactly the size needed for the
10336 currently displayed message, if there is one. If a mini-buffer
10337 is active, don't shrink it. */
10340 resize_echo_area_exactly (void)
10342 if (BUFFERP (echo_area_buffer
[0])
10343 && WINDOWP (echo_area_window
))
10345 struct window
*w
= XWINDOW (echo_area_window
);
10347 Lisp_Object resize_exactly
;
10349 if (minibuf_level
== 0)
10350 resize_exactly
= Qt
;
10352 resize_exactly
= Qnil
;
10354 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
10355 (intptr_t) w
, resize_exactly
,
10359 ++windows_or_buffers_changed
;
10360 ++update_mode_lines
;
10361 redisplay_internal ();
10367 /* Callback function for with_echo_area_buffer, when used from
10368 resize_echo_area_exactly. A1 contains a pointer to the window to
10369 resize, EXACTLY non-nil means resize the mini-window exactly to the
10370 size of the text displayed. A3 and A4 are not used. Value is what
10371 resize_mini_window returns. */
10374 resize_mini_window_1 (ptrdiff_t a1
, Lisp_Object exactly
, ptrdiff_t a3
, ptrdiff_t a4
)
10377 return resize_mini_window ((struct window
*) i1
, !NILP (exactly
));
10381 /* Resize mini-window W to fit the size of its contents. EXACT_P
10382 means size the window exactly to the size needed. Otherwise, it's
10383 only enlarged until W's buffer is empty.
10385 Set W->start to the right place to begin display. If the whole
10386 contents fit, start at the beginning. Otherwise, start so as
10387 to make the end of the contents appear. This is particularly
10388 important for y-or-n-p, but seems desirable generally.
10390 Value is non-zero if the window height has been changed. */
10393 resize_mini_window (struct window
*w
, int exact_p
)
10395 struct frame
*f
= XFRAME (w
->frame
);
10396 int window_height_changed_p
= 0;
10398 eassert (MINI_WINDOW_P (w
));
10400 /* By default, start display at the beginning. */
10401 set_marker_both (w
->start
, w
->buffer
,
10402 BUF_BEGV (XBUFFER (w
->buffer
)),
10403 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
10405 /* Don't resize windows while redisplaying a window; it would
10406 confuse redisplay functions when the size of the window they are
10407 displaying changes from under them. Such a resizing can happen,
10408 for instance, when which-func prints a long message while
10409 we are running fontification-functions. We're running these
10410 functions with safe_call which binds inhibit-redisplay to t. */
10411 if (!NILP (Vinhibit_redisplay
))
10414 /* Nil means don't try to resize. */
10415 if (NILP (Vresize_mini_windows
)
10416 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
10419 if (!FRAME_MINIBUF_ONLY_P (f
))
10422 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
10423 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
10425 EMACS_INT max_height
;
10426 int unit
= FRAME_LINE_HEIGHT (f
);
10427 struct text_pos start
;
10428 struct buffer
*old_current_buffer
= NULL
;
10430 if (current_buffer
!= XBUFFER (w
->buffer
))
10432 old_current_buffer
= current_buffer
;
10433 set_buffer_internal (XBUFFER (w
->buffer
));
10436 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10438 /* Compute the max. number of lines specified by the user. */
10439 if (FLOATP (Vmax_mini_window_height
))
10440 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
10441 else if (INTEGERP (Vmax_mini_window_height
))
10442 max_height
= XINT (Vmax_mini_window_height
);
10444 max_height
= total_height
/ 4;
10446 /* Correct that max. height if it's bogus. */
10447 max_height
= max (1, max_height
);
10448 max_height
= min (total_height
, max_height
);
10450 /* Find out the height of the text in the window. */
10451 if (it
.line_wrap
== TRUNCATE
)
10456 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
10457 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
10458 height
= it
.current_y
+ last_height
;
10460 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
10461 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
10462 height
= (height
+ unit
- 1) / unit
;
10465 /* Compute a suitable window start. */
10466 if (height
> max_height
)
10468 height
= max_height
;
10469 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10470 move_it_vertically_backward (&it
, (height
- 1) * unit
);
10471 start
= it
.current
.pos
;
10474 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
10475 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
10477 if (EQ (Vresize_mini_windows
, Qgrow_only
))
10479 /* Let it grow only, until we display an empty message, in which
10480 case the window shrinks again. */
10481 if (height
> WINDOW_TOTAL_LINES (w
))
10483 int old_height
= WINDOW_TOTAL_LINES (w
);
10484 freeze_window_starts (f
, 1);
10485 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10486 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10488 else if (height
< WINDOW_TOTAL_LINES (w
)
10489 && (exact_p
|| BEGV
== ZV
))
10491 int old_height
= WINDOW_TOTAL_LINES (w
);
10492 freeze_window_starts (f
, 0);
10493 shrink_mini_window (w
);
10494 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10499 /* Always resize to exact size needed. */
10500 if (height
> WINDOW_TOTAL_LINES (w
))
10502 int old_height
= WINDOW_TOTAL_LINES (w
);
10503 freeze_window_starts (f
, 1);
10504 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10505 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10507 else if (height
< WINDOW_TOTAL_LINES (w
))
10509 int old_height
= WINDOW_TOTAL_LINES (w
);
10510 freeze_window_starts (f
, 0);
10511 shrink_mini_window (w
);
10515 freeze_window_starts (f
, 1);
10516 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10519 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10523 if (old_current_buffer
)
10524 set_buffer_internal (old_current_buffer
);
10527 return window_height_changed_p
;
10531 /* Value is the current message, a string, or nil if there is no
10532 current message. */
10535 current_message (void)
10539 if (!BUFFERP (echo_area_buffer
[0]))
10543 with_echo_area_buffer (0, 0, current_message_1
,
10544 (intptr_t) &msg
, Qnil
, 0, 0);
10546 echo_area_buffer
[0] = Qnil
;
10554 current_message_1 (ptrdiff_t a1
, Lisp_Object a2
, ptrdiff_t a3
, ptrdiff_t a4
)
10557 Lisp_Object
*msg
= (Lisp_Object
*) i1
;
10560 *msg
= make_buffer_string (BEG
, Z
, 1);
10567 /* Push the current message on Vmessage_stack for later restoration
10568 by restore_message. Value is non-zero if the current message isn't
10569 empty. This is a relatively infrequent operation, so it's not
10570 worth optimizing. */
10573 push_message (void)
10575 Lisp_Object msg
= current_message ();
10576 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
10577 return STRINGP (msg
);
10581 /* Restore message display from the top of Vmessage_stack. */
10584 restore_message (void)
10588 eassert (CONSP (Vmessage_stack
));
10589 msg
= XCAR (Vmessage_stack
);
10591 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
10593 message3_nolog (msg
, 0, 0);
10597 /* Handler for record_unwind_protect calling pop_message. */
10600 pop_message_unwind (Lisp_Object dummy
)
10606 /* Pop the top-most entry off Vmessage_stack. */
10611 eassert (CONSP (Vmessage_stack
));
10612 Vmessage_stack
= XCDR (Vmessage_stack
);
10616 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
10617 exits. If the stack is not empty, we have a missing pop_message
10621 check_message_stack (void)
10623 if (!NILP (Vmessage_stack
))
10628 /* Truncate to NCHARS what will be displayed in the echo area the next
10629 time we display it---but don't redisplay it now. */
10632 truncate_echo_area (ptrdiff_t nchars
)
10635 echo_area_buffer
[0] = Qnil
;
10636 /* A null message buffer means that the frame hasn't really been
10637 initialized yet. Error messages get reported properly by
10638 cmd_error, so this must be just an informative message; toss it. */
10639 else if (!noninteractive
10641 && !NILP (echo_area_buffer
[0]))
10643 struct frame
*sf
= SELECTED_FRAME ();
10644 if (FRAME_MESSAGE_BUF (sf
))
10645 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
10650 /* Helper function for truncate_echo_area. Truncate the current
10651 message to at most NCHARS characters. */
10654 truncate_message_1 (ptrdiff_t nchars
, Lisp_Object a2
, ptrdiff_t a3
, ptrdiff_t a4
)
10656 if (BEG
+ nchars
< Z
)
10657 del_range (BEG
+ nchars
, Z
);
10659 echo_area_buffer
[0] = Qnil
;
10663 /* Set the current message to a substring of S or STRING.
10665 If STRING is a Lisp string, set the message to the first NBYTES
10666 bytes from STRING. NBYTES zero means use the whole string. If
10667 STRING is multibyte, the message will be displayed multibyte.
10669 If S is not null, set the message to the first LEN bytes of S. LEN
10670 zero means use the whole string. MULTIBYTE_P non-zero means S is
10671 multibyte. Display the message multibyte in that case.
10673 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
10674 to t before calling set_message_1 (which calls insert).
10678 set_message (const char *s
, Lisp_Object string
,
10679 ptrdiff_t nbytes
, int multibyte_p
)
10681 message_enable_multibyte
10682 = ((s
&& multibyte_p
)
10683 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
10685 with_echo_area_buffer (0, -1, set_message_1
,
10686 (intptr_t) s
, string
, nbytes
, multibyte_p
);
10687 message_buf_print
= 0;
10688 help_echo_showing_p
= 0;
10690 if (STRINGP (Vdebug_on_message
)
10691 && fast_string_match (Vdebug_on_message
, string
) >= 0)
10692 call_debugger (list2 (Qerror
, string
));
10696 /* Helper function for set_message. Arguments have the same meaning
10697 as there, with A1 corresponding to S and A2 corresponding to STRING
10698 This function is called with the echo area buffer being
10702 set_message_1 (ptrdiff_t a1
, Lisp_Object a2
, ptrdiff_t nbytes
, ptrdiff_t multibyte_p
)
10705 const char *s
= (const char *) i1
;
10706 const unsigned char *msg
= (const unsigned char *) s
;
10707 Lisp_Object string
= a2
;
10709 /* Change multibyteness of the echo buffer appropriately. */
10710 if (message_enable_multibyte
10711 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10712 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
10714 bset_truncate_lines (current_buffer
, message_truncate_lines
? Qt
: Qnil
);
10715 if (!NILP (BVAR (current_buffer
, bidi_display_reordering
)))
10716 bset_bidi_paragraph_direction (current_buffer
, Qleft_to_right
);
10718 /* Insert new message at BEG. */
10719 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10721 if (STRINGP (string
))
10726 nbytes
= SBYTES (string
);
10727 nchars
= string_byte_to_char (string
, nbytes
);
10729 /* This function takes care of single/multibyte conversion. We
10730 just have to ensure that the echo area buffer has the right
10731 setting of enable_multibyte_characters. */
10732 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
10737 nbytes
= strlen (s
);
10739 if (multibyte_p
&& NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10741 /* Convert from multi-byte to single-byte. */
10746 /* Convert a multibyte string to single-byte. */
10747 for (i
= 0; i
< nbytes
; i
+= n
)
10749 c
= string_char_and_length (msg
+ i
, &n
);
10750 work
[0] = (ASCII_CHAR_P (c
)
10752 : multibyte_char_to_unibyte (c
));
10753 insert_1_both (work
, 1, 1, 1, 0, 0);
10756 else if (!multibyte_p
10757 && !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10759 /* Convert from single-byte to multi-byte. */
10762 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
10764 /* Convert a single-byte string to multibyte. */
10765 for (i
= 0; i
< nbytes
; i
++)
10768 MAKE_CHAR_MULTIBYTE (c
);
10769 n
= CHAR_STRING (c
, str
);
10770 insert_1_both ((char *) str
, 1, n
, 1, 0, 0);
10774 insert_1 (s
, nbytes
, 1, 0, 0);
10781 /* Clear messages. CURRENT_P non-zero means clear the current
10782 message. LAST_DISPLAYED_P non-zero means clear the message
10786 clear_message (int current_p
, int last_displayed_p
)
10790 echo_area_buffer
[0] = Qnil
;
10791 message_cleared_p
= 1;
10794 if (last_displayed_p
)
10795 echo_area_buffer
[1] = Qnil
;
10797 message_buf_print
= 0;
10800 /* Clear garbaged frames.
10802 This function is used where the old redisplay called
10803 redraw_garbaged_frames which in turn called redraw_frame which in
10804 turn called clear_frame. The call to clear_frame was a source of
10805 flickering. I believe a clear_frame is not necessary. It should
10806 suffice in the new redisplay to invalidate all current matrices,
10807 and ensure a complete redisplay of all windows. */
10810 clear_garbaged_frames (void)
10812 if (frame_garbaged
)
10814 Lisp_Object tail
, frame
;
10815 int changed_count
= 0;
10817 FOR_EACH_FRAME (tail
, frame
)
10819 struct frame
*f
= XFRAME (frame
);
10821 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
10826 f
->force_flush_display_p
= 1;
10828 clear_current_matrices (f
);
10835 frame_garbaged
= 0;
10837 ++windows_or_buffers_changed
;
10842 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
10843 is non-zero update selected_frame. Value is non-zero if the
10844 mini-windows height has been changed. */
10847 echo_area_display (int update_frame_p
)
10849 Lisp_Object mini_window
;
10852 int window_height_changed_p
= 0;
10853 struct frame
*sf
= SELECTED_FRAME ();
10855 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10856 w
= XWINDOW (mini_window
);
10857 f
= XFRAME (WINDOW_FRAME (w
));
10859 /* Don't display if frame is invisible or not yet initialized. */
10860 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
10863 #ifdef HAVE_WINDOW_SYSTEM
10864 /* When Emacs starts, selected_frame may be the initial terminal
10865 frame. If we let this through, a message would be displayed on
10867 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
10869 #endif /* HAVE_WINDOW_SYSTEM */
10871 /* Redraw garbaged frames. */
10872 clear_garbaged_frames ();
10874 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
10876 echo_area_window
= mini_window
;
10877 window_height_changed_p
= display_echo_area (w
);
10878 w
->must_be_updated_p
= 1;
10880 /* Update the display, unless called from redisplay_internal.
10881 Also don't update the screen during redisplay itself. The
10882 update will happen at the end of redisplay, and an update
10883 here could cause confusion. */
10884 if (update_frame_p
&& !redisplaying_p
)
10888 /* If the display update has been interrupted by pending
10889 input, update mode lines in the frame. Due to the
10890 pending input, it might have been that redisplay hasn't
10891 been called, so that mode lines above the echo area are
10892 garbaged. This looks odd, so we prevent it here. */
10893 if (!display_completed
)
10894 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
10896 if (window_height_changed_p
10897 /* Don't do this if Emacs is shutting down. Redisplay
10898 needs to run hooks. */
10899 && !NILP (Vrun_hooks
))
10901 /* Must update other windows. Likewise as in other
10902 cases, don't let this update be interrupted by
10904 ptrdiff_t count
= SPECPDL_INDEX ();
10905 specbind (Qredisplay_dont_pause
, Qt
);
10906 windows_or_buffers_changed
= 1;
10907 redisplay_internal ();
10908 unbind_to (count
, Qnil
);
10910 else if (FRAME_WINDOW_P (f
) && n
== 0)
10912 /* Window configuration is the same as before.
10913 Can do with a display update of the echo area,
10914 unless we displayed some mode lines. */
10915 update_single_window (w
, 1);
10916 FRAME_RIF (f
)->flush_display (f
);
10919 update_frame (f
, 1, 1);
10921 /* If cursor is in the echo area, make sure that the next
10922 redisplay displays the minibuffer, so that the cursor will
10923 be replaced with what the minibuffer wants. */
10924 if (cursor_in_echo_area
)
10925 ++windows_or_buffers_changed
;
10928 else if (!EQ (mini_window
, selected_window
))
10929 windows_or_buffers_changed
++;
10931 /* Last displayed message is now the current message. */
10932 echo_area_buffer
[1] = echo_area_buffer
[0];
10933 /* Inform read_char that we're not echoing. */
10934 echo_message_buffer
= Qnil
;
10936 /* Prevent redisplay optimization in redisplay_internal by resetting
10937 this_line_start_pos. This is done because the mini-buffer now
10938 displays the message instead of its buffer text. */
10939 if (EQ (mini_window
, selected_window
))
10940 CHARPOS (this_line_start_pos
) = 0;
10942 return window_height_changed_p
;
10945 /* Nonzero if the current buffer is shown in more than
10946 one window and was modified since last display. */
10949 buffer_shared_and_changed (void)
10951 return (buffer_shared
> 1 && UNCHANGED_MODIFIED
< MODIFF
);
10954 /* Nonzero if W doesn't reflect the actual state of
10955 current buffer due to its text or overlays change. */
10958 window_outdated (struct window
*w
)
10960 eassert (XBUFFER (w
->buffer
) == current_buffer
);
10961 return (w
->last_modified
< MODIFF
10962 || w
->last_overlay_modified
< OVERLAY_MODIFF
);
10965 /* Nonzero if W's buffer was changed but not saved or Transient Mark mode
10966 is enabled and mark of W's buffer was changed since last W's update. */
10969 window_buffer_changed (struct window
*w
)
10971 struct buffer
*b
= XBUFFER (w
->buffer
);
10973 eassert (BUFFER_LIVE_P (b
));
10975 return (((BUF_SAVE_MODIFF (b
) < BUF_MODIFF (b
)) != w
->last_had_star
)
10976 || ((!NILP (Vtransient_mark_mode
) && !NILP (BVAR (b
, mark_active
)))
10977 != !NILP (w
->region_showing
)));
10980 /***********************************************************************
10981 Mode Lines and Frame Titles
10982 ***********************************************************************/
10984 /* A buffer for constructing non-propertized mode-line strings and
10985 frame titles in it; allocated from the heap in init_xdisp and
10986 resized as needed in store_mode_line_noprop_char. */
10988 static char *mode_line_noprop_buf
;
10990 /* The buffer's end, and a current output position in it. */
10992 static char *mode_line_noprop_buf_end
;
10993 static char *mode_line_noprop_ptr
;
10995 #define MODE_LINE_NOPROP_LEN(start) \
10996 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
10999 MODE_LINE_DISPLAY
= 0,
11003 } mode_line_target
;
11005 /* Alist that caches the results of :propertize.
11006 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
11007 static Lisp_Object mode_line_proptrans_alist
;
11009 /* List of strings making up the mode-line. */
11010 static Lisp_Object mode_line_string_list
;
11012 /* Base face property when building propertized mode line string. */
11013 static Lisp_Object mode_line_string_face
;
11014 static Lisp_Object mode_line_string_face_prop
;
11017 /* Unwind data for mode line strings */
11019 static Lisp_Object Vmode_line_unwind_vector
;
11022 format_mode_line_unwind_data (struct frame
*target_frame
,
11023 struct buffer
*obuf
,
11025 int save_proptrans
)
11027 Lisp_Object vector
, tmp
;
11029 /* Reduce consing by keeping one vector in
11030 Vwith_echo_area_save_vector. */
11031 vector
= Vmode_line_unwind_vector
;
11032 Vmode_line_unwind_vector
= Qnil
;
11035 vector
= Fmake_vector (make_number (10), Qnil
);
11037 ASET (vector
, 0, make_number (mode_line_target
));
11038 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
11039 ASET (vector
, 2, mode_line_string_list
);
11040 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
11041 ASET (vector
, 4, mode_line_string_face
);
11042 ASET (vector
, 5, mode_line_string_face_prop
);
11045 XSETBUFFER (tmp
, obuf
);
11048 ASET (vector
, 6, tmp
);
11049 ASET (vector
, 7, owin
);
11052 /* Similarly to `with-selected-window', if the operation selects
11053 a window on another frame, we must restore that frame's
11054 selected window, and (for a tty) the top-frame. */
11055 ASET (vector
, 8, target_frame
->selected_window
);
11056 if (FRAME_TERMCAP_P (target_frame
))
11057 ASET (vector
, 9, FRAME_TTY (target_frame
)->top_frame
);
11064 unwind_format_mode_line (Lisp_Object vector
)
11066 Lisp_Object old_window
= AREF (vector
, 7);
11067 Lisp_Object target_frame_window
= AREF (vector
, 8);
11068 Lisp_Object old_top_frame
= AREF (vector
, 9);
11070 mode_line_target
= XINT (AREF (vector
, 0));
11071 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
11072 mode_line_string_list
= AREF (vector
, 2);
11073 if (! EQ (AREF (vector
, 3), Qt
))
11074 mode_line_proptrans_alist
= AREF (vector
, 3);
11075 mode_line_string_face
= AREF (vector
, 4);
11076 mode_line_string_face_prop
= AREF (vector
, 5);
11078 /* Select window before buffer, since it may change the buffer. */
11079 if (!NILP (old_window
))
11081 /* If the operation that we are unwinding had selected a window
11082 on a different frame, reset its frame-selected-window. For a
11083 text terminal, reset its top-frame if necessary. */
11084 if (!NILP (target_frame_window
))
11087 = WINDOW_FRAME (XWINDOW (target_frame_window
));
11089 if (!EQ (frame
, WINDOW_FRAME (XWINDOW (old_window
))))
11090 Fselect_window (target_frame_window
, Qt
);
11092 if (!NILP (old_top_frame
) && !EQ (old_top_frame
, frame
))
11093 Fselect_frame (old_top_frame
, Qt
);
11096 Fselect_window (old_window
, Qt
);
11099 if (!NILP (AREF (vector
, 6)))
11101 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
11102 ASET (vector
, 6, Qnil
);
11105 Vmode_line_unwind_vector
= vector
;
11110 /* Store a single character C for the frame title in mode_line_noprop_buf.
11111 Re-allocate mode_line_noprop_buf if necessary. */
11114 store_mode_line_noprop_char (char c
)
11116 /* If output position has reached the end of the allocated buffer,
11117 increase the buffer's size. */
11118 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
11120 ptrdiff_t len
= MODE_LINE_NOPROP_LEN (0);
11121 ptrdiff_t size
= len
;
11122 mode_line_noprop_buf
=
11123 xpalloc (mode_line_noprop_buf
, &size
, 1, STRING_BYTES_BOUND
, 1);
11124 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
11125 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
11128 *mode_line_noprop_ptr
++ = c
;
11132 /* Store part of a frame title in mode_line_noprop_buf, beginning at
11133 mode_line_noprop_ptr. STRING is the string to store. Do not copy
11134 characters that yield more columns than PRECISION; PRECISION <= 0
11135 means copy the whole string. Pad with spaces until FIELD_WIDTH
11136 number of characters have been copied; FIELD_WIDTH <= 0 means don't
11137 pad. Called from display_mode_element when it is used to build a
11141 store_mode_line_noprop (const char *string
, int field_width
, int precision
)
11143 const unsigned char *str
= (const unsigned char *) string
;
11145 ptrdiff_t dummy
, nbytes
;
11147 /* Copy at most PRECISION chars from STR. */
11148 nbytes
= strlen (string
);
11149 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
11151 store_mode_line_noprop_char (*str
++);
11153 /* Fill up with spaces until FIELD_WIDTH reached. */
11154 while (field_width
> 0
11155 && n
< field_width
)
11157 store_mode_line_noprop_char (' ');
11164 /***********************************************************************
11166 ***********************************************************************/
11168 #ifdef HAVE_WINDOW_SYSTEM
11170 /* Set the title of FRAME, if it has changed. The title format is
11171 Vicon_title_format if FRAME is iconified, otherwise it is
11172 frame_title_format. */
11175 x_consider_frame_title (Lisp_Object frame
)
11177 struct frame
*f
= XFRAME (frame
);
11179 if (FRAME_WINDOW_P (f
)
11180 || FRAME_MINIBUF_ONLY_P (f
)
11181 || f
->explicit_name
)
11183 /* Do we have more than one visible frame on this X display? */
11184 Lisp_Object tail
, other_frame
, fmt
;
11185 ptrdiff_t title_start
;
11189 ptrdiff_t count
= SPECPDL_INDEX ();
11191 FOR_EACH_FRAME (tail
, other_frame
)
11193 struct frame
*tf
= XFRAME (other_frame
);
11196 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
11197 && !FRAME_MINIBUF_ONLY_P (tf
)
11198 && !EQ (other_frame
, tip_frame
)
11199 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
11203 /* Set global variable indicating that multiple frames exist. */
11204 multiple_frames
= CONSP (tail
);
11206 /* Switch to the buffer of selected window of the frame. Set up
11207 mode_line_target so that display_mode_element will output into
11208 mode_line_noprop_buf; then display the title. */
11209 record_unwind_protect (unwind_format_mode_line
,
11210 format_mode_line_unwind_data
11211 (f
, current_buffer
, selected_window
, 0));
11213 Fselect_window (f
->selected_window
, Qt
);
11214 set_buffer_internal_1
11215 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
11216 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
11218 mode_line_target
= MODE_LINE_TITLE
;
11219 title_start
= MODE_LINE_NOPROP_LEN (0);
11220 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
11221 NULL
, DEFAULT_FACE_ID
);
11222 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
11223 len
= MODE_LINE_NOPROP_LEN (title_start
);
11224 title
= mode_line_noprop_buf
+ title_start
;
11225 unbind_to (count
, Qnil
);
11227 /* Set the title only if it's changed. This avoids consing in
11228 the common case where it hasn't. (If it turns out that we've
11229 already wasted too much time by walking through the list with
11230 display_mode_element, then we might need to optimize at a
11231 higher level than this.) */
11232 if (! STRINGP (f
->name
)
11233 || SBYTES (f
->name
) != len
11234 || memcmp (title
, SDATA (f
->name
), len
) != 0)
11235 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
11239 #endif /* not HAVE_WINDOW_SYSTEM */
11242 /***********************************************************************
11244 ***********************************************************************/
11247 /* Prepare for redisplay by updating menu-bar item lists when
11248 appropriate. This can call eval. */
11251 prepare_menu_bars (void)
11254 struct gcpro gcpro1
, gcpro2
;
11256 Lisp_Object tooltip_frame
;
11258 #ifdef HAVE_WINDOW_SYSTEM
11259 tooltip_frame
= tip_frame
;
11261 tooltip_frame
= Qnil
;
11264 /* Update all frame titles based on their buffer names, etc. We do
11265 this before the menu bars so that the buffer-menu will show the
11266 up-to-date frame titles. */
11267 #ifdef HAVE_WINDOW_SYSTEM
11268 if (windows_or_buffers_changed
|| update_mode_lines
)
11270 Lisp_Object tail
, frame
;
11272 FOR_EACH_FRAME (tail
, frame
)
11274 f
= XFRAME (frame
);
11275 if (!EQ (frame
, tooltip_frame
)
11276 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
11277 x_consider_frame_title (frame
);
11280 #endif /* HAVE_WINDOW_SYSTEM */
11282 /* Update the menu bar item lists, if appropriate. This has to be
11283 done before any actual redisplay or generation of display lines. */
11284 all_windows
= (update_mode_lines
11285 || buffer_shared_and_changed ()
11286 || windows_or_buffers_changed
);
11289 Lisp_Object tail
, frame
;
11290 ptrdiff_t count
= SPECPDL_INDEX ();
11291 /* 1 means that update_menu_bar has run its hooks
11292 so any further calls to update_menu_bar shouldn't do so again. */
11293 int menu_bar_hooks_run
= 0;
11295 record_unwind_save_match_data ();
11297 FOR_EACH_FRAME (tail
, frame
)
11299 f
= XFRAME (frame
);
11301 /* Ignore tooltip frame. */
11302 if (EQ (frame
, tooltip_frame
))
11305 /* If a window on this frame changed size, report that to
11306 the user and clear the size-change flag. */
11307 if (FRAME_WINDOW_SIZES_CHANGED (f
))
11309 Lisp_Object functions
;
11311 /* Clear flag first in case we get an error below. */
11312 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
11313 functions
= Vwindow_size_change_functions
;
11314 GCPRO2 (tail
, functions
);
11316 while (CONSP (functions
))
11318 if (!EQ (XCAR (functions
), Qt
))
11319 call1 (XCAR (functions
), frame
);
11320 functions
= XCDR (functions
);
11326 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
11327 #ifdef HAVE_WINDOW_SYSTEM
11328 update_tool_bar (f
, 0);
11331 if (windows_or_buffers_changed
11334 (f
, Fbuffer_modified_p (XWINDOW (f
->selected_window
)->buffer
));
11339 unbind_to (count
, Qnil
);
11343 struct frame
*sf
= SELECTED_FRAME ();
11344 update_menu_bar (sf
, 1, 0);
11345 #ifdef HAVE_WINDOW_SYSTEM
11346 update_tool_bar (sf
, 1);
11352 /* Update the menu bar item list for frame F. This has to be done
11353 before we start to fill in any display lines, because it can call
11356 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
11358 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
11359 already ran the menu bar hooks for this redisplay, so there
11360 is no need to run them again. The return value is the
11361 updated value of this flag, to pass to the next call. */
11364 update_menu_bar (struct frame
*f
, int save_match_data
, int hooks_run
)
11366 Lisp_Object window
;
11367 register struct window
*w
;
11369 /* If called recursively during a menu update, do nothing. This can
11370 happen when, for instance, an activate-menubar-hook causes a
11372 if (inhibit_menubar_update
)
11375 window
= FRAME_SELECTED_WINDOW (f
);
11376 w
= XWINDOW (window
);
11378 if (FRAME_WINDOW_P (f
)
11380 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11381 || defined (HAVE_NS) || defined (USE_GTK)
11382 FRAME_EXTERNAL_MENU_BAR (f
)
11384 FRAME_MENU_BAR_LINES (f
) > 0
11386 : FRAME_MENU_BAR_LINES (f
) > 0)
11388 /* If the user has switched buffers or windows, we need to
11389 recompute to reflect the new bindings. But we'll
11390 recompute when update_mode_lines is set too; that means
11391 that people can use force-mode-line-update to request
11392 that the menu bar be recomputed. The adverse effect on
11393 the rest of the redisplay algorithm is about the same as
11394 windows_or_buffers_changed anyway. */
11395 if (windows_or_buffers_changed
11396 /* This used to test w->update_mode_line, but we believe
11397 there is no need to recompute the menu in that case. */
11398 || update_mode_lines
11399 || window_buffer_changed (w
))
11401 struct buffer
*prev
= current_buffer
;
11402 ptrdiff_t count
= SPECPDL_INDEX ();
11404 specbind (Qinhibit_menubar_update
, Qt
);
11406 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11407 if (save_match_data
)
11408 record_unwind_save_match_data ();
11409 if (NILP (Voverriding_local_map_menu_flag
))
11411 specbind (Qoverriding_terminal_local_map
, Qnil
);
11412 specbind (Qoverriding_local_map
, Qnil
);
11417 /* Run the Lucid hook. */
11418 safe_run_hooks (Qactivate_menubar_hook
);
11420 /* If it has changed current-menubar from previous value,
11421 really recompute the menu-bar from the value. */
11422 if (! NILP (Vlucid_menu_bar_dirty_flag
))
11423 call0 (Qrecompute_lucid_menubar
);
11425 safe_run_hooks (Qmenu_bar_update_hook
);
11430 XSETFRAME (Vmenu_updating_frame
, f
);
11431 fset_menu_bar_items (f
, menu_bar_items (FRAME_MENU_BAR_ITEMS (f
)));
11433 /* Redisplay the menu bar in case we changed it. */
11434 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11435 || defined (HAVE_NS) || defined (USE_GTK)
11436 if (FRAME_WINDOW_P (f
))
11438 #if defined (HAVE_NS)
11439 /* All frames on Mac OS share the same menubar. So only
11440 the selected frame should be allowed to set it. */
11441 if (f
== SELECTED_FRAME ())
11443 set_frame_menubar (f
, 0, 0);
11446 /* On a terminal screen, the menu bar is an ordinary screen
11447 line, and this makes it get updated. */
11448 w
->update_mode_line
= 1;
11449 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11450 /* In the non-toolkit version, the menu bar is an ordinary screen
11451 line, and this makes it get updated. */
11452 w
->update_mode_line
= 1;
11453 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11455 unbind_to (count
, Qnil
);
11456 set_buffer_internal_1 (prev
);
11465 /***********************************************************************
11467 ***********************************************************************/
11469 #ifdef HAVE_WINDOW_SYSTEM
11472 Nominal cursor position -- where to draw output.
11473 HPOS and VPOS are window relative glyph matrix coordinates.
11474 X and Y are window relative pixel coordinates. */
11476 struct cursor_pos output_cursor
;
11480 Set the global variable output_cursor to CURSOR. All cursor
11481 positions are relative to updated_window. */
11484 set_output_cursor (struct cursor_pos
*cursor
)
11486 output_cursor
.hpos
= cursor
->hpos
;
11487 output_cursor
.vpos
= cursor
->vpos
;
11488 output_cursor
.x
= cursor
->x
;
11489 output_cursor
.y
= cursor
->y
;
11494 Set a nominal cursor position.
11496 HPOS and VPOS are column/row positions in a window glyph matrix. X
11497 and Y are window text area relative pixel positions.
11499 If this is done during an update, updated_window will contain the
11500 window that is being updated and the position is the future output
11501 cursor position for that window. If updated_window is null, use
11502 selected_window and display the cursor at the given position. */
11505 x_cursor_to (int vpos
, int hpos
, int y
, int x
)
11509 /* If updated_window is not set, work on selected_window. */
11510 if (updated_window
)
11511 w
= updated_window
;
11513 w
= XWINDOW (selected_window
);
11515 /* Set the output cursor. */
11516 output_cursor
.hpos
= hpos
;
11517 output_cursor
.vpos
= vpos
;
11518 output_cursor
.x
= x
;
11519 output_cursor
.y
= y
;
11521 /* If not called as part of an update, really display the cursor.
11522 This will also set the cursor position of W. */
11523 if (updated_window
== NULL
)
11526 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
11527 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
11528 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
11533 #endif /* HAVE_WINDOW_SYSTEM */
11536 /***********************************************************************
11538 ***********************************************************************/
11540 #ifdef HAVE_WINDOW_SYSTEM
11542 /* Where the mouse was last time we reported a mouse event. */
11544 FRAME_PTR last_mouse_frame
;
11546 /* Tool-bar item index of the item on which a mouse button was pressed
11549 int last_tool_bar_item
;
11551 /* Select `frame' temporarily without running all the code in
11553 FIXME: Maybe do_switch_frame should be trimmed down similarly
11554 when `norecord' is set. */
11556 fast_set_selected_frame (Lisp_Object frame
)
11558 if (!EQ (selected_frame
, frame
))
11560 selected_frame
= frame
;
11561 selected_window
= XFRAME (frame
)->selected_window
;
11566 /* Update the tool-bar item list for frame F. This has to be done
11567 before we start to fill in any display lines. Called from
11568 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
11569 and restore it here. */
11572 update_tool_bar (struct frame
*f
, int save_match_data
)
11574 #if defined (USE_GTK) || defined (HAVE_NS)
11575 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
11577 int do_update
= WINDOWP (f
->tool_bar_window
)
11578 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
11583 Lisp_Object window
;
11586 window
= FRAME_SELECTED_WINDOW (f
);
11587 w
= XWINDOW (window
);
11589 /* If the user has switched buffers or windows, we need to
11590 recompute to reflect the new bindings. But we'll
11591 recompute when update_mode_lines is set too; that means
11592 that people can use force-mode-line-update to request
11593 that the menu bar be recomputed. The adverse effect on
11594 the rest of the redisplay algorithm is about the same as
11595 windows_or_buffers_changed anyway. */
11596 if (windows_or_buffers_changed
11597 || w
->update_mode_line
11598 || update_mode_lines
11599 || window_buffer_changed (w
))
11601 struct buffer
*prev
= current_buffer
;
11602 ptrdiff_t count
= SPECPDL_INDEX ();
11603 Lisp_Object frame
, new_tool_bar
;
11604 int new_n_tool_bar
;
11605 struct gcpro gcpro1
;
11607 /* Set current_buffer to the buffer of the selected
11608 window of the frame, so that we get the right local
11610 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11612 /* Save match data, if we must. */
11613 if (save_match_data
)
11614 record_unwind_save_match_data ();
11616 /* Make sure that we don't accidentally use bogus keymaps. */
11617 if (NILP (Voverriding_local_map_menu_flag
))
11619 specbind (Qoverriding_terminal_local_map
, Qnil
);
11620 specbind (Qoverriding_local_map
, Qnil
);
11623 GCPRO1 (new_tool_bar
);
11625 /* We must temporarily set the selected frame to this frame
11626 before calling tool_bar_items, because the calculation of
11627 the tool-bar keymap uses the selected frame (see
11628 `tool-bar-make-keymap' in tool-bar.el). */
11629 eassert (EQ (selected_window
,
11630 /* Since we only explicitly preserve selected_frame,
11631 check that selected_window would be redundant. */
11632 XFRAME (selected_frame
)->selected_window
));
11633 record_unwind_protect (fast_set_selected_frame
, selected_frame
);
11634 XSETFRAME (frame
, f
);
11635 fast_set_selected_frame (frame
);
11637 /* Build desired tool-bar items from keymaps. */
11639 = tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
11642 /* Redisplay the tool-bar if we changed it. */
11643 if (new_n_tool_bar
!= f
->n_tool_bar_items
11644 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
11646 /* Redisplay that happens asynchronously due to an expose event
11647 may access f->tool_bar_items. Make sure we update both
11648 variables within BLOCK_INPUT so no such event interrupts. */
11650 fset_tool_bar_items (f
, new_tool_bar
);
11651 f
->n_tool_bar_items
= new_n_tool_bar
;
11652 w
->update_mode_line
= 1;
11658 unbind_to (count
, Qnil
);
11659 set_buffer_internal_1 (prev
);
11665 /* Set F->desired_tool_bar_string to a Lisp string representing frame
11666 F's desired tool-bar contents. F->tool_bar_items must have
11667 been set up previously by calling prepare_menu_bars. */
11670 build_desired_tool_bar_string (struct frame
*f
)
11672 int i
, size
, size_needed
;
11673 struct gcpro gcpro1
, gcpro2
, gcpro3
;
11674 Lisp_Object image
, plist
, props
;
11676 image
= plist
= props
= Qnil
;
11677 GCPRO3 (image
, plist
, props
);
11679 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
11680 Otherwise, make a new string. */
11682 /* The size of the string we might be able to reuse. */
11683 size
= (STRINGP (f
->desired_tool_bar_string
)
11684 ? SCHARS (f
->desired_tool_bar_string
)
11687 /* We need one space in the string for each image. */
11688 size_needed
= f
->n_tool_bar_items
;
11690 /* Reuse f->desired_tool_bar_string, if possible. */
11691 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
11692 fset_desired_tool_bar_string
11693 (f
, Fmake_string (make_number (size_needed
), make_number (' ')));
11696 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
11697 Fremove_text_properties (make_number (0), make_number (size
),
11698 props
, f
->desired_tool_bar_string
);
11701 /* Put a `display' property on the string for the images to display,
11702 put a `menu_item' property on tool-bar items with a value that
11703 is the index of the item in F's tool-bar item vector. */
11704 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
11706 #define PROP(IDX) \
11707 AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
11709 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
11710 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
11711 int hmargin
, vmargin
, relief
, idx
, end
;
11713 /* If image is a vector, choose the image according to the
11715 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
11716 if (VECTORP (image
))
11720 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
11721 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
11724 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
11725 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
11727 eassert (ASIZE (image
) >= idx
);
11728 image
= AREF (image
, idx
);
11733 /* Ignore invalid image specifications. */
11734 if (!valid_image_p (image
))
11737 /* Display the tool-bar button pressed, or depressed. */
11738 plist
= Fcopy_sequence (XCDR (image
));
11740 /* Compute margin and relief to draw. */
11741 relief
= (tool_bar_button_relief
>= 0
11742 ? tool_bar_button_relief
11743 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
11744 hmargin
= vmargin
= relief
;
11746 if (RANGED_INTEGERP (1, Vtool_bar_button_margin
,
11747 INT_MAX
- max (hmargin
, vmargin
)))
11749 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
11750 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
11752 else if (CONSP (Vtool_bar_button_margin
))
11754 if (RANGED_INTEGERP (1, XCAR (Vtool_bar_button_margin
),
11755 INT_MAX
- hmargin
))
11756 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
11758 if (RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin
),
11759 INT_MAX
- vmargin
))
11760 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
11763 if (auto_raise_tool_bar_buttons_p
)
11765 /* Add a `:relief' property to the image spec if the item is
11769 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
11776 /* If image is selected, display it pressed, i.e. with a
11777 negative relief. If it's not selected, display it with a
11779 plist
= Fplist_put (plist
, QCrelief
,
11781 ? make_number (-relief
)
11782 : make_number (relief
)));
11787 /* Put a margin around the image. */
11788 if (hmargin
|| vmargin
)
11790 if (hmargin
== vmargin
)
11791 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
11793 plist
= Fplist_put (plist
, QCmargin
,
11794 Fcons (make_number (hmargin
),
11795 make_number (vmargin
)));
11798 /* If button is not enabled, and we don't have special images
11799 for the disabled state, make the image appear disabled by
11800 applying an appropriate algorithm to it. */
11801 if (!enabled_p
&& idx
< 0)
11802 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
11804 /* Put a `display' text property on the string for the image to
11805 display. Put a `menu-item' property on the string that gives
11806 the start of this item's properties in the tool-bar items
11808 image
= Fcons (Qimage
, plist
);
11809 props
= list4 (Qdisplay
, image
,
11810 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
11812 /* Let the last image hide all remaining spaces in the tool bar
11813 string. The string can be longer than needed when we reuse a
11814 previous string. */
11815 if (i
+ 1 == f
->n_tool_bar_items
)
11816 end
= SCHARS (f
->desired_tool_bar_string
);
11819 Fadd_text_properties (make_number (i
), make_number (end
),
11820 props
, f
->desired_tool_bar_string
);
11828 /* Display one line of the tool-bar of frame IT->f.
11830 HEIGHT specifies the desired height of the tool-bar line.
11831 If the actual height of the glyph row is less than HEIGHT, the
11832 row's height is increased to HEIGHT, and the icons are centered
11833 vertically in the new height.
11835 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
11836 count a final empty row in case the tool-bar width exactly matches
11841 display_tool_bar_line (struct it
*it
, int height
)
11843 struct glyph_row
*row
= it
->glyph_row
;
11844 int max_x
= it
->last_visible_x
;
11845 struct glyph
*last
;
11847 prepare_desired_row (row
);
11848 row
->y
= it
->current_y
;
11850 /* Note that this isn't made use of if the face hasn't a box,
11851 so there's no need to check the face here. */
11852 it
->start_of_box_run_p
= 1;
11854 while (it
->current_x
< max_x
)
11856 int x
, n_glyphs_before
, i
, nglyphs
;
11857 struct it it_before
;
11859 /* Get the next display element. */
11860 if (!get_next_display_element (it
))
11862 /* Don't count empty row if we are counting needed tool-bar lines. */
11863 if (height
< 0 && !it
->hpos
)
11868 /* Produce glyphs. */
11869 n_glyphs_before
= row
->used
[TEXT_AREA
];
11872 PRODUCE_GLYPHS (it
);
11874 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
11876 x
= it_before
.current_x
;
11877 while (i
< nglyphs
)
11879 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
11881 if (x
+ glyph
->pixel_width
> max_x
)
11883 /* Glyph doesn't fit on line. Backtrack. */
11884 row
->used
[TEXT_AREA
] = n_glyphs_before
;
11886 /* If this is the only glyph on this line, it will never fit on the
11887 tool-bar, so skip it. But ensure there is at least one glyph,
11888 so we don't accidentally disable the tool-bar. */
11889 if (n_glyphs_before
== 0
11890 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
11896 x
+= glyph
->pixel_width
;
11900 /* Stop at line end. */
11901 if (ITERATOR_AT_END_OF_LINE_P (it
))
11904 set_iterator_to_next (it
, 1);
11909 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
11911 /* Use default face for the border below the tool bar.
11913 FIXME: When auto-resize-tool-bars is grow-only, there is
11914 no additional border below the possibly empty tool-bar lines.
11915 So to make the extra empty lines look "normal", we have to
11916 use the tool-bar face for the border too. */
11917 if (!row
->displays_text_p
&& !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
11918 it
->face_id
= DEFAULT_FACE_ID
;
11920 extend_face_to_end_of_line (it
);
11921 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
11922 last
->right_box_line_p
= 1;
11923 if (last
== row
->glyphs
[TEXT_AREA
])
11924 last
->left_box_line_p
= 1;
11926 /* Make line the desired height and center it vertically. */
11927 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
11929 /* Don't add more than one line height. */
11930 height
%= FRAME_LINE_HEIGHT (it
->f
);
11931 it
->max_ascent
+= height
/ 2;
11932 it
->max_descent
+= (height
+ 1) / 2;
11935 compute_line_metrics (it
);
11937 /* If line is empty, make it occupy the rest of the tool-bar. */
11938 if (!row
->displays_text_p
)
11940 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
11941 row
->visible_height
= row
->height
;
11942 row
->ascent
= row
->phys_ascent
= 0;
11943 row
->extra_line_spacing
= 0;
11946 row
->full_width_p
= 1;
11947 row
->continued_p
= 0;
11948 row
->truncated_on_left_p
= 0;
11949 row
->truncated_on_right_p
= 0;
11951 it
->current_x
= it
->hpos
= 0;
11952 it
->current_y
+= row
->height
;
11958 /* Max tool-bar height. */
11960 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
11961 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
11963 /* Value is the number of screen lines needed to make all tool-bar
11964 items of frame F visible. The number of actual rows needed is
11965 returned in *N_ROWS if non-NULL. */
11968 tool_bar_lines_needed (struct frame
*f
, int *n_rows
)
11970 struct window
*w
= XWINDOW (f
->tool_bar_window
);
11972 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
11973 the desired matrix, so use (unused) mode-line row as temporary row to
11974 avoid destroying the first tool-bar row. */
11975 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
11977 /* Initialize an iterator for iteration over
11978 F->desired_tool_bar_string in the tool-bar window of frame F. */
11979 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
11980 it
.first_visible_x
= 0;
11981 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
11982 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
11983 it
.paragraph_embedding
= L2R
;
11985 while (!ITERATOR_AT_END_P (&it
))
11987 clear_glyph_row (temp_row
);
11988 it
.glyph_row
= temp_row
;
11989 display_tool_bar_line (&it
, -1);
11991 clear_glyph_row (temp_row
);
11993 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
11995 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
11997 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
12001 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
12003 doc
: /* Return the number of lines occupied by the tool bar of FRAME.
12004 If FRAME is nil or omitted, use the selected frame. */)
12005 (Lisp_Object frame
)
12007 struct frame
*f
= decode_any_frame (frame
);
12011 if (WINDOWP (f
->tool_bar_window
)
12012 && (w
= XWINDOW (f
->tool_bar_window
),
12013 WINDOW_TOTAL_LINES (w
) > 0))
12015 update_tool_bar (f
, 1);
12016 if (f
->n_tool_bar_items
)
12018 build_desired_tool_bar_string (f
);
12019 nlines
= tool_bar_lines_needed (f
, NULL
);
12023 return make_number (nlines
);
12027 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
12028 height should be changed. */
12031 redisplay_tool_bar (struct frame
*f
)
12035 struct glyph_row
*row
;
12037 #if defined (USE_GTK) || defined (HAVE_NS)
12038 if (FRAME_EXTERNAL_TOOL_BAR (f
))
12039 update_frame_tool_bar (f
);
12043 /* If frame hasn't a tool-bar window or if it is zero-height, don't
12044 do anything. This means you must start with tool-bar-lines
12045 non-zero to get the auto-sizing effect. Or in other words, you
12046 can turn off tool-bars by specifying tool-bar-lines zero. */
12047 if (!WINDOWP (f
->tool_bar_window
)
12048 || (w
= XWINDOW (f
->tool_bar_window
),
12049 WINDOW_TOTAL_LINES (w
) == 0))
12052 /* Set up an iterator for the tool-bar window. */
12053 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
12054 it
.first_visible_x
= 0;
12055 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
12056 row
= it
.glyph_row
;
12058 /* Build a string that represents the contents of the tool-bar. */
12059 build_desired_tool_bar_string (f
);
12060 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
12061 /* FIXME: This should be controlled by a user option. But it
12062 doesn't make sense to have an R2L tool bar if the menu bar cannot
12063 be drawn also R2L, and making the menu bar R2L is tricky due
12064 toolkit-specific code that implements it. If an R2L tool bar is
12065 ever supported, display_tool_bar_line should also be augmented to
12066 call unproduce_glyphs like display_line and display_string
12068 it
.paragraph_embedding
= L2R
;
12070 if (f
->n_tool_bar_rows
== 0)
12074 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
12075 nlines
!= WINDOW_TOTAL_LINES (w
)))
12078 int old_height
= WINDOW_TOTAL_LINES (w
);
12080 XSETFRAME (frame
, f
);
12081 Fmodify_frame_parameters (frame
,
12082 Fcons (Fcons (Qtool_bar_lines
,
12083 make_number (nlines
)),
12085 if (WINDOW_TOTAL_LINES (w
) != old_height
)
12087 clear_glyph_matrix (w
->desired_matrix
);
12088 fonts_changed_p
= 1;
12094 /* Display as many lines as needed to display all tool-bar items. */
12096 if (f
->n_tool_bar_rows
> 0)
12098 int border
, rows
, height
, extra
;
12100 if (TYPE_RANGED_INTEGERP (int, Vtool_bar_border
))
12101 border
= XINT (Vtool_bar_border
);
12102 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
12103 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
12104 else if (EQ (Vtool_bar_border
, Qborder_width
))
12105 border
= f
->border_width
;
12111 rows
= f
->n_tool_bar_rows
;
12112 height
= max (1, (it
.last_visible_y
- border
) / rows
);
12113 extra
= it
.last_visible_y
- border
- height
* rows
;
12115 while (it
.current_y
< it
.last_visible_y
)
12118 if (extra
> 0 && rows
-- > 0)
12120 h
= (extra
+ rows
- 1) / rows
;
12123 display_tool_bar_line (&it
, height
+ h
);
12128 while (it
.current_y
< it
.last_visible_y
)
12129 display_tool_bar_line (&it
, 0);
12132 /* It doesn't make much sense to try scrolling in the tool-bar
12133 window, so don't do it. */
12134 w
->desired_matrix
->no_scrolling_p
= 1;
12135 w
->must_be_updated_p
= 1;
12137 if (!NILP (Vauto_resize_tool_bars
))
12139 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
12140 int change_height_p
= 0;
12142 /* If we couldn't display everything, change the tool-bar's
12143 height if there is room for more. */
12144 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
12145 && it
.current_y
< max_tool_bar_height
)
12146 change_height_p
= 1;
12148 row
= it
.glyph_row
- 1;
12150 /* If there are blank lines at the end, except for a partially
12151 visible blank line at the end that is smaller than
12152 FRAME_LINE_HEIGHT, change the tool-bar's height. */
12153 if (!row
->displays_text_p
12154 && row
->height
>= FRAME_LINE_HEIGHT (f
))
12155 change_height_p
= 1;
12157 /* If row displays tool-bar items, but is partially visible,
12158 change the tool-bar's height. */
12159 if (row
->displays_text_p
12160 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
12161 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
12162 change_height_p
= 1;
12164 /* Resize windows as needed by changing the `tool-bar-lines'
12165 frame parameter. */
12166 if (change_height_p
)
12169 int old_height
= WINDOW_TOTAL_LINES (w
);
12171 int nlines
= tool_bar_lines_needed (f
, &nrows
);
12173 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
12174 && !f
->minimize_tool_bar_window_p
)
12175 ? (nlines
> old_height
)
12176 : (nlines
!= old_height
));
12177 f
->minimize_tool_bar_window_p
= 0;
12179 if (change_height_p
)
12181 XSETFRAME (frame
, f
);
12182 Fmodify_frame_parameters (frame
,
12183 Fcons (Fcons (Qtool_bar_lines
,
12184 make_number (nlines
)),
12186 if (WINDOW_TOTAL_LINES (w
) != old_height
)
12188 clear_glyph_matrix (w
->desired_matrix
);
12189 f
->n_tool_bar_rows
= nrows
;
12190 fonts_changed_p
= 1;
12197 f
->minimize_tool_bar_window_p
= 0;
12202 /* Get information about the tool-bar item which is displayed in GLYPH
12203 on frame F. Return in *PROP_IDX the index where tool-bar item
12204 properties start in F->tool_bar_items. Value is zero if
12205 GLYPH doesn't display a tool-bar item. */
12208 tool_bar_item_info (struct frame
*f
, struct glyph
*glyph
, int *prop_idx
)
12214 /* This function can be called asynchronously, which means we must
12215 exclude any possibility that Fget_text_property signals an
12217 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
12218 charpos
= max (0, charpos
);
12220 /* Get the text property `menu-item' at pos. The value of that
12221 property is the start index of this item's properties in
12222 F->tool_bar_items. */
12223 prop
= Fget_text_property (make_number (charpos
),
12224 Qmenu_item
, f
->current_tool_bar_string
);
12225 if (INTEGERP (prop
))
12227 *prop_idx
= XINT (prop
);
12237 /* Get information about the tool-bar item at position X/Y on frame F.
12238 Return in *GLYPH a pointer to the glyph of the tool-bar item in
12239 the current matrix of the tool-bar window of F, or NULL if not
12240 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
12241 item in F->tool_bar_items. Value is
12243 -1 if X/Y is not on a tool-bar item
12244 0 if X/Y is on the same item that was highlighted before.
12248 get_tool_bar_item (struct frame
*f
, int x
, int y
, struct glyph
**glyph
,
12249 int *hpos
, int *vpos
, int *prop_idx
)
12251 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12252 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12255 /* Find the glyph under X/Y. */
12256 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
12257 if (*glyph
== NULL
)
12260 /* Get the start of this tool-bar item's properties in
12261 f->tool_bar_items. */
12262 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
12265 /* Is mouse on the highlighted item? */
12266 if (EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
)
12267 && *vpos
>= hlinfo
->mouse_face_beg_row
12268 && *vpos
<= hlinfo
->mouse_face_end_row
12269 && (*vpos
> hlinfo
->mouse_face_beg_row
12270 || *hpos
>= hlinfo
->mouse_face_beg_col
)
12271 && (*vpos
< hlinfo
->mouse_face_end_row
12272 || *hpos
< hlinfo
->mouse_face_end_col
12273 || hlinfo
->mouse_face_past_end
))
12281 Handle mouse button event on the tool-bar of frame F, at
12282 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
12283 0 for button release. MODIFIERS is event modifiers for button
12287 handle_tool_bar_click (struct frame
*f
, int x
, int y
, int down_p
,
12290 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12291 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12292 int hpos
, vpos
, prop_idx
;
12293 struct glyph
*glyph
;
12294 Lisp_Object enabled_p
;
12296 /* If not on the highlighted tool-bar item, return. */
12297 frame_to_window_pixel_xy (w
, &x
, &y
);
12298 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
12301 /* If item is disabled, do nothing. */
12302 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12303 if (NILP (enabled_p
))
12308 /* Show item in pressed state. */
12309 show_mouse_face (hlinfo
, DRAW_IMAGE_SUNKEN
);
12310 hlinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
12311 last_tool_bar_item
= prop_idx
;
12315 Lisp_Object key
, frame
;
12316 struct input_event event
;
12317 EVENT_INIT (event
);
12319 /* Show item in released state. */
12320 show_mouse_face (hlinfo
, DRAW_IMAGE_RAISED
);
12321 hlinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
12323 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
12325 XSETFRAME (frame
, f
);
12326 event
.kind
= TOOL_BAR_EVENT
;
12327 event
.frame_or_window
= frame
;
12329 kbd_buffer_store_event (&event
);
12331 event
.kind
= TOOL_BAR_EVENT
;
12332 event
.frame_or_window
= frame
;
12334 event
.modifiers
= modifiers
;
12335 kbd_buffer_store_event (&event
);
12336 last_tool_bar_item
= -1;
12341 /* Possibly highlight a tool-bar item on frame F when mouse moves to
12342 tool-bar window-relative coordinates X/Y. Called from
12343 note_mouse_highlight. */
12346 note_tool_bar_highlight (struct frame
*f
, int x
, int y
)
12348 Lisp_Object window
= f
->tool_bar_window
;
12349 struct window
*w
= XWINDOW (window
);
12350 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12351 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12353 struct glyph
*glyph
;
12354 struct glyph_row
*row
;
12356 Lisp_Object enabled_p
;
12358 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
12359 int mouse_down_p
, rc
;
12361 /* Function note_mouse_highlight is called with negative X/Y
12362 values when mouse moves outside of the frame. */
12363 if (x
<= 0 || y
<= 0)
12365 clear_mouse_face (hlinfo
);
12369 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
12372 /* Not on tool-bar item. */
12373 clear_mouse_face (hlinfo
);
12377 /* On same tool-bar item as before. */
12378 goto set_help_echo
;
12380 clear_mouse_face (hlinfo
);
12382 /* Mouse is down, but on different tool-bar item? */
12383 mouse_down_p
= (dpyinfo
->grabbed
12384 && f
== last_mouse_frame
12385 && FRAME_LIVE_P (f
));
12387 && last_tool_bar_item
!= prop_idx
)
12390 hlinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
12391 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
12393 /* If tool-bar item is not enabled, don't highlight it. */
12394 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12395 if (!NILP (enabled_p
))
12397 /* Compute the x-position of the glyph. In front and past the
12398 image is a space. We include this in the highlighted area. */
12399 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
12400 for (i
= x
= 0; i
< hpos
; ++i
)
12401 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
12403 /* Record this as the current active region. */
12404 hlinfo
->mouse_face_beg_col
= hpos
;
12405 hlinfo
->mouse_face_beg_row
= vpos
;
12406 hlinfo
->mouse_face_beg_x
= x
;
12407 hlinfo
->mouse_face_beg_y
= row
->y
;
12408 hlinfo
->mouse_face_past_end
= 0;
12410 hlinfo
->mouse_face_end_col
= hpos
+ 1;
12411 hlinfo
->mouse_face_end_row
= vpos
;
12412 hlinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
12413 hlinfo
->mouse_face_end_y
= row
->y
;
12414 hlinfo
->mouse_face_window
= window
;
12415 hlinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
12417 /* Display it as active. */
12418 show_mouse_face (hlinfo
, draw
);
12419 hlinfo
->mouse_face_image_state
= draw
;
12424 /* Set help_echo_string to a help string to display for this tool-bar item.
12425 XTread_socket does the rest. */
12426 help_echo_object
= help_echo_window
= Qnil
;
12427 help_echo_pos
= -1;
12428 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
12429 if (NILP (help_echo_string
))
12430 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
12433 #endif /* HAVE_WINDOW_SYSTEM */
12437 /************************************************************************
12438 Horizontal scrolling
12439 ************************************************************************/
12441 static int hscroll_window_tree (Lisp_Object
);
12442 static int hscroll_windows (Lisp_Object
);
12444 /* For all leaf windows in the window tree rooted at WINDOW, set their
12445 hscroll value so that PT is (i) visible in the window, and (ii) so
12446 that it is not within a certain margin at the window's left and
12447 right border. Value is non-zero if any window's hscroll has been
12451 hscroll_window_tree (Lisp_Object window
)
12453 int hscrolled_p
= 0;
12454 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
12455 int hscroll_step_abs
= 0;
12456 double hscroll_step_rel
= 0;
12458 if (hscroll_relative_p
)
12460 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
12461 if (hscroll_step_rel
< 0)
12463 hscroll_relative_p
= 0;
12464 hscroll_step_abs
= 0;
12467 else if (TYPE_RANGED_INTEGERP (int, Vhscroll_step
))
12469 hscroll_step_abs
= XINT (Vhscroll_step
);
12470 if (hscroll_step_abs
< 0)
12471 hscroll_step_abs
= 0;
12474 hscroll_step_abs
= 0;
12476 while (WINDOWP (window
))
12478 struct window
*w
= XWINDOW (window
);
12480 if (WINDOWP (w
->hchild
))
12481 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
12482 else if (WINDOWP (w
->vchild
))
12483 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
12484 else if (w
->cursor
.vpos
>= 0)
12487 int text_area_width
;
12488 struct glyph_row
*current_cursor_row
12489 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
12490 struct glyph_row
*desired_cursor_row
12491 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
12492 struct glyph_row
*cursor_row
12493 = (desired_cursor_row
->enabled_p
12494 ? desired_cursor_row
12495 : current_cursor_row
);
12496 int row_r2l_p
= cursor_row
->reversed_p
;
12498 text_area_width
= window_box_width (w
, TEXT_AREA
);
12500 /* Scroll when cursor is inside this scroll margin. */
12501 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
12503 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->buffer
))
12504 /* For left-to-right rows, hscroll when cursor is either
12505 (i) inside the right hscroll margin, or (ii) if it is
12506 inside the left margin and the window is already
12510 && w
->cursor
.x
<= h_margin
)
12511 || (cursor_row
->enabled_p
12512 && cursor_row
->truncated_on_right_p
12513 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
12514 /* For right-to-left rows, the logic is similar,
12515 except that rules for scrolling to left and right
12516 are reversed. E.g., if cursor.x <= h_margin, we
12517 need to hscroll "to the right" unconditionally,
12518 and that will scroll the screen to the left so as
12519 to reveal the next portion of the row. */
12521 && ((cursor_row
->enabled_p
12522 /* FIXME: It is confusing to set the
12523 truncated_on_right_p flag when R2L rows
12524 are actually truncated on the left. */
12525 && cursor_row
->truncated_on_right_p
12526 && w
->cursor
.x
<= h_margin
)
12528 && (w
->cursor
.x
>= text_area_width
- h_margin
))))))
12532 struct buffer
*saved_current_buffer
;
12536 /* Find point in a display of infinite width. */
12537 saved_current_buffer
= current_buffer
;
12538 current_buffer
= XBUFFER (w
->buffer
);
12540 if (w
== XWINDOW (selected_window
))
12544 pt
= marker_position (w
->pointm
);
12545 pt
= max (BEGV
, pt
);
12549 /* Move iterator to pt starting at cursor_row->start in
12550 a line with infinite width. */
12551 init_to_row_start (&it
, w
, cursor_row
);
12552 it
.last_visible_x
= INFINITY
;
12553 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
12554 current_buffer
= saved_current_buffer
;
12556 /* Position cursor in window. */
12557 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
12558 hscroll
= max (0, (it
.current_x
12559 - (ITERATOR_AT_END_OF_LINE_P (&it
)
12560 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
12561 : (text_area_width
/ 2))))
12562 / FRAME_COLUMN_WIDTH (it
.f
);
12563 else if ((!row_r2l_p
12564 && w
->cursor
.x
>= text_area_width
- h_margin
)
12565 || (row_r2l_p
&& w
->cursor
.x
<= h_margin
))
12567 if (hscroll_relative_p
)
12568 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
12571 wanted_x
= text_area_width
12572 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12575 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12579 if (hscroll_relative_p
)
12580 wanted_x
= text_area_width
* hscroll_step_rel
12583 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12586 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12588 hscroll
= max (hscroll
, w
->min_hscroll
);
12590 /* Don't prevent redisplay optimizations if hscroll
12591 hasn't changed, as it will unnecessarily slow down
12593 if (w
->hscroll
!= hscroll
)
12595 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
12596 w
->hscroll
= hscroll
;
12605 /* Value is non-zero if hscroll of any leaf window has been changed. */
12606 return hscrolled_p
;
12610 /* Set hscroll so that cursor is visible and not inside horizontal
12611 scroll margins for all windows in the tree rooted at WINDOW. See
12612 also hscroll_window_tree above. Value is non-zero if any window's
12613 hscroll has been changed. If it has, desired matrices on the frame
12614 of WINDOW are cleared. */
12617 hscroll_windows (Lisp_Object window
)
12619 int hscrolled_p
= hscroll_window_tree (window
);
12621 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
12622 return hscrolled_p
;
12627 /************************************************************************
12629 ************************************************************************/
12631 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
12632 to a non-zero value. This is sometimes handy to have in a debugger
12637 /* First and last unchanged row for try_window_id. */
12639 static int debug_first_unchanged_at_end_vpos
;
12640 static int debug_last_unchanged_at_beg_vpos
;
12642 /* Delta vpos and y. */
12644 static int debug_dvpos
, debug_dy
;
12646 /* Delta in characters and bytes for try_window_id. */
12648 static ptrdiff_t debug_delta
, debug_delta_bytes
;
12650 /* Values of window_end_pos and window_end_vpos at the end of
12653 static ptrdiff_t debug_end_vpos
;
12655 /* Append a string to W->desired_matrix->method. FMT is a printf
12656 format string. If trace_redisplay_p is non-zero also printf the
12657 resulting string to stderr. */
12659 static void debug_method_add (struct window
*, char const *, ...)
12660 ATTRIBUTE_FORMAT_PRINTF (2, 3);
12663 debug_method_add (struct window
*w
, char const *fmt
, ...)
12665 char *method
= w
->desired_matrix
->method
;
12666 int len
= strlen (method
);
12667 int size
= sizeof w
->desired_matrix
->method
;
12668 int remaining
= size
- len
- 1;
12671 if (len
&& remaining
)
12674 --remaining
, ++len
;
12677 va_start (ap
, fmt
);
12678 vsnprintf (method
+ len
, remaining
+ 1, fmt
, ap
);
12681 if (trace_redisplay_p
)
12682 fprintf (stderr
, "%p (%s): %s\n",
12684 ((BUFFERP (w
->buffer
)
12685 && STRINGP (BVAR (XBUFFER (w
->buffer
), name
)))
12686 ? SSDATA (BVAR (XBUFFER (w
->buffer
), name
))
12691 #endif /* GLYPH_DEBUG */
12694 /* Value is non-zero if all changes in window W, which displays
12695 current_buffer, are in the text between START and END. START is a
12696 buffer position, END is given as a distance from Z. Used in
12697 redisplay_internal for display optimization. */
12700 text_outside_line_unchanged_p (struct window
*w
,
12701 ptrdiff_t start
, ptrdiff_t end
)
12703 int unchanged_p
= 1;
12705 /* If text or overlays have changed, see where. */
12706 if (window_outdated (w
))
12708 /* Gap in the line? */
12709 if (GPT
< start
|| Z
- GPT
< end
)
12712 /* Changes start in front of the line, or end after it? */
12714 && (BEG_UNCHANGED
< start
- 1
12715 || END_UNCHANGED
< end
))
12718 /* If selective display, can't optimize if changes start at the
12719 beginning of the line. */
12721 && INTEGERP (BVAR (current_buffer
, selective_display
))
12722 && XINT (BVAR (current_buffer
, selective_display
)) > 0
12723 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
12726 /* If there are overlays at the start or end of the line, these
12727 may have overlay strings with newlines in them. A change at
12728 START, for instance, may actually concern the display of such
12729 overlay strings as well, and they are displayed on different
12730 lines. So, quickly rule out this case. (For the future, it
12731 might be desirable to implement something more telling than
12732 just BEG/END_UNCHANGED.) */
12735 if (BEG
+ BEG_UNCHANGED
== start
12736 && overlay_touches_p (start
))
12738 if (END_UNCHANGED
== end
12739 && overlay_touches_p (Z
- end
))
12743 /* Under bidi reordering, adding or deleting a character in the
12744 beginning of a paragraph, before the first strong directional
12745 character, can change the base direction of the paragraph (unless
12746 the buffer specifies a fixed paragraph direction), which will
12747 require to redisplay the whole paragraph. It might be worthwhile
12748 to find the paragraph limits and widen the range of redisplayed
12749 lines to that, but for now just give up this optimization. */
12750 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
12751 && NILP (BVAR (XBUFFER (w
->buffer
), bidi_paragraph_direction
)))
12755 return unchanged_p
;
12759 /* Do a frame update, taking possible shortcuts into account. This is
12760 the main external entry point for redisplay.
12762 If the last redisplay displayed an echo area message and that message
12763 is no longer requested, we clear the echo area or bring back the
12764 mini-buffer if that is in use. */
12769 redisplay_internal ();
12774 overlay_arrow_string_or_property (Lisp_Object var
)
12778 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
12781 return Voverlay_arrow_string
;
12784 /* Return 1 if there are any overlay-arrows in current_buffer. */
12786 overlay_arrow_in_current_buffer_p (void)
12790 for (vlist
= Voverlay_arrow_variable_list
;
12792 vlist
= XCDR (vlist
))
12794 Lisp_Object var
= XCAR (vlist
);
12797 if (!SYMBOLP (var
))
12799 val
= find_symbol_value (var
);
12801 && current_buffer
== XMARKER (val
)->buffer
)
12808 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
12812 overlay_arrows_changed_p (void)
12816 for (vlist
= Voverlay_arrow_variable_list
;
12818 vlist
= XCDR (vlist
))
12820 Lisp_Object var
= XCAR (vlist
);
12821 Lisp_Object val
, pstr
;
12823 if (!SYMBOLP (var
))
12825 val
= find_symbol_value (var
);
12826 if (!MARKERP (val
))
12828 if (! EQ (COERCE_MARKER (val
),
12829 Fget (var
, Qlast_arrow_position
))
12830 || ! (pstr
= overlay_arrow_string_or_property (var
),
12831 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
12837 /* Mark overlay arrows to be updated on next redisplay. */
12840 update_overlay_arrows (int up_to_date
)
12844 for (vlist
= Voverlay_arrow_variable_list
;
12846 vlist
= XCDR (vlist
))
12848 Lisp_Object var
= XCAR (vlist
);
12850 if (!SYMBOLP (var
))
12853 if (up_to_date
> 0)
12855 Lisp_Object val
= find_symbol_value (var
);
12856 Fput (var
, Qlast_arrow_position
,
12857 COERCE_MARKER (val
));
12858 Fput (var
, Qlast_arrow_string
,
12859 overlay_arrow_string_or_property (var
));
12861 else if (up_to_date
< 0
12862 || !NILP (Fget (var
, Qlast_arrow_position
)))
12864 Fput (var
, Qlast_arrow_position
, Qt
);
12865 Fput (var
, Qlast_arrow_string
, Qt
);
12871 /* Return overlay arrow string to display at row.
12872 Return integer (bitmap number) for arrow bitmap in left fringe.
12873 Return nil if no overlay arrow. */
12876 overlay_arrow_at_row (struct it
*it
, struct glyph_row
*row
)
12880 for (vlist
= Voverlay_arrow_variable_list
;
12882 vlist
= XCDR (vlist
))
12884 Lisp_Object var
= XCAR (vlist
);
12887 if (!SYMBOLP (var
))
12890 val
= find_symbol_value (var
);
12893 && current_buffer
== XMARKER (val
)->buffer
12894 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
12896 if (FRAME_WINDOW_P (it
->f
)
12897 /* FIXME: if ROW->reversed_p is set, this should test
12898 the right fringe, not the left one. */
12899 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
12901 #ifdef HAVE_WINDOW_SYSTEM
12902 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
12905 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
12906 return make_number (fringe_bitmap
);
12909 return make_number (-1); /* Use default arrow bitmap. */
12911 return overlay_arrow_string_or_property (var
);
12918 /* Return 1 if point moved out of or into a composition. Otherwise
12919 return 0. PREV_BUF and PREV_PT are the last point buffer and
12920 position. BUF and PT are the current point buffer and position. */
12923 check_point_in_composition (struct buffer
*prev_buf
, ptrdiff_t prev_pt
,
12924 struct buffer
*buf
, ptrdiff_t pt
)
12926 ptrdiff_t start
, end
;
12928 Lisp_Object buffer
;
12930 XSETBUFFER (buffer
, buf
);
12931 /* Check a composition at the last point if point moved within the
12933 if (prev_buf
== buf
)
12936 /* Point didn't move. */
12939 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
12940 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
12941 && COMPOSITION_VALID_P (start
, end
, prop
)
12942 && start
< prev_pt
&& end
> prev_pt
)
12943 /* The last point was within the composition. Return 1 iff
12944 point moved out of the composition. */
12945 return (pt
<= start
|| pt
>= end
);
12948 /* Check a composition at the current point. */
12949 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
12950 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
12951 && COMPOSITION_VALID_P (start
, end
, prop
)
12952 && start
< pt
&& end
> pt
);
12956 /* Reconsider the setting of B->clip_changed which is displayed
12960 reconsider_clip_changes (struct window
*w
, struct buffer
*b
)
12962 if (b
->clip_changed
12963 && !NILP (w
->window_end_valid
)
12964 && w
->current_matrix
->buffer
== b
12965 && w
->current_matrix
->zv
== BUF_ZV (b
)
12966 && w
->current_matrix
->begv
== BUF_BEGV (b
))
12967 b
->clip_changed
= 0;
12969 /* If display wasn't paused, and W is not a tool bar window, see if
12970 point has been moved into or out of a composition. In that case,
12971 we set b->clip_changed to 1 to force updating the screen. If
12972 b->clip_changed has already been set to 1, we can skip this
12974 if (!b
->clip_changed
12975 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
12979 if (w
== XWINDOW (selected_window
))
12982 pt
= marker_position (w
->pointm
);
12984 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
12985 || pt
!= w
->last_point
)
12986 && check_point_in_composition (w
->current_matrix
->buffer
,
12988 XBUFFER (w
->buffer
), pt
))
12989 b
->clip_changed
= 1;
12994 /* Select FRAME to forward the values of frame-local variables into C
12995 variables so that the redisplay routines can access those values
12999 select_frame_for_redisplay (Lisp_Object frame
)
13001 Lisp_Object tail
, tem
;
13002 Lisp_Object old
= selected_frame
;
13003 struct Lisp_Symbol
*sym
;
13005 eassert (FRAMEP (frame
) && FRAME_LIVE_P (XFRAME (frame
)));
13007 selected_frame
= frame
;
13010 for (tail
= XFRAME (frame
)->param_alist
;
13011 CONSP (tail
); tail
= XCDR (tail
))
13012 if (CONSP (XCAR (tail
))
13013 && (tem
= XCAR (XCAR (tail
)),
13015 && (sym
= indirect_variable (XSYMBOL (tem
)),
13016 sym
->redirect
== SYMBOL_LOCALIZED
)
13017 && sym
->val
.blv
->frame_local
)
13018 /* Use find_symbol_value rather than Fsymbol_value
13019 to avoid an error if it is void. */
13020 find_symbol_value (tem
);
13021 } while (!EQ (frame
, old
) && (frame
= old
, 1));
13025 #define STOP_POLLING \
13026 do { if (! polling_stopped_here) stop_polling (); \
13027 polling_stopped_here = 1; } while (0)
13029 #define RESUME_POLLING \
13030 do { if (polling_stopped_here) start_polling (); \
13031 polling_stopped_here = 0; } while (0)
13034 /* Perhaps in the future avoid recentering windows if it
13035 is not necessary; currently that causes some problems. */
13038 redisplay_internal (void)
13040 struct window
*w
= XWINDOW (selected_window
);
13044 int must_finish
= 0;
13045 struct text_pos tlbufpos
, tlendpos
;
13046 int number_of_visible_frames
;
13047 ptrdiff_t count
, count1
;
13049 int polling_stopped_here
= 0;
13050 Lisp_Object tail
, frame
, old_frame
= selected_frame
;
13051 struct backtrace backtrace
;
13053 /* Non-zero means redisplay has to consider all windows on all
13054 frames. Zero means, only selected_window is considered. */
13055 int consider_all_windows_p
;
13057 /* Non-zero means redisplay has to redisplay the miniwindow. */
13058 int update_miniwindow_p
= 0;
13060 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
13062 /* No redisplay if running in batch mode or frame is not yet fully
13063 initialized, or redisplay is explicitly turned off by setting
13064 Vinhibit_redisplay. */
13065 if (FRAME_INITIAL_P (SELECTED_FRAME ())
13066 || !NILP (Vinhibit_redisplay
))
13069 /* Don't examine these until after testing Vinhibit_redisplay.
13070 When Emacs is shutting down, perhaps because its connection to
13071 X has dropped, we should not look at them at all. */
13072 fr
= XFRAME (w
->frame
);
13073 sf
= SELECTED_FRAME ();
13075 if (!fr
->glyphs_initialized_p
)
13078 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
13079 if (popup_activated ())
13083 /* I don't think this happens but let's be paranoid. */
13084 if (redisplaying_p
)
13087 /* Record a function that clears redisplaying_p
13088 when we leave this function. */
13089 count
= SPECPDL_INDEX ();
13090 record_unwind_protect (unwind_redisplay
, selected_frame
);
13091 redisplaying_p
= 1;
13092 specbind (Qinhibit_free_realized_faces
, Qnil
);
13094 /* Record this function, so it appears on the profiler's backtraces. */
13095 backtrace
.next
= backtrace_list
;
13096 backtrace
.function
= Qredisplay_internal
;
13097 backtrace
.args
= &Qnil
;
13098 backtrace
.nargs
= 0;
13099 backtrace
.debug_on_exit
= 0;
13100 backtrace_list
= &backtrace
;
13102 FOR_EACH_FRAME (tail
, frame
)
13103 XFRAME (frame
)->already_hscrolled_p
= 0;
13106 /* Remember the currently selected window. */
13109 if (!EQ (old_frame
, selected_frame
)
13110 && FRAME_LIVE_P (XFRAME (old_frame
)))
13111 /* When running redisplay, we play a bit fast-and-loose and allow e.g.
13112 selected_frame and selected_window to be temporarily out-of-sync so
13113 when we come back here via `goto retry', we need to resync because we
13114 may need to run Elisp code (via prepare_menu_bars). */
13115 select_frame_for_redisplay (old_frame
);
13118 reconsider_clip_changes (w
, current_buffer
);
13119 last_escape_glyph_frame
= NULL
;
13120 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
13121 last_glyphless_glyph_frame
= NULL
;
13122 last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
13124 /* If new fonts have been loaded that make a glyph matrix adjustment
13125 necessary, do it. */
13126 if (fonts_changed_p
)
13128 adjust_glyphs (NULL
);
13129 ++windows_or_buffers_changed
;
13130 fonts_changed_p
= 0;
13133 /* If face_change_count is non-zero, init_iterator will free all
13134 realized faces, which includes the faces referenced from current
13135 matrices. So, we can't reuse current matrices in this case. */
13136 if (face_change_count
)
13137 ++windows_or_buffers_changed
;
13139 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
13140 && FRAME_TTY (sf
)->previous_frame
!= sf
)
13142 /* Since frames on a single ASCII terminal share the same
13143 display area, displaying a different frame means redisplay
13144 the whole thing. */
13145 windows_or_buffers_changed
++;
13146 SET_FRAME_GARBAGED (sf
);
13148 set_tty_color_mode (FRAME_TTY (sf
), sf
);
13150 FRAME_TTY (sf
)->previous_frame
= sf
;
13153 /* Set the visible flags for all frames. Do this before checking for
13154 resized or garbaged frames; they want to know if their frames are
13155 visible. See the comment in frame.h for FRAME_SAMPLE_VISIBILITY. */
13156 number_of_visible_frames
= 0;
13158 FOR_EACH_FRAME (tail
, frame
)
13160 struct frame
*f
= XFRAME (frame
);
13162 FRAME_SAMPLE_VISIBILITY (f
);
13163 if (FRAME_VISIBLE_P (f
))
13164 ++number_of_visible_frames
;
13165 clear_desired_matrices (f
);
13168 /* Notice any pending interrupt request to change frame size. */
13169 do_pending_window_change (1);
13171 /* do_pending_window_change could change the selected_window due to
13172 frame resizing which makes the selected window too small. */
13173 if (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
)
13176 reconsider_clip_changes (w
, current_buffer
);
13179 /* Clear frames marked as garbaged. */
13180 clear_garbaged_frames ();
13182 /* Build menubar and tool-bar items. */
13183 if (NILP (Vmemory_full
))
13184 prepare_menu_bars ();
13186 if (windows_or_buffers_changed
)
13187 update_mode_lines
++;
13189 /* Detect case that we need to write or remove a star in the mode line. */
13190 if ((SAVE_MODIFF
< MODIFF
) != w
->last_had_star
)
13192 w
->update_mode_line
= 1;
13193 if (buffer_shared_and_changed ())
13194 update_mode_lines
++;
13197 /* Avoid invocation of point motion hooks by `current_column' below. */
13198 count1
= SPECPDL_INDEX ();
13199 specbind (Qinhibit_point_motion_hooks
, Qt
);
13201 /* If %c is in the mode line, update it if needed. */
13202 if (!NILP (w
->column_number_displayed
)
13203 /* This alternative quickly identifies a common case
13204 where no change is needed. */
13205 && !(PT
== w
->last_point
&& !window_outdated (w
))
13206 && (XFASTINT (w
->column_number_displayed
) != current_column ()))
13207 w
->update_mode_line
= 1;
13209 unbind_to (count1
, Qnil
);
13211 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
13213 /* The variable buffer_shared is set in redisplay_window and
13214 indicates that we redisplay a buffer in different windows. See
13216 consider_all_windows_p
= (update_mode_lines
13217 || buffer_shared_and_changed ()
13218 || cursor_type_changed
);
13220 /* If specs for an arrow have changed, do thorough redisplay
13221 to ensure we remove any arrow that should no longer exist. */
13222 if (overlay_arrows_changed_p ())
13223 consider_all_windows_p
= windows_or_buffers_changed
= 1;
13225 /* Normally the message* functions will have already displayed and
13226 updated the echo area, but the frame may have been trashed, or
13227 the update may have been preempted, so display the echo area
13228 again here. Checking message_cleared_p captures the case that
13229 the echo area should be cleared. */
13230 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
13231 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
13232 || (message_cleared_p
13233 && minibuf_level
== 0
13234 /* If the mini-window is currently selected, this means the
13235 echo-area doesn't show through. */
13236 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
13238 int window_height_changed_p
= echo_area_display (0);
13240 if (message_cleared_p
)
13241 update_miniwindow_p
= 1;
13245 /* If we don't display the current message, don't clear the
13246 message_cleared_p flag, because, if we did, we wouldn't clear
13247 the echo area in the next redisplay which doesn't preserve
13249 if (!display_last_displayed_message_p
)
13250 message_cleared_p
= 0;
13252 if (fonts_changed_p
)
13254 else if (window_height_changed_p
)
13256 consider_all_windows_p
= 1;
13257 ++update_mode_lines
;
13258 ++windows_or_buffers_changed
;
13260 /* If window configuration was changed, frames may have been
13261 marked garbaged. Clear them or we will experience
13262 surprises wrt scrolling. */
13263 clear_garbaged_frames ();
13266 else if (EQ (selected_window
, minibuf_window
)
13267 && (current_buffer
->clip_changed
|| window_outdated (w
))
13268 && resize_mini_window (w
, 0))
13270 /* Resized active mini-window to fit the size of what it is
13271 showing if its contents might have changed. */
13273 /* FIXME: this causes all frames to be updated, which seems unnecessary
13274 since only the current frame needs to be considered. This function
13275 needs to be rewritten with two variables, consider_all_windows and
13276 consider_all_frames. */
13277 consider_all_windows_p
= 1;
13278 ++windows_or_buffers_changed
;
13279 ++update_mode_lines
;
13281 /* If window configuration was changed, frames may have been
13282 marked garbaged. Clear them or we will experience
13283 surprises wrt scrolling. */
13284 clear_garbaged_frames ();
13288 /* If showing the region, and mark has changed, we must redisplay
13289 the whole window. The assignment to this_line_start_pos prevents
13290 the optimization directly below this if-statement. */
13291 if (((!NILP (Vtransient_mark_mode
)
13292 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
13293 != !NILP (w
->region_showing
))
13294 || (!NILP (w
->region_showing
)
13295 && !EQ (w
->region_showing
,
13296 Fmarker_position (BVAR (XBUFFER (w
->buffer
), mark
)))))
13297 CHARPOS (this_line_start_pos
) = 0;
13299 /* Optimize the case that only the line containing the cursor in the
13300 selected window has changed. Variables starting with this_ are
13301 set in display_line and record information about the line
13302 containing the cursor. */
13303 tlbufpos
= this_line_start_pos
;
13304 tlendpos
= this_line_end_pos
;
13305 if (!consider_all_windows_p
13306 && CHARPOS (tlbufpos
) > 0
13307 && !w
->update_mode_line
13308 && !current_buffer
->clip_changed
13309 && !current_buffer
->prevent_redisplay_optimizations_p
13310 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
13311 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
13312 /* Make sure recorded data applies to current buffer, etc. */
13313 && this_line_buffer
== current_buffer
13314 && current_buffer
== XBUFFER (w
->buffer
)
13316 && !w
->optional_new_start
13317 /* Point must be on the line that we have info recorded about. */
13318 && PT
>= CHARPOS (tlbufpos
)
13319 && PT
<= Z
- CHARPOS (tlendpos
)
13320 /* All text outside that line, including its final newline,
13321 must be unchanged. */
13322 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
13323 CHARPOS (tlendpos
)))
13325 if (CHARPOS (tlbufpos
) > BEGV
13326 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
13327 && (CHARPOS (tlbufpos
) == ZV
13328 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
13329 /* Former continuation line has disappeared by becoming empty. */
13331 else if (window_outdated (w
) || MINI_WINDOW_P (w
))
13333 /* We have to handle the case of continuation around a
13334 wide-column character (see the comment in indent.c around
13337 For instance, in the following case:
13339 -------- Insert --------
13340 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
13341 J_I_ ==> J_I_ `^^' are cursors.
13345 As we have to redraw the line above, we cannot use this
13349 int line_height_before
= this_line_pixel_height
;
13351 /* Note that start_display will handle the case that the
13352 line starting at tlbufpos is a continuation line. */
13353 start_display (&it
, w
, tlbufpos
);
13355 /* Implementation note: It this still necessary? */
13356 if (it
.current_x
!= this_line_start_x
)
13359 TRACE ((stderr
, "trying display optimization 1\n"));
13360 w
->cursor
.vpos
= -1;
13361 overlay_arrow_seen
= 0;
13362 it
.vpos
= this_line_vpos
;
13363 it
.current_y
= this_line_y
;
13364 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
13365 display_line (&it
);
13367 /* If line contains point, is not continued,
13368 and ends at same distance from eob as before, we win. */
13369 if (w
->cursor
.vpos
>= 0
13370 /* Line is not continued, otherwise this_line_start_pos
13371 would have been set to 0 in display_line. */
13372 && CHARPOS (this_line_start_pos
)
13373 /* Line ends as before. */
13374 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
13375 /* Line has same height as before. Otherwise other lines
13376 would have to be shifted up or down. */
13377 && this_line_pixel_height
== line_height_before
)
13379 /* If this is not the window's last line, we must adjust
13380 the charstarts of the lines below. */
13381 if (it
.current_y
< it
.last_visible_y
)
13383 struct glyph_row
*row
13384 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
13385 ptrdiff_t delta
, delta_bytes
;
13387 /* We used to distinguish between two cases here,
13388 conditioned by Z - CHARPOS (tlendpos) == ZV, for
13389 when the line ends in a newline or the end of the
13390 buffer's accessible portion. But both cases did
13391 the same, so they were collapsed. */
13393 - CHARPOS (tlendpos
)
13394 - MATRIX_ROW_START_CHARPOS (row
));
13395 delta_bytes
= (Z_BYTE
13396 - BYTEPOS (tlendpos
)
13397 - MATRIX_ROW_START_BYTEPOS (row
));
13399 increment_matrix_positions (w
->current_matrix
,
13400 this_line_vpos
+ 1,
13401 w
->current_matrix
->nrows
,
13402 delta
, delta_bytes
);
13405 /* If this row displays text now but previously didn't,
13406 or vice versa, w->window_end_vpos may have to be
13408 if ((it
.glyph_row
- 1)->displays_text_p
)
13410 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
13411 wset_window_end_vpos (w
, make_number (this_line_vpos
));
13413 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
13414 && this_line_vpos
> 0)
13415 wset_window_end_vpos (w
, make_number (this_line_vpos
- 1));
13416 wset_window_end_valid (w
, Qnil
);
13418 /* Update hint: No need to try to scroll in update_window. */
13419 w
->desired_matrix
->no_scrolling_p
= 1;
13422 *w
->desired_matrix
->method
= 0;
13423 debug_method_add (w
, "optimization 1");
13426 //debug optimization movement issue
13427 //w->desired_matrix->no_scrolling_p = 1;
13428 //*w->desired_matrix->method = 0;
13429 //debug_method_add (w, "optimization 1");
13432 #ifdef HAVE_WINDOW_SYSTEM
13433 update_window_fringes (w
, 0);
13440 else if (/* Cursor position hasn't changed. */
13441 PT
== w
->last_point
13442 /* Make sure the cursor was last displayed
13443 in this window. Otherwise we have to reposition it. */
13444 && 0 <= w
->cursor
.vpos
13445 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
13449 do_pending_window_change (1);
13450 /* If selected_window changed, redisplay again. */
13451 if (WINDOWP (selected_window
)
13452 && (w
= XWINDOW (selected_window
)) != sw
)
13455 /* We used to always goto end_of_redisplay here, but this
13456 isn't enough if we have a blinking cursor. */
13457 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
13458 goto end_of_redisplay
;
13462 /* If highlighting the region, or if the cursor is in the echo area,
13463 then we can't just move the cursor. */
13464 else if (! (!NILP (Vtransient_mark_mode
)
13465 && !NILP (BVAR (current_buffer
, mark_active
)))
13466 && (EQ (selected_window
,
13467 BVAR (current_buffer
, last_selected_window
))
13468 || highlight_nonselected_windows
)
13469 && NILP (w
->region_showing
)
13470 && NILP (Vshow_trailing_whitespace
)
13471 && !cursor_in_echo_area
)
13474 struct glyph_row
*row
;
13476 /* Skip from tlbufpos to PT and see where it is. Note that
13477 PT may be in invisible text. If so, we will end at the
13478 next visible position. */
13479 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
13480 NULL
, DEFAULT_FACE_ID
);
13481 it
.current_x
= this_line_start_x
;
13482 it
.current_y
= this_line_y
;
13483 it
.vpos
= this_line_vpos
;
13485 /* The call to move_it_to stops in front of PT, but
13486 moves over before-strings. */
13487 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
13489 if (it
.vpos
== this_line_vpos
13490 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
13493 eassert (this_line_vpos
== it
.vpos
);
13494 eassert (this_line_y
== it
.current_y
);
13495 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13497 *w
->desired_matrix
->method
= 0;
13498 debug_method_add (w
, "optimization 3");
13507 /* Text changed drastically or point moved off of line. */
13508 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
13511 CHARPOS (this_line_start_pos
) = 0;
13512 consider_all_windows_p
|= buffer_shared_and_changed ();
13513 ++clear_face_cache_count
;
13514 #ifdef HAVE_WINDOW_SYSTEM
13515 ++clear_image_cache_count
;
13518 /* Build desired matrices, and update the display. If
13519 consider_all_windows_p is non-zero, do it for all windows on all
13520 frames. Otherwise do it for selected_window, only. */
13522 if (consider_all_windows_p
)
13524 FOR_EACH_FRAME (tail
, frame
)
13525 XFRAME (frame
)->updated_p
= 0;
13527 /* Recompute # windows showing selected buffer. This will be
13528 incremented each time such a window is displayed. */
13531 FOR_EACH_FRAME (tail
, frame
)
13533 struct frame
*f
= XFRAME (frame
);
13535 /* We don't have to do anything for unselected terminal
13537 if ((FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
13538 && !EQ (FRAME_TTY (f
)->top_frame
, frame
))
13541 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
13543 if (! EQ (frame
, selected_frame
))
13544 /* Select the frame, for the sake of frame-local
13546 select_frame_for_redisplay (frame
);
13548 /* Mark all the scroll bars to be removed; we'll redeem
13549 the ones we want when we redisplay their windows. */
13550 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
13551 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
13553 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13554 redisplay_windows (FRAME_ROOT_WINDOW (f
));
13556 /* The X error handler may have deleted that frame. */
13557 if (!FRAME_LIVE_P (f
))
13560 /* Any scroll bars which redisplay_windows should have
13561 nuked should now go away. */
13562 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
13563 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
13565 /* If fonts changed, display again. */
13566 /* ??? rms: I suspect it is a mistake to jump all the way
13567 back to retry here. It should just retry this frame. */
13568 if (fonts_changed_p
)
13571 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13573 /* See if we have to hscroll. */
13574 if (!f
->already_hscrolled_p
)
13576 f
->already_hscrolled_p
= 1;
13577 if (hscroll_windows (f
->root_window
))
13581 /* Prevent various kinds of signals during display
13582 update. stdio is not robust about handling
13583 signals, which can cause an apparent I/O
13585 if (interrupt_input
)
13586 unrequest_sigio ();
13589 /* Update the display. */
13590 set_window_update_flags (XWINDOW (f
->root_window
), 1);
13591 pending
|= update_frame (f
, 0, 0);
13597 if (!EQ (old_frame
, selected_frame
)
13598 && FRAME_LIVE_P (XFRAME (old_frame
)))
13599 /* We played a bit fast-and-loose above and allowed selected_frame
13600 and selected_window to be temporarily out-of-sync but let's make
13601 sure this stays contained. */
13602 select_frame_for_redisplay (old_frame
);
13603 eassert (EQ (XFRAME (selected_frame
)->selected_window
,
13608 /* Do the mark_window_display_accurate after all windows have
13609 been redisplayed because this call resets flags in buffers
13610 which are needed for proper redisplay. */
13611 FOR_EACH_FRAME (tail
, frame
)
13613 struct frame
*f
= XFRAME (frame
);
13616 mark_window_display_accurate (f
->root_window
, 1);
13617 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
13618 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
13623 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13625 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13626 struct frame
*mini_frame
;
13628 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
13629 /* Use list_of_error, not Qerror, so that
13630 we catch only errors and don't run the debugger. */
13631 internal_condition_case_1 (redisplay_window_1
, selected_window
,
13633 redisplay_window_error
);
13634 if (update_miniwindow_p
)
13635 internal_condition_case_1 (redisplay_window_1
, mini_window
,
13637 redisplay_window_error
);
13639 /* Compare desired and current matrices, perform output. */
13642 /* If fonts changed, display again. */
13643 if (fonts_changed_p
)
13646 /* Prevent various kinds of signals during display update.
13647 stdio is not robust about handling signals,
13648 which can cause an apparent I/O error. */
13649 if (interrupt_input
)
13650 unrequest_sigio ();
13653 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13655 if (hscroll_windows (selected_window
))
13658 XWINDOW (selected_window
)->must_be_updated_p
= 1;
13659 pending
= update_frame (sf
, 0, 0);
13662 /* We may have called echo_area_display at the top of this
13663 function. If the echo area is on another frame, that may
13664 have put text on a frame other than the selected one, so the
13665 above call to update_frame would not have caught it. Catch
13667 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13668 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
13670 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
13672 XWINDOW (mini_window
)->must_be_updated_p
= 1;
13673 pending
|= update_frame (mini_frame
, 0, 0);
13674 if (!pending
&& hscroll_windows (mini_window
))
13679 /* If display was paused because of pending input, make sure we do a
13680 thorough update the next time. */
13683 /* Prevent the optimization at the beginning of
13684 redisplay_internal that tries a single-line update of the
13685 line containing the cursor in the selected window. */
13686 CHARPOS (this_line_start_pos
) = 0;
13688 /* Let the overlay arrow be updated the next time. */
13689 update_overlay_arrows (0);
13691 /* If we pause after scrolling, some rows in the current
13692 matrices of some windows are not valid. */
13693 if (!WINDOW_FULL_WIDTH_P (w
)
13694 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
13695 update_mode_lines
= 1;
13699 if (!consider_all_windows_p
)
13701 /* This has already been done above if
13702 consider_all_windows_p is set. */
13703 mark_window_display_accurate_1 (w
, 1);
13705 /* Say overlay arrows are up to date. */
13706 update_overlay_arrows (1);
13708 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
13709 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
13712 update_mode_lines
= 0;
13713 windows_or_buffers_changed
= 0;
13714 cursor_type_changed
= 0;
13717 /* Start SIGIO interrupts coming again. Having them off during the
13718 code above makes it less likely one will discard output, but not
13719 impossible, since there might be stuff in the system buffer here.
13720 But it is much hairier to try to do anything about that. */
13721 if (interrupt_input
)
13725 /* If a frame has become visible which was not before, redisplay
13726 again, so that we display it. Expose events for such a frame
13727 (which it gets when becoming visible) don't call the parts of
13728 redisplay constructing glyphs, so simply exposing a frame won't
13729 display anything in this case. So, we have to display these
13730 frames here explicitly. */
13735 FOR_EACH_FRAME (tail
, frame
)
13737 int this_is_visible
= 0;
13739 if (XFRAME (frame
)->visible
)
13740 this_is_visible
= 1;
13741 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
13742 if (XFRAME (frame
)->visible
)
13743 this_is_visible
= 1;
13745 if (this_is_visible
)
13749 if (new_count
!= number_of_visible_frames
)
13750 windows_or_buffers_changed
++;
13753 /* Change frame size now if a change is pending. */
13754 do_pending_window_change (1);
13756 /* If we just did a pending size change, or have additional
13757 visible frames, or selected_window changed, redisplay again. */
13758 if ((windows_or_buffers_changed
&& !pending
)
13759 || (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
))
13762 /* Clear the face and image caches.
13764 We used to do this only if consider_all_windows_p. But the cache
13765 needs to be cleared if a timer creates images in the current
13766 buffer (e.g. the test case in Bug#6230). */
13768 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
13770 clear_face_cache (0);
13771 clear_face_cache_count
= 0;
13774 #ifdef HAVE_WINDOW_SYSTEM
13775 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
13777 clear_image_caches (Qnil
);
13778 clear_image_cache_count
= 0;
13780 #endif /* HAVE_WINDOW_SYSTEM */
13783 backtrace_list
= backtrace
.next
;
13784 unbind_to (count
, Qnil
);
13789 /* Redisplay, but leave alone any recent echo area message unless
13790 another message has been requested in its place.
13792 This is useful in situations where you need to redisplay but no
13793 user action has occurred, making it inappropriate for the message
13794 area to be cleared. See tracking_off and
13795 wait_reading_process_output for examples of these situations.
13797 FROM_WHERE is an integer saying from where this function was
13798 called. This is useful for debugging. */
13801 redisplay_preserve_echo_area (int from_where
)
13803 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
13805 if (!NILP (echo_area_buffer
[1]))
13807 /* We have a previously displayed message, but no current
13808 message. Redisplay the previous message. */
13809 display_last_displayed_message_p
= 1;
13810 redisplay_internal ();
13811 display_last_displayed_message_p
= 0;
13814 redisplay_internal ();
13816 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
13817 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
13818 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
13822 /* Function registered with record_unwind_protect in redisplay_internal.
13823 Clear redisplaying_p. Also, select the previously
13824 selected frame, unless it has been deleted (by an X connection
13825 failure during redisplay, for example). */
13828 unwind_redisplay (Lisp_Object old_frame
)
13830 redisplaying_p
= 0;
13831 if (! EQ (old_frame
, selected_frame
)
13832 && FRAME_LIVE_P (XFRAME (old_frame
)))
13833 select_frame_for_redisplay (old_frame
);
13838 /* Mark the display of window W as accurate or inaccurate. If
13839 ACCURATE_P is non-zero mark display of W as accurate. If
13840 ACCURATE_P is zero, arrange for W to be redisplayed the next time
13841 redisplay_internal is called. */
13844 mark_window_display_accurate_1 (struct window
*w
, int accurate_p
)
13846 if (BUFFERP (w
->buffer
))
13848 struct buffer
*b
= XBUFFER (w
->buffer
);
13850 w
->last_modified
= accurate_p
? BUF_MODIFF(b
) : 0;
13851 w
->last_overlay_modified
= accurate_p
? BUF_OVERLAY_MODIFF(b
) : 0;
13853 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
);
13857 b
->clip_changed
= 0;
13858 b
->prevent_redisplay_optimizations_p
= 0;
13860 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
13861 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
13862 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
13863 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
13865 w
->current_matrix
->buffer
= b
;
13866 w
->current_matrix
->begv
= BUF_BEGV (b
);
13867 w
->current_matrix
->zv
= BUF_ZV (b
);
13869 w
->last_cursor
= w
->cursor
;
13870 w
->last_cursor_off_p
= w
->cursor_off_p
;
13872 if (w
== XWINDOW (selected_window
))
13873 w
->last_point
= BUF_PT (b
);
13875 w
->last_point
= XMARKER (w
->pointm
)->charpos
;
13881 wset_window_end_valid (w
, w
->buffer
);
13882 w
->update_mode_line
= 0;
13887 /* Mark the display of windows in the window tree rooted at WINDOW as
13888 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
13889 windows as accurate. If ACCURATE_P is zero, arrange for windows to
13890 be redisplayed the next time redisplay_internal is called. */
13893 mark_window_display_accurate (Lisp_Object window
, int accurate_p
)
13897 for (; !NILP (window
); window
= w
->next
)
13899 w
= XWINDOW (window
);
13900 mark_window_display_accurate_1 (w
, accurate_p
);
13902 if (!NILP (w
->vchild
))
13903 mark_window_display_accurate (w
->vchild
, accurate_p
);
13904 if (!NILP (w
->hchild
))
13905 mark_window_display_accurate (w
->hchild
, accurate_p
);
13910 update_overlay_arrows (1);
13914 /* Force a thorough redisplay the next time by setting
13915 last_arrow_position and last_arrow_string to t, which is
13916 unequal to any useful value of Voverlay_arrow_... */
13917 update_overlay_arrows (-1);
13922 /* Return value in display table DP (Lisp_Char_Table *) for character
13923 C. Since a display table doesn't have any parent, we don't have to
13924 follow parent. Do not call this function directly but use the
13925 macro DISP_CHAR_VECTOR. */
13928 disp_char_vector (struct Lisp_Char_Table
*dp
, int c
)
13932 if (ASCII_CHAR_P (c
))
13935 if (SUB_CHAR_TABLE_P (val
))
13936 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
13942 XSETCHAR_TABLE (table
, dp
);
13943 val
= char_table_ref (table
, c
);
13952 /***********************************************************************
13954 ***********************************************************************/
13956 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
13959 redisplay_windows (Lisp_Object window
)
13961 while (!NILP (window
))
13963 struct window
*w
= XWINDOW (window
);
13965 if (!NILP (w
->hchild
))
13966 redisplay_windows (w
->hchild
);
13967 else if (!NILP (w
->vchild
))
13968 redisplay_windows (w
->vchild
);
13969 else if (!NILP (w
->buffer
))
13971 displayed_buffer
= XBUFFER (w
->buffer
);
13972 /* Use list_of_error, not Qerror, so that
13973 we catch only errors and don't run the debugger. */
13974 internal_condition_case_1 (redisplay_window_0
, window
,
13976 redisplay_window_error
);
13984 redisplay_window_error (Lisp_Object ignore
)
13986 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
13991 redisplay_window_0 (Lisp_Object window
)
13993 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
13994 redisplay_window (window
, 0);
13999 redisplay_window_1 (Lisp_Object window
)
14001 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
14002 redisplay_window (window
, 1);
14007 /* Set cursor position of W. PT is assumed to be displayed in ROW.
14008 DELTA and DELTA_BYTES are the numbers of characters and bytes by
14009 which positions recorded in ROW differ from current buffer
14012 Return 0 if cursor is not on this row, 1 otherwise. */
14015 set_cursor_from_row (struct window
*w
, struct glyph_row
*row
,
14016 struct glyph_matrix
*matrix
,
14017 ptrdiff_t delta
, ptrdiff_t delta_bytes
,
14020 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
14021 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
14022 struct glyph
*cursor
= NULL
;
14023 /* The last known character position in row. */
14024 ptrdiff_t last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
14026 ptrdiff_t pt_old
= PT
- delta
;
14027 ptrdiff_t pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
14028 ptrdiff_t pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
14029 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
14030 /* A glyph beyond the edge of TEXT_AREA which we should never
14032 struct glyph
*glyphs_end
= end
;
14033 /* Non-zero means we've found a match for cursor position, but that
14034 glyph has the avoid_cursor_p flag set. */
14035 int match_with_avoid_cursor
= 0;
14036 /* Non-zero means we've seen at least one glyph that came from a
14038 int string_seen
= 0;
14039 /* Largest and smallest buffer positions seen so far during scan of
14041 ptrdiff_t bpos_max
= pos_before
;
14042 ptrdiff_t bpos_min
= pos_after
;
14043 /* Last buffer position covered by an overlay string with an integer
14044 `cursor' property. */
14045 ptrdiff_t bpos_covered
= 0;
14046 /* Non-zero means the display string on which to display the cursor
14047 comes from a text property, not from an overlay. */
14048 int string_from_text_prop
= 0;
14050 /* Don't even try doing anything if called for a mode-line or
14051 header-line row, since the rest of the code isn't prepared to
14052 deal with such calamities. */
14053 eassert (!row
->mode_line_p
);
14054 if (row
->mode_line_p
)
14057 /* Skip over glyphs not having an object at the start and the end of
14058 the row. These are special glyphs like truncation marks on
14059 terminal frames. */
14060 if (row
->displays_text_p
)
14062 if (!row
->reversed_p
)
14065 && INTEGERP (glyph
->object
)
14066 && glyph
->charpos
< 0)
14068 x
+= glyph
->pixel_width
;
14072 && INTEGERP ((end
- 1)->object
)
14073 /* CHARPOS is zero for blanks and stretch glyphs
14074 inserted by extend_face_to_end_of_line. */
14075 && (end
- 1)->charpos
<= 0)
14077 glyph_before
= glyph
- 1;
14084 /* If the glyph row is reversed, we need to process it from back
14085 to front, so swap the edge pointers. */
14086 glyphs_end
= end
= glyph
- 1;
14087 glyph
+= row
->used
[TEXT_AREA
] - 1;
14089 while (glyph
> end
+ 1
14090 && INTEGERP (glyph
->object
)
14091 && glyph
->charpos
< 0)
14094 x
-= glyph
->pixel_width
;
14096 if (INTEGERP (glyph
->object
) && glyph
->charpos
< 0)
14098 /* By default, in reversed rows we put the cursor on the
14099 rightmost (first in the reading order) glyph. */
14100 for (g
= end
+ 1; g
< glyph
; g
++)
14101 x
+= g
->pixel_width
;
14103 && INTEGERP ((end
+ 1)->object
)
14104 && (end
+ 1)->charpos
<= 0)
14106 glyph_before
= glyph
+ 1;
14110 else if (row
->reversed_p
)
14112 /* In R2L rows that don't display text, put the cursor on the
14113 rightmost glyph. Case in point: an empty last line that is
14114 part of an R2L paragraph. */
14116 /* Avoid placing the cursor on the last glyph of the row, where
14117 on terminal frames we hold the vertical border between
14118 adjacent windows. */
14119 if (!FRAME_WINDOW_P (WINDOW_XFRAME (w
))
14120 && !WINDOW_RIGHTMOST_P (w
)
14121 && cursor
== row
->glyphs
[LAST_AREA
] - 1)
14123 x
= -1; /* will be computed below, at label compute_x */
14126 /* Step 1: Try to find the glyph whose character position
14127 corresponds to point. If that's not possible, find 2 glyphs
14128 whose character positions are the closest to point, one before
14129 point, the other after it. */
14130 if (!row
->reversed_p
)
14131 while (/* not marched to end of glyph row */
14133 /* glyph was not inserted by redisplay for internal purposes */
14134 && !INTEGERP (glyph
->object
))
14136 if (BUFFERP (glyph
->object
))
14138 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
14140 if (glyph
->charpos
> bpos_max
)
14141 bpos_max
= glyph
->charpos
;
14142 if (glyph
->charpos
< bpos_min
)
14143 bpos_min
= glyph
->charpos
;
14144 if (!glyph
->avoid_cursor_p
)
14146 /* If we hit point, we've found the glyph on which to
14147 display the cursor. */
14150 match_with_avoid_cursor
= 0;
14153 /* See if we've found a better approximation to
14154 POS_BEFORE or to POS_AFTER. */
14155 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
14157 pos_before
= glyph
->charpos
;
14158 glyph_before
= glyph
;
14160 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
14162 pos_after
= glyph
->charpos
;
14163 glyph_after
= glyph
;
14166 else if (dpos
== 0)
14167 match_with_avoid_cursor
= 1;
14169 else if (STRINGP (glyph
->object
))
14171 Lisp_Object chprop
;
14172 ptrdiff_t glyph_pos
= glyph
->charpos
;
14174 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
14176 if (!NILP (chprop
))
14178 /* If the string came from a `display' text property,
14179 look up the buffer position of that property and
14180 use that position to update bpos_max, as if we
14181 actually saw such a position in one of the row's
14182 glyphs. This helps with supporting integer values
14183 of `cursor' property on the display string in
14184 situations where most or all of the row's buffer
14185 text is completely covered by display properties,
14186 so that no glyph with valid buffer positions is
14187 ever seen in the row. */
14188 ptrdiff_t prop_pos
=
14189 string_buffer_position_lim (glyph
->object
, pos_before
,
14192 if (prop_pos
>= pos_before
)
14193 bpos_max
= prop_pos
- 1;
14195 if (INTEGERP (chprop
))
14197 bpos_covered
= bpos_max
+ XINT (chprop
);
14198 /* If the `cursor' property covers buffer positions up
14199 to and including point, we should display cursor on
14200 this glyph. Note that, if a `cursor' property on one
14201 of the string's characters has an integer value, we
14202 will break out of the loop below _before_ we get to
14203 the position match above. IOW, integer values of
14204 the `cursor' property override the "exact match for
14205 point" strategy of positioning the cursor. */
14206 /* Implementation note: bpos_max == pt_old when, e.g.,
14207 we are in an empty line, where bpos_max is set to
14208 MATRIX_ROW_START_CHARPOS, see above. */
14209 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14218 x
+= glyph
->pixel_width
;
14221 else if (glyph
> end
) /* row is reversed */
14222 while (!INTEGERP (glyph
->object
))
14224 if (BUFFERP (glyph
->object
))
14226 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
14228 if (glyph
->charpos
> bpos_max
)
14229 bpos_max
= glyph
->charpos
;
14230 if (glyph
->charpos
< bpos_min
)
14231 bpos_min
= glyph
->charpos
;
14232 if (!glyph
->avoid_cursor_p
)
14236 match_with_avoid_cursor
= 0;
14239 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
14241 pos_before
= glyph
->charpos
;
14242 glyph_before
= glyph
;
14244 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
14246 pos_after
= glyph
->charpos
;
14247 glyph_after
= glyph
;
14250 else if (dpos
== 0)
14251 match_with_avoid_cursor
= 1;
14253 else if (STRINGP (glyph
->object
))
14255 Lisp_Object chprop
;
14256 ptrdiff_t glyph_pos
= glyph
->charpos
;
14258 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
14260 if (!NILP (chprop
))
14262 ptrdiff_t prop_pos
=
14263 string_buffer_position_lim (glyph
->object
, pos_before
,
14266 if (prop_pos
>= pos_before
)
14267 bpos_max
= prop_pos
- 1;
14269 if (INTEGERP (chprop
))
14271 bpos_covered
= bpos_max
+ XINT (chprop
);
14272 /* If the `cursor' property covers buffer positions up
14273 to and including point, we should display cursor on
14275 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14284 if (glyph
== glyphs_end
) /* don't dereference outside TEXT_AREA */
14286 x
--; /* can't use any pixel_width */
14289 x
-= glyph
->pixel_width
;
14292 /* Step 2: If we didn't find an exact match for point, we need to
14293 look for a proper place to put the cursor among glyphs between
14294 GLYPH_BEFORE and GLYPH_AFTER. */
14295 if (!((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14296 && BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14297 && !(bpos_max
< pt_old
&& pt_old
<= bpos_covered
))
14299 /* An empty line has a single glyph whose OBJECT is zero and
14300 whose CHARPOS is the position of a newline on that line.
14301 Note that on a TTY, there are more glyphs after that, which
14302 were produced by extend_face_to_end_of_line, but their
14303 CHARPOS is zero or negative. */
14305 (row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14306 && INTEGERP (glyph
->object
) && glyph
->charpos
> 0;
14308 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
14310 ptrdiff_t ellipsis_pos
;
14312 /* Scan back over the ellipsis glyphs. */
14313 if (!row
->reversed_p
)
14315 ellipsis_pos
= (glyph
- 1)->charpos
;
14316 while (glyph
> row
->glyphs
[TEXT_AREA
]
14317 && (glyph
- 1)->charpos
== ellipsis_pos
)
14318 glyph
--, x
-= glyph
->pixel_width
;
14319 /* That loop always goes one position too far, including
14320 the glyph before the ellipsis. So scan forward over
14322 x
+= glyph
->pixel_width
;
14325 else /* row is reversed */
14327 ellipsis_pos
= (glyph
+ 1)->charpos
;
14328 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14329 && (glyph
+ 1)->charpos
== ellipsis_pos
)
14330 glyph
++, x
+= glyph
->pixel_width
;
14331 x
-= glyph
->pixel_width
;
14335 else if (match_with_avoid_cursor
)
14337 cursor
= glyph_after
;
14340 else if (string_seen
)
14342 int incr
= row
->reversed_p
? -1 : +1;
14344 /* Need to find the glyph that came out of a string which is
14345 present at point. That glyph is somewhere between
14346 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
14347 positioned between POS_BEFORE and POS_AFTER in the
14349 struct glyph
*start
, *stop
;
14350 ptrdiff_t pos
= pos_before
;
14354 /* If the row ends in a newline from a display string,
14355 reordering could have moved the glyphs belonging to the
14356 string out of the [GLYPH_BEFORE..GLYPH_AFTER] range. So
14357 in this case we extend the search to the last glyph in
14358 the row that was not inserted by redisplay. */
14359 if (row
->ends_in_newline_from_string_p
)
14362 pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
14365 /* GLYPH_BEFORE and GLYPH_AFTER are the glyphs that
14366 correspond to POS_BEFORE and POS_AFTER, respectively. We
14367 need START and STOP in the order that corresponds to the
14368 row's direction as given by its reversed_p flag. If the
14369 directionality of characters between POS_BEFORE and
14370 POS_AFTER is the opposite of the row's base direction,
14371 these characters will have been reordered for display,
14372 and we need to reverse START and STOP. */
14373 if (!row
->reversed_p
)
14375 start
= min (glyph_before
, glyph_after
);
14376 stop
= max (glyph_before
, glyph_after
);
14380 start
= max (glyph_before
, glyph_after
);
14381 stop
= min (glyph_before
, glyph_after
);
14383 for (glyph
= start
+ incr
;
14384 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
14387 /* Any glyphs that come from the buffer are here because
14388 of bidi reordering. Skip them, and only pay
14389 attention to glyphs that came from some string. */
14390 if (STRINGP (glyph
->object
))
14394 /* If the display property covers the newline, we
14395 need to search for it one position farther. */
14396 ptrdiff_t lim
= pos_after
14397 + (pos_after
== MATRIX_ROW_END_CHARPOS (row
) + delta
);
14399 string_from_text_prop
= 0;
14400 str
= glyph
->object
;
14401 tem
= string_buffer_position_lim (str
, pos
, lim
, 0);
14402 if (tem
== 0 /* from overlay */
14405 /* If the string from which this glyph came is
14406 found in the buffer at point, or at position
14407 that is closer to point than pos_after, then
14408 we've found the glyph we've been looking for.
14409 If it comes from an overlay (tem == 0), and
14410 it has the `cursor' property on one of its
14411 glyphs, record that glyph as a candidate for
14412 displaying the cursor. (As in the
14413 unidirectional version, we will display the
14414 cursor on the last candidate we find.) */
14417 || (tem
- pt_old
> 0 && tem
< pos_after
))
14419 /* The glyphs from this string could have
14420 been reordered. Find the one with the
14421 smallest string position. Or there could
14422 be a character in the string with the
14423 `cursor' property, which means display
14424 cursor on that character's glyph. */
14425 ptrdiff_t strpos
= glyph
->charpos
;
14430 string_from_text_prop
= 1;
14433 (row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14434 && EQ (glyph
->object
, str
);
14438 ptrdiff_t gpos
= glyph
->charpos
;
14440 cprop
= Fget_char_property (make_number (gpos
),
14448 if (tem
&& glyph
->charpos
< strpos
)
14450 strpos
= glyph
->charpos
;
14456 || (tem
- pt_old
> 0 && tem
< pos_after
))
14460 pos
= tem
+ 1; /* don't find previous instances */
14462 /* This string is not what we want; skip all of the
14463 glyphs that came from it. */
14464 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14465 && EQ (glyph
->object
, str
))
14472 /* If we reached the end of the line, and END was from a string,
14473 the cursor is not on this line. */
14475 && (row
->reversed_p
? glyph
<= end
: glyph
>= end
)
14476 && (row
->reversed_p
? end
> glyphs_end
: end
< glyphs_end
)
14477 && STRINGP (end
->object
)
14478 && row
->continued_p
)
14481 /* A truncated row may not include PT among its character positions.
14482 Setting the cursor inside the scroll margin will trigger
14483 recalculation of hscroll in hscroll_window_tree. But if a
14484 display string covers point, defer to the string-handling
14485 code below to figure this out. */
14486 else if (row
->truncated_on_left_p
&& pt_old
< bpos_min
)
14488 cursor
= glyph_before
;
14491 else if ((row
->truncated_on_right_p
&& pt_old
> bpos_max
)
14492 /* Zero-width characters produce no glyphs. */
14494 && (row
->reversed_p
14495 ? glyph_after
> glyphs_end
14496 : glyph_after
< glyphs_end
)))
14498 cursor
= glyph_after
;
14504 if (cursor
!= NULL
)
14506 else if (glyph
== glyphs_end
14507 && pos_before
== pos_after
14508 && STRINGP ((row
->reversed_p
14509 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14510 : row
->glyphs
[TEXT_AREA
])->object
))
14512 /* If all the glyphs of this row came from strings, put the
14513 cursor on the first glyph of the row. This avoids having the
14514 cursor outside of the text area in this very rare and hard
14518 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14519 : row
->glyphs
[TEXT_AREA
];
14525 /* Need to compute x that corresponds to GLYPH. */
14526 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
14528 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
14530 x
+= g
->pixel_width
;
14534 /* ROW could be part of a continued line, which, under bidi
14535 reordering, might have other rows whose start and end charpos
14536 occlude point. Only set w->cursor if we found a better
14537 approximation to the cursor position than we have from previously
14538 examined candidate rows belonging to the same continued line. */
14539 if (/* we already have a candidate row */
14540 w
->cursor
.vpos
>= 0
14541 /* that candidate is not the row we are processing */
14542 && MATRIX_ROW (matrix
, w
->cursor
.vpos
) != row
14543 /* Make sure cursor.vpos specifies a row whose start and end
14544 charpos occlude point, and it is valid candidate for being a
14545 cursor-row. This is because some callers of this function
14546 leave cursor.vpos at the row where the cursor was displayed
14547 during the last redisplay cycle. */
14548 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)) <= pt_old
14549 && pt_old
<= MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14550 && cursor_row_p (MATRIX_ROW (matrix
, w
->cursor
.vpos
)))
14553 MATRIX_ROW_GLYPH_START (matrix
, w
->cursor
.vpos
) + w
->cursor
.hpos
;
14555 /* Don't consider glyphs that are outside TEXT_AREA. */
14556 if (!(row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
))
14558 /* Keep the candidate whose buffer position is the closest to
14559 point or has the `cursor' property. */
14560 if (/* previous candidate is a glyph in TEXT_AREA of that row */
14561 w
->cursor
.hpos
>= 0
14562 && w
->cursor
.hpos
< MATRIX_ROW_USED (matrix
, w
->cursor
.vpos
)
14563 && ((BUFFERP (g1
->object
)
14564 && (g1
->charpos
== pt_old
/* an exact match always wins */
14565 || (BUFFERP (glyph
->object
)
14566 && eabs (g1
->charpos
- pt_old
)
14567 < eabs (glyph
->charpos
- pt_old
))))
14568 /* previous candidate is a glyph from a string that has
14569 a non-nil `cursor' property */
14570 || (STRINGP (g1
->object
)
14571 && (!NILP (Fget_char_property (make_number (g1
->charpos
),
14572 Qcursor
, g1
->object
))
14573 /* previous candidate is from the same display
14574 string as this one, and the display string
14575 came from a text property */
14576 || (EQ (g1
->object
, glyph
->object
)
14577 && string_from_text_prop
)
14578 /* this candidate is from newline and its
14579 position is not an exact match */
14580 || (INTEGERP (glyph
->object
)
14581 && glyph
->charpos
!= pt_old
)))))
14583 /* If this candidate gives an exact match, use that. */
14584 if (!((BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14585 /* If this candidate is a glyph created for the
14586 terminating newline of a line, and point is on that
14587 newline, it wins because it's an exact match. */
14588 || (!row
->continued_p
14589 && INTEGERP (glyph
->object
)
14590 && glyph
->charpos
== 0
14591 && pt_old
== MATRIX_ROW_END_CHARPOS (row
) - 1))
14592 /* Otherwise, keep the candidate that comes from a row
14593 spanning less buffer positions. This may win when one or
14594 both candidate positions are on glyphs that came from
14595 display strings, for which we cannot compare buffer
14597 && MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14598 - MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14599 < MATRIX_ROW_END_CHARPOS (row
) - MATRIX_ROW_START_CHARPOS (row
))
14602 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
14604 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
14605 w
->cursor
.y
= row
->y
+ dy
;
14607 if (w
== XWINDOW (selected_window
))
14609 if (!row
->continued_p
14610 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
14613 this_line_buffer
= XBUFFER (w
->buffer
);
14615 CHARPOS (this_line_start_pos
)
14616 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
14617 BYTEPOS (this_line_start_pos
)
14618 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
14620 CHARPOS (this_line_end_pos
)
14621 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
14622 BYTEPOS (this_line_end_pos
)
14623 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
14625 this_line_y
= w
->cursor
.y
;
14626 this_line_pixel_height
= row
->height
;
14627 this_line_vpos
= w
->cursor
.vpos
;
14628 this_line_start_x
= row
->x
;
14631 CHARPOS (this_line_start_pos
) = 0;
14638 /* Run window scroll functions, if any, for WINDOW with new window
14639 start STARTP. Sets the window start of WINDOW to that position.
14641 We assume that the window's buffer is really current. */
14643 static struct text_pos
14644 run_window_scroll_functions (Lisp_Object window
, struct text_pos startp
)
14646 struct window
*w
= XWINDOW (window
);
14647 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
14649 if (current_buffer
!= XBUFFER (w
->buffer
))
14652 if (!NILP (Vwindow_scroll_functions
))
14654 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
14655 make_number (CHARPOS (startp
)));
14656 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14657 /* In case the hook functions switch buffers. */
14658 set_buffer_internal (XBUFFER (w
->buffer
));
14665 /* Make sure the line containing the cursor is fully visible.
14666 A value of 1 means there is nothing to be done.
14667 (Either the line is fully visible, or it cannot be made so,
14668 or we cannot tell.)
14670 If FORCE_P is non-zero, return 0 even if partial visible cursor row
14671 is higher than window.
14673 A value of 0 means the caller should do scrolling
14674 as if point had gone off the screen. */
14677 cursor_row_fully_visible_p (struct window
*w
, int force_p
, int current_matrix_p
)
14679 struct glyph_matrix
*matrix
;
14680 struct glyph_row
*row
;
14683 if (!make_cursor_line_fully_visible_p
)
14686 /* It's not always possible to find the cursor, e.g, when a window
14687 is full of overlay strings. Don't do anything in that case. */
14688 if (w
->cursor
.vpos
< 0)
14691 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
14692 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
14694 /* If the cursor row is not partially visible, there's nothing to do. */
14695 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
14698 /* If the row the cursor is in is taller than the window's height,
14699 it's not clear what to do, so do nothing. */
14700 window_height
= window_box_height (w
);
14701 if (row
->height
>= window_height
)
14703 if (!force_p
|| MINI_WINDOW_P (w
)
14704 || w
->vscroll
|| w
->cursor
.vpos
== 0)
14711 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
14712 non-zero means only WINDOW is redisplayed in redisplay_internal.
14713 TEMP_SCROLL_STEP has the same meaning as emacs_scroll_step, and is used
14714 in redisplay_window to bring a partially visible line into view in
14715 the case that only the cursor has moved.
14717 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
14718 last screen line's vertical height extends past the end of the screen.
14722 1 if scrolling succeeded
14724 0 if scrolling didn't find point.
14726 -1 if new fonts have been loaded so that we must interrupt
14727 redisplay, adjust glyph matrices, and try again. */
14733 SCROLLING_NEED_LARGER_MATRICES
14736 /* If scroll-conservatively is more than this, never recenter.
14738 If you change this, don't forget to update the doc string of
14739 `scroll-conservatively' and the Emacs manual. */
14740 #define SCROLL_LIMIT 100
14743 try_scrolling (Lisp_Object window
, int just_this_one_p
,
14744 ptrdiff_t arg_scroll_conservatively
, ptrdiff_t scroll_step
,
14745 int temp_scroll_step
, int last_line_misfit
)
14747 struct window
*w
= XWINDOW (window
);
14748 struct frame
*f
= XFRAME (w
->frame
);
14749 struct text_pos pos
, startp
;
14751 int this_scroll_margin
, scroll_max
, rc
, height
;
14752 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
14753 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
14754 Lisp_Object aggressive
;
14755 /* We will never try scrolling more than this number of lines. */
14756 int scroll_limit
= SCROLL_LIMIT
;
14759 debug_method_add (w
, "try_scrolling");
14762 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14764 /* Compute scroll margin height in pixels. We scroll when point is
14765 within this distance from the top or bottom of the window. */
14766 if (scroll_margin
> 0)
14767 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
14768 * FRAME_LINE_HEIGHT (f
);
14770 this_scroll_margin
= 0;
14772 /* Force arg_scroll_conservatively to have a reasonable value, to
14773 avoid scrolling too far away with slow move_it_* functions. Note
14774 that the user can supply scroll-conservatively equal to
14775 `most-positive-fixnum', which can be larger than INT_MAX. */
14776 if (arg_scroll_conservatively
> scroll_limit
)
14778 arg_scroll_conservatively
= scroll_limit
+ 1;
14779 scroll_max
= scroll_limit
* FRAME_LINE_HEIGHT (f
);
14781 else if (scroll_step
|| arg_scroll_conservatively
|| temp_scroll_step
)
14782 /* Compute how much we should try to scroll maximally to bring
14783 point into view. */
14784 scroll_max
= (max (scroll_step
,
14785 max (arg_scroll_conservatively
, temp_scroll_step
))
14786 * FRAME_LINE_HEIGHT (f
));
14787 else if (NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
))
14788 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
)))
14789 /* We're trying to scroll because of aggressive scrolling but no
14790 scroll_step is set. Choose an arbitrary one. */
14791 scroll_max
= 10 * FRAME_LINE_HEIGHT (f
);
14797 /* Decide whether to scroll down. */
14798 if (PT
> CHARPOS (startp
))
14800 int scroll_margin_y
;
14802 /* Compute the pixel ypos of the scroll margin, then move IT to
14803 either that ypos or PT, whichever comes first. */
14804 start_display (&it
, w
, startp
);
14805 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
14806 - FRAME_LINE_HEIGHT (f
) * extra_scroll_margin_lines
;
14807 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
14808 (MOVE_TO_POS
| MOVE_TO_Y
));
14810 if (PT
> CHARPOS (it
.current
.pos
))
14812 int y0
= line_bottom_y (&it
);
14813 /* Compute how many pixels below window bottom to stop searching
14814 for PT. This avoids costly search for PT that is far away if
14815 the user limited scrolling by a small number of lines, but
14816 always finds PT if scroll_conservatively is set to a large
14817 number, such as most-positive-fixnum. */
14818 int slack
= max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
));
14819 int y_to_move
= it
.last_visible_y
+ slack
;
14821 /* Compute the distance from the scroll margin to PT or to
14822 the scroll limit, whichever comes first. This should
14823 include the height of the cursor line, to make that line
14825 move_it_to (&it
, PT
, -1, y_to_move
,
14826 -1, MOVE_TO_POS
| MOVE_TO_Y
);
14827 dy
= line_bottom_y (&it
) - y0
;
14829 if (dy
> scroll_max
)
14830 return SCROLLING_FAILED
;
14839 /* Point is in or below the bottom scroll margin, so move the
14840 window start down. If scrolling conservatively, move it just
14841 enough down to make point visible. If scroll_step is set,
14842 move it down by scroll_step. */
14843 if (arg_scroll_conservatively
)
14845 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
14846 FRAME_LINE_HEIGHT (f
) * arg_scroll_conservatively
);
14847 else if (scroll_step
|| temp_scroll_step
)
14848 amount_to_scroll
= scroll_max
;
14851 aggressive
= BVAR (current_buffer
, scroll_up_aggressively
);
14852 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14853 if (NUMBERP (aggressive
))
14855 double float_amount
= XFLOATINT (aggressive
) * height
;
14856 int aggressive_scroll
= float_amount
;
14857 if (aggressive_scroll
== 0 && float_amount
> 0)
14858 aggressive_scroll
= 1;
14859 /* Don't let point enter the scroll margin near top of
14860 the window. This could happen if the value of
14861 scroll_up_aggressively is too large and there are
14862 non-zero margins, because scroll_up_aggressively
14863 means put point that fraction of window height
14864 _from_the_bottom_margin_. */
14865 if (aggressive_scroll
+ 2*this_scroll_margin
> height
)
14866 aggressive_scroll
= height
- 2*this_scroll_margin
;
14867 amount_to_scroll
= dy
+ aggressive_scroll
;
14871 if (amount_to_scroll
<= 0)
14872 return SCROLLING_FAILED
;
14874 start_display (&it
, w
, startp
);
14875 if (arg_scroll_conservatively
<= scroll_limit
)
14876 move_it_vertically (&it
, amount_to_scroll
);
14879 /* Extra precision for users who set scroll-conservatively
14880 to a large number: make sure the amount we scroll
14881 the window start is never less than amount_to_scroll,
14882 which was computed as distance from window bottom to
14883 point. This matters when lines at window top and lines
14884 below window bottom have different height. */
14886 void *it1data
= NULL
;
14887 /* We use a temporary it1 because line_bottom_y can modify
14888 its argument, if it moves one line down; see there. */
14891 SAVE_IT (it1
, it
, it1data
);
14892 start_y
= line_bottom_y (&it1
);
14894 RESTORE_IT (&it
, &it
, it1data
);
14895 move_it_by_lines (&it
, 1);
14896 SAVE_IT (it1
, it
, it1data
);
14897 } while (line_bottom_y (&it1
) - start_y
< amount_to_scroll
);
14900 /* If STARTP is unchanged, move it down another screen line. */
14901 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
14902 move_it_by_lines (&it
, 1);
14903 startp
= it
.current
.pos
;
14907 struct text_pos scroll_margin_pos
= startp
;
14909 /* See if point is inside the scroll margin at the top of the
14911 if (this_scroll_margin
)
14913 start_display (&it
, w
, startp
);
14914 move_it_vertically (&it
, this_scroll_margin
);
14915 scroll_margin_pos
= it
.current
.pos
;
14918 if (PT
< CHARPOS (scroll_margin_pos
))
14920 /* Point is in the scroll margin at the top of the window or
14921 above what is displayed in the window. */
14924 /* Compute the vertical distance from PT to the scroll
14925 margin position. Move as far as scroll_max allows, or
14926 one screenful, or 10 screen lines, whichever is largest.
14927 Give up if distance is greater than scroll_max or if we
14928 didn't reach the scroll margin position. */
14929 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
14930 start_display (&it
, w
, pos
);
14932 y_to_move
= max (it
.last_visible_y
,
14933 max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
)));
14934 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
14936 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
14937 dy
= it
.current_y
- y0
;
14938 if (dy
> scroll_max
14939 || IT_CHARPOS (it
) < CHARPOS (scroll_margin_pos
))
14940 return SCROLLING_FAILED
;
14942 /* Compute new window start. */
14943 start_display (&it
, w
, startp
);
14945 if (arg_scroll_conservatively
)
14946 amount_to_scroll
= max (dy
, FRAME_LINE_HEIGHT (f
) *
14947 max (scroll_step
, temp_scroll_step
));
14948 else if (scroll_step
|| temp_scroll_step
)
14949 amount_to_scroll
= scroll_max
;
14952 aggressive
= BVAR (current_buffer
, scroll_down_aggressively
);
14953 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14954 if (NUMBERP (aggressive
))
14956 double float_amount
= XFLOATINT (aggressive
) * height
;
14957 int aggressive_scroll
= float_amount
;
14958 if (aggressive_scroll
== 0 && float_amount
> 0)
14959 aggressive_scroll
= 1;
14960 /* Don't let point enter the scroll margin near
14961 bottom of the window, if the value of
14962 scroll_down_aggressively happens to be too
14964 if (aggressive_scroll
+ 2*this_scroll_margin
> height
)
14965 aggressive_scroll
= height
- 2*this_scroll_margin
;
14966 amount_to_scroll
= dy
+ aggressive_scroll
;
14970 if (amount_to_scroll
<= 0)
14971 return SCROLLING_FAILED
;
14973 move_it_vertically_backward (&it
, amount_to_scroll
);
14974 startp
= it
.current
.pos
;
14978 /* Run window scroll functions. */
14979 startp
= run_window_scroll_functions (window
, startp
);
14981 /* Display the window. Give up if new fonts are loaded, or if point
14983 if (!try_window (window
, startp
, 0))
14984 rc
= SCROLLING_NEED_LARGER_MATRICES
;
14985 else if (w
->cursor
.vpos
< 0)
14987 clear_glyph_matrix (w
->desired_matrix
);
14988 rc
= SCROLLING_FAILED
;
14992 /* Maybe forget recorded base line for line number display. */
14993 if (!just_this_one_p
14994 || current_buffer
->clip_changed
14995 || BEG_UNCHANGED
< CHARPOS (startp
))
14996 wset_base_line_number (w
, Qnil
);
14998 /* If cursor ends up on a partially visible line,
14999 treat that as being off the bottom of the screen. */
15000 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0)
15001 /* It's possible that the cursor is on the first line of the
15002 buffer, which is partially obscured due to a vscroll
15003 (Bug#7537). In that case, avoid looping forever . */
15004 && extra_scroll_margin_lines
< w
->desired_matrix
->nrows
- 1)
15006 clear_glyph_matrix (w
->desired_matrix
);
15007 ++extra_scroll_margin_lines
;
15010 rc
= SCROLLING_SUCCESS
;
15017 /* Compute a suitable window start for window W if display of W starts
15018 on a continuation line. Value is non-zero if a new window start
15021 The new window start will be computed, based on W's width, starting
15022 from the start of the continued line. It is the start of the
15023 screen line with the minimum distance from the old start W->start. */
15026 compute_window_start_on_continuation_line (struct window
*w
)
15028 struct text_pos pos
, start_pos
;
15029 int window_start_changed_p
= 0;
15031 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
15033 /* If window start is on a continuation line... Window start may be
15034 < BEGV in case there's invisible text at the start of the
15035 buffer (M-x rmail, for example). */
15036 if (CHARPOS (start_pos
) > BEGV
15037 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
15040 struct glyph_row
*row
;
15042 /* Handle the case that the window start is out of range. */
15043 if (CHARPOS (start_pos
) < BEGV
)
15044 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
15045 else if (CHARPOS (start_pos
) > ZV
)
15046 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
15048 /* Find the start of the continued line. This should be fast
15049 because scan_buffer is fast (newline cache). */
15050 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
15051 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
15052 row
, DEFAULT_FACE_ID
);
15053 reseat_at_previous_visible_line_start (&it
);
15055 /* If the line start is "too far" away from the window start,
15056 say it takes too much time to compute a new window start. */
15057 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
15058 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
15060 int min_distance
, distance
;
15062 /* Move forward by display lines to find the new window
15063 start. If window width was enlarged, the new start can
15064 be expected to be > the old start. If window width was
15065 decreased, the new window start will be < the old start.
15066 So, we're looking for the display line start with the
15067 minimum distance from the old window start. */
15068 pos
= it
.current
.pos
;
15069 min_distance
= INFINITY
;
15070 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
15071 distance
< min_distance
)
15073 min_distance
= distance
;
15074 pos
= it
.current
.pos
;
15075 move_it_by_lines (&it
, 1);
15078 /* Set the window start there. */
15079 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
15080 window_start_changed_p
= 1;
15084 return window_start_changed_p
;
15088 /* Try cursor movement in case text has not changed in window WINDOW,
15089 with window start STARTP. Value is
15091 CURSOR_MOVEMENT_SUCCESS if successful
15093 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
15095 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
15096 display. *SCROLL_STEP is set to 1, under certain circumstances, if
15097 we want to scroll as if scroll-step were set to 1. See the code.
15099 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
15100 which case we have to abort this redisplay, and adjust matrices
15105 CURSOR_MOVEMENT_SUCCESS
,
15106 CURSOR_MOVEMENT_CANNOT_BE_USED
,
15107 CURSOR_MOVEMENT_MUST_SCROLL
,
15108 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
15112 try_cursor_movement (Lisp_Object window
, struct text_pos startp
, int *scroll_step
)
15114 struct window
*w
= XWINDOW (window
);
15115 struct frame
*f
= XFRAME (w
->frame
);
15116 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
15119 if (inhibit_try_cursor_movement
)
15123 /* Previously, there was a check for Lisp integer in the
15124 if-statement below. Now, this field is converted to
15125 ptrdiff_t, thus zero means invalid position in a buffer. */
15126 eassert (w
->last_point
> 0);
15128 /* Handle case where text has not changed, only point, and it has
15129 not moved off the frame. */
15130 if (/* Point may be in this window. */
15131 PT
>= CHARPOS (startp
)
15132 /* Selective display hasn't changed. */
15133 && !current_buffer
->clip_changed
15134 /* Function force-mode-line-update is used to force a thorough
15135 redisplay. It sets either windows_or_buffers_changed or
15136 update_mode_lines. So don't take a shortcut here for these
15138 && !update_mode_lines
15139 && !windows_or_buffers_changed
15140 && !cursor_type_changed
15141 /* Can't use this case if highlighting a region. When a
15142 region exists, cursor movement has to do more than just
15144 && !(!NILP (Vtransient_mark_mode
)
15145 && !NILP (BVAR (current_buffer
, mark_active
)))
15146 && NILP (w
->region_showing
)
15147 && NILP (Vshow_trailing_whitespace
)
15148 /* This code is not used for mini-buffer for the sake of the case
15149 of redisplaying to replace an echo area message; since in
15150 that case the mini-buffer contents per se are usually
15151 unchanged. This code is of no real use in the mini-buffer
15152 since the handling of this_line_start_pos, etc., in redisplay
15153 handles the same cases. */
15154 && !EQ (window
, minibuf_window
)
15155 /* When splitting windows or for new windows, it happens that
15156 redisplay is called with a nil window_end_vpos or one being
15157 larger than the window. This should really be fixed in
15158 window.c. I don't have this on my list, now, so we do
15159 approximately the same as the old redisplay code. --gerd. */
15160 && INTEGERP (w
->window_end_vpos
)
15161 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
15162 && (FRAME_WINDOW_P (f
)
15163 || !overlay_arrow_in_current_buffer_p ()))
15165 int this_scroll_margin
, top_scroll_margin
;
15166 struct glyph_row
*row
= NULL
;
15169 debug_method_add (w
, "cursor movement");
15172 /* Scroll if point within this distance from the top or bottom
15173 of the window. This is a pixel value. */
15174 if (scroll_margin
> 0)
15176 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
15177 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
15180 this_scroll_margin
= 0;
15182 top_scroll_margin
= this_scroll_margin
;
15183 if (WINDOW_WANTS_HEADER_LINE_P (w
))
15184 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
15186 /* Start with the row the cursor was displayed during the last
15187 not paused redisplay. Give up if that row is not valid. */
15188 if (w
->last_cursor
.vpos
< 0
15189 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
15190 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15193 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
15194 if (row
->mode_line_p
)
15196 if (!row
->enabled_p
)
15197 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15200 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
15202 int scroll_p
= 0, must_scroll
= 0;
15203 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
15205 if (PT
> w
->last_point
)
15207 /* Point has moved forward. */
15208 while (MATRIX_ROW_END_CHARPOS (row
) < PT
15209 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
15211 eassert (row
->enabled_p
);
15215 /* If the end position of a row equals the start
15216 position of the next row, and PT is at that position,
15217 we would rather display cursor in the next line. */
15218 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15219 && MATRIX_ROW_END_CHARPOS (row
) == PT
15220 && row
< w
->current_matrix
->rows
15221 + w
->current_matrix
->nrows
- 1
15222 && MATRIX_ROW_START_CHARPOS (row
+1) == PT
15223 && !cursor_row_p (row
))
15226 /* If within the scroll margin, scroll. Note that
15227 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
15228 the next line would be drawn, and that
15229 this_scroll_margin can be zero. */
15230 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
15231 || PT
> MATRIX_ROW_END_CHARPOS (row
)
15232 /* Line is completely visible last line in window
15233 and PT is to be set in the next line. */
15234 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
15235 && PT
== MATRIX_ROW_END_CHARPOS (row
)
15236 && !row
->ends_at_zv_p
15237 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
15240 else if (PT
< w
->last_point
)
15242 /* Cursor has to be moved backward. Note that PT >=
15243 CHARPOS (startp) because of the outer if-statement. */
15244 while (!row
->mode_line_p
15245 && (MATRIX_ROW_START_CHARPOS (row
) > PT
15246 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15247 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
15248 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
15249 row
> w
->current_matrix
->rows
15250 && (row
-1)->ends_in_newline_from_string_p
))))
15251 && (row
->y
> top_scroll_margin
15252 || CHARPOS (startp
) == BEGV
))
15254 eassert (row
->enabled_p
);
15258 /* Consider the following case: Window starts at BEGV,
15259 there is invisible, intangible text at BEGV, so that
15260 display starts at some point START > BEGV. It can
15261 happen that we are called with PT somewhere between
15262 BEGV and START. Try to handle that case. */
15263 if (row
< w
->current_matrix
->rows
15264 || row
->mode_line_p
)
15266 row
= w
->current_matrix
->rows
;
15267 if (row
->mode_line_p
)
15271 /* Due to newlines in overlay strings, we may have to
15272 skip forward over overlay strings. */
15273 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15274 && MATRIX_ROW_END_CHARPOS (row
) == PT
15275 && !cursor_row_p (row
))
15278 /* If within the scroll margin, scroll. */
15279 if (row
->y
< top_scroll_margin
15280 && CHARPOS (startp
) != BEGV
)
15285 /* Cursor did not move. So don't scroll even if cursor line
15286 is partially visible, as it was so before. */
15287 rc
= CURSOR_MOVEMENT_SUCCESS
;
15290 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
15291 || PT
> MATRIX_ROW_END_CHARPOS (row
))
15293 /* if PT is not in the glyph row, give up. */
15294 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15297 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15298 && !NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
15300 struct glyph_row
*row1
;
15302 /* If rows are bidi-reordered and point moved, back up
15303 until we find a row that does not belong to a
15304 continuation line. This is because we must consider
15305 all rows of a continued line as candidates for the
15306 new cursor positioning, since row start and end
15307 positions change non-linearly with vertical position
15309 /* FIXME: Revisit this when glyph ``spilling'' in
15310 continuation lines' rows is implemented for
15311 bidi-reordered rows. */
15312 for (row1
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15313 MATRIX_ROW_CONTINUATION_LINE_P (row
);
15316 /* If we hit the beginning of the displayed portion
15317 without finding the first row of a continued
15321 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15324 eassert (row
->enabled_p
);
15329 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15330 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
15331 /* Make sure this isn't a header line by any chance, since
15332 then MATRIX_ROW_PARTIALLY_VISIBLE_P might yield non-zero. */
15333 && !row
->mode_line_p
15334 && make_cursor_line_fully_visible_p
)
15336 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
15337 && !row
->ends_at_zv_p
15338 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15339 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15340 else if (row
->height
> window_box_height (w
))
15342 /* If we end up in a partially visible line, let's
15343 make it fully visible, except when it's taller
15344 than the window, in which case we can't do much
15347 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15351 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15352 if (!cursor_row_fully_visible_p (w
, 0, 1))
15353 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15355 rc
= CURSOR_MOVEMENT_SUCCESS
;
15359 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15360 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15361 && !NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
15363 /* With bidi-reordered rows, there could be more than
15364 one candidate row whose start and end positions
15365 occlude point. We need to let set_cursor_from_row
15366 find the best candidate. */
15367 /* FIXME: Revisit this when glyph ``spilling'' in
15368 continuation lines' rows is implemented for
15369 bidi-reordered rows. */
15374 int at_zv_p
= 0, exact_match_p
= 0;
15376 if (MATRIX_ROW_START_CHARPOS (row
) <= PT
15377 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
15378 && cursor_row_p (row
))
15379 rv
|= set_cursor_from_row (w
, row
, w
->current_matrix
,
15381 /* As soon as we've found the exact match for point,
15382 or the first suitable row whose ends_at_zv_p flag
15383 is set, we are done. */
15385 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
)->ends_at_zv_p
;
15387 && w
->cursor
.hpos
>= 0
15388 && w
->cursor
.hpos
< MATRIX_ROW_USED (w
->current_matrix
,
15391 struct glyph_row
*candidate
=
15392 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
15394 candidate
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
15395 ptrdiff_t endpos
= MATRIX_ROW_END_CHARPOS (candidate
);
15398 (BUFFERP (g
->object
) && g
->charpos
== PT
)
15399 || (INTEGERP (g
->object
)
15400 && (g
->charpos
== PT
15401 || (g
->charpos
== 0 && endpos
- 1 == PT
)));
15403 if (rv
&& (at_zv_p
|| exact_match_p
))
15405 rc
= CURSOR_MOVEMENT_SUCCESS
;
15408 if (MATRIX_ROW_BOTTOM_Y (row
) == last_y
)
15412 while (((MATRIX_ROW_CONTINUATION_LINE_P (row
)
15413 || row
->continued_p
)
15414 && MATRIX_ROW_BOTTOM_Y (row
) <= last_y
)
15415 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15416 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
));
15417 /* If we didn't find any candidate rows, or exited the
15418 loop before all the candidates were examined, signal
15419 to the caller that this method failed. */
15420 if (rc
!= CURSOR_MOVEMENT_SUCCESS
15422 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
15423 && !row
->continued_p
))
15424 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15426 rc
= CURSOR_MOVEMENT_SUCCESS
;
15432 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
15434 rc
= CURSOR_MOVEMENT_SUCCESS
;
15439 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15440 && MATRIX_ROW_START_CHARPOS (row
) == PT
15441 && cursor_row_p (row
));
15449 #if !defined USE_TOOLKIT_SCROLL_BARS || defined USE_GTK
15453 set_vertical_scroll_bar (struct window
*w
)
15455 ptrdiff_t start
, end
, whole
;
15457 /* Calculate the start and end positions for the current window.
15458 At some point, it would be nice to choose between scrollbars
15459 which reflect the whole buffer size, with special markers
15460 indicating narrowing, and scrollbars which reflect only the
15463 Note that mini-buffers sometimes aren't displaying any text. */
15464 if (!MINI_WINDOW_P (w
)
15465 || (w
== XWINDOW (minibuf_window
)
15466 && NILP (echo_area_buffer
[0])))
15468 struct buffer
*buf
= XBUFFER (w
->buffer
);
15469 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
15470 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
15471 /* I don't think this is guaranteed to be right. For the
15472 moment, we'll pretend it is. */
15473 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
15477 if (whole
< (end
- start
))
15478 whole
= end
- start
;
15481 start
= end
= whole
= 0;
15483 /* Indicate what this scroll bar ought to be displaying now. */
15484 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15485 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15486 (w
, end
- start
, whole
, start
);
15490 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
15491 selected_window is redisplayed.
15493 We can return without actually redisplaying the window if
15494 fonts_changed_p. In that case, redisplay_internal will
15498 redisplay_window (Lisp_Object window
, int just_this_one_p
)
15500 struct window
*w
= XWINDOW (window
);
15501 struct frame
*f
= XFRAME (w
->frame
);
15502 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15503 struct buffer
*old
= current_buffer
;
15504 struct text_pos lpoint
, opoint
, startp
;
15505 int update_mode_line
;
15508 /* Record it now because it's overwritten. */
15509 int current_matrix_up_to_date_p
= 0;
15510 int used_current_matrix_p
= 0;
15511 /* This is less strict than current_matrix_up_to_date_p.
15512 It indicates that the buffer contents and narrowing are unchanged. */
15513 int buffer_unchanged_p
= 0;
15514 int temp_scroll_step
= 0;
15515 ptrdiff_t count
= SPECPDL_INDEX ();
15517 int centering_position
= -1;
15518 int last_line_misfit
= 0;
15519 ptrdiff_t beg_unchanged
, end_unchanged
;
15521 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15524 /* W must be a leaf window here. */
15525 eassert (!NILP (w
->buffer
));
15527 *w
->desired_matrix
->method
= 0;
15531 reconsider_clip_changes (w
, buffer
);
15533 /* Has the mode line to be updated? */
15534 update_mode_line
= (w
->update_mode_line
15535 || update_mode_lines
15536 || buffer
->clip_changed
15537 || buffer
->prevent_redisplay_optimizations_p
);
15539 if (MINI_WINDOW_P (w
))
15541 if (w
== XWINDOW (echo_area_window
)
15542 && !NILP (echo_area_buffer
[0]))
15544 if (update_mode_line
)
15545 /* We may have to update a tty frame's menu bar or a
15546 tool-bar. Example `M-x C-h C-h C-g'. */
15547 goto finish_menu_bars
;
15549 /* We've already displayed the echo area glyphs in this window. */
15550 goto finish_scroll_bars
;
15552 else if ((w
!= XWINDOW (minibuf_window
)
15553 || minibuf_level
== 0)
15554 /* When buffer is nonempty, redisplay window normally. */
15555 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
15556 /* Quail displays non-mini buffers in minibuffer window.
15557 In that case, redisplay the window normally. */
15558 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
15560 /* W is a mini-buffer window, but it's not active, so clear
15562 int yb
= window_text_bottom_y (w
);
15563 struct glyph_row
*row
;
15566 for (y
= 0, row
= w
->desired_matrix
->rows
;
15568 y
+= row
->height
, ++row
)
15569 blank_row (w
, row
, y
);
15570 goto finish_scroll_bars
;
15573 clear_glyph_matrix (w
->desired_matrix
);
15576 /* Otherwise set up data on this window; select its buffer and point
15578 /* Really select the buffer, for the sake of buffer-local
15580 set_buffer_internal_1 (XBUFFER (w
->buffer
));
15582 current_matrix_up_to_date_p
15583 = (!NILP (w
->window_end_valid
)
15584 && !current_buffer
->clip_changed
15585 && !current_buffer
->prevent_redisplay_optimizations_p
15586 && !window_outdated (w
));
15588 /* Run the window-bottom-change-functions
15589 if it is possible that the text on the screen has changed
15590 (either due to modification of the text, or any other reason). */
15591 if (!current_matrix_up_to_date_p
15592 && !NILP (Vwindow_text_change_functions
))
15594 safe_run_hooks (Qwindow_text_change_functions
);
15598 beg_unchanged
= BEG_UNCHANGED
;
15599 end_unchanged
= END_UNCHANGED
;
15601 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
15603 specbind (Qinhibit_point_motion_hooks
, Qt
);
15606 = (!NILP (w
->window_end_valid
)
15607 && !current_buffer
->clip_changed
15608 && !window_outdated (w
));
15610 /* When windows_or_buffers_changed is non-zero, we can't rely on
15611 the window end being valid, so set it to nil there. */
15612 if (windows_or_buffers_changed
)
15614 /* If window starts on a continuation line, maybe adjust the
15615 window start in case the window's width changed. */
15616 if (XMARKER (w
->start
)->buffer
== current_buffer
)
15617 compute_window_start_on_continuation_line (w
);
15619 wset_window_end_valid (w
, Qnil
);
15622 /* Some sanity checks. */
15623 CHECK_WINDOW_END (w
);
15624 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
15626 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
15629 /* If %c is in mode line, update it if needed. */
15630 if (!NILP (w
->column_number_displayed
)
15631 /* This alternative quickly identifies a common case
15632 where no change is needed. */
15633 && !(PT
== w
->last_point
&& !window_outdated (w
))
15634 && (XFASTINT (w
->column_number_displayed
) != current_column ()))
15635 update_mode_line
= 1;
15637 /* Count number of windows showing the selected buffer. An indirect
15638 buffer counts as its base buffer. */
15639 if (!just_this_one_p
)
15641 struct buffer
*current_base
, *window_base
;
15642 current_base
= current_buffer
;
15643 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
15644 if (current_base
->base_buffer
)
15645 current_base
= current_base
->base_buffer
;
15646 if (window_base
->base_buffer
)
15647 window_base
= window_base
->base_buffer
;
15648 if (current_base
== window_base
)
15652 /* Point refers normally to the selected window. For any other
15653 window, set up appropriate value. */
15654 if (!EQ (window
, selected_window
))
15656 ptrdiff_t new_pt
= XMARKER (w
->pointm
)->charpos
;
15657 ptrdiff_t new_pt_byte
= marker_byte_position (w
->pointm
);
15661 new_pt_byte
= BEGV_BYTE
;
15662 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
15664 else if (new_pt
> (ZV
- 1))
15667 new_pt_byte
= ZV_BYTE
;
15668 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
15671 /* We don't use SET_PT so that the point-motion hooks don't run. */
15672 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
15675 /* If any of the character widths specified in the display table
15676 have changed, invalidate the width run cache. It's true that
15677 this may be a bit late to catch such changes, but the rest of
15678 redisplay goes (non-fatally) haywire when the display table is
15679 changed, so why should we worry about doing any better? */
15680 if (current_buffer
->width_run_cache
)
15682 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
15684 if (! disptab_matches_widthtab
15685 (disptab
, XVECTOR (BVAR (current_buffer
, width_table
))))
15687 invalidate_region_cache (current_buffer
,
15688 current_buffer
->width_run_cache
,
15690 recompute_width_table (current_buffer
, disptab
);
15694 /* If window-start is screwed up, choose a new one. */
15695 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
15698 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15700 /* If someone specified a new starting point but did not insist,
15701 check whether it can be used. */
15702 if (w
->optional_new_start
15703 && CHARPOS (startp
) >= BEGV
15704 && CHARPOS (startp
) <= ZV
)
15706 w
->optional_new_start
= 0;
15707 start_display (&it
, w
, startp
);
15708 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
15709 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15710 if (IT_CHARPOS (it
) == PT
)
15711 w
->force_start
= 1;
15712 /* IT may overshoot PT if text at PT is invisible. */
15713 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
15714 w
->force_start
= 1;
15719 /* Handle case where place to start displaying has been specified,
15720 unless the specified location is outside the accessible range. */
15721 if (w
->force_start
|| w
->frozen_window_start_p
)
15723 /* We set this later on if we have to adjust point. */
15726 w
->force_start
= 0;
15728 wset_window_end_valid (w
, Qnil
);
15730 /* Forget any recorded base line for line number display. */
15731 if (!buffer_unchanged_p
)
15732 wset_base_line_number (w
, Qnil
);
15734 /* Redisplay the mode line. Select the buffer properly for that.
15735 Also, run the hook window-scroll-functions
15736 because we have scrolled. */
15737 /* Note, we do this after clearing force_start because
15738 if there's an error, it is better to forget about force_start
15739 than to get into an infinite loop calling the hook functions
15740 and having them get more errors. */
15741 if (!update_mode_line
15742 || ! NILP (Vwindow_scroll_functions
))
15744 update_mode_line
= 1;
15745 w
->update_mode_line
= 1;
15746 startp
= run_window_scroll_functions (window
, startp
);
15749 w
->last_modified
= 0;
15750 w
->last_overlay_modified
= 0;
15751 if (CHARPOS (startp
) < BEGV
)
15752 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
15753 else if (CHARPOS (startp
) > ZV
)
15754 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
15756 /* Redisplay, then check if cursor has been set during the
15757 redisplay. Give up if new fonts were loaded. */
15758 /* We used to issue a CHECK_MARGINS argument to try_window here,
15759 but this causes scrolling to fail when point begins inside
15760 the scroll margin (bug#148) -- cyd */
15761 if (!try_window (window
, startp
, 0))
15763 w
->force_start
= 1;
15764 clear_glyph_matrix (w
->desired_matrix
);
15765 goto need_larger_matrices
;
15768 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
15770 /* If point does not appear, try to move point so it does
15771 appear. The desired matrix has been built above, so we
15772 can use it here. */
15773 new_vpos
= window_box_height (w
) / 2;
15776 if (!cursor_row_fully_visible_p (w
, 0, 0))
15778 /* Point does appear, but on a line partly visible at end of window.
15779 Move it back to a fully-visible line. */
15780 new_vpos
= window_box_height (w
);
15783 /* If we need to move point for either of the above reasons,
15784 now actually do it. */
15787 struct glyph_row
*row
;
15789 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
15790 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
15793 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
15794 MATRIX_ROW_START_BYTEPOS (row
));
15796 if (w
!= XWINDOW (selected_window
))
15797 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
15798 else if (current_buffer
== old
)
15799 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15801 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
15803 /* If we are highlighting the region, then we just changed
15804 the region, so redisplay to show it. */
15805 if (!NILP (Vtransient_mark_mode
)
15806 && !NILP (BVAR (current_buffer
, mark_active
)))
15808 clear_glyph_matrix (w
->desired_matrix
);
15809 if (!try_window (window
, startp
, 0))
15810 goto need_larger_matrices
;
15815 debug_method_add (w
, "forced window start");
15820 /* Handle case where text has not changed, only point, and it has
15821 not moved off the frame, and we are not retrying after hscroll.
15822 (current_matrix_up_to_date_p is nonzero when retrying.) */
15823 if (current_matrix_up_to_date_p
15824 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
15825 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
15829 case CURSOR_MOVEMENT_SUCCESS
:
15830 used_current_matrix_p
= 1;
15833 case CURSOR_MOVEMENT_MUST_SCROLL
:
15834 goto try_to_scroll
;
15840 /* If current starting point was originally the beginning of a line
15841 but no longer is, find a new starting point. */
15842 else if (w
->start_at_line_beg
15843 && !(CHARPOS (startp
) <= BEGV
15844 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
15847 debug_method_add (w
, "recenter 1");
15852 /* Try scrolling with try_window_id. Value is > 0 if update has
15853 been done, it is -1 if we know that the same window start will
15854 not work. It is 0 if unsuccessful for some other reason. */
15855 else if ((tem
= try_window_id (w
)) != 0)
15858 debug_method_add (w
, "try_window_id %d", tem
);
15861 if (fonts_changed_p
)
15862 goto need_larger_matrices
;
15866 /* Otherwise try_window_id has returned -1 which means that we
15867 don't want the alternative below this comment to execute. */
15869 else if (CHARPOS (startp
) >= BEGV
15870 && CHARPOS (startp
) <= ZV
15871 && PT
>= CHARPOS (startp
)
15872 && (CHARPOS (startp
) < ZV
15873 /* Avoid starting at end of buffer. */
15874 || CHARPOS (startp
) == BEGV
15875 || !window_outdated (w
)))
15877 int d1
, d2
, d3
, d4
, d5
, d6
;
15879 /* If first window line is a continuation line, and window start
15880 is inside the modified region, but the first change is before
15881 current window start, we must select a new window start.
15883 However, if this is the result of a down-mouse event (e.g. by
15884 extending the mouse-drag-overlay), we don't want to select a
15885 new window start, since that would change the position under
15886 the mouse, resulting in an unwanted mouse-movement rather
15887 than a simple mouse-click. */
15888 if (!w
->start_at_line_beg
15889 && NILP (do_mouse_tracking
)
15890 && CHARPOS (startp
) > BEGV
15891 && CHARPOS (startp
) > BEG
+ beg_unchanged
15892 && CHARPOS (startp
) <= Z
- end_unchanged
15893 /* Even if w->start_at_line_beg is nil, a new window may
15894 start at a line_beg, since that's how set_buffer_window
15895 sets it. So, we need to check the return value of
15896 compute_window_start_on_continuation_line. (See also
15898 && XMARKER (w
->start
)->buffer
== current_buffer
15899 && compute_window_start_on_continuation_line (w
)
15900 /* It doesn't make sense to force the window start like we
15901 do at label force_start if it is already known that point
15902 will not be visible in the resulting window, because
15903 doing so will move point from its correct position
15904 instead of scrolling the window to bring point into view.
15906 && pos_visible_p (w
, PT
, &d1
, &d2
, &d3
, &d4
, &d5
, &d6
))
15908 w
->force_start
= 1;
15909 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15914 debug_method_add (w
, "same window start");
15917 /* Try to redisplay starting at same place as before.
15918 If point has not moved off frame, accept the results. */
15919 if (!current_matrix_up_to_date_p
15920 /* Don't use try_window_reusing_current_matrix in this case
15921 because a window scroll function can have changed the
15923 || !NILP (Vwindow_scroll_functions
)
15924 || MINI_WINDOW_P (w
)
15925 || !(used_current_matrix_p
15926 = try_window_reusing_current_matrix (w
)))
15928 IF_DEBUG (debug_method_add (w
, "1"));
15929 if (try_window (window
, startp
, TRY_WINDOW_CHECK_MARGINS
) < 0)
15930 /* -1 means we need to scroll.
15931 0 means we need new matrices, but fonts_changed_p
15932 is set in that case, so we will detect it below. */
15933 goto try_to_scroll
;
15936 if (fonts_changed_p
)
15937 goto need_larger_matrices
;
15939 if (w
->cursor
.vpos
>= 0)
15941 if (!just_this_one_p
15942 || current_buffer
->clip_changed
15943 || BEG_UNCHANGED
< CHARPOS (startp
))
15944 /* Forget any recorded base line for line number display. */
15945 wset_base_line_number (w
, Qnil
);
15947 if (!cursor_row_fully_visible_p (w
, 1, 0))
15949 clear_glyph_matrix (w
->desired_matrix
);
15950 last_line_misfit
= 1;
15952 /* Drop through and scroll. */
15957 clear_glyph_matrix (w
->desired_matrix
);
15962 w
->last_modified
= 0;
15963 w
->last_overlay_modified
= 0;
15965 /* Redisplay the mode line. Select the buffer properly for that. */
15966 if (!update_mode_line
)
15968 update_mode_line
= 1;
15969 w
->update_mode_line
= 1;
15972 /* Try to scroll by specified few lines. */
15973 if ((scroll_conservatively
15974 || emacs_scroll_step
15975 || temp_scroll_step
15976 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
))
15977 || NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
)))
15978 && CHARPOS (startp
) >= BEGV
15979 && CHARPOS (startp
) <= ZV
)
15981 /* The function returns -1 if new fonts were loaded, 1 if
15982 successful, 0 if not successful. */
15983 int ss
= try_scrolling (window
, just_this_one_p
,
15984 scroll_conservatively
,
15986 temp_scroll_step
, last_line_misfit
);
15989 case SCROLLING_SUCCESS
:
15992 case SCROLLING_NEED_LARGER_MATRICES
:
15993 goto need_larger_matrices
;
15995 case SCROLLING_FAILED
:
16003 /* Finally, just choose a place to start which positions point
16004 according to user preferences. */
16009 debug_method_add (w
, "recenter");
16012 /* w->vscroll = 0; */
16014 /* Forget any previously recorded base line for line number display. */
16015 if (!buffer_unchanged_p
)
16016 wset_base_line_number (w
, Qnil
);
16018 /* Determine the window start relative to point. */
16019 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
16020 it
.current_y
= it
.last_visible_y
;
16021 if (centering_position
< 0)
16025 ? min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
16027 ptrdiff_t margin_pos
= CHARPOS (startp
);
16028 Lisp_Object aggressive
;
16031 /* If there is a scroll margin at the top of the window, find
16032 its character position. */
16034 /* Cannot call start_display if startp is not in the
16035 accessible region of the buffer. This can happen when we
16036 have just switched to a different buffer and/or changed
16037 its restriction. In that case, startp is initialized to
16038 the character position 1 (BEGV) because we did not yet
16039 have chance to display the buffer even once. */
16040 && BEGV
<= CHARPOS (startp
) && CHARPOS (startp
) <= ZV
)
16043 void *it1data
= NULL
;
16045 SAVE_IT (it1
, it
, it1data
);
16046 start_display (&it1
, w
, startp
);
16047 move_it_vertically (&it1
, margin
* FRAME_LINE_HEIGHT (f
));
16048 margin_pos
= IT_CHARPOS (it1
);
16049 RESTORE_IT (&it
, &it
, it1data
);
16051 scrolling_up
= PT
> margin_pos
;
16054 ? BVAR (current_buffer
, scroll_up_aggressively
)
16055 : BVAR (current_buffer
, scroll_down_aggressively
);
16057 if (!MINI_WINDOW_P (w
)
16058 && (scroll_conservatively
> SCROLL_LIMIT
|| NUMBERP (aggressive
)))
16062 /* Setting scroll-conservatively overrides
16063 scroll-*-aggressively. */
16064 if (!scroll_conservatively
&& NUMBERP (aggressive
))
16066 double float_amount
= XFLOATINT (aggressive
);
16068 pt_offset
= float_amount
* WINDOW_BOX_TEXT_HEIGHT (w
);
16069 if (pt_offset
== 0 && float_amount
> 0)
16071 if (pt_offset
&& margin
> 0)
16074 /* Compute how much to move the window start backward from
16075 point so that point will be displayed where the user
16079 centering_position
= it
.last_visible_y
;
16081 centering_position
-= pt_offset
;
16082 centering_position
-=
16083 FRAME_LINE_HEIGHT (f
) * (1 + margin
+ (last_line_misfit
!= 0))
16084 + WINDOW_HEADER_LINE_HEIGHT (w
);
16085 /* Don't let point enter the scroll margin near top of
16087 if (centering_position
< margin
* FRAME_LINE_HEIGHT (f
))
16088 centering_position
= margin
* FRAME_LINE_HEIGHT (f
);
16091 centering_position
= margin
* FRAME_LINE_HEIGHT (f
) + pt_offset
;
16094 /* Set the window start half the height of the window backward
16096 centering_position
= window_box_height (w
) / 2;
16098 move_it_vertically_backward (&it
, centering_position
);
16100 eassert (IT_CHARPOS (it
) >= BEGV
);
16102 /* The function move_it_vertically_backward may move over more
16103 than the specified y-distance. If it->w is small, e.g. a
16104 mini-buffer window, we may end up in front of the window's
16105 display area. Start displaying at the start of the line
16106 containing PT in this case. */
16107 if (it
.current_y
<= 0)
16109 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
16110 move_it_vertically_backward (&it
, 0);
16114 it
.current_x
= it
.hpos
= 0;
16116 /* Set the window start position here explicitly, to avoid an
16117 infinite loop in case the functions in window-scroll-functions
16119 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
16121 /* Run scroll hooks. */
16122 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
16124 /* Redisplay the window. */
16125 if (!current_matrix_up_to_date_p
16126 || windows_or_buffers_changed
16127 || cursor_type_changed
16128 /* Don't use try_window_reusing_current_matrix in this case
16129 because it can have changed the buffer. */
16130 || !NILP (Vwindow_scroll_functions
)
16131 || !just_this_one_p
16132 || MINI_WINDOW_P (w
)
16133 || !(used_current_matrix_p
16134 = try_window_reusing_current_matrix (w
)))
16135 try_window (window
, startp
, 0);
16137 /* If new fonts have been loaded (due to fontsets), give up. We
16138 have to start a new redisplay since we need to re-adjust glyph
16140 if (fonts_changed_p
)
16141 goto need_larger_matrices
;
16143 /* If cursor did not appear assume that the middle of the window is
16144 in the first line of the window. Do it again with the next line.
16145 (Imagine a window of height 100, displaying two lines of height
16146 60. Moving back 50 from it->last_visible_y will end in the first
16148 if (w
->cursor
.vpos
< 0)
16150 if (!NILP (w
->window_end_valid
)
16151 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
16153 clear_glyph_matrix (w
->desired_matrix
);
16154 move_it_by_lines (&it
, 1);
16155 try_window (window
, it
.current
.pos
, 0);
16157 else if (PT
< IT_CHARPOS (it
))
16159 clear_glyph_matrix (w
->desired_matrix
);
16160 move_it_by_lines (&it
, -1);
16161 try_window (window
, it
.current
.pos
, 0);
16165 /* Not much we can do about it. */
16169 /* Consider the following case: Window starts at BEGV, there is
16170 invisible, intangible text at BEGV, so that display starts at
16171 some point START > BEGV. It can happen that we are called with
16172 PT somewhere between BEGV and START. Try to handle that case. */
16173 if (w
->cursor
.vpos
< 0)
16175 struct glyph_row
*row
= w
->current_matrix
->rows
;
16176 if (row
->mode_line_p
)
16178 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
16181 if (!cursor_row_fully_visible_p (w
, 0, 0))
16183 /* If vscroll is enabled, disable it and try again. */
16187 clear_glyph_matrix (w
->desired_matrix
);
16191 /* Users who set scroll-conservatively to a large number want
16192 point just above/below the scroll margin. If we ended up
16193 with point's row partially visible, move the window start to
16194 make that row fully visible and out of the margin. */
16195 if (scroll_conservatively
> SCROLL_LIMIT
)
16199 ? min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
16201 int move_down
= w
->cursor
.vpos
>= WINDOW_TOTAL_LINES (w
) / 2;
16203 move_it_by_lines (&it
, move_down
? margin
+ 1 : -(margin
+ 1));
16204 clear_glyph_matrix (w
->desired_matrix
);
16205 if (1 == try_window (window
, it
.current
.pos
,
16206 TRY_WINDOW_CHECK_MARGINS
))
16210 /* If centering point failed to make the whole line visible,
16211 put point at the top instead. That has to make the whole line
16212 visible, if it can be done. */
16213 if (centering_position
== 0)
16216 clear_glyph_matrix (w
->desired_matrix
);
16217 centering_position
= 0;
16223 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
16224 w
->start_at_line_beg
= (CHARPOS (startp
) == BEGV
16225 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n');
16227 /* Display the mode line, if we must. */
16228 if ((update_mode_line
16229 /* If window not full width, must redo its mode line
16230 if (a) the window to its side is being redone and
16231 (b) we do a frame-based redisplay. This is a consequence
16232 of how inverted lines are drawn in frame-based redisplay. */
16233 || (!just_this_one_p
16234 && !FRAME_WINDOW_P (f
)
16235 && !WINDOW_FULL_WIDTH_P (w
))
16236 /* Line number to display. */
16237 || INTEGERP (w
->base_line_pos
)
16238 /* Column number is displayed and different from the one displayed. */
16239 || (!NILP (w
->column_number_displayed
)
16240 && (XFASTINT (w
->column_number_displayed
) != current_column ())))
16241 /* This means that the window has a mode line. */
16242 && (WINDOW_WANTS_MODELINE_P (w
)
16243 || WINDOW_WANTS_HEADER_LINE_P (w
)))
16245 display_mode_lines (w
);
16247 /* If mode line height has changed, arrange for a thorough
16248 immediate redisplay using the correct mode line height. */
16249 if (WINDOW_WANTS_MODELINE_P (w
)
16250 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
16252 fonts_changed_p
= 1;
16253 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
16254 = DESIRED_MODE_LINE_HEIGHT (w
);
16257 /* If header line height has changed, arrange for a thorough
16258 immediate redisplay using the correct header line height. */
16259 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16260 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
16262 fonts_changed_p
= 1;
16263 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
16264 = DESIRED_HEADER_LINE_HEIGHT (w
);
16267 if (fonts_changed_p
)
16268 goto need_larger_matrices
;
16271 if (!line_number_displayed
16272 && !BUFFERP (w
->base_line_pos
))
16274 wset_base_line_pos (w
, Qnil
);
16275 wset_base_line_number (w
, Qnil
);
16280 /* When we reach a frame's selected window, redo the frame's menu bar. */
16281 if (update_mode_line
16282 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
16284 int redisplay_menu_p
= 0;
16286 if (FRAME_WINDOW_P (f
))
16288 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
16289 || defined (HAVE_NS) || defined (USE_GTK)
16290 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
16292 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16296 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16298 if (redisplay_menu_p
)
16299 display_menu_bar (w
);
16301 #ifdef HAVE_WINDOW_SYSTEM
16302 if (FRAME_WINDOW_P (f
))
16304 #if defined (USE_GTK) || defined (HAVE_NS)
16305 if (FRAME_EXTERNAL_TOOL_BAR (f
))
16306 redisplay_tool_bar (f
);
16308 if (WINDOWP (f
->tool_bar_window
)
16309 && (FRAME_TOOL_BAR_LINES (f
) > 0
16310 || !NILP (Vauto_resize_tool_bars
))
16311 && redisplay_tool_bar (f
))
16312 ignore_mouse_drag_p
= 1;
16318 #ifdef HAVE_WINDOW_SYSTEM
16319 if (FRAME_WINDOW_P (f
)
16320 && update_window_fringes (w
, (just_this_one_p
16321 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
16322 || w
->pseudo_window_p
)))
16326 if (draw_window_fringes (w
, 1))
16327 x_draw_vertical_border (w
);
16331 #endif /* HAVE_WINDOW_SYSTEM */
16333 /* We go to this label, with fonts_changed_p set,
16334 if it is necessary to try again using larger glyph matrices.
16335 We have to redeem the scroll bar even in this case,
16336 because the loop in redisplay_internal expects that. */
16337 need_larger_matrices
:
16339 finish_scroll_bars
:
16341 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
16343 /* Set the thumb's position and size. */
16344 set_vertical_scroll_bar (w
);
16346 /* Note that we actually used the scroll bar attached to this
16347 window, so it shouldn't be deleted at the end of redisplay. */
16348 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
16349 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
16352 /* Restore current_buffer and value of point in it. The window
16353 update may have changed the buffer, so first make sure `opoint'
16354 is still valid (Bug#6177). */
16355 if (CHARPOS (opoint
) < BEGV
)
16356 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
16357 else if (CHARPOS (opoint
) > ZV
)
16358 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
16360 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
16362 set_buffer_internal_1 (old
);
16363 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
16364 shorter. This can be caused by log truncation in *Messages*. */
16365 if (CHARPOS (lpoint
) <= ZV
)
16366 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
16368 unbind_to (count
, Qnil
);
16372 /* Build the complete desired matrix of WINDOW with a window start
16373 buffer position POS.
16375 Value is 1 if successful. It is zero if fonts were loaded during
16376 redisplay which makes re-adjusting glyph matrices necessary, and -1
16377 if point would appear in the scroll margins.
16378 (We check the former only if TRY_WINDOW_IGNORE_FONTS_CHANGE is
16379 unset in FLAGS, and the latter only if TRY_WINDOW_CHECK_MARGINS is
16383 try_window (Lisp_Object window
, struct text_pos pos
, int flags
)
16385 struct window
*w
= XWINDOW (window
);
16387 struct glyph_row
*last_text_row
= NULL
;
16388 struct frame
*f
= XFRAME (w
->frame
);
16390 /* Make POS the new window start. */
16391 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
16393 /* Mark cursor position as unknown. No overlay arrow seen. */
16394 w
->cursor
.vpos
= -1;
16395 overlay_arrow_seen
= 0;
16397 /* Initialize iterator and info to start at POS. */
16398 start_display (&it
, w
, pos
);
16402 /* Display all lines of W. */
16403 while (it
.current_y
< it
.last_visible_y
)
16405 if (display_line (&it
))
16406 last_text_row
= it
.glyph_row
- 1;
16407 if (fonts_changed_p
&& !(flags
& TRY_WINDOW_IGNORE_FONTS_CHANGE
))
16410 #ifdef HAVE_XWIDGETS_xxx
16411 //currently this is needed to detect xwidget movement reliably. or probably not.
16412 printf("try_window\n");
16416 /* Don't let the cursor end in the scroll margins. */
16417 if ((flags
& TRY_WINDOW_CHECK_MARGINS
)
16418 && !MINI_WINDOW_P (w
))
16420 int this_scroll_margin
;
16422 if (scroll_margin
> 0)
16424 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
16425 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
16428 this_scroll_margin
= 0;
16430 if ((w
->cursor
.y
>= 0 /* not vscrolled */
16431 && w
->cursor
.y
< this_scroll_margin
16432 && CHARPOS (pos
) > BEGV
16433 && IT_CHARPOS (it
) < ZV
)
16434 /* rms: considering make_cursor_line_fully_visible_p here
16435 seems to give wrong results. We don't want to recenter
16436 when the last line is partly visible, we want to allow
16437 that case to be handled in the usual way. */
16438 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
16440 w
->cursor
.vpos
= -1;
16441 clear_glyph_matrix (w
->desired_matrix
);
16446 /* If bottom moved off end of frame, change mode line percentage. */
16447 if (XFASTINT (w
->window_end_pos
) <= 0
16448 && Z
!= IT_CHARPOS (it
))
16449 w
->update_mode_line
= 1;
16451 /* Set window_end_pos to the offset of the last character displayed
16452 on the window from the end of current_buffer. Set
16453 window_end_vpos to its row number. */
16456 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
16457 w
->window_end_bytepos
16458 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16459 wset_window_end_pos
16460 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
)));
16461 wset_window_end_vpos
16462 (w
, make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
)));
16464 (MATRIX_ROW (w
->desired_matrix
,
16465 XFASTINT (w
->window_end_vpos
))->displays_text_p
);
16469 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16470 wset_window_end_pos (w
, make_number (Z
- ZV
));
16471 wset_window_end_vpos (w
, make_number (0));
16474 /* But that is not valid info until redisplay finishes. */
16475 wset_window_end_valid (w
, Qnil
);
16481 /************************************************************************
16482 Window redisplay reusing current matrix when buffer has not changed
16483 ************************************************************************/
16485 /* Try redisplay of window W showing an unchanged buffer with a
16486 different window start than the last time it was displayed by
16487 reusing its current matrix. Value is non-zero if successful.
16488 W->start is the new window start. */
16491 try_window_reusing_current_matrix (struct window
*w
)
16493 struct frame
*f
= XFRAME (w
->frame
);
16494 struct glyph_row
*bottom_row
;
16497 struct text_pos start
, new_start
;
16498 int nrows_scrolled
, i
;
16499 struct glyph_row
*last_text_row
;
16500 struct glyph_row
*last_reused_text_row
;
16501 struct glyph_row
*start_row
;
16502 int start_vpos
, min_y
, max_y
;
16505 if (inhibit_try_window_reusing
)
16509 #ifdef HAVE_XWIDGETS_xxx
16510 //currently this is needed to detect xwidget movement reliably. or probably not.
16511 printf("try_window_reusing_current_matrix\n");
16516 if (/* This function doesn't handle terminal frames. */
16517 !FRAME_WINDOW_P (f
)
16518 /* Don't try to reuse the display if windows have been split
16520 || windows_or_buffers_changed
16521 || cursor_type_changed
)
16524 /* Can't do this if region may have changed. */
16525 if ((!NILP (Vtransient_mark_mode
)
16526 && !NILP (BVAR (current_buffer
, mark_active
)))
16527 || !NILP (w
->region_showing
)
16528 || !NILP (Vshow_trailing_whitespace
))
16531 /* If top-line visibility has changed, give up. */
16532 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16533 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
16536 /* Give up if old or new display is scrolled vertically. We could
16537 make this function handle this, but right now it doesn't. */
16538 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16539 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
16542 /* The variable new_start now holds the new window start. The old
16543 start `start' can be determined from the current matrix. */
16544 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
16545 start
= start_row
->minpos
;
16546 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16548 /* Clear the desired matrix for the display below. */
16549 clear_glyph_matrix (w
->desired_matrix
);
16551 if (CHARPOS (new_start
) <= CHARPOS (start
))
16553 /* Don't use this method if the display starts with an ellipsis
16554 displayed for invisible text. It's not easy to handle that case
16555 below, and it's certainly not worth the effort since this is
16556 not a frequent case. */
16557 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
16560 IF_DEBUG (debug_method_add (w
, "twu1"));
16562 /* Display up to a row that can be reused. The variable
16563 last_text_row is set to the last row displayed that displays
16564 text. Note that it.vpos == 0 if or if not there is a
16565 header-line; it's not the same as the MATRIX_ROW_VPOS! */
16566 start_display (&it
, w
, new_start
);
16567 w
->cursor
.vpos
= -1;
16568 last_text_row
= last_reused_text_row
= NULL
;
16570 while (it
.current_y
< it
.last_visible_y
16571 && !fonts_changed_p
)
16573 /* If we have reached into the characters in the START row,
16574 that means the line boundaries have changed. So we
16575 can't start copying with the row START. Maybe it will
16576 work to start copying with the following row. */
16577 while (IT_CHARPOS (it
) > CHARPOS (start
))
16579 /* Advance to the next row as the "start". */
16581 start
= start_row
->minpos
;
16582 /* If there are no more rows to try, or just one, give up. */
16583 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
16584 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
16585 || CHARPOS (start
) == ZV
)
16587 clear_glyph_matrix (w
->desired_matrix
);
16591 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16593 /* If we have reached alignment, we can copy the rest of the
16595 if (IT_CHARPOS (it
) == CHARPOS (start
)
16596 /* Don't accept "alignment" inside a display vector,
16597 since start_row could have started in the middle of
16598 that same display vector (thus their character
16599 positions match), and we have no way of telling if
16600 that is the case. */
16601 && it
.current
.dpvec_index
< 0)
16604 if (display_line (&it
))
16605 last_text_row
= it
.glyph_row
- 1;
16609 /* A value of current_y < last_visible_y means that we stopped
16610 at the previous window start, which in turn means that we
16611 have at least one reusable row. */
16612 if (it
.current_y
< it
.last_visible_y
)
16614 struct glyph_row
*row
;
16616 /* IT.vpos always starts from 0; it counts text lines. */
16617 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
16619 /* Find PT if not already found in the lines displayed. */
16620 if (w
->cursor
.vpos
< 0)
16622 int dy
= it
.current_y
- start_row
->y
;
16624 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16625 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
16627 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
16628 dy
, nrows_scrolled
);
16631 clear_glyph_matrix (w
->desired_matrix
);
16636 /* Scroll the display. Do it before the current matrix is
16637 changed. The problem here is that update has not yet
16638 run, i.e. part of the current matrix is not up to date.
16639 scroll_run_hook will clear the cursor, and use the
16640 current matrix to get the height of the row the cursor is
16642 run
.current_y
= start_row
->y
;
16643 run
.desired_y
= it
.current_y
;
16644 run
.height
= it
.last_visible_y
- it
.current_y
;
16646 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
16649 FRAME_RIF (f
)->update_window_begin_hook (w
);
16650 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16651 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16652 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16656 /* Shift current matrix down by nrows_scrolled lines. */
16657 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16658 rotate_matrix (w
->current_matrix
,
16660 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16663 /* Disable lines that must be updated. */
16664 for (i
= 0; i
< nrows_scrolled
; ++i
)
16665 (start_row
+ i
)->enabled_p
= 0;
16667 /* Re-compute Y positions. */
16668 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16669 max_y
= it
.last_visible_y
;
16670 for (row
= start_row
+ nrows_scrolled
;
16674 row
->y
= it
.current_y
;
16675 row
->visible_height
= row
->height
;
16677 if (row
->y
< min_y
)
16678 row
->visible_height
-= min_y
- row
->y
;
16679 if (row
->y
+ row
->height
> max_y
)
16680 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16681 if (row
->fringe_bitmap_periodic_p
)
16682 row
->redraw_fringe_bitmaps_p
= 1;
16684 it
.current_y
+= row
->height
;
16686 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16687 last_reused_text_row
= row
;
16688 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
16692 /* Disable lines in the current matrix which are now
16693 below the window. */
16694 for (++row
; row
< bottom_row
; ++row
)
16695 row
->enabled_p
= row
->mode_line_p
= 0;
16698 /* Update window_end_pos etc.; last_reused_text_row is the last
16699 reused row from the current matrix containing text, if any.
16700 The value of last_text_row is the last displayed line
16701 containing text. */
16702 if (last_reused_text_row
)
16704 w
->window_end_bytepos
16705 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
16706 wset_window_end_pos
16708 - MATRIX_ROW_END_CHARPOS (last_reused_text_row
)));
16709 wset_window_end_vpos
16710 (w
, make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
16711 w
->current_matrix
)));
16713 else if (last_text_row
)
16715 w
->window_end_bytepos
16716 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16717 wset_window_end_pos
16718 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
)));
16719 wset_window_end_vpos
16720 (w
, make_number (MATRIX_ROW_VPOS (last_text_row
,
16721 w
->desired_matrix
)));
16725 /* This window must be completely empty. */
16726 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16727 wset_window_end_pos (w
, make_number (Z
- ZV
));
16728 wset_window_end_vpos (w
, make_number (0));
16730 wset_window_end_valid (w
, Qnil
);
16732 /* Update hint: don't try scrolling again in update_window. */
16733 w
->desired_matrix
->no_scrolling_p
= 1;
16736 debug_method_add (w
, "try_window_reusing_current_matrix 1");
16740 else if (CHARPOS (new_start
) > CHARPOS (start
))
16742 struct glyph_row
*pt_row
, *row
;
16743 struct glyph_row
*first_reusable_row
;
16744 struct glyph_row
*first_row_to_display
;
16746 int yb
= window_text_bottom_y (w
);
16748 /* Find the row starting at new_start, if there is one. Don't
16749 reuse a partially visible line at the end. */
16750 first_reusable_row
= start_row
;
16751 while (first_reusable_row
->enabled_p
16752 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
16753 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16754 < CHARPOS (new_start
)))
16755 ++first_reusable_row
;
16757 /* Give up if there is no row to reuse. */
16758 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
16759 || !first_reusable_row
->enabled_p
16760 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16761 != CHARPOS (new_start
)))
16764 /* We can reuse fully visible rows beginning with
16765 first_reusable_row to the end of the window. Set
16766 first_row_to_display to the first row that cannot be reused.
16767 Set pt_row to the row containing point, if there is any. */
16769 for (first_row_to_display
= first_reusable_row
;
16770 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
16771 ++first_row_to_display
)
16773 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
16774 && (PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16775 || (PT
== MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16776 && first_row_to_display
->ends_at_zv_p
16777 && pt_row
== NULL
)))
16778 pt_row
= first_row_to_display
;
16781 /* Start displaying at the start of first_row_to_display. */
16782 eassert (first_row_to_display
->y
< yb
);
16783 init_to_row_start (&it
, w
, first_row_to_display
);
16785 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
16787 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
16789 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
16790 + WINDOW_HEADER_LINE_HEIGHT (w
));
16792 /* Display lines beginning with first_row_to_display in the
16793 desired matrix. Set last_text_row to the last row displayed
16794 that displays text. */
16795 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
16796 if (pt_row
== NULL
)
16797 w
->cursor
.vpos
= -1;
16798 last_text_row
= NULL
;
16799 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
16800 if (display_line (&it
))
16801 last_text_row
= it
.glyph_row
- 1;
16803 /* If point is in a reused row, adjust y and vpos of the cursor
16807 w
->cursor
.vpos
-= nrows_scrolled
;
16808 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
16811 /* Give up if point isn't in a row displayed or reused. (This
16812 also handles the case where w->cursor.vpos < nrows_scrolled
16813 after the calls to display_line, which can happen with scroll
16814 margins. See bug#1295.) */
16815 if (w
->cursor
.vpos
< 0)
16817 clear_glyph_matrix (w
->desired_matrix
);
16821 /* Scroll the display. */
16822 run
.current_y
= first_reusable_row
->y
;
16823 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16824 run
.height
= it
.last_visible_y
- run
.current_y
;
16825 dy
= run
.current_y
- run
.desired_y
;
16830 FRAME_RIF (f
)->update_window_begin_hook (w
);
16831 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16832 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16833 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16837 /* Adjust Y positions of reused rows. */
16838 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16839 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16840 max_y
= it
.last_visible_y
;
16841 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
16844 row
->visible_height
= row
->height
;
16845 if (row
->y
< min_y
)
16846 row
->visible_height
-= min_y
- row
->y
;
16847 if (row
->y
+ row
->height
> max_y
)
16848 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16849 if (row
->fringe_bitmap_periodic_p
)
16850 row
->redraw_fringe_bitmaps_p
= 1;
16853 /* Scroll the current matrix. */
16854 eassert (nrows_scrolled
> 0);
16855 rotate_matrix (w
->current_matrix
,
16857 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16860 /* Disable rows not reused. */
16861 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
16862 row
->enabled_p
= 0;
16864 /* Point may have moved to a different line, so we cannot assume that
16865 the previous cursor position is valid; locate the correct row. */
16868 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
16870 && PT
>= MATRIX_ROW_END_CHARPOS (row
)
16871 && !row
->ends_at_zv_p
;
16875 w
->cursor
.y
= row
->y
;
16877 if (row
< bottom_row
)
16879 /* Can't simply scan the row for point with
16880 bidi-reordered glyph rows. Let set_cursor_from_row
16881 figure out where to put the cursor, and if it fails,
16883 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
16885 if (!set_cursor_from_row (w
, row
, w
->current_matrix
,
16888 clear_glyph_matrix (w
->desired_matrix
);
16894 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
16895 struct glyph
*end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16898 && (!BUFFERP (glyph
->object
)
16899 || glyph
->charpos
< PT
);
16903 w
->cursor
.x
+= glyph
->pixel_width
;
16909 /* Adjust window end. A null value of last_text_row means that
16910 the window end is in reused rows which in turn means that
16911 only its vpos can have changed. */
16914 w
->window_end_bytepos
16915 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16916 wset_window_end_pos
16917 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
)));
16918 wset_window_end_vpos
16919 (w
, make_number (MATRIX_ROW_VPOS (last_text_row
,
16920 w
->desired_matrix
)));
16924 wset_window_end_vpos
16925 (w
, make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
));
16928 wset_window_end_valid (w
, Qnil
);
16929 w
->desired_matrix
->no_scrolling_p
= 1;
16932 debug_method_add (w
, "try_window_reusing_current_matrix 2");
16942 /************************************************************************
16943 Window redisplay reusing current matrix when buffer has changed
16944 ************************************************************************/
16946 static struct glyph_row
*find_last_unchanged_at_beg_row (struct window
*);
16947 static struct glyph_row
*find_first_unchanged_at_end_row (struct window
*,
16948 ptrdiff_t *, ptrdiff_t *);
16949 static struct glyph_row
*
16950 find_last_row_displaying_text (struct glyph_matrix
*, struct it
*,
16951 struct glyph_row
*);
16954 /* Return the last row in MATRIX displaying text. If row START is
16955 non-null, start searching with that row. IT gives the dimensions
16956 of the display. Value is null if matrix is empty; otherwise it is
16957 a pointer to the row found. */
16959 static struct glyph_row
*
16960 find_last_row_displaying_text (struct glyph_matrix
*matrix
, struct it
*it
,
16961 struct glyph_row
*start
)
16963 struct glyph_row
*row
, *row_found
;
16965 /* Set row_found to the last row in IT->w's current matrix
16966 displaying text. The loop looks funny but think of partially
16969 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
16970 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16972 eassert (row
->enabled_p
);
16974 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
16983 /* Return the last row in the current matrix of W that is not affected
16984 by changes at the start of current_buffer that occurred since W's
16985 current matrix was built. Value is null if no such row exists.
16987 BEG_UNCHANGED us the number of characters unchanged at the start of
16988 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
16989 first changed character in current_buffer. Characters at positions <
16990 BEG + BEG_UNCHANGED are at the same buffer positions as they were
16991 when the current matrix was built. */
16993 static struct glyph_row
*
16994 find_last_unchanged_at_beg_row (struct window
*w
)
16996 ptrdiff_t first_changed_pos
= BEG
+ BEG_UNCHANGED
;
16997 struct glyph_row
*row
;
16998 struct glyph_row
*row_found
= NULL
;
16999 int yb
= window_text_bottom_y (w
);
17001 /* Find the last row displaying unchanged text. */
17002 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
17003 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
17004 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
17007 if (/* If row ends before first_changed_pos, it is unchanged,
17008 except in some case. */
17009 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
17010 /* When row ends in ZV and we write at ZV it is not
17012 && !row
->ends_at_zv_p
17013 /* When first_changed_pos is the end of a continued line,
17014 row is not unchanged because it may be no longer
17016 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
17017 && (row
->continued_p
17018 || row
->exact_window_width_line_p
))
17019 /* If ROW->end is beyond ZV, then ROW->end is outdated and
17020 needs to be recomputed, so don't consider this row as
17021 unchanged. This happens when the last line was
17022 bidi-reordered and was killed immediately before this
17023 redisplay cycle. In that case, ROW->end stores the
17024 buffer position of the first visual-order character of
17025 the killed text, which is now beyond ZV. */
17026 && CHARPOS (row
->end
.pos
) <= ZV
)
17029 /* Stop if last visible row. */
17030 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
17038 /* Find the first glyph row in the current matrix of W that is not
17039 affected by changes at the end of current_buffer since the
17040 time W's current matrix was built.
17042 Return in *DELTA the number of chars by which buffer positions in
17043 unchanged text at the end of current_buffer must be adjusted.
17045 Return in *DELTA_BYTES the corresponding number of bytes.
17047 Value is null if no such row exists, i.e. all rows are affected by
17050 static struct glyph_row
*
17051 find_first_unchanged_at_end_row (struct window
*w
,
17052 ptrdiff_t *delta
, ptrdiff_t *delta_bytes
)
17054 struct glyph_row
*row
;
17055 struct glyph_row
*row_found
= NULL
;
17057 *delta
= *delta_bytes
= 0;
17059 /* Display must not have been paused, otherwise the current matrix
17060 is not up to date. */
17061 eassert (!NILP (w
->window_end_valid
));
17063 /* A value of window_end_pos >= END_UNCHANGED means that the window
17064 end is in the range of changed text. If so, there is no
17065 unchanged row at the end of W's current matrix. */
17066 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
17069 /* Set row to the last row in W's current matrix displaying text. */
17070 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
17072 /* If matrix is entirely empty, no unchanged row exists. */
17073 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
17075 /* The value of row is the last glyph row in the matrix having a
17076 meaningful buffer position in it. The end position of row
17077 corresponds to window_end_pos. This allows us to translate
17078 buffer positions in the current matrix to current buffer
17079 positions for characters not in changed text. */
17081 MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
17082 ptrdiff_t Z_BYTE_old
=
17083 MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
17084 ptrdiff_t last_unchanged_pos
, last_unchanged_pos_old
;
17085 struct glyph_row
*first_text_row
17086 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
17088 *delta
= Z
- Z_old
;
17089 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
17091 /* Set last_unchanged_pos to the buffer position of the last
17092 character in the buffer that has not been changed. Z is the
17093 index + 1 of the last character in current_buffer, i.e. by
17094 subtracting END_UNCHANGED we get the index of the last
17095 unchanged character, and we have to add BEG to get its buffer
17097 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
17098 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
17100 /* Search backward from ROW for a row displaying a line that
17101 starts at a minimum position >= last_unchanged_pos_old. */
17102 for (; row
> first_text_row
; --row
)
17104 /* This used to abort, but it can happen.
17105 It is ok to just stop the search instead here. KFS. */
17106 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
17109 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
17114 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
17120 /* Make sure that glyph rows in the current matrix of window W
17121 reference the same glyph memory as corresponding rows in the
17122 frame's frame matrix. This function is called after scrolling W's
17123 current matrix on a terminal frame in try_window_id and
17124 try_window_reusing_current_matrix. */
17127 sync_frame_with_window_matrix_rows (struct window
*w
)
17129 struct frame
*f
= XFRAME (w
->frame
);
17130 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
17132 /* Preconditions: W must be a leaf window and full-width. Its frame
17133 must have a frame matrix. */
17134 eassert (NILP (w
->hchild
) && NILP (w
->vchild
));
17135 eassert (WINDOW_FULL_WIDTH_P (w
));
17136 eassert (!FRAME_WINDOW_P (f
));
17138 /* If W is a full-width window, glyph pointers in W's current matrix
17139 have, by definition, to be the same as glyph pointers in the
17140 corresponding frame matrix. Note that frame matrices have no
17141 marginal areas (see build_frame_matrix). */
17142 window_row
= w
->current_matrix
->rows
;
17143 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
17144 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
17145 while (window_row
< window_row_end
)
17147 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
17148 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
17150 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
17151 frame_row
->glyphs
[TEXT_AREA
] = start
;
17152 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
17153 frame_row
->glyphs
[LAST_AREA
] = end
;
17155 /* Disable frame rows whose corresponding window rows have
17156 been disabled in try_window_id. */
17157 if (!window_row
->enabled_p
)
17158 frame_row
->enabled_p
= 0;
17160 ++window_row
, ++frame_row
;
17165 /* Find the glyph row in window W containing CHARPOS. Consider all
17166 rows between START and END (not inclusive). END null means search
17167 all rows to the end of the display area of W. Value is the row
17168 containing CHARPOS or null. */
17171 row_containing_pos (struct window
*w
, ptrdiff_t charpos
,
17172 struct glyph_row
*start
, struct glyph_row
*end
, int dy
)
17174 struct glyph_row
*row
= start
;
17175 struct glyph_row
*best_row
= NULL
;
17176 ptrdiff_t mindif
= BUF_ZV (XBUFFER (w
->buffer
)) + 1;
17179 /* If we happen to start on a header-line, skip that. */
17180 if (row
->mode_line_p
)
17183 if ((end
&& row
>= end
) || !row
->enabled_p
)
17186 last_y
= window_text_bottom_y (w
) - dy
;
17190 /* Give up if we have gone too far. */
17191 if (end
&& row
>= end
)
17193 /* This formerly returned if they were equal.
17194 I think that both quantities are of a "last plus one" type;
17195 if so, when they are equal, the row is within the screen. -- rms. */
17196 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
17199 /* If it is in this row, return this row. */
17200 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
17201 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
17202 /* The end position of a row equals the start
17203 position of the next row. If CHARPOS is there, we
17204 would rather display it in the next line, except
17205 when this line ends in ZV. */
17206 && !row
->ends_at_zv_p
17207 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
17208 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
17212 if (NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
17213 || (!best_row
&& !row
->continued_p
))
17215 /* In bidi-reordered rows, there could be several rows
17216 occluding point, all of them belonging to the same
17217 continued line. We need to find the row which fits
17218 CHARPOS the best. */
17219 for (g
= row
->glyphs
[TEXT_AREA
];
17220 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
17223 if (!STRINGP (g
->object
))
17225 if (g
->charpos
> 0 && eabs (g
->charpos
- charpos
) < mindif
)
17227 mindif
= eabs (g
->charpos
- charpos
);
17229 /* Exact match always wins. */
17236 else if (best_row
&& !row
->continued_p
)
17243 /* Try to redisplay window W by reusing its existing display. W's
17244 current matrix must be up to date when this function is called,
17245 i.e. window_end_valid must not be nil.
17249 1 if display has been updated
17250 0 if otherwise unsuccessful
17251 -1 if redisplay with same window start is known not to succeed
17253 The following steps are performed:
17255 1. Find the last row in the current matrix of W that is not
17256 affected by changes at the start of current_buffer. If no such row
17259 2. Find the first row in W's current matrix that is not affected by
17260 changes at the end of current_buffer. Maybe there is no such row.
17262 3. Display lines beginning with the row + 1 found in step 1 to the
17263 row found in step 2 or, if step 2 didn't find a row, to the end of
17266 4. If cursor is not known to appear on the window, give up.
17268 5. If display stopped at the row found in step 2, scroll the
17269 display and current matrix as needed.
17271 6. Maybe display some lines at the end of W, if we must. This can
17272 happen under various circumstances, like a partially visible line
17273 becoming fully visible, or because newly displayed lines are displayed
17274 in smaller font sizes.
17276 7. Update W's window end information. */
17279 try_window_id (struct window
*w
)
17281 struct frame
*f
= XFRAME (w
->frame
);
17282 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
17283 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
17284 struct glyph_row
*last_unchanged_at_beg_row
;
17285 struct glyph_row
*first_unchanged_at_end_row
;
17286 struct glyph_row
*row
;
17287 struct glyph_row
*bottom_row
;
17290 ptrdiff_t delta
= 0, delta_bytes
= 0, stop_pos
;
17292 struct text_pos start_pos
;
17294 int first_unchanged_at_end_vpos
= 0;
17295 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
17296 struct text_pos start
;
17297 ptrdiff_t first_changed_charpos
, last_changed_charpos
;
17300 if (inhibit_try_window_id
)
17304 #ifdef HAVE_XWIDGETS_xxx
17305 //maybe needed for proper xwidget movement
17306 printf("try_window_id\n");
17311 /* This is handy for debugging. */
17313 #define GIVE_UP(X) \
17315 fprintf (stderr, "try_window_id give up %d\n", (X)); \
17319 #define GIVE_UP(X) return 0
17322 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
17324 /* Don't use this for mini-windows because these can show
17325 messages and mini-buffers, and we don't handle that here. */
17326 if (MINI_WINDOW_P (w
))
17329 /* This flag is used to prevent redisplay optimizations. */
17330 if (windows_or_buffers_changed
|| cursor_type_changed
)
17333 /* Verify that narrowing has not changed.
17334 Also verify that we were not told to prevent redisplay optimizations.
17335 It would be nice to further
17336 reduce the number of cases where this prevents try_window_id. */
17337 if (current_buffer
->clip_changed
17338 || current_buffer
->prevent_redisplay_optimizations_p
)
17341 /* Window must either use window-based redisplay or be full width. */
17342 if (!FRAME_WINDOW_P (f
)
17343 && (!FRAME_LINE_INS_DEL_OK (f
)
17344 || !WINDOW_FULL_WIDTH_P (w
)))
17347 /* Give up if point is known NOT to appear in W. */
17348 if (PT
< CHARPOS (start
))
17351 /* Another way to prevent redisplay optimizations. */
17352 if (w
->last_modified
== 0)
17355 /* Verify that window is not hscrolled. */
17356 if (w
->hscroll
!= 0)
17359 /* Verify that display wasn't paused. */
17360 if (NILP (w
->window_end_valid
))
17363 /* Can't use this if highlighting a region because a cursor movement
17364 will do more than just set the cursor. */
17365 if (!NILP (Vtransient_mark_mode
)
17366 && !NILP (BVAR (current_buffer
, mark_active
)))
17369 /* Likewise if highlighting trailing whitespace. */
17370 if (!NILP (Vshow_trailing_whitespace
))
17373 /* Likewise if showing a region. */
17374 if (!NILP (w
->region_showing
))
17377 /* Can't use this if overlay arrow position and/or string have
17379 if (overlay_arrows_changed_p ())
17382 /* When word-wrap is on, adding a space to the first word of a
17383 wrapped line can change the wrap position, altering the line
17384 above it. It might be worthwhile to handle this more
17385 intelligently, but for now just redisplay from scratch. */
17386 if (!NILP (BVAR (XBUFFER (w
->buffer
), word_wrap
)))
17389 /* Under bidi reordering, adding or deleting a character in the
17390 beginning of a paragraph, before the first strong directional
17391 character, can change the base direction of the paragraph (unless
17392 the buffer specifies a fixed paragraph direction), which will
17393 require to redisplay the whole paragraph. It might be worthwhile
17394 to find the paragraph limits and widen the range of redisplayed
17395 lines to that, but for now just give up this optimization and
17396 redisplay from scratch. */
17397 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
17398 && NILP (BVAR (XBUFFER (w
->buffer
), bidi_paragraph_direction
)))
17401 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
17402 only if buffer has really changed. The reason is that the gap is
17403 initially at Z for freshly visited files. The code below would
17404 set end_unchanged to 0 in that case. */
17405 if (MODIFF
> SAVE_MODIFF
17406 /* This seems to happen sometimes after saving a buffer. */
17407 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
17409 if (GPT
- BEG
< BEG_UNCHANGED
)
17410 BEG_UNCHANGED
= GPT
- BEG
;
17411 if (Z
- GPT
< END_UNCHANGED
)
17412 END_UNCHANGED
= Z
- GPT
;
17415 /* The position of the first and last character that has been changed. */
17416 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
17417 last_changed_charpos
= Z
- END_UNCHANGED
;
17419 /* If window starts after a line end, and the last change is in
17420 front of that newline, then changes don't affect the display.
17421 This case happens with stealth-fontification. Note that although
17422 the display is unchanged, glyph positions in the matrix have to
17423 be adjusted, of course. */
17424 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
17425 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
17426 && ((last_changed_charpos
< CHARPOS (start
)
17427 && CHARPOS (start
) == BEGV
)
17428 || (last_changed_charpos
< CHARPOS (start
) - 1
17429 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
17431 ptrdiff_t Z_old
, Z_delta
, Z_BYTE_old
, Z_delta_bytes
;
17432 struct glyph_row
*r0
;
17434 /* Compute how many chars/bytes have been added to or removed
17435 from the buffer. */
17436 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
17437 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
17438 Z_delta
= Z
- Z_old
;
17439 Z_delta_bytes
= Z_BYTE
- Z_BYTE_old
;
17441 /* Give up if PT is not in the window. Note that it already has
17442 been checked at the start of try_window_id that PT is not in
17443 front of the window start. */
17444 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + Z_delta
)
17447 /* If window start is unchanged, we can reuse the whole matrix
17448 as is, after adjusting glyph positions. No need to compute
17449 the window end again, since its offset from Z hasn't changed. */
17450 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17451 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + Z_delta
17452 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + Z_delta_bytes
17453 /* PT must not be in a partially visible line. */
17454 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + Z_delta
17455 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17457 /* Adjust positions in the glyph matrix. */
17458 if (Z_delta
|| Z_delta_bytes
)
17460 struct glyph_row
*r1
17461 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17462 increment_matrix_positions (w
->current_matrix
,
17463 MATRIX_ROW_VPOS (r0
, current_matrix
),
17464 MATRIX_ROW_VPOS (r1
, current_matrix
),
17465 Z_delta
, Z_delta_bytes
);
17468 /* Set the cursor. */
17469 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17471 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17478 /* Handle the case that changes are all below what is displayed in
17479 the window, and that PT is in the window. This shortcut cannot
17480 be taken if ZV is visible in the window, and text has been added
17481 there that is visible in the window. */
17482 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
17483 /* ZV is not visible in the window, or there are no
17484 changes at ZV, actually. */
17485 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
17486 || first_changed_charpos
== last_changed_charpos
))
17488 struct glyph_row
*r0
;
17490 /* Give up if PT is not in the window. Note that it already has
17491 been checked at the start of try_window_id that PT is not in
17492 front of the window start. */
17493 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
17496 /* If window start is unchanged, we can reuse the whole matrix
17497 as is, without changing glyph positions since no text has
17498 been added/removed in front of the window end. */
17499 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17500 if (TEXT_POS_EQUAL_P (start
, r0
->minpos
)
17501 /* PT must not be in a partially visible line. */
17502 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
17503 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17505 /* We have to compute the window end anew since text
17506 could have been added/removed after it. */
17507 wset_window_end_pos
17508 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (row
)));
17509 w
->window_end_bytepos
17510 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17512 /* Set the cursor. */
17513 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17515 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17522 /* Give up if window start is in the changed area.
17524 The condition used to read
17526 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
17528 but why that was tested escapes me at the moment. */
17529 if (CHARPOS (start
) >= first_changed_charpos
17530 && CHARPOS (start
) <= last_changed_charpos
)
17533 /* Check that window start agrees with the start of the first glyph
17534 row in its current matrix. Check this after we know the window
17535 start is not in changed text, otherwise positions would not be
17537 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17538 if (!TEXT_POS_EQUAL_P (start
, row
->minpos
))
17541 /* Give up if the window ends in strings. Overlay strings
17542 at the end are difficult to handle, so don't try. */
17543 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
17544 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
17547 /* Compute the position at which we have to start displaying new
17548 lines. Some of the lines at the top of the window might be
17549 reusable because they are not displaying changed text. Find the
17550 last row in W's current matrix not affected by changes at the
17551 start of current_buffer. Value is null if changes start in the
17552 first line of window. */
17553 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
17554 if (last_unchanged_at_beg_row
)
17556 /* Avoid starting to display in the middle of a character, a TAB
17557 for instance. This is easier than to set up the iterator
17558 exactly, and it's not a frequent case, so the additional
17559 effort wouldn't really pay off. */
17560 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
17561 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
17562 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
17563 --last_unchanged_at_beg_row
;
17565 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
17568 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
17570 start_pos
= it
.current
.pos
;
17572 /* Start displaying new lines in the desired matrix at the same
17573 vpos we would use in the current matrix, i.e. below
17574 last_unchanged_at_beg_row. */
17575 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
17577 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17578 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
17580 eassert (it
.hpos
== 0 && it
.current_x
== 0);
17584 /* There are no reusable lines at the start of the window.
17585 Start displaying in the first text line. */
17586 start_display (&it
, w
, start
);
17587 it
.vpos
= it
.first_vpos
;
17588 start_pos
= it
.current
.pos
;
17591 /* Find the first row that is not affected by changes at the end of
17592 the buffer. Value will be null if there is no unchanged row, in
17593 which case we must redisplay to the end of the window. delta
17594 will be set to the value by which buffer positions beginning with
17595 first_unchanged_at_end_row have to be adjusted due to text
17597 first_unchanged_at_end_row
17598 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
17599 IF_DEBUG (debug_delta
= delta
);
17600 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
17602 /* Set stop_pos to the buffer position up to which we will have to
17603 display new lines. If first_unchanged_at_end_row != NULL, this
17604 is the buffer position of the start of the line displayed in that
17605 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
17606 that we don't stop at a buffer position. */
17608 if (first_unchanged_at_end_row
)
17610 eassert (last_unchanged_at_beg_row
== NULL
17611 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
17613 /* If this is a continuation line, move forward to the next one
17614 that isn't. Changes in lines above affect this line.
17615 Caution: this may move first_unchanged_at_end_row to a row
17616 not displaying text. */
17617 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
17618 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17619 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17620 < it
.last_visible_y
))
17621 ++first_unchanged_at_end_row
;
17623 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17624 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17625 >= it
.last_visible_y
))
17626 first_unchanged_at_end_row
= NULL
;
17629 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
17631 first_unchanged_at_end_vpos
17632 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
17633 eassert (stop_pos
>= Z
- END_UNCHANGED
);
17636 else if (last_unchanged_at_beg_row
== NULL
)
17642 /* Either there is no unchanged row at the end, or the one we have
17643 now displays text. This is a necessary condition for the window
17644 end pos calculation at the end of this function. */
17645 eassert (first_unchanged_at_end_row
== NULL
17646 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
17648 debug_last_unchanged_at_beg_vpos
17649 = (last_unchanged_at_beg_row
17650 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
17652 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
17654 #endif /* GLYPH_DEBUG */
17657 /* Display new lines. Set last_text_row to the last new line
17658 displayed which has text on it, i.e. might end up as being the
17659 line where the window_end_vpos is. */
17660 w
->cursor
.vpos
= -1;
17661 last_text_row
= NULL
;
17662 overlay_arrow_seen
= 0;
17663 while (it
.current_y
< it
.last_visible_y
17664 && !fonts_changed_p
17665 && (first_unchanged_at_end_row
== NULL
17666 || IT_CHARPOS (it
) < stop_pos
))
17668 if (display_line (&it
))
17669 last_text_row
= it
.glyph_row
- 1;
17672 if (fonts_changed_p
)
17676 /* Compute differences in buffer positions, y-positions etc. for
17677 lines reused at the bottom of the window. Compute what we can
17679 if (first_unchanged_at_end_row
17680 /* No lines reused because we displayed everything up to the
17681 bottom of the window. */
17682 && it
.current_y
< it
.last_visible_y
)
17685 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
17687 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
17688 run
.current_y
= first_unchanged_at_end_row
->y
;
17689 run
.desired_y
= run
.current_y
+ dy
;
17690 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
17694 delta
= delta_bytes
= dvpos
= dy
17695 = run
.current_y
= run
.desired_y
= run
.height
= 0;
17696 first_unchanged_at_end_row
= NULL
;
17698 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
17701 /* Find the cursor if not already found. We have to decide whether
17702 PT will appear on this window (it sometimes doesn't, but this is
17703 not a very frequent case.) This decision has to be made before
17704 the current matrix is altered. A value of cursor.vpos < 0 means
17705 that PT is either in one of the lines beginning at
17706 first_unchanged_at_end_row or below the window. Don't care for
17707 lines that might be displayed later at the window end; as
17708 mentioned, this is not a frequent case. */
17709 if (w
->cursor
.vpos
< 0)
17711 /* Cursor in unchanged rows at the top? */
17712 if (PT
< CHARPOS (start_pos
)
17713 && last_unchanged_at_beg_row
)
17715 row
= row_containing_pos (w
, PT
,
17716 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
17717 last_unchanged_at_beg_row
+ 1, 0);
17719 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
17722 /* Start from first_unchanged_at_end_row looking for PT. */
17723 else if (first_unchanged_at_end_row
)
17725 row
= row_containing_pos (w
, PT
- delta
,
17726 first_unchanged_at_end_row
, NULL
, 0);
17728 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
17729 delta_bytes
, dy
, dvpos
);
17732 /* Give up if cursor was not found. */
17733 if (w
->cursor
.vpos
< 0)
17735 clear_glyph_matrix (w
->desired_matrix
);
17740 /* Don't let the cursor end in the scroll margins. */
17742 int this_scroll_margin
, cursor_height
;
17744 this_scroll_margin
=
17745 max (0, min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4));
17746 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
17747 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
17749 if ((w
->cursor
.y
< this_scroll_margin
17750 && CHARPOS (start
) > BEGV
)
17751 /* Old redisplay didn't take scroll margin into account at the bottom,
17752 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
17753 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
17754 ? cursor_height
+ this_scroll_margin
17755 : 1)) > it
.last_visible_y
)
17757 w
->cursor
.vpos
= -1;
17758 clear_glyph_matrix (w
->desired_matrix
);
17763 /* Scroll the display. Do it before changing the current matrix so
17764 that xterm.c doesn't get confused about where the cursor glyph is
17766 if (dy
&& run
.height
)
17770 if (FRAME_WINDOW_P (f
))
17772 FRAME_RIF (f
)->update_window_begin_hook (w
);
17773 FRAME_RIF (f
)->clear_window_mouse_face (w
);
17774 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
17775 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
17779 /* Terminal frame. In this case, dvpos gives the number of
17780 lines to scroll by; dvpos < 0 means scroll up. */
17782 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
17783 int from
= WINDOW_TOP_EDGE_LINE (w
) + from_vpos
;
17784 int end
= (WINDOW_TOP_EDGE_LINE (w
)
17785 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
17786 + window_internal_height (w
));
17788 #if defined (HAVE_GPM) || defined (MSDOS)
17789 x_clear_window_mouse_face (w
);
17791 /* Perform the operation on the screen. */
17794 /* Scroll last_unchanged_at_beg_row to the end of the
17795 window down dvpos lines. */
17796 set_terminal_window (f
, end
);
17798 /* On dumb terminals delete dvpos lines at the end
17799 before inserting dvpos empty lines. */
17800 if (!FRAME_SCROLL_REGION_OK (f
))
17801 ins_del_lines (f
, end
- dvpos
, -dvpos
);
17803 /* Insert dvpos empty lines in front of
17804 last_unchanged_at_beg_row. */
17805 ins_del_lines (f
, from
, dvpos
);
17807 else if (dvpos
< 0)
17809 /* Scroll up last_unchanged_at_beg_vpos to the end of
17810 the window to last_unchanged_at_beg_vpos - |dvpos|. */
17811 set_terminal_window (f
, end
);
17813 /* Delete dvpos lines in front of
17814 last_unchanged_at_beg_vpos. ins_del_lines will set
17815 the cursor to the given vpos and emit |dvpos| delete
17817 ins_del_lines (f
, from
+ dvpos
, dvpos
);
17819 /* On a dumb terminal insert dvpos empty lines at the
17821 if (!FRAME_SCROLL_REGION_OK (f
))
17822 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
17825 set_terminal_window (f
, 0);
17831 /* Shift reused rows of the current matrix to the right position.
17832 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
17834 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17835 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
17838 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
17839 bottom_vpos
, dvpos
);
17840 clear_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
17843 else if (dvpos
> 0)
17845 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
17846 bottom_vpos
, dvpos
);
17847 clear_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
17848 first_unchanged_at_end_vpos
+ dvpos
);
17851 /* For frame-based redisplay, make sure that current frame and window
17852 matrix are in sync with respect to glyph memory. */
17853 if (!FRAME_WINDOW_P (f
))
17854 sync_frame_with_window_matrix_rows (w
);
17856 /* Adjust buffer positions in reused rows. */
17857 if (delta
|| delta_bytes
)
17858 increment_matrix_positions (current_matrix
,
17859 first_unchanged_at_end_vpos
+ dvpos
,
17860 bottom_vpos
, delta
, delta_bytes
);
17862 /* Adjust Y positions. */
17864 shift_glyph_matrix (w
, current_matrix
,
17865 first_unchanged_at_end_vpos
+ dvpos
,
17868 if (first_unchanged_at_end_row
)
17870 first_unchanged_at_end_row
+= dvpos
;
17871 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
17872 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
17873 first_unchanged_at_end_row
= NULL
;
17876 /* If scrolling up, there may be some lines to display at the end of
17878 last_text_row_at_end
= NULL
;
17881 /* Scrolling up can leave for example a partially visible line
17882 at the end of the window to be redisplayed. */
17883 /* Set last_row to the glyph row in the current matrix where the
17884 window end line is found. It has been moved up or down in
17885 the matrix by dvpos. */
17886 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
17887 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
17889 /* If last_row is the window end line, it should display text. */
17890 eassert (last_row
->displays_text_p
);
17892 /* If window end line was partially visible before, begin
17893 displaying at that line. Otherwise begin displaying with the
17894 line following it. */
17895 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
17897 init_to_row_start (&it
, w
, last_row
);
17898 it
.vpos
= last_vpos
;
17899 it
.current_y
= last_row
->y
;
17903 init_to_row_end (&it
, w
, last_row
);
17904 it
.vpos
= 1 + last_vpos
;
17905 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
17909 /* We may start in a continuation line. If so, we have to
17910 get the right continuation_lines_width and current_x. */
17911 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
17912 it
.hpos
= it
.current_x
= 0;
17914 /* Display the rest of the lines at the window end. */
17915 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17916 while (it
.current_y
< it
.last_visible_y
17917 && !fonts_changed_p
)
17919 /* Is it always sure that the display agrees with lines in
17920 the current matrix? I don't think so, so we mark rows
17921 displayed invalid in the current matrix by setting their
17922 enabled_p flag to zero. */
17923 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
17924 if (display_line (&it
))
17925 last_text_row_at_end
= it
.glyph_row
- 1;
17929 /* Update window_end_pos and window_end_vpos. */
17930 if (first_unchanged_at_end_row
17931 && !last_text_row_at_end
)
17933 /* Window end line if one of the preserved rows from the current
17934 matrix. Set row to the last row displaying text in current
17935 matrix starting at first_unchanged_at_end_row, after
17937 eassert (first_unchanged_at_end_row
->displays_text_p
);
17938 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
17939 first_unchanged_at_end_row
);
17940 eassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
17942 wset_window_end_pos (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (row
)));
17943 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17944 wset_window_end_vpos
17945 (w
, make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
)));
17946 eassert (w
->window_end_bytepos
>= 0);
17947 IF_DEBUG (debug_method_add (w
, "A"));
17949 else if (last_text_row_at_end
)
17951 wset_window_end_pos
17952 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
)));
17953 w
->window_end_bytepos
17954 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
17955 wset_window_end_vpos
17956 (w
, make_number (MATRIX_ROW_VPOS (last_text_row_at_end
,
17958 eassert (w
->window_end_bytepos
>= 0);
17959 IF_DEBUG (debug_method_add (w
, "B"));
17961 else if (last_text_row
)
17963 /* We have displayed either to the end of the window or at the
17964 end of the window, i.e. the last row with text is to be found
17965 in the desired matrix. */
17966 wset_window_end_pos
17967 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
)));
17968 w
->window_end_bytepos
17969 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
17970 wset_window_end_vpos
17971 (w
, make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
)));
17972 eassert (w
->window_end_bytepos
>= 0);
17974 else if (first_unchanged_at_end_row
== NULL
17975 && last_text_row
== NULL
17976 && last_text_row_at_end
== NULL
)
17978 /* Displayed to end of window, but no line containing text was
17979 displayed. Lines were deleted at the end of the window. */
17980 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
17981 int vpos
= XFASTINT (w
->window_end_vpos
);
17982 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
17983 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
17986 row
== NULL
&& vpos
>= first_vpos
;
17987 --vpos
, --current_row
, --desired_row
)
17989 if (desired_row
->enabled_p
)
17991 if (desired_row
->displays_text_p
)
17994 else if (current_row
->displays_text_p
)
17998 eassert (row
!= NULL
);
17999 wset_window_end_vpos (w
, make_number (vpos
+ 1));
18000 wset_window_end_pos (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (row
)));
18001 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
18002 eassert (w
->window_end_bytepos
>= 0);
18003 IF_DEBUG (debug_method_add (w
, "C"));
18008 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
18009 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
18011 /* Record that display has not been completed. */
18012 wset_window_end_valid (w
, Qnil
);
18013 w
->desired_matrix
->no_scrolling_p
= 1;
18021 /***********************************************************************
18022 More debugging support
18023 ***********************************************************************/
18027 void dump_glyph_row (struct glyph_row
*, int, int) EXTERNALLY_VISIBLE
;
18028 void dump_glyph_matrix (struct glyph_matrix
*, int) EXTERNALLY_VISIBLE
;
18029 void dump_glyph (struct glyph_row
*, struct glyph
*, int) EXTERNALLY_VISIBLE
;
18032 /* Dump the contents of glyph matrix MATRIX on stderr.
18034 GLYPHS 0 means don't show glyph contents.
18035 GLYPHS 1 means show glyphs in short form
18036 GLYPHS > 1 means show glyphs in long form. */
18039 dump_glyph_matrix (struct glyph_matrix
*matrix
, int glyphs
)
18042 for (i
= 0; i
< matrix
->nrows
; ++i
)
18043 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
18047 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
18048 the glyph row and area where the glyph comes from. */
18051 dump_glyph (struct glyph_row
*row
, struct glyph
*glyph
, int area
)
18053 if (glyph
->type
== CHAR_GLYPH
)
18056 " %5td %4c %6"pI
"d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
18057 glyph
- row
->glyphs
[TEXT_AREA
],
18060 (BUFFERP (glyph
->object
)
18062 : (STRINGP (glyph
->object
)
18065 glyph
->pixel_width
,
18067 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
18071 glyph
->left_box_line_p
,
18072 glyph
->right_box_line_p
);
18074 else if (glyph
->type
== STRETCH_GLYPH
)
18077 " %5td %4c %6"pI
"d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
18078 glyph
- row
->glyphs
[TEXT_AREA
],
18081 (BUFFERP (glyph
->object
)
18083 : (STRINGP (glyph
->object
)
18086 glyph
->pixel_width
,
18090 glyph
->left_box_line_p
,
18091 glyph
->right_box_line_p
);
18093 else if (glyph
->type
== IMAGE_GLYPH
)
18096 " %5td %4c %6"pI
"d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
18097 glyph
- row
->glyphs
[TEXT_AREA
],
18100 (BUFFERP (glyph
->object
)
18102 : (STRINGP (glyph
->object
)
18105 glyph
->pixel_width
,
18109 glyph
->left_box_line_p
,
18110 glyph
->right_box_line_p
);
18112 else if (glyph
->type
== COMPOSITE_GLYPH
)
18115 " %5td %4c %6"pI
"d %c %3d 0x%05x",
18116 glyph
- row
->glyphs
[TEXT_AREA
],
18119 (BUFFERP (glyph
->object
)
18121 : (STRINGP (glyph
->object
)
18124 glyph
->pixel_width
,
18126 if (glyph
->u
.cmp
.automatic
)
18129 glyph
->slice
.cmp
.from
, glyph
->slice
.cmp
.to
);
18130 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
18132 glyph
->left_box_line_p
,
18133 glyph
->right_box_line_p
);
18135 #ifdef HAVE_XWIDGETS
18136 else if (glyph
->type
== XWIDGET_GLYPH
)
18139 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
18140 glyph
- row
->glyphs
[TEXT_AREA
],
18143 (BUFFERP (glyph
->object
)
18145 : (STRINGP (glyph
->object
)
18148 glyph
->pixel_width
,
18152 glyph
->left_box_line_p
,
18153 glyph
->right_box_line_p
);
18155 // printf("dump xwidget glyph\n");
18161 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
18162 GLYPHS 0 means don't show glyph contents.
18163 GLYPHS 1 means show glyphs in short form
18164 GLYPHS > 1 means show glyphs in long form. */
18167 dump_glyph_row (struct glyph_row
*row
, int vpos
, int glyphs
)
18171 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
18172 fprintf (stderr
, "======================================================================\n");
18174 fprintf (stderr
, "%3d %5"pI
"d %5"pI
"d %4d %1.1d%1.1d%1.1d%1.1d\
18175 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
18177 MATRIX_ROW_START_CHARPOS (row
),
18178 MATRIX_ROW_END_CHARPOS (row
),
18179 row
->used
[TEXT_AREA
],
18180 row
->contains_overlapping_glyphs_p
,
18182 row
->truncated_on_left_p
,
18183 row
->truncated_on_right_p
,
18185 MATRIX_ROW_CONTINUATION_LINE_P (row
),
18186 row
->displays_text_p
,
18189 row
->ends_in_middle_of_char_p
,
18190 row
->starts_in_middle_of_char_p
,
18196 row
->visible_height
,
18199 fprintf (stderr
, "%9"pD
"d %5"pD
"d\t%5d\n", row
->start
.overlay_string_index
,
18200 row
->end
.overlay_string_index
,
18201 row
->continuation_lines_width
);
18202 fprintf (stderr
, "%9"pI
"d %5"pI
"d\n",
18203 CHARPOS (row
->start
.string_pos
),
18204 CHARPOS (row
->end
.string_pos
));
18205 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
18206 row
->end
.dpvec_index
);
18213 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18215 struct glyph
*glyph
= row
->glyphs
[area
];
18216 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
18218 /* Glyph for a line end in text. */
18219 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
18222 if (glyph
< glyph_end
)
18223 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
18225 for (; glyph
< glyph_end
; ++glyph
)
18226 dump_glyph (row
, glyph
, area
);
18229 else if (glyphs
== 1)
18233 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18235 char *s
= alloca (row
->used
[area
] + 1);
18238 for (i
= 0; i
< row
->used
[area
]; ++i
)
18240 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
18241 if (glyph
->type
== CHAR_GLYPH
18242 && glyph
->u
.ch
< 0x80
18243 && glyph
->u
.ch
>= ' ')
18244 s
[i
] = glyph
->u
.ch
;
18250 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
18256 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
18257 Sdump_glyph_matrix
, 0, 1, "p",
18258 doc
: /* Dump the current matrix of the selected window to stderr.
18259 Shows contents of glyph row structures. With non-nil
18260 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
18261 glyphs in short form, otherwise show glyphs in long form. */)
18262 (Lisp_Object glyphs
)
18264 struct window
*w
= XWINDOW (selected_window
);
18265 struct buffer
*buffer
= XBUFFER (w
->buffer
);
18267 fprintf (stderr
, "PT = %"pI
"d, BEGV = %"pI
"d. ZV = %"pI
"d\n",
18268 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
18269 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
18270 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
18271 fprintf (stderr
, "=============================================\n");
18272 dump_glyph_matrix (w
->current_matrix
,
18273 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 0);
18278 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
18279 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
18282 struct frame
*f
= XFRAME (selected_frame
);
18283 dump_glyph_matrix (f
->current_matrix
, 1);
18288 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
18289 doc
: /* Dump glyph row ROW to stderr.
18290 GLYPH 0 means don't dump glyphs.
18291 GLYPH 1 means dump glyphs in short form.
18292 GLYPH > 1 or omitted means dump glyphs in long form. */)
18293 (Lisp_Object row
, Lisp_Object glyphs
)
18295 struct glyph_matrix
*matrix
;
18298 CHECK_NUMBER (row
);
18299 matrix
= XWINDOW (selected_window
)->current_matrix
;
18301 if (vpos
>= 0 && vpos
< matrix
->nrows
)
18302 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
18304 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18309 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
18310 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
18311 GLYPH 0 means don't dump glyphs.
18312 GLYPH 1 means dump glyphs in short form.
18313 GLYPH > 1 or omitted means dump glyphs in long form. */)
18314 (Lisp_Object row
, Lisp_Object glyphs
)
18316 struct frame
*sf
= SELECTED_FRAME ();
18317 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
18320 CHECK_NUMBER (row
);
18322 if (vpos
>= 0 && vpos
< m
->nrows
)
18323 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
18324 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18329 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
18330 doc
: /* Toggle tracing of redisplay.
18331 With ARG, turn tracing on if and only if ARG is positive. */)
18335 trace_redisplay_p
= !trace_redisplay_p
;
18338 arg
= Fprefix_numeric_value (arg
);
18339 trace_redisplay_p
= XINT (arg
) > 0;
18346 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
18347 doc
: /* Like `format', but print result to stderr.
18348 usage: (trace-to-stderr STRING &rest OBJECTS) */)
18349 (ptrdiff_t nargs
, Lisp_Object
*args
)
18351 Lisp_Object s
= Fformat (nargs
, args
);
18352 fprintf (stderr
, "%s", SDATA (s
));
18356 #endif /* GLYPH_DEBUG */
18360 /***********************************************************************
18361 Building Desired Matrix Rows
18362 ***********************************************************************/
18364 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
18365 Used for non-window-redisplay windows, and for windows w/o left fringe. */
18367 static struct glyph_row
*
18368 get_overlay_arrow_glyph_row (struct window
*w
, Lisp_Object overlay_arrow_string
)
18370 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18371 struct buffer
*buffer
= XBUFFER (w
->buffer
);
18372 struct buffer
*old
= current_buffer
;
18373 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
18374 int arrow_len
= SCHARS (overlay_arrow_string
);
18375 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
18376 const unsigned char *p
;
18379 int n_glyphs_before
;
18381 set_buffer_temp (buffer
);
18382 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
18383 it
.glyph_row
->used
[TEXT_AREA
] = 0;
18384 SET_TEXT_POS (it
.position
, 0, 0);
18386 multibyte_p
= !NILP (BVAR (buffer
, enable_multibyte_characters
));
18388 while (p
< arrow_end
)
18390 Lisp_Object face
, ilisp
;
18392 /* Get the next character. */
18394 it
.c
= it
.char_to_display
= string_char_and_length (p
, &it
.len
);
18397 it
.c
= it
.char_to_display
= *p
, it
.len
= 1;
18398 if (! ASCII_CHAR_P (it
.c
))
18399 it
.char_to_display
= BYTE8_TO_CHAR (it
.c
);
18403 /* Get its face. */
18404 ilisp
= make_number (p
- arrow_string
);
18405 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
18406 it
.face_id
= compute_char_face (f
, it
.char_to_display
, face
);
18408 /* Compute its width, get its glyphs. */
18409 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
18410 SET_TEXT_POS (it
.position
, -1, -1);
18411 PRODUCE_GLYPHS (&it
);
18413 /* If this character doesn't fit any more in the line, we have
18414 to remove some glyphs. */
18415 if (it
.current_x
> it
.last_visible_x
)
18417 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
18422 set_buffer_temp (old
);
18423 return it
.glyph_row
;
18427 /* Insert truncation glyphs at the start of IT->glyph_row. Which
18428 glyphs to insert is determined by produce_special_glyphs. */
18431 insert_left_trunc_glyphs (struct it
*it
)
18433 struct it truncate_it
;
18434 struct glyph
*from
, *end
, *to
, *toend
;
18436 eassert (!FRAME_WINDOW_P (it
->f
)
18437 || (!it
->glyph_row
->reversed_p
18438 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0)
18439 || (it
->glyph_row
->reversed_p
18440 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0));
18442 /* Get the truncation glyphs. */
18444 truncate_it
.current_x
= 0;
18445 truncate_it
.face_id
= DEFAULT_FACE_ID
;
18446 truncate_it
.glyph_row
= &scratch_glyph_row
;
18447 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
18448 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
18449 truncate_it
.object
= make_number (0);
18450 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
18452 /* Overwrite glyphs from IT with truncation glyphs. */
18453 if (!it
->glyph_row
->reversed_p
)
18455 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
18457 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18458 end
= from
+ tused
;
18459 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18460 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
18461 if (FRAME_WINDOW_P (it
->f
))
18463 /* On GUI frames, when variable-size fonts are displayed,
18464 the truncation glyphs may need more pixels than the row's
18465 glyphs they overwrite. We overwrite more glyphs to free
18466 enough screen real estate, and enlarge the stretch glyph
18467 on the right (see display_line), if there is one, to
18468 preserve the screen position of the truncation glyphs on
18471 struct glyph
*g
= to
;
18474 /* The first glyph could be partially visible, in which case
18475 it->glyph_row->x will be negative. But we want the left
18476 truncation glyphs to be aligned at the left margin of the
18477 window, so we override the x coordinate at which the row
18479 it
->glyph_row
->x
= 0;
18480 while (g
< toend
&& w
< it
->truncation_pixel_width
)
18482 w
+= g
->pixel_width
;
18485 if (g
- to
- tused
> 0)
18487 memmove (to
+ tused
, g
, (toend
- g
) * sizeof(*g
));
18488 it
->glyph_row
->used
[TEXT_AREA
] -= g
- to
- tused
;
18490 used
= it
->glyph_row
->used
[TEXT_AREA
];
18491 if (it
->glyph_row
->truncated_on_right_p
18492 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0
18493 && it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].type
18496 int extra
= w
- it
->truncation_pixel_width
;
18498 it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].pixel_width
+= extra
;
18505 /* There may be padding glyphs left over. Overwrite them too. */
18506 if (!FRAME_WINDOW_P (it
->f
))
18508 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
18510 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18517 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
18521 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
18523 /* In R2L rows, overwrite the last (rightmost) glyphs, and do
18524 that back to front. */
18525 end
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18526 from
= end
+ truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18527 toend
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18528 to
= toend
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18529 if (FRAME_WINDOW_P (it
->f
))
18532 struct glyph
*g
= to
;
18534 while (g
>= toend
&& w
< it
->truncation_pixel_width
)
18536 w
+= g
->pixel_width
;
18539 if (to
- g
- tused
> 0)
18541 if (it
->glyph_row
->truncated_on_right_p
18542 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0
18543 && it
->glyph_row
->glyphs
[TEXT_AREA
][1].type
== STRETCH_GLYPH
)
18545 int extra
= w
- it
->truncation_pixel_width
;
18547 it
->glyph_row
->glyphs
[TEXT_AREA
][1].pixel_width
+= extra
;
18551 while (from
>= end
&& to
>= toend
)
18553 if (!FRAME_WINDOW_P (it
->f
))
18555 while (to
>= toend
&& CHAR_GLYPH_PADDING_P (*to
))
18558 truncate_it
.glyph_row
->glyphs
[TEXT_AREA
]
18559 + truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18560 while (from
>= end
&& to
>= toend
)
18566 /* Need to free some room before prepending additional
18568 int move_by
= from
- end
+ 1;
18569 struct glyph
*g0
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18570 struct glyph
*g
= g0
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18572 for ( ; g
>= g0
; g
--)
18574 while (from
>= end
)
18576 it
->glyph_row
->used
[TEXT_AREA
] += move_by
;
18581 /* Compute the hash code for ROW. */
18583 row_hash (struct glyph_row
*row
)
18586 unsigned hashval
= 0;
18588 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18589 for (k
= 0; k
< row
->used
[area
]; ++k
)
18590 hashval
= ((((hashval
<< 4) + (hashval
>> 24)) & 0x0fffffff)
18591 + row
->glyphs
[area
][k
].u
.val
18592 + row
->glyphs
[area
][k
].face_id
18593 + row
->glyphs
[area
][k
].padding_p
18594 + (row
->glyphs
[area
][k
].type
<< 2));
18599 /* Compute the pixel height and width of IT->glyph_row.
18601 Most of the time, ascent and height of a display line will be equal
18602 to the max_ascent and max_height values of the display iterator
18603 structure. This is not the case if
18605 1. We hit ZV without displaying anything. In this case, max_ascent
18606 and max_height will be zero.
18608 2. We have some glyphs that don't contribute to the line height.
18609 (The glyph row flag contributes_to_line_height_p is for future
18610 pixmap extensions).
18612 The first case is easily covered by using default values because in
18613 these cases, the line height does not really matter, except that it
18614 must not be zero. */
18617 compute_line_metrics (struct it
*it
)
18619 struct glyph_row
*row
= it
->glyph_row
;
18621 if (FRAME_WINDOW_P (it
->f
))
18623 int i
, min_y
, max_y
;
18625 /* The line may consist of one space only, that was added to
18626 place the cursor on it. If so, the row's height hasn't been
18628 if (row
->height
== 0)
18630 if (it
->max_ascent
+ it
->max_descent
== 0)
18631 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
18632 row
->ascent
= it
->max_ascent
;
18633 row
->height
= it
->max_ascent
+ it
->max_descent
;
18634 row
->phys_ascent
= it
->max_phys_ascent
;
18635 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18636 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18639 /* Compute the width of this line. */
18640 row
->pixel_width
= row
->x
;
18641 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
18642 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
18644 eassert (row
->pixel_width
>= 0);
18645 eassert (row
->ascent
>= 0 && row
->height
> 0);
18647 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
18648 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
18650 /* If first line's physical ascent is larger than its logical
18651 ascent, use the physical ascent, and make the row taller.
18652 This makes accented characters fully visible. */
18653 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
18654 && row
->phys_ascent
> row
->ascent
)
18656 row
->height
+= row
->phys_ascent
- row
->ascent
;
18657 row
->ascent
= row
->phys_ascent
;
18660 /* Compute how much of the line is visible. */
18661 row
->visible_height
= row
->height
;
18663 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
18664 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
18666 if (row
->y
< min_y
)
18667 row
->visible_height
-= min_y
- row
->y
;
18668 if (row
->y
+ row
->height
> max_y
)
18669 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
18673 row
->pixel_width
= row
->used
[TEXT_AREA
];
18674 if (row
->continued_p
)
18675 row
->pixel_width
-= it
->continuation_pixel_width
;
18676 else if (row
->truncated_on_right_p
)
18677 row
->pixel_width
-= it
->truncation_pixel_width
;
18678 row
->ascent
= row
->phys_ascent
= 0;
18679 row
->height
= row
->phys_height
= row
->visible_height
= 1;
18680 row
->extra_line_spacing
= 0;
18683 /* Compute a hash code for this row. */
18684 row
->hash
= row_hash (row
);
18686 it
->max_ascent
= it
->max_descent
= 0;
18687 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
18691 /* Append one space to the glyph row of iterator IT if doing a
18692 window-based redisplay. The space has the same face as
18693 IT->face_id. Value is non-zero if a space was added.
18695 This function is called to make sure that there is always one glyph
18696 at the end of a glyph row that the cursor can be set on under
18697 window-systems. (If there weren't such a glyph we would not know
18698 how wide and tall a box cursor should be displayed).
18700 At the same time this space let's a nicely handle clearing to the
18701 end of the line if the row ends in italic text. */
18704 append_space_for_newline (struct it
*it
, int default_face_p
)
18706 if (FRAME_WINDOW_P (it
->f
))
18708 int n
= it
->glyph_row
->used
[TEXT_AREA
];
18710 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
18711 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
18713 /* Save some values that must not be changed.
18714 Must save IT->c and IT->len because otherwise
18715 ITERATOR_AT_END_P wouldn't work anymore after
18716 append_space_for_newline has been called. */
18717 enum display_element_type saved_what
= it
->what
;
18718 int saved_c
= it
->c
, saved_len
= it
->len
;
18719 int saved_char_to_display
= it
->char_to_display
;
18720 int saved_x
= it
->current_x
;
18721 int saved_face_id
= it
->face_id
;
18722 struct text_pos saved_pos
;
18723 Lisp_Object saved_object
;
18726 saved_object
= it
->object
;
18727 saved_pos
= it
->position
;
18729 it
->what
= IT_CHARACTER
;
18730 memset (&it
->position
, 0, sizeof it
->position
);
18731 it
->object
= make_number (0);
18732 it
->c
= it
->char_to_display
= ' ';
18735 /* If the default face was remapped, be sure to use the
18736 remapped face for the appended newline. */
18737 if (default_face_p
)
18738 it
->face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
18739 else if (it
->face_before_selective_p
)
18740 it
->face_id
= it
->saved_face_id
;
18741 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18742 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
18744 PRODUCE_GLYPHS (it
);
18746 it
->override_ascent
= -1;
18747 it
->constrain_row_ascent_descent_p
= 0;
18748 it
->current_x
= saved_x
;
18749 it
->object
= saved_object
;
18750 it
->position
= saved_pos
;
18751 it
->what
= saved_what
;
18752 it
->face_id
= saved_face_id
;
18753 it
->len
= saved_len
;
18755 it
->char_to_display
= saved_char_to_display
;
18764 /* Extend the face of the last glyph in the text area of IT->glyph_row
18765 to the end of the display line. Called from display_line. If the
18766 glyph row is empty, add a space glyph to it so that we know the
18767 face to draw. Set the glyph row flag fill_line_p. If the glyph
18768 row is R2L, prepend a stretch glyph to cover the empty space to the
18769 left of the leftmost glyph. */
18772 extend_face_to_end_of_line (struct it
*it
)
18774 struct face
*face
, *default_face
;
18775 struct frame
*f
= it
->f
;
18777 /* If line is already filled, do nothing. Non window-system frames
18778 get a grace of one more ``pixel'' because their characters are
18779 1-``pixel'' wide, so they hit the equality too early. This grace
18780 is needed only for R2L rows that are not continued, to produce
18781 one extra blank where we could display the cursor. */
18782 if (it
->current_x
>= it
->last_visible_x
18783 + (!FRAME_WINDOW_P (f
)
18784 && it
->glyph_row
->reversed_p
18785 && !it
->glyph_row
->continued_p
))
18788 /* The default face, possibly remapped. */
18789 default_face
= FACE_FROM_ID (f
, lookup_basic_face (f
, DEFAULT_FACE_ID
));
18791 /* Face extension extends the background and box of IT->face_id
18792 to the end of the line. If the background equals the background
18793 of the frame, we don't have to do anything. */
18794 if (it
->face_before_selective_p
)
18795 face
= FACE_FROM_ID (f
, it
->saved_face_id
);
18797 face
= FACE_FROM_ID (f
, it
->face_id
);
18799 if (FRAME_WINDOW_P (f
)
18800 && it
->glyph_row
->displays_text_p
18801 && face
->box
== FACE_NO_BOX
18802 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
18804 && !it
->glyph_row
->reversed_p
)
18807 /* Set the glyph row flag indicating that the face of the last glyph
18808 in the text area has to be drawn to the end of the text area. */
18809 it
->glyph_row
->fill_line_p
= 1;
18811 /* If current character of IT is not ASCII, make sure we have the
18812 ASCII face. This will be automatically undone the next time
18813 get_next_display_element returns a multibyte character. Note
18814 that the character will always be single byte in unibyte
18816 if (!ASCII_CHAR_P (it
->c
))
18818 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
18821 if (FRAME_WINDOW_P (f
))
18823 /* If the row is empty, add a space with the current face of IT,
18824 so that we know which face to draw. */
18825 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
18827 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
18828 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= face
->id
;
18829 it
->glyph_row
->used
[TEXT_AREA
] = 1;
18831 #ifdef HAVE_WINDOW_SYSTEM
18832 if (it
->glyph_row
->reversed_p
)
18834 /* Prepend a stretch glyph to the row, such that the
18835 rightmost glyph will be drawn flushed all the way to the
18836 right margin of the window. The stretch glyph that will
18837 occupy the empty space, if any, to the left of the
18839 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (f
);
18840 struct glyph
*row_start
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18841 struct glyph
*row_end
= row_start
+ it
->glyph_row
->used
[TEXT_AREA
];
18843 int row_width
, stretch_ascent
, stretch_width
;
18844 struct text_pos saved_pos
;
18845 int saved_face_id
, saved_avoid_cursor
;
18847 for (row_width
= 0, g
= row_start
; g
< row_end
; g
++)
18848 row_width
+= g
->pixel_width
;
18849 stretch_width
= window_box_width (it
->w
, TEXT_AREA
) - row_width
;
18850 if (stretch_width
> 0)
18853 (((it
->ascent
+ it
->descent
)
18854 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
18855 saved_pos
= it
->position
;
18856 memset (&it
->position
, 0, sizeof it
->position
);
18857 saved_avoid_cursor
= it
->avoid_cursor_p
;
18858 it
->avoid_cursor_p
= 1;
18859 saved_face_id
= it
->face_id
;
18860 /* The last row's stretch glyph should get the default
18861 face, to avoid painting the rest of the window with
18862 the region face, if the region ends at ZV. */
18863 if (it
->glyph_row
->ends_at_zv_p
)
18864 it
->face_id
= default_face
->id
;
18866 it
->face_id
= face
->id
;
18867 append_stretch_glyph (it
, make_number (0), stretch_width
,
18868 it
->ascent
+ it
->descent
, stretch_ascent
);
18869 it
->position
= saved_pos
;
18870 it
->avoid_cursor_p
= saved_avoid_cursor
;
18871 it
->face_id
= saved_face_id
;
18874 #endif /* HAVE_WINDOW_SYSTEM */
18878 /* Save some values that must not be changed. */
18879 int saved_x
= it
->current_x
;
18880 struct text_pos saved_pos
;
18881 Lisp_Object saved_object
;
18882 enum display_element_type saved_what
= it
->what
;
18883 int saved_face_id
= it
->face_id
;
18885 saved_object
= it
->object
;
18886 saved_pos
= it
->position
;
18888 it
->what
= IT_CHARACTER
;
18889 memset (&it
->position
, 0, sizeof it
->position
);
18890 it
->object
= make_number (0);
18891 it
->c
= it
->char_to_display
= ' ';
18893 /* The last row's blank glyphs should get the default face, to
18894 avoid painting the rest of the window with the region face,
18895 if the region ends at ZV. */
18896 if (it
->glyph_row
->ends_at_zv_p
)
18897 it
->face_id
= default_face
->id
;
18899 it
->face_id
= face
->id
;
18901 PRODUCE_GLYPHS (it
);
18903 while (it
->current_x
<= it
->last_visible_x
)
18904 PRODUCE_GLYPHS (it
);
18906 /* Don't count these blanks really. It would let us insert a left
18907 truncation glyph below and make us set the cursor on them, maybe. */
18908 it
->current_x
= saved_x
;
18909 it
->object
= saved_object
;
18910 it
->position
= saved_pos
;
18911 it
->what
= saved_what
;
18912 it
->face_id
= saved_face_id
;
18917 /* Value is non-zero if text starting at CHARPOS in current_buffer is
18918 trailing whitespace. */
18921 trailing_whitespace_p (ptrdiff_t charpos
)
18923 ptrdiff_t bytepos
= CHAR_TO_BYTE (charpos
);
18926 while (bytepos
< ZV_BYTE
18927 && (c
= FETCH_CHAR (bytepos
),
18928 c
== ' ' || c
== '\t'))
18931 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
18933 if (bytepos
!= PT_BYTE
)
18940 /* Highlight trailing whitespace, if any, in ROW. */
18943 highlight_trailing_whitespace (struct frame
*f
, struct glyph_row
*row
)
18945 int used
= row
->used
[TEXT_AREA
];
18949 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
18950 struct glyph
*glyph
= start
+ used
- 1;
18952 if (row
->reversed_p
)
18954 /* Right-to-left rows need to be processed in the opposite
18955 direction, so swap the edge pointers. */
18957 start
= row
->glyphs
[TEXT_AREA
] + used
- 1;
18960 /* Skip over glyphs inserted to display the cursor at the
18961 end of a line, for extending the face of the last glyph
18962 to the end of the line on terminals, and for truncation
18963 and continuation glyphs. */
18964 if (!row
->reversed_p
)
18966 while (glyph
>= start
18967 && glyph
->type
== CHAR_GLYPH
18968 && INTEGERP (glyph
->object
))
18973 while (glyph
<= start
18974 && glyph
->type
== CHAR_GLYPH
18975 && INTEGERP (glyph
->object
))
18979 /* If last glyph is a space or stretch, and it's trailing
18980 whitespace, set the face of all trailing whitespace glyphs in
18981 IT->glyph_row to `trailing-whitespace'. */
18982 if ((row
->reversed_p
? glyph
<= start
: glyph
>= start
)
18983 && BUFFERP (glyph
->object
)
18984 && (glyph
->type
== STRETCH_GLYPH
18985 || (glyph
->type
== CHAR_GLYPH
18986 && glyph
->u
.ch
== ' '))
18987 && trailing_whitespace_p (glyph
->charpos
))
18989 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
18993 if (!row
->reversed_p
)
18995 while (glyph
>= start
18996 && BUFFERP (glyph
->object
)
18997 && (glyph
->type
== STRETCH_GLYPH
18998 || (glyph
->type
== CHAR_GLYPH
18999 && glyph
->u
.ch
== ' ')))
19000 (glyph
--)->face_id
= face_id
;
19004 while (glyph
<= start
19005 && BUFFERP (glyph
->object
)
19006 && (glyph
->type
== STRETCH_GLYPH
19007 || (glyph
->type
== CHAR_GLYPH
19008 && glyph
->u
.ch
== ' ')))
19009 (glyph
++)->face_id
= face_id
;
19016 /* Value is non-zero if glyph row ROW should be
19017 used to hold the cursor. */
19020 cursor_row_p (struct glyph_row
*row
)
19024 if (PT
== CHARPOS (row
->end
.pos
)
19025 || PT
== MATRIX_ROW_END_CHARPOS (row
))
19027 /* Suppose the row ends on a string.
19028 Unless the row is continued, that means it ends on a newline
19029 in the string. If it's anything other than a display string
19030 (e.g., a before-string from an overlay), we don't want the
19031 cursor there. (This heuristic seems to give the optimal
19032 behavior for the various types of multi-line strings.)
19033 One exception: if the string has `cursor' property on one of
19034 its characters, we _do_ want the cursor there. */
19035 if (CHARPOS (row
->end
.string_pos
) >= 0)
19037 if (row
->continued_p
)
19041 /* Check for `display' property. */
19042 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
19043 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
19044 struct glyph
*glyph
;
19047 for (glyph
= end
; glyph
>= beg
; --glyph
)
19048 if (STRINGP (glyph
->object
))
19051 = Fget_char_property (make_number (PT
),
19055 && display_prop_string_p (prop
, glyph
->object
));
19056 /* If there's a `cursor' property on one of the
19057 string's characters, this row is a cursor row,
19058 even though this is not a display string. */
19061 Lisp_Object s
= glyph
->object
;
19063 for ( ; glyph
>= beg
&& EQ (glyph
->object
, s
); --glyph
)
19065 ptrdiff_t gpos
= glyph
->charpos
;
19067 if (!NILP (Fget_char_property (make_number (gpos
),
19079 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
19081 /* If the row ends in middle of a real character,
19082 and the line is continued, we want the cursor here.
19083 That's because CHARPOS (ROW->end.pos) would equal
19084 PT if PT is before the character. */
19085 if (!row
->ends_in_ellipsis_p
)
19086 result
= row
->continued_p
;
19088 /* If the row ends in an ellipsis, then
19089 CHARPOS (ROW->end.pos) will equal point after the
19090 invisible text. We want that position to be displayed
19091 after the ellipsis. */
19094 /* If the row ends at ZV, display the cursor at the end of that
19095 row instead of at the start of the row below. */
19096 else if (row
->ends_at_zv_p
)
19107 /* Push the property PROP so that it will be rendered at the current
19108 position in IT. Return 1 if PROP was successfully pushed, 0
19109 otherwise. Called from handle_line_prefix to handle the
19110 `line-prefix' and `wrap-prefix' properties. */
19113 push_prefix_prop (struct it
*it
, Lisp_Object prop
)
19115 struct text_pos pos
=
19116 STRINGP (it
->string
) ? it
->current
.string_pos
: it
->current
.pos
;
19118 eassert (it
->method
== GET_FROM_BUFFER
19119 || it
->method
== GET_FROM_DISPLAY_VECTOR
19120 || it
->method
== GET_FROM_STRING
);
19122 /* We need to save the current buffer/string position, so it will be
19123 restored by pop_it, because iterate_out_of_display_property
19124 depends on that being set correctly, but some situations leave
19125 it->position not yet set when this function is called. */
19126 push_it (it
, &pos
);
19128 if (STRINGP (prop
))
19130 if (SCHARS (prop
) == 0)
19137 it
->string_from_prefix_prop_p
= 1;
19138 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
19139 it
->current
.overlay_string_index
= -1;
19140 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
19141 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
19142 it
->method
= GET_FROM_STRING
;
19143 it
->stop_charpos
= 0;
19145 it
->base_level_stop
= 0;
19147 /* Force paragraph direction to be that of the parent
19149 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
19150 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
19152 it
->paragraph_embedding
= L2R
;
19154 /* Set up the bidi iterator for this display string. */
19157 it
->bidi_it
.string
.lstring
= it
->string
;
19158 it
->bidi_it
.string
.s
= NULL
;
19159 it
->bidi_it
.string
.schars
= it
->end_charpos
;
19160 it
->bidi_it
.string
.bufpos
= IT_CHARPOS (*it
);
19161 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
19162 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
19163 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
19166 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
19168 it
->method
= GET_FROM_STRETCH
;
19171 #ifdef HAVE_WINDOW_SYSTEM
19172 else if (IMAGEP (prop
))
19174 it
->what
= IT_IMAGE
;
19175 it
->image_id
= lookup_image (it
->f
, prop
);
19176 it
->method
= GET_FROM_IMAGE
;
19178 #endif /* HAVE_WINDOW_SYSTEM */
19181 pop_it (it
); /* bogus display property, give up */
19188 /* Return the character-property PROP at the current position in IT. */
19191 get_it_property (struct it
*it
, Lisp_Object prop
)
19193 Lisp_Object position
;
19195 if (STRINGP (it
->object
))
19196 position
= make_number (IT_STRING_CHARPOS (*it
));
19197 else if (BUFFERP (it
->object
))
19198 position
= make_number (IT_CHARPOS (*it
));
19202 return Fget_char_property (position
, prop
, it
->object
);
19205 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
19208 handle_line_prefix (struct it
*it
)
19210 Lisp_Object prefix
;
19212 if (it
->continuation_lines_width
> 0)
19214 prefix
= get_it_property (it
, Qwrap_prefix
);
19216 prefix
= Vwrap_prefix
;
19220 prefix
= get_it_property (it
, Qline_prefix
);
19222 prefix
= Vline_prefix
;
19224 if (! NILP (prefix
) && push_prefix_prop (it
, prefix
))
19226 /* If the prefix is wider than the window, and we try to wrap
19227 it, it would acquire its own wrap prefix, and so on till the
19228 iterator stack overflows. So, don't wrap the prefix. */
19229 it
->line_wrap
= TRUNCATE
;
19230 it
->avoid_cursor_p
= 1;
19236 /* Remove N glyphs at the start of a reversed IT->glyph_row. Called
19237 only for R2L lines from display_line and display_string, when they
19238 decide that too many glyphs were produced by PRODUCE_GLYPHS, and
19239 the line/string needs to be continued on the next glyph row. */
19241 unproduce_glyphs (struct it
*it
, int n
)
19243 struct glyph
*glyph
, *end
;
19245 eassert (it
->glyph_row
);
19246 eassert (it
->glyph_row
->reversed_p
);
19247 eassert (it
->area
== TEXT_AREA
);
19248 eassert (n
<= it
->glyph_row
->used
[TEXT_AREA
]);
19250 if (n
> it
->glyph_row
->used
[TEXT_AREA
])
19251 n
= it
->glyph_row
->used
[TEXT_AREA
];
19252 glyph
= it
->glyph_row
->glyphs
[TEXT_AREA
] + n
;
19253 end
= it
->glyph_row
->glyphs
[TEXT_AREA
] + it
->glyph_row
->used
[TEXT_AREA
];
19254 for ( ; glyph
< end
; glyph
++)
19255 glyph
[-n
] = *glyph
;
19258 /* Find the positions in a bidi-reordered ROW to serve as ROW->minpos
19259 and ROW->maxpos. */
19261 find_row_edges (struct it
*it
, struct glyph_row
*row
,
19262 ptrdiff_t min_pos
, ptrdiff_t min_bpos
,
19263 ptrdiff_t max_pos
, ptrdiff_t max_bpos
)
19265 /* FIXME: Revisit this when glyph ``spilling'' in continuation
19266 lines' rows is implemented for bidi-reordered rows. */
19268 /* ROW->minpos is the value of min_pos, the minimal buffer position
19269 we have in ROW, or ROW->start.pos if that is smaller. */
19270 if (min_pos
<= ZV
&& min_pos
< row
->start
.pos
.charpos
)
19271 SET_TEXT_POS (row
->minpos
, min_pos
, min_bpos
);
19273 /* We didn't find buffer positions smaller than ROW->start, or
19274 didn't find _any_ valid buffer positions in any of the glyphs,
19275 so we must trust the iterator's computed positions. */
19276 row
->minpos
= row
->start
.pos
;
19279 max_pos
= CHARPOS (it
->current
.pos
);
19280 max_bpos
= BYTEPOS (it
->current
.pos
);
19283 /* Here are the various use-cases for ending the row, and the
19284 corresponding values for ROW->maxpos:
19286 Line ends in a newline from buffer eol_pos + 1
19287 Line is continued from buffer max_pos + 1
19288 Line is truncated on right it->current.pos
19289 Line ends in a newline from string max_pos + 1(*)
19290 (*) + 1 only when line ends in a forward scan
19291 Line is continued from string max_pos
19292 Line is continued from display vector max_pos
19293 Line is entirely from a string min_pos == max_pos
19294 Line is entirely from a display vector min_pos == max_pos
19295 Line that ends at ZV ZV
19297 If you discover other use-cases, please add them here as
19299 if (row
->ends_at_zv_p
)
19300 row
->maxpos
= it
->current
.pos
;
19301 else if (row
->used
[TEXT_AREA
])
19303 int seen_this_string
= 0;
19304 struct glyph_row
*r1
= row
- 1;
19306 /* Did we see the same display string on the previous row? */
19307 if (STRINGP (it
->object
)
19308 /* this is not the first row */
19309 && row
> it
->w
->desired_matrix
->rows
19310 /* previous row is not the header line */
19311 && !r1
->mode_line_p
19312 /* previous row also ends in a newline from a string */
19313 && r1
->ends_in_newline_from_string_p
)
19315 struct glyph
*start
, *end
;
19317 /* Search for the last glyph of the previous row that came
19318 from buffer or string. Depending on whether the row is
19319 L2R or R2L, we need to process it front to back or the
19320 other way round. */
19321 if (!r1
->reversed_p
)
19323 start
= r1
->glyphs
[TEXT_AREA
];
19324 end
= start
+ r1
->used
[TEXT_AREA
];
19325 /* Glyphs inserted by redisplay have an integer (zero)
19326 as their object. */
19328 && INTEGERP ((end
- 1)->object
)
19329 && (end
- 1)->charpos
<= 0)
19333 if (EQ ((end
- 1)->object
, it
->object
))
19334 seen_this_string
= 1;
19337 /* If all the glyphs of the previous row were inserted
19338 by redisplay, it means the previous row was
19339 produced from a single newline, which is only
19340 possible if that newline came from the same string
19341 as the one which produced this ROW. */
19342 seen_this_string
= 1;
19346 end
= r1
->glyphs
[TEXT_AREA
] - 1;
19347 start
= end
+ r1
->used
[TEXT_AREA
];
19349 && INTEGERP ((end
+ 1)->object
)
19350 && (end
+ 1)->charpos
<= 0)
19354 if (EQ ((end
+ 1)->object
, it
->object
))
19355 seen_this_string
= 1;
19358 seen_this_string
= 1;
19361 /* Take note of each display string that covers a newline only
19362 once, the first time we see it. This is for when a display
19363 string includes more than one newline in it. */
19364 if (row
->ends_in_newline_from_string_p
&& !seen_this_string
)
19366 /* If we were scanning the buffer forward when we displayed
19367 the string, we want to account for at least one buffer
19368 position that belongs to this row (position covered by
19369 the display string), so that cursor positioning will
19370 consider this row as a candidate when point is at the end
19371 of the visual line represented by this row. This is not
19372 required when scanning back, because max_pos will already
19373 have a much larger value. */
19374 if (CHARPOS (row
->end
.pos
) > max_pos
)
19375 INC_BOTH (max_pos
, max_bpos
);
19376 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19378 else if (CHARPOS (it
->eol_pos
) > 0)
19379 SET_TEXT_POS (row
->maxpos
,
19380 CHARPOS (it
->eol_pos
) + 1, BYTEPOS (it
->eol_pos
) + 1);
19381 else if (row
->continued_p
)
19383 /* If max_pos is different from IT's current position, it
19384 means IT->method does not belong to the display element
19385 at max_pos. However, it also means that the display
19386 element at max_pos was displayed in its entirety on this
19387 line, which is equivalent to saying that the next line
19388 starts at the next buffer position. */
19389 if (IT_CHARPOS (*it
) == max_pos
&& it
->method
!= GET_FROM_BUFFER
)
19390 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19393 INC_BOTH (max_pos
, max_bpos
);
19394 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19397 else if (row
->truncated_on_right_p
)
19398 /* display_line already called reseat_at_next_visible_line_start,
19399 which puts the iterator at the beginning of the next line, in
19400 the logical order. */
19401 row
->maxpos
= it
->current
.pos
;
19402 else if (max_pos
== min_pos
&& it
->method
!= GET_FROM_BUFFER
)
19403 /* A line that is entirely from a string/image/stretch... */
19404 row
->maxpos
= row
->minpos
;
19409 row
->maxpos
= it
->current
.pos
;
19412 /* Construct the glyph row IT->glyph_row in the desired matrix of
19413 IT->w from text at the current position of IT. See dispextern.h
19414 for an overview of struct it. Value is non-zero if
19415 IT->glyph_row displays text, as opposed to a line displaying ZV
19419 display_line (struct it
*it
)
19421 struct glyph_row
*row
= it
->glyph_row
;
19422 Lisp_Object overlay_arrow_string
;
19424 void *wrap_data
= NULL
;
19425 int may_wrap
= 0, wrap_x
IF_LINT (= 0);
19426 int wrap_row_used
= -1;
19427 int wrap_row_ascent
IF_LINT (= 0), wrap_row_height
IF_LINT (= 0);
19428 int wrap_row_phys_ascent
IF_LINT (= 0), wrap_row_phys_height
IF_LINT (= 0);
19429 int wrap_row_extra_line_spacing
IF_LINT (= 0);
19430 ptrdiff_t wrap_row_min_pos
IF_LINT (= 0), wrap_row_min_bpos
IF_LINT (= 0);
19431 ptrdiff_t wrap_row_max_pos
IF_LINT (= 0), wrap_row_max_bpos
IF_LINT (= 0);
19433 ptrdiff_t min_pos
= ZV
+ 1, max_pos
= 0;
19434 ptrdiff_t min_bpos
IF_LINT (= 0), max_bpos
IF_LINT (= 0);
19436 /* We always start displaying at hpos zero even if hscrolled. */
19437 eassert (it
->hpos
== 0 && it
->current_x
== 0);
19439 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
19440 >= it
->w
->desired_matrix
->nrows
)
19442 it
->w
->nrows_scale_factor
++;
19443 fonts_changed_p
= 1;
19447 /* Is IT->w showing the region? */
19448 wset_region_showing (it
->w
, it
->region_beg_charpos
> 0 ? Qt
: Qnil
);
19450 /* Clear the result glyph row and enable it. */
19451 prepare_desired_row (row
);
19453 row
->y
= it
->current_y
;
19454 row
->start
= it
->start
;
19455 row
->continuation_lines_width
= it
->continuation_lines_width
;
19456 row
->displays_text_p
= 1;
19457 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
19458 it
->starts_in_middle_of_char_p
= 0;
19460 /* Arrange the overlays nicely for our purposes. Usually, we call
19461 display_line on only one line at a time, in which case this
19462 can't really hurt too much, or we call it on lines which appear
19463 one after another in the buffer, in which case all calls to
19464 recenter_overlay_lists but the first will be pretty cheap. */
19465 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
19467 /* Move over display elements that are not visible because we are
19468 hscrolled. This may stop at an x-position < IT->first_visible_x
19469 if the first glyph is partially visible or if we hit a line end. */
19470 if (it
->current_x
< it
->first_visible_x
)
19472 enum move_it_result move_result
;
19474 this_line_min_pos
= row
->start
.pos
;
19475 move_result
= move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
19476 MOVE_TO_POS
| MOVE_TO_X
);
19477 /* If we are under a large hscroll, move_it_in_display_line_to
19478 could hit the end of the line without reaching
19479 it->first_visible_x. Pretend that we did reach it. This is
19480 especially important on a TTY, where we will call
19481 extend_face_to_end_of_line, which needs to know how many
19482 blank glyphs to produce. */
19483 if (it
->current_x
< it
->first_visible_x
19484 && (move_result
== MOVE_NEWLINE_OR_CR
19485 || move_result
== MOVE_POS_MATCH_OR_ZV
))
19486 it
->current_x
= it
->first_visible_x
;
19488 /* Record the smallest positions seen while we moved over
19489 display elements that are not visible. This is needed by
19490 redisplay_internal for optimizing the case where the cursor
19491 stays inside the same line. The rest of this function only
19492 considers positions that are actually displayed, so
19493 RECORD_MAX_MIN_POS will not otherwise record positions that
19494 are hscrolled to the left of the left edge of the window. */
19495 min_pos
= CHARPOS (this_line_min_pos
);
19496 min_bpos
= BYTEPOS (this_line_min_pos
);
19500 /* We only do this when not calling `move_it_in_display_line_to'
19501 above, because move_it_in_display_line_to calls
19502 handle_line_prefix itself. */
19503 handle_line_prefix (it
);
19506 /* Get the initial row height. This is either the height of the
19507 text hscrolled, if there is any, or zero. */
19508 row
->ascent
= it
->max_ascent
;
19509 row
->height
= it
->max_ascent
+ it
->max_descent
;
19510 row
->phys_ascent
= it
->max_phys_ascent
;
19511 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
19512 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
19514 /* Utility macro to record max and min buffer positions seen until now. */
19515 #define RECORD_MAX_MIN_POS(IT) \
19518 int composition_p = !STRINGP ((IT)->string) \
19519 && ((IT)->what == IT_COMPOSITION); \
19520 ptrdiff_t current_pos = \
19521 composition_p ? (IT)->cmp_it.charpos \
19522 : IT_CHARPOS (*(IT)); \
19523 ptrdiff_t current_bpos = \
19524 composition_p ? CHAR_TO_BYTE (current_pos) \
19525 : IT_BYTEPOS (*(IT)); \
19526 if (current_pos < min_pos) \
19528 min_pos = current_pos; \
19529 min_bpos = current_bpos; \
19531 if (IT_CHARPOS (*it) > max_pos) \
19533 max_pos = IT_CHARPOS (*it); \
19534 max_bpos = IT_BYTEPOS (*it); \
19539 /* Loop generating characters. The loop is left with IT on the next
19540 character to display. */
19543 int n_glyphs_before
, hpos_before
, x_before
;
19545 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
19547 /* Retrieve the next thing to display. Value is zero if end of
19549 if (!get_next_display_element (it
))
19551 /* Maybe add a space at the end of this line that is used to
19552 display the cursor there under X. Set the charpos of the
19553 first glyph of blank lines not corresponding to any text
19555 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19556 row
->exact_window_width_line_p
= 1;
19557 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
19558 || row
->used
[TEXT_AREA
] == 0)
19560 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
19561 row
->displays_text_p
= 0;
19563 if (!NILP (BVAR (XBUFFER (it
->w
->buffer
), indicate_empty_lines
))
19564 && (!MINI_WINDOW_P (it
->w
)
19565 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
19566 row
->indicate_empty_line_p
= 1;
19569 it
->continuation_lines_width
= 0;
19570 row
->ends_at_zv_p
= 1;
19571 /* A row that displays right-to-left text must always have
19572 its last face extended all the way to the end of line,
19573 even if this row ends in ZV, because we still write to
19574 the screen left to right. We also need to extend the
19575 last face if the default face is remapped to some
19576 different face, otherwise the functions that clear
19577 portions of the screen will clear with the default face's
19578 background color. */
19579 if (row
->reversed_p
19580 || lookup_basic_face (it
->f
, DEFAULT_FACE_ID
) != DEFAULT_FACE_ID
)
19581 extend_face_to_end_of_line (it
);
19585 /* Now, get the metrics of what we want to display. This also
19586 generates glyphs in `row' (which is IT->glyph_row). */
19587 n_glyphs_before
= row
->used
[TEXT_AREA
];
19590 /* Remember the line height so far in case the next element doesn't
19591 fit on the line. */
19592 if (it
->line_wrap
!= TRUNCATE
)
19594 ascent
= it
->max_ascent
;
19595 descent
= it
->max_descent
;
19596 phys_ascent
= it
->max_phys_ascent
;
19597 phys_descent
= it
->max_phys_descent
;
19599 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
19601 if (IT_DISPLAYING_WHITESPACE (it
))
19605 SAVE_IT (wrap_it
, *it
, wrap_data
);
19607 wrap_row_used
= row
->used
[TEXT_AREA
];
19608 wrap_row_ascent
= row
->ascent
;
19609 wrap_row_height
= row
->height
;
19610 wrap_row_phys_ascent
= row
->phys_ascent
;
19611 wrap_row_phys_height
= row
->phys_height
;
19612 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
19613 wrap_row_min_pos
= min_pos
;
19614 wrap_row_min_bpos
= min_bpos
;
19615 wrap_row_max_pos
= max_pos
;
19616 wrap_row_max_bpos
= max_bpos
;
19622 PRODUCE_GLYPHS (it
);
19624 /* If this display element was in marginal areas, continue with
19626 if (it
->area
!= TEXT_AREA
)
19628 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19629 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19630 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19631 row
->phys_height
= max (row
->phys_height
,
19632 it
->max_phys_ascent
+ it
->max_phys_descent
);
19633 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19634 it
->max_extra_line_spacing
);
19635 set_iterator_to_next (it
, 1);
19639 /* Does the display element fit on the line? If we truncate
19640 lines, we should draw past the right edge of the window. If
19641 we don't truncate, we want to stop so that we can display the
19642 continuation glyph before the right margin. If lines are
19643 continued, there are two possible strategies for characters
19644 resulting in more than 1 glyph (e.g. tabs): Display as many
19645 glyphs as possible in this line and leave the rest for the
19646 continuation line, or display the whole element in the next
19647 line. Original redisplay did the former, so we do it also. */
19648 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
19649 hpos_before
= it
->hpos
;
19652 if (/* Not a newline. */
19654 /* Glyphs produced fit entirely in the line. */
19655 && it
->current_x
< it
->last_visible_x
)
19657 it
->hpos
+= nglyphs
;
19658 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19659 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19660 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19661 row
->phys_height
= max (row
->phys_height
,
19662 it
->max_phys_ascent
+ it
->max_phys_descent
);
19663 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19664 it
->max_extra_line_spacing
);
19665 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
19666 row
->x
= x
- it
->first_visible_x
;
19667 /* Record the maximum and minimum buffer positions seen so
19668 far in glyphs that will be displayed by this row. */
19670 RECORD_MAX_MIN_POS (it
);
19675 struct glyph
*glyph
;
19677 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
19679 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
19680 new_x
= x
+ glyph
->pixel_width
;
19682 if (/* Lines are continued. */
19683 it
->line_wrap
!= TRUNCATE
19684 && (/* Glyph doesn't fit on the line. */
19685 new_x
> it
->last_visible_x
19686 /* Or it fits exactly on a window system frame. */
19687 || (new_x
== it
->last_visible_x
19688 && FRAME_WINDOW_P (it
->f
)
19689 && (row
->reversed_p
19690 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19691 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
19693 /* End of a continued line. */
19696 || (new_x
== it
->last_visible_x
19697 && FRAME_WINDOW_P (it
->f
)
19698 && (row
->reversed_p
19699 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19700 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
))))
19702 /* Current glyph is the only one on the line or
19703 fits exactly on the line. We must continue
19704 the line because we can't draw the cursor
19705 after the glyph. */
19706 row
->continued_p
= 1;
19707 it
->current_x
= new_x
;
19708 it
->continuation_lines_width
+= new_x
;
19710 if (i
== nglyphs
- 1)
19712 /* If line-wrap is on, check if a previous
19713 wrap point was found. */
19714 if (wrap_row_used
> 0
19715 /* Even if there is a previous wrap
19716 point, continue the line here as
19717 usual, if (i) the previous character
19718 was a space or tab AND (ii) the
19719 current character is not. */
19721 || IT_DISPLAYING_WHITESPACE (it
)))
19724 /* Record the maximum and minimum buffer
19725 positions seen so far in glyphs that will be
19726 displayed by this row. */
19728 RECORD_MAX_MIN_POS (it
);
19729 set_iterator_to_next (it
, 1);
19730 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19732 if (!get_next_display_element (it
))
19734 row
->exact_window_width_line_p
= 1;
19735 it
->continuation_lines_width
= 0;
19736 row
->continued_p
= 0;
19737 row
->ends_at_zv_p
= 1;
19739 else if (ITERATOR_AT_END_OF_LINE_P (it
))
19741 row
->continued_p
= 0;
19742 row
->exact_window_width_line_p
= 1;
19746 else if (it
->bidi_p
)
19747 RECORD_MAX_MIN_POS (it
);
19749 else if (CHAR_GLYPH_PADDING_P (*glyph
)
19750 && !FRAME_WINDOW_P (it
->f
))
19752 /* A padding glyph that doesn't fit on this line.
19753 This means the whole character doesn't fit
19755 if (row
->reversed_p
)
19756 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19757 - n_glyphs_before
);
19758 row
->used
[TEXT_AREA
] = n_glyphs_before
;
19760 /* Fill the rest of the row with continuation
19761 glyphs like in 20.x. */
19762 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
19763 < row
->glyphs
[1 + TEXT_AREA
])
19764 produce_special_glyphs (it
, IT_CONTINUATION
);
19766 row
->continued_p
= 1;
19767 it
->current_x
= x_before
;
19768 it
->continuation_lines_width
+= x_before
;
19770 /* Restore the height to what it was before the
19771 element not fitting on the line. */
19772 it
->max_ascent
= ascent
;
19773 it
->max_descent
= descent
;
19774 it
->max_phys_ascent
= phys_ascent
;
19775 it
->max_phys_descent
= phys_descent
;
19777 else if (wrap_row_used
> 0)
19780 if (row
->reversed_p
)
19781 unproduce_glyphs (it
,
19782 row
->used
[TEXT_AREA
] - wrap_row_used
);
19783 RESTORE_IT (it
, &wrap_it
, wrap_data
);
19784 it
->continuation_lines_width
+= wrap_x
;
19785 row
->used
[TEXT_AREA
] = wrap_row_used
;
19786 row
->ascent
= wrap_row_ascent
;
19787 row
->height
= wrap_row_height
;
19788 row
->phys_ascent
= wrap_row_phys_ascent
;
19789 row
->phys_height
= wrap_row_phys_height
;
19790 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
19791 min_pos
= wrap_row_min_pos
;
19792 min_bpos
= wrap_row_min_bpos
;
19793 max_pos
= wrap_row_max_pos
;
19794 max_bpos
= wrap_row_max_bpos
;
19795 row
->continued_p
= 1;
19796 row
->ends_at_zv_p
= 0;
19797 row
->exact_window_width_line_p
= 0;
19798 it
->continuation_lines_width
+= x
;
19800 /* Make sure that a non-default face is extended
19801 up to the right margin of the window. */
19802 extend_face_to_end_of_line (it
);
19804 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
19806 /* A TAB that extends past the right edge of the
19807 window. This produces a single glyph on
19808 window system frames. We leave the glyph in
19809 this row and let it fill the row, but don't
19810 consume the TAB. */
19811 if ((row
->reversed_p
19812 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19813 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19814 produce_special_glyphs (it
, IT_CONTINUATION
);
19815 it
->continuation_lines_width
+= it
->last_visible_x
;
19816 row
->ends_in_middle_of_char_p
= 1;
19817 row
->continued_p
= 1;
19818 glyph
->pixel_width
= it
->last_visible_x
- x
;
19819 it
->starts_in_middle_of_char_p
= 1;
19823 /* Something other than a TAB that draws past
19824 the right edge of the window. Restore
19825 positions to values before the element. */
19826 if (row
->reversed_p
)
19827 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19828 - (n_glyphs_before
+ i
));
19829 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
19831 /* Display continuation glyphs. */
19832 it
->current_x
= x_before
;
19833 it
->continuation_lines_width
+= x
;
19834 if (!FRAME_WINDOW_P (it
->f
)
19835 || (row
->reversed_p
19836 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19837 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19838 produce_special_glyphs (it
, IT_CONTINUATION
);
19839 row
->continued_p
= 1;
19841 extend_face_to_end_of_line (it
);
19843 if (nglyphs
> 1 && i
> 0)
19845 row
->ends_in_middle_of_char_p
= 1;
19846 it
->starts_in_middle_of_char_p
= 1;
19849 /* Restore the height to what it was before the
19850 element not fitting on the line. */
19851 it
->max_ascent
= ascent
;
19852 it
->max_descent
= descent
;
19853 it
->max_phys_ascent
= phys_ascent
;
19854 it
->max_phys_descent
= phys_descent
;
19859 else if (new_x
> it
->first_visible_x
)
19861 /* Increment number of glyphs actually displayed. */
19864 /* Record the maximum and minimum buffer positions
19865 seen so far in glyphs that will be displayed by
19868 RECORD_MAX_MIN_POS (it
);
19870 if (x
< it
->first_visible_x
)
19871 /* Glyph is partially visible, i.e. row starts at
19872 negative X position. */
19873 row
->x
= x
- it
->first_visible_x
;
19877 /* Glyph is completely off the left margin of the
19878 window. This should not happen because of the
19879 move_it_in_display_line at the start of this
19880 function, unless the text display area of the
19881 window is empty. */
19882 eassert (it
->first_visible_x
<= it
->last_visible_x
);
19885 /* Even if this display element produced no glyphs at all,
19886 we want to record its position. */
19887 if (it
->bidi_p
&& nglyphs
== 0)
19888 RECORD_MAX_MIN_POS (it
);
19890 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19891 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19892 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19893 row
->phys_height
= max (row
->phys_height
,
19894 it
->max_phys_ascent
+ it
->max_phys_descent
);
19895 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19896 it
->max_extra_line_spacing
);
19898 /* End of this display line if row is continued. */
19899 if (row
->continued_p
|| row
->ends_at_zv_p
)
19904 /* Is this a line end? If yes, we're also done, after making
19905 sure that a non-default face is extended up to the right
19906 margin of the window. */
19907 if (ITERATOR_AT_END_OF_LINE_P (it
))
19909 int used_before
= row
->used
[TEXT_AREA
];
19911 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
19913 /* Add a space at the end of the line that is used to
19914 display the cursor there. */
19915 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19916 append_space_for_newline (it
, 0);
19918 /* Extend the face to the end of the line. */
19919 extend_face_to_end_of_line (it
);
19921 /* Make sure we have the position. */
19922 if (used_before
== 0)
19923 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
19925 /* Record the position of the newline, for use in
19927 it
->eol_pos
= it
->current
.pos
;
19929 /* Consume the line end. This skips over invisible lines. */
19930 set_iterator_to_next (it
, 1);
19931 it
->continuation_lines_width
= 0;
19935 /* Proceed with next display element. Note that this skips
19936 over lines invisible because of selective display. */
19937 set_iterator_to_next (it
, 1);
19939 /* If we truncate lines, we are done when the last displayed
19940 glyphs reach past the right margin of the window. */
19941 if (it
->line_wrap
== TRUNCATE
19942 && (FRAME_WINDOW_P (it
->f
) && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
19943 ? (it
->current_x
>= it
->last_visible_x
)
19944 : (it
->current_x
> it
->last_visible_x
)))
19946 /* Maybe add truncation glyphs. */
19947 if (!FRAME_WINDOW_P (it
->f
)
19948 || (row
->reversed_p
19949 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19950 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19954 if (!row
->reversed_p
)
19956 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
19957 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19962 for (i
= 0; i
< row
->used
[TEXT_AREA
]; i
++)
19963 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19965 /* Remove any padding glyphs at the front of ROW, to
19966 make room for the truncation glyphs we will be
19967 adding below. The loop below always inserts at
19968 least one truncation glyph, so also remove the
19969 last glyph added to ROW. */
19970 unproduce_glyphs (it
, i
+ 1);
19971 /* Adjust i for the loop below. */
19972 i
= row
->used
[TEXT_AREA
] - (i
+ 1);
19975 it
->current_x
= x_before
;
19976 if (!FRAME_WINDOW_P (it
->f
))
19978 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
19980 row
->used
[TEXT_AREA
] = i
;
19981 produce_special_glyphs (it
, IT_TRUNCATION
);
19986 row
->used
[TEXT_AREA
] = i
;
19987 produce_special_glyphs (it
, IT_TRUNCATION
);
19990 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19992 /* Don't truncate if we can overflow newline into fringe. */
19993 if (!get_next_display_element (it
))
19995 it
->continuation_lines_width
= 0;
19996 row
->ends_at_zv_p
= 1;
19997 row
->exact_window_width_line_p
= 1;
20000 if (ITERATOR_AT_END_OF_LINE_P (it
))
20002 row
->exact_window_width_line_p
= 1;
20003 goto at_end_of_line
;
20005 it
->current_x
= x_before
;
20008 row
->truncated_on_right_p
= 1;
20009 it
->continuation_lines_width
= 0;
20010 reseat_at_next_visible_line_start (it
, 0);
20011 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
20012 it
->hpos
= hpos_before
;
20018 bidi_unshelve_cache (wrap_data
, 1);
20020 /* If line is not empty and hscrolled, maybe insert truncation glyphs
20021 at the left window margin. */
20022 if (it
->first_visible_x
20023 && IT_CHARPOS (*it
) != CHARPOS (row
->start
.pos
))
20025 if (!FRAME_WINDOW_P (it
->f
)
20026 || (row
->reversed_p
20027 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
20028 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
20029 insert_left_trunc_glyphs (it
);
20030 row
->truncated_on_left_p
= 1;
20033 /* Remember the position at which this line ends.
20035 BIDI Note: any code that needs MATRIX_ROW_START/END_CHARPOS
20036 cannot be before the call to find_row_edges below, since that is
20037 where these positions are determined. */
20038 row
->end
= it
->current
;
20041 row
->minpos
= row
->start
.pos
;
20042 row
->maxpos
= row
->end
.pos
;
20046 /* ROW->minpos and ROW->maxpos must be the smallest and
20047 `1 + the largest' buffer positions in ROW. But if ROW was
20048 bidi-reordered, these two positions can be anywhere in the
20049 row, so we must determine them now. */
20050 find_row_edges (it
, row
, min_pos
, min_bpos
, max_pos
, max_bpos
);
20053 /* If the start of this line is the overlay arrow-position, then
20054 mark this glyph row as the one containing the overlay arrow.
20055 This is clearly a mess with variable size fonts. It would be
20056 better to let it be displayed like cursors under X. */
20057 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
20058 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
20059 !NILP (overlay_arrow_string
)))
20061 /* Overlay arrow in window redisplay is a fringe bitmap. */
20062 if (STRINGP (overlay_arrow_string
))
20064 struct glyph_row
*arrow_row
20065 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
20066 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
20067 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
20068 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
20069 struct glyph
*p2
, *end
;
20071 /* Copy the arrow glyphs. */
20072 while (glyph
< arrow_end
)
20075 /* Throw away padding glyphs. */
20077 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
20078 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
20084 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
20089 eassert (INTEGERP (overlay_arrow_string
));
20090 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
20092 overlay_arrow_seen
= 1;
20095 /* Highlight trailing whitespace. */
20096 if (!NILP (Vshow_trailing_whitespace
))
20097 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
20099 /* Compute pixel dimensions of this line. */
20100 compute_line_metrics (it
);
20102 /* Implementation note: No changes in the glyphs of ROW or in their
20103 faces can be done past this point, because compute_line_metrics
20104 computes ROW's hash value and stores it within the glyph_row
20107 /* Record whether this row ends inside an ellipsis. */
20108 row
->ends_in_ellipsis_p
20109 = (it
->method
== GET_FROM_DISPLAY_VECTOR
20110 && it
->ellipsis_p
);
20112 /* Save fringe bitmaps in this row. */
20113 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
20114 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
20115 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
20116 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
20118 it
->left_user_fringe_bitmap
= 0;
20119 it
->left_user_fringe_face_id
= 0;
20120 it
->right_user_fringe_bitmap
= 0;
20121 it
->right_user_fringe_face_id
= 0;
20123 /* Maybe set the cursor. */
20124 cvpos
= it
->w
->cursor
.vpos
;
20126 /* In bidi-reordered rows, keep checking for proper cursor
20127 position even if one has been found already, because buffer
20128 positions in such rows change non-linearly with ROW->VPOS,
20129 when a line is continued. One exception: when we are at ZV,
20130 display cursor on the first suitable glyph row, since all
20131 the empty rows after that also have their position set to ZV. */
20132 /* FIXME: Revisit this when glyph ``spilling'' in continuation
20133 lines' rows is implemented for bidi-reordered rows. */
20135 && !MATRIX_ROW (it
->w
->desired_matrix
, cvpos
)->ends_at_zv_p
))
20136 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
20137 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
20138 && cursor_row_p (row
))
20139 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
20141 /* Prepare for the next line. This line starts horizontally at (X
20142 HPOS) = (0 0). Vertical positions are incremented. As a
20143 convenience for the caller, IT->glyph_row is set to the next
20145 it
->current_x
= it
->hpos
= 0;
20146 it
->current_y
+= row
->height
;
20147 SET_TEXT_POS (it
->eol_pos
, 0, 0);
20150 /* The next row should by default use the same value of the
20151 reversed_p flag as this one. set_iterator_to_next decides when
20152 it's a new paragraph, and PRODUCE_GLYPHS recomputes the value of
20153 the flag accordingly. */
20154 if (it
->glyph_row
< MATRIX_BOTTOM_TEXT_ROW (it
->w
->desired_matrix
, it
->w
))
20155 it
->glyph_row
->reversed_p
= row
->reversed_p
;
20156 it
->start
= row
->end
;
20157 return row
->displays_text_p
;
20159 #undef RECORD_MAX_MIN_POS
20162 DEFUN ("current-bidi-paragraph-direction", Fcurrent_bidi_paragraph_direction
,
20163 Scurrent_bidi_paragraph_direction
, 0, 1, 0,
20164 doc
: /* Return paragraph direction at point in BUFFER.
20165 Value is either `left-to-right' or `right-to-left'.
20166 If BUFFER is omitted or nil, it defaults to the current buffer.
20168 Paragraph direction determines how the text in the paragraph is displayed.
20169 In left-to-right paragraphs, text begins at the left margin of the window
20170 and the reading direction is generally left to right. In right-to-left
20171 paragraphs, text begins at the right margin and is read from right to left.
20173 See also `bidi-paragraph-direction'. */)
20174 (Lisp_Object buffer
)
20176 struct buffer
*buf
= current_buffer
;
20177 struct buffer
*old
= buf
;
20179 if (! NILP (buffer
))
20181 CHECK_BUFFER (buffer
);
20182 buf
= XBUFFER (buffer
);
20185 if (NILP (BVAR (buf
, bidi_display_reordering
))
20186 || NILP (BVAR (buf
, enable_multibyte_characters
))
20187 /* When we are loading loadup.el, the character property tables
20188 needed for bidi iteration are not yet available. */
20189 || !NILP (Vpurify_flag
))
20190 return Qleft_to_right
;
20191 else if (!NILP (BVAR (buf
, bidi_paragraph_direction
)))
20192 return BVAR (buf
, bidi_paragraph_direction
);
20195 /* Determine the direction from buffer text. We could try to
20196 use current_matrix if it is up to date, but this seems fast
20197 enough as it is. */
20198 struct bidi_it itb
;
20199 ptrdiff_t pos
= BUF_PT (buf
);
20200 ptrdiff_t bytepos
= BUF_PT_BYTE (buf
);
20202 void *itb_data
= bidi_shelve_cache ();
20204 set_buffer_temp (buf
);
20205 /* bidi_paragraph_init finds the base direction of the paragraph
20206 by searching forward from paragraph start. We need the base
20207 direction of the current or _previous_ paragraph, so we need
20208 to make sure we are within that paragraph. To that end, find
20209 the previous non-empty line. */
20210 if (pos
>= ZV
&& pos
> BEGV
)
20213 bytepos
= CHAR_TO_BYTE (pos
);
20215 if (fast_looking_at (build_string ("[\f\t ]*\n"),
20216 pos
, bytepos
, ZV
, ZV_BYTE
, Qnil
) > 0)
20218 while ((c
= FETCH_BYTE (bytepos
)) == '\n'
20219 || c
== ' ' || c
== '\t' || c
== '\f')
20221 if (bytepos
<= BEGV_BYTE
)
20226 while (!CHAR_HEAD_P (FETCH_BYTE (bytepos
)))
20229 bidi_init_it (pos
, bytepos
, FRAME_WINDOW_P (SELECTED_FRAME ()), &itb
);
20230 itb
.paragraph_dir
= NEUTRAL_DIR
;
20231 itb
.string
.s
= NULL
;
20232 itb
.string
.lstring
= Qnil
;
20233 itb
.string
.bufpos
= 0;
20234 itb
.string
.unibyte
= 0;
20235 bidi_paragraph_init (NEUTRAL_DIR
, &itb
, 1);
20236 bidi_unshelve_cache (itb_data
, 0);
20237 set_buffer_temp (old
);
20238 switch (itb
.paragraph_dir
)
20241 return Qleft_to_right
;
20244 return Qright_to_left
;
20254 /***********************************************************************
20256 ***********************************************************************/
20258 /* Redisplay the menu bar in the frame for window W.
20260 The menu bar of X frames that don't have X toolkit support is
20261 displayed in a special window W->frame->menu_bar_window.
20263 The menu bar of terminal frames is treated specially as far as
20264 glyph matrices are concerned. Menu bar lines are not part of
20265 windows, so the update is done directly on the frame matrix rows
20266 for the menu bar. */
20269 display_menu_bar (struct window
*w
)
20271 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20276 /* Don't do all this for graphical frames. */
20278 if (FRAME_W32_P (f
))
20281 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
20287 if (FRAME_NS_P (f
))
20289 #endif /* HAVE_NS */
20291 #ifdef USE_X_TOOLKIT
20292 eassert (!FRAME_WINDOW_P (f
));
20293 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
20294 it
.first_visible_x
= 0;
20295 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
20296 #else /* not USE_X_TOOLKIT */
20297 if (FRAME_WINDOW_P (f
))
20299 /* Menu bar lines are displayed in the desired matrix of the
20300 dummy window menu_bar_window. */
20301 struct window
*menu_w
;
20302 eassert (WINDOWP (f
->menu_bar_window
));
20303 menu_w
= XWINDOW (f
->menu_bar_window
);
20304 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
20306 it
.first_visible_x
= 0;
20307 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
20311 /* This is a TTY frame, i.e. character hpos/vpos are used as
20313 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
20315 it
.first_visible_x
= 0;
20316 it
.last_visible_x
= FRAME_COLS (f
);
20318 #endif /* not USE_X_TOOLKIT */
20320 /* FIXME: This should be controlled by a user option. See the
20321 comments in redisplay_tool_bar and display_mode_line about
20323 it
.paragraph_embedding
= L2R
;
20325 /* Clear all rows of the menu bar. */
20326 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
20328 struct glyph_row
*row
= it
.glyph_row
+ i
;
20329 clear_glyph_row (row
);
20330 row
->enabled_p
= 1;
20331 row
->full_width_p
= 1;
20334 /* Display all items of the menu bar. */
20335 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
20336 for (i
= 0; i
< ASIZE (items
); i
+= 4)
20338 Lisp_Object string
;
20340 /* Stop at nil string. */
20341 string
= AREF (items
, i
+ 1);
20345 /* Remember where item was displayed. */
20346 ASET (items
, i
+ 3, make_number (it
.hpos
));
20348 /* Display the item, pad with one space. */
20349 if (it
.current_x
< it
.last_visible_x
)
20350 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
20351 SCHARS (string
) + 1, 0, 0, -1);
20354 /* Fill out the line with spaces. */
20355 if (it
.current_x
< it
.last_visible_x
)
20356 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
20358 /* Compute the total height of the lines. */
20359 compute_line_metrics (&it
);
20364 /***********************************************************************
20366 ***********************************************************************/
20368 /* Redisplay mode lines in the window tree whose root is WINDOW. If
20369 FORCE is non-zero, redisplay mode lines unconditionally.
20370 Otherwise, redisplay only mode lines that are garbaged. Value is
20371 the number of windows whose mode lines were redisplayed. */
20374 redisplay_mode_lines (Lisp_Object window
, int force
)
20378 while (!NILP (window
))
20380 struct window
*w
= XWINDOW (window
);
20382 if (WINDOWP (w
->hchild
))
20383 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
20384 else if (WINDOWP (w
->vchild
))
20385 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
20387 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
20388 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
20390 struct text_pos lpoint
;
20391 struct buffer
*old
= current_buffer
;
20393 /* Set the window's buffer for the mode line display. */
20394 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
20395 set_buffer_internal_1 (XBUFFER (w
->buffer
));
20397 /* Point refers normally to the selected window. For any
20398 other window, set up appropriate value. */
20399 if (!EQ (window
, selected_window
))
20401 struct text_pos pt
;
20403 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
20404 if (CHARPOS (pt
) < BEGV
)
20405 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
20406 else if (CHARPOS (pt
) > (ZV
- 1))
20407 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
20409 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
20412 /* Display mode lines. */
20413 clear_glyph_matrix (w
->desired_matrix
);
20414 if (display_mode_lines (w
))
20417 w
->must_be_updated_p
= 1;
20420 /* Restore old settings. */
20421 set_buffer_internal_1 (old
);
20422 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
20432 /* Display the mode and/or header line of window W. Value is the
20433 sum number of mode lines and header lines displayed. */
20436 display_mode_lines (struct window
*w
)
20438 Lisp_Object old_selected_window
, old_selected_frame
;
20441 old_selected_frame
= selected_frame
;
20442 selected_frame
= w
->frame
;
20443 old_selected_window
= selected_window
;
20444 XSETWINDOW (selected_window
, w
);
20446 /* These will be set while the mode line specs are processed. */
20447 line_number_displayed
= 0;
20448 wset_column_number_displayed (w
, Qnil
);
20450 if (WINDOW_WANTS_MODELINE_P (w
))
20452 struct window
*sel_w
= XWINDOW (old_selected_window
);
20454 /* Select mode line face based on the real selected window. */
20455 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
20456 BVAR (current_buffer
, mode_line_format
));
20460 if (WINDOW_WANTS_HEADER_LINE_P (w
))
20462 display_mode_line (w
, HEADER_LINE_FACE_ID
,
20463 BVAR (current_buffer
, header_line_format
));
20467 selected_frame
= old_selected_frame
;
20468 selected_window
= old_selected_window
;
20473 /* Display mode or header line of window W. FACE_ID specifies which
20474 line to display; it is either MODE_LINE_FACE_ID or
20475 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
20476 display. Value is the pixel height of the mode/header line
20480 display_mode_line (struct window
*w
, enum face_id face_id
, Lisp_Object format
)
20484 ptrdiff_t count
= SPECPDL_INDEX ();
20486 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
20487 /* Don't extend on a previously drawn mode-line.
20488 This may happen if called from pos_visible_p. */
20489 it
.glyph_row
->enabled_p
= 0;
20490 prepare_desired_row (it
.glyph_row
);
20492 it
.glyph_row
->mode_line_p
= 1;
20494 /* FIXME: This should be controlled by a user option. But
20495 supporting such an option is not trivial, since the mode line is
20496 made up of many separate strings. */
20497 it
.paragraph_embedding
= L2R
;
20499 record_unwind_protect (unwind_format_mode_line
,
20500 format_mode_line_unwind_data (NULL
, NULL
, Qnil
, 0));
20502 mode_line_target
= MODE_LINE_DISPLAY
;
20504 /* Temporarily make frame's keyboard the current kboard so that
20505 kboard-local variables in the mode_line_format will get the right
20507 push_kboard (FRAME_KBOARD (it
.f
));
20508 record_unwind_save_match_data ();
20509 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
20512 unbind_to (count
, Qnil
);
20514 /* Fill up with spaces. */
20515 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
20517 compute_line_metrics (&it
);
20518 it
.glyph_row
->full_width_p
= 1;
20519 it
.glyph_row
->continued_p
= 0;
20520 it
.glyph_row
->truncated_on_left_p
= 0;
20521 it
.glyph_row
->truncated_on_right_p
= 0;
20523 /* Make a 3D mode-line have a shadow at its right end. */
20524 face
= FACE_FROM_ID (it
.f
, face_id
);
20525 extend_face_to_end_of_line (&it
);
20526 if (face
->box
!= FACE_NO_BOX
)
20528 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
20529 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
20530 last
->right_box_line_p
= 1;
20533 return it
.glyph_row
->height
;
20536 /* Move element ELT in LIST to the front of LIST.
20537 Return the updated list. */
20540 move_elt_to_front (Lisp_Object elt
, Lisp_Object list
)
20542 register Lisp_Object tail
, prev
;
20543 register Lisp_Object tem
;
20547 while (CONSP (tail
))
20553 /* Splice out the link TAIL. */
20555 list
= XCDR (tail
);
20557 Fsetcdr (prev
, XCDR (tail
));
20559 /* Now make it the first. */
20560 Fsetcdr (tail
, list
);
20565 tail
= XCDR (tail
);
20569 /* Not found--return unchanged LIST. */
20573 /* Contribute ELT to the mode line for window IT->w. How it
20574 translates into text depends on its data type.
20576 IT describes the display environment in which we display, as usual.
20578 DEPTH is the depth in recursion. It is used to prevent
20579 infinite recursion here.
20581 FIELD_WIDTH is the number of characters the display of ELT should
20582 occupy in the mode line, and PRECISION is the maximum number of
20583 characters to display from ELT's representation. See
20584 display_string for details.
20586 Returns the hpos of the end of the text generated by ELT.
20588 PROPS is a property list to add to any string we encounter.
20590 If RISKY is nonzero, remove (disregard) any properties in any string
20591 we encounter, and ignore :eval and :propertize.
20593 The global variable `mode_line_target' determines whether the
20594 output is passed to `store_mode_line_noprop',
20595 `store_mode_line_string', or `display_string'. */
20598 display_mode_element (struct it
*it
, int depth
, int field_width
, int precision
,
20599 Lisp_Object elt
, Lisp_Object props
, int risky
)
20601 int n
= 0, field
, prec
;
20606 elt
= build_string ("*too-deep*");
20610 switch (XTYPE (elt
))
20614 /* A string: output it and check for %-constructs within it. */
20616 ptrdiff_t offset
= 0;
20618 if (SCHARS (elt
) > 0
20619 && (!NILP (props
) || risky
))
20621 Lisp_Object oprops
, aelt
;
20622 oprops
= Ftext_properties_at (make_number (0), elt
);
20624 /* If the starting string's properties are not what
20625 we want, translate the string. Also, if the string
20626 is risky, do that anyway. */
20628 if (NILP (Fequal (props
, oprops
)) || risky
)
20630 /* If the starting string has properties,
20631 merge the specified ones onto the existing ones. */
20632 if (! NILP (oprops
) && !risky
)
20636 oprops
= Fcopy_sequence (oprops
);
20638 while (CONSP (tem
))
20640 oprops
= Fplist_put (oprops
, XCAR (tem
),
20641 XCAR (XCDR (tem
)));
20642 tem
= XCDR (XCDR (tem
));
20647 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
20648 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
20650 /* AELT is what we want. Move it to the front
20651 without consing. */
20653 mode_line_proptrans_alist
20654 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
20660 /* If AELT has the wrong props, it is useless.
20661 so get rid of it. */
20663 mode_line_proptrans_alist
20664 = Fdelq (aelt
, mode_line_proptrans_alist
);
20666 elt
= Fcopy_sequence (elt
);
20667 Fset_text_properties (make_number (0), Flength (elt
),
20669 /* Add this item to mode_line_proptrans_alist. */
20670 mode_line_proptrans_alist
20671 = Fcons (Fcons (elt
, props
),
20672 mode_line_proptrans_alist
);
20673 /* Truncate mode_line_proptrans_alist
20674 to at most 50 elements. */
20675 tem
= Fnthcdr (make_number (50),
20676 mode_line_proptrans_alist
);
20678 XSETCDR (tem
, Qnil
);
20687 prec
= precision
- n
;
20688 switch (mode_line_target
)
20690 case MODE_LINE_NOPROP
:
20691 case MODE_LINE_TITLE
:
20692 n
+= store_mode_line_noprop (SSDATA (elt
), -1, prec
);
20694 case MODE_LINE_STRING
:
20695 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
20697 case MODE_LINE_DISPLAY
:
20698 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
20699 0, prec
, 0, STRING_MULTIBYTE (elt
));
20706 /* Handle the non-literal case. */
20708 while ((precision
<= 0 || n
< precision
)
20709 && SREF (elt
, offset
) != 0
20710 && (mode_line_target
!= MODE_LINE_DISPLAY
20711 || it
->current_x
< it
->last_visible_x
))
20713 ptrdiff_t last_offset
= offset
;
20715 /* Advance to end of string or next format specifier. */
20716 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
20719 if (offset
- 1 != last_offset
)
20721 ptrdiff_t nchars
, nbytes
;
20723 /* Output to end of string or up to '%'. Field width
20724 is length of string. Don't output more than
20725 PRECISION allows us. */
20728 prec
= c_string_width (SDATA (elt
) + last_offset
,
20729 offset
- last_offset
, precision
- n
,
20732 switch (mode_line_target
)
20734 case MODE_LINE_NOPROP
:
20735 case MODE_LINE_TITLE
:
20736 n
+= store_mode_line_noprop (SSDATA (elt
) + last_offset
, 0, prec
);
20738 case MODE_LINE_STRING
:
20740 ptrdiff_t bytepos
= last_offset
;
20741 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
20742 ptrdiff_t endpos
= (precision
<= 0
20743 ? string_byte_to_char (elt
, offset
)
20744 : charpos
+ nchars
);
20746 n
+= store_mode_line_string (NULL
,
20747 Fsubstring (elt
, make_number (charpos
),
20748 make_number (endpos
)),
20752 case MODE_LINE_DISPLAY
:
20754 ptrdiff_t bytepos
= last_offset
;
20755 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
20757 if (precision
<= 0)
20758 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
20759 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
20761 STRING_MULTIBYTE (elt
));
20766 else /* c == '%' */
20768 ptrdiff_t percent_position
= offset
;
20770 /* Get the specified minimum width. Zero means
20773 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
20774 field
= field
* 10 + c
- '0';
20776 /* Don't pad beyond the total padding allowed. */
20777 if (field_width
- n
> 0 && field
> field_width
- n
)
20778 field
= field_width
- n
;
20780 /* Note that either PRECISION <= 0 or N < PRECISION. */
20781 prec
= precision
- n
;
20784 n
+= display_mode_element (it
, depth
, field
, prec
,
20785 Vglobal_mode_string
, props
,
20790 ptrdiff_t bytepos
, charpos
;
20792 Lisp_Object string
;
20794 bytepos
= percent_position
;
20795 charpos
= (STRING_MULTIBYTE (elt
)
20796 ? string_byte_to_char (elt
, bytepos
)
20798 spec
= decode_mode_spec (it
->w
, c
, field
, &string
);
20799 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
20801 switch (mode_line_target
)
20803 case MODE_LINE_NOPROP
:
20804 case MODE_LINE_TITLE
:
20805 n
+= store_mode_line_noprop (spec
, field
, prec
);
20807 case MODE_LINE_STRING
:
20809 Lisp_Object tem
= build_string (spec
);
20810 props
= Ftext_properties_at (make_number (charpos
), elt
);
20811 /* Should only keep face property in props */
20812 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
20815 case MODE_LINE_DISPLAY
:
20817 int nglyphs_before
, nwritten
;
20819 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
20820 nwritten
= display_string (spec
, string
, elt
,
20825 /* Assign to the glyphs written above the
20826 string where the `%x' came from, position
20830 struct glyph
*glyph
20831 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
20835 for (i
= 0; i
< nwritten
; ++i
)
20837 glyph
[i
].object
= elt
;
20838 glyph
[i
].charpos
= charpos
;
20855 /* A symbol: process the value of the symbol recursively
20856 as if it appeared here directly. Avoid error if symbol void.
20857 Special case: if value of symbol is a string, output the string
20860 register Lisp_Object tem
;
20862 /* If the variable is not marked as risky to set
20863 then its contents are risky to use. */
20864 if (NILP (Fget (elt
, Qrisky_local_variable
)))
20867 tem
= Fboundp (elt
);
20870 tem
= Fsymbol_value (elt
);
20871 /* If value is a string, output that string literally:
20872 don't check for % within it. */
20876 if (!EQ (tem
, elt
))
20878 /* Give up right away for nil or t. */
20888 register Lisp_Object car
, tem
;
20890 /* A cons cell: five distinct cases.
20891 If first element is :eval or :propertize, do something special.
20892 If first element is a string or a cons, process all the elements
20893 and effectively concatenate them.
20894 If first element is a negative number, truncate displaying cdr to
20895 at most that many characters. If positive, pad (with spaces)
20896 to at least that many characters.
20897 If first element is a symbol, process the cadr or caddr recursively
20898 according to whether the symbol's value is non-nil or nil. */
20900 if (EQ (car
, QCeval
))
20902 /* An element of the form (:eval FORM) means evaluate FORM
20903 and use the result as mode line elements. */
20908 if (CONSP (XCDR (elt
)))
20911 spec
= safe_eval (XCAR (XCDR (elt
)));
20912 n
+= display_mode_element (it
, depth
, field_width
- n
,
20913 precision
- n
, spec
, props
,
20917 else if (EQ (car
, QCpropertize
))
20919 /* An element of the form (:propertize ELT PROPS...)
20920 means display ELT but applying properties PROPS. */
20925 if (CONSP (XCDR (elt
)))
20926 n
+= display_mode_element (it
, depth
, field_width
- n
,
20927 precision
- n
, XCAR (XCDR (elt
)),
20928 XCDR (XCDR (elt
)), risky
);
20930 else if (SYMBOLP (car
))
20932 tem
= Fboundp (car
);
20936 /* elt is now the cdr, and we know it is a cons cell.
20937 Use its car if CAR has a non-nil value. */
20940 tem
= Fsymbol_value (car
);
20947 /* Symbol's value is nil (or symbol is unbound)
20948 Get the cddr of the original list
20949 and if possible find the caddr and use that. */
20953 else if (!CONSP (elt
))
20958 else if (INTEGERP (car
))
20960 register int lim
= XINT (car
);
20964 /* Negative int means reduce maximum width. */
20965 if (precision
<= 0)
20968 precision
= min (precision
, -lim
);
20972 /* Padding specified. Don't let it be more than
20973 current maximum. */
20975 lim
= min (precision
, lim
);
20977 /* If that's more padding than already wanted, queue it.
20978 But don't reduce padding already specified even if
20979 that is beyond the current truncation point. */
20980 field_width
= max (lim
, field_width
);
20984 else if (STRINGP (car
) || CONSP (car
))
20986 Lisp_Object halftail
= elt
;
20990 && (precision
<= 0 || n
< precision
))
20992 n
+= display_mode_element (it
, depth
,
20993 /* Do padding only after the last
20994 element in the list. */
20995 (! CONSP (XCDR (elt
))
20998 precision
- n
, XCAR (elt
),
21002 if ((len
& 1) == 0)
21003 halftail
= XCDR (halftail
);
21004 /* Check for cycle. */
21005 if (EQ (halftail
, elt
))
21014 elt
= build_string ("*invalid*");
21018 /* Pad to FIELD_WIDTH. */
21019 if (field_width
> 0 && n
< field_width
)
21021 switch (mode_line_target
)
21023 case MODE_LINE_NOPROP
:
21024 case MODE_LINE_TITLE
:
21025 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
21027 case MODE_LINE_STRING
:
21028 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
21030 case MODE_LINE_DISPLAY
:
21031 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
21040 /* Store a mode-line string element in mode_line_string_list.
21042 If STRING is non-null, display that C string. Otherwise, the Lisp
21043 string LISP_STRING is displayed.
21045 FIELD_WIDTH is the minimum number of output glyphs to produce.
21046 If STRING has fewer characters than FIELD_WIDTH, pad to the right
21047 with spaces. FIELD_WIDTH <= 0 means don't pad.
21049 PRECISION is the maximum number of characters to output from
21050 STRING. PRECISION <= 0 means don't truncate the string.
21052 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
21053 properties to the string.
21055 PROPS are the properties to add to the string.
21056 The mode_line_string_face face property is always added to the string.
21060 store_mode_line_string (const char *string
, Lisp_Object lisp_string
, int copy_string
,
21061 int field_width
, int precision
, Lisp_Object props
)
21066 if (string
!= NULL
)
21068 len
= strlen (string
);
21069 if (precision
> 0 && len
> precision
)
21071 lisp_string
= make_string (string
, len
);
21073 props
= mode_line_string_face_prop
;
21074 else if (!NILP (mode_line_string_face
))
21076 Lisp_Object face
= Fplist_get (props
, Qface
);
21077 props
= Fcopy_sequence (props
);
21079 face
= mode_line_string_face
;
21081 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
21082 props
= Fplist_put (props
, Qface
, face
);
21084 Fadd_text_properties (make_number (0), make_number (len
),
21085 props
, lisp_string
);
21089 len
= XFASTINT (Flength (lisp_string
));
21090 if (precision
> 0 && len
> precision
)
21093 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
21096 if (!NILP (mode_line_string_face
))
21100 props
= Ftext_properties_at (make_number (0), lisp_string
);
21101 face
= Fplist_get (props
, Qface
);
21103 face
= mode_line_string_face
;
21105 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
21106 props
= Fcons (Qface
, Fcons (face
, Qnil
));
21108 lisp_string
= Fcopy_sequence (lisp_string
);
21111 Fadd_text_properties (make_number (0), make_number (len
),
21112 props
, lisp_string
);
21117 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
21121 if (field_width
> len
)
21123 field_width
-= len
;
21124 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
21126 Fadd_text_properties (make_number (0), make_number (field_width
),
21127 props
, lisp_string
);
21128 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
21136 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
21138 doc
: /* Format a string out of a mode line format specification.
21139 First arg FORMAT specifies the mode line format (see `mode-line-format'
21140 for details) to use.
21142 By default, the format is evaluated for the currently selected window.
21144 Optional second arg FACE specifies the face property to put on all
21145 characters for which no face is specified. The value nil means the
21146 default face. The value t means whatever face the window's mode line
21147 currently uses (either `mode-line' or `mode-line-inactive',
21148 depending on whether the window is the selected window or not).
21149 An integer value means the value string has no text
21152 Optional third and fourth args WINDOW and BUFFER specify the window
21153 and buffer to use as the context for the formatting (defaults
21154 are the selected window and the WINDOW's buffer). */)
21155 (Lisp_Object format
, Lisp_Object face
,
21156 Lisp_Object window
, Lisp_Object buffer
)
21161 struct buffer
*old_buffer
= NULL
;
21163 int no_props
= INTEGERP (face
);
21164 ptrdiff_t count
= SPECPDL_INDEX ();
21166 int string_start
= 0;
21168 w
= decode_any_window (window
);
21169 XSETWINDOW (window
, w
);
21172 buffer
= w
->buffer
;
21173 CHECK_BUFFER (buffer
);
21175 /* Make formatting the modeline a non-op when noninteractive, otherwise
21176 there will be problems later caused by a partially initialized frame. */
21177 if (NILP (format
) || noninteractive
)
21178 return empty_unibyte_string
;
21183 face_id
= (NILP (face
) || EQ (face
, Qdefault
)) ? DEFAULT_FACE_ID
21184 : EQ (face
, Qt
) ? (EQ (window
, selected_window
)
21185 ? MODE_LINE_FACE_ID
: MODE_LINE_INACTIVE_FACE_ID
)
21186 : EQ (face
, Qmode_line
) ? MODE_LINE_FACE_ID
21187 : EQ (face
, Qmode_line_inactive
) ? MODE_LINE_INACTIVE_FACE_ID
21188 : EQ (face
, Qheader_line
) ? HEADER_LINE_FACE_ID
21189 : EQ (face
, Qtool_bar
) ? TOOL_BAR_FACE_ID
21192 old_buffer
= current_buffer
;
21194 /* Save things including mode_line_proptrans_alist,
21195 and set that to nil so that we don't alter the outer value. */
21196 record_unwind_protect (unwind_format_mode_line
,
21197 format_mode_line_unwind_data
21198 (XFRAME (WINDOW_FRAME (w
)),
21199 old_buffer
, selected_window
, 1));
21200 mode_line_proptrans_alist
= Qnil
;
21202 Fselect_window (window
, Qt
);
21203 set_buffer_internal_1 (XBUFFER (buffer
));
21205 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
21209 mode_line_target
= MODE_LINE_NOPROP
;
21210 mode_line_string_face_prop
= Qnil
;
21211 mode_line_string_list
= Qnil
;
21212 string_start
= MODE_LINE_NOPROP_LEN (0);
21216 mode_line_target
= MODE_LINE_STRING
;
21217 mode_line_string_list
= Qnil
;
21218 mode_line_string_face
= face
;
21219 mode_line_string_face_prop
21220 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
21223 push_kboard (FRAME_KBOARD (it
.f
));
21224 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
21229 len
= MODE_LINE_NOPROP_LEN (string_start
);
21230 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
21234 mode_line_string_list
= Fnreverse (mode_line_string_list
);
21235 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
21236 empty_unibyte_string
);
21239 unbind_to (count
, Qnil
);
21243 /* Write a null-terminated, right justified decimal representation of
21244 the positive integer D to BUF using a minimal field width WIDTH. */
21247 pint2str (register char *buf
, register int width
, register ptrdiff_t d
)
21249 register char *p
= buf
;
21257 *p
++ = d
% 10 + '0';
21262 for (width
-= (int) (p
- buf
); width
> 0; --width
)
21273 /* Write a null-terminated, right justified decimal and "human
21274 readable" representation of the nonnegative integer D to BUF using
21275 a minimal field width WIDTH. D should be smaller than 999.5e24. */
21277 static const char power_letter
[] =
21291 pint2hrstr (char *buf
, int width
, ptrdiff_t d
)
21293 /* We aim to represent the nonnegative integer D as
21294 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
21295 ptrdiff_t quotient
= d
;
21297 /* -1 means: do not use TENTHS. */
21301 /* Length of QUOTIENT.TENTHS as a string. */
21307 if (1000 <= quotient
)
21309 /* Scale to the appropriate EXPONENT. */
21312 remainder
= quotient
% 1000;
21316 while (1000 <= quotient
);
21318 /* Round to nearest and decide whether to use TENTHS or not. */
21321 tenths
= remainder
/ 100;
21322 if (50 <= remainder
% 100)
21329 if (quotient
== 10)
21337 if (500 <= remainder
)
21339 if (quotient
< 999)
21350 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
21351 if (tenths
== -1 && quotient
<= 99)
21358 p
= psuffix
= buf
+ max (width
, length
);
21360 /* Print EXPONENT. */
21361 *psuffix
++ = power_letter
[exponent
];
21364 /* Print TENTHS. */
21367 *--p
= '0' + tenths
;
21371 /* Print QUOTIENT. */
21374 int digit
= quotient
% 10;
21375 *--p
= '0' + digit
;
21377 while ((quotient
/= 10) != 0);
21379 /* Print leading spaces. */
21384 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
21385 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
21386 type of CODING_SYSTEM. Return updated pointer into BUF. */
21388 static unsigned char invalid_eol_type
[] = "(*invalid*)";
21391 decode_mode_spec_coding (Lisp_Object coding_system
, register char *buf
, int eol_flag
)
21394 int multibyte
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
21395 const unsigned char *eol_str
;
21397 /* The EOL conversion we are using. */
21398 Lisp_Object eoltype
;
21400 val
= CODING_SYSTEM_SPEC (coding_system
);
21403 if (!VECTORP (val
)) /* Not yet decided. */
21405 *buf
++ = multibyte
? '-' : ' ';
21407 eoltype
= eol_mnemonic_undecided
;
21408 /* Don't mention EOL conversion if it isn't decided. */
21413 Lisp_Object eolvalue
;
21415 attrs
= AREF (val
, 0);
21416 eolvalue
= AREF (val
, 2);
21419 ? XFASTINT (CODING_ATTR_MNEMONIC (attrs
))
21424 /* The EOL conversion that is normal on this system. */
21426 if (NILP (eolvalue
)) /* Not yet decided. */
21427 eoltype
= eol_mnemonic_undecided
;
21428 else if (VECTORP (eolvalue
)) /* Not yet decided. */
21429 eoltype
= eol_mnemonic_undecided
;
21430 else /* eolvalue is Qunix, Qdos, or Qmac. */
21431 eoltype
= (EQ (eolvalue
, Qunix
)
21432 ? eol_mnemonic_unix
21433 : (EQ (eolvalue
, Qdos
) == 1
21434 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
21440 /* Mention the EOL conversion if it is not the usual one. */
21441 if (STRINGP (eoltype
))
21443 eol_str
= SDATA (eoltype
);
21444 eol_str_len
= SBYTES (eoltype
);
21446 else if (CHARACTERP (eoltype
))
21448 unsigned char *tmp
= alloca (MAX_MULTIBYTE_LENGTH
);
21449 int c
= XFASTINT (eoltype
);
21450 eol_str_len
= CHAR_STRING (c
, tmp
);
21455 eol_str
= invalid_eol_type
;
21456 eol_str_len
= sizeof (invalid_eol_type
) - 1;
21458 memcpy (buf
, eol_str
, eol_str_len
);
21459 buf
+= eol_str_len
;
21465 /* Return a string for the output of a mode line %-spec for window W,
21466 generated by character C. FIELD_WIDTH > 0 means pad the string
21467 returned with spaces to that value. Return a Lisp string in
21468 *STRING if the resulting string is taken from that Lisp string.
21470 Note we operate on the current buffer for most purposes,
21471 the exception being w->base_line_pos. */
21473 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
21475 static const char *
21476 decode_mode_spec (struct window
*w
, register int c
, int field_width
,
21477 Lisp_Object
*string
)
21480 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21481 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
21482 /* We are going to use f->decode_mode_spec_buffer as the buffer to
21483 produce strings from numerical values, so limit preposterously
21484 large values of FIELD_WIDTH to avoid overrunning the buffer's
21485 end. The size of the buffer is enough for FRAME_MESSAGE_BUF_SIZE
21486 bytes plus the terminating null. */
21487 int width
= min (field_width
, FRAME_MESSAGE_BUF_SIZE (f
));
21488 struct buffer
*b
= current_buffer
;
21496 if (!NILP (BVAR (b
, read_only
)))
21498 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21503 /* This differs from %* only for a modified read-only buffer. */
21504 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21506 if (!NILP (BVAR (b
, read_only
)))
21511 /* This differs from %* in ignoring read-only-ness. */
21512 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21524 if (command_loop_level
> 5)
21526 p
= decode_mode_spec_buf
;
21527 for (i
= 0; i
< command_loop_level
; i
++)
21530 return decode_mode_spec_buf
;
21538 if (command_loop_level
> 5)
21540 p
= decode_mode_spec_buf
;
21541 for (i
= 0; i
< command_loop_level
; i
++)
21544 return decode_mode_spec_buf
;
21551 /* Let lots_of_dashes be a string of infinite length. */
21552 if (mode_line_target
== MODE_LINE_NOPROP
||
21553 mode_line_target
== MODE_LINE_STRING
)
21555 if (field_width
<= 0
21556 || field_width
> sizeof (lots_of_dashes
))
21558 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
21559 decode_mode_spec_buf
[i
] = '-';
21560 decode_mode_spec_buf
[i
] = '\0';
21561 return decode_mode_spec_buf
;
21564 return lots_of_dashes
;
21568 obj
= BVAR (b
, name
);
21572 /* %c and %l are ignored in `frame-title-format'.
21573 (In redisplay_internal, the frame title is drawn _before_ the
21574 windows are updated, so the stuff which depends on actual
21575 window contents (such as %l) may fail to render properly, or
21576 even crash emacs.) */
21577 if (mode_line_target
== MODE_LINE_TITLE
)
21581 ptrdiff_t col
= current_column ();
21582 wset_column_number_displayed (w
, make_number (col
));
21583 pint2str (decode_mode_spec_buf
, width
, col
);
21584 return decode_mode_spec_buf
;
21588 #ifndef SYSTEM_MALLOC
21590 if (NILP (Vmemory_full
))
21593 return "!MEM FULL! ";
21600 /* %F displays the frame name. */
21601 if (!NILP (f
->title
))
21602 return SSDATA (f
->title
);
21603 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
21604 return SSDATA (f
->name
);
21608 obj
= BVAR (b
, filename
);
21613 ptrdiff_t size
= ZV
- BEGV
;
21614 pint2str (decode_mode_spec_buf
, width
, size
);
21615 return decode_mode_spec_buf
;
21620 ptrdiff_t size
= ZV
- BEGV
;
21621 pint2hrstr (decode_mode_spec_buf
, width
, size
);
21622 return decode_mode_spec_buf
;
21627 ptrdiff_t startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
21628 ptrdiff_t topline
, nlines
, height
;
21631 /* %c and %l are ignored in `frame-title-format'. */
21632 if (mode_line_target
== MODE_LINE_TITLE
)
21635 startpos
= XMARKER (w
->start
)->charpos
;
21636 startpos_byte
= marker_byte_position (w
->start
);
21637 height
= WINDOW_TOTAL_LINES (w
);
21639 /* If we decided that this buffer isn't suitable for line numbers,
21640 don't forget that too fast. */
21641 if (EQ (w
->base_line_pos
, w
->buffer
))
21643 /* But do forget it, if the window shows a different buffer now. */
21644 else if (BUFFERP (w
->base_line_pos
))
21645 wset_base_line_pos (w
, Qnil
);
21647 /* If the buffer is very big, don't waste time. */
21648 if (INTEGERP (Vline_number_display_limit
)
21649 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
21651 wset_base_line_pos (w
, Qnil
);
21652 wset_base_line_number (w
, Qnil
);
21656 if (INTEGERP (w
->base_line_number
)
21657 && INTEGERP (w
->base_line_pos
)
21658 && XFASTINT (w
->base_line_pos
) <= startpos
)
21660 line
= XFASTINT (w
->base_line_number
);
21661 linepos
= XFASTINT (w
->base_line_pos
);
21662 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
21667 linepos
= BUF_BEGV (b
);
21668 linepos_byte
= BUF_BEGV_BYTE (b
);
21671 /* Count lines from base line to window start position. */
21672 nlines
= display_count_lines (linepos_byte
,
21676 topline
= nlines
+ line
;
21678 /* Determine a new base line, if the old one is too close
21679 or too far away, or if we did not have one.
21680 "Too close" means it's plausible a scroll-down would
21681 go back past it. */
21682 if (startpos
== BUF_BEGV (b
))
21684 wset_base_line_number (w
, make_number (topline
));
21685 wset_base_line_pos (w
, make_number (BUF_BEGV (b
)));
21687 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
21688 || linepos
== BUF_BEGV (b
))
21690 ptrdiff_t limit
= BUF_BEGV (b
);
21691 ptrdiff_t limit_byte
= BUF_BEGV_BYTE (b
);
21692 ptrdiff_t position
;
21693 ptrdiff_t distance
=
21694 (height
* 2 + 30) * line_number_display_limit_width
;
21696 if (startpos
- distance
> limit
)
21698 limit
= startpos
- distance
;
21699 limit_byte
= CHAR_TO_BYTE (limit
);
21702 nlines
= display_count_lines (startpos_byte
,
21704 - (height
* 2 + 30),
21706 /* If we couldn't find the lines we wanted within
21707 line_number_display_limit_width chars per line,
21708 give up on line numbers for this window. */
21709 if (position
== limit_byte
&& limit
== startpos
- distance
)
21711 wset_base_line_pos (w
, w
->buffer
);
21712 wset_base_line_number (w
, Qnil
);
21716 wset_base_line_number (w
, make_number (topline
- nlines
));
21717 wset_base_line_pos (w
, make_number (BYTE_TO_CHAR (position
)));
21720 /* Now count lines from the start pos to point. */
21721 nlines
= display_count_lines (startpos_byte
,
21722 PT_BYTE
, PT
, &junk
);
21724 /* Record that we did display the line number. */
21725 line_number_displayed
= 1;
21727 /* Make the string to show. */
21728 pint2str (decode_mode_spec_buf
, width
, topline
+ nlines
);
21729 return decode_mode_spec_buf
;
21732 char* p
= decode_mode_spec_buf
;
21733 int pad
= width
- 2;
21739 return decode_mode_spec_buf
;
21745 obj
= BVAR (b
, mode_name
);
21749 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
21755 ptrdiff_t pos
= marker_position (w
->start
);
21756 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
21758 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
21760 if (pos
<= BUF_BEGV (b
))
21765 else if (pos
<= BUF_BEGV (b
))
21769 if (total
> 1000000)
21770 /* Do it differently for a large value, to avoid overflow. */
21771 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
21773 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
21774 /* We can't normally display a 3-digit number,
21775 so get us a 2-digit number that is close. */
21778 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
21779 return decode_mode_spec_buf
;
21783 /* Display percentage of size above the bottom of the screen. */
21786 ptrdiff_t toppos
= marker_position (w
->start
);
21787 ptrdiff_t botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
21788 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
21790 if (botpos
>= BUF_ZV (b
))
21792 if (toppos
<= BUF_BEGV (b
))
21799 if (total
> 1000000)
21800 /* Do it differently for a large value, to avoid overflow. */
21801 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
21803 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
21804 /* We can't normally display a 3-digit number,
21805 so get us a 2-digit number that is close. */
21808 if (toppos
<= BUF_BEGV (b
))
21809 sprintf (decode_mode_spec_buf
, "Top%2"pD
"d%%", total
);
21811 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
21812 return decode_mode_spec_buf
;
21817 /* status of process */
21818 obj
= Fget_buffer_process (Fcurrent_buffer ());
21820 return "no process";
21822 obj
= Fsymbol_name (Fprocess_status (obj
));
21828 ptrdiff_t count
= inhibit_garbage_collection ();
21829 Lisp_Object val
= call1 (intern ("file-remote-p"),
21830 BVAR (current_buffer
, directory
));
21831 unbind_to (count
, Qnil
);
21839 case 't': /* indicate TEXT or BINARY */
21843 /* coding-system (not including end-of-line format) */
21845 /* coding-system (including end-of-line type) */
21847 int eol_flag
= (c
== 'Z');
21848 char *p
= decode_mode_spec_buf
;
21850 if (! FRAME_WINDOW_P (f
))
21852 /* No need to mention EOL here--the terminal never needs
21853 to do EOL conversion. */
21854 p
= decode_mode_spec_coding (CODING_ID_NAME
21855 (FRAME_KEYBOARD_CODING (f
)->id
),
21857 p
= decode_mode_spec_coding (CODING_ID_NAME
21858 (FRAME_TERMINAL_CODING (f
)->id
),
21861 p
= decode_mode_spec_coding (BVAR (b
, buffer_file_coding_system
),
21864 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
21865 #ifdef subprocesses
21866 obj
= Fget_buffer_process (Fcurrent_buffer ());
21867 if (PROCESSP (obj
))
21869 p
= decode_mode_spec_coding
21870 (XPROCESS (obj
)->decode_coding_system
, p
, eol_flag
);
21871 p
= decode_mode_spec_coding
21872 (XPROCESS (obj
)->encode_coding_system
, p
, eol_flag
);
21874 #endif /* subprocesses */
21877 return decode_mode_spec_buf
;
21884 return SSDATA (obj
);
21891 /* Count up to COUNT lines starting from START_BYTE.
21892 But don't go beyond LIMIT_BYTE.
21893 Return the number of lines thus found (always nonnegative).
21895 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
21898 display_count_lines (ptrdiff_t start_byte
,
21899 ptrdiff_t limit_byte
, ptrdiff_t count
,
21900 ptrdiff_t *byte_pos_ptr
)
21902 register unsigned char *cursor
;
21903 unsigned char *base
;
21905 register ptrdiff_t ceiling
;
21906 register unsigned char *ceiling_addr
;
21907 ptrdiff_t orig_count
= count
;
21909 /* If we are not in selective display mode,
21910 check only for newlines. */
21911 int selective_display
= (!NILP (BVAR (current_buffer
, selective_display
))
21912 && !INTEGERP (BVAR (current_buffer
, selective_display
)));
21916 while (start_byte
< limit_byte
)
21918 ceiling
= BUFFER_CEILING_OF (start_byte
);
21919 ceiling
= min (limit_byte
- 1, ceiling
);
21920 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
21921 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
21924 if (selective_display
)
21925 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
21928 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
21931 if (cursor
!= ceiling_addr
)
21935 start_byte
+= cursor
- base
+ 1;
21936 *byte_pos_ptr
= start_byte
;
21940 if (++cursor
== ceiling_addr
)
21946 start_byte
+= cursor
- base
;
21951 while (start_byte
> limit_byte
)
21953 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
21954 ceiling
= max (limit_byte
, ceiling
);
21955 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
21956 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
21959 if (selective_display
)
21960 while (--cursor
!= ceiling_addr
21961 && *cursor
!= '\n' && *cursor
!= 015)
21964 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
21967 if (cursor
!= ceiling_addr
)
21971 start_byte
+= cursor
- base
+ 1;
21972 *byte_pos_ptr
= start_byte
;
21973 /* When scanning backwards, we should
21974 not count the newline posterior to which we stop. */
21975 return - orig_count
- 1;
21981 /* Here we add 1 to compensate for the last decrement
21982 of CURSOR, which took it past the valid range. */
21983 start_byte
+= cursor
- base
+ 1;
21987 *byte_pos_ptr
= limit_byte
;
21990 return - orig_count
+ count
;
21991 return orig_count
- count
;
21997 /***********************************************************************
21999 ***********************************************************************/
22001 /* Display a NUL-terminated string, starting with index START.
22003 If STRING is non-null, display that C string. Otherwise, the Lisp
22004 string LISP_STRING is displayed. There's a case that STRING is
22005 non-null and LISP_STRING is not nil. It means STRING is a string
22006 data of LISP_STRING. In that case, we display LISP_STRING while
22007 ignoring its text properties.
22009 If FACE_STRING is not nil, FACE_STRING_POS is a position in
22010 FACE_STRING. Display STRING or LISP_STRING with the face at
22011 FACE_STRING_POS in FACE_STRING:
22013 Display the string in the environment given by IT, but use the
22014 standard display table, temporarily.
22016 FIELD_WIDTH is the minimum number of output glyphs to produce.
22017 If STRING has fewer characters than FIELD_WIDTH, pad to the right
22018 with spaces. If STRING has more characters, more than FIELD_WIDTH
22019 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
22021 PRECISION is the maximum number of characters to output from
22022 STRING. PRECISION < 0 means don't truncate the string.
22024 This is roughly equivalent to printf format specifiers:
22026 FIELD_WIDTH PRECISION PRINTF
22027 ----------------------------------------
22033 MULTIBYTE zero means do not display multibyte chars, > 0 means do
22034 display them, and < 0 means obey the current buffer's value of
22035 enable_multibyte_characters.
22037 Value is the number of columns displayed. */
22040 display_string (const char *string
, Lisp_Object lisp_string
, Lisp_Object face_string
,
22041 ptrdiff_t face_string_pos
, ptrdiff_t start
, struct it
*it
,
22042 int field_width
, int precision
, int max_x
, int multibyte
)
22044 int hpos_at_start
= it
->hpos
;
22045 int saved_face_id
= it
->face_id
;
22046 struct glyph_row
*row
= it
->glyph_row
;
22047 ptrdiff_t it_charpos
;
22049 /* Initialize the iterator IT for iteration over STRING beginning
22050 with index START. */
22051 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
22052 precision
, field_width
, multibyte
);
22053 if (string
&& STRINGP (lisp_string
))
22054 /* LISP_STRING is the one returned by decode_mode_spec. We should
22055 ignore its text properties. */
22056 it
->stop_charpos
= it
->end_charpos
;
22058 /* If displaying STRING, set up the face of the iterator from
22059 FACE_STRING, if that's given. */
22060 if (STRINGP (face_string
))
22066 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
22067 0, it
->region_beg_charpos
,
22068 it
->region_end_charpos
,
22069 &endptr
, it
->base_face_id
, 0);
22070 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22071 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
22074 /* Set max_x to the maximum allowed X position. Don't let it go
22075 beyond the right edge of the window. */
22077 max_x
= it
->last_visible_x
;
22079 max_x
= min (max_x
, it
->last_visible_x
);
22081 /* Skip over display elements that are not visible. because IT->w is
22083 if (it
->current_x
< it
->first_visible_x
)
22084 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
22085 MOVE_TO_POS
| MOVE_TO_X
);
22087 row
->ascent
= it
->max_ascent
;
22088 row
->height
= it
->max_ascent
+ it
->max_descent
;
22089 row
->phys_ascent
= it
->max_phys_ascent
;
22090 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
22091 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
22093 if (STRINGP (it
->string
))
22094 it_charpos
= IT_STRING_CHARPOS (*it
);
22096 it_charpos
= IT_CHARPOS (*it
);
22098 /* This condition is for the case that we are called with current_x
22099 past last_visible_x. */
22100 while (it
->current_x
< max_x
)
22102 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
22104 /* Get the next display element. */
22105 if (!get_next_display_element (it
))
22108 /* Produce glyphs. */
22109 x_before
= it
->current_x
;
22110 n_glyphs_before
= row
->used
[TEXT_AREA
];
22111 PRODUCE_GLYPHS (it
);
22113 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
22116 while (i
< nglyphs
)
22118 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
22120 if (it
->line_wrap
!= TRUNCATE
22121 && x
+ glyph
->pixel_width
> max_x
)
22123 /* End of continued line or max_x reached. */
22124 if (CHAR_GLYPH_PADDING_P (*glyph
))
22126 /* A wide character is unbreakable. */
22127 if (row
->reversed_p
)
22128 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
22129 - n_glyphs_before
);
22130 row
->used
[TEXT_AREA
] = n_glyphs_before
;
22131 it
->current_x
= x_before
;
22135 if (row
->reversed_p
)
22136 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
22137 - (n_glyphs_before
+ i
));
22138 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
22143 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
22145 /* Glyph is at least partially visible. */
22147 if (x
< it
->first_visible_x
)
22148 row
->x
= x
- it
->first_visible_x
;
22152 /* Glyph is off the left margin of the display area.
22153 Should not happen. */
22157 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
22158 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
22159 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
22160 row
->phys_height
= max (row
->phys_height
,
22161 it
->max_phys_ascent
+ it
->max_phys_descent
);
22162 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
22163 it
->max_extra_line_spacing
);
22164 x
+= glyph
->pixel_width
;
22168 /* Stop if max_x reached. */
22172 /* Stop at line ends. */
22173 if (ITERATOR_AT_END_OF_LINE_P (it
))
22175 it
->continuation_lines_width
= 0;
22179 set_iterator_to_next (it
, 1);
22180 if (STRINGP (it
->string
))
22181 it_charpos
= IT_STRING_CHARPOS (*it
);
22183 it_charpos
= IT_CHARPOS (*it
);
22185 /* Stop if truncating at the right edge. */
22186 if (it
->line_wrap
== TRUNCATE
22187 && it
->current_x
>= it
->last_visible_x
)
22189 /* Add truncation mark, but don't do it if the line is
22190 truncated at a padding space. */
22191 if (it_charpos
< it
->string_nchars
)
22193 if (!FRAME_WINDOW_P (it
->f
))
22197 if (it
->current_x
> it
->last_visible_x
)
22199 if (!row
->reversed_p
)
22201 for (ii
= row
->used
[TEXT_AREA
] - 1; ii
> 0; --ii
)
22202 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
22207 for (ii
= 0; ii
< row
->used
[TEXT_AREA
]; ii
++)
22208 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
22210 unproduce_glyphs (it
, ii
+ 1);
22211 ii
= row
->used
[TEXT_AREA
] - (ii
+ 1);
22213 for (n
= row
->used
[TEXT_AREA
]; ii
< n
; ++ii
)
22215 row
->used
[TEXT_AREA
] = ii
;
22216 produce_special_glyphs (it
, IT_TRUNCATION
);
22219 produce_special_glyphs (it
, IT_TRUNCATION
);
22221 row
->truncated_on_right_p
= 1;
22227 /* Maybe insert a truncation at the left. */
22228 if (it
->first_visible_x
22231 if (!FRAME_WINDOW_P (it
->f
)
22232 || (row
->reversed_p
22233 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
22234 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
22235 insert_left_trunc_glyphs (it
);
22236 row
->truncated_on_left_p
= 1;
22239 it
->face_id
= saved_face_id
;
22241 /* Value is number of columns displayed. */
22242 return it
->hpos
- hpos_at_start
;
22247 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
22248 appears as an element of LIST or as the car of an element of LIST.
22249 If PROPVAL is a list, compare each element against LIST in that
22250 way, and return 1/2 if any element of PROPVAL is found in LIST.
22251 Otherwise return 0. This function cannot quit.
22252 The return value is 2 if the text is invisible but with an ellipsis
22253 and 1 if it's invisible and without an ellipsis. */
22256 invisible_p (register Lisp_Object propval
, Lisp_Object list
)
22258 register Lisp_Object tail
, proptail
;
22260 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
22262 register Lisp_Object tem
;
22264 if (EQ (propval
, tem
))
22266 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
22267 return NILP (XCDR (tem
)) ? 1 : 2;
22270 if (CONSP (propval
))
22272 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
22274 Lisp_Object propelt
;
22275 propelt
= XCAR (proptail
);
22276 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
22278 register Lisp_Object tem
;
22280 if (EQ (propelt
, tem
))
22282 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
22283 return NILP (XCDR (tem
)) ? 1 : 2;
22291 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
22292 doc
: /* Non-nil if the property makes the text invisible.
22293 POS-OR-PROP can be a marker or number, in which case it is taken to be
22294 a position in the current buffer and the value of the `invisible' property
22295 is checked; or it can be some other value, which is then presumed to be the
22296 value of the `invisible' property of the text of interest.
22297 The non-nil value returned can be t for truly invisible text or something
22298 else if the text is replaced by an ellipsis. */)
22299 (Lisp_Object pos_or_prop
)
22302 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
22303 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
22305 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
22306 return (invis
== 0 ? Qnil
22308 : make_number (invis
));
22311 /* Calculate a width or height in pixels from a specification using
22312 the following elements:
22315 NUM - a (fractional) multiple of the default font width/height
22316 (NUM) - specifies exactly NUM pixels
22317 UNIT - a fixed number of pixels, see below.
22318 ELEMENT - size of a display element in pixels, see below.
22319 (NUM . SPEC) - equals NUM * SPEC
22320 (+ SPEC SPEC ...) - add pixel values
22321 (- SPEC SPEC ...) - subtract pixel values
22322 (- SPEC) - negate pixel value
22325 INT or FLOAT - a number constant
22326 SYMBOL - use symbol's (buffer local) variable binding.
22329 in - pixels per inch *)
22330 mm - pixels per 1/1000 meter *)
22331 cm - pixels per 1/100 meter *)
22332 width - width of current font in pixels.
22333 height - height of current font in pixels.
22335 *) using the ratio(s) defined in display-pixels-per-inch.
22339 left-fringe - left fringe width in pixels
22340 right-fringe - right fringe width in pixels
22342 left-margin - left margin width in pixels
22343 right-margin - right margin width in pixels
22345 scroll-bar - scroll-bar area width in pixels
22349 Pixels corresponding to 5 inches:
22352 Total width of non-text areas on left side of window (if scroll-bar is on left):
22353 '(space :width (+ left-fringe left-margin scroll-bar))
22355 Align to first text column (in header line):
22356 '(space :align-to 0)
22358 Align to middle of text area minus half the width of variable `my-image'
22359 containing a loaded image:
22360 '(space :align-to (0.5 . (- text my-image)))
22362 Width of left margin minus width of 1 character in the default font:
22363 '(space :width (- left-margin 1))
22365 Width of left margin minus width of 2 characters in the current font:
22366 '(space :width (- left-margin (2 . width)))
22368 Center 1 character over left-margin (in header line):
22369 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
22371 Different ways to express width of left fringe plus left margin minus one pixel:
22372 '(space :width (- (+ left-fringe left-margin) (1)))
22373 '(space :width (+ left-fringe left-margin (- (1))))
22374 '(space :width (+ left-fringe left-margin (-1)))
22378 #define NUMVAL(X) \
22379 ((INTEGERP (X) || FLOATP (X)) \
22384 calc_pixel_width_or_height (double *res
, struct it
*it
, Lisp_Object prop
,
22385 struct font
*font
, int width_p
, int *align_to
)
22389 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
22390 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
22393 return OK_PIXELS (0);
22395 eassert (FRAME_LIVE_P (it
->f
));
22397 if (SYMBOLP (prop
))
22399 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
22401 char *unit
= SSDATA (SYMBOL_NAME (prop
));
22403 if (unit
[0] == 'i' && unit
[1] == 'n')
22405 else if (unit
[0] == 'm' && unit
[1] == 'm')
22407 else if (unit
[0] == 'c' && unit
[1] == 'm')
22414 #ifdef HAVE_WINDOW_SYSTEM
22415 if (FRAME_WINDOW_P (it
->f
)
22417 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
22418 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
22420 return OK_PIXELS (ppi
/ pixels
);
22423 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
22424 || (CONSP (Vdisplay_pixels_per_inch
)
22426 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
22427 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
22429 return OK_PIXELS (ppi
/ pixels
);
22435 #ifdef HAVE_WINDOW_SYSTEM
22436 if (EQ (prop
, Qheight
))
22437 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
22438 if (EQ (prop
, Qwidth
))
22439 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
22441 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
22442 return OK_PIXELS (1);
22445 if (EQ (prop
, Qtext
))
22446 return OK_PIXELS (width_p
22447 ? window_box_width (it
->w
, TEXT_AREA
)
22448 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
22450 if (align_to
&& *align_to
< 0)
22453 if (EQ (prop
, Qleft
))
22454 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
22455 if (EQ (prop
, Qright
))
22456 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
22457 if (EQ (prop
, Qcenter
))
22458 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
22459 + window_box_width (it
->w
, TEXT_AREA
) / 2);
22460 if (EQ (prop
, Qleft_fringe
))
22461 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22462 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
22463 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
22464 if (EQ (prop
, Qright_fringe
))
22465 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22466 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
22467 : window_box_right_offset (it
->w
, TEXT_AREA
));
22468 if (EQ (prop
, Qleft_margin
))
22469 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
22470 if (EQ (prop
, Qright_margin
))
22471 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
22472 if (EQ (prop
, Qscroll_bar
))
22473 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
22475 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
22476 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22477 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
22482 if (EQ (prop
, Qleft_fringe
))
22483 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
22484 if (EQ (prop
, Qright_fringe
))
22485 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
22486 if (EQ (prop
, Qleft_margin
))
22487 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
22488 if (EQ (prop
, Qright_margin
))
22489 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
22490 if (EQ (prop
, Qscroll_bar
))
22491 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
22494 prop
= buffer_local_value_1 (prop
, it
->w
->buffer
);
22495 if (EQ (prop
, Qunbound
))
22499 if (INTEGERP (prop
) || FLOATP (prop
))
22501 int base_unit
= (width_p
22502 ? FRAME_COLUMN_WIDTH (it
->f
)
22503 : FRAME_LINE_HEIGHT (it
->f
));
22504 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
22509 Lisp_Object car
= XCAR (prop
);
22510 Lisp_Object cdr
= XCDR (prop
);
22514 #ifdef HAVE_WINDOW_SYSTEM
22515 if (FRAME_WINDOW_P (it
->f
)
22516 && valid_image_p (prop
))
22518 ptrdiff_t id
= lookup_image (it
->f
, prop
);
22519 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
22521 return OK_PIXELS (width_p
? img
->width
: img
->height
);
22523 #ifdef HAVE_XWIDGETS
22524 if (FRAME_WINDOW_P (it
->f
) && valid_xwidget_p (prop
))
22526 printf("calc_pixel_width_or_height: return dummy size FIXME\n");
22527 return OK_PIXELS (width_p
? 100 : 100);
22531 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
22537 while (CONSP (cdr
))
22539 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
22540 font
, width_p
, align_to
))
22543 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
22548 if (EQ (car
, Qminus
))
22550 return OK_PIXELS (pixels
);
22553 car
= buffer_local_value_1 (car
, it
->w
->buffer
);
22554 if (EQ (car
, Qunbound
))
22558 if (INTEGERP (car
) || FLOATP (car
))
22561 pixels
= XFLOATINT (car
);
22563 return OK_PIXELS (pixels
);
22564 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
22565 font
, width_p
, align_to
))
22566 return OK_PIXELS (pixels
* fact
);
22577 /***********************************************************************
22579 ***********************************************************************/
22581 #ifdef HAVE_WINDOW_SYSTEM
22586 dump_glyph_string (struct glyph_string
*s
)
22588 fprintf (stderr
, "glyph string\n");
22589 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
22590 s
->x
, s
->y
, s
->width
, s
->height
);
22591 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
22592 fprintf (stderr
, " hl = %d\n", s
->hl
);
22593 fprintf (stderr
, " left overhang = %d, right = %d\n",
22594 s
->left_overhang
, s
->right_overhang
);
22595 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
22596 fprintf (stderr
, " extends to end of line = %d\n",
22597 s
->extends_to_end_of_line_p
);
22598 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
22599 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
22602 #endif /* GLYPH_DEBUG */
22604 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
22605 of XChar2b structures for S; it can't be allocated in
22606 init_glyph_string because it must be allocated via `alloca'. W
22607 is the window on which S is drawn. ROW and AREA are the glyph row
22608 and area within the row from which S is constructed. START is the
22609 index of the first glyph structure covered by S. HL is a
22610 face-override for drawing S. */
22613 #define OPTIONAL_HDC(hdc) HDC hdc,
22614 #define DECLARE_HDC(hdc) HDC hdc;
22615 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
22616 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
22619 #ifndef OPTIONAL_HDC
22620 #define OPTIONAL_HDC(hdc)
22621 #define DECLARE_HDC(hdc)
22622 #define ALLOCATE_HDC(hdc, f)
22623 #define RELEASE_HDC(hdc, f)
22627 init_glyph_string (struct glyph_string
*s
,
22629 XChar2b
*char2b
, struct window
*w
, struct glyph_row
*row
,
22630 enum glyph_row_area area
, int start
, enum draw_glyphs_face hl
)
22632 memset (s
, 0, sizeof *s
);
22634 s
->f
= XFRAME (w
->frame
);
22638 s
->display
= FRAME_X_DISPLAY (s
->f
);
22639 s
->window
= FRAME_X_WINDOW (s
->f
);
22640 s
->char2b
= char2b
;
22644 s
->first_glyph
= row
->glyphs
[area
] + start
;
22645 s
->height
= row
->height
;
22646 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
22647 s
->ybase
= s
->y
+ row
->ascent
;
22651 /* Append the list of glyph strings with head H and tail T to the list
22652 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
22655 append_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
22656 struct glyph_string
*h
, struct glyph_string
*t
)
22670 /* Prepend the list of glyph strings with head H and tail T to the
22671 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
22675 prepend_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
22676 struct glyph_string
*h
, struct glyph_string
*t
)
22690 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
22691 Set *HEAD and *TAIL to the resulting list. */
22694 append_glyph_string (struct glyph_string
**head
, struct glyph_string
**tail
,
22695 struct glyph_string
*s
)
22697 s
->next
= s
->prev
= NULL
;
22698 append_glyph_string_lists (head
, tail
, s
, s
);
22702 /* Get face and two-byte form of character C in face FACE_ID on frame F.
22703 The encoding of C is returned in *CHAR2B. DISPLAY_P non-zero means
22704 make sure that X resources for the face returned are allocated.
22705 Value is a pointer to a realized face that is ready for display if
22706 DISPLAY_P is non-zero. */
22708 static struct face
*
22709 get_char_face_and_encoding (struct frame
*f
, int c
, int face_id
,
22710 XChar2b
*char2b
, int display_p
)
22712 struct face
*face
= FACE_FROM_ID (f
, face_id
);
22716 unsigned code
= face
->font
->driver
->encode_char (face
->font
, c
);
22718 if (code
!= FONT_INVALID_CODE
)
22719 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22721 STORE_XCHAR2B (char2b
, 0, 0);
22724 /* Make sure X resources of the face are allocated. */
22725 #ifdef HAVE_X_WINDOWS
22729 eassert (face
!= NULL
);
22730 PREPARE_FACE_FOR_DISPLAY (f
, face
);
22737 /* Get face and two-byte form of character glyph GLYPH on frame F.
22738 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
22739 a pointer to a realized face that is ready for display. */
22741 static struct face
*
22742 get_glyph_face_and_encoding (struct frame
*f
, struct glyph
*glyph
,
22743 XChar2b
*char2b
, int *two_byte_p
)
22747 eassert (glyph
->type
== CHAR_GLYPH
);
22748 face
= FACE_FROM_ID (f
, glyph
->face_id
);
22757 if (CHAR_BYTE8_P (glyph
->u
.ch
))
22758 code
= CHAR_TO_BYTE8 (glyph
->u
.ch
);
22760 code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
22762 if (code
!= FONT_INVALID_CODE
)
22763 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22765 STORE_XCHAR2B (char2b
, 0, 0);
22768 /* Make sure X resources of the face are allocated. */
22769 eassert (face
!= NULL
);
22770 PREPARE_FACE_FOR_DISPLAY (f
, face
);
22775 /* Get glyph code of character C in FONT in the two-byte form CHAR2B.
22776 Return 1 if FONT has a glyph for C, otherwise return 0. */
22779 get_char_glyph_code (int c
, struct font
*font
, XChar2b
*char2b
)
22783 if (CHAR_BYTE8_P (c
))
22784 code
= CHAR_TO_BYTE8 (c
);
22786 code
= font
->driver
->encode_char (font
, c
);
22788 if (code
== FONT_INVALID_CODE
)
22790 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22795 /* Fill glyph string S with composition components specified by S->cmp.
22797 BASE_FACE is the base face of the composition.
22798 S->cmp_from is the index of the first component for S.
22800 OVERLAPS non-zero means S should draw the foreground only, and use
22801 its physical height for clipping. See also draw_glyphs.
22803 Value is the index of a component not in S. */
22806 fill_composite_glyph_string (struct glyph_string
*s
, struct face
*base_face
,
22810 /* For all glyphs of this composition, starting at the offset
22811 S->cmp_from, until we reach the end of the definition or encounter a
22812 glyph that requires the different face, add it to S. */
22817 s
->for_overlaps
= overlaps
;
22820 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
22822 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
22824 /* TAB in a composition means display glyphs with padding space
22825 on the left or right. */
22828 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
22831 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
22838 s
->font
= s
->face
->font
;
22840 else if (s
->face
!= face
)
22848 if (s
->face
== NULL
)
22850 s
->face
= base_face
->ascii_face
;
22851 s
->font
= s
->face
->font
;
22854 /* All glyph strings for the same composition has the same width,
22855 i.e. the width set for the first component of the composition. */
22856 s
->width
= s
->first_glyph
->pixel_width
;
22858 /* If the specified font could not be loaded, use the frame's
22859 default font, but record the fact that we couldn't load it in
22860 the glyph string so that we can draw rectangles for the
22861 characters of the glyph string. */
22862 if (s
->font
== NULL
)
22864 s
->font_not_found_p
= 1;
22865 s
->font
= FRAME_FONT (s
->f
);
22868 /* Adjust base line for subscript/superscript text. */
22869 s
->ybase
+= s
->first_glyph
->voffset
;
22871 /* This glyph string must always be drawn with 16-bit functions. */
22878 fill_gstring_glyph_string (struct glyph_string
*s
, int face_id
,
22879 int start
, int end
, int overlaps
)
22881 struct glyph
*glyph
, *last
;
22882 Lisp_Object lgstring
;
22885 s
->for_overlaps
= overlaps
;
22886 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22887 last
= s
->row
->glyphs
[s
->area
] + end
;
22888 s
->cmp_id
= glyph
->u
.cmp
.id
;
22889 s
->cmp_from
= glyph
->slice
.cmp
.from
;
22890 s
->cmp_to
= glyph
->slice
.cmp
.to
+ 1;
22891 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
22892 lgstring
= composition_gstring_from_id (s
->cmp_id
);
22893 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
22895 while (glyph
< last
22896 && glyph
->u
.cmp
.automatic
22897 && glyph
->u
.cmp
.id
== s
->cmp_id
22898 && s
->cmp_to
== glyph
->slice
.cmp
.from
)
22899 s
->cmp_to
= (glyph
++)->slice
.cmp
.to
+ 1;
22901 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
22903 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
22904 unsigned code
= LGLYPH_CODE (lglyph
);
22906 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
22908 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
22909 return glyph
- s
->row
->glyphs
[s
->area
];
22913 /* Fill glyph string S from a sequence glyphs for glyphless characters.
22914 See the comment of fill_glyph_string for arguments.
22915 Value is the index of the first glyph not in S. */
22919 fill_glyphless_glyph_string (struct glyph_string
*s
, int face_id
,
22920 int start
, int end
, int overlaps
)
22922 struct glyph
*glyph
, *last
;
22925 eassert (s
->first_glyph
->type
== GLYPHLESS_GLYPH
);
22926 s
->for_overlaps
= overlaps
;
22927 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22928 last
= s
->row
->glyphs
[s
->area
] + end
;
22929 voffset
= glyph
->voffset
;
22930 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
22931 s
->font
= s
->face
->font
? s
->face
->font
: FRAME_FONT (s
->f
);
22933 s
->width
= glyph
->pixel_width
;
22935 while (glyph
< last
22936 && glyph
->type
== GLYPHLESS_GLYPH
22937 && glyph
->voffset
== voffset
22938 && glyph
->face_id
== face_id
)
22941 s
->width
+= glyph
->pixel_width
;
22944 s
->ybase
+= voffset
;
22945 return glyph
- s
->row
->glyphs
[s
->area
];
22949 /* Fill glyph string S from a sequence of character glyphs.
22951 FACE_ID is the face id of the string. START is the index of the
22952 first glyph to consider, END is the index of the last + 1.
22953 OVERLAPS non-zero means S should draw the foreground only, and use
22954 its physical height for clipping. See also draw_glyphs.
22956 Value is the index of the first glyph not in S. */
22959 fill_glyph_string (struct glyph_string
*s
, int face_id
,
22960 int start
, int end
, int overlaps
)
22962 struct glyph
*glyph
, *last
;
22964 int glyph_not_available_p
;
22966 eassert (s
->f
== XFRAME (s
->w
->frame
));
22967 eassert (s
->nchars
== 0);
22968 eassert (start
>= 0 && end
> start
);
22970 s
->for_overlaps
= overlaps
;
22971 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22972 last
= s
->row
->glyphs
[s
->area
] + end
;
22973 voffset
= glyph
->voffset
;
22974 s
->padding_p
= glyph
->padding_p
;
22975 glyph_not_available_p
= glyph
->glyph_not_available_p
;
22977 while (glyph
< last
22978 && glyph
->type
== CHAR_GLYPH
22979 && glyph
->voffset
== voffset
22980 /* Same face id implies same font, nowadays. */
22981 && glyph
->face_id
== face_id
22982 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
22986 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
22987 s
->char2b
+ s
->nchars
,
22989 s
->two_byte_p
= two_byte_p
;
22991 eassert (s
->nchars
<= end
- start
);
22992 s
->width
+= glyph
->pixel_width
;
22993 if (glyph
++->padding_p
!= s
->padding_p
)
22997 s
->font
= s
->face
->font
;
22999 /* If the specified font could not be loaded, use the frame's font,
23000 but record the fact that we couldn't load it in
23001 S->font_not_found_p so that we can draw rectangles for the
23002 characters of the glyph string. */
23003 if (s
->font
== NULL
|| glyph_not_available_p
)
23005 s
->font_not_found_p
= 1;
23006 s
->font
= FRAME_FONT (s
->f
);
23009 /* Adjust base line for subscript/superscript text. */
23010 s
->ybase
+= voffset
;
23012 eassert (s
->face
&& s
->face
->gc
);
23013 return glyph
- s
->row
->glyphs
[s
->area
];
23017 /* Fill glyph string S from image glyph S->first_glyph. */
23020 fill_image_glyph_string (struct glyph_string
*s
)
23022 eassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
23023 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
23025 s
->slice
= s
->first_glyph
->slice
.img
;
23026 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
23027 s
->font
= s
->face
->font
;
23028 s
->width
= s
->first_glyph
->pixel_width
;
23030 /* Adjust base line for subscript/superscript text. */
23031 s
->ybase
+= s
->first_glyph
->voffset
;
23034 #ifdef HAVE_XWIDGETS
23036 fill_xwidget_glyph_string (struct glyph_string
*s
)
23038 eassert (s
->first_glyph
->type
== XWIDGET_GLYPH
);
23039 printf("fill_xwidget_glyph_string: width:%d \n",s
->first_glyph
->pixel_width
);
23040 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
23041 s
->font
= s
->face
->font
;
23042 s
->width
= s
->first_glyph
->pixel_width
;
23043 s
->ybase
+= s
->first_glyph
->voffset
;
23044 s
->xwidget
= s
->first_glyph
->u
.xwidget
;
23045 //assert_valid_xwidget_id ( s->xwidget, "fill_xwidget_glyph_string");
23048 /* Fill glyph string S from a sequence of stretch glyphs.
23050 START is the index of the first glyph to consider,
23051 END is the index of the last + 1.
23053 Value is the index of the first glyph not in S. */
23056 fill_stretch_glyph_string (struct glyph_string
*s
, int start
, int end
)
23058 struct glyph
*glyph
, *last
;
23059 int voffset
, face_id
;
23061 eassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
23063 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23064 last
= s
->row
->glyphs
[s
->area
] + end
;
23065 face_id
= glyph
->face_id
;
23066 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
23067 s
->font
= s
->face
->font
;
23068 s
->width
= glyph
->pixel_width
;
23070 voffset
= glyph
->voffset
;
23074 && glyph
->type
== STRETCH_GLYPH
23075 && glyph
->voffset
== voffset
23076 && glyph
->face_id
== face_id
);
23078 s
->width
+= glyph
->pixel_width
;
23080 /* Adjust base line for subscript/superscript text. */
23081 s
->ybase
+= voffset
;
23083 /* The case that face->gc == 0 is handled when drawing the glyph
23084 string by calling PREPARE_FACE_FOR_DISPLAY. */
23086 return glyph
- s
->row
->glyphs
[s
->area
];
23089 static struct font_metrics
*
23090 get_per_char_metric (struct font
*font
, XChar2b
*char2b
)
23092 static struct font_metrics metrics
;
23093 unsigned code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
23095 if (! font
|| code
== FONT_INVALID_CODE
)
23097 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
23102 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
23103 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
23104 assumed to be zero. */
23107 x_get_glyph_overhangs (struct glyph
*glyph
, struct frame
*f
, int *left
, int *right
)
23109 *left
= *right
= 0;
23111 if (glyph
->type
== CHAR_GLYPH
)
23115 struct font_metrics
*pcm
;
23117 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
23118 if (face
->font
&& (pcm
= get_per_char_metric (face
->font
, &char2b
)))
23120 if (pcm
->rbearing
> pcm
->width
)
23121 *right
= pcm
->rbearing
- pcm
->width
;
23122 if (pcm
->lbearing
< 0)
23123 *left
= -pcm
->lbearing
;
23126 else if (glyph
->type
== COMPOSITE_GLYPH
)
23128 if (! glyph
->u
.cmp
.automatic
)
23130 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
23132 if (cmp
->rbearing
> cmp
->pixel_width
)
23133 *right
= cmp
->rbearing
- cmp
->pixel_width
;
23134 if (cmp
->lbearing
< 0)
23135 *left
= - cmp
->lbearing
;
23139 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
23140 struct font_metrics metrics
;
23142 composition_gstring_width (gstring
, glyph
->slice
.cmp
.from
,
23143 glyph
->slice
.cmp
.to
+ 1, &metrics
);
23144 if (metrics
.rbearing
> metrics
.width
)
23145 *right
= metrics
.rbearing
- metrics
.width
;
23146 if (metrics
.lbearing
< 0)
23147 *left
= - metrics
.lbearing
;
23153 /* Return the index of the first glyph preceding glyph string S that
23154 is overwritten by S because of S's left overhang. Value is -1
23155 if no glyphs are overwritten. */
23158 left_overwritten (struct glyph_string
*s
)
23162 if (s
->left_overhang
)
23165 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23166 int first
= s
->first_glyph
- glyphs
;
23168 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
23169 x
-= glyphs
[i
].pixel_width
;
23180 /* Return the index of the first glyph preceding glyph string S that
23181 is overwriting S because of its right overhang. Value is -1 if no
23182 glyph in front of S overwrites S. */
23185 left_overwriting (struct glyph_string
*s
)
23188 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23189 int first
= s
->first_glyph
- glyphs
;
23193 for (i
= first
- 1; i
>= 0; --i
)
23196 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
23199 x
-= glyphs
[i
].pixel_width
;
23206 /* Return the index of the last glyph following glyph string S that is
23207 overwritten by S because of S's right overhang. Value is -1 if
23208 no such glyph is found. */
23211 right_overwritten (struct glyph_string
*s
)
23215 if (s
->right_overhang
)
23218 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23219 int first
= (s
->first_glyph
- glyphs
23220 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
23221 int end
= s
->row
->used
[s
->area
];
23223 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
23224 x
+= glyphs
[i
].pixel_width
;
23233 /* Return the index of the last glyph following glyph string S that
23234 overwrites S because of its left overhang. Value is negative
23235 if no such glyph is found. */
23238 right_overwriting (struct glyph_string
*s
)
23241 int end
= s
->row
->used
[s
->area
];
23242 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23243 int first
= (s
->first_glyph
- glyphs
23244 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
23248 for (i
= first
; i
< end
; ++i
)
23251 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
23254 x
+= glyphs
[i
].pixel_width
;
23261 /* Set background width of glyph string S. START is the index of the
23262 first glyph following S. LAST_X is the right-most x-position + 1
23263 in the drawing area. */
23266 set_glyph_string_background_width (struct glyph_string
*s
, int start
, int last_x
)
23268 /* If the face of this glyph string has to be drawn to the end of
23269 the drawing area, set S->extends_to_end_of_line_p. */
23271 if (start
== s
->row
->used
[s
->area
]
23272 && s
->area
== TEXT_AREA
23273 && ((s
->row
->fill_line_p
23274 && (s
->hl
== DRAW_NORMAL_TEXT
23275 || s
->hl
== DRAW_IMAGE_RAISED
23276 || s
->hl
== DRAW_IMAGE_SUNKEN
))
23277 || s
->hl
== DRAW_MOUSE_FACE
))
23278 s
->extends_to_end_of_line_p
= 1;
23280 /* If S extends its face to the end of the line, set its
23281 background_width to the distance to the right edge of the drawing
23283 if (s
->extends_to_end_of_line_p
)
23284 s
->background_width
= last_x
- s
->x
+ 1;
23286 s
->background_width
= s
->width
;
23290 /* Compute overhangs and x-positions for glyph string S and its
23291 predecessors, or successors. X is the starting x-position for S.
23292 BACKWARD_P non-zero means process predecessors. */
23295 compute_overhangs_and_x (struct glyph_string
*s
, int x
, int backward_p
)
23301 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
23302 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
23312 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
23313 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
23323 /* The following macros are only called from draw_glyphs below.
23324 They reference the following parameters of that function directly:
23325 `w', `row', `area', and `overlap_p'
23326 as well as the following local variables:
23327 `s', `f', and `hdc' (in W32) */
23330 /* On W32, silently add local `hdc' variable to argument list of
23331 init_glyph_string. */
23332 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
23333 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
23335 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
23336 init_glyph_string (s, char2b, w, row, area, start, hl)
23339 /* Add a glyph string for a stretch glyph to the list of strings
23340 between HEAD and TAIL. START is the index of the stretch glyph in
23341 row area AREA of glyph row ROW. END is the index of the last glyph
23342 in that glyph row area. X is the current output position assigned
23343 to the new glyph string constructed. HL overrides that face of the
23344 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
23345 is the right-most x-position of the drawing area. */
23347 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
23348 and below -- keep them on one line. */
23349 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23352 s = alloca (sizeof *s); \
23353 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23354 START = fill_stretch_glyph_string (s, START, END); \
23355 append_glyph_string (&HEAD, &TAIL, s); \
23361 /* Add a glyph string for an image glyph to the list of strings
23362 between HEAD and TAIL. START is the index of the image glyph in
23363 row area AREA of glyph row ROW. END is the index of the last glyph
23364 in that glyph row area. X is the current output position assigned
23365 to the new glyph string constructed. HL overrides that face of the
23366 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
23367 is the right-most x-position of the drawing area. */
23369 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23372 s = alloca (sizeof *s); \
23373 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23374 fill_image_glyph_string (s); \
23375 append_glyph_string (&HEAD, &TAIL, s); \
23381 #ifdef HAVE_XWIDGETS
23382 #define BUILD_XWIDGET_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23385 printf("BUILD_XWIDGET_GLYPH_STRING\n"); \
23386 s = (struct glyph_string *) alloca (sizeof *s); \
23387 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23388 fill_xwidget_glyph_string (s); \
23389 append_glyph_string (&HEAD, &TAIL, s); \
23397 /* Add a glyph string for a sequence of character glyphs to the list
23398 of strings between HEAD and TAIL. START is the index of the first
23399 glyph in row area AREA of glyph row ROW that is part of the new
23400 glyph string. END is the index of the last glyph in that glyph row
23401 area. X is the current output position assigned to the new glyph
23402 string constructed. HL overrides that face of the glyph; e.g. it
23403 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
23404 right-most x-position of the drawing area. */
23406 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
23412 face_id = (row)->glyphs[area][START].face_id; \
23414 s = alloca (sizeof *s); \
23415 char2b = alloca ((END - START) * sizeof *char2b); \
23416 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23417 append_glyph_string (&HEAD, &TAIL, s); \
23419 START = fill_glyph_string (s, face_id, START, END, overlaps); \
23424 /* Add a glyph string for a composite sequence to the list of strings
23425 between HEAD and TAIL. START is the index of the first glyph in
23426 row area AREA of glyph row ROW that is part of the new glyph
23427 string. END is the index of the last glyph in that glyph row area.
23428 X is the current output position assigned to the new glyph string
23429 constructed. HL overrides that face of the glyph; e.g. it is
23430 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
23431 x-position of the drawing area. */
23433 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23435 int face_id = (row)->glyphs[area][START].face_id; \
23436 struct face *base_face = FACE_FROM_ID (f, face_id); \
23437 ptrdiff_t cmp_id = (row)->glyphs[area][START].u.cmp.id; \
23438 struct composition *cmp = composition_table[cmp_id]; \
23440 struct glyph_string *first_s = NULL; \
23443 char2b = alloca (cmp->glyph_len * sizeof *char2b); \
23445 /* Make glyph_strings for each glyph sequence that is drawable by \
23446 the same face, and append them to HEAD/TAIL. */ \
23447 for (n = 0; n < cmp->glyph_len;) \
23449 s = alloca (sizeof *s); \
23450 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23451 append_glyph_string (&(HEAD), &(TAIL), s); \
23457 n = fill_composite_glyph_string (s, base_face, overlaps); \
23465 /* Add a glyph string for a glyph-string sequence to the list of strings
23466 between HEAD and TAIL. */
23468 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23472 Lisp_Object gstring; \
23474 face_id = (row)->glyphs[area][START].face_id; \
23475 gstring = (composition_gstring_from_id \
23476 ((row)->glyphs[area][START].u.cmp.id)); \
23477 s = alloca (sizeof *s); \
23478 char2b = alloca (LGSTRING_GLYPH_LEN (gstring) * sizeof *char2b); \
23479 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23480 append_glyph_string (&(HEAD), &(TAIL), s); \
23482 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
23486 /* Add a glyph string for a sequence of glyphless character's glyphs
23487 to the list of strings between HEAD and TAIL. The meanings of
23488 arguments are the same as those of BUILD_CHAR_GLYPH_STRINGS. */
23490 #define BUILD_GLYPHLESS_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23495 face_id = (row)->glyphs[area][START].face_id; \
23497 s = alloca (sizeof *s); \
23498 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23499 append_glyph_string (&HEAD, &TAIL, s); \
23501 START = fill_glyphless_glyph_string (s, face_id, START, END, \
23507 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
23508 of AREA of glyph row ROW on window W between indices START and END.
23509 HL overrides the face for drawing glyph strings, e.g. it is
23510 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
23511 x-positions of the drawing area.
23513 This is an ugly monster macro construct because we must use alloca
23514 to allocate glyph strings (because draw_glyphs can be called
23515 asynchronously). */
23517 #define BUILD_GLYPH_STRINGS_1(START, END, HEAD, TAIL, HL, X, LAST_X) \
23520 HEAD = TAIL = NULL; \
23521 while (START < END) \
23523 struct glyph *first_glyph = (row)->glyphs[area] + START; \
23524 switch (first_glyph->type) \
23527 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
23531 case COMPOSITE_GLYPH: \
23532 if (first_glyph->u.cmp.automatic) \
23533 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
23536 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
23540 case STRETCH_GLYPH: \
23541 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
23545 case IMAGE_GLYPH: \
23546 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
23550 #define BUILD_GLYPH_STRINGS_XW(START, END, HEAD, TAIL, HL, X, LAST_X) \
23551 case XWIDGET_GLYPH: \
23552 BUILD_XWIDGET_GLYPH_STRING (START, END, HEAD, TAIL, \
23556 #define BUILD_GLYPH_STRINGS_2(START, END, HEAD, TAIL, HL, X, LAST_X) \
23557 case GLYPHLESS_GLYPH: \
23558 BUILD_GLYPHLESS_GLYPH_STRING (START, END, HEAD, TAIL, \
23568 set_glyph_string_background_width (s, START, LAST_X); \
23575 #ifdef HAVE_XWIDGETS
23576 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
23577 BUILD_GLYPH_STRINGS_1(START, END, HEAD, TAIL, HL, X, LAST_X) \
23578 BUILD_GLYPH_STRINGS_XW(START, END, HEAD, TAIL, HL, X, LAST_X) \
23579 BUILD_GLYPH_STRINGS_2(START, END, HEAD, TAIL, HL, X, LAST_X)
23581 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
23582 BUILD_GLYPH_STRINGS_1(START, END, HEAD, TAIL, HL, X, LAST_X) \
23583 BUILD_GLYPH_STRINGS_2(START, END, HEAD, TAIL, HL, X, LAST_X)
23587 /* Draw glyphs between START and END in AREA of ROW on window W,
23588 starting at x-position X. X is relative to AREA in W. HL is a
23589 face-override with the following meaning:
23591 DRAW_NORMAL_TEXT draw normally
23592 DRAW_CURSOR draw in cursor face
23593 DRAW_MOUSE_FACE draw in mouse face.
23594 DRAW_INVERSE_VIDEO draw in mode line face
23595 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
23596 DRAW_IMAGE_RAISED draw an image with a raised relief around it
23598 If OVERLAPS is non-zero, draw only the foreground of characters and
23599 clip to the physical height of ROW. Non-zero value also defines
23600 the overlapping part to be drawn:
23602 OVERLAPS_PRED overlap with preceding rows
23603 OVERLAPS_SUCC overlap with succeeding rows
23604 OVERLAPS_BOTH overlap with both preceding/succeeding rows
23605 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
23607 Value is the x-position reached, relative to AREA of W. */
23610 draw_glyphs (struct window
*w
, int x
, struct glyph_row
*row
,
23611 enum glyph_row_area area
, ptrdiff_t start
, ptrdiff_t end
,
23612 enum draw_glyphs_face hl
, int overlaps
)
23614 struct glyph_string
*head
, *tail
;
23615 struct glyph_string
*s
;
23616 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
23617 int i
, j
, x_reached
, last_x
, area_left
= 0;
23618 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
23621 ALLOCATE_HDC (hdc
, f
);
23623 /* Let's rather be paranoid than getting a SEGV. */
23624 end
= min (end
, row
->used
[area
]);
23625 start
= max (0, start
);
23626 start
= min (end
, start
);
23628 /* Translate X to frame coordinates. Set last_x to the right
23629 end of the drawing area. */
23630 if (row
->full_width_p
)
23632 /* X is relative to the left edge of W, without scroll bars
23634 area_left
= WINDOW_LEFT_EDGE_X (w
);
23635 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
23639 area_left
= window_box_left (w
, area
);
23640 last_x
= area_left
+ window_box_width (w
, area
);
23644 /* Build a doubly-linked list of glyph_string structures between
23645 head and tail from what we have to draw. Note that the macro
23646 BUILD_GLYPH_STRINGS will modify its start parameter. That's
23647 the reason we use a separate variable `i'. */
23649 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
23651 x_reached
= tail
->x
+ tail
->background_width
;
23655 /* If there are any glyphs with lbearing < 0 or rbearing > width in
23656 the row, redraw some glyphs in front or following the glyph
23657 strings built above. */
23658 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
23660 struct glyph_string
*h
, *t
;
23661 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
23662 int mouse_beg_col
IF_LINT (= 0), mouse_end_col
IF_LINT (= 0);
23663 int check_mouse_face
= 0;
23666 /* If mouse highlighting is on, we may need to draw adjacent
23667 glyphs using mouse-face highlighting. */
23668 if (area
== TEXT_AREA
&& row
->mouse_face_p
)
23670 struct glyph_row
*mouse_beg_row
, *mouse_end_row
;
23672 mouse_beg_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
23673 mouse_end_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
23675 if (row
>= mouse_beg_row
&& row
<= mouse_end_row
)
23677 check_mouse_face
= 1;
23678 mouse_beg_col
= (row
== mouse_beg_row
)
23679 ? hlinfo
->mouse_face_beg_col
: 0;
23680 mouse_end_col
= (row
== mouse_end_row
)
23681 ? hlinfo
->mouse_face_end_col
23682 : row
->used
[TEXT_AREA
];
23686 /* Compute overhangs for all glyph strings. */
23687 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
23688 for (s
= head
; s
; s
= s
->next
)
23689 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
23691 /* Prepend glyph strings for glyphs in front of the first glyph
23692 string that are overwritten because of the first glyph
23693 string's left overhang. The background of all strings
23694 prepended must be drawn because the first glyph string
23696 i
= left_overwritten (head
);
23699 enum draw_glyphs_face overlap_hl
;
23701 /* If this row contains mouse highlighting, attempt to draw
23702 the overlapped glyphs with the correct highlight. This
23703 code fails if the overlap encompasses more than one glyph
23704 and mouse-highlight spans only some of these glyphs.
23705 However, making it work perfectly involves a lot more
23706 code, and I don't know if the pathological case occurs in
23707 practice, so we'll stick to this for now. --- cyd */
23708 if (check_mouse_face
23709 && mouse_beg_col
< start
&& mouse_end_col
> i
)
23710 overlap_hl
= DRAW_MOUSE_FACE
;
23712 overlap_hl
= DRAW_NORMAL_TEXT
;
23715 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
23716 overlap_hl
, dummy_x
, last_x
);
23718 compute_overhangs_and_x (t
, head
->x
, 1);
23719 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
23723 /* Prepend glyph strings for glyphs in front of the first glyph
23724 string that overwrite that glyph string because of their
23725 right overhang. For these strings, only the foreground must
23726 be drawn, because it draws over the glyph string at `head'.
23727 The background must not be drawn because this would overwrite
23728 right overhangs of preceding glyphs for which no glyph
23730 i
= left_overwriting (head
);
23733 enum draw_glyphs_face overlap_hl
;
23735 if (check_mouse_face
23736 && mouse_beg_col
< start
&& mouse_end_col
> i
)
23737 overlap_hl
= DRAW_MOUSE_FACE
;
23739 overlap_hl
= DRAW_NORMAL_TEXT
;
23742 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
23743 overlap_hl
, dummy_x
, last_x
);
23744 for (s
= h
; s
; s
= s
->next
)
23745 s
->background_filled_p
= 1;
23746 compute_overhangs_and_x (t
, head
->x
, 1);
23747 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
23750 /* Append glyphs strings for glyphs following the last glyph
23751 string tail that are overwritten by tail. The background of
23752 these strings has to be drawn because tail's foreground draws
23754 i
= right_overwritten (tail
);
23757 enum draw_glyphs_face overlap_hl
;
23759 if (check_mouse_face
23760 && mouse_beg_col
< i
&& mouse_end_col
> end
)
23761 overlap_hl
= DRAW_MOUSE_FACE
;
23763 overlap_hl
= DRAW_NORMAL_TEXT
;
23765 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
23766 overlap_hl
, x
, last_x
);
23767 /* Because BUILD_GLYPH_STRINGS updates the first argument,
23768 we don't have `end = i;' here. */
23769 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
23770 append_glyph_string_lists (&head
, &tail
, h
, t
);
23774 /* Append glyph strings for glyphs following the last glyph
23775 string tail that overwrite tail. The foreground of such
23776 glyphs has to be drawn because it writes into the background
23777 of tail. The background must not be drawn because it could
23778 paint over the foreground of following glyphs. */
23779 i
= right_overwriting (tail
);
23782 enum draw_glyphs_face overlap_hl
;
23783 if (check_mouse_face
23784 && mouse_beg_col
< i
&& mouse_end_col
> end
)
23785 overlap_hl
= DRAW_MOUSE_FACE
;
23787 overlap_hl
= DRAW_NORMAL_TEXT
;
23790 i
++; /* We must include the Ith glyph. */
23791 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
23792 overlap_hl
, x
, last_x
);
23793 for (s
= h
; s
; s
= s
->next
)
23794 s
->background_filled_p
= 1;
23795 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
23796 append_glyph_string_lists (&head
, &tail
, h
, t
);
23798 if (clip_head
|| clip_tail
)
23799 for (s
= head
; s
; s
= s
->next
)
23801 s
->clip_head
= clip_head
;
23802 s
->clip_tail
= clip_tail
;
23806 /* Draw all strings. */
23807 for (s
= head
; s
; s
= s
->next
)
23808 FRAME_RIF (f
)->draw_glyph_string (s
);
23811 /* When focus a sole frame and move horizontally, this sets on_p to 0
23812 causing a failure to erase prev cursor position. */
23813 if (area
== TEXT_AREA
23814 && !row
->full_width_p
23815 /* When drawing overlapping rows, only the glyph strings'
23816 foreground is drawn, which doesn't erase a cursor
23820 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
23821 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
23822 : (tail
? tail
->x
+ tail
->background_width
: x
));
23826 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
23827 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
23831 /* Value is the x-position up to which drawn, relative to AREA of W.
23832 This doesn't include parts drawn because of overhangs. */
23833 if (row
->full_width_p
)
23834 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
23836 x_reached
-= area_left
;
23838 RELEASE_HDC (hdc
, f
);
23843 /* Expand row matrix if too narrow. Don't expand if area
23846 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
23848 if (!fonts_changed_p \
23849 && (it->glyph_row->glyphs[area] \
23850 < it->glyph_row->glyphs[area + 1])) \
23852 it->w->ncols_scale_factor++; \
23853 fonts_changed_p = 1; \
23857 /* Store one glyph for IT->char_to_display in IT->glyph_row.
23858 Called from x_produce_glyphs when IT->glyph_row is non-null. */
23861 append_glyph (struct it
*it
)
23863 struct glyph
*glyph
;
23864 enum glyph_row_area area
= it
->area
;
23866 eassert (it
->glyph_row
);
23867 eassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
23869 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23870 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23872 /* If the glyph row is reversed, we need to prepend the glyph
23873 rather than append it. */
23874 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23878 /* Make room for the additional glyph. */
23879 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
23881 glyph
= it
->glyph_row
->glyphs
[area
];
23883 glyph
->charpos
= CHARPOS (it
->position
);
23884 glyph
->object
= it
->object
;
23885 if (it
->pixel_width
> 0)
23887 glyph
->pixel_width
= it
->pixel_width
;
23888 glyph
->padding_p
= 0;
23892 /* Assure at least 1-pixel width. Otherwise, cursor can't
23893 be displayed correctly. */
23894 glyph
->pixel_width
= 1;
23895 glyph
->padding_p
= 1;
23897 glyph
->ascent
= it
->ascent
;
23898 glyph
->descent
= it
->descent
;
23899 glyph
->voffset
= it
->voffset
;
23900 glyph
->type
= CHAR_GLYPH
;
23901 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23902 glyph
->multibyte_p
= it
->multibyte_p
;
23903 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23904 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23905 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
23906 || it
->phys_descent
> it
->descent
);
23907 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
23908 glyph
->face_id
= it
->face_id
;
23909 glyph
->u
.ch
= it
->char_to_display
;
23910 glyph
->slice
.img
= null_glyph_slice
;
23911 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23914 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23915 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23917 glyph
->bidi_type
= it
->bidi_it
.type
;
23921 glyph
->resolved_level
= 0;
23922 glyph
->bidi_type
= UNKNOWN_BT
;
23924 ++it
->glyph_row
->used
[area
];
23927 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23930 /* Store one glyph for the composition IT->cmp_it.id in
23931 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
23935 append_composite_glyph (struct it
*it
)
23937 struct glyph
*glyph
;
23938 enum glyph_row_area area
= it
->area
;
23940 eassert (it
->glyph_row
);
23942 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23943 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23945 /* If the glyph row is reversed, we need to prepend the glyph
23946 rather than append it. */
23947 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
23951 /* Make room for the new glyph. */
23952 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
23954 glyph
= it
->glyph_row
->glyphs
[it
->area
];
23956 glyph
->charpos
= it
->cmp_it
.charpos
;
23957 glyph
->object
= it
->object
;
23958 glyph
->pixel_width
= it
->pixel_width
;
23959 glyph
->ascent
= it
->ascent
;
23960 glyph
->descent
= it
->descent
;
23961 glyph
->voffset
= it
->voffset
;
23962 glyph
->type
= COMPOSITE_GLYPH
;
23963 if (it
->cmp_it
.ch
< 0)
23965 glyph
->u
.cmp
.automatic
= 0;
23966 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
23967 glyph
->slice
.cmp
.from
= glyph
->slice
.cmp
.to
= 0;
23971 glyph
->u
.cmp
.automatic
= 1;
23972 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
23973 glyph
->slice
.cmp
.from
= it
->cmp_it
.from
;
23974 glyph
->slice
.cmp
.to
= it
->cmp_it
.to
- 1;
23976 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23977 glyph
->multibyte_p
= it
->multibyte_p
;
23978 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23979 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23980 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
23981 || it
->phys_descent
> it
->descent
);
23982 glyph
->padding_p
= 0;
23983 glyph
->glyph_not_available_p
= 0;
23984 glyph
->face_id
= it
->face_id
;
23985 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23988 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23989 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23991 glyph
->bidi_type
= it
->bidi_it
.type
;
23993 ++it
->glyph_row
->used
[area
];
23996 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24000 /* Change IT->ascent and IT->height according to the setting of
24004 take_vertical_position_into_account (struct it
*it
)
24008 if (it
->voffset
< 0)
24009 /* Increase the ascent so that we can display the text higher
24011 it
->ascent
-= it
->voffset
;
24013 /* Increase the descent so that we can display the text lower
24015 it
->descent
+= it
->voffset
;
24020 /* Produce glyphs/get display metrics for the image IT is loaded with.
24021 See the description of struct display_iterator in dispextern.h for
24022 an overview of struct display_iterator. */
24025 produce_image_glyph (struct it
*it
)
24029 int glyph_ascent
, crop
;
24030 struct glyph_slice slice
;
24032 eassert (it
->what
== IT_IMAGE
);
24034 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24036 /* Make sure X resources of the face is loaded. */
24037 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24039 if (it
->image_id
< 0)
24041 /* Fringe bitmap. */
24042 it
->ascent
= it
->phys_ascent
= 0;
24043 it
->descent
= it
->phys_descent
= 0;
24044 it
->pixel_width
= 0;
24049 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
24051 /* Make sure X resources of the image is loaded. */
24052 prepare_image_for_display (it
->f
, img
);
24054 slice
.x
= slice
.y
= 0;
24055 slice
.width
= img
->width
;
24056 slice
.height
= img
->height
;
24058 if (INTEGERP (it
->slice
.x
))
24059 slice
.x
= XINT (it
->slice
.x
);
24060 else if (FLOATP (it
->slice
.x
))
24061 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
24063 if (INTEGERP (it
->slice
.y
))
24064 slice
.y
= XINT (it
->slice
.y
);
24065 else if (FLOATP (it
->slice
.y
))
24066 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
24068 if (INTEGERP (it
->slice
.width
))
24069 slice
.width
= XINT (it
->slice
.width
);
24070 else if (FLOATP (it
->slice
.width
))
24071 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
24073 if (INTEGERP (it
->slice
.height
))
24074 slice
.height
= XINT (it
->slice
.height
);
24075 else if (FLOATP (it
->slice
.height
))
24076 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
24078 if (slice
.x
>= img
->width
)
24079 slice
.x
= img
->width
;
24080 if (slice
.y
>= img
->height
)
24081 slice
.y
= img
->height
;
24082 if (slice
.x
+ slice
.width
>= img
->width
)
24083 slice
.width
= img
->width
- slice
.x
;
24084 if (slice
.y
+ slice
.height
> img
->height
)
24085 slice
.height
= img
->height
- slice
.y
;
24087 if (slice
.width
== 0 || slice
.height
== 0)
24090 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
24092 it
->descent
= slice
.height
- glyph_ascent
;
24094 it
->descent
+= img
->vmargin
;
24095 if (slice
.y
+ slice
.height
== img
->height
)
24096 it
->descent
+= img
->vmargin
;
24097 it
->phys_descent
= it
->descent
;
24099 it
->pixel_width
= slice
.width
;
24101 it
->pixel_width
+= img
->hmargin
;
24102 if (slice
.x
+ slice
.width
== img
->width
)
24103 it
->pixel_width
+= img
->hmargin
;
24105 /* It's quite possible for images to have an ascent greater than
24106 their height, so don't get confused in that case. */
24107 if (it
->descent
< 0)
24112 if (face
->box
!= FACE_NO_BOX
)
24114 if (face
->box_line_width
> 0)
24117 it
->ascent
+= face
->box_line_width
;
24118 if (slice
.y
+ slice
.height
== img
->height
)
24119 it
->descent
+= face
->box_line_width
;
24122 if (it
->start_of_box_run_p
&& slice
.x
== 0)
24123 it
->pixel_width
+= eabs (face
->box_line_width
);
24124 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
24125 it
->pixel_width
+= eabs (face
->box_line_width
);
24128 take_vertical_position_into_account (it
);
24130 /* Automatically crop wide image glyphs at right edge so we can
24131 draw the cursor on same display row. */
24132 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
24133 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
24135 it
->pixel_width
-= crop
;
24136 slice
.width
-= crop
;
24141 struct glyph
*glyph
;
24142 enum glyph_row_area area
= it
->area
;
24144 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24145 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24147 glyph
->charpos
= CHARPOS (it
->position
);
24148 glyph
->object
= it
->object
;
24149 glyph
->pixel_width
= it
->pixel_width
;
24150 glyph
->ascent
= glyph_ascent
;
24151 glyph
->descent
= it
->descent
;
24152 glyph
->voffset
= it
->voffset
;
24153 glyph
->type
= IMAGE_GLYPH
;
24154 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24155 glyph
->multibyte_p
= it
->multibyte_p
;
24156 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24157 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24158 glyph
->overlaps_vertically_p
= 0;
24159 glyph
->padding_p
= 0;
24160 glyph
->glyph_not_available_p
= 0;
24161 glyph
->face_id
= it
->face_id
;
24162 glyph
->u
.img_id
= img
->id
;
24163 glyph
->slice
.img
= slice
;
24164 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24167 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24168 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24170 glyph
->bidi_type
= it
->bidi_it
.type
;
24172 ++it
->glyph_row
->used
[area
];
24175 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24179 #ifdef HAVE_XWIDGETS
24181 produce_xwidget_glyph (struct it
*it
)
24183 struct xwidget
* xw
;
24185 int glyph_ascent
, crop
;
24186 printf("produce_xwidget_glyph:\n");
24187 eassert (it
->what
== IT_XWIDGET
);
24189 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24191 /* Make sure X resources of the face is loaded. */
24192 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24195 it
->ascent
= it
->phys_ascent
= glyph_ascent
= xw
->height
/2;
24196 it
->descent
= xw
->height
/2;
24197 it
->phys_descent
= it
->descent
;
24198 it
->pixel_width
= xw
->width
;
24199 /* It's quite possible for images to have an ascent greater than
24200 their height, so don't get confused in that case. */
24201 if (it
->descent
< 0)
24206 if (face
->box
!= FACE_NO_BOX
)
24208 if (face
->box_line_width
> 0)
24210 it
->ascent
+= face
->box_line_width
;
24211 it
->descent
+= face
->box_line_width
;
24214 if (it
->start_of_box_run_p
)
24215 it
->pixel_width
+= eabs (face
->box_line_width
);
24216 it
->pixel_width
+= eabs (face
->box_line_width
);
24219 take_vertical_position_into_account (it
);
24221 /* Automatically crop wide image glyphs at right edge so we can
24222 draw the cursor on same display row. */
24223 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
24224 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
24226 it
->pixel_width
-= crop
;
24231 struct glyph
*glyph
;
24232 enum glyph_row_area area
= it
->area
;
24234 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24235 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24237 glyph
->charpos
= CHARPOS (it
->position
);
24238 glyph
->object
= it
->object
;
24239 glyph
->pixel_width
= it
->pixel_width
;
24240 glyph
->ascent
= glyph_ascent
;
24241 glyph
->descent
= it
->descent
;
24242 glyph
->voffset
= it
->voffset
;
24243 glyph
->type
= XWIDGET_GLYPH
;
24245 glyph
->multibyte_p
= it
->multibyte_p
;
24246 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24247 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24248 glyph
->overlaps_vertically_p
= 0;
24249 glyph
->padding_p
= 0;
24250 glyph
->glyph_not_available_p
= 0;
24251 glyph
->face_id
= it
->face_id
;
24252 glyph
->u
.xwidget
= it
->xwidget
;
24253 //assert_valid_xwidget_id(glyph->u.xwidget_id,"produce_xwidget_glyph");
24254 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24255 ++it
->glyph_row
->used
[area
];
24258 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24263 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
24264 of the glyph, WIDTH and HEIGHT are the width and height of the
24265 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
24268 append_stretch_glyph (struct it
*it
, Lisp_Object object
,
24269 int width
, int height
, int ascent
)
24271 struct glyph
*glyph
;
24272 enum glyph_row_area area
= it
->area
;
24274 eassert (ascent
>= 0 && ascent
<= height
);
24276 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24277 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24279 /* If the glyph row is reversed, we need to prepend the glyph
24280 rather than append it. */
24281 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24285 /* Make room for the additional glyph. */
24286 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
24288 glyph
= it
->glyph_row
->glyphs
[area
];
24290 glyph
->charpos
= CHARPOS (it
->position
);
24291 glyph
->object
= object
;
24292 glyph
->pixel_width
= width
;
24293 glyph
->ascent
= ascent
;
24294 glyph
->descent
= height
- ascent
;
24295 glyph
->voffset
= it
->voffset
;
24296 glyph
->type
= STRETCH_GLYPH
;
24297 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24298 glyph
->multibyte_p
= it
->multibyte_p
;
24299 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24300 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24301 glyph
->overlaps_vertically_p
= 0;
24302 glyph
->padding_p
= 0;
24303 glyph
->glyph_not_available_p
= 0;
24304 glyph
->face_id
= it
->face_id
;
24305 glyph
->u
.stretch
.ascent
= ascent
;
24306 glyph
->u
.stretch
.height
= height
;
24307 glyph
->slice
.img
= null_glyph_slice
;
24308 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24311 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24312 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24314 glyph
->bidi_type
= it
->bidi_it
.type
;
24318 glyph
->resolved_level
= 0;
24319 glyph
->bidi_type
= UNKNOWN_BT
;
24321 ++it
->glyph_row
->used
[area
];
24324 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24327 #endif /* HAVE_WINDOW_SYSTEM */
24329 /* Produce a stretch glyph for iterator IT. IT->object is the value
24330 of the glyph property displayed. The value must be a list
24331 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
24334 1. `:width WIDTH' specifies that the space should be WIDTH *
24335 canonical char width wide. WIDTH may be an integer or floating
24338 2. `:relative-width FACTOR' specifies that the width of the stretch
24339 should be computed from the width of the first character having the
24340 `glyph' property, and should be FACTOR times that width.
24342 3. `:align-to HPOS' specifies that the space should be wide enough
24343 to reach HPOS, a value in canonical character units.
24345 Exactly one of the above pairs must be present.
24347 4. `:height HEIGHT' specifies that the height of the stretch produced
24348 should be HEIGHT, measured in canonical character units.
24350 5. `:relative-height FACTOR' specifies that the height of the
24351 stretch should be FACTOR times the height of the characters having
24352 the glyph property.
24354 Either none or exactly one of 4 or 5 must be present.
24356 6. `:ascent ASCENT' specifies that ASCENT percent of the height
24357 of the stretch should be used for the ascent of the stretch.
24358 ASCENT must be in the range 0 <= ASCENT <= 100. */
24361 produce_stretch_glyph (struct it
*it
)
24363 /* (space :width WIDTH :height HEIGHT ...) */
24364 Lisp_Object prop
, plist
;
24365 int width
= 0, height
= 0, align_to
= -1;
24366 int zero_width_ok_p
= 0;
24368 struct font
*font
= NULL
;
24370 #ifdef HAVE_WINDOW_SYSTEM
24372 int zero_height_ok_p
= 0;
24374 if (FRAME_WINDOW_P (it
->f
))
24376 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24377 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24378 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24382 /* List should start with `space'. */
24383 eassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
24384 plist
= XCDR (it
->object
);
24386 /* Compute the width of the stretch. */
24387 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
24388 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
24390 /* Absolute width `:width WIDTH' specified and valid. */
24391 zero_width_ok_p
= 1;
24394 #ifdef HAVE_WINDOW_SYSTEM
24395 else if (FRAME_WINDOW_P (it
->f
)
24396 && (prop
= Fplist_get (plist
, QCrelative_width
), NUMVAL (prop
) > 0))
24398 /* Relative width `:relative-width FACTOR' specified and valid.
24399 Compute the width of the characters having the `glyph'
24402 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
24405 if (it
->multibyte_p
)
24406 it2
.c
= it2
.char_to_display
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
24409 it2
.c
= it2
.char_to_display
= *p
, it2
.len
= 1;
24410 if (! ASCII_CHAR_P (it2
.c
))
24411 it2
.char_to_display
= BYTE8_TO_CHAR (it2
.c
);
24414 it2
.glyph_row
= NULL
;
24415 it2
.what
= IT_CHARACTER
;
24416 x_produce_glyphs (&it2
);
24417 width
= NUMVAL (prop
) * it2
.pixel_width
;
24419 #endif /* HAVE_WINDOW_SYSTEM */
24420 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
24421 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
24423 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
24424 align_to
= (align_to
< 0
24426 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
24427 else if (align_to
< 0)
24428 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
24429 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
24430 zero_width_ok_p
= 1;
24433 /* Nothing specified -> width defaults to canonical char width. */
24434 width
= FRAME_COLUMN_WIDTH (it
->f
);
24436 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
24439 #ifdef HAVE_WINDOW_SYSTEM
24440 /* Compute height. */
24441 if (FRAME_WINDOW_P (it
->f
))
24443 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
24444 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
24447 zero_height_ok_p
= 1;
24449 else if (prop
= Fplist_get (plist
, QCrelative_height
),
24451 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
24453 height
= FONT_HEIGHT (font
);
24455 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
24458 /* Compute percentage of height used for ascent. If
24459 `:ascent ASCENT' is present and valid, use that. Otherwise,
24460 derive the ascent from the font in use. */
24461 if (prop
= Fplist_get (plist
, QCascent
),
24462 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
24463 ascent
= height
* NUMVAL (prop
) / 100.0;
24464 else if (!NILP (prop
)
24465 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
24466 ascent
= min (max (0, (int)tem
), height
);
24468 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
24471 #endif /* HAVE_WINDOW_SYSTEM */
24474 if (width
> 0 && it
->line_wrap
!= TRUNCATE
24475 && it
->current_x
+ width
> it
->last_visible_x
)
24477 width
= it
->last_visible_x
- it
->current_x
;
24478 #ifdef HAVE_WINDOW_SYSTEM
24479 /* Subtract one more pixel from the stretch width, but only on
24480 GUI frames, since on a TTY each glyph is one "pixel" wide. */
24481 width
-= FRAME_WINDOW_P (it
->f
);
24485 if (width
> 0 && height
> 0 && it
->glyph_row
)
24487 Lisp_Object o_object
= it
->object
;
24488 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
24491 if (!STRINGP (object
))
24492 object
= it
->w
->buffer
;
24493 #ifdef HAVE_WINDOW_SYSTEM
24494 if (FRAME_WINDOW_P (it
->f
))
24495 append_stretch_glyph (it
, object
, width
, height
, ascent
);
24499 it
->object
= object
;
24500 it
->char_to_display
= ' ';
24501 it
->pixel_width
= it
->len
= 1;
24503 tty_append_glyph (it
);
24504 it
->object
= o_object
;
24508 it
->pixel_width
= width
;
24509 #ifdef HAVE_WINDOW_SYSTEM
24510 if (FRAME_WINDOW_P (it
->f
))
24512 it
->ascent
= it
->phys_ascent
= ascent
;
24513 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
24514 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
24515 take_vertical_position_into_account (it
);
24519 it
->nglyphs
= width
;
24522 /* Get information about special display element WHAT in an
24523 environment described by IT. WHAT is one of IT_TRUNCATION or
24524 IT_CONTINUATION. Maybe produce glyphs for WHAT if IT has a
24525 non-null glyph_row member. This function ensures that fields like
24526 face_id, c, len of IT are left untouched. */
24529 produce_special_glyphs (struct it
*it
, enum display_element_type what
)
24536 temp_it
.object
= make_number (0);
24537 memset (&temp_it
.current
, 0, sizeof temp_it
.current
);
24539 if (what
== IT_CONTINUATION
)
24541 /* Continuation glyph. For R2L lines, we mirror it by hand. */
24542 if (it
->bidi_it
.paragraph_dir
== R2L
)
24543 SET_GLYPH_FROM_CHAR (glyph
, '/');
24545 SET_GLYPH_FROM_CHAR (glyph
, '\\');
24547 && (gc
= DISP_CONTINUE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
24549 /* FIXME: Should we mirror GC for R2L lines? */
24550 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
24551 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
24554 else if (what
== IT_TRUNCATION
)
24556 /* Truncation glyph. */
24557 SET_GLYPH_FROM_CHAR (glyph
, '$');
24559 && (gc
= DISP_TRUNC_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
24561 /* FIXME: Should we mirror GC for R2L lines? */
24562 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
24563 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
24569 #ifdef HAVE_WINDOW_SYSTEM
24570 /* On a GUI frame, when the right fringe (left fringe for R2L rows)
24571 is turned off, we precede the truncation/continuation glyphs by a
24572 stretch glyph whose width is computed such that these special
24573 glyphs are aligned at the window margin, even when very different
24574 fonts are used in different glyph rows. */
24575 if (FRAME_WINDOW_P (temp_it
.f
)
24576 /* init_iterator calls this with it->glyph_row == NULL, and it
24577 wants only the pixel width of the truncation/continuation
24579 && temp_it
.glyph_row
24580 /* insert_left_trunc_glyphs calls us at the beginning of the
24581 row, and it has its own calculation of the stretch glyph
24583 && temp_it
.glyph_row
->used
[TEXT_AREA
] > 0
24584 && (temp_it
.glyph_row
->reversed_p
24585 ? WINDOW_LEFT_FRINGE_WIDTH (temp_it
.w
)
24586 : WINDOW_RIGHT_FRINGE_WIDTH (temp_it
.w
)) == 0)
24588 int stretch_width
= temp_it
.last_visible_x
- temp_it
.current_x
;
24590 if (stretch_width
> 0)
24592 struct face
*face
= FACE_FROM_ID (temp_it
.f
, temp_it
.face_id
);
24593 struct font
*font
=
24594 face
->font
? face
->font
: FRAME_FONT (temp_it
.f
);
24595 int stretch_ascent
=
24596 (((temp_it
.ascent
+ temp_it
.descent
)
24597 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
24599 append_stretch_glyph (&temp_it
, make_number (0), stretch_width
,
24600 temp_it
.ascent
+ temp_it
.descent
,
24607 temp_it
.what
= IT_CHARACTER
;
24609 temp_it
.c
= temp_it
.char_to_display
= GLYPH_CHAR (glyph
);
24610 temp_it
.face_id
= GLYPH_FACE (glyph
);
24611 temp_it
.len
= CHAR_BYTES (temp_it
.c
);
24613 PRODUCE_GLYPHS (&temp_it
);
24614 it
->pixel_width
= temp_it
.pixel_width
;
24615 it
->nglyphs
= temp_it
.pixel_width
;
24618 #ifdef HAVE_WINDOW_SYSTEM
24620 /* Calculate line-height and line-spacing properties.
24621 An integer value specifies explicit pixel value.
24622 A float value specifies relative value to current face height.
24623 A cons (float . face-name) specifies relative value to
24624 height of specified face font.
24626 Returns height in pixels, or nil. */
24630 calc_line_height_property (struct it
*it
, Lisp_Object val
, struct font
*font
,
24631 int boff
, int override
)
24633 Lisp_Object face_name
= Qnil
;
24634 int ascent
, descent
, height
;
24636 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
24641 face_name
= XCAR (val
);
24643 if (!NUMBERP (val
))
24644 val
= make_number (1);
24645 if (NILP (face_name
))
24647 height
= it
->ascent
+ it
->descent
;
24652 if (NILP (face_name
))
24654 font
= FRAME_FONT (it
->f
);
24655 boff
= FRAME_BASELINE_OFFSET (it
->f
);
24657 else if (EQ (face_name
, Qt
))
24666 face_id
= lookup_named_face (it
->f
, face_name
, 0);
24668 return make_number (-1);
24670 face
= FACE_FROM_ID (it
->f
, face_id
);
24673 return make_number (-1);
24674 boff
= font
->baseline_offset
;
24675 if (font
->vertical_centering
)
24676 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
24679 ascent
= FONT_BASE (font
) + boff
;
24680 descent
= FONT_DESCENT (font
) - boff
;
24684 it
->override_ascent
= ascent
;
24685 it
->override_descent
= descent
;
24686 it
->override_boff
= boff
;
24689 height
= ascent
+ descent
;
24693 height
= (int)(XFLOAT_DATA (val
) * height
);
24694 else if (INTEGERP (val
))
24695 height
*= XINT (val
);
24697 return make_number (height
);
24701 /* Append a glyph for a glyphless character to IT->glyph_row. FACE_ID
24702 is a face ID to be used for the glyph. FOR_NO_FONT is nonzero if
24703 and only if this is for a character for which no font was found.
24705 If the display method (it->glyphless_method) is
24706 GLYPHLESS_DISPLAY_ACRONYM or GLYPHLESS_DISPLAY_HEX_CODE, LEN is a
24707 length of the acronym or the hexadecimal string, UPPER_XOFF and
24708 UPPER_YOFF are pixel offsets for the upper part of the string,
24709 LOWER_XOFF and LOWER_YOFF are for the lower part.
24711 For the other display methods, LEN through LOWER_YOFF are zero. */
24714 append_glyphless_glyph (struct it
*it
, int face_id
, int for_no_font
, int len
,
24715 short upper_xoff
, short upper_yoff
,
24716 short lower_xoff
, short lower_yoff
)
24718 struct glyph
*glyph
;
24719 enum glyph_row_area area
= it
->area
;
24721 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24722 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24724 /* If the glyph row is reversed, we need to prepend the glyph
24725 rather than append it. */
24726 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24730 /* Make room for the additional glyph. */
24731 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
24733 glyph
= it
->glyph_row
->glyphs
[area
];
24735 glyph
->charpos
= CHARPOS (it
->position
);
24736 glyph
->object
= it
->object
;
24737 glyph
->pixel_width
= it
->pixel_width
;
24738 glyph
->ascent
= it
->ascent
;
24739 glyph
->descent
= it
->descent
;
24740 glyph
->voffset
= it
->voffset
;
24741 glyph
->type
= GLYPHLESS_GLYPH
;
24742 glyph
->u
.glyphless
.method
= it
->glyphless_method
;
24743 glyph
->u
.glyphless
.for_no_font
= for_no_font
;
24744 glyph
->u
.glyphless
.len
= len
;
24745 glyph
->u
.glyphless
.ch
= it
->c
;
24746 glyph
->slice
.glyphless
.upper_xoff
= upper_xoff
;
24747 glyph
->slice
.glyphless
.upper_yoff
= upper_yoff
;
24748 glyph
->slice
.glyphless
.lower_xoff
= lower_xoff
;
24749 glyph
->slice
.glyphless
.lower_yoff
= lower_yoff
;
24750 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24751 glyph
->multibyte_p
= it
->multibyte_p
;
24752 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24753 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24754 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
24755 || it
->phys_descent
> it
->descent
);
24756 glyph
->padding_p
= 0;
24757 glyph
->glyph_not_available_p
= 0;
24758 glyph
->face_id
= face_id
;
24759 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24762 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24763 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24765 glyph
->bidi_type
= it
->bidi_it
.type
;
24767 ++it
->glyph_row
->used
[area
];
24770 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24774 /* Produce a glyph for a glyphless character for iterator IT.
24775 IT->glyphless_method specifies which method to use for displaying
24776 the character. See the description of enum
24777 glyphless_display_method in dispextern.h for the detail.
24779 FOR_NO_FONT is nonzero if and only if this is for a character for
24780 which no font was found. ACRONYM, if non-nil, is an acronym string
24781 for the character. */
24784 produce_glyphless_glyph (struct it
*it
, int for_no_font
, Lisp_Object acronym
)
24789 int base_width
, base_height
, width
, height
;
24790 short upper_xoff
, upper_yoff
, lower_xoff
, lower_yoff
;
24793 /* Get the metrics of the base font. We always refer to the current
24795 face
= FACE_FROM_ID (it
->f
, it
->face_id
)->ascii_face
;
24796 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24797 it
->ascent
= FONT_BASE (font
) + font
->baseline_offset
;
24798 it
->descent
= FONT_DESCENT (font
) - font
->baseline_offset
;
24799 base_height
= it
->ascent
+ it
->descent
;
24800 base_width
= font
->average_width
;
24802 /* Get a face ID for the glyph by utilizing a cache (the same way as
24803 done for `escape-glyph' in get_next_display_element). */
24804 if (it
->f
== last_glyphless_glyph_frame
24805 && it
->face_id
== last_glyphless_glyph_face_id
)
24807 face_id
= last_glyphless_glyph_merged_face_id
;
24811 /* Merge the `glyphless-char' face into the current face. */
24812 face_id
= merge_faces (it
->f
, Qglyphless_char
, 0, it
->face_id
);
24813 last_glyphless_glyph_frame
= it
->f
;
24814 last_glyphless_glyph_face_id
= it
->face_id
;
24815 last_glyphless_glyph_merged_face_id
= face_id
;
24818 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_THIN_SPACE
)
24820 it
->pixel_width
= THIN_SPACE_WIDTH
;
24822 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
24824 else if (it
->glyphless_method
== GLYPHLESS_DISPLAY_EMPTY_BOX
)
24826 width
= CHAR_WIDTH (it
->c
);
24829 else if (width
> 4)
24831 it
->pixel_width
= base_width
* width
;
24833 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
24839 unsigned int code
[6];
24841 int ascent
, descent
;
24842 struct font_metrics metrics_upper
, metrics_lower
;
24844 face
= FACE_FROM_ID (it
->f
, face_id
);
24845 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24846 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24848 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_ACRONYM
)
24850 if (! STRINGP (acronym
) && CHAR_TABLE_P (Vglyphless_char_display
))
24851 acronym
= CHAR_TABLE_REF (Vglyphless_char_display
, it
->c
);
24852 if (CONSP (acronym
))
24853 acronym
= XCAR (acronym
);
24854 str
= STRINGP (acronym
) ? SSDATA (acronym
) : "";
24858 eassert (it
->glyphless_method
== GLYPHLESS_DISPLAY_HEX_CODE
);
24859 sprintf (buf
, "%0*X", it
->c
< 0x10000 ? 4 : 6, it
->c
);
24862 for (len
= 0; str
[len
] && ASCII_BYTE_P (str
[len
]) && len
< 6; len
++)
24863 code
[len
] = font
->driver
->encode_char (font
, str
[len
]);
24864 upper_len
= (len
+ 1) / 2;
24865 font
->driver
->text_extents (font
, code
, upper_len
,
24867 font
->driver
->text_extents (font
, code
+ upper_len
, len
- upper_len
,
24872 /* +4 is for vertical bars of a box plus 1-pixel spaces at both side. */
24873 width
= max (metrics_upper
.width
, metrics_lower
.width
) + 4;
24874 upper_xoff
= upper_yoff
= 2; /* the typical case */
24875 if (base_width
>= width
)
24877 /* Align the upper to the left, the lower to the right. */
24878 it
->pixel_width
= base_width
;
24879 lower_xoff
= base_width
- 2 - metrics_lower
.width
;
24883 /* Center the shorter one. */
24884 it
->pixel_width
= width
;
24885 if (metrics_upper
.width
>= metrics_lower
.width
)
24886 lower_xoff
= (width
- metrics_lower
.width
) / 2;
24889 /* FIXME: This code doesn't look right. It formerly was
24890 missing the "lower_xoff = 0;", which couldn't have
24891 been right since it left lower_xoff uninitialized. */
24893 upper_xoff
= (width
- metrics_upper
.width
) / 2;
24897 /* +5 is for horizontal bars of a box plus 1-pixel spaces at
24898 top, bottom, and between upper and lower strings. */
24899 height
= (metrics_upper
.ascent
+ metrics_upper
.descent
24900 + metrics_lower
.ascent
+ metrics_lower
.descent
) + 5;
24901 /* Center vertically.
24902 H:base_height, D:base_descent
24903 h:height, ld:lower_descent, la:lower_ascent, ud:upper_descent
24905 ascent = - (D - H/2 - h/2 + 1); "+ 1" for rounding up
24906 descent = D - H/2 + h/2;
24907 lower_yoff = descent - 2 - ld;
24908 upper_yoff = lower_yoff - la - 1 - ud; */
24909 ascent
= - (it
->descent
- (base_height
+ height
+ 1) / 2);
24910 descent
= it
->descent
- (base_height
- height
) / 2;
24911 lower_yoff
= descent
- 2 - metrics_lower
.descent
;
24912 upper_yoff
= (lower_yoff
- metrics_lower
.ascent
- 1
24913 - metrics_upper
.descent
);
24914 /* Don't make the height shorter than the base height. */
24915 if (height
> base_height
)
24917 it
->ascent
= ascent
;
24918 it
->descent
= descent
;
24922 it
->phys_ascent
= it
->ascent
;
24923 it
->phys_descent
= it
->descent
;
24925 append_glyphless_glyph (it
, face_id
, for_no_font
, len
,
24926 upper_xoff
, upper_yoff
,
24927 lower_xoff
, lower_yoff
);
24929 take_vertical_position_into_account (it
);
24934 Produce glyphs/get display metrics for the display element IT is
24935 loaded with. See the description of struct it in dispextern.h
24936 for an overview of struct it. */
24939 x_produce_glyphs (struct it
*it
)
24941 int extra_line_spacing
= it
->extra_line_spacing
;
24943 it
->glyph_not_available_p
= 0;
24945 if (it
->what
== IT_CHARACTER
)
24948 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24949 struct font
*font
= face
->font
;
24950 struct font_metrics
*pcm
= NULL
;
24951 int boff
; /* baseline offset */
24955 /* When no suitable font is found, display this character by
24956 the method specified in the first extra slot of
24957 Vglyphless_char_display. */
24958 Lisp_Object acronym
= lookup_glyphless_char_display (-1, it
);
24960 eassert (it
->what
== IT_GLYPHLESS
);
24961 produce_glyphless_glyph (it
, 1, STRINGP (acronym
) ? acronym
: Qnil
);
24965 boff
= font
->baseline_offset
;
24966 if (font
->vertical_centering
)
24967 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
24969 if (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t')
24975 if (it
->override_ascent
>= 0)
24977 it
->ascent
= it
->override_ascent
;
24978 it
->descent
= it
->override_descent
;
24979 boff
= it
->override_boff
;
24983 it
->ascent
= FONT_BASE (font
) + boff
;
24984 it
->descent
= FONT_DESCENT (font
) - boff
;
24987 if (get_char_glyph_code (it
->char_to_display
, font
, &char2b
))
24989 pcm
= get_per_char_metric (font
, &char2b
);
24990 if (pcm
->width
== 0
24991 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
24997 it
->phys_ascent
= pcm
->ascent
+ boff
;
24998 it
->phys_descent
= pcm
->descent
- boff
;
24999 it
->pixel_width
= pcm
->width
;
25003 it
->glyph_not_available_p
= 1;
25004 it
->phys_ascent
= it
->ascent
;
25005 it
->phys_descent
= it
->descent
;
25006 it
->pixel_width
= font
->space_width
;
25009 if (it
->constrain_row_ascent_descent_p
)
25011 if (it
->descent
> it
->max_descent
)
25013 it
->ascent
+= it
->descent
- it
->max_descent
;
25014 it
->descent
= it
->max_descent
;
25016 if (it
->ascent
> it
->max_ascent
)
25018 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
25019 it
->ascent
= it
->max_ascent
;
25021 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
25022 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
25023 extra_line_spacing
= 0;
25026 /* If this is a space inside a region of text with
25027 `space-width' property, change its width. */
25028 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
25030 it
->pixel_width
*= XFLOATINT (it
->space_width
);
25032 /* If face has a box, add the box thickness to the character
25033 height. If character has a box line to the left and/or
25034 right, add the box line width to the character's width. */
25035 if (face
->box
!= FACE_NO_BOX
)
25037 int thick
= face
->box_line_width
;
25041 it
->ascent
+= thick
;
25042 it
->descent
+= thick
;
25047 if (it
->start_of_box_run_p
)
25048 it
->pixel_width
+= thick
;
25049 if (it
->end_of_box_run_p
)
25050 it
->pixel_width
+= thick
;
25053 /* If face has an overline, add the height of the overline
25054 (1 pixel) and a 1 pixel margin to the character height. */
25055 if (face
->overline_p
)
25056 it
->ascent
+= overline_margin
;
25058 if (it
->constrain_row_ascent_descent_p
)
25060 if (it
->ascent
> it
->max_ascent
)
25061 it
->ascent
= it
->max_ascent
;
25062 if (it
->descent
> it
->max_descent
)
25063 it
->descent
= it
->max_descent
;
25066 take_vertical_position_into_account (it
);
25068 /* If we have to actually produce glyphs, do it. */
25073 /* Translate a space with a `space-width' property
25074 into a stretch glyph. */
25075 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
25076 / FONT_HEIGHT (font
));
25077 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
25078 it
->ascent
+ it
->descent
, ascent
);
25083 /* If characters with lbearing or rbearing are displayed
25084 in this line, record that fact in a flag of the
25085 glyph row. This is used to optimize X output code. */
25086 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
25087 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25089 if (! stretched_p
&& it
->pixel_width
== 0)
25090 /* We assure that all visible glyphs have at least 1-pixel
25092 it
->pixel_width
= 1;
25094 else if (it
->char_to_display
== '\n')
25096 /* A newline has no width, but we need the height of the
25097 line. But if previous part of the line sets a height,
25098 don't increase that height */
25100 Lisp_Object height
;
25101 Lisp_Object total_height
= Qnil
;
25103 it
->override_ascent
= -1;
25104 it
->pixel_width
= 0;
25107 height
= get_it_property (it
, Qline_height
);
25108 /* Split (line-height total-height) list */
25110 && CONSP (XCDR (height
))
25111 && NILP (XCDR (XCDR (height
))))
25113 total_height
= XCAR (XCDR (height
));
25114 height
= XCAR (height
);
25116 height
= calc_line_height_property (it
, height
, font
, boff
, 1);
25118 if (it
->override_ascent
>= 0)
25120 it
->ascent
= it
->override_ascent
;
25121 it
->descent
= it
->override_descent
;
25122 boff
= it
->override_boff
;
25126 it
->ascent
= FONT_BASE (font
) + boff
;
25127 it
->descent
= FONT_DESCENT (font
) - boff
;
25130 if (EQ (height
, Qt
))
25132 if (it
->descent
> it
->max_descent
)
25134 it
->ascent
+= it
->descent
- it
->max_descent
;
25135 it
->descent
= it
->max_descent
;
25137 if (it
->ascent
> it
->max_ascent
)
25139 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
25140 it
->ascent
= it
->max_ascent
;
25142 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
25143 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
25144 it
->constrain_row_ascent_descent_p
= 1;
25145 extra_line_spacing
= 0;
25149 Lisp_Object spacing
;
25151 it
->phys_ascent
= it
->ascent
;
25152 it
->phys_descent
= it
->descent
;
25154 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
25155 && face
->box
!= FACE_NO_BOX
25156 && face
->box_line_width
> 0)
25158 it
->ascent
+= face
->box_line_width
;
25159 it
->descent
+= face
->box_line_width
;
25162 && XINT (height
) > it
->ascent
+ it
->descent
)
25163 it
->ascent
= XINT (height
) - it
->descent
;
25165 if (!NILP (total_height
))
25166 spacing
= calc_line_height_property (it
, total_height
, font
, boff
, 0);
25169 spacing
= get_it_property (it
, Qline_spacing
);
25170 spacing
= calc_line_height_property (it
, spacing
, font
, boff
, 0);
25172 if (INTEGERP (spacing
))
25174 extra_line_spacing
= XINT (spacing
);
25175 if (!NILP (total_height
))
25176 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
25180 else /* i.e. (it->char_to_display == '\t') */
25182 if (font
->space_width
> 0)
25184 int tab_width
= it
->tab_width
* font
->space_width
;
25185 int x
= it
->current_x
+ it
->continuation_lines_width
;
25186 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
25188 /* If the distance from the current position to the next tab
25189 stop is less than a space character width, use the
25190 tab stop after that. */
25191 if (next_tab_x
- x
< font
->space_width
)
25192 next_tab_x
+= tab_width
;
25194 it
->pixel_width
= next_tab_x
- x
;
25196 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
25197 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
25201 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
25202 it
->ascent
+ it
->descent
, it
->ascent
);
25207 it
->pixel_width
= 0;
25212 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
25214 /* A static composition.
25216 Note: A composition is represented as one glyph in the
25217 glyph matrix. There are no padding glyphs.
25219 Important note: pixel_width, ascent, and descent are the
25220 values of what is drawn by draw_glyphs (i.e. the values of
25221 the overall glyphs composed). */
25222 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25223 int boff
; /* baseline offset */
25224 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
25225 int glyph_len
= cmp
->glyph_len
;
25226 struct font
*font
= face
->font
;
25230 /* If we have not yet calculated pixel size data of glyphs of
25231 the composition for the current face font, calculate them
25232 now. Theoretically, we have to check all fonts for the
25233 glyphs, but that requires much time and memory space. So,
25234 here we check only the font of the first glyph. This may
25235 lead to incorrect display, but it's very rare, and C-l
25236 (recenter-top-bottom) can correct the display anyway. */
25237 if (! cmp
->font
|| cmp
->font
!= font
)
25239 /* Ascent and descent of the font of the first character
25240 of this composition (adjusted by baseline offset).
25241 Ascent and descent of overall glyphs should not be less
25242 than these, respectively. */
25243 int font_ascent
, font_descent
, font_height
;
25244 /* Bounding box of the overall glyphs. */
25245 int leftmost
, rightmost
, lowest
, highest
;
25246 int lbearing
, rbearing
;
25247 int i
, width
, ascent
, descent
;
25248 int left_padded
= 0, right_padded
= 0;
25249 int c
IF_LINT (= 0); /* cmp->glyph_len can't be zero; see Bug#8512 */
25251 struct font_metrics
*pcm
;
25252 int font_not_found_p
;
25255 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
25256 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
25258 if (glyph_len
< cmp
->glyph_len
)
25260 for (i
= 0; i
< glyph_len
; i
++)
25262 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
25264 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
25269 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
25270 : IT_CHARPOS (*it
));
25271 /* If no suitable font is found, use the default font. */
25272 font_not_found_p
= font
== NULL
;
25273 if (font_not_found_p
)
25275 face
= face
->ascii_face
;
25278 boff
= font
->baseline_offset
;
25279 if (font
->vertical_centering
)
25280 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
25281 font_ascent
= FONT_BASE (font
) + boff
;
25282 font_descent
= FONT_DESCENT (font
) - boff
;
25283 font_height
= FONT_HEIGHT (font
);
25288 if (! font_not_found_p
)
25290 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
25292 pcm
= get_per_char_metric (font
, &char2b
);
25295 /* Initialize the bounding box. */
25298 width
= cmp
->glyph_len
> 0 ? pcm
->width
: 0;
25299 ascent
= pcm
->ascent
;
25300 descent
= pcm
->descent
;
25301 lbearing
= pcm
->lbearing
;
25302 rbearing
= pcm
->rbearing
;
25306 width
= cmp
->glyph_len
> 0 ? font
->space_width
: 0;
25307 ascent
= FONT_BASE (font
);
25308 descent
= FONT_DESCENT (font
);
25315 lowest
= - descent
+ boff
;
25316 highest
= ascent
+ boff
;
25318 if (! font_not_found_p
25319 && font
->default_ascent
25320 && CHAR_TABLE_P (Vuse_default_ascent
)
25321 && !NILP (Faref (Vuse_default_ascent
,
25322 make_number (it
->char_to_display
))))
25323 highest
= font
->default_ascent
+ boff
;
25325 /* Draw the first glyph at the normal position. It may be
25326 shifted to right later if some other glyphs are drawn
25328 cmp
->offsets
[i
* 2] = 0;
25329 cmp
->offsets
[i
* 2 + 1] = boff
;
25330 cmp
->lbearing
= lbearing
;
25331 cmp
->rbearing
= rbearing
;
25333 /* Set cmp->offsets for the remaining glyphs. */
25334 for (i
++; i
< glyph_len
; i
++)
25336 int left
, right
, btm
, top
;
25337 int ch
= COMPOSITION_GLYPH (cmp
, i
);
25339 struct face
*this_face
;
25343 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
25344 this_face
= FACE_FROM_ID (it
->f
, face_id
);
25345 font
= this_face
->font
;
25351 get_char_face_and_encoding (it
->f
, ch
, face_id
,
25353 pcm
= get_per_char_metric (font
, &char2b
);
25356 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
25359 width
= pcm
->width
;
25360 ascent
= pcm
->ascent
;
25361 descent
= pcm
->descent
;
25362 lbearing
= pcm
->lbearing
;
25363 rbearing
= pcm
->rbearing
;
25364 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
25366 /* Relative composition with or without
25367 alternate chars. */
25368 left
= (leftmost
+ rightmost
- width
) / 2;
25369 btm
= - descent
+ boff
;
25370 if (font
->relative_compose
25371 && (! CHAR_TABLE_P (Vignore_relative_composition
)
25372 || NILP (Faref (Vignore_relative_composition
,
25373 make_number (ch
)))))
25376 if (- descent
>= font
->relative_compose
)
25377 /* One extra pixel between two glyphs. */
25379 else if (ascent
<= 0)
25380 /* One extra pixel between two glyphs. */
25381 btm
= lowest
- 1 - ascent
- descent
;
25386 /* A composition rule is specified by an integer
25387 value that encodes global and new reference
25388 points (GREF and NREF). GREF and NREF are
25389 specified by numbers as below:
25391 0---1---2 -- ascent
25395 9--10--11 -- center
25397 ---3---4---5--- baseline
25399 6---7---8 -- descent
25401 int rule
= COMPOSITION_RULE (cmp
, i
);
25402 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
25404 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
25405 grefx
= gref
% 3, nrefx
= nref
% 3;
25406 grefy
= gref
/ 3, nrefy
= nref
/ 3;
25408 xoff
= font_height
* (xoff
- 128) / 256;
25410 yoff
= font_height
* (yoff
- 128) / 256;
25413 + grefx
* (rightmost
- leftmost
) / 2
25414 - nrefx
* width
/ 2
25417 btm
= ((grefy
== 0 ? highest
25419 : grefy
== 2 ? lowest
25420 : (highest
+ lowest
) / 2)
25421 - (nrefy
== 0 ? ascent
+ descent
25422 : nrefy
== 1 ? descent
- boff
25424 : (ascent
+ descent
) / 2)
25428 cmp
->offsets
[i
* 2] = left
;
25429 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
25431 /* Update the bounding box of the overall glyphs. */
25434 right
= left
+ width
;
25435 if (left
< leftmost
)
25437 if (right
> rightmost
)
25440 top
= btm
+ descent
+ ascent
;
25446 if (cmp
->lbearing
> left
+ lbearing
)
25447 cmp
->lbearing
= left
+ lbearing
;
25448 if (cmp
->rbearing
< left
+ rbearing
)
25449 cmp
->rbearing
= left
+ rbearing
;
25453 /* If there are glyphs whose x-offsets are negative,
25454 shift all glyphs to the right and make all x-offsets
25458 for (i
= 0; i
< cmp
->glyph_len
; i
++)
25459 cmp
->offsets
[i
* 2] -= leftmost
;
25460 rightmost
-= leftmost
;
25461 cmp
->lbearing
-= leftmost
;
25462 cmp
->rbearing
-= leftmost
;
25465 if (left_padded
&& cmp
->lbearing
< 0)
25467 for (i
= 0; i
< cmp
->glyph_len
; i
++)
25468 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
25469 rightmost
-= cmp
->lbearing
;
25470 cmp
->rbearing
-= cmp
->lbearing
;
25473 if (right_padded
&& rightmost
< cmp
->rbearing
)
25475 rightmost
= cmp
->rbearing
;
25478 cmp
->pixel_width
= rightmost
;
25479 cmp
->ascent
= highest
;
25480 cmp
->descent
= - lowest
;
25481 if (cmp
->ascent
< font_ascent
)
25482 cmp
->ascent
= font_ascent
;
25483 if (cmp
->descent
< font_descent
)
25484 cmp
->descent
= font_descent
;
25488 && (cmp
->lbearing
< 0
25489 || cmp
->rbearing
> cmp
->pixel_width
))
25490 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25492 it
->pixel_width
= cmp
->pixel_width
;
25493 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
25494 it
->descent
= it
->phys_descent
= cmp
->descent
;
25495 if (face
->box
!= FACE_NO_BOX
)
25497 int thick
= face
->box_line_width
;
25501 it
->ascent
+= thick
;
25502 it
->descent
+= thick
;
25507 if (it
->start_of_box_run_p
)
25508 it
->pixel_width
+= thick
;
25509 if (it
->end_of_box_run_p
)
25510 it
->pixel_width
+= thick
;
25513 /* If face has an overline, add the height of the overline
25514 (1 pixel) and a 1 pixel margin to the character height. */
25515 if (face
->overline_p
)
25516 it
->ascent
+= overline_margin
;
25518 take_vertical_position_into_account (it
);
25519 if (it
->ascent
< 0)
25521 if (it
->descent
< 0)
25524 if (it
->glyph_row
&& cmp
->glyph_len
> 0)
25525 append_composite_glyph (it
);
25527 else if (it
->what
== IT_COMPOSITION
)
25529 /* A dynamic (automatic) composition. */
25530 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25531 Lisp_Object gstring
;
25532 struct font_metrics metrics
;
25536 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
25538 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
25541 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
25542 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25543 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
25544 it
->descent
= it
->phys_descent
= metrics
.descent
;
25545 if (face
->box
!= FACE_NO_BOX
)
25547 int thick
= face
->box_line_width
;
25551 it
->ascent
+= thick
;
25552 it
->descent
+= thick
;
25557 if (it
->start_of_box_run_p
)
25558 it
->pixel_width
+= thick
;
25559 if (it
->end_of_box_run_p
)
25560 it
->pixel_width
+= thick
;
25562 /* If face has an overline, add the height of the overline
25563 (1 pixel) and a 1 pixel margin to the character height. */
25564 if (face
->overline_p
)
25565 it
->ascent
+= overline_margin
;
25566 take_vertical_position_into_account (it
);
25567 if (it
->ascent
< 0)
25569 if (it
->descent
< 0)
25573 append_composite_glyph (it
);
25575 else if (it
->what
== IT_GLYPHLESS
)
25576 produce_glyphless_glyph (it
, 0, Qnil
);
25577 else if (it
->what
== IT_IMAGE
)
25578 produce_image_glyph (it
);
25579 else if (it
->what
== IT_STRETCH
)
25580 produce_stretch_glyph (it
);
25581 #ifdef HAVE_XWIDGETS
25582 else if (it
->what
== IT_XWIDGET
)
25583 produce_xwidget_glyph (it
);
25586 /* Accumulate dimensions. Note: can't assume that it->descent > 0
25587 because this isn't true for images with `:ascent 100'. */
25588 eassert (it
->ascent
>= 0 && it
->descent
>= 0);
25589 if (it
->area
== TEXT_AREA
)
25590 it
->current_x
+= it
->pixel_width
;
25592 if (extra_line_spacing
> 0)
25594 it
->descent
+= extra_line_spacing
;
25595 if (extra_line_spacing
> it
->max_extra_line_spacing
)
25596 it
->max_extra_line_spacing
= extra_line_spacing
;
25599 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
25600 it
->max_descent
= max (it
->max_descent
, it
->descent
);
25601 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
25602 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
25606 Output LEN glyphs starting at START at the nominal cursor position.
25607 Advance the nominal cursor over the text. The global variable
25608 updated_window contains the window being updated, updated_row is
25609 the glyph row being updated, and updated_area is the area of that
25610 row being updated. */
25613 x_write_glyphs (struct glyph
*start
, int len
)
25615 int x
, hpos
, chpos
= updated_window
->phys_cursor
.hpos
;
25617 eassert (updated_window
&& updated_row
);
25618 /* When the window is hscrolled, cursor hpos can legitimately be out
25619 of bounds, but we draw the cursor at the corresponding window
25620 margin in that case. */
25621 if (!updated_row
->reversed_p
&& chpos
< 0)
25623 if (updated_row
->reversed_p
&& chpos
>= updated_row
->used
[TEXT_AREA
])
25624 chpos
= updated_row
->used
[TEXT_AREA
] - 1;
25628 /* Write glyphs. */
25630 hpos
= start
- updated_row
->glyphs
[updated_area
];
25631 x
= draw_glyphs (updated_window
, output_cursor
.x
,
25632 updated_row
, updated_area
,
25634 DRAW_NORMAL_TEXT
, 0);
25636 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
25637 if (updated_area
== TEXT_AREA
25638 && updated_window
->phys_cursor_on_p
25639 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
25641 && chpos
< hpos
+ len
)
25642 updated_window
->phys_cursor_on_p
= 0;
25646 /* Advance the output cursor. */
25647 output_cursor
.hpos
+= len
;
25648 output_cursor
.x
= x
;
25653 Insert LEN glyphs from START at the nominal cursor position. */
25656 x_insert_glyphs (struct glyph
*start
, int len
)
25660 int line_height
, shift_by_width
, shifted_region_width
;
25661 struct glyph_row
*row
;
25662 struct glyph
*glyph
;
25663 int frame_x
, frame_y
;
25666 eassert (updated_window
&& updated_row
);
25668 w
= updated_window
;
25669 f
= XFRAME (WINDOW_FRAME (w
));
25671 /* Get the height of the line we are in. */
25673 line_height
= row
->height
;
25675 /* Get the width of the glyphs to insert. */
25676 shift_by_width
= 0;
25677 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
25678 shift_by_width
+= glyph
->pixel_width
;
25680 /* Get the width of the region to shift right. */
25681 shifted_region_width
= (window_box_width (w
, updated_area
)
25686 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
25687 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
25689 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
25690 line_height
, shift_by_width
);
25692 /* Write the glyphs. */
25693 hpos
= start
- row
->glyphs
[updated_area
];
25694 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
25696 DRAW_NORMAL_TEXT
, 0);
25698 /* Advance the output cursor. */
25699 output_cursor
.hpos
+= len
;
25700 output_cursor
.x
+= shift_by_width
;
25706 Erase the current text line from the nominal cursor position
25707 (inclusive) to pixel column TO_X (exclusive). The idea is that
25708 everything from TO_X onward is already erased.
25710 TO_X is a pixel position relative to updated_area of
25711 updated_window. TO_X == -1 means clear to the end of this area. */
25714 x_clear_end_of_line (int to_x
)
25717 struct window
*w
= updated_window
;
25718 int max_x
, min_y
, max_y
;
25719 int from_x
, from_y
, to_y
;
25721 eassert (updated_window
&& updated_row
);
25722 f
= XFRAME (w
->frame
);
25724 if (updated_row
->full_width_p
)
25725 max_x
= WINDOW_TOTAL_WIDTH (w
);
25727 max_x
= window_box_width (w
, updated_area
);
25728 max_y
= window_text_bottom_y (w
);
25730 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
25731 of window. For TO_X > 0, truncate to end of drawing area. */
25737 to_x
= min (to_x
, max_x
);
25739 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
25741 /* Notice if the cursor will be cleared by this operation. */
25742 if (!updated_row
->full_width_p
)
25743 notice_overwritten_cursor (w
, updated_area
,
25744 output_cursor
.x
, -1,
25746 MATRIX_ROW_BOTTOM_Y (updated_row
));
25748 from_x
= output_cursor
.x
;
25750 /* Translate to frame coordinates. */
25751 if (updated_row
->full_width_p
)
25753 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
25754 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
25758 int area_left
= window_box_left (w
, updated_area
);
25759 from_x
+= area_left
;
25763 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
25764 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
25765 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
25767 /* Prevent inadvertently clearing to end of the X window. */
25768 if (to_x
> from_x
&& to_y
> from_y
)
25771 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
25772 to_x
- from_x
, to_y
- from_y
);
25777 #endif /* HAVE_WINDOW_SYSTEM */
25781 /***********************************************************************
25783 ***********************************************************************/
25785 /* Value is the internal representation of the specified cursor type
25786 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
25787 of the bar cursor. */
25789 static enum text_cursor_kinds
25790 get_specified_cursor_type (Lisp_Object arg
, int *width
)
25792 enum text_cursor_kinds type
;
25797 if (EQ (arg
, Qbox
))
25798 return FILLED_BOX_CURSOR
;
25800 if (EQ (arg
, Qhollow
))
25801 return HOLLOW_BOX_CURSOR
;
25803 if (EQ (arg
, Qbar
))
25810 && EQ (XCAR (arg
), Qbar
)
25811 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
25813 *width
= XINT (XCDR (arg
));
25817 if (EQ (arg
, Qhbar
))
25820 return HBAR_CURSOR
;
25824 && EQ (XCAR (arg
), Qhbar
)
25825 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
25827 *width
= XINT (XCDR (arg
));
25828 return HBAR_CURSOR
;
25831 /* Treat anything unknown as "hollow box cursor".
25832 It was bad to signal an error; people have trouble fixing
25833 .Xdefaults with Emacs, when it has something bad in it. */
25834 type
= HOLLOW_BOX_CURSOR
;
25839 /* Set the default cursor types for specified frame. */
25841 set_frame_cursor_types (struct frame
*f
, Lisp_Object arg
)
25846 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
25847 FRAME_CURSOR_WIDTH (f
) = width
;
25849 /* By default, set up the blink-off state depending on the on-state. */
25851 tem
= Fassoc (arg
, Vblink_cursor_alist
);
25854 FRAME_BLINK_OFF_CURSOR (f
)
25855 = get_specified_cursor_type (XCDR (tem
), &width
);
25856 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
25859 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
25863 #ifdef HAVE_WINDOW_SYSTEM
25865 /* Return the cursor we want to be displayed in window W. Return
25866 width of bar/hbar cursor through WIDTH arg. Return with
25867 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
25868 (i.e. if the `system caret' should track this cursor).
25870 In a mini-buffer window, we want the cursor only to appear if we
25871 are reading input from this window. For the selected window, we
25872 want the cursor type given by the frame parameter or buffer local
25873 setting of cursor-type. If explicitly marked off, draw no cursor.
25874 In all other cases, we want a hollow box cursor. */
25876 static enum text_cursor_kinds
25877 get_window_cursor_type (struct window
*w
, struct glyph
*glyph
, int *width
,
25878 int *active_cursor
)
25880 struct frame
*f
= XFRAME (w
->frame
);
25881 struct buffer
*b
= XBUFFER (w
->buffer
);
25882 int cursor_type
= DEFAULT_CURSOR
;
25883 Lisp_Object alt_cursor
;
25884 int non_selected
= 0;
25886 *active_cursor
= 1;
25889 if (cursor_in_echo_area
25890 && FRAME_HAS_MINIBUF_P (f
)
25891 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
25893 if (w
== XWINDOW (echo_area_window
))
25895 if (EQ (BVAR (b
, cursor_type
), Qt
) || NILP (BVAR (b
, cursor_type
)))
25897 *width
= FRAME_CURSOR_WIDTH (f
);
25898 return FRAME_DESIRED_CURSOR (f
);
25901 return get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
25904 *active_cursor
= 0;
25908 /* Detect a nonselected window or nonselected frame. */
25909 else if (w
!= XWINDOW (f
->selected_window
)
25910 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)
25912 *active_cursor
= 0;
25914 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
25920 /* Never display a cursor in a window in which cursor-type is nil. */
25921 if (NILP (BVAR (b
, cursor_type
)))
25924 /* Get the normal cursor type for this window. */
25925 if (EQ (BVAR (b
, cursor_type
), Qt
))
25927 cursor_type
= FRAME_DESIRED_CURSOR (f
);
25928 *width
= FRAME_CURSOR_WIDTH (f
);
25931 cursor_type
= get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
25933 /* Use cursor-in-non-selected-windows instead
25934 for non-selected window or frame. */
25937 alt_cursor
= BVAR (b
, cursor_in_non_selected_windows
);
25938 if (!EQ (Qt
, alt_cursor
))
25939 return get_specified_cursor_type (alt_cursor
, width
);
25940 /* t means modify the normal cursor type. */
25941 if (cursor_type
== FILLED_BOX_CURSOR
)
25942 cursor_type
= HOLLOW_BOX_CURSOR
;
25943 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
25945 return cursor_type
;
25948 /* Use normal cursor if not blinked off. */
25949 if (!w
->cursor_off_p
)
25952 #ifdef HAVE_XWIDGETS
25953 if (glyph
!= NULL
&& glyph
->type
== XWIDGET_GLYPH
){
25954 //printf("attempt xwidget cursor avoidance in get_window_cursor_type\n");
25958 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
25960 if (cursor_type
== FILLED_BOX_CURSOR
)
25962 /* Using a block cursor on large images can be very annoying.
25963 So use a hollow cursor for "large" images.
25964 If image is not transparent (no mask), also use hollow cursor. */
25965 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
25966 if (img
!= NULL
&& IMAGEP (img
->spec
))
25968 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
25969 where N = size of default frame font size.
25970 This should cover most of the "tiny" icons people may use. */
25972 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
25973 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
25974 cursor_type
= HOLLOW_BOX_CURSOR
;
25977 else if (cursor_type
!= NO_CURSOR
)
25979 /* Display current only supports BOX and HOLLOW cursors for images.
25980 So for now, unconditionally use a HOLLOW cursor when cursor is
25981 not a solid box cursor. */
25982 cursor_type
= HOLLOW_BOX_CURSOR
;
25985 return cursor_type
;
25988 /* Cursor is blinked off, so determine how to "toggle" it. */
25990 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
25991 if ((alt_cursor
= Fassoc (BVAR (b
, cursor_type
), Vblink_cursor_alist
), !NILP (alt_cursor
)))
25992 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
25994 /* Then see if frame has specified a specific blink off cursor type. */
25995 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
25997 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
25998 return FRAME_BLINK_OFF_CURSOR (f
);
26002 /* Some people liked having a permanently visible blinking cursor,
26003 while others had very strong opinions against it. So it was
26004 decided to remove it. KFS 2003-09-03 */
26006 /* Finally perform built-in cursor blinking:
26007 filled box <-> hollow box
26008 wide [h]bar <-> narrow [h]bar
26009 narrow [h]bar <-> no cursor
26010 other type <-> no cursor */
26012 if (cursor_type
== FILLED_BOX_CURSOR
)
26013 return HOLLOW_BOX_CURSOR
;
26015 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
26018 return cursor_type
;
26026 /* Notice when the text cursor of window W has been completely
26027 overwritten by a drawing operation that outputs glyphs in AREA
26028 starting at X0 and ending at X1 in the line starting at Y0 and
26029 ending at Y1. X coordinates are area-relative. X1 < 0 means all
26030 the rest of the line after X0 has been written. Y coordinates
26031 are window-relative. */
26034 notice_overwritten_cursor (struct window
*w
, enum glyph_row_area area
,
26035 int x0
, int x1
, int y0
, int y1
)
26037 int cx0
, cx1
, cy0
, cy1
;
26038 struct glyph_row
*row
;
26040 if (!w
->phys_cursor_on_p
)
26042 if (area
!= TEXT_AREA
)
26045 if (w
->phys_cursor
.vpos
< 0
26046 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
26047 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
26048 !(row
->enabled_p
&& row
->displays_text_p
)))
26051 if (row
->cursor_in_fringe_p
)
26053 row
->cursor_in_fringe_p
= 0;
26054 draw_fringe_bitmap (w
, row
, row
->reversed_p
);
26055 w
->phys_cursor_on_p
= 0;
26059 cx0
= w
->phys_cursor
.x
;
26060 cx1
= cx0
+ w
->phys_cursor_width
;
26061 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
26064 /* The cursor image will be completely removed from the
26065 screen if the output area intersects the cursor area in
26066 y-direction. When we draw in [y0 y1[, and some part of
26067 the cursor is at y < y0, that part must have been drawn
26068 before. When scrolling, the cursor is erased before
26069 actually scrolling, so we don't come here. When not
26070 scrolling, the rows above the old cursor row must have
26071 changed, and in this case these rows must have written
26072 over the cursor image.
26074 Likewise if part of the cursor is below y1, with the
26075 exception of the cursor being in the first blank row at
26076 the buffer and window end because update_text_area
26077 doesn't draw that row. (Except when it does, but
26078 that's handled in update_text_area.) */
26080 cy0
= w
->phys_cursor
.y
;
26081 cy1
= cy0
+ w
->phys_cursor_height
;
26082 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
26085 w
->phys_cursor_on_p
= 0;
26088 #endif /* HAVE_WINDOW_SYSTEM */
26091 /************************************************************************
26093 ************************************************************************/
26095 #ifdef HAVE_WINDOW_SYSTEM
26098 Fix the display of area AREA of overlapping row ROW in window W
26099 with respect to the overlapping part OVERLAPS. */
26102 x_fix_overlapping_area (struct window
*w
, struct glyph_row
*row
,
26103 enum glyph_row_area area
, int overlaps
)
26110 for (i
= 0; i
< row
->used
[area
];)
26112 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
26114 int start
= i
, start_x
= x
;
26118 x
+= row
->glyphs
[area
][i
].pixel_width
;
26121 while (i
< row
->used
[area
]
26122 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
26124 draw_glyphs (w
, start_x
, row
, area
,
26126 DRAW_NORMAL_TEXT
, overlaps
);
26130 x
+= row
->glyphs
[area
][i
].pixel_width
;
26140 Draw the cursor glyph of window W in glyph row ROW. See the
26141 comment of draw_glyphs for the meaning of HL. */
26144 draw_phys_cursor_glyph (struct window
*w
, struct glyph_row
*row
,
26145 enum draw_glyphs_face hl
)
26147 /* If cursor hpos is out of bounds, don't draw garbage. This can
26148 happen in mini-buffer windows when switching between echo area
26149 glyphs and mini-buffer. */
26150 if ((row
->reversed_p
26151 ? (w
->phys_cursor
.hpos
>= 0)
26152 : (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])))
26154 int on_p
= w
->phys_cursor_on_p
;
26156 int hpos
= w
->phys_cursor
.hpos
;
26158 /* When the window is hscrolled, cursor hpos can legitimately be
26159 out of bounds, but we draw the cursor at the corresponding
26160 window margin in that case. */
26161 if (!row
->reversed_p
&& hpos
< 0)
26163 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26164 hpos
= row
->used
[TEXT_AREA
] - 1;
26166 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
, hpos
, hpos
+ 1,
26168 w
->phys_cursor_on_p
= on_p
;
26170 if (hl
== DRAW_CURSOR
)
26171 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
26172 /* When we erase the cursor, and ROW is overlapped by other
26173 rows, make sure that these overlapping parts of other rows
26175 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
26177 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
26179 if (row
> w
->current_matrix
->rows
26180 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
26181 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
26182 OVERLAPS_ERASED_CURSOR
);
26184 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
26185 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
26186 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
26187 OVERLAPS_ERASED_CURSOR
);
26194 Erase the image of a cursor of window W from the screen. */
26197 erase_phys_cursor (struct window
*w
)
26199 struct frame
*f
= XFRAME (w
->frame
);
26200 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
26201 int hpos
= w
->phys_cursor
.hpos
;
26202 int vpos
= w
->phys_cursor
.vpos
;
26203 int mouse_face_here_p
= 0;
26204 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
26205 struct glyph_row
*cursor_row
;
26206 struct glyph
*cursor_glyph
;
26207 enum draw_glyphs_face hl
;
26209 /* No cursor displayed or row invalidated => nothing to do on the
26211 if (w
->phys_cursor_type
== NO_CURSOR
)
26212 goto mark_cursor_off
;
26214 /* VPOS >= active_glyphs->nrows means that window has been resized.
26215 Don't bother to erase the cursor. */
26216 if (vpos
>= active_glyphs
->nrows
)
26217 goto mark_cursor_off
;
26219 /* If row containing cursor is marked invalid, there is nothing we
26221 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
26222 if (!cursor_row
->enabled_p
)
26223 goto mark_cursor_off
;
26225 /* If line spacing is > 0, old cursor may only be partially visible in
26226 window after split-window. So adjust visible height. */
26227 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
26228 window_text_bottom_y (w
) - cursor_row
->y
);
26230 /* If row is completely invisible, don't attempt to delete a cursor which
26231 isn't there. This can happen if cursor is at top of a window, and
26232 we switch to a buffer with a header line in that window. */
26233 if (cursor_row
->visible_height
<= 0)
26234 goto mark_cursor_off
;
26236 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
26237 if (cursor_row
->cursor_in_fringe_p
)
26239 cursor_row
->cursor_in_fringe_p
= 0;
26240 draw_fringe_bitmap (w
, cursor_row
, cursor_row
->reversed_p
);
26241 goto mark_cursor_off
;
26244 /* This can happen when the new row is shorter than the old one.
26245 In this case, either draw_glyphs or clear_end_of_line
26246 should have cleared the cursor. Note that we wouldn't be
26247 able to erase the cursor in this case because we don't have a
26248 cursor glyph at hand. */
26249 if ((cursor_row
->reversed_p
26250 ? (w
->phys_cursor
.hpos
< 0)
26251 : (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])))
26252 goto mark_cursor_off
;
26254 /* When the window is hscrolled, cursor hpos can legitimately be out
26255 of bounds, but we draw the cursor at the corresponding window
26256 margin in that case. */
26257 if (!cursor_row
->reversed_p
&& hpos
< 0)
26259 if (cursor_row
->reversed_p
&& hpos
>= cursor_row
->used
[TEXT_AREA
])
26260 hpos
= cursor_row
->used
[TEXT_AREA
] - 1;
26262 /* If the cursor is in the mouse face area, redisplay that when
26263 we clear the cursor. */
26264 if (! NILP (hlinfo
->mouse_face_window
)
26265 && coords_in_mouse_face_p (w
, hpos
, vpos
)
26266 /* Don't redraw the cursor's spot in mouse face if it is at the
26267 end of a line (on a newline). The cursor appears there, but
26268 mouse highlighting does not. */
26269 && cursor_row
->used
[TEXT_AREA
] > hpos
&& hpos
>= 0)
26270 mouse_face_here_p
= 1;
26272 /* Maybe clear the display under the cursor. */
26273 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
26276 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
26279 cursor_glyph
= get_phys_cursor_glyph (w
);
26280 if (cursor_glyph
== NULL
)
26281 goto mark_cursor_off
;
26283 width
= cursor_glyph
->pixel_width
;
26284 left_x
= window_box_left_offset (w
, TEXT_AREA
);
26285 x
= w
->phys_cursor
.x
;
26287 width
-= left_x
- x
;
26288 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
26289 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
26290 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
26293 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
26296 /* Erase the cursor by redrawing the character underneath it. */
26297 if (mouse_face_here_p
)
26298 hl
= DRAW_MOUSE_FACE
;
26300 hl
= DRAW_NORMAL_TEXT
;
26301 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
26304 w
->phys_cursor_on_p
= 0;
26305 w
->phys_cursor_type
= NO_CURSOR
;
26310 Display or clear cursor of window W. If ON is zero, clear the
26311 cursor. If it is non-zero, display the cursor. If ON is nonzero,
26312 where to put the cursor is specified by HPOS, VPOS, X and Y. */
26315 display_and_set_cursor (struct window
*w
, int on
,
26316 int hpos
, int vpos
, int x
, int y
)
26318 struct frame
*f
= XFRAME (w
->frame
);
26319 int new_cursor_type
;
26320 int new_cursor_width
;
26322 struct glyph_row
*glyph_row
;
26323 struct glyph
*glyph
;
26325 /* This is pointless on invisible frames, and dangerous on garbaged
26326 windows and frames; in the latter case, the frame or window may
26327 be in the midst of changing its size, and x and y may be off the
26329 if (! FRAME_VISIBLE_P (f
)
26330 || FRAME_GARBAGED_P (f
)
26331 || vpos
>= w
->current_matrix
->nrows
26332 || hpos
>= w
->current_matrix
->matrix_w
)
26335 /* If cursor is off and we want it off, return quickly. */
26336 if (!on
&& !w
->phys_cursor_on_p
)
26339 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26340 /* If cursor row is not enabled, we don't really know where to
26341 display the cursor. */
26342 if (!glyph_row
->enabled_p
)
26344 w
->phys_cursor_on_p
= 0;
26349 if (!glyph_row
->exact_window_width_line_p
26350 || (0 <= hpos
&& hpos
< glyph_row
->used
[TEXT_AREA
]))
26351 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
26353 eassert (input_blocked_p ());
26355 /* Set new_cursor_type to the cursor we want to be displayed. */
26356 new_cursor_type
= get_window_cursor_type (w
, glyph
,
26357 &new_cursor_width
, &active_cursor
);
26359 /* If cursor is currently being shown and we don't want it to be or
26360 it is in the wrong place, or the cursor type is not what we want,
26362 if (w
->phys_cursor_on_p
26364 || w
->phys_cursor
.x
!= x
26365 || w
->phys_cursor
.y
!= y
26366 || new_cursor_type
!= w
->phys_cursor_type
26367 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
26368 && new_cursor_width
!= w
->phys_cursor_width
)))
26369 erase_phys_cursor (w
);
26371 /* Don't check phys_cursor_on_p here because that flag is only set
26372 to zero in some cases where we know that the cursor has been
26373 completely erased, to avoid the extra work of erasing the cursor
26374 twice. In other words, phys_cursor_on_p can be 1 and the cursor
26375 still not be visible, or it has only been partly erased. */
26378 w
->phys_cursor_ascent
= glyph_row
->ascent
;
26379 w
->phys_cursor_height
= glyph_row
->height
;
26381 /* Set phys_cursor_.* before x_draw_.* is called because some
26382 of them may need the information. */
26383 w
->phys_cursor
.x
= x
;
26384 w
->phys_cursor
.y
= glyph_row
->y
;
26385 w
->phys_cursor
.hpos
= hpos
;
26386 w
->phys_cursor
.vpos
= vpos
;
26389 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
26390 new_cursor_type
, new_cursor_width
,
26391 on
, active_cursor
);
26395 /* Switch the display of W's cursor on or off, according to the value
26399 update_window_cursor (struct window
*w
, int on
)
26401 /* Don't update cursor in windows whose frame is in the process
26402 of being deleted. */
26403 if (w
->current_matrix
)
26405 int hpos
= w
->phys_cursor
.hpos
;
26406 int vpos
= w
->phys_cursor
.vpos
;
26407 struct glyph_row
*row
;
26409 if (vpos
>= w
->current_matrix
->nrows
26410 || hpos
>= w
->current_matrix
->matrix_w
)
26413 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26415 /* When the window is hscrolled, cursor hpos can legitimately be
26416 out of bounds, but we draw the cursor at the corresponding
26417 window margin in that case. */
26418 if (!row
->reversed_p
&& hpos
< 0)
26420 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26421 hpos
= row
->used
[TEXT_AREA
] - 1;
26424 display_and_set_cursor (w
, on
, hpos
, vpos
,
26425 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
26431 /* Call update_window_cursor with parameter ON_P on all leaf windows
26432 in the window tree rooted at W. */
26435 update_cursor_in_window_tree (struct window
*w
, int on_p
)
26439 if (!NILP (w
->hchild
))
26440 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
26441 else if (!NILP (w
->vchild
))
26442 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
26444 update_window_cursor (w
, on_p
);
26446 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
26452 Display the cursor on window W, or clear it, according to ON_P.
26453 Don't change the cursor's position. */
26456 x_update_cursor (struct frame
*f
, int on_p
)
26458 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
26463 Clear the cursor of window W to background color, and mark the
26464 cursor as not shown. This is used when the text where the cursor
26465 is about to be rewritten. */
26468 x_clear_cursor (struct window
*w
)
26470 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
26471 update_window_cursor (w
, 0);
26474 #endif /* HAVE_WINDOW_SYSTEM */
26476 /* Implementation of draw_row_with_mouse_face for GUI sessions, GPM,
26479 draw_row_with_mouse_face (struct window
*w
, int start_x
, struct glyph_row
*row
,
26480 int start_hpos
, int end_hpos
,
26481 enum draw_glyphs_face draw
)
26483 #ifdef HAVE_WINDOW_SYSTEM
26484 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
26486 draw_glyphs (w
, start_x
, row
, TEXT_AREA
, start_hpos
, end_hpos
, draw
, 0);
26490 #if defined (HAVE_GPM) || defined (MSDOS) || defined (WINDOWSNT)
26491 tty_draw_row_with_mouse_face (w
, row
, start_hpos
, end_hpos
, draw
);
26495 /* Display the active region described by mouse_face_* according to DRAW. */
26498 show_mouse_face (Mouse_HLInfo
*hlinfo
, enum draw_glyphs_face draw
)
26500 struct window
*w
= XWINDOW (hlinfo
->mouse_face_window
);
26501 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
26503 if (/* If window is in the process of being destroyed, don't bother
26505 w
->current_matrix
!= NULL
26506 /* Don't update mouse highlight if hidden */
26507 && (draw
!= DRAW_MOUSE_FACE
|| !hlinfo
->mouse_face_hidden
)
26508 /* Recognize when we are called to operate on rows that don't exist
26509 anymore. This can happen when a window is split. */
26510 && hlinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
26512 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
26513 struct glyph_row
*row
, *first
, *last
;
26515 first
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
26516 last
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
26518 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
26520 int start_hpos
, end_hpos
, start_x
;
26522 /* For all but the first row, the highlight starts at column 0. */
26525 /* R2L rows have BEG and END in reversed order, but the
26526 screen drawing geometry is always left to right. So
26527 we need to mirror the beginning and end of the
26528 highlighted area in R2L rows. */
26529 if (!row
->reversed_p
)
26531 start_hpos
= hlinfo
->mouse_face_beg_col
;
26532 start_x
= hlinfo
->mouse_face_beg_x
;
26534 else if (row
== last
)
26536 start_hpos
= hlinfo
->mouse_face_end_col
;
26537 start_x
= hlinfo
->mouse_face_end_x
;
26545 else if (row
->reversed_p
&& row
== last
)
26547 start_hpos
= hlinfo
->mouse_face_end_col
;
26548 start_x
= hlinfo
->mouse_face_end_x
;
26558 if (!row
->reversed_p
)
26559 end_hpos
= hlinfo
->mouse_face_end_col
;
26560 else if (row
== first
)
26561 end_hpos
= hlinfo
->mouse_face_beg_col
;
26564 end_hpos
= row
->used
[TEXT_AREA
];
26565 if (draw
== DRAW_NORMAL_TEXT
)
26566 row
->fill_line_p
= 1; /* Clear to end of line */
26569 else if (row
->reversed_p
&& row
== first
)
26570 end_hpos
= hlinfo
->mouse_face_beg_col
;
26573 end_hpos
= row
->used
[TEXT_AREA
];
26574 if (draw
== DRAW_NORMAL_TEXT
)
26575 row
->fill_line_p
= 1; /* Clear to end of line */
26578 if (end_hpos
> start_hpos
)
26580 draw_row_with_mouse_face (w
, start_x
, row
,
26581 start_hpos
, end_hpos
, draw
);
26584 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
26588 #ifdef HAVE_WINDOW_SYSTEM
26589 /* When we've written over the cursor, arrange for it to
26590 be displayed again. */
26591 if (FRAME_WINDOW_P (f
)
26592 && phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
26594 int hpos
= w
->phys_cursor
.hpos
;
26596 /* When the window is hscrolled, cursor hpos can legitimately be
26597 out of bounds, but we draw the cursor at the corresponding
26598 window margin in that case. */
26599 if (!row
->reversed_p
&& hpos
< 0)
26601 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26602 hpos
= row
->used
[TEXT_AREA
] - 1;
26605 display_and_set_cursor (w
, 1, hpos
, w
->phys_cursor
.vpos
,
26606 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
26609 #endif /* HAVE_WINDOW_SYSTEM */
26612 #ifdef HAVE_WINDOW_SYSTEM
26613 /* Change the mouse cursor. */
26614 if (FRAME_WINDOW_P (f
))
26616 if (draw
== DRAW_NORMAL_TEXT
26617 && !EQ (hlinfo
->mouse_face_window
, f
->tool_bar_window
))
26618 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
26619 else if (draw
== DRAW_MOUSE_FACE
)
26620 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
26622 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
26624 #endif /* HAVE_WINDOW_SYSTEM */
26628 Clear out the mouse-highlighted active region.
26629 Redraw it un-highlighted first. Value is non-zero if mouse
26630 face was actually drawn unhighlighted. */
26633 clear_mouse_face (Mouse_HLInfo
*hlinfo
)
26637 if (!hlinfo
->mouse_face_hidden
&& !NILP (hlinfo
->mouse_face_window
))
26639 show_mouse_face (hlinfo
, DRAW_NORMAL_TEXT
);
26643 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
26644 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
26645 hlinfo
->mouse_face_window
= Qnil
;
26646 hlinfo
->mouse_face_overlay
= Qnil
;
26650 /* Return non-zero if the coordinates HPOS and VPOS on windows W are
26651 within the mouse face on that window. */
26653 coords_in_mouse_face_p (struct window
*w
, int hpos
, int vpos
)
26655 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
26657 /* Quickly resolve the easy cases. */
26658 if (!(WINDOWP (hlinfo
->mouse_face_window
)
26659 && XWINDOW (hlinfo
->mouse_face_window
) == w
))
26661 if (vpos
< hlinfo
->mouse_face_beg_row
26662 || vpos
> hlinfo
->mouse_face_end_row
)
26664 if (vpos
> hlinfo
->mouse_face_beg_row
26665 && vpos
< hlinfo
->mouse_face_end_row
)
26668 if (!MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
)
26670 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
26672 if (hlinfo
->mouse_face_beg_col
<= hpos
&& hpos
< hlinfo
->mouse_face_end_col
)
26675 else if ((vpos
== hlinfo
->mouse_face_beg_row
26676 && hpos
>= hlinfo
->mouse_face_beg_col
)
26677 || (vpos
== hlinfo
->mouse_face_end_row
26678 && hpos
< hlinfo
->mouse_face_end_col
))
26683 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
26685 if (hlinfo
->mouse_face_end_col
< hpos
&& hpos
<= hlinfo
->mouse_face_beg_col
)
26688 else if ((vpos
== hlinfo
->mouse_face_beg_row
26689 && hpos
<= hlinfo
->mouse_face_beg_col
)
26690 || (vpos
== hlinfo
->mouse_face_end_row
26691 && hpos
> hlinfo
->mouse_face_end_col
))
26699 Non-zero if physical cursor of window W is within mouse face. */
26702 cursor_in_mouse_face_p (struct window
*w
)
26704 int hpos
= w
->phys_cursor
.hpos
;
26705 int vpos
= w
->phys_cursor
.vpos
;
26706 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26708 /* When the window is hscrolled, cursor hpos can legitimately be out
26709 of bounds, but we draw the cursor at the corresponding window
26710 margin in that case. */
26711 if (!row
->reversed_p
&& hpos
< 0)
26713 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26714 hpos
= row
->used
[TEXT_AREA
] - 1;
26716 return coords_in_mouse_face_p (w
, hpos
, vpos
);
26721 /* Find the glyph rows START_ROW and END_ROW of window W that display
26722 characters between buffer positions START_CHARPOS and END_CHARPOS
26723 (excluding END_CHARPOS). DISP_STRING is a display string that
26724 covers these buffer positions. This is similar to
26725 row_containing_pos, but is more accurate when bidi reordering makes
26726 buffer positions change non-linearly with glyph rows. */
26728 rows_from_pos_range (struct window
*w
,
26729 ptrdiff_t start_charpos
, ptrdiff_t end_charpos
,
26730 Lisp_Object disp_string
,
26731 struct glyph_row
**start
, struct glyph_row
**end
)
26733 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26734 int last_y
= window_text_bottom_y (w
);
26735 struct glyph_row
*row
;
26740 while (!first
->enabled_p
26741 && first
< MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
26744 /* Find the START row. */
26746 row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
;
26749 /* A row can potentially be the START row if the range of the
26750 characters it displays intersects the range
26751 [START_CHARPOS..END_CHARPOS). */
26752 if (! ((start_charpos
< MATRIX_ROW_START_CHARPOS (row
)
26753 && end_charpos
< MATRIX_ROW_START_CHARPOS (row
))
26754 /* See the commentary in row_containing_pos, for the
26755 explanation of the complicated way to check whether
26756 some position is beyond the end of the characters
26757 displayed by a row. */
26758 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (row
)
26759 || (start_charpos
== MATRIX_ROW_END_CHARPOS (row
)
26760 && !row
->ends_at_zv_p
26761 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
26762 && (end_charpos
> MATRIX_ROW_END_CHARPOS (row
)
26763 || (end_charpos
== MATRIX_ROW_END_CHARPOS (row
)
26764 && !row
->ends_at_zv_p
26765 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))))
26767 /* Found a candidate row. Now make sure at least one of the
26768 glyphs it displays has a charpos from the range
26769 [START_CHARPOS..END_CHARPOS).
26771 This is not obvious because bidi reordering could make
26772 buffer positions of a row be 1,2,3,102,101,100, and if we
26773 want to highlight characters in [50..60), we don't want
26774 this row, even though [50..60) does intersect [1..103),
26775 the range of character positions given by the row's start
26776 and end positions. */
26777 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
26778 struct glyph
*e
= g
+ row
->used
[TEXT_AREA
];
26782 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
26783 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
26784 /* A glyph that comes from DISP_STRING is by
26785 definition to be highlighted. */
26786 || EQ (g
->object
, disp_string
))
26795 /* Find the END row. */
26797 /* If the last row is partially visible, start looking for END
26798 from that row, instead of starting from FIRST. */
26799 && !(row
->enabled_p
26800 && row
->y
< last_y
&& MATRIX_ROW_BOTTOM_Y (row
) > last_y
))
26802 for ( ; row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
; row
++)
26804 struct glyph_row
*next
= row
+ 1;
26805 ptrdiff_t next_start
= MATRIX_ROW_START_CHARPOS (next
);
26807 if (!next
->enabled_p
26808 || next
>= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
)
26809 /* The first row >= START whose range of displayed characters
26810 does NOT intersect the range [START_CHARPOS..END_CHARPOS]
26811 is the row END + 1. */
26812 || (start_charpos
< next_start
26813 && end_charpos
< next_start
)
26814 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (next
)
26815 || (start_charpos
== MATRIX_ROW_END_CHARPOS (next
)
26816 && !next
->ends_at_zv_p
26817 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))
26818 && (end_charpos
> MATRIX_ROW_END_CHARPOS (next
)
26819 || (end_charpos
== MATRIX_ROW_END_CHARPOS (next
)
26820 && !next
->ends_at_zv_p
26821 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))))
26828 /* If the next row's edges intersect [START_CHARPOS..END_CHARPOS],
26829 but none of the characters it displays are in the range, it is
26831 struct glyph
*g
= next
->glyphs
[TEXT_AREA
];
26832 struct glyph
*s
= g
;
26833 struct glyph
*e
= g
+ next
->used
[TEXT_AREA
];
26837 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
26838 && ((start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
26839 /* If the buffer position of the first glyph in
26840 the row is equal to END_CHARPOS, it means
26841 the last character to be highlighted is the
26842 newline of ROW, and we must consider NEXT as
26844 || (((!next
->reversed_p
&& g
== s
)
26845 || (next
->reversed_p
&& g
== e
- 1))
26846 && (g
->charpos
== end_charpos
26847 /* Special case for when NEXT is an
26848 empty line at ZV. */
26849 || (g
->charpos
== -1
26850 && !row
->ends_at_zv_p
26851 && next_start
== end_charpos
)))))
26852 /* A glyph that comes from DISP_STRING is by
26853 definition to be highlighted. */
26854 || EQ (g
->object
, disp_string
))
26863 /* The first row that ends at ZV must be the last to be
26865 else if (next
->ends_at_zv_p
)
26874 /* This function sets the mouse_face_* elements of HLINFO, assuming
26875 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
26876 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
26877 for the overlay or run of text properties specifying the mouse
26878 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
26879 before-string and after-string that must also be highlighted.
26880 DISP_STRING, if non-nil, is a display string that may cover some
26881 or all of the highlighted text. */
26884 mouse_face_from_buffer_pos (Lisp_Object window
,
26885 Mouse_HLInfo
*hlinfo
,
26886 ptrdiff_t mouse_charpos
,
26887 ptrdiff_t start_charpos
,
26888 ptrdiff_t end_charpos
,
26889 Lisp_Object before_string
,
26890 Lisp_Object after_string
,
26891 Lisp_Object disp_string
)
26893 struct window
*w
= XWINDOW (window
);
26894 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26895 struct glyph_row
*r1
, *r2
;
26896 struct glyph
*glyph
, *end
;
26897 ptrdiff_t ignore
, pos
;
26900 eassert (NILP (disp_string
) || STRINGP (disp_string
));
26901 eassert (NILP (before_string
) || STRINGP (before_string
));
26902 eassert (NILP (after_string
) || STRINGP (after_string
));
26904 /* Find the rows corresponding to START_CHARPOS and END_CHARPOS. */
26905 rows_from_pos_range (w
, start_charpos
, end_charpos
, disp_string
, &r1
, &r2
);
26907 r1
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
26908 /* If the before-string or display-string contains newlines,
26909 rows_from_pos_range skips to its last row. Move back. */
26910 if (!NILP (before_string
) || !NILP (disp_string
))
26912 struct glyph_row
*prev
;
26913 while ((prev
= r1
- 1, prev
>= first
)
26914 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
26915 && prev
->used
[TEXT_AREA
] > 0)
26917 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
26918 glyph
= beg
+ prev
->used
[TEXT_AREA
];
26919 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
26921 || !(EQ (glyph
->object
, before_string
)
26922 || EQ (glyph
->object
, disp_string
)))
26929 r2
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
26930 hlinfo
->mouse_face_past_end
= 1;
26932 else if (!NILP (after_string
))
26934 /* If the after-string has newlines, advance to its last row. */
26935 struct glyph_row
*next
;
26936 struct glyph_row
*last
26937 = MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
26939 for (next
= r2
+ 1;
26941 && next
->used
[TEXT_AREA
] > 0
26942 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
26946 /* The rest of the display engine assumes that mouse_face_beg_row is
26947 either above mouse_face_end_row or identical to it. But with
26948 bidi-reordered continued lines, the row for START_CHARPOS could
26949 be below the row for END_CHARPOS. If so, swap the rows and store
26950 them in correct order. */
26953 struct glyph_row
*tem
= r2
;
26959 hlinfo
->mouse_face_beg_y
= r1
->y
;
26960 hlinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (r1
, w
->current_matrix
);
26961 hlinfo
->mouse_face_end_y
= r2
->y
;
26962 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r2
, w
->current_matrix
);
26964 /* For a bidi-reordered row, the positions of BEFORE_STRING,
26965 AFTER_STRING, DISP_STRING, START_CHARPOS, and END_CHARPOS
26966 could be anywhere in the row and in any order. The strategy
26967 below is to find the leftmost and the rightmost glyph that
26968 belongs to either of these 3 strings, or whose position is
26969 between START_CHARPOS and END_CHARPOS, and highlight all the
26970 glyphs between those two. This may cover more than just the text
26971 between START_CHARPOS and END_CHARPOS if the range of characters
26972 strides the bidi level boundary, e.g. if the beginning is in R2L
26973 text while the end is in L2R text or vice versa. */
26974 if (!r1
->reversed_p
)
26976 /* This row is in a left to right paragraph. Scan it left to
26978 glyph
= r1
->glyphs
[TEXT_AREA
];
26979 end
= glyph
+ r1
->used
[TEXT_AREA
];
26982 /* Skip truncation glyphs at the start of the glyph row. */
26983 if (r1
->displays_text_p
)
26985 && INTEGERP (glyph
->object
)
26986 && glyph
->charpos
< 0;
26988 x
+= glyph
->pixel_width
;
26990 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
26991 or DISP_STRING, and the first glyph from buffer whose
26992 position is between START_CHARPOS and END_CHARPOS. */
26994 && !INTEGERP (glyph
->object
)
26995 && !EQ (glyph
->object
, disp_string
)
26996 && !(BUFFERP (glyph
->object
)
26997 && (glyph
->charpos
>= start_charpos
26998 && glyph
->charpos
< end_charpos
));
27001 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27002 are present at buffer positions between START_CHARPOS and
27003 END_CHARPOS, or if they come from an overlay. */
27004 if (EQ (glyph
->object
, before_string
))
27006 pos
= string_buffer_position (before_string
,
27008 /* If pos == 0, it means before_string came from an
27009 overlay, not from a buffer position. */
27010 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27013 else if (EQ (glyph
->object
, after_string
))
27015 pos
= string_buffer_position (after_string
, end_charpos
);
27016 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27019 x
+= glyph
->pixel_width
;
27021 hlinfo
->mouse_face_beg_x
= x
;
27022 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
27026 /* This row is in a right to left paragraph. Scan it right to
27030 end
= r1
->glyphs
[TEXT_AREA
] - 1;
27031 glyph
= end
+ r1
->used
[TEXT_AREA
];
27033 /* Skip truncation glyphs at the start of the glyph row. */
27034 if (r1
->displays_text_p
)
27036 && INTEGERP (glyph
->object
)
27037 && glyph
->charpos
< 0;
27041 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
27042 or DISP_STRING, and the first glyph from buffer whose
27043 position is between START_CHARPOS and END_CHARPOS. */
27045 && !INTEGERP (glyph
->object
)
27046 && !EQ (glyph
->object
, disp_string
)
27047 && !(BUFFERP (glyph
->object
)
27048 && (glyph
->charpos
>= start_charpos
27049 && glyph
->charpos
< end_charpos
));
27052 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27053 are present at buffer positions between START_CHARPOS and
27054 END_CHARPOS, or if they come from an overlay. */
27055 if (EQ (glyph
->object
, before_string
))
27057 pos
= string_buffer_position (before_string
, start_charpos
);
27058 /* If pos == 0, it means before_string came from an
27059 overlay, not from a buffer position. */
27060 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27063 else if (EQ (glyph
->object
, after_string
))
27065 pos
= string_buffer_position (after_string
, end_charpos
);
27066 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27071 glyph
++; /* first glyph to the right of the highlighted area */
27072 for (g
= r1
->glyphs
[TEXT_AREA
], x
= r1
->x
; g
< glyph
; g
++)
27073 x
+= g
->pixel_width
;
27074 hlinfo
->mouse_face_beg_x
= x
;
27075 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
27078 /* If the highlight ends in a different row, compute GLYPH and END
27079 for the end row. Otherwise, reuse the values computed above for
27080 the row where the highlight begins. */
27083 if (!r2
->reversed_p
)
27085 glyph
= r2
->glyphs
[TEXT_AREA
];
27086 end
= glyph
+ r2
->used
[TEXT_AREA
];
27091 end
= r2
->glyphs
[TEXT_AREA
] - 1;
27092 glyph
= end
+ r2
->used
[TEXT_AREA
];
27096 if (!r2
->reversed_p
)
27098 /* Skip truncation and continuation glyphs near the end of the
27099 row, and also blanks and stretch glyphs inserted by
27100 extend_face_to_end_of_line. */
27102 && INTEGERP ((end
- 1)->object
))
27104 /* Scan the rest of the glyph row from the end, looking for the
27105 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
27106 DISP_STRING, or whose position is between START_CHARPOS
27110 && !INTEGERP (end
->object
)
27111 && !EQ (end
->object
, disp_string
)
27112 && !(BUFFERP (end
->object
)
27113 && (end
->charpos
>= start_charpos
27114 && end
->charpos
< end_charpos
));
27117 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27118 are present at buffer positions between START_CHARPOS and
27119 END_CHARPOS, or if they come from an overlay. */
27120 if (EQ (end
->object
, before_string
))
27122 pos
= string_buffer_position (before_string
, start_charpos
);
27123 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27126 else if (EQ (end
->object
, after_string
))
27128 pos
= string_buffer_position (after_string
, end_charpos
);
27129 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27133 /* Find the X coordinate of the last glyph to be highlighted. */
27134 for (; glyph
<= end
; ++glyph
)
27135 x
+= glyph
->pixel_width
;
27137 hlinfo
->mouse_face_end_x
= x
;
27138 hlinfo
->mouse_face_end_col
= glyph
- r2
->glyphs
[TEXT_AREA
];
27142 /* Skip truncation and continuation glyphs near the end of the
27143 row, and also blanks and stretch glyphs inserted by
27144 extend_face_to_end_of_line. */
27148 && INTEGERP (end
->object
))
27150 x
+= end
->pixel_width
;
27153 /* Scan the rest of the glyph row from the end, looking for the
27154 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
27155 DISP_STRING, or whose position is between START_CHARPOS
27159 && !INTEGERP (end
->object
)
27160 && !EQ (end
->object
, disp_string
)
27161 && !(BUFFERP (end
->object
)
27162 && (end
->charpos
>= start_charpos
27163 && end
->charpos
< end_charpos
));
27166 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27167 are present at buffer positions between START_CHARPOS and
27168 END_CHARPOS, or if they come from an overlay. */
27169 if (EQ (end
->object
, before_string
))
27171 pos
= string_buffer_position (before_string
, start_charpos
);
27172 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27175 else if (EQ (end
->object
, after_string
))
27177 pos
= string_buffer_position (after_string
, end_charpos
);
27178 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27181 x
+= end
->pixel_width
;
27183 /* If we exited the above loop because we arrived at the last
27184 glyph of the row, and its buffer position is still not in
27185 range, it means the last character in range is the preceding
27186 newline. Bump the end column and x values to get past the
27189 && BUFFERP (end
->object
)
27190 && (end
->charpos
< start_charpos
27191 || end
->charpos
>= end_charpos
))
27193 x
+= end
->pixel_width
;
27196 hlinfo
->mouse_face_end_x
= x
;
27197 hlinfo
->mouse_face_end_col
= end
- r2
->glyphs
[TEXT_AREA
];
27200 hlinfo
->mouse_face_window
= window
;
27201 hlinfo
->mouse_face_face_id
27202 = face_at_buffer_position (w
, mouse_charpos
, 0, 0, &ignore
,
27204 !hlinfo
->mouse_face_hidden
, -1);
27205 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
27208 /* The following function is not used anymore (replaced with
27209 mouse_face_from_string_pos), but I leave it here for the time
27210 being, in case someone would. */
27212 #if 0 /* not used */
27214 /* Find the position of the glyph for position POS in OBJECT in
27215 window W's current matrix, and return in *X, *Y the pixel
27216 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
27218 RIGHT_P non-zero means return the position of the right edge of the
27219 glyph, RIGHT_P zero means return the left edge position.
27221 If no glyph for POS exists in the matrix, return the position of
27222 the glyph with the next smaller position that is in the matrix, if
27223 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
27224 exists in the matrix, return the position of the glyph with the
27225 next larger position in OBJECT.
27227 Value is non-zero if a glyph was found. */
27230 fast_find_string_pos (struct window
*w
, ptrdiff_t pos
, Lisp_Object object
,
27231 int *hpos
, int *vpos
, int *x
, int *y
, int right_p
)
27233 int yb
= window_text_bottom_y (w
);
27234 struct glyph_row
*r
;
27235 struct glyph
*best_glyph
= NULL
;
27236 struct glyph_row
*best_row
= NULL
;
27239 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27240 r
->enabled_p
&& r
->y
< yb
;
27243 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
27244 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
27247 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
27248 if (EQ (g
->object
, object
))
27250 if (g
->charpos
== pos
)
27257 else if (best_glyph
== NULL
27258 || ((eabs (g
->charpos
- pos
)
27259 < eabs (best_glyph
->charpos
- pos
))
27262 : g
->charpos
> pos
)))
27276 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
27280 *x
+= best_glyph
->pixel_width
;
27285 *vpos
= best_row
- w
->current_matrix
->rows
;
27288 return best_glyph
!= NULL
;
27290 #endif /* not used */
27292 /* Find the positions of the first and the last glyphs in window W's
27293 current matrix that occlude positions [STARTPOS..ENDPOS] in OBJECT
27294 (assumed to be a string), and return in HLINFO's mouse_face_*
27295 members the pixel and column/row coordinates of those glyphs. */
27298 mouse_face_from_string_pos (struct window
*w
, Mouse_HLInfo
*hlinfo
,
27299 Lisp_Object object
,
27300 ptrdiff_t startpos
, ptrdiff_t endpos
)
27302 int yb
= window_text_bottom_y (w
);
27303 struct glyph_row
*r
;
27304 struct glyph
*g
, *e
;
27308 /* Find the glyph row with at least one position in the range
27309 [STARTPOS..ENDPOS], and the first glyph in that row whose
27310 position belongs to that range. */
27311 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27312 r
->enabled_p
&& r
->y
< yb
;
27315 if (!r
->reversed_p
)
27317 g
= r
->glyphs
[TEXT_AREA
];
27318 e
= g
+ r
->used
[TEXT_AREA
];
27319 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
27320 if (EQ (g
->object
, object
)
27321 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
27323 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
27324 hlinfo
->mouse_face_beg_y
= r
->y
;
27325 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
27326 hlinfo
->mouse_face_beg_x
= gx
;
27335 e
= r
->glyphs
[TEXT_AREA
];
27336 g
= e
+ r
->used
[TEXT_AREA
];
27337 for ( ; g
> e
; --g
)
27338 if (EQ ((g
-1)->object
, object
)
27339 && startpos
<= (g
-1)->charpos
&& (g
-1)->charpos
<= endpos
)
27341 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
27342 hlinfo
->mouse_face_beg_y
= r
->y
;
27343 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
27344 for (gx
= r
->x
, g1
= r
->glyphs
[TEXT_AREA
]; g1
< g
; ++g1
)
27345 gx
+= g1
->pixel_width
;
27346 hlinfo
->mouse_face_beg_x
= gx
;
27358 /* Starting with the next row, look for the first row which does NOT
27359 include any glyphs whose positions are in the range. */
27360 for (++r
; r
->enabled_p
&& r
->y
< yb
; ++r
)
27362 g
= r
->glyphs
[TEXT_AREA
];
27363 e
= g
+ r
->used
[TEXT_AREA
];
27365 for ( ; g
< e
; ++g
)
27366 if (EQ (g
->object
, object
)
27367 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
27376 /* The highlighted region ends on the previous row. */
27379 /* Set the end row and its vertical pixel coordinate. */
27380 hlinfo
->mouse_face_end_row
= r
- w
->current_matrix
->rows
;
27381 hlinfo
->mouse_face_end_y
= r
->y
;
27383 /* Compute and set the end column and the end column's horizontal
27384 pixel coordinate. */
27385 if (!r
->reversed_p
)
27387 g
= r
->glyphs
[TEXT_AREA
];
27388 e
= g
+ r
->used
[TEXT_AREA
];
27389 for ( ; e
> g
; --e
)
27390 if (EQ ((e
-1)->object
, object
)
27391 && startpos
<= (e
-1)->charpos
&& (e
-1)->charpos
<= endpos
)
27393 hlinfo
->mouse_face_end_col
= e
- g
;
27395 for (gx
= r
->x
; g
< e
; ++g
)
27396 gx
+= g
->pixel_width
;
27397 hlinfo
->mouse_face_end_x
= gx
;
27401 e
= r
->glyphs
[TEXT_AREA
];
27402 g
= e
+ r
->used
[TEXT_AREA
];
27403 for (gx
= r
->x
; e
< g
; ++e
)
27405 if (EQ (e
->object
, object
)
27406 && startpos
<= e
->charpos
&& e
->charpos
<= endpos
)
27408 gx
+= e
->pixel_width
;
27410 hlinfo
->mouse_face_end_col
= e
- r
->glyphs
[TEXT_AREA
];
27411 hlinfo
->mouse_face_end_x
= gx
;
27415 #ifdef HAVE_WINDOW_SYSTEM
27417 /* See if position X, Y is within a hot-spot of an image. */
27420 on_hot_spot_p (Lisp_Object hot_spot
, int x
, int y
)
27422 if (!CONSP (hot_spot
))
27425 if (EQ (XCAR (hot_spot
), Qrect
))
27427 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
27428 Lisp_Object rect
= XCDR (hot_spot
);
27432 if (!CONSP (XCAR (rect
)))
27434 if (!CONSP (XCDR (rect
)))
27436 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
27438 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
27440 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
27442 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
27446 else if (EQ (XCAR (hot_spot
), Qcircle
))
27448 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
27449 Lisp_Object circ
= XCDR (hot_spot
);
27450 Lisp_Object lr
, lx0
, ly0
;
27452 && CONSP (XCAR (circ
))
27453 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
27454 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
27455 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
27457 double r
= XFLOATINT (lr
);
27458 double dx
= XINT (lx0
) - x
;
27459 double dy
= XINT (ly0
) - y
;
27460 return (dx
* dx
+ dy
* dy
<= r
* r
);
27463 else if (EQ (XCAR (hot_spot
), Qpoly
))
27465 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
27466 if (VECTORP (XCDR (hot_spot
)))
27468 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
27469 Lisp_Object
*poly
= v
->contents
;
27470 ptrdiff_t n
= v
->header
.size
;
27473 Lisp_Object lx
, ly
;
27476 /* Need an even number of coordinates, and at least 3 edges. */
27477 if (n
< 6 || n
& 1)
27480 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
27481 If count is odd, we are inside polygon. Pixels on edges
27482 may or may not be included depending on actual geometry of the
27484 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
27485 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
27487 x0
= XINT (lx
), y0
= XINT (ly
);
27488 for (i
= 0; i
< n
; i
+= 2)
27490 int x1
= x0
, y1
= y0
;
27491 if ((lx
= poly
[i
], !INTEGERP (lx
))
27492 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
27494 x0
= XINT (lx
), y0
= XINT (ly
);
27496 /* Does this segment cross the X line? */
27504 if (y
> y0
&& y
> y1
)
27506 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
27516 find_hot_spot (Lisp_Object map
, int x
, int y
)
27518 while (CONSP (map
))
27520 if (CONSP (XCAR (map
))
27521 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
27529 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
27531 doc
: /* Lookup in image map MAP coordinates X and Y.
27532 An image map is an alist where each element has the format (AREA ID PLIST).
27533 An AREA is specified as either a rectangle, a circle, or a polygon:
27534 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
27535 pixel coordinates of the upper left and bottom right corners.
27536 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
27537 and the radius of the circle; r may be a float or integer.
27538 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
27539 vector describes one corner in the polygon.
27540 Returns the alist element for the first matching AREA in MAP. */)
27541 (Lisp_Object map
, Lisp_Object x
, Lisp_Object y
)
27549 return find_hot_spot (map
,
27550 clip_to_bounds (INT_MIN
, XINT (x
), INT_MAX
),
27551 clip_to_bounds (INT_MIN
, XINT (y
), INT_MAX
));
27555 /* Display frame CURSOR, optionally using shape defined by POINTER. */
27557 define_frame_cursor1 (struct frame
*f
, Cursor cursor
, Lisp_Object pointer
)
27559 /* Do not change cursor shape while dragging mouse. */
27560 if (!NILP (do_mouse_tracking
))
27563 if (!NILP (pointer
))
27565 if (EQ (pointer
, Qarrow
))
27566 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27567 else if (EQ (pointer
, Qhand
))
27568 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
27569 else if (EQ (pointer
, Qtext
))
27570 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
27571 else if (EQ (pointer
, intern ("hdrag")))
27572 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
27573 #ifdef HAVE_X_WINDOWS
27574 else if (EQ (pointer
, intern ("vdrag")))
27575 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
27577 else if (EQ (pointer
, intern ("hourglass")))
27578 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
27579 else if (EQ (pointer
, Qmodeline
))
27580 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
27582 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27585 if (cursor
!= No_Cursor
)
27586 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
27589 #endif /* HAVE_WINDOW_SYSTEM */
27591 /* Take proper action when mouse has moved to the mode or header line
27592 or marginal area AREA of window W, x-position X and y-position Y.
27593 X is relative to the start of the text display area of W, so the
27594 width of bitmap areas and scroll bars must be subtracted to get a
27595 position relative to the start of the mode line. */
27598 note_mode_line_or_margin_highlight (Lisp_Object window
, int x
, int y
,
27599 enum window_part area
)
27601 struct window
*w
= XWINDOW (window
);
27602 struct frame
*f
= XFRAME (w
->frame
);
27603 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
27604 #ifdef HAVE_WINDOW_SYSTEM
27605 Display_Info
*dpyinfo
;
27607 Cursor cursor
= No_Cursor
;
27608 Lisp_Object pointer
= Qnil
;
27609 int dx
, dy
, width
, height
;
27611 Lisp_Object string
, object
= Qnil
;
27612 Lisp_Object pos
IF_LINT (= Qnil
), help
;
27614 Lisp_Object mouse_face
;
27615 int original_x_pixel
= x
;
27616 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
27617 struct glyph_row
*row
IF_LINT (= 0);
27619 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
27624 /* Kludge alert: mode_line_string takes X/Y in pixels, but
27625 returns them in row/column units! */
27626 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
27627 &object
, &dx
, &dy
, &width
, &height
);
27629 row
= (area
== ON_MODE_LINE
27630 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
27631 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
27633 /* Find the glyph under the mouse pointer. */
27634 if (row
->mode_line_p
&& row
->enabled_p
)
27636 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
27637 end
= glyph
+ row
->used
[TEXT_AREA
];
27639 for (x0
= original_x_pixel
;
27640 glyph
< end
&& x0
>= glyph
->pixel_width
;
27642 x0
-= glyph
->pixel_width
;
27650 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
27651 /* Kludge alert: marginal_area_string takes X/Y in pixels, but
27652 returns them in row/column units! */
27653 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
27654 &object
, &dx
, &dy
, &width
, &height
);
27659 #ifdef HAVE_WINDOW_SYSTEM
27660 if (IMAGEP (object
))
27662 Lisp_Object image_map
, hotspot
;
27663 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
27665 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
27667 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
27671 /* Could check XCAR (hotspot) to see if we enter/leave this hot-spot.
27672 If so, we could look for mouse-enter, mouse-leave
27673 properties in PLIST (and do something...). */
27674 hotspot
= XCDR (hotspot
);
27675 if (CONSP (hotspot
)
27676 && (plist
= XCAR (hotspot
), CONSP (plist
)))
27678 pointer
= Fplist_get (plist
, Qpointer
);
27679 if (NILP (pointer
))
27681 help
= Fplist_get (plist
, Qhelp_echo
);
27684 help_echo_string
= help
;
27685 XSETWINDOW (help_echo_window
, w
);
27686 help_echo_object
= w
->buffer
;
27687 help_echo_pos
= charpos
;
27691 if (NILP (pointer
))
27692 pointer
= Fplist_get (XCDR (object
), QCpointer
);
27694 #endif /* HAVE_WINDOW_SYSTEM */
27696 if (STRINGP (string
))
27697 pos
= make_number (charpos
);
27699 /* Set the help text and mouse pointer. If the mouse is on a part
27700 of the mode line without any text (e.g. past the right edge of
27701 the mode line text), use the default help text and pointer. */
27702 if (STRINGP (string
) || area
== ON_MODE_LINE
)
27704 /* Arrange to display the help by setting the global variables
27705 help_echo_string, help_echo_object, and help_echo_pos. */
27708 if (STRINGP (string
))
27709 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
27713 help_echo_string
= help
;
27714 XSETWINDOW (help_echo_window
, w
);
27715 help_echo_object
= string
;
27716 help_echo_pos
= charpos
;
27718 else if (area
== ON_MODE_LINE
)
27720 Lisp_Object default_help
27721 = buffer_local_value_1 (Qmode_line_default_help_echo
,
27724 if (STRINGP (default_help
))
27726 help_echo_string
= default_help
;
27727 XSETWINDOW (help_echo_window
, w
);
27728 help_echo_object
= Qnil
;
27729 help_echo_pos
= -1;
27734 #ifdef HAVE_WINDOW_SYSTEM
27735 /* Change the mouse pointer according to what is under it. */
27736 if (FRAME_WINDOW_P (f
))
27738 dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
27739 if (STRINGP (string
))
27741 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27743 if (NILP (pointer
))
27744 pointer
= Fget_text_property (pos
, Qpointer
, string
);
27746 /* Change the mouse pointer according to what is under X/Y. */
27748 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
27751 map
= Fget_text_property (pos
, Qlocal_map
, string
);
27752 if (!KEYMAPP (map
))
27753 map
= Fget_text_property (pos
, Qkeymap
, string
);
27754 if (!KEYMAPP (map
))
27755 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
27759 /* Default mode-line pointer. */
27760 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
27765 /* Change the mouse face according to what is under X/Y. */
27766 if (STRINGP (string
))
27768 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
27769 if (!NILP (mouse_face
)
27770 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
27775 struct glyph
* tmp_glyph
;
27779 int total_pixel_width
;
27780 ptrdiff_t begpos
, endpos
, ignore
;
27784 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
27785 Qmouse_face
, string
, Qnil
);
27791 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
27793 endpos
= SCHARS (string
);
27797 /* Calculate the glyph position GPOS of GLYPH in the
27798 displayed string, relative to the beginning of the
27799 highlighted part of the string.
27801 Note: GPOS is different from CHARPOS. CHARPOS is the
27802 position of GLYPH in the internal string object. A mode
27803 line string format has structures which are converted to
27804 a flattened string by the Emacs Lisp interpreter. The
27805 internal string is an element of those structures. The
27806 displayed string is the flattened string. */
27807 tmp_glyph
= row_start_glyph
;
27808 while (tmp_glyph
< glyph
27809 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
27810 && begpos
<= tmp_glyph
->charpos
27811 && tmp_glyph
->charpos
< endpos
)))
27813 gpos
= glyph
- tmp_glyph
;
27815 /* Calculate the length GSEQ_LENGTH of the glyph sequence of
27816 the highlighted part of the displayed string to which
27817 GLYPH belongs. Note: GSEQ_LENGTH is different from
27818 SCHARS (STRING), because the latter returns the length of
27819 the internal string. */
27820 for (tmp_glyph
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
27822 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
27823 && begpos
<= tmp_glyph
->charpos
27824 && tmp_glyph
->charpos
< endpos
));
27827 gseq_length
= gpos
+ (tmp_glyph
- glyph
) + 1;
27829 /* Calculate the total pixel width of all the glyphs between
27830 the beginning of the highlighted area and GLYPH. */
27831 total_pixel_width
= 0;
27832 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
27833 total_pixel_width
+= tmp_glyph
->pixel_width
;
27835 /* Pre calculation of re-rendering position. Note: X is in
27836 column units here, after the call to mode_line_string or
27837 marginal_area_string. */
27839 vpos
= (area
== ON_MODE_LINE
27840 ? (w
->current_matrix
)->nrows
- 1
27843 /* If GLYPH's position is included in the region that is
27844 already drawn in mouse face, we have nothing to do. */
27845 if ( EQ (window
, hlinfo
->mouse_face_window
)
27846 && (!row
->reversed_p
27847 ? (hlinfo
->mouse_face_beg_col
<= hpos
27848 && hpos
< hlinfo
->mouse_face_end_col
)
27849 /* In R2L rows we swap BEG and END, see below. */
27850 : (hlinfo
->mouse_face_end_col
<= hpos
27851 && hpos
< hlinfo
->mouse_face_beg_col
))
27852 && hlinfo
->mouse_face_beg_row
== vpos
)
27855 if (clear_mouse_face (hlinfo
))
27856 cursor
= No_Cursor
;
27858 if (!row
->reversed_p
)
27860 hlinfo
->mouse_face_beg_col
= hpos
;
27861 hlinfo
->mouse_face_beg_x
= original_x_pixel
27862 - (total_pixel_width
+ dx
);
27863 hlinfo
->mouse_face_end_col
= hpos
+ gseq_length
;
27864 hlinfo
->mouse_face_end_x
= 0;
27868 /* In R2L rows, show_mouse_face expects BEG and END
27869 coordinates to be swapped. */
27870 hlinfo
->mouse_face_end_col
= hpos
;
27871 hlinfo
->mouse_face_end_x
= original_x_pixel
27872 - (total_pixel_width
+ dx
);
27873 hlinfo
->mouse_face_beg_col
= hpos
+ gseq_length
;
27874 hlinfo
->mouse_face_beg_x
= 0;
27877 hlinfo
->mouse_face_beg_row
= vpos
;
27878 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_beg_row
;
27879 hlinfo
->mouse_face_beg_y
= 0;
27880 hlinfo
->mouse_face_end_y
= 0;
27881 hlinfo
->mouse_face_past_end
= 0;
27882 hlinfo
->mouse_face_window
= window
;
27884 hlinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
27890 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
27892 if (NILP (pointer
))
27895 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
27896 clear_mouse_face (hlinfo
);
27898 #ifdef HAVE_WINDOW_SYSTEM
27899 if (FRAME_WINDOW_P (f
))
27900 define_frame_cursor1 (f
, cursor
, pointer
);
27906 Take proper action when the mouse has moved to position X, Y on
27907 frame F as regards highlighting characters that have mouse-face
27908 properties. Also de-highlighting chars where the mouse was before.
27909 X and Y can be negative or out of range. */
27912 note_mouse_highlight (struct frame
*f
, int x
, int y
)
27914 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
27915 enum window_part part
= ON_NOTHING
;
27916 Lisp_Object window
;
27918 Cursor cursor
= No_Cursor
;
27919 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
27922 /* When a menu is active, don't highlight because this looks odd. */
27923 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (MSDOS)
27924 if (popup_activated ())
27928 if (NILP (Vmouse_highlight
)
27929 || !f
->glyphs_initialized_p
27930 || f
->pointer_invisible
)
27933 hlinfo
->mouse_face_mouse_x
= x
;
27934 hlinfo
->mouse_face_mouse_y
= y
;
27935 hlinfo
->mouse_face_mouse_frame
= f
;
27937 if (hlinfo
->mouse_face_defer
)
27940 /* Which window is that in? */
27941 window
= window_from_coordinates (f
, x
, y
, &part
, 1);
27943 /* If displaying active text in another window, clear that. */
27944 if (! EQ (window
, hlinfo
->mouse_face_window
)
27945 /* Also clear if we move out of text area in same window. */
27946 || (!NILP (hlinfo
->mouse_face_window
)
27949 && part
!= ON_MODE_LINE
27950 && part
!= ON_HEADER_LINE
))
27951 clear_mouse_face (hlinfo
);
27953 /* Not on a window -> return. */
27954 if (!WINDOWP (window
))
27957 /* Reset help_echo_string. It will get recomputed below. */
27958 help_echo_string
= Qnil
;
27960 /* Convert to window-relative pixel coordinates. */
27961 w
= XWINDOW (window
);
27962 frame_to_window_pixel_xy (w
, &x
, &y
);
27964 #ifdef HAVE_WINDOW_SYSTEM
27965 /* Handle tool-bar window differently since it doesn't display a
27967 if (EQ (window
, f
->tool_bar_window
))
27969 note_tool_bar_highlight (f
, x
, y
);
27974 /* Mouse is on the mode, header line or margin? */
27975 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
27976 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
27978 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
27982 #ifdef HAVE_WINDOW_SYSTEM
27983 if (part
== ON_VERTICAL_BORDER
)
27985 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
27986 help_echo_string
= build_string ("drag-mouse-1: resize");
27988 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
27989 || part
== ON_SCROLL_BAR
)
27990 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27992 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
27995 /* Are we in a window whose display is up to date?
27996 And verify the buffer's text has not changed. */
27997 b
= XBUFFER (w
->buffer
);
27998 if (part
== ON_TEXT
27999 && EQ (w
->window_end_valid
, w
->buffer
)
28000 && w
->last_modified
== BUF_MODIFF (b
)
28001 && w
->last_overlay_modified
== BUF_OVERLAY_MODIFF (b
))
28003 int hpos
, vpos
, dx
, dy
, area
= LAST_AREA
;
28005 struct glyph
*glyph
;
28006 Lisp_Object object
;
28007 Lisp_Object mouse_face
= Qnil
, position
;
28008 Lisp_Object
*overlay_vec
= NULL
;
28009 ptrdiff_t i
, noverlays
;
28010 struct buffer
*obuf
;
28011 ptrdiff_t obegv
, ozv
;
28014 /* Find the glyph under X/Y. */
28015 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
28017 #ifdef HAVE_WINDOW_SYSTEM
28018 /* Look for :pointer property on image. */
28019 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
28021 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
28022 if (img
!= NULL
&& IMAGEP (img
->spec
))
28024 Lisp_Object image_map
, hotspot
;
28025 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
28027 && (hotspot
= find_hot_spot (image_map
,
28028 glyph
->slice
.img
.x
+ dx
,
28029 glyph
->slice
.img
.y
+ dy
),
28031 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
28035 /* Could check XCAR (hotspot) to see if we enter/leave
28037 If so, we could look for mouse-enter, mouse-leave
28038 properties in PLIST (and do something...). */
28039 hotspot
= XCDR (hotspot
);
28040 if (CONSP (hotspot
)
28041 && (plist
= XCAR (hotspot
), CONSP (plist
)))
28043 pointer
= Fplist_get (plist
, Qpointer
);
28044 if (NILP (pointer
))
28046 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
28047 if (!NILP (help_echo_string
))
28049 help_echo_window
= window
;
28050 help_echo_object
= glyph
->object
;
28051 help_echo_pos
= glyph
->charpos
;
28055 if (NILP (pointer
))
28056 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
28059 #endif /* HAVE_WINDOW_SYSTEM */
28061 /* Clear mouse face if X/Y not over text. */
28063 || area
!= TEXT_AREA
28064 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
28065 /* Glyph's OBJECT is an integer for glyphs inserted by the
28066 display engine for its internal purposes, like truncation
28067 and continuation glyphs and blanks beyond the end of
28068 line's text on text terminals. If we are over such a
28069 glyph, we are not over any text. */
28070 || INTEGERP (glyph
->object
)
28071 /* R2L rows have a stretch glyph at their front, which
28072 stands for no text, whereas L2R rows have no glyphs at
28073 all beyond the end of text. Treat such stretch glyphs
28074 like we do with NULL glyphs in L2R rows. */
28075 || (MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
28076 && glyph
== MATRIX_ROW (w
->current_matrix
, vpos
)->glyphs
[TEXT_AREA
]
28077 && glyph
->type
== STRETCH_GLYPH
28078 && glyph
->avoid_cursor_p
))
28080 if (clear_mouse_face (hlinfo
))
28081 cursor
= No_Cursor
;
28082 #ifdef HAVE_WINDOW_SYSTEM
28083 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
28085 if (area
!= TEXT_AREA
)
28086 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
28088 pointer
= Vvoid_text_area_pointer
;
28094 pos
= glyph
->charpos
;
28095 object
= glyph
->object
;
28096 if (!STRINGP (object
) && !BUFFERP (object
))
28099 /* If we get an out-of-range value, return now; avoid an error. */
28100 if (BUFFERP (object
) && pos
> BUF_Z (b
))
28103 /* Make the window's buffer temporarily current for
28104 overlays_at and compute_char_face. */
28105 obuf
= current_buffer
;
28106 current_buffer
= b
;
28112 /* Is this char mouse-active or does it have help-echo? */
28113 position
= make_number (pos
);
28115 if (BUFFERP (object
))
28117 /* Put all the overlays we want in a vector in overlay_vec. */
28118 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
28119 /* Sort overlays into increasing priority order. */
28120 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
28125 same_region
= coords_in_mouse_face_p (w
, hpos
, vpos
);
28128 cursor
= No_Cursor
;
28130 /* Check mouse-face highlighting. */
28132 /* If there exists an overlay with mouse-face overlapping
28133 the one we are currently highlighting, we have to
28134 check if we enter the overlapping overlay, and then
28135 highlight only that. */
28136 || (OVERLAYP (hlinfo
->mouse_face_overlay
)
28137 && mouse_face_overlay_overlaps (hlinfo
->mouse_face_overlay
)))
28139 /* Find the highest priority overlay with a mouse-face. */
28140 Lisp_Object overlay
= Qnil
;
28141 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
28143 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
28144 if (!NILP (mouse_face
))
28145 overlay
= overlay_vec
[i
];
28148 /* If we're highlighting the same overlay as before, there's
28149 no need to do that again. */
28150 if (!NILP (overlay
) && EQ (overlay
, hlinfo
->mouse_face_overlay
))
28151 goto check_help_echo
;
28152 hlinfo
->mouse_face_overlay
= overlay
;
28154 /* Clear the display of the old active region, if any. */
28155 if (clear_mouse_face (hlinfo
))
28156 cursor
= No_Cursor
;
28158 /* If no overlay applies, get a text property. */
28159 if (NILP (overlay
))
28160 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
28162 /* Next, compute the bounds of the mouse highlighting and
28164 if (!NILP (mouse_face
) && STRINGP (object
))
28166 /* The mouse-highlighting comes from a display string
28167 with a mouse-face. */
28171 s
= Fprevious_single_property_change
28172 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
28173 e
= Fnext_single_property_change
28174 (position
, Qmouse_face
, object
, Qnil
);
28176 s
= make_number (0);
28178 e
= make_number (SCHARS (object
) - 1);
28179 mouse_face_from_string_pos (w
, hlinfo
, object
,
28180 XINT (s
), XINT (e
));
28181 hlinfo
->mouse_face_past_end
= 0;
28182 hlinfo
->mouse_face_window
= window
;
28183 hlinfo
->mouse_face_face_id
28184 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
28185 glyph
->face_id
, 1);
28186 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
28187 cursor
= No_Cursor
;
28191 /* The mouse-highlighting, if any, comes from an overlay
28192 or text property in the buffer. */
28193 Lisp_Object buffer
IF_LINT (= Qnil
);
28194 Lisp_Object disp_string
IF_LINT (= Qnil
);
28196 if (STRINGP (object
))
28198 /* If we are on a display string with no mouse-face,
28199 check if the text under it has one. */
28200 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
28201 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28202 pos
= string_buffer_position (object
, start
);
28205 mouse_face
= get_char_property_and_overlay
28206 (make_number (pos
), Qmouse_face
, w
->buffer
, &overlay
);
28207 buffer
= w
->buffer
;
28208 disp_string
= object
;
28214 disp_string
= Qnil
;
28217 if (!NILP (mouse_face
))
28219 Lisp_Object before
, after
;
28220 Lisp_Object before_string
, after_string
;
28221 /* To correctly find the limits of mouse highlight
28222 in a bidi-reordered buffer, we must not use the
28223 optimization of limiting the search in
28224 previous-single-property-change and
28225 next-single-property-change, because
28226 rows_from_pos_range needs the real start and end
28227 positions to DTRT in this case. That's because
28228 the first row visible in a window does not
28229 necessarily display the character whose position
28230 is the smallest. */
28232 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
28233 ? Fmarker_position (w
->start
)
28236 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
28237 ? make_number (BUF_Z (XBUFFER (buffer
))
28238 - XFASTINT (w
->window_end_pos
))
28241 if (NILP (overlay
))
28243 /* Handle the text property case. */
28244 before
= Fprevious_single_property_change
28245 (make_number (pos
+ 1), Qmouse_face
, buffer
, lim1
);
28246 after
= Fnext_single_property_change
28247 (make_number (pos
), Qmouse_face
, buffer
, lim2
);
28248 before_string
= after_string
= Qnil
;
28252 /* Handle the overlay case. */
28253 before
= Foverlay_start (overlay
);
28254 after
= Foverlay_end (overlay
);
28255 before_string
= Foverlay_get (overlay
, Qbefore_string
);
28256 after_string
= Foverlay_get (overlay
, Qafter_string
);
28258 if (!STRINGP (before_string
)) before_string
= Qnil
;
28259 if (!STRINGP (after_string
)) after_string
= Qnil
;
28262 mouse_face_from_buffer_pos (window
, hlinfo
, pos
,
28265 : XFASTINT (before
),
28267 ? BUF_Z (XBUFFER (buffer
))
28268 : XFASTINT (after
),
28269 before_string
, after_string
,
28271 cursor
= No_Cursor
;
28278 /* Look for a `help-echo' property. */
28279 if (NILP (help_echo_string
)) {
28280 Lisp_Object help
, overlay
;
28282 /* Check overlays first. */
28283 help
= overlay
= Qnil
;
28284 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
28286 overlay
= overlay_vec
[i
];
28287 help
= Foverlay_get (overlay
, Qhelp_echo
);
28292 help_echo_string
= help
;
28293 help_echo_window
= window
;
28294 help_echo_object
= overlay
;
28295 help_echo_pos
= pos
;
28299 Lisp_Object obj
= glyph
->object
;
28300 ptrdiff_t charpos
= glyph
->charpos
;
28302 /* Try text properties. */
28305 && charpos
< SCHARS (obj
))
28307 help
= Fget_text_property (make_number (charpos
),
28311 /* If the string itself doesn't specify a help-echo,
28312 see if the buffer text ``under'' it does. */
28313 struct glyph_row
*r
28314 = MATRIX_ROW (w
->current_matrix
, vpos
);
28315 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28316 ptrdiff_t p
= string_buffer_position (obj
, start
);
28319 help
= Fget_char_property (make_number (p
),
28320 Qhelp_echo
, w
->buffer
);
28329 else if (BUFFERP (obj
)
28332 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
28337 help_echo_string
= help
;
28338 help_echo_window
= window
;
28339 help_echo_object
= obj
;
28340 help_echo_pos
= charpos
;
28345 #ifdef HAVE_WINDOW_SYSTEM
28346 /* Look for a `pointer' property. */
28347 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
28349 /* Check overlays first. */
28350 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
28351 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
28353 if (NILP (pointer
))
28355 Lisp_Object obj
= glyph
->object
;
28356 ptrdiff_t charpos
= glyph
->charpos
;
28358 /* Try text properties. */
28361 && charpos
< SCHARS (obj
))
28363 pointer
= Fget_text_property (make_number (charpos
),
28365 if (NILP (pointer
))
28367 /* If the string itself doesn't specify a pointer,
28368 see if the buffer text ``under'' it does. */
28369 struct glyph_row
*r
28370 = MATRIX_ROW (w
->current_matrix
, vpos
);
28371 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28372 ptrdiff_t p
= string_buffer_position (obj
, start
);
28374 pointer
= Fget_char_property (make_number (p
),
28375 Qpointer
, w
->buffer
);
28378 else if (BUFFERP (obj
)
28381 pointer
= Fget_text_property (make_number (charpos
),
28385 #endif /* HAVE_WINDOW_SYSTEM */
28389 current_buffer
= obuf
;
28394 #ifdef HAVE_WINDOW_SYSTEM
28395 if (FRAME_WINDOW_P (f
))
28396 define_frame_cursor1 (f
, cursor
, pointer
);
28398 /* This is here to prevent a compiler error, about "label at end of
28399 compound statement". */
28406 Clear any mouse-face on window W. This function is part of the
28407 redisplay interface, and is called from try_window_id and similar
28408 functions to ensure the mouse-highlight is off. */
28411 x_clear_window_mouse_face (struct window
*w
)
28413 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
28414 Lisp_Object window
;
28417 XSETWINDOW (window
, w
);
28418 if (EQ (window
, hlinfo
->mouse_face_window
))
28419 clear_mouse_face (hlinfo
);
28425 Just discard the mouse face information for frame F, if any.
28426 This is used when the size of F is changed. */
28429 cancel_mouse_face (struct frame
*f
)
28431 Lisp_Object window
;
28432 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28434 window
= hlinfo
->mouse_face_window
;
28435 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
28437 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
28438 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
28439 hlinfo
->mouse_face_window
= Qnil
;
28445 /***********************************************************************
28447 ***********************************************************************/
28449 #ifdef HAVE_WINDOW_SYSTEM
28451 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
28452 which intersects rectangle R. R is in window-relative coordinates. */
28455 expose_area (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
,
28456 enum glyph_row_area area
)
28458 struct glyph
*first
= row
->glyphs
[area
];
28459 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
28460 struct glyph
*last
;
28461 int first_x
, start_x
, x
;
28463 if (area
== TEXT_AREA
&& row
->fill_line_p
)
28464 /* If row extends face to end of line write the whole line. */
28465 draw_glyphs (w
, 0, row
, area
,
28466 0, row
->used
[area
],
28467 DRAW_NORMAL_TEXT
, 0);
28470 /* Set START_X to the window-relative start position for drawing glyphs of
28471 AREA. The first glyph of the text area can be partially visible.
28472 The first glyphs of other areas cannot. */
28473 start_x
= window_box_left_offset (w
, area
);
28475 if (area
== TEXT_AREA
)
28478 /* Find the first glyph that must be redrawn. */
28480 && x
+ first
->pixel_width
< r
->x
)
28482 x
+= first
->pixel_width
;
28486 /* Find the last one. */
28490 && x
< r
->x
+ r
->width
)
28492 x
+= last
->pixel_width
;
28498 draw_glyphs (w
, first_x
- start_x
, row
, area
,
28499 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
28500 DRAW_NORMAL_TEXT
, 0);
28505 /* Redraw the parts of the glyph row ROW on window W intersecting
28506 rectangle R. R is in window-relative coordinates. Value is
28507 non-zero if mouse-face was overwritten. */
28510 expose_line (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
)
28512 eassert (row
->enabled_p
);
28514 if (row
->mode_line_p
|| w
->pseudo_window_p
)
28515 draw_glyphs (w
, 0, row
, TEXT_AREA
,
28516 0, row
->used
[TEXT_AREA
],
28517 DRAW_NORMAL_TEXT
, 0);
28520 if (row
->used
[LEFT_MARGIN_AREA
])
28521 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
28522 if (row
->used
[TEXT_AREA
])
28523 expose_area (w
, row
, r
, TEXT_AREA
);
28524 if (row
->used
[RIGHT_MARGIN_AREA
])
28525 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
28526 draw_row_fringe_bitmaps (w
, row
);
28529 return row
->mouse_face_p
;
28533 /* Redraw those parts of glyphs rows during expose event handling that
28534 overlap other rows. Redrawing of an exposed line writes over parts
28535 of lines overlapping that exposed line; this function fixes that.
28537 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
28538 row in W's current matrix that is exposed and overlaps other rows.
28539 LAST_OVERLAPPING_ROW is the last such row. */
28542 expose_overlaps (struct window
*w
,
28543 struct glyph_row
*first_overlapping_row
,
28544 struct glyph_row
*last_overlapping_row
,
28547 struct glyph_row
*row
;
28549 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
28550 if (row
->overlapping_p
)
28552 eassert (row
->enabled_p
&& !row
->mode_line_p
);
28555 if (row
->used
[LEFT_MARGIN_AREA
])
28556 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
28558 if (row
->used
[TEXT_AREA
])
28559 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
28561 if (row
->used
[RIGHT_MARGIN_AREA
])
28562 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
28568 /* Return non-zero if W's cursor intersects rectangle R. */
28571 phys_cursor_in_rect_p (struct window
*w
, XRectangle
*r
)
28573 XRectangle cr
, result
;
28574 struct glyph
*cursor_glyph
;
28575 struct glyph_row
*row
;
28577 if (w
->phys_cursor
.vpos
>= 0
28578 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
28579 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
28581 && row
->cursor_in_fringe_p
)
28583 /* Cursor is in the fringe. */
28584 cr
.x
= window_box_right_offset (w
,
28585 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
28586 ? RIGHT_MARGIN_AREA
28589 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
28590 cr
.height
= row
->height
;
28591 return x_intersect_rectangles (&cr
, r
, &result
);
28594 cursor_glyph
= get_phys_cursor_glyph (w
);
28597 /* r is relative to W's box, but w->phys_cursor.x is relative
28598 to left edge of W's TEXT area. Adjust it. */
28599 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
28600 cr
.y
= w
->phys_cursor
.y
;
28601 cr
.width
= cursor_glyph
->pixel_width
;
28602 cr
.height
= w
->phys_cursor_height
;
28603 /* ++KFS: W32 version used W32-specific IntersectRect here, but
28604 I assume the effect is the same -- and this is portable. */
28605 return x_intersect_rectangles (&cr
, r
, &result
);
28607 /* If we don't understand the format, pretend we're not in the hot-spot. */
28613 Draw a vertical window border to the right of window W if W doesn't
28614 have vertical scroll bars. */
28617 x_draw_vertical_border (struct window
*w
)
28619 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
28621 /* We could do better, if we knew what type of scroll-bar the adjacent
28622 windows (on either side) have... But we don't :-(
28623 However, I think this works ok. ++KFS 2003-04-25 */
28625 /* Redraw borders between horizontally adjacent windows. Don't
28626 do it for frames with vertical scroll bars because either the
28627 right scroll bar of a window, or the left scroll bar of its
28628 neighbor will suffice as a border. */
28629 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
28632 if (!WINDOW_RIGHTMOST_P (w
)
28633 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
28635 int x0
, x1
, y0
, y1
;
28637 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
28640 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
28643 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
28645 else if (!WINDOW_LEFTMOST_P (w
)
28646 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
28648 int x0
, x1
, y0
, y1
;
28650 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
28653 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
28656 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
28661 /* Redraw the part of window W intersection rectangle FR. Pixel
28662 coordinates in FR are frame-relative. Call this function with
28663 input blocked. Value is non-zero if the exposure overwrites
28667 expose_window (struct window
*w
, XRectangle
*fr
)
28669 struct frame
*f
= XFRAME (w
->frame
);
28671 int mouse_face_overwritten_p
= 0;
28673 /* If window is not yet fully initialized, do nothing. This can
28674 happen when toolkit scroll bars are used and a window is split.
28675 Reconfiguring the scroll bar will generate an expose for a newly
28677 if (w
->current_matrix
== NULL
)
28680 /* When we're currently updating the window, display and current
28681 matrix usually don't agree. Arrange for a thorough display
28683 if (w
== updated_window
)
28685 SET_FRAME_GARBAGED (f
);
28689 /* Frame-relative pixel rectangle of W. */
28690 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
28691 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
28692 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
28693 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
28695 if (x_intersect_rectangles (fr
, &wr
, &r
))
28697 int yb
= window_text_bottom_y (w
);
28698 struct glyph_row
*row
;
28699 int cursor_cleared_p
, phys_cursor_on_p
;
28700 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
28702 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
28703 r
.x
, r
.y
, r
.width
, r
.height
));
28705 /* Convert to window coordinates. */
28706 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
28707 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
28709 /* Turn off the cursor. */
28710 if (!w
->pseudo_window_p
28711 && phys_cursor_in_rect_p (w
, &r
))
28713 x_clear_cursor (w
);
28714 cursor_cleared_p
= 1;
28717 cursor_cleared_p
= 0;
28719 /* If the row containing the cursor extends face to end of line,
28720 then expose_area might overwrite the cursor outside the
28721 rectangle and thus notice_overwritten_cursor might clear
28722 w->phys_cursor_on_p. We remember the original value and
28723 check later if it is changed. */
28724 phys_cursor_on_p
= w
->phys_cursor_on_p
;
28726 /* Update lines intersecting rectangle R. */
28727 first_overlapping_row
= last_overlapping_row
= NULL
;
28728 for (row
= w
->current_matrix
->rows
;
28733 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
28735 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
28736 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
28737 || (r
.y
>= y0
&& r
.y
< y1
)
28738 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
28740 /* A header line may be overlapping, but there is no need
28741 to fix overlapping areas for them. KFS 2005-02-12 */
28742 if (row
->overlapping_p
&& !row
->mode_line_p
)
28744 if (first_overlapping_row
== NULL
)
28745 first_overlapping_row
= row
;
28746 last_overlapping_row
= row
;
28750 if (expose_line (w
, row
, &r
))
28751 mouse_face_overwritten_p
= 1;
28754 else if (row
->overlapping_p
)
28756 /* We must redraw a row overlapping the exposed area. */
28758 ? y0
+ row
->phys_height
> r
.y
28759 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
28761 if (first_overlapping_row
== NULL
)
28762 first_overlapping_row
= row
;
28763 last_overlapping_row
= row
;
28771 /* Display the mode line if there is one. */
28772 if (WINDOW_WANTS_MODELINE_P (w
)
28773 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
28775 && row
->y
< r
.y
+ r
.height
)
28777 if (expose_line (w
, row
, &r
))
28778 mouse_face_overwritten_p
= 1;
28781 if (!w
->pseudo_window_p
)
28783 /* Fix the display of overlapping rows. */
28784 if (first_overlapping_row
)
28785 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
28788 /* Draw border between windows. */
28789 x_draw_vertical_border (w
);
28791 /* Turn the cursor on again. */
28792 if (cursor_cleared_p
28793 || (phys_cursor_on_p
&& !w
->phys_cursor_on_p
))
28794 update_window_cursor (w
, 1);
28798 return mouse_face_overwritten_p
;
28803 /* Redraw (parts) of all windows in the window tree rooted at W that
28804 intersect R. R contains frame pixel coordinates. Value is
28805 non-zero if the exposure overwrites mouse-face. */
28808 expose_window_tree (struct window
*w
, XRectangle
*r
)
28810 struct frame
*f
= XFRAME (w
->frame
);
28811 int mouse_face_overwritten_p
= 0;
28813 while (w
&& !FRAME_GARBAGED_P (f
))
28815 if (!NILP (w
->hchild
))
28816 mouse_face_overwritten_p
28817 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
28818 else if (!NILP (w
->vchild
))
28819 mouse_face_overwritten_p
28820 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
28822 mouse_face_overwritten_p
|= expose_window (w
, r
);
28824 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
28827 return mouse_face_overwritten_p
;
28832 Redisplay an exposed area of frame F. X and Y are the upper-left
28833 corner of the exposed rectangle. W and H are width and height of
28834 the exposed area. All are pixel values. W or H zero means redraw
28835 the entire frame. */
28838 expose_frame (struct frame
*f
, int x
, int y
, int w
, int h
)
28841 int mouse_face_overwritten_p
= 0;
28843 TRACE ((stderr
, "expose_frame "));
28845 /* No need to redraw if frame will be redrawn soon. */
28846 if (FRAME_GARBAGED_P (f
))
28848 TRACE ((stderr
, " garbaged\n"));
28852 /* If basic faces haven't been realized yet, there is no point in
28853 trying to redraw anything. This can happen when we get an expose
28854 event while Emacs is starting, e.g. by moving another window. */
28855 if (FRAME_FACE_CACHE (f
) == NULL
28856 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
28858 TRACE ((stderr
, " no faces\n"));
28862 if (w
== 0 || h
== 0)
28865 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
28866 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
28876 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
28877 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
28879 if (WINDOWP (f
->tool_bar_window
))
28880 mouse_face_overwritten_p
28881 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
28883 #ifdef HAVE_X_WINDOWS
28885 #ifndef USE_X_TOOLKIT
28886 if (WINDOWP (f
->menu_bar_window
))
28887 mouse_face_overwritten_p
28888 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
28889 #endif /* not USE_X_TOOLKIT */
28893 /* Some window managers support a focus-follows-mouse style with
28894 delayed raising of frames. Imagine a partially obscured frame,
28895 and moving the mouse into partially obscured mouse-face on that
28896 frame. The visible part of the mouse-face will be highlighted,
28897 then the WM raises the obscured frame. With at least one WM, KDE
28898 2.1, Emacs is not getting any event for the raising of the frame
28899 (even tried with SubstructureRedirectMask), only Expose events.
28900 These expose events will draw text normally, i.e. not
28901 highlighted. Which means we must redo the highlight here.
28902 Subsume it under ``we love X''. --gerd 2001-08-15 */
28903 /* Included in Windows version because Windows most likely does not
28904 do the right thing if any third party tool offers
28905 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
28906 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
28908 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28909 if (f
== hlinfo
->mouse_face_mouse_frame
)
28911 int mouse_x
= hlinfo
->mouse_face_mouse_x
;
28912 int mouse_y
= hlinfo
->mouse_face_mouse_y
;
28913 clear_mouse_face (hlinfo
);
28914 note_mouse_highlight (f
, mouse_x
, mouse_y
);
28921 Determine the intersection of two rectangles R1 and R2. Return
28922 the intersection in *RESULT. Value is non-zero if RESULT is not
28926 x_intersect_rectangles (XRectangle
*r1
, XRectangle
*r2
, XRectangle
*result
)
28928 XRectangle
*left
, *right
;
28929 XRectangle
*upper
, *lower
;
28930 int intersection_p
= 0;
28932 /* Rearrange so that R1 is the left-most rectangle. */
28934 left
= r1
, right
= r2
;
28936 left
= r2
, right
= r1
;
28938 /* X0 of the intersection is right.x0, if this is inside R1,
28939 otherwise there is no intersection. */
28940 if (right
->x
<= left
->x
+ left
->width
)
28942 result
->x
= right
->x
;
28944 /* The right end of the intersection is the minimum of
28945 the right ends of left and right. */
28946 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
28949 /* Same game for Y. */
28951 upper
= r1
, lower
= r2
;
28953 upper
= r2
, lower
= r1
;
28955 /* The upper end of the intersection is lower.y0, if this is inside
28956 of upper. Otherwise, there is no intersection. */
28957 if (lower
->y
<= upper
->y
+ upper
->height
)
28959 result
->y
= lower
->y
;
28961 /* The lower end of the intersection is the minimum of the lower
28962 ends of upper and lower. */
28963 result
->height
= (min (lower
->y
+ lower
->height
,
28964 upper
->y
+ upper
->height
)
28966 intersection_p
= 1;
28970 return intersection_p
;
28973 #endif /* HAVE_WINDOW_SYSTEM */
28976 /***********************************************************************
28978 ***********************************************************************/
28981 syms_of_xdisp (void)
28983 Vwith_echo_area_save_vector
= Qnil
;
28984 staticpro (&Vwith_echo_area_save_vector
);
28986 Vmessage_stack
= Qnil
;
28987 staticpro (&Vmessage_stack
);
28989 DEFSYM (Qinhibit_redisplay
, "inhibit-redisplay");
28990 DEFSYM (Qredisplay_internal
, "redisplay_internal (C function)");
28992 message_dolog_marker1
= Fmake_marker ();
28993 staticpro (&message_dolog_marker1
);
28994 message_dolog_marker2
= Fmake_marker ();
28995 staticpro (&message_dolog_marker2
);
28996 message_dolog_marker3
= Fmake_marker ();
28997 staticpro (&message_dolog_marker3
);
29000 defsubr (&Sdump_frame_glyph_matrix
);
29001 defsubr (&Sdump_glyph_matrix
);
29002 defsubr (&Sdump_glyph_row
);
29003 defsubr (&Sdump_tool_bar_row
);
29004 defsubr (&Strace_redisplay
);
29005 defsubr (&Strace_to_stderr
);
29007 #ifdef HAVE_WINDOW_SYSTEM
29008 defsubr (&Stool_bar_lines_needed
);
29009 defsubr (&Slookup_image_map
);
29011 defsubr (&Sformat_mode_line
);
29012 defsubr (&Sinvisible_p
);
29013 defsubr (&Scurrent_bidi_paragraph_direction
);
29015 DEFSYM (Qmenu_bar_update_hook
, "menu-bar-update-hook");
29016 DEFSYM (Qoverriding_terminal_local_map
, "overriding-terminal-local-map");
29017 DEFSYM (Qoverriding_local_map
, "overriding-local-map");
29018 DEFSYM (Qwindow_scroll_functions
, "window-scroll-functions");
29019 DEFSYM (Qwindow_text_change_functions
, "window-text-change-functions");
29020 DEFSYM (Qredisplay_end_trigger_functions
, "redisplay-end-trigger-functions");
29021 DEFSYM (Qinhibit_point_motion_hooks
, "inhibit-point-motion-hooks");
29022 DEFSYM (Qeval
, "eval");
29023 DEFSYM (QCdata
, ":data");
29024 DEFSYM (Qdisplay
, "display");
29025 DEFSYM (Qspace_width
, "space-width");
29026 DEFSYM (Qraise
, "raise");
29027 DEFSYM (Qslice
, "slice");
29028 DEFSYM (Qspace
, "space");
29029 DEFSYM (Qmargin
, "margin");
29030 DEFSYM (Qpointer
, "pointer");
29031 DEFSYM (Qleft_margin
, "left-margin");
29032 DEFSYM (Qright_margin
, "right-margin");
29033 DEFSYM (Qcenter
, "center");
29034 DEFSYM (Qline_height
, "line-height");
29035 DEFSYM (QCalign_to
, ":align-to");
29036 DEFSYM (QCrelative_width
, ":relative-width");
29037 DEFSYM (QCrelative_height
, ":relative-height");
29038 DEFSYM (QCeval
, ":eval");
29039 DEFSYM (QCpropertize
, ":propertize");
29040 DEFSYM (QCfile
, ":file");
29041 DEFSYM (Qfontified
, "fontified");
29042 DEFSYM (Qfontification_functions
, "fontification-functions");
29043 DEFSYM (Qtrailing_whitespace
, "trailing-whitespace");
29044 DEFSYM (Qescape_glyph
, "escape-glyph");
29045 DEFSYM (Qnobreak_space
, "nobreak-space");
29046 DEFSYM (Qimage
, "image");
29047 DEFSYM (Qtext
, "text");
29048 DEFSYM (Qboth
, "both");
29049 DEFSYM (Qboth_horiz
, "both-horiz");
29050 DEFSYM (Qtext_image_horiz
, "text-image-horiz");
29051 DEFSYM (QCmap
, ":map");
29052 DEFSYM (QCpointer
, ":pointer");
29053 DEFSYM (Qrect
, "rect");
29054 DEFSYM (Qcircle
, "circle");
29055 DEFSYM (Qpoly
, "poly");
29056 DEFSYM (Qmessage_truncate_lines
, "message-truncate-lines");
29057 DEFSYM (Qgrow_only
, "grow-only");
29058 DEFSYM (Qinhibit_menubar_update
, "inhibit-menubar-update");
29059 DEFSYM (Qinhibit_eval_during_redisplay
, "inhibit-eval-during-redisplay");
29060 DEFSYM (Qposition
, "position");
29061 DEFSYM (Qbuffer_position
, "buffer-position");
29062 DEFSYM (Qobject
, "object");
29063 DEFSYM (Qbar
, "bar");
29064 DEFSYM (Qhbar
, "hbar");
29065 DEFSYM (Qbox
, "box");
29066 DEFSYM (Qhollow
, "hollow");
29067 DEFSYM (Qhand
, "hand");
29068 DEFSYM (Qarrow
, "arrow");
29069 DEFSYM (Qinhibit_free_realized_faces
, "inhibit-free-realized-faces");
29071 list_of_error
= Fcons (Fcons (intern_c_string ("error"),
29072 Fcons (intern_c_string ("void-variable"), Qnil
)),
29074 staticpro (&list_of_error
);
29076 DEFSYM (Qlast_arrow_position
, "last-arrow-position");
29077 DEFSYM (Qlast_arrow_string
, "last-arrow-string");
29078 DEFSYM (Qoverlay_arrow_string
, "overlay-arrow-string");
29079 DEFSYM (Qoverlay_arrow_bitmap
, "overlay-arrow-bitmap");
29081 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
29082 staticpro (&echo_buffer
[0]);
29083 staticpro (&echo_buffer
[1]);
29085 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
29086 staticpro (&echo_area_buffer
[0]);
29087 staticpro (&echo_area_buffer
[1]);
29089 Vmessages_buffer_name
= build_pure_c_string ("*Messages*");
29090 staticpro (&Vmessages_buffer_name
);
29092 mode_line_proptrans_alist
= Qnil
;
29093 staticpro (&mode_line_proptrans_alist
);
29094 mode_line_string_list
= Qnil
;
29095 staticpro (&mode_line_string_list
);
29096 mode_line_string_face
= Qnil
;
29097 staticpro (&mode_line_string_face
);
29098 mode_line_string_face_prop
= Qnil
;
29099 staticpro (&mode_line_string_face_prop
);
29100 Vmode_line_unwind_vector
= Qnil
;
29101 staticpro (&Vmode_line_unwind_vector
);
29103 DEFSYM (Qmode_line_default_help_echo
, "mode-line-default-help-echo");
29105 help_echo_string
= Qnil
;
29106 staticpro (&help_echo_string
);
29107 help_echo_object
= Qnil
;
29108 staticpro (&help_echo_object
);
29109 help_echo_window
= Qnil
;
29110 staticpro (&help_echo_window
);
29111 previous_help_echo_string
= Qnil
;
29112 staticpro (&previous_help_echo_string
);
29113 help_echo_pos
= -1;
29115 DEFSYM (Qright_to_left
, "right-to-left");
29116 DEFSYM (Qleft_to_right
, "left-to-right");
29118 #ifdef HAVE_WINDOW_SYSTEM
29119 DEFVAR_BOOL ("x-stretch-cursor", x_stretch_cursor_p
,
29120 doc
: /* Non-nil means draw block cursor as wide as the glyph under it.
29121 For example, if a block cursor is over a tab, it will be drawn as
29122 wide as that tab on the display. */);
29123 x_stretch_cursor_p
= 0;
29126 DEFVAR_LISP ("show-trailing-whitespace", Vshow_trailing_whitespace
,
29127 doc
: /* Non-nil means highlight trailing whitespace.
29128 The face used for trailing whitespace is `trailing-whitespace'. */);
29129 Vshow_trailing_whitespace
= Qnil
;
29131 DEFVAR_LISP ("nobreak-char-display", Vnobreak_char_display
,
29132 doc
: /* Control highlighting of non-ASCII space and hyphen chars.
29133 If the value is t, Emacs highlights non-ASCII chars which have the
29134 same appearance as an ASCII space or hyphen, using the `nobreak-space'
29135 or `escape-glyph' face respectively.
29137 U+00A0 (no-break space), U+00AD (soft hyphen), U+2010 (hyphen), and
29138 U+2011 (non-breaking hyphen) are affected.
29140 Any other non-nil value means to display these characters as a escape
29141 glyph followed by an ordinary space or hyphen.
29143 A value of nil means no special handling of these characters. */);
29144 Vnobreak_char_display
= Qt
;
29146 DEFVAR_LISP ("void-text-area-pointer", Vvoid_text_area_pointer
,
29147 doc
: /* The pointer shape to show in void text areas.
29148 A value of nil means to show the text pointer. Other options are `arrow',
29149 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
29150 Vvoid_text_area_pointer
= Qarrow
;
29152 DEFVAR_LISP ("inhibit-redisplay", Vinhibit_redisplay
,
29153 doc
: /* Non-nil means don't actually do any redisplay.
29154 This is used for internal purposes. */);
29155 Vinhibit_redisplay
= Qnil
;
29157 DEFVAR_LISP ("global-mode-string", Vglobal_mode_string
,
29158 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
29159 Vglobal_mode_string
= Qnil
;
29161 DEFVAR_LISP ("overlay-arrow-position", Voverlay_arrow_position
,
29162 doc
: /* Marker for where to display an arrow on top of the buffer text.
29163 This must be the beginning of a line in order to work.
29164 See also `overlay-arrow-string'. */);
29165 Voverlay_arrow_position
= Qnil
;
29167 DEFVAR_LISP ("overlay-arrow-string", Voverlay_arrow_string
,
29168 doc
: /* String to display as an arrow in non-window frames.
29169 See also `overlay-arrow-position'. */);
29170 Voverlay_arrow_string
= build_pure_c_string ("=>");
29172 DEFVAR_LISP ("overlay-arrow-variable-list", Voverlay_arrow_variable_list
,
29173 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
29174 The symbols on this list are examined during redisplay to determine
29175 where to display overlay arrows. */);
29176 Voverlay_arrow_variable_list
29177 = Fcons (intern_c_string ("overlay-arrow-position"), Qnil
);
29179 DEFVAR_INT ("scroll-step", emacs_scroll_step
,
29180 doc
: /* The number of lines to try scrolling a window by when point moves out.
29181 If that fails to bring point back on frame, point is centered instead.
29182 If this is zero, point is always centered after it moves off frame.
29183 If you want scrolling to always be a line at a time, you should set
29184 `scroll-conservatively' to a large value rather than set this to 1. */);
29186 DEFVAR_INT ("scroll-conservatively", scroll_conservatively
,
29187 doc
: /* Scroll up to this many lines, to bring point back on screen.
29188 If point moves off-screen, redisplay will scroll by up to
29189 `scroll-conservatively' lines in order to bring point just barely
29190 onto the screen again. If that cannot be done, then redisplay
29191 recenters point as usual.
29193 If the value is greater than 100, redisplay will never recenter point,
29194 but will always scroll just enough text to bring point into view, even
29195 if you move far away.
29197 A value of zero means always recenter point if it moves off screen. */);
29198 scroll_conservatively
= 0;
29200 DEFVAR_INT ("scroll-margin", scroll_margin
,
29201 doc
: /* Number of lines of margin at the top and bottom of a window.
29202 Recenter the window whenever point gets within this many lines
29203 of the top or bottom of the window. */);
29206 DEFVAR_LISP ("display-pixels-per-inch", Vdisplay_pixels_per_inch
,
29207 doc
: /* Pixels per inch value for non-window system displays.
29208 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
29209 Vdisplay_pixels_per_inch
= make_float (72.0);
29212 DEFVAR_INT ("debug-end-pos", debug_end_pos
, doc
: /* Don't ask. */);
29215 DEFVAR_LISP ("truncate-partial-width-windows",
29216 Vtruncate_partial_width_windows
,
29217 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
29218 For an integer value, truncate lines in each window narrower than the
29219 full frame width, provided the window width is less than that integer;
29220 otherwise, respect the value of `truncate-lines'.
29222 For any other non-nil value, truncate lines in all windows that do
29223 not span the full frame width.
29225 A value of nil means to respect the value of `truncate-lines'.
29227 If `word-wrap' is enabled, you might want to reduce this. */);
29228 Vtruncate_partial_width_windows
= make_number (50);
29230 DEFVAR_LISP ("line-number-display-limit", Vline_number_display_limit
,
29231 doc
: /* Maximum buffer size for which line number should be displayed.
29232 If the buffer is bigger than this, the line number does not appear
29233 in the mode line. A value of nil means no limit. */);
29234 Vline_number_display_limit
= Qnil
;
29236 DEFVAR_INT ("line-number-display-limit-width",
29237 line_number_display_limit_width
,
29238 doc
: /* Maximum line width (in characters) for line number display.
29239 If the average length of the lines near point is bigger than this, then the
29240 line number may be omitted from the mode line. */);
29241 line_number_display_limit_width
= 200;
29243 DEFVAR_BOOL ("highlight-nonselected-windows", highlight_nonselected_windows
,
29244 doc
: /* Non-nil means highlight region even in nonselected windows. */);
29245 highlight_nonselected_windows
= 0;
29247 DEFVAR_BOOL ("multiple-frames", multiple_frames
,
29248 doc
: /* Non-nil if more than one frame is visible on this display.
29249 Minibuffer-only frames don't count, but iconified frames do.
29250 This variable is not guaranteed to be accurate except while processing
29251 `frame-title-format' and `icon-title-format'. */);
29253 DEFVAR_LISP ("frame-title-format", Vframe_title_format
,
29254 doc
: /* Template for displaying the title bar of visible frames.
29255 \(Assuming the window manager supports this feature.)
29257 This variable has the same structure as `mode-line-format', except that
29258 the %c and %l constructs are ignored. It is used only on frames for
29259 which no explicit name has been set \(see `modify-frame-parameters'). */);
29261 DEFVAR_LISP ("icon-title-format", Vicon_title_format
,
29262 doc
: /* Template for displaying the title bar of an iconified frame.
29263 \(Assuming the window manager supports this feature.)
29264 This variable has the same structure as `mode-line-format' (which see),
29265 and is used only on frames for which no explicit name has been set
29266 \(see `modify-frame-parameters'). */);
29268 = Vframe_title_format
29269 = listn (CONSTYPE_PURE
, 3,
29270 intern_c_string ("multiple-frames"),
29271 build_pure_c_string ("%b"),
29272 listn (CONSTYPE_PURE
, 4,
29273 empty_unibyte_string
,
29274 intern_c_string ("invocation-name"),
29275 build_pure_c_string ("@"),
29276 intern_c_string ("system-name")));
29278 DEFVAR_LISP ("message-log-max", Vmessage_log_max
,
29279 doc
: /* Maximum number of lines to keep in the message log buffer.
29280 If nil, disable message logging. If t, log messages but don't truncate
29281 the buffer when it becomes large. */);
29282 Vmessage_log_max
= make_number (1000);
29284 DEFVAR_LISP ("window-size-change-functions", Vwindow_size_change_functions
,
29285 doc
: /* Functions called before redisplay, if window sizes have changed.
29286 The value should be a list of functions that take one argument.
29287 Just before redisplay, for each frame, if any of its windows have changed
29288 size since the last redisplay, or have been split or deleted,
29289 all the functions in the list are called, with the frame as argument. */);
29290 Vwindow_size_change_functions
= Qnil
;
29292 DEFVAR_LISP ("window-scroll-functions", Vwindow_scroll_functions
,
29293 doc
: /* List of functions to call before redisplaying a window with scrolling.
29294 Each function is called with two arguments, the window and its new
29295 display-start position. Note that these functions are also called by
29296 `set-window-buffer'. Also note that the value of `window-end' is not
29297 valid when these functions are called.
29299 Warning: Do not use this feature to alter the way the window
29300 is scrolled. It is not designed for that, and such use probably won't
29302 Vwindow_scroll_functions
= Qnil
;
29304 DEFVAR_LISP ("window-text-change-functions",
29305 Vwindow_text_change_functions
,
29306 doc
: /* Functions to call in redisplay when text in the window might change. */);
29307 Vwindow_text_change_functions
= Qnil
;
29309 DEFVAR_LISP ("redisplay-end-trigger-functions", Vredisplay_end_trigger_functions
,
29310 doc
: /* Functions called when redisplay of a window reaches the end trigger.
29311 Each function is called with two arguments, the window and the end trigger value.
29312 See `set-window-redisplay-end-trigger'. */);
29313 Vredisplay_end_trigger_functions
= Qnil
;
29315 DEFVAR_LISP ("mouse-autoselect-window", Vmouse_autoselect_window
,
29316 doc
: /* Non-nil means autoselect window with mouse pointer.
29317 If nil, do not autoselect windows.
29318 A positive number means delay autoselection by that many seconds: a
29319 window is autoselected only after the mouse has remained in that
29320 window for the duration of the delay.
29321 A negative number has a similar effect, but causes windows to be
29322 autoselected only after the mouse has stopped moving. \(Because of
29323 the way Emacs compares mouse events, you will occasionally wait twice
29324 that time before the window gets selected.\)
29325 Any other value means to autoselect window instantaneously when the
29326 mouse pointer enters it.
29328 Autoselection selects the minibuffer only if it is active, and never
29329 unselects the minibuffer if it is active.
29331 When customizing this variable make sure that the actual value of
29332 `focus-follows-mouse' matches the behavior of your window manager. */);
29333 Vmouse_autoselect_window
= Qnil
;
29335 DEFVAR_LISP ("auto-resize-tool-bars", Vauto_resize_tool_bars
,
29336 doc
: /* Non-nil means automatically resize tool-bars.
29337 This dynamically changes the tool-bar's height to the minimum height
29338 that is needed to make all tool-bar items visible.
29339 If value is `grow-only', the tool-bar's height is only increased
29340 automatically; to decrease the tool-bar height, use \\[recenter]. */);
29341 Vauto_resize_tool_bars
= Qt
;
29343 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", auto_raise_tool_bar_buttons_p
,
29344 doc
: /* Non-nil means raise tool-bar buttons when the mouse moves over them. */);
29345 auto_raise_tool_bar_buttons_p
= 1;
29347 DEFVAR_BOOL ("make-cursor-line-fully-visible", make_cursor_line_fully_visible_p
,
29348 doc
: /* Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
29349 make_cursor_line_fully_visible_p
= 1;
29351 DEFVAR_LISP ("tool-bar-border", Vtool_bar_border
,
29352 doc
: /* Border below tool-bar in pixels.
29353 If an integer, use it as the height of the border.
29354 If it is one of `internal-border-width' or `border-width', use the
29355 value of the corresponding frame parameter.
29356 Otherwise, no border is added below the tool-bar. */);
29357 Vtool_bar_border
= Qinternal_border_width
;
29359 DEFVAR_LISP ("tool-bar-button-margin", Vtool_bar_button_margin
,
29360 doc
: /* Margin around tool-bar buttons in pixels.
29361 If an integer, use that for both horizontal and vertical margins.
29362 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
29363 HORZ specifying the horizontal margin, and VERT specifying the
29364 vertical margin. */);
29365 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
29367 DEFVAR_INT ("tool-bar-button-relief", tool_bar_button_relief
,
29368 doc
: /* Relief thickness of tool-bar buttons. */);
29369 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
29371 DEFVAR_LISP ("tool-bar-style", Vtool_bar_style
,
29372 doc
: /* Tool bar style to use.
29374 image - show images only
29375 text - show text only
29376 both - show both, text below image
29377 both-horiz - show text to the right of the image
29378 text-image-horiz - show text to the left of the image
29379 any other - use system default or image if no system default.
29381 This variable only affects the GTK+ toolkit version of Emacs. */);
29382 Vtool_bar_style
= Qnil
;
29384 DEFVAR_INT ("tool-bar-max-label-size", tool_bar_max_label_size
,
29385 doc
: /* Maximum number of characters a label can have to be shown.
29386 The tool bar style must also show labels for this to have any effect, see
29387 `tool-bar-style'. */);
29388 tool_bar_max_label_size
= DEFAULT_TOOL_BAR_LABEL_SIZE
;
29390 DEFVAR_LISP ("fontification-functions", Vfontification_functions
,
29391 doc
: /* List of functions to call to fontify regions of text.
29392 Each function is called with one argument POS. Functions must
29393 fontify a region starting at POS in the current buffer, and give
29394 fontified regions the property `fontified'. */);
29395 Vfontification_functions
= Qnil
;
29396 Fmake_variable_buffer_local (Qfontification_functions
);
29398 DEFVAR_BOOL ("unibyte-display-via-language-environment",
29399 unibyte_display_via_language_environment
,
29400 doc
: /* Non-nil means display unibyte text according to language environment.
29401 Specifically, this means that raw bytes in the range 160-255 decimal
29402 are displayed by converting them to the equivalent multibyte characters
29403 according to the current language environment. As a result, they are
29404 displayed according to the current fontset.
29406 Note that this variable affects only how these bytes are displayed,
29407 but does not change the fact they are interpreted as raw bytes. */);
29408 unibyte_display_via_language_environment
= 0;
29410 DEFVAR_LISP ("max-mini-window-height", Vmax_mini_window_height
,
29411 doc
: /* Maximum height for resizing mini-windows (the minibuffer and the echo area).
29412 If a float, it specifies a fraction of the mini-window frame's height.
29413 If an integer, it specifies a number of lines. */);
29414 Vmax_mini_window_height
= make_float (0.25);
29416 DEFVAR_LISP ("resize-mini-windows", Vresize_mini_windows
,
29417 doc
: /* How to resize mini-windows (the minibuffer and the echo area).
29418 A value of nil means don't automatically resize mini-windows.
29419 A value of t means resize them to fit the text displayed in them.
29420 A value of `grow-only', the default, means let mini-windows grow only;
29421 they return to their normal size when the minibuffer is closed, or the
29422 echo area becomes empty. */);
29423 Vresize_mini_windows
= Qgrow_only
;
29425 DEFVAR_LISP ("blink-cursor-alist", Vblink_cursor_alist
,
29426 doc
: /* Alist specifying how to blink the cursor off.
29427 Each element has the form (ON-STATE . OFF-STATE). Whenever the
29428 `cursor-type' frame-parameter or variable equals ON-STATE,
29429 comparing using `equal', Emacs uses OFF-STATE to specify
29430 how to blink it off. ON-STATE and OFF-STATE are values for
29431 the `cursor-type' frame parameter.
29433 If a frame's ON-STATE has no entry in this list,
29434 the frame's other specifications determine how to blink the cursor off. */);
29435 Vblink_cursor_alist
= Qnil
;
29437 DEFVAR_BOOL ("auto-hscroll-mode", automatic_hscrolling_p
,
29438 doc
: /* Allow or disallow automatic horizontal scrolling of windows.
29439 If non-nil, windows are automatically scrolled horizontally to make
29440 point visible. */);
29441 automatic_hscrolling_p
= 1;
29442 DEFSYM (Qauto_hscroll_mode
, "auto-hscroll-mode");
29444 DEFVAR_INT ("hscroll-margin", hscroll_margin
,
29445 doc
: /* How many columns away from the window edge point is allowed to get
29446 before automatic hscrolling will horizontally scroll the window. */);
29447 hscroll_margin
= 5;
29449 DEFVAR_LISP ("hscroll-step", Vhscroll_step
,
29450 doc
: /* How many columns to scroll the window when point gets too close to the edge.
29451 When point is less than `hscroll-margin' columns from the window
29452 edge, automatic hscrolling will scroll the window by the amount of columns
29453 determined by this variable. If its value is a positive integer, scroll that
29454 many columns. If it's a positive floating-point number, it specifies the
29455 fraction of the window's width to scroll. If it's nil or zero, point will be
29456 centered horizontally after the scroll. Any other value, including negative
29457 numbers, are treated as if the value were zero.
29459 Automatic hscrolling always moves point outside the scroll margin, so if
29460 point was more than scroll step columns inside the margin, the window will
29461 scroll more than the value given by the scroll step.
29463 Note that the lower bound for automatic hscrolling specified by `scroll-left'
29464 and `scroll-right' overrides this variable's effect. */);
29465 Vhscroll_step
= make_number (0);
29467 DEFVAR_BOOL ("message-truncate-lines", message_truncate_lines
,
29468 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
29469 Bind this around calls to `message' to let it take effect. */);
29470 message_truncate_lines
= 0;
29472 DEFVAR_LISP ("menu-bar-update-hook", Vmenu_bar_update_hook
,
29473 doc
: /* Normal hook run to update the menu bar definitions.
29474 Redisplay runs this hook before it redisplays the menu bar.
29475 This is used to update submenus such as Buffers,
29476 whose contents depend on various data. */);
29477 Vmenu_bar_update_hook
= Qnil
;
29479 DEFVAR_LISP ("menu-updating-frame", Vmenu_updating_frame
,
29480 doc
: /* Frame for which we are updating a menu.
29481 The enable predicate for a menu binding should check this variable. */);
29482 Vmenu_updating_frame
= Qnil
;
29484 DEFVAR_BOOL ("inhibit-menubar-update", inhibit_menubar_update
,
29485 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
29486 inhibit_menubar_update
= 0;
29488 DEFVAR_LISP ("wrap-prefix", Vwrap_prefix
,
29489 doc
: /* Prefix prepended to all continuation lines at display time.
29490 The value may be a string, an image, or a stretch-glyph; it is
29491 interpreted in the same way as the value of a `display' text property.
29493 This variable is overridden by any `wrap-prefix' text or overlay
29496 To add a prefix to non-continuation lines, use `line-prefix'. */);
29497 Vwrap_prefix
= Qnil
;
29498 DEFSYM (Qwrap_prefix
, "wrap-prefix");
29499 Fmake_variable_buffer_local (Qwrap_prefix
);
29501 DEFVAR_LISP ("line-prefix", Vline_prefix
,
29502 doc
: /* Prefix prepended to all non-continuation lines at display time.
29503 The value may be a string, an image, or a stretch-glyph; it is
29504 interpreted in the same way as the value of a `display' text property.
29506 This variable is overridden by any `line-prefix' text or overlay
29509 To add a prefix to continuation lines, use `wrap-prefix'. */);
29510 Vline_prefix
= Qnil
;
29511 DEFSYM (Qline_prefix
, "line-prefix");
29512 Fmake_variable_buffer_local (Qline_prefix
);
29514 DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay
,
29515 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
29516 inhibit_eval_during_redisplay
= 0;
29518 DEFVAR_BOOL ("inhibit-free-realized-faces", inhibit_free_realized_faces
,
29519 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
29520 inhibit_free_realized_faces
= 0;
29523 DEFVAR_BOOL ("inhibit-try-window-id", inhibit_try_window_id
,
29524 doc
: /* Inhibit try_window_id display optimization. */);
29525 inhibit_try_window_id
= 0;
29527 DEFVAR_BOOL ("inhibit-try-window-reusing", inhibit_try_window_reusing
,
29528 doc
: /* Inhibit try_window_reusing display optimization. */);
29529 inhibit_try_window_reusing
= 0;
29531 DEFVAR_BOOL ("inhibit-try-cursor-movement", inhibit_try_cursor_movement
,
29532 doc
: /* Inhibit try_cursor_movement display optimization. */);
29533 inhibit_try_cursor_movement
= 0;
29534 #endif /* GLYPH_DEBUG */
29536 DEFVAR_INT ("overline-margin", overline_margin
,
29537 doc
: /* Space between overline and text, in pixels.
29538 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
29539 margin to the character height. */);
29540 overline_margin
= 2;
29542 DEFVAR_INT ("underline-minimum-offset",
29543 underline_minimum_offset
,
29544 doc
: /* Minimum distance between baseline and underline.
29545 This can improve legibility of underlined text at small font sizes,
29546 particularly when using variable `x-use-underline-position-properties'
29547 with fonts that specify an UNDERLINE_POSITION relatively close to the
29548 baseline. The default value is 1. */);
29549 underline_minimum_offset
= 1;
29551 DEFVAR_BOOL ("display-hourglass", display_hourglass_p
,
29552 doc
: /* Non-nil means show an hourglass pointer, when Emacs is busy.
29553 This feature only works when on a window system that can change
29554 cursor shapes. */);
29555 display_hourglass_p
= 1;
29557 DEFVAR_LISP ("hourglass-delay", Vhourglass_delay
,
29558 doc
: /* Seconds to wait before displaying an hourglass pointer when Emacs is busy. */);
29559 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
29561 hourglass_atimer
= NULL
;
29562 hourglass_shown_p
= 0;
29564 DEFSYM (Qglyphless_char
, "glyphless-char");
29565 DEFSYM (Qhex_code
, "hex-code");
29566 DEFSYM (Qempty_box
, "empty-box");
29567 DEFSYM (Qthin_space
, "thin-space");
29568 DEFSYM (Qzero_width
, "zero-width");
29570 DEFSYM (Qglyphless_char_display
, "glyphless-char-display");
29571 /* Intern this now in case it isn't already done.
29572 Setting this variable twice is harmless.
29573 But don't staticpro it here--that is done in alloc.c. */
29574 Qchar_table_extra_slots
= intern_c_string ("char-table-extra-slots");
29575 Fput (Qglyphless_char_display
, Qchar_table_extra_slots
, make_number (1));
29577 DEFVAR_LISP ("glyphless-char-display", Vglyphless_char_display
,
29578 doc
: /* Char-table defining glyphless characters.
29579 Each element, if non-nil, should be one of the following:
29580 an ASCII acronym string: display this string in a box
29581 `hex-code': display the hexadecimal code of a character in a box
29582 `empty-box': display as an empty box
29583 `thin-space': display as 1-pixel width space
29584 `zero-width': don't display
29585 An element may also be a cons cell (GRAPHICAL . TEXT), which specifies the
29586 display method for graphical terminals and text terminals respectively.
29587 GRAPHICAL and TEXT should each have one of the values listed above.
29589 The char-table has one extra slot to control the display of a character for
29590 which no font is found. This slot only takes effect on graphical terminals.
29591 Its value should be an ASCII acronym string, `hex-code', `empty-box', or
29592 `thin-space'. The default is `empty-box'. */);
29593 Vglyphless_char_display
= Fmake_char_table (Qglyphless_char_display
, Qnil
);
29594 Fset_char_table_extra_slot (Vglyphless_char_display
, make_number (0),
29597 DEFVAR_LISP ("debug-on-message", Vdebug_on_message
,
29598 doc
: /* If non-nil, debug if a message matching this regexp is displayed. */);
29599 Vdebug_on_message
= Qnil
;
29603 /* Initialize this module when Emacs starts. */
29608 current_header_line_height
= current_mode_line_height
= -1;
29610 CHARPOS (this_line_start_pos
) = 0;
29612 if (!noninteractive
)
29614 struct window
*m
= XWINDOW (minibuf_window
);
29615 Lisp_Object frame
= m
->frame
;
29616 struct frame
*f
= XFRAME (frame
);
29617 Lisp_Object root
= FRAME_ROOT_WINDOW (f
);
29618 struct window
*r
= XWINDOW (root
);
29621 echo_area_window
= minibuf_window
;
29623 wset_top_line (r
, make_number (FRAME_TOP_MARGIN (f
)));
29625 (r
, make_number (FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
)));
29626 wset_total_cols (r
, make_number (FRAME_COLS (f
)));
29627 wset_top_line (m
, make_number (FRAME_LINES (f
) - 1));
29628 wset_total_lines (m
, make_number (1));
29629 wset_total_cols (m
, make_number (FRAME_COLS (f
)));
29631 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
29632 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
29633 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
29635 /* The default ellipsis glyphs `...'. */
29636 for (i
= 0; i
< 3; ++i
)
29637 default_invis_vector
[i
] = make_number ('.');
29641 /* Allocate the buffer for frame titles.
29642 Also used for `format-mode-line'. */
29644 mode_line_noprop_buf
= xmalloc (size
);
29645 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
29646 mode_line_noprop_ptr
= mode_line_noprop_buf
;
29647 mode_line_target
= MODE_LINE_DISPLAY
;
29650 help_echo_showing_p
= 0;
29653 /* Platform-independent portion of hourglass implementation. */
29655 /* Cancel a currently active hourglass timer, and start a new one. */
29657 start_hourglass (void)
29659 #if defined (HAVE_WINDOW_SYSTEM)
29662 cancel_hourglass ();
29664 if (INTEGERP (Vhourglass_delay
)
29665 && XINT (Vhourglass_delay
) > 0)
29666 delay
= make_emacs_time (min (XINT (Vhourglass_delay
),
29667 TYPE_MAXIMUM (time_t)),
29669 else if (FLOATP (Vhourglass_delay
)
29670 && XFLOAT_DATA (Vhourglass_delay
) > 0)
29671 delay
= EMACS_TIME_FROM_DOUBLE (XFLOAT_DATA (Vhourglass_delay
));
29673 delay
= make_emacs_time (DEFAULT_HOURGLASS_DELAY
, 0);
29677 extern void w32_note_current_window (void);
29678 w32_note_current_window ();
29680 #endif /* HAVE_NTGUI */
29682 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
29683 show_hourglass
, NULL
);
29688 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
29691 cancel_hourglass (void)
29693 #if defined (HAVE_WINDOW_SYSTEM)
29694 if (hourglass_atimer
)
29696 cancel_atimer (hourglass_atimer
);
29697 hourglass_atimer
= NULL
;
29700 if (hourglass_shown_p
)