1 /* Display generation from window structure and buffer text.
3 Copyright (C) 1985-1988, 1993-1995, 1997-2013 Free Software Foundation,
6 This file is part of GNU Emacs.
8 GNU Emacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
21 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
25 Emacs separates the task of updating the display from code
26 modifying global state, e.g. buffer text. This way functions
27 operating on buffers don't also have to be concerned with updating
30 Updating the display is triggered by the Lisp interpreter when it
31 decides it's time to do it. This is done either automatically for
32 you as part of the interpreter's command loop or as the result of
33 calling Lisp functions like `sit-for'. The C function `redisplay'
34 in xdisp.c is the only entry into the inner redisplay code.
36 The following diagram shows how redisplay code is invoked. As you
37 can see, Lisp calls redisplay and vice versa. Under window systems
38 like X, some portions of the redisplay code are also called
39 asynchronously during mouse movement or expose events. It is very
40 important that these code parts do NOT use the C library (malloc,
41 free) because many C libraries under Unix are not reentrant. They
42 may also NOT call functions of the Lisp interpreter which could
43 change the interpreter's state. If you don't follow these rules,
44 you will encounter bugs which are very hard to explain.
46 +--------------+ redisplay +----------------+
47 | Lisp machine |---------------->| Redisplay code |<--+
48 +--------------+ (xdisp.c) +----------------+ |
50 +----------------------------------+ |
51 Don't use this path when called |
54 expose_window (asynchronous) |
56 X expose events -----+
58 What does redisplay do? Obviously, it has to figure out somehow what
59 has been changed since the last time the display has been updated,
60 and to make these changes visible. Preferably it would do that in
61 a moderately intelligent way, i.e. fast.
63 Changes in buffer text can be deduced from window and buffer
64 structures, and from some global variables like `beg_unchanged' and
65 `end_unchanged'. The contents of the display are additionally
66 recorded in a `glyph matrix', a two-dimensional matrix of glyph
67 structures. Each row in such a matrix corresponds to a line on the
68 display, and each glyph in a row corresponds to a column displaying
69 a character, an image, or what else. This matrix is called the
70 `current glyph matrix' or `current matrix' in redisplay
73 For buffer parts that have been changed since the last update, a
74 second glyph matrix is constructed, the so called `desired glyph
75 matrix' or short `desired matrix'. Current and desired matrix are
76 then compared to find a cheap way to update the display, e.g. by
77 reusing part of the display by scrolling lines.
79 You will find a lot of redisplay optimizations when you start
80 looking at the innards of redisplay. The overall goal of all these
81 optimizations is to make redisplay fast because it is done
82 frequently. Some of these optimizations are implemented by the
87 This function tries to update the display if the text in the
88 window did not change and did not scroll, only point moved, and
89 it did not move off the displayed portion of the text.
91 . try_window_reusing_current_matrix
93 This function reuses the current matrix of a window when text
94 has not changed, but the window start changed (e.g., due to
99 This function attempts to redisplay a window by reusing parts of
100 its existing display. It finds and reuses the part that was not
101 changed, and redraws the rest.
105 This function performs the full redisplay of a single window
106 assuming that its fonts were not changed and that the cursor
107 will not end up in the scroll margins. (Loading fonts requires
108 re-adjustment of dimensions of glyph matrices, which makes this
109 method impossible to use.)
111 These optimizations are tried in sequence (some can be skipped if
112 it is known that they are not applicable). If none of the
113 optimizations were successful, redisplay calls redisplay_windows,
114 which performs a full redisplay of all windows.
118 Desired matrices are always built per Emacs window. The function
119 `display_line' is the central function to look at if you are
120 interested. It constructs one row in a desired matrix given an
121 iterator structure containing both a buffer position and a
122 description of the environment in which the text is to be
123 displayed. But this is too early, read on.
125 Characters and pixmaps displayed for a range of buffer text depend
126 on various settings of buffers and windows, on overlays and text
127 properties, on display tables, on selective display. The good news
128 is that all this hairy stuff is hidden behind a small set of
129 interface functions taking an iterator structure (struct it)
132 Iteration over things to be displayed is then simple. It is
133 started by initializing an iterator with a call to init_iterator,
134 passing it the buffer position where to start iteration. For
135 iteration over strings, pass -1 as the position to init_iterator,
136 and call reseat_to_string when the string is ready, to initialize
137 the iterator for that string. Thereafter, calls to
138 get_next_display_element fill the iterator structure with relevant
139 information about the next thing to display. Calls to
140 set_iterator_to_next move the iterator to the next thing.
142 Besides this, an iterator also contains information about the
143 display environment in which glyphs for display elements are to be
144 produced. It has fields for the width and height of the display,
145 the information whether long lines are truncated or continued, a
146 current X and Y position, and lots of other stuff you can better
149 Glyphs in a desired matrix are normally constructed in a loop
150 calling get_next_display_element and then PRODUCE_GLYPHS. The call
151 to PRODUCE_GLYPHS will fill the iterator structure with pixel
152 information about the element being displayed and at the same time
153 produce glyphs for it. If the display element fits on the line
154 being displayed, set_iterator_to_next is called next, otherwise the
155 glyphs produced are discarded. The function display_line is the
156 workhorse of filling glyph rows in the desired matrix with glyphs.
157 In addition to producing glyphs, it also handles line truncation
158 and continuation, word wrap, and cursor positioning (for the
159 latter, see also set_cursor_from_row).
163 That just couldn't be all, could it? What about terminal types not
164 supporting operations on sub-windows of the screen? To update the
165 display on such a terminal, window-based glyph matrices are not
166 well suited. To be able to reuse part of the display (scrolling
167 lines up and down), we must instead have a view of the whole
168 screen. This is what `frame matrices' are for. They are a trick.
170 Frames on terminals like above have a glyph pool. Windows on such
171 a frame sub-allocate their glyph memory from their frame's glyph
172 pool. The frame itself is given its own glyph matrices. By
173 coincidence---or maybe something else---rows in window glyph
174 matrices are slices of corresponding rows in frame matrices. Thus
175 writing to window matrices implicitly updates a frame matrix which
176 provides us with the view of the whole screen that we originally
177 wanted to have without having to move many bytes around. To be
178 honest, there is a little bit more done, but not much more. If you
179 plan to extend that code, take a look at dispnew.c. The function
180 build_frame_matrix is a good starting point.
182 Bidirectional display.
184 Bidirectional display adds quite some hair to this already complex
185 design. The good news are that a large portion of that hairy stuff
186 is hidden in bidi.c behind only 3 interfaces. bidi.c implements a
187 reordering engine which is called by set_iterator_to_next and
188 returns the next character to display in the visual order. See
189 commentary on bidi.c for more details. As far as redisplay is
190 concerned, the effect of calling bidi_move_to_visually_next, the
191 main interface of the reordering engine, is that the iterator gets
192 magically placed on the buffer or string position that is to be
193 displayed next. In other words, a linear iteration through the
194 buffer/string is replaced with a non-linear one. All the rest of
195 the redisplay is oblivious to the bidi reordering.
197 Well, almost oblivious---there are still complications, most of
198 them due to the fact that buffer and string positions no longer
199 change monotonously with glyph indices in a glyph row. Moreover,
200 for continued lines, the buffer positions may not even be
201 monotonously changing with vertical positions. Also, accounting
202 for face changes, overlays, etc. becomes more complex because
203 non-linear iteration could potentially skip many positions with
204 changes, and then cross them again on the way back...
206 One other prominent effect of bidirectional display is that some
207 paragraphs of text need to be displayed starting at the right
208 margin of the window---the so-called right-to-left, or R2L
209 paragraphs. R2L paragraphs are displayed with R2L glyph rows,
210 which have their reversed_p flag set. The bidi reordering engine
211 produces characters in such rows starting from the character which
212 should be the rightmost on display. PRODUCE_GLYPHS then reverses
213 the order, when it fills up the glyph row whose reversed_p flag is
214 set, by prepending each new glyph to what is already there, instead
215 of appending it. When the glyph row is complete, the function
216 extend_face_to_end_of_line fills the empty space to the left of the
217 leftmost character with special glyphs, which will display as,
218 well, empty. On text terminals, these special glyphs are simply
219 blank characters. On graphics terminals, there's a single stretch
220 glyph of a suitably computed width. Both the blanks and the
221 stretch glyph are given the face of the background of the line.
222 This way, the terminal-specific back-end can still draw the glyphs
223 left to right, even for R2L lines.
225 Bidirectional display and character compositions
227 Some scripts cannot be displayed by drawing each character
228 individually, because adjacent characters change each other's shape
229 on display. For example, Arabic and Indic scripts belong to this
232 Emacs display supports this by providing "character compositions",
233 most of which is implemented in composite.c. During the buffer
234 scan that delivers characters to PRODUCE_GLYPHS, if the next
235 character to be delivered is a composed character, the iteration
236 calls composition_reseat_it and next_element_from_composition. If
237 they succeed to compose the character with one or more of the
238 following characters, the whole sequence of characters that where
239 composed is recorded in the `struct composition_it' object that is
240 part of the buffer iterator. The composed sequence could produce
241 one or more font glyphs (called "grapheme clusters") on the screen.
242 Each of these grapheme clusters is then delivered to PRODUCE_GLYPHS
243 in the direction corresponding to the current bidi scan direction
244 (recorded in the scan_dir member of the `struct bidi_it' object
245 that is part of the buffer iterator). In particular, if the bidi
246 iterator currently scans the buffer backwards, the grapheme
247 clusters are delivered back to front. This reorders the grapheme
248 clusters as appropriate for the current bidi context. Note that
249 this means that the grapheme clusters are always stored in the
250 LGSTRING object (see composite.c) in the logical order.
252 Moving an iterator in bidirectional text
253 without producing glyphs
255 Note one important detail mentioned above: that the bidi reordering
256 engine, driven by the iterator, produces characters in R2L rows
257 starting at the character that will be the rightmost on display.
258 As far as the iterator is concerned, the geometry of such rows is
259 still left to right, i.e. the iterator "thinks" the first character
260 is at the leftmost pixel position. The iterator does not know that
261 PRODUCE_GLYPHS reverses the order of the glyphs that the iterator
262 delivers. This is important when functions from the move_it_*
263 family are used to get to certain screen position or to match
264 screen coordinates with buffer coordinates: these functions use the
265 iterator geometry, which is left to right even in R2L paragraphs.
266 This works well with most callers of move_it_*, because they need
267 to get to a specific column, and columns are still numbered in the
268 reading order, i.e. the rightmost character in a R2L paragraph is
269 still column zero. But some callers do not get well with this; a
270 notable example is mouse clicks that need to find the character
271 that corresponds to certain pixel coordinates. See
272 buffer_posn_from_coords in dispnew.c for how this is handled. */
280 #include "keyboard.h"
283 #include "termchar.h"
284 #include "dispextern.h"
285 #include "character.h"
289 #include "commands.h"
293 #include "termhooks.h"
294 #include "termopts.h"
295 #include "intervals.h"
298 #include "region-cache.h"
301 #include "blockinput.h"
303 #ifdef HAVE_X_WINDOWS
318 #ifndef FRAME_X_OUTPUT
319 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
322 #define INFINITY 10000000
324 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
325 Lisp_Object Qwindow_scroll_functions
;
326 static Lisp_Object Qwindow_text_change_functions
;
327 static Lisp_Object Qredisplay_end_trigger_functions
;
328 Lisp_Object Qinhibit_point_motion_hooks
;
329 static Lisp_Object QCeval
, QCpropertize
;
330 Lisp_Object QCfile
, QCdata
;
331 static Lisp_Object Qfontified
;
332 static Lisp_Object Qgrow_only
;
333 static Lisp_Object Qinhibit_eval_during_redisplay
;
334 static Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
335 static Lisp_Object Qright_to_left
, Qleft_to_right
;
338 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
340 /* Pointer shapes. */
341 static Lisp_Object Qarrow
, Qhand
;
344 /* Holds the list (error). */
345 static Lisp_Object list_of_error
;
347 static Lisp_Object Qfontification_functions
;
349 static Lisp_Object Qwrap_prefix
;
350 static Lisp_Object Qline_prefix
;
351 static Lisp_Object Qredisplay_internal
;
353 /* Non-nil means don't actually do any redisplay. */
355 Lisp_Object Qinhibit_redisplay
;
357 /* Names of text properties relevant for redisplay. */
359 Lisp_Object Qdisplay
;
361 Lisp_Object Qspace
, QCalign_to
;
362 static Lisp_Object QCrelative_width
, QCrelative_height
;
363 Lisp_Object Qleft_margin
, Qright_margin
;
364 static Lisp_Object Qspace_width
, Qraise
;
365 static Lisp_Object Qslice
;
367 static Lisp_Object Qmargin
, Qpointer
;
368 static Lisp_Object Qline_height
;
370 #ifdef HAVE_WINDOW_SYSTEM
372 /* Test if overflow newline into fringe. Called with iterator IT
373 at or past right window margin, and with IT->current_x set. */
375 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(IT) \
376 (!NILP (Voverflow_newline_into_fringe) \
377 && FRAME_WINDOW_P ((IT)->f) \
378 && ((IT)->bidi_it.paragraph_dir == R2L \
379 ? (WINDOW_LEFT_FRINGE_WIDTH ((IT)->w) > 0) \
380 : (WINDOW_RIGHT_FRINGE_WIDTH ((IT)->w) > 0)) \
381 && (IT)->current_x == (IT)->last_visible_x \
382 && (IT)->line_wrap != WORD_WRAP)
384 #else /* !HAVE_WINDOW_SYSTEM */
385 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) 0
386 #endif /* HAVE_WINDOW_SYSTEM */
388 /* Test if the display element loaded in IT, or the underlying buffer
389 or string character, is a space or a TAB character. This is used
390 to determine where word wrapping can occur. */
392 #define IT_DISPLAYING_WHITESPACE(it) \
393 ((it->what == IT_CHARACTER && (it->c == ' ' || it->c == '\t')) \
394 || ((STRINGP (it->string) \
395 && (SREF (it->string, IT_STRING_BYTEPOS (*it)) == ' ' \
396 || SREF (it->string, IT_STRING_BYTEPOS (*it)) == '\t')) \
398 && (it->s[IT_BYTEPOS (*it)] == ' ' \
399 || it->s[IT_BYTEPOS (*it)] == '\t')) \
400 || (IT_BYTEPOS (*it) < ZV_BYTE \
401 && (*BYTE_POS_ADDR (IT_BYTEPOS (*it)) == ' ' \
402 || *BYTE_POS_ADDR (IT_BYTEPOS (*it)) == '\t')))) \
404 /* Name of the face used to highlight trailing whitespace. */
406 static Lisp_Object Qtrailing_whitespace
;
408 /* Name and number of the face used to highlight escape glyphs. */
410 static Lisp_Object Qescape_glyph
;
412 /* Name and number of the face used to highlight non-breaking spaces. */
414 static Lisp_Object Qnobreak_space
;
416 /* The symbol `image' which is the car of the lists used to represent
417 images in Lisp. Also a tool bar style. */
421 /* The image map types. */
423 static Lisp_Object QCpointer
;
424 static Lisp_Object Qrect
, Qcircle
, Qpoly
;
426 /* Tool bar styles */
427 Lisp_Object Qboth
, Qboth_horiz
, Qtext_image_horiz
;
429 /* Non-zero means print newline to stdout before next mini-buffer
432 int noninteractive_need_newline
;
434 /* Non-zero means print newline to message log before next message. */
436 static int message_log_need_newline
;
438 /* Three markers that message_dolog uses.
439 It could allocate them itself, but that causes trouble
440 in handling memory-full errors. */
441 static Lisp_Object message_dolog_marker1
;
442 static Lisp_Object message_dolog_marker2
;
443 static Lisp_Object message_dolog_marker3
;
445 /* The buffer position of the first character appearing entirely or
446 partially on the line of the selected window which contains the
447 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
448 redisplay optimization in redisplay_internal. */
450 static struct text_pos this_line_start_pos
;
452 /* Number of characters past the end of the line above, including the
453 terminating newline. */
455 static struct text_pos this_line_end_pos
;
457 /* The vertical positions and the height of this line. */
459 static int this_line_vpos
;
460 static int this_line_y
;
461 static int this_line_pixel_height
;
463 /* X position at which this display line starts. Usually zero;
464 negative if first character is partially visible. */
466 static int this_line_start_x
;
468 /* The smallest character position seen by move_it_* functions as they
469 move across display lines. Used to set MATRIX_ROW_START_CHARPOS of
470 hscrolled lines, see display_line. */
472 static struct text_pos this_line_min_pos
;
474 /* Buffer that this_line_.* variables are referring to. */
476 static struct buffer
*this_line_buffer
;
479 /* Values of those variables at last redisplay are stored as
480 properties on `overlay-arrow-position' symbol. However, if
481 Voverlay_arrow_position is a marker, last-arrow-position is its
482 numerical position. */
484 static Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
486 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
487 properties on a symbol in overlay-arrow-variable-list. */
489 static Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
491 Lisp_Object Qmenu_bar_update_hook
;
493 /* Nonzero if an overlay arrow has been displayed in this window. */
495 static int overlay_arrow_seen
;
497 /* Vector containing glyphs for an ellipsis `...'. */
499 static Lisp_Object default_invis_vector
[3];
501 /* This is the window where the echo area message was displayed. It
502 is always a mini-buffer window, but it may not be the same window
503 currently active as a mini-buffer. */
505 Lisp_Object echo_area_window
;
507 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
508 pushes the current message and the value of
509 message_enable_multibyte on the stack, the function restore_message
510 pops the stack and displays MESSAGE again. */
512 static Lisp_Object Vmessage_stack
;
514 /* Nonzero means multibyte characters were enabled when the echo area
515 message was specified. */
517 static int message_enable_multibyte
;
519 /* Nonzero if we should redraw the mode lines on the next redisplay. */
521 int update_mode_lines
;
523 /* Nonzero if window sizes or contents have changed since last
524 redisplay that finished. */
526 int windows_or_buffers_changed
;
528 /* Nonzero means a frame's cursor type has been changed. */
530 int cursor_type_changed
;
532 /* Nonzero after display_mode_line if %l was used and it displayed a
535 static int line_number_displayed
;
537 /* The name of the *Messages* buffer, a string. */
539 static Lisp_Object Vmessages_buffer_name
;
541 /* Current, index 0, and last displayed echo area message. Either
542 buffers from echo_buffers, or nil to indicate no message. */
544 Lisp_Object echo_area_buffer
[2];
546 /* The buffers referenced from echo_area_buffer. */
548 static Lisp_Object echo_buffer
[2];
550 /* A vector saved used in with_area_buffer to reduce consing. */
552 static Lisp_Object Vwith_echo_area_save_vector
;
554 /* Non-zero means display_echo_area should display the last echo area
555 message again. Set by redisplay_preserve_echo_area. */
557 static int display_last_displayed_message_p
;
559 /* Nonzero if echo area is being used by print; zero if being used by
562 static int message_buf_print
;
564 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
566 static Lisp_Object Qinhibit_menubar_update
;
567 static Lisp_Object Qmessage_truncate_lines
;
569 /* Set to 1 in clear_message to make redisplay_internal aware
570 of an emptied echo area. */
572 static int message_cleared_p
;
574 /* A scratch glyph row with contents used for generating truncation
575 glyphs. Also used in direct_output_for_insert. */
577 #define MAX_SCRATCH_GLYPHS 100
578 static struct glyph_row scratch_glyph_row
;
579 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
581 /* Ascent and height of the last line processed by move_it_to. */
583 static int last_max_ascent
, last_height
;
585 /* Non-zero if there's a help-echo in the echo area. */
587 int help_echo_showing_p
;
589 /* If >= 0, computed, exact values of mode-line and header-line height
590 to use in the macros CURRENT_MODE_LINE_HEIGHT and
591 CURRENT_HEADER_LINE_HEIGHT. */
593 int current_mode_line_height
, current_header_line_height
;
595 /* The maximum distance to look ahead for text properties. Values
596 that are too small let us call compute_char_face and similar
597 functions too often which is expensive. Values that are too large
598 let us call compute_char_face and alike too often because we
599 might not be interested in text properties that far away. */
601 #define TEXT_PROP_DISTANCE_LIMIT 100
603 /* SAVE_IT and RESTORE_IT are called when we save a snapshot of the
604 iterator state and later restore it. This is needed because the
605 bidi iterator on bidi.c keeps a stacked cache of its states, which
606 is really a singleton. When we use scratch iterator objects to
607 move around the buffer, we can cause the bidi cache to be pushed or
608 popped, and therefore we need to restore the cache state when we
609 return to the original iterator. */
610 #define SAVE_IT(ITCOPY,ITORIG,CACHE) \
613 bidi_unshelve_cache (CACHE, 1); \
615 CACHE = bidi_shelve_cache (); \
618 #define RESTORE_IT(pITORIG,pITCOPY,CACHE) \
620 if (pITORIG != pITCOPY) \
621 *(pITORIG) = *(pITCOPY); \
622 bidi_unshelve_cache (CACHE, 0); \
628 /* Non-zero means print traces of redisplay if compiled with
629 GLYPH_DEBUG defined. */
631 int trace_redisplay_p
;
633 #endif /* GLYPH_DEBUG */
635 #ifdef DEBUG_TRACE_MOVE
636 /* Non-zero means trace with TRACE_MOVE to stderr. */
639 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
641 #define TRACE_MOVE(x) (void) 0
644 static Lisp_Object Qauto_hscroll_mode
;
646 /* Buffer being redisplayed -- for redisplay_window_error. */
648 static struct buffer
*displayed_buffer
;
650 /* Value returned from text property handlers (see below). */
655 HANDLED_RECOMPUTE_PROPS
,
656 HANDLED_OVERLAY_STRING_CONSUMED
,
660 /* A description of text properties that redisplay is interested
665 /* The name of the property. */
668 /* A unique index for the property. */
671 /* A handler function called to set up iterator IT from the property
672 at IT's current position. Value is used to steer handle_stop. */
673 enum prop_handled (*handler
) (struct it
*it
);
676 static enum prop_handled
handle_face_prop (struct it
*);
677 static enum prop_handled
handle_invisible_prop (struct it
*);
678 static enum prop_handled
handle_display_prop (struct it
*);
679 static enum prop_handled
handle_composition_prop (struct it
*);
680 static enum prop_handled
handle_overlay_change (struct it
*);
681 static enum prop_handled
handle_fontified_prop (struct it
*);
683 /* Properties handled by iterators. */
685 static struct props it_props
[] =
687 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
688 /* Handle `face' before `display' because some sub-properties of
689 `display' need to know the face. */
690 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
691 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
692 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
693 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
697 /* Value is the position described by X. If X is a marker, value is
698 the marker_position of X. Otherwise, value is X. */
700 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
702 /* Enumeration returned by some move_it_.* functions internally. */
706 /* Not used. Undefined value. */
709 /* Move ended at the requested buffer position or ZV. */
710 MOVE_POS_MATCH_OR_ZV
,
712 /* Move ended at the requested X pixel position. */
715 /* Move within a line ended at the end of a line that must be
719 /* Move within a line ended at the end of a line that would
720 be displayed truncated. */
723 /* Move within a line ended at a line end. */
727 /* This counter is used to clear the face cache every once in a while
728 in redisplay_internal. It is incremented for each redisplay.
729 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
732 #define CLEAR_FACE_CACHE_COUNT 500
733 static int clear_face_cache_count
;
735 /* Similarly for the image cache. */
737 #ifdef HAVE_WINDOW_SYSTEM
738 #define CLEAR_IMAGE_CACHE_COUNT 101
739 static int clear_image_cache_count
;
741 /* Null glyph slice */
742 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
745 /* True while redisplay_internal is in progress. */
749 static Lisp_Object Qinhibit_free_realized_faces
;
750 static Lisp_Object Qmode_line_default_help_echo
;
752 /* If a string, XTread_socket generates an event to display that string.
753 (The display is done in read_char.) */
755 Lisp_Object help_echo_string
;
756 Lisp_Object help_echo_window
;
757 Lisp_Object help_echo_object
;
758 ptrdiff_t help_echo_pos
;
760 /* Temporary variable for XTread_socket. */
762 Lisp_Object previous_help_echo_string
;
764 /* Platform-independent portion of hourglass implementation. */
766 /* Non-zero means an hourglass cursor is currently shown. */
767 int hourglass_shown_p
;
769 /* If non-null, an asynchronous timer that, when it expires, displays
770 an hourglass cursor on all frames. */
771 struct atimer
*hourglass_atimer
;
773 /* Name of the face used to display glyphless characters. */
774 Lisp_Object Qglyphless_char
;
776 /* Symbol for the purpose of Vglyphless_char_display. */
777 static Lisp_Object Qglyphless_char_display
;
779 /* Method symbols for Vglyphless_char_display. */
780 static Lisp_Object Qhex_code
, Qempty_box
, Qthin_space
, Qzero_width
;
782 /* Default pixel width of `thin-space' display method. */
783 #define THIN_SPACE_WIDTH 1
785 /* Default number of seconds to wait before displaying an hourglass
787 #define DEFAULT_HOURGLASS_DELAY 1
790 /* Function prototypes. */
792 static void setup_for_ellipsis (struct it
*, int);
793 static void set_iterator_to_next (struct it
*, int);
794 static void mark_window_display_accurate_1 (struct window
*, int);
795 static int single_display_spec_string_p (Lisp_Object
, Lisp_Object
);
796 static int display_prop_string_p (Lisp_Object
, Lisp_Object
);
797 static int cursor_row_p (struct glyph_row
*);
798 static int redisplay_mode_lines (Lisp_Object
, int);
799 static char *decode_mode_spec_coding (Lisp_Object
, char *, int);
801 static Lisp_Object
get_it_property (struct it
*it
, Lisp_Object prop
);
803 static void handle_line_prefix (struct it
*);
805 static void pint2str (char *, int, ptrdiff_t);
806 static void pint2hrstr (char *, int, ptrdiff_t);
807 static struct text_pos
run_window_scroll_functions (Lisp_Object
,
809 static void reconsider_clip_changes (struct window
*, struct buffer
*);
810 static int text_outside_line_unchanged_p (struct window
*,
811 ptrdiff_t, ptrdiff_t);
812 static void store_mode_line_noprop_char (char);
813 static int store_mode_line_noprop (const char *, int, int);
814 static void handle_stop (struct it
*);
815 static void handle_stop_backwards (struct it
*, ptrdiff_t);
816 static void vmessage (const char *, va_list) ATTRIBUTE_FORMAT_PRINTF (1, 0);
817 static void ensure_echo_area_buffers (void);
818 static Lisp_Object
unwind_with_echo_area_buffer (Lisp_Object
);
819 static Lisp_Object
with_echo_area_buffer_unwind_data (struct window
*);
820 static int with_echo_area_buffer (struct window
*, int,
821 int (*) (ptrdiff_t, Lisp_Object
),
822 ptrdiff_t, Lisp_Object
);
823 static void clear_garbaged_frames (void);
824 static int current_message_1 (ptrdiff_t, Lisp_Object
);
825 static void pop_message (void);
826 static int truncate_message_1 (ptrdiff_t, Lisp_Object
);
827 static void set_message (Lisp_Object
);
828 static int set_message_1 (ptrdiff_t, Lisp_Object
);
829 static int display_echo_area (struct window
*);
830 static int display_echo_area_1 (ptrdiff_t, Lisp_Object
);
831 static int resize_mini_window_1 (ptrdiff_t, Lisp_Object
);
832 static Lisp_Object
unwind_redisplay (Lisp_Object
);
833 static int string_char_and_length (const unsigned char *, int *);
834 static struct text_pos
display_prop_end (struct it
*, Lisp_Object
,
836 static int compute_window_start_on_continuation_line (struct window
*);
837 static void insert_left_trunc_glyphs (struct it
*);
838 static struct glyph_row
*get_overlay_arrow_glyph_row (struct window
*,
840 static void extend_face_to_end_of_line (struct it
*);
841 static int append_space_for_newline (struct it
*, int);
842 static int cursor_row_fully_visible_p (struct window
*, int, int);
843 static int try_scrolling (Lisp_Object
, int, ptrdiff_t, ptrdiff_t, int, int);
844 static int try_cursor_movement (Lisp_Object
, struct text_pos
, int *);
845 static int trailing_whitespace_p (ptrdiff_t);
846 static intmax_t message_log_check_duplicate (ptrdiff_t, ptrdiff_t);
847 static void push_it (struct it
*, struct text_pos
*);
848 static void iterate_out_of_display_property (struct it
*);
849 static void pop_it (struct it
*);
850 static void sync_frame_with_window_matrix_rows (struct window
*);
851 static void redisplay_internal (void);
852 static int echo_area_display (int);
853 static void redisplay_windows (Lisp_Object
);
854 static void redisplay_window (Lisp_Object
, int);
855 static Lisp_Object
redisplay_window_error (Lisp_Object
);
856 static Lisp_Object
redisplay_window_0 (Lisp_Object
);
857 static Lisp_Object
redisplay_window_1 (Lisp_Object
);
858 static int set_cursor_from_row (struct window
*, struct glyph_row
*,
859 struct glyph_matrix
*, ptrdiff_t, ptrdiff_t,
861 static int update_menu_bar (struct frame
*, int, int);
862 static int try_window_reusing_current_matrix (struct window
*);
863 static int try_window_id (struct window
*);
864 static int display_line (struct it
*);
865 static int display_mode_lines (struct window
*);
866 static int display_mode_line (struct window
*, enum face_id
, Lisp_Object
);
867 static int display_mode_element (struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int);
868 static int store_mode_line_string (const char *, Lisp_Object
, int, int, int, Lisp_Object
);
869 static const char *decode_mode_spec (struct window
*, int, int, Lisp_Object
*);
870 static void display_menu_bar (struct window
*);
871 static ptrdiff_t display_count_lines (ptrdiff_t, ptrdiff_t, ptrdiff_t,
873 static int display_string (const char *, Lisp_Object
, Lisp_Object
,
874 ptrdiff_t, ptrdiff_t, struct it
*, int, int, int, int);
875 static void compute_line_metrics (struct it
*);
876 static void run_redisplay_end_trigger_hook (struct it
*);
877 static int get_overlay_strings (struct it
*, ptrdiff_t);
878 static int get_overlay_strings_1 (struct it
*, ptrdiff_t, int);
879 static void next_overlay_string (struct it
*);
880 static void reseat (struct it
*, struct text_pos
, int);
881 static void reseat_1 (struct it
*, struct text_pos
, int);
882 static void back_to_previous_visible_line_start (struct it
*);
883 void reseat_at_previous_visible_line_start (struct it
*);
884 static void reseat_at_next_visible_line_start (struct it
*, int);
885 static int next_element_from_ellipsis (struct it
*);
886 static int next_element_from_display_vector (struct it
*);
887 static int next_element_from_string (struct it
*);
888 static int next_element_from_c_string (struct it
*);
889 static int next_element_from_buffer (struct it
*);
890 static int next_element_from_composition (struct it
*);
891 static int next_element_from_image (struct it
*);
892 static int next_element_from_stretch (struct it
*);
893 static void load_overlay_strings (struct it
*, ptrdiff_t);
894 static int init_from_display_pos (struct it
*, struct window
*,
895 struct display_pos
*);
896 static void reseat_to_string (struct it
*, const char *,
897 Lisp_Object
, ptrdiff_t, ptrdiff_t, int, int);
898 static int get_next_display_element (struct it
*);
899 static enum move_it_result
900 move_it_in_display_line_to (struct it
*, ptrdiff_t, int,
901 enum move_operation_enum
);
902 void move_it_vertically_backward (struct it
*, int);
903 static void get_visually_first_element (struct it
*);
904 static void init_to_row_start (struct it
*, struct window
*,
906 static int init_to_row_end (struct it
*, struct window
*,
908 static void back_to_previous_line_start (struct it
*);
909 static int forward_to_next_line_start (struct it
*, int *, struct bidi_it
*);
910 static struct text_pos
string_pos_nchars_ahead (struct text_pos
,
911 Lisp_Object
, ptrdiff_t);
912 static struct text_pos
string_pos (ptrdiff_t, Lisp_Object
);
913 static struct text_pos
c_string_pos (ptrdiff_t, const char *, int);
914 static ptrdiff_t number_of_chars (const char *, int);
915 static void compute_stop_pos (struct it
*);
916 static void compute_string_pos (struct text_pos
*, struct text_pos
,
918 static int face_before_or_after_it_pos (struct it
*, int);
919 static ptrdiff_t next_overlay_change (ptrdiff_t);
920 static int handle_display_spec (struct it
*, Lisp_Object
, Lisp_Object
,
921 Lisp_Object
, struct text_pos
*, ptrdiff_t, int);
922 static int handle_single_display_spec (struct it
*, Lisp_Object
,
923 Lisp_Object
, Lisp_Object
,
924 struct text_pos
*, ptrdiff_t, int, int);
925 static int underlying_face_id (struct it
*);
926 static int in_ellipses_for_invisible_text_p (struct display_pos
*,
929 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
930 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
932 #ifdef HAVE_WINDOW_SYSTEM
934 static void x_consider_frame_title (Lisp_Object
);
935 static int tool_bar_lines_needed (struct frame
*, int *);
936 static void update_tool_bar (struct frame
*, int);
937 static void build_desired_tool_bar_string (struct frame
*f
);
938 static int redisplay_tool_bar (struct frame
*);
939 static void display_tool_bar_line (struct it
*, int);
940 static void notice_overwritten_cursor (struct window
*,
943 static void append_stretch_glyph (struct it
*, Lisp_Object
,
947 #endif /* HAVE_WINDOW_SYSTEM */
949 static void produce_special_glyphs (struct it
*, enum display_element_type
);
950 static void show_mouse_face (Mouse_HLInfo
*, enum draw_glyphs_face
);
951 static int coords_in_mouse_face_p (struct window
*, int, int);
955 /***********************************************************************
956 Window display dimensions
957 ***********************************************************************/
959 /* Return the bottom boundary y-position for text lines in window W.
960 This is the first y position at which a line cannot start.
961 It is relative to the top of the window.
963 This is the height of W minus the height of a mode line, if any. */
966 window_text_bottom_y (struct window
*w
)
968 int height
= WINDOW_TOTAL_HEIGHT (w
);
970 if (WINDOW_WANTS_MODELINE_P (w
))
971 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
975 /* Return the pixel width of display area AREA of window W. AREA < 0
976 means return the total width of W, not including fringes to
977 the left and right of the window. */
980 window_box_width (struct window
*w
, int area
)
982 int cols
= XFASTINT (w
->total_cols
);
985 if (!w
->pseudo_window_p
)
987 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
989 if (area
== TEXT_AREA
)
991 if (INTEGERP (w
->left_margin_cols
))
992 cols
-= XFASTINT (w
->left_margin_cols
);
993 if (INTEGERP (w
->right_margin_cols
))
994 cols
-= XFASTINT (w
->right_margin_cols
);
995 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
997 else if (area
== LEFT_MARGIN_AREA
)
999 cols
= (INTEGERP (w
->left_margin_cols
)
1000 ? XFASTINT (w
->left_margin_cols
) : 0);
1003 else if (area
== RIGHT_MARGIN_AREA
)
1005 cols
= (INTEGERP (w
->right_margin_cols
)
1006 ? XFASTINT (w
->right_margin_cols
) : 0);
1011 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1015 /* Return the pixel height of the display area of window W, not
1016 including mode lines of W, if any. */
1019 window_box_height (struct window
*w
)
1021 struct frame
*f
= XFRAME (w
->frame
);
1022 int height
= WINDOW_TOTAL_HEIGHT (w
);
1024 eassert (height
>= 0);
1026 /* Note: the code below that determines the mode-line/header-line
1027 height is essentially the same as that contained in the macro
1028 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1029 the appropriate glyph row has its `mode_line_p' flag set,
1030 and if it doesn't, uses estimate_mode_line_height instead. */
1032 if (WINDOW_WANTS_MODELINE_P (w
))
1034 struct glyph_row
*ml_row
1035 = (w
->current_matrix
&& w
->current_matrix
->rows
1036 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1038 if (ml_row
&& ml_row
->mode_line_p
)
1039 height
-= ml_row
->height
;
1041 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1044 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1046 struct glyph_row
*hl_row
1047 = (w
->current_matrix
&& w
->current_matrix
->rows
1048 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1050 if (hl_row
&& hl_row
->mode_line_p
)
1051 height
-= hl_row
->height
;
1053 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1056 /* With a very small font and a mode-line that's taller than
1057 default, we might end up with a negative height. */
1058 return max (0, height
);
1061 /* Return the window-relative coordinate of the left edge of display
1062 area AREA of window W. AREA < 0 means return the left edge of the
1063 whole window, to the right of the left fringe of W. */
1066 window_box_left_offset (struct window
*w
, int area
)
1070 if (w
->pseudo_window_p
)
1073 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1075 if (area
== TEXT_AREA
)
1076 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1077 + window_box_width (w
, LEFT_MARGIN_AREA
));
1078 else if (area
== RIGHT_MARGIN_AREA
)
1079 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1080 + window_box_width (w
, LEFT_MARGIN_AREA
)
1081 + window_box_width (w
, TEXT_AREA
)
1082 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1084 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1085 else if (area
== LEFT_MARGIN_AREA
1086 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1087 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1093 /* Return the window-relative coordinate of the right edge of display
1094 area AREA of window W. AREA < 0 means return the right edge of the
1095 whole window, to the left of the right fringe of W. */
1098 window_box_right_offset (struct window
*w
, int area
)
1100 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1103 /* Return the frame-relative coordinate of the left edge of display
1104 area AREA of window W. AREA < 0 means return the left edge of the
1105 whole window, to the right of the left fringe of W. */
1108 window_box_left (struct window
*w
, int area
)
1110 struct frame
*f
= XFRAME (w
->frame
);
1113 if (w
->pseudo_window_p
)
1114 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1116 x
= (WINDOW_LEFT_EDGE_X (w
)
1117 + window_box_left_offset (w
, area
));
1123 /* Return the frame-relative coordinate of the right edge of display
1124 area AREA of window W. AREA < 0 means return the right edge of the
1125 whole window, to the left of the right fringe of W. */
1128 window_box_right (struct window
*w
, int area
)
1130 return window_box_left (w
, area
) + window_box_width (w
, area
);
1133 /* Get the bounding box of the display area AREA of window W, without
1134 mode lines, in frame-relative coordinates. AREA < 0 means the
1135 whole window, not including the left and right fringes of
1136 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1137 coordinates of the upper-left corner of the box. Return in
1138 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1141 window_box (struct window
*w
, int area
, int *box_x
, int *box_y
,
1142 int *box_width
, int *box_height
)
1145 *box_width
= window_box_width (w
, area
);
1147 *box_height
= window_box_height (w
);
1149 *box_x
= window_box_left (w
, area
);
1152 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1153 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1154 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1159 /* Get the bounding box of the display area AREA of window W, without
1160 mode lines. AREA < 0 means the whole window, not including the
1161 left and right fringe of the window. Return in *TOP_LEFT_X
1162 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1163 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1164 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1168 window_box_edges (struct window
*w
, int area
, int *top_left_x
, int *top_left_y
,
1169 int *bottom_right_x
, int *bottom_right_y
)
1171 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1173 *bottom_right_x
+= *top_left_x
;
1174 *bottom_right_y
+= *top_left_y
;
1179 /***********************************************************************
1181 ***********************************************************************/
1183 /* Return the bottom y-position of the line the iterator IT is in.
1184 This can modify IT's settings. */
1187 line_bottom_y (struct it
*it
)
1189 int line_height
= it
->max_ascent
+ it
->max_descent
;
1190 int line_top_y
= it
->current_y
;
1192 if (line_height
== 0)
1195 line_height
= last_height
;
1196 else if (IT_CHARPOS (*it
) < ZV
)
1198 move_it_by_lines (it
, 1);
1199 line_height
= (it
->max_ascent
|| it
->max_descent
1200 ? it
->max_ascent
+ it
->max_descent
1205 struct glyph_row
*row
= it
->glyph_row
;
1207 /* Use the default character height. */
1208 it
->glyph_row
= NULL
;
1209 it
->what
= IT_CHARACTER
;
1212 PRODUCE_GLYPHS (it
);
1213 line_height
= it
->ascent
+ it
->descent
;
1214 it
->glyph_row
= row
;
1218 return line_top_y
+ line_height
;
1221 /* Subroutine of pos_visible_p below. Extracts a display string, if
1222 any, from the display spec given as its argument. */
1224 string_from_display_spec (Lisp_Object spec
)
1228 while (CONSP (spec
))
1230 if (STRINGP (XCAR (spec
)))
1235 else if (VECTORP (spec
))
1239 for (i
= 0; i
< ASIZE (spec
); i
++)
1241 if (STRINGP (AREF (spec
, i
)))
1242 return AREF (spec
, i
);
1251 /* Limit insanely large values of W->hscroll on frame F to the largest
1252 value that will still prevent first_visible_x and last_visible_x of
1253 'struct it' from overflowing an int. */
1255 window_hscroll_limited (struct window
*w
, struct frame
*f
)
1257 ptrdiff_t window_hscroll
= w
->hscroll
;
1258 int window_text_width
= window_box_width (w
, TEXT_AREA
);
1259 int colwidth
= FRAME_COLUMN_WIDTH (f
);
1261 if (window_hscroll
> (INT_MAX
- window_text_width
) / colwidth
- 1)
1262 window_hscroll
= (INT_MAX
- window_text_width
) / colwidth
- 1;
1264 return window_hscroll
;
1267 /* Return 1 if position CHARPOS is visible in window W.
1268 CHARPOS < 0 means return info about WINDOW_END position.
1269 If visible, set *X and *Y to pixel coordinates of top left corner.
1270 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1271 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1274 pos_visible_p (struct window
*w
, ptrdiff_t charpos
, int *x
, int *y
,
1275 int *rtop
, int *rbot
, int *rowh
, int *vpos
)
1278 void *itdata
= bidi_shelve_cache ();
1279 struct text_pos top
;
1281 struct buffer
*old_buffer
= NULL
;
1283 if (FRAME_INITIAL_P (XFRAME (WINDOW_FRAME (w
))))
1286 if (XBUFFER (w
->buffer
) != current_buffer
)
1288 old_buffer
= current_buffer
;
1289 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1292 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1293 /* Scrolling a minibuffer window via scroll bar when the echo area
1294 shows long text sometimes resets the minibuffer contents behind
1296 if (CHARPOS (top
) > ZV
)
1297 SET_TEXT_POS (top
, BEGV
, BEGV_BYTE
);
1299 /* Compute exact mode line heights. */
1300 if (WINDOW_WANTS_MODELINE_P (w
))
1301 current_mode_line_height
1302 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1303 BVAR (current_buffer
, mode_line_format
));
1305 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1306 current_header_line_height
1307 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1308 BVAR (current_buffer
, header_line_format
));
1310 start_display (&it
, w
, top
);
1311 move_it_to (&it
, charpos
, -1, it
.last_visible_y
- 1, -1,
1312 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1315 && (((!it
.bidi_p
|| it
.bidi_it
.scan_dir
== 1)
1316 && IT_CHARPOS (it
) >= charpos
)
1317 /* When scanning backwards under bidi iteration, move_it_to
1318 stops at or _before_ CHARPOS, because it stops at or to
1319 the _right_ of the character at CHARPOS. */
1320 || (it
.bidi_p
&& it
.bidi_it
.scan_dir
== -1
1321 && IT_CHARPOS (it
) <= charpos
)))
1323 /* We have reached CHARPOS, or passed it. How the call to
1324 move_it_to can overshoot: (i) If CHARPOS is on invisible text
1325 or covered by a display property, move_it_to stops at the end
1326 of the invisible text, to the right of CHARPOS. (ii) If
1327 CHARPOS is in a display vector, move_it_to stops on its last
1329 int top_x
= it
.current_x
;
1330 int top_y
= it
.current_y
;
1331 /* Calling line_bottom_y may change it.method, it.position, etc. */
1332 enum it_method it_method
= it
.method
;
1333 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1334 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1336 if (top_y
< window_top_y
)
1337 visible_p
= bottom_y
> window_top_y
;
1338 else if (top_y
< it
.last_visible_y
)
1340 if (bottom_y
>= it
.last_visible_y
1341 && it
.bidi_p
&& it
.bidi_it
.scan_dir
== -1
1342 && IT_CHARPOS (it
) < charpos
)
1344 /* When the last line of the window is scanned backwards
1345 under bidi iteration, we could be duped into thinking
1346 that we have passed CHARPOS, when in fact move_it_to
1347 simply stopped short of CHARPOS because it reached
1348 last_visible_y. To see if that's what happened, we call
1349 move_it_to again with a slightly larger vertical limit,
1350 and see if it actually moved vertically; if it did, we
1351 didn't really reach CHARPOS, which is beyond window end. */
1352 struct it save_it
= it
;
1353 /* Why 10? because we don't know how many canonical lines
1354 will the height of the next line(s) be. So we guess. */
1355 int ten_more_lines
=
1356 10 * FRAME_LINE_HEIGHT (XFRAME (WINDOW_FRAME (w
)));
1358 move_it_to (&it
, charpos
, -1, bottom_y
+ ten_more_lines
, -1,
1359 MOVE_TO_POS
| MOVE_TO_Y
);
1360 if (it
.current_y
> top_y
)
1367 if (it_method
== GET_FROM_DISPLAY_VECTOR
)
1369 /* We stopped on the last glyph of a display vector.
1370 Try and recompute. Hack alert! */
1371 if (charpos
< 2 || top
.charpos
>= charpos
)
1372 top_x
= it
.glyph_row
->x
;
1376 start_display (&it2
, w
, top
);
1377 move_it_to (&it2
, charpos
- 1, -1, -1, -1, MOVE_TO_POS
);
1378 get_next_display_element (&it2
);
1379 PRODUCE_GLYPHS (&it2
);
1380 if (ITERATOR_AT_END_OF_LINE_P (&it2
)
1381 || it2
.current_x
> it2
.last_visible_x
)
1382 top_x
= it
.glyph_row
->x
;
1385 top_x
= it2
.current_x
;
1386 top_y
= it2
.current_y
;
1390 else if (IT_CHARPOS (it
) != charpos
)
1392 Lisp_Object cpos
= make_number (charpos
);
1393 Lisp_Object spec
= Fget_char_property (cpos
, Qdisplay
, Qnil
);
1394 Lisp_Object string
= string_from_display_spec (spec
);
1395 int newline_in_string
= 0;
1397 if (STRINGP (string
))
1399 const char *s
= SSDATA (string
);
1400 const char *e
= s
+ SBYTES (string
);
1405 newline_in_string
= 1;
1410 /* The tricky code below is needed because there's a
1411 discrepancy between move_it_to and how we set cursor
1412 when the display line ends in a newline from a
1413 display string. move_it_to will stop _after_ such
1414 display strings, whereas set_cursor_from_row
1415 conspires with cursor_row_p to place the cursor on
1416 the first glyph produced from the display string. */
1418 /* We have overshoot PT because it is covered by a
1419 display property whose value is a string. If the
1420 string includes embedded newlines, we are also in the
1421 wrong display line. Backtrack to the correct line,
1422 where the display string begins. */
1423 if (newline_in_string
)
1425 Lisp_Object startpos
, endpos
;
1426 EMACS_INT start
, end
;
1430 /* Find the first and the last buffer positions
1431 covered by the display string. */
1433 Fnext_single_char_property_change (cpos
, Qdisplay
,
1436 Fprevious_single_char_property_change (endpos
, Qdisplay
,
1438 start
= XFASTINT (startpos
);
1439 end
= XFASTINT (endpos
);
1440 /* Move to the last buffer position before the
1441 display property. */
1442 start_display (&it3
, w
, top
);
1443 move_it_to (&it3
, start
- 1, -1, -1, -1, MOVE_TO_POS
);
1444 /* Move forward one more line if the position before
1445 the display string is a newline or if it is the
1446 rightmost character on a line that is
1447 continued or word-wrapped. */
1448 if (it3
.method
== GET_FROM_BUFFER
1450 move_it_by_lines (&it3
, 1);
1451 else if (move_it_in_display_line_to (&it3
, -1,
1455 == MOVE_LINE_CONTINUED
)
1457 move_it_by_lines (&it3
, 1);
1458 /* When we are under word-wrap, the #$@%!
1459 move_it_by_lines moves 2 lines, so we need to
1461 if (it3
.line_wrap
== WORD_WRAP
)
1462 move_it_by_lines (&it3
, -1);
1465 /* Record the vertical coordinate of the display
1466 line where we wound up. */
1467 top_y
= it3
.current_y
;
1470 /* When characters are reordered for display,
1471 the character displayed to the left of the
1472 display string could be _after_ the display
1473 property in the logical order. Use the
1474 smallest vertical position of these two. */
1475 start_display (&it3
, w
, top
);
1476 move_it_to (&it3
, end
+ 1, -1, -1, -1, MOVE_TO_POS
);
1477 if (it3
.current_y
< top_y
)
1478 top_y
= it3
.current_y
;
1480 /* Move from the top of the window to the beginning
1481 of the display line where the display string
1483 start_display (&it3
, w
, top
);
1484 move_it_to (&it3
, -1, 0, top_y
, -1, MOVE_TO_X
| MOVE_TO_Y
);
1485 /* If it3_moved stays zero after the 'while' loop
1486 below, that means we already were at a newline
1487 before the loop (e.g., the display string begins
1488 with a newline), so we don't need to (and cannot)
1489 inspect the glyphs of it3.glyph_row, because
1490 PRODUCE_GLYPHS will not produce anything for a
1491 newline, and thus it3.glyph_row stays at its
1492 stale content it got at top of the window. */
1494 /* Finally, advance the iterator until we hit the
1495 first display element whose character position is
1496 CHARPOS, or until the first newline from the
1497 display string, which signals the end of the
1499 while (get_next_display_element (&it3
))
1501 PRODUCE_GLYPHS (&it3
);
1502 if (IT_CHARPOS (it3
) == charpos
1503 || ITERATOR_AT_END_OF_LINE_P (&it3
))
1506 set_iterator_to_next (&it3
, 0);
1508 top_x
= it3
.current_x
- it3
.pixel_width
;
1509 /* Normally, we would exit the above loop because we
1510 found the display element whose character
1511 position is CHARPOS. For the contingency that we
1512 didn't, and stopped at the first newline from the
1513 display string, move back over the glyphs
1514 produced from the string, until we find the
1515 rightmost glyph not from the string. */
1517 && IT_CHARPOS (it3
) != charpos
&& EQ (it3
.object
, string
))
1519 struct glyph
*g
= it3
.glyph_row
->glyphs
[TEXT_AREA
]
1520 + it3
.glyph_row
->used
[TEXT_AREA
];
1522 while (EQ ((g
- 1)->object
, string
))
1525 top_x
-= g
->pixel_width
;
1527 eassert (g
< it3
.glyph_row
->glyphs
[TEXT_AREA
]
1528 + it3
.glyph_row
->used
[TEXT_AREA
]);
1534 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1535 *rtop
= max (0, window_top_y
- top_y
);
1536 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1537 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1538 - max (top_y
, window_top_y
)));
1544 /* We were asked to provide info about WINDOW_END. */
1546 void *it2data
= NULL
;
1548 SAVE_IT (it2
, it
, it2data
);
1549 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1550 move_it_by_lines (&it
, 1);
1551 if (charpos
< IT_CHARPOS (it
)
1552 || (it
.what
== IT_EOB
&& charpos
== IT_CHARPOS (it
)))
1555 RESTORE_IT (&it2
, &it2
, it2data
);
1556 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1558 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1559 *rtop
= max (0, -it2
.current_y
);
1560 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1561 - it
.last_visible_y
));
1562 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1564 - max (it2
.current_y
,
1565 WINDOW_HEADER_LINE_HEIGHT (w
))));
1569 bidi_unshelve_cache (it2data
, 1);
1571 bidi_unshelve_cache (itdata
, 0);
1574 set_buffer_internal_1 (old_buffer
);
1576 current_header_line_height
= current_mode_line_height
= -1;
1578 if (visible_p
&& w
->hscroll
> 0)
1580 window_hscroll_limited (w
, WINDOW_XFRAME (w
))
1581 * WINDOW_FRAME_COLUMN_WIDTH (w
);
1584 /* Debugging code. */
1586 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1587 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1589 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1596 /* Return the next character from STR. Return in *LEN the length of
1597 the character. This is like STRING_CHAR_AND_LENGTH but never
1598 returns an invalid character. If we find one, we return a `?', but
1599 with the length of the invalid character. */
1602 string_char_and_length (const unsigned char *str
, int *len
)
1606 c
= STRING_CHAR_AND_LENGTH (str
, *len
);
1607 if (!CHAR_VALID_P (c
))
1608 /* We may not change the length here because other places in Emacs
1609 don't use this function, i.e. they silently accept invalid
1618 /* Given a position POS containing a valid character and byte position
1619 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1621 static struct text_pos
1622 string_pos_nchars_ahead (struct text_pos pos
, Lisp_Object string
, ptrdiff_t nchars
)
1624 eassert (STRINGP (string
) && nchars
>= 0);
1626 if (STRING_MULTIBYTE (string
))
1628 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1633 string_char_and_length (p
, &len
);
1636 BYTEPOS (pos
) += len
;
1640 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1646 /* Value is the text position, i.e. character and byte position,
1647 for character position CHARPOS in STRING. */
1649 static struct text_pos
1650 string_pos (ptrdiff_t charpos
, Lisp_Object string
)
1652 struct text_pos pos
;
1653 eassert (STRINGP (string
));
1654 eassert (charpos
>= 0);
1655 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1660 /* Value is a text position, i.e. character and byte position, for
1661 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1662 means recognize multibyte characters. */
1664 static struct text_pos
1665 c_string_pos (ptrdiff_t charpos
, const char *s
, int multibyte_p
)
1667 struct text_pos pos
;
1669 eassert (s
!= NULL
);
1670 eassert (charpos
>= 0);
1676 SET_TEXT_POS (pos
, 0, 0);
1679 string_char_and_length ((const unsigned char *) s
, &len
);
1682 BYTEPOS (pos
) += len
;
1686 SET_TEXT_POS (pos
, charpos
, charpos
);
1692 /* Value is the number of characters in C string S. MULTIBYTE_P
1693 non-zero means recognize multibyte characters. */
1696 number_of_chars (const char *s
, int multibyte_p
)
1702 ptrdiff_t rest
= strlen (s
);
1704 const unsigned char *p
= (const unsigned char *) s
;
1706 for (nchars
= 0; rest
> 0; ++nchars
)
1708 string_char_and_length (p
, &len
);
1709 rest
-= len
, p
+= len
;
1713 nchars
= strlen (s
);
1719 /* Compute byte position NEWPOS->bytepos corresponding to
1720 NEWPOS->charpos. POS is a known position in string STRING.
1721 NEWPOS->charpos must be >= POS.charpos. */
1724 compute_string_pos (struct text_pos
*newpos
, struct text_pos pos
, Lisp_Object string
)
1726 eassert (STRINGP (string
));
1727 eassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1729 if (STRING_MULTIBYTE (string
))
1730 *newpos
= string_pos_nchars_ahead (pos
, string
,
1731 CHARPOS (*newpos
) - CHARPOS (pos
));
1733 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1737 Return an estimation of the pixel height of mode or header lines on
1738 frame F. FACE_ID specifies what line's height to estimate. */
1741 estimate_mode_line_height (struct frame
*f
, enum face_id face_id
)
1743 #ifdef HAVE_WINDOW_SYSTEM
1744 if (FRAME_WINDOW_P (f
))
1746 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1748 /* This function is called so early when Emacs starts that the face
1749 cache and mode line face are not yet initialized. */
1750 if (FRAME_FACE_CACHE (f
))
1752 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1756 height
= FONT_HEIGHT (face
->font
);
1757 if (face
->box_line_width
> 0)
1758 height
+= 2 * face
->box_line_width
;
1769 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1770 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1771 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1772 not force the value into range. */
1775 pixel_to_glyph_coords (FRAME_PTR f
, register int pix_x
, register int pix_y
,
1776 int *x
, int *y
, NativeRectangle
*bounds
, int noclip
)
1779 #ifdef HAVE_WINDOW_SYSTEM
1780 if (FRAME_WINDOW_P (f
))
1782 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1783 even for negative values. */
1785 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1787 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1789 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1790 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1793 STORE_NATIVE_RECT (*bounds
,
1794 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1795 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1796 FRAME_COLUMN_WIDTH (f
) - 1,
1797 FRAME_LINE_HEIGHT (f
) - 1);
1803 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1804 pix_x
= FRAME_TOTAL_COLS (f
);
1808 else if (pix_y
> FRAME_LINES (f
))
1809 pix_y
= FRAME_LINES (f
);
1819 /* Find the glyph under window-relative coordinates X/Y in window W.
1820 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1821 strings. Return in *HPOS and *VPOS the row and column number of
1822 the glyph found. Return in *AREA the glyph area containing X.
1823 Value is a pointer to the glyph found or null if X/Y is not on
1824 text, or we can't tell because W's current matrix is not up to
1829 x_y_to_hpos_vpos (struct window
*w
, int x
, int y
, int *hpos
, int *vpos
,
1830 int *dx
, int *dy
, int *area
)
1832 struct glyph
*glyph
, *end
;
1833 struct glyph_row
*row
= NULL
;
1836 /* Find row containing Y. Give up if some row is not enabled. */
1837 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1839 row
= MATRIX_ROW (w
->current_matrix
, i
);
1840 if (!row
->enabled_p
)
1842 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1849 /* Give up if Y is not in the window. */
1850 if (i
== w
->current_matrix
->nrows
)
1853 /* Get the glyph area containing X. */
1854 if (w
->pseudo_window_p
)
1861 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1863 *area
= LEFT_MARGIN_AREA
;
1864 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1866 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1869 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1873 *area
= RIGHT_MARGIN_AREA
;
1874 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1878 /* Find glyph containing X. */
1879 glyph
= row
->glyphs
[*area
];
1880 end
= glyph
+ row
->used
[*area
];
1882 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1884 x
-= glyph
->pixel_width
;
1894 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1897 *hpos
= glyph
- row
->glyphs
[*area
];
1901 /* Convert frame-relative x/y to coordinates relative to window W.
1902 Takes pseudo-windows into account. */
1905 frame_to_window_pixel_xy (struct window
*w
, int *x
, int *y
)
1907 if (w
->pseudo_window_p
)
1909 /* A pseudo-window is always full-width, and starts at the
1910 left edge of the frame, plus a frame border. */
1911 struct frame
*f
= XFRAME (w
->frame
);
1912 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1913 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1917 *x
-= WINDOW_LEFT_EDGE_X (w
);
1918 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1922 #ifdef HAVE_WINDOW_SYSTEM
1925 Return in RECTS[] at most N clipping rectangles for glyph string S.
1926 Return the number of stored rectangles. */
1929 get_glyph_string_clip_rects (struct glyph_string
*s
, NativeRectangle
*rects
, int n
)
1936 if (s
->row
->full_width_p
)
1938 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1939 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1940 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1942 /* Unless displaying a mode or menu bar line, which are always
1943 fully visible, clip to the visible part of the row. */
1944 if (s
->w
->pseudo_window_p
)
1945 r
.height
= s
->row
->visible_height
;
1947 r
.height
= s
->height
;
1951 /* This is a text line that may be partially visible. */
1952 r
.x
= window_box_left (s
->w
, s
->area
);
1953 r
.width
= window_box_width (s
->w
, s
->area
);
1954 r
.height
= s
->row
->visible_height
;
1958 if (r
.x
< s
->clip_head
->x
)
1960 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1961 r
.width
-= s
->clip_head
->x
- r
.x
;
1964 r
.x
= s
->clip_head
->x
;
1967 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1969 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1970 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
1975 /* If S draws overlapping rows, it's sufficient to use the top and
1976 bottom of the window for clipping because this glyph string
1977 intentionally draws over other lines. */
1978 if (s
->for_overlaps
)
1980 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1981 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1983 /* Alas, the above simple strategy does not work for the
1984 environments with anti-aliased text: if the same text is
1985 drawn onto the same place multiple times, it gets thicker.
1986 If the overlap we are processing is for the erased cursor, we
1987 take the intersection with the rectangle of the cursor. */
1988 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
1990 XRectangle rc
, r_save
= r
;
1992 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
1993 rc
.y
= s
->w
->phys_cursor
.y
;
1994 rc
.width
= s
->w
->phys_cursor_width
;
1995 rc
.height
= s
->w
->phys_cursor_height
;
1997 x_intersect_rectangles (&r_save
, &rc
, &r
);
2002 /* Don't use S->y for clipping because it doesn't take partially
2003 visible lines into account. For example, it can be negative for
2004 partially visible lines at the top of a window. */
2005 if (!s
->row
->full_width_p
2006 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
2007 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
2009 r
.y
= max (0, s
->row
->y
);
2012 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
2014 /* If drawing the cursor, don't let glyph draw outside its
2015 advertised boundaries. Cleartype does this under some circumstances. */
2016 if (s
->hl
== DRAW_CURSOR
)
2018 struct glyph
*glyph
= s
->first_glyph
;
2023 r
.width
-= s
->x
- r
.x
;
2026 r
.width
= min (r
.width
, glyph
->pixel_width
);
2028 /* If r.y is below window bottom, ensure that we still see a cursor. */
2029 height
= min (glyph
->ascent
+ glyph
->descent
,
2030 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
2031 max_y
= window_text_bottom_y (s
->w
) - height
;
2032 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
2033 if (s
->ybase
- glyph
->ascent
> max_y
)
2040 /* Don't draw cursor glyph taller than our actual glyph. */
2041 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
2042 if (height
< r
.height
)
2044 max_y
= r
.y
+ r
.height
;
2045 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
2046 r
.height
= min (max_y
- r
.y
, height
);
2053 XRectangle r_save
= r
;
2055 if (! x_intersect_rectangles (&r_save
, s
->row
->clip
, &r
))
2059 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
2060 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
2062 #ifdef CONVERT_FROM_XRECT
2063 CONVERT_FROM_XRECT (r
, *rects
);
2071 /* If we are processing overlapping and allowed to return
2072 multiple clipping rectangles, we exclude the row of the glyph
2073 string from the clipping rectangle. This is to avoid drawing
2074 the same text on the environment with anti-aliasing. */
2075 #ifdef CONVERT_FROM_XRECT
2078 XRectangle
*rs
= rects
;
2080 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
2082 if (s
->for_overlaps
& OVERLAPS_PRED
)
2085 if (r
.y
+ r
.height
> row_y
)
2088 rs
[i
].height
= row_y
- r
.y
;
2094 if (s
->for_overlaps
& OVERLAPS_SUCC
)
2097 if (r
.y
< row_y
+ s
->row
->visible_height
)
2099 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
2101 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
2102 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
2111 #ifdef CONVERT_FROM_XRECT
2112 for (i
= 0; i
< n
; i
++)
2113 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
2120 Return in *NR the clipping rectangle for glyph string S. */
2123 get_glyph_string_clip_rect (struct glyph_string
*s
, NativeRectangle
*nr
)
2125 get_glyph_string_clip_rects (s
, nr
, 1);
2130 Return the position and height of the phys cursor in window W.
2131 Set w->phys_cursor_width to width of phys cursor.
2135 get_phys_cursor_geometry (struct window
*w
, struct glyph_row
*row
,
2136 struct glyph
*glyph
, int *xp
, int *yp
, int *heightp
)
2138 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2139 int x
, y
, wd
, h
, h0
, y0
;
2141 /* Compute the width of the rectangle to draw. If on a stretch
2142 glyph, and `x-stretch-block-cursor' is nil, don't draw a
2143 rectangle as wide as the glyph, but use a canonical character
2145 wd
= glyph
->pixel_width
- 1;
2146 #if defined (HAVE_NTGUI) || defined (HAVE_NS)
2150 x
= w
->phys_cursor
.x
;
2157 if (glyph
->type
== STRETCH_GLYPH
2158 && !x_stretch_cursor_p
)
2159 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2160 w
->phys_cursor_width
= wd
;
2162 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
2164 /* If y is below window bottom, ensure that we still see a cursor. */
2165 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2167 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
2168 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
2170 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2173 h
= max (h
- (y0
- y
) + 1, h0
);
2178 y0
= window_text_bottom_y (w
) - h0
;
2186 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
2187 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2192 * Remember which glyph the mouse is over.
2196 remember_mouse_glyph (struct frame
*f
, int gx
, int gy
, NativeRectangle
*rect
)
2200 struct glyph_row
*r
, *gr
, *end_row
;
2201 enum window_part part
;
2202 enum glyph_row_area area
;
2203 int x
, y
, width
, height
;
2205 /* Try to determine frame pixel position and size of the glyph under
2206 frame pixel coordinates X/Y on frame F. */
2208 if (!f
->glyphs_initialized_p
2209 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, 0),
2212 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2213 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2217 w
= XWINDOW (window
);
2218 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2219 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2221 x
= window_relative_x_coord (w
, part
, gx
);
2222 y
= gy
- WINDOW_TOP_EDGE_Y (w
);
2224 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2225 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2227 if (w
->pseudo_window_p
)
2230 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2236 case ON_LEFT_MARGIN
:
2237 area
= LEFT_MARGIN_AREA
;
2240 case ON_RIGHT_MARGIN
:
2241 area
= RIGHT_MARGIN_AREA
;
2244 case ON_HEADER_LINE
:
2246 gr
= (part
== ON_HEADER_LINE
2247 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2248 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2251 goto text_glyph_row_found
;
2258 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2259 if (r
->y
+ r
->height
> y
)
2265 text_glyph_row_found
:
2268 struct glyph
*g
= gr
->glyphs
[area
];
2269 struct glyph
*end
= g
+ gr
->used
[area
];
2271 height
= gr
->height
;
2272 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2273 if (gx
+ g
->pixel_width
> x
)
2278 if (g
->type
== IMAGE_GLYPH
)
2280 /* Don't remember when mouse is over image, as
2281 image may have hot-spots. */
2282 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2285 width
= g
->pixel_width
;
2289 /* Use nominal char spacing at end of line. */
2291 gx
+= (x
/ width
) * width
;
2294 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2295 gx
+= window_box_left_offset (w
, area
);
2299 /* Use nominal line height at end of window. */
2300 gx
= (x
/ width
) * width
;
2302 gy
+= (y
/ height
) * height
;
2306 case ON_LEFT_FRINGE
:
2307 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2308 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2309 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2310 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2313 case ON_RIGHT_FRINGE
:
2314 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2315 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2316 : window_box_right_offset (w
, TEXT_AREA
));
2317 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2321 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2323 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2324 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2325 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2327 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2331 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2332 if (r
->y
+ r
->height
> y
)
2339 height
= gr
->height
;
2342 /* Use nominal line height at end of window. */
2344 gy
+= (y
/ height
) * height
;
2351 /* If there is no glyph under the mouse, then we divide the screen
2352 into a grid of the smallest glyph in the frame, and use that
2355 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2356 round down even for negative values. */
2362 gx
= (gx
/ width
) * width
;
2363 gy
= (gy
/ height
) * height
;
2368 gx
+= WINDOW_LEFT_EDGE_X (w
);
2369 gy
+= WINDOW_TOP_EDGE_Y (w
);
2372 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2374 /* Visible feedback for debugging. */
2377 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2378 f
->output_data
.x
->normal_gc
,
2379 gx
, gy
, width
, height
);
2385 #endif /* HAVE_WINDOW_SYSTEM */
2388 /***********************************************************************
2389 Lisp form evaluation
2390 ***********************************************************************/
2392 /* Error handler for safe_eval and safe_call. */
2395 safe_eval_handler (Lisp_Object arg
, ptrdiff_t nargs
, Lisp_Object
*args
)
2397 add_to_log ("Error during redisplay: %S signaled %S",
2398 Flist (nargs
, args
), arg
);
2402 /* Call function FUNC with the rest of NARGS - 1 arguments
2403 following. Return the result, or nil if something went
2404 wrong. Prevent redisplay during the evaluation. */
2407 safe_call (ptrdiff_t nargs
, Lisp_Object func
, ...)
2411 if (inhibit_eval_during_redisplay
)
2417 ptrdiff_t count
= SPECPDL_INDEX ();
2418 struct gcpro gcpro1
;
2419 Lisp_Object
*args
= alloca (nargs
* word_size
);
2422 va_start (ap
, func
);
2423 for (i
= 1; i
< nargs
; i
++)
2424 args
[i
] = va_arg (ap
, Lisp_Object
);
2428 gcpro1
.nvars
= nargs
;
2429 specbind (Qinhibit_redisplay
, Qt
);
2430 /* Use Qt to ensure debugger does not run,
2431 so there is no possibility of wanting to redisplay. */
2432 val
= internal_condition_case_n (Ffuncall
, nargs
, args
, Qt
,
2435 val
= unbind_to (count
, val
);
2442 /* Call function FN with one argument ARG.
2443 Return the result, or nil if something went wrong. */
2446 safe_call1 (Lisp_Object fn
, Lisp_Object arg
)
2448 return safe_call (2, fn
, arg
);
2451 static Lisp_Object Qeval
;
2454 safe_eval (Lisp_Object sexpr
)
2456 return safe_call1 (Qeval
, sexpr
);
2459 /* Call function FN with two arguments ARG1 and ARG2.
2460 Return the result, or nil if something went wrong. */
2463 safe_call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2465 return safe_call (3, fn
, arg1
, arg2
);
2470 /***********************************************************************
2472 ***********************************************************************/
2476 /* Define CHECK_IT to perform sanity checks on iterators.
2477 This is for debugging. It is too slow to do unconditionally. */
2480 check_it (struct it
*it
)
2482 if (it
->method
== GET_FROM_STRING
)
2484 eassert (STRINGP (it
->string
));
2485 eassert (IT_STRING_CHARPOS (*it
) >= 0);
2489 eassert (IT_STRING_CHARPOS (*it
) < 0);
2490 if (it
->method
== GET_FROM_BUFFER
)
2492 /* Check that character and byte positions agree. */
2493 eassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2498 eassert (it
->current
.dpvec_index
>= 0);
2500 eassert (it
->current
.dpvec_index
< 0);
2503 #define CHECK_IT(IT) check_it ((IT))
2507 #define CHECK_IT(IT) (void) 0
2512 #if defined GLYPH_DEBUG && defined ENABLE_CHECKING
2514 /* Check that the window end of window W is what we expect it
2515 to be---the last row in the current matrix displaying text. */
2518 check_window_end (struct window
*w
)
2520 if (!MINI_WINDOW_P (w
) && w
->window_end_valid
)
2522 struct glyph_row
*row
;
2523 eassert ((row
= MATRIX_ROW (w
->current_matrix
,
2524 XFASTINT (w
->window_end_vpos
)),
2526 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2527 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2531 #define CHECK_WINDOW_END(W) check_window_end ((W))
2535 #define CHECK_WINDOW_END(W) (void) 0
2537 #endif /* GLYPH_DEBUG and ENABLE_CHECKING */
2539 /* Return mark position if current buffer has the region of non-zero length,
2543 markpos_of_region (void)
2545 if (!NILP (Vtransient_mark_mode
)
2546 && !NILP (BVAR (current_buffer
, mark_active
))
2547 && XMARKER (BVAR (current_buffer
, mark
))->buffer
!= NULL
)
2549 ptrdiff_t markpos
= XMARKER (BVAR (current_buffer
, mark
))->charpos
;
2557 /***********************************************************************
2558 Iterator initialization
2559 ***********************************************************************/
2561 /* Initialize IT for displaying current_buffer in window W, starting
2562 at character position CHARPOS. CHARPOS < 0 means that no buffer
2563 position is specified which is useful when the iterator is assigned
2564 a position later. BYTEPOS is the byte position corresponding to
2565 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2567 If ROW is not null, calls to produce_glyphs with IT as parameter
2568 will produce glyphs in that row.
2570 BASE_FACE_ID is the id of a base face to use. It must be one of
2571 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2572 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2573 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2575 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2576 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2577 will be initialized to use the corresponding mode line glyph row of
2578 the desired matrix of W. */
2581 init_iterator (struct it
*it
, struct window
*w
,
2582 ptrdiff_t charpos
, ptrdiff_t bytepos
,
2583 struct glyph_row
*row
, enum face_id base_face_id
)
2586 enum face_id remapped_base_face_id
= base_face_id
;
2588 /* Some precondition checks. */
2589 eassert (w
!= NULL
&& it
!= NULL
);
2590 eassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2593 /* If face attributes have been changed since the last redisplay,
2594 free realized faces now because they depend on face definitions
2595 that might have changed. Don't free faces while there might be
2596 desired matrices pending which reference these faces. */
2597 if (face_change_count
&& !inhibit_free_realized_faces
)
2599 face_change_count
= 0;
2600 free_all_realized_faces (Qnil
);
2603 /* Perhaps remap BASE_FACE_ID to a user-specified alternative. */
2604 if (! NILP (Vface_remapping_alist
))
2605 remapped_base_face_id
2606 = lookup_basic_face (XFRAME (w
->frame
), base_face_id
);
2608 /* Use one of the mode line rows of W's desired matrix if
2612 if (base_face_id
== MODE_LINE_FACE_ID
2613 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2614 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2615 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2616 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2620 memset (it
, 0, sizeof *it
);
2621 it
->current
.overlay_string_index
= -1;
2622 it
->current
.dpvec_index
= -1;
2623 it
->base_face_id
= remapped_base_face_id
;
2625 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2626 it
->paragraph_embedding
= L2R
;
2627 it
->bidi_it
.string
.lstring
= Qnil
;
2628 it
->bidi_it
.string
.s
= NULL
;
2629 it
->bidi_it
.string
.bufpos
= 0;
2631 /* The window in which we iterate over current_buffer: */
2632 XSETWINDOW (it
->window
, w
);
2634 it
->f
= XFRAME (w
->frame
);
2638 /* Extra space between lines (on window systems only). */
2639 if (base_face_id
== DEFAULT_FACE_ID
2640 && FRAME_WINDOW_P (it
->f
))
2642 if (NATNUMP (BVAR (current_buffer
, extra_line_spacing
)))
2643 it
->extra_line_spacing
= XFASTINT (BVAR (current_buffer
, extra_line_spacing
));
2644 else if (FLOATP (BVAR (current_buffer
, extra_line_spacing
)))
2645 it
->extra_line_spacing
= (XFLOAT_DATA (BVAR (current_buffer
, extra_line_spacing
))
2646 * FRAME_LINE_HEIGHT (it
->f
));
2647 else if (it
->f
->extra_line_spacing
> 0)
2648 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2649 it
->max_extra_line_spacing
= 0;
2652 /* If realized faces have been removed, e.g. because of face
2653 attribute changes of named faces, recompute them. When running
2654 in batch mode, the face cache of the initial frame is null. If
2655 we happen to get called, make a dummy face cache. */
2656 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2657 init_frame_faces (it
->f
);
2658 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2659 recompute_basic_faces (it
->f
);
2661 /* Current value of the `slice', `space-width', and 'height' properties. */
2662 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2663 it
->space_width
= Qnil
;
2664 it
->font_height
= Qnil
;
2665 it
->override_ascent
= -1;
2667 /* Are control characters displayed as `^C'? */
2668 it
->ctl_arrow_p
= !NILP (BVAR (current_buffer
, ctl_arrow
));
2670 /* -1 means everything between a CR and the following line end
2671 is invisible. >0 means lines indented more than this value are
2673 it
->selective
= (INTEGERP (BVAR (current_buffer
, selective_display
))
2675 (-1, XINT (BVAR (current_buffer
, selective_display
)),
2677 : (!NILP (BVAR (current_buffer
, selective_display
))
2679 it
->selective_display_ellipsis_p
2680 = !NILP (BVAR (current_buffer
, selective_display_ellipses
));
2682 /* Display table to use. */
2683 it
->dp
= window_display_table (w
);
2685 /* Are multibyte characters enabled in current_buffer? */
2686 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
2688 /* If visible region is of non-zero length, set IT->region_beg_charpos
2689 and IT->region_end_charpos to the start and end of a visible region
2690 in window IT->w. Set both to -1 to indicate no region. */
2691 markpos
= markpos_of_region ();
2693 /* Maybe highlight only in selected window. */
2694 && (/* Either show region everywhere. */
2695 highlight_nonselected_windows
2696 /* Or show region in the selected window. */
2697 || w
== XWINDOW (selected_window
)
2698 /* Or show the region if we are in the mini-buffer and W is
2699 the window the mini-buffer refers to. */
2700 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2701 && WINDOWP (minibuf_selected_window
)
2702 && w
== XWINDOW (minibuf_selected_window
))))
2704 it
->region_beg_charpos
= min (PT
, markpos
);
2705 it
->region_end_charpos
= max (PT
, markpos
);
2708 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2710 /* Get the position at which the redisplay_end_trigger hook should
2711 be run, if it is to be run at all. */
2712 if (MARKERP (w
->redisplay_end_trigger
)
2713 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2714 it
->redisplay_end_trigger_charpos
2715 = marker_position (w
->redisplay_end_trigger
);
2716 else if (INTEGERP (w
->redisplay_end_trigger
))
2717 it
->redisplay_end_trigger_charpos
=
2718 clip_to_bounds (PTRDIFF_MIN
, XINT (w
->redisplay_end_trigger
), PTRDIFF_MAX
);
2720 it
->tab_width
= SANE_TAB_WIDTH (current_buffer
);
2722 /* Are lines in the display truncated? */
2723 if (base_face_id
!= DEFAULT_FACE_ID
2725 || (! WINDOW_FULL_WIDTH_P (it
->w
)
2726 && ((!NILP (Vtruncate_partial_width_windows
)
2727 && !INTEGERP (Vtruncate_partial_width_windows
))
2728 || (INTEGERP (Vtruncate_partial_width_windows
)
2729 && (WINDOW_TOTAL_COLS (it
->w
)
2730 < XINT (Vtruncate_partial_width_windows
))))))
2731 it
->line_wrap
= TRUNCATE
;
2732 else if (NILP (BVAR (current_buffer
, truncate_lines
)))
2733 it
->line_wrap
= NILP (BVAR (current_buffer
, word_wrap
))
2734 ? WINDOW_WRAP
: WORD_WRAP
;
2736 it
->line_wrap
= TRUNCATE
;
2738 /* Get dimensions of truncation and continuation glyphs. These are
2739 displayed as fringe bitmaps under X, but we need them for such
2740 frames when the fringes are turned off. But leave the dimensions
2741 zero for tooltip frames, as these glyphs look ugly there and also
2742 sabotage calculations of tooltip dimensions in x-show-tip. */
2743 #ifdef HAVE_WINDOW_SYSTEM
2744 if (!(FRAME_WINDOW_P (it
->f
)
2745 && FRAMEP (tip_frame
)
2746 && it
->f
== XFRAME (tip_frame
)))
2749 if (it
->line_wrap
== TRUNCATE
)
2751 /* We will need the truncation glyph. */
2752 eassert (it
->glyph_row
== NULL
);
2753 produce_special_glyphs (it
, IT_TRUNCATION
);
2754 it
->truncation_pixel_width
= it
->pixel_width
;
2758 /* We will need the continuation glyph. */
2759 eassert (it
->glyph_row
== NULL
);
2760 produce_special_glyphs (it
, IT_CONTINUATION
);
2761 it
->continuation_pixel_width
= it
->pixel_width
;
2765 /* Reset these values to zero because the produce_special_glyphs
2766 above has changed them. */
2767 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2768 it
->phys_ascent
= it
->phys_descent
= 0;
2770 /* Set this after getting the dimensions of truncation and
2771 continuation glyphs, so that we don't produce glyphs when calling
2772 produce_special_glyphs, above. */
2773 it
->glyph_row
= row
;
2774 it
->area
= TEXT_AREA
;
2776 /* Forget any previous info about this row being reversed. */
2778 it
->glyph_row
->reversed_p
= 0;
2780 /* Get the dimensions of the display area. The display area
2781 consists of the visible window area plus a horizontally scrolled
2782 part to the left of the window. All x-values are relative to the
2783 start of this total display area. */
2784 if (base_face_id
!= DEFAULT_FACE_ID
)
2786 /* Mode lines, menu bar in terminal frames. */
2787 it
->first_visible_x
= 0;
2788 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2792 it
->first_visible_x
=
2793 window_hscroll_limited (it
->w
, it
->f
) * FRAME_COLUMN_WIDTH (it
->f
);
2794 it
->last_visible_x
= (it
->first_visible_x
2795 + window_box_width (w
, TEXT_AREA
));
2797 /* If we truncate lines, leave room for the truncation glyph(s) at
2798 the right margin. Otherwise, leave room for the continuation
2799 glyph(s). Done only if the window has no fringes. Since we
2800 don't know at this point whether there will be any R2L lines in
2801 the window, we reserve space for truncation/continuation glyphs
2802 even if only one of the fringes is absent. */
2803 if (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0
2804 || (it
->bidi_p
&& WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0))
2806 if (it
->line_wrap
== TRUNCATE
)
2807 it
->last_visible_x
-= it
->truncation_pixel_width
;
2809 it
->last_visible_x
-= it
->continuation_pixel_width
;
2812 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2813 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2816 /* Leave room for a border glyph. */
2817 if (!FRAME_WINDOW_P (it
->f
)
2818 && !WINDOW_RIGHTMOST_P (it
->w
))
2819 it
->last_visible_x
-= 1;
2821 it
->last_visible_y
= window_text_bottom_y (w
);
2823 /* For mode lines and alike, arrange for the first glyph having a
2824 left box line if the face specifies a box. */
2825 if (base_face_id
!= DEFAULT_FACE_ID
)
2829 it
->face_id
= remapped_base_face_id
;
2831 /* If we have a boxed mode line, make the first character appear
2832 with a left box line. */
2833 face
= FACE_FROM_ID (it
->f
, remapped_base_face_id
);
2834 if (face
->box
!= FACE_NO_BOX
)
2835 it
->start_of_box_run_p
= 1;
2838 /* If a buffer position was specified, set the iterator there,
2839 getting overlays and face properties from that position. */
2840 if (charpos
>= BUF_BEG (current_buffer
))
2842 it
->end_charpos
= ZV
;
2843 IT_CHARPOS (*it
) = charpos
;
2845 /* We will rely on `reseat' to set this up properly, via
2846 handle_face_prop. */
2847 it
->face_id
= it
->base_face_id
;
2849 /* Compute byte position if not specified. */
2850 if (bytepos
< charpos
)
2851 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2853 IT_BYTEPOS (*it
) = bytepos
;
2855 it
->start
= it
->current
;
2856 /* Do we need to reorder bidirectional text? Not if this is a
2857 unibyte buffer: by definition, none of the single-byte
2858 characters are strong R2L, so no reordering is needed. And
2859 bidi.c doesn't support unibyte buffers anyway. Also, don't
2860 reorder while we are loading loadup.el, since the tables of
2861 character properties needed for reordering are not yet
2865 && !NILP (BVAR (current_buffer
, bidi_display_reordering
))
2868 /* If we are to reorder bidirectional text, init the bidi
2872 /* Note the paragraph direction that this buffer wants to
2874 if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2876 it
->paragraph_embedding
= L2R
;
2877 else if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2879 it
->paragraph_embedding
= R2L
;
2881 it
->paragraph_embedding
= NEUTRAL_DIR
;
2882 bidi_unshelve_cache (NULL
, 0);
2883 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
2887 /* Compute faces etc. */
2888 reseat (it
, it
->current
.pos
, 1);
2895 /* Initialize IT for the display of window W with window start POS. */
2898 start_display (struct it
*it
, struct window
*w
, struct text_pos pos
)
2900 struct glyph_row
*row
;
2901 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2903 row
= w
->desired_matrix
->rows
+ first_vpos
;
2904 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2905 it
->first_vpos
= first_vpos
;
2907 /* Don't reseat to previous visible line start if current start
2908 position is in a string or image. */
2909 if (it
->method
== GET_FROM_BUFFER
&& it
->line_wrap
!= TRUNCATE
)
2911 int start_at_line_beg_p
;
2912 int first_y
= it
->current_y
;
2914 /* If window start is not at a line start, skip forward to POS to
2915 get the correct continuation lines width. */
2916 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2917 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2918 if (!start_at_line_beg_p
)
2922 reseat_at_previous_visible_line_start (it
);
2923 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2925 new_x
= it
->current_x
+ it
->pixel_width
;
2927 /* If lines are continued, this line may end in the middle
2928 of a multi-glyph character (e.g. a control character
2929 displayed as \003, or in the middle of an overlay
2930 string). In this case move_it_to above will not have
2931 taken us to the start of the continuation line but to the
2932 end of the continued line. */
2933 if (it
->current_x
> 0
2934 && it
->line_wrap
!= TRUNCATE
/* Lines are continued. */
2935 && (/* And glyph doesn't fit on the line. */
2936 new_x
> it
->last_visible_x
2937 /* Or it fits exactly and we're on a window
2939 || (new_x
== it
->last_visible_x
2940 && FRAME_WINDOW_P (it
->f
)
2941 && ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
2942 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
2943 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
2945 if ((it
->current
.dpvec_index
>= 0
2946 || it
->current
.overlay_string_index
>= 0)
2947 /* If we are on a newline from a display vector or
2948 overlay string, then we are already at the end of
2949 a screen line; no need to go to the next line in
2950 that case, as this line is not really continued.
2951 (If we do go to the next line, C-e will not DTRT.) */
2954 set_iterator_to_next (it
, 1);
2955 move_it_in_display_line_to (it
, -1, -1, 0);
2958 it
->continuation_lines_width
+= it
->current_x
;
2960 /* If the character at POS is displayed via a display
2961 vector, move_it_to above stops at the final glyph of
2962 IT->dpvec. To make the caller redisplay that character
2963 again (a.k.a. start at POS), we need to reset the
2964 dpvec_index to the beginning of IT->dpvec. */
2965 else if (it
->current
.dpvec_index
>= 0)
2966 it
->current
.dpvec_index
= 0;
2968 /* We're starting a new display line, not affected by the
2969 height of the continued line, so clear the appropriate
2970 fields in the iterator structure. */
2971 it
->max_ascent
= it
->max_descent
= 0;
2972 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2974 it
->current_y
= first_y
;
2976 it
->current_x
= it
->hpos
= 0;
2982 /* Return 1 if POS is a position in ellipses displayed for invisible
2983 text. W is the window we display, for text property lookup. */
2986 in_ellipses_for_invisible_text_p (struct display_pos
*pos
, struct window
*w
)
2988 Lisp_Object prop
, window
;
2990 ptrdiff_t charpos
= CHARPOS (pos
->pos
);
2992 /* If POS specifies a position in a display vector, this might
2993 be for an ellipsis displayed for invisible text. We won't
2994 get the iterator set up for delivering that ellipsis unless
2995 we make sure that it gets aware of the invisible text. */
2996 if (pos
->dpvec_index
>= 0
2997 && pos
->overlay_string_index
< 0
2998 && CHARPOS (pos
->string_pos
) < 0
3000 && (XSETWINDOW (window
, w
),
3001 prop
= Fget_char_property (make_number (charpos
),
3002 Qinvisible
, window
),
3003 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
3005 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
3007 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
3014 /* Initialize IT for stepping through current_buffer in window W,
3015 starting at position POS that includes overlay string and display
3016 vector/ control character translation position information. Value
3017 is zero if there are overlay strings with newlines at POS. */
3020 init_from_display_pos (struct it
*it
, struct window
*w
, struct display_pos
*pos
)
3022 ptrdiff_t charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
3023 int i
, overlay_strings_with_newlines
= 0;
3025 /* If POS specifies a position in a display vector, this might
3026 be for an ellipsis displayed for invisible text. We won't
3027 get the iterator set up for delivering that ellipsis unless
3028 we make sure that it gets aware of the invisible text. */
3029 if (in_ellipses_for_invisible_text_p (pos
, w
))
3035 /* Keep in mind: the call to reseat in init_iterator skips invisible
3036 text, so we might end up at a position different from POS. This
3037 is only a problem when POS is a row start after a newline and an
3038 overlay starts there with an after-string, and the overlay has an
3039 invisible property. Since we don't skip invisible text in
3040 display_line and elsewhere immediately after consuming the
3041 newline before the row start, such a POS will not be in a string,
3042 but the call to init_iterator below will move us to the
3044 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
3046 /* This only scans the current chunk -- it should scan all chunks.
3047 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
3048 to 16 in 22.1 to make this a lesser problem. */
3049 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
3051 const char *s
= SSDATA (it
->overlay_strings
[i
]);
3052 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
3054 while (s
< e
&& *s
!= '\n')
3059 overlay_strings_with_newlines
= 1;
3064 /* If position is within an overlay string, set up IT to the right
3066 if (pos
->overlay_string_index
>= 0)
3070 /* If the first overlay string happens to have a `display'
3071 property for an image, the iterator will be set up for that
3072 image, and we have to undo that setup first before we can
3073 correct the overlay string index. */
3074 if (it
->method
== GET_FROM_IMAGE
)
3077 /* We already have the first chunk of overlay strings in
3078 IT->overlay_strings. Load more until the one for
3079 pos->overlay_string_index is in IT->overlay_strings. */
3080 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
3082 ptrdiff_t n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
3083 it
->current
.overlay_string_index
= 0;
3086 load_overlay_strings (it
, 0);
3087 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
3091 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
3092 relative_index
= (it
->current
.overlay_string_index
3093 % OVERLAY_STRING_CHUNK_SIZE
);
3094 it
->string
= it
->overlay_strings
[relative_index
];
3095 eassert (STRINGP (it
->string
));
3096 it
->current
.string_pos
= pos
->string_pos
;
3097 it
->method
= GET_FROM_STRING
;
3098 it
->end_charpos
= SCHARS (it
->string
);
3099 /* Set up the bidi iterator for this overlay string. */
3102 it
->bidi_it
.string
.lstring
= it
->string
;
3103 it
->bidi_it
.string
.s
= NULL
;
3104 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
3105 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
3106 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
3107 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
3108 bidi_init_it (IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
),
3109 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
3111 /* Synchronize the state of the bidi iterator with
3112 pos->string_pos. For any string position other than
3113 zero, this will be done automagically when we resume
3114 iteration over the string and get_visually_first_element
3115 is called. But if string_pos is zero, and the string is
3116 to be reordered for display, we need to resync manually,
3117 since it could be that the iteration state recorded in
3118 pos ended at string_pos of 0 moving backwards in string. */
3119 if (CHARPOS (pos
->string_pos
) == 0)
3121 get_visually_first_element (it
);
3122 if (IT_STRING_CHARPOS (*it
) != 0)
3125 eassert (it
->bidi_it
.charpos
< it
->bidi_it
.string
.schars
);
3126 bidi_move_to_visually_next (&it
->bidi_it
);
3127 } while (it
->bidi_it
.charpos
!= 0);
3129 eassert (IT_STRING_CHARPOS (*it
) == it
->bidi_it
.charpos
3130 && IT_STRING_BYTEPOS (*it
) == it
->bidi_it
.bytepos
);
3134 if (CHARPOS (pos
->string_pos
) >= 0)
3136 /* Recorded position is not in an overlay string, but in another
3137 string. This can only be a string from a `display' property.
3138 IT should already be filled with that string. */
3139 it
->current
.string_pos
= pos
->string_pos
;
3140 eassert (STRINGP (it
->string
));
3142 bidi_init_it (IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
),
3143 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
3146 /* Restore position in display vector translations, control
3147 character translations or ellipses. */
3148 if (pos
->dpvec_index
>= 0)
3150 if (it
->dpvec
== NULL
)
3151 get_next_display_element (it
);
3152 eassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
3153 it
->current
.dpvec_index
= pos
->dpvec_index
;
3157 return !overlay_strings_with_newlines
;
3161 /* Initialize IT for stepping through current_buffer in window W
3162 starting at ROW->start. */
3165 init_to_row_start (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3167 init_from_display_pos (it
, w
, &row
->start
);
3168 it
->start
= row
->start
;
3169 it
->continuation_lines_width
= row
->continuation_lines_width
;
3174 /* Initialize IT for stepping through current_buffer in window W
3175 starting in the line following ROW, i.e. starting at ROW->end.
3176 Value is zero if there are overlay strings with newlines at ROW's
3180 init_to_row_end (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3184 if (init_from_display_pos (it
, w
, &row
->end
))
3186 if (row
->continued_p
)
3187 it
->continuation_lines_width
3188 = row
->continuation_lines_width
+ row
->pixel_width
;
3199 /***********************************************************************
3201 ***********************************************************************/
3203 /* Called when IT reaches IT->stop_charpos. Handle text property and
3204 overlay changes. Set IT->stop_charpos to the next position where
3208 handle_stop (struct it
*it
)
3210 enum prop_handled handled
;
3211 int handle_overlay_change_p
;
3215 it
->current
.dpvec_index
= -1;
3216 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3217 it
->ignore_overlay_strings_at_pos_p
= 0;
3220 /* Use face of preceding text for ellipsis (if invisible) */
3221 if (it
->selective_display_ellipsis_p
)
3222 it
->saved_face_id
= it
->face_id
;
3226 handled
= HANDLED_NORMALLY
;
3228 /* Call text property handlers. */
3229 for (p
= it_props
; p
->handler
; ++p
)
3231 handled
= p
->handler (it
);
3233 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3235 else if (handled
== HANDLED_RETURN
)
3237 /* We still want to show before and after strings from
3238 overlays even if the actual buffer text is replaced. */
3239 if (!handle_overlay_change_p
3241 /* Don't call get_overlay_strings_1 if we already
3242 have overlay strings loaded, because doing so
3243 will load them again and push the iterator state
3244 onto the stack one more time, which is not
3245 expected by the rest of the code that processes
3247 || (it
->current
.overlay_string_index
< 0
3248 ? !get_overlay_strings_1 (it
, 0, 0)
3252 setup_for_ellipsis (it
, 0);
3253 /* When handling a display spec, we might load an
3254 empty string. In that case, discard it here. We
3255 used to discard it in handle_single_display_spec,
3256 but that causes get_overlay_strings_1, above, to
3257 ignore overlay strings that we must check. */
3258 if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3262 else if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3266 it
->ignore_overlay_strings_at_pos_p
= 1;
3267 it
->string_from_display_prop_p
= 0;
3268 it
->from_disp_prop_p
= 0;
3269 handle_overlay_change_p
= 0;
3271 handled
= HANDLED_RECOMPUTE_PROPS
;
3274 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3275 handle_overlay_change_p
= 0;
3278 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3280 /* Don't check for overlay strings below when set to deliver
3281 characters from a display vector. */
3282 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3283 handle_overlay_change_p
= 0;
3285 /* Handle overlay changes.
3286 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
3287 if it finds overlays. */
3288 if (handle_overlay_change_p
)
3289 handled
= handle_overlay_change (it
);
3294 setup_for_ellipsis (it
, 0);
3298 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3300 /* Determine where to stop next. */
3301 if (handled
== HANDLED_NORMALLY
)
3302 compute_stop_pos (it
);
3306 /* Compute IT->stop_charpos from text property and overlay change
3307 information for IT's current position. */
3310 compute_stop_pos (struct it
*it
)
3312 register INTERVAL iv
, next_iv
;
3313 Lisp_Object object
, limit
, position
;
3314 ptrdiff_t charpos
, bytepos
;
3316 if (STRINGP (it
->string
))
3318 /* Strings are usually short, so don't limit the search for
3320 it
->stop_charpos
= it
->end_charpos
;
3321 object
= it
->string
;
3323 charpos
= IT_STRING_CHARPOS (*it
);
3324 bytepos
= IT_STRING_BYTEPOS (*it
);
3330 /* If end_charpos is out of range for some reason, such as a
3331 misbehaving display function, rationalize it (Bug#5984). */
3332 if (it
->end_charpos
> ZV
)
3333 it
->end_charpos
= ZV
;
3334 it
->stop_charpos
= it
->end_charpos
;
3336 /* If next overlay change is in front of the current stop pos
3337 (which is IT->end_charpos), stop there. Note: value of
3338 next_overlay_change is point-max if no overlay change
3340 charpos
= IT_CHARPOS (*it
);
3341 bytepos
= IT_BYTEPOS (*it
);
3342 pos
= next_overlay_change (charpos
);
3343 if (pos
< it
->stop_charpos
)
3344 it
->stop_charpos
= pos
;
3346 /* If showing the region, we have to stop at the region
3347 start or end because the face might change there. */
3348 if (it
->region_beg_charpos
> 0)
3350 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
3351 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
3352 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
3353 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3356 /* Set up variables for computing the stop position from text
3357 property changes. */
3358 XSETBUFFER (object
, current_buffer
);
3359 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3362 /* Get the interval containing IT's position. Value is a null
3363 interval if there isn't such an interval. */
3364 position
= make_number (charpos
);
3365 iv
= validate_interval_range (object
, &position
, &position
, 0);
3368 Lisp_Object values_here
[LAST_PROP_IDX
];
3371 /* Get properties here. */
3372 for (p
= it_props
; p
->handler
; ++p
)
3373 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3375 /* Look for an interval following iv that has different
3377 for (next_iv
= next_interval (iv
);
3380 || XFASTINT (limit
) > next_iv
->position
));
3381 next_iv
= next_interval (next_iv
))
3383 for (p
= it_props
; p
->handler
; ++p
)
3385 Lisp_Object new_value
;
3387 new_value
= textget (next_iv
->plist
, *p
->name
);
3388 if (!EQ (values_here
[p
->idx
], new_value
))
3398 if (INTEGERP (limit
)
3399 && next_iv
->position
>= XFASTINT (limit
))
3400 /* No text property change up to limit. */
3401 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3403 /* Text properties change in next_iv. */
3404 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3408 if (it
->cmp_it
.id
< 0)
3410 ptrdiff_t stoppos
= it
->end_charpos
;
3412 if (it
->bidi_p
&& it
->bidi_it
.scan_dir
< 0)
3414 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
,
3415 stoppos
, it
->string
);
3418 eassert (STRINGP (it
->string
)
3419 || (it
->stop_charpos
>= BEGV
3420 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3424 /* Return the position of the next overlay change after POS in
3425 current_buffer. Value is point-max if no overlay change
3426 follows. This is like `next-overlay-change' but doesn't use
3430 next_overlay_change (ptrdiff_t pos
)
3432 ptrdiff_t i
, noverlays
;
3434 Lisp_Object
*overlays
;
3436 /* Get all overlays at the given position. */
3437 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3439 /* If any of these overlays ends before endpos,
3440 use its ending point instead. */
3441 for (i
= 0; i
< noverlays
; ++i
)
3446 oend
= OVERLAY_END (overlays
[i
]);
3447 oendpos
= OVERLAY_POSITION (oend
);
3448 endpos
= min (endpos
, oendpos
);
3454 /* How many characters forward to search for a display property or
3455 display string. Searching too far forward makes the bidi display
3456 sluggish, especially in small windows. */
3457 #define MAX_DISP_SCAN 250
3459 /* Return the character position of a display string at or after
3460 position specified by POSITION. If no display string exists at or
3461 after POSITION, return ZV. A display string is either an overlay
3462 with `display' property whose value is a string, or a `display'
3463 text property whose value is a string. STRING is data about the
3464 string to iterate; if STRING->lstring is nil, we are iterating a
3465 buffer. FRAME_WINDOW_P is non-zero when we are displaying a window
3466 on a GUI frame. DISP_PROP is set to zero if we searched
3467 MAX_DISP_SCAN characters forward without finding any display
3468 strings, non-zero otherwise. It is set to 2 if the display string
3469 uses any kind of `(space ...)' spec that will produce a stretch of
3470 white space in the text area. */
3472 compute_display_string_pos (struct text_pos
*position
,
3473 struct bidi_string_data
*string
,
3474 int frame_window_p
, int *disp_prop
)
3476 /* OBJECT = nil means current buffer. */
3477 Lisp_Object object
=
3478 (string
&& STRINGP (string
->lstring
)) ? string
->lstring
: Qnil
;
3479 Lisp_Object pos
, spec
, limpos
;
3480 int string_p
= (string
&& (STRINGP (string
->lstring
) || string
->s
));
3481 ptrdiff_t eob
= string_p
? string
->schars
: ZV
;
3482 ptrdiff_t begb
= string_p
? 0 : BEGV
;
3483 ptrdiff_t bufpos
, charpos
= CHARPOS (*position
);
3485 (charpos
< eob
- MAX_DISP_SCAN
) ? charpos
+ MAX_DISP_SCAN
: eob
;
3486 struct text_pos tpos
;
3492 /* We don't support display properties whose values are strings
3493 that have display string properties. */
3494 || string
->from_disp_str
3495 /* C strings cannot have display properties. */
3496 || (string
->s
&& !STRINGP (object
)))
3502 /* If the character at CHARPOS is where the display string begins,
3504 pos
= make_number (charpos
);
3505 if (STRINGP (object
))
3506 bufpos
= string
->bufpos
;
3510 if (!NILP (spec
= Fget_char_property (pos
, Qdisplay
, object
))
3512 || !EQ (Fget_char_property (make_number (charpos
- 1), Qdisplay
,
3515 && (rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
, bufpos
,
3523 /* Look forward for the first character with a `display' property
3524 that will replace the underlying text when displayed. */
3525 limpos
= make_number (lim
);
3527 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, limpos
);
3528 CHARPOS (tpos
) = XFASTINT (pos
);
3529 if (CHARPOS (tpos
) >= lim
)
3534 if (STRINGP (object
))
3535 BYTEPOS (tpos
) = string_char_to_byte (object
, CHARPOS (tpos
));
3537 BYTEPOS (tpos
) = CHAR_TO_BYTE (CHARPOS (tpos
));
3538 spec
= Fget_char_property (pos
, Qdisplay
, object
);
3539 if (!STRINGP (object
))
3540 bufpos
= CHARPOS (tpos
);
3541 } while (NILP (spec
)
3542 || !(rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
,
3543 bufpos
, frame_window_p
)));
3547 return CHARPOS (tpos
);
3550 /* Return the character position of the end of the display string that
3551 started at CHARPOS. If there's no display string at CHARPOS,
3552 return -1. A display string is either an overlay with `display'
3553 property whose value is a string or a `display' text property whose
3554 value is a string. */
3556 compute_display_string_end (ptrdiff_t charpos
, struct bidi_string_data
*string
)
3558 /* OBJECT = nil means current buffer. */
3559 Lisp_Object object
=
3560 (string
&& STRINGP (string
->lstring
)) ? string
->lstring
: Qnil
;
3561 Lisp_Object pos
= make_number (charpos
);
3563 (STRINGP (object
) || (string
&& string
->s
)) ? string
->schars
: ZV
;
3565 if (charpos
>= eob
|| (string
->s
&& !STRINGP (object
)))
3568 /* It could happen that the display property or overlay was removed
3569 since we found it in compute_display_string_pos above. One way
3570 this can happen is if JIT font-lock was called (through
3571 handle_fontified_prop), and jit-lock-functions remove text
3572 properties or overlays from the portion of buffer that includes
3573 CHARPOS. Muse mode is known to do that, for example. In this
3574 case, we return -1 to the caller, to signal that no display
3575 string is actually present at CHARPOS. See bidi_fetch_char for
3576 how this is handled.
3578 An alternative would be to never look for display properties past
3579 it->stop_charpos. But neither compute_display_string_pos nor
3580 bidi_fetch_char that calls it know or care where the next
3582 if (NILP (Fget_char_property (pos
, Qdisplay
, object
)))
3585 /* Look forward for the first character where the `display' property
3587 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, Qnil
);
3589 return XFASTINT (pos
);
3594 /***********************************************************************
3596 ***********************************************************************/
3598 /* Handle changes in the `fontified' property of the current buffer by
3599 calling hook functions from Qfontification_functions to fontify
3602 static enum prop_handled
3603 handle_fontified_prop (struct it
*it
)
3605 Lisp_Object prop
, pos
;
3606 enum prop_handled handled
= HANDLED_NORMALLY
;
3608 if (!NILP (Vmemory_full
))
3611 /* Get the value of the `fontified' property at IT's current buffer
3612 position. (The `fontified' property doesn't have a special
3613 meaning in strings.) If the value is nil, call functions from
3614 Qfontification_functions. */
3615 if (!STRINGP (it
->string
)
3617 && !NILP (Vfontification_functions
)
3618 && !NILP (Vrun_hooks
)
3619 && (pos
= make_number (IT_CHARPOS (*it
)),
3620 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3621 /* Ignore the special cased nil value always present at EOB since
3622 no amount of fontifying will be able to change it. */
3623 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3625 ptrdiff_t count
= SPECPDL_INDEX ();
3627 struct buffer
*obuf
= current_buffer
;
3628 int begv
= BEGV
, zv
= ZV
;
3629 int old_clip_changed
= current_buffer
->clip_changed
;
3631 val
= Vfontification_functions
;
3632 specbind (Qfontification_functions
, Qnil
);
3634 eassert (it
->end_charpos
== ZV
);
3636 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3637 safe_call1 (val
, pos
);
3640 Lisp_Object fns
, fn
;
3641 struct gcpro gcpro1
, gcpro2
;
3646 for (; CONSP (val
); val
= XCDR (val
))
3652 /* A value of t indicates this hook has a local
3653 binding; it means to run the global binding too.
3654 In a global value, t should not occur. If it
3655 does, we must ignore it to avoid an endless
3657 for (fns
= Fdefault_value (Qfontification_functions
);
3663 safe_call1 (fn
, pos
);
3667 safe_call1 (fn
, pos
);
3673 unbind_to (count
, Qnil
);
3675 /* Fontification functions routinely call `save-restriction'.
3676 Normally, this tags clip_changed, which can confuse redisplay
3677 (see discussion in Bug#6671). Since we don't perform any
3678 special handling of fontification changes in the case where
3679 `save-restriction' isn't called, there's no point doing so in
3680 this case either. So, if the buffer's restrictions are
3681 actually left unchanged, reset clip_changed. */
3682 if (obuf
== current_buffer
)
3684 if (begv
== BEGV
&& zv
== ZV
)
3685 current_buffer
->clip_changed
= old_clip_changed
;
3687 /* There isn't much we can reasonably do to protect against
3688 misbehaving fontification, but here's a fig leaf. */
3689 else if (BUFFER_LIVE_P (obuf
))
3690 set_buffer_internal_1 (obuf
);
3692 /* The fontification code may have added/removed text.
3693 It could do even a lot worse, but let's at least protect against
3694 the most obvious case where only the text past `pos' gets changed',
3695 as is/was done in grep.el where some escapes sequences are turned
3696 into face properties (bug#7876). */
3697 it
->end_charpos
= ZV
;
3699 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3700 something. This avoids an endless loop if they failed to
3701 fontify the text for which reason ever. */
3702 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3703 handled
= HANDLED_RECOMPUTE_PROPS
;
3711 /***********************************************************************
3713 ***********************************************************************/
3715 /* Set up iterator IT from face properties at its current position.
3716 Called from handle_stop. */
3718 static enum prop_handled
3719 handle_face_prop (struct it
*it
)
3722 ptrdiff_t next_stop
;
3724 if (!STRINGP (it
->string
))
3727 = face_at_buffer_position (it
->w
,
3729 it
->region_beg_charpos
,
3730 it
->region_end_charpos
,
3733 + TEXT_PROP_DISTANCE_LIMIT
),
3734 0, it
->base_face_id
);
3736 /* Is this a start of a run of characters with box face?
3737 Caveat: this can be called for a freshly initialized
3738 iterator; face_id is -1 in this case. We know that the new
3739 face will not change until limit, i.e. if the new face has a
3740 box, all characters up to limit will have one. But, as
3741 usual, we don't know whether limit is really the end. */
3742 if (new_face_id
!= it
->face_id
)
3744 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3745 /* If it->face_id is -1, old_face below will be NULL, see
3746 the definition of FACE_FROM_ID. This will happen if this
3747 is the initial call that gets the face. */
3748 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3750 /* If the value of face_id of the iterator is -1, we have to
3751 look in front of IT's position and see whether there is a
3752 face there that's different from new_face_id. */
3753 if (!old_face
&& IT_CHARPOS (*it
) > BEG
)
3755 int prev_face_id
= face_before_it_pos (it
);
3757 old_face
= FACE_FROM_ID (it
->f
, prev_face_id
);
3760 /* If the new face has a box, but the old face does not,
3761 this is the start of a run of characters with box face,
3762 i.e. this character has a shadow on the left side. */
3763 it
->start_of_box_run_p
= (new_face
->box
!= FACE_NO_BOX
3764 && (old_face
== NULL
|| !old_face
->box
));
3765 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3773 Lisp_Object from_overlay
3774 = (it
->current
.overlay_string_index
>= 0
3775 ? it
->string_overlays
[it
->current
.overlay_string_index
3776 % OVERLAY_STRING_CHUNK_SIZE
]
3779 /* See if we got to this string directly or indirectly from
3780 an overlay property. That includes the before-string or
3781 after-string of an overlay, strings in display properties
3782 provided by an overlay, their text properties, etc.
3784 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3785 if (! NILP (from_overlay
))
3786 for (i
= it
->sp
- 1; i
>= 0; i
--)
3788 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3790 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
3791 % OVERLAY_STRING_CHUNK_SIZE
];
3792 else if (! NILP (it
->stack
[i
].from_overlay
))
3793 from_overlay
= it
->stack
[i
].from_overlay
;
3795 if (!NILP (from_overlay
))
3799 if (! NILP (from_overlay
))
3801 bufpos
= IT_CHARPOS (*it
);
3802 /* For a string from an overlay, the base face depends
3803 only on text properties and ignores overlays. */
3805 = face_for_overlay_string (it
->w
,
3807 it
->region_beg_charpos
,
3808 it
->region_end_charpos
,
3811 + TEXT_PROP_DISTANCE_LIMIT
),
3819 /* For strings from a `display' property, use the face at
3820 IT's current buffer position as the base face to merge
3821 with, so that overlay strings appear in the same face as
3822 surrounding text, unless they specify their own
3824 base_face_id
= it
->string_from_prefix_prop_p
3826 : underlying_face_id (it
);
3829 new_face_id
= face_at_string_position (it
->w
,
3831 IT_STRING_CHARPOS (*it
),
3833 it
->region_beg_charpos
,
3834 it
->region_end_charpos
,
3838 /* Is this a start of a run of characters with box? Caveat:
3839 this can be called for a freshly allocated iterator; face_id
3840 is -1 is this case. We know that the new face will not
3841 change until the next check pos, i.e. if the new face has a
3842 box, all characters up to that position will have a
3843 box. But, as usual, we don't know whether that position
3844 is really the end. */
3845 if (new_face_id
!= it
->face_id
)
3847 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3848 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3850 /* If new face has a box but old face hasn't, this is the
3851 start of a run of characters with box, i.e. it has a
3852 shadow on the left side. */
3853 it
->start_of_box_run_p
3854 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3855 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3859 it
->face_id
= new_face_id
;
3860 return HANDLED_NORMALLY
;
3864 /* Return the ID of the face ``underlying'' IT's current position,
3865 which is in a string. If the iterator is associated with a
3866 buffer, return the face at IT's current buffer position.
3867 Otherwise, use the iterator's base_face_id. */
3870 underlying_face_id (struct it
*it
)
3872 int face_id
= it
->base_face_id
, i
;
3874 eassert (STRINGP (it
->string
));
3876 for (i
= it
->sp
- 1; i
>= 0; --i
)
3877 if (NILP (it
->stack
[i
].string
))
3878 face_id
= it
->stack
[i
].face_id
;
3884 /* Compute the face one character before or after the current position
3885 of IT, in the visual order. BEFORE_P non-zero means get the face
3886 in front (to the left in L2R paragraphs, to the right in R2L
3887 paragraphs) of IT's screen position. Value is the ID of the face. */
3890 face_before_or_after_it_pos (struct it
*it
, int before_p
)
3893 ptrdiff_t next_check_charpos
;
3895 void *it_copy_data
= NULL
;
3897 eassert (it
->s
== NULL
);
3899 if (STRINGP (it
->string
))
3901 ptrdiff_t bufpos
, charpos
;
3904 /* No face change past the end of the string (for the case
3905 we are padding with spaces). No face change before the
3907 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3908 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3913 /* Set charpos to the position before or after IT's current
3914 position, in the logical order, which in the non-bidi
3915 case is the same as the visual order. */
3917 charpos
= IT_STRING_CHARPOS (*it
) - 1;
3918 else if (it
->what
== IT_COMPOSITION
)
3919 /* For composition, we must check the character after the
3921 charpos
= IT_STRING_CHARPOS (*it
) + it
->cmp_it
.nchars
;
3923 charpos
= IT_STRING_CHARPOS (*it
) + 1;
3929 /* With bidi iteration, the character before the current
3930 in the visual order cannot be found by simple
3931 iteration, because "reverse" reordering is not
3932 supported. Instead, we need to use the move_it_*
3933 family of functions. */
3934 /* Ignore face changes before the first visible
3935 character on this display line. */
3936 if (it
->current_x
<= it
->first_visible_x
)
3938 SAVE_IT (it_copy
, *it
, it_copy_data
);
3939 /* Implementation note: Since move_it_in_display_line
3940 works in the iterator geometry, and thinks the first
3941 character is always the leftmost, even in R2L lines,
3942 we don't need to distinguish between the R2L and L2R
3944 move_it_in_display_line (&it_copy
, SCHARS (it_copy
.string
),
3945 it_copy
.current_x
- 1, MOVE_TO_X
);
3946 charpos
= IT_STRING_CHARPOS (it_copy
);
3947 RESTORE_IT (it
, it
, it_copy_data
);
3951 /* Set charpos to the string position of the character
3952 that comes after IT's current position in the visual
3954 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
3958 bidi_move_to_visually_next (&it_copy
.bidi_it
);
3960 charpos
= it_copy
.bidi_it
.charpos
;
3963 eassert (0 <= charpos
&& charpos
<= SCHARS (it
->string
));
3965 if (it
->current
.overlay_string_index
>= 0)
3966 bufpos
= IT_CHARPOS (*it
);
3970 base_face_id
= underlying_face_id (it
);
3972 /* Get the face for ASCII, or unibyte. */
3973 face_id
= face_at_string_position (it
->w
,
3977 it
->region_beg_charpos
,
3978 it
->region_end_charpos
,
3979 &next_check_charpos
,
3982 /* Correct the face for charsets different from ASCII. Do it
3983 for the multibyte case only. The face returned above is
3984 suitable for unibyte text if IT->string is unibyte. */
3985 if (STRING_MULTIBYTE (it
->string
))
3987 struct text_pos pos1
= string_pos (charpos
, it
->string
);
3988 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos1
);
3990 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3992 c
= string_char_and_length (p
, &len
);
3993 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, charpos
, it
->string
);
3998 struct text_pos pos
;
4000 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
4001 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
4004 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
4005 pos
= it
->current
.pos
;
4010 DEC_TEXT_POS (pos
, it
->multibyte_p
);
4013 if (it
->what
== IT_COMPOSITION
)
4015 /* For composition, we must check the position after
4017 pos
.charpos
+= it
->cmp_it
.nchars
;
4018 pos
.bytepos
+= it
->len
;
4021 INC_TEXT_POS (pos
, it
->multibyte_p
);
4028 /* With bidi iteration, the character before the current
4029 in the visual order cannot be found by simple
4030 iteration, because "reverse" reordering is not
4031 supported. Instead, we need to use the move_it_*
4032 family of functions. */
4033 /* Ignore face changes before the first visible
4034 character on this display line. */
4035 if (it
->current_x
<= it
->first_visible_x
)
4037 SAVE_IT (it_copy
, *it
, it_copy_data
);
4038 /* Implementation note: Since move_it_in_display_line
4039 works in the iterator geometry, and thinks the first
4040 character is always the leftmost, even in R2L lines,
4041 we don't need to distinguish between the R2L and L2R
4043 move_it_in_display_line (&it_copy
, ZV
,
4044 it_copy
.current_x
- 1, MOVE_TO_X
);
4045 pos
= it_copy
.current
.pos
;
4046 RESTORE_IT (it
, it
, it_copy_data
);
4050 /* Set charpos to the buffer position of the character
4051 that comes after IT's current position in the visual
4053 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
4057 bidi_move_to_visually_next (&it_copy
.bidi_it
);
4060 it_copy
.bidi_it
.charpos
, it_copy
.bidi_it
.bytepos
);
4063 eassert (BEGV
<= CHARPOS (pos
) && CHARPOS (pos
) <= ZV
);
4065 /* Determine face for CHARSET_ASCII, or unibyte. */
4066 face_id
= face_at_buffer_position (it
->w
,
4068 it
->region_beg_charpos
,
4069 it
->region_end_charpos
,
4070 &next_check_charpos
,
4073 /* Correct the face for charsets different from ASCII. Do it
4074 for the multibyte case only. The face returned above is
4075 suitable for unibyte text if current_buffer is unibyte. */
4076 if (it
->multibyte_p
)
4078 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
4079 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
4080 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
4089 /***********************************************************************
4091 ***********************************************************************/
4093 /* Set up iterator IT from invisible properties at its current
4094 position. Called from handle_stop. */
4096 static enum prop_handled
4097 handle_invisible_prop (struct it
*it
)
4099 enum prop_handled handled
= HANDLED_NORMALLY
;
4103 if (STRINGP (it
->string
))
4105 Lisp_Object end_charpos
, limit
, charpos
;
4107 /* Get the value of the invisible text property at the
4108 current position. Value will be nil if there is no such
4110 charpos
= make_number (IT_STRING_CHARPOS (*it
));
4111 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
4112 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4114 if (invis_p
&& IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
4116 /* Record whether we have to display an ellipsis for the
4118 int display_ellipsis_p
= (invis_p
== 2);
4119 ptrdiff_t len
, endpos
;
4121 handled
= HANDLED_RECOMPUTE_PROPS
;
4123 /* Get the position at which the next visible text can be
4124 found in IT->string, if any. */
4125 endpos
= len
= SCHARS (it
->string
);
4126 XSETINT (limit
, len
);
4129 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
4131 if (INTEGERP (end_charpos
))
4133 endpos
= XFASTINT (end_charpos
);
4134 prop
= Fget_text_property (end_charpos
, Qinvisible
, it
->string
);
4135 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4137 display_ellipsis_p
= 1;
4140 while (invis_p
&& endpos
< len
);
4142 if (display_ellipsis_p
)
4147 /* Text at END_CHARPOS is visible. Move IT there. */
4148 struct text_pos old
;
4151 old
= it
->current
.string_pos
;
4152 oldpos
= CHARPOS (old
);
4155 if (it
->bidi_it
.first_elt
4156 && it
->bidi_it
.charpos
< SCHARS (it
->string
))
4157 bidi_paragraph_init (it
->paragraph_embedding
,
4159 /* Bidi-iterate out of the invisible text. */
4162 bidi_move_to_visually_next (&it
->bidi_it
);
4164 while (oldpos
<= it
->bidi_it
.charpos
4165 && it
->bidi_it
.charpos
< endpos
);
4167 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4168 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4169 if (IT_CHARPOS (*it
) >= endpos
)
4170 it
->prev_stop
= endpos
;
4174 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
4175 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
4180 /* The rest of the string is invisible. If this is an
4181 overlay string, proceed with the next overlay string
4182 or whatever comes and return a character from there. */
4183 if (it
->current
.overlay_string_index
>= 0
4184 && !display_ellipsis_p
)
4186 next_overlay_string (it
);
4187 /* Don't check for overlay strings when we just
4188 finished processing them. */
4189 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
4193 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
4194 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
4201 ptrdiff_t newpos
, next_stop
, start_charpos
, tem
;
4202 Lisp_Object pos
, overlay
;
4204 /* First of all, is there invisible text at this position? */
4205 tem
= start_charpos
= IT_CHARPOS (*it
);
4206 pos
= make_number (tem
);
4207 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
4209 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4211 /* If we are on invisible text, skip over it. */
4212 if (invis_p
&& start_charpos
< it
->end_charpos
)
4214 /* Record whether we have to display an ellipsis for the
4216 int display_ellipsis_p
= invis_p
== 2;
4218 handled
= HANDLED_RECOMPUTE_PROPS
;
4220 /* Loop skipping over invisible text. The loop is left at
4221 ZV or with IT on the first char being visible again. */
4224 /* Try to skip some invisible text. Return value is the
4225 position reached which can be equal to where we start
4226 if there is nothing invisible there. This skips both
4227 over invisible text properties and overlays with
4228 invisible property. */
4229 newpos
= skip_invisible (tem
, &next_stop
, ZV
, it
->window
);
4231 /* If we skipped nothing at all we weren't at invisible
4232 text in the first place. If everything to the end of
4233 the buffer was skipped, end the loop. */
4234 if (newpos
== tem
|| newpos
>= ZV
)
4238 /* We skipped some characters but not necessarily
4239 all there are. Check if we ended up on visible
4240 text. Fget_char_property returns the property of
4241 the char before the given position, i.e. if we
4242 get invis_p = 0, this means that the char at
4243 newpos is visible. */
4244 pos
= make_number (newpos
);
4245 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
4246 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4249 /* If we ended up on invisible text, proceed to
4250 skip starting with next_stop. */
4254 /* If there are adjacent invisible texts, don't lose the
4255 second one's ellipsis. */
4257 display_ellipsis_p
= 1;
4261 /* The position newpos is now either ZV or on visible text. */
4264 ptrdiff_t bpos
= CHAR_TO_BYTE (newpos
);
4266 bpos
== ZV_BYTE
|| FETCH_BYTE (bpos
) == '\n';
4268 newpos
<= BEGV
|| FETCH_BYTE (bpos
- 1) == '\n';
4270 /* If the invisible text ends on a newline or on a
4271 character after a newline, we can avoid the costly,
4272 character by character, bidi iteration to NEWPOS, and
4273 instead simply reseat the iterator there. That's
4274 because all bidi reordering information is tossed at
4275 the newline. This is a big win for modes that hide
4276 complete lines, like Outline, Org, etc. */
4277 if (on_newline
|| after_newline
)
4279 struct text_pos tpos
;
4280 bidi_dir_t pdir
= it
->bidi_it
.paragraph_dir
;
4282 SET_TEXT_POS (tpos
, newpos
, bpos
);
4283 reseat_1 (it
, tpos
, 0);
4284 /* If we reseat on a newline/ZV, we need to prep the
4285 bidi iterator for advancing to the next character
4286 after the newline/EOB, keeping the current paragraph
4287 direction (so that PRODUCE_GLYPHS does TRT wrt
4288 prepending/appending glyphs to a glyph row). */
4291 it
->bidi_it
.first_elt
= 0;
4292 it
->bidi_it
.paragraph_dir
= pdir
;
4293 it
->bidi_it
.ch
= (bpos
== ZV_BYTE
) ? -1 : '\n';
4294 it
->bidi_it
.nchars
= 1;
4295 it
->bidi_it
.ch_len
= 1;
4298 else /* Must use the slow method. */
4300 /* With bidi iteration, the region of invisible text
4301 could start and/or end in the middle of a
4302 non-base embedding level. Therefore, we need to
4303 skip invisible text using the bidi iterator,
4304 starting at IT's current position, until we find
4305 ourselves outside of the invisible text.
4306 Skipping invisible text _after_ bidi iteration
4307 avoids affecting the visual order of the
4308 displayed text when invisible properties are
4309 added or removed. */
4310 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< ZV
)
4312 /* If we were `reseat'ed to a new paragraph,
4313 determine the paragraph base direction. We
4314 need to do it now because
4315 next_element_from_buffer may not have a
4316 chance to do it, if we are going to skip any
4317 text at the beginning, which resets the
4319 bidi_paragraph_init (it
->paragraph_embedding
,
4324 bidi_move_to_visually_next (&it
->bidi_it
);
4326 while (it
->stop_charpos
<= it
->bidi_it
.charpos
4327 && it
->bidi_it
.charpos
< newpos
);
4328 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4329 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4330 /* If we overstepped NEWPOS, record its position in
4331 the iterator, so that we skip invisible text if
4332 later the bidi iteration lands us in the
4333 invisible region again. */
4334 if (IT_CHARPOS (*it
) >= newpos
)
4335 it
->prev_stop
= newpos
;
4340 IT_CHARPOS (*it
) = newpos
;
4341 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
4344 /* If there are before-strings at the start of invisible
4345 text, and the text is invisible because of a text
4346 property, arrange to show before-strings because 20.x did
4347 it that way. (If the text is invisible because of an
4348 overlay property instead of a text property, this is
4349 already handled in the overlay code.) */
4351 && get_overlay_strings (it
, it
->stop_charpos
))
4353 handled
= HANDLED_RECOMPUTE_PROPS
;
4354 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
4356 else if (display_ellipsis_p
)
4358 /* Make sure that the glyphs of the ellipsis will get
4359 correct `charpos' values. If we would not update
4360 it->position here, the glyphs would belong to the
4361 last visible character _before_ the invisible
4362 text, which confuses `set_cursor_from_row'.
4364 We use the last invisible position instead of the
4365 first because this way the cursor is always drawn on
4366 the first "." of the ellipsis, whenever PT is inside
4367 the invisible text. Otherwise the cursor would be
4368 placed _after_ the ellipsis when the point is after the
4369 first invisible character. */
4370 if (!STRINGP (it
->object
))
4372 it
->position
.charpos
= newpos
- 1;
4373 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
4376 /* Let the ellipsis display before
4377 considering any properties of the following char.
4378 Fixes jasonr@gnu.org 01 Oct 07 bug. */
4379 handled
= HANDLED_RETURN
;
4388 /* Make iterator IT return `...' next.
4389 Replaces LEN characters from buffer. */
4392 setup_for_ellipsis (struct it
*it
, int len
)
4394 /* Use the display table definition for `...'. Invalid glyphs
4395 will be handled by the method returning elements from dpvec. */
4396 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
4398 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
4399 it
->dpvec
= v
->contents
;
4400 it
->dpend
= v
->contents
+ v
->header
.size
;
4404 /* Default `...'. */
4405 it
->dpvec
= default_invis_vector
;
4406 it
->dpend
= default_invis_vector
+ 3;
4409 it
->dpvec_char_len
= len
;
4410 it
->current
.dpvec_index
= 0;
4411 it
->dpvec_face_id
= -1;
4413 /* Remember the current face id in case glyphs specify faces.
4414 IT's face is restored in set_iterator_to_next.
4415 saved_face_id was set to preceding char's face in handle_stop. */
4416 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
4417 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
4419 it
->method
= GET_FROM_DISPLAY_VECTOR
;
4425 /***********************************************************************
4427 ***********************************************************************/
4429 /* Set up iterator IT from `display' property at its current position.
4430 Called from handle_stop.
4431 We return HANDLED_RETURN if some part of the display property
4432 overrides the display of the buffer text itself.
4433 Otherwise we return HANDLED_NORMALLY. */
4435 static enum prop_handled
4436 handle_display_prop (struct it
*it
)
4438 Lisp_Object propval
, object
, overlay
;
4439 struct text_pos
*position
;
4441 /* Nonzero if some property replaces the display of the text itself. */
4442 int display_replaced_p
= 0;
4444 if (STRINGP (it
->string
))
4446 object
= it
->string
;
4447 position
= &it
->current
.string_pos
;
4448 bufpos
= CHARPOS (it
->current
.pos
);
4452 XSETWINDOW (object
, it
->w
);
4453 position
= &it
->current
.pos
;
4454 bufpos
= CHARPOS (*position
);
4457 /* Reset those iterator values set from display property values. */
4458 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
4459 it
->space_width
= Qnil
;
4460 it
->font_height
= Qnil
;
4463 /* We don't support recursive `display' properties, i.e. string
4464 values that have a string `display' property, that have a string
4465 `display' property etc. */
4466 if (!it
->string_from_display_prop_p
)
4467 it
->area
= TEXT_AREA
;
4469 propval
= get_char_property_and_overlay (make_number (position
->charpos
),
4470 Qdisplay
, object
, &overlay
);
4472 return HANDLED_NORMALLY
;
4473 /* Now OVERLAY is the overlay that gave us this property, or nil
4474 if it was a text property. */
4476 if (!STRINGP (it
->string
))
4477 object
= it
->w
->buffer
;
4479 display_replaced_p
= handle_display_spec (it
, propval
, object
, overlay
,
4481 FRAME_WINDOW_P (it
->f
));
4483 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
4486 /* Subroutine of handle_display_prop. Returns non-zero if the display
4487 specification in SPEC is a replacing specification, i.e. it would
4488 replace the text covered by `display' property with something else,
4489 such as an image or a display string. If SPEC includes any kind or
4490 `(space ...) specification, the value is 2; this is used by
4491 compute_display_string_pos, which see.
4493 See handle_single_display_spec for documentation of arguments.
4494 frame_window_p is non-zero if the window being redisplayed is on a
4495 GUI frame; this argument is used only if IT is NULL, see below.
4497 IT can be NULL, if this is called by the bidi reordering code
4498 through compute_display_string_pos, which see. In that case, this
4499 function only examines SPEC, but does not otherwise "handle" it, in
4500 the sense that it doesn't set up members of IT from the display
4503 handle_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4504 Lisp_Object overlay
, struct text_pos
*position
,
4505 ptrdiff_t bufpos
, int frame_window_p
)
4507 int replacing_p
= 0;
4511 /* Simple specifications. */
4512 && !EQ (XCAR (spec
), Qimage
)
4513 && !EQ (XCAR (spec
), Qspace
)
4514 && !EQ (XCAR (spec
), Qwhen
)
4515 && !EQ (XCAR (spec
), Qslice
)
4516 && !EQ (XCAR (spec
), Qspace_width
)
4517 && !EQ (XCAR (spec
), Qheight
)
4518 && !EQ (XCAR (spec
), Qraise
)
4519 /* Marginal area specifications. */
4520 && !(CONSP (XCAR (spec
)) && EQ (XCAR (XCAR (spec
)), Qmargin
))
4521 && !EQ (XCAR (spec
), Qleft_fringe
)
4522 && !EQ (XCAR (spec
), Qright_fringe
)
4523 && !NILP (XCAR (spec
)))
4525 for (; CONSP (spec
); spec
= XCDR (spec
))
4527 if ((rv
= handle_single_display_spec (it
, XCAR (spec
), object
,
4528 overlay
, position
, bufpos
,
4529 replacing_p
, frame_window_p
)))
4532 /* If some text in a string is replaced, `position' no
4533 longer points to the position of `object'. */
4534 if (!it
|| STRINGP (object
))
4539 else if (VECTORP (spec
))
4542 for (i
= 0; i
< ASIZE (spec
); ++i
)
4543 if ((rv
= handle_single_display_spec (it
, AREF (spec
, i
), object
,
4544 overlay
, position
, bufpos
,
4545 replacing_p
, frame_window_p
)))
4548 /* If some text in a string is replaced, `position' no
4549 longer points to the position of `object'. */
4550 if (!it
|| STRINGP (object
))
4556 if ((rv
= handle_single_display_spec (it
, spec
, object
, overlay
,
4557 position
, bufpos
, 0,
4565 /* Value is the position of the end of the `display' property starting
4566 at START_POS in OBJECT. */
4568 static struct text_pos
4569 display_prop_end (struct it
*it
, Lisp_Object object
, struct text_pos start_pos
)
4572 struct text_pos end_pos
;
4574 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
4575 Qdisplay
, object
, Qnil
);
4576 CHARPOS (end_pos
) = XFASTINT (end
);
4577 if (STRINGP (object
))
4578 compute_string_pos (&end_pos
, start_pos
, it
->string
);
4580 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
4586 /* Set up IT from a single `display' property specification SPEC. OBJECT
4587 is the object in which the `display' property was found. *POSITION
4588 is the position in OBJECT at which the `display' property was found.
4589 BUFPOS is the buffer position of OBJECT (different from POSITION if
4590 OBJECT is not a buffer). DISPLAY_REPLACED_P non-zero means that we
4591 previously saw a display specification which already replaced text
4592 display with something else, for example an image; we ignore such
4593 properties after the first one has been processed.
4595 OVERLAY is the overlay this `display' property came from,
4596 or nil if it was a text property.
4598 If SPEC is a `space' or `image' specification, and in some other
4599 cases too, set *POSITION to the position where the `display'
4602 If IT is NULL, only examine the property specification in SPEC, but
4603 don't set up IT. In that case, FRAME_WINDOW_P non-zero means SPEC
4604 is intended to be displayed in a window on a GUI frame.
4606 Value is non-zero if something was found which replaces the display
4607 of buffer or string text. */
4610 handle_single_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4611 Lisp_Object overlay
, struct text_pos
*position
,
4612 ptrdiff_t bufpos
, int display_replaced_p
,
4616 Lisp_Object location
, value
;
4617 struct text_pos start_pos
= *position
;
4620 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
4621 If the result is non-nil, use VALUE instead of SPEC. */
4623 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4632 if (!NILP (form
) && !EQ (form
, Qt
))
4634 ptrdiff_t count
= SPECPDL_INDEX ();
4635 struct gcpro gcpro1
;
4637 /* Bind `object' to the object having the `display' property, a
4638 buffer or string. Bind `position' to the position in the
4639 object where the property was found, and `buffer-position'
4640 to the current position in the buffer. */
4643 XSETBUFFER (object
, current_buffer
);
4644 specbind (Qobject
, object
);
4645 specbind (Qposition
, make_number (CHARPOS (*position
)));
4646 specbind (Qbuffer_position
, make_number (bufpos
));
4648 form
= safe_eval (form
);
4650 unbind_to (count
, Qnil
);
4656 /* Handle `(height HEIGHT)' specifications. */
4658 && EQ (XCAR (spec
), Qheight
)
4659 && CONSP (XCDR (spec
)))
4663 if (!FRAME_WINDOW_P (it
->f
))
4666 it
->font_height
= XCAR (XCDR (spec
));
4667 if (!NILP (it
->font_height
))
4669 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4670 int new_height
= -1;
4672 if (CONSP (it
->font_height
)
4673 && (EQ (XCAR (it
->font_height
), Qplus
)
4674 || EQ (XCAR (it
->font_height
), Qminus
))
4675 && CONSP (XCDR (it
->font_height
))
4676 && RANGED_INTEGERP (0, XCAR (XCDR (it
->font_height
)), INT_MAX
))
4678 /* `(+ N)' or `(- N)' where N is an integer. */
4679 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4680 if (EQ (XCAR (it
->font_height
), Qplus
))
4682 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4684 else if (FUNCTIONP (it
->font_height
))
4686 /* Call function with current height as argument.
4687 Value is the new height. */
4689 height
= safe_call1 (it
->font_height
,
4690 face
->lface
[LFACE_HEIGHT_INDEX
]);
4691 if (NUMBERP (height
))
4692 new_height
= XFLOATINT (height
);
4694 else if (NUMBERP (it
->font_height
))
4696 /* Value is a multiple of the canonical char height. */
4699 f
= FACE_FROM_ID (it
->f
,
4700 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4701 new_height
= (XFLOATINT (it
->font_height
)
4702 * XINT (f
->lface
[LFACE_HEIGHT_INDEX
]));
4706 /* Evaluate IT->font_height with `height' bound to the
4707 current specified height to get the new height. */
4708 ptrdiff_t count
= SPECPDL_INDEX ();
4710 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4711 value
= safe_eval (it
->font_height
);
4712 unbind_to (count
, Qnil
);
4714 if (NUMBERP (value
))
4715 new_height
= XFLOATINT (value
);
4719 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4726 /* Handle `(space-width WIDTH)'. */
4728 && EQ (XCAR (spec
), Qspace_width
)
4729 && CONSP (XCDR (spec
)))
4733 if (!FRAME_WINDOW_P (it
->f
))
4736 value
= XCAR (XCDR (spec
));
4737 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4738 it
->space_width
= value
;
4744 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4746 && EQ (XCAR (spec
), Qslice
))
4752 if (!FRAME_WINDOW_P (it
->f
))
4755 if (tem
= XCDR (spec
), CONSP (tem
))
4757 it
->slice
.x
= XCAR (tem
);
4758 if (tem
= XCDR (tem
), CONSP (tem
))
4760 it
->slice
.y
= XCAR (tem
);
4761 if (tem
= XCDR (tem
), CONSP (tem
))
4763 it
->slice
.width
= XCAR (tem
);
4764 if (tem
= XCDR (tem
), CONSP (tem
))
4765 it
->slice
.height
= XCAR (tem
);
4774 /* Handle `(raise FACTOR)'. */
4776 && EQ (XCAR (spec
), Qraise
)
4777 && CONSP (XCDR (spec
)))
4781 if (!FRAME_WINDOW_P (it
->f
))
4784 #ifdef HAVE_WINDOW_SYSTEM
4785 value
= XCAR (XCDR (spec
));
4786 if (NUMBERP (value
))
4788 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4789 it
->voffset
= - (XFLOATINT (value
)
4790 * (FONT_HEIGHT (face
->font
)));
4792 #endif /* HAVE_WINDOW_SYSTEM */
4798 /* Don't handle the other kinds of display specifications
4799 inside a string that we got from a `display' property. */
4800 if (it
&& it
->string_from_display_prop_p
)
4803 /* Characters having this form of property are not displayed, so
4804 we have to find the end of the property. */
4807 start_pos
= *position
;
4808 *position
= display_prop_end (it
, object
, start_pos
);
4812 /* Stop the scan at that end position--we assume that all
4813 text properties change there. */
4815 it
->stop_charpos
= position
->charpos
;
4817 /* Handle `(left-fringe BITMAP [FACE])'
4818 and `(right-fringe BITMAP [FACE])'. */
4820 && (EQ (XCAR (spec
), Qleft_fringe
)
4821 || EQ (XCAR (spec
), Qright_fringe
))
4822 && CONSP (XCDR (spec
)))
4828 if (!FRAME_WINDOW_P (it
->f
))
4829 /* If we return here, POSITION has been advanced
4830 across the text with this property. */
4832 /* Synchronize the bidi iterator with POSITION. This is
4833 needed because we are not going to push the iterator
4834 on behalf of this display property, so there will be
4835 no pop_it call to do this synchronization for us. */
4838 it
->position
= *position
;
4839 iterate_out_of_display_property (it
);
4840 *position
= it
->position
;
4845 else if (!frame_window_p
)
4848 #ifdef HAVE_WINDOW_SYSTEM
4849 value
= XCAR (XCDR (spec
));
4850 if (!SYMBOLP (value
)
4851 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4852 /* If we return here, POSITION has been advanced
4853 across the text with this property. */
4855 if (it
&& it
->bidi_p
)
4857 it
->position
= *position
;
4858 iterate_out_of_display_property (it
);
4859 *position
= it
->position
;
4866 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);;
4868 if (CONSP (XCDR (XCDR (spec
))))
4870 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4871 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4877 /* Save current settings of IT so that we can restore them
4878 when we are finished with the glyph property value. */
4879 push_it (it
, position
);
4881 it
->area
= TEXT_AREA
;
4882 it
->what
= IT_IMAGE
;
4883 it
->image_id
= -1; /* no image */
4884 it
->position
= start_pos
;
4885 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4886 it
->method
= GET_FROM_IMAGE
;
4887 it
->from_overlay
= Qnil
;
4888 it
->face_id
= face_id
;
4889 it
->from_disp_prop_p
= 1;
4891 /* Say that we haven't consumed the characters with
4892 `display' property yet. The call to pop_it in
4893 set_iterator_to_next will clean this up. */
4894 *position
= start_pos
;
4896 if (EQ (XCAR (spec
), Qleft_fringe
))
4898 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4899 it
->left_user_fringe_face_id
= face_id
;
4903 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4904 it
->right_user_fringe_face_id
= face_id
;
4907 #endif /* HAVE_WINDOW_SYSTEM */
4911 /* Prepare to handle `((margin left-margin) ...)',
4912 `((margin right-margin) ...)' and `((margin nil) ...)'
4913 prefixes for display specifications. */
4914 location
= Qunbound
;
4915 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4919 value
= XCDR (spec
);
4921 value
= XCAR (value
);
4924 if (EQ (XCAR (tem
), Qmargin
)
4925 && (tem
= XCDR (tem
),
4926 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4928 || EQ (tem
, Qleft_margin
)
4929 || EQ (tem
, Qright_margin
))))
4933 if (EQ (location
, Qunbound
))
4939 /* After this point, VALUE is the property after any
4940 margin prefix has been stripped. It must be a string,
4941 an image specification, or `(space ...)'.
4943 LOCATION specifies where to display: `left-margin',
4944 `right-margin' or nil. */
4946 valid_p
= (STRINGP (value
)
4947 #ifdef HAVE_WINDOW_SYSTEM
4948 || ((it
? FRAME_WINDOW_P (it
->f
) : frame_window_p
)
4949 && valid_image_p (value
))
4950 #endif /* not HAVE_WINDOW_SYSTEM */
4951 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4953 if (valid_p
&& !display_replaced_p
)
4959 /* Callers need to know whether the display spec is any kind
4960 of `(space ...)' spec that is about to affect text-area
4962 if (CONSP (value
) && EQ (XCAR (value
), Qspace
) && NILP (location
))
4967 /* Save current settings of IT so that we can restore them
4968 when we are finished with the glyph property value. */
4969 push_it (it
, position
);
4970 it
->from_overlay
= overlay
;
4971 it
->from_disp_prop_p
= 1;
4973 if (NILP (location
))
4974 it
->area
= TEXT_AREA
;
4975 else if (EQ (location
, Qleft_margin
))
4976 it
->area
= LEFT_MARGIN_AREA
;
4978 it
->area
= RIGHT_MARGIN_AREA
;
4980 if (STRINGP (value
))
4983 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4984 it
->current
.overlay_string_index
= -1;
4985 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4986 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4987 it
->method
= GET_FROM_STRING
;
4988 it
->stop_charpos
= 0;
4990 it
->base_level_stop
= 0;
4991 it
->string_from_display_prop_p
= 1;
4992 /* Say that we haven't consumed the characters with
4993 `display' property yet. The call to pop_it in
4994 set_iterator_to_next will clean this up. */
4995 if (BUFFERP (object
))
4996 *position
= start_pos
;
4998 /* Force paragraph direction to be that of the parent
4999 object. If the parent object's paragraph direction is
5000 not yet determined, default to L2R. */
5001 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
5002 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5004 it
->paragraph_embedding
= L2R
;
5006 /* Set up the bidi iterator for this display string. */
5009 it
->bidi_it
.string
.lstring
= it
->string
;
5010 it
->bidi_it
.string
.s
= NULL
;
5011 it
->bidi_it
.string
.schars
= it
->end_charpos
;
5012 it
->bidi_it
.string
.bufpos
= bufpos
;
5013 it
->bidi_it
.string
.from_disp_str
= 1;
5014 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5015 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5018 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
5020 it
->method
= GET_FROM_STRETCH
;
5022 *position
= it
->position
= start_pos
;
5023 retval
= 1 + (it
->area
== TEXT_AREA
);
5025 #ifdef HAVE_WINDOW_SYSTEM
5028 it
->what
= IT_IMAGE
;
5029 it
->image_id
= lookup_image (it
->f
, value
);
5030 it
->position
= start_pos
;
5031 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
5032 it
->method
= GET_FROM_IMAGE
;
5034 /* Say that we haven't consumed the characters with
5035 `display' property yet. The call to pop_it in
5036 set_iterator_to_next will clean this up. */
5037 *position
= start_pos
;
5039 #endif /* HAVE_WINDOW_SYSTEM */
5044 /* Invalid property or property not supported. Restore
5045 POSITION to what it was before. */
5046 *position
= start_pos
;
5050 /* Check if PROP is a display property value whose text should be
5051 treated as intangible. OVERLAY is the overlay from which PROP
5052 came, or nil if it came from a text property. CHARPOS and BYTEPOS
5053 specify the buffer position covered by PROP. */
5056 display_prop_intangible_p (Lisp_Object prop
, Lisp_Object overlay
,
5057 ptrdiff_t charpos
, ptrdiff_t bytepos
)
5059 int frame_window_p
= FRAME_WINDOW_P (XFRAME (selected_frame
));
5060 struct text_pos position
;
5062 SET_TEXT_POS (position
, charpos
, bytepos
);
5063 return handle_display_spec (NULL
, prop
, Qnil
, overlay
,
5064 &position
, charpos
, frame_window_p
);
5068 /* Return 1 if PROP is a display sub-property value containing STRING.
5070 Implementation note: this and the following function are really
5071 special cases of handle_display_spec and
5072 handle_single_display_spec, and should ideally use the same code.
5073 Until they do, these two pairs must be consistent and must be
5074 modified in sync. */
5077 single_display_spec_string_p (Lisp_Object prop
, Lisp_Object string
)
5079 if (EQ (string
, prop
))
5082 /* Skip over `when FORM'. */
5083 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
5088 /* Actually, the condition following `when' should be eval'ed,
5089 like handle_single_display_spec does, and we should return
5090 zero if it evaluates to nil. However, this function is
5091 called only when the buffer was already displayed and some
5092 glyph in the glyph matrix was found to come from a display
5093 string. Therefore, the condition was already evaluated, and
5094 the result was non-nil, otherwise the display string wouldn't
5095 have been displayed and we would have never been called for
5096 this property. Thus, we can skip the evaluation and assume
5097 its result is non-nil. */
5102 /* Skip over `margin LOCATION'. */
5103 if (EQ (XCAR (prop
), Qmargin
))
5114 return EQ (prop
, string
) || (CONSP (prop
) && EQ (XCAR (prop
), string
));
5118 /* Return 1 if STRING appears in the `display' property PROP. */
5121 display_prop_string_p (Lisp_Object prop
, Lisp_Object string
)
5124 && !EQ (XCAR (prop
), Qwhen
)
5125 && !(CONSP (XCAR (prop
)) && EQ (Qmargin
, XCAR (XCAR (prop
)))))
5127 /* A list of sub-properties. */
5128 while (CONSP (prop
))
5130 if (single_display_spec_string_p (XCAR (prop
), string
))
5135 else if (VECTORP (prop
))
5137 /* A vector of sub-properties. */
5139 for (i
= 0; i
< ASIZE (prop
); ++i
)
5140 if (single_display_spec_string_p (AREF (prop
, i
), string
))
5144 return single_display_spec_string_p (prop
, string
);
5149 /* Look for STRING in overlays and text properties in the current
5150 buffer, between character positions FROM and TO (excluding TO).
5151 BACK_P non-zero means look back (in this case, TO is supposed to be
5153 Value is the first character position where STRING was found, or
5154 zero if it wasn't found before hitting TO.
5156 This function may only use code that doesn't eval because it is
5157 called asynchronously from note_mouse_highlight. */
5160 string_buffer_position_lim (Lisp_Object string
,
5161 ptrdiff_t from
, ptrdiff_t to
, int back_p
)
5163 Lisp_Object limit
, prop
, pos
;
5166 pos
= make_number (max (from
, BEGV
));
5168 if (!back_p
) /* looking forward */
5170 limit
= make_number (min (to
, ZV
));
5171 while (!found
&& !EQ (pos
, limit
))
5173 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5174 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5177 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
,
5181 else /* looking back */
5183 limit
= make_number (max (to
, BEGV
));
5184 while (!found
&& !EQ (pos
, limit
))
5186 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5187 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5190 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
5195 return found
? XINT (pos
) : 0;
5198 /* Determine which buffer position in current buffer STRING comes from.
5199 AROUND_CHARPOS is an approximate position where it could come from.
5200 Value is the buffer position or 0 if it couldn't be determined.
5202 This function is necessary because we don't record buffer positions
5203 in glyphs generated from strings (to keep struct glyph small).
5204 This function may only use code that doesn't eval because it is
5205 called asynchronously from note_mouse_highlight. */
5208 string_buffer_position (Lisp_Object string
, ptrdiff_t around_charpos
)
5210 const int MAX_DISTANCE
= 1000;
5211 ptrdiff_t found
= string_buffer_position_lim (string
, around_charpos
,
5212 around_charpos
+ MAX_DISTANCE
,
5216 found
= string_buffer_position_lim (string
, around_charpos
,
5217 around_charpos
- MAX_DISTANCE
, 1);
5223 /***********************************************************************
5224 `composition' property
5225 ***********************************************************************/
5227 /* Set up iterator IT from `composition' property at its current
5228 position. Called from handle_stop. */
5230 static enum prop_handled
5231 handle_composition_prop (struct it
*it
)
5233 Lisp_Object prop
, string
;
5234 ptrdiff_t pos
, pos_byte
, start
, end
;
5236 if (STRINGP (it
->string
))
5240 pos
= IT_STRING_CHARPOS (*it
);
5241 pos_byte
= IT_STRING_BYTEPOS (*it
);
5242 string
= it
->string
;
5243 s
= SDATA (string
) + pos_byte
;
5244 it
->c
= STRING_CHAR (s
);
5248 pos
= IT_CHARPOS (*it
);
5249 pos_byte
= IT_BYTEPOS (*it
);
5251 it
->c
= FETCH_CHAR (pos_byte
);
5254 /* If there's a valid composition and point is not inside of the
5255 composition (in the case that the composition is from the current
5256 buffer), draw a glyph composed from the composition components. */
5257 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
5258 && COMPOSITION_VALID_P (start
, end
, prop
)
5259 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
5262 /* As we can't handle this situation (perhaps font-lock added
5263 a new composition), we just return here hoping that next
5264 redisplay will detect this composition much earlier. */
5265 return HANDLED_NORMALLY
;
5268 if (STRINGP (it
->string
))
5269 pos_byte
= string_char_to_byte (it
->string
, start
);
5271 pos_byte
= CHAR_TO_BYTE (start
);
5273 it
->cmp_it
.id
= get_composition_id (start
, pos_byte
, end
- start
,
5276 if (it
->cmp_it
.id
>= 0)
5279 it
->cmp_it
.nchars
= COMPOSITION_LENGTH (prop
);
5280 it
->cmp_it
.nglyphs
= -1;
5284 return HANDLED_NORMALLY
;
5289 /***********************************************************************
5291 ***********************************************************************/
5293 /* The following structure is used to record overlay strings for
5294 later sorting in load_overlay_strings. */
5296 struct overlay_entry
5298 Lisp_Object overlay
;
5305 /* Set up iterator IT from overlay strings at its current position.
5306 Called from handle_stop. */
5308 static enum prop_handled
5309 handle_overlay_change (struct it
*it
)
5311 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
5312 return HANDLED_RECOMPUTE_PROPS
;
5314 return HANDLED_NORMALLY
;
5318 /* Set up the next overlay string for delivery by IT, if there is an
5319 overlay string to deliver. Called by set_iterator_to_next when the
5320 end of the current overlay string is reached. If there are more
5321 overlay strings to display, IT->string and
5322 IT->current.overlay_string_index are set appropriately here.
5323 Otherwise IT->string is set to nil. */
5326 next_overlay_string (struct it
*it
)
5328 ++it
->current
.overlay_string_index
;
5329 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
5331 /* No more overlay strings. Restore IT's settings to what
5332 they were before overlay strings were processed, and
5333 continue to deliver from current_buffer. */
5335 it
->ellipsis_p
= (it
->stack
[it
->sp
- 1].display_ellipsis_p
!= 0);
5338 || (NILP (it
->string
)
5339 && it
->method
== GET_FROM_BUFFER
5340 && it
->stop_charpos
>= BEGV
5341 && it
->stop_charpos
<= it
->end_charpos
));
5342 it
->current
.overlay_string_index
= -1;
5343 it
->n_overlay_strings
= 0;
5344 it
->overlay_strings_charpos
= -1;
5345 /* If there's an empty display string on the stack, pop the
5346 stack, to resync the bidi iterator with IT's position. Such
5347 empty strings are pushed onto the stack in
5348 get_overlay_strings_1. */
5349 if (it
->sp
> 0 && STRINGP (it
->string
) && !SCHARS (it
->string
))
5352 /* If we're at the end of the buffer, record that we have
5353 processed the overlay strings there already, so that
5354 next_element_from_buffer doesn't try it again. */
5355 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
5356 it
->overlay_strings_at_end_processed_p
= 1;
5360 /* There are more overlay strings to process. If
5361 IT->current.overlay_string_index has advanced to a position
5362 where we must load IT->overlay_strings with more strings, do
5363 it. We must load at the IT->overlay_strings_charpos where
5364 IT->n_overlay_strings was originally computed; when invisible
5365 text is present, this might not be IT_CHARPOS (Bug#7016). */
5366 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
5368 if (it
->current
.overlay_string_index
&& i
== 0)
5369 load_overlay_strings (it
, it
->overlay_strings_charpos
);
5371 /* Initialize IT to deliver display elements from the overlay
5373 it
->string
= it
->overlay_strings
[i
];
5374 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5375 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
5376 it
->method
= GET_FROM_STRING
;
5377 it
->stop_charpos
= 0;
5378 it
->end_charpos
= SCHARS (it
->string
);
5379 if (it
->cmp_it
.stop_pos
>= 0)
5380 it
->cmp_it
.stop_pos
= 0;
5382 it
->base_level_stop
= 0;
5384 /* Set up the bidi iterator for this overlay string. */
5387 it
->bidi_it
.string
.lstring
= it
->string
;
5388 it
->bidi_it
.string
.s
= NULL
;
5389 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5390 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
5391 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5392 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5393 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5401 /* Compare two overlay_entry structures E1 and E2. Used as a
5402 comparison function for qsort in load_overlay_strings. Overlay
5403 strings for the same position are sorted so that
5405 1. All after-strings come in front of before-strings, except
5406 when they come from the same overlay.
5408 2. Within after-strings, strings are sorted so that overlay strings
5409 from overlays with higher priorities come first.
5411 2. Within before-strings, strings are sorted so that overlay
5412 strings from overlays with higher priorities come last.
5414 Value is analogous to strcmp. */
5418 compare_overlay_entries (const void *e1
, const void *e2
)
5420 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
5421 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
5424 if (entry1
->after_string_p
!= entry2
->after_string_p
)
5426 /* Let after-strings appear in front of before-strings if
5427 they come from different overlays. */
5428 if (EQ (entry1
->overlay
, entry2
->overlay
))
5429 result
= entry1
->after_string_p
? 1 : -1;
5431 result
= entry1
->after_string_p
? -1 : 1;
5433 else if (entry1
->priority
!= entry2
->priority
)
5435 if (entry1
->after_string_p
)
5436 /* After-strings sorted in order of decreasing priority. */
5437 result
= entry2
->priority
< entry1
->priority
? -1 : 1;
5439 /* Before-strings sorted in order of increasing priority. */
5440 result
= entry1
->priority
< entry2
->priority
? -1 : 1;
5449 /* Load the vector IT->overlay_strings with overlay strings from IT's
5450 current buffer position, or from CHARPOS if that is > 0. Set
5451 IT->n_overlays to the total number of overlay strings found.
5453 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
5454 a time. On entry into load_overlay_strings,
5455 IT->current.overlay_string_index gives the number of overlay
5456 strings that have already been loaded by previous calls to this
5459 IT->add_overlay_start contains an additional overlay start
5460 position to consider for taking overlay strings from, if non-zero.
5461 This position comes into play when the overlay has an `invisible'
5462 property, and both before and after-strings. When we've skipped to
5463 the end of the overlay, because of its `invisible' property, we
5464 nevertheless want its before-string to appear.
5465 IT->add_overlay_start will contain the overlay start position
5468 Overlay strings are sorted so that after-string strings come in
5469 front of before-string strings. Within before and after-strings,
5470 strings are sorted by overlay priority. See also function
5471 compare_overlay_entries. */
5474 load_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5476 Lisp_Object overlay
, window
, str
, invisible
;
5477 struct Lisp_Overlay
*ov
;
5478 ptrdiff_t start
, end
;
5479 ptrdiff_t size
= 20;
5480 ptrdiff_t n
= 0, i
, j
;
5482 struct overlay_entry
*entries
= alloca (size
* sizeof *entries
);
5486 charpos
= IT_CHARPOS (*it
);
5488 /* Append the overlay string STRING of overlay OVERLAY to vector
5489 `entries' which has size `size' and currently contains `n'
5490 elements. AFTER_P non-zero means STRING is an after-string of
5492 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
5495 Lisp_Object priority; \
5499 struct overlay_entry *old = entries; \
5500 SAFE_NALLOCA (entries, 2, size); \
5501 memcpy (entries, old, size * sizeof *entries); \
5505 entries[n].string = (STRING); \
5506 entries[n].overlay = (OVERLAY); \
5507 priority = Foverlay_get ((OVERLAY), Qpriority); \
5508 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
5509 entries[n].after_string_p = (AFTER_P); \
5514 /* Process overlay before the overlay center. */
5515 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
5517 XSETMISC (overlay
, ov
);
5518 eassert (OVERLAYP (overlay
));
5519 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5520 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5525 /* Skip this overlay if it doesn't start or end at IT's current
5527 if (end
!= charpos
&& start
!= charpos
)
5530 /* Skip this overlay if it doesn't apply to IT->w. */
5531 window
= Foverlay_get (overlay
, Qwindow
);
5532 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5535 /* If the text ``under'' the overlay is invisible, both before-
5536 and after-strings from this overlay are visible; start and
5537 end position are indistinguishable. */
5538 invisible
= Foverlay_get (overlay
, Qinvisible
);
5539 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5541 /* If overlay has a non-empty before-string, record it. */
5542 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5543 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5545 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5547 /* If overlay has a non-empty after-string, record it. */
5548 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5549 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5551 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5554 /* Process overlays after the overlay center. */
5555 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
5557 XSETMISC (overlay
, ov
);
5558 eassert (OVERLAYP (overlay
));
5559 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5560 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5562 if (start
> charpos
)
5565 /* Skip this overlay if it doesn't start or end at IT's current
5567 if (end
!= charpos
&& start
!= charpos
)
5570 /* Skip this overlay if it doesn't apply to IT->w. */
5571 window
= Foverlay_get (overlay
, Qwindow
);
5572 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5575 /* If the text ``under'' the overlay is invisible, it has a zero
5576 dimension, and both before- and after-strings apply. */
5577 invisible
= Foverlay_get (overlay
, Qinvisible
);
5578 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5580 /* If overlay has a non-empty before-string, record it. */
5581 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5582 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5584 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5586 /* If overlay has a non-empty after-string, record it. */
5587 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5588 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5590 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5593 #undef RECORD_OVERLAY_STRING
5597 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
5599 /* Record number of overlay strings, and where we computed it. */
5600 it
->n_overlay_strings
= n
;
5601 it
->overlay_strings_charpos
= charpos
;
5603 /* IT->current.overlay_string_index is the number of overlay strings
5604 that have already been consumed by IT. Copy some of the
5605 remaining overlay strings to IT->overlay_strings. */
5607 j
= it
->current
.overlay_string_index
;
5608 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
5610 it
->overlay_strings
[i
] = entries
[j
].string
;
5611 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
5619 /* Get the first chunk of overlay strings at IT's current buffer
5620 position, or at CHARPOS if that is > 0. Value is non-zero if at
5621 least one overlay string was found. */
5624 get_overlay_strings_1 (struct it
*it
, ptrdiff_t charpos
, int compute_stop_p
)
5626 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5627 process. This fills IT->overlay_strings with strings, and sets
5628 IT->n_overlay_strings to the total number of strings to process.
5629 IT->pos.overlay_string_index has to be set temporarily to zero
5630 because load_overlay_strings needs this; it must be set to -1
5631 when no overlay strings are found because a zero value would
5632 indicate a position in the first overlay string. */
5633 it
->current
.overlay_string_index
= 0;
5634 load_overlay_strings (it
, charpos
);
5636 /* If we found overlay strings, set up IT to deliver display
5637 elements from the first one. Otherwise set up IT to deliver
5638 from current_buffer. */
5639 if (it
->n_overlay_strings
)
5641 /* Make sure we know settings in current_buffer, so that we can
5642 restore meaningful values when we're done with the overlay
5645 compute_stop_pos (it
);
5646 eassert (it
->face_id
>= 0);
5648 /* Save IT's settings. They are restored after all overlay
5649 strings have been processed. */
5650 eassert (!compute_stop_p
|| it
->sp
== 0);
5652 /* When called from handle_stop, there might be an empty display
5653 string loaded. In that case, don't bother saving it. But
5654 don't use this optimization with the bidi iterator, since we
5655 need the corresponding pop_it call to resync the bidi
5656 iterator's position with IT's position, after we are done
5657 with the overlay strings. (The corresponding call to pop_it
5658 in case of an empty display string is in
5659 next_overlay_string.) */
5661 && STRINGP (it
->string
) && !SCHARS (it
->string
)))
5664 /* Set up IT to deliver display elements from the first overlay
5666 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5667 it
->string
= it
->overlay_strings
[0];
5668 it
->from_overlay
= Qnil
;
5669 it
->stop_charpos
= 0;
5670 eassert (STRINGP (it
->string
));
5671 it
->end_charpos
= SCHARS (it
->string
);
5673 it
->base_level_stop
= 0;
5674 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5675 it
->method
= GET_FROM_STRING
;
5676 it
->from_disp_prop_p
= 0;
5678 /* Force paragraph direction to be that of the parent
5680 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
5681 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5683 it
->paragraph_embedding
= L2R
;
5685 /* Set up the bidi iterator for this overlay string. */
5688 ptrdiff_t pos
= (charpos
> 0 ? charpos
: IT_CHARPOS (*it
));
5690 it
->bidi_it
.string
.lstring
= it
->string
;
5691 it
->bidi_it
.string
.s
= NULL
;
5692 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5693 it
->bidi_it
.string
.bufpos
= pos
;
5694 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5695 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5696 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5701 it
->current
.overlay_string_index
= -1;
5706 get_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5709 it
->method
= GET_FROM_BUFFER
;
5711 (void) get_overlay_strings_1 (it
, charpos
, 1);
5715 /* Value is non-zero if we found at least one overlay string. */
5716 return STRINGP (it
->string
);
5721 /***********************************************************************
5722 Saving and restoring state
5723 ***********************************************************************/
5725 /* Save current settings of IT on IT->stack. Called, for example,
5726 before setting up IT for an overlay string, to be able to restore
5727 IT's settings to what they were after the overlay string has been
5728 processed. If POSITION is non-NULL, it is the position to save on
5729 the stack instead of IT->position. */
5732 push_it (struct it
*it
, struct text_pos
*position
)
5734 struct iterator_stack_entry
*p
;
5736 eassert (it
->sp
< IT_STACK_SIZE
);
5737 p
= it
->stack
+ it
->sp
;
5739 p
->stop_charpos
= it
->stop_charpos
;
5740 p
->prev_stop
= it
->prev_stop
;
5741 p
->base_level_stop
= it
->base_level_stop
;
5742 p
->cmp_it
= it
->cmp_it
;
5743 eassert (it
->face_id
>= 0);
5744 p
->face_id
= it
->face_id
;
5745 p
->string
= it
->string
;
5746 p
->method
= it
->method
;
5747 p
->from_overlay
= it
->from_overlay
;
5750 case GET_FROM_IMAGE
:
5751 p
->u
.image
.object
= it
->object
;
5752 p
->u
.image
.image_id
= it
->image_id
;
5753 p
->u
.image
.slice
= it
->slice
;
5755 case GET_FROM_STRETCH
:
5756 p
->u
.stretch
.object
= it
->object
;
5759 p
->position
= position
? *position
: it
->position
;
5760 p
->current
= it
->current
;
5761 p
->end_charpos
= it
->end_charpos
;
5762 p
->string_nchars
= it
->string_nchars
;
5764 p
->multibyte_p
= it
->multibyte_p
;
5765 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
5766 p
->space_width
= it
->space_width
;
5767 p
->font_height
= it
->font_height
;
5768 p
->voffset
= it
->voffset
;
5769 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5770 p
->string_from_prefix_prop_p
= it
->string_from_prefix_prop_p
;
5771 p
->display_ellipsis_p
= 0;
5772 p
->line_wrap
= it
->line_wrap
;
5773 p
->bidi_p
= it
->bidi_p
;
5774 p
->paragraph_embedding
= it
->paragraph_embedding
;
5775 p
->from_disp_prop_p
= it
->from_disp_prop_p
;
5778 /* Save the state of the bidi iterator as well. */
5780 bidi_push_it (&it
->bidi_it
);
5784 iterate_out_of_display_property (struct it
*it
)
5786 int buffer_p
= !STRINGP (it
->string
);
5787 ptrdiff_t eob
= (buffer_p
? ZV
: it
->end_charpos
);
5788 ptrdiff_t bob
= (buffer_p
? BEGV
: 0);
5790 eassert (eob
>= CHARPOS (it
->position
) && CHARPOS (it
->position
) >= bob
);
5792 /* Maybe initialize paragraph direction. If we are at the beginning
5793 of a new paragraph, next_element_from_buffer may not have a
5794 chance to do that. */
5795 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< eob
)
5796 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
5797 /* prev_stop can be zero, so check against BEGV as well. */
5798 while (it
->bidi_it
.charpos
>= bob
5799 && it
->prev_stop
<= it
->bidi_it
.charpos
5800 && it
->bidi_it
.charpos
< CHARPOS (it
->position
)
5801 && it
->bidi_it
.charpos
< eob
)
5802 bidi_move_to_visually_next (&it
->bidi_it
);
5803 /* Record the stop_pos we just crossed, for when we cross it
5805 if (it
->bidi_it
.charpos
> CHARPOS (it
->position
))
5806 it
->prev_stop
= CHARPOS (it
->position
);
5807 /* If we ended up not where pop_it put us, resync IT's
5808 positional members with the bidi iterator. */
5809 if (it
->bidi_it
.charpos
!= CHARPOS (it
->position
))
5810 SET_TEXT_POS (it
->position
, it
->bidi_it
.charpos
, it
->bidi_it
.bytepos
);
5812 it
->current
.pos
= it
->position
;
5814 it
->current
.string_pos
= it
->position
;
5817 /* Restore IT's settings from IT->stack. Called, for example, when no
5818 more overlay strings must be processed, and we return to delivering
5819 display elements from a buffer, or when the end of a string from a
5820 `display' property is reached and we return to delivering display
5821 elements from an overlay string, or from a buffer. */
5824 pop_it (struct it
*it
)
5826 struct iterator_stack_entry
*p
;
5827 int from_display_prop
= it
->from_disp_prop_p
;
5829 eassert (it
->sp
> 0);
5831 p
= it
->stack
+ it
->sp
;
5832 it
->stop_charpos
= p
->stop_charpos
;
5833 it
->prev_stop
= p
->prev_stop
;
5834 it
->base_level_stop
= p
->base_level_stop
;
5835 it
->cmp_it
= p
->cmp_it
;
5836 it
->face_id
= p
->face_id
;
5837 it
->current
= p
->current
;
5838 it
->position
= p
->position
;
5839 it
->string
= p
->string
;
5840 it
->from_overlay
= p
->from_overlay
;
5841 if (NILP (it
->string
))
5842 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5843 it
->method
= p
->method
;
5846 case GET_FROM_IMAGE
:
5847 it
->image_id
= p
->u
.image
.image_id
;
5848 it
->object
= p
->u
.image
.object
;
5849 it
->slice
= p
->u
.image
.slice
;
5851 case GET_FROM_STRETCH
:
5852 it
->object
= p
->u
.stretch
.object
;
5854 case GET_FROM_BUFFER
:
5855 it
->object
= it
->w
->buffer
;
5857 case GET_FROM_STRING
:
5858 it
->object
= it
->string
;
5860 case GET_FROM_DISPLAY_VECTOR
:
5862 it
->method
= GET_FROM_C_STRING
;
5863 else if (STRINGP (it
->string
))
5864 it
->method
= GET_FROM_STRING
;
5867 it
->method
= GET_FROM_BUFFER
;
5868 it
->object
= it
->w
->buffer
;
5871 it
->end_charpos
= p
->end_charpos
;
5872 it
->string_nchars
= p
->string_nchars
;
5874 it
->multibyte_p
= p
->multibyte_p
;
5875 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
5876 it
->space_width
= p
->space_width
;
5877 it
->font_height
= p
->font_height
;
5878 it
->voffset
= p
->voffset
;
5879 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5880 it
->string_from_prefix_prop_p
= p
->string_from_prefix_prop_p
;
5881 it
->line_wrap
= p
->line_wrap
;
5882 it
->bidi_p
= p
->bidi_p
;
5883 it
->paragraph_embedding
= p
->paragraph_embedding
;
5884 it
->from_disp_prop_p
= p
->from_disp_prop_p
;
5887 bidi_pop_it (&it
->bidi_it
);
5888 /* Bidi-iterate until we get out of the portion of text, if any,
5889 covered by a `display' text property or by an overlay with
5890 `display' property. (We cannot just jump there, because the
5891 internal coherency of the bidi iterator state can not be
5892 preserved across such jumps.) We also must determine the
5893 paragraph base direction if the overlay we just processed is
5894 at the beginning of a new paragraph. */
5895 if (from_display_prop
5896 && (it
->method
== GET_FROM_BUFFER
|| it
->method
== GET_FROM_STRING
))
5897 iterate_out_of_display_property (it
);
5899 eassert ((BUFFERP (it
->object
)
5900 && IT_CHARPOS (*it
) == it
->bidi_it
.charpos
5901 && IT_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
5902 || (STRINGP (it
->object
)
5903 && IT_STRING_CHARPOS (*it
) == it
->bidi_it
.charpos
5904 && IT_STRING_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
5905 || (CONSP (it
->object
) && it
->method
== GET_FROM_STRETCH
));
5911 /***********************************************************************
5913 ***********************************************************************/
5915 /* Set IT's current position to the previous line start. */
5918 back_to_previous_line_start (struct it
*it
)
5920 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
5921 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
5925 /* Move IT to the next line start.
5927 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5928 we skipped over part of the text (as opposed to moving the iterator
5929 continuously over the text). Otherwise, don't change the value
5932 If BIDI_IT_PREV is non-NULL, store into it the state of the bidi
5933 iterator on the newline, if it was found.
5935 Newlines may come from buffer text, overlay strings, or strings
5936 displayed via the `display' property. That's the reason we can't
5937 simply use find_next_newline_no_quit.
5939 Note that this function may not skip over invisible text that is so
5940 because of text properties and immediately follows a newline. If
5941 it would, function reseat_at_next_visible_line_start, when called
5942 from set_iterator_to_next, would effectively make invisible
5943 characters following a newline part of the wrong glyph row, which
5944 leads to wrong cursor motion. */
5947 forward_to_next_line_start (struct it
*it
, int *skipped_p
,
5948 struct bidi_it
*bidi_it_prev
)
5950 ptrdiff_t old_selective
;
5951 int newline_found_p
, n
;
5952 const int MAX_NEWLINE_DISTANCE
= 500;
5954 /* If already on a newline, just consume it to avoid unintended
5955 skipping over invisible text below. */
5956 if (it
->what
== IT_CHARACTER
5958 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
5960 if (it
->bidi_p
&& bidi_it_prev
)
5961 *bidi_it_prev
= it
->bidi_it
;
5962 set_iterator_to_next (it
, 0);
5967 /* Don't handle selective display in the following. It's (a)
5968 unnecessary because it's done by the caller, and (b) leads to an
5969 infinite recursion because next_element_from_ellipsis indirectly
5970 calls this function. */
5971 old_selective
= it
->selective
;
5974 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
5975 from buffer text. */
5976 for (n
= newline_found_p
= 0;
5977 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
5978 n
+= STRINGP (it
->string
) ? 0 : 1)
5980 if (!get_next_display_element (it
))
5982 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
5983 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
5984 *bidi_it_prev
= it
->bidi_it
;
5985 set_iterator_to_next (it
, 0);
5988 /* If we didn't find a newline near enough, see if we can use a
5990 if (!newline_found_p
)
5992 ptrdiff_t start
= IT_CHARPOS (*it
);
5993 ptrdiff_t limit
= find_next_newline_no_quit (start
, 1);
5996 eassert (!STRINGP (it
->string
));
5998 /* If there isn't any `display' property in sight, and no
5999 overlays, we can just use the position of the newline in
6001 if (it
->stop_charpos
>= limit
6002 || ((pos
= Fnext_single_property_change (make_number (start
),
6004 make_number (limit
)),
6006 && next_overlay_change (start
) == ZV
))
6010 IT_CHARPOS (*it
) = limit
;
6011 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
6015 struct bidi_it bprev
;
6017 /* Help bidi.c avoid expensive searches for display
6018 properties and overlays, by telling it that there are
6019 none up to `limit'. */
6020 if (it
->bidi_it
.disp_pos
< limit
)
6022 it
->bidi_it
.disp_pos
= limit
;
6023 it
->bidi_it
.disp_prop
= 0;
6026 bprev
= it
->bidi_it
;
6027 bidi_move_to_visually_next (&it
->bidi_it
);
6028 } while (it
->bidi_it
.charpos
!= limit
);
6029 IT_CHARPOS (*it
) = limit
;
6030 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6032 *bidi_it_prev
= bprev
;
6034 *skipped_p
= newline_found_p
= 1;
6038 while (get_next_display_element (it
)
6039 && !newline_found_p
)
6041 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
6042 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
6043 *bidi_it_prev
= it
->bidi_it
;
6044 set_iterator_to_next (it
, 0);
6049 it
->selective
= old_selective
;
6050 return newline_found_p
;
6054 /* Set IT's current position to the previous visible line start. Skip
6055 invisible text that is so either due to text properties or due to
6056 selective display. Caution: this does not change IT->current_x and
6060 back_to_previous_visible_line_start (struct it
*it
)
6062 while (IT_CHARPOS (*it
) > BEGV
)
6064 back_to_previous_line_start (it
);
6066 if (IT_CHARPOS (*it
) <= BEGV
)
6069 /* If selective > 0, then lines indented more than its value are
6071 if (it
->selective
> 0
6072 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6076 /* Check the newline before point for invisibility. */
6079 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
6080 Qinvisible
, it
->window
);
6081 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
6085 if (IT_CHARPOS (*it
) <= BEGV
)
6090 void *it2data
= NULL
;
6093 Lisp_Object val
, overlay
;
6095 SAVE_IT (it2
, *it
, it2data
);
6097 /* If newline is part of a composition, continue from start of composition */
6098 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
6099 && beg
< IT_CHARPOS (*it
))
6102 /* If newline is replaced by a display property, find start of overlay
6103 or interval and continue search from that point. */
6104 pos
= --IT_CHARPOS (it2
);
6107 bidi_unshelve_cache (NULL
, 0);
6108 it2
.string_from_display_prop_p
= 0;
6109 it2
.from_disp_prop_p
= 0;
6110 if (handle_display_prop (&it2
) == HANDLED_RETURN
6111 && !NILP (val
= get_char_property_and_overlay
6112 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
6113 && (OVERLAYP (overlay
)
6114 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
6115 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
6117 RESTORE_IT (it
, it
, it2data
);
6121 /* Newline is not replaced by anything -- so we are done. */
6122 RESTORE_IT (it
, it
, it2data
);
6128 IT_CHARPOS (*it
) = beg
;
6129 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
6133 it
->continuation_lines_width
= 0;
6135 eassert (IT_CHARPOS (*it
) >= BEGV
);
6136 eassert (IT_CHARPOS (*it
) == BEGV
6137 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6142 /* Reseat iterator IT at the previous visible line start. Skip
6143 invisible text that is so either due to text properties or due to
6144 selective display. At the end, update IT's overlay information,
6145 face information etc. */
6148 reseat_at_previous_visible_line_start (struct it
*it
)
6150 back_to_previous_visible_line_start (it
);
6151 reseat (it
, it
->current
.pos
, 1);
6156 /* Reseat iterator IT on the next visible line start in the current
6157 buffer. ON_NEWLINE_P non-zero means position IT on the newline
6158 preceding the line start. Skip over invisible text that is so
6159 because of selective display. Compute faces, overlays etc at the
6160 new position. Note that this function does not skip over text that
6161 is invisible because of text properties. */
6164 reseat_at_next_visible_line_start (struct it
*it
, int on_newline_p
)
6166 int newline_found_p
, skipped_p
= 0;
6167 struct bidi_it bidi_it_prev
;
6169 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6171 /* Skip over lines that are invisible because they are indented
6172 more than the value of IT->selective. */
6173 if (it
->selective
> 0)
6174 while (IT_CHARPOS (*it
) < ZV
6175 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6178 eassert (IT_BYTEPOS (*it
) == BEGV
6179 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6181 forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6184 /* Position on the newline if that's what's requested. */
6185 if (on_newline_p
&& newline_found_p
)
6187 if (STRINGP (it
->string
))
6189 if (IT_STRING_CHARPOS (*it
) > 0)
6193 --IT_STRING_CHARPOS (*it
);
6194 --IT_STRING_BYTEPOS (*it
);
6198 /* We need to restore the bidi iterator to the state
6199 it had on the newline, and resync the IT's
6200 position with that. */
6201 it
->bidi_it
= bidi_it_prev
;
6202 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6203 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6207 else if (IT_CHARPOS (*it
) > BEGV
)
6216 /* We need to restore the bidi iterator to the state it
6217 had on the newline and resync IT with that. */
6218 it
->bidi_it
= bidi_it_prev
;
6219 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6220 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6222 reseat (it
, it
->current
.pos
, 0);
6226 reseat (it
, it
->current
.pos
, 0);
6233 /***********************************************************************
6234 Changing an iterator's position
6235 ***********************************************************************/
6237 /* Change IT's current position to POS in current_buffer. If FORCE_P
6238 is non-zero, always check for text properties at the new position.
6239 Otherwise, text properties are only looked up if POS >=
6240 IT->check_charpos of a property. */
6243 reseat (struct it
*it
, struct text_pos pos
, int force_p
)
6245 ptrdiff_t original_pos
= IT_CHARPOS (*it
);
6247 reseat_1 (it
, pos
, 0);
6249 /* Determine where to check text properties. Avoid doing it
6250 where possible because text property lookup is very expensive. */
6252 || CHARPOS (pos
) > it
->stop_charpos
6253 || CHARPOS (pos
) < original_pos
)
6257 /* For bidi iteration, we need to prime prev_stop and
6258 base_level_stop with our best estimations. */
6259 /* Implementation note: Of course, POS is not necessarily a
6260 stop position, so assigning prev_pos to it is a lie; we
6261 should have called compute_stop_backwards. However, if
6262 the current buffer does not include any R2L characters,
6263 that call would be a waste of cycles, because the
6264 iterator will never move back, and thus never cross this
6265 "fake" stop position. So we delay that backward search
6266 until the time we really need it, in next_element_from_buffer. */
6267 if (CHARPOS (pos
) != it
->prev_stop
)
6268 it
->prev_stop
= CHARPOS (pos
);
6269 if (CHARPOS (pos
) < it
->base_level_stop
)
6270 it
->base_level_stop
= 0; /* meaning it's unknown */
6276 it
->prev_stop
= it
->base_level_stop
= 0;
6285 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
6286 IT->stop_pos to POS, also. */
6289 reseat_1 (struct it
*it
, struct text_pos pos
, int set_stop_p
)
6291 /* Don't call this function when scanning a C string. */
6292 eassert (it
->s
== NULL
);
6294 /* POS must be a reasonable value. */
6295 eassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
6297 it
->current
.pos
= it
->position
= pos
;
6298 it
->end_charpos
= ZV
;
6300 it
->current
.dpvec_index
= -1;
6301 it
->current
.overlay_string_index
= -1;
6302 IT_STRING_CHARPOS (*it
) = -1;
6303 IT_STRING_BYTEPOS (*it
) = -1;
6305 it
->method
= GET_FROM_BUFFER
;
6306 it
->object
= it
->w
->buffer
;
6307 it
->area
= TEXT_AREA
;
6308 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
6310 it
->string_from_display_prop_p
= 0;
6311 it
->string_from_prefix_prop_p
= 0;
6313 it
->from_disp_prop_p
= 0;
6314 it
->face_before_selective_p
= 0;
6317 bidi_init_it (IT_CHARPOS (*it
), IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6319 bidi_unshelve_cache (NULL
, 0);
6320 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6321 it
->bidi_it
.string
.s
= NULL
;
6322 it
->bidi_it
.string
.lstring
= Qnil
;
6323 it
->bidi_it
.string
.bufpos
= 0;
6324 it
->bidi_it
.string
.unibyte
= 0;
6329 it
->stop_charpos
= CHARPOS (pos
);
6330 it
->base_level_stop
= CHARPOS (pos
);
6332 /* This make the information stored in it->cmp_it invalidate. */
6337 /* Set up IT for displaying a string, starting at CHARPOS in window W.
6338 If S is non-null, it is a C string to iterate over. Otherwise,
6339 STRING gives a Lisp string to iterate over.
6341 If PRECISION > 0, don't return more then PRECISION number of
6342 characters from the string.
6344 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
6345 characters have been returned. FIELD_WIDTH < 0 means an infinite
6348 MULTIBYTE = 0 means disable processing of multibyte characters,
6349 MULTIBYTE > 0 means enable it,
6350 MULTIBYTE < 0 means use IT->multibyte_p.
6352 IT must be initialized via a prior call to init_iterator before
6353 calling this function. */
6356 reseat_to_string (struct it
*it
, const char *s
, Lisp_Object string
,
6357 ptrdiff_t charpos
, ptrdiff_t precision
, int field_width
,
6360 /* No region in strings. */
6361 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
6363 /* No text property checks performed by default, but see below. */
6364 it
->stop_charpos
= -1;
6366 /* Set iterator position and end position. */
6367 memset (&it
->current
, 0, sizeof it
->current
);
6368 it
->current
.overlay_string_index
= -1;
6369 it
->current
.dpvec_index
= -1;
6370 eassert (charpos
>= 0);
6372 /* If STRING is specified, use its multibyteness, otherwise use the
6373 setting of MULTIBYTE, if specified. */
6375 it
->multibyte_p
= multibyte
> 0;
6377 /* Bidirectional reordering of strings is controlled by the default
6378 value of bidi-display-reordering. Don't try to reorder while
6379 loading loadup.el, as the necessary character property tables are
6380 not yet available. */
6383 && !NILP (BVAR (&buffer_defaults
, bidi_display_reordering
));
6387 eassert (STRINGP (string
));
6388 it
->string
= string
;
6390 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
6391 it
->method
= GET_FROM_STRING
;
6392 it
->current
.string_pos
= string_pos (charpos
, string
);
6396 it
->bidi_it
.string
.lstring
= string
;
6397 it
->bidi_it
.string
.s
= NULL
;
6398 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6399 it
->bidi_it
.string
.bufpos
= 0;
6400 it
->bidi_it
.string
.from_disp_str
= 0;
6401 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6402 bidi_init_it (charpos
, IT_STRING_BYTEPOS (*it
),
6403 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
6408 it
->s
= (const unsigned char *) s
;
6411 /* Note that we use IT->current.pos, not it->current.string_pos,
6412 for displaying C strings. */
6413 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
6414 if (it
->multibyte_p
)
6416 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
6417 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
6421 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
6422 it
->end_charpos
= it
->string_nchars
= strlen (s
);
6427 it
->bidi_it
.string
.lstring
= Qnil
;
6428 it
->bidi_it
.string
.s
= (const unsigned char *) s
;
6429 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6430 it
->bidi_it
.string
.bufpos
= 0;
6431 it
->bidi_it
.string
.from_disp_str
= 0;
6432 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6433 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6436 it
->method
= GET_FROM_C_STRING
;
6439 /* PRECISION > 0 means don't return more than PRECISION characters
6441 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
6443 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
6445 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6448 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
6449 characters have been returned. FIELD_WIDTH == 0 means don't pad,
6450 FIELD_WIDTH < 0 means infinite field width. This is useful for
6451 padding with `-' at the end of a mode line. */
6452 if (field_width
< 0)
6453 field_width
= INFINITY
;
6454 /* Implementation note: We deliberately don't enlarge
6455 it->bidi_it.string.schars here to fit it->end_charpos, because
6456 the bidi iterator cannot produce characters out of thin air. */
6457 if (field_width
> it
->end_charpos
- charpos
)
6458 it
->end_charpos
= charpos
+ field_width
;
6460 /* Use the standard display table for displaying strings. */
6461 if (DISP_TABLE_P (Vstandard_display_table
))
6462 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
6464 it
->stop_charpos
= charpos
;
6465 it
->prev_stop
= charpos
;
6466 it
->base_level_stop
= 0;
6469 it
->bidi_it
.first_elt
= 1;
6470 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6471 it
->bidi_it
.disp_pos
= -1;
6473 if (s
== NULL
&& it
->multibyte_p
)
6475 ptrdiff_t endpos
= SCHARS (it
->string
);
6476 if (endpos
> it
->end_charpos
)
6477 endpos
= it
->end_charpos
;
6478 composition_compute_stop_pos (&it
->cmp_it
, charpos
, -1, endpos
,
6486 /***********************************************************************
6488 ***********************************************************************/
6490 /* Map enum it_method value to corresponding next_element_from_* function. */
6492 static int (* get_next_element
[NUM_IT_METHODS
]) (struct it
*it
) =
6494 next_element_from_buffer
,
6495 next_element_from_display_vector
,
6496 next_element_from_string
,
6497 next_element_from_c_string
,
6498 next_element_from_image
,
6499 next_element_from_stretch
6502 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
6505 /* Return 1 iff a character at CHARPOS (and BYTEPOS) is composed
6506 (possibly with the following characters). */
6508 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS,END_CHARPOS) \
6509 ((IT)->cmp_it.id >= 0 \
6510 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
6511 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
6512 END_CHARPOS, (IT)->w, \
6513 FACE_FROM_ID ((IT)->f, (IT)->face_id), \
6517 /* Lookup the char-table Vglyphless_char_display for character C (-1
6518 if we want information for no-font case), and return the display
6519 method symbol. By side-effect, update it->what and
6520 it->glyphless_method. This function is called from
6521 get_next_display_element for each character element, and from
6522 x_produce_glyphs when no suitable font was found. */
6525 lookup_glyphless_char_display (int c
, struct it
*it
)
6527 Lisp_Object glyphless_method
= Qnil
;
6529 if (CHAR_TABLE_P (Vglyphless_char_display
)
6530 && CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
)) >= 1)
6534 glyphless_method
= CHAR_TABLE_REF (Vglyphless_char_display
, c
);
6535 if (CONSP (glyphless_method
))
6536 glyphless_method
= FRAME_WINDOW_P (it
->f
)
6537 ? XCAR (glyphless_method
)
6538 : XCDR (glyphless_method
);
6541 glyphless_method
= XCHAR_TABLE (Vglyphless_char_display
)->extras
[0];
6545 if (NILP (glyphless_method
))
6548 /* The default is to display the character by a proper font. */
6550 /* The default for the no-font case is to display an empty box. */
6551 glyphless_method
= Qempty_box
;
6553 if (EQ (glyphless_method
, Qzero_width
))
6556 return glyphless_method
;
6557 /* This method can't be used for the no-font case. */
6558 glyphless_method
= Qempty_box
;
6560 if (EQ (glyphless_method
, Qthin_space
))
6561 it
->glyphless_method
= GLYPHLESS_DISPLAY_THIN_SPACE
;
6562 else if (EQ (glyphless_method
, Qempty_box
))
6563 it
->glyphless_method
= GLYPHLESS_DISPLAY_EMPTY_BOX
;
6564 else if (EQ (glyphless_method
, Qhex_code
))
6565 it
->glyphless_method
= GLYPHLESS_DISPLAY_HEX_CODE
;
6566 else if (STRINGP (glyphless_method
))
6567 it
->glyphless_method
= GLYPHLESS_DISPLAY_ACRONYM
;
6570 /* Invalid value. We use the default method. */
6571 glyphless_method
= Qnil
;
6574 it
->what
= IT_GLYPHLESS
;
6575 return glyphless_method
;
6578 /* Load IT's display element fields with information about the next
6579 display element from the current position of IT. Value is zero if
6580 end of buffer (or C string) is reached. */
6582 static struct frame
*last_escape_glyph_frame
= NULL
;
6583 static int last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
6584 static int last_escape_glyph_merged_face_id
= 0;
6586 struct frame
*last_glyphless_glyph_frame
= NULL
;
6587 int last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
6588 int last_glyphless_glyph_merged_face_id
= 0;
6591 get_next_display_element (struct it
*it
)
6593 /* Non-zero means that we found a display element. Zero means that
6594 we hit the end of what we iterate over. Performance note: the
6595 function pointer `method' used here turns out to be faster than
6596 using a sequence of if-statements. */
6600 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6602 if (it
->what
== IT_CHARACTER
)
6604 /* UAX#9, L4: "A character is depicted by a mirrored glyph if
6605 and only if (a) the resolved directionality of that character
6607 /* FIXME: Do we need an exception for characters from display
6609 if (it
->bidi_p
&& it
->bidi_it
.type
== STRONG_R
)
6610 it
->c
= bidi_mirror_char (it
->c
);
6611 /* Map via display table or translate control characters.
6612 IT->c, IT->len etc. have been set to the next character by
6613 the function call above. If we have a display table, and it
6614 contains an entry for IT->c, translate it. Don't do this if
6615 IT->c itself comes from a display table, otherwise we could
6616 end up in an infinite recursion. (An alternative could be to
6617 count the recursion depth of this function and signal an
6618 error when a certain maximum depth is reached.) Is it worth
6620 if (success_p
&& it
->dpvec
== NULL
)
6623 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
6624 int nonascii_space_p
= 0;
6625 int nonascii_hyphen_p
= 0;
6626 int c
= it
->c
; /* This is the character to display. */
6628 if (! it
->multibyte_p
&& ! ASCII_CHAR_P (c
))
6630 eassert (SINGLE_BYTE_CHAR_P (c
));
6631 if (unibyte_display_via_language_environment
)
6633 c
= DECODE_CHAR (unibyte
, c
);
6635 c
= BYTE8_TO_CHAR (it
->c
);
6638 c
= BYTE8_TO_CHAR (it
->c
);
6642 && (dv
= DISP_CHAR_VECTOR (it
->dp
, c
),
6645 struct Lisp_Vector
*v
= XVECTOR (dv
);
6647 /* Return the first character from the display table
6648 entry, if not empty. If empty, don't display the
6649 current character. */
6652 it
->dpvec_char_len
= it
->len
;
6653 it
->dpvec
= v
->contents
;
6654 it
->dpend
= v
->contents
+ v
->header
.size
;
6655 it
->current
.dpvec_index
= 0;
6656 it
->dpvec_face_id
= -1;
6657 it
->saved_face_id
= it
->face_id
;
6658 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6663 set_iterator_to_next (it
, 0);
6668 if (! NILP (lookup_glyphless_char_display (c
, it
)))
6670 if (it
->what
== IT_GLYPHLESS
)
6672 /* Don't display this character. */
6673 set_iterator_to_next (it
, 0);
6677 /* If `nobreak-char-display' is non-nil, we display
6678 non-ASCII spaces and hyphens specially. */
6679 if (! ASCII_CHAR_P (c
) && ! NILP (Vnobreak_char_display
))
6682 nonascii_space_p
= 1;
6683 else if (c
== 0xAD || c
== 0x2010 || c
== 0x2011)
6684 nonascii_hyphen_p
= 1;
6687 /* Translate control characters into `\003' or `^C' form.
6688 Control characters coming from a display table entry are
6689 currently not translated because we use IT->dpvec to hold
6690 the translation. This could easily be changed but I
6691 don't believe that it is worth doing.
6693 The characters handled by `nobreak-char-display' must be
6696 Non-printable characters and raw-byte characters are also
6697 translated to octal form. */
6698 if (((c
< ' ' || c
== 127) /* ASCII control chars */
6699 ? (it
->area
!= TEXT_AREA
6700 /* In mode line, treat \n, \t like other crl chars. */
6703 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
6704 || (c
!= '\n' && c
!= '\t'))
6706 || nonascii_hyphen_p
6708 || ! CHAR_PRINTABLE_P (c
))))
6710 /* C is a control character, non-ASCII space/hyphen,
6711 raw-byte, or a non-printable character which must be
6712 displayed either as '\003' or as `^C' where the '\\'
6713 and '^' can be defined in the display table. Fill
6714 IT->ctl_chars with glyphs for what we have to
6715 display. Then, set IT->dpvec to these glyphs. */
6722 /* Handle control characters with ^. */
6724 if (ASCII_CHAR_P (c
) && it
->ctl_arrow_p
)
6728 g
= '^'; /* default glyph for Control */
6729 /* Set IT->ctl_chars[0] to the glyph for `^'. */
6731 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
6733 g
= GLYPH_CODE_CHAR (gc
);
6734 lface_id
= GLYPH_CODE_FACE (gc
);
6738 face_id
= merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
);
6740 else if (it
->f
== last_escape_glyph_frame
6741 && it
->face_id
== last_escape_glyph_face_id
)
6743 face_id
= last_escape_glyph_merged_face_id
;
6747 /* Merge the escape-glyph face into the current face. */
6748 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
6750 last_escape_glyph_frame
= it
->f
;
6751 last_escape_glyph_face_id
= it
->face_id
;
6752 last_escape_glyph_merged_face_id
= face_id
;
6755 XSETINT (it
->ctl_chars
[0], g
);
6756 XSETINT (it
->ctl_chars
[1], c
^ 0100);
6758 goto display_control
;
6761 /* Handle non-ascii space in the mode where it only gets
6764 if (nonascii_space_p
&& EQ (Vnobreak_char_display
, Qt
))
6766 /* Merge `nobreak-space' into the current face. */
6767 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
6769 XSETINT (it
->ctl_chars
[0], ' ');
6771 goto display_control
;
6774 /* Handle sequences that start with the "escape glyph". */
6776 /* the default escape glyph is \. */
6777 escape_glyph
= '\\';
6780 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
6782 escape_glyph
= GLYPH_CODE_CHAR (gc
);
6783 lface_id
= GLYPH_CODE_FACE (gc
);
6787 /* The display table specified a face.
6788 Merge it into face_id and also into escape_glyph. */
6789 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6792 else if (it
->f
== last_escape_glyph_frame
6793 && it
->face_id
== last_escape_glyph_face_id
)
6795 face_id
= last_escape_glyph_merged_face_id
;
6799 /* Merge the escape-glyph face into the current face. */
6800 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
6802 last_escape_glyph_frame
= it
->f
;
6803 last_escape_glyph_face_id
= it
->face_id
;
6804 last_escape_glyph_merged_face_id
= face_id
;
6807 /* Draw non-ASCII hyphen with just highlighting: */
6809 if (nonascii_hyphen_p
&& EQ (Vnobreak_char_display
, Qt
))
6811 XSETINT (it
->ctl_chars
[0], '-');
6813 goto display_control
;
6816 /* Draw non-ASCII space/hyphen with escape glyph: */
6818 if (nonascii_space_p
|| nonascii_hyphen_p
)
6820 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6821 XSETINT (it
->ctl_chars
[1], nonascii_space_p
? ' ' : '-');
6823 goto display_control
;
6830 if (CHAR_BYTE8_P (c
))
6831 /* Display \200 instead of \17777600. */
6832 c
= CHAR_TO_BYTE8 (c
);
6833 len
= sprintf (str
, "%03o", c
);
6835 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6836 for (i
= 0; i
< len
; i
++)
6837 XSETINT (it
->ctl_chars
[i
+ 1], str
[i
]);
6842 /* Set up IT->dpvec and return first character from it. */
6843 it
->dpvec_char_len
= it
->len
;
6844 it
->dpvec
= it
->ctl_chars
;
6845 it
->dpend
= it
->dpvec
+ ctl_len
;
6846 it
->current
.dpvec_index
= 0;
6847 it
->dpvec_face_id
= face_id
;
6848 it
->saved_face_id
= it
->face_id
;
6849 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6853 it
->char_to_display
= c
;
6857 it
->char_to_display
= it
->c
;
6861 /* Adjust face id for a multibyte character. There are no multibyte
6862 character in unibyte text. */
6863 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
6866 && FRAME_WINDOW_P (it
->f
))
6868 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
6870 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
6872 /* Automatic composition with glyph-string. */
6873 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
6875 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
6879 ptrdiff_t pos
= (it
->s
? -1
6880 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
6881 : IT_CHARPOS (*it
));
6884 if (it
->what
== IT_CHARACTER
)
6885 c
= it
->char_to_display
;
6888 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
6892 for (i
= 0; i
< cmp
->glyph_len
; i
++)
6893 /* TAB in a composition means display glyphs with
6894 padding space on the left or right. */
6895 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
6898 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, pos
, it
->string
);
6903 /* Is this character the last one of a run of characters with
6904 box? If yes, set IT->end_of_box_run_p to 1. */
6908 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
6910 int face_id
= underlying_face_id (it
);
6911 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
6915 if (face
->box
== FACE_NO_BOX
)
6917 /* If the box comes from face properties in a
6918 display string, check faces in that string. */
6919 int string_face_id
= face_after_it_pos (it
);
6920 it
->end_of_box_run_p
6921 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
6924 /* Otherwise, the box comes from the underlying face.
6925 If this is the last string character displayed, check
6926 the next buffer location. */
6927 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
6928 && (it
->current
.overlay_string_index
6929 == it
->n_overlay_strings
- 1))
6933 struct text_pos pos
= it
->current
.pos
;
6934 INC_TEXT_POS (pos
, it
->multibyte_p
);
6936 next_face_id
= face_at_buffer_position
6937 (it
->w
, CHARPOS (pos
), it
->region_beg_charpos
,
6938 it
->region_end_charpos
, &ignore
,
6939 (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
), 0,
6941 it
->end_of_box_run_p
6942 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
6949 int face_id
= face_after_it_pos (it
);
6950 it
->end_of_box_run_p
6951 = (face_id
!= it
->face_id
6952 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
6955 /* If we reached the end of the object we've been iterating (e.g., a
6956 display string or an overlay string), and there's something on
6957 IT->stack, proceed with what's on the stack. It doesn't make
6958 sense to return zero if there's unprocessed stuff on the stack,
6959 because otherwise that stuff will never be displayed. */
6960 if (!success_p
&& it
->sp
> 0)
6962 set_iterator_to_next (it
, 0);
6963 success_p
= get_next_display_element (it
);
6966 /* Value is 0 if end of buffer or string reached. */
6971 /* Move IT to the next display element.
6973 RESEAT_P non-zero means if called on a newline in buffer text,
6974 skip to the next visible line start.
6976 Functions get_next_display_element and set_iterator_to_next are
6977 separate because I find this arrangement easier to handle than a
6978 get_next_display_element function that also increments IT's
6979 position. The way it is we can first look at an iterator's current
6980 display element, decide whether it fits on a line, and if it does,
6981 increment the iterator position. The other way around we probably
6982 would either need a flag indicating whether the iterator has to be
6983 incremented the next time, or we would have to implement a
6984 decrement position function which would not be easy to write. */
6987 set_iterator_to_next (struct it
*it
, int reseat_p
)
6989 /* Reset flags indicating start and end of a sequence of characters
6990 with box. Reset them at the start of this function because
6991 moving the iterator to a new position might set them. */
6992 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
6996 case GET_FROM_BUFFER
:
6997 /* The current display element of IT is a character from
6998 current_buffer. Advance in the buffer, and maybe skip over
6999 invisible lines that are so because of selective display. */
7000 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
7001 reseat_at_next_visible_line_start (it
, 0);
7002 else if (it
->cmp_it
.id
>= 0)
7004 /* We are currently getting glyphs from a composition. */
7009 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7010 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7011 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7013 it
->cmp_it
.from
= it
->cmp_it
.to
;
7018 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7020 it
->end_charpos
, Qnil
);
7023 else if (! it
->cmp_it
.reversed_p
)
7025 /* Composition created while scanning forward. */
7026 /* Update IT's char/byte positions to point to the first
7027 character of the next grapheme cluster, or to the
7028 character visually after the current composition. */
7029 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7030 bidi_move_to_visually_next (&it
->bidi_it
);
7031 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7032 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7034 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7036 /* Proceed to the next grapheme cluster. */
7037 it
->cmp_it
.from
= it
->cmp_it
.to
;
7041 /* No more grapheme clusters in this composition.
7042 Find the next stop position. */
7043 ptrdiff_t stop
= it
->end_charpos
;
7044 if (it
->bidi_it
.scan_dir
< 0)
7045 /* Now we are scanning backward and don't know
7048 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7049 IT_BYTEPOS (*it
), stop
, Qnil
);
7054 /* Composition created while scanning backward. */
7055 /* Update IT's char/byte positions to point to the last
7056 character of the previous grapheme cluster, or the
7057 character visually after the current composition. */
7058 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7059 bidi_move_to_visually_next (&it
->bidi_it
);
7060 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7061 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7062 if (it
->cmp_it
.from
> 0)
7064 /* Proceed to the previous grapheme cluster. */
7065 it
->cmp_it
.to
= it
->cmp_it
.from
;
7069 /* No more grapheme clusters in this composition.
7070 Find the next stop position. */
7071 ptrdiff_t stop
= it
->end_charpos
;
7072 if (it
->bidi_it
.scan_dir
< 0)
7073 /* Now we are scanning backward and don't know
7076 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7077 IT_BYTEPOS (*it
), stop
, Qnil
);
7083 eassert (it
->len
!= 0);
7087 IT_BYTEPOS (*it
) += it
->len
;
7088 IT_CHARPOS (*it
) += 1;
7092 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7093 /* If this is a new paragraph, determine its base
7094 direction (a.k.a. its base embedding level). */
7095 if (it
->bidi_it
.new_paragraph
)
7096 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
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
;
7100 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7102 /* As the scan direction was changed, we must
7103 re-compute the stop position for composition. */
7104 ptrdiff_t stop
= it
->end_charpos
;
7105 if (it
->bidi_it
.scan_dir
< 0)
7107 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7108 IT_BYTEPOS (*it
), stop
, Qnil
);
7111 eassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
7115 case GET_FROM_C_STRING
:
7116 /* Current display element of IT is from a C string. */
7118 /* If the string position is beyond string's end, it means
7119 next_element_from_c_string is padding the string with
7120 blanks, in which case we bypass the bidi iterator,
7121 because it cannot deal with such virtual characters. */
7122 || IT_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7124 IT_BYTEPOS (*it
) += it
->len
;
7125 IT_CHARPOS (*it
) += 1;
7129 bidi_move_to_visually_next (&it
->bidi_it
);
7130 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7131 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7135 case GET_FROM_DISPLAY_VECTOR
:
7136 /* Current display element of IT is from a display table entry.
7137 Advance in the display table definition. Reset it to null if
7138 end reached, and continue with characters from buffers/
7140 ++it
->current
.dpvec_index
;
7142 /* Restore face of the iterator to what they were before the
7143 display vector entry (these entries may contain faces). */
7144 it
->face_id
= it
->saved_face_id
;
7146 if (it
->dpvec
+ it
->current
.dpvec_index
>= it
->dpend
)
7148 int recheck_faces
= it
->ellipsis_p
;
7151 it
->method
= GET_FROM_C_STRING
;
7152 else if (STRINGP (it
->string
))
7153 it
->method
= GET_FROM_STRING
;
7156 it
->method
= GET_FROM_BUFFER
;
7157 it
->object
= it
->w
->buffer
;
7161 it
->current
.dpvec_index
= -1;
7163 /* Skip over characters which were displayed via IT->dpvec. */
7164 if (it
->dpvec_char_len
< 0)
7165 reseat_at_next_visible_line_start (it
, 1);
7166 else if (it
->dpvec_char_len
> 0)
7168 if (it
->method
== GET_FROM_STRING
7169 && it
->n_overlay_strings
> 0)
7170 it
->ignore_overlay_strings_at_pos_p
= 1;
7171 it
->len
= it
->dpvec_char_len
;
7172 set_iterator_to_next (it
, reseat_p
);
7175 /* Maybe recheck faces after display vector */
7177 it
->stop_charpos
= IT_CHARPOS (*it
);
7181 case GET_FROM_STRING
:
7182 /* Current display element is a character from a Lisp string. */
7183 eassert (it
->s
== NULL
&& STRINGP (it
->string
));
7184 /* Don't advance past string end. These conditions are true
7185 when set_iterator_to_next is called at the end of
7186 get_next_display_element, in which case the Lisp string is
7187 already exhausted, and all we want is pop the iterator
7189 if (it
->current
.overlay_string_index
>= 0)
7191 /* This is an overlay string, so there's no padding with
7192 spaces, and the number of characters in the string is
7193 where the string ends. */
7194 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7195 goto consider_string_end
;
7199 /* Not an overlay string. There could be padding, so test
7200 against it->end_charpos . */
7201 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7202 goto consider_string_end
;
7204 if (it
->cmp_it
.id
>= 0)
7210 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7211 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7212 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7213 it
->cmp_it
.from
= it
->cmp_it
.to
;
7217 composition_compute_stop_pos (&it
->cmp_it
,
7218 IT_STRING_CHARPOS (*it
),
7219 IT_STRING_BYTEPOS (*it
),
7220 it
->end_charpos
, it
->string
);
7223 else if (! it
->cmp_it
.reversed_p
)
7225 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7226 bidi_move_to_visually_next (&it
->bidi_it
);
7227 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7228 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7230 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7231 it
->cmp_it
.from
= it
->cmp_it
.to
;
7234 ptrdiff_t stop
= it
->end_charpos
;
7235 if (it
->bidi_it
.scan_dir
< 0)
7237 composition_compute_stop_pos (&it
->cmp_it
,
7238 IT_STRING_CHARPOS (*it
),
7239 IT_STRING_BYTEPOS (*it
), stop
,
7245 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7246 bidi_move_to_visually_next (&it
->bidi_it
);
7247 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7248 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7249 if (it
->cmp_it
.from
> 0)
7250 it
->cmp_it
.to
= it
->cmp_it
.from
;
7253 ptrdiff_t stop
= it
->end_charpos
;
7254 if (it
->bidi_it
.scan_dir
< 0)
7256 composition_compute_stop_pos (&it
->cmp_it
,
7257 IT_STRING_CHARPOS (*it
),
7258 IT_STRING_BYTEPOS (*it
), stop
,
7266 /* If the string position is beyond string's end, it
7267 means next_element_from_string is padding the string
7268 with blanks, in which case we bypass the bidi
7269 iterator, because it cannot deal with such virtual
7271 || IT_STRING_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7273 IT_STRING_BYTEPOS (*it
) += it
->len
;
7274 IT_STRING_CHARPOS (*it
) += 1;
7278 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7280 bidi_move_to_visually_next (&it
->bidi_it
);
7281 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7282 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7283 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7285 ptrdiff_t stop
= it
->end_charpos
;
7287 if (it
->bidi_it
.scan_dir
< 0)
7289 composition_compute_stop_pos (&it
->cmp_it
,
7290 IT_STRING_CHARPOS (*it
),
7291 IT_STRING_BYTEPOS (*it
), stop
,
7297 consider_string_end
:
7299 if (it
->current
.overlay_string_index
>= 0)
7301 /* IT->string is an overlay string. Advance to the
7302 next, if there is one. */
7303 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7306 next_overlay_string (it
);
7308 setup_for_ellipsis (it
, 0);
7313 /* IT->string is not an overlay string. If we reached
7314 its end, and there is something on IT->stack, proceed
7315 with what is on the stack. This can be either another
7316 string, this time an overlay string, or a buffer. */
7317 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
7321 if (it
->method
== GET_FROM_STRING
)
7322 goto consider_string_end
;
7327 case GET_FROM_IMAGE
:
7328 case GET_FROM_STRETCH
:
7329 /* The position etc with which we have to proceed are on
7330 the stack. The position may be at the end of a string,
7331 if the `display' property takes up the whole string. */
7332 eassert (it
->sp
> 0);
7334 if (it
->method
== GET_FROM_STRING
)
7335 goto consider_string_end
;
7339 /* There are no other methods defined, so this should be a bug. */
7343 eassert (it
->method
!= GET_FROM_STRING
7344 || (STRINGP (it
->string
)
7345 && IT_STRING_CHARPOS (*it
) >= 0));
7348 /* Load IT's display element fields with information about the next
7349 display element which comes from a display table entry or from the
7350 result of translating a control character to one of the forms `^C'
7353 IT->dpvec holds the glyphs to return as characters.
7354 IT->saved_face_id holds the face id before the display vector--it
7355 is restored into IT->face_id in set_iterator_to_next. */
7358 next_element_from_display_vector (struct it
*it
)
7363 eassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
7365 it
->face_id
= it
->saved_face_id
;
7367 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
7368 That seemed totally bogus - so I changed it... */
7369 gc
= it
->dpvec
[it
->current
.dpvec_index
];
7371 if (GLYPH_CODE_P (gc
))
7373 it
->c
= GLYPH_CODE_CHAR (gc
);
7374 it
->len
= CHAR_BYTES (it
->c
);
7376 /* The entry may contain a face id to use. Such a face id is
7377 the id of a Lisp face, not a realized face. A face id of
7378 zero means no face is specified. */
7379 if (it
->dpvec_face_id
>= 0)
7380 it
->face_id
= it
->dpvec_face_id
;
7383 int lface_id
= GLYPH_CODE_FACE (gc
);
7385 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
7390 /* Display table entry is invalid. Return a space. */
7391 it
->c
= ' ', it
->len
= 1;
7393 /* Don't change position and object of the iterator here. They are
7394 still the values of the character that had this display table
7395 entry or was translated, and that's what we want. */
7396 it
->what
= IT_CHARACTER
;
7400 /* Get the first element of string/buffer in the visual order, after
7401 being reseated to a new position in a string or a buffer. */
7403 get_visually_first_element (struct it
*it
)
7405 int string_p
= STRINGP (it
->string
) || it
->s
;
7406 ptrdiff_t eob
= (string_p
? it
->bidi_it
.string
.schars
: ZV
);
7407 ptrdiff_t bob
= (string_p
? 0 : BEGV
);
7409 if (STRINGP (it
->string
))
7411 it
->bidi_it
.charpos
= IT_STRING_CHARPOS (*it
);
7412 it
->bidi_it
.bytepos
= IT_STRING_BYTEPOS (*it
);
7416 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
7417 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
7420 if (it
->bidi_it
.charpos
== eob
)
7422 /* Nothing to do, but reset the FIRST_ELT flag, like
7423 bidi_paragraph_init does, because we are not going to
7425 it
->bidi_it
.first_elt
= 0;
7427 else if (it
->bidi_it
.charpos
== bob
7429 && (FETCH_CHAR (it
->bidi_it
.bytepos
- 1) == '\n'
7430 || FETCH_CHAR (it
->bidi_it
.bytepos
) == '\n')))
7432 /* If we are at the beginning of a line/string, we can produce
7433 the next element right away. */
7434 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7435 bidi_move_to_visually_next (&it
->bidi_it
);
7439 ptrdiff_t orig_bytepos
= it
->bidi_it
.bytepos
;
7441 /* We need to prime the bidi iterator starting at the line's or
7442 string's beginning, before we will be able to produce the
7445 it
->bidi_it
.charpos
= it
->bidi_it
.bytepos
= 0;
7448 it
->bidi_it
.charpos
= find_next_newline_no_quit (IT_CHARPOS (*it
),
7450 it
->bidi_it
.bytepos
= CHAR_TO_BYTE (it
->bidi_it
.charpos
);
7452 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7455 /* Now return to buffer/string position where we were asked
7456 to get the next display element, and produce that. */
7457 bidi_move_to_visually_next (&it
->bidi_it
);
7459 while (it
->bidi_it
.bytepos
!= orig_bytepos
7460 && it
->bidi_it
.charpos
< eob
);
7463 /* Adjust IT's position information to where we ended up. */
7464 if (STRINGP (it
->string
))
7466 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7467 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7471 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7472 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7475 if (STRINGP (it
->string
) || !it
->s
)
7477 ptrdiff_t stop
, charpos
, bytepos
;
7479 if (STRINGP (it
->string
))
7482 stop
= SCHARS (it
->string
);
7483 if (stop
> it
->end_charpos
)
7484 stop
= it
->end_charpos
;
7485 charpos
= IT_STRING_CHARPOS (*it
);
7486 bytepos
= IT_STRING_BYTEPOS (*it
);
7490 stop
= it
->end_charpos
;
7491 charpos
= IT_CHARPOS (*it
);
7492 bytepos
= IT_BYTEPOS (*it
);
7494 if (it
->bidi_it
.scan_dir
< 0)
7496 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
, stop
,
7501 /* Load IT with the next display element from Lisp string IT->string.
7502 IT->current.string_pos is the current position within the string.
7503 If IT->current.overlay_string_index >= 0, the Lisp string is an
7507 next_element_from_string (struct it
*it
)
7509 struct text_pos position
;
7511 eassert (STRINGP (it
->string
));
7512 eassert (!it
->bidi_p
|| EQ (it
->string
, it
->bidi_it
.string
.lstring
));
7513 eassert (IT_STRING_CHARPOS (*it
) >= 0);
7514 position
= it
->current
.string_pos
;
7516 /* With bidi reordering, the character to display might not be the
7517 character at IT_STRING_CHARPOS. BIDI_IT.FIRST_ELT non-zero means
7518 that we were reseat()ed to a new string, whose paragraph
7519 direction is not known. */
7520 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7522 get_visually_first_element (it
);
7523 SET_TEXT_POS (position
, IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
));
7526 /* Time to check for invisible text? */
7527 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
7529 if (IT_STRING_CHARPOS (*it
) >= it
->stop_charpos
)
7532 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7533 || IT_STRING_CHARPOS (*it
) == it
->stop_charpos
))
7535 /* With bidi non-linear iteration, we could find
7536 ourselves far beyond the last computed stop_charpos,
7537 with several other stop positions in between that we
7538 missed. Scan them all now, in buffer's logical
7539 order, until we find and handle the last stop_charpos
7540 that precedes our current position. */
7541 handle_stop_backwards (it
, it
->stop_charpos
);
7542 return GET_NEXT_DISPLAY_ELEMENT (it
);
7548 /* Take note of the stop position we just moved
7549 across, for when we will move back across it. */
7550 it
->prev_stop
= it
->stop_charpos
;
7551 /* If we are at base paragraph embedding level, take
7552 note of the last stop position seen at this
7554 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7555 it
->base_level_stop
= it
->stop_charpos
;
7559 /* Since a handler may have changed IT->method, we must
7561 return GET_NEXT_DISPLAY_ELEMENT (it
);
7565 /* If we are before prev_stop, we may have overstepped
7566 on our way backwards a stop_pos, and if so, we need
7567 to handle that stop_pos. */
7568 && IT_STRING_CHARPOS (*it
) < it
->prev_stop
7569 /* We can sometimes back up for reasons that have nothing
7570 to do with bidi reordering. E.g., compositions. The
7571 code below is only needed when we are above the base
7572 embedding level, so test for that explicitly. */
7573 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7575 /* If we lost track of base_level_stop, we have no better
7576 place for handle_stop_backwards to start from than string
7577 beginning. This happens, e.g., when we were reseated to
7578 the previous screenful of text by vertical-motion. */
7579 if (it
->base_level_stop
<= 0
7580 || IT_STRING_CHARPOS (*it
) < it
->base_level_stop
)
7581 it
->base_level_stop
= 0;
7582 handle_stop_backwards (it
, it
->base_level_stop
);
7583 return GET_NEXT_DISPLAY_ELEMENT (it
);
7587 if (it
->current
.overlay_string_index
>= 0)
7589 /* Get the next character from an overlay string. In overlay
7590 strings, there is no field width or padding with spaces to
7592 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7597 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7598 IT_STRING_BYTEPOS (*it
),
7599 it
->bidi_it
.scan_dir
< 0
7601 : SCHARS (it
->string
))
7602 && next_element_from_composition (it
))
7606 else if (STRING_MULTIBYTE (it
->string
))
7608 const unsigned char *s
= (SDATA (it
->string
)
7609 + IT_STRING_BYTEPOS (*it
));
7610 it
->c
= string_char_and_length (s
, &it
->len
);
7614 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7620 /* Get the next character from a Lisp string that is not an
7621 overlay string. Such strings come from the mode line, for
7622 example. We may have to pad with spaces, or truncate the
7623 string. See also next_element_from_c_string. */
7624 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7629 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
7631 /* Pad with spaces. */
7632 it
->c
= ' ', it
->len
= 1;
7633 CHARPOS (position
) = BYTEPOS (position
) = -1;
7635 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7636 IT_STRING_BYTEPOS (*it
),
7637 it
->bidi_it
.scan_dir
< 0
7639 : it
->string_nchars
)
7640 && next_element_from_composition (it
))
7644 else if (STRING_MULTIBYTE (it
->string
))
7646 const unsigned char *s
= (SDATA (it
->string
)
7647 + IT_STRING_BYTEPOS (*it
));
7648 it
->c
= string_char_and_length (s
, &it
->len
);
7652 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7657 /* Record what we have and where it came from. */
7658 it
->what
= IT_CHARACTER
;
7659 it
->object
= it
->string
;
7660 it
->position
= position
;
7665 /* Load IT with next display element from C string IT->s.
7666 IT->string_nchars is the maximum number of characters to return
7667 from the string. IT->end_charpos may be greater than
7668 IT->string_nchars when this function is called, in which case we
7669 may have to return padding spaces. Value is zero if end of string
7670 reached, including padding spaces. */
7673 next_element_from_c_string (struct it
*it
)
7678 eassert (!it
->bidi_p
|| it
->s
== it
->bidi_it
.string
.s
);
7679 it
->what
= IT_CHARACTER
;
7680 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
7683 /* With bidi reordering, the character to display might not be the
7684 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7685 we were reseated to a new string, whose paragraph direction is
7687 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7688 get_visually_first_element (it
);
7690 /* IT's position can be greater than IT->string_nchars in case a
7691 field width or precision has been specified when the iterator was
7693 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7695 /* End of the game. */
7699 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
7701 /* Pad with spaces. */
7702 it
->c
= ' ', it
->len
= 1;
7703 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
7705 else if (it
->multibyte_p
)
7706 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
), &it
->len
);
7708 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
7714 /* Set up IT to return characters from an ellipsis, if appropriate.
7715 The definition of the ellipsis glyphs may come from a display table
7716 entry. This function fills IT with the first glyph from the
7717 ellipsis if an ellipsis is to be displayed. */
7720 next_element_from_ellipsis (struct it
*it
)
7722 if (it
->selective_display_ellipsis_p
)
7723 setup_for_ellipsis (it
, it
->len
);
7726 /* The face at the current position may be different from the
7727 face we find after the invisible text. Remember what it
7728 was in IT->saved_face_id, and signal that it's there by
7729 setting face_before_selective_p. */
7730 it
->saved_face_id
= it
->face_id
;
7731 it
->method
= GET_FROM_BUFFER
;
7732 it
->object
= it
->w
->buffer
;
7733 reseat_at_next_visible_line_start (it
, 1);
7734 it
->face_before_selective_p
= 1;
7737 return GET_NEXT_DISPLAY_ELEMENT (it
);
7741 /* Deliver an image display element. The iterator IT is already
7742 filled with image information (done in handle_display_prop). Value
7747 next_element_from_image (struct it
*it
)
7749 it
->what
= IT_IMAGE
;
7750 it
->ignore_overlay_strings_at_pos_p
= 0;
7755 /* Fill iterator IT with next display element from a stretch glyph
7756 property. IT->object is the value of the text property. Value is
7760 next_element_from_stretch (struct it
*it
)
7762 it
->what
= IT_STRETCH
;
7766 /* Scan backwards from IT's current position until we find a stop
7767 position, or until BEGV. This is called when we find ourself
7768 before both the last known prev_stop and base_level_stop while
7769 reordering bidirectional text. */
7772 compute_stop_pos_backwards (struct it
*it
)
7774 const int SCAN_BACK_LIMIT
= 1000;
7775 struct text_pos pos
;
7776 struct display_pos save_current
= it
->current
;
7777 struct text_pos save_position
= it
->position
;
7778 ptrdiff_t charpos
= IT_CHARPOS (*it
);
7779 ptrdiff_t where_we_are
= charpos
;
7780 ptrdiff_t save_stop_pos
= it
->stop_charpos
;
7781 ptrdiff_t save_end_pos
= it
->end_charpos
;
7783 eassert (NILP (it
->string
) && !it
->s
);
7784 eassert (it
->bidi_p
);
7788 it
->end_charpos
= min (charpos
+ 1, ZV
);
7789 charpos
= max (charpos
- SCAN_BACK_LIMIT
, BEGV
);
7790 SET_TEXT_POS (pos
, charpos
, CHAR_TO_BYTE (charpos
));
7791 reseat_1 (it
, pos
, 0);
7792 compute_stop_pos (it
);
7793 /* We must advance forward, right? */
7794 if (it
->stop_charpos
<= charpos
)
7797 while (charpos
> BEGV
&& it
->stop_charpos
>= it
->end_charpos
);
7799 if (it
->stop_charpos
<= where_we_are
)
7800 it
->prev_stop
= it
->stop_charpos
;
7802 it
->prev_stop
= BEGV
;
7804 it
->current
= save_current
;
7805 it
->position
= save_position
;
7806 it
->stop_charpos
= save_stop_pos
;
7807 it
->end_charpos
= save_end_pos
;
7810 /* Scan forward from CHARPOS in the current buffer/string, until we
7811 find a stop position > current IT's position. Then handle the stop
7812 position before that. This is called when we bump into a stop
7813 position while reordering bidirectional text. CHARPOS should be
7814 the last previously processed stop_pos (or BEGV/0, if none were
7815 processed yet) whose position is less that IT's current
7819 handle_stop_backwards (struct it
*it
, ptrdiff_t charpos
)
7821 int bufp
= !STRINGP (it
->string
);
7822 ptrdiff_t where_we_are
= (bufp
? IT_CHARPOS (*it
) : IT_STRING_CHARPOS (*it
));
7823 struct display_pos save_current
= it
->current
;
7824 struct text_pos save_position
= it
->position
;
7825 struct text_pos pos1
;
7826 ptrdiff_t next_stop
;
7828 /* Scan in strict logical order. */
7829 eassert (it
->bidi_p
);
7833 it
->prev_stop
= charpos
;
7836 SET_TEXT_POS (pos1
, charpos
, CHAR_TO_BYTE (charpos
));
7837 reseat_1 (it
, pos1
, 0);
7840 it
->current
.string_pos
= string_pos (charpos
, it
->string
);
7841 compute_stop_pos (it
);
7842 /* We must advance forward, right? */
7843 if (it
->stop_charpos
<= it
->prev_stop
)
7845 charpos
= it
->stop_charpos
;
7847 while (charpos
<= where_we_are
);
7850 it
->current
= save_current
;
7851 it
->position
= save_position
;
7852 next_stop
= it
->stop_charpos
;
7853 it
->stop_charpos
= it
->prev_stop
;
7855 it
->stop_charpos
= next_stop
;
7858 /* Load IT with the next display element from current_buffer. Value
7859 is zero if end of buffer reached. IT->stop_charpos is the next
7860 position at which to stop and check for text properties or buffer
7864 next_element_from_buffer (struct it
*it
)
7868 eassert (IT_CHARPOS (*it
) >= BEGV
);
7869 eassert (NILP (it
->string
) && !it
->s
);
7870 eassert (!it
->bidi_p
7871 || (EQ (it
->bidi_it
.string
.lstring
, Qnil
)
7872 && it
->bidi_it
.string
.s
== NULL
));
7874 /* With bidi reordering, the character to display might not be the
7875 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7876 we were reseat()ed to a new buffer position, which is potentially
7877 a different paragraph. */
7878 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7880 get_visually_first_element (it
);
7881 SET_TEXT_POS (it
->position
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7884 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
7886 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7888 int overlay_strings_follow_p
;
7890 /* End of the game, except when overlay strings follow that
7891 haven't been returned yet. */
7892 if (it
->overlay_strings_at_end_processed_p
)
7893 overlay_strings_follow_p
= 0;
7896 it
->overlay_strings_at_end_processed_p
= 1;
7897 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
7900 if (overlay_strings_follow_p
)
7901 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
7905 it
->position
= it
->current
.pos
;
7909 else if (!(!it
->bidi_p
7910 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7911 || IT_CHARPOS (*it
) == it
->stop_charpos
))
7913 /* With bidi non-linear iteration, we could find ourselves
7914 far beyond the last computed stop_charpos, with several
7915 other stop positions in between that we missed. Scan
7916 them all now, in buffer's logical order, until we find
7917 and handle the last stop_charpos that precedes our
7918 current position. */
7919 handle_stop_backwards (it
, it
->stop_charpos
);
7920 return GET_NEXT_DISPLAY_ELEMENT (it
);
7926 /* Take note of the stop position we just moved across,
7927 for when we will move back across it. */
7928 it
->prev_stop
= it
->stop_charpos
;
7929 /* If we are at base paragraph embedding level, take
7930 note of the last stop position seen at this
7932 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7933 it
->base_level_stop
= it
->stop_charpos
;
7936 return GET_NEXT_DISPLAY_ELEMENT (it
);
7940 /* If we are before prev_stop, we may have overstepped on
7941 our way backwards a stop_pos, and if so, we need to
7942 handle that stop_pos. */
7943 && IT_CHARPOS (*it
) < it
->prev_stop
7944 /* We can sometimes back up for reasons that have nothing
7945 to do with bidi reordering. E.g., compositions. The
7946 code below is only needed when we are above the base
7947 embedding level, so test for that explicitly. */
7948 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7950 if (it
->base_level_stop
<= 0
7951 || IT_CHARPOS (*it
) < it
->base_level_stop
)
7953 /* If we lost track of base_level_stop, we need to find
7954 prev_stop by looking backwards. This happens, e.g., when
7955 we were reseated to the previous screenful of text by
7957 it
->base_level_stop
= BEGV
;
7958 compute_stop_pos_backwards (it
);
7959 handle_stop_backwards (it
, it
->prev_stop
);
7962 handle_stop_backwards (it
, it
->base_level_stop
);
7963 return GET_NEXT_DISPLAY_ELEMENT (it
);
7967 /* No face changes, overlays etc. in sight, so just return a
7968 character from current_buffer. */
7972 /* Maybe run the redisplay end trigger hook. Performance note:
7973 This doesn't seem to cost measurable time. */
7974 if (it
->redisplay_end_trigger_charpos
7976 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
7977 run_redisplay_end_trigger_hook (it
);
7979 stop
= it
->bidi_it
.scan_dir
< 0 ? -1 : it
->end_charpos
;
7980 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
7982 && next_element_from_composition (it
))
7987 /* Get the next character, maybe multibyte. */
7988 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
7989 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
7990 it
->c
= STRING_CHAR_AND_LENGTH (p
, it
->len
);
7992 it
->c
= *p
, it
->len
= 1;
7994 /* Record what we have and where it came from. */
7995 it
->what
= IT_CHARACTER
;
7996 it
->object
= it
->w
->buffer
;
7997 it
->position
= it
->current
.pos
;
7999 /* Normally we return the character found above, except when we
8000 really want to return an ellipsis for selective display. */
8005 /* A value of selective > 0 means hide lines indented more
8006 than that number of columns. */
8007 if (it
->selective
> 0
8008 && IT_CHARPOS (*it
) + 1 < ZV
8009 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
8010 IT_BYTEPOS (*it
) + 1,
8013 success_p
= next_element_from_ellipsis (it
);
8014 it
->dpvec_char_len
= -1;
8017 else if (it
->c
== '\r' && it
->selective
== -1)
8019 /* A value of selective == -1 means that everything from the
8020 CR to the end of the line is invisible, with maybe an
8021 ellipsis displayed for it. */
8022 success_p
= next_element_from_ellipsis (it
);
8023 it
->dpvec_char_len
= -1;
8028 /* Value is zero if end of buffer reached. */
8029 eassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
8034 /* Run the redisplay end trigger hook for IT. */
8037 run_redisplay_end_trigger_hook (struct it
*it
)
8039 Lisp_Object args
[3];
8041 /* IT->glyph_row should be non-null, i.e. we should be actually
8042 displaying something, or otherwise we should not run the hook. */
8043 eassert (it
->glyph_row
);
8045 /* Set up hook arguments. */
8046 args
[0] = Qredisplay_end_trigger_functions
;
8047 args
[1] = it
->window
;
8048 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
8049 it
->redisplay_end_trigger_charpos
= 0;
8051 /* Since we are *trying* to run these functions, don't try to run
8052 them again, even if they get an error. */
8053 wset_redisplay_end_trigger (it
->w
, Qnil
);
8054 Frun_hook_with_args (3, args
);
8056 /* Notice if it changed the face of the character we are on. */
8057 handle_face_prop (it
);
8061 /* Deliver a composition display element. Unlike the other
8062 next_element_from_XXX, this function is not registered in the array
8063 get_next_element[]. It is called from next_element_from_buffer and
8064 next_element_from_string when necessary. */
8067 next_element_from_composition (struct it
*it
)
8069 it
->what
= IT_COMPOSITION
;
8070 it
->len
= it
->cmp_it
.nbytes
;
8071 if (STRINGP (it
->string
))
8075 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
8076 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
8079 it
->position
= it
->current
.string_pos
;
8080 it
->object
= it
->string
;
8081 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
8082 IT_STRING_BYTEPOS (*it
), it
->string
);
8088 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
8089 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
8092 if (it
->bidi_it
.new_paragraph
)
8093 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
8094 /* Resync the bidi iterator with IT's new position.
8095 FIXME: this doesn't support bidirectional text. */
8096 while (it
->bidi_it
.charpos
< IT_CHARPOS (*it
))
8097 bidi_move_to_visually_next (&it
->bidi_it
);
8101 it
->position
= it
->current
.pos
;
8102 it
->object
= it
->w
->buffer
;
8103 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
8104 IT_BYTEPOS (*it
), Qnil
);
8111 /***********************************************************************
8112 Moving an iterator without producing glyphs
8113 ***********************************************************************/
8115 /* Check if iterator is at a position corresponding to a valid buffer
8116 position after some move_it_ call. */
8118 #define IT_POS_VALID_AFTER_MOVE_P(it) \
8119 ((it)->method == GET_FROM_STRING \
8120 ? IT_STRING_CHARPOS (*it) == 0 \
8124 /* Move iterator IT to a specified buffer or X position within one
8125 line on the display without producing glyphs.
8127 OP should be a bit mask including some or all of these bits:
8128 MOVE_TO_X: Stop upon reaching x-position TO_X.
8129 MOVE_TO_POS: Stop upon reaching buffer or string position TO_CHARPOS.
8130 Regardless of OP's value, stop upon reaching the end of the display line.
8132 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
8133 This means, in particular, that TO_X includes window's horizontal
8136 The return value has several possible values that
8137 say what condition caused the scan to stop:
8139 MOVE_POS_MATCH_OR_ZV
8140 - when TO_POS or ZV was reached.
8143 -when TO_X was reached before TO_POS or ZV were reached.
8146 - when we reached the end of the display area and the line must
8150 - when we reached the end of the display area and the line is
8154 - when we stopped at a line end, i.e. a newline or a CR and selective
8157 static enum move_it_result
8158 move_it_in_display_line_to (struct it
*it
,
8159 ptrdiff_t to_charpos
, int to_x
,
8160 enum move_operation_enum op
)
8162 enum move_it_result result
= MOVE_UNDEFINED
;
8163 struct glyph_row
*saved_glyph_row
;
8164 struct it wrap_it
, atpos_it
, atx_it
, ppos_it
;
8165 void *wrap_data
= NULL
, *atpos_data
= NULL
, *atx_data
= NULL
;
8166 void *ppos_data
= NULL
;
8168 enum it_method prev_method
= it
->method
;
8169 ptrdiff_t prev_pos
= IT_CHARPOS (*it
);
8170 int saw_smaller_pos
= prev_pos
< to_charpos
;
8172 /* Don't produce glyphs in produce_glyphs. */
8173 saved_glyph_row
= it
->glyph_row
;
8174 it
->glyph_row
= NULL
;
8176 /* Use wrap_it to save a copy of IT wherever a word wrap could
8177 occur. Use atpos_it to save a copy of IT at the desired buffer
8178 position, if found, so that we can scan ahead and check if the
8179 word later overshoots the window edge. Use atx_it similarly, for
8185 /* Use ppos_it under bidi reordering to save a copy of IT for the
8186 position > CHARPOS that is the closest to CHARPOS. We restore
8187 that position in IT when we have scanned the entire display line
8188 without finding a match for CHARPOS and all the character
8189 positions are greater than CHARPOS. */
8192 SAVE_IT (ppos_it
, *it
, ppos_data
);
8193 SET_TEXT_POS (ppos_it
.current
.pos
, ZV
, ZV_BYTE
);
8194 if ((op
& MOVE_TO_POS
) && IT_CHARPOS (*it
) >= to_charpos
)
8195 SAVE_IT (ppos_it
, *it
, ppos_data
);
8198 #define BUFFER_POS_REACHED_P() \
8199 ((op & MOVE_TO_POS) != 0 \
8200 && BUFFERP (it->object) \
8201 && (IT_CHARPOS (*it) == to_charpos \
8203 || BIDI_AT_BASE_LEVEL (it->bidi_it)) \
8204 && IT_CHARPOS (*it) > to_charpos) \
8205 || (it->what == IT_COMPOSITION \
8206 && ((IT_CHARPOS (*it) > to_charpos \
8207 && to_charpos >= it->cmp_it.charpos) \
8208 || (IT_CHARPOS (*it) < to_charpos \
8209 && to_charpos <= it->cmp_it.charpos)))) \
8210 && (it->method == GET_FROM_BUFFER \
8211 || (it->method == GET_FROM_DISPLAY_VECTOR \
8212 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
8214 /* If there's a line-/wrap-prefix, handle it. */
8215 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
8216 && it
->current_y
< it
->last_visible_y
)
8217 handle_line_prefix (it
);
8219 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8220 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8224 int x
, i
, ascent
= 0, descent
= 0;
8226 /* Utility macro to reset an iterator with x, ascent, and descent. */
8227 #define IT_RESET_X_ASCENT_DESCENT(IT) \
8228 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
8229 (IT)->max_descent = descent)
8231 /* Stop if we move beyond TO_CHARPOS (after an image or a
8232 display string or stretch glyph). */
8233 if ((op
& MOVE_TO_POS
) != 0
8234 && BUFFERP (it
->object
)
8235 && it
->method
== GET_FROM_BUFFER
8237 /* When the iterator is at base embedding level, we
8238 are guaranteed that characters are delivered for
8239 display in strictly increasing order of their
8240 buffer positions. */
8241 || BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8242 && IT_CHARPOS (*it
) > to_charpos
)
8244 && (prev_method
== GET_FROM_IMAGE
8245 || prev_method
== GET_FROM_STRETCH
8246 || prev_method
== GET_FROM_STRING
)
8247 /* Passed TO_CHARPOS from left to right. */
8248 && ((prev_pos
< to_charpos
8249 && IT_CHARPOS (*it
) > to_charpos
)
8250 /* Passed TO_CHARPOS from right to left. */
8251 || (prev_pos
> to_charpos
8252 && IT_CHARPOS (*it
) < to_charpos
)))))
8254 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8256 result
= MOVE_POS_MATCH_OR_ZV
;
8259 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8260 /* If wrap_it is valid, the current position might be in a
8261 word that is wrapped. So, save the iterator in
8262 atpos_it and continue to see if wrapping happens. */
8263 SAVE_IT (atpos_it
, *it
, atpos_data
);
8266 /* Stop when ZV reached.
8267 We used to stop here when TO_CHARPOS reached as well, but that is
8268 too soon if this glyph does not fit on this line. So we handle it
8269 explicitly below. */
8270 if (!get_next_display_element (it
))
8272 result
= MOVE_POS_MATCH_OR_ZV
;
8276 if (it
->line_wrap
== TRUNCATE
)
8278 if (BUFFER_POS_REACHED_P ())
8280 result
= MOVE_POS_MATCH_OR_ZV
;
8286 if (it
->line_wrap
== WORD_WRAP
)
8288 if (IT_DISPLAYING_WHITESPACE (it
))
8292 /* We have reached a glyph that follows one or more
8293 whitespace characters. If the position is
8294 already found, we are done. */
8295 if (atpos_it
.sp
>= 0)
8297 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8298 result
= MOVE_POS_MATCH_OR_ZV
;
8303 RESTORE_IT (it
, &atx_it
, atx_data
);
8304 result
= MOVE_X_REACHED
;
8307 /* Otherwise, we can wrap here. */
8308 SAVE_IT (wrap_it
, *it
, wrap_data
);
8314 /* Remember the line height for the current line, in case
8315 the next element doesn't fit on the line. */
8316 ascent
= it
->max_ascent
;
8317 descent
= it
->max_descent
;
8319 /* The call to produce_glyphs will get the metrics of the
8320 display element IT is loaded with. Record the x-position
8321 before this display element, in case it doesn't fit on the
8325 PRODUCE_GLYPHS (it
);
8327 if (it
->area
!= TEXT_AREA
)
8329 prev_method
= it
->method
;
8330 if (it
->method
== GET_FROM_BUFFER
)
8331 prev_pos
= IT_CHARPOS (*it
);
8332 set_iterator_to_next (it
, 1);
8333 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8334 SET_TEXT_POS (this_line_min_pos
,
8335 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8337 && (op
& MOVE_TO_POS
)
8338 && IT_CHARPOS (*it
) > to_charpos
8339 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8340 SAVE_IT (ppos_it
, *it
, ppos_data
);
8344 /* The number of glyphs we get back in IT->nglyphs will normally
8345 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
8346 character on a terminal frame, or (iii) a line end. For the
8347 second case, IT->nglyphs - 1 padding glyphs will be present.
8348 (On X frames, there is only one glyph produced for a
8349 composite character.)
8351 The behavior implemented below means, for continuation lines,
8352 that as many spaces of a TAB as fit on the current line are
8353 displayed there. For terminal frames, as many glyphs of a
8354 multi-glyph character are displayed in the current line, too.
8355 This is what the old redisplay code did, and we keep it that
8356 way. Under X, the whole shape of a complex character must
8357 fit on the line or it will be completely displayed in the
8360 Note that both for tabs and padding glyphs, all glyphs have
8364 /* More than one glyph or glyph doesn't fit on line. All
8365 glyphs have the same width. */
8366 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
8368 int x_before_this_char
= x
;
8369 int hpos_before_this_char
= it
->hpos
;
8371 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
8373 new_x
= x
+ single_glyph_width
;
8375 /* We want to leave anything reaching TO_X to the caller. */
8376 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
8378 if (BUFFER_POS_REACHED_P ())
8380 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8381 goto buffer_pos_reached
;
8382 if (atpos_it
.sp
< 0)
8384 SAVE_IT (atpos_it
, *it
, atpos_data
);
8385 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8390 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8393 result
= MOVE_X_REACHED
;
8398 SAVE_IT (atx_it
, *it
, atx_data
);
8399 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
8404 if (/* Lines are continued. */
8405 it
->line_wrap
!= TRUNCATE
8406 && (/* And glyph doesn't fit on the line. */
8407 new_x
> it
->last_visible_x
8408 /* Or it fits exactly and we're on a window
8410 || (new_x
== it
->last_visible_x
8411 && FRAME_WINDOW_P (it
->f
)
8412 && ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
8413 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8414 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
8416 if (/* IT->hpos == 0 means the very first glyph
8417 doesn't fit on the line, e.g. a wide image. */
8419 || (new_x
== it
->last_visible_x
8420 && FRAME_WINDOW_P (it
->f
)))
8423 it
->current_x
= new_x
;
8425 /* The character's last glyph just barely fits
8427 if (i
== it
->nglyphs
- 1)
8429 /* If this is the destination position,
8430 return a position *before* it in this row,
8431 now that we know it fits in this row. */
8432 if (BUFFER_POS_REACHED_P ())
8434 if (it
->line_wrap
!= WORD_WRAP
8437 it
->hpos
= hpos_before_this_char
;
8438 it
->current_x
= x_before_this_char
;
8439 result
= MOVE_POS_MATCH_OR_ZV
;
8442 if (it
->line_wrap
== WORD_WRAP
8445 SAVE_IT (atpos_it
, *it
, atpos_data
);
8446 atpos_it
.current_x
= x_before_this_char
;
8447 atpos_it
.hpos
= hpos_before_this_char
;
8451 prev_method
= it
->method
;
8452 if (it
->method
== GET_FROM_BUFFER
)
8453 prev_pos
= IT_CHARPOS (*it
);
8454 set_iterator_to_next (it
, 1);
8455 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8456 SET_TEXT_POS (this_line_min_pos
,
8457 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8458 /* On graphical terminals, newlines may
8459 "overflow" into the fringe if
8460 overflow-newline-into-fringe is non-nil.
8461 On text terminals, and on graphical
8462 terminals with no right margin, newlines
8463 may overflow into the last glyph on the
8465 if (!FRAME_WINDOW_P (it
->f
)
8467 && it
->bidi_it
.paragraph_dir
== R2L
)
8468 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8469 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0
8470 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8472 if (!get_next_display_element (it
))
8474 result
= MOVE_POS_MATCH_OR_ZV
;
8477 if (BUFFER_POS_REACHED_P ())
8479 if (ITERATOR_AT_END_OF_LINE_P (it
))
8480 result
= MOVE_POS_MATCH_OR_ZV
;
8482 result
= MOVE_LINE_CONTINUED
;
8485 if (ITERATOR_AT_END_OF_LINE_P (it
))
8487 result
= MOVE_NEWLINE_OR_CR
;
8494 IT_RESET_X_ASCENT_DESCENT (it
);
8496 if (wrap_it
.sp
>= 0)
8498 RESTORE_IT (it
, &wrap_it
, wrap_data
);
8503 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
8505 result
= MOVE_LINE_CONTINUED
;
8509 if (BUFFER_POS_REACHED_P ())
8511 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8512 goto buffer_pos_reached
;
8513 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8515 SAVE_IT (atpos_it
, *it
, atpos_data
);
8516 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8520 if (new_x
> it
->first_visible_x
)
8522 /* Glyph is visible. Increment number of glyphs that
8523 would be displayed. */
8528 if (result
!= MOVE_UNDEFINED
)
8531 else if (BUFFER_POS_REACHED_P ())
8534 IT_RESET_X_ASCENT_DESCENT (it
);
8535 result
= MOVE_POS_MATCH_OR_ZV
;
8538 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
8540 /* Stop when TO_X specified and reached. This check is
8541 necessary here because of lines consisting of a line end,
8542 only. The line end will not produce any glyphs and we
8543 would never get MOVE_X_REACHED. */
8544 eassert (it
->nglyphs
== 0);
8545 result
= MOVE_X_REACHED
;
8549 /* Is this a line end? If yes, we're done. */
8550 if (ITERATOR_AT_END_OF_LINE_P (it
))
8552 /* If we are past TO_CHARPOS, but never saw any character
8553 positions smaller than TO_CHARPOS, return
8554 MOVE_POS_MATCH_OR_ZV, like the unidirectional display
8556 if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0)
8558 if (!saw_smaller_pos
&& IT_CHARPOS (*it
) > to_charpos
)
8560 if (IT_CHARPOS (ppos_it
) < ZV
)
8562 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8563 result
= MOVE_POS_MATCH_OR_ZV
;
8566 goto buffer_pos_reached
;
8568 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
>= 0
8569 && IT_CHARPOS (*it
) > to_charpos
)
8570 goto buffer_pos_reached
;
8572 result
= MOVE_NEWLINE_OR_CR
;
8575 result
= MOVE_NEWLINE_OR_CR
;
8579 prev_method
= it
->method
;
8580 if (it
->method
== GET_FROM_BUFFER
)
8581 prev_pos
= IT_CHARPOS (*it
);
8582 /* The current display element has been consumed. Advance
8584 set_iterator_to_next (it
, 1);
8585 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8586 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8587 if (IT_CHARPOS (*it
) < to_charpos
)
8588 saw_smaller_pos
= 1;
8590 && (op
& MOVE_TO_POS
)
8591 && IT_CHARPOS (*it
) >= to_charpos
8592 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8593 SAVE_IT (ppos_it
, *it
, ppos_data
);
8595 /* Stop if lines are truncated and IT's current x-position is
8596 past the right edge of the window now. */
8597 if (it
->line_wrap
== TRUNCATE
8598 && it
->current_x
>= it
->last_visible_x
)
8600 if (!FRAME_WINDOW_P (it
->f
)
8601 || ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
8602 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8603 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0
8604 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8608 if ((at_eob_p
= !get_next_display_element (it
))
8609 || BUFFER_POS_REACHED_P ()
8610 /* If we are past TO_CHARPOS, but never saw any
8611 character positions smaller than TO_CHARPOS,
8612 return MOVE_POS_MATCH_OR_ZV, like the
8613 unidirectional display did. */
8614 || (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8616 && IT_CHARPOS (*it
) > to_charpos
))
8619 && !at_eob_p
&& IT_CHARPOS (ppos_it
) < ZV
)
8620 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8621 result
= MOVE_POS_MATCH_OR_ZV
;
8624 if (ITERATOR_AT_END_OF_LINE_P (it
))
8626 result
= MOVE_NEWLINE_OR_CR
;
8630 else if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8632 && IT_CHARPOS (*it
) > to_charpos
)
8634 if (IT_CHARPOS (ppos_it
) < ZV
)
8635 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8636 result
= MOVE_POS_MATCH_OR_ZV
;
8639 result
= MOVE_LINE_TRUNCATED
;
8642 #undef IT_RESET_X_ASCENT_DESCENT
8645 #undef BUFFER_POS_REACHED_P
8647 /* If we scanned beyond to_pos and didn't find a point to wrap at,
8648 restore the saved iterator. */
8649 if (atpos_it
.sp
>= 0)
8650 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8651 else if (atx_it
.sp
>= 0)
8652 RESTORE_IT (it
, &atx_it
, atx_data
);
8657 bidi_unshelve_cache (atpos_data
, 1);
8659 bidi_unshelve_cache (atx_data
, 1);
8661 bidi_unshelve_cache (wrap_data
, 1);
8663 bidi_unshelve_cache (ppos_data
, 1);
8665 /* Restore the iterator settings altered at the beginning of this
8667 it
->glyph_row
= saved_glyph_row
;
8671 /* For external use. */
8673 move_it_in_display_line (struct it
*it
,
8674 ptrdiff_t to_charpos
, int to_x
,
8675 enum move_operation_enum op
)
8677 if (it
->line_wrap
== WORD_WRAP
8678 && (op
& MOVE_TO_X
))
8681 void *save_data
= NULL
;
8684 SAVE_IT (save_it
, *it
, save_data
);
8685 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8686 /* When word-wrap is on, TO_X may lie past the end
8687 of a wrapped line. Then it->current is the
8688 character on the next line, so backtrack to the
8689 space before the wrap point. */
8690 if (skip
== MOVE_LINE_CONTINUED
)
8692 int prev_x
= max (it
->current_x
- 1, 0);
8693 RESTORE_IT (it
, &save_it
, save_data
);
8694 move_it_in_display_line_to
8695 (it
, -1, prev_x
, MOVE_TO_X
);
8698 bidi_unshelve_cache (save_data
, 1);
8701 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8705 /* Move IT forward until it satisfies one or more of the criteria in
8706 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
8708 OP is a bit-mask that specifies where to stop, and in particular,
8709 which of those four position arguments makes a difference. See the
8710 description of enum move_operation_enum.
8712 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
8713 screen line, this function will set IT to the next position that is
8714 displayed to the right of TO_CHARPOS on the screen. */
8717 move_it_to (struct it
*it
, ptrdiff_t to_charpos
, int to_x
, int to_y
, int to_vpos
, int op
)
8719 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
8720 int line_height
, line_start_x
= 0, reached
= 0;
8721 void *backup_data
= NULL
;
8725 if (op
& MOVE_TO_VPOS
)
8727 /* If no TO_CHARPOS and no TO_X specified, stop at the
8728 start of the line TO_VPOS. */
8729 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
8731 if (it
->vpos
== to_vpos
)
8737 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
8741 /* TO_VPOS >= 0 means stop at TO_X in the line at
8742 TO_VPOS, or at TO_POS, whichever comes first. */
8743 if (it
->vpos
== to_vpos
)
8749 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8751 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
8756 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
8758 /* We have reached TO_X but not in the line we want. */
8759 skip
= move_it_in_display_line_to (it
, to_charpos
,
8761 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8769 else if (op
& MOVE_TO_Y
)
8771 struct it it_backup
;
8773 if (it
->line_wrap
== WORD_WRAP
)
8774 SAVE_IT (it_backup
, *it
, backup_data
);
8776 /* TO_Y specified means stop at TO_X in the line containing
8777 TO_Y---or at TO_CHARPOS if this is reached first. The
8778 problem is that we can't really tell whether the line
8779 contains TO_Y before we have completely scanned it, and
8780 this may skip past TO_X. What we do is to first scan to
8783 If TO_X is not specified, use a TO_X of zero. The reason
8784 is to make the outcome of this function more predictable.
8785 If we didn't use TO_X == 0, we would stop at the end of
8786 the line which is probably not what a caller would expect
8788 skip
= move_it_in_display_line_to
8789 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
8790 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
8792 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
8793 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8795 else if (skip
== MOVE_X_REACHED
)
8797 /* If TO_X was reached, we want to know whether TO_Y is
8798 in the line. We know this is the case if the already
8799 scanned glyphs make the line tall enough. Otherwise,
8800 we must check by scanning the rest of the line. */
8801 line_height
= it
->max_ascent
+ it
->max_descent
;
8802 if (to_y
>= it
->current_y
8803 && to_y
< it
->current_y
+ line_height
)
8808 SAVE_IT (it_backup
, *it
, backup_data
);
8809 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
8810 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
8812 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
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 /* If TO_Y is in this line and TO_X was reached
8820 above, we scanned too far. We have to restore
8821 IT's settings to the ones before skipping. But
8822 keep the more accurate values of max_ascent and
8823 max_descent we've found while skipping the rest
8824 of the line, for the sake of callers, such as
8825 pos_visible_p, that need to know the line
8827 int max_ascent
= it
->max_ascent
;
8828 int max_descent
= it
->max_descent
;
8830 RESTORE_IT (it
, &it_backup
, backup_data
);
8831 it
->max_ascent
= max_ascent
;
8832 it
->max_descent
= max_descent
;
8838 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8844 /* Check whether TO_Y is in this line. */
8845 line_height
= it
->max_ascent
+ it
->max_descent
;
8846 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8848 if (to_y
>= it
->current_y
8849 && to_y
< it
->current_y
+ line_height
)
8851 /* When word-wrap is on, TO_X may lie past the end
8852 of a wrapped line. Then it->current is the
8853 character on the next line, so backtrack to the
8854 space before the wrap point. */
8855 if (skip
== MOVE_LINE_CONTINUED
8856 && it
->line_wrap
== WORD_WRAP
)
8858 int prev_x
= max (it
->current_x
- 1, 0);
8859 RESTORE_IT (it
, &it_backup
, backup_data
);
8860 skip
= move_it_in_display_line_to
8861 (it
, -1, prev_x
, MOVE_TO_X
);
8870 else if (BUFFERP (it
->object
)
8871 && (it
->method
== GET_FROM_BUFFER
8872 || it
->method
== GET_FROM_STRETCH
)
8873 && IT_CHARPOS (*it
) >= to_charpos
8874 /* Under bidi iteration, a call to set_iterator_to_next
8875 can scan far beyond to_charpos if the initial
8876 portion of the next line needs to be reordered. In
8877 that case, give move_it_in_display_line_to another
8880 && it
->bidi_it
.scan_dir
== -1))
8881 skip
= MOVE_POS_MATCH_OR_ZV
;
8883 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
8887 case MOVE_POS_MATCH_OR_ZV
:
8891 case MOVE_NEWLINE_OR_CR
:
8892 set_iterator_to_next (it
, 1);
8893 it
->continuation_lines_width
= 0;
8896 case MOVE_LINE_TRUNCATED
:
8897 it
->continuation_lines_width
= 0;
8898 reseat_at_next_visible_line_start (it
, 0);
8899 if ((op
& MOVE_TO_POS
) != 0
8900 && IT_CHARPOS (*it
) > to_charpos
)
8907 case MOVE_LINE_CONTINUED
:
8908 /* For continued lines ending in a tab, some of the glyphs
8909 associated with the tab are displayed on the current
8910 line. Since it->current_x does not include these glyphs,
8911 we use it->last_visible_x instead. */
8914 it
->continuation_lines_width
+= it
->last_visible_x
;
8915 /* When moving by vpos, ensure that the iterator really
8916 advances to the next line (bug#847, bug#969). Fixme:
8917 do we need to do this in other circumstances? */
8918 if (it
->current_x
!= it
->last_visible_x
8919 && (op
& MOVE_TO_VPOS
)
8920 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
8922 line_start_x
= it
->current_x
+ it
->pixel_width
8923 - it
->last_visible_x
;
8924 set_iterator_to_next (it
, 0);
8928 it
->continuation_lines_width
+= it
->current_x
;
8935 /* Reset/increment for the next run. */
8936 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
8937 it
->current_x
= line_start_x
;
8940 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
8942 last_height
= it
->max_ascent
+ it
->max_descent
;
8943 last_max_ascent
= it
->max_ascent
;
8944 it
->max_ascent
= it
->max_descent
= 0;
8949 /* On text terminals, we may stop at the end of a line in the middle
8950 of a multi-character glyph. If the glyph itself is continued,
8951 i.e. it is actually displayed on the next line, don't treat this
8952 stopping point as valid; move to the next line instead (unless
8953 that brings us offscreen). */
8954 if (!FRAME_WINDOW_P (it
->f
)
8956 && IT_CHARPOS (*it
) == to_charpos
8957 && it
->what
== IT_CHARACTER
8959 && it
->line_wrap
== WINDOW_WRAP
8960 && it
->current_x
== it
->last_visible_x
- 1
8963 && it
->vpos
< XFASTINT (it
->w
->window_end_vpos
))
8965 it
->continuation_lines_width
+= it
->current_x
;
8966 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
8967 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
8969 last_height
= it
->max_ascent
+ it
->max_descent
;
8970 last_max_ascent
= it
->max_ascent
;
8974 bidi_unshelve_cache (backup_data
, 1);
8976 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
8980 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
8982 If DY > 0, move IT backward at least that many pixels. DY = 0
8983 means move IT backward to the preceding line start or BEGV. This
8984 function may move over more than DY pixels if IT->current_y - DY
8985 ends up in the middle of a line; in this case IT->current_y will be
8986 set to the top of the line moved to. */
8989 move_it_vertically_backward (struct it
*it
, int dy
)
8993 void *it2data
= NULL
, *it3data
= NULL
;
8994 ptrdiff_t start_pos
;
8999 start_pos
= IT_CHARPOS (*it
);
9001 /* Estimate how many newlines we must move back. */
9002 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
9004 /* Set the iterator's position that many lines back. */
9005 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
9006 back_to_previous_visible_line_start (it
);
9008 /* Reseat the iterator here. When moving backward, we don't want
9009 reseat to skip forward over invisible text, set up the iterator
9010 to deliver from overlay strings at the new position etc. So,
9011 use reseat_1 here. */
9012 reseat_1 (it
, it
->current
.pos
, 1);
9014 /* We are now surely at a line start. */
9015 it
->current_x
= it
->hpos
= 0; /* FIXME: this is incorrect when bidi
9016 reordering is in effect. */
9017 it
->continuation_lines_width
= 0;
9019 /* Move forward and see what y-distance we moved. First move to the
9020 start of the next line so that we get its height. We need this
9021 height to be able to tell whether we reached the specified
9023 SAVE_IT (it2
, *it
, it2data
);
9024 it2
.max_ascent
= it2
.max_descent
= 0;
9027 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
9028 MOVE_TO_POS
| MOVE_TO_VPOS
);
9030 while (!(IT_POS_VALID_AFTER_MOVE_P (&it2
)
9031 /* If we are in a display string which starts at START_POS,
9032 and that display string includes a newline, and we are
9033 right after that newline (i.e. at the beginning of a
9034 display line), exit the loop, because otherwise we will
9035 infloop, since move_it_to will see that it is already at
9036 START_POS and will not move. */
9037 || (it2
.method
== GET_FROM_STRING
9038 && IT_CHARPOS (it2
) == start_pos
9039 && SREF (it2
.string
, IT_STRING_BYTEPOS (it2
) - 1) == '\n')));
9040 eassert (IT_CHARPOS (*it
) >= BEGV
);
9041 SAVE_IT (it3
, it2
, it3data
);
9043 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
9044 eassert (IT_CHARPOS (*it
) >= BEGV
);
9045 /* H is the actual vertical distance from the position in *IT
9046 and the starting position. */
9047 h
= it2
.current_y
- it
->current_y
;
9048 /* NLINES is the distance in number of lines. */
9049 nlines
= it2
.vpos
- it
->vpos
;
9051 /* Correct IT's y and vpos position
9052 so that they are relative to the starting point. */
9058 /* DY == 0 means move to the start of the screen line. The
9059 value of nlines is > 0 if continuation lines were involved,
9060 or if the original IT position was at start of a line. */
9061 RESTORE_IT (it
, it
, it2data
);
9063 move_it_by_lines (it
, nlines
);
9064 /* The above code moves us to some position NLINES down,
9065 usually to its first glyph (leftmost in an L2R line), but
9066 that's not necessarily the start of the line, under bidi
9067 reordering. We want to get to the character position
9068 that is immediately after the newline of the previous
9071 && !it
->continuation_lines_width
9072 && !STRINGP (it
->string
)
9073 && IT_CHARPOS (*it
) > BEGV
9074 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9077 find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
9079 move_it_to (it
, nl_pos
, -1, -1, -1, MOVE_TO_POS
);
9081 bidi_unshelve_cache (it3data
, 1);
9085 /* The y-position we try to reach, relative to *IT.
9086 Note that H has been subtracted in front of the if-statement. */
9087 int target_y
= it
->current_y
+ h
- dy
;
9088 int y0
= it3
.current_y
;
9092 RESTORE_IT (&it3
, &it3
, it3data
);
9093 y1
= line_bottom_y (&it3
);
9094 line_height
= y1
- y0
;
9095 RESTORE_IT (it
, it
, it2data
);
9096 /* If we did not reach target_y, try to move further backward if
9097 we can. If we moved too far backward, try to move forward. */
9098 if (target_y
< it
->current_y
9099 /* This is heuristic. In a window that's 3 lines high, with
9100 a line height of 13 pixels each, recentering with point
9101 on the bottom line will try to move -39/2 = 19 pixels
9102 backward. Try to avoid moving into the first line. */
9103 && (it
->current_y
- target_y
9104 > min (window_box_height (it
->w
), line_height
* 2 / 3))
9105 && IT_CHARPOS (*it
) > BEGV
)
9107 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
9108 target_y
- it
->current_y
));
9109 dy
= it
->current_y
- target_y
;
9110 goto move_further_back
;
9112 else if (target_y
>= it
->current_y
+ line_height
9113 && IT_CHARPOS (*it
) < ZV
)
9115 /* Should move forward by at least one line, maybe more.
9117 Note: Calling move_it_by_lines can be expensive on
9118 terminal frames, where compute_motion is used (via
9119 vmotion) to do the job, when there are very long lines
9120 and truncate-lines is nil. That's the reason for
9121 treating terminal frames specially here. */
9123 if (!FRAME_WINDOW_P (it
->f
))
9124 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
9129 move_it_by_lines (it
, 1);
9131 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
9138 /* Move IT by a specified amount of pixel lines DY. DY negative means
9139 move backwards. DY = 0 means move to start of screen line. At the
9140 end, IT will be on the start of a screen line. */
9143 move_it_vertically (struct it
*it
, int dy
)
9146 move_it_vertically_backward (it
, -dy
);
9149 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
9150 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
9151 MOVE_TO_POS
| MOVE_TO_Y
);
9152 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
9154 /* If buffer ends in ZV without a newline, move to the start of
9155 the line to satisfy the post-condition. */
9156 if (IT_CHARPOS (*it
) == ZV
9158 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9159 move_it_by_lines (it
, 0);
9164 /* Move iterator IT past the end of the text line it is in. */
9167 move_it_past_eol (struct it
*it
)
9169 enum move_it_result rc
;
9171 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
9172 if (rc
== MOVE_NEWLINE_OR_CR
)
9173 set_iterator_to_next (it
, 0);
9177 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
9178 negative means move up. DVPOS == 0 means move to the start of the
9181 Optimization idea: If we would know that IT->f doesn't use
9182 a face with proportional font, we could be faster for
9183 truncate-lines nil. */
9186 move_it_by_lines (struct it
*it
, ptrdiff_t dvpos
)
9189 /* The commented-out optimization uses vmotion on terminals. This
9190 gives bad results, because elements like it->what, on which
9191 callers such as pos_visible_p rely, aren't updated. */
9192 /* struct position pos;
9193 if (!FRAME_WINDOW_P (it->f))
9195 struct text_pos textpos;
9197 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
9198 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
9199 reseat (it, textpos, 1);
9200 it->vpos += pos.vpos;
9201 it->current_y += pos.vpos;
9207 /* DVPOS == 0 means move to the start of the screen line. */
9208 move_it_vertically_backward (it
, 0);
9209 /* Let next call to line_bottom_y calculate real line height */
9214 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
9215 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
9217 /* Only move to the next buffer position if we ended up in a
9218 string from display property, not in an overlay string
9219 (before-string or after-string). That is because the
9220 latter don't conceal the underlying buffer position, so
9221 we can ask to move the iterator to the exact position we
9222 are interested in. Note that, even if we are already at
9223 IT_CHARPOS (*it), the call below is not a no-op, as it
9224 will detect that we are at the end of the string, pop the
9225 iterator, and compute it->current_x and it->hpos
9227 move_it_to (it
, IT_CHARPOS (*it
) + it
->string_from_display_prop_p
,
9228 -1, -1, -1, MOVE_TO_POS
);
9234 void *it2data
= NULL
;
9235 ptrdiff_t start_charpos
, i
;
9237 /* Start at the beginning of the screen line containing IT's
9238 position. This may actually move vertically backwards,
9239 in case of overlays, so adjust dvpos accordingly. */
9241 move_it_vertically_backward (it
, 0);
9244 /* Go back -DVPOS visible lines and reseat the iterator there. */
9245 start_charpos
= IT_CHARPOS (*it
);
9246 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
9247 back_to_previous_visible_line_start (it
);
9248 reseat (it
, it
->current
.pos
, 1);
9250 /* Move further back if we end up in a string or an image. */
9251 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
9253 /* First try to move to start of display line. */
9255 move_it_vertically_backward (it
, 0);
9257 if (IT_POS_VALID_AFTER_MOVE_P (it
))
9259 /* If start of line is still in string or image,
9260 move further back. */
9261 back_to_previous_visible_line_start (it
);
9262 reseat (it
, it
->current
.pos
, 1);
9266 it
->current_x
= it
->hpos
= 0;
9268 /* Above call may have moved too far if continuation lines
9269 are involved. Scan forward and see if it did. */
9270 SAVE_IT (it2
, *it
, it2data
);
9271 it2
.vpos
= it2
.current_y
= 0;
9272 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
9273 it
->vpos
-= it2
.vpos
;
9274 it
->current_y
-= it2
.current_y
;
9275 it
->current_x
= it
->hpos
= 0;
9277 /* If we moved too far back, move IT some lines forward. */
9278 if (it2
.vpos
> -dvpos
)
9280 int delta
= it2
.vpos
+ dvpos
;
9282 RESTORE_IT (&it2
, &it2
, it2data
);
9283 SAVE_IT (it2
, *it
, it2data
);
9284 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
9285 /* Move back again if we got too far ahead. */
9286 if (IT_CHARPOS (*it
) >= start_charpos
)
9287 RESTORE_IT (it
, &it2
, it2data
);
9289 bidi_unshelve_cache (it2data
, 1);
9292 RESTORE_IT (it
, it
, it2data
);
9296 /* Return 1 if IT points into the middle of a display vector. */
9299 in_display_vector_p (struct it
*it
)
9301 return (it
->method
== GET_FROM_DISPLAY_VECTOR
9302 && it
->current
.dpvec_index
> 0
9303 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
9307 /***********************************************************************
9309 ***********************************************************************/
9312 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
9316 add_to_log (const char *format
, Lisp_Object arg1
, Lisp_Object arg2
)
9318 Lisp_Object args
[3];
9319 Lisp_Object msg
, fmt
;
9322 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
9326 GCPRO4 (fmt
, msg
, arg1
, arg2
);
9328 args
[0] = fmt
= build_string (format
);
9331 msg
= Fformat (3, args
);
9333 len
= SBYTES (msg
) + 1;
9334 buffer
= SAFE_ALLOCA (len
);
9335 memcpy (buffer
, SDATA (msg
), len
);
9337 message_dolog (buffer
, len
- 1, 1, 0);
9344 /* Output a newline in the *Messages* buffer if "needs" one. */
9347 message_log_maybe_newline (void)
9349 if (message_log_need_newline
)
9350 message_dolog ("", 0, 1, 0);
9354 /* Add a string M of length NBYTES to the message log, optionally
9355 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
9356 nonzero, means interpret the contents of M as multibyte. This
9357 function calls low-level routines in order to bypass text property
9358 hooks, etc. which might not be safe to run.
9360 This may GC (insert may run before/after change hooks),
9361 so the buffer M must NOT point to a Lisp string. */
9364 message_dolog (const char *m
, ptrdiff_t nbytes
, int nlflag
, int multibyte
)
9366 const unsigned char *msg
= (const unsigned char *) m
;
9368 if (!NILP (Vmemory_full
))
9371 if (!NILP (Vmessage_log_max
))
9373 struct buffer
*oldbuf
;
9374 Lisp_Object oldpoint
, oldbegv
, oldzv
;
9375 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
9376 ptrdiff_t point_at_end
= 0;
9377 ptrdiff_t zv_at_end
= 0;
9378 Lisp_Object old_deactivate_mark
;
9380 struct gcpro gcpro1
;
9382 old_deactivate_mark
= Vdeactivate_mark
;
9383 oldbuf
= current_buffer
;
9384 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
9385 bset_undo_list (current_buffer
, Qt
);
9387 oldpoint
= message_dolog_marker1
;
9388 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
9389 oldbegv
= message_dolog_marker2
;
9390 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
9391 oldzv
= message_dolog_marker3
;
9392 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
9393 GCPRO1 (old_deactivate_mark
);
9401 BEGV_BYTE
= BEG_BYTE
;
9404 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9406 /* Insert the string--maybe converting multibyte to single byte
9407 or vice versa, so that all the text fits the buffer. */
9409 && NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9415 /* Convert a multibyte string to single-byte
9416 for the *Message* buffer. */
9417 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
9419 c
= string_char_and_length (msg
+ i
, &char_bytes
);
9420 work
[0] = (ASCII_CHAR_P (c
)
9422 : multibyte_char_to_unibyte (c
));
9423 insert_1_both (work
, 1, 1, 1, 0, 0);
9426 else if (! multibyte
9427 && ! NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9431 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9432 /* Convert a single-byte string to multibyte
9433 for the *Message* buffer. */
9434 for (i
= 0; i
< nbytes
; i
++)
9437 MAKE_CHAR_MULTIBYTE (c
);
9438 char_bytes
= CHAR_STRING (c
, str
);
9439 insert_1_both ((char *) str
, 1, char_bytes
, 1, 0, 0);
9443 insert_1_both (m
, chars_in_text (msg
, nbytes
), nbytes
, 1, 0, 0);
9447 ptrdiff_t this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
;
9450 insert_1_both ("\n", 1, 1, 1, 0, 0);
9452 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9454 this_bol_byte
= PT_BYTE
;
9456 /* See if this line duplicates the previous one.
9457 If so, combine duplicates. */
9460 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9462 prev_bol_byte
= PT_BYTE
;
9464 dups
= message_log_check_duplicate (prev_bol_byte
,
9468 del_range_both (prev_bol
, prev_bol_byte
,
9469 this_bol
, this_bol_byte
, 0);
9472 char dupstr
[sizeof " [ times]"
9473 + INT_STRLEN_BOUND (printmax_t
)];
9475 /* If you change this format, don't forget to also
9476 change message_log_check_duplicate. */
9477 int duplen
= sprintf (dupstr
, " [%"pMd
" times]", dups
);
9478 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
9479 insert_1_both (dupstr
, duplen
, duplen
, 1, 0, 1);
9484 /* If we have more than the desired maximum number of lines
9485 in the *Messages* buffer now, delete the oldest ones.
9486 This is safe because we don't have undo in this buffer. */
9488 if (NATNUMP (Vmessage_log_max
))
9490 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
9491 -XFASTINT (Vmessage_log_max
) - 1, 0);
9492 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
9495 BEGV
= marker_position (oldbegv
);
9496 BEGV_BYTE
= marker_byte_position (oldbegv
);
9505 ZV
= marker_position (oldzv
);
9506 ZV_BYTE
= marker_byte_position (oldzv
);
9510 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9512 /* We can't do Fgoto_char (oldpoint) because it will run some
9514 TEMP_SET_PT_BOTH (marker_position (oldpoint
),
9515 marker_byte_position (oldpoint
));
9518 unchain_marker (XMARKER (oldpoint
));
9519 unchain_marker (XMARKER (oldbegv
));
9520 unchain_marker (XMARKER (oldzv
));
9522 shown
= buffer_window_count (current_buffer
) > 0;
9523 set_buffer_internal (oldbuf
);
9525 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
9526 message_log_need_newline
= !nlflag
;
9527 Vdeactivate_mark
= old_deactivate_mark
;
9532 /* We are at the end of the buffer after just having inserted a newline.
9533 (Note: We depend on the fact we won't be crossing the gap.)
9534 Check to see if the most recent message looks a lot like the previous one.
9535 Return 0 if different, 1 if the new one should just replace it, or a
9536 value N > 1 if we should also append " [N times]". */
9539 message_log_check_duplicate (ptrdiff_t prev_bol_byte
, ptrdiff_t this_bol_byte
)
9542 ptrdiff_t len
= Z_BYTE
- 1 - this_bol_byte
;
9544 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
9545 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
9547 for (i
= 0; i
< len
; i
++)
9549 if (i
>= 3 && p1
[i
- 3] == '.' && p1
[i
- 2] == '.' && p1
[i
- 1] == '.')
9557 if (*p1
++ == ' ' && *p1
++ == '[')
9560 intmax_t n
= strtoimax ((char *) p1
, &pend
, 10);
9561 if (0 < n
&& n
< INTMAX_MAX
&& strncmp (pend
, " times]\n", 8) == 0)
9568 /* Display an echo area message M with a specified length of NBYTES
9569 bytes. The string may include null characters. If M is not a
9570 string, clear out any existing message, and let the mini-buffer
9573 This function cancels echoing. */
9576 message3 (Lisp_Object m
)
9578 struct gcpro gcpro1
;
9581 clear_message (1,1);
9584 /* First flush out any partial line written with print. */
9585 message_log_maybe_newline ();
9588 ptrdiff_t nbytes
= SBYTES (m
);
9589 int multibyte
= STRING_MULTIBYTE (m
);
9591 char *buffer
= SAFE_ALLOCA (nbytes
);
9592 memcpy (buffer
, SDATA (m
), nbytes
);
9593 message_dolog (buffer
, nbytes
, 1, multibyte
);
9602 /* The non-logging version of message3.
9603 This does not cancel echoing, because it is used for echoing.
9604 Perhaps we need to make a separate function for echoing
9605 and make this cancel echoing. */
9608 message3_nolog (Lisp_Object m
)
9610 struct frame
*sf
= SELECTED_FRAME ();
9612 if (FRAME_INITIAL_P (sf
))
9614 if (noninteractive_need_newline
)
9615 putc ('\n', stderr
);
9616 noninteractive_need_newline
= 0;
9618 fwrite (SDATA (m
), SBYTES (m
), 1, stderr
);
9619 if (cursor_in_echo_area
== 0)
9620 fprintf (stderr
, "\n");
9623 /* Error messages get reported properly by cmd_error, so this must be just an
9624 informative message; if the frame hasn't really been initialized yet, just
9626 else if (INTERACTIVE
&& sf
->glyphs_initialized_p
)
9628 /* Get the frame containing the mini-buffer
9629 that the selected frame is using. */
9630 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9631 Lisp_Object frame
= XWINDOW (mini_window
)->frame
;
9632 struct frame
*f
= XFRAME (frame
);
9634 if (FRAME_VISIBLE_P (sf
) && !FRAME_VISIBLE_P (f
))
9635 Fmake_frame_visible (frame
);
9637 if (STRINGP (m
) && SCHARS (m
) > 0)
9640 if (minibuffer_auto_raise
)
9641 Fraise_frame (frame
);
9642 /* Assume we are not echoing.
9643 (If we are, echo_now will override this.) */
9644 echo_message_buffer
= Qnil
;
9647 clear_message (1, 1);
9649 do_pending_window_change (0);
9650 echo_area_display (1);
9651 do_pending_window_change (0);
9652 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
9653 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
9658 /* Display a null-terminated echo area message M. If M is 0, clear
9659 out any existing message, and let the mini-buffer text show through.
9661 The buffer M must continue to exist until after the echo area gets
9662 cleared or some other message gets displayed there. Do not pass
9663 text that is stored in a Lisp string. Do not pass text in a buffer
9664 that was alloca'd. */
9667 message1 (const char *m
)
9669 message3 (m
? make_unibyte_string (m
, strlen (m
)) : Qnil
);
9673 /* The non-logging counterpart of message1. */
9676 message1_nolog (const char *m
)
9678 message3_nolog (m
? make_unibyte_string (m
, strlen (m
)) : Qnil
);
9681 /* Display a message M which contains a single %s
9682 which gets replaced with STRING. */
9685 message_with_string (const char *m
, Lisp_Object string
, int log
)
9687 CHECK_STRING (string
);
9693 if (noninteractive_need_newline
)
9694 putc ('\n', stderr
);
9695 noninteractive_need_newline
= 0;
9696 fprintf (stderr
, m
, SDATA (string
));
9697 if (!cursor_in_echo_area
)
9698 fprintf (stderr
, "\n");
9702 else if (INTERACTIVE
)
9704 /* The frame whose minibuffer we're going to display the message on.
9705 It may be larger than the selected frame, so we need
9706 to use its buffer, not the selected frame's buffer. */
9707 Lisp_Object mini_window
;
9708 struct frame
*f
, *sf
= SELECTED_FRAME ();
9710 /* Get the frame containing the minibuffer
9711 that the selected frame is using. */
9712 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9713 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9715 /* Error messages get reported properly by cmd_error, so this must be
9716 just an informative message; if the frame hasn't really been
9717 initialized yet, just toss it. */
9718 if (f
->glyphs_initialized_p
)
9720 Lisp_Object args
[2], msg
;
9721 struct gcpro gcpro1
, gcpro2
;
9723 args
[0] = build_string (m
);
9724 args
[1] = msg
= string
;
9725 GCPRO2 (args
[0], msg
);
9728 msg
= Fformat (2, args
);
9733 message3_nolog (msg
);
9737 /* Print should start at the beginning of the message
9738 buffer next time. */
9739 message_buf_print
= 0;
9745 /* Dump an informative message to the minibuf. If M is 0, clear out
9746 any existing message, and let the mini-buffer text show through. */
9749 vmessage (const char *m
, va_list ap
)
9755 if (noninteractive_need_newline
)
9756 putc ('\n', stderr
);
9757 noninteractive_need_newline
= 0;
9758 vfprintf (stderr
, m
, ap
);
9759 if (cursor_in_echo_area
== 0)
9760 fprintf (stderr
, "\n");
9764 else if (INTERACTIVE
)
9766 /* The frame whose mini-buffer we're going to display the message
9767 on. It may be larger than the selected frame, so we need to
9768 use its buffer, not the selected frame's buffer. */
9769 Lisp_Object mini_window
;
9770 struct frame
*f
, *sf
= SELECTED_FRAME ();
9772 /* Get the frame containing the mini-buffer
9773 that the selected frame is using. */
9774 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9775 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9777 /* Error messages get reported properly by cmd_error, so this must be
9778 just an informative message; if the frame hasn't really been
9779 initialized yet, just toss it. */
9780 if (f
->glyphs_initialized_p
)
9785 ptrdiff_t maxsize
= FRAME_MESSAGE_BUF_SIZE (f
);
9786 char *message_buf
= alloca (maxsize
+ 1);
9788 len
= doprnt (message_buf
, maxsize
, m
, (char *)0, ap
);
9790 message3 (make_string (message_buf
, len
));
9795 /* Print should start at the beginning of the message
9796 buffer next time. */
9797 message_buf_print
= 0;
9803 message (const char *m
, ...)
9813 /* The non-logging version of message. */
9816 message_nolog (const char *m
, ...)
9818 Lisp_Object old_log_max
;
9821 old_log_max
= Vmessage_log_max
;
9822 Vmessage_log_max
= Qnil
;
9824 Vmessage_log_max
= old_log_max
;
9830 /* Display the current message in the current mini-buffer. This is
9831 only called from error handlers in process.c, and is not time
9835 update_echo_area (void)
9837 if (!NILP (echo_area_buffer
[0]))
9840 string
= Fcurrent_message ();
9846 /* Make sure echo area buffers in `echo_buffers' are live.
9847 If they aren't, make new ones. */
9850 ensure_echo_area_buffers (void)
9854 for (i
= 0; i
< 2; ++i
)
9855 if (!BUFFERP (echo_buffer
[i
])
9856 || !BUFFER_LIVE_P (XBUFFER (echo_buffer
[i
])))
9859 Lisp_Object old_buffer
;
9862 old_buffer
= echo_buffer
[i
];
9863 echo_buffer
[i
] = Fget_buffer_create
9864 (make_formatted_string (name
, " *Echo Area %d*", i
));
9865 bset_truncate_lines (XBUFFER (echo_buffer
[i
]), Qnil
);
9866 /* to force word wrap in echo area -
9867 it was decided to postpone this*/
9868 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
9870 for (j
= 0; j
< 2; ++j
)
9871 if (EQ (old_buffer
, echo_area_buffer
[j
]))
9872 echo_area_buffer
[j
] = echo_buffer
[i
];
9877 /* Call FN with args A1..A2 with either the current or last displayed
9878 echo_area_buffer as current buffer.
9880 WHICH zero means use the current message buffer
9881 echo_area_buffer[0]. If that is nil, choose a suitable buffer
9882 from echo_buffer[] and clear it.
9884 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
9885 suitable buffer from echo_buffer[] and clear it.
9887 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
9888 that the current message becomes the last displayed one, make
9889 choose a suitable buffer for echo_area_buffer[0], and clear it.
9891 Value is what FN returns. */
9894 with_echo_area_buffer (struct window
*w
, int which
,
9895 int (*fn
) (ptrdiff_t, Lisp_Object
),
9896 ptrdiff_t a1
, Lisp_Object a2
)
9899 int this_one
, the_other
, clear_buffer_p
, rc
;
9900 ptrdiff_t count
= SPECPDL_INDEX ();
9902 /* If buffers aren't live, make new ones. */
9903 ensure_echo_area_buffers ();
9908 this_one
= 0, the_other
= 1;
9910 this_one
= 1, the_other
= 0;
9913 this_one
= 0, the_other
= 1;
9916 /* We need a fresh one in case the current echo buffer equals
9917 the one containing the last displayed echo area message. */
9918 if (!NILP (echo_area_buffer
[this_one
])
9919 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
9920 echo_area_buffer
[this_one
] = Qnil
;
9923 /* Choose a suitable buffer from echo_buffer[] is we don't
9925 if (NILP (echo_area_buffer
[this_one
]))
9927 echo_area_buffer
[this_one
]
9928 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
9929 ? echo_buffer
[the_other
]
9930 : echo_buffer
[this_one
]);
9934 buffer
= echo_area_buffer
[this_one
];
9936 /* Don't get confused by reusing the buffer used for echoing
9937 for a different purpose. */
9938 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
9941 record_unwind_protect (unwind_with_echo_area_buffer
,
9942 with_echo_area_buffer_unwind_data (w
));
9944 /* Make the echo area buffer current. Note that for display
9945 purposes, it is not necessary that the displayed window's buffer
9946 == current_buffer, except for text property lookup. So, let's
9947 only set that buffer temporarily here without doing a full
9948 Fset_window_buffer. We must also change w->pointm, though,
9949 because otherwise an assertions in unshow_buffer fails, and Emacs
9951 set_buffer_internal_1 (XBUFFER (buffer
));
9954 wset_buffer (w
, buffer
);
9955 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
9958 bset_undo_list (current_buffer
, Qt
);
9959 bset_read_only (current_buffer
, Qnil
);
9960 specbind (Qinhibit_read_only
, Qt
);
9961 specbind (Qinhibit_modification_hooks
, Qt
);
9963 if (clear_buffer_p
&& Z
> BEG
)
9966 eassert (BEGV
>= BEG
);
9967 eassert (ZV
<= Z
&& ZV
>= BEGV
);
9971 eassert (BEGV
>= BEG
);
9972 eassert (ZV
<= Z
&& ZV
>= BEGV
);
9974 unbind_to (count
, Qnil
);
9979 /* Save state that should be preserved around the call to the function
9980 FN called in with_echo_area_buffer. */
9983 with_echo_area_buffer_unwind_data (struct window
*w
)
9986 Lisp_Object vector
, tmp
;
9988 /* Reduce consing by keeping one vector in
9989 Vwith_echo_area_save_vector. */
9990 vector
= Vwith_echo_area_save_vector
;
9991 Vwith_echo_area_save_vector
= Qnil
;
9994 vector
= Fmake_vector (make_number (7), Qnil
);
9996 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
9997 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
9998 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
10002 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
10003 ASET (vector
, i
, w
->buffer
); ++i
;
10004 ASET (vector
, i
, make_number (marker_position (w
->pointm
))); ++i
;
10005 ASET (vector
, i
, make_number (marker_byte_position (w
->pointm
))); ++i
;
10010 for (; i
< end
; ++i
)
10011 ASET (vector
, i
, Qnil
);
10014 eassert (i
== ASIZE (vector
));
10019 /* Restore global state from VECTOR which was created by
10020 with_echo_area_buffer_unwind_data. */
10023 unwind_with_echo_area_buffer (Lisp_Object vector
)
10025 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
10026 Vdeactivate_mark
= AREF (vector
, 1);
10027 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
10029 if (WINDOWP (AREF (vector
, 3)))
10032 Lisp_Object buffer
, charpos
, bytepos
;
10034 w
= XWINDOW (AREF (vector
, 3));
10035 buffer
= AREF (vector
, 4);
10036 charpos
= AREF (vector
, 5);
10037 bytepos
= AREF (vector
, 6);
10039 wset_buffer (w
, buffer
);
10040 set_marker_both (w
->pointm
, buffer
,
10041 XFASTINT (charpos
), XFASTINT (bytepos
));
10044 Vwith_echo_area_save_vector
= vector
;
10049 /* Set up the echo area for use by print functions. MULTIBYTE_P
10050 non-zero means we will print multibyte. */
10053 setup_echo_area_for_printing (int multibyte_p
)
10055 /* If we can't find an echo area any more, exit. */
10056 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
10057 Fkill_emacs (Qnil
);
10059 ensure_echo_area_buffers ();
10061 if (!message_buf_print
)
10063 /* A message has been output since the last time we printed.
10064 Choose a fresh echo area buffer. */
10065 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10066 echo_area_buffer
[0] = echo_buffer
[1];
10068 echo_area_buffer
[0] = echo_buffer
[0];
10070 /* Switch to that buffer and clear it. */
10071 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10072 bset_truncate_lines (current_buffer
, Qnil
);
10076 ptrdiff_t count
= SPECPDL_INDEX ();
10077 specbind (Qinhibit_read_only
, Qt
);
10078 /* Note that undo recording is always disabled. */
10079 del_range (BEG
, Z
);
10080 unbind_to (count
, Qnil
);
10082 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10084 /* Set up the buffer for the multibyteness we need. */
10086 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10087 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
10089 /* Raise the frame containing the echo area. */
10090 if (minibuffer_auto_raise
)
10092 struct frame
*sf
= SELECTED_FRAME ();
10093 Lisp_Object mini_window
;
10094 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10095 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
10098 message_log_maybe_newline ();
10099 message_buf_print
= 1;
10103 if (NILP (echo_area_buffer
[0]))
10105 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10106 echo_area_buffer
[0] = echo_buffer
[1];
10108 echo_area_buffer
[0] = echo_buffer
[0];
10111 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
10113 /* Someone switched buffers between print requests. */
10114 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10115 bset_truncate_lines (current_buffer
, Qnil
);
10121 /* Display an echo area message in window W. Value is non-zero if W's
10122 height is changed. If display_last_displayed_message_p is
10123 non-zero, display the message that was last displayed, otherwise
10124 display the current message. */
10127 display_echo_area (struct window
*w
)
10129 int i
, no_message_p
, window_height_changed_p
;
10131 /* Temporarily disable garbage collections while displaying the echo
10132 area. This is done because a GC can print a message itself.
10133 That message would modify the echo area buffer's contents while a
10134 redisplay of the buffer is going on, and seriously confuse
10136 ptrdiff_t count
= inhibit_garbage_collection ();
10138 /* If there is no message, we must call display_echo_area_1
10139 nevertheless because it resizes the window. But we will have to
10140 reset the echo_area_buffer in question to nil at the end because
10141 with_echo_area_buffer will sets it to an empty buffer. */
10142 i
= display_last_displayed_message_p
? 1 : 0;
10143 no_message_p
= NILP (echo_area_buffer
[i
]);
10145 window_height_changed_p
10146 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
10147 display_echo_area_1
,
10148 (intptr_t) w
, Qnil
);
10151 echo_area_buffer
[i
] = Qnil
;
10153 unbind_to (count
, Qnil
);
10154 return window_height_changed_p
;
10158 /* Helper for display_echo_area. Display the current buffer which
10159 contains the current echo area message in window W, a mini-window,
10160 a pointer to which is passed in A1. A2..A4 are currently not used.
10161 Change the height of W so that all of the message is displayed.
10162 Value is non-zero if height of W was changed. */
10165 display_echo_area_1 (ptrdiff_t a1
, Lisp_Object a2
)
10168 struct window
*w
= (struct window
*) i1
;
10169 Lisp_Object window
;
10170 struct text_pos start
;
10171 int window_height_changed_p
= 0;
10173 /* Do this before displaying, so that we have a large enough glyph
10174 matrix for the display. If we can't get enough space for the
10175 whole text, display the last N lines. That works by setting w->start. */
10176 window_height_changed_p
= resize_mini_window (w
, 0);
10178 /* Use the starting position chosen by resize_mini_window. */
10179 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
10182 clear_glyph_matrix (w
->desired_matrix
);
10183 XSETWINDOW (window
, w
);
10184 try_window (window
, start
, 0);
10186 return window_height_changed_p
;
10190 /* Resize the echo area window to exactly the size needed for the
10191 currently displayed message, if there is one. If a mini-buffer
10192 is active, don't shrink it. */
10195 resize_echo_area_exactly (void)
10197 if (BUFFERP (echo_area_buffer
[0])
10198 && WINDOWP (echo_area_window
))
10200 struct window
*w
= XWINDOW (echo_area_window
);
10202 Lisp_Object resize_exactly
;
10204 if (minibuf_level
== 0)
10205 resize_exactly
= Qt
;
10207 resize_exactly
= Qnil
;
10209 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
10210 (intptr_t) w
, resize_exactly
);
10213 ++windows_or_buffers_changed
;
10214 ++update_mode_lines
;
10215 redisplay_internal ();
10221 /* Callback function for with_echo_area_buffer, when used from
10222 resize_echo_area_exactly. A1 contains a pointer to the window to
10223 resize, EXACTLY non-nil means resize the mini-window exactly to the
10224 size of the text displayed. A3 and A4 are not used. Value is what
10225 resize_mini_window returns. */
10228 resize_mini_window_1 (ptrdiff_t a1
, Lisp_Object exactly
)
10231 return resize_mini_window ((struct window
*) i1
, !NILP (exactly
));
10235 /* Resize mini-window W to fit the size of its contents. EXACT_P
10236 means size the window exactly to the size needed. Otherwise, it's
10237 only enlarged until W's buffer is empty.
10239 Set W->start to the right place to begin display. If the whole
10240 contents fit, start at the beginning. Otherwise, start so as
10241 to make the end of the contents appear. This is particularly
10242 important for y-or-n-p, but seems desirable generally.
10244 Value is non-zero if the window height has been changed. */
10247 resize_mini_window (struct window
*w
, int exact_p
)
10249 struct frame
*f
= XFRAME (w
->frame
);
10250 int window_height_changed_p
= 0;
10252 eassert (MINI_WINDOW_P (w
));
10254 /* By default, start display at the beginning. */
10255 set_marker_both (w
->start
, w
->buffer
,
10256 BUF_BEGV (XBUFFER (w
->buffer
)),
10257 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
10259 /* Don't resize windows while redisplaying a window; it would
10260 confuse redisplay functions when the size of the window they are
10261 displaying changes from under them. Such a resizing can happen,
10262 for instance, when which-func prints a long message while
10263 we are running fontification-functions. We're running these
10264 functions with safe_call which binds inhibit-redisplay to t. */
10265 if (!NILP (Vinhibit_redisplay
))
10268 /* Nil means don't try to resize. */
10269 if (NILP (Vresize_mini_windows
)
10270 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
10273 if (!FRAME_MINIBUF_ONLY_P (f
))
10276 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
10277 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
10279 EMACS_INT max_height
;
10280 int unit
= FRAME_LINE_HEIGHT (f
);
10281 struct text_pos start
;
10282 struct buffer
*old_current_buffer
= NULL
;
10284 if (current_buffer
!= XBUFFER (w
->buffer
))
10286 old_current_buffer
= current_buffer
;
10287 set_buffer_internal (XBUFFER (w
->buffer
));
10290 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10292 /* Compute the max. number of lines specified by the user. */
10293 if (FLOATP (Vmax_mini_window_height
))
10294 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
10295 else if (INTEGERP (Vmax_mini_window_height
))
10296 max_height
= XINT (Vmax_mini_window_height
);
10298 max_height
= total_height
/ 4;
10300 /* Correct that max. height if it's bogus. */
10301 max_height
= clip_to_bounds (1, max_height
, total_height
);
10303 /* Find out the height of the text in the window. */
10304 if (it
.line_wrap
== TRUNCATE
)
10309 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
10310 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
10311 height
= it
.current_y
+ last_height
;
10313 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
10314 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
10315 height
= (height
+ unit
- 1) / unit
;
10318 /* Compute a suitable window start. */
10319 if (height
> max_height
)
10321 height
= max_height
;
10322 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10323 move_it_vertically_backward (&it
, (height
- 1) * unit
);
10324 start
= it
.current
.pos
;
10327 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
10328 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
10330 if (EQ (Vresize_mini_windows
, Qgrow_only
))
10332 /* Let it grow only, until we display an empty message, in which
10333 case the window shrinks again. */
10334 if (height
> WINDOW_TOTAL_LINES (w
))
10336 int old_height
= WINDOW_TOTAL_LINES (w
);
10337 freeze_window_starts (f
, 1);
10338 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10339 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10341 else if (height
< WINDOW_TOTAL_LINES (w
)
10342 && (exact_p
|| BEGV
== ZV
))
10344 int old_height
= WINDOW_TOTAL_LINES (w
);
10345 freeze_window_starts (f
, 0);
10346 shrink_mini_window (w
);
10347 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10352 /* Always resize to exact size needed. */
10353 if (height
> WINDOW_TOTAL_LINES (w
))
10355 int old_height
= WINDOW_TOTAL_LINES (w
);
10356 freeze_window_starts (f
, 1);
10357 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10358 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10360 else if (height
< WINDOW_TOTAL_LINES (w
))
10362 int old_height
= WINDOW_TOTAL_LINES (w
);
10363 freeze_window_starts (f
, 0);
10364 shrink_mini_window (w
);
10368 freeze_window_starts (f
, 1);
10369 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10372 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10376 if (old_current_buffer
)
10377 set_buffer_internal (old_current_buffer
);
10380 return window_height_changed_p
;
10384 /* Value is the current message, a string, or nil if there is no
10385 current message. */
10388 current_message (void)
10392 if (!BUFFERP (echo_area_buffer
[0]))
10396 with_echo_area_buffer (0, 0, current_message_1
,
10397 (intptr_t) &msg
, Qnil
);
10399 echo_area_buffer
[0] = Qnil
;
10407 current_message_1 (ptrdiff_t a1
, Lisp_Object a2
)
10410 Lisp_Object
*msg
= (Lisp_Object
*) i1
;
10413 *msg
= make_buffer_string (BEG
, Z
, 1);
10420 /* Push the current message on Vmessage_stack for later restoration
10421 by restore_message. Value is non-zero if the current message isn't
10422 empty. This is a relatively infrequent operation, so it's not
10423 worth optimizing. */
10426 push_message (void)
10428 Lisp_Object msg
= current_message ();
10429 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
10430 return STRINGP (msg
);
10434 /* Restore message display from the top of Vmessage_stack. */
10437 restore_message (void)
10439 eassert (CONSP (Vmessage_stack
));
10440 message3_nolog (XCAR (Vmessage_stack
));
10444 /* Handler for record_unwind_protect calling pop_message. */
10447 pop_message_unwind (Lisp_Object dummy
)
10453 /* Pop the top-most entry off Vmessage_stack. */
10458 eassert (CONSP (Vmessage_stack
));
10459 Vmessage_stack
= XCDR (Vmessage_stack
);
10463 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
10464 exits. If the stack is not empty, we have a missing pop_message
10468 check_message_stack (void)
10470 if (!NILP (Vmessage_stack
))
10475 /* Truncate to NCHARS what will be displayed in the echo area the next
10476 time we display it---but don't redisplay it now. */
10479 truncate_echo_area (ptrdiff_t nchars
)
10482 echo_area_buffer
[0] = Qnil
;
10483 else if (!noninteractive
10485 && !NILP (echo_area_buffer
[0]))
10487 struct frame
*sf
= SELECTED_FRAME ();
10488 /* Error messages get reported properly by cmd_error, so this must be
10489 just an informative message; if the frame hasn't really been
10490 initialized yet, just toss it. */
10491 if (sf
->glyphs_initialized_p
)
10492 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
);
10497 /* Helper function for truncate_echo_area. Truncate the current
10498 message to at most NCHARS characters. */
10501 truncate_message_1 (ptrdiff_t nchars
, Lisp_Object a2
)
10503 if (BEG
+ nchars
< Z
)
10504 del_range (BEG
+ nchars
, Z
);
10506 echo_area_buffer
[0] = Qnil
;
10510 /* Set the current message to STRING. */
10513 set_message (Lisp_Object string
)
10515 eassert (STRINGP (string
));
10517 message_enable_multibyte
= STRING_MULTIBYTE (string
);
10519 with_echo_area_buffer (0, -1, set_message_1
, 0, string
);
10520 message_buf_print
= 0;
10521 help_echo_showing_p
= 0;
10523 if (STRINGP (Vdebug_on_message
)
10524 && fast_string_match (Vdebug_on_message
, string
) >= 0)
10525 call_debugger (list2 (Qerror
, string
));
10529 /* Helper function for set_message. First argument is ignored and second
10530 argument has the same meaning as for set_message.
10531 This function is called with the echo area buffer being current. */
10534 set_message_1 (ptrdiff_t a1
, Lisp_Object string
)
10536 eassert (STRINGP (string
));
10538 /* Change multibyteness of the echo buffer appropriately. */
10539 if (message_enable_multibyte
10540 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10541 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
10543 bset_truncate_lines (current_buffer
, message_truncate_lines
? Qt
: Qnil
);
10544 if (!NILP (BVAR (current_buffer
, bidi_display_reordering
)))
10545 bset_bidi_paragraph_direction (current_buffer
, Qleft_to_right
);
10547 /* Insert new message at BEG. */
10548 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10550 /* This function takes care of single/multibyte conversion.
10551 We just have to ensure that the echo area buffer has the right
10552 setting of enable_multibyte_characters. */
10553 insert_from_string (string
, 0, 0, SCHARS (string
), SBYTES (string
), 1);
10559 /* Clear messages. CURRENT_P non-zero means clear the current
10560 message. LAST_DISPLAYED_P non-zero means clear the message
10564 clear_message (int current_p
, int last_displayed_p
)
10568 echo_area_buffer
[0] = Qnil
;
10569 message_cleared_p
= 1;
10572 if (last_displayed_p
)
10573 echo_area_buffer
[1] = Qnil
;
10575 message_buf_print
= 0;
10578 /* Clear garbaged frames.
10580 This function is used where the old redisplay called
10581 redraw_garbaged_frames which in turn called redraw_frame which in
10582 turn called clear_frame. The call to clear_frame was a source of
10583 flickering. I believe a clear_frame is not necessary. It should
10584 suffice in the new redisplay to invalidate all current matrices,
10585 and ensure a complete redisplay of all windows. */
10588 clear_garbaged_frames (void)
10590 if (frame_garbaged
)
10592 Lisp_Object tail
, frame
;
10593 int changed_count
= 0;
10595 FOR_EACH_FRAME (tail
, frame
)
10597 struct frame
*f
= XFRAME (frame
);
10599 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
10604 f
->force_flush_display_p
= 1;
10606 clear_current_matrices (f
);
10613 frame_garbaged
= 0;
10615 ++windows_or_buffers_changed
;
10620 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
10621 is non-zero update selected_frame. Value is non-zero if the
10622 mini-windows height has been changed. */
10625 echo_area_display (int update_frame_p
)
10627 Lisp_Object mini_window
;
10630 int window_height_changed_p
= 0;
10631 struct frame
*sf
= SELECTED_FRAME ();
10633 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10634 w
= XWINDOW (mini_window
);
10635 f
= XFRAME (WINDOW_FRAME (w
));
10637 /* Don't display if frame is invisible or not yet initialized. */
10638 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
10641 #ifdef HAVE_WINDOW_SYSTEM
10642 /* When Emacs starts, selected_frame may be the initial terminal
10643 frame. If we let this through, a message would be displayed on
10645 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
10647 #endif /* HAVE_WINDOW_SYSTEM */
10649 /* Redraw garbaged frames. */
10650 clear_garbaged_frames ();
10652 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
10654 echo_area_window
= mini_window
;
10655 window_height_changed_p
= display_echo_area (w
);
10656 w
->must_be_updated_p
= 1;
10658 /* Update the display, unless called from redisplay_internal.
10659 Also don't update the screen during redisplay itself. The
10660 update will happen at the end of redisplay, and an update
10661 here could cause confusion. */
10662 if (update_frame_p
&& !redisplaying_p
)
10666 /* If the display update has been interrupted by pending
10667 input, update mode lines in the frame. Due to the
10668 pending input, it might have been that redisplay hasn't
10669 been called, so that mode lines above the echo area are
10670 garbaged. This looks odd, so we prevent it here. */
10671 if (!display_completed
)
10672 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
10674 if (window_height_changed_p
10675 /* Don't do this if Emacs is shutting down. Redisplay
10676 needs to run hooks. */
10677 && !NILP (Vrun_hooks
))
10679 /* Must update other windows. Likewise as in other
10680 cases, don't let this update be interrupted by
10682 ptrdiff_t count
= SPECPDL_INDEX ();
10683 specbind (Qredisplay_dont_pause
, Qt
);
10684 windows_or_buffers_changed
= 1;
10685 redisplay_internal ();
10686 unbind_to (count
, Qnil
);
10688 else if (FRAME_WINDOW_P (f
) && n
== 0)
10690 /* Window configuration is the same as before.
10691 Can do with a display update of the echo area,
10692 unless we displayed some mode lines. */
10693 update_single_window (w
, 1);
10694 FRAME_RIF (f
)->flush_display (f
);
10697 update_frame (f
, 1, 1);
10699 /* If cursor is in the echo area, make sure that the next
10700 redisplay displays the minibuffer, so that the cursor will
10701 be replaced with what the minibuffer wants. */
10702 if (cursor_in_echo_area
)
10703 ++windows_or_buffers_changed
;
10706 else if (!EQ (mini_window
, selected_window
))
10707 windows_or_buffers_changed
++;
10709 /* Last displayed message is now the current message. */
10710 echo_area_buffer
[1] = echo_area_buffer
[0];
10711 /* Inform read_char that we're not echoing. */
10712 echo_message_buffer
= Qnil
;
10714 /* Prevent redisplay optimization in redisplay_internal by resetting
10715 this_line_start_pos. This is done because the mini-buffer now
10716 displays the message instead of its buffer text. */
10717 if (EQ (mini_window
, selected_window
))
10718 CHARPOS (this_line_start_pos
) = 0;
10720 return window_height_changed_p
;
10723 /* Nonzero if the current window's buffer is shown in more than one
10724 window and was modified since last redisplay. */
10727 buffer_shared_and_changed (void)
10729 return (buffer_window_count (current_buffer
) > 1
10730 && UNCHANGED_MODIFIED
< MODIFF
);
10733 /* Nonzero if W doesn't reflect the actual state of current buffer due
10734 to its text or overlays change. FIXME: this may be called when
10735 XBUFFER (w->buffer) != current_buffer, which looks suspicious. */
10738 window_outdated (struct window
*w
)
10740 return (w
->last_modified
< MODIFF
10741 || w
->last_overlay_modified
< OVERLAY_MODIFF
);
10744 /* Nonzero if W's buffer was changed but not saved or Transient Mark mode
10745 is enabled and mark of W's buffer was changed since last W's update. */
10748 window_buffer_changed (struct window
*w
)
10750 struct buffer
*b
= XBUFFER (w
->buffer
);
10752 eassert (BUFFER_LIVE_P (b
));
10754 return (((BUF_SAVE_MODIFF (b
) < BUF_MODIFF (b
)) != w
->last_had_star
)
10755 || ((!NILP (Vtransient_mark_mode
) && !NILP (BVAR (b
, mark_active
)))
10756 != (w
->region_showing
!= 0)));
10759 /* Nonzero if W has %c in its mode line and mode line should be updated. */
10762 mode_line_update_needed (struct window
*w
)
10764 return (w
->column_number_displayed
!= -1
10765 && !(PT
== w
->last_point
&& !window_outdated (w
))
10766 && (w
->column_number_displayed
!= current_column ()));
10769 /***********************************************************************
10770 Mode Lines and Frame Titles
10771 ***********************************************************************/
10773 /* A buffer for constructing non-propertized mode-line strings and
10774 frame titles in it; allocated from the heap in init_xdisp and
10775 resized as needed in store_mode_line_noprop_char. */
10777 static char *mode_line_noprop_buf
;
10779 /* The buffer's end, and a current output position in it. */
10781 static char *mode_line_noprop_buf_end
;
10782 static char *mode_line_noprop_ptr
;
10784 #define MODE_LINE_NOPROP_LEN(start) \
10785 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
10788 MODE_LINE_DISPLAY
= 0,
10792 } mode_line_target
;
10794 /* Alist that caches the results of :propertize.
10795 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
10796 static Lisp_Object mode_line_proptrans_alist
;
10798 /* List of strings making up the mode-line. */
10799 static Lisp_Object mode_line_string_list
;
10801 /* Base face property when building propertized mode line string. */
10802 static Lisp_Object mode_line_string_face
;
10803 static Lisp_Object mode_line_string_face_prop
;
10806 /* Unwind data for mode line strings */
10808 static Lisp_Object Vmode_line_unwind_vector
;
10811 format_mode_line_unwind_data (struct frame
*target_frame
,
10812 struct buffer
*obuf
,
10814 int save_proptrans
)
10816 Lisp_Object vector
, tmp
;
10818 /* Reduce consing by keeping one vector in
10819 Vwith_echo_area_save_vector. */
10820 vector
= Vmode_line_unwind_vector
;
10821 Vmode_line_unwind_vector
= Qnil
;
10824 vector
= Fmake_vector (make_number (10), Qnil
);
10826 ASET (vector
, 0, make_number (mode_line_target
));
10827 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
10828 ASET (vector
, 2, mode_line_string_list
);
10829 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
10830 ASET (vector
, 4, mode_line_string_face
);
10831 ASET (vector
, 5, mode_line_string_face_prop
);
10834 XSETBUFFER (tmp
, obuf
);
10837 ASET (vector
, 6, tmp
);
10838 ASET (vector
, 7, owin
);
10841 /* Similarly to `with-selected-window', if the operation selects
10842 a window on another frame, we must restore that frame's
10843 selected window, and (for a tty) the top-frame. */
10844 ASET (vector
, 8, target_frame
->selected_window
);
10845 if (FRAME_TERMCAP_P (target_frame
))
10846 ASET (vector
, 9, FRAME_TTY (target_frame
)->top_frame
);
10853 unwind_format_mode_line (Lisp_Object vector
)
10855 Lisp_Object old_window
= AREF (vector
, 7);
10856 Lisp_Object target_frame_window
= AREF (vector
, 8);
10857 Lisp_Object old_top_frame
= AREF (vector
, 9);
10859 mode_line_target
= XINT (AREF (vector
, 0));
10860 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
10861 mode_line_string_list
= AREF (vector
, 2);
10862 if (! EQ (AREF (vector
, 3), Qt
))
10863 mode_line_proptrans_alist
= AREF (vector
, 3);
10864 mode_line_string_face
= AREF (vector
, 4);
10865 mode_line_string_face_prop
= AREF (vector
, 5);
10867 /* Select window before buffer, since it may change the buffer. */
10868 if (!NILP (old_window
))
10870 /* If the operation that we are unwinding had selected a window
10871 on a different frame, reset its frame-selected-window. For a
10872 text terminal, reset its top-frame if necessary. */
10873 if (!NILP (target_frame_window
))
10876 = WINDOW_FRAME (XWINDOW (target_frame_window
));
10878 if (!EQ (frame
, WINDOW_FRAME (XWINDOW (old_window
))))
10879 Fselect_window (target_frame_window
, Qt
);
10881 if (!NILP (old_top_frame
) && !EQ (old_top_frame
, frame
))
10882 Fselect_frame (old_top_frame
, Qt
);
10885 Fselect_window (old_window
, Qt
);
10888 if (!NILP (AREF (vector
, 6)))
10890 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
10891 ASET (vector
, 6, Qnil
);
10894 Vmode_line_unwind_vector
= vector
;
10899 /* Store a single character C for the frame title in mode_line_noprop_buf.
10900 Re-allocate mode_line_noprop_buf if necessary. */
10903 store_mode_line_noprop_char (char c
)
10905 /* If output position has reached the end of the allocated buffer,
10906 increase the buffer's size. */
10907 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
10909 ptrdiff_t len
= MODE_LINE_NOPROP_LEN (0);
10910 ptrdiff_t size
= len
;
10911 mode_line_noprop_buf
=
10912 xpalloc (mode_line_noprop_buf
, &size
, 1, STRING_BYTES_BOUND
, 1);
10913 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
10914 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
10917 *mode_line_noprop_ptr
++ = c
;
10921 /* Store part of a frame title in mode_line_noprop_buf, beginning at
10922 mode_line_noprop_ptr. STRING is the string to store. Do not copy
10923 characters that yield more columns than PRECISION; PRECISION <= 0
10924 means copy the whole string. Pad with spaces until FIELD_WIDTH
10925 number of characters have been copied; FIELD_WIDTH <= 0 means don't
10926 pad. Called from display_mode_element when it is used to build a
10930 store_mode_line_noprop (const char *string
, int field_width
, int precision
)
10932 const unsigned char *str
= (const unsigned char *) string
;
10934 ptrdiff_t dummy
, nbytes
;
10936 /* Copy at most PRECISION chars from STR. */
10937 nbytes
= strlen (string
);
10938 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
10940 store_mode_line_noprop_char (*str
++);
10942 /* Fill up with spaces until FIELD_WIDTH reached. */
10943 while (field_width
> 0
10944 && n
< field_width
)
10946 store_mode_line_noprop_char (' ');
10953 /***********************************************************************
10955 ***********************************************************************/
10957 #ifdef HAVE_WINDOW_SYSTEM
10959 /* Set the title of FRAME, if it has changed. The title format is
10960 Vicon_title_format if FRAME is iconified, otherwise it is
10961 frame_title_format. */
10964 x_consider_frame_title (Lisp_Object frame
)
10966 struct frame
*f
= XFRAME (frame
);
10968 if (FRAME_WINDOW_P (f
)
10969 || FRAME_MINIBUF_ONLY_P (f
)
10970 || f
->explicit_name
)
10972 /* Do we have more than one visible frame on this X display? */
10973 Lisp_Object tail
, other_frame
, fmt
;
10974 ptrdiff_t title_start
;
10978 ptrdiff_t count
= SPECPDL_INDEX ();
10980 FOR_EACH_FRAME (tail
, other_frame
)
10982 struct frame
*tf
= XFRAME (other_frame
);
10985 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
10986 && !FRAME_MINIBUF_ONLY_P (tf
)
10987 && !EQ (other_frame
, tip_frame
)
10988 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
10992 /* Set global variable indicating that multiple frames exist. */
10993 multiple_frames
= CONSP (tail
);
10995 /* Switch to the buffer of selected window of the frame. Set up
10996 mode_line_target so that display_mode_element will output into
10997 mode_line_noprop_buf; then display the title. */
10998 record_unwind_protect (unwind_format_mode_line
,
10999 format_mode_line_unwind_data
11000 (f
, current_buffer
, selected_window
, 0));
11002 Fselect_window (f
->selected_window
, Qt
);
11003 set_buffer_internal_1
11004 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
11005 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
11007 mode_line_target
= MODE_LINE_TITLE
;
11008 title_start
= MODE_LINE_NOPROP_LEN (0);
11009 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
11010 NULL
, DEFAULT_FACE_ID
);
11011 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
11012 len
= MODE_LINE_NOPROP_LEN (title_start
);
11013 title
= mode_line_noprop_buf
+ title_start
;
11014 unbind_to (count
, Qnil
);
11016 /* Set the title only if it's changed. This avoids consing in
11017 the common case where it hasn't. (If it turns out that we've
11018 already wasted too much time by walking through the list with
11019 display_mode_element, then we might need to optimize at a
11020 higher level than this.) */
11021 if (! STRINGP (f
->name
)
11022 || SBYTES (f
->name
) != len
11023 || memcmp (title
, SDATA (f
->name
), len
) != 0)
11024 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
11028 #endif /* not HAVE_WINDOW_SYSTEM */
11031 /***********************************************************************
11033 ***********************************************************************/
11036 /* Prepare for redisplay by updating menu-bar item lists when
11037 appropriate. This can call eval. */
11040 prepare_menu_bars (void)
11043 struct gcpro gcpro1
, gcpro2
;
11045 Lisp_Object tooltip_frame
;
11047 #ifdef HAVE_WINDOW_SYSTEM
11048 tooltip_frame
= tip_frame
;
11050 tooltip_frame
= Qnil
;
11053 /* Update all frame titles based on their buffer names, etc. We do
11054 this before the menu bars so that the buffer-menu will show the
11055 up-to-date frame titles. */
11056 #ifdef HAVE_WINDOW_SYSTEM
11057 if (windows_or_buffers_changed
|| update_mode_lines
)
11059 Lisp_Object tail
, frame
;
11061 FOR_EACH_FRAME (tail
, frame
)
11063 f
= XFRAME (frame
);
11064 if (!EQ (frame
, tooltip_frame
)
11065 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
11066 x_consider_frame_title (frame
);
11069 #endif /* HAVE_WINDOW_SYSTEM */
11071 /* Update the menu bar item lists, if appropriate. This has to be
11072 done before any actual redisplay or generation of display lines. */
11073 all_windows
= (update_mode_lines
11074 || buffer_shared_and_changed ()
11075 || windows_or_buffers_changed
);
11078 Lisp_Object tail
, frame
;
11079 ptrdiff_t count
= SPECPDL_INDEX ();
11080 /* 1 means that update_menu_bar has run its hooks
11081 so any further calls to update_menu_bar shouldn't do so again. */
11082 int menu_bar_hooks_run
= 0;
11084 record_unwind_save_match_data ();
11086 FOR_EACH_FRAME (tail
, frame
)
11088 f
= XFRAME (frame
);
11090 /* Ignore tooltip frame. */
11091 if (EQ (frame
, tooltip_frame
))
11094 /* If a window on this frame changed size, report that to
11095 the user and clear the size-change flag. */
11096 if (FRAME_WINDOW_SIZES_CHANGED (f
))
11098 Lisp_Object functions
;
11100 /* Clear flag first in case we get an error below. */
11101 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
11102 functions
= Vwindow_size_change_functions
;
11103 GCPRO2 (tail
, functions
);
11105 while (CONSP (functions
))
11107 if (!EQ (XCAR (functions
), Qt
))
11108 call1 (XCAR (functions
), frame
);
11109 functions
= XCDR (functions
);
11115 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
11116 #ifdef HAVE_WINDOW_SYSTEM
11117 update_tool_bar (f
, 0);
11120 if (windows_or_buffers_changed
11123 (f
, Fbuffer_modified_p (XWINDOW (f
->selected_window
)->buffer
));
11128 unbind_to (count
, Qnil
);
11132 struct frame
*sf
= SELECTED_FRAME ();
11133 update_menu_bar (sf
, 1, 0);
11134 #ifdef HAVE_WINDOW_SYSTEM
11135 update_tool_bar (sf
, 1);
11141 /* Update the menu bar item list for frame F. This has to be done
11142 before we start to fill in any display lines, because it can call
11145 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
11147 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
11148 already ran the menu bar hooks for this redisplay, so there
11149 is no need to run them again. The return value is the
11150 updated value of this flag, to pass to the next call. */
11153 update_menu_bar (struct frame
*f
, int save_match_data
, int hooks_run
)
11155 Lisp_Object window
;
11156 register struct window
*w
;
11158 /* If called recursively during a menu update, do nothing. This can
11159 happen when, for instance, an activate-menubar-hook causes a
11161 if (inhibit_menubar_update
)
11164 window
= FRAME_SELECTED_WINDOW (f
);
11165 w
= XWINDOW (window
);
11167 if (FRAME_WINDOW_P (f
)
11169 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11170 || defined (HAVE_NS) || defined (USE_GTK)
11171 FRAME_EXTERNAL_MENU_BAR (f
)
11173 FRAME_MENU_BAR_LINES (f
) > 0
11175 : FRAME_MENU_BAR_LINES (f
) > 0)
11177 /* If the user has switched buffers or windows, we need to
11178 recompute to reflect the new bindings. But we'll
11179 recompute when update_mode_lines is set too; that means
11180 that people can use force-mode-line-update to request
11181 that the menu bar be recomputed. The adverse effect on
11182 the rest of the redisplay algorithm is about the same as
11183 windows_or_buffers_changed anyway. */
11184 if (windows_or_buffers_changed
11185 /* This used to test w->update_mode_line, but we believe
11186 there is no need to recompute the menu in that case. */
11187 || update_mode_lines
11188 || window_buffer_changed (w
))
11190 struct buffer
*prev
= current_buffer
;
11191 ptrdiff_t count
= SPECPDL_INDEX ();
11193 specbind (Qinhibit_menubar_update
, Qt
);
11195 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11196 if (save_match_data
)
11197 record_unwind_save_match_data ();
11198 if (NILP (Voverriding_local_map_menu_flag
))
11200 specbind (Qoverriding_terminal_local_map
, Qnil
);
11201 specbind (Qoverriding_local_map
, Qnil
);
11206 /* Run the Lucid hook. */
11207 safe_run_hooks (Qactivate_menubar_hook
);
11209 /* If it has changed current-menubar from previous value,
11210 really recompute the menu-bar from the value. */
11211 if (! NILP (Vlucid_menu_bar_dirty_flag
))
11212 call0 (Qrecompute_lucid_menubar
);
11214 safe_run_hooks (Qmenu_bar_update_hook
);
11219 XSETFRAME (Vmenu_updating_frame
, f
);
11220 fset_menu_bar_items (f
, menu_bar_items (FRAME_MENU_BAR_ITEMS (f
)));
11222 /* Redisplay the menu bar in case we changed it. */
11223 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11224 || defined (HAVE_NS) || defined (USE_GTK)
11225 if (FRAME_WINDOW_P (f
))
11227 #if defined (HAVE_NS)
11228 /* All frames on Mac OS share the same menubar. So only
11229 the selected frame should be allowed to set it. */
11230 if (f
== SELECTED_FRAME ())
11232 set_frame_menubar (f
, 0, 0);
11235 /* On a terminal screen, the menu bar is an ordinary screen
11236 line, and this makes it get updated. */
11237 w
->update_mode_line
= 1;
11238 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11239 /* In the non-toolkit version, the menu bar is an ordinary screen
11240 line, and this makes it get updated. */
11241 w
->update_mode_line
= 1;
11242 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11244 unbind_to (count
, Qnil
);
11245 set_buffer_internal_1 (prev
);
11254 /***********************************************************************
11256 ***********************************************************************/
11258 #ifdef HAVE_WINDOW_SYSTEM
11261 Nominal cursor position -- where to draw output.
11262 HPOS and VPOS are window relative glyph matrix coordinates.
11263 X and Y are window relative pixel coordinates. */
11265 struct cursor_pos output_cursor
;
11269 Set the global variable output_cursor to CURSOR. All cursor
11270 positions are relative to updated_window. */
11273 set_output_cursor (struct cursor_pos
*cursor
)
11275 output_cursor
.hpos
= cursor
->hpos
;
11276 output_cursor
.vpos
= cursor
->vpos
;
11277 output_cursor
.x
= cursor
->x
;
11278 output_cursor
.y
= cursor
->y
;
11283 Set a nominal cursor position.
11285 HPOS and VPOS are column/row positions in a window glyph matrix. X
11286 and Y are window text area relative pixel positions.
11288 If this is done during an update, updated_window will contain the
11289 window that is being updated and the position is the future output
11290 cursor position for that window. If updated_window is null, use
11291 selected_window and display the cursor at the given position. */
11294 x_cursor_to (int vpos
, int hpos
, int y
, int x
)
11298 /* If updated_window is not set, work on selected_window. */
11299 if (updated_window
)
11300 w
= updated_window
;
11302 w
= XWINDOW (selected_window
);
11304 /* Set the output cursor. */
11305 output_cursor
.hpos
= hpos
;
11306 output_cursor
.vpos
= vpos
;
11307 output_cursor
.x
= x
;
11308 output_cursor
.y
= y
;
11310 /* If not called as part of an update, really display the cursor.
11311 This will also set the cursor position of W. */
11312 if (updated_window
== NULL
)
11315 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
11316 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
11317 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
11322 #endif /* HAVE_WINDOW_SYSTEM */
11325 /***********************************************************************
11327 ***********************************************************************/
11329 #ifdef HAVE_WINDOW_SYSTEM
11331 /* Where the mouse was last time we reported a mouse event. */
11333 FRAME_PTR last_mouse_frame
;
11335 /* Tool-bar item index of the item on which a mouse button was pressed
11338 int last_tool_bar_item
;
11340 /* Select `frame' temporarily without running all the code in
11342 FIXME: Maybe do_switch_frame should be trimmed down similarly
11343 when `norecord' is set. */
11345 fast_set_selected_frame (Lisp_Object frame
)
11347 if (!EQ (selected_frame
, frame
))
11349 selected_frame
= frame
;
11350 selected_window
= XFRAME (frame
)->selected_window
;
11355 /* Update the tool-bar item list for frame F. This has to be done
11356 before we start to fill in any display lines. Called from
11357 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
11358 and restore it here. */
11361 update_tool_bar (struct frame
*f
, int save_match_data
)
11363 #if defined (USE_GTK) || defined (HAVE_NS)
11364 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
11366 int do_update
= WINDOWP (f
->tool_bar_window
)
11367 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
11372 Lisp_Object window
;
11375 window
= FRAME_SELECTED_WINDOW (f
);
11376 w
= XWINDOW (window
);
11378 /* If the user has switched buffers or windows, we need to
11379 recompute to reflect the new bindings. But we'll
11380 recompute when update_mode_lines is set too; that means
11381 that people can use force-mode-line-update to request
11382 that the menu bar be recomputed. The adverse effect on
11383 the rest of the redisplay algorithm is about the same as
11384 windows_or_buffers_changed anyway. */
11385 if (windows_or_buffers_changed
11386 || w
->update_mode_line
11387 || update_mode_lines
11388 || window_buffer_changed (w
))
11390 struct buffer
*prev
= current_buffer
;
11391 ptrdiff_t count
= SPECPDL_INDEX ();
11392 Lisp_Object frame
, new_tool_bar
;
11393 int new_n_tool_bar
;
11394 struct gcpro gcpro1
;
11396 /* Set current_buffer to the buffer of the selected
11397 window of the frame, so that we get the right local
11399 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11401 /* Save match data, if we must. */
11402 if (save_match_data
)
11403 record_unwind_save_match_data ();
11405 /* Make sure that we don't accidentally use bogus keymaps. */
11406 if (NILP (Voverriding_local_map_menu_flag
))
11408 specbind (Qoverriding_terminal_local_map
, Qnil
);
11409 specbind (Qoverriding_local_map
, Qnil
);
11412 GCPRO1 (new_tool_bar
);
11414 /* We must temporarily set the selected frame to this frame
11415 before calling tool_bar_items, because the calculation of
11416 the tool-bar keymap uses the selected frame (see
11417 `tool-bar-make-keymap' in tool-bar.el). */
11418 eassert (EQ (selected_window
,
11419 /* Since we only explicitly preserve selected_frame,
11420 check that selected_window would be redundant. */
11421 XFRAME (selected_frame
)->selected_window
));
11422 record_unwind_protect (fast_set_selected_frame
, selected_frame
);
11423 XSETFRAME (frame
, f
);
11424 fast_set_selected_frame (frame
);
11426 /* Build desired tool-bar items from keymaps. */
11428 = tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
11431 /* Redisplay the tool-bar if we changed it. */
11432 if (new_n_tool_bar
!= f
->n_tool_bar_items
11433 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
11435 /* Redisplay that happens asynchronously due to an expose event
11436 may access f->tool_bar_items. Make sure we update both
11437 variables within BLOCK_INPUT so no such event interrupts. */
11439 fset_tool_bar_items (f
, new_tool_bar
);
11440 f
->n_tool_bar_items
= new_n_tool_bar
;
11441 w
->update_mode_line
= 1;
11447 unbind_to (count
, Qnil
);
11448 set_buffer_internal_1 (prev
);
11454 /* Set F->desired_tool_bar_string to a Lisp string representing frame
11455 F's desired tool-bar contents. F->tool_bar_items must have
11456 been set up previously by calling prepare_menu_bars. */
11459 build_desired_tool_bar_string (struct frame
*f
)
11461 int i
, size
, size_needed
;
11462 struct gcpro gcpro1
, gcpro2
, gcpro3
;
11463 Lisp_Object image
, plist
, props
;
11465 image
= plist
= props
= Qnil
;
11466 GCPRO3 (image
, plist
, props
);
11468 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
11469 Otherwise, make a new string. */
11471 /* The size of the string we might be able to reuse. */
11472 size
= (STRINGP (f
->desired_tool_bar_string
)
11473 ? SCHARS (f
->desired_tool_bar_string
)
11476 /* We need one space in the string for each image. */
11477 size_needed
= f
->n_tool_bar_items
;
11479 /* Reuse f->desired_tool_bar_string, if possible. */
11480 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
11481 fset_desired_tool_bar_string
11482 (f
, Fmake_string (make_number (size_needed
), make_number (' ')));
11485 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
11486 Fremove_text_properties (make_number (0), make_number (size
),
11487 props
, f
->desired_tool_bar_string
);
11490 /* Put a `display' property on the string for the images to display,
11491 put a `menu_item' property on tool-bar items with a value that
11492 is the index of the item in F's tool-bar item vector. */
11493 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
11495 #define PROP(IDX) \
11496 AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
11498 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
11499 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
11500 int hmargin
, vmargin
, relief
, idx
, end
;
11502 /* If image is a vector, choose the image according to the
11504 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
11505 if (VECTORP (image
))
11509 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
11510 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
11513 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
11514 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
11516 eassert (ASIZE (image
) >= idx
);
11517 image
= AREF (image
, idx
);
11522 /* Ignore invalid image specifications. */
11523 if (!valid_image_p (image
))
11526 /* Display the tool-bar button pressed, or depressed. */
11527 plist
= Fcopy_sequence (XCDR (image
));
11529 /* Compute margin and relief to draw. */
11530 relief
= (tool_bar_button_relief
>= 0
11531 ? tool_bar_button_relief
11532 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
11533 hmargin
= vmargin
= relief
;
11535 if (RANGED_INTEGERP (1, Vtool_bar_button_margin
,
11536 INT_MAX
- max (hmargin
, vmargin
)))
11538 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
11539 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
11541 else if (CONSP (Vtool_bar_button_margin
))
11543 if (RANGED_INTEGERP (1, XCAR (Vtool_bar_button_margin
),
11544 INT_MAX
- hmargin
))
11545 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
11547 if (RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin
),
11548 INT_MAX
- vmargin
))
11549 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
11552 if (auto_raise_tool_bar_buttons_p
)
11554 /* Add a `:relief' property to the image spec if the item is
11558 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
11565 /* If image is selected, display it pressed, i.e. with a
11566 negative relief. If it's not selected, display it with a
11568 plist
= Fplist_put (plist
, QCrelief
,
11570 ? make_number (-relief
)
11571 : make_number (relief
)));
11576 /* Put a margin around the image. */
11577 if (hmargin
|| vmargin
)
11579 if (hmargin
== vmargin
)
11580 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
11582 plist
= Fplist_put (plist
, QCmargin
,
11583 Fcons (make_number (hmargin
),
11584 make_number (vmargin
)));
11587 /* If button is not enabled, and we don't have special images
11588 for the disabled state, make the image appear disabled by
11589 applying an appropriate algorithm to it. */
11590 if (!enabled_p
&& idx
< 0)
11591 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
11593 /* Put a `display' text property on the string for the image to
11594 display. Put a `menu-item' property on the string that gives
11595 the start of this item's properties in the tool-bar items
11597 image
= Fcons (Qimage
, plist
);
11598 props
= list4 (Qdisplay
, image
,
11599 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
11601 /* Let the last image hide all remaining spaces in the tool bar
11602 string. The string can be longer than needed when we reuse a
11603 previous string. */
11604 if (i
+ 1 == f
->n_tool_bar_items
)
11605 end
= SCHARS (f
->desired_tool_bar_string
);
11608 Fadd_text_properties (make_number (i
), make_number (end
),
11609 props
, f
->desired_tool_bar_string
);
11617 /* Display one line of the tool-bar of frame IT->f.
11619 HEIGHT specifies the desired height of the tool-bar line.
11620 If the actual height of the glyph row is less than HEIGHT, the
11621 row's height is increased to HEIGHT, and the icons are centered
11622 vertically in the new height.
11624 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
11625 count a final empty row in case the tool-bar width exactly matches
11630 display_tool_bar_line (struct it
*it
, int height
)
11632 struct glyph_row
*row
= it
->glyph_row
;
11633 int max_x
= it
->last_visible_x
;
11634 struct glyph
*last
;
11636 prepare_desired_row (row
);
11637 row
->y
= it
->current_y
;
11639 /* Note that this isn't made use of if the face hasn't a box,
11640 so there's no need to check the face here. */
11641 it
->start_of_box_run_p
= 1;
11643 while (it
->current_x
< max_x
)
11645 int x
, n_glyphs_before
, i
, nglyphs
;
11646 struct it it_before
;
11648 /* Get the next display element. */
11649 if (!get_next_display_element (it
))
11651 /* Don't count empty row if we are counting needed tool-bar lines. */
11652 if (height
< 0 && !it
->hpos
)
11657 /* Produce glyphs. */
11658 n_glyphs_before
= row
->used
[TEXT_AREA
];
11661 PRODUCE_GLYPHS (it
);
11663 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
11665 x
= it_before
.current_x
;
11666 while (i
< nglyphs
)
11668 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
11670 if (x
+ glyph
->pixel_width
> max_x
)
11672 /* Glyph doesn't fit on line. Backtrack. */
11673 row
->used
[TEXT_AREA
] = n_glyphs_before
;
11675 /* If this is the only glyph on this line, it will never fit on the
11676 tool-bar, so skip it. But ensure there is at least one glyph,
11677 so we don't accidentally disable the tool-bar. */
11678 if (n_glyphs_before
== 0
11679 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
11685 x
+= glyph
->pixel_width
;
11689 /* Stop at line end. */
11690 if (ITERATOR_AT_END_OF_LINE_P (it
))
11693 set_iterator_to_next (it
, 1);
11698 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
11700 /* Use default face for the border below the tool bar.
11702 FIXME: When auto-resize-tool-bars is grow-only, there is
11703 no additional border below the possibly empty tool-bar lines.
11704 So to make the extra empty lines look "normal", we have to
11705 use the tool-bar face for the border too. */
11706 if (!row
->displays_text_p
&& !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
11707 it
->face_id
= DEFAULT_FACE_ID
;
11709 extend_face_to_end_of_line (it
);
11710 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
11711 last
->right_box_line_p
= 1;
11712 if (last
== row
->glyphs
[TEXT_AREA
])
11713 last
->left_box_line_p
= 1;
11715 /* Make line the desired height and center it vertically. */
11716 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
11718 /* Don't add more than one line height. */
11719 height
%= FRAME_LINE_HEIGHT (it
->f
);
11720 it
->max_ascent
+= height
/ 2;
11721 it
->max_descent
+= (height
+ 1) / 2;
11724 compute_line_metrics (it
);
11726 /* If line is empty, make it occupy the rest of the tool-bar. */
11727 if (!row
->displays_text_p
)
11729 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
11730 row
->visible_height
= row
->height
;
11731 row
->ascent
= row
->phys_ascent
= 0;
11732 row
->extra_line_spacing
= 0;
11735 row
->full_width_p
= 1;
11736 row
->continued_p
= 0;
11737 row
->truncated_on_left_p
= 0;
11738 row
->truncated_on_right_p
= 0;
11740 it
->current_x
= it
->hpos
= 0;
11741 it
->current_y
+= row
->height
;
11747 /* Max tool-bar height. */
11749 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
11750 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
11752 /* Value is the number of screen lines needed to make all tool-bar
11753 items of frame F visible. The number of actual rows needed is
11754 returned in *N_ROWS if non-NULL. */
11757 tool_bar_lines_needed (struct frame
*f
, int *n_rows
)
11759 struct window
*w
= XWINDOW (f
->tool_bar_window
);
11761 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
11762 the desired matrix, so use (unused) mode-line row as temporary row to
11763 avoid destroying the first tool-bar row. */
11764 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
11766 /* Initialize an iterator for iteration over
11767 F->desired_tool_bar_string in the tool-bar window of frame F. */
11768 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
11769 it
.first_visible_x
= 0;
11770 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
11771 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
11772 it
.paragraph_embedding
= L2R
;
11774 while (!ITERATOR_AT_END_P (&it
))
11776 clear_glyph_row (temp_row
);
11777 it
.glyph_row
= temp_row
;
11778 display_tool_bar_line (&it
, -1);
11780 clear_glyph_row (temp_row
);
11782 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
11784 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
11786 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
11790 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
11792 doc
: /* Return the number of lines occupied by the tool bar of FRAME.
11793 If FRAME is nil or omitted, use the selected frame. */)
11794 (Lisp_Object frame
)
11796 struct frame
*f
= decode_any_frame (frame
);
11800 if (WINDOWP (f
->tool_bar_window
)
11801 && (w
= XWINDOW (f
->tool_bar_window
),
11802 WINDOW_TOTAL_LINES (w
) > 0))
11804 update_tool_bar (f
, 1);
11805 if (f
->n_tool_bar_items
)
11807 build_desired_tool_bar_string (f
);
11808 nlines
= tool_bar_lines_needed (f
, NULL
);
11812 return make_number (nlines
);
11816 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
11817 height should be changed. */
11820 redisplay_tool_bar (struct frame
*f
)
11824 struct glyph_row
*row
;
11826 #if defined (USE_GTK) || defined (HAVE_NS)
11827 if (FRAME_EXTERNAL_TOOL_BAR (f
))
11828 update_frame_tool_bar (f
);
11832 /* If frame hasn't a tool-bar window or if it is zero-height, don't
11833 do anything. This means you must start with tool-bar-lines
11834 non-zero to get the auto-sizing effect. Or in other words, you
11835 can turn off tool-bars by specifying tool-bar-lines zero. */
11836 if (!WINDOWP (f
->tool_bar_window
)
11837 || (w
= XWINDOW (f
->tool_bar_window
),
11838 WINDOW_TOTAL_LINES (w
) == 0))
11841 /* Set up an iterator for the tool-bar window. */
11842 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
11843 it
.first_visible_x
= 0;
11844 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
11845 row
= it
.glyph_row
;
11847 /* Build a string that represents the contents of the tool-bar. */
11848 build_desired_tool_bar_string (f
);
11849 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
11850 /* FIXME: This should be controlled by a user option. But it
11851 doesn't make sense to have an R2L tool bar if the menu bar cannot
11852 be drawn also R2L, and making the menu bar R2L is tricky due
11853 toolkit-specific code that implements it. If an R2L tool bar is
11854 ever supported, display_tool_bar_line should also be augmented to
11855 call unproduce_glyphs like display_line and display_string
11857 it
.paragraph_embedding
= L2R
;
11859 if (f
->n_tool_bar_rows
== 0)
11863 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
11864 nlines
!= WINDOW_TOTAL_LINES (w
)))
11867 int old_height
= WINDOW_TOTAL_LINES (w
);
11869 XSETFRAME (frame
, f
);
11870 Fmodify_frame_parameters (frame
,
11871 Fcons (Fcons (Qtool_bar_lines
,
11872 make_number (nlines
)),
11874 if (WINDOW_TOTAL_LINES (w
) != old_height
)
11876 clear_glyph_matrix (w
->desired_matrix
);
11877 fonts_changed_p
= 1;
11883 /* Display as many lines as needed to display all tool-bar items. */
11885 if (f
->n_tool_bar_rows
> 0)
11887 int border
, rows
, height
, extra
;
11889 if (TYPE_RANGED_INTEGERP (int, Vtool_bar_border
))
11890 border
= XINT (Vtool_bar_border
);
11891 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
11892 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
11893 else if (EQ (Vtool_bar_border
, Qborder_width
))
11894 border
= f
->border_width
;
11900 rows
= f
->n_tool_bar_rows
;
11901 height
= max (1, (it
.last_visible_y
- border
) / rows
);
11902 extra
= it
.last_visible_y
- border
- height
* rows
;
11904 while (it
.current_y
< it
.last_visible_y
)
11907 if (extra
> 0 && rows
-- > 0)
11909 h
= (extra
+ rows
- 1) / rows
;
11912 display_tool_bar_line (&it
, height
+ h
);
11917 while (it
.current_y
< it
.last_visible_y
)
11918 display_tool_bar_line (&it
, 0);
11921 /* It doesn't make much sense to try scrolling in the tool-bar
11922 window, so don't do it. */
11923 w
->desired_matrix
->no_scrolling_p
= 1;
11924 w
->must_be_updated_p
= 1;
11926 if (!NILP (Vauto_resize_tool_bars
))
11928 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
11929 int change_height_p
= 0;
11931 /* If we couldn't display everything, change the tool-bar's
11932 height if there is room for more. */
11933 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
11934 && it
.current_y
< max_tool_bar_height
)
11935 change_height_p
= 1;
11937 row
= it
.glyph_row
- 1;
11939 /* If there are blank lines at the end, except for a partially
11940 visible blank line at the end that is smaller than
11941 FRAME_LINE_HEIGHT, change the tool-bar's height. */
11942 if (!row
->displays_text_p
11943 && row
->height
>= FRAME_LINE_HEIGHT (f
))
11944 change_height_p
= 1;
11946 /* If row displays tool-bar items, but is partially visible,
11947 change the tool-bar's height. */
11948 if (row
->displays_text_p
11949 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
11950 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
11951 change_height_p
= 1;
11953 /* Resize windows as needed by changing the `tool-bar-lines'
11954 frame parameter. */
11955 if (change_height_p
)
11958 int old_height
= WINDOW_TOTAL_LINES (w
);
11960 int nlines
= tool_bar_lines_needed (f
, &nrows
);
11962 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
11963 && !f
->minimize_tool_bar_window_p
)
11964 ? (nlines
> old_height
)
11965 : (nlines
!= old_height
));
11966 f
->minimize_tool_bar_window_p
= 0;
11968 if (change_height_p
)
11970 XSETFRAME (frame
, f
);
11971 Fmodify_frame_parameters (frame
,
11972 Fcons (Fcons (Qtool_bar_lines
,
11973 make_number (nlines
)),
11975 if (WINDOW_TOTAL_LINES (w
) != old_height
)
11977 clear_glyph_matrix (w
->desired_matrix
);
11978 f
->n_tool_bar_rows
= nrows
;
11979 fonts_changed_p
= 1;
11986 f
->minimize_tool_bar_window_p
= 0;
11991 /* Get information about the tool-bar item which is displayed in GLYPH
11992 on frame F. Return in *PROP_IDX the index where tool-bar item
11993 properties start in F->tool_bar_items. Value is zero if
11994 GLYPH doesn't display a tool-bar item. */
11997 tool_bar_item_info (struct frame
*f
, struct glyph
*glyph
, int *prop_idx
)
12003 /* This function can be called asynchronously, which means we must
12004 exclude any possibility that Fget_text_property signals an
12006 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
12007 charpos
= max (0, charpos
);
12009 /* Get the text property `menu-item' at pos. The value of that
12010 property is the start index of this item's properties in
12011 F->tool_bar_items. */
12012 prop
= Fget_text_property (make_number (charpos
),
12013 Qmenu_item
, f
->current_tool_bar_string
);
12014 if (INTEGERP (prop
))
12016 *prop_idx
= XINT (prop
);
12026 /* Get information about the tool-bar item at position X/Y on frame F.
12027 Return in *GLYPH a pointer to the glyph of the tool-bar item in
12028 the current matrix of the tool-bar window of F, or NULL if not
12029 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
12030 item in F->tool_bar_items. Value is
12032 -1 if X/Y is not on a tool-bar item
12033 0 if X/Y is on the same item that was highlighted before.
12037 get_tool_bar_item (struct frame
*f
, int x
, int y
, struct glyph
**glyph
,
12038 int *hpos
, int *vpos
, int *prop_idx
)
12040 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12041 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12044 /* Find the glyph under X/Y. */
12045 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
12046 if (*glyph
== NULL
)
12049 /* Get the start of this tool-bar item's properties in
12050 f->tool_bar_items. */
12051 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
12054 /* Is mouse on the highlighted item? */
12055 if (EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
)
12056 && *vpos
>= hlinfo
->mouse_face_beg_row
12057 && *vpos
<= hlinfo
->mouse_face_end_row
12058 && (*vpos
> hlinfo
->mouse_face_beg_row
12059 || *hpos
>= hlinfo
->mouse_face_beg_col
)
12060 && (*vpos
< hlinfo
->mouse_face_end_row
12061 || *hpos
< hlinfo
->mouse_face_end_col
12062 || hlinfo
->mouse_face_past_end
))
12070 Handle mouse button event on the tool-bar of frame F, at
12071 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
12072 0 for button release. MODIFIERS is event modifiers for button
12076 handle_tool_bar_click (struct frame
*f
, int x
, int y
, int down_p
,
12079 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12080 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12081 int hpos
, vpos
, prop_idx
;
12082 struct glyph
*glyph
;
12083 Lisp_Object enabled_p
;
12085 /* If not on the highlighted tool-bar item, return. */
12086 frame_to_window_pixel_xy (w
, &x
, &y
);
12087 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
12090 /* If item is disabled, do nothing. */
12091 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12092 if (NILP (enabled_p
))
12097 /* Show item in pressed state. */
12098 show_mouse_face (hlinfo
, DRAW_IMAGE_SUNKEN
);
12099 last_tool_bar_item
= prop_idx
;
12103 Lisp_Object key
, frame
;
12104 struct input_event event
;
12105 EVENT_INIT (event
);
12107 /* Show item in released state. */
12108 show_mouse_face (hlinfo
, DRAW_IMAGE_RAISED
);
12110 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
12112 XSETFRAME (frame
, f
);
12113 event
.kind
= TOOL_BAR_EVENT
;
12114 event
.frame_or_window
= frame
;
12116 kbd_buffer_store_event (&event
);
12118 event
.kind
= TOOL_BAR_EVENT
;
12119 event
.frame_or_window
= frame
;
12121 event
.modifiers
= modifiers
;
12122 kbd_buffer_store_event (&event
);
12123 last_tool_bar_item
= -1;
12128 /* Possibly highlight a tool-bar item on frame F when mouse moves to
12129 tool-bar window-relative coordinates X/Y. Called from
12130 note_mouse_highlight. */
12133 note_tool_bar_highlight (struct frame
*f
, int x
, int y
)
12135 Lisp_Object window
= f
->tool_bar_window
;
12136 struct window
*w
= XWINDOW (window
);
12137 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12138 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12140 struct glyph
*glyph
;
12141 struct glyph_row
*row
;
12143 Lisp_Object enabled_p
;
12145 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
12146 int mouse_down_p
, rc
;
12148 /* Function note_mouse_highlight is called with negative X/Y
12149 values when mouse moves outside of the frame. */
12150 if (x
<= 0 || y
<= 0)
12152 clear_mouse_face (hlinfo
);
12156 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
12159 /* Not on tool-bar item. */
12160 clear_mouse_face (hlinfo
);
12164 /* On same tool-bar item as before. */
12165 goto set_help_echo
;
12167 clear_mouse_face (hlinfo
);
12169 /* Mouse is down, but on different tool-bar item? */
12170 mouse_down_p
= (dpyinfo
->grabbed
12171 && f
== last_mouse_frame
12172 && FRAME_LIVE_P (f
));
12174 && last_tool_bar_item
!= prop_idx
)
12177 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
12179 /* If tool-bar item is not enabled, don't highlight it. */
12180 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12181 if (!NILP (enabled_p
))
12183 /* Compute the x-position of the glyph. In front and past the
12184 image is a space. We include this in the highlighted area. */
12185 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
12186 for (i
= x
= 0; i
< hpos
; ++i
)
12187 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
12189 /* Record this as the current active region. */
12190 hlinfo
->mouse_face_beg_col
= hpos
;
12191 hlinfo
->mouse_face_beg_row
= vpos
;
12192 hlinfo
->mouse_face_beg_x
= x
;
12193 hlinfo
->mouse_face_beg_y
= row
->y
;
12194 hlinfo
->mouse_face_past_end
= 0;
12196 hlinfo
->mouse_face_end_col
= hpos
+ 1;
12197 hlinfo
->mouse_face_end_row
= vpos
;
12198 hlinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
12199 hlinfo
->mouse_face_end_y
= row
->y
;
12200 hlinfo
->mouse_face_window
= window
;
12201 hlinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
12203 /* Display it as active. */
12204 show_mouse_face (hlinfo
, draw
);
12209 /* Set help_echo_string to a help string to display for this tool-bar item.
12210 XTread_socket does the rest. */
12211 help_echo_object
= help_echo_window
= Qnil
;
12212 help_echo_pos
= -1;
12213 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
12214 if (NILP (help_echo_string
))
12215 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
12218 #endif /* HAVE_WINDOW_SYSTEM */
12222 /************************************************************************
12223 Horizontal scrolling
12224 ************************************************************************/
12226 static int hscroll_window_tree (Lisp_Object
);
12227 static int hscroll_windows (Lisp_Object
);
12229 /* For all leaf windows in the window tree rooted at WINDOW, set their
12230 hscroll value so that PT is (i) visible in the window, and (ii) so
12231 that it is not within a certain margin at the window's left and
12232 right border. Value is non-zero if any window's hscroll has been
12236 hscroll_window_tree (Lisp_Object window
)
12238 int hscrolled_p
= 0;
12239 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
12240 int hscroll_step_abs
= 0;
12241 double hscroll_step_rel
= 0;
12243 if (hscroll_relative_p
)
12245 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
12246 if (hscroll_step_rel
< 0)
12248 hscroll_relative_p
= 0;
12249 hscroll_step_abs
= 0;
12252 else if (TYPE_RANGED_INTEGERP (int, Vhscroll_step
))
12254 hscroll_step_abs
= XINT (Vhscroll_step
);
12255 if (hscroll_step_abs
< 0)
12256 hscroll_step_abs
= 0;
12259 hscroll_step_abs
= 0;
12261 while (WINDOWP (window
))
12263 struct window
*w
= XWINDOW (window
);
12265 if (WINDOWP (w
->hchild
))
12266 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
12267 else if (WINDOWP (w
->vchild
))
12268 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
12269 else if (w
->cursor
.vpos
>= 0)
12272 int text_area_width
;
12273 struct glyph_row
*current_cursor_row
12274 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
12275 struct glyph_row
*desired_cursor_row
12276 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
12277 struct glyph_row
*cursor_row
12278 = (desired_cursor_row
->enabled_p
12279 ? desired_cursor_row
12280 : current_cursor_row
);
12281 int row_r2l_p
= cursor_row
->reversed_p
;
12283 text_area_width
= window_box_width (w
, TEXT_AREA
);
12285 /* Scroll when cursor is inside this scroll margin. */
12286 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
12288 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->buffer
))
12289 /* For left-to-right rows, hscroll when cursor is either
12290 (i) inside the right hscroll margin, or (ii) if it is
12291 inside the left margin and the window is already
12295 && w
->cursor
.x
<= h_margin
)
12296 || (cursor_row
->enabled_p
12297 && cursor_row
->truncated_on_right_p
12298 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
12299 /* For right-to-left rows, the logic is similar,
12300 except that rules for scrolling to left and right
12301 are reversed. E.g., if cursor.x <= h_margin, we
12302 need to hscroll "to the right" unconditionally,
12303 and that will scroll the screen to the left so as
12304 to reveal the next portion of the row. */
12306 && ((cursor_row
->enabled_p
12307 /* FIXME: It is confusing to set the
12308 truncated_on_right_p flag when R2L rows
12309 are actually truncated on the left. */
12310 && cursor_row
->truncated_on_right_p
12311 && w
->cursor
.x
<= h_margin
)
12313 && (w
->cursor
.x
>= text_area_width
- h_margin
))))))
12317 struct buffer
*saved_current_buffer
;
12321 /* Find point in a display of infinite width. */
12322 saved_current_buffer
= current_buffer
;
12323 current_buffer
= XBUFFER (w
->buffer
);
12325 if (w
== XWINDOW (selected_window
))
12328 pt
= clip_to_bounds (BEGV
, marker_position (w
->pointm
), ZV
);
12330 /* Move iterator to pt starting at cursor_row->start in
12331 a line with infinite width. */
12332 init_to_row_start (&it
, w
, cursor_row
);
12333 it
.last_visible_x
= INFINITY
;
12334 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
12335 current_buffer
= saved_current_buffer
;
12337 /* Position cursor in window. */
12338 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
12339 hscroll
= max (0, (it
.current_x
12340 - (ITERATOR_AT_END_OF_LINE_P (&it
)
12341 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
12342 : (text_area_width
/ 2))))
12343 / FRAME_COLUMN_WIDTH (it
.f
);
12344 else if ((!row_r2l_p
12345 && w
->cursor
.x
>= text_area_width
- h_margin
)
12346 || (row_r2l_p
&& w
->cursor
.x
<= h_margin
))
12348 if (hscroll_relative_p
)
12349 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
12352 wanted_x
= text_area_width
12353 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12356 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12360 if (hscroll_relative_p
)
12361 wanted_x
= text_area_width
* hscroll_step_rel
12364 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12367 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12369 hscroll
= max (hscroll
, w
->min_hscroll
);
12371 /* Don't prevent redisplay optimizations if hscroll
12372 hasn't changed, as it will unnecessarily slow down
12374 if (w
->hscroll
!= hscroll
)
12376 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
12377 w
->hscroll
= hscroll
;
12386 /* Value is non-zero if hscroll of any leaf window has been changed. */
12387 return hscrolled_p
;
12391 /* Set hscroll so that cursor is visible and not inside horizontal
12392 scroll margins for all windows in the tree rooted at WINDOW. See
12393 also hscroll_window_tree above. Value is non-zero if any window's
12394 hscroll has been changed. If it has, desired matrices on the frame
12395 of WINDOW are cleared. */
12398 hscroll_windows (Lisp_Object window
)
12400 int hscrolled_p
= hscroll_window_tree (window
);
12402 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
12403 return hscrolled_p
;
12408 /************************************************************************
12410 ************************************************************************/
12412 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
12413 to a non-zero value. This is sometimes handy to have in a debugger
12418 /* First and last unchanged row for try_window_id. */
12420 static int debug_first_unchanged_at_end_vpos
;
12421 static int debug_last_unchanged_at_beg_vpos
;
12423 /* Delta vpos and y. */
12425 static int debug_dvpos
, debug_dy
;
12427 /* Delta in characters and bytes for try_window_id. */
12429 static ptrdiff_t debug_delta
, debug_delta_bytes
;
12431 /* Values of window_end_pos and window_end_vpos at the end of
12434 static ptrdiff_t debug_end_vpos
;
12436 /* Append a string to W->desired_matrix->method. FMT is a printf
12437 format string. If trace_redisplay_p is non-zero also printf the
12438 resulting string to stderr. */
12440 static void debug_method_add (struct window
*, char const *, ...)
12441 ATTRIBUTE_FORMAT_PRINTF (2, 3);
12444 debug_method_add (struct window
*w
, char const *fmt
, ...)
12446 char *method
= w
->desired_matrix
->method
;
12447 int len
= strlen (method
);
12448 int size
= sizeof w
->desired_matrix
->method
;
12449 int remaining
= size
- len
- 1;
12452 if (len
&& remaining
)
12455 --remaining
, ++len
;
12458 va_start (ap
, fmt
);
12459 vsnprintf (method
+ len
, remaining
+ 1, fmt
, ap
);
12462 if (trace_redisplay_p
)
12463 fprintf (stderr
, "%p (%s): %s\n",
12465 ((BUFFERP (w
->buffer
)
12466 && STRINGP (BVAR (XBUFFER (w
->buffer
), name
)))
12467 ? SSDATA (BVAR (XBUFFER (w
->buffer
), name
))
12472 #endif /* GLYPH_DEBUG */
12475 /* Value is non-zero if all changes in window W, which displays
12476 current_buffer, are in the text between START and END. START is a
12477 buffer position, END is given as a distance from Z. Used in
12478 redisplay_internal for display optimization. */
12481 text_outside_line_unchanged_p (struct window
*w
,
12482 ptrdiff_t start
, ptrdiff_t end
)
12484 int unchanged_p
= 1;
12486 /* If text or overlays have changed, see where. */
12487 if (window_outdated (w
))
12489 /* Gap in the line? */
12490 if (GPT
< start
|| Z
- GPT
< end
)
12493 /* Changes start in front of the line, or end after it? */
12495 && (BEG_UNCHANGED
< start
- 1
12496 || END_UNCHANGED
< end
))
12499 /* If selective display, can't optimize if changes start at the
12500 beginning of the line. */
12502 && INTEGERP (BVAR (current_buffer
, selective_display
))
12503 && XINT (BVAR (current_buffer
, selective_display
)) > 0
12504 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
12507 /* If there are overlays at the start or end of the line, these
12508 may have overlay strings with newlines in them. A change at
12509 START, for instance, may actually concern the display of such
12510 overlay strings as well, and they are displayed on different
12511 lines. So, quickly rule out this case. (For the future, it
12512 might be desirable to implement something more telling than
12513 just BEG/END_UNCHANGED.) */
12516 if (BEG
+ BEG_UNCHANGED
== start
12517 && overlay_touches_p (start
))
12519 if (END_UNCHANGED
== end
12520 && overlay_touches_p (Z
- end
))
12524 /* Under bidi reordering, adding or deleting a character in the
12525 beginning of a paragraph, before the first strong directional
12526 character, can change the base direction of the paragraph (unless
12527 the buffer specifies a fixed paragraph direction), which will
12528 require to redisplay the whole paragraph. It might be worthwhile
12529 to find the paragraph limits and widen the range of redisplayed
12530 lines to that, but for now just give up this optimization. */
12531 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
12532 && NILP (BVAR (XBUFFER (w
->buffer
), bidi_paragraph_direction
)))
12536 return unchanged_p
;
12540 /* Do a frame update, taking possible shortcuts into account. This is
12541 the main external entry point for redisplay.
12543 If the last redisplay displayed an echo area message and that message
12544 is no longer requested, we clear the echo area or bring back the
12545 mini-buffer if that is in use. */
12550 redisplay_internal ();
12555 overlay_arrow_string_or_property (Lisp_Object var
)
12559 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
12562 return Voverlay_arrow_string
;
12565 /* Return 1 if there are any overlay-arrows in current_buffer. */
12567 overlay_arrow_in_current_buffer_p (void)
12571 for (vlist
= Voverlay_arrow_variable_list
;
12573 vlist
= XCDR (vlist
))
12575 Lisp_Object var
= XCAR (vlist
);
12578 if (!SYMBOLP (var
))
12580 val
= find_symbol_value (var
);
12582 && current_buffer
== XMARKER (val
)->buffer
)
12589 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
12593 overlay_arrows_changed_p (void)
12597 for (vlist
= Voverlay_arrow_variable_list
;
12599 vlist
= XCDR (vlist
))
12601 Lisp_Object var
= XCAR (vlist
);
12602 Lisp_Object val
, pstr
;
12604 if (!SYMBOLP (var
))
12606 val
= find_symbol_value (var
);
12607 if (!MARKERP (val
))
12609 if (! EQ (COERCE_MARKER (val
),
12610 Fget (var
, Qlast_arrow_position
))
12611 || ! (pstr
= overlay_arrow_string_or_property (var
),
12612 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
12618 /* Mark overlay arrows to be updated on next redisplay. */
12621 update_overlay_arrows (int up_to_date
)
12625 for (vlist
= Voverlay_arrow_variable_list
;
12627 vlist
= XCDR (vlist
))
12629 Lisp_Object var
= XCAR (vlist
);
12631 if (!SYMBOLP (var
))
12634 if (up_to_date
> 0)
12636 Lisp_Object val
= find_symbol_value (var
);
12637 Fput (var
, Qlast_arrow_position
,
12638 COERCE_MARKER (val
));
12639 Fput (var
, Qlast_arrow_string
,
12640 overlay_arrow_string_or_property (var
));
12642 else if (up_to_date
< 0
12643 || !NILP (Fget (var
, Qlast_arrow_position
)))
12645 Fput (var
, Qlast_arrow_position
, Qt
);
12646 Fput (var
, Qlast_arrow_string
, Qt
);
12652 /* Return overlay arrow string to display at row.
12653 Return integer (bitmap number) for arrow bitmap in left fringe.
12654 Return nil if no overlay arrow. */
12657 overlay_arrow_at_row (struct it
*it
, struct glyph_row
*row
)
12661 for (vlist
= Voverlay_arrow_variable_list
;
12663 vlist
= XCDR (vlist
))
12665 Lisp_Object var
= XCAR (vlist
);
12668 if (!SYMBOLP (var
))
12671 val
= find_symbol_value (var
);
12674 && current_buffer
== XMARKER (val
)->buffer
12675 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
12677 if (FRAME_WINDOW_P (it
->f
)
12678 /* FIXME: if ROW->reversed_p is set, this should test
12679 the right fringe, not the left one. */
12680 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
12682 #ifdef HAVE_WINDOW_SYSTEM
12683 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
12686 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
12687 return make_number (fringe_bitmap
);
12690 return make_number (-1); /* Use default arrow bitmap. */
12692 return overlay_arrow_string_or_property (var
);
12699 /* Return 1 if point moved out of or into a composition. Otherwise
12700 return 0. PREV_BUF and PREV_PT are the last point buffer and
12701 position. BUF and PT are the current point buffer and position. */
12704 check_point_in_composition (struct buffer
*prev_buf
, ptrdiff_t prev_pt
,
12705 struct buffer
*buf
, ptrdiff_t pt
)
12707 ptrdiff_t start
, end
;
12709 Lisp_Object buffer
;
12711 XSETBUFFER (buffer
, buf
);
12712 /* Check a composition at the last point if point moved within the
12714 if (prev_buf
== buf
)
12717 /* Point didn't move. */
12720 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
12721 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
12722 && COMPOSITION_VALID_P (start
, end
, prop
)
12723 && start
< prev_pt
&& end
> prev_pt
)
12724 /* The last point was within the composition. Return 1 iff
12725 point moved out of the composition. */
12726 return (pt
<= start
|| pt
>= end
);
12729 /* Check a composition at the current point. */
12730 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
12731 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
12732 && COMPOSITION_VALID_P (start
, end
, prop
)
12733 && start
< pt
&& end
> pt
);
12737 /* Reconsider the setting of B->clip_changed which is displayed
12741 reconsider_clip_changes (struct window
*w
, struct buffer
*b
)
12743 if (b
->clip_changed
12744 && w
->window_end_valid
12745 && w
->current_matrix
->buffer
== b
12746 && w
->current_matrix
->zv
== BUF_ZV (b
)
12747 && w
->current_matrix
->begv
== BUF_BEGV (b
))
12748 b
->clip_changed
= 0;
12750 /* If display wasn't paused, and W is not a tool bar window, see if
12751 point has been moved into or out of a composition. In that case,
12752 we set b->clip_changed to 1 to force updating the screen. If
12753 b->clip_changed has already been set to 1, we can skip this
12755 if (!b
->clip_changed
&& BUFFERP (w
->buffer
) && w
->window_end_valid
)
12759 if (w
== XWINDOW (selected_window
))
12762 pt
= marker_position (w
->pointm
);
12764 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
12765 || pt
!= w
->last_point
)
12766 && check_point_in_composition (w
->current_matrix
->buffer
,
12768 XBUFFER (w
->buffer
), pt
))
12769 b
->clip_changed
= 1;
12774 #define STOP_POLLING \
12775 do { if (! polling_stopped_here) stop_polling (); \
12776 polling_stopped_here = 1; } while (0)
12778 #define RESUME_POLLING \
12779 do { if (polling_stopped_here) start_polling (); \
12780 polling_stopped_here = 0; } while (0)
12783 /* Perhaps in the future avoid recentering windows if it
12784 is not necessary; currently that causes some problems. */
12787 redisplay_internal (void)
12789 struct window
*w
= XWINDOW (selected_window
);
12793 int must_finish
= 0;
12794 struct text_pos tlbufpos
, tlendpos
;
12795 int number_of_visible_frames
;
12796 ptrdiff_t count
, count1
;
12798 int polling_stopped_here
= 0;
12799 Lisp_Object tail
, frame
;
12800 struct backtrace backtrace
;
12802 /* Non-zero means redisplay has to consider all windows on all
12803 frames. Zero means, only selected_window is considered. */
12804 int consider_all_windows_p
;
12806 /* Non-zero means redisplay has to redisplay the miniwindow. */
12807 int update_miniwindow_p
= 0;
12809 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
12811 /* No redisplay if running in batch mode or frame is not yet fully
12812 initialized, or redisplay is explicitly turned off by setting
12813 Vinhibit_redisplay. */
12814 if (FRAME_INITIAL_P (SELECTED_FRAME ())
12815 || !NILP (Vinhibit_redisplay
))
12818 /* Don't examine these until after testing Vinhibit_redisplay.
12819 When Emacs is shutting down, perhaps because its connection to
12820 X has dropped, we should not look at them at all. */
12821 fr
= XFRAME (w
->frame
);
12822 sf
= SELECTED_FRAME ();
12824 if (!fr
->glyphs_initialized_p
)
12827 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
12828 if (popup_activated ())
12832 /* I don't think this happens but let's be paranoid. */
12833 if (redisplaying_p
)
12836 /* Record a function that clears redisplaying_p
12837 when we leave this function. */
12838 count
= SPECPDL_INDEX ();
12839 record_unwind_protect (unwind_redisplay
, selected_frame
);
12840 redisplaying_p
= 1;
12841 specbind (Qinhibit_free_realized_faces
, Qnil
);
12843 /* Record this function, so it appears on the profiler's backtraces. */
12844 backtrace
.next
= backtrace_list
;
12845 backtrace
.function
= Qredisplay_internal
;
12846 backtrace
.args
= &Qnil
;
12847 backtrace
.nargs
= 0;
12848 backtrace
.debug_on_exit
= 0;
12849 backtrace_list
= &backtrace
;
12851 FOR_EACH_FRAME (tail
, frame
)
12852 XFRAME (frame
)->already_hscrolled_p
= 0;
12855 /* Remember the currently selected window. */
12859 reconsider_clip_changes (w
, current_buffer
);
12860 last_escape_glyph_frame
= NULL
;
12861 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
12862 last_glyphless_glyph_frame
= NULL
;
12863 last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
12865 /* If new fonts have been loaded that make a glyph matrix adjustment
12866 necessary, do it. */
12867 if (fonts_changed_p
)
12869 adjust_glyphs (NULL
);
12870 ++windows_or_buffers_changed
;
12871 fonts_changed_p
= 0;
12874 /* If face_change_count is non-zero, init_iterator will free all
12875 realized faces, which includes the faces referenced from current
12876 matrices. So, we can't reuse current matrices in this case. */
12877 if (face_change_count
)
12878 ++windows_or_buffers_changed
;
12880 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
12881 && FRAME_TTY (sf
)->previous_frame
!= sf
)
12883 /* Since frames on a single ASCII terminal share the same
12884 display area, displaying a different frame means redisplay
12885 the whole thing. */
12886 windows_or_buffers_changed
++;
12887 SET_FRAME_GARBAGED (sf
);
12889 set_tty_color_mode (FRAME_TTY (sf
), sf
);
12891 FRAME_TTY (sf
)->previous_frame
= sf
;
12894 /* Set the visible flags for all frames. Do this before checking for
12895 resized or garbaged frames; they want to know if their frames are
12896 visible. See the comment in frame.h for FRAME_SAMPLE_VISIBILITY. */
12897 number_of_visible_frames
= 0;
12899 FOR_EACH_FRAME (tail
, frame
)
12901 struct frame
*f
= XFRAME (frame
);
12903 if (FRAME_VISIBLE_P (f
))
12904 ++number_of_visible_frames
;
12905 clear_desired_matrices (f
);
12908 /* Notice any pending interrupt request to change frame size. */
12909 do_pending_window_change (1);
12911 /* do_pending_window_change could change the selected_window due to
12912 frame resizing which makes the selected window too small. */
12913 if (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
)
12916 reconsider_clip_changes (w
, current_buffer
);
12919 /* Clear frames marked as garbaged. */
12920 clear_garbaged_frames ();
12922 /* Build menubar and tool-bar items. */
12923 if (NILP (Vmemory_full
))
12924 prepare_menu_bars ();
12926 if (windows_or_buffers_changed
)
12927 update_mode_lines
++;
12929 /* Detect case that we need to write or remove a star in the mode line. */
12930 if ((SAVE_MODIFF
< MODIFF
) != w
->last_had_star
)
12932 w
->update_mode_line
= 1;
12933 if (buffer_shared_and_changed ())
12934 update_mode_lines
++;
12937 /* Avoid invocation of point motion hooks by `current_column' below. */
12938 count1
= SPECPDL_INDEX ();
12939 specbind (Qinhibit_point_motion_hooks
, Qt
);
12941 if (mode_line_update_needed (w
))
12942 w
->update_mode_line
= 1;
12944 unbind_to (count1
, Qnil
);
12946 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
12948 consider_all_windows_p
= (update_mode_lines
12949 || buffer_shared_and_changed ()
12950 || cursor_type_changed
);
12952 /* If specs for an arrow have changed, do thorough redisplay
12953 to ensure we remove any arrow that should no longer exist. */
12954 if (overlay_arrows_changed_p ())
12955 consider_all_windows_p
= windows_or_buffers_changed
= 1;
12957 /* Normally the message* functions will have already displayed and
12958 updated the echo area, but the frame may have been trashed, or
12959 the update may have been preempted, so display the echo area
12960 again here. Checking message_cleared_p captures the case that
12961 the echo area should be cleared. */
12962 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
12963 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
12964 || (message_cleared_p
12965 && minibuf_level
== 0
12966 /* If the mini-window is currently selected, this means the
12967 echo-area doesn't show through. */
12968 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
12970 int window_height_changed_p
= echo_area_display (0);
12972 if (message_cleared_p
)
12973 update_miniwindow_p
= 1;
12977 /* If we don't display the current message, don't clear the
12978 message_cleared_p flag, because, if we did, we wouldn't clear
12979 the echo area in the next redisplay which doesn't preserve
12981 if (!display_last_displayed_message_p
)
12982 message_cleared_p
= 0;
12984 if (fonts_changed_p
)
12986 else if (window_height_changed_p
)
12988 consider_all_windows_p
= 1;
12989 ++update_mode_lines
;
12990 ++windows_or_buffers_changed
;
12992 /* If window configuration was changed, frames may have been
12993 marked garbaged. Clear them or we will experience
12994 surprises wrt scrolling. */
12995 clear_garbaged_frames ();
12998 else if (EQ (selected_window
, minibuf_window
)
12999 && (current_buffer
->clip_changed
|| window_outdated (w
))
13000 && resize_mini_window (w
, 0))
13002 /* Resized active mini-window to fit the size of what it is
13003 showing if its contents might have changed. */
13005 /* FIXME: this causes all frames to be updated, which seems unnecessary
13006 since only the current frame needs to be considered. This function
13007 needs to be rewritten with two variables, consider_all_windows and
13008 consider_all_frames. */
13009 consider_all_windows_p
= 1;
13010 ++windows_or_buffers_changed
;
13011 ++update_mode_lines
;
13013 /* If window configuration was changed, frames may have been
13014 marked garbaged. Clear them or we will experience
13015 surprises wrt scrolling. */
13016 clear_garbaged_frames ();
13019 /* If showing the region, and mark has changed, we must redisplay
13020 the whole window. The assignment to this_line_start_pos prevents
13021 the optimization directly below this if-statement. */
13022 if (((!NILP (Vtransient_mark_mode
)
13023 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
13024 != (w
->region_showing
> 0))
13025 || (w
->region_showing
13026 && w
->region_showing
13027 != XINT (Fmarker_position (BVAR (XBUFFER (w
->buffer
), mark
)))))
13028 CHARPOS (this_line_start_pos
) = 0;
13030 /* Optimize the case that only the line containing the cursor in the
13031 selected window has changed. Variables starting with this_ are
13032 set in display_line and record information about the line
13033 containing the cursor. */
13034 tlbufpos
= this_line_start_pos
;
13035 tlendpos
= this_line_end_pos
;
13036 if (!consider_all_windows_p
13037 && CHARPOS (tlbufpos
) > 0
13038 && !w
->update_mode_line
13039 && !current_buffer
->clip_changed
13040 && !current_buffer
->prevent_redisplay_optimizations_p
13041 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
13042 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
13043 /* Make sure recorded data applies to current buffer, etc. */
13044 && this_line_buffer
== current_buffer
13045 && current_buffer
== XBUFFER (w
->buffer
)
13047 && !w
->optional_new_start
13048 /* Point must be on the line that we have info recorded about. */
13049 && PT
>= CHARPOS (tlbufpos
)
13050 && PT
<= Z
- CHARPOS (tlendpos
)
13051 /* All text outside that line, including its final newline,
13052 must be unchanged. */
13053 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
13054 CHARPOS (tlendpos
)))
13056 if (CHARPOS (tlbufpos
) > BEGV
13057 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
13058 && (CHARPOS (tlbufpos
) == ZV
13059 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
13060 /* Former continuation line has disappeared by becoming empty. */
13062 else if (window_outdated (w
) || MINI_WINDOW_P (w
))
13064 /* We have to handle the case of continuation around a
13065 wide-column character (see the comment in indent.c around
13068 For instance, in the following case:
13070 -------- Insert --------
13071 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
13072 J_I_ ==> J_I_ `^^' are cursors.
13076 As we have to redraw the line above, we cannot use this
13080 int line_height_before
= this_line_pixel_height
;
13082 /* Note that start_display will handle the case that the
13083 line starting at tlbufpos is a continuation line. */
13084 start_display (&it
, w
, tlbufpos
);
13086 /* Implementation note: It this still necessary? */
13087 if (it
.current_x
!= this_line_start_x
)
13090 TRACE ((stderr
, "trying display optimization 1\n"));
13091 w
->cursor
.vpos
= -1;
13092 overlay_arrow_seen
= 0;
13093 it
.vpos
= this_line_vpos
;
13094 it
.current_y
= this_line_y
;
13095 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
13096 display_line (&it
);
13098 /* If line contains point, is not continued,
13099 and ends at same distance from eob as before, we win. */
13100 if (w
->cursor
.vpos
>= 0
13101 /* Line is not continued, otherwise this_line_start_pos
13102 would have been set to 0 in display_line. */
13103 && CHARPOS (this_line_start_pos
)
13104 /* Line ends as before. */
13105 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
13106 /* Line has same height as before. Otherwise other lines
13107 would have to be shifted up or down. */
13108 && this_line_pixel_height
== line_height_before
)
13110 /* If this is not the window's last line, we must adjust
13111 the charstarts of the lines below. */
13112 if (it
.current_y
< it
.last_visible_y
)
13114 struct glyph_row
*row
13115 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
13116 ptrdiff_t delta
, delta_bytes
;
13118 /* We used to distinguish between two cases here,
13119 conditioned by Z - CHARPOS (tlendpos) == ZV, for
13120 when the line ends in a newline or the end of the
13121 buffer's accessible portion. But both cases did
13122 the same, so they were collapsed. */
13124 - CHARPOS (tlendpos
)
13125 - MATRIX_ROW_START_CHARPOS (row
));
13126 delta_bytes
= (Z_BYTE
13127 - BYTEPOS (tlendpos
)
13128 - MATRIX_ROW_START_BYTEPOS (row
));
13130 increment_matrix_positions (w
->current_matrix
,
13131 this_line_vpos
+ 1,
13132 w
->current_matrix
->nrows
,
13133 delta
, delta_bytes
);
13136 /* If this row displays text now but previously didn't,
13137 or vice versa, w->window_end_vpos may have to be
13139 if ((it
.glyph_row
- 1)->displays_text_p
)
13141 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
13142 wset_window_end_vpos (w
, make_number (this_line_vpos
));
13144 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
13145 && this_line_vpos
> 0)
13146 wset_window_end_vpos (w
, make_number (this_line_vpos
- 1));
13147 w
->window_end_valid
= 0;
13149 /* Update hint: No need to try to scroll in update_window. */
13150 w
->desired_matrix
->no_scrolling_p
= 1;
13153 *w
->desired_matrix
->method
= 0;
13154 debug_method_add (w
, "optimization 1");
13156 #ifdef HAVE_WINDOW_SYSTEM
13157 update_window_fringes (w
, 0);
13164 else if (/* Cursor position hasn't changed. */
13165 PT
== w
->last_point
13166 /* Make sure the cursor was last displayed
13167 in this window. Otherwise we have to reposition it. */
13168 && 0 <= w
->cursor
.vpos
13169 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
13173 do_pending_window_change (1);
13174 /* If selected_window changed, redisplay again. */
13175 if (WINDOWP (selected_window
)
13176 && (w
= XWINDOW (selected_window
)) != sw
)
13179 /* We used to always goto end_of_redisplay here, but this
13180 isn't enough if we have a blinking cursor. */
13181 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
13182 goto end_of_redisplay
;
13186 /* If highlighting the region, or if the cursor is in the echo area,
13187 then we can't just move the cursor. */
13188 else if (! (!NILP (Vtransient_mark_mode
)
13189 && !NILP (BVAR (current_buffer
, mark_active
)))
13190 && (EQ (selected_window
,
13191 BVAR (current_buffer
, last_selected_window
))
13192 || highlight_nonselected_windows
)
13193 && !w
->region_showing
13194 && NILP (Vshow_trailing_whitespace
)
13195 && !cursor_in_echo_area
)
13198 struct glyph_row
*row
;
13200 /* Skip from tlbufpos to PT and see where it is. Note that
13201 PT may be in invisible text. If so, we will end at the
13202 next visible position. */
13203 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
13204 NULL
, DEFAULT_FACE_ID
);
13205 it
.current_x
= this_line_start_x
;
13206 it
.current_y
= this_line_y
;
13207 it
.vpos
= this_line_vpos
;
13209 /* The call to move_it_to stops in front of PT, but
13210 moves over before-strings. */
13211 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
13213 if (it
.vpos
== this_line_vpos
13214 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
13217 eassert (this_line_vpos
== it
.vpos
);
13218 eassert (this_line_y
== it
.current_y
);
13219 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13221 *w
->desired_matrix
->method
= 0;
13222 debug_method_add (w
, "optimization 3");
13231 /* Text changed drastically or point moved off of line. */
13232 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
13235 CHARPOS (this_line_start_pos
) = 0;
13236 consider_all_windows_p
|= buffer_shared_and_changed ();
13237 ++clear_face_cache_count
;
13238 #ifdef HAVE_WINDOW_SYSTEM
13239 ++clear_image_cache_count
;
13242 w
->region_showing
= XINT (Fmarker_position (BVAR (XBUFFER (w
->buffer
), mark
)));
13244 /* Build desired matrices, and update the display. If
13245 consider_all_windows_p is non-zero, do it for all windows on all
13246 frames. Otherwise do it for selected_window, only. */
13248 if (consider_all_windows_p
)
13250 FOR_EACH_FRAME (tail
, frame
)
13251 XFRAME (frame
)->updated_p
= 0;
13253 FOR_EACH_FRAME (tail
, frame
)
13255 struct frame
*f
= XFRAME (frame
);
13257 /* We don't have to do anything for unselected terminal
13259 if ((FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
13260 && !EQ (FRAME_TTY (f
)->top_frame
, frame
))
13263 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
13265 /* Mark all the scroll bars to be removed; we'll redeem
13266 the ones we want when we redisplay their windows. */
13267 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
13268 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
13270 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13271 redisplay_windows (FRAME_ROOT_WINDOW (f
));
13273 /* The X error handler may have deleted that frame. */
13274 if (!FRAME_LIVE_P (f
))
13277 /* Any scroll bars which redisplay_windows should have
13278 nuked should now go away. */
13279 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
13280 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
13282 /* If fonts changed, display again. */
13283 /* ??? rms: I suspect it is a mistake to jump all the way
13284 back to retry here. It should just retry this frame. */
13285 if (fonts_changed_p
)
13288 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13290 /* See if we have to hscroll. */
13291 if (!f
->already_hscrolled_p
)
13293 f
->already_hscrolled_p
= 1;
13294 if (hscroll_windows (f
->root_window
))
13298 /* Prevent various kinds of signals during display
13299 update. stdio is not robust about handling
13300 signals, which can cause an apparent I/O
13302 if (interrupt_input
)
13303 unrequest_sigio ();
13306 /* Update the display. */
13307 set_window_update_flags (XWINDOW (f
->root_window
), 1);
13308 pending
|= update_frame (f
, 0, 0);
13314 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
13318 /* Do the mark_window_display_accurate after all windows have
13319 been redisplayed because this call resets flags in buffers
13320 which are needed for proper redisplay. */
13321 FOR_EACH_FRAME (tail
, frame
)
13323 struct frame
*f
= XFRAME (frame
);
13326 mark_window_display_accurate (f
->root_window
, 1);
13327 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
13328 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
13333 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13335 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13336 struct frame
*mini_frame
;
13338 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
13339 /* Use list_of_error, not Qerror, so that
13340 we catch only errors and don't run the debugger. */
13341 internal_condition_case_1 (redisplay_window_1
, selected_window
,
13343 redisplay_window_error
);
13344 if (update_miniwindow_p
)
13345 internal_condition_case_1 (redisplay_window_1
, mini_window
,
13347 redisplay_window_error
);
13349 /* Compare desired and current matrices, perform output. */
13352 /* If fonts changed, display again. */
13353 if (fonts_changed_p
)
13356 /* Prevent various kinds of signals during display update.
13357 stdio is not robust about handling signals,
13358 which can cause an apparent I/O error. */
13359 if (interrupt_input
)
13360 unrequest_sigio ();
13363 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13365 if (hscroll_windows (selected_window
))
13368 XWINDOW (selected_window
)->must_be_updated_p
= 1;
13369 pending
= update_frame (sf
, 0, 0);
13372 /* We may have called echo_area_display at the top of this
13373 function. If the echo area is on another frame, that may
13374 have put text on a frame other than the selected one, so the
13375 above call to update_frame would not have caught it. Catch
13377 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13378 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
13380 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
13382 XWINDOW (mini_window
)->must_be_updated_p
= 1;
13383 pending
|= update_frame (mini_frame
, 0, 0);
13384 if (!pending
&& hscroll_windows (mini_window
))
13389 /* If display was paused because of pending input, make sure we do a
13390 thorough update the next time. */
13393 /* Prevent the optimization at the beginning of
13394 redisplay_internal that tries a single-line update of the
13395 line containing the cursor in the selected window. */
13396 CHARPOS (this_line_start_pos
) = 0;
13398 /* Let the overlay arrow be updated the next time. */
13399 update_overlay_arrows (0);
13401 /* If we pause after scrolling, some rows in the current
13402 matrices of some windows are not valid. */
13403 if (!WINDOW_FULL_WIDTH_P (w
)
13404 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
13405 update_mode_lines
= 1;
13409 if (!consider_all_windows_p
)
13411 /* This has already been done above if
13412 consider_all_windows_p is set. */
13413 mark_window_display_accurate_1 (w
, 1);
13415 /* Say overlay arrows are up to date. */
13416 update_overlay_arrows (1);
13418 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
13419 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
13422 update_mode_lines
= 0;
13423 windows_or_buffers_changed
= 0;
13424 cursor_type_changed
= 0;
13427 /* Start SIGIO interrupts coming again. Having them off during the
13428 code above makes it less likely one will discard output, but not
13429 impossible, since there might be stuff in the system buffer here.
13430 But it is much hairier to try to do anything about that. */
13431 if (interrupt_input
)
13435 /* If a frame has become visible which was not before, redisplay
13436 again, so that we display it. Expose events for such a frame
13437 (which it gets when becoming visible) don't call the parts of
13438 redisplay constructing glyphs, so simply exposing a frame won't
13439 display anything in this case. So, we have to display these
13440 frames here explicitly. */
13445 FOR_EACH_FRAME (tail
, frame
)
13447 int this_is_visible
= 0;
13449 if (XFRAME (frame
)->visible
)
13450 this_is_visible
= 1;
13452 if (this_is_visible
)
13456 if (new_count
!= number_of_visible_frames
)
13457 windows_or_buffers_changed
++;
13460 /* Change frame size now if a change is pending. */
13461 do_pending_window_change (1);
13463 /* If we just did a pending size change, or have additional
13464 visible frames, or selected_window changed, redisplay again. */
13465 if ((windows_or_buffers_changed
&& !pending
)
13466 || (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
))
13469 /* Clear the face and image caches.
13471 We used to do this only if consider_all_windows_p. But the cache
13472 needs to be cleared if a timer creates images in the current
13473 buffer (e.g. the test case in Bug#6230). */
13475 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
13477 clear_face_cache (0);
13478 clear_face_cache_count
= 0;
13481 #ifdef HAVE_WINDOW_SYSTEM
13482 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
13484 clear_image_caches (Qnil
);
13485 clear_image_cache_count
= 0;
13487 #endif /* HAVE_WINDOW_SYSTEM */
13490 backtrace_list
= backtrace
.next
;
13491 unbind_to (count
, Qnil
);
13496 /* Redisplay, but leave alone any recent echo area message unless
13497 another message has been requested in its place.
13499 This is useful in situations where you need to redisplay but no
13500 user action has occurred, making it inappropriate for the message
13501 area to be cleared. See tracking_off and
13502 wait_reading_process_output for examples of these situations.
13504 FROM_WHERE is an integer saying from where this function was
13505 called. This is useful for debugging. */
13508 redisplay_preserve_echo_area (int from_where
)
13510 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
13512 if (!NILP (echo_area_buffer
[1]))
13514 /* We have a previously displayed message, but no current
13515 message. Redisplay the previous message. */
13516 display_last_displayed_message_p
= 1;
13517 redisplay_internal ();
13518 display_last_displayed_message_p
= 0;
13521 redisplay_internal ();
13523 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
13524 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
13525 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
13529 /* Function registered with record_unwind_protect in redisplay_internal.
13530 Clear redisplaying_p. Also select the previously selected frame. */
13533 unwind_redisplay (Lisp_Object old_frame
)
13535 redisplaying_p
= 0;
13540 /* Mark the display of leaf window W as accurate or inaccurate.
13541 If ACCURATE_P is non-zero mark display of W as accurate. If
13542 ACCURATE_P is zero, arrange for W to be redisplayed the next
13543 time redisplay_internal is called. */
13546 mark_window_display_accurate_1 (struct window
*w
, int accurate_p
)
13548 struct buffer
*b
= XBUFFER (w
->buffer
);
13550 w
->last_modified
= accurate_p
? BUF_MODIFF (b
) : 0;
13551 w
->last_overlay_modified
= accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0;
13552 w
->last_had_star
= BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
);
13556 b
->clip_changed
= 0;
13557 b
->prevent_redisplay_optimizations_p
= 0;
13559 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
13560 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
13561 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
13562 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
13564 w
->current_matrix
->buffer
= b
;
13565 w
->current_matrix
->begv
= BUF_BEGV (b
);
13566 w
->current_matrix
->zv
= BUF_ZV (b
);
13568 w
->last_cursor
= w
->cursor
;
13569 w
->last_cursor_off_p
= w
->cursor_off_p
;
13571 if (w
== XWINDOW (selected_window
))
13572 w
->last_point
= BUF_PT (b
);
13574 w
->last_point
= marker_position (w
->pointm
);
13576 w
->window_end_valid
= 1;
13577 w
->update_mode_line
= 0;
13582 /* Mark the display of windows in the window tree rooted at WINDOW as
13583 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
13584 windows as accurate. If ACCURATE_P is zero, arrange for windows to
13585 be redisplayed the next time redisplay_internal is called. */
13588 mark_window_display_accurate (Lisp_Object window
, int accurate_p
)
13592 for (; !NILP (window
); window
= w
->next
)
13594 w
= XWINDOW (window
);
13595 if (!NILP (w
->vchild
))
13596 mark_window_display_accurate (w
->vchild
, accurate_p
);
13597 else if (!NILP (w
->hchild
))
13598 mark_window_display_accurate (w
->hchild
, accurate_p
);
13599 else if (BUFFERP (w
->buffer
))
13600 mark_window_display_accurate_1 (w
, accurate_p
);
13604 update_overlay_arrows (1);
13606 /* Force a thorough redisplay the next time by setting
13607 last_arrow_position and last_arrow_string to t, which is
13608 unequal to any useful value of Voverlay_arrow_... */
13609 update_overlay_arrows (-1);
13613 /* Return value in display table DP (Lisp_Char_Table *) for character
13614 C. Since a display table doesn't have any parent, we don't have to
13615 follow parent. Do not call this function directly but use the
13616 macro DISP_CHAR_VECTOR. */
13619 disp_char_vector (struct Lisp_Char_Table
*dp
, int c
)
13623 if (ASCII_CHAR_P (c
))
13626 if (SUB_CHAR_TABLE_P (val
))
13627 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
13633 XSETCHAR_TABLE (table
, dp
);
13634 val
= char_table_ref (table
, c
);
13643 /***********************************************************************
13645 ***********************************************************************/
13647 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
13650 redisplay_windows (Lisp_Object window
)
13652 while (!NILP (window
))
13654 struct window
*w
= XWINDOW (window
);
13656 if (!NILP (w
->hchild
))
13657 redisplay_windows (w
->hchild
);
13658 else if (!NILP (w
->vchild
))
13659 redisplay_windows (w
->vchild
);
13660 else if (!NILP (w
->buffer
))
13662 displayed_buffer
= XBUFFER (w
->buffer
);
13663 /* Use list_of_error, not Qerror, so that
13664 we catch only errors and don't run the debugger. */
13665 internal_condition_case_1 (redisplay_window_0
, window
,
13667 redisplay_window_error
);
13675 redisplay_window_error (Lisp_Object ignore
)
13677 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
13682 redisplay_window_0 (Lisp_Object window
)
13684 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
13685 redisplay_window (window
, 0);
13690 redisplay_window_1 (Lisp_Object window
)
13692 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
13693 redisplay_window (window
, 1);
13698 /* Set cursor position of W. PT is assumed to be displayed in ROW.
13699 DELTA and DELTA_BYTES are the numbers of characters and bytes by
13700 which positions recorded in ROW differ from current buffer
13703 Return 0 if cursor is not on this row, 1 otherwise. */
13706 set_cursor_from_row (struct window
*w
, struct glyph_row
*row
,
13707 struct glyph_matrix
*matrix
,
13708 ptrdiff_t delta
, ptrdiff_t delta_bytes
,
13711 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
13712 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
13713 struct glyph
*cursor
= NULL
;
13714 /* The last known character position in row. */
13715 ptrdiff_t last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13717 ptrdiff_t pt_old
= PT
- delta
;
13718 ptrdiff_t pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13719 ptrdiff_t pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
13720 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
13721 /* A glyph beyond the edge of TEXT_AREA which we should never
13723 struct glyph
*glyphs_end
= end
;
13724 /* Non-zero means we've found a match for cursor position, but that
13725 glyph has the avoid_cursor_p flag set. */
13726 int match_with_avoid_cursor
= 0;
13727 /* Non-zero means we've seen at least one glyph that came from a
13729 int string_seen
= 0;
13730 /* Largest and smallest buffer positions seen so far during scan of
13732 ptrdiff_t bpos_max
= pos_before
;
13733 ptrdiff_t bpos_min
= pos_after
;
13734 /* Last buffer position covered by an overlay string with an integer
13735 `cursor' property. */
13736 ptrdiff_t bpos_covered
= 0;
13737 /* Non-zero means the display string on which to display the cursor
13738 comes from a text property, not from an overlay. */
13739 int string_from_text_prop
= 0;
13741 /* Don't even try doing anything if called for a mode-line or
13742 header-line row, since the rest of the code isn't prepared to
13743 deal with such calamities. */
13744 eassert (!row
->mode_line_p
);
13745 if (row
->mode_line_p
)
13748 /* Skip over glyphs not having an object at the start and the end of
13749 the row. These are special glyphs like truncation marks on
13750 terminal frames. */
13751 if (row
->displays_text_p
)
13753 if (!row
->reversed_p
)
13756 && INTEGERP (glyph
->object
)
13757 && glyph
->charpos
< 0)
13759 x
+= glyph
->pixel_width
;
13763 && INTEGERP ((end
- 1)->object
)
13764 /* CHARPOS is zero for blanks and stretch glyphs
13765 inserted by extend_face_to_end_of_line. */
13766 && (end
- 1)->charpos
<= 0)
13768 glyph_before
= glyph
- 1;
13775 /* If the glyph row is reversed, we need to process it from back
13776 to front, so swap the edge pointers. */
13777 glyphs_end
= end
= glyph
- 1;
13778 glyph
+= row
->used
[TEXT_AREA
] - 1;
13780 while (glyph
> end
+ 1
13781 && INTEGERP (glyph
->object
)
13782 && glyph
->charpos
< 0)
13785 x
-= glyph
->pixel_width
;
13787 if (INTEGERP (glyph
->object
) && glyph
->charpos
< 0)
13789 /* By default, in reversed rows we put the cursor on the
13790 rightmost (first in the reading order) glyph. */
13791 for (g
= end
+ 1; g
< glyph
; g
++)
13792 x
+= g
->pixel_width
;
13794 && INTEGERP ((end
+ 1)->object
)
13795 && (end
+ 1)->charpos
<= 0)
13797 glyph_before
= glyph
+ 1;
13801 else if (row
->reversed_p
)
13803 /* In R2L rows that don't display text, put the cursor on the
13804 rightmost glyph. Case in point: an empty last line that is
13805 part of an R2L paragraph. */
13807 /* Avoid placing the cursor on the last glyph of the row, where
13808 on terminal frames we hold the vertical border between
13809 adjacent windows. */
13810 if (!FRAME_WINDOW_P (WINDOW_XFRAME (w
))
13811 && !WINDOW_RIGHTMOST_P (w
)
13812 && cursor
== row
->glyphs
[LAST_AREA
] - 1)
13814 x
= -1; /* will be computed below, at label compute_x */
13817 /* Step 1: Try to find the glyph whose character position
13818 corresponds to point. If that's not possible, find 2 glyphs
13819 whose character positions are the closest to point, one before
13820 point, the other after it. */
13821 if (!row
->reversed_p
)
13822 while (/* not marched to end of glyph row */
13824 /* glyph was not inserted by redisplay for internal purposes */
13825 && !INTEGERP (glyph
->object
))
13827 if (BUFFERP (glyph
->object
))
13829 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
13831 if (glyph
->charpos
> bpos_max
)
13832 bpos_max
= glyph
->charpos
;
13833 if (glyph
->charpos
< bpos_min
)
13834 bpos_min
= glyph
->charpos
;
13835 if (!glyph
->avoid_cursor_p
)
13837 /* If we hit point, we've found the glyph on which to
13838 display the cursor. */
13841 match_with_avoid_cursor
= 0;
13844 /* See if we've found a better approximation to
13845 POS_BEFORE or to POS_AFTER. */
13846 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
13848 pos_before
= glyph
->charpos
;
13849 glyph_before
= glyph
;
13851 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
13853 pos_after
= glyph
->charpos
;
13854 glyph_after
= glyph
;
13857 else if (dpos
== 0)
13858 match_with_avoid_cursor
= 1;
13860 else if (STRINGP (glyph
->object
))
13862 Lisp_Object chprop
;
13863 ptrdiff_t glyph_pos
= glyph
->charpos
;
13865 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
13867 if (!NILP (chprop
))
13869 /* If the string came from a `display' text property,
13870 look up the buffer position of that property and
13871 use that position to update bpos_max, as if we
13872 actually saw such a position in one of the row's
13873 glyphs. This helps with supporting integer values
13874 of `cursor' property on the display string in
13875 situations where most or all of the row's buffer
13876 text is completely covered by display properties,
13877 so that no glyph with valid buffer positions is
13878 ever seen in the row. */
13879 ptrdiff_t prop_pos
=
13880 string_buffer_position_lim (glyph
->object
, pos_before
,
13883 if (prop_pos
>= pos_before
)
13884 bpos_max
= prop_pos
- 1;
13886 if (INTEGERP (chprop
))
13888 bpos_covered
= bpos_max
+ XINT (chprop
);
13889 /* If the `cursor' property covers buffer positions up
13890 to and including point, we should display cursor on
13891 this glyph. Note that, if a `cursor' property on one
13892 of the string's characters has an integer value, we
13893 will break out of the loop below _before_ we get to
13894 the position match above. IOW, integer values of
13895 the `cursor' property override the "exact match for
13896 point" strategy of positioning the cursor. */
13897 /* Implementation note: bpos_max == pt_old when, e.g.,
13898 we are in an empty line, where bpos_max is set to
13899 MATRIX_ROW_START_CHARPOS, see above. */
13900 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
13909 x
+= glyph
->pixel_width
;
13912 else if (glyph
> end
) /* row is reversed */
13913 while (!INTEGERP (glyph
->object
))
13915 if (BUFFERP (glyph
->object
))
13917 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
13919 if (glyph
->charpos
> bpos_max
)
13920 bpos_max
= glyph
->charpos
;
13921 if (glyph
->charpos
< bpos_min
)
13922 bpos_min
= glyph
->charpos
;
13923 if (!glyph
->avoid_cursor_p
)
13927 match_with_avoid_cursor
= 0;
13930 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
13932 pos_before
= glyph
->charpos
;
13933 glyph_before
= glyph
;
13935 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
13937 pos_after
= glyph
->charpos
;
13938 glyph_after
= glyph
;
13941 else if (dpos
== 0)
13942 match_with_avoid_cursor
= 1;
13944 else if (STRINGP (glyph
->object
))
13946 Lisp_Object chprop
;
13947 ptrdiff_t glyph_pos
= glyph
->charpos
;
13949 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
13951 if (!NILP (chprop
))
13953 ptrdiff_t prop_pos
=
13954 string_buffer_position_lim (glyph
->object
, pos_before
,
13957 if (prop_pos
>= pos_before
)
13958 bpos_max
= prop_pos
- 1;
13960 if (INTEGERP (chprop
))
13962 bpos_covered
= bpos_max
+ XINT (chprop
);
13963 /* If the `cursor' property covers buffer positions up
13964 to and including point, we should display cursor on
13966 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
13975 if (glyph
== glyphs_end
) /* don't dereference outside TEXT_AREA */
13977 x
--; /* can't use any pixel_width */
13980 x
-= glyph
->pixel_width
;
13983 /* Step 2: If we didn't find an exact match for point, we need to
13984 look for a proper place to put the cursor among glyphs between
13985 GLYPH_BEFORE and GLYPH_AFTER. */
13986 if (!((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
13987 && BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
13988 && !(bpos_max
< pt_old
&& pt_old
<= bpos_covered
))
13990 /* An empty line has a single glyph whose OBJECT is zero and
13991 whose CHARPOS is the position of a newline on that line.
13992 Note that on a TTY, there are more glyphs after that, which
13993 were produced by extend_face_to_end_of_line, but their
13994 CHARPOS is zero or negative. */
13996 (row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
13997 && INTEGERP (glyph
->object
) && glyph
->charpos
> 0
13998 /* On a TTY, continued and truncated rows also have a glyph at
13999 their end whose OBJECT is zero and whose CHARPOS is
14000 positive (the continuation and truncation glyphs), but such
14001 rows are obviously not "empty". */
14002 && !(row
->continued_p
|| row
->truncated_on_right_p
);
14004 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
14006 ptrdiff_t ellipsis_pos
;
14008 /* Scan back over the ellipsis glyphs. */
14009 if (!row
->reversed_p
)
14011 ellipsis_pos
= (glyph
- 1)->charpos
;
14012 while (glyph
> row
->glyphs
[TEXT_AREA
]
14013 && (glyph
- 1)->charpos
== ellipsis_pos
)
14014 glyph
--, x
-= glyph
->pixel_width
;
14015 /* That loop always goes one position too far, including
14016 the glyph before the ellipsis. So scan forward over
14018 x
+= glyph
->pixel_width
;
14021 else /* row is reversed */
14023 ellipsis_pos
= (glyph
+ 1)->charpos
;
14024 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14025 && (glyph
+ 1)->charpos
== ellipsis_pos
)
14026 glyph
++, x
+= glyph
->pixel_width
;
14027 x
-= glyph
->pixel_width
;
14031 else if (match_with_avoid_cursor
)
14033 cursor
= glyph_after
;
14036 else if (string_seen
)
14038 int incr
= row
->reversed_p
? -1 : +1;
14040 /* Need to find the glyph that came out of a string which is
14041 present at point. That glyph is somewhere between
14042 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
14043 positioned between POS_BEFORE and POS_AFTER in the
14045 struct glyph
*start
, *stop
;
14046 ptrdiff_t pos
= pos_before
;
14050 /* If the row ends in a newline from a display string,
14051 reordering could have moved the glyphs belonging to the
14052 string out of the [GLYPH_BEFORE..GLYPH_AFTER] range. So
14053 in this case we extend the search to the last glyph in
14054 the row that was not inserted by redisplay. */
14055 if (row
->ends_in_newline_from_string_p
)
14058 pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
14061 /* GLYPH_BEFORE and GLYPH_AFTER are the glyphs that
14062 correspond to POS_BEFORE and POS_AFTER, respectively. We
14063 need START and STOP in the order that corresponds to the
14064 row's direction as given by its reversed_p flag. If the
14065 directionality of characters between POS_BEFORE and
14066 POS_AFTER is the opposite of the row's base direction,
14067 these characters will have been reordered for display,
14068 and we need to reverse START and STOP. */
14069 if (!row
->reversed_p
)
14071 start
= min (glyph_before
, glyph_after
);
14072 stop
= max (glyph_before
, glyph_after
);
14076 start
= max (glyph_before
, glyph_after
);
14077 stop
= min (glyph_before
, glyph_after
);
14079 for (glyph
= start
+ incr
;
14080 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
14083 /* Any glyphs that come from the buffer are here because
14084 of bidi reordering. Skip them, and only pay
14085 attention to glyphs that came from some string. */
14086 if (STRINGP (glyph
->object
))
14090 /* If the display property covers the newline, we
14091 need to search for it one position farther. */
14092 ptrdiff_t lim
= pos_after
14093 + (pos_after
== MATRIX_ROW_END_CHARPOS (row
) + delta
);
14095 string_from_text_prop
= 0;
14096 str
= glyph
->object
;
14097 tem
= string_buffer_position_lim (str
, pos
, lim
, 0);
14098 if (tem
== 0 /* from overlay */
14101 /* If the string from which this glyph came is
14102 found in the buffer at point, or at position
14103 that is closer to point than pos_after, then
14104 we've found the glyph we've been looking for.
14105 If it comes from an overlay (tem == 0), and
14106 it has the `cursor' property on one of its
14107 glyphs, record that glyph as a candidate for
14108 displaying the cursor. (As in the
14109 unidirectional version, we will display the
14110 cursor on the last candidate we find.) */
14113 || (tem
- pt_old
> 0 && tem
< pos_after
))
14115 /* The glyphs from this string could have
14116 been reordered. Find the one with the
14117 smallest string position. Or there could
14118 be a character in the string with the
14119 `cursor' property, which means display
14120 cursor on that character's glyph. */
14121 ptrdiff_t strpos
= glyph
->charpos
;
14126 string_from_text_prop
= 1;
14129 (row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14130 && EQ (glyph
->object
, str
);
14134 ptrdiff_t gpos
= glyph
->charpos
;
14136 cprop
= Fget_char_property (make_number (gpos
),
14144 if (tem
&& glyph
->charpos
< strpos
)
14146 strpos
= glyph
->charpos
;
14152 || (tem
- pt_old
> 0 && tem
< pos_after
))
14156 pos
= tem
+ 1; /* don't find previous instances */
14158 /* This string is not what we want; skip all of the
14159 glyphs that came from it. */
14160 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14161 && EQ (glyph
->object
, str
))
14168 /* If we reached the end of the line, and END was from a string,
14169 the cursor is not on this line. */
14171 && (row
->reversed_p
? glyph
<= end
: glyph
>= end
)
14172 && (row
->reversed_p
? end
> glyphs_end
: end
< glyphs_end
)
14173 && STRINGP (end
->object
)
14174 && row
->continued_p
)
14177 /* A truncated row may not include PT among its character positions.
14178 Setting the cursor inside the scroll margin will trigger
14179 recalculation of hscroll in hscroll_window_tree. But if a
14180 display string covers point, defer to the string-handling
14181 code below to figure this out. */
14182 else if (row
->truncated_on_left_p
&& pt_old
< bpos_min
)
14184 cursor
= glyph_before
;
14187 else if ((row
->truncated_on_right_p
&& pt_old
> bpos_max
)
14188 /* Zero-width characters produce no glyphs. */
14190 && (row
->reversed_p
14191 ? glyph_after
> glyphs_end
14192 : glyph_after
< glyphs_end
)))
14194 cursor
= glyph_after
;
14200 if (cursor
!= NULL
)
14202 else if (glyph
== glyphs_end
14203 && pos_before
== pos_after
14204 && STRINGP ((row
->reversed_p
14205 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14206 : row
->glyphs
[TEXT_AREA
])->object
))
14208 /* If all the glyphs of this row came from strings, put the
14209 cursor on the first glyph of the row. This avoids having the
14210 cursor outside of the text area in this very rare and hard
14214 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14215 : row
->glyphs
[TEXT_AREA
];
14221 /* Need to compute x that corresponds to GLYPH. */
14222 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
14224 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
14226 x
+= g
->pixel_width
;
14230 /* ROW could be part of a continued line, which, under bidi
14231 reordering, might have other rows whose start and end charpos
14232 occlude point. Only set w->cursor if we found a better
14233 approximation to the cursor position than we have from previously
14234 examined candidate rows belonging to the same continued line. */
14235 if (/* we already have a candidate row */
14236 w
->cursor
.vpos
>= 0
14237 /* that candidate is not the row we are processing */
14238 && MATRIX_ROW (matrix
, w
->cursor
.vpos
) != row
14239 /* Make sure cursor.vpos specifies a row whose start and end
14240 charpos occlude point, and it is valid candidate for being a
14241 cursor-row. This is because some callers of this function
14242 leave cursor.vpos at the row where the cursor was displayed
14243 during the last redisplay cycle. */
14244 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)) <= pt_old
14245 && pt_old
<= MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14246 && cursor_row_p (MATRIX_ROW (matrix
, w
->cursor
.vpos
)))
14249 MATRIX_ROW_GLYPH_START (matrix
, w
->cursor
.vpos
) + w
->cursor
.hpos
;
14251 /* Don't consider glyphs that are outside TEXT_AREA. */
14252 if (!(row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
))
14254 /* Keep the candidate whose buffer position is the closest to
14255 point or has the `cursor' property. */
14256 if (/* previous candidate is a glyph in TEXT_AREA of that row */
14257 w
->cursor
.hpos
>= 0
14258 && w
->cursor
.hpos
< MATRIX_ROW_USED (matrix
, w
->cursor
.vpos
)
14259 && ((BUFFERP (g1
->object
)
14260 && (g1
->charpos
== pt_old
/* an exact match always wins */
14261 || (BUFFERP (glyph
->object
)
14262 && eabs (g1
->charpos
- pt_old
)
14263 < eabs (glyph
->charpos
- pt_old
))))
14264 /* previous candidate is a glyph from a string that has
14265 a non-nil `cursor' property */
14266 || (STRINGP (g1
->object
)
14267 && (!NILP (Fget_char_property (make_number (g1
->charpos
),
14268 Qcursor
, g1
->object
))
14269 /* previous candidate is from the same display
14270 string as this one, and the display string
14271 came from a text property */
14272 || (EQ (g1
->object
, glyph
->object
)
14273 && string_from_text_prop
)
14274 /* this candidate is from newline and its
14275 position is not an exact match */
14276 || (INTEGERP (glyph
->object
)
14277 && glyph
->charpos
!= pt_old
)))))
14279 /* If this candidate gives an exact match, use that. */
14280 if (!((BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14281 /* If this candidate is a glyph created for the
14282 terminating newline of a line, and point is on that
14283 newline, it wins because it's an exact match. */
14284 || (!row
->continued_p
14285 && INTEGERP (glyph
->object
)
14286 && glyph
->charpos
== 0
14287 && pt_old
== MATRIX_ROW_END_CHARPOS (row
) - 1))
14288 /* Otherwise, keep the candidate that comes from a row
14289 spanning less buffer positions. This may win when one or
14290 both candidate positions are on glyphs that came from
14291 display strings, for which we cannot compare buffer
14293 && MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14294 - MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14295 < MATRIX_ROW_END_CHARPOS (row
) - MATRIX_ROW_START_CHARPOS (row
))
14298 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
14300 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
14301 w
->cursor
.y
= row
->y
+ dy
;
14303 if (w
== XWINDOW (selected_window
))
14305 if (!row
->continued_p
14306 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
14309 this_line_buffer
= XBUFFER (w
->buffer
);
14311 CHARPOS (this_line_start_pos
)
14312 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
14313 BYTEPOS (this_line_start_pos
)
14314 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
14316 CHARPOS (this_line_end_pos
)
14317 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
14318 BYTEPOS (this_line_end_pos
)
14319 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
14321 this_line_y
= w
->cursor
.y
;
14322 this_line_pixel_height
= row
->height
;
14323 this_line_vpos
= w
->cursor
.vpos
;
14324 this_line_start_x
= row
->x
;
14327 CHARPOS (this_line_start_pos
) = 0;
14334 /* Run window scroll functions, if any, for WINDOW with new window
14335 start STARTP. Sets the window start of WINDOW to that position.
14337 We assume that the window's buffer is really current. */
14339 static struct text_pos
14340 run_window_scroll_functions (Lisp_Object window
, struct text_pos startp
)
14342 struct window
*w
= XWINDOW (window
);
14343 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
14345 if (current_buffer
!= XBUFFER (w
->buffer
))
14348 if (!NILP (Vwindow_scroll_functions
))
14350 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
14351 make_number (CHARPOS (startp
)));
14352 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14353 /* In case the hook functions switch buffers. */
14354 set_buffer_internal (XBUFFER (w
->buffer
));
14361 /* Make sure the line containing the cursor is fully visible.
14362 A value of 1 means there is nothing to be done.
14363 (Either the line is fully visible, or it cannot be made so,
14364 or we cannot tell.)
14366 If FORCE_P is non-zero, return 0 even if partial visible cursor row
14367 is higher than window.
14369 A value of 0 means the caller should do scrolling
14370 as if point had gone off the screen. */
14373 cursor_row_fully_visible_p (struct window
*w
, int force_p
, int current_matrix_p
)
14375 struct glyph_matrix
*matrix
;
14376 struct glyph_row
*row
;
14379 if (!make_cursor_line_fully_visible_p
)
14382 /* It's not always possible to find the cursor, e.g, when a window
14383 is full of overlay strings. Don't do anything in that case. */
14384 if (w
->cursor
.vpos
< 0)
14387 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
14388 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
14390 /* If the cursor row is not partially visible, there's nothing to do. */
14391 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
14394 /* If the row the cursor is in is taller than the window's height,
14395 it's not clear what to do, so do nothing. */
14396 window_height
= window_box_height (w
);
14397 if (row
->height
>= window_height
)
14399 if (!force_p
|| MINI_WINDOW_P (w
)
14400 || w
->vscroll
|| w
->cursor
.vpos
== 0)
14407 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
14408 non-zero means only WINDOW is redisplayed in redisplay_internal.
14409 TEMP_SCROLL_STEP has the same meaning as emacs_scroll_step, and is used
14410 in redisplay_window to bring a partially visible line into view in
14411 the case that only the cursor has moved.
14413 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
14414 last screen line's vertical height extends past the end of the screen.
14418 1 if scrolling succeeded
14420 0 if scrolling didn't find point.
14422 -1 if new fonts have been loaded so that we must interrupt
14423 redisplay, adjust glyph matrices, and try again. */
14429 SCROLLING_NEED_LARGER_MATRICES
14432 /* If scroll-conservatively is more than this, never recenter.
14434 If you change this, don't forget to update the doc string of
14435 `scroll-conservatively' and the Emacs manual. */
14436 #define SCROLL_LIMIT 100
14439 try_scrolling (Lisp_Object window
, int just_this_one_p
,
14440 ptrdiff_t arg_scroll_conservatively
, ptrdiff_t scroll_step
,
14441 int temp_scroll_step
, int last_line_misfit
)
14443 struct window
*w
= XWINDOW (window
);
14444 struct frame
*f
= XFRAME (w
->frame
);
14445 struct text_pos pos
, startp
;
14447 int this_scroll_margin
, scroll_max
, rc
, height
;
14448 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
14449 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
14450 Lisp_Object aggressive
;
14451 /* We will never try scrolling more than this number of lines. */
14452 int scroll_limit
= SCROLL_LIMIT
;
14455 debug_method_add (w
, "try_scrolling");
14458 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14460 /* Compute scroll margin height in pixels. We scroll when point is
14461 within this distance from the top or bottom of the window. */
14462 if (scroll_margin
> 0)
14463 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
14464 * FRAME_LINE_HEIGHT (f
);
14466 this_scroll_margin
= 0;
14468 /* Force arg_scroll_conservatively to have a reasonable value, to
14469 avoid scrolling too far away with slow move_it_* functions. Note
14470 that the user can supply scroll-conservatively equal to
14471 `most-positive-fixnum', which can be larger than INT_MAX. */
14472 if (arg_scroll_conservatively
> scroll_limit
)
14474 arg_scroll_conservatively
= scroll_limit
+ 1;
14475 scroll_max
= scroll_limit
* FRAME_LINE_HEIGHT (f
);
14477 else if (scroll_step
|| arg_scroll_conservatively
|| temp_scroll_step
)
14478 /* Compute how much we should try to scroll maximally to bring
14479 point into view. */
14480 scroll_max
= (max (scroll_step
,
14481 max (arg_scroll_conservatively
, temp_scroll_step
))
14482 * FRAME_LINE_HEIGHT (f
));
14483 else if (NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
))
14484 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
)))
14485 /* We're trying to scroll because of aggressive scrolling but no
14486 scroll_step is set. Choose an arbitrary one. */
14487 scroll_max
= 10 * FRAME_LINE_HEIGHT (f
);
14493 /* Decide whether to scroll down. */
14494 if (PT
> CHARPOS (startp
))
14496 int scroll_margin_y
;
14498 /* Compute the pixel ypos of the scroll margin, then move IT to
14499 either that ypos or PT, whichever comes first. */
14500 start_display (&it
, w
, startp
);
14501 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
14502 - FRAME_LINE_HEIGHT (f
) * extra_scroll_margin_lines
;
14503 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
14504 (MOVE_TO_POS
| MOVE_TO_Y
));
14506 if (PT
> CHARPOS (it
.current
.pos
))
14508 int y0
= line_bottom_y (&it
);
14509 /* Compute how many pixels below window bottom to stop searching
14510 for PT. This avoids costly search for PT that is far away if
14511 the user limited scrolling by a small number of lines, but
14512 always finds PT if scroll_conservatively is set to a large
14513 number, such as most-positive-fixnum. */
14514 int slack
= max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
));
14515 int y_to_move
= it
.last_visible_y
+ slack
;
14517 /* Compute the distance from the scroll margin to PT or to
14518 the scroll limit, whichever comes first. This should
14519 include the height of the cursor line, to make that line
14521 move_it_to (&it
, PT
, -1, y_to_move
,
14522 -1, MOVE_TO_POS
| MOVE_TO_Y
);
14523 dy
= line_bottom_y (&it
) - y0
;
14525 if (dy
> scroll_max
)
14526 return SCROLLING_FAILED
;
14535 /* Point is in or below the bottom scroll margin, so move the
14536 window start down. If scrolling conservatively, move it just
14537 enough down to make point visible. If scroll_step is set,
14538 move it down by scroll_step. */
14539 if (arg_scroll_conservatively
)
14541 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
14542 FRAME_LINE_HEIGHT (f
) * arg_scroll_conservatively
);
14543 else if (scroll_step
|| temp_scroll_step
)
14544 amount_to_scroll
= scroll_max
;
14547 aggressive
= BVAR (current_buffer
, scroll_up_aggressively
);
14548 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14549 if (NUMBERP (aggressive
))
14551 double float_amount
= XFLOATINT (aggressive
) * height
;
14552 int aggressive_scroll
= float_amount
;
14553 if (aggressive_scroll
== 0 && float_amount
> 0)
14554 aggressive_scroll
= 1;
14555 /* Don't let point enter the scroll margin near top of
14556 the window. This could happen if the value of
14557 scroll_up_aggressively is too large and there are
14558 non-zero margins, because scroll_up_aggressively
14559 means put point that fraction of window height
14560 _from_the_bottom_margin_. */
14561 if (aggressive_scroll
+ 2*this_scroll_margin
> height
)
14562 aggressive_scroll
= height
- 2*this_scroll_margin
;
14563 amount_to_scroll
= dy
+ aggressive_scroll
;
14567 if (amount_to_scroll
<= 0)
14568 return SCROLLING_FAILED
;
14570 start_display (&it
, w
, startp
);
14571 if (arg_scroll_conservatively
<= scroll_limit
)
14572 move_it_vertically (&it
, amount_to_scroll
);
14575 /* Extra precision for users who set scroll-conservatively
14576 to a large number: make sure the amount we scroll
14577 the window start is never less than amount_to_scroll,
14578 which was computed as distance from window bottom to
14579 point. This matters when lines at window top and lines
14580 below window bottom have different height. */
14582 void *it1data
= NULL
;
14583 /* We use a temporary it1 because line_bottom_y can modify
14584 its argument, if it moves one line down; see there. */
14587 SAVE_IT (it1
, it
, it1data
);
14588 start_y
= line_bottom_y (&it1
);
14590 RESTORE_IT (&it
, &it
, it1data
);
14591 move_it_by_lines (&it
, 1);
14592 SAVE_IT (it1
, it
, it1data
);
14593 } while (line_bottom_y (&it1
) - start_y
< amount_to_scroll
);
14596 /* If STARTP is unchanged, move it down another screen line. */
14597 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
14598 move_it_by_lines (&it
, 1);
14599 startp
= it
.current
.pos
;
14603 struct text_pos scroll_margin_pos
= startp
;
14605 /* See if point is inside the scroll margin at the top of the
14607 if (this_scroll_margin
)
14609 start_display (&it
, w
, startp
);
14610 move_it_vertically (&it
, this_scroll_margin
);
14611 scroll_margin_pos
= it
.current
.pos
;
14614 if (PT
< CHARPOS (scroll_margin_pos
))
14616 /* Point is in the scroll margin at the top of the window or
14617 above what is displayed in the window. */
14620 /* Compute the vertical distance from PT to the scroll
14621 margin position. Move as far as scroll_max allows, or
14622 one screenful, or 10 screen lines, whichever is largest.
14623 Give up if distance is greater than scroll_max or if we
14624 didn't reach the scroll margin position. */
14625 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
14626 start_display (&it
, w
, pos
);
14628 y_to_move
= max (it
.last_visible_y
,
14629 max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
)));
14630 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
14632 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
14633 dy
= it
.current_y
- y0
;
14634 if (dy
> scroll_max
14635 || IT_CHARPOS (it
) < CHARPOS (scroll_margin_pos
))
14636 return SCROLLING_FAILED
;
14638 /* Compute new window start. */
14639 start_display (&it
, w
, startp
);
14641 if (arg_scroll_conservatively
)
14642 amount_to_scroll
= max (dy
, FRAME_LINE_HEIGHT (f
) *
14643 max (scroll_step
, temp_scroll_step
));
14644 else if (scroll_step
|| temp_scroll_step
)
14645 amount_to_scroll
= scroll_max
;
14648 aggressive
= BVAR (current_buffer
, scroll_down_aggressively
);
14649 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14650 if (NUMBERP (aggressive
))
14652 double float_amount
= XFLOATINT (aggressive
) * height
;
14653 int aggressive_scroll
= float_amount
;
14654 if (aggressive_scroll
== 0 && float_amount
> 0)
14655 aggressive_scroll
= 1;
14656 /* Don't let point enter the scroll margin near
14657 bottom of the window, if the value of
14658 scroll_down_aggressively happens to be too
14660 if (aggressive_scroll
+ 2*this_scroll_margin
> height
)
14661 aggressive_scroll
= height
- 2*this_scroll_margin
;
14662 amount_to_scroll
= dy
+ aggressive_scroll
;
14666 if (amount_to_scroll
<= 0)
14667 return SCROLLING_FAILED
;
14669 move_it_vertically_backward (&it
, amount_to_scroll
);
14670 startp
= it
.current
.pos
;
14674 /* Run window scroll functions. */
14675 startp
= run_window_scroll_functions (window
, startp
);
14677 /* Display the window. Give up if new fonts are loaded, or if point
14679 if (!try_window (window
, startp
, 0))
14680 rc
= SCROLLING_NEED_LARGER_MATRICES
;
14681 else if (w
->cursor
.vpos
< 0)
14683 clear_glyph_matrix (w
->desired_matrix
);
14684 rc
= SCROLLING_FAILED
;
14688 /* Maybe forget recorded base line for line number display. */
14689 if (!just_this_one_p
14690 || current_buffer
->clip_changed
14691 || BEG_UNCHANGED
< CHARPOS (startp
))
14692 w
->base_line_number
= 0;
14694 /* If cursor ends up on a partially visible line,
14695 treat that as being off the bottom of the screen. */
14696 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0)
14697 /* It's possible that the cursor is on the first line of the
14698 buffer, which is partially obscured due to a vscroll
14699 (Bug#7537). In that case, avoid looping forever . */
14700 && extra_scroll_margin_lines
< w
->desired_matrix
->nrows
- 1)
14702 clear_glyph_matrix (w
->desired_matrix
);
14703 ++extra_scroll_margin_lines
;
14706 rc
= SCROLLING_SUCCESS
;
14713 /* Compute a suitable window start for window W if display of W starts
14714 on a continuation line. Value is non-zero if a new window start
14717 The new window start will be computed, based on W's width, starting
14718 from the start of the continued line. It is the start of the
14719 screen line with the minimum distance from the old start W->start. */
14722 compute_window_start_on_continuation_line (struct window
*w
)
14724 struct text_pos pos
, start_pos
;
14725 int window_start_changed_p
= 0;
14727 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
14729 /* If window start is on a continuation line... Window start may be
14730 < BEGV in case there's invisible text at the start of the
14731 buffer (M-x rmail, for example). */
14732 if (CHARPOS (start_pos
) > BEGV
14733 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
14736 struct glyph_row
*row
;
14738 /* Handle the case that the window start is out of range. */
14739 if (CHARPOS (start_pos
) < BEGV
)
14740 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
14741 else if (CHARPOS (start_pos
) > ZV
)
14742 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
14744 /* Find the start of the continued line. This should be fast
14745 because scan_buffer is fast (newline cache). */
14746 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
14747 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
14748 row
, DEFAULT_FACE_ID
);
14749 reseat_at_previous_visible_line_start (&it
);
14751 /* If the line start is "too far" away from the window start,
14752 say it takes too much time to compute a new window start. */
14753 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
14754 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
14756 int min_distance
, distance
;
14758 /* Move forward by display lines to find the new window
14759 start. If window width was enlarged, the new start can
14760 be expected to be > the old start. If window width was
14761 decreased, the new window start will be < the old start.
14762 So, we're looking for the display line start with the
14763 minimum distance from the old window start. */
14764 pos
= it
.current
.pos
;
14765 min_distance
= INFINITY
;
14766 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
14767 distance
< min_distance
)
14769 min_distance
= distance
;
14770 pos
= it
.current
.pos
;
14771 move_it_by_lines (&it
, 1);
14774 /* Set the window start there. */
14775 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
14776 window_start_changed_p
= 1;
14780 return window_start_changed_p
;
14784 /* Try cursor movement in case text has not changed in window WINDOW,
14785 with window start STARTP. Value is
14787 CURSOR_MOVEMENT_SUCCESS if successful
14789 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
14791 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
14792 display. *SCROLL_STEP is set to 1, under certain circumstances, if
14793 we want to scroll as if scroll-step were set to 1. See the code.
14795 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
14796 which case we have to abort this redisplay, and adjust matrices
14801 CURSOR_MOVEMENT_SUCCESS
,
14802 CURSOR_MOVEMENT_CANNOT_BE_USED
,
14803 CURSOR_MOVEMENT_MUST_SCROLL
,
14804 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
14808 try_cursor_movement (Lisp_Object window
, struct text_pos startp
, int *scroll_step
)
14810 struct window
*w
= XWINDOW (window
);
14811 struct frame
*f
= XFRAME (w
->frame
);
14812 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
14815 if (inhibit_try_cursor_movement
)
14819 /* Previously, there was a check for Lisp integer in the
14820 if-statement below. Now, this field is converted to
14821 ptrdiff_t, thus zero means invalid position in a buffer. */
14822 eassert (w
->last_point
> 0);
14824 /* Handle case where text has not changed, only point, and it has
14825 not moved off the frame. */
14826 if (/* Point may be in this window. */
14827 PT
>= CHARPOS (startp
)
14828 /* Selective display hasn't changed. */
14829 && !current_buffer
->clip_changed
14830 /* Function force-mode-line-update is used to force a thorough
14831 redisplay. It sets either windows_or_buffers_changed or
14832 update_mode_lines. So don't take a shortcut here for these
14834 && !update_mode_lines
14835 && !windows_or_buffers_changed
14836 && !cursor_type_changed
14837 /* Can't use this case if highlighting a region. When a
14838 region exists, cursor movement has to do more than just
14840 && markpos_of_region () < 0
14841 && !w
->region_showing
14842 && NILP (Vshow_trailing_whitespace
)
14843 /* This code is not used for mini-buffer for the sake of the case
14844 of redisplaying to replace an echo area message; since in
14845 that case the mini-buffer contents per se are usually
14846 unchanged. This code is of no real use in the mini-buffer
14847 since the handling of this_line_start_pos, etc., in redisplay
14848 handles the same cases. */
14849 && !EQ (window
, minibuf_window
)
14850 /* When splitting windows or for new windows, it happens that
14851 redisplay is called with a nil window_end_vpos or one being
14852 larger than the window. This should really be fixed in
14853 window.c. I don't have this on my list, now, so we do
14854 approximately the same as the old redisplay code. --gerd. */
14855 && INTEGERP (w
->window_end_vpos
)
14856 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
14857 && (FRAME_WINDOW_P (f
)
14858 || !overlay_arrow_in_current_buffer_p ()))
14860 int this_scroll_margin
, top_scroll_margin
;
14861 struct glyph_row
*row
= NULL
;
14864 debug_method_add (w
, "cursor movement");
14867 /* Scroll if point within this distance from the top or bottom
14868 of the window. This is a pixel value. */
14869 if (scroll_margin
> 0)
14871 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14872 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
14875 this_scroll_margin
= 0;
14877 top_scroll_margin
= this_scroll_margin
;
14878 if (WINDOW_WANTS_HEADER_LINE_P (w
))
14879 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
14881 /* Start with the row the cursor was displayed during the last
14882 not paused redisplay. Give up if that row is not valid. */
14883 if (w
->last_cursor
.vpos
< 0
14884 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
14885 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14888 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
14889 if (row
->mode_line_p
)
14891 if (!row
->enabled_p
)
14892 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14895 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
14897 int scroll_p
= 0, must_scroll
= 0;
14898 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
14900 if (PT
> w
->last_point
)
14902 /* Point has moved forward. */
14903 while (MATRIX_ROW_END_CHARPOS (row
) < PT
14904 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
14906 eassert (row
->enabled_p
);
14910 /* If the end position of a row equals the start
14911 position of the next row, and PT is at that position,
14912 we would rather display cursor in the next line. */
14913 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
14914 && MATRIX_ROW_END_CHARPOS (row
) == PT
14915 && row
< w
->current_matrix
->rows
14916 + w
->current_matrix
->nrows
- 1
14917 && MATRIX_ROW_START_CHARPOS (row
+1) == PT
14918 && !cursor_row_p (row
))
14921 /* If within the scroll margin, scroll. Note that
14922 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
14923 the next line would be drawn, and that
14924 this_scroll_margin can be zero. */
14925 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
14926 || PT
> MATRIX_ROW_END_CHARPOS (row
)
14927 /* Line is completely visible last line in window
14928 and PT is to be set in the next line. */
14929 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
14930 && PT
== MATRIX_ROW_END_CHARPOS (row
)
14931 && !row
->ends_at_zv_p
14932 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
14935 else if (PT
< w
->last_point
)
14937 /* Cursor has to be moved backward. Note that PT >=
14938 CHARPOS (startp) because of the outer if-statement. */
14939 while (!row
->mode_line_p
14940 && (MATRIX_ROW_START_CHARPOS (row
) > PT
14941 || (MATRIX_ROW_START_CHARPOS (row
) == PT
14942 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
14943 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
14944 row
> w
->current_matrix
->rows
14945 && (row
-1)->ends_in_newline_from_string_p
))))
14946 && (row
->y
> top_scroll_margin
14947 || CHARPOS (startp
) == BEGV
))
14949 eassert (row
->enabled_p
);
14953 /* Consider the following case: Window starts at BEGV,
14954 there is invisible, intangible text at BEGV, so that
14955 display starts at some point START > BEGV. It can
14956 happen that we are called with PT somewhere between
14957 BEGV and START. Try to handle that case. */
14958 if (row
< w
->current_matrix
->rows
14959 || row
->mode_line_p
)
14961 row
= w
->current_matrix
->rows
;
14962 if (row
->mode_line_p
)
14966 /* Due to newlines in overlay strings, we may have to
14967 skip forward over overlay strings. */
14968 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
14969 && MATRIX_ROW_END_CHARPOS (row
) == PT
14970 && !cursor_row_p (row
))
14973 /* If within the scroll margin, scroll. */
14974 if (row
->y
< top_scroll_margin
14975 && CHARPOS (startp
) != BEGV
)
14980 /* Cursor did not move. So don't scroll even if cursor line
14981 is partially visible, as it was so before. */
14982 rc
= CURSOR_MOVEMENT_SUCCESS
;
14985 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
14986 || PT
> MATRIX_ROW_END_CHARPOS (row
))
14988 /* if PT is not in the glyph row, give up. */
14989 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14992 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
14993 && !NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
14995 struct glyph_row
*row1
;
14997 /* If rows are bidi-reordered and point moved, back up
14998 until we find a row that does not belong to a
14999 continuation line. This is because we must consider
15000 all rows of a continued line as candidates for the
15001 new cursor positioning, since row start and end
15002 positions change non-linearly with vertical position
15004 /* FIXME: Revisit this when glyph ``spilling'' in
15005 continuation lines' rows is implemented for
15006 bidi-reordered rows. */
15007 for (row1
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15008 MATRIX_ROW_CONTINUATION_LINE_P (row
);
15011 /* If we hit the beginning of the displayed portion
15012 without finding the first row of a continued
15016 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15019 eassert (row
->enabled_p
);
15024 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15025 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
15026 /* Make sure this isn't a header line by any chance, since
15027 then MATRIX_ROW_PARTIALLY_VISIBLE_P might yield non-zero. */
15028 && !row
->mode_line_p
15029 && make_cursor_line_fully_visible_p
)
15031 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
15032 && !row
->ends_at_zv_p
15033 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15034 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15035 else if (row
->height
> window_box_height (w
))
15037 /* If we end up in a partially visible line, let's
15038 make it fully visible, except when it's taller
15039 than the window, in which case we can't do much
15042 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15046 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15047 if (!cursor_row_fully_visible_p (w
, 0, 1))
15048 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15050 rc
= CURSOR_MOVEMENT_SUCCESS
;
15054 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15055 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15056 && !NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
15058 /* With bidi-reordered rows, there could be more than
15059 one candidate row whose start and end positions
15060 occlude point. We need to let set_cursor_from_row
15061 find the best candidate. */
15062 /* FIXME: Revisit this when glyph ``spilling'' in
15063 continuation lines' rows is implemented for
15064 bidi-reordered rows. */
15069 int at_zv_p
= 0, exact_match_p
= 0;
15071 if (MATRIX_ROW_START_CHARPOS (row
) <= PT
15072 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
15073 && cursor_row_p (row
))
15074 rv
|= set_cursor_from_row (w
, row
, w
->current_matrix
,
15076 /* As soon as we've found the exact match for point,
15077 or the first suitable row whose ends_at_zv_p flag
15078 is set, we are done. */
15080 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
)->ends_at_zv_p
;
15082 && w
->cursor
.hpos
>= 0
15083 && w
->cursor
.hpos
< MATRIX_ROW_USED (w
->current_matrix
,
15086 struct glyph_row
*candidate
=
15087 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
15089 candidate
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
15090 ptrdiff_t endpos
= MATRIX_ROW_END_CHARPOS (candidate
);
15093 (BUFFERP (g
->object
) && g
->charpos
== PT
)
15094 || (INTEGERP (g
->object
)
15095 && (g
->charpos
== PT
15096 || (g
->charpos
== 0 && endpos
- 1 == PT
)));
15098 if (rv
&& (at_zv_p
|| exact_match_p
))
15100 rc
= CURSOR_MOVEMENT_SUCCESS
;
15103 if (MATRIX_ROW_BOTTOM_Y (row
) == last_y
)
15107 while (((MATRIX_ROW_CONTINUATION_LINE_P (row
)
15108 || row
->continued_p
)
15109 && MATRIX_ROW_BOTTOM_Y (row
) <= last_y
)
15110 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15111 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
));
15112 /* If we didn't find any candidate rows, or exited the
15113 loop before all the candidates were examined, signal
15114 to the caller that this method failed. */
15115 if (rc
!= CURSOR_MOVEMENT_SUCCESS
15117 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
15118 && !row
->continued_p
))
15119 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15121 rc
= CURSOR_MOVEMENT_SUCCESS
;
15127 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
15129 rc
= CURSOR_MOVEMENT_SUCCESS
;
15134 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15135 && MATRIX_ROW_START_CHARPOS (row
) == PT
15136 && cursor_row_p (row
));
15144 #if !defined USE_TOOLKIT_SCROLL_BARS || defined USE_GTK
15148 set_vertical_scroll_bar (struct window
*w
)
15150 ptrdiff_t start
, end
, whole
;
15152 /* Calculate the start and end positions for the current window.
15153 At some point, it would be nice to choose between scrollbars
15154 which reflect the whole buffer size, with special markers
15155 indicating narrowing, and scrollbars which reflect only the
15158 Note that mini-buffers sometimes aren't displaying any text. */
15159 if (!MINI_WINDOW_P (w
)
15160 || (w
== XWINDOW (minibuf_window
)
15161 && NILP (echo_area_buffer
[0])))
15163 struct buffer
*buf
= XBUFFER (w
->buffer
);
15164 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
15165 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
15166 /* I don't think this is guaranteed to be right. For the
15167 moment, we'll pretend it is. */
15168 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
15172 if (whole
< (end
- start
))
15173 whole
= end
- start
;
15176 start
= end
= whole
= 0;
15178 /* Indicate what this scroll bar ought to be displaying now. */
15179 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15180 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15181 (w
, end
- start
, whole
, start
);
15185 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
15186 selected_window is redisplayed.
15188 We can return without actually redisplaying the window if
15189 fonts_changed_p. In that case, redisplay_internal will
15193 redisplay_window (Lisp_Object window
, int just_this_one_p
)
15195 struct window
*w
= XWINDOW (window
);
15196 struct frame
*f
= XFRAME (w
->frame
);
15197 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15198 struct buffer
*old
= current_buffer
;
15199 struct text_pos lpoint
, opoint
, startp
;
15200 int update_mode_line
;
15203 /* Record it now because it's overwritten. */
15204 int current_matrix_up_to_date_p
= 0;
15205 int used_current_matrix_p
= 0;
15206 /* This is less strict than current_matrix_up_to_date_p.
15207 It indicates that the buffer contents and narrowing are unchanged. */
15208 int buffer_unchanged_p
= 0;
15209 int temp_scroll_step
= 0;
15210 ptrdiff_t count
= SPECPDL_INDEX ();
15212 int centering_position
= -1;
15213 int last_line_misfit
= 0;
15214 ptrdiff_t beg_unchanged
, end_unchanged
;
15216 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15219 /* W must be a leaf window here. */
15220 eassert (!NILP (w
->buffer
));
15222 *w
->desired_matrix
->method
= 0;
15226 reconsider_clip_changes (w
, buffer
);
15228 /* Has the mode line to be updated? */
15229 update_mode_line
= (w
->update_mode_line
15230 || update_mode_lines
15231 || buffer
->clip_changed
15232 || buffer
->prevent_redisplay_optimizations_p
);
15234 if (MINI_WINDOW_P (w
))
15236 if (w
== XWINDOW (echo_area_window
)
15237 && !NILP (echo_area_buffer
[0]))
15239 if (update_mode_line
)
15240 /* We may have to update a tty frame's menu bar or a
15241 tool-bar. Example `M-x C-h C-h C-g'. */
15242 goto finish_menu_bars
;
15244 /* We've already displayed the echo area glyphs in this window. */
15245 goto finish_scroll_bars
;
15247 else if ((w
!= XWINDOW (minibuf_window
)
15248 || minibuf_level
== 0)
15249 /* When buffer is nonempty, redisplay window normally. */
15250 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
15251 /* Quail displays non-mini buffers in minibuffer window.
15252 In that case, redisplay the window normally. */
15253 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
15255 /* W is a mini-buffer window, but it's not active, so clear
15257 int yb
= window_text_bottom_y (w
);
15258 struct glyph_row
*row
;
15261 for (y
= 0, row
= w
->desired_matrix
->rows
;
15263 y
+= row
->height
, ++row
)
15264 blank_row (w
, row
, y
);
15265 goto finish_scroll_bars
;
15268 clear_glyph_matrix (w
->desired_matrix
);
15271 /* Otherwise set up data on this window; select its buffer and point
15273 /* Really select the buffer, for the sake of buffer-local
15275 set_buffer_internal_1 (XBUFFER (w
->buffer
));
15277 current_matrix_up_to_date_p
15278 = (w
->window_end_valid
15279 && !current_buffer
->clip_changed
15280 && !current_buffer
->prevent_redisplay_optimizations_p
15281 && !window_outdated (w
));
15283 /* Run the window-bottom-change-functions
15284 if it is possible that the text on the screen has changed
15285 (either due to modification of the text, or any other reason). */
15286 if (!current_matrix_up_to_date_p
15287 && !NILP (Vwindow_text_change_functions
))
15289 safe_run_hooks (Qwindow_text_change_functions
);
15293 beg_unchanged
= BEG_UNCHANGED
;
15294 end_unchanged
= END_UNCHANGED
;
15296 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
15298 specbind (Qinhibit_point_motion_hooks
, Qt
);
15301 = (w
->window_end_valid
15302 && !current_buffer
->clip_changed
15303 && !window_outdated (w
));
15305 /* When windows_or_buffers_changed is non-zero, we can't rely on
15306 the window end being valid, so set it to nil there. */
15307 if (windows_or_buffers_changed
)
15309 /* If window starts on a continuation line, maybe adjust the
15310 window start in case the window's width changed. */
15311 if (XMARKER (w
->start
)->buffer
== current_buffer
)
15312 compute_window_start_on_continuation_line (w
);
15314 w
->window_end_valid
= 0;
15317 /* Some sanity checks. */
15318 CHECK_WINDOW_END (w
);
15319 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
15321 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
15324 if (mode_line_update_needed (w
))
15325 update_mode_line
= 1;
15327 /* Point refers normally to the selected window. For any other
15328 window, set up appropriate value. */
15329 if (!EQ (window
, selected_window
))
15331 ptrdiff_t new_pt
= marker_position (w
->pointm
);
15332 ptrdiff_t new_pt_byte
= marker_byte_position (w
->pointm
);
15336 new_pt_byte
= BEGV_BYTE
;
15337 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
15339 else if (new_pt
> (ZV
- 1))
15342 new_pt_byte
= ZV_BYTE
;
15343 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
15346 /* We don't use SET_PT so that the point-motion hooks don't run. */
15347 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
15350 /* If any of the character widths specified in the display table
15351 have changed, invalidate the width run cache. It's true that
15352 this may be a bit late to catch such changes, but the rest of
15353 redisplay goes (non-fatally) haywire when the display table is
15354 changed, so why should we worry about doing any better? */
15355 if (current_buffer
->width_run_cache
)
15357 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
15359 if (! disptab_matches_widthtab
15360 (disptab
, XVECTOR (BVAR (current_buffer
, width_table
))))
15362 invalidate_region_cache (current_buffer
,
15363 current_buffer
->width_run_cache
,
15365 recompute_width_table (current_buffer
, disptab
);
15369 /* If window-start is screwed up, choose a new one. */
15370 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
15373 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15375 /* If someone specified a new starting point but did not insist,
15376 check whether it can be used. */
15377 if (w
->optional_new_start
15378 && CHARPOS (startp
) >= BEGV
15379 && CHARPOS (startp
) <= ZV
)
15381 w
->optional_new_start
= 0;
15382 start_display (&it
, w
, startp
);
15383 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
15384 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15385 if (IT_CHARPOS (it
) == PT
)
15386 w
->force_start
= 1;
15387 /* IT may overshoot PT if text at PT is invisible. */
15388 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
15389 w
->force_start
= 1;
15394 /* Handle case where place to start displaying has been specified,
15395 unless the specified location is outside the accessible range. */
15396 if (w
->force_start
|| w
->frozen_window_start_p
)
15398 /* We set this later on if we have to adjust point. */
15401 w
->force_start
= 0;
15403 w
->window_end_valid
= 0;
15405 /* Forget any recorded base line for line number display. */
15406 if (!buffer_unchanged_p
)
15407 w
->base_line_number
= 0;
15409 /* Redisplay the mode line. Select the buffer properly for that.
15410 Also, run the hook window-scroll-functions
15411 because we have scrolled. */
15412 /* Note, we do this after clearing force_start because
15413 if there's an error, it is better to forget about force_start
15414 than to get into an infinite loop calling the hook functions
15415 and having them get more errors. */
15416 if (!update_mode_line
15417 || ! NILP (Vwindow_scroll_functions
))
15419 update_mode_line
= 1;
15420 w
->update_mode_line
= 1;
15421 startp
= run_window_scroll_functions (window
, startp
);
15424 w
->last_modified
= 0;
15425 w
->last_overlay_modified
= 0;
15426 if (CHARPOS (startp
) < BEGV
)
15427 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
15428 else if (CHARPOS (startp
) > ZV
)
15429 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
15431 /* Redisplay, then check if cursor has been set during the
15432 redisplay. Give up if new fonts were loaded. */
15433 /* We used to issue a CHECK_MARGINS argument to try_window here,
15434 but this causes scrolling to fail when point begins inside
15435 the scroll margin (bug#148) -- cyd */
15436 if (!try_window (window
, startp
, 0))
15438 w
->force_start
= 1;
15439 clear_glyph_matrix (w
->desired_matrix
);
15440 goto need_larger_matrices
;
15443 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
15445 /* If point does not appear, try to move point so it does
15446 appear. The desired matrix has been built above, so we
15447 can use it here. */
15448 new_vpos
= window_box_height (w
) / 2;
15451 if (!cursor_row_fully_visible_p (w
, 0, 0))
15453 /* Point does appear, but on a line partly visible at end of window.
15454 Move it back to a fully-visible line. */
15455 new_vpos
= window_box_height (w
);
15457 else if (w
->cursor
.vpos
>=0)
15459 /* Some people insist on not letting point enter the scroll
15460 margin, even though this part handles windows that didn't
15462 int margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
15463 int pixel_margin
= margin
* FRAME_LINE_HEIGHT (f
);
15464 bool header_line
= WINDOW_WANTS_HEADER_LINE_P (w
);
15466 /* Note: We add an extra FRAME_LINE_HEIGHT, because the loop
15467 below, which finds the row to move point to, advances by
15468 the Y coordinate of the _next_ row, see the definition of
15469 MATRIX_ROW_BOTTOM_Y. */
15470 if (w
->cursor
.vpos
< margin
+ header_line
)
15472 = pixel_margin
+ (header_line
15473 ? CURRENT_HEADER_LINE_HEIGHT (w
)
15474 : 0) + FRAME_LINE_HEIGHT (f
);
15477 int window_height
= window_box_height (w
);
15480 window_height
+= CURRENT_HEADER_LINE_HEIGHT (w
);
15481 if (w
->cursor
.y
>= window_height
- pixel_margin
)
15482 new_vpos
= window_height
- pixel_margin
;
15486 /* If we need to move point for either of the above reasons,
15487 now actually do it. */
15490 struct glyph_row
*row
;
15492 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
15493 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
15496 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
15497 MATRIX_ROW_START_BYTEPOS (row
));
15499 if (w
!= XWINDOW (selected_window
))
15500 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
15501 else if (current_buffer
== old
)
15502 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15504 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
15506 /* If we are highlighting the region, then we just changed
15507 the region, so redisplay to show it. */
15508 if (0 <= markpos_of_region ())
15510 clear_glyph_matrix (w
->desired_matrix
);
15511 if (!try_window (window
, startp
, 0))
15512 goto need_larger_matrices
;
15517 debug_method_add (w
, "forced window start");
15522 /* Handle case where text has not changed, only point, and it has
15523 not moved off the frame, and we are not retrying after hscroll.
15524 (current_matrix_up_to_date_p is nonzero when retrying.) */
15525 if (current_matrix_up_to_date_p
15526 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
15527 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
15531 case CURSOR_MOVEMENT_SUCCESS
:
15532 used_current_matrix_p
= 1;
15535 case CURSOR_MOVEMENT_MUST_SCROLL
:
15536 goto try_to_scroll
;
15542 /* If current starting point was originally the beginning of a line
15543 but no longer is, find a new starting point. */
15544 else if (w
->start_at_line_beg
15545 && !(CHARPOS (startp
) <= BEGV
15546 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
15549 debug_method_add (w
, "recenter 1");
15554 /* Try scrolling with try_window_id. Value is > 0 if update has
15555 been done, it is -1 if we know that the same window start will
15556 not work. It is 0 if unsuccessful for some other reason. */
15557 else if ((tem
= try_window_id (w
)) != 0)
15560 debug_method_add (w
, "try_window_id %d", tem
);
15563 if (fonts_changed_p
)
15564 goto need_larger_matrices
;
15568 /* Otherwise try_window_id has returned -1 which means that we
15569 don't want the alternative below this comment to execute. */
15571 else if (CHARPOS (startp
) >= BEGV
15572 && CHARPOS (startp
) <= ZV
15573 && PT
>= CHARPOS (startp
)
15574 && (CHARPOS (startp
) < ZV
15575 /* Avoid starting at end of buffer. */
15576 || CHARPOS (startp
) == BEGV
15577 || !window_outdated (w
)))
15579 int d1
, d2
, d3
, d4
, d5
, d6
;
15581 /* If first window line is a continuation line, and window start
15582 is inside the modified region, but the first change is before
15583 current window start, we must select a new window start.
15585 However, if this is the result of a down-mouse event (e.g. by
15586 extending the mouse-drag-overlay), we don't want to select a
15587 new window start, since that would change the position under
15588 the mouse, resulting in an unwanted mouse-movement rather
15589 than a simple mouse-click. */
15590 if (!w
->start_at_line_beg
15591 && NILP (do_mouse_tracking
)
15592 && CHARPOS (startp
) > BEGV
15593 && CHARPOS (startp
) > BEG
+ beg_unchanged
15594 && CHARPOS (startp
) <= Z
- end_unchanged
15595 /* Even if w->start_at_line_beg is nil, a new window may
15596 start at a line_beg, since that's how set_buffer_window
15597 sets it. So, we need to check the return value of
15598 compute_window_start_on_continuation_line. (See also
15600 && XMARKER (w
->start
)->buffer
== current_buffer
15601 && compute_window_start_on_continuation_line (w
)
15602 /* It doesn't make sense to force the window start like we
15603 do at label force_start if it is already known that point
15604 will not be visible in the resulting window, because
15605 doing so will move point from its correct position
15606 instead of scrolling the window to bring point into view.
15608 && pos_visible_p (w
, PT
, &d1
, &d2
, &d3
, &d4
, &d5
, &d6
))
15610 w
->force_start
= 1;
15611 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15616 debug_method_add (w
, "same window start");
15619 /* Try to redisplay starting at same place as before.
15620 If point has not moved off frame, accept the results. */
15621 if (!current_matrix_up_to_date_p
15622 /* Don't use try_window_reusing_current_matrix in this case
15623 because a window scroll function can have changed the
15625 || !NILP (Vwindow_scroll_functions
)
15626 || MINI_WINDOW_P (w
)
15627 || !(used_current_matrix_p
15628 = try_window_reusing_current_matrix (w
)))
15630 IF_DEBUG (debug_method_add (w
, "1"));
15631 if (try_window (window
, startp
, TRY_WINDOW_CHECK_MARGINS
) < 0)
15632 /* -1 means we need to scroll.
15633 0 means we need new matrices, but fonts_changed_p
15634 is set in that case, so we will detect it below. */
15635 goto try_to_scroll
;
15638 if (fonts_changed_p
)
15639 goto need_larger_matrices
;
15641 if (w
->cursor
.vpos
>= 0)
15643 if (!just_this_one_p
15644 || current_buffer
->clip_changed
15645 || BEG_UNCHANGED
< CHARPOS (startp
))
15646 /* Forget any recorded base line for line number display. */
15647 w
->base_line_number
= 0;
15649 if (!cursor_row_fully_visible_p (w
, 1, 0))
15651 clear_glyph_matrix (w
->desired_matrix
);
15652 last_line_misfit
= 1;
15654 /* Drop through and scroll. */
15659 clear_glyph_matrix (w
->desired_matrix
);
15664 w
->last_modified
= 0;
15665 w
->last_overlay_modified
= 0;
15667 /* Redisplay the mode line. Select the buffer properly for that. */
15668 if (!update_mode_line
)
15670 update_mode_line
= 1;
15671 w
->update_mode_line
= 1;
15674 /* Try to scroll by specified few lines. */
15675 if ((scroll_conservatively
15676 || emacs_scroll_step
15677 || temp_scroll_step
15678 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
))
15679 || NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
)))
15680 && CHARPOS (startp
) >= BEGV
15681 && CHARPOS (startp
) <= ZV
)
15683 /* The function returns -1 if new fonts were loaded, 1 if
15684 successful, 0 if not successful. */
15685 int ss
= try_scrolling (window
, just_this_one_p
,
15686 scroll_conservatively
,
15688 temp_scroll_step
, last_line_misfit
);
15691 case SCROLLING_SUCCESS
:
15694 case SCROLLING_NEED_LARGER_MATRICES
:
15695 goto need_larger_matrices
;
15697 case SCROLLING_FAILED
:
15705 /* Finally, just choose a place to start which positions point
15706 according to user preferences. */
15711 debug_method_add (w
, "recenter");
15714 /* Forget any previously recorded base line for line number display. */
15715 if (!buffer_unchanged_p
)
15716 w
->base_line_number
= 0;
15718 /* Determine the window start relative to point. */
15719 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
15720 it
.current_y
= it
.last_visible_y
;
15721 if (centering_position
< 0)
15725 ? min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
15727 ptrdiff_t margin_pos
= CHARPOS (startp
);
15728 Lisp_Object aggressive
;
15731 /* If there is a scroll margin at the top of the window, find
15732 its character position. */
15734 /* Cannot call start_display if startp is not in the
15735 accessible region of the buffer. This can happen when we
15736 have just switched to a different buffer and/or changed
15737 its restriction. In that case, startp is initialized to
15738 the character position 1 (BEGV) because we did not yet
15739 have chance to display the buffer even once. */
15740 && BEGV
<= CHARPOS (startp
) && CHARPOS (startp
) <= ZV
)
15743 void *it1data
= NULL
;
15745 SAVE_IT (it1
, it
, it1data
);
15746 start_display (&it1
, w
, startp
);
15747 move_it_vertically (&it1
, margin
* FRAME_LINE_HEIGHT (f
));
15748 margin_pos
= IT_CHARPOS (it1
);
15749 RESTORE_IT (&it
, &it
, it1data
);
15751 scrolling_up
= PT
> margin_pos
;
15754 ? BVAR (current_buffer
, scroll_up_aggressively
)
15755 : BVAR (current_buffer
, scroll_down_aggressively
);
15757 if (!MINI_WINDOW_P (w
)
15758 && (scroll_conservatively
> SCROLL_LIMIT
|| NUMBERP (aggressive
)))
15762 /* Setting scroll-conservatively overrides
15763 scroll-*-aggressively. */
15764 if (!scroll_conservatively
&& NUMBERP (aggressive
))
15766 double float_amount
= XFLOATINT (aggressive
);
15768 pt_offset
= float_amount
* WINDOW_BOX_TEXT_HEIGHT (w
);
15769 if (pt_offset
== 0 && float_amount
> 0)
15771 if (pt_offset
&& margin
> 0)
15774 /* Compute how much to move the window start backward from
15775 point so that point will be displayed where the user
15779 centering_position
= it
.last_visible_y
;
15781 centering_position
-= pt_offset
;
15782 centering_position
-=
15783 FRAME_LINE_HEIGHT (f
) * (1 + margin
+ (last_line_misfit
!= 0))
15784 + WINDOW_HEADER_LINE_HEIGHT (w
);
15785 /* Don't let point enter the scroll margin near top of
15787 if (centering_position
< margin
* FRAME_LINE_HEIGHT (f
))
15788 centering_position
= margin
* FRAME_LINE_HEIGHT (f
);
15791 centering_position
= margin
* FRAME_LINE_HEIGHT (f
) + pt_offset
;
15794 /* Set the window start half the height of the window backward
15796 centering_position
= window_box_height (w
) / 2;
15798 move_it_vertically_backward (&it
, centering_position
);
15800 eassert (IT_CHARPOS (it
) >= BEGV
);
15802 /* The function move_it_vertically_backward may move over more
15803 than the specified y-distance. If it->w is small, e.g. a
15804 mini-buffer window, we may end up in front of the window's
15805 display area. Start displaying at the start of the line
15806 containing PT in this case. */
15807 if (it
.current_y
<= 0)
15809 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
15810 move_it_vertically_backward (&it
, 0);
15814 it
.current_x
= it
.hpos
= 0;
15816 /* Set the window start position here explicitly, to avoid an
15817 infinite loop in case the functions in window-scroll-functions
15819 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
15821 /* Run scroll hooks. */
15822 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
15824 /* Redisplay the window. */
15825 if (!current_matrix_up_to_date_p
15826 || windows_or_buffers_changed
15827 || cursor_type_changed
15828 /* Don't use try_window_reusing_current_matrix in this case
15829 because it can have changed the buffer. */
15830 || !NILP (Vwindow_scroll_functions
)
15831 || !just_this_one_p
15832 || MINI_WINDOW_P (w
)
15833 || !(used_current_matrix_p
15834 = try_window_reusing_current_matrix (w
)))
15835 try_window (window
, startp
, 0);
15837 /* If new fonts have been loaded (due to fontsets), give up. We
15838 have to start a new redisplay since we need to re-adjust glyph
15840 if (fonts_changed_p
)
15841 goto need_larger_matrices
;
15843 /* If cursor did not appear assume that the middle of the window is
15844 in the first line of the window. Do it again with the next line.
15845 (Imagine a window of height 100, displaying two lines of height
15846 60. Moving back 50 from it->last_visible_y will end in the first
15848 if (w
->cursor
.vpos
< 0)
15850 if (w
->window_end_valid
&& PT
>= Z
- XFASTINT (w
->window_end_pos
))
15852 clear_glyph_matrix (w
->desired_matrix
);
15853 move_it_by_lines (&it
, 1);
15854 try_window (window
, it
.current
.pos
, 0);
15856 else if (PT
< IT_CHARPOS (it
))
15858 clear_glyph_matrix (w
->desired_matrix
);
15859 move_it_by_lines (&it
, -1);
15860 try_window (window
, it
.current
.pos
, 0);
15864 /* Not much we can do about it. */
15868 /* Consider the following case: Window starts at BEGV, there is
15869 invisible, intangible text at BEGV, so that display starts at
15870 some point START > BEGV. It can happen that we are called with
15871 PT somewhere between BEGV and START. Try to handle that case. */
15872 if (w
->cursor
.vpos
< 0)
15874 struct glyph_row
*row
= w
->current_matrix
->rows
;
15875 if (row
->mode_line_p
)
15877 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15880 if (!cursor_row_fully_visible_p (w
, 0, 0))
15882 /* If vscroll is enabled, disable it and try again. */
15886 clear_glyph_matrix (w
->desired_matrix
);
15890 /* Users who set scroll-conservatively to a large number want
15891 point just above/below the scroll margin. If we ended up
15892 with point's row partially visible, move the window start to
15893 make that row fully visible and out of the margin. */
15894 if (scroll_conservatively
> SCROLL_LIMIT
)
15898 ? min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
15900 int move_down
= w
->cursor
.vpos
>= WINDOW_TOTAL_LINES (w
) / 2;
15902 move_it_by_lines (&it
, move_down
? margin
+ 1 : -(margin
+ 1));
15903 clear_glyph_matrix (w
->desired_matrix
);
15904 if (1 == try_window (window
, it
.current
.pos
,
15905 TRY_WINDOW_CHECK_MARGINS
))
15909 /* If centering point failed to make the whole line visible,
15910 put point at the top instead. That has to make the whole line
15911 visible, if it can be done. */
15912 if (centering_position
== 0)
15915 clear_glyph_matrix (w
->desired_matrix
);
15916 centering_position
= 0;
15922 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15923 w
->start_at_line_beg
= (CHARPOS (startp
) == BEGV
15924 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n');
15926 /* Display the mode line, if we must. */
15927 if ((update_mode_line
15928 /* If window not full width, must redo its mode line
15929 if (a) the window to its side is being redone and
15930 (b) we do a frame-based redisplay. This is a consequence
15931 of how inverted lines are drawn in frame-based redisplay. */
15932 || (!just_this_one_p
15933 && !FRAME_WINDOW_P (f
)
15934 && !WINDOW_FULL_WIDTH_P (w
))
15935 /* Line number to display. */
15936 || w
->base_line_pos
> 0
15937 /* Column number is displayed and different from the one displayed. */
15938 || (w
->column_number_displayed
!= -1
15939 && (w
->column_number_displayed
!= current_column ())))
15940 /* This means that the window has a mode line. */
15941 && (WINDOW_WANTS_MODELINE_P (w
)
15942 || WINDOW_WANTS_HEADER_LINE_P (w
)))
15944 display_mode_lines (w
);
15946 /* If mode line height has changed, arrange for a thorough
15947 immediate redisplay using the correct mode line height. */
15948 if (WINDOW_WANTS_MODELINE_P (w
)
15949 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
15951 fonts_changed_p
= 1;
15952 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
15953 = DESIRED_MODE_LINE_HEIGHT (w
);
15956 /* If header line height has changed, arrange for a thorough
15957 immediate redisplay using the correct header line height. */
15958 if (WINDOW_WANTS_HEADER_LINE_P (w
)
15959 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
15961 fonts_changed_p
= 1;
15962 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
15963 = DESIRED_HEADER_LINE_HEIGHT (w
);
15966 if (fonts_changed_p
)
15967 goto need_larger_matrices
;
15970 if (!line_number_displayed
&& w
->base_line_pos
!= -1)
15972 w
->base_line_pos
= 0;
15973 w
->base_line_number
= 0;
15978 /* When we reach a frame's selected window, redo the frame's menu bar. */
15979 if (update_mode_line
15980 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
15982 int redisplay_menu_p
= 0;
15984 if (FRAME_WINDOW_P (f
))
15986 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
15987 || defined (HAVE_NS) || defined (USE_GTK)
15988 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
15990 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
15994 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
15996 if (redisplay_menu_p
)
15997 display_menu_bar (w
);
15999 #ifdef HAVE_WINDOW_SYSTEM
16000 if (FRAME_WINDOW_P (f
))
16002 #if defined (USE_GTK) || defined (HAVE_NS)
16003 if (FRAME_EXTERNAL_TOOL_BAR (f
))
16004 redisplay_tool_bar (f
);
16006 if (WINDOWP (f
->tool_bar_window
)
16007 && (FRAME_TOOL_BAR_LINES (f
) > 0
16008 || !NILP (Vauto_resize_tool_bars
))
16009 && redisplay_tool_bar (f
))
16010 ignore_mouse_drag_p
= 1;
16016 #ifdef HAVE_WINDOW_SYSTEM
16017 if (FRAME_WINDOW_P (f
)
16018 && update_window_fringes (w
, (just_this_one_p
16019 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
16020 || w
->pseudo_window_p
)))
16024 if (draw_window_fringes (w
, 1))
16025 x_draw_vertical_border (w
);
16029 #endif /* HAVE_WINDOW_SYSTEM */
16031 /* We go to this label, with fonts_changed_p set,
16032 if it is necessary to try again using larger glyph matrices.
16033 We have to redeem the scroll bar even in this case,
16034 because the loop in redisplay_internal expects that. */
16035 need_larger_matrices
:
16037 finish_scroll_bars
:
16039 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
16041 /* Set the thumb's position and size. */
16042 set_vertical_scroll_bar (w
);
16044 /* Note that we actually used the scroll bar attached to this
16045 window, so it shouldn't be deleted at the end of redisplay. */
16046 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
16047 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
16050 /* Restore current_buffer and value of point in it. The window
16051 update may have changed the buffer, so first make sure `opoint'
16052 is still valid (Bug#6177). */
16053 if (CHARPOS (opoint
) < BEGV
)
16054 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
16055 else if (CHARPOS (opoint
) > ZV
)
16056 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
16058 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
16060 set_buffer_internal_1 (old
);
16061 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
16062 shorter. This can be caused by log truncation in *Messages*. */
16063 if (CHARPOS (lpoint
) <= ZV
)
16064 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
16066 unbind_to (count
, Qnil
);
16070 /* Build the complete desired matrix of WINDOW with a window start
16071 buffer position POS.
16073 Value is 1 if successful. It is zero if fonts were loaded during
16074 redisplay which makes re-adjusting glyph matrices necessary, and -1
16075 if point would appear in the scroll margins.
16076 (We check the former only if TRY_WINDOW_IGNORE_FONTS_CHANGE is
16077 unset in FLAGS, and the latter only if TRY_WINDOW_CHECK_MARGINS is
16081 try_window (Lisp_Object window
, struct text_pos pos
, int flags
)
16083 struct window
*w
= XWINDOW (window
);
16085 struct glyph_row
*last_text_row
= NULL
;
16086 struct frame
*f
= XFRAME (w
->frame
);
16088 /* Make POS the new window start. */
16089 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
16091 /* Mark cursor position as unknown. No overlay arrow seen. */
16092 w
->cursor
.vpos
= -1;
16093 overlay_arrow_seen
= 0;
16095 /* Initialize iterator and info to start at POS. */
16096 start_display (&it
, w
, pos
);
16098 /* Display all lines of W. */
16099 while (it
.current_y
< it
.last_visible_y
)
16101 if (display_line (&it
))
16102 last_text_row
= it
.glyph_row
- 1;
16103 if (fonts_changed_p
&& !(flags
& TRY_WINDOW_IGNORE_FONTS_CHANGE
))
16107 /* Don't let the cursor end in the scroll margins. */
16108 if ((flags
& TRY_WINDOW_CHECK_MARGINS
)
16109 && !MINI_WINDOW_P (w
))
16111 int this_scroll_margin
;
16113 if (scroll_margin
> 0)
16115 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
16116 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
16119 this_scroll_margin
= 0;
16121 if ((w
->cursor
.y
>= 0 /* not vscrolled */
16122 && w
->cursor
.y
< this_scroll_margin
16123 && CHARPOS (pos
) > BEGV
16124 && IT_CHARPOS (it
) < ZV
)
16125 /* rms: considering make_cursor_line_fully_visible_p here
16126 seems to give wrong results. We don't want to recenter
16127 when the last line is partly visible, we want to allow
16128 that case to be handled in the usual way. */
16129 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
16131 w
->cursor
.vpos
= -1;
16132 clear_glyph_matrix (w
->desired_matrix
);
16137 /* If bottom moved off end of frame, change mode line percentage. */
16138 if (XFASTINT (w
->window_end_pos
) <= 0
16139 && Z
!= IT_CHARPOS (it
))
16140 w
->update_mode_line
= 1;
16142 /* Set window_end_pos to the offset of the last character displayed
16143 on the window from the end of current_buffer. Set
16144 window_end_vpos to its row number. */
16147 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
16148 w
->window_end_bytepos
16149 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16150 wset_window_end_pos
16151 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
)));
16152 wset_window_end_vpos
16153 (w
, make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
)));
16155 (MATRIX_ROW (w
->desired_matrix
,
16156 XFASTINT (w
->window_end_vpos
))->displays_text_p
);
16160 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16161 wset_window_end_pos (w
, make_number (Z
- ZV
));
16162 wset_window_end_vpos (w
, make_number (0));
16165 /* But that is not valid info until redisplay finishes. */
16166 w
->window_end_valid
= 0;
16172 /************************************************************************
16173 Window redisplay reusing current matrix when buffer has not changed
16174 ************************************************************************/
16176 /* Try redisplay of window W showing an unchanged buffer with a
16177 different window start than the last time it was displayed by
16178 reusing its current matrix. Value is non-zero if successful.
16179 W->start is the new window start. */
16182 try_window_reusing_current_matrix (struct window
*w
)
16184 struct frame
*f
= XFRAME (w
->frame
);
16185 struct glyph_row
*bottom_row
;
16188 struct text_pos start
, new_start
;
16189 int nrows_scrolled
, i
;
16190 struct glyph_row
*last_text_row
;
16191 struct glyph_row
*last_reused_text_row
;
16192 struct glyph_row
*start_row
;
16193 int start_vpos
, min_y
, max_y
;
16196 if (inhibit_try_window_reusing
)
16200 if (/* This function doesn't handle terminal frames. */
16201 !FRAME_WINDOW_P (f
)
16202 /* Don't try to reuse the display if windows have been split
16204 || windows_or_buffers_changed
16205 || cursor_type_changed
)
16208 /* Can't do this if region may have changed. */
16209 if (0 <= markpos_of_region ()
16210 || w
->region_showing
16211 || !NILP (Vshow_trailing_whitespace
))
16214 /* If top-line visibility has changed, give up. */
16215 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16216 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
16219 /* Give up if old or new display is scrolled vertically. We could
16220 make this function handle this, but right now it doesn't. */
16221 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16222 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
16225 /* The variable new_start now holds the new window start. The old
16226 start `start' can be determined from the current matrix. */
16227 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
16228 start
= start_row
->minpos
;
16229 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16231 /* Clear the desired matrix for the display below. */
16232 clear_glyph_matrix (w
->desired_matrix
);
16234 if (CHARPOS (new_start
) <= CHARPOS (start
))
16236 /* Don't use this method if the display starts with an ellipsis
16237 displayed for invisible text. It's not easy to handle that case
16238 below, and it's certainly not worth the effort since this is
16239 not a frequent case. */
16240 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
16243 IF_DEBUG (debug_method_add (w
, "twu1"));
16245 /* Display up to a row that can be reused. The variable
16246 last_text_row is set to the last row displayed that displays
16247 text. Note that it.vpos == 0 if or if not there is a
16248 header-line; it's not the same as the MATRIX_ROW_VPOS! */
16249 start_display (&it
, w
, new_start
);
16250 w
->cursor
.vpos
= -1;
16251 last_text_row
= last_reused_text_row
= NULL
;
16253 while (it
.current_y
< it
.last_visible_y
16254 && !fonts_changed_p
)
16256 /* If we have reached into the characters in the START row,
16257 that means the line boundaries have changed. So we
16258 can't start copying with the row START. Maybe it will
16259 work to start copying with the following row. */
16260 while (IT_CHARPOS (it
) > CHARPOS (start
))
16262 /* Advance to the next row as the "start". */
16264 start
= start_row
->minpos
;
16265 /* If there are no more rows to try, or just one, give up. */
16266 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
16267 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
16268 || CHARPOS (start
) == ZV
)
16270 clear_glyph_matrix (w
->desired_matrix
);
16274 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16276 /* If we have reached alignment, we can copy the rest of the
16278 if (IT_CHARPOS (it
) == CHARPOS (start
)
16279 /* Don't accept "alignment" inside a display vector,
16280 since start_row could have started in the middle of
16281 that same display vector (thus their character
16282 positions match), and we have no way of telling if
16283 that is the case. */
16284 && it
.current
.dpvec_index
< 0)
16287 if (display_line (&it
))
16288 last_text_row
= it
.glyph_row
- 1;
16292 /* A value of current_y < last_visible_y means that we stopped
16293 at the previous window start, which in turn means that we
16294 have at least one reusable row. */
16295 if (it
.current_y
< it
.last_visible_y
)
16297 struct glyph_row
*row
;
16299 /* IT.vpos always starts from 0; it counts text lines. */
16300 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
16302 /* Find PT if not already found in the lines displayed. */
16303 if (w
->cursor
.vpos
< 0)
16305 int dy
= it
.current_y
- start_row
->y
;
16307 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16308 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
16310 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
16311 dy
, nrows_scrolled
);
16314 clear_glyph_matrix (w
->desired_matrix
);
16319 /* Scroll the display. Do it before the current matrix is
16320 changed. The problem here is that update has not yet
16321 run, i.e. part of the current matrix is not up to date.
16322 scroll_run_hook will clear the cursor, and use the
16323 current matrix to get the height of the row the cursor is
16325 run
.current_y
= start_row
->y
;
16326 run
.desired_y
= it
.current_y
;
16327 run
.height
= it
.last_visible_y
- it
.current_y
;
16329 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
16332 FRAME_RIF (f
)->update_window_begin_hook (w
);
16333 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16334 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16335 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16339 /* Shift current matrix down by nrows_scrolled lines. */
16340 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16341 rotate_matrix (w
->current_matrix
,
16343 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16346 /* Disable lines that must be updated. */
16347 for (i
= 0; i
< nrows_scrolled
; ++i
)
16348 (start_row
+ i
)->enabled_p
= 0;
16350 /* Re-compute Y positions. */
16351 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16352 max_y
= it
.last_visible_y
;
16353 for (row
= start_row
+ nrows_scrolled
;
16357 row
->y
= it
.current_y
;
16358 row
->visible_height
= row
->height
;
16360 if (row
->y
< min_y
)
16361 row
->visible_height
-= min_y
- row
->y
;
16362 if (row
->y
+ row
->height
> max_y
)
16363 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16364 if (row
->fringe_bitmap_periodic_p
)
16365 row
->redraw_fringe_bitmaps_p
= 1;
16367 it
.current_y
+= row
->height
;
16369 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16370 last_reused_text_row
= row
;
16371 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
16375 /* Disable lines in the current matrix which are now
16376 below the window. */
16377 for (++row
; row
< bottom_row
; ++row
)
16378 row
->enabled_p
= row
->mode_line_p
= 0;
16381 /* Update window_end_pos etc.; last_reused_text_row is the last
16382 reused row from the current matrix containing text, if any.
16383 The value of last_text_row is the last displayed line
16384 containing text. */
16385 if (last_reused_text_row
)
16387 w
->window_end_bytepos
16388 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
16389 wset_window_end_pos
16391 - MATRIX_ROW_END_CHARPOS (last_reused_text_row
)));
16392 wset_window_end_vpos
16393 (w
, make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
16394 w
->current_matrix
)));
16396 else if (last_text_row
)
16398 w
->window_end_bytepos
16399 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16400 wset_window_end_pos
16401 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
)));
16402 wset_window_end_vpos
16403 (w
, make_number (MATRIX_ROW_VPOS (last_text_row
,
16404 w
->desired_matrix
)));
16408 /* This window must be completely empty. */
16409 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16410 wset_window_end_pos (w
, make_number (Z
- ZV
));
16411 wset_window_end_vpos (w
, make_number (0));
16413 w
->window_end_valid
= 0;
16415 /* Update hint: don't try scrolling again in update_window. */
16416 w
->desired_matrix
->no_scrolling_p
= 1;
16419 debug_method_add (w
, "try_window_reusing_current_matrix 1");
16423 else if (CHARPOS (new_start
) > CHARPOS (start
))
16425 struct glyph_row
*pt_row
, *row
;
16426 struct glyph_row
*first_reusable_row
;
16427 struct glyph_row
*first_row_to_display
;
16429 int yb
= window_text_bottom_y (w
);
16431 /* Find the row starting at new_start, if there is one. Don't
16432 reuse a partially visible line at the end. */
16433 first_reusable_row
= start_row
;
16434 while (first_reusable_row
->enabled_p
16435 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
16436 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16437 < CHARPOS (new_start
)))
16438 ++first_reusable_row
;
16440 /* Give up if there is no row to reuse. */
16441 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
16442 || !first_reusable_row
->enabled_p
16443 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16444 != CHARPOS (new_start
)))
16447 /* We can reuse fully visible rows beginning with
16448 first_reusable_row to the end of the window. Set
16449 first_row_to_display to the first row that cannot be reused.
16450 Set pt_row to the row containing point, if there is any. */
16452 for (first_row_to_display
= first_reusable_row
;
16453 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
16454 ++first_row_to_display
)
16456 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
16457 && (PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16458 || (PT
== MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16459 && first_row_to_display
->ends_at_zv_p
16460 && pt_row
== NULL
)))
16461 pt_row
= first_row_to_display
;
16464 /* Start displaying at the start of first_row_to_display. */
16465 eassert (first_row_to_display
->y
< yb
);
16466 init_to_row_start (&it
, w
, first_row_to_display
);
16468 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
16470 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
16472 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
16473 + WINDOW_HEADER_LINE_HEIGHT (w
));
16475 /* Display lines beginning with first_row_to_display in the
16476 desired matrix. Set last_text_row to the last row displayed
16477 that displays text. */
16478 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
16479 if (pt_row
== NULL
)
16480 w
->cursor
.vpos
= -1;
16481 last_text_row
= NULL
;
16482 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
16483 if (display_line (&it
))
16484 last_text_row
= it
.glyph_row
- 1;
16486 /* If point is in a reused row, adjust y and vpos of the cursor
16490 w
->cursor
.vpos
-= nrows_scrolled
;
16491 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
16494 /* Give up if point isn't in a row displayed or reused. (This
16495 also handles the case where w->cursor.vpos < nrows_scrolled
16496 after the calls to display_line, which can happen with scroll
16497 margins. See bug#1295.) */
16498 if (w
->cursor
.vpos
< 0)
16500 clear_glyph_matrix (w
->desired_matrix
);
16504 /* Scroll the display. */
16505 run
.current_y
= first_reusable_row
->y
;
16506 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16507 run
.height
= it
.last_visible_y
- run
.current_y
;
16508 dy
= run
.current_y
- run
.desired_y
;
16513 FRAME_RIF (f
)->update_window_begin_hook (w
);
16514 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16515 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16516 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16520 /* Adjust Y positions of reused rows. */
16521 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16522 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16523 max_y
= it
.last_visible_y
;
16524 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
16527 row
->visible_height
= row
->height
;
16528 if (row
->y
< min_y
)
16529 row
->visible_height
-= min_y
- row
->y
;
16530 if (row
->y
+ row
->height
> max_y
)
16531 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16532 if (row
->fringe_bitmap_periodic_p
)
16533 row
->redraw_fringe_bitmaps_p
= 1;
16536 /* Scroll the current matrix. */
16537 eassert (nrows_scrolled
> 0);
16538 rotate_matrix (w
->current_matrix
,
16540 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16543 /* Disable rows not reused. */
16544 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
16545 row
->enabled_p
= 0;
16547 /* Point may have moved to a different line, so we cannot assume that
16548 the previous cursor position is valid; locate the correct row. */
16551 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
16553 && PT
>= MATRIX_ROW_END_CHARPOS (row
)
16554 && !row
->ends_at_zv_p
;
16558 w
->cursor
.y
= row
->y
;
16560 if (row
< bottom_row
)
16562 /* Can't simply scan the row for point with
16563 bidi-reordered glyph rows. Let set_cursor_from_row
16564 figure out where to put the cursor, and if it fails,
16566 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
16568 if (!set_cursor_from_row (w
, row
, w
->current_matrix
,
16571 clear_glyph_matrix (w
->desired_matrix
);
16577 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
16578 struct glyph
*end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16581 && (!BUFFERP (glyph
->object
)
16582 || glyph
->charpos
< PT
);
16586 w
->cursor
.x
+= glyph
->pixel_width
;
16592 /* Adjust window end. A null value of last_text_row means that
16593 the window end is in reused rows which in turn means that
16594 only its vpos can have changed. */
16597 w
->window_end_bytepos
16598 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16599 wset_window_end_pos
16600 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
)));
16601 wset_window_end_vpos
16602 (w
, make_number (MATRIX_ROW_VPOS (last_text_row
,
16603 w
->desired_matrix
)));
16607 wset_window_end_vpos
16608 (w
, make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
));
16611 w
->window_end_valid
= 0;
16612 w
->desired_matrix
->no_scrolling_p
= 1;
16615 debug_method_add (w
, "try_window_reusing_current_matrix 2");
16625 /************************************************************************
16626 Window redisplay reusing current matrix when buffer has changed
16627 ************************************************************************/
16629 static struct glyph_row
*find_last_unchanged_at_beg_row (struct window
*);
16630 static struct glyph_row
*find_first_unchanged_at_end_row (struct window
*,
16631 ptrdiff_t *, ptrdiff_t *);
16632 static struct glyph_row
*
16633 find_last_row_displaying_text (struct glyph_matrix
*, struct it
*,
16634 struct glyph_row
*);
16637 /* Return the last row in MATRIX displaying text. If row START is
16638 non-null, start searching with that row. IT gives the dimensions
16639 of the display. Value is null if matrix is empty; otherwise it is
16640 a pointer to the row found. */
16642 static struct glyph_row
*
16643 find_last_row_displaying_text (struct glyph_matrix
*matrix
, struct it
*it
,
16644 struct glyph_row
*start
)
16646 struct glyph_row
*row
, *row_found
;
16648 /* Set row_found to the last row in IT->w's current matrix
16649 displaying text. The loop looks funny but think of partially
16652 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
16653 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16655 eassert (row
->enabled_p
);
16657 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
16666 /* Return the last row in the current matrix of W that is not affected
16667 by changes at the start of current_buffer that occurred since W's
16668 current matrix was built. Value is null if no such row exists.
16670 BEG_UNCHANGED us the number of characters unchanged at the start of
16671 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
16672 first changed character in current_buffer. Characters at positions <
16673 BEG + BEG_UNCHANGED are at the same buffer positions as they were
16674 when the current matrix was built. */
16676 static struct glyph_row
*
16677 find_last_unchanged_at_beg_row (struct window
*w
)
16679 ptrdiff_t first_changed_pos
= BEG
+ BEG_UNCHANGED
;
16680 struct glyph_row
*row
;
16681 struct glyph_row
*row_found
= NULL
;
16682 int yb
= window_text_bottom_y (w
);
16684 /* Find the last row displaying unchanged text. */
16685 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16686 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
16687 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
16690 if (/* If row ends before first_changed_pos, it is unchanged,
16691 except in some case. */
16692 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
16693 /* When row ends in ZV and we write at ZV it is not
16695 && !row
->ends_at_zv_p
16696 /* When first_changed_pos is the end of a continued line,
16697 row is not unchanged because it may be no longer
16699 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
16700 && (row
->continued_p
16701 || row
->exact_window_width_line_p
))
16702 /* If ROW->end is beyond ZV, then ROW->end is outdated and
16703 needs to be recomputed, so don't consider this row as
16704 unchanged. This happens when the last line was
16705 bidi-reordered and was killed immediately before this
16706 redisplay cycle. In that case, ROW->end stores the
16707 buffer position of the first visual-order character of
16708 the killed text, which is now beyond ZV. */
16709 && CHARPOS (row
->end
.pos
) <= ZV
)
16712 /* Stop if last visible row. */
16713 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
16721 /* Find the first glyph row in the current matrix of W that is not
16722 affected by changes at the end of current_buffer since the
16723 time W's current matrix was built.
16725 Return in *DELTA the number of chars by which buffer positions in
16726 unchanged text at the end of current_buffer must be adjusted.
16728 Return in *DELTA_BYTES the corresponding number of bytes.
16730 Value is null if no such row exists, i.e. all rows are affected by
16733 static struct glyph_row
*
16734 find_first_unchanged_at_end_row (struct window
*w
,
16735 ptrdiff_t *delta
, ptrdiff_t *delta_bytes
)
16737 struct glyph_row
*row
;
16738 struct glyph_row
*row_found
= NULL
;
16740 *delta
= *delta_bytes
= 0;
16742 /* Display must not have been paused, otherwise the current matrix
16743 is not up to date. */
16744 eassert (w
->window_end_valid
);
16746 /* A value of window_end_pos >= END_UNCHANGED means that the window
16747 end is in the range of changed text. If so, there is no
16748 unchanged row at the end of W's current matrix. */
16749 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
16752 /* Set row to the last row in W's current matrix displaying text. */
16753 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
16755 /* If matrix is entirely empty, no unchanged row exists. */
16756 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16758 /* The value of row is the last glyph row in the matrix having a
16759 meaningful buffer position in it. The end position of row
16760 corresponds to window_end_pos. This allows us to translate
16761 buffer positions in the current matrix to current buffer
16762 positions for characters not in changed text. */
16764 MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
16765 ptrdiff_t Z_BYTE_old
=
16766 MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
16767 ptrdiff_t last_unchanged_pos
, last_unchanged_pos_old
;
16768 struct glyph_row
*first_text_row
16769 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16771 *delta
= Z
- Z_old
;
16772 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
16774 /* Set last_unchanged_pos to the buffer position of the last
16775 character in the buffer that has not been changed. Z is the
16776 index + 1 of the last character in current_buffer, i.e. by
16777 subtracting END_UNCHANGED we get the index of the last
16778 unchanged character, and we have to add BEG to get its buffer
16780 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
16781 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
16783 /* Search backward from ROW for a row displaying a line that
16784 starts at a minimum position >= last_unchanged_pos_old. */
16785 for (; row
> first_text_row
; --row
)
16787 /* This used to abort, but it can happen.
16788 It is ok to just stop the search instead here. KFS. */
16789 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16792 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
16797 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
16803 /* Make sure that glyph rows in the current matrix of window W
16804 reference the same glyph memory as corresponding rows in the
16805 frame's frame matrix. This function is called after scrolling W's
16806 current matrix on a terminal frame in try_window_id and
16807 try_window_reusing_current_matrix. */
16810 sync_frame_with_window_matrix_rows (struct window
*w
)
16812 struct frame
*f
= XFRAME (w
->frame
);
16813 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
16815 /* Preconditions: W must be a leaf window and full-width. Its frame
16816 must have a frame matrix. */
16817 eassert (NILP (w
->hchild
) && NILP (w
->vchild
));
16818 eassert (WINDOW_FULL_WIDTH_P (w
));
16819 eassert (!FRAME_WINDOW_P (f
));
16821 /* If W is a full-width window, glyph pointers in W's current matrix
16822 have, by definition, to be the same as glyph pointers in the
16823 corresponding frame matrix. Note that frame matrices have no
16824 marginal areas (see build_frame_matrix). */
16825 window_row
= w
->current_matrix
->rows
;
16826 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
16827 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
16828 while (window_row
< window_row_end
)
16830 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
16831 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
16833 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
16834 frame_row
->glyphs
[TEXT_AREA
] = start
;
16835 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
16836 frame_row
->glyphs
[LAST_AREA
] = end
;
16838 /* Disable frame rows whose corresponding window rows have
16839 been disabled in try_window_id. */
16840 if (!window_row
->enabled_p
)
16841 frame_row
->enabled_p
= 0;
16843 ++window_row
, ++frame_row
;
16848 /* Find the glyph row in window W containing CHARPOS. Consider all
16849 rows between START and END (not inclusive). END null means search
16850 all rows to the end of the display area of W. Value is the row
16851 containing CHARPOS or null. */
16854 row_containing_pos (struct window
*w
, ptrdiff_t charpos
,
16855 struct glyph_row
*start
, struct glyph_row
*end
, int dy
)
16857 struct glyph_row
*row
= start
;
16858 struct glyph_row
*best_row
= NULL
;
16859 ptrdiff_t mindif
= BUF_ZV (XBUFFER (w
->buffer
)) + 1;
16862 /* If we happen to start on a header-line, skip that. */
16863 if (row
->mode_line_p
)
16866 if ((end
&& row
>= end
) || !row
->enabled_p
)
16869 last_y
= window_text_bottom_y (w
) - dy
;
16873 /* Give up if we have gone too far. */
16874 if (end
&& row
>= end
)
16876 /* This formerly returned if they were equal.
16877 I think that both quantities are of a "last plus one" type;
16878 if so, when they are equal, the row is within the screen. -- rms. */
16879 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
16882 /* If it is in this row, return this row. */
16883 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
16884 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
16885 /* The end position of a row equals the start
16886 position of the next row. If CHARPOS is there, we
16887 would rather display it in the next line, except
16888 when this line ends in ZV. */
16889 && !row
->ends_at_zv_p
16890 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
16891 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
16895 if (NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
16896 || (!best_row
&& !row
->continued_p
))
16898 /* In bidi-reordered rows, there could be several rows
16899 occluding point, all of them belonging to the same
16900 continued line. We need to find the row which fits
16901 CHARPOS the best. */
16902 for (g
= row
->glyphs
[TEXT_AREA
];
16903 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16906 if (!STRINGP (g
->object
))
16908 if (g
->charpos
> 0 && eabs (g
->charpos
- charpos
) < mindif
)
16910 mindif
= eabs (g
->charpos
- charpos
);
16912 /* Exact match always wins. */
16919 else if (best_row
&& !row
->continued_p
)
16926 /* Try to redisplay window W by reusing its existing display. W's
16927 current matrix must be up to date when this function is called,
16928 i.e. window_end_valid must be nonzero.
16932 1 if display has been updated
16933 0 if otherwise unsuccessful
16934 -1 if redisplay with same window start is known not to succeed
16936 The following steps are performed:
16938 1. Find the last row in the current matrix of W that is not
16939 affected by changes at the start of current_buffer. If no such row
16942 2. Find the first row in W's current matrix that is not affected by
16943 changes at the end of current_buffer. Maybe there is no such row.
16945 3. Display lines beginning with the row + 1 found in step 1 to the
16946 row found in step 2 or, if step 2 didn't find a row, to the end of
16949 4. If cursor is not known to appear on the window, give up.
16951 5. If display stopped at the row found in step 2, scroll the
16952 display and current matrix as needed.
16954 6. Maybe display some lines at the end of W, if we must. This can
16955 happen under various circumstances, like a partially visible line
16956 becoming fully visible, or because newly displayed lines are displayed
16957 in smaller font sizes.
16959 7. Update W's window end information. */
16962 try_window_id (struct window
*w
)
16964 struct frame
*f
= XFRAME (w
->frame
);
16965 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
16966 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
16967 struct glyph_row
*last_unchanged_at_beg_row
;
16968 struct glyph_row
*first_unchanged_at_end_row
;
16969 struct glyph_row
*row
;
16970 struct glyph_row
*bottom_row
;
16973 ptrdiff_t delta
= 0, delta_bytes
= 0, stop_pos
;
16975 struct text_pos start_pos
;
16977 int first_unchanged_at_end_vpos
= 0;
16978 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
16979 struct text_pos start
;
16980 ptrdiff_t first_changed_charpos
, last_changed_charpos
;
16983 if (inhibit_try_window_id
)
16987 /* This is handy for debugging. */
16989 #define GIVE_UP(X) \
16991 fprintf (stderr, "try_window_id give up %d\n", (X)); \
16995 #define GIVE_UP(X) return 0
16998 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
17000 /* Don't use this for mini-windows because these can show
17001 messages and mini-buffers, and we don't handle that here. */
17002 if (MINI_WINDOW_P (w
))
17005 /* This flag is used to prevent redisplay optimizations. */
17006 if (windows_or_buffers_changed
|| cursor_type_changed
)
17009 /* Verify that narrowing has not changed.
17010 Also verify that we were not told to prevent redisplay optimizations.
17011 It would be nice to further
17012 reduce the number of cases where this prevents try_window_id. */
17013 if (current_buffer
->clip_changed
17014 || current_buffer
->prevent_redisplay_optimizations_p
)
17017 /* Window must either use window-based redisplay or be full width. */
17018 if (!FRAME_WINDOW_P (f
)
17019 && (!FRAME_LINE_INS_DEL_OK (f
)
17020 || !WINDOW_FULL_WIDTH_P (w
)))
17023 /* Give up if point is known NOT to appear in W. */
17024 if (PT
< CHARPOS (start
))
17027 /* Another way to prevent redisplay optimizations. */
17028 if (w
->last_modified
== 0)
17031 /* Verify that window is not hscrolled. */
17032 if (w
->hscroll
!= 0)
17035 /* Verify that display wasn't paused. */
17036 if (!w
->window_end_valid
)
17039 /* Can't use this if highlighting a region because a cursor movement
17040 will do more than just set the cursor. */
17041 if (0 <= markpos_of_region ())
17044 /* Likewise if highlighting trailing whitespace. */
17045 if (!NILP (Vshow_trailing_whitespace
))
17048 /* Likewise if showing a region. */
17049 if (w
->region_showing
)
17052 /* Can't use this if overlay arrow position and/or string have
17054 if (overlay_arrows_changed_p ())
17057 /* When word-wrap is on, adding a space to the first word of a
17058 wrapped line can change the wrap position, altering the line
17059 above it. It might be worthwhile to handle this more
17060 intelligently, but for now just redisplay from scratch. */
17061 if (!NILP (BVAR (XBUFFER (w
->buffer
), word_wrap
)))
17064 /* Under bidi reordering, adding or deleting a character in the
17065 beginning of a paragraph, before the first strong directional
17066 character, can change the base direction of the paragraph (unless
17067 the buffer specifies a fixed paragraph direction), which will
17068 require to redisplay the whole paragraph. It might be worthwhile
17069 to find the paragraph limits and widen the range of redisplayed
17070 lines to that, but for now just give up this optimization and
17071 redisplay from scratch. */
17072 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
17073 && NILP (BVAR (XBUFFER (w
->buffer
), bidi_paragraph_direction
)))
17076 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
17077 only if buffer has really changed. The reason is that the gap is
17078 initially at Z for freshly visited files. The code below would
17079 set end_unchanged to 0 in that case. */
17080 if (MODIFF
> SAVE_MODIFF
17081 /* This seems to happen sometimes after saving a buffer. */
17082 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
17084 if (GPT
- BEG
< BEG_UNCHANGED
)
17085 BEG_UNCHANGED
= GPT
- BEG
;
17086 if (Z
- GPT
< END_UNCHANGED
)
17087 END_UNCHANGED
= Z
- GPT
;
17090 /* The position of the first and last character that has been changed. */
17091 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
17092 last_changed_charpos
= Z
- END_UNCHANGED
;
17094 /* If window starts after a line end, and the last change is in
17095 front of that newline, then changes don't affect the display.
17096 This case happens with stealth-fontification. Note that although
17097 the display is unchanged, glyph positions in the matrix have to
17098 be adjusted, of course. */
17099 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
17100 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
17101 && ((last_changed_charpos
< CHARPOS (start
)
17102 && CHARPOS (start
) == BEGV
)
17103 || (last_changed_charpos
< CHARPOS (start
) - 1
17104 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
17106 ptrdiff_t Z_old
, Z_delta
, Z_BYTE_old
, Z_delta_bytes
;
17107 struct glyph_row
*r0
;
17109 /* Compute how many chars/bytes have been added to or removed
17110 from the buffer. */
17111 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
17112 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
17113 Z_delta
= Z
- Z_old
;
17114 Z_delta_bytes
= Z_BYTE
- Z_BYTE_old
;
17116 /* Give up if PT is not in the window. Note that it already has
17117 been checked at the start of try_window_id that PT is not in
17118 front of the window start. */
17119 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + Z_delta
)
17122 /* If window start is unchanged, we can reuse the whole matrix
17123 as is, after adjusting glyph positions. No need to compute
17124 the window end again, since its offset from Z hasn't changed. */
17125 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17126 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + Z_delta
17127 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + Z_delta_bytes
17128 /* PT must not be in a partially visible line. */
17129 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + Z_delta
17130 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17132 /* Adjust positions in the glyph matrix. */
17133 if (Z_delta
|| Z_delta_bytes
)
17135 struct glyph_row
*r1
17136 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17137 increment_matrix_positions (w
->current_matrix
,
17138 MATRIX_ROW_VPOS (r0
, current_matrix
),
17139 MATRIX_ROW_VPOS (r1
, current_matrix
),
17140 Z_delta
, Z_delta_bytes
);
17143 /* Set the cursor. */
17144 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17146 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17153 /* Handle the case that changes are all below what is displayed in
17154 the window, and that PT is in the window. This shortcut cannot
17155 be taken if ZV is visible in the window, and text has been added
17156 there that is visible in the window. */
17157 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
17158 /* ZV is not visible in the window, or there are no
17159 changes at ZV, actually. */
17160 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
17161 || first_changed_charpos
== last_changed_charpos
))
17163 struct glyph_row
*r0
;
17165 /* Give up if PT is not in the window. Note that it already has
17166 been checked at the start of try_window_id that PT is not in
17167 front of the window start. */
17168 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
17171 /* If window start is unchanged, we can reuse the whole matrix
17172 as is, without changing glyph positions since no text has
17173 been added/removed in front of the window end. */
17174 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17175 if (TEXT_POS_EQUAL_P (start
, r0
->minpos
)
17176 /* PT must not be in a partially visible line. */
17177 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
17178 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17180 /* We have to compute the window end anew since text
17181 could have been added/removed after it. */
17182 wset_window_end_pos
17183 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (row
)));
17184 w
->window_end_bytepos
17185 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17187 /* Set the cursor. */
17188 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17190 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17197 /* Give up if window start is in the changed area.
17199 The condition used to read
17201 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
17203 but why that was tested escapes me at the moment. */
17204 if (CHARPOS (start
) >= first_changed_charpos
17205 && CHARPOS (start
) <= last_changed_charpos
)
17208 /* Check that window start agrees with the start of the first glyph
17209 row in its current matrix. Check this after we know the window
17210 start is not in changed text, otherwise positions would not be
17212 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17213 if (!TEXT_POS_EQUAL_P (start
, row
->minpos
))
17216 /* Give up if the window ends in strings. Overlay strings
17217 at the end are difficult to handle, so don't try. */
17218 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
17219 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
17222 /* Compute the position at which we have to start displaying new
17223 lines. Some of the lines at the top of the window might be
17224 reusable because they are not displaying changed text. Find the
17225 last row in W's current matrix not affected by changes at the
17226 start of current_buffer. Value is null if changes start in the
17227 first line of window. */
17228 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
17229 if (last_unchanged_at_beg_row
)
17231 /* Avoid starting to display in the middle of a character, a TAB
17232 for instance. This is easier than to set up the iterator
17233 exactly, and it's not a frequent case, so the additional
17234 effort wouldn't really pay off. */
17235 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
17236 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
17237 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
17238 --last_unchanged_at_beg_row
;
17240 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
17243 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
17245 start_pos
= it
.current
.pos
;
17247 /* Start displaying new lines in the desired matrix at the same
17248 vpos we would use in the current matrix, i.e. below
17249 last_unchanged_at_beg_row. */
17250 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
17252 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17253 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
17255 eassert (it
.hpos
== 0 && it
.current_x
== 0);
17259 /* There are no reusable lines at the start of the window.
17260 Start displaying in the first text line. */
17261 start_display (&it
, w
, start
);
17262 it
.vpos
= it
.first_vpos
;
17263 start_pos
= it
.current
.pos
;
17266 /* Find the first row that is not affected by changes at the end of
17267 the buffer. Value will be null if there is no unchanged row, in
17268 which case we must redisplay to the end of the window. delta
17269 will be set to the value by which buffer positions beginning with
17270 first_unchanged_at_end_row have to be adjusted due to text
17272 first_unchanged_at_end_row
17273 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
17274 IF_DEBUG (debug_delta
= delta
);
17275 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
17277 /* Set stop_pos to the buffer position up to which we will have to
17278 display new lines. If first_unchanged_at_end_row != NULL, this
17279 is the buffer position of the start of the line displayed in that
17280 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
17281 that we don't stop at a buffer position. */
17283 if (first_unchanged_at_end_row
)
17285 eassert (last_unchanged_at_beg_row
== NULL
17286 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
17288 /* If this is a continuation line, move forward to the next one
17289 that isn't. Changes in lines above affect this line.
17290 Caution: this may move first_unchanged_at_end_row to a row
17291 not displaying text. */
17292 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
17293 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17294 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17295 < it
.last_visible_y
))
17296 ++first_unchanged_at_end_row
;
17298 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17299 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17300 >= it
.last_visible_y
))
17301 first_unchanged_at_end_row
= NULL
;
17304 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
17306 first_unchanged_at_end_vpos
17307 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
17308 eassert (stop_pos
>= Z
- END_UNCHANGED
);
17311 else if (last_unchanged_at_beg_row
== NULL
)
17317 /* Either there is no unchanged row at the end, or the one we have
17318 now displays text. This is a necessary condition for the window
17319 end pos calculation at the end of this function. */
17320 eassert (first_unchanged_at_end_row
== NULL
17321 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
17323 debug_last_unchanged_at_beg_vpos
17324 = (last_unchanged_at_beg_row
17325 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
17327 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
17329 #endif /* GLYPH_DEBUG */
17332 /* Display new lines. Set last_text_row to the last new line
17333 displayed which has text on it, i.e. might end up as being the
17334 line where the window_end_vpos is. */
17335 w
->cursor
.vpos
= -1;
17336 last_text_row
= NULL
;
17337 overlay_arrow_seen
= 0;
17338 while (it
.current_y
< it
.last_visible_y
17339 && !fonts_changed_p
17340 && (first_unchanged_at_end_row
== NULL
17341 || IT_CHARPOS (it
) < stop_pos
))
17343 if (display_line (&it
))
17344 last_text_row
= it
.glyph_row
- 1;
17347 if (fonts_changed_p
)
17351 /* Compute differences in buffer positions, y-positions etc. for
17352 lines reused at the bottom of the window. Compute what we can
17354 if (first_unchanged_at_end_row
17355 /* No lines reused because we displayed everything up to the
17356 bottom of the window. */
17357 && it
.current_y
< it
.last_visible_y
)
17360 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
17362 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
17363 run
.current_y
= first_unchanged_at_end_row
->y
;
17364 run
.desired_y
= run
.current_y
+ dy
;
17365 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
17369 delta
= delta_bytes
= dvpos
= dy
17370 = run
.current_y
= run
.desired_y
= run
.height
= 0;
17371 first_unchanged_at_end_row
= NULL
;
17373 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
17376 /* Find the cursor if not already found. We have to decide whether
17377 PT will appear on this window (it sometimes doesn't, but this is
17378 not a very frequent case.) This decision has to be made before
17379 the current matrix is altered. A value of cursor.vpos < 0 means
17380 that PT is either in one of the lines beginning at
17381 first_unchanged_at_end_row or below the window. Don't care for
17382 lines that might be displayed later at the window end; as
17383 mentioned, this is not a frequent case. */
17384 if (w
->cursor
.vpos
< 0)
17386 /* Cursor in unchanged rows at the top? */
17387 if (PT
< CHARPOS (start_pos
)
17388 && last_unchanged_at_beg_row
)
17390 row
= row_containing_pos (w
, PT
,
17391 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
17392 last_unchanged_at_beg_row
+ 1, 0);
17394 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
17397 /* Start from first_unchanged_at_end_row looking for PT. */
17398 else if (first_unchanged_at_end_row
)
17400 row
= row_containing_pos (w
, PT
- delta
,
17401 first_unchanged_at_end_row
, NULL
, 0);
17403 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
17404 delta_bytes
, dy
, dvpos
);
17407 /* Give up if cursor was not found. */
17408 if (w
->cursor
.vpos
< 0)
17410 clear_glyph_matrix (w
->desired_matrix
);
17415 /* Don't let the cursor end in the scroll margins. */
17417 int this_scroll_margin
, cursor_height
;
17419 this_scroll_margin
=
17420 max (0, min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4));
17421 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
17422 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
17424 if ((w
->cursor
.y
< this_scroll_margin
17425 && CHARPOS (start
) > BEGV
)
17426 /* Old redisplay didn't take scroll margin into account at the bottom,
17427 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
17428 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
17429 ? cursor_height
+ this_scroll_margin
17430 : 1)) > it
.last_visible_y
)
17432 w
->cursor
.vpos
= -1;
17433 clear_glyph_matrix (w
->desired_matrix
);
17438 /* Scroll the display. Do it before changing the current matrix so
17439 that xterm.c doesn't get confused about where the cursor glyph is
17441 if (dy
&& run
.height
)
17445 if (FRAME_WINDOW_P (f
))
17447 FRAME_RIF (f
)->update_window_begin_hook (w
);
17448 FRAME_RIF (f
)->clear_window_mouse_face (w
);
17449 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
17450 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
17454 /* Terminal frame. In this case, dvpos gives the number of
17455 lines to scroll by; dvpos < 0 means scroll up. */
17457 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
17458 int from
= WINDOW_TOP_EDGE_LINE (w
) + from_vpos
;
17459 int end
= (WINDOW_TOP_EDGE_LINE (w
)
17460 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
17461 + window_internal_height (w
));
17463 #if defined (HAVE_GPM) || defined (MSDOS)
17464 x_clear_window_mouse_face (w
);
17466 /* Perform the operation on the screen. */
17469 /* Scroll last_unchanged_at_beg_row to the end of the
17470 window down dvpos lines. */
17471 set_terminal_window (f
, end
);
17473 /* On dumb terminals delete dvpos lines at the end
17474 before inserting dvpos empty lines. */
17475 if (!FRAME_SCROLL_REGION_OK (f
))
17476 ins_del_lines (f
, end
- dvpos
, -dvpos
);
17478 /* Insert dvpos empty lines in front of
17479 last_unchanged_at_beg_row. */
17480 ins_del_lines (f
, from
, dvpos
);
17482 else if (dvpos
< 0)
17484 /* Scroll up last_unchanged_at_beg_vpos to the end of
17485 the window to last_unchanged_at_beg_vpos - |dvpos|. */
17486 set_terminal_window (f
, end
);
17488 /* Delete dvpos lines in front of
17489 last_unchanged_at_beg_vpos. ins_del_lines will set
17490 the cursor to the given vpos and emit |dvpos| delete
17492 ins_del_lines (f
, from
+ dvpos
, dvpos
);
17494 /* On a dumb terminal insert dvpos empty lines at the
17496 if (!FRAME_SCROLL_REGION_OK (f
))
17497 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
17500 set_terminal_window (f
, 0);
17506 /* Shift reused rows of the current matrix to the right position.
17507 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
17509 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17510 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
17513 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
17514 bottom_vpos
, dvpos
);
17515 clear_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
17518 else if (dvpos
> 0)
17520 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
17521 bottom_vpos
, dvpos
);
17522 clear_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
17523 first_unchanged_at_end_vpos
+ dvpos
);
17526 /* For frame-based redisplay, make sure that current frame and window
17527 matrix are in sync with respect to glyph memory. */
17528 if (!FRAME_WINDOW_P (f
))
17529 sync_frame_with_window_matrix_rows (w
);
17531 /* Adjust buffer positions in reused rows. */
17532 if (delta
|| delta_bytes
)
17533 increment_matrix_positions (current_matrix
,
17534 first_unchanged_at_end_vpos
+ dvpos
,
17535 bottom_vpos
, delta
, delta_bytes
);
17537 /* Adjust Y positions. */
17539 shift_glyph_matrix (w
, current_matrix
,
17540 first_unchanged_at_end_vpos
+ dvpos
,
17543 if (first_unchanged_at_end_row
)
17545 first_unchanged_at_end_row
+= dvpos
;
17546 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
17547 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
17548 first_unchanged_at_end_row
= NULL
;
17551 /* If scrolling up, there may be some lines to display at the end of
17553 last_text_row_at_end
= NULL
;
17556 /* Scrolling up can leave for example a partially visible line
17557 at the end of the window to be redisplayed. */
17558 /* Set last_row to the glyph row in the current matrix where the
17559 window end line is found. It has been moved up or down in
17560 the matrix by dvpos. */
17561 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
17562 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
17564 /* If last_row is the window end line, it should display text. */
17565 eassert (last_row
->displays_text_p
);
17567 /* If window end line was partially visible before, begin
17568 displaying at that line. Otherwise begin displaying with the
17569 line following it. */
17570 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
17572 init_to_row_start (&it
, w
, last_row
);
17573 it
.vpos
= last_vpos
;
17574 it
.current_y
= last_row
->y
;
17578 init_to_row_end (&it
, w
, last_row
);
17579 it
.vpos
= 1 + last_vpos
;
17580 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
17584 /* We may start in a continuation line. If so, we have to
17585 get the right continuation_lines_width and current_x. */
17586 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
17587 it
.hpos
= it
.current_x
= 0;
17589 /* Display the rest of the lines at the window end. */
17590 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17591 while (it
.current_y
< it
.last_visible_y
17592 && !fonts_changed_p
)
17594 /* Is it always sure that the display agrees with lines in
17595 the current matrix? I don't think so, so we mark rows
17596 displayed invalid in the current matrix by setting their
17597 enabled_p flag to zero. */
17598 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
17599 if (display_line (&it
))
17600 last_text_row_at_end
= it
.glyph_row
- 1;
17604 /* Update window_end_pos and window_end_vpos. */
17605 if (first_unchanged_at_end_row
17606 && !last_text_row_at_end
)
17608 /* Window end line if one of the preserved rows from the current
17609 matrix. Set row to the last row displaying text in current
17610 matrix starting at first_unchanged_at_end_row, after
17612 eassert (first_unchanged_at_end_row
->displays_text_p
);
17613 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
17614 first_unchanged_at_end_row
);
17615 eassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
17617 wset_window_end_pos (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (row
)));
17618 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17619 wset_window_end_vpos
17620 (w
, make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
)));
17621 eassert (w
->window_end_bytepos
>= 0);
17622 IF_DEBUG (debug_method_add (w
, "A"));
17624 else if (last_text_row_at_end
)
17626 wset_window_end_pos
17627 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
)));
17628 w
->window_end_bytepos
17629 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
17630 wset_window_end_vpos
17631 (w
, make_number (MATRIX_ROW_VPOS (last_text_row_at_end
,
17633 eassert (w
->window_end_bytepos
>= 0);
17634 IF_DEBUG (debug_method_add (w
, "B"));
17636 else if (last_text_row
)
17638 /* We have displayed either to the end of the window or at the
17639 end of the window, i.e. the last row with text is to be found
17640 in the desired matrix. */
17641 wset_window_end_pos
17642 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
)));
17643 w
->window_end_bytepos
17644 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
17645 wset_window_end_vpos
17646 (w
, make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
)));
17647 eassert (w
->window_end_bytepos
>= 0);
17649 else if (first_unchanged_at_end_row
== NULL
17650 && last_text_row
== NULL
17651 && last_text_row_at_end
== NULL
)
17653 /* Displayed to end of window, but no line containing text was
17654 displayed. Lines were deleted at the end of the window. */
17655 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
17656 int vpos
= XFASTINT (w
->window_end_vpos
);
17657 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
17658 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
17661 row
== NULL
&& vpos
>= first_vpos
;
17662 --vpos
, --current_row
, --desired_row
)
17664 if (desired_row
->enabled_p
)
17666 if (desired_row
->displays_text_p
)
17669 else if (current_row
->displays_text_p
)
17673 eassert (row
!= NULL
);
17674 wset_window_end_vpos (w
, make_number (vpos
+ 1));
17675 wset_window_end_pos (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (row
)));
17676 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17677 eassert (w
->window_end_bytepos
>= 0);
17678 IF_DEBUG (debug_method_add (w
, "C"));
17683 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
17684 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
17686 /* Record that display has not been completed. */
17687 w
->window_end_valid
= 0;
17688 w
->desired_matrix
->no_scrolling_p
= 1;
17696 /***********************************************************************
17697 More debugging support
17698 ***********************************************************************/
17702 void dump_glyph_row (struct glyph_row
*, int, int) EXTERNALLY_VISIBLE
;
17703 void dump_glyph_matrix (struct glyph_matrix
*, int) EXTERNALLY_VISIBLE
;
17704 void dump_glyph (struct glyph_row
*, struct glyph
*, int) EXTERNALLY_VISIBLE
;
17707 /* Dump the contents of glyph matrix MATRIX on stderr.
17709 GLYPHS 0 means don't show glyph contents.
17710 GLYPHS 1 means show glyphs in short form
17711 GLYPHS > 1 means show glyphs in long form. */
17714 dump_glyph_matrix (struct glyph_matrix
*matrix
, int glyphs
)
17717 for (i
= 0; i
< matrix
->nrows
; ++i
)
17718 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
17722 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
17723 the glyph row and area where the glyph comes from. */
17726 dump_glyph (struct glyph_row
*row
, struct glyph
*glyph
, int area
)
17728 if (glyph
->type
== CHAR_GLYPH
17729 || glyph
->type
== GLYPHLESS_GLYPH
)
17732 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
17733 glyph
- row
->glyphs
[TEXT_AREA
],
17734 (glyph
->type
== CHAR_GLYPH
17738 (BUFFERP (glyph
->object
)
17740 : (STRINGP (glyph
->object
)
17742 : (INTEGERP (glyph
->object
)
17745 glyph
->pixel_width
,
17747 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
17751 glyph
->left_box_line_p
,
17752 glyph
->right_box_line_p
);
17754 else if (glyph
->type
== STRETCH_GLYPH
)
17757 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
17758 glyph
- row
->glyphs
[TEXT_AREA
],
17761 (BUFFERP (glyph
->object
)
17763 : (STRINGP (glyph
->object
)
17765 : (INTEGERP (glyph
->object
)
17768 glyph
->pixel_width
,
17772 glyph
->left_box_line_p
,
17773 glyph
->right_box_line_p
);
17775 else if (glyph
->type
== IMAGE_GLYPH
)
17778 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
17779 glyph
- row
->glyphs
[TEXT_AREA
],
17782 (BUFFERP (glyph
->object
)
17784 : (STRINGP (glyph
->object
)
17786 : (INTEGERP (glyph
->object
)
17789 glyph
->pixel_width
,
17793 glyph
->left_box_line_p
,
17794 glyph
->right_box_line_p
);
17796 else if (glyph
->type
== COMPOSITE_GLYPH
)
17799 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x",
17800 glyph
- row
->glyphs
[TEXT_AREA
],
17803 (BUFFERP (glyph
->object
)
17805 : (STRINGP (glyph
->object
)
17807 : (INTEGERP (glyph
->object
)
17810 glyph
->pixel_width
,
17812 if (glyph
->u
.cmp
.automatic
)
17815 glyph
->slice
.cmp
.from
, glyph
->slice
.cmp
.to
);
17816 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
17818 glyph
->left_box_line_p
,
17819 glyph
->right_box_line_p
);
17824 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
17825 GLYPHS 0 means don't show glyph contents.
17826 GLYPHS 1 means show glyphs in short form
17827 GLYPHS > 1 means show glyphs in long form. */
17830 dump_glyph_row (struct glyph_row
*row
, int vpos
, int glyphs
)
17834 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
17835 fprintf (stderr
, "==============================================================================\n");
17837 fprintf (stderr
, "%3d %9"pI
"d %9"pI
"d %4d %1.1d%1.1d%1.1d%1.1d\
17838 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
17840 MATRIX_ROW_START_CHARPOS (row
),
17841 MATRIX_ROW_END_CHARPOS (row
),
17842 row
->used
[TEXT_AREA
],
17843 row
->contains_overlapping_glyphs_p
,
17845 row
->truncated_on_left_p
,
17846 row
->truncated_on_right_p
,
17848 MATRIX_ROW_CONTINUATION_LINE_P (row
),
17849 row
->displays_text_p
,
17852 row
->ends_in_middle_of_char_p
,
17853 row
->starts_in_middle_of_char_p
,
17859 row
->visible_height
,
17862 /* The next 3 lines should align to "Start" in the header. */
17863 fprintf (stderr
, " %9"pD
"d %9"pD
"d\t%5d\n", row
->start
.overlay_string_index
,
17864 row
->end
.overlay_string_index
,
17865 row
->continuation_lines_width
);
17866 fprintf (stderr
, " %9"pI
"d %9"pI
"d\n",
17867 CHARPOS (row
->start
.string_pos
),
17868 CHARPOS (row
->end
.string_pos
));
17869 fprintf (stderr
, " %9d %9d\n", row
->start
.dpvec_index
,
17870 row
->end
.dpvec_index
);
17877 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
17879 struct glyph
*glyph
= row
->glyphs
[area
];
17880 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
17882 /* Glyph for a line end in text. */
17883 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
17886 if (glyph
< glyph_end
)
17887 fprintf (stderr
, " Glyph# Type Pos O W Code C Face LR\n");
17889 for (; glyph
< glyph_end
; ++glyph
)
17890 dump_glyph (row
, glyph
, area
);
17893 else if (glyphs
== 1)
17897 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
17899 char *s
= alloca (row
->used
[area
] + 4);
17902 for (i
= 0; i
< row
->used
[area
]; ++i
)
17904 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
17905 if (i
== row
->used
[area
] - 1
17906 && area
== TEXT_AREA
17907 && INTEGERP (glyph
->object
)
17908 && glyph
->type
== CHAR_GLYPH
17909 && glyph
->u
.ch
== ' ')
17911 strcpy (&s
[i
], "[\\n]");
17914 else if (glyph
->type
== CHAR_GLYPH
17915 && glyph
->u
.ch
< 0x80
17916 && glyph
->u
.ch
>= ' ')
17917 s
[i
] = glyph
->u
.ch
;
17923 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
17929 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
17930 Sdump_glyph_matrix
, 0, 1, "p",
17931 doc
: /* Dump the current matrix of the selected window to stderr.
17932 Shows contents of glyph row structures. With non-nil
17933 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
17934 glyphs in short form, otherwise show glyphs in long form. */)
17935 (Lisp_Object glyphs
)
17937 struct window
*w
= XWINDOW (selected_window
);
17938 struct buffer
*buffer
= XBUFFER (w
->buffer
);
17940 fprintf (stderr
, "PT = %"pI
"d, BEGV = %"pI
"d. ZV = %"pI
"d\n",
17941 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
17942 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
17943 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
17944 fprintf (stderr
, "=============================================\n");
17945 dump_glyph_matrix (w
->current_matrix
,
17946 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 0);
17951 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
17952 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
17955 struct frame
*f
= XFRAME (selected_frame
);
17956 dump_glyph_matrix (f
->current_matrix
, 1);
17961 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
17962 doc
: /* Dump glyph row ROW to stderr.
17963 GLYPH 0 means don't dump glyphs.
17964 GLYPH 1 means dump glyphs in short form.
17965 GLYPH > 1 or omitted means dump glyphs in long form. */)
17966 (Lisp_Object row
, Lisp_Object glyphs
)
17968 struct glyph_matrix
*matrix
;
17971 CHECK_NUMBER (row
);
17972 matrix
= XWINDOW (selected_window
)->current_matrix
;
17974 if (vpos
>= 0 && vpos
< matrix
->nrows
)
17975 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
17977 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
17982 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
17983 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
17984 GLYPH 0 means don't dump glyphs.
17985 GLYPH 1 means dump glyphs in short form.
17986 GLYPH > 1 or omitted means dump glyphs in long form. */)
17987 (Lisp_Object row
, Lisp_Object glyphs
)
17989 struct frame
*sf
= SELECTED_FRAME ();
17990 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
17993 CHECK_NUMBER (row
);
17995 if (vpos
>= 0 && vpos
< m
->nrows
)
17996 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
17997 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18002 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
18003 doc
: /* Toggle tracing of redisplay.
18004 With ARG, turn tracing on if and only if ARG is positive. */)
18008 trace_redisplay_p
= !trace_redisplay_p
;
18011 arg
= Fprefix_numeric_value (arg
);
18012 trace_redisplay_p
= XINT (arg
) > 0;
18019 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
18020 doc
: /* Like `format', but print result to stderr.
18021 usage: (trace-to-stderr STRING &rest OBJECTS) */)
18022 (ptrdiff_t nargs
, Lisp_Object
*args
)
18024 Lisp_Object s
= Fformat (nargs
, args
);
18025 fprintf (stderr
, "%s", SDATA (s
));
18029 #endif /* GLYPH_DEBUG */
18033 /***********************************************************************
18034 Building Desired Matrix Rows
18035 ***********************************************************************/
18037 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
18038 Used for non-window-redisplay windows, and for windows w/o left fringe. */
18040 static struct glyph_row
*
18041 get_overlay_arrow_glyph_row (struct window
*w
, Lisp_Object overlay_arrow_string
)
18043 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18044 struct buffer
*buffer
= XBUFFER (w
->buffer
);
18045 struct buffer
*old
= current_buffer
;
18046 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
18047 int arrow_len
= SCHARS (overlay_arrow_string
);
18048 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
18049 const unsigned char *p
;
18052 int n_glyphs_before
;
18054 set_buffer_temp (buffer
);
18055 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
18056 it
.glyph_row
->used
[TEXT_AREA
] = 0;
18057 SET_TEXT_POS (it
.position
, 0, 0);
18059 multibyte_p
= !NILP (BVAR (buffer
, enable_multibyte_characters
));
18061 while (p
< arrow_end
)
18063 Lisp_Object face
, ilisp
;
18065 /* Get the next character. */
18067 it
.c
= it
.char_to_display
= string_char_and_length (p
, &it
.len
);
18070 it
.c
= it
.char_to_display
= *p
, it
.len
= 1;
18071 if (! ASCII_CHAR_P (it
.c
))
18072 it
.char_to_display
= BYTE8_TO_CHAR (it
.c
);
18076 /* Get its face. */
18077 ilisp
= make_number (p
- arrow_string
);
18078 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
18079 it
.face_id
= compute_char_face (f
, it
.char_to_display
, face
);
18081 /* Compute its width, get its glyphs. */
18082 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
18083 SET_TEXT_POS (it
.position
, -1, -1);
18084 PRODUCE_GLYPHS (&it
);
18086 /* If this character doesn't fit any more in the line, we have
18087 to remove some glyphs. */
18088 if (it
.current_x
> it
.last_visible_x
)
18090 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
18095 set_buffer_temp (old
);
18096 return it
.glyph_row
;
18100 /* Insert truncation glyphs at the start of IT->glyph_row. Which
18101 glyphs to insert is determined by produce_special_glyphs. */
18104 insert_left_trunc_glyphs (struct it
*it
)
18106 struct it truncate_it
;
18107 struct glyph
*from
, *end
, *to
, *toend
;
18109 eassert (!FRAME_WINDOW_P (it
->f
)
18110 || (!it
->glyph_row
->reversed_p
18111 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0)
18112 || (it
->glyph_row
->reversed_p
18113 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0));
18115 /* Get the truncation glyphs. */
18117 truncate_it
.current_x
= 0;
18118 truncate_it
.face_id
= DEFAULT_FACE_ID
;
18119 truncate_it
.glyph_row
= &scratch_glyph_row
;
18120 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
18121 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
18122 truncate_it
.object
= make_number (0);
18123 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
18125 /* Overwrite glyphs from IT with truncation glyphs. */
18126 if (!it
->glyph_row
->reversed_p
)
18128 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
18130 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18131 end
= from
+ tused
;
18132 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18133 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
18134 if (FRAME_WINDOW_P (it
->f
))
18136 /* On GUI frames, when variable-size fonts are displayed,
18137 the truncation glyphs may need more pixels than the row's
18138 glyphs they overwrite. We overwrite more glyphs to free
18139 enough screen real estate, and enlarge the stretch glyph
18140 on the right (see display_line), if there is one, to
18141 preserve the screen position of the truncation glyphs on
18144 struct glyph
*g
= to
;
18147 /* The first glyph could be partially visible, in which case
18148 it->glyph_row->x will be negative. But we want the left
18149 truncation glyphs to be aligned at the left margin of the
18150 window, so we override the x coordinate at which the row
18152 it
->glyph_row
->x
= 0;
18153 while (g
< toend
&& w
< it
->truncation_pixel_width
)
18155 w
+= g
->pixel_width
;
18158 if (g
- to
- tused
> 0)
18160 memmove (to
+ tused
, g
, (toend
- g
) * sizeof(*g
));
18161 it
->glyph_row
->used
[TEXT_AREA
] -= g
- to
- tused
;
18163 used
= it
->glyph_row
->used
[TEXT_AREA
];
18164 if (it
->glyph_row
->truncated_on_right_p
18165 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0
18166 && it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].type
18169 int extra
= w
- it
->truncation_pixel_width
;
18171 it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].pixel_width
+= extra
;
18178 /* There may be padding glyphs left over. Overwrite them too. */
18179 if (!FRAME_WINDOW_P (it
->f
))
18181 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
18183 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18190 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
18194 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
18196 /* In R2L rows, overwrite the last (rightmost) glyphs, and do
18197 that back to front. */
18198 end
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18199 from
= end
+ truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18200 toend
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18201 to
= toend
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18202 if (FRAME_WINDOW_P (it
->f
))
18205 struct glyph
*g
= to
;
18207 while (g
>= toend
&& w
< it
->truncation_pixel_width
)
18209 w
+= g
->pixel_width
;
18212 if (to
- g
- tused
> 0)
18214 if (it
->glyph_row
->truncated_on_right_p
18215 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0
18216 && it
->glyph_row
->glyphs
[TEXT_AREA
][1].type
== STRETCH_GLYPH
)
18218 int extra
= w
- it
->truncation_pixel_width
;
18220 it
->glyph_row
->glyphs
[TEXT_AREA
][1].pixel_width
+= extra
;
18224 while (from
>= end
&& to
>= toend
)
18226 if (!FRAME_WINDOW_P (it
->f
))
18228 while (to
>= toend
&& CHAR_GLYPH_PADDING_P (*to
))
18231 truncate_it
.glyph_row
->glyphs
[TEXT_AREA
]
18232 + truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18233 while (from
>= end
&& to
>= toend
)
18239 /* Need to free some room before prepending additional
18241 int move_by
= from
- end
+ 1;
18242 struct glyph
*g0
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18243 struct glyph
*g
= g0
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18245 for ( ; g
>= g0
; g
--)
18247 while (from
>= end
)
18249 it
->glyph_row
->used
[TEXT_AREA
] += move_by
;
18254 /* Compute the hash code for ROW. */
18256 row_hash (struct glyph_row
*row
)
18259 unsigned hashval
= 0;
18261 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18262 for (k
= 0; k
< row
->used
[area
]; ++k
)
18263 hashval
= ((((hashval
<< 4) + (hashval
>> 24)) & 0x0fffffff)
18264 + row
->glyphs
[area
][k
].u
.val
18265 + row
->glyphs
[area
][k
].face_id
18266 + row
->glyphs
[area
][k
].padding_p
18267 + (row
->glyphs
[area
][k
].type
<< 2));
18272 /* Compute the pixel height and width of IT->glyph_row.
18274 Most of the time, ascent and height of a display line will be equal
18275 to the max_ascent and max_height values of the display iterator
18276 structure. This is not the case if
18278 1. We hit ZV without displaying anything. In this case, max_ascent
18279 and max_height will be zero.
18281 2. We have some glyphs that don't contribute to the line height.
18282 (The glyph row flag contributes_to_line_height_p is for future
18283 pixmap extensions).
18285 The first case is easily covered by using default values because in
18286 these cases, the line height does not really matter, except that it
18287 must not be zero. */
18290 compute_line_metrics (struct it
*it
)
18292 struct glyph_row
*row
= it
->glyph_row
;
18294 if (FRAME_WINDOW_P (it
->f
))
18296 int i
, min_y
, max_y
;
18298 /* The line may consist of one space only, that was added to
18299 place the cursor on it. If so, the row's height hasn't been
18301 if (row
->height
== 0)
18303 if (it
->max_ascent
+ it
->max_descent
== 0)
18304 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
18305 row
->ascent
= it
->max_ascent
;
18306 row
->height
= it
->max_ascent
+ it
->max_descent
;
18307 row
->phys_ascent
= it
->max_phys_ascent
;
18308 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18309 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18312 /* Compute the width of this line. */
18313 row
->pixel_width
= row
->x
;
18314 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
18315 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
18317 eassert (row
->pixel_width
>= 0);
18318 eassert (row
->ascent
>= 0 && row
->height
> 0);
18320 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
18321 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
18323 /* If first line's physical ascent is larger than its logical
18324 ascent, use the physical ascent, and make the row taller.
18325 This makes accented characters fully visible. */
18326 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
18327 && row
->phys_ascent
> row
->ascent
)
18329 row
->height
+= row
->phys_ascent
- row
->ascent
;
18330 row
->ascent
= row
->phys_ascent
;
18333 /* Compute how much of the line is visible. */
18334 row
->visible_height
= row
->height
;
18336 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
18337 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
18339 if (row
->y
< min_y
)
18340 row
->visible_height
-= min_y
- row
->y
;
18341 if (row
->y
+ row
->height
> max_y
)
18342 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
18346 row
->pixel_width
= row
->used
[TEXT_AREA
];
18347 if (row
->continued_p
)
18348 row
->pixel_width
-= it
->continuation_pixel_width
;
18349 else if (row
->truncated_on_right_p
)
18350 row
->pixel_width
-= it
->truncation_pixel_width
;
18351 row
->ascent
= row
->phys_ascent
= 0;
18352 row
->height
= row
->phys_height
= row
->visible_height
= 1;
18353 row
->extra_line_spacing
= 0;
18356 /* Compute a hash code for this row. */
18357 row
->hash
= row_hash (row
);
18359 it
->max_ascent
= it
->max_descent
= 0;
18360 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
18364 /* Append one space to the glyph row of iterator IT if doing a
18365 window-based redisplay. The space has the same face as
18366 IT->face_id. Value is non-zero if a space was added.
18368 This function is called to make sure that there is always one glyph
18369 at the end of a glyph row that the cursor can be set on under
18370 window-systems. (If there weren't such a glyph we would not know
18371 how wide and tall a box cursor should be displayed).
18373 At the same time this space let's a nicely handle clearing to the
18374 end of the line if the row ends in italic text. */
18377 append_space_for_newline (struct it
*it
, int default_face_p
)
18379 if (FRAME_WINDOW_P (it
->f
))
18381 int n
= it
->glyph_row
->used
[TEXT_AREA
];
18383 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
18384 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
18386 /* Save some values that must not be changed.
18387 Must save IT->c and IT->len because otherwise
18388 ITERATOR_AT_END_P wouldn't work anymore after
18389 append_space_for_newline has been called. */
18390 enum display_element_type saved_what
= it
->what
;
18391 int saved_c
= it
->c
, saved_len
= it
->len
;
18392 int saved_char_to_display
= it
->char_to_display
;
18393 int saved_x
= it
->current_x
;
18394 int saved_face_id
= it
->face_id
;
18395 int saved_box_end
= it
->end_of_box_run_p
;
18396 struct text_pos saved_pos
;
18397 Lisp_Object saved_object
;
18400 saved_object
= it
->object
;
18401 saved_pos
= it
->position
;
18403 it
->what
= IT_CHARACTER
;
18404 memset (&it
->position
, 0, sizeof it
->position
);
18405 it
->object
= make_number (0);
18406 it
->c
= it
->char_to_display
= ' ';
18409 /* If the default face was remapped, be sure to use the
18410 remapped face for the appended newline. */
18411 if (default_face_p
)
18412 it
->face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
18413 else if (it
->face_before_selective_p
)
18414 it
->face_id
= it
->saved_face_id
;
18415 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18416 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
18417 /* In R2L rows, we will prepend a stretch glyph that will
18418 have the end_of_box_run_p flag set for it, so there's no
18419 need for the appended newline glyph to have that flag
18421 if (it
->glyph_row
->reversed_p
18422 /* But if the appended newline glyph goes all the way to
18423 the end of the row, there will be no stretch glyph,
18424 so leave the box flag set. */
18425 && saved_x
+ FRAME_COLUMN_WIDTH (it
->f
) < it
->last_visible_x
)
18426 it
->end_of_box_run_p
= 0;
18428 PRODUCE_GLYPHS (it
);
18430 it
->override_ascent
= -1;
18431 it
->constrain_row_ascent_descent_p
= 0;
18432 it
->current_x
= saved_x
;
18433 it
->object
= saved_object
;
18434 it
->position
= saved_pos
;
18435 it
->what
= saved_what
;
18436 it
->face_id
= saved_face_id
;
18437 it
->len
= saved_len
;
18439 it
->char_to_display
= saved_char_to_display
;
18440 it
->end_of_box_run_p
= saved_box_end
;
18449 /* Extend the face of the last glyph in the text area of IT->glyph_row
18450 to the end of the display line. Called from display_line. If the
18451 glyph row is empty, add a space glyph to it so that we know the
18452 face to draw. Set the glyph row flag fill_line_p. If the glyph
18453 row is R2L, prepend a stretch glyph to cover the empty space to the
18454 left of the leftmost glyph. */
18457 extend_face_to_end_of_line (struct it
*it
)
18459 struct face
*face
, *default_face
;
18460 struct frame
*f
= it
->f
;
18462 /* If line is already filled, do nothing. Non window-system frames
18463 get a grace of one more ``pixel'' because their characters are
18464 1-``pixel'' wide, so they hit the equality too early. This grace
18465 is needed only for R2L rows that are not continued, to produce
18466 one extra blank where we could display the cursor. */
18467 if (it
->current_x
>= it
->last_visible_x
18468 + (!FRAME_WINDOW_P (f
)
18469 && it
->glyph_row
->reversed_p
18470 && !it
->glyph_row
->continued_p
))
18473 /* The default face, possibly remapped. */
18474 default_face
= FACE_FROM_ID (f
, lookup_basic_face (f
, DEFAULT_FACE_ID
));
18476 /* Face extension extends the background and box of IT->face_id
18477 to the end of the line. If the background equals the background
18478 of the frame, we don't have to do anything. */
18479 if (it
->face_before_selective_p
)
18480 face
= FACE_FROM_ID (f
, it
->saved_face_id
);
18482 face
= FACE_FROM_ID (f
, it
->face_id
);
18484 if (FRAME_WINDOW_P (f
)
18485 && it
->glyph_row
->displays_text_p
18486 && face
->box
== FACE_NO_BOX
18487 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
18489 && !it
->glyph_row
->reversed_p
)
18492 /* Set the glyph row flag indicating that the face of the last glyph
18493 in the text area has to be drawn to the end of the text area. */
18494 it
->glyph_row
->fill_line_p
= 1;
18496 /* If current character of IT is not ASCII, make sure we have the
18497 ASCII face. This will be automatically undone the next time
18498 get_next_display_element returns a multibyte character. Note
18499 that the character will always be single byte in unibyte
18501 if (!ASCII_CHAR_P (it
->c
))
18503 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
18506 if (FRAME_WINDOW_P (f
))
18508 /* If the row is empty, add a space with the current face of IT,
18509 so that we know which face to draw. */
18510 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
18512 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
18513 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= face
->id
;
18514 it
->glyph_row
->used
[TEXT_AREA
] = 1;
18516 #ifdef HAVE_WINDOW_SYSTEM
18517 if (it
->glyph_row
->reversed_p
)
18519 /* Prepend a stretch glyph to the row, such that the
18520 rightmost glyph will be drawn flushed all the way to the
18521 right margin of the window. The stretch glyph that will
18522 occupy the empty space, if any, to the left of the
18524 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (f
);
18525 struct glyph
*row_start
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18526 struct glyph
*row_end
= row_start
+ it
->glyph_row
->used
[TEXT_AREA
];
18528 int row_width
, stretch_ascent
, stretch_width
;
18529 struct text_pos saved_pos
;
18530 int saved_face_id
, saved_avoid_cursor
, saved_box_start
;
18532 for (row_width
= 0, g
= row_start
; g
< row_end
; g
++)
18533 row_width
+= g
->pixel_width
;
18534 stretch_width
= window_box_width (it
->w
, TEXT_AREA
) - row_width
;
18535 if (stretch_width
> 0)
18538 (((it
->ascent
+ it
->descent
)
18539 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
18540 saved_pos
= it
->position
;
18541 memset (&it
->position
, 0, sizeof it
->position
);
18542 saved_avoid_cursor
= it
->avoid_cursor_p
;
18543 it
->avoid_cursor_p
= 1;
18544 saved_face_id
= it
->face_id
;
18545 saved_box_start
= it
->start_of_box_run_p
;
18546 /* The last row's stretch glyph should get the default
18547 face, to avoid painting the rest of the window with
18548 the region face, if the region ends at ZV. */
18549 if (it
->glyph_row
->ends_at_zv_p
)
18550 it
->face_id
= default_face
->id
;
18552 it
->face_id
= face
->id
;
18553 it
->start_of_box_run_p
= 0;
18554 append_stretch_glyph (it
, make_number (0), stretch_width
,
18555 it
->ascent
+ it
->descent
, stretch_ascent
);
18556 it
->position
= saved_pos
;
18557 it
->avoid_cursor_p
= saved_avoid_cursor
;
18558 it
->face_id
= saved_face_id
;
18559 it
->start_of_box_run_p
= saved_box_start
;
18562 #endif /* HAVE_WINDOW_SYSTEM */
18566 /* Save some values that must not be changed. */
18567 int saved_x
= it
->current_x
;
18568 struct text_pos saved_pos
;
18569 Lisp_Object saved_object
;
18570 enum display_element_type saved_what
= it
->what
;
18571 int saved_face_id
= it
->face_id
;
18573 saved_object
= it
->object
;
18574 saved_pos
= it
->position
;
18576 it
->what
= IT_CHARACTER
;
18577 memset (&it
->position
, 0, sizeof it
->position
);
18578 it
->object
= make_number (0);
18579 it
->c
= it
->char_to_display
= ' ';
18581 /* The last row's blank glyphs should get the default face, to
18582 avoid painting the rest of the window with the region face,
18583 if the region ends at ZV. */
18584 if (it
->glyph_row
->ends_at_zv_p
)
18585 it
->face_id
= default_face
->id
;
18587 it
->face_id
= face
->id
;
18589 PRODUCE_GLYPHS (it
);
18591 while (it
->current_x
<= it
->last_visible_x
)
18592 PRODUCE_GLYPHS (it
);
18594 /* Don't count these blanks really. It would let us insert a left
18595 truncation glyph below and make us set the cursor on them, maybe. */
18596 it
->current_x
= saved_x
;
18597 it
->object
= saved_object
;
18598 it
->position
= saved_pos
;
18599 it
->what
= saved_what
;
18600 it
->face_id
= saved_face_id
;
18605 /* Value is non-zero if text starting at CHARPOS in current_buffer is
18606 trailing whitespace. */
18609 trailing_whitespace_p (ptrdiff_t charpos
)
18611 ptrdiff_t bytepos
= CHAR_TO_BYTE (charpos
);
18614 while (bytepos
< ZV_BYTE
18615 && (c
= FETCH_CHAR (bytepos
),
18616 c
== ' ' || c
== '\t'))
18619 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
18621 if (bytepos
!= PT_BYTE
)
18628 /* Highlight trailing whitespace, if any, in ROW. */
18631 highlight_trailing_whitespace (struct frame
*f
, struct glyph_row
*row
)
18633 int used
= row
->used
[TEXT_AREA
];
18637 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
18638 struct glyph
*glyph
= start
+ used
- 1;
18640 if (row
->reversed_p
)
18642 /* Right-to-left rows need to be processed in the opposite
18643 direction, so swap the edge pointers. */
18645 start
= row
->glyphs
[TEXT_AREA
] + used
- 1;
18648 /* Skip over glyphs inserted to display the cursor at the
18649 end of a line, for extending the face of the last glyph
18650 to the end of the line on terminals, and for truncation
18651 and continuation glyphs. */
18652 if (!row
->reversed_p
)
18654 while (glyph
>= start
18655 && glyph
->type
== CHAR_GLYPH
18656 && INTEGERP (glyph
->object
))
18661 while (glyph
<= start
18662 && glyph
->type
== CHAR_GLYPH
18663 && INTEGERP (glyph
->object
))
18667 /* If last glyph is a space or stretch, and it's trailing
18668 whitespace, set the face of all trailing whitespace glyphs in
18669 IT->glyph_row to `trailing-whitespace'. */
18670 if ((row
->reversed_p
? glyph
<= start
: glyph
>= start
)
18671 && BUFFERP (glyph
->object
)
18672 && (glyph
->type
== STRETCH_GLYPH
18673 || (glyph
->type
== CHAR_GLYPH
18674 && glyph
->u
.ch
== ' '))
18675 && trailing_whitespace_p (glyph
->charpos
))
18677 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
18681 if (!row
->reversed_p
)
18683 while (glyph
>= start
18684 && BUFFERP (glyph
->object
)
18685 && (glyph
->type
== STRETCH_GLYPH
18686 || (glyph
->type
== CHAR_GLYPH
18687 && glyph
->u
.ch
== ' ')))
18688 (glyph
--)->face_id
= face_id
;
18692 while (glyph
<= start
18693 && BUFFERP (glyph
->object
)
18694 && (glyph
->type
== STRETCH_GLYPH
18695 || (glyph
->type
== CHAR_GLYPH
18696 && glyph
->u
.ch
== ' ')))
18697 (glyph
++)->face_id
= face_id
;
18704 /* Value is non-zero if glyph row ROW should be
18705 used to hold the cursor. */
18708 cursor_row_p (struct glyph_row
*row
)
18712 if (PT
== CHARPOS (row
->end
.pos
)
18713 || PT
== MATRIX_ROW_END_CHARPOS (row
))
18715 /* Suppose the row ends on a string.
18716 Unless the row is continued, that means it ends on a newline
18717 in the string. If it's anything other than a display string
18718 (e.g., a before-string from an overlay), we don't want the
18719 cursor there. (This heuristic seems to give the optimal
18720 behavior for the various types of multi-line strings.)
18721 One exception: if the string has `cursor' property on one of
18722 its characters, we _do_ want the cursor there. */
18723 if (CHARPOS (row
->end
.string_pos
) >= 0)
18725 if (row
->continued_p
)
18729 /* Check for `display' property. */
18730 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
18731 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
18732 struct glyph
*glyph
;
18735 for (glyph
= end
; glyph
>= beg
; --glyph
)
18736 if (STRINGP (glyph
->object
))
18739 = Fget_char_property (make_number (PT
),
18743 && display_prop_string_p (prop
, glyph
->object
));
18744 /* If there's a `cursor' property on one of the
18745 string's characters, this row is a cursor row,
18746 even though this is not a display string. */
18749 Lisp_Object s
= glyph
->object
;
18751 for ( ; glyph
>= beg
&& EQ (glyph
->object
, s
); --glyph
)
18753 ptrdiff_t gpos
= glyph
->charpos
;
18755 if (!NILP (Fget_char_property (make_number (gpos
),
18767 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
18769 /* If the row ends in middle of a real character,
18770 and the line is continued, we want the cursor here.
18771 That's because CHARPOS (ROW->end.pos) would equal
18772 PT if PT is before the character. */
18773 if (!row
->ends_in_ellipsis_p
)
18774 result
= row
->continued_p
;
18776 /* If the row ends in an ellipsis, then
18777 CHARPOS (ROW->end.pos) will equal point after the
18778 invisible text. We want that position to be displayed
18779 after the ellipsis. */
18782 /* If the row ends at ZV, display the cursor at the end of that
18783 row instead of at the start of the row below. */
18784 else if (row
->ends_at_zv_p
)
18795 /* Push the property PROP so that it will be rendered at the current
18796 position in IT. Return 1 if PROP was successfully pushed, 0
18797 otherwise. Called from handle_line_prefix to handle the
18798 `line-prefix' and `wrap-prefix' properties. */
18801 push_prefix_prop (struct it
*it
, Lisp_Object prop
)
18803 struct text_pos pos
=
18804 STRINGP (it
->string
) ? it
->current
.string_pos
: it
->current
.pos
;
18806 eassert (it
->method
== GET_FROM_BUFFER
18807 || it
->method
== GET_FROM_DISPLAY_VECTOR
18808 || it
->method
== GET_FROM_STRING
);
18810 /* We need to save the current buffer/string position, so it will be
18811 restored by pop_it, because iterate_out_of_display_property
18812 depends on that being set correctly, but some situations leave
18813 it->position not yet set when this function is called. */
18814 push_it (it
, &pos
);
18816 if (STRINGP (prop
))
18818 if (SCHARS (prop
) == 0)
18825 it
->string_from_prefix_prop_p
= 1;
18826 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
18827 it
->current
.overlay_string_index
= -1;
18828 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
18829 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
18830 it
->method
= GET_FROM_STRING
;
18831 it
->stop_charpos
= 0;
18833 it
->base_level_stop
= 0;
18835 /* Force paragraph direction to be that of the parent
18837 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
18838 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
18840 it
->paragraph_embedding
= L2R
;
18842 /* Set up the bidi iterator for this display string. */
18845 it
->bidi_it
.string
.lstring
= it
->string
;
18846 it
->bidi_it
.string
.s
= NULL
;
18847 it
->bidi_it
.string
.schars
= it
->end_charpos
;
18848 it
->bidi_it
.string
.bufpos
= IT_CHARPOS (*it
);
18849 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
18850 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
18851 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
18854 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
18856 it
->method
= GET_FROM_STRETCH
;
18859 #ifdef HAVE_WINDOW_SYSTEM
18860 else if (IMAGEP (prop
))
18862 it
->what
= IT_IMAGE
;
18863 it
->image_id
= lookup_image (it
->f
, prop
);
18864 it
->method
= GET_FROM_IMAGE
;
18866 #endif /* HAVE_WINDOW_SYSTEM */
18869 pop_it (it
); /* bogus display property, give up */
18876 /* Return the character-property PROP at the current position in IT. */
18879 get_it_property (struct it
*it
, Lisp_Object prop
)
18881 Lisp_Object position
;
18883 if (STRINGP (it
->object
))
18884 position
= make_number (IT_STRING_CHARPOS (*it
));
18885 else if (BUFFERP (it
->object
))
18886 position
= make_number (IT_CHARPOS (*it
));
18890 return Fget_char_property (position
, prop
, it
->object
);
18893 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
18896 handle_line_prefix (struct it
*it
)
18898 Lisp_Object prefix
;
18900 if (it
->continuation_lines_width
> 0)
18902 prefix
= get_it_property (it
, Qwrap_prefix
);
18904 prefix
= Vwrap_prefix
;
18908 prefix
= get_it_property (it
, Qline_prefix
);
18910 prefix
= Vline_prefix
;
18912 if (! NILP (prefix
) && push_prefix_prop (it
, prefix
))
18914 /* If the prefix is wider than the window, and we try to wrap
18915 it, it would acquire its own wrap prefix, and so on till the
18916 iterator stack overflows. So, don't wrap the prefix. */
18917 it
->line_wrap
= TRUNCATE
;
18918 it
->avoid_cursor_p
= 1;
18924 /* Remove N glyphs at the start of a reversed IT->glyph_row. Called
18925 only for R2L lines from display_line and display_string, when they
18926 decide that too many glyphs were produced by PRODUCE_GLYPHS, and
18927 the line/string needs to be continued on the next glyph row. */
18929 unproduce_glyphs (struct it
*it
, int n
)
18931 struct glyph
*glyph
, *end
;
18933 eassert (it
->glyph_row
);
18934 eassert (it
->glyph_row
->reversed_p
);
18935 eassert (it
->area
== TEXT_AREA
);
18936 eassert (n
<= it
->glyph_row
->used
[TEXT_AREA
]);
18938 if (n
> it
->glyph_row
->used
[TEXT_AREA
])
18939 n
= it
->glyph_row
->used
[TEXT_AREA
];
18940 glyph
= it
->glyph_row
->glyphs
[TEXT_AREA
] + n
;
18941 end
= it
->glyph_row
->glyphs
[TEXT_AREA
] + it
->glyph_row
->used
[TEXT_AREA
];
18942 for ( ; glyph
< end
; glyph
++)
18943 glyph
[-n
] = *glyph
;
18946 /* Find the positions in a bidi-reordered ROW to serve as ROW->minpos
18947 and ROW->maxpos. */
18949 find_row_edges (struct it
*it
, struct glyph_row
*row
,
18950 ptrdiff_t min_pos
, ptrdiff_t min_bpos
,
18951 ptrdiff_t max_pos
, ptrdiff_t max_bpos
)
18953 /* FIXME: Revisit this when glyph ``spilling'' in continuation
18954 lines' rows is implemented for bidi-reordered rows. */
18956 /* ROW->minpos is the value of min_pos, the minimal buffer position
18957 we have in ROW, or ROW->start.pos if that is smaller. */
18958 if (min_pos
<= ZV
&& min_pos
< row
->start
.pos
.charpos
)
18959 SET_TEXT_POS (row
->minpos
, min_pos
, min_bpos
);
18961 /* We didn't find buffer positions smaller than ROW->start, or
18962 didn't find _any_ valid buffer positions in any of the glyphs,
18963 so we must trust the iterator's computed positions. */
18964 row
->minpos
= row
->start
.pos
;
18967 max_pos
= CHARPOS (it
->current
.pos
);
18968 max_bpos
= BYTEPOS (it
->current
.pos
);
18971 /* Here are the various use-cases for ending the row, and the
18972 corresponding values for ROW->maxpos:
18974 Line ends in a newline from buffer eol_pos + 1
18975 Line is continued from buffer max_pos + 1
18976 Line is truncated on right it->current.pos
18977 Line ends in a newline from string max_pos + 1(*)
18978 (*) + 1 only when line ends in a forward scan
18979 Line is continued from string max_pos
18980 Line is continued from display vector max_pos
18981 Line is entirely from a string min_pos == max_pos
18982 Line is entirely from a display vector min_pos == max_pos
18983 Line that ends at ZV ZV
18985 If you discover other use-cases, please add them here as
18987 if (row
->ends_at_zv_p
)
18988 row
->maxpos
= it
->current
.pos
;
18989 else if (row
->used
[TEXT_AREA
])
18991 int seen_this_string
= 0;
18992 struct glyph_row
*r1
= row
- 1;
18994 /* Did we see the same display string on the previous row? */
18995 if (STRINGP (it
->object
)
18996 /* this is not the first row */
18997 && row
> it
->w
->desired_matrix
->rows
18998 /* previous row is not the header line */
18999 && !r1
->mode_line_p
19000 /* previous row also ends in a newline from a string */
19001 && r1
->ends_in_newline_from_string_p
)
19003 struct glyph
*start
, *end
;
19005 /* Search for the last glyph of the previous row that came
19006 from buffer or string. Depending on whether the row is
19007 L2R or R2L, we need to process it front to back or the
19008 other way round. */
19009 if (!r1
->reversed_p
)
19011 start
= r1
->glyphs
[TEXT_AREA
];
19012 end
= start
+ r1
->used
[TEXT_AREA
];
19013 /* Glyphs inserted by redisplay have an integer (zero)
19014 as their object. */
19016 && INTEGERP ((end
- 1)->object
)
19017 && (end
- 1)->charpos
<= 0)
19021 if (EQ ((end
- 1)->object
, it
->object
))
19022 seen_this_string
= 1;
19025 /* If all the glyphs of the previous row were inserted
19026 by redisplay, it means the previous row was
19027 produced from a single newline, which is only
19028 possible if that newline came from the same string
19029 as the one which produced this ROW. */
19030 seen_this_string
= 1;
19034 end
= r1
->glyphs
[TEXT_AREA
] - 1;
19035 start
= end
+ r1
->used
[TEXT_AREA
];
19037 && INTEGERP ((end
+ 1)->object
)
19038 && (end
+ 1)->charpos
<= 0)
19042 if (EQ ((end
+ 1)->object
, it
->object
))
19043 seen_this_string
= 1;
19046 seen_this_string
= 1;
19049 /* Take note of each display string that covers a newline only
19050 once, the first time we see it. This is for when a display
19051 string includes more than one newline in it. */
19052 if (row
->ends_in_newline_from_string_p
&& !seen_this_string
)
19054 /* If we were scanning the buffer forward when we displayed
19055 the string, we want to account for at least one buffer
19056 position that belongs to this row (position covered by
19057 the display string), so that cursor positioning will
19058 consider this row as a candidate when point is at the end
19059 of the visual line represented by this row. This is not
19060 required when scanning back, because max_pos will already
19061 have a much larger value. */
19062 if (CHARPOS (row
->end
.pos
) > max_pos
)
19063 INC_BOTH (max_pos
, max_bpos
);
19064 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19066 else if (CHARPOS (it
->eol_pos
) > 0)
19067 SET_TEXT_POS (row
->maxpos
,
19068 CHARPOS (it
->eol_pos
) + 1, BYTEPOS (it
->eol_pos
) + 1);
19069 else if (row
->continued_p
)
19071 /* If max_pos is different from IT's current position, it
19072 means IT->method does not belong to the display element
19073 at max_pos. However, it also means that the display
19074 element at max_pos was displayed in its entirety on this
19075 line, which is equivalent to saying that the next line
19076 starts at the next buffer position. */
19077 if (IT_CHARPOS (*it
) == max_pos
&& it
->method
!= GET_FROM_BUFFER
)
19078 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19081 INC_BOTH (max_pos
, max_bpos
);
19082 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19085 else if (row
->truncated_on_right_p
)
19086 /* display_line already called reseat_at_next_visible_line_start,
19087 which puts the iterator at the beginning of the next line, in
19088 the logical order. */
19089 row
->maxpos
= it
->current
.pos
;
19090 else if (max_pos
== min_pos
&& it
->method
!= GET_FROM_BUFFER
)
19091 /* A line that is entirely from a string/image/stretch... */
19092 row
->maxpos
= row
->minpos
;
19097 row
->maxpos
= it
->current
.pos
;
19100 /* Construct the glyph row IT->glyph_row in the desired matrix of
19101 IT->w from text at the current position of IT. See dispextern.h
19102 for an overview of struct it. Value is non-zero if
19103 IT->glyph_row displays text, as opposed to a line displaying ZV
19107 display_line (struct it
*it
)
19109 struct glyph_row
*row
= it
->glyph_row
;
19110 Lisp_Object overlay_arrow_string
;
19112 void *wrap_data
= NULL
;
19113 int may_wrap
= 0, wrap_x
IF_LINT (= 0);
19114 int wrap_row_used
= -1;
19115 int wrap_row_ascent
IF_LINT (= 0), wrap_row_height
IF_LINT (= 0);
19116 int wrap_row_phys_ascent
IF_LINT (= 0), wrap_row_phys_height
IF_LINT (= 0);
19117 int wrap_row_extra_line_spacing
IF_LINT (= 0);
19118 ptrdiff_t wrap_row_min_pos
IF_LINT (= 0), wrap_row_min_bpos
IF_LINT (= 0);
19119 ptrdiff_t wrap_row_max_pos
IF_LINT (= 0), wrap_row_max_bpos
IF_LINT (= 0);
19121 ptrdiff_t min_pos
= ZV
+ 1, max_pos
= 0;
19122 ptrdiff_t min_bpos
IF_LINT (= 0), max_bpos
IF_LINT (= 0);
19124 /* We always start displaying at hpos zero even if hscrolled. */
19125 eassert (it
->hpos
== 0 && it
->current_x
== 0);
19127 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
19128 >= it
->w
->desired_matrix
->nrows
)
19130 it
->w
->nrows_scale_factor
++;
19131 fonts_changed_p
= 1;
19135 /* Is IT->w showing the region? */
19136 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? -1 : 0;
19138 /* Clear the result glyph row and enable it. */
19139 prepare_desired_row (row
);
19141 row
->y
= it
->current_y
;
19142 row
->start
= it
->start
;
19143 row
->continuation_lines_width
= it
->continuation_lines_width
;
19144 row
->displays_text_p
= 1;
19145 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
19146 it
->starts_in_middle_of_char_p
= 0;
19148 /* Arrange the overlays nicely for our purposes. Usually, we call
19149 display_line on only one line at a time, in which case this
19150 can't really hurt too much, or we call it on lines which appear
19151 one after another in the buffer, in which case all calls to
19152 recenter_overlay_lists but the first will be pretty cheap. */
19153 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
19155 /* Move over display elements that are not visible because we are
19156 hscrolled. This may stop at an x-position < IT->first_visible_x
19157 if the first glyph is partially visible or if we hit a line end. */
19158 if (it
->current_x
< it
->first_visible_x
)
19160 enum move_it_result move_result
;
19162 this_line_min_pos
= row
->start
.pos
;
19163 move_result
= move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
19164 MOVE_TO_POS
| MOVE_TO_X
);
19165 /* If we are under a large hscroll, move_it_in_display_line_to
19166 could hit the end of the line without reaching
19167 it->first_visible_x. Pretend that we did reach it. This is
19168 especially important on a TTY, where we will call
19169 extend_face_to_end_of_line, which needs to know how many
19170 blank glyphs to produce. */
19171 if (it
->current_x
< it
->first_visible_x
19172 && (move_result
== MOVE_NEWLINE_OR_CR
19173 || move_result
== MOVE_POS_MATCH_OR_ZV
))
19174 it
->current_x
= it
->first_visible_x
;
19176 /* Record the smallest positions seen while we moved over
19177 display elements that are not visible. This is needed by
19178 redisplay_internal for optimizing the case where the cursor
19179 stays inside the same line. The rest of this function only
19180 considers positions that are actually displayed, so
19181 RECORD_MAX_MIN_POS will not otherwise record positions that
19182 are hscrolled to the left of the left edge of the window. */
19183 min_pos
= CHARPOS (this_line_min_pos
);
19184 min_bpos
= BYTEPOS (this_line_min_pos
);
19188 /* We only do this when not calling `move_it_in_display_line_to'
19189 above, because move_it_in_display_line_to calls
19190 handle_line_prefix itself. */
19191 handle_line_prefix (it
);
19194 /* Get the initial row height. This is either the height of the
19195 text hscrolled, if there is any, or zero. */
19196 row
->ascent
= it
->max_ascent
;
19197 row
->height
= it
->max_ascent
+ it
->max_descent
;
19198 row
->phys_ascent
= it
->max_phys_ascent
;
19199 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
19200 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
19202 /* Utility macro to record max and min buffer positions seen until now. */
19203 #define RECORD_MAX_MIN_POS(IT) \
19206 int composition_p = !STRINGP ((IT)->string) \
19207 && ((IT)->what == IT_COMPOSITION); \
19208 ptrdiff_t current_pos = \
19209 composition_p ? (IT)->cmp_it.charpos \
19210 : IT_CHARPOS (*(IT)); \
19211 ptrdiff_t current_bpos = \
19212 composition_p ? CHAR_TO_BYTE (current_pos) \
19213 : IT_BYTEPOS (*(IT)); \
19214 if (current_pos < min_pos) \
19216 min_pos = current_pos; \
19217 min_bpos = current_bpos; \
19219 if (IT_CHARPOS (*it) > max_pos) \
19221 max_pos = IT_CHARPOS (*it); \
19222 max_bpos = IT_BYTEPOS (*it); \
19227 /* Loop generating characters. The loop is left with IT on the next
19228 character to display. */
19231 int n_glyphs_before
, hpos_before
, x_before
;
19233 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
19235 /* Retrieve the next thing to display. Value is zero if end of
19237 if (!get_next_display_element (it
))
19239 /* Maybe add a space at the end of this line that is used to
19240 display the cursor there under X. Set the charpos of the
19241 first glyph of blank lines not corresponding to any text
19243 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19244 row
->exact_window_width_line_p
= 1;
19245 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
19246 || row
->used
[TEXT_AREA
] == 0)
19248 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
19249 row
->displays_text_p
= 0;
19251 if (!NILP (BVAR (XBUFFER (it
->w
->buffer
), indicate_empty_lines
))
19252 && (!MINI_WINDOW_P (it
->w
)
19253 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
19254 row
->indicate_empty_line_p
= 1;
19257 it
->continuation_lines_width
= 0;
19258 row
->ends_at_zv_p
= 1;
19259 /* A row that displays right-to-left text must always have
19260 its last face extended all the way to the end of line,
19261 even if this row ends in ZV, because we still write to
19262 the screen left to right. We also need to extend the
19263 last face if the default face is remapped to some
19264 different face, otherwise the functions that clear
19265 portions of the screen will clear with the default face's
19266 background color. */
19267 if (row
->reversed_p
19268 || lookup_basic_face (it
->f
, DEFAULT_FACE_ID
) != DEFAULT_FACE_ID
)
19269 extend_face_to_end_of_line (it
);
19273 /* Now, get the metrics of what we want to display. This also
19274 generates glyphs in `row' (which is IT->glyph_row). */
19275 n_glyphs_before
= row
->used
[TEXT_AREA
];
19278 /* Remember the line height so far in case the next element doesn't
19279 fit on the line. */
19280 if (it
->line_wrap
!= TRUNCATE
)
19282 ascent
= it
->max_ascent
;
19283 descent
= it
->max_descent
;
19284 phys_ascent
= it
->max_phys_ascent
;
19285 phys_descent
= it
->max_phys_descent
;
19287 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
19289 if (IT_DISPLAYING_WHITESPACE (it
))
19293 SAVE_IT (wrap_it
, *it
, wrap_data
);
19295 wrap_row_used
= row
->used
[TEXT_AREA
];
19296 wrap_row_ascent
= row
->ascent
;
19297 wrap_row_height
= row
->height
;
19298 wrap_row_phys_ascent
= row
->phys_ascent
;
19299 wrap_row_phys_height
= row
->phys_height
;
19300 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
19301 wrap_row_min_pos
= min_pos
;
19302 wrap_row_min_bpos
= min_bpos
;
19303 wrap_row_max_pos
= max_pos
;
19304 wrap_row_max_bpos
= max_bpos
;
19310 PRODUCE_GLYPHS (it
);
19312 /* If this display element was in marginal areas, continue with
19314 if (it
->area
!= TEXT_AREA
)
19316 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19317 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19318 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19319 row
->phys_height
= max (row
->phys_height
,
19320 it
->max_phys_ascent
+ it
->max_phys_descent
);
19321 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19322 it
->max_extra_line_spacing
);
19323 set_iterator_to_next (it
, 1);
19327 /* Does the display element fit on the line? If we truncate
19328 lines, we should draw past the right edge of the window. If
19329 we don't truncate, we want to stop so that we can display the
19330 continuation glyph before the right margin. If lines are
19331 continued, there are two possible strategies for characters
19332 resulting in more than 1 glyph (e.g. tabs): Display as many
19333 glyphs as possible in this line and leave the rest for the
19334 continuation line, or display the whole element in the next
19335 line. Original redisplay did the former, so we do it also. */
19336 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
19337 hpos_before
= it
->hpos
;
19340 if (/* Not a newline. */
19342 /* Glyphs produced fit entirely in the line. */
19343 && it
->current_x
< it
->last_visible_x
)
19345 it
->hpos
+= nglyphs
;
19346 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19347 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19348 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19349 row
->phys_height
= max (row
->phys_height
,
19350 it
->max_phys_ascent
+ it
->max_phys_descent
);
19351 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19352 it
->max_extra_line_spacing
);
19353 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
19354 row
->x
= x
- it
->first_visible_x
;
19355 /* Record the maximum and minimum buffer positions seen so
19356 far in glyphs that will be displayed by this row. */
19358 RECORD_MAX_MIN_POS (it
);
19363 struct glyph
*glyph
;
19365 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
19367 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
19368 new_x
= x
+ glyph
->pixel_width
;
19370 if (/* Lines are continued. */
19371 it
->line_wrap
!= TRUNCATE
19372 && (/* Glyph doesn't fit on the line. */
19373 new_x
> it
->last_visible_x
19374 /* Or it fits exactly on a window system frame. */
19375 || (new_x
== it
->last_visible_x
19376 && FRAME_WINDOW_P (it
->f
)
19377 && (row
->reversed_p
19378 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19379 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
19381 /* End of a continued line. */
19384 || (new_x
== it
->last_visible_x
19385 && FRAME_WINDOW_P (it
->f
)
19386 && (row
->reversed_p
19387 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19388 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
))))
19390 /* Current glyph is the only one on the line or
19391 fits exactly on the line. We must continue
19392 the line because we can't draw the cursor
19393 after the glyph. */
19394 row
->continued_p
= 1;
19395 it
->current_x
= new_x
;
19396 it
->continuation_lines_width
+= new_x
;
19398 if (i
== nglyphs
- 1)
19400 /* If line-wrap is on, check if a previous
19401 wrap point was found. */
19402 if (wrap_row_used
> 0
19403 /* Even if there is a previous wrap
19404 point, continue the line here as
19405 usual, if (i) the previous character
19406 was a space or tab AND (ii) the
19407 current character is not. */
19409 || IT_DISPLAYING_WHITESPACE (it
)))
19412 /* Record the maximum and minimum buffer
19413 positions seen so far in glyphs that will be
19414 displayed by this row. */
19416 RECORD_MAX_MIN_POS (it
);
19417 set_iterator_to_next (it
, 1);
19418 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19420 if (!get_next_display_element (it
))
19422 row
->exact_window_width_line_p
= 1;
19423 it
->continuation_lines_width
= 0;
19424 row
->continued_p
= 0;
19425 row
->ends_at_zv_p
= 1;
19427 else if (ITERATOR_AT_END_OF_LINE_P (it
))
19429 row
->continued_p
= 0;
19430 row
->exact_window_width_line_p
= 1;
19434 else if (it
->bidi_p
)
19435 RECORD_MAX_MIN_POS (it
);
19437 else if (CHAR_GLYPH_PADDING_P (*glyph
)
19438 && !FRAME_WINDOW_P (it
->f
))
19440 /* A padding glyph that doesn't fit on this line.
19441 This means the whole character doesn't fit
19443 if (row
->reversed_p
)
19444 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19445 - n_glyphs_before
);
19446 row
->used
[TEXT_AREA
] = n_glyphs_before
;
19448 /* Fill the rest of the row with continuation
19449 glyphs like in 20.x. */
19450 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
19451 < row
->glyphs
[1 + TEXT_AREA
])
19452 produce_special_glyphs (it
, IT_CONTINUATION
);
19454 row
->continued_p
= 1;
19455 it
->current_x
= x_before
;
19456 it
->continuation_lines_width
+= x_before
;
19458 /* Restore the height to what it was before the
19459 element not fitting on the line. */
19460 it
->max_ascent
= ascent
;
19461 it
->max_descent
= descent
;
19462 it
->max_phys_ascent
= phys_ascent
;
19463 it
->max_phys_descent
= phys_descent
;
19465 else if (wrap_row_used
> 0)
19468 if (row
->reversed_p
)
19469 unproduce_glyphs (it
,
19470 row
->used
[TEXT_AREA
] - wrap_row_used
);
19471 RESTORE_IT (it
, &wrap_it
, wrap_data
);
19472 it
->continuation_lines_width
+= wrap_x
;
19473 row
->used
[TEXT_AREA
] = wrap_row_used
;
19474 row
->ascent
= wrap_row_ascent
;
19475 row
->height
= wrap_row_height
;
19476 row
->phys_ascent
= wrap_row_phys_ascent
;
19477 row
->phys_height
= wrap_row_phys_height
;
19478 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
19479 min_pos
= wrap_row_min_pos
;
19480 min_bpos
= wrap_row_min_bpos
;
19481 max_pos
= wrap_row_max_pos
;
19482 max_bpos
= wrap_row_max_bpos
;
19483 row
->continued_p
= 1;
19484 row
->ends_at_zv_p
= 0;
19485 row
->exact_window_width_line_p
= 0;
19486 it
->continuation_lines_width
+= x
;
19488 /* Make sure that a non-default face is extended
19489 up to the right margin of the window. */
19490 extend_face_to_end_of_line (it
);
19492 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
19494 /* A TAB that extends past the right edge of the
19495 window. This produces a single glyph on
19496 window system frames. We leave the glyph in
19497 this row and let it fill the row, but don't
19498 consume the TAB. */
19499 if ((row
->reversed_p
19500 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19501 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19502 produce_special_glyphs (it
, IT_CONTINUATION
);
19503 it
->continuation_lines_width
+= it
->last_visible_x
;
19504 row
->ends_in_middle_of_char_p
= 1;
19505 row
->continued_p
= 1;
19506 glyph
->pixel_width
= it
->last_visible_x
- x
;
19507 it
->starts_in_middle_of_char_p
= 1;
19511 /* Something other than a TAB that draws past
19512 the right edge of the window. Restore
19513 positions to values before the element. */
19514 if (row
->reversed_p
)
19515 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19516 - (n_glyphs_before
+ i
));
19517 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
19519 /* Display continuation glyphs. */
19520 it
->current_x
= x_before
;
19521 it
->continuation_lines_width
+= x
;
19522 if (!FRAME_WINDOW_P (it
->f
)
19523 || (row
->reversed_p
19524 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19525 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19526 produce_special_glyphs (it
, IT_CONTINUATION
);
19527 row
->continued_p
= 1;
19529 extend_face_to_end_of_line (it
);
19531 if (nglyphs
> 1 && i
> 0)
19533 row
->ends_in_middle_of_char_p
= 1;
19534 it
->starts_in_middle_of_char_p
= 1;
19537 /* Restore the height to what it was before the
19538 element not fitting on the line. */
19539 it
->max_ascent
= ascent
;
19540 it
->max_descent
= descent
;
19541 it
->max_phys_ascent
= phys_ascent
;
19542 it
->max_phys_descent
= phys_descent
;
19547 else if (new_x
> it
->first_visible_x
)
19549 /* Increment number of glyphs actually displayed. */
19552 /* Record the maximum and minimum buffer positions
19553 seen so far in glyphs that will be displayed by
19556 RECORD_MAX_MIN_POS (it
);
19558 if (x
< it
->first_visible_x
)
19559 /* Glyph is partially visible, i.e. row starts at
19560 negative X position. */
19561 row
->x
= x
- it
->first_visible_x
;
19565 /* Glyph is completely off the left margin of the
19566 window. This should not happen because of the
19567 move_it_in_display_line at the start of this
19568 function, unless the text display area of the
19569 window is empty. */
19570 eassert (it
->first_visible_x
<= it
->last_visible_x
);
19573 /* Even if this display element produced no glyphs at all,
19574 we want to record its position. */
19575 if (it
->bidi_p
&& nglyphs
== 0)
19576 RECORD_MAX_MIN_POS (it
);
19578 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19579 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19580 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19581 row
->phys_height
= max (row
->phys_height
,
19582 it
->max_phys_ascent
+ it
->max_phys_descent
);
19583 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19584 it
->max_extra_line_spacing
);
19586 /* End of this display line if row is continued. */
19587 if (row
->continued_p
|| row
->ends_at_zv_p
)
19592 /* Is this a line end? If yes, we're also done, after making
19593 sure that a non-default face is extended up to the right
19594 margin of the window. */
19595 if (ITERATOR_AT_END_OF_LINE_P (it
))
19597 int used_before
= row
->used
[TEXT_AREA
];
19599 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
19601 /* Add a space at the end of the line that is used to
19602 display the cursor there. */
19603 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19604 append_space_for_newline (it
, 0);
19606 /* Extend the face to the end of the line. */
19607 extend_face_to_end_of_line (it
);
19609 /* Make sure we have the position. */
19610 if (used_before
== 0)
19611 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
19613 /* Record the position of the newline, for use in
19615 it
->eol_pos
= it
->current
.pos
;
19617 /* Consume the line end. This skips over invisible lines. */
19618 set_iterator_to_next (it
, 1);
19619 it
->continuation_lines_width
= 0;
19623 /* Proceed with next display element. Note that this skips
19624 over lines invisible because of selective display. */
19625 set_iterator_to_next (it
, 1);
19627 /* If we truncate lines, we are done when the last displayed
19628 glyphs reach past the right margin of the window. */
19629 if (it
->line_wrap
== TRUNCATE
19630 && (FRAME_WINDOW_P (it
->f
) && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
19631 ? (it
->current_x
>= it
->last_visible_x
)
19632 : (it
->current_x
> it
->last_visible_x
)))
19634 /* Maybe add truncation glyphs. */
19635 if (!FRAME_WINDOW_P (it
->f
)
19636 || (row
->reversed_p
19637 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19638 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19642 if (!row
->reversed_p
)
19644 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
19645 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19650 for (i
= 0; i
< row
->used
[TEXT_AREA
]; i
++)
19651 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19653 /* Remove any padding glyphs at the front of ROW, to
19654 make room for the truncation glyphs we will be
19655 adding below. The loop below always inserts at
19656 least one truncation glyph, so also remove the
19657 last glyph added to ROW. */
19658 unproduce_glyphs (it
, i
+ 1);
19659 /* Adjust i for the loop below. */
19660 i
= row
->used
[TEXT_AREA
] - (i
+ 1);
19663 it
->current_x
= x_before
;
19664 if (!FRAME_WINDOW_P (it
->f
))
19666 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
19668 row
->used
[TEXT_AREA
] = i
;
19669 produce_special_glyphs (it
, IT_TRUNCATION
);
19674 row
->used
[TEXT_AREA
] = i
;
19675 produce_special_glyphs (it
, IT_TRUNCATION
);
19678 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19680 /* Don't truncate if we can overflow newline into fringe. */
19681 if (!get_next_display_element (it
))
19683 it
->continuation_lines_width
= 0;
19684 row
->ends_at_zv_p
= 1;
19685 row
->exact_window_width_line_p
= 1;
19688 if (ITERATOR_AT_END_OF_LINE_P (it
))
19690 row
->exact_window_width_line_p
= 1;
19691 goto at_end_of_line
;
19693 it
->current_x
= x_before
;
19696 row
->truncated_on_right_p
= 1;
19697 it
->continuation_lines_width
= 0;
19698 reseat_at_next_visible_line_start (it
, 0);
19699 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
19700 it
->hpos
= hpos_before
;
19706 bidi_unshelve_cache (wrap_data
, 1);
19708 /* If line is not empty and hscrolled, maybe insert truncation glyphs
19709 at the left window margin. */
19710 if (it
->first_visible_x
19711 && IT_CHARPOS (*it
) != CHARPOS (row
->start
.pos
))
19713 if (!FRAME_WINDOW_P (it
->f
)
19714 || (row
->reversed_p
19715 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
19716 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
19717 insert_left_trunc_glyphs (it
);
19718 row
->truncated_on_left_p
= 1;
19721 /* Remember the position at which this line ends.
19723 BIDI Note: any code that needs MATRIX_ROW_START/END_CHARPOS
19724 cannot be before the call to find_row_edges below, since that is
19725 where these positions are determined. */
19726 row
->end
= it
->current
;
19729 row
->minpos
= row
->start
.pos
;
19730 row
->maxpos
= row
->end
.pos
;
19734 /* ROW->minpos and ROW->maxpos must be the smallest and
19735 `1 + the largest' buffer positions in ROW. But if ROW was
19736 bidi-reordered, these two positions can be anywhere in the
19737 row, so we must determine them now. */
19738 find_row_edges (it
, row
, min_pos
, min_bpos
, max_pos
, max_bpos
);
19741 /* If the start of this line is the overlay arrow-position, then
19742 mark this glyph row as the one containing the overlay arrow.
19743 This is clearly a mess with variable size fonts. It would be
19744 better to let it be displayed like cursors under X. */
19745 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
19746 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
19747 !NILP (overlay_arrow_string
)))
19749 /* Overlay arrow in window redisplay is a fringe bitmap. */
19750 if (STRINGP (overlay_arrow_string
))
19752 struct glyph_row
*arrow_row
19753 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
19754 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
19755 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
19756 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
19757 struct glyph
*p2
, *end
;
19759 /* Copy the arrow glyphs. */
19760 while (glyph
< arrow_end
)
19763 /* Throw away padding glyphs. */
19765 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
19766 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
19772 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
19777 eassert (INTEGERP (overlay_arrow_string
));
19778 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
19780 overlay_arrow_seen
= 1;
19783 /* Highlight trailing whitespace. */
19784 if (!NILP (Vshow_trailing_whitespace
))
19785 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
19787 /* Compute pixel dimensions of this line. */
19788 compute_line_metrics (it
);
19790 /* Implementation note: No changes in the glyphs of ROW or in their
19791 faces can be done past this point, because compute_line_metrics
19792 computes ROW's hash value and stores it within the glyph_row
19795 /* Record whether this row ends inside an ellipsis. */
19796 row
->ends_in_ellipsis_p
19797 = (it
->method
== GET_FROM_DISPLAY_VECTOR
19798 && it
->ellipsis_p
);
19800 /* Save fringe bitmaps in this row. */
19801 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
19802 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
19803 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
19804 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
19806 it
->left_user_fringe_bitmap
= 0;
19807 it
->left_user_fringe_face_id
= 0;
19808 it
->right_user_fringe_bitmap
= 0;
19809 it
->right_user_fringe_face_id
= 0;
19811 /* Maybe set the cursor. */
19812 cvpos
= it
->w
->cursor
.vpos
;
19814 /* In bidi-reordered rows, keep checking for proper cursor
19815 position even if one has been found already, because buffer
19816 positions in such rows change non-linearly with ROW->VPOS,
19817 when a line is continued. One exception: when we are at ZV,
19818 display cursor on the first suitable glyph row, since all
19819 the empty rows after that also have their position set to ZV. */
19820 /* FIXME: Revisit this when glyph ``spilling'' in continuation
19821 lines' rows is implemented for bidi-reordered rows. */
19823 && !MATRIX_ROW (it
->w
->desired_matrix
, cvpos
)->ends_at_zv_p
))
19824 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
19825 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
19826 && cursor_row_p (row
))
19827 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
19829 /* Prepare for the next line. This line starts horizontally at (X
19830 HPOS) = (0 0). Vertical positions are incremented. As a
19831 convenience for the caller, IT->glyph_row is set to the next
19833 it
->current_x
= it
->hpos
= 0;
19834 it
->current_y
+= row
->height
;
19835 SET_TEXT_POS (it
->eol_pos
, 0, 0);
19838 /* The next row should by default use the same value of the
19839 reversed_p flag as this one. set_iterator_to_next decides when
19840 it's a new paragraph, and PRODUCE_GLYPHS recomputes the value of
19841 the flag accordingly. */
19842 if (it
->glyph_row
< MATRIX_BOTTOM_TEXT_ROW (it
->w
->desired_matrix
, it
->w
))
19843 it
->glyph_row
->reversed_p
= row
->reversed_p
;
19844 it
->start
= row
->end
;
19845 return row
->displays_text_p
;
19847 #undef RECORD_MAX_MIN_POS
19850 DEFUN ("current-bidi-paragraph-direction", Fcurrent_bidi_paragraph_direction
,
19851 Scurrent_bidi_paragraph_direction
, 0, 1, 0,
19852 doc
: /* Return paragraph direction at point in BUFFER.
19853 Value is either `left-to-right' or `right-to-left'.
19854 If BUFFER is omitted or nil, it defaults to the current buffer.
19856 Paragraph direction determines how the text in the paragraph is displayed.
19857 In left-to-right paragraphs, text begins at the left margin of the window
19858 and the reading direction is generally left to right. In right-to-left
19859 paragraphs, text begins at the right margin and is read from right to left.
19861 See also `bidi-paragraph-direction'. */)
19862 (Lisp_Object buffer
)
19864 struct buffer
*buf
= current_buffer
;
19865 struct buffer
*old
= buf
;
19867 if (! NILP (buffer
))
19869 CHECK_BUFFER (buffer
);
19870 buf
= XBUFFER (buffer
);
19873 if (NILP (BVAR (buf
, bidi_display_reordering
))
19874 || NILP (BVAR (buf
, enable_multibyte_characters
))
19875 /* When we are loading loadup.el, the character property tables
19876 needed for bidi iteration are not yet available. */
19877 || !NILP (Vpurify_flag
))
19878 return Qleft_to_right
;
19879 else if (!NILP (BVAR (buf
, bidi_paragraph_direction
)))
19880 return BVAR (buf
, bidi_paragraph_direction
);
19883 /* Determine the direction from buffer text. We could try to
19884 use current_matrix if it is up to date, but this seems fast
19885 enough as it is. */
19886 struct bidi_it itb
;
19887 ptrdiff_t pos
= BUF_PT (buf
);
19888 ptrdiff_t bytepos
= BUF_PT_BYTE (buf
);
19890 void *itb_data
= bidi_shelve_cache ();
19892 set_buffer_temp (buf
);
19893 /* bidi_paragraph_init finds the base direction of the paragraph
19894 by searching forward from paragraph start. We need the base
19895 direction of the current or _previous_ paragraph, so we need
19896 to make sure we are within that paragraph. To that end, find
19897 the previous non-empty line. */
19898 if (pos
>= ZV
&& pos
> BEGV
)
19901 bytepos
= CHAR_TO_BYTE (pos
);
19903 if (fast_looking_at (build_string ("[\f\t ]*\n"),
19904 pos
, bytepos
, ZV
, ZV_BYTE
, Qnil
) > 0)
19906 while ((c
= FETCH_BYTE (bytepos
)) == '\n'
19907 || c
== ' ' || c
== '\t' || c
== '\f')
19909 if (bytepos
<= BEGV_BYTE
)
19914 while (!CHAR_HEAD_P (FETCH_BYTE (bytepos
)))
19917 bidi_init_it (pos
, bytepos
, FRAME_WINDOW_P (SELECTED_FRAME ()), &itb
);
19918 itb
.paragraph_dir
= NEUTRAL_DIR
;
19919 itb
.string
.s
= NULL
;
19920 itb
.string
.lstring
= Qnil
;
19921 itb
.string
.bufpos
= 0;
19922 itb
.string
.unibyte
= 0;
19923 bidi_paragraph_init (NEUTRAL_DIR
, &itb
, 1);
19924 bidi_unshelve_cache (itb_data
, 0);
19925 set_buffer_temp (old
);
19926 switch (itb
.paragraph_dir
)
19929 return Qleft_to_right
;
19932 return Qright_to_left
;
19942 /***********************************************************************
19944 ***********************************************************************/
19946 /* Redisplay the menu bar in the frame for window W.
19948 The menu bar of X frames that don't have X toolkit support is
19949 displayed in a special window W->frame->menu_bar_window.
19951 The menu bar of terminal frames is treated specially as far as
19952 glyph matrices are concerned. Menu bar lines are not part of
19953 windows, so the update is done directly on the frame matrix rows
19954 for the menu bar. */
19957 display_menu_bar (struct window
*w
)
19959 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19964 /* Don't do all this for graphical frames. */
19966 if (FRAME_W32_P (f
))
19969 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
19975 if (FRAME_NS_P (f
))
19977 #endif /* HAVE_NS */
19979 #ifdef USE_X_TOOLKIT
19980 eassert (!FRAME_WINDOW_P (f
));
19981 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
19982 it
.first_visible_x
= 0;
19983 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
19984 #else /* not USE_X_TOOLKIT */
19985 if (FRAME_WINDOW_P (f
))
19987 /* Menu bar lines are displayed in the desired matrix of the
19988 dummy window menu_bar_window. */
19989 struct window
*menu_w
;
19990 eassert (WINDOWP (f
->menu_bar_window
));
19991 menu_w
= XWINDOW (f
->menu_bar_window
);
19992 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
19994 it
.first_visible_x
= 0;
19995 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
19999 /* This is a TTY frame, i.e. character hpos/vpos are used as
20001 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
20003 it
.first_visible_x
= 0;
20004 it
.last_visible_x
= FRAME_COLS (f
);
20006 #endif /* not USE_X_TOOLKIT */
20008 /* FIXME: This should be controlled by a user option. See the
20009 comments in redisplay_tool_bar and display_mode_line about
20011 it
.paragraph_embedding
= L2R
;
20013 /* Clear all rows of the menu bar. */
20014 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
20016 struct glyph_row
*row
= it
.glyph_row
+ i
;
20017 clear_glyph_row (row
);
20018 row
->enabled_p
= 1;
20019 row
->full_width_p
= 1;
20022 /* Display all items of the menu bar. */
20023 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
20024 for (i
= 0; i
< ASIZE (items
); i
+= 4)
20026 Lisp_Object string
;
20028 /* Stop at nil string. */
20029 string
= AREF (items
, i
+ 1);
20033 /* Remember where item was displayed. */
20034 ASET (items
, i
+ 3, make_number (it
.hpos
));
20036 /* Display the item, pad with one space. */
20037 if (it
.current_x
< it
.last_visible_x
)
20038 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
20039 SCHARS (string
) + 1, 0, 0, -1);
20042 /* Fill out the line with spaces. */
20043 if (it
.current_x
< it
.last_visible_x
)
20044 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
20046 /* Compute the total height of the lines. */
20047 compute_line_metrics (&it
);
20052 /***********************************************************************
20054 ***********************************************************************/
20056 /* Redisplay mode lines in the window tree whose root is WINDOW. If
20057 FORCE is non-zero, redisplay mode lines unconditionally.
20058 Otherwise, redisplay only mode lines that are garbaged. Value is
20059 the number of windows whose mode lines were redisplayed. */
20062 redisplay_mode_lines (Lisp_Object window
, int force
)
20066 while (!NILP (window
))
20068 struct window
*w
= XWINDOW (window
);
20070 if (WINDOWP (w
->hchild
))
20071 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
20072 else if (WINDOWP (w
->vchild
))
20073 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
20075 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
20076 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
20078 struct text_pos lpoint
;
20079 struct buffer
*old
= current_buffer
;
20081 /* Set the window's buffer for the mode line display. */
20082 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
20083 set_buffer_internal_1 (XBUFFER (w
->buffer
));
20085 /* Point refers normally to the selected window. For any
20086 other window, set up appropriate value. */
20087 if (!EQ (window
, selected_window
))
20089 struct text_pos pt
;
20091 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
20092 if (CHARPOS (pt
) < BEGV
)
20093 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
20094 else if (CHARPOS (pt
) > (ZV
- 1))
20095 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
20097 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
20100 /* Display mode lines. */
20101 clear_glyph_matrix (w
->desired_matrix
);
20102 if (display_mode_lines (w
))
20105 w
->must_be_updated_p
= 1;
20108 /* Restore old settings. */
20109 set_buffer_internal_1 (old
);
20110 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
20120 /* Display the mode and/or header line of window W. Value is the
20121 sum number of mode lines and header lines displayed. */
20124 display_mode_lines (struct window
*w
)
20126 Lisp_Object old_selected_window
= selected_window
;
20127 Lisp_Object old_selected_frame
= selected_frame
;
20128 Lisp_Object new_frame
= w
->frame
;
20129 Lisp_Object old_frame_selected_window
= XFRAME (new_frame
)->selected_window
;
20132 selected_frame
= new_frame
;
20133 /* FIXME: If we were to allow the mode-line's computation changing the buffer
20134 or window's point, then we'd need select_window_1 here as well. */
20135 XSETWINDOW (selected_window
, w
);
20136 XFRAME (new_frame
)->selected_window
= selected_window
;
20138 /* These will be set while the mode line specs are processed. */
20139 line_number_displayed
= 0;
20140 w
->column_number_displayed
= -1;
20142 if (WINDOW_WANTS_MODELINE_P (w
))
20144 struct window
*sel_w
= XWINDOW (old_selected_window
);
20146 /* Select mode line face based on the real selected window. */
20147 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
20148 BVAR (current_buffer
, mode_line_format
));
20152 if (WINDOW_WANTS_HEADER_LINE_P (w
))
20154 display_mode_line (w
, HEADER_LINE_FACE_ID
,
20155 BVAR (current_buffer
, header_line_format
));
20159 XFRAME (new_frame
)->selected_window
= old_frame_selected_window
;
20160 selected_frame
= old_selected_frame
;
20161 selected_window
= old_selected_window
;
20166 /* Display mode or header line of window W. FACE_ID specifies which
20167 line to display; it is either MODE_LINE_FACE_ID or
20168 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
20169 display. Value is the pixel height of the mode/header line
20173 display_mode_line (struct window
*w
, enum face_id face_id
, Lisp_Object format
)
20177 ptrdiff_t count
= SPECPDL_INDEX ();
20179 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
20180 /* Don't extend on a previously drawn mode-line.
20181 This may happen if called from pos_visible_p. */
20182 it
.glyph_row
->enabled_p
= 0;
20183 prepare_desired_row (it
.glyph_row
);
20185 it
.glyph_row
->mode_line_p
= 1;
20187 /* FIXME: This should be controlled by a user option. But
20188 supporting such an option is not trivial, since the mode line is
20189 made up of many separate strings. */
20190 it
.paragraph_embedding
= L2R
;
20192 record_unwind_protect (unwind_format_mode_line
,
20193 format_mode_line_unwind_data (NULL
, NULL
, Qnil
, 0));
20195 mode_line_target
= MODE_LINE_DISPLAY
;
20197 /* Temporarily make frame's keyboard the current kboard so that
20198 kboard-local variables in the mode_line_format will get the right
20200 push_kboard (FRAME_KBOARD (it
.f
));
20201 record_unwind_save_match_data ();
20202 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
20205 unbind_to (count
, Qnil
);
20207 /* Fill up with spaces. */
20208 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
20210 compute_line_metrics (&it
);
20211 it
.glyph_row
->full_width_p
= 1;
20212 it
.glyph_row
->continued_p
= 0;
20213 it
.glyph_row
->truncated_on_left_p
= 0;
20214 it
.glyph_row
->truncated_on_right_p
= 0;
20216 /* Make a 3D mode-line have a shadow at its right end. */
20217 face
= FACE_FROM_ID (it
.f
, face_id
);
20218 extend_face_to_end_of_line (&it
);
20219 if (face
->box
!= FACE_NO_BOX
)
20221 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
20222 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
20223 last
->right_box_line_p
= 1;
20226 return it
.glyph_row
->height
;
20229 /* Move element ELT in LIST to the front of LIST.
20230 Return the updated list. */
20233 move_elt_to_front (Lisp_Object elt
, Lisp_Object list
)
20235 register Lisp_Object tail
, prev
;
20236 register Lisp_Object tem
;
20240 while (CONSP (tail
))
20246 /* Splice out the link TAIL. */
20248 list
= XCDR (tail
);
20250 Fsetcdr (prev
, XCDR (tail
));
20252 /* Now make it the first. */
20253 Fsetcdr (tail
, list
);
20258 tail
= XCDR (tail
);
20262 /* Not found--return unchanged LIST. */
20266 /* Contribute ELT to the mode line for window IT->w. How it
20267 translates into text depends on its data type.
20269 IT describes the display environment in which we display, as usual.
20271 DEPTH is the depth in recursion. It is used to prevent
20272 infinite recursion here.
20274 FIELD_WIDTH is the number of characters the display of ELT should
20275 occupy in the mode line, and PRECISION is the maximum number of
20276 characters to display from ELT's representation. See
20277 display_string for details.
20279 Returns the hpos of the end of the text generated by ELT.
20281 PROPS is a property list to add to any string we encounter.
20283 If RISKY is nonzero, remove (disregard) any properties in any string
20284 we encounter, and ignore :eval and :propertize.
20286 The global variable `mode_line_target' determines whether the
20287 output is passed to `store_mode_line_noprop',
20288 `store_mode_line_string', or `display_string'. */
20291 display_mode_element (struct it
*it
, int depth
, int field_width
, int precision
,
20292 Lisp_Object elt
, Lisp_Object props
, int risky
)
20294 int n
= 0, field
, prec
;
20299 elt
= build_string ("*too-deep*");
20303 switch (XTYPE (elt
))
20307 /* A string: output it and check for %-constructs within it. */
20309 ptrdiff_t offset
= 0;
20311 if (SCHARS (elt
) > 0
20312 && (!NILP (props
) || risky
))
20314 Lisp_Object oprops
, aelt
;
20315 oprops
= Ftext_properties_at (make_number (0), elt
);
20317 /* If the starting string's properties are not what
20318 we want, translate the string. Also, if the string
20319 is risky, do that anyway. */
20321 if (NILP (Fequal (props
, oprops
)) || risky
)
20323 /* If the starting string has properties,
20324 merge the specified ones onto the existing ones. */
20325 if (! NILP (oprops
) && !risky
)
20329 oprops
= Fcopy_sequence (oprops
);
20331 while (CONSP (tem
))
20333 oprops
= Fplist_put (oprops
, XCAR (tem
),
20334 XCAR (XCDR (tem
)));
20335 tem
= XCDR (XCDR (tem
));
20340 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
20341 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
20343 /* AELT is what we want. Move it to the front
20344 without consing. */
20346 mode_line_proptrans_alist
20347 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
20353 /* If AELT has the wrong props, it is useless.
20354 so get rid of it. */
20356 mode_line_proptrans_alist
20357 = Fdelq (aelt
, mode_line_proptrans_alist
);
20359 elt
= Fcopy_sequence (elt
);
20360 Fset_text_properties (make_number (0), Flength (elt
),
20362 /* Add this item to mode_line_proptrans_alist. */
20363 mode_line_proptrans_alist
20364 = Fcons (Fcons (elt
, props
),
20365 mode_line_proptrans_alist
);
20366 /* Truncate mode_line_proptrans_alist
20367 to at most 50 elements. */
20368 tem
= Fnthcdr (make_number (50),
20369 mode_line_proptrans_alist
);
20371 XSETCDR (tem
, Qnil
);
20380 prec
= precision
- n
;
20381 switch (mode_line_target
)
20383 case MODE_LINE_NOPROP
:
20384 case MODE_LINE_TITLE
:
20385 n
+= store_mode_line_noprop (SSDATA (elt
), -1, prec
);
20387 case MODE_LINE_STRING
:
20388 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
20390 case MODE_LINE_DISPLAY
:
20391 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
20392 0, prec
, 0, STRING_MULTIBYTE (elt
));
20399 /* Handle the non-literal case. */
20401 while ((precision
<= 0 || n
< precision
)
20402 && SREF (elt
, offset
) != 0
20403 && (mode_line_target
!= MODE_LINE_DISPLAY
20404 || it
->current_x
< it
->last_visible_x
))
20406 ptrdiff_t last_offset
= offset
;
20408 /* Advance to end of string or next format specifier. */
20409 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
20412 if (offset
- 1 != last_offset
)
20414 ptrdiff_t nchars
, nbytes
;
20416 /* Output to end of string or up to '%'. Field width
20417 is length of string. Don't output more than
20418 PRECISION allows us. */
20421 prec
= c_string_width (SDATA (elt
) + last_offset
,
20422 offset
- last_offset
, precision
- n
,
20425 switch (mode_line_target
)
20427 case MODE_LINE_NOPROP
:
20428 case MODE_LINE_TITLE
:
20429 n
+= store_mode_line_noprop (SSDATA (elt
) + last_offset
, 0, prec
);
20431 case MODE_LINE_STRING
:
20433 ptrdiff_t bytepos
= last_offset
;
20434 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
20435 ptrdiff_t endpos
= (precision
<= 0
20436 ? string_byte_to_char (elt
, offset
)
20437 : charpos
+ nchars
);
20439 n
+= store_mode_line_string (NULL
,
20440 Fsubstring (elt
, make_number (charpos
),
20441 make_number (endpos
)),
20445 case MODE_LINE_DISPLAY
:
20447 ptrdiff_t bytepos
= last_offset
;
20448 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
20450 if (precision
<= 0)
20451 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
20452 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
20454 STRING_MULTIBYTE (elt
));
20459 else /* c == '%' */
20461 ptrdiff_t percent_position
= offset
;
20463 /* Get the specified minimum width. Zero means
20466 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
20467 field
= field
* 10 + c
- '0';
20469 /* Don't pad beyond the total padding allowed. */
20470 if (field_width
- n
> 0 && field
> field_width
- n
)
20471 field
= field_width
- n
;
20473 /* Note that either PRECISION <= 0 or N < PRECISION. */
20474 prec
= precision
- n
;
20477 n
+= display_mode_element (it
, depth
, field
, prec
,
20478 Vglobal_mode_string
, props
,
20483 ptrdiff_t bytepos
, charpos
;
20485 Lisp_Object string
;
20487 bytepos
= percent_position
;
20488 charpos
= (STRING_MULTIBYTE (elt
)
20489 ? string_byte_to_char (elt
, bytepos
)
20491 spec
= decode_mode_spec (it
->w
, c
, field
, &string
);
20492 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
20494 switch (mode_line_target
)
20496 case MODE_LINE_NOPROP
:
20497 case MODE_LINE_TITLE
:
20498 n
+= store_mode_line_noprop (spec
, field
, prec
);
20500 case MODE_LINE_STRING
:
20502 Lisp_Object tem
= build_string (spec
);
20503 props
= Ftext_properties_at (make_number (charpos
), elt
);
20504 /* Should only keep face property in props */
20505 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
20508 case MODE_LINE_DISPLAY
:
20510 int nglyphs_before
, nwritten
;
20512 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
20513 nwritten
= display_string (spec
, string
, elt
,
20518 /* Assign to the glyphs written above the
20519 string where the `%x' came from, position
20523 struct glyph
*glyph
20524 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
20528 for (i
= 0; i
< nwritten
; ++i
)
20530 glyph
[i
].object
= elt
;
20531 glyph
[i
].charpos
= charpos
;
20548 /* A symbol: process the value of the symbol recursively
20549 as if it appeared here directly. Avoid error if symbol void.
20550 Special case: if value of symbol is a string, output the string
20553 register Lisp_Object tem
;
20555 /* If the variable is not marked as risky to set
20556 then its contents are risky to use. */
20557 if (NILP (Fget (elt
, Qrisky_local_variable
)))
20560 tem
= Fboundp (elt
);
20563 tem
= Fsymbol_value (elt
);
20564 /* If value is a string, output that string literally:
20565 don't check for % within it. */
20569 if (!EQ (tem
, elt
))
20571 /* Give up right away for nil or t. */
20581 register Lisp_Object car
, tem
;
20583 /* A cons cell: five distinct cases.
20584 If first element is :eval or :propertize, do something special.
20585 If first element is a string or a cons, process all the elements
20586 and effectively concatenate them.
20587 If first element is a negative number, truncate displaying cdr to
20588 at most that many characters. If positive, pad (with spaces)
20589 to at least that many characters.
20590 If first element is a symbol, process the cadr or caddr recursively
20591 according to whether the symbol's value is non-nil or nil. */
20593 if (EQ (car
, QCeval
))
20595 /* An element of the form (:eval FORM) means evaluate FORM
20596 and use the result as mode line elements. */
20601 if (CONSP (XCDR (elt
)))
20604 spec
= safe_eval (XCAR (XCDR (elt
)));
20605 n
+= display_mode_element (it
, depth
, field_width
- n
,
20606 precision
- n
, spec
, props
,
20610 else if (EQ (car
, QCpropertize
))
20612 /* An element of the form (:propertize ELT PROPS...)
20613 means display ELT but applying properties PROPS. */
20618 if (CONSP (XCDR (elt
)))
20619 n
+= display_mode_element (it
, depth
, field_width
- n
,
20620 precision
- n
, XCAR (XCDR (elt
)),
20621 XCDR (XCDR (elt
)), risky
);
20623 else if (SYMBOLP (car
))
20625 tem
= Fboundp (car
);
20629 /* elt is now the cdr, and we know it is a cons cell.
20630 Use its car if CAR has a non-nil value. */
20633 tem
= Fsymbol_value (car
);
20640 /* Symbol's value is nil (or symbol is unbound)
20641 Get the cddr of the original list
20642 and if possible find the caddr and use that. */
20646 else if (!CONSP (elt
))
20651 else if (INTEGERP (car
))
20653 register int lim
= XINT (car
);
20657 /* Negative int means reduce maximum width. */
20658 if (precision
<= 0)
20661 precision
= min (precision
, -lim
);
20665 /* Padding specified. Don't let it be more than
20666 current maximum. */
20668 lim
= min (precision
, lim
);
20670 /* If that's more padding than already wanted, queue it.
20671 But don't reduce padding already specified even if
20672 that is beyond the current truncation point. */
20673 field_width
= max (lim
, field_width
);
20677 else if (STRINGP (car
) || CONSP (car
))
20679 Lisp_Object halftail
= elt
;
20683 && (precision
<= 0 || n
< precision
))
20685 n
+= display_mode_element (it
, depth
,
20686 /* Do padding only after the last
20687 element in the list. */
20688 (! CONSP (XCDR (elt
))
20691 precision
- n
, XCAR (elt
),
20695 if ((len
& 1) == 0)
20696 halftail
= XCDR (halftail
);
20697 /* Check for cycle. */
20698 if (EQ (halftail
, elt
))
20707 elt
= build_string ("*invalid*");
20711 /* Pad to FIELD_WIDTH. */
20712 if (field_width
> 0 && n
< field_width
)
20714 switch (mode_line_target
)
20716 case MODE_LINE_NOPROP
:
20717 case MODE_LINE_TITLE
:
20718 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
20720 case MODE_LINE_STRING
:
20721 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
20723 case MODE_LINE_DISPLAY
:
20724 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
20733 /* Store a mode-line string element in mode_line_string_list.
20735 If STRING is non-null, display that C string. Otherwise, the Lisp
20736 string LISP_STRING is displayed.
20738 FIELD_WIDTH is the minimum number of output glyphs to produce.
20739 If STRING has fewer characters than FIELD_WIDTH, pad to the right
20740 with spaces. FIELD_WIDTH <= 0 means don't pad.
20742 PRECISION is the maximum number of characters to output from
20743 STRING. PRECISION <= 0 means don't truncate the string.
20745 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
20746 properties to the string.
20748 PROPS are the properties to add to the string.
20749 The mode_line_string_face face property is always added to the string.
20753 store_mode_line_string (const char *string
, Lisp_Object lisp_string
, int copy_string
,
20754 int field_width
, int precision
, Lisp_Object props
)
20759 if (string
!= NULL
)
20761 len
= strlen (string
);
20762 if (precision
> 0 && len
> precision
)
20764 lisp_string
= make_string (string
, len
);
20766 props
= mode_line_string_face_prop
;
20767 else if (!NILP (mode_line_string_face
))
20769 Lisp_Object face
= Fplist_get (props
, Qface
);
20770 props
= Fcopy_sequence (props
);
20772 face
= mode_line_string_face
;
20774 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
20775 props
= Fplist_put (props
, Qface
, face
);
20777 Fadd_text_properties (make_number (0), make_number (len
),
20778 props
, lisp_string
);
20782 len
= XFASTINT (Flength (lisp_string
));
20783 if (precision
> 0 && len
> precision
)
20786 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
20789 if (!NILP (mode_line_string_face
))
20793 props
= Ftext_properties_at (make_number (0), lisp_string
);
20794 face
= Fplist_get (props
, Qface
);
20796 face
= mode_line_string_face
;
20798 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
20799 props
= Fcons (Qface
, Fcons (face
, Qnil
));
20801 lisp_string
= Fcopy_sequence (lisp_string
);
20804 Fadd_text_properties (make_number (0), make_number (len
),
20805 props
, lisp_string
);
20810 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
20814 if (field_width
> len
)
20816 field_width
-= len
;
20817 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
20819 Fadd_text_properties (make_number (0), make_number (field_width
),
20820 props
, lisp_string
);
20821 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
20829 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
20831 doc
: /* Format a string out of a mode line format specification.
20832 First arg FORMAT specifies the mode line format (see `mode-line-format'
20833 for details) to use.
20835 By default, the format is evaluated for the currently selected window.
20837 Optional second arg FACE specifies the face property to put on all
20838 characters for which no face is specified. The value nil means the
20839 default face. The value t means whatever face the window's mode line
20840 currently uses (either `mode-line' or `mode-line-inactive',
20841 depending on whether the window is the selected window or not).
20842 An integer value means the value string has no text
20845 Optional third and fourth args WINDOW and BUFFER specify the window
20846 and buffer to use as the context for the formatting (defaults
20847 are the selected window and the WINDOW's buffer). */)
20848 (Lisp_Object format
, Lisp_Object face
,
20849 Lisp_Object window
, Lisp_Object buffer
)
20854 struct buffer
*old_buffer
= NULL
;
20856 int no_props
= INTEGERP (face
);
20857 ptrdiff_t count
= SPECPDL_INDEX ();
20859 int string_start
= 0;
20861 w
= decode_any_window (window
);
20862 XSETWINDOW (window
, w
);
20865 buffer
= w
->buffer
;
20866 CHECK_BUFFER (buffer
);
20868 /* Make formatting the modeline a non-op when noninteractive, otherwise
20869 there will be problems later caused by a partially initialized frame. */
20870 if (NILP (format
) || noninteractive
)
20871 return empty_unibyte_string
;
20876 face_id
= (NILP (face
) || EQ (face
, Qdefault
)) ? DEFAULT_FACE_ID
20877 : EQ (face
, Qt
) ? (EQ (window
, selected_window
)
20878 ? MODE_LINE_FACE_ID
: MODE_LINE_INACTIVE_FACE_ID
)
20879 : EQ (face
, Qmode_line
) ? MODE_LINE_FACE_ID
20880 : EQ (face
, Qmode_line_inactive
) ? MODE_LINE_INACTIVE_FACE_ID
20881 : EQ (face
, Qheader_line
) ? HEADER_LINE_FACE_ID
20882 : EQ (face
, Qtool_bar
) ? TOOL_BAR_FACE_ID
20885 old_buffer
= current_buffer
;
20887 /* Save things including mode_line_proptrans_alist,
20888 and set that to nil so that we don't alter the outer value. */
20889 record_unwind_protect (unwind_format_mode_line
,
20890 format_mode_line_unwind_data
20891 (XFRAME (WINDOW_FRAME (w
)),
20892 old_buffer
, selected_window
, 1));
20893 mode_line_proptrans_alist
= Qnil
;
20895 Fselect_window (window
, Qt
);
20896 set_buffer_internal_1 (XBUFFER (buffer
));
20898 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
20902 mode_line_target
= MODE_LINE_NOPROP
;
20903 mode_line_string_face_prop
= Qnil
;
20904 mode_line_string_list
= Qnil
;
20905 string_start
= MODE_LINE_NOPROP_LEN (0);
20909 mode_line_target
= MODE_LINE_STRING
;
20910 mode_line_string_list
= Qnil
;
20911 mode_line_string_face
= face
;
20912 mode_line_string_face_prop
20913 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
20916 push_kboard (FRAME_KBOARD (it
.f
));
20917 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
20922 len
= MODE_LINE_NOPROP_LEN (string_start
);
20923 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
20927 mode_line_string_list
= Fnreverse (mode_line_string_list
);
20928 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
20929 empty_unibyte_string
);
20932 unbind_to (count
, Qnil
);
20936 /* Write a null-terminated, right justified decimal representation of
20937 the positive integer D to BUF using a minimal field width WIDTH. */
20940 pint2str (register char *buf
, register int width
, register ptrdiff_t d
)
20942 register char *p
= buf
;
20950 *p
++ = d
% 10 + '0';
20955 for (width
-= (int) (p
- buf
); width
> 0; --width
)
20966 /* Write a null-terminated, right justified decimal and "human
20967 readable" representation of the nonnegative integer D to BUF using
20968 a minimal field width WIDTH. D should be smaller than 999.5e24. */
20970 static const char power_letter
[] =
20984 pint2hrstr (char *buf
, int width
, ptrdiff_t d
)
20986 /* We aim to represent the nonnegative integer D as
20987 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
20988 ptrdiff_t quotient
= d
;
20990 /* -1 means: do not use TENTHS. */
20994 /* Length of QUOTIENT.TENTHS as a string. */
21000 if (1000 <= quotient
)
21002 /* Scale to the appropriate EXPONENT. */
21005 remainder
= quotient
% 1000;
21009 while (1000 <= quotient
);
21011 /* Round to nearest and decide whether to use TENTHS or not. */
21014 tenths
= remainder
/ 100;
21015 if (50 <= remainder
% 100)
21022 if (quotient
== 10)
21030 if (500 <= remainder
)
21032 if (quotient
< 999)
21043 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
21044 if (tenths
== -1 && quotient
<= 99)
21051 p
= psuffix
= buf
+ max (width
, length
);
21053 /* Print EXPONENT. */
21054 *psuffix
++ = power_letter
[exponent
];
21057 /* Print TENTHS. */
21060 *--p
= '0' + tenths
;
21064 /* Print QUOTIENT. */
21067 int digit
= quotient
% 10;
21068 *--p
= '0' + digit
;
21070 while ((quotient
/= 10) != 0);
21072 /* Print leading spaces. */
21077 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
21078 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
21079 type of CODING_SYSTEM. Return updated pointer into BUF. */
21081 static unsigned char invalid_eol_type
[] = "(*invalid*)";
21084 decode_mode_spec_coding (Lisp_Object coding_system
, register char *buf
, int eol_flag
)
21087 int multibyte
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
21088 const unsigned char *eol_str
;
21090 /* The EOL conversion we are using. */
21091 Lisp_Object eoltype
;
21093 val
= CODING_SYSTEM_SPEC (coding_system
);
21096 if (!VECTORP (val
)) /* Not yet decided. */
21098 *buf
++ = multibyte
? '-' : ' ';
21100 eoltype
= eol_mnemonic_undecided
;
21101 /* Don't mention EOL conversion if it isn't decided. */
21106 Lisp_Object eolvalue
;
21108 attrs
= AREF (val
, 0);
21109 eolvalue
= AREF (val
, 2);
21112 ? XFASTINT (CODING_ATTR_MNEMONIC (attrs
))
21117 /* The EOL conversion that is normal on this system. */
21119 if (NILP (eolvalue
)) /* Not yet decided. */
21120 eoltype
= eol_mnemonic_undecided
;
21121 else if (VECTORP (eolvalue
)) /* Not yet decided. */
21122 eoltype
= eol_mnemonic_undecided
;
21123 else /* eolvalue is Qunix, Qdos, or Qmac. */
21124 eoltype
= (EQ (eolvalue
, Qunix
)
21125 ? eol_mnemonic_unix
21126 : (EQ (eolvalue
, Qdos
) == 1
21127 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
21133 /* Mention the EOL conversion if it is not the usual one. */
21134 if (STRINGP (eoltype
))
21136 eol_str
= SDATA (eoltype
);
21137 eol_str_len
= SBYTES (eoltype
);
21139 else if (CHARACTERP (eoltype
))
21141 unsigned char *tmp
= alloca (MAX_MULTIBYTE_LENGTH
);
21142 int c
= XFASTINT (eoltype
);
21143 eol_str_len
= CHAR_STRING (c
, tmp
);
21148 eol_str
= invalid_eol_type
;
21149 eol_str_len
= sizeof (invalid_eol_type
) - 1;
21151 memcpy (buf
, eol_str
, eol_str_len
);
21152 buf
+= eol_str_len
;
21158 /* Return a string for the output of a mode line %-spec for window W,
21159 generated by character C. FIELD_WIDTH > 0 means pad the string
21160 returned with spaces to that value. Return a Lisp string in
21161 *STRING if the resulting string is taken from that Lisp string.
21163 Note we operate on the current buffer for most purposes. */
21165 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
21167 static const char *
21168 decode_mode_spec (struct window
*w
, register int c
, int field_width
,
21169 Lisp_Object
*string
)
21172 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21173 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
21174 /* We are going to use f->decode_mode_spec_buffer as the buffer to
21175 produce strings from numerical values, so limit preposterously
21176 large values of FIELD_WIDTH to avoid overrunning the buffer's
21177 end. The size of the buffer is enough for FRAME_MESSAGE_BUF_SIZE
21178 bytes plus the terminating null. */
21179 int width
= min (field_width
, FRAME_MESSAGE_BUF_SIZE (f
));
21180 struct buffer
*b
= current_buffer
;
21188 if (!NILP (BVAR (b
, read_only
)))
21190 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21195 /* This differs from %* only for a modified read-only buffer. */
21196 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21198 if (!NILP (BVAR (b
, read_only
)))
21203 /* This differs from %* in ignoring read-only-ness. */
21204 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21216 if (command_loop_level
> 5)
21218 p
= decode_mode_spec_buf
;
21219 for (i
= 0; i
< command_loop_level
; i
++)
21222 return decode_mode_spec_buf
;
21230 if (command_loop_level
> 5)
21232 p
= decode_mode_spec_buf
;
21233 for (i
= 0; i
< command_loop_level
; i
++)
21236 return decode_mode_spec_buf
;
21243 /* Let lots_of_dashes be a string of infinite length. */
21244 if (mode_line_target
== MODE_LINE_NOPROP
21245 || mode_line_target
== MODE_LINE_STRING
)
21247 if (field_width
<= 0
21248 || field_width
> sizeof (lots_of_dashes
))
21250 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
21251 decode_mode_spec_buf
[i
] = '-';
21252 decode_mode_spec_buf
[i
] = '\0';
21253 return decode_mode_spec_buf
;
21256 return lots_of_dashes
;
21260 obj
= BVAR (b
, name
);
21264 /* %c and %l are ignored in `frame-title-format'.
21265 (In redisplay_internal, the frame title is drawn _before_ the
21266 windows are updated, so the stuff which depends on actual
21267 window contents (such as %l) may fail to render properly, or
21268 even crash emacs.) */
21269 if (mode_line_target
== MODE_LINE_TITLE
)
21273 ptrdiff_t col
= current_column ();
21274 w
->column_number_displayed
= col
;
21275 pint2str (decode_mode_spec_buf
, width
, col
);
21276 return decode_mode_spec_buf
;
21280 #ifndef SYSTEM_MALLOC
21282 if (NILP (Vmemory_full
))
21285 return "!MEM FULL! ";
21292 /* %F displays the frame name. */
21293 if (!NILP (f
->title
))
21294 return SSDATA (f
->title
);
21295 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
21296 return SSDATA (f
->name
);
21300 obj
= BVAR (b
, filename
);
21305 ptrdiff_t size
= ZV
- BEGV
;
21306 pint2str (decode_mode_spec_buf
, width
, size
);
21307 return decode_mode_spec_buf
;
21312 ptrdiff_t size
= ZV
- BEGV
;
21313 pint2hrstr (decode_mode_spec_buf
, width
, size
);
21314 return decode_mode_spec_buf
;
21319 ptrdiff_t startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
21320 ptrdiff_t topline
, nlines
, height
;
21323 /* %c and %l are ignored in `frame-title-format'. */
21324 if (mode_line_target
== MODE_LINE_TITLE
)
21327 startpos
= marker_position (w
->start
);
21328 startpos_byte
= marker_byte_position (w
->start
);
21329 height
= WINDOW_TOTAL_LINES (w
);
21331 /* If we decided that this buffer isn't suitable for line numbers,
21332 don't forget that too fast. */
21333 if (w
->base_line_pos
== -1)
21336 /* If the buffer is very big, don't waste time. */
21337 if (INTEGERP (Vline_number_display_limit
)
21338 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
21340 w
->base_line_pos
= 0;
21341 w
->base_line_number
= 0;
21345 if (w
->base_line_number
> 0
21346 && w
->base_line_pos
> 0
21347 && w
->base_line_pos
<= startpos
)
21349 line
= w
->base_line_number
;
21350 linepos
= w
->base_line_pos
;
21351 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
21356 linepos
= BUF_BEGV (b
);
21357 linepos_byte
= BUF_BEGV_BYTE (b
);
21360 /* Count lines from base line to window start position. */
21361 nlines
= display_count_lines (linepos_byte
,
21365 topline
= nlines
+ line
;
21367 /* Determine a new base line, if the old one is too close
21368 or too far away, or if we did not have one.
21369 "Too close" means it's plausible a scroll-down would
21370 go back past it. */
21371 if (startpos
== BUF_BEGV (b
))
21373 w
->base_line_number
= topline
;
21374 w
->base_line_pos
= BUF_BEGV (b
);
21376 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
21377 || linepos
== BUF_BEGV (b
))
21379 ptrdiff_t limit
= BUF_BEGV (b
);
21380 ptrdiff_t limit_byte
= BUF_BEGV_BYTE (b
);
21381 ptrdiff_t position
;
21382 ptrdiff_t distance
=
21383 (height
* 2 + 30) * line_number_display_limit_width
;
21385 if (startpos
- distance
> limit
)
21387 limit
= startpos
- distance
;
21388 limit_byte
= CHAR_TO_BYTE (limit
);
21391 nlines
= display_count_lines (startpos_byte
,
21393 - (height
* 2 + 30),
21395 /* If we couldn't find the lines we wanted within
21396 line_number_display_limit_width chars per line,
21397 give up on line numbers for this window. */
21398 if (position
== limit_byte
&& limit
== startpos
- distance
)
21400 w
->base_line_pos
= -1;
21401 w
->base_line_number
= 0;
21405 w
->base_line_number
= topline
- nlines
;
21406 w
->base_line_pos
= BYTE_TO_CHAR (position
);
21409 /* Now count lines from the start pos to point. */
21410 nlines
= display_count_lines (startpos_byte
,
21411 PT_BYTE
, PT
, &junk
);
21413 /* Record that we did display the line number. */
21414 line_number_displayed
= 1;
21416 /* Make the string to show. */
21417 pint2str (decode_mode_spec_buf
, width
, topline
+ nlines
);
21418 return decode_mode_spec_buf
;
21421 char* p
= decode_mode_spec_buf
;
21422 int pad
= width
- 2;
21428 return decode_mode_spec_buf
;
21434 obj
= BVAR (b
, mode_name
);
21438 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
21444 ptrdiff_t pos
= marker_position (w
->start
);
21445 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
21447 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
21449 if (pos
<= BUF_BEGV (b
))
21454 else if (pos
<= BUF_BEGV (b
))
21458 if (total
> 1000000)
21459 /* Do it differently for a large value, to avoid overflow. */
21460 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
21462 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
21463 /* We can't normally display a 3-digit number,
21464 so get us a 2-digit number that is close. */
21467 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
21468 return decode_mode_spec_buf
;
21472 /* Display percentage of size above the bottom of the screen. */
21475 ptrdiff_t toppos
= marker_position (w
->start
);
21476 ptrdiff_t botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
21477 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
21479 if (botpos
>= BUF_ZV (b
))
21481 if (toppos
<= BUF_BEGV (b
))
21488 if (total
> 1000000)
21489 /* Do it differently for a large value, to avoid overflow. */
21490 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
21492 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
21493 /* We can't normally display a 3-digit number,
21494 so get us a 2-digit number that is close. */
21497 if (toppos
<= BUF_BEGV (b
))
21498 sprintf (decode_mode_spec_buf
, "Top%2"pD
"d%%", total
);
21500 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
21501 return decode_mode_spec_buf
;
21506 /* status of process */
21507 obj
= Fget_buffer_process (Fcurrent_buffer ());
21509 return "no process";
21511 obj
= Fsymbol_name (Fprocess_status (obj
));
21517 ptrdiff_t count
= inhibit_garbage_collection ();
21518 Lisp_Object val
= call1 (intern ("file-remote-p"),
21519 BVAR (current_buffer
, directory
));
21520 unbind_to (count
, Qnil
);
21528 case 't': /* indicate TEXT or BINARY */
21532 /* coding-system (not including end-of-line format) */
21534 /* coding-system (including end-of-line type) */
21536 int eol_flag
= (c
== 'Z');
21537 char *p
= decode_mode_spec_buf
;
21539 if (! FRAME_WINDOW_P (f
))
21541 /* No need to mention EOL here--the terminal never needs
21542 to do EOL conversion. */
21543 p
= decode_mode_spec_coding (CODING_ID_NAME
21544 (FRAME_KEYBOARD_CODING (f
)->id
),
21546 p
= decode_mode_spec_coding (CODING_ID_NAME
21547 (FRAME_TERMINAL_CODING (f
)->id
),
21550 p
= decode_mode_spec_coding (BVAR (b
, buffer_file_coding_system
),
21553 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
21554 #ifdef subprocesses
21555 obj
= Fget_buffer_process (Fcurrent_buffer ());
21556 if (PROCESSP (obj
))
21558 p
= decode_mode_spec_coding
21559 (XPROCESS (obj
)->decode_coding_system
, p
, eol_flag
);
21560 p
= decode_mode_spec_coding
21561 (XPROCESS (obj
)->encode_coding_system
, p
, eol_flag
);
21563 #endif /* subprocesses */
21566 return decode_mode_spec_buf
;
21573 return SSDATA (obj
);
21580 /* Count up to COUNT lines starting from START_BYTE.
21581 But don't go beyond LIMIT_BYTE.
21582 Return the number of lines thus found (always nonnegative).
21584 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
21587 display_count_lines (ptrdiff_t start_byte
,
21588 ptrdiff_t limit_byte
, ptrdiff_t count
,
21589 ptrdiff_t *byte_pos_ptr
)
21591 register unsigned char *cursor
;
21592 unsigned char *base
;
21594 register ptrdiff_t ceiling
;
21595 register unsigned char *ceiling_addr
;
21596 ptrdiff_t orig_count
= count
;
21598 /* If we are not in selective display mode,
21599 check only for newlines. */
21600 int selective_display
= (!NILP (BVAR (current_buffer
, selective_display
))
21601 && !INTEGERP (BVAR (current_buffer
, selective_display
)));
21605 while (start_byte
< limit_byte
)
21607 ceiling
= BUFFER_CEILING_OF (start_byte
);
21608 ceiling
= min (limit_byte
- 1, ceiling
);
21609 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
21610 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
21613 if (selective_display
)
21614 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
21617 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
21620 if (cursor
!= ceiling_addr
)
21624 start_byte
+= cursor
- base
+ 1;
21625 *byte_pos_ptr
= start_byte
;
21629 if (++cursor
== ceiling_addr
)
21635 start_byte
+= cursor
- base
;
21640 while (start_byte
> limit_byte
)
21642 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
21643 ceiling
= max (limit_byte
, ceiling
);
21644 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
21645 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
21648 if (selective_display
)
21649 while (--cursor
!= ceiling_addr
21650 && *cursor
!= '\n' && *cursor
!= 015)
21653 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
21656 if (cursor
!= ceiling_addr
)
21660 start_byte
+= cursor
- base
+ 1;
21661 *byte_pos_ptr
= start_byte
;
21662 /* When scanning backwards, we should
21663 not count the newline posterior to which we stop. */
21664 return - orig_count
- 1;
21670 /* Here we add 1 to compensate for the last decrement
21671 of CURSOR, which took it past the valid range. */
21672 start_byte
+= cursor
- base
+ 1;
21676 *byte_pos_ptr
= limit_byte
;
21679 return - orig_count
+ count
;
21680 return orig_count
- count
;
21686 /***********************************************************************
21688 ***********************************************************************/
21690 /* Display a NUL-terminated string, starting with index START.
21692 If STRING is non-null, display that C string. Otherwise, the Lisp
21693 string LISP_STRING is displayed. There's a case that STRING is
21694 non-null and LISP_STRING is not nil. It means STRING is a string
21695 data of LISP_STRING. In that case, we display LISP_STRING while
21696 ignoring its text properties.
21698 If FACE_STRING is not nil, FACE_STRING_POS is a position in
21699 FACE_STRING. Display STRING or LISP_STRING with the face at
21700 FACE_STRING_POS in FACE_STRING:
21702 Display the string in the environment given by IT, but use the
21703 standard display table, temporarily.
21705 FIELD_WIDTH is the minimum number of output glyphs to produce.
21706 If STRING has fewer characters than FIELD_WIDTH, pad to the right
21707 with spaces. If STRING has more characters, more than FIELD_WIDTH
21708 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
21710 PRECISION is the maximum number of characters to output from
21711 STRING. PRECISION < 0 means don't truncate the string.
21713 This is roughly equivalent to printf format specifiers:
21715 FIELD_WIDTH PRECISION PRINTF
21716 ----------------------------------------
21722 MULTIBYTE zero means do not display multibyte chars, > 0 means do
21723 display them, and < 0 means obey the current buffer's value of
21724 enable_multibyte_characters.
21726 Value is the number of columns displayed. */
21729 display_string (const char *string
, Lisp_Object lisp_string
, Lisp_Object face_string
,
21730 ptrdiff_t face_string_pos
, ptrdiff_t start
, struct it
*it
,
21731 int field_width
, int precision
, int max_x
, int multibyte
)
21733 int hpos_at_start
= it
->hpos
;
21734 int saved_face_id
= it
->face_id
;
21735 struct glyph_row
*row
= it
->glyph_row
;
21736 ptrdiff_t it_charpos
;
21738 /* Initialize the iterator IT for iteration over STRING beginning
21739 with index START. */
21740 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
21741 precision
, field_width
, multibyte
);
21742 if (string
&& STRINGP (lisp_string
))
21743 /* LISP_STRING is the one returned by decode_mode_spec. We should
21744 ignore its text properties. */
21745 it
->stop_charpos
= it
->end_charpos
;
21747 /* If displaying STRING, set up the face of the iterator from
21748 FACE_STRING, if that's given. */
21749 if (STRINGP (face_string
))
21755 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
21756 0, it
->region_beg_charpos
,
21757 it
->region_end_charpos
,
21758 &endptr
, it
->base_face_id
, 0);
21759 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21760 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
21763 /* Set max_x to the maximum allowed X position. Don't let it go
21764 beyond the right edge of the window. */
21766 max_x
= it
->last_visible_x
;
21768 max_x
= min (max_x
, it
->last_visible_x
);
21770 /* Skip over display elements that are not visible. because IT->w is
21772 if (it
->current_x
< it
->first_visible_x
)
21773 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
21774 MOVE_TO_POS
| MOVE_TO_X
);
21776 row
->ascent
= it
->max_ascent
;
21777 row
->height
= it
->max_ascent
+ it
->max_descent
;
21778 row
->phys_ascent
= it
->max_phys_ascent
;
21779 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
21780 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
21782 if (STRINGP (it
->string
))
21783 it_charpos
= IT_STRING_CHARPOS (*it
);
21785 it_charpos
= IT_CHARPOS (*it
);
21787 /* This condition is for the case that we are called with current_x
21788 past last_visible_x. */
21789 while (it
->current_x
< max_x
)
21791 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
21793 /* Get the next display element. */
21794 if (!get_next_display_element (it
))
21797 /* Produce glyphs. */
21798 x_before
= it
->current_x
;
21799 n_glyphs_before
= row
->used
[TEXT_AREA
];
21800 PRODUCE_GLYPHS (it
);
21802 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
21805 while (i
< nglyphs
)
21807 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
21809 if (it
->line_wrap
!= TRUNCATE
21810 && x
+ glyph
->pixel_width
> max_x
)
21812 /* End of continued line or max_x reached. */
21813 if (CHAR_GLYPH_PADDING_P (*glyph
))
21815 /* A wide character is unbreakable. */
21816 if (row
->reversed_p
)
21817 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
21818 - n_glyphs_before
);
21819 row
->used
[TEXT_AREA
] = n_glyphs_before
;
21820 it
->current_x
= x_before
;
21824 if (row
->reversed_p
)
21825 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
21826 - (n_glyphs_before
+ i
));
21827 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
21832 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
21834 /* Glyph is at least partially visible. */
21836 if (x
< it
->first_visible_x
)
21837 row
->x
= x
- it
->first_visible_x
;
21841 /* Glyph is off the left margin of the display area.
21842 Should not happen. */
21846 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
21847 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
21848 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
21849 row
->phys_height
= max (row
->phys_height
,
21850 it
->max_phys_ascent
+ it
->max_phys_descent
);
21851 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
21852 it
->max_extra_line_spacing
);
21853 x
+= glyph
->pixel_width
;
21857 /* Stop if max_x reached. */
21861 /* Stop at line ends. */
21862 if (ITERATOR_AT_END_OF_LINE_P (it
))
21864 it
->continuation_lines_width
= 0;
21868 set_iterator_to_next (it
, 1);
21869 if (STRINGP (it
->string
))
21870 it_charpos
= IT_STRING_CHARPOS (*it
);
21872 it_charpos
= IT_CHARPOS (*it
);
21874 /* Stop if truncating at the right edge. */
21875 if (it
->line_wrap
== TRUNCATE
21876 && it
->current_x
>= it
->last_visible_x
)
21878 /* Add truncation mark, but don't do it if the line is
21879 truncated at a padding space. */
21880 if (it_charpos
< it
->string_nchars
)
21882 if (!FRAME_WINDOW_P (it
->f
))
21886 if (it
->current_x
> it
->last_visible_x
)
21888 if (!row
->reversed_p
)
21890 for (ii
= row
->used
[TEXT_AREA
] - 1; ii
> 0; --ii
)
21891 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
21896 for (ii
= 0; ii
< row
->used
[TEXT_AREA
]; ii
++)
21897 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
21899 unproduce_glyphs (it
, ii
+ 1);
21900 ii
= row
->used
[TEXT_AREA
] - (ii
+ 1);
21902 for (n
= row
->used
[TEXT_AREA
]; ii
< n
; ++ii
)
21904 row
->used
[TEXT_AREA
] = ii
;
21905 produce_special_glyphs (it
, IT_TRUNCATION
);
21908 produce_special_glyphs (it
, IT_TRUNCATION
);
21910 row
->truncated_on_right_p
= 1;
21916 /* Maybe insert a truncation at the left. */
21917 if (it
->first_visible_x
21920 if (!FRAME_WINDOW_P (it
->f
)
21921 || (row
->reversed_p
21922 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
21923 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
21924 insert_left_trunc_glyphs (it
);
21925 row
->truncated_on_left_p
= 1;
21928 it
->face_id
= saved_face_id
;
21930 /* Value is number of columns displayed. */
21931 return it
->hpos
- hpos_at_start
;
21936 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
21937 appears as an element of LIST or as the car of an element of LIST.
21938 If PROPVAL is a list, compare each element against LIST in that
21939 way, and return 1/2 if any element of PROPVAL is found in LIST.
21940 Otherwise return 0. This function cannot quit.
21941 The return value is 2 if the text is invisible but with an ellipsis
21942 and 1 if it's invisible and without an ellipsis. */
21945 invisible_p (register Lisp_Object propval
, Lisp_Object list
)
21947 register Lisp_Object tail
, proptail
;
21949 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
21951 register Lisp_Object tem
;
21953 if (EQ (propval
, tem
))
21955 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
21956 return NILP (XCDR (tem
)) ? 1 : 2;
21959 if (CONSP (propval
))
21961 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
21963 Lisp_Object propelt
;
21964 propelt
= XCAR (proptail
);
21965 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
21967 register Lisp_Object tem
;
21969 if (EQ (propelt
, tem
))
21971 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
21972 return NILP (XCDR (tem
)) ? 1 : 2;
21980 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
21981 doc
: /* Non-nil if the property makes the text invisible.
21982 POS-OR-PROP can be a marker or number, in which case it is taken to be
21983 a position in the current buffer and the value of the `invisible' property
21984 is checked; or it can be some other value, which is then presumed to be the
21985 value of the `invisible' property of the text of interest.
21986 The non-nil value returned can be t for truly invisible text or something
21987 else if the text is replaced by an ellipsis. */)
21988 (Lisp_Object pos_or_prop
)
21991 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
21992 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
21994 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
21995 return (invis
== 0 ? Qnil
21997 : make_number (invis
));
22000 /* Calculate a width or height in pixels from a specification using
22001 the following elements:
22004 NUM - a (fractional) multiple of the default font width/height
22005 (NUM) - specifies exactly NUM pixels
22006 UNIT - a fixed number of pixels, see below.
22007 ELEMENT - size of a display element in pixels, see below.
22008 (NUM . SPEC) - equals NUM * SPEC
22009 (+ SPEC SPEC ...) - add pixel values
22010 (- SPEC SPEC ...) - subtract pixel values
22011 (- SPEC) - negate pixel value
22014 INT or FLOAT - a number constant
22015 SYMBOL - use symbol's (buffer local) variable binding.
22018 in - pixels per inch *)
22019 mm - pixels per 1/1000 meter *)
22020 cm - pixels per 1/100 meter *)
22021 width - width of current font in pixels.
22022 height - height of current font in pixels.
22024 *) using the ratio(s) defined in display-pixels-per-inch.
22028 left-fringe - left fringe width in pixels
22029 right-fringe - right fringe width in pixels
22031 left-margin - left margin width in pixels
22032 right-margin - right margin width in pixels
22034 scroll-bar - scroll-bar area width in pixels
22038 Pixels corresponding to 5 inches:
22041 Total width of non-text areas on left side of window (if scroll-bar is on left):
22042 '(space :width (+ left-fringe left-margin scroll-bar))
22044 Align to first text column (in header line):
22045 '(space :align-to 0)
22047 Align to middle of text area minus half the width of variable `my-image'
22048 containing a loaded image:
22049 '(space :align-to (0.5 . (- text my-image)))
22051 Width of left margin minus width of 1 character in the default font:
22052 '(space :width (- left-margin 1))
22054 Width of left margin minus width of 2 characters in the current font:
22055 '(space :width (- left-margin (2 . width)))
22057 Center 1 character over left-margin (in header line):
22058 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
22060 Different ways to express width of left fringe plus left margin minus one pixel:
22061 '(space :width (- (+ left-fringe left-margin) (1)))
22062 '(space :width (+ left-fringe left-margin (- (1))))
22063 '(space :width (+ left-fringe left-margin (-1)))
22067 #define NUMVAL(X) \
22068 ((INTEGERP (X) || FLOATP (X)) \
22073 calc_pixel_width_or_height (double *res
, struct it
*it
, Lisp_Object prop
,
22074 struct font
*font
, int width_p
, int *align_to
)
22078 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
22079 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
22082 return OK_PIXELS (0);
22084 eassert (FRAME_LIVE_P (it
->f
));
22086 if (SYMBOLP (prop
))
22088 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
22090 char *unit
= SSDATA (SYMBOL_NAME (prop
));
22092 if (unit
[0] == 'i' && unit
[1] == 'n')
22094 else if (unit
[0] == 'm' && unit
[1] == 'm')
22096 else if (unit
[0] == 'c' && unit
[1] == 'm')
22103 #ifdef HAVE_WINDOW_SYSTEM
22104 if (FRAME_WINDOW_P (it
->f
)
22106 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
22107 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
22109 return OK_PIXELS (ppi
/ pixels
);
22112 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
22113 || (CONSP (Vdisplay_pixels_per_inch
)
22115 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
22116 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
22118 return OK_PIXELS (ppi
/ pixels
);
22124 #ifdef HAVE_WINDOW_SYSTEM
22125 if (EQ (prop
, Qheight
))
22126 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
22127 if (EQ (prop
, Qwidth
))
22128 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
22130 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
22131 return OK_PIXELS (1);
22134 if (EQ (prop
, Qtext
))
22135 return OK_PIXELS (width_p
22136 ? window_box_width (it
->w
, TEXT_AREA
)
22137 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
22139 if (align_to
&& *align_to
< 0)
22142 if (EQ (prop
, Qleft
))
22143 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
22144 if (EQ (prop
, Qright
))
22145 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
22146 if (EQ (prop
, Qcenter
))
22147 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
22148 + window_box_width (it
->w
, TEXT_AREA
) / 2);
22149 if (EQ (prop
, Qleft_fringe
))
22150 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22151 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
22152 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
22153 if (EQ (prop
, Qright_fringe
))
22154 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22155 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
22156 : window_box_right_offset (it
->w
, TEXT_AREA
));
22157 if (EQ (prop
, Qleft_margin
))
22158 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
22159 if (EQ (prop
, Qright_margin
))
22160 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
22161 if (EQ (prop
, Qscroll_bar
))
22162 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
22164 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
22165 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22166 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
22171 if (EQ (prop
, Qleft_fringe
))
22172 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
22173 if (EQ (prop
, Qright_fringe
))
22174 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
22175 if (EQ (prop
, Qleft_margin
))
22176 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
22177 if (EQ (prop
, Qright_margin
))
22178 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
22179 if (EQ (prop
, Qscroll_bar
))
22180 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
22183 prop
= buffer_local_value_1 (prop
, it
->w
->buffer
);
22184 if (EQ (prop
, Qunbound
))
22188 if (INTEGERP (prop
) || FLOATP (prop
))
22190 int base_unit
= (width_p
22191 ? FRAME_COLUMN_WIDTH (it
->f
)
22192 : FRAME_LINE_HEIGHT (it
->f
));
22193 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
22198 Lisp_Object car
= XCAR (prop
);
22199 Lisp_Object cdr
= XCDR (prop
);
22203 #ifdef HAVE_WINDOW_SYSTEM
22204 if (FRAME_WINDOW_P (it
->f
)
22205 && valid_image_p (prop
))
22207 ptrdiff_t id
= lookup_image (it
->f
, prop
);
22208 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
22210 return OK_PIXELS (width_p
? img
->width
: img
->height
);
22213 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
22219 while (CONSP (cdr
))
22221 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
22222 font
, width_p
, align_to
))
22225 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
22230 if (EQ (car
, Qminus
))
22232 return OK_PIXELS (pixels
);
22235 car
= buffer_local_value_1 (car
, it
->w
->buffer
);
22236 if (EQ (car
, Qunbound
))
22240 if (INTEGERP (car
) || FLOATP (car
))
22243 pixels
= XFLOATINT (car
);
22245 return OK_PIXELS (pixels
);
22246 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
22247 font
, width_p
, align_to
))
22248 return OK_PIXELS (pixels
* fact
);
22259 /***********************************************************************
22261 ***********************************************************************/
22263 #ifdef HAVE_WINDOW_SYSTEM
22268 dump_glyph_string (struct glyph_string
*s
)
22270 fprintf (stderr
, "glyph string\n");
22271 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
22272 s
->x
, s
->y
, s
->width
, s
->height
);
22273 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
22274 fprintf (stderr
, " hl = %d\n", s
->hl
);
22275 fprintf (stderr
, " left overhang = %d, right = %d\n",
22276 s
->left_overhang
, s
->right_overhang
);
22277 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
22278 fprintf (stderr
, " extends to end of line = %d\n",
22279 s
->extends_to_end_of_line_p
);
22280 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
22281 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
22284 #endif /* GLYPH_DEBUG */
22286 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
22287 of XChar2b structures for S; it can't be allocated in
22288 init_glyph_string because it must be allocated via `alloca'. W
22289 is the window on which S is drawn. ROW and AREA are the glyph row
22290 and area within the row from which S is constructed. START is the
22291 index of the first glyph structure covered by S. HL is a
22292 face-override for drawing S. */
22295 #define OPTIONAL_HDC(hdc) HDC hdc,
22296 #define DECLARE_HDC(hdc) HDC hdc;
22297 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
22298 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
22301 #ifndef OPTIONAL_HDC
22302 #define OPTIONAL_HDC(hdc)
22303 #define DECLARE_HDC(hdc)
22304 #define ALLOCATE_HDC(hdc, f)
22305 #define RELEASE_HDC(hdc, f)
22309 init_glyph_string (struct glyph_string
*s
,
22311 XChar2b
*char2b
, struct window
*w
, struct glyph_row
*row
,
22312 enum glyph_row_area area
, int start
, enum draw_glyphs_face hl
)
22314 memset (s
, 0, sizeof *s
);
22316 s
->f
= XFRAME (w
->frame
);
22320 s
->display
= FRAME_X_DISPLAY (s
->f
);
22321 s
->window
= FRAME_X_WINDOW (s
->f
);
22322 s
->char2b
= char2b
;
22326 s
->first_glyph
= row
->glyphs
[area
] + start
;
22327 s
->height
= row
->height
;
22328 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
22329 s
->ybase
= s
->y
+ row
->ascent
;
22333 /* Append the list of glyph strings with head H and tail T to the list
22334 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
22337 append_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
22338 struct glyph_string
*h
, struct glyph_string
*t
)
22352 /* Prepend the list of glyph strings with head H and tail T to the
22353 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
22357 prepend_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
22358 struct glyph_string
*h
, struct glyph_string
*t
)
22372 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
22373 Set *HEAD and *TAIL to the resulting list. */
22376 append_glyph_string (struct glyph_string
**head
, struct glyph_string
**tail
,
22377 struct glyph_string
*s
)
22379 s
->next
= s
->prev
= NULL
;
22380 append_glyph_string_lists (head
, tail
, s
, s
);
22384 /* Get face and two-byte form of character C in face FACE_ID on frame F.
22385 The encoding of C is returned in *CHAR2B. DISPLAY_P non-zero means
22386 make sure that X resources for the face returned are allocated.
22387 Value is a pointer to a realized face that is ready for display if
22388 DISPLAY_P is non-zero. */
22390 static struct face
*
22391 get_char_face_and_encoding (struct frame
*f
, int c
, int face_id
,
22392 XChar2b
*char2b
, int display_p
)
22394 struct face
*face
= FACE_FROM_ID (f
, face_id
);
22398 unsigned code
= face
->font
->driver
->encode_char (face
->font
, c
);
22400 if (code
!= FONT_INVALID_CODE
)
22401 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22403 STORE_XCHAR2B (char2b
, 0, 0);
22406 /* Make sure X resources of the face are allocated. */
22407 #ifdef HAVE_X_WINDOWS
22411 eassert (face
!= NULL
);
22412 PREPARE_FACE_FOR_DISPLAY (f
, face
);
22419 /* Get face and two-byte form of character glyph GLYPH on frame F.
22420 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
22421 a pointer to a realized face that is ready for display. */
22423 static struct face
*
22424 get_glyph_face_and_encoding (struct frame
*f
, struct glyph
*glyph
,
22425 XChar2b
*char2b
, int *two_byte_p
)
22429 eassert (glyph
->type
== CHAR_GLYPH
);
22430 face
= FACE_FROM_ID (f
, glyph
->face_id
);
22439 if (CHAR_BYTE8_P (glyph
->u
.ch
))
22440 code
= CHAR_TO_BYTE8 (glyph
->u
.ch
);
22442 code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
22444 if (code
!= FONT_INVALID_CODE
)
22445 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22447 STORE_XCHAR2B (char2b
, 0, 0);
22450 /* Make sure X resources of the face are allocated. */
22451 eassert (face
!= NULL
);
22452 PREPARE_FACE_FOR_DISPLAY (f
, face
);
22457 /* Get glyph code of character C in FONT in the two-byte form CHAR2B.
22458 Return 1 if FONT has a glyph for C, otherwise return 0. */
22461 get_char_glyph_code (int c
, struct font
*font
, XChar2b
*char2b
)
22465 if (CHAR_BYTE8_P (c
))
22466 code
= CHAR_TO_BYTE8 (c
);
22468 code
= font
->driver
->encode_char (font
, c
);
22470 if (code
== FONT_INVALID_CODE
)
22472 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22477 /* Fill glyph string S with composition components specified by S->cmp.
22479 BASE_FACE is the base face of the composition.
22480 S->cmp_from is the index of the first component for S.
22482 OVERLAPS non-zero means S should draw the foreground only, and use
22483 its physical height for clipping. See also draw_glyphs.
22485 Value is the index of a component not in S. */
22488 fill_composite_glyph_string (struct glyph_string
*s
, struct face
*base_face
,
22492 /* For all glyphs of this composition, starting at the offset
22493 S->cmp_from, until we reach the end of the definition or encounter a
22494 glyph that requires the different face, add it to S. */
22499 s
->for_overlaps
= overlaps
;
22502 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
22504 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
22506 /* TAB in a composition means display glyphs with padding space
22507 on the left or right. */
22510 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
22513 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
22520 s
->font
= s
->face
->font
;
22522 else if (s
->face
!= face
)
22530 if (s
->face
== NULL
)
22532 s
->face
= base_face
->ascii_face
;
22533 s
->font
= s
->face
->font
;
22536 /* All glyph strings for the same composition has the same width,
22537 i.e. the width set for the first component of the composition. */
22538 s
->width
= s
->first_glyph
->pixel_width
;
22540 /* If the specified font could not be loaded, use the frame's
22541 default font, but record the fact that we couldn't load it in
22542 the glyph string so that we can draw rectangles for the
22543 characters of the glyph string. */
22544 if (s
->font
== NULL
)
22546 s
->font_not_found_p
= 1;
22547 s
->font
= FRAME_FONT (s
->f
);
22550 /* Adjust base line for subscript/superscript text. */
22551 s
->ybase
+= s
->first_glyph
->voffset
;
22553 /* This glyph string must always be drawn with 16-bit functions. */
22560 fill_gstring_glyph_string (struct glyph_string
*s
, int face_id
,
22561 int start
, int end
, int overlaps
)
22563 struct glyph
*glyph
, *last
;
22564 Lisp_Object lgstring
;
22567 s
->for_overlaps
= overlaps
;
22568 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22569 last
= s
->row
->glyphs
[s
->area
] + end
;
22570 s
->cmp_id
= glyph
->u
.cmp
.id
;
22571 s
->cmp_from
= glyph
->slice
.cmp
.from
;
22572 s
->cmp_to
= glyph
->slice
.cmp
.to
+ 1;
22573 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
22574 lgstring
= composition_gstring_from_id (s
->cmp_id
);
22575 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
22577 while (glyph
< last
22578 && glyph
->u
.cmp
.automatic
22579 && glyph
->u
.cmp
.id
== s
->cmp_id
22580 && s
->cmp_to
== glyph
->slice
.cmp
.from
)
22581 s
->cmp_to
= (glyph
++)->slice
.cmp
.to
+ 1;
22583 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
22585 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
22586 unsigned code
= LGLYPH_CODE (lglyph
);
22588 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
22590 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
22591 return glyph
- s
->row
->glyphs
[s
->area
];
22595 /* Fill glyph string S from a sequence glyphs for glyphless characters.
22596 See the comment of fill_glyph_string for arguments.
22597 Value is the index of the first glyph not in S. */
22601 fill_glyphless_glyph_string (struct glyph_string
*s
, int face_id
,
22602 int start
, int end
, int overlaps
)
22604 struct glyph
*glyph
, *last
;
22607 eassert (s
->first_glyph
->type
== GLYPHLESS_GLYPH
);
22608 s
->for_overlaps
= overlaps
;
22609 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22610 last
= s
->row
->glyphs
[s
->area
] + end
;
22611 voffset
= glyph
->voffset
;
22612 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
22613 s
->font
= s
->face
->font
? s
->face
->font
: FRAME_FONT (s
->f
);
22615 s
->width
= glyph
->pixel_width
;
22617 while (glyph
< last
22618 && glyph
->type
== GLYPHLESS_GLYPH
22619 && glyph
->voffset
== voffset
22620 && glyph
->face_id
== face_id
)
22623 s
->width
+= glyph
->pixel_width
;
22626 s
->ybase
+= voffset
;
22627 return glyph
- s
->row
->glyphs
[s
->area
];
22631 /* Fill glyph string S from a sequence of character glyphs.
22633 FACE_ID is the face id of the string. START is the index of the
22634 first glyph to consider, END is the index of the last + 1.
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 the first glyph not in S. */
22641 fill_glyph_string (struct glyph_string
*s
, int face_id
,
22642 int start
, int end
, int overlaps
)
22644 struct glyph
*glyph
, *last
;
22646 int glyph_not_available_p
;
22648 eassert (s
->f
== XFRAME (s
->w
->frame
));
22649 eassert (s
->nchars
== 0);
22650 eassert (start
>= 0 && end
> start
);
22652 s
->for_overlaps
= overlaps
;
22653 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22654 last
= s
->row
->glyphs
[s
->area
] + end
;
22655 voffset
= glyph
->voffset
;
22656 s
->padding_p
= glyph
->padding_p
;
22657 glyph_not_available_p
= glyph
->glyph_not_available_p
;
22659 while (glyph
< last
22660 && glyph
->type
== CHAR_GLYPH
22661 && glyph
->voffset
== voffset
22662 /* Same face id implies same font, nowadays. */
22663 && glyph
->face_id
== face_id
22664 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
22668 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
22669 s
->char2b
+ s
->nchars
,
22671 s
->two_byte_p
= two_byte_p
;
22673 eassert (s
->nchars
<= end
- start
);
22674 s
->width
+= glyph
->pixel_width
;
22675 if (glyph
++->padding_p
!= s
->padding_p
)
22679 s
->font
= s
->face
->font
;
22681 /* If the specified font could not be loaded, use the frame's font,
22682 but record the fact that we couldn't load it in
22683 S->font_not_found_p so that we can draw rectangles for the
22684 characters of the glyph string. */
22685 if (s
->font
== NULL
|| glyph_not_available_p
)
22687 s
->font_not_found_p
= 1;
22688 s
->font
= FRAME_FONT (s
->f
);
22691 /* Adjust base line for subscript/superscript text. */
22692 s
->ybase
+= voffset
;
22694 eassert (s
->face
&& s
->face
->gc
);
22695 return glyph
- s
->row
->glyphs
[s
->area
];
22699 /* Fill glyph string S from image glyph S->first_glyph. */
22702 fill_image_glyph_string (struct glyph_string
*s
)
22704 eassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
22705 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
22707 s
->slice
= s
->first_glyph
->slice
.img
;
22708 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
22709 s
->font
= s
->face
->font
;
22710 s
->width
= s
->first_glyph
->pixel_width
;
22712 /* Adjust base line for subscript/superscript text. */
22713 s
->ybase
+= s
->first_glyph
->voffset
;
22717 /* Fill glyph string S from a sequence of stretch glyphs.
22719 START is the index of the first glyph to consider,
22720 END is the index of the last + 1.
22722 Value is the index of the first glyph not in S. */
22725 fill_stretch_glyph_string (struct glyph_string
*s
, int start
, int end
)
22727 struct glyph
*glyph
, *last
;
22728 int voffset
, face_id
;
22730 eassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
22732 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22733 last
= s
->row
->glyphs
[s
->area
] + end
;
22734 face_id
= glyph
->face_id
;
22735 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
22736 s
->font
= s
->face
->font
;
22737 s
->width
= glyph
->pixel_width
;
22739 voffset
= glyph
->voffset
;
22743 && glyph
->type
== STRETCH_GLYPH
22744 && glyph
->voffset
== voffset
22745 && glyph
->face_id
== face_id
);
22747 s
->width
+= glyph
->pixel_width
;
22749 /* Adjust base line for subscript/superscript text. */
22750 s
->ybase
+= voffset
;
22752 /* The case that face->gc == 0 is handled when drawing the glyph
22753 string by calling PREPARE_FACE_FOR_DISPLAY. */
22755 return glyph
- s
->row
->glyphs
[s
->area
];
22758 static struct font_metrics
*
22759 get_per_char_metric (struct font
*font
, XChar2b
*char2b
)
22761 static struct font_metrics metrics
;
22762 unsigned code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
22764 if (! font
|| code
== FONT_INVALID_CODE
)
22766 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
22771 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
22772 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
22773 assumed to be zero. */
22776 x_get_glyph_overhangs (struct glyph
*glyph
, struct frame
*f
, int *left
, int *right
)
22778 *left
= *right
= 0;
22780 if (glyph
->type
== CHAR_GLYPH
)
22784 struct font_metrics
*pcm
;
22786 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
22787 if (face
->font
&& (pcm
= get_per_char_metric (face
->font
, &char2b
)))
22789 if (pcm
->rbearing
> pcm
->width
)
22790 *right
= pcm
->rbearing
- pcm
->width
;
22791 if (pcm
->lbearing
< 0)
22792 *left
= -pcm
->lbearing
;
22795 else if (glyph
->type
== COMPOSITE_GLYPH
)
22797 if (! glyph
->u
.cmp
.automatic
)
22799 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
22801 if (cmp
->rbearing
> cmp
->pixel_width
)
22802 *right
= cmp
->rbearing
- cmp
->pixel_width
;
22803 if (cmp
->lbearing
< 0)
22804 *left
= - cmp
->lbearing
;
22808 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
22809 struct font_metrics metrics
;
22811 composition_gstring_width (gstring
, glyph
->slice
.cmp
.from
,
22812 glyph
->slice
.cmp
.to
+ 1, &metrics
);
22813 if (metrics
.rbearing
> metrics
.width
)
22814 *right
= metrics
.rbearing
- metrics
.width
;
22815 if (metrics
.lbearing
< 0)
22816 *left
= - metrics
.lbearing
;
22822 /* Return the index of the first glyph preceding glyph string S that
22823 is overwritten by S because of S's left overhang. Value is -1
22824 if no glyphs are overwritten. */
22827 left_overwritten (struct glyph_string
*s
)
22831 if (s
->left_overhang
)
22834 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
22835 int first
= s
->first_glyph
- glyphs
;
22837 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
22838 x
-= glyphs
[i
].pixel_width
;
22849 /* Return the index of the first glyph preceding glyph string S that
22850 is overwriting S because of its right overhang. Value is -1 if no
22851 glyph in front of S overwrites S. */
22854 left_overwriting (struct glyph_string
*s
)
22857 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
22858 int first
= s
->first_glyph
- glyphs
;
22862 for (i
= first
- 1; i
>= 0; --i
)
22865 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
22868 x
-= glyphs
[i
].pixel_width
;
22875 /* Return the index of the last glyph following glyph string S that is
22876 overwritten by S because of S's right overhang. Value is -1 if
22877 no such glyph is found. */
22880 right_overwritten (struct glyph_string
*s
)
22884 if (s
->right_overhang
)
22887 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
22888 int first
= (s
->first_glyph
- glyphs
22889 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
22890 int end
= s
->row
->used
[s
->area
];
22892 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
22893 x
+= glyphs
[i
].pixel_width
;
22902 /* Return the index of the last glyph following glyph string S that
22903 overwrites S because of its left overhang. Value is negative
22904 if no such glyph is found. */
22907 right_overwriting (struct glyph_string
*s
)
22910 int end
= s
->row
->used
[s
->area
];
22911 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
22912 int first
= (s
->first_glyph
- glyphs
22913 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
22917 for (i
= first
; i
< end
; ++i
)
22920 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
22923 x
+= glyphs
[i
].pixel_width
;
22930 /* Set background width of glyph string S. START is the index of the
22931 first glyph following S. LAST_X is the right-most x-position + 1
22932 in the drawing area. */
22935 set_glyph_string_background_width (struct glyph_string
*s
, int start
, int last_x
)
22937 /* If the face of this glyph string has to be drawn to the end of
22938 the drawing area, set S->extends_to_end_of_line_p. */
22940 if (start
== s
->row
->used
[s
->area
]
22941 && s
->area
== TEXT_AREA
22942 && ((s
->row
->fill_line_p
22943 && (s
->hl
== DRAW_NORMAL_TEXT
22944 || s
->hl
== DRAW_IMAGE_RAISED
22945 || s
->hl
== DRAW_IMAGE_SUNKEN
))
22946 || s
->hl
== DRAW_MOUSE_FACE
))
22947 s
->extends_to_end_of_line_p
= 1;
22949 /* If S extends its face to the end of the line, set its
22950 background_width to the distance to the right edge of the drawing
22952 if (s
->extends_to_end_of_line_p
)
22953 s
->background_width
= last_x
- s
->x
+ 1;
22955 s
->background_width
= s
->width
;
22959 /* Compute overhangs and x-positions for glyph string S and its
22960 predecessors, or successors. X is the starting x-position for S.
22961 BACKWARD_P non-zero means process predecessors. */
22964 compute_overhangs_and_x (struct glyph_string
*s
, int x
, int backward_p
)
22970 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
22971 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
22981 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
22982 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
22992 /* The following macros are only called from draw_glyphs below.
22993 They reference the following parameters of that function directly:
22994 `w', `row', `area', and `overlap_p'
22995 as well as the following local variables:
22996 `s', `f', and `hdc' (in W32) */
22999 /* On W32, silently add local `hdc' variable to argument list of
23000 init_glyph_string. */
23001 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
23002 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
23004 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
23005 init_glyph_string (s, char2b, w, row, area, start, hl)
23008 /* Add a glyph string for a stretch glyph to the list of strings
23009 between HEAD and TAIL. START is the index of the stretch glyph in
23010 row area AREA of glyph row ROW. END is the index of the last glyph
23011 in that glyph row area. X is the current output position assigned
23012 to the new glyph string constructed. HL overrides that face of the
23013 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
23014 is the right-most x-position of the drawing area. */
23016 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
23017 and below -- keep them on one line. */
23018 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23021 s = alloca (sizeof *s); \
23022 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23023 START = fill_stretch_glyph_string (s, START, END); \
23024 append_glyph_string (&HEAD, &TAIL, s); \
23030 /* Add a glyph string for an image glyph to the list of strings
23031 between HEAD and TAIL. START is the index of the image glyph in
23032 row area AREA of glyph row ROW. END is the index of the last glyph
23033 in that glyph row area. X is the current output position assigned
23034 to the new glyph string constructed. HL overrides that face of the
23035 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
23036 is the right-most x-position of the drawing area. */
23038 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23041 s = alloca (sizeof *s); \
23042 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23043 fill_image_glyph_string (s); \
23044 append_glyph_string (&HEAD, &TAIL, s); \
23051 /* Add a glyph string for a sequence of character glyphs to the list
23052 of strings between HEAD and TAIL. START is the index of the first
23053 glyph in row area AREA of glyph row ROW that is part of the new
23054 glyph string. END is the index of the last glyph in that glyph row
23055 area. X is the current output position assigned to the new glyph
23056 string constructed. HL overrides that face of the glyph; e.g. it
23057 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
23058 right-most x-position of the drawing area. */
23060 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
23066 face_id = (row)->glyphs[area][START].face_id; \
23068 s = alloca (sizeof *s); \
23069 char2b = alloca ((END - START) * sizeof *char2b); \
23070 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23071 append_glyph_string (&HEAD, &TAIL, s); \
23073 START = fill_glyph_string (s, face_id, START, END, overlaps); \
23078 /* Add a glyph string for a composite sequence to the list of strings
23079 between HEAD and TAIL. START is the index of the first glyph in
23080 row area AREA of glyph row ROW that is part of the new glyph
23081 string. END is the index of the last glyph in that glyph row area.
23082 X is the current output position assigned to the new glyph string
23083 constructed. HL overrides that face of the glyph; e.g. it is
23084 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
23085 x-position of the drawing area. */
23087 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23089 int face_id = (row)->glyphs[area][START].face_id; \
23090 struct face *base_face = FACE_FROM_ID (f, face_id); \
23091 ptrdiff_t cmp_id = (row)->glyphs[area][START].u.cmp.id; \
23092 struct composition *cmp = composition_table[cmp_id]; \
23094 struct glyph_string *first_s = NULL; \
23097 char2b = alloca (cmp->glyph_len * sizeof *char2b); \
23099 /* Make glyph_strings for each glyph sequence that is drawable by \
23100 the same face, and append them to HEAD/TAIL. */ \
23101 for (n = 0; n < cmp->glyph_len;) \
23103 s = alloca (sizeof *s); \
23104 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23105 append_glyph_string (&(HEAD), &(TAIL), s); \
23111 n = fill_composite_glyph_string (s, base_face, overlaps); \
23119 /* Add a glyph string for a glyph-string sequence to the list of strings
23120 between HEAD and TAIL. */
23122 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23126 Lisp_Object gstring; \
23128 face_id = (row)->glyphs[area][START].face_id; \
23129 gstring = (composition_gstring_from_id \
23130 ((row)->glyphs[area][START].u.cmp.id)); \
23131 s = alloca (sizeof *s); \
23132 char2b = alloca (LGSTRING_GLYPH_LEN (gstring) * sizeof *char2b); \
23133 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23134 append_glyph_string (&(HEAD), &(TAIL), s); \
23136 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
23140 /* Add a glyph string for a sequence of glyphless character's glyphs
23141 to the list of strings between HEAD and TAIL. The meanings of
23142 arguments are the same as those of BUILD_CHAR_GLYPH_STRINGS. */
23144 #define BUILD_GLYPHLESS_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23149 face_id = (row)->glyphs[area][START].face_id; \
23151 s = alloca (sizeof *s); \
23152 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23153 append_glyph_string (&HEAD, &TAIL, s); \
23155 START = fill_glyphless_glyph_string (s, face_id, START, END, \
23161 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
23162 of AREA of glyph row ROW on window W between indices START and END.
23163 HL overrides the face for drawing glyph strings, e.g. it is
23164 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
23165 x-positions of the drawing area.
23167 This is an ugly monster macro construct because we must use alloca
23168 to allocate glyph strings (because draw_glyphs can be called
23169 asynchronously). */
23171 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
23174 HEAD = TAIL = NULL; \
23175 while (START < END) \
23177 struct glyph *first_glyph = (row)->glyphs[area] + START; \
23178 switch (first_glyph->type) \
23181 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
23185 case COMPOSITE_GLYPH: \
23186 if (first_glyph->u.cmp.automatic) \
23187 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
23190 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
23194 case STRETCH_GLYPH: \
23195 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
23199 case IMAGE_GLYPH: \
23200 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
23204 case GLYPHLESS_GLYPH: \
23205 BUILD_GLYPHLESS_GLYPH_STRING (START, END, HEAD, TAIL, \
23215 set_glyph_string_background_width (s, START, LAST_X); \
23222 /* Draw glyphs between START and END in AREA of ROW on window W,
23223 starting at x-position X. X is relative to AREA in W. HL is a
23224 face-override with the following meaning:
23226 DRAW_NORMAL_TEXT draw normally
23227 DRAW_CURSOR draw in cursor face
23228 DRAW_MOUSE_FACE draw in mouse face.
23229 DRAW_INVERSE_VIDEO draw in mode line face
23230 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
23231 DRAW_IMAGE_RAISED draw an image with a raised relief around it
23233 If OVERLAPS is non-zero, draw only the foreground of characters and
23234 clip to the physical height of ROW. Non-zero value also defines
23235 the overlapping part to be drawn:
23237 OVERLAPS_PRED overlap with preceding rows
23238 OVERLAPS_SUCC overlap with succeeding rows
23239 OVERLAPS_BOTH overlap with both preceding/succeeding rows
23240 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
23242 Value is the x-position reached, relative to AREA of W. */
23245 draw_glyphs (struct window
*w
, int x
, struct glyph_row
*row
,
23246 enum glyph_row_area area
, ptrdiff_t start
, ptrdiff_t end
,
23247 enum draw_glyphs_face hl
, int overlaps
)
23249 struct glyph_string
*head
, *tail
;
23250 struct glyph_string
*s
;
23251 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
23252 int i
, j
, x_reached
, last_x
, area_left
= 0;
23253 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
23256 ALLOCATE_HDC (hdc
, f
);
23258 /* Let's rather be paranoid than getting a SEGV. */
23259 end
= min (end
, row
->used
[area
]);
23260 start
= clip_to_bounds (0, start
, end
);
23262 /* Translate X to frame coordinates. Set last_x to the right
23263 end of the drawing area. */
23264 if (row
->full_width_p
)
23266 /* X is relative to the left edge of W, without scroll bars
23268 area_left
= WINDOW_LEFT_EDGE_X (w
);
23269 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
23273 area_left
= window_box_left (w
, area
);
23274 last_x
= area_left
+ window_box_width (w
, area
);
23278 /* Build a doubly-linked list of glyph_string structures between
23279 head and tail from what we have to draw. Note that the macro
23280 BUILD_GLYPH_STRINGS will modify its start parameter. That's
23281 the reason we use a separate variable `i'. */
23283 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
23285 x_reached
= tail
->x
+ tail
->background_width
;
23289 /* If there are any glyphs with lbearing < 0 or rbearing > width in
23290 the row, redraw some glyphs in front or following the glyph
23291 strings built above. */
23292 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
23294 struct glyph_string
*h
, *t
;
23295 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
23296 int mouse_beg_col
IF_LINT (= 0), mouse_end_col
IF_LINT (= 0);
23297 int check_mouse_face
= 0;
23300 /* If mouse highlighting is on, we may need to draw adjacent
23301 glyphs using mouse-face highlighting. */
23302 if (area
== TEXT_AREA
&& row
->mouse_face_p
23303 && hlinfo
->mouse_face_beg_row
>= 0
23304 && hlinfo
->mouse_face_end_row
>= 0)
23306 struct glyph_row
*mouse_beg_row
, *mouse_end_row
;
23308 mouse_beg_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
23309 mouse_end_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
23311 if (row
>= mouse_beg_row
&& row
<= mouse_end_row
)
23313 check_mouse_face
= 1;
23314 mouse_beg_col
= (row
== mouse_beg_row
)
23315 ? hlinfo
->mouse_face_beg_col
: 0;
23316 mouse_end_col
= (row
== mouse_end_row
)
23317 ? hlinfo
->mouse_face_end_col
23318 : row
->used
[TEXT_AREA
];
23322 /* Compute overhangs for all glyph strings. */
23323 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
23324 for (s
= head
; s
; s
= s
->next
)
23325 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
23327 /* Prepend glyph strings for glyphs in front of the first glyph
23328 string that are overwritten because of the first glyph
23329 string's left overhang. The background of all strings
23330 prepended must be drawn because the first glyph string
23332 i
= left_overwritten (head
);
23335 enum draw_glyphs_face overlap_hl
;
23337 /* If this row contains mouse highlighting, attempt to draw
23338 the overlapped glyphs with the correct highlight. This
23339 code fails if the overlap encompasses more than one glyph
23340 and mouse-highlight spans only some of these glyphs.
23341 However, making it work perfectly involves a lot more
23342 code, and I don't know if the pathological case occurs in
23343 practice, so we'll stick to this for now. --- cyd */
23344 if (check_mouse_face
23345 && mouse_beg_col
< start
&& mouse_end_col
> i
)
23346 overlap_hl
= DRAW_MOUSE_FACE
;
23348 overlap_hl
= DRAW_NORMAL_TEXT
;
23351 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
23352 overlap_hl
, dummy_x
, last_x
);
23354 compute_overhangs_and_x (t
, head
->x
, 1);
23355 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
23359 /* Prepend glyph strings for glyphs in front of the first glyph
23360 string that overwrite that glyph string because of their
23361 right overhang. For these strings, only the foreground must
23362 be drawn, because it draws over the glyph string at `head'.
23363 The background must not be drawn because this would overwrite
23364 right overhangs of preceding glyphs for which no glyph
23366 i
= left_overwriting (head
);
23369 enum draw_glyphs_face overlap_hl
;
23371 if (check_mouse_face
23372 && mouse_beg_col
< start
&& mouse_end_col
> i
)
23373 overlap_hl
= DRAW_MOUSE_FACE
;
23375 overlap_hl
= DRAW_NORMAL_TEXT
;
23378 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
23379 overlap_hl
, dummy_x
, last_x
);
23380 for (s
= h
; s
; s
= s
->next
)
23381 s
->background_filled_p
= 1;
23382 compute_overhangs_and_x (t
, head
->x
, 1);
23383 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
23386 /* Append glyphs strings for glyphs following the last glyph
23387 string tail that are overwritten by tail. The background of
23388 these strings has to be drawn because tail's foreground draws
23390 i
= right_overwritten (tail
);
23393 enum draw_glyphs_face overlap_hl
;
23395 if (check_mouse_face
23396 && mouse_beg_col
< i
&& mouse_end_col
> end
)
23397 overlap_hl
= DRAW_MOUSE_FACE
;
23399 overlap_hl
= DRAW_NORMAL_TEXT
;
23401 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
23402 overlap_hl
, x
, last_x
);
23403 /* Because BUILD_GLYPH_STRINGS updates the first argument,
23404 we don't have `end = i;' here. */
23405 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
23406 append_glyph_string_lists (&head
, &tail
, h
, t
);
23410 /* Append glyph strings for glyphs following the last glyph
23411 string tail that overwrite tail. The foreground of such
23412 glyphs has to be drawn because it writes into the background
23413 of tail. The background must not be drawn because it could
23414 paint over the foreground of following glyphs. */
23415 i
= right_overwriting (tail
);
23418 enum draw_glyphs_face overlap_hl
;
23419 if (check_mouse_face
23420 && mouse_beg_col
< i
&& mouse_end_col
> end
)
23421 overlap_hl
= DRAW_MOUSE_FACE
;
23423 overlap_hl
= DRAW_NORMAL_TEXT
;
23426 i
++; /* We must include the Ith glyph. */
23427 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
23428 overlap_hl
, x
, last_x
);
23429 for (s
= h
; s
; s
= s
->next
)
23430 s
->background_filled_p
= 1;
23431 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
23432 append_glyph_string_lists (&head
, &tail
, h
, t
);
23434 if (clip_head
|| clip_tail
)
23435 for (s
= head
; s
; s
= s
->next
)
23437 s
->clip_head
= clip_head
;
23438 s
->clip_tail
= clip_tail
;
23442 /* Draw all strings. */
23443 for (s
= head
; s
; s
= s
->next
)
23444 FRAME_RIF (f
)->draw_glyph_string (s
);
23447 /* When focus a sole frame and move horizontally, this sets on_p to 0
23448 causing a failure to erase prev cursor position. */
23449 if (area
== TEXT_AREA
23450 && !row
->full_width_p
23451 /* When drawing overlapping rows, only the glyph strings'
23452 foreground is drawn, which doesn't erase a cursor
23456 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
23457 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
23458 : (tail
? tail
->x
+ tail
->background_width
: x
));
23462 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
23463 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
23467 /* Value is the x-position up to which drawn, relative to AREA of W.
23468 This doesn't include parts drawn because of overhangs. */
23469 if (row
->full_width_p
)
23470 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
23472 x_reached
-= area_left
;
23474 RELEASE_HDC (hdc
, f
);
23479 /* Expand row matrix if too narrow. Don't expand if area
23482 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
23484 if (!fonts_changed_p \
23485 && (it->glyph_row->glyphs[area] \
23486 < it->glyph_row->glyphs[area + 1])) \
23488 it->w->ncols_scale_factor++; \
23489 fonts_changed_p = 1; \
23493 /* Store one glyph for IT->char_to_display in IT->glyph_row.
23494 Called from x_produce_glyphs when IT->glyph_row is non-null. */
23497 append_glyph (struct it
*it
)
23499 struct glyph
*glyph
;
23500 enum glyph_row_area area
= it
->area
;
23502 eassert (it
->glyph_row
);
23503 eassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
23505 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23506 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23508 /* If the glyph row is reversed, we need to prepend the glyph
23509 rather than append it. */
23510 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23514 /* Make room for the additional glyph. */
23515 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
23517 glyph
= it
->glyph_row
->glyphs
[area
];
23519 glyph
->charpos
= CHARPOS (it
->position
);
23520 glyph
->object
= it
->object
;
23521 if (it
->pixel_width
> 0)
23523 glyph
->pixel_width
= it
->pixel_width
;
23524 glyph
->padding_p
= 0;
23528 /* Assure at least 1-pixel width. Otherwise, cursor can't
23529 be displayed correctly. */
23530 glyph
->pixel_width
= 1;
23531 glyph
->padding_p
= 1;
23533 glyph
->ascent
= it
->ascent
;
23534 glyph
->descent
= it
->descent
;
23535 glyph
->voffset
= it
->voffset
;
23536 glyph
->type
= CHAR_GLYPH
;
23537 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23538 glyph
->multibyte_p
= it
->multibyte_p
;
23539 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23541 /* In R2L rows, the left and the right box edges need to be
23542 drawn in reverse direction. */
23543 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
23544 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
23548 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23549 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23551 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
23552 || it
->phys_descent
> it
->descent
);
23553 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
23554 glyph
->face_id
= it
->face_id
;
23555 glyph
->u
.ch
= it
->char_to_display
;
23556 glyph
->slice
.img
= null_glyph_slice
;
23557 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23560 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23561 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23563 glyph
->bidi_type
= it
->bidi_it
.type
;
23567 glyph
->resolved_level
= 0;
23568 glyph
->bidi_type
= UNKNOWN_BT
;
23570 ++it
->glyph_row
->used
[area
];
23573 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23576 /* Store one glyph for the composition IT->cmp_it.id in
23577 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
23581 append_composite_glyph (struct it
*it
)
23583 struct glyph
*glyph
;
23584 enum glyph_row_area area
= it
->area
;
23586 eassert (it
->glyph_row
);
23588 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23589 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23591 /* If the glyph row is reversed, we need to prepend the glyph
23592 rather than append it. */
23593 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
23597 /* Make room for the new glyph. */
23598 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
23600 glyph
= it
->glyph_row
->glyphs
[it
->area
];
23602 glyph
->charpos
= it
->cmp_it
.charpos
;
23603 glyph
->object
= it
->object
;
23604 glyph
->pixel_width
= it
->pixel_width
;
23605 glyph
->ascent
= it
->ascent
;
23606 glyph
->descent
= it
->descent
;
23607 glyph
->voffset
= it
->voffset
;
23608 glyph
->type
= COMPOSITE_GLYPH
;
23609 if (it
->cmp_it
.ch
< 0)
23611 glyph
->u
.cmp
.automatic
= 0;
23612 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
23613 glyph
->slice
.cmp
.from
= glyph
->slice
.cmp
.to
= 0;
23617 glyph
->u
.cmp
.automatic
= 1;
23618 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
23619 glyph
->slice
.cmp
.from
= it
->cmp_it
.from
;
23620 glyph
->slice
.cmp
.to
= it
->cmp_it
.to
- 1;
23622 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23623 glyph
->multibyte_p
= it
->multibyte_p
;
23624 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23626 /* In R2L rows, the left and the right box edges need to be
23627 drawn in reverse direction. */
23628 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
23629 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
23633 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23634 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23636 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
23637 || it
->phys_descent
> it
->descent
);
23638 glyph
->padding_p
= 0;
23639 glyph
->glyph_not_available_p
= 0;
23640 glyph
->face_id
= it
->face_id
;
23641 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23644 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23645 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23647 glyph
->bidi_type
= it
->bidi_it
.type
;
23649 ++it
->glyph_row
->used
[area
];
23652 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23656 /* Change IT->ascent and IT->height according to the setting of
23660 take_vertical_position_into_account (struct it
*it
)
23664 if (it
->voffset
< 0)
23665 /* Increase the ascent so that we can display the text higher
23667 it
->ascent
-= it
->voffset
;
23669 /* Increase the descent so that we can display the text lower
23671 it
->descent
+= it
->voffset
;
23676 /* Produce glyphs/get display metrics for the image IT is loaded with.
23677 See the description of struct display_iterator in dispextern.h for
23678 an overview of struct display_iterator. */
23681 produce_image_glyph (struct it
*it
)
23685 int glyph_ascent
, crop
;
23686 struct glyph_slice slice
;
23688 eassert (it
->what
== IT_IMAGE
);
23690 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
23692 /* Make sure X resources of the face is loaded. */
23693 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
23695 if (it
->image_id
< 0)
23697 /* Fringe bitmap. */
23698 it
->ascent
= it
->phys_ascent
= 0;
23699 it
->descent
= it
->phys_descent
= 0;
23700 it
->pixel_width
= 0;
23705 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
23707 /* Make sure X resources of the image is loaded. */
23708 prepare_image_for_display (it
->f
, img
);
23710 slice
.x
= slice
.y
= 0;
23711 slice
.width
= img
->width
;
23712 slice
.height
= img
->height
;
23714 if (INTEGERP (it
->slice
.x
))
23715 slice
.x
= XINT (it
->slice
.x
);
23716 else if (FLOATP (it
->slice
.x
))
23717 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
23719 if (INTEGERP (it
->slice
.y
))
23720 slice
.y
= XINT (it
->slice
.y
);
23721 else if (FLOATP (it
->slice
.y
))
23722 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
23724 if (INTEGERP (it
->slice
.width
))
23725 slice
.width
= XINT (it
->slice
.width
);
23726 else if (FLOATP (it
->slice
.width
))
23727 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
23729 if (INTEGERP (it
->slice
.height
))
23730 slice
.height
= XINT (it
->slice
.height
);
23731 else if (FLOATP (it
->slice
.height
))
23732 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
23734 if (slice
.x
>= img
->width
)
23735 slice
.x
= img
->width
;
23736 if (slice
.y
>= img
->height
)
23737 slice
.y
= img
->height
;
23738 if (slice
.x
+ slice
.width
>= img
->width
)
23739 slice
.width
= img
->width
- slice
.x
;
23740 if (slice
.y
+ slice
.height
> img
->height
)
23741 slice
.height
= img
->height
- slice
.y
;
23743 if (slice
.width
== 0 || slice
.height
== 0)
23746 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
23748 it
->descent
= slice
.height
- glyph_ascent
;
23750 it
->descent
+= img
->vmargin
;
23751 if (slice
.y
+ slice
.height
== img
->height
)
23752 it
->descent
+= img
->vmargin
;
23753 it
->phys_descent
= it
->descent
;
23755 it
->pixel_width
= slice
.width
;
23757 it
->pixel_width
+= img
->hmargin
;
23758 if (slice
.x
+ slice
.width
== img
->width
)
23759 it
->pixel_width
+= img
->hmargin
;
23761 /* It's quite possible for images to have an ascent greater than
23762 their height, so don't get confused in that case. */
23763 if (it
->descent
< 0)
23768 if (face
->box
!= FACE_NO_BOX
)
23770 if (face
->box_line_width
> 0)
23773 it
->ascent
+= face
->box_line_width
;
23774 if (slice
.y
+ slice
.height
== img
->height
)
23775 it
->descent
+= face
->box_line_width
;
23778 if (it
->start_of_box_run_p
&& slice
.x
== 0)
23779 it
->pixel_width
+= eabs (face
->box_line_width
);
23780 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
23781 it
->pixel_width
+= eabs (face
->box_line_width
);
23784 take_vertical_position_into_account (it
);
23786 /* Automatically crop wide image glyphs at right edge so we can
23787 draw the cursor on same display row. */
23788 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
23789 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
23791 it
->pixel_width
-= crop
;
23792 slice
.width
-= crop
;
23797 struct glyph
*glyph
;
23798 enum glyph_row_area area
= it
->area
;
23800 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23801 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23803 glyph
->charpos
= CHARPOS (it
->position
);
23804 glyph
->object
= it
->object
;
23805 glyph
->pixel_width
= it
->pixel_width
;
23806 glyph
->ascent
= glyph_ascent
;
23807 glyph
->descent
= it
->descent
;
23808 glyph
->voffset
= it
->voffset
;
23809 glyph
->type
= IMAGE_GLYPH
;
23810 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23811 glyph
->multibyte_p
= it
->multibyte_p
;
23812 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23814 /* In R2L rows, the left and the right box edges need to be
23815 drawn in reverse direction. */
23816 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
23817 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
23821 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23822 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23824 glyph
->overlaps_vertically_p
= 0;
23825 glyph
->padding_p
= 0;
23826 glyph
->glyph_not_available_p
= 0;
23827 glyph
->face_id
= it
->face_id
;
23828 glyph
->u
.img_id
= img
->id
;
23829 glyph
->slice
.img
= slice
;
23830 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23833 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23834 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23836 glyph
->bidi_type
= it
->bidi_it
.type
;
23838 ++it
->glyph_row
->used
[area
];
23841 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23846 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
23847 of the glyph, WIDTH and HEIGHT are the width and height of the
23848 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
23851 append_stretch_glyph (struct it
*it
, Lisp_Object object
,
23852 int width
, int height
, int ascent
)
23854 struct glyph
*glyph
;
23855 enum glyph_row_area area
= it
->area
;
23857 eassert (ascent
>= 0 && ascent
<= height
);
23859 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23860 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23862 /* If the glyph row is reversed, we need to prepend the glyph
23863 rather than append it. */
23864 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23868 /* Make room for the additional glyph. */
23869 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
23871 glyph
= it
->glyph_row
->glyphs
[area
];
23873 glyph
->charpos
= CHARPOS (it
->position
);
23874 glyph
->object
= object
;
23875 glyph
->pixel_width
= width
;
23876 glyph
->ascent
= ascent
;
23877 glyph
->descent
= height
- ascent
;
23878 glyph
->voffset
= it
->voffset
;
23879 glyph
->type
= STRETCH_GLYPH
;
23880 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23881 glyph
->multibyte_p
= it
->multibyte_p
;
23882 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23884 /* In R2L rows, the left and the right box edges need to be
23885 drawn in reverse direction. */
23886 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
23887 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
23891 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23892 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23894 glyph
->overlaps_vertically_p
= 0;
23895 glyph
->padding_p
= 0;
23896 glyph
->glyph_not_available_p
= 0;
23897 glyph
->face_id
= it
->face_id
;
23898 glyph
->u
.stretch
.ascent
= ascent
;
23899 glyph
->u
.stretch
.height
= height
;
23900 glyph
->slice
.img
= null_glyph_slice
;
23901 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23904 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23905 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23907 glyph
->bidi_type
= it
->bidi_it
.type
;
23911 glyph
->resolved_level
= 0;
23912 glyph
->bidi_type
= UNKNOWN_BT
;
23914 ++it
->glyph_row
->used
[area
];
23917 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23920 #endif /* HAVE_WINDOW_SYSTEM */
23922 /* Produce a stretch glyph for iterator IT. IT->object is the value
23923 of the glyph property displayed. The value must be a list
23924 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
23927 1. `:width WIDTH' specifies that the space should be WIDTH *
23928 canonical char width wide. WIDTH may be an integer or floating
23931 2. `:relative-width FACTOR' specifies that the width of the stretch
23932 should be computed from the width of the first character having the
23933 `glyph' property, and should be FACTOR times that width.
23935 3. `:align-to HPOS' specifies that the space should be wide enough
23936 to reach HPOS, a value in canonical character units.
23938 Exactly one of the above pairs must be present.
23940 4. `:height HEIGHT' specifies that the height of the stretch produced
23941 should be HEIGHT, measured in canonical character units.
23943 5. `:relative-height FACTOR' specifies that the height of the
23944 stretch should be FACTOR times the height of the characters having
23945 the glyph property.
23947 Either none or exactly one of 4 or 5 must be present.
23949 6. `:ascent ASCENT' specifies that ASCENT percent of the height
23950 of the stretch should be used for the ascent of the stretch.
23951 ASCENT must be in the range 0 <= ASCENT <= 100. */
23954 produce_stretch_glyph (struct it
*it
)
23956 /* (space :width WIDTH :height HEIGHT ...) */
23957 Lisp_Object prop
, plist
;
23958 int width
= 0, height
= 0, align_to
= -1;
23959 int zero_width_ok_p
= 0;
23961 struct font
*font
= NULL
;
23963 #ifdef HAVE_WINDOW_SYSTEM
23965 int zero_height_ok_p
= 0;
23967 if (FRAME_WINDOW_P (it
->f
))
23969 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
23970 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
23971 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
23975 /* List should start with `space'. */
23976 eassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
23977 plist
= XCDR (it
->object
);
23979 /* Compute the width of the stretch. */
23980 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
23981 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
23983 /* Absolute width `:width WIDTH' specified and valid. */
23984 zero_width_ok_p
= 1;
23987 #ifdef HAVE_WINDOW_SYSTEM
23988 else if (FRAME_WINDOW_P (it
->f
)
23989 && (prop
= Fplist_get (plist
, QCrelative_width
), NUMVAL (prop
) > 0))
23991 /* Relative width `:relative-width FACTOR' specified and valid.
23992 Compute the width of the characters having the `glyph'
23995 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
23998 if (it
->multibyte_p
)
23999 it2
.c
= it2
.char_to_display
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
24002 it2
.c
= it2
.char_to_display
= *p
, it2
.len
= 1;
24003 if (! ASCII_CHAR_P (it2
.c
))
24004 it2
.char_to_display
= BYTE8_TO_CHAR (it2
.c
);
24007 it2
.glyph_row
= NULL
;
24008 it2
.what
= IT_CHARACTER
;
24009 x_produce_glyphs (&it2
);
24010 width
= NUMVAL (prop
) * it2
.pixel_width
;
24012 #endif /* HAVE_WINDOW_SYSTEM */
24013 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
24014 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
24016 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
24017 align_to
= (align_to
< 0
24019 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
24020 else if (align_to
< 0)
24021 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
24022 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
24023 zero_width_ok_p
= 1;
24026 /* Nothing specified -> width defaults to canonical char width. */
24027 width
= FRAME_COLUMN_WIDTH (it
->f
);
24029 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
24032 #ifdef HAVE_WINDOW_SYSTEM
24033 /* Compute height. */
24034 if (FRAME_WINDOW_P (it
->f
))
24036 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
24037 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
24040 zero_height_ok_p
= 1;
24042 else if (prop
= Fplist_get (plist
, QCrelative_height
),
24044 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
24046 height
= FONT_HEIGHT (font
);
24048 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
24051 /* Compute percentage of height used for ascent. If
24052 `:ascent ASCENT' is present and valid, use that. Otherwise,
24053 derive the ascent from the font in use. */
24054 if (prop
= Fplist_get (plist
, QCascent
),
24055 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
24056 ascent
= height
* NUMVAL (prop
) / 100.0;
24057 else if (!NILP (prop
)
24058 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
24059 ascent
= min (max (0, (int)tem
), height
);
24061 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
24064 #endif /* HAVE_WINDOW_SYSTEM */
24067 if (width
> 0 && it
->line_wrap
!= TRUNCATE
24068 && it
->current_x
+ width
> it
->last_visible_x
)
24070 width
= it
->last_visible_x
- it
->current_x
;
24071 #ifdef HAVE_WINDOW_SYSTEM
24072 /* Subtract one more pixel from the stretch width, but only on
24073 GUI frames, since on a TTY each glyph is one "pixel" wide. */
24074 width
-= FRAME_WINDOW_P (it
->f
);
24078 if (width
> 0 && height
> 0 && it
->glyph_row
)
24080 Lisp_Object o_object
= it
->object
;
24081 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
24084 if (!STRINGP (object
))
24085 object
= it
->w
->buffer
;
24086 #ifdef HAVE_WINDOW_SYSTEM
24087 if (FRAME_WINDOW_P (it
->f
))
24088 append_stretch_glyph (it
, object
, width
, height
, ascent
);
24092 it
->object
= object
;
24093 it
->char_to_display
= ' ';
24094 it
->pixel_width
= it
->len
= 1;
24096 tty_append_glyph (it
);
24097 it
->object
= o_object
;
24101 it
->pixel_width
= width
;
24102 #ifdef HAVE_WINDOW_SYSTEM
24103 if (FRAME_WINDOW_P (it
->f
))
24105 it
->ascent
= it
->phys_ascent
= ascent
;
24106 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
24107 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
24108 take_vertical_position_into_account (it
);
24112 it
->nglyphs
= width
;
24115 /* Get information about special display element WHAT in an
24116 environment described by IT. WHAT is one of IT_TRUNCATION or
24117 IT_CONTINUATION. Maybe produce glyphs for WHAT if IT has a
24118 non-null glyph_row member. This function ensures that fields like
24119 face_id, c, len of IT are left untouched. */
24122 produce_special_glyphs (struct it
*it
, enum display_element_type what
)
24129 temp_it
.object
= make_number (0);
24130 memset (&temp_it
.current
, 0, sizeof temp_it
.current
);
24132 if (what
== IT_CONTINUATION
)
24134 /* Continuation glyph. For R2L lines, we mirror it by hand. */
24135 if (it
->bidi_it
.paragraph_dir
== R2L
)
24136 SET_GLYPH_FROM_CHAR (glyph
, '/');
24138 SET_GLYPH_FROM_CHAR (glyph
, '\\');
24140 && (gc
= DISP_CONTINUE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
24142 /* FIXME: Should we mirror GC for R2L lines? */
24143 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
24144 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
24147 else if (what
== IT_TRUNCATION
)
24149 /* Truncation glyph. */
24150 SET_GLYPH_FROM_CHAR (glyph
, '$');
24152 && (gc
= DISP_TRUNC_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
24154 /* FIXME: Should we mirror GC for R2L lines? */
24155 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
24156 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
24162 #ifdef HAVE_WINDOW_SYSTEM
24163 /* On a GUI frame, when the right fringe (left fringe for R2L rows)
24164 is turned off, we precede the truncation/continuation glyphs by a
24165 stretch glyph whose width is computed such that these special
24166 glyphs are aligned at the window margin, even when very different
24167 fonts are used in different glyph rows. */
24168 if (FRAME_WINDOW_P (temp_it
.f
)
24169 /* init_iterator calls this with it->glyph_row == NULL, and it
24170 wants only the pixel width of the truncation/continuation
24172 && temp_it
.glyph_row
24173 /* insert_left_trunc_glyphs calls us at the beginning of the
24174 row, and it has its own calculation of the stretch glyph
24176 && temp_it
.glyph_row
->used
[TEXT_AREA
] > 0
24177 && (temp_it
.glyph_row
->reversed_p
24178 ? WINDOW_LEFT_FRINGE_WIDTH (temp_it
.w
)
24179 : WINDOW_RIGHT_FRINGE_WIDTH (temp_it
.w
)) == 0)
24181 int stretch_width
= temp_it
.last_visible_x
- temp_it
.current_x
;
24183 if (stretch_width
> 0)
24185 struct face
*face
= FACE_FROM_ID (temp_it
.f
, temp_it
.face_id
);
24186 struct font
*font
=
24187 face
->font
? face
->font
: FRAME_FONT (temp_it
.f
);
24188 int stretch_ascent
=
24189 (((temp_it
.ascent
+ temp_it
.descent
)
24190 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
24192 append_stretch_glyph (&temp_it
, make_number (0), stretch_width
,
24193 temp_it
.ascent
+ temp_it
.descent
,
24200 temp_it
.what
= IT_CHARACTER
;
24202 temp_it
.c
= temp_it
.char_to_display
= GLYPH_CHAR (glyph
);
24203 temp_it
.face_id
= GLYPH_FACE (glyph
);
24204 temp_it
.len
= CHAR_BYTES (temp_it
.c
);
24206 PRODUCE_GLYPHS (&temp_it
);
24207 it
->pixel_width
= temp_it
.pixel_width
;
24208 it
->nglyphs
= temp_it
.pixel_width
;
24211 #ifdef HAVE_WINDOW_SYSTEM
24213 /* Calculate line-height and line-spacing properties.
24214 An integer value specifies explicit pixel value.
24215 A float value specifies relative value to current face height.
24216 A cons (float . face-name) specifies relative value to
24217 height of specified face font.
24219 Returns height in pixels, or nil. */
24223 calc_line_height_property (struct it
*it
, Lisp_Object val
, struct font
*font
,
24224 int boff
, int override
)
24226 Lisp_Object face_name
= Qnil
;
24227 int ascent
, descent
, height
;
24229 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
24234 face_name
= XCAR (val
);
24236 if (!NUMBERP (val
))
24237 val
= make_number (1);
24238 if (NILP (face_name
))
24240 height
= it
->ascent
+ it
->descent
;
24245 if (NILP (face_name
))
24247 font
= FRAME_FONT (it
->f
);
24248 boff
= FRAME_BASELINE_OFFSET (it
->f
);
24250 else if (EQ (face_name
, Qt
))
24259 face_id
= lookup_named_face (it
->f
, face_name
, 0);
24261 return make_number (-1);
24263 face
= FACE_FROM_ID (it
->f
, face_id
);
24266 return make_number (-1);
24267 boff
= font
->baseline_offset
;
24268 if (font
->vertical_centering
)
24269 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
24272 ascent
= FONT_BASE (font
) + boff
;
24273 descent
= FONT_DESCENT (font
) - boff
;
24277 it
->override_ascent
= ascent
;
24278 it
->override_descent
= descent
;
24279 it
->override_boff
= boff
;
24282 height
= ascent
+ descent
;
24286 height
= (int)(XFLOAT_DATA (val
) * height
);
24287 else if (INTEGERP (val
))
24288 height
*= XINT (val
);
24290 return make_number (height
);
24294 /* Append a glyph for a glyphless character to IT->glyph_row. FACE_ID
24295 is a face ID to be used for the glyph. FOR_NO_FONT is nonzero if
24296 and only if this is for a character for which no font was found.
24298 If the display method (it->glyphless_method) is
24299 GLYPHLESS_DISPLAY_ACRONYM or GLYPHLESS_DISPLAY_HEX_CODE, LEN is a
24300 length of the acronym or the hexadecimal string, UPPER_XOFF and
24301 UPPER_YOFF are pixel offsets for the upper part of the string,
24302 LOWER_XOFF and LOWER_YOFF are for the lower part.
24304 For the other display methods, LEN through LOWER_YOFF are zero. */
24307 append_glyphless_glyph (struct it
*it
, int face_id
, int for_no_font
, int len
,
24308 short upper_xoff
, short upper_yoff
,
24309 short lower_xoff
, short lower_yoff
)
24311 struct glyph
*glyph
;
24312 enum glyph_row_area area
= it
->area
;
24314 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24315 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24317 /* If the glyph row is reversed, we need to prepend the glyph
24318 rather than append it. */
24319 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24323 /* Make room for the additional glyph. */
24324 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
24326 glyph
= it
->glyph_row
->glyphs
[area
];
24328 glyph
->charpos
= CHARPOS (it
->position
);
24329 glyph
->object
= it
->object
;
24330 glyph
->pixel_width
= it
->pixel_width
;
24331 glyph
->ascent
= it
->ascent
;
24332 glyph
->descent
= it
->descent
;
24333 glyph
->voffset
= it
->voffset
;
24334 glyph
->type
= GLYPHLESS_GLYPH
;
24335 glyph
->u
.glyphless
.method
= it
->glyphless_method
;
24336 glyph
->u
.glyphless
.for_no_font
= for_no_font
;
24337 glyph
->u
.glyphless
.len
= len
;
24338 glyph
->u
.glyphless
.ch
= it
->c
;
24339 glyph
->slice
.glyphless
.upper_xoff
= upper_xoff
;
24340 glyph
->slice
.glyphless
.upper_yoff
= upper_yoff
;
24341 glyph
->slice
.glyphless
.lower_xoff
= lower_xoff
;
24342 glyph
->slice
.glyphless
.lower_yoff
= lower_yoff
;
24343 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24344 glyph
->multibyte_p
= it
->multibyte_p
;
24345 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24347 /* In R2L rows, the left and the right box edges need to be
24348 drawn in reverse direction. */
24349 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24350 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24354 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24355 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24357 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
24358 || it
->phys_descent
> it
->descent
);
24359 glyph
->padding_p
= 0;
24360 glyph
->glyph_not_available_p
= 0;
24361 glyph
->face_id
= face_id
;
24362 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24365 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24366 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24368 glyph
->bidi_type
= it
->bidi_it
.type
;
24370 ++it
->glyph_row
->used
[area
];
24373 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24377 /* Produce a glyph for a glyphless character for iterator IT.
24378 IT->glyphless_method specifies which method to use for displaying
24379 the character. See the description of enum
24380 glyphless_display_method in dispextern.h for the detail.
24382 FOR_NO_FONT is nonzero if and only if this is for a character for
24383 which no font was found. ACRONYM, if non-nil, is an acronym string
24384 for the character. */
24387 produce_glyphless_glyph (struct it
*it
, int for_no_font
, Lisp_Object acronym
)
24392 int base_width
, base_height
, width
, height
;
24393 short upper_xoff
, upper_yoff
, lower_xoff
, lower_yoff
;
24396 /* Get the metrics of the base font. We always refer to the current
24398 face
= FACE_FROM_ID (it
->f
, it
->face_id
)->ascii_face
;
24399 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24400 it
->ascent
= FONT_BASE (font
) + font
->baseline_offset
;
24401 it
->descent
= FONT_DESCENT (font
) - font
->baseline_offset
;
24402 base_height
= it
->ascent
+ it
->descent
;
24403 base_width
= font
->average_width
;
24405 /* Get a face ID for the glyph by utilizing a cache (the same way as
24406 done for `escape-glyph' in get_next_display_element). */
24407 if (it
->f
== last_glyphless_glyph_frame
24408 && it
->face_id
== last_glyphless_glyph_face_id
)
24410 face_id
= last_glyphless_glyph_merged_face_id
;
24414 /* Merge the `glyphless-char' face into the current face. */
24415 face_id
= merge_faces (it
->f
, Qglyphless_char
, 0, it
->face_id
);
24416 last_glyphless_glyph_frame
= it
->f
;
24417 last_glyphless_glyph_face_id
= it
->face_id
;
24418 last_glyphless_glyph_merged_face_id
= face_id
;
24421 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_THIN_SPACE
)
24423 it
->pixel_width
= THIN_SPACE_WIDTH
;
24425 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
24427 else if (it
->glyphless_method
== GLYPHLESS_DISPLAY_EMPTY_BOX
)
24429 width
= CHAR_WIDTH (it
->c
);
24432 else if (width
> 4)
24434 it
->pixel_width
= base_width
* width
;
24436 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
24442 unsigned int code
[6];
24444 int ascent
, descent
;
24445 struct font_metrics metrics_upper
, metrics_lower
;
24447 face
= FACE_FROM_ID (it
->f
, face_id
);
24448 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24449 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24451 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_ACRONYM
)
24453 if (! STRINGP (acronym
) && CHAR_TABLE_P (Vglyphless_char_display
))
24454 acronym
= CHAR_TABLE_REF (Vglyphless_char_display
, it
->c
);
24455 if (CONSP (acronym
))
24456 acronym
= XCAR (acronym
);
24457 str
= STRINGP (acronym
) ? SSDATA (acronym
) : "";
24461 eassert (it
->glyphless_method
== GLYPHLESS_DISPLAY_HEX_CODE
);
24462 sprintf (buf
, "%0*X", it
->c
< 0x10000 ? 4 : 6, it
->c
);
24465 for (len
= 0; str
[len
] && ASCII_BYTE_P (str
[len
]) && len
< 6; len
++)
24466 code
[len
] = font
->driver
->encode_char (font
, str
[len
]);
24467 upper_len
= (len
+ 1) / 2;
24468 font
->driver
->text_extents (font
, code
, upper_len
,
24470 font
->driver
->text_extents (font
, code
+ upper_len
, len
- upper_len
,
24475 /* +4 is for vertical bars of a box plus 1-pixel spaces at both side. */
24476 width
= max (metrics_upper
.width
, metrics_lower
.width
) + 4;
24477 upper_xoff
= upper_yoff
= 2; /* the typical case */
24478 if (base_width
>= width
)
24480 /* Align the upper to the left, the lower to the right. */
24481 it
->pixel_width
= base_width
;
24482 lower_xoff
= base_width
- 2 - metrics_lower
.width
;
24486 /* Center the shorter one. */
24487 it
->pixel_width
= width
;
24488 if (metrics_upper
.width
>= metrics_lower
.width
)
24489 lower_xoff
= (width
- metrics_lower
.width
) / 2;
24492 /* FIXME: This code doesn't look right. It formerly was
24493 missing the "lower_xoff = 0;", which couldn't have
24494 been right since it left lower_xoff uninitialized. */
24496 upper_xoff
= (width
- metrics_upper
.width
) / 2;
24500 /* +5 is for horizontal bars of a box plus 1-pixel spaces at
24501 top, bottom, and between upper and lower strings. */
24502 height
= (metrics_upper
.ascent
+ metrics_upper
.descent
24503 + metrics_lower
.ascent
+ metrics_lower
.descent
) + 5;
24504 /* Center vertically.
24505 H:base_height, D:base_descent
24506 h:height, ld:lower_descent, la:lower_ascent, ud:upper_descent
24508 ascent = - (D - H/2 - h/2 + 1); "+ 1" for rounding up
24509 descent = D - H/2 + h/2;
24510 lower_yoff = descent - 2 - ld;
24511 upper_yoff = lower_yoff - la - 1 - ud; */
24512 ascent
= - (it
->descent
- (base_height
+ height
+ 1) / 2);
24513 descent
= it
->descent
- (base_height
- height
) / 2;
24514 lower_yoff
= descent
- 2 - metrics_lower
.descent
;
24515 upper_yoff
= (lower_yoff
- metrics_lower
.ascent
- 1
24516 - metrics_upper
.descent
);
24517 /* Don't make the height shorter than the base height. */
24518 if (height
> base_height
)
24520 it
->ascent
= ascent
;
24521 it
->descent
= descent
;
24525 it
->phys_ascent
= it
->ascent
;
24526 it
->phys_descent
= it
->descent
;
24528 append_glyphless_glyph (it
, face_id
, for_no_font
, len
,
24529 upper_xoff
, upper_yoff
,
24530 lower_xoff
, lower_yoff
);
24532 take_vertical_position_into_account (it
);
24537 Produce glyphs/get display metrics for the display element IT is
24538 loaded with. See the description of struct it in dispextern.h
24539 for an overview of struct it. */
24542 x_produce_glyphs (struct it
*it
)
24544 int extra_line_spacing
= it
->extra_line_spacing
;
24546 it
->glyph_not_available_p
= 0;
24548 if (it
->what
== IT_CHARACTER
)
24551 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24552 struct font
*font
= face
->font
;
24553 struct font_metrics
*pcm
= NULL
;
24554 int boff
; /* baseline offset */
24558 /* When no suitable font is found, display this character by
24559 the method specified in the first extra slot of
24560 Vglyphless_char_display. */
24561 Lisp_Object acronym
= lookup_glyphless_char_display (-1, it
);
24563 eassert (it
->what
== IT_GLYPHLESS
);
24564 produce_glyphless_glyph (it
, 1, STRINGP (acronym
) ? acronym
: Qnil
);
24568 boff
= font
->baseline_offset
;
24569 if (font
->vertical_centering
)
24570 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
24572 if (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t')
24578 if (it
->override_ascent
>= 0)
24580 it
->ascent
= it
->override_ascent
;
24581 it
->descent
= it
->override_descent
;
24582 boff
= it
->override_boff
;
24586 it
->ascent
= FONT_BASE (font
) + boff
;
24587 it
->descent
= FONT_DESCENT (font
) - boff
;
24590 if (get_char_glyph_code (it
->char_to_display
, font
, &char2b
))
24592 pcm
= get_per_char_metric (font
, &char2b
);
24593 if (pcm
->width
== 0
24594 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
24600 it
->phys_ascent
= pcm
->ascent
+ boff
;
24601 it
->phys_descent
= pcm
->descent
- boff
;
24602 it
->pixel_width
= pcm
->width
;
24606 it
->glyph_not_available_p
= 1;
24607 it
->phys_ascent
= it
->ascent
;
24608 it
->phys_descent
= it
->descent
;
24609 it
->pixel_width
= font
->space_width
;
24612 if (it
->constrain_row_ascent_descent_p
)
24614 if (it
->descent
> it
->max_descent
)
24616 it
->ascent
+= it
->descent
- it
->max_descent
;
24617 it
->descent
= it
->max_descent
;
24619 if (it
->ascent
> it
->max_ascent
)
24621 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
24622 it
->ascent
= it
->max_ascent
;
24624 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
24625 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
24626 extra_line_spacing
= 0;
24629 /* If this is a space inside a region of text with
24630 `space-width' property, change its width. */
24631 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
24633 it
->pixel_width
*= XFLOATINT (it
->space_width
);
24635 /* If face has a box, add the box thickness to the character
24636 height. If character has a box line to the left and/or
24637 right, add the box line width to the character's width. */
24638 if (face
->box
!= FACE_NO_BOX
)
24640 int thick
= face
->box_line_width
;
24644 it
->ascent
+= thick
;
24645 it
->descent
+= thick
;
24650 if (it
->start_of_box_run_p
)
24651 it
->pixel_width
+= thick
;
24652 if (it
->end_of_box_run_p
)
24653 it
->pixel_width
+= thick
;
24656 /* If face has an overline, add the height of the overline
24657 (1 pixel) and a 1 pixel margin to the character height. */
24658 if (face
->overline_p
)
24659 it
->ascent
+= overline_margin
;
24661 if (it
->constrain_row_ascent_descent_p
)
24663 if (it
->ascent
> it
->max_ascent
)
24664 it
->ascent
= it
->max_ascent
;
24665 if (it
->descent
> it
->max_descent
)
24666 it
->descent
= it
->max_descent
;
24669 take_vertical_position_into_account (it
);
24671 /* If we have to actually produce glyphs, do it. */
24676 /* Translate a space with a `space-width' property
24677 into a stretch glyph. */
24678 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
24679 / FONT_HEIGHT (font
));
24680 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
24681 it
->ascent
+ it
->descent
, ascent
);
24686 /* If characters with lbearing or rbearing are displayed
24687 in this line, record that fact in a flag of the
24688 glyph row. This is used to optimize X output code. */
24689 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
24690 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
24692 if (! stretched_p
&& it
->pixel_width
== 0)
24693 /* We assure that all visible glyphs have at least 1-pixel
24695 it
->pixel_width
= 1;
24697 else if (it
->char_to_display
== '\n')
24699 /* A newline has no width, but we need the height of the
24700 line. But if previous part of the line sets a height,
24701 don't increase that height */
24703 Lisp_Object height
;
24704 Lisp_Object total_height
= Qnil
;
24706 it
->override_ascent
= -1;
24707 it
->pixel_width
= 0;
24710 height
= get_it_property (it
, Qline_height
);
24711 /* Split (line-height total-height) list */
24713 && CONSP (XCDR (height
))
24714 && NILP (XCDR (XCDR (height
))))
24716 total_height
= XCAR (XCDR (height
));
24717 height
= XCAR (height
);
24719 height
= calc_line_height_property (it
, height
, font
, boff
, 1);
24721 if (it
->override_ascent
>= 0)
24723 it
->ascent
= it
->override_ascent
;
24724 it
->descent
= it
->override_descent
;
24725 boff
= it
->override_boff
;
24729 it
->ascent
= FONT_BASE (font
) + boff
;
24730 it
->descent
= FONT_DESCENT (font
) - boff
;
24733 if (EQ (height
, Qt
))
24735 if (it
->descent
> it
->max_descent
)
24737 it
->ascent
+= it
->descent
- it
->max_descent
;
24738 it
->descent
= it
->max_descent
;
24740 if (it
->ascent
> it
->max_ascent
)
24742 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
24743 it
->ascent
= it
->max_ascent
;
24745 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
24746 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
24747 it
->constrain_row_ascent_descent_p
= 1;
24748 extra_line_spacing
= 0;
24752 Lisp_Object spacing
;
24754 it
->phys_ascent
= it
->ascent
;
24755 it
->phys_descent
= it
->descent
;
24757 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
24758 && face
->box
!= FACE_NO_BOX
24759 && face
->box_line_width
> 0)
24761 it
->ascent
+= face
->box_line_width
;
24762 it
->descent
+= face
->box_line_width
;
24765 && XINT (height
) > it
->ascent
+ it
->descent
)
24766 it
->ascent
= XINT (height
) - it
->descent
;
24768 if (!NILP (total_height
))
24769 spacing
= calc_line_height_property (it
, total_height
, font
, boff
, 0);
24772 spacing
= get_it_property (it
, Qline_spacing
);
24773 spacing
= calc_line_height_property (it
, spacing
, font
, boff
, 0);
24775 if (INTEGERP (spacing
))
24777 extra_line_spacing
= XINT (spacing
);
24778 if (!NILP (total_height
))
24779 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
24783 else /* i.e. (it->char_to_display == '\t') */
24785 if (font
->space_width
> 0)
24787 int tab_width
= it
->tab_width
* font
->space_width
;
24788 int x
= it
->current_x
+ it
->continuation_lines_width
;
24789 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
24791 /* If the distance from the current position to the next tab
24792 stop is less than a space character width, use the
24793 tab stop after that. */
24794 if (next_tab_x
- x
< font
->space_width
)
24795 next_tab_x
+= tab_width
;
24797 it
->pixel_width
= next_tab_x
- x
;
24799 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
24800 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
24804 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
24805 it
->ascent
+ it
->descent
, it
->ascent
);
24810 it
->pixel_width
= 0;
24815 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
24817 /* A static composition.
24819 Note: A composition is represented as one glyph in the
24820 glyph matrix. There are no padding glyphs.
24822 Important note: pixel_width, ascent, and descent are the
24823 values of what is drawn by draw_glyphs (i.e. the values of
24824 the overall glyphs composed). */
24825 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24826 int boff
; /* baseline offset */
24827 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
24828 int glyph_len
= cmp
->glyph_len
;
24829 struct font
*font
= face
->font
;
24833 /* If we have not yet calculated pixel size data of glyphs of
24834 the composition for the current face font, calculate them
24835 now. Theoretically, we have to check all fonts for the
24836 glyphs, but that requires much time and memory space. So,
24837 here we check only the font of the first glyph. This may
24838 lead to incorrect display, but it's very rare, and C-l
24839 (recenter-top-bottom) can correct the display anyway. */
24840 if (! cmp
->font
|| cmp
->font
!= font
)
24842 /* Ascent and descent of the font of the first character
24843 of this composition (adjusted by baseline offset).
24844 Ascent and descent of overall glyphs should not be less
24845 than these, respectively. */
24846 int font_ascent
, font_descent
, font_height
;
24847 /* Bounding box of the overall glyphs. */
24848 int leftmost
, rightmost
, lowest
, highest
;
24849 int lbearing
, rbearing
;
24850 int i
, width
, ascent
, descent
;
24851 int left_padded
= 0, right_padded
= 0;
24852 int c
IF_LINT (= 0); /* cmp->glyph_len can't be zero; see Bug#8512 */
24854 struct font_metrics
*pcm
;
24855 int font_not_found_p
;
24858 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
24859 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
24861 if (glyph_len
< cmp
->glyph_len
)
24863 for (i
= 0; i
< glyph_len
; i
++)
24865 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
24867 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
24872 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
24873 : IT_CHARPOS (*it
));
24874 /* If no suitable font is found, use the default font. */
24875 font_not_found_p
= font
== NULL
;
24876 if (font_not_found_p
)
24878 face
= face
->ascii_face
;
24881 boff
= font
->baseline_offset
;
24882 if (font
->vertical_centering
)
24883 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
24884 font_ascent
= FONT_BASE (font
) + boff
;
24885 font_descent
= FONT_DESCENT (font
) - boff
;
24886 font_height
= FONT_HEIGHT (font
);
24891 if (! font_not_found_p
)
24893 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
24895 pcm
= get_per_char_metric (font
, &char2b
);
24898 /* Initialize the bounding box. */
24901 width
= cmp
->glyph_len
> 0 ? pcm
->width
: 0;
24902 ascent
= pcm
->ascent
;
24903 descent
= pcm
->descent
;
24904 lbearing
= pcm
->lbearing
;
24905 rbearing
= pcm
->rbearing
;
24909 width
= cmp
->glyph_len
> 0 ? font
->space_width
: 0;
24910 ascent
= FONT_BASE (font
);
24911 descent
= FONT_DESCENT (font
);
24918 lowest
= - descent
+ boff
;
24919 highest
= ascent
+ boff
;
24921 if (! font_not_found_p
24922 && font
->default_ascent
24923 && CHAR_TABLE_P (Vuse_default_ascent
)
24924 && !NILP (Faref (Vuse_default_ascent
,
24925 make_number (it
->char_to_display
))))
24926 highest
= font
->default_ascent
+ boff
;
24928 /* Draw the first glyph at the normal position. It may be
24929 shifted to right later if some other glyphs are drawn
24931 cmp
->offsets
[i
* 2] = 0;
24932 cmp
->offsets
[i
* 2 + 1] = boff
;
24933 cmp
->lbearing
= lbearing
;
24934 cmp
->rbearing
= rbearing
;
24936 /* Set cmp->offsets for the remaining glyphs. */
24937 for (i
++; i
< glyph_len
; i
++)
24939 int left
, right
, btm
, top
;
24940 int ch
= COMPOSITION_GLYPH (cmp
, i
);
24942 struct face
*this_face
;
24946 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
24947 this_face
= FACE_FROM_ID (it
->f
, face_id
);
24948 font
= this_face
->font
;
24954 get_char_face_and_encoding (it
->f
, ch
, face_id
,
24956 pcm
= get_per_char_metric (font
, &char2b
);
24959 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
24962 width
= pcm
->width
;
24963 ascent
= pcm
->ascent
;
24964 descent
= pcm
->descent
;
24965 lbearing
= pcm
->lbearing
;
24966 rbearing
= pcm
->rbearing
;
24967 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
24969 /* Relative composition with or without
24970 alternate chars. */
24971 left
= (leftmost
+ rightmost
- width
) / 2;
24972 btm
= - descent
+ boff
;
24973 if (font
->relative_compose
24974 && (! CHAR_TABLE_P (Vignore_relative_composition
)
24975 || NILP (Faref (Vignore_relative_composition
,
24976 make_number (ch
)))))
24979 if (- descent
>= font
->relative_compose
)
24980 /* One extra pixel between two glyphs. */
24982 else if (ascent
<= 0)
24983 /* One extra pixel between two glyphs. */
24984 btm
= lowest
- 1 - ascent
- descent
;
24989 /* A composition rule is specified by an integer
24990 value that encodes global and new reference
24991 points (GREF and NREF). GREF and NREF are
24992 specified by numbers as below:
24994 0---1---2 -- ascent
24998 9--10--11 -- center
25000 ---3---4---5--- baseline
25002 6---7---8 -- descent
25004 int rule
= COMPOSITION_RULE (cmp
, i
);
25005 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
25007 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
25008 grefx
= gref
% 3, nrefx
= nref
% 3;
25009 grefy
= gref
/ 3, nrefy
= nref
/ 3;
25011 xoff
= font_height
* (xoff
- 128) / 256;
25013 yoff
= font_height
* (yoff
- 128) / 256;
25016 + grefx
* (rightmost
- leftmost
) / 2
25017 - nrefx
* width
/ 2
25020 btm
= ((grefy
== 0 ? highest
25022 : grefy
== 2 ? lowest
25023 : (highest
+ lowest
) / 2)
25024 - (nrefy
== 0 ? ascent
+ descent
25025 : nrefy
== 1 ? descent
- boff
25027 : (ascent
+ descent
) / 2)
25031 cmp
->offsets
[i
* 2] = left
;
25032 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
25034 /* Update the bounding box of the overall glyphs. */
25037 right
= left
+ width
;
25038 if (left
< leftmost
)
25040 if (right
> rightmost
)
25043 top
= btm
+ descent
+ ascent
;
25049 if (cmp
->lbearing
> left
+ lbearing
)
25050 cmp
->lbearing
= left
+ lbearing
;
25051 if (cmp
->rbearing
< left
+ rbearing
)
25052 cmp
->rbearing
= left
+ rbearing
;
25056 /* If there are glyphs whose x-offsets are negative,
25057 shift all glyphs to the right and make all x-offsets
25061 for (i
= 0; i
< cmp
->glyph_len
; i
++)
25062 cmp
->offsets
[i
* 2] -= leftmost
;
25063 rightmost
-= leftmost
;
25064 cmp
->lbearing
-= leftmost
;
25065 cmp
->rbearing
-= leftmost
;
25068 if (left_padded
&& cmp
->lbearing
< 0)
25070 for (i
= 0; i
< cmp
->glyph_len
; i
++)
25071 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
25072 rightmost
-= cmp
->lbearing
;
25073 cmp
->rbearing
-= cmp
->lbearing
;
25076 if (right_padded
&& rightmost
< cmp
->rbearing
)
25078 rightmost
= cmp
->rbearing
;
25081 cmp
->pixel_width
= rightmost
;
25082 cmp
->ascent
= highest
;
25083 cmp
->descent
= - lowest
;
25084 if (cmp
->ascent
< font_ascent
)
25085 cmp
->ascent
= font_ascent
;
25086 if (cmp
->descent
< font_descent
)
25087 cmp
->descent
= font_descent
;
25091 && (cmp
->lbearing
< 0
25092 || cmp
->rbearing
> cmp
->pixel_width
))
25093 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25095 it
->pixel_width
= cmp
->pixel_width
;
25096 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
25097 it
->descent
= it
->phys_descent
= cmp
->descent
;
25098 if (face
->box
!= FACE_NO_BOX
)
25100 int thick
= face
->box_line_width
;
25104 it
->ascent
+= thick
;
25105 it
->descent
+= thick
;
25110 if (it
->start_of_box_run_p
)
25111 it
->pixel_width
+= thick
;
25112 if (it
->end_of_box_run_p
)
25113 it
->pixel_width
+= thick
;
25116 /* If face has an overline, add the height of the overline
25117 (1 pixel) and a 1 pixel margin to the character height. */
25118 if (face
->overline_p
)
25119 it
->ascent
+= overline_margin
;
25121 take_vertical_position_into_account (it
);
25122 if (it
->ascent
< 0)
25124 if (it
->descent
< 0)
25127 if (it
->glyph_row
&& cmp
->glyph_len
> 0)
25128 append_composite_glyph (it
);
25130 else if (it
->what
== IT_COMPOSITION
)
25132 /* A dynamic (automatic) composition. */
25133 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25134 Lisp_Object gstring
;
25135 struct font_metrics metrics
;
25139 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
25141 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
25144 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
25145 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25146 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
25147 it
->descent
= it
->phys_descent
= metrics
.descent
;
25148 if (face
->box
!= FACE_NO_BOX
)
25150 int thick
= face
->box_line_width
;
25154 it
->ascent
+= thick
;
25155 it
->descent
+= thick
;
25160 if (it
->start_of_box_run_p
)
25161 it
->pixel_width
+= thick
;
25162 if (it
->end_of_box_run_p
)
25163 it
->pixel_width
+= thick
;
25165 /* If face has an overline, add the height of the overline
25166 (1 pixel) and a 1 pixel margin to the character height. */
25167 if (face
->overline_p
)
25168 it
->ascent
+= overline_margin
;
25169 take_vertical_position_into_account (it
);
25170 if (it
->ascent
< 0)
25172 if (it
->descent
< 0)
25176 append_composite_glyph (it
);
25178 else if (it
->what
== IT_GLYPHLESS
)
25179 produce_glyphless_glyph (it
, 0, Qnil
);
25180 else if (it
->what
== IT_IMAGE
)
25181 produce_image_glyph (it
);
25182 else if (it
->what
== IT_STRETCH
)
25183 produce_stretch_glyph (it
);
25186 /* Accumulate dimensions. Note: can't assume that it->descent > 0
25187 because this isn't true for images with `:ascent 100'. */
25188 eassert (it
->ascent
>= 0 && it
->descent
>= 0);
25189 if (it
->area
== TEXT_AREA
)
25190 it
->current_x
+= it
->pixel_width
;
25192 if (extra_line_spacing
> 0)
25194 it
->descent
+= extra_line_spacing
;
25195 if (extra_line_spacing
> it
->max_extra_line_spacing
)
25196 it
->max_extra_line_spacing
= extra_line_spacing
;
25199 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
25200 it
->max_descent
= max (it
->max_descent
, it
->descent
);
25201 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
25202 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
25206 Output LEN glyphs starting at START at the nominal cursor position.
25207 Advance the nominal cursor over the text. The global variable
25208 updated_window contains the window being updated, updated_row is
25209 the glyph row being updated, and updated_area is the area of that
25210 row being updated. */
25213 x_write_glyphs (struct glyph
*start
, int len
)
25215 int x
, hpos
, chpos
= updated_window
->phys_cursor
.hpos
;
25217 eassert (updated_window
&& updated_row
);
25218 /* When the window is hscrolled, cursor hpos can legitimately be out
25219 of bounds, but we draw the cursor at the corresponding window
25220 margin in that case. */
25221 if (!updated_row
->reversed_p
&& chpos
< 0)
25223 if (updated_row
->reversed_p
&& chpos
>= updated_row
->used
[TEXT_AREA
])
25224 chpos
= updated_row
->used
[TEXT_AREA
] - 1;
25228 /* Write glyphs. */
25230 hpos
= start
- updated_row
->glyphs
[updated_area
];
25231 x
= draw_glyphs (updated_window
, output_cursor
.x
,
25232 updated_row
, updated_area
,
25234 DRAW_NORMAL_TEXT
, 0);
25236 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
25237 if (updated_area
== TEXT_AREA
25238 && updated_window
->phys_cursor_on_p
25239 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
25241 && chpos
< hpos
+ len
)
25242 updated_window
->phys_cursor_on_p
= 0;
25246 /* Advance the output cursor. */
25247 output_cursor
.hpos
+= len
;
25248 output_cursor
.x
= x
;
25253 Insert LEN glyphs from START at the nominal cursor position. */
25256 x_insert_glyphs (struct glyph
*start
, int len
)
25260 int line_height
, shift_by_width
, shifted_region_width
;
25261 struct glyph_row
*row
;
25262 struct glyph
*glyph
;
25263 int frame_x
, frame_y
;
25266 eassert (updated_window
&& updated_row
);
25268 w
= updated_window
;
25269 f
= XFRAME (WINDOW_FRAME (w
));
25271 /* Get the height of the line we are in. */
25273 line_height
= row
->height
;
25275 /* Get the width of the glyphs to insert. */
25276 shift_by_width
= 0;
25277 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
25278 shift_by_width
+= glyph
->pixel_width
;
25280 /* Get the width of the region to shift right. */
25281 shifted_region_width
= (window_box_width (w
, updated_area
)
25286 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
25287 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
25289 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
25290 line_height
, shift_by_width
);
25292 /* Write the glyphs. */
25293 hpos
= start
- row
->glyphs
[updated_area
];
25294 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
25296 DRAW_NORMAL_TEXT
, 0);
25298 /* Advance the output cursor. */
25299 output_cursor
.hpos
+= len
;
25300 output_cursor
.x
+= shift_by_width
;
25306 Erase the current text line from the nominal cursor position
25307 (inclusive) to pixel column TO_X (exclusive). The idea is that
25308 everything from TO_X onward is already erased.
25310 TO_X is a pixel position relative to updated_area of
25311 updated_window. TO_X == -1 means clear to the end of this area. */
25314 x_clear_end_of_line (int to_x
)
25317 struct window
*w
= updated_window
;
25318 int max_x
, min_y
, max_y
;
25319 int from_x
, from_y
, to_y
;
25321 eassert (updated_window
&& updated_row
);
25322 f
= XFRAME (w
->frame
);
25324 if (updated_row
->full_width_p
)
25325 max_x
= WINDOW_TOTAL_WIDTH (w
);
25327 max_x
= window_box_width (w
, updated_area
);
25328 max_y
= window_text_bottom_y (w
);
25330 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
25331 of window. For TO_X > 0, truncate to end of drawing area. */
25337 to_x
= min (to_x
, max_x
);
25339 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
25341 /* Notice if the cursor will be cleared by this operation. */
25342 if (!updated_row
->full_width_p
)
25343 notice_overwritten_cursor (w
, updated_area
,
25344 output_cursor
.x
, -1,
25346 MATRIX_ROW_BOTTOM_Y (updated_row
));
25348 from_x
= output_cursor
.x
;
25350 /* Translate to frame coordinates. */
25351 if (updated_row
->full_width_p
)
25353 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
25354 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
25358 int area_left
= window_box_left (w
, updated_area
);
25359 from_x
+= area_left
;
25363 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
25364 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
25365 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
25367 /* Prevent inadvertently clearing to end of the X window. */
25368 if (to_x
> from_x
&& to_y
> from_y
)
25371 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
25372 to_x
- from_x
, to_y
- from_y
);
25377 #endif /* HAVE_WINDOW_SYSTEM */
25381 /***********************************************************************
25383 ***********************************************************************/
25385 /* Value is the internal representation of the specified cursor type
25386 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
25387 of the bar cursor. */
25389 static enum text_cursor_kinds
25390 get_specified_cursor_type (Lisp_Object arg
, int *width
)
25392 enum text_cursor_kinds type
;
25397 if (EQ (arg
, Qbox
))
25398 return FILLED_BOX_CURSOR
;
25400 if (EQ (arg
, Qhollow
))
25401 return HOLLOW_BOX_CURSOR
;
25403 if (EQ (arg
, Qbar
))
25410 && EQ (XCAR (arg
), Qbar
)
25411 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
25413 *width
= XINT (XCDR (arg
));
25417 if (EQ (arg
, Qhbar
))
25420 return HBAR_CURSOR
;
25424 && EQ (XCAR (arg
), Qhbar
)
25425 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
25427 *width
= XINT (XCDR (arg
));
25428 return HBAR_CURSOR
;
25431 /* Treat anything unknown as "hollow box cursor".
25432 It was bad to signal an error; people have trouble fixing
25433 .Xdefaults with Emacs, when it has something bad in it. */
25434 type
= HOLLOW_BOX_CURSOR
;
25439 /* Set the default cursor types for specified frame. */
25441 set_frame_cursor_types (struct frame
*f
, Lisp_Object arg
)
25446 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
25447 FRAME_CURSOR_WIDTH (f
) = width
;
25449 /* By default, set up the blink-off state depending on the on-state. */
25451 tem
= Fassoc (arg
, Vblink_cursor_alist
);
25454 FRAME_BLINK_OFF_CURSOR (f
)
25455 = get_specified_cursor_type (XCDR (tem
), &width
);
25456 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
25459 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
25463 #ifdef HAVE_WINDOW_SYSTEM
25465 /* Return the cursor we want to be displayed in window W. Return
25466 width of bar/hbar cursor through WIDTH arg. Return with
25467 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
25468 (i.e. if the `system caret' should track this cursor).
25470 In a mini-buffer window, we want the cursor only to appear if we
25471 are reading input from this window. For the selected window, we
25472 want the cursor type given by the frame parameter or buffer local
25473 setting of cursor-type. If explicitly marked off, draw no cursor.
25474 In all other cases, we want a hollow box cursor. */
25476 static enum text_cursor_kinds
25477 get_window_cursor_type (struct window
*w
, struct glyph
*glyph
, int *width
,
25478 int *active_cursor
)
25480 struct frame
*f
= XFRAME (w
->frame
);
25481 struct buffer
*b
= XBUFFER (w
->buffer
);
25482 int cursor_type
= DEFAULT_CURSOR
;
25483 Lisp_Object alt_cursor
;
25484 int non_selected
= 0;
25486 *active_cursor
= 1;
25489 if (cursor_in_echo_area
25490 && FRAME_HAS_MINIBUF_P (f
)
25491 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
25493 if (w
== XWINDOW (echo_area_window
))
25495 if (EQ (BVAR (b
, cursor_type
), Qt
) || NILP (BVAR (b
, cursor_type
)))
25497 *width
= FRAME_CURSOR_WIDTH (f
);
25498 return FRAME_DESIRED_CURSOR (f
);
25501 return get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
25504 *active_cursor
= 0;
25508 /* Detect a nonselected window or nonselected frame. */
25509 else if (w
!= XWINDOW (f
->selected_window
)
25510 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)
25512 *active_cursor
= 0;
25514 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
25520 /* Never display a cursor in a window in which cursor-type is nil. */
25521 if (NILP (BVAR (b
, cursor_type
)))
25524 /* Get the normal cursor type for this window. */
25525 if (EQ (BVAR (b
, cursor_type
), Qt
))
25527 cursor_type
= FRAME_DESIRED_CURSOR (f
);
25528 *width
= FRAME_CURSOR_WIDTH (f
);
25531 cursor_type
= get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
25533 /* Use cursor-in-non-selected-windows instead
25534 for non-selected window or frame. */
25537 alt_cursor
= BVAR (b
, cursor_in_non_selected_windows
);
25538 if (!EQ (Qt
, alt_cursor
))
25539 return get_specified_cursor_type (alt_cursor
, width
);
25540 /* t means modify the normal cursor type. */
25541 if (cursor_type
== FILLED_BOX_CURSOR
)
25542 cursor_type
= HOLLOW_BOX_CURSOR
;
25543 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
25545 return cursor_type
;
25548 /* Use normal cursor if not blinked off. */
25549 if (!w
->cursor_off_p
)
25551 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
25553 if (cursor_type
== FILLED_BOX_CURSOR
)
25555 /* Using a block cursor on large images can be very annoying.
25556 So use a hollow cursor for "large" images.
25557 If image is not transparent (no mask), also use hollow cursor. */
25558 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
25559 if (img
!= NULL
&& IMAGEP (img
->spec
))
25561 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
25562 where N = size of default frame font size.
25563 This should cover most of the "tiny" icons people may use. */
25565 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
25566 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
25567 cursor_type
= HOLLOW_BOX_CURSOR
;
25570 else if (cursor_type
!= NO_CURSOR
)
25572 /* Display current only supports BOX and HOLLOW cursors for images.
25573 So for now, unconditionally use a HOLLOW cursor when cursor is
25574 not a solid box cursor. */
25575 cursor_type
= HOLLOW_BOX_CURSOR
;
25578 return cursor_type
;
25581 /* Cursor is blinked off, so determine how to "toggle" it. */
25583 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
25584 if ((alt_cursor
= Fassoc (BVAR (b
, cursor_type
), Vblink_cursor_alist
), !NILP (alt_cursor
)))
25585 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
25587 /* Then see if frame has specified a specific blink off cursor type. */
25588 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
25590 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
25591 return FRAME_BLINK_OFF_CURSOR (f
);
25595 /* Some people liked having a permanently visible blinking cursor,
25596 while others had very strong opinions against it. So it was
25597 decided to remove it. KFS 2003-09-03 */
25599 /* Finally perform built-in cursor blinking:
25600 filled box <-> hollow box
25601 wide [h]bar <-> narrow [h]bar
25602 narrow [h]bar <-> no cursor
25603 other type <-> no cursor */
25605 if (cursor_type
== FILLED_BOX_CURSOR
)
25606 return HOLLOW_BOX_CURSOR
;
25608 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
25611 return cursor_type
;
25619 /* Notice when the text cursor of window W has been completely
25620 overwritten by a drawing operation that outputs glyphs in AREA
25621 starting at X0 and ending at X1 in the line starting at Y0 and
25622 ending at Y1. X coordinates are area-relative. X1 < 0 means all
25623 the rest of the line after X0 has been written. Y coordinates
25624 are window-relative. */
25627 notice_overwritten_cursor (struct window
*w
, enum glyph_row_area area
,
25628 int x0
, int x1
, int y0
, int y1
)
25630 int cx0
, cx1
, cy0
, cy1
;
25631 struct glyph_row
*row
;
25633 if (!w
->phys_cursor_on_p
)
25635 if (area
!= TEXT_AREA
)
25638 if (w
->phys_cursor
.vpos
< 0
25639 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
25640 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
25641 !(row
->enabled_p
&& row
->displays_text_p
)))
25644 if (row
->cursor_in_fringe_p
)
25646 row
->cursor_in_fringe_p
= 0;
25647 draw_fringe_bitmap (w
, row
, row
->reversed_p
);
25648 w
->phys_cursor_on_p
= 0;
25652 cx0
= w
->phys_cursor
.x
;
25653 cx1
= cx0
+ w
->phys_cursor_width
;
25654 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
25657 /* The cursor image will be completely removed from the
25658 screen if the output area intersects the cursor area in
25659 y-direction. When we draw in [y0 y1[, and some part of
25660 the cursor is at y < y0, that part must have been drawn
25661 before. When scrolling, the cursor is erased before
25662 actually scrolling, so we don't come here. When not
25663 scrolling, the rows above the old cursor row must have
25664 changed, and in this case these rows must have written
25665 over the cursor image.
25667 Likewise if part of the cursor is below y1, with the
25668 exception of the cursor being in the first blank row at
25669 the buffer and window end because update_text_area
25670 doesn't draw that row. (Except when it does, but
25671 that's handled in update_text_area.) */
25673 cy0
= w
->phys_cursor
.y
;
25674 cy1
= cy0
+ w
->phys_cursor_height
;
25675 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
25678 w
->phys_cursor_on_p
= 0;
25681 #endif /* HAVE_WINDOW_SYSTEM */
25684 /************************************************************************
25686 ************************************************************************/
25688 #ifdef HAVE_WINDOW_SYSTEM
25691 Fix the display of area AREA of overlapping row ROW in window W
25692 with respect to the overlapping part OVERLAPS. */
25695 x_fix_overlapping_area (struct window
*w
, struct glyph_row
*row
,
25696 enum glyph_row_area area
, int overlaps
)
25703 for (i
= 0; i
< row
->used
[area
];)
25705 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
25707 int start
= i
, start_x
= x
;
25711 x
+= row
->glyphs
[area
][i
].pixel_width
;
25714 while (i
< row
->used
[area
]
25715 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
25717 draw_glyphs (w
, start_x
, row
, area
,
25719 DRAW_NORMAL_TEXT
, overlaps
);
25723 x
+= row
->glyphs
[area
][i
].pixel_width
;
25733 Draw the cursor glyph of window W in glyph row ROW. See the
25734 comment of draw_glyphs for the meaning of HL. */
25737 draw_phys_cursor_glyph (struct window
*w
, struct glyph_row
*row
,
25738 enum draw_glyphs_face hl
)
25740 /* If cursor hpos is out of bounds, don't draw garbage. This can
25741 happen in mini-buffer windows when switching between echo area
25742 glyphs and mini-buffer. */
25743 if ((row
->reversed_p
25744 ? (w
->phys_cursor
.hpos
>= 0)
25745 : (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])))
25747 int on_p
= w
->phys_cursor_on_p
;
25749 int hpos
= w
->phys_cursor
.hpos
;
25751 /* When the window is hscrolled, cursor hpos can legitimately be
25752 out of bounds, but we draw the cursor at the corresponding
25753 window margin in that case. */
25754 if (!row
->reversed_p
&& hpos
< 0)
25756 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
25757 hpos
= row
->used
[TEXT_AREA
] - 1;
25759 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
, hpos
, hpos
+ 1,
25761 w
->phys_cursor_on_p
= on_p
;
25763 if (hl
== DRAW_CURSOR
)
25764 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
25765 /* When we erase the cursor, and ROW is overlapped by other
25766 rows, make sure that these overlapping parts of other rows
25768 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
25770 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
25772 if (row
> w
->current_matrix
->rows
25773 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
25774 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
25775 OVERLAPS_ERASED_CURSOR
);
25777 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
25778 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
25779 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
25780 OVERLAPS_ERASED_CURSOR
);
25787 Erase the image of a cursor of window W from the screen. */
25790 erase_phys_cursor (struct window
*w
)
25792 struct frame
*f
= XFRAME (w
->frame
);
25793 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
25794 int hpos
= w
->phys_cursor
.hpos
;
25795 int vpos
= w
->phys_cursor
.vpos
;
25796 int mouse_face_here_p
= 0;
25797 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
25798 struct glyph_row
*cursor_row
;
25799 struct glyph
*cursor_glyph
;
25800 enum draw_glyphs_face hl
;
25802 /* No cursor displayed or row invalidated => nothing to do on the
25804 if (w
->phys_cursor_type
== NO_CURSOR
)
25805 goto mark_cursor_off
;
25807 /* VPOS >= active_glyphs->nrows means that window has been resized.
25808 Don't bother to erase the cursor. */
25809 if (vpos
>= active_glyphs
->nrows
)
25810 goto mark_cursor_off
;
25812 /* If row containing cursor is marked invalid, there is nothing we
25814 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
25815 if (!cursor_row
->enabled_p
)
25816 goto mark_cursor_off
;
25818 /* If line spacing is > 0, old cursor may only be partially visible in
25819 window after split-window. So adjust visible height. */
25820 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
25821 window_text_bottom_y (w
) - cursor_row
->y
);
25823 /* If row is completely invisible, don't attempt to delete a cursor which
25824 isn't there. This can happen if cursor is at top of a window, and
25825 we switch to a buffer with a header line in that window. */
25826 if (cursor_row
->visible_height
<= 0)
25827 goto mark_cursor_off
;
25829 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
25830 if (cursor_row
->cursor_in_fringe_p
)
25832 cursor_row
->cursor_in_fringe_p
= 0;
25833 draw_fringe_bitmap (w
, cursor_row
, cursor_row
->reversed_p
);
25834 goto mark_cursor_off
;
25837 /* This can happen when the new row is shorter than the old one.
25838 In this case, either draw_glyphs or clear_end_of_line
25839 should have cleared the cursor. Note that we wouldn't be
25840 able to erase the cursor in this case because we don't have a
25841 cursor glyph at hand. */
25842 if ((cursor_row
->reversed_p
25843 ? (w
->phys_cursor
.hpos
< 0)
25844 : (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])))
25845 goto mark_cursor_off
;
25847 /* When the window is hscrolled, cursor hpos can legitimately be out
25848 of bounds, but we draw the cursor at the corresponding window
25849 margin in that case. */
25850 if (!cursor_row
->reversed_p
&& hpos
< 0)
25852 if (cursor_row
->reversed_p
&& hpos
>= cursor_row
->used
[TEXT_AREA
])
25853 hpos
= cursor_row
->used
[TEXT_AREA
] - 1;
25855 /* If the cursor is in the mouse face area, redisplay that when
25856 we clear the cursor. */
25857 if (! NILP (hlinfo
->mouse_face_window
)
25858 && coords_in_mouse_face_p (w
, hpos
, vpos
)
25859 /* Don't redraw the cursor's spot in mouse face if it is at the
25860 end of a line (on a newline). The cursor appears there, but
25861 mouse highlighting does not. */
25862 && cursor_row
->used
[TEXT_AREA
] > hpos
&& hpos
>= 0)
25863 mouse_face_here_p
= 1;
25865 /* Maybe clear the display under the cursor. */
25866 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
25869 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
25872 cursor_glyph
= get_phys_cursor_glyph (w
);
25873 if (cursor_glyph
== NULL
)
25874 goto mark_cursor_off
;
25876 width
= cursor_glyph
->pixel_width
;
25877 left_x
= window_box_left_offset (w
, TEXT_AREA
);
25878 x
= w
->phys_cursor
.x
;
25880 width
-= left_x
- x
;
25881 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
25882 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
25883 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
25886 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
25889 /* Erase the cursor by redrawing the character underneath it. */
25890 if (mouse_face_here_p
)
25891 hl
= DRAW_MOUSE_FACE
;
25893 hl
= DRAW_NORMAL_TEXT
;
25894 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
25897 w
->phys_cursor_on_p
= 0;
25898 w
->phys_cursor_type
= NO_CURSOR
;
25903 Display or clear cursor of window W. If ON is zero, clear the
25904 cursor. If it is non-zero, display the cursor. If ON is nonzero,
25905 where to put the cursor is specified by HPOS, VPOS, X and Y. */
25908 display_and_set_cursor (struct window
*w
, int on
,
25909 int hpos
, int vpos
, int x
, int y
)
25911 struct frame
*f
= XFRAME (w
->frame
);
25912 int new_cursor_type
;
25913 int new_cursor_width
;
25915 struct glyph_row
*glyph_row
;
25916 struct glyph
*glyph
;
25918 /* This is pointless on invisible frames, and dangerous on garbaged
25919 windows and frames; in the latter case, the frame or window may
25920 be in the midst of changing its size, and x and y may be off the
25922 if (! FRAME_VISIBLE_P (f
)
25923 || FRAME_GARBAGED_P (f
)
25924 || vpos
>= w
->current_matrix
->nrows
25925 || hpos
>= w
->current_matrix
->matrix_w
)
25928 /* If cursor is off and we want it off, return quickly. */
25929 if (!on
&& !w
->phys_cursor_on_p
)
25932 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
25933 /* If cursor row is not enabled, we don't really know where to
25934 display the cursor. */
25935 if (!glyph_row
->enabled_p
)
25937 w
->phys_cursor_on_p
= 0;
25942 if (!glyph_row
->exact_window_width_line_p
25943 || (0 <= hpos
&& hpos
< glyph_row
->used
[TEXT_AREA
]))
25944 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
25946 eassert (input_blocked_p ());
25948 /* Set new_cursor_type to the cursor we want to be displayed. */
25949 new_cursor_type
= get_window_cursor_type (w
, glyph
,
25950 &new_cursor_width
, &active_cursor
);
25952 /* If cursor is currently being shown and we don't want it to be or
25953 it is in the wrong place, or the cursor type is not what we want,
25955 if (w
->phys_cursor_on_p
25957 || w
->phys_cursor
.x
!= x
25958 || w
->phys_cursor
.y
!= y
25959 || new_cursor_type
!= w
->phys_cursor_type
25960 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
25961 && new_cursor_width
!= w
->phys_cursor_width
)))
25962 erase_phys_cursor (w
);
25964 /* Don't check phys_cursor_on_p here because that flag is only set
25965 to zero in some cases where we know that the cursor has been
25966 completely erased, to avoid the extra work of erasing the cursor
25967 twice. In other words, phys_cursor_on_p can be 1 and the cursor
25968 still not be visible, or it has only been partly erased. */
25971 w
->phys_cursor_ascent
= glyph_row
->ascent
;
25972 w
->phys_cursor_height
= glyph_row
->height
;
25974 /* Set phys_cursor_.* before x_draw_.* is called because some
25975 of them may need the information. */
25976 w
->phys_cursor
.x
= x
;
25977 w
->phys_cursor
.y
= glyph_row
->y
;
25978 w
->phys_cursor
.hpos
= hpos
;
25979 w
->phys_cursor
.vpos
= vpos
;
25982 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
25983 new_cursor_type
, new_cursor_width
,
25984 on
, active_cursor
);
25988 /* Switch the display of W's cursor on or off, according to the value
25992 update_window_cursor (struct window
*w
, int on
)
25994 /* Don't update cursor in windows whose frame is in the process
25995 of being deleted. */
25996 if (w
->current_matrix
)
25998 int hpos
= w
->phys_cursor
.hpos
;
25999 int vpos
= w
->phys_cursor
.vpos
;
26000 struct glyph_row
*row
;
26002 if (vpos
>= w
->current_matrix
->nrows
26003 || hpos
>= w
->current_matrix
->matrix_w
)
26006 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26008 /* When the window is hscrolled, cursor hpos can legitimately be
26009 out of bounds, but we draw the cursor at the corresponding
26010 window margin in that case. */
26011 if (!row
->reversed_p
&& hpos
< 0)
26013 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26014 hpos
= row
->used
[TEXT_AREA
] - 1;
26017 display_and_set_cursor (w
, on
, hpos
, vpos
,
26018 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
26024 /* Call update_window_cursor with parameter ON_P on all leaf windows
26025 in the window tree rooted at W. */
26028 update_cursor_in_window_tree (struct window
*w
, int on_p
)
26032 if (!NILP (w
->hchild
))
26033 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
26034 else if (!NILP (w
->vchild
))
26035 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
26037 update_window_cursor (w
, on_p
);
26039 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
26045 Display the cursor on window W, or clear it, according to ON_P.
26046 Don't change the cursor's position. */
26049 x_update_cursor (struct frame
*f
, int on_p
)
26051 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
26056 Clear the cursor of window W to background color, and mark the
26057 cursor as not shown. This is used when the text where the cursor
26058 is about to be rewritten. */
26061 x_clear_cursor (struct window
*w
)
26063 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
26064 update_window_cursor (w
, 0);
26067 #endif /* HAVE_WINDOW_SYSTEM */
26069 /* Implementation of draw_row_with_mouse_face for GUI sessions, GPM,
26072 draw_row_with_mouse_face (struct window
*w
, int start_x
, struct glyph_row
*row
,
26073 int start_hpos
, int end_hpos
,
26074 enum draw_glyphs_face draw
)
26076 #ifdef HAVE_WINDOW_SYSTEM
26077 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
26079 draw_glyphs (w
, start_x
, row
, TEXT_AREA
, start_hpos
, end_hpos
, draw
, 0);
26083 #if defined (HAVE_GPM) || defined (MSDOS) || defined (WINDOWSNT)
26084 tty_draw_row_with_mouse_face (w
, row
, start_hpos
, end_hpos
, draw
);
26088 /* Display the active region described by mouse_face_* according to DRAW. */
26091 show_mouse_face (Mouse_HLInfo
*hlinfo
, enum draw_glyphs_face draw
)
26093 struct window
*w
= XWINDOW (hlinfo
->mouse_face_window
);
26094 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
26096 if (/* If window is in the process of being destroyed, don't bother
26098 w
->current_matrix
!= NULL
26099 /* Don't update mouse highlight if hidden */
26100 && (draw
!= DRAW_MOUSE_FACE
|| !hlinfo
->mouse_face_hidden
)
26101 /* Recognize when we are called to operate on rows that don't exist
26102 anymore. This can happen when a window is split. */
26103 && hlinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
26105 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
26106 struct glyph_row
*row
, *first
, *last
;
26108 first
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
26109 last
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
26111 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
26113 int start_hpos
, end_hpos
, start_x
;
26115 /* For all but the first row, the highlight starts at column 0. */
26118 /* R2L rows have BEG and END in reversed order, but the
26119 screen drawing geometry is always left to right. So
26120 we need to mirror the beginning and end of the
26121 highlighted area in R2L rows. */
26122 if (!row
->reversed_p
)
26124 start_hpos
= hlinfo
->mouse_face_beg_col
;
26125 start_x
= hlinfo
->mouse_face_beg_x
;
26127 else if (row
== last
)
26129 start_hpos
= hlinfo
->mouse_face_end_col
;
26130 start_x
= hlinfo
->mouse_face_end_x
;
26138 else if (row
->reversed_p
&& row
== last
)
26140 start_hpos
= hlinfo
->mouse_face_end_col
;
26141 start_x
= hlinfo
->mouse_face_end_x
;
26151 if (!row
->reversed_p
)
26152 end_hpos
= hlinfo
->mouse_face_end_col
;
26153 else if (row
== first
)
26154 end_hpos
= hlinfo
->mouse_face_beg_col
;
26157 end_hpos
= row
->used
[TEXT_AREA
];
26158 if (draw
== DRAW_NORMAL_TEXT
)
26159 row
->fill_line_p
= 1; /* Clear to end of line */
26162 else if (row
->reversed_p
&& row
== first
)
26163 end_hpos
= hlinfo
->mouse_face_beg_col
;
26166 end_hpos
= row
->used
[TEXT_AREA
];
26167 if (draw
== DRAW_NORMAL_TEXT
)
26168 row
->fill_line_p
= 1; /* Clear to end of line */
26171 if (end_hpos
> start_hpos
)
26173 draw_row_with_mouse_face (w
, start_x
, row
,
26174 start_hpos
, end_hpos
, draw
);
26177 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
26181 #ifdef HAVE_WINDOW_SYSTEM
26182 /* When we've written over the cursor, arrange for it to
26183 be displayed again. */
26184 if (FRAME_WINDOW_P (f
)
26185 && phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
26187 int hpos
= w
->phys_cursor
.hpos
;
26189 /* When the window is hscrolled, cursor hpos can legitimately be
26190 out of bounds, but we draw the cursor at the corresponding
26191 window margin in that case. */
26192 if (!row
->reversed_p
&& hpos
< 0)
26194 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26195 hpos
= row
->used
[TEXT_AREA
] - 1;
26198 display_and_set_cursor (w
, 1, hpos
, w
->phys_cursor
.vpos
,
26199 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
26202 #endif /* HAVE_WINDOW_SYSTEM */
26205 #ifdef HAVE_WINDOW_SYSTEM
26206 /* Change the mouse cursor. */
26207 if (FRAME_WINDOW_P (f
))
26209 if (draw
== DRAW_NORMAL_TEXT
26210 && !EQ (hlinfo
->mouse_face_window
, f
->tool_bar_window
))
26211 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
26212 else if (draw
== DRAW_MOUSE_FACE
)
26213 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
26215 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
26217 #endif /* HAVE_WINDOW_SYSTEM */
26221 Clear out the mouse-highlighted active region.
26222 Redraw it un-highlighted first. Value is non-zero if mouse
26223 face was actually drawn unhighlighted. */
26226 clear_mouse_face (Mouse_HLInfo
*hlinfo
)
26230 if (!hlinfo
->mouse_face_hidden
&& !NILP (hlinfo
->mouse_face_window
))
26232 show_mouse_face (hlinfo
, DRAW_NORMAL_TEXT
);
26236 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
26237 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
26238 hlinfo
->mouse_face_window
= Qnil
;
26239 hlinfo
->mouse_face_overlay
= Qnil
;
26243 /* Return non-zero if the coordinates HPOS and VPOS on windows W are
26244 within the mouse face on that window. */
26246 coords_in_mouse_face_p (struct window
*w
, int hpos
, int vpos
)
26248 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
26250 /* Quickly resolve the easy cases. */
26251 if (!(WINDOWP (hlinfo
->mouse_face_window
)
26252 && XWINDOW (hlinfo
->mouse_face_window
) == w
))
26254 if (vpos
< hlinfo
->mouse_face_beg_row
26255 || vpos
> hlinfo
->mouse_face_end_row
)
26257 if (vpos
> hlinfo
->mouse_face_beg_row
26258 && vpos
< hlinfo
->mouse_face_end_row
)
26261 if (!MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
)
26263 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
26265 if (hlinfo
->mouse_face_beg_col
<= hpos
&& hpos
< hlinfo
->mouse_face_end_col
)
26268 else if ((vpos
== hlinfo
->mouse_face_beg_row
26269 && hpos
>= hlinfo
->mouse_face_beg_col
)
26270 || (vpos
== hlinfo
->mouse_face_end_row
26271 && hpos
< hlinfo
->mouse_face_end_col
))
26276 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
26278 if (hlinfo
->mouse_face_end_col
< hpos
&& hpos
<= hlinfo
->mouse_face_beg_col
)
26281 else if ((vpos
== hlinfo
->mouse_face_beg_row
26282 && hpos
<= hlinfo
->mouse_face_beg_col
)
26283 || (vpos
== hlinfo
->mouse_face_end_row
26284 && hpos
> hlinfo
->mouse_face_end_col
))
26292 Non-zero if physical cursor of window W is within mouse face. */
26295 cursor_in_mouse_face_p (struct window
*w
)
26297 int hpos
= w
->phys_cursor
.hpos
;
26298 int vpos
= w
->phys_cursor
.vpos
;
26299 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26301 /* When the window is hscrolled, cursor hpos can legitimately be out
26302 of bounds, but we draw the cursor at the corresponding window
26303 margin in that case. */
26304 if (!row
->reversed_p
&& hpos
< 0)
26306 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26307 hpos
= row
->used
[TEXT_AREA
] - 1;
26309 return coords_in_mouse_face_p (w
, hpos
, vpos
);
26314 /* Find the glyph rows START_ROW and END_ROW of window W that display
26315 characters between buffer positions START_CHARPOS and END_CHARPOS
26316 (excluding END_CHARPOS). DISP_STRING is a display string that
26317 covers these buffer positions. This is similar to
26318 row_containing_pos, but is more accurate when bidi reordering makes
26319 buffer positions change non-linearly with glyph rows. */
26321 rows_from_pos_range (struct window
*w
,
26322 ptrdiff_t start_charpos
, ptrdiff_t end_charpos
,
26323 Lisp_Object disp_string
,
26324 struct glyph_row
**start
, struct glyph_row
**end
)
26326 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26327 int last_y
= window_text_bottom_y (w
);
26328 struct glyph_row
*row
;
26333 while (!first
->enabled_p
26334 && first
< MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
26337 /* Find the START row. */
26339 row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
;
26342 /* A row can potentially be the START row if the range of the
26343 characters it displays intersects the range
26344 [START_CHARPOS..END_CHARPOS). */
26345 if (! ((start_charpos
< MATRIX_ROW_START_CHARPOS (row
)
26346 && end_charpos
< MATRIX_ROW_START_CHARPOS (row
))
26347 /* See the commentary in row_containing_pos, for the
26348 explanation of the complicated way to check whether
26349 some position is beyond the end of the characters
26350 displayed by a row. */
26351 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (row
)
26352 || (start_charpos
== MATRIX_ROW_END_CHARPOS (row
)
26353 && !row
->ends_at_zv_p
26354 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
26355 && (end_charpos
> MATRIX_ROW_END_CHARPOS (row
)
26356 || (end_charpos
== MATRIX_ROW_END_CHARPOS (row
)
26357 && !row
->ends_at_zv_p
26358 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))))
26360 /* Found a candidate row. Now make sure at least one of the
26361 glyphs it displays has a charpos from the range
26362 [START_CHARPOS..END_CHARPOS).
26364 This is not obvious because bidi reordering could make
26365 buffer positions of a row be 1,2,3,102,101,100, and if we
26366 want to highlight characters in [50..60), we don't want
26367 this row, even though [50..60) does intersect [1..103),
26368 the range of character positions given by the row's start
26369 and end positions. */
26370 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
26371 struct glyph
*e
= g
+ row
->used
[TEXT_AREA
];
26375 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
26376 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
26377 /* A glyph that comes from DISP_STRING is by
26378 definition to be highlighted. */
26379 || EQ (g
->object
, disp_string
))
26388 /* Find the END row. */
26390 /* If the last row is partially visible, start looking for END
26391 from that row, instead of starting from FIRST. */
26392 && !(row
->enabled_p
26393 && row
->y
< last_y
&& MATRIX_ROW_BOTTOM_Y (row
) > last_y
))
26395 for ( ; row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
; row
++)
26397 struct glyph_row
*next
= row
+ 1;
26398 ptrdiff_t next_start
= MATRIX_ROW_START_CHARPOS (next
);
26400 if (!next
->enabled_p
26401 || next
>= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
)
26402 /* The first row >= START whose range of displayed characters
26403 does NOT intersect the range [START_CHARPOS..END_CHARPOS]
26404 is the row END + 1. */
26405 || (start_charpos
< next_start
26406 && end_charpos
< next_start
)
26407 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (next
)
26408 || (start_charpos
== MATRIX_ROW_END_CHARPOS (next
)
26409 && !next
->ends_at_zv_p
26410 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))
26411 && (end_charpos
> MATRIX_ROW_END_CHARPOS (next
)
26412 || (end_charpos
== MATRIX_ROW_END_CHARPOS (next
)
26413 && !next
->ends_at_zv_p
26414 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))))
26421 /* If the next row's edges intersect [START_CHARPOS..END_CHARPOS],
26422 but none of the characters it displays are in the range, it is
26424 struct glyph
*g
= next
->glyphs
[TEXT_AREA
];
26425 struct glyph
*s
= g
;
26426 struct glyph
*e
= g
+ next
->used
[TEXT_AREA
];
26430 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
26431 && ((start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
26432 /* If the buffer position of the first glyph in
26433 the row is equal to END_CHARPOS, it means
26434 the last character to be highlighted is the
26435 newline of ROW, and we must consider NEXT as
26437 || (((!next
->reversed_p
&& g
== s
)
26438 || (next
->reversed_p
&& g
== e
- 1))
26439 && (g
->charpos
== end_charpos
26440 /* Special case for when NEXT is an
26441 empty line at ZV. */
26442 || (g
->charpos
== -1
26443 && !row
->ends_at_zv_p
26444 && next_start
== end_charpos
)))))
26445 /* A glyph that comes from DISP_STRING is by
26446 definition to be highlighted. */
26447 || EQ (g
->object
, disp_string
))
26456 /* The first row that ends at ZV must be the last to be
26458 else if (next
->ends_at_zv_p
)
26467 /* This function sets the mouse_face_* elements of HLINFO, assuming
26468 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
26469 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
26470 for the overlay or run of text properties specifying the mouse
26471 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
26472 before-string and after-string that must also be highlighted.
26473 DISP_STRING, if non-nil, is a display string that may cover some
26474 or all of the highlighted text. */
26477 mouse_face_from_buffer_pos (Lisp_Object window
,
26478 Mouse_HLInfo
*hlinfo
,
26479 ptrdiff_t mouse_charpos
,
26480 ptrdiff_t start_charpos
,
26481 ptrdiff_t end_charpos
,
26482 Lisp_Object before_string
,
26483 Lisp_Object after_string
,
26484 Lisp_Object disp_string
)
26486 struct window
*w
= XWINDOW (window
);
26487 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26488 struct glyph_row
*r1
, *r2
;
26489 struct glyph
*glyph
, *end
;
26490 ptrdiff_t ignore
, pos
;
26493 eassert (NILP (disp_string
) || STRINGP (disp_string
));
26494 eassert (NILP (before_string
) || STRINGP (before_string
));
26495 eassert (NILP (after_string
) || STRINGP (after_string
));
26497 /* Find the rows corresponding to START_CHARPOS and END_CHARPOS. */
26498 rows_from_pos_range (w
, start_charpos
, end_charpos
, disp_string
, &r1
, &r2
);
26500 r1
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
26501 /* If the before-string or display-string contains newlines,
26502 rows_from_pos_range skips to its last row. Move back. */
26503 if (!NILP (before_string
) || !NILP (disp_string
))
26505 struct glyph_row
*prev
;
26506 while ((prev
= r1
- 1, prev
>= first
)
26507 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
26508 && prev
->used
[TEXT_AREA
] > 0)
26510 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
26511 glyph
= beg
+ prev
->used
[TEXT_AREA
];
26512 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
26514 || !(EQ (glyph
->object
, before_string
)
26515 || EQ (glyph
->object
, disp_string
)))
26522 r2
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
26523 hlinfo
->mouse_face_past_end
= 1;
26525 else if (!NILP (after_string
))
26527 /* If the after-string has newlines, advance to its last row. */
26528 struct glyph_row
*next
;
26529 struct glyph_row
*last
26530 = MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
26532 for (next
= r2
+ 1;
26534 && next
->used
[TEXT_AREA
] > 0
26535 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
26539 /* The rest of the display engine assumes that mouse_face_beg_row is
26540 either above mouse_face_end_row or identical to it. But with
26541 bidi-reordered continued lines, the row for START_CHARPOS could
26542 be below the row for END_CHARPOS. If so, swap the rows and store
26543 them in correct order. */
26546 struct glyph_row
*tem
= r2
;
26552 hlinfo
->mouse_face_beg_y
= r1
->y
;
26553 hlinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (r1
, w
->current_matrix
);
26554 hlinfo
->mouse_face_end_y
= r2
->y
;
26555 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r2
, w
->current_matrix
);
26557 /* For a bidi-reordered row, the positions of BEFORE_STRING,
26558 AFTER_STRING, DISP_STRING, START_CHARPOS, and END_CHARPOS
26559 could be anywhere in the row and in any order. The strategy
26560 below is to find the leftmost and the rightmost glyph that
26561 belongs to either of these 3 strings, or whose position is
26562 between START_CHARPOS and END_CHARPOS, and highlight all the
26563 glyphs between those two. This may cover more than just the text
26564 between START_CHARPOS and END_CHARPOS if the range of characters
26565 strides the bidi level boundary, e.g. if the beginning is in R2L
26566 text while the end is in L2R text or vice versa. */
26567 if (!r1
->reversed_p
)
26569 /* This row is in a left to right paragraph. Scan it left to
26571 glyph
= r1
->glyphs
[TEXT_AREA
];
26572 end
= glyph
+ r1
->used
[TEXT_AREA
];
26575 /* Skip truncation glyphs at the start of the glyph row. */
26576 if (r1
->displays_text_p
)
26578 && INTEGERP (glyph
->object
)
26579 && glyph
->charpos
< 0;
26581 x
+= glyph
->pixel_width
;
26583 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
26584 or DISP_STRING, and the first glyph from buffer whose
26585 position is between START_CHARPOS and END_CHARPOS. */
26587 && !INTEGERP (glyph
->object
)
26588 && !EQ (glyph
->object
, disp_string
)
26589 && !(BUFFERP (glyph
->object
)
26590 && (glyph
->charpos
>= start_charpos
26591 && glyph
->charpos
< end_charpos
));
26594 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26595 are present at buffer positions between START_CHARPOS and
26596 END_CHARPOS, or if they come from an overlay. */
26597 if (EQ (glyph
->object
, before_string
))
26599 pos
= string_buffer_position (before_string
,
26601 /* If pos == 0, it means before_string came from an
26602 overlay, not from a buffer position. */
26603 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26606 else if (EQ (glyph
->object
, after_string
))
26608 pos
= string_buffer_position (after_string
, end_charpos
);
26609 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26612 x
+= glyph
->pixel_width
;
26614 hlinfo
->mouse_face_beg_x
= x
;
26615 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
26619 /* This row is in a right to left paragraph. Scan it right to
26623 end
= r1
->glyphs
[TEXT_AREA
] - 1;
26624 glyph
= end
+ r1
->used
[TEXT_AREA
];
26626 /* Skip truncation glyphs at the start of the glyph row. */
26627 if (r1
->displays_text_p
)
26629 && INTEGERP (glyph
->object
)
26630 && glyph
->charpos
< 0;
26634 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
26635 or DISP_STRING, and the first glyph from buffer whose
26636 position is between START_CHARPOS and END_CHARPOS. */
26638 && !INTEGERP (glyph
->object
)
26639 && !EQ (glyph
->object
, disp_string
)
26640 && !(BUFFERP (glyph
->object
)
26641 && (glyph
->charpos
>= start_charpos
26642 && glyph
->charpos
< end_charpos
));
26645 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26646 are present at buffer positions between START_CHARPOS and
26647 END_CHARPOS, or if they come from an overlay. */
26648 if (EQ (glyph
->object
, before_string
))
26650 pos
= string_buffer_position (before_string
, start_charpos
);
26651 /* If pos == 0, it means before_string came from an
26652 overlay, not from a buffer position. */
26653 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26656 else if (EQ (glyph
->object
, after_string
))
26658 pos
= string_buffer_position (after_string
, end_charpos
);
26659 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26664 glyph
++; /* first glyph to the right of the highlighted area */
26665 for (g
= r1
->glyphs
[TEXT_AREA
], x
= r1
->x
; g
< glyph
; g
++)
26666 x
+= g
->pixel_width
;
26667 hlinfo
->mouse_face_beg_x
= x
;
26668 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
26671 /* If the highlight ends in a different row, compute GLYPH and END
26672 for the end row. Otherwise, reuse the values computed above for
26673 the row where the highlight begins. */
26676 if (!r2
->reversed_p
)
26678 glyph
= r2
->glyphs
[TEXT_AREA
];
26679 end
= glyph
+ r2
->used
[TEXT_AREA
];
26684 end
= r2
->glyphs
[TEXT_AREA
] - 1;
26685 glyph
= end
+ r2
->used
[TEXT_AREA
];
26689 if (!r2
->reversed_p
)
26691 /* Skip truncation and continuation glyphs near the end of the
26692 row, and also blanks and stretch glyphs inserted by
26693 extend_face_to_end_of_line. */
26695 && INTEGERP ((end
- 1)->object
))
26697 /* Scan the rest of the glyph row from the end, looking for the
26698 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
26699 DISP_STRING, or whose position is between START_CHARPOS
26703 && !INTEGERP (end
->object
)
26704 && !EQ (end
->object
, disp_string
)
26705 && !(BUFFERP (end
->object
)
26706 && (end
->charpos
>= start_charpos
26707 && end
->charpos
< end_charpos
));
26710 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26711 are present at buffer positions between START_CHARPOS and
26712 END_CHARPOS, or if they come from an overlay. */
26713 if (EQ (end
->object
, before_string
))
26715 pos
= string_buffer_position (before_string
, start_charpos
);
26716 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26719 else if (EQ (end
->object
, after_string
))
26721 pos
= string_buffer_position (after_string
, end_charpos
);
26722 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26726 /* Find the X coordinate of the last glyph to be highlighted. */
26727 for (; glyph
<= end
; ++glyph
)
26728 x
+= glyph
->pixel_width
;
26730 hlinfo
->mouse_face_end_x
= x
;
26731 hlinfo
->mouse_face_end_col
= glyph
- r2
->glyphs
[TEXT_AREA
];
26735 /* Skip truncation and continuation glyphs near the end of the
26736 row, and also blanks and stretch glyphs inserted by
26737 extend_face_to_end_of_line. */
26741 && INTEGERP (end
->object
))
26743 x
+= end
->pixel_width
;
26746 /* Scan the rest of the glyph row from the end, looking for the
26747 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
26748 DISP_STRING, or whose position is between START_CHARPOS
26752 && !INTEGERP (end
->object
)
26753 && !EQ (end
->object
, disp_string
)
26754 && !(BUFFERP (end
->object
)
26755 && (end
->charpos
>= start_charpos
26756 && end
->charpos
< end_charpos
));
26759 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26760 are present at buffer positions between START_CHARPOS and
26761 END_CHARPOS, or if they come from an overlay. */
26762 if (EQ (end
->object
, before_string
))
26764 pos
= string_buffer_position (before_string
, start_charpos
);
26765 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26768 else if (EQ (end
->object
, after_string
))
26770 pos
= string_buffer_position (after_string
, end_charpos
);
26771 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26774 x
+= end
->pixel_width
;
26776 /* If we exited the above loop because we arrived at the last
26777 glyph of the row, and its buffer position is still not in
26778 range, it means the last character in range is the preceding
26779 newline. Bump the end column and x values to get past the
26782 && BUFFERP (end
->object
)
26783 && (end
->charpos
< start_charpos
26784 || end
->charpos
>= end_charpos
))
26786 x
+= end
->pixel_width
;
26789 hlinfo
->mouse_face_end_x
= x
;
26790 hlinfo
->mouse_face_end_col
= end
- r2
->glyphs
[TEXT_AREA
];
26793 hlinfo
->mouse_face_window
= window
;
26794 hlinfo
->mouse_face_face_id
26795 = face_at_buffer_position (w
, mouse_charpos
, 0, 0, &ignore
,
26797 !hlinfo
->mouse_face_hidden
, -1);
26798 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
26801 /* The following function is not used anymore (replaced with
26802 mouse_face_from_string_pos), but I leave it here for the time
26803 being, in case someone would. */
26805 #if 0 /* not used */
26807 /* Find the position of the glyph for position POS in OBJECT in
26808 window W's current matrix, and return in *X, *Y the pixel
26809 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
26811 RIGHT_P non-zero means return the position of the right edge of the
26812 glyph, RIGHT_P zero means return the left edge position.
26814 If no glyph for POS exists in the matrix, return the position of
26815 the glyph with the next smaller position that is in the matrix, if
26816 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
26817 exists in the matrix, return the position of the glyph with the
26818 next larger position in OBJECT.
26820 Value is non-zero if a glyph was found. */
26823 fast_find_string_pos (struct window
*w
, ptrdiff_t pos
, Lisp_Object object
,
26824 int *hpos
, int *vpos
, int *x
, int *y
, int right_p
)
26826 int yb
= window_text_bottom_y (w
);
26827 struct glyph_row
*r
;
26828 struct glyph
*best_glyph
= NULL
;
26829 struct glyph_row
*best_row
= NULL
;
26832 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26833 r
->enabled_p
&& r
->y
< yb
;
26836 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
26837 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
26840 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
26841 if (EQ (g
->object
, object
))
26843 if (g
->charpos
== pos
)
26850 else if (best_glyph
== NULL
26851 || ((eabs (g
->charpos
- pos
)
26852 < eabs (best_glyph
->charpos
- pos
))
26855 : g
->charpos
> pos
)))
26869 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
26873 *x
+= best_glyph
->pixel_width
;
26878 *vpos
= best_row
- w
->current_matrix
->rows
;
26881 return best_glyph
!= NULL
;
26883 #endif /* not used */
26885 /* Find the positions of the first and the last glyphs in window W's
26886 current matrix that occlude positions [STARTPOS..ENDPOS] in OBJECT
26887 (assumed to be a string), and return in HLINFO's mouse_face_*
26888 members the pixel and column/row coordinates of those glyphs. */
26891 mouse_face_from_string_pos (struct window
*w
, Mouse_HLInfo
*hlinfo
,
26892 Lisp_Object object
,
26893 ptrdiff_t startpos
, ptrdiff_t endpos
)
26895 int yb
= window_text_bottom_y (w
);
26896 struct glyph_row
*r
;
26897 struct glyph
*g
, *e
;
26901 /* Find the glyph row with at least one position in the range
26902 [STARTPOS..ENDPOS], and the first glyph in that row whose
26903 position belongs to that range. */
26904 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26905 r
->enabled_p
&& r
->y
< yb
;
26908 if (!r
->reversed_p
)
26910 g
= r
->glyphs
[TEXT_AREA
];
26911 e
= g
+ r
->used
[TEXT_AREA
];
26912 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
26913 if (EQ (g
->object
, object
)
26914 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
26916 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
26917 hlinfo
->mouse_face_beg_y
= r
->y
;
26918 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
26919 hlinfo
->mouse_face_beg_x
= gx
;
26928 e
= r
->glyphs
[TEXT_AREA
];
26929 g
= e
+ r
->used
[TEXT_AREA
];
26930 for ( ; g
> e
; --g
)
26931 if (EQ ((g
-1)->object
, object
)
26932 && startpos
<= (g
-1)->charpos
&& (g
-1)->charpos
<= endpos
)
26934 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
26935 hlinfo
->mouse_face_beg_y
= r
->y
;
26936 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
26937 for (gx
= r
->x
, g1
= r
->glyphs
[TEXT_AREA
]; g1
< g
; ++g1
)
26938 gx
+= g1
->pixel_width
;
26939 hlinfo
->mouse_face_beg_x
= gx
;
26951 /* Starting with the next row, look for the first row which does NOT
26952 include any glyphs whose positions are in the range. */
26953 for (++r
; r
->enabled_p
&& r
->y
< yb
; ++r
)
26955 g
= r
->glyphs
[TEXT_AREA
];
26956 e
= g
+ r
->used
[TEXT_AREA
];
26958 for ( ; g
< e
; ++g
)
26959 if (EQ (g
->object
, object
)
26960 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
26969 /* The highlighted region ends on the previous row. */
26972 /* Set the end row and its vertical pixel coordinate. */
26973 hlinfo
->mouse_face_end_row
= r
- w
->current_matrix
->rows
;
26974 hlinfo
->mouse_face_end_y
= r
->y
;
26976 /* Compute and set the end column and the end column's horizontal
26977 pixel coordinate. */
26978 if (!r
->reversed_p
)
26980 g
= r
->glyphs
[TEXT_AREA
];
26981 e
= g
+ r
->used
[TEXT_AREA
];
26982 for ( ; e
> g
; --e
)
26983 if (EQ ((e
-1)->object
, object
)
26984 && startpos
<= (e
-1)->charpos
&& (e
-1)->charpos
<= endpos
)
26986 hlinfo
->mouse_face_end_col
= e
- g
;
26988 for (gx
= r
->x
; g
< e
; ++g
)
26989 gx
+= g
->pixel_width
;
26990 hlinfo
->mouse_face_end_x
= gx
;
26994 e
= r
->glyphs
[TEXT_AREA
];
26995 g
= e
+ r
->used
[TEXT_AREA
];
26996 for (gx
= r
->x
; e
< g
; ++e
)
26998 if (EQ (e
->object
, object
)
26999 && startpos
<= e
->charpos
&& e
->charpos
<= endpos
)
27001 gx
+= e
->pixel_width
;
27003 hlinfo
->mouse_face_end_col
= e
- r
->glyphs
[TEXT_AREA
];
27004 hlinfo
->mouse_face_end_x
= gx
;
27008 #ifdef HAVE_WINDOW_SYSTEM
27010 /* See if position X, Y is within a hot-spot of an image. */
27013 on_hot_spot_p (Lisp_Object hot_spot
, int x
, int y
)
27015 if (!CONSP (hot_spot
))
27018 if (EQ (XCAR (hot_spot
), Qrect
))
27020 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
27021 Lisp_Object rect
= XCDR (hot_spot
);
27025 if (!CONSP (XCAR (rect
)))
27027 if (!CONSP (XCDR (rect
)))
27029 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
27031 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
27033 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
27035 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
27039 else if (EQ (XCAR (hot_spot
), Qcircle
))
27041 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
27042 Lisp_Object circ
= XCDR (hot_spot
);
27043 Lisp_Object lr
, lx0
, ly0
;
27045 && CONSP (XCAR (circ
))
27046 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
27047 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
27048 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
27050 double r
= XFLOATINT (lr
);
27051 double dx
= XINT (lx0
) - x
;
27052 double dy
= XINT (ly0
) - y
;
27053 return (dx
* dx
+ dy
* dy
<= r
* r
);
27056 else if (EQ (XCAR (hot_spot
), Qpoly
))
27058 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
27059 if (VECTORP (XCDR (hot_spot
)))
27061 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
27062 Lisp_Object
*poly
= v
->contents
;
27063 ptrdiff_t n
= v
->header
.size
;
27066 Lisp_Object lx
, ly
;
27069 /* Need an even number of coordinates, and at least 3 edges. */
27070 if (n
< 6 || n
& 1)
27073 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
27074 If count is odd, we are inside polygon. Pixels on edges
27075 may or may not be included depending on actual geometry of the
27077 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
27078 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
27080 x0
= XINT (lx
), y0
= XINT (ly
);
27081 for (i
= 0; i
< n
; i
+= 2)
27083 int x1
= x0
, y1
= y0
;
27084 if ((lx
= poly
[i
], !INTEGERP (lx
))
27085 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
27087 x0
= XINT (lx
), y0
= XINT (ly
);
27089 /* Does this segment cross the X line? */
27097 if (y
> y0
&& y
> y1
)
27099 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
27109 find_hot_spot (Lisp_Object map
, int x
, int y
)
27111 while (CONSP (map
))
27113 if (CONSP (XCAR (map
))
27114 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
27122 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
27124 doc
: /* Lookup in image map MAP coordinates X and Y.
27125 An image map is an alist where each element has the format (AREA ID PLIST).
27126 An AREA is specified as either a rectangle, a circle, or a polygon:
27127 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
27128 pixel coordinates of the upper left and bottom right corners.
27129 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
27130 and the radius of the circle; r may be a float or integer.
27131 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
27132 vector describes one corner in the polygon.
27133 Returns the alist element for the first matching AREA in MAP. */)
27134 (Lisp_Object map
, Lisp_Object x
, Lisp_Object y
)
27142 return find_hot_spot (map
,
27143 clip_to_bounds (INT_MIN
, XINT (x
), INT_MAX
),
27144 clip_to_bounds (INT_MIN
, XINT (y
), INT_MAX
));
27148 /* Display frame CURSOR, optionally using shape defined by POINTER. */
27150 define_frame_cursor1 (struct frame
*f
, Cursor cursor
, Lisp_Object pointer
)
27152 /* Do not change cursor shape while dragging mouse. */
27153 if (!NILP (do_mouse_tracking
))
27156 if (!NILP (pointer
))
27158 if (EQ (pointer
, Qarrow
))
27159 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27160 else if (EQ (pointer
, Qhand
))
27161 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
27162 else if (EQ (pointer
, Qtext
))
27163 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
27164 else if (EQ (pointer
, intern ("hdrag")))
27165 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
27166 #ifdef HAVE_X_WINDOWS
27167 else if (EQ (pointer
, intern ("vdrag")))
27168 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
27170 else if (EQ (pointer
, intern ("hourglass")))
27171 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
27172 else if (EQ (pointer
, Qmodeline
))
27173 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
27175 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27178 if (cursor
!= No_Cursor
)
27179 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
27182 #endif /* HAVE_WINDOW_SYSTEM */
27184 /* Take proper action when mouse has moved to the mode or header line
27185 or marginal area AREA of window W, x-position X and y-position Y.
27186 X is relative to the start of the text display area of W, so the
27187 width of bitmap areas and scroll bars must be subtracted to get a
27188 position relative to the start of the mode line. */
27191 note_mode_line_or_margin_highlight (Lisp_Object window
, int x
, int y
,
27192 enum window_part area
)
27194 struct window
*w
= XWINDOW (window
);
27195 struct frame
*f
= XFRAME (w
->frame
);
27196 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
27197 #ifdef HAVE_WINDOW_SYSTEM
27198 Display_Info
*dpyinfo
;
27200 Cursor cursor
= No_Cursor
;
27201 Lisp_Object pointer
= Qnil
;
27202 int dx
, dy
, width
, height
;
27204 Lisp_Object string
, object
= Qnil
;
27205 Lisp_Object pos
IF_LINT (= Qnil
), help
;
27207 Lisp_Object mouse_face
;
27208 int original_x_pixel
= x
;
27209 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
27210 struct glyph_row
*row
IF_LINT (= 0);
27212 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
27217 /* Kludge alert: mode_line_string takes X/Y in pixels, but
27218 returns them in row/column units! */
27219 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
27220 &object
, &dx
, &dy
, &width
, &height
);
27222 row
= (area
== ON_MODE_LINE
27223 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
27224 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
27226 /* Find the glyph under the mouse pointer. */
27227 if (row
->mode_line_p
&& row
->enabled_p
)
27229 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
27230 end
= glyph
+ row
->used
[TEXT_AREA
];
27232 for (x0
= original_x_pixel
;
27233 glyph
< end
&& x0
>= glyph
->pixel_width
;
27235 x0
-= glyph
->pixel_width
;
27243 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
27244 /* Kludge alert: marginal_area_string takes X/Y in pixels, but
27245 returns them in row/column units! */
27246 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
27247 &object
, &dx
, &dy
, &width
, &height
);
27252 #ifdef HAVE_WINDOW_SYSTEM
27253 if (IMAGEP (object
))
27255 Lisp_Object image_map
, hotspot
;
27256 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
27258 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
27260 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
27264 /* Could check XCAR (hotspot) to see if we enter/leave this hot-spot.
27265 If so, we could look for mouse-enter, mouse-leave
27266 properties in PLIST (and do something...). */
27267 hotspot
= XCDR (hotspot
);
27268 if (CONSP (hotspot
)
27269 && (plist
= XCAR (hotspot
), CONSP (plist
)))
27271 pointer
= Fplist_get (plist
, Qpointer
);
27272 if (NILP (pointer
))
27274 help
= Fplist_get (plist
, Qhelp_echo
);
27277 help_echo_string
= help
;
27278 XSETWINDOW (help_echo_window
, w
);
27279 help_echo_object
= w
->buffer
;
27280 help_echo_pos
= charpos
;
27284 if (NILP (pointer
))
27285 pointer
= Fplist_get (XCDR (object
), QCpointer
);
27287 #endif /* HAVE_WINDOW_SYSTEM */
27289 if (STRINGP (string
))
27290 pos
= make_number (charpos
);
27292 /* Set the help text and mouse pointer. If the mouse is on a part
27293 of the mode line without any text (e.g. past the right edge of
27294 the mode line text), use the default help text and pointer. */
27295 if (STRINGP (string
) || area
== ON_MODE_LINE
)
27297 /* Arrange to display the help by setting the global variables
27298 help_echo_string, help_echo_object, and help_echo_pos. */
27301 if (STRINGP (string
))
27302 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
27306 help_echo_string
= help
;
27307 XSETWINDOW (help_echo_window
, w
);
27308 help_echo_object
= string
;
27309 help_echo_pos
= charpos
;
27311 else if (area
== ON_MODE_LINE
)
27313 Lisp_Object default_help
27314 = buffer_local_value_1 (Qmode_line_default_help_echo
,
27317 if (STRINGP (default_help
))
27319 help_echo_string
= default_help
;
27320 XSETWINDOW (help_echo_window
, w
);
27321 help_echo_object
= Qnil
;
27322 help_echo_pos
= -1;
27327 #ifdef HAVE_WINDOW_SYSTEM
27328 /* Change the mouse pointer according to what is under it. */
27329 if (FRAME_WINDOW_P (f
))
27331 dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
27332 if (STRINGP (string
))
27334 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27336 if (NILP (pointer
))
27337 pointer
= Fget_text_property (pos
, Qpointer
, string
);
27339 /* Change the mouse pointer according to what is under X/Y. */
27341 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
27344 map
= Fget_text_property (pos
, Qlocal_map
, string
);
27345 if (!KEYMAPP (map
))
27346 map
= Fget_text_property (pos
, Qkeymap
, string
);
27347 if (!KEYMAPP (map
))
27348 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
27352 /* Default mode-line pointer. */
27353 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
27358 /* Change the mouse face according to what is under X/Y. */
27359 if (STRINGP (string
))
27361 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
27362 if (!NILP (mouse_face
)
27363 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
27368 struct glyph
* tmp_glyph
;
27372 int total_pixel_width
;
27373 ptrdiff_t begpos
, endpos
, ignore
;
27377 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
27378 Qmouse_face
, string
, Qnil
);
27384 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
27386 endpos
= SCHARS (string
);
27390 /* Calculate the glyph position GPOS of GLYPH in the
27391 displayed string, relative to the beginning of the
27392 highlighted part of the string.
27394 Note: GPOS is different from CHARPOS. CHARPOS is the
27395 position of GLYPH in the internal string object. A mode
27396 line string format has structures which are converted to
27397 a flattened string by the Emacs Lisp interpreter. The
27398 internal string is an element of those structures. The
27399 displayed string is the flattened string. */
27400 tmp_glyph
= row_start_glyph
;
27401 while (tmp_glyph
< glyph
27402 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
27403 && begpos
<= tmp_glyph
->charpos
27404 && tmp_glyph
->charpos
< endpos
)))
27406 gpos
= glyph
- tmp_glyph
;
27408 /* Calculate the length GSEQ_LENGTH of the glyph sequence of
27409 the highlighted part of the displayed string to which
27410 GLYPH belongs. Note: GSEQ_LENGTH is different from
27411 SCHARS (STRING), because the latter returns the length of
27412 the internal string. */
27413 for (tmp_glyph
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
27415 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
27416 && begpos
<= tmp_glyph
->charpos
27417 && tmp_glyph
->charpos
< endpos
));
27420 gseq_length
= gpos
+ (tmp_glyph
- glyph
) + 1;
27422 /* Calculate the total pixel width of all the glyphs between
27423 the beginning of the highlighted area and GLYPH. */
27424 total_pixel_width
= 0;
27425 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
27426 total_pixel_width
+= tmp_glyph
->pixel_width
;
27428 /* Pre calculation of re-rendering position. Note: X is in
27429 column units here, after the call to mode_line_string or
27430 marginal_area_string. */
27432 vpos
= (area
== ON_MODE_LINE
27433 ? (w
->current_matrix
)->nrows
- 1
27436 /* If GLYPH's position is included in the region that is
27437 already drawn in mouse face, we have nothing to do. */
27438 if ( EQ (window
, hlinfo
->mouse_face_window
)
27439 && (!row
->reversed_p
27440 ? (hlinfo
->mouse_face_beg_col
<= hpos
27441 && hpos
< hlinfo
->mouse_face_end_col
)
27442 /* In R2L rows we swap BEG and END, see below. */
27443 : (hlinfo
->mouse_face_end_col
<= hpos
27444 && hpos
< hlinfo
->mouse_face_beg_col
))
27445 && hlinfo
->mouse_face_beg_row
== vpos
)
27448 if (clear_mouse_face (hlinfo
))
27449 cursor
= No_Cursor
;
27451 if (!row
->reversed_p
)
27453 hlinfo
->mouse_face_beg_col
= hpos
;
27454 hlinfo
->mouse_face_beg_x
= original_x_pixel
27455 - (total_pixel_width
+ dx
);
27456 hlinfo
->mouse_face_end_col
= hpos
+ gseq_length
;
27457 hlinfo
->mouse_face_end_x
= 0;
27461 /* In R2L rows, show_mouse_face expects BEG and END
27462 coordinates to be swapped. */
27463 hlinfo
->mouse_face_end_col
= hpos
;
27464 hlinfo
->mouse_face_end_x
= original_x_pixel
27465 - (total_pixel_width
+ dx
);
27466 hlinfo
->mouse_face_beg_col
= hpos
+ gseq_length
;
27467 hlinfo
->mouse_face_beg_x
= 0;
27470 hlinfo
->mouse_face_beg_row
= vpos
;
27471 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_beg_row
;
27472 hlinfo
->mouse_face_beg_y
= 0;
27473 hlinfo
->mouse_face_end_y
= 0;
27474 hlinfo
->mouse_face_past_end
= 0;
27475 hlinfo
->mouse_face_window
= window
;
27477 hlinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
27483 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
27485 if (NILP (pointer
))
27488 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
27489 clear_mouse_face (hlinfo
);
27491 #ifdef HAVE_WINDOW_SYSTEM
27492 if (FRAME_WINDOW_P (f
))
27493 define_frame_cursor1 (f
, cursor
, pointer
);
27499 Take proper action when the mouse has moved to position X, Y on
27500 frame F as regards highlighting characters that have mouse-face
27501 properties. Also de-highlighting chars where the mouse was before.
27502 X and Y can be negative or out of range. */
27505 note_mouse_highlight (struct frame
*f
, int x
, int y
)
27507 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
27508 enum window_part part
= ON_NOTHING
;
27509 Lisp_Object window
;
27511 Cursor cursor
= No_Cursor
;
27512 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
27515 /* When a menu is active, don't highlight because this looks odd. */
27516 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (MSDOS)
27517 if (popup_activated ())
27521 if (NILP (Vmouse_highlight
)
27522 || !f
->glyphs_initialized_p
27523 || f
->pointer_invisible
)
27526 hlinfo
->mouse_face_mouse_x
= x
;
27527 hlinfo
->mouse_face_mouse_y
= y
;
27528 hlinfo
->mouse_face_mouse_frame
= f
;
27530 if (hlinfo
->mouse_face_defer
)
27533 /* Which window is that in? */
27534 window
= window_from_coordinates (f
, x
, y
, &part
, 1);
27536 /* If displaying active text in another window, clear that. */
27537 if (! EQ (window
, hlinfo
->mouse_face_window
)
27538 /* Also clear if we move out of text area in same window. */
27539 || (!NILP (hlinfo
->mouse_face_window
)
27542 && part
!= ON_MODE_LINE
27543 && part
!= ON_HEADER_LINE
))
27544 clear_mouse_face (hlinfo
);
27546 /* Not on a window -> return. */
27547 if (!WINDOWP (window
))
27550 /* Reset help_echo_string. It will get recomputed below. */
27551 help_echo_string
= Qnil
;
27553 /* Convert to window-relative pixel coordinates. */
27554 w
= XWINDOW (window
);
27555 frame_to_window_pixel_xy (w
, &x
, &y
);
27557 #ifdef HAVE_WINDOW_SYSTEM
27558 /* Handle tool-bar window differently since it doesn't display a
27560 if (EQ (window
, f
->tool_bar_window
))
27562 note_tool_bar_highlight (f
, x
, y
);
27567 /* Mouse is on the mode, header line or margin? */
27568 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
27569 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
27571 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
27575 #ifdef HAVE_WINDOW_SYSTEM
27576 if (part
== ON_VERTICAL_BORDER
)
27578 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
27579 help_echo_string
= build_string ("drag-mouse-1: resize");
27581 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
27582 || part
== ON_SCROLL_BAR
)
27583 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27585 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
27588 /* Are we in a window whose display is up to date?
27589 And verify the buffer's text has not changed. */
27590 b
= XBUFFER (w
->buffer
);
27591 if (part
== ON_TEXT
27592 && w
->window_end_valid
27593 && w
->last_modified
== BUF_MODIFF (b
)
27594 && w
->last_overlay_modified
== BUF_OVERLAY_MODIFF (b
))
27596 int hpos
, vpos
, dx
, dy
, area
= LAST_AREA
;
27598 struct glyph
*glyph
;
27599 Lisp_Object object
;
27600 Lisp_Object mouse_face
= Qnil
, position
;
27601 Lisp_Object
*overlay_vec
= NULL
;
27602 ptrdiff_t i
, noverlays
;
27603 struct buffer
*obuf
;
27604 ptrdiff_t obegv
, ozv
;
27607 /* Find the glyph under X/Y. */
27608 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
27610 #ifdef HAVE_WINDOW_SYSTEM
27611 /* Look for :pointer property on image. */
27612 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
27614 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
27615 if (img
!= NULL
&& IMAGEP (img
->spec
))
27617 Lisp_Object image_map
, hotspot
;
27618 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
27620 && (hotspot
= find_hot_spot (image_map
,
27621 glyph
->slice
.img
.x
+ dx
,
27622 glyph
->slice
.img
.y
+ dy
),
27624 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
27628 /* Could check XCAR (hotspot) to see if we enter/leave
27630 If so, we could look for mouse-enter, mouse-leave
27631 properties in PLIST (and do something...). */
27632 hotspot
= XCDR (hotspot
);
27633 if (CONSP (hotspot
)
27634 && (plist
= XCAR (hotspot
), CONSP (plist
)))
27636 pointer
= Fplist_get (plist
, Qpointer
);
27637 if (NILP (pointer
))
27639 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
27640 if (!NILP (help_echo_string
))
27642 help_echo_window
= window
;
27643 help_echo_object
= glyph
->object
;
27644 help_echo_pos
= glyph
->charpos
;
27648 if (NILP (pointer
))
27649 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
27652 #endif /* HAVE_WINDOW_SYSTEM */
27654 /* Clear mouse face if X/Y not over text. */
27656 || area
!= TEXT_AREA
27657 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
27658 /* Glyph's OBJECT is an integer for glyphs inserted by the
27659 display engine for its internal purposes, like truncation
27660 and continuation glyphs and blanks beyond the end of
27661 line's text on text terminals. If we are over such a
27662 glyph, we are not over any text. */
27663 || INTEGERP (glyph
->object
)
27664 /* R2L rows have a stretch glyph at their front, which
27665 stands for no text, whereas L2R rows have no glyphs at
27666 all beyond the end of text. Treat such stretch glyphs
27667 like we do with NULL glyphs in L2R rows. */
27668 || (MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
27669 && glyph
== MATRIX_ROW (w
->current_matrix
, vpos
)->glyphs
[TEXT_AREA
]
27670 && glyph
->type
== STRETCH_GLYPH
27671 && glyph
->avoid_cursor_p
))
27673 if (clear_mouse_face (hlinfo
))
27674 cursor
= No_Cursor
;
27675 #ifdef HAVE_WINDOW_SYSTEM
27676 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
27678 if (area
!= TEXT_AREA
)
27679 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27681 pointer
= Vvoid_text_area_pointer
;
27687 pos
= glyph
->charpos
;
27688 object
= glyph
->object
;
27689 if (!STRINGP (object
) && !BUFFERP (object
))
27692 /* If we get an out-of-range value, return now; avoid an error. */
27693 if (BUFFERP (object
) && pos
> BUF_Z (b
))
27696 /* Make the window's buffer temporarily current for
27697 overlays_at and compute_char_face. */
27698 obuf
= current_buffer
;
27699 current_buffer
= b
;
27705 /* Is this char mouse-active or does it have help-echo? */
27706 position
= make_number (pos
);
27708 if (BUFFERP (object
))
27710 /* Put all the overlays we want in a vector in overlay_vec. */
27711 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
27712 /* Sort overlays into increasing priority order. */
27713 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
27718 same_region
= coords_in_mouse_face_p (w
, hpos
, vpos
);
27721 cursor
= No_Cursor
;
27723 /* Check mouse-face highlighting. */
27725 /* If there exists an overlay with mouse-face overlapping
27726 the one we are currently highlighting, we have to
27727 check if we enter the overlapping overlay, and then
27728 highlight only that. */
27729 || (OVERLAYP (hlinfo
->mouse_face_overlay
)
27730 && mouse_face_overlay_overlaps (hlinfo
->mouse_face_overlay
)))
27732 /* Find the highest priority overlay with a mouse-face. */
27733 Lisp_Object overlay
= Qnil
;
27734 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
27736 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
27737 if (!NILP (mouse_face
))
27738 overlay
= overlay_vec
[i
];
27741 /* If we're highlighting the same overlay as before, there's
27742 no need to do that again. */
27743 if (!NILP (overlay
) && EQ (overlay
, hlinfo
->mouse_face_overlay
))
27744 goto check_help_echo
;
27745 hlinfo
->mouse_face_overlay
= overlay
;
27747 /* Clear the display of the old active region, if any. */
27748 if (clear_mouse_face (hlinfo
))
27749 cursor
= No_Cursor
;
27751 /* If no overlay applies, get a text property. */
27752 if (NILP (overlay
))
27753 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
27755 /* Next, compute the bounds of the mouse highlighting and
27757 if (!NILP (mouse_face
) && STRINGP (object
))
27759 /* The mouse-highlighting comes from a display string
27760 with a mouse-face. */
27764 s
= Fprevious_single_property_change
27765 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
27766 e
= Fnext_single_property_change
27767 (position
, Qmouse_face
, object
, Qnil
);
27769 s
= make_number (0);
27771 e
= make_number (SCHARS (object
) - 1);
27772 mouse_face_from_string_pos (w
, hlinfo
, object
,
27773 XINT (s
), XINT (e
));
27774 hlinfo
->mouse_face_past_end
= 0;
27775 hlinfo
->mouse_face_window
= window
;
27776 hlinfo
->mouse_face_face_id
27777 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
27778 glyph
->face_id
, 1);
27779 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
27780 cursor
= No_Cursor
;
27784 /* The mouse-highlighting, if any, comes from an overlay
27785 or text property in the buffer. */
27786 Lisp_Object buffer
IF_LINT (= Qnil
);
27787 Lisp_Object disp_string
IF_LINT (= Qnil
);
27789 if (STRINGP (object
))
27791 /* If we are on a display string with no mouse-face,
27792 check if the text under it has one. */
27793 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
27794 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
27795 pos
= string_buffer_position (object
, start
);
27798 mouse_face
= get_char_property_and_overlay
27799 (make_number (pos
), Qmouse_face
, w
->buffer
, &overlay
);
27800 buffer
= w
->buffer
;
27801 disp_string
= object
;
27807 disp_string
= Qnil
;
27810 if (!NILP (mouse_face
))
27812 Lisp_Object before
, after
;
27813 Lisp_Object before_string
, after_string
;
27814 /* To correctly find the limits of mouse highlight
27815 in a bidi-reordered buffer, we must not use the
27816 optimization of limiting the search in
27817 previous-single-property-change and
27818 next-single-property-change, because
27819 rows_from_pos_range needs the real start and end
27820 positions to DTRT in this case. That's because
27821 the first row visible in a window does not
27822 necessarily display the character whose position
27823 is the smallest. */
27825 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
27826 ? Fmarker_position (w
->start
)
27829 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
27830 ? make_number (BUF_Z (XBUFFER (buffer
))
27831 - XFASTINT (w
->window_end_pos
))
27834 if (NILP (overlay
))
27836 /* Handle the text property case. */
27837 before
= Fprevious_single_property_change
27838 (make_number (pos
+ 1), Qmouse_face
, buffer
, lim1
);
27839 after
= Fnext_single_property_change
27840 (make_number (pos
), Qmouse_face
, buffer
, lim2
);
27841 before_string
= after_string
= Qnil
;
27845 /* Handle the overlay case. */
27846 before
= Foverlay_start (overlay
);
27847 after
= Foverlay_end (overlay
);
27848 before_string
= Foverlay_get (overlay
, Qbefore_string
);
27849 after_string
= Foverlay_get (overlay
, Qafter_string
);
27851 if (!STRINGP (before_string
)) before_string
= Qnil
;
27852 if (!STRINGP (after_string
)) after_string
= Qnil
;
27855 mouse_face_from_buffer_pos (window
, hlinfo
, pos
,
27858 : XFASTINT (before
),
27860 ? BUF_Z (XBUFFER (buffer
))
27861 : XFASTINT (after
),
27862 before_string
, after_string
,
27864 cursor
= No_Cursor
;
27871 /* Look for a `help-echo' property. */
27872 if (NILP (help_echo_string
)) {
27873 Lisp_Object help
, overlay
;
27875 /* Check overlays first. */
27876 help
= overlay
= Qnil
;
27877 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
27879 overlay
= overlay_vec
[i
];
27880 help
= Foverlay_get (overlay
, Qhelp_echo
);
27885 help_echo_string
= help
;
27886 help_echo_window
= window
;
27887 help_echo_object
= overlay
;
27888 help_echo_pos
= pos
;
27892 Lisp_Object obj
= glyph
->object
;
27893 ptrdiff_t charpos
= glyph
->charpos
;
27895 /* Try text properties. */
27898 && charpos
< SCHARS (obj
))
27900 help
= Fget_text_property (make_number (charpos
),
27904 /* If the string itself doesn't specify a help-echo,
27905 see if the buffer text ``under'' it does. */
27906 struct glyph_row
*r
27907 = MATRIX_ROW (w
->current_matrix
, vpos
);
27908 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
27909 ptrdiff_t p
= string_buffer_position (obj
, start
);
27912 help
= Fget_char_property (make_number (p
),
27913 Qhelp_echo
, w
->buffer
);
27922 else if (BUFFERP (obj
)
27925 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
27930 help_echo_string
= help
;
27931 help_echo_window
= window
;
27932 help_echo_object
= obj
;
27933 help_echo_pos
= charpos
;
27938 #ifdef HAVE_WINDOW_SYSTEM
27939 /* Look for a `pointer' property. */
27940 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
27942 /* Check overlays first. */
27943 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
27944 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
27946 if (NILP (pointer
))
27948 Lisp_Object obj
= glyph
->object
;
27949 ptrdiff_t charpos
= glyph
->charpos
;
27951 /* Try text properties. */
27954 && charpos
< SCHARS (obj
))
27956 pointer
= Fget_text_property (make_number (charpos
),
27958 if (NILP (pointer
))
27960 /* If the string itself doesn't specify a pointer,
27961 see if the buffer text ``under'' it does. */
27962 struct glyph_row
*r
27963 = MATRIX_ROW (w
->current_matrix
, vpos
);
27964 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
27965 ptrdiff_t p
= string_buffer_position (obj
, start
);
27967 pointer
= Fget_char_property (make_number (p
),
27968 Qpointer
, w
->buffer
);
27971 else if (BUFFERP (obj
)
27974 pointer
= Fget_text_property (make_number (charpos
),
27978 #endif /* HAVE_WINDOW_SYSTEM */
27982 current_buffer
= obuf
;
27987 #ifdef HAVE_WINDOW_SYSTEM
27988 if (FRAME_WINDOW_P (f
))
27989 define_frame_cursor1 (f
, cursor
, pointer
);
27991 /* This is here to prevent a compiler error, about "label at end of
27992 compound statement". */
27999 Clear any mouse-face on window W. This function is part of the
28000 redisplay interface, and is called from try_window_id and similar
28001 functions to ensure the mouse-highlight is off. */
28004 x_clear_window_mouse_face (struct window
*w
)
28006 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
28007 Lisp_Object window
;
28010 XSETWINDOW (window
, w
);
28011 if (EQ (window
, hlinfo
->mouse_face_window
))
28012 clear_mouse_face (hlinfo
);
28018 Just discard the mouse face information for frame F, if any.
28019 This is used when the size of F is changed. */
28022 cancel_mouse_face (struct frame
*f
)
28024 Lisp_Object window
;
28025 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28027 window
= hlinfo
->mouse_face_window
;
28028 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
28030 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
28031 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
28032 hlinfo
->mouse_face_window
= Qnil
;
28038 /***********************************************************************
28040 ***********************************************************************/
28042 #ifdef HAVE_WINDOW_SYSTEM
28044 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
28045 which intersects rectangle R. R is in window-relative coordinates. */
28048 expose_area (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
,
28049 enum glyph_row_area area
)
28051 struct glyph
*first
= row
->glyphs
[area
];
28052 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
28053 struct glyph
*last
;
28054 int first_x
, start_x
, x
;
28056 if (area
== TEXT_AREA
&& row
->fill_line_p
)
28057 /* If row extends face to end of line write the whole line. */
28058 draw_glyphs (w
, 0, row
, area
,
28059 0, row
->used
[area
],
28060 DRAW_NORMAL_TEXT
, 0);
28063 /* Set START_X to the window-relative start position for drawing glyphs of
28064 AREA. The first glyph of the text area can be partially visible.
28065 The first glyphs of other areas cannot. */
28066 start_x
= window_box_left_offset (w
, area
);
28068 if (area
== TEXT_AREA
)
28071 /* Find the first glyph that must be redrawn. */
28073 && x
+ first
->pixel_width
< r
->x
)
28075 x
+= first
->pixel_width
;
28079 /* Find the last one. */
28083 && x
< r
->x
+ r
->width
)
28085 x
+= last
->pixel_width
;
28091 draw_glyphs (w
, first_x
- start_x
, row
, area
,
28092 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
28093 DRAW_NORMAL_TEXT
, 0);
28098 /* Redraw the parts of the glyph row ROW on window W intersecting
28099 rectangle R. R is in window-relative coordinates. Value is
28100 non-zero if mouse-face was overwritten. */
28103 expose_line (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
)
28105 eassert (row
->enabled_p
);
28107 if (row
->mode_line_p
|| w
->pseudo_window_p
)
28108 draw_glyphs (w
, 0, row
, TEXT_AREA
,
28109 0, row
->used
[TEXT_AREA
],
28110 DRAW_NORMAL_TEXT
, 0);
28113 if (row
->used
[LEFT_MARGIN_AREA
])
28114 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
28115 if (row
->used
[TEXT_AREA
])
28116 expose_area (w
, row
, r
, TEXT_AREA
);
28117 if (row
->used
[RIGHT_MARGIN_AREA
])
28118 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
28119 draw_row_fringe_bitmaps (w
, row
);
28122 return row
->mouse_face_p
;
28126 /* Redraw those parts of glyphs rows during expose event handling that
28127 overlap other rows. Redrawing of an exposed line writes over parts
28128 of lines overlapping that exposed line; this function fixes that.
28130 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
28131 row in W's current matrix that is exposed and overlaps other rows.
28132 LAST_OVERLAPPING_ROW is the last such row. */
28135 expose_overlaps (struct window
*w
,
28136 struct glyph_row
*first_overlapping_row
,
28137 struct glyph_row
*last_overlapping_row
,
28140 struct glyph_row
*row
;
28142 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
28143 if (row
->overlapping_p
)
28145 eassert (row
->enabled_p
&& !row
->mode_line_p
);
28148 if (row
->used
[LEFT_MARGIN_AREA
])
28149 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
28151 if (row
->used
[TEXT_AREA
])
28152 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
28154 if (row
->used
[RIGHT_MARGIN_AREA
])
28155 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
28161 /* Return non-zero if W's cursor intersects rectangle R. */
28164 phys_cursor_in_rect_p (struct window
*w
, XRectangle
*r
)
28166 XRectangle cr
, result
;
28167 struct glyph
*cursor_glyph
;
28168 struct glyph_row
*row
;
28170 if (w
->phys_cursor
.vpos
>= 0
28171 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
28172 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
28174 && row
->cursor_in_fringe_p
)
28176 /* Cursor is in the fringe. */
28177 cr
.x
= window_box_right_offset (w
,
28178 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
28179 ? RIGHT_MARGIN_AREA
28182 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
28183 cr
.height
= row
->height
;
28184 return x_intersect_rectangles (&cr
, r
, &result
);
28187 cursor_glyph
= get_phys_cursor_glyph (w
);
28190 /* r is relative to W's box, but w->phys_cursor.x is relative
28191 to left edge of W's TEXT area. Adjust it. */
28192 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
28193 cr
.y
= w
->phys_cursor
.y
;
28194 cr
.width
= cursor_glyph
->pixel_width
;
28195 cr
.height
= w
->phys_cursor_height
;
28196 /* ++KFS: W32 version used W32-specific IntersectRect here, but
28197 I assume the effect is the same -- and this is portable. */
28198 return x_intersect_rectangles (&cr
, r
, &result
);
28200 /* If we don't understand the format, pretend we're not in the hot-spot. */
28206 Draw a vertical window border to the right of window W if W doesn't
28207 have vertical scroll bars. */
28210 x_draw_vertical_border (struct window
*w
)
28212 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
28214 /* We could do better, if we knew what type of scroll-bar the adjacent
28215 windows (on either side) have... But we don't :-(
28216 However, I think this works ok. ++KFS 2003-04-25 */
28218 /* Redraw borders between horizontally adjacent windows. Don't
28219 do it for frames with vertical scroll bars because either the
28220 right scroll bar of a window, or the left scroll bar of its
28221 neighbor will suffice as a border. */
28222 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
28225 if (!WINDOW_RIGHTMOST_P (w
)
28226 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
28228 int x0
, x1
, y0
, y1
;
28230 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
28233 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
28236 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
28238 else if (!WINDOW_LEFTMOST_P (w
)
28239 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
28241 int x0
, x1
, y0
, y1
;
28243 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
28246 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
28249 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
28254 /* Redraw the part of window W intersection rectangle FR. Pixel
28255 coordinates in FR are frame-relative. Call this function with
28256 input blocked. Value is non-zero if the exposure overwrites
28260 expose_window (struct window
*w
, XRectangle
*fr
)
28262 struct frame
*f
= XFRAME (w
->frame
);
28264 int mouse_face_overwritten_p
= 0;
28266 /* If window is not yet fully initialized, do nothing. This can
28267 happen when toolkit scroll bars are used and a window is split.
28268 Reconfiguring the scroll bar will generate an expose for a newly
28270 if (w
->current_matrix
== NULL
)
28273 /* When we're currently updating the window, display and current
28274 matrix usually don't agree. Arrange for a thorough display
28276 if (w
== updated_window
)
28278 SET_FRAME_GARBAGED (f
);
28282 /* Frame-relative pixel rectangle of W. */
28283 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
28284 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
28285 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
28286 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
28288 if (x_intersect_rectangles (fr
, &wr
, &r
))
28290 int yb
= window_text_bottom_y (w
);
28291 struct glyph_row
*row
;
28292 int cursor_cleared_p
, phys_cursor_on_p
;
28293 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
28295 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
28296 r
.x
, r
.y
, r
.width
, r
.height
));
28298 /* Convert to window coordinates. */
28299 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
28300 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
28302 /* Turn off the cursor. */
28303 if (!w
->pseudo_window_p
28304 && phys_cursor_in_rect_p (w
, &r
))
28306 x_clear_cursor (w
);
28307 cursor_cleared_p
= 1;
28310 cursor_cleared_p
= 0;
28312 /* If the row containing the cursor extends face to end of line,
28313 then expose_area might overwrite the cursor outside the
28314 rectangle and thus notice_overwritten_cursor might clear
28315 w->phys_cursor_on_p. We remember the original value and
28316 check later if it is changed. */
28317 phys_cursor_on_p
= w
->phys_cursor_on_p
;
28319 /* Update lines intersecting rectangle R. */
28320 first_overlapping_row
= last_overlapping_row
= NULL
;
28321 for (row
= w
->current_matrix
->rows
;
28326 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
28328 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
28329 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
28330 || (r
.y
>= y0
&& r
.y
< y1
)
28331 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
28333 /* A header line may be overlapping, but there is no need
28334 to fix overlapping areas for them. KFS 2005-02-12 */
28335 if (row
->overlapping_p
&& !row
->mode_line_p
)
28337 if (first_overlapping_row
== NULL
)
28338 first_overlapping_row
= row
;
28339 last_overlapping_row
= row
;
28343 if (expose_line (w
, row
, &r
))
28344 mouse_face_overwritten_p
= 1;
28347 else if (row
->overlapping_p
)
28349 /* We must redraw a row overlapping the exposed area. */
28351 ? y0
+ row
->phys_height
> r
.y
28352 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
28354 if (first_overlapping_row
== NULL
)
28355 first_overlapping_row
= row
;
28356 last_overlapping_row
= row
;
28364 /* Display the mode line if there is one. */
28365 if (WINDOW_WANTS_MODELINE_P (w
)
28366 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
28368 && row
->y
< r
.y
+ r
.height
)
28370 if (expose_line (w
, row
, &r
))
28371 mouse_face_overwritten_p
= 1;
28374 if (!w
->pseudo_window_p
)
28376 /* Fix the display of overlapping rows. */
28377 if (first_overlapping_row
)
28378 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
28381 /* Draw border between windows. */
28382 x_draw_vertical_border (w
);
28384 /* Turn the cursor on again. */
28385 if (cursor_cleared_p
28386 || (phys_cursor_on_p
&& !w
->phys_cursor_on_p
))
28387 update_window_cursor (w
, 1);
28391 return mouse_face_overwritten_p
;
28396 /* Redraw (parts) of all windows in the window tree rooted at W that
28397 intersect R. R contains frame pixel coordinates. Value is
28398 non-zero if the exposure overwrites mouse-face. */
28401 expose_window_tree (struct window
*w
, XRectangle
*r
)
28403 struct frame
*f
= XFRAME (w
->frame
);
28404 int mouse_face_overwritten_p
= 0;
28406 while (w
&& !FRAME_GARBAGED_P (f
))
28408 if (!NILP (w
->hchild
))
28409 mouse_face_overwritten_p
28410 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
28411 else if (!NILP (w
->vchild
))
28412 mouse_face_overwritten_p
28413 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
28415 mouse_face_overwritten_p
|= expose_window (w
, r
);
28417 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
28420 return mouse_face_overwritten_p
;
28425 Redisplay an exposed area of frame F. X and Y are the upper-left
28426 corner of the exposed rectangle. W and H are width and height of
28427 the exposed area. All are pixel values. W or H zero means redraw
28428 the entire frame. */
28431 expose_frame (struct frame
*f
, int x
, int y
, int w
, int h
)
28434 int mouse_face_overwritten_p
= 0;
28436 TRACE ((stderr
, "expose_frame "));
28438 /* No need to redraw if frame will be redrawn soon. */
28439 if (FRAME_GARBAGED_P (f
))
28441 TRACE ((stderr
, " garbaged\n"));
28445 /* If basic faces haven't been realized yet, there is no point in
28446 trying to redraw anything. This can happen when we get an expose
28447 event while Emacs is starting, e.g. by moving another window. */
28448 if (FRAME_FACE_CACHE (f
) == NULL
28449 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
28451 TRACE ((stderr
, " no faces\n"));
28455 if (w
== 0 || h
== 0)
28458 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
28459 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
28469 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
28470 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
28472 if (WINDOWP (f
->tool_bar_window
))
28473 mouse_face_overwritten_p
28474 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
28476 #ifdef HAVE_X_WINDOWS
28478 #ifndef USE_X_TOOLKIT
28479 if (WINDOWP (f
->menu_bar_window
))
28480 mouse_face_overwritten_p
28481 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
28482 #endif /* not USE_X_TOOLKIT */
28486 /* Some window managers support a focus-follows-mouse style with
28487 delayed raising of frames. Imagine a partially obscured frame,
28488 and moving the mouse into partially obscured mouse-face on that
28489 frame. The visible part of the mouse-face will be highlighted,
28490 then the WM raises the obscured frame. With at least one WM, KDE
28491 2.1, Emacs is not getting any event for the raising of the frame
28492 (even tried with SubstructureRedirectMask), only Expose events.
28493 These expose events will draw text normally, i.e. not
28494 highlighted. Which means we must redo the highlight here.
28495 Subsume it under ``we love X''. --gerd 2001-08-15 */
28496 /* Included in Windows version because Windows most likely does not
28497 do the right thing if any third party tool offers
28498 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
28499 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
28501 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28502 if (f
== hlinfo
->mouse_face_mouse_frame
)
28504 int mouse_x
= hlinfo
->mouse_face_mouse_x
;
28505 int mouse_y
= hlinfo
->mouse_face_mouse_y
;
28506 clear_mouse_face (hlinfo
);
28507 note_mouse_highlight (f
, mouse_x
, mouse_y
);
28514 Determine the intersection of two rectangles R1 and R2. Return
28515 the intersection in *RESULT. Value is non-zero if RESULT is not
28519 x_intersect_rectangles (XRectangle
*r1
, XRectangle
*r2
, XRectangle
*result
)
28521 XRectangle
*left
, *right
;
28522 XRectangle
*upper
, *lower
;
28523 int intersection_p
= 0;
28525 /* Rearrange so that R1 is the left-most rectangle. */
28527 left
= r1
, right
= r2
;
28529 left
= r2
, right
= r1
;
28531 /* X0 of the intersection is right.x0, if this is inside R1,
28532 otherwise there is no intersection. */
28533 if (right
->x
<= left
->x
+ left
->width
)
28535 result
->x
= right
->x
;
28537 /* The right end of the intersection is the minimum of
28538 the right ends of left and right. */
28539 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
28542 /* Same game for Y. */
28544 upper
= r1
, lower
= r2
;
28546 upper
= r2
, lower
= r1
;
28548 /* The upper end of the intersection is lower.y0, if this is inside
28549 of upper. Otherwise, there is no intersection. */
28550 if (lower
->y
<= upper
->y
+ upper
->height
)
28552 result
->y
= lower
->y
;
28554 /* The lower end of the intersection is the minimum of the lower
28555 ends of upper and lower. */
28556 result
->height
= (min (lower
->y
+ lower
->height
,
28557 upper
->y
+ upper
->height
)
28559 intersection_p
= 1;
28563 return intersection_p
;
28566 #endif /* HAVE_WINDOW_SYSTEM */
28569 /***********************************************************************
28571 ***********************************************************************/
28574 syms_of_xdisp (void)
28576 Vwith_echo_area_save_vector
= Qnil
;
28577 staticpro (&Vwith_echo_area_save_vector
);
28579 Vmessage_stack
= Qnil
;
28580 staticpro (&Vmessage_stack
);
28582 DEFSYM (Qinhibit_redisplay
, "inhibit-redisplay");
28583 DEFSYM (Qredisplay_internal
, "redisplay_internal (C function)");
28585 message_dolog_marker1
= Fmake_marker ();
28586 staticpro (&message_dolog_marker1
);
28587 message_dolog_marker2
= Fmake_marker ();
28588 staticpro (&message_dolog_marker2
);
28589 message_dolog_marker3
= Fmake_marker ();
28590 staticpro (&message_dolog_marker3
);
28593 defsubr (&Sdump_frame_glyph_matrix
);
28594 defsubr (&Sdump_glyph_matrix
);
28595 defsubr (&Sdump_glyph_row
);
28596 defsubr (&Sdump_tool_bar_row
);
28597 defsubr (&Strace_redisplay
);
28598 defsubr (&Strace_to_stderr
);
28600 #ifdef HAVE_WINDOW_SYSTEM
28601 defsubr (&Stool_bar_lines_needed
);
28602 defsubr (&Slookup_image_map
);
28604 defsubr (&Sformat_mode_line
);
28605 defsubr (&Sinvisible_p
);
28606 defsubr (&Scurrent_bidi_paragraph_direction
);
28608 DEFSYM (Qmenu_bar_update_hook
, "menu-bar-update-hook");
28609 DEFSYM (Qoverriding_terminal_local_map
, "overriding-terminal-local-map");
28610 DEFSYM (Qoverriding_local_map
, "overriding-local-map");
28611 DEFSYM (Qwindow_scroll_functions
, "window-scroll-functions");
28612 DEFSYM (Qwindow_text_change_functions
, "window-text-change-functions");
28613 DEFSYM (Qredisplay_end_trigger_functions
, "redisplay-end-trigger-functions");
28614 DEFSYM (Qinhibit_point_motion_hooks
, "inhibit-point-motion-hooks");
28615 DEFSYM (Qeval
, "eval");
28616 DEFSYM (QCdata
, ":data");
28617 DEFSYM (Qdisplay
, "display");
28618 DEFSYM (Qspace_width
, "space-width");
28619 DEFSYM (Qraise
, "raise");
28620 DEFSYM (Qslice
, "slice");
28621 DEFSYM (Qspace
, "space");
28622 DEFSYM (Qmargin
, "margin");
28623 DEFSYM (Qpointer
, "pointer");
28624 DEFSYM (Qleft_margin
, "left-margin");
28625 DEFSYM (Qright_margin
, "right-margin");
28626 DEFSYM (Qcenter
, "center");
28627 DEFSYM (Qline_height
, "line-height");
28628 DEFSYM (QCalign_to
, ":align-to");
28629 DEFSYM (QCrelative_width
, ":relative-width");
28630 DEFSYM (QCrelative_height
, ":relative-height");
28631 DEFSYM (QCeval
, ":eval");
28632 DEFSYM (QCpropertize
, ":propertize");
28633 DEFSYM (QCfile
, ":file");
28634 DEFSYM (Qfontified
, "fontified");
28635 DEFSYM (Qfontification_functions
, "fontification-functions");
28636 DEFSYM (Qtrailing_whitespace
, "trailing-whitespace");
28637 DEFSYM (Qescape_glyph
, "escape-glyph");
28638 DEFSYM (Qnobreak_space
, "nobreak-space");
28639 DEFSYM (Qimage
, "image");
28640 DEFSYM (Qtext
, "text");
28641 DEFSYM (Qboth
, "both");
28642 DEFSYM (Qboth_horiz
, "both-horiz");
28643 DEFSYM (Qtext_image_horiz
, "text-image-horiz");
28644 DEFSYM (QCmap
, ":map");
28645 DEFSYM (QCpointer
, ":pointer");
28646 DEFSYM (Qrect
, "rect");
28647 DEFSYM (Qcircle
, "circle");
28648 DEFSYM (Qpoly
, "poly");
28649 DEFSYM (Qmessage_truncate_lines
, "message-truncate-lines");
28650 DEFSYM (Qgrow_only
, "grow-only");
28651 DEFSYM (Qinhibit_menubar_update
, "inhibit-menubar-update");
28652 DEFSYM (Qinhibit_eval_during_redisplay
, "inhibit-eval-during-redisplay");
28653 DEFSYM (Qposition
, "position");
28654 DEFSYM (Qbuffer_position
, "buffer-position");
28655 DEFSYM (Qobject
, "object");
28656 DEFSYM (Qbar
, "bar");
28657 DEFSYM (Qhbar
, "hbar");
28658 DEFSYM (Qbox
, "box");
28659 DEFSYM (Qhollow
, "hollow");
28660 DEFSYM (Qhand
, "hand");
28661 DEFSYM (Qarrow
, "arrow");
28662 DEFSYM (Qinhibit_free_realized_faces
, "inhibit-free-realized-faces");
28664 list_of_error
= Fcons (Fcons (intern_c_string ("error"),
28665 Fcons (intern_c_string ("void-variable"), Qnil
)),
28667 staticpro (&list_of_error
);
28669 DEFSYM (Qlast_arrow_position
, "last-arrow-position");
28670 DEFSYM (Qlast_arrow_string
, "last-arrow-string");
28671 DEFSYM (Qoverlay_arrow_string
, "overlay-arrow-string");
28672 DEFSYM (Qoverlay_arrow_bitmap
, "overlay-arrow-bitmap");
28674 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
28675 staticpro (&echo_buffer
[0]);
28676 staticpro (&echo_buffer
[1]);
28678 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
28679 staticpro (&echo_area_buffer
[0]);
28680 staticpro (&echo_area_buffer
[1]);
28682 Vmessages_buffer_name
= build_pure_c_string ("*Messages*");
28683 staticpro (&Vmessages_buffer_name
);
28685 mode_line_proptrans_alist
= Qnil
;
28686 staticpro (&mode_line_proptrans_alist
);
28687 mode_line_string_list
= Qnil
;
28688 staticpro (&mode_line_string_list
);
28689 mode_line_string_face
= Qnil
;
28690 staticpro (&mode_line_string_face
);
28691 mode_line_string_face_prop
= Qnil
;
28692 staticpro (&mode_line_string_face_prop
);
28693 Vmode_line_unwind_vector
= Qnil
;
28694 staticpro (&Vmode_line_unwind_vector
);
28696 DEFSYM (Qmode_line_default_help_echo
, "mode-line-default-help-echo");
28698 help_echo_string
= Qnil
;
28699 staticpro (&help_echo_string
);
28700 help_echo_object
= Qnil
;
28701 staticpro (&help_echo_object
);
28702 help_echo_window
= Qnil
;
28703 staticpro (&help_echo_window
);
28704 previous_help_echo_string
= Qnil
;
28705 staticpro (&previous_help_echo_string
);
28706 help_echo_pos
= -1;
28708 DEFSYM (Qright_to_left
, "right-to-left");
28709 DEFSYM (Qleft_to_right
, "left-to-right");
28711 #ifdef HAVE_WINDOW_SYSTEM
28712 DEFVAR_BOOL ("x-stretch-cursor", x_stretch_cursor_p
,
28713 doc
: /* Non-nil means draw block cursor as wide as the glyph under it.
28714 For example, if a block cursor is over a tab, it will be drawn as
28715 wide as that tab on the display. */);
28716 x_stretch_cursor_p
= 0;
28719 DEFVAR_LISP ("show-trailing-whitespace", Vshow_trailing_whitespace
,
28720 doc
: /* Non-nil means highlight trailing whitespace.
28721 The face used for trailing whitespace is `trailing-whitespace'. */);
28722 Vshow_trailing_whitespace
= Qnil
;
28724 DEFVAR_LISP ("nobreak-char-display", Vnobreak_char_display
,
28725 doc
: /* Control highlighting of non-ASCII space and hyphen chars.
28726 If the value is t, Emacs highlights non-ASCII chars which have the
28727 same appearance as an ASCII space or hyphen, using the `nobreak-space'
28728 or `escape-glyph' face respectively.
28730 U+00A0 (no-break space), U+00AD (soft hyphen), U+2010 (hyphen), and
28731 U+2011 (non-breaking hyphen) are affected.
28733 Any other non-nil value means to display these characters as a escape
28734 glyph followed by an ordinary space or hyphen.
28736 A value of nil means no special handling of these characters. */);
28737 Vnobreak_char_display
= Qt
;
28739 DEFVAR_LISP ("void-text-area-pointer", Vvoid_text_area_pointer
,
28740 doc
: /* The pointer shape to show in void text areas.
28741 A value of nil means to show the text pointer. Other options are `arrow',
28742 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
28743 Vvoid_text_area_pointer
= Qarrow
;
28745 DEFVAR_LISP ("inhibit-redisplay", Vinhibit_redisplay
,
28746 doc
: /* Non-nil means don't actually do any redisplay.
28747 This is used for internal purposes. */);
28748 Vinhibit_redisplay
= Qnil
;
28750 DEFVAR_LISP ("global-mode-string", Vglobal_mode_string
,
28751 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
28752 Vglobal_mode_string
= Qnil
;
28754 DEFVAR_LISP ("overlay-arrow-position", Voverlay_arrow_position
,
28755 doc
: /* Marker for where to display an arrow on top of the buffer text.
28756 This must be the beginning of a line in order to work.
28757 See also `overlay-arrow-string'. */);
28758 Voverlay_arrow_position
= Qnil
;
28760 DEFVAR_LISP ("overlay-arrow-string", Voverlay_arrow_string
,
28761 doc
: /* String to display as an arrow in non-window frames.
28762 See also `overlay-arrow-position'. */);
28763 Voverlay_arrow_string
= build_pure_c_string ("=>");
28765 DEFVAR_LISP ("overlay-arrow-variable-list", Voverlay_arrow_variable_list
,
28766 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
28767 The symbols on this list are examined during redisplay to determine
28768 where to display overlay arrows. */);
28769 Voverlay_arrow_variable_list
28770 = Fcons (intern_c_string ("overlay-arrow-position"), Qnil
);
28772 DEFVAR_INT ("scroll-step", emacs_scroll_step
,
28773 doc
: /* The number of lines to try scrolling a window by when point moves out.
28774 If that fails to bring point back on frame, point is centered instead.
28775 If this is zero, point is always centered after it moves off frame.
28776 If you want scrolling to always be a line at a time, you should set
28777 `scroll-conservatively' to a large value rather than set this to 1. */);
28779 DEFVAR_INT ("scroll-conservatively", scroll_conservatively
,
28780 doc
: /* Scroll up to this many lines, to bring point back on screen.
28781 If point moves off-screen, redisplay will scroll by up to
28782 `scroll-conservatively' lines in order to bring point just barely
28783 onto the screen again. If that cannot be done, then redisplay
28784 recenters point as usual.
28786 If the value is greater than 100, redisplay will never recenter point,
28787 but will always scroll just enough text to bring point into view, even
28788 if you move far away.
28790 A value of zero means always recenter point if it moves off screen. */);
28791 scroll_conservatively
= 0;
28793 DEFVAR_INT ("scroll-margin", scroll_margin
,
28794 doc
: /* Number of lines of margin at the top and bottom of a window.
28795 Recenter the window whenever point gets within this many lines
28796 of the top or bottom of the window. */);
28799 DEFVAR_LISP ("display-pixels-per-inch", Vdisplay_pixels_per_inch
,
28800 doc
: /* Pixels per inch value for non-window system displays.
28801 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
28802 Vdisplay_pixels_per_inch
= make_float (72.0);
28805 DEFVAR_INT ("debug-end-pos", debug_end_pos
, doc
: /* Don't ask. */);
28808 DEFVAR_LISP ("truncate-partial-width-windows",
28809 Vtruncate_partial_width_windows
,
28810 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
28811 For an integer value, truncate lines in each window narrower than the
28812 full frame width, provided the window width is less than that integer;
28813 otherwise, respect the value of `truncate-lines'.
28815 For any other non-nil value, truncate lines in all windows that do
28816 not span the full frame width.
28818 A value of nil means to respect the value of `truncate-lines'.
28820 If `word-wrap' is enabled, you might want to reduce this. */);
28821 Vtruncate_partial_width_windows
= make_number (50);
28823 DEFVAR_LISP ("line-number-display-limit", Vline_number_display_limit
,
28824 doc
: /* Maximum buffer size for which line number should be displayed.
28825 If the buffer is bigger than this, the line number does not appear
28826 in the mode line. A value of nil means no limit. */);
28827 Vline_number_display_limit
= Qnil
;
28829 DEFVAR_INT ("line-number-display-limit-width",
28830 line_number_display_limit_width
,
28831 doc
: /* Maximum line width (in characters) for line number display.
28832 If the average length of the lines near point is bigger than this, then the
28833 line number may be omitted from the mode line. */);
28834 line_number_display_limit_width
= 200;
28836 DEFVAR_BOOL ("highlight-nonselected-windows", highlight_nonselected_windows
,
28837 doc
: /* Non-nil means highlight region even in nonselected windows. */);
28838 highlight_nonselected_windows
= 0;
28840 DEFVAR_BOOL ("multiple-frames", multiple_frames
,
28841 doc
: /* Non-nil if more than one frame is visible on this display.
28842 Minibuffer-only frames don't count, but iconified frames do.
28843 This variable is not guaranteed to be accurate except while processing
28844 `frame-title-format' and `icon-title-format'. */);
28846 DEFVAR_LISP ("frame-title-format", Vframe_title_format
,
28847 doc
: /* Template for displaying the title bar of visible frames.
28848 \(Assuming the window manager supports this feature.)
28850 This variable has the same structure as `mode-line-format', except that
28851 the %c and %l constructs are ignored. It is used only on frames for
28852 which no explicit name has been set \(see `modify-frame-parameters'). */);
28854 DEFVAR_LISP ("icon-title-format", Vicon_title_format
,
28855 doc
: /* Template for displaying the title bar of an iconified frame.
28856 \(Assuming the window manager supports this feature.)
28857 This variable has the same structure as `mode-line-format' (which see),
28858 and is used only on frames for which no explicit name has been set
28859 \(see `modify-frame-parameters'). */);
28861 = Vframe_title_format
28862 = listn (CONSTYPE_PURE
, 3,
28863 intern_c_string ("multiple-frames"),
28864 build_pure_c_string ("%b"),
28865 listn (CONSTYPE_PURE
, 4,
28866 empty_unibyte_string
,
28867 intern_c_string ("invocation-name"),
28868 build_pure_c_string ("@"),
28869 intern_c_string ("system-name")));
28871 DEFVAR_LISP ("message-log-max", Vmessage_log_max
,
28872 doc
: /* Maximum number of lines to keep in the message log buffer.
28873 If nil, disable message logging. If t, log messages but don't truncate
28874 the buffer when it becomes large. */);
28875 Vmessage_log_max
= make_number (1000);
28877 DEFVAR_LISP ("window-size-change-functions", Vwindow_size_change_functions
,
28878 doc
: /* Functions called before redisplay, if window sizes have changed.
28879 The value should be a list of functions that take one argument.
28880 Just before redisplay, for each frame, if any of its windows have changed
28881 size since the last redisplay, or have been split or deleted,
28882 all the functions in the list are called, with the frame as argument. */);
28883 Vwindow_size_change_functions
= Qnil
;
28885 DEFVAR_LISP ("window-scroll-functions", Vwindow_scroll_functions
,
28886 doc
: /* List of functions to call before redisplaying a window with scrolling.
28887 Each function is called with two arguments, the window and its new
28888 display-start position. Note that these functions are also called by
28889 `set-window-buffer'. Also note that the value of `window-end' is not
28890 valid when these functions are called.
28892 Warning: Do not use this feature to alter the way the window
28893 is scrolled. It is not designed for that, and such use probably won't
28895 Vwindow_scroll_functions
= Qnil
;
28897 DEFVAR_LISP ("window-text-change-functions",
28898 Vwindow_text_change_functions
,
28899 doc
: /* Functions to call in redisplay when text in the window might change. */);
28900 Vwindow_text_change_functions
= Qnil
;
28902 DEFVAR_LISP ("redisplay-end-trigger-functions", Vredisplay_end_trigger_functions
,
28903 doc
: /* Functions called when redisplay of a window reaches the end trigger.
28904 Each function is called with two arguments, the window and the end trigger value.
28905 See `set-window-redisplay-end-trigger'. */);
28906 Vredisplay_end_trigger_functions
= Qnil
;
28908 DEFVAR_LISP ("mouse-autoselect-window", Vmouse_autoselect_window
,
28909 doc
: /* Non-nil means autoselect window with mouse pointer.
28910 If nil, do not autoselect windows.
28911 A positive number means delay autoselection by that many seconds: a
28912 window is autoselected only after the mouse has remained in that
28913 window for the duration of the delay.
28914 A negative number has a similar effect, but causes windows to be
28915 autoselected only after the mouse has stopped moving. \(Because of
28916 the way Emacs compares mouse events, you will occasionally wait twice
28917 that time before the window gets selected.\)
28918 Any other value means to autoselect window instantaneously when the
28919 mouse pointer enters it.
28921 Autoselection selects the minibuffer only if it is active, and never
28922 unselects the minibuffer if it is active.
28924 When customizing this variable make sure that the actual value of
28925 `focus-follows-mouse' matches the behavior of your window manager. */);
28926 Vmouse_autoselect_window
= Qnil
;
28928 DEFVAR_LISP ("auto-resize-tool-bars", Vauto_resize_tool_bars
,
28929 doc
: /* Non-nil means automatically resize tool-bars.
28930 This dynamically changes the tool-bar's height to the minimum height
28931 that is needed to make all tool-bar items visible.
28932 If value is `grow-only', the tool-bar's height is only increased
28933 automatically; to decrease the tool-bar height, use \\[recenter]. */);
28934 Vauto_resize_tool_bars
= Qt
;
28936 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", auto_raise_tool_bar_buttons_p
,
28937 doc
: /* Non-nil means raise tool-bar buttons when the mouse moves over them. */);
28938 auto_raise_tool_bar_buttons_p
= 1;
28940 DEFVAR_BOOL ("make-cursor-line-fully-visible", make_cursor_line_fully_visible_p
,
28941 doc
: /* Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
28942 make_cursor_line_fully_visible_p
= 1;
28944 DEFVAR_LISP ("tool-bar-border", Vtool_bar_border
,
28945 doc
: /* Border below tool-bar in pixels.
28946 If an integer, use it as the height of the border.
28947 If it is one of `internal-border-width' or `border-width', use the
28948 value of the corresponding frame parameter.
28949 Otherwise, no border is added below the tool-bar. */);
28950 Vtool_bar_border
= Qinternal_border_width
;
28952 DEFVAR_LISP ("tool-bar-button-margin", Vtool_bar_button_margin
,
28953 doc
: /* Margin around tool-bar buttons in pixels.
28954 If an integer, use that for both horizontal and vertical margins.
28955 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
28956 HORZ specifying the horizontal margin, and VERT specifying the
28957 vertical margin. */);
28958 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
28960 DEFVAR_INT ("tool-bar-button-relief", tool_bar_button_relief
,
28961 doc
: /* Relief thickness of tool-bar buttons. */);
28962 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
28964 DEFVAR_LISP ("tool-bar-style", Vtool_bar_style
,
28965 doc
: /* Tool bar style to use.
28967 image - show images only
28968 text - show text only
28969 both - show both, text below image
28970 both-horiz - show text to the right of the image
28971 text-image-horiz - show text to the left of the image
28972 any other - use system default or image if no system default.
28974 This variable only affects the GTK+ toolkit version of Emacs. */);
28975 Vtool_bar_style
= Qnil
;
28977 DEFVAR_INT ("tool-bar-max-label-size", tool_bar_max_label_size
,
28978 doc
: /* Maximum number of characters a label can have to be shown.
28979 The tool bar style must also show labels for this to have any effect, see
28980 `tool-bar-style'. */);
28981 tool_bar_max_label_size
= DEFAULT_TOOL_BAR_LABEL_SIZE
;
28983 DEFVAR_LISP ("fontification-functions", Vfontification_functions
,
28984 doc
: /* List of functions to call to fontify regions of text.
28985 Each function is called with one argument POS. Functions must
28986 fontify a region starting at POS in the current buffer, and give
28987 fontified regions the property `fontified'. */);
28988 Vfontification_functions
= Qnil
;
28989 Fmake_variable_buffer_local (Qfontification_functions
);
28991 DEFVAR_BOOL ("unibyte-display-via-language-environment",
28992 unibyte_display_via_language_environment
,
28993 doc
: /* Non-nil means display unibyte text according to language environment.
28994 Specifically, this means that raw bytes in the range 160-255 decimal
28995 are displayed by converting them to the equivalent multibyte characters
28996 according to the current language environment. As a result, they are
28997 displayed according to the current fontset.
28999 Note that this variable affects only how these bytes are displayed,
29000 but does not change the fact they are interpreted as raw bytes. */);
29001 unibyte_display_via_language_environment
= 0;
29003 DEFVAR_LISP ("max-mini-window-height", Vmax_mini_window_height
,
29004 doc
: /* Maximum height for resizing mini-windows (the minibuffer and the echo area).
29005 If a float, it specifies a fraction of the mini-window frame's height.
29006 If an integer, it specifies a number of lines. */);
29007 Vmax_mini_window_height
= make_float (0.25);
29009 DEFVAR_LISP ("resize-mini-windows", Vresize_mini_windows
,
29010 doc
: /* How to resize mini-windows (the minibuffer and the echo area).
29011 A value of nil means don't automatically resize mini-windows.
29012 A value of t means resize them to fit the text displayed in them.
29013 A value of `grow-only', the default, means let mini-windows grow only;
29014 they return to their normal size when the minibuffer is closed, or the
29015 echo area becomes empty. */);
29016 Vresize_mini_windows
= Qgrow_only
;
29018 DEFVAR_LISP ("blink-cursor-alist", Vblink_cursor_alist
,
29019 doc
: /* Alist specifying how to blink the cursor off.
29020 Each element has the form (ON-STATE . OFF-STATE). Whenever the
29021 `cursor-type' frame-parameter or variable equals ON-STATE,
29022 comparing using `equal', Emacs uses OFF-STATE to specify
29023 how to blink it off. ON-STATE and OFF-STATE are values for
29024 the `cursor-type' frame parameter.
29026 If a frame's ON-STATE has no entry in this list,
29027 the frame's other specifications determine how to blink the cursor off. */);
29028 Vblink_cursor_alist
= Qnil
;
29030 DEFVAR_BOOL ("auto-hscroll-mode", automatic_hscrolling_p
,
29031 doc
: /* Allow or disallow automatic horizontal scrolling of windows.
29032 If non-nil, windows are automatically scrolled horizontally to make
29033 point visible. */);
29034 automatic_hscrolling_p
= 1;
29035 DEFSYM (Qauto_hscroll_mode
, "auto-hscroll-mode");
29037 DEFVAR_INT ("hscroll-margin", hscroll_margin
,
29038 doc
: /* How many columns away from the window edge point is allowed to get
29039 before automatic hscrolling will horizontally scroll the window. */);
29040 hscroll_margin
= 5;
29042 DEFVAR_LISP ("hscroll-step", Vhscroll_step
,
29043 doc
: /* How many columns to scroll the window when point gets too close to the edge.
29044 When point is less than `hscroll-margin' columns from the window
29045 edge, automatic hscrolling will scroll the window by the amount of columns
29046 determined by this variable. If its value is a positive integer, scroll that
29047 many columns. If it's a positive floating-point number, it specifies the
29048 fraction of the window's width to scroll. If it's nil or zero, point will be
29049 centered horizontally after the scroll. Any other value, including negative
29050 numbers, are treated as if the value were zero.
29052 Automatic hscrolling always moves point outside the scroll margin, so if
29053 point was more than scroll step columns inside the margin, the window will
29054 scroll more than the value given by the scroll step.
29056 Note that the lower bound for automatic hscrolling specified by `scroll-left'
29057 and `scroll-right' overrides this variable's effect. */);
29058 Vhscroll_step
= make_number (0);
29060 DEFVAR_BOOL ("message-truncate-lines", message_truncate_lines
,
29061 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
29062 Bind this around calls to `message' to let it take effect. */);
29063 message_truncate_lines
= 0;
29065 DEFVAR_LISP ("menu-bar-update-hook", Vmenu_bar_update_hook
,
29066 doc
: /* Normal hook run to update the menu bar definitions.
29067 Redisplay runs this hook before it redisplays the menu bar.
29068 This is used to update submenus such as Buffers,
29069 whose contents depend on various data. */);
29070 Vmenu_bar_update_hook
= Qnil
;
29072 DEFVAR_LISP ("menu-updating-frame", Vmenu_updating_frame
,
29073 doc
: /* Frame for which we are updating a menu.
29074 The enable predicate for a menu binding should check this variable. */);
29075 Vmenu_updating_frame
= Qnil
;
29077 DEFVAR_BOOL ("inhibit-menubar-update", inhibit_menubar_update
,
29078 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
29079 inhibit_menubar_update
= 0;
29081 DEFVAR_LISP ("wrap-prefix", Vwrap_prefix
,
29082 doc
: /* Prefix prepended to all continuation lines at display time.
29083 The value may be a string, an image, or a stretch-glyph; it is
29084 interpreted in the same way as the value of a `display' text property.
29086 This variable is overridden by any `wrap-prefix' text or overlay
29089 To add a prefix to non-continuation lines, use `line-prefix'. */);
29090 Vwrap_prefix
= Qnil
;
29091 DEFSYM (Qwrap_prefix
, "wrap-prefix");
29092 Fmake_variable_buffer_local (Qwrap_prefix
);
29094 DEFVAR_LISP ("line-prefix", Vline_prefix
,
29095 doc
: /* Prefix prepended to all non-continuation lines at display time.
29096 The value may be a string, an image, or a stretch-glyph; it is
29097 interpreted in the same way as the value of a `display' text property.
29099 This variable is overridden by any `line-prefix' text or overlay
29102 To add a prefix to continuation lines, use `wrap-prefix'. */);
29103 Vline_prefix
= Qnil
;
29104 DEFSYM (Qline_prefix
, "line-prefix");
29105 Fmake_variable_buffer_local (Qline_prefix
);
29107 DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay
,
29108 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
29109 inhibit_eval_during_redisplay
= 0;
29111 DEFVAR_BOOL ("inhibit-free-realized-faces", inhibit_free_realized_faces
,
29112 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
29113 inhibit_free_realized_faces
= 0;
29116 DEFVAR_BOOL ("inhibit-try-window-id", inhibit_try_window_id
,
29117 doc
: /* Inhibit try_window_id display optimization. */);
29118 inhibit_try_window_id
= 0;
29120 DEFVAR_BOOL ("inhibit-try-window-reusing", inhibit_try_window_reusing
,
29121 doc
: /* Inhibit try_window_reusing display optimization. */);
29122 inhibit_try_window_reusing
= 0;
29124 DEFVAR_BOOL ("inhibit-try-cursor-movement", inhibit_try_cursor_movement
,
29125 doc
: /* Inhibit try_cursor_movement display optimization. */);
29126 inhibit_try_cursor_movement
= 0;
29127 #endif /* GLYPH_DEBUG */
29129 DEFVAR_INT ("overline-margin", overline_margin
,
29130 doc
: /* Space between overline and text, in pixels.
29131 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
29132 margin to the character height. */);
29133 overline_margin
= 2;
29135 DEFVAR_INT ("underline-minimum-offset",
29136 underline_minimum_offset
,
29137 doc
: /* Minimum distance between baseline and underline.
29138 This can improve legibility of underlined text at small font sizes,
29139 particularly when using variable `x-use-underline-position-properties'
29140 with fonts that specify an UNDERLINE_POSITION relatively close to the
29141 baseline. The default value is 1. */);
29142 underline_minimum_offset
= 1;
29144 DEFVAR_BOOL ("display-hourglass", display_hourglass_p
,
29145 doc
: /* Non-nil means show an hourglass pointer, when Emacs is busy.
29146 This feature only works when on a window system that can change
29147 cursor shapes. */);
29148 display_hourglass_p
= 1;
29150 DEFVAR_LISP ("hourglass-delay", Vhourglass_delay
,
29151 doc
: /* Seconds to wait before displaying an hourglass pointer when Emacs is busy. */);
29152 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
29154 hourglass_atimer
= NULL
;
29155 hourglass_shown_p
= 0;
29157 DEFSYM (Qglyphless_char
, "glyphless-char");
29158 DEFSYM (Qhex_code
, "hex-code");
29159 DEFSYM (Qempty_box
, "empty-box");
29160 DEFSYM (Qthin_space
, "thin-space");
29161 DEFSYM (Qzero_width
, "zero-width");
29163 DEFSYM (Qglyphless_char_display
, "glyphless-char-display");
29164 /* Intern this now in case it isn't already done.
29165 Setting this variable twice is harmless.
29166 But don't staticpro it here--that is done in alloc.c. */
29167 Qchar_table_extra_slots
= intern_c_string ("char-table-extra-slots");
29168 Fput (Qglyphless_char_display
, Qchar_table_extra_slots
, make_number (1));
29170 DEFVAR_LISP ("glyphless-char-display", Vglyphless_char_display
,
29171 doc
: /* Char-table defining glyphless characters.
29172 Each element, if non-nil, should be one of the following:
29173 an ASCII acronym string: display this string in a box
29174 `hex-code': display the hexadecimal code of a character in a box
29175 `empty-box': display as an empty box
29176 `thin-space': display as 1-pixel width space
29177 `zero-width': don't display
29178 An element may also be a cons cell (GRAPHICAL . TEXT), which specifies the
29179 display method for graphical terminals and text terminals respectively.
29180 GRAPHICAL and TEXT should each have one of the values listed above.
29182 The char-table has one extra slot to control the display of a character for
29183 which no font is found. This slot only takes effect on graphical terminals.
29184 Its value should be an ASCII acronym string, `hex-code', `empty-box', or
29185 `thin-space'. The default is `empty-box'. */);
29186 Vglyphless_char_display
= Fmake_char_table (Qglyphless_char_display
, Qnil
);
29187 Fset_char_table_extra_slot (Vglyphless_char_display
, make_number (0),
29190 DEFVAR_LISP ("debug-on-message", Vdebug_on_message
,
29191 doc
: /* If non-nil, debug if a message matching this regexp is displayed. */);
29192 Vdebug_on_message
= Qnil
;
29196 /* Initialize this module when Emacs starts. */
29201 current_header_line_height
= current_mode_line_height
= -1;
29203 CHARPOS (this_line_start_pos
) = 0;
29205 if (!noninteractive
)
29207 struct window
*m
= XWINDOW (minibuf_window
);
29208 Lisp_Object frame
= m
->frame
;
29209 struct frame
*f
= XFRAME (frame
);
29210 Lisp_Object root
= FRAME_ROOT_WINDOW (f
);
29211 struct window
*r
= XWINDOW (root
);
29214 echo_area_window
= minibuf_window
;
29216 wset_top_line (r
, make_number (FRAME_TOP_MARGIN (f
)));
29218 (r
, make_number (FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
)));
29219 wset_total_cols (r
, make_number (FRAME_COLS (f
)));
29220 wset_top_line (m
, make_number (FRAME_LINES (f
) - 1));
29221 wset_total_lines (m
, make_number (1));
29222 wset_total_cols (m
, make_number (FRAME_COLS (f
)));
29224 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
29225 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
29226 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
29228 /* The default ellipsis glyphs `...'. */
29229 for (i
= 0; i
< 3; ++i
)
29230 default_invis_vector
[i
] = make_number ('.');
29234 /* Allocate the buffer for frame titles.
29235 Also used for `format-mode-line'. */
29237 mode_line_noprop_buf
= xmalloc (size
);
29238 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
29239 mode_line_noprop_ptr
= mode_line_noprop_buf
;
29240 mode_line_target
= MODE_LINE_DISPLAY
;
29243 help_echo_showing_p
= 0;
29246 /* Platform-independent portion of hourglass implementation. */
29248 /* Cancel a currently active hourglass timer, and start a new one. */
29250 start_hourglass (void)
29252 #if defined (HAVE_WINDOW_SYSTEM)
29255 cancel_hourglass ();
29257 if (INTEGERP (Vhourglass_delay
)
29258 && XINT (Vhourglass_delay
) > 0)
29259 delay
= make_emacs_time (min (XINT (Vhourglass_delay
),
29260 TYPE_MAXIMUM (time_t)),
29262 else if (FLOATP (Vhourglass_delay
)
29263 && XFLOAT_DATA (Vhourglass_delay
) > 0)
29264 delay
= EMACS_TIME_FROM_DOUBLE (XFLOAT_DATA (Vhourglass_delay
));
29266 delay
= make_emacs_time (DEFAULT_HOURGLASS_DELAY
, 0);
29270 extern void w32_note_current_window (void);
29271 w32_note_current_window ();
29273 #endif /* HAVE_NTGUI */
29275 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
29276 show_hourglass
, NULL
);
29281 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
29284 cancel_hourglass (void)
29286 #if defined (HAVE_WINDOW_SYSTEM)
29287 if (hourglass_atimer
)
29289 cancel_atimer (hourglass_atimer
);
29290 hourglass_atimer
= NULL
;
29293 if (hourglass_shown_p
)