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
, CHAR_TO_BYTE (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
;
9294 GCPRO4 (fmt
, msg
, arg1
, arg2
);
9296 args
[0] = fmt
= build_string (format
);
9299 msg
= Fformat (3, args
);
9301 len
= SBYTES (msg
) + 1;
9302 buffer
= SAFE_ALLOCA (len
);
9303 memcpy (buffer
, SDATA (msg
), len
);
9305 message_dolog (buffer
, len
- 1, 1, 0);
9312 /* Output a newline in the *Messages* buffer if "needs" one. */
9315 message_log_maybe_newline (void)
9317 if (message_log_need_newline
)
9318 message_dolog ("", 0, 1, 0);
9322 /* Add a string M of length NBYTES to the message log, optionally
9323 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
9324 nonzero, means interpret the contents of M as multibyte. This
9325 function calls low-level routines in order to bypass text property
9326 hooks, etc. which might not be safe to run.
9328 This may GC (insert may run before/after change hooks),
9329 so the buffer M must NOT point to a Lisp string. */
9332 message_dolog (const char *m
, ptrdiff_t nbytes
, int nlflag
, int multibyte
)
9334 const unsigned char *msg
= (const unsigned char *) m
;
9336 if (!NILP (Vmemory_full
))
9339 if (!NILP (Vmessage_log_max
))
9341 struct buffer
*oldbuf
;
9342 Lisp_Object oldpoint
, oldbegv
, oldzv
;
9343 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
9344 ptrdiff_t point_at_end
= 0;
9345 ptrdiff_t zv_at_end
= 0;
9346 Lisp_Object old_deactivate_mark
, tem
;
9347 struct gcpro gcpro1
;
9349 old_deactivate_mark
= Vdeactivate_mark
;
9350 oldbuf
= current_buffer
;
9351 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
9352 bset_undo_list (current_buffer
, Qt
);
9354 oldpoint
= message_dolog_marker1
;
9355 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
9356 oldbegv
= message_dolog_marker2
;
9357 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
9358 oldzv
= message_dolog_marker3
;
9359 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
9360 GCPRO1 (old_deactivate_mark
);
9368 BEGV_BYTE
= BEG_BYTE
;
9371 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9373 /* Insert the string--maybe converting multibyte to single byte
9374 or vice versa, so that all the text fits the buffer. */
9376 && NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9382 /* Convert a multibyte string to single-byte
9383 for the *Message* buffer. */
9384 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
9386 c
= string_char_and_length (msg
+ i
, &char_bytes
);
9387 work
[0] = (ASCII_CHAR_P (c
)
9389 : multibyte_char_to_unibyte (c
));
9390 insert_1_both (work
, 1, 1, 1, 0, 0);
9393 else if (! multibyte
9394 && ! NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9398 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9399 /* Convert a single-byte string to multibyte
9400 for the *Message* buffer. */
9401 for (i
= 0; i
< nbytes
; i
++)
9404 MAKE_CHAR_MULTIBYTE (c
);
9405 char_bytes
= CHAR_STRING (c
, str
);
9406 insert_1_both ((char *) str
, 1, char_bytes
, 1, 0, 0);
9410 insert_1 (m
, nbytes
, 1, 0, 0);
9414 ptrdiff_t this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
;
9416 insert_1 ("\n", 1, 1, 0, 0);
9418 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9420 this_bol_byte
= PT_BYTE
;
9422 /* See if this line duplicates the previous one.
9423 If so, combine duplicates. */
9426 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9428 prev_bol_byte
= PT_BYTE
;
9430 dups
= message_log_check_duplicate (prev_bol_byte
,
9434 del_range_both (prev_bol
, prev_bol_byte
,
9435 this_bol
, this_bol_byte
, 0);
9438 char dupstr
[sizeof " [ times]"
9439 + INT_STRLEN_BOUND (printmax_t
)];
9441 /* If you change this format, don't forget to also
9442 change message_log_check_duplicate. */
9443 int duplen
= sprintf (dupstr
, " [%"pMd
" times]", dups
);
9444 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
9445 insert_1 (dupstr
, duplen
, 1, 0, 1);
9450 /* If we have more than the desired maximum number of lines
9451 in the *Messages* buffer now, delete the oldest ones.
9452 This is safe because we don't have undo in this buffer. */
9454 if (NATNUMP (Vmessage_log_max
))
9456 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
9457 -XFASTINT (Vmessage_log_max
) - 1, 0);
9458 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
9461 BEGV
= XMARKER (oldbegv
)->charpos
;
9462 BEGV_BYTE
= marker_byte_position (oldbegv
);
9471 ZV
= XMARKER (oldzv
)->charpos
;
9472 ZV_BYTE
= marker_byte_position (oldzv
);
9476 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9478 /* We can't do Fgoto_char (oldpoint) because it will run some
9480 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
9481 XMARKER (oldpoint
)->bytepos
);
9484 unchain_marker (XMARKER (oldpoint
));
9485 unchain_marker (XMARKER (oldbegv
));
9486 unchain_marker (XMARKER (oldzv
));
9488 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
9489 set_buffer_internal (oldbuf
);
9491 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
9492 message_log_need_newline
= !nlflag
;
9493 Vdeactivate_mark
= old_deactivate_mark
;
9498 /* We are at the end of the buffer after just having inserted a newline.
9499 (Note: We depend on the fact we won't be crossing the gap.)
9500 Check to see if the most recent message looks a lot like the previous one.
9501 Return 0 if different, 1 if the new one should just replace it, or a
9502 value N > 1 if we should also append " [N times]". */
9505 message_log_check_duplicate (ptrdiff_t prev_bol_byte
, ptrdiff_t this_bol_byte
)
9508 ptrdiff_t len
= Z_BYTE
- 1 - this_bol_byte
;
9510 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
9511 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
9513 for (i
= 0; i
< len
; i
++)
9515 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
9523 if (*p1
++ == ' ' && *p1
++ == '[')
9526 intmax_t n
= strtoimax ((char *) p1
, &pend
, 10);
9527 if (0 < n
&& n
< INTMAX_MAX
&& strncmp (pend
, " times]\n", 8) == 0)
9534 /* Display an echo area message M with a specified length of NBYTES
9535 bytes. The string may include null characters. If M is 0, clear
9536 out any existing message, and let the mini-buffer text show
9539 This may GC, so the buffer M must NOT point to a Lisp string. */
9542 message2 (const char *m
, ptrdiff_t nbytes
, int multibyte
)
9544 /* First flush out any partial line written with print. */
9545 message_log_maybe_newline ();
9547 message_dolog (m
, nbytes
, 1, multibyte
);
9548 message2_nolog (m
, nbytes
, multibyte
);
9552 /* The non-logging counterpart of message2. */
9555 message2_nolog (const char *m
, ptrdiff_t nbytes
, int multibyte
)
9557 struct frame
*sf
= SELECTED_FRAME ();
9558 message_enable_multibyte
= multibyte
;
9560 if (FRAME_INITIAL_P (sf
))
9562 if (noninteractive_need_newline
)
9563 putc ('\n', stderr
);
9564 noninteractive_need_newline
= 0;
9566 fwrite (m
, nbytes
, 1, stderr
);
9567 if (cursor_in_echo_area
== 0)
9568 fprintf (stderr
, "\n");
9571 /* A null message buffer means that the frame hasn't really been
9572 initialized yet. Error messages get reported properly by
9573 cmd_error, so this must be just an informative message; toss it. */
9574 else if (INTERACTIVE
9575 && sf
->glyphs_initialized_p
9576 && FRAME_MESSAGE_BUF (sf
))
9578 Lisp_Object mini_window
;
9581 /* Get the frame containing the mini-buffer
9582 that the selected frame is using. */
9583 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9584 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9586 FRAME_SAMPLE_VISIBILITY (f
);
9587 if (FRAME_VISIBLE_P (sf
)
9588 && ! FRAME_VISIBLE_P (f
))
9589 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
9593 set_message (m
, Qnil
, nbytes
, multibyte
);
9594 if (minibuffer_auto_raise
)
9595 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
9598 clear_message (1, 1);
9600 do_pending_window_change (0);
9601 echo_area_display (1);
9602 do_pending_window_change (0);
9603 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
9604 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
9609 /* Display an echo area message M with a specified length of NBYTES
9610 bytes. The string may include null characters. If M is not a
9611 string, clear out any existing message, and let the mini-buffer
9614 This function cancels echoing. */
9617 message3 (Lisp_Object m
, ptrdiff_t nbytes
, int multibyte
)
9619 struct gcpro gcpro1
;
9622 clear_message (1,1);
9625 /* First flush out any partial line written with print. */
9626 message_log_maybe_newline ();
9630 char *buffer
= SAFE_ALLOCA (nbytes
);
9631 memcpy (buffer
, SDATA (m
), nbytes
);
9632 message_dolog (buffer
, nbytes
, 1, multibyte
);
9635 message3_nolog (m
, nbytes
, multibyte
);
9641 /* The non-logging version of message3.
9642 This does not cancel echoing, because it is used for echoing.
9643 Perhaps we need to make a separate function for echoing
9644 and make this cancel echoing. */
9647 message3_nolog (Lisp_Object m
, ptrdiff_t nbytes
, int multibyte
)
9649 struct frame
*sf
= SELECTED_FRAME ();
9650 message_enable_multibyte
= multibyte
;
9652 if (FRAME_INITIAL_P (sf
))
9654 if (noninteractive_need_newline
)
9655 putc ('\n', stderr
);
9656 noninteractive_need_newline
= 0;
9658 fwrite (SDATA (m
), nbytes
, 1, stderr
);
9659 if (cursor_in_echo_area
== 0)
9660 fprintf (stderr
, "\n");
9663 /* A null message buffer means that the frame hasn't really been
9664 initialized yet. Error messages get reported properly by
9665 cmd_error, so this must be just an informative message; toss it. */
9666 else if (INTERACTIVE
9667 && sf
->glyphs_initialized_p
9668 && FRAME_MESSAGE_BUF (sf
))
9670 Lisp_Object mini_window
;
9674 /* Get the frame containing the mini-buffer
9675 that the selected frame is using. */
9676 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9677 frame
= XWINDOW (mini_window
)->frame
;
9680 FRAME_SAMPLE_VISIBILITY (f
);
9681 if (FRAME_VISIBLE_P (sf
)
9682 && !FRAME_VISIBLE_P (f
))
9683 Fmake_frame_visible (frame
);
9685 if (STRINGP (m
) && SCHARS (m
) > 0)
9687 set_message (NULL
, m
, nbytes
, multibyte
);
9688 if (minibuffer_auto_raise
)
9689 Fraise_frame (frame
);
9690 /* Assume we are not echoing.
9691 (If we are, echo_now will override this.) */
9692 echo_message_buffer
= Qnil
;
9695 clear_message (1, 1);
9697 do_pending_window_change (0);
9698 echo_area_display (1);
9699 do_pending_window_change (0);
9700 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
9701 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
9706 /* Display a null-terminated echo area message M. If M is 0, clear
9707 out any existing message, and let the mini-buffer text show through.
9709 The buffer M must continue to exist until after the echo area gets
9710 cleared or some other message gets displayed there. Do not pass
9711 text that is stored in a Lisp string. Do not pass text in a buffer
9712 that was alloca'd. */
9715 message1 (const char *m
)
9717 message2 (m
, (m
? strlen (m
) : 0), 0);
9721 /* The non-logging counterpart of message1. */
9724 message1_nolog (const char *m
)
9726 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
9729 /* Display a message M which contains a single %s
9730 which gets replaced with STRING. */
9733 message_with_string (const char *m
, Lisp_Object string
, int log
)
9735 CHECK_STRING (string
);
9741 if (noninteractive_need_newline
)
9742 putc ('\n', stderr
);
9743 noninteractive_need_newline
= 0;
9744 fprintf (stderr
, m
, SDATA (string
));
9745 if (!cursor_in_echo_area
)
9746 fprintf (stderr
, "\n");
9750 else if (INTERACTIVE
)
9752 /* The frame whose minibuffer we're going to display the message on.
9753 It may be larger than the selected frame, so we need
9754 to use its buffer, not the selected frame's buffer. */
9755 Lisp_Object mini_window
;
9756 struct frame
*f
, *sf
= SELECTED_FRAME ();
9758 /* Get the frame containing the minibuffer
9759 that the selected frame is using. */
9760 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9761 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9763 /* A null message buffer means that the frame hasn't really been
9764 initialized yet. Error messages get reported properly by
9765 cmd_error, so this must be just an informative message; toss it. */
9766 if (FRAME_MESSAGE_BUF (f
))
9768 Lisp_Object args
[2], msg
;
9769 struct gcpro gcpro1
, gcpro2
;
9771 args
[0] = build_string (m
);
9772 args
[1] = msg
= string
;
9773 GCPRO2 (args
[0], msg
);
9776 msg
= Fformat (2, args
);
9779 message3 (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
9781 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
9785 /* Print should start at the beginning of the message
9786 buffer next time. */
9787 message_buf_print
= 0;
9793 /* Dump an informative message to the minibuf. If M is 0, clear out
9794 any existing message, and let the mini-buffer text show through. */
9797 vmessage (const char *m
, va_list ap
)
9803 if (noninteractive_need_newline
)
9804 putc ('\n', stderr
);
9805 noninteractive_need_newline
= 0;
9806 vfprintf (stderr
, m
, ap
);
9807 if (cursor_in_echo_area
== 0)
9808 fprintf (stderr
, "\n");
9812 else if (INTERACTIVE
)
9814 /* The frame whose mini-buffer we're going to display the message
9815 on. It may be larger than the selected frame, so we need to
9816 use its buffer, not the selected frame's buffer. */
9817 Lisp_Object mini_window
;
9818 struct frame
*f
, *sf
= SELECTED_FRAME ();
9820 /* Get the frame containing the mini-buffer
9821 that the selected frame is using. */
9822 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9823 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9825 /* A null message buffer means that the frame hasn't really been
9826 initialized yet. Error messages get reported properly by
9827 cmd_error, so this must be just an informative message; toss
9829 if (FRAME_MESSAGE_BUF (f
))
9835 len
= doprnt (FRAME_MESSAGE_BUF (f
),
9836 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, ap
);
9838 message2 (FRAME_MESSAGE_BUF (f
), len
, 1);
9843 /* Print should start at the beginning of the message
9844 buffer next time. */
9845 message_buf_print
= 0;
9851 message (const char *m
, ...)
9861 /* The non-logging version of message. */
9864 message_nolog (const char *m
, ...)
9866 Lisp_Object old_log_max
;
9869 old_log_max
= Vmessage_log_max
;
9870 Vmessage_log_max
= Qnil
;
9872 Vmessage_log_max
= old_log_max
;
9878 /* Display the current message in the current mini-buffer. This is
9879 only called from error handlers in process.c, and is not time
9883 update_echo_area (void)
9885 if (!NILP (echo_area_buffer
[0]))
9888 string
= Fcurrent_message ();
9889 message3 (string
, SBYTES (string
),
9890 !NILP (BVAR (current_buffer
, enable_multibyte_characters
)));
9895 /* Make sure echo area buffers in `echo_buffers' are live.
9896 If they aren't, make new ones. */
9899 ensure_echo_area_buffers (void)
9903 for (i
= 0; i
< 2; ++i
)
9904 if (!BUFFERP (echo_buffer
[i
])
9905 || !BUFFER_LIVE_P (XBUFFER (echo_buffer
[i
])))
9908 Lisp_Object old_buffer
;
9911 old_buffer
= echo_buffer
[i
];
9912 echo_buffer
[i
] = Fget_buffer_create
9913 (make_formatted_string (name
, " *Echo Area %d*", i
));
9914 bset_truncate_lines (XBUFFER (echo_buffer
[i
]), Qnil
);
9915 /* to force word wrap in echo area -
9916 it was decided to postpone this*/
9917 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
9919 for (j
= 0; j
< 2; ++j
)
9920 if (EQ (old_buffer
, echo_area_buffer
[j
]))
9921 echo_area_buffer
[j
] = echo_buffer
[i
];
9926 /* Call FN with args A1..A4 with either the current or last displayed
9927 echo_area_buffer as current buffer.
9929 WHICH zero means use the current message buffer
9930 echo_area_buffer[0]. If that is nil, choose a suitable buffer
9931 from echo_buffer[] and clear it.
9933 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
9934 suitable buffer from echo_buffer[] and clear it.
9936 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
9937 that the current message becomes the last displayed one, make
9938 choose a suitable buffer for echo_area_buffer[0], and clear it.
9940 Value is what FN returns. */
9943 with_echo_area_buffer (struct window
*w
, int which
,
9944 int (*fn
) (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t),
9945 ptrdiff_t a1
, Lisp_Object a2
, ptrdiff_t a3
, ptrdiff_t a4
)
9948 int this_one
, the_other
, clear_buffer_p
, rc
;
9949 ptrdiff_t count
= SPECPDL_INDEX ();
9951 /* If buffers aren't live, make new ones. */
9952 ensure_echo_area_buffers ();
9957 this_one
= 0, the_other
= 1;
9959 this_one
= 1, the_other
= 0;
9962 this_one
= 0, the_other
= 1;
9965 /* We need a fresh one in case the current echo buffer equals
9966 the one containing the last displayed echo area message. */
9967 if (!NILP (echo_area_buffer
[this_one
])
9968 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
9969 echo_area_buffer
[this_one
] = Qnil
;
9972 /* Choose a suitable buffer from echo_buffer[] is we don't
9974 if (NILP (echo_area_buffer
[this_one
]))
9976 echo_area_buffer
[this_one
]
9977 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
9978 ? echo_buffer
[the_other
]
9979 : echo_buffer
[this_one
]);
9983 buffer
= echo_area_buffer
[this_one
];
9985 /* Don't get confused by reusing the buffer used for echoing
9986 for a different purpose. */
9987 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
9990 record_unwind_protect (unwind_with_echo_area_buffer
,
9991 with_echo_area_buffer_unwind_data (w
));
9993 /* Make the echo area buffer current. Note that for display
9994 purposes, it is not necessary that the displayed window's buffer
9995 == current_buffer, except for text property lookup. So, let's
9996 only set that buffer temporarily here without doing a full
9997 Fset_window_buffer. We must also change w->pointm, though,
9998 because otherwise an assertions in unshow_buffer fails, and Emacs
10000 set_buffer_internal_1 (XBUFFER (buffer
));
10003 wset_buffer (w
, buffer
);
10004 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
10007 bset_undo_list (current_buffer
, Qt
);
10008 bset_read_only (current_buffer
, Qnil
);
10009 specbind (Qinhibit_read_only
, Qt
);
10010 specbind (Qinhibit_modification_hooks
, Qt
);
10012 if (clear_buffer_p
&& Z
> BEG
)
10013 del_range (BEG
, Z
);
10015 eassert (BEGV
>= BEG
);
10016 eassert (ZV
<= Z
&& ZV
>= BEGV
);
10018 rc
= fn (a1
, a2
, a3
, a4
);
10020 eassert (BEGV
>= BEG
);
10021 eassert (ZV
<= Z
&& ZV
>= BEGV
);
10023 unbind_to (count
, Qnil
);
10028 /* Save state that should be preserved around the call to the function
10029 FN called in with_echo_area_buffer. */
10032 with_echo_area_buffer_unwind_data (struct window
*w
)
10035 Lisp_Object vector
, tmp
;
10037 /* Reduce consing by keeping one vector in
10038 Vwith_echo_area_save_vector. */
10039 vector
= Vwith_echo_area_save_vector
;
10040 Vwith_echo_area_save_vector
= Qnil
;
10043 vector
= Fmake_vector (make_number (7), Qnil
);
10045 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
10046 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
10047 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
10051 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
10052 ASET (vector
, i
, w
->buffer
); ++i
;
10053 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->charpos
)); ++i
;
10054 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->bytepos
)); ++i
;
10059 for (; i
< end
; ++i
)
10060 ASET (vector
, i
, Qnil
);
10063 eassert (i
== ASIZE (vector
));
10068 /* Restore global state from VECTOR which was created by
10069 with_echo_area_buffer_unwind_data. */
10072 unwind_with_echo_area_buffer (Lisp_Object vector
)
10074 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
10075 Vdeactivate_mark
= AREF (vector
, 1);
10076 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
10078 if (WINDOWP (AREF (vector
, 3)))
10081 Lisp_Object buffer
, charpos
, bytepos
;
10083 w
= XWINDOW (AREF (vector
, 3));
10084 buffer
= AREF (vector
, 4);
10085 charpos
= AREF (vector
, 5);
10086 bytepos
= AREF (vector
, 6);
10088 wset_buffer (w
, buffer
);
10089 set_marker_both (w
->pointm
, buffer
,
10090 XFASTINT (charpos
), XFASTINT (bytepos
));
10093 Vwith_echo_area_save_vector
= vector
;
10098 /* Set up the echo area for use by print functions. MULTIBYTE_P
10099 non-zero means we will print multibyte. */
10102 setup_echo_area_for_printing (int multibyte_p
)
10104 /* If we can't find an echo area any more, exit. */
10105 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
10106 Fkill_emacs (Qnil
);
10108 ensure_echo_area_buffers ();
10110 if (!message_buf_print
)
10112 /* A message has been output since the last time we printed.
10113 Choose a fresh echo area buffer. */
10114 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10115 echo_area_buffer
[0] = echo_buffer
[1];
10117 echo_area_buffer
[0] = echo_buffer
[0];
10119 /* Switch to that buffer and clear it. */
10120 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10121 bset_truncate_lines (current_buffer
, Qnil
);
10125 ptrdiff_t count
= SPECPDL_INDEX ();
10126 specbind (Qinhibit_read_only
, Qt
);
10127 /* Note that undo recording is always disabled. */
10128 del_range (BEG
, Z
);
10129 unbind_to (count
, Qnil
);
10131 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10133 /* Set up the buffer for the multibyteness we need. */
10135 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10136 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
10138 /* Raise the frame containing the echo area. */
10139 if (minibuffer_auto_raise
)
10141 struct frame
*sf
= SELECTED_FRAME ();
10142 Lisp_Object mini_window
;
10143 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10144 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
10147 message_log_maybe_newline ();
10148 message_buf_print
= 1;
10152 if (NILP (echo_area_buffer
[0]))
10154 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10155 echo_area_buffer
[0] = echo_buffer
[1];
10157 echo_area_buffer
[0] = echo_buffer
[0];
10160 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
10162 /* Someone switched buffers between print requests. */
10163 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10164 bset_truncate_lines (current_buffer
, Qnil
);
10170 /* Display an echo area message in window W. Value is non-zero if W's
10171 height is changed. If display_last_displayed_message_p is
10172 non-zero, display the message that was last displayed, otherwise
10173 display the current message. */
10176 display_echo_area (struct window
*w
)
10178 int i
, no_message_p
, window_height_changed_p
;
10180 /* Temporarily disable garbage collections while displaying the echo
10181 area. This is done because a GC can print a message itself.
10182 That message would modify the echo area buffer's contents while a
10183 redisplay of the buffer is going on, and seriously confuse
10185 ptrdiff_t count
= inhibit_garbage_collection ();
10187 /* If there is no message, we must call display_echo_area_1
10188 nevertheless because it resizes the window. But we will have to
10189 reset the echo_area_buffer in question to nil at the end because
10190 with_echo_area_buffer will sets it to an empty buffer. */
10191 i
= display_last_displayed_message_p
? 1 : 0;
10192 no_message_p
= NILP (echo_area_buffer
[i
]);
10194 window_height_changed_p
10195 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
10196 display_echo_area_1
,
10197 (intptr_t) w
, Qnil
, 0, 0);
10200 echo_area_buffer
[i
] = Qnil
;
10202 unbind_to (count
, Qnil
);
10203 return window_height_changed_p
;
10207 /* Helper for display_echo_area. Display the current buffer which
10208 contains the current echo area message in window W, a mini-window,
10209 a pointer to which is passed in A1. A2..A4 are currently not used.
10210 Change the height of W so that all of the message is displayed.
10211 Value is non-zero if height of W was changed. */
10214 display_echo_area_1 (ptrdiff_t a1
, Lisp_Object a2
, ptrdiff_t a3
, ptrdiff_t a4
)
10217 struct window
*w
= (struct window
*) i1
;
10218 Lisp_Object window
;
10219 struct text_pos start
;
10220 int window_height_changed_p
= 0;
10222 /* Do this before displaying, so that we have a large enough glyph
10223 matrix for the display. If we can't get enough space for the
10224 whole text, display the last N lines. That works by setting w->start. */
10225 window_height_changed_p
= resize_mini_window (w
, 0);
10227 /* Use the starting position chosen by resize_mini_window. */
10228 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
10231 clear_glyph_matrix (w
->desired_matrix
);
10232 XSETWINDOW (window
, w
);
10233 try_window (window
, start
, 0);
10235 return window_height_changed_p
;
10239 /* Resize the echo area window to exactly the size needed for the
10240 currently displayed message, if there is one. If a mini-buffer
10241 is active, don't shrink it. */
10244 resize_echo_area_exactly (void)
10246 if (BUFFERP (echo_area_buffer
[0])
10247 && WINDOWP (echo_area_window
))
10249 struct window
*w
= XWINDOW (echo_area_window
);
10251 Lisp_Object resize_exactly
;
10253 if (minibuf_level
== 0)
10254 resize_exactly
= Qt
;
10256 resize_exactly
= Qnil
;
10258 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
10259 (intptr_t) w
, resize_exactly
,
10263 ++windows_or_buffers_changed
;
10264 ++update_mode_lines
;
10265 redisplay_internal ();
10271 /* Callback function for with_echo_area_buffer, when used from
10272 resize_echo_area_exactly. A1 contains a pointer to the window to
10273 resize, EXACTLY non-nil means resize the mini-window exactly to the
10274 size of the text displayed. A3 and A4 are not used. Value is what
10275 resize_mini_window returns. */
10278 resize_mini_window_1 (ptrdiff_t a1
, Lisp_Object exactly
, ptrdiff_t a3
, ptrdiff_t a4
)
10281 return resize_mini_window ((struct window
*) i1
, !NILP (exactly
));
10285 /* Resize mini-window W to fit the size of its contents. EXACT_P
10286 means size the window exactly to the size needed. Otherwise, it's
10287 only enlarged until W's buffer is empty.
10289 Set W->start to the right place to begin display. If the whole
10290 contents fit, start at the beginning. Otherwise, start so as
10291 to make the end of the contents appear. This is particularly
10292 important for y-or-n-p, but seems desirable generally.
10294 Value is non-zero if the window height has been changed. */
10297 resize_mini_window (struct window
*w
, int exact_p
)
10299 struct frame
*f
= XFRAME (w
->frame
);
10300 int window_height_changed_p
= 0;
10302 eassert (MINI_WINDOW_P (w
));
10304 /* By default, start display at the beginning. */
10305 set_marker_both (w
->start
, w
->buffer
,
10306 BUF_BEGV (XBUFFER (w
->buffer
)),
10307 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
10309 /* Don't resize windows while redisplaying a window; it would
10310 confuse redisplay functions when the size of the window they are
10311 displaying changes from under them. Such a resizing can happen,
10312 for instance, when which-func prints a long message while
10313 we are running fontification-functions. We're running these
10314 functions with safe_call which binds inhibit-redisplay to t. */
10315 if (!NILP (Vinhibit_redisplay
))
10318 /* Nil means don't try to resize. */
10319 if (NILP (Vresize_mini_windows
)
10320 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
10323 if (!FRAME_MINIBUF_ONLY_P (f
))
10326 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
10327 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
10329 EMACS_INT max_height
;
10330 int unit
= FRAME_LINE_HEIGHT (f
);
10331 struct text_pos start
;
10332 struct buffer
*old_current_buffer
= NULL
;
10334 if (current_buffer
!= XBUFFER (w
->buffer
))
10336 old_current_buffer
= current_buffer
;
10337 set_buffer_internal (XBUFFER (w
->buffer
));
10340 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10342 /* Compute the max. number of lines specified by the user. */
10343 if (FLOATP (Vmax_mini_window_height
))
10344 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
10345 else if (INTEGERP (Vmax_mini_window_height
))
10346 max_height
= XINT (Vmax_mini_window_height
);
10348 max_height
= total_height
/ 4;
10350 /* Correct that max. height if it's bogus. */
10351 max_height
= max (1, max_height
);
10352 max_height
= min (total_height
, max_height
);
10354 /* Find out the height of the text in the window. */
10355 if (it
.line_wrap
== TRUNCATE
)
10360 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
10361 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
10362 height
= it
.current_y
+ last_height
;
10364 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
10365 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
10366 height
= (height
+ unit
- 1) / unit
;
10369 /* Compute a suitable window start. */
10370 if (height
> max_height
)
10372 height
= max_height
;
10373 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10374 move_it_vertically_backward (&it
, (height
- 1) * unit
);
10375 start
= it
.current
.pos
;
10378 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
10379 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
10381 if (EQ (Vresize_mini_windows
, Qgrow_only
))
10383 /* Let it grow only, until we display an empty message, in which
10384 case the window shrinks again. */
10385 if (height
> WINDOW_TOTAL_LINES (w
))
10387 int old_height
= WINDOW_TOTAL_LINES (w
);
10388 freeze_window_starts (f
, 1);
10389 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10390 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10392 else if (height
< WINDOW_TOTAL_LINES (w
)
10393 && (exact_p
|| BEGV
== ZV
))
10395 int old_height
= WINDOW_TOTAL_LINES (w
);
10396 freeze_window_starts (f
, 0);
10397 shrink_mini_window (w
);
10398 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10403 /* Always resize to exact size needed. */
10404 if (height
> WINDOW_TOTAL_LINES (w
))
10406 int old_height
= WINDOW_TOTAL_LINES (w
);
10407 freeze_window_starts (f
, 1);
10408 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10409 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10411 else if (height
< WINDOW_TOTAL_LINES (w
))
10413 int old_height
= WINDOW_TOTAL_LINES (w
);
10414 freeze_window_starts (f
, 0);
10415 shrink_mini_window (w
);
10419 freeze_window_starts (f
, 1);
10420 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10423 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10427 if (old_current_buffer
)
10428 set_buffer_internal (old_current_buffer
);
10431 return window_height_changed_p
;
10435 /* Value is the current message, a string, or nil if there is no
10436 current message. */
10439 current_message (void)
10443 if (!BUFFERP (echo_area_buffer
[0]))
10447 with_echo_area_buffer (0, 0, current_message_1
,
10448 (intptr_t) &msg
, Qnil
, 0, 0);
10450 echo_area_buffer
[0] = Qnil
;
10458 current_message_1 (ptrdiff_t a1
, Lisp_Object a2
, ptrdiff_t a3
, ptrdiff_t a4
)
10461 Lisp_Object
*msg
= (Lisp_Object
*) i1
;
10464 *msg
= make_buffer_string (BEG
, Z
, 1);
10471 /* Push the current message on Vmessage_stack for later restoration
10472 by restore_message. Value is non-zero if the current message isn't
10473 empty. This is a relatively infrequent operation, so it's not
10474 worth optimizing. */
10477 push_message (void)
10479 Lisp_Object msg
= current_message ();
10480 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
10481 return STRINGP (msg
);
10485 /* Restore message display from the top of Vmessage_stack. */
10488 restore_message (void)
10492 eassert (CONSP (Vmessage_stack
));
10493 msg
= XCAR (Vmessage_stack
);
10495 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
10497 message3_nolog (msg
, 0, 0);
10501 /* Handler for record_unwind_protect calling pop_message. */
10504 pop_message_unwind (Lisp_Object dummy
)
10510 /* Pop the top-most entry off Vmessage_stack. */
10515 eassert (CONSP (Vmessage_stack
));
10516 Vmessage_stack
= XCDR (Vmessage_stack
);
10520 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
10521 exits. If the stack is not empty, we have a missing pop_message
10525 check_message_stack (void)
10527 if (!NILP (Vmessage_stack
))
10532 /* Truncate to NCHARS what will be displayed in the echo area the next
10533 time we display it---but don't redisplay it now. */
10536 truncate_echo_area (ptrdiff_t nchars
)
10539 echo_area_buffer
[0] = Qnil
;
10540 /* A null message buffer means that the frame hasn't really been
10541 initialized yet. Error messages get reported properly by
10542 cmd_error, so this must be just an informative message; toss it. */
10543 else if (!noninteractive
10545 && !NILP (echo_area_buffer
[0]))
10547 struct frame
*sf
= SELECTED_FRAME ();
10548 if (FRAME_MESSAGE_BUF (sf
))
10549 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
10554 /* Helper function for truncate_echo_area. Truncate the current
10555 message to at most NCHARS characters. */
10558 truncate_message_1 (ptrdiff_t nchars
, Lisp_Object a2
, ptrdiff_t a3
, ptrdiff_t a4
)
10560 if (BEG
+ nchars
< Z
)
10561 del_range (BEG
+ nchars
, Z
);
10563 echo_area_buffer
[0] = Qnil
;
10567 /* Set the current message to a substring of S or STRING.
10569 If STRING is a Lisp string, set the message to the first NBYTES
10570 bytes from STRING. NBYTES zero means use the whole string. If
10571 STRING is multibyte, the message will be displayed multibyte.
10573 If S is not null, set the message to the first LEN bytes of S. LEN
10574 zero means use the whole string. MULTIBYTE_P non-zero means S is
10575 multibyte. Display the message multibyte in that case.
10577 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
10578 to t before calling set_message_1 (which calls insert).
10582 set_message (const char *s
, Lisp_Object string
,
10583 ptrdiff_t nbytes
, int multibyte_p
)
10585 message_enable_multibyte
10586 = ((s
&& multibyte_p
)
10587 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
10589 with_echo_area_buffer (0, -1, set_message_1
,
10590 (intptr_t) s
, string
, nbytes
, multibyte_p
);
10591 message_buf_print
= 0;
10592 help_echo_showing_p
= 0;
10594 if (STRINGP (Vdebug_on_message
)
10595 && fast_string_match (Vdebug_on_message
, string
) >= 0)
10596 call_debugger (list2 (Qerror
, string
));
10600 /* Helper function for set_message. Arguments have the same meaning
10601 as there, with A1 corresponding to S and A2 corresponding to STRING
10602 This function is called with the echo area buffer being
10606 set_message_1 (ptrdiff_t a1
, Lisp_Object a2
, ptrdiff_t nbytes
, ptrdiff_t multibyte_p
)
10609 const char *s
= (const char *) i1
;
10610 const unsigned char *msg
= (const unsigned char *) s
;
10611 Lisp_Object string
= a2
;
10613 /* Change multibyteness of the echo buffer appropriately. */
10614 if (message_enable_multibyte
10615 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10616 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
10618 bset_truncate_lines (current_buffer
, message_truncate_lines
? Qt
: Qnil
);
10619 if (!NILP (BVAR (current_buffer
, bidi_display_reordering
)))
10620 bset_bidi_paragraph_direction (current_buffer
, Qleft_to_right
);
10622 /* Insert new message at BEG. */
10623 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10625 if (STRINGP (string
))
10630 nbytes
= SBYTES (string
);
10631 nchars
= string_byte_to_char (string
, nbytes
);
10633 /* This function takes care of single/multibyte conversion. We
10634 just have to ensure that the echo area buffer has the right
10635 setting of enable_multibyte_characters. */
10636 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
10641 nbytes
= strlen (s
);
10643 if (multibyte_p
&& NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10645 /* Convert from multi-byte to single-byte. */
10650 /* Convert a multibyte string to single-byte. */
10651 for (i
= 0; i
< nbytes
; i
+= n
)
10653 c
= string_char_and_length (msg
+ i
, &n
);
10654 work
[0] = (ASCII_CHAR_P (c
)
10656 : multibyte_char_to_unibyte (c
));
10657 insert_1_both (work
, 1, 1, 1, 0, 0);
10660 else if (!multibyte_p
10661 && !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10663 /* Convert from single-byte to multi-byte. */
10666 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
10668 /* Convert a single-byte string to multibyte. */
10669 for (i
= 0; i
< nbytes
; i
++)
10672 MAKE_CHAR_MULTIBYTE (c
);
10673 n
= CHAR_STRING (c
, str
);
10674 insert_1_both ((char *) str
, 1, n
, 1, 0, 0);
10678 insert_1 (s
, nbytes
, 1, 0, 0);
10685 /* Clear messages. CURRENT_P non-zero means clear the current
10686 message. LAST_DISPLAYED_P non-zero means clear the message
10690 clear_message (int current_p
, int last_displayed_p
)
10694 echo_area_buffer
[0] = Qnil
;
10695 message_cleared_p
= 1;
10698 if (last_displayed_p
)
10699 echo_area_buffer
[1] = Qnil
;
10701 message_buf_print
= 0;
10704 /* Clear garbaged frames.
10706 This function is used where the old redisplay called
10707 redraw_garbaged_frames which in turn called redraw_frame which in
10708 turn called clear_frame. The call to clear_frame was a source of
10709 flickering. I believe a clear_frame is not necessary. It should
10710 suffice in the new redisplay to invalidate all current matrices,
10711 and ensure a complete redisplay of all windows. */
10714 clear_garbaged_frames (void)
10716 if (frame_garbaged
)
10718 Lisp_Object tail
, frame
;
10719 int changed_count
= 0;
10721 FOR_EACH_FRAME (tail
, frame
)
10723 struct frame
*f
= XFRAME (frame
);
10725 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
10729 Fredraw_frame (frame
);
10730 f
->force_flush_display_p
= 1;
10732 clear_current_matrices (f
);
10739 frame_garbaged
= 0;
10741 ++windows_or_buffers_changed
;
10746 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
10747 is non-zero update selected_frame. Value is non-zero if the
10748 mini-windows height has been changed. */
10751 echo_area_display (int update_frame_p
)
10753 Lisp_Object mini_window
;
10756 int window_height_changed_p
= 0;
10757 struct frame
*sf
= SELECTED_FRAME ();
10759 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10760 w
= XWINDOW (mini_window
);
10761 f
= XFRAME (WINDOW_FRAME (w
));
10763 /* Don't display if frame is invisible or not yet initialized. */
10764 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
10767 #ifdef HAVE_WINDOW_SYSTEM
10768 /* When Emacs starts, selected_frame may be the initial terminal
10769 frame. If we let this through, a message would be displayed on
10771 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
10773 #endif /* HAVE_WINDOW_SYSTEM */
10775 /* Redraw garbaged frames. */
10776 if (frame_garbaged
)
10777 clear_garbaged_frames ();
10779 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
10781 echo_area_window
= mini_window
;
10782 window_height_changed_p
= display_echo_area (w
);
10783 w
->must_be_updated_p
= 1;
10785 /* Update the display, unless called from redisplay_internal.
10786 Also don't update the screen during redisplay itself. The
10787 update will happen at the end of redisplay, and an update
10788 here could cause confusion. */
10789 if (update_frame_p
&& !redisplaying_p
)
10793 /* If the display update has been interrupted by pending
10794 input, update mode lines in the frame. Due to the
10795 pending input, it might have been that redisplay hasn't
10796 been called, so that mode lines above the echo area are
10797 garbaged. This looks odd, so we prevent it here. */
10798 if (!display_completed
)
10799 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
10801 if (window_height_changed_p
10802 /* Don't do this if Emacs is shutting down. Redisplay
10803 needs to run hooks. */
10804 && !NILP (Vrun_hooks
))
10806 /* Must update other windows. Likewise as in other
10807 cases, don't let this update be interrupted by
10809 ptrdiff_t count
= SPECPDL_INDEX ();
10810 specbind (Qredisplay_dont_pause
, Qt
);
10811 windows_or_buffers_changed
= 1;
10812 redisplay_internal ();
10813 unbind_to (count
, Qnil
);
10815 else if (FRAME_WINDOW_P (f
) && n
== 0)
10817 /* Window configuration is the same as before.
10818 Can do with a display update of the echo area,
10819 unless we displayed some mode lines. */
10820 update_single_window (w
, 1);
10821 FRAME_RIF (f
)->flush_display (f
);
10824 update_frame (f
, 1, 1);
10826 /* If cursor is in the echo area, make sure that the next
10827 redisplay displays the minibuffer, so that the cursor will
10828 be replaced with what the minibuffer wants. */
10829 if (cursor_in_echo_area
)
10830 ++windows_or_buffers_changed
;
10833 else if (!EQ (mini_window
, selected_window
))
10834 windows_or_buffers_changed
++;
10836 /* Last displayed message is now the current message. */
10837 echo_area_buffer
[1] = echo_area_buffer
[0];
10838 /* Inform read_char that we're not echoing. */
10839 echo_message_buffer
= Qnil
;
10841 /* Prevent redisplay optimization in redisplay_internal by resetting
10842 this_line_start_pos. This is done because the mini-buffer now
10843 displays the message instead of its buffer text. */
10844 if (EQ (mini_window
, selected_window
))
10845 CHARPOS (this_line_start_pos
) = 0;
10847 return window_height_changed_p
;
10852 /***********************************************************************
10853 Mode Lines and Frame Titles
10854 ***********************************************************************/
10856 /* A buffer for constructing non-propertized mode-line strings and
10857 frame titles in it; allocated from the heap in init_xdisp and
10858 resized as needed in store_mode_line_noprop_char. */
10860 static char *mode_line_noprop_buf
;
10862 /* The buffer's end, and a current output position in it. */
10864 static char *mode_line_noprop_buf_end
;
10865 static char *mode_line_noprop_ptr
;
10867 #define MODE_LINE_NOPROP_LEN(start) \
10868 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
10871 MODE_LINE_DISPLAY
= 0,
10875 } mode_line_target
;
10877 /* Alist that caches the results of :propertize.
10878 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
10879 static Lisp_Object mode_line_proptrans_alist
;
10881 /* List of strings making up the mode-line. */
10882 static Lisp_Object mode_line_string_list
;
10884 /* Base face property when building propertized mode line string. */
10885 static Lisp_Object mode_line_string_face
;
10886 static Lisp_Object mode_line_string_face_prop
;
10889 /* Unwind data for mode line strings */
10891 static Lisp_Object Vmode_line_unwind_vector
;
10894 format_mode_line_unwind_data (struct frame
*target_frame
,
10895 struct buffer
*obuf
,
10897 int save_proptrans
)
10899 Lisp_Object vector
, tmp
;
10901 /* Reduce consing by keeping one vector in
10902 Vwith_echo_area_save_vector. */
10903 vector
= Vmode_line_unwind_vector
;
10904 Vmode_line_unwind_vector
= Qnil
;
10907 vector
= Fmake_vector (make_number (10), Qnil
);
10909 ASET (vector
, 0, make_number (mode_line_target
));
10910 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
10911 ASET (vector
, 2, mode_line_string_list
);
10912 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
10913 ASET (vector
, 4, mode_line_string_face
);
10914 ASET (vector
, 5, mode_line_string_face_prop
);
10917 XSETBUFFER (tmp
, obuf
);
10920 ASET (vector
, 6, tmp
);
10921 ASET (vector
, 7, owin
);
10924 /* Similarly to `with-selected-window', if the operation selects
10925 a window on another frame, we must restore that frame's
10926 selected window, and (for a tty) the top-frame. */
10927 ASET (vector
, 8, target_frame
->selected_window
);
10928 if (FRAME_TERMCAP_P (target_frame
))
10929 ASET (vector
, 9, FRAME_TTY (target_frame
)->top_frame
);
10936 unwind_format_mode_line (Lisp_Object vector
)
10938 Lisp_Object old_window
= AREF (vector
, 7);
10939 Lisp_Object target_frame_window
= AREF (vector
, 8);
10940 Lisp_Object old_top_frame
= AREF (vector
, 9);
10942 mode_line_target
= XINT (AREF (vector
, 0));
10943 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
10944 mode_line_string_list
= AREF (vector
, 2);
10945 if (! EQ (AREF (vector
, 3), Qt
))
10946 mode_line_proptrans_alist
= AREF (vector
, 3);
10947 mode_line_string_face
= AREF (vector
, 4);
10948 mode_line_string_face_prop
= AREF (vector
, 5);
10950 /* Select window before buffer, since it may change the buffer. */
10951 if (!NILP (old_window
))
10953 /* If the operation that we are unwinding had selected a window
10954 on a different frame, reset its frame-selected-window. For a
10955 text terminal, reset its top-frame if necessary. */
10956 if (!NILP (target_frame_window
))
10959 = WINDOW_FRAME (XWINDOW (target_frame_window
));
10961 if (!EQ (frame
, WINDOW_FRAME (XWINDOW (old_window
))))
10962 Fselect_window (target_frame_window
, Qt
);
10964 if (!NILP (old_top_frame
) && !EQ (old_top_frame
, frame
))
10965 Fselect_frame (old_top_frame
, Qt
);
10968 Fselect_window (old_window
, Qt
);
10971 if (!NILP (AREF (vector
, 6)))
10973 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
10974 ASET (vector
, 6, Qnil
);
10977 Vmode_line_unwind_vector
= vector
;
10982 /* Store a single character C for the frame title in mode_line_noprop_buf.
10983 Re-allocate mode_line_noprop_buf if necessary. */
10986 store_mode_line_noprop_char (char c
)
10988 /* If output position has reached the end of the allocated buffer,
10989 increase the buffer's size. */
10990 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
10992 ptrdiff_t len
= MODE_LINE_NOPROP_LEN (0);
10993 ptrdiff_t size
= len
;
10994 mode_line_noprop_buf
=
10995 xpalloc (mode_line_noprop_buf
, &size
, 1, STRING_BYTES_BOUND
, 1);
10996 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
10997 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
11000 *mode_line_noprop_ptr
++ = c
;
11004 /* Store part of a frame title in mode_line_noprop_buf, beginning at
11005 mode_line_noprop_ptr. STRING is the string to store. Do not copy
11006 characters that yield more columns than PRECISION; PRECISION <= 0
11007 means copy the whole string. Pad with spaces until FIELD_WIDTH
11008 number of characters have been copied; FIELD_WIDTH <= 0 means don't
11009 pad. Called from display_mode_element when it is used to build a
11013 store_mode_line_noprop (const char *string
, int field_width
, int precision
)
11015 const unsigned char *str
= (const unsigned char *) string
;
11017 ptrdiff_t dummy
, nbytes
;
11019 /* Copy at most PRECISION chars from STR. */
11020 nbytes
= strlen (string
);
11021 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
11023 store_mode_line_noprop_char (*str
++);
11025 /* Fill up with spaces until FIELD_WIDTH reached. */
11026 while (field_width
> 0
11027 && n
< field_width
)
11029 store_mode_line_noprop_char (' ');
11036 /***********************************************************************
11038 ***********************************************************************/
11040 #ifdef HAVE_WINDOW_SYSTEM
11042 /* Set the title of FRAME, if it has changed. The title format is
11043 Vicon_title_format if FRAME is iconified, otherwise it is
11044 frame_title_format. */
11047 x_consider_frame_title (Lisp_Object frame
)
11049 struct frame
*f
= XFRAME (frame
);
11051 if (FRAME_WINDOW_P (f
)
11052 || FRAME_MINIBUF_ONLY_P (f
)
11053 || f
->explicit_name
)
11055 /* Do we have more than one visible frame on this X display? */
11058 ptrdiff_t title_start
;
11062 ptrdiff_t count
= SPECPDL_INDEX ();
11064 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
11066 Lisp_Object other_frame
= XCAR (tail
);
11067 struct frame
*tf
= XFRAME (other_frame
);
11070 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
11071 && !FRAME_MINIBUF_ONLY_P (tf
)
11072 && !EQ (other_frame
, tip_frame
)
11073 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
11077 /* Set global variable indicating that multiple frames exist. */
11078 multiple_frames
= CONSP (tail
);
11080 /* Switch to the buffer of selected window of the frame. Set up
11081 mode_line_target so that display_mode_element will output into
11082 mode_line_noprop_buf; then display the title. */
11083 record_unwind_protect (unwind_format_mode_line
,
11084 format_mode_line_unwind_data
11085 (f
, current_buffer
, selected_window
, 0));
11087 Fselect_window (f
->selected_window
, Qt
);
11088 set_buffer_internal_1
11089 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
11090 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
11092 mode_line_target
= MODE_LINE_TITLE
;
11093 title_start
= MODE_LINE_NOPROP_LEN (0);
11094 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
11095 NULL
, DEFAULT_FACE_ID
);
11096 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
11097 len
= MODE_LINE_NOPROP_LEN (title_start
);
11098 title
= mode_line_noprop_buf
+ title_start
;
11099 unbind_to (count
, Qnil
);
11101 /* Set the title only if it's changed. This avoids consing in
11102 the common case where it hasn't. (If it turns out that we've
11103 already wasted too much time by walking through the list with
11104 display_mode_element, then we might need to optimize at a
11105 higher level than this.) */
11106 if (! STRINGP (f
->name
)
11107 || SBYTES (f
->name
) != len
11108 || memcmp (title
, SDATA (f
->name
), len
) != 0)
11109 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
11113 #endif /* not HAVE_WINDOW_SYSTEM */
11116 /***********************************************************************
11118 ***********************************************************************/
11121 /* Prepare for redisplay by updating menu-bar item lists when
11122 appropriate. This can call eval. */
11125 prepare_menu_bars (void)
11128 struct gcpro gcpro1
, gcpro2
;
11130 Lisp_Object tooltip_frame
;
11132 #ifdef HAVE_WINDOW_SYSTEM
11133 tooltip_frame
= tip_frame
;
11135 tooltip_frame
= Qnil
;
11138 /* Update all frame titles based on their buffer names, etc. We do
11139 this before the menu bars so that the buffer-menu will show the
11140 up-to-date frame titles. */
11141 #ifdef HAVE_WINDOW_SYSTEM
11142 if (windows_or_buffers_changed
|| update_mode_lines
)
11144 Lisp_Object tail
, frame
;
11146 FOR_EACH_FRAME (tail
, frame
)
11148 f
= XFRAME (frame
);
11149 if (!EQ (frame
, tooltip_frame
)
11150 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
11151 x_consider_frame_title (frame
);
11154 #endif /* HAVE_WINDOW_SYSTEM */
11156 /* Update the menu bar item lists, if appropriate. This has to be
11157 done before any actual redisplay or generation of display lines. */
11158 all_windows
= (update_mode_lines
11159 || buffer_shared
> 1
11160 || windows_or_buffers_changed
);
11163 Lisp_Object tail
, frame
;
11164 ptrdiff_t count
= SPECPDL_INDEX ();
11165 /* 1 means that update_menu_bar has run its hooks
11166 so any further calls to update_menu_bar shouldn't do so again. */
11167 int menu_bar_hooks_run
= 0;
11169 record_unwind_save_match_data ();
11171 FOR_EACH_FRAME (tail
, frame
)
11173 f
= XFRAME (frame
);
11175 /* Ignore tooltip frame. */
11176 if (EQ (frame
, tooltip_frame
))
11179 /* If a window on this frame changed size, report that to
11180 the user and clear the size-change flag. */
11181 if (FRAME_WINDOW_SIZES_CHANGED (f
))
11183 Lisp_Object functions
;
11185 /* Clear flag first in case we get an error below. */
11186 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
11187 functions
= Vwindow_size_change_functions
;
11188 GCPRO2 (tail
, functions
);
11190 while (CONSP (functions
))
11192 if (!EQ (XCAR (functions
), Qt
))
11193 call1 (XCAR (functions
), frame
);
11194 functions
= XCDR (functions
);
11200 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
11201 #ifdef HAVE_WINDOW_SYSTEM
11202 update_tool_bar (f
, 0);
11205 if (windows_or_buffers_changed
11208 (f
, Fbuffer_modified_p (XWINDOW (f
->selected_window
)->buffer
));
11213 unbind_to (count
, Qnil
);
11217 struct frame
*sf
= SELECTED_FRAME ();
11218 update_menu_bar (sf
, 1, 0);
11219 #ifdef HAVE_WINDOW_SYSTEM
11220 update_tool_bar (sf
, 1);
11226 /* Update the menu bar item list for frame F. This has to be done
11227 before we start to fill in any display lines, because it can call
11230 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
11232 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
11233 already ran the menu bar hooks for this redisplay, so there
11234 is no need to run them again. The return value is the
11235 updated value of this flag, to pass to the next call. */
11238 update_menu_bar (struct frame
*f
, int save_match_data
, int hooks_run
)
11240 Lisp_Object window
;
11241 register struct window
*w
;
11243 /* If called recursively during a menu update, do nothing. This can
11244 happen when, for instance, an activate-menubar-hook causes a
11246 if (inhibit_menubar_update
)
11249 window
= FRAME_SELECTED_WINDOW (f
);
11250 w
= XWINDOW (window
);
11252 if (FRAME_WINDOW_P (f
)
11254 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11255 || defined (HAVE_NS) || defined (USE_GTK)
11256 FRAME_EXTERNAL_MENU_BAR (f
)
11258 FRAME_MENU_BAR_LINES (f
) > 0
11260 : FRAME_MENU_BAR_LINES (f
) > 0)
11262 /* If the user has switched buffers or windows, we need to
11263 recompute to reflect the new bindings. But we'll
11264 recompute when update_mode_lines is set too; that means
11265 that people can use force-mode-line-update to request
11266 that the menu bar be recomputed. The adverse effect on
11267 the rest of the redisplay algorithm is about the same as
11268 windows_or_buffers_changed anyway. */
11269 if (windows_or_buffers_changed
11270 /* This used to test w->update_mode_line, but we believe
11271 there is no need to recompute the menu in that case. */
11272 || update_mode_lines
11273 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
11274 < BUF_MODIFF (XBUFFER (w
->buffer
)))
11275 != w
->last_had_star
)
11276 || ((!NILP (Vtransient_mark_mode
)
11277 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
11278 != !NILP (w
->region_showing
)))
11280 struct buffer
*prev
= current_buffer
;
11281 ptrdiff_t count
= SPECPDL_INDEX ();
11283 specbind (Qinhibit_menubar_update
, Qt
);
11285 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11286 if (save_match_data
)
11287 record_unwind_save_match_data ();
11288 if (NILP (Voverriding_local_map_menu_flag
))
11290 specbind (Qoverriding_terminal_local_map
, Qnil
);
11291 specbind (Qoverriding_local_map
, Qnil
);
11296 /* Run the Lucid hook. */
11297 safe_run_hooks (Qactivate_menubar_hook
);
11299 /* If it has changed current-menubar from previous value,
11300 really recompute the menu-bar from the value. */
11301 if (! NILP (Vlucid_menu_bar_dirty_flag
))
11302 call0 (Qrecompute_lucid_menubar
);
11304 safe_run_hooks (Qmenu_bar_update_hook
);
11309 XSETFRAME (Vmenu_updating_frame
, f
);
11310 fset_menu_bar_items (f
, menu_bar_items (FRAME_MENU_BAR_ITEMS (f
)));
11312 /* Redisplay the menu bar in case we changed it. */
11313 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11314 || defined (HAVE_NS) || defined (USE_GTK)
11315 if (FRAME_WINDOW_P (f
))
11317 #if defined (HAVE_NS)
11318 /* All frames on Mac OS share the same menubar. So only
11319 the selected frame should be allowed to set it. */
11320 if (f
== SELECTED_FRAME ())
11322 set_frame_menubar (f
, 0, 0);
11325 /* On a terminal screen, the menu bar is an ordinary screen
11326 line, and this makes it get updated. */
11327 w
->update_mode_line
= 1;
11328 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11329 /* In the non-toolkit version, the menu bar is an ordinary screen
11330 line, and this makes it get updated. */
11331 w
->update_mode_line
= 1;
11332 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11334 unbind_to (count
, Qnil
);
11335 set_buffer_internal_1 (prev
);
11344 /***********************************************************************
11346 ***********************************************************************/
11348 #ifdef HAVE_WINDOW_SYSTEM
11351 Nominal cursor position -- where to draw output.
11352 HPOS and VPOS are window relative glyph matrix coordinates.
11353 X and Y are window relative pixel coordinates. */
11355 struct cursor_pos output_cursor
;
11359 Set the global variable output_cursor to CURSOR. All cursor
11360 positions are relative to updated_window. */
11363 set_output_cursor (struct cursor_pos
*cursor
)
11365 output_cursor
.hpos
= cursor
->hpos
;
11366 output_cursor
.vpos
= cursor
->vpos
;
11367 output_cursor
.x
= cursor
->x
;
11368 output_cursor
.y
= cursor
->y
;
11373 Set a nominal cursor position.
11375 HPOS and VPOS are column/row positions in a window glyph matrix. X
11376 and Y are window text area relative pixel positions.
11378 If this is done during an update, updated_window will contain the
11379 window that is being updated and the position is the future output
11380 cursor position for that window. If updated_window is null, use
11381 selected_window and display the cursor at the given position. */
11384 x_cursor_to (int vpos
, int hpos
, int y
, int x
)
11388 /* If updated_window is not set, work on selected_window. */
11389 if (updated_window
)
11390 w
= updated_window
;
11392 w
= XWINDOW (selected_window
);
11394 /* Set the output cursor. */
11395 output_cursor
.hpos
= hpos
;
11396 output_cursor
.vpos
= vpos
;
11397 output_cursor
.x
= x
;
11398 output_cursor
.y
= y
;
11400 /* If not called as part of an update, really display the cursor.
11401 This will also set the cursor position of W. */
11402 if (updated_window
== NULL
)
11405 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
11406 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
11407 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
11412 #endif /* HAVE_WINDOW_SYSTEM */
11415 /***********************************************************************
11417 ***********************************************************************/
11419 #ifdef HAVE_WINDOW_SYSTEM
11421 /* Where the mouse was last time we reported a mouse event. */
11423 FRAME_PTR last_mouse_frame
;
11425 /* Tool-bar item index of the item on which a mouse button was pressed
11428 int last_tool_bar_item
;
11432 update_tool_bar_unwind (Lisp_Object frame
)
11434 selected_frame
= frame
;
11438 /* Update the tool-bar item list for frame F. This has to be done
11439 before we start to fill in any display lines. Called from
11440 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
11441 and restore it here. */
11444 update_tool_bar (struct frame
*f
, int save_match_data
)
11446 #if defined (USE_GTK) || defined (HAVE_NS)
11447 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
11449 int do_update
= WINDOWP (f
->tool_bar_window
)
11450 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
11455 Lisp_Object window
;
11458 window
= FRAME_SELECTED_WINDOW (f
);
11459 w
= XWINDOW (window
);
11461 /* If the user has switched buffers or windows, we need to
11462 recompute to reflect the new bindings. But we'll
11463 recompute when update_mode_lines is set too; that means
11464 that people can use force-mode-line-update to request
11465 that the menu bar be recomputed. The adverse effect on
11466 the rest of the redisplay algorithm is about the same as
11467 windows_or_buffers_changed anyway. */
11468 if (windows_or_buffers_changed
11469 || w
->update_mode_line
11470 || update_mode_lines
11471 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
11472 < BUF_MODIFF (XBUFFER (w
->buffer
)))
11473 != w
->last_had_star
)
11474 || ((!NILP (Vtransient_mark_mode
)
11475 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
11476 != !NILP (w
->region_showing
)))
11478 struct buffer
*prev
= current_buffer
;
11479 ptrdiff_t count
= SPECPDL_INDEX ();
11480 Lisp_Object frame
, new_tool_bar
;
11481 int new_n_tool_bar
;
11482 struct gcpro gcpro1
;
11484 /* Set current_buffer to the buffer of the selected
11485 window of the frame, so that we get the right local
11487 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11489 /* Save match data, if we must. */
11490 if (save_match_data
)
11491 record_unwind_save_match_data ();
11493 /* Make sure that we don't accidentally use bogus keymaps. */
11494 if (NILP (Voverriding_local_map_menu_flag
))
11496 specbind (Qoverriding_terminal_local_map
, Qnil
);
11497 specbind (Qoverriding_local_map
, Qnil
);
11500 GCPRO1 (new_tool_bar
);
11502 /* We must temporarily set the selected frame to this frame
11503 before calling tool_bar_items, because the calculation of
11504 the tool-bar keymap uses the selected frame (see
11505 `tool-bar-make-keymap' in tool-bar.el). */
11506 record_unwind_protect (update_tool_bar_unwind
, selected_frame
);
11507 XSETFRAME (frame
, f
);
11508 selected_frame
= frame
;
11510 /* Build desired tool-bar items from keymaps. */
11512 = tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
11515 /* Redisplay the tool-bar if we changed it. */
11516 if (new_n_tool_bar
!= f
->n_tool_bar_items
11517 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
11519 /* Redisplay that happens asynchronously due to an expose event
11520 may access f->tool_bar_items. Make sure we update both
11521 variables within BLOCK_INPUT so no such event interrupts. */
11523 fset_tool_bar_items (f
, new_tool_bar
);
11524 f
->n_tool_bar_items
= new_n_tool_bar
;
11525 w
->update_mode_line
= 1;
11531 unbind_to (count
, Qnil
);
11532 set_buffer_internal_1 (prev
);
11538 /* Set F->desired_tool_bar_string to a Lisp string representing frame
11539 F's desired tool-bar contents. F->tool_bar_items must have
11540 been set up previously by calling prepare_menu_bars. */
11543 build_desired_tool_bar_string (struct frame
*f
)
11545 int i
, size
, size_needed
;
11546 struct gcpro gcpro1
, gcpro2
, gcpro3
;
11547 Lisp_Object image
, plist
, props
;
11549 image
= plist
= props
= Qnil
;
11550 GCPRO3 (image
, plist
, props
);
11552 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
11553 Otherwise, make a new string. */
11555 /* The size of the string we might be able to reuse. */
11556 size
= (STRINGP (f
->desired_tool_bar_string
)
11557 ? SCHARS (f
->desired_tool_bar_string
)
11560 /* We need one space in the string for each image. */
11561 size_needed
= f
->n_tool_bar_items
;
11563 /* Reuse f->desired_tool_bar_string, if possible. */
11564 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
11565 fset_desired_tool_bar_string
11566 (f
, Fmake_string (make_number (size_needed
), make_number (' ')));
11569 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
11570 Fremove_text_properties (make_number (0), make_number (size
),
11571 props
, f
->desired_tool_bar_string
);
11574 /* Put a `display' property on the string for the images to display,
11575 put a `menu_item' property on tool-bar items with a value that
11576 is the index of the item in F's tool-bar item vector. */
11577 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
11579 #define PROP(IDX) \
11580 AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
11582 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
11583 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
11584 int hmargin
, vmargin
, relief
, idx
, end
;
11586 /* If image is a vector, choose the image according to the
11588 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
11589 if (VECTORP (image
))
11593 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
11594 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
11597 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
11598 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
11600 eassert (ASIZE (image
) >= idx
);
11601 image
= AREF (image
, idx
);
11606 /* Ignore invalid image specifications. */
11607 if (!valid_image_p (image
))
11610 /* Display the tool-bar button pressed, or depressed. */
11611 plist
= Fcopy_sequence (XCDR (image
));
11613 /* Compute margin and relief to draw. */
11614 relief
= (tool_bar_button_relief
>= 0
11615 ? tool_bar_button_relief
11616 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
11617 hmargin
= vmargin
= relief
;
11619 if (RANGED_INTEGERP (1, Vtool_bar_button_margin
,
11620 INT_MAX
- max (hmargin
, vmargin
)))
11622 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
11623 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
11625 else if (CONSP (Vtool_bar_button_margin
))
11627 if (RANGED_INTEGERP (1, XCAR (Vtool_bar_button_margin
),
11628 INT_MAX
- hmargin
))
11629 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
11631 if (RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin
),
11632 INT_MAX
- vmargin
))
11633 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
11636 if (auto_raise_tool_bar_buttons_p
)
11638 /* Add a `:relief' property to the image spec if the item is
11642 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
11649 /* If image is selected, display it pressed, i.e. with a
11650 negative relief. If it's not selected, display it with a
11652 plist
= Fplist_put (plist
, QCrelief
,
11654 ? make_number (-relief
)
11655 : make_number (relief
)));
11660 /* Put a margin around the image. */
11661 if (hmargin
|| vmargin
)
11663 if (hmargin
== vmargin
)
11664 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
11666 plist
= Fplist_put (plist
, QCmargin
,
11667 Fcons (make_number (hmargin
),
11668 make_number (vmargin
)));
11671 /* If button is not enabled, and we don't have special images
11672 for the disabled state, make the image appear disabled by
11673 applying an appropriate algorithm to it. */
11674 if (!enabled_p
&& idx
< 0)
11675 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
11677 /* Put a `display' text property on the string for the image to
11678 display. Put a `menu-item' property on the string that gives
11679 the start of this item's properties in the tool-bar items
11681 image
= Fcons (Qimage
, plist
);
11682 props
= list4 (Qdisplay
, image
,
11683 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
11685 /* Let the last image hide all remaining spaces in the tool bar
11686 string. The string can be longer than needed when we reuse a
11687 previous string. */
11688 if (i
+ 1 == f
->n_tool_bar_items
)
11689 end
= SCHARS (f
->desired_tool_bar_string
);
11692 Fadd_text_properties (make_number (i
), make_number (end
),
11693 props
, f
->desired_tool_bar_string
);
11701 /* Display one line of the tool-bar of frame IT->f.
11703 HEIGHT specifies the desired height of the tool-bar line.
11704 If the actual height of the glyph row is less than HEIGHT, the
11705 row's height is increased to HEIGHT, and the icons are centered
11706 vertically in the new height.
11708 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
11709 count a final empty row in case the tool-bar width exactly matches
11714 display_tool_bar_line (struct it
*it
, int height
)
11716 struct glyph_row
*row
= it
->glyph_row
;
11717 int max_x
= it
->last_visible_x
;
11718 struct glyph
*last
;
11720 prepare_desired_row (row
);
11721 row
->y
= it
->current_y
;
11723 /* Note that this isn't made use of if the face hasn't a box,
11724 so there's no need to check the face here. */
11725 it
->start_of_box_run_p
= 1;
11727 while (it
->current_x
< max_x
)
11729 int x
, n_glyphs_before
, i
, nglyphs
;
11730 struct it it_before
;
11732 /* Get the next display element. */
11733 if (!get_next_display_element (it
))
11735 /* Don't count empty row if we are counting needed tool-bar lines. */
11736 if (height
< 0 && !it
->hpos
)
11741 /* Produce glyphs. */
11742 n_glyphs_before
= row
->used
[TEXT_AREA
];
11745 PRODUCE_GLYPHS (it
);
11747 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
11749 x
= it_before
.current_x
;
11750 while (i
< nglyphs
)
11752 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
11754 if (x
+ glyph
->pixel_width
> max_x
)
11756 /* Glyph doesn't fit on line. Backtrack. */
11757 row
->used
[TEXT_AREA
] = n_glyphs_before
;
11759 /* If this is the only glyph on this line, it will never fit on the
11760 tool-bar, so skip it. But ensure there is at least one glyph,
11761 so we don't accidentally disable the tool-bar. */
11762 if (n_glyphs_before
== 0
11763 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
11769 x
+= glyph
->pixel_width
;
11773 /* Stop at line end. */
11774 if (ITERATOR_AT_END_OF_LINE_P (it
))
11777 set_iterator_to_next (it
, 1);
11782 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
11784 /* Use default face for the border below the tool bar.
11786 FIXME: When auto-resize-tool-bars is grow-only, there is
11787 no additional border below the possibly empty tool-bar lines.
11788 So to make the extra empty lines look "normal", we have to
11789 use the tool-bar face for the border too. */
11790 if (!row
->displays_text_p
&& !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
11791 it
->face_id
= DEFAULT_FACE_ID
;
11793 extend_face_to_end_of_line (it
);
11794 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
11795 last
->right_box_line_p
= 1;
11796 if (last
== row
->glyphs
[TEXT_AREA
])
11797 last
->left_box_line_p
= 1;
11799 /* Make line the desired height and center it vertically. */
11800 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
11802 /* Don't add more than one line height. */
11803 height
%= FRAME_LINE_HEIGHT (it
->f
);
11804 it
->max_ascent
+= height
/ 2;
11805 it
->max_descent
+= (height
+ 1) / 2;
11808 compute_line_metrics (it
);
11810 /* If line is empty, make it occupy the rest of the tool-bar. */
11811 if (!row
->displays_text_p
)
11813 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
11814 row
->visible_height
= row
->height
;
11815 row
->ascent
= row
->phys_ascent
= 0;
11816 row
->extra_line_spacing
= 0;
11819 row
->full_width_p
= 1;
11820 row
->continued_p
= 0;
11821 row
->truncated_on_left_p
= 0;
11822 row
->truncated_on_right_p
= 0;
11824 it
->current_x
= it
->hpos
= 0;
11825 it
->current_y
+= row
->height
;
11831 /* Max tool-bar height. */
11833 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
11834 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
11836 /* Value is the number of screen lines needed to make all tool-bar
11837 items of frame F visible. The number of actual rows needed is
11838 returned in *N_ROWS if non-NULL. */
11841 tool_bar_lines_needed (struct frame
*f
, int *n_rows
)
11843 struct window
*w
= XWINDOW (f
->tool_bar_window
);
11845 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
11846 the desired matrix, so use (unused) mode-line row as temporary row to
11847 avoid destroying the first tool-bar row. */
11848 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
11850 /* Initialize an iterator for iteration over
11851 F->desired_tool_bar_string in the tool-bar window of frame F. */
11852 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
11853 it
.first_visible_x
= 0;
11854 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
11855 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
11856 it
.paragraph_embedding
= L2R
;
11858 while (!ITERATOR_AT_END_P (&it
))
11860 clear_glyph_row (temp_row
);
11861 it
.glyph_row
= temp_row
;
11862 display_tool_bar_line (&it
, -1);
11864 clear_glyph_row (temp_row
);
11866 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
11868 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
11870 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
11874 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
11876 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
11877 (Lisp_Object frame
)
11884 frame
= selected_frame
;
11886 CHECK_FRAME (frame
);
11887 f
= XFRAME (frame
);
11889 if (WINDOWP (f
->tool_bar_window
)
11890 && (w
= XWINDOW (f
->tool_bar_window
),
11891 WINDOW_TOTAL_LINES (w
) > 0))
11893 update_tool_bar (f
, 1);
11894 if (f
->n_tool_bar_items
)
11896 build_desired_tool_bar_string (f
);
11897 nlines
= tool_bar_lines_needed (f
, NULL
);
11901 return make_number (nlines
);
11905 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
11906 height should be changed. */
11909 redisplay_tool_bar (struct frame
*f
)
11913 struct glyph_row
*row
;
11915 #if defined (USE_GTK) || defined (HAVE_NS)
11916 if (FRAME_EXTERNAL_TOOL_BAR (f
))
11917 update_frame_tool_bar (f
);
11921 /* If frame hasn't a tool-bar window or if it is zero-height, don't
11922 do anything. This means you must start with tool-bar-lines
11923 non-zero to get the auto-sizing effect. Or in other words, you
11924 can turn off tool-bars by specifying tool-bar-lines zero. */
11925 if (!WINDOWP (f
->tool_bar_window
)
11926 || (w
= XWINDOW (f
->tool_bar_window
),
11927 WINDOW_TOTAL_LINES (w
) == 0))
11930 /* Set up an iterator for the tool-bar window. */
11931 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
11932 it
.first_visible_x
= 0;
11933 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
11934 row
= it
.glyph_row
;
11936 /* Build a string that represents the contents of the tool-bar. */
11937 build_desired_tool_bar_string (f
);
11938 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
11939 /* FIXME: This should be controlled by a user option. But it
11940 doesn't make sense to have an R2L tool bar if the menu bar cannot
11941 be drawn also R2L, and making the menu bar R2L is tricky due
11942 toolkit-specific code that implements it. If an R2L tool bar is
11943 ever supported, display_tool_bar_line should also be augmented to
11944 call unproduce_glyphs like display_line and display_string
11946 it
.paragraph_embedding
= L2R
;
11948 if (f
->n_tool_bar_rows
== 0)
11952 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
11953 nlines
!= WINDOW_TOTAL_LINES (w
)))
11956 int old_height
= WINDOW_TOTAL_LINES (w
);
11958 XSETFRAME (frame
, f
);
11959 Fmodify_frame_parameters (frame
,
11960 Fcons (Fcons (Qtool_bar_lines
,
11961 make_number (nlines
)),
11963 if (WINDOW_TOTAL_LINES (w
) != old_height
)
11965 clear_glyph_matrix (w
->desired_matrix
);
11966 fonts_changed_p
= 1;
11972 /* Display as many lines as needed to display all tool-bar items. */
11974 if (f
->n_tool_bar_rows
> 0)
11976 int border
, rows
, height
, extra
;
11978 if (TYPE_RANGED_INTEGERP (int, Vtool_bar_border
))
11979 border
= XINT (Vtool_bar_border
);
11980 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
11981 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
11982 else if (EQ (Vtool_bar_border
, Qborder_width
))
11983 border
= f
->border_width
;
11989 rows
= f
->n_tool_bar_rows
;
11990 height
= max (1, (it
.last_visible_y
- border
) / rows
);
11991 extra
= it
.last_visible_y
- border
- height
* rows
;
11993 while (it
.current_y
< it
.last_visible_y
)
11996 if (extra
> 0 && rows
-- > 0)
11998 h
= (extra
+ rows
- 1) / rows
;
12001 display_tool_bar_line (&it
, height
+ h
);
12006 while (it
.current_y
< it
.last_visible_y
)
12007 display_tool_bar_line (&it
, 0);
12010 /* It doesn't make much sense to try scrolling in the tool-bar
12011 window, so don't do it. */
12012 w
->desired_matrix
->no_scrolling_p
= 1;
12013 w
->must_be_updated_p
= 1;
12015 if (!NILP (Vauto_resize_tool_bars
))
12017 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
12018 int change_height_p
= 0;
12020 /* If we couldn't display everything, change the tool-bar's
12021 height if there is room for more. */
12022 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
12023 && it
.current_y
< max_tool_bar_height
)
12024 change_height_p
= 1;
12026 row
= it
.glyph_row
- 1;
12028 /* If there are blank lines at the end, except for a partially
12029 visible blank line at the end that is smaller than
12030 FRAME_LINE_HEIGHT, change the tool-bar's height. */
12031 if (!row
->displays_text_p
12032 && row
->height
>= FRAME_LINE_HEIGHT (f
))
12033 change_height_p
= 1;
12035 /* If row displays tool-bar items, but is partially visible,
12036 change the tool-bar's height. */
12037 if (row
->displays_text_p
12038 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
12039 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
12040 change_height_p
= 1;
12042 /* Resize windows as needed by changing the `tool-bar-lines'
12043 frame parameter. */
12044 if (change_height_p
)
12047 int old_height
= WINDOW_TOTAL_LINES (w
);
12049 int nlines
= tool_bar_lines_needed (f
, &nrows
);
12051 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
12052 && !f
->minimize_tool_bar_window_p
)
12053 ? (nlines
> old_height
)
12054 : (nlines
!= old_height
));
12055 f
->minimize_tool_bar_window_p
= 0;
12057 if (change_height_p
)
12059 XSETFRAME (frame
, f
);
12060 Fmodify_frame_parameters (frame
,
12061 Fcons (Fcons (Qtool_bar_lines
,
12062 make_number (nlines
)),
12064 if (WINDOW_TOTAL_LINES (w
) != old_height
)
12066 clear_glyph_matrix (w
->desired_matrix
);
12067 f
->n_tool_bar_rows
= nrows
;
12068 fonts_changed_p
= 1;
12075 f
->minimize_tool_bar_window_p
= 0;
12080 /* Get information about the tool-bar item which is displayed in GLYPH
12081 on frame F. Return in *PROP_IDX the index where tool-bar item
12082 properties start in F->tool_bar_items. Value is zero if
12083 GLYPH doesn't display a tool-bar item. */
12086 tool_bar_item_info (struct frame
*f
, struct glyph
*glyph
, int *prop_idx
)
12092 /* This function can be called asynchronously, which means we must
12093 exclude any possibility that Fget_text_property signals an
12095 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
12096 charpos
= max (0, charpos
);
12098 /* Get the text property `menu-item' at pos. The value of that
12099 property is the start index of this item's properties in
12100 F->tool_bar_items. */
12101 prop
= Fget_text_property (make_number (charpos
),
12102 Qmenu_item
, f
->current_tool_bar_string
);
12103 if (INTEGERP (prop
))
12105 *prop_idx
= XINT (prop
);
12115 /* Get information about the tool-bar item at position X/Y on frame F.
12116 Return in *GLYPH a pointer to the glyph of the tool-bar item in
12117 the current matrix of the tool-bar window of F, or NULL if not
12118 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
12119 item in F->tool_bar_items. Value is
12121 -1 if X/Y is not on a tool-bar item
12122 0 if X/Y is on the same item that was highlighted before.
12126 get_tool_bar_item (struct frame
*f
, int x
, int y
, struct glyph
**glyph
,
12127 int *hpos
, int *vpos
, int *prop_idx
)
12129 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12130 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12133 /* Find the glyph under X/Y. */
12134 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
12135 if (*glyph
== NULL
)
12138 /* Get the start of this tool-bar item's properties in
12139 f->tool_bar_items. */
12140 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
12143 /* Is mouse on the highlighted item? */
12144 if (EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
)
12145 && *vpos
>= hlinfo
->mouse_face_beg_row
12146 && *vpos
<= hlinfo
->mouse_face_end_row
12147 && (*vpos
> hlinfo
->mouse_face_beg_row
12148 || *hpos
>= hlinfo
->mouse_face_beg_col
)
12149 && (*vpos
< hlinfo
->mouse_face_end_row
12150 || *hpos
< hlinfo
->mouse_face_end_col
12151 || hlinfo
->mouse_face_past_end
))
12159 Handle mouse button event on the tool-bar of frame F, at
12160 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
12161 0 for button release. MODIFIERS is event modifiers for button
12165 handle_tool_bar_click (struct frame
*f
, int x
, int y
, int down_p
,
12168 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12169 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12170 int hpos
, vpos
, prop_idx
;
12171 struct glyph
*glyph
;
12172 Lisp_Object enabled_p
;
12174 /* If not on the highlighted tool-bar item, return. */
12175 frame_to_window_pixel_xy (w
, &x
, &y
);
12176 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
12179 /* If item is disabled, do nothing. */
12180 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12181 if (NILP (enabled_p
))
12186 /* Show item in pressed state. */
12187 show_mouse_face (hlinfo
, DRAW_IMAGE_SUNKEN
);
12188 hlinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
12189 last_tool_bar_item
= prop_idx
;
12193 Lisp_Object key
, frame
;
12194 struct input_event event
;
12195 EVENT_INIT (event
);
12197 /* Show item in released state. */
12198 show_mouse_face (hlinfo
, DRAW_IMAGE_RAISED
);
12199 hlinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
12201 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
12203 XSETFRAME (frame
, f
);
12204 event
.kind
= TOOL_BAR_EVENT
;
12205 event
.frame_or_window
= frame
;
12207 kbd_buffer_store_event (&event
);
12209 event
.kind
= TOOL_BAR_EVENT
;
12210 event
.frame_or_window
= frame
;
12212 event
.modifiers
= modifiers
;
12213 kbd_buffer_store_event (&event
);
12214 last_tool_bar_item
= -1;
12219 /* Possibly highlight a tool-bar item on frame F when mouse moves to
12220 tool-bar window-relative coordinates X/Y. Called from
12221 note_mouse_highlight. */
12224 note_tool_bar_highlight (struct frame
*f
, int x
, int y
)
12226 Lisp_Object window
= f
->tool_bar_window
;
12227 struct window
*w
= XWINDOW (window
);
12228 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12229 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12231 struct glyph
*glyph
;
12232 struct glyph_row
*row
;
12234 Lisp_Object enabled_p
;
12236 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
12237 int mouse_down_p
, rc
;
12239 /* Function note_mouse_highlight is called with negative X/Y
12240 values when mouse moves outside of the frame. */
12241 if (x
<= 0 || y
<= 0)
12243 clear_mouse_face (hlinfo
);
12247 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
12250 /* Not on tool-bar item. */
12251 clear_mouse_face (hlinfo
);
12255 /* On same tool-bar item as before. */
12256 goto set_help_echo
;
12258 clear_mouse_face (hlinfo
);
12260 /* Mouse is down, but on different tool-bar item? */
12261 mouse_down_p
= (dpyinfo
->grabbed
12262 && f
== last_mouse_frame
12263 && FRAME_LIVE_P (f
));
12265 && last_tool_bar_item
!= prop_idx
)
12268 hlinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
12269 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
12271 /* If tool-bar item is not enabled, don't highlight it. */
12272 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12273 if (!NILP (enabled_p
))
12275 /* Compute the x-position of the glyph. In front and past the
12276 image is a space. We include this in the highlighted area. */
12277 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
12278 for (i
= x
= 0; i
< hpos
; ++i
)
12279 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
12281 /* Record this as the current active region. */
12282 hlinfo
->mouse_face_beg_col
= hpos
;
12283 hlinfo
->mouse_face_beg_row
= vpos
;
12284 hlinfo
->mouse_face_beg_x
= x
;
12285 hlinfo
->mouse_face_beg_y
= row
->y
;
12286 hlinfo
->mouse_face_past_end
= 0;
12288 hlinfo
->mouse_face_end_col
= hpos
+ 1;
12289 hlinfo
->mouse_face_end_row
= vpos
;
12290 hlinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
12291 hlinfo
->mouse_face_end_y
= row
->y
;
12292 hlinfo
->mouse_face_window
= window
;
12293 hlinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
12295 /* Display it as active. */
12296 show_mouse_face (hlinfo
, draw
);
12297 hlinfo
->mouse_face_image_state
= draw
;
12302 /* Set help_echo_string to a help string to display for this tool-bar item.
12303 XTread_socket does the rest. */
12304 help_echo_object
= help_echo_window
= Qnil
;
12305 help_echo_pos
= -1;
12306 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
12307 if (NILP (help_echo_string
))
12308 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
12311 #endif /* HAVE_WINDOW_SYSTEM */
12315 /************************************************************************
12316 Horizontal scrolling
12317 ************************************************************************/
12319 static int hscroll_window_tree (Lisp_Object
);
12320 static int hscroll_windows (Lisp_Object
);
12322 /* For all leaf windows in the window tree rooted at WINDOW, set their
12323 hscroll value so that PT is (i) visible in the window, and (ii) so
12324 that it is not within a certain margin at the window's left and
12325 right border. Value is non-zero if any window's hscroll has been
12329 hscroll_window_tree (Lisp_Object window
)
12331 int hscrolled_p
= 0;
12332 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
12333 int hscroll_step_abs
= 0;
12334 double hscroll_step_rel
= 0;
12336 if (hscroll_relative_p
)
12338 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
12339 if (hscroll_step_rel
< 0)
12341 hscroll_relative_p
= 0;
12342 hscroll_step_abs
= 0;
12345 else if (TYPE_RANGED_INTEGERP (int, Vhscroll_step
))
12347 hscroll_step_abs
= XINT (Vhscroll_step
);
12348 if (hscroll_step_abs
< 0)
12349 hscroll_step_abs
= 0;
12352 hscroll_step_abs
= 0;
12354 while (WINDOWP (window
))
12356 struct window
*w
= XWINDOW (window
);
12358 if (WINDOWP (w
->hchild
))
12359 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
12360 else if (WINDOWP (w
->vchild
))
12361 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
12362 else if (w
->cursor
.vpos
>= 0)
12365 int text_area_width
;
12366 struct glyph_row
*current_cursor_row
12367 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
12368 struct glyph_row
*desired_cursor_row
12369 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
12370 struct glyph_row
*cursor_row
12371 = (desired_cursor_row
->enabled_p
12372 ? desired_cursor_row
12373 : current_cursor_row
);
12374 int row_r2l_p
= cursor_row
->reversed_p
;
12376 text_area_width
= window_box_width (w
, TEXT_AREA
);
12378 /* Scroll when cursor is inside this scroll margin. */
12379 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
12381 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->buffer
))
12382 /* For left-to-right rows, hscroll when cursor is either
12383 (i) inside the right hscroll margin, or (ii) if it is
12384 inside the left margin and the window is already
12388 && w
->cursor
.x
<= h_margin
)
12389 || (cursor_row
->enabled_p
12390 && cursor_row
->truncated_on_right_p
12391 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
12392 /* For right-to-left rows, the logic is similar,
12393 except that rules for scrolling to left and right
12394 are reversed. E.g., if cursor.x <= h_margin, we
12395 need to hscroll "to the right" unconditionally,
12396 and that will scroll the screen to the left so as
12397 to reveal the next portion of the row. */
12399 && ((cursor_row
->enabled_p
12400 /* FIXME: It is confusing to set the
12401 truncated_on_right_p flag when R2L rows
12402 are actually truncated on the left. */
12403 && cursor_row
->truncated_on_right_p
12404 && w
->cursor
.x
<= h_margin
)
12406 && (w
->cursor
.x
>= text_area_width
- h_margin
))))))
12410 struct buffer
*saved_current_buffer
;
12414 /* Find point in a display of infinite width. */
12415 saved_current_buffer
= current_buffer
;
12416 current_buffer
= XBUFFER (w
->buffer
);
12418 if (w
== XWINDOW (selected_window
))
12422 pt
= marker_position (w
->pointm
);
12423 pt
= max (BEGV
, pt
);
12427 /* Move iterator to pt starting at cursor_row->start in
12428 a line with infinite width. */
12429 init_to_row_start (&it
, w
, cursor_row
);
12430 it
.last_visible_x
= INFINITY
;
12431 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
12432 current_buffer
= saved_current_buffer
;
12434 /* Position cursor in window. */
12435 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
12436 hscroll
= max (0, (it
.current_x
12437 - (ITERATOR_AT_END_OF_LINE_P (&it
)
12438 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
12439 : (text_area_width
/ 2))))
12440 / FRAME_COLUMN_WIDTH (it
.f
);
12441 else if ((!row_r2l_p
12442 && w
->cursor
.x
>= text_area_width
- h_margin
)
12443 || (row_r2l_p
&& w
->cursor
.x
<= h_margin
))
12445 if (hscroll_relative_p
)
12446 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
12449 wanted_x
= text_area_width
12450 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12453 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12457 if (hscroll_relative_p
)
12458 wanted_x
= text_area_width
* hscroll_step_rel
12461 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12464 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12466 hscroll
= max (hscroll
, w
->min_hscroll
);
12468 /* Don't prevent redisplay optimizations if hscroll
12469 hasn't changed, as it will unnecessarily slow down
12471 if (w
->hscroll
!= hscroll
)
12473 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
12474 w
->hscroll
= hscroll
;
12483 /* Value is non-zero if hscroll of any leaf window has been changed. */
12484 return hscrolled_p
;
12488 /* Set hscroll so that cursor is visible and not inside horizontal
12489 scroll margins for all windows in the tree rooted at WINDOW. See
12490 also hscroll_window_tree above. Value is non-zero if any window's
12491 hscroll has been changed. If it has, desired matrices on the frame
12492 of WINDOW are cleared. */
12495 hscroll_windows (Lisp_Object window
)
12497 int hscrolled_p
= hscroll_window_tree (window
);
12499 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
12500 return hscrolled_p
;
12505 /************************************************************************
12507 ************************************************************************/
12509 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
12510 to a non-zero value. This is sometimes handy to have in a debugger
12515 /* First and last unchanged row for try_window_id. */
12517 static int debug_first_unchanged_at_end_vpos
;
12518 static int debug_last_unchanged_at_beg_vpos
;
12520 /* Delta vpos and y. */
12522 static int debug_dvpos
, debug_dy
;
12524 /* Delta in characters and bytes for try_window_id. */
12526 static ptrdiff_t debug_delta
, debug_delta_bytes
;
12528 /* Values of window_end_pos and window_end_vpos at the end of
12531 static ptrdiff_t debug_end_vpos
;
12533 /* Append a string to W->desired_matrix->method. FMT is a printf
12534 format string. If trace_redisplay_p is non-zero also printf the
12535 resulting string to stderr. */
12537 static void debug_method_add (struct window
*, char const *, ...)
12538 ATTRIBUTE_FORMAT_PRINTF (2, 3);
12541 debug_method_add (struct window
*w
, char const *fmt
, ...)
12543 char *method
= w
->desired_matrix
->method
;
12544 int len
= strlen (method
);
12545 int size
= sizeof w
->desired_matrix
->method
;
12546 int remaining
= size
- len
- 1;
12549 if (len
&& remaining
)
12552 --remaining
, ++len
;
12555 va_start (ap
, fmt
);
12556 vsnprintf (method
+ len
, remaining
+ 1, fmt
, ap
);
12559 if (trace_redisplay_p
)
12560 fprintf (stderr
, "%p (%s): %s\n",
12562 ((BUFFERP (w
->buffer
)
12563 && STRINGP (BVAR (XBUFFER (w
->buffer
), name
)))
12564 ? SSDATA (BVAR (XBUFFER (w
->buffer
), name
))
12569 #endif /* GLYPH_DEBUG */
12572 /* Value is non-zero if all changes in window W, which displays
12573 current_buffer, are in the text between START and END. START is a
12574 buffer position, END is given as a distance from Z. Used in
12575 redisplay_internal for display optimization. */
12578 text_outside_line_unchanged_p (struct window
*w
,
12579 ptrdiff_t start
, ptrdiff_t end
)
12581 int unchanged_p
= 1;
12583 /* If text or overlays have changed, see where. */
12584 if (w
->last_modified
< MODIFF
12585 || w
->last_overlay_modified
< OVERLAY_MODIFF
)
12587 /* Gap in the line? */
12588 if (GPT
< start
|| Z
- GPT
< end
)
12591 /* Changes start in front of the line, or end after it? */
12593 && (BEG_UNCHANGED
< start
- 1
12594 || END_UNCHANGED
< end
))
12597 /* If selective display, can't optimize if changes start at the
12598 beginning of the line. */
12600 && INTEGERP (BVAR (current_buffer
, selective_display
))
12601 && XINT (BVAR (current_buffer
, selective_display
)) > 0
12602 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
12605 /* If there are overlays at the start or end of the line, these
12606 may have overlay strings with newlines in them. A change at
12607 START, for instance, may actually concern the display of such
12608 overlay strings as well, and they are displayed on different
12609 lines. So, quickly rule out this case. (For the future, it
12610 might be desirable to implement something more telling than
12611 just BEG/END_UNCHANGED.) */
12614 if (BEG
+ BEG_UNCHANGED
== start
12615 && overlay_touches_p (start
))
12617 if (END_UNCHANGED
== end
12618 && overlay_touches_p (Z
- end
))
12622 /* Under bidi reordering, adding or deleting a character in the
12623 beginning of a paragraph, before the first strong directional
12624 character, can change the base direction of the paragraph (unless
12625 the buffer specifies a fixed paragraph direction), which will
12626 require to redisplay the whole paragraph. It might be worthwhile
12627 to find the paragraph limits and widen the range of redisplayed
12628 lines to that, but for now just give up this optimization. */
12629 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
12630 && NILP (BVAR (XBUFFER (w
->buffer
), bidi_paragraph_direction
)))
12634 return unchanged_p
;
12638 /* Do a frame update, taking possible shortcuts into account. This is
12639 the main external entry point for redisplay.
12641 If the last redisplay displayed an echo area message and that message
12642 is no longer requested, we clear the echo area or bring back the
12643 mini-buffer if that is in use. */
12648 redisplay_internal ();
12653 overlay_arrow_string_or_property (Lisp_Object var
)
12657 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
12660 return Voverlay_arrow_string
;
12663 /* Return 1 if there are any overlay-arrows in current_buffer. */
12665 overlay_arrow_in_current_buffer_p (void)
12669 for (vlist
= Voverlay_arrow_variable_list
;
12671 vlist
= XCDR (vlist
))
12673 Lisp_Object var
= XCAR (vlist
);
12676 if (!SYMBOLP (var
))
12678 val
= find_symbol_value (var
);
12680 && current_buffer
== XMARKER (val
)->buffer
)
12687 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
12691 overlay_arrows_changed_p (void)
12695 for (vlist
= Voverlay_arrow_variable_list
;
12697 vlist
= XCDR (vlist
))
12699 Lisp_Object var
= XCAR (vlist
);
12700 Lisp_Object val
, pstr
;
12702 if (!SYMBOLP (var
))
12704 val
= find_symbol_value (var
);
12705 if (!MARKERP (val
))
12707 if (! EQ (COERCE_MARKER (val
),
12708 Fget (var
, Qlast_arrow_position
))
12709 || ! (pstr
= overlay_arrow_string_or_property (var
),
12710 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
12716 /* Mark overlay arrows to be updated on next redisplay. */
12719 update_overlay_arrows (int up_to_date
)
12723 for (vlist
= Voverlay_arrow_variable_list
;
12725 vlist
= XCDR (vlist
))
12727 Lisp_Object var
= XCAR (vlist
);
12729 if (!SYMBOLP (var
))
12732 if (up_to_date
> 0)
12734 Lisp_Object val
= find_symbol_value (var
);
12735 Fput (var
, Qlast_arrow_position
,
12736 COERCE_MARKER (val
));
12737 Fput (var
, Qlast_arrow_string
,
12738 overlay_arrow_string_or_property (var
));
12740 else if (up_to_date
< 0
12741 || !NILP (Fget (var
, Qlast_arrow_position
)))
12743 Fput (var
, Qlast_arrow_position
, Qt
);
12744 Fput (var
, Qlast_arrow_string
, Qt
);
12750 /* Return overlay arrow string to display at row.
12751 Return integer (bitmap number) for arrow bitmap in left fringe.
12752 Return nil if no overlay arrow. */
12755 overlay_arrow_at_row (struct it
*it
, struct glyph_row
*row
)
12759 for (vlist
= Voverlay_arrow_variable_list
;
12761 vlist
= XCDR (vlist
))
12763 Lisp_Object var
= XCAR (vlist
);
12766 if (!SYMBOLP (var
))
12769 val
= find_symbol_value (var
);
12772 && current_buffer
== XMARKER (val
)->buffer
12773 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
12775 if (FRAME_WINDOW_P (it
->f
)
12776 /* FIXME: if ROW->reversed_p is set, this should test
12777 the right fringe, not the left one. */
12778 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
12780 #ifdef HAVE_WINDOW_SYSTEM
12781 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
12784 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
12785 return make_number (fringe_bitmap
);
12788 return make_number (-1); /* Use default arrow bitmap. */
12790 return overlay_arrow_string_or_property (var
);
12797 /* Return 1 if point moved out of or into a composition. Otherwise
12798 return 0. PREV_BUF and PREV_PT are the last point buffer and
12799 position. BUF and PT are the current point buffer and position. */
12802 check_point_in_composition (struct buffer
*prev_buf
, ptrdiff_t prev_pt
,
12803 struct buffer
*buf
, ptrdiff_t pt
)
12805 ptrdiff_t start
, end
;
12807 Lisp_Object buffer
;
12809 XSETBUFFER (buffer
, buf
);
12810 /* Check a composition at the last point if point moved within the
12812 if (prev_buf
== buf
)
12815 /* Point didn't move. */
12818 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
12819 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
12820 && COMPOSITION_VALID_P (start
, end
, prop
)
12821 && start
< prev_pt
&& end
> prev_pt
)
12822 /* The last point was within the composition. Return 1 iff
12823 point moved out of the composition. */
12824 return (pt
<= start
|| pt
>= end
);
12827 /* Check a composition at the current point. */
12828 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
12829 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
12830 && COMPOSITION_VALID_P (start
, end
, prop
)
12831 && start
< pt
&& end
> pt
);
12835 /* Reconsider the setting of B->clip_changed which is displayed
12839 reconsider_clip_changes (struct window
*w
, struct buffer
*b
)
12841 if (b
->clip_changed
12842 && !NILP (w
->window_end_valid
)
12843 && w
->current_matrix
->buffer
== b
12844 && w
->current_matrix
->zv
== BUF_ZV (b
)
12845 && w
->current_matrix
->begv
== BUF_BEGV (b
))
12846 b
->clip_changed
= 0;
12848 /* If display wasn't paused, and W is not a tool bar window, see if
12849 point has been moved into or out of a composition. In that case,
12850 we set b->clip_changed to 1 to force updating the screen. If
12851 b->clip_changed has already been set to 1, we can skip this
12853 if (!b
->clip_changed
12854 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
12858 if (w
== XWINDOW (selected_window
))
12861 pt
= marker_position (w
->pointm
);
12863 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
12864 || pt
!= w
->last_point
)
12865 && check_point_in_composition (w
->current_matrix
->buffer
,
12867 XBUFFER (w
->buffer
), pt
))
12868 b
->clip_changed
= 1;
12873 /* Select FRAME to forward the values of frame-local variables into C
12874 variables so that the redisplay routines can access those values
12878 select_frame_for_redisplay (Lisp_Object frame
)
12880 Lisp_Object tail
, tem
;
12881 Lisp_Object old
= selected_frame
;
12882 struct Lisp_Symbol
*sym
;
12884 eassert (FRAMEP (frame
) && FRAME_LIVE_P (XFRAME (frame
)));
12886 selected_frame
= frame
;
12889 for (tail
= XFRAME (frame
)->param_alist
;
12890 CONSP (tail
); tail
= XCDR (tail
))
12891 if (CONSP (XCAR (tail
))
12892 && (tem
= XCAR (XCAR (tail
)),
12894 && (sym
= indirect_variable (XSYMBOL (tem
)),
12895 sym
->redirect
== SYMBOL_LOCALIZED
)
12896 && sym
->val
.blv
->frame_local
)
12897 /* Use find_symbol_value rather than Fsymbol_value
12898 to avoid an error if it is void. */
12899 find_symbol_value (tem
);
12900 } while (!EQ (frame
, old
) && (frame
= old
, 1));
12904 #define STOP_POLLING \
12905 do { if (! polling_stopped_here) stop_polling (); \
12906 polling_stopped_here = 1; } while (0)
12908 #define RESUME_POLLING \
12909 do { if (polling_stopped_here) start_polling (); \
12910 polling_stopped_here = 0; } while (0)
12913 /* Perhaps in the future avoid recentering windows if it
12914 is not necessary; currently that causes some problems. */
12917 redisplay_internal (void)
12919 struct window
*w
= XWINDOW (selected_window
);
12923 int must_finish
= 0;
12924 struct text_pos tlbufpos
, tlendpos
;
12925 int number_of_visible_frames
;
12926 ptrdiff_t count
, count1
;
12928 int polling_stopped_here
= 0;
12929 Lisp_Object old_frame
= selected_frame
;
12931 /* Non-zero means redisplay has to consider all windows on all
12932 frames. Zero means, only selected_window is considered. */
12933 int consider_all_windows_p
;
12935 /* Non-zero means redisplay has to redisplay the miniwindow */
12936 int update_miniwindow_p
= 0;
12938 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
12940 /* No redisplay if running in batch mode or frame is not yet fully
12941 initialized, or redisplay is explicitly turned off by setting
12942 Vinhibit_redisplay. */
12943 if (FRAME_INITIAL_P (SELECTED_FRAME ())
12944 || !NILP (Vinhibit_redisplay
))
12947 /* Don't examine these until after testing Vinhibit_redisplay.
12948 When Emacs is shutting down, perhaps because its connection to
12949 X has dropped, we should not look at them at all. */
12950 fr
= XFRAME (w
->frame
);
12951 sf
= SELECTED_FRAME ();
12953 if (!fr
->glyphs_initialized_p
)
12956 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
12957 if (popup_activated ())
12961 /* I don't think this happens but let's be paranoid. */
12962 if (redisplaying_p
)
12965 /* Record a function that clears redisplaying_p
12966 when we leave this function. */
12967 count
= SPECPDL_INDEX ();
12968 record_unwind_protect (unwind_redisplay
, selected_frame
);
12969 redisplaying_p
= 1;
12970 specbind (Qinhibit_free_realized_faces
, Qnil
);
12973 Lisp_Object tail
, frame
;
12975 FOR_EACH_FRAME (tail
, frame
)
12977 struct frame
*f
= XFRAME (frame
);
12978 f
->already_hscrolled_p
= 0;
12983 /* Remember the currently selected window. */
12986 if (!EQ (old_frame
, selected_frame
)
12987 && FRAME_LIVE_P (XFRAME (old_frame
)))
12988 /* When running redisplay, we play a bit fast-and-loose and allow e.g.
12989 selected_frame and selected_window to be temporarily out-of-sync so
12990 when we come back here via `goto retry', we need to resync because we
12991 may need to run Elisp code (via prepare_menu_bars). */
12992 select_frame_for_redisplay (old_frame
);
12995 reconsider_clip_changes (w
, current_buffer
);
12996 last_escape_glyph_frame
= NULL
;
12997 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
12998 last_glyphless_glyph_frame
= NULL
;
12999 last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
13001 /* If new fonts have been loaded that make a glyph matrix adjustment
13002 necessary, do it. */
13003 if (fonts_changed_p
)
13005 adjust_glyphs (NULL
);
13006 ++windows_or_buffers_changed
;
13007 fonts_changed_p
= 0;
13010 /* If face_change_count is non-zero, init_iterator will free all
13011 realized faces, which includes the faces referenced from current
13012 matrices. So, we can't reuse current matrices in this case. */
13013 if (face_change_count
)
13014 ++windows_or_buffers_changed
;
13016 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
13017 && FRAME_TTY (sf
)->previous_frame
!= sf
)
13019 /* Since frames on a single ASCII terminal share the same
13020 display area, displaying a different frame means redisplay
13021 the whole thing. */
13022 windows_or_buffers_changed
++;
13023 SET_FRAME_GARBAGED (sf
);
13025 set_tty_color_mode (FRAME_TTY (sf
), sf
);
13027 FRAME_TTY (sf
)->previous_frame
= sf
;
13030 /* Set the visible flags for all frames. Do this before checking
13031 for resized or garbaged frames; they want to know if their frames
13032 are visible. See the comment in frame.h for
13033 FRAME_SAMPLE_VISIBILITY. */
13035 Lisp_Object tail
, frame
;
13037 number_of_visible_frames
= 0;
13039 FOR_EACH_FRAME (tail
, frame
)
13041 struct frame
*f
= XFRAME (frame
);
13043 FRAME_SAMPLE_VISIBILITY (f
);
13044 if (FRAME_VISIBLE_P (f
))
13045 ++number_of_visible_frames
;
13046 clear_desired_matrices (f
);
13050 /* Notice any pending interrupt request to change frame size. */
13051 do_pending_window_change (1);
13053 /* do_pending_window_change could change the selected_window due to
13054 frame resizing which makes the selected window too small. */
13055 if (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
)
13058 reconsider_clip_changes (w
, current_buffer
);
13061 /* Clear frames marked as garbaged. */
13062 if (frame_garbaged
)
13063 clear_garbaged_frames ();
13065 /* Build menubar and tool-bar items. */
13066 if (NILP (Vmemory_full
))
13067 prepare_menu_bars ();
13069 if (windows_or_buffers_changed
)
13070 update_mode_lines
++;
13072 /* Detect case that we need to write or remove a star in the mode line. */
13073 if ((SAVE_MODIFF
< MODIFF
) != w
->last_had_star
)
13075 w
->update_mode_line
= 1;
13076 if (buffer_shared
> 1)
13077 update_mode_lines
++;
13080 /* Avoid invocation of point motion hooks by `current_column' below. */
13081 count1
= SPECPDL_INDEX ();
13082 specbind (Qinhibit_point_motion_hooks
, Qt
);
13084 /* If %c is in the mode line, update it if needed. */
13085 if (!NILP (w
->column_number_displayed
)
13086 /* This alternative quickly identifies a common case
13087 where no change is needed. */
13088 && !(PT
== w
->last_point
13089 && w
->last_modified
>= MODIFF
13090 && w
->last_overlay_modified
>= OVERLAY_MODIFF
)
13091 && (XFASTINT (w
->column_number_displayed
) != current_column ()))
13092 w
->update_mode_line
= 1;
13094 unbind_to (count1
, Qnil
);
13096 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
13098 /* The variable buffer_shared is set in redisplay_window and
13099 indicates that we redisplay a buffer in different windows. See
13101 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
13102 || cursor_type_changed
);
13104 /* If specs for an arrow have changed, do thorough redisplay
13105 to ensure we remove any arrow that should no longer exist. */
13106 if (overlay_arrows_changed_p ())
13107 consider_all_windows_p
= windows_or_buffers_changed
= 1;
13109 /* Normally the message* functions will have already displayed and
13110 updated the echo area, but the frame may have been trashed, or
13111 the update may have been preempted, so display the echo area
13112 again here. Checking message_cleared_p captures the case that
13113 the echo area should be cleared. */
13114 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
13115 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
13116 || (message_cleared_p
13117 && minibuf_level
== 0
13118 /* If the mini-window is currently selected, this means the
13119 echo-area doesn't show through. */
13120 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
13122 int window_height_changed_p
= echo_area_display (0);
13124 if (message_cleared_p
)
13125 update_miniwindow_p
= 1;
13129 /* If we don't display the current message, don't clear the
13130 message_cleared_p flag, because, if we did, we wouldn't clear
13131 the echo area in the next redisplay which doesn't preserve
13133 if (!display_last_displayed_message_p
)
13134 message_cleared_p
= 0;
13136 if (fonts_changed_p
)
13138 else if (window_height_changed_p
)
13140 consider_all_windows_p
= 1;
13141 ++update_mode_lines
;
13142 ++windows_or_buffers_changed
;
13144 /* If window configuration was changed, frames may have been
13145 marked garbaged. Clear them or we will experience
13146 surprises wrt scrolling. */
13147 if (frame_garbaged
)
13148 clear_garbaged_frames ();
13151 else if (EQ (selected_window
, minibuf_window
)
13152 && (current_buffer
->clip_changed
13153 || w
->last_modified
< MODIFF
13154 || w
->last_overlay_modified
< OVERLAY_MODIFF
)
13155 && resize_mini_window (w
, 0))
13157 /* Resized active mini-window to fit the size of what it is
13158 showing if its contents might have changed. */
13160 /* FIXME: this causes all frames to be updated, which seems unnecessary
13161 since only the current frame needs to be considered. This function needs
13162 to be rewritten with two variables, consider_all_windows and
13163 consider_all_frames. */
13164 consider_all_windows_p
= 1;
13165 ++windows_or_buffers_changed
;
13166 ++update_mode_lines
;
13168 /* If window configuration was changed, frames may have been
13169 marked garbaged. Clear them or we will experience
13170 surprises wrt scrolling. */
13171 if (frame_garbaged
)
13172 clear_garbaged_frames ();
13176 /* If showing the region, and mark has changed, we must redisplay
13177 the whole window. The assignment to this_line_start_pos prevents
13178 the optimization directly below this if-statement. */
13179 if (((!NILP (Vtransient_mark_mode
)
13180 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
13181 != !NILP (w
->region_showing
))
13182 || (!NILP (w
->region_showing
)
13183 && !EQ (w
->region_showing
,
13184 Fmarker_position (BVAR (XBUFFER (w
->buffer
), mark
)))))
13185 CHARPOS (this_line_start_pos
) = 0;
13187 /* Optimize the case that only the line containing the cursor in the
13188 selected window has changed. Variables starting with this_ are
13189 set in display_line and record information about the line
13190 containing the cursor. */
13191 tlbufpos
= this_line_start_pos
;
13192 tlendpos
= this_line_end_pos
;
13193 if (!consider_all_windows_p
13194 && CHARPOS (tlbufpos
) > 0
13195 && !w
->update_mode_line
13196 && !current_buffer
->clip_changed
13197 && !current_buffer
->prevent_redisplay_optimizations_p
13198 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
13199 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
13200 /* Make sure recorded data applies to current buffer, etc. */
13201 && this_line_buffer
== current_buffer
13202 && current_buffer
== XBUFFER (w
->buffer
)
13204 && !w
->optional_new_start
13205 /* Point must be on the line that we have info recorded about. */
13206 && PT
>= CHARPOS (tlbufpos
)
13207 && PT
<= Z
- CHARPOS (tlendpos
)
13208 /* All text outside that line, including its final newline,
13209 must be unchanged. */
13210 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
13211 CHARPOS (tlendpos
)))
13213 if (CHARPOS (tlbufpos
) > BEGV
13214 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
13215 && (CHARPOS (tlbufpos
) == ZV
13216 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
13217 /* Former continuation line has disappeared by becoming empty. */
13219 else if (w
->last_modified
< MODIFF
13220 || w
->last_overlay_modified
< OVERLAY_MODIFF
13221 || MINI_WINDOW_P (w
))
13223 /* We have to handle the case of continuation around a
13224 wide-column character (see the comment in indent.c around
13227 For instance, in the following case:
13229 -------- Insert --------
13230 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
13231 J_I_ ==> J_I_ `^^' are cursors.
13235 As we have to redraw the line above, we cannot use this
13239 int line_height_before
= this_line_pixel_height
;
13241 /* Note that start_display will handle the case that the
13242 line starting at tlbufpos is a continuation line. */
13243 start_display (&it
, w
, tlbufpos
);
13245 /* Implementation note: It this still necessary? */
13246 if (it
.current_x
!= this_line_start_x
)
13249 TRACE ((stderr
, "trying display optimization 1\n"));
13250 w
->cursor
.vpos
= -1;
13251 overlay_arrow_seen
= 0;
13252 it
.vpos
= this_line_vpos
;
13253 it
.current_y
= this_line_y
;
13254 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
13255 display_line (&it
);
13257 /* If line contains point, is not continued,
13258 and ends at same distance from eob as before, we win. */
13259 if (w
->cursor
.vpos
>= 0
13260 /* Line is not continued, otherwise this_line_start_pos
13261 would have been set to 0 in display_line. */
13262 && CHARPOS (this_line_start_pos
)
13263 /* Line ends as before. */
13264 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
13265 /* Line has same height as before. Otherwise other lines
13266 would have to be shifted up or down. */
13267 && this_line_pixel_height
== line_height_before
)
13269 /* If this is not the window's last line, we must adjust
13270 the charstarts of the lines below. */
13271 if (it
.current_y
< it
.last_visible_y
)
13273 struct glyph_row
*row
13274 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
13275 ptrdiff_t delta
, delta_bytes
;
13277 /* We used to distinguish between two cases here,
13278 conditioned by Z - CHARPOS (tlendpos) == ZV, for
13279 when the line ends in a newline or the end of the
13280 buffer's accessible portion. But both cases did
13281 the same, so they were collapsed. */
13283 - CHARPOS (tlendpos
)
13284 - MATRIX_ROW_START_CHARPOS (row
));
13285 delta_bytes
= (Z_BYTE
13286 - BYTEPOS (tlendpos
)
13287 - MATRIX_ROW_START_BYTEPOS (row
));
13289 increment_matrix_positions (w
->current_matrix
,
13290 this_line_vpos
+ 1,
13291 w
->current_matrix
->nrows
,
13292 delta
, delta_bytes
);
13295 /* If this row displays text now but previously didn't,
13296 or vice versa, w->window_end_vpos may have to be
13298 if ((it
.glyph_row
- 1)->displays_text_p
)
13300 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
13301 wset_window_end_vpos (w
, make_number (this_line_vpos
));
13303 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
13304 && this_line_vpos
> 0)
13305 wset_window_end_vpos (w
, make_number (this_line_vpos
- 1));
13306 wset_window_end_valid (w
, Qnil
);
13308 /* Update hint: No need to try to scroll in update_window. */
13309 w
->desired_matrix
->no_scrolling_p
= 1;
13312 *w
->desired_matrix
->method
= 0;
13313 debug_method_add (w
, "optimization 1");
13315 #ifdef HAVE_WINDOW_SYSTEM
13316 update_window_fringes (w
, 0);
13323 else if (/* Cursor position hasn't changed. */
13324 PT
== w
->last_point
13325 /* Make sure the cursor was last displayed
13326 in this window. Otherwise we have to reposition it. */
13327 && 0 <= w
->cursor
.vpos
13328 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
13332 do_pending_window_change (1);
13333 /* If selected_window changed, redisplay again. */
13334 if (WINDOWP (selected_window
)
13335 && (w
= XWINDOW (selected_window
)) != sw
)
13338 /* We used to always goto end_of_redisplay here, but this
13339 isn't enough if we have a blinking cursor. */
13340 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
13341 goto end_of_redisplay
;
13345 /* If highlighting the region, or if the cursor is in the echo area,
13346 then we can't just move the cursor. */
13347 else if (! (!NILP (Vtransient_mark_mode
)
13348 && !NILP (BVAR (current_buffer
, mark_active
)))
13349 && (EQ (selected_window
,
13350 BVAR (current_buffer
, last_selected_window
))
13351 || highlight_nonselected_windows
)
13352 && NILP (w
->region_showing
)
13353 && NILP (Vshow_trailing_whitespace
)
13354 && !cursor_in_echo_area
)
13357 struct glyph_row
*row
;
13359 /* Skip from tlbufpos to PT and see where it is. Note that
13360 PT may be in invisible text. If so, we will end at the
13361 next visible position. */
13362 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
13363 NULL
, DEFAULT_FACE_ID
);
13364 it
.current_x
= this_line_start_x
;
13365 it
.current_y
= this_line_y
;
13366 it
.vpos
= this_line_vpos
;
13368 /* The call to move_it_to stops in front of PT, but
13369 moves over before-strings. */
13370 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
13372 if (it
.vpos
== this_line_vpos
13373 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
13376 eassert (this_line_vpos
== it
.vpos
);
13377 eassert (this_line_y
== it
.current_y
);
13378 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13380 *w
->desired_matrix
->method
= 0;
13381 debug_method_add (w
, "optimization 3");
13390 /* Text changed drastically or point moved off of line. */
13391 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
13394 CHARPOS (this_line_start_pos
) = 0;
13395 consider_all_windows_p
|= buffer_shared
> 1;
13396 ++clear_face_cache_count
;
13397 #ifdef HAVE_WINDOW_SYSTEM
13398 ++clear_image_cache_count
;
13401 /* Build desired matrices, and update the display. If
13402 consider_all_windows_p is non-zero, do it for all windows on all
13403 frames. Otherwise do it for selected_window, only. */
13405 if (consider_all_windows_p
)
13407 Lisp_Object tail
, frame
;
13409 FOR_EACH_FRAME (tail
, frame
)
13410 XFRAME (frame
)->updated_p
= 0;
13412 /* Recompute # windows showing selected buffer. This will be
13413 incremented each time such a window is displayed. */
13416 FOR_EACH_FRAME (tail
, frame
)
13418 struct frame
*f
= XFRAME (frame
);
13420 /* We don't have to do anything for unselected terminal
13422 if ((FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
13423 && !EQ (FRAME_TTY (f
)->top_frame
, frame
))
13426 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
13428 if (! EQ (frame
, selected_frame
))
13429 /* Select the frame, for the sake of frame-local
13431 select_frame_for_redisplay (frame
);
13433 /* Mark all the scroll bars to be removed; we'll redeem
13434 the ones we want when we redisplay their windows. */
13435 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
13436 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
13438 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13439 redisplay_windows (FRAME_ROOT_WINDOW (f
));
13441 /* The X error handler may have deleted that frame. */
13442 if (!FRAME_LIVE_P (f
))
13445 /* Any scroll bars which redisplay_windows should have
13446 nuked should now go away. */
13447 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
13448 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
13450 /* If fonts changed, display again. */
13451 /* ??? rms: I suspect it is a mistake to jump all the way
13452 back to retry here. It should just retry this frame. */
13453 if (fonts_changed_p
)
13456 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13458 /* See if we have to hscroll. */
13459 if (!f
->already_hscrolled_p
)
13461 f
->already_hscrolled_p
= 1;
13462 if (hscroll_windows (f
->root_window
))
13466 /* Prevent various kinds of signals during display
13467 update. stdio is not robust about handling
13468 signals, which can cause an apparent I/O
13470 if (interrupt_input
)
13471 unrequest_sigio ();
13474 /* Update the display. */
13475 set_window_update_flags (XWINDOW (f
->root_window
), 1);
13476 pending
|= update_frame (f
, 0, 0);
13482 if (!EQ (old_frame
, selected_frame
)
13483 && FRAME_LIVE_P (XFRAME (old_frame
)))
13484 /* We played a bit fast-and-loose above and allowed selected_frame
13485 and selected_window to be temporarily out-of-sync but let's make
13486 sure this stays contained. */
13487 select_frame_for_redisplay (old_frame
);
13488 eassert (EQ (XFRAME (selected_frame
)->selected_window
,
13493 /* Do the mark_window_display_accurate after all windows have
13494 been redisplayed because this call resets flags in buffers
13495 which are needed for proper redisplay. */
13496 FOR_EACH_FRAME (tail
, frame
)
13498 struct frame
*f
= XFRAME (frame
);
13501 mark_window_display_accurate (f
->root_window
, 1);
13502 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
13503 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
13508 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13510 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13511 struct frame
*mini_frame
;
13513 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
13514 /* Use list_of_error, not Qerror, so that
13515 we catch only errors and don't run the debugger. */
13516 internal_condition_case_1 (redisplay_window_1
, selected_window
,
13518 redisplay_window_error
);
13519 if (update_miniwindow_p
)
13520 internal_condition_case_1 (redisplay_window_1
, mini_window
,
13522 redisplay_window_error
);
13524 /* Compare desired and current matrices, perform output. */
13527 /* If fonts changed, display again. */
13528 if (fonts_changed_p
)
13531 /* Prevent various kinds of signals during display update.
13532 stdio is not robust about handling signals,
13533 which can cause an apparent I/O error. */
13534 if (interrupt_input
)
13535 unrequest_sigio ();
13538 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13540 if (hscroll_windows (selected_window
))
13543 XWINDOW (selected_window
)->must_be_updated_p
= 1;
13544 pending
= update_frame (sf
, 0, 0);
13547 /* We may have called echo_area_display at the top of this
13548 function. If the echo area is on another frame, that may
13549 have put text on a frame other than the selected one, so the
13550 above call to update_frame would not have caught it. Catch
13552 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13553 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
13555 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
13557 XWINDOW (mini_window
)->must_be_updated_p
= 1;
13558 pending
|= update_frame (mini_frame
, 0, 0);
13559 if (!pending
&& hscroll_windows (mini_window
))
13564 /* If display was paused because of pending input, make sure we do a
13565 thorough update the next time. */
13568 /* Prevent the optimization at the beginning of
13569 redisplay_internal that tries a single-line update of the
13570 line containing the cursor in the selected window. */
13571 CHARPOS (this_line_start_pos
) = 0;
13573 /* Let the overlay arrow be updated the next time. */
13574 update_overlay_arrows (0);
13576 /* If we pause after scrolling, some rows in the current
13577 matrices of some windows are not valid. */
13578 if (!WINDOW_FULL_WIDTH_P (w
)
13579 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
13580 update_mode_lines
= 1;
13584 if (!consider_all_windows_p
)
13586 /* This has already been done above if
13587 consider_all_windows_p is set. */
13588 mark_window_display_accurate_1 (w
, 1);
13590 /* Say overlay arrows are up to date. */
13591 update_overlay_arrows (1);
13593 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
13594 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
13597 update_mode_lines
= 0;
13598 windows_or_buffers_changed
= 0;
13599 cursor_type_changed
= 0;
13602 /* Start SIGIO interrupts coming again. Having them off during the
13603 code above makes it less likely one will discard output, but not
13604 impossible, since there might be stuff in the system buffer here.
13605 But it is much hairier to try to do anything about that. */
13606 if (interrupt_input
)
13610 /* If a frame has become visible which was not before, redisplay
13611 again, so that we display it. Expose events for such a frame
13612 (which it gets when becoming visible) don't call the parts of
13613 redisplay constructing glyphs, so simply exposing a frame won't
13614 display anything in this case. So, we have to display these
13615 frames here explicitly. */
13618 Lisp_Object tail
, frame
;
13621 FOR_EACH_FRAME (tail
, frame
)
13623 int this_is_visible
= 0;
13625 if (XFRAME (frame
)->visible
)
13626 this_is_visible
= 1;
13627 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
13628 if (XFRAME (frame
)->visible
)
13629 this_is_visible
= 1;
13631 if (this_is_visible
)
13635 if (new_count
!= number_of_visible_frames
)
13636 windows_or_buffers_changed
++;
13639 /* Change frame size now if a change is pending. */
13640 do_pending_window_change (1);
13642 /* If we just did a pending size change, or have additional
13643 visible frames, or selected_window changed, redisplay again. */
13644 if ((windows_or_buffers_changed
&& !pending
)
13645 || (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
))
13648 /* Clear the face and image caches.
13650 We used to do this only if consider_all_windows_p. But the cache
13651 needs to be cleared if a timer creates images in the current
13652 buffer (e.g. the test case in Bug#6230). */
13654 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
13656 clear_face_cache (0);
13657 clear_face_cache_count
= 0;
13660 #ifdef HAVE_WINDOW_SYSTEM
13661 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
13663 clear_image_caches (Qnil
);
13664 clear_image_cache_count
= 0;
13666 #endif /* HAVE_WINDOW_SYSTEM */
13669 unbind_to (count
, Qnil
);
13674 /* Redisplay, but leave alone any recent echo area message unless
13675 another message has been requested in its place.
13677 This is useful in situations where you need to redisplay but no
13678 user action has occurred, making it inappropriate for the message
13679 area to be cleared. See tracking_off and
13680 wait_reading_process_output for examples of these situations.
13682 FROM_WHERE is an integer saying from where this function was
13683 called. This is useful for debugging. */
13686 redisplay_preserve_echo_area (int from_where
)
13688 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
13690 if (!NILP (echo_area_buffer
[1]))
13692 /* We have a previously displayed message, but no current
13693 message. Redisplay the previous message. */
13694 display_last_displayed_message_p
= 1;
13695 redisplay_internal ();
13696 display_last_displayed_message_p
= 0;
13699 redisplay_internal ();
13701 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
13702 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
13703 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
13707 /* Function registered with record_unwind_protect in redisplay_internal.
13708 Clear redisplaying_p. Also, select the previously
13709 selected frame, unless it has been deleted (by an X connection
13710 failure during redisplay, for example). */
13713 unwind_redisplay (Lisp_Object old_frame
)
13715 redisplaying_p
= 0;
13716 if (! EQ (old_frame
, selected_frame
)
13717 && FRAME_LIVE_P (XFRAME (old_frame
)))
13718 select_frame_for_redisplay (old_frame
);
13723 /* Mark the display of window W as accurate or inaccurate. If
13724 ACCURATE_P is non-zero mark display of W as accurate. If
13725 ACCURATE_P is zero, arrange for W to be redisplayed the next time
13726 redisplay_internal is called. */
13729 mark_window_display_accurate_1 (struct window
*w
, int accurate_p
)
13731 if (BUFFERP (w
->buffer
))
13733 struct buffer
*b
= XBUFFER (w
->buffer
);
13735 w
->last_modified
= accurate_p
? BUF_MODIFF(b
) : 0;
13736 w
->last_overlay_modified
= accurate_p
? BUF_OVERLAY_MODIFF(b
) : 0;
13738 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
);
13742 b
->clip_changed
= 0;
13743 b
->prevent_redisplay_optimizations_p
= 0;
13745 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
13746 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
13747 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
13748 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
13750 w
->current_matrix
->buffer
= b
;
13751 w
->current_matrix
->begv
= BUF_BEGV (b
);
13752 w
->current_matrix
->zv
= BUF_ZV (b
);
13754 w
->last_cursor
= w
->cursor
;
13755 w
->last_cursor_off_p
= w
->cursor_off_p
;
13757 if (w
== XWINDOW (selected_window
))
13758 w
->last_point
= BUF_PT (b
);
13760 w
->last_point
= XMARKER (w
->pointm
)->charpos
;
13766 wset_window_end_valid (w
, w
->buffer
);
13767 w
->update_mode_line
= 0;
13772 /* Mark the display of windows in the window tree rooted at WINDOW as
13773 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
13774 windows as accurate. If ACCURATE_P is zero, arrange for windows to
13775 be redisplayed the next time redisplay_internal is called. */
13778 mark_window_display_accurate (Lisp_Object window
, int accurate_p
)
13782 for (; !NILP (window
); window
= w
->next
)
13784 w
= XWINDOW (window
);
13785 mark_window_display_accurate_1 (w
, accurate_p
);
13787 if (!NILP (w
->vchild
))
13788 mark_window_display_accurate (w
->vchild
, accurate_p
);
13789 if (!NILP (w
->hchild
))
13790 mark_window_display_accurate (w
->hchild
, accurate_p
);
13795 update_overlay_arrows (1);
13799 /* Force a thorough redisplay the next time by setting
13800 last_arrow_position and last_arrow_string to t, which is
13801 unequal to any useful value of Voverlay_arrow_... */
13802 update_overlay_arrows (-1);
13807 /* Return value in display table DP (Lisp_Char_Table *) for character
13808 C. Since a display table doesn't have any parent, we don't have to
13809 follow parent. Do not call this function directly but use the
13810 macro DISP_CHAR_VECTOR. */
13813 disp_char_vector (struct Lisp_Char_Table
*dp
, int c
)
13817 if (ASCII_CHAR_P (c
))
13820 if (SUB_CHAR_TABLE_P (val
))
13821 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
13827 XSETCHAR_TABLE (table
, dp
);
13828 val
= char_table_ref (table
, c
);
13837 /***********************************************************************
13839 ***********************************************************************/
13841 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
13844 redisplay_windows (Lisp_Object window
)
13846 while (!NILP (window
))
13848 struct window
*w
= XWINDOW (window
);
13850 if (!NILP (w
->hchild
))
13851 redisplay_windows (w
->hchild
);
13852 else if (!NILP (w
->vchild
))
13853 redisplay_windows (w
->vchild
);
13854 else if (!NILP (w
->buffer
))
13856 displayed_buffer
= XBUFFER (w
->buffer
);
13857 /* Use list_of_error, not Qerror, so that
13858 we catch only errors and don't run the debugger. */
13859 internal_condition_case_1 (redisplay_window_0
, window
,
13861 redisplay_window_error
);
13869 redisplay_window_error (Lisp_Object ignore
)
13871 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
13876 redisplay_window_0 (Lisp_Object window
)
13878 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
13879 redisplay_window (window
, 0);
13884 redisplay_window_1 (Lisp_Object window
)
13886 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
13887 redisplay_window (window
, 1);
13892 /* Set cursor position of W. PT is assumed to be displayed in ROW.
13893 DELTA and DELTA_BYTES are the numbers of characters and bytes by
13894 which positions recorded in ROW differ from current buffer
13897 Return 0 if cursor is not on this row, 1 otherwise. */
13900 set_cursor_from_row (struct window
*w
, struct glyph_row
*row
,
13901 struct glyph_matrix
*matrix
,
13902 ptrdiff_t delta
, ptrdiff_t delta_bytes
,
13905 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
13906 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
13907 struct glyph
*cursor
= NULL
;
13908 /* The last known character position in row. */
13909 ptrdiff_t last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13911 ptrdiff_t pt_old
= PT
- delta
;
13912 ptrdiff_t pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13913 ptrdiff_t pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
13914 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
13915 /* A glyph beyond the edge of TEXT_AREA which we should never
13917 struct glyph
*glyphs_end
= end
;
13918 /* Non-zero means we've found a match for cursor position, but that
13919 glyph has the avoid_cursor_p flag set. */
13920 int match_with_avoid_cursor
= 0;
13921 /* Non-zero means we've seen at least one glyph that came from a
13923 int string_seen
= 0;
13924 /* Largest and smallest buffer positions seen so far during scan of
13926 ptrdiff_t bpos_max
= pos_before
;
13927 ptrdiff_t bpos_min
= pos_after
;
13928 /* Last buffer position covered by an overlay string with an integer
13929 `cursor' property. */
13930 ptrdiff_t bpos_covered
= 0;
13931 /* Non-zero means the display string on which to display the cursor
13932 comes from a text property, not from an overlay. */
13933 int string_from_text_prop
= 0;
13935 /* Don't even try doing anything if called for a mode-line or
13936 header-line row, since the rest of the code isn't prepared to
13937 deal with such calamities. */
13938 eassert (!row
->mode_line_p
);
13939 if (row
->mode_line_p
)
13942 /* Skip over glyphs not having an object at the start and the end of
13943 the row. These are special glyphs like truncation marks on
13944 terminal frames. */
13945 if (row
->displays_text_p
)
13947 if (!row
->reversed_p
)
13950 && INTEGERP (glyph
->object
)
13951 && glyph
->charpos
< 0)
13953 x
+= glyph
->pixel_width
;
13957 && INTEGERP ((end
- 1)->object
)
13958 /* CHARPOS is zero for blanks and stretch glyphs
13959 inserted by extend_face_to_end_of_line. */
13960 && (end
- 1)->charpos
<= 0)
13962 glyph_before
= glyph
- 1;
13969 /* If the glyph row is reversed, we need to process it from back
13970 to front, so swap the edge pointers. */
13971 glyphs_end
= end
= glyph
- 1;
13972 glyph
+= row
->used
[TEXT_AREA
] - 1;
13974 while (glyph
> end
+ 1
13975 && INTEGERP (glyph
->object
)
13976 && glyph
->charpos
< 0)
13979 x
-= glyph
->pixel_width
;
13981 if (INTEGERP (glyph
->object
) && glyph
->charpos
< 0)
13983 /* By default, in reversed rows we put the cursor on the
13984 rightmost (first in the reading order) glyph. */
13985 for (g
= end
+ 1; g
< glyph
; g
++)
13986 x
+= g
->pixel_width
;
13988 && INTEGERP ((end
+ 1)->object
)
13989 && (end
+ 1)->charpos
<= 0)
13991 glyph_before
= glyph
+ 1;
13995 else if (row
->reversed_p
)
13997 /* In R2L rows that don't display text, put the cursor on the
13998 rightmost glyph. Case in point: an empty last line that is
13999 part of an R2L paragraph. */
14001 /* Avoid placing the cursor on the last glyph of the row, where
14002 on terminal frames we hold the vertical border between
14003 adjacent windows. */
14004 if (!FRAME_WINDOW_P (WINDOW_XFRAME (w
))
14005 && !WINDOW_RIGHTMOST_P (w
)
14006 && cursor
== row
->glyphs
[LAST_AREA
] - 1)
14008 x
= -1; /* will be computed below, at label compute_x */
14011 /* Step 1: Try to find the glyph whose character position
14012 corresponds to point. If that's not possible, find 2 glyphs
14013 whose character positions are the closest to point, one before
14014 point, the other after it. */
14015 if (!row
->reversed_p
)
14016 while (/* not marched to end of glyph row */
14018 /* glyph was not inserted by redisplay for internal purposes */
14019 && !INTEGERP (glyph
->object
))
14021 if (BUFFERP (glyph
->object
))
14023 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
14025 if (glyph
->charpos
> bpos_max
)
14026 bpos_max
= glyph
->charpos
;
14027 if (glyph
->charpos
< bpos_min
)
14028 bpos_min
= glyph
->charpos
;
14029 if (!glyph
->avoid_cursor_p
)
14031 /* If we hit point, we've found the glyph on which to
14032 display the cursor. */
14035 match_with_avoid_cursor
= 0;
14038 /* See if we've found a better approximation to
14039 POS_BEFORE or to POS_AFTER. */
14040 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
14042 pos_before
= glyph
->charpos
;
14043 glyph_before
= glyph
;
14045 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
14047 pos_after
= glyph
->charpos
;
14048 glyph_after
= glyph
;
14051 else if (dpos
== 0)
14052 match_with_avoid_cursor
= 1;
14054 else if (STRINGP (glyph
->object
))
14056 Lisp_Object chprop
;
14057 ptrdiff_t glyph_pos
= glyph
->charpos
;
14059 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
14061 if (!NILP (chprop
))
14063 /* If the string came from a `display' text property,
14064 look up the buffer position of that property and
14065 use that position to update bpos_max, as if we
14066 actually saw such a position in one of the row's
14067 glyphs. This helps with supporting integer values
14068 of `cursor' property on the display string in
14069 situations where most or all of the row's buffer
14070 text is completely covered by display properties,
14071 so that no glyph with valid buffer positions is
14072 ever seen in the row. */
14073 ptrdiff_t prop_pos
=
14074 string_buffer_position_lim (glyph
->object
, pos_before
,
14077 if (prop_pos
>= pos_before
)
14078 bpos_max
= prop_pos
- 1;
14080 if (INTEGERP (chprop
))
14082 bpos_covered
= bpos_max
+ XINT (chprop
);
14083 /* If the `cursor' property covers buffer positions up
14084 to and including point, we should display cursor on
14085 this glyph. Note that, if a `cursor' property on one
14086 of the string's characters has an integer value, we
14087 will break out of the loop below _before_ we get to
14088 the position match above. IOW, integer values of
14089 the `cursor' property override the "exact match for
14090 point" strategy of positioning the cursor. */
14091 /* Implementation note: bpos_max == pt_old when, e.g.,
14092 we are in an empty line, where bpos_max is set to
14093 MATRIX_ROW_START_CHARPOS, see above. */
14094 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14103 x
+= glyph
->pixel_width
;
14106 else if (glyph
> end
) /* row is reversed */
14107 while (!INTEGERP (glyph
->object
))
14109 if (BUFFERP (glyph
->object
))
14111 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
14113 if (glyph
->charpos
> bpos_max
)
14114 bpos_max
= glyph
->charpos
;
14115 if (glyph
->charpos
< bpos_min
)
14116 bpos_min
= glyph
->charpos
;
14117 if (!glyph
->avoid_cursor_p
)
14121 match_with_avoid_cursor
= 0;
14124 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
14126 pos_before
= glyph
->charpos
;
14127 glyph_before
= glyph
;
14129 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
14131 pos_after
= glyph
->charpos
;
14132 glyph_after
= glyph
;
14135 else if (dpos
== 0)
14136 match_with_avoid_cursor
= 1;
14138 else if (STRINGP (glyph
->object
))
14140 Lisp_Object chprop
;
14141 ptrdiff_t glyph_pos
= glyph
->charpos
;
14143 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
14145 if (!NILP (chprop
))
14147 ptrdiff_t prop_pos
=
14148 string_buffer_position_lim (glyph
->object
, pos_before
,
14151 if (prop_pos
>= pos_before
)
14152 bpos_max
= prop_pos
- 1;
14154 if (INTEGERP (chprop
))
14156 bpos_covered
= bpos_max
+ XINT (chprop
);
14157 /* If the `cursor' property covers buffer positions up
14158 to and including point, we should display cursor on
14160 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14169 if (glyph
== glyphs_end
) /* don't dereference outside TEXT_AREA */
14171 x
--; /* can't use any pixel_width */
14174 x
-= glyph
->pixel_width
;
14177 /* Step 2: If we didn't find an exact match for point, we need to
14178 look for a proper place to put the cursor among glyphs between
14179 GLYPH_BEFORE and GLYPH_AFTER. */
14180 if (!((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14181 && BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14182 && bpos_covered
< pt_old
)
14184 /* An empty line has a single glyph whose OBJECT is zero and
14185 whose CHARPOS is the position of a newline on that line.
14186 Note that on a TTY, there are more glyphs after that, which
14187 were produced by extend_face_to_end_of_line, but their
14188 CHARPOS is zero or negative. */
14190 (row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14191 && INTEGERP (glyph
->object
) && glyph
->charpos
> 0;
14193 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
14195 ptrdiff_t ellipsis_pos
;
14197 /* Scan back over the ellipsis glyphs. */
14198 if (!row
->reversed_p
)
14200 ellipsis_pos
= (glyph
- 1)->charpos
;
14201 while (glyph
> row
->glyphs
[TEXT_AREA
]
14202 && (glyph
- 1)->charpos
== ellipsis_pos
)
14203 glyph
--, x
-= glyph
->pixel_width
;
14204 /* That loop always goes one position too far, including
14205 the glyph before the ellipsis. So scan forward over
14207 x
+= glyph
->pixel_width
;
14210 else /* row is reversed */
14212 ellipsis_pos
= (glyph
+ 1)->charpos
;
14213 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14214 && (glyph
+ 1)->charpos
== ellipsis_pos
)
14215 glyph
++, x
+= glyph
->pixel_width
;
14216 x
-= glyph
->pixel_width
;
14220 else if (match_with_avoid_cursor
)
14222 cursor
= glyph_after
;
14225 else if (string_seen
)
14227 int incr
= row
->reversed_p
? -1 : +1;
14229 /* Need to find the glyph that came out of a string which is
14230 present at point. That glyph is somewhere between
14231 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
14232 positioned between POS_BEFORE and POS_AFTER in the
14234 struct glyph
*start
, *stop
;
14235 ptrdiff_t pos
= pos_before
;
14239 /* If the row ends in a newline from a display string,
14240 reordering could have moved the glyphs belonging to the
14241 string out of the [GLYPH_BEFORE..GLYPH_AFTER] range. So
14242 in this case we extend the search to the last glyph in
14243 the row that was not inserted by redisplay. */
14244 if (row
->ends_in_newline_from_string_p
)
14247 pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
14250 /* GLYPH_BEFORE and GLYPH_AFTER are the glyphs that
14251 correspond to POS_BEFORE and POS_AFTER, respectively. We
14252 need START and STOP in the order that corresponds to the
14253 row's direction as given by its reversed_p flag. If the
14254 directionality of characters between POS_BEFORE and
14255 POS_AFTER is the opposite of the row's base direction,
14256 these characters will have been reordered for display,
14257 and we need to reverse START and STOP. */
14258 if (!row
->reversed_p
)
14260 start
= min (glyph_before
, glyph_after
);
14261 stop
= max (glyph_before
, glyph_after
);
14265 start
= max (glyph_before
, glyph_after
);
14266 stop
= min (glyph_before
, glyph_after
);
14268 for (glyph
= start
+ incr
;
14269 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
14272 /* Any glyphs that come from the buffer are here because
14273 of bidi reordering. Skip them, and only pay
14274 attention to glyphs that came from some string. */
14275 if (STRINGP (glyph
->object
))
14279 /* If the display property covers the newline, we
14280 need to search for it one position farther. */
14281 ptrdiff_t lim
= pos_after
14282 + (pos_after
== MATRIX_ROW_END_CHARPOS (row
) + delta
);
14284 string_from_text_prop
= 0;
14285 str
= glyph
->object
;
14286 tem
= string_buffer_position_lim (str
, pos
, lim
, 0);
14287 if (tem
== 0 /* from overlay */
14290 /* If the string from which this glyph came is
14291 found in the buffer at point, or at position
14292 that is closer to point than pos_after, then
14293 we've found the glyph we've been looking for.
14294 If it comes from an overlay (tem == 0), and
14295 it has the `cursor' property on one of its
14296 glyphs, record that glyph as a candidate for
14297 displaying the cursor. (As in the
14298 unidirectional version, we will display the
14299 cursor on the last candidate we find.) */
14302 || (tem
- pt_old
> 0 && tem
< pos_after
))
14304 /* The glyphs from this string could have
14305 been reordered. Find the one with the
14306 smallest string position. Or there could
14307 be a character in the string with the
14308 `cursor' property, which means display
14309 cursor on that character's glyph. */
14310 ptrdiff_t strpos
= glyph
->charpos
;
14315 string_from_text_prop
= 1;
14318 (row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14319 && EQ (glyph
->object
, str
);
14323 ptrdiff_t gpos
= glyph
->charpos
;
14325 cprop
= Fget_char_property (make_number (gpos
),
14333 if (tem
&& glyph
->charpos
< strpos
)
14335 strpos
= glyph
->charpos
;
14341 || (tem
- pt_old
> 0 && tem
< pos_after
))
14345 pos
= tem
+ 1; /* don't find previous instances */
14347 /* This string is not what we want; skip all of the
14348 glyphs that came from it. */
14349 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14350 && EQ (glyph
->object
, str
))
14357 /* If we reached the end of the line, and END was from a string,
14358 the cursor is not on this line. */
14360 && (row
->reversed_p
? glyph
<= end
: glyph
>= end
)
14361 && (row
->reversed_p
? end
> glyphs_end
: end
< glyphs_end
)
14362 && STRINGP (end
->object
)
14363 && row
->continued_p
)
14366 /* A truncated row may not include PT among its character positions.
14367 Setting the cursor inside the scroll margin will trigger
14368 recalculation of hscroll in hscroll_window_tree. But if a
14369 display string covers point, defer to the string-handling
14370 code below to figure this out. */
14371 else if (row
->truncated_on_left_p
&& pt_old
< bpos_min
)
14373 cursor
= glyph_before
;
14376 else if ((row
->truncated_on_right_p
&& pt_old
> bpos_max
)
14377 /* Zero-width characters produce no glyphs. */
14379 && (row
->reversed_p
14380 ? glyph_after
> glyphs_end
14381 : glyph_after
< glyphs_end
)))
14383 cursor
= glyph_after
;
14389 if (cursor
!= NULL
)
14391 else if (glyph
== glyphs_end
14392 && pos_before
== pos_after
14393 && STRINGP ((row
->reversed_p
14394 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14395 : row
->glyphs
[TEXT_AREA
])->object
))
14397 /* If all the glyphs of this row came from strings, put the
14398 cursor on the first glyph of the row. This avoids having the
14399 cursor outside of the text area in this very rare and hard
14403 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14404 : row
->glyphs
[TEXT_AREA
];
14410 /* Need to compute x that corresponds to GLYPH. */
14411 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
14413 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
14415 x
+= g
->pixel_width
;
14419 /* ROW could be part of a continued line, which, under bidi
14420 reordering, might have other rows whose start and end charpos
14421 occlude point. Only set w->cursor if we found a better
14422 approximation to the cursor position than we have from previously
14423 examined candidate rows belonging to the same continued line. */
14424 if (/* we already have a candidate row */
14425 w
->cursor
.vpos
>= 0
14426 /* that candidate is not the row we are processing */
14427 && MATRIX_ROW (matrix
, w
->cursor
.vpos
) != row
14428 /* Make sure cursor.vpos specifies a row whose start and end
14429 charpos occlude point, and it is valid candidate for being a
14430 cursor-row. This is because some callers of this function
14431 leave cursor.vpos at the row where the cursor was displayed
14432 during the last redisplay cycle. */
14433 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)) <= pt_old
14434 && pt_old
<= MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14435 && cursor_row_p (MATRIX_ROW (matrix
, w
->cursor
.vpos
)))
14438 MATRIX_ROW_GLYPH_START (matrix
, w
->cursor
.vpos
) + w
->cursor
.hpos
;
14440 /* Don't consider glyphs that are outside TEXT_AREA. */
14441 if (!(row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
))
14443 /* Keep the candidate whose buffer position is the closest to
14444 point or has the `cursor' property. */
14445 if (/* previous candidate is a glyph in TEXT_AREA of that row */
14446 w
->cursor
.hpos
>= 0
14447 && w
->cursor
.hpos
< MATRIX_ROW_USED (matrix
, w
->cursor
.vpos
)
14448 && ((BUFFERP (g1
->object
)
14449 && (g1
->charpos
== pt_old
/* an exact match always wins */
14450 || (BUFFERP (glyph
->object
)
14451 && eabs (g1
->charpos
- pt_old
)
14452 < eabs (glyph
->charpos
- pt_old
))))
14453 /* previous candidate is a glyph from a string that has
14454 a non-nil `cursor' property */
14455 || (STRINGP (g1
->object
)
14456 && (!NILP (Fget_char_property (make_number (g1
->charpos
),
14457 Qcursor
, g1
->object
))
14458 /* previous candidate is from the same display
14459 string as this one, and the display string
14460 came from a text property */
14461 || (EQ (g1
->object
, glyph
->object
)
14462 && string_from_text_prop
)
14463 /* this candidate is from newline and its
14464 position is not an exact match */
14465 || (INTEGERP (glyph
->object
)
14466 && glyph
->charpos
!= pt_old
)))))
14468 /* If this candidate gives an exact match, use that. */
14469 if (!((BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14470 /* If this candidate is a glyph created for the
14471 terminating newline of a line, and point is on that
14472 newline, it wins because it's an exact match. */
14473 || (!row
->continued_p
14474 && INTEGERP (glyph
->object
)
14475 && glyph
->charpos
== 0
14476 && pt_old
== MATRIX_ROW_END_CHARPOS (row
) - 1))
14477 /* Otherwise, keep the candidate that comes from a row
14478 spanning less buffer positions. This may win when one or
14479 both candidate positions are on glyphs that came from
14480 display strings, for which we cannot compare buffer
14482 && MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14483 - MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14484 < MATRIX_ROW_END_CHARPOS (row
) - MATRIX_ROW_START_CHARPOS (row
))
14487 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
14489 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
14490 w
->cursor
.y
= row
->y
+ dy
;
14492 if (w
== XWINDOW (selected_window
))
14494 if (!row
->continued_p
14495 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
14498 this_line_buffer
= XBUFFER (w
->buffer
);
14500 CHARPOS (this_line_start_pos
)
14501 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
14502 BYTEPOS (this_line_start_pos
)
14503 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
14505 CHARPOS (this_line_end_pos
)
14506 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
14507 BYTEPOS (this_line_end_pos
)
14508 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
14510 this_line_y
= w
->cursor
.y
;
14511 this_line_pixel_height
= row
->height
;
14512 this_line_vpos
= w
->cursor
.vpos
;
14513 this_line_start_x
= row
->x
;
14516 CHARPOS (this_line_start_pos
) = 0;
14523 /* Run window scroll functions, if any, for WINDOW with new window
14524 start STARTP. Sets the window start of WINDOW to that position.
14526 We assume that the window's buffer is really current. */
14528 static inline struct text_pos
14529 run_window_scroll_functions (Lisp_Object window
, struct text_pos startp
)
14531 struct window
*w
= XWINDOW (window
);
14532 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
14534 if (current_buffer
!= XBUFFER (w
->buffer
))
14537 if (!NILP (Vwindow_scroll_functions
))
14539 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
14540 make_number (CHARPOS (startp
)));
14541 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14542 /* In case the hook functions switch buffers. */
14543 set_buffer_internal (XBUFFER (w
->buffer
));
14550 /* Make sure the line containing the cursor is fully visible.
14551 A value of 1 means there is nothing to be done.
14552 (Either the line is fully visible, or it cannot be made so,
14553 or we cannot tell.)
14555 If FORCE_P is non-zero, return 0 even if partial visible cursor row
14556 is higher than window.
14558 A value of 0 means the caller should do scrolling
14559 as if point had gone off the screen. */
14562 cursor_row_fully_visible_p (struct window
*w
, int force_p
, int current_matrix_p
)
14564 struct glyph_matrix
*matrix
;
14565 struct glyph_row
*row
;
14568 if (!make_cursor_line_fully_visible_p
)
14571 /* It's not always possible to find the cursor, e.g, when a window
14572 is full of overlay strings. Don't do anything in that case. */
14573 if (w
->cursor
.vpos
< 0)
14576 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
14577 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
14579 /* If the cursor row is not partially visible, there's nothing to do. */
14580 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
14583 /* If the row the cursor is in is taller than the window's height,
14584 it's not clear what to do, so do nothing. */
14585 window_height
= window_box_height (w
);
14586 if (row
->height
>= window_height
)
14588 if (!force_p
|| MINI_WINDOW_P (w
)
14589 || w
->vscroll
|| w
->cursor
.vpos
== 0)
14596 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
14597 non-zero means only WINDOW is redisplayed in redisplay_internal.
14598 TEMP_SCROLL_STEP has the same meaning as emacs_scroll_step, and is used
14599 in redisplay_window to bring a partially visible line into view in
14600 the case that only the cursor has moved.
14602 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
14603 last screen line's vertical height extends past the end of the screen.
14607 1 if scrolling succeeded
14609 0 if scrolling didn't find point.
14611 -1 if new fonts have been loaded so that we must interrupt
14612 redisplay, adjust glyph matrices, and try again. */
14618 SCROLLING_NEED_LARGER_MATRICES
14621 /* If scroll-conservatively is more than this, never recenter.
14623 If you change this, don't forget to update the doc string of
14624 `scroll-conservatively' and the Emacs manual. */
14625 #define SCROLL_LIMIT 100
14628 try_scrolling (Lisp_Object window
, int just_this_one_p
,
14629 ptrdiff_t arg_scroll_conservatively
, ptrdiff_t scroll_step
,
14630 int temp_scroll_step
, int last_line_misfit
)
14632 struct window
*w
= XWINDOW (window
);
14633 struct frame
*f
= XFRAME (w
->frame
);
14634 struct text_pos pos
, startp
;
14636 int this_scroll_margin
, scroll_max
, rc
, height
;
14637 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
14638 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
14639 Lisp_Object aggressive
;
14640 /* We will never try scrolling more than this number of lines. */
14641 int scroll_limit
= SCROLL_LIMIT
;
14644 debug_method_add (w
, "try_scrolling");
14647 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14649 /* Compute scroll margin height in pixels. We scroll when point is
14650 within this distance from the top or bottom of the window. */
14651 if (scroll_margin
> 0)
14652 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
14653 * FRAME_LINE_HEIGHT (f
);
14655 this_scroll_margin
= 0;
14657 /* Force arg_scroll_conservatively to have a reasonable value, to
14658 avoid scrolling too far away with slow move_it_* functions. Note
14659 that the user can supply scroll-conservatively equal to
14660 `most-positive-fixnum', which can be larger than INT_MAX. */
14661 if (arg_scroll_conservatively
> scroll_limit
)
14663 arg_scroll_conservatively
= scroll_limit
+ 1;
14664 scroll_max
= scroll_limit
* FRAME_LINE_HEIGHT (f
);
14666 else if (scroll_step
|| arg_scroll_conservatively
|| temp_scroll_step
)
14667 /* Compute how much we should try to scroll maximally to bring
14668 point into view. */
14669 scroll_max
= (max (scroll_step
,
14670 max (arg_scroll_conservatively
, temp_scroll_step
))
14671 * FRAME_LINE_HEIGHT (f
));
14672 else if (NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
))
14673 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
)))
14674 /* We're trying to scroll because of aggressive scrolling but no
14675 scroll_step is set. Choose an arbitrary one. */
14676 scroll_max
= 10 * FRAME_LINE_HEIGHT (f
);
14682 /* Decide whether to scroll down. */
14683 if (PT
> CHARPOS (startp
))
14685 int scroll_margin_y
;
14687 /* Compute the pixel ypos of the scroll margin, then move IT to
14688 either that ypos or PT, whichever comes first. */
14689 start_display (&it
, w
, startp
);
14690 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
14691 - FRAME_LINE_HEIGHT (f
) * extra_scroll_margin_lines
;
14692 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
14693 (MOVE_TO_POS
| MOVE_TO_Y
));
14695 if (PT
> CHARPOS (it
.current
.pos
))
14697 int y0
= line_bottom_y (&it
);
14698 /* Compute how many pixels below window bottom to stop searching
14699 for PT. This avoids costly search for PT that is far away if
14700 the user limited scrolling by a small number of lines, but
14701 always finds PT if scroll_conservatively is set to a large
14702 number, such as most-positive-fixnum. */
14703 int slack
= max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
));
14704 int y_to_move
= it
.last_visible_y
+ slack
;
14706 /* Compute the distance from the scroll margin to PT or to
14707 the scroll limit, whichever comes first. This should
14708 include the height of the cursor line, to make that line
14710 move_it_to (&it
, PT
, -1, y_to_move
,
14711 -1, MOVE_TO_POS
| MOVE_TO_Y
);
14712 dy
= line_bottom_y (&it
) - y0
;
14714 if (dy
> scroll_max
)
14715 return SCROLLING_FAILED
;
14724 /* Point is in or below the bottom scroll margin, so move the
14725 window start down. If scrolling conservatively, move it just
14726 enough down to make point visible. If scroll_step is set,
14727 move it down by scroll_step. */
14728 if (arg_scroll_conservatively
)
14730 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
14731 FRAME_LINE_HEIGHT (f
) * arg_scroll_conservatively
);
14732 else if (scroll_step
|| temp_scroll_step
)
14733 amount_to_scroll
= scroll_max
;
14736 aggressive
= BVAR (current_buffer
, scroll_up_aggressively
);
14737 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14738 if (NUMBERP (aggressive
))
14740 double float_amount
= XFLOATINT (aggressive
) * height
;
14741 amount_to_scroll
= float_amount
;
14742 if (amount_to_scroll
== 0 && float_amount
> 0)
14743 amount_to_scroll
= 1;
14744 /* Don't let point enter the scroll margin near top of
14746 if (amount_to_scroll
> height
- 2*this_scroll_margin
+ dy
)
14747 amount_to_scroll
= height
- 2*this_scroll_margin
+ dy
;
14751 if (amount_to_scroll
<= 0)
14752 return SCROLLING_FAILED
;
14754 start_display (&it
, w
, startp
);
14755 if (arg_scroll_conservatively
<= scroll_limit
)
14756 move_it_vertically (&it
, amount_to_scroll
);
14759 /* Extra precision for users who set scroll-conservatively
14760 to a large number: make sure the amount we scroll
14761 the window start is never less than amount_to_scroll,
14762 which was computed as distance from window bottom to
14763 point. This matters when lines at window top and lines
14764 below window bottom have different height. */
14766 void *it1data
= NULL
;
14767 /* We use a temporary it1 because line_bottom_y can modify
14768 its argument, if it moves one line down; see there. */
14771 SAVE_IT (it1
, it
, it1data
);
14772 start_y
= line_bottom_y (&it1
);
14774 RESTORE_IT (&it
, &it
, it1data
);
14775 move_it_by_lines (&it
, 1);
14776 SAVE_IT (it1
, it
, it1data
);
14777 } while (line_bottom_y (&it1
) - start_y
< amount_to_scroll
);
14780 /* If STARTP is unchanged, move it down another screen line. */
14781 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
14782 move_it_by_lines (&it
, 1);
14783 startp
= it
.current
.pos
;
14787 struct text_pos scroll_margin_pos
= startp
;
14789 /* See if point is inside the scroll margin at the top of the
14791 if (this_scroll_margin
)
14793 start_display (&it
, w
, startp
);
14794 move_it_vertically (&it
, this_scroll_margin
);
14795 scroll_margin_pos
= it
.current
.pos
;
14798 if (PT
< CHARPOS (scroll_margin_pos
))
14800 /* Point is in the scroll margin at the top of the window or
14801 above what is displayed in the window. */
14804 /* Compute the vertical distance from PT to the scroll
14805 margin position. Move as far as scroll_max allows, or
14806 one screenful, or 10 screen lines, whichever is largest.
14807 Give up if distance is greater than scroll_max. */
14808 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
14809 start_display (&it
, w
, pos
);
14811 y_to_move
= max (it
.last_visible_y
,
14812 max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
)));
14813 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
14815 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
14816 dy
= it
.current_y
- y0
;
14817 if (dy
> scroll_max
)
14818 return SCROLLING_FAILED
;
14820 /* Compute new window start. */
14821 start_display (&it
, w
, startp
);
14823 if (arg_scroll_conservatively
)
14824 amount_to_scroll
= max (dy
, FRAME_LINE_HEIGHT (f
) *
14825 max (scroll_step
, temp_scroll_step
));
14826 else if (scroll_step
|| temp_scroll_step
)
14827 amount_to_scroll
= scroll_max
;
14830 aggressive
= BVAR (current_buffer
, scroll_down_aggressively
);
14831 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14832 if (NUMBERP (aggressive
))
14834 double float_amount
= XFLOATINT (aggressive
) * height
;
14835 amount_to_scroll
= float_amount
;
14836 if (amount_to_scroll
== 0 && float_amount
> 0)
14837 amount_to_scroll
= 1;
14838 amount_to_scroll
-=
14839 this_scroll_margin
- dy
- FRAME_LINE_HEIGHT (f
);
14840 /* Don't let point enter the scroll margin near
14841 bottom of the window. */
14842 if (amount_to_scroll
> height
- 2*this_scroll_margin
+ dy
)
14843 amount_to_scroll
= height
- 2*this_scroll_margin
+ dy
;
14847 if (amount_to_scroll
<= 0)
14848 return SCROLLING_FAILED
;
14850 move_it_vertically_backward (&it
, amount_to_scroll
);
14851 startp
= it
.current
.pos
;
14855 /* Run window scroll functions. */
14856 startp
= run_window_scroll_functions (window
, startp
);
14858 /* Display the window. Give up if new fonts are loaded, or if point
14860 if (!try_window (window
, startp
, 0))
14861 rc
= SCROLLING_NEED_LARGER_MATRICES
;
14862 else if (w
->cursor
.vpos
< 0)
14864 clear_glyph_matrix (w
->desired_matrix
);
14865 rc
= SCROLLING_FAILED
;
14869 /* Maybe forget recorded base line for line number display. */
14870 if (!just_this_one_p
14871 || current_buffer
->clip_changed
14872 || BEG_UNCHANGED
< CHARPOS (startp
))
14873 wset_base_line_number (w
, Qnil
);
14875 /* If cursor ends up on a partially visible line,
14876 treat that as being off the bottom of the screen. */
14877 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0)
14878 /* It's possible that the cursor is on the first line of the
14879 buffer, which is partially obscured due to a vscroll
14880 (Bug#7537). In that case, avoid looping forever . */
14881 && extra_scroll_margin_lines
< w
->desired_matrix
->nrows
- 1)
14883 clear_glyph_matrix (w
->desired_matrix
);
14884 ++extra_scroll_margin_lines
;
14887 rc
= SCROLLING_SUCCESS
;
14894 /* Compute a suitable window start for window W if display of W starts
14895 on a continuation line. Value is non-zero if a new window start
14898 The new window start will be computed, based on W's width, starting
14899 from the start of the continued line. It is the start of the
14900 screen line with the minimum distance from the old start W->start. */
14903 compute_window_start_on_continuation_line (struct window
*w
)
14905 struct text_pos pos
, start_pos
;
14906 int window_start_changed_p
= 0;
14908 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
14910 /* If window start is on a continuation line... Window start may be
14911 < BEGV in case there's invisible text at the start of the
14912 buffer (M-x rmail, for example). */
14913 if (CHARPOS (start_pos
) > BEGV
14914 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
14917 struct glyph_row
*row
;
14919 /* Handle the case that the window start is out of range. */
14920 if (CHARPOS (start_pos
) < BEGV
)
14921 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
14922 else if (CHARPOS (start_pos
) > ZV
)
14923 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
14925 /* Find the start of the continued line. This should be fast
14926 because scan_buffer is fast (newline cache). */
14927 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
14928 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
14929 row
, DEFAULT_FACE_ID
);
14930 reseat_at_previous_visible_line_start (&it
);
14932 /* If the line start is "too far" away from the window start,
14933 say it takes too much time to compute a new window start. */
14934 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
14935 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
14937 int min_distance
, distance
;
14939 /* Move forward by display lines to find the new window
14940 start. If window width was enlarged, the new start can
14941 be expected to be > the old start. If window width was
14942 decreased, the new window start will be < the old start.
14943 So, we're looking for the display line start with the
14944 minimum distance from the old window start. */
14945 pos
= it
.current
.pos
;
14946 min_distance
= INFINITY
;
14947 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
14948 distance
< min_distance
)
14950 min_distance
= distance
;
14951 pos
= it
.current
.pos
;
14952 move_it_by_lines (&it
, 1);
14955 /* Set the window start there. */
14956 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
14957 window_start_changed_p
= 1;
14961 return window_start_changed_p
;
14965 /* Try cursor movement in case text has not changed in window WINDOW,
14966 with window start STARTP. Value is
14968 CURSOR_MOVEMENT_SUCCESS if successful
14970 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
14972 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
14973 display. *SCROLL_STEP is set to 1, under certain circumstances, if
14974 we want to scroll as if scroll-step were set to 1. See the code.
14976 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
14977 which case we have to abort this redisplay, and adjust matrices
14982 CURSOR_MOVEMENT_SUCCESS
,
14983 CURSOR_MOVEMENT_CANNOT_BE_USED
,
14984 CURSOR_MOVEMENT_MUST_SCROLL
,
14985 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
14989 try_cursor_movement (Lisp_Object window
, struct text_pos startp
, int *scroll_step
)
14991 struct window
*w
= XWINDOW (window
);
14992 struct frame
*f
= XFRAME (w
->frame
);
14993 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
14996 if (inhibit_try_cursor_movement
)
15000 /* Previously, there was a check for Lisp integer in the
15001 if-statement below. Now, this field is converted to
15002 ptrdiff_t, thus zero means invalid position in a buffer. */
15003 eassert (w
->last_point
> 0);
15005 /* Handle case where text has not changed, only point, and it has
15006 not moved off the frame. */
15007 if (/* Point may be in this window. */
15008 PT
>= CHARPOS (startp
)
15009 /* Selective display hasn't changed. */
15010 && !current_buffer
->clip_changed
15011 /* Function force-mode-line-update is used to force a thorough
15012 redisplay. It sets either windows_or_buffers_changed or
15013 update_mode_lines. So don't take a shortcut here for these
15015 && !update_mode_lines
15016 && !windows_or_buffers_changed
15017 && !cursor_type_changed
15018 /* Can't use this case if highlighting a region. When a
15019 region exists, cursor movement has to do more than just
15021 && !(!NILP (Vtransient_mark_mode
)
15022 && !NILP (BVAR (current_buffer
, mark_active
)))
15023 && NILP (w
->region_showing
)
15024 && NILP (Vshow_trailing_whitespace
)
15025 /* This code is not used for mini-buffer for the sake of the case
15026 of redisplaying to replace an echo area message; since in
15027 that case the mini-buffer contents per se are usually
15028 unchanged. This code is of no real use in the mini-buffer
15029 since the handling of this_line_start_pos, etc., in redisplay
15030 handles the same cases. */
15031 && !EQ (window
, minibuf_window
)
15032 /* When splitting windows or for new windows, it happens that
15033 redisplay is called with a nil window_end_vpos or one being
15034 larger than the window. This should really be fixed in
15035 window.c. I don't have this on my list, now, so we do
15036 approximately the same as the old redisplay code. --gerd. */
15037 && INTEGERP (w
->window_end_vpos
)
15038 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
15039 && (FRAME_WINDOW_P (f
)
15040 || !overlay_arrow_in_current_buffer_p ()))
15042 int this_scroll_margin
, top_scroll_margin
;
15043 struct glyph_row
*row
= NULL
;
15046 debug_method_add (w
, "cursor movement");
15049 /* Scroll if point within this distance from the top or bottom
15050 of the window. This is a pixel value. */
15051 if (scroll_margin
> 0)
15053 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
15054 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
15057 this_scroll_margin
= 0;
15059 top_scroll_margin
= this_scroll_margin
;
15060 if (WINDOW_WANTS_HEADER_LINE_P (w
))
15061 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
15063 /* Start with the row the cursor was displayed during the last
15064 not paused redisplay. Give up if that row is not valid. */
15065 if (w
->last_cursor
.vpos
< 0
15066 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
15067 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15070 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
15071 if (row
->mode_line_p
)
15073 if (!row
->enabled_p
)
15074 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15077 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
15079 int scroll_p
= 0, must_scroll
= 0;
15080 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
15082 if (PT
> w
->last_point
)
15084 /* Point has moved forward. */
15085 while (MATRIX_ROW_END_CHARPOS (row
) < PT
15086 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
15088 eassert (row
->enabled_p
);
15092 /* If the end position of a row equals the start
15093 position of the next row, and PT is at that position,
15094 we would rather display cursor in the next line. */
15095 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15096 && MATRIX_ROW_END_CHARPOS (row
) == PT
15097 && row
< w
->current_matrix
->rows
15098 + w
->current_matrix
->nrows
- 1
15099 && MATRIX_ROW_START_CHARPOS (row
+1) == PT
15100 && !cursor_row_p (row
))
15103 /* If within the scroll margin, scroll. Note that
15104 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
15105 the next line would be drawn, and that
15106 this_scroll_margin can be zero. */
15107 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
15108 || PT
> MATRIX_ROW_END_CHARPOS (row
)
15109 /* Line is completely visible last line in window
15110 and PT is to be set in the next line. */
15111 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
15112 && PT
== MATRIX_ROW_END_CHARPOS (row
)
15113 && !row
->ends_at_zv_p
15114 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
15117 else if (PT
< w
->last_point
)
15119 /* Cursor has to be moved backward. Note that PT >=
15120 CHARPOS (startp) because of the outer if-statement. */
15121 while (!row
->mode_line_p
15122 && (MATRIX_ROW_START_CHARPOS (row
) > PT
15123 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15124 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
15125 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
15126 row
> w
->current_matrix
->rows
15127 && (row
-1)->ends_in_newline_from_string_p
))))
15128 && (row
->y
> top_scroll_margin
15129 || CHARPOS (startp
) == BEGV
))
15131 eassert (row
->enabled_p
);
15135 /* Consider the following case: Window starts at BEGV,
15136 there is invisible, intangible text at BEGV, so that
15137 display starts at some point START > BEGV. It can
15138 happen that we are called with PT somewhere between
15139 BEGV and START. Try to handle that case. */
15140 if (row
< w
->current_matrix
->rows
15141 || row
->mode_line_p
)
15143 row
= w
->current_matrix
->rows
;
15144 if (row
->mode_line_p
)
15148 /* Due to newlines in overlay strings, we may have to
15149 skip forward over overlay strings. */
15150 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15151 && MATRIX_ROW_END_CHARPOS (row
) == PT
15152 && !cursor_row_p (row
))
15155 /* If within the scroll margin, scroll. */
15156 if (row
->y
< top_scroll_margin
15157 && CHARPOS (startp
) != BEGV
)
15162 /* Cursor did not move. So don't scroll even if cursor line
15163 is partially visible, as it was so before. */
15164 rc
= CURSOR_MOVEMENT_SUCCESS
;
15167 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
15168 || PT
> MATRIX_ROW_END_CHARPOS (row
))
15170 /* if PT is not in the glyph row, give up. */
15171 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15174 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15175 && !NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
15177 struct glyph_row
*row1
;
15179 /* If rows are bidi-reordered and point moved, back up
15180 until we find a row that does not belong to a
15181 continuation line. This is because we must consider
15182 all rows of a continued line as candidates for the
15183 new cursor positioning, since row start and end
15184 positions change non-linearly with vertical position
15186 /* FIXME: Revisit this when glyph ``spilling'' in
15187 continuation lines' rows is implemented for
15188 bidi-reordered rows. */
15189 for (row1
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15190 MATRIX_ROW_CONTINUATION_LINE_P (row
);
15193 /* If we hit the beginning of the displayed portion
15194 without finding the first row of a continued
15198 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15201 eassert (row
->enabled_p
);
15206 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15207 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
15208 /* Make sure this isn't a header line by any chance, since
15209 then MATRIX_ROW_PARTIALLY_VISIBLE_P might yield non-zero. */
15210 && !row
->mode_line_p
15211 && make_cursor_line_fully_visible_p
)
15213 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
15214 && !row
->ends_at_zv_p
15215 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15216 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15217 else if (row
->height
> window_box_height (w
))
15219 /* If we end up in a partially visible line, let's
15220 make it fully visible, except when it's taller
15221 than the window, in which case we can't do much
15224 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15228 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15229 if (!cursor_row_fully_visible_p (w
, 0, 1))
15230 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15232 rc
= CURSOR_MOVEMENT_SUCCESS
;
15236 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15237 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15238 && !NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
15240 /* With bidi-reordered rows, there could be more than
15241 one candidate row whose start and end positions
15242 occlude point. We need to let set_cursor_from_row
15243 find the best candidate. */
15244 /* FIXME: Revisit this when glyph ``spilling'' in
15245 continuation lines' rows is implemented for
15246 bidi-reordered rows. */
15251 int at_zv_p
= 0, exact_match_p
= 0;
15253 if (MATRIX_ROW_START_CHARPOS (row
) <= PT
15254 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
15255 && cursor_row_p (row
))
15256 rv
|= set_cursor_from_row (w
, row
, w
->current_matrix
,
15258 /* As soon as we've found the exact match for point,
15259 or the first suitable row whose ends_at_zv_p flag
15260 is set, we are done. */
15262 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
)->ends_at_zv_p
;
15264 && w
->cursor
.hpos
>= 0
15265 && w
->cursor
.hpos
< MATRIX_ROW_USED (w
->current_matrix
,
15268 struct glyph_row
*candidate
=
15269 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
15271 candidate
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
15272 ptrdiff_t endpos
= MATRIX_ROW_END_CHARPOS (candidate
);
15275 (BUFFERP (g
->object
) && g
->charpos
== PT
)
15276 || (INTEGERP (g
->object
)
15277 && (g
->charpos
== PT
15278 || (g
->charpos
== 0 && endpos
- 1 == PT
)));
15280 if (rv
&& (at_zv_p
|| exact_match_p
))
15282 rc
= CURSOR_MOVEMENT_SUCCESS
;
15285 if (MATRIX_ROW_BOTTOM_Y (row
) == last_y
)
15289 while (((MATRIX_ROW_CONTINUATION_LINE_P (row
)
15290 || row
->continued_p
)
15291 && MATRIX_ROW_BOTTOM_Y (row
) <= last_y
)
15292 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15293 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
));
15294 /* If we didn't find any candidate rows, or exited the
15295 loop before all the candidates were examined, signal
15296 to the caller that this method failed. */
15297 if (rc
!= CURSOR_MOVEMENT_SUCCESS
15299 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
15300 && !row
->continued_p
))
15301 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15303 rc
= CURSOR_MOVEMENT_SUCCESS
;
15309 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
15311 rc
= CURSOR_MOVEMENT_SUCCESS
;
15316 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15317 && MATRIX_ROW_START_CHARPOS (row
) == PT
15318 && cursor_row_p (row
));
15326 #if !defined USE_TOOLKIT_SCROLL_BARS || defined USE_GTK
15330 set_vertical_scroll_bar (struct window
*w
)
15332 ptrdiff_t start
, end
, whole
;
15334 /* Calculate the start and end positions for the current window.
15335 At some point, it would be nice to choose between scrollbars
15336 which reflect the whole buffer size, with special markers
15337 indicating narrowing, and scrollbars which reflect only the
15340 Note that mini-buffers sometimes aren't displaying any text. */
15341 if (!MINI_WINDOW_P (w
)
15342 || (w
== XWINDOW (minibuf_window
)
15343 && NILP (echo_area_buffer
[0])))
15345 struct buffer
*buf
= XBUFFER (w
->buffer
);
15346 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
15347 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
15348 /* I don't think this is guaranteed to be right. For the
15349 moment, we'll pretend it is. */
15350 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
15354 if (whole
< (end
- start
))
15355 whole
= end
- start
;
15358 start
= end
= whole
= 0;
15360 /* Indicate what this scroll bar ought to be displaying now. */
15361 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15362 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15363 (w
, end
- start
, whole
, start
);
15367 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
15368 selected_window is redisplayed.
15370 We can return without actually redisplaying the window if
15371 fonts_changed_p. In that case, redisplay_internal will
15375 redisplay_window (Lisp_Object window
, int just_this_one_p
)
15377 struct window
*w
= XWINDOW (window
);
15378 struct frame
*f
= XFRAME (w
->frame
);
15379 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15380 struct buffer
*old
= current_buffer
;
15381 struct text_pos lpoint
, opoint
, startp
;
15382 int update_mode_line
;
15385 /* Record it now because it's overwritten. */
15386 int current_matrix_up_to_date_p
= 0;
15387 int used_current_matrix_p
= 0;
15388 /* This is less strict than current_matrix_up_to_date_p.
15389 It indicates that the buffer contents and narrowing are unchanged. */
15390 int buffer_unchanged_p
= 0;
15391 int temp_scroll_step
= 0;
15392 ptrdiff_t count
= SPECPDL_INDEX ();
15394 int centering_position
= -1;
15395 int last_line_misfit
= 0;
15396 ptrdiff_t beg_unchanged
, end_unchanged
;
15398 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15401 /* W must be a leaf window here. */
15402 eassert (!NILP (w
->buffer
));
15404 *w
->desired_matrix
->method
= 0;
15408 reconsider_clip_changes (w
, buffer
);
15410 /* Has the mode line to be updated? */
15411 update_mode_line
= (w
->update_mode_line
15412 || update_mode_lines
15413 || buffer
->clip_changed
15414 || buffer
->prevent_redisplay_optimizations_p
);
15416 if (MINI_WINDOW_P (w
))
15418 if (w
== XWINDOW (echo_area_window
)
15419 && !NILP (echo_area_buffer
[0]))
15421 if (update_mode_line
)
15422 /* We may have to update a tty frame's menu bar or a
15423 tool-bar. Example `M-x C-h C-h C-g'. */
15424 goto finish_menu_bars
;
15426 /* We've already displayed the echo area glyphs in this window. */
15427 goto finish_scroll_bars
;
15429 else if ((w
!= XWINDOW (minibuf_window
)
15430 || minibuf_level
== 0)
15431 /* When buffer is nonempty, redisplay window normally. */
15432 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
15433 /* Quail displays non-mini buffers in minibuffer window.
15434 In that case, redisplay the window normally. */
15435 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
15437 /* W is a mini-buffer window, but it's not active, so clear
15439 int yb
= window_text_bottom_y (w
);
15440 struct glyph_row
*row
;
15443 for (y
= 0, row
= w
->desired_matrix
->rows
;
15445 y
+= row
->height
, ++row
)
15446 blank_row (w
, row
, y
);
15447 goto finish_scroll_bars
;
15450 clear_glyph_matrix (w
->desired_matrix
);
15453 /* Otherwise set up data on this window; select its buffer and point
15455 /* Really select the buffer, for the sake of buffer-local
15457 set_buffer_internal_1 (XBUFFER (w
->buffer
));
15459 current_matrix_up_to_date_p
15460 = (!NILP (w
->window_end_valid
)
15461 && !current_buffer
->clip_changed
15462 && !current_buffer
->prevent_redisplay_optimizations_p
15463 && w
->last_modified
>= MODIFF
15464 && w
->last_overlay_modified
>= OVERLAY_MODIFF
);
15466 /* Run the window-bottom-change-functions
15467 if it is possible that the text on the screen has changed
15468 (either due to modification of the text, or any other reason). */
15469 if (!current_matrix_up_to_date_p
15470 && !NILP (Vwindow_text_change_functions
))
15472 safe_run_hooks (Qwindow_text_change_functions
);
15476 beg_unchanged
= BEG_UNCHANGED
;
15477 end_unchanged
= END_UNCHANGED
;
15479 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
15481 specbind (Qinhibit_point_motion_hooks
, Qt
);
15484 = (!NILP (w
->window_end_valid
)
15485 && !current_buffer
->clip_changed
15486 && w
->last_modified
>= MODIFF
15487 && w
->last_overlay_modified
>= OVERLAY_MODIFF
);
15489 /* When windows_or_buffers_changed is non-zero, we can't rely on
15490 the window end being valid, so set it to nil there. */
15491 if (windows_or_buffers_changed
)
15493 /* If window starts on a continuation line, maybe adjust the
15494 window start in case the window's width changed. */
15495 if (XMARKER (w
->start
)->buffer
== current_buffer
)
15496 compute_window_start_on_continuation_line (w
);
15498 wset_window_end_valid (w
, Qnil
);
15501 /* Some sanity checks. */
15502 CHECK_WINDOW_END (w
);
15503 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
15505 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
15508 /* If %c is in mode line, update it if needed. */
15509 if (!NILP (w
->column_number_displayed
)
15510 /* This alternative quickly identifies a common case
15511 where no change is needed. */
15512 && !(PT
== w
->last_point
15513 && w
->last_modified
>= MODIFF
15514 && w
->last_overlay_modified
>= OVERLAY_MODIFF
)
15515 && (XFASTINT (w
->column_number_displayed
) != current_column ()))
15516 update_mode_line
= 1;
15518 /* Count number of windows showing the selected buffer. An indirect
15519 buffer counts as its base buffer. */
15520 if (!just_this_one_p
)
15522 struct buffer
*current_base
, *window_base
;
15523 current_base
= current_buffer
;
15524 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
15525 if (current_base
->base_buffer
)
15526 current_base
= current_base
->base_buffer
;
15527 if (window_base
->base_buffer
)
15528 window_base
= window_base
->base_buffer
;
15529 if (current_base
== window_base
)
15533 /* Point refers normally to the selected window. For any other
15534 window, set up appropriate value. */
15535 if (!EQ (window
, selected_window
))
15537 ptrdiff_t new_pt
= XMARKER (w
->pointm
)->charpos
;
15538 ptrdiff_t new_pt_byte
= marker_byte_position (w
->pointm
);
15542 new_pt_byte
= BEGV_BYTE
;
15543 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
15545 else if (new_pt
> (ZV
- 1))
15548 new_pt_byte
= ZV_BYTE
;
15549 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
15552 /* We don't use SET_PT so that the point-motion hooks don't run. */
15553 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
15556 /* If any of the character widths specified in the display table
15557 have changed, invalidate the width run cache. It's true that
15558 this may be a bit late to catch such changes, but the rest of
15559 redisplay goes (non-fatally) haywire when the display table is
15560 changed, so why should we worry about doing any better? */
15561 if (current_buffer
->width_run_cache
)
15563 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
15565 if (! disptab_matches_widthtab
15566 (disptab
, XVECTOR (BVAR (current_buffer
, width_table
))))
15568 invalidate_region_cache (current_buffer
,
15569 current_buffer
->width_run_cache
,
15571 recompute_width_table (current_buffer
, disptab
);
15575 /* If window-start is screwed up, choose a new one. */
15576 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
15579 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15581 /* If someone specified a new starting point but did not insist,
15582 check whether it can be used. */
15583 if (w
->optional_new_start
15584 && CHARPOS (startp
) >= BEGV
15585 && CHARPOS (startp
) <= ZV
)
15587 w
->optional_new_start
= 0;
15588 start_display (&it
, w
, startp
);
15589 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
15590 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15591 if (IT_CHARPOS (it
) == PT
)
15592 w
->force_start
= 1;
15593 /* IT may overshoot PT if text at PT is invisible. */
15594 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
15595 w
->force_start
= 1;
15600 /* Handle case where place to start displaying has been specified,
15601 unless the specified location is outside the accessible range. */
15602 if (w
->force_start
|| w
->frozen_window_start_p
)
15604 /* We set this later on if we have to adjust point. */
15607 w
->force_start
= 0;
15609 wset_window_end_valid (w
, Qnil
);
15611 /* Forget any recorded base line for line number display. */
15612 if (!buffer_unchanged_p
)
15613 wset_base_line_number (w
, Qnil
);
15615 /* Redisplay the mode line. Select the buffer properly for that.
15616 Also, run the hook window-scroll-functions
15617 because we have scrolled. */
15618 /* Note, we do this after clearing force_start because
15619 if there's an error, it is better to forget about force_start
15620 than to get into an infinite loop calling the hook functions
15621 and having them get more errors. */
15622 if (!update_mode_line
15623 || ! NILP (Vwindow_scroll_functions
))
15625 update_mode_line
= 1;
15626 w
->update_mode_line
= 1;
15627 startp
= run_window_scroll_functions (window
, startp
);
15630 w
->last_modified
= 0;
15631 w
->last_overlay_modified
= 0;
15632 if (CHARPOS (startp
) < BEGV
)
15633 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
15634 else if (CHARPOS (startp
) > ZV
)
15635 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
15637 /* Redisplay, then check if cursor has been set during the
15638 redisplay. Give up if new fonts were loaded. */
15639 /* We used to issue a CHECK_MARGINS argument to try_window here,
15640 but this causes scrolling to fail when point begins inside
15641 the scroll margin (bug#148) -- cyd */
15642 if (!try_window (window
, startp
, 0))
15644 w
->force_start
= 1;
15645 clear_glyph_matrix (w
->desired_matrix
);
15646 goto need_larger_matrices
;
15649 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
15651 /* If point does not appear, try to move point so it does
15652 appear. The desired matrix has been built above, so we
15653 can use it here. */
15654 new_vpos
= window_box_height (w
) / 2;
15657 if (!cursor_row_fully_visible_p (w
, 0, 0))
15659 /* Point does appear, but on a line partly visible at end of window.
15660 Move it back to a fully-visible line. */
15661 new_vpos
= window_box_height (w
);
15664 /* If we need to move point for either of the above reasons,
15665 now actually do it. */
15668 struct glyph_row
*row
;
15670 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
15671 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
15674 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
15675 MATRIX_ROW_START_BYTEPOS (row
));
15677 if (w
!= XWINDOW (selected_window
))
15678 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
15679 else if (current_buffer
== old
)
15680 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15682 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
15684 /* If we are highlighting the region, then we just changed
15685 the region, so redisplay to show it. */
15686 if (!NILP (Vtransient_mark_mode
)
15687 && !NILP (BVAR (current_buffer
, mark_active
)))
15689 clear_glyph_matrix (w
->desired_matrix
);
15690 if (!try_window (window
, startp
, 0))
15691 goto need_larger_matrices
;
15696 debug_method_add (w
, "forced window start");
15701 /* Handle case where text has not changed, only point, and it has
15702 not moved off the frame, and we are not retrying after hscroll.
15703 (current_matrix_up_to_date_p is nonzero when retrying.) */
15704 if (current_matrix_up_to_date_p
15705 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
15706 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
15710 case CURSOR_MOVEMENT_SUCCESS
:
15711 used_current_matrix_p
= 1;
15714 case CURSOR_MOVEMENT_MUST_SCROLL
:
15715 goto try_to_scroll
;
15721 /* If current starting point was originally the beginning of a line
15722 but no longer is, find a new starting point. */
15723 else if (w
->start_at_line_beg
15724 && !(CHARPOS (startp
) <= BEGV
15725 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
15728 debug_method_add (w
, "recenter 1");
15733 /* Try scrolling with try_window_id. Value is > 0 if update has
15734 been done, it is -1 if we know that the same window start will
15735 not work. It is 0 if unsuccessful for some other reason. */
15736 else if ((tem
= try_window_id (w
)) != 0)
15739 debug_method_add (w
, "try_window_id %d", tem
);
15742 if (fonts_changed_p
)
15743 goto need_larger_matrices
;
15747 /* Otherwise try_window_id has returned -1 which means that we
15748 don't want the alternative below this comment to execute. */
15750 else if (CHARPOS (startp
) >= BEGV
15751 && CHARPOS (startp
) <= ZV
15752 && PT
>= CHARPOS (startp
)
15753 && (CHARPOS (startp
) < ZV
15754 /* Avoid starting at end of buffer. */
15755 || CHARPOS (startp
) == BEGV
15756 || (w
->last_modified
>= MODIFF
15757 && w
->last_overlay_modified
>= OVERLAY_MODIFF
)))
15759 int d1
, d2
, d3
, d4
, d5
, d6
;
15761 /* If first window line is a continuation line, and window start
15762 is inside the modified region, but the first change is before
15763 current window start, we must select a new window start.
15765 However, if this is the result of a down-mouse event (e.g. by
15766 extending the mouse-drag-overlay), we don't want to select a
15767 new window start, since that would change the position under
15768 the mouse, resulting in an unwanted mouse-movement rather
15769 than a simple mouse-click. */
15770 if (!w
->start_at_line_beg
15771 && NILP (do_mouse_tracking
)
15772 && CHARPOS (startp
) > BEGV
15773 && CHARPOS (startp
) > BEG
+ beg_unchanged
15774 && CHARPOS (startp
) <= Z
- end_unchanged
15775 /* Even if w->start_at_line_beg is nil, a new window may
15776 start at a line_beg, since that's how set_buffer_window
15777 sets it. So, we need to check the return value of
15778 compute_window_start_on_continuation_line. (See also
15780 && XMARKER (w
->start
)->buffer
== current_buffer
15781 && compute_window_start_on_continuation_line (w
)
15782 /* It doesn't make sense to force the window start like we
15783 do at label force_start if it is already known that point
15784 will not be visible in the resulting window, because
15785 doing so will move point from its correct position
15786 instead of scrolling the window to bring point into view.
15788 && pos_visible_p (w
, PT
, &d1
, &d2
, &d3
, &d4
, &d5
, &d6
))
15790 w
->force_start
= 1;
15791 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15796 debug_method_add (w
, "same window start");
15799 /* Try to redisplay starting at same place as before.
15800 If point has not moved off frame, accept the results. */
15801 if (!current_matrix_up_to_date_p
15802 /* Don't use try_window_reusing_current_matrix in this case
15803 because a window scroll function can have changed the
15805 || !NILP (Vwindow_scroll_functions
)
15806 || MINI_WINDOW_P (w
)
15807 || !(used_current_matrix_p
15808 = try_window_reusing_current_matrix (w
)))
15810 IF_DEBUG (debug_method_add (w
, "1"));
15811 if (try_window (window
, startp
, TRY_WINDOW_CHECK_MARGINS
) < 0)
15812 /* -1 means we need to scroll.
15813 0 means we need new matrices, but fonts_changed_p
15814 is set in that case, so we will detect it below. */
15815 goto try_to_scroll
;
15818 if (fonts_changed_p
)
15819 goto need_larger_matrices
;
15821 if (w
->cursor
.vpos
>= 0)
15823 if (!just_this_one_p
15824 || current_buffer
->clip_changed
15825 || BEG_UNCHANGED
< CHARPOS (startp
))
15826 /* Forget any recorded base line for line number display. */
15827 wset_base_line_number (w
, Qnil
);
15829 if (!cursor_row_fully_visible_p (w
, 1, 0))
15831 clear_glyph_matrix (w
->desired_matrix
);
15832 last_line_misfit
= 1;
15834 /* Drop through and scroll. */
15839 clear_glyph_matrix (w
->desired_matrix
);
15844 w
->last_modified
= 0;
15845 w
->last_overlay_modified
= 0;
15847 /* Redisplay the mode line. Select the buffer properly for that. */
15848 if (!update_mode_line
)
15850 update_mode_line
= 1;
15851 w
->update_mode_line
= 1;
15854 /* Try to scroll by specified few lines. */
15855 if ((scroll_conservatively
15856 || emacs_scroll_step
15857 || temp_scroll_step
15858 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
))
15859 || NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
)))
15860 && CHARPOS (startp
) >= BEGV
15861 && CHARPOS (startp
) <= ZV
)
15863 /* The function returns -1 if new fonts were loaded, 1 if
15864 successful, 0 if not successful. */
15865 int ss
= try_scrolling (window
, just_this_one_p
,
15866 scroll_conservatively
,
15868 temp_scroll_step
, last_line_misfit
);
15871 case SCROLLING_SUCCESS
:
15874 case SCROLLING_NEED_LARGER_MATRICES
:
15875 goto need_larger_matrices
;
15877 case SCROLLING_FAILED
:
15885 /* Finally, just choose a place to start which positions point
15886 according to user preferences. */
15891 debug_method_add (w
, "recenter");
15894 /* w->vscroll = 0; */
15896 /* Forget any previously recorded base line for line number display. */
15897 if (!buffer_unchanged_p
)
15898 wset_base_line_number (w
, Qnil
);
15900 /* Determine the window start relative to point. */
15901 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
15902 it
.current_y
= it
.last_visible_y
;
15903 if (centering_position
< 0)
15907 ? min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
15909 ptrdiff_t margin_pos
= CHARPOS (startp
);
15910 Lisp_Object aggressive
;
15913 /* If there is a scroll margin at the top of the window, find
15914 its character position. */
15916 /* Cannot call start_display if startp is not in the
15917 accessible region of the buffer. This can happen when we
15918 have just switched to a different buffer and/or changed
15919 its restriction. In that case, startp is initialized to
15920 the character position 1 (BEGV) because we did not yet
15921 have chance to display the buffer even once. */
15922 && BEGV
<= CHARPOS (startp
) && CHARPOS (startp
) <= ZV
)
15925 void *it1data
= NULL
;
15927 SAVE_IT (it1
, it
, it1data
);
15928 start_display (&it1
, w
, startp
);
15929 move_it_vertically (&it1
, margin
* FRAME_LINE_HEIGHT (f
));
15930 margin_pos
= IT_CHARPOS (it1
);
15931 RESTORE_IT (&it
, &it
, it1data
);
15933 scrolling_up
= PT
> margin_pos
;
15936 ? BVAR (current_buffer
, scroll_up_aggressively
)
15937 : BVAR (current_buffer
, scroll_down_aggressively
);
15939 if (!MINI_WINDOW_P (w
)
15940 && (scroll_conservatively
> SCROLL_LIMIT
|| NUMBERP (aggressive
)))
15944 /* Setting scroll-conservatively overrides
15945 scroll-*-aggressively. */
15946 if (!scroll_conservatively
&& NUMBERP (aggressive
))
15948 double float_amount
= XFLOATINT (aggressive
);
15950 pt_offset
= float_amount
* WINDOW_BOX_TEXT_HEIGHT (w
);
15951 if (pt_offset
== 0 && float_amount
> 0)
15953 if (pt_offset
&& margin
> 0)
15956 /* Compute how much to move the window start backward from
15957 point so that point will be displayed where the user
15961 centering_position
= it
.last_visible_y
;
15963 centering_position
-= pt_offset
;
15964 centering_position
-=
15965 FRAME_LINE_HEIGHT (f
) * (1 + margin
+ (last_line_misfit
!= 0))
15966 + WINDOW_HEADER_LINE_HEIGHT (w
);
15967 /* Don't let point enter the scroll margin near top of
15969 if (centering_position
< margin
* FRAME_LINE_HEIGHT (f
))
15970 centering_position
= margin
* FRAME_LINE_HEIGHT (f
);
15973 centering_position
= margin
* FRAME_LINE_HEIGHT (f
) + pt_offset
;
15976 /* Set the window start half the height of the window backward
15978 centering_position
= window_box_height (w
) / 2;
15980 move_it_vertically_backward (&it
, centering_position
);
15982 eassert (IT_CHARPOS (it
) >= BEGV
);
15984 /* The function move_it_vertically_backward may move over more
15985 than the specified y-distance. If it->w is small, e.g. a
15986 mini-buffer window, we may end up in front of the window's
15987 display area. Start displaying at the start of the line
15988 containing PT in this case. */
15989 if (it
.current_y
<= 0)
15991 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
15992 move_it_vertically_backward (&it
, 0);
15996 it
.current_x
= it
.hpos
= 0;
15998 /* Set the window start position here explicitly, to avoid an
15999 infinite loop in case the functions in window-scroll-functions
16001 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
16003 /* Run scroll hooks. */
16004 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
16006 /* Redisplay the window. */
16007 if (!current_matrix_up_to_date_p
16008 || windows_or_buffers_changed
16009 || cursor_type_changed
16010 /* Don't use try_window_reusing_current_matrix in this case
16011 because it can have changed the buffer. */
16012 || !NILP (Vwindow_scroll_functions
)
16013 || !just_this_one_p
16014 || MINI_WINDOW_P (w
)
16015 || !(used_current_matrix_p
16016 = try_window_reusing_current_matrix (w
)))
16017 try_window (window
, startp
, 0);
16019 /* If new fonts have been loaded (due to fontsets), give up. We
16020 have to start a new redisplay since we need to re-adjust glyph
16022 if (fonts_changed_p
)
16023 goto need_larger_matrices
;
16025 /* If cursor did not appear assume that the middle of the window is
16026 in the first line of the window. Do it again with the next line.
16027 (Imagine a window of height 100, displaying two lines of height
16028 60. Moving back 50 from it->last_visible_y will end in the first
16030 if (w
->cursor
.vpos
< 0)
16032 if (!NILP (w
->window_end_valid
)
16033 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
16035 clear_glyph_matrix (w
->desired_matrix
);
16036 move_it_by_lines (&it
, 1);
16037 try_window (window
, it
.current
.pos
, 0);
16039 else if (PT
< IT_CHARPOS (it
))
16041 clear_glyph_matrix (w
->desired_matrix
);
16042 move_it_by_lines (&it
, -1);
16043 try_window (window
, it
.current
.pos
, 0);
16047 /* Not much we can do about it. */
16051 /* Consider the following case: Window starts at BEGV, there is
16052 invisible, intangible text at BEGV, so that display starts at
16053 some point START > BEGV. It can happen that we are called with
16054 PT somewhere between BEGV and START. Try to handle that case. */
16055 if (w
->cursor
.vpos
< 0)
16057 struct glyph_row
*row
= w
->current_matrix
->rows
;
16058 if (row
->mode_line_p
)
16060 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
16063 if (!cursor_row_fully_visible_p (w
, 0, 0))
16065 /* If vscroll is enabled, disable it and try again. */
16069 clear_glyph_matrix (w
->desired_matrix
);
16073 /* Users who set scroll-conservatively to a large number want
16074 point just above/below the scroll margin. If we ended up
16075 with point's row partially visible, move the window start to
16076 make that row fully visible and out of the margin. */
16077 if (scroll_conservatively
> SCROLL_LIMIT
)
16081 ? min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
16083 int move_down
= w
->cursor
.vpos
>= WINDOW_TOTAL_LINES (w
) / 2;
16085 move_it_by_lines (&it
, move_down
? margin
+ 1 : -(margin
+ 1));
16086 clear_glyph_matrix (w
->desired_matrix
);
16087 if (1 == try_window (window
, it
.current
.pos
,
16088 TRY_WINDOW_CHECK_MARGINS
))
16092 /* If centering point failed to make the whole line visible,
16093 put point at the top instead. That has to make the whole line
16094 visible, if it can be done. */
16095 if (centering_position
== 0)
16098 clear_glyph_matrix (w
->desired_matrix
);
16099 centering_position
= 0;
16105 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
16106 w
->start_at_line_beg
= (CHARPOS (startp
) == BEGV
16107 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n');
16109 /* Display the mode line, if we must. */
16110 if ((update_mode_line
16111 /* If window not full width, must redo its mode line
16112 if (a) the window to its side is being redone and
16113 (b) we do a frame-based redisplay. This is a consequence
16114 of how inverted lines are drawn in frame-based redisplay. */
16115 || (!just_this_one_p
16116 && !FRAME_WINDOW_P (f
)
16117 && !WINDOW_FULL_WIDTH_P (w
))
16118 /* Line number to display. */
16119 || INTEGERP (w
->base_line_pos
)
16120 /* Column number is displayed and different from the one displayed. */
16121 || (!NILP (w
->column_number_displayed
)
16122 && (XFASTINT (w
->column_number_displayed
) != current_column ())))
16123 /* This means that the window has a mode line. */
16124 && (WINDOW_WANTS_MODELINE_P (w
)
16125 || WINDOW_WANTS_HEADER_LINE_P (w
)))
16127 display_mode_lines (w
);
16129 /* If mode line height has changed, arrange for a thorough
16130 immediate redisplay using the correct mode line height. */
16131 if (WINDOW_WANTS_MODELINE_P (w
)
16132 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
16134 fonts_changed_p
= 1;
16135 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
16136 = DESIRED_MODE_LINE_HEIGHT (w
);
16139 /* If header line height has changed, arrange for a thorough
16140 immediate redisplay using the correct header line height. */
16141 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16142 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
16144 fonts_changed_p
= 1;
16145 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
16146 = DESIRED_HEADER_LINE_HEIGHT (w
);
16149 if (fonts_changed_p
)
16150 goto need_larger_matrices
;
16153 if (!line_number_displayed
16154 && !BUFFERP (w
->base_line_pos
))
16156 wset_base_line_pos (w
, Qnil
);
16157 wset_base_line_number (w
, Qnil
);
16162 /* When we reach a frame's selected window, redo the frame's menu bar. */
16163 if (update_mode_line
16164 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
16166 int redisplay_menu_p
= 0;
16168 if (FRAME_WINDOW_P (f
))
16170 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
16171 || defined (HAVE_NS) || defined (USE_GTK)
16172 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
16174 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16178 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16180 if (redisplay_menu_p
)
16181 display_menu_bar (w
);
16183 #ifdef HAVE_WINDOW_SYSTEM
16184 if (FRAME_WINDOW_P (f
))
16186 #if defined (USE_GTK) || defined (HAVE_NS)
16187 if (FRAME_EXTERNAL_TOOL_BAR (f
))
16188 redisplay_tool_bar (f
);
16190 if (WINDOWP (f
->tool_bar_window
)
16191 && (FRAME_TOOL_BAR_LINES (f
) > 0
16192 || !NILP (Vauto_resize_tool_bars
))
16193 && redisplay_tool_bar (f
))
16194 ignore_mouse_drag_p
= 1;
16200 #ifdef HAVE_WINDOW_SYSTEM
16201 if (FRAME_WINDOW_P (f
)
16202 && update_window_fringes (w
, (just_this_one_p
16203 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
16204 || w
->pseudo_window_p
)))
16208 if (draw_window_fringes (w
, 1))
16209 x_draw_vertical_border (w
);
16213 #endif /* HAVE_WINDOW_SYSTEM */
16215 /* We go to this label, with fonts_changed_p set,
16216 if it is necessary to try again using larger glyph matrices.
16217 We have to redeem the scroll bar even in this case,
16218 because the loop in redisplay_internal expects that. */
16219 need_larger_matrices
:
16221 finish_scroll_bars
:
16223 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
16225 /* Set the thumb's position and size. */
16226 set_vertical_scroll_bar (w
);
16228 /* Note that we actually used the scroll bar attached to this
16229 window, so it shouldn't be deleted at the end of redisplay. */
16230 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
16231 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
16234 /* Restore current_buffer and value of point in it. The window
16235 update may have changed the buffer, so first make sure `opoint'
16236 is still valid (Bug#6177). */
16237 if (CHARPOS (opoint
) < BEGV
)
16238 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
16239 else if (CHARPOS (opoint
) > ZV
)
16240 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
16242 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
16244 set_buffer_internal_1 (old
);
16245 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
16246 shorter. This can be caused by log truncation in *Messages*. */
16247 if (CHARPOS (lpoint
) <= ZV
)
16248 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
16250 unbind_to (count
, Qnil
);
16254 /* Build the complete desired matrix of WINDOW with a window start
16255 buffer position POS.
16257 Value is 1 if successful. It is zero if fonts were loaded during
16258 redisplay which makes re-adjusting glyph matrices necessary, and -1
16259 if point would appear in the scroll margins.
16260 (We check the former only if TRY_WINDOW_IGNORE_FONTS_CHANGE is
16261 unset in FLAGS, and the latter only if TRY_WINDOW_CHECK_MARGINS is
16265 try_window (Lisp_Object window
, struct text_pos pos
, int flags
)
16267 struct window
*w
= XWINDOW (window
);
16269 struct glyph_row
*last_text_row
= NULL
;
16270 struct frame
*f
= XFRAME (w
->frame
);
16272 /* Make POS the new window start. */
16273 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
16275 /* Mark cursor position as unknown. No overlay arrow seen. */
16276 w
->cursor
.vpos
= -1;
16277 overlay_arrow_seen
= 0;
16279 /* Initialize iterator and info to start at POS. */
16280 start_display (&it
, w
, pos
);
16282 /* Display all lines of W. */
16283 while (it
.current_y
< it
.last_visible_y
)
16285 if (display_line (&it
))
16286 last_text_row
= it
.glyph_row
- 1;
16287 if (fonts_changed_p
&& !(flags
& TRY_WINDOW_IGNORE_FONTS_CHANGE
))
16291 /* Don't let the cursor end in the scroll margins. */
16292 if ((flags
& TRY_WINDOW_CHECK_MARGINS
)
16293 && !MINI_WINDOW_P (w
))
16295 int this_scroll_margin
;
16297 if (scroll_margin
> 0)
16299 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
16300 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
16303 this_scroll_margin
= 0;
16305 if ((w
->cursor
.y
>= 0 /* not vscrolled */
16306 && w
->cursor
.y
< this_scroll_margin
16307 && CHARPOS (pos
) > BEGV
16308 && IT_CHARPOS (it
) < ZV
)
16309 /* rms: considering make_cursor_line_fully_visible_p here
16310 seems to give wrong results. We don't want to recenter
16311 when the last line is partly visible, we want to allow
16312 that case to be handled in the usual way. */
16313 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
16315 w
->cursor
.vpos
= -1;
16316 clear_glyph_matrix (w
->desired_matrix
);
16321 /* If bottom moved off end of frame, change mode line percentage. */
16322 if (XFASTINT (w
->window_end_pos
) <= 0
16323 && Z
!= IT_CHARPOS (it
))
16324 w
->update_mode_line
= 1;
16326 /* Set window_end_pos to the offset of the last character displayed
16327 on the window from the end of current_buffer. Set
16328 window_end_vpos to its row number. */
16331 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
16332 w
->window_end_bytepos
16333 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16334 wset_window_end_pos
16335 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
)));
16336 wset_window_end_vpos
16337 (w
, make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
)));
16339 (MATRIX_ROW (w
->desired_matrix
,
16340 XFASTINT (w
->window_end_vpos
))->displays_text_p
);
16344 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16345 wset_window_end_pos (w
, make_number (Z
- ZV
));
16346 wset_window_end_vpos (w
, make_number (0));
16349 /* But that is not valid info until redisplay finishes. */
16350 wset_window_end_valid (w
, Qnil
);
16356 /************************************************************************
16357 Window redisplay reusing current matrix when buffer has not changed
16358 ************************************************************************/
16360 /* Try redisplay of window W showing an unchanged buffer with a
16361 different window start than the last time it was displayed by
16362 reusing its current matrix. Value is non-zero if successful.
16363 W->start is the new window start. */
16366 try_window_reusing_current_matrix (struct window
*w
)
16368 struct frame
*f
= XFRAME (w
->frame
);
16369 struct glyph_row
*bottom_row
;
16372 struct text_pos start
, new_start
;
16373 int nrows_scrolled
, i
;
16374 struct glyph_row
*last_text_row
;
16375 struct glyph_row
*last_reused_text_row
;
16376 struct glyph_row
*start_row
;
16377 int start_vpos
, min_y
, max_y
;
16380 if (inhibit_try_window_reusing
)
16384 if (/* This function doesn't handle terminal frames. */
16385 !FRAME_WINDOW_P (f
)
16386 /* Don't try to reuse the display if windows have been split
16388 || windows_or_buffers_changed
16389 || cursor_type_changed
)
16392 /* Can't do this if region may have changed. */
16393 if ((!NILP (Vtransient_mark_mode
)
16394 && !NILP (BVAR (current_buffer
, mark_active
)))
16395 || !NILP (w
->region_showing
)
16396 || !NILP (Vshow_trailing_whitespace
))
16399 /* If top-line visibility has changed, give up. */
16400 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16401 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
16404 /* Give up if old or new display is scrolled vertically. We could
16405 make this function handle this, but right now it doesn't. */
16406 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16407 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
16410 /* The variable new_start now holds the new window start. The old
16411 start `start' can be determined from the current matrix. */
16412 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
16413 start
= start_row
->minpos
;
16414 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16416 /* Clear the desired matrix for the display below. */
16417 clear_glyph_matrix (w
->desired_matrix
);
16419 if (CHARPOS (new_start
) <= CHARPOS (start
))
16421 /* Don't use this method if the display starts with an ellipsis
16422 displayed for invisible text. It's not easy to handle that case
16423 below, and it's certainly not worth the effort since this is
16424 not a frequent case. */
16425 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
16428 IF_DEBUG (debug_method_add (w
, "twu1"));
16430 /* Display up to a row that can be reused. The variable
16431 last_text_row is set to the last row displayed that displays
16432 text. Note that it.vpos == 0 if or if not there is a
16433 header-line; it's not the same as the MATRIX_ROW_VPOS! */
16434 start_display (&it
, w
, new_start
);
16435 w
->cursor
.vpos
= -1;
16436 last_text_row
= last_reused_text_row
= NULL
;
16438 while (it
.current_y
< it
.last_visible_y
16439 && !fonts_changed_p
)
16441 /* If we have reached into the characters in the START row,
16442 that means the line boundaries have changed. So we
16443 can't start copying with the row START. Maybe it will
16444 work to start copying with the following row. */
16445 while (IT_CHARPOS (it
) > CHARPOS (start
))
16447 /* Advance to the next row as the "start". */
16449 start
= start_row
->minpos
;
16450 /* If there are no more rows to try, or just one, give up. */
16451 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
16452 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
16453 || CHARPOS (start
) == ZV
)
16455 clear_glyph_matrix (w
->desired_matrix
);
16459 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16461 /* If we have reached alignment, we can copy the rest of the
16463 if (IT_CHARPOS (it
) == CHARPOS (start
)
16464 /* Don't accept "alignment" inside a display vector,
16465 since start_row could have started in the middle of
16466 that same display vector (thus their character
16467 positions match), and we have no way of telling if
16468 that is the case. */
16469 && it
.current
.dpvec_index
< 0)
16472 if (display_line (&it
))
16473 last_text_row
= it
.glyph_row
- 1;
16477 /* A value of current_y < last_visible_y means that we stopped
16478 at the previous window start, which in turn means that we
16479 have at least one reusable row. */
16480 if (it
.current_y
< it
.last_visible_y
)
16482 struct glyph_row
*row
;
16484 /* IT.vpos always starts from 0; it counts text lines. */
16485 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
16487 /* Find PT if not already found in the lines displayed. */
16488 if (w
->cursor
.vpos
< 0)
16490 int dy
= it
.current_y
- start_row
->y
;
16492 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16493 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
16495 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
16496 dy
, nrows_scrolled
);
16499 clear_glyph_matrix (w
->desired_matrix
);
16504 /* Scroll the display. Do it before the current matrix is
16505 changed. The problem here is that update has not yet
16506 run, i.e. part of the current matrix is not up to date.
16507 scroll_run_hook will clear the cursor, and use the
16508 current matrix to get the height of the row the cursor is
16510 run
.current_y
= start_row
->y
;
16511 run
.desired_y
= it
.current_y
;
16512 run
.height
= it
.last_visible_y
- it
.current_y
;
16514 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
16517 FRAME_RIF (f
)->update_window_begin_hook (w
);
16518 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16519 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16520 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16524 /* Shift current matrix down by nrows_scrolled lines. */
16525 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16526 rotate_matrix (w
->current_matrix
,
16528 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16531 /* Disable lines that must be updated. */
16532 for (i
= 0; i
< nrows_scrolled
; ++i
)
16533 (start_row
+ i
)->enabled_p
= 0;
16535 /* Re-compute Y positions. */
16536 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16537 max_y
= it
.last_visible_y
;
16538 for (row
= start_row
+ nrows_scrolled
;
16542 row
->y
= it
.current_y
;
16543 row
->visible_height
= row
->height
;
16545 if (row
->y
< min_y
)
16546 row
->visible_height
-= min_y
- row
->y
;
16547 if (row
->y
+ row
->height
> max_y
)
16548 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16549 if (row
->fringe_bitmap_periodic_p
)
16550 row
->redraw_fringe_bitmaps_p
= 1;
16552 it
.current_y
+= row
->height
;
16554 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16555 last_reused_text_row
= row
;
16556 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
16560 /* Disable lines in the current matrix which are now
16561 below the window. */
16562 for (++row
; row
< bottom_row
; ++row
)
16563 row
->enabled_p
= row
->mode_line_p
= 0;
16566 /* Update window_end_pos etc.; last_reused_text_row is the last
16567 reused row from the current matrix containing text, if any.
16568 The value of last_text_row is the last displayed line
16569 containing text. */
16570 if (last_reused_text_row
)
16572 w
->window_end_bytepos
16573 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
16574 wset_window_end_pos
16576 - MATRIX_ROW_END_CHARPOS (last_reused_text_row
)));
16577 wset_window_end_vpos
16578 (w
, make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
16579 w
->current_matrix
)));
16581 else if (last_text_row
)
16583 w
->window_end_bytepos
16584 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16585 wset_window_end_pos
16586 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
)));
16587 wset_window_end_vpos
16588 (w
, make_number (MATRIX_ROW_VPOS (last_text_row
,
16589 w
->desired_matrix
)));
16593 /* This window must be completely empty. */
16594 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16595 wset_window_end_pos (w
, make_number (Z
- ZV
));
16596 wset_window_end_vpos (w
, make_number (0));
16598 wset_window_end_valid (w
, Qnil
);
16600 /* Update hint: don't try scrolling again in update_window. */
16601 w
->desired_matrix
->no_scrolling_p
= 1;
16604 debug_method_add (w
, "try_window_reusing_current_matrix 1");
16608 else if (CHARPOS (new_start
) > CHARPOS (start
))
16610 struct glyph_row
*pt_row
, *row
;
16611 struct glyph_row
*first_reusable_row
;
16612 struct glyph_row
*first_row_to_display
;
16614 int yb
= window_text_bottom_y (w
);
16616 /* Find the row starting at new_start, if there is one. Don't
16617 reuse a partially visible line at the end. */
16618 first_reusable_row
= start_row
;
16619 while (first_reusable_row
->enabled_p
16620 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
16621 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16622 < CHARPOS (new_start
)))
16623 ++first_reusable_row
;
16625 /* Give up if there is no row to reuse. */
16626 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
16627 || !first_reusable_row
->enabled_p
16628 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16629 != CHARPOS (new_start
)))
16632 /* We can reuse fully visible rows beginning with
16633 first_reusable_row to the end of the window. Set
16634 first_row_to_display to the first row that cannot be reused.
16635 Set pt_row to the row containing point, if there is any. */
16637 for (first_row_to_display
= first_reusable_row
;
16638 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
16639 ++first_row_to_display
)
16641 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
16642 && (PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16643 || (PT
== MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16644 && first_row_to_display
->ends_at_zv_p
16645 && pt_row
== NULL
)))
16646 pt_row
= first_row_to_display
;
16649 /* Start displaying at the start of first_row_to_display. */
16650 eassert (first_row_to_display
->y
< yb
);
16651 init_to_row_start (&it
, w
, first_row_to_display
);
16653 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
16655 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
16657 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
16658 + WINDOW_HEADER_LINE_HEIGHT (w
));
16660 /* Display lines beginning with first_row_to_display in the
16661 desired matrix. Set last_text_row to the last row displayed
16662 that displays text. */
16663 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
16664 if (pt_row
== NULL
)
16665 w
->cursor
.vpos
= -1;
16666 last_text_row
= NULL
;
16667 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
16668 if (display_line (&it
))
16669 last_text_row
= it
.glyph_row
- 1;
16671 /* If point is in a reused row, adjust y and vpos of the cursor
16675 w
->cursor
.vpos
-= nrows_scrolled
;
16676 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
16679 /* Give up if point isn't in a row displayed or reused. (This
16680 also handles the case where w->cursor.vpos < nrows_scrolled
16681 after the calls to display_line, which can happen with scroll
16682 margins. See bug#1295.) */
16683 if (w
->cursor
.vpos
< 0)
16685 clear_glyph_matrix (w
->desired_matrix
);
16689 /* Scroll the display. */
16690 run
.current_y
= first_reusable_row
->y
;
16691 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16692 run
.height
= it
.last_visible_y
- run
.current_y
;
16693 dy
= run
.current_y
- run
.desired_y
;
16698 FRAME_RIF (f
)->update_window_begin_hook (w
);
16699 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16700 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16701 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16705 /* Adjust Y positions of reused rows. */
16706 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16707 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16708 max_y
= it
.last_visible_y
;
16709 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
16712 row
->visible_height
= row
->height
;
16713 if (row
->y
< min_y
)
16714 row
->visible_height
-= min_y
- row
->y
;
16715 if (row
->y
+ row
->height
> max_y
)
16716 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16717 if (row
->fringe_bitmap_periodic_p
)
16718 row
->redraw_fringe_bitmaps_p
= 1;
16721 /* Scroll the current matrix. */
16722 eassert (nrows_scrolled
> 0);
16723 rotate_matrix (w
->current_matrix
,
16725 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16728 /* Disable rows not reused. */
16729 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
16730 row
->enabled_p
= 0;
16732 /* Point may have moved to a different line, so we cannot assume that
16733 the previous cursor position is valid; locate the correct row. */
16736 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
16738 && PT
>= MATRIX_ROW_END_CHARPOS (row
)
16739 && !row
->ends_at_zv_p
;
16743 w
->cursor
.y
= row
->y
;
16745 if (row
< bottom_row
)
16747 /* Can't simply scan the row for point with
16748 bidi-reordered glyph rows. Let set_cursor_from_row
16749 figure out where to put the cursor, and if it fails,
16751 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
16753 if (!set_cursor_from_row (w
, row
, w
->current_matrix
,
16756 clear_glyph_matrix (w
->desired_matrix
);
16762 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
16763 struct glyph
*end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16766 && (!BUFFERP (glyph
->object
)
16767 || glyph
->charpos
< PT
);
16771 w
->cursor
.x
+= glyph
->pixel_width
;
16777 /* Adjust window end. A null value of last_text_row means that
16778 the window end is in reused rows which in turn means that
16779 only its vpos can have changed. */
16782 w
->window_end_bytepos
16783 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16784 wset_window_end_pos
16785 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
)));
16786 wset_window_end_vpos
16787 (w
, make_number (MATRIX_ROW_VPOS (last_text_row
,
16788 w
->desired_matrix
)));
16792 wset_window_end_vpos
16793 (w
, make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
));
16796 wset_window_end_valid (w
, Qnil
);
16797 w
->desired_matrix
->no_scrolling_p
= 1;
16800 debug_method_add (w
, "try_window_reusing_current_matrix 2");
16810 /************************************************************************
16811 Window redisplay reusing current matrix when buffer has changed
16812 ************************************************************************/
16814 static struct glyph_row
*find_last_unchanged_at_beg_row (struct window
*);
16815 static struct glyph_row
*find_first_unchanged_at_end_row (struct window
*,
16816 ptrdiff_t *, ptrdiff_t *);
16817 static struct glyph_row
*
16818 find_last_row_displaying_text (struct glyph_matrix
*, struct it
*,
16819 struct glyph_row
*);
16822 /* Return the last row in MATRIX displaying text. If row START is
16823 non-null, start searching with that row. IT gives the dimensions
16824 of the display. Value is null if matrix is empty; otherwise it is
16825 a pointer to the row found. */
16827 static struct glyph_row
*
16828 find_last_row_displaying_text (struct glyph_matrix
*matrix
, struct it
*it
,
16829 struct glyph_row
*start
)
16831 struct glyph_row
*row
, *row_found
;
16833 /* Set row_found to the last row in IT->w's current matrix
16834 displaying text. The loop looks funny but think of partially
16837 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
16838 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16840 eassert (row
->enabled_p
);
16842 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
16851 /* Return the last row in the current matrix of W that is not affected
16852 by changes at the start of current_buffer that occurred since W's
16853 current matrix was built. Value is null if no such row exists.
16855 BEG_UNCHANGED us the number of characters unchanged at the start of
16856 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
16857 first changed character in current_buffer. Characters at positions <
16858 BEG + BEG_UNCHANGED are at the same buffer positions as they were
16859 when the current matrix was built. */
16861 static struct glyph_row
*
16862 find_last_unchanged_at_beg_row (struct window
*w
)
16864 ptrdiff_t first_changed_pos
= BEG
+ BEG_UNCHANGED
;
16865 struct glyph_row
*row
;
16866 struct glyph_row
*row_found
= NULL
;
16867 int yb
= window_text_bottom_y (w
);
16869 /* Find the last row displaying unchanged text. */
16870 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16871 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
16872 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
16875 if (/* If row ends before first_changed_pos, it is unchanged,
16876 except in some case. */
16877 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
16878 /* When row ends in ZV and we write at ZV it is not
16880 && !row
->ends_at_zv_p
16881 /* When first_changed_pos is the end of a continued line,
16882 row is not unchanged because it may be no longer
16884 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
16885 && (row
->continued_p
16886 || row
->exact_window_width_line_p
))
16887 /* If ROW->end is beyond ZV, then ROW->end is outdated and
16888 needs to be recomputed, so don't consider this row as
16889 unchanged. This happens when the last line was
16890 bidi-reordered and was killed immediately before this
16891 redisplay cycle. In that case, ROW->end stores the
16892 buffer position of the first visual-order character of
16893 the killed text, which is now beyond ZV. */
16894 && CHARPOS (row
->end
.pos
) <= ZV
)
16897 /* Stop if last visible row. */
16898 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
16906 /* Find the first glyph row in the current matrix of W that is not
16907 affected by changes at the end of current_buffer since the
16908 time W's current matrix was built.
16910 Return in *DELTA the number of chars by which buffer positions in
16911 unchanged text at the end of current_buffer must be adjusted.
16913 Return in *DELTA_BYTES the corresponding number of bytes.
16915 Value is null if no such row exists, i.e. all rows are affected by
16918 static struct glyph_row
*
16919 find_first_unchanged_at_end_row (struct window
*w
,
16920 ptrdiff_t *delta
, ptrdiff_t *delta_bytes
)
16922 struct glyph_row
*row
;
16923 struct glyph_row
*row_found
= NULL
;
16925 *delta
= *delta_bytes
= 0;
16927 /* Display must not have been paused, otherwise the current matrix
16928 is not up to date. */
16929 eassert (!NILP (w
->window_end_valid
));
16931 /* A value of window_end_pos >= END_UNCHANGED means that the window
16932 end is in the range of changed text. If so, there is no
16933 unchanged row at the end of W's current matrix. */
16934 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
16937 /* Set row to the last row in W's current matrix displaying text. */
16938 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
16940 /* If matrix is entirely empty, no unchanged row exists. */
16941 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16943 /* The value of row is the last glyph row in the matrix having a
16944 meaningful buffer position in it. The end position of row
16945 corresponds to window_end_pos. This allows us to translate
16946 buffer positions in the current matrix to current buffer
16947 positions for characters not in changed text. */
16949 MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
16950 ptrdiff_t Z_BYTE_old
=
16951 MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
16952 ptrdiff_t last_unchanged_pos
, last_unchanged_pos_old
;
16953 struct glyph_row
*first_text_row
16954 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16956 *delta
= Z
- Z_old
;
16957 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
16959 /* Set last_unchanged_pos to the buffer position of the last
16960 character in the buffer that has not been changed. Z is the
16961 index + 1 of the last character in current_buffer, i.e. by
16962 subtracting END_UNCHANGED we get the index of the last
16963 unchanged character, and we have to add BEG to get its buffer
16965 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
16966 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
16968 /* Search backward from ROW for a row displaying a line that
16969 starts at a minimum position >= last_unchanged_pos_old. */
16970 for (; row
> first_text_row
; --row
)
16972 /* This used to abort, but it can happen.
16973 It is ok to just stop the search instead here. KFS. */
16974 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16977 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
16982 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
16988 /* Make sure that glyph rows in the current matrix of window W
16989 reference the same glyph memory as corresponding rows in the
16990 frame's frame matrix. This function is called after scrolling W's
16991 current matrix on a terminal frame in try_window_id and
16992 try_window_reusing_current_matrix. */
16995 sync_frame_with_window_matrix_rows (struct window
*w
)
16997 struct frame
*f
= XFRAME (w
->frame
);
16998 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
17000 /* Preconditions: W must be a leaf window and full-width. Its frame
17001 must have a frame matrix. */
17002 eassert (NILP (w
->hchild
) && NILP (w
->vchild
));
17003 eassert (WINDOW_FULL_WIDTH_P (w
));
17004 eassert (!FRAME_WINDOW_P (f
));
17006 /* If W is a full-width window, glyph pointers in W's current matrix
17007 have, by definition, to be the same as glyph pointers in the
17008 corresponding frame matrix. Note that frame matrices have no
17009 marginal areas (see build_frame_matrix). */
17010 window_row
= w
->current_matrix
->rows
;
17011 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
17012 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
17013 while (window_row
< window_row_end
)
17015 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
17016 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
17018 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
17019 frame_row
->glyphs
[TEXT_AREA
] = start
;
17020 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
17021 frame_row
->glyphs
[LAST_AREA
] = end
;
17023 /* Disable frame rows whose corresponding window rows have
17024 been disabled in try_window_id. */
17025 if (!window_row
->enabled_p
)
17026 frame_row
->enabled_p
= 0;
17028 ++window_row
, ++frame_row
;
17033 /* Find the glyph row in window W containing CHARPOS. Consider all
17034 rows between START and END (not inclusive). END null means search
17035 all rows to the end of the display area of W. Value is the row
17036 containing CHARPOS or null. */
17039 row_containing_pos (struct window
*w
, ptrdiff_t charpos
,
17040 struct glyph_row
*start
, struct glyph_row
*end
, int dy
)
17042 struct glyph_row
*row
= start
;
17043 struct glyph_row
*best_row
= NULL
;
17044 ptrdiff_t mindif
= BUF_ZV (XBUFFER (w
->buffer
)) + 1;
17047 /* If we happen to start on a header-line, skip that. */
17048 if (row
->mode_line_p
)
17051 if ((end
&& row
>= end
) || !row
->enabled_p
)
17054 last_y
= window_text_bottom_y (w
) - dy
;
17058 /* Give up if we have gone too far. */
17059 if (end
&& row
>= end
)
17061 /* This formerly returned if they were equal.
17062 I think that both quantities are of a "last plus one" type;
17063 if so, when they are equal, the row is within the screen. -- rms. */
17064 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
17067 /* If it is in this row, return this row. */
17068 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
17069 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
17070 /* The end position of a row equals the start
17071 position of the next row. If CHARPOS is there, we
17072 would rather display it in the next line, except
17073 when this line ends in ZV. */
17074 && !row
->ends_at_zv_p
17075 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
17076 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
17080 if (NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
17081 || (!best_row
&& !row
->continued_p
))
17083 /* In bidi-reordered rows, there could be several rows
17084 occluding point, all of them belonging to the same
17085 continued line. We need to find the row which fits
17086 CHARPOS the best. */
17087 for (g
= row
->glyphs
[TEXT_AREA
];
17088 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
17091 if (!STRINGP (g
->object
))
17093 if (g
->charpos
> 0 && eabs (g
->charpos
- charpos
) < mindif
)
17095 mindif
= eabs (g
->charpos
- charpos
);
17097 /* Exact match always wins. */
17104 else if (best_row
&& !row
->continued_p
)
17111 /* Try to redisplay window W by reusing its existing display. W's
17112 current matrix must be up to date when this function is called,
17113 i.e. window_end_valid must not be nil.
17117 1 if display has been updated
17118 0 if otherwise unsuccessful
17119 -1 if redisplay with same window start is known not to succeed
17121 The following steps are performed:
17123 1. Find the last row in the current matrix of W that is not
17124 affected by changes at the start of current_buffer. If no such row
17127 2. Find the first row in W's current matrix that is not affected by
17128 changes at the end of current_buffer. Maybe there is no such row.
17130 3. Display lines beginning with the row + 1 found in step 1 to the
17131 row found in step 2 or, if step 2 didn't find a row, to the end of
17134 4. If cursor is not known to appear on the window, give up.
17136 5. If display stopped at the row found in step 2, scroll the
17137 display and current matrix as needed.
17139 6. Maybe display some lines at the end of W, if we must. This can
17140 happen under various circumstances, like a partially visible line
17141 becoming fully visible, or because newly displayed lines are displayed
17142 in smaller font sizes.
17144 7. Update W's window end information. */
17147 try_window_id (struct window
*w
)
17149 struct frame
*f
= XFRAME (w
->frame
);
17150 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
17151 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
17152 struct glyph_row
*last_unchanged_at_beg_row
;
17153 struct glyph_row
*first_unchanged_at_end_row
;
17154 struct glyph_row
*row
;
17155 struct glyph_row
*bottom_row
;
17158 ptrdiff_t delta
= 0, delta_bytes
= 0, stop_pos
;
17160 struct text_pos start_pos
;
17162 int first_unchanged_at_end_vpos
= 0;
17163 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
17164 struct text_pos start
;
17165 ptrdiff_t first_changed_charpos
, last_changed_charpos
;
17168 if (inhibit_try_window_id
)
17172 /* This is handy for debugging. */
17174 #define GIVE_UP(X) \
17176 fprintf (stderr, "try_window_id give up %d\n", (X)); \
17180 #define GIVE_UP(X) return 0
17183 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
17185 /* Don't use this for mini-windows because these can show
17186 messages and mini-buffers, and we don't handle that here. */
17187 if (MINI_WINDOW_P (w
))
17190 /* This flag is used to prevent redisplay optimizations. */
17191 if (windows_or_buffers_changed
|| cursor_type_changed
)
17194 /* Verify that narrowing has not changed.
17195 Also verify that we were not told to prevent redisplay optimizations.
17196 It would be nice to further
17197 reduce the number of cases where this prevents try_window_id. */
17198 if (current_buffer
->clip_changed
17199 || current_buffer
->prevent_redisplay_optimizations_p
)
17202 /* Window must either use window-based redisplay or be full width. */
17203 if (!FRAME_WINDOW_P (f
)
17204 && (!FRAME_LINE_INS_DEL_OK (f
)
17205 || !WINDOW_FULL_WIDTH_P (w
)))
17208 /* Give up if point is known NOT to appear in W. */
17209 if (PT
< CHARPOS (start
))
17212 /* Another way to prevent redisplay optimizations. */
17213 if (w
->last_modified
== 0)
17216 /* Verify that window is not hscrolled. */
17217 if (w
->hscroll
!= 0)
17220 /* Verify that display wasn't paused. */
17221 if (NILP (w
->window_end_valid
))
17224 /* Can't use this if highlighting a region because a cursor movement
17225 will do more than just set the cursor. */
17226 if (!NILP (Vtransient_mark_mode
)
17227 && !NILP (BVAR (current_buffer
, mark_active
)))
17230 /* Likewise if highlighting trailing whitespace. */
17231 if (!NILP (Vshow_trailing_whitespace
))
17234 /* Likewise if showing a region. */
17235 if (!NILP (w
->region_showing
))
17238 /* Can't use this if overlay arrow position and/or string have
17240 if (overlay_arrows_changed_p ())
17243 /* When word-wrap is on, adding a space to the first word of a
17244 wrapped line can change the wrap position, altering the line
17245 above it. It might be worthwhile to handle this more
17246 intelligently, but for now just redisplay from scratch. */
17247 if (!NILP (BVAR (XBUFFER (w
->buffer
), word_wrap
)))
17250 /* Under bidi reordering, adding or deleting a character in the
17251 beginning of a paragraph, before the first strong directional
17252 character, can change the base direction of the paragraph (unless
17253 the buffer specifies a fixed paragraph direction), which will
17254 require to redisplay the whole paragraph. It might be worthwhile
17255 to find the paragraph limits and widen the range of redisplayed
17256 lines to that, but for now just give up this optimization and
17257 redisplay from scratch. */
17258 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
17259 && NILP (BVAR (XBUFFER (w
->buffer
), bidi_paragraph_direction
)))
17262 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
17263 only if buffer has really changed. The reason is that the gap is
17264 initially at Z for freshly visited files. The code below would
17265 set end_unchanged to 0 in that case. */
17266 if (MODIFF
> SAVE_MODIFF
17267 /* This seems to happen sometimes after saving a buffer. */
17268 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
17270 if (GPT
- BEG
< BEG_UNCHANGED
)
17271 BEG_UNCHANGED
= GPT
- BEG
;
17272 if (Z
- GPT
< END_UNCHANGED
)
17273 END_UNCHANGED
= Z
- GPT
;
17276 /* The position of the first and last character that has been changed. */
17277 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
17278 last_changed_charpos
= Z
- END_UNCHANGED
;
17280 /* If window starts after a line end, and the last change is in
17281 front of that newline, then changes don't affect the display.
17282 This case happens with stealth-fontification. Note that although
17283 the display is unchanged, glyph positions in the matrix have to
17284 be adjusted, of course. */
17285 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
17286 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
17287 && ((last_changed_charpos
< CHARPOS (start
)
17288 && CHARPOS (start
) == BEGV
)
17289 || (last_changed_charpos
< CHARPOS (start
) - 1
17290 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
17292 ptrdiff_t Z_old
, Z_delta
, Z_BYTE_old
, Z_delta_bytes
;
17293 struct glyph_row
*r0
;
17295 /* Compute how many chars/bytes have been added to or removed
17296 from the buffer. */
17297 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
17298 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
17299 Z_delta
= Z
- Z_old
;
17300 Z_delta_bytes
= Z_BYTE
- Z_BYTE_old
;
17302 /* Give up if PT is not in the window. Note that it already has
17303 been checked at the start of try_window_id that PT is not in
17304 front of the window start. */
17305 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + Z_delta
)
17308 /* If window start is unchanged, we can reuse the whole matrix
17309 as is, after adjusting glyph positions. No need to compute
17310 the window end again, since its offset from Z hasn't changed. */
17311 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17312 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + Z_delta
17313 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + Z_delta_bytes
17314 /* PT must not be in a partially visible line. */
17315 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + Z_delta
17316 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17318 /* Adjust positions in the glyph matrix. */
17319 if (Z_delta
|| Z_delta_bytes
)
17321 struct glyph_row
*r1
17322 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17323 increment_matrix_positions (w
->current_matrix
,
17324 MATRIX_ROW_VPOS (r0
, current_matrix
),
17325 MATRIX_ROW_VPOS (r1
, current_matrix
),
17326 Z_delta
, Z_delta_bytes
);
17329 /* Set the cursor. */
17330 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17332 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17339 /* Handle the case that changes are all below what is displayed in
17340 the window, and that PT is in the window. This shortcut cannot
17341 be taken if ZV is visible in the window, and text has been added
17342 there that is visible in the window. */
17343 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
17344 /* ZV is not visible in the window, or there are no
17345 changes at ZV, actually. */
17346 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
17347 || first_changed_charpos
== last_changed_charpos
))
17349 struct glyph_row
*r0
;
17351 /* Give up if PT is not in the window. Note that it already has
17352 been checked at the start of try_window_id that PT is not in
17353 front of the window start. */
17354 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
17357 /* If window start is unchanged, we can reuse the whole matrix
17358 as is, without changing glyph positions since no text has
17359 been added/removed in front of the window end. */
17360 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17361 if (TEXT_POS_EQUAL_P (start
, r0
->minpos
)
17362 /* PT must not be in a partially visible line. */
17363 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
17364 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17366 /* We have to compute the window end anew since text
17367 could have been added/removed after it. */
17368 wset_window_end_pos
17369 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (row
)));
17370 w
->window_end_bytepos
17371 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17373 /* Set the cursor. */
17374 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17376 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17383 /* Give up if window start is in the changed area.
17385 The condition used to read
17387 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
17389 but why that was tested escapes me at the moment. */
17390 if (CHARPOS (start
) >= first_changed_charpos
17391 && CHARPOS (start
) <= last_changed_charpos
)
17394 /* Check that window start agrees with the start of the first glyph
17395 row in its current matrix. Check this after we know the window
17396 start is not in changed text, otherwise positions would not be
17398 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17399 if (!TEXT_POS_EQUAL_P (start
, row
->minpos
))
17402 /* Give up if the window ends in strings. Overlay strings
17403 at the end are difficult to handle, so don't try. */
17404 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
17405 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
17408 /* Compute the position at which we have to start displaying new
17409 lines. Some of the lines at the top of the window might be
17410 reusable because they are not displaying changed text. Find the
17411 last row in W's current matrix not affected by changes at the
17412 start of current_buffer. Value is null if changes start in the
17413 first line of window. */
17414 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
17415 if (last_unchanged_at_beg_row
)
17417 /* Avoid starting to display in the middle of a character, a TAB
17418 for instance. This is easier than to set up the iterator
17419 exactly, and it's not a frequent case, so the additional
17420 effort wouldn't really pay off. */
17421 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
17422 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
17423 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
17424 --last_unchanged_at_beg_row
;
17426 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
17429 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
17431 start_pos
= it
.current
.pos
;
17433 /* Start displaying new lines in the desired matrix at the same
17434 vpos we would use in the current matrix, i.e. below
17435 last_unchanged_at_beg_row. */
17436 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
17438 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17439 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
17441 eassert (it
.hpos
== 0 && it
.current_x
== 0);
17445 /* There are no reusable lines at the start of the window.
17446 Start displaying in the first text line. */
17447 start_display (&it
, w
, start
);
17448 it
.vpos
= it
.first_vpos
;
17449 start_pos
= it
.current
.pos
;
17452 /* Find the first row that is not affected by changes at the end of
17453 the buffer. Value will be null if there is no unchanged row, in
17454 which case we must redisplay to the end of the window. delta
17455 will be set to the value by which buffer positions beginning with
17456 first_unchanged_at_end_row have to be adjusted due to text
17458 first_unchanged_at_end_row
17459 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
17460 IF_DEBUG (debug_delta
= delta
);
17461 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
17463 /* Set stop_pos to the buffer position up to which we will have to
17464 display new lines. If first_unchanged_at_end_row != NULL, this
17465 is the buffer position of the start of the line displayed in that
17466 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
17467 that we don't stop at a buffer position. */
17469 if (first_unchanged_at_end_row
)
17471 eassert (last_unchanged_at_beg_row
== NULL
17472 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
17474 /* If this is a continuation line, move forward to the next one
17475 that isn't. Changes in lines above affect this line.
17476 Caution: this may move first_unchanged_at_end_row to a row
17477 not displaying text. */
17478 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
17479 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17480 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17481 < it
.last_visible_y
))
17482 ++first_unchanged_at_end_row
;
17484 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17485 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17486 >= it
.last_visible_y
))
17487 first_unchanged_at_end_row
= NULL
;
17490 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
17492 first_unchanged_at_end_vpos
17493 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
17494 eassert (stop_pos
>= Z
- END_UNCHANGED
);
17497 else if (last_unchanged_at_beg_row
== NULL
)
17503 /* Either there is no unchanged row at the end, or the one we have
17504 now displays text. This is a necessary condition for the window
17505 end pos calculation at the end of this function. */
17506 eassert (first_unchanged_at_end_row
== NULL
17507 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
17509 debug_last_unchanged_at_beg_vpos
17510 = (last_unchanged_at_beg_row
17511 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
17513 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
17515 #endif /* GLYPH_DEBUG */
17518 /* Display new lines. Set last_text_row to the last new line
17519 displayed which has text on it, i.e. might end up as being the
17520 line where the window_end_vpos is. */
17521 w
->cursor
.vpos
= -1;
17522 last_text_row
= NULL
;
17523 overlay_arrow_seen
= 0;
17524 while (it
.current_y
< it
.last_visible_y
17525 && !fonts_changed_p
17526 && (first_unchanged_at_end_row
== NULL
17527 || IT_CHARPOS (it
) < stop_pos
))
17529 if (display_line (&it
))
17530 last_text_row
= it
.glyph_row
- 1;
17533 if (fonts_changed_p
)
17537 /* Compute differences in buffer positions, y-positions etc. for
17538 lines reused at the bottom of the window. Compute what we can
17540 if (first_unchanged_at_end_row
17541 /* No lines reused because we displayed everything up to the
17542 bottom of the window. */
17543 && it
.current_y
< it
.last_visible_y
)
17546 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
17548 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
17549 run
.current_y
= first_unchanged_at_end_row
->y
;
17550 run
.desired_y
= run
.current_y
+ dy
;
17551 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
17555 delta
= delta_bytes
= dvpos
= dy
17556 = run
.current_y
= run
.desired_y
= run
.height
= 0;
17557 first_unchanged_at_end_row
= NULL
;
17559 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
17562 /* Find the cursor if not already found. We have to decide whether
17563 PT will appear on this window (it sometimes doesn't, but this is
17564 not a very frequent case.) This decision has to be made before
17565 the current matrix is altered. A value of cursor.vpos < 0 means
17566 that PT is either in one of the lines beginning at
17567 first_unchanged_at_end_row or below the window. Don't care for
17568 lines that might be displayed later at the window end; as
17569 mentioned, this is not a frequent case. */
17570 if (w
->cursor
.vpos
< 0)
17572 /* Cursor in unchanged rows at the top? */
17573 if (PT
< CHARPOS (start_pos
)
17574 && last_unchanged_at_beg_row
)
17576 row
= row_containing_pos (w
, PT
,
17577 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
17578 last_unchanged_at_beg_row
+ 1, 0);
17580 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
17583 /* Start from first_unchanged_at_end_row looking for PT. */
17584 else if (first_unchanged_at_end_row
)
17586 row
= row_containing_pos (w
, PT
- delta
,
17587 first_unchanged_at_end_row
, NULL
, 0);
17589 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
17590 delta_bytes
, dy
, dvpos
);
17593 /* Give up if cursor was not found. */
17594 if (w
->cursor
.vpos
< 0)
17596 clear_glyph_matrix (w
->desired_matrix
);
17601 /* Don't let the cursor end in the scroll margins. */
17603 int this_scroll_margin
, cursor_height
;
17605 this_scroll_margin
=
17606 max (0, min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4));
17607 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
17608 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
17610 if ((w
->cursor
.y
< this_scroll_margin
17611 && CHARPOS (start
) > BEGV
)
17612 /* Old redisplay didn't take scroll margin into account at the bottom,
17613 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
17614 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
17615 ? cursor_height
+ this_scroll_margin
17616 : 1)) > it
.last_visible_y
)
17618 w
->cursor
.vpos
= -1;
17619 clear_glyph_matrix (w
->desired_matrix
);
17624 /* Scroll the display. Do it before changing the current matrix so
17625 that xterm.c doesn't get confused about where the cursor glyph is
17627 if (dy
&& run
.height
)
17631 if (FRAME_WINDOW_P (f
))
17633 FRAME_RIF (f
)->update_window_begin_hook (w
);
17634 FRAME_RIF (f
)->clear_window_mouse_face (w
);
17635 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
17636 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
17640 /* Terminal frame. In this case, dvpos gives the number of
17641 lines to scroll by; dvpos < 0 means scroll up. */
17643 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
17644 int from
= WINDOW_TOP_EDGE_LINE (w
) + from_vpos
;
17645 int end
= (WINDOW_TOP_EDGE_LINE (w
)
17646 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
17647 + window_internal_height (w
));
17649 #if defined (HAVE_GPM) || defined (MSDOS)
17650 x_clear_window_mouse_face (w
);
17652 /* Perform the operation on the screen. */
17655 /* Scroll last_unchanged_at_beg_row to the end of the
17656 window down dvpos lines. */
17657 set_terminal_window (f
, end
);
17659 /* On dumb terminals delete dvpos lines at the end
17660 before inserting dvpos empty lines. */
17661 if (!FRAME_SCROLL_REGION_OK (f
))
17662 ins_del_lines (f
, end
- dvpos
, -dvpos
);
17664 /* Insert dvpos empty lines in front of
17665 last_unchanged_at_beg_row. */
17666 ins_del_lines (f
, from
, dvpos
);
17668 else if (dvpos
< 0)
17670 /* Scroll up last_unchanged_at_beg_vpos to the end of
17671 the window to last_unchanged_at_beg_vpos - |dvpos|. */
17672 set_terminal_window (f
, end
);
17674 /* Delete dvpos lines in front of
17675 last_unchanged_at_beg_vpos. ins_del_lines will set
17676 the cursor to the given vpos and emit |dvpos| delete
17678 ins_del_lines (f
, from
+ dvpos
, dvpos
);
17680 /* On a dumb terminal insert dvpos empty lines at the
17682 if (!FRAME_SCROLL_REGION_OK (f
))
17683 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
17686 set_terminal_window (f
, 0);
17692 /* Shift reused rows of the current matrix to the right position.
17693 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
17695 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17696 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
17699 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
17700 bottom_vpos
, dvpos
);
17701 clear_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
17704 else if (dvpos
> 0)
17706 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
17707 bottom_vpos
, dvpos
);
17708 clear_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
17709 first_unchanged_at_end_vpos
+ dvpos
);
17712 /* For frame-based redisplay, make sure that current frame and window
17713 matrix are in sync with respect to glyph memory. */
17714 if (!FRAME_WINDOW_P (f
))
17715 sync_frame_with_window_matrix_rows (w
);
17717 /* Adjust buffer positions in reused rows. */
17718 if (delta
|| delta_bytes
)
17719 increment_matrix_positions (current_matrix
,
17720 first_unchanged_at_end_vpos
+ dvpos
,
17721 bottom_vpos
, delta
, delta_bytes
);
17723 /* Adjust Y positions. */
17725 shift_glyph_matrix (w
, current_matrix
,
17726 first_unchanged_at_end_vpos
+ dvpos
,
17729 if (first_unchanged_at_end_row
)
17731 first_unchanged_at_end_row
+= dvpos
;
17732 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
17733 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
17734 first_unchanged_at_end_row
= NULL
;
17737 /* If scrolling up, there may be some lines to display at the end of
17739 last_text_row_at_end
= NULL
;
17742 /* Scrolling up can leave for example a partially visible line
17743 at the end of the window to be redisplayed. */
17744 /* Set last_row to the glyph row in the current matrix where the
17745 window end line is found. It has been moved up or down in
17746 the matrix by dvpos. */
17747 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
17748 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
17750 /* If last_row is the window end line, it should display text. */
17751 eassert (last_row
->displays_text_p
);
17753 /* If window end line was partially visible before, begin
17754 displaying at that line. Otherwise begin displaying with the
17755 line following it. */
17756 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
17758 init_to_row_start (&it
, w
, last_row
);
17759 it
.vpos
= last_vpos
;
17760 it
.current_y
= last_row
->y
;
17764 init_to_row_end (&it
, w
, last_row
);
17765 it
.vpos
= 1 + last_vpos
;
17766 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
17770 /* We may start in a continuation line. If so, we have to
17771 get the right continuation_lines_width and current_x. */
17772 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
17773 it
.hpos
= it
.current_x
= 0;
17775 /* Display the rest of the lines at the window end. */
17776 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17777 while (it
.current_y
< it
.last_visible_y
17778 && !fonts_changed_p
)
17780 /* Is it always sure that the display agrees with lines in
17781 the current matrix? I don't think so, so we mark rows
17782 displayed invalid in the current matrix by setting their
17783 enabled_p flag to zero. */
17784 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
17785 if (display_line (&it
))
17786 last_text_row_at_end
= it
.glyph_row
- 1;
17790 /* Update window_end_pos and window_end_vpos. */
17791 if (first_unchanged_at_end_row
17792 && !last_text_row_at_end
)
17794 /* Window end line if one of the preserved rows from the current
17795 matrix. Set row to the last row displaying text in current
17796 matrix starting at first_unchanged_at_end_row, after
17798 eassert (first_unchanged_at_end_row
->displays_text_p
);
17799 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
17800 first_unchanged_at_end_row
);
17801 eassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
17803 wset_window_end_pos (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (row
)));
17804 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17805 wset_window_end_vpos
17806 (w
, make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
)));
17807 eassert (w
->window_end_bytepos
>= 0);
17808 IF_DEBUG (debug_method_add (w
, "A"));
17810 else if (last_text_row_at_end
)
17812 wset_window_end_pos
17813 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
)));
17814 w
->window_end_bytepos
17815 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
17816 wset_window_end_vpos
17817 (w
, make_number (MATRIX_ROW_VPOS (last_text_row_at_end
,
17819 eassert (w
->window_end_bytepos
>= 0);
17820 IF_DEBUG (debug_method_add (w
, "B"));
17822 else if (last_text_row
)
17824 /* We have displayed either to the end of the window or at the
17825 end of the window, i.e. the last row with text is to be found
17826 in the desired matrix. */
17827 wset_window_end_pos
17828 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
)));
17829 w
->window_end_bytepos
17830 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
17831 wset_window_end_vpos
17832 (w
, make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
)));
17833 eassert (w
->window_end_bytepos
>= 0);
17835 else if (first_unchanged_at_end_row
== NULL
17836 && last_text_row
== NULL
17837 && last_text_row_at_end
== NULL
)
17839 /* Displayed to end of window, but no line containing text was
17840 displayed. Lines were deleted at the end of the window. */
17841 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
17842 int vpos
= XFASTINT (w
->window_end_vpos
);
17843 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
17844 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
17847 row
== NULL
&& vpos
>= first_vpos
;
17848 --vpos
, --current_row
, --desired_row
)
17850 if (desired_row
->enabled_p
)
17852 if (desired_row
->displays_text_p
)
17855 else if (current_row
->displays_text_p
)
17859 eassert (row
!= NULL
);
17860 wset_window_end_vpos (w
, make_number (vpos
+ 1));
17861 wset_window_end_pos (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (row
)));
17862 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17863 eassert (w
->window_end_bytepos
>= 0);
17864 IF_DEBUG (debug_method_add (w
, "C"));
17869 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
17870 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
17872 /* Record that display has not been completed. */
17873 wset_window_end_valid (w
, Qnil
);
17874 w
->desired_matrix
->no_scrolling_p
= 1;
17882 /***********************************************************************
17883 More debugging support
17884 ***********************************************************************/
17888 void dump_glyph_row (struct glyph_row
*, int, int) EXTERNALLY_VISIBLE
;
17889 void dump_glyph_matrix (struct glyph_matrix
*, int) EXTERNALLY_VISIBLE
;
17890 void dump_glyph (struct glyph_row
*, struct glyph
*, int) EXTERNALLY_VISIBLE
;
17893 /* Dump the contents of glyph matrix MATRIX on stderr.
17895 GLYPHS 0 means don't show glyph contents.
17896 GLYPHS 1 means show glyphs in short form
17897 GLYPHS > 1 means show glyphs in long form. */
17900 dump_glyph_matrix (struct glyph_matrix
*matrix
, int glyphs
)
17903 for (i
= 0; i
< matrix
->nrows
; ++i
)
17904 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
17908 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
17909 the glyph row and area where the glyph comes from. */
17912 dump_glyph (struct glyph_row
*row
, struct glyph
*glyph
, int area
)
17914 if (glyph
->type
== CHAR_GLYPH
)
17917 " %5td %4c %6"pI
"d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
17918 glyph
- row
->glyphs
[TEXT_AREA
],
17921 (BUFFERP (glyph
->object
)
17923 : (STRINGP (glyph
->object
)
17926 glyph
->pixel_width
,
17928 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
17932 glyph
->left_box_line_p
,
17933 glyph
->right_box_line_p
);
17935 else if (glyph
->type
== STRETCH_GLYPH
)
17938 " %5td %4c %6"pI
"d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
17939 glyph
- row
->glyphs
[TEXT_AREA
],
17942 (BUFFERP (glyph
->object
)
17944 : (STRINGP (glyph
->object
)
17947 glyph
->pixel_width
,
17951 glyph
->left_box_line_p
,
17952 glyph
->right_box_line_p
);
17954 else if (glyph
->type
== IMAGE_GLYPH
)
17957 " %5td %4c %6"pI
"d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
17958 glyph
- row
->glyphs
[TEXT_AREA
],
17961 (BUFFERP (glyph
->object
)
17963 : (STRINGP (glyph
->object
)
17966 glyph
->pixel_width
,
17970 glyph
->left_box_line_p
,
17971 glyph
->right_box_line_p
);
17973 else if (glyph
->type
== COMPOSITE_GLYPH
)
17976 " %5td %4c %6"pI
"d %c %3d 0x%05x",
17977 glyph
- row
->glyphs
[TEXT_AREA
],
17980 (BUFFERP (glyph
->object
)
17982 : (STRINGP (glyph
->object
)
17985 glyph
->pixel_width
,
17987 if (glyph
->u
.cmp
.automatic
)
17990 glyph
->slice
.cmp
.from
, glyph
->slice
.cmp
.to
);
17991 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
17993 glyph
->left_box_line_p
,
17994 glyph
->right_box_line_p
);
17999 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
18000 GLYPHS 0 means don't show glyph contents.
18001 GLYPHS 1 means show glyphs in short form
18002 GLYPHS > 1 means show glyphs in long form. */
18005 dump_glyph_row (struct glyph_row
*row
, int vpos
, int glyphs
)
18009 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
18010 fprintf (stderr
, "======================================================================\n");
18012 fprintf (stderr
, "%3d %5"pI
"d %5"pI
"d %4d %1.1d%1.1d%1.1d%1.1d\
18013 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
18015 MATRIX_ROW_START_CHARPOS (row
),
18016 MATRIX_ROW_END_CHARPOS (row
),
18017 row
->used
[TEXT_AREA
],
18018 row
->contains_overlapping_glyphs_p
,
18020 row
->truncated_on_left_p
,
18021 row
->truncated_on_right_p
,
18023 MATRIX_ROW_CONTINUATION_LINE_P (row
),
18024 row
->displays_text_p
,
18027 row
->ends_in_middle_of_char_p
,
18028 row
->starts_in_middle_of_char_p
,
18034 row
->visible_height
,
18037 fprintf (stderr
, "%9"pD
"d %5"pD
"d\t%5d\n", row
->start
.overlay_string_index
,
18038 row
->end
.overlay_string_index
,
18039 row
->continuation_lines_width
);
18040 fprintf (stderr
, "%9"pI
"d %5"pI
"d\n",
18041 CHARPOS (row
->start
.string_pos
),
18042 CHARPOS (row
->end
.string_pos
));
18043 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
18044 row
->end
.dpvec_index
);
18051 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18053 struct glyph
*glyph
= row
->glyphs
[area
];
18054 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
18056 /* Glyph for a line end in text. */
18057 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
18060 if (glyph
< glyph_end
)
18061 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
18063 for (; glyph
< glyph_end
; ++glyph
)
18064 dump_glyph (row
, glyph
, area
);
18067 else if (glyphs
== 1)
18071 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18073 char *s
= alloca (row
->used
[area
] + 1);
18076 for (i
= 0; i
< row
->used
[area
]; ++i
)
18078 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
18079 if (glyph
->type
== CHAR_GLYPH
18080 && glyph
->u
.ch
< 0x80
18081 && glyph
->u
.ch
>= ' ')
18082 s
[i
] = glyph
->u
.ch
;
18088 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
18094 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
18095 Sdump_glyph_matrix
, 0, 1, "p",
18096 doc
: /* Dump the current matrix of the selected window to stderr.
18097 Shows contents of glyph row structures. With non-nil
18098 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
18099 glyphs in short form, otherwise show glyphs in long form. */)
18100 (Lisp_Object glyphs
)
18102 struct window
*w
= XWINDOW (selected_window
);
18103 struct buffer
*buffer
= XBUFFER (w
->buffer
);
18105 fprintf (stderr
, "PT = %"pI
"d, BEGV = %"pI
"d. ZV = %"pI
"d\n",
18106 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
18107 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
18108 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
18109 fprintf (stderr
, "=============================================\n");
18110 dump_glyph_matrix (w
->current_matrix
,
18111 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 0);
18116 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
18117 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
18120 struct frame
*f
= XFRAME (selected_frame
);
18121 dump_glyph_matrix (f
->current_matrix
, 1);
18126 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
18127 doc
: /* Dump glyph row ROW to stderr.
18128 GLYPH 0 means don't dump glyphs.
18129 GLYPH 1 means dump glyphs in short form.
18130 GLYPH > 1 or omitted means dump glyphs in long form. */)
18131 (Lisp_Object row
, Lisp_Object glyphs
)
18133 struct glyph_matrix
*matrix
;
18136 CHECK_NUMBER (row
);
18137 matrix
= XWINDOW (selected_window
)->current_matrix
;
18139 if (vpos
>= 0 && vpos
< matrix
->nrows
)
18140 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
18142 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18147 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
18148 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
18149 GLYPH 0 means don't dump glyphs.
18150 GLYPH 1 means dump glyphs in short form.
18151 GLYPH > 1 or omitted means dump glyphs in long form. */)
18152 (Lisp_Object row
, Lisp_Object glyphs
)
18154 struct frame
*sf
= SELECTED_FRAME ();
18155 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
18158 CHECK_NUMBER (row
);
18160 if (vpos
>= 0 && vpos
< m
->nrows
)
18161 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
18162 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18167 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
18168 doc
: /* Toggle tracing of redisplay.
18169 With ARG, turn tracing on if and only if ARG is positive. */)
18173 trace_redisplay_p
= !trace_redisplay_p
;
18176 arg
= Fprefix_numeric_value (arg
);
18177 trace_redisplay_p
= XINT (arg
) > 0;
18184 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
18185 doc
: /* Like `format', but print result to stderr.
18186 usage: (trace-to-stderr STRING &rest OBJECTS) */)
18187 (ptrdiff_t nargs
, Lisp_Object
*args
)
18189 Lisp_Object s
= Fformat (nargs
, args
);
18190 fprintf (stderr
, "%s", SDATA (s
));
18194 #endif /* GLYPH_DEBUG */
18198 /***********************************************************************
18199 Building Desired Matrix Rows
18200 ***********************************************************************/
18202 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
18203 Used for non-window-redisplay windows, and for windows w/o left fringe. */
18205 static struct glyph_row
*
18206 get_overlay_arrow_glyph_row (struct window
*w
, Lisp_Object overlay_arrow_string
)
18208 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18209 struct buffer
*buffer
= XBUFFER (w
->buffer
);
18210 struct buffer
*old
= current_buffer
;
18211 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
18212 int arrow_len
= SCHARS (overlay_arrow_string
);
18213 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
18214 const unsigned char *p
;
18217 int n_glyphs_before
;
18219 set_buffer_temp (buffer
);
18220 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
18221 it
.glyph_row
->used
[TEXT_AREA
] = 0;
18222 SET_TEXT_POS (it
.position
, 0, 0);
18224 multibyte_p
= !NILP (BVAR (buffer
, enable_multibyte_characters
));
18226 while (p
< arrow_end
)
18228 Lisp_Object face
, ilisp
;
18230 /* Get the next character. */
18232 it
.c
= it
.char_to_display
= string_char_and_length (p
, &it
.len
);
18235 it
.c
= it
.char_to_display
= *p
, it
.len
= 1;
18236 if (! ASCII_CHAR_P (it
.c
))
18237 it
.char_to_display
= BYTE8_TO_CHAR (it
.c
);
18241 /* Get its face. */
18242 ilisp
= make_number (p
- arrow_string
);
18243 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
18244 it
.face_id
= compute_char_face (f
, it
.char_to_display
, face
);
18246 /* Compute its width, get its glyphs. */
18247 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
18248 SET_TEXT_POS (it
.position
, -1, -1);
18249 PRODUCE_GLYPHS (&it
);
18251 /* If this character doesn't fit any more in the line, we have
18252 to remove some glyphs. */
18253 if (it
.current_x
> it
.last_visible_x
)
18255 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
18260 set_buffer_temp (old
);
18261 return it
.glyph_row
;
18265 /* Insert truncation glyphs at the start of IT->glyph_row. Which
18266 glyphs to insert is determined by produce_special_glyphs. */
18269 insert_left_trunc_glyphs (struct it
*it
)
18271 struct it truncate_it
;
18272 struct glyph
*from
, *end
, *to
, *toend
;
18274 eassert (!FRAME_WINDOW_P (it
->f
)
18275 || (!it
->glyph_row
->reversed_p
18276 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0)
18277 || (it
->glyph_row
->reversed_p
18278 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0));
18280 /* Get the truncation glyphs. */
18282 truncate_it
.current_x
= 0;
18283 truncate_it
.face_id
= DEFAULT_FACE_ID
;
18284 truncate_it
.glyph_row
= &scratch_glyph_row
;
18285 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
18286 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
18287 truncate_it
.object
= make_number (0);
18288 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
18290 /* Overwrite glyphs from IT with truncation glyphs. */
18291 if (!it
->glyph_row
->reversed_p
)
18293 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
18295 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18296 end
= from
+ tused
;
18297 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18298 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
18299 if (FRAME_WINDOW_P (it
->f
))
18301 /* On GUI frames, when variable-size fonts are displayed,
18302 the truncation glyphs may need more pixels than the row's
18303 glyphs they overwrite. We overwrite more glyphs to free
18304 enough screen real estate, and enlarge the stretch glyph
18305 on the right (see display_line), if there is one, to
18306 preserve the screen position of the truncation glyphs on
18309 struct glyph
*g
= to
;
18312 /* The first glyph could be partially visible, in which case
18313 it->glyph_row->x will be negative. But we want the left
18314 truncation glyphs to be aligned at the left margin of the
18315 window, so we override the x coordinate at which the row
18317 it
->glyph_row
->x
= 0;
18318 while (g
< toend
&& w
< it
->truncation_pixel_width
)
18320 w
+= g
->pixel_width
;
18323 if (g
- to
- tused
> 0)
18325 memmove (to
+ tused
, g
, (toend
- g
) * sizeof(*g
));
18326 it
->glyph_row
->used
[TEXT_AREA
] -= g
- to
- tused
;
18328 used
= it
->glyph_row
->used
[TEXT_AREA
];
18329 if (it
->glyph_row
->truncated_on_right_p
18330 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0
18331 && it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].type
18334 int extra
= w
- it
->truncation_pixel_width
;
18336 it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].pixel_width
+= extra
;
18343 /* There may be padding glyphs left over. Overwrite them too. */
18344 if (!FRAME_WINDOW_P (it
->f
))
18346 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
18348 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18355 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
18359 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
18361 /* In R2L rows, overwrite the last (rightmost) glyphs, and do
18362 that back to front. */
18363 end
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18364 from
= end
+ truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18365 toend
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18366 to
= toend
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18367 if (FRAME_WINDOW_P (it
->f
))
18370 struct glyph
*g
= to
;
18372 while (g
>= toend
&& w
< it
->truncation_pixel_width
)
18374 w
+= g
->pixel_width
;
18377 if (to
- g
- tused
> 0)
18379 if (it
->glyph_row
->truncated_on_right_p
18380 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0
18381 && it
->glyph_row
->glyphs
[TEXT_AREA
][1].type
== STRETCH_GLYPH
)
18383 int extra
= w
- it
->truncation_pixel_width
;
18385 it
->glyph_row
->glyphs
[TEXT_AREA
][1].pixel_width
+= extra
;
18389 while (from
>= end
&& to
>= toend
)
18391 if (!FRAME_WINDOW_P (it
->f
))
18393 while (to
>= toend
&& CHAR_GLYPH_PADDING_P (*to
))
18396 truncate_it
.glyph_row
->glyphs
[TEXT_AREA
]
18397 + truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18398 while (from
>= end
&& to
>= toend
)
18404 /* Need to free some room before prepending additional
18406 int move_by
= from
- end
+ 1;
18407 struct glyph
*g0
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18408 struct glyph
*g
= g0
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18410 for ( ; g
>= g0
; g
--)
18412 while (from
>= end
)
18414 it
->glyph_row
->used
[TEXT_AREA
] += move_by
;
18419 /* Compute the hash code for ROW. */
18421 row_hash (struct glyph_row
*row
)
18424 unsigned hashval
= 0;
18426 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18427 for (k
= 0; k
< row
->used
[area
]; ++k
)
18428 hashval
= ((((hashval
<< 4) + (hashval
>> 24)) & 0x0fffffff)
18429 + row
->glyphs
[area
][k
].u
.val
18430 + row
->glyphs
[area
][k
].face_id
18431 + row
->glyphs
[area
][k
].padding_p
18432 + (row
->glyphs
[area
][k
].type
<< 2));
18437 /* Compute the pixel height and width of IT->glyph_row.
18439 Most of the time, ascent and height of a display line will be equal
18440 to the max_ascent and max_height values of the display iterator
18441 structure. This is not the case if
18443 1. We hit ZV without displaying anything. In this case, max_ascent
18444 and max_height will be zero.
18446 2. We have some glyphs that don't contribute to the line height.
18447 (The glyph row flag contributes_to_line_height_p is for future
18448 pixmap extensions).
18450 The first case is easily covered by using default values because in
18451 these cases, the line height does not really matter, except that it
18452 must not be zero. */
18455 compute_line_metrics (struct it
*it
)
18457 struct glyph_row
*row
= it
->glyph_row
;
18459 if (FRAME_WINDOW_P (it
->f
))
18461 int i
, min_y
, max_y
;
18463 /* The line may consist of one space only, that was added to
18464 place the cursor on it. If so, the row's height hasn't been
18466 if (row
->height
== 0)
18468 if (it
->max_ascent
+ it
->max_descent
== 0)
18469 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
18470 row
->ascent
= it
->max_ascent
;
18471 row
->height
= it
->max_ascent
+ it
->max_descent
;
18472 row
->phys_ascent
= it
->max_phys_ascent
;
18473 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18474 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18477 /* Compute the width of this line. */
18478 row
->pixel_width
= row
->x
;
18479 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
18480 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
18482 eassert (row
->pixel_width
>= 0);
18483 eassert (row
->ascent
>= 0 && row
->height
> 0);
18485 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
18486 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
18488 /* If first line's physical ascent is larger than its logical
18489 ascent, use the physical ascent, and make the row taller.
18490 This makes accented characters fully visible. */
18491 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
18492 && row
->phys_ascent
> row
->ascent
)
18494 row
->height
+= row
->phys_ascent
- row
->ascent
;
18495 row
->ascent
= row
->phys_ascent
;
18498 /* Compute how much of the line is visible. */
18499 row
->visible_height
= row
->height
;
18501 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
18502 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
18504 if (row
->y
< min_y
)
18505 row
->visible_height
-= min_y
- row
->y
;
18506 if (row
->y
+ row
->height
> max_y
)
18507 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
18511 row
->pixel_width
= row
->used
[TEXT_AREA
];
18512 if (row
->continued_p
)
18513 row
->pixel_width
-= it
->continuation_pixel_width
;
18514 else if (row
->truncated_on_right_p
)
18515 row
->pixel_width
-= it
->truncation_pixel_width
;
18516 row
->ascent
= row
->phys_ascent
= 0;
18517 row
->height
= row
->phys_height
= row
->visible_height
= 1;
18518 row
->extra_line_spacing
= 0;
18521 /* Compute a hash code for this row. */
18522 row
->hash
= row_hash (row
);
18524 it
->max_ascent
= it
->max_descent
= 0;
18525 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
18529 /* Append one space to the glyph row of iterator IT if doing a
18530 window-based redisplay. The space has the same face as
18531 IT->face_id. Value is non-zero if a space was added.
18533 This function is called to make sure that there is always one glyph
18534 at the end of a glyph row that the cursor can be set on under
18535 window-systems. (If there weren't such a glyph we would not know
18536 how wide and tall a box cursor should be displayed).
18538 At the same time this space let's a nicely handle clearing to the
18539 end of the line if the row ends in italic text. */
18542 append_space_for_newline (struct it
*it
, int default_face_p
)
18544 if (FRAME_WINDOW_P (it
->f
))
18546 int n
= it
->glyph_row
->used
[TEXT_AREA
];
18548 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
18549 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
18551 /* Save some values that must not be changed.
18552 Must save IT->c and IT->len because otherwise
18553 ITERATOR_AT_END_P wouldn't work anymore after
18554 append_space_for_newline has been called. */
18555 enum display_element_type saved_what
= it
->what
;
18556 int saved_c
= it
->c
, saved_len
= it
->len
;
18557 int saved_char_to_display
= it
->char_to_display
;
18558 int saved_x
= it
->current_x
;
18559 int saved_face_id
= it
->face_id
;
18560 struct text_pos saved_pos
;
18561 Lisp_Object saved_object
;
18564 saved_object
= it
->object
;
18565 saved_pos
= it
->position
;
18567 it
->what
= IT_CHARACTER
;
18568 memset (&it
->position
, 0, sizeof it
->position
);
18569 it
->object
= make_number (0);
18570 it
->c
= it
->char_to_display
= ' ';
18573 /* If the default face was remapped, be sure to use the
18574 remapped face for the appended newline. */
18575 if (default_face_p
)
18576 it
->face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
18577 else if (it
->face_before_selective_p
)
18578 it
->face_id
= it
->saved_face_id
;
18579 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18580 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
18582 PRODUCE_GLYPHS (it
);
18584 it
->override_ascent
= -1;
18585 it
->constrain_row_ascent_descent_p
= 0;
18586 it
->current_x
= saved_x
;
18587 it
->object
= saved_object
;
18588 it
->position
= saved_pos
;
18589 it
->what
= saved_what
;
18590 it
->face_id
= saved_face_id
;
18591 it
->len
= saved_len
;
18593 it
->char_to_display
= saved_char_to_display
;
18602 /* Extend the face of the last glyph in the text area of IT->glyph_row
18603 to the end of the display line. Called from display_line. If the
18604 glyph row is empty, add a space glyph to it so that we know the
18605 face to draw. Set the glyph row flag fill_line_p. If the glyph
18606 row is R2L, prepend a stretch glyph to cover the empty space to the
18607 left of the leftmost glyph. */
18610 extend_face_to_end_of_line (struct it
*it
)
18612 struct face
*face
, *default_face
;
18613 struct frame
*f
= it
->f
;
18615 /* If line is already filled, do nothing. Non window-system frames
18616 get a grace of one more ``pixel'' because their characters are
18617 1-``pixel'' wide, so they hit the equality too early. This grace
18618 is needed only for R2L rows that are not continued, to produce
18619 one extra blank where we could display the cursor. */
18620 if (it
->current_x
>= it
->last_visible_x
18621 + (!FRAME_WINDOW_P (f
)
18622 && it
->glyph_row
->reversed_p
18623 && !it
->glyph_row
->continued_p
))
18626 /* The default face, possibly remapped. */
18627 default_face
= FACE_FROM_ID (f
, lookup_basic_face (f
, DEFAULT_FACE_ID
));
18629 /* Face extension extends the background and box of IT->face_id
18630 to the end of the line. If the background equals the background
18631 of the frame, we don't have to do anything. */
18632 if (it
->face_before_selective_p
)
18633 face
= FACE_FROM_ID (f
, it
->saved_face_id
);
18635 face
= FACE_FROM_ID (f
, it
->face_id
);
18637 if (FRAME_WINDOW_P (f
)
18638 && it
->glyph_row
->displays_text_p
18639 && face
->box
== FACE_NO_BOX
18640 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
18642 && !it
->glyph_row
->reversed_p
)
18645 /* Set the glyph row flag indicating that the face of the last glyph
18646 in the text area has to be drawn to the end of the text area. */
18647 it
->glyph_row
->fill_line_p
= 1;
18649 /* If current character of IT is not ASCII, make sure we have the
18650 ASCII face. This will be automatically undone the next time
18651 get_next_display_element returns a multibyte character. Note
18652 that the character will always be single byte in unibyte
18654 if (!ASCII_CHAR_P (it
->c
))
18656 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
18659 if (FRAME_WINDOW_P (f
))
18661 /* If the row is empty, add a space with the current face of IT,
18662 so that we know which face to draw. */
18663 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
18665 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
18666 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= face
->id
;
18667 it
->glyph_row
->used
[TEXT_AREA
] = 1;
18669 #ifdef HAVE_WINDOW_SYSTEM
18670 if (it
->glyph_row
->reversed_p
)
18672 /* Prepend a stretch glyph to the row, such that the
18673 rightmost glyph will be drawn flushed all the way to the
18674 right margin of the window. The stretch glyph that will
18675 occupy the empty space, if any, to the left of the
18677 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (f
);
18678 struct glyph
*row_start
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18679 struct glyph
*row_end
= row_start
+ it
->glyph_row
->used
[TEXT_AREA
];
18681 int row_width
, stretch_ascent
, stretch_width
;
18682 struct text_pos saved_pos
;
18683 int saved_face_id
, saved_avoid_cursor
;
18685 for (row_width
= 0, g
= row_start
; g
< row_end
; g
++)
18686 row_width
+= g
->pixel_width
;
18687 stretch_width
= window_box_width (it
->w
, TEXT_AREA
) - row_width
;
18688 if (stretch_width
> 0)
18691 (((it
->ascent
+ it
->descent
)
18692 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
18693 saved_pos
= it
->position
;
18694 memset (&it
->position
, 0, sizeof it
->position
);
18695 saved_avoid_cursor
= it
->avoid_cursor_p
;
18696 it
->avoid_cursor_p
= 1;
18697 saved_face_id
= it
->face_id
;
18698 /* The last row's stretch glyph should get the default
18699 face, to avoid painting the rest of the window with
18700 the region face, if the region ends at ZV. */
18701 if (it
->glyph_row
->ends_at_zv_p
)
18702 it
->face_id
= default_face
->id
;
18704 it
->face_id
= face
->id
;
18705 append_stretch_glyph (it
, make_number (0), stretch_width
,
18706 it
->ascent
+ it
->descent
, stretch_ascent
);
18707 it
->position
= saved_pos
;
18708 it
->avoid_cursor_p
= saved_avoid_cursor
;
18709 it
->face_id
= saved_face_id
;
18712 #endif /* HAVE_WINDOW_SYSTEM */
18716 /* Save some values that must not be changed. */
18717 int saved_x
= it
->current_x
;
18718 struct text_pos saved_pos
;
18719 Lisp_Object saved_object
;
18720 enum display_element_type saved_what
= it
->what
;
18721 int saved_face_id
= it
->face_id
;
18723 saved_object
= it
->object
;
18724 saved_pos
= it
->position
;
18726 it
->what
= IT_CHARACTER
;
18727 memset (&it
->position
, 0, sizeof it
->position
);
18728 it
->object
= make_number (0);
18729 it
->c
= it
->char_to_display
= ' ';
18731 /* The last row's blank glyphs should get the default face, to
18732 avoid painting the rest of the window with the region face,
18733 if the region ends at ZV. */
18734 if (it
->glyph_row
->ends_at_zv_p
)
18735 it
->face_id
= default_face
->id
;
18737 it
->face_id
= face
->id
;
18739 PRODUCE_GLYPHS (it
);
18741 while (it
->current_x
<= it
->last_visible_x
)
18742 PRODUCE_GLYPHS (it
);
18744 /* Don't count these blanks really. It would let us insert a left
18745 truncation glyph below and make us set the cursor on them, maybe. */
18746 it
->current_x
= saved_x
;
18747 it
->object
= saved_object
;
18748 it
->position
= saved_pos
;
18749 it
->what
= saved_what
;
18750 it
->face_id
= saved_face_id
;
18755 /* Value is non-zero if text starting at CHARPOS in current_buffer is
18756 trailing whitespace. */
18759 trailing_whitespace_p (ptrdiff_t charpos
)
18761 ptrdiff_t bytepos
= CHAR_TO_BYTE (charpos
);
18764 while (bytepos
< ZV_BYTE
18765 && (c
= FETCH_CHAR (bytepos
),
18766 c
== ' ' || c
== '\t'))
18769 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
18771 if (bytepos
!= PT_BYTE
)
18778 /* Highlight trailing whitespace, if any, in ROW. */
18781 highlight_trailing_whitespace (struct frame
*f
, struct glyph_row
*row
)
18783 int used
= row
->used
[TEXT_AREA
];
18787 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
18788 struct glyph
*glyph
= start
+ used
- 1;
18790 if (row
->reversed_p
)
18792 /* Right-to-left rows need to be processed in the opposite
18793 direction, so swap the edge pointers. */
18795 start
= row
->glyphs
[TEXT_AREA
] + used
- 1;
18798 /* Skip over glyphs inserted to display the cursor at the
18799 end of a line, for extending the face of the last glyph
18800 to the end of the line on terminals, and for truncation
18801 and continuation glyphs. */
18802 if (!row
->reversed_p
)
18804 while (glyph
>= start
18805 && glyph
->type
== CHAR_GLYPH
18806 && INTEGERP (glyph
->object
))
18811 while (glyph
<= start
18812 && glyph
->type
== CHAR_GLYPH
18813 && INTEGERP (glyph
->object
))
18817 /* If last glyph is a space or stretch, and it's trailing
18818 whitespace, set the face of all trailing whitespace glyphs in
18819 IT->glyph_row to `trailing-whitespace'. */
18820 if ((row
->reversed_p
? glyph
<= start
: glyph
>= start
)
18821 && BUFFERP (glyph
->object
)
18822 && (glyph
->type
== STRETCH_GLYPH
18823 || (glyph
->type
== CHAR_GLYPH
18824 && glyph
->u
.ch
== ' '))
18825 && trailing_whitespace_p (glyph
->charpos
))
18827 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
18831 if (!row
->reversed_p
)
18833 while (glyph
>= start
18834 && BUFFERP (glyph
->object
)
18835 && (glyph
->type
== STRETCH_GLYPH
18836 || (glyph
->type
== CHAR_GLYPH
18837 && glyph
->u
.ch
== ' ')))
18838 (glyph
--)->face_id
= face_id
;
18842 while (glyph
<= start
18843 && BUFFERP (glyph
->object
)
18844 && (glyph
->type
== STRETCH_GLYPH
18845 || (glyph
->type
== CHAR_GLYPH
18846 && glyph
->u
.ch
== ' ')))
18847 (glyph
++)->face_id
= face_id
;
18854 /* Value is non-zero if glyph row ROW should be
18855 used to hold the cursor. */
18858 cursor_row_p (struct glyph_row
*row
)
18862 if (PT
== CHARPOS (row
->end
.pos
)
18863 || PT
== MATRIX_ROW_END_CHARPOS (row
))
18865 /* Suppose the row ends on a string.
18866 Unless the row is continued, that means it ends on a newline
18867 in the string. If it's anything other than a display string
18868 (e.g., a before-string from an overlay), we don't want the
18869 cursor there. (This heuristic seems to give the optimal
18870 behavior for the various types of multi-line strings.)
18871 One exception: if the string has `cursor' property on one of
18872 its characters, we _do_ want the cursor there. */
18873 if (CHARPOS (row
->end
.string_pos
) >= 0)
18875 if (row
->continued_p
)
18879 /* Check for `display' property. */
18880 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
18881 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
18882 struct glyph
*glyph
;
18885 for (glyph
= end
; glyph
>= beg
; --glyph
)
18886 if (STRINGP (glyph
->object
))
18889 = Fget_char_property (make_number (PT
),
18893 && display_prop_string_p (prop
, glyph
->object
));
18894 /* If there's a `cursor' property on one of the
18895 string's characters, this row is a cursor row,
18896 even though this is not a display string. */
18899 Lisp_Object s
= glyph
->object
;
18901 for ( ; glyph
>= beg
&& EQ (glyph
->object
, s
); --glyph
)
18903 ptrdiff_t gpos
= glyph
->charpos
;
18905 if (!NILP (Fget_char_property (make_number (gpos
),
18917 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
18919 /* If the row ends in middle of a real character,
18920 and the line is continued, we want the cursor here.
18921 That's because CHARPOS (ROW->end.pos) would equal
18922 PT if PT is before the character. */
18923 if (!row
->ends_in_ellipsis_p
)
18924 result
= row
->continued_p
;
18926 /* If the row ends in an ellipsis, then
18927 CHARPOS (ROW->end.pos) will equal point after the
18928 invisible text. We want that position to be displayed
18929 after the ellipsis. */
18932 /* If the row ends at ZV, display the cursor at the end of that
18933 row instead of at the start of the row below. */
18934 else if (row
->ends_at_zv_p
)
18945 /* Push the property PROP so that it will be rendered at the current
18946 position in IT. Return 1 if PROP was successfully pushed, 0
18947 otherwise. Called from handle_line_prefix to handle the
18948 `line-prefix' and `wrap-prefix' properties. */
18951 push_prefix_prop (struct it
*it
, Lisp_Object prop
)
18953 struct text_pos pos
=
18954 STRINGP (it
->string
) ? it
->current
.string_pos
: it
->current
.pos
;
18956 eassert (it
->method
== GET_FROM_BUFFER
18957 || it
->method
== GET_FROM_DISPLAY_VECTOR
18958 || it
->method
== GET_FROM_STRING
);
18960 /* We need to save the current buffer/string position, so it will be
18961 restored by pop_it, because iterate_out_of_display_property
18962 depends on that being set correctly, but some situations leave
18963 it->position not yet set when this function is called. */
18964 push_it (it
, &pos
);
18966 if (STRINGP (prop
))
18968 if (SCHARS (prop
) == 0)
18975 it
->string_from_prefix_prop_p
= 1;
18976 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
18977 it
->current
.overlay_string_index
= -1;
18978 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
18979 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
18980 it
->method
= GET_FROM_STRING
;
18981 it
->stop_charpos
= 0;
18983 it
->base_level_stop
= 0;
18985 /* Force paragraph direction to be that of the parent
18987 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
18988 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
18990 it
->paragraph_embedding
= L2R
;
18992 /* Set up the bidi iterator for this display string. */
18995 it
->bidi_it
.string
.lstring
= it
->string
;
18996 it
->bidi_it
.string
.s
= NULL
;
18997 it
->bidi_it
.string
.schars
= it
->end_charpos
;
18998 it
->bidi_it
.string
.bufpos
= IT_CHARPOS (*it
);
18999 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
19000 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
19001 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
19004 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
19006 it
->method
= GET_FROM_STRETCH
;
19009 #ifdef HAVE_WINDOW_SYSTEM
19010 else if (IMAGEP (prop
))
19012 it
->what
= IT_IMAGE
;
19013 it
->image_id
= lookup_image (it
->f
, prop
);
19014 it
->method
= GET_FROM_IMAGE
;
19016 #endif /* HAVE_WINDOW_SYSTEM */
19019 pop_it (it
); /* bogus display property, give up */
19026 /* Return the character-property PROP at the current position in IT. */
19029 get_it_property (struct it
*it
, Lisp_Object prop
)
19031 Lisp_Object position
;
19033 if (STRINGP (it
->object
))
19034 position
= make_number (IT_STRING_CHARPOS (*it
));
19035 else if (BUFFERP (it
->object
))
19036 position
= make_number (IT_CHARPOS (*it
));
19040 return Fget_char_property (position
, prop
, it
->object
);
19043 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
19046 handle_line_prefix (struct it
*it
)
19048 Lisp_Object prefix
;
19050 if (it
->continuation_lines_width
> 0)
19052 prefix
= get_it_property (it
, Qwrap_prefix
);
19054 prefix
= Vwrap_prefix
;
19058 prefix
= get_it_property (it
, Qline_prefix
);
19060 prefix
= Vline_prefix
;
19062 if (! NILP (prefix
) && push_prefix_prop (it
, prefix
))
19064 /* If the prefix is wider than the window, and we try to wrap
19065 it, it would acquire its own wrap prefix, and so on till the
19066 iterator stack overflows. So, don't wrap the prefix. */
19067 it
->line_wrap
= TRUNCATE
;
19068 it
->avoid_cursor_p
= 1;
19074 /* Remove N glyphs at the start of a reversed IT->glyph_row. Called
19075 only for R2L lines from display_line and display_string, when they
19076 decide that too many glyphs were produced by PRODUCE_GLYPHS, and
19077 the line/string needs to be continued on the next glyph row. */
19079 unproduce_glyphs (struct it
*it
, int n
)
19081 struct glyph
*glyph
, *end
;
19083 eassert (it
->glyph_row
);
19084 eassert (it
->glyph_row
->reversed_p
);
19085 eassert (it
->area
== TEXT_AREA
);
19086 eassert (n
<= it
->glyph_row
->used
[TEXT_AREA
]);
19088 if (n
> it
->glyph_row
->used
[TEXT_AREA
])
19089 n
= it
->glyph_row
->used
[TEXT_AREA
];
19090 glyph
= it
->glyph_row
->glyphs
[TEXT_AREA
] + n
;
19091 end
= it
->glyph_row
->glyphs
[TEXT_AREA
] + it
->glyph_row
->used
[TEXT_AREA
];
19092 for ( ; glyph
< end
; glyph
++)
19093 glyph
[-n
] = *glyph
;
19096 /* Find the positions in a bidi-reordered ROW to serve as ROW->minpos
19097 and ROW->maxpos. */
19099 find_row_edges (struct it
*it
, struct glyph_row
*row
,
19100 ptrdiff_t min_pos
, ptrdiff_t min_bpos
,
19101 ptrdiff_t max_pos
, ptrdiff_t max_bpos
)
19103 /* FIXME: Revisit this when glyph ``spilling'' in continuation
19104 lines' rows is implemented for bidi-reordered rows. */
19106 /* ROW->minpos is the value of min_pos, the minimal buffer position
19107 we have in ROW, or ROW->start.pos if that is smaller. */
19108 if (min_pos
<= ZV
&& min_pos
< row
->start
.pos
.charpos
)
19109 SET_TEXT_POS (row
->minpos
, min_pos
, min_bpos
);
19111 /* We didn't find buffer positions smaller than ROW->start, or
19112 didn't find _any_ valid buffer positions in any of the glyphs,
19113 so we must trust the iterator's computed positions. */
19114 row
->minpos
= row
->start
.pos
;
19117 max_pos
= CHARPOS (it
->current
.pos
);
19118 max_bpos
= BYTEPOS (it
->current
.pos
);
19121 /* Here are the various use-cases for ending the row, and the
19122 corresponding values for ROW->maxpos:
19124 Line ends in a newline from buffer eol_pos + 1
19125 Line is continued from buffer max_pos + 1
19126 Line is truncated on right it->current.pos
19127 Line ends in a newline from string max_pos + 1(*)
19128 (*) + 1 only when line ends in a forward scan
19129 Line is continued from string max_pos
19130 Line is continued from display vector max_pos
19131 Line is entirely from a string min_pos == max_pos
19132 Line is entirely from a display vector min_pos == max_pos
19133 Line that ends at ZV ZV
19135 If you discover other use-cases, please add them here as
19137 if (row
->ends_at_zv_p
)
19138 row
->maxpos
= it
->current
.pos
;
19139 else if (row
->used
[TEXT_AREA
])
19141 int seen_this_string
= 0;
19142 struct glyph_row
*r1
= row
- 1;
19144 /* Did we see the same display string on the previous row? */
19145 if (STRINGP (it
->object
)
19146 /* this is not the first row */
19147 && row
> it
->w
->desired_matrix
->rows
19148 /* previous row is not the header line */
19149 && !r1
->mode_line_p
19150 /* previous row also ends in a newline from a string */
19151 && r1
->ends_in_newline_from_string_p
)
19153 struct glyph
*start
, *end
;
19155 /* Search for the last glyph of the previous row that came
19156 from buffer or string. Depending on whether the row is
19157 L2R or R2L, we need to process it front to back or the
19158 other way round. */
19159 if (!r1
->reversed_p
)
19161 start
= r1
->glyphs
[TEXT_AREA
];
19162 end
= start
+ r1
->used
[TEXT_AREA
];
19163 /* Glyphs inserted by redisplay have an integer (zero)
19164 as their object. */
19166 && INTEGERP ((end
- 1)->object
)
19167 && (end
- 1)->charpos
<= 0)
19171 if (EQ ((end
- 1)->object
, it
->object
))
19172 seen_this_string
= 1;
19175 /* If all the glyphs of the previous row were inserted
19176 by redisplay, it means the previous row was
19177 produced from a single newline, which is only
19178 possible if that newline came from the same string
19179 as the one which produced this ROW. */
19180 seen_this_string
= 1;
19184 end
= r1
->glyphs
[TEXT_AREA
] - 1;
19185 start
= end
+ r1
->used
[TEXT_AREA
];
19187 && INTEGERP ((end
+ 1)->object
)
19188 && (end
+ 1)->charpos
<= 0)
19192 if (EQ ((end
+ 1)->object
, it
->object
))
19193 seen_this_string
= 1;
19196 seen_this_string
= 1;
19199 /* Take note of each display string that covers a newline only
19200 once, the first time we see it. This is for when a display
19201 string includes more than one newline in it. */
19202 if (row
->ends_in_newline_from_string_p
&& !seen_this_string
)
19204 /* If we were scanning the buffer forward when we displayed
19205 the string, we want to account for at least one buffer
19206 position that belongs to this row (position covered by
19207 the display string), so that cursor positioning will
19208 consider this row as a candidate when point is at the end
19209 of the visual line represented by this row. This is not
19210 required when scanning back, because max_pos will already
19211 have a much larger value. */
19212 if (CHARPOS (row
->end
.pos
) > max_pos
)
19213 INC_BOTH (max_pos
, max_bpos
);
19214 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19216 else if (CHARPOS (it
->eol_pos
) > 0)
19217 SET_TEXT_POS (row
->maxpos
,
19218 CHARPOS (it
->eol_pos
) + 1, BYTEPOS (it
->eol_pos
) + 1);
19219 else if (row
->continued_p
)
19221 /* If max_pos is different from IT's current position, it
19222 means IT->method does not belong to the display element
19223 at max_pos. However, it also means that the display
19224 element at max_pos was displayed in its entirety on this
19225 line, which is equivalent to saying that the next line
19226 starts at the next buffer position. */
19227 if (IT_CHARPOS (*it
) == max_pos
&& it
->method
!= GET_FROM_BUFFER
)
19228 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19231 INC_BOTH (max_pos
, max_bpos
);
19232 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19235 else if (row
->truncated_on_right_p
)
19236 /* display_line already called reseat_at_next_visible_line_start,
19237 which puts the iterator at the beginning of the next line, in
19238 the logical order. */
19239 row
->maxpos
= it
->current
.pos
;
19240 else if (max_pos
== min_pos
&& it
->method
!= GET_FROM_BUFFER
)
19241 /* A line that is entirely from a string/image/stretch... */
19242 row
->maxpos
= row
->minpos
;
19247 row
->maxpos
= it
->current
.pos
;
19250 /* Construct the glyph row IT->glyph_row in the desired matrix of
19251 IT->w from text at the current position of IT. See dispextern.h
19252 for an overview of struct it. Value is non-zero if
19253 IT->glyph_row displays text, as opposed to a line displaying ZV
19257 display_line (struct it
*it
)
19259 struct glyph_row
*row
= it
->glyph_row
;
19260 Lisp_Object overlay_arrow_string
;
19262 void *wrap_data
= NULL
;
19263 int may_wrap
= 0, wrap_x
IF_LINT (= 0);
19264 int wrap_row_used
= -1;
19265 int wrap_row_ascent
IF_LINT (= 0), wrap_row_height
IF_LINT (= 0);
19266 int wrap_row_phys_ascent
IF_LINT (= 0), wrap_row_phys_height
IF_LINT (= 0);
19267 int wrap_row_extra_line_spacing
IF_LINT (= 0);
19268 ptrdiff_t wrap_row_min_pos
IF_LINT (= 0), wrap_row_min_bpos
IF_LINT (= 0);
19269 ptrdiff_t wrap_row_max_pos
IF_LINT (= 0), wrap_row_max_bpos
IF_LINT (= 0);
19271 ptrdiff_t min_pos
= ZV
+ 1, max_pos
= 0;
19272 ptrdiff_t min_bpos
IF_LINT (= 0), max_bpos
IF_LINT (= 0);
19274 /* We always start displaying at hpos zero even if hscrolled. */
19275 eassert (it
->hpos
== 0 && it
->current_x
== 0);
19277 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
19278 >= it
->w
->desired_matrix
->nrows
)
19280 it
->w
->nrows_scale_factor
++;
19281 fonts_changed_p
= 1;
19285 /* Is IT->w showing the region? */
19286 wset_region_showing (it
->w
, it
->region_beg_charpos
> 0 ? Qt
: Qnil
);
19288 /* Clear the result glyph row and enable it. */
19289 prepare_desired_row (row
);
19291 row
->y
= it
->current_y
;
19292 row
->start
= it
->start
;
19293 row
->continuation_lines_width
= it
->continuation_lines_width
;
19294 row
->displays_text_p
= 1;
19295 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
19296 it
->starts_in_middle_of_char_p
= 0;
19298 /* Arrange the overlays nicely for our purposes. Usually, we call
19299 display_line on only one line at a time, in which case this
19300 can't really hurt too much, or we call it on lines which appear
19301 one after another in the buffer, in which case all calls to
19302 recenter_overlay_lists but the first will be pretty cheap. */
19303 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
19305 /* Move over display elements that are not visible because we are
19306 hscrolled. This may stop at an x-position < IT->first_visible_x
19307 if the first glyph is partially visible or if we hit a line end. */
19308 if (it
->current_x
< it
->first_visible_x
)
19310 enum move_it_result move_result
;
19312 this_line_min_pos
= row
->start
.pos
;
19313 move_result
= move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
19314 MOVE_TO_POS
| MOVE_TO_X
);
19315 /* If we are under a large hscroll, move_it_in_display_line_to
19316 could hit the end of the line without reaching
19317 it->first_visible_x. Pretend that we did reach it. This is
19318 especially important on a TTY, where we will call
19319 extend_face_to_end_of_line, which needs to know how many
19320 blank glyphs to produce. */
19321 if (it
->current_x
< it
->first_visible_x
19322 && (move_result
== MOVE_NEWLINE_OR_CR
19323 || move_result
== MOVE_POS_MATCH_OR_ZV
))
19324 it
->current_x
= it
->first_visible_x
;
19326 /* Record the smallest positions seen while we moved over
19327 display elements that are not visible. This is needed by
19328 redisplay_internal for optimizing the case where the cursor
19329 stays inside the same line. The rest of this function only
19330 considers positions that are actually displayed, so
19331 RECORD_MAX_MIN_POS will not otherwise record positions that
19332 are hscrolled to the left of the left edge of the window. */
19333 min_pos
= CHARPOS (this_line_min_pos
);
19334 min_bpos
= BYTEPOS (this_line_min_pos
);
19338 /* We only do this when not calling `move_it_in_display_line_to'
19339 above, because move_it_in_display_line_to calls
19340 handle_line_prefix itself. */
19341 handle_line_prefix (it
);
19344 /* Get the initial row height. This is either the height of the
19345 text hscrolled, if there is any, or zero. */
19346 row
->ascent
= it
->max_ascent
;
19347 row
->height
= it
->max_ascent
+ it
->max_descent
;
19348 row
->phys_ascent
= it
->max_phys_ascent
;
19349 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
19350 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
19352 /* Utility macro to record max and min buffer positions seen until now. */
19353 #define RECORD_MAX_MIN_POS(IT) \
19356 int composition_p = !STRINGP ((IT)->string) \
19357 && ((IT)->what == IT_COMPOSITION); \
19358 ptrdiff_t current_pos = \
19359 composition_p ? (IT)->cmp_it.charpos \
19360 : IT_CHARPOS (*(IT)); \
19361 ptrdiff_t current_bpos = \
19362 composition_p ? CHAR_TO_BYTE (current_pos) \
19363 : IT_BYTEPOS (*(IT)); \
19364 if (current_pos < min_pos) \
19366 min_pos = current_pos; \
19367 min_bpos = current_bpos; \
19369 if (IT_CHARPOS (*it) > max_pos) \
19371 max_pos = IT_CHARPOS (*it); \
19372 max_bpos = IT_BYTEPOS (*it); \
19377 /* Loop generating characters. The loop is left with IT on the next
19378 character to display. */
19381 int n_glyphs_before
, hpos_before
, x_before
;
19383 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
19385 /* Retrieve the next thing to display. Value is zero if end of
19387 if (!get_next_display_element (it
))
19389 /* Maybe add a space at the end of this line that is used to
19390 display the cursor there under X. Set the charpos of the
19391 first glyph of blank lines not corresponding to any text
19393 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19394 row
->exact_window_width_line_p
= 1;
19395 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
19396 || row
->used
[TEXT_AREA
] == 0)
19398 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
19399 row
->displays_text_p
= 0;
19401 if (!NILP (BVAR (XBUFFER (it
->w
->buffer
), indicate_empty_lines
))
19402 && (!MINI_WINDOW_P (it
->w
)
19403 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
19404 row
->indicate_empty_line_p
= 1;
19407 it
->continuation_lines_width
= 0;
19408 row
->ends_at_zv_p
= 1;
19409 /* A row that displays right-to-left text must always have
19410 its last face extended all the way to the end of line,
19411 even if this row ends in ZV, because we still write to
19412 the screen left to right. We also need to extend the
19413 last face if the default face is remapped to some
19414 different face, otherwise the functions that clear
19415 portions of the screen will clear with the default face's
19416 background color. */
19417 if (row
->reversed_p
19418 || lookup_basic_face (it
->f
, DEFAULT_FACE_ID
) != DEFAULT_FACE_ID
)
19419 extend_face_to_end_of_line (it
);
19423 /* Now, get the metrics of what we want to display. This also
19424 generates glyphs in `row' (which is IT->glyph_row). */
19425 n_glyphs_before
= row
->used
[TEXT_AREA
];
19428 /* Remember the line height so far in case the next element doesn't
19429 fit on the line. */
19430 if (it
->line_wrap
!= TRUNCATE
)
19432 ascent
= it
->max_ascent
;
19433 descent
= it
->max_descent
;
19434 phys_ascent
= it
->max_phys_ascent
;
19435 phys_descent
= it
->max_phys_descent
;
19437 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
19439 if (IT_DISPLAYING_WHITESPACE (it
))
19443 SAVE_IT (wrap_it
, *it
, wrap_data
);
19445 wrap_row_used
= row
->used
[TEXT_AREA
];
19446 wrap_row_ascent
= row
->ascent
;
19447 wrap_row_height
= row
->height
;
19448 wrap_row_phys_ascent
= row
->phys_ascent
;
19449 wrap_row_phys_height
= row
->phys_height
;
19450 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
19451 wrap_row_min_pos
= min_pos
;
19452 wrap_row_min_bpos
= min_bpos
;
19453 wrap_row_max_pos
= max_pos
;
19454 wrap_row_max_bpos
= max_bpos
;
19460 PRODUCE_GLYPHS (it
);
19462 /* If this display element was in marginal areas, continue with
19464 if (it
->area
!= TEXT_AREA
)
19466 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19467 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19468 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19469 row
->phys_height
= max (row
->phys_height
,
19470 it
->max_phys_ascent
+ it
->max_phys_descent
);
19471 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19472 it
->max_extra_line_spacing
);
19473 set_iterator_to_next (it
, 1);
19477 /* Does the display element fit on the line? If we truncate
19478 lines, we should draw past the right edge of the window. If
19479 we don't truncate, we want to stop so that we can display the
19480 continuation glyph before the right margin. If lines are
19481 continued, there are two possible strategies for characters
19482 resulting in more than 1 glyph (e.g. tabs): Display as many
19483 glyphs as possible in this line and leave the rest for the
19484 continuation line, or display the whole element in the next
19485 line. Original redisplay did the former, so we do it also. */
19486 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
19487 hpos_before
= it
->hpos
;
19490 if (/* Not a newline. */
19492 /* Glyphs produced fit entirely in the line. */
19493 && it
->current_x
< it
->last_visible_x
)
19495 it
->hpos
+= nglyphs
;
19496 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19497 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19498 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19499 row
->phys_height
= max (row
->phys_height
,
19500 it
->max_phys_ascent
+ it
->max_phys_descent
);
19501 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19502 it
->max_extra_line_spacing
);
19503 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
19504 row
->x
= x
- it
->first_visible_x
;
19505 /* Record the maximum and minimum buffer positions seen so
19506 far in glyphs that will be displayed by this row. */
19508 RECORD_MAX_MIN_POS (it
);
19513 struct glyph
*glyph
;
19515 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
19517 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
19518 new_x
= x
+ glyph
->pixel_width
;
19520 if (/* Lines are continued. */
19521 it
->line_wrap
!= TRUNCATE
19522 && (/* Glyph doesn't fit on the line. */
19523 new_x
> it
->last_visible_x
19524 /* Or it fits exactly on a window system frame. */
19525 || (new_x
== it
->last_visible_x
19526 && FRAME_WINDOW_P (it
->f
)
19527 && (row
->reversed_p
19528 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19529 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
19531 /* End of a continued line. */
19534 || (new_x
== it
->last_visible_x
19535 && FRAME_WINDOW_P (it
->f
)
19536 && (row
->reversed_p
19537 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19538 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
))))
19540 /* Current glyph is the only one on the line or
19541 fits exactly on the line. We must continue
19542 the line because we can't draw the cursor
19543 after the glyph. */
19544 row
->continued_p
= 1;
19545 it
->current_x
= new_x
;
19546 it
->continuation_lines_width
+= new_x
;
19548 if (i
== nglyphs
- 1)
19550 /* If line-wrap is on, check if a previous
19551 wrap point was found. */
19552 if (wrap_row_used
> 0
19553 /* Even if there is a previous wrap
19554 point, continue the line here as
19555 usual, if (i) the previous character
19556 was a space or tab AND (ii) the
19557 current character is not. */
19559 || IT_DISPLAYING_WHITESPACE (it
)))
19562 /* Record the maximum and minimum buffer
19563 positions seen so far in glyphs that will be
19564 displayed by this row. */
19566 RECORD_MAX_MIN_POS (it
);
19567 set_iterator_to_next (it
, 1);
19568 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19570 if (!get_next_display_element (it
))
19572 row
->exact_window_width_line_p
= 1;
19573 it
->continuation_lines_width
= 0;
19574 row
->continued_p
= 0;
19575 row
->ends_at_zv_p
= 1;
19577 else if (ITERATOR_AT_END_OF_LINE_P (it
))
19579 row
->continued_p
= 0;
19580 row
->exact_window_width_line_p
= 1;
19584 else if (it
->bidi_p
)
19585 RECORD_MAX_MIN_POS (it
);
19587 else if (CHAR_GLYPH_PADDING_P (*glyph
)
19588 && !FRAME_WINDOW_P (it
->f
))
19590 /* A padding glyph that doesn't fit on this line.
19591 This means the whole character doesn't fit
19593 if (row
->reversed_p
)
19594 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19595 - n_glyphs_before
);
19596 row
->used
[TEXT_AREA
] = n_glyphs_before
;
19598 /* Fill the rest of the row with continuation
19599 glyphs like in 20.x. */
19600 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
19601 < row
->glyphs
[1 + TEXT_AREA
])
19602 produce_special_glyphs (it
, IT_CONTINUATION
);
19604 row
->continued_p
= 1;
19605 it
->current_x
= x_before
;
19606 it
->continuation_lines_width
+= x_before
;
19608 /* Restore the height to what it was before the
19609 element not fitting on the line. */
19610 it
->max_ascent
= ascent
;
19611 it
->max_descent
= descent
;
19612 it
->max_phys_ascent
= phys_ascent
;
19613 it
->max_phys_descent
= phys_descent
;
19615 else if (wrap_row_used
> 0)
19618 if (row
->reversed_p
)
19619 unproduce_glyphs (it
,
19620 row
->used
[TEXT_AREA
] - wrap_row_used
);
19621 RESTORE_IT (it
, &wrap_it
, wrap_data
);
19622 it
->continuation_lines_width
+= wrap_x
;
19623 row
->used
[TEXT_AREA
] = wrap_row_used
;
19624 row
->ascent
= wrap_row_ascent
;
19625 row
->height
= wrap_row_height
;
19626 row
->phys_ascent
= wrap_row_phys_ascent
;
19627 row
->phys_height
= wrap_row_phys_height
;
19628 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
19629 min_pos
= wrap_row_min_pos
;
19630 min_bpos
= wrap_row_min_bpos
;
19631 max_pos
= wrap_row_max_pos
;
19632 max_bpos
= wrap_row_max_bpos
;
19633 row
->continued_p
= 1;
19634 row
->ends_at_zv_p
= 0;
19635 row
->exact_window_width_line_p
= 0;
19636 it
->continuation_lines_width
+= x
;
19638 /* Make sure that a non-default face is extended
19639 up to the right margin of the window. */
19640 extend_face_to_end_of_line (it
);
19642 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
19644 /* A TAB that extends past the right edge of the
19645 window. This produces a single glyph on
19646 window system frames. We leave the glyph in
19647 this row and let it fill the row, but don't
19648 consume the TAB. */
19649 if ((row
->reversed_p
19650 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19651 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19652 produce_special_glyphs (it
, IT_CONTINUATION
);
19653 it
->continuation_lines_width
+= it
->last_visible_x
;
19654 row
->ends_in_middle_of_char_p
= 1;
19655 row
->continued_p
= 1;
19656 glyph
->pixel_width
= it
->last_visible_x
- x
;
19657 it
->starts_in_middle_of_char_p
= 1;
19661 /* Something other than a TAB that draws past
19662 the right edge of the window. Restore
19663 positions to values before the element. */
19664 if (row
->reversed_p
)
19665 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19666 - (n_glyphs_before
+ i
));
19667 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
19669 /* Display continuation glyphs. */
19670 it
->current_x
= x_before
;
19671 it
->continuation_lines_width
+= x
;
19672 if (!FRAME_WINDOW_P (it
->f
)
19673 || (row
->reversed_p
19674 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19675 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19676 produce_special_glyphs (it
, IT_CONTINUATION
);
19677 row
->continued_p
= 1;
19679 extend_face_to_end_of_line (it
);
19681 if (nglyphs
> 1 && i
> 0)
19683 row
->ends_in_middle_of_char_p
= 1;
19684 it
->starts_in_middle_of_char_p
= 1;
19687 /* Restore the height to what it was before the
19688 element not fitting on the line. */
19689 it
->max_ascent
= ascent
;
19690 it
->max_descent
= descent
;
19691 it
->max_phys_ascent
= phys_ascent
;
19692 it
->max_phys_descent
= phys_descent
;
19697 else if (new_x
> it
->first_visible_x
)
19699 /* Increment number of glyphs actually displayed. */
19702 /* Record the maximum and minimum buffer positions
19703 seen so far in glyphs that will be displayed by
19706 RECORD_MAX_MIN_POS (it
);
19708 if (x
< it
->first_visible_x
)
19709 /* Glyph is partially visible, i.e. row starts at
19710 negative X position. */
19711 row
->x
= x
- it
->first_visible_x
;
19715 /* Glyph is completely off the left margin of the
19716 window. This should not happen because of the
19717 move_it_in_display_line at the start of this
19718 function, unless the text display area of the
19719 window is empty. */
19720 eassert (it
->first_visible_x
<= it
->last_visible_x
);
19723 /* Even if this display element produced no glyphs at all,
19724 we want to record its position. */
19725 if (it
->bidi_p
&& nglyphs
== 0)
19726 RECORD_MAX_MIN_POS (it
);
19728 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19729 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19730 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19731 row
->phys_height
= max (row
->phys_height
,
19732 it
->max_phys_ascent
+ it
->max_phys_descent
);
19733 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19734 it
->max_extra_line_spacing
);
19736 /* End of this display line if row is continued. */
19737 if (row
->continued_p
|| row
->ends_at_zv_p
)
19742 /* Is this a line end? If yes, we're also done, after making
19743 sure that a non-default face is extended up to the right
19744 margin of the window. */
19745 if (ITERATOR_AT_END_OF_LINE_P (it
))
19747 int used_before
= row
->used
[TEXT_AREA
];
19749 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
19751 /* Add a space at the end of the line that is used to
19752 display the cursor there. */
19753 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19754 append_space_for_newline (it
, 0);
19756 /* Extend the face to the end of the line. */
19757 extend_face_to_end_of_line (it
);
19759 /* Make sure we have the position. */
19760 if (used_before
== 0)
19761 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
19763 /* Record the position of the newline, for use in
19765 it
->eol_pos
= it
->current
.pos
;
19767 /* Consume the line end. This skips over invisible lines. */
19768 set_iterator_to_next (it
, 1);
19769 it
->continuation_lines_width
= 0;
19773 /* Proceed with next display element. Note that this skips
19774 over lines invisible because of selective display. */
19775 set_iterator_to_next (it
, 1);
19777 /* If we truncate lines, we are done when the last displayed
19778 glyphs reach past the right margin of the window. */
19779 if (it
->line_wrap
== TRUNCATE
19780 && (FRAME_WINDOW_P (it
->f
) && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
19781 ? (it
->current_x
>= it
->last_visible_x
)
19782 : (it
->current_x
> it
->last_visible_x
)))
19784 /* Maybe add truncation glyphs. */
19785 if (!FRAME_WINDOW_P (it
->f
)
19786 || (row
->reversed_p
19787 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19788 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19792 if (!row
->reversed_p
)
19794 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
19795 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19800 for (i
= 0; i
< row
->used
[TEXT_AREA
]; i
++)
19801 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19803 /* Remove any padding glyphs at the front of ROW, to
19804 make room for the truncation glyphs we will be
19805 adding below. The loop below always inserts at
19806 least one truncation glyph, so also remove the
19807 last glyph added to ROW. */
19808 unproduce_glyphs (it
, i
+ 1);
19809 /* Adjust i for the loop below. */
19810 i
= row
->used
[TEXT_AREA
] - (i
+ 1);
19813 it
->current_x
= x_before
;
19814 if (!FRAME_WINDOW_P (it
->f
))
19816 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
19818 row
->used
[TEXT_AREA
] = i
;
19819 produce_special_glyphs (it
, IT_TRUNCATION
);
19824 row
->used
[TEXT_AREA
] = i
;
19825 produce_special_glyphs (it
, IT_TRUNCATION
);
19828 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19830 /* Don't truncate if we can overflow newline into fringe. */
19831 if (!get_next_display_element (it
))
19833 it
->continuation_lines_width
= 0;
19834 row
->ends_at_zv_p
= 1;
19835 row
->exact_window_width_line_p
= 1;
19838 if (ITERATOR_AT_END_OF_LINE_P (it
))
19840 row
->exact_window_width_line_p
= 1;
19841 goto at_end_of_line
;
19843 it
->current_x
= x_before
;
19846 row
->truncated_on_right_p
= 1;
19847 it
->continuation_lines_width
= 0;
19848 reseat_at_next_visible_line_start (it
, 0);
19849 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
19850 it
->hpos
= hpos_before
;
19856 bidi_unshelve_cache (wrap_data
, 1);
19858 /* If line is not empty and hscrolled, maybe insert truncation glyphs
19859 at the left window margin. */
19860 if (it
->first_visible_x
19861 && IT_CHARPOS (*it
) != CHARPOS (row
->start
.pos
))
19863 if (!FRAME_WINDOW_P (it
->f
)
19864 || (row
->reversed_p
19865 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
19866 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
19867 insert_left_trunc_glyphs (it
);
19868 row
->truncated_on_left_p
= 1;
19871 /* Remember the position at which this line ends.
19873 BIDI Note: any code that needs MATRIX_ROW_START/END_CHARPOS
19874 cannot be before the call to find_row_edges below, since that is
19875 where these positions are determined. */
19876 row
->end
= it
->current
;
19879 row
->minpos
= row
->start
.pos
;
19880 row
->maxpos
= row
->end
.pos
;
19884 /* ROW->minpos and ROW->maxpos must be the smallest and
19885 `1 + the largest' buffer positions in ROW. But if ROW was
19886 bidi-reordered, these two positions can be anywhere in the
19887 row, so we must determine them now. */
19888 find_row_edges (it
, row
, min_pos
, min_bpos
, max_pos
, max_bpos
);
19891 /* If the start of this line is the overlay arrow-position, then
19892 mark this glyph row as the one containing the overlay arrow.
19893 This is clearly a mess with variable size fonts. It would be
19894 better to let it be displayed like cursors under X. */
19895 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
19896 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
19897 !NILP (overlay_arrow_string
)))
19899 /* Overlay arrow in window redisplay is a fringe bitmap. */
19900 if (STRINGP (overlay_arrow_string
))
19902 struct glyph_row
*arrow_row
19903 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
19904 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
19905 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
19906 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
19907 struct glyph
*p2
, *end
;
19909 /* Copy the arrow glyphs. */
19910 while (glyph
< arrow_end
)
19913 /* Throw away padding glyphs. */
19915 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
19916 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
19922 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
19927 eassert (INTEGERP (overlay_arrow_string
));
19928 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
19930 overlay_arrow_seen
= 1;
19933 /* Highlight trailing whitespace. */
19934 if (!NILP (Vshow_trailing_whitespace
))
19935 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
19937 /* Compute pixel dimensions of this line. */
19938 compute_line_metrics (it
);
19940 /* Implementation note: No changes in the glyphs of ROW or in their
19941 faces can be done past this point, because compute_line_metrics
19942 computes ROW's hash value and stores it within the glyph_row
19945 /* Record whether this row ends inside an ellipsis. */
19946 row
->ends_in_ellipsis_p
19947 = (it
->method
== GET_FROM_DISPLAY_VECTOR
19948 && it
->ellipsis_p
);
19950 /* Save fringe bitmaps in this row. */
19951 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
19952 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
19953 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
19954 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
19956 it
->left_user_fringe_bitmap
= 0;
19957 it
->left_user_fringe_face_id
= 0;
19958 it
->right_user_fringe_bitmap
= 0;
19959 it
->right_user_fringe_face_id
= 0;
19961 /* Maybe set the cursor. */
19962 cvpos
= it
->w
->cursor
.vpos
;
19964 /* In bidi-reordered rows, keep checking for proper cursor
19965 position even if one has been found already, because buffer
19966 positions in such rows change non-linearly with ROW->VPOS,
19967 when a line is continued. One exception: when we are at ZV,
19968 display cursor on the first suitable glyph row, since all
19969 the empty rows after that also have their position set to ZV. */
19970 /* FIXME: Revisit this when glyph ``spilling'' in continuation
19971 lines' rows is implemented for bidi-reordered rows. */
19973 && !MATRIX_ROW (it
->w
->desired_matrix
, cvpos
)->ends_at_zv_p
))
19974 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
19975 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
19976 && cursor_row_p (row
))
19977 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
19979 /* Prepare for the next line. This line starts horizontally at (X
19980 HPOS) = (0 0). Vertical positions are incremented. As a
19981 convenience for the caller, IT->glyph_row is set to the next
19983 it
->current_x
= it
->hpos
= 0;
19984 it
->current_y
+= row
->height
;
19985 SET_TEXT_POS (it
->eol_pos
, 0, 0);
19988 /* The next row should by default use the same value of the
19989 reversed_p flag as this one. set_iterator_to_next decides when
19990 it's a new paragraph, and PRODUCE_GLYPHS recomputes the value of
19991 the flag accordingly. */
19992 if (it
->glyph_row
< MATRIX_BOTTOM_TEXT_ROW (it
->w
->desired_matrix
, it
->w
))
19993 it
->glyph_row
->reversed_p
= row
->reversed_p
;
19994 it
->start
= row
->end
;
19995 return row
->displays_text_p
;
19997 #undef RECORD_MAX_MIN_POS
20000 DEFUN ("current-bidi-paragraph-direction", Fcurrent_bidi_paragraph_direction
,
20001 Scurrent_bidi_paragraph_direction
, 0, 1, 0,
20002 doc
: /* Return paragraph direction at point in BUFFER.
20003 Value is either `left-to-right' or `right-to-left'.
20004 If BUFFER is omitted or nil, it defaults to the current buffer.
20006 Paragraph direction determines how the text in the paragraph is displayed.
20007 In left-to-right paragraphs, text begins at the left margin of the window
20008 and the reading direction is generally left to right. In right-to-left
20009 paragraphs, text begins at the right margin and is read from right to left.
20011 See also `bidi-paragraph-direction'. */)
20012 (Lisp_Object buffer
)
20014 struct buffer
*buf
= current_buffer
;
20015 struct buffer
*old
= buf
;
20017 if (! NILP (buffer
))
20019 CHECK_BUFFER (buffer
);
20020 buf
= XBUFFER (buffer
);
20023 if (NILP (BVAR (buf
, bidi_display_reordering
))
20024 || NILP (BVAR (buf
, enable_multibyte_characters
))
20025 /* When we are loading loadup.el, the character property tables
20026 needed for bidi iteration are not yet available. */
20027 || !NILP (Vpurify_flag
))
20028 return Qleft_to_right
;
20029 else if (!NILP (BVAR (buf
, bidi_paragraph_direction
)))
20030 return BVAR (buf
, bidi_paragraph_direction
);
20033 /* Determine the direction from buffer text. We could try to
20034 use current_matrix if it is up to date, but this seems fast
20035 enough as it is. */
20036 struct bidi_it itb
;
20037 ptrdiff_t pos
= BUF_PT (buf
);
20038 ptrdiff_t bytepos
= BUF_PT_BYTE (buf
);
20040 void *itb_data
= bidi_shelve_cache ();
20042 set_buffer_temp (buf
);
20043 /* bidi_paragraph_init finds the base direction of the paragraph
20044 by searching forward from paragraph start. We need the base
20045 direction of the current or _previous_ paragraph, so we need
20046 to make sure we are within that paragraph. To that end, find
20047 the previous non-empty line. */
20048 if (pos
>= ZV
&& pos
> BEGV
)
20051 bytepos
= CHAR_TO_BYTE (pos
);
20053 if (fast_looking_at (build_string ("[\f\t ]*\n"),
20054 pos
, bytepos
, ZV
, ZV_BYTE
, Qnil
) > 0)
20056 while ((c
= FETCH_BYTE (bytepos
)) == '\n'
20057 || c
== ' ' || c
== '\t' || c
== '\f')
20059 if (bytepos
<= BEGV_BYTE
)
20064 while (!CHAR_HEAD_P (FETCH_BYTE (bytepos
)))
20067 bidi_init_it (pos
, bytepos
, FRAME_WINDOW_P (SELECTED_FRAME ()), &itb
);
20068 itb
.paragraph_dir
= NEUTRAL_DIR
;
20069 itb
.string
.s
= NULL
;
20070 itb
.string
.lstring
= Qnil
;
20071 itb
.string
.bufpos
= 0;
20072 itb
.string
.unibyte
= 0;
20073 bidi_paragraph_init (NEUTRAL_DIR
, &itb
, 1);
20074 bidi_unshelve_cache (itb_data
, 0);
20075 set_buffer_temp (old
);
20076 switch (itb
.paragraph_dir
)
20079 return Qleft_to_right
;
20082 return Qright_to_left
;
20092 /***********************************************************************
20094 ***********************************************************************/
20096 /* Redisplay the menu bar in the frame for window W.
20098 The menu bar of X frames that don't have X toolkit support is
20099 displayed in a special window W->frame->menu_bar_window.
20101 The menu bar of terminal frames is treated specially as far as
20102 glyph matrices are concerned. Menu bar lines are not part of
20103 windows, so the update is done directly on the frame matrix rows
20104 for the menu bar. */
20107 display_menu_bar (struct window
*w
)
20109 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20114 /* Don't do all this for graphical frames. */
20116 if (FRAME_W32_P (f
))
20119 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
20125 if (FRAME_NS_P (f
))
20127 #endif /* HAVE_NS */
20129 #ifdef USE_X_TOOLKIT
20130 eassert (!FRAME_WINDOW_P (f
));
20131 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
20132 it
.first_visible_x
= 0;
20133 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
20134 #else /* not USE_X_TOOLKIT */
20135 if (FRAME_WINDOW_P (f
))
20137 /* Menu bar lines are displayed in the desired matrix of the
20138 dummy window menu_bar_window. */
20139 struct window
*menu_w
;
20140 eassert (WINDOWP (f
->menu_bar_window
));
20141 menu_w
= XWINDOW (f
->menu_bar_window
);
20142 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
20144 it
.first_visible_x
= 0;
20145 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
20149 /* This is a TTY frame, i.e. character hpos/vpos are used as
20151 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
20153 it
.first_visible_x
= 0;
20154 it
.last_visible_x
= FRAME_COLS (f
);
20156 #endif /* not USE_X_TOOLKIT */
20158 /* FIXME: This should be controlled by a user option. See the
20159 comments in redisplay_tool_bar and display_mode_line about
20161 it
.paragraph_embedding
= L2R
;
20163 if (! mode_line_inverse_video
)
20164 /* Force the menu-bar to be displayed in the default face. */
20165 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
20167 /* Clear all rows of the menu bar. */
20168 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
20170 struct glyph_row
*row
= it
.glyph_row
+ i
;
20171 clear_glyph_row (row
);
20172 row
->enabled_p
= 1;
20173 row
->full_width_p
= 1;
20176 /* Display all items of the menu bar. */
20177 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
20178 for (i
= 0; i
< ASIZE (items
); i
+= 4)
20180 Lisp_Object string
;
20182 /* Stop at nil string. */
20183 string
= AREF (items
, i
+ 1);
20187 /* Remember where item was displayed. */
20188 ASET (items
, i
+ 3, make_number (it
.hpos
));
20190 /* Display the item, pad with one space. */
20191 if (it
.current_x
< it
.last_visible_x
)
20192 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
20193 SCHARS (string
) + 1, 0, 0, -1);
20196 /* Fill out the line with spaces. */
20197 if (it
.current_x
< it
.last_visible_x
)
20198 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
20200 /* Compute the total height of the lines. */
20201 compute_line_metrics (&it
);
20206 /***********************************************************************
20208 ***********************************************************************/
20210 /* Redisplay mode lines in the window tree whose root is WINDOW. If
20211 FORCE is non-zero, redisplay mode lines unconditionally.
20212 Otherwise, redisplay only mode lines that are garbaged. Value is
20213 the number of windows whose mode lines were redisplayed. */
20216 redisplay_mode_lines (Lisp_Object window
, int force
)
20220 while (!NILP (window
))
20222 struct window
*w
= XWINDOW (window
);
20224 if (WINDOWP (w
->hchild
))
20225 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
20226 else if (WINDOWP (w
->vchild
))
20227 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
20229 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
20230 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
20232 struct text_pos lpoint
;
20233 struct buffer
*old
= current_buffer
;
20235 /* Set the window's buffer for the mode line display. */
20236 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
20237 set_buffer_internal_1 (XBUFFER (w
->buffer
));
20239 /* Point refers normally to the selected window. For any
20240 other window, set up appropriate value. */
20241 if (!EQ (window
, selected_window
))
20243 struct text_pos pt
;
20245 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
20246 if (CHARPOS (pt
) < BEGV
)
20247 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
20248 else if (CHARPOS (pt
) > (ZV
- 1))
20249 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
20251 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
20254 /* Display mode lines. */
20255 clear_glyph_matrix (w
->desired_matrix
);
20256 if (display_mode_lines (w
))
20259 w
->must_be_updated_p
= 1;
20262 /* Restore old settings. */
20263 set_buffer_internal_1 (old
);
20264 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
20274 /* Display the mode and/or header line of window W. Value is the
20275 sum number of mode lines and header lines displayed. */
20278 display_mode_lines (struct window
*w
)
20280 Lisp_Object old_selected_window
, old_selected_frame
;
20283 old_selected_frame
= selected_frame
;
20284 selected_frame
= w
->frame
;
20285 old_selected_window
= selected_window
;
20286 XSETWINDOW (selected_window
, w
);
20288 /* These will be set while the mode line specs are processed. */
20289 line_number_displayed
= 0;
20290 wset_column_number_displayed (w
, Qnil
);
20292 if (WINDOW_WANTS_MODELINE_P (w
))
20294 struct window
*sel_w
= XWINDOW (old_selected_window
);
20296 /* Select mode line face based on the real selected window. */
20297 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
20298 BVAR (current_buffer
, mode_line_format
));
20302 if (WINDOW_WANTS_HEADER_LINE_P (w
))
20304 display_mode_line (w
, HEADER_LINE_FACE_ID
,
20305 BVAR (current_buffer
, header_line_format
));
20309 selected_frame
= old_selected_frame
;
20310 selected_window
= old_selected_window
;
20315 /* Display mode or header line of window W. FACE_ID specifies which
20316 line to display; it is either MODE_LINE_FACE_ID or
20317 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
20318 display. Value is the pixel height of the mode/header line
20322 display_mode_line (struct window
*w
, enum face_id face_id
, Lisp_Object format
)
20326 ptrdiff_t count
= SPECPDL_INDEX ();
20328 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
20329 /* Don't extend on a previously drawn mode-line.
20330 This may happen if called from pos_visible_p. */
20331 it
.glyph_row
->enabled_p
= 0;
20332 prepare_desired_row (it
.glyph_row
);
20334 it
.glyph_row
->mode_line_p
= 1;
20336 if (! mode_line_inverse_video
)
20337 /* Force the mode-line to be displayed in the default face. */
20338 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
20340 /* FIXME: This should be controlled by a user option. But
20341 supporting such an option is not trivial, since the mode line is
20342 made up of many separate strings. */
20343 it
.paragraph_embedding
= L2R
;
20345 record_unwind_protect (unwind_format_mode_line
,
20346 format_mode_line_unwind_data (NULL
, NULL
, Qnil
, 0));
20348 mode_line_target
= MODE_LINE_DISPLAY
;
20350 /* Temporarily make frame's keyboard the current kboard so that
20351 kboard-local variables in the mode_line_format will get the right
20353 push_kboard (FRAME_KBOARD (it
.f
));
20354 record_unwind_save_match_data ();
20355 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
20358 unbind_to (count
, Qnil
);
20360 /* Fill up with spaces. */
20361 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
20363 compute_line_metrics (&it
);
20364 it
.glyph_row
->full_width_p
= 1;
20365 it
.glyph_row
->continued_p
= 0;
20366 it
.glyph_row
->truncated_on_left_p
= 0;
20367 it
.glyph_row
->truncated_on_right_p
= 0;
20369 /* Make a 3D mode-line have a shadow at its right end. */
20370 face
= FACE_FROM_ID (it
.f
, face_id
);
20371 extend_face_to_end_of_line (&it
);
20372 if (face
->box
!= FACE_NO_BOX
)
20374 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
20375 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
20376 last
->right_box_line_p
= 1;
20379 return it
.glyph_row
->height
;
20382 /* Move element ELT in LIST to the front of LIST.
20383 Return the updated list. */
20386 move_elt_to_front (Lisp_Object elt
, Lisp_Object list
)
20388 register Lisp_Object tail
, prev
;
20389 register Lisp_Object tem
;
20393 while (CONSP (tail
))
20399 /* Splice out the link TAIL. */
20401 list
= XCDR (tail
);
20403 Fsetcdr (prev
, XCDR (tail
));
20405 /* Now make it the first. */
20406 Fsetcdr (tail
, list
);
20411 tail
= XCDR (tail
);
20415 /* Not found--return unchanged LIST. */
20419 /* Contribute ELT to the mode line for window IT->w. How it
20420 translates into text depends on its data type.
20422 IT describes the display environment in which we display, as usual.
20424 DEPTH is the depth in recursion. It is used to prevent
20425 infinite recursion here.
20427 FIELD_WIDTH is the number of characters the display of ELT should
20428 occupy in the mode line, and PRECISION is the maximum number of
20429 characters to display from ELT's representation. See
20430 display_string for details.
20432 Returns the hpos of the end of the text generated by ELT.
20434 PROPS is a property list to add to any string we encounter.
20436 If RISKY is nonzero, remove (disregard) any properties in any string
20437 we encounter, and ignore :eval and :propertize.
20439 The global variable `mode_line_target' determines whether the
20440 output is passed to `store_mode_line_noprop',
20441 `store_mode_line_string', or `display_string'. */
20444 display_mode_element (struct it
*it
, int depth
, int field_width
, int precision
,
20445 Lisp_Object elt
, Lisp_Object props
, int risky
)
20447 int n
= 0, field
, prec
;
20452 elt
= build_string ("*too-deep*");
20456 switch (XTYPE (elt
))
20460 /* A string: output it and check for %-constructs within it. */
20462 ptrdiff_t offset
= 0;
20464 if (SCHARS (elt
) > 0
20465 && (!NILP (props
) || risky
))
20467 Lisp_Object oprops
, aelt
;
20468 oprops
= Ftext_properties_at (make_number (0), elt
);
20470 /* If the starting string's properties are not what
20471 we want, translate the string. Also, if the string
20472 is risky, do that anyway. */
20474 if (NILP (Fequal (props
, oprops
)) || risky
)
20476 /* If the starting string has properties,
20477 merge the specified ones onto the existing ones. */
20478 if (! NILP (oprops
) && !risky
)
20482 oprops
= Fcopy_sequence (oprops
);
20484 while (CONSP (tem
))
20486 oprops
= Fplist_put (oprops
, XCAR (tem
),
20487 XCAR (XCDR (tem
)));
20488 tem
= XCDR (XCDR (tem
));
20493 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
20494 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
20496 /* AELT is what we want. Move it to the front
20497 without consing. */
20499 mode_line_proptrans_alist
20500 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
20506 /* If AELT has the wrong props, it is useless.
20507 so get rid of it. */
20509 mode_line_proptrans_alist
20510 = Fdelq (aelt
, mode_line_proptrans_alist
);
20512 elt
= Fcopy_sequence (elt
);
20513 Fset_text_properties (make_number (0), Flength (elt
),
20515 /* Add this item to mode_line_proptrans_alist. */
20516 mode_line_proptrans_alist
20517 = Fcons (Fcons (elt
, props
),
20518 mode_line_proptrans_alist
);
20519 /* Truncate mode_line_proptrans_alist
20520 to at most 50 elements. */
20521 tem
= Fnthcdr (make_number (50),
20522 mode_line_proptrans_alist
);
20524 XSETCDR (tem
, Qnil
);
20533 prec
= precision
- n
;
20534 switch (mode_line_target
)
20536 case MODE_LINE_NOPROP
:
20537 case MODE_LINE_TITLE
:
20538 n
+= store_mode_line_noprop (SSDATA (elt
), -1, prec
);
20540 case MODE_LINE_STRING
:
20541 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
20543 case MODE_LINE_DISPLAY
:
20544 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
20545 0, prec
, 0, STRING_MULTIBYTE (elt
));
20552 /* Handle the non-literal case. */
20554 while ((precision
<= 0 || n
< precision
)
20555 && SREF (elt
, offset
) != 0
20556 && (mode_line_target
!= MODE_LINE_DISPLAY
20557 || it
->current_x
< it
->last_visible_x
))
20559 ptrdiff_t last_offset
= offset
;
20561 /* Advance to end of string or next format specifier. */
20562 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
20565 if (offset
- 1 != last_offset
)
20567 ptrdiff_t nchars
, nbytes
;
20569 /* Output to end of string or up to '%'. Field width
20570 is length of string. Don't output more than
20571 PRECISION allows us. */
20574 prec
= c_string_width (SDATA (elt
) + last_offset
,
20575 offset
- last_offset
, precision
- n
,
20578 switch (mode_line_target
)
20580 case MODE_LINE_NOPROP
:
20581 case MODE_LINE_TITLE
:
20582 n
+= store_mode_line_noprop (SSDATA (elt
) + last_offset
, 0, prec
);
20584 case MODE_LINE_STRING
:
20586 ptrdiff_t bytepos
= last_offset
;
20587 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
20588 ptrdiff_t endpos
= (precision
<= 0
20589 ? string_byte_to_char (elt
, offset
)
20590 : charpos
+ nchars
);
20592 n
+= store_mode_line_string (NULL
,
20593 Fsubstring (elt
, make_number (charpos
),
20594 make_number (endpos
)),
20598 case MODE_LINE_DISPLAY
:
20600 ptrdiff_t bytepos
= last_offset
;
20601 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
20603 if (precision
<= 0)
20604 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
20605 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
20607 STRING_MULTIBYTE (elt
));
20612 else /* c == '%' */
20614 ptrdiff_t percent_position
= offset
;
20616 /* Get the specified minimum width. Zero means
20619 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
20620 field
= field
* 10 + c
- '0';
20622 /* Don't pad beyond the total padding allowed. */
20623 if (field_width
- n
> 0 && field
> field_width
- n
)
20624 field
= field_width
- n
;
20626 /* Note that either PRECISION <= 0 or N < PRECISION. */
20627 prec
= precision
- n
;
20630 n
+= display_mode_element (it
, depth
, field
, prec
,
20631 Vglobal_mode_string
, props
,
20636 ptrdiff_t bytepos
, charpos
;
20638 Lisp_Object string
;
20640 bytepos
= percent_position
;
20641 charpos
= (STRING_MULTIBYTE (elt
)
20642 ? string_byte_to_char (elt
, bytepos
)
20644 spec
= decode_mode_spec (it
->w
, c
, field
, &string
);
20645 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
20647 switch (mode_line_target
)
20649 case MODE_LINE_NOPROP
:
20650 case MODE_LINE_TITLE
:
20651 n
+= store_mode_line_noprop (spec
, field
, prec
);
20653 case MODE_LINE_STRING
:
20655 Lisp_Object tem
= build_string (spec
);
20656 props
= Ftext_properties_at (make_number (charpos
), elt
);
20657 /* Should only keep face property in props */
20658 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
20661 case MODE_LINE_DISPLAY
:
20663 int nglyphs_before
, nwritten
;
20665 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
20666 nwritten
= display_string (spec
, string
, elt
,
20671 /* Assign to the glyphs written above the
20672 string where the `%x' came from, position
20676 struct glyph
*glyph
20677 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
20681 for (i
= 0; i
< nwritten
; ++i
)
20683 glyph
[i
].object
= elt
;
20684 glyph
[i
].charpos
= charpos
;
20701 /* A symbol: process the value of the symbol recursively
20702 as if it appeared here directly. Avoid error if symbol void.
20703 Special case: if value of symbol is a string, output the string
20706 register Lisp_Object tem
;
20708 /* If the variable is not marked as risky to set
20709 then its contents are risky to use. */
20710 if (NILP (Fget (elt
, Qrisky_local_variable
)))
20713 tem
= Fboundp (elt
);
20716 tem
= Fsymbol_value (elt
);
20717 /* If value is a string, output that string literally:
20718 don't check for % within it. */
20722 if (!EQ (tem
, elt
))
20724 /* Give up right away for nil or t. */
20734 register Lisp_Object car
, tem
;
20736 /* A cons cell: five distinct cases.
20737 If first element is :eval or :propertize, do something special.
20738 If first element is a string or a cons, process all the elements
20739 and effectively concatenate them.
20740 If first element is a negative number, truncate displaying cdr to
20741 at most that many characters. If positive, pad (with spaces)
20742 to at least that many characters.
20743 If first element is a symbol, process the cadr or caddr recursively
20744 according to whether the symbol's value is non-nil or nil. */
20746 if (EQ (car
, QCeval
))
20748 /* An element of the form (:eval FORM) means evaluate FORM
20749 and use the result as mode line elements. */
20754 if (CONSP (XCDR (elt
)))
20757 spec
= safe_eval (XCAR (XCDR (elt
)));
20758 n
+= display_mode_element (it
, depth
, field_width
- n
,
20759 precision
- n
, spec
, props
,
20763 else if (EQ (car
, QCpropertize
))
20765 /* An element of the form (:propertize ELT PROPS...)
20766 means display ELT but applying properties PROPS. */
20771 if (CONSP (XCDR (elt
)))
20772 n
+= display_mode_element (it
, depth
, field_width
- n
,
20773 precision
- n
, XCAR (XCDR (elt
)),
20774 XCDR (XCDR (elt
)), risky
);
20776 else if (SYMBOLP (car
))
20778 tem
= Fboundp (car
);
20782 /* elt is now the cdr, and we know it is a cons cell.
20783 Use its car if CAR has a non-nil value. */
20786 tem
= Fsymbol_value (car
);
20793 /* Symbol's value is nil (or symbol is unbound)
20794 Get the cddr of the original list
20795 and if possible find the caddr and use that. */
20799 else if (!CONSP (elt
))
20804 else if (INTEGERP (car
))
20806 register int lim
= XINT (car
);
20810 /* Negative int means reduce maximum width. */
20811 if (precision
<= 0)
20814 precision
= min (precision
, -lim
);
20818 /* Padding specified. Don't let it be more than
20819 current maximum. */
20821 lim
= min (precision
, lim
);
20823 /* If that's more padding than already wanted, queue it.
20824 But don't reduce padding already specified even if
20825 that is beyond the current truncation point. */
20826 field_width
= max (lim
, field_width
);
20830 else if (STRINGP (car
) || CONSP (car
))
20832 Lisp_Object halftail
= elt
;
20836 && (precision
<= 0 || n
< precision
))
20838 n
+= display_mode_element (it
, depth
,
20839 /* Do padding only after the last
20840 element in the list. */
20841 (! CONSP (XCDR (elt
))
20844 precision
- n
, XCAR (elt
),
20848 if ((len
& 1) == 0)
20849 halftail
= XCDR (halftail
);
20850 /* Check for cycle. */
20851 if (EQ (halftail
, elt
))
20860 elt
= build_string ("*invalid*");
20864 /* Pad to FIELD_WIDTH. */
20865 if (field_width
> 0 && n
< field_width
)
20867 switch (mode_line_target
)
20869 case MODE_LINE_NOPROP
:
20870 case MODE_LINE_TITLE
:
20871 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
20873 case MODE_LINE_STRING
:
20874 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
20876 case MODE_LINE_DISPLAY
:
20877 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
20886 /* Store a mode-line string element in mode_line_string_list.
20888 If STRING is non-null, display that C string. Otherwise, the Lisp
20889 string LISP_STRING is displayed.
20891 FIELD_WIDTH is the minimum number of output glyphs to produce.
20892 If STRING has fewer characters than FIELD_WIDTH, pad to the right
20893 with spaces. FIELD_WIDTH <= 0 means don't pad.
20895 PRECISION is the maximum number of characters to output from
20896 STRING. PRECISION <= 0 means don't truncate the string.
20898 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
20899 properties to the string.
20901 PROPS are the properties to add to the string.
20902 The mode_line_string_face face property is always added to the string.
20906 store_mode_line_string (const char *string
, Lisp_Object lisp_string
, int copy_string
,
20907 int field_width
, int precision
, Lisp_Object props
)
20912 if (string
!= NULL
)
20914 len
= strlen (string
);
20915 if (precision
> 0 && len
> precision
)
20917 lisp_string
= make_string (string
, len
);
20919 props
= mode_line_string_face_prop
;
20920 else if (!NILP (mode_line_string_face
))
20922 Lisp_Object face
= Fplist_get (props
, Qface
);
20923 props
= Fcopy_sequence (props
);
20925 face
= mode_line_string_face
;
20927 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
20928 props
= Fplist_put (props
, Qface
, face
);
20930 Fadd_text_properties (make_number (0), make_number (len
),
20931 props
, lisp_string
);
20935 len
= XFASTINT (Flength (lisp_string
));
20936 if (precision
> 0 && len
> precision
)
20939 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
20942 if (!NILP (mode_line_string_face
))
20946 props
= Ftext_properties_at (make_number (0), lisp_string
);
20947 face
= Fplist_get (props
, Qface
);
20949 face
= mode_line_string_face
;
20951 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
20952 props
= Fcons (Qface
, Fcons (face
, Qnil
));
20954 lisp_string
= Fcopy_sequence (lisp_string
);
20957 Fadd_text_properties (make_number (0), make_number (len
),
20958 props
, lisp_string
);
20963 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
20967 if (field_width
> len
)
20969 field_width
-= len
;
20970 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
20972 Fadd_text_properties (make_number (0), make_number (field_width
),
20973 props
, lisp_string
);
20974 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
20982 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
20984 doc
: /* Format a string out of a mode line format specification.
20985 First arg FORMAT specifies the mode line format (see `mode-line-format'
20986 for details) to use.
20988 By default, the format is evaluated for the currently selected window.
20990 Optional second arg FACE specifies the face property to put on all
20991 characters for which no face is specified. The value nil means the
20992 default face. The value t means whatever face the window's mode line
20993 currently uses (either `mode-line' or `mode-line-inactive',
20994 depending on whether the window is the selected window or not).
20995 An integer value means the value string has no text
20998 Optional third and fourth args WINDOW and BUFFER specify the window
20999 and buffer to use as the context for the formatting (defaults
21000 are the selected window and the WINDOW's buffer). */)
21001 (Lisp_Object format
, Lisp_Object face
,
21002 Lisp_Object window
, Lisp_Object buffer
)
21007 struct buffer
*old_buffer
= NULL
;
21009 int no_props
= INTEGERP (face
);
21010 ptrdiff_t count
= SPECPDL_INDEX ();
21012 int string_start
= 0;
21015 window
= selected_window
;
21016 CHECK_WINDOW (window
);
21017 w
= XWINDOW (window
);
21020 buffer
= w
->buffer
;
21021 CHECK_BUFFER (buffer
);
21023 /* Make formatting the modeline a non-op when noninteractive, otherwise
21024 there will be problems later caused by a partially initialized frame. */
21025 if (NILP (format
) || noninteractive
)
21026 return empty_unibyte_string
;
21031 face_id
= (NILP (face
) || EQ (face
, Qdefault
)) ? DEFAULT_FACE_ID
21032 : EQ (face
, Qt
) ? (EQ (window
, selected_window
)
21033 ? MODE_LINE_FACE_ID
: MODE_LINE_INACTIVE_FACE_ID
)
21034 : EQ (face
, Qmode_line
) ? MODE_LINE_FACE_ID
21035 : EQ (face
, Qmode_line_inactive
) ? MODE_LINE_INACTIVE_FACE_ID
21036 : EQ (face
, Qheader_line
) ? HEADER_LINE_FACE_ID
21037 : EQ (face
, Qtool_bar
) ? TOOL_BAR_FACE_ID
21040 old_buffer
= current_buffer
;
21042 /* Save things including mode_line_proptrans_alist,
21043 and set that to nil so that we don't alter the outer value. */
21044 record_unwind_protect (unwind_format_mode_line
,
21045 format_mode_line_unwind_data
21046 (XFRAME (WINDOW_FRAME (XWINDOW (window
))),
21047 old_buffer
, selected_window
, 1));
21048 mode_line_proptrans_alist
= Qnil
;
21050 Fselect_window (window
, Qt
);
21051 set_buffer_internal_1 (XBUFFER (buffer
));
21053 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
21057 mode_line_target
= MODE_LINE_NOPROP
;
21058 mode_line_string_face_prop
= Qnil
;
21059 mode_line_string_list
= Qnil
;
21060 string_start
= MODE_LINE_NOPROP_LEN (0);
21064 mode_line_target
= MODE_LINE_STRING
;
21065 mode_line_string_list
= Qnil
;
21066 mode_line_string_face
= face
;
21067 mode_line_string_face_prop
21068 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
21071 push_kboard (FRAME_KBOARD (it
.f
));
21072 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
21077 len
= MODE_LINE_NOPROP_LEN (string_start
);
21078 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
21082 mode_line_string_list
= Fnreverse (mode_line_string_list
);
21083 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
21084 empty_unibyte_string
);
21087 unbind_to (count
, Qnil
);
21091 /* Write a null-terminated, right justified decimal representation of
21092 the positive integer D to BUF using a minimal field width WIDTH. */
21095 pint2str (register char *buf
, register int width
, register ptrdiff_t d
)
21097 register char *p
= buf
;
21105 *p
++ = d
% 10 + '0';
21110 for (width
-= (int) (p
- buf
); width
> 0; --width
)
21121 /* Write a null-terminated, right justified decimal and "human
21122 readable" representation of the nonnegative integer D to BUF using
21123 a minimal field width WIDTH. D should be smaller than 999.5e24. */
21125 static const char power_letter
[] =
21139 pint2hrstr (char *buf
, int width
, ptrdiff_t d
)
21141 /* We aim to represent the nonnegative integer D as
21142 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
21143 ptrdiff_t quotient
= d
;
21145 /* -1 means: do not use TENTHS. */
21149 /* Length of QUOTIENT.TENTHS as a string. */
21155 if (1000 <= quotient
)
21157 /* Scale to the appropriate EXPONENT. */
21160 remainder
= quotient
% 1000;
21164 while (1000 <= quotient
);
21166 /* Round to nearest and decide whether to use TENTHS or not. */
21169 tenths
= remainder
/ 100;
21170 if (50 <= remainder
% 100)
21177 if (quotient
== 10)
21185 if (500 <= remainder
)
21187 if (quotient
< 999)
21198 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
21199 if (tenths
== -1 && quotient
<= 99)
21206 p
= psuffix
= buf
+ max (width
, length
);
21208 /* Print EXPONENT. */
21209 *psuffix
++ = power_letter
[exponent
];
21212 /* Print TENTHS. */
21215 *--p
= '0' + tenths
;
21219 /* Print QUOTIENT. */
21222 int digit
= quotient
% 10;
21223 *--p
= '0' + digit
;
21225 while ((quotient
/= 10) != 0);
21227 /* Print leading spaces. */
21232 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
21233 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
21234 type of CODING_SYSTEM. Return updated pointer into BUF. */
21236 static unsigned char invalid_eol_type
[] = "(*invalid*)";
21239 decode_mode_spec_coding (Lisp_Object coding_system
, register char *buf
, int eol_flag
)
21242 int multibyte
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
21243 const unsigned char *eol_str
;
21245 /* The EOL conversion we are using. */
21246 Lisp_Object eoltype
;
21248 val
= CODING_SYSTEM_SPEC (coding_system
);
21251 if (!VECTORP (val
)) /* Not yet decided. */
21253 *buf
++ = multibyte
? '-' : ' ';
21255 eoltype
= eol_mnemonic_undecided
;
21256 /* Don't mention EOL conversion if it isn't decided. */
21261 Lisp_Object eolvalue
;
21263 attrs
= AREF (val
, 0);
21264 eolvalue
= AREF (val
, 2);
21267 ? XFASTINT (CODING_ATTR_MNEMONIC (attrs
))
21272 /* The EOL conversion that is normal on this system. */
21274 if (NILP (eolvalue
)) /* Not yet decided. */
21275 eoltype
= eol_mnemonic_undecided
;
21276 else if (VECTORP (eolvalue
)) /* Not yet decided. */
21277 eoltype
= eol_mnemonic_undecided
;
21278 else /* eolvalue is Qunix, Qdos, or Qmac. */
21279 eoltype
= (EQ (eolvalue
, Qunix
)
21280 ? eol_mnemonic_unix
21281 : (EQ (eolvalue
, Qdos
) == 1
21282 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
21288 /* Mention the EOL conversion if it is not the usual one. */
21289 if (STRINGP (eoltype
))
21291 eol_str
= SDATA (eoltype
);
21292 eol_str_len
= SBYTES (eoltype
);
21294 else if (CHARACTERP (eoltype
))
21296 unsigned char *tmp
= alloca (MAX_MULTIBYTE_LENGTH
);
21297 int c
= XFASTINT (eoltype
);
21298 eol_str_len
= CHAR_STRING (c
, tmp
);
21303 eol_str
= invalid_eol_type
;
21304 eol_str_len
= sizeof (invalid_eol_type
) - 1;
21306 memcpy (buf
, eol_str
, eol_str_len
);
21307 buf
+= eol_str_len
;
21313 /* Return a string for the output of a mode line %-spec for window W,
21314 generated by character C. FIELD_WIDTH > 0 means pad the string
21315 returned with spaces to that value. Return a Lisp string in
21316 *STRING if the resulting string is taken from that Lisp string.
21318 Note we operate on the current buffer for most purposes,
21319 the exception being w->base_line_pos. */
21321 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
21323 static const char *
21324 decode_mode_spec (struct window
*w
, register int c
, int field_width
,
21325 Lisp_Object
*string
)
21328 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21329 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
21330 struct buffer
*b
= current_buffer
;
21338 if (!NILP (BVAR (b
, read_only
)))
21340 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21345 /* This differs from %* only for a modified read-only buffer. */
21346 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21348 if (!NILP (BVAR (b
, read_only
)))
21353 /* This differs from %* in ignoring read-only-ness. */
21354 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21366 if (command_loop_level
> 5)
21368 p
= decode_mode_spec_buf
;
21369 for (i
= 0; i
< command_loop_level
; i
++)
21372 return decode_mode_spec_buf
;
21380 if (command_loop_level
> 5)
21382 p
= decode_mode_spec_buf
;
21383 for (i
= 0; i
< command_loop_level
; i
++)
21386 return decode_mode_spec_buf
;
21393 /* Let lots_of_dashes be a string of infinite length. */
21394 if (mode_line_target
== MODE_LINE_NOPROP
||
21395 mode_line_target
== MODE_LINE_STRING
)
21397 if (field_width
<= 0
21398 || field_width
> sizeof (lots_of_dashes
))
21400 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
21401 decode_mode_spec_buf
[i
] = '-';
21402 decode_mode_spec_buf
[i
] = '\0';
21403 return decode_mode_spec_buf
;
21406 return lots_of_dashes
;
21410 obj
= BVAR (b
, name
);
21414 /* %c and %l are ignored in `frame-title-format'.
21415 (In redisplay_internal, the frame title is drawn _before_ the
21416 windows are updated, so the stuff which depends on actual
21417 window contents (such as %l) may fail to render properly, or
21418 even crash emacs.) */
21419 if (mode_line_target
== MODE_LINE_TITLE
)
21423 ptrdiff_t col
= current_column ();
21424 wset_column_number_displayed (w
, make_number (col
));
21425 pint2str (decode_mode_spec_buf
, field_width
, col
);
21426 return decode_mode_spec_buf
;
21430 #ifndef SYSTEM_MALLOC
21432 if (NILP (Vmemory_full
))
21435 return "!MEM FULL! ";
21442 /* %F displays the frame name. */
21443 if (!NILP (f
->title
))
21444 return SSDATA (f
->title
);
21445 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
21446 return SSDATA (f
->name
);
21450 obj
= BVAR (b
, filename
);
21455 ptrdiff_t size
= ZV
- BEGV
;
21456 pint2str (decode_mode_spec_buf
, field_width
, size
);
21457 return decode_mode_spec_buf
;
21462 ptrdiff_t size
= ZV
- BEGV
;
21463 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
21464 return decode_mode_spec_buf
;
21469 ptrdiff_t startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
21470 ptrdiff_t topline
, nlines
, height
;
21473 /* %c and %l are ignored in `frame-title-format'. */
21474 if (mode_line_target
== MODE_LINE_TITLE
)
21477 startpos
= XMARKER (w
->start
)->charpos
;
21478 startpos_byte
= marker_byte_position (w
->start
);
21479 height
= WINDOW_TOTAL_LINES (w
);
21481 /* If we decided that this buffer isn't suitable for line numbers,
21482 don't forget that too fast. */
21483 if (EQ (w
->base_line_pos
, w
->buffer
))
21485 /* But do forget it, if the window shows a different buffer now. */
21486 else if (BUFFERP (w
->base_line_pos
))
21487 wset_base_line_pos (w
, Qnil
);
21489 /* If the buffer is very big, don't waste time. */
21490 if (INTEGERP (Vline_number_display_limit
)
21491 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
21493 wset_base_line_pos (w
, Qnil
);
21494 wset_base_line_number (w
, Qnil
);
21498 if (INTEGERP (w
->base_line_number
)
21499 && INTEGERP (w
->base_line_pos
)
21500 && XFASTINT (w
->base_line_pos
) <= startpos
)
21502 line
= XFASTINT (w
->base_line_number
);
21503 linepos
= XFASTINT (w
->base_line_pos
);
21504 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
21509 linepos
= BUF_BEGV (b
);
21510 linepos_byte
= BUF_BEGV_BYTE (b
);
21513 /* Count lines from base line to window start position. */
21514 nlines
= display_count_lines (linepos_byte
,
21518 topline
= nlines
+ line
;
21520 /* Determine a new base line, if the old one is too close
21521 or too far away, or if we did not have one.
21522 "Too close" means it's plausible a scroll-down would
21523 go back past it. */
21524 if (startpos
== BUF_BEGV (b
))
21526 wset_base_line_number (w
, make_number (topline
));
21527 wset_base_line_pos (w
, make_number (BUF_BEGV (b
)));
21529 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
21530 || linepos
== BUF_BEGV (b
))
21532 ptrdiff_t limit
= BUF_BEGV (b
);
21533 ptrdiff_t limit_byte
= BUF_BEGV_BYTE (b
);
21534 ptrdiff_t position
;
21535 ptrdiff_t distance
=
21536 (height
* 2 + 30) * line_number_display_limit_width
;
21538 if (startpos
- distance
> limit
)
21540 limit
= startpos
- distance
;
21541 limit_byte
= CHAR_TO_BYTE (limit
);
21544 nlines
= display_count_lines (startpos_byte
,
21546 - (height
* 2 + 30),
21548 /* If we couldn't find the lines we wanted within
21549 line_number_display_limit_width chars per line,
21550 give up on line numbers for this window. */
21551 if (position
== limit_byte
&& limit
== startpos
- distance
)
21553 wset_base_line_pos (w
, w
->buffer
);
21554 wset_base_line_number (w
, Qnil
);
21558 wset_base_line_number (w
, make_number (topline
- nlines
));
21559 wset_base_line_pos (w
, make_number (BYTE_TO_CHAR (position
)));
21562 /* Now count lines from the start pos to point. */
21563 nlines
= display_count_lines (startpos_byte
,
21564 PT_BYTE
, PT
, &junk
);
21566 /* Record that we did display the line number. */
21567 line_number_displayed
= 1;
21569 /* Make the string to show. */
21570 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
21571 return decode_mode_spec_buf
;
21574 char* p
= decode_mode_spec_buf
;
21575 int pad
= field_width
- 2;
21581 return decode_mode_spec_buf
;
21587 obj
= BVAR (b
, mode_name
);
21591 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
21597 ptrdiff_t pos
= marker_position (w
->start
);
21598 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
21600 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
21602 if (pos
<= BUF_BEGV (b
))
21607 else if (pos
<= BUF_BEGV (b
))
21611 if (total
> 1000000)
21612 /* Do it differently for a large value, to avoid overflow. */
21613 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
21615 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
21616 /* We can't normally display a 3-digit number,
21617 so get us a 2-digit number that is close. */
21620 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
21621 return decode_mode_spec_buf
;
21625 /* Display percentage of size above the bottom of the screen. */
21628 ptrdiff_t toppos
= marker_position (w
->start
);
21629 ptrdiff_t botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
21630 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
21632 if (botpos
>= BUF_ZV (b
))
21634 if (toppos
<= BUF_BEGV (b
))
21641 if (total
> 1000000)
21642 /* Do it differently for a large value, to avoid overflow. */
21643 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
21645 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
21646 /* We can't normally display a 3-digit number,
21647 so get us a 2-digit number that is close. */
21650 if (toppos
<= BUF_BEGV (b
))
21651 sprintf (decode_mode_spec_buf
, "Top%2"pD
"d%%", total
);
21653 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
21654 return decode_mode_spec_buf
;
21659 /* status of process */
21660 obj
= Fget_buffer_process (Fcurrent_buffer ());
21662 return "no process";
21664 obj
= Fsymbol_name (Fprocess_status (obj
));
21670 ptrdiff_t count
= inhibit_garbage_collection ();
21671 Lisp_Object val
= call1 (intern ("file-remote-p"),
21672 BVAR (current_buffer
, directory
));
21673 unbind_to (count
, Qnil
);
21681 case 't': /* indicate TEXT or BINARY */
21685 /* coding-system (not including end-of-line format) */
21687 /* coding-system (including end-of-line type) */
21689 int eol_flag
= (c
== 'Z');
21690 char *p
= decode_mode_spec_buf
;
21692 if (! FRAME_WINDOW_P (f
))
21694 /* No need to mention EOL here--the terminal never needs
21695 to do EOL conversion. */
21696 p
= decode_mode_spec_coding (CODING_ID_NAME
21697 (FRAME_KEYBOARD_CODING (f
)->id
),
21699 p
= decode_mode_spec_coding (CODING_ID_NAME
21700 (FRAME_TERMINAL_CODING (f
)->id
),
21703 p
= decode_mode_spec_coding (BVAR (b
, buffer_file_coding_system
),
21706 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
21707 #ifdef subprocesses
21708 obj
= Fget_buffer_process (Fcurrent_buffer ());
21709 if (PROCESSP (obj
))
21711 p
= decode_mode_spec_coding
21712 (XPROCESS (obj
)->decode_coding_system
, p
, eol_flag
);
21713 p
= decode_mode_spec_coding
21714 (XPROCESS (obj
)->encode_coding_system
, p
, eol_flag
);
21716 #endif /* subprocesses */
21719 return decode_mode_spec_buf
;
21726 return SSDATA (obj
);
21733 /* Count up to COUNT lines starting from START_BYTE.
21734 But don't go beyond LIMIT_BYTE.
21735 Return the number of lines thus found (always nonnegative).
21737 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
21740 display_count_lines (ptrdiff_t start_byte
,
21741 ptrdiff_t limit_byte
, ptrdiff_t count
,
21742 ptrdiff_t *byte_pos_ptr
)
21744 register unsigned char *cursor
;
21745 unsigned char *base
;
21747 register ptrdiff_t ceiling
;
21748 register unsigned char *ceiling_addr
;
21749 ptrdiff_t orig_count
= count
;
21751 /* If we are not in selective display mode,
21752 check only for newlines. */
21753 int selective_display
= (!NILP (BVAR (current_buffer
, selective_display
))
21754 && !INTEGERP (BVAR (current_buffer
, selective_display
)));
21758 while (start_byte
< limit_byte
)
21760 ceiling
= BUFFER_CEILING_OF (start_byte
);
21761 ceiling
= min (limit_byte
- 1, ceiling
);
21762 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
21763 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
21766 if (selective_display
)
21767 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
21770 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
21773 if (cursor
!= ceiling_addr
)
21777 start_byte
+= cursor
- base
+ 1;
21778 *byte_pos_ptr
= start_byte
;
21782 if (++cursor
== ceiling_addr
)
21788 start_byte
+= cursor
- base
;
21793 while (start_byte
> limit_byte
)
21795 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
21796 ceiling
= max (limit_byte
, ceiling
);
21797 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
21798 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
21801 if (selective_display
)
21802 while (--cursor
!= ceiling_addr
21803 && *cursor
!= '\n' && *cursor
!= 015)
21806 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
21809 if (cursor
!= ceiling_addr
)
21813 start_byte
+= cursor
- base
+ 1;
21814 *byte_pos_ptr
= start_byte
;
21815 /* When scanning backwards, we should
21816 not count the newline posterior to which we stop. */
21817 return - orig_count
- 1;
21823 /* Here we add 1 to compensate for the last decrement
21824 of CURSOR, which took it past the valid range. */
21825 start_byte
+= cursor
- base
+ 1;
21829 *byte_pos_ptr
= limit_byte
;
21832 return - orig_count
+ count
;
21833 return orig_count
- count
;
21839 /***********************************************************************
21841 ***********************************************************************/
21843 /* Display a NUL-terminated string, starting with index START.
21845 If STRING is non-null, display that C string. Otherwise, the Lisp
21846 string LISP_STRING is displayed. There's a case that STRING is
21847 non-null and LISP_STRING is not nil. It means STRING is a string
21848 data of LISP_STRING. In that case, we display LISP_STRING while
21849 ignoring its text properties.
21851 If FACE_STRING is not nil, FACE_STRING_POS is a position in
21852 FACE_STRING. Display STRING or LISP_STRING with the face at
21853 FACE_STRING_POS in FACE_STRING:
21855 Display the string in the environment given by IT, but use the
21856 standard display table, temporarily.
21858 FIELD_WIDTH is the minimum number of output glyphs to produce.
21859 If STRING has fewer characters than FIELD_WIDTH, pad to the right
21860 with spaces. If STRING has more characters, more than FIELD_WIDTH
21861 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
21863 PRECISION is the maximum number of characters to output from
21864 STRING. PRECISION < 0 means don't truncate the string.
21866 This is roughly equivalent to printf format specifiers:
21868 FIELD_WIDTH PRECISION PRINTF
21869 ----------------------------------------
21875 MULTIBYTE zero means do not display multibyte chars, > 0 means do
21876 display them, and < 0 means obey the current buffer's value of
21877 enable_multibyte_characters.
21879 Value is the number of columns displayed. */
21882 display_string (const char *string
, Lisp_Object lisp_string
, Lisp_Object face_string
,
21883 ptrdiff_t face_string_pos
, ptrdiff_t start
, struct it
*it
,
21884 int field_width
, int precision
, int max_x
, int multibyte
)
21886 int hpos_at_start
= it
->hpos
;
21887 int saved_face_id
= it
->face_id
;
21888 struct glyph_row
*row
= it
->glyph_row
;
21889 ptrdiff_t it_charpos
;
21891 /* Initialize the iterator IT for iteration over STRING beginning
21892 with index START. */
21893 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
21894 precision
, field_width
, multibyte
);
21895 if (string
&& STRINGP (lisp_string
))
21896 /* LISP_STRING is the one returned by decode_mode_spec. We should
21897 ignore its text properties. */
21898 it
->stop_charpos
= it
->end_charpos
;
21900 /* If displaying STRING, set up the face of the iterator from
21901 FACE_STRING, if that's given. */
21902 if (STRINGP (face_string
))
21908 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
21909 0, it
->region_beg_charpos
,
21910 it
->region_end_charpos
,
21911 &endptr
, it
->base_face_id
, 0);
21912 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21913 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
21916 /* Set max_x to the maximum allowed X position. Don't let it go
21917 beyond the right edge of the window. */
21919 max_x
= it
->last_visible_x
;
21921 max_x
= min (max_x
, it
->last_visible_x
);
21923 /* Skip over display elements that are not visible. because IT->w is
21925 if (it
->current_x
< it
->first_visible_x
)
21926 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
21927 MOVE_TO_POS
| MOVE_TO_X
);
21929 row
->ascent
= it
->max_ascent
;
21930 row
->height
= it
->max_ascent
+ it
->max_descent
;
21931 row
->phys_ascent
= it
->max_phys_ascent
;
21932 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
21933 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
21935 if (STRINGP (it
->string
))
21936 it_charpos
= IT_STRING_CHARPOS (*it
);
21938 it_charpos
= IT_CHARPOS (*it
);
21940 /* This condition is for the case that we are called with current_x
21941 past last_visible_x. */
21942 while (it
->current_x
< max_x
)
21944 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
21946 /* Get the next display element. */
21947 if (!get_next_display_element (it
))
21950 /* Produce glyphs. */
21951 x_before
= it
->current_x
;
21952 n_glyphs_before
= row
->used
[TEXT_AREA
];
21953 PRODUCE_GLYPHS (it
);
21955 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
21958 while (i
< nglyphs
)
21960 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
21962 if (it
->line_wrap
!= TRUNCATE
21963 && x
+ glyph
->pixel_width
> max_x
)
21965 /* End of continued line or max_x reached. */
21966 if (CHAR_GLYPH_PADDING_P (*glyph
))
21968 /* A wide character is unbreakable. */
21969 if (row
->reversed_p
)
21970 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
21971 - n_glyphs_before
);
21972 row
->used
[TEXT_AREA
] = n_glyphs_before
;
21973 it
->current_x
= x_before
;
21977 if (row
->reversed_p
)
21978 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
21979 - (n_glyphs_before
+ i
));
21980 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
21985 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
21987 /* Glyph is at least partially visible. */
21989 if (x
< it
->first_visible_x
)
21990 row
->x
= x
- it
->first_visible_x
;
21994 /* Glyph is off the left margin of the display area.
21995 Should not happen. */
21999 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
22000 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
22001 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
22002 row
->phys_height
= max (row
->phys_height
,
22003 it
->max_phys_ascent
+ it
->max_phys_descent
);
22004 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
22005 it
->max_extra_line_spacing
);
22006 x
+= glyph
->pixel_width
;
22010 /* Stop if max_x reached. */
22014 /* Stop at line ends. */
22015 if (ITERATOR_AT_END_OF_LINE_P (it
))
22017 it
->continuation_lines_width
= 0;
22021 set_iterator_to_next (it
, 1);
22022 if (STRINGP (it
->string
))
22023 it_charpos
= IT_STRING_CHARPOS (*it
);
22025 it_charpos
= IT_CHARPOS (*it
);
22027 /* Stop if truncating at the right edge. */
22028 if (it
->line_wrap
== TRUNCATE
22029 && it
->current_x
>= it
->last_visible_x
)
22031 /* Add truncation mark, but don't do it if the line is
22032 truncated at a padding space. */
22033 if (it_charpos
< it
->string_nchars
)
22035 if (!FRAME_WINDOW_P (it
->f
))
22039 if (it
->current_x
> it
->last_visible_x
)
22041 if (!row
->reversed_p
)
22043 for (ii
= row
->used
[TEXT_AREA
] - 1; ii
> 0; --ii
)
22044 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
22049 for (ii
= 0; ii
< row
->used
[TEXT_AREA
]; ii
++)
22050 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
22052 unproduce_glyphs (it
, ii
+ 1);
22053 ii
= row
->used
[TEXT_AREA
] - (ii
+ 1);
22055 for (n
= row
->used
[TEXT_AREA
]; ii
< n
; ++ii
)
22057 row
->used
[TEXT_AREA
] = ii
;
22058 produce_special_glyphs (it
, IT_TRUNCATION
);
22061 produce_special_glyphs (it
, IT_TRUNCATION
);
22063 row
->truncated_on_right_p
= 1;
22069 /* Maybe insert a truncation at the left. */
22070 if (it
->first_visible_x
22073 if (!FRAME_WINDOW_P (it
->f
)
22074 || (row
->reversed_p
22075 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
22076 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
22077 insert_left_trunc_glyphs (it
);
22078 row
->truncated_on_left_p
= 1;
22081 it
->face_id
= saved_face_id
;
22083 /* Value is number of columns displayed. */
22084 return it
->hpos
- hpos_at_start
;
22089 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
22090 appears as an element of LIST or as the car of an element of LIST.
22091 If PROPVAL is a list, compare each element against LIST in that
22092 way, and return 1/2 if any element of PROPVAL is found in LIST.
22093 Otherwise return 0. This function cannot quit.
22094 The return value is 2 if the text is invisible but with an ellipsis
22095 and 1 if it's invisible and without an ellipsis. */
22098 invisible_p (register Lisp_Object propval
, Lisp_Object list
)
22100 register Lisp_Object tail
, proptail
;
22102 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
22104 register Lisp_Object tem
;
22106 if (EQ (propval
, tem
))
22108 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
22109 return NILP (XCDR (tem
)) ? 1 : 2;
22112 if (CONSP (propval
))
22114 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
22116 Lisp_Object propelt
;
22117 propelt
= XCAR (proptail
);
22118 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
22120 register Lisp_Object tem
;
22122 if (EQ (propelt
, tem
))
22124 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
22125 return NILP (XCDR (tem
)) ? 1 : 2;
22133 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
22134 doc
: /* Non-nil if the property makes the text invisible.
22135 POS-OR-PROP can be a marker or number, in which case it is taken to be
22136 a position in the current buffer and the value of the `invisible' property
22137 is checked; or it can be some other value, which is then presumed to be the
22138 value of the `invisible' property of the text of interest.
22139 The non-nil value returned can be t for truly invisible text or something
22140 else if the text is replaced by an ellipsis. */)
22141 (Lisp_Object pos_or_prop
)
22144 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
22145 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
22147 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
22148 return (invis
== 0 ? Qnil
22150 : make_number (invis
));
22153 /* Calculate a width or height in pixels from a specification using
22154 the following elements:
22157 NUM - a (fractional) multiple of the default font width/height
22158 (NUM) - specifies exactly NUM pixels
22159 UNIT - a fixed number of pixels, see below.
22160 ELEMENT - size of a display element in pixels, see below.
22161 (NUM . SPEC) - equals NUM * SPEC
22162 (+ SPEC SPEC ...) - add pixel values
22163 (- SPEC SPEC ...) - subtract pixel values
22164 (- SPEC) - negate pixel value
22167 INT or FLOAT - a number constant
22168 SYMBOL - use symbol's (buffer local) variable binding.
22171 in - pixels per inch *)
22172 mm - pixels per 1/1000 meter *)
22173 cm - pixels per 1/100 meter *)
22174 width - width of current font in pixels.
22175 height - height of current font in pixels.
22177 *) using the ratio(s) defined in display-pixels-per-inch.
22181 left-fringe - left fringe width in pixels
22182 right-fringe - right fringe width in pixels
22184 left-margin - left margin width in pixels
22185 right-margin - right margin width in pixels
22187 scroll-bar - scroll-bar area width in pixels
22191 Pixels corresponding to 5 inches:
22194 Total width of non-text areas on left side of window (if scroll-bar is on left):
22195 '(space :width (+ left-fringe left-margin scroll-bar))
22197 Align to first text column (in header line):
22198 '(space :align-to 0)
22200 Align to middle of text area minus half the width of variable `my-image'
22201 containing a loaded image:
22202 '(space :align-to (0.5 . (- text my-image)))
22204 Width of left margin minus width of 1 character in the default font:
22205 '(space :width (- left-margin 1))
22207 Width of left margin minus width of 2 characters in the current font:
22208 '(space :width (- left-margin (2 . width)))
22210 Center 1 character over left-margin (in header line):
22211 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
22213 Different ways to express width of left fringe plus left margin minus one pixel:
22214 '(space :width (- (+ left-fringe left-margin) (1)))
22215 '(space :width (+ left-fringe left-margin (- (1))))
22216 '(space :width (+ left-fringe left-margin (-1)))
22220 #define NUMVAL(X) \
22221 ((INTEGERP (X) || FLOATP (X)) \
22226 calc_pixel_width_or_height (double *res
, struct it
*it
, Lisp_Object prop
,
22227 struct font
*font
, int width_p
, int *align_to
)
22231 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
22232 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
22235 return OK_PIXELS (0);
22237 eassert (FRAME_LIVE_P (it
->f
));
22239 if (SYMBOLP (prop
))
22241 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
22243 char *unit
= SSDATA (SYMBOL_NAME (prop
));
22245 if (unit
[0] == 'i' && unit
[1] == 'n')
22247 else if (unit
[0] == 'm' && unit
[1] == 'm')
22249 else if (unit
[0] == 'c' && unit
[1] == 'm')
22256 #ifdef HAVE_WINDOW_SYSTEM
22257 if (FRAME_WINDOW_P (it
->f
)
22259 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
22260 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
22262 return OK_PIXELS (ppi
/ pixels
);
22265 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
22266 || (CONSP (Vdisplay_pixels_per_inch
)
22268 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
22269 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
22271 return OK_PIXELS (ppi
/ pixels
);
22277 #ifdef HAVE_WINDOW_SYSTEM
22278 if (EQ (prop
, Qheight
))
22279 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
22280 if (EQ (prop
, Qwidth
))
22281 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
22283 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
22284 return OK_PIXELS (1);
22287 if (EQ (prop
, Qtext
))
22288 return OK_PIXELS (width_p
22289 ? window_box_width (it
->w
, TEXT_AREA
)
22290 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
22292 if (align_to
&& *align_to
< 0)
22295 if (EQ (prop
, Qleft
))
22296 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
22297 if (EQ (prop
, Qright
))
22298 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
22299 if (EQ (prop
, Qcenter
))
22300 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
22301 + window_box_width (it
->w
, TEXT_AREA
) / 2);
22302 if (EQ (prop
, Qleft_fringe
))
22303 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22304 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
22305 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
22306 if (EQ (prop
, Qright_fringe
))
22307 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22308 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
22309 : window_box_right_offset (it
->w
, TEXT_AREA
));
22310 if (EQ (prop
, Qleft_margin
))
22311 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
22312 if (EQ (prop
, Qright_margin
))
22313 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
22314 if (EQ (prop
, Qscroll_bar
))
22315 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
22317 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
22318 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22319 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
22324 if (EQ (prop
, Qleft_fringe
))
22325 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
22326 if (EQ (prop
, Qright_fringe
))
22327 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
22328 if (EQ (prop
, Qleft_margin
))
22329 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
22330 if (EQ (prop
, Qright_margin
))
22331 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
22332 if (EQ (prop
, Qscroll_bar
))
22333 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
22336 prop
= buffer_local_value_1 (prop
, it
->w
->buffer
);
22337 if (EQ (prop
, Qunbound
))
22341 if (INTEGERP (prop
) || FLOATP (prop
))
22343 int base_unit
= (width_p
22344 ? FRAME_COLUMN_WIDTH (it
->f
)
22345 : FRAME_LINE_HEIGHT (it
->f
));
22346 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
22351 Lisp_Object car
= XCAR (prop
);
22352 Lisp_Object cdr
= XCDR (prop
);
22356 #ifdef HAVE_WINDOW_SYSTEM
22357 if (FRAME_WINDOW_P (it
->f
)
22358 && valid_image_p (prop
))
22360 ptrdiff_t id
= lookup_image (it
->f
, prop
);
22361 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
22363 return OK_PIXELS (width_p
? img
->width
: img
->height
);
22366 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
22372 while (CONSP (cdr
))
22374 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
22375 font
, width_p
, align_to
))
22378 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
22383 if (EQ (car
, Qminus
))
22385 return OK_PIXELS (pixels
);
22388 car
= buffer_local_value_1 (car
, it
->w
->buffer
);
22389 if (EQ (car
, Qunbound
))
22393 if (INTEGERP (car
) || FLOATP (car
))
22396 pixels
= XFLOATINT (car
);
22398 return OK_PIXELS (pixels
);
22399 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
22400 font
, width_p
, align_to
))
22401 return OK_PIXELS (pixels
* fact
);
22412 /***********************************************************************
22414 ***********************************************************************/
22416 #ifdef HAVE_WINDOW_SYSTEM
22421 dump_glyph_string (struct glyph_string
*s
)
22423 fprintf (stderr
, "glyph string\n");
22424 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
22425 s
->x
, s
->y
, s
->width
, s
->height
);
22426 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
22427 fprintf (stderr
, " hl = %d\n", s
->hl
);
22428 fprintf (stderr
, " left overhang = %d, right = %d\n",
22429 s
->left_overhang
, s
->right_overhang
);
22430 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
22431 fprintf (stderr
, " extends to end of line = %d\n",
22432 s
->extends_to_end_of_line_p
);
22433 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
22434 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
22437 #endif /* GLYPH_DEBUG */
22439 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
22440 of XChar2b structures for S; it can't be allocated in
22441 init_glyph_string because it must be allocated via `alloca'. W
22442 is the window on which S is drawn. ROW and AREA are the glyph row
22443 and area within the row from which S is constructed. START is the
22444 index of the first glyph structure covered by S. HL is a
22445 face-override for drawing S. */
22448 #define OPTIONAL_HDC(hdc) HDC hdc,
22449 #define DECLARE_HDC(hdc) HDC hdc;
22450 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
22451 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
22454 #ifndef OPTIONAL_HDC
22455 #define OPTIONAL_HDC(hdc)
22456 #define DECLARE_HDC(hdc)
22457 #define ALLOCATE_HDC(hdc, f)
22458 #define RELEASE_HDC(hdc, f)
22462 init_glyph_string (struct glyph_string
*s
,
22464 XChar2b
*char2b
, struct window
*w
, struct glyph_row
*row
,
22465 enum glyph_row_area area
, int start
, enum draw_glyphs_face hl
)
22467 memset (s
, 0, sizeof *s
);
22469 s
->f
= XFRAME (w
->frame
);
22473 s
->display
= FRAME_X_DISPLAY (s
->f
);
22474 s
->window
= FRAME_X_WINDOW (s
->f
);
22475 s
->char2b
= char2b
;
22479 s
->first_glyph
= row
->glyphs
[area
] + start
;
22480 s
->height
= row
->height
;
22481 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
22482 s
->ybase
= s
->y
+ row
->ascent
;
22486 /* Append the list of glyph strings with head H and tail T to the list
22487 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
22490 append_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
22491 struct glyph_string
*h
, struct glyph_string
*t
)
22505 /* Prepend the list of glyph strings with head H and tail T to the
22506 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
22510 prepend_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
22511 struct glyph_string
*h
, struct glyph_string
*t
)
22525 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
22526 Set *HEAD and *TAIL to the resulting list. */
22529 append_glyph_string (struct glyph_string
**head
, struct glyph_string
**tail
,
22530 struct glyph_string
*s
)
22532 s
->next
= s
->prev
= NULL
;
22533 append_glyph_string_lists (head
, tail
, s
, s
);
22537 /* Get face and two-byte form of character C in face FACE_ID on frame F.
22538 The encoding of C is returned in *CHAR2B. DISPLAY_P non-zero means
22539 make sure that X resources for the face returned are allocated.
22540 Value is a pointer to a realized face that is ready for display if
22541 DISPLAY_P is non-zero. */
22543 static inline struct face
*
22544 get_char_face_and_encoding (struct frame
*f
, int c
, int face_id
,
22545 XChar2b
*char2b
, int display_p
)
22547 struct face
*face
= FACE_FROM_ID (f
, face_id
);
22551 unsigned code
= face
->font
->driver
->encode_char (face
->font
, c
);
22553 if (code
!= FONT_INVALID_CODE
)
22554 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22556 STORE_XCHAR2B (char2b
, 0, 0);
22559 /* Make sure X resources of the face are allocated. */
22560 #ifdef HAVE_X_WINDOWS
22564 eassert (face
!= NULL
);
22565 PREPARE_FACE_FOR_DISPLAY (f
, face
);
22572 /* Get face and two-byte form of character glyph GLYPH on frame F.
22573 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
22574 a pointer to a realized face that is ready for display. */
22576 static inline struct face
*
22577 get_glyph_face_and_encoding (struct frame
*f
, struct glyph
*glyph
,
22578 XChar2b
*char2b
, int *two_byte_p
)
22582 eassert (glyph
->type
== CHAR_GLYPH
);
22583 face
= FACE_FROM_ID (f
, glyph
->face_id
);
22592 if (CHAR_BYTE8_P (glyph
->u
.ch
))
22593 code
= CHAR_TO_BYTE8 (glyph
->u
.ch
);
22595 code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
22597 if (code
!= FONT_INVALID_CODE
)
22598 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22600 STORE_XCHAR2B (char2b
, 0, 0);
22603 /* Make sure X resources of the face are allocated. */
22604 eassert (face
!= NULL
);
22605 PREPARE_FACE_FOR_DISPLAY (f
, face
);
22610 /* Get glyph code of character C in FONT in the two-byte form CHAR2B.
22611 Return 1 if FONT has a glyph for C, otherwise return 0. */
22614 get_char_glyph_code (int c
, struct font
*font
, XChar2b
*char2b
)
22618 if (CHAR_BYTE8_P (c
))
22619 code
= CHAR_TO_BYTE8 (c
);
22621 code
= font
->driver
->encode_char (font
, c
);
22623 if (code
== FONT_INVALID_CODE
)
22625 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22630 /* Fill glyph string S with composition components specified by S->cmp.
22632 BASE_FACE is the base face of the composition.
22633 S->cmp_from is the index of the first component for S.
22635 OVERLAPS non-zero means S should draw the foreground only, and use
22636 its physical height for clipping. See also draw_glyphs.
22638 Value is the index of a component not in S. */
22641 fill_composite_glyph_string (struct glyph_string
*s
, struct face
*base_face
,
22645 /* For all glyphs of this composition, starting at the offset
22646 S->cmp_from, until we reach the end of the definition or encounter a
22647 glyph that requires the different face, add it to S. */
22652 s
->for_overlaps
= overlaps
;
22655 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
22657 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
22659 /* TAB in a composition means display glyphs with padding space
22660 on the left or right. */
22663 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
22666 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
22673 s
->font
= s
->face
->font
;
22675 else if (s
->face
!= face
)
22683 if (s
->face
== NULL
)
22685 s
->face
= base_face
->ascii_face
;
22686 s
->font
= s
->face
->font
;
22689 /* All glyph strings for the same composition has the same width,
22690 i.e. the width set for the first component of the composition. */
22691 s
->width
= s
->first_glyph
->pixel_width
;
22693 /* If the specified font could not be loaded, use the frame's
22694 default font, but record the fact that we couldn't load it in
22695 the glyph string so that we can draw rectangles for the
22696 characters of the glyph string. */
22697 if (s
->font
== NULL
)
22699 s
->font_not_found_p
= 1;
22700 s
->font
= FRAME_FONT (s
->f
);
22703 /* Adjust base line for subscript/superscript text. */
22704 s
->ybase
+= s
->first_glyph
->voffset
;
22706 /* This glyph string must always be drawn with 16-bit functions. */
22713 fill_gstring_glyph_string (struct glyph_string
*s
, int face_id
,
22714 int start
, int end
, int overlaps
)
22716 struct glyph
*glyph
, *last
;
22717 Lisp_Object lgstring
;
22720 s
->for_overlaps
= overlaps
;
22721 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22722 last
= s
->row
->glyphs
[s
->area
] + end
;
22723 s
->cmp_id
= glyph
->u
.cmp
.id
;
22724 s
->cmp_from
= glyph
->slice
.cmp
.from
;
22725 s
->cmp_to
= glyph
->slice
.cmp
.to
+ 1;
22726 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
22727 lgstring
= composition_gstring_from_id (s
->cmp_id
);
22728 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
22730 while (glyph
< last
22731 && glyph
->u
.cmp
.automatic
22732 && glyph
->u
.cmp
.id
== s
->cmp_id
22733 && s
->cmp_to
== glyph
->slice
.cmp
.from
)
22734 s
->cmp_to
= (glyph
++)->slice
.cmp
.to
+ 1;
22736 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
22738 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
22739 unsigned code
= LGLYPH_CODE (lglyph
);
22741 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
22743 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
22744 return glyph
- s
->row
->glyphs
[s
->area
];
22748 /* Fill glyph string S from a sequence glyphs for glyphless characters.
22749 See the comment of fill_glyph_string for arguments.
22750 Value is the index of the first glyph not in S. */
22754 fill_glyphless_glyph_string (struct glyph_string
*s
, int face_id
,
22755 int start
, int end
, int overlaps
)
22757 struct glyph
*glyph
, *last
;
22760 eassert (s
->first_glyph
->type
== GLYPHLESS_GLYPH
);
22761 s
->for_overlaps
= overlaps
;
22762 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22763 last
= s
->row
->glyphs
[s
->area
] + end
;
22764 voffset
= glyph
->voffset
;
22765 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
22766 s
->font
= s
->face
->font
? s
->face
->font
: FRAME_FONT (s
->f
);
22768 s
->width
= glyph
->pixel_width
;
22770 while (glyph
< last
22771 && glyph
->type
== GLYPHLESS_GLYPH
22772 && glyph
->voffset
== voffset
22773 && glyph
->face_id
== face_id
)
22776 s
->width
+= glyph
->pixel_width
;
22779 s
->ybase
+= voffset
;
22780 return glyph
- s
->row
->glyphs
[s
->area
];
22784 /* Fill glyph string S from a sequence of character glyphs.
22786 FACE_ID is the face id of the string. START is the index of the
22787 first glyph to consider, END is the index of the last + 1.
22788 OVERLAPS non-zero means S should draw the foreground only, and use
22789 its physical height for clipping. See also draw_glyphs.
22791 Value is the index of the first glyph not in S. */
22794 fill_glyph_string (struct glyph_string
*s
, int face_id
,
22795 int start
, int end
, int overlaps
)
22797 struct glyph
*glyph
, *last
;
22799 int glyph_not_available_p
;
22801 eassert (s
->f
== XFRAME (s
->w
->frame
));
22802 eassert (s
->nchars
== 0);
22803 eassert (start
>= 0 && end
> start
);
22805 s
->for_overlaps
= overlaps
;
22806 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22807 last
= s
->row
->glyphs
[s
->area
] + end
;
22808 voffset
= glyph
->voffset
;
22809 s
->padding_p
= glyph
->padding_p
;
22810 glyph_not_available_p
= glyph
->glyph_not_available_p
;
22812 while (glyph
< last
22813 && glyph
->type
== CHAR_GLYPH
22814 && glyph
->voffset
== voffset
22815 /* Same face id implies same font, nowadays. */
22816 && glyph
->face_id
== face_id
22817 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
22821 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
22822 s
->char2b
+ s
->nchars
,
22824 s
->two_byte_p
= two_byte_p
;
22826 eassert (s
->nchars
<= end
- start
);
22827 s
->width
+= glyph
->pixel_width
;
22828 if (glyph
++->padding_p
!= s
->padding_p
)
22832 s
->font
= s
->face
->font
;
22834 /* If the specified font could not be loaded, use the frame's font,
22835 but record the fact that we couldn't load it in
22836 S->font_not_found_p so that we can draw rectangles for the
22837 characters of the glyph string. */
22838 if (s
->font
== NULL
|| glyph_not_available_p
)
22840 s
->font_not_found_p
= 1;
22841 s
->font
= FRAME_FONT (s
->f
);
22844 /* Adjust base line for subscript/superscript text. */
22845 s
->ybase
+= voffset
;
22847 eassert (s
->face
&& s
->face
->gc
);
22848 return glyph
- s
->row
->glyphs
[s
->area
];
22852 /* Fill glyph string S from image glyph S->first_glyph. */
22855 fill_image_glyph_string (struct glyph_string
*s
)
22857 eassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
22858 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
22860 s
->slice
= s
->first_glyph
->slice
.img
;
22861 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
22862 s
->font
= s
->face
->font
;
22863 s
->width
= s
->first_glyph
->pixel_width
;
22865 /* Adjust base line for subscript/superscript text. */
22866 s
->ybase
+= s
->first_glyph
->voffset
;
22870 /* Fill glyph string S from a sequence of stretch glyphs.
22872 START is the index of the first glyph to consider,
22873 END is the index of the last + 1.
22875 Value is the index of the first glyph not in S. */
22878 fill_stretch_glyph_string (struct glyph_string
*s
, int start
, int end
)
22880 struct glyph
*glyph
, *last
;
22881 int voffset
, face_id
;
22883 eassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
22885 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22886 last
= s
->row
->glyphs
[s
->area
] + end
;
22887 face_id
= glyph
->face_id
;
22888 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
22889 s
->font
= s
->face
->font
;
22890 s
->width
= glyph
->pixel_width
;
22892 voffset
= glyph
->voffset
;
22896 && glyph
->type
== STRETCH_GLYPH
22897 && glyph
->voffset
== voffset
22898 && glyph
->face_id
== face_id
);
22900 s
->width
+= glyph
->pixel_width
;
22902 /* Adjust base line for subscript/superscript text. */
22903 s
->ybase
+= voffset
;
22905 /* The case that face->gc == 0 is handled when drawing the glyph
22906 string by calling PREPARE_FACE_FOR_DISPLAY. */
22908 return glyph
- s
->row
->glyphs
[s
->area
];
22911 static struct font_metrics
*
22912 get_per_char_metric (struct font
*font
, XChar2b
*char2b
)
22914 static struct font_metrics metrics
;
22915 unsigned code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
22917 if (! font
|| code
== FONT_INVALID_CODE
)
22919 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
22924 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
22925 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
22926 assumed to be zero. */
22929 x_get_glyph_overhangs (struct glyph
*glyph
, struct frame
*f
, int *left
, int *right
)
22931 *left
= *right
= 0;
22933 if (glyph
->type
== CHAR_GLYPH
)
22937 struct font_metrics
*pcm
;
22939 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
22940 if (face
->font
&& (pcm
= get_per_char_metric (face
->font
, &char2b
)))
22942 if (pcm
->rbearing
> pcm
->width
)
22943 *right
= pcm
->rbearing
- pcm
->width
;
22944 if (pcm
->lbearing
< 0)
22945 *left
= -pcm
->lbearing
;
22948 else if (glyph
->type
== COMPOSITE_GLYPH
)
22950 if (! glyph
->u
.cmp
.automatic
)
22952 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
22954 if (cmp
->rbearing
> cmp
->pixel_width
)
22955 *right
= cmp
->rbearing
- cmp
->pixel_width
;
22956 if (cmp
->lbearing
< 0)
22957 *left
= - cmp
->lbearing
;
22961 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
22962 struct font_metrics metrics
;
22964 composition_gstring_width (gstring
, glyph
->slice
.cmp
.from
,
22965 glyph
->slice
.cmp
.to
+ 1, &metrics
);
22966 if (metrics
.rbearing
> metrics
.width
)
22967 *right
= metrics
.rbearing
- metrics
.width
;
22968 if (metrics
.lbearing
< 0)
22969 *left
= - metrics
.lbearing
;
22975 /* Return the index of the first glyph preceding glyph string S that
22976 is overwritten by S because of S's left overhang. Value is -1
22977 if no glyphs are overwritten. */
22980 left_overwritten (struct glyph_string
*s
)
22984 if (s
->left_overhang
)
22987 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
22988 int first
= s
->first_glyph
- glyphs
;
22990 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
22991 x
-= glyphs
[i
].pixel_width
;
23002 /* Return the index of the first glyph preceding glyph string S that
23003 is overwriting S because of its right overhang. Value is -1 if no
23004 glyph in front of S overwrites S. */
23007 left_overwriting (struct glyph_string
*s
)
23010 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23011 int first
= s
->first_glyph
- glyphs
;
23015 for (i
= first
- 1; i
>= 0; --i
)
23018 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
23021 x
-= glyphs
[i
].pixel_width
;
23028 /* Return the index of the last glyph following glyph string S that is
23029 overwritten by S because of S's right overhang. Value is -1 if
23030 no such glyph is found. */
23033 right_overwritten (struct glyph_string
*s
)
23037 if (s
->right_overhang
)
23040 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23041 int first
= (s
->first_glyph
- glyphs
23042 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
23043 int end
= s
->row
->used
[s
->area
];
23045 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
23046 x
+= glyphs
[i
].pixel_width
;
23055 /* Return the index of the last glyph following glyph string S that
23056 overwrites S because of its left overhang. Value is negative
23057 if no such glyph is found. */
23060 right_overwriting (struct glyph_string
*s
)
23063 int end
= s
->row
->used
[s
->area
];
23064 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23065 int first
= (s
->first_glyph
- glyphs
23066 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
23070 for (i
= first
; i
< end
; ++i
)
23073 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
23076 x
+= glyphs
[i
].pixel_width
;
23083 /* Set background width of glyph string S. START is the index of the
23084 first glyph following S. LAST_X is the right-most x-position + 1
23085 in the drawing area. */
23088 set_glyph_string_background_width (struct glyph_string
*s
, int start
, int last_x
)
23090 /* If the face of this glyph string has to be drawn to the end of
23091 the drawing area, set S->extends_to_end_of_line_p. */
23093 if (start
== s
->row
->used
[s
->area
]
23094 && s
->area
== TEXT_AREA
23095 && ((s
->row
->fill_line_p
23096 && (s
->hl
== DRAW_NORMAL_TEXT
23097 || s
->hl
== DRAW_IMAGE_RAISED
23098 || s
->hl
== DRAW_IMAGE_SUNKEN
))
23099 || s
->hl
== DRAW_MOUSE_FACE
))
23100 s
->extends_to_end_of_line_p
= 1;
23102 /* If S extends its face to the end of the line, set its
23103 background_width to the distance to the right edge of the drawing
23105 if (s
->extends_to_end_of_line_p
)
23106 s
->background_width
= last_x
- s
->x
+ 1;
23108 s
->background_width
= s
->width
;
23112 /* Compute overhangs and x-positions for glyph string S and its
23113 predecessors, or successors. X is the starting x-position for S.
23114 BACKWARD_P non-zero means process predecessors. */
23117 compute_overhangs_and_x (struct glyph_string
*s
, int x
, int backward_p
)
23123 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
23124 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
23134 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
23135 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
23145 /* The following macros are only called from draw_glyphs below.
23146 They reference the following parameters of that function directly:
23147 `w', `row', `area', and `overlap_p'
23148 as well as the following local variables:
23149 `s', `f', and `hdc' (in W32) */
23152 /* On W32, silently add local `hdc' variable to argument list of
23153 init_glyph_string. */
23154 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
23155 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
23157 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
23158 init_glyph_string (s, char2b, w, row, area, start, hl)
23161 /* Add a glyph string for a stretch glyph to the list of strings
23162 between HEAD and TAIL. START is the index of the stretch glyph in
23163 row area AREA of glyph row ROW. END is the index of the last glyph
23164 in that glyph row area. X is the current output position assigned
23165 to the new glyph string constructed. HL overrides that face of the
23166 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
23167 is the right-most x-position of the drawing area. */
23169 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
23170 and below -- keep them on one line. */
23171 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23174 s = alloca (sizeof *s); \
23175 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23176 START = fill_stretch_glyph_string (s, START, END); \
23177 append_glyph_string (&HEAD, &TAIL, s); \
23183 /* Add a glyph string for an image glyph to the list of strings
23184 between HEAD and TAIL. START is the index of the image glyph in
23185 row area AREA of glyph row ROW. END is the index of the last glyph
23186 in that glyph row area. X is the current output position assigned
23187 to the new glyph string constructed. HL overrides that face of the
23188 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
23189 is the right-most x-position of the drawing area. */
23191 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23194 s = alloca (sizeof *s); \
23195 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23196 fill_image_glyph_string (s); \
23197 append_glyph_string (&HEAD, &TAIL, s); \
23204 /* Add a glyph string for a sequence of character glyphs to the list
23205 of strings between HEAD and TAIL. START is the index of the first
23206 glyph in row area AREA of glyph row ROW that is part of the new
23207 glyph string. END is the index of the last glyph in that glyph row
23208 area. X is the current output position assigned to the new glyph
23209 string constructed. HL overrides that face of the glyph; e.g. it
23210 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
23211 right-most x-position of the drawing area. */
23213 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
23219 face_id = (row)->glyphs[area][START].face_id; \
23221 s = alloca (sizeof *s); \
23222 char2b = alloca ((END - START) * sizeof *char2b); \
23223 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23224 append_glyph_string (&HEAD, &TAIL, s); \
23226 START = fill_glyph_string (s, face_id, START, END, overlaps); \
23231 /* Add a glyph string for a composite sequence to the list of strings
23232 between HEAD and TAIL. START is the index of the first glyph in
23233 row area AREA of glyph row ROW that is part of the new glyph
23234 string. END is the index of the last glyph in that glyph row area.
23235 X is the current output position assigned to the new glyph string
23236 constructed. HL overrides that face of the glyph; e.g. it is
23237 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
23238 x-position of the drawing area. */
23240 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23242 int face_id = (row)->glyphs[area][START].face_id; \
23243 struct face *base_face = FACE_FROM_ID (f, face_id); \
23244 ptrdiff_t cmp_id = (row)->glyphs[area][START].u.cmp.id; \
23245 struct composition *cmp = composition_table[cmp_id]; \
23247 struct glyph_string *first_s = NULL; \
23250 char2b = alloca (cmp->glyph_len * sizeof *char2b); \
23252 /* Make glyph_strings for each glyph sequence that is drawable by \
23253 the same face, and append them to HEAD/TAIL. */ \
23254 for (n = 0; n < cmp->glyph_len;) \
23256 s = alloca (sizeof *s); \
23257 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23258 append_glyph_string (&(HEAD), &(TAIL), s); \
23264 n = fill_composite_glyph_string (s, base_face, overlaps); \
23272 /* Add a glyph string for a glyph-string sequence to the list of strings
23273 between HEAD and TAIL. */
23275 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23279 Lisp_Object gstring; \
23281 face_id = (row)->glyphs[area][START].face_id; \
23282 gstring = (composition_gstring_from_id \
23283 ((row)->glyphs[area][START].u.cmp.id)); \
23284 s = alloca (sizeof *s); \
23285 char2b = alloca (LGSTRING_GLYPH_LEN (gstring) * sizeof *char2b); \
23286 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23287 append_glyph_string (&(HEAD), &(TAIL), s); \
23289 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
23293 /* Add a glyph string for a sequence of glyphless character's glyphs
23294 to the list of strings between HEAD and TAIL. The meanings of
23295 arguments are the same as those of BUILD_CHAR_GLYPH_STRINGS. */
23297 #define BUILD_GLYPHLESS_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23302 face_id = (row)->glyphs[area][START].face_id; \
23304 s = alloca (sizeof *s); \
23305 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23306 append_glyph_string (&HEAD, &TAIL, s); \
23308 START = fill_glyphless_glyph_string (s, face_id, START, END, \
23314 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
23315 of AREA of glyph row ROW on window W between indices START and END.
23316 HL overrides the face for drawing glyph strings, e.g. it is
23317 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
23318 x-positions of the drawing area.
23320 This is an ugly monster macro construct because we must use alloca
23321 to allocate glyph strings (because draw_glyphs can be called
23322 asynchronously). */
23324 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
23327 HEAD = TAIL = NULL; \
23328 while (START < END) \
23330 struct glyph *first_glyph = (row)->glyphs[area] + START; \
23331 switch (first_glyph->type) \
23334 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
23338 case COMPOSITE_GLYPH: \
23339 if (first_glyph->u.cmp.automatic) \
23340 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
23343 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
23347 case STRETCH_GLYPH: \
23348 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
23352 case IMAGE_GLYPH: \
23353 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
23357 case GLYPHLESS_GLYPH: \
23358 BUILD_GLYPHLESS_GLYPH_STRING (START, END, HEAD, TAIL, \
23368 set_glyph_string_background_width (s, START, LAST_X); \
23375 /* Draw glyphs between START and END in AREA of ROW on window W,
23376 starting at x-position X. X is relative to AREA in W. HL is a
23377 face-override with the following meaning:
23379 DRAW_NORMAL_TEXT draw normally
23380 DRAW_CURSOR draw in cursor face
23381 DRAW_MOUSE_FACE draw in mouse face.
23382 DRAW_INVERSE_VIDEO draw in mode line face
23383 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
23384 DRAW_IMAGE_RAISED draw an image with a raised relief around it
23386 If OVERLAPS is non-zero, draw only the foreground of characters and
23387 clip to the physical height of ROW. Non-zero value also defines
23388 the overlapping part to be drawn:
23390 OVERLAPS_PRED overlap with preceding rows
23391 OVERLAPS_SUCC overlap with succeeding rows
23392 OVERLAPS_BOTH overlap with both preceding/succeeding rows
23393 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
23395 Value is the x-position reached, relative to AREA of W. */
23398 draw_glyphs (struct window
*w
, int x
, struct glyph_row
*row
,
23399 enum glyph_row_area area
, ptrdiff_t start
, ptrdiff_t end
,
23400 enum draw_glyphs_face hl
, int overlaps
)
23402 struct glyph_string
*head
, *tail
;
23403 struct glyph_string
*s
;
23404 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
23405 int i
, j
, x_reached
, last_x
, area_left
= 0;
23406 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
23409 ALLOCATE_HDC (hdc
, f
);
23411 /* Let's rather be paranoid than getting a SEGV. */
23412 end
= min (end
, row
->used
[area
]);
23413 start
= max (0, start
);
23414 start
= min (end
, start
);
23416 /* Translate X to frame coordinates. Set last_x to the right
23417 end of the drawing area. */
23418 if (row
->full_width_p
)
23420 /* X is relative to the left edge of W, without scroll bars
23422 area_left
= WINDOW_LEFT_EDGE_X (w
);
23423 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
23427 area_left
= window_box_left (w
, area
);
23428 last_x
= area_left
+ window_box_width (w
, area
);
23432 /* Build a doubly-linked list of glyph_string structures between
23433 head and tail from what we have to draw. Note that the macro
23434 BUILD_GLYPH_STRINGS will modify its start parameter. That's
23435 the reason we use a separate variable `i'. */
23437 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
23439 x_reached
= tail
->x
+ tail
->background_width
;
23443 /* If there are any glyphs with lbearing < 0 or rbearing > width in
23444 the row, redraw some glyphs in front or following the glyph
23445 strings built above. */
23446 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
23448 struct glyph_string
*h
, *t
;
23449 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
23450 int mouse_beg_col
IF_LINT (= 0), mouse_end_col
IF_LINT (= 0);
23451 int check_mouse_face
= 0;
23454 /* If mouse highlighting is on, we may need to draw adjacent
23455 glyphs using mouse-face highlighting. */
23456 if (area
== TEXT_AREA
&& row
->mouse_face_p
)
23458 struct glyph_row
*mouse_beg_row
, *mouse_end_row
;
23460 mouse_beg_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
23461 mouse_end_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
23463 if (row
>= mouse_beg_row
&& row
<= mouse_end_row
)
23465 check_mouse_face
= 1;
23466 mouse_beg_col
= (row
== mouse_beg_row
)
23467 ? hlinfo
->mouse_face_beg_col
: 0;
23468 mouse_end_col
= (row
== mouse_end_row
)
23469 ? hlinfo
->mouse_face_end_col
23470 : row
->used
[TEXT_AREA
];
23474 /* Compute overhangs for all glyph strings. */
23475 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
23476 for (s
= head
; s
; s
= s
->next
)
23477 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
23479 /* Prepend glyph strings for glyphs in front of the first glyph
23480 string that are overwritten because of the first glyph
23481 string's left overhang. The background of all strings
23482 prepended must be drawn because the first glyph string
23484 i
= left_overwritten (head
);
23487 enum draw_glyphs_face overlap_hl
;
23489 /* If this row contains mouse highlighting, attempt to draw
23490 the overlapped glyphs with the correct highlight. This
23491 code fails if the overlap encompasses more than one glyph
23492 and mouse-highlight spans only some of these glyphs.
23493 However, making it work perfectly involves a lot more
23494 code, and I don't know if the pathological case occurs in
23495 practice, so we'll stick to this for now. --- cyd */
23496 if (check_mouse_face
23497 && mouse_beg_col
< start
&& mouse_end_col
> i
)
23498 overlap_hl
= DRAW_MOUSE_FACE
;
23500 overlap_hl
= DRAW_NORMAL_TEXT
;
23503 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
23504 overlap_hl
, dummy_x
, last_x
);
23506 compute_overhangs_and_x (t
, head
->x
, 1);
23507 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
23511 /* Prepend glyph strings for glyphs in front of the first glyph
23512 string that overwrite that glyph string because of their
23513 right overhang. For these strings, only the foreground must
23514 be drawn, because it draws over the glyph string at `head'.
23515 The background must not be drawn because this would overwrite
23516 right overhangs of preceding glyphs for which no glyph
23518 i
= left_overwriting (head
);
23521 enum draw_glyphs_face overlap_hl
;
23523 if (check_mouse_face
23524 && mouse_beg_col
< start
&& mouse_end_col
> i
)
23525 overlap_hl
= DRAW_MOUSE_FACE
;
23527 overlap_hl
= DRAW_NORMAL_TEXT
;
23530 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
23531 overlap_hl
, dummy_x
, last_x
);
23532 for (s
= h
; s
; s
= s
->next
)
23533 s
->background_filled_p
= 1;
23534 compute_overhangs_and_x (t
, head
->x
, 1);
23535 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
23538 /* Append glyphs strings for glyphs following the last glyph
23539 string tail that are overwritten by tail. The background of
23540 these strings has to be drawn because tail's foreground draws
23542 i
= right_overwritten (tail
);
23545 enum draw_glyphs_face overlap_hl
;
23547 if (check_mouse_face
23548 && mouse_beg_col
< i
&& mouse_end_col
> end
)
23549 overlap_hl
= DRAW_MOUSE_FACE
;
23551 overlap_hl
= DRAW_NORMAL_TEXT
;
23553 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
23554 overlap_hl
, x
, last_x
);
23555 /* Because BUILD_GLYPH_STRINGS updates the first argument,
23556 we don't have `end = i;' here. */
23557 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
23558 append_glyph_string_lists (&head
, &tail
, h
, t
);
23562 /* Append glyph strings for glyphs following the last glyph
23563 string tail that overwrite tail. The foreground of such
23564 glyphs has to be drawn because it writes into the background
23565 of tail. The background must not be drawn because it could
23566 paint over the foreground of following glyphs. */
23567 i
= right_overwriting (tail
);
23570 enum draw_glyphs_face overlap_hl
;
23571 if (check_mouse_face
23572 && mouse_beg_col
< i
&& mouse_end_col
> end
)
23573 overlap_hl
= DRAW_MOUSE_FACE
;
23575 overlap_hl
= DRAW_NORMAL_TEXT
;
23578 i
++; /* We must include the Ith glyph. */
23579 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
23580 overlap_hl
, x
, last_x
);
23581 for (s
= h
; s
; s
= s
->next
)
23582 s
->background_filled_p
= 1;
23583 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
23584 append_glyph_string_lists (&head
, &tail
, h
, t
);
23586 if (clip_head
|| clip_tail
)
23587 for (s
= head
; s
; s
= s
->next
)
23589 s
->clip_head
= clip_head
;
23590 s
->clip_tail
= clip_tail
;
23594 /* Draw all strings. */
23595 for (s
= head
; s
; s
= s
->next
)
23596 FRAME_RIF (f
)->draw_glyph_string (s
);
23599 /* When focus a sole frame and move horizontally, this sets on_p to 0
23600 causing a failure to erase prev cursor position. */
23601 if (area
== TEXT_AREA
23602 && !row
->full_width_p
23603 /* When drawing overlapping rows, only the glyph strings'
23604 foreground is drawn, which doesn't erase a cursor
23608 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
23609 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
23610 : (tail
? tail
->x
+ tail
->background_width
: x
));
23614 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
23615 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
23619 /* Value is the x-position up to which drawn, relative to AREA of W.
23620 This doesn't include parts drawn because of overhangs. */
23621 if (row
->full_width_p
)
23622 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
23624 x_reached
-= area_left
;
23626 RELEASE_HDC (hdc
, f
);
23631 /* Expand row matrix if too narrow. Don't expand if area
23634 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
23636 if (!fonts_changed_p \
23637 && (it->glyph_row->glyphs[area] \
23638 < it->glyph_row->glyphs[area + 1])) \
23640 it->w->ncols_scale_factor++; \
23641 fonts_changed_p = 1; \
23645 /* Store one glyph for IT->char_to_display in IT->glyph_row.
23646 Called from x_produce_glyphs when IT->glyph_row is non-null. */
23649 append_glyph (struct it
*it
)
23651 struct glyph
*glyph
;
23652 enum glyph_row_area area
= it
->area
;
23654 eassert (it
->glyph_row
);
23655 eassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
23657 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23658 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23660 /* If the glyph row is reversed, we need to prepend the glyph
23661 rather than append it. */
23662 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23666 /* Make room for the additional glyph. */
23667 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
23669 glyph
= it
->glyph_row
->glyphs
[area
];
23671 glyph
->charpos
= CHARPOS (it
->position
);
23672 glyph
->object
= it
->object
;
23673 if (it
->pixel_width
> 0)
23675 glyph
->pixel_width
= it
->pixel_width
;
23676 glyph
->padding_p
= 0;
23680 /* Assure at least 1-pixel width. Otherwise, cursor can't
23681 be displayed correctly. */
23682 glyph
->pixel_width
= 1;
23683 glyph
->padding_p
= 1;
23685 glyph
->ascent
= it
->ascent
;
23686 glyph
->descent
= it
->descent
;
23687 glyph
->voffset
= it
->voffset
;
23688 glyph
->type
= CHAR_GLYPH
;
23689 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23690 glyph
->multibyte_p
= it
->multibyte_p
;
23691 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23692 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23693 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
23694 || it
->phys_descent
> it
->descent
);
23695 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
23696 glyph
->face_id
= it
->face_id
;
23697 glyph
->u
.ch
= it
->char_to_display
;
23698 glyph
->slice
.img
= null_glyph_slice
;
23699 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23702 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23703 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23705 glyph
->bidi_type
= it
->bidi_it
.type
;
23709 glyph
->resolved_level
= 0;
23710 glyph
->bidi_type
= UNKNOWN_BT
;
23712 ++it
->glyph_row
->used
[area
];
23715 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23718 /* Store one glyph for the composition IT->cmp_it.id in
23719 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
23723 append_composite_glyph (struct it
*it
)
23725 struct glyph
*glyph
;
23726 enum glyph_row_area area
= it
->area
;
23728 eassert (it
->glyph_row
);
23730 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23731 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23733 /* If the glyph row is reversed, we need to prepend the glyph
23734 rather than append it. */
23735 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
23739 /* Make room for the new glyph. */
23740 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
23742 glyph
= it
->glyph_row
->glyphs
[it
->area
];
23744 glyph
->charpos
= it
->cmp_it
.charpos
;
23745 glyph
->object
= it
->object
;
23746 glyph
->pixel_width
= it
->pixel_width
;
23747 glyph
->ascent
= it
->ascent
;
23748 glyph
->descent
= it
->descent
;
23749 glyph
->voffset
= it
->voffset
;
23750 glyph
->type
= COMPOSITE_GLYPH
;
23751 if (it
->cmp_it
.ch
< 0)
23753 glyph
->u
.cmp
.automatic
= 0;
23754 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
23755 glyph
->slice
.cmp
.from
= glyph
->slice
.cmp
.to
= 0;
23759 glyph
->u
.cmp
.automatic
= 1;
23760 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
23761 glyph
->slice
.cmp
.from
= it
->cmp_it
.from
;
23762 glyph
->slice
.cmp
.to
= it
->cmp_it
.to
- 1;
23764 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23765 glyph
->multibyte_p
= it
->multibyte_p
;
23766 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23767 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23768 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
23769 || it
->phys_descent
> it
->descent
);
23770 glyph
->padding_p
= 0;
23771 glyph
->glyph_not_available_p
= 0;
23772 glyph
->face_id
= it
->face_id
;
23773 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23776 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23777 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23779 glyph
->bidi_type
= it
->bidi_it
.type
;
23781 ++it
->glyph_row
->used
[area
];
23784 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23788 /* Change IT->ascent and IT->height according to the setting of
23792 take_vertical_position_into_account (struct it
*it
)
23796 if (it
->voffset
< 0)
23797 /* Increase the ascent so that we can display the text higher
23799 it
->ascent
-= it
->voffset
;
23801 /* Increase the descent so that we can display the text lower
23803 it
->descent
+= it
->voffset
;
23808 /* Produce glyphs/get display metrics for the image IT is loaded with.
23809 See the description of struct display_iterator in dispextern.h for
23810 an overview of struct display_iterator. */
23813 produce_image_glyph (struct it
*it
)
23817 int glyph_ascent
, crop
;
23818 struct glyph_slice slice
;
23820 eassert (it
->what
== IT_IMAGE
);
23822 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
23824 /* Make sure X resources of the face is loaded. */
23825 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
23827 if (it
->image_id
< 0)
23829 /* Fringe bitmap. */
23830 it
->ascent
= it
->phys_ascent
= 0;
23831 it
->descent
= it
->phys_descent
= 0;
23832 it
->pixel_width
= 0;
23837 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
23839 /* Make sure X resources of the image is loaded. */
23840 prepare_image_for_display (it
->f
, img
);
23842 slice
.x
= slice
.y
= 0;
23843 slice
.width
= img
->width
;
23844 slice
.height
= img
->height
;
23846 if (INTEGERP (it
->slice
.x
))
23847 slice
.x
= XINT (it
->slice
.x
);
23848 else if (FLOATP (it
->slice
.x
))
23849 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
23851 if (INTEGERP (it
->slice
.y
))
23852 slice
.y
= XINT (it
->slice
.y
);
23853 else if (FLOATP (it
->slice
.y
))
23854 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
23856 if (INTEGERP (it
->slice
.width
))
23857 slice
.width
= XINT (it
->slice
.width
);
23858 else if (FLOATP (it
->slice
.width
))
23859 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
23861 if (INTEGERP (it
->slice
.height
))
23862 slice
.height
= XINT (it
->slice
.height
);
23863 else if (FLOATP (it
->slice
.height
))
23864 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
23866 if (slice
.x
>= img
->width
)
23867 slice
.x
= img
->width
;
23868 if (slice
.y
>= img
->height
)
23869 slice
.y
= img
->height
;
23870 if (slice
.x
+ slice
.width
>= img
->width
)
23871 slice
.width
= img
->width
- slice
.x
;
23872 if (slice
.y
+ slice
.height
> img
->height
)
23873 slice
.height
= img
->height
- slice
.y
;
23875 if (slice
.width
== 0 || slice
.height
== 0)
23878 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
23880 it
->descent
= slice
.height
- glyph_ascent
;
23882 it
->descent
+= img
->vmargin
;
23883 if (slice
.y
+ slice
.height
== img
->height
)
23884 it
->descent
+= img
->vmargin
;
23885 it
->phys_descent
= it
->descent
;
23887 it
->pixel_width
= slice
.width
;
23889 it
->pixel_width
+= img
->hmargin
;
23890 if (slice
.x
+ slice
.width
== img
->width
)
23891 it
->pixel_width
+= img
->hmargin
;
23893 /* It's quite possible for images to have an ascent greater than
23894 their height, so don't get confused in that case. */
23895 if (it
->descent
< 0)
23900 if (face
->box
!= FACE_NO_BOX
)
23902 if (face
->box_line_width
> 0)
23905 it
->ascent
+= face
->box_line_width
;
23906 if (slice
.y
+ slice
.height
== img
->height
)
23907 it
->descent
+= face
->box_line_width
;
23910 if (it
->start_of_box_run_p
&& slice
.x
== 0)
23911 it
->pixel_width
+= eabs (face
->box_line_width
);
23912 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
23913 it
->pixel_width
+= eabs (face
->box_line_width
);
23916 take_vertical_position_into_account (it
);
23918 /* Automatically crop wide image glyphs at right edge so we can
23919 draw the cursor on same display row. */
23920 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
23921 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
23923 it
->pixel_width
-= crop
;
23924 slice
.width
-= crop
;
23929 struct glyph
*glyph
;
23930 enum glyph_row_area area
= it
->area
;
23932 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23933 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23935 glyph
->charpos
= CHARPOS (it
->position
);
23936 glyph
->object
= it
->object
;
23937 glyph
->pixel_width
= it
->pixel_width
;
23938 glyph
->ascent
= glyph_ascent
;
23939 glyph
->descent
= it
->descent
;
23940 glyph
->voffset
= it
->voffset
;
23941 glyph
->type
= IMAGE_GLYPH
;
23942 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23943 glyph
->multibyte_p
= it
->multibyte_p
;
23944 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23945 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23946 glyph
->overlaps_vertically_p
= 0;
23947 glyph
->padding_p
= 0;
23948 glyph
->glyph_not_available_p
= 0;
23949 glyph
->face_id
= it
->face_id
;
23950 glyph
->u
.img_id
= img
->id
;
23951 glyph
->slice
.img
= slice
;
23952 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23955 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23956 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23958 glyph
->bidi_type
= it
->bidi_it
.type
;
23960 ++it
->glyph_row
->used
[area
];
23963 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23968 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
23969 of the glyph, WIDTH and HEIGHT are the width and height of the
23970 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
23973 append_stretch_glyph (struct it
*it
, Lisp_Object object
,
23974 int width
, int height
, int ascent
)
23976 struct glyph
*glyph
;
23977 enum glyph_row_area area
= it
->area
;
23979 eassert (ascent
>= 0 && ascent
<= height
);
23981 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23982 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23984 /* If the glyph row is reversed, we need to prepend the glyph
23985 rather than append it. */
23986 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23990 /* Make room for the additional glyph. */
23991 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
23993 glyph
= it
->glyph_row
->glyphs
[area
];
23995 glyph
->charpos
= CHARPOS (it
->position
);
23996 glyph
->object
= object
;
23997 glyph
->pixel_width
= width
;
23998 glyph
->ascent
= ascent
;
23999 glyph
->descent
= height
- ascent
;
24000 glyph
->voffset
= it
->voffset
;
24001 glyph
->type
= STRETCH_GLYPH
;
24002 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24003 glyph
->multibyte_p
= it
->multibyte_p
;
24004 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24005 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24006 glyph
->overlaps_vertically_p
= 0;
24007 glyph
->padding_p
= 0;
24008 glyph
->glyph_not_available_p
= 0;
24009 glyph
->face_id
= it
->face_id
;
24010 glyph
->u
.stretch
.ascent
= ascent
;
24011 glyph
->u
.stretch
.height
= height
;
24012 glyph
->slice
.img
= null_glyph_slice
;
24013 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24016 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24017 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24019 glyph
->bidi_type
= it
->bidi_it
.type
;
24023 glyph
->resolved_level
= 0;
24024 glyph
->bidi_type
= UNKNOWN_BT
;
24026 ++it
->glyph_row
->used
[area
];
24029 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24032 #endif /* HAVE_WINDOW_SYSTEM */
24034 /* Produce a stretch glyph for iterator IT. IT->object is the value
24035 of the glyph property displayed. The value must be a list
24036 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
24039 1. `:width WIDTH' specifies that the space should be WIDTH *
24040 canonical char width wide. WIDTH may be an integer or floating
24043 2. `:relative-width FACTOR' specifies that the width of the stretch
24044 should be computed from the width of the first character having the
24045 `glyph' property, and should be FACTOR times that width.
24047 3. `:align-to HPOS' specifies that the space should be wide enough
24048 to reach HPOS, a value in canonical character units.
24050 Exactly one of the above pairs must be present.
24052 4. `:height HEIGHT' specifies that the height of the stretch produced
24053 should be HEIGHT, measured in canonical character units.
24055 5. `:relative-height FACTOR' specifies that the height of the
24056 stretch should be FACTOR times the height of the characters having
24057 the glyph property.
24059 Either none or exactly one of 4 or 5 must be present.
24061 6. `:ascent ASCENT' specifies that ASCENT percent of the height
24062 of the stretch should be used for the ascent of the stretch.
24063 ASCENT must be in the range 0 <= ASCENT <= 100. */
24066 produce_stretch_glyph (struct it
*it
)
24068 /* (space :width WIDTH :height HEIGHT ...) */
24069 Lisp_Object prop
, plist
;
24070 int width
= 0, height
= 0, align_to
= -1;
24071 int zero_width_ok_p
= 0;
24074 struct face
*face
= NULL
;
24075 struct font
*font
= NULL
;
24077 #ifdef HAVE_WINDOW_SYSTEM
24078 int zero_height_ok_p
= 0;
24080 if (FRAME_WINDOW_P (it
->f
))
24082 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24083 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24084 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24088 /* List should start with `space'. */
24089 eassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
24090 plist
= XCDR (it
->object
);
24092 /* Compute the width of the stretch. */
24093 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
24094 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
24096 /* Absolute width `:width WIDTH' specified and valid. */
24097 zero_width_ok_p
= 1;
24100 #ifdef HAVE_WINDOW_SYSTEM
24101 else if (FRAME_WINDOW_P (it
->f
)
24102 && (prop
= Fplist_get (plist
, QCrelative_width
), NUMVAL (prop
) > 0))
24104 /* Relative width `:relative-width FACTOR' specified and valid.
24105 Compute the width of the characters having the `glyph'
24108 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
24111 if (it
->multibyte_p
)
24112 it2
.c
= it2
.char_to_display
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
24115 it2
.c
= it2
.char_to_display
= *p
, it2
.len
= 1;
24116 if (! ASCII_CHAR_P (it2
.c
))
24117 it2
.char_to_display
= BYTE8_TO_CHAR (it2
.c
);
24120 it2
.glyph_row
= NULL
;
24121 it2
.what
= IT_CHARACTER
;
24122 x_produce_glyphs (&it2
);
24123 width
= NUMVAL (prop
) * it2
.pixel_width
;
24125 #endif /* HAVE_WINDOW_SYSTEM */
24126 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
24127 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
24129 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
24130 align_to
= (align_to
< 0
24132 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
24133 else if (align_to
< 0)
24134 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
24135 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
24136 zero_width_ok_p
= 1;
24139 /* Nothing specified -> width defaults to canonical char width. */
24140 width
= FRAME_COLUMN_WIDTH (it
->f
);
24142 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
24145 #ifdef HAVE_WINDOW_SYSTEM
24146 /* Compute height. */
24147 if (FRAME_WINDOW_P (it
->f
))
24149 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
24150 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
24153 zero_height_ok_p
= 1;
24155 else if (prop
= Fplist_get (plist
, QCrelative_height
),
24157 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
24159 height
= FONT_HEIGHT (font
);
24161 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
24164 /* Compute percentage of height used for ascent. If
24165 `:ascent ASCENT' is present and valid, use that. Otherwise,
24166 derive the ascent from the font in use. */
24167 if (prop
= Fplist_get (plist
, QCascent
),
24168 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
24169 ascent
= height
* NUMVAL (prop
) / 100.0;
24170 else if (!NILP (prop
)
24171 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
24172 ascent
= min (max (0, (int)tem
), height
);
24174 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
24177 #endif /* HAVE_WINDOW_SYSTEM */
24180 if (width
> 0 && it
->line_wrap
!= TRUNCATE
24181 && it
->current_x
+ width
> it
->last_visible_x
)
24183 width
= it
->last_visible_x
- it
->current_x
;
24184 #ifdef HAVE_WINDOW_SYSTEM
24185 /* Subtract one more pixel from the stretch width, but only on
24186 GUI frames, since on a TTY each glyph is one "pixel" wide. */
24187 width
-= FRAME_WINDOW_P (it
->f
);
24191 if (width
> 0 && height
> 0 && it
->glyph_row
)
24193 Lisp_Object o_object
= it
->object
;
24194 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
24197 if (!STRINGP (object
))
24198 object
= it
->w
->buffer
;
24199 #ifdef HAVE_WINDOW_SYSTEM
24200 if (FRAME_WINDOW_P (it
->f
))
24201 append_stretch_glyph (it
, object
, width
, height
, ascent
);
24205 it
->object
= object
;
24206 it
->char_to_display
= ' ';
24207 it
->pixel_width
= it
->len
= 1;
24209 tty_append_glyph (it
);
24210 it
->object
= o_object
;
24214 it
->pixel_width
= width
;
24215 #ifdef HAVE_WINDOW_SYSTEM
24216 if (FRAME_WINDOW_P (it
->f
))
24218 it
->ascent
= it
->phys_ascent
= ascent
;
24219 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
24220 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
24221 take_vertical_position_into_account (it
);
24225 it
->nglyphs
= width
;
24228 /* Get information about special display element WHAT in an
24229 environment described by IT. WHAT is one of IT_TRUNCATION or
24230 IT_CONTINUATION. Maybe produce glyphs for WHAT if IT has a
24231 non-null glyph_row member. This function ensures that fields like
24232 face_id, c, len of IT are left untouched. */
24235 produce_special_glyphs (struct it
*it
, enum display_element_type what
)
24242 temp_it
.object
= make_number (0);
24243 memset (&temp_it
.current
, 0, sizeof temp_it
.current
);
24245 if (what
== IT_CONTINUATION
)
24247 /* Continuation glyph. For R2L lines, we mirror it by hand. */
24248 if (it
->bidi_it
.paragraph_dir
== R2L
)
24249 SET_GLYPH_FROM_CHAR (glyph
, '/');
24251 SET_GLYPH_FROM_CHAR (glyph
, '\\');
24253 && (gc
= DISP_CONTINUE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
24255 /* FIXME: Should we mirror GC for R2L lines? */
24256 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
24257 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
24260 else if (what
== IT_TRUNCATION
)
24262 /* Truncation glyph. */
24263 SET_GLYPH_FROM_CHAR (glyph
, '$');
24265 && (gc
= DISP_TRUNC_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
24267 /* FIXME: Should we mirror GC for R2L lines? */
24268 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
24269 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
24275 #ifdef HAVE_WINDOW_SYSTEM
24276 /* On a GUI frame, when the right fringe (left fringe for R2L rows)
24277 is turned off, we precede the truncation/continuation glyphs by a
24278 stretch glyph whose width is computed such that these special
24279 glyphs are aligned at the window margin, even when very different
24280 fonts are used in different glyph rows. */
24281 if (FRAME_WINDOW_P (temp_it
.f
)
24282 /* init_iterator calls this with it->glyph_row == NULL, and it
24283 wants only the pixel width of the truncation/continuation
24285 && temp_it
.glyph_row
24286 /* insert_left_trunc_glyphs calls us at the beginning of the
24287 row, and it has its own calculation of the stretch glyph
24289 && temp_it
.glyph_row
->used
[TEXT_AREA
] > 0
24290 && (temp_it
.glyph_row
->reversed_p
24291 ? WINDOW_LEFT_FRINGE_WIDTH (temp_it
.w
)
24292 : WINDOW_RIGHT_FRINGE_WIDTH (temp_it
.w
)) == 0)
24294 int stretch_width
= temp_it
.last_visible_x
- temp_it
.current_x
;
24296 if (stretch_width
> 0)
24298 struct face
*face
= FACE_FROM_ID (temp_it
.f
, temp_it
.face_id
);
24299 struct font
*font
=
24300 face
->font
? face
->font
: FRAME_FONT (temp_it
.f
);
24301 int stretch_ascent
=
24302 (((temp_it
.ascent
+ temp_it
.descent
)
24303 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
24305 append_stretch_glyph (&temp_it
, make_number (0), stretch_width
,
24306 temp_it
.ascent
+ temp_it
.descent
,
24313 temp_it
.what
= IT_CHARACTER
;
24315 temp_it
.c
= temp_it
.char_to_display
= GLYPH_CHAR (glyph
);
24316 temp_it
.face_id
= GLYPH_FACE (glyph
);
24317 temp_it
.len
= CHAR_BYTES (temp_it
.c
);
24319 PRODUCE_GLYPHS (&temp_it
);
24320 it
->pixel_width
= temp_it
.pixel_width
;
24321 it
->nglyphs
= temp_it
.pixel_width
;
24324 #ifdef HAVE_WINDOW_SYSTEM
24326 /* Calculate line-height and line-spacing properties.
24327 An integer value specifies explicit pixel value.
24328 A float value specifies relative value to current face height.
24329 A cons (float . face-name) specifies relative value to
24330 height of specified face font.
24332 Returns height in pixels, or nil. */
24336 calc_line_height_property (struct it
*it
, Lisp_Object val
, struct font
*font
,
24337 int boff
, int override
)
24339 Lisp_Object face_name
= Qnil
;
24340 int ascent
, descent
, height
;
24342 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
24347 face_name
= XCAR (val
);
24349 if (!NUMBERP (val
))
24350 val
= make_number (1);
24351 if (NILP (face_name
))
24353 height
= it
->ascent
+ it
->descent
;
24358 if (NILP (face_name
))
24360 font
= FRAME_FONT (it
->f
);
24361 boff
= FRAME_BASELINE_OFFSET (it
->f
);
24363 else if (EQ (face_name
, Qt
))
24372 face_id
= lookup_named_face (it
->f
, face_name
, 0);
24374 return make_number (-1);
24376 face
= FACE_FROM_ID (it
->f
, face_id
);
24379 return make_number (-1);
24380 boff
= font
->baseline_offset
;
24381 if (font
->vertical_centering
)
24382 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
24385 ascent
= FONT_BASE (font
) + boff
;
24386 descent
= FONT_DESCENT (font
) - boff
;
24390 it
->override_ascent
= ascent
;
24391 it
->override_descent
= descent
;
24392 it
->override_boff
= boff
;
24395 height
= ascent
+ descent
;
24399 height
= (int)(XFLOAT_DATA (val
) * height
);
24400 else if (INTEGERP (val
))
24401 height
*= XINT (val
);
24403 return make_number (height
);
24407 /* Append a glyph for a glyphless character to IT->glyph_row. FACE_ID
24408 is a face ID to be used for the glyph. FOR_NO_FONT is nonzero if
24409 and only if this is for a character for which no font was found.
24411 If the display method (it->glyphless_method) is
24412 GLYPHLESS_DISPLAY_ACRONYM or GLYPHLESS_DISPLAY_HEX_CODE, LEN is a
24413 length of the acronym or the hexadecimal string, UPPER_XOFF and
24414 UPPER_YOFF are pixel offsets for the upper part of the string,
24415 LOWER_XOFF and LOWER_YOFF are for the lower part.
24417 For the other display methods, LEN through LOWER_YOFF are zero. */
24420 append_glyphless_glyph (struct it
*it
, int face_id
, int for_no_font
, int len
,
24421 short upper_xoff
, short upper_yoff
,
24422 short lower_xoff
, short lower_yoff
)
24424 struct glyph
*glyph
;
24425 enum glyph_row_area area
= it
->area
;
24427 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24428 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24430 /* If the glyph row is reversed, we need to prepend the glyph
24431 rather than append it. */
24432 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24436 /* Make room for the additional glyph. */
24437 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
24439 glyph
= it
->glyph_row
->glyphs
[area
];
24441 glyph
->charpos
= CHARPOS (it
->position
);
24442 glyph
->object
= it
->object
;
24443 glyph
->pixel_width
= it
->pixel_width
;
24444 glyph
->ascent
= it
->ascent
;
24445 glyph
->descent
= it
->descent
;
24446 glyph
->voffset
= it
->voffset
;
24447 glyph
->type
= GLYPHLESS_GLYPH
;
24448 glyph
->u
.glyphless
.method
= it
->glyphless_method
;
24449 glyph
->u
.glyphless
.for_no_font
= for_no_font
;
24450 glyph
->u
.glyphless
.len
= len
;
24451 glyph
->u
.glyphless
.ch
= it
->c
;
24452 glyph
->slice
.glyphless
.upper_xoff
= upper_xoff
;
24453 glyph
->slice
.glyphless
.upper_yoff
= upper_yoff
;
24454 glyph
->slice
.glyphless
.lower_xoff
= lower_xoff
;
24455 glyph
->slice
.glyphless
.lower_yoff
= lower_yoff
;
24456 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24457 glyph
->multibyte_p
= it
->multibyte_p
;
24458 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24459 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24460 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
24461 || it
->phys_descent
> it
->descent
);
24462 glyph
->padding_p
= 0;
24463 glyph
->glyph_not_available_p
= 0;
24464 glyph
->face_id
= face_id
;
24465 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24468 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24469 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24471 glyph
->bidi_type
= it
->bidi_it
.type
;
24473 ++it
->glyph_row
->used
[area
];
24476 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24480 /* Produce a glyph for a glyphless character for iterator IT.
24481 IT->glyphless_method specifies which method to use for displaying
24482 the character. See the description of enum
24483 glyphless_display_method in dispextern.h for the detail.
24485 FOR_NO_FONT is nonzero if and only if this is for a character for
24486 which no font was found. ACRONYM, if non-nil, is an acronym string
24487 for the character. */
24490 produce_glyphless_glyph (struct it
*it
, int for_no_font
, Lisp_Object acronym
)
24495 int base_width
, base_height
, width
, height
;
24496 short upper_xoff
, upper_yoff
, lower_xoff
, lower_yoff
;
24499 /* Get the metrics of the base font. We always refer to the current
24501 face
= FACE_FROM_ID (it
->f
, it
->face_id
)->ascii_face
;
24502 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24503 it
->ascent
= FONT_BASE (font
) + font
->baseline_offset
;
24504 it
->descent
= FONT_DESCENT (font
) - font
->baseline_offset
;
24505 base_height
= it
->ascent
+ it
->descent
;
24506 base_width
= font
->average_width
;
24508 /* Get a face ID for the glyph by utilizing a cache (the same way as
24509 done for `escape-glyph' in get_next_display_element). */
24510 if (it
->f
== last_glyphless_glyph_frame
24511 && it
->face_id
== last_glyphless_glyph_face_id
)
24513 face_id
= last_glyphless_glyph_merged_face_id
;
24517 /* Merge the `glyphless-char' face into the current face. */
24518 face_id
= merge_faces (it
->f
, Qglyphless_char
, 0, it
->face_id
);
24519 last_glyphless_glyph_frame
= it
->f
;
24520 last_glyphless_glyph_face_id
= it
->face_id
;
24521 last_glyphless_glyph_merged_face_id
= face_id
;
24524 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_THIN_SPACE
)
24526 it
->pixel_width
= THIN_SPACE_WIDTH
;
24528 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
24530 else if (it
->glyphless_method
== GLYPHLESS_DISPLAY_EMPTY_BOX
)
24532 width
= CHAR_WIDTH (it
->c
);
24535 else if (width
> 4)
24537 it
->pixel_width
= base_width
* width
;
24539 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
24545 unsigned int code
[6];
24547 int ascent
, descent
;
24548 struct font_metrics metrics_upper
, metrics_lower
;
24550 face
= FACE_FROM_ID (it
->f
, face_id
);
24551 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24552 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24554 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_ACRONYM
)
24556 if (! STRINGP (acronym
) && CHAR_TABLE_P (Vglyphless_char_display
))
24557 acronym
= CHAR_TABLE_REF (Vglyphless_char_display
, it
->c
);
24558 if (CONSP (acronym
))
24559 acronym
= XCAR (acronym
);
24560 str
= STRINGP (acronym
) ? SSDATA (acronym
) : "";
24564 eassert (it
->glyphless_method
== GLYPHLESS_DISPLAY_HEX_CODE
);
24565 sprintf (buf
, "%0*X", it
->c
< 0x10000 ? 4 : 6, it
->c
);
24568 for (len
= 0; str
[len
] && ASCII_BYTE_P (str
[len
]) && len
< 6; len
++)
24569 code
[len
] = font
->driver
->encode_char (font
, str
[len
]);
24570 upper_len
= (len
+ 1) / 2;
24571 font
->driver
->text_extents (font
, code
, upper_len
,
24573 font
->driver
->text_extents (font
, code
+ upper_len
, len
- upper_len
,
24578 /* +4 is for vertical bars of a box plus 1-pixel spaces at both side. */
24579 width
= max (metrics_upper
.width
, metrics_lower
.width
) + 4;
24580 upper_xoff
= upper_yoff
= 2; /* the typical case */
24581 if (base_width
>= width
)
24583 /* Align the upper to the left, the lower to the right. */
24584 it
->pixel_width
= base_width
;
24585 lower_xoff
= base_width
- 2 - metrics_lower
.width
;
24589 /* Center the shorter one. */
24590 it
->pixel_width
= width
;
24591 if (metrics_upper
.width
>= metrics_lower
.width
)
24592 lower_xoff
= (width
- metrics_lower
.width
) / 2;
24595 /* FIXME: This code doesn't look right. It formerly was
24596 missing the "lower_xoff = 0;", which couldn't have
24597 been right since it left lower_xoff uninitialized. */
24599 upper_xoff
= (width
- metrics_upper
.width
) / 2;
24603 /* +5 is for horizontal bars of a box plus 1-pixel spaces at
24604 top, bottom, and between upper and lower strings. */
24605 height
= (metrics_upper
.ascent
+ metrics_upper
.descent
24606 + metrics_lower
.ascent
+ metrics_lower
.descent
) + 5;
24607 /* Center vertically.
24608 H:base_height, D:base_descent
24609 h:height, ld:lower_descent, la:lower_ascent, ud:upper_descent
24611 ascent = - (D - H/2 - h/2 + 1); "+ 1" for rounding up
24612 descent = D - H/2 + h/2;
24613 lower_yoff = descent - 2 - ld;
24614 upper_yoff = lower_yoff - la - 1 - ud; */
24615 ascent
= - (it
->descent
- (base_height
+ height
+ 1) / 2);
24616 descent
= it
->descent
- (base_height
- height
) / 2;
24617 lower_yoff
= descent
- 2 - metrics_lower
.descent
;
24618 upper_yoff
= (lower_yoff
- metrics_lower
.ascent
- 1
24619 - metrics_upper
.descent
);
24620 /* Don't make the height shorter than the base height. */
24621 if (height
> base_height
)
24623 it
->ascent
= ascent
;
24624 it
->descent
= descent
;
24628 it
->phys_ascent
= it
->ascent
;
24629 it
->phys_descent
= it
->descent
;
24631 append_glyphless_glyph (it
, face_id
, for_no_font
, len
,
24632 upper_xoff
, upper_yoff
,
24633 lower_xoff
, lower_yoff
);
24635 take_vertical_position_into_account (it
);
24640 Produce glyphs/get display metrics for the display element IT is
24641 loaded with. See the description of struct it in dispextern.h
24642 for an overview of struct it. */
24645 x_produce_glyphs (struct it
*it
)
24647 int extra_line_spacing
= it
->extra_line_spacing
;
24649 it
->glyph_not_available_p
= 0;
24651 if (it
->what
== IT_CHARACTER
)
24654 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24655 struct font
*font
= face
->font
;
24656 struct font_metrics
*pcm
= NULL
;
24657 int boff
; /* baseline offset */
24661 /* When no suitable font is found, display this character by
24662 the method specified in the first extra slot of
24663 Vglyphless_char_display. */
24664 Lisp_Object acronym
= lookup_glyphless_char_display (-1, it
);
24666 eassert (it
->what
== IT_GLYPHLESS
);
24667 produce_glyphless_glyph (it
, 1, STRINGP (acronym
) ? acronym
: Qnil
);
24671 boff
= font
->baseline_offset
;
24672 if (font
->vertical_centering
)
24673 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
24675 if (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t')
24681 if (it
->override_ascent
>= 0)
24683 it
->ascent
= it
->override_ascent
;
24684 it
->descent
= it
->override_descent
;
24685 boff
= it
->override_boff
;
24689 it
->ascent
= FONT_BASE (font
) + boff
;
24690 it
->descent
= FONT_DESCENT (font
) - boff
;
24693 if (get_char_glyph_code (it
->char_to_display
, font
, &char2b
))
24695 pcm
= get_per_char_metric (font
, &char2b
);
24696 if (pcm
->width
== 0
24697 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
24703 it
->phys_ascent
= pcm
->ascent
+ boff
;
24704 it
->phys_descent
= pcm
->descent
- boff
;
24705 it
->pixel_width
= pcm
->width
;
24709 it
->glyph_not_available_p
= 1;
24710 it
->phys_ascent
= it
->ascent
;
24711 it
->phys_descent
= it
->descent
;
24712 it
->pixel_width
= font
->space_width
;
24715 if (it
->constrain_row_ascent_descent_p
)
24717 if (it
->descent
> it
->max_descent
)
24719 it
->ascent
+= it
->descent
- it
->max_descent
;
24720 it
->descent
= it
->max_descent
;
24722 if (it
->ascent
> it
->max_ascent
)
24724 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
24725 it
->ascent
= it
->max_ascent
;
24727 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
24728 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
24729 extra_line_spacing
= 0;
24732 /* If this is a space inside a region of text with
24733 `space-width' property, change its width. */
24734 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
24736 it
->pixel_width
*= XFLOATINT (it
->space_width
);
24738 /* If face has a box, add the box thickness to the character
24739 height. If character has a box line to the left and/or
24740 right, add the box line width to the character's width. */
24741 if (face
->box
!= FACE_NO_BOX
)
24743 int thick
= face
->box_line_width
;
24747 it
->ascent
+= thick
;
24748 it
->descent
+= thick
;
24753 if (it
->start_of_box_run_p
)
24754 it
->pixel_width
+= thick
;
24755 if (it
->end_of_box_run_p
)
24756 it
->pixel_width
+= thick
;
24759 /* If face has an overline, add the height of the overline
24760 (1 pixel) and a 1 pixel margin to the character height. */
24761 if (face
->overline_p
)
24762 it
->ascent
+= overline_margin
;
24764 if (it
->constrain_row_ascent_descent_p
)
24766 if (it
->ascent
> it
->max_ascent
)
24767 it
->ascent
= it
->max_ascent
;
24768 if (it
->descent
> it
->max_descent
)
24769 it
->descent
= it
->max_descent
;
24772 take_vertical_position_into_account (it
);
24774 /* If we have to actually produce glyphs, do it. */
24779 /* Translate a space with a `space-width' property
24780 into a stretch glyph. */
24781 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
24782 / FONT_HEIGHT (font
));
24783 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
24784 it
->ascent
+ it
->descent
, ascent
);
24789 /* If characters with lbearing or rbearing are displayed
24790 in this line, record that fact in a flag of the
24791 glyph row. This is used to optimize X output code. */
24792 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
24793 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
24795 if (! stretched_p
&& it
->pixel_width
== 0)
24796 /* We assure that all visible glyphs have at least 1-pixel
24798 it
->pixel_width
= 1;
24800 else if (it
->char_to_display
== '\n')
24802 /* A newline has no width, but we need the height of the
24803 line. But if previous part of the line sets a height,
24804 don't increase that height */
24806 Lisp_Object height
;
24807 Lisp_Object total_height
= Qnil
;
24809 it
->override_ascent
= -1;
24810 it
->pixel_width
= 0;
24813 height
= get_it_property (it
, Qline_height
);
24814 /* Split (line-height total-height) list */
24816 && CONSP (XCDR (height
))
24817 && NILP (XCDR (XCDR (height
))))
24819 total_height
= XCAR (XCDR (height
));
24820 height
= XCAR (height
);
24822 height
= calc_line_height_property (it
, height
, font
, boff
, 1);
24824 if (it
->override_ascent
>= 0)
24826 it
->ascent
= it
->override_ascent
;
24827 it
->descent
= it
->override_descent
;
24828 boff
= it
->override_boff
;
24832 it
->ascent
= FONT_BASE (font
) + boff
;
24833 it
->descent
= FONT_DESCENT (font
) - boff
;
24836 if (EQ (height
, Qt
))
24838 if (it
->descent
> it
->max_descent
)
24840 it
->ascent
+= it
->descent
- it
->max_descent
;
24841 it
->descent
= it
->max_descent
;
24843 if (it
->ascent
> it
->max_ascent
)
24845 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
24846 it
->ascent
= it
->max_ascent
;
24848 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
24849 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
24850 it
->constrain_row_ascent_descent_p
= 1;
24851 extra_line_spacing
= 0;
24855 Lisp_Object spacing
;
24857 it
->phys_ascent
= it
->ascent
;
24858 it
->phys_descent
= it
->descent
;
24860 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
24861 && face
->box
!= FACE_NO_BOX
24862 && face
->box_line_width
> 0)
24864 it
->ascent
+= face
->box_line_width
;
24865 it
->descent
+= face
->box_line_width
;
24868 && XINT (height
) > it
->ascent
+ it
->descent
)
24869 it
->ascent
= XINT (height
) - it
->descent
;
24871 if (!NILP (total_height
))
24872 spacing
= calc_line_height_property (it
, total_height
, font
, boff
, 0);
24875 spacing
= get_it_property (it
, Qline_spacing
);
24876 spacing
= calc_line_height_property (it
, spacing
, font
, boff
, 0);
24878 if (INTEGERP (spacing
))
24880 extra_line_spacing
= XINT (spacing
);
24881 if (!NILP (total_height
))
24882 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
24886 else /* i.e. (it->char_to_display == '\t') */
24888 if (font
->space_width
> 0)
24890 int tab_width
= it
->tab_width
* font
->space_width
;
24891 int x
= it
->current_x
+ it
->continuation_lines_width
;
24892 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
24894 /* If the distance from the current position to the next tab
24895 stop is less than a space character width, use the
24896 tab stop after that. */
24897 if (next_tab_x
- x
< font
->space_width
)
24898 next_tab_x
+= tab_width
;
24900 it
->pixel_width
= next_tab_x
- x
;
24902 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
24903 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
24907 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
24908 it
->ascent
+ it
->descent
, it
->ascent
);
24913 it
->pixel_width
= 0;
24918 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
24920 /* A static composition.
24922 Note: A composition is represented as one glyph in the
24923 glyph matrix. There are no padding glyphs.
24925 Important note: pixel_width, ascent, and descent are the
24926 values of what is drawn by draw_glyphs (i.e. the values of
24927 the overall glyphs composed). */
24928 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24929 int boff
; /* baseline offset */
24930 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
24931 int glyph_len
= cmp
->glyph_len
;
24932 struct font
*font
= face
->font
;
24936 /* If we have not yet calculated pixel size data of glyphs of
24937 the composition for the current face font, calculate them
24938 now. Theoretically, we have to check all fonts for the
24939 glyphs, but that requires much time and memory space. So,
24940 here we check only the font of the first glyph. This may
24941 lead to incorrect display, but it's very rare, and C-l
24942 (recenter-top-bottom) can correct the display anyway. */
24943 if (! cmp
->font
|| cmp
->font
!= font
)
24945 /* Ascent and descent of the font of the first character
24946 of this composition (adjusted by baseline offset).
24947 Ascent and descent of overall glyphs should not be less
24948 than these, respectively. */
24949 int font_ascent
, font_descent
, font_height
;
24950 /* Bounding box of the overall glyphs. */
24951 int leftmost
, rightmost
, lowest
, highest
;
24952 int lbearing
, rbearing
;
24953 int i
, width
, ascent
, descent
;
24954 int left_padded
= 0, right_padded
= 0;
24955 int c
IF_LINT (= 0); /* cmp->glyph_len can't be zero; see Bug#8512 */
24957 struct font_metrics
*pcm
;
24958 int font_not_found_p
;
24961 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
24962 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
24964 if (glyph_len
< cmp
->glyph_len
)
24966 for (i
= 0; i
< glyph_len
; i
++)
24968 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
24970 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
24975 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
24976 : IT_CHARPOS (*it
));
24977 /* If no suitable font is found, use the default font. */
24978 font_not_found_p
= font
== NULL
;
24979 if (font_not_found_p
)
24981 face
= face
->ascii_face
;
24984 boff
= font
->baseline_offset
;
24985 if (font
->vertical_centering
)
24986 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
24987 font_ascent
= FONT_BASE (font
) + boff
;
24988 font_descent
= FONT_DESCENT (font
) - boff
;
24989 font_height
= FONT_HEIGHT (font
);
24994 if (! font_not_found_p
)
24996 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
24998 pcm
= get_per_char_metric (font
, &char2b
);
25001 /* Initialize the bounding box. */
25004 width
= cmp
->glyph_len
> 0 ? pcm
->width
: 0;
25005 ascent
= pcm
->ascent
;
25006 descent
= pcm
->descent
;
25007 lbearing
= pcm
->lbearing
;
25008 rbearing
= pcm
->rbearing
;
25012 width
= cmp
->glyph_len
> 0 ? font
->space_width
: 0;
25013 ascent
= FONT_BASE (font
);
25014 descent
= FONT_DESCENT (font
);
25021 lowest
= - descent
+ boff
;
25022 highest
= ascent
+ boff
;
25024 if (! font_not_found_p
25025 && font
->default_ascent
25026 && CHAR_TABLE_P (Vuse_default_ascent
)
25027 && !NILP (Faref (Vuse_default_ascent
,
25028 make_number (it
->char_to_display
))))
25029 highest
= font
->default_ascent
+ boff
;
25031 /* Draw the first glyph at the normal position. It may be
25032 shifted to right later if some other glyphs are drawn
25034 cmp
->offsets
[i
* 2] = 0;
25035 cmp
->offsets
[i
* 2 + 1] = boff
;
25036 cmp
->lbearing
= lbearing
;
25037 cmp
->rbearing
= rbearing
;
25039 /* Set cmp->offsets for the remaining glyphs. */
25040 for (i
++; i
< glyph_len
; i
++)
25042 int left
, right
, btm
, top
;
25043 int ch
= COMPOSITION_GLYPH (cmp
, i
);
25045 struct face
*this_face
;
25049 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
25050 this_face
= FACE_FROM_ID (it
->f
, face_id
);
25051 font
= this_face
->font
;
25057 get_char_face_and_encoding (it
->f
, ch
, face_id
,
25059 pcm
= get_per_char_metric (font
, &char2b
);
25062 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
25065 width
= pcm
->width
;
25066 ascent
= pcm
->ascent
;
25067 descent
= pcm
->descent
;
25068 lbearing
= pcm
->lbearing
;
25069 rbearing
= pcm
->rbearing
;
25070 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
25072 /* Relative composition with or without
25073 alternate chars. */
25074 left
= (leftmost
+ rightmost
- width
) / 2;
25075 btm
= - descent
+ boff
;
25076 if (font
->relative_compose
25077 && (! CHAR_TABLE_P (Vignore_relative_composition
)
25078 || NILP (Faref (Vignore_relative_composition
,
25079 make_number (ch
)))))
25082 if (- descent
>= font
->relative_compose
)
25083 /* One extra pixel between two glyphs. */
25085 else if (ascent
<= 0)
25086 /* One extra pixel between two glyphs. */
25087 btm
= lowest
- 1 - ascent
- descent
;
25092 /* A composition rule is specified by an integer
25093 value that encodes global and new reference
25094 points (GREF and NREF). GREF and NREF are
25095 specified by numbers as below:
25097 0---1---2 -- ascent
25101 9--10--11 -- center
25103 ---3---4---5--- baseline
25105 6---7---8 -- descent
25107 int rule
= COMPOSITION_RULE (cmp
, i
);
25108 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
25110 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
25111 grefx
= gref
% 3, nrefx
= nref
% 3;
25112 grefy
= gref
/ 3, nrefy
= nref
/ 3;
25114 xoff
= font_height
* (xoff
- 128) / 256;
25116 yoff
= font_height
* (yoff
- 128) / 256;
25119 + grefx
* (rightmost
- leftmost
) / 2
25120 - nrefx
* width
/ 2
25123 btm
= ((grefy
== 0 ? highest
25125 : grefy
== 2 ? lowest
25126 : (highest
+ lowest
) / 2)
25127 - (nrefy
== 0 ? ascent
+ descent
25128 : nrefy
== 1 ? descent
- boff
25130 : (ascent
+ descent
) / 2)
25134 cmp
->offsets
[i
* 2] = left
;
25135 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
25137 /* Update the bounding box of the overall glyphs. */
25140 right
= left
+ width
;
25141 if (left
< leftmost
)
25143 if (right
> rightmost
)
25146 top
= btm
+ descent
+ ascent
;
25152 if (cmp
->lbearing
> left
+ lbearing
)
25153 cmp
->lbearing
= left
+ lbearing
;
25154 if (cmp
->rbearing
< left
+ rbearing
)
25155 cmp
->rbearing
= left
+ rbearing
;
25159 /* If there are glyphs whose x-offsets are negative,
25160 shift all glyphs to the right and make all x-offsets
25164 for (i
= 0; i
< cmp
->glyph_len
; i
++)
25165 cmp
->offsets
[i
* 2] -= leftmost
;
25166 rightmost
-= leftmost
;
25167 cmp
->lbearing
-= leftmost
;
25168 cmp
->rbearing
-= leftmost
;
25171 if (left_padded
&& cmp
->lbearing
< 0)
25173 for (i
= 0; i
< cmp
->glyph_len
; i
++)
25174 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
25175 rightmost
-= cmp
->lbearing
;
25176 cmp
->rbearing
-= cmp
->lbearing
;
25179 if (right_padded
&& rightmost
< cmp
->rbearing
)
25181 rightmost
= cmp
->rbearing
;
25184 cmp
->pixel_width
= rightmost
;
25185 cmp
->ascent
= highest
;
25186 cmp
->descent
= - lowest
;
25187 if (cmp
->ascent
< font_ascent
)
25188 cmp
->ascent
= font_ascent
;
25189 if (cmp
->descent
< font_descent
)
25190 cmp
->descent
= font_descent
;
25194 && (cmp
->lbearing
< 0
25195 || cmp
->rbearing
> cmp
->pixel_width
))
25196 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25198 it
->pixel_width
= cmp
->pixel_width
;
25199 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
25200 it
->descent
= it
->phys_descent
= cmp
->descent
;
25201 if (face
->box
!= FACE_NO_BOX
)
25203 int thick
= face
->box_line_width
;
25207 it
->ascent
+= thick
;
25208 it
->descent
+= thick
;
25213 if (it
->start_of_box_run_p
)
25214 it
->pixel_width
+= thick
;
25215 if (it
->end_of_box_run_p
)
25216 it
->pixel_width
+= thick
;
25219 /* If face has an overline, add the height of the overline
25220 (1 pixel) and a 1 pixel margin to the character height. */
25221 if (face
->overline_p
)
25222 it
->ascent
+= overline_margin
;
25224 take_vertical_position_into_account (it
);
25225 if (it
->ascent
< 0)
25227 if (it
->descent
< 0)
25230 if (it
->glyph_row
&& cmp
->glyph_len
> 0)
25231 append_composite_glyph (it
);
25233 else if (it
->what
== IT_COMPOSITION
)
25235 /* A dynamic (automatic) composition. */
25236 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25237 Lisp_Object gstring
;
25238 struct font_metrics metrics
;
25242 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
25244 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
25247 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
25248 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25249 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
25250 it
->descent
= it
->phys_descent
= metrics
.descent
;
25251 if (face
->box
!= FACE_NO_BOX
)
25253 int thick
= face
->box_line_width
;
25257 it
->ascent
+= thick
;
25258 it
->descent
+= thick
;
25263 if (it
->start_of_box_run_p
)
25264 it
->pixel_width
+= thick
;
25265 if (it
->end_of_box_run_p
)
25266 it
->pixel_width
+= thick
;
25268 /* If face has an overline, add the height of the overline
25269 (1 pixel) and a 1 pixel margin to the character height. */
25270 if (face
->overline_p
)
25271 it
->ascent
+= overline_margin
;
25272 take_vertical_position_into_account (it
);
25273 if (it
->ascent
< 0)
25275 if (it
->descent
< 0)
25279 append_composite_glyph (it
);
25281 else if (it
->what
== IT_GLYPHLESS
)
25282 produce_glyphless_glyph (it
, 0, Qnil
);
25283 else if (it
->what
== IT_IMAGE
)
25284 produce_image_glyph (it
);
25285 else if (it
->what
== IT_STRETCH
)
25286 produce_stretch_glyph (it
);
25289 /* Accumulate dimensions. Note: can't assume that it->descent > 0
25290 because this isn't true for images with `:ascent 100'. */
25291 eassert (it
->ascent
>= 0 && it
->descent
>= 0);
25292 if (it
->area
== TEXT_AREA
)
25293 it
->current_x
+= it
->pixel_width
;
25295 if (extra_line_spacing
> 0)
25297 it
->descent
+= extra_line_spacing
;
25298 if (extra_line_spacing
> it
->max_extra_line_spacing
)
25299 it
->max_extra_line_spacing
= extra_line_spacing
;
25302 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
25303 it
->max_descent
= max (it
->max_descent
, it
->descent
);
25304 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
25305 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
25309 Output LEN glyphs starting at START at the nominal cursor position.
25310 Advance the nominal cursor over the text. The global variable
25311 updated_window contains the window being updated, updated_row is
25312 the glyph row being updated, and updated_area is the area of that
25313 row being updated. */
25316 x_write_glyphs (struct glyph
*start
, int len
)
25318 int x
, hpos
, chpos
= updated_window
->phys_cursor
.hpos
;
25320 eassert (updated_window
&& updated_row
);
25321 /* When the window is hscrolled, cursor hpos can legitimately be out
25322 of bounds, but we draw the cursor at the corresponding window
25323 margin in that case. */
25324 if (!updated_row
->reversed_p
&& chpos
< 0)
25326 if (updated_row
->reversed_p
&& chpos
>= updated_row
->used
[TEXT_AREA
])
25327 chpos
= updated_row
->used
[TEXT_AREA
] - 1;
25331 /* Write glyphs. */
25333 hpos
= start
- updated_row
->glyphs
[updated_area
];
25334 x
= draw_glyphs (updated_window
, output_cursor
.x
,
25335 updated_row
, updated_area
,
25337 DRAW_NORMAL_TEXT
, 0);
25339 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
25340 if (updated_area
== TEXT_AREA
25341 && updated_window
->phys_cursor_on_p
25342 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
25344 && chpos
< hpos
+ len
)
25345 updated_window
->phys_cursor_on_p
= 0;
25349 /* Advance the output cursor. */
25350 output_cursor
.hpos
+= len
;
25351 output_cursor
.x
= x
;
25356 Insert LEN glyphs from START at the nominal cursor position. */
25359 x_insert_glyphs (struct glyph
*start
, int len
)
25363 int line_height
, shift_by_width
, shifted_region_width
;
25364 struct glyph_row
*row
;
25365 struct glyph
*glyph
;
25366 int frame_x
, frame_y
;
25369 eassert (updated_window
&& updated_row
);
25371 w
= updated_window
;
25372 f
= XFRAME (WINDOW_FRAME (w
));
25374 /* Get the height of the line we are in. */
25376 line_height
= row
->height
;
25378 /* Get the width of the glyphs to insert. */
25379 shift_by_width
= 0;
25380 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
25381 shift_by_width
+= glyph
->pixel_width
;
25383 /* Get the width of the region to shift right. */
25384 shifted_region_width
= (window_box_width (w
, updated_area
)
25389 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
25390 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
25392 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
25393 line_height
, shift_by_width
);
25395 /* Write the glyphs. */
25396 hpos
= start
- row
->glyphs
[updated_area
];
25397 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
25399 DRAW_NORMAL_TEXT
, 0);
25401 /* Advance the output cursor. */
25402 output_cursor
.hpos
+= len
;
25403 output_cursor
.x
+= shift_by_width
;
25409 Erase the current text line from the nominal cursor position
25410 (inclusive) to pixel column TO_X (exclusive). The idea is that
25411 everything from TO_X onward is already erased.
25413 TO_X is a pixel position relative to updated_area of
25414 updated_window. TO_X == -1 means clear to the end of this area. */
25417 x_clear_end_of_line (int to_x
)
25420 struct window
*w
= updated_window
;
25421 int max_x
, min_y
, max_y
;
25422 int from_x
, from_y
, to_y
;
25424 eassert (updated_window
&& updated_row
);
25425 f
= XFRAME (w
->frame
);
25427 if (updated_row
->full_width_p
)
25428 max_x
= WINDOW_TOTAL_WIDTH (w
);
25430 max_x
= window_box_width (w
, updated_area
);
25431 max_y
= window_text_bottom_y (w
);
25433 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
25434 of window. For TO_X > 0, truncate to end of drawing area. */
25440 to_x
= min (to_x
, max_x
);
25442 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
25444 /* Notice if the cursor will be cleared by this operation. */
25445 if (!updated_row
->full_width_p
)
25446 notice_overwritten_cursor (w
, updated_area
,
25447 output_cursor
.x
, -1,
25449 MATRIX_ROW_BOTTOM_Y (updated_row
));
25451 from_x
= output_cursor
.x
;
25453 /* Translate to frame coordinates. */
25454 if (updated_row
->full_width_p
)
25456 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
25457 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
25461 int area_left
= window_box_left (w
, updated_area
);
25462 from_x
+= area_left
;
25466 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
25467 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
25468 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
25470 /* Prevent inadvertently clearing to end of the X window. */
25471 if (to_x
> from_x
&& to_y
> from_y
)
25474 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
25475 to_x
- from_x
, to_y
- from_y
);
25480 #endif /* HAVE_WINDOW_SYSTEM */
25484 /***********************************************************************
25486 ***********************************************************************/
25488 /* Value is the internal representation of the specified cursor type
25489 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
25490 of the bar cursor. */
25492 static enum text_cursor_kinds
25493 get_specified_cursor_type (Lisp_Object arg
, int *width
)
25495 enum text_cursor_kinds type
;
25500 if (EQ (arg
, Qbox
))
25501 return FILLED_BOX_CURSOR
;
25503 if (EQ (arg
, Qhollow
))
25504 return HOLLOW_BOX_CURSOR
;
25506 if (EQ (arg
, Qbar
))
25513 && EQ (XCAR (arg
), Qbar
)
25514 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
25516 *width
= XINT (XCDR (arg
));
25520 if (EQ (arg
, Qhbar
))
25523 return HBAR_CURSOR
;
25527 && EQ (XCAR (arg
), Qhbar
)
25528 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
25530 *width
= XINT (XCDR (arg
));
25531 return HBAR_CURSOR
;
25534 /* Treat anything unknown as "hollow box cursor".
25535 It was bad to signal an error; people have trouble fixing
25536 .Xdefaults with Emacs, when it has something bad in it. */
25537 type
= HOLLOW_BOX_CURSOR
;
25542 /* Set the default cursor types for specified frame. */
25544 set_frame_cursor_types (struct frame
*f
, Lisp_Object arg
)
25549 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
25550 FRAME_CURSOR_WIDTH (f
) = width
;
25552 /* By default, set up the blink-off state depending on the on-state. */
25554 tem
= Fassoc (arg
, Vblink_cursor_alist
);
25557 FRAME_BLINK_OFF_CURSOR (f
)
25558 = get_specified_cursor_type (XCDR (tem
), &width
);
25559 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
25562 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
25566 #ifdef HAVE_WINDOW_SYSTEM
25568 /* Return the cursor we want to be displayed in window W. Return
25569 width of bar/hbar cursor through WIDTH arg. Return with
25570 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
25571 (i.e. if the `system caret' should track this cursor).
25573 In a mini-buffer window, we want the cursor only to appear if we
25574 are reading input from this window. For the selected window, we
25575 want the cursor type given by the frame parameter or buffer local
25576 setting of cursor-type. If explicitly marked off, draw no cursor.
25577 In all other cases, we want a hollow box cursor. */
25579 static enum text_cursor_kinds
25580 get_window_cursor_type (struct window
*w
, struct glyph
*glyph
, int *width
,
25581 int *active_cursor
)
25583 struct frame
*f
= XFRAME (w
->frame
);
25584 struct buffer
*b
= XBUFFER (w
->buffer
);
25585 int cursor_type
= DEFAULT_CURSOR
;
25586 Lisp_Object alt_cursor
;
25587 int non_selected
= 0;
25589 *active_cursor
= 1;
25592 if (cursor_in_echo_area
25593 && FRAME_HAS_MINIBUF_P (f
)
25594 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
25596 if (w
== XWINDOW (echo_area_window
))
25598 if (EQ (BVAR (b
, cursor_type
), Qt
) || NILP (BVAR (b
, cursor_type
)))
25600 *width
= FRAME_CURSOR_WIDTH (f
);
25601 return FRAME_DESIRED_CURSOR (f
);
25604 return get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
25607 *active_cursor
= 0;
25611 /* Detect a nonselected window or nonselected frame. */
25612 else if (w
!= XWINDOW (f
->selected_window
)
25613 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)
25615 *active_cursor
= 0;
25617 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
25623 /* Never display a cursor in a window in which cursor-type is nil. */
25624 if (NILP (BVAR (b
, cursor_type
)))
25627 /* Get the normal cursor type for this window. */
25628 if (EQ (BVAR (b
, cursor_type
), Qt
))
25630 cursor_type
= FRAME_DESIRED_CURSOR (f
);
25631 *width
= FRAME_CURSOR_WIDTH (f
);
25634 cursor_type
= get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
25636 /* Use cursor-in-non-selected-windows instead
25637 for non-selected window or frame. */
25640 alt_cursor
= BVAR (b
, cursor_in_non_selected_windows
);
25641 if (!EQ (Qt
, alt_cursor
))
25642 return get_specified_cursor_type (alt_cursor
, width
);
25643 /* t means modify the normal cursor type. */
25644 if (cursor_type
== FILLED_BOX_CURSOR
)
25645 cursor_type
= HOLLOW_BOX_CURSOR
;
25646 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
25648 return cursor_type
;
25651 /* Use normal cursor if not blinked off. */
25652 if (!w
->cursor_off_p
)
25654 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
25656 if (cursor_type
== FILLED_BOX_CURSOR
)
25658 /* Using a block cursor on large images can be very annoying.
25659 So use a hollow cursor for "large" images.
25660 If image is not transparent (no mask), also use hollow cursor. */
25661 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
25662 if (img
!= NULL
&& IMAGEP (img
->spec
))
25664 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
25665 where N = size of default frame font size.
25666 This should cover most of the "tiny" icons people may use. */
25668 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
25669 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
25670 cursor_type
= HOLLOW_BOX_CURSOR
;
25673 else if (cursor_type
!= NO_CURSOR
)
25675 /* Display current only supports BOX and HOLLOW cursors for images.
25676 So for now, unconditionally use a HOLLOW cursor when cursor is
25677 not a solid box cursor. */
25678 cursor_type
= HOLLOW_BOX_CURSOR
;
25681 return cursor_type
;
25684 /* Cursor is blinked off, so determine how to "toggle" it. */
25686 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
25687 if ((alt_cursor
= Fassoc (BVAR (b
, cursor_type
), Vblink_cursor_alist
), !NILP (alt_cursor
)))
25688 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
25690 /* Then see if frame has specified a specific blink off cursor type. */
25691 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
25693 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
25694 return FRAME_BLINK_OFF_CURSOR (f
);
25698 /* Some people liked having a permanently visible blinking cursor,
25699 while others had very strong opinions against it. So it was
25700 decided to remove it. KFS 2003-09-03 */
25702 /* Finally perform built-in cursor blinking:
25703 filled box <-> hollow box
25704 wide [h]bar <-> narrow [h]bar
25705 narrow [h]bar <-> no cursor
25706 other type <-> no cursor */
25708 if (cursor_type
== FILLED_BOX_CURSOR
)
25709 return HOLLOW_BOX_CURSOR
;
25711 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
25714 return cursor_type
;
25722 /* Notice when the text cursor of window W has been completely
25723 overwritten by a drawing operation that outputs glyphs in AREA
25724 starting at X0 and ending at X1 in the line starting at Y0 and
25725 ending at Y1. X coordinates are area-relative. X1 < 0 means all
25726 the rest of the line after X0 has been written. Y coordinates
25727 are window-relative. */
25730 notice_overwritten_cursor (struct window
*w
, enum glyph_row_area area
,
25731 int x0
, int x1
, int y0
, int y1
)
25733 int cx0
, cx1
, cy0
, cy1
;
25734 struct glyph_row
*row
;
25736 if (!w
->phys_cursor_on_p
)
25738 if (area
!= TEXT_AREA
)
25741 if (w
->phys_cursor
.vpos
< 0
25742 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
25743 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
25744 !(row
->enabled_p
&& row
->displays_text_p
)))
25747 if (row
->cursor_in_fringe_p
)
25749 row
->cursor_in_fringe_p
= 0;
25750 draw_fringe_bitmap (w
, row
, row
->reversed_p
);
25751 w
->phys_cursor_on_p
= 0;
25755 cx0
= w
->phys_cursor
.x
;
25756 cx1
= cx0
+ w
->phys_cursor_width
;
25757 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
25760 /* The cursor image will be completely removed from the
25761 screen if the output area intersects the cursor area in
25762 y-direction. When we draw in [y0 y1[, and some part of
25763 the cursor is at y < y0, that part must have been drawn
25764 before. When scrolling, the cursor is erased before
25765 actually scrolling, so we don't come here. When not
25766 scrolling, the rows above the old cursor row must have
25767 changed, and in this case these rows must have written
25768 over the cursor image.
25770 Likewise if part of the cursor is below y1, with the
25771 exception of the cursor being in the first blank row at
25772 the buffer and window end because update_text_area
25773 doesn't draw that row. (Except when it does, but
25774 that's handled in update_text_area.) */
25776 cy0
= w
->phys_cursor
.y
;
25777 cy1
= cy0
+ w
->phys_cursor_height
;
25778 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
25781 w
->phys_cursor_on_p
= 0;
25784 #endif /* HAVE_WINDOW_SYSTEM */
25787 /************************************************************************
25789 ************************************************************************/
25791 #ifdef HAVE_WINDOW_SYSTEM
25794 Fix the display of area AREA of overlapping row ROW in window W
25795 with respect to the overlapping part OVERLAPS. */
25798 x_fix_overlapping_area (struct window
*w
, struct glyph_row
*row
,
25799 enum glyph_row_area area
, int overlaps
)
25806 for (i
= 0; i
< row
->used
[area
];)
25808 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
25810 int start
= i
, start_x
= x
;
25814 x
+= row
->glyphs
[area
][i
].pixel_width
;
25817 while (i
< row
->used
[area
]
25818 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
25820 draw_glyphs (w
, start_x
, row
, area
,
25822 DRAW_NORMAL_TEXT
, overlaps
);
25826 x
+= row
->glyphs
[area
][i
].pixel_width
;
25836 Draw the cursor glyph of window W in glyph row ROW. See the
25837 comment of draw_glyphs for the meaning of HL. */
25840 draw_phys_cursor_glyph (struct window
*w
, struct glyph_row
*row
,
25841 enum draw_glyphs_face hl
)
25843 /* If cursor hpos is out of bounds, don't draw garbage. This can
25844 happen in mini-buffer windows when switching between echo area
25845 glyphs and mini-buffer. */
25846 if ((row
->reversed_p
25847 ? (w
->phys_cursor
.hpos
>= 0)
25848 : (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])))
25850 int on_p
= w
->phys_cursor_on_p
;
25852 int hpos
= w
->phys_cursor
.hpos
;
25854 /* When the window is hscrolled, cursor hpos can legitimately be
25855 out of bounds, but we draw the cursor at the corresponding
25856 window margin in that case. */
25857 if (!row
->reversed_p
&& hpos
< 0)
25859 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
25860 hpos
= row
->used
[TEXT_AREA
] - 1;
25862 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
, hpos
, hpos
+ 1,
25864 w
->phys_cursor_on_p
= on_p
;
25866 if (hl
== DRAW_CURSOR
)
25867 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
25868 /* When we erase the cursor, and ROW is overlapped by other
25869 rows, make sure that these overlapping parts of other rows
25871 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
25873 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
25875 if (row
> w
->current_matrix
->rows
25876 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
25877 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
25878 OVERLAPS_ERASED_CURSOR
);
25880 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
25881 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
25882 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
25883 OVERLAPS_ERASED_CURSOR
);
25890 Erase the image of a cursor of window W from the screen. */
25893 erase_phys_cursor (struct window
*w
)
25895 struct frame
*f
= XFRAME (w
->frame
);
25896 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
25897 int hpos
= w
->phys_cursor
.hpos
;
25898 int vpos
= w
->phys_cursor
.vpos
;
25899 int mouse_face_here_p
= 0;
25900 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
25901 struct glyph_row
*cursor_row
;
25902 struct glyph
*cursor_glyph
;
25903 enum draw_glyphs_face hl
;
25905 /* No cursor displayed or row invalidated => nothing to do on the
25907 if (w
->phys_cursor_type
== NO_CURSOR
)
25908 goto mark_cursor_off
;
25910 /* VPOS >= active_glyphs->nrows means that window has been resized.
25911 Don't bother to erase the cursor. */
25912 if (vpos
>= active_glyphs
->nrows
)
25913 goto mark_cursor_off
;
25915 /* If row containing cursor is marked invalid, there is nothing we
25917 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
25918 if (!cursor_row
->enabled_p
)
25919 goto mark_cursor_off
;
25921 /* If line spacing is > 0, old cursor may only be partially visible in
25922 window after split-window. So adjust visible height. */
25923 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
25924 window_text_bottom_y (w
) - cursor_row
->y
);
25926 /* If row is completely invisible, don't attempt to delete a cursor which
25927 isn't there. This can happen if cursor is at top of a window, and
25928 we switch to a buffer with a header line in that window. */
25929 if (cursor_row
->visible_height
<= 0)
25930 goto mark_cursor_off
;
25932 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
25933 if (cursor_row
->cursor_in_fringe_p
)
25935 cursor_row
->cursor_in_fringe_p
= 0;
25936 draw_fringe_bitmap (w
, cursor_row
, cursor_row
->reversed_p
);
25937 goto mark_cursor_off
;
25940 /* This can happen when the new row is shorter than the old one.
25941 In this case, either draw_glyphs or clear_end_of_line
25942 should have cleared the cursor. Note that we wouldn't be
25943 able to erase the cursor in this case because we don't have a
25944 cursor glyph at hand. */
25945 if ((cursor_row
->reversed_p
25946 ? (w
->phys_cursor
.hpos
< 0)
25947 : (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])))
25948 goto mark_cursor_off
;
25950 /* When the window is hscrolled, cursor hpos can legitimately be out
25951 of bounds, but we draw the cursor at the corresponding window
25952 margin in that case. */
25953 if (!cursor_row
->reversed_p
&& hpos
< 0)
25955 if (cursor_row
->reversed_p
&& hpos
>= cursor_row
->used
[TEXT_AREA
])
25956 hpos
= cursor_row
->used
[TEXT_AREA
] - 1;
25958 /* If the cursor is in the mouse face area, redisplay that when
25959 we clear the cursor. */
25960 if (! NILP (hlinfo
->mouse_face_window
)
25961 && coords_in_mouse_face_p (w
, hpos
, vpos
)
25962 /* Don't redraw the cursor's spot in mouse face if it is at the
25963 end of a line (on a newline). The cursor appears there, but
25964 mouse highlighting does not. */
25965 && cursor_row
->used
[TEXT_AREA
] > hpos
&& hpos
>= 0)
25966 mouse_face_here_p
= 1;
25968 /* Maybe clear the display under the cursor. */
25969 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
25972 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
25975 cursor_glyph
= get_phys_cursor_glyph (w
);
25976 if (cursor_glyph
== NULL
)
25977 goto mark_cursor_off
;
25979 width
= cursor_glyph
->pixel_width
;
25980 left_x
= window_box_left_offset (w
, TEXT_AREA
);
25981 x
= w
->phys_cursor
.x
;
25983 width
-= left_x
- x
;
25984 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
25985 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
25986 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
25989 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
25992 /* Erase the cursor by redrawing the character underneath it. */
25993 if (mouse_face_here_p
)
25994 hl
= DRAW_MOUSE_FACE
;
25996 hl
= DRAW_NORMAL_TEXT
;
25997 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
26000 w
->phys_cursor_on_p
= 0;
26001 w
->phys_cursor_type
= NO_CURSOR
;
26006 Display or clear cursor of window W. If ON is zero, clear the
26007 cursor. If it is non-zero, display the cursor. If ON is nonzero,
26008 where to put the cursor is specified by HPOS, VPOS, X and Y. */
26011 display_and_set_cursor (struct window
*w
, int on
,
26012 int hpos
, int vpos
, int x
, int y
)
26014 struct frame
*f
= XFRAME (w
->frame
);
26015 int new_cursor_type
;
26016 int new_cursor_width
;
26018 struct glyph_row
*glyph_row
;
26019 struct glyph
*glyph
;
26021 /* This is pointless on invisible frames, and dangerous on garbaged
26022 windows and frames; in the latter case, the frame or window may
26023 be in the midst of changing its size, and x and y may be off the
26025 if (! FRAME_VISIBLE_P (f
)
26026 || FRAME_GARBAGED_P (f
)
26027 || vpos
>= w
->current_matrix
->nrows
26028 || hpos
>= w
->current_matrix
->matrix_w
)
26031 /* If cursor is off and we want it off, return quickly. */
26032 if (!on
&& !w
->phys_cursor_on_p
)
26035 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26036 /* If cursor row is not enabled, we don't really know where to
26037 display the cursor. */
26038 if (!glyph_row
->enabled_p
)
26040 w
->phys_cursor_on_p
= 0;
26045 if (!glyph_row
->exact_window_width_line_p
26046 || (0 <= hpos
&& hpos
< glyph_row
->used
[TEXT_AREA
]))
26047 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
26049 eassert (interrupt_input_blocked
);
26051 /* Set new_cursor_type to the cursor we want to be displayed. */
26052 new_cursor_type
= get_window_cursor_type (w
, glyph
,
26053 &new_cursor_width
, &active_cursor
);
26055 /* If cursor is currently being shown and we don't want it to be or
26056 it is in the wrong place, or the cursor type is not what we want,
26058 if (w
->phys_cursor_on_p
26060 || w
->phys_cursor
.x
!= x
26061 || w
->phys_cursor
.y
!= y
26062 || new_cursor_type
!= w
->phys_cursor_type
26063 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
26064 && new_cursor_width
!= w
->phys_cursor_width
)))
26065 erase_phys_cursor (w
);
26067 /* Don't check phys_cursor_on_p here because that flag is only set
26068 to zero in some cases where we know that the cursor has been
26069 completely erased, to avoid the extra work of erasing the cursor
26070 twice. In other words, phys_cursor_on_p can be 1 and the cursor
26071 still not be visible, or it has only been partly erased. */
26074 w
->phys_cursor_ascent
= glyph_row
->ascent
;
26075 w
->phys_cursor_height
= glyph_row
->height
;
26077 /* Set phys_cursor_.* before x_draw_.* is called because some
26078 of them may need the information. */
26079 w
->phys_cursor
.x
= x
;
26080 w
->phys_cursor
.y
= glyph_row
->y
;
26081 w
->phys_cursor
.hpos
= hpos
;
26082 w
->phys_cursor
.vpos
= vpos
;
26085 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
26086 new_cursor_type
, new_cursor_width
,
26087 on
, active_cursor
);
26091 /* Switch the display of W's cursor on or off, according to the value
26095 update_window_cursor (struct window
*w
, int on
)
26097 /* Don't update cursor in windows whose frame is in the process
26098 of being deleted. */
26099 if (w
->current_matrix
)
26101 int hpos
= w
->phys_cursor
.hpos
;
26102 int vpos
= w
->phys_cursor
.vpos
;
26103 struct glyph_row
*row
;
26105 if (vpos
>= w
->current_matrix
->nrows
26106 || hpos
>= w
->current_matrix
->matrix_w
)
26109 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26111 /* When the window is hscrolled, cursor hpos can legitimately be
26112 out of bounds, but we draw the cursor at the corresponding
26113 window margin in that case. */
26114 if (!row
->reversed_p
&& hpos
< 0)
26116 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26117 hpos
= row
->used
[TEXT_AREA
] - 1;
26120 display_and_set_cursor (w
, on
, hpos
, vpos
,
26121 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
26127 /* Call update_window_cursor with parameter ON_P on all leaf windows
26128 in the window tree rooted at W. */
26131 update_cursor_in_window_tree (struct window
*w
, int on_p
)
26135 if (!NILP (w
->hchild
))
26136 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
26137 else if (!NILP (w
->vchild
))
26138 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
26140 update_window_cursor (w
, on_p
);
26142 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
26148 Display the cursor on window W, or clear it, according to ON_P.
26149 Don't change the cursor's position. */
26152 x_update_cursor (struct frame
*f
, int on_p
)
26154 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
26159 Clear the cursor of window W to background color, and mark the
26160 cursor as not shown. This is used when the text where the cursor
26161 is about to be rewritten. */
26164 x_clear_cursor (struct window
*w
)
26166 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
26167 update_window_cursor (w
, 0);
26170 #endif /* HAVE_WINDOW_SYSTEM */
26172 /* Implementation of draw_row_with_mouse_face for GUI sessions, GPM,
26175 draw_row_with_mouse_face (struct window
*w
, int start_x
, struct glyph_row
*row
,
26176 int start_hpos
, int end_hpos
,
26177 enum draw_glyphs_face draw
)
26179 #ifdef HAVE_WINDOW_SYSTEM
26180 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
26182 draw_glyphs (w
, start_x
, row
, TEXT_AREA
, start_hpos
, end_hpos
, draw
, 0);
26186 #if defined (HAVE_GPM) || defined (MSDOS) || defined (WINDOWSNT)
26187 tty_draw_row_with_mouse_face (w
, row
, start_hpos
, end_hpos
, draw
);
26191 /* Display the active region described by mouse_face_* according to DRAW. */
26194 show_mouse_face (Mouse_HLInfo
*hlinfo
, enum draw_glyphs_face draw
)
26196 struct window
*w
= XWINDOW (hlinfo
->mouse_face_window
);
26197 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
26199 if (/* If window is in the process of being destroyed, don't bother
26201 w
->current_matrix
!= NULL
26202 /* Don't update mouse highlight if hidden */
26203 && (draw
!= DRAW_MOUSE_FACE
|| !hlinfo
->mouse_face_hidden
)
26204 /* Recognize when we are called to operate on rows that don't exist
26205 anymore. This can happen when a window is split. */
26206 && hlinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
26208 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
26209 struct glyph_row
*row
, *first
, *last
;
26211 first
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
26212 last
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
26214 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
26216 int start_hpos
, end_hpos
, start_x
;
26218 /* For all but the first row, the highlight starts at column 0. */
26221 /* R2L rows have BEG and END in reversed order, but the
26222 screen drawing geometry is always left to right. So
26223 we need to mirror the beginning and end of the
26224 highlighted area in R2L rows. */
26225 if (!row
->reversed_p
)
26227 start_hpos
= hlinfo
->mouse_face_beg_col
;
26228 start_x
= hlinfo
->mouse_face_beg_x
;
26230 else if (row
== last
)
26232 start_hpos
= hlinfo
->mouse_face_end_col
;
26233 start_x
= hlinfo
->mouse_face_end_x
;
26241 else if (row
->reversed_p
&& row
== last
)
26243 start_hpos
= hlinfo
->mouse_face_end_col
;
26244 start_x
= hlinfo
->mouse_face_end_x
;
26254 if (!row
->reversed_p
)
26255 end_hpos
= hlinfo
->mouse_face_end_col
;
26256 else if (row
== first
)
26257 end_hpos
= hlinfo
->mouse_face_beg_col
;
26260 end_hpos
= row
->used
[TEXT_AREA
];
26261 if (draw
== DRAW_NORMAL_TEXT
)
26262 row
->fill_line_p
= 1; /* Clear to end of line */
26265 else if (row
->reversed_p
&& row
== first
)
26266 end_hpos
= hlinfo
->mouse_face_beg_col
;
26269 end_hpos
= row
->used
[TEXT_AREA
];
26270 if (draw
== DRAW_NORMAL_TEXT
)
26271 row
->fill_line_p
= 1; /* Clear to end of line */
26274 if (end_hpos
> start_hpos
)
26276 draw_row_with_mouse_face (w
, start_x
, row
,
26277 start_hpos
, end_hpos
, draw
);
26280 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
26284 #ifdef HAVE_WINDOW_SYSTEM
26285 /* When we've written over the cursor, arrange for it to
26286 be displayed again. */
26287 if (FRAME_WINDOW_P (f
)
26288 && phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
26290 int hpos
= w
->phys_cursor
.hpos
;
26292 /* When the window is hscrolled, cursor hpos can legitimately be
26293 out of bounds, but we draw the cursor at the corresponding
26294 window margin in that case. */
26295 if (!row
->reversed_p
&& hpos
< 0)
26297 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26298 hpos
= row
->used
[TEXT_AREA
] - 1;
26301 display_and_set_cursor (w
, 1, hpos
, w
->phys_cursor
.vpos
,
26302 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
26305 #endif /* HAVE_WINDOW_SYSTEM */
26308 #ifdef HAVE_WINDOW_SYSTEM
26309 /* Change the mouse cursor. */
26310 if (FRAME_WINDOW_P (f
))
26312 if (draw
== DRAW_NORMAL_TEXT
26313 && !EQ (hlinfo
->mouse_face_window
, f
->tool_bar_window
))
26314 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
26315 else if (draw
== DRAW_MOUSE_FACE
)
26316 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
26318 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
26320 #endif /* HAVE_WINDOW_SYSTEM */
26324 Clear out the mouse-highlighted active region.
26325 Redraw it un-highlighted first. Value is non-zero if mouse
26326 face was actually drawn unhighlighted. */
26329 clear_mouse_face (Mouse_HLInfo
*hlinfo
)
26333 if (!hlinfo
->mouse_face_hidden
&& !NILP (hlinfo
->mouse_face_window
))
26335 show_mouse_face (hlinfo
, DRAW_NORMAL_TEXT
);
26339 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
26340 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
26341 hlinfo
->mouse_face_window
= Qnil
;
26342 hlinfo
->mouse_face_overlay
= Qnil
;
26346 /* Return non-zero if the coordinates HPOS and VPOS on windows W are
26347 within the mouse face on that window. */
26349 coords_in_mouse_face_p (struct window
*w
, int hpos
, int vpos
)
26351 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
26353 /* Quickly resolve the easy cases. */
26354 if (!(WINDOWP (hlinfo
->mouse_face_window
)
26355 && XWINDOW (hlinfo
->mouse_face_window
) == w
))
26357 if (vpos
< hlinfo
->mouse_face_beg_row
26358 || vpos
> hlinfo
->mouse_face_end_row
)
26360 if (vpos
> hlinfo
->mouse_face_beg_row
26361 && vpos
< hlinfo
->mouse_face_end_row
)
26364 if (!MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
)
26366 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
26368 if (hlinfo
->mouse_face_beg_col
<= hpos
&& hpos
< hlinfo
->mouse_face_end_col
)
26371 else if ((vpos
== hlinfo
->mouse_face_beg_row
26372 && hpos
>= hlinfo
->mouse_face_beg_col
)
26373 || (vpos
== hlinfo
->mouse_face_end_row
26374 && hpos
< hlinfo
->mouse_face_end_col
))
26379 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
26381 if (hlinfo
->mouse_face_end_col
< hpos
&& hpos
<= hlinfo
->mouse_face_beg_col
)
26384 else if ((vpos
== hlinfo
->mouse_face_beg_row
26385 && hpos
<= hlinfo
->mouse_face_beg_col
)
26386 || (vpos
== hlinfo
->mouse_face_end_row
26387 && hpos
> hlinfo
->mouse_face_end_col
))
26395 Non-zero if physical cursor of window W is within mouse face. */
26398 cursor_in_mouse_face_p (struct window
*w
)
26400 int hpos
= w
->phys_cursor
.hpos
;
26401 int vpos
= w
->phys_cursor
.vpos
;
26402 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26404 /* When the window is hscrolled, cursor hpos can legitimately be out
26405 of bounds, but we draw the cursor at the corresponding window
26406 margin in that case. */
26407 if (!row
->reversed_p
&& hpos
< 0)
26409 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26410 hpos
= row
->used
[TEXT_AREA
] - 1;
26412 return coords_in_mouse_face_p (w
, hpos
, vpos
);
26417 /* Find the glyph rows START_ROW and END_ROW of window W that display
26418 characters between buffer positions START_CHARPOS and END_CHARPOS
26419 (excluding END_CHARPOS). DISP_STRING is a display string that
26420 covers these buffer positions. This is similar to
26421 row_containing_pos, but is more accurate when bidi reordering makes
26422 buffer positions change non-linearly with glyph rows. */
26424 rows_from_pos_range (struct window
*w
,
26425 ptrdiff_t start_charpos
, ptrdiff_t end_charpos
,
26426 Lisp_Object disp_string
,
26427 struct glyph_row
**start
, struct glyph_row
**end
)
26429 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26430 int last_y
= window_text_bottom_y (w
);
26431 struct glyph_row
*row
;
26436 while (!first
->enabled_p
26437 && first
< MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
26440 /* Find the START row. */
26442 row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
;
26445 /* A row can potentially be the START row if the range of the
26446 characters it displays intersects the range
26447 [START_CHARPOS..END_CHARPOS). */
26448 if (! ((start_charpos
< MATRIX_ROW_START_CHARPOS (row
)
26449 && end_charpos
< MATRIX_ROW_START_CHARPOS (row
))
26450 /* See the commentary in row_containing_pos, for the
26451 explanation of the complicated way to check whether
26452 some position is beyond the end of the characters
26453 displayed by a row. */
26454 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (row
)
26455 || (start_charpos
== MATRIX_ROW_END_CHARPOS (row
)
26456 && !row
->ends_at_zv_p
26457 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
26458 && (end_charpos
> MATRIX_ROW_END_CHARPOS (row
)
26459 || (end_charpos
== MATRIX_ROW_END_CHARPOS (row
)
26460 && !row
->ends_at_zv_p
26461 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))))
26463 /* Found a candidate row. Now make sure at least one of the
26464 glyphs it displays has a charpos from the range
26465 [START_CHARPOS..END_CHARPOS).
26467 This is not obvious because bidi reordering could make
26468 buffer positions of a row be 1,2,3,102,101,100, and if we
26469 want to highlight characters in [50..60), we don't want
26470 this row, even though [50..60) does intersect [1..103),
26471 the range of character positions given by the row's start
26472 and end positions. */
26473 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
26474 struct glyph
*e
= g
+ row
->used
[TEXT_AREA
];
26478 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
26479 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
26480 /* A glyph that comes from DISP_STRING is by
26481 definition to be highlighted. */
26482 || EQ (g
->object
, disp_string
))
26491 /* Find the END row. */
26493 /* If the last row is partially visible, start looking for END
26494 from that row, instead of starting from FIRST. */
26495 && !(row
->enabled_p
26496 && row
->y
< last_y
&& MATRIX_ROW_BOTTOM_Y (row
) > last_y
))
26498 for ( ; row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
; row
++)
26500 struct glyph_row
*next
= row
+ 1;
26501 ptrdiff_t next_start
= MATRIX_ROW_START_CHARPOS (next
);
26503 if (!next
->enabled_p
26504 || next
>= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
)
26505 /* The first row >= START whose range of displayed characters
26506 does NOT intersect the range [START_CHARPOS..END_CHARPOS]
26507 is the row END + 1. */
26508 || (start_charpos
< next_start
26509 && end_charpos
< next_start
)
26510 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (next
)
26511 || (start_charpos
== MATRIX_ROW_END_CHARPOS (next
)
26512 && !next
->ends_at_zv_p
26513 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))
26514 && (end_charpos
> MATRIX_ROW_END_CHARPOS (next
)
26515 || (end_charpos
== MATRIX_ROW_END_CHARPOS (next
)
26516 && !next
->ends_at_zv_p
26517 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))))
26524 /* If the next row's edges intersect [START_CHARPOS..END_CHARPOS],
26525 but none of the characters it displays are in the range, it is
26527 struct glyph
*g
= next
->glyphs
[TEXT_AREA
];
26528 struct glyph
*s
= g
;
26529 struct glyph
*e
= g
+ next
->used
[TEXT_AREA
];
26533 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
26534 && ((start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
26535 /* If the buffer position of the first glyph in
26536 the row is equal to END_CHARPOS, it means
26537 the last character to be highlighted is the
26538 newline of ROW, and we must consider NEXT as
26540 || (((!next
->reversed_p
&& g
== s
)
26541 || (next
->reversed_p
&& g
== e
- 1))
26542 && (g
->charpos
== end_charpos
26543 /* Special case for when NEXT is an
26544 empty line at ZV. */
26545 || (g
->charpos
== -1
26546 && !row
->ends_at_zv_p
26547 && next_start
== end_charpos
)))))
26548 /* A glyph that comes from DISP_STRING is by
26549 definition to be highlighted. */
26550 || EQ (g
->object
, disp_string
))
26559 /* The first row that ends at ZV must be the last to be
26561 else if (next
->ends_at_zv_p
)
26570 /* This function sets the mouse_face_* elements of HLINFO, assuming
26571 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
26572 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
26573 for the overlay or run of text properties specifying the mouse
26574 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
26575 before-string and after-string that must also be highlighted.
26576 DISP_STRING, if non-nil, is a display string that may cover some
26577 or all of the highlighted text. */
26580 mouse_face_from_buffer_pos (Lisp_Object window
,
26581 Mouse_HLInfo
*hlinfo
,
26582 ptrdiff_t mouse_charpos
,
26583 ptrdiff_t start_charpos
,
26584 ptrdiff_t end_charpos
,
26585 Lisp_Object before_string
,
26586 Lisp_Object after_string
,
26587 Lisp_Object disp_string
)
26589 struct window
*w
= XWINDOW (window
);
26590 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26591 struct glyph_row
*r1
, *r2
;
26592 struct glyph
*glyph
, *end
;
26593 ptrdiff_t ignore
, pos
;
26596 eassert (NILP (disp_string
) || STRINGP (disp_string
));
26597 eassert (NILP (before_string
) || STRINGP (before_string
));
26598 eassert (NILP (after_string
) || STRINGP (after_string
));
26600 /* Find the rows corresponding to START_CHARPOS and END_CHARPOS. */
26601 rows_from_pos_range (w
, start_charpos
, end_charpos
, disp_string
, &r1
, &r2
);
26603 r1
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
26604 /* If the before-string or display-string contains newlines,
26605 rows_from_pos_range skips to its last row. Move back. */
26606 if (!NILP (before_string
) || !NILP (disp_string
))
26608 struct glyph_row
*prev
;
26609 while ((prev
= r1
- 1, prev
>= first
)
26610 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
26611 && prev
->used
[TEXT_AREA
] > 0)
26613 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
26614 glyph
= beg
+ prev
->used
[TEXT_AREA
];
26615 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
26617 || !(EQ (glyph
->object
, before_string
)
26618 || EQ (glyph
->object
, disp_string
)))
26625 r2
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
26626 hlinfo
->mouse_face_past_end
= 1;
26628 else if (!NILP (after_string
))
26630 /* If the after-string has newlines, advance to its last row. */
26631 struct glyph_row
*next
;
26632 struct glyph_row
*last
26633 = MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
26635 for (next
= r2
+ 1;
26637 && next
->used
[TEXT_AREA
] > 0
26638 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
26642 /* The rest of the display engine assumes that mouse_face_beg_row is
26643 either above mouse_face_end_row or identical to it. But with
26644 bidi-reordered continued lines, the row for START_CHARPOS could
26645 be below the row for END_CHARPOS. If so, swap the rows and store
26646 them in correct order. */
26649 struct glyph_row
*tem
= r2
;
26655 hlinfo
->mouse_face_beg_y
= r1
->y
;
26656 hlinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (r1
, w
->current_matrix
);
26657 hlinfo
->mouse_face_end_y
= r2
->y
;
26658 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r2
, w
->current_matrix
);
26660 /* For a bidi-reordered row, the positions of BEFORE_STRING,
26661 AFTER_STRING, DISP_STRING, START_CHARPOS, and END_CHARPOS
26662 could be anywhere in the row and in any order. The strategy
26663 below is to find the leftmost and the rightmost glyph that
26664 belongs to either of these 3 strings, or whose position is
26665 between START_CHARPOS and END_CHARPOS, and highlight all the
26666 glyphs between those two. This may cover more than just the text
26667 between START_CHARPOS and END_CHARPOS if the range of characters
26668 strides the bidi level boundary, e.g. if the beginning is in R2L
26669 text while the end is in L2R text or vice versa. */
26670 if (!r1
->reversed_p
)
26672 /* This row is in a left to right paragraph. Scan it left to
26674 glyph
= r1
->glyphs
[TEXT_AREA
];
26675 end
= glyph
+ r1
->used
[TEXT_AREA
];
26678 /* Skip truncation glyphs at the start of the glyph row. */
26679 if (r1
->displays_text_p
)
26681 && INTEGERP (glyph
->object
)
26682 && glyph
->charpos
< 0;
26684 x
+= glyph
->pixel_width
;
26686 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
26687 or DISP_STRING, and the first glyph from buffer whose
26688 position is between START_CHARPOS and END_CHARPOS. */
26690 && !INTEGERP (glyph
->object
)
26691 && !EQ (glyph
->object
, disp_string
)
26692 && !(BUFFERP (glyph
->object
)
26693 && (glyph
->charpos
>= start_charpos
26694 && glyph
->charpos
< end_charpos
));
26697 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26698 are present at buffer positions between START_CHARPOS and
26699 END_CHARPOS, or if they come from an overlay. */
26700 if (EQ (glyph
->object
, before_string
))
26702 pos
= string_buffer_position (before_string
,
26704 /* If pos == 0, it means before_string came from an
26705 overlay, not from a buffer position. */
26706 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26709 else if (EQ (glyph
->object
, after_string
))
26711 pos
= string_buffer_position (after_string
, end_charpos
);
26712 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26715 x
+= glyph
->pixel_width
;
26717 hlinfo
->mouse_face_beg_x
= x
;
26718 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
26722 /* This row is in a right to left paragraph. Scan it right to
26726 end
= r1
->glyphs
[TEXT_AREA
] - 1;
26727 glyph
= end
+ r1
->used
[TEXT_AREA
];
26729 /* Skip truncation glyphs at the start of the glyph row. */
26730 if (r1
->displays_text_p
)
26732 && INTEGERP (glyph
->object
)
26733 && glyph
->charpos
< 0;
26737 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
26738 or DISP_STRING, and the first glyph from buffer whose
26739 position is between START_CHARPOS and END_CHARPOS. */
26741 && !INTEGERP (glyph
->object
)
26742 && !EQ (glyph
->object
, disp_string
)
26743 && !(BUFFERP (glyph
->object
)
26744 && (glyph
->charpos
>= start_charpos
26745 && glyph
->charpos
< end_charpos
));
26748 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26749 are present at buffer positions between START_CHARPOS and
26750 END_CHARPOS, or if they come from an overlay. */
26751 if (EQ (glyph
->object
, before_string
))
26753 pos
= string_buffer_position (before_string
, start_charpos
);
26754 /* If pos == 0, it means before_string came from an
26755 overlay, not from a buffer position. */
26756 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26759 else if (EQ (glyph
->object
, after_string
))
26761 pos
= string_buffer_position (after_string
, end_charpos
);
26762 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26767 glyph
++; /* first glyph to the right of the highlighted area */
26768 for (g
= r1
->glyphs
[TEXT_AREA
], x
= r1
->x
; g
< glyph
; g
++)
26769 x
+= g
->pixel_width
;
26770 hlinfo
->mouse_face_beg_x
= x
;
26771 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
26774 /* If the highlight ends in a different row, compute GLYPH and END
26775 for the end row. Otherwise, reuse the values computed above for
26776 the row where the highlight begins. */
26779 if (!r2
->reversed_p
)
26781 glyph
= r2
->glyphs
[TEXT_AREA
];
26782 end
= glyph
+ r2
->used
[TEXT_AREA
];
26787 end
= r2
->glyphs
[TEXT_AREA
] - 1;
26788 glyph
= end
+ r2
->used
[TEXT_AREA
];
26792 if (!r2
->reversed_p
)
26794 /* Skip truncation and continuation glyphs near the end of the
26795 row, and also blanks and stretch glyphs inserted by
26796 extend_face_to_end_of_line. */
26798 && INTEGERP ((end
- 1)->object
))
26800 /* Scan the rest of the glyph row from the end, looking for the
26801 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
26802 DISP_STRING, or whose position is between START_CHARPOS
26806 && !INTEGERP (end
->object
)
26807 && !EQ (end
->object
, disp_string
)
26808 && !(BUFFERP (end
->object
)
26809 && (end
->charpos
>= start_charpos
26810 && end
->charpos
< end_charpos
));
26813 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26814 are present at buffer positions between START_CHARPOS and
26815 END_CHARPOS, or if they come from an overlay. */
26816 if (EQ (end
->object
, before_string
))
26818 pos
= string_buffer_position (before_string
, start_charpos
);
26819 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26822 else if (EQ (end
->object
, after_string
))
26824 pos
= string_buffer_position (after_string
, end_charpos
);
26825 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26829 /* Find the X coordinate of the last glyph to be highlighted. */
26830 for (; glyph
<= end
; ++glyph
)
26831 x
+= glyph
->pixel_width
;
26833 hlinfo
->mouse_face_end_x
= x
;
26834 hlinfo
->mouse_face_end_col
= glyph
- r2
->glyphs
[TEXT_AREA
];
26838 /* Skip truncation and continuation glyphs near the end of the
26839 row, and also blanks and stretch glyphs inserted by
26840 extend_face_to_end_of_line. */
26844 && INTEGERP (end
->object
))
26846 x
+= end
->pixel_width
;
26849 /* Scan the rest of the glyph row from the end, looking for the
26850 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
26851 DISP_STRING, or whose position is between START_CHARPOS
26855 && !INTEGERP (end
->object
)
26856 && !EQ (end
->object
, disp_string
)
26857 && !(BUFFERP (end
->object
)
26858 && (end
->charpos
>= start_charpos
26859 && end
->charpos
< end_charpos
));
26862 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26863 are present at buffer positions between START_CHARPOS and
26864 END_CHARPOS, or if they come from an overlay. */
26865 if (EQ (end
->object
, before_string
))
26867 pos
= string_buffer_position (before_string
, start_charpos
);
26868 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26871 else if (EQ (end
->object
, after_string
))
26873 pos
= string_buffer_position (after_string
, end_charpos
);
26874 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26877 x
+= end
->pixel_width
;
26879 /* If we exited the above loop because we arrived at the last
26880 glyph of the row, and its buffer position is still not in
26881 range, it means the last character in range is the preceding
26882 newline. Bump the end column and x values to get past the
26885 && BUFFERP (end
->object
)
26886 && (end
->charpos
< start_charpos
26887 || end
->charpos
>= end_charpos
))
26889 x
+= end
->pixel_width
;
26892 hlinfo
->mouse_face_end_x
= x
;
26893 hlinfo
->mouse_face_end_col
= end
- r2
->glyphs
[TEXT_AREA
];
26896 hlinfo
->mouse_face_window
= window
;
26897 hlinfo
->mouse_face_face_id
26898 = face_at_buffer_position (w
, mouse_charpos
, 0, 0, &ignore
,
26900 !hlinfo
->mouse_face_hidden
, -1);
26901 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
26904 /* The following function is not used anymore (replaced with
26905 mouse_face_from_string_pos), but I leave it here for the time
26906 being, in case someone would. */
26908 #if 0 /* not used */
26910 /* Find the position of the glyph for position POS in OBJECT in
26911 window W's current matrix, and return in *X, *Y the pixel
26912 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
26914 RIGHT_P non-zero means return the position of the right edge of the
26915 glyph, RIGHT_P zero means return the left edge position.
26917 If no glyph for POS exists in the matrix, return the position of
26918 the glyph with the next smaller position that is in the matrix, if
26919 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
26920 exists in the matrix, return the position of the glyph with the
26921 next larger position in OBJECT.
26923 Value is non-zero if a glyph was found. */
26926 fast_find_string_pos (struct window
*w
, ptrdiff_t pos
, Lisp_Object object
,
26927 int *hpos
, int *vpos
, int *x
, int *y
, int right_p
)
26929 int yb
= window_text_bottom_y (w
);
26930 struct glyph_row
*r
;
26931 struct glyph
*best_glyph
= NULL
;
26932 struct glyph_row
*best_row
= NULL
;
26935 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26936 r
->enabled_p
&& r
->y
< yb
;
26939 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
26940 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
26943 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
26944 if (EQ (g
->object
, object
))
26946 if (g
->charpos
== pos
)
26953 else if (best_glyph
== NULL
26954 || ((eabs (g
->charpos
- pos
)
26955 < eabs (best_glyph
->charpos
- pos
))
26958 : g
->charpos
> pos
)))
26972 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
26976 *x
+= best_glyph
->pixel_width
;
26981 *vpos
= best_row
- w
->current_matrix
->rows
;
26984 return best_glyph
!= NULL
;
26986 #endif /* not used */
26988 /* Find the positions of the first and the last glyphs in window W's
26989 current matrix that occlude positions [STARTPOS..ENDPOS] in OBJECT
26990 (assumed to be a string), and return in HLINFO's mouse_face_*
26991 members the pixel and column/row coordinates of those glyphs. */
26994 mouse_face_from_string_pos (struct window
*w
, Mouse_HLInfo
*hlinfo
,
26995 Lisp_Object object
,
26996 ptrdiff_t startpos
, ptrdiff_t endpos
)
26998 int yb
= window_text_bottom_y (w
);
26999 struct glyph_row
*r
;
27000 struct glyph
*g
, *e
;
27004 /* Find the glyph row with at least one position in the range
27005 [STARTPOS..ENDPOS], and the first glyph in that row whose
27006 position belongs to that range. */
27007 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27008 r
->enabled_p
&& r
->y
< yb
;
27011 if (!r
->reversed_p
)
27013 g
= r
->glyphs
[TEXT_AREA
];
27014 e
= g
+ r
->used
[TEXT_AREA
];
27015 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
27016 if (EQ (g
->object
, object
)
27017 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
27019 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
27020 hlinfo
->mouse_face_beg_y
= r
->y
;
27021 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
27022 hlinfo
->mouse_face_beg_x
= gx
;
27031 e
= r
->glyphs
[TEXT_AREA
];
27032 g
= e
+ r
->used
[TEXT_AREA
];
27033 for ( ; g
> e
; --g
)
27034 if (EQ ((g
-1)->object
, object
)
27035 && startpos
<= (g
-1)->charpos
&& (g
-1)->charpos
<= endpos
)
27037 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
27038 hlinfo
->mouse_face_beg_y
= r
->y
;
27039 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
27040 for (gx
= r
->x
, g1
= r
->glyphs
[TEXT_AREA
]; g1
< g
; ++g1
)
27041 gx
+= g1
->pixel_width
;
27042 hlinfo
->mouse_face_beg_x
= gx
;
27054 /* Starting with the next row, look for the first row which does NOT
27055 include any glyphs whose positions are in the range. */
27056 for (++r
; r
->enabled_p
&& r
->y
< yb
; ++r
)
27058 g
= r
->glyphs
[TEXT_AREA
];
27059 e
= g
+ r
->used
[TEXT_AREA
];
27061 for ( ; g
< e
; ++g
)
27062 if (EQ (g
->object
, object
)
27063 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
27072 /* The highlighted region ends on the previous row. */
27075 /* Set the end row and its vertical pixel coordinate. */
27076 hlinfo
->mouse_face_end_row
= r
- w
->current_matrix
->rows
;
27077 hlinfo
->mouse_face_end_y
= r
->y
;
27079 /* Compute and set the end column and the end column's horizontal
27080 pixel coordinate. */
27081 if (!r
->reversed_p
)
27083 g
= r
->glyphs
[TEXT_AREA
];
27084 e
= g
+ r
->used
[TEXT_AREA
];
27085 for ( ; e
> g
; --e
)
27086 if (EQ ((e
-1)->object
, object
)
27087 && startpos
<= (e
-1)->charpos
&& (e
-1)->charpos
<= endpos
)
27089 hlinfo
->mouse_face_end_col
= e
- g
;
27091 for (gx
= r
->x
; g
< e
; ++g
)
27092 gx
+= g
->pixel_width
;
27093 hlinfo
->mouse_face_end_x
= gx
;
27097 e
= r
->glyphs
[TEXT_AREA
];
27098 g
= e
+ r
->used
[TEXT_AREA
];
27099 for (gx
= r
->x
; e
< g
; ++e
)
27101 if (EQ (e
->object
, object
)
27102 && startpos
<= e
->charpos
&& e
->charpos
<= endpos
)
27104 gx
+= e
->pixel_width
;
27106 hlinfo
->mouse_face_end_col
= e
- r
->glyphs
[TEXT_AREA
];
27107 hlinfo
->mouse_face_end_x
= gx
;
27111 #ifdef HAVE_WINDOW_SYSTEM
27113 /* See if position X, Y is within a hot-spot of an image. */
27116 on_hot_spot_p (Lisp_Object hot_spot
, int x
, int y
)
27118 if (!CONSP (hot_spot
))
27121 if (EQ (XCAR (hot_spot
), Qrect
))
27123 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
27124 Lisp_Object rect
= XCDR (hot_spot
);
27128 if (!CONSP (XCAR (rect
)))
27130 if (!CONSP (XCDR (rect
)))
27132 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
27134 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
27136 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
27138 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
27142 else if (EQ (XCAR (hot_spot
), Qcircle
))
27144 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
27145 Lisp_Object circ
= XCDR (hot_spot
);
27146 Lisp_Object lr
, lx0
, ly0
;
27148 && CONSP (XCAR (circ
))
27149 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
27150 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
27151 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
27153 double r
= XFLOATINT (lr
);
27154 double dx
= XINT (lx0
) - x
;
27155 double dy
= XINT (ly0
) - y
;
27156 return (dx
* dx
+ dy
* dy
<= r
* r
);
27159 else if (EQ (XCAR (hot_spot
), Qpoly
))
27161 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
27162 if (VECTORP (XCDR (hot_spot
)))
27164 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
27165 Lisp_Object
*poly
= v
->contents
;
27166 ptrdiff_t n
= v
->header
.size
;
27169 Lisp_Object lx
, ly
;
27172 /* Need an even number of coordinates, and at least 3 edges. */
27173 if (n
< 6 || n
& 1)
27176 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
27177 If count is odd, we are inside polygon. Pixels on edges
27178 may or may not be included depending on actual geometry of the
27180 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
27181 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
27183 x0
= XINT (lx
), y0
= XINT (ly
);
27184 for (i
= 0; i
< n
; i
+= 2)
27186 int x1
= x0
, y1
= y0
;
27187 if ((lx
= poly
[i
], !INTEGERP (lx
))
27188 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
27190 x0
= XINT (lx
), y0
= XINT (ly
);
27192 /* Does this segment cross the X line? */
27200 if (y
> y0
&& y
> y1
)
27202 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
27212 find_hot_spot (Lisp_Object map
, int x
, int y
)
27214 while (CONSP (map
))
27216 if (CONSP (XCAR (map
))
27217 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
27225 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
27227 doc
: /* Lookup in image map MAP coordinates X and Y.
27228 An image map is an alist where each element has the format (AREA ID PLIST).
27229 An AREA is specified as either a rectangle, a circle, or a polygon:
27230 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
27231 pixel coordinates of the upper left and bottom right corners.
27232 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
27233 and the radius of the circle; r may be a float or integer.
27234 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
27235 vector describes one corner in the polygon.
27236 Returns the alist element for the first matching AREA in MAP. */)
27237 (Lisp_Object map
, Lisp_Object x
, Lisp_Object y
)
27245 return find_hot_spot (map
,
27246 clip_to_bounds (INT_MIN
, XINT (x
), INT_MAX
),
27247 clip_to_bounds (INT_MIN
, XINT (y
), INT_MAX
));
27251 /* Display frame CURSOR, optionally using shape defined by POINTER. */
27253 define_frame_cursor1 (struct frame
*f
, Cursor cursor
, Lisp_Object pointer
)
27255 /* Do not change cursor shape while dragging mouse. */
27256 if (!NILP (do_mouse_tracking
))
27259 if (!NILP (pointer
))
27261 if (EQ (pointer
, Qarrow
))
27262 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27263 else if (EQ (pointer
, Qhand
))
27264 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
27265 else if (EQ (pointer
, Qtext
))
27266 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
27267 else if (EQ (pointer
, intern ("hdrag")))
27268 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
27269 #ifdef HAVE_X_WINDOWS
27270 else if (EQ (pointer
, intern ("vdrag")))
27271 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
27273 else if (EQ (pointer
, intern ("hourglass")))
27274 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
27275 else if (EQ (pointer
, Qmodeline
))
27276 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
27278 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27281 if (cursor
!= No_Cursor
)
27282 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
27285 #endif /* HAVE_WINDOW_SYSTEM */
27287 /* Take proper action when mouse has moved to the mode or header line
27288 or marginal area AREA of window W, x-position X and y-position Y.
27289 X is relative to the start of the text display area of W, so the
27290 width of bitmap areas and scroll bars must be subtracted to get a
27291 position relative to the start of the mode line. */
27294 note_mode_line_or_margin_highlight (Lisp_Object window
, int x
, int y
,
27295 enum window_part area
)
27297 struct window
*w
= XWINDOW (window
);
27298 struct frame
*f
= XFRAME (w
->frame
);
27299 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
27300 #ifdef HAVE_WINDOW_SYSTEM
27301 Display_Info
*dpyinfo
;
27303 Cursor cursor
= No_Cursor
;
27304 Lisp_Object pointer
= Qnil
;
27305 int dx
, dy
, width
, height
;
27307 Lisp_Object string
, object
= Qnil
;
27308 Lisp_Object pos
IF_LINT (= Qnil
), help
;
27310 Lisp_Object mouse_face
;
27311 int original_x_pixel
= x
;
27312 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
27313 struct glyph_row
*row
IF_LINT (= 0);
27315 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
27320 /* Kludge alert: mode_line_string takes X/Y in pixels, but
27321 returns them in row/column units! */
27322 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
27323 &object
, &dx
, &dy
, &width
, &height
);
27325 row
= (area
== ON_MODE_LINE
27326 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
27327 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
27329 /* Find the glyph under the mouse pointer. */
27330 if (row
->mode_line_p
&& row
->enabled_p
)
27332 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
27333 end
= glyph
+ row
->used
[TEXT_AREA
];
27335 for (x0
= original_x_pixel
;
27336 glyph
< end
&& x0
>= glyph
->pixel_width
;
27338 x0
-= glyph
->pixel_width
;
27346 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
27347 /* Kludge alert: marginal_area_string takes X/Y in pixels, but
27348 returns them in row/column units! */
27349 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
27350 &object
, &dx
, &dy
, &width
, &height
);
27355 #ifdef HAVE_WINDOW_SYSTEM
27356 if (IMAGEP (object
))
27358 Lisp_Object image_map
, hotspot
;
27359 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
27361 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
27363 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
27367 /* Could check XCAR (hotspot) to see if we enter/leave this hot-spot.
27368 If so, we could look for mouse-enter, mouse-leave
27369 properties in PLIST (and do something...). */
27370 hotspot
= XCDR (hotspot
);
27371 if (CONSP (hotspot
)
27372 && (plist
= XCAR (hotspot
), CONSP (plist
)))
27374 pointer
= Fplist_get (plist
, Qpointer
);
27375 if (NILP (pointer
))
27377 help
= Fplist_get (plist
, Qhelp_echo
);
27380 help_echo_string
= help
;
27381 XSETWINDOW (help_echo_window
, w
);
27382 help_echo_object
= w
->buffer
;
27383 help_echo_pos
= charpos
;
27387 if (NILP (pointer
))
27388 pointer
= Fplist_get (XCDR (object
), QCpointer
);
27390 #endif /* HAVE_WINDOW_SYSTEM */
27392 if (STRINGP (string
))
27393 pos
= make_number (charpos
);
27395 /* Set the help text and mouse pointer. If the mouse is on a part
27396 of the mode line without any text (e.g. past the right edge of
27397 the mode line text), use the default help text and pointer. */
27398 if (STRINGP (string
) || area
== ON_MODE_LINE
)
27400 /* Arrange to display the help by setting the global variables
27401 help_echo_string, help_echo_object, and help_echo_pos. */
27404 if (STRINGP (string
))
27405 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
27409 help_echo_string
= help
;
27410 XSETWINDOW (help_echo_window
, w
);
27411 help_echo_object
= string
;
27412 help_echo_pos
= charpos
;
27414 else if (area
== ON_MODE_LINE
)
27416 Lisp_Object default_help
27417 = buffer_local_value_1 (Qmode_line_default_help_echo
,
27420 if (STRINGP (default_help
))
27422 help_echo_string
= default_help
;
27423 XSETWINDOW (help_echo_window
, w
);
27424 help_echo_object
= Qnil
;
27425 help_echo_pos
= -1;
27430 #ifdef HAVE_WINDOW_SYSTEM
27431 /* Change the mouse pointer according to what is under it. */
27432 if (FRAME_WINDOW_P (f
))
27434 dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
27435 if (STRINGP (string
))
27437 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27439 if (NILP (pointer
))
27440 pointer
= Fget_text_property (pos
, Qpointer
, string
);
27442 /* Change the mouse pointer according to what is under X/Y. */
27444 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
27447 map
= Fget_text_property (pos
, Qlocal_map
, string
);
27448 if (!KEYMAPP (map
))
27449 map
= Fget_text_property (pos
, Qkeymap
, string
);
27450 if (!KEYMAPP (map
))
27451 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
27455 /* Default mode-line pointer. */
27456 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
27461 /* Change the mouse face according to what is under X/Y. */
27462 if (STRINGP (string
))
27464 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
27465 if (!NILP (mouse_face
)
27466 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
27471 struct glyph
* tmp_glyph
;
27475 int total_pixel_width
;
27476 ptrdiff_t begpos
, endpos
, ignore
;
27480 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
27481 Qmouse_face
, string
, Qnil
);
27487 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
27489 endpos
= SCHARS (string
);
27493 /* Calculate the glyph position GPOS of GLYPH in the
27494 displayed string, relative to the beginning of the
27495 highlighted part of the string.
27497 Note: GPOS is different from CHARPOS. CHARPOS is the
27498 position of GLYPH in the internal string object. A mode
27499 line string format has structures which are converted to
27500 a flattened string by the Emacs Lisp interpreter. The
27501 internal string is an element of those structures. The
27502 displayed string is the flattened string. */
27503 tmp_glyph
= row_start_glyph
;
27504 while (tmp_glyph
< glyph
27505 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
27506 && begpos
<= tmp_glyph
->charpos
27507 && tmp_glyph
->charpos
< endpos
)))
27509 gpos
= glyph
- tmp_glyph
;
27511 /* Calculate the length GSEQ_LENGTH of the glyph sequence of
27512 the highlighted part of the displayed string to which
27513 GLYPH belongs. Note: GSEQ_LENGTH is different from
27514 SCHARS (STRING), because the latter returns the length of
27515 the internal string. */
27516 for (tmp_glyph
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
27518 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
27519 && begpos
<= tmp_glyph
->charpos
27520 && tmp_glyph
->charpos
< endpos
));
27523 gseq_length
= gpos
+ (tmp_glyph
- glyph
) + 1;
27525 /* Calculate the total pixel width of all the glyphs between
27526 the beginning of the highlighted area and GLYPH. */
27527 total_pixel_width
= 0;
27528 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
27529 total_pixel_width
+= tmp_glyph
->pixel_width
;
27531 /* Pre calculation of re-rendering position. Note: X is in
27532 column units here, after the call to mode_line_string or
27533 marginal_area_string. */
27535 vpos
= (area
== ON_MODE_LINE
27536 ? (w
->current_matrix
)->nrows
- 1
27539 /* If GLYPH's position is included in the region that is
27540 already drawn in mouse face, we have nothing to do. */
27541 if ( EQ (window
, hlinfo
->mouse_face_window
)
27542 && (!row
->reversed_p
27543 ? (hlinfo
->mouse_face_beg_col
<= hpos
27544 && hpos
< hlinfo
->mouse_face_end_col
)
27545 /* In R2L rows we swap BEG and END, see below. */
27546 : (hlinfo
->mouse_face_end_col
<= hpos
27547 && hpos
< hlinfo
->mouse_face_beg_col
))
27548 && hlinfo
->mouse_face_beg_row
== vpos
)
27551 if (clear_mouse_face (hlinfo
))
27552 cursor
= No_Cursor
;
27554 if (!row
->reversed_p
)
27556 hlinfo
->mouse_face_beg_col
= hpos
;
27557 hlinfo
->mouse_face_beg_x
= original_x_pixel
27558 - (total_pixel_width
+ dx
);
27559 hlinfo
->mouse_face_end_col
= hpos
+ gseq_length
;
27560 hlinfo
->mouse_face_end_x
= 0;
27564 /* In R2L rows, show_mouse_face expects BEG and END
27565 coordinates to be swapped. */
27566 hlinfo
->mouse_face_end_col
= hpos
;
27567 hlinfo
->mouse_face_end_x
= original_x_pixel
27568 - (total_pixel_width
+ dx
);
27569 hlinfo
->mouse_face_beg_col
= hpos
+ gseq_length
;
27570 hlinfo
->mouse_face_beg_x
= 0;
27573 hlinfo
->mouse_face_beg_row
= vpos
;
27574 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_beg_row
;
27575 hlinfo
->mouse_face_beg_y
= 0;
27576 hlinfo
->mouse_face_end_y
= 0;
27577 hlinfo
->mouse_face_past_end
= 0;
27578 hlinfo
->mouse_face_window
= window
;
27580 hlinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
27586 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
27588 if (NILP (pointer
))
27591 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
27592 clear_mouse_face (hlinfo
);
27594 #ifdef HAVE_WINDOW_SYSTEM
27595 if (FRAME_WINDOW_P (f
))
27596 define_frame_cursor1 (f
, cursor
, pointer
);
27602 Take proper action when the mouse has moved to position X, Y on
27603 frame F as regards highlighting characters that have mouse-face
27604 properties. Also de-highlighting chars where the mouse was before.
27605 X and Y can be negative or out of range. */
27608 note_mouse_highlight (struct frame
*f
, int x
, int y
)
27610 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
27611 enum window_part part
= ON_NOTHING
;
27612 Lisp_Object window
;
27614 Cursor cursor
= No_Cursor
;
27615 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
27618 /* When a menu is active, don't highlight because this looks odd. */
27619 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (MSDOS)
27620 if (popup_activated ())
27624 if (NILP (Vmouse_highlight
)
27625 || !f
->glyphs_initialized_p
27626 || f
->pointer_invisible
)
27629 hlinfo
->mouse_face_mouse_x
= x
;
27630 hlinfo
->mouse_face_mouse_y
= y
;
27631 hlinfo
->mouse_face_mouse_frame
= f
;
27633 if (hlinfo
->mouse_face_defer
)
27636 if (gc_in_progress
)
27638 hlinfo
->mouse_face_deferred_gc
= 1;
27642 /* Which window is that in? */
27643 window
= window_from_coordinates (f
, x
, y
, &part
, 1);
27645 /* If displaying active text in another window, clear that. */
27646 if (! EQ (window
, hlinfo
->mouse_face_window
)
27647 /* Also clear if we move out of text area in same window. */
27648 || (!NILP (hlinfo
->mouse_face_window
)
27651 && part
!= ON_MODE_LINE
27652 && part
!= ON_HEADER_LINE
))
27653 clear_mouse_face (hlinfo
);
27655 /* Not on a window -> return. */
27656 if (!WINDOWP (window
))
27659 /* Reset help_echo_string. It will get recomputed below. */
27660 help_echo_string
= Qnil
;
27662 /* Convert to window-relative pixel coordinates. */
27663 w
= XWINDOW (window
);
27664 frame_to_window_pixel_xy (w
, &x
, &y
);
27666 #ifdef HAVE_WINDOW_SYSTEM
27667 /* Handle tool-bar window differently since it doesn't display a
27669 if (EQ (window
, f
->tool_bar_window
))
27671 note_tool_bar_highlight (f
, x
, y
);
27676 /* Mouse is on the mode, header line or margin? */
27677 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
27678 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
27680 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
27684 #ifdef HAVE_WINDOW_SYSTEM
27685 if (part
== ON_VERTICAL_BORDER
)
27687 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
27688 help_echo_string
= build_string ("drag-mouse-1: resize");
27690 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
27691 || part
== ON_SCROLL_BAR
)
27692 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27694 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
27697 /* Are we in a window whose display is up to date?
27698 And verify the buffer's text has not changed. */
27699 b
= XBUFFER (w
->buffer
);
27700 if (part
== ON_TEXT
27701 && EQ (w
->window_end_valid
, w
->buffer
)
27702 && w
->last_modified
== BUF_MODIFF (b
)
27703 && w
->last_overlay_modified
== BUF_OVERLAY_MODIFF (b
))
27705 int hpos
, vpos
, dx
, dy
, area
= LAST_AREA
;
27707 struct glyph
*glyph
;
27708 Lisp_Object object
;
27709 Lisp_Object mouse_face
= Qnil
, position
;
27710 Lisp_Object
*overlay_vec
= NULL
;
27711 ptrdiff_t i
, noverlays
;
27712 struct buffer
*obuf
;
27713 ptrdiff_t obegv
, ozv
;
27716 /* Find the glyph under X/Y. */
27717 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
27719 #ifdef HAVE_WINDOW_SYSTEM
27720 /* Look for :pointer property on image. */
27721 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
27723 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
27724 if (img
!= NULL
&& IMAGEP (img
->spec
))
27726 Lisp_Object image_map
, hotspot
;
27727 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
27729 && (hotspot
= find_hot_spot (image_map
,
27730 glyph
->slice
.img
.x
+ dx
,
27731 glyph
->slice
.img
.y
+ dy
),
27733 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
27737 /* Could check XCAR (hotspot) to see if we enter/leave
27739 If so, we could look for mouse-enter, mouse-leave
27740 properties in PLIST (and do something...). */
27741 hotspot
= XCDR (hotspot
);
27742 if (CONSP (hotspot
)
27743 && (plist
= XCAR (hotspot
), CONSP (plist
)))
27745 pointer
= Fplist_get (plist
, Qpointer
);
27746 if (NILP (pointer
))
27748 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
27749 if (!NILP (help_echo_string
))
27751 help_echo_window
= window
;
27752 help_echo_object
= glyph
->object
;
27753 help_echo_pos
= glyph
->charpos
;
27757 if (NILP (pointer
))
27758 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
27761 #endif /* HAVE_WINDOW_SYSTEM */
27763 /* Clear mouse face if X/Y not over text. */
27765 || area
!= TEXT_AREA
27766 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
27767 /* Glyph's OBJECT is an integer for glyphs inserted by the
27768 display engine for its internal purposes, like truncation
27769 and continuation glyphs and blanks beyond the end of
27770 line's text on text terminals. If we are over such a
27771 glyph, we are not over any text. */
27772 || INTEGERP (glyph
->object
)
27773 /* R2L rows have a stretch glyph at their front, which
27774 stands for no text, whereas L2R rows have no glyphs at
27775 all beyond the end of text. Treat such stretch glyphs
27776 like we do with NULL glyphs in L2R rows. */
27777 || (MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
27778 && glyph
== MATRIX_ROW (w
->current_matrix
, vpos
)->glyphs
[TEXT_AREA
]
27779 && glyph
->type
== STRETCH_GLYPH
27780 && glyph
->avoid_cursor_p
))
27782 if (clear_mouse_face (hlinfo
))
27783 cursor
= No_Cursor
;
27784 #ifdef HAVE_WINDOW_SYSTEM
27785 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
27787 if (area
!= TEXT_AREA
)
27788 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27790 pointer
= Vvoid_text_area_pointer
;
27796 pos
= glyph
->charpos
;
27797 object
= glyph
->object
;
27798 if (!STRINGP (object
) && !BUFFERP (object
))
27801 /* If we get an out-of-range value, return now; avoid an error. */
27802 if (BUFFERP (object
) && pos
> BUF_Z (b
))
27805 /* Make the window's buffer temporarily current for
27806 overlays_at and compute_char_face. */
27807 obuf
= current_buffer
;
27808 current_buffer
= b
;
27814 /* Is this char mouse-active or does it have help-echo? */
27815 position
= make_number (pos
);
27817 if (BUFFERP (object
))
27819 /* Put all the overlays we want in a vector in overlay_vec. */
27820 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
27821 /* Sort overlays into increasing priority order. */
27822 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
27827 same_region
= coords_in_mouse_face_p (w
, hpos
, vpos
);
27830 cursor
= No_Cursor
;
27832 /* Check mouse-face highlighting. */
27834 /* If there exists an overlay with mouse-face overlapping
27835 the one we are currently highlighting, we have to
27836 check if we enter the overlapping overlay, and then
27837 highlight only that. */
27838 || (OVERLAYP (hlinfo
->mouse_face_overlay
)
27839 && mouse_face_overlay_overlaps (hlinfo
->mouse_face_overlay
)))
27841 /* Find the highest priority overlay with a mouse-face. */
27842 Lisp_Object overlay
= Qnil
;
27843 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
27845 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
27846 if (!NILP (mouse_face
))
27847 overlay
= overlay_vec
[i
];
27850 /* If we're highlighting the same overlay as before, there's
27851 no need to do that again. */
27852 if (!NILP (overlay
) && EQ (overlay
, hlinfo
->mouse_face_overlay
))
27853 goto check_help_echo
;
27854 hlinfo
->mouse_face_overlay
= overlay
;
27856 /* Clear the display of the old active region, if any. */
27857 if (clear_mouse_face (hlinfo
))
27858 cursor
= No_Cursor
;
27860 /* If no overlay applies, get a text property. */
27861 if (NILP (overlay
))
27862 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
27864 /* Next, compute the bounds of the mouse highlighting and
27866 if (!NILP (mouse_face
) && STRINGP (object
))
27868 /* The mouse-highlighting comes from a display string
27869 with a mouse-face. */
27873 s
= Fprevious_single_property_change
27874 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
27875 e
= Fnext_single_property_change
27876 (position
, Qmouse_face
, object
, Qnil
);
27878 s
= make_number (0);
27880 e
= make_number (SCHARS (object
) - 1);
27881 mouse_face_from_string_pos (w
, hlinfo
, object
,
27882 XINT (s
), XINT (e
));
27883 hlinfo
->mouse_face_past_end
= 0;
27884 hlinfo
->mouse_face_window
= window
;
27885 hlinfo
->mouse_face_face_id
27886 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
27887 glyph
->face_id
, 1);
27888 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
27889 cursor
= No_Cursor
;
27893 /* The mouse-highlighting, if any, comes from an overlay
27894 or text property in the buffer. */
27895 Lisp_Object buffer
IF_LINT (= Qnil
);
27896 Lisp_Object disp_string
IF_LINT (= Qnil
);
27898 if (STRINGP (object
))
27900 /* If we are on a display string with no mouse-face,
27901 check if the text under it has one. */
27902 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
27903 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
27904 pos
= string_buffer_position (object
, start
);
27907 mouse_face
= get_char_property_and_overlay
27908 (make_number (pos
), Qmouse_face
, w
->buffer
, &overlay
);
27909 buffer
= w
->buffer
;
27910 disp_string
= object
;
27916 disp_string
= Qnil
;
27919 if (!NILP (mouse_face
))
27921 Lisp_Object before
, after
;
27922 Lisp_Object before_string
, after_string
;
27923 /* To correctly find the limits of mouse highlight
27924 in a bidi-reordered buffer, we must not use the
27925 optimization of limiting the search in
27926 previous-single-property-change and
27927 next-single-property-change, because
27928 rows_from_pos_range needs the real start and end
27929 positions to DTRT in this case. That's because
27930 the first row visible in a window does not
27931 necessarily display the character whose position
27932 is the smallest. */
27934 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
27935 ? Fmarker_position (w
->start
)
27938 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
27939 ? make_number (BUF_Z (XBUFFER (buffer
))
27940 - XFASTINT (w
->window_end_pos
))
27943 if (NILP (overlay
))
27945 /* Handle the text property case. */
27946 before
= Fprevious_single_property_change
27947 (make_number (pos
+ 1), Qmouse_face
, buffer
, lim1
);
27948 after
= Fnext_single_property_change
27949 (make_number (pos
), Qmouse_face
, buffer
, lim2
);
27950 before_string
= after_string
= Qnil
;
27954 /* Handle the overlay case. */
27955 before
= Foverlay_start (overlay
);
27956 after
= Foverlay_end (overlay
);
27957 before_string
= Foverlay_get (overlay
, Qbefore_string
);
27958 after_string
= Foverlay_get (overlay
, Qafter_string
);
27960 if (!STRINGP (before_string
)) before_string
= Qnil
;
27961 if (!STRINGP (after_string
)) after_string
= Qnil
;
27964 mouse_face_from_buffer_pos (window
, hlinfo
, pos
,
27967 : XFASTINT (before
),
27969 ? BUF_Z (XBUFFER (buffer
))
27970 : XFASTINT (after
),
27971 before_string
, after_string
,
27973 cursor
= No_Cursor
;
27980 /* Look for a `help-echo' property. */
27981 if (NILP (help_echo_string
)) {
27982 Lisp_Object help
, overlay
;
27984 /* Check overlays first. */
27985 help
= overlay
= Qnil
;
27986 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
27988 overlay
= overlay_vec
[i
];
27989 help
= Foverlay_get (overlay
, Qhelp_echo
);
27994 help_echo_string
= help
;
27995 help_echo_window
= window
;
27996 help_echo_object
= overlay
;
27997 help_echo_pos
= pos
;
28001 Lisp_Object obj
= glyph
->object
;
28002 ptrdiff_t charpos
= glyph
->charpos
;
28004 /* Try text properties. */
28007 && charpos
< SCHARS (obj
))
28009 help
= Fget_text_property (make_number (charpos
),
28013 /* If the string itself doesn't specify a help-echo,
28014 see if the buffer text ``under'' it does. */
28015 struct glyph_row
*r
28016 = MATRIX_ROW (w
->current_matrix
, vpos
);
28017 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28018 ptrdiff_t p
= string_buffer_position (obj
, start
);
28021 help
= Fget_char_property (make_number (p
),
28022 Qhelp_echo
, w
->buffer
);
28031 else if (BUFFERP (obj
)
28034 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
28039 help_echo_string
= help
;
28040 help_echo_window
= window
;
28041 help_echo_object
= obj
;
28042 help_echo_pos
= charpos
;
28047 #ifdef HAVE_WINDOW_SYSTEM
28048 /* Look for a `pointer' property. */
28049 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
28051 /* Check overlays first. */
28052 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
28053 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
28055 if (NILP (pointer
))
28057 Lisp_Object obj
= glyph
->object
;
28058 ptrdiff_t charpos
= glyph
->charpos
;
28060 /* Try text properties. */
28063 && charpos
< SCHARS (obj
))
28065 pointer
= Fget_text_property (make_number (charpos
),
28067 if (NILP (pointer
))
28069 /* If the string itself doesn't specify a pointer,
28070 see if the buffer text ``under'' it does. */
28071 struct glyph_row
*r
28072 = MATRIX_ROW (w
->current_matrix
, vpos
);
28073 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28074 ptrdiff_t p
= string_buffer_position (obj
, start
);
28076 pointer
= Fget_char_property (make_number (p
),
28077 Qpointer
, w
->buffer
);
28080 else if (BUFFERP (obj
)
28083 pointer
= Fget_text_property (make_number (charpos
),
28087 #endif /* HAVE_WINDOW_SYSTEM */
28091 current_buffer
= obuf
;
28096 #ifdef HAVE_WINDOW_SYSTEM
28097 if (FRAME_WINDOW_P (f
))
28098 define_frame_cursor1 (f
, cursor
, pointer
);
28100 /* This is here to prevent a compiler error, about "label at end of
28101 compound statement". */
28108 Clear any mouse-face on window W. This function is part of the
28109 redisplay interface, and is called from try_window_id and similar
28110 functions to ensure the mouse-highlight is off. */
28113 x_clear_window_mouse_face (struct window
*w
)
28115 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
28116 Lisp_Object window
;
28119 XSETWINDOW (window
, w
);
28120 if (EQ (window
, hlinfo
->mouse_face_window
))
28121 clear_mouse_face (hlinfo
);
28127 Just discard the mouse face information for frame F, if any.
28128 This is used when the size of F is changed. */
28131 cancel_mouse_face (struct frame
*f
)
28133 Lisp_Object window
;
28134 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28136 window
= hlinfo
->mouse_face_window
;
28137 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
28139 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
28140 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
28141 hlinfo
->mouse_face_window
= Qnil
;
28147 /***********************************************************************
28149 ***********************************************************************/
28151 #ifdef HAVE_WINDOW_SYSTEM
28153 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
28154 which intersects rectangle R. R is in window-relative coordinates. */
28157 expose_area (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
,
28158 enum glyph_row_area area
)
28160 struct glyph
*first
= row
->glyphs
[area
];
28161 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
28162 struct glyph
*last
;
28163 int first_x
, start_x
, x
;
28165 if (area
== TEXT_AREA
&& row
->fill_line_p
)
28166 /* If row extends face to end of line write the whole line. */
28167 draw_glyphs (w
, 0, row
, area
,
28168 0, row
->used
[area
],
28169 DRAW_NORMAL_TEXT
, 0);
28172 /* Set START_X to the window-relative start position for drawing glyphs of
28173 AREA. The first glyph of the text area can be partially visible.
28174 The first glyphs of other areas cannot. */
28175 start_x
= window_box_left_offset (w
, area
);
28177 if (area
== TEXT_AREA
)
28180 /* Find the first glyph that must be redrawn. */
28182 && x
+ first
->pixel_width
< r
->x
)
28184 x
+= first
->pixel_width
;
28188 /* Find the last one. */
28192 && x
< r
->x
+ r
->width
)
28194 x
+= last
->pixel_width
;
28200 draw_glyphs (w
, first_x
- start_x
, row
, area
,
28201 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
28202 DRAW_NORMAL_TEXT
, 0);
28207 /* Redraw the parts of the glyph row ROW on window W intersecting
28208 rectangle R. R is in window-relative coordinates. Value is
28209 non-zero if mouse-face was overwritten. */
28212 expose_line (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
)
28214 eassert (row
->enabled_p
);
28216 if (row
->mode_line_p
|| w
->pseudo_window_p
)
28217 draw_glyphs (w
, 0, row
, TEXT_AREA
,
28218 0, row
->used
[TEXT_AREA
],
28219 DRAW_NORMAL_TEXT
, 0);
28222 if (row
->used
[LEFT_MARGIN_AREA
])
28223 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
28224 if (row
->used
[TEXT_AREA
])
28225 expose_area (w
, row
, r
, TEXT_AREA
);
28226 if (row
->used
[RIGHT_MARGIN_AREA
])
28227 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
28228 draw_row_fringe_bitmaps (w
, row
);
28231 return row
->mouse_face_p
;
28235 /* Redraw those parts of glyphs rows during expose event handling that
28236 overlap other rows. Redrawing of an exposed line writes over parts
28237 of lines overlapping that exposed line; this function fixes that.
28239 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
28240 row in W's current matrix that is exposed and overlaps other rows.
28241 LAST_OVERLAPPING_ROW is the last such row. */
28244 expose_overlaps (struct window
*w
,
28245 struct glyph_row
*first_overlapping_row
,
28246 struct glyph_row
*last_overlapping_row
,
28249 struct glyph_row
*row
;
28251 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
28252 if (row
->overlapping_p
)
28254 eassert (row
->enabled_p
&& !row
->mode_line_p
);
28257 if (row
->used
[LEFT_MARGIN_AREA
])
28258 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
28260 if (row
->used
[TEXT_AREA
])
28261 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
28263 if (row
->used
[RIGHT_MARGIN_AREA
])
28264 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
28270 /* Return non-zero if W's cursor intersects rectangle R. */
28273 phys_cursor_in_rect_p (struct window
*w
, XRectangle
*r
)
28275 XRectangle cr
, result
;
28276 struct glyph
*cursor_glyph
;
28277 struct glyph_row
*row
;
28279 if (w
->phys_cursor
.vpos
>= 0
28280 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
28281 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
28283 && row
->cursor_in_fringe_p
)
28285 /* Cursor is in the fringe. */
28286 cr
.x
= window_box_right_offset (w
,
28287 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
28288 ? RIGHT_MARGIN_AREA
28291 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
28292 cr
.height
= row
->height
;
28293 return x_intersect_rectangles (&cr
, r
, &result
);
28296 cursor_glyph
= get_phys_cursor_glyph (w
);
28299 /* r is relative to W's box, but w->phys_cursor.x is relative
28300 to left edge of W's TEXT area. Adjust it. */
28301 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
28302 cr
.y
= w
->phys_cursor
.y
;
28303 cr
.width
= cursor_glyph
->pixel_width
;
28304 cr
.height
= w
->phys_cursor_height
;
28305 /* ++KFS: W32 version used W32-specific IntersectRect here, but
28306 I assume the effect is the same -- and this is portable. */
28307 return x_intersect_rectangles (&cr
, r
, &result
);
28309 /* If we don't understand the format, pretend we're not in the hot-spot. */
28315 Draw a vertical window border to the right of window W if W doesn't
28316 have vertical scroll bars. */
28319 x_draw_vertical_border (struct window
*w
)
28321 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
28323 /* We could do better, if we knew what type of scroll-bar the adjacent
28324 windows (on either side) have... But we don't :-(
28325 However, I think this works ok. ++KFS 2003-04-25 */
28327 /* Redraw borders between horizontally adjacent windows. Don't
28328 do it for frames with vertical scroll bars because either the
28329 right scroll bar of a window, or the left scroll bar of its
28330 neighbor will suffice as a border. */
28331 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
28334 if (!WINDOW_RIGHTMOST_P (w
)
28335 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
28337 int x0
, x1
, y0
, y1
;
28339 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
28342 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
28345 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
28347 else if (!WINDOW_LEFTMOST_P (w
)
28348 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
28350 int x0
, x1
, y0
, y1
;
28352 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
28355 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
28358 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
28363 /* Redraw the part of window W intersection rectangle FR. Pixel
28364 coordinates in FR are frame-relative. Call this function with
28365 input blocked. Value is non-zero if the exposure overwrites
28369 expose_window (struct window
*w
, XRectangle
*fr
)
28371 struct frame
*f
= XFRAME (w
->frame
);
28373 int mouse_face_overwritten_p
= 0;
28375 /* If window is not yet fully initialized, do nothing. This can
28376 happen when toolkit scroll bars are used and a window is split.
28377 Reconfiguring the scroll bar will generate an expose for a newly
28379 if (w
->current_matrix
== NULL
)
28382 /* When we're currently updating the window, display and current
28383 matrix usually don't agree. Arrange for a thorough display
28385 if (w
== updated_window
)
28387 SET_FRAME_GARBAGED (f
);
28391 /* Frame-relative pixel rectangle of W. */
28392 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
28393 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
28394 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
28395 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
28397 if (x_intersect_rectangles (fr
, &wr
, &r
))
28399 int yb
= window_text_bottom_y (w
);
28400 struct glyph_row
*row
;
28401 int cursor_cleared_p
, phys_cursor_on_p
;
28402 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
28404 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
28405 r
.x
, r
.y
, r
.width
, r
.height
));
28407 /* Convert to window coordinates. */
28408 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
28409 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
28411 /* Turn off the cursor. */
28412 if (!w
->pseudo_window_p
28413 && phys_cursor_in_rect_p (w
, &r
))
28415 x_clear_cursor (w
);
28416 cursor_cleared_p
= 1;
28419 cursor_cleared_p
= 0;
28421 /* If the row containing the cursor extends face to end of line,
28422 then expose_area might overwrite the cursor outside the
28423 rectangle and thus notice_overwritten_cursor might clear
28424 w->phys_cursor_on_p. We remember the original value and
28425 check later if it is changed. */
28426 phys_cursor_on_p
= w
->phys_cursor_on_p
;
28428 /* Update lines intersecting rectangle R. */
28429 first_overlapping_row
= last_overlapping_row
= NULL
;
28430 for (row
= w
->current_matrix
->rows
;
28435 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
28437 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
28438 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
28439 || (r
.y
>= y0
&& r
.y
< y1
)
28440 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
28442 /* A header line may be overlapping, but there is no need
28443 to fix overlapping areas for them. KFS 2005-02-12 */
28444 if (row
->overlapping_p
&& !row
->mode_line_p
)
28446 if (first_overlapping_row
== NULL
)
28447 first_overlapping_row
= row
;
28448 last_overlapping_row
= row
;
28452 if (expose_line (w
, row
, &r
))
28453 mouse_face_overwritten_p
= 1;
28456 else if (row
->overlapping_p
)
28458 /* We must redraw a row overlapping the exposed area. */
28460 ? y0
+ row
->phys_height
> r
.y
28461 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
28463 if (first_overlapping_row
== NULL
)
28464 first_overlapping_row
= row
;
28465 last_overlapping_row
= row
;
28473 /* Display the mode line if there is one. */
28474 if (WINDOW_WANTS_MODELINE_P (w
)
28475 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
28477 && row
->y
< r
.y
+ r
.height
)
28479 if (expose_line (w
, row
, &r
))
28480 mouse_face_overwritten_p
= 1;
28483 if (!w
->pseudo_window_p
)
28485 /* Fix the display of overlapping rows. */
28486 if (first_overlapping_row
)
28487 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
28490 /* Draw border between windows. */
28491 x_draw_vertical_border (w
);
28493 /* Turn the cursor on again. */
28494 if (cursor_cleared_p
28495 || (phys_cursor_on_p
&& !w
->phys_cursor_on_p
))
28496 update_window_cursor (w
, 1);
28500 return mouse_face_overwritten_p
;
28505 /* Redraw (parts) of all windows in the window tree rooted at W that
28506 intersect R. R contains frame pixel coordinates. Value is
28507 non-zero if the exposure overwrites mouse-face. */
28510 expose_window_tree (struct window
*w
, XRectangle
*r
)
28512 struct frame
*f
= XFRAME (w
->frame
);
28513 int mouse_face_overwritten_p
= 0;
28515 while (w
&& !FRAME_GARBAGED_P (f
))
28517 if (!NILP (w
->hchild
))
28518 mouse_face_overwritten_p
28519 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
28520 else if (!NILP (w
->vchild
))
28521 mouse_face_overwritten_p
28522 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
28524 mouse_face_overwritten_p
|= expose_window (w
, r
);
28526 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
28529 return mouse_face_overwritten_p
;
28534 Redisplay an exposed area of frame F. X and Y are the upper-left
28535 corner of the exposed rectangle. W and H are width and height of
28536 the exposed area. All are pixel values. W or H zero means redraw
28537 the entire frame. */
28540 expose_frame (struct frame
*f
, int x
, int y
, int w
, int h
)
28543 int mouse_face_overwritten_p
= 0;
28545 TRACE ((stderr
, "expose_frame "));
28547 /* No need to redraw if frame will be redrawn soon. */
28548 if (FRAME_GARBAGED_P (f
))
28550 TRACE ((stderr
, " garbaged\n"));
28554 /* If basic faces haven't been realized yet, there is no point in
28555 trying to redraw anything. This can happen when we get an expose
28556 event while Emacs is starting, e.g. by moving another window. */
28557 if (FRAME_FACE_CACHE (f
) == NULL
28558 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
28560 TRACE ((stderr
, " no faces\n"));
28564 if (w
== 0 || h
== 0)
28567 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
28568 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
28578 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
28579 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
28581 if (WINDOWP (f
->tool_bar_window
))
28582 mouse_face_overwritten_p
28583 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
28585 #ifdef HAVE_X_WINDOWS
28587 #ifndef USE_X_TOOLKIT
28588 if (WINDOWP (f
->menu_bar_window
))
28589 mouse_face_overwritten_p
28590 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
28591 #endif /* not USE_X_TOOLKIT */
28595 /* Some window managers support a focus-follows-mouse style with
28596 delayed raising of frames. Imagine a partially obscured frame,
28597 and moving the mouse into partially obscured mouse-face on that
28598 frame. The visible part of the mouse-face will be highlighted,
28599 then the WM raises the obscured frame. With at least one WM, KDE
28600 2.1, Emacs is not getting any event for the raising of the frame
28601 (even tried with SubstructureRedirectMask), only Expose events.
28602 These expose events will draw text normally, i.e. not
28603 highlighted. Which means we must redo the highlight here.
28604 Subsume it under ``we love X''. --gerd 2001-08-15 */
28605 /* Included in Windows version because Windows most likely does not
28606 do the right thing if any third party tool offers
28607 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
28608 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
28610 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28611 if (f
== hlinfo
->mouse_face_mouse_frame
)
28613 int mouse_x
= hlinfo
->mouse_face_mouse_x
;
28614 int mouse_y
= hlinfo
->mouse_face_mouse_y
;
28615 clear_mouse_face (hlinfo
);
28616 note_mouse_highlight (f
, mouse_x
, mouse_y
);
28623 Determine the intersection of two rectangles R1 and R2. Return
28624 the intersection in *RESULT. Value is non-zero if RESULT is not
28628 x_intersect_rectangles (XRectangle
*r1
, XRectangle
*r2
, XRectangle
*result
)
28630 XRectangle
*left
, *right
;
28631 XRectangle
*upper
, *lower
;
28632 int intersection_p
= 0;
28634 /* Rearrange so that R1 is the left-most rectangle. */
28636 left
= r1
, right
= r2
;
28638 left
= r2
, right
= r1
;
28640 /* X0 of the intersection is right.x0, if this is inside R1,
28641 otherwise there is no intersection. */
28642 if (right
->x
<= left
->x
+ left
->width
)
28644 result
->x
= right
->x
;
28646 /* The right end of the intersection is the minimum of
28647 the right ends of left and right. */
28648 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
28651 /* Same game for Y. */
28653 upper
= r1
, lower
= r2
;
28655 upper
= r2
, lower
= r1
;
28657 /* The upper end of the intersection is lower.y0, if this is inside
28658 of upper. Otherwise, there is no intersection. */
28659 if (lower
->y
<= upper
->y
+ upper
->height
)
28661 result
->y
= lower
->y
;
28663 /* The lower end of the intersection is the minimum of the lower
28664 ends of upper and lower. */
28665 result
->height
= (min (lower
->y
+ lower
->height
,
28666 upper
->y
+ upper
->height
)
28668 intersection_p
= 1;
28672 return intersection_p
;
28675 #endif /* HAVE_WINDOW_SYSTEM */
28678 /***********************************************************************
28680 ***********************************************************************/
28683 syms_of_xdisp (void)
28685 Vwith_echo_area_save_vector
= Qnil
;
28686 staticpro (&Vwith_echo_area_save_vector
);
28688 Vmessage_stack
= Qnil
;
28689 staticpro (&Vmessage_stack
);
28691 DEFSYM (Qinhibit_redisplay
, "inhibit-redisplay");
28693 message_dolog_marker1
= Fmake_marker ();
28694 staticpro (&message_dolog_marker1
);
28695 message_dolog_marker2
= Fmake_marker ();
28696 staticpro (&message_dolog_marker2
);
28697 message_dolog_marker3
= Fmake_marker ();
28698 staticpro (&message_dolog_marker3
);
28701 defsubr (&Sdump_frame_glyph_matrix
);
28702 defsubr (&Sdump_glyph_matrix
);
28703 defsubr (&Sdump_glyph_row
);
28704 defsubr (&Sdump_tool_bar_row
);
28705 defsubr (&Strace_redisplay
);
28706 defsubr (&Strace_to_stderr
);
28708 #ifdef HAVE_WINDOW_SYSTEM
28709 defsubr (&Stool_bar_lines_needed
);
28710 defsubr (&Slookup_image_map
);
28712 defsubr (&Sformat_mode_line
);
28713 defsubr (&Sinvisible_p
);
28714 defsubr (&Scurrent_bidi_paragraph_direction
);
28716 DEFSYM (Qmenu_bar_update_hook
, "menu-bar-update-hook");
28717 DEFSYM (Qoverriding_terminal_local_map
, "overriding-terminal-local-map");
28718 DEFSYM (Qoverriding_local_map
, "overriding-local-map");
28719 DEFSYM (Qwindow_scroll_functions
, "window-scroll-functions");
28720 DEFSYM (Qwindow_text_change_functions
, "window-text-change-functions");
28721 DEFSYM (Qredisplay_end_trigger_functions
, "redisplay-end-trigger-functions");
28722 DEFSYM (Qinhibit_point_motion_hooks
, "inhibit-point-motion-hooks");
28723 DEFSYM (Qeval
, "eval");
28724 DEFSYM (QCdata
, ":data");
28725 DEFSYM (Qdisplay
, "display");
28726 DEFSYM (Qspace_width
, "space-width");
28727 DEFSYM (Qraise
, "raise");
28728 DEFSYM (Qslice
, "slice");
28729 DEFSYM (Qspace
, "space");
28730 DEFSYM (Qmargin
, "margin");
28731 DEFSYM (Qpointer
, "pointer");
28732 DEFSYM (Qleft_margin
, "left-margin");
28733 DEFSYM (Qright_margin
, "right-margin");
28734 DEFSYM (Qcenter
, "center");
28735 DEFSYM (Qline_height
, "line-height");
28736 DEFSYM (QCalign_to
, ":align-to");
28737 DEFSYM (QCrelative_width
, ":relative-width");
28738 DEFSYM (QCrelative_height
, ":relative-height");
28739 DEFSYM (QCeval
, ":eval");
28740 DEFSYM (QCpropertize
, ":propertize");
28741 DEFSYM (QCfile
, ":file");
28742 DEFSYM (Qfontified
, "fontified");
28743 DEFSYM (Qfontification_functions
, "fontification-functions");
28744 DEFSYM (Qtrailing_whitespace
, "trailing-whitespace");
28745 DEFSYM (Qescape_glyph
, "escape-glyph");
28746 DEFSYM (Qnobreak_space
, "nobreak-space");
28747 DEFSYM (Qimage
, "image");
28748 DEFSYM (Qtext
, "text");
28749 DEFSYM (Qboth
, "both");
28750 DEFSYM (Qboth_horiz
, "both-horiz");
28751 DEFSYM (Qtext_image_horiz
, "text-image-horiz");
28752 DEFSYM (QCmap
, ":map");
28753 DEFSYM (QCpointer
, ":pointer");
28754 DEFSYM (Qrect
, "rect");
28755 DEFSYM (Qcircle
, "circle");
28756 DEFSYM (Qpoly
, "poly");
28757 DEFSYM (Qmessage_truncate_lines
, "message-truncate-lines");
28758 DEFSYM (Qgrow_only
, "grow-only");
28759 DEFSYM (Qinhibit_menubar_update
, "inhibit-menubar-update");
28760 DEFSYM (Qinhibit_eval_during_redisplay
, "inhibit-eval-during-redisplay");
28761 DEFSYM (Qposition
, "position");
28762 DEFSYM (Qbuffer_position
, "buffer-position");
28763 DEFSYM (Qobject
, "object");
28764 DEFSYM (Qbar
, "bar");
28765 DEFSYM (Qhbar
, "hbar");
28766 DEFSYM (Qbox
, "box");
28767 DEFSYM (Qhollow
, "hollow");
28768 DEFSYM (Qhand
, "hand");
28769 DEFSYM (Qarrow
, "arrow");
28770 DEFSYM (Qinhibit_free_realized_faces
, "inhibit-free-realized-faces");
28772 list_of_error
= Fcons (Fcons (intern_c_string ("error"),
28773 Fcons (intern_c_string ("void-variable"), Qnil
)),
28775 staticpro (&list_of_error
);
28777 DEFSYM (Qlast_arrow_position
, "last-arrow-position");
28778 DEFSYM (Qlast_arrow_string
, "last-arrow-string");
28779 DEFSYM (Qoverlay_arrow_string
, "overlay-arrow-string");
28780 DEFSYM (Qoverlay_arrow_bitmap
, "overlay-arrow-bitmap");
28782 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
28783 staticpro (&echo_buffer
[0]);
28784 staticpro (&echo_buffer
[1]);
28786 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
28787 staticpro (&echo_area_buffer
[0]);
28788 staticpro (&echo_area_buffer
[1]);
28790 Vmessages_buffer_name
= build_pure_c_string ("*Messages*");
28791 staticpro (&Vmessages_buffer_name
);
28793 mode_line_proptrans_alist
= Qnil
;
28794 staticpro (&mode_line_proptrans_alist
);
28795 mode_line_string_list
= Qnil
;
28796 staticpro (&mode_line_string_list
);
28797 mode_line_string_face
= Qnil
;
28798 staticpro (&mode_line_string_face
);
28799 mode_line_string_face_prop
= Qnil
;
28800 staticpro (&mode_line_string_face_prop
);
28801 Vmode_line_unwind_vector
= Qnil
;
28802 staticpro (&Vmode_line_unwind_vector
);
28804 DEFSYM (Qmode_line_default_help_echo
, "mode-line-default-help-echo");
28806 help_echo_string
= Qnil
;
28807 staticpro (&help_echo_string
);
28808 help_echo_object
= Qnil
;
28809 staticpro (&help_echo_object
);
28810 help_echo_window
= Qnil
;
28811 staticpro (&help_echo_window
);
28812 previous_help_echo_string
= Qnil
;
28813 staticpro (&previous_help_echo_string
);
28814 help_echo_pos
= -1;
28816 DEFSYM (Qright_to_left
, "right-to-left");
28817 DEFSYM (Qleft_to_right
, "left-to-right");
28819 #ifdef HAVE_WINDOW_SYSTEM
28820 DEFVAR_BOOL ("x-stretch-cursor", x_stretch_cursor_p
,
28821 doc
: /* Non-nil means draw block cursor as wide as the glyph under it.
28822 For example, if a block cursor is over a tab, it will be drawn as
28823 wide as that tab on the display. */);
28824 x_stretch_cursor_p
= 0;
28827 DEFVAR_LISP ("show-trailing-whitespace", Vshow_trailing_whitespace
,
28828 doc
: /* Non-nil means highlight trailing whitespace.
28829 The face used for trailing whitespace is `trailing-whitespace'. */);
28830 Vshow_trailing_whitespace
= Qnil
;
28832 DEFVAR_LISP ("nobreak-char-display", Vnobreak_char_display
,
28833 doc
: /* Control highlighting of non-ASCII space and hyphen chars.
28834 If the value is t, Emacs highlights non-ASCII chars which have the
28835 same appearance as an ASCII space or hyphen, using the `nobreak-space'
28836 or `escape-glyph' face respectively.
28838 U+00A0 (no-break space), U+00AD (soft hyphen), U+2010 (hyphen), and
28839 U+2011 (non-breaking hyphen) are affected.
28841 Any other non-nil value means to display these characters as a escape
28842 glyph followed by an ordinary space or hyphen.
28844 A value of nil means no special handling of these characters. */);
28845 Vnobreak_char_display
= Qt
;
28847 DEFVAR_LISP ("void-text-area-pointer", Vvoid_text_area_pointer
,
28848 doc
: /* The pointer shape to show in void text areas.
28849 A value of nil means to show the text pointer. Other options are `arrow',
28850 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
28851 Vvoid_text_area_pointer
= Qarrow
;
28853 DEFVAR_LISP ("inhibit-redisplay", Vinhibit_redisplay
,
28854 doc
: /* Non-nil means don't actually do any redisplay.
28855 This is used for internal purposes. */);
28856 Vinhibit_redisplay
= Qnil
;
28858 DEFVAR_LISP ("global-mode-string", Vglobal_mode_string
,
28859 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
28860 Vglobal_mode_string
= Qnil
;
28862 DEFVAR_LISP ("overlay-arrow-position", Voverlay_arrow_position
,
28863 doc
: /* Marker for where to display an arrow on top of the buffer text.
28864 This must be the beginning of a line in order to work.
28865 See also `overlay-arrow-string'. */);
28866 Voverlay_arrow_position
= Qnil
;
28868 DEFVAR_LISP ("overlay-arrow-string", Voverlay_arrow_string
,
28869 doc
: /* String to display as an arrow in non-window frames.
28870 See also `overlay-arrow-position'. */);
28871 Voverlay_arrow_string
= build_pure_c_string ("=>");
28873 DEFVAR_LISP ("overlay-arrow-variable-list", Voverlay_arrow_variable_list
,
28874 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
28875 The symbols on this list are examined during redisplay to determine
28876 where to display overlay arrows. */);
28877 Voverlay_arrow_variable_list
28878 = Fcons (intern_c_string ("overlay-arrow-position"), Qnil
);
28880 DEFVAR_INT ("scroll-step", emacs_scroll_step
,
28881 doc
: /* The number of lines to try scrolling a window by when point moves out.
28882 If that fails to bring point back on frame, point is centered instead.
28883 If this is zero, point is always centered after it moves off frame.
28884 If you want scrolling to always be a line at a time, you should set
28885 `scroll-conservatively' to a large value rather than set this to 1. */);
28887 DEFVAR_INT ("scroll-conservatively", scroll_conservatively
,
28888 doc
: /* Scroll up to this many lines, to bring point back on screen.
28889 If point moves off-screen, redisplay will scroll by up to
28890 `scroll-conservatively' lines in order to bring point just barely
28891 onto the screen again. If that cannot be done, then redisplay
28892 recenters point as usual.
28894 If the value is greater than 100, redisplay will never recenter point,
28895 but will always scroll just enough text to bring point into view, even
28896 if you move far away.
28898 A value of zero means always recenter point if it moves off screen. */);
28899 scroll_conservatively
= 0;
28901 DEFVAR_INT ("scroll-margin", scroll_margin
,
28902 doc
: /* Number of lines of margin at the top and bottom of a window.
28903 Recenter the window whenever point gets within this many lines
28904 of the top or bottom of the window. */);
28907 DEFVAR_LISP ("display-pixels-per-inch", Vdisplay_pixels_per_inch
,
28908 doc
: /* Pixels per inch value for non-window system displays.
28909 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
28910 Vdisplay_pixels_per_inch
= make_float (72.0);
28913 DEFVAR_INT ("debug-end-pos", debug_end_pos
, doc
: /* Don't ask. */);
28916 DEFVAR_LISP ("truncate-partial-width-windows",
28917 Vtruncate_partial_width_windows
,
28918 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
28919 For an integer value, truncate lines in each window narrower than the
28920 full frame width, provided the window width is less than that integer;
28921 otherwise, respect the value of `truncate-lines'.
28923 For any other non-nil value, truncate lines in all windows that do
28924 not span the full frame width.
28926 A value of nil means to respect the value of `truncate-lines'.
28928 If `word-wrap' is enabled, you might want to reduce this. */);
28929 Vtruncate_partial_width_windows
= make_number (50);
28931 DEFVAR_BOOL ("mode-line-inverse-video", mode_line_inverse_video
,
28932 doc
: /* When nil, display the mode-line/header-line/menu-bar in the default face.
28933 Any other value means to use the appropriate face, `mode-line',
28934 `header-line', or `menu' respectively. */);
28935 mode_line_inverse_video
= 1;
28937 DEFVAR_LISP ("line-number-display-limit", Vline_number_display_limit
,
28938 doc
: /* Maximum buffer size for which line number should be displayed.
28939 If the buffer is bigger than this, the line number does not appear
28940 in the mode line. A value of nil means no limit. */);
28941 Vline_number_display_limit
= Qnil
;
28943 DEFVAR_INT ("line-number-display-limit-width",
28944 line_number_display_limit_width
,
28945 doc
: /* Maximum line width (in characters) for line number display.
28946 If the average length of the lines near point is bigger than this, then the
28947 line number may be omitted from the mode line. */);
28948 line_number_display_limit_width
= 200;
28950 DEFVAR_BOOL ("highlight-nonselected-windows", highlight_nonselected_windows
,
28951 doc
: /* Non-nil means highlight region even in nonselected windows. */);
28952 highlight_nonselected_windows
= 0;
28954 DEFVAR_BOOL ("multiple-frames", multiple_frames
,
28955 doc
: /* Non-nil if more than one frame is visible on this display.
28956 Minibuffer-only frames don't count, but iconified frames do.
28957 This variable is not guaranteed to be accurate except while processing
28958 `frame-title-format' and `icon-title-format'. */);
28960 DEFVAR_LISP ("frame-title-format", Vframe_title_format
,
28961 doc
: /* Template for displaying the title bar of visible frames.
28962 \(Assuming the window manager supports this feature.)
28964 This variable has the same structure as `mode-line-format', except that
28965 the %c and %l constructs are ignored. It is used only on frames for
28966 which no explicit name has been set \(see `modify-frame-parameters'). */);
28968 DEFVAR_LISP ("icon-title-format", Vicon_title_format
,
28969 doc
: /* Template for displaying the title bar of an iconified frame.
28970 \(Assuming the window manager supports this feature.)
28971 This variable has the same structure as `mode-line-format' (which see),
28972 and is used only on frames for which no explicit name has been set
28973 \(see `modify-frame-parameters'). */);
28975 = Vframe_title_format
28976 = listn (CONSTYPE_PURE
, 3,
28977 intern_c_string ("multiple-frames"),
28978 build_pure_c_string ("%b"),
28979 listn (CONSTYPE_PURE
, 4,
28980 empty_unibyte_string
,
28981 intern_c_string ("invocation-name"),
28982 build_pure_c_string ("@"),
28983 intern_c_string ("system-name")));
28985 DEFVAR_LISP ("message-log-max", Vmessage_log_max
,
28986 doc
: /* Maximum number of lines to keep in the message log buffer.
28987 If nil, disable message logging. If t, log messages but don't truncate
28988 the buffer when it becomes large. */);
28989 Vmessage_log_max
= make_number (100);
28991 DEFVAR_LISP ("window-size-change-functions", Vwindow_size_change_functions
,
28992 doc
: /* Functions called before redisplay, if window sizes have changed.
28993 The value should be a list of functions that take one argument.
28994 Just before redisplay, for each frame, if any of its windows have changed
28995 size since the last redisplay, or have been split or deleted,
28996 all the functions in the list are called, with the frame as argument. */);
28997 Vwindow_size_change_functions
= Qnil
;
28999 DEFVAR_LISP ("window-scroll-functions", Vwindow_scroll_functions
,
29000 doc
: /* List of functions to call before redisplaying a window with scrolling.
29001 Each function is called with two arguments, the window and its new
29002 display-start position. Note that these functions are also called by
29003 `set-window-buffer'. Also note that the value of `window-end' is not
29004 valid when these functions are called.
29006 Warning: Do not use this feature to alter the way the window
29007 is scrolled. It is not designed for that, and such use probably won't
29009 Vwindow_scroll_functions
= Qnil
;
29011 DEFVAR_LISP ("window-text-change-functions",
29012 Vwindow_text_change_functions
,
29013 doc
: /* Functions to call in redisplay when text in the window might change. */);
29014 Vwindow_text_change_functions
= Qnil
;
29016 DEFVAR_LISP ("redisplay-end-trigger-functions", Vredisplay_end_trigger_functions
,
29017 doc
: /* Functions called when redisplay of a window reaches the end trigger.
29018 Each function is called with two arguments, the window and the end trigger value.
29019 See `set-window-redisplay-end-trigger'. */);
29020 Vredisplay_end_trigger_functions
= Qnil
;
29022 DEFVAR_LISP ("mouse-autoselect-window", Vmouse_autoselect_window
,
29023 doc
: /* Non-nil means autoselect window with mouse pointer.
29024 If nil, do not autoselect windows.
29025 A positive number means delay autoselection by that many seconds: a
29026 window is autoselected only after the mouse has remained in that
29027 window for the duration of the delay.
29028 A negative number has a similar effect, but causes windows to be
29029 autoselected only after the mouse has stopped moving. \(Because of
29030 the way Emacs compares mouse events, you will occasionally wait twice
29031 that time before the window gets selected.\)
29032 Any other value means to autoselect window instantaneously when the
29033 mouse pointer enters it.
29035 Autoselection selects the minibuffer only if it is active, and never
29036 unselects the minibuffer if it is active.
29038 When customizing this variable make sure that the actual value of
29039 `focus-follows-mouse' matches the behavior of your window manager. */);
29040 Vmouse_autoselect_window
= Qnil
;
29042 DEFVAR_LISP ("auto-resize-tool-bars", Vauto_resize_tool_bars
,
29043 doc
: /* Non-nil means automatically resize tool-bars.
29044 This dynamically changes the tool-bar's height to the minimum height
29045 that is needed to make all tool-bar items visible.
29046 If value is `grow-only', the tool-bar's height is only increased
29047 automatically; to decrease the tool-bar height, use \\[recenter]. */);
29048 Vauto_resize_tool_bars
= Qt
;
29050 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", auto_raise_tool_bar_buttons_p
,
29051 doc
: /* Non-nil means raise tool-bar buttons when the mouse moves over them. */);
29052 auto_raise_tool_bar_buttons_p
= 1;
29054 DEFVAR_BOOL ("make-cursor-line-fully-visible", make_cursor_line_fully_visible_p
,
29055 doc
: /* Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
29056 make_cursor_line_fully_visible_p
= 1;
29058 DEFVAR_LISP ("tool-bar-border", Vtool_bar_border
,
29059 doc
: /* Border below tool-bar in pixels.
29060 If an integer, use it as the height of the border.
29061 If it is one of `internal-border-width' or `border-width', use the
29062 value of the corresponding frame parameter.
29063 Otherwise, no border is added below the tool-bar. */);
29064 Vtool_bar_border
= Qinternal_border_width
;
29066 DEFVAR_LISP ("tool-bar-button-margin", Vtool_bar_button_margin
,
29067 doc
: /* Margin around tool-bar buttons in pixels.
29068 If an integer, use that for both horizontal and vertical margins.
29069 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
29070 HORZ specifying the horizontal margin, and VERT specifying the
29071 vertical margin. */);
29072 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
29074 DEFVAR_INT ("tool-bar-button-relief", tool_bar_button_relief
,
29075 doc
: /* Relief thickness of tool-bar buttons. */);
29076 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
29078 DEFVAR_LISP ("tool-bar-style", Vtool_bar_style
,
29079 doc
: /* Tool bar style to use.
29081 image - show images only
29082 text - show text only
29083 both - show both, text below image
29084 both-horiz - show text to the right of the image
29085 text-image-horiz - show text to the left of the image
29086 any other - use system default or image if no system default.
29088 This variable only affects the GTK+ toolkit version of Emacs. */);
29089 Vtool_bar_style
= Qnil
;
29091 DEFVAR_INT ("tool-bar-max-label-size", tool_bar_max_label_size
,
29092 doc
: /* Maximum number of characters a label can have to be shown.
29093 The tool bar style must also show labels for this to have any effect, see
29094 `tool-bar-style'. */);
29095 tool_bar_max_label_size
= DEFAULT_TOOL_BAR_LABEL_SIZE
;
29097 DEFVAR_LISP ("fontification-functions", Vfontification_functions
,
29098 doc
: /* List of functions to call to fontify regions of text.
29099 Each function is called with one argument POS. Functions must
29100 fontify a region starting at POS in the current buffer, and give
29101 fontified regions the property `fontified'. */);
29102 Vfontification_functions
= Qnil
;
29103 Fmake_variable_buffer_local (Qfontification_functions
);
29105 DEFVAR_BOOL ("unibyte-display-via-language-environment",
29106 unibyte_display_via_language_environment
,
29107 doc
: /* Non-nil means display unibyte text according to language environment.
29108 Specifically, this means that raw bytes in the range 160-255 decimal
29109 are displayed by converting them to the equivalent multibyte characters
29110 according to the current language environment. As a result, they are
29111 displayed according to the current fontset.
29113 Note that this variable affects only how these bytes are displayed,
29114 but does not change the fact they are interpreted as raw bytes. */);
29115 unibyte_display_via_language_environment
= 0;
29117 DEFVAR_LISP ("max-mini-window-height", Vmax_mini_window_height
,
29118 doc
: /* Maximum height for resizing mini-windows (the minibuffer and the echo area).
29119 If a float, it specifies a fraction of the mini-window frame's height.
29120 If an integer, it specifies a number of lines. */);
29121 Vmax_mini_window_height
= make_float (0.25);
29123 DEFVAR_LISP ("resize-mini-windows", Vresize_mini_windows
,
29124 doc
: /* How to resize mini-windows (the minibuffer and the echo area).
29125 A value of nil means don't automatically resize mini-windows.
29126 A value of t means resize them to fit the text displayed in them.
29127 A value of `grow-only', the default, means let mini-windows grow only;
29128 they return to their normal size when the minibuffer is closed, or the
29129 echo area becomes empty. */);
29130 Vresize_mini_windows
= Qgrow_only
;
29132 DEFVAR_LISP ("blink-cursor-alist", Vblink_cursor_alist
,
29133 doc
: /* Alist specifying how to blink the cursor off.
29134 Each element has the form (ON-STATE . OFF-STATE). Whenever the
29135 `cursor-type' frame-parameter or variable equals ON-STATE,
29136 comparing using `equal', Emacs uses OFF-STATE to specify
29137 how to blink it off. ON-STATE and OFF-STATE are values for
29138 the `cursor-type' frame parameter.
29140 If a frame's ON-STATE has no entry in this list,
29141 the frame's other specifications determine how to blink the cursor off. */);
29142 Vblink_cursor_alist
= Qnil
;
29144 DEFVAR_BOOL ("auto-hscroll-mode", automatic_hscrolling_p
,
29145 doc
: /* Allow or disallow automatic horizontal scrolling of windows.
29146 If non-nil, windows are automatically scrolled horizontally to make
29147 point visible. */);
29148 automatic_hscrolling_p
= 1;
29149 DEFSYM (Qauto_hscroll_mode
, "auto-hscroll-mode");
29151 DEFVAR_INT ("hscroll-margin", hscroll_margin
,
29152 doc
: /* How many columns away from the window edge point is allowed to get
29153 before automatic hscrolling will horizontally scroll the window. */);
29154 hscroll_margin
= 5;
29156 DEFVAR_LISP ("hscroll-step", Vhscroll_step
,
29157 doc
: /* How many columns to scroll the window when point gets too close to the edge.
29158 When point is less than `hscroll-margin' columns from the window
29159 edge, automatic hscrolling will scroll the window by the amount of columns
29160 determined by this variable. If its value is a positive integer, scroll that
29161 many columns. If it's a positive floating-point number, it specifies the
29162 fraction of the window's width to scroll. If it's nil or zero, point will be
29163 centered horizontally after the scroll. Any other value, including negative
29164 numbers, are treated as if the value were zero.
29166 Automatic hscrolling always moves point outside the scroll margin, so if
29167 point was more than scroll step columns inside the margin, the window will
29168 scroll more than the value given by the scroll step.
29170 Note that the lower bound for automatic hscrolling specified by `scroll-left'
29171 and `scroll-right' overrides this variable's effect. */);
29172 Vhscroll_step
= make_number (0);
29174 DEFVAR_BOOL ("message-truncate-lines", message_truncate_lines
,
29175 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
29176 Bind this around calls to `message' to let it take effect. */);
29177 message_truncate_lines
= 0;
29179 DEFVAR_LISP ("menu-bar-update-hook", Vmenu_bar_update_hook
,
29180 doc
: /* Normal hook run to update the menu bar definitions.
29181 Redisplay runs this hook before it redisplays the menu bar.
29182 This is used to update submenus such as Buffers,
29183 whose contents depend on various data. */);
29184 Vmenu_bar_update_hook
= Qnil
;
29186 DEFVAR_LISP ("menu-updating-frame", Vmenu_updating_frame
,
29187 doc
: /* Frame for which we are updating a menu.
29188 The enable predicate for a menu binding should check this variable. */);
29189 Vmenu_updating_frame
= Qnil
;
29191 DEFVAR_BOOL ("inhibit-menubar-update", inhibit_menubar_update
,
29192 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
29193 inhibit_menubar_update
= 0;
29195 DEFVAR_LISP ("wrap-prefix", Vwrap_prefix
,
29196 doc
: /* Prefix prepended to all continuation lines at display time.
29197 The value may be a string, an image, or a stretch-glyph; it is
29198 interpreted in the same way as the value of a `display' text property.
29200 This variable is overridden by any `wrap-prefix' text or overlay
29203 To add a prefix to non-continuation lines, use `line-prefix'. */);
29204 Vwrap_prefix
= Qnil
;
29205 DEFSYM (Qwrap_prefix
, "wrap-prefix");
29206 Fmake_variable_buffer_local (Qwrap_prefix
);
29208 DEFVAR_LISP ("line-prefix", Vline_prefix
,
29209 doc
: /* Prefix prepended to all non-continuation lines at display time.
29210 The value may be a string, an image, or a stretch-glyph; it is
29211 interpreted in the same way as the value of a `display' text property.
29213 This variable is overridden by any `line-prefix' text or overlay
29216 To add a prefix to continuation lines, use `wrap-prefix'. */);
29217 Vline_prefix
= Qnil
;
29218 DEFSYM (Qline_prefix
, "line-prefix");
29219 Fmake_variable_buffer_local (Qline_prefix
);
29221 DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay
,
29222 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
29223 inhibit_eval_during_redisplay
= 0;
29225 DEFVAR_BOOL ("inhibit-free-realized-faces", inhibit_free_realized_faces
,
29226 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
29227 inhibit_free_realized_faces
= 0;
29230 DEFVAR_BOOL ("inhibit-try-window-id", inhibit_try_window_id
,
29231 doc
: /* Inhibit try_window_id display optimization. */);
29232 inhibit_try_window_id
= 0;
29234 DEFVAR_BOOL ("inhibit-try-window-reusing", inhibit_try_window_reusing
,
29235 doc
: /* Inhibit try_window_reusing display optimization. */);
29236 inhibit_try_window_reusing
= 0;
29238 DEFVAR_BOOL ("inhibit-try-cursor-movement", inhibit_try_cursor_movement
,
29239 doc
: /* Inhibit try_cursor_movement display optimization. */);
29240 inhibit_try_cursor_movement
= 0;
29241 #endif /* GLYPH_DEBUG */
29243 DEFVAR_INT ("overline-margin", overline_margin
,
29244 doc
: /* Space between overline and text, in pixels.
29245 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
29246 margin to the character height. */);
29247 overline_margin
= 2;
29249 DEFVAR_INT ("underline-minimum-offset",
29250 underline_minimum_offset
,
29251 doc
: /* Minimum distance between baseline and underline.
29252 This can improve legibility of underlined text at small font sizes,
29253 particularly when using variable `x-use-underline-position-properties'
29254 with fonts that specify an UNDERLINE_POSITION relatively close to the
29255 baseline. The default value is 1. */);
29256 underline_minimum_offset
= 1;
29258 DEFVAR_BOOL ("display-hourglass", display_hourglass_p
,
29259 doc
: /* Non-nil means show an hourglass pointer, when Emacs is busy.
29260 This feature only works when on a window system that can change
29261 cursor shapes. */);
29262 display_hourglass_p
= 1;
29264 DEFVAR_LISP ("hourglass-delay", Vhourglass_delay
,
29265 doc
: /* Seconds to wait before displaying an hourglass pointer when Emacs is busy. */);
29266 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
29268 hourglass_atimer
= NULL
;
29269 hourglass_shown_p
= 0;
29271 DEFSYM (Qglyphless_char
, "glyphless-char");
29272 DEFSYM (Qhex_code
, "hex-code");
29273 DEFSYM (Qempty_box
, "empty-box");
29274 DEFSYM (Qthin_space
, "thin-space");
29275 DEFSYM (Qzero_width
, "zero-width");
29277 DEFSYM (Qglyphless_char_display
, "glyphless-char-display");
29278 /* Intern this now in case it isn't already done.
29279 Setting this variable twice is harmless.
29280 But don't staticpro it here--that is done in alloc.c. */
29281 Qchar_table_extra_slots
= intern_c_string ("char-table-extra-slots");
29282 Fput (Qglyphless_char_display
, Qchar_table_extra_slots
, make_number (1));
29284 DEFVAR_LISP ("glyphless-char-display", Vglyphless_char_display
,
29285 doc
: /* Char-table defining glyphless characters.
29286 Each element, if non-nil, should be one of the following:
29287 an ASCII acronym string: display this string in a box
29288 `hex-code': display the hexadecimal code of a character in a box
29289 `empty-box': display as an empty box
29290 `thin-space': display as 1-pixel width space
29291 `zero-width': don't display
29292 An element may also be a cons cell (GRAPHICAL . TEXT), which specifies the
29293 display method for graphical terminals and text terminals respectively.
29294 GRAPHICAL and TEXT should each have one of the values listed above.
29296 The char-table has one extra slot to control the display of a character for
29297 which no font is found. This slot only takes effect on graphical terminals.
29298 Its value should be an ASCII acronym string, `hex-code', `empty-box', or
29299 `thin-space'. The default is `empty-box'. */);
29300 Vglyphless_char_display
= Fmake_char_table (Qglyphless_char_display
, Qnil
);
29301 Fset_char_table_extra_slot (Vglyphless_char_display
, make_number (0),
29304 DEFVAR_LISP ("debug-on-message", Vdebug_on_message
,
29305 doc
: /* If non-nil, debug if a message matching this regexp is displayed. */);
29306 Vdebug_on_message
= Qnil
;
29310 /* Initialize this module when Emacs starts. */
29315 current_header_line_height
= current_mode_line_height
= -1;
29317 CHARPOS (this_line_start_pos
) = 0;
29319 if (!noninteractive
)
29321 struct window
*m
= XWINDOW (minibuf_window
);
29322 Lisp_Object frame
= m
->frame
;
29323 struct frame
*f
= XFRAME (frame
);
29324 Lisp_Object root
= FRAME_ROOT_WINDOW (f
);
29325 struct window
*r
= XWINDOW (root
);
29328 echo_area_window
= minibuf_window
;
29330 wset_top_line (r
, make_number (FRAME_TOP_MARGIN (f
)));
29332 (r
, make_number (FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
)));
29333 wset_total_cols (r
, make_number (FRAME_COLS (f
)));
29334 wset_top_line (m
, make_number (FRAME_LINES (f
) - 1));
29335 wset_total_lines (m
, make_number (1));
29336 wset_total_cols (m
, make_number (FRAME_COLS (f
)));
29338 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
29339 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
29340 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
29342 /* The default ellipsis glyphs `...'. */
29343 for (i
= 0; i
< 3; ++i
)
29344 default_invis_vector
[i
] = make_number ('.');
29348 /* Allocate the buffer for frame titles.
29349 Also used for `format-mode-line'. */
29351 mode_line_noprop_buf
= xmalloc (size
);
29352 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
29353 mode_line_noprop_ptr
= mode_line_noprop_buf
;
29354 mode_line_target
= MODE_LINE_DISPLAY
;
29357 help_echo_showing_p
= 0;
29360 /* Since w32 does not support atimers, it defines its own implementation of
29361 the following three functions in w32fns.c. */
29364 /* Platform-independent portion of hourglass implementation. */
29366 /* Cancel a currently active hourglass timer, and start a new one. */
29368 start_hourglass (void)
29370 #if defined (HAVE_WINDOW_SYSTEM)
29373 cancel_hourglass ();
29375 if (INTEGERP (Vhourglass_delay
)
29376 && XINT (Vhourglass_delay
) > 0)
29377 delay
= make_emacs_time (min (XINT (Vhourglass_delay
),
29378 TYPE_MAXIMUM (time_t)),
29380 else if (FLOATP (Vhourglass_delay
)
29381 && XFLOAT_DATA (Vhourglass_delay
) > 0)
29382 delay
= EMACS_TIME_FROM_DOUBLE (XFLOAT_DATA (Vhourglass_delay
));
29384 delay
= make_emacs_time (DEFAULT_HOURGLASS_DELAY
, 0);
29386 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
29387 show_hourglass
, NULL
);
29392 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
29395 cancel_hourglass (void)
29397 #if defined (HAVE_WINDOW_SYSTEM)
29398 if (hourglass_atimer
)
29400 cancel_atimer (hourglass_atimer
);
29401 hourglass_atimer
= NULL
;
29404 if (hourglass_shown_p
)
29408 #endif /* ! WINDOWSNT */