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. */
278 #include "keyboard.h"
281 #include "termchar.h"
282 #include "dispextern.h"
283 #include "character.h"
287 #include "commands.h"
291 #include "termhooks.h"
292 #include "termopts.h"
293 #include "intervals.h"
296 #include "region-cache.h"
299 #include "blockinput.h"
301 #ifdef HAVE_X_WINDOWS
316 #ifndef FRAME_X_OUTPUT
317 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
320 #define INFINITY 10000000
322 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
323 Lisp_Object Qwindow_scroll_functions
;
324 static Lisp_Object Qwindow_text_change_functions
;
325 static Lisp_Object Qredisplay_end_trigger_functions
;
326 Lisp_Object Qinhibit_point_motion_hooks
;
327 static Lisp_Object QCeval
, QCpropertize
;
328 Lisp_Object QCfile
, QCdata
;
329 static Lisp_Object Qfontified
;
330 static Lisp_Object Qgrow_only
;
331 static Lisp_Object Qinhibit_eval_during_redisplay
;
332 static Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
333 static Lisp_Object Qright_to_left
, Qleft_to_right
;
336 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
339 static Lisp_Object Qarrow
, Qhand
;
342 /* Holds the list (error). */
343 static Lisp_Object list_of_error
;
345 static Lisp_Object Qfontification_functions
;
347 static Lisp_Object Qwrap_prefix
;
348 static Lisp_Object Qline_prefix
;
350 /* Non-nil means don't actually do any redisplay. */
352 Lisp_Object Qinhibit_redisplay
;
354 /* Names of text properties relevant for redisplay. */
356 Lisp_Object Qdisplay
;
358 Lisp_Object Qspace
, QCalign_to
;
359 static Lisp_Object QCrelative_width
, QCrelative_height
;
360 Lisp_Object Qleft_margin
, Qright_margin
;
361 static Lisp_Object Qspace_width
, Qraise
;
362 static Lisp_Object Qslice
;
364 static Lisp_Object Qmargin
, Qpointer
;
365 static Lisp_Object Qline_height
;
367 /* These setters are used only in this file, so they can be private. */
369 wset_base_line_number (struct window
*w
, Lisp_Object val
)
371 w
->base_line_number
= val
;
374 wset_base_line_pos (struct window
*w
, Lisp_Object val
)
376 w
->base_line_pos
= val
;
379 wset_column_number_displayed (struct window
*w
, Lisp_Object val
)
381 w
->column_number_displayed
= val
;
384 wset_region_showing (struct window
*w
, Lisp_Object val
)
386 w
->region_showing
= val
;
389 #ifdef HAVE_WINDOW_SYSTEM
391 /* Test if overflow newline into fringe. Called with iterator IT
392 at or past right window margin, and with IT->current_x set. */
394 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(IT) \
395 (!NILP (Voverflow_newline_into_fringe) \
396 && FRAME_WINDOW_P ((IT)->f) \
397 && ((IT)->bidi_it.paragraph_dir == R2L \
398 ? (WINDOW_LEFT_FRINGE_WIDTH ((IT)->w) > 0) \
399 : (WINDOW_RIGHT_FRINGE_WIDTH ((IT)->w) > 0)) \
400 && (IT)->current_x == (IT)->last_visible_x \
401 && (IT)->line_wrap != WORD_WRAP)
403 #else /* !HAVE_WINDOW_SYSTEM */
404 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) 0
405 #endif /* HAVE_WINDOW_SYSTEM */
407 /* Test if the display element loaded in IT, or the underlying buffer
408 or string character, is a space or a TAB character. This is used
409 to determine where word wrapping can occur. */
411 #define IT_DISPLAYING_WHITESPACE(it) \
412 ((it->what == IT_CHARACTER && (it->c == ' ' || it->c == '\t')) \
413 || ((STRINGP (it->string) \
414 && (SREF (it->string, IT_STRING_BYTEPOS (*it)) == ' ' \
415 || SREF (it->string, IT_STRING_BYTEPOS (*it)) == '\t')) \
417 && (it->s[IT_BYTEPOS (*it)] == ' ' \
418 || it->s[IT_BYTEPOS (*it)] == '\t')) \
419 || (IT_BYTEPOS (*it) < ZV_BYTE \
420 && (*BYTE_POS_ADDR (IT_BYTEPOS (*it)) == ' ' \
421 || *BYTE_POS_ADDR (IT_BYTEPOS (*it)) == '\t')))) \
423 /* Name of the face used to highlight trailing whitespace. */
425 static Lisp_Object Qtrailing_whitespace
;
427 /* Name and number of the face used to highlight escape glyphs. */
429 static Lisp_Object Qescape_glyph
;
431 /* Name and number of the face used to highlight non-breaking spaces. */
433 static Lisp_Object Qnobreak_space
;
435 /* The symbol `image' which is the car of the lists used to represent
436 images in Lisp. Also a tool bar style. */
440 /* The image map types. */
442 static Lisp_Object QCpointer
;
443 static Lisp_Object Qrect
, Qcircle
, Qpoly
;
445 /* Tool bar styles */
446 Lisp_Object Qboth
, Qboth_horiz
, Qtext_image_horiz
;
448 /* Non-zero means print newline to stdout before next mini-buffer
451 int noninteractive_need_newline
;
453 /* Non-zero means print newline to message log before next message. */
455 static int message_log_need_newline
;
457 /* Three markers that message_dolog uses.
458 It could allocate them itself, but that causes trouble
459 in handling memory-full errors. */
460 static Lisp_Object message_dolog_marker1
;
461 static Lisp_Object message_dolog_marker2
;
462 static Lisp_Object message_dolog_marker3
;
464 /* The buffer position of the first character appearing entirely or
465 partially on the line of the selected window which contains the
466 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
467 redisplay optimization in redisplay_internal. */
469 static struct text_pos this_line_start_pos
;
471 /* Number of characters past the end of the line above, including the
472 terminating newline. */
474 static struct text_pos this_line_end_pos
;
476 /* The vertical positions and the height of this line. */
478 static int this_line_vpos
;
479 static int this_line_y
;
480 static int this_line_pixel_height
;
482 /* X position at which this display line starts. Usually zero;
483 negative if first character is partially visible. */
485 static int this_line_start_x
;
487 /* The smallest character position seen by move_it_* functions as they
488 move across display lines. Used to set MATRIX_ROW_START_CHARPOS of
489 hscrolled lines, see display_line. */
491 static struct text_pos this_line_min_pos
;
493 /* Buffer that this_line_.* variables are referring to. */
495 static struct buffer
*this_line_buffer
;
498 /* Values of those variables at last redisplay are stored as
499 properties on `overlay-arrow-position' symbol. However, if
500 Voverlay_arrow_position is a marker, last-arrow-position is its
501 numerical position. */
503 static Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
505 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
506 properties on a symbol in overlay-arrow-variable-list. */
508 static Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
510 Lisp_Object Qmenu_bar_update_hook
;
512 /* Nonzero if an overlay arrow has been displayed in this window. */
514 static int overlay_arrow_seen
;
516 /* Number of windows showing the buffer of the selected window (or
517 another buffer with the same base buffer). keyboard.c refers to
522 /* Vector containing glyphs for an ellipsis `...'. */
524 static Lisp_Object default_invis_vector
[3];
526 /* This is the window where the echo area message was displayed. It
527 is always a mini-buffer window, but it may not be the same window
528 currently active as a mini-buffer. */
530 Lisp_Object echo_area_window
;
532 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
533 pushes the current message and the value of
534 message_enable_multibyte on the stack, the function restore_message
535 pops the stack and displays MESSAGE again. */
537 static Lisp_Object Vmessage_stack
;
539 /* Nonzero means multibyte characters were enabled when the echo area
540 message was specified. */
542 static int message_enable_multibyte
;
544 /* Nonzero if we should redraw the mode lines on the next redisplay. */
546 int update_mode_lines
;
548 /* Nonzero if window sizes or contents have changed since last
549 redisplay that finished. */
551 int windows_or_buffers_changed
;
553 /* Nonzero means a frame's cursor type has been changed. */
555 int cursor_type_changed
;
557 /* Nonzero after display_mode_line if %l was used and it displayed a
560 static int line_number_displayed
;
562 /* The name of the *Messages* buffer, a string. */
564 static Lisp_Object Vmessages_buffer_name
;
566 /* Current, index 0, and last displayed echo area message. Either
567 buffers from echo_buffers, or nil to indicate no message. */
569 Lisp_Object echo_area_buffer
[2];
571 /* The buffers referenced from echo_area_buffer. */
573 static Lisp_Object echo_buffer
[2];
575 /* A vector saved used in with_area_buffer to reduce consing. */
577 static Lisp_Object Vwith_echo_area_save_vector
;
579 /* Non-zero means display_echo_area should display the last echo area
580 message again. Set by redisplay_preserve_echo_area. */
582 static int display_last_displayed_message_p
;
584 /* Nonzero if echo area is being used by print; zero if being used by
587 static int message_buf_print
;
589 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
591 static Lisp_Object Qinhibit_menubar_update
;
592 static Lisp_Object Qmessage_truncate_lines
;
594 /* Set to 1 in clear_message to make redisplay_internal aware
595 of an emptied echo area. */
597 static int message_cleared_p
;
599 /* A scratch glyph row with contents used for generating truncation
600 glyphs. Also used in direct_output_for_insert. */
602 #define MAX_SCRATCH_GLYPHS 100
603 static struct glyph_row scratch_glyph_row
;
604 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
606 /* Ascent and height of the last line processed by move_it_to. */
608 static int last_max_ascent
, last_height
;
610 /* Non-zero if there's a help-echo in the echo area. */
612 int help_echo_showing_p
;
614 /* If >= 0, computed, exact values of mode-line and header-line height
615 to use in the macros CURRENT_MODE_LINE_HEIGHT and
616 CURRENT_HEADER_LINE_HEIGHT. */
618 int current_mode_line_height
, current_header_line_height
;
620 /* The maximum distance to look ahead for text properties. Values
621 that are too small let us call compute_char_face and similar
622 functions too often which is expensive. Values that are too large
623 let us call compute_char_face and alike too often because we
624 might not be interested in text properties that far away. */
626 #define TEXT_PROP_DISTANCE_LIMIT 100
628 /* SAVE_IT and RESTORE_IT are called when we save a snapshot of the
629 iterator state and later restore it. This is needed because the
630 bidi iterator on bidi.c keeps a stacked cache of its states, which
631 is really a singleton. When we use scratch iterator objects to
632 move around the buffer, we can cause the bidi cache to be pushed or
633 popped, and therefore we need to restore the cache state when we
634 return to the original iterator. */
635 #define SAVE_IT(ITCOPY,ITORIG,CACHE) \
638 bidi_unshelve_cache (CACHE, 1); \
640 CACHE = bidi_shelve_cache (); \
643 #define RESTORE_IT(pITORIG,pITCOPY,CACHE) \
645 if (pITORIG != pITCOPY) \
646 *(pITORIG) = *(pITCOPY); \
647 bidi_unshelve_cache (CACHE, 0); \
653 /* Non-zero means print traces of redisplay if compiled with
654 GLYPH_DEBUG defined. */
656 int trace_redisplay_p
;
658 #endif /* GLYPH_DEBUG */
660 #ifdef DEBUG_TRACE_MOVE
661 /* Non-zero means trace with TRACE_MOVE to stderr. */
664 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
666 #define TRACE_MOVE(x) (void) 0
669 static Lisp_Object Qauto_hscroll_mode
;
671 /* Buffer being redisplayed -- for redisplay_window_error. */
673 static struct buffer
*displayed_buffer
;
675 /* Value returned from text property handlers (see below). */
680 HANDLED_RECOMPUTE_PROPS
,
681 HANDLED_OVERLAY_STRING_CONSUMED
,
685 /* A description of text properties that redisplay is interested
690 /* The name of the property. */
693 /* A unique index for the property. */
696 /* A handler function called to set up iterator IT from the property
697 at IT's current position. Value is used to steer handle_stop. */
698 enum prop_handled (*handler
) (struct it
*it
);
701 static enum prop_handled
handle_face_prop (struct it
*);
702 static enum prop_handled
handle_invisible_prop (struct it
*);
703 static enum prop_handled
handle_display_prop (struct it
*);
704 static enum prop_handled
handle_composition_prop (struct it
*);
705 static enum prop_handled
handle_overlay_change (struct it
*);
706 static enum prop_handled
handle_fontified_prop (struct it
*);
708 /* Properties handled by iterators. */
710 static struct props it_props
[] =
712 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
713 /* Handle `face' before `display' because some sub-properties of
714 `display' need to know the face. */
715 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
716 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
717 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
718 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
722 /* Value is the position described by X. If X is a marker, value is
723 the marker_position of X. Otherwise, value is X. */
725 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
727 /* Enumeration returned by some move_it_.* functions internally. */
731 /* Not used. Undefined value. */
734 /* Move ended at the requested buffer position or ZV. */
735 MOVE_POS_MATCH_OR_ZV
,
737 /* Move ended at the requested X pixel position. */
740 /* Move within a line ended at the end of a line that must be
744 /* Move within a line ended at the end of a line that would
745 be displayed truncated. */
748 /* Move within a line ended at a line end. */
752 /* This counter is used to clear the face cache every once in a while
753 in redisplay_internal. It is incremented for each redisplay.
754 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
757 #define CLEAR_FACE_CACHE_COUNT 500
758 static int clear_face_cache_count
;
760 /* Similarly for the image cache. */
762 #ifdef HAVE_WINDOW_SYSTEM
763 #define CLEAR_IMAGE_CACHE_COUNT 101
764 static int clear_image_cache_count
;
766 /* Null glyph slice */
767 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
770 /* True while redisplay_internal is in progress. */
774 static Lisp_Object Qinhibit_free_realized_faces
;
775 static Lisp_Object Qmode_line_default_help_echo
;
777 /* If a string, XTread_socket generates an event to display that string.
778 (The display is done in read_char.) */
780 Lisp_Object help_echo_string
;
781 Lisp_Object help_echo_window
;
782 Lisp_Object help_echo_object
;
783 ptrdiff_t help_echo_pos
;
785 /* Temporary variable for XTread_socket. */
787 Lisp_Object previous_help_echo_string
;
789 /* Platform-independent portion of hourglass implementation. */
791 /* Non-zero means an hourglass cursor is currently shown. */
792 int hourglass_shown_p
;
794 /* If non-null, an asynchronous timer that, when it expires, displays
795 an hourglass cursor on all frames. */
796 struct atimer
*hourglass_atimer
;
798 /* Name of the face used to display glyphless characters. */
799 Lisp_Object Qglyphless_char
;
801 /* Symbol for the purpose of Vglyphless_char_display. */
802 static Lisp_Object Qglyphless_char_display
;
804 /* Method symbols for Vglyphless_char_display. */
805 static Lisp_Object Qhex_code
, Qempty_box
, Qthin_space
, Qzero_width
;
807 /* Default pixel width of `thin-space' display method. */
808 #define THIN_SPACE_WIDTH 1
810 /* Default number of seconds to wait before displaying an hourglass
812 #define DEFAULT_HOURGLASS_DELAY 1
815 /* Function prototypes. */
817 static void setup_for_ellipsis (struct it
*, int);
818 static void set_iterator_to_next (struct it
*, int);
819 static void mark_window_display_accurate_1 (struct window
*, int);
820 static int single_display_spec_string_p (Lisp_Object
, Lisp_Object
);
821 static int display_prop_string_p (Lisp_Object
, Lisp_Object
);
822 static int cursor_row_p (struct glyph_row
*);
823 static int redisplay_mode_lines (Lisp_Object
, int);
824 static char *decode_mode_spec_coding (Lisp_Object
, char *, int);
826 static Lisp_Object
get_it_property (struct it
*it
, Lisp_Object prop
);
828 static void handle_line_prefix (struct it
*);
830 static void pint2str (char *, int, ptrdiff_t);
831 static void pint2hrstr (char *, int, ptrdiff_t);
832 static struct text_pos
run_window_scroll_functions (Lisp_Object
,
834 static void reconsider_clip_changes (struct window
*, struct buffer
*);
835 static int text_outside_line_unchanged_p (struct window
*,
836 ptrdiff_t, ptrdiff_t);
837 static void store_mode_line_noprop_char (char);
838 static int store_mode_line_noprop (const char *, int, int);
839 static void handle_stop (struct it
*);
840 static void handle_stop_backwards (struct it
*, ptrdiff_t);
841 static void vmessage (const char *, va_list) ATTRIBUTE_FORMAT_PRINTF (1, 0);
842 static void ensure_echo_area_buffers (void);
843 static Lisp_Object
unwind_with_echo_area_buffer (Lisp_Object
);
844 static Lisp_Object
with_echo_area_buffer_unwind_data (struct window
*);
845 static int with_echo_area_buffer (struct window
*, int,
846 int (*) (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t),
847 ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t);
848 static void clear_garbaged_frames (void);
849 static int current_message_1 (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t);
850 static void pop_message (void);
851 static int truncate_message_1 (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t);
852 static void set_message (const char *, Lisp_Object
, ptrdiff_t, int);
853 static int set_message_1 (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t);
854 static int display_echo_area (struct window
*);
855 static int display_echo_area_1 (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t);
856 static int resize_mini_window_1 (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t);
857 static Lisp_Object
unwind_redisplay (Lisp_Object
);
858 static int string_char_and_length (const unsigned char *, int *);
859 static struct text_pos
display_prop_end (struct it
*, Lisp_Object
,
861 static int compute_window_start_on_continuation_line (struct window
*);
862 static void insert_left_trunc_glyphs (struct it
*);
863 static struct glyph_row
*get_overlay_arrow_glyph_row (struct window
*,
865 static void extend_face_to_end_of_line (struct it
*);
866 static int append_space_for_newline (struct it
*, int);
867 static int cursor_row_fully_visible_p (struct window
*, int, int);
868 static int try_scrolling (Lisp_Object
, int, ptrdiff_t, ptrdiff_t, int, int);
869 static int try_cursor_movement (Lisp_Object
, struct text_pos
, int *);
870 static int trailing_whitespace_p (ptrdiff_t);
871 static intmax_t message_log_check_duplicate (ptrdiff_t, ptrdiff_t);
872 static void push_it (struct it
*, struct text_pos
*);
873 static void iterate_out_of_display_property (struct it
*);
874 static void pop_it (struct it
*);
875 static void sync_frame_with_window_matrix_rows (struct window
*);
876 static void select_frame_for_redisplay (Lisp_Object
);
877 static void redisplay_internal (void);
878 static int echo_area_display (int);
879 static void redisplay_windows (Lisp_Object
);
880 static void redisplay_window (Lisp_Object
, int);
881 static Lisp_Object
redisplay_window_error (Lisp_Object
);
882 static Lisp_Object
redisplay_window_0 (Lisp_Object
);
883 static Lisp_Object
redisplay_window_1 (Lisp_Object
);
884 static int set_cursor_from_row (struct window
*, struct glyph_row
*,
885 struct glyph_matrix
*, ptrdiff_t, ptrdiff_t,
887 static int update_menu_bar (struct frame
*, int, int);
888 static int try_window_reusing_current_matrix (struct window
*);
889 static int try_window_id (struct window
*);
890 static int display_line (struct it
*);
891 static int display_mode_lines (struct window
*);
892 static int display_mode_line (struct window
*, enum face_id
, Lisp_Object
);
893 static int display_mode_element (struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int);
894 static int store_mode_line_string (const char *, Lisp_Object
, int, int, int, Lisp_Object
);
895 static const char *decode_mode_spec (struct window
*, int, int, Lisp_Object
*);
896 static void display_menu_bar (struct window
*);
897 static ptrdiff_t display_count_lines (ptrdiff_t, ptrdiff_t, ptrdiff_t,
899 static int display_string (const char *, Lisp_Object
, Lisp_Object
,
900 ptrdiff_t, ptrdiff_t, struct it
*, int, int, int, int);
901 static void compute_line_metrics (struct it
*);
902 static void run_redisplay_end_trigger_hook (struct it
*);
903 static int get_overlay_strings (struct it
*, ptrdiff_t);
904 static int get_overlay_strings_1 (struct it
*, ptrdiff_t, int);
905 static void next_overlay_string (struct it
*);
906 static void reseat (struct it
*, struct text_pos
, int);
907 static void reseat_1 (struct it
*, struct text_pos
, int);
908 static void back_to_previous_visible_line_start (struct it
*);
909 void reseat_at_previous_visible_line_start (struct it
*);
910 static void reseat_at_next_visible_line_start (struct it
*, int);
911 static int next_element_from_ellipsis (struct it
*);
912 static int next_element_from_display_vector (struct it
*);
913 static int next_element_from_string (struct it
*);
914 static int next_element_from_c_string (struct it
*);
915 static int next_element_from_buffer (struct it
*);
916 static int next_element_from_composition (struct it
*);
917 static int next_element_from_image (struct it
*);
918 static int next_element_from_stretch (struct it
*);
919 static void load_overlay_strings (struct it
*, ptrdiff_t);
920 static int init_from_display_pos (struct it
*, struct window
*,
921 struct display_pos
*);
922 static void reseat_to_string (struct it
*, const char *,
923 Lisp_Object
, ptrdiff_t, ptrdiff_t, int, int);
924 static int get_next_display_element (struct it
*);
925 static enum move_it_result
926 move_it_in_display_line_to (struct it
*, ptrdiff_t, int,
927 enum move_operation_enum
);
928 void move_it_vertically_backward (struct it
*, int);
929 static void init_to_row_start (struct it
*, struct window
*,
931 static int init_to_row_end (struct it
*, struct window
*,
933 static void back_to_previous_line_start (struct it
*);
934 static int forward_to_next_line_start (struct it
*, int *, struct bidi_it
*);
935 static struct text_pos
string_pos_nchars_ahead (struct text_pos
,
936 Lisp_Object
, ptrdiff_t);
937 static struct text_pos
string_pos (ptrdiff_t, Lisp_Object
);
938 static struct text_pos
c_string_pos (ptrdiff_t, const char *, int);
939 static ptrdiff_t number_of_chars (const char *, int);
940 static void compute_stop_pos (struct it
*);
941 static void compute_string_pos (struct text_pos
*, struct text_pos
,
943 static int face_before_or_after_it_pos (struct it
*, int);
944 static ptrdiff_t next_overlay_change (ptrdiff_t);
945 static int handle_display_spec (struct it
*, Lisp_Object
, Lisp_Object
,
946 Lisp_Object
, struct text_pos
*, ptrdiff_t, int);
947 static int handle_single_display_spec (struct it
*, Lisp_Object
,
948 Lisp_Object
, Lisp_Object
,
949 struct text_pos
*, ptrdiff_t, int, int);
950 static int underlying_face_id (struct it
*);
951 static int in_ellipses_for_invisible_text_p (struct display_pos
*,
954 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
955 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
957 #ifdef HAVE_WINDOW_SYSTEM
959 static void x_consider_frame_title (Lisp_Object
);
960 static int tool_bar_lines_needed (struct frame
*, int *);
961 static void update_tool_bar (struct frame
*, int);
962 static void build_desired_tool_bar_string (struct frame
*f
);
963 static int redisplay_tool_bar (struct frame
*);
964 static void display_tool_bar_line (struct it
*, int);
965 static void notice_overwritten_cursor (struct window
*,
968 static void append_stretch_glyph (struct it
*, Lisp_Object
,
972 #endif /* HAVE_WINDOW_SYSTEM */
974 static void produce_special_glyphs (struct it
*, enum display_element_type
);
975 static void show_mouse_face (Mouse_HLInfo
*, enum draw_glyphs_face
);
976 static int coords_in_mouse_face_p (struct window
*, int, int);
980 /***********************************************************************
981 Window display dimensions
982 ***********************************************************************/
984 /* Return the bottom boundary y-position for text lines in window W.
985 This is the first y position at which a line cannot start.
986 It is relative to the top of the window.
988 This is the height of W minus the height of a mode line, if any. */
991 window_text_bottom_y (struct window
*w
)
993 int height
= WINDOW_TOTAL_HEIGHT (w
);
995 if (WINDOW_WANTS_MODELINE_P (w
))
996 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
1000 /* Return the pixel width of display area AREA of window W. AREA < 0
1001 means return the total width of W, not including fringes to
1002 the left and right of the window. */
1005 window_box_width (struct window
*w
, int area
)
1007 int cols
= XFASTINT (w
->total_cols
);
1010 if (!w
->pseudo_window_p
)
1012 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
1014 if (area
== TEXT_AREA
)
1016 if (INTEGERP (w
->left_margin_cols
))
1017 cols
-= XFASTINT (w
->left_margin_cols
);
1018 if (INTEGERP (w
->right_margin_cols
))
1019 cols
-= XFASTINT (w
->right_margin_cols
);
1020 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
1022 else if (area
== LEFT_MARGIN_AREA
)
1024 cols
= (INTEGERP (w
->left_margin_cols
)
1025 ? XFASTINT (w
->left_margin_cols
) : 0);
1028 else if (area
== RIGHT_MARGIN_AREA
)
1030 cols
= (INTEGERP (w
->right_margin_cols
)
1031 ? XFASTINT (w
->right_margin_cols
) : 0);
1036 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1040 /* Return the pixel height of the display area of window W, not
1041 including mode lines of W, if any. */
1044 window_box_height (struct window
*w
)
1046 struct frame
*f
= XFRAME (w
->frame
);
1047 int height
= WINDOW_TOTAL_HEIGHT (w
);
1049 eassert (height
>= 0);
1051 /* Note: the code below that determines the mode-line/header-line
1052 height is essentially the same as that contained in the macro
1053 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1054 the appropriate glyph row has its `mode_line_p' flag set,
1055 and if it doesn't, uses estimate_mode_line_height instead. */
1057 if (WINDOW_WANTS_MODELINE_P (w
))
1059 struct glyph_row
*ml_row
1060 = (w
->current_matrix
&& w
->current_matrix
->rows
1061 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1063 if (ml_row
&& ml_row
->mode_line_p
)
1064 height
-= ml_row
->height
;
1066 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1069 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1071 struct glyph_row
*hl_row
1072 = (w
->current_matrix
&& w
->current_matrix
->rows
1073 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1075 if (hl_row
&& hl_row
->mode_line_p
)
1076 height
-= hl_row
->height
;
1078 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1081 /* With a very small font and a mode-line that's taller than
1082 default, we might end up with a negative height. */
1083 return max (0, height
);
1086 /* Return the window-relative coordinate of the left edge of display
1087 area AREA of window W. AREA < 0 means return the left edge of the
1088 whole window, to the right of the left fringe of W. */
1091 window_box_left_offset (struct window
*w
, int area
)
1095 if (w
->pseudo_window_p
)
1098 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1100 if (area
== TEXT_AREA
)
1101 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1102 + window_box_width (w
, LEFT_MARGIN_AREA
));
1103 else if (area
== RIGHT_MARGIN_AREA
)
1104 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1105 + window_box_width (w
, LEFT_MARGIN_AREA
)
1106 + window_box_width (w
, TEXT_AREA
)
1107 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1109 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1110 else if (area
== LEFT_MARGIN_AREA
1111 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1112 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1118 /* Return the window-relative coordinate of the right edge of display
1119 area AREA of window W. AREA < 0 means return the right edge of the
1120 whole window, to the left of the right fringe of W. */
1123 window_box_right_offset (struct window
*w
, int area
)
1125 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1128 /* Return the frame-relative coordinate of the left edge of display
1129 area AREA of window W. AREA < 0 means return the left edge of the
1130 whole window, to the right of the left fringe of W. */
1133 window_box_left (struct window
*w
, int area
)
1135 struct frame
*f
= XFRAME (w
->frame
);
1138 if (w
->pseudo_window_p
)
1139 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1141 x
= (WINDOW_LEFT_EDGE_X (w
)
1142 + window_box_left_offset (w
, area
));
1148 /* Return the frame-relative coordinate of the right edge of display
1149 area AREA of window W. AREA < 0 means return the right edge of the
1150 whole window, to the left of the right fringe of W. */
1153 window_box_right (struct window
*w
, int area
)
1155 return window_box_left (w
, area
) + window_box_width (w
, area
);
1158 /* Get the bounding box of the display area AREA of window W, without
1159 mode lines, in frame-relative coordinates. AREA < 0 means the
1160 whole window, not including the left and right fringes of
1161 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1162 coordinates of the upper-left corner of the box. Return in
1163 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1166 window_box (struct window
*w
, int area
, int *box_x
, int *box_y
,
1167 int *box_width
, int *box_height
)
1170 *box_width
= window_box_width (w
, area
);
1172 *box_height
= window_box_height (w
);
1174 *box_x
= window_box_left (w
, area
);
1177 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1178 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1179 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1184 /* Get the bounding box of the display area AREA of window W, without
1185 mode lines. AREA < 0 means the whole window, not including the
1186 left and right fringe of the window. Return in *TOP_LEFT_X
1187 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1188 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1189 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1193 window_box_edges (struct window
*w
, int area
, int *top_left_x
, int *top_left_y
,
1194 int *bottom_right_x
, int *bottom_right_y
)
1196 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1198 *bottom_right_x
+= *top_left_x
;
1199 *bottom_right_y
+= *top_left_y
;
1204 /***********************************************************************
1206 ***********************************************************************/
1208 /* Return the bottom y-position of the line the iterator IT is in.
1209 This can modify IT's settings. */
1212 line_bottom_y (struct it
*it
)
1214 int line_height
= it
->max_ascent
+ it
->max_descent
;
1215 int line_top_y
= it
->current_y
;
1217 if (line_height
== 0)
1220 line_height
= last_height
;
1221 else if (IT_CHARPOS (*it
) < ZV
)
1223 move_it_by_lines (it
, 1);
1224 line_height
= (it
->max_ascent
|| it
->max_descent
1225 ? it
->max_ascent
+ it
->max_descent
1230 struct glyph_row
*row
= it
->glyph_row
;
1232 /* Use the default character height. */
1233 it
->glyph_row
= NULL
;
1234 it
->what
= IT_CHARACTER
;
1237 PRODUCE_GLYPHS (it
);
1238 line_height
= it
->ascent
+ it
->descent
;
1239 it
->glyph_row
= row
;
1243 return line_top_y
+ line_height
;
1246 /* Subroutine of pos_visible_p below. Extracts a display string, if
1247 any, from the display spec given as its argument. */
1249 string_from_display_spec (Lisp_Object spec
)
1253 while (CONSP (spec
))
1255 if (STRINGP (XCAR (spec
)))
1260 else if (VECTORP (spec
))
1264 for (i
= 0; i
< ASIZE (spec
); i
++)
1266 if (STRINGP (AREF (spec
, i
)))
1267 return AREF (spec
, i
);
1276 /* Limit insanely large values of W->hscroll on frame F to the largest
1277 value that will still prevent first_visible_x and last_visible_x of
1278 'struct it' from overflowing an int. */
1280 window_hscroll_limited (struct window
*w
, struct frame
*f
)
1282 ptrdiff_t window_hscroll
= w
->hscroll
;
1283 int window_text_width
= window_box_width (w
, TEXT_AREA
);
1284 int colwidth
= FRAME_COLUMN_WIDTH (f
);
1286 if (window_hscroll
> (INT_MAX
- window_text_width
) / colwidth
- 1)
1287 window_hscroll
= (INT_MAX
- window_text_width
) / colwidth
- 1;
1289 return window_hscroll
;
1292 /* Return 1 if position CHARPOS is visible in window W.
1293 CHARPOS < 0 means return info about WINDOW_END position.
1294 If visible, set *X and *Y to pixel coordinates of top left corner.
1295 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1296 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1299 pos_visible_p (struct window
*w
, ptrdiff_t charpos
, int *x
, int *y
,
1300 int *rtop
, int *rbot
, int *rowh
, int *vpos
)
1303 void *itdata
= bidi_shelve_cache ();
1304 struct text_pos top
;
1306 struct buffer
*old_buffer
= NULL
;
1308 if (FRAME_INITIAL_P (XFRAME (WINDOW_FRAME (w
))))
1311 if (XBUFFER (w
->buffer
) != current_buffer
)
1313 old_buffer
= current_buffer
;
1314 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1317 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1318 /* Scrolling a minibuffer window via scroll bar when the echo area
1319 shows long text sometimes resets the minibuffer contents behind
1321 if (CHARPOS (top
) > ZV
)
1322 SET_TEXT_POS (top
, BEGV
, BEGV_BYTE
);
1324 /* Compute exact mode line heights. */
1325 if (WINDOW_WANTS_MODELINE_P (w
))
1326 current_mode_line_height
1327 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1328 BVAR (current_buffer
, mode_line_format
));
1330 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1331 current_header_line_height
1332 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1333 BVAR (current_buffer
, header_line_format
));
1335 start_display (&it
, w
, top
);
1336 move_it_to (&it
, charpos
, -1, it
.last_visible_y
-1, -1,
1337 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1340 && (((!it
.bidi_p
|| it
.bidi_it
.scan_dir
== 1)
1341 && IT_CHARPOS (it
) >= charpos
)
1342 /* When scanning backwards under bidi iteration, move_it_to
1343 stops at or _before_ CHARPOS, because it stops at or to
1344 the _right_ of the character at CHARPOS. */
1345 || (it
.bidi_p
&& it
.bidi_it
.scan_dir
== -1
1346 && IT_CHARPOS (it
) <= charpos
)))
1348 /* We have reached CHARPOS, or passed it. How the call to
1349 move_it_to can overshoot: (i) If CHARPOS is on invisible text
1350 or covered by a display property, move_it_to stops at the end
1351 of the invisible text, to the right of CHARPOS. (ii) If
1352 CHARPOS is in a display vector, move_it_to stops on its last
1354 int top_x
= it
.current_x
;
1355 int top_y
= it
.current_y
;
1356 /* Calling line_bottom_y may change it.method, it.position, etc. */
1357 enum it_method it_method
= it
.method
;
1358 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1359 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1361 if (top_y
< window_top_y
)
1362 visible_p
= bottom_y
> window_top_y
;
1363 else if (top_y
< it
.last_visible_y
)
1365 if (bottom_y
>= it
.last_visible_y
1366 && it
.bidi_p
&& it
.bidi_it
.scan_dir
== -1
1367 && IT_CHARPOS (it
) < charpos
)
1369 /* When the last line of the window is scanned backwards
1370 under bidi iteration, we could be duped into thinking
1371 that we have passed CHARPOS, when in fact move_it_to
1372 simply stopped short of CHARPOS because it reached
1373 last_visible_y. To see if that's what happened, we call
1374 move_it_to again with a slightly larger vertical limit,
1375 and see if it actually moved vertically; if it did, we
1376 didn't really reach CHARPOS, which is beyond window end. */
1377 struct it save_it
= it
;
1378 /* Why 10? because we don't know how many canonical lines
1379 will the height of the next line(s) be. So we guess. */
1380 int ten_more_lines
=
1381 10 * FRAME_LINE_HEIGHT (XFRAME (WINDOW_FRAME (w
)));
1383 move_it_to (&it
, charpos
, -1, bottom_y
+ ten_more_lines
, -1,
1384 MOVE_TO_POS
| MOVE_TO_Y
);
1385 if (it
.current_y
> top_y
)
1392 if (it_method
== GET_FROM_DISPLAY_VECTOR
)
1394 /* We stopped on the last glyph of a display vector.
1395 Try and recompute. Hack alert! */
1396 if (charpos
< 2 || top
.charpos
>= charpos
)
1397 top_x
= it
.glyph_row
->x
;
1401 start_display (&it2
, w
, top
);
1402 move_it_to (&it2
, charpos
- 1, -1, -1, -1, MOVE_TO_POS
);
1403 get_next_display_element (&it2
);
1404 PRODUCE_GLYPHS (&it2
);
1405 if (ITERATOR_AT_END_OF_LINE_P (&it2
)
1406 || it2
.current_x
> it2
.last_visible_x
)
1407 top_x
= it
.glyph_row
->x
;
1410 top_x
= it2
.current_x
;
1411 top_y
= it2
.current_y
;
1415 else if (IT_CHARPOS (it
) != charpos
)
1417 Lisp_Object cpos
= make_number (charpos
);
1418 Lisp_Object spec
= Fget_char_property (cpos
, Qdisplay
, Qnil
);
1419 Lisp_Object string
= string_from_display_spec (spec
);
1420 int newline_in_string
= 0;
1422 if (STRINGP (string
))
1424 const char *s
= SSDATA (string
);
1425 const char *e
= s
+ SBYTES (string
);
1430 newline_in_string
= 1;
1435 /* The tricky code below is needed because there's a
1436 discrepancy between move_it_to and how we set cursor
1437 when the display line ends in a newline from a
1438 display string. move_it_to will stop _after_ such
1439 display strings, whereas set_cursor_from_row
1440 conspires with cursor_row_p to place the cursor on
1441 the first glyph produced from the display string. */
1443 /* We have overshoot PT because it is covered by a
1444 display property whose value is a string. If the
1445 string includes embedded newlines, we are also in the
1446 wrong display line. Backtrack to the correct line,
1447 where the display string begins. */
1448 if (newline_in_string
)
1450 Lisp_Object startpos
, endpos
;
1451 EMACS_INT start
, end
;
1455 /* Find the first and the last buffer positions
1456 covered by the display string. */
1458 Fnext_single_char_property_change (cpos
, Qdisplay
,
1461 Fprevious_single_char_property_change (endpos
, Qdisplay
,
1463 start
= XFASTINT (startpos
);
1464 end
= XFASTINT (endpos
);
1465 /* Move to the last buffer position before the
1466 display property. */
1467 start_display (&it3
, w
, top
);
1468 move_it_to (&it3
, start
- 1, -1, -1, -1, MOVE_TO_POS
);
1469 /* Move forward one more line if the position before
1470 the display string is a newline or if it is the
1471 rightmost character on a line that is
1472 continued or word-wrapped. */
1473 if (it3
.method
== GET_FROM_BUFFER
1475 move_it_by_lines (&it3
, 1);
1476 else if (move_it_in_display_line_to (&it3
, -1,
1480 == MOVE_LINE_CONTINUED
)
1482 move_it_by_lines (&it3
, 1);
1483 /* When we are under word-wrap, the #$@%!
1484 move_it_by_lines moves 2 lines, so we need to
1486 if (it3
.line_wrap
== WORD_WRAP
)
1487 move_it_by_lines (&it3
, -1);
1490 /* Record the vertical coordinate of the display
1491 line where we wound up. */
1492 top_y
= it3
.current_y
;
1495 /* When characters are reordered for display,
1496 the character displayed to the left of the
1497 display string could be _after_ the display
1498 property in the logical order. Use the
1499 smallest vertical position of these two. */
1500 start_display (&it3
, w
, top
);
1501 move_it_to (&it3
, end
+ 1, -1, -1, -1, MOVE_TO_POS
);
1502 if (it3
.current_y
< top_y
)
1503 top_y
= it3
.current_y
;
1505 /* Move from the top of the window to the beginning
1506 of the display line where the display string
1508 start_display (&it3
, w
, top
);
1509 move_it_to (&it3
, -1, 0, top_y
, -1, MOVE_TO_X
| MOVE_TO_Y
);
1510 /* If it3_moved stays zero after the 'while' loop
1511 below, that means we already were at a newline
1512 before the loop (e.g., the display string begins
1513 with a newline), so we don't need to (and cannot)
1514 inspect the glyphs of it3.glyph_row, because
1515 PRODUCE_GLYPHS will not produce anything for a
1516 newline, and thus it3.glyph_row stays at its
1517 stale content it got at top of the window. */
1519 /* Finally, advance the iterator until we hit the
1520 first display element whose character position is
1521 CHARPOS, or until the first newline from the
1522 display string, which signals the end of the
1524 while (get_next_display_element (&it3
))
1526 PRODUCE_GLYPHS (&it3
);
1527 if (IT_CHARPOS (it3
) == charpos
1528 || ITERATOR_AT_END_OF_LINE_P (&it3
))
1531 set_iterator_to_next (&it3
, 0);
1533 top_x
= it3
.current_x
- it3
.pixel_width
;
1534 /* Normally, we would exit the above loop because we
1535 found the display element whose character
1536 position is CHARPOS. For the contingency that we
1537 didn't, and stopped at the first newline from the
1538 display string, move back over the glyphs
1539 produced from the string, until we find the
1540 rightmost glyph not from the string. */
1542 && IT_CHARPOS (it3
) != charpos
&& EQ (it3
.object
, string
))
1544 struct glyph
*g
= it3
.glyph_row
->glyphs
[TEXT_AREA
]
1545 + it3
.glyph_row
->used
[TEXT_AREA
];
1547 while (EQ ((g
- 1)->object
, string
))
1550 top_x
-= g
->pixel_width
;
1552 eassert (g
< it3
.glyph_row
->glyphs
[TEXT_AREA
]
1553 + it3
.glyph_row
->used
[TEXT_AREA
]);
1559 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1560 *rtop
= max (0, window_top_y
- top_y
);
1561 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1562 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1563 - max (top_y
, window_top_y
)));
1569 /* We were asked to provide info about WINDOW_END. */
1571 void *it2data
= NULL
;
1573 SAVE_IT (it2
, it
, it2data
);
1574 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1575 move_it_by_lines (&it
, 1);
1576 if (charpos
< IT_CHARPOS (it
)
1577 || (it
.what
== IT_EOB
&& charpos
== IT_CHARPOS (it
)))
1580 RESTORE_IT (&it2
, &it2
, it2data
);
1581 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1583 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1584 *rtop
= max (0, -it2
.current_y
);
1585 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1586 - it
.last_visible_y
));
1587 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1589 - max (it2
.current_y
,
1590 WINDOW_HEADER_LINE_HEIGHT (w
))));
1594 bidi_unshelve_cache (it2data
, 1);
1596 bidi_unshelve_cache (itdata
, 0);
1599 set_buffer_internal_1 (old_buffer
);
1601 current_header_line_height
= current_mode_line_height
= -1;
1603 if (visible_p
&& w
->hscroll
> 0)
1605 window_hscroll_limited (w
, WINDOW_XFRAME (w
))
1606 * WINDOW_FRAME_COLUMN_WIDTH (w
);
1609 /* Debugging code. */
1611 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1612 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1614 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1621 /* Return the next character from STR. Return in *LEN the length of
1622 the character. This is like STRING_CHAR_AND_LENGTH but never
1623 returns an invalid character. If we find one, we return a `?', but
1624 with the length of the invalid character. */
1627 string_char_and_length (const unsigned char *str
, int *len
)
1631 c
= STRING_CHAR_AND_LENGTH (str
, *len
);
1632 if (!CHAR_VALID_P (c
))
1633 /* We may not change the length here because other places in Emacs
1634 don't use this function, i.e. they silently accept invalid
1643 /* Given a position POS containing a valid character and byte position
1644 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1646 static struct text_pos
1647 string_pos_nchars_ahead (struct text_pos pos
, Lisp_Object string
, ptrdiff_t nchars
)
1649 eassert (STRINGP (string
) && nchars
>= 0);
1651 if (STRING_MULTIBYTE (string
))
1653 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1658 string_char_and_length (p
, &len
);
1661 BYTEPOS (pos
) += len
;
1665 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1671 /* Value is the text position, i.e. character and byte position,
1672 for character position CHARPOS in STRING. */
1674 static inline struct text_pos
1675 string_pos (ptrdiff_t charpos
, Lisp_Object string
)
1677 struct text_pos pos
;
1678 eassert (STRINGP (string
));
1679 eassert (charpos
>= 0);
1680 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1685 /* Value is a text position, i.e. character and byte position, for
1686 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1687 means recognize multibyte characters. */
1689 static struct text_pos
1690 c_string_pos (ptrdiff_t charpos
, const char *s
, int multibyte_p
)
1692 struct text_pos pos
;
1694 eassert (s
!= NULL
);
1695 eassert (charpos
>= 0);
1701 SET_TEXT_POS (pos
, 0, 0);
1704 string_char_and_length ((const unsigned char *) s
, &len
);
1707 BYTEPOS (pos
) += len
;
1711 SET_TEXT_POS (pos
, charpos
, charpos
);
1717 /* Value is the number of characters in C string S. MULTIBYTE_P
1718 non-zero means recognize multibyte characters. */
1721 number_of_chars (const char *s
, int multibyte_p
)
1727 ptrdiff_t rest
= strlen (s
);
1729 const unsigned char *p
= (const unsigned char *) s
;
1731 for (nchars
= 0; rest
> 0; ++nchars
)
1733 string_char_and_length (p
, &len
);
1734 rest
-= len
, p
+= len
;
1738 nchars
= strlen (s
);
1744 /* Compute byte position NEWPOS->bytepos corresponding to
1745 NEWPOS->charpos. POS is a known position in string STRING.
1746 NEWPOS->charpos must be >= POS.charpos. */
1749 compute_string_pos (struct text_pos
*newpos
, struct text_pos pos
, Lisp_Object string
)
1751 eassert (STRINGP (string
));
1752 eassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1754 if (STRING_MULTIBYTE (string
))
1755 *newpos
= string_pos_nchars_ahead (pos
, string
,
1756 CHARPOS (*newpos
) - CHARPOS (pos
));
1758 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1762 Return an estimation of the pixel height of mode or header lines on
1763 frame F. FACE_ID specifies what line's height to estimate. */
1766 estimate_mode_line_height (struct frame
*f
, enum face_id face_id
)
1768 #ifdef HAVE_WINDOW_SYSTEM
1769 if (FRAME_WINDOW_P (f
))
1771 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1773 /* This function is called so early when Emacs starts that the face
1774 cache and mode line face are not yet initialized. */
1775 if (FRAME_FACE_CACHE (f
))
1777 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1781 height
= FONT_HEIGHT (face
->font
);
1782 if (face
->box_line_width
> 0)
1783 height
+= 2 * face
->box_line_width
;
1794 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1795 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1796 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1797 not force the value into range. */
1800 pixel_to_glyph_coords (FRAME_PTR f
, register int pix_x
, register int pix_y
,
1801 int *x
, int *y
, NativeRectangle
*bounds
, int noclip
)
1804 #ifdef HAVE_WINDOW_SYSTEM
1805 if (FRAME_WINDOW_P (f
))
1807 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1808 even for negative values. */
1810 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1812 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1814 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1815 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1818 STORE_NATIVE_RECT (*bounds
,
1819 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1820 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1821 FRAME_COLUMN_WIDTH (f
) - 1,
1822 FRAME_LINE_HEIGHT (f
) - 1);
1828 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1829 pix_x
= FRAME_TOTAL_COLS (f
);
1833 else if (pix_y
> FRAME_LINES (f
))
1834 pix_y
= FRAME_LINES (f
);
1844 /* Find the glyph under window-relative coordinates X/Y in window W.
1845 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1846 strings. Return in *HPOS and *VPOS the row and column number of
1847 the glyph found. Return in *AREA the glyph area containing X.
1848 Value is a pointer to the glyph found or null if X/Y is not on
1849 text, or we can't tell because W's current matrix is not up to
1854 x_y_to_hpos_vpos (struct window
*w
, int x
, int y
, int *hpos
, int *vpos
,
1855 int *dx
, int *dy
, int *area
)
1857 struct glyph
*glyph
, *end
;
1858 struct glyph_row
*row
= NULL
;
1861 /* Find row containing Y. Give up if some row is not enabled. */
1862 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1864 row
= MATRIX_ROW (w
->current_matrix
, i
);
1865 if (!row
->enabled_p
)
1867 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1874 /* Give up if Y is not in the window. */
1875 if (i
== w
->current_matrix
->nrows
)
1878 /* Get the glyph area containing X. */
1879 if (w
->pseudo_window_p
)
1886 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1888 *area
= LEFT_MARGIN_AREA
;
1889 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1891 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1894 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1898 *area
= RIGHT_MARGIN_AREA
;
1899 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1903 /* Find glyph containing X. */
1904 glyph
= row
->glyphs
[*area
];
1905 end
= glyph
+ row
->used
[*area
];
1907 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1909 x
-= glyph
->pixel_width
;
1919 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1922 *hpos
= glyph
- row
->glyphs
[*area
];
1926 /* Convert frame-relative x/y to coordinates relative to window W.
1927 Takes pseudo-windows into account. */
1930 frame_to_window_pixel_xy (struct window
*w
, int *x
, int *y
)
1932 if (w
->pseudo_window_p
)
1934 /* A pseudo-window is always full-width, and starts at the
1935 left edge of the frame, plus a frame border. */
1936 struct frame
*f
= XFRAME (w
->frame
);
1937 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1938 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1942 *x
-= WINDOW_LEFT_EDGE_X (w
);
1943 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1947 #ifdef HAVE_WINDOW_SYSTEM
1950 Return in RECTS[] at most N clipping rectangles for glyph string S.
1951 Return the number of stored rectangles. */
1954 get_glyph_string_clip_rects (struct glyph_string
*s
, NativeRectangle
*rects
, int n
)
1961 if (s
->row
->full_width_p
)
1963 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1964 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1965 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1967 /* Unless displaying a mode or menu bar line, which are always
1968 fully visible, clip to the visible part of the row. */
1969 if (s
->w
->pseudo_window_p
)
1970 r
.height
= s
->row
->visible_height
;
1972 r
.height
= s
->height
;
1976 /* This is a text line that may be partially visible. */
1977 r
.x
= window_box_left (s
->w
, s
->area
);
1978 r
.width
= window_box_width (s
->w
, s
->area
);
1979 r
.height
= s
->row
->visible_height
;
1983 if (r
.x
< s
->clip_head
->x
)
1985 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1986 r
.width
-= s
->clip_head
->x
- r
.x
;
1989 r
.x
= s
->clip_head
->x
;
1992 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1994 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1995 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
2000 /* If S draws overlapping rows, it's sufficient to use the top and
2001 bottom of the window for clipping because this glyph string
2002 intentionally draws over other lines. */
2003 if (s
->for_overlaps
)
2005 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
2006 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
2008 /* Alas, the above simple strategy does not work for the
2009 environments with anti-aliased text: if the same text is
2010 drawn onto the same place multiple times, it gets thicker.
2011 If the overlap we are processing is for the erased cursor, we
2012 take the intersection with the rectangle of the cursor. */
2013 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
2015 XRectangle rc
, r_save
= r
;
2017 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
2018 rc
.y
= s
->w
->phys_cursor
.y
;
2019 rc
.width
= s
->w
->phys_cursor_width
;
2020 rc
.height
= s
->w
->phys_cursor_height
;
2022 x_intersect_rectangles (&r_save
, &rc
, &r
);
2027 /* Don't use S->y for clipping because it doesn't take partially
2028 visible lines into account. For example, it can be negative for
2029 partially visible lines at the top of a window. */
2030 if (!s
->row
->full_width_p
2031 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
2032 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
2034 r
.y
= max (0, s
->row
->y
);
2037 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
2039 /* If drawing the cursor, don't let glyph draw outside its
2040 advertised boundaries. Cleartype does this under some circumstances. */
2041 if (s
->hl
== DRAW_CURSOR
)
2043 struct glyph
*glyph
= s
->first_glyph
;
2048 r
.width
-= s
->x
- r
.x
;
2051 r
.width
= min (r
.width
, glyph
->pixel_width
);
2053 /* If r.y is below window bottom, ensure that we still see a cursor. */
2054 height
= min (glyph
->ascent
+ glyph
->descent
,
2055 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
2056 max_y
= window_text_bottom_y (s
->w
) - height
;
2057 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
2058 if (s
->ybase
- glyph
->ascent
> max_y
)
2065 /* Don't draw cursor glyph taller than our actual glyph. */
2066 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
2067 if (height
< r
.height
)
2069 max_y
= r
.y
+ r
.height
;
2070 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
2071 r
.height
= min (max_y
- r
.y
, height
);
2078 XRectangle r_save
= r
;
2080 if (! x_intersect_rectangles (&r_save
, s
->row
->clip
, &r
))
2084 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
2085 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
2087 #ifdef CONVERT_FROM_XRECT
2088 CONVERT_FROM_XRECT (r
, *rects
);
2096 /* If we are processing overlapping and allowed to return
2097 multiple clipping rectangles, we exclude the row of the glyph
2098 string from the clipping rectangle. This is to avoid drawing
2099 the same text on the environment with anti-aliasing. */
2100 #ifdef CONVERT_FROM_XRECT
2103 XRectangle
*rs
= rects
;
2105 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
2107 if (s
->for_overlaps
& OVERLAPS_PRED
)
2110 if (r
.y
+ r
.height
> row_y
)
2113 rs
[i
].height
= row_y
- r
.y
;
2119 if (s
->for_overlaps
& OVERLAPS_SUCC
)
2122 if (r
.y
< row_y
+ s
->row
->visible_height
)
2124 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
2126 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
2127 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
2136 #ifdef CONVERT_FROM_XRECT
2137 for (i
= 0; i
< n
; i
++)
2138 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
2145 Return in *NR the clipping rectangle for glyph string S. */
2148 get_glyph_string_clip_rect (struct glyph_string
*s
, NativeRectangle
*nr
)
2150 get_glyph_string_clip_rects (s
, nr
, 1);
2155 Return the position and height of the phys cursor in window W.
2156 Set w->phys_cursor_width to width of phys cursor.
2160 get_phys_cursor_geometry (struct window
*w
, struct glyph_row
*row
,
2161 struct glyph
*glyph
, int *xp
, int *yp
, int *heightp
)
2163 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2164 int x
, y
, wd
, h
, h0
, y0
;
2166 /* Compute the width of the rectangle to draw. If on a stretch
2167 glyph, and `x-stretch-block-cursor' is nil, don't draw a
2168 rectangle as wide as the glyph, but use a canonical character
2170 wd
= glyph
->pixel_width
- 1;
2171 #if defined (HAVE_NTGUI) || defined (HAVE_NS)
2175 x
= w
->phys_cursor
.x
;
2182 if (glyph
->type
== STRETCH_GLYPH
2183 && !x_stretch_cursor_p
)
2184 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2185 w
->phys_cursor_width
= wd
;
2187 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
2189 /* If y is below window bottom, ensure that we still see a cursor. */
2190 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2192 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
2193 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
2195 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2198 h
= max (h
- (y0
- y
) + 1, h0
);
2203 y0
= window_text_bottom_y (w
) - h0
;
2211 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
2212 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2217 * Remember which glyph the mouse is over.
2221 remember_mouse_glyph (struct frame
*f
, int gx
, int gy
, NativeRectangle
*rect
)
2225 struct glyph_row
*r
, *gr
, *end_row
;
2226 enum window_part part
;
2227 enum glyph_row_area area
;
2228 int x
, y
, width
, height
;
2230 /* Try to determine frame pixel position and size of the glyph under
2231 frame pixel coordinates X/Y on frame F. */
2233 if (!f
->glyphs_initialized_p
2234 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, 0),
2237 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2238 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2242 w
= XWINDOW (window
);
2243 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2244 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2246 x
= window_relative_x_coord (w
, part
, gx
);
2247 y
= gy
- WINDOW_TOP_EDGE_Y (w
);
2249 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2250 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2252 if (w
->pseudo_window_p
)
2255 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2261 case ON_LEFT_MARGIN
:
2262 area
= LEFT_MARGIN_AREA
;
2265 case ON_RIGHT_MARGIN
:
2266 area
= RIGHT_MARGIN_AREA
;
2269 case ON_HEADER_LINE
:
2271 gr
= (part
== ON_HEADER_LINE
2272 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2273 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2276 goto text_glyph_row_found
;
2283 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2284 if (r
->y
+ r
->height
> y
)
2290 text_glyph_row_found
:
2293 struct glyph
*g
= gr
->glyphs
[area
];
2294 struct glyph
*end
= g
+ gr
->used
[area
];
2296 height
= gr
->height
;
2297 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2298 if (gx
+ g
->pixel_width
> x
)
2303 if (g
->type
== IMAGE_GLYPH
)
2305 /* Don't remember when mouse is over image, as
2306 image may have hot-spots. */
2307 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2310 width
= g
->pixel_width
;
2314 /* Use nominal char spacing at end of line. */
2316 gx
+= (x
/ width
) * width
;
2319 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2320 gx
+= window_box_left_offset (w
, area
);
2324 /* Use nominal line height at end of window. */
2325 gx
= (x
/ width
) * width
;
2327 gy
+= (y
/ height
) * height
;
2331 case ON_LEFT_FRINGE
:
2332 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2333 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2334 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2335 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2338 case ON_RIGHT_FRINGE
:
2339 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2340 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2341 : window_box_right_offset (w
, TEXT_AREA
));
2342 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2346 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2348 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2349 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2350 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2352 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2356 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2357 if (r
->y
+ r
->height
> y
)
2364 height
= gr
->height
;
2367 /* Use nominal line height at end of window. */
2369 gy
+= (y
/ height
) * height
;
2376 /* If there is no glyph under the mouse, then we divide the screen
2377 into a grid of the smallest glyph in the frame, and use that
2380 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2381 round down even for negative values. */
2387 gx
= (gx
/ width
) * width
;
2388 gy
= (gy
/ height
) * height
;
2393 gx
+= WINDOW_LEFT_EDGE_X (w
);
2394 gy
+= WINDOW_TOP_EDGE_Y (w
);
2397 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2399 /* Visible feedback for debugging. */
2402 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2403 f
->output_data
.x
->normal_gc
,
2404 gx
, gy
, width
, height
);
2410 #endif /* HAVE_WINDOW_SYSTEM */
2413 /***********************************************************************
2414 Lisp form evaluation
2415 ***********************************************************************/
2417 /* Error handler for safe_eval and safe_call. */
2420 safe_eval_handler (Lisp_Object arg
, ptrdiff_t nargs
, Lisp_Object
*args
)
2422 add_to_log ("Error during redisplay: %S signaled %S",
2423 Flist (nargs
, args
), arg
);
2427 /* Call function FUNC with the rest of NARGS - 1 arguments
2428 following. Return the result, or nil if something went
2429 wrong. Prevent redisplay during the evaluation. */
2432 safe_call (ptrdiff_t nargs
, Lisp_Object func
, ...)
2436 if (inhibit_eval_during_redisplay
)
2442 ptrdiff_t count
= SPECPDL_INDEX ();
2443 struct gcpro gcpro1
;
2444 Lisp_Object
*args
= alloca (nargs
* word_size
);
2447 va_start (ap
, func
);
2448 for (i
= 1; i
< nargs
; i
++)
2449 args
[i
] = va_arg (ap
, Lisp_Object
);
2453 gcpro1
.nvars
= nargs
;
2454 specbind (Qinhibit_redisplay
, Qt
);
2455 /* Use Qt to ensure debugger does not run,
2456 so there is no possibility of wanting to redisplay. */
2457 val
= internal_condition_case_n (Ffuncall
, nargs
, args
, Qt
,
2460 val
= unbind_to (count
, val
);
2467 /* Call function FN with one argument ARG.
2468 Return the result, or nil if something went wrong. */
2471 safe_call1 (Lisp_Object fn
, Lisp_Object arg
)
2473 return safe_call (2, fn
, arg
);
2476 static Lisp_Object Qeval
;
2479 safe_eval (Lisp_Object sexpr
)
2481 return safe_call1 (Qeval
, sexpr
);
2484 /* Call function FN with two arguments ARG1 and ARG2.
2485 Return the result, or nil if something went wrong. */
2488 safe_call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2490 return safe_call (3, fn
, arg1
, arg2
);
2495 /***********************************************************************
2497 ***********************************************************************/
2501 /* Define CHECK_IT to perform sanity checks on iterators.
2502 This is for debugging. It is too slow to do unconditionally. */
2505 check_it (struct it
*it
)
2507 if (it
->method
== GET_FROM_STRING
)
2509 eassert (STRINGP (it
->string
));
2510 eassert (IT_STRING_CHARPOS (*it
) >= 0);
2514 eassert (IT_STRING_CHARPOS (*it
) < 0);
2515 if (it
->method
== GET_FROM_BUFFER
)
2517 /* Check that character and byte positions agree. */
2518 eassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2523 eassert (it
->current
.dpvec_index
>= 0);
2525 eassert (it
->current
.dpvec_index
< 0);
2528 #define CHECK_IT(IT) check_it ((IT))
2532 #define CHECK_IT(IT) (void) 0
2537 #if defined GLYPH_DEBUG && defined ENABLE_CHECKING
2539 /* Check that the window end of window W is what we expect it
2540 to be---the last row in the current matrix displaying text. */
2543 check_window_end (struct window
*w
)
2545 if (!MINI_WINDOW_P (w
)
2546 && !NILP (w
->window_end_valid
))
2548 struct glyph_row
*row
;
2549 eassert ((row
= MATRIX_ROW (w
->current_matrix
,
2550 XFASTINT (w
->window_end_vpos
)),
2552 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2553 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2557 #define CHECK_WINDOW_END(W) check_window_end ((W))
2561 #define CHECK_WINDOW_END(W) (void) 0
2563 #endif /* GLYPH_DEBUG and ENABLE_CHECKING */
2567 /***********************************************************************
2568 Iterator initialization
2569 ***********************************************************************/
2571 /* Initialize IT for displaying current_buffer in window W, starting
2572 at character position CHARPOS. CHARPOS < 0 means that no buffer
2573 position is specified which is useful when the iterator is assigned
2574 a position later. BYTEPOS is the byte position corresponding to
2575 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2577 If ROW is not null, calls to produce_glyphs with IT as parameter
2578 will produce glyphs in that row.
2580 BASE_FACE_ID is the id of a base face to use. It must be one of
2581 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2582 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2583 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2585 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2586 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2587 will be initialized to use the corresponding mode line glyph row of
2588 the desired matrix of W. */
2591 init_iterator (struct it
*it
, struct window
*w
,
2592 ptrdiff_t charpos
, ptrdiff_t bytepos
,
2593 struct glyph_row
*row
, enum face_id base_face_id
)
2595 int highlight_region_p
;
2596 enum face_id remapped_base_face_id
= base_face_id
;
2598 /* Some precondition checks. */
2599 eassert (w
!= NULL
&& it
!= NULL
);
2600 eassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2603 /* If face attributes have been changed since the last redisplay,
2604 free realized faces now because they depend on face definitions
2605 that might have changed. Don't free faces while there might be
2606 desired matrices pending which reference these faces. */
2607 if (face_change_count
&& !inhibit_free_realized_faces
)
2609 face_change_count
= 0;
2610 free_all_realized_faces (Qnil
);
2613 /* Perhaps remap BASE_FACE_ID to a user-specified alternative. */
2614 if (! NILP (Vface_remapping_alist
))
2615 remapped_base_face_id
2616 = lookup_basic_face (XFRAME (w
->frame
), base_face_id
);
2618 /* Use one of the mode line rows of W's desired matrix if
2622 if (base_face_id
== MODE_LINE_FACE_ID
2623 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2624 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2625 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2626 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2630 memset (it
, 0, sizeof *it
);
2631 it
->current
.overlay_string_index
= -1;
2632 it
->current
.dpvec_index
= -1;
2633 it
->base_face_id
= remapped_base_face_id
;
2635 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2636 it
->paragraph_embedding
= L2R
;
2637 it
->bidi_it
.string
.lstring
= Qnil
;
2638 it
->bidi_it
.string
.s
= NULL
;
2639 it
->bidi_it
.string
.bufpos
= 0;
2641 /* The window in which we iterate over current_buffer: */
2642 XSETWINDOW (it
->window
, w
);
2644 it
->f
= XFRAME (w
->frame
);
2648 /* Extra space between lines (on window systems only). */
2649 if (base_face_id
== DEFAULT_FACE_ID
2650 && FRAME_WINDOW_P (it
->f
))
2652 if (NATNUMP (BVAR (current_buffer
, extra_line_spacing
)))
2653 it
->extra_line_spacing
= XFASTINT (BVAR (current_buffer
, extra_line_spacing
));
2654 else if (FLOATP (BVAR (current_buffer
, extra_line_spacing
)))
2655 it
->extra_line_spacing
= (XFLOAT_DATA (BVAR (current_buffer
, extra_line_spacing
))
2656 * FRAME_LINE_HEIGHT (it
->f
));
2657 else if (it
->f
->extra_line_spacing
> 0)
2658 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2659 it
->max_extra_line_spacing
= 0;
2662 /* If realized faces have been removed, e.g. because of face
2663 attribute changes of named faces, recompute them. When running
2664 in batch mode, the face cache of the initial frame is null. If
2665 we happen to get called, make a dummy face cache. */
2666 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2667 init_frame_faces (it
->f
);
2668 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2669 recompute_basic_faces (it
->f
);
2671 /* Current value of the `slice', `space-width', and 'height' properties. */
2672 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2673 it
->space_width
= Qnil
;
2674 it
->font_height
= Qnil
;
2675 it
->override_ascent
= -1;
2677 /* Are control characters displayed as `^C'? */
2678 it
->ctl_arrow_p
= !NILP (BVAR (current_buffer
, ctl_arrow
));
2680 /* -1 means everything between a CR and the following line end
2681 is invisible. >0 means lines indented more than this value are
2683 it
->selective
= (INTEGERP (BVAR (current_buffer
, selective_display
))
2685 (-1, XINT (BVAR (current_buffer
, selective_display
)),
2687 : (!NILP (BVAR (current_buffer
, selective_display
))
2689 it
->selective_display_ellipsis_p
2690 = !NILP (BVAR (current_buffer
, selective_display_ellipses
));
2692 /* Display table to use. */
2693 it
->dp
= window_display_table (w
);
2695 /* Are multibyte characters enabled in current_buffer? */
2696 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
2698 /* Non-zero if we should highlight the region. */
2700 = (!NILP (Vtransient_mark_mode
)
2701 && !NILP (BVAR (current_buffer
, mark_active
))
2702 && XMARKER (BVAR (current_buffer
, mark
))->buffer
!= 0);
2704 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2705 start and end of a visible region in window IT->w. Set both to
2706 -1 to indicate no region. */
2707 if (highlight_region_p
2708 /* Maybe highlight only in selected window. */
2709 && (/* Either show region everywhere. */
2710 highlight_nonselected_windows
2711 /* Or show region in the selected window. */
2712 || w
== XWINDOW (selected_window
)
2713 /* Or show the region if we are in the mini-buffer and W is
2714 the window the mini-buffer refers to. */
2715 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2716 && WINDOWP (minibuf_selected_window
)
2717 && w
== XWINDOW (minibuf_selected_window
))))
2719 ptrdiff_t markpos
= marker_position (BVAR (current_buffer
, mark
));
2720 it
->region_beg_charpos
= min (PT
, markpos
);
2721 it
->region_end_charpos
= max (PT
, markpos
);
2724 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2726 /* Get the position at which the redisplay_end_trigger hook should
2727 be run, if it is to be run at all. */
2728 if (MARKERP (w
->redisplay_end_trigger
)
2729 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2730 it
->redisplay_end_trigger_charpos
2731 = marker_position (w
->redisplay_end_trigger
);
2732 else if (INTEGERP (w
->redisplay_end_trigger
))
2733 it
->redisplay_end_trigger_charpos
=
2734 clip_to_bounds (PTRDIFF_MIN
, XINT (w
->redisplay_end_trigger
), PTRDIFF_MAX
);
2736 it
->tab_width
= SANE_TAB_WIDTH (current_buffer
);
2738 /* Are lines in the display truncated? */
2739 if (base_face_id
!= DEFAULT_FACE_ID
2741 || (! WINDOW_FULL_WIDTH_P (it
->w
)
2742 && ((!NILP (Vtruncate_partial_width_windows
)
2743 && !INTEGERP (Vtruncate_partial_width_windows
))
2744 || (INTEGERP (Vtruncate_partial_width_windows
)
2745 && (WINDOW_TOTAL_COLS (it
->w
)
2746 < XINT (Vtruncate_partial_width_windows
))))))
2747 it
->line_wrap
= TRUNCATE
;
2748 else if (NILP (BVAR (current_buffer
, truncate_lines
)))
2749 it
->line_wrap
= NILP (BVAR (current_buffer
, word_wrap
))
2750 ? WINDOW_WRAP
: WORD_WRAP
;
2752 it
->line_wrap
= TRUNCATE
;
2754 /* Get dimensions of truncation and continuation glyphs. These are
2755 displayed as fringe bitmaps under X, but we need them for such
2756 frames when the fringes are turned off. But leave the dimensions
2757 zero for tooltip frames, as these glyphs look ugly there and also
2758 sabotage calculations of tooltip dimensions in x-show-tip. */
2759 #ifdef HAVE_WINDOW_SYSTEM
2760 if (!(FRAME_WINDOW_P (it
->f
)
2761 && FRAMEP (tip_frame
)
2762 && it
->f
== XFRAME (tip_frame
)))
2765 if (it
->line_wrap
== TRUNCATE
)
2767 /* We will need the truncation glyph. */
2768 eassert (it
->glyph_row
== NULL
);
2769 produce_special_glyphs (it
, IT_TRUNCATION
);
2770 it
->truncation_pixel_width
= it
->pixel_width
;
2774 /* We will need the continuation glyph. */
2775 eassert (it
->glyph_row
== NULL
);
2776 produce_special_glyphs (it
, IT_CONTINUATION
);
2777 it
->continuation_pixel_width
= it
->pixel_width
;
2781 /* Reset these values to zero because the produce_special_glyphs
2782 above has changed them. */
2783 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2784 it
->phys_ascent
= it
->phys_descent
= 0;
2786 /* Set this after getting the dimensions of truncation and
2787 continuation glyphs, so that we don't produce glyphs when calling
2788 produce_special_glyphs, above. */
2789 it
->glyph_row
= row
;
2790 it
->area
= TEXT_AREA
;
2792 /* Forget any previous info about this row being reversed. */
2794 it
->glyph_row
->reversed_p
= 0;
2796 /* Get the dimensions of the display area. The display area
2797 consists of the visible window area plus a horizontally scrolled
2798 part to the left of the window. All x-values are relative to the
2799 start of this total display area. */
2800 if (base_face_id
!= DEFAULT_FACE_ID
)
2802 /* Mode lines, menu bar in terminal frames. */
2803 it
->first_visible_x
= 0;
2804 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2808 it
->first_visible_x
=
2809 window_hscroll_limited (it
->w
, it
->f
) * FRAME_COLUMN_WIDTH (it
->f
);
2810 it
->last_visible_x
= (it
->first_visible_x
2811 + window_box_width (w
, TEXT_AREA
));
2813 /* If we truncate lines, leave room for the truncation glyph(s) at
2814 the right margin. Otherwise, leave room for the continuation
2815 glyph(s). Done only if the window has no fringes. Since we
2816 don't know at this point whether there will be any R2L lines in
2817 the window, we reserve space for truncation/continuation glyphs
2818 even if only one of the fringes is absent. */
2819 if (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0
2820 || (it
->bidi_p
&& WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0))
2822 if (it
->line_wrap
== TRUNCATE
)
2823 it
->last_visible_x
-= it
->truncation_pixel_width
;
2825 it
->last_visible_x
-= it
->continuation_pixel_width
;
2828 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2829 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2832 /* Leave room for a border glyph. */
2833 if (!FRAME_WINDOW_P (it
->f
)
2834 && !WINDOW_RIGHTMOST_P (it
->w
))
2835 it
->last_visible_x
-= 1;
2837 it
->last_visible_y
= window_text_bottom_y (w
);
2839 /* For mode lines and alike, arrange for the first glyph having a
2840 left box line if the face specifies a box. */
2841 if (base_face_id
!= DEFAULT_FACE_ID
)
2845 it
->face_id
= remapped_base_face_id
;
2847 /* If we have a boxed mode line, make the first character appear
2848 with a left box line. */
2849 face
= FACE_FROM_ID (it
->f
, remapped_base_face_id
);
2850 if (face
->box
!= FACE_NO_BOX
)
2851 it
->start_of_box_run_p
= 1;
2854 /* If a buffer position was specified, set the iterator there,
2855 getting overlays and face properties from that position. */
2856 if (charpos
>= BUF_BEG (current_buffer
))
2858 it
->end_charpos
= ZV
;
2859 IT_CHARPOS (*it
) = charpos
;
2861 /* We will rely on `reseat' to set this up properly, via
2862 handle_face_prop. */
2863 it
->face_id
= it
->base_face_id
;
2865 /* Compute byte position if not specified. */
2866 if (bytepos
< charpos
)
2867 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2869 IT_BYTEPOS (*it
) = bytepos
;
2871 it
->start
= it
->current
;
2872 /* Do we need to reorder bidirectional text? Not if this is a
2873 unibyte buffer: by definition, none of the single-byte
2874 characters are strong R2L, so no reordering is needed. And
2875 bidi.c doesn't support unibyte buffers anyway. Also, don't
2876 reorder while we are loading loadup.el, since the tables of
2877 character properties needed for reordering are not yet
2881 && !NILP (BVAR (current_buffer
, bidi_display_reordering
))
2884 /* If we are to reorder bidirectional text, init the bidi
2888 /* Note the paragraph direction that this buffer wants to
2890 if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2892 it
->paragraph_embedding
= L2R
;
2893 else if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2895 it
->paragraph_embedding
= R2L
;
2897 it
->paragraph_embedding
= NEUTRAL_DIR
;
2898 bidi_unshelve_cache (NULL
, 0);
2899 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
2903 /* Compute faces etc. */
2904 reseat (it
, it
->current
.pos
, 1);
2911 /* Initialize IT for the display of window W with window start POS. */
2914 start_display (struct it
*it
, struct window
*w
, struct text_pos pos
)
2916 struct glyph_row
*row
;
2917 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2919 row
= w
->desired_matrix
->rows
+ first_vpos
;
2920 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2921 it
->first_vpos
= first_vpos
;
2923 /* Don't reseat to previous visible line start if current start
2924 position is in a string or image. */
2925 if (it
->method
== GET_FROM_BUFFER
&& it
->line_wrap
!= TRUNCATE
)
2927 int start_at_line_beg_p
;
2928 int first_y
= it
->current_y
;
2930 /* If window start is not at a line start, skip forward to POS to
2931 get the correct continuation lines width. */
2932 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2933 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2934 if (!start_at_line_beg_p
)
2938 reseat_at_previous_visible_line_start (it
);
2939 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2941 new_x
= it
->current_x
+ it
->pixel_width
;
2943 /* If lines are continued, this line may end in the middle
2944 of a multi-glyph character (e.g. a control character
2945 displayed as \003, or in the middle of an overlay
2946 string). In this case move_it_to above will not have
2947 taken us to the start of the continuation line but to the
2948 end of the continued line. */
2949 if (it
->current_x
> 0
2950 && it
->line_wrap
!= TRUNCATE
/* Lines are continued. */
2951 && (/* And glyph doesn't fit on the line. */
2952 new_x
> it
->last_visible_x
2953 /* Or it fits exactly and we're on a window
2955 || (new_x
== it
->last_visible_x
2956 && FRAME_WINDOW_P (it
->f
)
2957 && ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
2958 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
2959 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
2961 if ((it
->current
.dpvec_index
>= 0
2962 || it
->current
.overlay_string_index
>= 0)
2963 /* If we are on a newline from a display vector or
2964 overlay string, then we are already at the end of
2965 a screen line; no need to go to the next line in
2966 that case, as this line is not really continued.
2967 (If we do go to the next line, C-e will not DTRT.) */
2970 set_iterator_to_next (it
, 1);
2971 move_it_in_display_line_to (it
, -1, -1, 0);
2974 it
->continuation_lines_width
+= it
->current_x
;
2976 /* If the character at POS is displayed via a display
2977 vector, move_it_to above stops at the final glyph of
2978 IT->dpvec. To make the caller redisplay that character
2979 again (a.k.a. start at POS), we need to reset the
2980 dpvec_index to the beginning of IT->dpvec. */
2981 else if (it
->current
.dpvec_index
>= 0)
2982 it
->current
.dpvec_index
= 0;
2984 /* We're starting a new display line, not affected by the
2985 height of the continued line, so clear the appropriate
2986 fields in the iterator structure. */
2987 it
->max_ascent
= it
->max_descent
= 0;
2988 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2990 it
->current_y
= first_y
;
2992 it
->current_x
= it
->hpos
= 0;
2998 /* Return 1 if POS is a position in ellipses displayed for invisible
2999 text. W is the window we display, for text property lookup. */
3002 in_ellipses_for_invisible_text_p (struct display_pos
*pos
, struct window
*w
)
3004 Lisp_Object prop
, window
;
3006 ptrdiff_t charpos
= CHARPOS (pos
->pos
);
3008 /* If POS specifies a position in a display vector, this might
3009 be for an ellipsis displayed for invisible text. We won't
3010 get the iterator set up for delivering that ellipsis unless
3011 we make sure that it gets aware of the invisible text. */
3012 if (pos
->dpvec_index
>= 0
3013 && pos
->overlay_string_index
< 0
3014 && CHARPOS (pos
->string_pos
) < 0
3016 && (XSETWINDOW (window
, w
),
3017 prop
= Fget_char_property (make_number (charpos
),
3018 Qinvisible
, window
),
3019 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
3021 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
3023 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
3030 /* Initialize IT for stepping through current_buffer in window W,
3031 starting at position POS that includes overlay string and display
3032 vector/ control character translation position information. Value
3033 is zero if there are overlay strings with newlines at POS. */
3036 init_from_display_pos (struct it
*it
, struct window
*w
, struct display_pos
*pos
)
3038 ptrdiff_t charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
3039 int i
, overlay_strings_with_newlines
= 0;
3041 /* If POS specifies a position in a display vector, this might
3042 be for an ellipsis displayed for invisible text. We won't
3043 get the iterator set up for delivering that ellipsis unless
3044 we make sure that it gets aware of the invisible text. */
3045 if (in_ellipses_for_invisible_text_p (pos
, w
))
3051 /* Keep in mind: the call to reseat in init_iterator skips invisible
3052 text, so we might end up at a position different from POS. This
3053 is only a problem when POS is a row start after a newline and an
3054 overlay starts there with an after-string, and the overlay has an
3055 invisible property. Since we don't skip invisible text in
3056 display_line and elsewhere immediately after consuming the
3057 newline before the row start, such a POS will not be in a string,
3058 but the call to init_iterator below will move us to the
3060 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
3062 /* This only scans the current chunk -- it should scan all chunks.
3063 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
3064 to 16 in 22.1 to make this a lesser problem. */
3065 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
3067 const char *s
= SSDATA (it
->overlay_strings
[i
]);
3068 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
3070 while (s
< e
&& *s
!= '\n')
3075 overlay_strings_with_newlines
= 1;
3080 /* If position is within an overlay string, set up IT to the right
3082 if (pos
->overlay_string_index
>= 0)
3086 /* If the first overlay string happens to have a `display'
3087 property for an image, the iterator will be set up for that
3088 image, and we have to undo that setup first before we can
3089 correct the overlay string index. */
3090 if (it
->method
== GET_FROM_IMAGE
)
3093 /* We already have the first chunk of overlay strings in
3094 IT->overlay_strings. Load more until the one for
3095 pos->overlay_string_index is in IT->overlay_strings. */
3096 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
3098 ptrdiff_t n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
3099 it
->current
.overlay_string_index
= 0;
3102 load_overlay_strings (it
, 0);
3103 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
3107 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
3108 relative_index
= (it
->current
.overlay_string_index
3109 % OVERLAY_STRING_CHUNK_SIZE
);
3110 it
->string
= it
->overlay_strings
[relative_index
];
3111 eassert (STRINGP (it
->string
));
3112 it
->current
.string_pos
= pos
->string_pos
;
3113 it
->method
= GET_FROM_STRING
;
3116 if (CHARPOS (pos
->string_pos
) >= 0)
3118 /* Recorded position is not in an overlay string, but in another
3119 string. This can only be a string from a `display' property.
3120 IT should already be filled with that string. */
3121 it
->current
.string_pos
= pos
->string_pos
;
3122 eassert (STRINGP (it
->string
));
3125 /* Restore position in display vector translations, control
3126 character translations or ellipses. */
3127 if (pos
->dpvec_index
>= 0)
3129 if (it
->dpvec
== NULL
)
3130 get_next_display_element (it
);
3131 eassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
3132 it
->current
.dpvec_index
= pos
->dpvec_index
;
3136 return !overlay_strings_with_newlines
;
3140 /* Initialize IT for stepping through current_buffer in window W
3141 starting at ROW->start. */
3144 init_to_row_start (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3146 init_from_display_pos (it
, w
, &row
->start
);
3147 it
->start
= row
->start
;
3148 it
->continuation_lines_width
= row
->continuation_lines_width
;
3153 /* Initialize IT for stepping through current_buffer in window W
3154 starting in the line following ROW, i.e. starting at ROW->end.
3155 Value is zero if there are overlay strings with newlines at ROW's
3159 init_to_row_end (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3163 if (init_from_display_pos (it
, w
, &row
->end
))
3165 if (row
->continued_p
)
3166 it
->continuation_lines_width
3167 = row
->continuation_lines_width
+ row
->pixel_width
;
3178 /***********************************************************************
3180 ***********************************************************************/
3182 /* Called when IT reaches IT->stop_charpos. Handle text property and
3183 overlay changes. Set IT->stop_charpos to the next position where
3187 handle_stop (struct it
*it
)
3189 enum prop_handled handled
;
3190 int handle_overlay_change_p
;
3194 it
->current
.dpvec_index
= -1;
3195 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3196 it
->ignore_overlay_strings_at_pos_p
= 0;
3199 /* Use face of preceding text for ellipsis (if invisible) */
3200 if (it
->selective_display_ellipsis_p
)
3201 it
->saved_face_id
= it
->face_id
;
3205 handled
= HANDLED_NORMALLY
;
3207 /* Call text property handlers. */
3208 for (p
= it_props
; p
->handler
; ++p
)
3210 handled
= p
->handler (it
);
3212 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3214 else if (handled
== HANDLED_RETURN
)
3216 /* We still want to show before and after strings from
3217 overlays even if the actual buffer text is replaced. */
3218 if (!handle_overlay_change_p
3220 /* Don't call get_overlay_strings_1 if we already
3221 have overlay strings loaded, because doing so
3222 will load them again and push the iterator state
3223 onto the stack one more time, which is not
3224 expected by the rest of the code that processes
3226 || (it
->current
.overlay_string_index
< 0
3227 ? !get_overlay_strings_1 (it
, 0, 0)
3231 setup_for_ellipsis (it
, 0);
3232 /* When handling a display spec, we might load an
3233 empty string. In that case, discard it here. We
3234 used to discard it in handle_single_display_spec,
3235 but that causes get_overlay_strings_1, above, to
3236 ignore overlay strings that we must check. */
3237 if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3241 else if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3245 it
->ignore_overlay_strings_at_pos_p
= 1;
3246 it
->string_from_display_prop_p
= 0;
3247 it
->from_disp_prop_p
= 0;
3248 handle_overlay_change_p
= 0;
3250 handled
= HANDLED_RECOMPUTE_PROPS
;
3253 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3254 handle_overlay_change_p
= 0;
3257 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3259 /* Don't check for overlay strings below when set to deliver
3260 characters from a display vector. */
3261 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3262 handle_overlay_change_p
= 0;
3264 /* Handle overlay changes.
3265 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
3266 if it finds overlays. */
3267 if (handle_overlay_change_p
)
3268 handled
= handle_overlay_change (it
);
3273 setup_for_ellipsis (it
, 0);
3277 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3279 /* Determine where to stop next. */
3280 if (handled
== HANDLED_NORMALLY
)
3281 compute_stop_pos (it
);
3285 /* Compute IT->stop_charpos from text property and overlay change
3286 information for IT's current position. */
3289 compute_stop_pos (struct it
*it
)
3291 register INTERVAL iv
, next_iv
;
3292 Lisp_Object object
, limit
, position
;
3293 ptrdiff_t charpos
, bytepos
;
3295 if (STRINGP (it
->string
))
3297 /* Strings are usually short, so don't limit the search for
3299 it
->stop_charpos
= it
->end_charpos
;
3300 object
= it
->string
;
3302 charpos
= IT_STRING_CHARPOS (*it
);
3303 bytepos
= IT_STRING_BYTEPOS (*it
);
3309 /* If end_charpos is out of range for some reason, such as a
3310 misbehaving display function, rationalize it (Bug#5984). */
3311 if (it
->end_charpos
> ZV
)
3312 it
->end_charpos
= ZV
;
3313 it
->stop_charpos
= it
->end_charpos
;
3315 /* If next overlay change is in front of the current stop pos
3316 (which is IT->end_charpos), stop there. Note: value of
3317 next_overlay_change is point-max if no overlay change
3319 charpos
= IT_CHARPOS (*it
);
3320 bytepos
= IT_BYTEPOS (*it
);
3321 pos
= next_overlay_change (charpos
);
3322 if (pos
< it
->stop_charpos
)
3323 it
->stop_charpos
= pos
;
3325 /* If showing the region, we have to stop at the region
3326 start or end because the face might change there. */
3327 if (it
->region_beg_charpos
> 0)
3329 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
3330 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
3331 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
3332 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3335 /* Set up variables for computing the stop position from text
3336 property changes. */
3337 XSETBUFFER (object
, current_buffer
);
3338 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3341 /* Get the interval containing IT's position. Value is a null
3342 interval if there isn't such an interval. */
3343 position
= make_number (charpos
);
3344 iv
= validate_interval_range (object
, &position
, &position
, 0);
3347 Lisp_Object values_here
[LAST_PROP_IDX
];
3350 /* Get properties here. */
3351 for (p
= it_props
; p
->handler
; ++p
)
3352 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3354 /* Look for an interval following iv that has different
3356 for (next_iv
= next_interval (iv
);
3359 || XFASTINT (limit
) > next_iv
->position
));
3360 next_iv
= next_interval (next_iv
))
3362 for (p
= it_props
; p
->handler
; ++p
)
3364 Lisp_Object new_value
;
3366 new_value
= textget (next_iv
->plist
, *p
->name
);
3367 if (!EQ (values_here
[p
->idx
], new_value
))
3377 if (INTEGERP (limit
)
3378 && next_iv
->position
>= XFASTINT (limit
))
3379 /* No text property change up to limit. */
3380 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3382 /* Text properties change in next_iv. */
3383 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3387 if (it
->cmp_it
.id
< 0)
3389 ptrdiff_t stoppos
= it
->end_charpos
;
3391 if (it
->bidi_p
&& it
->bidi_it
.scan_dir
< 0)
3393 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
,
3394 stoppos
, it
->string
);
3397 eassert (STRINGP (it
->string
)
3398 || (it
->stop_charpos
>= BEGV
3399 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3403 /* Return the position of the next overlay change after POS in
3404 current_buffer. Value is point-max if no overlay change
3405 follows. This is like `next-overlay-change' but doesn't use
3409 next_overlay_change (ptrdiff_t pos
)
3411 ptrdiff_t i
, noverlays
;
3413 Lisp_Object
*overlays
;
3415 /* Get all overlays at the given position. */
3416 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3418 /* If any of these overlays ends before endpos,
3419 use its ending point instead. */
3420 for (i
= 0; i
< noverlays
; ++i
)
3425 oend
= OVERLAY_END (overlays
[i
]);
3426 oendpos
= OVERLAY_POSITION (oend
);
3427 endpos
= min (endpos
, oendpos
);
3433 /* How many characters forward to search for a display property or
3434 display string. Searching too far forward makes the bidi display
3435 sluggish, especially in small windows. */
3436 #define MAX_DISP_SCAN 250
3438 /* Return the character position of a display string at or after
3439 position specified by POSITION. If no display string exists at or
3440 after POSITION, return ZV. A display string is either an overlay
3441 with `display' property whose value is a string, or a `display'
3442 text property whose value is a string. STRING is data about the
3443 string to iterate; if STRING->lstring is nil, we are iterating a
3444 buffer. FRAME_WINDOW_P is non-zero when we are displaying a window
3445 on a GUI frame. DISP_PROP is set to zero if we searched
3446 MAX_DISP_SCAN characters forward without finding any display
3447 strings, non-zero otherwise. It is set to 2 if the display string
3448 uses any kind of `(space ...)' spec that will produce a stretch of
3449 white space in the text area. */
3451 compute_display_string_pos (struct text_pos
*position
,
3452 struct bidi_string_data
*string
,
3453 int frame_window_p
, int *disp_prop
)
3455 /* OBJECT = nil means current buffer. */
3456 Lisp_Object object
=
3457 (string
&& STRINGP (string
->lstring
)) ? string
->lstring
: Qnil
;
3458 Lisp_Object pos
, spec
, limpos
;
3459 int string_p
= (string
&& (STRINGP (string
->lstring
) || string
->s
));
3460 ptrdiff_t eob
= string_p
? string
->schars
: ZV
;
3461 ptrdiff_t begb
= string_p
? 0 : BEGV
;
3462 ptrdiff_t bufpos
, charpos
= CHARPOS (*position
);
3464 (charpos
< eob
- MAX_DISP_SCAN
) ? charpos
+ MAX_DISP_SCAN
: eob
;
3465 struct text_pos tpos
;
3471 /* We don't support display properties whose values are strings
3472 that have display string properties. */
3473 || string
->from_disp_str
3474 /* C strings cannot have display properties. */
3475 || (string
->s
&& !STRINGP (object
)))
3481 /* If the character at CHARPOS is where the display string begins,
3483 pos
= make_number (charpos
);
3484 if (STRINGP (object
))
3485 bufpos
= string
->bufpos
;
3489 if (!NILP (spec
= Fget_char_property (pos
, Qdisplay
, object
))
3491 || !EQ (Fget_char_property (make_number (charpos
- 1), Qdisplay
,
3494 && (rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
, bufpos
,
3502 /* Look forward for the first character with a `display' property
3503 that will replace the underlying text when displayed. */
3504 limpos
= make_number (lim
);
3506 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, limpos
);
3507 CHARPOS (tpos
) = XFASTINT (pos
);
3508 if (CHARPOS (tpos
) >= lim
)
3513 if (STRINGP (object
))
3514 BYTEPOS (tpos
) = string_char_to_byte (object
, CHARPOS (tpos
));
3516 BYTEPOS (tpos
) = CHAR_TO_BYTE (CHARPOS (tpos
));
3517 spec
= Fget_char_property (pos
, Qdisplay
, object
);
3518 if (!STRINGP (object
))
3519 bufpos
= CHARPOS (tpos
);
3520 } while (NILP (spec
)
3521 || !(rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
,
3522 bufpos
, frame_window_p
)));
3526 return CHARPOS (tpos
);
3529 /* Return the character position of the end of the display string that
3530 started at CHARPOS. If there's no display string at CHARPOS,
3531 return -1. A display string is either an overlay with `display'
3532 property whose value is a string or a `display' text property whose
3533 value is a string. */
3535 compute_display_string_end (ptrdiff_t charpos
, struct bidi_string_data
*string
)
3537 /* OBJECT = nil means current buffer. */
3538 Lisp_Object object
=
3539 (string
&& STRINGP (string
->lstring
)) ? string
->lstring
: Qnil
;
3540 Lisp_Object pos
= make_number (charpos
);
3542 (STRINGP (object
) || (string
&& string
->s
)) ? string
->schars
: ZV
;
3544 if (charpos
>= eob
|| (string
->s
&& !STRINGP (object
)))
3547 /* It could happen that the display property or overlay was removed
3548 since we found it in compute_display_string_pos above. One way
3549 this can happen is if JIT font-lock was called (through
3550 handle_fontified_prop), and jit-lock-functions remove text
3551 properties or overlays from the portion of buffer that includes
3552 CHARPOS. Muse mode is known to do that, for example. In this
3553 case, we return -1 to the caller, to signal that no display
3554 string is actually present at CHARPOS. See bidi_fetch_char for
3555 how this is handled.
3557 An alternative would be to never look for display properties past
3558 it->stop_charpos. But neither compute_display_string_pos nor
3559 bidi_fetch_char that calls it know or care where the next
3561 if (NILP (Fget_char_property (pos
, Qdisplay
, object
)))
3564 /* Look forward for the first character where the `display' property
3566 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, Qnil
);
3568 return XFASTINT (pos
);
3573 /***********************************************************************
3575 ***********************************************************************/
3577 /* Handle changes in the `fontified' property of the current buffer by
3578 calling hook functions from Qfontification_functions to fontify
3581 static enum prop_handled
3582 handle_fontified_prop (struct it
*it
)
3584 Lisp_Object prop
, pos
;
3585 enum prop_handled handled
= HANDLED_NORMALLY
;
3587 if (!NILP (Vmemory_full
))
3590 /* Get the value of the `fontified' property at IT's current buffer
3591 position. (The `fontified' property doesn't have a special
3592 meaning in strings.) If the value is nil, call functions from
3593 Qfontification_functions. */
3594 if (!STRINGP (it
->string
)
3596 && !NILP (Vfontification_functions
)
3597 && !NILP (Vrun_hooks
)
3598 && (pos
= make_number (IT_CHARPOS (*it
)),
3599 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3600 /* Ignore the special cased nil value always present at EOB since
3601 no amount of fontifying will be able to change it. */
3602 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3604 ptrdiff_t count
= SPECPDL_INDEX ();
3606 struct buffer
*obuf
= current_buffer
;
3607 int begv
= BEGV
, zv
= ZV
;
3608 int old_clip_changed
= current_buffer
->clip_changed
;
3610 val
= Vfontification_functions
;
3611 specbind (Qfontification_functions
, Qnil
);
3613 eassert (it
->end_charpos
== ZV
);
3615 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3616 safe_call1 (val
, pos
);
3619 Lisp_Object fns
, fn
;
3620 struct gcpro gcpro1
, gcpro2
;
3625 for (; CONSP (val
); val
= XCDR (val
))
3631 /* A value of t indicates this hook has a local
3632 binding; it means to run the global binding too.
3633 In a global value, t should not occur. If it
3634 does, we must ignore it to avoid an endless
3636 for (fns
= Fdefault_value (Qfontification_functions
);
3642 safe_call1 (fn
, pos
);
3646 safe_call1 (fn
, pos
);
3652 unbind_to (count
, Qnil
);
3654 /* Fontification functions routinely call `save-restriction'.
3655 Normally, this tags clip_changed, which can confuse redisplay
3656 (see discussion in Bug#6671). Since we don't perform any
3657 special handling of fontification changes in the case where
3658 `save-restriction' isn't called, there's no point doing so in
3659 this case either. So, if the buffer's restrictions are
3660 actually left unchanged, reset clip_changed. */
3661 if (obuf
== current_buffer
)
3663 if (begv
== BEGV
&& zv
== ZV
)
3664 current_buffer
->clip_changed
= old_clip_changed
;
3666 /* There isn't much we can reasonably do to protect against
3667 misbehaving fontification, but here's a fig leaf. */
3668 else if (BUFFER_LIVE_P (obuf
))
3669 set_buffer_internal_1 (obuf
);
3671 /* The fontification code may have added/removed text.
3672 It could do even a lot worse, but let's at least protect against
3673 the most obvious case where only the text past `pos' gets changed',
3674 as is/was done in grep.el where some escapes sequences are turned
3675 into face properties (bug#7876). */
3676 it
->end_charpos
= ZV
;
3678 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3679 something. This avoids an endless loop if they failed to
3680 fontify the text for which reason ever. */
3681 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3682 handled
= HANDLED_RECOMPUTE_PROPS
;
3690 /***********************************************************************
3692 ***********************************************************************/
3694 /* Set up iterator IT from face properties at its current position.
3695 Called from handle_stop. */
3697 static enum prop_handled
3698 handle_face_prop (struct it
*it
)
3701 ptrdiff_t next_stop
;
3703 if (!STRINGP (it
->string
))
3706 = face_at_buffer_position (it
->w
,
3708 it
->region_beg_charpos
,
3709 it
->region_end_charpos
,
3712 + TEXT_PROP_DISTANCE_LIMIT
),
3713 0, it
->base_face_id
);
3715 /* Is this a start of a run of characters with box face?
3716 Caveat: this can be called for a freshly initialized
3717 iterator; face_id is -1 in this case. We know that the new
3718 face will not change until limit, i.e. if the new face has a
3719 box, all characters up to limit will have one. But, as
3720 usual, we don't know whether limit is really the end. */
3721 if (new_face_id
!= it
->face_id
)
3723 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3725 /* If new face has a box but old face has not, this is
3726 the start of a run of characters with box, i.e. it has
3727 a shadow on the left side. The value of face_id of the
3728 iterator will be -1 if this is the initial call that gets
3729 the face. In this case, we have to look in front of IT's
3730 position and see whether there is a face != new_face_id. */
3731 it
->start_of_box_run_p
3732 = (new_face
->box
!= FACE_NO_BOX
3733 && (it
->face_id
>= 0
3734 || IT_CHARPOS (*it
) == BEG
3735 || new_face_id
!= face_before_it_pos (it
)));
3736 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3744 Lisp_Object from_overlay
3745 = (it
->current
.overlay_string_index
>= 0
3746 ? it
->string_overlays
[it
->current
.overlay_string_index
3747 % OVERLAY_STRING_CHUNK_SIZE
]
3750 /* See if we got to this string directly or indirectly from
3751 an overlay property. That includes the before-string or
3752 after-string of an overlay, strings in display properties
3753 provided by an overlay, their text properties, etc.
3755 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3756 if (! NILP (from_overlay
))
3757 for (i
= it
->sp
- 1; i
>= 0; i
--)
3759 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3761 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
3762 % OVERLAY_STRING_CHUNK_SIZE
];
3763 else if (! NILP (it
->stack
[i
].from_overlay
))
3764 from_overlay
= it
->stack
[i
].from_overlay
;
3766 if (!NILP (from_overlay
))
3770 if (! NILP (from_overlay
))
3772 bufpos
= IT_CHARPOS (*it
);
3773 /* For a string from an overlay, the base face depends
3774 only on text properties and ignores overlays. */
3776 = face_for_overlay_string (it
->w
,
3778 it
->region_beg_charpos
,
3779 it
->region_end_charpos
,
3782 + TEXT_PROP_DISTANCE_LIMIT
),
3790 /* For strings from a `display' property, use the face at
3791 IT's current buffer position as the base face to merge
3792 with, so that overlay strings appear in the same face as
3793 surrounding text, unless they specify their own
3795 base_face_id
= it
->string_from_prefix_prop_p
3797 : underlying_face_id (it
);
3800 new_face_id
= face_at_string_position (it
->w
,
3802 IT_STRING_CHARPOS (*it
),
3804 it
->region_beg_charpos
,
3805 it
->region_end_charpos
,
3809 /* Is this a start of a run of characters with box? Caveat:
3810 this can be called for a freshly allocated iterator; face_id
3811 is -1 is this case. We know that the new face will not
3812 change until the next check pos, i.e. if the new face has a
3813 box, all characters up to that position will have a
3814 box. But, as usual, we don't know whether that position
3815 is really the end. */
3816 if (new_face_id
!= it
->face_id
)
3818 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3819 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3821 /* If new face has a box but old face hasn't, this is the
3822 start of a run of characters with box, i.e. it has a
3823 shadow on the left side. */
3824 it
->start_of_box_run_p
3825 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3826 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3830 it
->face_id
= new_face_id
;
3831 return HANDLED_NORMALLY
;
3835 /* Return the ID of the face ``underlying'' IT's current position,
3836 which is in a string. If the iterator is associated with a
3837 buffer, return the face at IT's current buffer position.
3838 Otherwise, use the iterator's base_face_id. */
3841 underlying_face_id (struct it
*it
)
3843 int face_id
= it
->base_face_id
, i
;
3845 eassert (STRINGP (it
->string
));
3847 for (i
= it
->sp
- 1; i
>= 0; --i
)
3848 if (NILP (it
->stack
[i
].string
))
3849 face_id
= it
->stack
[i
].face_id
;
3855 /* Compute the face one character before or after the current position
3856 of IT, in the visual order. BEFORE_P non-zero means get the face
3857 in front (to the left in L2R paragraphs, to the right in R2L
3858 paragraphs) of IT's screen position. Value is the ID of the face. */
3861 face_before_or_after_it_pos (struct it
*it
, int before_p
)
3864 ptrdiff_t next_check_charpos
;
3866 void *it_copy_data
= NULL
;
3868 eassert (it
->s
== NULL
);
3870 if (STRINGP (it
->string
))
3872 ptrdiff_t bufpos
, charpos
;
3875 /* No face change past the end of the string (for the case
3876 we are padding with spaces). No face change before the
3878 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3879 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3884 /* Set charpos to the position before or after IT's current
3885 position, in the logical order, which in the non-bidi
3886 case is the same as the visual order. */
3888 charpos
= IT_STRING_CHARPOS (*it
) - 1;
3889 else if (it
->what
== IT_COMPOSITION
)
3890 /* For composition, we must check the character after the
3892 charpos
= IT_STRING_CHARPOS (*it
) + it
->cmp_it
.nchars
;
3894 charpos
= IT_STRING_CHARPOS (*it
) + 1;
3900 /* With bidi iteration, the character before the current
3901 in the visual order cannot be found by simple
3902 iteration, because "reverse" reordering is not
3903 supported. Instead, we need to use the move_it_*
3904 family of functions. */
3905 /* Ignore face changes before the first visible
3906 character on this display line. */
3907 if (it
->current_x
<= it
->first_visible_x
)
3909 SAVE_IT (it_copy
, *it
, it_copy_data
);
3910 /* Implementation note: Since move_it_in_display_line
3911 works in the iterator geometry, and thinks the first
3912 character is always the leftmost, even in R2L lines,
3913 we don't need to distinguish between the R2L and L2R
3915 move_it_in_display_line (&it_copy
, SCHARS (it_copy
.string
),
3916 it_copy
.current_x
- 1, MOVE_TO_X
);
3917 charpos
= IT_STRING_CHARPOS (it_copy
);
3918 RESTORE_IT (it
, it
, it_copy_data
);
3922 /* Set charpos to the string position of the character
3923 that comes after IT's current position in the visual
3925 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
3929 bidi_move_to_visually_next (&it_copy
.bidi_it
);
3931 charpos
= it_copy
.bidi_it
.charpos
;
3934 eassert (0 <= charpos
&& charpos
<= SCHARS (it
->string
));
3936 if (it
->current
.overlay_string_index
>= 0)
3937 bufpos
= IT_CHARPOS (*it
);
3941 base_face_id
= underlying_face_id (it
);
3943 /* Get the face for ASCII, or unibyte. */
3944 face_id
= face_at_string_position (it
->w
,
3948 it
->region_beg_charpos
,
3949 it
->region_end_charpos
,
3950 &next_check_charpos
,
3953 /* Correct the face for charsets different from ASCII. Do it
3954 for the multibyte case only. The face returned above is
3955 suitable for unibyte text if IT->string is unibyte. */
3956 if (STRING_MULTIBYTE (it
->string
))
3958 struct text_pos pos1
= string_pos (charpos
, it
->string
);
3959 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos1
);
3961 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3963 c
= string_char_and_length (p
, &len
);
3964 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, charpos
, it
->string
);
3969 struct text_pos pos
;
3971 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3972 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3975 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3976 pos
= it
->current
.pos
;
3981 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3984 if (it
->what
== IT_COMPOSITION
)
3986 /* For composition, we must check the position after
3988 pos
.charpos
+= it
->cmp_it
.nchars
;
3989 pos
.bytepos
+= it
->len
;
3992 INC_TEXT_POS (pos
, it
->multibyte_p
);
3999 /* With bidi iteration, the character before the current
4000 in the visual order cannot be found by simple
4001 iteration, because "reverse" reordering is not
4002 supported. Instead, we need to use the move_it_*
4003 family of functions. */
4004 /* Ignore face changes before the first visible
4005 character on this display line. */
4006 if (it
->current_x
<= it
->first_visible_x
)
4008 SAVE_IT (it_copy
, *it
, it_copy_data
);
4009 /* Implementation note: Since move_it_in_display_line
4010 works in the iterator geometry, and thinks the first
4011 character is always the leftmost, even in R2L lines,
4012 we don't need to distinguish between the R2L and L2R
4014 move_it_in_display_line (&it_copy
, ZV
,
4015 it_copy
.current_x
- 1, MOVE_TO_X
);
4016 pos
= it_copy
.current
.pos
;
4017 RESTORE_IT (it
, it
, it_copy_data
);
4021 /* Set charpos to the buffer position of the character
4022 that comes after IT's current position in the visual
4024 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
4028 bidi_move_to_visually_next (&it_copy
.bidi_it
);
4031 it_copy
.bidi_it
.charpos
, it_copy
.bidi_it
.bytepos
);
4034 eassert (BEGV
<= CHARPOS (pos
) && CHARPOS (pos
) <= ZV
);
4036 /* Determine face for CHARSET_ASCII, or unibyte. */
4037 face_id
= face_at_buffer_position (it
->w
,
4039 it
->region_beg_charpos
,
4040 it
->region_end_charpos
,
4041 &next_check_charpos
,
4044 /* Correct the face for charsets different from ASCII. Do it
4045 for the multibyte case only. The face returned above is
4046 suitable for unibyte text if current_buffer is unibyte. */
4047 if (it
->multibyte_p
)
4049 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
4050 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
4051 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
4060 /***********************************************************************
4062 ***********************************************************************/
4064 /* Set up iterator IT from invisible properties at its current
4065 position. Called from handle_stop. */
4067 static enum prop_handled
4068 handle_invisible_prop (struct it
*it
)
4070 enum prop_handled handled
= HANDLED_NORMALLY
;
4074 if (STRINGP (it
->string
))
4076 Lisp_Object end_charpos
, limit
, charpos
;
4078 /* Get the value of the invisible text property at the
4079 current position. Value will be nil if there is no such
4081 charpos
= make_number (IT_STRING_CHARPOS (*it
));
4082 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
4083 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4085 if (invis_p
&& IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
4087 /* Record whether we have to display an ellipsis for the
4089 int display_ellipsis_p
= (invis_p
== 2);
4090 ptrdiff_t len
, endpos
;
4092 handled
= HANDLED_RECOMPUTE_PROPS
;
4094 /* Get the position at which the next visible text can be
4095 found in IT->string, if any. */
4096 endpos
= len
= SCHARS (it
->string
);
4097 XSETINT (limit
, len
);
4100 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
4102 if (INTEGERP (end_charpos
))
4104 endpos
= XFASTINT (end_charpos
);
4105 prop
= Fget_text_property (end_charpos
, Qinvisible
, it
->string
);
4106 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4108 display_ellipsis_p
= 1;
4111 while (invis_p
&& endpos
< len
);
4113 if (display_ellipsis_p
)
4118 /* Text at END_CHARPOS is visible. Move IT there. */
4119 struct text_pos old
;
4122 old
= it
->current
.string_pos
;
4123 oldpos
= CHARPOS (old
);
4126 if (it
->bidi_it
.first_elt
4127 && it
->bidi_it
.charpos
< SCHARS (it
->string
))
4128 bidi_paragraph_init (it
->paragraph_embedding
,
4130 /* Bidi-iterate out of the invisible text. */
4133 bidi_move_to_visually_next (&it
->bidi_it
);
4135 while (oldpos
<= it
->bidi_it
.charpos
4136 && it
->bidi_it
.charpos
< endpos
);
4138 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4139 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4140 if (IT_CHARPOS (*it
) >= endpos
)
4141 it
->prev_stop
= endpos
;
4145 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
4146 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
4151 /* The rest of the string is invisible. If this is an
4152 overlay string, proceed with the next overlay string
4153 or whatever comes and return a character from there. */
4154 if (it
->current
.overlay_string_index
>= 0
4155 && !display_ellipsis_p
)
4157 next_overlay_string (it
);
4158 /* Don't check for overlay strings when we just
4159 finished processing them. */
4160 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
4164 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
4165 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
4172 ptrdiff_t newpos
, next_stop
, start_charpos
, tem
;
4173 Lisp_Object pos
, overlay
;
4175 /* First of all, is there invisible text at this position? */
4176 tem
= start_charpos
= IT_CHARPOS (*it
);
4177 pos
= make_number (tem
);
4178 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
4180 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4182 /* If we are on invisible text, skip over it. */
4183 if (invis_p
&& start_charpos
< it
->end_charpos
)
4185 /* Record whether we have to display an ellipsis for the
4187 int display_ellipsis_p
= invis_p
== 2;
4189 handled
= HANDLED_RECOMPUTE_PROPS
;
4191 /* Loop skipping over invisible text. The loop is left at
4192 ZV or with IT on the first char being visible again. */
4195 /* Try to skip some invisible text. Return value is the
4196 position reached which can be equal to where we start
4197 if there is nothing invisible there. This skips both
4198 over invisible text properties and overlays with
4199 invisible property. */
4200 newpos
= skip_invisible (tem
, &next_stop
, ZV
, it
->window
);
4202 /* If we skipped nothing at all we weren't at invisible
4203 text in the first place. If everything to the end of
4204 the buffer was skipped, end the loop. */
4205 if (newpos
== tem
|| newpos
>= ZV
)
4209 /* We skipped some characters but not necessarily
4210 all there are. Check if we ended up on visible
4211 text. Fget_char_property returns the property of
4212 the char before the given position, i.e. if we
4213 get invis_p = 0, this means that the char at
4214 newpos is visible. */
4215 pos
= make_number (newpos
);
4216 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
4217 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4220 /* If we ended up on invisible text, proceed to
4221 skip starting with next_stop. */
4225 /* If there are adjacent invisible texts, don't lose the
4226 second one's ellipsis. */
4228 display_ellipsis_p
= 1;
4232 /* The position newpos is now either ZV or on visible text. */
4235 ptrdiff_t bpos
= CHAR_TO_BYTE (newpos
);
4237 bpos
== ZV_BYTE
|| FETCH_BYTE (bpos
) == '\n';
4239 newpos
<= BEGV
|| FETCH_BYTE (bpos
- 1) == '\n';
4241 /* If the invisible text ends on a newline or on a
4242 character after a newline, we can avoid the costly,
4243 character by character, bidi iteration to NEWPOS, and
4244 instead simply reseat the iterator there. That's
4245 because all bidi reordering information is tossed at
4246 the newline. This is a big win for modes that hide
4247 complete lines, like Outline, Org, etc. */
4248 if (on_newline
|| after_newline
)
4250 struct text_pos tpos
;
4251 bidi_dir_t pdir
= it
->bidi_it
.paragraph_dir
;
4253 SET_TEXT_POS (tpos
, newpos
, bpos
);
4254 reseat_1 (it
, tpos
, 0);
4255 /* If we reseat on a newline/ZV, we need to prep the
4256 bidi iterator for advancing to the next character
4257 after the newline/EOB, keeping the current paragraph
4258 direction (so that PRODUCE_GLYPHS does TRT wrt
4259 prepending/appending glyphs to a glyph row). */
4262 it
->bidi_it
.first_elt
= 0;
4263 it
->bidi_it
.paragraph_dir
= pdir
;
4264 it
->bidi_it
.ch
= (bpos
== ZV_BYTE
) ? -1 : '\n';
4265 it
->bidi_it
.nchars
= 1;
4266 it
->bidi_it
.ch_len
= 1;
4269 else /* Must use the slow method. */
4271 /* With bidi iteration, the region of invisible text
4272 could start and/or end in the middle of a
4273 non-base embedding level. Therefore, we need to
4274 skip invisible text using the bidi iterator,
4275 starting at IT's current position, until we find
4276 ourselves outside of the invisible text.
4277 Skipping invisible text _after_ bidi iteration
4278 avoids affecting the visual order of the
4279 displayed text when invisible properties are
4280 added or removed. */
4281 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< ZV
)
4283 /* If we were `reseat'ed to a new paragraph,
4284 determine the paragraph base direction. We
4285 need to do it now because
4286 next_element_from_buffer may not have a
4287 chance to do it, if we are going to skip any
4288 text at the beginning, which resets the
4290 bidi_paragraph_init (it
->paragraph_embedding
,
4295 bidi_move_to_visually_next (&it
->bidi_it
);
4297 while (it
->stop_charpos
<= it
->bidi_it
.charpos
4298 && it
->bidi_it
.charpos
< newpos
);
4299 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4300 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4301 /* If we overstepped NEWPOS, record its position in
4302 the iterator, so that we skip invisible text if
4303 later the bidi iteration lands us in the
4304 invisible region again. */
4305 if (IT_CHARPOS (*it
) >= newpos
)
4306 it
->prev_stop
= newpos
;
4311 IT_CHARPOS (*it
) = newpos
;
4312 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
4315 /* If there are before-strings at the start of invisible
4316 text, and the text is invisible because of a text
4317 property, arrange to show before-strings because 20.x did
4318 it that way. (If the text is invisible because of an
4319 overlay property instead of a text property, this is
4320 already handled in the overlay code.) */
4322 && get_overlay_strings (it
, it
->stop_charpos
))
4324 handled
= HANDLED_RECOMPUTE_PROPS
;
4325 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
4327 else if (display_ellipsis_p
)
4329 /* Make sure that the glyphs of the ellipsis will get
4330 correct `charpos' values. If we would not update
4331 it->position here, the glyphs would belong to the
4332 last visible character _before_ the invisible
4333 text, which confuses `set_cursor_from_row'.
4335 We use the last invisible position instead of the
4336 first because this way the cursor is always drawn on
4337 the first "." of the ellipsis, whenever PT is inside
4338 the invisible text. Otherwise the cursor would be
4339 placed _after_ the ellipsis when the point is after the
4340 first invisible character. */
4341 if (!STRINGP (it
->object
))
4343 it
->position
.charpos
= newpos
- 1;
4344 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
4347 /* Let the ellipsis display before
4348 considering any properties of the following char.
4349 Fixes jasonr@gnu.org 01 Oct 07 bug. */
4350 handled
= HANDLED_RETURN
;
4359 /* Make iterator IT return `...' next.
4360 Replaces LEN characters from buffer. */
4363 setup_for_ellipsis (struct it
*it
, int len
)
4365 /* Use the display table definition for `...'. Invalid glyphs
4366 will be handled by the method returning elements from dpvec. */
4367 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
4369 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
4370 it
->dpvec
= v
->contents
;
4371 it
->dpend
= v
->contents
+ v
->header
.size
;
4375 /* Default `...'. */
4376 it
->dpvec
= default_invis_vector
;
4377 it
->dpend
= default_invis_vector
+ 3;
4380 it
->dpvec_char_len
= len
;
4381 it
->current
.dpvec_index
= 0;
4382 it
->dpvec_face_id
= -1;
4384 /* Remember the current face id in case glyphs specify faces.
4385 IT's face is restored in set_iterator_to_next.
4386 saved_face_id was set to preceding char's face in handle_stop. */
4387 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
4388 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
4390 it
->method
= GET_FROM_DISPLAY_VECTOR
;
4396 /***********************************************************************
4398 ***********************************************************************/
4400 /* Set up iterator IT from `display' property at its current position.
4401 Called from handle_stop.
4402 We return HANDLED_RETURN if some part of the display property
4403 overrides the display of the buffer text itself.
4404 Otherwise we return HANDLED_NORMALLY. */
4406 static enum prop_handled
4407 handle_display_prop (struct it
*it
)
4409 Lisp_Object propval
, object
, overlay
;
4410 struct text_pos
*position
;
4412 /* Nonzero if some property replaces the display of the text itself. */
4413 int display_replaced_p
= 0;
4415 if (STRINGP (it
->string
))
4417 object
= it
->string
;
4418 position
= &it
->current
.string_pos
;
4419 bufpos
= CHARPOS (it
->current
.pos
);
4423 XSETWINDOW (object
, it
->w
);
4424 position
= &it
->current
.pos
;
4425 bufpos
= CHARPOS (*position
);
4428 /* Reset those iterator values set from display property values. */
4429 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
4430 it
->space_width
= Qnil
;
4431 it
->font_height
= Qnil
;
4434 /* We don't support recursive `display' properties, i.e. string
4435 values that have a string `display' property, that have a string
4436 `display' property etc. */
4437 if (!it
->string_from_display_prop_p
)
4438 it
->area
= TEXT_AREA
;
4440 propval
= get_char_property_and_overlay (make_number (position
->charpos
),
4441 Qdisplay
, object
, &overlay
);
4443 return HANDLED_NORMALLY
;
4444 /* Now OVERLAY is the overlay that gave us this property, or nil
4445 if it was a text property. */
4447 if (!STRINGP (it
->string
))
4448 object
= it
->w
->buffer
;
4450 display_replaced_p
= handle_display_spec (it
, propval
, object
, overlay
,
4452 FRAME_WINDOW_P (it
->f
));
4454 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
4457 /* Subroutine of handle_display_prop. Returns non-zero if the display
4458 specification in SPEC is a replacing specification, i.e. it would
4459 replace the text covered by `display' property with something else,
4460 such as an image or a display string. If SPEC includes any kind or
4461 `(space ...) specification, the value is 2; this is used by
4462 compute_display_string_pos, which see.
4464 See handle_single_display_spec for documentation of arguments.
4465 frame_window_p is non-zero if the window being redisplayed is on a
4466 GUI frame; this argument is used only if IT is NULL, see below.
4468 IT can be NULL, if this is called by the bidi reordering code
4469 through compute_display_string_pos, which see. In that case, this
4470 function only examines SPEC, but does not otherwise "handle" it, in
4471 the sense that it doesn't set up members of IT from the display
4474 handle_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4475 Lisp_Object overlay
, struct text_pos
*position
,
4476 ptrdiff_t bufpos
, int frame_window_p
)
4478 int replacing_p
= 0;
4482 /* Simple specifications. */
4483 && !EQ (XCAR (spec
), Qimage
)
4484 && !EQ (XCAR (spec
), Qspace
)
4485 && !EQ (XCAR (spec
), Qwhen
)
4486 && !EQ (XCAR (spec
), Qslice
)
4487 && !EQ (XCAR (spec
), Qspace_width
)
4488 && !EQ (XCAR (spec
), Qheight
)
4489 && !EQ (XCAR (spec
), Qraise
)
4490 /* Marginal area specifications. */
4491 && !(CONSP (XCAR (spec
)) && EQ (XCAR (XCAR (spec
)), Qmargin
))
4492 && !EQ (XCAR (spec
), Qleft_fringe
)
4493 && !EQ (XCAR (spec
), Qright_fringe
)
4494 && !NILP (XCAR (spec
)))
4496 for (; CONSP (spec
); spec
= XCDR (spec
))
4498 if ((rv
= handle_single_display_spec (it
, XCAR (spec
), object
,
4499 overlay
, position
, bufpos
,
4500 replacing_p
, frame_window_p
)))
4503 /* If some text in a string is replaced, `position' no
4504 longer points to the position of `object'. */
4505 if (!it
|| STRINGP (object
))
4510 else if (VECTORP (spec
))
4513 for (i
= 0; i
< ASIZE (spec
); ++i
)
4514 if ((rv
= handle_single_display_spec (it
, AREF (spec
, i
), object
,
4515 overlay
, position
, bufpos
,
4516 replacing_p
, frame_window_p
)))
4519 /* If some text in a string is replaced, `position' no
4520 longer points to the position of `object'. */
4521 if (!it
|| STRINGP (object
))
4527 if ((rv
= handle_single_display_spec (it
, spec
, object
, overlay
,
4528 position
, bufpos
, 0,
4536 /* Value is the position of the end of the `display' property starting
4537 at START_POS in OBJECT. */
4539 static struct text_pos
4540 display_prop_end (struct it
*it
, Lisp_Object object
, struct text_pos start_pos
)
4543 struct text_pos end_pos
;
4545 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
4546 Qdisplay
, object
, Qnil
);
4547 CHARPOS (end_pos
) = XFASTINT (end
);
4548 if (STRINGP (object
))
4549 compute_string_pos (&end_pos
, start_pos
, it
->string
);
4551 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
4557 /* Set up IT from a single `display' property specification SPEC. OBJECT
4558 is the object in which the `display' property was found. *POSITION
4559 is the position in OBJECT at which the `display' property was found.
4560 BUFPOS is the buffer position of OBJECT (different from POSITION if
4561 OBJECT is not a buffer). DISPLAY_REPLACED_P non-zero means that we
4562 previously saw a display specification which already replaced text
4563 display with something else, for example an image; we ignore such
4564 properties after the first one has been processed.
4566 OVERLAY is the overlay this `display' property came from,
4567 or nil if it was a text property.
4569 If SPEC is a `space' or `image' specification, and in some other
4570 cases too, set *POSITION to the position where the `display'
4573 If IT is NULL, only examine the property specification in SPEC, but
4574 don't set up IT. In that case, FRAME_WINDOW_P non-zero means SPEC
4575 is intended to be displayed in a window on a GUI frame.
4577 Value is non-zero if something was found which replaces the display
4578 of buffer or string text. */
4581 handle_single_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4582 Lisp_Object overlay
, struct text_pos
*position
,
4583 ptrdiff_t bufpos
, int display_replaced_p
,
4587 Lisp_Object location
, value
;
4588 struct text_pos start_pos
= *position
;
4591 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
4592 If the result is non-nil, use VALUE instead of SPEC. */
4594 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4603 if (!NILP (form
) && !EQ (form
, Qt
))
4605 ptrdiff_t count
= SPECPDL_INDEX ();
4606 struct gcpro gcpro1
;
4608 /* Bind `object' to the object having the `display' property, a
4609 buffer or string. Bind `position' to the position in the
4610 object where the property was found, and `buffer-position'
4611 to the current position in the buffer. */
4614 XSETBUFFER (object
, current_buffer
);
4615 specbind (Qobject
, object
);
4616 specbind (Qposition
, make_number (CHARPOS (*position
)));
4617 specbind (Qbuffer_position
, make_number (bufpos
));
4619 form
= safe_eval (form
);
4621 unbind_to (count
, Qnil
);
4627 /* Handle `(height HEIGHT)' specifications. */
4629 && EQ (XCAR (spec
), Qheight
)
4630 && CONSP (XCDR (spec
)))
4634 if (!FRAME_WINDOW_P (it
->f
))
4637 it
->font_height
= XCAR (XCDR (spec
));
4638 if (!NILP (it
->font_height
))
4640 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4641 int new_height
= -1;
4643 if (CONSP (it
->font_height
)
4644 && (EQ (XCAR (it
->font_height
), Qplus
)
4645 || EQ (XCAR (it
->font_height
), Qminus
))
4646 && CONSP (XCDR (it
->font_height
))
4647 && RANGED_INTEGERP (0, XCAR (XCDR (it
->font_height
)), INT_MAX
))
4649 /* `(+ N)' or `(- N)' where N is an integer. */
4650 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4651 if (EQ (XCAR (it
->font_height
), Qplus
))
4653 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4655 else if (FUNCTIONP (it
->font_height
))
4657 /* Call function with current height as argument.
4658 Value is the new height. */
4660 height
= safe_call1 (it
->font_height
,
4661 face
->lface
[LFACE_HEIGHT_INDEX
]);
4662 if (NUMBERP (height
))
4663 new_height
= XFLOATINT (height
);
4665 else if (NUMBERP (it
->font_height
))
4667 /* Value is a multiple of the canonical char height. */
4670 f
= FACE_FROM_ID (it
->f
,
4671 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4672 new_height
= (XFLOATINT (it
->font_height
)
4673 * XINT (f
->lface
[LFACE_HEIGHT_INDEX
]));
4677 /* Evaluate IT->font_height with `height' bound to the
4678 current specified height to get the new height. */
4679 ptrdiff_t count
= SPECPDL_INDEX ();
4681 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4682 value
= safe_eval (it
->font_height
);
4683 unbind_to (count
, Qnil
);
4685 if (NUMBERP (value
))
4686 new_height
= XFLOATINT (value
);
4690 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4697 /* Handle `(space-width WIDTH)'. */
4699 && EQ (XCAR (spec
), Qspace_width
)
4700 && CONSP (XCDR (spec
)))
4704 if (!FRAME_WINDOW_P (it
->f
))
4707 value
= XCAR (XCDR (spec
));
4708 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4709 it
->space_width
= value
;
4715 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4717 && EQ (XCAR (spec
), Qslice
))
4723 if (!FRAME_WINDOW_P (it
->f
))
4726 if (tem
= XCDR (spec
), CONSP (tem
))
4728 it
->slice
.x
= XCAR (tem
);
4729 if (tem
= XCDR (tem
), CONSP (tem
))
4731 it
->slice
.y
= XCAR (tem
);
4732 if (tem
= XCDR (tem
), CONSP (tem
))
4734 it
->slice
.width
= XCAR (tem
);
4735 if (tem
= XCDR (tem
), CONSP (tem
))
4736 it
->slice
.height
= XCAR (tem
);
4745 /* Handle `(raise FACTOR)'. */
4747 && EQ (XCAR (spec
), Qraise
)
4748 && CONSP (XCDR (spec
)))
4752 if (!FRAME_WINDOW_P (it
->f
))
4755 #ifdef HAVE_WINDOW_SYSTEM
4756 value
= XCAR (XCDR (spec
));
4757 if (NUMBERP (value
))
4759 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4760 it
->voffset
= - (XFLOATINT (value
)
4761 * (FONT_HEIGHT (face
->font
)));
4763 #endif /* HAVE_WINDOW_SYSTEM */
4769 /* Don't handle the other kinds of display specifications
4770 inside a string that we got from a `display' property. */
4771 if (it
&& it
->string_from_display_prop_p
)
4774 /* Characters having this form of property are not displayed, so
4775 we have to find the end of the property. */
4778 start_pos
= *position
;
4779 *position
= display_prop_end (it
, object
, start_pos
);
4783 /* Stop the scan at that end position--we assume that all
4784 text properties change there. */
4786 it
->stop_charpos
= position
->charpos
;
4788 /* Handle `(left-fringe BITMAP [FACE])'
4789 and `(right-fringe BITMAP [FACE])'. */
4791 && (EQ (XCAR (spec
), Qleft_fringe
)
4792 || EQ (XCAR (spec
), Qright_fringe
))
4793 && CONSP (XCDR (spec
)))
4799 if (!FRAME_WINDOW_P (it
->f
))
4800 /* If we return here, POSITION has been advanced
4801 across the text with this property. */
4803 /* Synchronize the bidi iterator with POSITION. This is
4804 needed because we are not going to push the iterator
4805 on behalf of this display property, so there will be
4806 no pop_it call to do this synchronization for us. */
4809 it
->position
= *position
;
4810 iterate_out_of_display_property (it
);
4811 *position
= it
->position
;
4816 else if (!frame_window_p
)
4819 #ifdef HAVE_WINDOW_SYSTEM
4820 value
= XCAR (XCDR (spec
));
4821 if (!SYMBOLP (value
)
4822 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4823 /* If we return here, POSITION has been advanced
4824 across the text with this property. */
4826 if (it
&& it
->bidi_p
)
4828 it
->position
= *position
;
4829 iterate_out_of_display_property (it
);
4830 *position
= it
->position
;
4837 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);;
4839 if (CONSP (XCDR (XCDR (spec
))))
4841 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4842 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4848 /* Save current settings of IT so that we can restore them
4849 when we are finished with the glyph property value. */
4850 push_it (it
, position
);
4852 it
->area
= TEXT_AREA
;
4853 it
->what
= IT_IMAGE
;
4854 it
->image_id
= -1; /* no image */
4855 it
->position
= start_pos
;
4856 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4857 it
->method
= GET_FROM_IMAGE
;
4858 it
->from_overlay
= Qnil
;
4859 it
->face_id
= face_id
;
4860 it
->from_disp_prop_p
= 1;
4862 /* Say that we haven't consumed the characters with
4863 `display' property yet. The call to pop_it in
4864 set_iterator_to_next will clean this up. */
4865 *position
= start_pos
;
4867 if (EQ (XCAR (spec
), Qleft_fringe
))
4869 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4870 it
->left_user_fringe_face_id
= face_id
;
4874 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4875 it
->right_user_fringe_face_id
= face_id
;
4878 #endif /* HAVE_WINDOW_SYSTEM */
4882 /* Prepare to handle `((margin left-margin) ...)',
4883 `((margin right-margin) ...)' and `((margin nil) ...)'
4884 prefixes for display specifications. */
4885 location
= Qunbound
;
4886 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4890 value
= XCDR (spec
);
4892 value
= XCAR (value
);
4895 if (EQ (XCAR (tem
), Qmargin
)
4896 && (tem
= XCDR (tem
),
4897 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4899 || EQ (tem
, Qleft_margin
)
4900 || EQ (tem
, Qright_margin
))))
4904 if (EQ (location
, Qunbound
))
4910 /* After this point, VALUE is the property after any
4911 margin prefix has been stripped. It must be a string,
4912 an image specification, or `(space ...)'.
4914 LOCATION specifies where to display: `left-margin',
4915 `right-margin' or nil. */
4917 valid_p
= (STRINGP (value
)
4918 #ifdef HAVE_WINDOW_SYSTEM
4919 || ((it
? FRAME_WINDOW_P (it
->f
) : frame_window_p
)
4920 && valid_image_p (value
))
4921 #endif /* not HAVE_WINDOW_SYSTEM */
4922 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4924 if (valid_p
&& !display_replaced_p
)
4930 /* Callers need to know whether the display spec is any kind
4931 of `(space ...)' spec that is about to affect text-area
4933 if (CONSP (value
) && EQ (XCAR (value
), Qspace
) && NILP (location
))
4938 /* Save current settings of IT so that we can restore them
4939 when we are finished with the glyph property value. */
4940 push_it (it
, position
);
4941 it
->from_overlay
= overlay
;
4942 it
->from_disp_prop_p
= 1;
4944 if (NILP (location
))
4945 it
->area
= TEXT_AREA
;
4946 else if (EQ (location
, Qleft_margin
))
4947 it
->area
= LEFT_MARGIN_AREA
;
4949 it
->area
= RIGHT_MARGIN_AREA
;
4951 if (STRINGP (value
))
4954 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4955 it
->current
.overlay_string_index
= -1;
4956 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4957 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4958 it
->method
= GET_FROM_STRING
;
4959 it
->stop_charpos
= 0;
4961 it
->base_level_stop
= 0;
4962 it
->string_from_display_prop_p
= 1;
4963 /* Say that we haven't consumed the characters with
4964 `display' property yet. The call to pop_it in
4965 set_iterator_to_next will clean this up. */
4966 if (BUFFERP (object
))
4967 *position
= start_pos
;
4969 /* Force paragraph direction to be that of the parent
4970 object. If the parent object's paragraph direction is
4971 not yet determined, default to L2R. */
4972 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
4973 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
4975 it
->paragraph_embedding
= L2R
;
4977 /* Set up the bidi iterator for this display string. */
4980 it
->bidi_it
.string
.lstring
= it
->string
;
4981 it
->bidi_it
.string
.s
= NULL
;
4982 it
->bidi_it
.string
.schars
= it
->end_charpos
;
4983 it
->bidi_it
.string
.bufpos
= bufpos
;
4984 it
->bidi_it
.string
.from_disp_str
= 1;
4985 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
4986 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
4989 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
4991 it
->method
= GET_FROM_STRETCH
;
4993 *position
= it
->position
= start_pos
;
4994 retval
= 1 + (it
->area
== TEXT_AREA
);
4996 #ifdef HAVE_WINDOW_SYSTEM
4999 it
->what
= IT_IMAGE
;
5000 it
->image_id
= lookup_image (it
->f
, value
);
5001 it
->position
= start_pos
;
5002 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
5003 it
->method
= GET_FROM_IMAGE
;
5005 /* Say that we haven't consumed the characters with
5006 `display' property yet. The call to pop_it in
5007 set_iterator_to_next will clean this up. */
5008 *position
= start_pos
;
5010 #endif /* HAVE_WINDOW_SYSTEM */
5015 /* Invalid property or property not supported. Restore
5016 POSITION to what it was before. */
5017 *position
= start_pos
;
5021 /* Check if PROP is a display property value whose text should be
5022 treated as intangible. OVERLAY is the overlay from which PROP
5023 came, or nil if it came from a text property. CHARPOS and BYTEPOS
5024 specify the buffer position covered by PROP. */
5027 display_prop_intangible_p (Lisp_Object prop
, Lisp_Object overlay
,
5028 ptrdiff_t charpos
, ptrdiff_t bytepos
)
5030 int frame_window_p
= FRAME_WINDOW_P (XFRAME (selected_frame
));
5031 struct text_pos position
;
5033 SET_TEXT_POS (position
, charpos
, bytepos
);
5034 return handle_display_spec (NULL
, prop
, Qnil
, overlay
,
5035 &position
, charpos
, frame_window_p
);
5039 /* Return 1 if PROP is a display sub-property value containing STRING.
5041 Implementation note: this and the following function are really
5042 special cases of handle_display_spec and
5043 handle_single_display_spec, and should ideally use the same code.
5044 Until they do, these two pairs must be consistent and must be
5045 modified in sync. */
5048 single_display_spec_string_p (Lisp_Object prop
, Lisp_Object string
)
5050 if (EQ (string
, prop
))
5053 /* Skip over `when FORM'. */
5054 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
5059 /* Actually, the condition following `when' should be eval'ed,
5060 like handle_single_display_spec does, and we should return
5061 zero if it evaluates to nil. However, this function is
5062 called only when the buffer was already displayed and some
5063 glyph in the glyph matrix was found to come from a display
5064 string. Therefore, the condition was already evaluated, and
5065 the result was non-nil, otherwise the display string wouldn't
5066 have been displayed and we would have never been called for
5067 this property. Thus, we can skip the evaluation and assume
5068 its result is non-nil. */
5073 /* Skip over `margin LOCATION'. */
5074 if (EQ (XCAR (prop
), Qmargin
))
5085 return EQ (prop
, string
) || (CONSP (prop
) && EQ (XCAR (prop
), string
));
5089 /* Return 1 if STRING appears in the `display' property PROP. */
5092 display_prop_string_p (Lisp_Object prop
, Lisp_Object string
)
5095 && !EQ (XCAR (prop
), Qwhen
)
5096 && !(CONSP (XCAR (prop
)) && EQ (Qmargin
, XCAR (XCAR (prop
)))))
5098 /* A list of sub-properties. */
5099 while (CONSP (prop
))
5101 if (single_display_spec_string_p (XCAR (prop
), string
))
5106 else if (VECTORP (prop
))
5108 /* A vector of sub-properties. */
5110 for (i
= 0; i
< ASIZE (prop
); ++i
)
5111 if (single_display_spec_string_p (AREF (prop
, i
), string
))
5115 return single_display_spec_string_p (prop
, string
);
5120 /* Look for STRING in overlays and text properties in the current
5121 buffer, between character positions FROM and TO (excluding TO).
5122 BACK_P non-zero means look back (in this case, TO is supposed to be
5124 Value is the first character position where STRING was found, or
5125 zero if it wasn't found before hitting TO.
5127 This function may only use code that doesn't eval because it is
5128 called asynchronously from note_mouse_highlight. */
5131 string_buffer_position_lim (Lisp_Object string
,
5132 ptrdiff_t from
, ptrdiff_t to
, int back_p
)
5134 Lisp_Object limit
, prop
, pos
;
5137 pos
= make_number (max (from
, BEGV
));
5139 if (!back_p
) /* looking forward */
5141 limit
= make_number (min (to
, ZV
));
5142 while (!found
&& !EQ (pos
, limit
))
5144 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5145 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5148 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
,
5152 else /* looking back */
5154 limit
= make_number (max (to
, BEGV
));
5155 while (!found
&& !EQ (pos
, limit
))
5157 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5158 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5161 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
5166 return found
? XINT (pos
) : 0;
5169 /* Determine which buffer position in current buffer STRING comes from.
5170 AROUND_CHARPOS is an approximate position where it could come from.
5171 Value is the buffer position or 0 if it couldn't be determined.
5173 This function is necessary because we don't record buffer positions
5174 in glyphs generated from strings (to keep struct glyph small).
5175 This function may only use code that doesn't eval because it is
5176 called asynchronously from note_mouse_highlight. */
5179 string_buffer_position (Lisp_Object string
, ptrdiff_t around_charpos
)
5181 const int MAX_DISTANCE
= 1000;
5182 ptrdiff_t found
= string_buffer_position_lim (string
, around_charpos
,
5183 around_charpos
+ MAX_DISTANCE
,
5187 found
= string_buffer_position_lim (string
, around_charpos
,
5188 around_charpos
- MAX_DISTANCE
, 1);
5194 /***********************************************************************
5195 `composition' property
5196 ***********************************************************************/
5198 /* Set up iterator IT from `composition' property at its current
5199 position. Called from handle_stop. */
5201 static enum prop_handled
5202 handle_composition_prop (struct it
*it
)
5204 Lisp_Object prop
, string
;
5205 ptrdiff_t pos
, pos_byte
, start
, end
;
5207 if (STRINGP (it
->string
))
5211 pos
= IT_STRING_CHARPOS (*it
);
5212 pos_byte
= IT_STRING_BYTEPOS (*it
);
5213 string
= it
->string
;
5214 s
= SDATA (string
) + pos_byte
;
5215 it
->c
= STRING_CHAR (s
);
5219 pos
= IT_CHARPOS (*it
);
5220 pos_byte
= IT_BYTEPOS (*it
);
5222 it
->c
= FETCH_CHAR (pos_byte
);
5225 /* If there's a valid composition and point is not inside of the
5226 composition (in the case that the composition is from the current
5227 buffer), draw a glyph composed from the composition components. */
5228 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
5229 && COMPOSITION_VALID_P (start
, end
, prop
)
5230 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
5233 /* As we can't handle this situation (perhaps font-lock added
5234 a new composition), we just return here hoping that next
5235 redisplay will detect this composition much earlier. */
5236 return HANDLED_NORMALLY
;
5239 if (STRINGP (it
->string
))
5240 pos_byte
= string_char_to_byte (it
->string
, start
);
5242 pos_byte
= CHAR_TO_BYTE (start
);
5244 it
->cmp_it
.id
= get_composition_id (start
, pos_byte
, end
- start
,
5247 if (it
->cmp_it
.id
>= 0)
5250 it
->cmp_it
.nchars
= COMPOSITION_LENGTH (prop
);
5251 it
->cmp_it
.nglyphs
= -1;
5255 return HANDLED_NORMALLY
;
5260 /***********************************************************************
5262 ***********************************************************************/
5264 /* The following structure is used to record overlay strings for
5265 later sorting in load_overlay_strings. */
5267 struct overlay_entry
5269 Lisp_Object overlay
;
5276 /* Set up iterator IT from overlay strings at its current position.
5277 Called from handle_stop. */
5279 static enum prop_handled
5280 handle_overlay_change (struct it
*it
)
5282 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
5283 return HANDLED_RECOMPUTE_PROPS
;
5285 return HANDLED_NORMALLY
;
5289 /* Set up the next overlay string for delivery by IT, if there is an
5290 overlay string to deliver. Called by set_iterator_to_next when the
5291 end of the current overlay string is reached. If there are more
5292 overlay strings to display, IT->string and
5293 IT->current.overlay_string_index are set appropriately here.
5294 Otherwise IT->string is set to nil. */
5297 next_overlay_string (struct it
*it
)
5299 ++it
->current
.overlay_string_index
;
5300 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
5302 /* No more overlay strings. Restore IT's settings to what
5303 they were before overlay strings were processed, and
5304 continue to deliver from current_buffer. */
5306 it
->ellipsis_p
= (it
->stack
[it
->sp
- 1].display_ellipsis_p
!= 0);
5309 || (NILP (it
->string
)
5310 && it
->method
== GET_FROM_BUFFER
5311 && it
->stop_charpos
>= BEGV
5312 && it
->stop_charpos
<= it
->end_charpos
));
5313 it
->current
.overlay_string_index
= -1;
5314 it
->n_overlay_strings
= 0;
5315 it
->overlay_strings_charpos
= -1;
5316 /* If there's an empty display string on the stack, pop the
5317 stack, to resync the bidi iterator with IT's position. Such
5318 empty strings are pushed onto the stack in
5319 get_overlay_strings_1. */
5320 if (it
->sp
> 0 && STRINGP (it
->string
) && !SCHARS (it
->string
))
5323 /* If we're at the end of the buffer, record that we have
5324 processed the overlay strings there already, so that
5325 next_element_from_buffer doesn't try it again. */
5326 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
5327 it
->overlay_strings_at_end_processed_p
= 1;
5331 /* There are more overlay strings to process. If
5332 IT->current.overlay_string_index has advanced to a position
5333 where we must load IT->overlay_strings with more strings, do
5334 it. We must load at the IT->overlay_strings_charpos where
5335 IT->n_overlay_strings was originally computed; when invisible
5336 text is present, this might not be IT_CHARPOS (Bug#7016). */
5337 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
5339 if (it
->current
.overlay_string_index
&& i
== 0)
5340 load_overlay_strings (it
, it
->overlay_strings_charpos
);
5342 /* Initialize IT to deliver display elements from the overlay
5344 it
->string
= it
->overlay_strings
[i
];
5345 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5346 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
5347 it
->method
= GET_FROM_STRING
;
5348 it
->stop_charpos
= 0;
5349 if (it
->cmp_it
.stop_pos
>= 0)
5350 it
->cmp_it
.stop_pos
= 0;
5352 it
->base_level_stop
= 0;
5354 /* Set up the bidi iterator for this overlay string. */
5357 it
->bidi_it
.string
.lstring
= it
->string
;
5358 it
->bidi_it
.string
.s
= NULL
;
5359 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5360 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
5361 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5362 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5363 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5371 /* Compare two overlay_entry structures E1 and E2. Used as a
5372 comparison function for qsort in load_overlay_strings. Overlay
5373 strings for the same position are sorted so that
5375 1. All after-strings come in front of before-strings, except
5376 when they come from the same overlay.
5378 2. Within after-strings, strings are sorted so that overlay strings
5379 from overlays with higher priorities come first.
5381 2. Within before-strings, strings are sorted so that overlay
5382 strings from overlays with higher priorities come last.
5384 Value is analogous to strcmp. */
5388 compare_overlay_entries (const void *e1
, const void *e2
)
5390 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
5391 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
5394 if (entry1
->after_string_p
!= entry2
->after_string_p
)
5396 /* Let after-strings appear in front of before-strings if
5397 they come from different overlays. */
5398 if (EQ (entry1
->overlay
, entry2
->overlay
))
5399 result
= entry1
->after_string_p
? 1 : -1;
5401 result
= entry1
->after_string_p
? -1 : 1;
5403 else if (entry1
->priority
!= entry2
->priority
)
5405 if (entry1
->after_string_p
)
5406 /* After-strings sorted in order of decreasing priority. */
5407 result
= entry2
->priority
< entry1
->priority
? -1 : 1;
5409 /* Before-strings sorted in order of increasing priority. */
5410 result
= entry1
->priority
< entry2
->priority
? -1 : 1;
5419 /* Load the vector IT->overlay_strings with overlay strings from IT's
5420 current buffer position, or from CHARPOS if that is > 0. Set
5421 IT->n_overlays to the total number of overlay strings found.
5423 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
5424 a time. On entry into load_overlay_strings,
5425 IT->current.overlay_string_index gives the number of overlay
5426 strings that have already been loaded by previous calls to this
5429 IT->add_overlay_start contains an additional overlay start
5430 position to consider for taking overlay strings from, if non-zero.
5431 This position comes into play when the overlay has an `invisible'
5432 property, and both before and after-strings. When we've skipped to
5433 the end of the overlay, because of its `invisible' property, we
5434 nevertheless want its before-string to appear.
5435 IT->add_overlay_start will contain the overlay start position
5438 Overlay strings are sorted so that after-string strings come in
5439 front of before-string strings. Within before and after-strings,
5440 strings are sorted by overlay priority. See also function
5441 compare_overlay_entries. */
5444 load_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5446 Lisp_Object overlay
, window
, str
, invisible
;
5447 struct Lisp_Overlay
*ov
;
5448 ptrdiff_t start
, end
;
5449 ptrdiff_t size
= 20;
5450 ptrdiff_t n
= 0, i
, j
;
5452 struct overlay_entry
*entries
= alloca (size
* sizeof *entries
);
5456 charpos
= IT_CHARPOS (*it
);
5458 /* Append the overlay string STRING of overlay OVERLAY to vector
5459 `entries' which has size `size' and currently contains `n'
5460 elements. AFTER_P non-zero means STRING is an after-string of
5462 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
5465 Lisp_Object priority; \
5469 struct overlay_entry *old = entries; \
5470 SAFE_NALLOCA (entries, 2, size); \
5471 memcpy (entries, old, size * sizeof *entries); \
5475 entries[n].string = (STRING); \
5476 entries[n].overlay = (OVERLAY); \
5477 priority = Foverlay_get ((OVERLAY), Qpriority); \
5478 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
5479 entries[n].after_string_p = (AFTER_P); \
5484 /* Process overlay before the overlay center. */
5485 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
5487 XSETMISC (overlay
, ov
);
5488 eassert (OVERLAYP (overlay
));
5489 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5490 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5495 /* Skip this overlay if it doesn't start or end at IT's current
5497 if (end
!= charpos
&& start
!= charpos
)
5500 /* Skip this overlay if it doesn't apply to IT->w. */
5501 window
= Foverlay_get (overlay
, Qwindow
);
5502 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5505 /* If the text ``under'' the overlay is invisible, both before-
5506 and after-strings from this overlay are visible; start and
5507 end position are indistinguishable. */
5508 invisible
= Foverlay_get (overlay
, Qinvisible
);
5509 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5511 /* If overlay has a non-empty before-string, record it. */
5512 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5513 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5515 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5517 /* If overlay has a non-empty after-string, record it. */
5518 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5519 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5521 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5524 /* Process overlays after the overlay center. */
5525 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
5527 XSETMISC (overlay
, ov
);
5528 eassert (OVERLAYP (overlay
));
5529 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5530 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5532 if (start
> charpos
)
5535 /* Skip this overlay if it doesn't start or end at IT's current
5537 if (end
!= charpos
&& start
!= charpos
)
5540 /* Skip this overlay if it doesn't apply to IT->w. */
5541 window
= Foverlay_get (overlay
, Qwindow
);
5542 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5545 /* If the text ``under'' the overlay is invisible, it has a zero
5546 dimension, and both before- and after-strings apply. */
5547 invisible
= Foverlay_get (overlay
, Qinvisible
);
5548 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5550 /* If overlay has a non-empty before-string, record it. */
5551 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5552 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5554 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5556 /* If overlay has a non-empty after-string, record it. */
5557 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5558 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5560 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5563 #undef RECORD_OVERLAY_STRING
5567 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
5569 /* Record number of overlay strings, and where we computed it. */
5570 it
->n_overlay_strings
= n
;
5571 it
->overlay_strings_charpos
= charpos
;
5573 /* IT->current.overlay_string_index is the number of overlay strings
5574 that have already been consumed by IT. Copy some of the
5575 remaining overlay strings to IT->overlay_strings. */
5577 j
= it
->current
.overlay_string_index
;
5578 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
5580 it
->overlay_strings
[i
] = entries
[j
].string
;
5581 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
5589 /* Get the first chunk of overlay strings at IT's current buffer
5590 position, or at CHARPOS if that is > 0. Value is non-zero if at
5591 least one overlay string was found. */
5594 get_overlay_strings_1 (struct it
*it
, ptrdiff_t charpos
, int compute_stop_p
)
5596 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5597 process. This fills IT->overlay_strings with strings, and sets
5598 IT->n_overlay_strings to the total number of strings to process.
5599 IT->pos.overlay_string_index has to be set temporarily to zero
5600 because load_overlay_strings needs this; it must be set to -1
5601 when no overlay strings are found because a zero value would
5602 indicate a position in the first overlay string. */
5603 it
->current
.overlay_string_index
= 0;
5604 load_overlay_strings (it
, charpos
);
5606 /* If we found overlay strings, set up IT to deliver display
5607 elements from the first one. Otherwise set up IT to deliver
5608 from current_buffer. */
5609 if (it
->n_overlay_strings
)
5611 /* Make sure we know settings in current_buffer, so that we can
5612 restore meaningful values when we're done with the overlay
5615 compute_stop_pos (it
);
5616 eassert (it
->face_id
>= 0);
5618 /* Save IT's settings. They are restored after all overlay
5619 strings have been processed. */
5620 eassert (!compute_stop_p
|| it
->sp
== 0);
5622 /* When called from handle_stop, there might be an empty display
5623 string loaded. In that case, don't bother saving it. But
5624 don't use this optimization with the bidi iterator, since we
5625 need the corresponding pop_it call to resync the bidi
5626 iterator's position with IT's position, after we are done
5627 with the overlay strings. (The corresponding call to pop_it
5628 in case of an empty display string is in
5629 next_overlay_string.) */
5631 && STRINGP (it
->string
) && !SCHARS (it
->string
)))
5634 /* Set up IT to deliver display elements from the first overlay
5636 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5637 it
->string
= it
->overlay_strings
[0];
5638 it
->from_overlay
= Qnil
;
5639 it
->stop_charpos
= 0;
5640 eassert (STRINGP (it
->string
));
5641 it
->end_charpos
= SCHARS (it
->string
);
5643 it
->base_level_stop
= 0;
5644 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5645 it
->method
= GET_FROM_STRING
;
5646 it
->from_disp_prop_p
= 0;
5648 /* Force paragraph direction to be that of the parent
5650 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
5651 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5653 it
->paragraph_embedding
= L2R
;
5655 /* Set up the bidi iterator for this overlay string. */
5658 ptrdiff_t pos
= (charpos
> 0 ? charpos
: IT_CHARPOS (*it
));
5660 it
->bidi_it
.string
.lstring
= it
->string
;
5661 it
->bidi_it
.string
.s
= NULL
;
5662 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5663 it
->bidi_it
.string
.bufpos
= pos
;
5664 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5665 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5666 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5671 it
->current
.overlay_string_index
= -1;
5676 get_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5679 it
->method
= GET_FROM_BUFFER
;
5681 (void) get_overlay_strings_1 (it
, charpos
, 1);
5685 /* Value is non-zero if we found at least one overlay string. */
5686 return STRINGP (it
->string
);
5691 /***********************************************************************
5692 Saving and restoring state
5693 ***********************************************************************/
5695 /* Save current settings of IT on IT->stack. Called, for example,
5696 before setting up IT for an overlay string, to be able to restore
5697 IT's settings to what they were after the overlay string has been
5698 processed. If POSITION is non-NULL, it is the position to save on
5699 the stack instead of IT->position. */
5702 push_it (struct it
*it
, struct text_pos
*position
)
5704 struct iterator_stack_entry
*p
;
5706 eassert (it
->sp
< IT_STACK_SIZE
);
5707 p
= it
->stack
+ it
->sp
;
5709 p
->stop_charpos
= it
->stop_charpos
;
5710 p
->prev_stop
= it
->prev_stop
;
5711 p
->base_level_stop
= it
->base_level_stop
;
5712 p
->cmp_it
= it
->cmp_it
;
5713 eassert (it
->face_id
>= 0);
5714 p
->face_id
= it
->face_id
;
5715 p
->string
= it
->string
;
5716 p
->method
= it
->method
;
5717 p
->from_overlay
= it
->from_overlay
;
5720 case GET_FROM_IMAGE
:
5721 p
->u
.image
.object
= it
->object
;
5722 p
->u
.image
.image_id
= it
->image_id
;
5723 p
->u
.image
.slice
= it
->slice
;
5725 case GET_FROM_STRETCH
:
5726 p
->u
.stretch
.object
= it
->object
;
5729 p
->position
= position
? *position
: it
->position
;
5730 p
->current
= it
->current
;
5731 p
->end_charpos
= it
->end_charpos
;
5732 p
->string_nchars
= it
->string_nchars
;
5734 p
->multibyte_p
= it
->multibyte_p
;
5735 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
5736 p
->space_width
= it
->space_width
;
5737 p
->font_height
= it
->font_height
;
5738 p
->voffset
= it
->voffset
;
5739 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5740 p
->string_from_prefix_prop_p
= it
->string_from_prefix_prop_p
;
5741 p
->display_ellipsis_p
= 0;
5742 p
->line_wrap
= it
->line_wrap
;
5743 p
->bidi_p
= it
->bidi_p
;
5744 p
->paragraph_embedding
= it
->paragraph_embedding
;
5745 p
->from_disp_prop_p
= it
->from_disp_prop_p
;
5748 /* Save the state of the bidi iterator as well. */
5750 bidi_push_it (&it
->bidi_it
);
5754 iterate_out_of_display_property (struct it
*it
)
5756 int buffer_p
= !STRINGP (it
->string
);
5757 ptrdiff_t eob
= (buffer_p
? ZV
: it
->end_charpos
);
5758 ptrdiff_t bob
= (buffer_p
? BEGV
: 0);
5760 eassert (eob
>= CHARPOS (it
->position
) && CHARPOS (it
->position
) >= bob
);
5762 /* Maybe initialize paragraph direction. If we are at the beginning
5763 of a new paragraph, next_element_from_buffer may not have a
5764 chance to do that. */
5765 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< eob
)
5766 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
5767 /* prev_stop can be zero, so check against BEGV as well. */
5768 while (it
->bidi_it
.charpos
>= bob
5769 && it
->prev_stop
<= it
->bidi_it
.charpos
5770 && it
->bidi_it
.charpos
< CHARPOS (it
->position
)
5771 && it
->bidi_it
.charpos
< eob
)
5772 bidi_move_to_visually_next (&it
->bidi_it
);
5773 /* Record the stop_pos we just crossed, for when we cross it
5775 if (it
->bidi_it
.charpos
> CHARPOS (it
->position
))
5776 it
->prev_stop
= CHARPOS (it
->position
);
5777 /* If we ended up not where pop_it put us, resync IT's
5778 positional members with the bidi iterator. */
5779 if (it
->bidi_it
.charpos
!= CHARPOS (it
->position
))
5780 SET_TEXT_POS (it
->position
, it
->bidi_it
.charpos
, it
->bidi_it
.bytepos
);
5782 it
->current
.pos
= it
->position
;
5784 it
->current
.string_pos
= it
->position
;
5787 /* Restore IT's settings from IT->stack. Called, for example, when no
5788 more overlay strings must be processed, and we return to delivering
5789 display elements from a buffer, or when the end of a string from a
5790 `display' property is reached and we return to delivering display
5791 elements from an overlay string, or from a buffer. */
5794 pop_it (struct it
*it
)
5796 struct iterator_stack_entry
*p
;
5797 int from_display_prop
= it
->from_disp_prop_p
;
5799 eassert (it
->sp
> 0);
5801 p
= it
->stack
+ it
->sp
;
5802 it
->stop_charpos
= p
->stop_charpos
;
5803 it
->prev_stop
= p
->prev_stop
;
5804 it
->base_level_stop
= p
->base_level_stop
;
5805 it
->cmp_it
= p
->cmp_it
;
5806 it
->face_id
= p
->face_id
;
5807 it
->current
= p
->current
;
5808 it
->position
= p
->position
;
5809 it
->string
= p
->string
;
5810 it
->from_overlay
= p
->from_overlay
;
5811 if (NILP (it
->string
))
5812 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5813 it
->method
= p
->method
;
5816 case GET_FROM_IMAGE
:
5817 it
->image_id
= p
->u
.image
.image_id
;
5818 it
->object
= p
->u
.image
.object
;
5819 it
->slice
= p
->u
.image
.slice
;
5821 case GET_FROM_STRETCH
:
5822 it
->object
= p
->u
.stretch
.object
;
5824 case GET_FROM_BUFFER
:
5825 it
->object
= it
->w
->buffer
;
5827 case GET_FROM_STRING
:
5828 it
->object
= it
->string
;
5830 case GET_FROM_DISPLAY_VECTOR
:
5832 it
->method
= GET_FROM_C_STRING
;
5833 else if (STRINGP (it
->string
))
5834 it
->method
= GET_FROM_STRING
;
5837 it
->method
= GET_FROM_BUFFER
;
5838 it
->object
= it
->w
->buffer
;
5841 it
->end_charpos
= p
->end_charpos
;
5842 it
->string_nchars
= p
->string_nchars
;
5844 it
->multibyte_p
= p
->multibyte_p
;
5845 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
5846 it
->space_width
= p
->space_width
;
5847 it
->font_height
= p
->font_height
;
5848 it
->voffset
= p
->voffset
;
5849 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5850 it
->string_from_prefix_prop_p
= p
->string_from_prefix_prop_p
;
5851 it
->line_wrap
= p
->line_wrap
;
5852 it
->bidi_p
= p
->bidi_p
;
5853 it
->paragraph_embedding
= p
->paragraph_embedding
;
5854 it
->from_disp_prop_p
= p
->from_disp_prop_p
;
5857 bidi_pop_it (&it
->bidi_it
);
5858 /* Bidi-iterate until we get out of the portion of text, if any,
5859 covered by a `display' text property or by an overlay with
5860 `display' property. (We cannot just jump there, because the
5861 internal coherency of the bidi iterator state can not be
5862 preserved across such jumps.) We also must determine the
5863 paragraph base direction if the overlay we just processed is
5864 at the beginning of a new paragraph. */
5865 if (from_display_prop
5866 && (it
->method
== GET_FROM_BUFFER
|| it
->method
== GET_FROM_STRING
))
5867 iterate_out_of_display_property (it
);
5869 eassert ((BUFFERP (it
->object
)
5870 && IT_CHARPOS (*it
) == it
->bidi_it
.charpos
5871 && IT_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
5872 || (STRINGP (it
->object
)
5873 && IT_STRING_CHARPOS (*it
) == it
->bidi_it
.charpos
5874 && IT_STRING_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
5875 || (CONSP (it
->object
) && it
->method
== GET_FROM_STRETCH
));
5881 /***********************************************************************
5883 ***********************************************************************/
5885 /* Set IT's current position to the previous line start. */
5888 back_to_previous_line_start (struct it
*it
)
5890 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
5891 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
5895 /* Move IT to the next line start.
5897 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5898 we skipped over part of the text (as opposed to moving the iterator
5899 continuously over the text). Otherwise, don't change the value
5902 If BIDI_IT_PREV is non-NULL, store into it the state of the bidi
5903 iterator on the newline, if it was found.
5905 Newlines may come from buffer text, overlay strings, or strings
5906 displayed via the `display' property. That's the reason we can't
5907 simply use find_next_newline_no_quit.
5909 Note that this function may not skip over invisible text that is so
5910 because of text properties and immediately follows a newline. If
5911 it would, function reseat_at_next_visible_line_start, when called
5912 from set_iterator_to_next, would effectively make invisible
5913 characters following a newline part of the wrong glyph row, which
5914 leads to wrong cursor motion. */
5917 forward_to_next_line_start (struct it
*it
, int *skipped_p
,
5918 struct bidi_it
*bidi_it_prev
)
5920 ptrdiff_t old_selective
;
5921 int newline_found_p
, n
;
5922 const int MAX_NEWLINE_DISTANCE
= 500;
5924 /* If already on a newline, just consume it to avoid unintended
5925 skipping over invisible text below. */
5926 if (it
->what
== IT_CHARACTER
5928 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
5930 if (it
->bidi_p
&& bidi_it_prev
)
5931 *bidi_it_prev
= it
->bidi_it
;
5932 set_iterator_to_next (it
, 0);
5937 /* Don't handle selective display in the following. It's (a)
5938 unnecessary because it's done by the caller, and (b) leads to an
5939 infinite recursion because next_element_from_ellipsis indirectly
5940 calls this function. */
5941 old_selective
= it
->selective
;
5944 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
5945 from buffer text. */
5946 for (n
= newline_found_p
= 0;
5947 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
5948 n
+= STRINGP (it
->string
) ? 0 : 1)
5950 if (!get_next_display_element (it
))
5952 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
5953 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
5954 *bidi_it_prev
= it
->bidi_it
;
5955 set_iterator_to_next (it
, 0);
5958 /* If we didn't find a newline near enough, see if we can use a
5960 if (!newline_found_p
)
5962 ptrdiff_t start
= IT_CHARPOS (*it
);
5963 ptrdiff_t limit
= find_next_newline_no_quit (start
, 1);
5966 eassert (!STRINGP (it
->string
));
5968 /* If there isn't any `display' property in sight, and no
5969 overlays, we can just use the position of the newline in
5971 if (it
->stop_charpos
>= limit
5972 || ((pos
= Fnext_single_property_change (make_number (start
),
5974 make_number (limit
)),
5976 && next_overlay_change (start
) == ZV
))
5980 IT_CHARPOS (*it
) = limit
;
5981 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
5985 struct bidi_it bprev
;
5987 /* Help bidi.c avoid expensive searches for display
5988 properties and overlays, by telling it that there are
5989 none up to `limit'. */
5990 if (it
->bidi_it
.disp_pos
< limit
)
5992 it
->bidi_it
.disp_pos
= limit
;
5993 it
->bidi_it
.disp_prop
= 0;
5996 bprev
= it
->bidi_it
;
5997 bidi_move_to_visually_next (&it
->bidi_it
);
5998 } while (it
->bidi_it
.charpos
!= limit
);
5999 IT_CHARPOS (*it
) = limit
;
6000 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6002 *bidi_it_prev
= bprev
;
6004 *skipped_p
= newline_found_p
= 1;
6008 while (get_next_display_element (it
)
6009 && !newline_found_p
)
6011 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
6012 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
6013 *bidi_it_prev
= it
->bidi_it
;
6014 set_iterator_to_next (it
, 0);
6019 it
->selective
= old_selective
;
6020 return newline_found_p
;
6024 /* Set IT's current position to the previous visible line start. Skip
6025 invisible text that is so either due to text properties or due to
6026 selective display. Caution: this does not change IT->current_x and
6030 back_to_previous_visible_line_start (struct it
*it
)
6032 while (IT_CHARPOS (*it
) > BEGV
)
6034 back_to_previous_line_start (it
);
6036 if (IT_CHARPOS (*it
) <= BEGV
)
6039 /* If selective > 0, then lines indented more than its value are
6041 if (it
->selective
> 0
6042 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6046 /* Check the newline before point for invisibility. */
6049 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
6050 Qinvisible
, it
->window
);
6051 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
6055 if (IT_CHARPOS (*it
) <= BEGV
)
6060 void *it2data
= NULL
;
6063 Lisp_Object val
, overlay
;
6065 SAVE_IT (it2
, *it
, it2data
);
6067 /* If newline is part of a composition, continue from start of composition */
6068 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
6069 && beg
< IT_CHARPOS (*it
))
6072 /* If newline is replaced by a display property, find start of overlay
6073 or interval and continue search from that point. */
6074 pos
= --IT_CHARPOS (it2
);
6077 bidi_unshelve_cache (NULL
, 0);
6078 it2
.string_from_display_prop_p
= 0;
6079 it2
.from_disp_prop_p
= 0;
6080 if (handle_display_prop (&it2
) == HANDLED_RETURN
6081 && !NILP (val
= get_char_property_and_overlay
6082 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
6083 && (OVERLAYP (overlay
)
6084 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
6085 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
6087 RESTORE_IT (it
, it
, it2data
);
6091 /* Newline is not replaced by anything -- so we are done. */
6092 RESTORE_IT (it
, it
, it2data
);
6098 IT_CHARPOS (*it
) = beg
;
6099 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
6103 it
->continuation_lines_width
= 0;
6105 eassert (IT_CHARPOS (*it
) >= BEGV
);
6106 eassert (IT_CHARPOS (*it
) == BEGV
6107 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6112 /* Reseat iterator IT at the previous visible line start. Skip
6113 invisible text that is so either due to text properties or due to
6114 selective display. At the end, update IT's overlay information,
6115 face information etc. */
6118 reseat_at_previous_visible_line_start (struct it
*it
)
6120 back_to_previous_visible_line_start (it
);
6121 reseat (it
, it
->current
.pos
, 1);
6126 /* Reseat iterator IT on the next visible line start in the current
6127 buffer. ON_NEWLINE_P non-zero means position IT on the newline
6128 preceding the line start. Skip over invisible text that is so
6129 because of selective display. Compute faces, overlays etc at the
6130 new position. Note that this function does not skip over text that
6131 is invisible because of text properties. */
6134 reseat_at_next_visible_line_start (struct it
*it
, int on_newline_p
)
6136 int newline_found_p
, skipped_p
= 0;
6137 struct bidi_it bidi_it_prev
;
6139 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6141 /* Skip over lines that are invisible because they are indented
6142 more than the value of IT->selective. */
6143 if (it
->selective
> 0)
6144 while (IT_CHARPOS (*it
) < ZV
6145 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6148 eassert (IT_BYTEPOS (*it
) == BEGV
6149 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6151 forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6154 /* Position on the newline if that's what's requested. */
6155 if (on_newline_p
&& newline_found_p
)
6157 if (STRINGP (it
->string
))
6159 if (IT_STRING_CHARPOS (*it
) > 0)
6163 --IT_STRING_CHARPOS (*it
);
6164 --IT_STRING_BYTEPOS (*it
);
6168 /* We need to restore the bidi iterator to the state
6169 it had on the newline, and resync the IT's
6170 position with that. */
6171 it
->bidi_it
= bidi_it_prev
;
6172 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6173 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6177 else if (IT_CHARPOS (*it
) > BEGV
)
6186 /* We need to restore the bidi iterator to the state it
6187 had on the newline and resync IT with that. */
6188 it
->bidi_it
= bidi_it_prev
;
6189 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6190 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6192 reseat (it
, it
->current
.pos
, 0);
6196 reseat (it
, it
->current
.pos
, 0);
6203 /***********************************************************************
6204 Changing an iterator's position
6205 ***********************************************************************/
6207 /* Change IT's current position to POS in current_buffer. If FORCE_P
6208 is non-zero, always check for text properties at the new position.
6209 Otherwise, text properties are only looked up if POS >=
6210 IT->check_charpos of a property. */
6213 reseat (struct it
*it
, struct text_pos pos
, int force_p
)
6215 ptrdiff_t original_pos
= IT_CHARPOS (*it
);
6217 reseat_1 (it
, pos
, 0);
6219 /* Determine where to check text properties. Avoid doing it
6220 where possible because text property lookup is very expensive. */
6222 || CHARPOS (pos
) > it
->stop_charpos
6223 || CHARPOS (pos
) < original_pos
)
6227 /* For bidi iteration, we need to prime prev_stop and
6228 base_level_stop with our best estimations. */
6229 /* Implementation note: Of course, POS is not necessarily a
6230 stop position, so assigning prev_pos to it is a lie; we
6231 should have called compute_stop_backwards. However, if
6232 the current buffer does not include any R2L characters,
6233 that call would be a waste of cycles, because the
6234 iterator will never move back, and thus never cross this
6235 "fake" stop position. So we delay that backward search
6236 until the time we really need it, in next_element_from_buffer. */
6237 if (CHARPOS (pos
) != it
->prev_stop
)
6238 it
->prev_stop
= CHARPOS (pos
);
6239 if (CHARPOS (pos
) < it
->base_level_stop
)
6240 it
->base_level_stop
= 0; /* meaning it's unknown */
6246 it
->prev_stop
= it
->base_level_stop
= 0;
6255 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
6256 IT->stop_pos to POS, also. */
6259 reseat_1 (struct it
*it
, struct text_pos pos
, int set_stop_p
)
6261 /* Don't call this function when scanning a C string. */
6262 eassert (it
->s
== NULL
);
6264 /* POS must be a reasonable value. */
6265 eassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
6267 it
->current
.pos
= it
->position
= pos
;
6268 it
->end_charpos
= ZV
;
6270 it
->current
.dpvec_index
= -1;
6271 it
->current
.overlay_string_index
= -1;
6272 IT_STRING_CHARPOS (*it
) = -1;
6273 IT_STRING_BYTEPOS (*it
) = -1;
6275 it
->method
= GET_FROM_BUFFER
;
6276 it
->object
= it
->w
->buffer
;
6277 it
->area
= TEXT_AREA
;
6278 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
6280 it
->string_from_display_prop_p
= 0;
6281 it
->string_from_prefix_prop_p
= 0;
6283 it
->from_disp_prop_p
= 0;
6284 it
->face_before_selective_p
= 0;
6287 bidi_init_it (IT_CHARPOS (*it
), IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6289 bidi_unshelve_cache (NULL
, 0);
6290 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6291 it
->bidi_it
.string
.s
= NULL
;
6292 it
->bidi_it
.string
.lstring
= Qnil
;
6293 it
->bidi_it
.string
.bufpos
= 0;
6294 it
->bidi_it
.string
.unibyte
= 0;
6299 it
->stop_charpos
= CHARPOS (pos
);
6300 it
->base_level_stop
= CHARPOS (pos
);
6305 /* Set up IT for displaying a string, starting at CHARPOS in window W.
6306 If S is non-null, it is a C string to iterate over. Otherwise,
6307 STRING gives a Lisp string to iterate over.
6309 If PRECISION > 0, don't return more then PRECISION number of
6310 characters from the string.
6312 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
6313 characters have been returned. FIELD_WIDTH < 0 means an infinite
6316 MULTIBYTE = 0 means disable processing of multibyte characters,
6317 MULTIBYTE > 0 means enable it,
6318 MULTIBYTE < 0 means use IT->multibyte_p.
6320 IT must be initialized via a prior call to init_iterator before
6321 calling this function. */
6324 reseat_to_string (struct it
*it
, const char *s
, Lisp_Object string
,
6325 ptrdiff_t charpos
, ptrdiff_t precision
, int field_width
,
6328 /* No region in strings. */
6329 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
6331 /* No text property checks performed by default, but see below. */
6332 it
->stop_charpos
= -1;
6334 /* Set iterator position and end position. */
6335 memset (&it
->current
, 0, sizeof it
->current
);
6336 it
->current
.overlay_string_index
= -1;
6337 it
->current
.dpvec_index
= -1;
6338 eassert (charpos
>= 0);
6340 /* If STRING is specified, use its multibyteness, otherwise use the
6341 setting of MULTIBYTE, if specified. */
6343 it
->multibyte_p
= multibyte
> 0;
6345 /* Bidirectional reordering of strings is controlled by the default
6346 value of bidi-display-reordering. Don't try to reorder while
6347 loading loadup.el, as the necessary character property tables are
6348 not yet available. */
6351 && !NILP (BVAR (&buffer_defaults
, bidi_display_reordering
));
6355 eassert (STRINGP (string
));
6356 it
->string
= string
;
6358 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
6359 it
->method
= GET_FROM_STRING
;
6360 it
->current
.string_pos
= string_pos (charpos
, string
);
6364 it
->bidi_it
.string
.lstring
= string
;
6365 it
->bidi_it
.string
.s
= NULL
;
6366 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6367 it
->bidi_it
.string
.bufpos
= 0;
6368 it
->bidi_it
.string
.from_disp_str
= 0;
6369 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6370 bidi_init_it (charpos
, IT_STRING_BYTEPOS (*it
),
6371 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
6376 it
->s
= (const unsigned char *) s
;
6379 /* Note that we use IT->current.pos, not it->current.string_pos,
6380 for displaying C strings. */
6381 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
6382 if (it
->multibyte_p
)
6384 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
6385 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
6389 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
6390 it
->end_charpos
= it
->string_nchars
= strlen (s
);
6395 it
->bidi_it
.string
.lstring
= Qnil
;
6396 it
->bidi_it
.string
.s
= (const unsigned char *) s
;
6397 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6398 it
->bidi_it
.string
.bufpos
= 0;
6399 it
->bidi_it
.string
.from_disp_str
= 0;
6400 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6401 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6404 it
->method
= GET_FROM_C_STRING
;
6407 /* PRECISION > 0 means don't return more than PRECISION characters
6409 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
6411 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
6413 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6416 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
6417 characters have been returned. FIELD_WIDTH == 0 means don't pad,
6418 FIELD_WIDTH < 0 means infinite field width. This is useful for
6419 padding with `-' at the end of a mode line. */
6420 if (field_width
< 0)
6421 field_width
= INFINITY
;
6422 /* Implementation note: We deliberately don't enlarge
6423 it->bidi_it.string.schars here to fit it->end_charpos, because
6424 the bidi iterator cannot produce characters out of thin air. */
6425 if (field_width
> it
->end_charpos
- charpos
)
6426 it
->end_charpos
= charpos
+ field_width
;
6428 /* Use the standard display table for displaying strings. */
6429 if (DISP_TABLE_P (Vstandard_display_table
))
6430 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
6432 it
->stop_charpos
= charpos
;
6433 it
->prev_stop
= charpos
;
6434 it
->base_level_stop
= 0;
6437 it
->bidi_it
.first_elt
= 1;
6438 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6439 it
->bidi_it
.disp_pos
= -1;
6441 if (s
== NULL
&& it
->multibyte_p
)
6443 ptrdiff_t endpos
= SCHARS (it
->string
);
6444 if (endpos
> it
->end_charpos
)
6445 endpos
= it
->end_charpos
;
6446 composition_compute_stop_pos (&it
->cmp_it
, charpos
, -1, endpos
,
6454 /***********************************************************************
6456 ***********************************************************************/
6458 /* Map enum it_method value to corresponding next_element_from_* function. */
6460 static int (* get_next_element
[NUM_IT_METHODS
]) (struct it
*it
) =
6462 next_element_from_buffer
,
6463 next_element_from_display_vector
,
6464 next_element_from_string
,
6465 next_element_from_c_string
,
6466 next_element_from_image
,
6467 next_element_from_stretch
6470 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
6473 /* Return 1 iff a character at CHARPOS (and BYTEPOS) is composed
6474 (possibly with the following characters). */
6476 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS,END_CHARPOS) \
6477 ((IT)->cmp_it.id >= 0 \
6478 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
6479 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
6480 END_CHARPOS, (IT)->w, \
6481 FACE_FROM_ID ((IT)->f, (IT)->face_id), \
6485 /* Lookup the char-table Vglyphless_char_display for character C (-1
6486 if we want information for no-font case), and return the display
6487 method symbol. By side-effect, update it->what and
6488 it->glyphless_method. This function is called from
6489 get_next_display_element for each character element, and from
6490 x_produce_glyphs when no suitable font was found. */
6493 lookup_glyphless_char_display (int c
, struct it
*it
)
6495 Lisp_Object glyphless_method
= Qnil
;
6497 if (CHAR_TABLE_P (Vglyphless_char_display
)
6498 && CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
)) >= 1)
6502 glyphless_method
= CHAR_TABLE_REF (Vglyphless_char_display
, c
);
6503 if (CONSP (glyphless_method
))
6504 glyphless_method
= FRAME_WINDOW_P (it
->f
)
6505 ? XCAR (glyphless_method
)
6506 : XCDR (glyphless_method
);
6509 glyphless_method
= XCHAR_TABLE (Vglyphless_char_display
)->extras
[0];
6513 if (NILP (glyphless_method
))
6516 /* The default is to display the character by a proper font. */
6518 /* The default for the no-font case is to display an empty box. */
6519 glyphless_method
= Qempty_box
;
6521 if (EQ (glyphless_method
, Qzero_width
))
6524 return glyphless_method
;
6525 /* This method can't be used for the no-font case. */
6526 glyphless_method
= Qempty_box
;
6528 if (EQ (glyphless_method
, Qthin_space
))
6529 it
->glyphless_method
= GLYPHLESS_DISPLAY_THIN_SPACE
;
6530 else if (EQ (glyphless_method
, Qempty_box
))
6531 it
->glyphless_method
= GLYPHLESS_DISPLAY_EMPTY_BOX
;
6532 else if (EQ (glyphless_method
, Qhex_code
))
6533 it
->glyphless_method
= GLYPHLESS_DISPLAY_HEX_CODE
;
6534 else if (STRINGP (glyphless_method
))
6535 it
->glyphless_method
= GLYPHLESS_DISPLAY_ACRONYM
;
6538 /* Invalid value. We use the default method. */
6539 glyphless_method
= Qnil
;
6542 it
->what
= IT_GLYPHLESS
;
6543 return glyphless_method
;
6546 /* Load IT's display element fields with information about the next
6547 display element from the current position of IT. Value is zero if
6548 end of buffer (or C string) is reached. */
6550 static struct frame
*last_escape_glyph_frame
= NULL
;
6551 static int last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
6552 static int last_escape_glyph_merged_face_id
= 0;
6554 struct frame
*last_glyphless_glyph_frame
= NULL
;
6555 int last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
6556 int last_glyphless_glyph_merged_face_id
= 0;
6559 get_next_display_element (struct it
*it
)
6561 /* Non-zero means that we found a display element. Zero means that
6562 we hit the end of what we iterate over. Performance note: the
6563 function pointer `method' used here turns out to be faster than
6564 using a sequence of if-statements. */
6568 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6570 if (it
->what
== IT_CHARACTER
)
6572 /* UAX#9, L4: "A character is depicted by a mirrored glyph if
6573 and only if (a) the resolved directionality of that character
6575 /* FIXME: Do we need an exception for characters from display
6577 if (it
->bidi_p
&& it
->bidi_it
.type
== STRONG_R
)
6578 it
->c
= bidi_mirror_char (it
->c
);
6579 /* Map via display table or translate control characters.
6580 IT->c, IT->len etc. have been set to the next character by
6581 the function call above. If we have a display table, and it
6582 contains an entry for IT->c, translate it. Don't do this if
6583 IT->c itself comes from a display table, otherwise we could
6584 end up in an infinite recursion. (An alternative could be to
6585 count the recursion depth of this function and signal an
6586 error when a certain maximum depth is reached.) Is it worth
6588 if (success_p
&& it
->dpvec
== NULL
)
6591 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
6592 int nonascii_space_p
= 0;
6593 int nonascii_hyphen_p
= 0;
6594 int c
= it
->c
; /* This is the character to display. */
6596 if (! it
->multibyte_p
&& ! ASCII_CHAR_P (c
))
6598 eassert (SINGLE_BYTE_CHAR_P (c
));
6599 if (unibyte_display_via_language_environment
)
6601 c
= DECODE_CHAR (unibyte
, c
);
6603 c
= BYTE8_TO_CHAR (it
->c
);
6606 c
= BYTE8_TO_CHAR (it
->c
);
6610 && (dv
= DISP_CHAR_VECTOR (it
->dp
, c
),
6613 struct Lisp_Vector
*v
= XVECTOR (dv
);
6615 /* Return the first character from the display table
6616 entry, if not empty. If empty, don't display the
6617 current character. */
6620 it
->dpvec_char_len
= it
->len
;
6621 it
->dpvec
= v
->contents
;
6622 it
->dpend
= v
->contents
+ v
->header
.size
;
6623 it
->current
.dpvec_index
= 0;
6624 it
->dpvec_face_id
= -1;
6625 it
->saved_face_id
= it
->face_id
;
6626 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6631 set_iterator_to_next (it
, 0);
6636 if (! NILP (lookup_glyphless_char_display (c
, it
)))
6638 if (it
->what
== IT_GLYPHLESS
)
6640 /* Don't display this character. */
6641 set_iterator_to_next (it
, 0);
6645 /* If `nobreak-char-display' is non-nil, we display
6646 non-ASCII spaces and hyphens specially. */
6647 if (! ASCII_CHAR_P (c
) && ! NILP (Vnobreak_char_display
))
6650 nonascii_space_p
= 1;
6651 else if (c
== 0xAD || c
== 0x2010 || c
== 0x2011)
6652 nonascii_hyphen_p
= 1;
6655 /* Translate control characters into `\003' or `^C' form.
6656 Control characters coming from a display table entry are
6657 currently not translated because we use IT->dpvec to hold
6658 the translation. This could easily be changed but I
6659 don't believe that it is worth doing.
6661 The characters handled by `nobreak-char-display' must be
6664 Non-printable characters and raw-byte characters are also
6665 translated to octal form. */
6666 if (((c
< ' ' || c
== 127) /* ASCII control chars */
6667 ? (it
->area
!= TEXT_AREA
6668 /* In mode line, treat \n, \t like other crl chars. */
6671 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
6672 || (c
!= '\n' && c
!= '\t'))
6674 || nonascii_hyphen_p
6676 || ! CHAR_PRINTABLE_P (c
))))
6678 /* C is a control character, non-ASCII space/hyphen,
6679 raw-byte, or a non-printable character which must be
6680 displayed either as '\003' or as `^C' where the '\\'
6681 and '^' can be defined in the display table. Fill
6682 IT->ctl_chars with glyphs for what we have to
6683 display. Then, set IT->dpvec to these glyphs. */
6690 /* Handle control characters with ^. */
6692 if (ASCII_CHAR_P (c
) && it
->ctl_arrow_p
)
6696 g
= '^'; /* default glyph for Control */
6697 /* Set IT->ctl_chars[0] to the glyph for `^'. */
6699 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
6701 g
= GLYPH_CODE_CHAR (gc
);
6702 lface_id
= GLYPH_CODE_FACE (gc
);
6706 face_id
= merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
);
6708 else if (it
->f
== last_escape_glyph_frame
6709 && it
->face_id
== last_escape_glyph_face_id
)
6711 face_id
= last_escape_glyph_merged_face_id
;
6715 /* Merge the escape-glyph face into the current face. */
6716 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
6718 last_escape_glyph_frame
= it
->f
;
6719 last_escape_glyph_face_id
= it
->face_id
;
6720 last_escape_glyph_merged_face_id
= face_id
;
6723 XSETINT (it
->ctl_chars
[0], g
);
6724 XSETINT (it
->ctl_chars
[1], c
^ 0100);
6726 goto display_control
;
6729 /* Handle non-ascii space in the mode where it only gets
6732 if (nonascii_space_p
&& EQ (Vnobreak_char_display
, Qt
))
6734 /* Merge `nobreak-space' into the current face. */
6735 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
6737 XSETINT (it
->ctl_chars
[0], ' ');
6739 goto display_control
;
6742 /* Handle sequences that start with the "escape glyph". */
6744 /* the default escape glyph is \. */
6745 escape_glyph
= '\\';
6748 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
6750 escape_glyph
= GLYPH_CODE_CHAR (gc
);
6751 lface_id
= GLYPH_CODE_FACE (gc
);
6755 /* The display table specified a face.
6756 Merge it into face_id and also into escape_glyph. */
6757 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6760 else if (it
->f
== last_escape_glyph_frame
6761 && it
->face_id
== last_escape_glyph_face_id
)
6763 face_id
= last_escape_glyph_merged_face_id
;
6767 /* Merge the escape-glyph face into the current face. */
6768 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
6770 last_escape_glyph_frame
= it
->f
;
6771 last_escape_glyph_face_id
= it
->face_id
;
6772 last_escape_glyph_merged_face_id
= face_id
;
6775 /* Draw non-ASCII hyphen with just highlighting: */
6777 if (nonascii_hyphen_p
&& EQ (Vnobreak_char_display
, Qt
))
6779 XSETINT (it
->ctl_chars
[0], '-');
6781 goto display_control
;
6784 /* Draw non-ASCII space/hyphen with escape glyph: */
6786 if (nonascii_space_p
|| nonascii_hyphen_p
)
6788 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6789 XSETINT (it
->ctl_chars
[1], nonascii_space_p
? ' ' : '-');
6791 goto display_control
;
6798 if (CHAR_BYTE8_P (c
))
6799 /* Display \200 instead of \17777600. */
6800 c
= CHAR_TO_BYTE8 (c
);
6801 len
= sprintf (str
, "%03o", c
);
6803 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6804 for (i
= 0; i
< len
; i
++)
6805 XSETINT (it
->ctl_chars
[i
+ 1], str
[i
]);
6810 /* Set up IT->dpvec and return first character from it. */
6811 it
->dpvec_char_len
= it
->len
;
6812 it
->dpvec
= it
->ctl_chars
;
6813 it
->dpend
= it
->dpvec
+ ctl_len
;
6814 it
->current
.dpvec_index
= 0;
6815 it
->dpvec_face_id
= face_id
;
6816 it
->saved_face_id
= it
->face_id
;
6817 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6821 it
->char_to_display
= c
;
6825 it
->char_to_display
= it
->c
;
6829 /* Adjust face id for a multibyte character. There are no multibyte
6830 character in unibyte text. */
6831 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
6834 && FRAME_WINDOW_P (it
->f
))
6836 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
6838 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
6840 /* Automatic composition with glyph-string. */
6841 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
6843 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
6847 ptrdiff_t pos
= (it
->s
? -1
6848 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
6849 : IT_CHARPOS (*it
));
6852 if (it
->what
== IT_CHARACTER
)
6853 c
= it
->char_to_display
;
6856 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
6860 for (i
= 0; i
< cmp
->glyph_len
; i
++)
6861 /* TAB in a composition means display glyphs with
6862 padding space on the left or right. */
6863 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
6866 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, pos
, it
->string
);
6871 /* Is this character the last one of a run of characters with
6872 box? If yes, set IT->end_of_box_run_p to 1. */
6876 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
6878 int face_id
= underlying_face_id (it
);
6879 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
6883 if (face
->box
== FACE_NO_BOX
)
6885 /* If the box comes from face properties in a
6886 display string, check faces in that string. */
6887 int string_face_id
= face_after_it_pos (it
);
6888 it
->end_of_box_run_p
6889 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
6892 /* Otherwise, the box comes from the underlying face.
6893 If this is the last string character displayed, check
6894 the next buffer location. */
6895 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
6896 && (it
->current
.overlay_string_index
6897 == it
->n_overlay_strings
- 1))
6901 struct text_pos pos
= it
->current
.pos
;
6902 INC_TEXT_POS (pos
, it
->multibyte_p
);
6904 next_face_id
= face_at_buffer_position
6905 (it
->w
, CHARPOS (pos
), it
->region_beg_charpos
,
6906 it
->region_end_charpos
, &ignore
,
6907 (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
), 0,
6909 it
->end_of_box_run_p
6910 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
6917 int face_id
= face_after_it_pos (it
);
6918 it
->end_of_box_run_p
6919 = (face_id
!= it
->face_id
6920 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
6923 /* If we reached the end of the object we've been iterating (e.g., a
6924 display string or an overlay string), and there's something on
6925 IT->stack, proceed with what's on the stack. It doesn't make
6926 sense to return zero if there's unprocessed stuff on the stack,
6927 because otherwise that stuff will never be displayed. */
6928 if (!success_p
&& it
->sp
> 0)
6930 set_iterator_to_next (it
, 0);
6931 success_p
= get_next_display_element (it
);
6934 /* Value is 0 if end of buffer or string reached. */
6939 /* Move IT to the next display element.
6941 RESEAT_P non-zero means if called on a newline in buffer text,
6942 skip to the next visible line start.
6944 Functions get_next_display_element and set_iterator_to_next are
6945 separate because I find this arrangement easier to handle than a
6946 get_next_display_element function that also increments IT's
6947 position. The way it is we can first look at an iterator's current
6948 display element, decide whether it fits on a line, and if it does,
6949 increment the iterator position. The other way around we probably
6950 would either need a flag indicating whether the iterator has to be
6951 incremented the next time, or we would have to implement a
6952 decrement position function which would not be easy to write. */
6955 set_iterator_to_next (struct it
*it
, int reseat_p
)
6957 /* Reset flags indicating start and end of a sequence of characters
6958 with box. Reset them at the start of this function because
6959 moving the iterator to a new position might set them. */
6960 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
6964 case GET_FROM_BUFFER
:
6965 /* The current display element of IT is a character from
6966 current_buffer. Advance in the buffer, and maybe skip over
6967 invisible lines that are so because of selective display. */
6968 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
6969 reseat_at_next_visible_line_start (it
, 0);
6970 else if (it
->cmp_it
.id
>= 0)
6972 /* We are currently getting glyphs from a composition. */
6977 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6978 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6979 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6981 it
->cmp_it
.from
= it
->cmp_it
.to
;
6986 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6988 it
->end_charpos
, Qnil
);
6991 else if (! it
->cmp_it
.reversed_p
)
6993 /* Composition created while scanning forward. */
6994 /* Update IT's char/byte positions to point to the first
6995 character of the next grapheme cluster, or to the
6996 character visually after the current composition. */
6997 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
6998 bidi_move_to_visually_next (&it
->bidi_it
);
6999 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7000 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7002 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7004 /* Proceed to the next grapheme cluster. */
7005 it
->cmp_it
.from
= it
->cmp_it
.to
;
7009 /* No more grapheme clusters in this composition.
7010 Find the next stop position. */
7011 ptrdiff_t stop
= it
->end_charpos
;
7012 if (it
->bidi_it
.scan_dir
< 0)
7013 /* Now we are scanning backward and don't know
7016 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7017 IT_BYTEPOS (*it
), stop
, Qnil
);
7022 /* Composition created while scanning backward. */
7023 /* Update IT's char/byte positions to point to the last
7024 character of the previous grapheme cluster, or the
7025 character visually after the current composition. */
7026 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7027 bidi_move_to_visually_next (&it
->bidi_it
);
7028 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7029 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7030 if (it
->cmp_it
.from
> 0)
7032 /* Proceed to the previous grapheme cluster. */
7033 it
->cmp_it
.to
= it
->cmp_it
.from
;
7037 /* No more grapheme clusters in this composition.
7038 Find the next stop position. */
7039 ptrdiff_t stop
= it
->end_charpos
;
7040 if (it
->bidi_it
.scan_dir
< 0)
7041 /* Now we are scanning backward and don't know
7044 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7045 IT_BYTEPOS (*it
), stop
, Qnil
);
7051 eassert (it
->len
!= 0);
7055 IT_BYTEPOS (*it
) += it
->len
;
7056 IT_CHARPOS (*it
) += 1;
7060 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7061 /* If this is a new paragraph, determine its base
7062 direction (a.k.a. its base embedding level). */
7063 if (it
->bidi_it
.new_paragraph
)
7064 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
7065 bidi_move_to_visually_next (&it
->bidi_it
);
7066 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7067 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7068 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7070 /* As the scan direction was changed, we must
7071 re-compute the stop position for composition. */
7072 ptrdiff_t stop
= it
->end_charpos
;
7073 if (it
->bidi_it
.scan_dir
< 0)
7075 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7076 IT_BYTEPOS (*it
), stop
, Qnil
);
7079 eassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
7083 case GET_FROM_C_STRING
:
7084 /* Current display element of IT is from a C string. */
7086 /* If the string position is beyond string's end, it means
7087 next_element_from_c_string is padding the string with
7088 blanks, in which case we bypass the bidi iterator,
7089 because it cannot deal with such virtual characters. */
7090 || IT_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7092 IT_BYTEPOS (*it
) += it
->len
;
7093 IT_CHARPOS (*it
) += 1;
7097 bidi_move_to_visually_next (&it
->bidi_it
);
7098 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7099 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7103 case GET_FROM_DISPLAY_VECTOR
:
7104 /* Current display element of IT is from a display table entry.
7105 Advance in the display table definition. Reset it to null if
7106 end reached, and continue with characters from buffers/
7108 ++it
->current
.dpvec_index
;
7110 /* Restore face of the iterator to what they were before the
7111 display vector entry (these entries may contain faces). */
7112 it
->face_id
= it
->saved_face_id
;
7114 if (it
->dpvec
+ it
->current
.dpvec_index
>= it
->dpend
)
7116 int recheck_faces
= it
->ellipsis_p
;
7119 it
->method
= GET_FROM_C_STRING
;
7120 else if (STRINGP (it
->string
))
7121 it
->method
= GET_FROM_STRING
;
7124 it
->method
= GET_FROM_BUFFER
;
7125 it
->object
= it
->w
->buffer
;
7129 it
->current
.dpvec_index
= -1;
7131 /* Skip over characters which were displayed via IT->dpvec. */
7132 if (it
->dpvec_char_len
< 0)
7133 reseat_at_next_visible_line_start (it
, 1);
7134 else if (it
->dpvec_char_len
> 0)
7136 if (it
->method
== GET_FROM_STRING
7137 && it
->n_overlay_strings
> 0)
7138 it
->ignore_overlay_strings_at_pos_p
= 1;
7139 it
->len
= it
->dpvec_char_len
;
7140 set_iterator_to_next (it
, reseat_p
);
7143 /* Maybe recheck faces after display vector */
7145 it
->stop_charpos
= IT_CHARPOS (*it
);
7149 case GET_FROM_STRING
:
7150 /* Current display element is a character from a Lisp string. */
7151 eassert (it
->s
== NULL
&& STRINGP (it
->string
));
7152 /* Don't advance past string end. These conditions are true
7153 when set_iterator_to_next is called at the end of
7154 get_next_display_element, in which case the Lisp string is
7155 already exhausted, and all we want is pop the iterator
7157 if (it
->current
.overlay_string_index
>= 0)
7159 /* This is an overlay string, so there's no padding with
7160 spaces, and the number of characters in the string is
7161 where the string ends. */
7162 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7163 goto consider_string_end
;
7167 /* Not an overlay string. There could be padding, so test
7168 against it->end_charpos . */
7169 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7170 goto consider_string_end
;
7172 if (it
->cmp_it
.id
>= 0)
7178 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7179 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7180 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7181 it
->cmp_it
.from
= it
->cmp_it
.to
;
7185 composition_compute_stop_pos (&it
->cmp_it
,
7186 IT_STRING_CHARPOS (*it
),
7187 IT_STRING_BYTEPOS (*it
),
7188 it
->end_charpos
, it
->string
);
7191 else if (! it
->cmp_it
.reversed_p
)
7193 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7194 bidi_move_to_visually_next (&it
->bidi_it
);
7195 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7196 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7198 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7199 it
->cmp_it
.from
= it
->cmp_it
.to
;
7202 ptrdiff_t stop
= it
->end_charpos
;
7203 if (it
->bidi_it
.scan_dir
< 0)
7205 composition_compute_stop_pos (&it
->cmp_it
,
7206 IT_STRING_CHARPOS (*it
),
7207 IT_STRING_BYTEPOS (*it
), stop
,
7213 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7214 bidi_move_to_visually_next (&it
->bidi_it
);
7215 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7216 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7217 if (it
->cmp_it
.from
> 0)
7218 it
->cmp_it
.to
= it
->cmp_it
.from
;
7221 ptrdiff_t stop
= it
->end_charpos
;
7222 if (it
->bidi_it
.scan_dir
< 0)
7224 composition_compute_stop_pos (&it
->cmp_it
,
7225 IT_STRING_CHARPOS (*it
),
7226 IT_STRING_BYTEPOS (*it
), stop
,
7234 /* If the string position is beyond string's end, it
7235 means next_element_from_string is padding the string
7236 with blanks, in which case we bypass the bidi
7237 iterator, because it cannot deal with such virtual
7239 || IT_STRING_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7241 IT_STRING_BYTEPOS (*it
) += it
->len
;
7242 IT_STRING_CHARPOS (*it
) += 1;
7246 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7248 bidi_move_to_visually_next (&it
->bidi_it
);
7249 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7250 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7251 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7253 ptrdiff_t stop
= it
->end_charpos
;
7255 if (it
->bidi_it
.scan_dir
< 0)
7257 composition_compute_stop_pos (&it
->cmp_it
,
7258 IT_STRING_CHARPOS (*it
),
7259 IT_STRING_BYTEPOS (*it
), stop
,
7265 consider_string_end
:
7267 if (it
->current
.overlay_string_index
>= 0)
7269 /* IT->string is an overlay string. Advance to the
7270 next, if there is one. */
7271 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7274 next_overlay_string (it
);
7276 setup_for_ellipsis (it
, 0);
7281 /* IT->string is not an overlay string. If we reached
7282 its end, and there is something on IT->stack, proceed
7283 with what is on the stack. This can be either another
7284 string, this time an overlay string, or a buffer. */
7285 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
7289 if (it
->method
== GET_FROM_STRING
)
7290 goto consider_string_end
;
7295 case GET_FROM_IMAGE
:
7296 case GET_FROM_STRETCH
:
7297 /* The position etc with which we have to proceed are on
7298 the stack. The position may be at the end of a string,
7299 if the `display' property takes up the whole string. */
7300 eassert (it
->sp
> 0);
7302 if (it
->method
== GET_FROM_STRING
)
7303 goto consider_string_end
;
7307 /* There are no other methods defined, so this should be a bug. */
7311 eassert (it
->method
!= GET_FROM_STRING
7312 || (STRINGP (it
->string
)
7313 && IT_STRING_CHARPOS (*it
) >= 0));
7316 /* Load IT's display element fields with information about the next
7317 display element which comes from a display table entry or from the
7318 result of translating a control character to one of the forms `^C'
7321 IT->dpvec holds the glyphs to return as characters.
7322 IT->saved_face_id holds the face id before the display vector--it
7323 is restored into IT->face_id in set_iterator_to_next. */
7326 next_element_from_display_vector (struct it
*it
)
7331 eassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
7333 it
->face_id
= it
->saved_face_id
;
7335 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
7336 That seemed totally bogus - so I changed it... */
7337 gc
= it
->dpvec
[it
->current
.dpvec_index
];
7339 if (GLYPH_CODE_P (gc
))
7341 it
->c
= GLYPH_CODE_CHAR (gc
);
7342 it
->len
= CHAR_BYTES (it
->c
);
7344 /* The entry may contain a face id to use. Such a face id is
7345 the id of a Lisp face, not a realized face. A face id of
7346 zero means no face is specified. */
7347 if (it
->dpvec_face_id
>= 0)
7348 it
->face_id
= it
->dpvec_face_id
;
7351 int lface_id
= GLYPH_CODE_FACE (gc
);
7353 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
7358 /* Display table entry is invalid. Return a space. */
7359 it
->c
= ' ', it
->len
= 1;
7361 /* Don't change position and object of the iterator here. They are
7362 still the values of the character that had this display table
7363 entry or was translated, and that's what we want. */
7364 it
->what
= IT_CHARACTER
;
7368 /* Get the first element of string/buffer in the visual order, after
7369 being reseated to a new position in a string or a buffer. */
7371 get_visually_first_element (struct it
*it
)
7373 int string_p
= STRINGP (it
->string
) || it
->s
;
7374 ptrdiff_t eob
= (string_p
? it
->bidi_it
.string
.schars
: ZV
);
7375 ptrdiff_t bob
= (string_p
? 0 : BEGV
);
7377 if (STRINGP (it
->string
))
7379 it
->bidi_it
.charpos
= IT_STRING_CHARPOS (*it
);
7380 it
->bidi_it
.bytepos
= IT_STRING_BYTEPOS (*it
);
7384 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
7385 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
7388 if (it
->bidi_it
.charpos
== eob
)
7390 /* Nothing to do, but reset the FIRST_ELT flag, like
7391 bidi_paragraph_init does, because we are not going to
7393 it
->bidi_it
.first_elt
= 0;
7395 else if (it
->bidi_it
.charpos
== bob
7397 && (FETCH_CHAR (it
->bidi_it
.bytepos
- 1) == '\n'
7398 || FETCH_CHAR (it
->bidi_it
.bytepos
) == '\n')))
7400 /* If we are at the beginning of a line/string, we can produce
7401 the next element right away. */
7402 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7403 bidi_move_to_visually_next (&it
->bidi_it
);
7407 ptrdiff_t orig_bytepos
= it
->bidi_it
.bytepos
;
7409 /* We need to prime the bidi iterator starting at the line's or
7410 string's beginning, before we will be able to produce the
7413 it
->bidi_it
.charpos
= it
->bidi_it
.bytepos
= 0;
7416 it
->bidi_it
.charpos
= find_next_newline_no_quit (IT_CHARPOS (*it
),
7418 it
->bidi_it
.bytepos
= CHAR_TO_BYTE (it
->bidi_it
.charpos
);
7420 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7423 /* Now return to buffer/string position where we were asked
7424 to get the next display element, and produce that. */
7425 bidi_move_to_visually_next (&it
->bidi_it
);
7427 while (it
->bidi_it
.bytepos
!= orig_bytepos
7428 && it
->bidi_it
.charpos
< eob
);
7431 /* Adjust IT's position information to where we ended up. */
7432 if (STRINGP (it
->string
))
7434 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7435 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7439 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7440 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7443 if (STRINGP (it
->string
) || !it
->s
)
7445 ptrdiff_t stop
, charpos
, bytepos
;
7447 if (STRINGP (it
->string
))
7450 stop
= SCHARS (it
->string
);
7451 if (stop
> it
->end_charpos
)
7452 stop
= it
->end_charpos
;
7453 charpos
= IT_STRING_CHARPOS (*it
);
7454 bytepos
= IT_STRING_BYTEPOS (*it
);
7458 stop
= it
->end_charpos
;
7459 charpos
= IT_CHARPOS (*it
);
7460 bytepos
= IT_BYTEPOS (*it
);
7462 if (it
->bidi_it
.scan_dir
< 0)
7464 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
, stop
,
7469 /* Load IT with the next display element from Lisp string IT->string.
7470 IT->current.string_pos is the current position within the string.
7471 If IT->current.overlay_string_index >= 0, the Lisp string is an
7475 next_element_from_string (struct it
*it
)
7477 struct text_pos position
;
7479 eassert (STRINGP (it
->string
));
7480 eassert (!it
->bidi_p
|| EQ (it
->string
, it
->bidi_it
.string
.lstring
));
7481 eassert (IT_STRING_CHARPOS (*it
) >= 0);
7482 position
= it
->current
.string_pos
;
7484 /* With bidi reordering, the character to display might not be the
7485 character at IT_STRING_CHARPOS. BIDI_IT.FIRST_ELT non-zero means
7486 that we were reseat()ed to a new string, whose paragraph
7487 direction is not known. */
7488 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7490 get_visually_first_element (it
);
7491 SET_TEXT_POS (position
, IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
));
7494 /* Time to check for invisible text? */
7495 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
7497 if (IT_STRING_CHARPOS (*it
) >= it
->stop_charpos
)
7500 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7501 || IT_STRING_CHARPOS (*it
) == it
->stop_charpos
))
7503 /* With bidi non-linear iteration, we could find
7504 ourselves far beyond the last computed stop_charpos,
7505 with several other stop positions in between that we
7506 missed. Scan them all now, in buffer's logical
7507 order, until we find and handle the last stop_charpos
7508 that precedes our current position. */
7509 handle_stop_backwards (it
, it
->stop_charpos
);
7510 return GET_NEXT_DISPLAY_ELEMENT (it
);
7516 /* Take note of the stop position we just moved
7517 across, for when we will move back across it. */
7518 it
->prev_stop
= it
->stop_charpos
;
7519 /* If we are at base paragraph embedding level, take
7520 note of the last stop position seen at this
7522 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7523 it
->base_level_stop
= it
->stop_charpos
;
7527 /* Since a handler may have changed IT->method, we must
7529 return GET_NEXT_DISPLAY_ELEMENT (it
);
7533 /* If we are before prev_stop, we may have overstepped
7534 on our way backwards a stop_pos, and if so, we need
7535 to handle that stop_pos. */
7536 && IT_STRING_CHARPOS (*it
) < it
->prev_stop
7537 /* We can sometimes back up for reasons that have nothing
7538 to do with bidi reordering. E.g., compositions. The
7539 code below is only needed when we are above the base
7540 embedding level, so test for that explicitly. */
7541 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7543 /* If we lost track of base_level_stop, we have no better
7544 place for handle_stop_backwards to start from than string
7545 beginning. This happens, e.g., when we were reseated to
7546 the previous screenful of text by vertical-motion. */
7547 if (it
->base_level_stop
<= 0
7548 || IT_STRING_CHARPOS (*it
) < it
->base_level_stop
)
7549 it
->base_level_stop
= 0;
7550 handle_stop_backwards (it
, it
->base_level_stop
);
7551 return GET_NEXT_DISPLAY_ELEMENT (it
);
7555 if (it
->current
.overlay_string_index
>= 0)
7557 /* Get the next character from an overlay string. In overlay
7558 strings, there is no field width or padding with spaces to
7560 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7565 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7566 IT_STRING_BYTEPOS (*it
),
7567 it
->bidi_it
.scan_dir
< 0
7569 : SCHARS (it
->string
))
7570 && next_element_from_composition (it
))
7574 else if (STRING_MULTIBYTE (it
->string
))
7576 const unsigned char *s
= (SDATA (it
->string
)
7577 + IT_STRING_BYTEPOS (*it
));
7578 it
->c
= string_char_and_length (s
, &it
->len
);
7582 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7588 /* Get the next character from a Lisp string that is not an
7589 overlay string. Such strings come from the mode line, for
7590 example. We may have to pad with spaces, or truncate the
7591 string. See also next_element_from_c_string. */
7592 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7597 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
7599 /* Pad with spaces. */
7600 it
->c
= ' ', it
->len
= 1;
7601 CHARPOS (position
) = BYTEPOS (position
) = -1;
7603 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7604 IT_STRING_BYTEPOS (*it
),
7605 it
->bidi_it
.scan_dir
< 0
7607 : it
->string_nchars
)
7608 && next_element_from_composition (it
))
7612 else if (STRING_MULTIBYTE (it
->string
))
7614 const unsigned char *s
= (SDATA (it
->string
)
7615 + IT_STRING_BYTEPOS (*it
));
7616 it
->c
= string_char_and_length (s
, &it
->len
);
7620 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7625 /* Record what we have and where it came from. */
7626 it
->what
= IT_CHARACTER
;
7627 it
->object
= it
->string
;
7628 it
->position
= position
;
7633 /* Load IT with next display element from C string IT->s.
7634 IT->string_nchars is the maximum number of characters to return
7635 from the string. IT->end_charpos may be greater than
7636 IT->string_nchars when this function is called, in which case we
7637 may have to return padding spaces. Value is zero if end of string
7638 reached, including padding spaces. */
7641 next_element_from_c_string (struct it
*it
)
7646 eassert (!it
->bidi_p
|| it
->s
== it
->bidi_it
.string
.s
);
7647 it
->what
= IT_CHARACTER
;
7648 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
7651 /* With bidi reordering, the character to display might not be the
7652 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7653 we were reseated to a new string, whose paragraph direction is
7655 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7656 get_visually_first_element (it
);
7658 /* IT's position can be greater than IT->string_nchars in case a
7659 field width or precision has been specified when the iterator was
7661 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7663 /* End of the game. */
7667 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
7669 /* Pad with spaces. */
7670 it
->c
= ' ', it
->len
= 1;
7671 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
7673 else if (it
->multibyte_p
)
7674 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
), &it
->len
);
7676 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
7682 /* Set up IT to return characters from an ellipsis, if appropriate.
7683 The definition of the ellipsis glyphs may come from a display table
7684 entry. This function fills IT with the first glyph from the
7685 ellipsis if an ellipsis is to be displayed. */
7688 next_element_from_ellipsis (struct it
*it
)
7690 if (it
->selective_display_ellipsis_p
)
7691 setup_for_ellipsis (it
, it
->len
);
7694 /* The face at the current position may be different from the
7695 face we find after the invisible text. Remember what it
7696 was in IT->saved_face_id, and signal that it's there by
7697 setting face_before_selective_p. */
7698 it
->saved_face_id
= it
->face_id
;
7699 it
->method
= GET_FROM_BUFFER
;
7700 it
->object
= it
->w
->buffer
;
7701 reseat_at_next_visible_line_start (it
, 1);
7702 it
->face_before_selective_p
= 1;
7705 return GET_NEXT_DISPLAY_ELEMENT (it
);
7709 /* Deliver an image display element. The iterator IT is already
7710 filled with image information (done in handle_display_prop). Value
7715 next_element_from_image (struct it
*it
)
7717 it
->what
= IT_IMAGE
;
7718 it
->ignore_overlay_strings_at_pos_p
= 0;
7723 /* Fill iterator IT with next display element from a stretch glyph
7724 property. IT->object is the value of the text property. Value is
7728 next_element_from_stretch (struct it
*it
)
7730 it
->what
= IT_STRETCH
;
7734 /* Scan backwards from IT's current position until we find a stop
7735 position, or until BEGV. This is called when we find ourself
7736 before both the last known prev_stop and base_level_stop while
7737 reordering bidirectional text. */
7740 compute_stop_pos_backwards (struct it
*it
)
7742 const int SCAN_BACK_LIMIT
= 1000;
7743 struct text_pos pos
;
7744 struct display_pos save_current
= it
->current
;
7745 struct text_pos save_position
= it
->position
;
7746 ptrdiff_t charpos
= IT_CHARPOS (*it
);
7747 ptrdiff_t where_we_are
= charpos
;
7748 ptrdiff_t save_stop_pos
= it
->stop_charpos
;
7749 ptrdiff_t save_end_pos
= it
->end_charpos
;
7751 eassert (NILP (it
->string
) && !it
->s
);
7752 eassert (it
->bidi_p
);
7756 it
->end_charpos
= min (charpos
+ 1, ZV
);
7757 charpos
= max (charpos
- SCAN_BACK_LIMIT
, BEGV
);
7758 SET_TEXT_POS (pos
, charpos
, BYTE_TO_CHAR (charpos
));
7759 reseat_1 (it
, pos
, 0);
7760 compute_stop_pos (it
);
7761 /* We must advance forward, right? */
7762 if (it
->stop_charpos
<= charpos
)
7765 while (charpos
> BEGV
&& it
->stop_charpos
>= it
->end_charpos
);
7767 if (it
->stop_charpos
<= where_we_are
)
7768 it
->prev_stop
= it
->stop_charpos
;
7770 it
->prev_stop
= BEGV
;
7772 it
->current
= save_current
;
7773 it
->position
= save_position
;
7774 it
->stop_charpos
= save_stop_pos
;
7775 it
->end_charpos
= save_end_pos
;
7778 /* Scan forward from CHARPOS in the current buffer/string, until we
7779 find a stop position > current IT's position. Then handle the stop
7780 position before that. This is called when we bump into a stop
7781 position while reordering bidirectional text. CHARPOS should be
7782 the last previously processed stop_pos (or BEGV/0, if none were
7783 processed yet) whose position is less that IT's current
7787 handle_stop_backwards (struct it
*it
, ptrdiff_t charpos
)
7789 int bufp
= !STRINGP (it
->string
);
7790 ptrdiff_t where_we_are
= (bufp
? IT_CHARPOS (*it
) : IT_STRING_CHARPOS (*it
));
7791 struct display_pos save_current
= it
->current
;
7792 struct text_pos save_position
= it
->position
;
7793 struct text_pos pos1
;
7794 ptrdiff_t next_stop
;
7796 /* Scan in strict logical order. */
7797 eassert (it
->bidi_p
);
7801 it
->prev_stop
= charpos
;
7804 SET_TEXT_POS (pos1
, charpos
, CHAR_TO_BYTE (charpos
));
7805 reseat_1 (it
, pos1
, 0);
7808 it
->current
.string_pos
= string_pos (charpos
, it
->string
);
7809 compute_stop_pos (it
);
7810 /* We must advance forward, right? */
7811 if (it
->stop_charpos
<= it
->prev_stop
)
7813 charpos
= it
->stop_charpos
;
7815 while (charpos
<= where_we_are
);
7818 it
->current
= save_current
;
7819 it
->position
= save_position
;
7820 next_stop
= it
->stop_charpos
;
7821 it
->stop_charpos
= it
->prev_stop
;
7823 it
->stop_charpos
= next_stop
;
7826 /* Load IT with the next display element from current_buffer. Value
7827 is zero if end of buffer reached. IT->stop_charpos is the next
7828 position at which to stop and check for text properties or buffer
7832 next_element_from_buffer (struct it
*it
)
7836 eassert (IT_CHARPOS (*it
) >= BEGV
);
7837 eassert (NILP (it
->string
) && !it
->s
);
7838 eassert (!it
->bidi_p
7839 || (EQ (it
->bidi_it
.string
.lstring
, Qnil
)
7840 && it
->bidi_it
.string
.s
== NULL
));
7842 /* With bidi reordering, the character to display might not be the
7843 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7844 we were reseat()ed to a new buffer position, which is potentially
7845 a different paragraph. */
7846 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7848 get_visually_first_element (it
);
7849 SET_TEXT_POS (it
->position
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7852 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
7854 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7856 int overlay_strings_follow_p
;
7858 /* End of the game, except when overlay strings follow that
7859 haven't been returned yet. */
7860 if (it
->overlay_strings_at_end_processed_p
)
7861 overlay_strings_follow_p
= 0;
7864 it
->overlay_strings_at_end_processed_p
= 1;
7865 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
7868 if (overlay_strings_follow_p
)
7869 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
7873 it
->position
= it
->current
.pos
;
7877 else if (!(!it
->bidi_p
7878 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7879 || IT_CHARPOS (*it
) == it
->stop_charpos
))
7881 /* With bidi non-linear iteration, we could find ourselves
7882 far beyond the last computed stop_charpos, with several
7883 other stop positions in between that we missed. Scan
7884 them all now, in buffer's logical order, until we find
7885 and handle the last stop_charpos that precedes our
7886 current position. */
7887 handle_stop_backwards (it
, it
->stop_charpos
);
7888 return GET_NEXT_DISPLAY_ELEMENT (it
);
7894 /* Take note of the stop position we just moved across,
7895 for when we will move back across it. */
7896 it
->prev_stop
= it
->stop_charpos
;
7897 /* If we are at base paragraph embedding level, take
7898 note of the last stop position seen at this
7900 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7901 it
->base_level_stop
= it
->stop_charpos
;
7904 return GET_NEXT_DISPLAY_ELEMENT (it
);
7908 /* If we are before prev_stop, we may have overstepped on
7909 our way backwards a stop_pos, and if so, we need to
7910 handle that stop_pos. */
7911 && IT_CHARPOS (*it
) < it
->prev_stop
7912 /* We can sometimes back up for reasons that have nothing
7913 to do with bidi reordering. E.g., compositions. The
7914 code below is only needed when we are above the base
7915 embedding level, so test for that explicitly. */
7916 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7918 if (it
->base_level_stop
<= 0
7919 || IT_CHARPOS (*it
) < it
->base_level_stop
)
7921 /* If we lost track of base_level_stop, we need to find
7922 prev_stop by looking backwards. This happens, e.g., when
7923 we were reseated to the previous screenful of text by
7925 it
->base_level_stop
= BEGV
;
7926 compute_stop_pos_backwards (it
);
7927 handle_stop_backwards (it
, it
->prev_stop
);
7930 handle_stop_backwards (it
, it
->base_level_stop
);
7931 return GET_NEXT_DISPLAY_ELEMENT (it
);
7935 /* No face changes, overlays etc. in sight, so just return a
7936 character from current_buffer. */
7940 /* Maybe run the redisplay end trigger hook. Performance note:
7941 This doesn't seem to cost measurable time. */
7942 if (it
->redisplay_end_trigger_charpos
7944 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
7945 run_redisplay_end_trigger_hook (it
);
7947 stop
= it
->bidi_it
.scan_dir
< 0 ? -1 : it
->end_charpos
;
7948 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
7950 && next_element_from_composition (it
))
7955 /* Get the next character, maybe multibyte. */
7956 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
7957 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
7958 it
->c
= STRING_CHAR_AND_LENGTH (p
, it
->len
);
7960 it
->c
= *p
, it
->len
= 1;
7962 /* Record what we have and where it came from. */
7963 it
->what
= IT_CHARACTER
;
7964 it
->object
= it
->w
->buffer
;
7965 it
->position
= it
->current
.pos
;
7967 /* Normally we return the character found above, except when we
7968 really want to return an ellipsis for selective display. */
7973 /* A value of selective > 0 means hide lines indented more
7974 than that number of columns. */
7975 if (it
->selective
> 0
7976 && IT_CHARPOS (*it
) + 1 < ZV
7977 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
7978 IT_BYTEPOS (*it
) + 1,
7981 success_p
= next_element_from_ellipsis (it
);
7982 it
->dpvec_char_len
= -1;
7985 else if (it
->c
== '\r' && it
->selective
== -1)
7987 /* A value of selective == -1 means that everything from the
7988 CR to the end of the line is invisible, with maybe an
7989 ellipsis displayed for it. */
7990 success_p
= next_element_from_ellipsis (it
);
7991 it
->dpvec_char_len
= -1;
7996 /* Value is zero if end of buffer reached. */
7997 eassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
8002 /* Run the redisplay end trigger hook for IT. */
8005 run_redisplay_end_trigger_hook (struct it
*it
)
8007 Lisp_Object args
[3];
8009 /* IT->glyph_row should be non-null, i.e. we should be actually
8010 displaying something, or otherwise we should not run the hook. */
8011 eassert (it
->glyph_row
);
8013 /* Set up hook arguments. */
8014 args
[0] = Qredisplay_end_trigger_functions
;
8015 args
[1] = it
->window
;
8016 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
8017 it
->redisplay_end_trigger_charpos
= 0;
8019 /* Since we are *trying* to run these functions, don't try to run
8020 them again, even if they get an error. */
8021 wset_redisplay_end_trigger (it
->w
, Qnil
);
8022 Frun_hook_with_args (3, args
);
8024 /* Notice if it changed the face of the character we are on. */
8025 handle_face_prop (it
);
8029 /* Deliver a composition display element. Unlike the other
8030 next_element_from_XXX, this function is not registered in the array
8031 get_next_element[]. It is called from next_element_from_buffer and
8032 next_element_from_string when necessary. */
8035 next_element_from_composition (struct it
*it
)
8037 it
->what
= IT_COMPOSITION
;
8038 it
->len
= it
->cmp_it
.nbytes
;
8039 if (STRINGP (it
->string
))
8043 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
8044 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
8047 it
->position
= it
->current
.string_pos
;
8048 it
->object
= it
->string
;
8049 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
8050 IT_STRING_BYTEPOS (*it
), it
->string
);
8056 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
8057 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
8060 if (it
->bidi_it
.new_paragraph
)
8061 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
8062 /* Resync the bidi iterator with IT's new position.
8063 FIXME: this doesn't support bidirectional text. */
8064 while (it
->bidi_it
.charpos
< IT_CHARPOS (*it
))
8065 bidi_move_to_visually_next (&it
->bidi_it
);
8069 it
->position
= it
->current
.pos
;
8070 it
->object
= it
->w
->buffer
;
8071 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
8072 IT_BYTEPOS (*it
), Qnil
);
8079 /***********************************************************************
8080 Moving an iterator without producing glyphs
8081 ***********************************************************************/
8083 /* Check if iterator is at a position corresponding to a valid buffer
8084 position after some move_it_ call. */
8086 #define IT_POS_VALID_AFTER_MOVE_P(it) \
8087 ((it)->method == GET_FROM_STRING \
8088 ? IT_STRING_CHARPOS (*it) == 0 \
8092 /* Move iterator IT to a specified buffer or X position within one
8093 line on the display without producing glyphs.
8095 OP should be a bit mask including some or all of these bits:
8096 MOVE_TO_X: Stop upon reaching x-position TO_X.
8097 MOVE_TO_POS: Stop upon reaching buffer or string position TO_CHARPOS.
8098 Regardless of OP's value, stop upon reaching the end of the display line.
8100 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
8101 This means, in particular, that TO_X includes window's horizontal
8104 The return value has several possible values that
8105 say what condition caused the scan to stop:
8107 MOVE_POS_MATCH_OR_ZV
8108 - when TO_POS or ZV was reached.
8111 -when TO_X was reached before TO_POS or ZV were reached.
8114 - when we reached the end of the display area and the line must
8118 - when we reached the end of the display area and the line is
8122 - when we stopped at a line end, i.e. a newline or a CR and selective
8125 static enum move_it_result
8126 move_it_in_display_line_to (struct it
*it
,
8127 ptrdiff_t to_charpos
, int to_x
,
8128 enum move_operation_enum op
)
8130 enum move_it_result result
= MOVE_UNDEFINED
;
8131 struct glyph_row
*saved_glyph_row
;
8132 struct it wrap_it
, atpos_it
, atx_it
, ppos_it
;
8133 void *wrap_data
= NULL
, *atpos_data
= NULL
, *atx_data
= NULL
;
8134 void *ppos_data
= NULL
;
8136 enum it_method prev_method
= it
->method
;
8137 ptrdiff_t prev_pos
= IT_CHARPOS (*it
);
8138 int saw_smaller_pos
= prev_pos
< to_charpos
;
8140 /* Don't produce glyphs in produce_glyphs. */
8141 saved_glyph_row
= it
->glyph_row
;
8142 it
->glyph_row
= NULL
;
8144 /* Use wrap_it to save a copy of IT wherever a word wrap could
8145 occur. Use atpos_it to save a copy of IT at the desired buffer
8146 position, if found, so that we can scan ahead and check if the
8147 word later overshoots the window edge. Use atx_it similarly, for
8153 /* Use ppos_it under bidi reordering to save a copy of IT for the
8154 position > CHARPOS that is the closest to CHARPOS. We restore
8155 that position in IT when we have scanned the entire display line
8156 without finding a match for CHARPOS and all the character
8157 positions are greater than CHARPOS. */
8160 SAVE_IT (ppos_it
, *it
, ppos_data
);
8161 SET_TEXT_POS (ppos_it
.current
.pos
, ZV
, ZV_BYTE
);
8162 if ((op
& MOVE_TO_POS
) && IT_CHARPOS (*it
) >= to_charpos
)
8163 SAVE_IT (ppos_it
, *it
, ppos_data
);
8166 #define BUFFER_POS_REACHED_P() \
8167 ((op & MOVE_TO_POS) != 0 \
8168 && BUFFERP (it->object) \
8169 && (IT_CHARPOS (*it) == to_charpos \
8171 || BIDI_AT_BASE_LEVEL (it->bidi_it)) \
8172 && IT_CHARPOS (*it) > to_charpos) \
8173 || (it->what == IT_COMPOSITION \
8174 && ((IT_CHARPOS (*it) > to_charpos \
8175 && to_charpos >= it->cmp_it.charpos) \
8176 || (IT_CHARPOS (*it) < to_charpos \
8177 && to_charpos <= it->cmp_it.charpos)))) \
8178 && (it->method == GET_FROM_BUFFER \
8179 || (it->method == GET_FROM_DISPLAY_VECTOR \
8180 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
8182 /* If there's a line-/wrap-prefix, handle it. */
8183 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
8184 && it
->current_y
< it
->last_visible_y
)
8185 handle_line_prefix (it
);
8187 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8188 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8192 int x
, i
, ascent
= 0, descent
= 0;
8194 /* Utility macro to reset an iterator with x, ascent, and descent. */
8195 #define IT_RESET_X_ASCENT_DESCENT(IT) \
8196 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
8197 (IT)->max_descent = descent)
8199 /* Stop if we move beyond TO_CHARPOS (after an image or a
8200 display string or stretch glyph). */
8201 if ((op
& MOVE_TO_POS
) != 0
8202 && BUFFERP (it
->object
)
8203 && it
->method
== GET_FROM_BUFFER
8205 /* When the iterator is at base embedding level, we
8206 are guaranteed that characters are delivered for
8207 display in strictly increasing order of their
8208 buffer positions. */
8209 || BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8210 && IT_CHARPOS (*it
) > to_charpos
)
8212 && (prev_method
== GET_FROM_IMAGE
8213 || prev_method
== GET_FROM_STRETCH
8214 || prev_method
== GET_FROM_STRING
)
8215 /* Passed TO_CHARPOS from left to right. */
8216 && ((prev_pos
< to_charpos
8217 && IT_CHARPOS (*it
) > to_charpos
)
8218 /* Passed TO_CHARPOS from right to left. */
8219 || (prev_pos
> to_charpos
8220 && IT_CHARPOS (*it
) < to_charpos
)))))
8222 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8224 result
= MOVE_POS_MATCH_OR_ZV
;
8227 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8228 /* If wrap_it is valid, the current position might be in a
8229 word that is wrapped. So, save the iterator in
8230 atpos_it and continue to see if wrapping happens. */
8231 SAVE_IT (atpos_it
, *it
, atpos_data
);
8234 /* Stop when ZV reached.
8235 We used to stop here when TO_CHARPOS reached as well, but that is
8236 too soon if this glyph does not fit on this line. So we handle it
8237 explicitly below. */
8238 if (!get_next_display_element (it
))
8240 result
= MOVE_POS_MATCH_OR_ZV
;
8244 if (it
->line_wrap
== TRUNCATE
)
8246 if (BUFFER_POS_REACHED_P ())
8248 result
= MOVE_POS_MATCH_OR_ZV
;
8254 if (it
->line_wrap
== WORD_WRAP
)
8256 if (IT_DISPLAYING_WHITESPACE (it
))
8260 /* We have reached a glyph that follows one or more
8261 whitespace characters. If the position is
8262 already found, we are done. */
8263 if (atpos_it
.sp
>= 0)
8265 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8266 result
= MOVE_POS_MATCH_OR_ZV
;
8271 RESTORE_IT (it
, &atx_it
, atx_data
);
8272 result
= MOVE_X_REACHED
;
8275 /* Otherwise, we can wrap here. */
8276 SAVE_IT (wrap_it
, *it
, wrap_data
);
8282 /* Remember the line height for the current line, in case
8283 the next element doesn't fit on the line. */
8284 ascent
= it
->max_ascent
;
8285 descent
= it
->max_descent
;
8287 /* The call to produce_glyphs will get the metrics of the
8288 display element IT is loaded with. Record the x-position
8289 before this display element, in case it doesn't fit on the
8293 PRODUCE_GLYPHS (it
);
8295 if (it
->area
!= TEXT_AREA
)
8297 prev_method
= it
->method
;
8298 if (it
->method
== GET_FROM_BUFFER
)
8299 prev_pos
= IT_CHARPOS (*it
);
8300 set_iterator_to_next (it
, 1);
8301 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8302 SET_TEXT_POS (this_line_min_pos
,
8303 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8305 && (op
& MOVE_TO_POS
)
8306 && IT_CHARPOS (*it
) > to_charpos
8307 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8308 SAVE_IT (ppos_it
, *it
, ppos_data
);
8312 /* The number of glyphs we get back in IT->nglyphs will normally
8313 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
8314 character on a terminal frame, or (iii) a line end. For the
8315 second case, IT->nglyphs - 1 padding glyphs will be present.
8316 (On X frames, there is only one glyph produced for a
8317 composite character.)
8319 The behavior implemented below means, for continuation lines,
8320 that as many spaces of a TAB as fit on the current line are
8321 displayed there. For terminal frames, as many glyphs of a
8322 multi-glyph character are displayed in the current line, too.
8323 This is what the old redisplay code did, and we keep it that
8324 way. Under X, the whole shape of a complex character must
8325 fit on the line or it will be completely displayed in the
8328 Note that both for tabs and padding glyphs, all glyphs have
8332 /* More than one glyph or glyph doesn't fit on line. All
8333 glyphs have the same width. */
8334 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
8336 int x_before_this_char
= x
;
8337 int hpos_before_this_char
= it
->hpos
;
8339 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
8341 new_x
= x
+ single_glyph_width
;
8343 /* We want to leave anything reaching TO_X to the caller. */
8344 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
8346 if (BUFFER_POS_REACHED_P ())
8348 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8349 goto buffer_pos_reached
;
8350 if (atpos_it
.sp
< 0)
8352 SAVE_IT (atpos_it
, *it
, atpos_data
);
8353 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8358 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8361 result
= MOVE_X_REACHED
;
8366 SAVE_IT (atx_it
, *it
, atx_data
);
8367 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
8372 if (/* Lines are continued. */
8373 it
->line_wrap
!= TRUNCATE
8374 && (/* And glyph doesn't fit on the line. */
8375 new_x
> it
->last_visible_x
8376 /* Or it fits exactly and we're on a window
8378 || (new_x
== it
->last_visible_x
8379 && FRAME_WINDOW_P (it
->f
)
8380 && ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
8381 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8382 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
8384 if (/* IT->hpos == 0 means the very first glyph
8385 doesn't fit on the line, e.g. a wide image. */
8387 || (new_x
== it
->last_visible_x
8388 && FRAME_WINDOW_P (it
->f
)))
8391 it
->current_x
= new_x
;
8393 /* The character's last glyph just barely fits
8395 if (i
== it
->nglyphs
- 1)
8397 /* If this is the destination position,
8398 return a position *before* it in this row,
8399 now that we know it fits in this row. */
8400 if (BUFFER_POS_REACHED_P ())
8402 if (it
->line_wrap
!= WORD_WRAP
8405 it
->hpos
= hpos_before_this_char
;
8406 it
->current_x
= x_before_this_char
;
8407 result
= MOVE_POS_MATCH_OR_ZV
;
8410 if (it
->line_wrap
== WORD_WRAP
8413 SAVE_IT (atpos_it
, *it
, atpos_data
);
8414 atpos_it
.current_x
= x_before_this_char
;
8415 atpos_it
.hpos
= hpos_before_this_char
;
8419 prev_method
= it
->method
;
8420 if (it
->method
== GET_FROM_BUFFER
)
8421 prev_pos
= IT_CHARPOS (*it
);
8422 set_iterator_to_next (it
, 1);
8423 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8424 SET_TEXT_POS (this_line_min_pos
,
8425 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8426 /* On graphical terminals, newlines may
8427 "overflow" into the fringe if
8428 overflow-newline-into-fringe is non-nil.
8429 On text terminals, and on graphical
8430 terminals with no right margin, newlines
8431 may overflow into the last glyph on the
8433 if (!FRAME_WINDOW_P (it
->f
)
8435 && it
->bidi_it
.paragraph_dir
== R2L
)
8436 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8437 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0
8438 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8440 if (!get_next_display_element (it
))
8442 result
= MOVE_POS_MATCH_OR_ZV
;
8445 if (BUFFER_POS_REACHED_P ())
8447 if (ITERATOR_AT_END_OF_LINE_P (it
))
8448 result
= MOVE_POS_MATCH_OR_ZV
;
8450 result
= MOVE_LINE_CONTINUED
;
8453 if (ITERATOR_AT_END_OF_LINE_P (it
))
8455 result
= MOVE_NEWLINE_OR_CR
;
8462 IT_RESET_X_ASCENT_DESCENT (it
);
8464 if (wrap_it
.sp
>= 0)
8466 RESTORE_IT (it
, &wrap_it
, wrap_data
);
8471 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
8473 result
= MOVE_LINE_CONTINUED
;
8477 if (BUFFER_POS_REACHED_P ())
8479 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8480 goto buffer_pos_reached
;
8481 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8483 SAVE_IT (atpos_it
, *it
, atpos_data
);
8484 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8488 if (new_x
> it
->first_visible_x
)
8490 /* Glyph is visible. Increment number of glyphs that
8491 would be displayed. */
8496 if (result
!= MOVE_UNDEFINED
)
8499 else if (BUFFER_POS_REACHED_P ())
8502 IT_RESET_X_ASCENT_DESCENT (it
);
8503 result
= MOVE_POS_MATCH_OR_ZV
;
8506 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
8508 /* Stop when TO_X specified and reached. This check is
8509 necessary here because of lines consisting of a line end,
8510 only. The line end will not produce any glyphs and we
8511 would never get MOVE_X_REACHED. */
8512 eassert (it
->nglyphs
== 0);
8513 result
= MOVE_X_REACHED
;
8517 /* Is this a line end? If yes, we're done. */
8518 if (ITERATOR_AT_END_OF_LINE_P (it
))
8520 /* If we are past TO_CHARPOS, but never saw any character
8521 positions smaller than TO_CHARPOS, return
8522 MOVE_POS_MATCH_OR_ZV, like the unidirectional display
8524 if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0)
8526 if (!saw_smaller_pos
&& IT_CHARPOS (*it
) > to_charpos
)
8528 if (IT_CHARPOS (ppos_it
) < ZV
)
8530 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8531 result
= MOVE_POS_MATCH_OR_ZV
;
8534 goto buffer_pos_reached
;
8536 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
>= 0
8537 && IT_CHARPOS (*it
) > to_charpos
)
8538 goto buffer_pos_reached
;
8540 result
= MOVE_NEWLINE_OR_CR
;
8543 result
= MOVE_NEWLINE_OR_CR
;
8547 prev_method
= it
->method
;
8548 if (it
->method
== GET_FROM_BUFFER
)
8549 prev_pos
= IT_CHARPOS (*it
);
8550 /* The current display element has been consumed. Advance
8552 set_iterator_to_next (it
, 1);
8553 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8554 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8555 if (IT_CHARPOS (*it
) < to_charpos
)
8556 saw_smaller_pos
= 1;
8558 && (op
& MOVE_TO_POS
)
8559 && IT_CHARPOS (*it
) >= to_charpos
8560 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8561 SAVE_IT (ppos_it
, *it
, ppos_data
);
8563 /* Stop if lines are truncated and IT's current x-position is
8564 past the right edge of the window now. */
8565 if (it
->line_wrap
== TRUNCATE
8566 && it
->current_x
>= it
->last_visible_x
)
8568 if (!FRAME_WINDOW_P (it
->f
)
8569 || ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
8570 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8571 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0
8572 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8576 if ((at_eob_p
= !get_next_display_element (it
))
8577 || BUFFER_POS_REACHED_P ()
8578 /* If we are past TO_CHARPOS, but never saw any
8579 character positions smaller than TO_CHARPOS,
8580 return MOVE_POS_MATCH_OR_ZV, like the
8581 unidirectional display did. */
8582 || (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8584 && IT_CHARPOS (*it
) > to_charpos
))
8587 && !at_eob_p
&& IT_CHARPOS (ppos_it
) < ZV
)
8588 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8589 result
= MOVE_POS_MATCH_OR_ZV
;
8592 if (ITERATOR_AT_END_OF_LINE_P (it
))
8594 result
= MOVE_NEWLINE_OR_CR
;
8598 else if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8600 && IT_CHARPOS (*it
) > to_charpos
)
8602 if (IT_CHARPOS (ppos_it
) < ZV
)
8603 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8604 result
= MOVE_POS_MATCH_OR_ZV
;
8607 result
= MOVE_LINE_TRUNCATED
;
8610 #undef IT_RESET_X_ASCENT_DESCENT
8613 #undef BUFFER_POS_REACHED_P
8615 /* If we scanned beyond to_pos and didn't find a point to wrap at,
8616 restore the saved iterator. */
8617 if (atpos_it
.sp
>= 0)
8618 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8619 else if (atx_it
.sp
>= 0)
8620 RESTORE_IT (it
, &atx_it
, atx_data
);
8625 bidi_unshelve_cache (atpos_data
, 1);
8627 bidi_unshelve_cache (atx_data
, 1);
8629 bidi_unshelve_cache (wrap_data
, 1);
8631 bidi_unshelve_cache (ppos_data
, 1);
8633 /* Restore the iterator settings altered at the beginning of this
8635 it
->glyph_row
= saved_glyph_row
;
8639 /* For external use. */
8641 move_it_in_display_line (struct it
*it
,
8642 ptrdiff_t to_charpos
, int to_x
,
8643 enum move_operation_enum op
)
8645 if (it
->line_wrap
== WORD_WRAP
8646 && (op
& MOVE_TO_X
))
8649 void *save_data
= NULL
;
8652 SAVE_IT (save_it
, *it
, save_data
);
8653 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8654 /* When word-wrap is on, TO_X may lie past the end
8655 of a wrapped line. Then it->current is the
8656 character on the next line, so backtrack to the
8657 space before the wrap point. */
8658 if (skip
== MOVE_LINE_CONTINUED
)
8660 int prev_x
= max (it
->current_x
- 1, 0);
8661 RESTORE_IT (it
, &save_it
, save_data
);
8662 move_it_in_display_line_to
8663 (it
, -1, prev_x
, MOVE_TO_X
);
8666 bidi_unshelve_cache (save_data
, 1);
8669 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8673 /* Move IT forward until it satisfies one or more of the criteria in
8674 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
8676 OP is a bit-mask that specifies where to stop, and in particular,
8677 which of those four position arguments makes a difference. See the
8678 description of enum move_operation_enum.
8680 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
8681 screen line, this function will set IT to the next position that is
8682 displayed to the right of TO_CHARPOS on the screen. */
8685 move_it_to (struct it
*it
, ptrdiff_t to_charpos
, int to_x
, int to_y
, int to_vpos
, int op
)
8687 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
8688 int line_height
, line_start_x
= 0, reached
= 0;
8689 void *backup_data
= NULL
;
8693 if (op
& MOVE_TO_VPOS
)
8695 /* If no TO_CHARPOS and no TO_X specified, stop at the
8696 start of the line TO_VPOS. */
8697 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
8699 if (it
->vpos
== to_vpos
)
8705 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
8709 /* TO_VPOS >= 0 means stop at TO_X in the line at
8710 TO_VPOS, or at TO_POS, whichever comes first. */
8711 if (it
->vpos
== to_vpos
)
8717 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8719 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
8724 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
8726 /* We have reached TO_X but not in the line we want. */
8727 skip
= move_it_in_display_line_to (it
, to_charpos
,
8729 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8737 else if (op
& MOVE_TO_Y
)
8739 struct it it_backup
;
8741 if (it
->line_wrap
== WORD_WRAP
)
8742 SAVE_IT (it_backup
, *it
, backup_data
);
8744 /* TO_Y specified means stop at TO_X in the line containing
8745 TO_Y---or at TO_CHARPOS if this is reached first. The
8746 problem is that we can't really tell whether the line
8747 contains TO_Y before we have completely scanned it, and
8748 this may skip past TO_X. What we do is to first scan to
8751 If TO_X is not specified, use a TO_X of zero. The reason
8752 is to make the outcome of this function more predictable.
8753 If we didn't use TO_X == 0, we would stop at the end of
8754 the line which is probably not what a caller would expect
8756 skip
= move_it_in_display_line_to
8757 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
8758 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
8760 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
8761 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8763 else if (skip
== MOVE_X_REACHED
)
8765 /* If TO_X was reached, we want to know whether TO_Y is
8766 in the line. We know this is the case if the already
8767 scanned glyphs make the line tall enough. Otherwise,
8768 we must check by scanning the rest of the line. */
8769 line_height
= it
->max_ascent
+ it
->max_descent
;
8770 if (to_y
>= it
->current_y
8771 && to_y
< it
->current_y
+ line_height
)
8776 SAVE_IT (it_backup
, *it
, backup_data
);
8777 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
8778 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
8780 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
8781 line_height
= it
->max_ascent
+ it
->max_descent
;
8782 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8784 if (to_y
>= it
->current_y
8785 && to_y
< it
->current_y
+ line_height
)
8787 /* If TO_Y is in this line and TO_X was reached
8788 above, we scanned too far. We have to restore
8789 IT's settings to the ones before skipping. But
8790 keep the more accurate values of max_ascent and
8791 max_descent we've found while skipping the rest
8792 of the line, for the sake of callers, such as
8793 pos_visible_p, that need to know the line
8795 int max_ascent
= it
->max_ascent
;
8796 int max_descent
= it
->max_descent
;
8798 RESTORE_IT (it
, &it_backup
, backup_data
);
8799 it
->max_ascent
= max_ascent
;
8800 it
->max_descent
= max_descent
;
8806 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8812 /* Check whether TO_Y is in this line. */
8813 line_height
= it
->max_ascent
+ it
->max_descent
;
8814 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8816 if (to_y
>= it
->current_y
8817 && to_y
< it
->current_y
+ line_height
)
8819 /* When word-wrap is on, TO_X may lie past the end
8820 of a wrapped line. Then it->current is the
8821 character on the next line, so backtrack to the
8822 space before the wrap point. */
8823 if (skip
== MOVE_LINE_CONTINUED
8824 && it
->line_wrap
== WORD_WRAP
)
8826 int prev_x
= max (it
->current_x
- 1, 0);
8827 RESTORE_IT (it
, &it_backup
, backup_data
);
8828 skip
= move_it_in_display_line_to
8829 (it
, -1, prev_x
, MOVE_TO_X
);
8838 else if (BUFFERP (it
->object
)
8839 && (it
->method
== GET_FROM_BUFFER
8840 || it
->method
== GET_FROM_STRETCH
)
8841 && IT_CHARPOS (*it
) >= to_charpos
8842 /* Under bidi iteration, a call to set_iterator_to_next
8843 can scan far beyond to_charpos if the initial
8844 portion of the next line needs to be reordered. In
8845 that case, give move_it_in_display_line_to another
8848 && it
->bidi_it
.scan_dir
== -1))
8849 skip
= MOVE_POS_MATCH_OR_ZV
;
8851 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
8855 case MOVE_POS_MATCH_OR_ZV
:
8859 case MOVE_NEWLINE_OR_CR
:
8860 set_iterator_to_next (it
, 1);
8861 it
->continuation_lines_width
= 0;
8864 case MOVE_LINE_TRUNCATED
:
8865 it
->continuation_lines_width
= 0;
8866 reseat_at_next_visible_line_start (it
, 0);
8867 if ((op
& MOVE_TO_POS
) != 0
8868 && IT_CHARPOS (*it
) > to_charpos
)
8875 case MOVE_LINE_CONTINUED
:
8876 /* For continued lines ending in a tab, some of the glyphs
8877 associated with the tab are displayed on the current
8878 line. Since it->current_x does not include these glyphs,
8879 we use it->last_visible_x instead. */
8882 it
->continuation_lines_width
+= it
->last_visible_x
;
8883 /* When moving by vpos, ensure that the iterator really
8884 advances to the next line (bug#847, bug#969). Fixme:
8885 do we need to do this in other circumstances? */
8886 if (it
->current_x
!= it
->last_visible_x
8887 && (op
& MOVE_TO_VPOS
)
8888 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
8890 line_start_x
= it
->current_x
+ it
->pixel_width
8891 - it
->last_visible_x
;
8892 set_iterator_to_next (it
, 0);
8896 it
->continuation_lines_width
+= it
->current_x
;
8903 /* Reset/increment for the next run. */
8904 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
8905 it
->current_x
= line_start_x
;
8908 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
8910 last_height
= it
->max_ascent
+ it
->max_descent
;
8911 last_max_ascent
= it
->max_ascent
;
8912 it
->max_ascent
= it
->max_descent
= 0;
8917 /* On text terminals, we may stop at the end of a line in the middle
8918 of a multi-character glyph. If the glyph itself is continued,
8919 i.e. it is actually displayed on the next line, don't treat this
8920 stopping point as valid; move to the next line instead (unless
8921 that brings us offscreen). */
8922 if (!FRAME_WINDOW_P (it
->f
)
8924 && IT_CHARPOS (*it
) == to_charpos
8925 && it
->what
== IT_CHARACTER
8927 && it
->line_wrap
== WINDOW_WRAP
8928 && it
->current_x
== it
->last_visible_x
- 1
8931 && it
->vpos
< XFASTINT (it
->w
->window_end_vpos
))
8933 it
->continuation_lines_width
+= it
->current_x
;
8934 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
8935 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
8937 last_height
= it
->max_ascent
+ it
->max_descent
;
8938 last_max_ascent
= it
->max_ascent
;
8942 bidi_unshelve_cache (backup_data
, 1);
8944 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
8948 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
8950 If DY > 0, move IT backward at least that many pixels. DY = 0
8951 means move IT backward to the preceding line start or BEGV. This
8952 function may move over more than DY pixels if IT->current_y - DY
8953 ends up in the middle of a line; in this case IT->current_y will be
8954 set to the top of the line moved to. */
8957 move_it_vertically_backward (struct it
*it
, int dy
)
8961 void *it2data
= NULL
, *it3data
= NULL
;
8962 ptrdiff_t start_pos
;
8967 start_pos
= IT_CHARPOS (*it
);
8969 /* Estimate how many newlines we must move back. */
8970 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
8972 /* Set the iterator's position that many lines back. */
8973 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
8974 back_to_previous_visible_line_start (it
);
8976 /* Reseat the iterator here. When moving backward, we don't want
8977 reseat to skip forward over invisible text, set up the iterator
8978 to deliver from overlay strings at the new position etc. So,
8979 use reseat_1 here. */
8980 reseat_1 (it
, it
->current
.pos
, 1);
8982 /* We are now surely at a line start. */
8983 it
->current_x
= it
->hpos
= 0; /* FIXME: this is incorrect when bidi
8984 reordering is in effect. */
8985 it
->continuation_lines_width
= 0;
8987 /* Move forward and see what y-distance we moved. First move to the
8988 start of the next line so that we get its height. We need this
8989 height to be able to tell whether we reached the specified
8991 SAVE_IT (it2
, *it
, it2data
);
8992 it2
.max_ascent
= it2
.max_descent
= 0;
8995 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
8996 MOVE_TO_POS
| MOVE_TO_VPOS
);
8998 while (!(IT_POS_VALID_AFTER_MOVE_P (&it2
)
8999 /* If we are in a display string which starts at START_POS,
9000 and that display string includes a newline, and we are
9001 right after that newline (i.e. at the beginning of a
9002 display line), exit the loop, because otherwise we will
9003 infloop, since move_it_to will see that it is already at
9004 START_POS and will not move. */
9005 || (it2
.method
== GET_FROM_STRING
9006 && IT_CHARPOS (it2
) == start_pos
9007 && SREF (it2
.string
, IT_STRING_BYTEPOS (it2
) - 1) == '\n')));
9008 eassert (IT_CHARPOS (*it
) >= BEGV
);
9009 SAVE_IT (it3
, it2
, it3data
);
9011 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
9012 eassert (IT_CHARPOS (*it
) >= BEGV
);
9013 /* H is the actual vertical distance from the position in *IT
9014 and the starting position. */
9015 h
= it2
.current_y
- it
->current_y
;
9016 /* NLINES is the distance in number of lines. */
9017 nlines
= it2
.vpos
- it
->vpos
;
9019 /* Correct IT's y and vpos position
9020 so that they are relative to the starting point. */
9026 /* DY == 0 means move to the start of the screen line. The
9027 value of nlines is > 0 if continuation lines were involved,
9028 or if the original IT position was at start of a line. */
9029 RESTORE_IT (it
, it
, it2data
);
9031 move_it_by_lines (it
, nlines
);
9032 /* The above code moves us to some position NLINES down,
9033 usually to its first glyph (leftmost in an L2R line), but
9034 that's not necessarily the start of the line, under bidi
9035 reordering. We want to get to the character position
9036 that is immediately after the newline of the previous
9039 && !it
->continuation_lines_width
9040 && !STRINGP (it
->string
)
9041 && IT_CHARPOS (*it
) > BEGV
9042 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9045 find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
9047 move_it_to (it
, nl_pos
, -1, -1, -1, MOVE_TO_POS
);
9049 bidi_unshelve_cache (it3data
, 1);
9053 /* The y-position we try to reach, relative to *IT.
9054 Note that H has been subtracted in front of the if-statement. */
9055 int target_y
= it
->current_y
+ h
- dy
;
9056 int y0
= it3
.current_y
;
9060 RESTORE_IT (&it3
, &it3
, it3data
);
9061 y1
= line_bottom_y (&it3
);
9062 line_height
= y1
- y0
;
9063 RESTORE_IT (it
, it
, it2data
);
9064 /* If we did not reach target_y, try to move further backward if
9065 we can. If we moved too far backward, try to move forward. */
9066 if (target_y
< it
->current_y
9067 /* This is heuristic. In a window that's 3 lines high, with
9068 a line height of 13 pixels each, recentering with point
9069 on the bottom line will try to move -39/2 = 19 pixels
9070 backward. Try to avoid moving into the first line. */
9071 && (it
->current_y
- target_y
9072 > min (window_box_height (it
->w
), line_height
* 2 / 3))
9073 && IT_CHARPOS (*it
) > BEGV
)
9075 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
9076 target_y
- it
->current_y
));
9077 dy
= it
->current_y
- target_y
;
9078 goto move_further_back
;
9080 else if (target_y
>= it
->current_y
+ line_height
9081 && IT_CHARPOS (*it
) < ZV
)
9083 /* Should move forward by at least one line, maybe more.
9085 Note: Calling move_it_by_lines can be expensive on
9086 terminal frames, where compute_motion is used (via
9087 vmotion) to do the job, when there are very long lines
9088 and truncate-lines is nil. That's the reason for
9089 treating terminal frames specially here. */
9091 if (!FRAME_WINDOW_P (it
->f
))
9092 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
9097 move_it_by_lines (it
, 1);
9099 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
9106 /* Move IT by a specified amount of pixel lines DY. DY negative means
9107 move backwards. DY = 0 means move to start of screen line. At the
9108 end, IT will be on the start of a screen line. */
9111 move_it_vertically (struct it
*it
, int dy
)
9114 move_it_vertically_backward (it
, -dy
);
9117 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
9118 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
9119 MOVE_TO_POS
| MOVE_TO_Y
);
9120 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
9122 /* If buffer ends in ZV without a newline, move to the start of
9123 the line to satisfy the post-condition. */
9124 if (IT_CHARPOS (*it
) == ZV
9126 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9127 move_it_by_lines (it
, 0);
9132 /* Move iterator IT past the end of the text line it is in. */
9135 move_it_past_eol (struct it
*it
)
9137 enum move_it_result rc
;
9139 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
9140 if (rc
== MOVE_NEWLINE_OR_CR
)
9141 set_iterator_to_next (it
, 0);
9145 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
9146 negative means move up. DVPOS == 0 means move to the start of the
9149 Optimization idea: If we would know that IT->f doesn't use
9150 a face with proportional font, we could be faster for
9151 truncate-lines nil. */
9154 move_it_by_lines (struct it
*it
, ptrdiff_t dvpos
)
9157 /* The commented-out optimization uses vmotion on terminals. This
9158 gives bad results, because elements like it->what, on which
9159 callers such as pos_visible_p rely, aren't updated. */
9160 /* struct position pos;
9161 if (!FRAME_WINDOW_P (it->f))
9163 struct text_pos textpos;
9165 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
9166 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
9167 reseat (it, textpos, 1);
9168 it->vpos += pos.vpos;
9169 it->current_y += pos.vpos;
9175 /* DVPOS == 0 means move to the start of the screen line. */
9176 move_it_vertically_backward (it
, 0);
9177 /* Let next call to line_bottom_y calculate real line height */
9182 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
9183 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
9185 /* Only move to the next buffer position if we ended up in a
9186 string from display property, not in an overlay string
9187 (before-string or after-string). That is because the
9188 latter don't conceal the underlying buffer position, so
9189 we can ask to move the iterator to the exact position we
9190 are interested in. Note that, even if we are already at
9191 IT_CHARPOS (*it), the call below is not a no-op, as it
9192 will detect that we are at the end of the string, pop the
9193 iterator, and compute it->current_x and it->hpos
9195 move_it_to (it
, IT_CHARPOS (*it
) + it
->string_from_display_prop_p
,
9196 -1, -1, -1, MOVE_TO_POS
);
9202 void *it2data
= NULL
;
9203 ptrdiff_t start_charpos
, i
;
9205 /* Start at the beginning of the screen line containing IT's
9206 position. This may actually move vertically backwards,
9207 in case of overlays, so adjust dvpos accordingly. */
9209 move_it_vertically_backward (it
, 0);
9212 /* Go back -DVPOS visible lines and reseat the iterator there. */
9213 start_charpos
= IT_CHARPOS (*it
);
9214 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
9215 back_to_previous_visible_line_start (it
);
9216 reseat (it
, it
->current
.pos
, 1);
9218 /* Move further back if we end up in a string or an image. */
9219 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
9221 /* First try to move to start of display line. */
9223 move_it_vertically_backward (it
, 0);
9225 if (IT_POS_VALID_AFTER_MOVE_P (it
))
9227 /* If start of line is still in string or image,
9228 move further back. */
9229 back_to_previous_visible_line_start (it
);
9230 reseat (it
, it
->current
.pos
, 1);
9234 it
->current_x
= it
->hpos
= 0;
9236 /* Above call may have moved too far if continuation lines
9237 are involved. Scan forward and see if it did. */
9238 SAVE_IT (it2
, *it
, it2data
);
9239 it2
.vpos
= it2
.current_y
= 0;
9240 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
9241 it
->vpos
-= it2
.vpos
;
9242 it
->current_y
-= it2
.current_y
;
9243 it
->current_x
= it
->hpos
= 0;
9245 /* If we moved too far back, move IT some lines forward. */
9246 if (it2
.vpos
> -dvpos
)
9248 int delta
= it2
.vpos
+ dvpos
;
9250 RESTORE_IT (&it2
, &it2
, it2data
);
9251 SAVE_IT (it2
, *it
, it2data
);
9252 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
9253 /* Move back again if we got too far ahead. */
9254 if (IT_CHARPOS (*it
) >= start_charpos
)
9255 RESTORE_IT (it
, &it2
, it2data
);
9257 bidi_unshelve_cache (it2data
, 1);
9260 RESTORE_IT (it
, it
, it2data
);
9264 /* Return 1 if IT points into the middle of a display vector. */
9267 in_display_vector_p (struct it
*it
)
9269 return (it
->method
== GET_FROM_DISPLAY_VECTOR
9270 && it
->current
.dpvec_index
> 0
9271 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
9275 /***********************************************************************
9277 ***********************************************************************/
9280 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
9284 add_to_log (const char *format
, Lisp_Object arg1
, Lisp_Object arg2
)
9286 Lisp_Object args
[3];
9287 Lisp_Object msg
, fmt
;
9290 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
9293 /* Do nothing if called asynchronously. Inserting text into
9294 a buffer may call after-change-functions and alike and
9295 that would means running Lisp asynchronously. */
9296 if (handling_signal
)
9300 GCPRO4 (fmt
, msg
, arg1
, arg2
);
9302 args
[0] = fmt
= build_string (format
);
9305 msg
= Fformat (3, args
);
9307 len
= SBYTES (msg
) + 1;
9308 buffer
= SAFE_ALLOCA (len
);
9309 memcpy (buffer
, SDATA (msg
), len
);
9311 message_dolog (buffer
, len
- 1, 1, 0);
9318 /* Output a newline in the *Messages* buffer if "needs" one. */
9321 message_log_maybe_newline (void)
9323 if (message_log_need_newline
)
9324 message_dolog ("", 0, 1, 0);
9328 /* Add a string M of length NBYTES to the message log, optionally
9329 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
9330 nonzero, means interpret the contents of M as multibyte. This
9331 function calls low-level routines in order to bypass text property
9332 hooks, etc. which might not be safe to run.
9334 This may GC (insert may run before/after change hooks),
9335 so the buffer M must NOT point to a Lisp string. */
9338 message_dolog (const char *m
, ptrdiff_t nbytes
, int nlflag
, int multibyte
)
9340 const unsigned char *msg
= (const unsigned char *) m
;
9342 if (!NILP (Vmemory_full
))
9345 if (!NILP (Vmessage_log_max
))
9347 struct buffer
*oldbuf
;
9348 Lisp_Object oldpoint
, oldbegv
, oldzv
;
9349 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
9350 ptrdiff_t point_at_end
= 0;
9351 ptrdiff_t zv_at_end
= 0;
9352 Lisp_Object old_deactivate_mark
, tem
;
9353 struct gcpro gcpro1
;
9355 old_deactivate_mark
= Vdeactivate_mark
;
9356 oldbuf
= current_buffer
;
9357 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
9358 bset_undo_list (current_buffer
, Qt
);
9360 oldpoint
= message_dolog_marker1
;
9361 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
9362 oldbegv
= message_dolog_marker2
;
9363 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
9364 oldzv
= message_dolog_marker3
;
9365 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
9366 GCPRO1 (old_deactivate_mark
);
9374 BEGV_BYTE
= BEG_BYTE
;
9377 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9379 /* Insert the string--maybe converting multibyte to single byte
9380 or vice versa, so that all the text fits the buffer. */
9382 && NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9388 /* Convert a multibyte string to single-byte
9389 for the *Message* buffer. */
9390 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
9392 c
= string_char_and_length (msg
+ i
, &char_bytes
);
9393 work
[0] = (ASCII_CHAR_P (c
)
9395 : multibyte_char_to_unibyte (c
));
9396 insert_1_both (work
, 1, 1, 1, 0, 0);
9399 else if (! multibyte
9400 && ! NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9404 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9405 /* Convert a single-byte string to multibyte
9406 for the *Message* buffer. */
9407 for (i
= 0; i
< nbytes
; i
++)
9410 MAKE_CHAR_MULTIBYTE (c
);
9411 char_bytes
= CHAR_STRING (c
, str
);
9412 insert_1_both ((char *) str
, 1, char_bytes
, 1, 0, 0);
9416 insert_1 (m
, nbytes
, 1, 0, 0);
9420 ptrdiff_t this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
;
9422 insert_1 ("\n", 1, 1, 0, 0);
9424 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9426 this_bol_byte
= PT_BYTE
;
9428 /* See if this line duplicates the previous one.
9429 If so, combine duplicates. */
9432 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9434 prev_bol_byte
= PT_BYTE
;
9436 dups
= message_log_check_duplicate (prev_bol_byte
,
9440 del_range_both (prev_bol
, prev_bol_byte
,
9441 this_bol
, this_bol_byte
, 0);
9444 char dupstr
[sizeof " [ times]"
9445 + INT_STRLEN_BOUND (printmax_t
)];
9447 /* If you change this format, don't forget to also
9448 change message_log_check_duplicate. */
9449 int duplen
= sprintf (dupstr
, " [%"pMd
" times]", dups
);
9450 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
9451 insert_1 (dupstr
, duplen
, 1, 0, 1);
9456 /* If we have more than the desired maximum number of lines
9457 in the *Messages* buffer now, delete the oldest ones.
9458 This is safe because we don't have undo in this buffer. */
9460 if (NATNUMP (Vmessage_log_max
))
9462 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
9463 -XFASTINT (Vmessage_log_max
) - 1, 0);
9464 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
9467 BEGV
= XMARKER (oldbegv
)->charpos
;
9468 BEGV_BYTE
= marker_byte_position (oldbegv
);
9477 ZV
= XMARKER (oldzv
)->charpos
;
9478 ZV_BYTE
= marker_byte_position (oldzv
);
9482 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9484 /* We can't do Fgoto_char (oldpoint) because it will run some
9486 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
9487 XMARKER (oldpoint
)->bytepos
);
9490 unchain_marker (XMARKER (oldpoint
));
9491 unchain_marker (XMARKER (oldbegv
));
9492 unchain_marker (XMARKER (oldzv
));
9494 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
9495 set_buffer_internal (oldbuf
);
9497 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
9498 message_log_need_newline
= !nlflag
;
9499 Vdeactivate_mark
= old_deactivate_mark
;
9504 /* We are at the end of the buffer after just having inserted a newline.
9505 (Note: We depend on the fact we won't be crossing the gap.)
9506 Check to see if the most recent message looks a lot like the previous one.
9507 Return 0 if different, 1 if the new one should just replace it, or a
9508 value N > 1 if we should also append " [N times]". */
9511 message_log_check_duplicate (ptrdiff_t prev_bol_byte
, ptrdiff_t this_bol_byte
)
9514 ptrdiff_t len
= Z_BYTE
- 1 - this_bol_byte
;
9516 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
9517 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
9519 for (i
= 0; i
< len
; i
++)
9521 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
9529 if (*p1
++ == ' ' && *p1
++ == '[')
9532 intmax_t n
= strtoimax ((char *) p1
, &pend
, 10);
9533 if (0 < n
&& n
< INTMAX_MAX
&& strncmp (pend
, " times]\n", 8) == 0)
9540 /* Display an echo area message M with a specified length of NBYTES
9541 bytes. The string may include null characters. If M is 0, clear
9542 out any existing message, and let the mini-buffer text show
9545 This may GC, so the buffer M must NOT point to a Lisp string. */
9548 message2 (const char *m
, ptrdiff_t nbytes
, int multibyte
)
9550 /* First flush out any partial line written with print. */
9551 message_log_maybe_newline ();
9553 message_dolog (m
, nbytes
, 1, multibyte
);
9554 message2_nolog (m
, nbytes
, multibyte
);
9558 /* The non-logging counterpart of message2. */
9561 message2_nolog (const char *m
, ptrdiff_t nbytes
, int multibyte
)
9563 struct frame
*sf
= SELECTED_FRAME ();
9564 message_enable_multibyte
= multibyte
;
9566 if (FRAME_INITIAL_P (sf
))
9568 if (noninteractive_need_newline
)
9569 putc ('\n', stderr
);
9570 noninteractive_need_newline
= 0;
9572 fwrite (m
, nbytes
, 1, stderr
);
9573 if (cursor_in_echo_area
== 0)
9574 fprintf (stderr
, "\n");
9577 /* A null message buffer means that the frame hasn't really been
9578 initialized yet. Error messages get reported properly by
9579 cmd_error, so this must be just an informative message; toss it. */
9580 else if (INTERACTIVE
9581 && sf
->glyphs_initialized_p
9582 && FRAME_MESSAGE_BUF (sf
))
9584 Lisp_Object mini_window
;
9587 /* Get the frame containing the mini-buffer
9588 that the selected frame is using. */
9589 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9590 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9592 FRAME_SAMPLE_VISIBILITY (f
);
9593 if (FRAME_VISIBLE_P (sf
)
9594 && ! FRAME_VISIBLE_P (f
))
9595 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
9599 set_message (m
, Qnil
, nbytes
, multibyte
);
9600 if (minibuffer_auto_raise
)
9601 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
9604 clear_message (1, 1);
9606 do_pending_window_change (0);
9607 echo_area_display (1);
9608 do_pending_window_change (0);
9609 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
9610 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
9615 /* Display an echo area message M with a specified length of NBYTES
9616 bytes. The string may include null characters. If M is not a
9617 string, clear out any existing message, and let the mini-buffer
9620 This function cancels echoing. */
9623 message3 (Lisp_Object m
, ptrdiff_t nbytes
, int multibyte
)
9625 struct gcpro gcpro1
;
9628 clear_message (1,1);
9631 /* First flush out any partial line written with print. */
9632 message_log_maybe_newline ();
9636 char *buffer
= SAFE_ALLOCA (nbytes
);
9637 memcpy (buffer
, SDATA (m
), nbytes
);
9638 message_dolog (buffer
, nbytes
, 1, multibyte
);
9641 message3_nolog (m
, nbytes
, multibyte
);
9647 /* The non-logging version of message3.
9648 This does not cancel echoing, because it is used for echoing.
9649 Perhaps we need to make a separate function for echoing
9650 and make this cancel echoing. */
9653 message3_nolog (Lisp_Object m
, ptrdiff_t nbytes
, int multibyte
)
9655 struct frame
*sf
= SELECTED_FRAME ();
9656 message_enable_multibyte
= multibyte
;
9658 if (FRAME_INITIAL_P (sf
))
9660 if (noninteractive_need_newline
)
9661 putc ('\n', stderr
);
9662 noninteractive_need_newline
= 0;
9664 fwrite (SDATA (m
), nbytes
, 1, stderr
);
9665 if (cursor_in_echo_area
== 0)
9666 fprintf (stderr
, "\n");
9669 /* A null message buffer means that the frame hasn't really been
9670 initialized yet. Error messages get reported properly by
9671 cmd_error, so this must be just an informative message; toss it. */
9672 else if (INTERACTIVE
9673 && sf
->glyphs_initialized_p
9674 && FRAME_MESSAGE_BUF (sf
))
9676 Lisp_Object mini_window
;
9680 /* Get the frame containing the mini-buffer
9681 that the selected frame is using. */
9682 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9683 frame
= XWINDOW (mini_window
)->frame
;
9686 FRAME_SAMPLE_VISIBILITY (f
);
9687 if (FRAME_VISIBLE_P (sf
)
9688 && !FRAME_VISIBLE_P (f
))
9689 Fmake_frame_visible (frame
);
9691 if (STRINGP (m
) && SCHARS (m
) > 0)
9693 set_message (NULL
, m
, nbytes
, multibyte
);
9694 if (minibuffer_auto_raise
)
9695 Fraise_frame (frame
);
9696 /* Assume we are not echoing.
9697 (If we are, echo_now will override this.) */
9698 echo_message_buffer
= Qnil
;
9701 clear_message (1, 1);
9703 do_pending_window_change (0);
9704 echo_area_display (1);
9705 do_pending_window_change (0);
9706 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
9707 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
9712 /* Display a null-terminated echo area message M. If M is 0, clear
9713 out any existing message, and let the mini-buffer text show through.
9715 The buffer M must continue to exist until after the echo area gets
9716 cleared or some other message gets displayed there. Do not pass
9717 text that is stored in a Lisp string. Do not pass text in a buffer
9718 that was alloca'd. */
9721 message1 (const char *m
)
9723 message2 (m
, (m
? strlen (m
) : 0), 0);
9727 /* The non-logging counterpart of message1. */
9730 message1_nolog (const char *m
)
9732 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
9735 /* Display a message M which contains a single %s
9736 which gets replaced with STRING. */
9739 message_with_string (const char *m
, Lisp_Object string
, int log
)
9741 CHECK_STRING (string
);
9747 if (noninteractive_need_newline
)
9748 putc ('\n', stderr
);
9749 noninteractive_need_newline
= 0;
9750 fprintf (stderr
, m
, SDATA (string
));
9751 if (!cursor_in_echo_area
)
9752 fprintf (stderr
, "\n");
9756 else if (INTERACTIVE
)
9758 /* The frame whose minibuffer we're going to display the message on.
9759 It may be larger than the selected frame, so we need
9760 to use its buffer, not the selected frame's buffer. */
9761 Lisp_Object mini_window
;
9762 struct frame
*f
, *sf
= SELECTED_FRAME ();
9764 /* Get the frame containing the minibuffer
9765 that the selected frame is using. */
9766 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9767 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9769 /* A null message buffer means that the frame hasn't really been
9770 initialized yet. Error messages get reported properly by
9771 cmd_error, so this must be just an informative message; toss it. */
9772 if (FRAME_MESSAGE_BUF (f
))
9774 Lisp_Object args
[2], msg
;
9775 struct gcpro gcpro1
, gcpro2
;
9777 args
[0] = build_string (m
);
9778 args
[1] = msg
= string
;
9779 GCPRO2 (args
[0], msg
);
9782 msg
= Fformat (2, args
);
9785 message3 (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
9787 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
9791 /* Print should start at the beginning of the message
9792 buffer next time. */
9793 message_buf_print
= 0;
9799 /* Dump an informative message to the minibuf. If M is 0, clear out
9800 any existing message, and let the mini-buffer text show through. */
9803 vmessage (const char *m
, va_list ap
)
9809 if (noninteractive_need_newline
)
9810 putc ('\n', stderr
);
9811 noninteractive_need_newline
= 0;
9812 vfprintf (stderr
, m
, ap
);
9813 if (cursor_in_echo_area
== 0)
9814 fprintf (stderr
, "\n");
9818 else if (INTERACTIVE
)
9820 /* The frame whose mini-buffer we're going to display the message
9821 on. It may be larger than the selected frame, so we need to
9822 use its buffer, not the selected frame's buffer. */
9823 Lisp_Object mini_window
;
9824 struct frame
*f
, *sf
= SELECTED_FRAME ();
9826 /* Get the frame containing the mini-buffer
9827 that the selected frame is using. */
9828 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9829 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9831 /* A null message buffer means that the frame hasn't really been
9832 initialized yet. Error messages get reported properly by
9833 cmd_error, so this must be just an informative message; toss
9835 if (FRAME_MESSAGE_BUF (f
))
9841 len
= doprnt (FRAME_MESSAGE_BUF (f
),
9842 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, ap
);
9844 message2 (FRAME_MESSAGE_BUF (f
), len
, 1);
9849 /* Print should start at the beginning of the message
9850 buffer next time. */
9851 message_buf_print
= 0;
9857 message (const char *m
, ...)
9867 /* The non-logging version of message. */
9870 message_nolog (const char *m
, ...)
9872 Lisp_Object old_log_max
;
9875 old_log_max
= Vmessage_log_max
;
9876 Vmessage_log_max
= Qnil
;
9878 Vmessage_log_max
= old_log_max
;
9884 /* Display the current message in the current mini-buffer. This is
9885 only called from error handlers in process.c, and is not time
9889 update_echo_area (void)
9891 if (!NILP (echo_area_buffer
[0]))
9894 string
= Fcurrent_message ();
9895 message3 (string
, SBYTES (string
),
9896 !NILP (BVAR (current_buffer
, enable_multibyte_characters
)));
9901 /* Make sure echo area buffers in `echo_buffers' are live.
9902 If they aren't, make new ones. */
9905 ensure_echo_area_buffers (void)
9909 for (i
= 0; i
< 2; ++i
)
9910 if (!BUFFERP (echo_buffer
[i
])
9911 || !BUFFER_LIVE_P (XBUFFER (echo_buffer
[i
])))
9914 Lisp_Object old_buffer
;
9917 old_buffer
= echo_buffer
[i
];
9918 echo_buffer
[i
] = Fget_buffer_create
9919 (make_formatted_string (name
, " *Echo Area %d*", i
));
9920 bset_truncate_lines (XBUFFER (echo_buffer
[i
]), Qnil
);
9921 /* to force word wrap in echo area -
9922 it was decided to postpone this*/
9923 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
9925 for (j
= 0; j
< 2; ++j
)
9926 if (EQ (old_buffer
, echo_area_buffer
[j
]))
9927 echo_area_buffer
[j
] = echo_buffer
[i
];
9932 /* Call FN with args A1..A4 with either the current or last displayed
9933 echo_area_buffer as current buffer.
9935 WHICH zero means use the current message buffer
9936 echo_area_buffer[0]. If that is nil, choose a suitable buffer
9937 from echo_buffer[] and clear it.
9939 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
9940 suitable buffer from echo_buffer[] and clear it.
9942 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
9943 that the current message becomes the last displayed one, make
9944 choose a suitable buffer for echo_area_buffer[0], and clear it.
9946 Value is what FN returns. */
9949 with_echo_area_buffer (struct window
*w
, int which
,
9950 int (*fn
) (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t),
9951 ptrdiff_t a1
, Lisp_Object a2
, ptrdiff_t a3
, ptrdiff_t a4
)
9954 int this_one
, the_other
, clear_buffer_p
, rc
;
9955 ptrdiff_t count
= SPECPDL_INDEX ();
9957 /* If buffers aren't live, make new ones. */
9958 ensure_echo_area_buffers ();
9963 this_one
= 0, the_other
= 1;
9965 this_one
= 1, the_other
= 0;
9968 this_one
= 0, the_other
= 1;
9971 /* We need a fresh one in case the current echo buffer equals
9972 the one containing the last displayed echo area message. */
9973 if (!NILP (echo_area_buffer
[this_one
])
9974 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
9975 echo_area_buffer
[this_one
] = Qnil
;
9978 /* Choose a suitable buffer from echo_buffer[] is we don't
9980 if (NILP (echo_area_buffer
[this_one
]))
9982 echo_area_buffer
[this_one
]
9983 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
9984 ? echo_buffer
[the_other
]
9985 : echo_buffer
[this_one
]);
9989 buffer
= echo_area_buffer
[this_one
];
9991 /* Don't get confused by reusing the buffer used for echoing
9992 for a different purpose. */
9993 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
9996 record_unwind_protect (unwind_with_echo_area_buffer
,
9997 with_echo_area_buffer_unwind_data (w
));
9999 /* Make the echo area buffer current. Note that for display
10000 purposes, it is not necessary that the displayed window's buffer
10001 == current_buffer, except for text property lookup. So, let's
10002 only set that buffer temporarily here without doing a full
10003 Fset_window_buffer. We must also change w->pointm, though,
10004 because otherwise an assertions in unshow_buffer fails, and Emacs
10006 set_buffer_internal_1 (XBUFFER (buffer
));
10009 wset_buffer (w
, buffer
);
10010 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
10013 bset_undo_list (current_buffer
, Qt
);
10014 bset_read_only (current_buffer
, Qnil
);
10015 specbind (Qinhibit_read_only
, Qt
);
10016 specbind (Qinhibit_modification_hooks
, Qt
);
10018 if (clear_buffer_p
&& Z
> BEG
)
10019 del_range (BEG
, Z
);
10021 eassert (BEGV
>= BEG
);
10022 eassert (ZV
<= Z
&& ZV
>= BEGV
);
10024 rc
= fn (a1
, a2
, a3
, a4
);
10026 eassert (BEGV
>= BEG
);
10027 eassert (ZV
<= Z
&& ZV
>= BEGV
);
10029 unbind_to (count
, Qnil
);
10034 /* Save state that should be preserved around the call to the function
10035 FN called in with_echo_area_buffer. */
10038 with_echo_area_buffer_unwind_data (struct window
*w
)
10041 Lisp_Object vector
, tmp
;
10043 /* Reduce consing by keeping one vector in
10044 Vwith_echo_area_save_vector. */
10045 vector
= Vwith_echo_area_save_vector
;
10046 Vwith_echo_area_save_vector
= Qnil
;
10049 vector
= Fmake_vector (make_number (7), Qnil
);
10051 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
10052 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
10053 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
10057 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
10058 ASET (vector
, i
, w
->buffer
); ++i
;
10059 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->charpos
)); ++i
;
10060 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->bytepos
)); ++i
;
10065 for (; i
< end
; ++i
)
10066 ASET (vector
, i
, Qnil
);
10069 eassert (i
== ASIZE (vector
));
10074 /* Restore global state from VECTOR which was created by
10075 with_echo_area_buffer_unwind_data. */
10078 unwind_with_echo_area_buffer (Lisp_Object vector
)
10080 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
10081 Vdeactivate_mark
= AREF (vector
, 1);
10082 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
10084 if (WINDOWP (AREF (vector
, 3)))
10087 Lisp_Object buffer
, charpos
, bytepos
;
10089 w
= XWINDOW (AREF (vector
, 3));
10090 buffer
= AREF (vector
, 4);
10091 charpos
= AREF (vector
, 5);
10092 bytepos
= AREF (vector
, 6);
10094 wset_buffer (w
, buffer
);
10095 set_marker_both (w
->pointm
, buffer
,
10096 XFASTINT (charpos
), XFASTINT (bytepos
));
10099 Vwith_echo_area_save_vector
= vector
;
10104 /* Set up the echo area for use by print functions. MULTIBYTE_P
10105 non-zero means we will print multibyte. */
10108 setup_echo_area_for_printing (int multibyte_p
)
10110 /* If we can't find an echo area any more, exit. */
10111 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
10112 Fkill_emacs (Qnil
);
10114 ensure_echo_area_buffers ();
10116 if (!message_buf_print
)
10118 /* A message has been output since the last time we printed.
10119 Choose a fresh echo area buffer. */
10120 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10121 echo_area_buffer
[0] = echo_buffer
[1];
10123 echo_area_buffer
[0] = echo_buffer
[0];
10125 /* Switch to that buffer and clear it. */
10126 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10127 bset_truncate_lines (current_buffer
, Qnil
);
10131 ptrdiff_t count
= SPECPDL_INDEX ();
10132 specbind (Qinhibit_read_only
, Qt
);
10133 /* Note that undo recording is always disabled. */
10134 del_range (BEG
, Z
);
10135 unbind_to (count
, Qnil
);
10137 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10139 /* Set up the buffer for the multibyteness we need. */
10141 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10142 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
10144 /* Raise the frame containing the echo area. */
10145 if (minibuffer_auto_raise
)
10147 struct frame
*sf
= SELECTED_FRAME ();
10148 Lisp_Object mini_window
;
10149 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10150 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
10153 message_log_maybe_newline ();
10154 message_buf_print
= 1;
10158 if (NILP (echo_area_buffer
[0]))
10160 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10161 echo_area_buffer
[0] = echo_buffer
[1];
10163 echo_area_buffer
[0] = echo_buffer
[0];
10166 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
10168 /* Someone switched buffers between print requests. */
10169 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10170 bset_truncate_lines (current_buffer
, Qnil
);
10176 /* Display an echo area message in window W. Value is non-zero if W's
10177 height is changed. If display_last_displayed_message_p is
10178 non-zero, display the message that was last displayed, otherwise
10179 display the current message. */
10182 display_echo_area (struct window
*w
)
10184 int i
, no_message_p
, window_height_changed_p
;
10186 /* Temporarily disable garbage collections while displaying the echo
10187 area. This is done because a GC can print a message itself.
10188 That message would modify the echo area buffer's contents while a
10189 redisplay of the buffer is going on, and seriously confuse
10191 ptrdiff_t count
= inhibit_garbage_collection ();
10193 /* If there is no message, we must call display_echo_area_1
10194 nevertheless because it resizes the window. But we will have to
10195 reset the echo_area_buffer in question to nil at the end because
10196 with_echo_area_buffer will sets it to an empty buffer. */
10197 i
= display_last_displayed_message_p
? 1 : 0;
10198 no_message_p
= NILP (echo_area_buffer
[i
]);
10200 window_height_changed_p
10201 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
10202 display_echo_area_1
,
10203 (intptr_t) w
, Qnil
, 0, 0);
10206 echo_area_buffer
[i
] = Qnil
;
10208 unbind_to (count
, Qnil
);
10209 return window_height_changed_p
;
10213 /* Helper for display_echo_area. Display the current buffer which
10214 contains the current echo area message in window W, a mini-window,
10215 a pointer to which is passed in A1. A2..A4 are currently not used.
10216 Change the height of W so that all of the message is displayed.
10217 Value is non-zero if height of W was changed. */
10220 display_echo_area_1 (ptrdiff_t a1
, Lisp_Object a2
, ptrdiff_t a3
, ptrdiff_t a4
)
10223 struct window
*w
= (struct window
*) i1
;
10224 Lisp_Object window
;
10225 struct text_pos start
;
10226 int window_height_changed_p
= 0;
10228 /* Do this before displaying, so that we have a large enough glyph
10229 matrix for the display. If we can't get enough space for the
10230 whole text, display the last N lines. That works by setting w->start. */
10231 window_height_changed_p
= resize_mini_window (w
, 0);
10233 /* Use the starting position chosen by resize_mini_window. */
10234 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
10237 clear_glyph_matrix (w
->desired_matrix
);
10238 XSETWINDOW (window
, w
);
10239 try_window (window
, start
, 0);
10241 return window_height_changed_p
;
10245 /* Resize the echo area window to exactly the size needed for the
10246 currently displayed message, if there is one. If a mini-buffer
10247 is active, don't shrink it. */
10250 resize_echo_area_exactly (void)
10252 if (BUFFERP (echo_area_buffer
[0])
10253 && WINDOWP (echo_area_window
))
10255 struct window
*w
= XWINDOW (echo_area_window
);
10257 Lisp_Object resize_exactly
;
10259 if (minibuf_level
== 0)
10260 resize_exactly
= Qt
;
10262 resize_exactly
= Qnil
;
10264 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
10265 (intptr_t) w
, resize_exactly
,
10269 ++windows_or_buffers_changed
;
10270 ++update_mode_lines
;
10271 redisplay_internal ();
10277 /* Callback function for with_echo_area_buffer, when used from
10278 resize_echo_area_exactly. A1 contains a pointer to the window to
10279 resize, EXACTLY non-nil means resize the mini-window exactly to the
10280 size of the text displayed. A3 and A4 are not used. Value is what
10281 resize_mini_window returns. */
10284 resize_mini_window_1 (ptrdiff_t a1
, Lisp_Object exactly
, ptrdiff_t a3
, ptrdiff_t a4
)
10287 return resize_mini_window ((struct window
*) i1
, !NILP (exactly
));
10291 /* Resize mini-window W to fit the size of its contents. EXACT_P
10292 means size the window exactly to the size needed. Otherwise, it's
10293 only enlarged until W's buffer is empty.
10295 Set W->start to the right place to begin display. If the whole
10296 contents fit, start at the beginning. Otherwise, start so as
10297 to make the end of the contents appear. This is particularly
10298 important for y-or-n-p, but seems desirable generally.
10300 Value is non-zero if the window height has been changed. */
10303 resize_mini_window (struct window
*w
, int exact_p
)
10305 struct frame
*f
= XFRAME (w
->frame
);
10306 int window_height_changed_p
= 0;
10308 eassert (MINI_WINDOW_P (w
));
10310 /* By default, start display at the beginning. */
10311 set_marker_both (w
->start
, w
->buffer
,
10312 BUF_BEGV (XBUFFER (w
->buffer
)),
10313 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
10315 /* Don't resize windows while redisplaying a window; it would
10316 confuse redisplay functions when the size of the window they are
10317 displaying changes from under them. Such a resizing can happen,
10318 for instance, when which-func prints a long message while
10319 we are running fontification-functions. We're running these
10320 functions with safe_call which binds inhibit-redisplay to t. */
10321 if (!NILP (Vinhibit_redisplay
))
10324 /* Nil means don't try to resize. */
10325 if (NILP (Vresize_mini_windows
)
10326 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
10329 if (!FRAME_MINIBUF_ONLY_P (f
))
10332 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
10333 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
10335 EMACS_INT max_height
;
10336 int unit
= FRAME_LINE_HEIGHT (f
);
10337 struct text_pos start
;
10338 struct buffer
*old_current_buffer
= NULL
;
10340 if (current_buffer
!= XBUFFER (w
->buffer
))
10342 old_current_buffer
= current_buffer
;
10343 set_buffer_internal (XBUFFER (w
->buffer
));
10346 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10348 /* Compute the max. number of lines specified by the user. */
10349 if (FLOATP (Vmax_mini_window_height
))
10350 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
10351 else if (INTEGERP (Vmax_mini_window_height
))
10352 max_height
= XINT (Vmax_mini_window_height
);
10354 max_height
= total_height
/ 4;
10356 /* Correct that max. height if it's bogus. */
10357 max_height
= max (1, max_height
);
10358 max_height
= min (total_height
, max_height
);
10360 /* Find out the height of the text in the window. */
10361 if (it
.line_wrap
== TRUNCATE
)
10366 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
10367 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
10368 height
= it
.current_y
+ last_height
;
10370 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
10371 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
10372 height
= (height
+ unit
- 1) / unit
;
10375 /* Compute a suitable window start. */
10376 if (height
> max_height
)
10378 height
= max_height
;
10379 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10380 move_it_vertically_backward (&it
, (height
- 1) * unit
);
10381 start
= it
.current
.pos
;
10384 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
10385 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
10387 if (EQ (Vresize_mini_windows
, Qgrow_only
))
10389 /* Let it grow only, until we display an empty message, in which
10390 case the window shrinks again. */
10391 if (height
> WINDOW_TOTAL_LINES (w
))
10393 int old_height
= WINDOW_TOTAL_LINES (w
);
10394 freeze_window_starts (f
, 1);
10395 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10396 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10398 else if (height
< WINDOW_TOTAL_LINES (w
)
10399 && (exact_p
|| BEGV
== ZV
))
10401 int old_height
= WINDOW_TOTAL_LINES (w
);
10402 freeze_window_starts (f
, 0);
10403 shrink_mini_window (w
);
10404 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10409 /* Always resize to exact size needed. */
10410 if (height
> WINDOW_TOTAL_LINES (w
))
10412 int old_height
= WINDOW_TOTAL_LINES (w
);
10413 freeze_window_starts (f
, 1);
10414 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10415 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10417 else if (height
< WINDOW_TOTAL_LINES (w
))
10419 int old_height
= WINDOW_TOTAL_LINES (w
);
10420 freeze_window_starts (f
, 0);
10421 shrink_mini_window (w
);
10425 freeze_window_starts (f
, 1);
10426 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10429 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10433 if (old_current_buffer
)
10434 set_buffer_internal (old_current_buffer
);
10437 return window_height_changed_p
;
10441 /* Value is the current message, a string, or nil if there is no
10442 current message. */
10445 current_message (void)
10449 if (!BUFFERP (echo_area_buffer
[0]))
10453 with_echo_area_buffer (0, 0, current_message_1
,
10454 (intptr_t) &msg
, Qnil
, 0, 0);
10456 echo_area_buffer
[0] = Qnil
;
10464 current_message_1 (ptrdiff_t a1
, Lisp_Object a2
, ptrdiff_t a3
, ptrdiff_t a4
)
10467 Lisp_Object
*msg
= (Lisp_Object
*) i1
;
10470 *msg
= make_buffer_string (BEG
, Z
, 1);
10477 /* Push the current message on Vmessage_stack for later restoration
10478 by restore_message. Value is non-zero if the current message isn't
10479 empty. This is a relatively infrequent operation, so it's not
10480 worth optimizing. */
10483 push_message (void)
10485 Lisp_Object msg
= current_message ();
10486 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
10487 return STRINGP (msg
);
10491 /* Restore message display from the top of Vmessage_stack. */
10494 restore_message (void)
10498 eassert (CONSP (Vmessage_stack
));
10499 msg
= XCAR (Vmessage_stack
);
10501 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
10503 message3_nolog (msg
, 0, 0);
10507 /* Handler for record_unwind_protect calling pop_message. */
10510 pop_message_unwind (Lisp_Object dummy
)
10516 /* Pop the top-most entry off Vmessage_stack. */
10521 eassert (CONSP (Vmessage_stack
));
10522 Vmessage_stack
= XCDR (Vmessage_stack
);
10526 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
10527 exits. If the stack is not empty, we have a missing pop_message
10531 check_message_stack (void)
10533 if (!NILP (Vmessage_stack
))
10538 /* Truncate to NCHARS what will be displayed in the echo area the next
10539 time we display it---but don't redisplay it now. */
10542 truncate_echo_area (ptrdiff_t nchars
)
10545 echo_area_buffer
[0] = Qnil
;
10546 /* A null message buffer means that the frame hasn't really been
10547 initialized yet. Error messages get reported properly by
10548 cmd_error, so this must be just an informative message; toss it. */
10549 else if (!noninteractive
10551 && !NILP (echo_area_buffer
[0]))
10553 struct frame
*sf
= SELECTED_FRAME ();
10554 if (FRAME_MESSAGE_BUF (sf
))
10555 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
10560 /* Helper function for truncate_echo_area. Truncate the current
10561 message to at most NCHARS characters. */
10564 truncate_message_1 (ptrdiff_t nchars
, Lisp_Object a2
, ptrdiff_t a3
, ptrdiff_t a4
)
10566 if (BEG
+ nchars
< Z
)
10567 del_range (BEG
+ nchars
, Z
);
10569 echo_area_buffer
[0] = Qnil
;
10573 /* Set the current message to a substring of S or STRING.
10575 If STRING is a Lisp string, set the message to the first NBYTES
10576 bytes from STRING. NBYTES zero means use the whole string. If
10577 STRING is multibyte, the message will be displayed multibyte.
10579 If S is not null, set the message to the first LEN bytes of S. LEN
10580 zero means use the whole string. MULTIBYTE_P non-zero means S is
10581 multibyte. Display the message multibyte in that case.
10583 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
10584 to t before calling set_message_1 (which calls insert).
10588 set_message (const char *s
, Lisp_Object string
,
10589 ptrdiff_t nbytes
, int multibyte_p
)
10591 message_enable_multibyte
10592 = ((s
&& multibyte_p
)
10593 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
10595 with_echo_area_buffer (0, -1, set_message_1
,
10596 (intptr_t) s
, string
, nbytes
, multibyte_p
);
10597 message_buf_print
= 0;
10598 help_echo_showing_p
= 0;
10600 if (STRINGP (Vdebug_on_message
)
10601 && fast_string_match (Vdebug_on_message
, string
) >= 0)
10602 call_debugger (list2 (Qerror
, string
));
10606 /* Helper function for set_message. Arguments have the same meaning
10607 as there, with A1 corresponding to S and A2 corresponding to STRING
10608 This function is called with the echo area buffer being
10612 set_message_1 (ptrdiff_t a1
, Lisp_Object a2
, ptrdiff_t nbytes
, ptrdiff_t multibyte_p
)
10615 const char *s
= (const char *) i1
;
10616 const unsigned char *msg
= (const unsigned char *) s
;
10617 Lisp_Object string
= a2
;
10619 /* Change multibyteness of the echo buffer appropriately. */
10620 if (message_enable_multibyte
10621 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10622 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
10624 bset_truncate_lines (current_buffer
, message_truncate_lines
? Qt
: Qnil
);
10625 if (!NILP (BVAR (current_buffer
, bidi_display_reordering
)))
10626 bset_bidi_paragraph_direction (current_buffer
, Qleft_to_right
);
10628 /* Insert new message at BEG. */
10629 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10631 if (STRINGP (string
))
10636 nbytes
= SBYTES (string
);
10637 nchars
= string_byte_to_char (string
, nbytes
);
10639 /* This function takes care of single/multibyte conversion. We
10640 just have to ensure that the echo area buffer has the right
10641 setting of enable_multibyte_characters. */
10642 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
10647 nbytes
= strlen (s
);
10649 if (multibyte_p
&& NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10651 /* Convert from multi-byte to single-byte. */
10656 /* Convert a multibyte string to single-byte. */
10657 for (i
= 0; i
< nbytes
; i
+= n
)
10659 c
= string_char_and_length (msg
+ i
, &n
);
10660 work
[0] = (ASCII_CHAR_P (c
)
10662 : multibyte_char_to_unibyte (c
));
10663 insert_1_both (work
, 1, 1, 1, 0, 0);
10666 else if (!multibyte_p
10667 && !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10669 /* Convert from single-byte to multi-byte. */
10672 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
10674 /* Convert a single-byte string to multibyte. */
10675 for (i
= 0; i
< nbytes
; i
++)
10678 MAKE_CHAR_MULTIBYTE (c
);
10679 n
= CHAR_STRING (c
, str
);
10680 insert_1_both ((char *) str
, 1, n
, 1, 0, 0);
10684 insert_1 (s
, nbytes
, 1, 0, 0);
10691 /* Clear messages. CURRENT_P non-zero means clear the current
10692 message. LAST_DISPLAYED_P non-zero means clear the message
10696 clear_message (int current_p
, int last_displayed_p
)
10700 echo_area_buffer
[0] = Qnil
;
10701 message_cleared_p
= 1;
10704 if (last_displayed_p
)
10705 echo_area_buffer
[1] = Qnil
;
10707 message_buf_print
= 0;
10710 /* Clear garbaged frames.
10712 This function is used where the old redisplay called
10713 redraw_garbaged_frames which in turn called redraw_frame which in
10714 turn called clear_frame. The call to clear_frame was a source of
10715 flickering. I believe a clear_frame is not necessary. It should
10716 suffice in the new redisplay to invalidate all current matrices,
10717 and ensure a complete redisplay of all windows. */
10720 clear_garbaged_frames (void)
10722 if (frame_garbaged
)
10724 Lisp_Object tail
, frame
;
10725 int changed_count
= 0;
10727 FOR_EACH_FRAME (tail
, frame
)
10729 struct frame
*f
= XFRAME (frame
);
10731 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
10735 Fredraw_frame (frame
);
10736 f
->force_flush_display_p
= 1;
10738 clear_current_matrices (f
);
10745 frame_garbaged
= 0;
10747 ++windows_or_buffers_changed
;
10752 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
10753 is non-zero update selected_frame. Value is non-zero if the
10754 mini-windows height has been changed. */
10757 echo_area_display (int update_frame_p
)
10759 Lisp_Object mini_window
;
10762 int window_height_changed_p
= 0;
10763 struct frame
*sf
= SELECTED_FRAME ();
10765 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10766 w
= XWINDOW (mini_window
);
10767 f
= XFRAME (WINDOW_FRAME (w
));
10769 /* Don't display if frame is invisible or not yet initialized. */
10770 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
10773 #ifdef HAVE_WINDOW_SYSTEM
10774 /* When Emacs starts, selected_frame may be the initial terminal
10775 frame. If we let this through, a message would be displayed on
10777 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
10779 #endif /* HAVE_WINDOW_SYSTEM */
10781 /* Redraw garbaged frames. */
10782 if (frame_garbaged
)
10783 clear_garbaged_frames ();
10785 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
10787 echo_area_window
= mini_window
;
10788 window_height_changed_p
= display_echo_area (w
);
10789 w
->must_be_updated_p
= 1;
10791 /* Update the display, unless called from redisplay_internal.
10792 Also don't update the screen during redisplay itself. The
10793 update will happen at the end of redisplay, and an update
10794 here could cause confusion. */
10795 if (update_frame_p
&& !redisplaying_p
)
10799 /* If the display update has been interrupted by pending
10800 input, update mode lines in the frame. Due to the
10801 pending input, it might have been that redisplay hasn't
10802 been called, so that mode lines above the echo area are
10803 garbaged. This looks odd, so we prevent it here. */
10804 if (!display_completed
)
10805 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
10807 if (window_height_changed_p
10808 /* Don't do this if Emacs is shutting down. Redisplay
10809 needs to run hooks. */
10810 && !NILP (Vrun_hooks
))
10812 /* Must update other windows. Likewise as in other
10813 cases, don't let this update be interrupted by
10815 ptrdiff_t count
= SPECPDL_INDEX ();
10816 specbind (Qredisplay_dont_pause
, Qt
);
10817 windows_or_buffers_changed
= 1;
10818 redisplay_internal ();
10819 unbind_to (count
, Qnil
);
10821 else if (FRAME_WINDOW_P (f
) && n
== 0)
10823 /* Window configuration is the same as before.
10824 Can do with a display update of the echo area,
10825 unless we displayed some mode lines. */
10826 update_single_window (w
, 1);
10827 FRAME_RIF (f
)->flush_display (f
);
10830 update_frame (f
, 1, 1);
10832 /* If cursor is in the echo area, make sure that the next
10833 redisplay displays the minibuffer, so that the cursor will
10834 be replaced with what the minibuffer wants. */
10835 if (cursor_in_echo_area
)
10836 ++windows_or_buffers_changed
;
10839 else if (!EQ (mini_window
, selected_window
))
10840 windows_or_buffers_changed
++;
10842 /* Last displayed message is now the current message. */
10843 echo_area_buffer
[1] = echo_area_buffer
[0];
10844 /* Inform read_char that we're not echoing. */
10845 echo_message_buffer
= Qnil
;
10847 /* Prevent redisplay optimization in redisplay_internal by resetting
10848 this_line_start_pos. This is done because the mini-buffer now
10849 displays the message instead of its buffer text. */
10850 if (EQ (mini_window
, selected_window
))
10851 CHARPOS (this_line_start_pos
) = 0;
10853 return window_height_changed_p
;
10858 /***********************************************************************
10859 Mode Lines and Frame Titles
10860 ***********************************************************************/
10862 /* A buffer for constructing non-propertized mode-line strings and
10863 frame titles in it; allocated from the heap in init_xdisp and
10864 resized as needed in store_mode_line_noprop_char. */
10866 static char *mode_line_noprop_buf
;
10868 /* The buffer's end, and a current output position in it. */
10870 static char *mode_line_noprop_buf_end
;
10871 static char *mode_line_noprop_ptr
;
10873 #define MODE_LINE_NOPROP_LEN(start) \
10874 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
10877 MODE_LINE_DISPLAY
= 0,
10881 } mode_line_target
;
10883 /* Alist that caches the results of :propertize.
10884 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
10885 static Lisp_Object mode_line_proptrans_alist
;
10887 /* List of strings making up the mode-line. */
10888 static Lisp_Object mode_line_string_list
;
10890 /* Base face property when building propertized mode line string. */
10891 static Lisp_Object mode_line_string_face
;
10892 static Lisp_Object mode_line_string_face_prop
;
10895 /* Unwind data for mode line strings */
10897 static Lisp_Object Vmode_line_unwind_vector
;
10900 format_mode_line_unwind_data (struct frame
*target_frame
,
10901 struct buffer
*obuf
,
10903 int save_proptrans
)
10905 Lisp_Object vector
, tmp
;
10907 /* Reduce consing by keeping one vector in
10908 Vwith_echo_area_save_vector. */
10909 vector
= Vmode_line_unwind_vector
;
10910 Vmode_line_unwind_vector
= Qnil
;
10913 vector
= Fmake_vector (make_number (10), Qnil
);
10915 ASET (vector
, 0, make_number (mode_line_target
));
10916 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
10917 ASET (vector
, 2, mode_line_string_list
);
10918 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
10919 ASET (vector
, 4, mode_line_string_face
);
10920 ASET (vector
, 5, mode_line_string_face_prop
);
10923 XSETBUFFER (tmp
, obuf
);
10926 ASET (vector
, 6, tmp
);
10927 ASET (vector
, 7, owin
);
10930 /* Similarly to `with-selected-window', if the operation selects
10931 a window on another frame, we must restore that frame's
10932 selected window, and (for a tty) the top-frame. */
10933 ASET (vector
, 8, target_frame
->selected_window
);
10934 if (FRAME_TERMCAP_P (target_frame
))
10935 ASET (vector
, 9, FRAME_TTY (target_frame
)->top_frame
);
10942 unwind_format_mode_line (Lisp_Object vector
)
10944 Lisp_Object old_window
= AREF (vector
, 7);
10945 Lisp_Object target_frame_window
= AREF (vector
, 8);
10946 Lisp_Object old_top_frame
= AREF (vector
, 9);
10948 mode_line_target
= XINT (AREF (vector
, 0));
10949 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
10950 mode_line_string_list
= AREF (vector
, 2);
10951 if (! EQ (AREF (vector
, 3), Qt
))
10952 mode_line_proptrans_alist
= AREF (vector
, 3);
10953 mode_line_string_face
= AREF (vector
, 4);
10954 mode_line_string_face_prop
= AREF (vector
, 5);
10956 /* Select window before buffer, since it may change the buffer. */
10957 if (!NILP (old_window
))
10959 /* If the operation that we are unwinding had selected a window
10960 on a different frame, reset its frame-selected-window. For a
10961 text terminal, reset its top-frame if necessary. */
10962 if (!NILP (target_frame_window
))
10965 = WINDOW_FRAME (XWINDOW (target_frame_window
));
10967 if (!EQ (frame
, WINDOW_FRAME (XWINDOW (old_window
))))
10968 Fselect_window (target_frame_window
, Qt
);
10970 if (!NILP (old_top_frame
) && !EQ (old_top_frame
, frame
))
10971 Fselect_frame (old_top_frame
, Qt
);
10974 Fselect_window (old_window
, Qt
);
10977 if (!NILP (AREF (vector
, 6)))
10979 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
10980 ASET (vector
, 6, Qnil
);
10983 Vmode_line_unwind_vector
= vector
;
10988 /* Store a single character C for the frame title in mode_line_noprop_buf.
10989 Re-allocate mode_line_noprop_buf if necessary. */
10992 store_mode_line_noprop_char (char c
)
10994 /* If output position has reached the end of the allocated buffer,
10995 increase the buffer's size. */
10996 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
10998 ptrdiff_t len
= MODE_LINE_NOPROP_LEN (0);
10999 ptrdiff_t size
= len
;
11000 mode_line_noprop_buf
=
11001 xpalloc (mode_line_noprop_buf
, &size
, 1, STRING_BYTES_BOUND
, 1);
11002 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
11003 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
11006 *mode_line_noprop_ptr
++ = c
;
11010 /* Store part of a frame title in mode_line_noprop_buf, beginning at
11011 mode_line_noprop_ptr. STRING is the string to store. Do not copy
11012 characters that yield more columns than PRECISION; PRECISION <= 0
11013 means copy the whole string. Pad with spaces until FIELD_WIDTH
11014 number of characters have been copied; FIELD_WIDTH <= 0 means don't
11015 pad. Called from display_mode_element when it is used to build a
11019 store_mode_line_noprop (const char *string
, int field_width
, int precision
)
11021 const unsigned char *str
= (const unsigned char *) string
;
11023 ptrdiff_t dummy
, nbytes
;
11025 /* Copy at most PRECISION chars from STR. */
11026 nbytes
= strlen (string
);
11027 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
11029 store_mode_line_noprop_char (*str
++);
11031 /* Fill up with spaces until FIELD_WIDTH reached. */
11032 while (field_width
> 0
11033 && n
< field_width
)
11035 store_mode_line_noprop_char (' ');
11042 /***********************************************************************
11044 ***********************************************************************/
11046 #ifdef HAVE_WINDOW_SYSTEM
11048 /* Set the title of FRAME, if it has changed. The title format is
11049 Vicon_title_format if FRAME is iconified, otherwise it is
11050 frame_title_format. */
11053 x_consider_frame_title (Lisp_Object frame
)
11055 struct frame
*f
= XFRAME (frame
);
11057 if (FRAME_WINDOW_P (f
)
11058 || FRAME_MINIBUF_ONLY_P (f
)
11059 || f
->explicit_name
)
11061 /* Do we have more than one visible frame on this X display? */
11064 ptrdiff_t title_start
;
11068 ptrdiff_t count
= SPECPDL_INDEX ();
11070 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
11072 Lisp_Object other_frame
= XCAR (tail
);
11073 struct frame
*tf
= XFRAME (other_frame
);
11076 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
11077 && !FRAME_MINIBUF_ONLY_P (tf
)
11078 && !EQ (other_frame
, tip_frame
)
11079 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
11083 /* Set global variable indicating that multiple frames exist. */
11084 multiple_frames
= CONSP (tail
);
11086 /* Switch to the buffer of selected window of the frame. Set up
11087 mode_line_target so that display_mode_element will output into
11088 mode_line_noprop_buf; then display the title. */
11089 record_unwind_protect (unwind_format_mode_line
,
11090 format_mode_line_unwind_data
11091 (f
, current_buffer
, selected_window
, 0));
11093 Fselect_window (f
->selected_window
, Qt
);
11094 set_buffer_internal_1
11095 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
11096 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
11098 mode_line_target
= MODE_LINE_TITLE
;
11099 title_start
= MODE_LINE_NOPROP_LEN (0);
11100 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
11101 NULL
, DEFAULT_FACE_ID
);
11102 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
11103 len
= MODE_LINE_NOPROP_LEN (title_start
);
11104 title
= mode_line_noprop_buf
+ title_start
;
11105 unbind_to (count
, Qnil
);
11107 /* Set the title only if it's changed. This avoids consing in
11108 the common case where it hasn't. (If it turns out that we've
11109 already wasted too much time by walking through the list with
11110 display_mode_element, then we might need to optimize at a
11111 higher level than this.) */
11112 if (! STRINGP (f
->name
)
11113 || SBYTES (f
->name
) != len
11114 || memcmp (title
, SDATA (f
->name
), len
) != 0)
11115 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
11119 #endif /* not HAVE_WINDOW_SYSTEM */
11122 /***********************************************************************
11124 ***********************************************************************/
11127 /* Prepare for redisplay by updating menu-bar item lists when
11128 appropriate. This can call eval. */
11131 prepare_menu_bars (void)
11134 struct gcpro gcpro1
, gcpro2
;
11136 Lisp_Object tooltip_frame
;
11138 #ifdef HAVE_WINDOW_SYSTEM
11139 tooltip_frame
= tip_frame
;
11141 tooltip_frame
= Qnil
;
11144 /* Update all frame titles based on their buffer names, etc. We do
11145 this before the menu bars so that the buffer-menu will show the
11146 up-to-date frame titles. */
11147 #ifdef HAVE_WINDOW_SYSTEM
11148 if (windows_or_buffers_changed
|| update_mode_lines
)
11150 Lisp_Object tail
, frame
;
11152 FOR_EACH_FRAME (tail
, frame
)
11154 f
= XFRAME (frame
);
11155 if (!EQ (frame
, tooltip_frame
)
11156 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
11157 x_consider_frame_title (frame
);
11160 #endif /* HAVE_WINDOW_SYSTEM */
11162 /* Update the menu bar item lists, if appropriate. This has to be
11163 done before any actual redisplay or generation of display lines. */
11164 all_windows
= (update_mode_lines
11165 || buffer_shared
> 1
11166 || windows_or_buffers_changed
);
11169 Lisp_Object tail
, frame
;
11170 ptrdiff_t count
= SPECPDL_INDEX ();
11171 /* 1 means that update_menu_bar has run its hooks
11172 so any further calls to update_menu_bar shouldn't do so again. */
11173 int menu_bar_hooks_run
= 0;
11175 record_unwind_save_match_data ();
11177 FOR_EACH_FRAME (tail
, frame
)
11179 f
= XFRAME (frame
);
11181 /* Ignore tooltip frame. */
11182 if (EQ (frame
, tooltip_frame
))
11185 /* If a window on this frame changed size, report that to
11186 the user and clear the size-change flag. */
11187 if (FRAME_WINDOW_SIZES_CHANGED (f
))
11189 Lisp_Object functions
;
11191 /* Clear flag first in case we get an error below. */
11192 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
11193 functions
= Vwindow_size_change_functions
;
11194 GCPRO2 (tail
, functions
);
11196 while (CONSP (functions
))
11198 if (!EQ (XCAR (functions
), Qt
))
11199 call1 (XCAR (functions
), frame
);
11200 functions
= XCDR (functions
);
11206 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
11207 #ifdef HAVE_WINDOW_SYSTEM
11208 update_tool_bar (f
, 0);
11211 if (windows_or_buffers_changed
11214 (f
, Fbuffer_modified_p (XWINDOW (f
->selected_window
)->buffer
));
11219 unbind_to (count
, Qnil
);
11223 struct frame
*sf
= SELECTED_FRAME ();
11224 update_menu_bar (sf
, 1, 0);
11225 #ifdef HAVE_WINDOW_SYSTEM
11226 update_tool_bar (sf
, 1);
11232 /* Update the menu bar item list for frame F. This has to be done
11233 before we start to fill in any display lines, because it can call
11236 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
11238 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
11239 already ran the menu bar hooks for this redisplay, so there
11240 is no need to run them again. The return value is the
11241 updated value of this flag, to pass to the next call. */
11244 update_menu_bar (struct frame
*f
, int save_match_data
, int hooks_run
)
11246 Lisp_Object window
;
11247 register struct window
*w
;
11249 /* If called recursively during a menu update, do nothing. This can
11250 happen when, for instance, an activate-menubar-hook causes a
11252 if (inhibit_menubar_update
)
11255 window
= FRAME_SELECTED_WINDOW (f
);
11256 w
= XWINDOW (window
);
11258 if (FRAME_WINDOW_P (f
)
11260 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11261 || defined (HAVE_NS) || defined (USE_GTK)
11262 FRAME_EXTERNAL_MENU_BAR (f
)
11264 FRAME_MENU_BAR_LINES (f
) > 0
11266 : FRAME_MENU_BAR_LINES (f
) > 0)
11268 /* If the user has switched buffers or windows, we need to
11269 recompute to reflect the new bindings. But we'll
11270 recompute when update_mode_lines is set too; that means
11271 that people can use force-mode-line-update to request
11272 that the menu bar be recomputed. The adverse effect on
11273 the rest of the redisplay algorithm is about the same as
11274 windows_or_buffers_changed anyway. */
11275 if (windows_or_buffers_changed
11276 /* This used to test w->update_mode_line, but we believe
11277 there is no need to recompute the menu in that case. */
11278 || update_mode_lines
11279 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
11280 < BUF_MODIFF (XBUFFER (w
->buffer
)))
11281 != w
->last_had_star
)
11282 || ((!NILP (Vtransient_mark_mode
)
11283 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
11284 != !NILP (w
->region_showing
)))
11286 struct buffer
*prev
= current_buffer
;
11287 ptrdiff_t count
= SPECPDL_INDEX ();
11289 specbind (Qinhibit_menubar_update
, Qt
);
11291 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11292 if (save_match_data
)
11293 record_unwind_save_match_data ();
11294 if (NILP (Voverriding_local_map_menu_flag
))
11296 specbind (Qoverriding_terminal_local_map
, Qnil
);
11297 specbind (Qoverriding_local_map
, Qnil
);
11302 /* Run the Lucid hook. */
11303 safe_run_hooks (Qactivate_menubar_hook
);
11305 /* If it has changed current-menubar from previous value,
11306 really recompute the menu-bar from the value. */
11307 if (! NILP (Vlucid_menu_bar_dirty_flag
))
11308 call0 (Qrecompute_lucid_menubar
);
11310 safe_run_hooks (Qmenu_bar_update_hook
);
11315 XSETFRAME (Vmenu_updating_frame
, f
);
11316 fset_menu_bar_items (f
, menu_bar_items (FRAME_MENU_BAR_ITEMS (f
)));
11318 /* Redisplay the menu bar in case we changed it. */
11319 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11320 || defined (HAVE_NS) || defined (USE_GTK)
11321 if (FRAME_WINDOW_P (f
))
11323 #if defined (HAVE_NS)
11324 /* All frames on Mac OS share the same menubar. So only
11325 the selected frame should be allowed to set it. */
11326 if (f
== SELECTED_FRAME ())
11328 set_frame_menubar (f
, 0, 0);
11331 /* On a terminal screen, the menu bar is an ordinary screen
11332 line, and this makes it get updated. */
11333 w
->update_mode_line
= 1;
11334 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11335 /* In the non-toolkit version, the menu bar is an ordinary screen
11336 line, and this makes it get updated. */
11337 w
->update_mode_line
= 1;
11338 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11340 unbind_to (count
, Qnil
);
11341 set_buffer_internal_1 (prev
);
11350 /***********************************************************************
11352 ***********************************************************************/
11354 #ifdef HAVE_WINDOW_SYSTEM
11357 Nominal cursor position -- where to draw output.
11358 HPOS and VPOS are window relative glyph matrix coordinates.
11359 X and Y are window relative pixel coordinates. */
11361 struct cursor_pos output_cursor
;
11365 Set the global variable output_cursor to CURSOR. All cursor
11366 positions are relative to updated_window. */
11369 set_output_cursor (struct cursor_pos
*cursor
)
11371 output_cursor
.hpos
= cursor
->hpos
;
11372 output_cursor
.vpos
= cursor
->vpos
;
11373 output_cursor
.x
= cursor
->x
;
11374 output_cursor
.y
= cursor
->y
;
11379 Set a nominal cursor position.
11381 HPOS and VPOS are column/row positions in a window glyph matrix. X
11382 and Y are window text area relative pixel positions.
11384 If this is done during an update, updated_window will contain the
11385 window that is being updated and the position is the future output
11386 cursor position for that window. If updated_window is null, use
11387 selected_window and display the cursor at the given position. */
11390 x_cursor_to (int vpos
, int hpos
, int y
, int x
)
11394 /* If updated_window is not set, work on selected_window. */
11395 if (updated_window
)
11396 w
= updated_window
;
11398 w
= XWINDOW (selected_window
);
11400 /* Set the output cursor. */
11401 output_cursor
.hpos
= hpos
;
11402 output_cursor
.vpos
= vpos
;
11403 output_cursor
.x
= x
;
11404 output_cursor
.y
= y
;
11406 /* If not called as part of an update, really display the cursor.
11407 This will also set the cursor position of W. */
11408 if (updated_window
== NULL
)
11411 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
11412 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
11413 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
11418 #endif /* HAVE_WINDOW_SYSTEM */
11421 /***********************************************************************
11423 ***********************************************************************/
11425 #ifdef HAVE_WINDOW_SYSTEM
11427 /* Where the mouse was last time we reported a mouse event. */
11429 FRAME_PTR last_mouse_frame
;
11431 /* Tool-bar item index of the item on which a mouse button was pressed
11434 int last_tool_bar_item
;
11438 update_tool_bar_unwind (Lisp_Object frame
)
11440 selected_frame
= frame
;
11444 /* Update the tool-bar item list for frame F. This has to be done
11445 before we start to fill in any display lines. Called from
11446 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
11447 and restore it here. */
11450 update_tool_bar (struct frame
*f
, int save_match_data
)
11452 #if defined (USE_GTK) || defined (HAVE_NS)
11453 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
11455 int do_update
= WINDOWP (f
->tool_bar_window
)
11456 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
11461 Lisp_Object window
;
11464 window
= FRAME_SELECTED_WINDOW (f
);
11465 w
= XWINDOW (window
);
11467 /* If the user has switched buffers or windows, we need to
11468 recompute to reflect the new bindings. But we'll
11469 recompute when update_mode_lines is set too; that means
11470 that people can use force-mode-line-update to request
11471 that the menu bar be recomputed. The adverse effect on
11472 the rest of the redisplay algorithm is about the same as
11473 windows_or_buffers_changed anyway. */
11474 if (windows_or_buffers_changed
11475 || w
->update_mode_line
11476 || update_mode_lines
11477 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
11478 < BUF_MODIFF (XBUFFER (w
->buffer
)))
11479 != w
->last_had_star
)
11480 || ((!NILP (Vtransient_mark_mode
)
11481 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
11482 != !NILP (w
->region_showing
)))
11484 struct buffer
*prev
= current_buffer
;
11485 ptrdiff_t count
= SPECPDL_INDEX ();
11486 Lisp_Object frame
, new_tool_bar
;
11487 int new_n_tool_bar
;
11488 struct gcpro gcpro1
;
11490 /* Set current_buffer to the buffer of the selected
11491 window of the frame, so that we get the right local
11493 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11495 /* Save match data, if we must. */
11496 if (save_match_data
)
11497 record_unwind_save_match_data ();
11499 /* Make sure that we don't accidentally use bogus keymaps. */
11500 if (NILP (Voverriding_local_map_menu_flag
))
11502 specbind (Qoverriding_terminal_local_map
, Qnil
);
11503 specbind (Qoverriding_local_map
, Qnil
);
11506 GCPRO1 (new_tool_bar
);
11508 /* We must temporarily set the selected frame to this frame
11509 before calling tool_bar_items, because the calculation of
11510 the tool-bar keymap uses the selected frame (see
11511 `tool-bar-make-keymap' in tool-bar.el). */
11512 record_unwind_protect (update_tool_bar_unwind
, selected_frame
);
11513 XSETFRAME (frame
, f
);
11514 selected_frame
= frame
;
11516 /* Build desired tool-bar items from keymaps. */
11518 = tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
11521 /* Redisplay the tool-bar if we changed it. */
11522 if (new_n_tool_bar
!= f
->n_tool_bar_items
11523 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
11525 /* Redisplay that happens asynchronously due to an expose event
11526 may access f->tool_bar_items. Make sure we update both
11527 variables within BLOCK_INPUT so no such event interrupts. */
11529 fset_tool_bar_items (f
, new_tool_bar
);
11530 f
->n_tool_bar_items
= new_n_tool_bar
;
11531 w
->update_mode_line
= 1;
11537 unbind_to (count
, Qnil
);
11538 set_buffer_internal_1 (prev
);
11544 /* Set F->desired_tool_bar_string to a Lisp string representing frame
11545 F's desired tool-bar contents. F->tool_bar_items must have
11546 been set up previously by calling prepare_menu_bars. */
11549 build_desired_tool_bar_string (struct frame
*f
)
11551 int i
, size
, size_needed
;
11552 struct gcpro gcpro1
, gcpro2
, gcpro3
;
11553 Lisp_Object image
, plist
, props
;
11555 image
= plist
= props
= Qnil
;
11556 GCPRO3 (image
, plist
, props
);
11558 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
11559 Otherwise, make a new string. */
11561 /* The size of the string we might be able to reuse. */
11562 size
= (STRINGP (f
->desired_tool_bar_string
)
11563 ? SCHARS (f
->desired_tool_bar_string
)
11566 /* We need one space in the string for each image. */
11567 size_needed
= f
->n_tool_bar_items
;
11569 /* Reuse f->desired_tool_bar_string, if possible. */
11570 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
11571 fset_desired_tool_bar_string
11572 (f
, Fmake_string (make_number (size_needed
), make_number (' ')));
11575 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
11576 Fremove_text_properties (make_number (0), make_number (size
),
11577 props
, f
->desired_tool_bar_string
);
11580 /* Put a `display' property on the string for the images to display,
11581 put a `menu_item' property on tool-bar items with a value that
11582 is the index of the item in F's tool-bar item vector. */
11583 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
11585 #define PROP(IDX) \
11586 AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
11588 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
11589 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
11590 int hmargin
, vmargin
, relief
, idx
, end
;
11592 /* If image is a vector, choose the image according to the
11594 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
11595 if (VECTORP (image
))
11599 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
11600 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
11603 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
11604 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
11606 eassert (ASIZE (image
) >= idx
);
11607 image
= AREF (image
, idx
);
11612 /* Ignore invalid image specifications. */
11613 if (!valid_image_p (image
))
11616 /* Display the tool-bar button pressed, or depressed. */
11617 plist
= Fcopy_sequence (XCDR (image
));
11619 /* Compute margin and relief to draw. */
11620 relief
= (tool_bar_button_relief
>= 0
11621 ? tool_bar_button_relief
11622 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
11623 hmargin
= vmargin
= relief
;
11625 if (RANGED_INTEGERP (1, Vtool_bar_button_margin
,
11626 INT_MAX
- max (hmargin
, vmargin
)))
11628 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
11629 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
11631 else if (CONSP (Vtool_bar_button_margin
))
11633 if (RANGED_INTEGERP (1, XCAR (Vtool_bar_button_margin
),
11634 INT_MAX
- hmargin
))
11635 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
11637 if (RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin
),
11638 INT_MAX
- vmargin
))
11639 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
11642 if (auto_raise_tool_bar_buttons_p
)
11644 /* Add a `:relief' property to the image spec if the item is
11648 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
11655 /* If image is selected, display it pressed, i.e. with a
11656 negative relief. If it's not selected, display it with a
11658 plist
= Fplist_put (plist
, QCrelief
,
11660 ? make_number (-relief
)
11661 : make_number (relief
)));
11666 /* Put a margin around the image. */
11667 if (hmargin
|| vmargin
)
11669 if (hmargin
== vmargin
)
11670 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
11672 plist
= Fplist_put (plist
, QCmargin
,
11673 Fcons (make_number (hmargin
),
11674 make_number (vmargin
)));
11677 /* If button is not enabled, and we don't have special images
11678 for the disabled state, make the image appear disabled by
11679 applying an appropriate algorithm to it. */
11680 if (!enabled_p
&& idx
< 0)
11681 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
11683 /* Put a `display' text property on the string for the image to
11684 display. Put a `menu-item' property on the string that gives
11685 the start of this item's properties in the tool-bar items
11687 image
= Fcons (Qimage
, plist
);
11688 props
= list4 (Qdisplay
, image
,
11689 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
11691 /* Let the last image hide all remaining spaces in the tool bar
11692 string. The string can be longer than needed when we reuse a
11693 previous string. */
11694 if (i
+ 1 == f
->n_tool_bar_items
)
11695 end
= SCHARS (f
->desired_tool_bar_string
);
11698 Fadd_text_properties (make_number (i
), make_number (end
),
11699 props
, f
->desired_tool_bar_string
);
11707 /* Display one line of the tool-bar of frame IT->f.
11709 HEIGHT specifies the desired height of the tool-bar line.
11710 If the actual height of the glyph row is less than HEIGHT, the
11711 row's height is increased to HEIGHT, and the icons are centered
11712 vertically in the new height.
11714 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
11715 count a final empty row in case the tool-bar width exactly matches
11720 display_tool_bar_line (struct it
*it
, int height
)
11722 struct glyph_row
*row
= it
->glyph_row
;
11723 int max_x
= it
->last_visible_x
;
11724 struct glyph
*last
;
11726 prepare_desired_row (row
);
11727 row
->y
= it
->current_y
;
11729 /* Note that this isn't made use of if the face hasn't a box,
11730 so there's no need to check the face here. */
11731 it
->start_of_box_run_p
= 1;
11733 while (it
->current_x
< max_x
)
11735 int x
, n_glyphs_before
, i
, nglyphs
;
11736 struct it it_before
;
11738 /* Get the next display element. */
11739 if (!get_next_display_element (it
))
11741 /* Don't count empty row if we are counting needed tool-bar lines. */
11742 if (height
< 0 && !it
->hpos
)
11747 /* Produce glyphs. */
11748 n_glyphs_before
= row
->used
[TEXT_AREA
];
11751 PRODUCE_GLYPHS (it
);
11753 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
11755 x
= it_before
.current_x
;
11756 while (i
< nglyphs
)
11758 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
11760 if (x
+ glyph
->pixel_width
> max_x
)
11762 /* Glyph doesn't fit on line. Backtrack. */
11763 row
->used
[TEXT_AREA
] = n_glyphs_before
;
11765 /* If this is the only glyph on this line, it will never fit on the
11766 tool-bar, so skip it. But ensure there is at least one glyph,
11767 so we don't accidentally disable the tool-bar. */
11768 if (n_glyphs_before
== 0
11769 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
11775 x
+= glyph
->pixel_width
;
11779 /* Stop at line end. */
11780 if (ITERATOR_AT_END_OF_LINE_P (it
))
11783 set_iterator_to_next (it
, 1);
11788 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
11790 /* Use default face for the border below the tool bar.
11792 FIXME: When auto-resize-tool-bars is grow-only, there is
11793 no additional border below the possibly empty tool-bar lines.
11794 So to make the extra empty lines look "normal", we have to
11795 use the tool-bar face for the border too. */
11796 if (!row
->displays_text_p
&& !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
11797 it
->face_id
= DEFAULT_FACE_ID
;
11799 extend_face_to_end_of_line (it
);
11800 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
11801 last
->right_box_line_p
= 1;
11802 if (last
== row
->glyphs
[TEXT_AREA
])
11803 last
->left_box_line_p
= 1;
11805 /* Make line the desired height and center it vertically. */
11806 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
11808 /* Don't add more than one line height. */
11809 height
%= FRAME_LINE_HEIGHT (it
->f
);
11810 it
->max_ascent
+= height
/ 2;
11811 it
->max_descent
+= (height
+ 1) / 2;
11814 compute_line_metrics (it
);
11816 /* If line is empty, make it occupy the rest of the tool-bar. */
11817 if (!row
->displays_text_p
)
11819 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
11820 row
->visible_height
= row
->height
;
11821 row
->ascent
= row
->phys_ascent
= 0;
11822 row
->extra_line_spacing
= 0;
11825 row
->full_width_p
= 1;
11826 row
->continued_p
= 0;
11827 row
->truncated_on_left_p
= 0;
11828 row
->truncated_on_right_p
= 0;
11830 it
->current_x
= it
->hpos
= 0;
11831 it
->current_y
+= row
->height
;
11837 /* Max tool-bar height. */
11839 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
11840 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
11842 /* Value is the number of screen lines needed to make all tool-bar
11843 items of frame F visible. The number of actual rows needed is
11844 returned in *N_ROWS if non-NULL. */
11847 tool_bar_lines_needed (struct frame
*f
, int *n_rows
)
11849 struct window
*w
= XWINDOW (f
->tool_bar_window
);
11851 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
11852 the desired matrix, so use (unused) mode-line row as temporary row to
11853 avoid destroying the first tool-bar row. */
11854 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
11856 /* Initialize an iterator for iteration over
11857 F->desired_tool_bar_string in the tool-bar window of frame F. */
11858 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
11859 it
.first_visible_x
= 0;
11860 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
11861 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
11862 it
.paragraph_embedding
= L2R
;
11864 while (!ITERATOR_AT_END_P (&it
))
11866 clear_glyph_row (temp_row
);
11867 it
.glyph_row
= temp_row
;
11868 display_tool_bar_line (&it
, -1);
11870 clear_glyph_row (temp_row
);
11872 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
11874 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
11876 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
11880 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
11882 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
11883 (Lisp_Object frame
)
11890 frame
= selected_frame
;
11892 CHECK_FRAME (frame
);
11893 f
= XFRAME (frame
);
11895 if (WINDOWP (f
->tool_bar_window
)
11896 && (w
= XWINDOW (f
->tool_bar_window
),
11897 WINDOW_TOTAL_LINES (w
) > 0))
11899 update_tool_bar (f
, 1);
11900 if (f
->n_tool_bar_items
)
11902 build_desired_tool_bar_string (f
);
11903 nlines
= tool_bar_lines_needed (f
, NULL
);
11907 return make_number (nlines
);
11911 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
11912 height should be changed. */
11915 redisplay_tool_bar (struct frame
*f
)
11919 struct glyph_row
*row
;
11921 #if defined (USE_GTK) || defined (HAVE_NS)
11922 if (FRAME_EXTERNAL_TOOL_BAR (f
))
11923 update_frame_tool_bar (f
);
11927 /* If frame hasn't a tool-bar window or if it is zero-height, don't
11928 do anything. This means you must start with tool-bar-lines
11929 non-zero to get the auto-sizing effect. Or in other words, you
11930 can turn off tool-bars by specifying tool-bar-lines zero. */
11931 if (!WINDOWP (f
->tool_bar_window
)
11932 || (w
= XWINDOW (f
->tool_bar_window
),
11933 WINDOW_TOTAL_LINES (w
) == 0))
11936 /* Set up an iterator for the tool-bar window. */
11937 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
11938 it
.first_visible_x
= 0;
11939 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
11940 row
= it
.glyph_row
;
11942 /* Build a string that represents the contents of the tool-bar. */
11943 build_desired_tool_bar_string (f
);
11944 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
11945 /* FIXME: This should be controlled by a user option. But it
11946 doesn't make sense to have an R2L tool bar if the menu bar cannot
11947 be drawn also R2L, and making the menu bar R2L is tricky due
11948 toolkit-specific code that implements it. If an R2L tool bar is
11949 ever supported, display_tool_bar_line should also be augmented to
11950 call unproduce_glyphs like display_line and display_string
11952 it
.paragraph_embedding
= L2R
;
11954 if (f
->n_tool_bar_rows
== 0)
11958 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
11959 nlines
!= WINDOW_TOTAL_LINES (w
)))
11962 int old_height
= WINDOW_TOTAL_LINES (w
);
11964 XSETFRAME (frame
, f
);
11965 Fmodify_frame_parameters (frame
,
11966 Fcons (Fcons (Qtool_bar_lines
,
11967 make_number (nlines
)),
11969 if (WINDOW_TOTAL_LINES (w
) != old_height
)
11971 clear_glyph_matrix (w
->desired_matrix
);
11972 fonts_changed_p
= 1;
11978 /* Display as many lines as needed to display all tool-bar items. */
11980 if (f
->n_tool_bar_rows
> 0)
11982 int border
, rows
, height
, extra
;
11984 if (TYPE_RANGED_INTEGERP (int, Vtool_bar_border
))
11985 border
= XINT (Vtool_bar_border
);
11986 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
11987 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
11988 else if (EQ (Vtool_bar_border
, Qborder_width
))
11989 border
= f
->border_width
;
11995 rows
= f
->n_tool_bar_rows
;
11996 height
= max (1, (it
.last_visible_y
- border
) / rows
);
11997 extra
= it
.last_visible_y
- border
- height
* rows
;
11999 while (it
.current_y
< it
.last_visible_y
)
12002 if (extra
> 0 && rows
-- > 0)
12004 h
= (extra
+ rows
- 1) / rows
;
12007 display_tool_bar_line (&it
, height
+ h
);
12012 while (it
.current_y
< it
.last_visible_y
)
12013 display_tool_bar_line (&it
, 0);
12016 /* It doesn't make much sense to try scrolling in the tool-bar
12017 window, so don't do it. */
12018 w
->desired_matrix
->no_scrolling_p
= 1;
12019 w
->must_be_updated_p
= 1;
12021 if (!NILP (Vauto_resize_tool_bars
))
12023 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
12024 int change_height_p
= 0;
12026 /* If we couldn't display everything, change the tool-bar's
12027 height if there is room for more. */
12028 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
12029 && it
.current_y
< max_tool_bar_height
)
12030 change_height_p
= 1;
12032 row
= it
.glyph_row
- 1;
12034 /* If there are blank lines at the end, except for a partially
12035 visible blank line at the end that is smaller than
12036 FRAME_LINE_HEIGHT, change the tool-bar's height. */
12037 if (!row
->displays_text_p
12038 && row
->height
>= FRAME_LINE_HEIGHT (f
))
12039 change_height_p
= 1;
12041 /* If row displays tool-bar items, but is partially visible,
12042 change the tool-bar's height. */
12043 if (row
->displays_text_p
12044 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
12045 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
12046 change_height_p
= 1;
12048 /* Resize windows as needed by changing the `tool-bar-lines'
12049 frame parameter. */
12050 if (change_height_p
)
12053 int old_height
= WINDOW_TOTAL_LINES (w
);
12055 int nlines
= tool_bar_lines_needed (f
, &nrows
);
12057 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
12058 && !f
->minimize_tool_bar_window_p
)
12059 ? (nlines
> old_height
)
12060 : (nlines
!= old_height
));
12061 f
->minimize_tool_bar_window_p
= 0;
12063 if (change_height_p
)
12065 XSETFRAME (frame
, f
);
12066 Fmodify_frame_parameters (frame
,
12067 Fcons (Fcons (Qtool_bar_lines
,
12068 make_number (nlines
)),
12070 if (WINDOW_TOTAL_LINES (w
) != old_height
)
12072 clear_glyph_matrix (w
->desired_matrix
);
12073 f
->n_tool_bar_rows
= nrows
;
12074 fonts_changed_p
= 1;
12081 f
->minimize_tool_bar_window_p
= 0;
12086 /* Get information about the tool-bar item which is displayed in GLYPH
12087 on frame F. Return in *PROP_IDX the index where tool-bar item
12088 properties start in F->tool_bar_items. Value is zero if
12089 GLYPH doesn't display a tool-bar item. */
12092 tool_bar_item_info (struct frame
*f
, struct glyph
*glyph
, int *prop_idx
)
12098 /* This function can be called asynchronously, which means we must
12099 exclude any possibility that Fget_text_property signals an
12101 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
12102 charpos
= max (0, charpos
);
12104 /* Get the text property `menu-item' at pos. The value of that
12105 property is the start index of this item's properties in
12106 F->tool_bar_items. */
12107 prop
= Fget_text_property (make_number (charpos
),
12108 Qmenu_item
, f
->current_tool_bar_string
);
12109 if (INTEGERP (prop
))
12111 *prop_idx
= XINT (prop
);
12121 /* Get information about the tool-bar item at position X/Y on frame F.
12122 Return in *GLYPH a pointer to the glyph of the tool-bar item in
12123 the current matrix of the tool-bar window of F, or NULL if not
12124 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
12125 item in F->tool_bar_items. Value is
12127 -1 if X/Y is not on a tool-bar item
12128 0 if X/Y is on the same item that was highlighted before.
12132 get_tool_bar_item (struct frame
*f
, int x
, int y
, struct glyph
**glyph
,
12133 int *hpos
, int *vpos
, int *prop_idx
)
12135 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12136 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12139 /* Find the glyph under X/Y. */
12140 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
12141 if (*glyph
== NULL
)
12144 /* Get the start of this tool-bar item's properties in
12145 f->tool_bar_items. */
12146 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
12149 /* Is mouse on the highlighted item? */
12150 if (EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
)
12151 && *vpos
>= hlinfo
->mouse_face_beg_row
12152 && *vpos
<= hlinfo
->mouse_face_end_row
12153 && (*vpos
> hlinfo
->mouse_face_beg_row
12154 || *hpos
>= hlinfo
->mouse_face_beg_col
)
12155 && (*vpos
< hlinfo
->mouse_face_end_row
12156 || *hpos
< hlinfo
->mouse_face_end_col
12157 || hlinfo
->mouse_face_past_end
))
12165 Handle mouse button event on the tool-bar of frame F, at
12166 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
12167 0 for button release. MODIFIERS is event modifiers for button
12171 handle_tool_bar_click (struct frame
*f
, int x
, int y
, int down_p
,
12174 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12175 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12176 int hpos
, vpos
, prop_idx
;
12177 struct glyph
*glyph
;
12178 Lisp_Object enabled_p
;
12180 /* If not on the highlighted tool-bar item, return. */
12181 frame_to_window_pixel_xy (w
, &x
, &y
);
12182 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
12185 /* If item is disabled, do nothing. */
12186 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12187 if (NILP (enabled_p
))
12192 /* Show item in pressed state. */
12193 show_mouse_face (hlinfo
, DRAW_IMAGE_SUNKEN
);
12194 hlinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
12195 last_tool_bar_item
= prop_idx
;
12199 Lisp_Object key
, frame
;
12200 struct input_event event
;
12201 EVENT_INIT (event
);
12203 /* Show item in released state. */
12204 show_mouse_face (hlinfo
, DRAW_IMAGE_RAISED
);
12205 hlinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
12207 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
12209 XSETFRAME (frame
, f
);
12210 event
.kind
= TOOL_BAR_EVENT
;
12211 event
.frame_or_window
= frame
;
12213 kbd_buffer_store_event (&event
);
12215 event
.kind
= TOOL_BAR_EVENT
;
12216 event
.frame_or_window
= frame
;
12218 event
.modifiers
= modifiers
;
12219 kbd_buffer_store_event (&event
);
12220 last_tool_bar_item
= -1;
12225 /* Possibly highlight a tool-bar item on frame F when mouse moves to
12226 tool-bar window-relative coordinates X/Y. Called from
12227 note_mouse_highlight. */
12230 note_tool_bar_highlight (struct frame
*f
, int x
, int y
)
12232 Lisp_Object window
= f
->tool_bar_window
;
12233 struct window
*w
= XWINDOW (window
);
12234 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12235 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12237 struct glyph
*glyph
;
12238 struct glyph_row
*row
;
12240 Lisp_Object enabled_p
;
12242 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
12243 int mouse_down_p
, rc
;
12245 /* Function note_mouse_highlight is called with negative X/Y
12246 values when mouse moves outside of the frame. */
12247 if (x
<= 0 || y
<= 0)
12249 clear_mouse_face (hlinfo
);
12253 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
12256 /* Not on tool-bar item. */
12257 clear_mouse_face (hlinfo
);
12261 /* On same tool-bar item as before. */
12262 goto set_help_echo
;
12264 clear_mouse_face (hlinfo
);
12266 /* Mouse is down, but on different tool-bar item? */
12267 mouse_down_p
= (dpyinfo
->grabbed
12268 && f
== last_mouse_frame
12269 && FRAME_LIVE_P (f
));
12271 && last_tool_bar_item
!= prop_idx
)
12274 hlinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
12275 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
12277 /* If tool-bar item is not enabled, don't highlight it. */
12278 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12279 if (!NILP (enabled_p
))
12281 /* Compute the x-position of the glyph. In front and past the
12282 image is a space. We include this in the highlighted area. */
12283 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
12284 for (i
= x
= 0; i
< hpos
; ++i
)
12285 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
12287 /* Record this as the current active region. */
12288 hlinfo
->mouse_face_beg_col
= hpos
;
12289 hlinfo
->mouse_face_beg_row
= vpos
;
12290 hlinfo
->mouse_face_beg_x
= x
;
12291 hlinfo
->mouse_face_beg_y
= row
->y
;
12292 hlinfo
->mouse_face_past_end
= 0;
12294 hlinfo
->mouse_face_end_col
= hpos
+ 1;
12295 hlinfo
->mouse_face_end_row
= vpos
;
12296 hlinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
12297 hlinfo
->mouse_face_end_y
= row
->y
;
12298 hlinfo
->mouse_face_window
= window
;
12299 hlinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
12301 /* Display it as active. */
12302 show_mouse_face (hlinfo
, draw
);
12303 hlinfo
->mouse_face_image_state
= draw
;
12308 /* Set help_echo_string to a help string to display for this tool-bar item.
12309 XTread_socket does the rest. */
12310 help_echo_object
= help_echo_window
= Qnil
;
12311 help_echo_pos
= -1;
12312 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
12313 if (NILP (help_echo_string
))
12314 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
12317 #endif /* HAVE_WINDOW_SYSTEM */
12321 /************************************************************************
12322 Horizontal scrolling
12323 ************************************************************************/
12325 static int hscroll_window_tree (Lisp_Object
);
12326 static int hscroll_windows (Lisp_Object
);
12328 /* For all leaf windows in the window tree rooted at WINDOW, set their
12329 hscroll value so that PT is (i) visible in the window, and (ii) so
12330 that it is not within a certain margin at the window's left and
12331 right border. Value is non-zero if any window's hscroll has been
12335 hscroll_window_tree (Lisp_Object window
)
12337 int hscrolled_p
= 0;
12338 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
12339 int hscroll_step_abs
= 0;
12340 double hscroll_step_rel
= 0;
12342 if (hscroll_relative_p
)
12344 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
12345 if (hscroll_step_rel
< 0)
12347 hscroll_relative_p
= 0;
12348 hscroll_step_abs
= 0;
12351 else if (TYPE_RANGED_INTEGERP (int, Vhscroll_step
))
12353 hscroll_step_abs
= XINT (Vhscroll_step
);
12354 if (hscroll_step_abs
< 0)
12355 hscroll_step_abs
= 0;
12358 hscroll_step_abs
= 0;
12360 while (WINDOWP (window
))
12362 struct window
*w
= XWINDOW (window
);
12364 if (WINDOWP (w
->hchild
))
12365 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
12366 else if (WINDOWP (w
->vchild
))
12367 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
12368 else if (w
->cursor
.vpos
>= 0)
12371 int text_area_width
;
12372 struct glyph_row
*current_cursor_row
12373 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
12374 struct glyph_row
*desired_cursor_row
12375 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
12376 struct glyph_row
*cursor_row
12377 = (desired_cursor_row
->enabled_p
12378 ? desired_cursor_row
12379 : current_cursor_row
);
12380 int row_r2l_p
= cursor_row
->reversed_p
;
12382 text_area_width
= window_box_width (w
, TEXT_AREA
);
12384 /* Scroll when cursor is inside this scroll margin. */
12385 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
12387 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->buffer
))
12388 /* For left-to-right rows, hscroll when cursor is either
12389 (i) inside the right hscroll margin, or (ii) if it is
12390 inside the left margin and the window is already
12394 && w
->cursor
.x
<= h_margin
)
12395 || (cursor_row
->enabled_p
12396 && cursor_row
->truncated_on_right_p
12397 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
12398 /* For right-to-left rows, the logic is similar,
12399 except that rules for scrolling to left and right
12400 are reversed. E.g., if cursor.x <= h_margin, we
12401 need to hscroll "to the right" unconditionally,
12402 and that will scroll the screen to the left so as
12403 to reveal the next portion of the row. */
12405 && ((cursor_row
->enabled_p
12406 /* FIXME: It is confusing to set the
12407 truncated_on_right_p flag when R2L rows
12408 are actually truncated on the left. */
12409 && cursor_row
->truncated_on_right_p
12410 && w
->cursor
.x
<= h_margin
)
12412 && (w
->cursor
.x
>= text_area_width
- h_margin
))))))
12416 struct buffer
*saved_current_buffer
;
12420 /* Find point in a display of infinite width. */
12421 saved_current_buffer
= current_buffer
;
12422 current_buffer
= XBUFFER (w
->buffer
);
12424 if (w
== XWINDOW (selected_window
))
12428 pt
= marker_position (w
->pointm
);
12429 pt
= max (BEGV
, pt
);
12433 /* Move iterator to pt starting at cursor_row->start in
12434 a line with infinite width. */
12435 init_to_row_start (&it
, w
, cursor_row
);
12436 it
.last_visible_x
= INFINITY
;
12437 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
12438 current_buffer
= saved_current_buffer
;
12440 /* Position cursor in window. */
12441 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
12442 hscroll
= max (0, (it
.current_x
12443 - (ITERATOR_AT_END_OF_LINE_P (&it
)
12444 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
12445 : (text_area_width
/ 2))))
12446 / FRAME_COLUMN_WIDTH (it
.f
);
12447 else if ((!row_r2l_p
12448 && w
->cursor
.x
>= text_area_width
- h_margin
)
12449 || (row_r2l_p
&& w
->cursor
.x
<= h_margin
))
12451 if (hscroll_relative_p
)
12452 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
12455 wanted_x
= text_area_width
12456 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12459 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12463 if (hscroll_relative_p
)
12464 wanted_x
= text_area_width
* hscroll_step_rel
12467 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12470 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12472 hscroll
= max (hscroll
, w
->min_hscroll
);
12474 /* Don't prevent redisplay optimizations if hscroll
12475 hasn't changed, as it will unnecessarily slow down
12477 if (w
->hscroll
!= hscroll
)
12479 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
12480 w
->hscroll
= hscroll
;
12489 /* Value is non-zero if hscroll of any leaf window has been changed. */
12490 return hscrolled_p
;
12494 /* Set hscroll so that cursor is visible and not inside horizontal
12495 scroll margins for all windows in the tree rooted at WINDOW. See
12496 also hscroll_window_tree above. Value is non-zero if any window's
12497 hscroll has been changed. If it has, desired matrices on the frame
12498 of WINDOW are cleared. */
12501 hscroll_windows (Lisp_Object window
)
12503 int hscrolled_p
= hscroll_window_tree (window
);
12505 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
12506 return hscrolled_p
;
12511 /************************************************************************
12513 ************************************************************************/
12515 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
12516 to a non-zero value. This is sometimes handy to have in a debugger
12521 /* First and last unchanged row for try_window_id. */
12523 static int debug_first_unchanged_at_end_vpos
;
12524 static int debug_last_unchanged_at_beg_vpos
;
12526 /* Delta vpos and y. */
12528 static int debug_dvpos
, debug_dy
;
12530 /* Delta in characters and bytes for try_window_id. */
12532 static ptrdiff_t debug_delta
, debug_delta_bytes
;
12534 /* Values of window_end_pos and window_end_vpos at the end of
12537 static ptrdiff_t debug_end_vpos
;
12539 /* Append a string to W->desired_matrix->method. FMT is a printf
12540 format string. If trace_redisplay_p is non-zero also printf the
12541 resulting string to stderr. */
12543 static void debug_method_add (struct window
*, char const *, ...)
12544 ATTRIBUTE_FORMAT_PRINTF (2, 3);
12547 debug_method_add (struct window
*w
, char const *fmt
, ...)
12549 char *method
= w
->desired_matrix
->method
;
12550 int len
= strlen (method
);
12551 int size
= sizeof w
->desired_matrix
->method
;
12552 int remaining
= size
- len
- 1;
12555 if (len
&& remaining
)
12558 --remaining
, ++len
;
12561 va_start (ap
, fmt
);
12562 vsnprintf (method
+ len
, remaining
+ 1, fmt
, ap
);
12565 if (trace_redisplay_p
)
12566 fprintf (stderr
, "%p (%s): %s\n",
12568 ((BUFFERP (w
->buffer
)
12569 && STRINGP (BVAR (XBUFFER (w
->buffer
), name
)))
12570 ? SSDATA (BVAR (XBUFFER (w
->buffer
), name
))
12575 #endif /* GLYPH_DEBUG */
12578 /* Value is non-zero if all changes in window W, which displays
12579 current_buffer, are in the text between START and END. START is a
12580 buffer position, END is given as a distance from Z. Used in
12581 redisplay_internal for display optimization. */
12584 text_outside_line_unchanged_p (struct window
*w
,
12585 ptrdiff_t start
, ptrdiff_t end
)
12587 int unchanged_p
= 1;
12589 /* If text or overlays have changed, see where. */
12590 if (w
->last_modified
< MODIFF
12591 || w
->last_overlay_modified
< OVERLAY_MODIFF
)
12593 /* Gap in the line? */
12594 if (GPT
< start
|| Z
- GPT
< end
)
12597 /* Changes start in front of the line, or end after it? */
12599 && (BEG_UNCHANGED
< start
- 1
12600 || END_UNCHANGED
< end
))
12603 /* If selective display, can't optimize if changes start at the
12604 beginning of the line. */
12606 && INTEGERP (BVAR (current_buffer
, selective_display
))
12607 && XINT (BVAR (current_buffer
, selective_display
)) > 0
12608 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
12611 /* If there are overlays at the start or end of the line, these
12612 may have overlay strings with newlines in them. A change at
12613 START, for instance, may actually concern the display of such
12614 overlay strings as well, and they are displayed on different
12615 lines. So, quickly rule out this case. (For the future, it
12616 might be desirable to implement something more telling than
12617 just BEG/END_UNCHANGED.) */
12620 if (BEG
+ BEG_UNCHANGED
== start
12621 && overlay_touches_p (start
))
12623 if (END_UNCHANGED
== end
12624 && overlay_touches_p (Z
- end
))
12628 /* Under bidi reordering, adding or deleting a character in the
12629 beginning of a paragraph, before the first strong directional
12630 character, can change the base direction of the paragraph (unless
12631 the buffer specifies a fixed paragraph direction), which will
12632 require to redisplay the whole paragraph. It might be worthwhile
12633 to find the paragraph limits and widen the range of redisplayed
12634 lines to that, but for now just give up this optimization. */
12635 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
12636 && NILP (BVAR (XBUFFER (w
->buffer
), bidi_paragraph_direction
)))
12640 return unchanged_p
;
12644 /* Do a frame update, taking possible shortcuts into account. This is
12645 the main external entry point for redisplay.
12647 If the last redisplay displayed an echo area message and that message
12648 is no longer requested, we clear the echo area or bring back the
12649 mini-buffer if that is in use. */
12654 redisplay_internal ();
12659 overlay_arrow_string_or_property (Lisp_Object var
)
12663 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
12666 return Voverlay_arrow_string
;
12669 /* Return 1 if there are any overlay-arrows in current_buffer. */
12671 overlay_arrow_in_current_buffer_p (void)
12675 for (vlist
= Voverlay_arrow_variable_list
;
12677 vlist
= XCDR (vlist
))
12679 Lisp_Object var
= XCAR (vlist
);
12682 if (!SYMBOLP (var
))
12684 val
= find_symbol_value (var
);
12686 && current_buffer
== XMARKER (val
)->buffer
)
12693 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
12697 overlay_arrows_changed_p (void)
12701 for (vlist
= Voverlay_arrow_variable_list
;
12703 vlist
= XCDR (vlist
))
12705 Lisp_Object var
= XCAR (vlist
);
12706 Lisp_Object val
, pstr
;
12708 if (!SYMBOLP (var
))
12710 val
= find_symbol_value (var
);
12711 if (!MARKERP (val
))
12713 if (! EQ (COERCE_MARKER (val
),
12714 Fget (var
, Qlast_arrow_position
))
12715 || ! (pstr
= overlay_arrow_string_or_property (var
),
12716 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
12722 /* Mark overlay arrows to be updated on next redisplay. */
12725 update_overlay_arrows (int up_to_date
)
12729 for (vlist
= Voverlay_arrow_variable_list
;
12731 vlist
= XCDR (vlist
))
12733 Lisp_Object var
= XCAR (vlist
);
12735 if (!SYMBOLP (var
))
12738 if (up_to_date
> 0)
12740 Lisp_Object val
= find_symbol_value (var
);
12741 Fput (var
, Qlast_arrow_position
,
12742 COERCE_MARKER (val
));
12743 Fput (var
, Qlast_arrow_string
,
12744 overlay_arrow_string_or_property (var
));
12746 else if (up_to_date
< 0
12747 || !NILP (Fget (var
, Qlast_arrow_position
)))
12749 Fput (var
, Qlast_arrow_position
, Qt
);
12750 Fput (var
, Qlast_arrow_string
, Qt
);
12756 /* Return overlay arrow string to display at row.
12757 Return integer (bitmap number) for arrow bitmap in left fringe.
12758 Return nil if no overlay arrow. */
12761 overlay_arrow_at_row (struct it
*it
, struct glyph_row
*row
)
12765 for (vlist
= Voverlay_arrow_variable_list
;
12767 vlist
= XCDR (vlist
))
12769 Lisp_Object var
= XCAR (vlist
);
12772 if (!SYMBOLP (var
))
12775 val
= find_symbol_value (var
);
12778 && current_buffer
== XMARKER (val
)->buffer
12779 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
12781 if (FRAME_WINDOW_P (it
->f
)
12782 /* FIXME: if ROW->reversed_p is set, this should test
12783 the right fringe, not the left one. */
12784 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
12786 #ifdef HAVE_WINDOW_SYSTEM
12787 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
12790 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
12791 return make_number (fringe_bitmap
);
12794 return make_number (-1); /* Use default arrow bitmap. */
12796 return overlay_arrow_string_or_property (var
);
12803 /* Return 1 if point moved out of or into a composition. Otherwise
12804 return 0. PREV_BUF and PREV_PT are the last point buffer and
12805 position. BUF and PT are the current point buffer and position. */
12808 check_point_in_composition (struct buffer
*prev_buf
, ptrdiff_t prev_pt
,
12809 struct buffer
*buf
, ptrdiff_t pt
)
12811 ptrdiff_t start
, end
;
12813 Lisp_Object buffer
;
12815 XSETBUFFER (buffer
, buf
);
12816 /* Check a composition at the last point if point moved within the
12818 if (prev_buf
== buf
)
12821 /* Point didn't move. */
12824 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
12825 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
12826 && COMPOSITION_VALID_P (start
, end
, prop
)
12827 && start
< prev_pt
&& end
> prev_pt
)
12828 /* The last point was within the composition. Return 1 iff
12829 point moved out of the composition. */
12830 return (pt
<= start
|| pt
>= end
);
12833 /* Check a composition at the current point. */
12834 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
12835 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
12836 && COMPOSITION_VALID_P (start
, end
, prop
)
12837 && start
< pt
&& end
> pt
);
12841 /* Reconsider the setting of B->clip_changed which is displayed
12845 reconsider_clip_changes (struct window
*w
, struct buffer
*b
)
12847 if (b
->clip_changed
12848 && !NILP (w
->window_end_valid
)
12849 && w
->current_matrix
->buffer
== b
12850 && w
->current_matrix
->zv
== BUF_ZV (b
)
12851 && w
->current_matrix
->begv
== BUF_BEGV (b
))
12852 b
->clip_changed
= 0;
12854 /* If display wasn't paused, and W is not a tool bar window, see if
12855 point has been moved into or out of a composition. In that case,
12856 we set b->clip_changed to 1 to force updating the screen. If
12857 b->clip_changed has already been set to 1, we can skip this
12859 if (!b
->clip_changed
12860 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
12864 if (w
== XWINDOW (selected_window
))
12867 pt
= marker_position (w
->pointm
);
12869 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
12870 || pt
!= w
->last_point
)
12871 && check_point_in_composition (w
->current_matrix
->buffer
,
12873 XBUFFER (w
->buffer
), pt
))
12874 b
->clip_changed
= 1;
12879 /* Select FRAME to forward the values of frame-local variables into C
12880 variables so that the redisplay routines can access those values
12884 select_frame_for_redisplay (Lisp_Object frame
)
12886 Lisp_Object tail
, tem
;
12887 Lisp_Object old
= selected_frame
;
12888 struct Lisp_Symbol
*sym
;
12890 eassert (FRAMEP (frame
) && FRAME_LIVE_P (XFRAME (frame
)));
12892 selected_frame
= frame
;
12895 for (tail
= XFRAME (frame
)->param_alist
;
12896 CONSP (tail
); tail
= XCDR (tail
))
12897 if (CONSP (XCAR (tail
))
12898 && (tem
= XCAR (XCAR (tail
)),
12900 && (sym
= indirect_variable (XSYMBOL (tem
)),
12901 sym
->redirect
== SYMBOL_LOCALIZED
)
12902 && sym
->val
.blv
->frame_local
)
12903 /* Use find_symbol_value rather than Fsymbol_value
12904 to avoid an error if it is void. */
12905 find_symbol_value (tem
);
12906 } while (!EQ (frame
, old
) && (frame
= old
, 1));
12910 #define STOP_POLLING \
12911 do { if (! polling_stopped_here) stop_polling (); \
12912 polling_stopped_here = 1; } while (0)
12914 #define RESUME_POLLING \
12915 do { if (polling_stopped_here) start_polling (); \
12916 polling_stopped_here = 0; } while (0)
12919 /* Perhaps in the future avoid recentering windows if it
12920 is not necessary; currently that causes some problems. */
12923 redisplay_internal (void)
12925 struct window
*w
= XWINDOW (selected_window
);
12929 int must_finish
= 0;
12930 struct text_pos tlbufpos
, tlendpos
;
12931 int number_of_visible_frames
;
12932 ptrdiff_t count
, count1
;
12934 int polling_stopped_here
= 0;
12935 Lisp_Object old_frame
= selected_frame
;
12937 /* Non-zero means redisplay has to consider all windows on all
12938 frames. Zero means, only selected_window is considered. */
12939 int consider_all_windows_p
;
12941 /* Non-zero means redisplay has to redisplay the miniwindow */
12942 int update_miniwindow_p
= 0;
12944 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
12946 /* No redisplay if running in batch mode or frame is not yet fully
12947 initialized, or redisplay is explicitly turned off by setting
12948 Vinhibit_redisplay. */
12949 if (FRAME_INITIAL_P (SELECTED_FRAME ())
12950 || !NILP (Vinhibit_redisplay
))
12953 /* Don't examine these until after testing Vinhibit_redisplay.
12954 When Emacs is shutting down, perhaps because its connection to
12955 X has dropped, we should not look at them at all. */
12956 fr
= XFRAME (w
->frame
);
12957 sf
= SELECTED_FRAME ();
12959 if (!fr
->glyphs_initialized_p
)
12962 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
12963 if (popup_activated ())
12967 /* I don't think this happens but let's be paranoid. */
12968 if (redisplaying_p
)
12971 /* Record a function that clears redisplaying_p
12972 when we leave this function. */
12973 count
= SPECPDL_INDEX ();
12974 record_unwind_protect (unwind_redisplay
, selected_frame
);
12975 redisplaying_p
= 1;
12976 specbind (Qinhibit_free_realized_faces
, Qnil
);
12979 Lisp_Object tail
, frame
;
12981 FOR_EACH_FRAME (tail
, frame
)
12983 struct frame
*f
= XFRAME (frame
);
12984 f
->already_hscrolled_p
= 0;
12989 /* Remember the currently selected window. */
12992 if (!EQ (old_frame
, selected_frame
)
12993 && FRAME_LIVE_P (XFRAME (old_frame
)))
12994 /* When running redisplay, we play a bit fast-and-loose and allow e.g.
12995 selected_frame and selected_window to be temporarily out-of-sync so
12996 when we come back here via `goto retry', we need to resync because we
12997 may need to run Elisp code (via prepare_menu_bars). */
12998 select_frame_for_redisplay (old_frame
);
13001 reconsider_clip_changes (w
, current_buffer
);
13002 last_escape_glyph_frame
= NULL
;
13003 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
13004 last_glyphless_glyph_frame
= NULL
;
13005 last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
13007 /* If new fonts have been loaded that make a glyph matrix adjustment
13008 necessary, do it. */
13009 if (fonts_changed_p
)
13011 adjust_glyphs (NULL
);
13012 ++windows_or_buffers_changed
;
13013 fonts_changed_p
= 0;
13016 /* If face_change_count is non-zero, init_iterator will free all
13017 realized faces, which includes the faces referenced from current
13018 matrices. So, we can't reuse current matrices in this case. */
13019 if (face_change_count
)
13020 ++windows_or_buffers_changed
;
13022 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
13023 && FRAME_TTY (sf
)->previous_frame
!= sf
)
13025 /* Since frames on a single ASCII terminal share the same
13026 display area, displaying a different frame means redisplay
13027 the whole thing. */
13028 windows_or_buffers_changed
++;
13029 SET_FRAME_GARBAGED (sf
);
13031 set_tty_color_mode (FRAME_TTY (sf
), sf
);
13033 FRAME_TTY (sf
)->previous_frame
= sf
;
13036 /* Set the visible flags for all frames. Do this before checking
13037 for resized or garbaged frames; they want to know if their frames
13038 are visible. See the comment in frame.h for
13039 FRAME_SAMPLE_VISIBILITY. */
13041 Lisp_Object tail
, frame
;
13043 number_of_visible_frames
= 0;
13045 FOR_EACH_FRAME (tail
, frame
)
13047 struct frame
*f
= XFRAME (frame
);
13049 FRAME_SAMPLE_VISIBILITY (f
);
13050 if (FRAME_VISIBLE_P (f
))
13051 ++number_of_visible_frames
;
13052 clear_desired_matrices (f
);
13056 /* Notice any pending interrupt request to change frame size. */
13057 do_pending_window_change (1);
13059 /* do_pending_window_change could change the selected_window due to
13060 frame resizing which makes the selected window too small. */
13061 if (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
)
13064 reconsider_clip_changes (w
, current_buffer
);
13067 /* Clear frames marked as garbaged. */
13068 if (frame_garbaged
)
13069 clear_garbaged_frames ();
13071 /* Build menubar and tool-bar items. */
13072 if (NILP (Vmemory_full
))
13073 prepare_menu_bars ();
13075 if (windows_or_buffers_changed
)
13076 update_mode_lines
++;
13078 /* Detect case that we need to write or remove a star in the mode line. */
13079 if ((SAVE_MODIFF
< MODIFF
) != w
->last_had_star
)
13081 w
->update_mode_line
= 1;
13082 if (buffer_shared
> 1)
13083 update_mode_lines
++;
13086 /* Avoid invocation of point motion hooks by `current_column' below. */
13087 count1
= SPECPDL_INDEX ();
13088 specbind (Qinhibit_point_motion_hooks
, Qt
);
13090 /* If %c is in the mode line, update it if needed. */
13091 if (!NILP (w
->column_number_displayed
)
13092 /* This alternative quickly identifies a common case
13093 where no change is needed. */
13094 && !(PT
== w
->last_point
13095 && w
->last_modified
>= MODIFF
13096 && w
->last_overlay_modified
>= OVERLAY_MODIFF
)
13097 && (XFASTINT (w
->column_number_displayed
) != current_column ()))
13098 w
->update_mode_line
= 1;
13100 unbind_to (count1
, Qnil
);
13102 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
13104 /* The variable buffer_shared is set in redisplay_window and
13105 indicates that we redisplay a buffer in different windows. See
13107 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
13108 || cursor_type_changed
);
13110 /* If specs for an arrow have changed, do thorough redisplay
13111 to ensure we remove any arrow that should no longer exist. */
13112 if (overlay_arrows_changed_p ())
13113 consider_all_windows_p
= windows_or_buffers_changed
= 1;
13115 /* Normally the message* functions will have already displayed and
13116 updated the echo area, but the frame may have been trashed, or
13117 the update may have been preempted, so display the echo area
13118 again here. Checking message_cleared_p captures the case that
13119 the echo area should be cleared. */
13120 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
13121 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
13122 || (message_cleared_p
13123 && minibuf_level
== 0
13124 /* If the mini-window is currently selected, this means the
13125 echo-area doesn't show through. */
13126 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
13128 int window_height_changed_p
= echo_area_display (0);
13130 if (message_cleared_p
)
13131 update_miniwindow_p
= 1;
13135 /* If we don't display the current message, don't clear the
13136 message_cleared_p flag, because, if we did, we wouldn't clear
13137 the echo area in the next redisplay which doesn't preserve
13139 if (!display_last_displayed_message_p
)
13140 message_cleared_p
= 0;
13142 if (fonts_changed_p
)
13144 else if (window_height_changed_p
)
13146 consider_all_windows_p
= 1;
13147 ++update_mode_lines
;
13148 ++windows_or_buffers_changed
;
13150 /* If window configuration was changed, frames may have been
13151 marked garbaged. Clear them or we will experience
13152 surprises wrt scrolling. */
13153 if (frame_garbaged
)
13154 clear_garbaged_frames ();
13157 else if (EQ (selected_window
, minibuf_window
)
13158 && (current_buffer
->clip_changed
13159 || w
->last_modified
< MODIFF
13160 || w
->last_overlay_modified
< OVERLAY_MODIFF
)
13161 && resize_mini_window (w
, 0))
13163 /* Resized active mini-window to fit the size of what it is
13164 showing if its contents might have changed. */
13166 /* FIXME: this causes all frames to be updated, which seems unnecessary
13167 since only the current frame needs to be considered. This function needs
13168 to be rewritten with two variables, consider_all_windows and
13169 consider_all_frames. */
13170 consider_all_windows_p
= 1;
13171 ++windows_or_buffers_changed
;
13172 ++update_mode_lines
;
13174 /* If window configuration was changed, frames may have been
13175 marked garbaged. Clear them or we will experience
13176 surprises wrt scrolling. */
13177 if (frame_garbaged
)
13178 clear_garbaged_frames ();
13182 /* If showing the region, and mark has changed, we must redisplay
13183 the whole window. The assignment to this_line_start_pos prevents
13184 the optimization directly below this if-statement. */
13185 if (((!NILP (Vtransient_mark_mode
)
13186 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
13187 != !NILP (w
->region_showing
))
13188 || (!NILP (w
->region_showing
)
13189 && !EQ (w
->region_showing
,
13190 Fmarker_position (BVAR (XBUFFER (w
->buffer
), mark
)))))
13191 CHARPOS (this_line_start_pos
) = 0;
13193 /* Optimize the case that only the line containing the cursor in the
13194 selected window has changed. Variables starting with this_ are
13195 set in display_line and record information about the line
13196 containing the cursor. */
13197 tlbufpos
= this_line_start_pos
;
13198 tlendpos
= this_line_end_pos
;
13199 if (!consider_all_windows_p
13200 && CHARPOS (tlbufpos
) > 0
13201 && !w
->update_mode_line
13202 && !current_buffer
->clip_changed
13203 && !current_buffer
->prevent_redisplay_optimizations_p
13204 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
13205 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
13206 /* Make sure recorded data applies to current buffer, etc. */
13207 && this_line_buffer
== current_buffer
13208 && current_buffer
== XBUFFER (w
->buffer
)
13210 && !w
->optional_new_start
13211 /* Point must be on the line that we have info recorded about. */
13212 && PT
>= CHARPOS (tlbufpos
)
13213 && PT
<= Z
- CHARPOS (tlendpos
)
13214 /* All text outside that line, including its final newline,
13215 must be unchanged. */
13216 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
13217 CHARPOS (tlendpos
)))
13219 if (CHARPOS (tlbufpos
) > BEGV
13220 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
13221 && (CHARPOS (tlbufpos
) == ZV
13222 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
13223 /* Former continuation line has disappeared by becoming empty. */
13225 else if (w
->last_modified
< MODIFF
13226 || w
->last_overlay_modified
< OVERLAY_MODIFF
13227 || MINI_WINDOW_P (w
))
13229 /* We have to handle the case of continuation around a
13230 wide-column character (see the comment in indent.c around
13233 For instance, in the following case:
13235 -------- Insert --------
13236 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
13237 J_I_ ==> J_I_ `^^' are cursors.
13241 As we have to redraw the line above, we cannot use this
13245 int line_height_before
= this_line_pixel_height
;
13247 /* Note that start_display will handle the case that the
13248 line starting at tlbufpos is a continuation line. */
13249 start_display (&it
, w
, tlbufpos
);
13251 /* Implementation note: It this still necessary? */
13252 if (it
.current_x
!= this_line_start_x
)
13255 TRACE ((stderr
, "trying display optimization 1\n"));
13256 w
->cursor
.vpos
= -1;
13257 overlay_arrow_seen
= 0;
13258 it
.vpos
= this_line_vpos
;
13259 it
.current_y
= this_line_y
;
13260 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
13261 display_line (&it
);
13263 /* If line contains point, is not continued,
13264 and ends at same distance from eob as before, we win. */
13265 if (w
->cursor
.vpos
>= 0
13266 /* Line is not continued, otherwise this_line_start_pos
13267 would have been set to 0 in display_line. */
13268 && CHARPOS (this_line_start_pos
)
13269 /* Line ends as before. */
13270 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
13271 /* Line has same height as before. Otherwise other lines
13272 would have to be shifted up or down. */
13273 && this_line_pixel_height
== line_height_before
)
13275 /* If this is not the window's last line, we must adjust
13276 the charstarts of the lines below. */
13277 if (it
.current_y
< it
.last_visible_y
)
13279 struct glyph_row
*row
13280 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
13281 ptrdiff_t delta
, delta_bytes
;
13283 /* We used to distinguish between two cases here,
13284 conditioned by Z - CHARPOS (tlendpos) == ZV, for
13285 when the line ends in a newline or the end of the
13286 buffer's accessible portion. But both cases did
13287 the same, so they were collapsed. */
13289 - CHARPOS (tlendpos
)
13290 - MATRIX_ROW_START_CHARPOS (row
));
13291 delta_bytes
= (Z_BYTE
13292 - BYTEPOS (tlendpos
)
13293 - MATRIX_ROW_START_BYTEPOS (row
));
13295 increment_matrix_positions (w
->current_matrix
,
13296 this_line_vpos
+ 1,
13297 w
->current_matrix
->nrows
,
13298 delta
, delta_bytes
);
13301 /* If this row displays text now but previously didn't,
13302 or vice versa, w->window_end_vpos may have to be
13304 if ((it
.glyph_row
- 1)->displays_text_p
)
13306 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
13307 wset_window_end_vpos (w
, make_number (this_line_vpos
));
13309 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
13310 && this_line_vpos
> 0)
13311 wset_window_end_vpos (w
, make_number (this_line_vpos
- 1));
13312 wset_window_end_valid (w
, Qnil
);
13314 /* Update hint: No need to try to scroll in update_window. */
13315 w
->desired_matrix
->no_scrolling_p
= 1;
13318 *w
->desired_matrix
->method
= 0;
13319 debug_method_add (w
, "optimization 1");
13321 #ifdef HAVE_WINDOW_SYSTEM
13322 update_window_fringes (w
, 0);
13329 else if (/* Cursor position hasn't changed. */
13330 PT
== w
->last_point
13331 /* Make sure the cursor was last displayed
13332 in this window. Otherwise we have to reposition it. */
13333 && 0 <= w
->cursor
.vpos
13334 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
13338 do_pending_window_change (1);
13339 /* If selected_window changed, redisplay again. */
13340 if (WINDOWP (selected_window
)
13341 && (w
= XWINDOW (selected_window
)) != sw
)
13344 /* We used to always goto end_of_redisplay here, but this
13345 isn't enough if we have a blinking cursor. */
13346 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
13347 goto end_of_redisplay
;
13351 /* If highlighting the region, or if the cursor is in the echo area,
13352 then we can't just move the cursor. */
13353 else if (! (!NILP (Vtransient_mark_mode
)
13354 && !NILP (BVAR (current_buffer
, mark_active
)))
13355 && (EQ (selected_window
,
13356 BVAR (current_buffer
, last_selected_window
))
13357 || highlight_nonselected_windows
)
13358 && NILP (w
->region_showing
)
13359 && NILP (Vshow_trailing_whitespace
)
13360 && !cursor_in_echo_area
)
13363 struct glyph_row
*row
;
13365 /* Skip from tlbufpos to PT and see where it is. Note that
13366 PT may be in invisible text. If so, we will end at the
13367 next visible position. */
13368 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
13369 NULL
, DEFAULT_FACE_ID
);
13370 it
.current_x
= this_line_start_x
;
13371 it
.current_y
= this_line_y
;
13372 it
.vpos
= this_line_vpos
;
13374 /* The call to move_it_to stops in front of PT, but
13375 moves over before-strings. */
13376 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
13378 if (it
.vpos
== this_line_vpos
13379 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
13382 eassert (this_line_vpos
== it
.vpos
);
13383 eassert (this_line_y
== it
.current_y
);
13384 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13386 *w
->desired_matrix
->method
= 0;
13387 debug_method_add (w
, "optimization 3");
13396 /* Text changed drastically or point moved off of line. */
13397 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
13400 CHARPOS (this_line_start_pos
) = 0;
13401 consider_all_windows_p
|= buffer_shared
> 1;
13402 ++clear_face_cache_count
;
13403 #ifdef HAVE_WINDOW_SYSTEM
13404 ++clear_image_cache_count
;
13407 /* Build desired matrices, and update the display. If
13408 consider_all_windows_p is non-zero, do it for all windows on all
13409 frames. Otherwise do it for selected_window, only. */
13411 if (consider_all_windows_p
)
13413 Lisp_Object tail
, frame
;
13415 FOR_EACH_FRAME (tail
, frame
)
13416 XFRAME (frame
)->updated_p
= 0;
13418 /* Recompute # windows showing selected buffer. This will be
13419 incremented each time such a window is displayed. */
13422 FOR_EACH_FRAME (tail
, frame
)
13424 struct frame
*f
= XFRAME (frame
);
13426 /* We don't have to do anything for unselected terminal
13428 if ((FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
13429 && !EQ (FRAME_TTY (f
)->top_frame
, frame
))
13432 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
13434 if (! EQ (frame
, selected_frame
))
13435 /* Select the frame, for the sake of frame-local
13437 select_frame_for_redisplay (frame
);
13439 /* Mark all the scroll bars to be removed; we'll redeem
13440 the ones we want when we redisplay their windows. */
13441 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
13442 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
13444 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13445 redisplay_windows (FRAME_ROOT_WINDOW (f
));
13447 /* The X error handler may have deleted that frame. */
13448 if (!FRAME_LIVE_P (f
))
13451 /* Any scroll bars which redisplay_windows should have
13452 nuked should now go away. */
13453 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
13454 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
13456 /* If fonts changed, display again. */
13457 /* ??? rms: I suspect it is a mistake to jump all the way
13458 back to retry here. It should just retry this frame. */
13459 if (fonts_changed_p
)
13462 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13464 /* See if we have to hscroll. */
13465 if (!f
->already_hscrolled_p
)
13467 f
->already_hscrolled_p
= 1;
13468 if (hscroll_windows (f
->root_window
))
13472 /* Prevent various kinds of signals during display
13473 update. stdio is not robust about handling
13474 signals, which can cause an apparent I/O
13476 if (interrupt_input
)
13477 unrequest_sigio ();
13480 /* Update the display. */
13481 set_window_update_flags (XWINDOW (f
->root_window
), 1);
13482 pending
|= update_frame (f
, 0, 0);
13488 if (!EQ (old_frame
, selected_frame
)
13489 && FRAME_LIVE_P (XFRAME (old_frame
)))
13490 /* We played a bit fast-and-loose above and allowed selected_frame
13491 and selected_window to be temporarily out-of-sync but let's make
13492 sure this stays contained. */
13493 select_frame_for_redisplay (old_frame
);
13494 eassert (EQ (XFRAME (selected_frame
)->selected_window
,
13499 /* Do the mark_window_display_accurate after all windows have
13500 been redisplayed because this call resets flags in buffers
13501 which are needed for proper redisplay. */
13502 FOR_EACH_FRAME (tail
, frame
)
13504 struct frame
*f
= XFRAME (frame
);
13507 mark_window_display_accurate (f
->root_window
, 1);
13508 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
13509 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
13514 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13516 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13517 struct frame
*mini_frame
;
13519 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
13520 /* Use list_of_error, not Qerror, so that
13521 we catch only errors and don't run the debugger. */
13522 internal_condition_case_1 (redisplay_window_1
, selected_window
,
13524 redisplay_window_error
);
13525 if (update_miniwindow_p
)
13526 internal_condition_case_1 (redisplay_window_1
, mini_window
,
13528 redisplay_window_error
);
13530 /* Compare desired and current matrices, perform output. */
13533 /* If fonts changed, display again. */
13534 if (fonts_changed_p
)
13537 /* Prevent various kinds of signals during display update.
13538 stdio is not robust about handling signals,
13539 which can cause an apparent I/O error. */
13540 if (interrupt_input
)
13541 unrequest_sigio ();
13544 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13546 if (hscroll_windows (selected_window
))
13549 XWINDOW (selected_window
)->must_be_updated_p
= 1;
13550 pending
= update_frame (sf
, 0, 0);
13553 /* We may have called echo_area_display at the top of this
13554 function. If the echo area is on another frame, that may
13555 have put text on a frame other than the selected one, so the
13556 above call to update_frame would not have caught it. Catch
13558 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13559 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
13561 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
13563 XWINDOW (mini_window
)->must_be_updated_p
= 1;
13564 pending
|= update_frame (mini_frame
, 0, 0);
13565 if (!pending
&& hscroll_windows (mini_window
))
13570 /* If display was paused because of pending input, make sure we do a
13571 thorough update the next time. */
13574 /* Prevent the optimization at the beginning of
13575 redisplay_internal that tries a single-line update of the
13576 line containing the cursor in the selected window. */
13577 CHARPOS (this_line_start_pos
) = 0;
13579 /* Let the overlay arrow be updated the next time. */
13580 update_overlay_arrows (0);
13582 /* If we pause after scrolling, some rows in the current
13583 matrices of some windows are not valid. */
13584 if (!WINDOW_FULL_WIDTH_P (w
)
13585 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
13586 update_mode_lines
= 1;
13590 if (!consider_all_windows_p
)
13592 /* This has already been done above if
13593 consider_all_windows_p is set. */
13594 mark_window_display_accurate_1 (w
, 1);
13596 /* Say overlay arrows are up to date. */
13597 update_overlay_arrows (1);
13599 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
13600 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
13603 update_mode_lines
= 0;
13604 windows_or_buffers_changed
= 0;
13605 cursor_type_changed
= 0;
13608 /* Start SIGIO interrupts coming again. Having them off during the
13609 code above makes it less likely one will discard output, but not
13610 impossible, since there might be stuff in the system buffer here.
13611 But it is much hairier to try to do anything about that. */
13612 if (interrupt_input
)
13616 /* If a frame has become visible which was not before, redisplay
13617 again, so that we display it. Expose events for such a frame
13618 (which it gets when becoming visible) don't call the parts of
13619 redisplay constructing glyphs, so simply exposing a frame won't
13620 display anything in this case. So, we have to display these
13621 frames here explicitly. */
13624 Lisp_Object tail
, frame
;
13627 FOR_EACH_FRAME (tail
, frame
)
13629 int this_is_visible
= 0;
13631 if (XFRAME (frame
)->visible
)
13632 this_is_visible
= 1;
13633 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
13634 if (XFRAME (frame
)->visible
)
13635 this_is_visible
= 1;
13637 if (this_is_visible
)
13641 if (new_count
!= number_of_visible_frames
)
13642 windows_or_buffers_changed
++;
13645 /* Change frame size now if a change is pending. */
13646 do_pending_window_change (1);
13648 /* If we just did a pending size change, or have additional
13649 visible frames, or selected_window changed, redisplay again. */
13650 if ((windows_or_buffers_changed
&& !pending
)
13651 || (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
))
13654 /* Clear the face and image caches.
13656 We used to do this only if consider_all_windows_p. But the cache
13657 needs to be cleared if a timer creates images in the current
13658 buffer (e.g. the test case in Bug#6230). */
13660 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
13662 clear_face_cache (0);
13663 clear_face_cache_count
= 0;
13666 #ifdef HAVE_WINDOW_SYSTEM
13667 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
13669 clear_image_caches (Qnil
);
13670 clear_image_cache_count
= 0;
13672 #endif /* HAVE_WINDOW_SYSTEM */
13675 unbind_to (count
, Qnil
);
13680 /* Redisplay, but leave alone any recent echo area message unless
13681 another message has been requested in its place.
13683 This is useful in situations where you need to redisplay but no
13684 user action has occurred, making it inappropriate for the message
13685 area to be cleared. See tracking_off and
13686 wait_reading_process_output for examples of these situations.
13688 FROM_WHERE is an integer saying from where this function was
13689 called. This is useful for debugging. */
13692 redisplay_preserve_echo_area (int from_where
)
13694 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
13696 if (!NILP (echo_area_buffer
[1]))
13698 /* We have a previously displayed message, but no current
13699 message. Redisplay the previous message. */
13700 display_last_displayed_message_p
= 1;
13701 redisplay_internal ();
13702 display_last_displayed_message_p
= 0;
13705 redisplay_internal ();
13707 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
13708 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
13709 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
13713 /* Function registered with record_unwind_protect in redisplay_internal.
13714 Clear redisplaying_p. Also, select the previously
13715 selected frame, unless it has been deleted (by an X connection
13716 failure during redisplay, for example). */
13719 unwind_redisplay (Lisp_Object old_frame
)
13721 redisplaying_p
= 0;
13722 if (! EQ (old_frame
, selected_frame
)
13723 && FRAME_LIVE_P (XFRAME (old_frame
)))
13724 select_frame_for_redisplay (old_frame
);
13729 /* Mark the display of window W as accurate or inaccurate. If
13730 ACCURATE_P is non-zero mark display of W as accurate. If
13731 ACCURATE_P is zero, arrange for W to be redisplayed the next time
13732 redisplay_internal is called. */
13735 mark_window_display_accurate_1 (struct window
*w
, int accurate_p
)
13737 if (BUFFERP (w
->buffer
))
13739 struct buffer
*b
= XBUFFER (w
->buffer
);
13741 w
->last_modified
= accurate_p
? BUF_MODIFF(b
) : 0;
13742 w
->last_overlay_modified
= accurate_p
? BUF_OVERLAY_MODIFF(b
) : 0;
13744 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
);
13748 b
->clip_changed
= 0;
13749 b
->prevent_redisplay_optimizations_p
= 0;
13751 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
13752 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
13753 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
13754 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
13756 w
->current_matrix
->buffer
= b
;
13757 w
->current_matrix
->begv
= BUF_BEGV (b
);
13758 w
->current_matrix
->zv
= BUF_ZV (b
);
13760 w
->last_cursor
= w
->cursor
;
13761 w
->last_cursor_off_p
= w
->cursor_off_p
;
13763 if (w
== XWINDOW (selected_window
))
13764 w
->last_point
= BUF_PT (b
);
13766 w
->last_point
= XMARKER (w
->pointm
)->charpos
;
13772 wset_window_end_valid (w
, w
->buffer
);
13773 w
->update_mode_line
= 0;
13778 /* Mark the display of windows in the window tree rooted at WINDOW as
13779 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
13780 windows as accurate. If ACCURATE_P is zero, arrange for windows to
13781 be redisplayed the next time redisplay_internal is called. */
13784 mark_window_display_accurate (Lisp_Object window
, int accurate_p
)
13788 for (; !NILP (window
); window
= w
->next
)
13790 w
= XWINDOW (window
);
13791 mark_window_display_accurate_1 (w
, accurate_p
);
13793 if (!NILP (w
->vchild
))
13794 mark_window_display_accurate (w
->vchild
, accurate_p
);
13795 if (!NILP (w
->hchild
))
13796 mark_window_display_accurate (w
->hchild
, accurate_p
);
13801 update_overlay_arrows (1);
13805 /* Force a thorough redisplay the next time by setting
13806 last_arrow_position and last_arrow_string to t, which is
13807 unequal to any useful value of Voverlay_arrow_... */
13808 update_overlay_arrows (-1);
13813 /* Return value in display table DP (Lisp_Char_Table *) for character
13814 C. Since a display table doesn't have any parent, we don't have to
13815 follow parent. Do not call this function directly but use the
13816 macro DISP_CHAR_VECTOR. */
13819 disp_char_vector (struct Lisp_Char_Table
*dp
, int c
)
13823 if (ASCII_CHAR_P (c
))
13826 if (SUB_CHAR_TABLE_P (val
))
13827 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
13833 XSETCHAR_TABLE (table
, dp
);
13834 val
= char_table_ref (table
, c
);
13843 /***********************************************************************
13845 ***********************************************************************/
13847 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
13850 redisplay_windows (Lisp_Object window
)
13852 while (!NILP (window
))
13854 struct window
*w
= XWINDOW (window
);
13856 if (!NILP (w
->hchild
))
13857 redisplay_windows (w
->hchild
);
13858 else if (!NILP (w
->vchild
))
13859 redisplay_windows (w
->vchild
);
13860 else if (!NILP (w
->buffer
))
13862 displayed_buffer
= XBUFFER (w
->buffer
);
13863 /* Use list_of_error, not Qerror, so that
13864 we catch only errors and don't run the debugger. */
13865 internal_condition_case_1 (redisplay_window_0
, window
,
13867 redisplay_window_error
);
13875 redisplay_window_error (Lisp_Object ignore
)
13877 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
13882 redisplay_window_0 (Lisp_Object window
)
13884 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
13885 redisplay_window (window
, 0);
13890 redisplay_window_1 (Lisp_Object window
)
13892 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
13893 redisplay_window (window
, 1);
13898 /* Set cursor position of W. PT is assumed to be displayed in ROW.
13899 DELTA and DELTA_BYTES are the numbers of characters and bytes by
13900 which positions recorded in ROW differ from current buffer
13903 Return 0 if cursor is not on this row, 1 otherwise. */
13906 set_cursor_from_row (struct window
*w
, struct glyph_row
*row
,
13907 struct glyph_matrix
*matrix
,
13908 ptrdiff_t delta
, ptrdiff_t delta_bytes
,
13911 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
13912 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
13913 struct glyph
*cursor
= NULL
;
13914 /* The last known character position in row. */
13915 ptrdiff_t last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13917 ptrdiff_t pt_old
= PT
- delta
;
13918 ptrdiff_t pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13919 ptrdiff_t pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
13920 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
13921 /* A glyph beyond the edge of TEXT_AREA which we should never
13923 struct glyph
*glyphs_end
= end
;
13924 /* Non-zero means we've found a match for cursor position, but that
13925 glyph has the avoid_cursor_p flag set. */
13926 int match_with_avoid_cursor
= 0;
13927 /* Non-zero means we've seen at least one glyph that came from a
13929 int string_seen
= 0;
13930 /* Largest and smallest buffer positions seen so far during scan of
13932 ptrdiff_t bpos_max
= pos_before
;
13933 ptrdiff_t bpos_min
= pos_after
;
13934 /* Last buffer position covered by an overlay string with an integer
13935 `cursor' property. */
13936 ptrdiff_t bpos_covered
= 0;
13937 /* Non-zero means the display string on which to display the cursor
13938 comes from a text property, not from an overlay. */
13939 int string_from_text_prop
= 0;
13941 /* Don't even try doing anything if called for a mode-line or
13942 header-line row, since the rest of the code isn't prepared to
13943 deal with such calamities. */
13944 eassert (!row
->mode_line_p
);
13945 if (row
->mode_line_p
)
13948 /* Skip over glyphs not having an object at the start and the end of
13949 the row. These are special glyphs like truncation marks on
13950 terminal frames. */
13951 if (row
->displays_text_p
)
13953 if (!row
->reversed_p
)
13956 && INTEGERP (glyph
->object
)
13957 && glyph
->charpos
< 0)
13959 x
+= glyph
->pixel_width
;
13963 && INTEGERP ((end
- 1)->object
)
13964 /* CHARPOS is zero for blanks and stretch glyphs
13965 inserted by extend_face_to_end_of_line. */
13966 && (end
- 1)->charpos
<= 0)
13968 glyph_before
= glyph
- 1;
13975 /* If the glyph row is reversed, we need to process it from back
13976 to front, so swap the edge pointers. */
13977 glyphs_end
= end
= glyph
- 1;
13978 glyph
+= row
->used
[TEXT_AREA
] - 1;
13980 while (glyph
> end
+ 1
13981 && INTEGERP (glyph
->object
)
13982 && glyph
->charpos
< 0)
13985 x
-= glyph
->pixel_width
;
13987 if (INTEGERP (glyph
->object
) && glyph
->charpos
< 0)
13989 /* By default, in reversed rows we put the cursor on the
13990 rightmost (first in the reading order) glyph. */
13991 for (g
= end
+ 1; g
< glyph
; g
++)
13992 x
+= g
->pixel_width
;
13994 && INTEGERP ((end
+ 1)->object
)
13995 && (end
+ 1)->charpos
<= 0)
13997 glyph_before
= glyph
+ 1;
14001 else if (row
->reversed_p
)
14003 /* In R2L rows that don't display text, put the cursor on the
14004 rightmost glyph. Case in point: an empty last line that is
14005 part of an R2L paragraph. */
14007 /* Avoid placing the cursor on the last glyph of the row, where
14008 on terminal frames we hold the vertical border between
14009 adjacent windows. */
14010 if (!FRAME_WINDOW_P (WINDOW_XFRAME (w
))
14011 && !WINDOW_RIGHTMOST_P (w
)
14012 && cursor
== row
->glyphs
[LAST_AREA
] - 1)
14014 x
= -1; /* will be computed below, at label compute_x */
14017 /* Step 1: Try to find the glyph whose character position
14018 corresponds to point. If that's not possible, find 2 glyphs
14019 whose character positions are the closest to point, one before
14020 point, the other after it. */
14021 if (!row
->reversed_p
)
14022 while (/* not marched to end of glyph row */
14024 /* glyph was not inserted by redisplay for internal purposes */
14025 && !INTEGERP (glyph
->object
))
14027 if (BUFFERP (glyph
->object
))
14029 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
14031 if (glyph
->charpos
> bpos_max
)
14032 bpos_max
= glyph
->charpos
;
14033 if (glyph
->charpos
< bpos_min
)
14034 bpos_min
= glyph
->charpos
;
14035 if (!glyph
->avoid_cursor_p
)
14037 /* If we hit point, we've found the glyph on which to
14038 display the cursor. */
14041 match_with_avoid_cursor
= 0;
14044 /* See if we've found a better approximation to
14045 POS_BEFORE or to POS_AFTER. */
14046 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
14048 pos_before
= glyph
->charpos
;
14049 glyph_before
= glyph
;
14051 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
14053 pos_after
= glyph
->charpos
;
14054 glyph_after
= glyph
;
14057 else if (dpos
== 0)
14058 match_with_avoid_cursor
= 1;
14060 else if (STRINGP (glyph
->object
))
14062 Lisp_Object chprop
;
14063 ptrdiff_t glyph_pos
= glyph
->charpos
;
14065 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
14067 if (!NILP (chprop
))
14069 /* If the string came from a `display' text property,
14070 look up the buffer position of that property and
14071 use that position to update bpos_max, as if we
14072 actually saw such a position in one of the row's
14073 glyphs. This helps with supporting integer values
14074 of `cursor' property on the display string in
14075 situations where most or all of the row's buffer
14076 text is completely covered by display properties,
14077 so that no glyph with valid buffer positions is
14078 ever seen in the row. */
14079 ptrdiff_t prop_pos
=
14080 string_buffer_position_lim (glyph
->object
, pos_before
,
14083 if (prop_pos
>= pos_before
)
14084 bpos_max
= prop_pos
- 1;
14086 if (INTEGERP (chprop
))
14088 bpos_covered
= bpos_max
+ XINT (chprop
);
14089 /* If the `cursor' property covers buffer positions up
14090 to and including point, we should display cursor on
14091 this glyph. Note that, if a `cursor' property on one
14092 of the string's characters has an integer value, we
14093 will break out of the loop below _before_ we get to
14094 the position match above. IOW, integer values of
14095 the `cursor' property override the "exact match for
14096 point" strategy of positioning the cursor. */
14097 /* Implementation note: bpos_max == pt_old when, e.g.,
14098 we are in an empty line, where bpos_max is set to
14099 MATRIX_ROW_START_CHARPOS, see above. */
14100 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14109 x
+= glyph
->pixel_width
;
14112 else if (glyph
> end
) /* row is reversed */
14113 while (!INTEGERP (glyph
->object
))
14115 if (BUFFERP (glyph
->object
))
14117 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
14119 if (glyph
->charpos
> bpos_max
)
14120 bpos_max
= glyph
->charpos
;
14121 if (glyph
->charpos
< bpos_min
)
14122 bpos_min
= glyph
->charpos
;
14123 if (!glyph
->avoid_cursor_p
)
14127 match_with_avoid_cursor
= 0;
14130 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
14132 pos_before
= glyph
->charpos
;
14133 glyph_before
= glyph
;
14135 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
14137 pos_after
= glyph
->charpos
;
14138 glyph_after
= glyph
;
14141 else if (dpos
== 0)
14142 match_with_avoid_cursor
= 1;
14144 else if (STRINGP (glyph
->object
))
14146 Lisp_Object chprop
;
14147 ptrdiff_t glyph_pos
= glyph
->charpos
;
14149 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
14151 if (!NILP (chprop
))
14153 ptrdiff_t prop_pos
=
14154 string_buffer_position_lim (glyph
->object
, pos_before
,
14157 if (prop_pos
>= pos_before
)
14158 bpos_max
= prop_pos
- 1;
14160 if (INTEGERP (chprop
))
14162 bpos_covered
= bpos_max
+ XINT (chprop
);
14163 /* If the `cursor' property covers buffer positions up
14164 to and including point, we should display cursor on
14166 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14175 if (glyph
== glyphs_end
) /* don't dereference outside TEXT_AREA */
14177 x
--; /* can't use any pixel_width */
14180 x
-= glyph
->pixel_width
;
14183 /* Step 2: If we didn't find an exact match for point, we need to
14184 look for a proper place to put the cursor among glyphs between
14185 GLYPH_BEFORE and GLYPH_AFTER. */
14186 if (!((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14187 && BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14188 && bpos_covered
< pt_old
)
14190 /* An empty line has a single glyph whose OBJECT is zero and
14191 whose CHARPOS is the position of a newline on that line.
14192 Note that on a TTY, there are more glyphs after that, which
14193 were produced by extend_face_to_end_of_line, but their
14194 CHARPOS is zero or negative. */
14196 (row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14197 && INTEGERP (glyph
->object
) && glyph
->charpos
> 0;
14199 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
14201 ptrdiff_t ellipsis_pos
;
14203 /* Scan back over the ellipsis glyphs. */
14204 if (!row
->reversed_p
)
14206 ellipsis_pos
= (glyph
- 1)->charpos
;
14207 while (glyph
> row
->glyphs
[TEXT_AREA
]
14208 && (glyph
- 1)->charpos
== ellipsis_pos
)
14209 glyph
--, x
-= glyph
->pixel_width
;
14210 /* That loop always goes one position too far, including
14211 the glyph before the ellipsis. So scan forward over
14213 x
+= glyph
->pixel_width
;
14216 else /* row is reversed */
14218 ellipsis_pos
= (glyph
+ 1)->charpos
;
14219 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14220 && (glyph
+ 1)->charpos
== ellipsis_pos
)
14221 glyph
++, x
+= glyph
->pixel_width
;
14222 x
-= glyph
->pixel_width
;
14226 else if (match_with_avoid_cursor
)
14228 cursor
= glyph_after
;
14231 else if (string_seen
)
14233 int incr
= row
->reversed_p
? -1 : +1;
14235 /* Need to find the glyph that came out of a string which is
14236 present at point. That glyph is somewhere between
14237 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
14238 positioned between POS_BEFORE and POS_AFTER in the
14240 struct glyph
*start
, *stop
;
14241 ptrdiff_t pos
= pos_before
;
14245 /* If the row ends in a newline from a display string,
14246 reordering could have moved the glyphs belonging to the
14247 string out of the [GLYPH_BEFORE..GLYPH_AFTER] range. So
14248 in this case we extend the search to the last glyph in
14249 the row that was not inserted by redisplay. */
14250 if (row
->ends_in_newline_from_string_p
)
14253 pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
14256 /* GLYPH_BEFORE and GLYPH_AFTER are the glyphs that
14257 correspond to POS_BEFORE and POS_AFTER, respectively. We
14258 need START and STOP in the order that corresponds to the
14259 row's direction as given by its reversed_p flag. If the
14260 directionality of characters between POS_BEFORE and
14261 POS_AFTER is the opposite of the row's base direction,
14262 these characters will have been reordered for display,
14263 and we need to reverse START and STOP. */
14264 if (!row
->reversed_p
)
14266 start
= min (glyph_before
, glyph_after
);
14267 stop
= max (glyph_before
, glyph_after
);
14271 start
= max (glyph_before
, glyph_after
);
14272 stop
= min (glyph_before
, glyph_after
);
14274 for (glyph
= start
+ incr
;
14275 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
14278 /* Any glyphs that come from the buffer are here because
14279 of bidi reordering. Skip them, and only pay
14280 attention to glyphs that came from some string. */
14281 if (STRINGP (glyph
->object
))
14285 /* If the display property covers the newline, we
14286 need to search for it one position farther. */
14287 ptrdiff_t lim
= pos_after
14288 + (pos_after
== MATRIX_ROW_END_CHARPOS (row
) + delta
);
14290 string_from_text_prop
= 0;
14291 str
= glyph
->object
;
14292 tem
= string_buffer_position_lim (str
, pos
, lim
, 0);
14293 if (tem
== 0 /* from overlay */
14296 /* If the string from which this glyph came is
14297 found in the buffer at point, or at position
14298 that is closer to point than pos_after, then
14299 we've found the glyph we've been looking for.
14300 If it comes from an overlay (tem == 0), and
14301 it has the `cursor' property on one of its
14302 glyphs, record that glyph as a candidate for
14303 displaying the cursor. (As in the
14304 unidirectional version, we will display the
14305 cursor on the last candidate we find.) */
14308 || (tem
- pt_old
> 0 && tem
< pos_after
))
14310 /* The glyphs from this string could have
14311 been reordered. Find the one with the
14312 smallest string position. Or there could
14313 be a character in the string with the
14314 `cursor' property, which means display
14315 cursor on that character's glyph. */
14316 ptrdiff_t strpos
= glyph
->charpos
;
14321 string_from_text_prop
= 1;
14324 (row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14325 && EQ (glyph
->object
, str
);
14329 ptrdiff_t gpos
= glyph
->charpos
;
14331 cprop
= Fget_char_property (make_number (gpos
),
14339 if (tem
&& glyph
->charpos
< strpos
)
14341 strpos
= glyph
->charpos
;
14347 || (tem
- pt_old
> 0 && tem
< pos_after
))
14351 pos
= tem
+ 1; /* don't find previous instances */
14353 /* This string is not what we want; skip all of the
14354 glyphs that came from it. */
14355 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14356 && EQ (glyph
->object
, str
))
14363 /* If we reached the end of the line, and END was from a string,
14364 the cursor is not on this line. */
14366 && (row
->reversed_p
? glyph
<= end
: glyph
>= end
)
14367 && (row
->reversed_p
? end
> glyphs_end
: end
< glyphs_end
)
14368 && STRINGP (end
->object
)
14369 && row
->continued_p
)
14372 /* A truncated row may not include PT among its character positions.
14373 Setting the cursor inside the scroll margin will trigger
14374 recalculation of hscroll in hscroll_window_tree. But if a
14375 display string covers point, defer to the string-handling
14376 code below to figure this out. */
14377 else if (row
->truncated_on_left_p
&& pt_old
< bpos_min
)
14379 cursor
= glyph_before
;
14382 else if ((row
->truncated_on_right_p
&& pt_old
> bpos_max
)
14383 /* Zero-width characters produce no glyphs. */
14385 && (row
->reversed_p
14386 ? glyph_after
> glyphs_end
14387 : glyph_after
< glyphs_end
)))
14389 cursor
= glyph_after
;
14395 if (cursor
!= NULL
)
14397 else if (glyph
== glyphs_end
14398 && pos_before
== pos_after
14399 && STRINGP ((row
->reversed_p
14400 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14401 : row
->glyphs
[TEXT_AREA
])->object
))
14403 /* If all the glyphs of this row came from strings, put the
14404 cursor on the first glyph of the row. This avoids having the
14405 cursor outside of the text area in this very rare and hard
14409 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14410 : row
->glyphs
[TEXT_AREA
];
14416 /* Need to compute x that corresponds to GLYPH. */
14417 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
14419 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
14421 x
+= g
->pixel_width
;
14425 /* ROW could be part of a continued line, which, under bidi
14426 reordering, might have other rows whose start and end charpos
14427 occlude point. Only set w->cursor if we found a better
14428 approximation to the cursor position than we have from previously
14429 examined candidate rows belonging to the same continued line. */
14430 if (/* we already have a candidate row */
14431 w
->cursor
.vpos
>= 0
14432 /* that candidate is not the row we are processing */
14433 && MATRIX_ROW (matrix
, w
->cursor
.vpos
) != row
14434 /* Make sure cursor.vpos specifies a row whose start and end
14435 charpos occlude point, and it is valid candidate for being a
14436 cursor-row. This is because some callers of this function
14437 leave cursor.vpos at the row where the cursor was displayed
14438 during the last redisplay cycle. */
14439 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)) <= pt_old
14440 && pt_old
<= MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14441 && cursor_row_p (MATRIX_ROW (matrix
, w
->cursor
.vpos
)))
14444 MATRIX_ROW_GLYPH_START (matrix
, w
->cursor
.vpos
) + w
->cursor
.hpos
;
14446 /* Don't consider glyphs that are outside TEXT_AREA. */
14447 if (!(row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
))
14449 /* Keep the candidate whose buffer position is the closest to
14450 point or has the `cursor' property. */
14451 if (/* previous candidate is a glyph in TEXT_AREA of that row */
14452 w
->cursor
.hpos
>= 0
14453 && w
->cursor
.hpos
< MATRIX_ROW_USED (matrix
, w
->cursor
.vpos
)
14454 && ((BUFFERP (g1
->object
)
14455 && (g1
->charpos
== pt_old
/* an exact match always wins */
14456 || (BUFFERP (glyph
->object
)
14457 && eabs (g1
->charpos
- pt_old
)
14458 < eabs (glyph
->charpos
- pt_old
))))
14459 /* previous candidate is a glyph from a string that has
14460 a non-nil `cursor' property */
14461 || (STRINGP (g1
->object
)
14462 && (!NILP (Fget_char_property (make_number (g1
->charpos
),
14463 Qcursor
, g1
->object
))
14464 /* previous candidate is from the same display
14465 string as this one, and the display string
14466 came from a text property */
14467 || (EQ (g1
->object
, glyph
->object
)
14468 && string_from_text_prop
)
14469 /* this candidate is from newline and its
14470 position is not an exact match */
14471 || (INTEGERP (glyph
->object
)
14472 && glyph
->charpos
!= pt_old
)))))
14474 /* If this candidate gives an exact match, use that. */
14475 if (!((BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14476 /* If this candidate is a glyph created for the
14477 terminating newline of a line, and point is on that
14478 newline, it wins because it's an exact match. */
14479 || (!row
->continued_p
14480 && INTEGERP (glyph
->object
)
14481 && glyph
->charpos
== 0
14482 && pt_old
== MATRIX_ROW_END_CHARPOS (row
) - 1))
14483 /* Otherwise, keep the candidate that comes from a row
14484 spanning less buffer positions. This may win when one or
14485 both candidate positions are on glyphs that came from
14486 display strings, for which we cannot compare buffer
14488 && MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14489 - MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14490 < MATRIX_ROW_END_CHARPOS (row
) - MATRIX_ROW_START_CHARPOS (row
))
14493 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
14495 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
14496 w
->cursor
.y
= row
->y
+ dy
;
14498 if (w
== XWINDOW (selected_window
))
14500 if (!row
->continued_p
14501 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
14504 this_line_buffer
= XBUFFER (w
->buffer
);
14506 CHARPOS (this_line_start_pos
)
14507 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
14508 BYTEPOS (this_line_start_pos
)
14509 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
14511 CHARPOS (this_line_end_pos
)
14512 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
14513 BYTEPOS (this_line_end_pos
)
14514 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
14516 this_line_y
= w
->cursor
.y
;
14517 this_line_pixel_height
= row
->height
;
14518 this_line_vpos
= w
->cursor
.vpos
;
14519 this_line_start_x
= row
->x
;
14522 CHARPOS (this_line_start_pos
) = 0;
14529 /* Run window scroll functions, if any, for WINDOW with new window
14530 start STARTP. Sets the window start of WINDOW to that position.
14532 We assume that the window's buffer is really current. */
14534 static inline struct text_pos
14535 run_window_scroll_functions (Lisp_Object window
, struct text_pos startp
)
14537 struct window
*w
= XWINDOW (window
);
14538 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
14540 if (current_buffer
!= XBUFFER (w
->buffer
))
14543 if (!NILP (Vwindow_scroll_functions
))
14545 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
14546 make_number (CHARPOS (startp
)));
14547 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14548 /* In case the hook functions switch buffers. */
14549 set_buffer_internal (XBUFFER (w
->buffer
));
14556 /* Make sure the line containing the cursor is fully visible.
14557 A value of 1 means there is nothing to be done.
14558 (Either the line is fully visible, or it cannot be made so,
14559 or we cannot tell.)
14561 If FORCE_P is non-zero, return 0 even if partial visible cursor row
14562 is higher than window.
14564 A value of 0 means the caller should do scrolling
14565 as if point had gone off the screen. */
14568 cursor_row_fully_visible_p (struct window
*w
, int force_p
, int current_matrix_p
)
14570 struct glyph_matrix
*matrix
;
14571 struct glyph_row
*row
;
14574 if (!make_cursor_line_fully_visible_p
)
14577 /* It's not always possible to find the cursor, e.g, when a window
14578 is full of overlay strings. Don't do anything in that case. */
14579 if (w
->cursor
.vpos
< 0)
14582 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
14583 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
14585 /* If the cursor row is not partially visible, there's nothing to do. */
14586 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
14589 /* If the row the cursor is in is taller than the window's height,
14590 it's not clear what to do, so do nothing. */
14591 window_height
= window_box_height (w
);
14592 if (row
->height
>= window_height
)
14594 if (!force_p
|| MINI_WINDOW_P (w
)
14595 || w
->vscroll
|| w
->cursor
.vpos
== 0)
14602 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
14603 non-zero means only WINDOW is redisplayed in redisplay_internal.
14604 TEMP_SCROLL_STEP has the same meaning as emacs_scroll_step, and is used
14605 in redisplay_window to bring a partially visible line into view in
14606 the case that only the cursor has moved.
14608 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
14609 last screen line's vertical height extends past the end of the screen.
14613 1 if scrolling succeeded
14615 0 if scrolling didn't find point.
14617 -1 if new fonts have been loaded so that we must interrupt
14618 redisplay, adjust glyph matrices, and try again. */
14624 SCROLLING_NEED_LARGER_MATRICES
14627 /* If scroll-conservatively is more than this, never recenter.
14629 If you change this, don't forget to update the doc string of
14630 `scroll-conservatively' and the Emacs manual. */
14631 #define SCROLL_LIMIT 100
14634 try_scrolling (Lisp_Object window
, int just_this_one_p
,
14635 ptrdiff_t arg_scroll_conservatively
, ptrdiff_t scroll_step
,
14636 int temp_scroll_step
, int last_line_misfit
)
14638 struct window
*w
= XWINDOW (window
);
14639 struct frame
*f
= XFRAME (w
->frame
);
14640 struct text_pos pos
, startp
;
14642 int this_scroll_margin
, scroll_max
, rc
, height
;
14643 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
14644 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
14645 Lisp_Object aggressive
;
14646 /* We will never try scrolling more than this number of lines. */
14647 int scroll_limit
= SCROLL_LIMIT
;
14650 debug_method_add (w
, "try_scrolling");
14653 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14655 /* Compute scroll margin height in pixels. We scroll when point is
14656 within this distance from the top or bottom of the window. */
14657 if (scroll_margin
> 0)
14658 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
14659 * FRAME_LINE_HEIGHT (f
);
14661 this_scroll_margin
= 0;
14663 /* Force arg_scroll_conservatively to have a reasonable value, to
14664 avoid scrolling too far away with slow move_it_* functions. Note
14665 that the user can supply scroll-conservatively equal to
14666 `most-positive-fixnum', which can be larger than INT_MAX. */
14667 if (arg_scroll_conservatively
> scroll_limit
)
14669 arg_scroll_conservatively
= scroll_limit
+ 1;
14670 scroll_max
= scroll_limit
* FRAME_LINE_HEIGHT (f
);
14672 else if (scroll_step
|| arg_scroll_conservatively
|| temp_scroll_step
)
14673 /* Compute how much we should try to scroll maximally to bring
14674 point into view. */
14675 scroll_max
= (max (scroll_step
,
14676 max (arg_scroll_conservatively
, temp_scroll_step
))
14677 * FRAME_LINE_HEIGHT (f
));
14678 else if (NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
))
14679 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
)))
14680 /* We're trying to scroll because of aggressive scrolling but no
14681 scroll_step is set. Choose an arbitrary one. */
14682 scroll_max
= 10 * FRAME_LINE_HEIGHT (f
);
14688 /* Decide whether to scroll down. */
14689 if (PT
> CHARPOS (startp
))
14691 int scroll_margin_y
;
14693 /* Compute the pixel ypos of the scroll margin, then move IT to
14694 either that ypos or PT, whichever comes first. */
14695 start_display (&it
, w
, startp
);
14696 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
14697 - FRAME_LINE_HEIGHT (f
) * extra_scroll_margin_lines
;
14698 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
14699 (MOVE_TO_POS
| MOVE_TO_Y
));
14701 if (PT
> CHARPOS (it
.current
.pos
))
14703 int y0
= line_bottom_y (&it
);
14704 /* Compute how many pixels below window bottom to stop searching
14705 for PT. This avoids costly search for PT that is far away if
14706 the user limited scrolling by a small number of lines, but
14707 always finds PT if scroll_conservatively is set to a large
14708 number, such as most-positive-fixnum. */
14709 int slack
= max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
));
14710 int y_to_move
= it
.last_visible_y
+ slack
;
14712 /* Compute the distance from the scroll margin to PT or to
14713 the scroll limit, whichever comes first. This should
14714 include the height of the cursor line, to make that line
14716 move_it_to (&it
, PT
, -1, y_to_move
,
14717 -1, MOVE_TO_POS
| MOVE_TO_Y
);
14718 dy
= line_bottom_y (&it
) - y0
;
14720 if (dy
> scroll_max
)
14721 return SCROLLING_FAILED
;
14730 /* Point is in or below the bottom scroll margin, so move the
14731 window start down. If scrolling conservatively, move it just
14732 enough down to make point visible. If scroll_step is set,
14733 move it down by scroll_step. */
14734 if (arg_scroll_conservatively
)
14736 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
14737 FRAME_LINE_HEIGHT (f
) * arg_scroll_conservatively
);
14738 else if (scroll_step
|| temp_scroll_step
)
14739 amount_to_scroll
= scroll_max
;
14742 aggressive
= BVAR (current_buffer
, scroll_up_aggressively
);
14743 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14744 if (NUMBERP (aggressive
))
14746 double float_amount
= XFLOATINT (aggressive
) * height
;
14747 amount_to_scroll
= float_amount
;
14748 if (amount_to_scroll
== 0 && float_amount
> 0)
14749 amount_to_scroll
= 1;
14750 /* Don't let point enter the scroll margin near top of
14752 if (amount_to_scroll
> height
- 2*this_scroll_margin
+ dy
)
14753 amount_to_scroll
= height
- 2*this_scroll_margin
+ dy
;
14757 if (amount_to_scroll
<= 0)
14758 return SCROLLING_FAILED
;
14760 start_display (&it
, w
, startp
);
14761 if (arg_scroll_conservatively
<= scroll_limit
)
14762 move_it_vertically (&it
, amount_to_scroll
);
14765 /* Extra precision for users who set scroll-conservatively
14766 to a large number: make sure the amount we scroll
14767 the window start is never less than amount_to_scroll,
14768 which was computed as distance from window bottom to
14769 point. This matters when lines at window top and lines
14770 below window bottom have different height. */
14772 void *it1data
= NULL
;
14773 /* We use a temporary it1 because line_bottom_y can modify
14774 its argument, if it moves one line down; see there. */
14777 SAVE_IT (it1
, it
, it1data
);
14778 start_y
= line_bottom_y (&it1
);
14780 RESTORE_IT (&it
, &it
, it1data
);
14781 move_it_by_lines (&it
, 1);
14782 SAVE_IT (it1
, it
, it1data
);
14783 } while (line_bottom_y (&it1
) - start_y
< amount_to_scroll
);
14786 /* If STARTP is unchanged, move it down another screen line. */
14787 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
14788 move_it_by_lines (&it
, 1);
14789 startp
= it
.current
.pos
;
14793 struct text_pos scroll_margin_pos
= startp
;
14795 /* See if point is inside the scroll margin at the top of the
14797 if (this_scroll_margin
)
14799 start_display (&it
, w
, startp
);
14800 move_it_vertically (&it
, this_scroll_margin
);
14801 scroll_margin_pos
= it
.current
.pos
;
14804 if (PT
< CHARPOS (scroll_margin_pos
))
14806 /* Point is in the scroll margin at the top of the window or
14807 above what is displayed in the window. */
14810 /* Compute the vertical distance from PT to the scroll
14811 margin position. Move as far as scroll_max allows, or
14812 one screenful, or 10 screen lines, whichever is largest.
14813 Give up if distance is greater than scroll_max. */
14814 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
14815 start_display (&it
, w
, pos
);
14817 y_to_move
= max (it
.last_visible_y
,
14818 max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
)));
14819 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
14821 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
14822 dy
= it
.current_y
- y0
;
14823 if (dy
> scroll_max
)
14824 return SCROLLING_FAILED
;
14826 /* Compute new window start. */
14827 start_display (&it
, w
, startp
);
14829 if (arg_scroll_conservatively
)
14830 amount_to_scroll
= max (dy
, FRAME_LINE_HEIGHT (f
) *
14831 max (scroll_step
, temp_scroll_step
));
14832 else if (scroll_step
|| temp_scroll_step
)
14833 amount_to_scroll
= scroll_max
;
14836 aggressive
= BVAR (current_buffer
, scroll_down_aggressively
);
14837 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14838 if (NUMBERP (aggressive
))
14840 double float_amount
= XFLOATINT (aggressive
) * height
;
14841 amount_to_scroll
= float_amount
;
14842 if (amount_to_scroll
== 0 && float_amount
> 0)
14843 amount_to_scroll
= 1;
14844 amount_to_scroll
-=
14845 this_scroll_margin
- dy
- FRAME_LINE_HEIGHT (f
);
14846 /* Don't let point enter the scroll margin near
14847 bottom of the window. */
14848 if (amount_to_scroll
> height
- 2*this_scroll_margin
+ dy
)
14849 amount_to_scroll
= height
- 2*this_scroll_margin
+ dy
;
14853 if (amount_to_scroll
<= 0)
14854 return SCROLLING_FAILED
;
14856 move_it_vertically_backward (&it
, amount_to_scroll
);
14857 startp
= it
.current
.pos
;
14861 /* Run window scroll functions. */
14862 startp
= run_window_scroll_functions (window
, startp
);
14864 /* Display the window. Give up if new fonts are loaded, or if point
14866 if (!try_window (window
, startp
, 0))
14867 rc
= SCROLLING_NEED_LARGER_MATRICES
;
14868 else if (w
->cursor
.vpos
< 0)
14870 clear_glyph_matrix (w
->desired_matrix
);
14871 rc
= SCROLLING_FAILED
;
14875 /* Maybe forget recorded base line for line number display. */
14876 if (!just_this_one_p
14877 || current_buffer
->clip_changed
14878 || BEG_UNCHANGED
< CHARPOS (startp
))
14879 wset_base_line_number (w
, Qnil
);
14881 /* If cursor ends up on a partially visible line,
14882 treat that as being off the bottom of the screen. */
14883 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0)
14884 /* It's possible that the cursor is on the first line of the
14885 buffer, which is partially obscured due to a vscroll
14886 (Bug#7537). In that case, avoid looping forever . */
14887 && extra_scroll_margin_lines
< w
->desired_matrix
->nrows
- 1)
14889 clear_glyph_matrix (w
->desired_matrix
);
14890 ++extra_scroll_margin_lines
;
14893 rc
= SCROLLING_SUCCESS
;
14900 /* Compute a suitable window start for window W if display of W starts
14901 on a continuation line. Value is non-zero if a new window start
14904 The new window start will be computed, based on W's width, starting
14905 from the start of the continued line. It is the start of the
14906 screen line with the minimum distance from the old start W->start. */
14909 compute_window_start_on_continuation_line (struct window
*w
)
14911 struct text_pos pos
, start_pos
;
14912 int window_start_changed_p
= 0;
14914 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
14916 /* If window start is on a continuation line... Window start may be
14917 < BEGV in case there's invisible text at the start of the
14918 buffer (M-x rmail, for example). */
14919 if (CHARPOS (start_pos
) > BEGV
14920 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
14923 struct glyph_row
*row
;
14925 /* Handle the case that the window start is out of range. */
14926 if (CHARPOS (start_pos
) < BEGV
)
14927 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
14928 else if (CHARPOS (start_pos
) > ZV
)
14929 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
14931 /* Find the start of the continued line. This should be fast
14932 because scan_buffer is fast (newline cache). */
14933 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
14934 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
14935 row
, DEFAULT_FACE_ID
);
14936 reseat_at_previous_visible_line_start (&it
);
14938 /* If the line start is "too far" away from the window start,
14939 say it takes too much time to compute a new window start. */
14940 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
14941 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
14943 int min_distance
, distance
;
14945 /* Move forward by display lines to find the new window
14946 start. If window width was enlarged, the new start can
14947 be expected to be > the old start. If window width was
14948 decreased, the new window start will be < the old start.
14949 So, we're looking for the display line start with the
14950 minimum distance from the old window start. */
14951 pos
= it
.current
.pos
;
14952 min_distance
= INFINITY
;
14953 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
14954 distance
< min_distance
)
14956 min_distance
= distance
;
14957 pos
= it
.current
.pos
;
14958 move_it_by_lines (&it
, 1);
14961 /* Set the window start there. */
14962 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
14963 window_start_changed_p
= 1;
14967 return window_start_changed_p
;
14971 /* Try cursor movement in case text has not changed in window WINDOW,
14972 with window start STARTP. Value is
14974 CURSOR_MOVEMENT_SUCCESS if successful
14976 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
14978 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
14979 display. *SCROLL_STEP is set to 1, under certain circumstances, if
14980 we want to scroll as if scroll-step were set to 1. See the code.
14982 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
14983 which case we have to abort this redisplay, and adjust matrices
14988 CURSOR_MOVEMENT_SUCCESS
,
14989 CURSOR_MOVEMENT_CANNOT_BE_USED
,
14990 CURSOR_MOVEMENT_MUST_SCROLL
,
14991 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
14995 try_cursor_movement (Lisp_Object window
, struct text_pos startp
, int *scroll_step
)
14997 struct window
*w
= XWINDOW (window
);
14998 struct frame
*f
= XFRAME (w
->frame
);
14999 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
15002 if (inhibit_try_cursor_movement
)
15006 /* Previously, there was a check for Lisp integer in the
15007 if-statement below. Now, this field is converted to
15008 ptrdiff_t, thus zero means invalid position in a buffer. */
15009 eassert (w
->last_point
> 0);
15011 /* Handle case where text has not changed, only point, and it has
15012 not moved off the frame. */
15013 if (/* Point may be in this window. */
15014 PT
>= CHARPOS (startp
)
15015 /* Selective display hasn't changed. */
15016 && !current_buffer
->clip_changed
15017 /* Function force-mode-line-update is used to force a thorough
15018 redisplay. It sets either windows_or_buffers_changed or
15019 update_mode_lines. So don't take a shortcut here for these
15021 && !update_mode_lines
15022 && !windows_or_buffers_changed
15023 && !cursor_type_changed
15024 /* Can't use this case if highlighting a region. When a
15025 region exists, cursor movement has to do more than just
15027 && !(!NILP (Vtransient_mark_mode
)
15028 && !NILP (BVAR (current_buffer
, mark_active
)))
15029 && NILP (w
->region_showing
)
15030 && NILP (Vshow_trailing_whitespace
)
15031 /* This code is not used for mini-buffer for the sake of the case
15032 of redisplaying to replace an echo area message; since in
15033 that case the mini-buffer contents per se are usually
15034 unchanged. This code is of no real use in the mini-buffer
15035 since the handling of this_line_start_pos, etc., in redisplay
15036 handles the same cases. */
15037 && !EQ (window
, minibuf_window
)
15038 /* When splitting windows or for new windows, it happens that
15039 redisplay is called with a nil window_end_vpos or one being
15040 larger than the window. This should really be fixed in
15041 window.c. I don't have this on my list, now, so we do
15042 approximately the same as the old redisplay code. --gerd. */
15043 && INTEGERP (w
->window_end_vpos
)
15044 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
15045 && (FRAME_WINDOW_P (f
)
15046 || !overlay_arrow_in_current_buffer_p ()))
15048 int this_scroll_margin
, top_scroll_margin
;
15049 struct glyph_row
*row
= NULL
;
15052 debug_method_add (w
, "cursor movement");
15055 /* Scroll if point within this distance from the top or bottom
15056 of the window. This is a pixel value. */
15057 if (scroll_margin
> 0)
15059 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
15060 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
15063 this_scroll_margin
= 0;
15065 top_scroll_margin
= this_scroll_margin
;
15066 if (WINDOW_WANTS_HEADER_LINE_P (w
))
15067 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
15069 /* Start with the row the cursor was displayed during the last
15070 not paused redisplay. Give up if that row is not valid. */
15071 if (w
->last_cursor
.vpos
< 0
15072 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
15073 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15076 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
15077 if (row
->mode_line_p
)
15079 if (!row
->enabled_p
)
15080 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15083 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
15085 int scroll_p
= 0, must_scroll
= 0;
15086 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
15088 if (PT
> w
->last_point
)
15090 /* Point has moved forward. */
15091 while (MATRIX_ROW_END_CHARPOS (row
) < PT
15092 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
15094 eassert (row
->enabled_p
);
15098 /* If the end position of a row equals the start
15099 position of the next row, and PT is at that position,
15100 we would rather display cursor in the next line. */
15101 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15102 && MATRIX_ROW_END_CHARPOS (row
) == PT
15103 && row
< w
->current_matrix
->rows
15104 + w
->current_matrix
->nrows
- 1
15105 && MATRIX_ROW_START_CHARPOS (row
+1) == PT
15106 && !cursor_row_p (row
))
15109 /* If within the scroll margin, scroll. Note that
15110 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
15111 the next line would be drawn, and that
15112 this_scroll_margin can be zero. */
15113 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
15114 || PT
> MATRIX_ROW_END_CHARPOS (row
)
15115 /* Line is completely visible last line in window
15116 and PT is to be set in the next line. */
15117 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
15118 && PT
== MATRIX_ROW_END_CHARPOS (row
)
15119 && !row
->ends_at_zv_p
15120 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
15123 else if (PT
< w
->last_point
)
15125 /* Cursor has to be moved backward. Note that PT >=
15126 CHARPOS (startp) because of the outer if-statement. */
15127 while (!row
->mode_line_p
15128 && (MATRIX_ROW_START_CHARPOS (row
) > PT
15129 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15130 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
15131 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
15132 row
> w
->current_matrix
->rows
15133 && (row
-1)->ends_in_newline_from_string_p
))))
15134 && (row
->y
> top_scroll_margin
15135 || CHARPOS (startp
) == BEGV
))
15137 eassert (row
->enabled_p
);
15141 /* Consider the following case: Window starts at BEGV,
15142 there is invisible, intangible text at BEGV, so that
15143 display starts at some point START > BEGV. It can
15144 happen that we are called with PT somewhere between
15145 BEGV and START. Try to handle that case. */
15146 if (row
< w
->current_matrix
->rows
15147 || row
->mode_line_p
)
15149 row
= w
->current_matrix
->rows
;
15150 if (row
->mode_line_p
)
15154 /* Due to newlines in overlay strings, we may have to
15155 skip forward over overlay strings. */
15156 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15157 && MATRIX_ROW_END_CHARPOS (row
) == PT
15158 && !cursor_row_p (row
))
15161 /* If within the scroll margin, scroll. */
15162 if (row
->y
< top_scroll_margin
15163 && CHARPOS (startp
) != BEGV
)
15168 /* Cursor did not move. So don't scroll even if cursor line
15169 is partially visible, as it was so before. */
15170 rc
= CURSOR_MOVEMENT_SUCCESS
;
15173 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
15174 || PT
> MATRIX_ROW_END_CHARPOS (row
))
15176 /* if PT is not in the glyph row, give up. */
15177 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15180 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15181 && !NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
15183 struct glyph_row
*row1
;
15185 /* If rows are bidi-reordered and point moved, back up
15186 until we find a row that does not belong to a
15187 continuation line. This is because we must consider
15188 all rows of a continued line as candidates for the
15189 new cursor positioning, since row start and end
15190 positions change non-linearly with vertical position
15192 /* FIXME: Revisit this when glyph ``spilling'' in
15193 continuation lines' rows is implemented for
15194 bidi-reordered rows. */
15195 for (row1
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15196 MATRIX_ROW_CONTINUATION_LINE_P (row
);
15199 /* If we hit the beginning of the displayed portion
15200 without finding the first row of a continued
15204 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15207 eassert (row
->enabled_p
);
15212 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15213 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
15214 /* Make sure this isn't a header line by any chance, since
15215 then MATRIX_ROW_PARTIALLY_VISIBLE_P might yield non-zero. */
15216 && !row
->mode_line_p
15217 && make_cursor_line_fully_visible_p
)
15219 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
15220 && !row
->ends_at_zv_p
15221 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15222 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15223 else if (row
->height
> window_box_height (w
))
15225 /* If we end up in a partially visible line, let's
15226 make it fully visible, except when it's taller
15227 than the window, in which case we can't do much
15230 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15234 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15235 if (!cursor_row_fully_visible_p (w
, 0, 1))
15236 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15238 rc
= CURSOR_MOVEMENT_SUCCESS
;
15242 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15243 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15244 && !NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
15246 /* With bidi-reordered rows, there could be more than
15247 one candidate row whose start and end positions
15248 occlude point. We need to let set_cursor_from_row
15249 find the best candidate. */
15250 /* FIXME: Revisit this when glyph ``spilling'' in
15251 continuation lines' rows is implemented for
15252 bidi-reordered rows. */
15257 int at_zv_p
= 0, exact_match_p
= 0;
15259 if (MATRIX_ROW_START_CHARPOS (row
) <= PT
15260 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
15261 && cursor_row_p (row
))
15262 rv
|= set_cursor_from_row (w
, row
, w
->current_matrix
,
15264 /* As soon as we've found the exact match for point,
15265 or the first suitable row whose ends_at_zv_p flag
15266 is set, we are done. */
15268 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
)->ends_at_zv_p
;
15270 && w
->cursor
.hpos
>= 0
15271 && w
->cursor
.hpos
< MATRIX_ROW_USED (w
->current_matrix
,
15274 struct glyph_row
*candidate
=
15275 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
15277 candidate
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
15278 ptrdiff_t endpos
= MATRIX_ROW_END_CHARPOS (candidate
);
15281 (BUFFERP (g
->object
) && g
->charpos
== PT
)
15282 || (INTEGERP (g
->object
)
15283 && (g
->charpos
== PT
15284 || (g
->charpos
== 0 && endpos
- 1 == PT
)));
15286 if (rv
&& (at_zv_p
|| exact_match_p
))
15288 rc
= CURSOR_MOVEMENT_SUCCESS
;
15291 if (MATRIX_ROW_BOTTOM_Y (row
) == last_y
)
15295 while (((MATRIX_ROW_CONTINUATION_LINE_P (row
)
15296 || row
->continued_p
)
15297 && MATRIX_ROW_BOTTOM_Y (row
) <= last_y
)
15298 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15299 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
));
15300 /* If we didn't find any candidate rows, or exited the
15301 loop before all the candidates were examined, signal
15302 to the caller that this method failed. */
15303 if (rc
!= CURSOR_MOVEMENT_SUCCESS
15305 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
15306 && !row
->continued_p
))
15307 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15309 rc
= CURSOR_MOVEMENT_SUCCESS
;
15315 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
15317 rc
= CURSOR_MOVEMENT_SUCCESS
;
15322 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15323 && MATRIX_ROW_START_CHARPOS (row
) == PT
15324 && cursor_row_p (row
));
15332 #if !defined USE_TOOLKIT_SCROLL_BARS || defined USE_GTK
15336 set_vertical_scroll_bar (struct window
*w
)
15338 ptrdiff_t start
, end
, whole
;
15340 /* Calculate the start and end positions for the current window.
15341 At some point, it would be nice to choose between scrollbars
15342 which reflect the whole buffer size, with special markers
15343 indicating narrowing, and scrollbars which reflect only the
15346 Note that mini-buffers sometimes aren't displaying any text. */
15347 if (!MINI_WINDOW_P (w
)
15348 || (w
== XWINDOW (minibuf_window
)
15349 && NILP (echo_area_buffer
[0])))
15351 struct buffer
*buf
= XBUFFER (w
->buffer
);
15352 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
15353 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
15354 /* I don't think this is guaranteed to be right. For the
15355 moment, we'll pretend it is. */
15356 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
15360 if (whole
< (end
- start
))
15361 whole
= end
- start
;
15364 start
= end
= whole
= 0;
15366 /* Indicate what this scroll bar ought to be displaying now. */
15367 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15368 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15369 (w
, end
- start
, whole
, start
);
15373 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
15374 selected_window is redisplayed.
15376 We can return without actually redisplaying the window if
15377 fonts_changed_p. In that case, redisplay_internal will
15381 redisplay_window (Lisp_Object window
, int just_this_one_p
)
15383 struct window
*w
= XWINDOW (window
);
15384 struct frame
*f
= XFRAME (w
->frame
);
15385 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15386 struct buffer
*old
= current_buffer
;
15387 struct text_pos lpoint
, opoint
, startp
;
15388 int update_mode_line
;
15391 /* Record it now because it's overwritten. */
15392 int current_matrix_up_to_date_p
= 0;
15393 int used_current_matrix_p
= 0;
15394 /* This is less strict than current_matrix_up_to_date_p.
15395 It indicates that the buffer contents and narrowing are unchanged. */
15396 int buffer_unchanged_p
= 0;
15397 int temp_scroll_step
= 0;
15398 ptrdiff_t count
= SPECPDL_INDEX ();
15400 int centering_position
= -1;
15401 int last_line_misfit
= 0;
15402 ptrdiff_t beg_unchanged
, end_unchanged
;
15404 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15407 /* W must be a leaf window here. */
15408 eassert (!NILP (w
->buffer
));
15410 *w
->desired_matrix
->method
= 0;
15414 reconsider_clip_changes (w
, buffer
);
15416 /* Has the mode line to be updated? */
15417 update_mode_line
= (w
->update_mode_line
15418 || update_mode_lines
15419 || buffer
->clip_changed
15420 || buffer
->prevent_redisplay_optimizations_p
);
15422 if (MINI_WINDOW_P (w
))
15424 if (w
== XWINDOW (echo_area_window
)
15425 && !NILP (echo_area_buffer
[0]))
15427 if (update_mode_line
)
15428 /* We may have to update a tty frame's menu bar or a
15429 tool-bar. Example `M-x C-h C-h C-g'. */
15430 goto finish_menu_bars
;
15432 /* We've already displayed the echo area glyphs in this window. */
15433 goto finish_scroll_bars
;
15435 else if ((w
!= XWINDOW (minibuf_window
)
15436 || minibuf_level
== 0)
15437 /* When buffer is nonempty, redisplay window normally. */
15438 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
15439 /* Quail displays non-mini buffers in minibuffer window.
15440 In that case, redisplay the window normally. */
15441 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
15443 /* W is a mini-buffer window, but it's not active, so clear
15445 int yb
= window_text_bottom_y (w
);
15446 struct glyph_row
*row
;
15449 for (y
= 0, row
= w
->desired_matrix
->rows
;
15451 y
+= row
->height
, ++row
)
15452 blank_row (w
, row
, y
);
15453 goto finish_scroll_bars
;
15456 clear_glyph_matrix (w
->desired_matrix
);
15459 /* Otherwise set up data on this window; select its buffer and point
15461 /* Really select the buffer, for the sake of buffer-local
15463 set_buffer_internal_1 (XBUFFER (w
->buffer
));
15465 current_matrix_up_to_date_p
15466 = (!NILP (w
->window_end_valid
)
15467 && !current_buffer
->clip_changed
15468 && !current_buffer
->prevent_redisplay_optimizations_p
15469 && w
->last_modified
>= MODIFF
15470 && w
->last_overlay_modified
>= OVERLAY_MODIFF
);
15472 /* Run the window-bottom-change-functions
15473 if it is possible that the text on the screen has changed
15474 (either due to modification of the text, or any other reason). */
15475 if (!current_matrix_up_to_date_p
15476 && !NILP (Vwindow_text_change_functions
))
15478 safe_run_hooks (Qwindow_text_change_functions
);
15482 beg_unchanged
= BEG_UNCHANGED
;
15483 end_unchanged
= END_UNCHANGED
;
15485 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
15487 specbind (Qinhibit_point_motion_hooks
, Qt
);
15490 = (!NILP (w
->window_end_valid
)
15491 && !current_buffer
->clip_changed
15492 && w
->last_modified
>= MODIFF
15493 && w
->last_overlay_modified
>= OVERLAY_MODIFF
);
15495 /* When windows_or_buffers_changed is non-zero, we can't rely on
15496 the window end being valid, so set it to nil there. */
15497 if (windows_or_buffers_changed
)
15499 /* If window starts on a continuation line, maybe adjust the
15500 window start in case the window's width changed. */
15501 if (XMARKER (w
->start
)->buffer
== current_buffer
)
15502 compute_window_start_on_continuation_line (w
);
15504 wset_window_end_valid (w
, Qnil
);
15507 /* Some sanity checks. */
15508 CHECK_WINDOW_END (w
);
15509 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
15511 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
15514 /* If %c is in mode line, update it if needed. */
15515 if (!NILP (w
->column_number_displayed
)
15516 /* This alternative quickly identifies a common case
15517 where no change is needed. */
15518 && !(PT
== w
->last_point
15519 && w
->last_modified
>= MODIFF
15520 && w
->last_overlay_modified
>= OVERLAY_MODIFF
)
15521 && (XFASTINT (w
->column_number_displayed
) != current_column ()))
15522 update_mode_line
= 1;
15524 /* Count number of windows showing the selected buffer. An indirect
15525 buffer counts as its base buffer. */
15526 if (!just_this_one_p
)
15528 struct buffer
*current_base
, *window_base
;
15529 current_base
= current_buffer
;
15530 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
15531 if (current_base
->base_buffer
)
15532 current_base
= current_base
->base_buffer
;
15533 if (window_base
->base_buffer
)
15534 window_base
= window_base
->base_buffer
;
15535 if (current_base
== window_base
)
15539 /* Point refers normally to the selected window. For any other
15540 window, set up appropriate value. */
15541 if (!EQ (window
, selected_window
))
15543 ptrdiff_t new_pt
= XMARKER (w
->pointm
)->charpos
;
15544 ptrdiff_t new_pt_byte
= marker_byte_position (w
->pointm
);
15548 new_pt_byte
= BEGV_BYTE
;
15549 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
15551 else if (new_pt
> (ZV
- 1))
15554 new_pt_byte
= ZV_BYTE
;
15555 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
15558 /* We don't use SET_PT so that the point-motion hooks don't run. */
15559 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
15562 /* If any of the character widths specified in the display table
15563 have changed, invalidate the width run cache. It's true that
15564 this may be a bit late to catch such changes, but the rest of
15565 redisplay goes (non-fatally) haywire when the display table is
15566 changed, so why should we worry about doing any better? */
15567 if (current_buffer
->width_run_cache
)
15569 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
15571 if (! disptab_matches_widthtab
15572 (disptab
, XVECTOR (BVAR (current_buffer
, width_table
))))
15574 invalidate_region_cache (current_buffer
,
15575 current_buffer
->width_run_cache
,
15577 recompute_width_table (current_buffer
, disptab
);
15581 /* If window-start is screwed up, choose a new one. */
15582 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
15585 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15587 /* If someone specified a new starting point but did not insist,
15588 check whether it can be used. */
15589 if (w
->optional_new_start
15590 && CHARPOS (startp
) >= BEGV
15591 && CHARPOS (startp
) <= ZV
)
15593 w
->optional_new_start
= 0;
15594 start_display (&it
, w
, startp
);
15595 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
15596 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15597 if (IT_CHARPOS (it
) == PT
)
15598 w
->force_start
= 1;
15599 /* IT may overshoot PT if text at PT is invisible. */
15600 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
15601 w
->force_start
= 1;
15606 /* Handle case where place to start displaying has been specified,
15607 unless the specified location is outside the accessible range. */
15608 if (w
->force_start
|| w
->frozen_window_start_p
)
15610 /* We set this later on if we have to adjust point. */
15613 w
->force_start
= 0;
15615 wset_window_end_valid (w
, Qnil
);
15617 /* Forget any recorded base line for line number display. */
15618 if (!buffer_unchanged_p
)
15619 wset_base_line_number (w
, Qnil
);
15621 /* Redisplay the mode line. Select the buffer properly for that.
15622 Also, run the hook window-scroll-functions
15623 because we have scrolled. */
15624 /* Note, we do this after clearing force_start because
15625 if there's an error, it is better to forget about force_start
15626 than to get into an infinite loop calling the hook functions
15627 and having them get more errors. */
15628 if (!update_mode_line
15629 || ! NILP (Vwindow_scroll_functions
))
15631 update_mode_line
= 1;
15632 w
->update_mode_line
= 1;
15633 startp
= run_window_scroll_functions (window
, startp
);
15636 w
->last_modified
= 0;
15637 w
->last_overlay_modified
= 0;
15638 if (CHARPOS (startp
) < BEGV
)
15639 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
15640 else if (CHARPOS (startp
) > ZV
)
15641 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
15643 /* Redisplay, then check if cursor has been set during the
15644 redisplay. Give up if new fonts were loaded. */
15645 /* We used to issue a CHECK_MARGINS argument to try_window here,
15646 but this causes scrolling to fail when point begins inside
15647 the scroll margin (bug#148) -- cyd */
15648 if (!try_window (window
, startp
, 0))
15650 w
->force_start
= 1;
15651 clear_glyph_matrix (w
->desired_matrix
);
15652 goto need_larger_matrices
;
15655 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
15657 /* If point does not appear, try to move point so it does
15658 appear. The desired matrix has been built above, so we
15659 can use it here. */
15660 new_vpos
= window_box_height (w
) / 2;
15663 if (!cursor_row_fully_visible_p (w
, 0, 0))
15665 /* Point does appear, but on a line partly visible at end of window.
15666 Move it back to a fully-visible line. */
15667 new_vpos
= window_box_height (w
);
15670 /* If we need to move point for either of the above reasons,
15671 now actually do it. */
15674 struct glyph_row
*row
;
15676 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
15677 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
15680 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
15681 MATRIX_ROW_START_BYTEPOS (row
));
15683 if (w
!= XWINDOW (selected_window
))
15684 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
15685 else if (current_buffer
== old
)
15686 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15688 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
15690 /* If we are highlighting the region, then we just changed
15691 the region, so redisplay to show it. */
15692 if (!NILP (Vtransient_mark_mode
)
15693 && !NILP (BVAR (current_buffer
, mark_active
)))
15695 clear_glyph_matrix (w
->desired_matrix
);
15696 if (!try_window (window
, startp
, 0))
15697 goto need_larger_matrices
;
15702 debug_method_add (w
, "forced window start");
15707 /* Handle case where text has not changed, only point, and it has
15708 not moved off the frame, and we are not retrying after hscroll.
15709 (current_matrix_up_to_date_p is nonzero when retrying.) */
15710 if (current_matrix_up_to_date_p
15711 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
15712 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
15716 case CURSOR_MOVEMENT_SUCCESS
:
15717 used_current_matrix_p
= 1;
15720 case CURSOR_MOVEMENT_MUST_SCROLL
:
15721 goto try_to_scroll
;
15727 /* If current starting point was originally the beginning of a line
15728 but no longer is, find a new starting point. */
15729 else if (w
->start_at_line_beg
15730 && !(CHARPOS (startp
) <= BEGV
15731 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
15734 debug_method_add (w
, "recenter 1");
15739 /* Try scrolling with try_window_id. Value is > 0 if update has
15740 been done, it is -1 if we know that the same window start will
15741 not work. It is 0 if unsuccessful for some other reason. */
15742 else if ((tem
= try_window_id (w
)) != 0)
15745 debug_method_add (w
, "try_window_id %d", tem
);
15748 if (fonts_changed_p
)
15749 goto need_larger_matrices
;
15753 /* Otherwise try_window_id has returned -1 which means that we
15754 don't want the alternative below this comment to execute. */
15756 else if (CHARPOS (startp
) >= BEGV
15757 && CHARPOS (startp
) <= ZV
15758 && PT
>= CHARPOS (startp
)
15759 && (CHARPOS (startp
) < ZV
15760 /* Avoid starting at end of buffer. */
15761 || CHARPOS (startp
) == BEGV
15762 || (w
->last_modified
>= MODIFF
15763 && w
->last_overlay_modified
>= OVERLAY_MODIFF
)))
15765 int d1
, d2
, d3
, d4
, d5
, d6
;
15767 /* If first window line is a continuation line, and window start
15768 is inside the modified region, but the first change is before
15769 current window start, we must select a new window start.
15771 However, if this is the result of a down-mouse event (e.g. by
15772 extending the mouse-drag-overlay), we don't want to select a
15773 new window start, since that would change the position under
15774 the mouse, resulting in an unwanted mouse-movement rather
15775 than a simple mouse-click. */
15776 if (!w
->start_at_line_beg
15777 && NILP (do_mouse_tracking
)
15778 && CHARPOS (startp
) > BEGV
15779 && CHARPOS (startp
) > BEG
+ beg_unchanged
15780 && CHARPOS (startp
) <= Z
- end_unchanged
15781 /* Even if w->start_at_line_beg is nil, a new window may
15782 start at a line_beg, since that's how set_buffer_window
15783 sets it. So, we need to check the return value of
15784 compute_window_start_on_continuation_line. (See also
15786 && XMARKER (w
->start
)->buffer
== current_buffer
15787 && compute_window_start_on_continuation_line (w
)
15788 /* It doesn't make sense to force the window start like we
15789 do at label force_start if it is already known that point
15790 will not be visible in the resulting window, because
15791 doing so will move point from its correct position
15792 instead of scrolling the window to bring point into view.
15794 && pos_visible_p (w
, PT
, &d1
, &d2
, &d3
, &d4
, &d5
, &d6
))
15796 w
->force_start
= 1;
15797 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15802 debug_method_add (w
, "same window start");
15805 /* Try to redisplay starting at same place as before.
15806 If point has not moved off frame, accept the results. */
15807 if (!current_matrix_up_to_date_p
15808 /* Don't use try_window_reusing_current_matrix in this case
15809 because a window scroll function can have changed the
15811 || !NILP (Vwindow_scroll_functions
)
15812 || MINI_WINDOW_P (w
)
15813 || !(used_current_matrix_p
15814 = try_window_reusing_current_matrix (w
)))
15816 IF_DEBUG (debug_method_add (w
, "1"));
15817 if (try_window (window
, startp
, TRY_WINDOW_CHECK_MARGINS
) < 0)
15818 /* -1 means we need to scroll.
15819 0 means we need new matrices, but fonts_changed_p
15820 is set in that case, so we will detect it below. */
15821 goto try_to_scroll
;
15824 if (fonts_changed_p
)
15825 goto need_larger_matrices
;
15827 if (w
->cursor
.vpos
>= 0)
15829 if (!just_this_one_p
15830 || current_buffer
->clip_changed
15831 || BEG_UNCHANGED
< CHARPOS (startp
))
15832 /* Forget any recorded base line for line number display. */
15833 wset_base_line_number (w
, Qnil
);
15835 if (!cursor_row_fully_visible_p (w
, 1, 0))
15837 clear_glyph_matrix (w
->desired_matrix
);
15838 last_line_misfit
= 1;
15840 /* Drop through and scroll. */
15845 clear_glyph_matrix (w
->desired_matrix
);
15850 w
->last_modified
= 0;
15851 w
->last_overlay_modified
= 0;
15853 /* Redisplay the mode line. Select the buffer properly for that. */
15854 if (!update_mode_line
)
15856 update_mode_line
= 1;
15857 w
->update_mode_line
= 1;
15860 /* Try to scroll by specified few lines. */
15861 if ((scroll_conservatively
15862 || emacs_scroll_step
15863 || temp_scroll_step
15864 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
))
15865 || NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
)))
15866 && CHARPOS (startp
) >= BEGV
15867 && CHARPOS (startp
) <= ZV
)
15869 /* The function returns -1 if new fonts were loaded, 1 if
15870 successful, 0 if not successful. */
15871 int ss
= try_scrolling (window
, just_this_one_p
,
15872 scroll_conservatively
,
15874 temp_scroll_step
, last_line_misfit
);
15877 case SCROLLING_SUCCESS
:
15880 case SCROLLING_NEED_LARGER_MATRICES
:
15881 goto need_larger_matrices
;
15883 case SCROLLING_FAILED
:
15891 /* Finally, just choose a place to start which positions point
15892 according to user preferences. */
15897 debug_method_add (w
, "recenter");
15900 /* w->vscroll = 0; */
15902 /* Forget any previously recorded base line for line number display. */
15903 if (!buffer_unchanged_p
)
15904 wset_base_line_number (w
, Qnil
);
15906 /* Determine the window start relative to point. */
15907 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
15908 it
.current_y
= it
.last_visible_y
;
15909 if (centering_position
< 0)
15913 ? min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
15915 ptrdiff_t margin_pos
= CHARPOS (startp
);
15916 Lisp_Object aggressive
;
15919 /* If there is a scroll margin at the top of the window, find
15920 its character position. */
15922 /* Cannot call start_display if startp is not in the
15923 accessible region of the buffer. This can happen when we
15924 have just switched to a different buffer and/or changed
15925 its restriction. In that case, startp is initialized to
15926 the character position 1 (BEGV) because we did not yet
15927 have chance to display the buffer even once. */
15928 && BEGV
<= CHARPOS (startp
) && CHARPOS (startp
) <= ZV
)
15931 void *it1data
= NULL
;
15933 SAVE_IT (it1
, it
, it1data
);
15934 start_display (&it1
, w
, startp
);
15935 move_it_vertically (&it1
, margin
* FRAME_LINE_HEIGHT (f
));
15936 margin_pos
= IT_CHARPOS (it1
);
15937 RESTORE_IT (&it
, &it
, it1data
);
15939 scrolling_up
= PT
> margin_pos
;
15942 ? BVAR (current_buffer
, scroll_up_aggressively
)
15943 : BVAR (current_buffer
, scroll_down_aggressively
);
15945 if (!MINI_WINDOW_P (w
)
15946 && (scroll_conservatively
> SCROLL_LIMIT
|| NUMBERP (aggressive
)))
15950 /* Setting scroll-conservatively overrides
15951 scroll-*-aggressively. */
15952 if (!scroll_conservatively
&& NUMBERP (aggressive
))
15954 double float_amount
= XFLOATINT (aggressive
);
15956 pt_offset
= float_amount
* WINDOW_BOX_TEXT_HEIGHT (w
);
15957 if (pt_offset
== 0 && float_amount
> 0)
15959 if (pt_offset
&& margin
> 0)
15962 /* Compute how much to move the window start backward from
15963 point so that point will be displayed where the user
15967 centering_position
= it
.last_visible_y
;
15969 centering_position
-= pt_offset
;
15970 centering_position
-=
15971 FRAME_LINE_HEIGHT (f
) * (1 + margin
+ (last_line_misfit
!= 0))
15972 + WINDOW_HEADER_LINE_HEIGHT (w
);
15973 /* Don't let point enter the scroll margin near top of
15975 if (centering_position
< margin
* FRAME_LINE_HEIGHT (f
))
15976 centering_position
= margin
* FRAME_LINE_HEIGHT (f
);
15979 centering_position
= margin
* FRAME_LINE_HEIGHT (f
) + pt_offset
;
15982 /* Set the window start half the height of the window backward
15984 centering_position
= window_box_height (w
) / 2;
15986 move_it_vertically_backward (&it
, centering_position
);
15988 eassert (IT_CHARPOS (it
) >= BEGV
);
15990 /* The function move_it_vertically_backward may move over more
15991 than the specified y-distance. If it->w is small, e.g. a
15992 mini-buffer window, we may end up in front of the window's
15993 display area. Start displaying at the start of the line
15994 containing PT in this case. */
15995 if (it
.current_y
<= 0)
15997 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
15998 move_it_vertically_backward (&it
, 0);
16002 it
.current_x
= it
.hpos
= 0;
16004 /* Set the window start position here explicitly, to avoid an
16005 infinite loop in case the functions in window-scroll-functions
16007 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
16009 /* Run scroll hooks. */
16010 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
16012 /* Redisplay the window. */
16013 if (!current_matrix_up_to_date_p
16014 || windows_or_buffers_changed
16015 || cursor_type_changed
16016 /* Don't use try_window_reusing_current_matrix in this case
16017 because it can have changed the buffer. */
16018 || !NILP (Vwindow_scroll_functions
)
16019 || !just_this_one_p
16020 || MINI_WINDOW_P (w
)
16021 || !(used_current_matrix_p
16022 = try_window_reusing_current_matrix (w
)))
16023 try_window (window
, startp
, 0);
16025 /* If new fonts have been loaded (due to fontsets), give up. We
16026 have to start a new redisplay since we need to re-adjust glyph
16028 if (fonts_changed_p
)
16029 goto need_larger_matrices
;
16031 /* If cursor did not appear assume that the middle of the window is
16032 in the first line of the window. Do it again with the next line.
16033 (Imagine a window of height 100, displaying two lines of height
16034 60. Moving back 50 from it->last_visible_y will end in the first
16036 if (w
->cursor
.vpos
< 0)
16038 if (!NILP (w
->window_end_valid
)
16039 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
16041 clear_glyph_matrix (w
->desired_matrix
);
16042 move_it_by_lines (&it
, 1);
16043 try_window (window
, it
.current
.pos
, 0);
16045 else if (PT
< IT_CHARPOS (it
))
16047 clear_glyph_matrix (w
->desired_matrix
);
16048 move_it_by_lines (&it
, -1);
16049 try_window (window
, it
.current
.pos
, 0);
16053 /* Not much we can do about it. */
16057 /* Consider the following case: Window starts at BEGV, there is
16058 invisible, intangible text at BEGV, so that display starts at
16059 some point START > BEGV. It can happen that we are called with
16060 PT somewhere between BEGV and START. Try to handle that case. */
16061 if (w
->cursor
.vpos
< 0)
16063 struct glyph_row
*row
= w
->current_matrix
->rows
;
16064 if (row
->mode_line_p
)
16066 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
16069 if (!cursor_row_fully_visible_p (w
, 0, 0))
16071 /* If vscroll is enabled, disable it and try again. */
16075 clear_glyph_matrix (w
->desired_matrix
);
16079 /* Users who set scroll-conservatively to a large number want
16080 point just above/below the scroll margin. If we ended up
16081 with point's row partially visible, move the window start to
16082 make that row fully visible and out of the margin. */
16083 if (scroll_conservatively
> SCROLL_LIMIT
)
16087 ? min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
16089 int move_down
= w
->cursor
.vpos
>= WINDOW_TOTAL_LINES (w
) / 2;
16091 move_it_by_lines (&it
, move_down
? margin
+ 1 : -(margin
+ 1));
16092 clear_glyph_matrix (w
->desired_matrix
);
16093 if (1 == try_window (window
, it
.current
.pos
,
16094 TRY_WINDOW_CHECK_MARGINS
))
16098 /* If centering point failed to make the whole line visible,
16099 put point at the top instead. That has to make the whole line
16100 visible, if it can be done. */
16101 if (centering_position
== 0)
16104 clear_glyph_matrix (w
->desired_matrix
);
16105 centering_position
= 0;
16111 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
16112 w
->start_at_line_beg
= (CHARPOS (startp
) == BEGV
16113 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n');
16115 /* Display the mode line, if we must. */
16116 if ((update_mode_line
16117 /* If window not full width, must redo its mode line
16118 if (a) the window to its side is being redone and
16119 (b) we do a frame-based redisplay. This is a consequence
16120 of how inverted lines are drawn in frame-based redisplay. */
16121 || (!just_this_one_p
16122 && !FRAME_WINDOW_P (f
)
16123 && !WINDOW_FULL_WIDTH_P (w
))
16124 /* Line number to display. */
16125 || INTEGERP (w
->base_line_pos
)
16126 /* Column number is displayed and different from the one displayed. */
16127 || (!NILP (w
->column_number_displayed
)
16128 && (XFASTINT (w
->column_number_displayed
) != current_column ())))
16129 /* This means that the window has a mode line. */
16130 && (WINDOW_WANTS_MODELINE_P (w
)
16131 || WINDOW_WANTS_HEADER_LINE_P (w
)))
16133 display_mode_lines (w
);
16135 /* If mode line height has changed, arrange for a thorough
16136 immediate redisplay using the correct mode line height. */
16137 if (WINDOW_WANTS_MODELINE_P (w
)
16138 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
16140 fonts_changed_p
= 1;
16141 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
16142 = DESIRED_MODE_LINE_HEIGHT (w
);
16145 /* If header line height has changed, arrange for a thorough
16146 immediate redisplay using the correct header line height. */
16147 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16148 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
16150 fonts_changed_p
= 1;
16151 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
16152 = DESIRED_HEADER_LINE_HEIGHT (w
);
16155 if (fonts_changed_p
)
16156 goto need_larger_matrices
;
16159 if (!line_number_displayed
16160 && !BUFFERP (w
->base_line_pos
))
16162 wset_base_line_pos (w
, Qnil
);
16163 wset_base_line_number (w
, Qnil
);
16168 /* When we reach a frame's selected window, redo the frame's menu bar. */
16169 if (update_mode_line
16170 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
16172 int redisplay_menu_p
= 0;
16174 if (FRAME_WINDOW_P (f
))
16176 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
16177 || defined (HAVE_NS) || defined (USE_GTK)
16178 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
16180 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16184 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16186 if (redisplay_menu_p
)
16187 display_menu_bar (w
);
16189 #ifdef HAVE_WINDOW_SYSTEM
16190 if (FRAME_WINDOW_P (f
))
16192 #if defined (USE_GTK) || defined (HAVE_NS)
16193 if (FRAME_EXTERNAL_TOOL_BAR (f
))
16194 redisplay_tool_bar (f
);
16196 if (WINDOWP (f
->tool_bar_window
)
16197 && (FRAME_TOOL_BAR_LINES (f
) > 0
16198 || !NILP (Vauto_resize_tool_bars
))
16199 && redisplay_tool_bar (f
))
16200 ignore_mouse_drag_p
= 1;
16206 #ifdef HAVE_WINDOW_SYSTEM
16207 if (FRAME_WINDOW_P (f
)
16208 && update_window_fringes (w
, (just_this_one_p
16209 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
16210 || w
->pseudo_window_p
)))
16214 if (draw_window_fringes (w
, 1))
16215 x_draw_vertical_border (w
);
16219 #endif /* HAVE_WINDOW_SYSTEM */
16221 /* We go to this label, with fonts_changed_p set,
16222 if it is necessary to try again using larger glyph matrices.
16223 We have to redeem the scroll bar even in this case,
16224 because the loop in redisplay_internal expects that. */
16225 need_larger_matrices
:
16227 finish_scroll_bars
:
16229 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
16231 /* Set the thumb's position and size. */
16232 set_vertical_scroll_bar (w
);
16234 /* Note that we actually used the scroll bar attached to this
16235 window, so it shouldn't be deleted at the end of redisplay. */
16236 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
16237 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
16240 /* Restore current_buffer and value of point in it. The window
16241 update may have changed the buffer, so first make sure `opoint'
16242 is still valid (Bug#6177). */
16243 if (CHARPOS (opoint
) < BEGV
)
16244 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
16245 else if (CHARPOS (opoint
) > ZV
)
16246 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
16248 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
16250 set_buffer_internal_1 (old
);
16251 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
16252 shorter. This can be caused by log truncation in *Messages*. */
16253 if (CHARPOS (lpoint
) <= ZV
)
16254 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
16256 unbind_to (count
, Qnil
);
16260 /* Build the complete desired matrix of WINDOW with a window start
16261 buffer position POS.
16263 Value is 1 if successful. It is zero if fonts were loaded during
16264 redisplay which makes re-adjusting glyph matrices necessary, and -1
16265 if point would appear in the scroll margins.
16266 (We check the former only if TRY_WINDOW_IGNORE_FONTS_CHANGE is
16267 unset in FLAGS, and the latter only if TRY_WINDOW_CHECK_MARGINS is
16271 try_window (Lisp_Object window
, struct text_pos pos
, int flags
)
16273 struct window
*w
= XWINDOW (window
);
16275 struct glyph_row
*last_text_row
= NULL
;
16276 struct frame
*f
= XFRAME (w
->frame
);
16278 /* Make POS the new window start. */
16279 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
16281 /* Mark cursor position as unknown. No overlay arrow seen. */
16282 w
->cursor
.vpos
= -1;
16283 overlay_arrow_seen
= 0;
16285 /* Initialize iterator and info to start at POS. */
16286 start_display (&it
, w
, pos
);
16288 /* Display all lines of W. */
16289 while (it
.current_y
< it
.last_visible_y
)
16291 if (display_line (&it
))
16292 last_text_row
= it
.glyph_row
- 1;
16293 if (fonts_changed_p
&& !(flags
& TRY_WINDOW_IGNORE_FONTS_CHANGE
))
16297 /* Don't let the cursor end in the scroll margins. */
16298 if ((flags
& TRY_WINDOW_CHECK_MARGINS
)
16299 && !MINI_WINDOW_P (w
))
16301 int this_scroll_margin
;
16303 if (scroll_margin
> 0)
16305 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
16306 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
16309 this_scroll_margin
= 0;
16311 if ((w
->cursor
.y
>= 0 /* not vscrolled */
16312 && w
->cursor
.y
< this_scroll_margin
16313 && CHARPOS (pos
) > BEGV
16314 && IT_CHARPOS (it
) < ZV
)
16315 /* rms: considering make_cursor_line_fully_visible_p here
16316 seems to give wrong results. We don't want to recenter
16317 when the last line is partly visible, we want to allow
16318 that case to be handled in the usual way. */
16319 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
16321 w
->cursor
.vpos
= -1;
16322 clear_glyph_matrix (w
->desired_matrix
);
16327 /* If bottom moved off end of frame, change mode line percentage. */
16328 if (XFASTINT (w
->window_end_pos
) <= 0
16329 && Z
!= IT_CHARPOS (it
))
16330 w
->update_mode_line
= 1;
16332 /* Set window_end_pos to the offset of the last character displayed
16333 on the window from the end of current_buffer. Set
16334 window_end_vpos to its row number. */
16337 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
16338 w
->window_end_bytepos
16339 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16340 wset_window_end_pos
16341 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
)));
16342 wset_window_end_vpos
16343 (w
, make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
)));
16345 (MATRIX_ROW (w
->desired_matrix
,
16346 XFASTINT (w
->window_end_vpos
))->displays_text_p
);
16350 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16351 wset_window_end_pos (w
, make_number (Z
- ZV
));
16352 wset_window_end_vpos (w
, make_number (0));
16355 /* But that is not valid info until redisplay finishes. */
16356 wset_window_end_valid (w
, Qnil
);
16362 /************************************************************************
16363 Window redisplay reusing current matrix when buffer has not changed
16364 ************************************************************************/
16366 /* Try redisplay of window W showing an unchanged buffer with a
16367 different window start than the last time it was displayed by
16368 reusing its current matrix. Value is non-zero if successful.
16369 W->start is the new window start. */
16372 try_window_reusing_current_matrix (struct window
*w
)
16374 struct frame
*f
= XFRAME (w
->frame
);
16375 struct glyph_row
*bottom_row
;
16378 struct text_pos start
, new_start
;
16379 int nrows_scrolled
, i
;
16380 struct glyph_row
*last_text_row
;
16381 struct glyph_row
*last_reused_text_row
;
16382 struct glyph_row
*start_row
;
16383 int start_vpos
, min_y
, max_y
;
16386 if (inhibit_try_window_reusing
)
16390 if (/* This function doesn't handle terminal frames. */
16391 !FRAME_WINDOW_P (f
)
16392 /* Don't try to reuse the display if windows have been split
16394 || windows_or_buffers_changed
16395 || cursor_type_changed
)
16398 /* Can't do this if region may have changed. */
16399 if ((!NILP (Vtransient_mark_mode
)
16400 && !NILP (BVAR (current_buffer
, mark_active
)))
16401 || !NILP (w
->region_showing
)
16402 || !NILP (Vshow_trailing_whitespace
))
16405 /* If top-line visibility has changed, give up. */
16406 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16407 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
16410 /* Give up if old or new display is scrolled vertically. We could
16411 make this function handle this, but right now it doesn't. */
16412 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16413 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
16416 /* The variable new_start now holds the new window start. The old
16417 start `start' can be determined from the current matrix. */
16418 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
16419 start
= start_row
->minpos
;
16420 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16422 /* Clear the desired matrix for the display below. */
16423 clear_glyph_matrix (w
->desired_matrix
);
16425 if (CHARPOS (new_start
) <= CHARPOS (start
))
16427 /* Don't use this method if the display starts with an ellipsis
16428 displayed for invisible text. It's not easy to handle that case
16429 below, and it's certainly not worth the effort since this is
16430 not a frequent case. */
16431 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
16434 IF_DEBUG (debug_method_add (w
, "twu1"));
16436 /* Display up to a row that can be reused. The variable
16437 last_text_row is set to the last row displayed that displays
16438 text. Note that it.vpos == 0 if or if not there is a
16439 header-line; it's not the same as the MATRIX_ROW_VPOS! */
16440 start_display (&it
, w
, new_start
);
16441 w
->cursor
.vpos
= -1;
16442 last_text_row
= last_reused_text_row
= NULL
;
16444 while (it
.current_y
< it
.last_visible_y
16445 && !fonts_changed_p
)
16447 /* If we have reached into the characters in the START row,
16448 that means the line boundaries have changed. So we
16449 can't start copying with the row START. Maybe it will
16450 work to start copying with the following row. */
16451 while (IT_CHARPOS (it
) > CHARPOS (start
))
16453 /* Advance to the next row as the "start". */
16455 start
= start_row
->minpos
;
16456 /* If there are no more rows to try, or just one, give up. */
16457 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
16458 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
16459 || CHARPOS (start
) == ZV
)
16461 clear_glyph_matrix (w
->desired_matrix
);
16465 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16467 /* If we have reached alignment, we can copy the rest of the
16469 if (IT_CHARPOS (it
) == CHARPOS (start
)
16470 /* Don't accept "alignment" inside a display vector,
16471 since start_row could have started in the middle of
16472 that same display vector (thus their character
16473 positions match), and we have no way of telling if
16474 that is the case. */
16475 && it
.current
.dpvec_index
< 0)
16478 if (display_line (&it
))
16479 last_text_row
= it
.glyph_row
- 1;
16483 /* A value of current_y < last_visible_y means that we stopped
16484 at the previous window start, which in turn means that we
16485 have at least one reusable row. */
16486 if (it
.current_y
< it
.last_visible_y
)
16488 struct glyph_row
*row
;
16490 /* IT.vpos always starts from 0; it counts text lines. */
16491 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
16493 /* Find PT if not already found in the lines displayed. */
16494 if (w
->cursor
.vpos
< 0)
16496 int dy
= it
.current_y
- start_row
->y
;
16498 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16499 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
16501 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
16502 dy
, nrows_scrolled
);
16505 clear_glyph_matrix (w
->desired_matrix
);
16510 /* Scroll the display. Do it before the current matrix is
16511 changed. The problem here is that update has not yet
16512 run, i.e. part of the current matrix is not up to date.
16513 scroll_run_hook will clear the cursor, and use the
16514 current matrix to get the height of the row the cursor is
16516 run
.current_y
= start_row
->y
;
16517 run
.desired_y
= it
.current_y
;
16518 run
.height
= it
.last_visible_y
- it
.current_y
;
16520 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
16523 FRAME_RIF (f
)->update_window_begin_hook (w
);
16524 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16525 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16526 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16530 /* Shift current matrix down by nrows_scrolled lines. */
16531 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16532 rotate_matrix (w
->current_matrix
,
16534 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16537 /* Disable lines that must be updated. */
16538 for (i
= 0; i
< nrows_scrolled
; ++i
)
16539 (start_row
+ i
)->enabled_p
= 0;
16541 /* Re-compute Y positions. */
16542 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16543 max_y
= it
.last_visible_y
;
16544 for (row
= start_row
+ nrows_scrolled
;
16548 row
->y
= it
.current_y
;
16549 row
->visible_height
= row
->height
;
16551 if (row
->y
< min_y
)
16552 row
->visible_height
-= min_y
- row
->y
;
16553 if (row
->y
+ row
->height
> max_y
)
16554 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16555 if (row
->fringe_bitmap_periodic_p
)
16556 row
->redraw_fringe_bitmaps_p
= 1;
16558 it
.current_y
+= row
->height
;
16560 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16561 last_reused_text_row
= row
;
16562 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
16566 /* Disable lines in the current matrix which are now
16567 below the window. */
16568 for (++row
; row
< bottom_row
; ++row
)
16569 row
->enabled_p
= row
->mode_line_p
= 0;
16572 /* Update window_end_pos etc.; last_reused_text_row is the last
16573 reused row from the current matrix containing text, if any.
16574 The value of last_text_row is the last displayed line
16575 containing text. */
16576 if (last_reused_text_row
)
16578 w
->window_end_bytepos
16579 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
16580 wset_window_end_pos
16582 - MATRIX_ROW_END_CHARPOS (last_reused_text_row
)));
16583 wset_window_end_vpos
16584 (w
, make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
16585 w
->current_matrix
)));
16587 else if (last_text_row
)
16589 w
->window_end_bytepos
16590 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16591 wset_window_end_pos
16592 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
)));
16593 wset_window_end_vpos
16594 (w
, make_number (MATRIX_ROW_VPOS (last_text_row
,
16595 w
->desired_matrix
)));
16599 /* This window must be completely empty. */
16600 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16601 wset_window_end_pos (w
, make_number (Z
- ZV
));
16602 wset_window_end_vpos (w
, make_number (0));
16604 wset_window_end_valid (w
, Qnil
);
16606 /* Update hint: don't try scrolling again in update_window. */
16607 w
->desired_matrix
->no_scrolling_p
= 1;
16610 debug_method_add (w
, "try_window_reusing_current_matrix 1");
16614 else if (CHARPOS (new_start
) > CHARPOS (start
))
16616 struct glyph_row
*pt_row
, *row
;
16617 struct glyph_row
*first_reusable_row
;
16618 struct glyph_row
*first_row_to_display
;
16620 int yb
= window_text_bottom_y (w
);
16622 /* Find the row starting at new_start, if there is one. Don't
16623 reuse a partially visible line at the end. */
16624 first_reusable_row
= start_row
;
16625 while (first_reusable_row
->enabled_p
16626 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
16627 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16628 < CHARPOS (new_start
)))
16629 ++first_reusable_row
;
16631 /* Give up if there is no row to reuse. */
16632 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
16633 || !first_reusable_row
->enabled_p
16634 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16635 != CHARPOS (new_start
)))
16638 /* We can reuse fully visible rows beginning with
16639 first_reusable_row to the end of the window. Set
16640 first_row_to_display to the first row that cannot be reused.
16641 Set pt_row to the row containing point, if there is any. */
16643 for (first_row_to_display
= first_reusable_row
;
16644 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
16645 ++first_row_to_display
)
16647 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
16648 && (PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16649 || (PT
== MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16650 && first_row_to_display
->ends_at_zv_p
16651 && pt_row
== NULL
)))
16652 pt_row
= first_row_to_display
;
16655 /* Start displaying at the start of first_row_to_display. */
16656 eassert (first_row_to_display
->y
< yb
);
16657 init_to_row_start (&it
, w
, first_row_to_display
);
16659 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
16661 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
16663 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
16664 + WINDOW_HEADER_LINE_HEIGHT (w
));
16666 /* Display lines beginning with first_row_to_display in the
16667 desired matrix. Set last_text_row to the last row displayed
16668 that displays text. */
16669 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
16670 if (pt_row
== NULL
)
16671 w
->cursor
.vpos
= -1;
16672 last_text_row
= NULL
;
16673 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
16674 if (display_line (&it
))
16675 last_text_row
= it
.glyph_row
- 1;
16677 /* If point is in a reused row, adjust y and vpos of the cursor
16681 w
->cursor
.vpos
-= nrows_scrolled
;
16682 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
16685 /* Give up if point isn't in a row displayed or reused. (This
16686 also handles the case where w->cursor.vpos < nrows_scrolled
16687 after the calls to display_line, which can happen with scroll
16688 margins. See bug#1295.) */
16689 if (w
->cursor
.vpos
< 0)
16691 clear_glyph_matrix (w
->desired_matrix
);
16695 /* Scroll the display. */
16696 run
.current_y
= first_reusable_row
->y
;
16697 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16698 run
.height
= it
.last_visible_y
- run
.current_y
;
16699 dy
= run
.current_y
- run
.desired_y
;
16704 FRAME_RIF (f
)->update_window_begin_hook (w
);
16705 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16706 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16707 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16711 /* Adjust Y positions of reused rows. */
16712 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16713 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16714 max_y
= it
.last_visible_y
;
16715 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
16718 row
->visible_height
= row
->height
;
16719 if (row
->y
< min_y
)
16720 row
->visible_height
-= min_y
- row
->y
;
16721 if (row
->y
+ row
->height
> max_y
)
16722 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16723 if (row
->fringe_bitmap_periodic_p
)
16724 row
->redraw_fringe_bitmaps_p
= 1;
16727 /* Scroll the current matrix. */
16728 eassert (nrows_scrolled
> 0);
16729 rotate_matrix (w
->current_matrix
,
16731 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16734 /* Disable rows not reused. */
16735 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
16736 row
->enabled_p
= 0;
16738 /* Point may have moved to a different line, so we cannot assume that
16739 the previous cursor position is valid; locate the correct row. */
16742 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
16744 && PT
>= MATRIX_ROW_END_CHARPOS (row
)
16745 && !row
->ends_at_zv_p
;
16749 w
->cursor
.y
= row
->y
;
16751 if (row
< bottom_row
)
16753 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
16754 struct glyph
*end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16756 /* Can't use this optimization with bidi-reordered glyph
16757 rows, unless cursor is already at point. */
16758 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
16760 if (!(w
->cursor
.hpos
>= 0
16761 && w
->cursor
.hpos
< row
->used
[TEXT_AREA
]
16762 && BUFFERP (glyph
->object
)
16763 && glyph
->charpos
== PT
))
16768 && (!BUFFERP (glyph
->object
)
16769 || glyph
->charpos
< PT
);
16773 w
->cursor
.x
+= glyph
->pixel_width
;
16778 /* Adjust window end. A null value of last_text_row means that
16779 the window end is in reused rows which in turn means that
16780 only its vpos can have changed. */
16783 w
->window_end_bytepos
16784 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16785 wset_window_end_pos
16786 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
)));
16787 wset_window_end_vpos
16788 (w
, make_number (MATRIX_ROW_VPOS (last_text_row
,
16789 w
->desired_matrix
)));
16793 wset_window_end_vpos
16794 (w
, make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
));
16797 wset_window_end_valid (w
, Qnil
);
16798 w
->desired_matrix
->no_scrolling_p
= 1;
16801 debug_method_add (w
, "try_window_reusing_current_matrix 2");
16811 /************************************************************************
16812 Window redisplay reusing current matrix when buffer has changed
16813 ************************************************************************/
16815 static struct glyph_row
*find_last_unchanged_at_beg_row (struct window
*);
16816 static struct glyph_row
*find_first_unchanged_at_end_row (struct window
*,
16817 ptrdiff_t *, ptrdiff_t *);
16818 static struct glyph_row
*
16819 find_last_row_displaying_text (struct glyph_matrix
*, struct it
*,
16820 struct glyph_row
*);
16823 /* Return the last row in MATRIX displaying text. If row START is
16824 non-null, start searching with that row. IT gives the dimensions
16825 of the display. Value is null if matrix is empty; otherwise it is
16826 a pointer to the row found. */
16828 static struct glyph_row
*
16829 find_last_row_displaying_text (struct glyph_matrix
*matrix
, struct it
*it
,
16830 struct glyph_row
*start
)
16832 struct glyph_row
*row
, *row_found
;
16834 /* Set row_found to the last row in IT->w's current matrix
16835 displaying text. The loop looks funny but think of partially
16838 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
16839 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16841 eassert (row
->enabled_p
);
16843 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
16852 /* Return the last row in the current matrix of W that is not affected
16853 by changes at the start of current_buffer that occurred since W's
16854 current matrix was built. Value is null if no such row exists.
16856 BEG_UNCHANGED us the number of characters unchanged at the start of
16857 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
16858 first changed character in current_buffer. Characters at positions <
16859 BEG + BEG_UNCHANGED are at the same buffer positions as they were
16860 when the current matrix was built. */
16862 static struct glyph_row
*
16863 find_last_unchanged_at_beg_row (struct window
*w
)
16865 ptrdiff_t first_changed_pos
= BEG
+ BEG_UNCHANGED
;
16866 struct glyph_row
*row
;
16867 struct glyph_row
*row_found
= NULL
;
16868 int yb
= window_text_bottom_y (w
);
16870 /* Find the last row displaying unchanged text. */
16871 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16872 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
16873 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
16876 if (/* If row ends before first_changed_pos, it is unchanged,
16877 except in some case. */
16878 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
16879 /* When row ends in ZV and we write at ZV it is not
16881 && !row
->ends_at_zv_p
16882 /* When first_changed_pos is the end of a continued line,
16883 row is not unchanged because it may be no longer
16885 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
16886 && (row
->continued_p
16887 || row
->exact_window_width_line_p
))
16888 /* If ROW->end is beyond ZV, then ROW->end is outdated and
16889 needs to be recomputed, so don't consider this row as
16890 unchanged. This happens when the last line was
16891 bidi-reordered and was killed immediately before this
16892 redisplay cycle. In that case, ROW->end stores the
16893 buffer position of the first visual-order character of
16894 the killed text, which is now beyond ZV. */
16895 && CHARPOS (row
->end
.pos
) <= ZV
)
16898 /* Stop if last visible row. */
16899 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
16907 /* Find the first glyph row in the current matrix of W that is not
16908 affected by changes at the end of current_buffer since the
16909 time W's current matrix was built.
16911 Return in *DELTA the number of chars by which buffer positions in
16912 unchanged text at the end of current_buffer must be adjusted.
16914 Return in *DELTA_BYTES the corresponding number of bytes.
16916 Value is null if no such row exists, i.e. all rows are affected by
16919 static struct glyph_row
*
16920 find_first_unchanged_at_end_row (struct window
*w
,
16921 ptrdiff_t *delta
, ptrdiff_t *delta_bytes
)
16923 struct glyph_row
*row
;
16924 struct glyph_row
*row_found
= NULL
;
16926 *delta
= *delta_bytes
= 0;
16928 /* Display must not have been paused, otherwise the current matrix
16929 is not up to date. */
16930 eassert (!NILP (w
->window_end_valid
));
16932 /* A value of window_end_pos >= END_UNCHANGED means that the window
16933 end is in the range of changed text. If so, there is no
16934 unchanged row at the end of W's current matrix. */
16935 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
16938 /* Set row to the last row in W's current matrix displaying text. */
16939 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
16941 /* If matrix is entirely empty, no unchanged row exists. */
16942 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16944 /* The value of row is the last glyph row in the matrix having a
16945 meaningful buffer position in it. The end position of row
16946 corresponds to window_end_pos. This allows us to translate
16947 buffer positions in the current matrix to current buffer
16948 positions for characters not in changed text. */
16950 MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
16951 ptrdiff_t Z_BYTE_old
=
16952 MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
16953 ptrdiff_t last_unchanged_pos
, last_unchanged_pos_old
;
16954 struct glyph_row
*first_text_row
16955 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16957 *delta
= Z
- Z_old
;
16958 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
16960 /* Set last_unchanged_pos to the buffer position of the last
16961 character in the buffer that has not been changed. Z is the
16962 index + 1 of the last character in current_buffer, i.e. by
16963 subtracting END_UNCHANGED we get the index of the last
16964 unchanged character, and we have to add BEG to get its buffer
16966 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
16967 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
16969 /* Search backward from ROW for a row displaying a line that
16970 starts at a minimum position >= last_unchanged_pos_old. */
16971 for (; row
> first_text_row
; --row
)
16973 /* This used to abort, but it can happen.
16974 It is ok to just stop the search instead here. KFS. */
16975 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16978 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
16983 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
16989 /* Make sure that glyph rows in the current matrix of window W
16990 reference the same glyph memory as corresponding rows in the
16991 frame's frame matrix. This function is called after scrolling W's
16992 current matrix on a terminal frame in try_window_id and
16993 try_window_reusing_current_matrix. */
16996 sync_frame_with_window_matrix_rows (struct window
*w
)
16998 struct frame
*f
= XFRAME (w
->frame
);
16999 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
17001 /* Preconditions: W must be a leaf window and full-width. Its frame
17002 must have a frame matrix. */
17003 eassert (NILP (w
->hchild
) && NILP (w
->vchild
));
17004 eassert (WINDOW_FULL_WIDTH_P (w
));
17005 eassert (!FRAME_WINDOW_P (f
));
17007 /* If W is a full-width window, glyph pointers in W's current matrix
17008 have, by definition, to be the same as glyph pointers in the
17009 corresponding frame matrix. Note that frame matrices have no
17010 marginal areas (see build_frame_matrix). */
17011 window_row
= w
->current_matrix
->rows
;
17012 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
17013 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
17014 while (window_row
< window_row_end
)
17016 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
17017 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
17019 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
17020 frame_row
->glyphs
[TEXT_AREA
] = start
;
17021 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
17022 frame_row
->glyphs
[LAST_AREA
] = end
;
17024 /* Disable frame rows whose corresponding window rows have
17025 been disabled in try_window_id. */
17026 if (!window_row
->enabled_p
)
17027 frame_row
->enabled_p
= 0;
17029 ++window_row
, ++frame_row
;
17034 /* Find the glyph row in window W containing CHARPOS. Consider all
17035 rows between START and END (not inclusive). END null means search
17036 all rows to the end of the display area of W. Value is the row
17037 containing CHARPOS or null. */
17040 row_containing_pos (struct window
*w
, ptrdiff_t charpos
,
17041 struct glyph_row
*start
, struct glyph_row
*end
, int dy
)
17043 struct glyph_row
*row
= start
;
17044 struct glyph_row
*best_row
= NULL
;
17045 ptrdiff_t mindif
= BUF_ZV (XBUFFER (w
->buffer
)) + 1;
17048 /* If we happen to start on a header-line, skip that. */
17049 if (row
->mode_line_p
)
17052 if ((end
&& row
>= end
) || !row
->enabled_p
)
17055 last_y
= window_text_bottom_y (w
) - dy
;
17059 /* Give up if we have gone too far. */
17060 if (end
&& row
>= end
)
17062 /* This formerly returned if they were equal.
17063 I think that both quantities are of a "last plus one" type;
17064 if so, when they are equal, the row is within the screen. -- rms. */
17065 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
17068 /* If it is in this row, return this row. */
17069 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
17070 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
17071 /* The end position of a row equals the start
17072 position of the next row. If CHARPOS is there, we
17073 would rather display it in the next line, except
17074 when this line ends in ZV. */
17075 && !row
->ends_at_zv_p
17076 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
17077 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
17081 if (NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
17082 || (!best_row
&& !row
->continued_p
))
17084 /* In bidi-reordered rows, there could be several rows
17085 occluding point, all of them belonging to the same
17086 continued line. We need to find the row which fits
17087 CHARPOS the best. */
17088 for (g
= row
->glyphs
[TEXT_AREA
];
17089 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
17092 if (!STRINGP (g
->object
))
17094 if (g
->charpos
> 0 && eabs (g
->charpos
- charpos
) < mindif
)
17096 mindif
= eabs (g
->charpos
- charpos
);
17098 /* Exact match always wins. */
17105 else if (best_row
&& !row
->continued_p
)
17112 /* Try to redisplay window W by reusing its existing display. W's
17113 current matrix must be up to date when this function is called,
17114 i.e. window_end_valid must not be nil.
17118 1 if display has been updated
17119 0 if otherwise unsuccessful
17120 -1 if redisplay with same window start is known not to succeed
17122 The following steps are performed:
17124 1. Find the last row in the current matrix of W that is not
17125 affected by changes at the start of current_buffer. If no such row
17128 2. Find the first row in W's current matrix that is not affected by
17129 changes at the end of current_buffer. Maybe there is no such row.
17131 3. Display lines beginning with the row + 1 found in step 1 to the
17132 row found in step 2 or, if step 2 didn't find a row, to the end of
17135 4. If cursor is not known to appear on the window, give up.
17137 5. If display stopped at the row found in step 2, scroll the
17138 display and current matrix as needed.
17140 6. Maybe display some lines at the end of W, if we must. This can
17141 happen under various circumstances, like a partially visible line
17142 becoming fully visible, or because newly displayed lines are displayed
17143 in smaller font sizes.
17145 7. Update W's window end information. */
17148 try_window_id (struct window
*w
)
17150 struct frame
*f
= XFRAME (w
->frame
);
17151 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
17152 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
17153 struct glyph_row
*last_unchanged_at_beg_row
;
17154 struct glyph_row
*first_unchanged_at_end_row
;
17155 struct glyph_row
*row
;
17156 struct glyph_row
*bottom_row
;
17159 ptrdiff_t delta
= 0, delta_bytes
= 0, stop_pos
;
17161 struct text_pos start_pos
;
17163 int first_unchanged_at_end_vpos
= 0;
17164 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
17165 struct text_pos start
;
17166 ptrdiff_t first_changed_charpos
, last_changed_charpos
;
17169 if (inhibit_try_window_id
)
17173 /* This is handy for debugging. */
17175 #define GIVE_UP(X) \
17177 fprintf (stderr, "try_window_id give up %d\n", (X)); \
17181 #define GIVE_UP(X) return 0
17184 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
17186 /* Don't use this for mini-windows because these can show
17187 messages and mini-buffers, and we don't handle that here. */
17188 if (MINI_WINDOW_P (w
))
17191 /* This flag is used to prevent redisplay optimizations. */
17192 if (windows_or_buffers_changed
|| cursor_type_changed
)
17195 /* Verify that narrowing has not changed.
17196 Also verify that we were not told to prevent redisplay optimizations.
17197 It would be nice to further
17198 reduce the number of cases where this prevents try_window_id. */
17199 if (current_buffer
->clip_changed
17200 || current_buffer
->prevent_redisplay_optimizations_p
)
17203 /* Window must either use window-based redisplay or be full width. */
17204 if (!FRAME_WINDOW_P (f
)
17205 && (!FRAME_LINE_INS_DEL_OK (f
)
17206 || !WINDOW_FULL_WIDTH_P (w
)))
17209 /* Give up if point is known NOT to appear in W. */
17210 if (PT
< CHARPOS (start
))
17213 /* Another way to prevent redisplay optimizations. */
17214 if (w
->last_modified
== 0)
17217 /* Verify that window is not hscrolled. */
17218 if (w
->hscroll
!= 0)
17221 /* Verify that display wasn't paused. */
17222 if (NILP (w
->window_end_valid
))
17225 /* Can't use this if highlighting a region because a cursor movement
17226 will do more than just set the cursor. */
17227 if (!NILP (Vtransient_mark_mode
)
17228 && !NILP (BVAR (current_buffer
, mark_active
)))
17231 /* Likewise if highlighting trailing whitespace. */
17232 if (!NILP (Vshow_trailing_whitespace
))
17235 /* Likewise if showing a region. */
17236 if (!NILP (w
->region_showing
))
17239 /* Can't use this if overlay arrow position and/or string have
17241 if (overlay_arrows_changed_p ())
17244 /* When word-wrap is on, adding a space to the first word of a
17245 wrapped line can change the wrap position, altering the line
17246 above it. It might be worthwhile to handle this more
17247 intelligently, but for now just redisplay from scratch. */
17248 if (!NILP (BVAR (XBUFFER (w
->buffer
), word_wrap
)))
17251 /* Under bidi reordering, adding or deleting a character in the
17252 beginning of a paragraph, before the first strong directional
17253 character, can change the base direction of the paragraph (unless
17254 the buffer specifies a fixed paragraph direction), which will
17255 require to redisplay the whole paragraph. It might be worthwhile
17256 to find the paragraph limits and widen the range of redisplayed
17257 lines to that, but for now just give up this optimization and
17258 redisplay from scratch. */
17259 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
17260 && NILP (BVAR (XBUFFER (w
->buffer
), bidi_paragraph_direction
)))
17263 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
17264 only if buffer has really changed. The reason is that the gap is
17265 initially at Z for freshly visited files. The code below would
17266 set end_unchanged to 0 in that case. */
17267 if (MODIFF
> SAVE_MODIFF
17268 /* This seems to happen sometimes after saving a buffer. */
17269 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
17271 if (GPT
- BEG
< BEG_UNCHANGED
)
17272 BEG_UNCHANGED
= GPT
- BEG
;
17273 if (Z
- GPT
< END_UNCHANGED
)
17274 END_UNCHANGED
= Z
- GPT
;
17277 /* The position of the first and last character that has been changed. */
17278 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
17279 last_changed_charpos
= Z
- END_UNCHANGED
;
17281 /* If window starts after a line end, and the last change is in
17282 front of that newline, then changes don't affect the display.
17283 This case happens with stealth-fontification. Note that although
17284 the display is unchanged, glyph positions in the matrix have to
17285 be adjusted, of course. */
17286 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
17287 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
17288 && ((last_changed_charpos
< CHARPOS (start
)
17289 && CHARPOS (start
) == BEGV
)
17290 || (last_changed_charpos
< CHARPOS (start
) - 1
17291 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
17293 ptrdiff_t Z_old
, Z_delta
, Z_BYTE_old
, Z_delta_bytes
;
17294 struct glyph_row
*r0
;
17296 /* Compute how many chars/bytes have been added to or removed
17297 from the buffer. */
17298 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
17299 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
17300 Z_delta
= Z
- Z_old
;
17301 Z_delta_bytes
= Z_BYTE
- Z_BYTE_old
;
17303 /* Give up if PT is not in the window. Note that it already has
17304 been checked at the start of try_window_id that PT is not in
17305 front of the window start. */
17306 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + Z_delta
)
17309 /* If window start is unchanged, we can reuse the whole matrix
17310 as is, after adjusting glyph positions. No need to compute
17311 the window end again, since its offset from Z hasn't changed. */
17312 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17313 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + Z_delta
17314 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + Z_delta_bytes
17315 /* PT must not be in a partially visible line. */
17316 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + Z_delta
17317 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17319 /* Adjust positions in the glyph matrix. */
17320 if (Z_delta
|| Z_delta_bytes
)
17322 struct glyph_row
*r1
17323 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17324 increment_matrix_positions (w
->current_matrix
,
17325 MATRIX_ROW_VPOS (r0
, current_matrix
),
17326 MATRIX_ROW_VPOS (r1
, current_matrix
),
17327 Z_delta
, Z_delta_bytes
);
17330 /* Set the cursor. */
17331 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17333 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17340 /* Handle the case that changes are all below what is displayed in
17341 the window, and that PT is in the window. This shortcut cannot
17342 be taken if ZV is visible in the window, and text has been added
17343 there that is visible in the window. */
17344 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
17345 /* ZV is not visible in the window, or there are no
17346 changes at ZV, actually. */
17347 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
17348 || first_changed_charpos
== last_changed_charpos
))
17350 struct glyph_row
*r0
;
17352 /* Give up if PT is not in the window. Note that it already has
17353 been checked at the start of try_window_id that PT is not in
17354 front of the window start. */
17355 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
17358 /* If window start is unchanged, we can reuse the whole matrix
17359 as is, without changing glyph positions since no text has
17360 been added/removed in front of the window end. */
17361 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17362 if (TEXT_POS_EQUAL_P (start
, r0
->minpos
)
17363 /* PT must not be in a partially visible line. */
17364 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
17365 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17367 /* We have to compute the window end anew since text
17368 could have been added/removed after it. */
17369 wset_window_end_pos
17370 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (row
)));
17371 w
->window_end_bytepos
17372 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17374 /* Set the cursor. */
17375 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17377 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17384 /* Give up if window start is in the changed area.
17386 The condition used to read
17388 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
17390 but why that was tested escapes me at the moment. */
17391 if (CHARPOS (start
) >= first_changed_charpos
17392 && CHARPOS (start
) <= last_changed_charpos
)
17395 /* Check that window start agrees with the start of the first glyph
17396 row in its current matrix. Check this after we know the window
17397 start is not in changed text, otherwise positions would not be
17399 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17400 if (!TEXT_POS_EQUAL_P (start
, row
->minpos
))
17403 /* Give up if the window ends in strings. Overlay strings
17404 at the end are difficult to handle, so don't try. */
17405 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
17406 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
17409 /* Compute the position at which we have to start displaying new
17410 lines. Some of the lines at the top of the window might be
17411 reusable because they are not displaying changed text. Find the
17412 last row in W's current matrix not affected by changes at the
17413 start of current_buffer. Value is null if changes start in the
17414 first line of window. */
17415 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
17416 if (last_unchanged_at_beg_row
)
17418 /* Avoid starting to display in the middle of a character, a TAB
17419 for instance. This is easier than to set up the iterator
17420 exactly, and it's not a frequent case, so the additional
17421 effort wouldn't really pay off. */
17422 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
17423 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
17424 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
17425 --last_unchanged_at_beg_row
;
17427 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
17430 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
17432 start_pos
= it
.current
.pos
;
17434 /* Start displaying new lines in the desired matrix at the same
17435 vpos we would use in the current matrix, i.e. below
17436 last_unchanged_at_beg_row. */
17437 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
17439 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17440 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
17442 eassert (it
.hpos
== 0 && it
.current_x
== 0);
17446 /* There are no reusable lines at the start of the window.
17447 Start displaying in the first text line. */
17448 start_display (&it
, w
, start
);
17449 it
.vpos
= it
.first_vpos
;
17450 start_pos
= it
.current
.pos
;
17453 /* Find the first row that is not affected by changes at the end of
17454 the buffer. Value will be null if there is no unchanged row, in
17455 which case we must redisplay to the end of the window. delta
17456 will be set to the value by which buffer positions beginning with
17457 first_unchanged_at_end_row have to be adjusted due to text
17459 first_unchanged_at_end_row
17460 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
17461 IF_DEBUG (debug_delta
= delta
);
17462 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
17464 /* Set stop_pos to the buffer position up to which we will have to
17465 display new lines. If first_unchanged_at_end_row != NULL, this
17466 is the buffer position of the start of the line displayed in that
17467 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
17468 that we don't stop at a buffer position. */
17470 if (first_unchanged_at_end_row
)
17472 eassert (last_unchanged_at_beg_row
== NULL
17473 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
17475 /* If this is a continuation line, move forward to the next one
17476 that isn't. Changes in lines above affect this line.
17477 Caution: this may move first_unchanged_at_end_row to a row
17478 not displaying text. */
17479 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
17480 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17481 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17482 < it
.last_visible_y
))
17483 ++first_unchanged_at_end_row
;
17485 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17486 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17487 >= it
.last_visible_y
))
17488 first_unchanged_at_end_row
= NULL
;
17491 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
17493 first_unchanged_at_end_vpos
17494 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
17495 eassert (stop_pos
>= Z
- END_UNCHANGED
);
17498 else if (last_unchanged_at_beg_row
== NULL
)
17504 /* Either there is no unchanged row at the end, or the one we have
17505 now displays text. This is a necessary condition for the window
17506 end pos calculation at the end of this function. */
17507 eassert (first_unchanged_at_end_row
== NULL
17508 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
17510 debug_last_unchanged_at_beg_vpos
17511 = (last_unchanged_at_beg_row
17512 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
17514 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
17516 #endif /* GLYPH_DEBUG */
17519 /* Display new lines. Set last_text_row to the last new line
17520 displayed which has text on it, i.e. might end up as being the
17521 line where the window_end_vpos is. */
17522 w
->cursor
.vpos
= -1;
17523 last_text_row
= NULL
;
17524 overlay_arrow_seen
= 0;
17525 while (it
.current_y
< it
.last_visible_y
17526 && !fonts_changed_p
17527 && (first_unchanged_at_end_row
== NULL
17528 || IT_CHARPOS (it
) < stop_pos
))
17530 if (display_line (&it
))
17531 last_text_row
= it
.glyph_row
- 1;
17534 if (fonts_changed_p
)
17538 /* Compute differences in buffer positions, y-positions etc. for
17539 lines reused at the bottom of the window. Compute what we can
17541 if (first_unchanged_at_end_row
17542 /* No lines reused because we displayed everything up to the
17543 bottom of the window. */
17544 && it
.current_y
< it
.last_visible_y
)
17547 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
17549 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
17550 run
.current_y
= first_unchanged_at_end_row
->y
;
17551 run
.desired_y
= run
.current_y
+ dy
;
17552 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
17556 delta
= delta_bytes
= dvpos
= dy
17557 = run
.current_y
= run
.desired_y
= run
.height
= 0;
17558 first_unchanged_at_end_row
= NULL
;
17560 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
17563 /* Find the cursor if not already found. We have to decide whether
17564 PT will appear on this window (it sometimes doesn't, but this is
17565 not a very frequent case.) This decision has to be made before
17566 the current matrix is altered. A value of cursor.vpos < 0 means
17567 that PT is either in one of the lines beginning at
17568 first_unchanged_at_end_row or below the window. Don't care for
17569 lines that might be displayed later at the window end; as
17570 mentioned, this is not a frequent case. */
17571 if (w
->cursor
.vpos
< 0)
17573 /* Cursor in unchanged rows at the top? */
17574 if (PT
< CHARPOS (start_pos
)
17575 && last_unchanged_at_beg_row
)
17577 row
= row_containing_pos (w
, PT
,
17578 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
17579 last_unchanged_at_beg_row
+ 1, 0);
17581 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
17584 /* Start from first_unchanged_at_end_row looking for PT. */
17585 else if (first_unchanged_at_end_row
)
17587 row
= row_containing_pos (w
, PT
- delta
,
17588 first_unchanged_at_end_row
, NULL
, 0);
17590 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
17591 delta_bytes
, dy
, dvpos
);
17594 /* Give up if cursor was not found. */
17595 if (w
->cursor
.vpos
< 0)
17597 clear_glyph_matrix (w
->desired_matrix
);
17602 /* Don't let the cursor end in the scroll margins. */
17604 int this_scroll_margin
, cursor_height
;
17606 this_scroll_margin
=
17607 max (0, min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4));
17608 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
17609 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
17611 if ((w
->cursor
.y
< this_scroll_margin
17612 && CHARPOS (start
) > BEGV
)
17613 /* Old redisplay didn't take scroll margin into account at the bottom,
17614 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
17615 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
17616 ? cursor_height
+ this_scroll_margin
17617 : 1)) > it
.last_visible_y
)
17619 w
->cursor
.vpos
= -1;
17620 clear_glyph_matrix (w
->desired_matrix
);
17625 /* Scroll the display. Do it before changing the current matrix so
17626 that xterm.c doesn't get confused about where the cursor glyph is
17628 if (dy
&& run
.height
)
17632 if (FRAME_WINDOW_P (f
))
17634 FRAME_RIF (f
)->update_window_begin_hook (w
);
17635 FRAME_RIF (f
)->clear_window_mouse_face (w
);
17636 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
17637 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
17641 /* Terminal frame. In this case, dvpos gives the number of
17642 lines to scroll by; dvpos < 0 means scroll up. */
17644 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
17645 int from
= WINDOW_TOP_EDGE_LINE (w
) + from_vpos
;
17646 int end
= (WINDOW_TOP_EDGE_LINE (w
)
17647 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
17648 + window_internal_height (w
));
17650 #if defined (HAVE_GPM) || defined (MSDOS)
17651 x_clear_window_mouse_face (w
);
17653 /* Perform the operation on the screen. */
17656 /* Scroll last_unchanged_at_beg_row to the end of the
17657 window down dvpos lines. */
17658 set_terminal_window (f
, end
);
17660 /* On dumb terminals delete dvpos lines at the end
17661 before inserting dvpos empty lines. */
17662 if (!FRAME_SCROLL_REGION_OK (f
))
17663 ins_del_lines (f
, end
- dvpos
, -dvpos
);
17665 /* Insert dvpos empty lines in front of
17666 last_unchanged_at_beg_row. */
17667 ins_del_lines (f
, from
, dvpos
);
17669 else if (dvpos
< 0)
17671 /* Scroll up last_unchanged_at_beg_vpos to the end of
17672 the window to last_unchanged_at_beg_vpos - |dvpos|. */
17673 set_terminal_window (f
, end
);
17675 /* Delete dvpos lines in front of
17676 last_unchanged_at_beg_vpos. ins_del_lines will set
17677 the cursor to the given vpos and emit |dvpos| delete
17679 ins_del_lines (f
, from
+ dvpos
, dvpos
);
17681 /* On a dumb terminal insert dvpos empty lines at the
17683 if (!FRAME_SCROLL_REGION_OK (f
))
17684 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
17687 set_terminal_window (f
, 0);
17693 /* Shift reused rows of the current matrix to the right position.
17694 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
17696 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17697 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
17700 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
17701 bottom_vpos
, dvpos
);
17702 clear_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
17705 else if (dvpos
> 0)
17707 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
17708 bottom_vpos
, dvpos
);
17709 clear_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
17710 first_unchanged_at_end_vpos
+ dvpos
);
17713 /* For frame-based redisplay, make sure that current frame and window
17714 matrix are in sync with respect to glyph memory. */
17715 if (!FRAME_WINDOW_P (f
))
17716 sync_frame_with_window_matrix_rows (w
);
17718 /* Adjust buffer positions in reused rows. */
17719 if (delta
|| delta_bytes
)
17720 increment_matrix_positions (current_matrix
,
17721 first_unchanged_at_end_vpos
+ dvpos
,
17722 bottom_vpos
, delta
, delta_bytes
);
17724 /* Adjust Y positions. */
17726 shift_glyph_matrix (w
, current_matrix
,
17727 first_unchanged_at_end_vpos
+ dvpos
,
17730 if (first_unchanged_at_end_row
)
17732 first_unchanged_at_end_row
+= dvpos
;
17733 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
17734 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
17735 first_unchanged_at_end_row
= NULL
;
17738 /* If scrolling up, there may be some lines to display at the end of
17740 last_text_row_at_end
= NULL
;
17743 /* Scrolling up can leave for example a partially visible line
17744 at the end of the window to be redisplayed. */
17745 /* Set last_row to the glyph row in the current matrix where the
17746 window end line is found. It has been moved up or down in
17747 the matrix by dvpos. */
17748 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
17749 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
17751 /* If last_row is the window end line, it should display text. */
17752 eassert (last_row
->displays_text_p
);
17754 /* If window end line was partially visible before, begin
17755 displaying at that line. Otherwise begin displaying with the
17756 line following it. */
17757 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
17759 init_to_row_start (&it
, w
, last_row
);
17760 it
.vpos
= last_vpos
;
17761 it
.current_y
= last_row
->y
;
17765 init_to_row_end (&it
, w
, last_row
);
17766 it
.vpos
= 1 + last_vpos
;
17767 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
17771 /* We may start in a continuation line. If so, we have to
17772 get the right continuation_lines_width and current_x. */
17773 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
17774 it
.hpos
= it
.current_x
= 0;
17776 /* Display the rest of the lines at the window end. */
17777 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17778 while (it
.current_y
< it
.last_visible_y
17779 && !fonts_changed_p
)
17781 /* Is it always sure that the display agrees with lines in
17782 the current matrix? I don't think so, so we mark rows
17783 displayed invalid in the current matrix by setting their
17784 enabled_p flag to zero. */
17785 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
17786 if (display_line (&it
))
17787 last_text_row_at_end
= it
.glyph_row
- 1;
17791 /* Update window_end_pos and window_end_vpos. */
17792 if (first_unchanged_at_end_row
17793 && !last_text_row_at_end
)
17795 /* Window end line if one of the preserved rows from the current
17796 matrix. Set row to the last row displaying text in current
17797 matrix starting at first_unchanged_at_end_row, after
17799 eassert (first_unchanged_at_end_row
->displays_text_p
);
17800 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
17801 first_unchanged_at_end_row
);
17802 eassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
17804 wset_window_end_pos (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (row
)));
17805 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17806 wset_window_end_vpos
17807 (w
, make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
)));
17808 eassert (w
->window_end_bytepos
>= 0);
17809 IF_DEBUG (debug_method_add (w
, "A"));
17811 else if (last_text_row_at_end
)
17813 wset_window_end_pos
17814 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
)));
17815 w
->window_end_bytepos
17816 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
17817 wset_window_end_vpos
17818 (w
, make_number (MATRIX_ROW_VPOS (last_text_row_at_end
,
17820 eassert (w
->window_end_bytepos
>= 0);
17821 IF_DEBUG (debug_method_add (w
, "B"));
17823 else if (last_text_row
)
17825 /* We have displayed either to the end of the window or at the
17826 end of the window, i.e. the last row with text is to be found
17827 in the desired matrix. */
17828 wset_window_end_pos
17829 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
)));
17830 w
->window_end_bytepos
17831 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
17832 wset_window_end_vpos
17833 (w
, make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
)));
17834 eassert (w
->window_end_bytepos
>= 0);
17836 else if (first_unchanged_at_end_row
== NULL
17837 && last_text_row
== NULL
17838 && last_text_row_at_end
== NULL
)
17840 /* Displayed to end of window, but no line containing text was
17841 displayed. Lines were deleted at the end of the window. */
17842 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
17843 int vpos
= XFASTINT (w
->window_end_vpos
);
17844 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
17845 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
17848 row
== NULL
&& vpos
>= first_vpos
;
17849 --vpos
, --current_row
, --desired_row
)
17851 if (desired_row
->enabled_p
)
17853 if (desired_row
->displays_text_p
)
17856 else if (current_row
->displays_text_p
)
17860 eassert (row
!= NULL
);
17861 wset_window_end_vpos (w
, make_number (vpos
+ 1));
17862 wset_window_end_pos (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (row
)));
17863 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17864 eassert (w
->window_end_bytepos
>= 0);
17865 IF_DEBUG (debug_method_add (w
, "C"));
17870 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
17871 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
17873 /* Record that display has not been completed. */
17874 wset_window_end_valid (w
, Qnil
);
17875 w
->desired_matrix
->no_scrolling_p
= 1;
17883 /***********************************************************************
17884 More debugging support
17885 ***********************************************************************/
17889 void dump_glyph_row (struct glyph_row
*, int, int) EXTERNALLY_VISIBLE
;
17890 void dump_glyph_matrix (struct glyph_matrix
*, int) EXTERNALLY_VISIBLE
;
17891 void dump_glyph (struct glyph_row
*, struct glyph
*, int) EXTERNALLY_VISIBLE
;
17894 /* Dump the contents of glyph matrix MATRIX on stderr.
17896 GLYPHS 0 means don't show glyph contents.
17897 GLYPHS 1 means show glyphs in short form
17898 GLYPHS > 1 means show glyphs in long form. */
17901 dump_glyph_matrix (struct glyph_matrix
*matrix
, int glyphs
)
17904 for (i
= 0; i
< matrix
->nrows
; ++i
)
17905 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
17909 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
17910 the glyph row and area where the glyph comes from. */
17913 dump_glyph (struct glyph_row
*row
, struct glyph
*glyph
, int area
)
17915 if (glyph
->type
== CHAR_GLYPH
)
17918 " %5td %4c %6"pI
"d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
17919 glyph
- row
->glyphs
[TEXT_AREA
],
17922 (BUFFERP (glyph
->object
)
17924 : (STRINGP (glyph
->object
)
17927 glyph
->pixel_width
,
17929 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
17933 glyph
->left_box_line_p
,
17934 glyph
->right_box_line_p
);
17936 else if (glyph
->type
== STRETCH_GLYPH
)
17939 " %5td %4c %6"pI
"d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
17940 glyph
- row
->glyphs
[TEXT_AREA
],
17943 (BUFFERP (glyph
->object
)
17945 : (STRINGP (glyph
->object
)
17948 glyph
->pixel_width
,
17952 glyph
->left_box_line_p
,
17953 glyph
->right_box_line_p
);
17955 else if (glyph
->type
== IMAGE_GLYPH
)
17958 " %5td %4c %6"pI
"d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
17959 glyph
- row
->glyphs
[TEXT_AREA
],
17962 (BUFFERP (glyph
->object
)
17964 : (STRINGP (glyph
->object
)
17967 glyph
->pixel_width
,
17971 glyph
->left_box_line_p
,
17972 glyph
->right_box_line_p
);
17974 else if (glyph
->type
== COMPOSITE_GLYPH
)
17977 " %5td %4c %6"pI
"d %c %3d 0x%05x",
17978 glyph
- row
->glyphs
[TEXT_AREA
],
17981 (BUFFERP (glyph
->object
)
17983 : (STRINGP (glyph
->object
)
17986 glyph
->pixel_width
,
17988 if (glyph
->u
.cmp
.automatic
)
17991 glyph
->slice
.cmp
.from
, glyph
->slice
.cmp
.to
);
17992 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
17994 glyph
->left_box_line_p
,
17995 glyph
->right_box_line_p
);
18000 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
18001 GLYPHS 0 means don't show glyph contents.
18002 GLYPHS 1 means show glyphs in short form
18003 GLYPHS > 1 means show glyphs in long form. */
18006 dump_glyph_row (struct glyph_row
*row
, int vpos
, int glyphs
)
18010 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
18011 fprintf (stderr
, "======================================================================\n");
18013 fprintf (stderr
, "%3d %5"pI
"d %5"pI
"d %4d %1.1d%1.1d%1.1d%1.1d\
18014 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
18016 MATRIX_ROW_START_CHARPOS (row
),
18017 MATRIX_ROW_END_CHARPOS (row
),
18018 row
->used
[TEXT_AREA
],
18019 row
->contains_overlapping_glyphs_p
,
18021 row
->truncated_on_left_p
,
18022 row
->truncated_on_right_p
,
18024 MATRIX_ROW_CONTINUATION_LINE_P (row
),
18025 row
->displays_text_p
,
18028 row
->ends_in_middle_of_char_p
,
18029 row
->starts_in_middle_of_char_p
,
18035 row
->visible_height
,
18038 fprintf (stderr
, "%9"pD
"d %5"pD
"d\t%5d\n", row
->start
.overlay_string_index
,
18039 row
->end
.overlay_string_index
,
18040 row
->continuation_lines_width
);
18041 fprintf (stderr
, "%9"pI
"d %5"pI
"d\n",
18042 CHARPOS (row
->start
.string_pos
),
18043 CHARPOS (row
->end
.string_pos
));
18044 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
18045 row
->end
.dpvec_index
);
18052 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18054 struct glyph
*glyph
= row
->glyphs
[area
];
18055 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
18057 /* Glyph for a line end in text. */
18058 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
18061 if (glyph
< glyph_end
)
18062 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
18064 for (; glyph
< glyph_end
; ++glyph
)
18065 dump_glyph (row
, glyph
, area
);
18068 else if (glyphs
== 1)
18072 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18074 char *s
= alloca (row
->used
[area
] + 1);
18077 for (i
= 0; i
< row
->used
[area
]; ++i
)
18079 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
18080 if (glyph
->type
== CHAR_GLYPH
18081 && glyph
->u
.ch
< 0x80
18082 && glyph
->u
.ch
>= ' ')
18083 s
[i
] = glyph
->u
.ch
;
18089 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
18095 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
18096 Sdump_glyph_matrix
, 0, 1, "p",
18097 doc
: /* Dump the current matrix of the selected window to stderr.
18098 Shows contents of glyph row structures. With non-nil
18099 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
18100 glyphs in short form, otherwise show glyphs in long form. */)
18101 (Lisp_Object glyphs
)
18103 struct window
*w
= XWINDOW (selected_window
);
18104 struct buffer
*buffer
= XBUFFER (w
->buffer
);
18106 fprintf (stderr
, "PT = %"pI
"d, BEGV = %"pI
"d. ZV = %"pI
"d\n",
18107 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
18108 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
18109 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
18110 fprintf (stderr
, "=============================================\n");
18111 dump_glyph_matrix (w
->current_matrix
,
18112 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 0);
18117 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
18118 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
18121 struct frame
*f
= XFRAME (selected_frame
);
18122 dump_glyph_matrix (f
->current_matrix
, 1);
18127 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
18128 doc
: /* Dump glyph row ROW to stderr.
18129 GLYPH 0 means don't dump glyphs.
18130 GLYPH 1 means dump glyphs in short form.
18131 GLYPH > 1 or omitted means dump glyphs in long form. */)
18132 (Lisp_Object row
, Lisp_Object glyphs
)
18134 struct glyph_matrix
*matrix
;
18137 CHECK_NUMBER (row
);
18138 matrix
= XWINDOW (selected_window
)->current_matrix
;
18140 if (vpos
>= 0 && vpos
< matrix
->nrows
)
18141 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
18143 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18148 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
18149 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
18150 GLYPH 0 means don't dump glyphs.
18151 GLYPH 1 means dump glyphs in short form.
18152 GLYPH > 1 or omitted means dump glyphs in long form. */)
18153 (Lisp_Object row
, Lisp_Object glyphs
)
18155 struct frame
*sf
= SELECTED_FRAME ();
18156 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
18159 CHECK_NUMBER (row
);
18161 if (vpos
>= 0 && vpos
< m
->nrows
)
18162 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
18163 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18168 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
18169 doc
: /* Toggle tracing of redisplay.
18170 With ARG, turn tracing on if and only if ARG is positive. */)
18174 trace_redisplay_p
= !trace_redisplay_p
;
18177 arg
= Fprefix_numeric_value (arg
);
18178 trace_redisplay_p
= XINT (arg
) > 0;
18185 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
18186 doc
: /* Like `format', but print result to stderr.
18187 usage: (trace-to-stderr STRING &rest OBJECTS) */)
18188 (ptrdiff_t nargs
, Lisp_Object
*args
)
18190 Lisp_Object s
= Fformat (nargs
, args
);
18191 fprintf (stderr
, "%s", SDATA (s
));
18195 #endif /* GLYPH_DEBUG */
18199 /***********************************************************************
18200 Building Desired Matrix Rows
18201 ***********************************************************************/
18203 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
18204 Used for non-window-redisplay windows, and for windows w/o left fringe. */
18206 static struct glyph_row
*
18207 get_overlay_arrow_glyph_row (struct window
*w
, Lisp_Object overlay_arrow_string
)
18209 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18210 struct buffer
*buffer
= XBUFFER (w
->buffer
);
18211 struct buffer
*old
= current_buffer
;
18212 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
18213 int arrow_len
= SCHARS (overlay_arrow_string
);
18214 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
18215 const unsigned char *p
;
18218 int n_glyphs_before
;
18220 set_buffer_temp (buffer
);
18221 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
18222 it
.glyph_row
->used
[TEXT_AREA
] = 0;
18223 SET_TEXT_POS (it
.position
, 0, 0);
18225 multibyte_p
= !NILP (BVAR (buffer
, enable_multibyte_characters
));
18227 while (p
< arrow_end
)
18229 Lisp_Object face
, ilisp
;
18231 /* Get the next character. */
18233 it
.c
= it
.char_to_display
= string_char_and_length (p
, &it
.len
);
18236 it
.c
= it
.char_to_display
= *p
, it
.len
= 1;
18237 if (! ASCII_CHAR_P (it
.c
))
18238 it
.char_to_display
= BYTE8_TO_CHAR (it
.c
);
18242 /* Get its face. */
18243 ilisp
= make_number (p
- arrow_string
);
18244 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
18245 it
.face_id
= compute_char_face (f
, it
.char_to_display
, face
);
18247 /* Compute its width, get its glyphs. */
18248 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
18249 SET_TEXT_POS (it
.position
, -1, -1);
18250 PRODUCE_GLYPHS (&it
);
18252 /* If this character doesn't fit any more in the line, we have
18253 to remove some glyphs. */
18254 if (it
.current_x
> it
.last_visible_x
)
18256 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
18261 set_buffer_temp (old
);
18262 return it
.glyph_row
;
18266 /* Insert truncation glyphs at the start of IT->glyph_row. Which
18267 glyphs to insert is determined by produce_special_glyphs. */
18270 insert_left_trunc_glyphs (struct it
*it
)
18272 struct it truncate_it
;
18273 struct glyph
*from
, *end
, *to
, *toend
;
18275 eassert (!FRAME_WINDOW_P (it
->f
)
18276 || (!it
->glyph_row
->reversed_p
18277 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0)
18278 || (it
->glyph_row
->reversed_p
18279 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0));
18281 /* Get the truncation glyphs. */
18283 truncate_it
.current_x
= 0;
18284 truncate_it
.face_id
= DEFAULT_FACE_ID
;
18285 truncate_it
.glyph_row
= &scratch_glyph_row
;
18286 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
18287 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
18288 truncate_it
.object
= make_number (0);
18289 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
18291 /* Overwrite glyphs from IT with truncation glyphs. */
18292 if (!it
->glyph_row
->reversed_p
)
18294 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
18296 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18297 end
= from
+ tused
;
18298 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18299 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
18300 if (FRAME_WINDOW_P (it
->f
))
18302 /* On GUI frames, when variable-size fonts are displayed,
18303 the truncation glyphs may need more pixels than the row's
18304 glyphs they overwrite. We overwrite more glyphs to free
18305 enough screen real estate, and enlarge the stretch glyph
18306 on the right (see display_line), if there is one, to
18307 preserve the screen position of the truncation glyphs on
18310 struct glyph
*g
= to
;
18313 /* The first glyph could be partially visible, in which case
18314 it->glyph_row->x will be negative. But we want the left
18315 truncation glyphs to be aligned at the left margin of the
18316 window, so we override the x coordinate at which the row
18318 it
->glyph_row
->x
= 0;
18319 while (g
< toend
&& w
< it
->truncation_pixel_width
)
18321 w
+= g
->pixel_width
;
18324 if (g
- to
- tused
> 0)
18326 memmove (to
+ tused
, g
, (toend
- g
) * sizeof(*g
));
18327 it
->glyph_row
->used
[TEXT_AREA
] -= g
- to
- tused
;
18329 used
= it
->glyph_row
->used
[TEXT_AREA
];
18330 if (it
->glyph_row
->truncated_on_right_p
18331 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0
18332 && it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].type
18335 int extra
= w
- it
->truncation_pixel_width
;
18337 it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].pixel_width
+= extra
;
18344 /* There may be padding glyphs left over. Overwrite them too. */
18345 if (!FRAME_WINDOW_P (it
->f
))
18347 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
18349 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18356 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
18360 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
18362 /* In R2L rows, overwrite the last (rightmost) glyphs, and do
18363 that back to front. */
18364 end
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18365 from
= end
+ truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18366 toend
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18367 to
= toend
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18368 if (FRAME_WINDOW_P (it
->f
))
18371 struct glyph
*g
= to
;
18373 while (g
>= toend
&& w
< it
->truncation_pixel_width
)
18375 w
+= g
->pixel_width
;
18378 if (to
- g
- tused
> 0)
18380 if (it
->glyph_row
->truncated_on_right_p
18381 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0
18382 && it
->glyph_row
->glyphs
[TEXT_AREA
][1].type
== STRETCH_GLYPH
)
18384 int extra
= w
- it
->truncation_pixel_width
;
18386 it
->glyph_row
->glyphs
[TEXT_AREA
][1].pixel_width
+= extra
;
18390 while (from
>= end
&& to
>= toend
)
18392 if (!FRAME_WINDOW_P (it
->f
))
18394 while (to
>= toend
&& CHAR_GLYPH_PADDING_P (*to
))
18397 truncate_it
.glyph_row
->glyphs
[TEXT_AREA
]
18398 + truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18399 while (from
>= end
&& to
>= toend
)
18405 /* Need to free some room before prepending additional
18407 int move_by
= from
- end
+ 1;
18408 struct glyph
*g0
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18409 struct glyph
*g
= g0
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18411 for ( ; g
>= g0
; g
--)
18413 while (from
>= end
)
18415 it
->glyph_row
->used
[TEXT_AREA
] += move_by
;
18420 /* Compute the hash code for ROW. */
18422 row_hash (struct glyph_row
*row
)
18425 unsigned hashval
= 0;
18427 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18428 for (k
= 0; k
< row
->used
[area
]; ++k
)
18429 hashval
= ((((hashval
<< 4) + (hashval
>> 24)) & 0x0fffffff)
18430 + row
->glyphs
[area
][k
].u
.val
18431 + row
->glyphs
[area
][k
].face_id
18432 + row
->glyphs
[area
][k
].padding_p
18433 + (row
->glyphs
[area
][k
].type
<< 2));
18438 /* Compute the pixel height and width of IT->glyph_row.
18440 Most of the time, ascent and height of a display line will be equal
18441 to the max_ascent and max_height values of the display iterator
18442 structure. This is not the case if
18444 1. We hit ZV without displaying anything. In this case, max_ascent
18445 and max_height will be zero.
18447 2. We have some glyphs that don't contribute to the line height.
18448 (The glyph row flag contributes_to_line_height_p is for future
18449 pixmap extensions).
18451 The first case is easily covered by using default values because in
18452 these cases, the line height does not really matter, except that it
18453 must not be zero. */
18456 compute_line_metrics (struct it
*it
)
18458 struct glyph_row
*row
= it
->glyph_row
;
18460 if (FRAME_WINDOW_P (it
->f
))
18462 int i
, min_y
, max_y
;
18464 /* The line may consist of one space only, that was added to
18465 place the cursor on it. If so, the row's height hasn't been
18467 if (row
->height
== 0)
18469 if (it
->max_ascent
+ it
->max_descent
== 0)
18470 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
18471 row
->ascent
= it
->max_ascent
;
18472 row
->height
= it
->max_ascent
+ it
->max_descent
;
18473 row
->phys_ascent
= it
->max_phys_ascent
;
18474 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18475 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18478 /* Compute the width of this line. */
18479 row
->pixel_width
= row
->x
;
18480 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
18481 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
18483 eassert (row
->pixel_width
>= 0);
18484 eassert (row
->ascent
>= 0 && row
->height
> 0);
18486 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
18487 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
18489 /* If first line's physical ascent is larger than its logical
18490 ascent, use the physical ascent, and make the row taller.
18491 This makes accented characters fully visible. */
18492 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
18493 && row
->phys_ascent
> row
->ascent
)
18495 row
->height
+= row
->phys_ascent
- row
->ascent
;
18496 row
->ascent
= row
->phys_ascent
;
18499 /* Compute how much of the line is visible. */
18500 row
->visible_height
= row
->height
;
18502 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
18503 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
18505 if (row
->y
< min_y
)
18506 row
->visible_height
-= min_y
- row
->y
;
18507 if (row
->y
+ row
->height
> max_y
)
18508 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
18512 row
->pixel_width
= row
->used
[TEXT_AREA
];
18513 if (row
->continued_p
)
18514 row
->pixel_width
-= it
->continuation_pixel_width
;
18515 else if (row
->truncated_on_right_p
)
18516 row
->pixel_width
-= it
->truncation_pixel_width
;
18517 row
->ascent
= row
->phys_ascent
= 0;
18518 row
->height
= row
->phys_height
= row
->visible_height
= 1;
18519 row
->extra_line_spacing
= 0;
18522 /* Compute a hash code for this row. */
18523 row
->hash
= row_hash (row
);
18525 it
->max_ascent
= it
->max_descent
= 0;
18526 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
18530 /* Append one space to the glyph row of iterator IT if doing a
18531 window-based redisplay. The space has the same face as
18532 IT->face_id. Value is non-zero if a space was added.
18534 This function is called to make sure that there is always one glyph
18535 at the end of a glyph row that the cursor can be set on under
18536 window-systems. (If there weren't such a glyph we would not know
18537 how wide and tall a box cursor should be displayed).
18539 At the same time this space let's a nicely handle clearing to the
18540 end of the line if the row ends in italic text. */
18543 append_space_for_newline (struct it
*it
, int default_face_p
)
18545 if (FRAME_WINDOW_P (it
->f
))
18547 int n
= it
->glyph_row
->used
[TEXT_AREA
];
18549 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
18550 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
18552 /* Save some values that must not be changed.
18553 Must save IT->c and IT->len because otherwise
18554 ITERATOR_AT_END_P wouldn't work anymore after
18555 append_space_for_newline has been called. */
18556 enum display_element_type saved_what
= it
->what
;
18557 int saved_c
= it
->c
, saved_len
= it
->len
;
18558 int saved_char_to_display
= it
->char_to_display
;
18559 int saved_x
= it
->current_x
;
18560 int saved_face_id
= it
->face_id
;
18561 struct text_pos saved_pos
;
18562 Lisp_Object saved_object
;
18565 saved_object
= it
->object
;
18566 saved_pos
= it
->position
;
18568 it
->what
= IT_CHARACTER
;
18569 memset (&it
->position
, 0, sizeof it
->position
);
18570 it
->object
= make_number (0);
18571 it
->c
= it
->char_to_display
= ' ';
18574 /* If the default face was remapped, be sure to use the
18575 remapped face for the appended newline. */
18576 if (default_face_p
)
18577 it
->face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
18578 else if (it
->face_before_selective_p
)
18579 it
->face_id
= it
->saved_face_id
;
18580 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18581 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
18583 PRODUCE_GLYPHS (it
);
18585 it
->override_ascent
= -1;
18586 it
->constrain_row_ascent_descent_p
= 0;
18587 it
->current_x
= saved_x
;
18588 it
->object
= saved_object
;
18589 it
->position
= saved_pos
;
18590 it
->what
= saved_what
;
18591 it
->face_id
= saved_face_id
;
18592 it
->len
= saved_len
;
18594 it
->char_to_display
= saved_char_to_display
;
18603 /* Extend the face of the last glyph in the text area of IT->glyph_row
18604 to the end of the display line. Called from display_line. If the
18605 glyph row is empty, add a space glyph to it so that we know the
18606 face to draw. Set the glyph row flag fill_line_p. If the glyph
18607 row is R2L, prepend a stretch glyph to cover the empty space to the
18608 left of the leftmost glyph. */
18611 extend_face_to_end_of_line (struct it
*it
)
18613 struct face
*face
, *default_face
;
18614 struct frame
*f
= it
->f
;
18616 /* If line is already filled, do nothing. Non window-system frames
18617 get a grace of one more ``pixel'' because their characters are
18618 1-``pixel'' wide, so they hit the equality too early. This grace
18619 is needed only for R2L rows that are not continued, to produce
18620 one extra blank where we could display the cursor. */
18621 if (it
->current_x
>= it
->last_visible_x
18622 + (!FRAME_WINDOW_P (f
)
18623 && it
->glyph_row
->reversed_p
18624 && !it
->glyph_row
->continued_p
))
18627 /* The default face, possibly remapped. */
18628 default_face
= FACE_FROM_ID (f
, lookup_basic_face (f
, DEFAULT_FACE_ID
));
18630 /* Face extension extends the background and box of IT->face_id
18631 to the end of the line. If the background equals the background
18632 of the frame, we don't have to do anything. */
18633 if (it
->face_before_selective_p
)
18634 face
= FACE_FROM_ID (f
, it
->saved_face_id
);
18636 face
= FACE_FROM_ID (f
, it
->face_id
);
18638 if (FRAME_WINDOW_P (f
)
18639 && it
->glyph_row
->displays_text_p
18640 && face
->box
== FACE_NO_BOX
18641 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
18643 && !it
->glyph_row
->reversed_p
)
18646 /* Set the glyph row flag indicating that the face of the last glyph
18647 in the text area has to be drawn to the end of the text area. */
18648 it
->glyph_row
->fill_line_p
= 1;
18650 /* If current character of IT is not ASCII, make sure we have the
18651 ASCII face. This will be automatically undone the next time
18652 get_next_display_element returns a multibyte character. Note
18653 that the character will always be single byte in unibyte
18655 if (!ASCII_CHAR_P (it
->c
))
18657 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
18660 if (FRAME_WINDOW_P (f
))
18662 /* If the row is empty, add a space with the current face of IT,
18663 so that we know which face to draw. */
18664 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
18666 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
18667 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= face
->id
;
18668 it
->glyph_row
->used
[TEXT_AREA
] = 1;
18670 #ifdef HAVE_WINDOW_SYSTEM
18671 if (it
->glyph_row
->reversed_p
)
18673 /* Prepend a stretch glyph to the row, such that the
18674 rightmost glyph will be drawn flushed all the way to the
18675 right margin of the window. The stretch glyph that will
18676 occupy the empty space, if any, to the left of the
18678 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (f
);
18679 struct glyph
*row_start
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18680 struct glyph
*row_end
= row_start
+ it
->glyph_row
->used
[TEXT_AREA
];
18682 int row_width
, stretch_ascent
, stretch_width
;
18683 struct text_pos saved_pos
;
18684 int saved_face_id
, saved_avoid_cursor
;
18686 for (row_width
= 0, g
= row_start
; g
< row_end
; g
++)
18687 row_width
+= g
->pixel_width
;
18688 stretch_width
= window_box_width (it
->w
, TEXT_AREA
) - row_width
;
18689 if (stretch_width
> 0)
18692 (((it
->ascent
+ it
->descent
)
18693 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
18694 saved_pos
= it
->position
;
18695 memset (&it
->position
, 0, sizeof it
->position
);
18696 saved_avoid_cursor
= it
->avoid_cursor_p
;
18697 it
->avoid_cursor_p
= 1;
18698 saved_face_id
= it
->face_id
;
18699 /* The last row's stretch glyph should get the default
18700 face, to avoid painting the rest of the window with
18701 the region face, if the region ends at ZV. */
18702 if (it
->glyph_row
->ends_at_zv_p
)
18703 it
->face_id
= default_face
->id
;
18705 it
->face_id
= face
->id
;
18706 append_stretch_glyph (it
, make_number (0), stretch_width
,
18707 it
->ascent
+ it
->descent
, stretch_ascent
);
18708 it
->position
= saved_pos
;
18709 it
->avoid_cursor_p
= saved_avoid_cursor
;
18710 it
->face_id
= saved_face_id
;
18713 #endif /* HAVE_WINDOW_SYSTEM */
18717 /* Save some values that must not be changed. */
18718 int saved_x
= it
->current_x
;
18719 struct text_pos saved_pos
;
18720 Lisp_Object saved_object
;
18721 enum display_element_type saved_what
= it
->what
;
18722 int saved_face_id
= it
->face_id
;
18724 saved_object
= it
->object
;
18725 saved_pos
= it
->position
;
18727 it
->what
= IT_CHARACTER
;
18728 memset (&it
->position
, 0, sizeof it
->position
);
18729 it
->object
= make_number (0);
18730 it
->c
= it
->char_to_display
= ' ';
18732 /* The last row's blank glyphs should get the default face, to
18733 avoid painting the rest of the window with the region face,
18734 if the region ends at ZV. */
18735 if (it
->glyph_row
->ends_at_zv_p
)
18736 it
->face_id
= default_face
->id
;
18738 it
->face_id
= face
->id
;
18740 PRODUCE_GLYPHS (it
);
18742 while (it
->current_x
<= it
->last_visible_x
)
18743 PRODUCE_GLYPHS (it
);
18745 /* Don't count these blanks really. It would let us insert a left
18746 truncation glyph below and make us set the cursor on them, maybe. */
18747 it
->current_x
= saved_x
;
18748 it
->object
= saved_object
;
18749 it
->position
= saved_pos
;
18750 it
->what
= saved_what
;
18751 it
->face_id
= saved_face_id
;
18756 /* Value is non-zero if text starting at CHARPOS in current_buffer is
18757 trailing whitespace. */
18760 trailing_whitespace_p (ptrdiff_t charpos
)
18762 ptrdiff_t bytepos
= CHAR_TO_BYTE (charpos
);
18765 while (bytepos
< ZV_BYTE
18766 && (c
= FETCH_CHAR (bytepos
),
18767 c
== ' ' || c
== '\t'))
18770 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
18772 if (bytepos
!= PT_BYTE
)
18779 /* Highlight trailing whitespace, if any, in ROW. */
18782 highlight_trailing_whitespace (struct frame
*f
, struct glyph_row
*row
)
18784 int used
= row
->used
[TEXT_AREA
];
18788 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
18789 struct glyph
*glyph
= start
+ used
- 1;
18791 if (row
->reversed_p
)
18793 /* Right-to-left rows need to be processed in the opposite
18794 direction, so swap the edge pointers. */
18796 start
= row
->glyphs
[TEXT_AREA
] + used
- 1;
18799 /* Skip over glyphs inserted to display the cursor at the
18800 end of a line, for extending the face of the last glyph
18801 to the end of the line on terminals, and for truncation
18802 and continuation glyphs. */
18803 if (!row
->reversed_p
)
18805 while (glyph
>= start
18806 && glyph
->type
== CHAR_GLYPH
18807 && INTEGERP (glyph
->object
))
18812 while (glyph
<= start
18813 && glyph
->type
== CHAR_GLYPH
18814 && INTEGERP (glyph
->object
))
18818 /* If last glyph is a space or stretch, and it's trailing
18819 whitespace, set the face of all trailing whitespace glyphs in
18820 IT->glyph_row to `trailing-whitespace'. */
18821 if ((row
->reversed_p
? glyph
<= start
: glyph
>= start
)
18822 && BUFFERP (glyph
->object
)
18823 && (glyph
->type
== STRETCH_GLYPH
18824 || (glyph
->type
== CHAR_GLYPH
18825 && glyph
->u
.ch
== ' '))
18826 && trailing_whitespace_p (glyph
->charpos
))
18828 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
18832 if (!row
->reversed_p
)
18834 while (glyph
>= start
18835 && BUFFERP (glyph
->object
)
18836 && (glyph
->type
== STRETCH_GLYPH
18837 || (glyph
->type
== CHAR_GLYPH
18838 && glyph
->u
.ch
== ' ')))
18839 (glyph
--)->face_id
= face_id
;
18843 while (glyph
<= start
18844 && BUFFERP (glyph
->object
)
18845 && (glyph
->type
== STRETCH_GLYPH
18846 || (glyph
->type
== CHAR_GLYPH
18847 && glyph
->u
.ch
== ' ')))
18848 (glyph
++)->face_id
= face_id
;
18855 /* Value is non-zero if glyph row ROW should be
18856 used to hold the cursor. */
18859 cursor_row_p (struct glyph_row
*row
)
18863 if (PT
== CHARPOS (row
->end
.pos
)
18864 || PT
== MATRIX_ROW_END_CHARPOS (row
))
18866 /* Suppose the row ends on a string.
18867 Unless the row is continued, that means it ends on a newline
18868 in the string. If it's anything other than a display string
18869 (e.g., a before-string from an overlay), we don't want the
18870 cursor there. (This heuristic seems to give the optimal
18871 behavior for the various types of multi-line strings.)
18872 One exception: if the string has `cursor' property on one of
18873 its characters, we _do_ want the cursor there. */
18874 if (CHARPOS (row
->end
.string_pos
) >= 0)
18876 if (row
->continued_p
)
18880 /* Check for `display' property. */
18881 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
18882 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
18883 struct glyph
*glyph
;
18886 for (glyph
= end
; glyph
>= beg
; --glyph
)
18887 if (STRINGP (glyph
->object
))
18890 = Fget_char_property (make_number (PT
),
18894 && display_prop_string_p (prop
, glyph
->object
));
18895 /* If there's a `cursor' property on one of the
18896 string's characters, this row is a cursor row,
18897 even though this is not a display string. */
18900 Lisp_Object s
= glyph
->object
;
18902 for ( ; glyph
>= beg
&& EQ (glyph
->object
, s
); --glyph
)
18904 ptrdiff_t gpos
= glyph
->charpos
;
18906 if (!NILP (Fget_char_property (make_number (gpos
),
18918 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
18920 /* If the row ends in middle of a real character,
18921 and the line is continued, we want the cursor here.
18922 That's because CHARPOS (ROW->end.pos) would equal
18923 PT if PT is before the character. */
18924 if (!row
->ends_in_ellipsis_p
)
18925 result
= row
->continued_p
;
18927 /* If the row ends in an ellipsis, then
18928 CHARPOS (ROW->end.pos) will equal point after the
18929 invisible text. We want that position to be displayed
18930 after the ellipsis. */
18933 /* If the row ends at ZV, display the cursor at the end of that
18934 row instead of at the start of the row below. */
18935 else if (row
->ends_at_zv_p
)
18946 /* Push the property PROP so that it will be rendered at the current
18947 position in IT. Return 1 if PROP was successfully pushed, 0
18948 otherwise. Called from handle_line_prefix to handle the
18949 `line-prefix' and `wrap-prefix' properties. */
18952 push_prefix_prop (struct it
*it
, Lisp_Object prop
)
18954 struct text_pos pos
=
18955 STRINGP (it
->string
) ? it
->current
.string_pos
: it
->current
.pos
;
18957 eassert (it
->method
== GET_FROM_BUFFER
18958 || it
->method
== GET_FROM_DISPLAY_VECTOR
18959 || it
->method
== GET_FROM_STRING
);
18961 /* We need to save the current buffer/string position, so it will be
18962 restored by pop_it, because iterate_out_of_display_property
18963 depends on that being set correctly, but some situations leave
18964 it->position not yet set when this function is called. */
18965 push_it (it
, &pos
);
18967 if (STRINGP (prop
))
18969 if (SCHARS (prop
) == 0)
18976 it
->string_from_prefix_prop_p
= 1;
18977 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
18978 it
->current
.overlay_string_index
= -1;
18979 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
18980 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
18981 it
->method
= GET_FROM_STRING
;
18982 it
->stop_charpos
= 0;
18984 it
->base_level_stop
= 0;
18986 /* Force paragraph direction to be that of the parent
18988 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
18989 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
18991 it
->paragraph_embedding
= L2R
;
18993 /* Set up the bidi iterator for this display string. */
18996 it
->bidi_it
.string
.lstring
= it
->string
;
18997 it
->bidi_it
.string
.s
= NULL
;
18998 it
->bidi_it
.string
.schars
= it
->end_charpos
;
18999 it
->bidi_it
.string
.bufpos
= IT_CHARPOS (*it
);
19000 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
19001 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
19002 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
19005 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
19007 it
->method
= GET_FROM_STRETCH
;
19010 #ifdef HAVE_WINDOW_SYSTEM
19011 else if (IMAGEP (prop
))
19013 it
->what
= IT_IMAGE
;
19014 it
->image_id
= lookup_image (it
->f
, prop
);
19015 it
->method
= GET_FROM_IMAGE
;
19017 #endif /* HAVE_WINDOW_SYSTEM */
19020 pop_it (it
); /* bogus display property, give up */
19027 /* Return the character-property PROP at the current position in IT. */
19030 get_it_property (struct it
*it
, Lisp_Object prop
)
19032 Lisp_Object position
;
19034 if (STRINGP (it
->object
))
19035 position
= make_number (IT_STRING_CHARPOS (*it
));
19036 else if (BUFFERP (it
->object
))
19037 position
= make_number (IT_CHARPOS (*it
));
19041 return Fget_char_property (position
, prop
, it
->object
);
19044 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
19047 handle_line_prefix (struct it
*it
)
19049 Lisp_Object prefix
;
19051 if (it
->continuation_lines_width
> 0)
19053 prefix
= get_it_property (it
, Qwrap_prefix
);
19055 prefix
= Vwrap_prefix
;
19059 prefix
= get_it_property (it
, Qline_prefix
);
19061 prefix
= Vline_prefix
;
19063 if (! NILP (prefix
) && push_prefix_prop (it
, prefix
))
19065 /* If the prefix is wider than the window, and we try to wrap
19066 it, it would acquire its own wrap prefix, and so on till the
19067 iterator stack overflows. So, don't wrap the prefix. */
19068 it
->line_wrap
= TRUNCATE
;
19069 it
->avoid_cursor_p
= 1;
19075 /* Remove N glyphs at the start of a reversed IT->glyph_row. Called
19076 only for R2L lines from display_line and display_string, when they
19077 decide that too many glyphs were produced by PRODUCE_GLYPHS, and
19078 the line/string needs to be continued on the next glyph row. */
19080 unproduce_glyphs (struct it
*it
, int n
)
19082 struct glyph
*glyph
, *end
;
19084 eassert (it
->glyph_row
);
19085 eassert (it
->glyph_row
->reversed_p
);
19086 eassert (it
->area
== TEXT_AREA
);
19087 eassert (n
<= it
->glyph_row
->used
[TEXT_AREA
]);
19089 if (n
> it
->glyph_row
->used
[TEXT_AREA
])
19090 n
= it
->glyph_row
->used
[TEXT_AREA
];
19091 glyph
= it
->glyph_row
->glyphs
[TEXT_AREA
] + n
;
19092 end
= it
->glyph_row
->glyphs
[TEXT_AREA
] + it
->glyph_row
->used
[TEXT_AREA
];
19093 for ( ; glyph
< end
; glyph
++)
19094 glyph
[-n
] = *glyph
;
19097 /* Find the positions in a bidi-reordered ROW to serve as ROW->minpos
19098 and ROW->maxpos. */
19100 find_row_edges (struct it
*it
, struct glyph_row
*row
,
19101 ptrdiff_t min_pos
, ptrdiff_t min_bpos
,
19102 ptrdiff_t max_pos
, ptrdiff_t max_bpos
)
19104 /* FIXME: Revisit this when glyph ``spilling'' in continuation
19105 lines' rows is implemented for bidi-reordered rows. */
19107 /* ROW->minpos is the value of min_pos, the minimal buffer position
19108 we have in ROW, or ROW->start.pos if that is smaller. */
19109 if (min_pos
<= ZV
&& min_pos
< row
->start
.pos
.charpos
)
19110 SET_TEXT_POS (row
->minpos
, min_pos
, min_bpos
);
19112 /* We didn't find buffer positions smaller than ROW->start, or
19113 didn't find _any_ valid buffer positions in any of the glyphs,
19114 so we must trust the iterator's computed positions. */
19115 row
->minpos
= row
->start
.pos
;
19118 max_pos
= CHARPOS (it
->current
.pos
);
19119 max_bpos
= BYTEPOS (it
->current
.pos
);
19122 /* Here are the various use-cases for ending the row, and the
19123 corresponding values for ROW->maxpos:
19125 Line ends in a newline from buffer eol_pos + 1
19126 Line is continued from buffer max_pos + 1
19127 Line is truncated on right it->current.pos
19128 Line ends in a newline from string max_pos + 1(*)
19129 (*) + 1 only when line ends in a forward scan
19130 Line is continued from string max_pos
19131 Line is continued from display vector max_pos
19132 Line is entirely from a string min_pos == max_pos
19133 Line is entirely from a display vector min_pos == max_pos
19134 Line that ends at ZV ZV
19136 If you discover other use-cases, please add them here as
19138 if (row
->ends_at_zv_p
)
19139 row
->maxpos
= it
->current
.pos
;
19140 else if (row
->used
[TEXT_AREA
])
19142 int seen_this_string
= 0;
19143 struct glyph_row
*r1
= row
- 1;
19145 /* Did we see the same display string on the previous row? */
19146 if (STRINGP (it
->object
)
19147 /* this is not the first row */
19148 && row
> it
->w
->desired_matrix
->rows
19149 /* previous row is not the header line */
19150 && !r1
->mode_line_p
19151 /* previous row also ends in a newline from a string */
19152 && r1
->ends_in_newline_from_string_p
)
19154 struct glyph
*start
, *end
;
19156 /* Search for the last glyph of the previous row that came
19157 from buffer or string. Depending on whether the row is
19158 L2R or R2L, we need to process it front to back or the
19159 other way round. */
19160 if (!r1
->reversed_p
)
19162 start
= r1
->glyphs
[TEXT_AREA
];
19163 end
= start
+ r1
->used
[TEXT_AREA
];
19164 /* Glyphs inserted by redisplay have an integer (zero)
19165 as their object. */
19167 && INTEGERP ((end
- 1)->object
)
19168 && (end
- 1)->charpos
<= 0)
19172 if (EQ ((end
- 1)->object
, it
->object
))
19173 seen_this_string
= 1;
19176 /* If all the glyphs of the previous row were inserted
19177 by redisplay, it means the previous row was
19178 produced from a single newline, which is only
19179 possible if that newline came from the same string
19180 as the one which produced this ROW. */
19181 seen_this_string
= 1;
19185 end
= r1
->glyphs
[TEXT_AREA
] - 1;
19186 start
= end
+ r1
->used
[TEXT_AREA
];
19188 && INTEGERP ((end
+ 1)->object
)
19189 && (end
+ 1)->charpos
<= 0)
19193 if (EQ ((end
+ 1)->object
, it
->object
))
19194 seen_this_string
= 1;
19197 seen_this_string
= 1;
19200 /* Take note of each display string that covers a newline only
19201 once, the first time we see it. This is for when a display
19202 string includes more than one newline in it. */
19203 if (row
->ends_in_newline_from_string_p
&& !seen_this_string
)
19205 /* If we were scanning the buffer forward when we displayed
19206 the string, we want to account for at least one buffer
19207 position that belongs to this row (position covered by
19208 the display string), so that cursor positioning will
19209 consider this row as a candidate when point is at the end
19210 of the visual line represented by this row. This is not
19211 required when scanning back, because max_pos will already
19212 have a much larger value. */
19213 if (CHARPOS (row
->end
.pos
) > max_pos
)
19214 INC_BOTH (max_pos
, max_bpos
);
19215 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19217 else if (CHARPOS (it
->eol_pos
) > 0)
19218 SET_TEXT_POS (row
->maxpos
,
19219 CHARPOS (it
->eol_pos
) + 1, BYTEPOS (it
->eol_pos
) + 1);
19220 else if (row
->continued_p
)
19222 /* If max_pos is different from IT's current position, it
19223 means IT->method does not belong to the display element
19224 at max_pos. However, it also means that the display
19225 element at max_pos was displayed in its entirety on this
19226 line, which is equivalent to saying that the next line
19227 starts at the next buffer position. */
19228 if (IT_CHARPOS (*it
) == max_pos
&& it
->method
!= GET_FROM_BUFFER
)
19229 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19232 INC_BOTH (max_pos
, max_bpos
);
19233 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19236 else if (row
->truncated_on_right_p
)
19237 /* display_line already called reseat_at_next_visible_line_start,
19238 which puts the iterator at the beginning of the next line, in
19239 the logical order. */
19240 row
->maxpos
= it
->current
.pos
;
19241 else if (max_pos
== min_pos
&& it
->method
!= GET_FROM_BUFFER
)
19242 /* A line that is entirely from a string/image/stretch... */
19243 row
->maxpos
= row
->minpos
;
19248 row
->maxpos
= it
->current
.pos
;
19251 /* Construct the glyph row IT->glyph_row in the desired matrix of
19252 IT->w from text at the current position of IT. See dispextern.h
19253 for an overview of struct it. Value is non-zero if
19254 IT->glyph_row displays text, as opposed to a line displaying ZV
19258 display_line (struct it
*it
)
19260 struct glyph_row
*row
= it
->glyph_row
;
19261 Lisp_Object overlay_arrow_string
;
19263 void *wrap_data
= NULL
;
19264 int may_wrap
= 0, wrap_x
IF_LINT (= 0);
19265 int wrap_row_used
= -1;
19266 int wrap_row_ascent
IF_LINT (= 0), wrap_row_height
IF_LINT (= 0);
19267 int wrap_row_phys_ascent
IF_LINT (= 0), wrap_row_phys_height
IF_LINT (= 0);
19268 int wrap_row_extra_line_spacing
IF_LINT (= 0);
19269 ptrdiff_t wrap_row_min_pos
IF_LINT (= 0), wrap_row_min_bpos
IF_LINT (= 0);
19270 ptrdiff_t wrap_row_max_pos
IF_LINT (= 0), wrap_row_max_bpos
IF_LINT (= 0);
19272 ptrdiff_t min_pos
= ZV
+ 1, max_pos
= 0;
19273 ptrdiff_t min_bpos
IF_LINT (= 0), max_bpos
IF_LINT (= 0);
19275 /* We always start displaying at hpos zero even if hscrolled. */
19276 eassert (it
->hpos
== 0 && it
->current_x
== 0);
19278 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
19279 >= it
->w
->desired_matrix
->nrows
)
19281 it
->w
->nrows_scale_factor
++;
19282 fonts_changed_p
= 1;
19286 /* Is IT->w showing the region? */
19287 wset_region_showing (it
->w
, it
->region_beg_charpos
> 0 ? Qt
: Qnil
);
19289 /* Clear the result glyph row and enable it. */
19290 prepare_desired_row (row
);
19292 row
->y
= it
->current_y
;
19293 row
->start
= it
->start
;
19294 row
->continuation_lines_width
= it
->continuation_lines_width
;
19295 row
->displays_text_p
= 1;
19296 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
19297 it
->starts_in_middle_of_char_p
= 0;
19299 /* Arrange the overlays nicely for our purposes. Usually, we call
19300 display_line on only one line at a time, in which case this
19301 can't really hurt too much, or we call it on lines which appear
19302 one after another in the buffer, in which case all calls to
19303 recenter_overlay_lists but the first will be pretty cheap. */
19304 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
19306 /* Move over display elements that are not visible because we are
19307 hscrolled. This may stop at an x-position < IT->first_visible_x
19308 if the first glyph is partially visible or if we hit a line end. */
19309 if (it
->current_x
< it
->first_visible_x
)
19311 enum move_it_result move_result
;
19313 this_line_min_pos
= row
->start
.pos
;
19314 move_result
= move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
19315 MOVE_TO_POS
| MOVE_TO_X
);
19316 /* If we are under a large hscroll, move_it_in_display_line_to
19317 could hit the end of the line without reaching
19318 it->first_visible_x. Pretend that we did reach it. This is
19319 especially important on a TTY, where we will call
19320 extend_face_to_end_of_line, which needs to know how many
19321 blank glyphs to produce. */
19322 if (it
->current_x
< it
->first_visible_x
19323 && (move_result
== MOVE_NEWLINE_OR_CR
19324 || move_result
== MOVE_POS_MATCH_OR_ZV
))
19325 it
->current_x
= it
->first_visible_x
;
19327 /* Record the smallest positions seen while we moved over
19328 display elements that are not visible. This is needed by
19329 redisplay_internal for optimizing the case where the cursor
19330 stays inside the same line. The rest of this function only
19331 considers positions that are actually displayed, so
19332 RECORD_MAX_MIN_POS will not otherwise record positions that
19333 are hscrolled to the left of the left edge of the window. */
19334 min_pos
= CHARPOS (this_line_min_pos
);
19335 min_bpos
= BYTEPOS (this_line_min_pos
);
19339 /* We only do this when not calling `move_it_in_display_line_to'
19340 above, because move_it_in_display_line_to calls
19341 handle_line_prefix itself. */
19342 handle_line_prefix (it
);
19345 /* Get the initial row height. This is either the height of the
19346 text hscrolled, if there is any, or zero. */
19347 row
->ascent
= it
->max_ascent
;
19348 row
->height
= it
->max_ascent
+ it
->max_descent
;
19349 row
->phys_ascent
= it
->max_phys_ascent
;
19350 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
19351 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
19353 /* Utility macro to record max and min buffer positions seen until now. */
19354 #define RECORD_MAX_MIN_POS(IT) \
19357 int composition_p = !STRINGP ((IT)->string) \
19358 && ((IT)->what == IT_COMPOSITION); \
19359 ptrdiff_t current_pos = \
19360 composition_p ? (IT)->cmp_it.charpos \
19361 : IT_CHARPOS (*(IT)); \
19362 ptrdiff_t current_bpos = \
19363 composition_p ? CHAR_TO_BYTE (current_pos) \
19364 : IT_BYTEPOS (*(IT)); \
19365 if (current_pos < min_pos) \
19367 min_pos = current_pos; \
19368 min_bpos = current_bpos; \
19370 if (IT_CHARPOS (*it) > max_pos) \
19372 max_pos = IT_CHARPOS (*it); \
19373 max_bpos = IT_BYTEPOS (*it); \
19378 /* Loop generating characters. The loop is left with IT on the next
19379 character to display. */
19382 int n_glyphs_before
, hpos_before
, x_before
;
19384 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
19386 /* Retrieve the next thing to display. Value is zero if end of
19388 if (!get_next_display_element (it
))
19390 /* Maybe add a space at the end of this line that is used to
19391 display the cursor there under X. Set the charpos of the
19392 first glyph of blank lines not corresponding to any text
19394 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19395 row
->exact_window_width_line_p
= 1;
19396 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
19397 || row
->used
[TEXT_AREA
] == 0)
19399 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
19400 row
->displays_text_p
= 0;
19402 if (!NILP (BVAR (XBUFFER (it
->w
->buffer
), indicate_empty_lines
))
19403 && (!MINI_WINDOW_P (it
->w
)
19404 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
19405 row
->indicate_empty_line_p
= 1;
19408 it
->continuation_lines_width
= 0;
19409 row
->ends_at_zv_p
= 1;
19410 /* A row that displays right-to-left text must always have
19411 its last face extended all the way to the end of line,
19412 even if this row ends in ZV, because we still write to
19413 the screen left to right. We also need to extend the
19414 last face if the default face is remapped to some
19415 different face, otherwise the functions that clear
19416 portions of the screen will clear with the default face's
19417 background color. */
19418 if (row
->reversed_p
19419 || lookup_basic_face (it
->f
, DEFAULT_FACE_ID
) != DEFAULT_FACE_ID
)
19420 extend_face_to_end_of_line (it
);
19424 /* Now, get the metrics of what we want to display. This also
19425 generates glyphs in `row' (which is IT->glyph_row). */
19426 n_glyphs_before
= row
->used
[TEXT_AREA
];
19429 /* Remember the line height so far in case the next element doesn't
19430 fit on the line. */
19431 if (it
->line_wrap
!= TRUNCATE
)
19433 ascent
= it
->max_ascent
;
19434 descent
= it
->max_descent
;
19435 phys_ascent
= it
->max_phys_ascent
;
19436 phys_descent
= it
->max_phys_descent
;
19438 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
19440 if (IT_DISPLAYING_WHITESPACE (it
))
19444 SAVE_IT (wrap_it
, *it
, wrap_data
);
19446 wrap_row_used
= row
->used
[TEXT_AREA
];
19447 wrap_row_ascent
= row
->ascent
;
19448 wrap_row_height
= row
->height
;
19449 wrap_row_phys_ascent
= row
->phys_ascent
;
19450 wrap_row_phys_height
= row
->phys_height
;
19451 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
19452 wrap_row_min_pos
= min_pos
;
19453 wrap_row_min_bpos
= min_bpos
;
19454 wrap_row_max_pos
= max_pos
;
19455 wrap_row_max_bpos
= max_bpos
;
19461 PRODUCE_GLYPHS (it
);
19463 /* If this display element was in marginal areas, continue with
19465 if (it
->area
!= TEXT_AREA
)
19467 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19468 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19469 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19470 row
->phys_height
= max (row
->phys_height
,
19471 it
->max_phys_ascent
+ it
->max_phys_descent
);
19472 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19473 it
->max_extra_line_spacing
);
19474 set_iterator_to_next (it
, 1);
19478 /* Does the display element fit on the line? If we truncate
19479 lines, we should draw past the right edge of the window. If
19480 we don't truncate, we want to stop so that we can display the
19481 continuation glyph before the right margin. If lines are
19482 continued, there are two possible strategies for characters
19483 resulting in more than 1 glyph (e.g. tabs): Display as many
19484 glyphs as possible in this line and leave the rest for the
19485 continuation line, or display the whole element in the next
19486 line. Original redisplay did the former, so we do it also. */
19487 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
19488 hpos_before
= it
->hpos
;
19491 if (/* Not a newline. */
19493 /* Glyphs produced fit entirely in the line. */
19494 && it
->current_x
< it
->last_visible_x
)
19496 it
->hpos
+= nglyphs
;
19497 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19498 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19499 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19500 row
->phys_height
= max (row
->phys_height
,
19501 it
->max_phys_ascent
+ it
->max_phys_descent
);
19502 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19503 it
->max_extra_line_spacing
);
19504 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
19505 row
->x
= x
- it
->first_visible_x
;
19506 /* Record the maximum and minimum buffer positions seen so
19507 far in glyphs that will be displayed by this row. */
19509 RECORD_MAX_MIN_POS (it
);
19514 struct glyph
*glyph
;
19516 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
19518 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
19519 new_x
= x
+ glyph
->pixel_width
;
19521 if (/* Lines are continued. */
19522 it
->line_wrap
!= TRUNCATE
19523 && (/* Glyph doesn't fit on the line. */
19524 new_x
> it
->last_visible_x
19525 /* Or it fits exactly on a window system frame. */
19526 || (new_x
== it
->last_visible_x
19527 && FRAME_WINDOW_P (it
->f
)
19528 && (row
->reversed_p
19529 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19530 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
19532 /* End of a continued line. */
19535 || (new_x
== it
->last_visible_x
19536 && FRAME_WINDOW_P (it
->f
)
19537 && (row
->reversed_p
19538 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19539 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
))))
19541 /* Current glyph is the only one on the line or
19542 fits exactly on the line. We must continue
19543 the line because we can't draw the cursor
19544 after the glyph. */
19545 row
->continued_p
= 1;
19546 it
->current_x
= new_x
;
19547 it
->continuation_lines_width
+= new_x
;
19549 if (i
== nglyphs
- 1)
19551 /* If line-wrap is on, check if a previous
19552 wrap point was found. */
19553 if (wrap_row_used
> 0
19554 /* Even if there is a previous wrap
19555 point, continue the line here as
19556 usual, if (i) the previous character
19557 was a space or tab AND (ii) the
19558 current character is not. */
19560 || IT_DISPLAYING_WHITESPACE (it
)))
19563 /* Record the maximum and minimum buffer
19564 positions seen so far in glyphs that will be
19565 displayed by this row. */
19567 RECORD_MAX_MIN_POS (it
);
19568 set_iterator_to_next (it
, 1);
19569 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19571 if (!get_next_display_element (it
))
19573 row
->exact_window_width_line_p
= 1;
19574 it
->continuation_lines_width
= 0;
19575 row
->continued_p
= 0;
19576 row
->ends_at_zv_p
= 1;
19578 else if (ITERATOR_AT_END_OF_LINE_P (it
))
19580 row
->continued_p
= 0;
19581 row
->exact_window_width_line_p
= 1;
19585 else if (it
->bidi_p
)
19586 RECORD_MAX_MIN_POS (it
);
19588 else if (CHAR_GLYPH_PADDING_P (*glyph
)
19589 && !FRAME_WINDOW_P (it
->f
))
19591 /* A padding glyph that doesn't fit on this line.
19592 This means the whole character doesn't fit
19594 if (row
->reversed_p
)
19595 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19596 - n_glyphs_before
);
19597 row
->used
[TEXT_AREA
] = n_glyphs_before
;
19599 /* Fill the rest of the row with continuation
19600 glyphs like in 20.x. */
19601 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
19602 < row
->glyphs
[1 + TEXT_AREA
])
19603 produce_special_glyphs (it
, IT_CONTINUATION
);
19605 row
->continued_p
= 1;
19606 it
->current_x
= x_before
;
19607 it
->continuation_lines_width
+= x_before
;
19609 /* Restore the height to what it was before the
19610 element not fitting on the line. */
19611 it
->max_ascent
= ascent
;
19612 it
->max_descent
= descent
;
19613 it
->max_phys_ascent
= phys_ascent
;
19614 it
->max_phys_descent
= phys_descent
;
19616 else if (wrap_row_used
> 0)
19619 if (row
->reversed_p
)
19620 unproduce_glyphs (it
,
19621 row
->used
[TEXT_AREA
] - wrap_row_used
);
19622 RESTORE_IT (it
, &wrap_it
, wrap_data
);
19623 it
->continuation_lines_width
+= wrap_x
;
19624 row
->used
[TEXT_AREA
] = wrap_row_used
;
19625 row
->ascent
= wrap_row_ascent
;
19626 row
->height
= wrap_row_height
;
19627 row
->phys_ascent
= wrap_row_phys_ascent
;
19628 row
->phys_height
= wrap_row_phys_height
;
19629 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
19630 min_pos
= wrap_row_min_pos
;
19631 min_bpos
= wrap_row_min_bpos
;
19632 max_pos
= wrap_row_max_pos
;
19633 max_bpos
= wrap_row_max_bpos
;
19634 row
->continued_p
= 1;
19635 row
->ends_at_zv_p
= 0;
19636 row
->exact_window_width_line_p
= 0;
19637 it
->continuation_lines_width
+= x
;
19639 /* Make sure that a non-default face is extended
19640 up to the right margin of the window. */
19641 extend_face_to_end_of_line (it
);
19643 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
19645 /* A TAB that extends past the right edge of the
19646 window. This produces a single glyph on
19647 window system frames. We leave the glyph in
19648 this row and let it fill the row, but don't
19649 consume the TAB. */
19650 if ((row
->reversed_p
19651 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19652 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19653 produce_special_glyphs (it
, IT_CONTINUATION
);
19654 it
->continuation_lines_width
+= it
->last_visible_x
;
19655 row
->ends_in_middle_of_char_p
= 1;
19656 row
->continued_p
= 1;
19657 glyph
->pixel_width
= it
->last_visible_x
- x
;
19658 it
->starts_in_middle_of_char_p
= 1;
19662 /* Something other than a TAB that draws past
19663 the right edge of the window. Restore
19664 positions to values before the element. */
19665 if (row
->reversed_p
)
19666 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19667 - (n_glyphs_before
+ i
));
19668 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
19670 /* Display continuation glyphs. */
19671 it
->current_x
= x_before
;
19672 it
->continuation_lines_width
+= x
;
19673 if (!FRAME_WINDOW_P (it
->f
)
19674 || (row
->reversed_p
19675 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19676 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19677 produce_special_glyphs (it
, IT_CONTINUATION
);
19678 row
->continued_p
= 1;
19680 extend_face_to_end_of_line (it
);
19682 if (nglyphs
> 1 && i
> 0)
19684 row
->ends_in_middle_of_char_p
= 1;
19685 it
->starts_in_middle_of_char_p
= 1;
19688 /* Restore the height to what it was before the
19689 element not fitting on the line. */
19690 it
->max_ascent
= ascent
;
19691 it
->max_descent
= descent
;
19692 it
->max_phys_ascent
= phys_ascent
;
19693 it
->max_phys_descent
= phys_descent
;
19698 else if (new_x
> it
->first_visible_x
)
19700 /* Increment number of glyphs actually displayed. */
19703 /* Record the maximum and minimum buffer positions
19704 seen so far in glyphs that will be displayed by
19707 RECORD_MAX_MIN_POS (it
);
19709 if (x
< it
->first_visible_x
)
19710 /* Glyph is partially visible, i.e. row starts at
19711 negative X position. */
19712 row
->x
= x
- it
->first_visible_x
;
19716 /* Glyph is completely off the left margin of the
19717 window. This should not happen because of the
19718 move_it_in_display_line at the start of this
19719 function, unless the text display area of the
19720 window is empty. */
19721 eassert (it
->first_visible_x
<= it
->last_visible_x
);
19724 /* Even if this display element produced no glyphs at all,
19725 we want to record its position. */
19726 if (it
->bidi_p
&& nglyphs
== 0)
19727 RECORD_MAX_MIN_POS (it
);
19729 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19730 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19731 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19732 row
->phys_height
= max (row
->phys_height
,
19733 it
->max_phys_ascent
+ it
->max_phys_descent
);
19734 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19735 it
->max_extra_line_spacing
);
19737 /* End of this display line if row is continued. */
19738 if (row
->continued_p
|| row
->ends_at_zv_p
)
19743 /* Is this a line end? If yes, we're also done, after making
19744 sure that a non-default face is extended up to the right
19745 margin of the window. */
19746 if (ITERATOR_AT_END_OF_LINE_P (it
))
19748 int used_before
= row
->used
[TEXT_AREA
];
19750 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
19752 /* Add a space at the end of the line that is used to
19753 display the cursor there. */
19754 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19755 append_space_for_newline (it
, 0);
19757 /* Extend the face to the end of the line. */
19758 extend_face_to_end_of_line (it
);
19760 /* Make sure we have the position. */
19761 if (used_before
== 0)
19762 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
19764 /* Record the position of the newline, for use in
19766 it
->eol_pos
= it
->current
.pos
;
19768 /* Consume the line end. This skips over invisible lines. */
19769 set_iterator_to_next (it
, 1);
19770 it
->continuation_lines_width
= 0;
19774 /* Proceed with next display element. Note that this skips
19775 over lines invisible because of selective display. */
19776 set_iterator_to_next (it
, 1);
19778 /* If we truncate lines, we are done when the last displayed
19779 glyphs reach past the right margin of the window. */
19780 if (it
->line_wrap
== TRUNCATE
19781 && (FRAME_WINDOW_P (it
->f
) && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
19782 ? (it
->current_x
>= it
->last_visible_x
)
19783 : (it
->current_x
> it
->last_visible_x
)))
19785 /* Maybe add truncation glyphs. */
19786 if (!FRAME_WINDOW_P (it
->f
)
19787 || (row
->reversed_p
19788 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19789 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19793 if (!row
->reversed_p
)
19795 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
19796 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19801 for (i
= 0; i
< row
->used
[TEXT_AREA
]; i
++)
19802 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19804 /* Remove any padding glyphs at the front of ROW, to
19805 make room for the truncation glyphs we will be
19806 adding below. The loop below always inserts at
19807 least one truncation glyph, so also remove the
19808 last glyph added to ROW. */
19809 unproduce_glyphs (it
, i
+ 1);
19810 /* Adjust i for the loop below. */
19811 i
= row
->used
[TEXT_AREA
] - (i
+ 1);
19814 it
->current_x
= x_before
;
19815 if (!FRAME_WINDOW_P (it
->f
))
19817 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
19819 row
->used
[TEXT_AREA
] = i
;
19820 produce_special_glyphs (it
, IT_TRUNCATION
);
19825 row
->used
[TEXT_AREA
] = i
;
19826 produce_special_glyphs (it
, IT_TRUNCATION
);
19829 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19831 /* Don't truncate if we can overflow newline into fringe. */
19832 if (!get_next_display_element (it
))
19834 it
->continuation_lines_width
= 0;
19835 row
->ends_at_zv_p
= 1;
19836 row
->exact_window_width_line_p
= 1;
19839 if (ITERATOR_AT_END_OF_LINE_P (it
))
19841 row
->exact_window_width_line_p
= 1;
19842 goto at_end_of_line
;
19844 it
->current_x
= x_before
;
19847 row
->truncated_on_right_p
= 1;
19848 it
->continuation_lines_width
= 0;
19849 reseat_at_next_visible_line_start (it
, 0);
19850 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
19851 it
->hpos
= hpos_before
;
19857 bidi_unshelve_cache (wrap_data
, 1);
19859 /* If line is not empty and hscrolled, maybe insert truncation glyphs
19860 at the left window margin. */
19861 if (it
->first_visible_x
19862 && IT_CHARPOS (*it
) != CHARPOS (row
->start
.pos
))
19864 if (!FRAME_WINDOW_P (it
->f
)
19865 || (row
->reversed_p
19866 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
19867 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
19868 insert_left_trunc_glyphs (it
);
19869 row
->truncated_on_left_p
= 1;
19872 /* Remember the position at which this line ends.
19874 BIDI Note: any code that needs MATRIX_ROW_START/END_CHARPOS
19875 cannot be before the call to find_row_edges below, since that is
19876 where these positions are determined. */
19877 row
->end
= it
->current
;
19880 row
->minpos
= row
->start
.pos
;
19881 row
->maxpos
= row
->end
.pos
;
19885 /* ROW->minpos and ROW->maxpos must be the smallest and
19886 `1 + the largest' buffer positions in ROW. But if ROW was
19887 bidi-reordered, these two positions can be anywhere in the
19888 row, so we must determine them now. */
19889 find_row_edges (it
, row
, min_pos
, min_bpos
, max_pos
, max_bpos
);
19892 /* If the start of this line is the overlay arrow-position, then
19893 mark this glyph row as the one containing the overlay arrow.
19894 This is clearly a mess with variable size fonts. It would be
19895 better to let it be displayed like cursors under X. */
19896 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
19897 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
19898 !NILP (overlay_arrow_string
)))
19900 /* Overlay arrow in window redisplay is a fringe bitmap. */
19901 if (STRINGP (overlay_arrow_string
))
19903 struct glyph_row
*arrow_row
19904 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
19905 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
19906 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
19907 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
19908 struct glyph
*p2
, *end
;
19910 /* Copy the arrow glyphs. */
19911 while (glyph
< arrow_end
)
19914 /* Throw away padding glyphs. */
19916 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
19917 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
19923 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
19928 eassert (INTEGERP (overlay_arrow_string
));
19929 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
19931 overlay_arrow_seen
= 1;
19934 /* Highlight trailing whitespace. */
19935 if (!NILP (Vshow_trailing_whitespace
))
19936 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
19938 /* Compute pixel dimensions of this line. */
19939 compute_line_metrics (it
);
19941 /* Implementation note: No changes in the glyphs of ROW or in their
19942 faces can be done past this point, because compute_line_metrics
19943 computes ROW's hash value and stores it within the glyph_row
19946 /* Record whether this row ends inside an ellipsis. */
19947 row
->ends_in_ellipsis_p
19948 = (it
->method
== GET_FROM_DISPLAY_VECTOR
19949 && it
->ellipsis_p
);
19951 /* Save fringe bitmaps in this row. */
19952 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
19953 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
19954 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
19955 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
19957 it
->left_user_fringe_bitmap
= 0;
19958 it
->left_user_fringe_face_id
= 0;
19959 it
->right_user_fringe_bitmap
= 0;
19960 it
->right_user_fringe_face_id
= 0;
19962 /* Maybe set the cursor. */
19963 cvpos
= it
->w
->cursor
.vpos
;
19965 /* In bidi-reordered rows, keep checking for proper cursor
19966 position even if one has been found already, because buffer
19967 positions in such rows change non-linearly with ROW->VPOS,
19968 when a line is continued. One exception: when we are at ZV,
19969 display cursor on the first suitable glyph row, since all
19970 the empty rows after that also have their position set to ZV. */
19971 /* FIXME: Revisit this when glyph ``spilling'' in continuation
19972 lines' rows is implemented for bidi-reordered rows. */
19974 && !MATRIX_ROW (it
->w
->desired_matrix
, cvpos
)->ends_at_zv_p
))
19975 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
19976 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
19977 && cursor_row_p (row
))
19978 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
19980 /* Prepare for the next line. This line starts horizontally at (X
19981 HPOS) = (0 0). Vertical positions are incremented. As a
19982 convenience for the caller, IT->glyph_row is set to the next
19984 it
->current_x
= it
->hpos
= 0;
19985 it
->current_y
+= row
->height
;
19986 SET_TEXT_POS (it
->eol_pos
, 0, 0);
19989 /* The next row should by default use the same value of the
19990 reversed_p flag as this one. set_iterator_to_next decides when
19991 it's a new paragraph, and PRODUCE_GLYPHS recomputes the value of
19992 the flag accordingly. */
19993 if (it
->glyph_row
< MATRIX_BOTTOM_TEXT_ROW (it
->w
->desired_matrix
, it
->w
))
19994 it
->glyph_row
->reversed_p
= row
->reversed_p
;
19995 it
->start
= row
->end
;
19996 return row
->displays_text_p
;
19998 #undef RECORD_MAX_MIN_POS
20001 DEFUN ("current-bidi-paragraph-direction", Fcurrent_bidi_paragraph_direction
,
20002 Scurrent_bidi_paragraph_direction
, 0, 1, 0,
20003 doc
: /* Return paragraph direction at point in BUFFER.
20004 Value is either `left-to-right' or `right-to-left'.
20005 If BUFFER is omitted or nil, it defaults to the current buffer.
20007 Paragraph direction determines how the text in the paragraph is displayed.
20008 In left-to-right paragraphs, text begins at the left margin of the window
20009 and the reading direction is generally left to right. In right-to-left
20010 paragraphs, text begins at the right margin and is read from right to left.
20012 See also `bidi-paragraph-direction'. */)
20013 (Lisp_Object buffer
)
20015 struct buffer
*buf
= current_buffer
;
20016 struct buffer
*old
= buf
;
20018 if (! NILP (buffer
))
20020 CHECK_BUFFER (buffer
);
20021 buf
= XBUFFER (buffer
);
20024 if (NILP (BVAR (buf
, bidi_display_reordering
))
20025 || NILP (BVAR (buf
, enable_multibyte_characters
))
20026 /* When we are loading loadup.el, the character property tables
20027 needed for bidi iteration are not yet available. */
20028 || !NILP (Vpurify_flag
))
20029 return Qleft_to_right
;
20030 else if (!NILP (BVAR (buf
, bidi_paragraph_direction
)))
20031 return BVAR (buf
, bidi_paragraph_direction
);
20034 /* Determine the direction from buffer text. We could try to
20035 use current_matrix if it is up to date, but this seems fast
20036 enough as it is. */
20037 struct bidi_it itb
;
20038 ptrdiff_t pos
= BUF_PT (buf
);
20039 ptrdiff_t bytepos
= BUF_PT_BYTE (buf
);
20041 void *itb_data
= bidi_shelve_cache ();
20043 set_buffer_temp (buf
);
20044 /* bidi_paragraph_init finds the base direction of the paragraph
20045 by searching forward from paragraph start. We need the base
20046 direction of the current or _previous_ paragraph, so we need
20047 to make sure we are within that paragraph. To that end, find
20048 the previous non-empty line. */
20049 if (pos
>= ZV
&& pos
> BEGV
)
20052 bytepos
= CHAR_TO_BYTE (pos
);
20054 if (fast_looking_at (build_string ("[\f\t ]*\n"),
20055 pos
, bytepos
, ZV
, ZV_BYTE
, Qnil
) > 0)
20057 while ((c
= FETCH_BYTE (bytepos
)) == '\n'
20058 || c
== ' ' || c
== '\t' || c
== '\f')
20060 if (bytepos
<= BEGV_BYTE
)
20065 while (!CHAR_HEAD_P (FETCH_BYTE (bytepos
)))
20068 bidi_init_it (pos
, bytepos
, FRAME_WINDOW_P (SELECTED_FRAME ()), &itb
);
20069 itb
.paragraph_dir
= NEUTRAL_DIR
;
20070 itb
.string
.s
= NULL
;
20071 itb
.string
.lstring
= Qnil
;
20072 itb
.string
.bufpos
= 0;
20073 itb
.string
.unibyte
= 0;
20074 bidi_paragraph_init (NEUTRAL_DIR
, &itb
, 1);
20075 bidi_unshelve_cache (itb_data
, 0);
20076 set_buffer_temp (old
);
20077 switch (itb
.paragraph_dir
)
20080 return Qleft_to_right
;
20083 return Qright_to_left
;
20093 /***********************************************************************
20095 ***********************************************************************/
20097 /* Redisplay the menu bar in the frame for window W.
20099 The menu bar of X frames that don't have X toolkit support is
20100 displayed in a special window W->frame->menu_bar_window.
20102 The menu bar of terminal frames is treated specially as far as
20103 glyph matrices are concerned. Menu bar lines are not part of
20104 windows, so the update is done directly on the frame matrix rows
20105 for the menu bar. */
20108 display_menu_bar (struct window
*w
)
20110 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20115 /* Don't do all this for graphical frames. */
20117 if (FRAME_W32_P (f
))
20120 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
20126 if (FRAME_NS_P (f
))
20128 #endif /* HAVE_NS */
20130 #ifdef USE_X_TOOLKIT
20131 eassert (!FRAME_WINDOW_P (f
));
20132 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
20133 it
.first_visible_x
= 0;
20134 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
20135 #else /* not USE_X_TOOLKIT */
20136 if (FRAME_WINDOW_P (f
))
20138 /* Menu bar lines are displayed in the desired matrix of the
20139 dummy window menu_bar_window. */
20140 struct window
*menu_w
;
20141 eassert (WINDOWP (f
->menu_bar_window
));
20142 menu_w
= XWINDOW (f
->menu_bar_window
);
20143 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
20145 it
.first_visible_x
= 0;
20146 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
20150 /* This is a TTY frame, i.e. character hpos/vpos are used as
20152 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
20154 it
.first_visible_x
= 0;
20155 it
.last_visible_x
= FRAME_COLS (f
);
20157 #endif /* not USE_X_TOOLKIT */
20159 /* FIXME: This should be controlled by a user option. See the
20160 comments in redisplay_tool_bar and display_mode_line about
20162 it
.paragraph_embedding
= L2R
;
20164 if (! mode_line_inverse_video
)
20165 /* Force the menu-bar to be displayed in the default face. */
20166 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
20168 /* Clear all rows of the menu bar. */
20169 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
20171 struct glyph_row
*row
= it
.glyph_row
+ i
;
20172 clear_glyph_row (row
);
20173 row
->enabled_p
= 1;
20174 row
->full_width_p
= 1;
20177 /* Display all items of the menu bar. */
20178 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
20179 for (i
= 0; i
< ASIZE (items
); i
+= 4)
20181 Lisp_Object string
;
20183 /* Stop at nil string. */
20184 string
= AREF (items
, i
+ 1);
20188 /* Remember where item was displayed. */
20189 ASET (items
, i
+ 3, make_number (it
.hpos
));
20191 /* Display the item, pad with one space. */
20192 if (it
.current_x
< it
.last_visible_x
)
20193 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
20194 SCHARS (string
) + 1, 0, 0, -1);
20197 /* Fill out the line with spaces. */
20198 if (it
.current_x
< it
.last_visible_x
)
20199 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
20201 /* Compute the total height of the lines. */
20202 compute_line_metrics (&it
);
20207 /***********************************************************************
20209 ***********************************************************************/
20211 /* Redisplay mode lines in the window tree whose root is WINDOW. If
20212 FORCE is non-zero, redisplay mode lines unconditionally.
20213 Otherwise, redisplay only mode lines that are garbaged. Value is
20214 the number of windows whose mode lines were redisplayed. */
20217 redisplay_mode_lines (Lisp_Object window
, int force
)
20221 while (!NILP (window
))
20223 struct window
*w
= XWINDOW (window
);
20225 if (WINDOWP (w
->hchild
))
20226 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
20227 else if (WINDOWP (w
->vchild
))
20228 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
20230 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
20231 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
20233 struct text_pos lpoint
;
20234 struct buffer
*old
= current_buffer
;
20236 /* Set the window's buffer for the mode line display. */
20237 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
20238 set_buffer_internal_1 (XBUFFER (w
->buffer
));
20240 /* Point refers normally to the selected window. For any
20241 other window, set up appropriate value. */
20242 if (!EQ (window
, selected_window
))
20244 struct text_pos pt
;
20246 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
20247 if (CHARPOS (pt
) < BEGV
)
20248 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
20249 else if (CHARPOS (pt
) > (ZV
- 1))
20250 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
20252 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
20255 /* Display mode lines. */
20256 clear_glyph_matrix (w
->desired_matrix
);
20257 if (display_mode_lines (w
))
20260 w
->must_be_updated_p
= 1;
20263 /* Restore old settings. */
20264 set_buffer_internal_1 (old
);
20265 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
20275 /* Display the mode and/or header line of window W. Value is the
20276 sum number of mode lines and header lines displayed. */
20279 display_mode_lines (struct window
*w
)
20281 Lisp_Object old_selected_window
, old_selected_frame
;
20284 old_selected_frame
= selected_frame
;
20285 selected_frame
= w
->frame
;
20286 old_selected_window
= selected_window
;
20287 XSETWINDOW (selected_window
, w
);
20289 /* These will be set while the mode line specs are processed. */
20290 line_number_displayed
= 0;
20291 wset_column_number_displayed (w
, Qnil
);
20293 if (WINDOW_WANTS_MODELINE_P (w
))
20295 struct window
*sel_w
= XWINDOW (old_selected_window
);
20297 /* Select mode line face based on the real selected window. */
20298 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
20299 BVAR (current_buffer
, mode_line_format
));
20303 if (WINDOW_WANTS_HEADER_LINE_P (w
))
20305 display_mode_line (w
, HEADER_LINE_FACE_ID
,
20306 BVAR (current_buffer
, header_line_format
));
20310 selected_frame
= old_selected_frame
;
20311 selected_window
= old_selected_window
;
20316 /* Display mode or header line of window W. FACE_ID specifies which
20317 line to display; it is either MODE_LINE_FACE_ID or
20318 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
20319 display. Value is the pixel height of the mode/header line
20323 display_mode_line (struct window
*w
, enum face_id face_id
, Lisp_Object format
)
20327 ptrdiff_t count
= SPECPDL_INDEX ();
20329 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
20330 /* Don't extend on a previously drawn mode-line.
20331 This may happen if called from pos_visible_p. */
20332 it
.glyph_row
->enabled_p
= 0;
20333 prepare_desired_row (it
.glyph_row
);
20335 it
.glyph_row
->mode_line_p
= 1;
20337 if (! mode_line_inverse_video
)
20338 /* Force the mode-line to be displayed in the default face. */
20339 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
20341 /* FIXME: This should be controlled by a user option. But
20342 supporting such an option is not trivial, since the mode line is
20343 made up of many separate strings. */
20344 it
.paragraph_embedding
= L2R
;
20346 record_unwind_protect (unwind_format_mode_line
,
20347 format_mode_line_unwind_data (NULL
, NULL
, Qnil
, 0));
20349 mode_line_target
= MODE_LINE_DISPLAY
;
20351 /* Temporarily make frame's keyboard the current kboard so that
20352 kboard-local variables in the mode_line_format will get the right
20354 push_kboard (FRAME_KBOARD (it
.f
));
20355 record_unwind_save_match_data ();
20356 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
20359 unbind_to (count
, Qnil
);
20361 /* Fill up with spaces. */
20362 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
20364 compute_line_metrics (&it
);
20365 it
.glyph_row
->full_width_p
= 1;
20366 it
.glyph_row
->continued_p
= 0;
20367 it
.glyph_row
->truncated_on_left_p
= 0;
20368 it
.glyph_row
->truncated_on_right_p
= 0;
20370 /* Make a 3D mode-line have a shadow at its right end. */
20371 face
= FACE_FROM_ID (it
.f
, face_id
);
20372 extend_face_to_end_of_line (&it
);
20373 if (face
->box
!= FACE_NO_BOX
)
20375 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
20376 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
20377 last
->right_box_line_p
= 1;
20380 return it
.glyph_row
->height
;
20383 /* Move element ELT in LIST to the front of LIST.
20384 Return the updated list. */
20387 move_elt_to_front (Lisp_Object elt
, Lisp_Object list
)
20389 register Lisp_Object tail
, prev
;
20390 register Lisp_Object tem
;
20394 while (CONSP (tail
))
20400 /* Splice out the link TAIL. */
20402 list
= XCDR (tail
);
20404 Fsetcdr (prev
, XCDR (tail
));
20406 /* Now make it the first. */
20407 Fsetcdr (tail
, list
);
20412 tail
= XCDR (tail
);
20416 /* Not found--return unchanged LIST. */
20420 /* Contribute ELT to the mode line for window IT->w. How it
20421 translates into text depends on its data type.
20423 IT describes the display environment in which we display, as usual.
20425 DEPTH is the depth in recursion. It is used to prevent
20426 infinite recursion here.
20428 FIELD_WIDTH is the number of characters the display of ELT should
20429 occupy in the mode line, and PRECISION is the maximum number of
20430 characters to display from ELT's representation. See
20431 display_string for details.
20433 Returns the hpos of the end of the text generated by ELT.
20435 PROPS is a property list to add to any string we encounter.
20437 If RISKY is nonzero, remove (disregard) any properties in any string
20438 we encounter, and ignore :eval and :propertize.
20440 The global variable `mode_line_target' determines whether the
20441 output is passed to `store_mode_line_noprop',
20442 `store_mode_line_string', or `display_string'. */
20445 display_mode_element (struct it
*it
, int depth
, int field_width
, int precision
,
20446 Lisp_Object elt
, Lisp_Object props
, int risky
)
20448 int n
= 0, field
, prec
;
20453 elt
= build_string ("*too-deep*");
20457 switch (XTYPE (elt
))
20461 /* A string: output it and check for %-constructs within it. */
20463 ptrdiff_t offset
= 0;
20465 if (SCHARS (elt
) > 0
20466 && (!NILP (props
) || risky
))
20468 Lisp_Object oprops
, aelt
;
20469 oprops
= Ftext_properties_at (make_number (0), elt
);
20471 /* If the starting string's properties are not what
20472 we want, translate the string. Also, if the string
20473 is risky, do that anyway. */
20475 if (NILP (Fequal (props
, oprops
)) || risky
)
20477 /* If the starting string has properties,
20478 merge the specified ones onto the existing ones. */
20479 if (! NILP (oprops
) && !risky
)
20483 oprops
= Fcopy_sequence (oprops
);
20485 while (CONSP (tem
))
20487 oprops
= Fplist_put (oprops
, XCAR (tem
),
20488 XCAR (XCDR (tem
)));
20489 tem
= XCDR (XCDR (tem
));
20494 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
20495 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
20497 /* AELT is what we want. Move it to the front
20498 without consing. */
20500 mode_line_proptrans_alist
20501 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
20507 /* If AELT has the wrong props, it is useless.
20508 so get rid of it. */
20510 mode_line_proptrans_alist
20511 = Fdelq (aelt
, mode_line_proptrans_alist
);
20513 elt
= Fcopy_sequence (elt
);
20514 Fset_text_properties (make_number (0), Flength (elt
),
20516 /* Add this item to mode_line_proptrans_alist. */
20517 mode_line_proptrans_alist
20518 = Fcons (Fcons (elt
, props
),
20519 mode_line_proptrans_alist
);
20520 /* Truncate mode_line_proptrans_alist
20521 to at most 50 elements. */
20522 tem
= Fnthcdr (make_number (50),
20523 mode_line_proptrans_alist
);
20525 XSETCDR (tem
, Qnil
);
20534 prec
= precision
- n
;
20535 switch (mode_line_target
)
20537 case MODE_LINE_NOPROP
:
20538 case MODE_LINE_TITLE
:
20539 n
+= store_mode_line_noprop (SSDATA (elt
), -1, prec
);
20541 case MODE_LINE_STRING
:
20542 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
20544 case MODE_LINE_DISPLAY
:
20545 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
20546 0, prec
, 0, STRING_MULTIBYTE (elt
));
20553 /* Handle the non-literal case. */
20555 while ((precision
<= 0 || n
< precision
)
20556 && SREF (elt
, offset
) != 0
20557 && (mode_line_target
!= MODE_LINE_DISPLAY
20558 || it
->current_x
< it
->last_visible_x
))
20560 ptrdiff_t last_offset
= offset
;
20562 /* Advance to end of string or next format specifier. */
20563 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
20566 if (offset
- 1 != last_offset
)
20568 ptrdiff_t nchars
, nbytes
;
20570 /* Output to end of string or up to '%'. Field width
20571 is length of string. Don't output more than
20572 PRECISION allows us. */
20575 prec
= c_string_width (SDATA (elt
) + last_offset
,
20576 offset
- last_offset
, precision
- n
,
20579 switch (mode_line_target
)
20581 case MODE_LINE_NOPROP
:
20582 case MODE_LINE_TITLE
:
20583 n
+= store_mode_line_noprop (SSDATA (elt
) + last_offset
, 0, prec
);
20585 case MODE_LINE_STRING
:
20587 ptrdiff_t bytepos
= last_offset
;
20588 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
20589 ptrdiff_t endpos
= (precision
<= 0
20590 ? string_byte_to_char (elt
, offset
)
20591 : charpos
+ nchars
);
20593 n
+= store_mode_line_string (NULL
,
20594 Fsubstring (elt
, make_number (charpos
),
20595 make_number (endpos
)),
20599 case MODE_LINE_DISPLAY
:
20601 ptrdiff_t bytepos
= last_offset
;
20602 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
20604 if (precision
<= 0)
20605 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
20606 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
20608 STRING_MULTIBYTE (elt
));
20613 else /* c == '%' */
20615 ptrdiff_t percent_position
= offset
;
20617 /* Get the specified minimum width. Zero means
20620 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
20621 field
= field
* 10 + c
- '0';
20623 /* Don't pad beyond the total padding allowed. */
20624 if (field_width
- n
> 0 && field
> field_width
- n
)
20625 field
= field_width
- n
;
20627 /* Note that either PRECISION <= 0 or N < PRECISION. */
20628 prec
= precision
- n
;
20631 n
+= display_mode_element (it
, depth
, field
, prec
,
20632 Vglobal_mode_string
, props
,
20637 ptrdiff_t bytepos
, charpos
;
20639 Lisp_Object string
;
20641 bytepos
= percent_position
;
20642 charpos
= (STRING_MULTIBYTE (elt
)
20643 ? string_byte_to_char (elt
, bytepos
)
20645 spec
= decode_mode_spec (it
->w
, c
, field
, &string
);
20646 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
20648 switch (mode_line_target
)
20650 case MODE_LINE_NOPROP
:
20651 case MODE_LINE_TITLE
:
20652 n
+= store_mode_line_noprop (spec
, field
, prec
);
20654 case MODE_LINE_STRING
:
20656 Lisp_Object tem
= build_string (spec
);
20657 props
= Ftext_properties_at (make_number (charpos
), elt
);
20658 /* Should only keep face property in props */
20659 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
20662 case MODE_LINE_DISPLAY
:
20664 int nglyphs_before
, nwritten
;
20666 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
20667 nwritten
= display_string (spec
, string
, elt
,
20672 /* Assign to the glyphs written above the
20673 string where the `%x' came from, position
20677 struct glyph
*glyph
20678 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
20682 for (i
= 0; i
< nwritten
; ++i
)
20684 glyph
[i
].object
= elt
;
20685 glyph
[i
].charpos
= charpos
;
20702 /* A symbol: process the value of the symbol recursively
20703 as if it appeared here directly. Avoid error if symbol void.
20704 Special case: if value of symbol is a string, output the string
20707 register Lisp_Object tem
;
20709 /* If the variable is not marked as risky to set
20710 then its contents are risky to use. */
20711 if (NILP (Fget (elt
, Qrisky_local_variable
)))
20714 tem
= Fboundp (elt
);
20717 tem
= Fsymbol_value (elt
);
20718 /* If value is a string, output that string literally:
20719 don't check for % within it. */
20723 if (!EQ (tem
, elt
))
20725 /* Give up right away for nil or t. */
20735 register Lisp_Object car
, tem
;
20737 /* A cons cell: five distinct cases.
20738 If first element is :eval or :propertize, do something special.
20739 If first element is a string or a cons, process all the elements
20740 and effectively concatenate them.
20741 If first element is a negative number, truncate displaying cdr to
20742 at most that many characters. If positive, pad (with spaces)
20743 to at least that many characters.
20744 If first element is a symbol, process the cadr or caddr recursively
20745 according to whether the symbol's value is non-nil or nil. */
20747 if (EQ (car
, QCeval
))
20749 /* An element of the form (:eval FORM) means evaluate FORM
20750 and use the result as mode line elements. */
20755 if (CONSP (XCDR (elt
)))
20758 spec
= safe_eval (XCAR (XCDR (elt
)));
20759 n
+= display_mode_element (it
, depth
, field_width
- n
,
20760 precision
- n
, spec
, props
,
20764 else if (EQ (car
, QCpropertize
))
20766 /* An element of the form (:propertize ELT PROPS...)
20767 means display ELT but applying properties PROPS. */
20772 if (CONSP (XCDR (elt
)))
20773 n
+= display_mode_element (it
, depth
, field_width
- n
,
20774 precision
- n
, XCAR (XCDR (elt
)),
20775 XCDR (XCDR (elt
)), risky
);
20777 else if (SYMBOLP (car
))
20779 tem
= Fboundp (car
);
20783 /* elt is now the cdr, and we know it is a cons cell.
20784 Use its car if CAR has a non-nil value. */
20787 tem
= Fsymbol_value (car
);
20794 /* Symbol's value is nil (or symbol is unbound)
20795 Get the cddr of the original list
20796 and if possible find the caddr and use that. */
20800 else if (!CONSP (elt
))
20805 else if (INTEGERP (car
))
20807 register int lim
= XINT (car
);
20811 /* Negative int means reduce maximum width. */
20812 if (precision
<= 0)
20815 precision
= min (precision
, -lim
);
20819 /* Padding specified. Don't let it be more than
20820 current maximum. */
20822 lim
= min (precision
, lim
);
20824 /* If that's more padding than already wanted, queue it.
20825 But don't reduce padding already specified even if
20826 that is beyond the current truncation point. */
20827 field_width
= max (lim
, field_width
);
20831 else if (STRINGP (car
) || CONSP (car
))
20833 Lisp_Object halftail
= elt
;
20837 && (precision
<= 0 || n
< precision
))
20839 n
+= display_mode_element (it
, depth
,
20840 /* Do padding only after the last
20841 element in the list. */
20842 (! CONSP (XCDR (elt
))
20845 precision
- n
, XCAR (elt
),
20849 if ((len
& 1) == 0)
20850 halftail
= XCDR (halftail
);
20851 /* Check for cycle. */
20852 if (EQ (halftail
, elt
))
20861 elt
= build_string ("*invalid*");
20865 /* Pad to FIELD_WIDTH. */
20866 if (field_width
> 0 && n
< field_width
)
20868 switch (mode_line_target
)
20870 case MODE_LINE_NOPROP
:
20871 case MODE_LINE_TITLE
:
20872 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
20874 case MODE_LINE_STRING
:
20875 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
20877 case MODE_LINE_DISPLAY
:
20878 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
20887 /* Store a mode-line string element in mode_line_string_list.
20889 If STRING is non-null, display that C string. Otherwise, the Lisp
20890 string LISP_STRING is displayed.
20892 FIELD_WIDTH is the minimum number of output glyphs to produce.
20893 If STRING has fewer characters than FIELD_WIDTH, pad to the right
20894 with spaces. FIELD_WIDTH <= 0 means don't pad.
20896 PRECISION is the maximum number of characters to output from
20897 STRING. PRECISION <= 0 means don't truncate the string.
20899 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
20900 properties to the string.
20902 PROPS are the properties to add to the string.
20903 The mode_line_string_face face property is always added to the string.
20907 store_mode_line_string (const char *string
, Lisp_Object lisp_string
, int copy_string
,
20908 int field_width
, int precision
, Lisp_Object props
)
20913 if (string
!= NULL
)
20915 len
= strlen (string
);
20916 if (precision
> 0 && len
> precision
)
20918 lisp_string
= make_string (string
, len
);
20920 props
= mode_line_string_face_prop
;
20921 else if (!NILP (mode_line_string_face
))
20923 Lisp_Object face
= Fplist_get (props
, Qface
);
20924 props
= Fcopy_sequence (props
);
20926 face
= mode_line_string_face
;
20928 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
20929 props
= Fplist_put (props
, Qface
, face
);
20931 Fadd_text_properties (make_number (0), make_number (len
),
20932 props
, lisp_string
);
20936 len
= XFASTINT (Flength (lisp_string
));
20937 if (precision
> 0 && len
> precision
)
20940 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
20943 if (!NILP (mode_line_string_face
))
20947 props
= Ftext_properties_at (make_number (0), lisp_string
);
20948 face
= Fplist_get (props
, Qface
);
20950 face
= mode_line_string_face
;
20952 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
20953 props
= Fcons (Qface
, Fcons (face
, Qnil
));
20955 lisp_string
= Fcopy_sequence (lisp_string
);
20958 Fadd_text_properties (make_number (0), make_number (len
),
20959 props
, lisp_string
);
20964 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
20968 if (field_width
> len
)
20970 field_width
-= len
;
20971 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
20973 Fadd_text_properties (make_number (0), make_number (field_width
),
20974 props
, lisp_string
);
20975 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
20983 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
20985 doc
: /* Format a string out of a mode line format specification.
20986 First arg FORMAT specifies the mode line format (see `mode-line-format'
20987 for details) to use.
20989 By default, the format is evaluated for the currently selected window.
20991 Optional second arg FACE specifies the face property to put on all
20992 characters for which no face is specified. The value nil means the
20993 default face. The value t means whatever face the window's mode line
20994 currently uses (either `mode-line' or `mode-line-inactive',
20995 depending on whether the window is the selected window or not).
20996 An integer value means the value string has no text
20999 Optional third and fourth args WINDOW and BUFFER specify the window
21000 and buffer to use as the context for the formatting (defaults
21001 are the selected window and the WINDOW's buffer). */)
21002 (Lisp_Object format
, Lisp_Object face
,
21003 Lisp_Object window
, Lisp_Object buffer
)
21008 struct buffer
*old_buffer
= NULL
;
21010 int no_props
= INTEGERP (face
);
21011 ptrdiff_t count
= SPECPDL_INDEX ();
21013 int string_start
= 0;
21016 window
= selected_window
;
21017 CHECK_WINDOW (window
);
21018 w
= XWINDOW (window
);
21021 buffer
= w
->buffer
;
21022 CHECK_BUFFER (buffer
);
21024 /* Make formatting the modeline a non-op when noninteractive, otherwise
21025 there will be problems later caused by a partially initialized frame. */
21026 if (NILP (format
) || noninteractive
)
21027 return empty_unibyte_string
;
21032 face_id
= (NILP (face
) || EQ (face
, Qdefault
)) ? DEFAULT_FACE_ID
21033 : EQ (face
, Qt
) ? (EQ (window
, selected_window
)
21034 ? MODE_LINE_FACE_ID
: MODE_LINE_INACTIVE_FACE_ID
)
21035 : EQ (face
, Qmode_line
) ? MODE_LINE_FACE_ID
21036 : EQ (face
, Qmode_line_inactive
) ? MODE_LINE_INACTIVE_FACE_ID
21037 : EQ (face
, Qheader_line
) ? HEADER_LINE_FACE_ID
21038 : EQ (face
, Qtool_bar
) ? TOOL_BAR_FACE_ID
21041 old_buffer
= current_buffer
;
21043 /* Save things including mode_line_proptrans_alist,
21044 and set that to nil so that we don't alter the outer value. */
21045 record_unwind_protect (unwind_format_mode_line
,
21046 format_mode_line_unwind_data
21047 (XFRAME (WINDOW_FRAME (XWINDOW (window
))),
21048 old_buffer
, selected_window
, 1));
21049 mode_line_proptrans_alist
= Qnil
;
21051 Fselect_window (window
, Qt
);
21052 set_buffer_internal_1 (XBUFFER (buffer
));
21054 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
21058 mode_line_target
= MODE_LINE_NOPROP
;
21059 mode_line_string_face_prop
= Qnil
;
21060 mode_line_string_list
= Qnil
;
21061 string_start
= MODE_LINE_NOPROP_LEN (0);
21065 mode_line_target
= MODE_LINE_STRING
;
21066 mode_line_string_list
= Qnil
;
21067 mode_line_string_face
= face
;
21068 mode_line_string_face_prop
21069 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
21072 push_kboard (FRAME_KBOARD (it
.f
));
21073 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
21078 len
= MODE_LINE_NOPROP_LEN (string_start
);
21079 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
21083 mode_line_string_list
= Fnreverse (mode_line_string_list
);
21084 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
21085 empty_unibyte_string
);
21088 unbind_to (count
, Qnil
);
21092 /* Write a null-terminated, right justified decimal representation of
21093 the positive integer D to BUF using a minimal field width WIDTH. */
21096 pint2str (register char *buf
, register int width
, register ptrdiff_t d
)
21098 register char *p
= buf
;
21106 *p
++ = d
% 10 + '0';
21111 for (width
-= (int) (p
- buf
); width
> 0; --width
)
21122 /* Write a null-terminated, right justified decimal and "human
21123 readable" representation of the nonnegative integer D to BUF using
21124 a minimal field width WIDTH. D should be smaller than 999.5e24. */
21126 static const char power_letter
[] =
21140 pint2hrstr (char *buf
, int width
, ptrdiff_t d
)
21142 /* We aim to represent the nonnegative integer D as
21143 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
21144 ptrdiff_t quotient
= d
;
21146 /* -1 means: do not use TENTHS. */
21150 /* Length of QUOTIENT.TENTHS as a string. */
21156 if (1000 <= quotient
)
21158 /* Scale to the appropriate EXPONENT. */
21161 remainder
= quotient
% 1000;
21165 while (1000 <= quotient
);
21167 /* Round to nearest and decide whether to use TENTHS or not. */
21170 tenths
= remainder
/ 100;
21171 if (50 <= remainder
% 100)
21178 if (quotient
== 10)
21186 if (500 <= remainder
)
21188 if (quotient
< 999)
21199 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
21200 if (tenths
== -1 && quotient
<= 99)
21207 p
= psuffix
= buf
+ max (width
, length
);
21209 /* Print EXPONENT. */
21210 *psuffix
++ = power_letter
[exponent
];
21213 /* Print TENTHS. */
21216 *--p
= '0' + tenths
;
21220 /* Print QUOTIENT. */
21223 int digit
= quotient
% 10;
21224 *--p
= '0' + digit
;
21226 while ((quotient
/= 10) != 0);
21228 /* Print leading spaces. */
21233 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
21234 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
21235 type of CODING_SYSTEM. Return updated pointer into BUF. */
21237 static unsigned char invalid_eol_type
[] = "(*invalid*)";
21240 decode_mode_spec_coding (Lisp_Object coding_system
, register char *buf
, int eol_flag
)
21243 int multibyte
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
21244 const unsigned char *eol_str
;
21246 /* The EOL conversion we are using. */
21247 Lisp_Object eoltype
;
21249 val
= CODING_SYSTEM_SPEC (coding_system
);
21252 if (!VECTORP (val
)) /* Not yet decided. */
21254 *buf
++ = multibyte
? '-' : ' ';
21256 eoltype
= eol_mnemonic_undecided
;
21257 /* Don't mention EOL conversion if it isn't decided. */
21262 Lisp_Object eolvalue
;
21264 attrs
= AREF (val
, 0);
21265 eolvalue
= AREF (val
, 2);
21268 ? XFASTINT (CODING_ATTR_MNEMONIC (attrs
))
21273 /* The EOL conversion that is normal on this system. */
21275 if (NILP (eolvalue
)) /* Not yet decided. */
21276 eoltype
= eol_mnemonic_undecided
;
21277 else if (VECTORP (eolvalue
)) /* Not yet decided. */
21278 eoltype
= eol_mnemonic_undecided
;
21279 else /* eolvalue is Qunix, Qdos, or Qmac. */
21280 eoltype
= (EQ (eolvalue
, Qunix
)
21281 ? eol_mnemonic_unix
21282 : (EQ (eolvalue
, Qdos
) == 1
21283 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
21289 /* Mention the EOL conversion if it is not the usual one. */
21290 if (STRINGP (eoltype
))
21292 eol_str
= SDATA (eoltype
);
21293 eol_str_len
= SBYTES (eoltype
);
21295 else if (CHARACTERP (eoltype
))
21297 unsigned char *tmp
= alloca (MAX_MULTIBYTE_LENGTH
);
21298 int c
= XFASTINT (eoltype
);
21299 eol_str_len
= CHAR_STRING (c
, tmp
);
21304 eol_str
= invalid_eol_type
;
21305 eol_str_len
= sizeof (invalid_eol_type
) - 1;
21307 memcpy (buf
, eol_str
, eol_str_len
);
21308 buf
+= eol_str_len
;
21314 /* Return a string for the output of a mode line %-spec for window W,
21315 generated by character C. FIELD_WIDTH > 0 means pad the string
21316 returned with spaces to that value. Return a Lisp string in
21317 *STRING if the resulting string is taken from that Lisp string.
21319 Note we operate on the current buffer for most purposes,
21320 the exception being w->base_line_pos. */
21322 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
21324 static const char *
21325 decode_mode_spec (struct window
*w
, register int c
, int field_width
,
21326 Lisp_Object
*string
)
21329 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21330 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
21331 struct buffer
*b
= current_buffer
;
21339 if (!NILP (BVAR (b
, read_only
)))
21341 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21346 /* This differs from %* only for a modified read-only buffer. */
21347 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21349 if (!NILP (BVAR (b
, read_only
)))
21354 /* This differs from %* in ignoring read-only-ness. */
21355 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21367 if (command_loop_level
> 5)
21369 p
= decode_mode_spec_buf
;
21370 for (i
= 0; i
< command_loop_level
; i
++)
21373 return decode_mode_spec_buf
;
21381 if (command_loop_level
> 5)
21383 p
= decode_mode_spec_buf
;
21384 for (i
= 0; i
< command_loop_level
; i
++)
21387 return decode_mode_spec_buf
;
21394 /* Let lots_of_dashes be a string of infinite length. */
21395 if (mode_line_target
== MODE_LINE_NOPROP
||
21396 mode_line_target
== MODE_LINE_STRING
)
21398 if (field_width
<= 0
21399 || field_width
> sizeof (lots_of_dashes
))
21401 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
21402 decode_mode_spec_buf
[i
] = '-';
21403 decode_mode_spec_buf
[i
] = '\0';
21404 return decode_mode_spec_buf
;
21407 return lots_of_dashes
;
21411 obj
= BVAR (b
, name
);
21415 /* %c and %l are ignored in `frame-title-format'.
21416 (In redisplay_internal, the frame title is drawn _before_ the
21417 windows are updated, so the stuff which depends on actual
21418 window contents (such as %l) may fail to render properly, or
21419 even crash emacs.) */
21420 if (mode_line_target
== MODE_LINE_TITLE
)
21424 ptrdiff_t col
= current_column ();
21425 wset_column_number_displayed (w
, make_number (col
));
21426 pint2str (decode_mode_spec_buf
, field_width
, col
);
21427 return decode_mode_spec_buf
;
21431 #ifndef SYSTEM_MALLOC
21433 if (NILP (Vmemory_full
))
21436 return "!MEM FULL! ";
21443 /* %F displays the frame name. */
21444 if (!NILP (f
->title
))
21445 return SSDATA (f
->title
);
21446 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
21447 return SSDATA (f
->name
);
21451 obj
= BVAR (b
, filename
);
21456 ptrdiff_t size
= ZV
- BEGV
;
21457 pint2str (decode_mode_spec_buf
, field_width
, size
);
21458 return decode_mode_spec_buf
;
21463 ptrdiff_t size
= ZV
- BEGV
;
21464 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
21465 return decode_mode_spec_buf
;
21470 ptrdiff_t startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
21471 ptrdiff_t topline
, nlines
, height
;
21474 /* %c and %l are ignored in `frame-title-format'. */
21475 if (mode_line_target
== MODE_LINE_TITLE
)
21478 startpos
= XMARKER (w
->start
)->charpos
;
21479 startpos_byte
= marker_byte_position (w
->start
);
21480 height
= WINDOW_TOTAL_LINES (w
);
21482 /* If we decided that this buffer isn't suitable for line numbers,
21483 don't forget that too fast. */
21484 if (EQ (w
->base_line_pos
, w
->buffer
))
21486 /* But do forget it, if the window shows a different buffer now. */
21487 else if (BUFFERP (w
->base_line_pos
))
21488 wset_base_line_pos (w
, Qnil
);
21490 /* If the buffer is very big, don't waste time. */
21491 if (INTEGERP (Vline_number_display_limit
)
21492 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
21494 wset_base_line_pos (w
, Qnil
);
21495 wset_base_line_number (w
, Qnil
);
21499 if (INTEGERP (w
->base_line_number
)
21500 && INTEGERP (w
->base_line_pos
)
21501 && XFASTINT (w
->base_line_pos
) <= startpos
)
21503 line
= XFASTINT (w
->base_line_number
);
21504 linepos
= XFASTINT (w
->base_line_pos
);
21505 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
21510 linepos
= BUF_BEGV (b
);
21511 linepos_byte
= BUF_BEGV_BYTE (b
);
21514 /* Count lines from base line to window start position. */
21515 nlines
= display_count_lines (linepos_byte
,
21519 topline
= nlines
+ line
;
21521 /* Determine a new base line, if the old one is too close
21522 or too far away, or if we did not have one.
21523 "Too close" means it's plausible a scroll-down would
21524 go back past it. */
21525 if (startpos
== BUF_BEGV (b
))
21527 wset_base_line_number (w
, make_number (topline
));
21528 wset_base_line_pos (w
, make_number (BUF_BEGV (b
)));
21530 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
21531 || linepos
== BUF_BEGV (b
))
21533 ptrdiff_t limit
= BUF_BEGV (b
);
21534 ptrdiff_t limit_byte
= BUF_BEGV_BYTE (b
);
21535 ptrdiff_t position
;
21536 ptrdiff_t distance
=
21537 (height
* 2 + 30) * line_number_display_limit_width
;
21539 if (startpos
- distance
> limit
)
21541 limit
= startpos
- distance
;
21542 limit_byte
= CHAR_TO_BYTE (limit
);
21545 nlines
= display_count_lines (startpos_byte
,
21547 - (height
* 2 + 30),
21549 /* If we couldn't find the lines we wanted within
21550 line_number_display_limit_width chars per line,
21551 give up on line numbers for this window. */
21552 if (position
== limit_byte
&& limit
== startpos
- distance
)
21554 wset_base_line_pos (w
, w
->buffer
);
21555 wset_base_line_number (w
, Qnil
);
21559 wset_base_line_number (w
, make_number (topline
- nlines
));
21560 wset_base_line_pos (w
, make_number (BYTE_TO_CHAR (position
)));
21563 /* Now count lines from the start pos to point. */
21564 nlines
= display_count_lines (startpos_byte
,
21565 PT_BYTE
, PT
, &junk
);
21567 /* Record that we did display the line number. */
21568 line_number_displayed
= 1;
21570 /* Make the string to show. */
21571 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
21572 return decode_mode_spec_buf
;
21575 char* p
= decode_mode_spec_buf
;
21576 int pad
= field_width
- 2;
21582 return decode_mode_spec_buf
;
21588 obj
= BVAR (b
, mode_name
);
21592 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
21598 ptrdiff_t pos
= marker_position (w
->start
);
21599 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
21601 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
21603 if (pos
<= BUF_BEGV (b
))
21608 else if (pos
<= BUF_BEGV (b
))
21612 if (total
> 1000000)
21613 /* Do it differently for a large value, to avoid overflow. */
21614 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
21616 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
21617 /* We can't normally display a 3-digit number,
21618 so get us a 2-digit number that is close. */
21621 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
21622 return decode_mode_spec_buf
;
21626 /* Display percentage of size above the bottom of the screen. */
21629 ptrdiff_t toppos
= marker_position (w
->start
);
21630 ptrdiff_t botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
21631 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
21633 if (botpos
>= BUF_ZV (b
))
21635 if (toppos
<= BUF_BEGV (b
))
21642 if (total
> 1000000)
21643 /* Do it differently for a large value, to avoid overflow. */
21644 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
21646 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
21647 /* We can't normally display a 3-digit number,
21648 so get us a 2-digit number that is close. */
21651 if (toppos
<= BUF_BEGV (b
))
21652 sprintf (decode_mode_spec_buf
, "Top%2"pD
"d%%", total
);
21654 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
21655 return decode_mode_spec_buf
;
21660 /* status of process */
21661 obj
= Fget_buffer_process (Fcurrent_buffer ());
21663 return "no process";
21665 obj
= Fsymbol_name (Fprocess_status (obj
));
21671 ptrdiff_t count
= inhibit_garbage_collection ();
21672 Lisp_Object val
= call1 (intern ("file-remote-p"),
21673 BVAR (current_buffer
, directory
));
21674 unbind_to (count
, Qnil
);
21682 case 't': /* indicate TEXT or BINARY */
21686 /* coding-system (not including end-of-line format) */
21688 /* coding-system (including end-of-line type) */
21690 int eol_flag
= (c
== 'Z');
21691 char *p
= decode_mode_spec_buf
;
21693 if (! FRAME_WINDOW_P (f
))
21695 /* No need to mention EOL here--the terminal never needs
21696 to do EOL conversion. */
21697 p
= decode_mode_spec_coding (CODING_ID_NAME
21698 (FRAME_KEYBOARD_CODING (f
)->id
),
21700 p
= decode_mode_spec_coding (CODING_ID_NAME
21701 (FRAME_TERMINAL_CODING (f
)->id
),
21704 p
= decode_mode_spec_coding (BVAR (b
, buffer_file_coding_system
),
21707 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
21708 #ifdef subprocesses
21709 obj
= Fget_buffer_process (Fcurrent_buffer ());
21710 if (PROCESSP (obj
))
21712 p
= decode_mode_spec_coding
21713 (XPROCESS (obj
)->decode_coding_system
, p
, eol_flag
);
21714 p
= decode_mode_spec_coding
21715 (XPROCESS (obj
)->encode_coding_system
, p
, eol_flag
);
21717 #endif /* subprocesses */
21720 return decode_mode_spec_buf
;
21727 return SSDATA (obj
);
21734 /* Count up to COUNT lines starting from START_BYTE.
21735 But don't go beyond LIMIT_BYTE.
21736 Return the number of lines thus found (always nonnegative).
21738 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
21741 display_count_lines (ptrdiff_t start_byte
,
21742 ptrdiff_t limit_byte
, ptrdiff_t count
,
21743 ptrdiff_t *byte_pos_ptr
)
21745 register unsigned char *cursor
;
21746 unsigned char *base
;
21748 register ptrdiff_t ceiling
;
21749 register unsigned char *ceiling_addr
;
21750 ptrdiff_t orig_count
= count
;
21752 /* If we are not in selective display mode,
21753 check only for newlines. */
21754 int selective_display
= (!NILP (BVAR (current_buffer
, selective_display
))
21755 && !INTEGERP (BVAR (current_buffer
, selective_display
)));
21759 while (start_byte
< limit_byte
)
21761 ceiling
= BUFFER_CEILING_OF (start_byte
);
21762 ceiling
= min (limit_byte
- 1, ceiling
);
21763 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
21764 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
21767 if (selective_display
)
21768 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
21771 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
21774 if (cursor
!= ceiling_addr
)
21778 start_byte
+= cursor
- base
+ 1;
21779 *byte_pos_ptr
= start_byte
;
21783 if (++cursor
== ceiling_addr
)
21789 start_byte
+= cursor
- base
;
21794 while (start_byte
> limit_byte
)
21796 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
21797 ceiling
= max (limit_byte
, ceiling
);
21798 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
21799 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
21802 if (selective_display
)
21803 while (--cursor
!= ceiling_addr
21804 && *cursor
!= '\n' && *cursor
!= 015)
21807 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
21810 if (cursor
!= ceiling_addr
)
21814 start_byte
+= cursor
- base
+ 1;
21815 *byte_pos_ptr
= start_byte
;
21816 /* When scanning backwards, we should
21817 not count the newline posterior to which we stop. */
21818 return - orig_count
- 1;
21824 /* Here we add 1 to compensate for the last decrement
21825 of CURSOR, which took it past the valid range. */
21826 start_byte
+= cursor
- base
+ 1;
21830 *byte_pos_ptr
= limit_byte
;
21833 return - orig_count
+ count
;
21834 return orig_count
- count
;
21840 /***********************************************************************
21842 ***********************************************************************/
21844 /* Display a NUL-terminated string, starting with index START.
21846 If STRING is non-null, display that C string. Otherwise, the Lisp
21847 string LISP_STRING is displayed. There's a case that STRING is
21848 non-null and LISP_STRING is not nil. It means STRING is a string
21849 data of LISP_STRING. In that case, we display LISP_STRING while
21850 ignoring its text properties.
21852 If FACE_STRING is not nil, FACE_STRING_POS is a position in
21853 FACE_STRING. Display STRING or LISP_STRING with the face at
21854 FACE_STRING_POS in FACE_STRING:
21856 Display the string in the environment given by IT, but use the
21857 standard display table, temporarily.
21859 FIELD_WIDTH is the minimum number of output glyphs to produce.
21860 If STRING has fewer characters than FIELD_WIDTH, pad to the right
21861 with spaces. If STRING has more characters, more than FIELD_WIDTH
21862 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
21864 PRECISION is the maximum number of characters to output from
21865 STRING. PRECISION < 0 means don't truncate the string.
21867 This is roughly equivalent to printf format specifiers:
21869 FIELD_WIDTH PRECISION PRINTF
21870 ----------------------------------------
21876 MULTIBYTE zero means do not display multibyte chars, > 0 means do
21877 display them, and < 0 means obey the current buffer's value of
21878 enable_multibyte_characters.
21880 Value is the number of columns displayed. */
21883 display_string (const char *string
, Lisp_Object lisp_string
, Lisp_Object face_string
,
21884 ptrdiff_t face_string_pos
, ptrdiff_t start
, struct it
*it
,
21885 int field_width
, int precision
, int max_x
, int multibyte
)
21887 int hpos_at_start
= it
->hpos
;
21888 int saved_face_id
= it
->face_id
;
21889 struct glyph_row
*row
= it
->glyph_row
;
21890 ptrdiff_t it_charpos
;
21892 /* Initialize the iterator IT for iteration over STRING beginning
21893 with index START. */
21894 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
21895 precision
, field_width
, multibyte
);
21896 if (string
&& STRINGP (lisp_string
))
21897 /* LISP_STRING is the one returned by decode_mode_spec. We should
21898 ignore its text properties. */
21899 it
->stop_charpos
= it
->end_charpos
;
21901 /* If displaying STRING, set up the face of the iterator from
21902 FACE_STRING, if that's given. */
21903 if (STRINGP (face_string
))
21909 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
21910 0, it
->region_beg_charpos
,
21911 it
->region_end_charpos
,
21912 &endptr
, it
->base_face_id
, 0);
21913 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21914 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
21917 /* Set max_x to the maximum allowed X position. Don't let it go
21918 beyond the right edge of the window. */
21920 max_x
= it
->last_visible_x
;
21922 max_x
= min (max_x
, it
->last_visible_x
);
21924 /* Skip over display elements that are not visible. because IT->w is
21926 if (it
->current_x
< it
->first_visible_x
)
21927 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
21928 MOVE_TO_POS
| MOVE_TO_X
);
21930 row
->ascent
= it
->max_ascent
;
21931 row
->height
= it
->max_ascent
+ it
->max_descent
;
21932 row
->phys_ascent
= it
->max_phys_ascent
;
21933 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
21934 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
21936 if (STRINGP (it
->string
))
21937 it_charpos
= IT_STRING_CHARPOS (*it
);
21939 it_charpos
= IT_CHARPOS (*it
);
21941 /* This condition is for the case that we are called with current_x
21942 past last_visible_x. */
21943 while (it
->current_x
< max_x
)
21945 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
21947 /* Get the next display element. */
21948 if (!get_next_display_element (it
))
21951 /* Produce glyphs. */
21952 x_before
= it
->current_x
;
21953 n_glyphs_before
= row
->used
[TEXT_AREA
];
21954 PRODUCE_GLYPHS (it
);
21956 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
21959 while (i
< nglyphs
)
21961 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
21963 if (it
->line_wrap
!= TRUNCATE
21964 && x
+ glyph
->pixel_width
> max_x
)
21966 /* End of continued line or max_x reached. */
21967 if (CHAR_GLYPH_PADDING_P (*glyph
))
21969 /* A wide character is unbreakable. */
21970 if (row
->reversed_p
)
21971 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
21972 - n_glyphs_before
);
21973 row
->used
[TEXT_AREA
] = n_glyphs_before
;
21974 it
->current_x
= x_before
;
21978 if (row
->reversed_p
)
21979 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
21980 - (n_glyphs_before
+ i
));
21981 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
21986 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
21988 /* Glyph is at least partially visible. */
21990 if (x
< it
->first_visible_x
)
21991 row
->x
= x
- it
->first_visible_x
;
21995 /* Glyph is off the left margin of the display area.
21996 Should not happen. */
22000 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
22001 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
22002 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
22003 row
->phys_height
= max (row
->phys_height
,
22004 it
->max_phys_ascent
+ it
->max_phys_descent
);
22005 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
22006 it
->max_extra_line_spacing
);
22007 x
+= glyph
->pixel_width
;
22011 /* Stop if max_x reached. */
22015 /* Stop at line ends. */
22016 if (ITERATOR_AT_END_OF_LINE_P (it
))
22018 it
->continuation_lines_width
= 0;
22022 set_iterator_to_next (it
, 1);
22023 if (STRINGP (it
->string
))
22024 it_charpos
= IT_STRING_CHARPOS (*it
);
22026 it_charpos
= IT_CHARPOS (*it
);
22028 /* Stop if truncating at the right edge. */
22029 if (it
->line_wrap
== TRUNCATE
22030 && it
->current_x
>= it
->last_visible_x
)
22032 /* Add truncation mark, but don't do it if the line is
22033 truncated at a padding space. */
22034 if (it_charpos
< it
->string_nchars
)
22036 if (!FRAME_WINDOW_P (it
->f
))
22040 if (it
->current_x
> it
->last_visible_x
)
22042 if (!row
->reversed_p
)
22044 for (ii
= row
->used
[TEXT_AREA
] - 1; ii
> 0; --ii
)
22045 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
22050 for (ii
= 0; ii
< row
->used
[TEXT_AREA
]; ii
++)
22051 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
22053 unproduce_glyphs (it
, ii
+ 1);
22054 ii
= row
->used
[TEXT_AREA
] - (ii
+ 1);
22056 for (n
= row
->used
[TEXT_AREA
]; ii
< n
; ++ii
)
22058 row
->used
[TEXT_AREA
] = ii
;
22059 produce_special_glyphs (it
, IT_TRUNCATION
);
22062 produce_special_glyphs (it
, IT_TRUNCATION
);
22064 row
->truncated_on_right_p
= 1;
22070 /* Maybe insert a truncation at the left. */
22071 if (it
->first_visible_x
22074 if (!FRAME_WINDOW_P (it
->f
)
22075 || (row
->reversed_p
22076 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
22077 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
22078 insert_left_trunc_glyphs (it
);
22079 row
->truncated_on_left_p
= 1;
22082 it
->face_id
= saved_face_id
;
22084 /* Value is number of columns displayed. */
22085 return it
->hpos
- hpos_at_start
;
22090 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
22091 appears as an element of LIST or as the car of an element of LIST.
22092 If PROPVAL is a list, compare each element against LIST in that
22093 way, and return 1/2 if any element of PROPVAL is found in LIST.
22094 Otherwise return 0. This function cannot quit.
22095 The return value is 2 if the text is invisible but with an ellipsis
22096 and 1 if it's invisible and without an ellipsis. */
22099 invisible_p (register Lisp_Object propval
, Lisp_Object list
)
22101 register Lisp_Object tail
, proptail
;
22103 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
22105 register Lisp_Object tem
;
22107 if (EQ (propval
, tem
))
22109 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
22110 return NILP (XCDR (tem
)) ? 1 : 2;
22113 if (CONSP (propval
))
22115 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
22117 Lisp_Object propelt
;
22118 propelt
= XCAR (proptail
);
22119 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
22121 register Lisp_Object tem
;
22123 if (EQ (propelt
, tem
))
22125 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
22126 return NILP (XCDR (tem
)) ? 1 : 2;
22134 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
22135 doc
: /* Non-nil if the property makes the text invisible.
22136 POS-OR-PROP can be a marker or number, in which case it is taken to be
22137 a position in the current buffer and the value of the `invisible' property
22138 is checked; or it can be some other value, which is then presumed to be the
22139 value of the `invisible' property of the text of interest.
22140 The non-nil value returned can be t for truly invisible text or something
22141 else if the text is replaced by an ellipsis. */)
22142 (Lisp_Object pos_or_prop
)
22145 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
22146 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
22148 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
22149 return (invis
== 0 ? Qnil
22151 : make_number (invis
));
22154 /* Calculate a width or height in pixels from a specification using
22155 the following elements:
22158 NUM - a (fractional) multiple of the default font width/height
22159 (NUM) - specifies exactly NUM pixels
22160 UNIT - a fixed number of pixels, see below.
22161 ELEMENT - size of a display element in pixels, see below.
22162 (NUM . SPEC) - equals NUM * SPEC
22163 (+ SPEC SPEC ...) - add pixel values
22164 (- SPEC SPEC ...) - subtract pixel values
22165 (- SPEC) - negate pixel value
22168 INT or FLOAT - a number constant
22169 SYMBOL - use symbol's (buffer local) variable binding.
22172 in - pixels per inch *)
22173 mm - pixels per 1/1000 meter *)
22174 cm - pixels per 1/100 meter *)
22175 width - width of current font in pixels.
22176 height - height of current font in pixels.
22178 *) using the ratio(s) defined in display-pixels-per-inch.
22182 left-fringe - left fringe width in pixels
22183 right-fringe - right fringe width in pixels
22185 left-margin - left margin width in pixels
22186 right-margin - right margin width in pixels
22188 scroll-bar - scroll-bar area width in pixels
22192 Pixels corresponding to 5 inches:
22195 Total width of non-text areas on left side of window (if scroll-bar is on left):
22196 '(space :width (+ left-fringe left-margin scroll-bar))
22198 Align to first text column (in header line):
22199 '(space :align-to 0)
22201 Align to middle of text area minus half the width of variable `my-image'
22202 containing a loaded image:
22203 '(space :align-to (0.5 . (- text my-image)))
22205 Width of left margin minus width of 1 character in the default font:
22206 '(space :width (- left-margin 1))
22208 Width of left margin minus width of 2 characters in the current font:
22209 '(space :width (- left-margin (2 . width)))
22211 Center 1 character over left-margin (in header line):
22212 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
22214 Different ways to express width of left fringe plus left margin minus one pixel:
22215 '(space :width (- (+ left-fringe left-margin) (1)))
22216 '(space :width (+ left-fringe left-margin (- (1))))
22217 '(space :width (+ left-fringe left-margin (-1)))
22221 #define NUMVAL(X) \
22222 ((INTEGERP (X) || FLOATP (X)) \
22227 calc_pixel_width_or_height (double *res
, struct it
*it
, Lisp_Object prop
,
22228 struct font
*font
, int width_p
, int *align_to
)
22232 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
22233 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
22236 return OK_PIXELS (0);
22238 eassert (FRAME_LIVE_P (it
->f
));
22240 if (SYMBOLP (prop
))
22242 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
22244 char *unit
= SSDATA (SYMBOL_NAME (prop
));
22246 if (unit
[0] == 'i' && unit
[1] == 'n')
22248 else if (unit
[0] == 'm' && unit
[1] == 'm')
22250 else if (unit
[0] == 'c' && unit
[1] == 'm')
22257 #ifdef HAVE_WINDOW_SYSTEM
22258 if (FRAME_WINDOW_P (it
->f
)
22260 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
22261 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
22263 return OK_PIXELS (ppi
/ pixels
);
22266 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
22267 || (CONSP (Vdisplay_pixels_per_inch
)
22269 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
22270 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
22272 return OK_PIXELS (ppi
/ pixels
);
22278 #ifdef HAVE_WINDOW_SYSTEM
22279 if (EQ (prop
, Qheight
))
22280 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
22281 if (EQ (prop
, Qwidth
))
22282 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
22284 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
22285 return OK_PIXELS (1);
22288 if (EQ (prop
, Qtext
))
22289 return OK_PIXELS (width_p
22290 ? window_box_width (it
->w
, TEXT_AREA
)
22291 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
22293 if (align_to
&& *align_to
< 0)
22296 if (EQ (prop
, Qleft
))
22297 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
22298 if (EQ (prop
, Qright
))
22299 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
22300 if (EQ (prop
, Qcenter
))
22301 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
22302 + window_box_width (it
->w
, TEXT_AREA
) / 2);
22303 if (EQ (prop
, Qleft_fringe
))
22304 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22305 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
22306 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
22307 if (EQ (prop
, Qright_fringe
))
22308 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22309 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
22310 : window_box_right_offset (it
->w
, TEXT_AREA
));
22311 if (EQ (prop
, Qleft_margin
))
22312 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
22313 if (EQ (prop
, Qright_margin
))
22314 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
22315 if (EQ (prop
, Qscroll_bar
))
22316 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
22318 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
22319 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22320 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
22325 if (EQ (prop
, Qleft_fringe
))
22326 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
22327 if (EQ (prop
, Qright_fringe
))
22328 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
22329 if (EQ (prop
, Qleft_margin
))
22330 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
22331 if (EQ (prop
, Qright_margin
))
22332 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
22333 if (EQ (prop
, Qscroll_bar
))
22334 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
22337 prop
= buffer_local_value_1 (prop
, it
->w
->buffer
);
22338 if (EQ (prop
, Qunbound
))
22342 if (INTEGERP (prop
) || FLOATP (prop
))
22344 int base_unit
= (width_p
22345 ? FRAME_COLUMN_WIDTH (it
->f
)
22346 : FRAME_LINE_HEIGHT (it
->f
));
22347 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
22352 Lisp_Object car
= XCAR (prop
);
22353 Lisp_Object cdr
= XCDR (prop
);
22357 #ifdef HAVE_WINDOW_SYSTEM
22358 if (FRAME_WINDOW_P (it
->f
)
22359 && valid_image_p (prop
))
22361 ptrdiff_t id
= lookup_image (it
->f
, prop
);
22362 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
22364 return OK_PIXELS (width_p
? img
->width
: img
->height
);
22367 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
22373 while (CONSP (cdr
))
22375 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
22376 font
, width_p
, align_to
))
22379 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
22384 if (EQ (car
, Qminus
))
22386 return OK_PIXELS (pixels
);
22389 car
= buffer_local_value_1 (car
, it
->w
->buffer
);
22390 if (EQ (car
, Qunbound
))
22394 if (INTEGERP (car
) || FLOATP (car
))
22397 pixels
= XFLOATINT (car
);
22399 return OK_PIXELS (pixels
);
22400 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
22401 font
, width_p
, align_to
))
22402 return OK_PIXELS (pixels
* fact
);
22413 /***********************************************************************
22415 ***********************************************************************/
22417 #ifdef HAVE_WINDOW_SYSTEM
22422 dump_glyph_string (struct glyph_string
*s
)
22424 fprintf (stderr
, "glyph string\n");
22425 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
22426 s
->x
, s
->y
, s
->width
, s
->height
);
22427 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
22428 fprintf (stderr
, " hl = %d\n", s
->hl
);
22429 fprintf (stderr
, " left overhang = %d, right = %d\n",
22430 s
->left_overhang
, s
->right_overhang
);
22431 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
22432 fprintf (stderr
, " extends to end of line = %d\n",
22433 s
->extends_to_end_of_line_p
);
22434 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
22435 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
22438 #endif /* GLYPH_DEBUG */
22440 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
22441 of XChar2b structures for S; it can't be allocated in
22442 init_glyph_string because it must be allocated via `alloca'. W
22443 is the window on which S is drawn. ROW and AREA are the glyph row
22444 and area within the row from which S is constructed. START is the
22445 index of the first glyph structure covered by S. HL is a
22446 face-override for drawing S. */
22449 #define OPTIONAL_HDC(hdc) HDC hdc,
22450 #define DECLARE_HDC(hdc) HDC hdc;
22451 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
22452 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
22455 #ifndef OPTIONAL_HDC
22456 #define OPTIONAL_HDC(hdc)
22457 #define DECLARE_HDC(hdc)
22458 #define ALLOCATE_HDC(hdc, f)
22459 #define RELEASE_HDC(hdc, f)
22463 init_glyph_string (struct glyph_string
*s
,
22465 XChar2b
*char2b
, struct window
*w
, struct glyph_row
*row
,
22466 enum glyph_row_area area
, int start
, enum draw_glyphs_face hl
)
22468 memset (s
, 0, sizeof *s
);
22470 s
->f
= XFRAME (w
->frame
);
22474 s
->display
= FRAME_X_DISPLAY (s
->f
);
22475 s
->window
= FRAME_X_WINDOW (s
->f
);
22476 s
->char2b
= char2b
;
22480 s
->first_glyph
= row
->glyphs
[area
] + start
;
22481 s
->height
= row
->height
;
22482 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
22483 s
->ybase
= s
->y
+ row
->ascent
;
22487 /* Append the list of glyph strings with head H and tail T to the list
22488 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
22491 append_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
22492 struct glyph_string
*h
, struct glyph_string
*t
)
22506 /* Prepend the list of glyph strings with head H and tail T to the
22507 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
22511 prepend_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
22512 struct glyph_string
*h
, struct glyph_string
*t
)
22526 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
22527 Set *HEAD and *TAIL to the resulting list. */
22530 append_glyph_string (struct glyph_string
**head
, struct glyph_string
**tail
,
22531 struct glyph_string
*s
)
22533 s
->next
= s
->prev
= NULL
;
22534 append_glyph_string_lists (head
, tail
, s
, s
);
22538 /* Get face and two-byte form of character C in face FACE_ID on frame F.
22539 The encoding of C is returned in *CHAR2B. DISPLAY_P non-zero means
22540 make sure that X resources for the face returned are allocated.
22541 Value is a pointer to a realized face that is ready for display if
22542 DISPLAY_P is non-zero. */
22544 static inline struct face
*
22545 get_char_face_and_encoding (struct frame
*f
, int c
, int face_id
,
22546 XChar2b
*char2b
, int display_p
)
22548 struct face
*face
= FACE_FROM_ID (f
, face_id
);
22552 unsigned code
= face
->font
->driver
->encode_char (face
->font
, c
);
22554 if (code
!= FONT_INVALID_CODE
)
22555 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22557 STORE_XCHAR2B (char2b
, 0, 0);
22560 /* Make sure X resources of the face are allocated. */
22561 #ifdef HAVE_X_WINDOWS
22565 eassert (face
!= NULL
);
22566 PREPARE_FACE_FOR_DISPLAY (f
, face
);
22573 /* Get face and two-byte form of character glyph GLYPH on frame F.
22574 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
22575 a pointer to a realized face that is ready for display. */
22577 static inline struct face
*
22578 get_glyph_face_and_encoding (struct frame
*f
, struct glyph
*glyph
,
22579 XChar2b
*char2b
, int *two_byte_p
)
22583 eassert (glyph
->type
== CHAR_GLYPH
);
22584 face
= FACE_FROM_ID (f
, glyph
->face_id
);
22593 if (CHAR_BYTE8_P (glyph
->u
.ch
))
22594 code
= CHAR_TO_BYTE8 (glyph
->u
.ch
);
22596 code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
22598 if (code
!= FONT_INVALID_CODE
)
22599 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22601 STORE_XCHAR2B (char2b
, 0, 0);
22604 /* Make sure X resources of the face are allocated. */
22605 eassert (face
!= NULL
);
22606 PREPARE_FACE_FOR_DISPLAY (f
, face
);
22611 /* Get glyph code of character C in FONT in the two-byte form CHAR2B.
22612 Return 1 if FONT has a glyph for C, otherwise return 0. */
22615 get_char_glyph_code (int c
, struct font
*font
, XChar2b
*char2b
)
22619 if (CHAR_BYTE8_P (c
))
22620 code
= CHAR_TO_BYTE8 (c
);
22622 code
= font
->driver
->encode_char (font
, c
);
22624 if (code
== FONT_INVALID_CODE
)
22626 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22631 /* Fill glyph string S with composition components specified by S->cmp.
22633 BASE_FACE is the base face of the composition.
22634 S->cmp_from is the index of the first component for S.
22636 OVERLAPS non-zero means S should draw the foreground only, and use
22637 its physical height for clipping. See also draw_glyphs.
22639 Value is the index of a component not in S. */
22642 fill_composite_glyph_string (struct glyph_string
*s
, struct face
*base_face
,
22646 /* For all glyphs of this composition, starting at the offset
22647 S->cmp_from, until we reach the end of the definition or encounter a
22648 glyph that requires the different face, add it to S. */
22653 s
->for_overlaps
= overlaps
;
22656 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
22658 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
22660 /* TAB in a composition means display glyphs with padding space
22661 on the left or right. */
22664 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
22667 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
22674 s
->font
= s
->face
->font
;
22676 else if (s
->face
!= face
)
22684 if (s
->face
== NULL
)
22686 s
->face
= base_face
->ascii_face
;
22687 s
->font
= s
->face
->font
;
22690 /* All glyph strings for the same composition has the same width,
22691 i.e. the width set for the first component of the composition. */
22692 s
->width
= s
->first_glyph
->pixel_width
;
22694 /* If the specified font could not be loaded, use the frame's
22695 default font, but record the fact that we couldn't load it in
22696 the glyph string so that we can draw rectangles for the
22697 characters of the glyph string. */
22698 if (s
->font
== NULL
)
22700 s
->font_not_found_p
= 1;
22701 s
->font
= FRAME_FONT (s
->f
);
22704 /* Adjust base line for subscript/superscript text. */
22705 s
->ybase
+= s
->first_glyph
->voffset
;
22707 /* This glyph string must always be drawn with 16-bit functions. */
22714 fill_gstring_glyph_string (struct glyph_string
*s
, int face_id
,
22715 int start
, int end
, int overlaps
)
22717 struct glyph
*glyph
, *last
;
22718 Lisp_Object lgstring
;
22721 s
->for_overlaps
= overlaps
;
22722 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22723 last
= s
->row
->glyphs
[s
->area
] + end
;
22724 s
->cmp_id
= glyph
->u
.cmp
.id
;
22725 s
->cmp_from
= glyph
->slice
.cmp
.from
;
22726 s
->cmp_to
= glyph
->slice
.cmp
.to
+ 1;
22727 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
22728 lgstring
= composition_gstring_from_id (s
->cmp_id
);
22729 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
22731 while (glyph
< last
22732 && glyph
->u
.cmp
.automatic
22733 && glyph
->u
.cmp
.id
== s
->cmp_id
22734 && s
->cmp_to
== glyph
->slice
.cmp
.from
)
22735 s
->cmp_to
= (glyph
++)->slice
.cmp
.to
+ 1;
22737 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
22739 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
22740 unsigned code
= LGLYPH_CODE (lglyph
);
22742 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
22744 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
22745 return glyph
- s
->row
->glyphs
[s
->area
];
22749 /* Fill glyph string S from a sequence glyphs for glyphless characters.
22750 See the comment of fill_glyph_string for arguments.
22751 Value is the index of the first glyph not in S. */
22755 fill_glyphless_glyph_string (struct glyph_string
*s
, int face_id
,
22756 int start
, int end
, int overlaps
)
22758 struct glyph
*glyph
, *last
;
22761 eassert (s
->first_glyph
->type
== GLYPHLESS_GLYPH
);
22762 s
->for_overlaps
= overlaps
;
22763 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22764 last
= s
->row
->glyphs
[s
->area
] + end
;
22765 voffset
= glyph
->voffset
;
22766 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
22767 s
->font
= s
->face
->font
? s
->face
->font
: FRAME_FONT (s
->f
);
22769 s
->width
= glyph
->pixel_width
;
22771 while (glyph
< last
22772 && glyph
->type
== GLYPHLESS_GLYPH
22773 && glyph
->voffset
== voffset
22774 && glyph
->face_id
== face_id
)
22777 s
->width
+= glyph
->pixel_width
;
22780 s
->ybase
+= voffset
;
22781 return glyph
- s
->row
->glyphs
[s
->area
];
22785 /* Fill glyph string S from a sequence of character glyphs.
22787 FACE_ID is the face id of the string. START is the index of the
22788 first glyph to consider, END is the index of the last + 1.
22789 OVERLAPS non-zero means S should draw the foreground only, and use
22790 its physical height for clipping. See also draw_glyphs.
22792 Value is the index of the first glyph not in S. */
22795 fill_glyph_string (struct glyph_string
*s
, int face_id
,
22796 int start
, int end
, int overlaps
)
22798 struct glyph
*glyph
, *last
;
22800 int glyph_not_available_p
;
22802 eassert (s
->f
== XFRAME (s
->w
->frame
));
22803 eassert (s
->nchars
== 0);
22804 eassert (start
>= 0 && end
> start
);
22806 s
->for_overlaps
= overlaps
;
22807 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22808 last
= s
->row
->glyphs
[s
->area
] + end
;
22809 voffset
= glyph
->voffset
;
22810 s
->padding_p
= glyph
->padding_p
;
22811 glyph_not_available_p
= glyph
->glyph_not_available_p
;
22813 while (glyph
< last
22814 && glyph
->type
== CHAR_GLYPH
22815 && glyph
->voffset
== voffset
22816 /* Same face id implies same font, nowadays. */
22817 && glyph
->face_id
== face_id
22818 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
22822 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
22823 s
->char2b
+ s
->nchars
,
22825 s
->two_byte_p
= two_byte_p
;
22827 eassert (s
->nchars
<= end
- start
);
22828 s
->width
+= glyph
->pixel_width
;
22829 if (glyph
++->padding_p
!= s
->padding_p
)
22833 s
->font
= s
->face
->font
;
22835 /* If the specified font could not be loaded, use the frame's font,
22836 but record the fact that we couldn't load it in
22837 S->font_not_found_p so that we can draw rectangles for the
22838 characters of the glyph string. */
22839 if (s
->font
== NULL
|| glyph_not_available_p
)
22841 s
->font_not_found_p
= 1;
22842 s
->font
= FRAME_FONT (s
->f
);
22845 /* Adjust base line for subscript/superscript text. */
22846 s
->ybase
+= voffset
;
22848 eassert (s
->face
&& s
->face
->gc
);
22849 return glyph
- s
->row
->glyphs
[s
->area
];
22853 /* Fill glyph string S from image glyph S->first_glyph. */
22856 fill_image_glyph_string (struct glyph_string
*s
)
22858 eassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
22859 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
22861 s
->slice
= s
->first_glyph
->slice
.img
;
22862 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
22863 s
->font
= s
->face
->font
;
22864 s
->width
= s
->first_glyph
->pixel_width
;
22866 /* Adjust base line for subscript/superscript text. */
22867 s
->ybase
+= s
->first_glyph
->voffset
;
22871 /* Fill glyph string S from a sequence of stretch glyphs.
22873 START is the index of the first glyph to consider,
22874 END is the index of the last + 1.
22876 Value is the index of the first glyph not in S. */
22879 fill_stretch_glyph_string (struct glyph_string
*s
, int start
, int end
)
22881 struct glyph
*glyph
, *last
;
22882 int voffset
, face_id
;
22884 eassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
22886 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22887 last
= s
->row
->glyphs
[s
->area
] + end
;
22888 face_id
= glyph
->face_id
;
22889 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
22890 s
->font
= s
->face
->font
;
22891 s
->width
= glyph
->pixel_width
;
22893 voffset
= glyph
->voffset
;
22897 && glyph
->type
== STRETCH_GLYPH
22898 && glyph
->voffset
== voffset
22899 && glyph
->face_id
== face_id
);
22901 s
->width
+= glyph
->pixel_width
;
22903 /* Adjust base line for subscript/superscript text. */
22904 s
->ybase
+= voffset
;
22906 /* The case that face->gc == 0 is handled when drawing the glyph
22907 string by calling PREPARE_FACE_FOR_DISPLAY. */
22909 return glyph
- s
->row
->glyphs
[s
->area
];
22912 static struct font_metrics
*
22913 get_per_char_metric (struct font
*font
, XChar2b
*char2b
)
22915 static struct font_metrics metrics
;
22916 unsigned code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
22918 if (! font
|| code
== FONT_INVALID_CODE
)
22920 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
22925 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
22926 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
22927 assumed to be zero. */
22930 x_get_glyph_overhangs (struct glyph
*glyph
, struct frame
*f
, int *left
, int *right
)
22932 *left
= *right
= 0;
22934 if (glyph
->type
== CHAR_GLYPH
)
22938 struct font_metrics
*pcm
;
22940 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
22941 if (face
->font
&& (pcm
= get_per_char_metric (face
->font
, &char2b
)))
22943 if (pcm
->rbearing
> pcm
->width
)
22944 *right
= pcm
->rbearing
- pcm
->width
;
22945 if (pcm
->lbearing
< 0)
22946 *left
= -pcm
->lbearing
;
22949 else if (glyph
->type
== COMPOSITE_GLYPH
)
22951 if (! glyph
->u
.cmp
.automatic
)
22953 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
22955 if (cmp
->rbearing
> cmp
->pixel_width
)
22956 *right
= cmp
->rbearing
- cmp
->pixel_width
;
22957 if (cmp
->lbearing
< 0)
22958 *left
= - cmp
->lbearing
;
22962 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
22963 struct font_metrics metrics
;
22965 composition_gstring_width (gstring
, glyph
->slice
.cmp
.from
,
22966 glyph
->slice
.cmp
.to
+ 1, &metrics
);
22967 if (metrics
.rbearing
> metrics
.width
)
22968 *right
= metrics
.rbearing
- metrics
.width
;
22969 if (metrics
.lbearing
< 0)
22970 *left
= - metrics
.lbearing
;
22976 /* Return the index of the first glyph preceding glyph string S that
22977 is overwritten by S because of S's left overhang. Value is -1
22978 if no glyphs are overwritten. */
22981 left_overwritten (struct glyph_string
*s
)
22985 if (s
->left_overhang
)
22988 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
22989 int first
= s
->first_glyph
- glyphs
;
22991 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
22992 x
-= glyphs
[i
].pixel_width
;
23003 /* Return the index of the first glyph preceding glyph string S that
23004 is overwriting S because of its right overhang. Value is -1 if no
23005 glyph in front of S overwrites S. */
23008 left_overwriting (struct glyph_string
*s
)
23011 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23012 int first
= s
->first_glyph
- glyphs
;
23016 for (i
= first
- 1; i
>= 0; --i
)
23019 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
23022 x
-= glyphs
[i
].pixel_width
;
23029 /* Return the index of the last glyph following glyph string S that is
23030 overwritten by S because of S's right overhang. Value is -1 if
23031 no such glyph is found. */
23034 right_overwritten (struct glyph_string
*s
)
23038 if (s
->right_overhang
)
23041 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23042 int first
= (s
->first_glyph
- glyphs
23043 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
23044 int end
= s
->row
->used
[s
->area
];
23046 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
23047 x
+= glyphs
[i
].pixel_width
;
23056 /* Return the index of the last glyph following glyph string S that
23057 overwrites S because of its left overhang. Value is negative
23058 if no such glyph is found. */
23061 right_overwriting (struct glyph_string
*s
)
23064 int end
= s
->row
->used
[s
->area
];
23065 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23066 int first
= (s
->first_glyph
- glyphs
23067 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
23071 for (i
= first
; i
< end
; ++i
)
23074 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
23077 x
+= glyphs
[i
].pixel_width
;
23084 /* Set background width of glyph string S. START is the index of the
23085 first glyph following S. LAST_X is the right-most x-position + 1
23086 in the drawing area. */
23089 set_glyph_string_background_width (struct glyph_string
*s
, int start
, int last_x
)
23091 /* If the face of this glyph string has to be drawn to the end of
23092 the drawing area, set S->extends_to_end_of_line_p. */
23094 if (start
== s
->row
->used
[s
->area
]
23095 && s
->area
== TEXT_AREA
23096 && ((s
->row
->fill_line_p
23097 && (s
->hl
== DRAW_NORMAL_TEXT
23098 || s
->hl
== DRAW_IMAGE_RAISED
23099 || s
->hl
== DRAW_IMAGE_SUNKEN
))
23100 || s
->hl
== DRAW_MOUSE_FACE
))
23101 s
->extends_to_end_of_line_p
= 1;
23103 /* If S extends its face to the end of the line, set its
23104 background_width to the distance to the right edge of the drawing
23106 if (s
->extends_to_end_of_line_p
)
23107 s
->background_width
= last_x
- s
->x
+ 1;
23109 s
->background_width
= s
->width
;
23113 /* Compute overhangs and x-positions for glyph string S and its
23114 predecessors, or successors. X is the starting x-position for S.
23115 BACKWARD_P non-zero means process predecessors. */
23118 compute_overhangs_and_x (struct glyph_string
*s
, int x
, int backward_p
)
23124 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
23125 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
23135 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
23136 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
23146 /* The following macros are only called from draw_glyphs below.
23147 They reference the following parameters of that function directly:
23148 `w', `row', `area', and `overlap_p'
23149 as well as the following local variables:
23150 `s', `f', and `hdc' (in W32) */
23153 /* On W32, silently add local `hdc' variable to argument list of
23154 init_glyph_string. */
23155 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
23156 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
23158 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
23159 init_glyph_string (s, char2b, w, row, area, start, hl)
23162 /* Add a glyph string for a stretch glyph to the list of strings
23163 between HEAD and TAIL. START is the index of the stretch glyph in
23164 row area AREA of glyph row ROW. END is the index of the last glyph
23165 in that glyph row area. X is the current output position assigned
23166 to the new glyph string constructed. HL overrides that face of the
23167 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
23168 is the right-most x-position of the drawing area. */
23170 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
23171 and below -- keep them on one line. */
23172 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23175 s = alloca (sizeof *s); \
23176 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23177 START = fill_stretch_glyph_string (s, START, END); \
23178 append_glyph_string (&HEAD, &TAIL, s); \
23184 /* Add a glyph string for an image glyph to the list of strings
23185 between HEAD and TAIL. START is the index of the image glyph in
23186 row area AREA of glyph row ROW. END is the index of the last glyph
23187 in that glyph row area. X is the current output position assigned
23188 to the new glyph string constructed. HL overrides that face of the
23189 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
23190 is the right-most x-position of the drawing area. */
23192 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23195 s = alloca (sizeof *s); \
23196 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23197 fill_image_glyph_string (s); \
23198 append_glyph_string (&HEAD, &TAIL, s); \
23205 /* Add a glyph string for a sequence of character glyphs to the list
23206 of strings between HEAD and TAIL. START is the index of the first
23207 glyph in row area AREA of glyph row ROW that is part of the new
23208 glyph string. END is the index of the last glyph in that glyph row
23209 area. X is the current output position assigned to the new glyph
23210 string constructed. HL overrides that face of the glyph; e.g. it
23211 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
23212 right-most x-position of the drawing area. */
23214 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
23220 face_id = (row)->glyphs[area][START].face_id; \
23222 s = alloca (sizeof *s); \
23223 char2b = alloca ((END - START) * sizeof *char2b); \
23224 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23225 append_glyph_string (&HEAD, &TAIL, s); \
23227 START = fill_glyph_string (s, face_id, START, END, overlaps); \
23232 /* Add a glyph string for a composite sequence to the list of strings
23233 between HEAD and TAIL. START is the index of the first glyph in
23234 row area AREA of glyph row ROW that is part of the new glyph
23235 string. END is the index of the last glyph in that glyph row area.
23236 X is the current output position assigned to the new glyph string
23237 constructed. HL overrides that face of the glyph; e.g. it is
23238 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
23239 x-position of the drawing area. */
23241 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23243 int face_id = (row)->glyphs[area][START].face_id; \
23244 struct face *base_face = FACE_FROM_ID (f, face_id); \
23245 ptrdiff_t cmp_id = (row)->glyphs[area][START].u.cmp.id; \
23246 struct composition *cmp = composition_table[cmp_id]; \
23248 struct glyph_string *first_s = NULL; \
23251 char2b = alloca (cmp->glyph_len * sizeof *char2b); \
23253 /* Make glyph_strings for each glyph sequence that is drawable by \
23254 the same face, and append them to HEAD/TAIL. */ \
23255 for (n = 0; n < cmp->glyph_len;) \
23257 s = alloca (sizeof *s); \
23258 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23259 append_glyph_string (&(HEAD), &(TAIL), s); \
23265 n = fill_composite_glyph_string (s, base_face, overlaps); \
23273 /* Add a glyph string for a glyph-string sequence to the list of strings
23274 between HEAD and TAIL. */
23276 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23280 Lisp_Object gstring; \
23282 face_id = (row)->glyphs[area][START].face_id; \
23283 gstring = (composition_gstring_from_id \
23284 ((row)->glyphs[area][START].u.cmp.id)); \
23285 s = alloca (sizeof *s); \
23286 char2b = alloca (LGSTRING_GLYPH_LEN (gstring) * sizeof *char2b); \
23287 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23288 append_glyph_string (&(HEAD), &(TAIL), s); \
23290 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
23294 /* Add a glyph string for a sequence of glyphless character's glyphs
23295 to the list of strings between HEAD and TAIL. The meanings of
23296 arguments are the same as those of BUILD_CHAR_GLYPH_STRINGS. */
23298 #define BUILD_GLYPHLESS_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23303 face_id = (row)->glyphs[area][START].face_id; \
23305 s = alloca (sizeof *s); \
23306 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23307 append_glyph_string (&HEAD, &TAIL, s); \
23309 START = fill_glyphless_glyph_string (s, face_id, START, END, \
23315 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
23316 of AREA of glyph row ROW on window W between indices START and END.
23317 HL overrides the face for drawing glyph strings, e.g. it is
23318 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
23319 x-positions of the drawing area.
23321 This is an ugly monster macro construct because we must use alloca
23322 to allocate glyph strings (because draw_glyphs can be called
23323 asynchronously). */
23325 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
23328 HEAD = TAIL = NULL; \
23329 while (START < END) \
23331 struct glyph *first_glyph = (row)->glyphs[area] + START; \
23332 switch (first_glyph->type) \
23335 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
23339 case COMPOSITE_GLYPH: \
23340 if (first_glyph->u.cmp.automatic) \
23341 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
23344 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
23348 case STRETCH_GLYPH: \
23349 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
23353 case IMAGE_GLYPH: \
23354 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
23358 case GLYPHLESS_GLYPH: \
23359 BUILD_GLYPHLESS_GLYPH_STRING (START, END, HEAD, TAIL, \
23369 set_glyph_string_background_width (s, START, LAST_X); \
23376 /* Draw glyphs between START and END in AREA of ROW on window W,
23377 starting at x-position X. X is relative to AREA in W. HL is a
23378 face-override with the following meaning:
23380 DRAW_NORMAL_TEXT draw normally
23381 DRAW_CURSOR draw in cursor face
23382 DRAW_MOUSE_FACE draw in mouse face.
23383 DRAW_INVERSE_VIDEO draw in mode line face
23384 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
23385 DRAW_IMAGE_RAISED draw an image with a raised relief around it
23387 If OVERLAPS is non-zero, draw only the foreground of characters and
23388 clip to the physical height of ROW. Non-zero value also defines
23389 the overlapping part to be drawn:
23391 OVERLAPS_PRED overlap with preceding rows
23392 OVERLAPS_SUCC overlap with succeeding rows
23393 OVERLAPS_BOTH overlap with both preceding/succeeding rows
23394 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
23396 Value is the x-position reached, relative to AREA of W. */
23399 draw_glyphs (struct window
*w
, int x
, struct glyph_row
*row
,
23400 enum glyph_row_area area
, ptrdiff_t start
, ptrdiff_t end
,
23401 enum draw_glyphs_face hl
, int overlaps
)
23403 struct glyph_string
*head
, *tail
;
23404 struct glyph_string
*s
;
23405 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
23406 int i
, j
, x_reached
, last_x
, area_left
= 0;
23407 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
23410 ALLOCATE_HDC (hdc
, f
);
23412 /* Let's rather be paranoid than getting a SEGV. */
23413 end
= min (end
, row
->used
[area
]);
23414 start
= max (0, start
);
23415 start
= min (end
, start
);
23417 /* Translate X to frame coordinates. Set last_x to the right
23418 end of the drawing area. */
23419 if (row
->full_width_p
)
23421 /* X is relative to the left edge of W, without scroll bars
23423 area_left
= WINDOW_LEFT_EDGE_X (w
);
23424 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
23428 area_left
= window_box_left (w
, area
);
23429 last_x
= area_left
+ window_box_width (w
, area
);
23433 /* Build a doubly-linked list of glyph_string structures between
23434 head and tail from what we have to draw. Note that the macro
23435 BUILD_GLYPH_STRINGS will modify its start parameter. That's
23436 the reason we use a separate variable `i'. */
23438 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
23440 x_reached
= tail
->x
+ tail
->background_width
;
23444 /* If there are any glyphs with lbearing < 0 or rbearing > width in
23445 the row, redraw some glyphs in front or following the glyph
23446 strings built above. */
23447 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
23449 struct glyph_string
*h
, *t
;
23450 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
23451 int mouse_beg_col
IF_LINT (= 0), mouse_end_col
IF_LINT (= 0);
23452 int check_mouse_face
= 0;
23455 /* If mouse highlighting is on, we may need to draw adjacent
23456 glyphs using mouse-face highlighting. */
23457 if (area
== TEXT_AREA
&& row
->mouse_face_p
)
23459 struct glyph_row
*mouse_beg_row
, *mouse_end_row
;
23461 mouse_beg_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
23462 mouse_end_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
23464 if (row
>= mouse_beg_row
&& row
<= mouse_end_row
)
23466 check_mouse_face
= 1;
23467 mouse_beg_col
= (row
== mouse_beg_row
)
23468 ? hlinfo
->mouse_face_beg_col
: 0;
23469 mouse_end_col
= (row
== mouse_end_row
)
23470 ? hlinfo
->mouse_face_end_col
23471 : row
->used
[TEXT_AREA
];
23475 /* Compute overhangs for all glyph strings. */
23476 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
23477 for (s
= head
; s
; s
= s
->next
)
23478 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
23480 /* Prepend glyph strings for glyphs in front of the first glyph
23481 string that are overwritten because of the first glyph
23482 string's left overhang. The background of all strings
23483 prepended must be drawn because the first glyph string
23485 i
= left_overwritten (head
);
23488 enum draw_glyphs_face overlap_hl
;
23490 /* If this row contains mouse highlighting, attempt to draw
23491 the overlapped glyphs with the correct highlight. This
23492 code fails if the overlap encompasses more than one glyph
23493 and mouse-highlight spans only some of these glyphs.
23494 However, making it work perfectly involves a lot more
23495 code, and I don't know if the pathological case occurs in
23496 practice, so we'll stick to this for now. --- cyd */
23497 if (check_mouse_face
23498 && mouse_beg_col
< start
&& mouse_end_col
> i
)
23499 overlap_hl
= DRAW_MOUSE_FACE
;
23501 overlap_hl
= DRAW_NORMAL_TEXT
;
23504 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
23505 overlap_hl
, dummy_x
, last_x
);
23507 compute_overhangs_and_x (t
, head
->x
, 1);
23508 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
23512 /* Prepend glyph strings for glyphs in front of the first glyph
23513 string that overwrite that glyph string because of their
23514 right overhang. For these strings, only the foreground must
23515 be drawn, because it draws over the glyph string at `head'.
23516 The background must not be drawn because this would overwrite
23517 right overhangs of preceding glyphs for which no glyph
23519 i
= left_overwriting (head
);
23522 enum draw_glyphs_face overlap_hl
;
23524 if (check_mouse_face
23525 && mouse_beg_col
< start
&& mouse_end_col
> i
)
23526 overlap_hl
= DRAW_MOUSE_FACE
;
23528 overlap_hl
= DRAW_NORMAL_TEXT
;
23531 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
23532 overlap_hl
, dummy_x
, last_x
);
23533 for (s
= h
; s
; s
= s
->next
)
23534 s
->background_filled_p
= 1;
23535 compute_overhangs_and_x (t
, head
->x
, 1);
23536 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
23539 /* Append glyphs strings for glyphs following the last glyph
23540 string tail that are overwritten by tail. The background of
23541 these strings has to be drawn because tail's foreground draws
23543 i
= right_overwritten (tail
);
23546 enum draw_glyphs_face overlap_hl
;
23548 if (check_mouse_face
23549 && mouse_beg_col
< i
&& mouse_end_col
> end
)
23550 overlap_hl
= DRAW_MOUSE_FACE
;
23552 overlap_hl
= DRAW_NORMAL_TEXT
;
23554 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
23555 overlap_hl
, x
, last_x
);
23556 /* Because BUILD_GLYPH_STRINGS updates the first argument,
23557 we don't have `end = i;' here. */
23558 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
23559 append_glyph_string_lists (&head
, &tail
, h
, t
);
23563 /* Append glyph strings for glyphs following the last glyph
23564 string tail that overwrite tail. The foreground of such
23565 glyphs has to be drawn because it writes into the background
23566 of tail. The background must not be drawn because it could
23567 paint over the foreground of following glyphs. */
23568 i
= right_overwriting (tail
);
23571 enum draw_glyphs_face overlap_hl
;
23572 if (check_mouse_face
23573 && mouse_beg_col
< i
&& mouse_end_col
> end
)
23574 overlap_hl
= DRAW_MOUSE_FACE
;
23576 overlap_hl
= DRAW_NORMAL_TEXT
;
23579 i
++; /* We must include the Ith glyph. */
23580 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
23581 overlap_hl
, x
, last_x
);
23582 for (s
= h
; s
; s
= s
->next
)
23583 s
->background_filled_p
= 1;
23584 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
23585 append_glyph_string_lists (&head
, &tail
, h
, t
);
23587 if (clip_head
|| clip_tail
)
23588 for (s
= head
; s
; s
= s
->next
)
23590 s
->clip_head
= clip_head
;
23591 s
->clip_tail
= clip_tail
;
23595 /* Draw all strings. */
23596 for (s
= head
; s
; s
= s
->next
)
23597 FRAME_RIF (f
)->draw_glyph_string (s
);
23600 /* When focus a sole frame and move horizontally, this sets on_p to 0
23601 causing a failure to erase prev cursor position. */
23602 if (area
== TEXT_AREA
23603 && !row
->full_width_p
23604 /* When drawing overlapping rows, only the glyph strings'
23605 foreground is drawn, which doesn't erase a cursor
23609 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
23610 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
23611 : (tail
? tail
->x
+ tail
->background_width
: x
));
23615 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
23616 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
23620 /* Value is the x-position up to which drawn, relative to AREA of W.
23621 This doesn't include parts drawn because of overhangs. */
23622 if (row
->full_width_p
)
23623 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
23625 x_reached
-= area_left
;
23627 RELEASE_HDC (hdc
, f
);
23632 /* Expand row matrix if too narrow. Don't expand if area
23635 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
23637 if (!fonts_changed_p \
23638 && (it->glyph_row->glyphs[area] \
23639 < it->glyph_row->glyphs[area + 1])) \
23641 it->w->ncols_scale_factor++; \
23642 fonts_changed_p = 1; \
23646 /* Store one glyph for IT->char_to_display in IT->glyph_row.
23647 Called from x_produce_glyphs when IT->glyph_row is non-null. */
23650 append_glyph (struct it
*it
)
23652 struct glyph
*glyph
;
23653 enum glyph_row_area area
= it
->area
;
23655 eassert (it
->glyph_row
);
23656 eassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
23658 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23659 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23661 /* If the glyph row is reversed, we need to prepend the glyph
23662 rather than append it. */
23663 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23667 /* Make room for the additional glyph. */
23668 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
23670 glyph
= it
->glyph_row
->glyphs
[area
];
23672 glyph
->charpos
= CHARPOS (it
->position
);
23673 glyph
->object
= it
->object
;
23674 if (it
->pixel_width
> 0)
23676 glyph
->pixel_width
= it
->pixel_width
;
23677 glyph
->padding_p
= 0;
23681 /* Assure at least 1-pixel width. Otherwise, cursor can't
23682 be displayed correctly. */
23683 glyph
->pixel_width
= 1;
23684 glyph
->padding_p
= 1;
23686 glyph
->ascent
= it
->ascent
;
23687 glyph
->descent
= it
->descent
;
23688 glyph
->voffset
= it
->voffset
;
23689 glyph
->type
= CHAR_GLYPH
;
23690 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23691 glyph
->multibyte_p
= it
->multibyte_p
;
23692 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23693 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23694 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
23695 || it
->phys_descent
> it
->descent
);
23696 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
23697 glyph
->face_id
= it
->face_id
;
23698 glyph
->u
.ch
= it
->char_to_display
;
23699 glyph
->slice
.img
= null_glyph_slice
;
23700 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23703 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23704 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23706 glyph
->bidi_type
= it
->bidi_it
.type
;
23710 glyph
->resolved_level
= 0;
23711 glyph
->bidi_type
= UNKNOWN_BT
;
23713 ++it
->glyph_row
->used
[area
];
23716 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23719 /* Store one glyph for the composition IT->cmp_it.id in
23720 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
23724 append_composite_glyph (struct it
*it
)
23726 struct glyph
*glyph
;
23727 enum glyph_row_area area
= it
->area
;
23729 eassert (it
->glyph_row
);
23731 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23732 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23734 /* If the glyph row is reversed, we need to prepend the glyph
23735 rather than append it. */
23736 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
23740 /* Make room for the new glyph. */
23741 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
23743 glyph
= it
->glyph_row
->glyphs
[it
->area
];
23745 glyph
->charpos
= it
->cmp_it
.charpos
;
23746 glyph
->object
= it
->object
;
23747 glyph
->pixel_width
= it
->pixel_width
;
23748 glyph
->ascent
= it
->ascent
;
23749 glyph
->descent
= it
->descent
;
23750 glyph
->voffset
= it
->voffset
;
23751 glyph
->type
= COMPOSITE_GLYPH
;
23752 if (it
->cmp_it
.ch
< 0)
23754 glyph
->u
.cmp
.automatic
= 0;
23755 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
23756 glyph
->slice
.cmp
.from
= glyph
->slice
.cmp
.to
= 0;
23760 glyph
->u
.cmp
.automatic
= 1;
23761 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
23762 glyph
->slice
.cmp
.from
= it
->cmp_it
.from
;
23763 glyph
->slice
.cmp
.to
= it
->cmp_it
.to
- 1;
23765 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23766 glyph
->multibyte_p
= it
->multibyte_p
;
23767 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23768 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23769 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
23770 || it
->phys_descent
> it
->descent
);
23771 glyph
->padding_p
= 0;
23772 glyph
->glyph_not_available_p
= 0;
23773 glyph
->face_id
= it
->face_id
;
23774 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23777 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23778 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23780 glyph
->bidi_type
= it
->bidi_it
.type
;
23782 ++it
->glyph_row
->used
[area
];
23785 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23789 /* Change IT->ascent and IT->height according to the setting of
23793 take_vertical_position_into_account (struct it
*it
)
23797 if (it
->voffset
< 0)
23798 /* Increase the ascent so that we can display the text higher
23800 it
->ascent
-= it
->voffset
;
23802 /* Increase the descent so that we can display the text lower
23804 it
->descent
+= it
->voffset
;
23809 /* Produce glyphs/get display metrics for the image IT is loaded with.
23810 See the description of struct display_iterator in dispextern.h for
23811 an overview of struct display_iterator. */
23814 produce_image_glyph (struct it
*it
)
23818 int glyph_ascent
, crop
;
23819 struct glyph_slice slice
;
23821 eassert (it
->what
== IT_IMAGE
);
23823 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
23825 /* Make sure X resources of the face is loaded. */
23826 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
23828 if (it
->image_id
< 0)
23830 /* Fringe bitmap. */
23831 it
->ascent
= it
->phys_ascent
= 0;
23832 it
->descent
= it
->phys_descent
= 0;
23833 it
->pixel_width
= 0;
23838 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
23840 /* Make sure X resources of the image is loaded. */
23841 prepare_image_for_display (it
->f
, img
);
23843 slice
.x
= slice
.y
= 0;
23844 slice
.width
= img
->width
;
23845 slice
.height
= img
->height
;
23847 if (INTEGERP (it
->slice
.x
))
23848 slice
.x
= XINT (it
->slice
.x
);
23849 else if (FLOATP (it
->slice
.x
))
23850 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
23852 if (INTEGERP (it
->slice
.y
))
23853 slice
.y
= XINT (it
->slice
.y
);
23854 else if (FLOATP (it
->slice
.y
))
23855 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
23857 if (INTEGERP (it
->slice
.width
))
23858 slice
.width
= XINT (it
->slice
.width
);
23859 else if (FLOATP (it
->slice
.width
))
23860 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
23862 if (INTEGERP (it
->slice
.height
))
23863 slice
.height
= XINT (it
->slice
.height
);
23864 else if (FLOATP (it
->slice
.height
))
23865 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
23867 if (slice
.x
>= img
->width
)
23868 slice
.x
= img
->width
;
23869 if (slice
.y
>= img
->height
)
23870 slice
.y
= img
->height
;
23871 if (slice
.x
+ slice
.width
>= img
->width
)
23872 slice
.width
= img
->width
- slice
.x
;
23873 if (slice
.y
+ slice
.height
> img
->height
)
23874 slice
.height
= img
->height
- slice
.y
;
23876 if (slice
.width
== 0 || slice
.height
== 0)
23879 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
23881 it
->descent
= slice
.height
- glyph_ascent
;
23883 it
->descent
+= img
->vmargin
;
23884 if (slice
.y
+ slice
.height
== img
->height
)
23885 it
->descent
+= img
->vmargin
;
23886 it
->phys_descent
= it
->descent
;
23888 it
->pixel_width
= slice
.width
;
23890 it
->pixel_width
+= img
->hmargin
;
23891 if (slice
.x
+ slice
.width
== img
->width
)
23892 it
->pixel_width
+= img
->hmargin
;
23894 /* It's quite possible for images to have an ascent greater than
23895 their height, so don't get confused in that case. */
23896 if (it
->descent
< 0)
23901 if (face
->box
!= FACE_NO_BOX
)
23903 if (face
->box_line_width
> 0)
23906 it
->ascent
+= face
->box_line_width
;
23907 if (slice
.y
+ slice
.height
== img
->height
)
23908 it
->descent
+= face
->box_line_width
;
23911 if (it
->start_of_box_run_p
&& slice
.x
== 0)
23912 it
->pixel_width
+= eabs (face
->box_line_width
);
23913 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
23914 it
->pixel_width
+= eabs (face
->box_line_width
);
23917 take_vertical_position_into_account (it
);
23919 /* Automatically crop wide image glyphs at right edge so we can
23920 draw the cursor on same display row. */
23921 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
23922 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
23924 it
->pixel_width
-= crop
;
23925 slice
.width
-= crop
;
23930 struct glyph
*glyph
;
23931 enum glyph_row_area area
= it
->area
;
23933 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23934 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23936 glyph
->charpos
= CHARPOS (it
->position
);
23937 glyph
->object
= it
->object
;
23938 glyph
->pixel_width
= it
->pixel_width
;
23939 glyph
->ascent
= glyph_ascent
;
23940 glyph
->descent
= it
->descent
;
23941 glyph
->voffset
= it
->voffset
;
23942 glyph
->type
= IMAGE_GLYPH
;
23943 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23944 glyph
->multibyte_p
= it
->multibyte_p
;
23945 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23946 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23947 glyph
->overlaps_vertically_p
= 0;
23948 glyph
->padding_p
= 0;
23949 glyph
->glyph_not_available_p
= 0;
23950 glyph
->face_id
= it
->face_id
;
23951 glyph
->u
.img_id
= img
->id
;
23952 glyph
->slice
.img
= slice
;
23953 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23956 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23957 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23959 glyph
->bidi_type
= it
->bidi_it
.type
;
23961 ++it
->glyph_row
->used
[area
];
23964 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23969 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
23970 of the glyph, WIDTH and HEIGHT are the width and height of the
23971 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
23974 append_stretch_glyph (struct it
*it
, Lisp_Object object
,
23975 int width
, int height
, int ascent
)
23977 struct glyph
*glyph
;
23978 enum glyph_row_area area
= it
->area
;
23980 eassert (ascent
>= 0 && ascent
<= height
);
23982 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23983 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23985 /* If the glyph row is reversed, we need to prepend the glyph
23986 rather than append it. */
23987 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23991 /* Make room for the additional glyph. */
23992 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
23994 glyph
= it
->glyph_row
->glyphs
[area
];
23996 glyph
->charpos
= CHARPOS (it
->position
);
23997 glyph
->object
= object
;
23998 glyph
->pixel_width
= width
;
23999 glyph
->ascent
= ascent
;
24000 glyph
->descent
= height
- ascent
;
24001 glyph
->voffset
= it
->voffset
;
24002 glyph
->type
= STRETCH_GLYPH
;
24003 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24004 glyph
->multibyte_p
= it
->multibyte_p
;
24005 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24006 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24007 glyph
->overlaps_vertically_p
= 0;
24008 glyph
->padding_p
= 0;
24009 glyph
->glyph_not_available_p
= 0;
24010 glyph
->face_id
= it
->face_id
;
24011 glyph
->u
.stretch
.ascent
= ascent
;
24012 glyph
->u
.stretch
.height
= height
;
24013 glyph
->slice
.img
= null_glyph_slice
;
24014 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24017 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24018 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24020 glyph
->bidi_type
= it
->bidi_it
.type
;
24024 glyph
->resolved_level
= 0;
24025 glyph
->bidi_type
= UNKNOWN_BT
;
24027 ++it
->glyph_row
->used
[area
];
24030 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24033 #endif /* HAVE_WINDOW_SYSTEM */
24035 /* Produce a stretch glyph for iterator IT. IT->object is the value
24036 of the glyph property displayed. The value must be a list
24037 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
24040 1. `:width WIDTH' specifies that the space should be WIDTH *
24041 canonical char width wide. WIDTH may be an integer or floating
24044 2. `:relative-width FACTOR' specifies that the width of the stretch
24045 should be computed from the width of the first character having the
24046 `glyph' property, and should be FACTOR times that width.
24048 3. `:align-to HPOS' specifies that the space should be wide enough
24049 to reach HPOS, a value in canonical character units.
24051 Exactly one of the above pairs must be present.
24053 4. `:height HEIGHT' specifies that the height of the stretch produced
24054 should be HEIGHT, measured in canonical character units.
24056 5. `:relative-height FACTOR' specifies that the height of the
24057 stretch should be FACTOR times the height of the characters having
24058 the glyph property.
24060 Either none or exactly one of 4 or 5 must be present.
24062 6. `:ascent ASCENT' specifies that ASCENT percent of the height
24063 of the stretch should be used for the ascent of the stretch.
24064 ASCENT must be in the range 0 <= ASCENT <= 100. */
24067 produce_stretch_glyph (struct it
*it
)
24069 /* (space :width WIDTH :height HEIGHT ...) */
24070 Lisp_Object prop
, plist
;
24071 int width
= 0, height
= 0, align_to
= -1;
24072 int zero_width_ok_p
= 0;
24075 struct face
*face
= NULL
;
24076 struct font
*font
= NULL
;
24078 #ifdef HAVE_WINDOW_SYSTEM
24079 int zero_height_ok_p
= 0;
24081 if (FRAME_WINDOW_P (it
->f
))
24083 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24084 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24085 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24089 /* List should start with `space'. */
24090 eassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
24091 plist
= XCDR (it
->object
);
24093 /* Compute the width of the stretch. */
24094 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
24095 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
24097 /* Absolute width `:width WIDTH' specified and valid. */
24098 zero_width_ok_p
= 1;
24101 #ifdef HAVE_WINDOW_SYSTEM
24102 else if (FRAME_WINDOW_P (it
->f
)
24103 && (prop
= Fplist_get (plist
, QCrelative_width
), NUMVAL (prop
) > 0))
24105 /* Relative width `:relative-width FACTOR' specified and valid.
24106 Compute the width of the characters having the `glyph'
24109 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
24112 if (it
->multibyte_p
)
24113 it2
.c
= it2
.char_to_display
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
24116 it2
.c
= it2
.char_to_display
= *p
, it2
.len
= 1;
24117 if (! ASCII_CHAR_P (it2
.c
))
24118 it2
.char_to_display
= BYTE8_TO_CHAR (it2
.c
);
24121 it2
.glyph_row
= NULL
;
24122 it2
.what
= IT_CHARACTER
;
24123 x_produce_glyphs (&it2
);
24124 width
= NUMVAL (prop
) * it2
.pixel_width
;
24126 #endif /* HAVE_WINDOW_SYSTEM */
24127 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
24128 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
24130 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
24131 align_to
= (align_to
< 0
24133 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
24134 else if (align_to
< 0)
24135 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
24136 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
24137 zero_width_ok_p
= 1;
24140 /* Nothing specified -> width defaults to canonical char width. */
24141 width
= FRAME_COLUMN_WIDTH (it
->f
);
24143 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
24146 #ifdef HAVE_WINDOW_SYSTEM
24147 /* Compute height. */
24148 if (FRAME_WINDOW_P (it
->f
))
24150 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
24151 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
24154 zero_height_ok_p
= 1;
24156 else if (prop
= Fplist_get (plist
, QCrelative_height
),
24158 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
24160 height
= FONT_HEIGHT (font
);
24162 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
24165 /* Compute percentage of height used for ascent. If
24166 `:ascent ASCENT' is present and valid, use that. Otherwise,
24167 derive the ascent from the font in use. */
24168 if (prop
= Fplist_get (plist
, QCascent
),
24169 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
24170 ascent
= height
* NUMVAL (prop
) / 100.0;
24171 else if (!NILP (prop
)
24172 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
24173 ascent
= min (max (0, (int)tem
), height
);
24175 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
24178 #endif /* HAVE_WINDOW_SYSTEM */
24181 if (width
> 0 && it
->line_wrap
!= TRUNCATE
24182 && it
->current_x
+ width
> it
->last_visible_x
)
24184 width
= it
->last_visible_x
- it
->current_x
;
24185 #ifdef HAVE_WINDOW_SYSTEM
24186 /* Subtract one more pixel from the stretch width, but only on
24187 GUI frames, since on a TTY each glyph is one "pixel" wide. */
24188 width
-= FRAME_WINDOW_P (it
->f
);
24192 if (width
> 0 && height
> 0 && it
->glyph_row
)
24194 Lisp_Object o_object
= it
->object
;
24195 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
24198 if (!STRINGP (object
))
24199 object
= it
->w
->buffer
;
24200 #ifdef HAVE_WINDOW_SYSTEM
24201 if (FRAME_WINDOW_P (it
->f
))
24202 append_stretch_glyph (it
, object
, width
, height
, ascent
);
24206 it
->object
= object
;
24207 it
->char_to_display
= ' ';
24208 it
->pixel_width
= it
->len
= 1;
24210 tty_append_glyph (it
);
24211 it
->object
= o_object
;
24215 it
->pixel_width
= width
;
24216 #ifdef HAVE_WINDOW_SYSTEM
24217 if (FRAME_WINDOW_P (it
->f
))
24219 it
->ascent
= it
->phys_ascent
= ascent
;
24220 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
24221 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
24222 take_vertical_position_into_account (it
);
24226 it
->nglyphs
= width
;
24229 /* Get information about special display element WHAT in an
24230 environment described by IT. WHAT is one of IT_TRUNCATION or
24231 IT_CONTINUATION. Maybe produce glyphs for WHAT if IT has a
24232 non-null glyph_row member. This function ensures that fields like
24233 face_id, c, len of IT are left untouched. */
24236 produce_special_glyphs (struct it
*it
, enum display_element_type what
)
24243 temp_it
.object
= make_number (0);
24244 memset (&temp_it
.current
, 0, sizeof temp_it
.current
);
24246 if (what
== IT_CONTINUATION
)
24248 /* Continuation glyph. For R2L lines, we mirror it by hand. */
24249 if (it
->bidi_it
.paragraph_dir
== R2L
)
24250 SET_GLYPH_FROM_CHAR (glyph
, '/');
24252 SET_GLYPH_FROM_CHAR (glyph
, '\\');
24254 && (gc
= DISP_CONTINUE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
24256 /* FIXME: Should we mirror GC for R2L lines? */
24257 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
24258 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
24261 else if (what
== IT_TRUNCATION
)
24263 /* Truncation glyph. */
24264 SET_GLYPH_FROM_CHAR (glyph
, '$');
24266 && (gc
= DISP_TRUNC_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
24268 /* FIXME: Should we mirror GC for R2L lines? */
24269 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
24270 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
24276 #ifdef HAVE_WINDOW_SYSTEM
24277 /* On a GUI frame, when the right fringe (left fringe for R2L rows)
24278 is turned off, we precede the truncation/continuation glyphs by a
24279 stretch glyph whose width is computed such that these special
24280 glyphs are aligned at the window margin, even when very different
24281 fonts are used in different glyph rows. */
24282 if (FRAME_WINDOW_P (temp_it
.f
)
24283 /* init_iterator calls this with it->glyph_row == NULL, and it
24284 wants only the pixel width of the truncation/continuation
24286 && temp_it
.glyph_row
24287 /* insert_left_trunc_glyphs calls us at the beginning of the
24288 row, and it has its own calculation of the stretch glyph
24290 && temp_it
.glyph_row
->used
[TEXT_AREA
] > 0
24291 && (temp_it
.glyph_row
->reversed_p
24292 ? WINDOW_LEFT_FRINGE_WIDTH (temp_it
.w
)
24293 : WINDOW_RIGHT_FRINGE_WIDTH (temp_it
.w
)) == 0)
24295 int stretch_width
= temp_it
.last_visible_x
- temp_it
.current_x
;
24297 if (stretch_width
> 0)
24299 struct face
*face
= FACE_FROM_ID (temp_it
.f
, temp_it
.face_id
);
24300 struct font
*font
=
24301 face
->font
? face
->font
: FRAME_FONT (temp_it
.f
);
24302 int stretch_ascent
=
24303 (((temp_it
.ascent
+ temp_it
.descent
)
24304 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
24306 append_stretch_glyph (&temp_it
, make_number (0), stretch_width
,
24307 temp_it
.ascent
+ temp_it
.descent
,
24314 temp_it
.what
= IT_CHARACTER
;
24316 temp_it
.c
= temp_it
.char_to_display
= GLYPH_CHAR (glyph
);
24317 temp_it
.face_id
= GLYPH_FACE (glyph
);
24318 temp_it
.len
= CHAR_BYTES (temp_it
.c
);
24320 PRODUCE_GLYPHS (&temp_it
);
24321 it
->pixel_width
= temp_it
.pixel_width
;
24322 it
->nglyphs
= temp_it
.pixel_width
;
24325 #ifdef HAVE_WINDOW_SYSTEM
24327 /* Calculate line-height and line-spacing properties.
24328 An integer value specifies explicit pixel value.
24329 A float value specifies relative value to current face height.
24330 A cons (float . face-name) specifies relative value to
24331 height of specified face font.
24333 Returns height in pixels, or nil. */
24337 calc_line_height_property (struct it
*it
, Lisp_Object val
, struct font
*font
,
24338 int boff
, int override
)
24340 Lisp_Object face_name
= Qnil
;
24341 int ascent
, descent
, height
;
24343 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
24348 face_name
= XCAR (val
);
24350 if (!NUMBERP (val
))
24351 val
= make_number (1);
24352 if (NILP (face_name
))
24354 height
= it
->ascent
+ it
->descent
;
24359 if (NILP (face_name
))
24361 font
= FRAME_FONT (it
->f
);
24362 boff
= FRAME_BASELINE_OFFSET (it
->f
);
24364 else if (EQ (face_name
, Qt
))
24373 face_id
= lookup_named_face (it
->f
, face_name
, 0);
24375 return make_number (-1);
24377 face
= FACE_FROM_ID (it
->f
, face_id
);
24380 return make_number (-1);
24381 boff
= font
->baseline_offset
;
24382 if (font
->vertical_centering
)
24383 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
24386 ascent
= FONT_BASE (font
) + boff
;
24387 descent
= FONT_DESCENT (font
) - boff
;
24391 it
->override_ascent
= ascent
;
24392 it
->override_descent
= descent
;
24393 it
->override_boff
= boff
;
24396 height
= ascent
+ descent
;
24400 height
= (int)(XFLOAT_DATA (val
) * height
);
24401 else if (INTEGERP (val
))
24402 height
*= XINT (val
);
24404 return make_number (height
);
24408 /* Append a glyph for a glyphless character to IT->glyph_row. FACE_ID
24409 is a face ID to be used for the glyph. FOR_NO_FONT is nonzero if
24410 and only if this is for a character for which no font was found.
24412 If the display method (it->glyphless_method) is
24413 GLYPHLESS_DISPLAY_ACRONYM or GLYPHLESS_DISPLAY_HEX_CODE, LEN is a
24414 length of the acronym or the hexadecimal string, UPPER_XOFF and
24415 UPPER_YOFF are pixel offsets for the upper part of the string,
24416 LOWER_XOFF and LOWER_YOFF are for the lower part.
24418 For the other display methods, LEN through LOWER_YOFF are zero. */
24421 append_glyphless_glyph (struct it
*it
, int face_id
, int for_no_font
, int len
,
24422 short upper_xoff
, short upper_yoff
,
24423 short lower_xoff
, short lower_yoff
)
24425 struct glyph
*glyph
;
24426 enum glyph_row_area area
= it
->area
;
24428 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24429 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24431 /* If the glyph row is reversed, we need to prepend the glyph
24432 rather than append it. */
24433 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24437 /* Make room for the additional glyph. */
24438 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
24440 glyph
= it
->glyph_row
->glyphs
[area
];
24442 glyph
->charpos
= CHARPOS (it
->position
);
24443 glyph
->object
= it
->object
;
24444 glyph
->pixel_width
= it
->pixel_width
;
24445 glyph
->ascent
= it
->ascent
;
24446 glyph
->descent
= it
->descent
;
24447 glyph
->voffset
= it
->voffset
;
24448 glyph
->type
= GLYPHLESS_GLYPH
;
24449 glyph
->u
.glyphless
.method
= it
->glyphless_method
;
24450 glyph
->u
.glyphless
.for_no_font
= for_no_font
;
24451 glyph
->u
.glyphless
.len
= len
;
24452 glyph
->u
.glyphless
.ch
= it
->c
;
24453 glyph
->slice
.glyphless
.upper_xoff
= upper_xoff
;
24454 glyph
->slice
.glyphless
.upper_yoff
= upper_yoff
;
24455 glyph
->slice
.glyphless
.lower_xoff
= lower_xoff
;
24456 glyph
->slice
.glyphless
.lower_yoff
= lower_yoff
;
24457 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24458 glyph
->multibyte_p
= it
->multibyte_p
;
24459 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24460 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24461 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
24462 || it
->phys_descent
> it
->descent
);
24463 glyph
->padding_p
= 0;
24464 glyph
->glyph_not_available_p
= 0;
24465 glyph
->face_id
= face_id
;
24466 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24469 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24470 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24472 glyph
->bidi_type
= it
->bidi_it
.type
;
24474 ++it
->glyph_row
->used
[area
];
24477 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24481 /* Produce a glyph for a glyphless character for iterator IT.
24482 IT->glyphless_method specifies which method to use for displaying
24483 the character. See the description of enum
24484 glyphless_display_method in dispextern.h for the detail.
24486 FOR_NO_FONT is nonzero if and only if this is for a character for
24487 which no font was found. ACRONYM, if non-nil, is an acronym string
24488 for the character. */
24491 produce_glyphless_glyph (struct it
*it
, int for_no_font
, Lisp_Object acronym
)
24496 int base_width
, base_height
, width
, height
;
24497 short upper_xoff
, upper_yoff
, lower_xoff
, lower_yoff
;
24500 /* Get the metrics of the base font. We always refer to the current
24502 face
= FACE_FROM_ID (it
->f
, it
->face_id
)->ascii_face
;
24503 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24504 it
->ascent
= FONT_BASE (font
) + font
->baseline_offset
;
24505 it
->descent
= FONT_DESCENT (font
) - font
->baseline_offset
;
24506 base_height
= it
->ascent
+ it
->descent
;
24507 base_width
= font
->average_width
;
24509 /* Get a face ID for the glyph by utilizing a cache (the same way as
24510 done for `escape-glyph' in get_next_display_element). */
24511 if (it
->f
== last_glyphless_glyph_frame
24512 && it
->face_id
== last_glyphless_glyph_face_id
)
24514 face_id
= last_glyphless_glyph_merged_face_id
;
24518 /* Merge the `glyphless-char' face into the current face. */
24519 face_id
= merge_faces (it
->f
, Qglyphless_char
, 0, it
->face_id
);
24520 last_glyphless_glyph_frame
= it
->f
;
24521 last_glyphless_glyph_face_id
= it
->face_id
;
24522 last_glyphless_glyph_merged_face_id
= face_id
;
24525 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_THIN_SPACE
)
24527 it
->pixel_width
= THIN_SPACE_WIDTH
;
24529 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
24531 else if (it
->glyphless_method
== GLYPHLESS_DISPLAY_EMPTY_BOX
)
24533 width
= CHAR_WIDTH (it
->c
);
24536 else if (width
> 4)
24538 it
->pixel_width
= base_width
* width
;
24540 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
24546 unsigned int code
[6];
24548 int ascent
, descent
;
24549 struct font_metrics metrics_upper
, metrics_lower
;
24551 face
= FACE_FROM_ID (it
->f
, face_id
);
24552 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24553 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24555 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_ACRONYM
)
24557 if (! STRINGP (acronym
) && CHAR_TABLE_P (Vglyphless_char_display
))
24558 acronym
= CHAR_TABLE_REF (Vglyphless_char_display
, it
->c
);
24559 if (CONSP (acronym
))
24560 acronym
= XCAR (acronym
);
24561 str
= STRINGP (acronym
) ? SSDATA (acronym
) : "";
24565 eassert (it
->glyphless_method
== GLYPHLESS_DISPLAY_HEX_CODE
);
24566 sprintf (buf
, "%0*X", it
->c
< 0x10000 ? 4 : 6, it
->c
);
24569 for (len
= 0; str
[len
] && ASCII_BYTE_P (str
[len
]) && len
< 6; len
++)
24570 code
[len
] = font
->driver
->encode_char (font
, str
[len
]);
24571 upper_len
= (len
+ 1) / 2;
24572 font
->driver
->text_extents (font
, code
, upper_len
,
24574 font
->driver
->text_extents (font
, code
+ upper_len
, len
- upper_len
,
24579 /* +4 is for vertical bars of a box plus 1-pixel spaces at both side. */
24580 width
= max (metrics_upper
.width
, metrics_lower
.width
) + 4;
24581 upper_xoff
= upper_yoff
= 2; /* the typical case */
24582 if (base_width
>= width
)
24584 /* Align the upper to the left, the lower to the right. */
24585 it
->pixel_width
= base_width
;
24586 lower_xoff
= base_width
- 2 - metrics_lower
.width
;
24590 /* Center the shorter one. */
24591 it
->pixel_width
= width
;
24592 if (metrics_upper
.width
>= metrics_lower
.width
)
24593 lower_xoff
= (width
- metrics_lower
.width
) / 2;
24596 /* FIXME: This code doesn't look right. It formerly was
24597 missing the "lower_xoff = 0;", which couldn't have
24598 been right since it left lower_xoff uninitialized. */
24600 upper_xoff
= (width
- metrics_upper
.width
) / 2;
24604 /* +5 is for horizontal bars of a box plus 1-pixel spaces at
24605 top, bottom, and between upper and lower strings. */
24606 height
= (metrics_upper
.ascent
+ metrics_upper
.descent
24607 + metrics_lower
.ascent
+ metrics_lower
.descent
) + 5;
24608 /* Center vertically.
24609 H:base_height, D:base_descent
24610 h:height, ld:lower_descent, la:lower_ascent, ud:upper_descent
24612 ascent = - (D - H/2 - h/2 + 1); "+ 1" for rounding up
24613 descent = D - H/2 + h/2;
24614 lower_yoff = descent - 2 - ld;
24615 upper_yoff = lower_yoff - la - 1 - ud; */
24616 ascent
= - (it
->descent
- (base_height
+ height
+ 1) / 2);
24617 descent
= it
->descent
- (base_height
- height
) / 2;
24618 lower_yoff
= descent
- 2 - metrics_lower
.descent
;
24619 upper_yoff
= (lower_yoff
- metrics_lower
.ascent
- 1
24620 - metrics_upper
.descent
);
24621 /* Don't make the height shorter than the base height. */
24622 if (height
> base_height
)
24624 it
->ascent
= ascent
;
24625 it
->descent
= descent
;
24629 it
->phys_ascent
= it
->ascent
;
24630 it
->phys_descent
= it
->descent
;
24632 append_glyphless_glyph (it
, face_id
, for_no_font
, len
,
24633 upper_xoff
, upper_yoff
,
24634 lower_xoff
, lower_yoff
);
24636 take_vertical_position_into_account (it
);
24641 Produce glyphs/get display metrics for the display element IT is
24642 loaded with. See the description of struct it in dispextern.h
24643 for an overview of struct it. */
24646 x_produce_glyphs (struct it
*it
)
24648 int extra_line_spacing
= it
->extra_line_spacing
;
24650 it
->glyph_not_available_p
= 0;
24652 if (it
->what
== IT_CHARACTER
)
24655 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24656 struct font
*font
= face
->font
;
24657 struct font_metrics
*pcm
= NULL
;
24658 int boff
; /* baseline offset */
24662 /* When no suitable font is found, display this character by
24663 the method specified in the first extra slot of
24664 Vglyphless_char_display. */
24665 Lisp_Object acronym
= lookup_glyphless_char_display (-1, it
);
24667 eassert (it
->what
== IT_GLYPHLESS
);
24668 produce_glyphless_glyph (it
, 1, STRINGP (acronym
) ? acronym
: Qnil
);
24672 boff
= font
->baseline_offset
;
24673 if (font
->vertical_centering
)
24674 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
24676 if (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t')
24682 if (it
->override_ascent
>= 0)
24684 it
->ascent
= it
->override_ascent
;
24685 it
->descent
= it
->override_descent
;
24686 boff
= it
->override_boff
;
24690 it
->ascent
= FONT_BASE (font
) + boff
;
24691 it
->descent
= FONT_DESCENT (font
) - boff
;
24694 if (get_char_glyph_code (it
->char_to_display
, font
, &char2b
))
24696 pcm
= get_per_char_metric (font
, &char2b
);
24697 if (pcm
->width
== 0
24698 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
24704 it
->phys_ascent
= pcm
->ascent
+ boff
;
24705 it
->phys_descent
= pcm
->descent
- boff
;
24706 it
->pixel_width
= pcm
->width
;
24710 it
->glyph_not_available_p
= 1;
24711 it
->phys_ascent
= it
->ascent
;
24712 it
->phys_descent
= it
->descent
;
24713 it
->pixel_width
= font
->space_width
;
24716 if (it
->constrain_row_ascent_descent_p
)
24718 if (it
->descent
> it
->max_descent
)
24720 it
->ascent
+= it
->descent
- it
->max_descent
;
24721 it
->descent
= it
->max_descent
;
24723 if (it
->ascent
> it
->max_ascent
)
24725 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
24726 it
->ascent
= it
->max_ascent
;
24728 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
24729 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
24730 extra_line_spacing
= 0;
24733 /* If this is a space inside a region of text with
24734 `space-width' property, change its width. */
24735 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
24737 it
->pixel_width
*= XFLOATINT (it
->space_width
);
24739 /* If face has a box, add the box thickness to the character
24740 height. If character has a box line to the left and/or
24741 right, add the box line width to the character's width. */
24742 if (face
->box
!= FACE_NO_BOX
)
24744 int thick
= face
->box_line_width
;
24748 it
->ascent
+= thick
;
24749 it
->descent
+= thick
;
24754 if (it
->start_of_box_run_p
)
24755 it
->pixel_width
+= thick
;
24756 if (it
->end_of_box_run_p
)
24757 it
->pixel_width
+= thick
;
24760 /* If face has an overline, add the height of the overline
24761 (1 pixel) and a 1 pixel margin to the character height. */
24762 if (face
->overline_p
)
24763 it
->ascent
+= overline_margin
;
24765 if (it
->constrain_row_ascent_descent_p
)
24767 if (it
->ascent
> it
->max_ascent
)
24768 it
->ascent
= it
->max_ascent
;
24769 if (it
->descent
> it
->max_descent
)
24770 it
->descent
= it
->max_descent
;
24773 take_vertical_position_into_account (it
);
24775 /* If we have to actually produce glyphs, do it. */
24780 /* Translate a space with a `space-width' property
24781 into a stretch glyph. */
24782 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
24783 / FONT_HEIGHT (font
));
24784 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
24785 it
->ascent
+ it
->descent
, ascent
);
24790 /* If characters with lbearing or rbearing are displayed
24791 in this line, record that fact in a flag of the
24792 glyph row. This is used to optimize X output code. */
24793 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
24794 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
24796 if (! stretched_p
&& it
->pixel_width
== 0)
24797 /* We assure that all visible glyphs have at least 1-pixel
24799 it
->pixel_width
= 1;
24801 else if (it
->char_to_display
== '\n')
24803 /* A newline has no width, but we need the height of the
24804 line. But if previous part of the line sets a height,
24805 don't increase that height */
24807 Lisp_Object height
;
24808 Lisp_Object total_height
= Qnil
;
24810 it
->override_ascent
= -1;
24811 it
->pixel_width
= 0;
24814 height
= get_it_property (it
, Qline_height
);
24815 /* Split (line-height total-height) list */
24817 && CONSP (XCDR (height
))
24818 && NILP (XCDR (XCDR (height
))))
24820 total_height
= XCAR (XCDR (height
));
24821 height
= XCAR (height
);
24823 height
= calc_line_height_property (it
, height
, font
, boff
, 1);
24825 if (it
->override_ascent
>= 0)
24827 it
->ascent
= it
->override_ascent
;
24828 it
->descent
= it
->override_descent
;
24829 boff
= it
->override_boff
;
24833 it
->ascent
= FONT_BASE (font
) + boff
;
24834 it
->descent
= FONT_DESCENT (font
) - boff
;
24837 if (EQ (height
, Qt
))
24839 if (it
->descent
> it
->max_descent
)
24841 it
->ascent
+= it
->descent
- it
->max_descent
;
24842 it
->descent
= it
->max_descent
;
24844 if (it
->ascent
> it
->max_ascent
)
24846 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
24847 it
->ascent
= it
->max_ascent
;
24849 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
24850 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
24851 it
->constrain_row_ascent_descent_p
= 1;
24852 extra_line_spacing
= 0;
24856 Lisp_Object spacing
;
24858 it
->phys_ascent
= it
->ascent
;
24859 it
->phys_descent
= it
->descent
;
24861 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
24862 && face
->box
!= FACE_NO_BOX
24863 && face
->box_line_width
> 0)
24865 it
->ascent
+= face
->box_line_width
;
24866 it
->descent
+= face
->box_line_width
;
24869 && XINT (height
) > it
->ascent
+ it
->descent
)
24870 it
->ascent
= XINT (height
) - it
->descent
;
24872 if (!NILP (total_height
))
24873 spacing
= calc_line_height_property (it
, total_height
, font
, boff
, 0);
24876 spacing
= get_it_property (it
, Qline_spacing
);
24877 spacing
= calc_line_height_property (it
, spacing
, font
, boff
, 0);
24879 if (INTEGERP (spacing
))
24881 extra_line_spacing
= XINT (spacing
);
24882 if (!NILP (total_height
))
24883 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
24887 else /* i.e. (it->char_to_display == '\t') */
24889 if (font
->space_width
> 0)
24891 int tab_width
= it
->tab_width
* font
->space_width
;
24892 int x
= it
->current_x
+ it
->continuation_lines_width
;
24893 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
24895 /* If the distance from the current position to the next tab
24896 stop is less than a space character width, use the
24897 tab stop after that. */
24898 if (next_tab_x
- x
< font
->space_width
)
24899 next_tab_x
+= tab_width
;
24901 it
->pixel_width
= next_tab_x
- x
;
24903 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
24904 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
24908 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
24909 it
->ascent
+ it
->descent
, it
->ascent
);
24914 it
->pixel_width
= 0;
24919 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
24921 /* A static composition.
24923 Note: A composition is represented as one glyph in the
24924 glyph matrix. There are no padding glyphs.
24926 Important note: pixel_width, ascent, and descent are the
24927 values of what is drawn by draw_glyphs (i.e. the values of
24928 the overall glyphs composed). */
24929 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24930 int boff
; /* baseline offset */
24931 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
24932 int glyph_len
= cmp
->glyph_len
;
24933 struct font
*font
= face
->font
;
24937 /* If we have not yet calculated pixel size data of glyphs of
24938 the composition for the current face font, calculate them
24939 now. Theoretically, we have to check all fonts for the
24940 glyphs, but that requires much time and memory space. So,
24941 here we check only the font of the first glyph. This may
24942 lead to incorrect display, but it's very rare, and C-l
24943 (recenter-top-bottom) can correct the display anyway. */
24944 if (! cmp
->font
|| cmp
->font
!= font
)
24946 /* Ascent and descent of the font of the first character
24947 of this composition (adjusted by baseline offset).
24948 Ascent and descent of overall glyphs should not be less
24949 than these, respectively. */
24950 int font_ascent
, font_descent
, font_height
;
24951 /* Bounding box of the overall glyphs. */
24952 int leftmost
, rightmost
, lowest
, highest
;
24953 int lbearing
, rbearing
;
24954 int i
, width
, ascent
, descent
;
24955 int left_padded
= 0, right_padded
= 0;
24956 int c
IF_LINT (= 0); /* cmp->glyph_len can't be zero; see Bug#8512 */
24958 struct font_metrics
*pcm
;
24959 int font_not_found_p
;
24962 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
24963 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
24965 if (glyph_len
< cmp
->glyph_len
)
24967 for (i
= 0; i
< glyph_len
; i
++)
24969 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
24971 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
24976 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
24977 : IT_CHARPOS (*it
));
24978 /* If no suitable font is found, use the default font. */
24979 font_not_found_p
= font
== NULL
;
24980 if (font_not_found_p
)
24982 face
= face
->ascii_face
;
24985 boff
= font
->baseline_offset
;
24986 if (font
->vertical_centering
)
24987 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
24988 font_ascent
= FONT_BASE (font
) + boff
;
24989 font_descent
= FONT_DESCENT (font
) - boff
;
24990 font_height
= FONT_HEIGHT (font
);
24995 if (! font_not_found_p
)
24997 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
24999 pcm
= get_per_char_metric (font
, &char2b
);
25002 /* Initialize the bounding box. */
25005 width
= cmp
->glyph_len
> 0 ? pcm
->width
: 0;
25006 ascent
= pcm
->ascent
;
25007 descent
= pcm
->descent
;
25008 lbearing
= pcm
->lbearing
;
25009 rbearing
= pcm
->rbearing
;
25013 width
= cmp
->glyph_len
> 0 ? font
->space_width
: 0;
25014 ascent
= FONT_BASE (font
);
25015 descent
= FONT_DESCENT (font
);
25022 lowest
= - descent
+ boff
;
25023 highest
= ascent
+ boff
;
25025 if (! font_not_found_p
25026 && font
->default_ascent
25027 && CHAR_TABLE_P (Vuse_default_ascent
)
25028 && !NILP (Faref (Vuse_default_ascent
,
25029 make_number (it
->char_to_display
))))
25030 highest
= font
->default_ascent
+ boff
;
25032 /* Draw the first glyph at the normal position. It may be
25033 shifted to right later if some other glyphs are drawn
25035 cmp
->offsets
[i
* 2] = 0;
25036 cmp
->offsets
[i
* 2 + 1] = boff
;
25037 cmp
->lbearing
= lbearing
;
25038 cmp
->rbearing
= rbearing
;
25040 /* Set cmp->offsets for the remaining glyphs. */
25041 for (i
++; i
< glyph_len
; i
++)
25043 int left
, right
, btm
, top
;
25044 int ch
= COMPOSITION_GLYPH (cmp
, i
);
25046 struct face
*this_face
;
25050 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
25051 this_face
= FACE_FROM_ID (it
->f
, face_id
);
25052 font
= this_face
->font
;
25058 get_char_face_and_encoding (it
->f
, ch
, face_id
,
25060 pcm
= get_per_char_metric (font
, &char2b
);
25063 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
25066 width
= pcm
->width
;
25067 ascent
= pcm
->ascent
;
25068 descent
= pcm
->descent
;
25069 lbearing
= pcm
->lbearing
;
25070 rbearing
= pcm
->rbearing
;
25071 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
25073 /* Relative composition with or without
25074 alternate chars. */
25075 left
= (leftmost
+ rightmost
- width
) / 2;
25076 btm
= - descent
+ boff
;
25077 if (font
->relative_compose
25078 && (! CHAR_TABLE_P (Vignore_relative_composition
)
25079 || NILP (Faref (Vignore_relative_composition
,
25080 make_number (ch
)))))
25083 if (- descent
>= font
->relative_compose
)
25084 /* One extra pixel between two glyphs. */
25086 else if (ascent
<= 0)
25087 /* One extra pixel between two glyphs. */
25088 btm
= lowest
- 1 - ascent
- descent
;
25093 /* A composition rule is specified by an integer
25094 value that encodes global and new reference
25095 points (GREF and NREF). GREF and NREF are
25096 specified by numbers as below:
25098 0---1---2 -- ascent
25102 9--10--11 -- center
25104 ---3---4---5--- baseline
25106 6---7---8 -- descent
25108 int rule
= COMPOSITION_RULE (cmp
, i
);
25109 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
25111 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
25112 grefx
= gref
% 3, nrefx
= nref
% 3;
25113 grefy
= gref
/ 3, nrefy
= nref
/ 3;
25115 xoff
= font_height
* (xoff
- 128) / 256;
25117 yoff
= font_height
* (yoff
- 128) / 256;
25120 + grefx
* (rightmost
- leftmost
) / 2
25121 - nrefx
* width
/ 2
25124 btm
= ((grefy
== 0 ? highest
25126 : grefy
== 2 ? lowest
25127 : (highest
+ lowest
) / 2)
25128 - (nrefy
== 0 ? ascent
+ descent
25129 : nrefy
== 1 ? descent
- boff
25131 : (ascent
+ descent
) / 2)
25135 cmp
->offsets
[i
* 2] = left
;
25136 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
25138 /* Update the bounding box of the overall glyphs. */
25141 right
= left
+ width
;
25142 if (left
< leftmost
)
25144 if (right
> rightmost
)
25147 top
= btm
+ descent
+ ascent
;
25153 if (cmp
->lbearing
> left
+ lbearing
)
25154 cmp
->lbearing
= left
+ lbearing
;
25155 if (cmp
->rbearing
< left
+ rbearing
)
25156 cmp
->rbearing
= left
+ rbearing
;
25160 /* If there are glyphs whose x-offsets are negative,
25161 shift all glyphs to the right and make all x-offsets
25165 for (i
= 0; i
< cmp
->glyph_len
; i
++)
25166 cmp
->offsets
[i
* 2] -= leftmost
;
25167 rightmost
-= leftmost
;
25168 cmp
->lbearing
-= leftmost
;
25169 cmp
->rbearing
-= leftmost
;
25172 if (left_padded
&& cmp
->lbearing
< 0)
25174 for (i
= 0; i
< cmp
->glyph_len
; i
++)
25175 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
25176 rightmost
-= cmp
->lbearing
;
25177 cmp
->rbearing
-= cmp
->lbearing
;
25180 if (right_padded
&& rightmost
< cmp
->rbearing
)
25182 rightmost
= cmp
->rbearing
;
25185 cmp
->pixel_width
= rightmost
;
25186 cmp
->ascent
= highest
;
25187 cmp
->descent
= - lowest
;
25188 if (cmp
->ascent
< font_ascent
)
25189 cmp
->ascent
= font_ascent
;
25190 if (cmp
->descent
< font_descent
)
25191 cmp
->descent
= font_descent
;
25195 && (cmp
->lbearing
< 0
25196 || cmp
->rbearing
> cmp
->pixel_width
))
25197 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25199 it
->pixel_width
= cmp
->pixel_width
;
25200 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
25201 it
->descent
= it
->phys_descent
= cmp
->descent
;
25202 if (face
->box
!= FACE_NO_BOX
)
25204 int thick
= face
->box_line_width
;
25208 it
->ascent
+= thick
;
25209 it
->descent
+= thick
;
25214 if (it
->start_of_box_run_p
)
25215 it
->pixel_width
+= thick
;
25216 if (it
->end_of_box_run_p
)
25217 it
->pixel_width
+= thick
;
25220 /* If face has an overline, add the height of the overline
25221 (1 pixel) and a 1 pixel margin to the character height. */
25222 if (face
->overline_p
)
25223 it
->ascent
+= overline_margin
;
25225 take_vertical_position_into_account (it
);
25226 if (it
->ascent
< 0)
25228 if (it
->descent
< 0)
25231 if (it
->glyph_row
&& cmp
->glyph_len
> 0)
25232 append_composite_glyph (it
);
25234 else if (it
->what
== IT_COMPOSITION
)
25236 /* A dynamic (automatic) composition. */
25237 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25238 Lisp_Object gstring
;
25239 struct font_metrics metrics
;
25243 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
25245 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
25248 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
25249 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25250 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
25251 it
->descent
= it
->phys_descent
= metrics
.descent
;
25252 if (face
->box
!= FACE_NO_BOX
)
25254 int thick
= face
->box_line_width
;
25258 it
->ascent
+= thick
;
25259 it
->descent
+= thick
;
25264 if (it
->start_of_box_run_p
)
25265 it
->pixel_width
+= thick
;
25266 if (it
->end_of_box_run_p
)
25267 it
->pixel_width
+= thick
;
25269 /* If face has an overline, add the height of the overline
25270 (1 pixel) and a 1 pixel margin to the character height. */
25271 if (face
->overline_p
)
25272 it
->ascent
+= overline_margin
;
25273 take_vertical_position_into_account (it
);
25274 if (it
->ascent
< 0)
25276 if (it
->descent
< 0)
25280 append_composite_glyph (it
);
25282 else if (it
->what
== IT_GLYPHLESS
)
25283 produce_glyphless_glyph (it
, 0, Qnil
);
25284 else if (it
->what
== IT_IMAGE
)
25285 produce_image_glyph (it
);
25286 else if (it
->what
== IT_STRETCH
)
25287 produce_stretch_glyph (it
);
25290 /* Accumulate dimensions. Note: can't assume that it->descent > 0
25291 because this isn't true for images with `:ascent 100'. */
25292 eassert (it
->ascent
>= 0 && it
->descent
>= 0);
25293 if (it
->area
== TEXT_AREA
)
25294 it
->current_x
+= it
->pixel_width
;
25296 if (extra_line_spacing
> 0)
25298 it
->descent
+= extra_line_spacing
;
25299 if (extra_line_spacing
> it
->max_extra_line_spacing
)
25300 it
->max_extra_line_spacing
= extra_line_spacing
;
25303 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
25304 it
->max_descent
= max (it
->max_descent
, it
->descent
);
25305 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
25306 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
25310 Output LEN glyphs starting at START at the nominal cursor position.
25311 Advance the nominal cursor over the text. The global variable
25312 updated_window contains the window being updated, updated_row is
25313 the glyph row being updated, and updated_area is the area of that
25314 row being updated. */
25317 x_write_glyphs (struct glyph
*start
, int len
)
25319 int x
, hpos
, chpos
= updated_window
->phys_cursor
.hpos
;
25321 eassert (updated_window
&& updated_row
);
25322 /* When the window is hscrolled, cursor hpos can legitimately be out
25323 of bounds, but we draw the cursor at the corresponding window
25324 margin in that case. */
25325 if (!updated_row
->reversed_p
&& chpos
< 0)
25327 if (updated_row
->reversed_p
&& chpos
>= updated_row
->used
[TEXT_AREA
])
25328 chpos
= updated_row
->used
[TEXT_AREA
] - 1;
25332 /* Write glyphs. */
25334 hpos
= start
- updated_row
->glyphs
[updated_area
];
25335 x
= draw_glyphs (updated_window
, output_cursor
.x
,
25336 updated_row
, updated_area
,
25338 DRAW_NORMAL_TEXT
, 0);
25340 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
25341 if (updated_area
== TEXT_AREA
25342 && updated_window
->phys_cursor_on_p
25343 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
25345 && chpos
< hpos
+ len
)
25346 updated_window
->phys_cursor_on_p
= 0;
25350 /* Advance the output cursor. */
25351 output_cursor
.hpos
+= len
;
25352 output_cursor
.x
= x
;
25357 Insert LEN glyphs from START at the nominal cursor position. */
25360 x_insert_glyphs (struct glyph
*start
, int len
)
25364 int line_height
, shift_by_width
, shifted_region_width
;
25365 struct glyph_row
*row
;
25366 struct glyph
*glyph
;
25367 int frame_x
, frame_y
;
25370 eassert (updated_window
&& updated_row
);
25372 w
= updated_window
;
25373 f
= XFRAME (WINDOW_FRAME (w
));
25375 /* Get the height of the line we are in. */
25377 line_height
= row
->height
;
25379 /* Get the width of the glyphs to insert. */
25380 shift_by_width
= 0;
25381 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
25382 shift_by_width
+= glyph
->pixel_width
;
25384 /* Get the width of the region to shift right. */
25385 shifted_region_width
= (window_box_width (w
, updated_area
)
25390 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
25391 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
25393 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
25394 line_height
, shift_by_width
);
25396 /* Write the glyphs. */
25397 hpos
= start
- row
->glyphs
[updated_area
];
25398 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
25400 DRAW_NORMAL_TEXT
, 0);
25402 /* Advance the output cursor. */
25403 output_cursor
.hpos
+= len
;
25404 output_cursor
.x
+= shift_by_width
;
25410 Erase the current text line from the nominal cursor position
25411 (inclusive) to pixel column TO_X (exclusive). The idea is that
25412 everything from TO_X onward is already erased.
25414 TO_X is a pixel position relative to updated_area of
25415 updated_window. TO_X == -1 means clear to the end of this area. */
25418 x_clear_end_of_line (int to_x
)
25421 struct window
*w
= updated_window
;
25422 int max_x
, min_y
, max_y
;
25423 int from_x
, from_y
, to_y
;
25425 eassert (updated_window
&& updated_row
);
25426 f
= XFRAME (w
->frame
);
25428 if (updated_row
->full_width_p
)
25429 max_x
= WINDOW_TOTAL_WIDTH (w
);
25431 max_x
= window_box_width (w
, updated_area
);
25432 max_y
= window_text_bottom_y (w
);
25434 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
25435 of window. For TO_X > 0, truncate to end of drawing area. */
25441 to_x
= min (to_x
, max_x
);
25443 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
25445 /* Notice if the cursor will be cleared by this operation. */
25446 if (!updated_row
->full_width_p
)
25447 notice_overwritten_cursor (w
, updated_area
,
25448 output_cursor
.x
, -1,
25450 MATRIX_ROW_BOTTOM_Y (updated_row
));
25452 from_x
= output_cursor
.x
;
25454 /* Translate to frame coordinates. */
25455 if (updated_row
->full_width_p
)
25457 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
25458 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
25462 int area_left
= window_box_left (w
, updated_area
);
25463 from_x
+= area_left
;
25467 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
25468 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
25469 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
25471 /* Prevent inadvertently clearing to end of the X window. */
25472 if (to_x
> from_x
&& to_y
> from_y
)
25475 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
25476 to_x
- from_x
, to_y
- from_y
);
25481 #endif /* HAVE_WINDOW_SYSTEM */
25485 /***********************************************************************
25487 ***********************************************************************/
25489 /* Value is the internal representation of the specified cursor type
25490 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
25491 of the bar cursor. */
25493 static enum text_cursor_kinds
25494 get_specified_cursor_type (Lisp_Object arg
, int *width
)
25496 enum text_cursor_kinds type
;
25501 if (EQ (arg
, Qbox
))
25502 return FILLED_BOX_CURSOR
;
25504 if (EQ (arg
, Qhollow
))
25505 return HOLLOW_BOX_CURSOR
;
25507 if (EQ (arg
, Qbar
))
25514 && EQ (XCAR (arg
), Qbar
)
25515 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
25517 *width
= XINT (XCDR (arg
));
25521 if (EQ (arg
, Qhbar
))
25524 return HBAR_CURSOR
;
25528 && EQ (XCAR (arg
), Qhbar
)
25529 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
25531 *width
= XINT (XCDR (arg
));
25532 return HBAR_CURSOR
;
25535 /* Treat anything unknown as "hollow box cursor".
25536 It was bad to signal an error; people have trouble fixing
25537 .Xdefaults with Emacs, when it has something bad in it. */
25538 type
= HOLLOW_BOX_CURSOR
;
25543 /* Set the default cursor types for specified frame. */
25545 set_frame_cursor_types (struct frame
*f
, Lisp_Object arg
)
25550 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
25551 FRAME_CURSOR_WIDTH (f
) = width
;
25553 /* By default, set up the blink-off state depending on the on-state. */
25555 tem
= Fassoc (arg
, Vblink_cursor_alist
);
25558 FRAME_BLINK_OFF_CURSOR (f
)
25559 = get_specified_cursor_type (XCDR (tem
), &width
);
25560 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
25563 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
25567 #ifdef HAVE_WINDOW_SYSTEM
25569 /* Return the cursor we want to be displayed in window W. Return
25570 width of bar/hbar cursor through WIDTH arg. Return with
25571 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
25572 (i.e. if the `system caret' should track this cursor).
25574 In a mini-buffer window, we want the cursor only to appear if we
25575 are reading input from this window. For the selected window, we
25576 want the cursor type given by the frame parameter or buffer local
25577 setting of cursor-type. If explicitly marked off, draw no cursor.
25578 In all other cases, we want a hollow box cursor. */
25580 static enum text_cursor_kinds
25581 get_window_cursor_type (struct window
*w
, struct glyph
*glyph
, int *width
,
25582 int *active_cursor
)
25584 struct frame
*f
= XFRAME (w
->frame
);
25585 struct buffer
*b
= XBUFFER (w
->buffer
);
25586 int cursor_type
= DEFAULT_CURSOR
;
25587 Lisp_Object alt_cursor
;
25588 int non_selected
= 0;
25590 *active_cursor
= 1;
25593 if (cursor_in_echo_area
25594 && FRAME_HAS_MINIBUF_P (f
)
25595 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
25597 if (w
== XWINDOW (echo_area_window
))
25599 if (EQ (BVAR (b
, cursor_type
), Qt
) || NILP (BVAR (b
, cursor_type
)))
25601 *width
= FRAME_CURSOR_WIDTH (f
);
25602 return FRAME_DESIRED_CURSOR (f
);
25605 return get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
25608 *active_cursor
= 0;
25612 /* Detect a nonselected window or nonselected frame. */
25613 else if (w
!= XWINDOW (f
->selected_window
)
25614 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)
25616 *active_cursor
= 0;
25618 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
25624 /* Never display a cursor in a window in which cursor-type is nil. */
25625 if (NILP (BVAR (b
, cursor_type
)))
25628 /* Get the normal cursor type for this window. */
25629 if (EQ (BVAR (b
, cursor_type
), Qt
))
25631 cursor_type
= FRAME_DESIRED_CURSOR (f
);
25632 *width
= FRAME_CURSOR_WIDTH (f
);
25635 cursor_type
= get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
25637 /* Use cursor-in-non-selected-windows instead
25638 for non-selected window or frame. */
25641 alt_cursor
= BVAR (b
, cursor_in_non_selected_windows
);
25642 if (!EQ (Qt
, alt_cursor
))
25643 return get_specified_cursor_type (alt_cursor
, width
);
25644 /* t means modify the normal cursor type. */
25645 if (cursor_type
== FILLED_BOX_CURSOR
)
25646 cursor_type
= HOLLOW_BOX_CURSOR
;
25647 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
25649 return cursor_type
;
25652 /* Use normal cursor if not blinked off. */
25653 if (!w
->cursor_off_p
)
25655 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
25657 if (cursor_type
== FILLED_BOX_CURSOR
)
25659 /* Using a block cursor on large images can be very annoying.
25660 So use a hollow cursor for "large" images.
25661 If image is not transparent (no mask), also use hollow cursor. */
25662 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
25663 if (img
!= NULL
&& IMAGEP (img
->spec
))
25665 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
25666 where N = size of default frame font size.
25667 This should cover most of the "tiny" icons people may use. */
25669 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
25670 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
25671 cursor_type
= HOLLOW_BOX_CURSOR
;
25674 else if (cursor_type
!= NO_CURSOR
)
25676 /* Display current only supports BOX and HOLLOW cursors for images.
25677 So for now, unconditionally use a HOLLOW cursor when cursor is
25678 not a solid box cursor. */
25679 cursor_type
= HOLLOW_BOX_CURSOR
;
25682 return cursor_type
;
25685 /* Cursor is blinked off, so determine how to "toggle" it. */
25687 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
25688 if ((alt_cursor
= Fassoc (BVAR (b
, cursor_type
), Vblink_cursor_alist
), !NILP (alt_cursor
)))
25689 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
25691 /* Then see if frame has specified a specific blink off cursor type. */
25692 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
25694 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
25695 return FRAME_BLINK_OFF_CURSOR (f
);
25699 /* Some people liked having a permanently visible blinking cursor,
25700 while others had very strong opinions against it. So it was
25701 decided to remove it. KFS 2003-09-03 */
25703 /* Finally perform built-in cursor blinking:
25704 filled box <-> hollow box
25705 wide [h]bar <-> narrow [h]bar
25706 narrow [h]bar <-> no cursor
25707 other type <-> no cursor */
25709 if (cursor_type
== FILLED_BOX_CURSOR
)
25710 return HOLLOW_BOX_CURSOR
;
25712 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
25715 return cursor_type
;
25723 /* Notice when the text cursor of window W has been completely
25724 overwritten by a drawing operation that outputs glyphs in AREA
25725 starting at X0 and ending at X1 in the line starting at Y0 and
25726 ending at Y1. X coordinates are area-relative. X1 < 0 means all
25727 the rest of the line after X0 has been written. Y coordinates
25728 are window-relative. */
25731 notice_overwritten_cursor (struct window
*w
, enum glyph_row_area area
,
25732 int x0
, int x1
, int y0
, int y1
)
25734 int cx0
, cx1
, cy0
, cy1
;
25735 struct glyph_row
*row
;
25737 if (!w
->phys_cursor_on_p
)
25739 if (area
!= TEXT_AREA
)
25742 if (w
->phys_cursor
.vpos
< 0
25743 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
25744 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
25745 !(row
->enabled_p
&& row
->displays_text_p
)))
25748 if (row
->cursor_in_fringe_p
)
25750 row
->cursor_in_fringe_p
= 0;
25751 draw_fringe_bitmap (w
, row
, row
->reversed_p
);
25752 w
->phys_cursor_on_p
= 0;
25756 cx0
= w
->phys_cursor
.x
;
25757 cx1
= cx0
+ w
->phys_cursor_width
;
25758 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
25761 /* The cursor image will be completely removed from the
25762 screen if the output area intersects the cursor area in
25763 y-direction. When we draw in [y0 y1[, and some part of
25764 the cursor is at y < y0, that part must have been drawn
25765 before. When scrolling, the cursor is erased before
25766 actually scrolling, so we don't come here. When not
25767 scrolling, the rows above the old cursor row must have
25768 changed, and in this case these rows must have written
25769 over the cursor image.
25771 Likewise if part of the cursor is below y1, with the
25772 exception of the cursor being in the first blank row at
25773 the buffer and window end because update_text_area
25774 doesn't draw that row. (Except when it does, but
25775 that's handled in update_text_area.) */
25777 cy0
= w
->phys_cursor
.y
;
25778 cy1
= cy0
+ w
->phys_cursor_height
;
25779 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
25782 w
->phys_cursor_on_p
= 0;
25785 #endif /* HAVE_WINDOW_SYSTEM */
25788 /************************************************************************
25790 ************************************************************************/
25792 #ifdef HAVE_WINDOW_SYSTEM
25795 Fix the display of area AREA of overlapping row ROW in window W
25796 with respect to the overlapping part OVERLAPS. */
25799 x_fix_overlapping_area (struct window
*w
, struct glyph_row
*row
,
25800 enum glyph_row_area area
, int overlaps
)
25807 for (i
= 0; i
< row
->used
[area
];)
25809 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
25811 int start
= i
, start_x
= x
;
25815 x
+= row
->glyphs
[area
][i
].pixel_width
;
25818 while (i
< row
->used
[area
]
25819 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
25821 draw_glyphs (w
, start_x
, row
, area
,
25823 DRAW_NORMAL_TEXT
, overlaps
);
25827 x
+= row
->glyphs
[area
][i
].pixel_width
;
25837 Draw the cursor glyph of window W in glyph row ROW. See the
25838 comment of draw_glyphs for the meaning of HL. */
25841 draw_phys_cursor_glyph (struct window
*w
, struct glyph_row
*row
,
25842 enum draw_glyphs_face hl
)
25844 /* If cursor hpos is out of bounds, don't draw garbage. This can
25845 happen in mini-buffer windows when switching between echo area
25846 glyphs and mini-buffer. */
25847 if ((row
->reversed_p
25848 ? (w
->phys_cursor
.hpos
>= 0)
25849 : (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])))
25851 int on_p
= w
->phys_cursor_on_p
;
25853 int hpos
= w
->phys_cursor
.hpos
;
25855 /* When the window is hscrolled, cursor hpos can legitimately be
25856 out of bounds, but we draw the cursor at the corresponding
25857 window margin in that case. */
25858 if (!row
->reversed_p
&& hpos
< 0)
25860 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
25861 hpos
= row
->used
[TEXT_AREA
] - 1;
25863 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
, hpos
, hpos
+ 1,
25865 w
->phys_cursor_on_p
= on_p
;
25867 if (hl
== DRAW_CURSOR
)
25868 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
25869 /* When we erase the cursor, and ROW is overlapped by other
25870 rows, make sure that these overlapping parts of other rows
25872 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
25874 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
25876 if (row
> w
->current_matrix
->rows
25877 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
25878 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
25879 OVERLAPS_ERASED_CURSOR
);
25881 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
25882 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
25883 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
25884 OVERLAPS_ERASED_CURSOR
);
25891 Erase the image of a cursor of window W from the screen. */
25894 erase_phys_cursor (struct window
*w
)
25896 struct frame
*f
= XFRAME (w
->frame
);
25897 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
25898 int hpos
= w
->phys_cursor
.hpos
;
25899 int vpos
= w
->phys_cursor
.vpos
;
25900 int mouse_face_here_p
= 0;
25901 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
25902 struct glyph_row
*cursor_row
;
25903 struct glyph
*cursor_glyph
;
25904 enum draw_glyphs_face hl
;
25906 /* No cursor displayed or row invalidated => nothing to do on the
25908 if (w
->phys_cursor_type
== NO_CURSOR
)
25909 goto mark_cursor_off
;
25911 /* VPOS >= active_glyphs->nrows means that window has been resized.
25912 Don't bother to erase the cursor. */
25913 if (vpos
>= active_glyphs
->nrows
)
25914 goto mark_cursor_off
;
25916 /* If row containing cursor is marked invalid, there is nothing we
25918 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
25919 if (!cursor_row
->enabled_p
)
25920 goto mark_cursor_off
;
25922 /* If line spacing is > 0, old cursor may only be partially visible in
25923 window after split-window. So adjust visible height. */
25924 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
25925 window_text_bottom_y (w
) - cursor_row
->y
);
25927 /* If row is completely invisible, don't attempt to delete a cursor which
25928 isn't there. This can happen if cursor is at top of a window, and
25929 we switch to a buffer with a header line in that window. */
25930 if (cursor_row
->visible_height
<= 0)
25931 goto mark_cursor_off
;
25933 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
25934 if (cursor_row
->cursor_in_fringe_p
)
25936 cursor_row
->cursor_in_fringe_p
= 0;
25937 draw_fringe_bitmap (w
, cursor_row
, cursor_row
->reversed_p
);
25938 goto mark_cursor_off
;
25941 /* This can happen when the new row is shorter than the old one.
25942 In this case, either draw_glyphs or clear_end_of_line
25943 should have cleared the cursor. Note that we wouldn't be
25944 able to erase the cursor in this case because we don't have a
25945 cursor glyph at hand. */
25946 if ((cursor_row
->reversed_p
25947 ? (w
->phys_cursor
.hpos
< 0)
25948 : (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])))
25949 goto mark_cursor_off
;
25951 /* When the window is hscrolled, cursor hpos can legitimately be out
25952 of bounds, but we draw the cursor at the corresponding window
25953 margin in that case. */
25954 if (!cursor_row
->reversed_p
&& hpos
< 0)
25956 if (cursor_row
->reversed_p
&& hpos
>= cursor_row
->used
[TEXT_AREA
])
25957 hpos
= cursor_row
->used
[TEXT_AREA
] - 1;
25959 /* If the cursor is in the mouse face area, redisplay that when
25960 we clear the cursor. */
25961 if (! NILP (hlinfo
->mouse_face_window
)
25962 && coords_in_mouse_face_p (w
, hpos
, vpos
)
25963 /* Don't redraw the cursor's spot in mouse face if it is at the
25964 end of a line (on a newline). The cursor appears there, but
25965 mouse highlighting does not. */
25966 && cursor_row
->used
[TEXT_AREA
] > hpos
&& hpos
>= 0)
25967 mouse_face_here_p
= 1;
25969 /* Maybe clear the display under the cursor. */
25970 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
25973 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
25976 cursor_glyph
= get_phys_cursor_glyph (w
);
25977 if (cursor_glyph
== NULL
)
25978 goto mark_cursor_off
;
25980 width
= cursor_glyph
->pixel_width
;
25981 left_x
= window_box_left_offset (w
, TEXT_AREA
);
25982 x
= w
->phys_cursor
.x
;
25984 width
-= left_x
- x
;
25985 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
25986 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
25987 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
25990 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
25993 /* Erase the cursor by redrawing the character underneath it. */
25994 if (mouse_face_here_p
)
25995 hl
= DRAW_MOUSE_FACE
;
25997 hl
= DRAW_NORMAL_TEXT
;
25998 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
26001 w
->phys_cursor_on_p
= 0;
26002 w
->phys_cursor_type
= NO_CURSOR
;
26007 Display or clear cursor of window W. If ON is zero, clear the
26008 cursor. If it is non-zero, display the cursor. If ON is nonzero,
26009 where to put the cursor is specified by HPOS, VPOS, X and Y. */
26012 display_and_set_cursor (struct window
*w
, int on
,
26013 int hpos
, int vpos
, int x
, int y
)
26015 struct frame
*f
= XFRAME (w
->frame
);
26016 int new_cursor_type
;
26017 int new_cursor_width
;
26019 struct glyph_row
*glyph_row
;
26020 struct glyph
*glyph
;
26022 /* This is pointless on invisible frames, and dangerous on garbaged
26023 windows and frames; in the latter case, the frame or window may
26024 be in the midst of changing its size, and x and y may be off the
26026 if (! FRAME_VISIBLE_P (f
)
26027 || FRAME_GARBAGED_P (f
)
26028 || vpos
>= w
->current_matrix
->nrows
26029 || hpos
>= w
->current_matrix
->matrix_w
)
26032 /* If cursor is off and we want it off, return quickly. */
26033 if (!on
&& !w
->phys_cursor_on_p
)
26036 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26037 /* If cursor row is not enabled, we don't really know where to
26038 display the cursor. */
26039 if (!glyph_row
->enabled_p
)
26041 w
->phys_cursor_on_p
= 0;
26046 if (!glyph_row
->exact_window_width_line_p
26047 || (0 <= hpos
&& hpos
< glyph_row
->used
[TEXT_AREA
]))
26048 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
26050 eassert (interrupt_input_blocked
);
26052 /* Set new_cursor_type to the cursor we want to be displayed. */
26053 new_cursor_type
= get_window_cursor_type (w
, glyph
,
26054 &new_cursor_width
, &active_cursor
);
26056 /* If cursor is currently being shown and we don't want it to be or
26057 it is in the wrong place, or the cursor type is not what we want,
26059 if (w
->phys_cursor_on_p
26061 || w
->phys_cursor
.x
!= x
26062 || w
->phys_cursor
.y
!= y
26063 || new_cursor_type
!= w
->phys_cursor_type
26064 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
26065 && new_cursor_width
!= w
->phys_cursor_width
)))
26066 erase_phys_cursor (w
);
26068 /* Don't check phys_cursor_on_p here because that flag is only set
26069 to zero in some cases where we know that the cursor has been
26070 completely erased, to avoid the extra work of erasing the cursor
26071 twice. In other words, phys_cursor_on_p can be 1 and the cursor
26072 still not be visible, or it has only been partly erased. */
26075 w
->phys_cursor_ascent
= glyph_row
->ascent
;
26076 w
->phys_cursor_height
= glyph_row
->height
;
26078 /* Set phys_cursor_.* before x_draw_.* is called because some
26079 of them may need the information. */
26080 w
->phys_cursor
.x
= x
;
26081 w
->phys_cursor
.y
= glyph_row
->y
;
26082 w
->phys_cursor
.hpos
= hpos
;
26083 w
->phys_cursor
.vpos
= vpos
;
26086 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
26087 new_cursor_type
, new_cursor_width
,
26088 on
, active_cursor
);
26092 /* Switch the display of W's cursor on or off, according to the value
26096 update_window_cursor (struct window
*w
, int on
)
26098 /* Don't update cursor in windows whose frame is in the process
26099 of being deleted. */
26100 if (w
->current_matrix
)
26102 int hpos
= w
->phys_cursor
.hpos
;
26103 int vpos
= w
->phys_cursor
.vpos
;
26104 struct glyph_row
*row
;
26106 if (vpos
>= w
->current_matrix
->nrows
26107 || hpos
>= w
->current_matrix
->matrix_w
)
26110 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26112 /* When the window is hscrolled, cursor hpos can legitimately be
26113 out of bounds, but we draw the cursor at the corresponding
26114 window margin in that case. */
26115 if (!row
->reversed_p
&& hpos
< 0)
26117 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26118 hpos
= row
->used
[TEXT_AREA
] - 1;
26121 display_and_set_cursor (w
, on
, hpos
, vpos
,
26122 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
26128 /* Call update_window_cursor with parameter ON_P on all leaf windows
26129 in the window tree rooted at W. */
26132 update_cursor_in_window_tree (struct window
*w
, int on_p
)
26136 if (!NILP (w
->hchild
))
26137 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
26138 else if (!NILP (w
->vchild
))
26139 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
26141 update_window_cursor (w
, on_p
);
26143 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
26149 Display the cursor on window W, or clear it, according to ON_P.
26150 Don't change the cursor's position. */
26153 x_update_cursor (struct frame
*f
, int on_p
)
26155 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
26160 Clear the cursor of window W to background color, and mark the
26161 cursor as not shown. This is used when the text where the cursor
26162 is about to be rewritten. */
26165 x_clear_cursor (struct window
*w
)
26167 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
26168 update_window_cursor (w
, 0);
26171 #endif /* HAVE_WINDOW_SYSTEM */
26173 /* Implementation of draw_row_with_mouse_face for GUI sessions, GPM,
26176 draw_row_with_mouse_face (struct window
*w
, int start_x
, struct glyph_row
*row
,
26177 int start_hpos
, int end_hpos
,
26178 enum draw_glyphs_face draw
)
26180 #ifdef HAVE_WINDOW_SYSTEM
26181 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
26183 draw_glyphs (w
, start_x
, row
, TEXT_AREA
, start_hpos
, end_hpos
, draw
, 0);
26187 #if defined (HAVE_GPM) || defined (MSDOS) || defined (WINDOWSNT)
26188 tty_draw_row_with_mouse_face (w
, row
, start_hpos
, end_hpos
, draw
);
26192 /* Display the active region described by mouse_face_* according to DRAW. */
26195 show_mouse_face (Mouse_HLInfo
*hlinfo
, enum draw_glyphs_face draw
)
26197 struct window
*w
= XWINDOW (hlinfo
->mouse_face_window
);
26198 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
26200 if (/* If window is in the process of being destroyed, don't bother
26202 w
->current_matrix
!= NULL
26203 /* Don't update mouse highlight if hidden */
26204 && (draw
!= DRAW_MOUSE_FACE
|| !hlinfo
->mouse_face_hidden
)
26205 /* Recognize when we are called to operate on rows that don't exist
26206 anymore. This can happen when a window is split. */
26207 && hlinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
26209 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
26210 struct glyph_row
*row
, *first
, *last
;
26212 first
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
26213 last
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
26215 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
26217 int start_hpos
, end_hpos
, start_x
;
26219 /* For all but the first row, the highlight starts at column 0. */
26222 /* R2L rows have BEG and END in reversed order, but the
26223 screen drawing geometry is always left to right. So
26224 we need to mirror the beginning and end of the
26225 highlighted area in R2L rows. */
26226 if (!row
->reversed_p
)
26228 start_hpos
= hlinfo
->mouse_face_beg_col
;
26229 start_x
= hlinfo
->mouse_face_beg_x
;
26231 else if (row
== last
)
26233 start_hpos
= hlinfo
->mouse_face_end_col
;
26234 start_x
= hlinfo
->mouse_face_end_x
;
26242 else if (row
->reversed_p
&& row
== last
)
26244 start_hpos
= hlinfo
->mouse_face_end_col
;
26245 start_x
= hlinfo
->mouse_face_end_x
;
26255 if (!row
->reversed_p
)
26256 end_hpos
= hlinfo
->mouse_face_end_col
;
26257 else if (row
== first
)
26258 end_hpos
= hlinfo
->mouse_face_beg_col
;
26261 end_hpos
= row
->used
[TEXT_AREA
];
26262 if (draw
== DRAW_NORMAL_TEXT
)
26263 row
->fill_line_p
= 1; /* Clear to end of line */
26266 else if (row
->reversed_p
&& row
== first
)
26267 end_hpos
= hlinfo
->mouse_face_beg_col
;
26270 end_hpos
= row
->used
[TEXT_AREA
];
26271 if (draw
== DRAW_NORMAL_TEXT
)
26272 row
->fill_line_p
= 1; /* Clear to end of line */
26275 if (end_hpos
> start_hpos
)
26277 draw_row_with_mouse_face (w
, start_x
, row
,
26278 start_hpos
, end_hpos
, draw
);
26281 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
26285 #ifdef HAVE_WINDOW_SYSTEM
26286 /* When we've written over the cursor, arrange for it to
26287 be displayed again. */
26288 if (FRAME_WINDOW_P (f
)
26289 && phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
26291 int hpos
= w
->phys_cursor
.hpos
;
26293 /* When the window is hscrolled, cursor hpos can legitimately be
26294 out of bounds, but we draw the cursor at the corresponding
26295 window margin in that case. */
26296 if (!row
->reversed_p
&& hpos
< 0)
26298 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26299 hpos
= row
->used
[TEXT_AREA
] - 1;
26302 display_and_set_cursor (w
, 1, hpos
, w
->phys_cursor
.vpos
,
26303 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
26306 #endif /* HAVE_WINDOW_SYSTEM */
26309 #ifdef HAVE_WINDOW_SYSTEM
26310 /* Change the mouse cursor. */
26311 if (FRAME_WINDOW_P (f
))
26313 if (draw
== DRAW_NORMAL_TEXT
26314 && !EQ (hlinfo
->mouse_face_window
, f
->tool_bar_window
))
26315 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
26316 else if (draw
== DRAW_MOUSE_FACE
)
26317 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
26319 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
26321 #endif /* HAVE_WINDOW_SYSTEM */
26325 Clear out the mouse-highlighted active region.
26326 Redraw it un-highlighted first. Value is non-zero if mouse
26327 face was actually drawn unhighlighted. */
26330 clear_mouse_face (Mouse_HLInfo
*hlinfo
)
26334 if (!hlinfo
->mouse_face_hidden
&& !NILP (hlinfo
->mouse_face_window
))
26336 show_mouse_face (hlinfo
, DRAW_NORMAL_TEXT
);
26340 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
26341 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
26342 hlinfo
->mouse_face_window
= Qnil
;
26343 hlinfo
->mouse_face_overlay
= Qnil
;
26347 /* Return non-zero if the coordinates HPOS and VPOS on windows W are
26348 within the mouse face on that window. */
26350 coords_in_mouse_face_p (struct window
*w
, int hpos
, int vpos
)
26352 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
26354 /* Quickly resolve the easy cases. */
26355 if (!(WINDOWP (hlinfo
->mouse_face_window
)
26356 && XWINDOW (hlinfo
->mouse_face_window
) == w
))
26358 if (vpos
< hlinfo
->mouse_face_beg_row
26359 || vpos
> hlinfo
->mouse_face_end_row
)
26361 if (vpos
> hlinfo
->mouse_face_beg_row
26362 && vpos
< hlinfo
->mouse_face_end_row
)
26365 if (!MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
)
26367 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
26369 if (hlinfo
->mouse_face_beg_col
<= hpos
&& hpos
< hlinfo
->mouse_face_end_col
)
26372 else if ((vpos
== hlinfo
->mouse_face_beg_row
26373 && hpos
>= hlinfo
->mouse_face_beg_col
)
26374 || (vpos
== hlinfo
->mouse_face_end_row
26375 && hpos
< hlinfo
->mouse_face_end_col
))
26380 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
26382 if (hlinfo
->mouse_face_end_col
< hpos
&& hpos
<= hlinfo
->mouse_face_beg_col
)
26385 else if ((vpos
== hlinfo
->mouse_face_beg_row
26386 && hpos
<= hlinfo
->mouse_face_beg_col
)
26387 || (vpos
== hlinfo
->mouse_face_end_row
26388 && hpos
> hlinfo
->mouse_face_end_col
))
26396 Non-zero if physical cursor of window W is within mouse face. */
26399 cursor_in_mouse_face_p (struct window
*w
)
26401 int hpos
= w
->phys_cursor
.hpos
;
26402 int vpos
= w
->phys_cursor
.vpos
;
26403 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26405 /* When the window is hscrolled, cursor hpos can legitimately be out
26406 of bounds, but we draw the cursor at the corresponding window
26407 margin in that case. */
26408 if (!row
->reversed_p
&& hpos
< 0)
26410 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26411 hpos
= row
->used
[TEXT_AREA
] - 1;
26413 return coords_in_mouse_face_p (w
, hpos
, vpos
);
26418 /* Find the glyph rows START_ROW and END_ROW of window W that display
26419 characters between buffer positions START_CHARPOS and END_CHARPOS
26420 (excluding END_CHARPOS). DISP_STRING is a display string that
26421 covers these buffer positions. This is similar to
26422 row_containing_pos, but is more accurate when bidi reordering makes
26423 buffer positions change non-linearly with glyph rows. */
26425 rows_from_pos_range (struct window
*w
,
26426 ptrdiff_t start_charpos
, ptrdiff_t end_charpos
,
26427 Lisp_Object disp_string
,
26428 struct glyph_row
**start
, struct glyph_row
**end
)
26430 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26431 int last_y
= window_text_bottom_y (w
);
26432 struct glyph_row
*row
;
26437 while (!first
->enabled_p
26438 && first
< MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
26441 /* Find the START row. */
26443 row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
;
26446 /* A row can potentially be the START row if the range of the
26447 characters it displays intersects the range
26448 [START_CHARPOS..END_CHARPOS). */
26449 if (! ((start_charpos
< MATRIX_ROW_START_CHARPOS (row
)
26450 && end_charpos
< MATRIX_ROW_START_CHARPOS (row
))
26451 /* See the commentary in row_containing_pos, for the
26452 explanation of the complicated way to check whether
26453 some position is beyond the end of the characters
26454 displayed by a row. */
26455 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (row
)
26456 || (start_charpos
== MATRIX_ROW_END_CHARPOS (row
)
26457 && !row
->ends_at_zv_p
26458 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
26459 && (end_charpos
> MATRIX_ROW_END_CHARPOS (row
)
26460 || (end_charpos
== MATRIX_ROW_END_CHARPOS (row
)
26461 && !row
->ends_at_zv_p
26462 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))))
26464 /* Found a candidate row. Now make sure at least one of the
26465 glyphs it displays has a charpos from the range
26466 [START_CHARPOS..END_CHARPOS).
26468 This is not obvious because bidi reordering could make
26469 buffer positions of a row be 1,2,3,102,101,100, and if we
26470 want to highlight characters in [50..60), we don't want
26471 this row, even though [50..60) does intersect [1..103),
26472 the range of character positions given by the row's start
26473 and end positions. */
26474 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
26475 struct glyph
*e
= g
+ row
->used
[TEXT_AREA
];
26479 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
26480 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
26481 /* A glyph that comes from DISP_STRING is by
26482 definition to be highlighted. */
26483 || EQ (g
->object
, disp_string
))
26492 /* Find the END row. */
26494 /* If the last row is partially visible, start looking for END
26495 from that row, instead of starting from FIRST. */
26496 && !(row
->enabled_p
26497 && row
->y
< last_y
&& MATRIX_ROW_BOTTOM_Y (row
) > last_y
))
26499 for ( ; row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
; row
++)
26501 struct glyph_row
*next
= row
+ 1;
26502 ptrdiff_t next_start
= MATRIX_ROW_START_CHARPOS (next
);
26504 if (!next
->enabled_p
26505 || next
>= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
)
26506 /* The first row >= START whose range of displayed characters
26507 does NOT intersect the range [START_CHARPOS..END_CHARPOS]
26508 is the row END + 1. */
26509 || (start_charpos
< next_start
26510 && end_charpos
< next_start
)
26511 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (next
)
26512 || (start_charpos
== MATRIX_ROW_END_CHARPOS (next
)
26513 && !next
->ends_at_zv_p
26514 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))
26515 && (end_charpos
> MATRIX_ROW_END_CHARPOS (next
)
26516 || (end_charpos
== MATRIX_ROW_END_CHARPOS (next
)
26517 && !next
->ends_at_zv_p
26518 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))))
26525 /* If the next row's edges intersect [START_CHARPOS..END_CHARPOS],
26526 but none of the characters it displays are in the range, it is
26528 struct glyph
*g
= next
->glyphs
[TEXT_AREA
];
26529 struct glyph
*s
= g
;
26530 struct glyph
*e
= g
+ next
->used
[TEXT_AREA
];
26534 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
26535 && ((start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
26536 /* If the buffer position of the first glyph in
26537 the row is equal to END_CHARPOS, it means
26538 the last character to be highlighted is the
26539 newline of ROW, and we must consider NEXT as
26541 || (((!next
->reversed_p
&& g
== s
)
26542 || (next
->reversed_p
&& g
== e
- 1))
26543 && (g
->charpos
== end_charpos
26544 /* Special case for when NEXT is an
26545 empty line at ZV. */
26546 || (g
->charpos
== -1
26547 && !row
->ends_at_zv_p
26548 && next_start
== end_charpos
)))))
26549 /* A glyph that comes from DISP_STRING is by
26550 definition to be highlighted. */
26551 || EQ (g
->object
, disp_string
))
26560 /* The first row that ends at ZV must be the last to be
26562 else if (next
->ends_at_zv_p
)
26571 /* This function sets the mouse_face_* elements of HLINFO, assuming
26572 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
26573 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
26574 for the overlay or run of text properties specifying the mouse
26575 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
26576 before-string and after-string that must also be highlighted.
26577 DISP_STRING, if non-nil, is a display string that may cover some
26578 or all of the highlighted text. */
26581 mouse_face_from_buffer_pos (Lisp_Object window
,
26582 Mouse_HLInfo
*hlinfo
,
26583 ptrdiff_t mouse_charpos
,
26584 ptrdiff_t start_charpos
,
26585 ptrdiff_t end_charpos
,
26586 Lisp_Object before_string
,
26587 Lisp_Object after_string
,
26588 Lisp_Object disp_string
)
26590 struct window
*w
= XWINDOW (window
);
26591 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26592 struct glyph_row
*r1
, *r2
;
26593 struct glyph
*glyph
, *end
;
26594 ptrdiff_t ignore
, pos
;
26597 eassert (NILP (disp_string
) || STRINGP (disp_string
));
26598 eassert (NILP (before_string
) || STRINGP (before_string
));
26599 eassert (NILP (after_string
) || STRINGP (after_string
));
26601 /* Find the rows corresponding to START_CHARPOS and END_CHARPOS. */
26602 rows_from_pos_range (w
, start_charpos
, end_charpos
, disp_string
, &r1
, &r2
);
26604 r1
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
26605 /* If the before-string or display-string contains newlines,
26606 rows_from_pos_range skips to its last row. Move back. */
26607 if (!NILP (before_string
) || !NILP (disp_string
))
26609 struct glyph_row
*prev
;
26610 while ((prev
= r1
- 1, prev
>= first
)
26611 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
26612 && prev
->used
[TEXT_AREA
] > 0)
26614 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
26615 glyph
= beg
+ prev
->used
[TEXT_AREA
];
26616 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
26618 || !(EQ (glyph
->object
, before_string
)
26619 || EQ (glyph
->object
, disp_string
)))
26626 r2
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
26627 hlinfo
->mouse_face_past_end
= 1;
26629 else if (!NILP (after_string
))
26631 /* If the after-string has newlines, advance to its last row. */
26632 struct glyph_row
*next
;
26633 struct glyph_row
*last
26634 = MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
26636 for (next
= r2
+ 1;
26638 && next
->used
[TEXT_AREA
] > 0
26639 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
26643 /* The rest of the display engine assumes that mouse_face_beg_row is
26644 either above mouse_face_end_row or identical to it. But with
26645 bidi-reordered continued lines, the row for START_CHARPOS could
26646 be below the row for END_CHARPOS. If so, swap the rows and store
26647 them in correct order. */
26650 struct glyph_row
*tem
= r2
;
26656 hlinfo
->mouse_face_beg_y
= r1
->y
;
26657 hlinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (r1
, w
->current_matrix
);
26658 hlinfo
->mouse_face_end_y
= r2
->y
;
26659 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r2
, w
->current_matrix
);
26661 /* For a bidi-reordered row, the positions of BEFORE_STRING,
26662 AFTER_STRING, DISP_STRING, START_CHARPOS, and END_CHARPOS
26663 could be anywhere in the row and in any order. The strategy
26664 below is to find the leftmost and the rightmost glyph that
26665 belongs to either of these 3 strings, or whose position is
26666 between START_CHARPOS and END_CHARPOS, and highlight all the
26667 glyphs between those two. This may cover more than just the text
26668 between START_CHARPOS and END_CHARPOS if the range of characters
26669 strides the bidi level boundary, e.g. if the beginning is in R2L
26670 text while the end is in L2R text or vice versa. */
26671 if (!r1
->reversed_p
)
26673 /* This row is in a left to right paragraph. Scan it left to
26675 glyph
= r1
->glyphs
[TEXT_AREA
];
26676 end
= glyph
+ r1
->used
[TEXT_AREA
];
26679 /* Skip truncation glyphs at the start of the glyph row. */
26680 if (r1
->displays_text_p
)
26682 && INTEGERP (glyph
->object
)
26683 && glyph
->charpos
< 0;
26685 x
+= glyph
->pixel_width
;
26687 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
26688 or DISP_STRING, and the first glyph from buffer whose
26689 position is between START_CHARPOS and END_CHARPOS. */
26691 && !INTEGERP (glyph
->object
)
26692 && !EQ (glyph
->object
, disp_string
)
26693 && !(BUFFERP (glyph
->object
)
26694 && (glyph
->charpos
>= start_charpos
26695 && glyph
->charpos
< end_charpos
));
26698 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26699 are present at buffer positions between START_CHARPOS and
26700 END_CHARPOS, or if they come from an overlay. */
26701 if (EQ (glyph
->object
, before_string
))
26703 pos
= string_buffer_position (before_string
,
26705 /* If pos == 0, it means before_string came from an
26706 overlay, not from a buffer position. */
26707 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26710 else if (EQ (glyph
->object
, after_string
))
26712 pos
= string_buffer_position (after_string
, end_charpos
);
26713 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26716 x
+= glyph
->pixel_width
;
26718 hlinfo
->mouse_face_beg_x
= x
;
26719 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
26723 /* This row is in a right to left paragraph. Scan it right to
26727 end
= r1
->glyphs
[TEXT_AREA
] - 1;
26728 glyph
= end
+ r1
->used
[TEXT_AREA
];
26730 /* Skip truncation glyphs at the start of the glyph row. */
26731 if (r1
->displays_text_p
)
26733 && INTEGERP (glyph
->object
)
26734 && glyph
->charpos
< 0;
26738 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
26739 or DISP_STRING, and the first glyph from buffer whose
26740 position is between START_CHARPOS and END_CHARPOS. */
26742 && !INTEGERP (glyph
->object
)
26743 && !EQ (glyph
->object
, disp_string
)
26744 && !(BUFFERP (glyph
->object
)
26745 && (glyph
->charpos
>= start_charpos
26746 && glyph
->charpos
< end_charpos
));
26749 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26750 are present at buffer positions between START_CHARPOS and
26751 END_CHARPOS, or if they come from an overlay. */
26752 if (EQ (glyph
->object
, before_string
))
26754 pos
= string_buffer_position (before_string
, start_charpos
);
26755 /* If pos == 0, it means before_string came from an
26756 overlay, not from a buffer position. */
26757 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26760 else if (EQ (glyph
->object
, after_string
))
26762 pos
= string_buffer_position (after_string
, end_charpos
);
26763 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26768 glyph
++; /* first glyph to the right of the highlighted area */
26769 for (g
= r1
->glyphs
[TEXT_AREA
], x
= r1
->x
; g
< glyph
; g
++)
26770 x
+= g
->pixel_width
;
26771 hlinfo
->mouse_face_beg_x
= x
;
26772 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
26775 /* If the highlight ends in a different row, compute GLYPH and END
26776 for the end row. Otherwise, reuse the values computed above for
26777 the row where the highlight begins. */
26780 if (!r2
->reversed_p
)
26782 glyph
= r2
->glyphs
[TEXT_AREA
];
26783 end
= glyph
+ r2
->used
[TEXT_AREA
];
26788 end
= r2
->glyphs
[TEXT_AREA
] - 1;
26789 glyph
= end
+ r2
->used
[TEXT_AREA
];
26793 if (!r2
->reversed_p
)
26795 /* Skip truncation and continuation glyphs near the end of the
26796 row, and also blanks and stretch glyphs inserted by
26797 extend_face_to_end_of_line. */
26799 && INTEGERP ((end
- 1)->object
))
26801 /* Scan the rest of the glyph row from the end, looking for the
26802 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
26803 DISP_STRING, or whose position is between START_CHARPOS
26807 && !INTEGERP (end
->object
)
26808 && !EQ (end
->object
, disp_string
)
26809 && !(BUFFERP (end
->object
)
26810 && (end
->charpos
>= start_charpos
26811 && end
->charpos
< end_charpos
));
26814 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26815 are present at buffer positions between START_CHARPOS and
26816 END_CHARPOS, or if they come from an overlay. */
26817 if (EQ (end
->object
, before_string
))
26819 pos
= string_buffer_position (before_string
, start_charpos
);
26820 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26823 else if (EQ (end
->object
, after_string
))
26825 pos
= string_buffer_position (after_string
, end_charpos
);
26826 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26830 /* Find the X coordinate of the last glyph to be highlighted. */
26831 for (; glyph
<= end
; ++glyph
)
26832 x
+= glyph
->pixel_width
;
26834 hlinfo
->mouse_face_end_x
= x
;
26835 hlinfo
->mouse_face_end_col
= glyph
- r2
->glyphs
[TEXT_AREA
];
26839 /* Skip truncation and continuation glyphs near the end of the
26840 row, and also blanks and stretch glyphs inserted by
26841 extend_face_to_end_of_line. */
26845 && INTEGERP (end
->object
))
26847 x
+= end
->pixel_width
;
26850 /* Scan the rest of the glyph row from the end, looking for the
26851 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
26852 DISP_STRING, or whose position is between START_CHARPOS
26856 && !INTEGERP (end
->object
)
26857 && !EQ (end
->object
, disp_string
)
26858 && !(BUFFERP (end
->object
)
26859 && (end
->charpos
>= start_charpos
26860 && end
->charpos
< end_charpos
));
26863 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26864 are present at buffer positions between START_CHARPOS and
26865 END_CHARPOS, or if they come from an overlay. */
26866 if (EQ (end
->object
, before_string
))
26868 pos
= string_buffer_position (before_string
, start_charpos
);
26869 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26872 else if (EQ (end
->object
, after_string
))
26874 pos
= string_buffer_position (after_string
, end_charpos
);
26875 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26878 x
+= end
->pixel_width
;
26880 /* If we exited the above loop because we arrived at the last
26881 glyph of the row, and its buffer position is still not in
26882 range, it means the last character in range is the preceding
26883 newline. Bump the end column and x values to get past the
26886 && BUFFERP (end
->object
)
26887 && (end
->charpos
< start_charpos
26888 || end
->charpos
>= end_charpos
))
26890 x
+= end
->pixel_width
;
26893 hlinfo
->mouse_face_end_x
= x
;
26894 hlinfo
->mouse_face_end_col
= end
- r2
->glyphs
[TEXT_AREA
];
26897 hlinfo
->mouse_face_window
= window
;
26898 hlinfo
->mouse_face_face_id
26899 = face_at_buffer_position (w
, mouse_charpos
, 0, 0, &ignore
,
26901 !hlinfo
->mouse_face_hidden
, -1);
26902 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
26905 /* The following function is not used anymore (replaced with
26906 mouse_face_from_string_pos), but I leave it here for the time
26907 being, in case someone would. */
26909 #if 0 /* not used */
26911 /* Find the position of the glyph for position POS in OBJECT in
26912 window W's current matrix, and return in *X, *Y the pixel
26913 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
26915 RIGHT_P non-zero means return the position of the right edge of the
26916 glyph, RIGHT_P zero means return the left edge position.
26918 If no glyph for POS exists in the matrix, return the position of
26919 the glyph with the next smaller position that is in the matrix, if
26920 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
26921 exists in the matrix, return the position of the glyph with the
26922 next larger position in OBJECT.
26924 Value is non-zero if a glyph was found. */
26927 fast_find_string_pos (struct window
*w
, ptrdiff_t pos
, Lisp_Object object
,
26928 int *hpos
, int *vpos
, int *x
, int *y
, int right_p
)
26930 int yb
= window_text_bottom_y (w
);
26931 struct glyph_row
*r
;
26932 struct glyph
*best_glyph
= NULL
;
26933 struct glyph_row
*best_row
= NULL
;
26936 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26937 r
->enabled_p
&& r
->y
< yb
;
26940 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
26941 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
26944 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
26945 if (EQ (g
->object
, object
))
26947 if (g
->charpos
== pos
)
26954 else if (best_glyph
== NULL
26955 || ((eabs (g
->charpos
- pos
)
26956 < eabs (best_glyph
->charpos
- pos
))
26959 : g
->charpos
> pos
)))
26973 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
26977 *x
+= best_glyph
->pixel_width
;
26982 *vpos
= best_row
- w
->current_matrix
->rows
;
26985 return best_glyph
!= NULL
;
26987 #endif /* not used */
26989 /* Find the positions of the first and the last glyphs in window W's
26990 current matrix that occlude positions [STARTPOS..ENDPOS] in OBJECT
26991 (assumed to be a string), and return in HLINFO's mouse_face_*
26992 members the pixel and column/row coordinates of those glyphs. */
26995 mouse_face_from_string_pos (struct window
*w
, Mouse_HLInfo
*hlinfo
,
26996 Lisp_Object object
,
26997 ptrdiff_t startpos
, ptrdiff_t endpos
)
26999 int yb
= window_text_bottom_y (w
);
27000 struct glyph_row
*r
;
27001 struct glyph
*g
, *e
;
27005 /* Find the glyph row with at least one position in the range
27006 [STARTPOS..ENDPOS], and the first glyph in that row whose
27007 position belongs to that range. */
27008 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27009 r
->enabled_p
&& r
->y
< yb
;
27012 if (!r
->reversed_p
)
27014 g
= r
->glyphs
[TEXT_AREA
];
27015 e
= g
+ r
->used
[TEXT_AREA
];
27016 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
27017 if (EQ (g
->object
, object
)
27018 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
27020 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
27021 hlinfo
->mouse_face_beg_y
= r
->y
;
27022 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
27023 hlinfo
->mouse_face_beg_x
= gx
;
27032 e
= r
->glyphs
[TEXT_AREA
];
27033 g
= e
+ r
->used
[TEXT_AREA
];
27034 for ( ; g
> e
; --g
)
27035 if (EQ ((g
-1)->object
, object
)
27036 && startpos
<= (g
-1)->charpos
&& (g
-1)->charpos
<= endpos
)
27038 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
27039 hlinfo
->mouse_face_beg_y
= r
->y
;
27040 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
27041 for (gx
= r
->x
, g1
= r
->glyphs
[TEXT_AREA
]; g1
< g
; ++g1
)
27042 gx
+= g1
->pixel_width
;
27043 hlinfo
->mouse_face_beg_x
= gx
;
27055 /* Starting with the next row, look for the first row which does NOT
27056 include any glyphs whose positions are in the range. */
27057 for (++r
; r
->enabled_p
&& r
->y
< yb
; ++r
)
27059 g
= r
->glyphs
[TEXT_AREA
];
27060 e
= g
+ r
->used
[TEXT_AREA
];
27062 for ( ; g
< e
; ++g
)
27063 if (EQ (g
->object
, object
)
27064 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
27073 /* The highlighted region ends on the previous row. */
27076 /* Set the end row and its vertical pixel coordinate. */
27077 hlinfo
->mouse_face_end_row
= r
- w
->current_matrix
->rows
;
27078 hlinfo
->mouse_face_end_y
= r
->y
;
27080 /* Compute and set the end column and the end column's horizontal
27081 pixel coordinate. */
27082 if (!r
->reversed_p
)
27084 g
= r
->glyphs
[TEXT_AREA
];
27085 e
= g
+ r
->used
[TEXT_AREA
];
27086 for ( ; e
> g
; --e
)
27087 if (EQ ((e
-1)->object
, object
)
27088 && startpos
<= (e
-1)->charpos
&& (e
-1)->charpos
<= endpos
)
27090 hlinfo
->mouse_face_end_col
= e
- g
;
27092 for (gx
= r
->x
; g
< e
; ++g
)
27093 gx
+= g
->pixel_width
;
27094 hlinfo
->mouse_face_end_x
= gx
;
27098 e
= r
->glyphs
[TEXT_AREA
];
27099 g
= e
+ r
->used
[TEXT_AREA
];
27100 for (gx
= r
->x
; e
< g
; ++e
)
27102 if (EQ (e
->object
, object
)
27103 && startpos
<= e
->charpos
&& e
->charpos
<= endpos
)
27105 gx
+= e
->pixel_width
;
27107 hlinfo
->mouse_face_end_col
= e
- r
->glyphs
[TEXT_AREA
];
27108 hlinfo
->mouse_face_end_x
= gx
;
27112 #ifdef HAVE_WINDOW_SYSTEM
27114 /* See if position X, Y is within a hot-spot of an image. */
27117 on_hot_spot_p (Lisp_Object hot_spot
, int x
, int y
)
27119 if (!CONSP (hot_spot
))
27122 if (EQ (XCAR (hot_spot
), Qrect
))
27124 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
27125 Lisp_Object rect
= XCDR (hot_spot
);
27129 if (!CONSP (XCAR (rect
)))
27131 if (!CONSP (XCDR (rect
)))
27133 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
27135 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
27137 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
27139 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
27143 else if (EQ (XCAR (hot_spot
), Qcircle
))
27145 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
27146 Lisp_Object circ
= XCDR (hot_spot
);
27147 Lisp_Object lr
, lx0
, ly0
;
27149 && CONSP (XCAR (circ
))
27150 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
27151 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
27152 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
27154 double r
= XFLOATINT (lr
);
27155 double dx
= XINT (lx0
) - x
;
27156 double dy
= XINT (ly0
) - y
;
27157 return (dx
* dx
+ dy
* dy
<= r
* r
);
27160 else if (EQ (XCAR (hot_spot
), Qpoly
))
27162 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
27163 if (VECTORP (XCDR (hot_spot
)))
27165 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
27166 Lisp_Object
*poly
= v
->contents
;
27167 ptrdiff_t n
= v
->header
.size
;
27170 Lisp_Object lx
, ly
;
27173 /* Need an even number of coordinates, and at least 3 edges. */
27174 if (n
< 6 || n
& 1)
27177 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
27178 If count is odd, we are inside polygon. Pixels on edges
27179 may or may not be included depending on actual geometry of the
27181 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
27182 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
27184 x0
= XINT (lx
), y0
= XINT (ly
);
27185 for (i
= 0; i
< n
; i
+= 2)
27187 int x1
= x0
, y1
= y0
;
27188 if ((lx
= poly
[i
], !INTEGERP (lx
))
27189 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
27191 x0
= XINT (lx
), y0
= XINT (ly
);
27193 /* Does this segment cross the X line? */
27201 if (y
> y0
&& y
> y1
)
27203 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
27213 find_hot_spot (Lisp_Object map
, int x
, int y
)
27215 while (CONSP (map
))
27217 if (CONSP (XCAR (map
))
27218 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
27226 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
27228 doc
: /* Lookup in image map MAP coordinates X and Y.
27229 An image map is an alist where each element has the format (AREA ID PLIST).
27230 An AREA is specified as either a rectangle, a circle, or a polygon:
27231 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
27232 pixel coordinates of the upper left and bottom right corners.
27233 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
27234 and the radius of the circle; r may be a float or integer.
27235 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
27236 vector describes one corner in the polygon.
27237 Returns the alist element for the first matching AREA in MAP. */)
27238 (Lisp_Object map
, Lisp_Object x
, Lisp_Object y
)
27246 return find_hot_spot (map
,
27247 clip_to_bounds (INT_MIN
, XINT (x
), INT_MAX
),
27248 clip_to_bounds (INT_MIN
, XINT (y
), INT_MAX
));
27252 /* Display frame CURSOR, optionally using shape defined by POINTER. */
27254 define_frame_cursor1 (struct frame
*f
, Cursor cursor
, Lisp_Object pointer
)
27256 /* Do not change cursor shape while dragging mouse. */
27257 if (!NILP (do_mouse_tracking
))
27260 if (!NILP (pointer
))
27262 if (EQ (pointer
, Qarrow
))
27263 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27264 else if (EQ (pointer
, Qhand
))
27265 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
27266 else if (EQ (pointer
, Qtext
))
27267 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
27268 else if (EQ (pointer
, intern ("hdrag")))
27269 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
27270 #ifdef HAVE_X_WINDOWS
27271 else if (EQ (pointer
, intern ("vdrag")))
27272 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
27274 else if (EQ (pointer
, intern ("hourglass")))
27275 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
27276 else if (EQ (pointer
, Qmodeline
))
27277 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
27279 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27282 if (cursor
!= No_Cursor
)
27283 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
27286 #endif /* HAVE_WINDOW_SYSTEM */
27288 /* Take proper action when mouse has moved to the mode or header line
27289 or marginal area AREA of window W, x-position X and y-position Y.
27290 X is relative to the start of the text display area of W, so the
27291 width of bitmap areas and scroll bars must be subtracted to get a
27292 position relative to the start of the mode line. */
27295 note_mode_line_or_margin_highlight (Lisp_Object window
, int x
, int y
,
27296 enum window_part area
)
27298 struct window
*w
= XWINDOW (window
);
27299 struct frame
*f
= XFRAME (w
->frame
);
27300 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
27301 #ifdef HAVE_WINDOW_SYSTEM
27302 Display_Info
*dpyinfo
;
27304 Cursor cursor
= No_Cursor
;
27305 Lisp_Object pointer
= Qnil
;
27306 int dx
, dy
, width
, height
;
27308 Lisp_Object string
, object
= Qnil
;
27309 Lisp_Object pos
IF_LINT (= Qnil
), help
;
27311 Lisp_Object mouse_face
;
27312 int original_x_pixel
= x
;
27313 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
27314 struct glyph_row
*row
IF_LINT (= 0);
27316 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
27321 /* Kludge alert: mode_line_string takes X/Y in pixels, but
27322 returns them in row/column units! */
27323 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
27324 &object
, &dx
, &dy
, &width
, &height
);
27326 row
= (area
== ON_MODE_LINE
27327 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
27328 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
27330 /* Find the glyph under the mouse pointer. */
27331 if (row
->mode_line_p
&& row
->enabled_p
)
27333 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
27334 end
= glyph
+ row
->used
[TEXT_AREA
];
27336 for (x0
= original_x_pixel
;
27337 glyph
< end
&& x0
>= glyph
->pixel_width
;
27339 x0
-= glyph
->pixel_width
;
27347 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
27348 /* Kludge alert: marginal_area_string takes X/Y in pixels, but
27349 returns them in row/column units! */
27350 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
27351 &object
, &dx
, &dy
, &width
, &height
);
27356 #ifdef HAVE_WINDOW_SYSTEM
27357 if (IMAGEP (object
))
27359 Lisp_Object image_map
, hotspot
;
27360 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
27362 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
27364 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
27368 /* Could check XCAR (hotspot) to see if we enter/leave this hot-spot.
27369 If so, we could look for mouse-enter, mouse-leave
27370 properties in PLIST (and do something...). */
27371 hotspot
= XCDR (hotspot
);
27372 if (CONSP (hotspot
)
27373 && (plist
= XCAR (hotspot
), CONSP (plist
)))
27375 pointer
= Fplist_get (plist
, Qpointer
);
27376 if (NILP (pointer
))
27378 help
= Fplist_get (plist
, Qhelp_echo
);
27381 help_echo_string
= help
;
27382 XSETWINDOW (help_echo_window
, w
);
27383 help_echo_object
= w
->buffer
;
27384 help_echo_pos
= charpos
;
27388 if (NILP (pointer
))
27389 pointer
= Fplist_get (XCDR (object
), QCpointer
);
27391 #endif /* HAVE_WINDOW_SYSTEM */
27393 if (STRINGP (string
))
27394 pos
= make_number (charpos
);
27396 /* Set the help text and mouse pointer. If the mouse is on a part
27397 of the mode line without any text (e.g. past the right edge of
27398 the mode line text), use the default help text and pointer. */
27399 if (STRINGP (string
) || area
== ON_MODE_LINE
)
27401 /* Arrange to display the help by setting the global variables
27402 help_echo_string, help_echo_object, and help_echo_pos. */
27405 if (STRINGP (string
))
27406 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
27410 help_echo_string
= help
;
27411 XSETWINDOW (help_echo_window
, w
);
27412 help_echo_object
= string
;
27413 help_echo_pos
= charpos
;
27415 else if (area
== ON_MODE_LINE
)
27417 Lisp_Object default_help
27418 = buffer_local_value_1 (Qmode_line_default_help_echo
,
27421 if (STRINGP (default_help
))
27423 help_echo_string
= default_help
;
27424 XSETWINDOW (help_echo_window
, w
);
27425 help_echo_object
= Qnil
;
27426 help_echo_pos
= -1;
27431 #ifdef HAVE_WINDOW_SYSTEM
27432 /* Change the mouse pointer according to what is under it. */
27433 if (FRAME_WINDOW_P (f
))
27435 dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
27436 if (STRINGP (string
))
27438 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27440 if (NILP (pointer
))
27441 pointer
= Fget_text_property (pos
, Qpointer
, string
);
27443 /* Change the mouse pointer according to what is under X/Y. */
27445 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
27448 map
= Fget_text_property (pos
, Qlocal_map
, string
);
27449 if (!KEYMAPP (map
))
27450 map
= Fget_text_property (pos
, Qkeymap
, string
);
27451 if (!KEYMAPP (map
))
27452 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
27456 /* Default mode-line pointer. */
27457 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
27462 /* Change the mouse face according to what is under X/Y. */
27463 if (STRINGP (string
))
27465 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
27466 if (!NILP (mouse_face
)
27467 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
27472 struct glyph
* tmp_glyph
;
27476 int total_pixel_width
;
27477 ptrdiff_t begpos
, endpos
, ignore
;
27481 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
27482 Qmouse_face
, string
, Qnil
);
27488 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
27490 endpos
= SCHARS (string
);
27494 /* Calculate the glyph position GPOS of GLYPH in the
27495 displayed string, relative to the beginning of the
27496 highlighted part of the string.
27498 Note: GPOS is different from CHARPOS. CHARPOS is the
27499 position of GLYPH in the internal string object. A mode
27500 line string format has structures which are converted to
27501 a flattened string by the Emacs Lisp interpreter. The
27502 internal string is an element of those structures. The
27503 displayed string is the flattened string. */
27504 tmp_glyph
= row_start_glyph
;
27505 while (tmp_glyph
< glyph
27506 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
27507 && begpos
<= tmp_glyph
->charpos
27508 && tmp_glyph
->charpos
< endpos
)))
27510 gpos
= glyph
- tmp_glyph
;
27512 /* Calculate the length GSEQ_LENGTH of the glyph sequence of
27513 the highlighted part of the displayed string to which
27514 GLYPH belongs. Note: GSEQ_LENGTH is different from
27515 SCHARS (STRING), because the latter returns the length of
27516 the internal string. */
27517 for (tmp_glyph
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
27519 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
27520 && begpos
<= tmp_glyph
->charpos
27521 && tmp_glyph
->charpos
< endpos
));
27524 gseq_length
= gpos
+ (tmp_glyph
- glyph
) + 1;
27526 /* Calculate the total pixel width of all the glyphs between
27527 the beginning of the highlighted area and GLYPH. */
27528 total_pixel_width
= 0;
27529 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
27530 total_pixel_width
+= tmp_glyph
->pixel_width
;
27532 /* Pre calculation of re-rendering position. Note: X is in
27533 column units here, after the call to mode_line_string or
27534 marginal_area_string. */
27536 vpos
= (area
== ON_MODE_LINE
27537 ? (w
->current_matrix
)->nrows
- 1
27540 /* If GLYPH's position is included in the region that is
27541 already drawn in mouse face, we have nothing to do. */
27542 if ( EQ (window
, hlinfo
->mouse_face_window
)
27543 && (!row
->reversed_p
27544 ? (hlinfo
->mouse_face_beg_col
<= hpos
27545 && hpos
< hlinfo
->mouse_face_end_col
)
27546 /* In R2L rows we swap BEG and END, see below. */
27547 : (hlinfo
->mouse_face_end_col
<= hpos
27548 && hpos
< hlinfo
->mouse_face_beg_col
))
27549 && hlinfo
->mouse_face_beg_row
== vpos
)
27552 if (clear_mouse_face (hlinfo
))
27553 cursor
= No_Cursor
;
27555 if (!row
->reversed_p
)
27557 hlinfo
->mouse_face_beg_col
= hpos
;
27558 hlinfo
->mouse_face_beg_x
= original_x_pixel
27559 - (total_pixel_width
+ dx
);
27560 hlinfo
->mouse_face_end_col
= hpos
+ gseq_length
;
27561 hlinfo
->mouse_face_end_x
= 0;
27565 /* In R2L rows, show_mouse_face expects BEG and END
27566 coordinates to be swapped. */
27567 hlinfo
->mouse_face_end_col
= hpos
;
27568 hlinfo
->mouse_face_end_x
= original_x_pixel
27569 - (total_pixel_width
+ dx
);
27570 hlinfo
->mouse_face_beg_col
= hpos
+ gseq_length
;
27571 hlinfo
->mouse_face_beg_x
= 0;
27574 hlinfo
->mouse_face_beg_row
= vpos
;
27575 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_beg_row
;
27576 hlinfo
->mouse_face_beg_y
= 0;
27577 hlinfo
->mouse_face_end_y
= 0;
27578 hlinfo
->mouse_face_past_end
= 0;
27579 hlinfo
->mouse_face_window
= window
;
27581 hlinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
27587 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
27589 if (NILP (pointer
))
27592 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
27593 clear_mouse_face (hlinfo
);
27595 #ifdef HAVE_WINDOW_SYSTEM
27596 if (FRAME_WINDOW_P (f
))
27597 define_frame_cursor1 (f
, cursor
, pointer
);
27603 Take proper action when the mouse has moved to position X, Y on
27604 frame F as regards highlighting characters that have mouse-face
27605 properties. Also de-highlighting chars where the mouse was before.
27606 X and Y can be negative or out of range. */
27609 note_mouse_highlight (struct frame
*f
, int x
, int y
)
27611 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
27612 enum window_part part
= ON_NOTHING
;
27613 Lisp_Object window
;
27615 Cursor cursor
= No_Cursor
;
27616 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
27619 /* When a menu is active, don't highlight because this looks odd. */
27620 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (MSDOS)
27621 if (popup_activated ())
27625 if (NILP (Vmouse_highlight
)
27626 || !f
->glyphs_initialized_p
27627 || f
->pointer_invisible
)
27630 hlinfo
->mouse_face_mouse_x
= x
;
27631 hlinfo
->mouse_face_mouse_y
= y
;
27632 hlinfo
->mouse_face_mouse_frame
= f
;
27634 if (hlinfo
->mouse_face_defer
)
27637 if (gc_in_progress
)
27639 hlinfo
->mouse_face_deferred_gc
= 1;
27643 /* Which window is that in? */
27644 window
= window_from_coordinates (f
, x
, y
, &part
, 1);
27646 /* If displaying active text in another window, clear that. */
27647 if (! EQ (window
, hlinfo
->mouse_face_window
)
27648 /* Also clear if we move out of text area in same window. */
27649 || (!NILP (hlinfo
->mouse_face_window
)
27652 && part
!= ON_MODE_LINE
27653 && part
!= ON_HEADER_LINE
))
27654 clear_mouse_face (hlinfo
);
27656 /* Not on a window -> return. */
27657 if (!WINDOWP (window
))
27660 /* Reset help_echo_string. It will get recomputed below. */
27661 help_echo_string
= Qnil
;
27663 /* Convert to window-relative pixel coordinates. */
27664 w
= XWINDOW (window
);
27665 frame_to_window_pixel_xy (w
, &x
, &y
);
27667 #ifdef HAVE_WINDOW_SYSTEM
27668 /* Handle tool-bar window differently since it doesn't display a
27670 if (EQ (window
, f
->tool_bar_window
))
27672 note_tool_bar_highlight (f
, x
, y
);
27677 /* Mouse is on the mode, header line or margin? */
27678 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
27679 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
27681 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
27685 #ifdef HAVE_WINDOW_SYSTEM
27686 if (part
== ON_VERTICAL_BORDER
)
27688 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
27689 help_echo_string
= build_string ("drag-mouse-1: resize");
27691 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
27692 || part
== ON_SCROLL_BAR
)
27693 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27695 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
27698 /* Are we in a window whose display is up to date?
27699 And verify the buffer's text has not changed. */
27700 b
= XBUFFER (w
->buffer
);
27701 if (part
== ON_TEXT
27702 && EQ (w
->window_end_valid
, w
->buffer
)
27703 && w
->last_modified
== BUF_MODIFF (b
)
27704 && w
->last_overlay_modified
== BUF_OVERLAY_MODIFF (b
))
27706 int hpos
, vpos
, dx
, dy
, area
= LAST_AREA
;
27708 struct glyph
*glyph
;
27709 Lisp_Object object
;
27710 Lisp_Object mouse_face
= Qnil
, position
;
27711 Lisp_Object
*overlay_vec
= NULL
;
27712 ptrdiff_t i
, noverlays
;
27713 struct buffer
*obuf
;
27714 ptrdiff_t obegv
, ozv
;
27717 /* Find the glyph under X/Y. */
27718 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
27720 #ifdef HAVE_WINDOW_SYSTEM
27721 /* Look for :pointer property on image. */
27722 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
27724 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
27725 if (img
!= NULL
&& IMAGEP (img
->spec
))
27727 Lisp_Object image_map
, hotspot
;
27728 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
27730 && (hotspot
= find_hot_spot (image_map
,
27731 glyph
->slice
.img
.x
+ dx
,
27732 glyph
->slice
.img
.y
+ dy
),
27734 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
27738 /* Could check XCAR (hotspot) to see if we enter/leave
27740 If so, we could look for mouse-enter, mouse-leave
27741 properties in PLIST (and do something...). */
27742 hotspot
= XCDR (hotspot
);
27743 if (CONSP (hotspot
)
27744 && (plist
= XCAR (hotspot
), CONSP (plist
)))
27746 pointer
= Fplist_get (plist
, Qpointer
);
27747 if (NILP (pointer
))
27749 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
27750 if (!NILP (help_echo_string
))
27752 help_echo_window
= window
;
27753 help_echo_object
= glyph
->object
;
27754 help_echo_pos
= glyph
->charpos
;
27758 if (NILP (pointer
))
27759 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
27762 #endif /* HAVE_WINDOW_SYSTEM */
27764 /* Clear mouse face if X/Y not over text. */
27766 || area
!= TEXT_AREA
27767 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
27768 /* Glyph's OBJECT is an integer for glyphs inserted by the
27769 display engine for its internal purposes, like truncation
27770 and continuation glyphs and blanks beyond the end of
27771 line's text on text terminals. If we are over such a
27772 glyph, we are not over any text. */
27773 || INTEGERP (glyph
->object
)
27774 /* R2L rows have a stretch glyph at their front, which
27775 stands for no text, whereas L2R rows have no glyphs at
27776 all beyond the end of text. Treat such stretch glyphs
27777 like we do with NULL glyphs in L2R rows. */
27778 || (MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
27779 && glyph
== MATRIX_ROW (w
->current_matrix
, vpos
)->glyphs
[TEXT_AREA
]
27780 && glyph
->type
== STRETCH_GLYPH
27781 && glyph
->avoid_cursor_p
))
27783 if (clear_mouse_face (hlinfo
))
27784 cursor
= No_Cursor
;
27785 #ifdef HAVE_WINDOW_SYSTEM
27786 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
27788 if (area
!= TEXT_AREA
)
27789 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27791 pointer
= Vvoid_text_area_pointer
;
27797 pos
= glyph
->charpos
;
27798 object
= glyph
->object
;
27799 if (!STRINGP (object
) && !BUFFERP (object
))
27802 /* If we get an out-of-range value, return now; avoid an error. */
27803 if (BUFFERP (object
) && pos
> BUF_Z (b
))
27806 /* Make the window's buffer temporarily current for
27807 overlays_at and compute_char_face. */
27808 obuf
= current_buffer
;
27809 current_buffer
= b
;
27815 /* Is this char mouse-active or does it have help-echo? */
27816 position
= make_number (pos
);
27818 if (BUFFERP (object
))
27820 /* Put all the overlays we want in a vector in overlay_vec. */
27821 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
27822 /* Sort overlays into increasing priority order. */
27823 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
27828 same_region
= coords_in_mouse_face_p (w
, hpos
, vpos
);
27831 cursor
= No_Cursor
;
27833 /* Check mouse-face highlighting. */
27835 /* If there exists an overlay with mouse-face overlapping
27836 the one we are currently highlighting, we have to
27837 check if we enter the overlapping overlay, and then
27838 highlight only that. */
27839 || (OVERLAYP (hlinfo
->mouse_face_overlay
)
27840 && mouse_face_overlay_overlaps (hlinfo
->mouse_face_overlay
)))
27842 /* Find the highest priority overlay with a mouse-face. */
27843 Lisp_Object overlay
= Qnil
;
27844 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
27846 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
27847 if (!NILP (mouse_face
))
27848 overlay
= overlay_vec
[i
];
27851 /* If we're highlighting the same overlay as before, there's
27852 no need to do that again. */
27853 if (!NILP (overlay
) && EQ (overlay
, hlinfo
->mouse_face_overlay
))
27854 goto check_help_echo
;
27855 hlinfo
->mouse_face_overlay
= overlay
;
27857 /* Clear the display of the old active region, if any. */
27858 if (clear_mouse_face (hlinfo
))
27859 cursor
= No_Cursor
;
27861 /* If no overlay applies, get a text property. */
27862 if (NILP (overlay
))
27863 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
27865 /* Next, compute the bounds of the mouse highlighting and
27867 if (!NILP (mouse_face
) && STRINGP (object
))
27869 /* The mouse-highlighting comes from a display string
27870 with a mouse-face. */
27874 s
= Fprevious_single_property_change
27875 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
27876 e
= Fnext_single_property_change
27877 (position
, Qmouse_face
, object
, Qnil
);
27879 s
= make_number (0);
27881 e
= make_number (SCHARS (object
) - 1);
27882 mouse_face_from_string_pos (w
, hlinfo
, object
,
27883 XINT (s
), XINT (e
));
27884 hlinfo
->mouse_face_past_end
= 0;
27885 hlinfo
->mouse_face_window
= window
;
27886 hlinfo
->mouse_face_face_id
27887 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
27888 glyph
->face_id
, 1);
27889 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
27890 cursor
= No_Cursor
;
27894 /* The mouse-highlighting, if any, comes from an overlay
27895 or text property in the buffer. */
27896 Lisp_Object buffer
IF_LINT (= Qnil
);
27897 Lisp_Object disp_string
IF_LINT (= Qnil
);
27899 if (STRINGP (object
))
27901 /* If we are on a display string with no mouse-face,
27902 check if the text under it has one. */
27903 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
27904 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
27905 pos
= string_buffer_position (object
, start
);
27908 mouse_face
= get_char_property_and_overlay
27909 (make_number (pos
), Qmouse_face
, w
->buffer
, &overlay
);
27910 buffer
= w
->buffer
;
27911 disp_string
= object
;
27917 disp_string
= Qnil
;
27920 if (!NILP (mouse_face
))
27922 Lisp_Object before
, after
;
27923 Lisp_Object before_string
, after_string
;
27924 /* To correctly find the limits of mouse highlight
27925 in a bidi-reordered buffer, we must not use the
27926 optimization of limiting the search in
27927 previous-single-property-change and
27928 next-single-property-change, because
27929 rows_from_pos_range needs the real start and end
27930 positions to DTRT in this case. That's because
27931 the first row visible in a window does not
27932 necessarily display the character whose position
27933 is the smallest. */
27935 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
27936 ? Fmarker_position (w
->start
)
27939 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
27940 ? make_number (BUF_Z (XBUFFER (buffer
))
27941 - XFASTINT (w
->window_end_pos
))
27944 if (NILP (overlay
))
27946 /* Handle the text property case. */
27947 before
= Fprevious_single_property_change
27948 (make_number (pos
+ 1), Qmouse_face
, buffer
, lim1
);
27949 after
= Fnext_single_property_change
27950 (make_number (pos
), Qmouse_face
, buffer
, lim2
);
27951 before_string
= after_string
= Qnil
;
27955 /* Handle the overlay case. */
27956 before
= Foverlay_start (overlay
);
27957 after
= Foverlay_end (overlay
);
27958 before_string
= Foverlay_get (overlay
, Qbefore_string
);
27959 after_string
= Foverlay_get (overlay
, Qafter_string
);
27961 if (!STRINGP (before_string
)) before_string
= Qnil
;
27962 if (!STRINGP (after_string
)) after_string
= Qnil
;
27965 mouse_face_from_buffer_pos (window
, hlinfo
, pos
,
27968 : XFASTINT (before
),
27970 ? BUF_Z (XBUFFER (buffer
))
27971 : XFASTINT (after
),
27972 before_string
, after_string
,
27974 cursor
= No_Cursor
;
27981 /* Look for a `help-echo' property. */
27982 if (NILP (help_echo_string
)) {
27983 Lisp_Object help
, overlay
;
27985 /* Check overlays first. */
27986 help
= overlay
= Qnil
;
27987 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
27989 overlay
= overlay_vec
[i
];
27990 help
= Foverlay_get (overlay
, Qhelp_echo
);
27995 help_echo_string
= help
;
27996 help_echo_window
= window
;
27997 help_echo_object
= overlay
;
27998 help_echo_pos
= pos
;
28002 Lisp_Object obj
= glyph
->object
;
28003 ptrdiff_t charpos
= glyph
->charpos
;
28005 /* Try text properties. */
28008 && charpos
< SCHARS (obj
))
28010 help
= Fget_text_property (make_number (charpos
),
28014 /* If the string itself doesn't specify a help-echo,
28015 see if the buffer text ``under'' it does. */
28016 struct glyph_row
*r
28017 = MATRIX_ROW (w
->current_matrix
, vpos
);
28018 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28019 ptrdiff_t p
= string_buffer_position (obj
, start
);
28022 help
= Fget_char_property (make_number (p
),
28023 Qhelp_echo
, w
->buffer
);
28032 else if (BUFFERP (obj
)
28035 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
28040 help_echo_string
= help
;
28041 help_echo_window
= window
;
28042 help_echo_object
= obj
;
28043 help_echo_pos
= charpos
;
28048 #ifdef HAVE_WINDOW_SYSTEM
28049 /* Look for a `pointer' property. */
28050 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
28052 /* Check overlays first. */
28053 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
28054 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
28056 if (NILP (pointer
))
28058 Lisp_Object obj
= glyph
->object
;
28059 ptrdiff_t charpos
= glyph
->charpos
;
28061 /* Try text properties. */
28064 && charpos
< SCHARS (obj
))
28066 pointer
= Fget_text_property (make_number (charpos
),
28068 if (NILP (pointer
))
28070 /* If the string itself doesn't specify a pointer,
28071 see if the buffer text ``under'' it does. */
28072 struct glyph_row
*r
28073 = MATRIX_ROW (w
->current_matrix
, vpos
);
28074 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28075 ptrdiff_t p
= string_buffer_position (obj
, start
);
28077 pointer
= Fget_char_property (make_number (p
),
28078 Qpointer
, w
->buffer
);
28081 else if (BUFFERP (obj
)
28084 pointer
= Fget_text_property (make_number (charpos
),
28088 #endif /* HAVE_WINDOW_SYSTEM */
28092 current_buffer
= obuf
;
28097 #ifdef HAVE_WINDOW_SYSTEM
28098 if (FRAME_WINDOW_P (f
))
28099 define_frame_cursor1 (f
, cursor
, pointer
);
28101 /* This is here to prevent a compiler error, about "label at end of
28102 compound statement". */
28109 Clear any mouse-face on window W. This function is part of the
28110 redisplay interface, and is called from try_window_id and similar
28111 functions to ensure the mouse-highlight is off. */
28114 x_clear_window_mouse_face (struct window
*w
)
28116 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
28117 Lisp_Object window
;
28120 XSETWINDOW (window
, w
);
28121 if (EQ (window
, hlinfo
->mouse_face_window
))
28122 clear_mouse_face (hlinfo
);
28128 Just discard the mouse face information for frame F, if any.
28129 This is used when the size of F is changed. */
28132 cancel_mouse_face (struct frame
*f
)
28134 Lisp_Object window
;
28135 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28137 window
= hlinfo
->mouse_face_window
;
28138 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
28140 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
28141 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
28142 hlinfo
->mouse_face_window
= Qnil
;
28148 /***********************************************************************
28150 ***********************************************************************/
28152 #ifdef HAVE_WINDOW_SYSTEM
28154 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
28155 which intersects rectangle R. R is in window-relative coordinates. */
28158 expose_area (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
,
28159 enum glyph_row_area area
)
28161 struct glyph
*first
= row
->glyphs
[area
];
28162 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
28163 struct glyph
*last
;
28164 int first_x
, start_x
, x
;
28166 if (area
== TEXT_AREA
&& row
->fill_line_p
)
28167 /* If row extends face to end of line write the whole line. */
28168 draw_glyphs (w
, 0, row
, area
,
28169 0, row
->used
[area
],
28170 DRAW_NORMAL_TEXT
, 0);
28173 /* Set START_X to the window-relative start position for drawing glyphs of
28174 AREA. The first glyph of the text area can be partially visible.
28175 The first glyphs of other areas cannot. */
28176 start_x
= window_box_left_offset (w
, area
);
28178 if (area
== TEXT_AREA
)
28181 /* Find the first glyph that must be redrawn. */
28183 && x
+ first
->pixel_width
< r
->x
)
28185 x
+= first
->pixel_width
;
28189 /* Find the last one. */
28193 && x
< r
->x
+ r
->width
)
28195 x
+= last
->pixel_width
;
28201 draw_glyphs (w
, first_x
- start_x
, row
, area
,
28202 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
28203 DRAW_NORMAL_TEXT
, 0);
28208 /* Redraw the parts of the glyph row ROW on window W intersecting
28209 rectangle R. R is in window-relative coordinates. Value is
28210 non-zero if mouse-face was overwritten. */
28213 expose_line (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
)
28215 eassert (row
->enabled_p
);
28217 if (row
->mode_line_p
|| w
->pseudo_window_p
)
28218 draw_glyphs (w
, 0, row
, TEXT_AREA
,
28219 0, row
->used
[TEXT_AREA
],
28220 DRAW_NORMAL_TEXT
, 0);
28223 if (row
->used
[LEFT_MARGIN_AREA
])
28224 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
28225 if (row
->used
[TEXT_AREA
])
28226 expose_area (w
, row
, r
, TEXT_AREA
);
28227 if (row
->used
[RIGHT_MARGIN_AREA
])
28228 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
28229 draw_row_fringe_bitmaps (w
, row
);
28232 return row
->mouse_face_p
;
28236 /* Redraw those parts of glyphs rows during expose event handling that
28237 overlap other rows. Redrawing of an exposed line writes over parts
28238 of lines overlapping that exposed line; this function fixes that.
28240 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
28241 row in W's current matrix that is exposed and overlaps other rows.
28242 LAST_OVERLAPPING_ROW is the last such row. */
28245 expose_overlaps (struct window
*w
,
28246 struct glyph_row
*first_overlapping_row
,
28247 struct glyph_row
*last_overlapping_row
,
28250 struct glyph_row
*row
;
28252 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
28253 if (row
->overlapping_p
)
28255 eassert (row
->enabled_p
&& !row
->mode_line_p
);
28258 if (row
->used
[LEFT_MARGIN_AREA
])
28259 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
28261 if (row
->used
[TEXT_AREA
])
28262 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
28264 if (row
->used
[RIGHT_MARGIN_AREA
])
28265 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
28271 /* Return non-zero if W's cursor intersects rectangle R. */
28274 phys_cursor_in_rect_p (struct window
*w
, XRectangle
*r
)
28276 XRectangle cr
, result
;
28277 struct glyph
*cursor_glyph
;
28278 struct glyph_row
*row
;
28280 if (w
->phys_cursor
.vpos
>= 0
28281 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
28282 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
28284 && row
->cursor_in_fringe_p
)
28286 /* Cursor is in the fringe. */
28287 cr
.x
= window_box_right_offset (w
,
28288 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
28289 ? RIGHT_MARGIN_AREA
28292 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
28293 cr
.height
= row
->height
;
28294 return x_intersect_rectangles (&cr
, r
, &result
);
28297 cursor_glyph
= get_phys_cursor_glyph (w
);
28300 /* r is relative to W's box, but w->phys_cursor.x is relative
28301 to left edge of W's TEXT area. Adjust it. */
28302 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
28303 cr
.y
= w
->phys_cursor
.y
;
28304 cr
.width
= cursor_glyph
->pixel_width
;
28305 cr
.height
= w
->phys_cursor_height
;
28306 /* ++KFS: W32 version used W32-specific IntersectRect here, but
28307 I assume the effect is the same -- and this is portable. */
28308 return x_intersect_rectangles (&cr
, r
, &result
);
28310 /* If we don't understand the format, pretend we're not in the hot-spot. */
28316 Draw a vertical window border to the right of window W if W doesn't
28317 have vertical scroll bars. */
28320 x_draw_vertical_border (struct window
*w
)
28322 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
28324 /* We could do better, if we knew what type of scroll-bar the adjacent
28325 windows (on either side) have... But we don't :-(
28326 However, I think this works ok. ++KFS 2003-04-25 */
28328 /* Redraw borders between horizontally adjacent windows. Don't
28329 do it for frames with vertical scroll bars because either the
28330 right scroll bar of a window, or the left scroll bar of its
28331 neighbor will suffice as a border. */
28332 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
28335 if (!WINDOW_RIGHTMOST_P (w
)
28336 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
28338 int x0
, x1
, y0
, y1
;
28340 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
28343 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
28346 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
28348 else if (!WINDOW_LEFTMOST_P (w
)
28349 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
28351 int x0
, x1
, y0
, y1
;
28353 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
28356 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
28359 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
28364 /* Redraw the part of window W intersection rectangle FR. Pixel
28365 coordinates in FR are frame-relative. Call this function with
28366 input blocked. Value is non-zero if the exposure overwrites
28370 expose_window (struct window
*w
, XRectangle
*fr
)
28372 struct frame
*f
= XFRAME (w
->frame
);
28374 int mouse_face_overwritten_p
= 0;
28376 /* If window is not yet fully initialized, do nothing. This can
28377 happen when toolkit scroll bars are used and a window is split.
28378 Reconfiguring the scroll bar will generate an expose for a newly
28380 if (w
->current_matrix
== NULL
)
28383 /* When we're currently updating the window, display and current
28384 matrix usually don't agree. Arrange for a thorough display
28386 if (w
== updated_window
)
28388 SET_FRAME_GARBAGED (f
);
28392 /* Frame-relative pixel rectangle of W. */
28393 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
28394 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
28395 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
28396 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
28398 if (x_intersect_rectangles (fr
, &wr
, &r
))
28400 int yb
= window_text_bottom_y (w
);
28401 struct glyph_row
*row
;
28402 int cursor_cleared_p
, phys_cursor_on_p
;
28403 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
28405 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
28406 r
.x
, r
.y
, r
.width
, r
.height
));
28408 /* Convert to window coordinates. */
28409 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
28410 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
28412 /* Turn off the cursor. */
28413 if (!w
->pseudo_window_p
28414 && phys_cursor_in_rect_p (w
, &r
))
28416 x_clear_cursor (w
);
28417 cursor_cleared_p
= 1;
28420 cursor_cleared_p
= 0;
28422 /* If the row containing the cursor extends face to end of line,
28423 then expose_area might overwrite the cursor outside the
28424 rectangle and thus notice_overwritten_cursor might clear
28425 w->phys_cursor_on_p. We remember the original value and
28426 check later if it is changed. */
28427 phys_cursor_on_p
= w
->phys_cursor_on_p
;
28429 /* Update lines intersecting rectangle R. */
28430 first_overlapping_row
= last_overlapping_row
= NULL
;
28431 for (row
= w
->current_matrix
->rows
;
28436 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
28438 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
28439 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
28440 || (r
.y
>= y0
&& r
.y
< y1
)
28441 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
28443 /* A header line may be overlapping, but there is no need
28444 to fix overlapping areas for them. KFS 2005-02-12 */
28445 if (row
->overlapping_p
&& !row
->mode_line_p
)
28447 if (first_overlapping_row
== NULL
)
28448 first_overlapping_row
= row
;
28449 last_overlapping_row
= row
;
28453 if (expose_line (w
, row
, &r
))
28454 mouse_face_overwritten_p
= 1;
28457 else if (row
->overlapping_p
)
28459 /* We must redraw a row overlapping the exposed area. */
28461 ? y0
+ row
->phys_height
> r
.y
28462 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
28464 if (first_overlapping_row
== NULL
)
28465 first_overlapping_row
= row
;
28466 last_overlapping_row
= row
;
28474 /* Display the mode line if there is one. */
28475 if (WINDOW_WANTS_MODELINE_P (w
)
28476 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
28478 && row
->y
< r
.y
+ r
.height
)
28480 if (expose_line (w
, row
, &r
))
28481 mouse_face_overwritten_p
= 1;
28484 if (!w
->pseudo_window_p
)
28486 /* Fix the display of overlapping rows. */
28487 if (first_overlapping_row
)
28488 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
28491 /* Draw border between windows. */
28492 x_draw_vertical_border (w
);
28494 /* Turn the cursor on again. */
28495 if (cursor_cleared_p
28496 || (phys_cursor_on_p
&& !w
->phys_cursor_on_p
))
28497 update_window_cursor (w
, 1);
28501 return mouse_face_overwritten_p
;
28506 /* Redraw (parts) of all windows in the window tree rooted at W that
28507 intersect R. R contains frame pixel coordinates. Value is
28508 non-zero if the exposure overwrites mouse-face. */
28511 expose_window_tree (struct window
*w
, XRectangle
*r
)
28513 struct frame
*f
= XFRAME (w
->frame
);
28514 int mouse_face_overwritten_p
= 0;
28516 while (w
&& !FRAME_GARBAGED_P (f
))
28518 if (!NILP (w
->hchild
))
28519 mouse_face_overwritten_p
28520 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
28521 else if (!NILP (w
->vchild
))
28522 mouse_face_overwritten_p
28523 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
28525 mouse_face_overwritten_p
|= expose_window (w
, r
);
28527 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
28530 return mouse_face_overwritten_p
;
28535 Redisplay an exposed area of frame F. X and Y are the upper-left
28536 corner of the exposed rectangle. W and H are width and height of
28537 the exposed area. All are pixel values. W or H zero means redraw
28538 the entire frame. */
28541 expose_frame (struct frame
*f
, int x
, int y
, int w
, int h
)
28544 int mouse_face_overwritten_p
= 0;
28546 TRACE ((stderr
, "expose_frame "));
28548 /* No need to redraw if frame will be redrawn soon. */
28549 if (FRAME_GARBAGED_P (f
))
28551 TRACE ((stderr
, " garbaged\n"));
28555 /* If basic faces haven't been realized yet, there is no point in
28556 trying to redraw anything. This can happen when we get an expose
28557 event while Emacs is starting, e.g. by moving another window. */
28558 if (FRAME_FACE_CACHE (f
) == NULL
28559 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
28561 TRACE ((stderr
, " no faces\n"));
28565 if (w
== 0 || h
== 0)
28568 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
28569 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
28579 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
28580 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
28582 if (WINDOWP (f
->tool_bar_window
))
28583 mouse_face_overwritten_p
28584 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
28586 #ifdef HAVE_X_WINDOWS
28588 #ifndef USE_X_TOOLKIT
28589 if (WINDOWP (f
->menu_bar_window
))
28590 mouse_face_overwritten_p
28591 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
28592 #endif /* not USE_X_TOOLKIT */
28596 /* Some window managers support a focus-follows-mouse style with
28597 delayed raising of frames. Imagine a partially obscured frame,
28598 and moving the mouse into partially obscured mouse-face on that
28599 frame. The visible part of the mouse-face will be highlighted,
28600 then the WM raises the obscured frame. With at least one WM, KDE
28601 2.1, Emacs is not getting any event for the raising of the frame
28602 (even tried with SubstructureRedirectMask), only Expose events.
28603 These expose events will draw text normally, i.e. not
28604 highlighted. Which means we must redo the highlight here.
28605 Subsume it under ``we love X''. --gerd 2001-08-15 */
28606 /* Included in Windows version because Windows most likely does not
28607 do the right thing if any third party tool offers
28608 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
28609 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
28611 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28612 if (f
== hlinfo
->mouse_face_mouse_frame
)
28614 int mouse_x
= hlinfo
->mouse_face_mouse_x
;
28615 int mouse_y
= hlinfo
->mouse_face_mouse_y
;
28616 clear_mouse_face (hlinfo
);
28617 note_mouse_highlight (f
, mouse_x
, mouse_y
);
28624 Determine the intersection of two rectangles R1 and R2. Return
28625 the intersection in *RESULT. Value is non-zero if RESULT is not
28629 x_intersect_rectangles (XRectangle
*r1
, XRectangle
*r2
, XRectangle
*result
)
28631 XRectangle
*left
, *right
;
28632 XRectangle
*upper
, *lower
;
28633 int intersection_p
= 0;
28635 /* Rearrange so that R1 is the left-most rectangle. */
28637 left
= r1
, right
= r2
;
28639 left
= r2
, right
= r1
;
28641 /* X0 of the intersection is right.x0, if this is inside R1,
28642 otherwise there is no intersection. */
28643 if (right
->x
<= left
->x
+ left
->width
)
28645 result
->x
= right
->x
;
28647 /* The right end of the intersection is the minimum of
28648 the right ends of left and right. */
28649 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
28652 /* Same game for Y. */
28654 upper
= r1
, lower
= r2
;
28656 upper
= r2
, lower
= r1
;
28658 /* The upper end of the intersection is lower.y0, if this is inside
28659 of upper. Otherwise, there is no intersection. */
28660 if (lower
->y
<= upper
->y
+ upper
->height
)
28662 result
->y
= lower
->y
;
28664 /* The lower end of the intersection is the minimum of the lower
28665 ends of upper and lower. */
28666 result
->height
= (min (lower
->y
+ lower
->height
,
28667 upper
->y
+ upper
->height
)
28669 intersection_p
= 1;
28673 return intersection_p
;
28676 #endif /* HAVE_WINDOW_SYSTEM */
28679 /***********************************************************************
28681 ***********************************************************************/
28684 syms_of_xdisp (void)
28686 Vwith_echo_area_save_vector
= Qnil
;
28687 staticpro (&Vwith_echo_area_save_vector
);
28689 Vmessage_stack
= Qnil
;
28690 staticpro (&Vmessage_stack
);
28692 DEFSYM (Qinhibit_redisplay
, "inhibit-redisplay");
28694 message_dolog_marker1
= Fmake_marker ();
28695 staticpro (&message_dolog_marker1
);
28696 message_dolog_marker2
= Fmake_marker ();
28697 staticpro (&message_dolog_marker2
);
28698 message_dolog_marker3
= Fmake_marker ();
28699 staticpro (&message_dolog_marker3
);
28702 defsubr (&Sdump_frame_glyph_matrix
);
28703 defsubr (&Sdump_glyph_matrix
);
28704 defsubr (&Sdump_glyph_row
);
28705 defsubr (&Sdump_tool_bar_row
);
28706 defsubr (&Strace_redisplay
);
28707 defsubr (&Strace_to_stderr
);
28709 #ifdef HAVE_WINDOW_SYSTEM
28710 defsubr (&Stool_bar_lines_needed
);
28711 defsubr (&Slookup_image_map
);
28713 defsubr (&Sformat_mode_line
);
28714 defsubr (&Sinvisible_p
);
28715 defsubr (&Scurrent_bidi_paragraph_direction
);
28717 DEFSYM (Qmenu_bar_update_hook
, "menu-bar-update-hook");
28718 DEFSYM (Qoverriding_terminal_local_map
, "overriding-terminal-local-map");
28719 DEFSYM (Qoverriding_local_map
, "overriding-local-map");
28720 DEFSYM (Qwindow_scroll_functions
, "window-scroll-functions");
28721 DEFSYM (Qwindow_text_change_functions
, "window-text-change-functions");
28722 DEFSYM (Qredisplay_end_trigger_functions
, "redisplay-end-trigger-functions");
28723 DEFSYM (Qinhibit_point_motion_hooks
, "inhibit-point-motion-hooks");
28724 DEFSYM (Qeval
, "eval");
28725 DEFSYM (QCdata
, ":data");
28726 DEFSYM (Qdisplay
, "display");
28727 DEFSYM (Qspace_width
, "space-width");
28728 DEFSYM (Qraise
, "raise");
28729 DEFSYM (Qslice
, "slice");
28730 DEFSYM (Qspace
, "space");
28731 DEFSYM (Qmargin
, "margin");
28732 DEFSYM (Qpointer
, "pointer");
28733 DEFSYM (Qleft_margin
, "left-margin");
28734 DEFSYM (Qright_margin
, "right-margin");
28735 DEFSYM (Qcenter
, "center");
28736 DEFSYM (Qline_height
, "line-height");
28737 DEFSYM (QCalign_to
, ":align-to");
28738 DEFSYM (QCrelative_width
, ":relative-width");
28739 DEFSYM (QCrelative_height
, ":relative-height");
28740 DEFSYM (QCeval
, ":eval");
28741 DEFSYM (QCpropertize
, ":propertize");
28742 DEFSYM (QCfile
, ":file");
28743 DEFSYM (Qfontified
, "fontified");
28744 DEFSYM (Qfontification_functions
, "fontification-functions");
28745 DEFSYM (Qtrailing_whitespace
, "trailing-whitespace");
28746 DEFSYM (Qescape_glyph
, "escape-glyph");
28747 DEFSYM (Qnobreak_space
, "nobreak-space");
28748 DEFSYM (Qimage
, "image");
28749 DEFSYM (Qtext
, "text");
28750 DEFSYM (Qboth
, "both");
28751 DEFSYM (Qboth_horiz
, "both-horiz");
28752 DEFSYM (Qtext_image_horiz
, "text-image-horiz");
28753 DEFSYM (QCmap
, ":map");
28754 DEFSYM (QCpointer
, ":pointer");
28755 DEFSYM (Qrect
, "rect");
28756 DEFSYM (Qcircle
, "circle");
28757 DEFSYM (Qpoly
, "poly");
28758 DEFSYM (Qmessage_truncate_lines
, "message-truncate-lines");
28759 DEFSYM (Qgrow_only
, "grow-only");
28760 DEFSYM (Qinhibit_menubar_update
, "inhibit-menubar-update");
28761 DEFSYM (Qinhibit_eval_during_redisplay
, "inhibit-eval-during-redisplay");
28762 DEFSYM (Qposition
, "position");
28763 DEFSYM (Qbuffer_position
, "buffer-position");
28764 DEFSYM (Qobject
, "object");
28765 DEFSYM (Qbar
, "bar");
28766 DEFSYM (Qhbar
, "hbar");
28767 DEFSYM (Qbox
, "box");
28768 DEFSYM (Qhollow
, "hollow");
28769 DEFSYM (Qhand
, "hand");
28770 DEFSYM (Qarrow
, "arrow");
28771 DEFSYM (Qinhibit_free_realized_faces
, "inhibit-free-realized-faces");
28773 list_of_error
= Fcons (Fcons (intern_c_string ("error"),
28774 Fcons (intern_c_string ("void-variable"), Qnil
)),
28776 staticpro (&list_of_error
);
28778 DEFSYM (Qlast_arrow_position
, "last-arrow-position");
28779 DEFSYM (Qlast_arrow_string
, "last-arrow-string");
28780 DEFSYM (Qoverlay_arrow_string
, "overlay-arrow-string");
28781 DEFSYM (Qoverlay_arrow_bitmap
, "overlay-arrow-bitmap");
28783 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
28784 staticpro (&echo_buffer
[0]);
28785 staticpro (&echo_buffer
[1]);
28787 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
28788 staticpro (&echo_area_buffer
[0]);
28789 staticpro (&echo_area_buffer
[1]);
28791 Vmessages_buffer_name
= build_pure_c_string ("*Messages*");
28792 staticpro (&Vmessages_buffer_name
);
28794 mode_line_proptrans_alist
= Qnil
;
28795 staticpro (&mode_line_proptrans_alist
);
28796 mode_line_string_list
= Qnil
;
28797 staticpro (&mode_line_string_list
);
28798 mode_line_string_face
= Qnil
;
28799 staticpro (&mode_line_string_face
);
28800 mode_line_string_face_prop
= Qnil
;
28801 staticpro (&mode_line_string_face_prop
);
28802 Vmode_line_unwind_vector
= Qnil
;
28803 staticpro (&Vmode_line_unwind_vector
);
28805 DEFSYM (Qmode_line_default_help_echo
, "mode-line-default-help-echo");
28807 help_echo_string
= Qnil
;
28808 staticpro (&help_echo_string
);
28809 help_echo_object
= Qnil
;
28810 staticpro (&help_echo_object
);
28811 help_echo_window
= Qnil
;
28812 staticpro (&help_echo_window
);
28813 previous_help_echo_string
= Qnil
;
28814 staticpro (&previous_help_echo_string
);
28815 help_echo_pos
= -1;
28817 DEFSYM (Qright_to_left
, "right-to-left");
28818 DEFSYM (Qleft_to_right
, "left-to-right");
28820 #ifdef HAVE_WINDOW_SYSTEM
28821 DEFVAR_BOOL ("x-stretch-cursor", x_stretch_cursor_p
,
28822 doc
: /* Non-nil means draw block cursor as wide as the glyph under it.
28823 For example, if a block cursor is over a tab, it will be drawn as
28824 wide as that tab on the display. */);
28825 x_stretch_cursor_p
= 0;
28828 DEFVAR_LISP ("show-trailing-whitespace", Vshow_trailing_whitespace
,
28829 doc
: /* Non-nil means highlight trailing whitespace.
28830 The face used for trailing whitespace is `trailing-whitespace'. */);
28831 Vshow_trailing_whitespace
= Qnil
;
28833 DEFVAR_LISP ("nobreak-char-display", Vnobreak_char_display
,
28834 doc
: /* Control highlighting of non-ASCII space and hyphen chars.
28835 If the value is t, Emacs highlights non-ASCII chars which have the
28836 same appearance as an ASCII space or hyphen, using the `nobreak-space'
28837 or `escape-glyph' face respectively.
28839 U+00A0 (no-break space), U+00AD (soft hyphen), U+2010 (hyphen), and
28840 U+2011 (non-breaking hyphen) are affected.
28842 Any other non-nil value means to display these characters as a escape
28843 glyph followed by an ordinary space or hyphen.
28845 A value of nil means no special handling of these characters. */);
28846 Vnobreak_char_display
= Qt
;
28848 DEFVAR_LISP ("void-text-area-pointer", Vvoid_text_area_pointer
,
28849 doc
: /* The pointer shape to show in void text areas.
28850 A value of nil means to show the text pointer. Other options are `arrow',
28851 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
28852 Vvoid_text_area_pointer
= Qarrow
;
28854 DEFVAR_LISP ("inhibit-redisplay", Vinhibit_redisplay
,
28855 doc
: /* Non-nil means don't actually do any redisplay.
28856 This is used for internal purposes. */);
28857 Vinhibit_redisplay
= Qnil
;
28859 DEFVAR_LISP ("global-mode-string", Vglobal_mode_string
,
28860 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
28861 Vglobal_mode_string
= Qnil
;
28863 DEFVAR_LISP ("overlay-arrow-position", Voverlay_arrow_position
,
28864 doc
: /* Marker for where to display an arrow on top of the buffer text.
28865 This must be the beginning of a line in order to work.
28866 See also `overlay-arrow-string'. */);
28867 Voverlay_arrow_position
= Qnil
;
28869 DEFVAR_LISP ("overlay-arrow-string", Voverlay_arrow_string
,
28870 doc
: /* String to display as an arrow in non-window frames.
28871 See also `overlay-arrow-position'. */);
28872 Voverlay_arrow_string
= build_pure_c_string ("=>");
28874 DEFVAR_LISP ("overlay-arrow-variable-list", Voverlay_arrow_variable_list
,
28875 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
28876 The symbols on this list are examined during redisplay to determine
28877 where to display overlay arrows. */);
28878 Voverlay_arrow_variable_list
28879 = Fcons (intern_c_string ("overlay-arrow-position"), Qnil
);
28881 DEFVAR_INT ("scroll-step", emacs_scroll_step
,
28882 doc
: /* The number of lines to try scrolling a window by when point moves out.
28883 If that fails to bring point back on frame, point is centered instead.
28884 If this is zero, point is always centered after it moves off frame.
28885 If you want scrolling to always be a line at a time, you should set
28886 `scroll-conservatively' to a large value rather than set this to 1. */);
28888 DEFVAR_INT ("scroll-conservatively", scroll_conservatively
,
28889 doc
: /* Scroll up to this many lines, to bring point back on screen.
28890 If point moves off-screen, redisplay will scroll by up to
28891 `scroll-conservatively' lines in order to bring point just barely
28892 onto the screen again. If that cannot be done, then redisplay
28893 recenters point as usual.
28895 If the value is greater than 100, redisplay will never recenter point,
28896 but will always scroll just enough text to bring point into view, even
28897 if you move far away.
28899 A value of zero means always recenter point if it moves off screen. */);
28900 scroll_conservatively
= 0;
28902 DEFVAR_INT ("scroll-margin", scroll_margin
,
28903 doc
: /* Number of lines of margin at the top and bottom of a window.
28904 Recenter the window whenever point gets within this many lines
28905 of the top or bottom of the window. */);
28908 DEFVAR_LISP ("display-pixels-per-inch", Vdisplay_pixels_per_inch
,
28909 doc
: /* Pixels per inch value for non-window system displays.
28910 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
28911 Vdisplay_pixels_per_inch
= make_float (72.0);
28914 DEFVAR_INT ("debug-end-pos", debug_end_pos
, doc
: /* Don't ask. */);
28917 DEFVAR_LISP ("truncate-partial-width-windows",
28918 Vtruncate_partial_width_windows
,
28919 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
28920 For an integer value, truncate lines in each window narrower than the
28921 full frame width, provided the window width is less than that integer;
28922 otherwise, respect the value of `truncate-lines'.
28924 For any other non-nil value, truncate lines in all windows that do
28925 not span the full frame width.
28927 A value of nil means to respect the value of `truncate-lines'.
28929 If `word-wrap' is enabled, you might want to reduce this. */);
28930 Vtruncate_partial_width_windows
= make_number (50);
28932 DEFVAR_BOOL ("mode-line-inverse-video", mode_line_inverse_video
,
28933 doc
: /* When nil, display the mode-line/header-line/menu-bar in the default face.
28934 Any other value means to use the appropriate face, `mode-line',
28935 `header-line', or `menu' respectively. */);
28936 mode_line_inverse_video
= 1;
28938 DEFVAR_LISP ("line-number-display-limit", Vline_number_display_limit
,
28939 doc
: /* Maximum buffer size for which line number should be displayed.
28940 If the buffer is bigger than this, the line number does not appear
28941 in the mode line. A value of nil means no limit. */);
28942 Vline_number_display_limit
= Qnil
;
28944 DEFVAR_INT ("line-number-display-limit-width",
28945 line_number_display_limit_width
,
28946 doc
: /* Maximum line width (in characters) for line number display.
28947 If the average length of the lines near point is bigger than this, then the
28948 line number may be omitted from the mode line. */);
28949 line_number_display_limit_width
= 200;
28951 DEFVAR_BOOL ("highlight-nonselected-windows", highlight_nonselected_windows
,
28952 doc
: /* Non-nil means highlight region even in nonselected windows. */);
28953 highlight_nonselected_windows
= 0;
28955 DEFVAR_BOOL ("multiple-frames", multiple_frames
,
28956 doc
: /* Non-nil if more than one frame is visible on this display.
28957 Minibuffer-only frames don't count, but iconified frames do.
28958 This variable is not guaranteed to be accurate except while processing
28959 `frame-title-format' and `icon-title-format'. */);
28961 DEFVAR_LISP ("frame-title-format", Vframe_title_format
,
28962 doc
: /* Template for displaying the title bar of visible frames.
28963 \(Assuming the window manager supports this feature.)
28965 This variable has the same structure as `mode-line-format', except that
28966 the %c and %l constructs are ignored. It is used only on frames for
28967 which no explicit name has been set \(see `modify-frame-parameters'). */);
28969 DEFVAR_LISP ("icon-title-format", Vicon_title_format
,
28970 doc
: /* Template for displaying the title bar of an iconified frame.
28971 \(Assuming the window manager supports this feature.)
28972 This variable has the same structure as `mode-line-format' (which see),
28973 and is used only on frames for which no explicit name has been set
28974 \(see `modify-frame-parameters'). */);
28976 = Vframe_title_format
28977 = listn (CONSTYPE_PURE
, 3,
28978 intern_c_string ("multiple-frames"),
28979 build_pure_c_string ("%b"),
28980 listn (CONSTYPE_PURE
, 4,
28981 empty_unibyte_string
,
28982 intern_c_string ("invocation-name"),
28983 build_pure_c_string ("@"),
28984 intern_c_string ("system-name")));
28986 DEFVAR_LISP ("message-log-max", Vmessage_log_max
,
28987 doc
: /* Maximum number of lines to keep in the message log buffer.
28988 If nil, disable message logging. If t, log messages but don't truncate
28989 the buffer when it becomes large. */);
28990 Vmessage_log_max
= make_number (100);
28992 DEFVAR_LISP ("window-size-change-functions", Vwindow_size_change_functions
,
28993 doc
: /* Functions called before redisplay, if window sizes have changed.
28994 The value should be a list of functions that take one argument.
28995 Just before redisplay, for each frame, if any of its windows have changed
28996 size since the last redisplay, or have been split or deleted,
28997 all the functions in the list are called, with the frame as argument. */);
28998 Vwindow_size_change_functions
= Qnil
;
29000 DEFVAR_LISP ("window-scroll-functions", Vwindow_scroll_functions
,
29001 doc
: /* List of functions to call before redisplaying a window with scrolling.
29002 Each function is called with two arguments, the window and its new
29003 display-start position. Note that these functions are also called by
29004 `set-window-buffer'. Also note that the value of `window-end' is not
29005 valid when these functions are called.
29007 Warning: Do not use this feature to alter the way the window
29008 is scrolled. It is not designed for that, and such use probably won't
29010 Vwindow_scroll_functions
= Qnil
;
29012 DEFVAR_LISP ("window-text-change-functions",
29013 Vwindow_text_change_functions
,
29014 doc
: /* Functions to call in redisplay when text in the window might change. */);
29015 Vwindow_text_change_functions
= Qnil
;
29017 DEFVAR_LISP ("redisplay-end-trigger-functions", Vredisplay_end_trigger_functions
,
29018 doc
: /* Functions called when redisplay of a window reaches the end trigger.
29019 Each function is called with two arguments, the window and the end trigger value.
29020 See `set-window-redisplay-end-trigger'. */);
29021 Vredisplay_end_trigger_functions
= Qnil
;
29023 DEFVAR_LISP ("mouse-autoselect-window", Vmouse_autoselect_window
,
29024 doc
: /* Non-nil means autoselect window with mouse pointer.
29025 If nil, do not autoselect windows.
29026 A positive number means delay autoselection by that many seconds: a
29027 window is autoselected only after the mouse has remained in that
29028 window for the duration of the delay.
29029 A negative number has a similar effect, but causes windows to be
29030 autoselected only after the mouse has stopped moving. \(Because of
29031 the way Emacs compares mouse events, you will occasionally wait twice
29032 that time before the window gets selected.\)
29033 Any other value means to autoselect window instantaneously when the
29034 mouse pointer enters it.
29036 Autoselection selects the minibuffer only if it is active, and never
29037 unselects the minibuffer if it is active.
29039 When customizing this variable make sure that the actual value of
29040 `focus-follows-mouse' matches the behavior of your window manager. */);
29041 Vmouse_autoselect_window
= Qnil
;
29043 DEFVAR_LISP ("auto-resize-tool-bars", Vauto_resize_tool_bars
,
29044 doc
: /* Non-nil means automatically resize tool-bars.
29045 This dynamically changes the tool-bar's height to the minimum height
29046 that is needed to make all tool-bar items visible.
29047 If value is `grow-only', the tool-bar's height is only increased
29048 automatically; to decrease the tool-bar height, use \\[recenter]. */);
29049 Vauto_resize_tool_bars
= Qt
;
29051 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", auto_raise_tool_bar_buttons_p
,
29052 doc
: /* Non-nil means raise tool-bar buttons when the mouse moves over them. */);
29053 auto_raise_tool_bar_buttons_p
= 1;
29055 DEFVAR_BOOL ("make-cursor-line-fully-visible", make_cursor_line_fully_visible_p
,
29056 doc
: /* Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
29057 make_cursor_line_fully_visible_p
= 1;
29059 DEFVAR_LISP ("tool-bar-border", Vtool_bar_border
,
29060 doc
: /* Border below tool-bar in pixels.
29061 If an integer, use it as the height of the border.
29062 If it is one of `internal-border-width' or `border-width', use the
29063 value of the corresponding frame parameter.
29064 Otherwise, no border is added below the tool-bar. */);
29065 Vtool_bar_border
= Qinternal_border_width
;
29067 DEFVAR_LISP ("tool-bar-button-margin", Vtool_bar_button_margin
,
29068 doc
: /* Margin around tool-bar buttons in pixels.
29069 If an integer, use that for both horizontal and vertical margins.
29070 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
29071 HORZ specifying the horizontal margin, and VERT specifying the
29072 vertical margin. */);
29073 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
29075 DEFVAR_INT ("tool-bar-button-relief", tool_bar_button_relief
,
29076 doc
: /* Relief thickness of tool-bar buttons. */);
29077 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
29079 DEFVAR_LISP ("tool-bar-style", Vtool_bar_style
,
29080 doc
: /* Tool bar style to use.
29082 image - show images only
29083 text - show text only
29084 both - show both, text below image
29085 both-horiz - show text to the right of the image
29086 text-image-horiz - show text to the left of the image
29087 any other - use system default or image if no system default.
29089 This variable only affects the GTK+ toolkit version of Emacs. */);
29090 Vtool_bar_style
= Qnil
;
29092 DEFVAR_INT ("tool-bar-max-label-size", tool_bar_max_label_size
,
29093 doc
: /* Maximum number of characters a label can have to be shown.
29094 The tool bar style must also show labels for this to have any effect, see
29095 `tool-bar-style'. */);
29096 tool_bar_max_label_size
= DEFAULT_TOOL_BAR_LABEL_SIZE
;
29098 DEFVAR_LISP ("fontification-functions", Vfontification_functions
,
29099 doc
: /* List of functions to call to fontify regions of text.
29100 Each function is called with one argument POS. Functions must
29101 fontify a region starting at POS in the current buffer, and give
29102 fontified regions the property `fontified'. */);
29103 Vfontification_functions
= Qnil
;
29104 Fmake_variable_buffer_local (Qfontification_functions
);
29106 DEFVAR_BOOL ("unibyte-display-via-language-environment",
29107 unibyte_display_via_language_environment
,
29108 doc
: /* Non-nil means display unibyte text according to language environment.
29109 Specifically, this means that raw bytes in the range 160-255 decimal
29110 are displayed by converting them to the equivalent multibyte characters
29111 according to the current language environment. As a result, they are
29112 displayed according to the current fontset.
29114 Note that this variable affects only how these bytes are displayed,
29115 but does not change the fact they are interpreted as raw bytes. */);
29116 unibyte_display_via_language_environment
= 0;
29118 DEFVAR_LISP ("max-mini-window-height", Vmax_mini_window_height
,
29119 doc
: /* Maximum height for resizing mini-windows (the minibuffer and the echo area).
29120 If a float, it specifies a fraction of the mini-window frame's height.
29121 If an integer, it specifies a number of lines. */);
29122 Vmax_mini_window_height
= make_float (0.25);
29124 DEFVAR_LISP ("resize-mini-windows", Vresize_mini_windows
,
29125 doc
: /* How to resize mini-windows (the minibuffer and the echo area).
29126 A value of nil means don't automatically resize mini-windows.
29127 A value of t means resize them to fit the text displayed in them.
29128 A value of `grow-only', the default, means let mini-windows grow only;
29129 they return to their normal size when the minibuffer is closed, or the
29130 echo area becomes empty. */);
29131 Vresize_mini_windows
= Qgrow_only
;
29133 DEFVAR_LISP ("blink-cursor-alist", Vblink_cursor_alist
,
29134 doc
: /* Alist specifying how to blink the cursor off.
29135 Each element has the form (ON-STATE . OFF-STATE). Whenever the
29136 `cursor-type' frame-parameter or variable equals ON-STATE,
29137 comparing using `equal', Emacs uses OFF-STATE to specify
29138 how to blink it off. ON-STATE and OFF-STATE are values for
29139 the `cursor-type' frame parameter.
29141 If a frame's ON-STATE has no entry in this list,
29142 the frame's other specifications determine how to blink the cursor off. */);
29143 Vblink_cursor_alist
= Qnil
;
29145 DEFVAR_BOOL ("auto-hscroll-mode", automatic_hscrolling_p
,
29146 doc
: /* Allow or disallow automatic horizontal scrolling of windows.
29147 If non-nil, windows are automatically scrolled horizontally to make
29148 point visible. */);
29149 automatic_hscrolling_p
= 1;
29150 DEFSYM (Qauto_hscroll_mode
, "auto-hscroll-mode");
29152 DEFVAR_INT ("hscroll-margin", hscroll_margin
,
29153 doc
: /* How many columns away from the window edge point is allowed to get
29154 before automatic hscrolling will horizontally scroll the window. */);
29155 hscroll_margin
= 5;
29157 DEFVAR_LISP ("hscroll-step", Vhscroll_step
,
29158 doc
: /* How many columns to scroll the window when point gets too close to the edge.
29159 When point is less than `hscroll-margin' columns from the window
29160 edge, automatic hscrolling will scroll the window by the amount of columns
29161 determined by this variable. If its value is a positive integer, scroll that
29162 many columns. If it's a positive floating-point number, it specifies the
29163 fraction of the window's width to scroll. If it's nil or zero, point will be
29164 centered horizontally after the scroll. Any other value, including negative
29165 numbers, are treated as if the value were zero.
29167 Automatic hscrolling always moves point outside the scroll margin, so if
29168 point was more than scroll step columns inside the margin, the window will
29169 scroll more than the value given by the scroll step.
29171 Note that the lower bound for automatic hscrolling specified by `scroll-left'
29172 and `scroll-right' overrides this variable's effect. */);
29173 Vhscroll_step
= make_number (0);
29175 DEFVAR_BOOL ("message-truncate-lines", message_truncate_lines
,
29176 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
29177 Bind this around calls to `message' to let it take effect. */);
29178 message_truncate_lines
= 0;
29180 DEFVAR_LISP ("menu-bar-update-hook", Vmenu_bar_update_hook
,
29181 doc
: /* Normal hook run to update the menu bar definitions.
29182 Redisplay runs this hook before it redisplays the menu bar.
29183 This is used to update submenus such as Buffers,
29184 whose contents depend on various data. */);
29185 Vmenu_bar_update_hook
= Qnil
;
29187 DEFVAR_LISP ("menu-updating-frame", Vmenu_updating_frame
,
29188 doc
: /* Frame for which we are updating a menu.
29189 The enable predicate for a menu binding should check this variable. */);
29190 Vmenu_updating_frame
= Qnil
;
29192 DEFVAR_BOOL ("inhibit-menubar-update", inhibit_menubar_update
,
29193 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
29194 inhibit_menubar_update
= 0;
29196 DEFVAR_LISP ("wrap-prefix", Vwrap_prefix
,
29197 doc
: /* Prefix prepended to all continuation lines at display time.
29198 The value may be a string, an image, or a stretch-glyph; it is
29199 interpreted in the same way as the value of a `display' text property.
29201 This variable is overridden by any `wrap-prefix' text or overlay
29204 To add a prefix to non-continuation lines, use `line-prefix'. */);
29205 Vwrap_prefix
= Qnil
;
29206 DEFSYM (Qwrap_prefix
, "wrap-prefix");
29207 Fmake_variable_buffer_local (Qwrap_prefix
);
29209 DEFVAR_LISP ("line-prefix", Vline_prefix
,
29210 doc
: /* Prefix prepended to all non-continuation lines at display time.
29211 The value may be a string, an image, or a stretch-glyph; it is
29212 interpreted in the same way as the value of a `display' text property.
29214 This variable is overridden by any `line-prefix' text or overlay
29217 To add a prefix to continuation lines, use `wrap-prefix'. */);
29218 Vline_prefix
= Qnil
;
29219 DEFSYM (Qline_prefix
, "line-prefix");
29220 Fmake_variable_buffer_local (Qline_prefix
);
29222 DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay
,
29223 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
29224 inhibit_eval_during_redisplay
= 0;
29226 DEFVAR_BOOL ("inhibit-free-realized-faces", inhibit_free_realized_faces
,
29227 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
29228 inhibit_free_realized_faces
= 0;
29231 DEFVAR_BOOL ("inhibit-try-window-id", inhibit_try_window_id
,
29232 doc
: /* Inhibit try_window_id display optimization. */);
29233 inhibit_try_window_id
= 0;
29235 DEFVAR_BOOL ("inhibit-try-window-reusing", inhibit_try_window_reusing
,
29236 doc
: /* Inhibit try_window_reusing display optimization. */);
29237 inhibit_try_window_reusing
= 0;
29239 DEFVAR_BOOL ("inhibit-try-cursor-movement", inhibit_try_cursor_movement
,
29240 doc
: /* Inhibit try_cursor_movement display optimization. */);
29241 inhibit_try_cursor_movement
= 0;
29242 #endif /* GLYPH_DEBUG */
29244 DEFVAR_INT ("overline-margin", overline_margin
,
29245 doc
: /* Space between overline and text, in pixels.
29246 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
29247 margin to the character height. */);
29248 overline_margin
= 2;
29250 DEFVAR_INT ("underline-minimum-offset",
29251 underline_minimum_offset
,
29252 doc
: /* Minimum distance between baseline and underline.
29253 This can improve legibility of underlined text at small font sizes,
29254 particularly when using variable `x-use-underline-position-properties'
29255 with fonts that specify an UNDERLINE_POSITION relatively close to the
29256 baseline. The default value is 1. */);
29257 underline_minimum_offset
= 1;
29259 DEFVAR_BOOL ("display-hourglass", display_hourglass_p
,
29260 doc
: /* Non-nil means show an hourglass pointer, when Emacs is busy.
29261 This feature only works when on a window system that can change
29262 cursor shapes. */);
29263 display_hourglass_p
= 1;
29265 DEFVAR_LISP ("hourglass-delay", Vhourglass_delay
,
29266 doc
: /* Seconds to wait before displaying an hourglass pointer when Emacs is busy. */);
29267 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
29269 hourglass_atimer
= NULL
;
29270 hourglass_shown_p
= 0;
29272 DEFSYM (Qglyphless_char
, "glyphless-char");
29273 DEFSYM (Qhex_code
, "hex-code");
29274 DEFSYM (Qempty_box
, "empty-box");
29275 DEFSYM (Qthin_space
, "thin-space");
29276 DEFSYM (Qzero_width
, "zero-width");
29278 DEFSYM (Qglyphless_char_display
, "glyphless-char-display");
29279 /* Intern this now in case it isn't already done.
29280 Setting this variable twice is harmless.
29281 But don't staticpro it here--that is done in alloc.c. */
29282 Qchar_table_extra_slots
= intern_c_string ("char-table-extra-slots");
29283 Fput (Qglyphless_char_display
, Qchar_table_extra_slots
, make_number (1));
29285 DEFVAR_LISP ("glyphless-char-display", Vglyphless_char_display
,
29286 doc
: /* Char-table defining glyphless characters.
29287 Each element, if non-nil, should be one of the following:
29288 an ASCII acronym string: display this string in a box
29289 `hex-code': display the hexadecimal code of a character in a box
29290 `empty-box': display as an empty box
29291 `thin-space': display as 1-pixel width space
29292 `zero-width': don't display
29293 An element may also be a cons cell (GRAPHICAL . TEXT), which specifies the
29294 display method for graphical terminals and text terminals respectively.
29295 GRAPHICAL and TEXT should each have one of the values listed above.
29297 The char-table has one extra slot to control the display of a character for
29298 which no font is found. This slot only takes effect on graphical terminals.
29299 Its value should be an ASCII acronym string, `hex-code', `empty-box', or
29300 `thin-space'. The default is `empty-box'. */);
29301 Vglyphless_char_display
= Fmake_char_table (Qglyphless_char_display
, Qnil
);
29302 Fset_char_table_extra_slot (Vglyphless_char_display
, make_number (0),
29305 DEFVAR_LISP ("debug-on-message", Vdebug_on_message
,
29306 doc
: /* If non-nil, debug if a message matching this regexp is displayed. */);
29307 Vdebug_on_message
= Qnil
;
29311 /* Initialize this module when Emacs starts. */
29316 current_header_line_height
= current_mode_line_height
= -1;
29318 CHARPOS (this_line_start_pos
) = 0;
29320 if (!noninteractive
)
29322 struct window
*m
= XWINDOW (minibuf_window
);
29323 Lisp_Object frame
= m
->frame
;
29324 struct frame
*f
= XFRAME (frame
);
29325 Lisp_Object root
= FRAME_ROOT_WINDOW (f
);
29326 struct window
*r
= XWINDOW (root
);
29329 echo_area_window
= minibuf_window
;
29331 wset_top_line (r
, make_number (FRAME_TOP_MARGIN (f
)));
29333 (r
, make_number (FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
)));
29334 wset_total_cols (r
, make_number (FRAME_COLS (f
)));
29335 wset_top_line (m
, make_number (FRAME_LINES (f
) - 1));
29336 wset_total_lines (m
, make_number (1));
29337 wset_total_cols (m
, make_number (FRAME_COLS (f
)));
29339 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
29340 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
29341 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
29343 /* The default ellipsis glyphs `...'. */
29344 for (i
= 0; i
< 3; ++i
)
29345 default_invis_vector
[i
] = make_number ('.');
29349 /* Allocate the buffer for frame titles.
29350 Also used for `format-mode-line'. */
29352 mode_line_noprop_buf
= xmalloc (size
);
29353 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
29354 mode_line_noprop_ptr
= mode_line_noprop_buf
;
29355 mode_line_target
= MODE_LINE_DISPLAY
;
29358 help_echo_showing_p
= 0;
29361 /* Since w32 does not support atimers, it defines its own implementation of
29362 the following three functions in w32fns.c. */
29365 /* Platform-independent portion of hourglass implementation. */
29367 /* Cancel a currently active hourglass timer, and start a new one. */
29369 start_hourglass (void)
29371 #if defined (HAVE_WINDOW_SYSTEM)
29374 cancel_hourglass ();
29376 if (INTEGERP (Vhourglass_delay
)
29377 && XINT (Vhourglass_delay
) > 0)
29378 delay
= make_emacs_time (min (XINT (Vhourglass_delay
),
29379 TYPE_MAXIMUM (time_t)),
29381 else if (FLOATP (Vhourglass_delay
)
29382 && XFLOAT_DATA (Vhourglass_delay
) > 0)
29383 delay
= EMACS_TIME_FROM_DOUBLE (XFLOAT_DATA (Vhourglass_delay
));
29385 delay
= make_emacs_time (DEFAULT_HOURGLASS_DELAY
, 0);
29387 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
29388 show_hourglass
, NULL
);
29393 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
29396 cancel_hourglass (void)
29398 #if defined (HAVE_WINDOW_SYSTEM)
29399 if (hourglass_atimer
)
29401 cancel_atimer (hourglass_atimer
);
29402 hourglass_atimer
= NULL
;
29405 if (hourglass_shown_p
)
29409 #endif /* ! WINDOWSNT */