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
320 #ifndef FRAME_X_OUTPUT
321 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
324 #define INFINITY 10000000
326 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
327 Lisp_Object Qwindow_scroll_functions
;
328 static Lisp_Object Qwindow_text_change_functions
;
329 static Lisp_Object Qredisplay_end_trigger_functions
;
330 Lisp_Object Qinhibit_point_motion_hooks
;
331 static Lisp_Object QCeval
, QCpropertize
;
332 Lisp_Object QCfile
, QCdata
;
333 static Lisp_Object Qfontified
;
334 static Lisp_Object Qgrow_only
;
335 static Lisp_Object Qinhibit_eval_during_redisplay
;
336 static Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
337 static Lisp_Object Qright_to_left
, Qleft_to_right
;
340 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
342 /* Pointer shapes. */
343 static Lisp_Object Qarrow
, Qhand
;
346 /* Holds the list (error). */
347 static Lisp_Object list_of_error
;
349 static Lisp_Object Qfontification_functions
;
351 static Lisp_Object Qwrap_prefix
;
352 static Lisp_Object Qline_prefix
;
353 static Lisp_Object Qredisplay_internal
;
355 /* Non-nil means don't actually do any redisplay. */
357 Lisp_Object Qinhibit_redisplay
;
359 /* Names of text properties relevant for redisplay. */
361 Lisp_Object Qdisplay
;
363 Lisp_Object Qspace
, QCalign_to
;
364 static Lisp_Object QCrelative_width
, QCrelative_height
;
365 Lisp_Object Qleft_margin
, Qright_margin
;
366 static Lisp_Object Qspace_width
, Qraise
;
367 static Lisp_Object Qslice
;
369 static Lisp_Object Qmargin
, Qpointer
;
370 static Lisp_Object Qline_height
;
372 #ifdef HAVE_WINDOW_SYSTEM
374 /* Test if overflow newline into fringe. Called with iterator IT
375 at or past right window margin, and with IT->current_x set. */
377 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(IT) \
378 (!NILP (Voverflow_newline_into_fringe) \
379 && FRAME_WINDOW_P ((IT)->f) \
380 && ((IT)->bidi_it.paragraph_dir == R2L \
381 ? (WINDOW_LEFT_FRINGE_WIDTH ((IT)->w) > 0) \
382 : (WINDOW_RIGHT_FRINGE_WIDTH ((IT)->w) > 0)) \
383 && (IT)->current_x == (IT)->last_visible_x)
385 #else /* !HAVE_WINDOW_SYSTEM */
386 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) 0
387 #endif /* HAVE_WINDOW_SYSTEM */
389 /* Test if the display element loaded in IT, or the underlying buffer
390 or string character, is a space or a TAB character. This is used
391 to determine where word wrapping can occur. */
393 #define IT_DISPLAYING_WHITESPACE(it) \
394 ((it->what == IT_CHARACTER && (it->c == ' ' || it->c == '\t')) \
395 || ((STRINGP (it->string) \
396 && (SREF (it->string, IT_STRING_BYTEPOS (*it)) == ' ' \
397 || SREF (it->string, IT_STRING_BYTEPOS (*it)) == '\t')) \
399 && (it->s[IT_BYTEPOS (*it)] == ' ' \
400 || it->s[IT_BYTEPOS (*it)] == '\t')) \
401 || (IT_BYTEPOS (*it) < ZV_BYTE \
402 && (*BYTE_POS_ADDR (IT_BYTEPOS (*it)) == ' ' \
403 || *BYTE_POS_ADDR (IT_BYTEPOS (*it)) == '\t')))) \
405 /* Name of the face used to highlight trailing whitespace. */
407 static Lisp_Object Qtrailing_whitespace
;
409 /* Name and number of the face used to highlight escape glyphs. */
411 static Lisp_Object Qescape_glyph
;
413 /* Name and number of the face used to highlight non-breaking spaces. */
415 static Lisp_Object Qnobreak_space
;
417 /* The symbol `image' which is the car of the lists used to represent
418 images in Lisp. Also a tool bar style. */
422 /* The image map types. */
424 static Lisp_Object QCpointer
;
425 static Lisp_Object Qrect
, Qcircle
, Qpoly
;
427 /* Tool bar styles */
428 Lisp_Object Qboth
, Qboth_horiz
, Qtext_image_horiz
;
430 /* Non-zero means print newline to stdout before next mini-buffer
433 int noninteractive_need_newline
;
435 /* Non-zero means print newline to message log before next message. */
437 static int message_log_need_newline
;
439 /* Three markers that message_dolog uses.
440 It could allocate them itself, but that causes trouble
441 in handling memory-full errors. */
442 static Lisp_Object message_dolog_marker1
;
443 static Lisp_Object message_dolog_marker2
;
444 static Lisp_Object message_dolog_marker3
;
446 /* The buffer position of the first character appearing entirely or
447 partially on the line of the selected window which contains the
448 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
449 redisplay optimization in redisplay_internal. */
451 static struct text_pos this_line_start_pos
;
453 /* Number of characters past the end of the line above, including the
454 terminating newline. */
456 static struct text_pos this_line_end_pos
;
458 /* The vertical positions and the height of this line. */
460 static int this_line_vpos
;
461 static int this_line_y
;
462 static int this_line_pixel_height
;
464 /* X position at which this display line starts. Usually zero;
465 negative if first character is partially visible. */
467 static int this_line_start_x
;
469 /* The smallest character position seen by move_it_* functions as they
470 move across display lines. Used to set MATRIX_ROW_START_CHARPOS of
471 hscrolled lines, see display_line. */
473 static struct text_pos this_line_min_pos
;
475 /* Buffer that this_line_.* variables are referring to. */
477 static struct buffer
*this_line_buffer
;
480 /* Values of those variables at last redisplay are stored as
481 properties on `overlay-arrow-position' symbol. However, if
482 Voverlay_arrow_position is a marker, last-arrow-position is its
483 numerical position. */
485 static Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
487 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
488 properties on a symbol in overlay-arrow-variable-list. */
490 static Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
492 Lisp_Object Qmenu_bar_update_hook
;
494 /* Nonzero if an overlay arrow has been displayed in this window. */
496 static int overlay_arrow_seen
;
498 /* Vector containing glyphs for an ellipsis `...'. */
500 static Lisp_Object default_invis_vector
[3];
502 /* This is the window where the echo area message was displayed. It
503 is always a mini-buffer window, but it may not be the same window
504 currently active as a mini-buffer. */
506 Lisp_Object echo_area_window
;
508 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
509 pushes the current message and the value of
510 message_enable_multibyte on the stack, the function restore_message
511 pops the stack and displays MESSAGE again. */
513 static Lisp_Object Vmessage_stack
;
515 /* Nonzero means multibyte characters were enabled when the echo area
516 message was specified. */
518 static int message_enable_multibyte
;
520 /* Nonzero if we should redraw the mode lines on the next redisplay. */
522 int update_mode_lines
;
524 /* Nonzero if window sizes or contents have changed since last
525 redisplay that finished. */
527 int windows_or_buffers_changed
;
529 /* Nonzero means a frame's cursor type has been changed. */
531 static int cursor_type_changed
;
533 /* Nonzero after display_mode_line if %l was used and it displayed a
536 static int line_number_displayed
;
538 /* The name of the *Messages* buffer, a string. */
540 static Lisp_Object Vmessages_buffer_name
;
542 /* Current, index 0, and last displayed echo area message. Either
543 buffers from echo_buffers, or nil to indicate no message. */
545 Lisp_Object echo_area_buffer
[2];
547 /* The buffers referenced from echo_area_buffer. */
549 static Lisp_Object echo_buffer
[2];
551 /* A vector saved used in with_area_buffer to reduce consing. */
553 static Lisp_Object Vwith_echo_area_save_vector
;
555 /* Non-zero means display_echo_area should display the last echo area
556 message again. Set by redisplay_preserve_echo_area. */
558 static int display_last_displayed_message_p
;
560 /* Nonzero if echo area is being used by print; zero if being used by
563 static int message_buf_print
;
565 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
567 static Lisp_Object Qinhibit_menubar_update
;
568 static Lisp_Object Qmessage_truncate_lines
;
570 /* Set to 1 in clear_message to make redisplay_internal aware
571 of an emptied echo area. */
573 static int message_cleared_p
;
575 /* A scratch glyph row with contents used for generating truncation
576 glyphs. Also used in direct_output_for_insert. */
578 #define MAX_SCRATCH_GLYPHS 100
579 static struct glyph_row scratch_glyph_row
;
580 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
582 /* Ascent and height of the last line processed by move_it_to. */
584 static int last_height
;
586 /* Non-zero if there's a help-echo in the echo area. */
588 int help_echo_showing_p
;
590 /* If >= 0, computed, exact values of mode-line and header-line height
591 to use in the macros CURRENT_MODE_LINE_HEIGHT and
592 CURRENT_HEADER_LINE_HEIGHT. */
594 int current_mode_line_height
, current_header_line_height
;
596 /* The maximum distance to look ahead for text properties. Values
597 that are too small let us call compute_char_face and similar
598 functions too often which is expensive. Values that are too large
599 let us call compute_char_face and alike too often because we
600 might not be interested in text properties that far away. */
602 #define TEXT_PROP_DISTANCE_LIMIT 100
604 /* SAVE_IT and RESTORE_IT are called when we save a snapshot of the
605 iterator state and later restore it. This is needed because the
606 bidi iterator on bidi.c keeps a stacked cache of its states, which
607 is really a singleton. When we use scratch iterator objects to
608 move around the buffer, we can cause the bidi cache to be pushed or
609 popped, and therefore we need to restore the cache state when we
610 return to the original iterator. */
611 #define SAVE_IT(ITCOPY,ITORIG,CACHE) \
614 bidi_unshelve_cache (CACHE, 1); \
616 CACHE = bidi_shelve_cache (); \
619 #define RESTORE_IT(pITORIG,pITCOPY,CACHE) \
621 if (pITORIG != pITCOPY) \
622 *(pITORIG) = *(pITCOPY); \
623 bidi_unshelve_cache (CACHE, 0); \
629 /* Non-zero means print traces of redisplay if compiled with
630 GLYPH_DEBUG defined. */
632 int trace_redisplay_p
;
634 #endif /* GLYPH_DEBUG */
636 #ifdef DEBUG_TRACE_MOVE
637 /* Non-zero means trace with TRACE_MOVE to stderr. */
640 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
642 #define TRACE_MOVE(x) (void) 0
645 static Lisp_Object Qauto_hscroll_mode
;
647 /* Buffer being redisplayed -- for redisplay_window_error. */
649 static struct buffer
*displayed_buffer
;
651 /* Value returned from text property handlers (see below). */
656 HANDLED_RECOMPUTE_PROPS
,
657 HANDLED_OVERLAY_STRING_CONSUMED
,
661 /* A description of text properties that redisplay is interested
666 /* The name of the property. */
669 /* A unique index for the property. */
672 /* A handler function called to set up iterator IT from the property
673 at IT's current position. Value is used to steer handle_stop. */
674 enum prop_handled (*handler
) (struct it
*it
);
677 static enum prop_handled
handle_face_prop (struct it
*);
678 static enum prop_handled
handle_invisible_prop (struct it
*);
679 static enum prop_handled
handle_display_prop (struct it
*);
680 static enum prop_handled
handle_composition_prop (struct it
*);
681 static enum prop_handled
handle_overlay_change (struct it
*);
682 static enum prop_handled
handle_fontified_prop (struct it
*);
684 /* Properties handled by iterators. */
686 static struct props it_props
[] =
688 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
689 /* Handle `face' before `display' because some sub-properties of
690 `display' need to know the face. */
691 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
692 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
693 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
694 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
698 /* Value is the position described by X. If X is a marker, value is
699 the marker_position of X. Otherwise, value is X. */
701 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
703 /* Enumeration returned by some move_it_.* functions internally. */
707 /* Not used. Undefined value. */
710 /* Move ended at the requested buffer position or ZV. */
711 MOVE_POS_MATCH_OR_ZV
,
713 /* Move ended at the requested X pixel position. */
716 /* Move within a line ended at the end of a line that must be
720 /* Move within a line ended at the end of a line that would
721 be displayed truncated. */
724 /* Move within a line ended at a line end. */
728 /* This counter is used to clear the face cache every once in a while
729 in redisplay_internal. It is incremented for each redisplay.
730 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
733 #define CLEAR_FACE_CACHE_COUNT 500
734 static int clear_face_cache_count
;
736 /* Similarly for the image cache. */
738 #ifdef HAVE_WINDOW_SYSTEM
739 #define CLEAR_IMAGE_CACHE_COUNT 101
740 static int clear_image_cache_count
;
742 /* Null glyph slice */
743 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
746 /* True while redisplay_internal is in progress. */
750 static Lisp_Object Qinhibit_free_realized_faces
;
751 static Lisp_Object Qmode_line_default_help_echo
;
753 /* If a string, XTread_socket generates an event to display that string.
754 (The display is done in read_char.) */
756 Lisp_Object help_echo_string
;
757 Lisp_Object help_echo_window
;
758 Lisp_Object help_echo_object
;
759 ptrdiff_t help_echo_pos
;
761 /* Temporary variable for XTread_socket. */
763 Lisp_Object previous_help_echo_string
;
765 /* Platform-independent portion of hourglass implementation. */
767 /* Non-zero means an hourglass cursor is currently shown. */
768 int hourglass_shown_p
;
770 /* If non-null, an asynchronous timer that, when it expires, displays
771 an hourglass cursor on all frames. */
772 struct atimer
*hourglass_atimer
;
774 /* Name of the face used to display glyphless characters. */
775 Lisp_Object Qglyphless_char
;
777 /* Symbol for the purpose of Vglyphless_char_display. */
778 static Lisp_Object Qglyphless_char_display
;
780 /* Method symbols for Vglyphless_char_display. */
781 static Lisp_Object Qhex_code
, Qempty_box
, Qthin_space
, Qzero_width
;
783 /* Default pixel width of `thin-space' display method. */
784 #define THIN_SPACE_WIDTH 1
786 /* Default number of seconds to wait before displaying an hourglass
788 #define DEFAULT_HOURGLASS_DELAY 1
791 /* Function prototypes. */
793 static void setup_for_ellipsis (struct it
*, int);
794 static void set_iterator_to_next (struct it
*, int);
795 static void mark_window_display_accurate_1 (struct window
*, int);
796 static int single_display_spec_string_p (Lisp_Object
, Lisp_Object
);
797 static int display_prop_string_p (Lisp_Object
, Lisp_Object
);
798 static int row_for_charpos_p (struct glyph_row
*, ptrdiff_t);
799 static int cursor_row_p (struct glyph_row
*);
800 static int redisplay_mode_lines (Lisp_Object
, int);
801 static char *decode_mode_spec_coding (Lisp_Object
, char *, int);
803 static Lisp_Object
get_it_property (struct it
*it
, Lisp_Object prop
);
805 static void handle_line_prefix (struct it
*);
807 static void pint2str (char *, int, ptrdiff_t);
808 static void pint2hrstr (char *, int, ptrdiff_t);
809 static struct text_pos
run_window_scroll_functions (Lisp_Object
,
811 static int text_outside_line_unchanged_p (struct window
*,
812 ptrdiff_t, ptrdiff_t);
813 static void store_mode_line_noprop_char (char);
814 static int store_mode_line_noprop (const char *, int, int);
815 static void handle_stop (struct it
*);
816 static void handle_stop_backwards (struct it
*, ptrdiff_t);
817 static void vmessage (const char *, va_list) ATTRIBUTE_FORMAT_PRINTF (1, 0);
818 static void ensure_echo_area_buffers (void);
819 static void unwind_with_echo_area_buffer (Lisp_Object
);
820 static Lisp_Object
with_echo_area_buffer_unwind_data (struct window
*);
821 static int with_echo_area_buffer (struct window
*, int,
822 int (*) (ptrdiff_t, Lisp_Object
),
823 ptrdiff_t, Lisp_Object
);
824 static void clear_garbaged_frames (void);
825 static int current_message_1 (ptrdiff_t, Lisp_Object
);
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 void unwind_redisplay (void);
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 static void reseat_at_next_visible_line_start (struct it
*, int);
884 static int next_element_from_ellipsis (struct it
*);
885 static int next_element_from_display_vector (struct it
*);
886 static int next_element_from_string (struct it
*);
887 static int next_element_from_c_string (struct it
*);
888 static int next_element_from_buffer (struct it
*);
889 static int next_element_from_composition (struct it
*);
890 static int next_element_from_image (struct it
*);
892 static int next_element_from_xwidget(struct it
*);
894 static int next_element_from_stretch (struct it
*);
895 static void load_overlay_strings (struct it
*, ptrdiff_t);
896 static int init_from_display_pos (struct it
*, struct window
*,
897 struct display_pos
*);
898 static void reseat_to_string (struct it
*, const char *,
899 Lisp_Object
, ptrdiff_t, ptrdiff_t, int, int);
900 static int get_next_display_element (struct it
*);
901 static enum move_it_result
902 move_it_in_display_line_to (struct it
*, ptrdiff_t, int,
903 enum move_operation_enum
);
904 static void get_visually_first_element (struct it
*);
905 static void init_to_row_start (struct it
*, struct window
*,
907 static int init_to_row_end (struct it
*, struct window
*,
909 static void back_to_previous_line_start (struct it
*);
910 static int forward_to_next_line_start (struct it
*, int *, struct bidi_it
*);
911 static struct text_pos
string_pos_nchars_ahead (struct text_pos
,
912 Lisp_Object
, ptrdiff_t);
913 static struct text_pos
string_pos (ptrdiff_t, Lisp_Object
);
914 static struct text_pos
c_string_pos (ptrdiff_t, const char *, bool);
915 static ptrdiff_t number_of_chars (const char *, bool);
916 static void compute_stop_pos (struct it
*);
917 static void compute_string_pos (struct text_pos
*, struct text_pos
,
919 static int face_before_or_after_it_pos (struct it
*, int);
920 static ptrdiff_t next_overlay_change (ptrdiff_t);
921 static int handle_display_spec (struct it
*, Lisp_Object
, Lisp_Object
,
922 Lisp_Object
, struct text_pos
*, ptrdiff_t, int);
923 static int handle_single_display_spec (struct it
*, Lisp_Object
,
924 Lisp_Object
, Lisp_Object
,
925 struct text_pos
*, ptrdiff_t, int, int);
926 static int underlying_face_id (struct it
*);
927 static int in_ellipses_for_invisible_text_p (struct display_pos
*,
930 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
931 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
933 #ifdef HAVE_WINDOW_SYSTEM
935 static void x_consider_frame_title (Lisp_Object
);
936 static int tool_bar_lines_needed (struct frame
*, int *);
937 static void update_tool_bar (struct frame
*, int);
938 static void build_desired_tool_bar_string (struct frame
*f
);
939 static int redisplay_tool_bar (struct frame
*);
940 static void display_tool_bar_line (struct it
*, int);
941 static void notice_overwritten_cursor (struct window
*,
944 static void append_stretch_glyph (struct it
*, Lisp_Object
,
948 #endif /* HAVE_WINDOW_SYSTEM */
950 static void produce_special_glyphs (struct it
*, enum display_element_type
);
951 static void show_mouse_face (Mouse_HLInfo
*, enum draw_glyphs_face
);
952 static int coords_in_mouse_face_p (struct window
*, int, int);
956 /***********************************************************************
957 Window display dimensions
958 ***********************************************************************/
960 /* Return the bottom boundary y-position for text lines in window W.
961 This is the first y position at which a line cannot start.
962 It is relative to the top of the window.
964 This is the height of W minus the height of a mode line, if any. */
967 window_text_bottom_y (struct window
*w
)
969 int height
= WINDOW_TOTAL_HEIGHT (w
);
971 if (WINDOW_WANTS_MODELINE_P (w
))
972 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
976 /* Return the pixel width of display area AREA of window W. AREA < 0
977 means return the total width of W, not including fringes to
978 the left and right of the window. */
981 window_box_width (struct window
*w
, int area
)
983 int cols
= w
->total_cols
;
986 if (!w
->pseudo_window_p
)
988 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
990 if (area
== TEXT_AREA
)
992 cols
-= max (0, w
->left_margin_cols
);
993 cols
-= max (0, w
->right_margin_cols
);
994 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
996 else if (area
== LEFT_MARGIN_AREA
)
998 cols
= max (0, w
->left_margin_cols
);
1001 else if (area
== RIGHT_MARGIN_AREA
)
1003 cols
= max (0, w
->right_margin_cols
);
1008 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1012 /* Return the pixel height of the display area of window W, not
1013 including mode lines of W, if any. */
1016 window_box_height (struct window
*w
)
1018 struct frame
*f
= XFRAME (w
->frame
);
1019 int height
= WINDOW_TOTAL_HEIGHT (w
);
1021 eassert (height
>= 0);
1023 /* Note: the code below that determines the mode-line/header-line
1024 height is essentially the same as that contained in the macro
1025 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1026 the appropriate glyph row has its `mode_line_p' flag set,
1027 and if it doesn't, uses estimate_mode_line_height instead. */
1029 if (WINDOW_WANTS_MODELINE_P (w
))
1031 struct glyph_row
*ml_row
1032 = (w
->current_matrix
&& w
->current_matrix
->rows
1033 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1035 if (ml_row
&& ml_row
->mode_line_p
)
1036 height
-= ml_row
->height
;
1038 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1041 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1043 struct glyph_row
*hl_row
1044 = (w
->current_matrix
&& w
->current_matrix
->rows
1045 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1047 if (hl_row
&& hl_row
->mode_line_p
)
1048 height
-= hl_row
->height
;
1050 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1053 /* With a very small font and a mode-line that's taller than
1054 default, we might end up with a negative height. */
1055 return max (0, height
);
1058 /* Return the window-relative coordinate of the left edge of display
1059 area AREA of window W. AREA < 0 means return the left edge of the
1060 whole window, to the right of the left fringe of W. */
1063 window_box_left_offset (struct window
*w
, int area
)
1067 if (w
->pseudo_window_p
)
1070 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1072 if (area
== TEXT_AREA
)
1073 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1074 + window_box_width (w
, LEFT_MARGIN_AREA
));
1075 else if (area
== RIGHT_MARGIN_AREA
)
1076 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1077 + window_box_width (w
, LEFT_MARGIN_AREA
)
1078 + window_box_width (w
, TEXT_AREA
)
1079 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1081 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1082 else if (area
== LEFT_MARGIN_AREA
1083 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1084 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1090 /* Return the window-relative coordinate of the right edge of display
1091 area AREA of window W. AREA < 0 means return the right edge of the
1092 whole window, to the left of the right fringe of W. */
1095 window_box_right_offset (struct window
*w
, int area
)
1097 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1100 /* Return the frame-relative coordinate of the left edge of display
1101 area AREA of window W. AREA < 0 means return the left edge of the
1102 whole window, to the right of the left fringe of W. */
1105 window_box_left (struct window
*w
, int area
)
1107 struct frame
*f
= XFRAME (w
->frame
);
1110 if (w
->pseudo_window_p
)
1111 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1113 x
= (WINDOW_LEFT_EDGE_X (w
)
1114 + window_box_left_offset (w
, area
));
1120 /* Return the frame-relative coordinate of the right edge of display
1121 area AREA of window W. AREA < 0 means return the right edge of the
1122 whole window, to the left of the right fringe of W. */
1125 window_box_right (struct window
*w
, int area
)
1127 return window_box_left (w
, area
) + window_box_width (w
, area
);
1130 /* Get the bounding box of the display area AREA of window W, without
1131 mode lines, in frame-relative coordinates. AREA < 0 means the
1132 whole window, not including the left and right fringes of
1133 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1134 coordinates of the upper-left corner of the box. Return in
1135 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1138 window_box (struct window
*w
, int area
, int *box_x
, int *box_y
,
1139 int *box_width
, int *box_height
)
1142 *box_width
= window_box_width (w
, area
);
1144 *box_height
= window_box_height (w
);
1146 *box_x
= window_box_left (w
, area
);
1149 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1150 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1151 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1156 /* Get the bounding box of the display area AREA of window W, without
1157 mode lines. AREA < 0 means the whole window, not including the
1158 left and right fringe of the window. Return in *TOP_LEFT_X
1159 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1160 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1161 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1165 window_box_edges (struct window
*w
, int area
, int *top_left_x
, int *top_left_y
,
1166 int *bottom_right_x
, int *bottom_right_y
)
1168 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1170 *bottom_right_x
+= *top_left_x
;
1171 *bottom_right_y
+= *top_left_y
;
1176 /***********************************************************************
1178 ***********************************************************************/
1180 /* Return the bottom y-position of the line the iterator IT is in.
1181 This can modify IT's settings. */
1184 line_bottom_y (struct it
*it
)
1186 int line_height
= it
->max_ascent
+ it
->max_descent
;
1187 int line_top_y
= it
->current_y
;
1189 if (line_height
== 0)
1192 line_height
= last_height
;
1193 else if (IT_CHARPOS (*it
) < ZV
)
1195 move_it_by_lines (it
, 1);
1196 line_height
= (it
->max_ascent
|| it
->max_descent
1197 ? it
->max_ascent
+ it
->max_descent
1202 struct glyph_row
*row
= it
->glyph_row
;
1204 /* Use the default character height. */
1205 it
->glyph_row
= NULL
;
1206 it
->what
= IT_CHARACTER
;
1209 PRODUCE_GLYPHS (it
);
1210 line_height
= it
->ascent
+ it
->descent
;
1211 it
->glyph_row
= row
;
1215 return line_top_y
+ line_height
;
1218 DEFUN ("line-pixel-height", Fline_pixel_height
,
1219 Sline_pixel_height
, 0, 0, 0,
1220 doc
: /* Return height in pixels of text line in the selected window.
1222 Value is the height in pixels of the line at point. */)
1227 struct window
*w
= XWINDOW (selected_window
);
1229 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
1230 start_display (&it
, w
, pt
);
1231 it
.vpos
= it
.current_y
= 0;
1233 return make_number (line_bottom_y (&it
));
1236 /* Return the default pixel height of text lines in window W. The
1237 value is the canonical height of the W frame's default font, plus
1238 any extra space required by the line-spacing variable or frame
1241 Implementation note: this ignores any line-spacing text properties
1242 put on the newline characters. This is because those properties
1243 only affect the _screen_ line ending in the newline (i.e., in a
1244 continued line, only the last screen line will be affected), which
1245 means only a small number of lines in a buffer can ever use this
1246 feature. Since this function is used to compute the default pixel
1247 equivalent of text lines in a window, we can safely ignore those
1248 few lines. For the same reasons, we ignore the line-height
1251 default_line_pixel_height (struct window
*w
)
1253 struct frame
*f
= WINDOW_XFRAME (w
);
1254 int height
= FRAME_LINE_HEIGHT (f
);
1256 if (!FRAME_INITIAL_P (f
) && BUFFERP (w
->contents
))
1258 struct buffer
*b
= XBUFFER (w
->contents
);
1259 Lisp_Object val
= BVAR (b
, extra_line_spacing
);
1262 val
= BVAR (&buffer_defaults
, extra_line_spacing
);
1265 if (RANGED_INTEGERP (0, val
, INT_MAX
))
1266 height
+= XFASTINT (val
);
1267 else if (FLOATP (val
))
1269 int addon
= XFLOAT_DATA (val
) * height
+ 0.5;
1276 height
+= f
->extra_line_spacing
;
1282 /* Subroutine of pos_visible_p below. Extracts a display string, if
1283 any, from the display spec given as its argument. */
1285 string_from_display_spec (Lisp_Object spec
)
1289 while (CONSP (spec
))
1291 if (STRINGP (XCAR (spec
)))
1296 else if (VECTORP (spec
))
1300 for (i
= 0; i
< ASIZE (spec
); i
++)
1302 if (STRINGP (AREF (spec
, i
)))
1303 return AREF (spec
, i
);
1312 /* Limit insanely large values of W->hscroll on frame F to the largest
1313 value that will still prevent first_visible_x and last_visible_x of
1314 'struct it' from overflowing an int. */
1316 window_hscroll_limited (struct window
*w
, struct frame
*f
)
1318 ptrdiff_t window_hscroll
= w
->hscroll
;
1319 int window_text_width
= window_box_width (w
, TEXT_AREA
);
1320 int colwidth
= FRAME_COLUMN_WIDTH (f
);
1322 if (window_hscroll
> (INT_MAX
- window_text_width
) / colwidth
- 1)
1323 window_hscroll
= (INT_MAX
- window_text_width
) / colwidth
- 1;
1325 return window_hscroll
;
1328 /* Return 1 if position CHARPOS is visible in window W.
1329 CHARPOS < 0 means return info about WINDOW_END position.
1330 If visible, set *X and *Y to pixel coordinates of top left corner.
1331 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1332 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1335 pos_visible_p (struct window
*w
, ptrdiff_t charpos
, int *x
, int *y
,
1336 int *rtop
, int *rbot
, int *rowh
, int *vpos
)
1339 void *itdata
= bidi_shelve_cache ();
1340 struct text_pos top
;
1342 struct buffer
*old_buffer
= NULL
;
1344 if (FRAME_INITIAL_P (XFRAME (WINDOW_FRAME (w
))))
1347 if (XBUFFER (w
->contents
) != current_buffer
)
1349 old_buffer
= current_buffer
;
1350 set_buffer_internal_1 (XBUFFER (w
->contents
));
1353 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1354 /* Scrolling a minibuffer window via scroll bar when the echo area
1355 shows long text sometimes resets the minibuffer contents behind
1357 if (CHARPOS (top
) > ZV
)
1358 SET_TEXT_POS (top
, BEGV
, BEGV_BYTE
);
1360 /* Compute exact mode line heights. */
1361 if (WINDOW_WANTS_MODELINE_P (w
))
1362 current_mode_line_height
1363 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1364 BVAR (current_buffer
, mode_line_format
));
1366 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1367 current_header_line_height
1368 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1369 BVAR (current_buffer
, header_line_format
));
1371 start_display (&it
, w
, top
);
1372 move_it_to (&it
, charpos
, -1, it
.last_visible_y
- 1, -1,
1373 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1376 && (((!it
.bidi_p
|| it
.bidi_it
.scan_dir
== 1)
1377 && IT_CHARPOS (it
) >= charpos
)
1378 /* When scanning backwards under bidi iteration, move_it_to
1379 stops at or _before_ CHARPOS, because it stops at or to
1380 the _right_ of the character at CHARPOS. */
1381 || (it
.bidi_p
&& it
.bidi_it
.scan_dir
== -1
1382 && IT_CHARPOS (it
) <= charpos
)))
1384 /* We have reached CHARPOS, or passed it. How the call to
1385 move_it_to can overshoot: (i) If CHARPOS is on invisible text
1386 or covered by a display property, move_it_to stops at the end
1387 of the invisible text, to the right of CHARPOS. (ii) If
1388 CHARPOS is in a display vector, move_it_to stops on its last
1390 int top_x
= it
.current_x
;
1391 int top_y
= it
.current_y
;
1392 /* Calling line_bottom_y may change it.method, it.position, etc. */
1393 enum it_method it_method
= it
.method
;
1394 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1395 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1397 if (top_y
< window_top_y
)
1398 visible_p
= bottom_y
> window_top_y
;
1399 else if (top_y
< it
.last_visible_y
)
1401 if (bottom_y
>= it
.last_visible_y
1402 && it
.bidi_p
&& it
.bidi_it
.scan_dir
== -1
1403 && IT_CHARPOS (it
) < charpos
)
1405 /* When the last line of the window is scanned backwards
1406 under bidi iteration, we could be duped into thinking
1407 that we have passed CHARPOS, when in fact move_it_to
1408 simply stopped short of CHARPOS because it reached
1409 last_visible_y. To see if that's what happened, we call
1410 move_it_to again with a slightly larger vertical limit,
1411 and see if it actually moved vertically; if it did, we
1412 didn't really reach CHARPOS, which is beyond window end. */
1413 struct it save_it
= it
;
1414 /* Why 10? because we don't know how many canonical lines
1415 will the height of the next line(s) be. So we guess. */
1416 int ten_more_lines
= 10 * default_line_pixel_height (w
);
1418 move_it_to (&it
, charpos
, -1, bottom_y
+ ten_more_lines
, -1,
1419 MOVE_TO_POS
| MOVE_TO_Y
);
1420 if (it
.current_y
> top_y
)
1427 if (it_method
== GET_FROM_DISPLAY_VECTOR
)
1429 /* We stopped on the last glyph of a display vector.
1430 Try and recompute. Hack alert! */
1431 if (charpos
< 2 || top
.charpos
>= charpos
)
1432 top_x
= it
.glyph_row
->x
;
1435 struct it it2
, it2_prev
;
1436 /* The idea is to get to the previous buffer
1437 position, consume the character there, and use
1438 the pixel coordinates we get after that. But if
1439 the previous buffer position is also displayed
1440 from a display vector, we need to consume all of
1441 the glyphs from that display vector. */
1442 start_display (&it2
, w
, top
);
1443 move_it_to (&it2
, charpos
- 1, -1, -1, -1, MOVE_TO_POS
);
1444 /* If we didn't get to CHARPOS - 1, there's some
1445 replacing display property at that position, and
1446 we stopped after it. That is exactly the place
1447 whose coordinates we want. */
1448 if (IT_CHARPOS (it2
) != charpos
- 1)
1452 /* Iterate until we get out of the display
1453 vector that displays the character at
1456 get_next_display_element (&it2
);
1457 PRODUCE_GLYPHS (&it2
);
1459 set_iterator_to_next (&it2
, 1);
1460 } while (it2
.method
== GET_FROM_DISPLAY_VECTOR
1461 && IT_CHARPOS (it2
) < charpos
);
1463 if (ITERATOR_AT_END_OF_LINE_P (&it2_prev
)
1464 || it2_prev
.current_x
> it2_prev
.last_visible_x
)
1465 top_x
= it
.glyph_row
->x
;
1468 top_x
= it2_prev
.current_x
;
1469 top_y
= it2_prev
.current_y
;
1473 else if (IT_CHARPOS (it
) != charpos
)
1475 Lisp_Object cpos
= make_number (charpos
);
1476 Lisp_Object spec
= Fget_char_property (cpos
, Qdisplay
, Qnil
);
1477 Lisp_Object string
= string_from_display_spec (spec
);
1478 struct text_pos tpos
;
1479 int replacing_spec_p
;
1480 bool newline_in_string
1482 && memchr (SDATA (string
), '\n', SBYTES (string
)));
1484 SET_TEXT_POS (tpos
, charpos
, CHAR_TO_BYTE (charpos
));
1487 && handle_display_spec (NULL
, spec
, Qnil
, Qnil
, &tpos
,
1488 charpos
, FRAME_WINDOW_P (it
.f
)));
1489 /* The tricky code below is needed because there's a
1490 discrepancy between move_it_to and how we set cursor
1491 when PT is at the beginning of a portion of text
1492 covered by a display property or an overlay with a
1493 display property, or the display line ends in a
1494 newline from a display string. move_it_to will stop
1495 _after_ such display strings, whereas
1496 set_cursor_from_row conspires with cursor_row_p to
1497 place the cursor on the first glyph produced from the
1500 /* We have overshoot PT because it is covered by a
1501 display property that replaces the text it covers.
1502 If the string includes embedded newlines, we are also
1503 in the wrong display line. Backtrack to the correct
1504 line, where the display property begins. */
1505 if (replacing_spec_p
)
1507 Lisp_Object startpos
, endpos
;
1508 EMACS_INT start
, end
;
1512 /* Find the first and the last buffer positions
1513 covered by the display string. */
1515 Fnext_single_char_property_change (cpos
, Qdisplay
,
1518 Fprevious_single_char_property_change (endpos
, Qdisplay
,
1520 start
= XFASTINT (startpos
);
1521 end
= XFASTINT (endpos
);
1522 /* Move to the last buffer position before the
1523 display property. */
1524 start_display (&it3
, w
, top
);
1525 move_it_to (&it3
, start
- 1, -1, -1, -1, MOVE_TO_POS
);
1526 /* Move forward one more line if the position before
1527 the display string is a newline or if it is the
1528 rightmost character on a line that is
1529 continued or word-wrapped. */
1530 if (it3
.method
== GET_FROM_BUFFER
1532 || FETCH_BYTE (IT_BYTEPOS (it3
)) == '\n'))
1533 move_it_by_lines (&it3
, 1);
1534 else if (move_it_in_display_line_to (&it3
, -1,
1538 == MOVE_LINE_CONTINUED
)
1540 move_it_by_lines (&it3
, 1);
1541 /* When we are under word-wrap, the #$@%!
1542 move_it_by_lines moves 2 lines, so we need to
1544 if (it3
.line_wrap
== WORD_WRAP
)
1545 move_it_by_lines (&it3
, -1);
1548 /* Record the vertical coordinate of the display
1549 line where we wound up. */
1550 top_y
= it3
.current_y
;
1553 /* When characters are reordered for display,
1554 the character displayed to the left of the
1555 display string could be _after_ the display
1556 property in the logical order. Use the
1557 smallest vertical position of these two. */
1558 start_display (&it3
, w
, top
);
1559 move_it_to (&it3
, end
+ 1, -1, -1, -1, MOVE_TO_POS
);
1560 if (it3
.current_y
< top_y
)
1561 top_y
= it3
.current_y
;
1563 /* Move from the top of the window to the beginning
1564 of the display line where the display string
1566 start_display (&it3
, w
, top
);
1567 move_it_to (&it3
, -1, 0, top_y
, -1, MOVE_TO_X
| MOVE_TO_Y
);
1568 /* If it3_moved stays zero after the 'while' loop
1569 below, that means we already were at a newline
1570 before the loop (e.g., the display string begins
1571 with a newline), so we don't need to (and cannot)
1572 inspect the glyphs of it3.glyph_row, because
1573 PRODUCE_GLYPHS will not produce anything for a
1574 newline, and thus it3.glyph_row stays at its
1575 stale content it got at top of the window. */
1577 /* Finally, advance the iterator until we hit the
1578 first display element whose character position is
1579 CHARPOS, or until the first newline from the
1580 display string, which signals the end of the
1582 while (get_next_display_element (&it3
))
1584 PRODUCE_GLYPHS (&it3
);
1585 if (IT_CHARPOS (it3
) == charpos
1586 || ITERATOR_AT_END_OF_LINE_P (&it3
))
1589 set_iterator_to_next (&it3
, 0);
1591 top_x
= it3
.current_x
- it3
.pixel_width
;
1592 /* Normally, we would exit the above loop because we
1593 found the display element whose character
1594 position is CHARPOS. For the contingency that we
1595 didn't, and stopped at the first newline from the
1596 display string, move back over the glyphs
1597 produced from the string, until we find the
1598 rightmost glyph not from the string. */
1600 && newline_in_string
1601 && IT_CHARPOS (it3
) != charpos
&& EQ (it3
.object
, string
))
1603 struct glyph
*g
= it3
.glyph_row
->glyphs
[TEXT_AREA
]
1604 + it3
.glyph_row
->used
[TEXT_AREA
];
1606 while (EQ ((g
- 1)->object
, string
))
1609 top_x
-= g
->pixel_width
;
1611 eassert (g
< it3
.glyph_row
->glyphs
[TEXT_AREA
]
1612 + it3
.glyph_row
->used
[TEXT_AREA
]);
1618 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1619 *rtop
= max (0, window_top_y
- top_y
);
1620 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1621 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1622 - max (top_y
, window_top_y
)));
1628 /* We were asked to provide info about WINDOW_END. */
1630 void *it2data
= NULL
;
1632 SAVE_IT (it2
, it
, it2data
);
1633 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1634 move_it_by_lines (&it
, 1);
1635 if (charpos
< IT_CHARPOS (it
)
1636 || (it
.what
== IT_EOB
&& charpos
== IT_CHARPOS (it
)))
1639 RESTORE_IT (&it2
, &it2
, it2data
);
1640 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1642 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1643 *rtop
= max (0, -it2
.current_y
);
1644 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1645 - it
.last_visible_y
));
1646 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1648 - max (it2
.current_y
,
1649 WINDOW_HEADER_LINE_HEIGHT (w
))));
1653 bidi_unshelve_cache (it2data
, 1);
1655 bidi_unshelve_cache (itdata
, 0);
1658 set_buffer_internal_1 (old_buffer
);
1660 current_header_line_height
= current_mode_line_height
= -1;
1662 if (visible_p
&& w
->hscroll
> 0)
1664 window_hscroll_limited (w
, WINDOW_XFRAME (w
))
1665 * WINDOW_FRAME_COLUMN_WIDTH (w
);
1668 /* Debugging code. */
1670 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1671 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1673 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1680 /* Return the next character from STR. Return in *LEN the length of
1681 the character. This is like STRING_CHAR_AND_LENGTH but never
1682 returns an invalid character. If we find one, we return a `?', but
1683 with the length of the invalid character. */
1686 string_char_and_length (const unsigned char *str
, int *len
)
1690 c
= STRING_CHAR_AND_LENGTH (str
, *len
);
1691 if (!CHAR_VALID_P (c
))
1692 /* We may not change the length here because other places in Emacs
1693 don't use this function, i.e. they silently accept invalid
1702 /* Given a position POS containing a valid character and byte position
1703 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1705 static struct text_pos
1706 string_pos_nchars_ahead (struct text_pos pos
, Lisp_Object string
, ptrdiff_t nchars
)
1708 eassert (STRINGP (string
) && nchars
>= 0);
1710 if (STRING_MULTIBYTE (string
))
1712 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1717 string_char_and_length (p
, &len
);
1720 BYTEPOS (pos
) += len
;
1724 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1730 /* Value is the text position, i.e. character and byte position,
1731 for character position CHARPOS in STRING. */
1733 static struct text_pos
1734 string_pos (ptrdiff_t charpos
, Lisp_Object string
)
1736 struct text_pos pos
;
1737 eassert (STRINGP (string
));
1738 eassert (charpos
>= 0);
1739 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1744 /* Value is a text position, i.e. character and byte position, for
1745 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1746 means recognize multibyte characters. */
1748 static struct text_pos
1749 c_string_pos (ptrdiff_t charpos
, const char *s
, bool multibyte_p
)
1751 struct text_pos pos
;
1753 eassert (s
!= NULL
);
1754 eassert (charpos
>= 0);
1760 SET_TEXT_POS (pos
, 0, 0);
1763 string_char_and_length ((const unsigned char *) s
, &len
);
1766 BYTEPOS (pos
) += len
;
1770 SET_TEXT_POS (pos
, charpos
, charpos
);
1776 /* Value is the number of characters in C string S. MULTIBYTE_P
1777 non-zero means recognize multibyte characters. */
1780 number_of_chars (const char *s
, bool multibyte_p
)
1786 ptrdiff_t rest
= strlen (s
);
1788 const unsigned char *p
= (const unsigned char *) s
;
1790 for (nchars
= 0; rest
> 0; ++nchars
)
1792 string_char_and_length (p
, &len
);
1793 rest
-= len
, p
+= len
;
1797 nchars
= strlen (s
);
1803 /* Compute byte position NEWPOS->bytepos corresponding to
1804 NEWPOS->charpos. POS is a known position in string STRING.
1805 NEWPOS->charpos must be >= POS.charpos. */
1808 compute_string_pos (struct text_pos
*newpos
, struct text_pos pos
, Lisp_Object string
)
1810 eassert (STRINGP (string
));
1811 eassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1813 if (STRING_MULTIBYTE (string
))
1814 *newpos
= string_pos_nchars_ahead (pos
, string
,
1815 CHARPOS (*newpos
) - CHARPOS (pos
));
1817 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1821 Return an estimation of the pixel height of mode or header lines on
1822 frame F. FACE_ID specifies what line's height to estimate. */
1825 estimate_mode_line_height (struct frame
*f
, enum face_id face_id
)
1827 #ifdef HAVE_WINDOW_SYSTEM
1828 if (FRAME_WINDOW_P (f
))
1830 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1832 /* This function is called so early when Emacs starts that the face
1833 cache and mode line face are not yet initialized. */
1834 if (FRAME_FACE_CACHE (f
))
1836 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1840 height
= FONT_HEIGHT (face
->font
);
1841 if (face
->box_line_width
> 0)
1842 height
+= 2 * face
->box_line_width
;
1853 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1854 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1855 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1856 not force the value into range. */
1859 pixel_to_glyph_coords (struct frame
*f
, register int pix_x
, register int pix_y
,
1860 int *x
, int *y
, NativeRectangle
*bounds
, int noclip
)
1863 #ifdef HAVE_WINDOW_SYSTEM
1864 if (FRAME_WINDOW_P (f
))
1866 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1867 even for negative values. */
1869 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1871 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1873 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1874 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1877 STORE_NATIVE_RECT (*bounds
,
1878 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1879 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1880 FRAME_COLUMN_WIDTH (f
) - 1,
1881 FRAME_LINE_HEIGHT (f
) - 1);
1887 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1888 pix_x
= FRAME_TOTAL_COLS (f
);
1892 else if (pix_y
> FRAME_LINES (f
))
1893 pix_y
= FRAME_LINES (f
);
1903 /* Find the glyph under window-relative coordinates X/Y in window W.
1904 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1905 strings. Return in *HPOS and *VPOS the row and column number of
1906 the glyph found. Return in *AREA the glyph area containing X.
1907 Value is a pointer to the glyph found or null if X/Y is not on
1908 text, or we can't tell because W's current matrix is not up to
1913 x_y_to_hpos_vpos (struct window
*w
, int x
, int y
, int *hpos
, int *vpos
,
1914 int *dx
, int *dy
, int *area
)
1916 struct glyph
*glyph
, *end
;
1917 struct glyph_row
*row
= NULL
;
1920 /* Find row containing Y. Give up if some row is not enabled. */
1921 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1923 row
= MATRIX_ROW (w
->current_matrix
, i
);
1924 if (!row
->enabled_p
)
1926 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1933 /* Give up if Y is not in the window. */
1934 if (i
== w
->current_matrix
->nrows
)
1937 /* Get the glyph area containing X. */
1938 if (w
->pseudo_window_p
)
1945 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1947 *area
= LEFT_MARGIN_AREA
;
1948 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1950 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1953 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1957 *area
= RIGHT_MARGIN_AREA
;
1958 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1962 /* Find glyph containing X. */
1963 glyph
= row
->glyphs
[*area
];
1964 end
= glyph
+ row
->used
[*area
];
1966 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1968 x
-= glyph
->pixel_width
;
1978 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1981 *hpos
= glyph
- row
->glyphs
[*area
];
1985 /* Convert frame-relative x/y to coordinates relative to window W.
1986 Takes pseudo-windows into account. */
1989 frame_to_window_pixel_xy (struct window
*w
, int *x
, int *y
)
1991 if (w
->pseudo_window_p
)
1993 /* A pseudo-window is always full-width, and starts at the
1994 left edge of the frame, plus a frame border. */
1995 struct frame
*f
= XFRAME (w
->frame
);
1996 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1997 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
2001 *x
-= WINDOW_LEFT_EDGE_X (w
);
2002 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
2006 #ifdef HAVE_WINDOW_SYSTEM
2009 Return in RECTS[] at most N clipping rectangles for glyph string S.
2010 Return the number of stored rectangles. */
2013 get_glyph_string_clip_rects (struct glyph_string
*s
, NativeRectangle
*rects
, int n
)
2020 if (s
->row
->full_width_p
)
2022 /* Draw full-width. X coordinates are relative to S->w->left_col. */
2023 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
2024 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
2026 /* Unless displaying a mode or menu bar line, which are always
2027 fully visible, clip to the visible part of the row. */
2028 if (s
->w
->pseudo_window_p
)
2029 r
.height
= s
->row
->visible_height
;
2031 r
.height
= s
->height
;
2035 /* This is a text line that may be partially visible. */
2036 r
.x
= window_box_left (s
->w
, s
->area
);
2037 r
.width
= window_box_width (s
->w
, s
->area
);
2038 r
.height
= s
->row
->visible_height
;
2042 if (r
.x
< s
->clip_head
->x
)
2044 if (r
.width
>= s
->clip_head
->x
- r
.x
)
2045 r
.width
-= s
->clip_head
->x
- r
.x
;
2048 r
.x
= s
->clip_head
->x
;
2051 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
2053 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
2054 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
2059 /* If S draws overlapping rows, it's sufficient to use the top and
2060 bottom of the window for clipping because this glyph string
2061 intentionally draws over other lines. */
2062 if (s
->for_overlaps
)
2064 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
2065 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
2067 /* Alas, the above simple strategy does not work for the
2068 environments with anti-aliased text: if the same text is
2069 drawn onto the same place multiple times, it gets thicker.
2070 If the overlap we are processing is for the erased cursor, we
2071 take the intersection with the rectangle of the cursor. */
2072 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
2074 XRectangle rc
, r_save
= r
;
2076 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
2077 rc
.y
= s
->w
->phys_cursor
.y
;
2078 rc
.width
= s
->w
->phys_cursor_width
;
2079 rc
.height
= s
->w
->phys_cursor_height
;
2081 x_intersect_rectangles (&r_save
, &rc
, &r
);
2086 /* Don't use S->y for clipping because it doesn't take partially
2087 visible lines into account. For example, it can be negative for
2088 partially visible lines at the top of a window. */
2089 if (!s
->row
->full_width_p
2090 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
2091 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
2093 r
.y
= max (0, s
->row
->y
);
2096 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
2098 /* If drawing the cursor, don't let glyph draw outside its
2099 advertised boundaries. Cleartype does this under some circumstances. */
2100 if (s
->hl
== DRAW_CURSOR
)
2102 struct glyph
*glyph
= s
->first_glyph
;
2107 r
.width
-= s
->x
- r
.x
;
2110 r
.width
= min (r
.width
, glyph
->pixel_width
);
2112 /* If r.y is below window bottom, ensure that we still see a cursor. */
2113 height
= min (glyph
->ascent
+ glyph
->descent
,
2114 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
2115 max_y
= window_text_bottom_y (s
->w
) - height
;
2116 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
2117 if (s
->ybase
- glyph
->ascent
> max_y
)
2124 /* Don't draw cursor glyph taller than our actual glyph. */
2125 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
2126 if (height
< r
.height
)
2128 max_y
= r
.y
+ r
.height
;
2129 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
2130 r
.height
= min (max_y
- r
.y
, height
);
2137 XRectangle r_save
= r
;
2139 if (! x_intersect_rectangles (&r_save
, s
->row
->clip
, &r
))
2143 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
2144 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
2146 #ifdef CONVERT_FROM_XRECT
2147 CONVERT_FROM_XRECT (r
, *rects
);
2155 /* If we are processing overlapping and allowed to return
2156 multiple clipping rectangles, we exclude the row of the glyph
2157 string from the clipping rectangle. This is to avoid drawing
2158 the same text on the environment with anti-aliasing. */
2159 #ifdef CONVERT_FROM_XRECT
2162 XRectangle
*rs
= rects
;
2164 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
2166 if (s
->for_overlaps
& OVERLAPS_PRED
)
2169 if (r
.y
+ r
.height
> row_y
)
2172 rs
[i
].height
= row_y
- r
.y
;
2178 if (s
->for_overlaps
& OVERLAPS_SUCC
)
2181 if (r
.y
< row_y
+ s
->row
->visible_height
)
2183 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
2185 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
2186 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
2195 #ifdef CONVERT_FROM_XRECT
2196 for (i
= 0; i
< n
; i
++)
2197 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
2204 Return in *NR the clipping rectangle for glyph string S. */
2207 get_glyph_string_clip_rect (struct glyph_string
*s
, NativeRectangle
*nr
)
2209 get_glyph_string_clip_rects (s
, nr
, 1);
2214 Return the position and height of the phys cursor in window W.
2215 Set w->phys_cursor_width to width of phys cursor.
2219 get_phys_cursor_geometry (struct window
*w
, struct glyph_row
*row
,
2220 struct glyph
*glyph
, int *xp
, int *yp
, int *heightp
)
2222 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2223 int x
, y
, wd
, h
, h0
, y0
;
2225 /* Compute the width of the rectangle to draw. If on a stretch
2226 glyph, and `x-stretch-block-cursor' is nil, don't draw a
2227 rectangle as wide as the glyph, but use a canonical character
2229 wd
= glyph
->pixel_width
- 1;
2230 #if defined (HAVE_NTGUI) || defined (HAVE_NS)
2234 x
= w
->phys_cursor
.x
;
2241 if (glyph
->type
== STRETCH_GLYPH
2242 && !x_stretch_cursor_p
)
2243 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2244 w
->phys_cursor_width
= wd
;
2246 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
2248 /* If y is below window bottom, ensure that we still see a cursor. */
2249 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2251 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
2252 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
2254 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2257 h
= max (h
- (y0
- y
) + 1, h0
);
2262 y0
= window_text_bottom_y (w
) - h0
;
2270 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
2271 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2276 * Remember which glyph the mouse is over.
2280 remember_mouse_glyph (struct frame
*f
, int gx
, int gy
, NativeRectangle
*rect
)
2284 struct glyph_row
*r
, *gr
, *end_row
;
2285 enum window_part part
;
2286 enum glyph_row_area area
;
2287 int x
, y
, width
, height
;
2289 /* Try to determine frame pixel position and size of the glyph under
2290 frame pixel coordinates X/Y on frame F. */
2292 if (!f
->glyphs_initialized_p
2293 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, 0),
2296 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2297 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2301 w
= XWINDOW (window
);
2302 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2303 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2305 x
= window_relative_x_coord (w
, part
, gx
);
2306 y
= gy
- WINDOW_TOP_EDGE_Y (w
);
2308 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2309 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2311 if (w
->pseudo_window_p
)
2314 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2320 case ON_LEFT_MARGIN
:
2321 area
= LEFT_MARGIN_AREA
;
2324 case ON_RIGHT_MARGIN
:
2325 area
= RIGHT_MARGIN_AREA
;
2328 case ON_HEADER_LINE
:
2330 gr
= (part
== ON_HEADER_LINE
2331 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2332 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2335 goto text_glyph_row_found
;
2342 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2343 if (r
->y
+ r
->height
> y
)
2349 text_glyph_row_found
:
2352 struct glyph
*g
= gr
->glyphs
[area
];
2353 struct glyph
*end
= g
+ gr
->used
[area
];
2355 height
= gr
->height
;
2356 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2357 if (gx
+ g
->pixel_width
> x
)
2362 if (g
->type
== IMAGE_GLYPH
)
2364 /* Don't remember when mouse is over image, as
2365 image may have hot-spots. */
2366 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2369 width
= g
->pixel_width
;
2373 /* Use nominal char spacing at end of line. */
2375 gx
+= (x
/ width
) * width
;
2378 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2379 gx
+= window_box_left_offset (w
, area
);
2383 /* Use nominal line height at end of window. */
2384 gx
= (x
/ width
) * width
;
2386 gy
+= (y
/ height
) * height
;
2390 case ON_LEFT_FRINGE
:
2391 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2392 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2393 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2394 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2397 case ON_RIGHT_FRINGE
:
2398 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2399 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2400 : window_box_right_offset (w
, TEXT_AREA
));
2401 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2405 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2407 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2408 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2409 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2411 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2415 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2416 if (r
->y
+ r
->height
> y
)
2423 height
= gr
->height
;
2426 /* Use nominal line height at end of window. */
2428 gy
+= (y
/ height
) * height
;
2435 /* If there is no glyph under the mouse, then we divide the screen
2436 into a grid of the smallest glyph in the frame, and use that
2439 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2440 round down even for negative values. */
2446 gx
= (gx
/ width
) * width
;
2447 gy
= (gy
/ height
) * height
;
2452 gx
+= WINDOW_LEFT_EDGE_X (w
);
2453 gy
+= WINDOW_TOP_EDGE_Y (w
);
2456 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2458 /* Visible feedback for debugging. */
2461 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2462 f
->output_data
.x
->normal_gc
,
2463 gx
, gy
, width
, height
);
2469 #endif /* HAVE_WINDOW_SYSTEM */
2472 adjust_window_ends (struct window
*w
, struct glyph_row
*row
, bool current
)
2475 w
->window_end_pos
= Z
- MATRIX_ROW_END_CHARPOS (row
);
2476 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
2478 = MATRIX_ROW_VPOS (row
, current
? w
->current_matrix
: w
->desired_matrix
);
2481 /***********************************************************************
2482 Lisp form evaluation
2483 ***********************************************************************/
2485 /* Error handler for safe_eval and safe_call. */
2488 safe_eval_handler (Lisp_Object arg
, ptrdiff_t nargs
, Lisp_Object
*args
)
2490 add_to_log ("Error during redisplay: %S signaled %S",
2491 Flist (nargs
, args
), arg
);
2495 /* Call function FUNC with the rest of NARGS - 1 arguments
2496 following. Return the result, or nil if something went
2497 wrong. Prevent redisplay during the evaluation. */
2500 safe_call (ptrdiff_t nargs
, Lisp_Object func
, ...)
2504 if (inhibit_eval_during_redisplay
)
2510 ptrdiff_t count
= SPECPDL_INDEX ();
2511 struct gcpro gcpro1
;
2512 Lisp_Object
*args
= alloca (nargs
* word_size
);
2515 va_start (ap
, func
);
2516 for (i
= 1; i
< nargs
; i
++)
2517 args
[i
] = va_arg (ap
, Lisp_Object
);
2521 gcpro1
.nvars
= nargs
;
2522 specbind (Qinhibit_redisplay
, Qt
);
2523 /* Use Qt to ensure debugger does not run,
2524 so there is no possibility of wanting to redisplay. */
2525 val
= internal_condition_case_n (Ffuncall
, nargs
, args
, Qt
,
2528 val
= unbind_to (count
, val
);
2535 /* Call function FN with one argument ARG.
2536 Return the result, or nil if something went wrong. */
2539 safe_call1 (Lisp_Object fn
, Lisp_Object arg
)
2541 return safe_call (2, fn
, arg
);
2544 static Lisp_Object Qeval
;
2547 safe_eval (Lisp_Object sexpr
)
2549 return safe_call1 (Qeval
, sexpr
);
2552 /* Call function FN with two arguments ARG1 and ARG2.
2553 Return the result, or nil if something went wrong. */
2556 safe_call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2558 return safe_call (3, fn
, arg1
, arg2
);
2563 /***********************************************************************
2565 ***********************************************************************/
2569 /* Define CHECK_IT to perform sanity checks on iterators.
2570 This is for debugging. It is too slow to do unconditionally. */
2573 check_it (struct it
*it
)
2575 if (it
->method
== GET_FROM_STRING
)
2577 eassert (STRINGP (it
->string
));
2578 eassert (IT_STRING_CHARPOS (*it
) >= 0);
2582 eassert (IT_STRING_CHARPOS (*it
) < 0);
2583 if (it
->method
== GET_FROM_BUFFER
)
2585 /* Check that character and byte positions agree. */
2586 eassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2591 eassert (it
->current
.dpvec_index
>= 0);
2593 eassert (it
->current
.dpvec_index
< 0);
2596 #define CHECK_IT(IT) check_it ((IT))
2600 #define CHECK_IT(IT) (void) 0
2605 #if defined GLYPH_DEBUG && defined ENABLE_CHECKING
2607 /* Check that the window end of window W is what we expect it
2608 to be---the last row in the current matrix displaying text. */
2611 check_window_end (struct window
*w
)
2613 if (!MINI_WINDOW_P (w
) && w
->window_end_valid
)
2615 struct glyph_row
*row
;
2616 eassert ((row
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
),
2618 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2619 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2623 #define CHECK_WINDOW_END(W) check_window_end ((W))
2627 #define CHECK_WINDOW_END(W) (void) 0
2629 #endif /* GLYPH_DEBUG and ENABLE_CHECKING */
2631 /* Return mark position if current buffer has the region of non-zero length,
2635 markpos_of_region (void)
2637 if (!NILP (Vtransient_mark_mode
)
2638 && !NILP (BVAR (current_buffer
, mark_active
))
2639 && XMARKER (BVAR (current_buffer
, mark
))->buffer
!= NULL
)
2641 ptrdiff_t markpos
= XMARKER (BVAR (current_buffer
, mark
))->charpos
;
2649 /***********************************************************************
2650 Iterator initialization
2651 ***********************************************************************/
2653 /* Initialize IT for displaying current_buffer in window W, starting
2654 at character position CHARPOS. CHARPOS < 0 means that no buffer
2655 position is specified which is useful when the iterator is assigned
2656 a position later. BYTEPOS is the byte position corresponding to
2659 If ROW is not null, calls to produce_glyphs with IT as parameter
2660 will produce glyphs in that row.
2662 BASE_FACE_ID is the id of a base face to use. It must be one of
2663 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2664 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2665 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2667 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2668 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2669 will be initialized to use the corresponding mode line glyph row of
2670 the desired matrix of W. */
2673 init_iterator (struct it
*it
, struct window
*w
,
2674 ptrdiff_t charpos
, ptrdiff_t bytepos
,
2675 struct glyph_row
*row
, enum face_id base_face_id
)
2678 enum face_id remapped_base_face_id
= base_face_id
;
2680 /* Some precondition checks. */
2681 eassert (w
!= NULL
&& it
!= NULL
);
2682 eassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2685 /* If face attributes have been changed since the last redisplay,
2686 free realized faces now because they depend on face definitions
2687 that might have changed. Don't free faces while there might be
2688 desired matrices pending which reference these faces. */
2689 if (face_change_count
&& !inhibit_free_realized_faces
)
2691 face_change_count
= 0;
2692 free_all_realized_faces (Qnil
);
2695 /* Perhaps remap BASE_FACE_ID to a user-specified alternative. */
2696 if (! NILP (Vface_remapping_alist
))
2697 remapped_base_face_id
2698 = lookup_basic_face (XFRAME (w
->frame
), base_face_id
);
2700 /* Use one of the mode line rows of W's desired matrix if
2704 if (base_face_id
== MODE_LINE_FACE_ID
2705 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2706 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2707 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2708 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2712 memset (it
, 0, sizeof *it
);
2713 it
->current
.overlay_string_index
= -1;
2714 it
->current
.dpvec_index
= -1;
2715 it
->base_face_id
= remapped_base_face_id
;
2717 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2718 it
->paragraph_embedding
= L2R
;
2719 it
->bidi_it
.string
.lstring
= Qnil
;
2720 it
->bidi_it
.string
.s
= NULL
;
2721 it
->bidi_it
.string
.bufpos
= 0;
2724 /* The window in which we iterate over current_buffer: */
2725 XSETWINDOW (it
->window
, w
);
2727 it
->f
= XFRAME (w
->frame
);
2731 /* Extra space between lines (on window systems only). */
2732 if (base_face_id
== DEFAULT_FACE_ID
2733 && FRAME_WINDOW_P (it
->f
))
2735 if (NATNUMP (BVAR (current_buffer
, extra_line_spacing
)))
2736 it
->extra_line_spacing
= XFASTINT (BVAR (current_buffer
, extra_line_spacing
));
2737 else if (FLOATP (BVAR (current_buffer
, extra_line_spacing
)))
2738 it
->extra_line_spacing
= (XFLOAT_DATA (BVAR (current_buffer
, extra_line_spacing
))
2739 * FRAME_LINE_HEIGHT (it
->f
));
2740 else if (it
->f
->extra_line_spacing
> 0)
2741 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2742 it
->max_extra_line_spacing
= 0;
2745 /* If realized faces have been removed, e.g. because of face
2746 attribute changes of named faces, recompute them. When running
2747 in batch mode, the face cache of the initial frame is null. If
2748 we happen to get called, make a dummy face cache. */
2749 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2750 init_frame_faces (it
->f
);
2751 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2752 recompute_basic_faces (it
->f
);
2754 /* Current value of the `slice', `space-width', and 'height' properties. */
2755 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2756 it
->space_width
= Qnil
;
2757 it
->font_height
= Qnil
;
2758 it
->override_ascent
= -1;
2760 /* Are control characters displayed as `^C'? */
2761 it
->ctl_arrow_p
= !NILP (BVAR (current_buffer
, ctl_arrow
));
2763 /* -1 means everything between a CR and the following line end
2764 is invisible. >0 means lines indented more than this value are
2766 it
->selective
= (INTEGERP (BVAR (current_buffer
, selective_display
))
2768 (-1, XINT (BVAR (current_buffer
, selective_display
)),
2770 : (!NILP (BVAR (current_buffer
, selective_display
))
2772 it
->selective_display_ellipsis_p
2773 = !NILP (BVAR (current_buffer
, selective_display_ellipses
));
2775 /* Display table to use. */
2776 it
->dp
= window_display_table (w
);
2778 /* Are multibyte characters enabled in current_buffer? */
2779 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
2781 /* If visible region is of non-zero length, set IT->region_beg_charpos
2782 and IT->region_end_charpos to the start and end of a visible region
2783 in window IT->w. Set both to -1 to indicate no region. */
2784 markpos
= markpos_of_region ();
2786 /* Maybe highlight only in selected window. */
2787 && (/* Either show region everywhere. */
2788 highlight_nonselected_windows
2789 /* Or show region in the selected window. */
2790 || w
== XWINDOW (selected_window
)
2791 /* Or show the region if we are in the mini-buffer and W is
2792 the window the mini-buffer refers to. */
2793 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2794 && WINDOWP (minibuf_selected_window
)
2795 && w
== XWINDOW (minibuf_selected_window
))))
2797 it
->region_beg_charpos
= min (PT
, markpos
);
2798 it
->region_end_charpos
= max (PT
, markpos
);
2801 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2803 /* Get the position at which the redisplay_end_trigger hook should
2804 be run, if it is to be run at all. */
2805 if (MARKERP (w
->redisplay_end_trigger
)
2806 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2807 it
->redisplay_end_trigger_charpos
2808 = marker_position (w
->redisplay_end_trigger
);
2809 else if (INTEGERP (w
->redisplay_end_trigger
))
2810 it
->redisplay_end_trigger_charpos
=
2811 clip_to_bounds (PTRDIFF_MIN
, XINT (w
->redisplay_end_trigger
), PTRDIFF_MAX
);
2813 it
->tab_width
= SANE_TAB_WIDTH (current_buffer
);
2815 /* Are lines in the display truncated? */
2816 if (base_face_id
!= DEFAULT_FACE_ID
2818 || (! WINDOW_FULL_WIDTH_P (it
->w
)
2819 && ((!NILP (Vtruncate_partial_width_windows
)
2820 && !INTEGERP (Vtruncate_partial_width_windows
))
2821 || (INTEGERP (Vtruncate_partial_width_windows
)
2822 && (WINDOW_TOTAL_COLS (it
->w
)
2823 < XINT (Vtruncate_partial_width_windows
))))))
2824 it
->line_wrap
= TRUNCATE
;
2825 else if (NILP (BVAR (current_buffer
, truncate_lines
)))
2826 it
->line_wrap
= NILP (BVAR (current_buffer
, word_wrap
))
2827 ? WINDOW_WRAP
: WORD_WRAP
;
2829 it
->line_wrap
= TRUNCATE
;
2831 /* Get dimensions of truncation and continuation glyphs. These are
2832 displayed as fringe bitmaps under X, but we need them for such
2833 frames when the fringes are turned off. But leave the dimensions
2834 zero for tooltip frames, as these glyphs look ugly there and also
2835 sabotage calculations of tooltip dimensions in x-show-tip. */
2836 #ifdef HAVE_WINDOW_SYSTEM
2837 if (!(FRAME_WINDOW_P (it
->f
)
2838 && FRAMEP (tip_frame
)
2839 && it
->f
== XFRAME (tip_frame
)))
2842 if (it
->line_wrap
== TRUNCATE
)
2844 /* We will need the truncation glyph. */
2845 eassert (it
->glyph_row
== NULL
);
2846 produce_special_glyphs (it
, IT_TRUNCATION
);
2847 it
->truncation_pixel_width
= it
->pixel_width
;
2851 /* We will need the continuation glyph. */
2852 eassert (it
->glyph_row
== NULL
);
2853 produce_special_glyphs (it
, IT_CONTINUATION
);
2854 it
->continuation_pixel_width
= it
->pixel_width
;
2858 /* Reset these values to zero because the produce_special_glyphs
2859 above has changed them. */
2860 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2861 it
->phys_ascent
= it
->phys_descent
= 0;
2863 /* Set this after getting the dimensions of truncation and
2864 continuation glyphs, so that we don't produce glyphs when calling
2865 produce_special_glyphs, above. */
2866 it
->glyph_row
= row
;
2867 it
->area
= TEXT_AREA
;
2869 /* Forget any previous info about this row being reversed. */
2871 it
->glyph_row
->reversed_p
= 0;
2873 /* Get the dimensions of the display area. The display area
2874 consists of the visible window area plus a horizontally scrolled
2875 part to the left of the window. All x-values are relative to the
2876 start of this total display area. */
2877 if (base_face_id
!= DEFAULT_FACE_ID
)
2879 /* Mode lines, menu bar in terminal frames. */
2880 it
->first_visible_x
= 0;
2881 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2885 it
->first_visible_x
=
2886 window_hscroll_limited (it
->w
, it
->f
) * FRAME_COLUMN_WIDTH (it
->f
);
2887 it
->last_visible_x
= (it
->first_visible_x
2888 + window_box_width (w
, TEXT_AREA
));
2890 /* If we truncate lines, leave room for the truncation glyph(s) at
2891 the right margin. Otherwise, leave room for the continuation
2892 glyph(s). Done only if the window has no fringes. Since we
2893 don't know at this point whether there will be any R2L lines in
2894 the window, we reserve space for truncation/continuation glyphs
2895 even if only one of the fringes is absent. */
2896 if (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0
2897 || (it
->bidi_p
&& WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0))
2899 if (it
->line_wrap
== TRUNCATE
)
2900 it
->last_visible_x
-= it
->truncation_pixel_width
;
2902 it
->last_visible_x
-= it
->continuation_pixel_width
;
2905 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2906 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2909 /* Leave room for a border glyph. */
2910 if (!FRAME_WINDOW_P (it
->f
)
2911 && !WINDOW_RIGHTMOST_P (it
->w
))
2912 it
->last_visible_x
-= 1;
2914 it
->last_visible_y
= window_text_bottom_y (w
);
2916 /* For mode lines and alike, arrange for the first glyph having a
2917 left box line if the face specifies a box. */
2918 if (base_face_id
!= DEFAULT_FACE_ID
)
2922 it
->face_id
= remapped_base_face_id
;
2924 /* If we have a boxed mode line, make the first character appear
2925 with a left box line. */
2926 face
= FACE_FROM_ID (it
->f
, remapped_base_face_id
);
2927 if (face
->box
!= FACE_NO_BOX
)
2928 it
->start_of_box_run_p
= 1;
2931 /* If a buffer position was specified, set the iterator there,
2932 getting overlays and face properties from that position. */
2933 if (charpos
>= BUF_BEG (current_buffer
))
2935 it
->end_charpos
= ZV
;
2936 eassert (charpos
== BYTE_TO_CHAR (bytepos
));
2937 IT_CHARPOS (*it
) = charpos
;
2938 IT_BYTEPOS (*it
) = bytepos
;
2940 /* We will rely on `reseat' to set this up properly, via
2941 handle_face_prop. */
2942 it
->face_id
= it
->base_face_id
;
2944 it
->start
= it
->current
;
2945 /* Do we need to reorder bidirectional text? Not if this is a
2946 unibyte buffer: by definition, none of the single-byte
2947 characters are strong R2L, so no reordering is needed. And
2948 bidi.c doesn't support unibyte buffers anyway. Also, don't
2949 reorder while we are loading loadup.el, since the tables of
2950 character properties needed for reordering are not yet
2954 && !NILP (BVAR (current_buffer
, bidi_display_reordering
))
2957 /* If we are to reorder bidirectional text, init the bidi
2961 /* Note the paragraph direction that this buffer wants to
2963 if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2965 it
->paragraph_embedding
= L2R
;
2966 else if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2968 it
->paragraph_embedding
= R2L
;
2970 it
->paragraph_embedding
= NEUTRAL_DIR
;
2971 bidi_unshelve_cache (NULL
, 0);
2972 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
2976 /* Compute faces etc. */
2977 reseat (it
, it
->current
.pos
, 1);
2984 /* Initialize IT for the display of window W with window start POS. */
2987 start_display (struct it
*it
, struct window
*w
, struct text_pos pos
)
2989 struct glyph_row
*row
;
2990 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2992 row
= w
->desired_matrix
->rows
+ first_vpos
;
2993 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2994 it
->first_vpos
= first_vpos
;
2996 /* Don't reseat to previous visible line start if current start
2997 position is in a string or image. */
2998 if (it
->method
== GET_FROM_BUFFER
&& it
->line_wrap
!= TRUNCATE
)
3000 int start_at_line_beg_p
;
3001 int first_y
= it
->current_y
;
3003 /* If window start is not at a line start, skip forward to POS to
3004 get the correct continuation lines width. */
3005 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
3006 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
3007 if (!start_at_line_beg_p
)
3011 reseat_at_previous_visible_line_start (it
);
3012 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
3014 new_x
= it
->current_x
+ it
->pixel_width
;
3016 /* If lines are continued, this line may end in the middle
3017 of a multi-glyph character (e.g. a control character
3018 displayed as \003, or in the middle of an overlay
3019 string). In this case move_it_to above will not have
3020 taken us to the start of the continuation line but to the
3021 end of the continued line. */
3022 if (it
->current_x
> 0
3023 && it
->line_wrap
!= TRUNCATE
/* Lines are continued. */
3024 && (/* And glyph doesn't fit on the line. */
3025 new_x
> it
->last_visible_x
3026 /* Or it fits exactly and we're on a window
3028 || (new_x
== it
->last_visible_x
3029 && FRAME_WINDOW_P (it
->f
)
3030 && ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
3031 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
3032 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
3034 if ((it
->current
.dpvec_index
>= 0
3035 || it
->current
.overlay_string_index
>= 0)
3036 /* If we are on a newline from a display vector or
3037 overlay string, then we are already at the end of
3038 a screen line; no need to go to the next line in
3039 that case, as this line is not really continued.
3040 (If we do go to the next line, C-e will not DTRT.) */
3043 set_iterator_to_next (it
, 1);
3044 move_it_in_display_line_to (it
, -1, -1, 0);
3047 it
->continuation_lines_width
+= it
->current_x
;
3049 /* If the character at POS is displayed via a display
3050 vector, move_it_to above stops at the final glyph of
3051 IT->dpvec. To make the caller redisplay that character
3052 again (a.k.a. start at POS), we need to reset the
3053 dpvec_index to the beginning of IT->dpvec. */
3054 else if (it
->current
.dpvec_index
>= 0)
3055 it
->current
.dpvec_index
= 0;
3057 /* We're starting a new display line, not affected by the
3058 height of the continued line, so clear the appropriate
3059 fields in the iterator structure. */
3060 it
->max_ascent
= it
->max_descent
= 0;
3061 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
3063 it
->current_y
= first_y
;
3065 it
->current_x
= it
->hpos
= 0;
3071 /* Return 1 if POS is a position in ellipses displayed for invisible
3072 text. W is the window we display, for text property lookup. */
3075 in_ellipses_for_invisible_text_p (struct display_pos
*pos
, struct window
*w
)
3077 Lisp_Object prop
, window
;
3079 ptrdiff_t charpos
= CHARPOS (pos
->pos
);
3081 /* If POS specifies a position in a display vector, this might
3082 be for an ellipsis displayed for invisible text. We won't
3083 get the iterator set up for delivering that ellipsis unless
3084 we make sure that it gets aware of the invisible text. */
3085 if (pos
->dpvec_index
>= 0
3086 && pos
->overlay_string_index
< 0
3087 && CHARPOS (pos
->string_pos
) < 0
3089 && (XSETWINDOW (window
, w
),
3090 prop
= Fget_char_property (make_number (charpos
),
3091 Qinvisible
, window
),
3092 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
3094 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
3096 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
3103 /* Initialize IT for stepping through current_buffer in window W,
3104 starting at position POS that includes overlay string and display
3105 vector/ control character translation position information. Value
3106 is zero if there are overlay strings with newlines at POS. */
3109 init_from_display_pos (struct it
*it
, struct window
*w
, struct display_pos
*pos
)
3111 ptrdiff_t charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
3112 int i
, overlay_strings_with_newlines
= 0;
3114 /* If POS specifies a position in a display vector, this might
3115 be for an ellipsis displayed for invisible text. We won't
3116 get the iterator set up for delivering that ellipsis unless
3117 we make sure that it gets aware of the invisible text. */
3118 if (in_ellipses_for_invisible_text_p (pos
, w
))
3124 /* Keep in mind: the call to reseat in init_iterator skips invisible
3125 text, so we might end up at a position different from POS. This
3126 is only a problem when POS is a row start after a newline and an
3127 overlay starts there with an after-string, and the overlay has an
3128 invisible property. Since we don't skip invisible text in
3129 display_line and elsewhere immediately after consuming the
3130 newline before the row start, such a POS will not be in a string,
3131 but the call to init_iterator below will move us to the
3133 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
3135 /* This only scans the current chunk -- it should scan all chunks.
3136 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
3137 to 16 in 22.1 to make this a lesser problem. */
3138 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
3140 const char *s
= SSDATA (it
->overlay_strings
[i
]);
3141 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
3143 while (s
< e
&& *s
!= '\n')
3148 overlay_strings_with_newlines
= 1;
3153 /* If position is within an overlay string, set up IT to the right
3155 if (pos
->overlay_string_index
>= 0)
3159 /* If the first overlay string happens to have a `display'
3160 property for an image, the iterator will be set up for that
3161 image, and we have to undo that setup first before we can
3162 correct the overlay string index. */
3163 if (it
->method
== GET_FROM_IMAGE
)
3166 /* We already have the first chunk of overlay strings in
3167 IT->overlay_strings. Load more until the one for
3168 pos->overlay_string_index is in IT->overlay_strings. */
3169 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
3171 ptrdiff_t n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
3172 it
->current
.overlay_string_index
= 0;
3175 load_overlay_strings (it
, 0);
3176 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
3180 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
3181 relative_index
= (it
->current
.overlay_string_index
3182 % OVERLAY_STRING_CHUNK_SIZE
);
3183 it
->string
= it
->overlay_strings
[relative_index
];
3184 eassert (STRINGP (it
->string
));
3185 it
->current
.string_pos
= pos
->string_pos
;
3186 it
->method
= GET_FROM_STRING
;
3187 it
->end_charpos
= SCHARS (it
->string
);
3188 /* Set up the bidi iterator for this overlay string. */
3191 it
->bidi_it
.string
.lstring
= it
->string
;
3192 it
->bidi_it
.string
.s
= NULL
;
3193 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
3194 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
3195 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
3196 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
3197 it
->bidi_it
.w
= it
->w
;
3198 bidi_init_it (IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
),
3199 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
3201 /* Synchronize the state of the bidi iterator with
3202 pos->string_pos. For any string position other than
3203 zero, this will be done automagically when we resume
3204 iteration over the string and get_visually_first_element
3205 is called. But if string_pos is zero, and the string is
3206 to be reordered for display, we need to resync manually,
3207 since it could be that the iteration state recorded in
3208 pos ended at string_pos of 0 moving backwards in string. */
3209 if (CHARPOS (pos
->string_pos
) == 0)
3211 get_visually_first_element (it
);
3212 if (IT_STRING_CHARPOS (*it
) != 0)
3215 eassert (it
->bidi_it
.charpos
< it
->bidi_it
.string
.schars
);
3216 bidi_move_to_visually_next (&it
->bidi_it
);
3217 } while (it
->bidi_it
.charpos
!= 0);
3219 eassert (IT_STRING_CHARPOS (*it
) == it
->bidi_it
.charpos
3220 && IT_STRING_BYTEPOS (*it
) == it
->bidi_it
.bytepos
);
3224 if (CHARPOS (pos
->string_pos
) >= 0)
3226 /* Recorded position is not in an overlay string, but in another
3227 string. This can only be a string from a `display' property.
3228 IT should already be filled with that string. */
3229 it
->current
.string_pos
= pos
->string_pos
;
3230 eassert (STRINGP (it
->string
));
3232 bidi_init_it (IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
),
3233 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
3236 /* Restore position in display vector translations, control
3237 character translations or ellipses. */
3238 if (pos
->dpvec_index
>= 0)
3240 if (it
->dpvec
== NULL
)
3241 get_next_display_element (it
);
3242 eassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
3243 it
->current
.dpvec_index
= pos
->dpvec_index
;
3247 return !overlay_strings_with_newlines
;
3251 /* Initialize IT for stepping through current_buffer in window W
3252 starting at ROW->start. */
3255 init_to_row_start (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3257 init_from_display_pos (it
, w
, &row
->start
);
3258 it
->start
= row
->start
;
3259 it
->continuation_lines_width
= row
->continuation_lines_width
;
3264 /* Initialize IT for stepping through current_buffer in window W
3265 starting in the line following ROW, i.e. starting at ROW->end.
3266 Value is zero if there are overlay strings with newlines at ROW's
3270 init_to_row_end (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3274 if (init_from_display_pos (it
, w
, &row
->end
))
3276 if (row
->continued_p
)
3277 it
->continuation_lines_width
3278 = row
->continuation_lines_width
+ row
->pixel_width
;
3289 /***********************************************************************
3291 ***********************************************************************/
3293 /* Called when IT reaches IT->stop_charpos. Handle text property and
3294 overlay changes. Set IT->stop_charpos to the next position where
3298 handle_stop (struct it
*it
)
3300 enum prop_handled handled
;
3301 int handle_overlay_change_p
;
3305 it
->current
.dpvec_index
= -1;
3306 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3307 it
->ignore_overlay_strings_at_pos_p
= 0;
3310 /* Use face of preceding text for ellipsis (if invisible) */
3311 if (it
->selective_display_ellipsis_p
)
3312 it
->saved_face_id
= it
->face_id
;
3316 handled
= HANDLED_NORMALLY
;
3318 /* Call text property handlers. */
3319 for (p
= it_props
; p
->handler
; ++p
)
3321 handled
= p
->handler (it
);
3323 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3325 else if (handled
== HANDLED_RETURN
)
3327 /* We still want to show before and after strings from
3328 overlays even if the actual buffer text is replaced. */
3329 if (!handle_overlay_change_p
3331 /* Don't call get_overlay_strings_1 if we already
3332 have overlay strings loaded, because doing so
3333 will load them again and push the iterator state
3334 onto the stack one more time, which is not
3335 expected by the rest of the code that processes
3337 || (it
->current
.overlay_string_index
< 0
3338 ? !get_overlay_strings_1 (it
, 0, 0)
3342 setup_for_ellipsis (it
, 0);
3343 /* When handling a display spec, we might load an
3344 empty string. In that case, discard it here. We
3345 used to discard it in handle_single_display_spec,
3346 but that causes get_overlay_strings_1, above, to
3347 ignore overlay strings that we must check. */
3348 if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3352 else if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3356 it
->ignore_overlay_strings_at_pos_p
= 1;
3357 it
->string_from_display_prop_p
= 0;
3358 it
->from_disp_prop_p
= 0;
3359 handle_overlay_change_p
= 0;
3361 handled
= HANDLED_RECOMPUTE_PROPS
;
3364 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3365 handle_overlay_change_p
= 0;
3368 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3370 /* Don't check for overlay strings below when set to deliver
3371 characters from a display vector. */
3372 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3373 handle_overlay_change_p
= 0;
3375 /* Handle overlay changes.
3376 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
3377 if it finds overlays. */
3378 if (handle_overlay_change_p
)
3379 handled
= handle_overlay_change (it
);
3384 setup_for_ellipsis (it
, 0);
3388 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3390 /* Determine where to stop next. */
3391 if (handled
== HANDLED_NORMALLY
)
3392 compute_stop_pos (it
);
3396 /* Compute IT->stop_charpos from text property and overlay change
3397 information for IT's current position. */
3400 compute_stop_pos (struct it
*it
)
3402 register INTERVAL iv
, next_iv
;
3403 Lisp_Object object
, limit
, position
;
3404 ptrdiff_t charpos
, bytepos
;
3406 if (STRINGP (it
->string
))
3408 /* Strings are usually short, so don't limit the search for
3410 it
->stop_charpos
= it
->end_charpos
;
3411 object
= it
->string
;
3413 charpos
= IT_STRING_CHARPOS (*it
);
3414 bytepos
= IT_STRING_BYTEPOS (*it
);
3420 /* If end_charpos is out of range for some reason, such as a
3421 misbehaving display function, rationalize it (Bug#5984). */
3422 if (it
->end_charpos
> ZV
)
3423 it
->end_charpos
= ZV
;
3424 it
->stop_charpos
= it
->end_charpos
;
3426 /* If next overlay change is in front of the current stop pos
3427 (which is IT->end_charpos), stop there. Note: value of
3428 next_overlay_change is point-max if no overlay change
3430 charpos
= IT_CHARPOS (*it
);
3431 bytepos
= IT_BYTEPOS (*it
);
3432 pos
= next_overlay_change (charpos
);
3433 if (pos
< it
->stop_charpos
)
3434 it
->stop_charpos
= pos
;
3436 /* If showing the region, we have to stop at the region
3437 start or end because the face might change there. */
3438 if (it
->region_beg_charpos
> 0)
3440 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
3441 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
3442 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
3443 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3446 /* Set up variables for computing the stop position from text
3447 property changes. */
3448 XSETBUFFER (object
, current_buffer
);
3449 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3452 /* Get the interval containing IT's position. Value is a null
3453 interval if there isn't such an interval. */
3454 position
= make_number (charpos
);
3455 iv
= validate_interval_range (object
, &position
, &position
, 0);
3458 Lisp_Object values_here
[LAST_PROP_IDX
];
3461 /* Get properties here. */
3462 for (p
= it_props
; p
->handler
; ++p
)
3463 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3465 /* Look for an interval following iv that has different
3467 for (next_iv
= next_interval (iv
);
3470 || XFASTINT (limit
) > next_iv
->position
));
3471 next_iv
= next_interval (next_iv
))
3473 for (p
= it_props
; p
->handler
; ++p
)
3475 Lisp_Object new_value
;
3477 new_value
= textget (next_iv
->plist
, *p
->name
);
3478 if (!EQ (values_here
[p
->idx
], new_value
))
3488 if (INTEGERP (limit
)
3489 && next_iv
->position
>= XFASTINT (limit
))
3490 /* No text property change up to limit. */
3491 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3493 /* Text properties change in next_iv. */
3494 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3498 if (it
->cmp_it
.id
< 0)
3500 ptrdiff_t stoppos
= it
->end_charpos
;
3502 if (it
->bidi_p
&& it
->bidi_it
.scan_dir
< 0)
3504 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
,
3505 stoppos
, it
->string
);
3508 eassert (STRINGP (it
->string
)
3509 || (it
->stop_charpos
>= BEGV
3510 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3514 /* Return the position of the next overlay change after POS in
3515 current_buffer. Value is point-max if no overlay change
3516 follows. This is like `next-overlay-change' but doesn't use
3520 next_overlay_change (ptrdiff_t pos
)
3522 ptrdiff_t i
, noverlays
;
3524 Lisp_Object
*overlays
;
3526 /* Get all overlays at the given position. */
3527 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3529 /* If any of these overlays ends before endpos,
3530 use its ending point instead. */
3531 for (i
= 0; i
< noverlays
; ++i
)
3536 oend
= OVERLAY_END (overlays
[i
]);
3537 oendpos
= OVERLAY_POSITION (oend
);
3538 endpos
= min (endpos
, oendpos
);
3544 /* How many characters forward to search for a display property or
3545 display string. Searching too far forward makes the bidi display
3546 sluggish, especially in small windows. */
3547 #define MAX_DISP_SCAN 250
3549 /* Return the character position of a display string at or after
3550 position specified by POSITION. If no display string exists at or
3551 after POSITION, return ZV. A display string is either an overlay
3552 with `display' property whose value is a string, or a `display'
3553 text property whose value is a string. STRING is data about the
3554 string to iterate; if STRING->lstring is nil, we are iterating a
3555 buffer. FRAME_WINDOW_P is non-zero when we are displaying a window
3556 on a GUI frame. DISP_PROP is set to zero if we searched
3557 MAX_DISP_SCAN characters forward without finding any display
3558 strings, non-zero otherwise. It is set to 2 if the display string
3559 uses any kind of `(space ...)' spec that will produce a stretch of
3560 white space in the text area. */
3562 compute_display_string_pos (struct text_pos
*position
,
3563 struct bidi_string_data
*string
,
3565 int frame_window_p
, int *disp_prop
)
3567 /* OBJECT = nil means current buffer. */
3568 Lisp_Object object
, object1
;
3569 Lisp_Object pos
, spec
, limpos
;
3570 int string_p
= (string
&& (STRINGP (string
->lstring
) || string
->s
));
3571 ptrdiff_t eob
= string_p
? string
->schars
: ZV
;
3572 ptrdiff_t begb
= string_p
? 0 : BEGV
;
3573 ptrdiff_t bufpos
, charpos
= CHARPOS (*position
);
3575 (charpos
< eob
- MAX_DISP_SCAN
) ? charpos
+ MAX_DISP_SCAN
: eob
;
3576 struct text_pos tpos
;
3579 if (string
&& STRINGP (string
->lstring
))
3580 object1
= object
= string
->lstring
;
3581 else if (w
&& !string_p
)
3583 XSETWINDOW (object
, w
);
3587 object1
= object
= Qnil
;
3592 /* We don't support display properties whose values are strings
3593 that have display string properties. */
3594 || string
->from_disp_str
3595 /* C strings cannot have display properties. */
3596 || (string
->s
&& !STRINGP (object
)))
3602 /* If the character at CHARPOS is where the display string begins,
3604 pos
= make_number (charpos
);
3605 if (STRINGP (object
))
3606 bufpos
= string
->bufpos
;
3610 if (!NILP (spec
= Fget_char_property (pos
, Qdisplay
, object
))
3612 || !EQ (Fget_char_property (make_number (charpos
- 1), Qdisplay
,
3615 && (rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
, bufpos
,
3623 /* Look forward for the first character with a `display' property
3624 that will replace the underlying text when displayed. */
3625 limpos
= make_number (lim
);
3627 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object1
, limpos
);
3628 CHARPOS (tpos
) = XFASTINT (pos
);
3629 if (CHARPOS (tpos
) >= lim
)
3634 if (STRINGP (object
))
3635 BYTEPOS (tpos
) = string_char_to_byte (object
, CHARPOS (tpos
));
3637 BYTEPOS (tpos
) = CHAR_TO_BYTE (CHARPOS (tpos
));
3638 spec
= Fget_char_property (pos
, Qdisplay
, object
);
3639 if (!STRINGP (object
))
3640 bufpos
= CHARPOS (tpos
);
3641 } while (NILP (spec
)
3642 || !(rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
,
3643 bufpos
, frame_window_p
)));
3647 return CHARPOS (tpos
);
3650 /* Return the character position of the end of the display string that
3651 started at CHARPOS. If there's no display string at CHARPOS,
3652 return -1. A display string is either an overlay with `display'
3653 property whose value is a string or a `display' text property whose
3654 value is a string. */
3656 compute_display_string_end (ptrdiff_t charpos
, struct bidi_string_data
*string
)
3658 /* OBJECT = nil means current buffer. */
3659 Lisp_Object object
=
3660 (string
&& STRINGP (string
->lstring
)) ? string
->lstring
: Qnil
;
3661 Lisp_Object pos
= make_number (charpos
);
3663 (STRINGP (object
) || (string
&& string
->s
)) ? string
->schars
: ZV
;
3665 if (charpos
>= eob
|| (string
->s
&& !STRINGP (object
)))
3668 /* It could happen that the display property or overlay was removed
3669 since we found it in compute_display_string_pos above. One way
3670 this can happen is if JIT font-lock was called (through
3671 handle_fontified_prop), and jit-lock-functions remove text
3672 properties or overlays from the portion of buffer that includes
3673 CHARPOS. Muse mode is known to do that, for example. In this
3674 case, we return -1 to the caller, to signal that no display
3675 string is actually present at CHARPOS. See bidi_fetch_char for
3676 how this is handled.
3678 An alternative would be to never look for display properties past
3679 it->stop_charpos. But neither compute_display_string_pos nor
3680 bidi_fetch_char that calls it know or care where the next
3682 if (NILP (Fget_char_property (pos
, Qdisplay
, object
)))
3685 /* Look forward for the first character where the `display' property
3687 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, Qnil
);
3689 return XFASTINT (pos
);
3694 /***********************************************************************
3696 ***********************************************************************/
3698 /* Handle changes in the `fontified' property of the current buffer by
3699 calling hook functions from Qfontification_functions to fontify
3702 static enum prop_handled
3703 handle_fontified_prop (struct it
*it
)
3705 Lisp_Object prop
, pos
;
3706 enum prop_handled handled
= HANDLED_NORMALLY
;
3708 if (!NILP (Vmemory_full
))
3711 /* Get the value of the `fontified' property at IT's current buffer
3712 position. (The `fontified' property doesn't have a special
3713 meaning in strings.) If the value is nil, call functions from
3714 Qfontification_functions. */
3715 if (!STRINGP (it
->string
)
3717 && !NILP (Vfontification_functions
)
3718 && !NILP (Vrun_hooks
)
3719 && (pos
= make_number (IT_CHARPOS (*it
)),
3720 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3721 /* Ignore the special cased nil value always present at EOB since
3722 no amount of fontifying will be able to change it. */
3723 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3725 ptrdiff_t count
= SPECPDL_INDEX ();
3727 struct buffer
*obuf
= current_buffer
;
3728 int begv
= BEGV
, zv
= ZV
;
3729 int old_clip_changed
= current_buffer
->clip_changed
;
3731 val
= Vfontification_functions
;
3732 specbind (Qfontification_functions
, Qnil
);
3734 eassert (it
->end_charpos
== ZV
);
3736 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3737 safe_call1 (val
, pos
);
3740 Lisp_Object fns
, fn
;
3741 struct gcpro gcpro1
, gcpro2
;
3746 for (; CONSP (val
); val
= XCDR (val
))
3752 /* A value of t indicates this hook has a local
3753 binding; it means to run the global binding too.
3754 In a global value, t should not occur. If it
3755 does, we must ignore it to avoid an endless
3757 for (fns
= Fdefault_value (Qfontification_functions
);
3763 safe_call1 (fn
, pos
);
3767 safe_call1 (fn
, pos
);
3773 unbind_to (count
, Qnil
);
3775 /* Fontification functions routinely call `save-restriction'.
3776 Normally, this tags clip_changed, which can confuse redisplay
3777 (see discussion in Bug#6671). Since we don't perform any
3778 special handling of fontification changes in the case where
3779 `save-restriction' isn't called, there's no point doing so in
3780 this case either. So, if the buffer's restrictions are
3781 actually left unchanged, reset clip_changed. */
3782 if (obuf
== current_buffer
)
3784 if (begv
== BEGV
&& zv
== ZV
)
3785 current_buffer
->clip_changed
= old_clip_changed
;
3787 /* There isn't much we can reasonably do to protect against
3788 misbehaving fontification, but here's a fig leaf. */
3789 else if (BUFFER_LIVE_P (obuf
))
3790 set_buffer_internal_1 (obuf
);
3792 /* The fontification code may have added/removed text.
3793 It could do even a lot worse, but let's at least protect against
3794 the most obvious case where only the text past `pos' gets changed',
3795 as is/was done in grep.el where some escapes sequences are turned
3796 into face properties (bug#7876). */
3797 it
->end_charpos
= ZV
;
3799 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3800 something. This avoids an endless loop if they failed to
3801 fontify the text for which reason ever. */
3802 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3803 handled
= HANDLED_RECOMPUTE_PROPS
;
3811 /***********************************************************************
3813 ***********************************************************************/
3815 /* Set up iterator IT from face properties at its current position.
3816 Called from handle_stop. */
3818 static enum prop_handled
3819 handle_face_prop (struct it
*it
)
3822 ptrdiff_t next_stop
;
3824 if (!STRINGP (it
->string
))
3827 = face_at_buffer_position (it
->w
,
3829 it
->region_beg_charpos
,
3830 it
->region_end_charpos
,
3833 + TEXT_PROP_DISTANCE_LIMIT
),
3834 0, it
->base_face_id
);
3836 /* Is this a start of a run of characters with box face?
3837 Caveat: this can be called for a freshly initialized
3838 iterator; face_id is -1 in this case. We know that the new
3839 face will not change until limit, i.e. if the new face has a
3840 box, all characters up to limit will have one. But, as
3841 usual, we don't know whether limit is really the end. */
3842 if (new_face_id
!= it
->face_id
)
3844 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3845 /* If it->face_id is -1, old_face below will be NULL, see
3846 the definition of FACE_FROM_ID. This will happen if this
3847 is the initial call that gets the face. */
3848 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3850 /* If the value of face_id of the iterator is -1, we have to
3851 look in front of IT's position and see whether there is a
3852 face there that's different from new_face_id. */
3853 if (!old_face
&& IT_CHARPOS (*it
) > BEG
)
3855 int prev_face_id
= face_before_it_pos (it
);
3857 old_face
= FACE_FROM_ID (it
->f
, prev_face_id
);
3860 /* If the new face has a box, but the old face does not,
3861 this is the start of a run of characters with box face,
3862 i.e. this character has a shadow on the left side. */
3863 it
->start_of_box_run_p
= (new_face
->box
!= FACE_NO_BOX
3864 && (old_face
== NULL
|| !old_face
->box
));
3865 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3873 Lisp_Object from_overlay
3874 = (it
->current
.overlay_string_index
>= 0
3875 ? it
->string_overlays
[it
->current
.overlay_string_index
3876 % OVERLAY_STRING_CHUNK_SIZE
]
3879 /* See if we got to this string directly or indirectly from
3880 an overlay property. That includes the before-string or
3881 after-string of an overlay, strings in display properties
3882 provided by an overlay, their text properties, etc.
3884 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3885 if (! NILP (from_overlay
))
3886 for (i
= it
->sp
- 1; i
>= 0; i
--)
3888 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3890 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
3891 % OVERLAY_STRING_CHUNK_SIZE
];
3892 else if (! NILP (it
->stack
[i
].from_overlay
))
3893 from_overlay
= it
->stack
[i
].from_overlay
;
3895 if (!NILP (from_overlay
))
3899 if (! NILP (from_overlay
))
3901 bufpos
= IT_CHARPOS (*it
);
3902 /* For a string from an overlay, the base face depends
3903 only on text properties and ignores overlays. */
3905 = face_for_overlay_string (it
->w
,
3907 it
->region_beg_charpos
,
3908 it
->region_end_charpos
,
3911 + TEXT_PROP_DISTANCE_LIMIT
),
3919 /* For strings from a `display' property, use the face at
3920 IT's current buffer position as the base face to merge
3921 with, so that overlay strings appear in the same face as
3922 surrounding text, unless they specify their own faces.
3923 For strings from wrap-prefix and line-prefix properties,
3924 use the default face, possibly remapped via
3925 Vface_remapping_alist. */
3926 base_face_id
= it
->string_from_prefix_prop_p
3927 ? (!NILP (Vface_remapping_alist
)
3928 ? lookup_basic_face (it
->f
, DEFAULT_FACE_ID
)
3930 : underlying_face_id (it
);
3933 new_face_id
= face_at_string_position (it
->w
,
3935 IT_STRING_CHARPOS (*it
),
3937 it
->region_beg_charpos
,
3938 it
->region_end_charpos
,
3942 /* Is this a start of a run of characters with box? Caveat:
3943 this can be called for a freshly allocated iterator; face_id
3944 is -1 is this case. We know that the new face will not
3945 change until the next check pos, i.e. if the new face has a
3946 box, all characters up to that position will have a
3947 box. But, as usual, we don't know whether that position
3948 is really the end. */
3949 if (new_face_id
!= it
->face_id
)
3951 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3952 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3954 /* If new face has a box but old face hasn't, this is the
3955 start of a run of characters with box, i.e. it has a
3956 shadow on the left side. */
3957 it
->start_of_box_run_p
3958 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3959 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3963 it
->face_id
= new_face_id
;
3964 return HANDLED_NORMALLY
;
3968 /* Return the ID of the face ``underlying'' IT's current position,
3969 which is in a string. If the iterator is associated with a
3970 buffer, return the face at IT's current buffer position.
3971 Otherwise, use the iterator's base_face_id. */
3974 underlying_face_id (struct it
*it
)
3976 int face_id
= it
->base_face_id
, i
;
3978 eassert (STRINGP (it
->string
));
3980 for (i
= it
->sp
- 1; i
>= 0; --i
)
3981 if (NILP (it
->stack
[i
].string
))
3982 face_id
= it
->stack
[i
].face_id
;
3988 /* Compute the face one character before or after the current position
3989 of IT, in the visual order. BEFORE_P non-zero means get the face
3990 in front (to the left in L2R paragraphs, to the right in R2L
3991 paragraphs) of IT's screen position. Value is the ID of the face. */
3994 face_before_or_after_it_pos (struct it
*it
, int before_p
)
3997 ptrdiff_t next_check_charpos
;
3999 void *it_copy_data
= NULL
;
4001 eassert (it
->s
== NULL
);
4003 if (STRINGP (it
->string
))
4005 ptrdiff_t bufpos
, charpos
;
4008 /* No face change past the end of the string (for the case
4009 we are padding with spaces). No face change before the
4011 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
4012 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
4017 /* Set charpos to the position before or after IT's current
4018 position, in the logical order, which in the non-bidi
4019 case is the same as the visual order. */
4021 charpos
= IT_STRING_CHARPOS (*it
) - 1;
4022 else if (it
->what
== IT_COMPOSITION
)
4023 /* For composition, we must check the character after the
4025 charpos
= IT_STRING_CHARPOS (*it
) + it
->cmp_it
.nchars
;
4027 charpos
= IT_STRING_CHARPOS (*it
) + 1;
4033 /* With bidi iteration, the character before the current
4034 in the visual order cannot be found by simple
4035 iteration, because "reverse" reordering is not
4036 supported. Instead, we need to use the move_it_*
4037 family of functions. */
4038 /* Ignore face changes before the first visible
4039 character on this display line. */
4040 if (it
->current_x
<= it
->first_visible_x
)
4042 SAVE_IT (it_copy
, *it
, it_copy_data
);
4043 /* Implementation note: Since move_it_in_display_line
4044 works in the iterator geometry, and thinks the first
4045 character is always the leftmost, even in R2L lines,
4046 we don't need to distinguish between the R2L and L2R
4048 move_it_in_display_line (&it_copy
, SCHARS (it_copy
.string
),
4049 it_copy
.current_x
- 1, MOVE_TO_X
);
4050 charpos
= IT_STRING_CHARPOS (it_copy
);
4051 RESTORE_IT (it
, it
, it_copy_data
);
4055 /* Set charpos to the string position of the character
4056 that comes after IT's current position in the visual
4058 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
4062 bidi_move_to_visually_next (&it_copy
.bidi_it
);
4064 charpos
= it_copy
.bidi_it
.charpos
;
4067 eassert (0 <= charpos
&& charpos
<= SCHARS (it
->string
));
4069 if (it
->current
.overlay_string_index
>= 0)
4070 bufpos
= IT_CHARPOS (*it
);
4074 base_face_id
= underlying_face_id (it
);
4076 /* Get the face for ASCII, or unibyte. */
4077 face_id
= face_at_string_position (it
->w
,
4081 it
->region_beg_charpos
,
4082 it
->region_end_charpos
,
4083 &next_check_charpos
,
4086 /* Correct the face for charsets different from ASCII. Do it
4087 for the multibyte case only. The face returned above is
4088 suitable for unibyte text if IT->string is unibyte. */
4089 if (STRING_MULTIBYTE (it
->string
))
4091 struct text_pos pos1
= string_pos (charpos
, it
->string
);
4092 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos1
);
4094 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
4096 c
= string_char_and_length (p
, &len
);
4097 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, charpos
, it
->string
);
4102 struct text_pos pos
;
4104 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
4105 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
4108 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
4109 pos
= it
->current
.pos
;
4114 DEC_TEXT_POS (pos
, it
->multibyte_p
);
4117 if (it
->what
== IT_COMPOSITION
)
4119 /* For composition, we must check the position after
4121 pos
.charpos
+= it
->cmp_it
.nchars
;
4122 pos
.bytepos
+= it
->len
;
4125 INC_TEXT_POS (pos
, it
->multibyte_p
);
4132 /* With bidi iteration, the character before the current
4133 in the visual order cannot be found by simple
4134 iteration, because "reverse" reordering is not
4135 supported. Instead, we need to use the move_it_*
4136 family of functions. */
4137 /* Ignore face changes before the first visible
4138 character on this display line. */
4139 if (it
->current_x
<= it
->first_visible_x
)
4141 SAVE_IT (it_copy
, *it
, it_copy_data
);
4142 /* Implementation note: Since move_it_in_display_line
4143 works in the iterator geometry, and thinks the first
4144 character is always the leftmost, even in R2L lines,
4145 we don't need to distinguish between the R2L and L2R
4147 move_it_in_display_line (&it_copy
, ZV
,
4148 it_copy
.current_x
- 1, MOVE_TO_X
);
4149 pos
= it_copy
.current
.pos
;
4150 RESTORE_IT (it
, it
, it_copy_data
);
4154 /* Set charpos to the buffer position of the character
4155 that comes after IT's current position in the visual
4157 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
4161 bidi_move_to_visually_next (&it_copy
.bidi_it
);
4164 it_copy
.bidi_it
.charpos
, it_copy
.bidi_it
.bytepos
);
4167 eassert (BEGV
<= CHARPOS (pos
) && CHARPOS (pos
) <= ZV
);
4169 /* Determine face for CHARSET_ASCII, or unibyte. */
4170 face_id
= face_at_buffer_position (it
->w
,
4172 it
->region_beg_charpos
,
4173 it
->region_end_charpos
,
4174 &next_check_charpos
,
4177 /* Correct the face for charsets different from ASCII. Do it
4178 for the multibyte case only. The face returned above is
4179 suitable for unibyte text if current_buffer is unibyte. */
4180 if (it
->multibyte_p
)
4182 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
4183 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
4184 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
4193 /***********************************************************************
4195 ***********************************************************************/
4197 /* Set up iterator IT from invisible properties at its current
4198 position. Called from handle_stop. */
4200 static enum prop_handled
4201 handle_invisible_prop (struct it
*it
)
4203 enum prop_handled handled
= HANDLED_NORMALLY
;
4207 if (STRINGP (it
->string
))
4209 Lisp_Object end_charpos
, limit
, charpos
;
4211 /* Get the value of the invisible text property at the
4212 current position. Value will be nil if there is no such
4214 charpos
= make_number (IT_STRING_CHARPOS (*it
));
4215 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
4216 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4218 if (invis_p
&& IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
4220 /* Record whether we have to display an ellipsis for the
4222 int display_ellipsis_p
= (invis_p
== 2);
4223 ptrdiff_t len
, endpos
;
4225 handled
= HANDLED_RECOMPUTE_PROPS
;
4227 /* Get the position at which the next visible text can be
4228 found in IT->string, if any. */
4229 endpos
= len
= SCHARS (it
->string
);
4230 XSETINT (limit
, len
);
4233 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
4235 if (INTEGERP (end_charpos
))
4237 endpos
= XFASTINT (end_charpos
);
4238 prop
= Fget_text_property (end_charpos
, Qinvisible
, it
->string
);
4239 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4241 display_ellipsis_p
= 1;
4244 while (invis_p
&& endpos
< len
);
4246 if (display_ellipsis_p
)
4251 /* Text at END_CHARPOS is visible. Move IT there. */
4252 struct text_pos old
;
4255 old
= it
->current
.string_pos
;
4256 oldpos
= CHARPOS (old
);
4259 if (it
->bidi_it
.first_elt
4260 && it
->bidi_it
.charpos
< SCHARS (it
->string
))
4261 bidi_paragraph_init (it
->paragraph_embedding
,
4263 /* Bidi-iterate out of the invisible text. */
4266 bidi_move_to_visually_next (&it
->bidi_it
);
4268 while (oldpos
<= it
->bidi_it
.charpos
4269 && it
->bidi_it
.charpos
< endpos
);
4271 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4272 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4273 if (IT_CHARPOS (*it
) >= endpos
)
4274 it
->prev_stop
= endpos
;
4278 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
4279 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
4284 /* The rest of the string is invisible. If this is an
4285 overlay string, proceed with the next overlay string
4286 or whatever comes and return a character from there. */
4287 if (it
->current
.overlay_string_index
>= 0
4288 && !display_ellipsis_p
)
4290 next_overlay_string (it
);
4291 /* Don't check for overlay strings when we just
4292 finished processing them. */
4293 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
4297 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
4298 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
4305 ptrdiff_t newpos
, next_stop
, start_charpos
, tem
;
4306 Lisp_Object pos
, overlay
;
4308 /* First of all, is there invisible text at this position? */
4309 tem
= start_charpos
= IT_CHARPOS (*it
);
4310 pos
= make_number (tem
);
4311 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
4313 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4315 /* If we are on invisible text, skip over it. */
4316 if (invis_p
&& start_charpos
< it
->end_charpos
)
4318 /* Record whether we have to display an ellipsis for the
4320 int display_ellipsis_p
= invis_p
== 2;
4322 handled
= HANDLED_RECOMPUTE_PROPS
;
4324 /* Loop skipping over invisible text. The loop is left at
4325 ZV or with IT on the first char being visible again. */
4328 /* Try to skip some invisible text. Return value is the
4329 position reached which can be equal to where we start
4330 if there is nothing invisible there. This skips both
4331 over invisible text properties and overlays with
4332 invisible property. */
4333 newpos
= skip_invisible (tem
, &next_stop
, ZV
, it
->window
);
4335 /* If we skipped nothing at all we weren't at invisible
4336 text in the first place. If everything to the end of
4337 the buffer was skipped, end the loop. */
4338 if (newpos
== tem
|| newpos
>= ZV
)
4342 /* We skipped some characters but not necessarily
4343 all there are. Check if we ended up on visible
4344 text. Fget_char_property returns the property of
4345 the char before the given position, i.e. if we
4346 get invis_p = 0, this means that the char at
4347 newpos is visible. */
4348 pos
= make_number (newpos
);
4349 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
4350 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4353 /* If we ended up on invisible text, proceed to
4354 skip starting with next_stop. */
4358 /* If there are adjacent invisible texts, don't lose the
4359 second one's ellipsis. */
4361 display_ellipsis_p
= 1;
4365 /* The position newpos is now either ZV or on visible text. */
4368 ptrdiff_t bpos
= CHAR_TO_BYTE (newpos
);
4370 bpos
== ZV_BYTE
|| FETCH_BYTE (bpos
) == '\n';
4372 newpos
<= BEGV
|| FETCH_BYTE (bpos
- 1) == '\n';
4374 /* If the invisible text ends on a newline or on a
4375 character after a newline, we can avoid the costly,
4376 character by character, bidi iteration to NEWPOS, and
4377 instead simply reseat the iterator there. That's
4378 because all bidi reordering information is tossed at
4379 the newline. This is a big win for modes that hide
4380 complete lines, like Outline, Org, etc. */
4381 if (on_newline
|| after_newline
)
4383 struct text_pos tpos
;
4384 bidi_dir_t pdir
= it
->bidi_it
.paragraph_dir
;
4386 SET_TEXT_POS (tpos
, newpos
, bpos
);
4387 reseat_1 (it
, tpos
, 0);
4388 /* If we reseat on a newline/ZV, we need to prep the
4389 bidi iterator for advancing to the next character
4390 after the newline/EOB, keeping the current paragraph
4391 direction (so that PRODUCE_GLYPHS does TRT wrt
4392 prepending/appending glyphs to a glyph row). */
4395 it
->bidi_it
.first_elt
= 0;
4396 it
->bidi_it
.paragraph_dir
= pdir
;
4397 it
->bidi_it
.ch
= (bpos
== ZV_BYTE
) ? -1 : '\n';
4398 it
->bidi_it
.nchars
= 1;
4399 it
->bidi_it
.ch_len
= 1;
4402 else /* Must use the slow method. */
4404 /* With bidi iteration, the region of invisible text
4405 could start and/or end in the middle of a
4406 non-base embedding level. Therefore, we need to
4407 skip invisible text using the bidi iterator,
4408 starting at IT's current position, until we find
4409 ourselves outside of the invisible text.
4410 Skipping invisible text _after_ bidi iteration
4411 avoids affecting the visual order of the
4412 displayed text when invisible properties are
4413 added or removed. */
4414 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< ZV
)
4416 /* If we were `reseat'ed to a new paragraph,
4417 determine the paragraph base direction. We
4418 need to do it now because
4419 next_element_from_buffer may not have a
4420 chance to do it, if we are going to skip any
4421 text at the beginning, which resets the
4423 bidi_paragraph_init (it
->paragraph_embedding
,
4428 bidi_move_to_visually_next (&it
->bidi_it
);
4430 while (it
->stop_charpos
<= it
->bidi_it
.charpos
4431 && it
->bidi_it
.charpos
< newpos
);
4432 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4433 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4434 /* If we overstepped NEWPOS, record its position in
4435 the iterator, so that we skip invisible text if
4436 later the bidi iteration lands us in the
4437 invisible region again. */
4438 if (IT_CHARPOS (*it
) >= newpos
)
4439 it
->prev_stop
= newpos
;
4444 IT_CHARPOS (*it
) = newpos
;
4445 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
4448 /* If there are before-strings at the start of invisible
4449 text, and the text is invisible because of a text
4450 property, arrange to show before-strings because 20.x did
4451 it that way. (If the text is invisible because of an
4452 overlay property instead of a text property, this is
4453 already handled in the overlay code.) */
4455 && get_overlay_strings (it
, it
->stop_charpos
))
4457 handled
= HANDLED_RECOMPUTE_PROPS
;
4458 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
4460 else if (display_ellipsis_p
)
4462 /* Make sure that the glyphs of the ellipsis will get
4463 correct `charpos' values. If we would not update
4464 it->position here, the glyphs would belong to the
4465 last visible character _before_ the invisible
4466 text, which confuses `set_cursor_from_row'.
4468 We use the last invisible position instead of the
4469 first because this way the cursor is always drawn on
4470 the first "." of the ellipsis, whenever PT is inside
4471 the invisible text. Otherwise the cursor would be
4472 placed _after_ the ellipsis when the point is after the
4473 first invisible character. */
4474 if (!STRINGP (it
->object
))
4476 it
->position
.charpos
= newpos
- 1;
4477 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
4480 /* Let the ellipsis display before
4481 considering any properties of the following char.
4482 Fixes jasonr@gnu.org 01 Oct 07 bug. */
4483 handled
= HANDLED_RETURN
;
4492 /* Make iterator IT return `...' next.
4493 Replaces LEN characters from buffer. */
4496 setup_for_ellipsis (struct it
*it
, int len
)
4498 /* Use the display table definition for `...'. Invalid glyphs
4499 will be handled by the method returning elements from dpvec. */
4500 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
4502 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
4503 it
->dpvec
= v
->contents
;
4504 it
->dpend
= v
->contents
+ v
->header
.size
;
4508 /* Default `...'. */
4509 it
->dpvec
= default_invis_vector
;
4510 it
->dpend
= default_invis_vector
+ 3;
4513 it
->dpvec_char_len
= len
;
4514 it
->current
.dpvec_index
= 0;
4515 it
->dpvec_face_id
= -1;
4517 /* Remember the current face id in case glyphs specify faces.
4518 IT's face is restored in set_iterator_to_next.
4519 saved_face_id was set to preceding char's face in handle_stop. */
4520 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
4521 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
4523 it
->method
= GET_FROM_DISPLAY_VECTOR
;
4529 /***********************************************************************
4531 ***********************************************************************/
4533 /* Set up iterator IT from `display' property at its current position.
4534 Called from handle_stop.
4535 We return HANDLED_RETURN if some part of the display property
4536 overrides the display of the buffer text itself.
4537 Otherwise we return HANDLED_NORMALLY. */
4539 static enum prop_handled
4540 handle_display_prop (struct it
*it
)
4542 Lisp_Object propval
, object
, overlay
;
4543 struct text_pos
*position
;
4545 /* Nonzero if some property replaces the display of the text itself. */
4546 int display_replaced_p
= 0;
4548 if (STRINGP (it
->string
))
4550 object
= it
->string
;
4551 position
= &it
->current
.string_pos
;
4552 bufpos
= CHARPOS (it
->current
.pos
);
4556 XSETWINDOW (object
, it
->w
);
4557 position
= &it
->current
.pos
;
4558 bufpos
= CHARPOS (*position
);
4561 /* Reset those iterator values set from display property values. */
4562 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
4563 it
->space_width
= Qnil
;
4564 it
->font_height
= Qnil
;
4567 /* We don't support recursive `display' properties, i.e. string
4568 values that have a string `display' property, that have a string
4569 `display' property etc. */
4570 if (!it
->string_from_display_prop_p
)
4571 it
->area
= TEXT_AREA
;
4573 propval
= get_char_property_and_overlay (make_number (position
->charpos
),
4574 Qdisplay
, object
, &overlay
);
4576 return HANDLED_NORMALLY
;
4577 /* Now OVERLAY is the overlay that gave us this property, or nil
4578 if it was a text property. */
4580 if (!STRINGP (it
->string
))
4581 object
= it
->w
->contents
;
4583 display_replaced_p
= handle_display_spec (it
, propval
, object
, overlay
,
4585 FRAME_WINDOW_P (it
->f
));
4587 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
4590 /* Subroutine of handle_display_prop. Returns non-zero if the display
4591 specification in SPEC is a replacing specification, i.e. it would
4592 replace the text covered by `display' property with something else,
4593 such as an image or a display string. If SPEC includes any kind or
4594 `(space ...) specification, the value is 2; this is used by
4595 compute_display_string_pos, which see.
4597 See handle_single_display_spec for documentation of arguments.
4598 frame_window_p is non-zero if the window being redisplayed is on a
4599 GUI frame; this argument is used only if IT is NULL, see below.
4601 IT can be NULL, if this is called by the bidi reordering code
4602 through compute_display_string_pos, which see. In that case, this
4603 function only examines SPEC, but does not otherwise "handle" it, in
4604 the sense that it doesn't set up members of IT from the display
4607 handle_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4608 Lisp_Object overlay
, struct text_pos
*position
,
4609 ptrdiff_t bufpos
, int frame_window_p
)
4611 int replacing_p
= 0;
4615 /* Simple specifications. */
4616 && !EQ (XCAR (spec
), Qimage
)
4617 #ifdef HAVE_XWIDGETS
4618 && !EQ (XCAR (spec
), Qxwidget
)
4620 && !EQ (XCAR (spec
), Qspace
)
4621 && !EQ (XCAR (spec
), Qwhen
)
4622 && !EQ (XCAR (spec
), Qslice
)
4623 && !EQ (XCAR (spec
), Qspace_width
)
4624 && !EQ (XCAR (spec
), Qheight
)
4625 && !EQ (XCAR (spec
), Qraise
)
4626 /* Marginal area specifications. */
4627 && !(CONSP (XCAR (spec
)) && EQ (XCAR (XCAR (spec
)), Qmargin
))
4628 && !EQ (XCAR (spec
), Qleft_fringe
)
4629 && !EQ (XCAR (spec
), Qright_fringe
)
4630 && !NILP (XCAR (spec
)))
4632 for (; CONSP (spec
); spec
= XCDR (spec
))
4634 if ((rv
= handle_single_display_spec (it
, XCAR (spec
), object
,
4635 overlay
, position
, bufpos
,
4636 replacing_p
, frame_window_p
)))
4639 /* If some text in a string is replaced, `position' no
4640 longer points to the position of `object'. */
4641 if (!it
|| STRINGP (object
))
4646 else if (VECTORP (spec
))
4649 for (i
= 0; i
< ASIZE (spec
); ++i
)
4650 if ((rv
= handle_single_display_spec (it
, AREF (spec
, i
), object
,
4651 overlay
, position
, bufpos
,
4652 replacing_p
, frame_window_p
)))
4655 /* If some text in a string is replaced, `position' no
4656 longer points to the position of `object'. */
4657 if (!it
|| STRINGP (object
))
4663 if ((rv
= handle_single_display_spec (it
, spec
, object
, overlay
,
4664 position
, bufpos
, 0,
4672 /* Value is the position of the end of the `display' property starting
4673 at START_POS in OBJECT. */
4675 static struct text_pos
4676 display_prop_end (struct it
*it
, Lisp_Object object
, struct text_pos start_pos
)
4679 struct text_pos end_pos
;
4681 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
4682 Qdisplay
, object
, Qnil
);
4683 CHARPOS (end_pos
) = XFASTINT (end
);
4684 if (STRINGP (object
))
4685 compute_string_pos (&end_pos
, start_pos
, it
->string
);
4687 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
4693 /* Set up IT from a single `display' property specification SPEC. OBJECT
4694 is the object in which the `display' property was found. *POSITION
4695 is the position in OBJECT at which the `display' property was found.
4696 BUFPOS is the buffer position of OBJECT (different from POSITION if
4697 OBJECT is not a buffer). DISPLAY_REPLACED_P non-zero means that we
4698 previously saw a display specification which already replaced text
4699 display with something else, for example an image; we ignore such
4700 properties after the first one has been processed.
4702 OVERLAY is the overlay this `display' property came from,
4703 or nil if it was a text property.
4705 If SPEC is a `space' or `image' specification, and in some other
4706 cases too, set *POSITION to the position where the `display'
4709 If IT is NULL, only examine the property specification in SPEC, but
4710 don't set up IT. In that case, FRAME_WINDOW_P non-zero means SPEC
4711 is intended to be displayed in a window on a GUI frame.
4713 Value is non-zero if something was found which replaces the display
4714 of buffer or string text. */
4717 handle_single_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4718 Lisp_Object overlay
, struct text_pos
*position
,
4719 ptrdiff_t bufpos
, int display_replaced_p
,
4723 Lisp_Object location
, value
;
4724 struct text_pos start_pos
= *position
;
4727 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
4728 If the result is non-nil, use VALUE instead of SPEC. */
4730 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4739 if (!NILP (form
) && !EQ (form
, Qt
))
4741 ptrdiff_t count
= SPECPDL_INDEX ();
4742 struct gcpro gcpro1
;
4744 /* Bind `object' to the object having the `display' property, a
4745 buffer or string. Bind `position' to the position in the
4746 object where the property was found, and `buffer-position'
4747 to the current position in the buffer. */
4750 XSETBUFFER (object
, current_buffer
);
4751 specbind (Qobject
, object
);
4752 specbind (Qposition
, make_number (CHARPOS (*position
)));
4753 specbind (Qbuffer_position
, make_number (bufpos
));
4755 form
= safe_eval (form
);
4757 unbind_to (count
, Qnil
);
4763 /* Handle `(height HEIGHT)' specifications. */
4765 && EQ (XCAR (spec
), Qheight
)
4766 && CONSP (XCDR (spec
)))
4770 if (!FRAME_WINDOW_P (it
->f
))
4773 it
->font_height
= XCAR (XCDR (spec
));
4774 if (!NILP (it
->font_height
))
4776 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4777 int new_height
= -1;
4779 if (CONSP (it
->font_height
)
4780 && (EQ (XCAR (it
->font_height
), Qplus
)
4781 || EQ (XCAR (it
->font_height
), Qminus
))
4782 && CONSP (XCDR (it
->font_height
))
4783 && RANGED_INTEGERP (0, XCAR (XCDR (it
->font_height
)), INT_MAX
))
4785 /* `(+ N)' or `(- N)' where N is an integer. */
4786 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4787 if (EQ (XCAR (it
->font_height
), Qplus
))
4789 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4791 else if (FUNCTIONP (it
->font_height
))
4793 /* Call function with current height as argument.
4794 Value is the new height. */
4796 height
= safe_call1 (it
->font_height
,
4797 face
->lface
[LFACE_HEIGHT_INDEX
]);
4798 if (NUMBERP (height
))
4799 new_height
= XFLOATINT (height
);
4801 else if (NUMBERP (it
->font_height
))
4803 /* Value is a multiple of the canonical char height. */
4806 f
= FACE_FROM_ID (it
->f
,
4807 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4808 new_height
= (XFLOATINT (it
->font_height
)
4809 * XINT (f
->lface
[LFACE_HEIGHT_INDEX
]));
4813 /* Evaluate IT->font_height with `height' bound to the
4814 current specified height to get the new height. */
4815 ptrdiff_t count
= SPECPDL_INDEX ();
4817 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4818 value
= safe_eval (it
->font_height
);
4819 unbind_to (count
, Qnil
);
4821 if (NUMBERP (value
))
4822 new_height
= XFLOATINT (value
);
4826 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4833 /* Handle `(space-width WIDTH)'. */
4835 && EQ (XCAR (spec
), Qspace_width
)
4836 && CONSP (XCDR (spec
)))
4840 if (!FRAME_WINDOW_P (it
->f
))
4843 value
= XCAR (XCDR (spec
));
4844 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4845 it
->space_width
= value
;
4851 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4853 && EQ (XCAR (spec
), Qslice
))
4859 if (!FRAME_WINDOW_P (it
->f
))
4862 if (tem
= XCDR (spec
), CONSP (tem
))
4864 it
->slice
.x
= XCAR (tem
);
4865 if (tem
= XCDR (tem
), CONSP (tem
))
4867 it
->slice
.y
= XCAR (tem
);
4868 if (tem
= XCDR (tem
), CONSP (tem
))
4870 it
->slice
.width
= XCAR (tem
);
4871 if (tem
= XCDR (tem
), CONSP (tem
))
4872 it
->slice
.height
= XCAR (tem
);
4881 /* Handle `(raise FACTOR)'. */
4883 && EQ (XCAR (spec
), Qraise
)
4884 && CONSP (XCDR (spec
)))
4888 if (!FRAME_WINDOW_P (it
->f
))
4891 #ifdef HAVE_WINDOW_SYSTEM
4892 value
= XCAR (XCDR (spec
));
4893 if (NUMBERP (value
))
4895 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4896 it
->voffset
= - (XFLOATINT (value
)
4897 * (FONT_HEIGHT (face
->font
)));
4899 #endif /* HAVE_WINDOW_SYSTEM */
4905 /* Don't handle the other kinds of display specifications
4906 inside a string that we got from a `display' property. */
4907 if (it
&& it
->string_from_display_prop_p
)
4910 /* Characters having this form of property are not displayed, so
4911 we have to find the end of the property. */
4914 start_pos
= *position
;
4915 *position
= display_prop_end (it
, object
, start_pos
);
4919 /* Stop the scan at that end position--we assume that all
4920 text properties change there. */
4922 it
->stop_charpos
= position
->charpos
;
4924 /* Handle `(left-fringe BITMAP [FACE])'
4925 and `(right-fringe BITMAP [FACE])'. */
4927 && (EQ (XCAR (spec
), Qleft_fringe
)
4928 || EQ (XCAR (spec
), Qright_fringe
))
4929 && CONSP (XCDR (spec
)))
4935 if (!FRAME_WINDOW_P (it
->f
))
4936 /* If we return here, POSITION has been advanced
4937 across the text with this property. */
4939 /* Synchronize the bidi iterator with POSITION. This is
4940 needed because we are not going to push the iterator
4941 on behalf of this display property, so there will be
4942 no pop_it call to do this synchronization for us. */
4945 it
->position
= *position
;
4946 iterate_out_of_display_property (it
);
4947 *position
= it
->position
;
4952 else if (!frame_window_p
)
4955 #ifdef HAVE_WINDOW_SYSTEM
4956 value
= XCAR (XCDR (spec
));
4957 if (!SYMBOLP (value
)
4958 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4959 /* If we return here, POSITION has been advanced
4960 across the text with this property. */
4962 if (it
&& it
->bidi_p
)
4964 it
->position
= *position
;
4965 iterate_out_of_display_property (it
);
4966 *position
= it
->position
;
4973 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);;
4975 if (CONSP (XCDR (XCDR (spec
))))
4977 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4978 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4984 /* Save current settings of IT so that we can restore them
4985 when we are finished with the glyph property value. */
4986 push_it (it
, position
);
4988 it
->area
= TEXT_AREA
;
4989 it
->what
= IT_IMAGE
;
4990 it
->image_id
= -1; /* no image */
4991 it
->position
= start_pos
;
4992 it
->object
= NILP (object
) ? it
->w
->contents
: object
;
4993 it
->method
= GET_FROM_IMAGE
;
4994 it
->from_overlay
= Qnil
;
4995 it
->face_id
= face_id
;
4996 it
->from_disp_prop_p
= 1;
4998 /* Say that we haven't consumed the characters with
4999 `display' property yet. The call to pop_it in
5000 set_iterator_to_next will clean this up. */
5001 *position
= start_pos
;
5003 if (EQ (XCAR (spec
), Qleft_fringe
))
5005 it
->left_user_fringe_bitmap
= fringe_bitmap
;
5006 it
->left_user_fringe_face_id
= face_id
;
5010 it
->right_user_fringe_bitmap
= fringe_bitmap
;
5011 it
->right_user_fringe_face_id
= face_id
;
5014 #endif /* HAVE_WINDOW_SYSTEM */
5018 /* Prepare to handle `((margin left-margin) ...)',
5019 `((margin right-margin) ...)' and `((margin nil) ...)'
5020 prefixes for display specifications. */
5021 location
= Qunbound
;
5022 if (CONSP (spec
) && CONSP (XCAR (spec
)))
5026 value
= XCDR (spec
);
5028 value
= XCAR (value
);
5031 if (EQ (XCAR (tem
), Qmargin
)
5032 && (tem
= XCDR (tem
),
5033 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
5035 || EQ (tem
, Qleft_margin
)
5036 || EQ (tem
, Qright_margin
))))
5040 if (EQ (location
, Qunbound
))
5046 /* After this point, VALUE is the property after any
5047 margin prefix has been stripped. It must be a string,
5048 an image specification, or `(space ...)'.
5050 LOCATION specifies where to display: `left-margin',
5051 `right-margin' or nil. */
5053 valid_p
= (STRINGP (value
)
5054 #ifdef HAVE_WINDOW_SYSTEM
5055 || ((it
? FRAME_WINDOW_P (it
->f
) : frame_window_p
)
5056 && valid_image_p (value
))
5057 #endif /* not HAVE_WINDOW_SYSTEM */
5058 || (CONSP (value
) && EQ (XCAR (value
), Qspace
))
5059 #ifdef HAVE_XWIDGETS
5060 || valid_xwidget_spec_p(value
)
5064 if (valid_p
&& !display_replaced_p
)
5070 /* Callers need to know whether the display spec is any kind
5071 of `(space ...)' spec that is about to affect text-area
5073 if (CONSP (value
) && EQ (XCAR (value
), Qspace
) && NILP (location
))
5078 /* Save current settings of IT so that we can restore them
5079 when we are finished with the glyph property value. */
5080 push_it (it
, position
);
5081 it
->from_overlay
= overlay
;
5082 it
->from_disp_prop_p
= 1;
5084 if (NILP (location
))
5085 it
->area
= TEXT_AREA
;
5086 else if (EQ (location
, Qleft_margin
))
5087 it
->area
= LEFT_MARGIN_AREA
;
5089 it
->area
= RIGHT_MARGIN_AREA
;
5091 if (STRINGP (value
))
5094 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5095 it
->current
.overlay_string_index
= -1;
5096 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5097 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
5098 it
->method
= GET_FROM_STRING
;
5099 it
->stop_charpos
= 0;
5101 it
->base_level_stop
= 0;
5102 it
->string_from_display_prop_p
= 1;
5103 /* Say that we haven't consumed the characters with
5104 `display' property yet. The call to pop_it in
5105 set_iterator_to_next will clean this up. */
5106 if (BUFFERP (object
))
5107 *position
= start_pos
;
5109 /* Force paragraph direction to be that of the parent
5110 object. If the parent object's paragraph direction is
5111 not yet determined, default to L2R. */
5112 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
5113 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5115 it
->paragraph_embedding
= L2R
;
5117 /* Set up the bidi iterator for this display string. */
5120 it
->bidi_it
.string
.lstring
= it
->string
;
5121 it
->bidi_it
.string
.s
= NULL
;
5122 it
->bidi_it
.string
.schars
= it
->end_charpos
;
5123 it
->bidi_it
.string
.bufpos
= bufpos
;
5124 it
->bidi_it
.string
.from_disp_str
= 1;
5125 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5126 it
->bidi_it
.w
= it
->w
;
5127 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5130 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
5132 it
->method
= GET_FROM_STRETCH
;
5134 *position
= it
->position
= start_pos
;
5135 retval
= 1 + (it
->area
== TEXT_AREA
);
5137 #ifdef HAVE_XWIDGETS
5138 else if (valid_xwidget_spec_p(value
))
5140 //printf("handle_single_display_spec: im an xwidget!!\n");
5141 it
->what
= IT_XWIDGET
;
5142 it
->method
= GET_FROM_XWIDGET
;
5143 it
->position
= start_pos
;
5144 it
->object
= NILP (object
) ? it
->w
->contents
: object
;
5145 *position
= start_pos
;
5147 it
->xwidget
= lookup_xwidget(value
);
5150 #ifdef HAVE_WINDOW_SYSTEM
5153 it
->what
= IT_IMAGE
;
5154 it
->image_id
= lookup_image (it
->f
, value
);
5155 it
->position
= start_pos
;
5156 it
->object
= NILP (object
) ? it
->w
->contents
: object
;
5157 it
->method
= GET_FROM_IMAGE
;
5159 /* Say that we haven't consumed the characters with
5160 `display' property yet. The call to pop_it in
5161 set_iterator_to_next will clean this up. */
5162 *position
= start_pos
;
5164 #endif /* HAVE_WINDOW_SYSTEM */
5169 /* Invalid property or property not supported. Restore
5170 POSITION to what it was before. */
5171 *position
= start_pos
;
5175 /* Check if PROP is a display property value whose text should be
5176 treated as intangible. OVERLAY is the overlay from which PROP
5177 came, or nil if it came from a text property. CHARPOS and BYTEPOS
5178 specify the buffer position covered by PROP. */
5181 display_prop_intangible_p (Lisp_Object prop
, Lisp_Object overlay
,
5182 ptrdiff_t charpos
, ptrdiff_t bytepos
)
5184 int frame_window_p
= FRAME_WINDOW_P (XFRAME (selected_frame
));
5185 struct text_pos position
;
5187 SET_TEXT_POS (position
, charpos
, bytepos
);
5188 return handle_display_spec (NULL
, prop
, Qnil
, overlay
,
5189 &position
, charpos
, frame_window_p
);
5193 /* Return 1 if PROP is a display sub-property value containing STRING.
5195 Implementation note: this and the following function are really
5196 special cases of handle_display_spec and
5197 handle_single_display_spec, and should ideally use the same code.
5198 Until they do, these two pairs must be consistent and must be
5199 modified in sync. */
5202 single_display_spec_string_p (Lisp_Object prop
, Lisp_Object string
)
5204 if (EQ (string
, prop
))
5207 /* Skip over `when FORM'. */
5208 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
5213 /* Actually, the condition following `when' should be eval'ed,
5214 like handle_single_display_spec does, and we should return
5215 zero if it evaluates to nil. However, this function is
5216 called only when the buffer was already displayed and some
5217 glyph in the glyph matrix was found to come from a display
5218 string. Therefore, the condition was already evaluated, and
5219 the result was non-nil, otherwise the display string wouldn't
5220 have been displayed and we would have never been called for
5221 this property. Thus, we can skip the evaluation and assume
5222 its result is non-nil. */
5227 /* Skip over `margin LOCATION'. */
5228 if (EQ (XCAR (prop
), Qmargin
))
5239 return EQ (prop
, string
) || (CONSP (prop
) && EQ (XCAR (prop
), string
));
5243 /* Return 1 if STRING appears in the `display' property PROP. */
5246 display_prop_string_p (Lisp_Object prop
, Lisp_Object string
)
5249 && !EQ (XCAR (prop
), Qwhen
)
5250 && !(CONSP (XCAR (prop
)) && EQ (Qmargin
, XCAR (XCAR (prop
)))))
5252 /* A list of sub-properties. */
5253 while (CONSP (prop
))
5255 if (single_display_spec_string_p (XCAR (prop
), string
))
5260 else if (VECTORP (prop
))
5262 /* A vector of sub-properties. */
5264 for (i
= 0; i
< ASIZE (prop
); ++i
)
5265 if (single_display_spec_string_p (AREF (prop
, i
), string
))
5269 return single_display_spec_string_p (prop
, string
);
5274 /* Look for STRING in overlays and text properties in the current
5275 buffer, between character positions FROM and TO (excluding TO).
5276 BACK_P non-zero means look back (in this case, TO is supposed to be
5278 Value is the first character position where STRING was found, or
5279 zero if it wasn't found before hitting TO.
5281 This function may only use code that doesn't eval because it is
5282 called asynchronously from note_mouse_highlight. */
5285 string_buffer_position_lim (Lisp_Object string
,
5286 ptrdiff_t from
, ptrdiff_t to
, int back_p
)
5288 Lisp_Object limit
, prop
, pos
;
5291 pos
= make_number (max (from
, BEGV
));
5293 if (!back_p
) /* looking forward */
5295 limit
= make_number (min (to
, ZV
));
5296 while (!found
&& !EQ (pos
, limit
))
5298 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5299 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5302 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
,
5306 else /* looking back */
5308 limit
= make_number (max (to
, BEGV
));
5309 while (!found
&& !EQ (pos
, limit
))
5311 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5312 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5315 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
5320 return found
? XINT (pos
) : 0;
5323 /* Determine which buffer position in current buffer STRING comes from.
5324 AROUND_CHARPOS is an approximate position where it could come from.
5325 Value is the buffer position or 0 if it couldn't be determined.
5327 This function is necessary because we don't record buffer positions
5328 in glyphs generated from strings (to keep struct glyph small).
5329 This function may only use code that doesn't eval because it is
5330 called asynchronously from note_mouse_highlight. */
5333 string_buffer_position (Lisp_Object string
, ptrdiff_t around_charpos
)
5335 const int MAX_DISTANCE
= 1000;
5336 ptrdiff_t found
= string_buffer_position_lim (string
, around_charpos
,
5337 around_charpos
+ MAX_DISTANCE
,
5341 found
= string_buffer_position_lim (string
, around_charpos
,
5342 around_charpos
- MAX_DISTANCE
, 1);
5348 /***********************************************************************
5349 `composition' property
5350 ***********************************************************************/
5352 /* Set up iterator IT from `composition' property at its current
5353 position. Called from handle_stop. */
5355 static enum prop_handled
5356 handle_composition_prop (struct it
*it
)
5358 Lisp_Object prop
, string
;
5359 ptrdiff_t pos
, pos_byte
, start
, end
;
5361 if (STRINGP (it
->string
))
5365 pos
= IT_STRING_CHARPOS (*it
);
5366 pos_byte
= IT_STRING_BYTEPOS (*it
);
5367 string
= it
->string
;
5368 s
= SDATA (string
) + pos_byte
;
5369 it
->c
= STRING_CHAR (s
);
5373 pos
= IT_CHARPOS (*it
);
5374 pos_byte
= IT_BYTEPOS (*it
);
5376 it
->c
= FETCH_CHAR (pos_byte
);
5379 /* If there's a valid composition and point is not inside of the
5380 composition (in the case that the composition is from the current
5381 buffer), draw a glyph composed from the composition components. */
5382 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
5383 && composition_valid_p (start
, end
, prop
)
5384 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
5387 /* As we can't handle this situation (perhaps font-lock added
5388 a new composition), we just return here hoping that next
5389 redisplay will detect this composition much earlier. */
5390 return HANDLED_NORMALLY
;
5393 if (STRINGP (it
->string
))
5394 pos_byte
= string_char_to_byte (it
->string
, start
);
5396 pos_byte
= CHAR_TO_BYTE (start
);
5398 it
->cmp_it
.id
= get_composition_id (start
, pos_byte
, end
- start
,
5401 if (it
->cmp_it
.id
>= 0)
5404 it
->cmp_it
.nchars
= COMPOSITION_LENGTH (prop
);
5405 it
->cmp_it
.nglyphs
= -1;
5409 return HANDLED_NORMALLY
;
5414 /***********************************************************************
5416 ***********************************************************************/
5418 /* The following structure is used to record overlay strings for
5419 later sorting in load_overlay_strings. */
5421 struct overlay_entry
5423 Lisp_Object overlay
;
5430 /* Set up iterator IT from overlay strings at its current position.
5431 Called from handle_stop. */
5433 static enum prop_handled
5434 handle_overlay_change (struct it
*it
)
5436 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
5437 return HANDLED_RECOMPUTE_PROPS
;
5439 return HANDLED_NORMALLY
;
5443 /* Set up the next overlay string for delivery by IT, if there is an
5444 overlay string to deliver. Called by set_iterator_to_next when the
5445 end of the current overlay string is reached. If there are more
5446 overlay strings to display, IT->string and
5447 IT->current.overlay_string_index are set appropriately here.
5448 Otherwise IT->string is set to nil. */
5451 next_overlay_string (struct it
*it
)
5453 ++it
->current
.overlay_string_index
;
5454 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
5456 /* No more overlay strings. Restore IT's settings to what
5457 they were before overlay strings were processed, and
5458 continue to deliver from current_buffer. */
5460 it
->ellipsis_p
= (it
->stack
[it
->sp
- 1].display_ellipsis_p
!= 0);
5463 || (NILP (it
->string
)
5464 && it
->method
== GET_FROM_BUFFER
5465 && it
->stop_charpos
>= BEGV
5466 && it
->stop_charpos
<= it
->end_charpos
));
5467 it
->current
.overlay_string_index
= -1;
5468 it
->n_overlay_strings
= 0;
5469 it
->overlay_strings_charpos
= -1;
5470 /* If there's an empty display string on the stack, pop the
5471 stack, to resync the bidi iterator with IT's position. Such
5472 empty strings are pushed onto the stack in
5473 get_overlay_strings_1. */
5474 if (it
->sp
> 0 && STRINGP (it
->string
) && !SCHARS (it
->string
))
5477 /* If we're at the end of the buffer, record that we have
5478 processed the overlay strings there already, so that
5479 next_element_from_buffer doesn't try it again. */
5480 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
5481 it
->overlay_strings_at_end_processed_p
= 1;
5485 /* There are more overlay strings to process. If
5486 IT->current.overlay_string_index has advanced to a position
5487 where we must load IT->overlay_strings with more strings, do
5488 it. We must load at the IT->overlay_strings_charpos where
5489 IT->n_overlay_strings was originally computed; when invisible
5490 text is present, this might not be IT_CHARPOS (Bug#7016). */
5491 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
5493 if (it
->current
.overlay_string_index
&& i
== 0)
5494 load_overlay_strings (it
, it
->overlay_strings_charpos
);
5496 /* Initialize IT to deliver display elements from the overlay
5498 it
->string
= it
->overlay_strings
[i
];
5499 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5500 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
5501 it
->method
= GET_FROM_STRING
;
5502 it
->stop_charpos
= 0;
5503 it
->end_charpos
= SCHARS (it
->string
);
5504 if (it
->cmp_it
.stop_pos
>= 0)
5505 it
->cmp_it
.stop_pos
= 0;
5507 it
->base_level_stop
= 0;
5509 /* Set up the bidi iterator for this overlay string. */
5512 it
->bidi_it
.string
.lstring
= it
->string
;
5513 it
->bidi_it
.string
.s
= NULL
;
5514 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5515 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
5516 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5517 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5518 it
->bidi_it
.w
= it
->w
;
5519 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5527 /* Compare two overlay_entry structures E1 and E2. Used as a
5528 comparison function for qsort in load_overlay_strings. Overlay
5529 strings for the same position are sorted so that
5531 1. All after-strings come in front of before-strings, except
5532 when they come from the same overlay.
5534 2. Within after-strings, strings are sorted so that overlay strings
5535 from overlays with higher priorities come first.
5537 2. Within before-strings, strings are sorted so that overlay
5538 strings from overlays with higher priorities come last.
5540 Value is analogous to strcmp. */
5544 compare_overlay_entries (const void *e1
, const void *e2
)
5546 struct overlay_entry
const *entry1
= e1
;
5547 struct overlay_entry
const *entry2
= e2
;
5550 if (entry1
->after_string_p
!= entry2
->after_string_p
)
5552 /* Let after-strings appear in front of before-strings if
5553 they come from different overlays. */
5554 if (EQ (entry1
->overlay
, entry2
->overlay
))
5555 result
= entry1
->after_string_p
? 1 : -1;
5557 result
= entry1
->after_string_p
? -1 : 1;
5559 else if (entry1
->priority
!= entry2
->priority
)
5561 if (entry1
->after_string_p
)
5562 /* After-strings sorted in order of decreasing priority. */
5563 result
= entry2
->priority
< entry1
->priority
? -1 : 1;
5565 /* Before-strings sorted in order of increasing priority. */
5566 result
= entry1
->priority
< entry2
->priority
? -1 : 1;
5575 /* Load the vector IT->overlay_strings with overlay strings from IT's
5576 current buffer position, or from CHARPOS if that is > 0. Set
5577 IT->n_overlays to the total number of overlay strings found.
5579 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
5580 a time. On entry into load_overlay_strings,
5581 IT->current.overlay_string_index gives the number of overlay
5582 strings that have already been loaded by previous calls to this
5585 IT->add_overlay_start contains an additional overlay start
5586 position to consider for taking overlay strings from, if non-zero.
5587 This position comes into play when the overlay has an `invisible'
5588 property, and both before and after-strings. When we've skipped to
5589 the end of the overlay, because of its `invisible' property, we
5590 nevertheless want its before-string to appear.
5591 IT->add_overlay_start will contain the overlay start position
5594 Overlay strings are sorted so that after-string strings come in
5595 front of before-string strings. Within before and after-strings,
5596 strings are sorted by overlay priority. See also function
5597 compare_overlay_entries. */
5600 load_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5602 Lisp_Object overlay
, window
, str
, invisible
;
5603 struct Lisp_Overlay
*ov
;
5604 ptrdiff_t start
, end
;
5605 ptrdiff_t size
= 20;
5606 ptrdiff_t n
= 0, i
, j
;
5608 struct overlay_entry
*entries
= alloca (size
* sizeof *entries
);
5612 charpos
= IT_CHARPOS (*it
);
5614 /* Append the overlay string STRING of overlay OVERLAY to vector
5615 `entries' which has size `size' and currently contains `n'
5616 elements. AFTER_P non-zero means STRING is an after-string of
5618 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
5621 Lisp_Object priority; \
5625 struct overlay_entry *old = entries; \
5626 SAFE_NALLOCA (entries, 2, size); \
5627 memcpy (entries, old, size * sizeof *entries); \
5631 entries[n].string = (STRING); \
5632 entries[n].overlay = (OVERLAY); \
5633 priority = Foverlay_get ((OVERLAY), Qpriority); \
5634 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
5635 entries[n].after_string_p = (AFTER_P); \
5640 /* Process overlay before the overlay center. */
5641 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
5643 XSETMISC (overlay
, ov
);
5644 eassert (OVERLAYP (overlay
));
5645 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5646 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5651 /* Skip this overlay if it doesn't start or end at IT's current
5653 if (end
!= charpos
&& start
!= charpos
)
5656 /* Skip this overlay if it doesn't apply to IT->w. */
5657 window
= Foverlay_get (overlay
, Qwindow
);
5658 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5661 /* If the text ``under'' the overlay is invisible, both before-
5662 and after-strings from this overlay are visible; start and
5663 end position are indistinguishable. */
5664 invisible
= Foverlay_get (overlay
, Qinvisible
);
5665 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5667 /* If overlay has a non-empty before-string, record it. */
5668 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5669 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5671 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5673 /* If overlay has a non-empty after-string, record it. */
5674 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5675 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5677 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5680 /* Process overlays after the overlay center. */
5681 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
5683 XSETMISC (overlay
, ov
);
5684 eassert (OVERLAYP (overlay
));
5685 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5686 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5688 if (start
> charpos
)
5691 /* Skip this overlay if it doesn't start or end at IT's current
5693 if (end
!= charpos
&& start
!= charpos
)
5696 /* Skip this overlay if it doesn't apply to IT->w. */
5697 window
= Foverlay_get (overlay
, Qwindow
);
5698 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5701 /* If the text ``under'' the overlay is invisible, it has a zero
5702 dimension, and both before- and after-strings apply. */
5703 invisible
= Foverlay_get (overlay
, Qinvisible
);
5704 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5706 /* If overlay has a non-empty before-string, record it. */
5707 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5708 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5710 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5712 /* If overlay has a non-empty after-string, record it. */
5713 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5714 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5716 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5719 #undef RECORD_OVERLAY_STRING
5723 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
5725 /* Record number of overlay strings, and where we computed it. */
5726 it
->n_overlay_strings
= n
;
5727 it
->overlay_strings_charpos
= charpos
;
5729 /* IT->current.overlay_string_index is the number of overlay strings
5730 that have already been consumed by IT. Copy some of the
5731 remaining overlay strings to IT->overlay_strings. */
5733 j
= it
->current
.overlay_string_index
;
5734 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
5736 it
->overlay_strings
[i
] = entries
[j
].string
;
5737 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
5745 /* Get the first chunk of overlay strings at IT's current buffer
5746 position, or at CHARPOS if that is > 0. Value is non-zero if at
5747 least one overlay string was found. */
5750 get_overlay_strings_1 (struct it
*it
, ptrdiff_t charpos
, int compute_stop_p
)
5752 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5753 process. This fills IT->overlay_strings with strings, and sets
5754 IT->n_overlay_strings to the total number of strings to process.
5755 IT->pos.overlay_string_index has to be set temporarily to zero
5756 because load_overlay_strings needs this; it must be set to -1
5757 when no overlay strings are found because a zero value would
5758 indicate a position in the first overlay string. */
5759 it
->current
.overlay_string_index
= 0;
5760 load_overlay_strings (it
, charpos
);
5762 /* If we found overlay strings, set up IT to deliver display
5763 elements from the first one. Otherwise set up IT to deliver
5764 from current_buffer. */
5765 if (it
->n_overlay_strings
)
5767 /* Make sure we know settings in current_buffer, so that we can
5768 restore meaningful values when we're done with the overlay
5771 compute_stop_pos (it
);
5772 eassert (it
->face_id
>= 0);
5774 /* Save IT's settings. They are restored after all overlay
5775 strings have been processed. */
5776 eassert (!compute_stop_p
|| it
->sp
== 0);
5778 /* When called from handle_stop, there might be an empty display
5779 string loaded. In that case, don't bother saving it. But
5780 don't use this optimization with the bidi iterator, since we
5781 need the corresponding pop_it call to resync the bidi
5782 iterator's position with IT's position, after we are done
5783 with the overlay strings. (The corresponding call to pop_it
5784 in case of an empty display string is in
5785 next_overlay_string.) */
5787 && STRINGP (it
->string
) && !SCHARS (it
->string
)))
5790 /* Set up IT to deliver display elements from the first overlay
5792 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5793 it
->string
= it
->overlay_strings
[0];
5794 it
->from_overlay
= Qnil
;
5795 it
->stop_charpos
= 0;
5796 eassert (STRINGP (it
->string
));
5797 it
->end_charpos
= SCHARS (it
->string
);
5799 it
->base_level_stop
= 0;
5800 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5801 it
->method
= GET_FROM_STRING
;
5802 it
->from_disp_prop_p
= 0;
5804 /* Force paragraph direction to be that of the parent
5806 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
5807 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5809 it
->paragraph_embedding
= L2R
;
5811 /* Set up the bidi iterator for this overlay string. */
5814 ptrdiff_t pos
= (charpos
> 0 ? charpos
: IT_CHARPOS (*it
));
5816 it
->bidi_it
.string
.lstring
= it
->string
;
5817 it
->bidi_it
.string
.s
= NULL
;
5818 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5819 it
->bidi_it
.string
.bufpos
= pos
;
5820 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5821 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5822 it
->bidi_it
.w
= it
->w
;
5823 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5828 it
->current
.overlay_string_index
= -1;
5833 get_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5836 it
->method
= GET_FROM_BUFFER
;
5838 (void) get_overlay_strings_1 (it
, charpos
, 1);
5842 /* Value is non-zero if we found at least one overlay string. */
5843 return STRINGP (it
->string
);
5848 /***********************************************************************
5849 Saving and restoring state
5850 ***********************************************************************/
5852 /* Save current settings of IT on IT->stack. Called, for example,
5853 before setting up IT for an overlay string, to be able to restore
5854 IT's settings to what they were after the overlay string has been
5855 processed. If POSITION is non-NULL, it is the position to save on
5856 the stack instead of IT->position. */
5859 push_it (struct it
*it
, struct text_pos
*position
)
5861 struct iterator_stack_entry
*p
;
5863 eassert (it
->sp
< IT_STACK_SIZE
);
5864 p
= it
->stack
+ it
->sp
;
5866 p
->stop_charpos
= it
->stop_charpos
;
5867 p
->prev_stop
= it
->prev_stop
;
5868 p
->base_level_stop
= it
->base_level_stop
;
5869 p
->cmp_it
= it
->cmp_it
;
5870 eassert (it
->face_id
>= 0);
5871 p
->face_id
= it
->face_id
;
5872 p
->string
= it
->string
;
5873 p
->method
= it
->method
;
5874 p
->from_overlay
= it
->from_overlay
;
5877 case GET_FROM_IMAGE
:
5878 p
->u
.image
.object
= it
->object
;
5879 p
->u
.image
.image_id
= it
->image_id
;
5880 p
->u
.image
.slice
= it
->slice
;
5882 case GET_FROM_STRETCH
:
5883 p
->u
.stretch
.object
= it
->object
;
5885 #ifdef HAVE_XWIDGETS
5886 case GET_FROM_XWIDGET
:
5887 p
->u
.xwidget
.object
= it
->object
;
5891 p
->position
= position
? *position
: it
->position
;
5892 p
->current
= it
->current
;
5893 p
->end_charpos
= it
->end_charpos
;
5894 p
->string_nchars
= it
->string_nchars
;
5896 p
->multibyte_p
= it
->multibyte_p
;
5897 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
5898 p
->space_width
= it
->space_width
;
5899 p
->font_height
= it
->font_height
;
5900 p
->voffset
= it
->voffset
;
5901 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5902 p
->string_from_prefix_prop_p
= it
->string_from_prefix_prop_p
;
5903 p
->display_ellipsis_p
= 0;
5904 p
->line_wrap
= it
->line_wrap
;
5905 p
->bidi_p
= it
->bidi_p
;
5906 p
->paragraph_embedding
= it
->paragraph_embedding
;
5907 p
->from_disp_prop_p
= it
->from_disp_prop_p
;
5910 /* Save the state of the bidi iterator as well. */
5912 bidi_push_it (&it
->bidi_it
);
5916 iterate_out_of_display_property (struct it
*it
)
5918 int buffer_p
= !STRINGP (it
->string
);
5919 ptrdiff_t eob
= (buffer_p
? ZV
: it
->end_charpos
);
5920 ptrdiff_t bob
= (buffer_p
? BEGV
: 0);
5922 eassert (eob
>= CHARPOS (it
->position
) && CHARPOS (it
->position
) >= bob
);
5924 /* Maybe initialize paragraph direction. If we are at the beginning
5925 of a new paragraph, next_element_from_buffer may not have a
5926 chance to do that. */
5927 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< eob
)
5928 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
5929 /* prev_stop can be zero, so check against BEGV as well. */
5930 while (it
->bidi_it
.charpos
>= bob
5931 && it
->prev_stop
<= it
->bidi_it
.charpos
5932 && it
->bidi_it
.charpos
< CHARPOS (it
->position
)
5933 && it
->bidi_it
.charpos
< eob
)
5934 bidi_move_to_visually_next (&it
->bidi_it
);
5935 /* Record the stop_pos we just crossed, for when we cross it
5937 if (it
->bidi_it
.charpos
> CHARPOS (it
->position
))
5938 it
->prev_stop
= CHARPOS (it
->position
);
5939 /* If we ended up not where pop_it put us, resync IT's
5940 positional members with the bidi iterator. */
5941 if (it
->bidi_it
.charpos
!= CHARPOS (it
->position
))
5942 SET_TEXT_POS (it
->position
, it
->bidi_it
.charpos
, it
->bidi_it
.bytepos
);
5944 it
->current
.pos
= it
->position
;
5946 it
->current
.string_pos
= it
->position
;
5949 /* Restore IT's settings from IT->stack. Called, for example, when no
5950 more overlay strings must be processed, and we return to delivering
5951 display elements from a buffer, or when the end of a string from a
5952 `display' property is reached and we return to delivering display
5953 elements from an overlay string, or from a buffer. */
5956 pop_it (struct it
*it
)
5958 struct iterator_stack_entry
*p
;
5959 int from_display_prop
= it
->from_disp_prop_p
;
5961 eassert (it
->sp
> 0);
5963 p
= it
->stack
+ it
->sp
;
5964 it
->stop_charpos
= p
->stop_charpos
;
5965 it
->prev_stop
= p
->prev_stop
;
5966 it
->base_level_stop
= p
->base_level_stop
;
5967 it
->cmp_it
= p
->cmp_it
;
5968 it
->face_id
= p
->face_id
;
5969 it
->current
= p
->current
;
5970 it
->position
= p
->position
;
5971 it
->string
= p
->string
;
5972 it
->from_overlay
= p
->from_overlay
;
5973 if (NILP (it
->string
))
5974 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5975 it
->method
= p
->method
;
5978 case GET_FROM_IMAGE
:
5979 it
->image_id
= p
->u
.image
.image_id
;
5980 it
->object
= p
->u
.image
.object
;
5981 it
->slice
= p
->u
.image
.slice
;
5983 #ifdef HAVE_XWIDGETS
5984 case GET_FROM_XWIDGET
:
5985 it
->object
= p
->u
.xwidget
.object
;
5988 case GET_FROM_STRETCH
:
5989 it
->object
= p
->u
.stretch
.object
;
5991 case GET_FROM_BUFFER
:
5992 it
->object
= it
->w
->contents
;
5994 case GET_FROM_STRING
:
5995 it
->object
= it
->string
;
5997 case GET_FROM_DISPLAY_VECTOR
:
5999 it
->method
= GET_FROM_C_STRING
;
6000 else if (STRINGP (it
->string
))
6001 it
->method
= GET_FROM_STRING
;
6004 it
->method
= GET_FROM_BUFFER
;
6005 it
->object
= it
->w
->contents
;
6008 it
->end_charpos
= p
->end_charpos
;
6009 it
->string_nchars
= p
->string_nchars
;
6011 it
->multibyte_p
= p
->multibyte_p
;
6012 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
6013 it
->space_width
= p
->space_width
;
6014 it
->font_height
= p
->font_height
;
6015 it
->voffset
= p
->voffset
;
6016 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
6017 it
->string_from_prefix_prop_p
= p
->string_from_prefix_prop_p
;
6018 it
->line_wrap
= p
->line_wrap
;
6019 it
->bidi_p
= p
->bidi_p
;
6020 it
->paragraph_embedding
= p
->paragraph_embedding
;
6021 it
->from_disp_prop_p
= p
->from_disp_prop_p
;
6024 bidi_pop_it (&it
->bidi_it
);
6025 /* Bidi-iterate until we get out of the portion of text, if any,
6026 covered by a `display' text property or by an overlay with
6027 `display' property. (We cannot just jump there, because the
6028 internal coherency of the bidi iterator state can not be
6029 preserved across such jumps.) We also must determine the
6030 paragraph base direction if the overlay we just processed is
6031 at the beginning of a new paragraph. */
6032 if (from_display_prop
6033 && (it
->method
== GET_FROM_BUFFER
|| it
->method
== GET_FROM_STRING
))
6034 iterate_out_of_display_property (it
);
6036 eassert ((BUFFERP (it
->object
)
6037 && IT_CHARPOS (*it
) == it
->bidi_it
.charpos
6038 && IT_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
6039 || (STRINGP (it
->object
)
6040 && IT_STRING_CHARPOS (*it
) == it
->bidi_it
.charpos
6041 && IT_STRING_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
6042 || (CONSP (it
->object
) && it
->method
== GET_FROM_STRETCH
));
6048 /***********************************************************************
6050 ***********************************************************************/
6052 /* Set IT's current position to the previous line start. */
6055 back_to_previous_line_start (struct it
*it
)
6057 ptrdiff_t cp
= IT_CHARPOS (*it
), bp
= IT_BYTEPOS (*it
);
6060 IT_CHARPOS (*it
) = find_newline_no_quit (cp
, bp
, -1, &IT_BYTEPOS (*it
));
6064 /* Move IT to the next line start.
6066 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
6067 we skipped over part of the text (as opposed to moving the iterator
6068 continuously over the text). Otherwise, don't change the value
6071 If BIDI_IT_PREV is non-NULL, store into it the state of the bidi
6072 iterator on the newline, if it was found.
6074 Newlines may come from buffer text, overlay strings, or strings
6075 displayed via the `display' property. That's the reason we can't
6076 simply use find_newline_no_quit.
6078 Note that this function may not skip over invisible text that is so
6079 because of text properties and immediately follows a newline. If
6080 it would, function reseat_at_next_visible_line_start, when called
6081 from set_iterator_to_next, would effectively make invisible
6082 characters following a newline part of the wrong glyph row, which
6083 leads to wrong cursor motion. */
6086 forward_to_next_line_start (struct it
*it
, int *skipped_p
,
6087 struct bidi_it
*bidi_it_prev
)
6089 ptrdiff_t old_selective
;
6090 int newline_found_p
, n
;
6091 const int MAX_NEWLINE_DISTANCE
= 500;
6093 /* If already on a newline, just consume it to avoid unintended
6094 skipping over invisible text below. */
6095 if (it
->what
== IT_CHARACTER
6097 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
6099 if (it
->bidi_p
&& bidi_it_prev
)
6100 *bidi_it_prev
= it
->bidi_it
;
6101 set_iterator_to_next (it
, 0);
6106 /* Don't handle selective display in the following. It's (a)
6107 unnecessary because it's done by the caller, and (b) leads to an
6108 infinite recursion because next_element_from_ellipsis indirectly
6109 calls this function. */
6110 old_selective
= it
->selective
;
6113 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
6114 from buffer text. */
6115 for (n
= newline_found_p
= 0;
6116 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
6117 n
+= STRINGP (it
->string
) ? 0 : 1)
6119 if (!get_next_display_element (it
))
6121 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
6122 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
6123 *bidi_it_prev
= it
->bidi_it
;
6124 set_iterator_to_next (it
, 0);
6127 /* If we didn't find a newline near enough, see if we can use a
6129 if (!newline_found_p
)
6131 ptrdiff_t bytepos
, start
= IT_CHARPOS (*it
);
6132 ptrdiff_t limit
= find_newline_no_quit (start
, IT_BYTEPOS (*it
),
6136 eassert (!STRINGP (it
->string
));
6138 /* If there isn't any `display' property in sight, and no
6139 overlays, we can just use the position of the newline in
6141 if (it
->stop_charpos
>= limit
6142 || ((pos
= Fnext_single_property_change (make_number (start
),
6144 make_number (limit
)),
6146 && next_overlay_change (start
) == ZV
))
6150 IT_CHARPOS (*it
) = limit
;
6151 IT_BYTEPOS (*it
) = bytepos
;
6155 struct bidi_it bprev
;
6157 /* Help bidi.c avoid expensive searches for display
6158 properties and overlays, by telling it that there are
6159 none up to `limit'. */
6160 if (it
->bidi_it
.disp_pos
< limit
)
6162 it
->bidi_it
.disp_pos
= limit
;
6163 it
->bidi_it
.disp_prop
= 0;
6166 bprev
= it
->bidi_it
;
6167 bidi_move_to_visually_next (&it
->bidi_it
);
6168 } while (it
->bidi_it
.charpos
!= limit
);
6169 IT_CHARPOS (*it
) = limit
;
6170 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6172 *bidi_it_prev
= bprev
;
6174 *skipped_p
= newline_found_p
= 1;
6178 while (get_next_display_element (it
)
6179 && !newline_found_p
)
6181 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
6182 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
6183 *bidi_it_prev
= it
->bidi_it
;
6184 set_iterator_to_next (it
, 0);
6189 it
->selective
= old_selective
;
6190 return newline_found_p
;
6194 /* Set IT's current position to the previous visible line start. Skip
6195 invisible text that is so either due to text properties or due to
6196 selective display. Caution: this does not change IT->current_x and
6200 back_to_previous_visible_line_start (struct it
*it
)
6202 while (IT_CHARPOS (*it
) > BEGV
)
6204 back_to_previous_line_start (it
);
6206 if (IT_CHARPOS (*it
) <= BEGV
)
6209 /* If selective > 0, then lines indented more than its value are
6211 if (it
->selective
> 0
6212 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6216 /* Check the newline before point for invisibility. */
6219 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
6220 Qinvisible
, it
->window
);
6221 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
6225 if (IT_CHARPOS (*it
) <= BEGV
)
6230 void *it2data
= NULL
;
6233 Lisp_Object val
, overlay
;
6235 SAVE_IT (it2
, *it
, it2data
);
6237 /* If newline is part of a composition, continue from start of composition */
6238 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
6239 && beg
< IT_CHARPOS (*it
))
6242 /* If newline is replaced by a display property, find start of overlay
6243 or interval and continue search from that point. */
6244 pos
= --IT_CHARPOS (it2
);
6247 bidi_unshelve_cache (NULL
, 0);
6248 it2
.string_from_display_prop_p
= 0;
6249 it2
.from_disp_prop_p
= 0;
6250 if (handle_display_prop (&it2
) == HANDLED_RETURN
6251 && !NILP (val
= get_char_property_and_overlay
6252 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
6253 && (OVERLAYP (overlay
)
6254 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
6255 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
6257 RESTORE_IT (it
, it
, it2data
);
6261 /* Newline is not replaced by anything -- so we are done. */
6262 RESTORE_IT (it
, it
, it2data
);
6268 IT_CHARPOS (*it
) = beg
;
6269 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
6273 it
->continuation_lines_width
= 0;
6275 eassert (IT_CHARPOS (*it
) >= BEGV
);
6276 eassert (IT_CHARPOS (*it
) == BEGV
6277 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6282 /* Reseat iterator IT at the previous visible line start. Skip
6283 invisible text that is so either due to text properties or due to
6284 selective display. At the end, update IT's overlay information,
6285 face information etc. */
6288 reseat_at_previous_visible_line_start (struct it
*it
)
6290 back_to_previous_visible_line_start (it
);
6291 reseat (it
, it
->current
.pos
, 1);
6296 /* Reseat iterator IT on the next visible line start in the current
6297 buffer. ON_NEWLINE_P non-zero means position IT on the newline
6298 preceding the line start. Skip over invisible text that is so
6299 because of selective display. Compute faces, overlays etc at the
6300 new position. Note that this function does not skip over text that
6301 is invisible because of text properties. */
6304 reseat_at_next_visible_line_start (struct it
*it
, int on_newline_p
)
6306 int newline_found_p
, skipped_p
= 0;
6307 struct bidi_it bidi_it_prev
;
6309 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6311 /* Skip over lines that are invisible because they are indented
6312 more than the value of IT->selective. */
6313 if (it
->selective
> 0)
6314 while (IT_CHARPOS (*it
) < ZV
6315 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6318 eassert (IT_BYTEPOS (*it
) == BEGV
6319 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6321 forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6324 /* Position on the newline if that's what's requested. */
6325 if (on_newline_p
&& newline_found_p
)
6327 if (STRINGP (it
->string
))
6329 if (IT_STRING_CHARPOS (*it
) > 0)
6333 --IT_STRING_CHARPOS (*it
);
6334 --IT_STRING_BYTEPOS (*it
);
6338 /* We need to restore the bidi iterator to the state
6339 it had on the newline, and resync the IT's
6340 position with that. */
6341 it
->bidi_it
= bidi_it_prev
;
6342 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6343 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6347 else if (IT_CHARPOS (*it
) > BEGV
)
6356 /* We need to restore the bidi iterator to the state it
6357 had on the newline and resync IT with that. */
6358 it
->bidi_it
= bidi_it_prev
;
6359 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6360 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6362 reseat (it
, it
->current
.pos
, 0);
6366 reseat (it
, it
->current
.pos
, 0);
6373 /***********************************************************************
6374 Changing an iterator's position
6375 ***********************************************************************/
6377 /* Change IT's current position to POS in current_buffer. If FORCE_P
6378 is non-zero, always check for text properties at the new position.
6379 Otherwise, text properties are only looked up if POS >=
6380 IT->check_charpos of a property. */
6383 reseat (struct it
*it
, struct text_pos pos
, int force_p
)
6385 ptrdiff_t original_pos
= IT_CHARPOS (*it
);
6387 reseat_1 (it
, pos
, 0);
6389 /* Determine where to check text properties. Avoid doing it
6390 where possible because text property lookup is very expensive. */
6392 || CHARPOS (pos
) > it
->stop_charpos
6393 || CHARPOS (pos
) < original_pos
)
6397 /* For bidi iteration, we need to prime prev_stop and
6398 base_level_stop with our best estimations. */
6399 /* Implementation note: Of course, POS is not necessarily a
6400 stop position, so assigning prev_pos to it is a lie; we
6401 should have called compute_stop_backwards. However, if
6402 the current buffer does not include any R2L characters,
6403 that call would be a waste of cycles, because the
6404 iterator will never move back, and thus never cross this
6405 "fake" stop position. So we delay that backward search
6406 until the time we really need it, in next_element_from_buffer. */
6407 if (CHARPOS (pos
) != it
->prev_stop
)
6408 it
->prev_stop
= CHARPOS (pos
);
6409 if (CHARPOS (pos
) < it
->base_level_stop
)
6410 it
->base_level_stop
= 0; /* meaning it's unknown */
6416 it
->prev_stop
= it
->base_level_stop
= 0;
6425 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
6426 IT->stop_pos to POS, also. */
6429 reseat_1 (struct it
*it
, struct text_pos pos
, int set_stop_p
)
6431 /* Don't call this function when scanning a C string. */
6432 eassert (it
->s
== NULL
);
6434 /* POS must be a reasonable value. */
6435 eassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
6437 it
->current
.pos
= it
->position
= pos
;
6438 it
->end_charpos
= ZV
;
6440 it
->current
.dpvec_index
= -1;
6441 it
->current
.overlay_string_index
= -1;
6442 IT_STRING_CHARPOS (*it
) = -1;
6443 IT_STRING_BYTEPOS (*it
) = -1;
6445 it
->method
= GET_FROM_BUFFER
;
6446 it
->object
= it
->w
->contents
;
6447 it
->area
= TEXT_AREA
;
6448 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
6450 it
->string_from_display_prop_p
= 0;
6451 it
->string_from_prefix_prop_p
= 0;
6453 it
->from_disp_prop_p
= 0;
6454 it
->face_before_selective_p
= 0;
6457 bidi_init_it (IT_CHARPOS (*it
), IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6459 bidi_unshelve_cache (NULL
, 0);
6460 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6461 it
->bidi_it
.string
.s
= NULL
;
6462 it
->bidi_it
.string
.lstring
= Qnil
;
6463 it
->bidi_it
.string
.bufpos
= 0;
6464 it
->bidi_it
.string
.unibyte
= 0;
6465 it
->bidi_it
.w
= it
->w
;
6470 it
->stop_charpos
= CHARPOS (pos
);
6471 it
->base_level_stop
= CHARPOS (pos
);
6473 /* This make the information stored in it->cmp_it invalidate. */
6478 /* Set up IT for displaying a string, starting at CHARPOS in window W.
6479 If S is non-null, it is a C string to iterate over. Otherwise,
6480 STRING gives a Lisp string to iterate over.
6482 If PRECISION > 0, don't return more then PRECISION number of
6483 characters from the string.
6485 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
6486 characters have been returned. FIELD_WIDTH < 0 means an infinite
6489 MULTIBYTE = 0 means disable processing of multibyte characters,
6490 MULTIBYTE > 0 means enable it,
6491 MULTIBYTE < 0 means use IT->multibyte_p.
6493 IT must be initialized via a prior call to init_iterator before
6494 calling this function. */
6497 reseat_to_string (struct it
*it
, const char *s
, Lisp_Object string
,
6498 ptrdiff_t charpos
, ptrdiff_t precision
, int field_width
,
6501 /* No region in strings. */
6502 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
6504 /* No text property checks performed by default, but see below. */
6505 it
->stop_charpos
= -1;
6507 /* Set iterator position and end position. */
6508 memset (&it
->current
, 0, sizeof it
->current
);
6509 it
->current
.overlay_string_index
= -1;
6510 it
->current
.dpvec_index
= -1;
6511 eassert (charpos
>= 0);
6513 /* If STRING is specified, use its multibyteness, otherwise use the
6514 setting of MULTIBYTE, if specified. */
6516 it
->multibyte_p
= multibyte
> 0;
6518 /* Bidirectional reordering of strings is controlled by the default
6519 value of bidi-display-reordering. Don't try to reorder while
6520 loading loadup.el, as the necessary character property tables are
6521 not yet available. */
6524 && !NILP (BVAR (&buffer_defaults
, bidi_display_reordering
));
6528 eassert (STRINGP (string
));
6529 it
->string
= string
;
6531 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
6532 it
->method
= GET_FROM_STRING
;
6533 it
->current
.string_pos
= string_pos (charpos
, string
);
6537 it
->bidi_it
.string
.lstring
= string
;
6538 it
->bidi_it
.string
.s
= NULL
;
6539 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6540 it
->bidi_it
.string
.bufpos
= 0;
6541 it
->bidi_it
.string
.from_disp_str
= 0;
6542 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6543 it
->bidi_it
.w
= it
->w
;
6544 bidi_init_it (charpos
, IT_STRING_BYTEPOS (*it
),
6545 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
6550 it
->s
= (const unsigned char *) s
;
6553 /* Note that we use IT->current.pos, not it->current.string_pos,
6554 for displaying C strings. */
6555 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
6556 if (it
->multibyte_p
)
6558 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
6559 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
6563 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
6564 it
->end_charpos
= it
->string_nchars
= strlen (s
);
6569 it
->bidi_it
.string
.lstring
= Qnil
;
6570 it
->bidi_it
.string
.s
= (const unsigned char *) s
;
6571 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6572 it
->bidi_it
.string
.bufpos
= 0;
6573 it
->bidi_it
.string
.from_disp_str
= 0;
6574 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6575 it
->bidi_it
.w
= it
->w
;
6576 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6579 it
->method
= GET_FROM_C_STRING
;
6582 /* PRECISION > 0 means don't return more than PRECISION characters
6584 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
6586 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
6588 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6591 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
6592 characters have been returned. FIELD_WIDTH == 0 means don't pad,
6593 FIELD_WIDTH < 0 means infinite field width. This is useful for
6594 padding with `-' at the end of a mode line. */
6595 if (field_width
< 0)
6596 field_width
= INFINITY
;
6597 /* Implementation note: We deliberately don't enlarge
6598 it->bidi_it.string.schars here to fit it->end_charpos, because
6599 the bidi iterator cannot produce characters out of thin air. */
6600 if (field_width
> it
->end_charpos
- charpos
)
6601 it
->end_charpos
= charpos
+ field_width
;
6603 /* Use the standard display table for displaying strings. */
6604 if (DISP_TABLE_P (Vstandard_display_table
))
6605 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
6607 it
->stop_charpos
= charpos
;
6608 it
->prev_stop
= charpos
;
6609 it
->base_level_stop
= 0;
6612 it
->bidi_it
.first_elt
= 1;
6613 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6614 it
->bidi_it
.disp_pos
= -1;
6616 if (s
== NULL
&& it
->multibyte_p
)
6618 ptrdiff_t endpos
= SCHARS (it
->string
);
6619 if (endpos
> it
->end_charpos
)
6620 endpos
= it
->end_charpos
;
6621 composition_compute_stop_pos (&it
->cmp_it
, charpos
, -1, endpos
,
6629 /***********************************************************************
6631 ***********************************************************************/
6633 /* Map enum it_method value to corresponding next_element_from_* function. */
6635 static int (* get_next_element
[NUM_IT_METHODS
]) (struct it
*it
) =
6637 next_element_from_buffer
,
6638 next_element_from_display_vector
,
6639 next_element_from_string
,
6640 next_element_from_c_string
,
6641 next_element_from_image
,
6642 next_element_from_stretch
6643 #ifdef HAVE_XWIDGETS
6644 ,next_element_from_xwidget
6648 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
6651 /* Return 1 iff a character at CHARPOS (and BYTEPOS) is composed
6652 (possibly with the following characters). */
6654 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS,END_CHARPOS) \
6655 ((IT)->cmp_it.id >= 0 \
6656 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
6657 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
6658 END_CHARPOS, (IT)->w, \
6659 FACE_FROM_ID ((IT)->f, (IT)->face_id), \
6663 /* Lookup the char-table Vglyphless_char_display for character C (-1
6664 if we want information for no-font case), and return the display
6665 method symbol. By side-effect, update it->what and
6666 it->glyphless_method. This function is called from
6667 get_next_display_element for each character element, and from
6668 x_produce_glyphs when no suitable font was found. */
6671 lookup_glyphless_char_display (int c
, struct it
*it
)
6673 Lisp_Object glyphless_method
= Qnil
;
6675 if (CHAR_TABLE_P (Vglyphless_char_display
)
6676 && CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
)) >= 1)
6680 glyphless_method
= CHAR_TABLE_REF (Vglyphless_char_display
, c
);
6681 if (CONSP (glyphless_method
))
6682 glyphless_method
= FRAME_WINDOW_P (it
->f
)
6683 ? XCAR (glyphless_method
)
6684 : XCDR (glyphless_method
);
6687 glyphless_method
= XCHAR_TABLE (Vglyphless_char_display
)->extras
[0];
6691 if (NILP (glyphless_method
))
6694 /* The default is to display the character by a proper font. */
6696 /* The default for the no-font case is to display an empty box. */
6697 glyphless_method
= Qempty_box
;
6699 if (EQ (glyphless_method
, Qzero_width
))
6702 return glyphless_method
;
6703 /* This method can't be used for the no-font case. */
6704 glyphless_method
= Qempty_box
;
6706 if (EQ (glyphless_method
, Qthin_space
))
6707 it
->glyphless_method
= GLYPHLESS_DISPLAY_THIN_SPACE
;
6708 else if (EQ (glyphless_method
, Qempty_box
))
6709 it
->glyphless_method
= GLYPHLESS_DISPLAY_EMPTY_BOX
;
6710 else if (EQ (glyphless_method
, Qhex_code
))
6711 it
->glyphless_method
= GLYPHLESS_DISPLAY_HEX_CODE
;
6712 else if (STRINGP (glyphless_method
))
6713 it
->glyphless_method
= GLYPHLESS_DISPLAY_ACRONYM
;
6716 /* Invalid value. We use the default method. */
6717 glyphless_method
= Qnil
;
6720 it
->what
= IT_GLYPHLESS
;
6721 return glyphless_method
;
6724 /* Load IT's display element fields with information about the next
6725 display element from the current position of IT. Value is zero if
6726 end of buffer (or C string) is reached. */
6728 static struct frame
*last_escape_glyph_frame
= NULL
;
6729 static int last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
6730 static int last_escape_glyph_merged_face_id
= 0;
6732 struct frame
*last_glyphless_glyph_frame
= NULL
;
6733 int last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
6734 int last_glyphless_glyph_merged_face_id
= 0;
6737 get_next_display_element (struct it
*it
)
6739 /* Non-zero means that we found a display element. Zero means that
6740 we hit the end of what we iterate over. Performance note: the
6741 function pointer `method' used here turns out to be faster than
6742 using a sequence of if-statements. */
6746 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6748 if (it
->what
== IT_CHARACTER
)
6750 /* UAX#9, L4: "A character is depicted by a mirrored glyph if
6751 and only if (a) the resolved directionality of that character
6753 /* FIXME: Do we need an exception for characters from display
6755 if (it
->bidi_p
&& it
->bidi_it
.type
== STRONG_R
)
6756 it
->c
= bidi_mirror_char (it
->c
);
6757 /* Map via display table or translate control characters.
6758 IT->c, IT->len etc. have been set to the next character by
6759 the function call above. If we have a display table, and it
6760 contains an entry for IT->c, translate it. Don't do this if
6761 IT->c itself comes from a display table, otherwise we could
6762 end up in an infinite recursion. (An alternative could be to
6763 count the recursion depth of this function and signal an
6764 error when a certain maximum depth is reached.) Is it worth
6766 if (success_p
&& it
->dpvec
== NULL
)
6769 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
6770 int nonascii_space_p
= 0;
6771 int nonascii_hyphen_p
= 0;
6772 int c
= it
->c
; /* This is the character to display. */
6774 if (! it
->multibyte_p
&& ! ASCII_CHAR_P (c
))
6776 eassert (SINGLE_BYTE_CHAR_P (c
));
6777 if (unibyte_display_via_language_environment
)
6779 c
= DECODE_CHAR (unibyte
, c
);
6781 c
= BYTE8_TO_CHAR (it
->c
);
6784 c
= BYTE8_TO_CHAR (it
->c
);
6788 && (dv
= DISP_CHAR_VECTOR (it
->dp
, c
),
6791 struct Lisp_Vector
*v
= XVECTOR (dv
);
6793 /* Return the first character from the display table
6794 entry, if not empty. If empty, don't display the
6795 current character. */
6798 it
->dpvec_char_len
= it
->len
;
6799 it
->dpvec
= v
->contents
;
6800 it
->dpend
= v
->contents
+ v
->header
.size
;
6801 it
->current
.dpvec_index
= 0;
6802 it
->dpvec_face_id
= -1;
6803 it
->saved_face_id
= it
->face_id
;
6804 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6809 set_iterator_to_next (it
, 0);
6814 if (! NILP (lookup_glyphless_char_display (c
, it
)))
6816 if (it
->what
== IT_GLYPHLESS
)
6818 /* Don't display this character. */
6819 set_iterator_to_next (it
, 0);
6823 /* If `nobreak-char-display' is non-nil, we display
6824 non-ASCII spaces and hyphens specially. */
6825 if (! ASCII_CHAR_P (c
) && ! NILP (Vnobreak_char_display
))
6828 nonascii_space_p
= 1;
6829 else if (c
== 0xAD || c
== 0x2010 || c
== 0x2011)
6830 nonascii_hyphen_p
= 1;
6833 /* Translate control characters into `\003' or `^C' form.
6834 Control characters coming from a display table entry are
6835 currently not translated because we use IT->dpvec to hold
6836 the translation. This could easily be changed but I
6837 don't believe that it is worth doing.
6839 The characters handled by `nobreak-char-display' must be
6842 Non-printable characters and raw-byte characters are also
6843 translated to octal form. */
6844 if (((c
< ' ' || c
== 127) /* ASCII control chars */
6845 ? (it
->area
!= TEXT_AREA
6846 /* In mode line, treat \n, \t like other crl chars. */
6849 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
6850 || (c
!= '\n' && c
!= '\t'))
6852 || nonascii_hyphen_p
6854 || ! CHAR_PRINTABLE_P (c
))))
6856 /* C is a control character, non-ASCII space/hyphen,
6857 raw-byte, or a non-printable character which must be
6858 displayed either as '\003' or as `^C' where the '\\'
6859 and '^' can be defined in the display table. Fill
6860 IT->ctl_chars with glyphs for what we have to
6861 display. Then, set IT->dpvec to these glyphs. */
6868 /* Handle control characters with ^. */
6870 if (ASCII_CHAR_P (c
) && it
->ctl_arrow_p
)
6874 g
= '^'; /* default glyph for Control */
6875 /* Set IT->ctl_chars[0] to the glyph for `^'. */
6877 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
6879 g
= GLYPH_CODE_CHAR (gc
);
6880 lface_id
= GLYPH_CODE_FACE (gc
);
6884 face_id
= merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
);
6886 else if (it
->f
== last_escape_glyph_frame
6887 && it
->face_id
== last_escape_glyph_face_id
)
6889 face_id
= last_escape_glyph_merged_face_id
;
6893 /* Merge the escape-glyph face into the current face. */
6894 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
6896 last_escape_glyph_frame
= it
->f
;
6897 last_escape_glyph_face_id
= it
->face_id
;
6898 last_escape_glyph_merged_face_id
= face_id
;
6901 XSETINT (it
->ctl_chars
[0], g
);
6902 XSETINT (it
->ctl_chars
[1], c
^ 0100);
6904 goto display_control
;
6907 /* Handle non-ascii space in the mode where it only gets
6910 if (nonascii_space_p
&& EQ (Vnobreak_char_display
, Qt
))
6912 /* Merge `nobreak-space' into the current face. */
6913 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
6915 XSETINT (it
->ctl_chars
[0], ' ');
6917 goto display_control
;
6920 /* Handle sequences that start with the "escape glyph". */
6922 /* the default escape glyph is \. */
6923 escape_glyph
= '\\';
6926 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
6928 escape_glyph
= GLYPH_CODE_CHAR (gc
);
6929 lface_id
= GLYPH_CODE_FACE (gc
);
6933 /* The display table specified a face.
6934 Merge it into face_id and also into escape_glyph. */
6935 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6938 else if (it
->f
== last_escape_glyph_frame
6939 && it
->face_id
== last_escape_glyph_face_id
)
6941 face_id
= last_escape_glyph_merged_face_id
;
6945 /* Merge the escape-glyph face into the current face. */
6946 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
6948 last_escape_glyph_frame
= it
->f
;
6949 last_escape_glyph_face_id
= it
->face_id
;
6950 last_escape_glyph_merged_face_id
= face_id
;
6953 /* Draw non-ASCII hyphen with just highlighting: */
6955 if (nonascii_hyphen_p
&& EQ (Vnobreak_char_display
, Qt
))
6957 XSETINT (it
->ctl_chars
[0], '-');
6959 goto display_control
;
6962 /* Draw non-ASCII space/hyphen with escape glyph: */
6964 if (nonascii_space_p
|| nonascii_hyphen_p
)
6966 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6967 XSETINT (it
->ctl_chars
[1], nonascii_space_p
? ' ' : '-');
6969 goto display_control
;
6976 if (CHAR_BYTE8_P (c
))
6977 /* Display \200 instead of \17777600. */
6978 c
= CHAR_TO_BYTE8 (c
);
6979 len
= sprintf (str
, "%03o", c
);
6981 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6982 for (i
= 0; i
< len
; i
++)
6983 XSETINT (it
->ctl_chars
[i
+ 1], str
[i
]);
6988 /* Set up IT->dpvec and return first character from it. */
6989 it
->dpvec_char_len
= it
->len
;
6990 it
->dpvec
= it
->ctl_chars
;
6991 it
->dpend
= it
->dpvec
+ ctl_len
;
6992 it
->current
.dpvec_index
= 0;
6993 it
->dpvec_face_id
= face_id
;
6994 it
->saved_face_id
= it
->face_id
;
6995 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6999 it
->char_to_display
= c
;
7003 it
->char_to_display
= it
->c
;
7007 /* Adjust face id for a multibyte character. There are no multibyte
7008 character in unibyte text. */
7009 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
7012 && FRAME_WINDOW_P (it
->f
))
7014 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
7016 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
7018 /* Automatic composition with glyph-string. */
7019 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
7021 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
7025 ptrdiff_t pos
= (it
->s
? -1
7026 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
7027 : IT_CHARPOS (*it
));
7030 if (it
->what
== IT_CHARACTER
)
7031 c
= it
->char_to_display
;
7034 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
7038 for (i
= 0; i
< cmp
->glyph_len
; i
++)
7039 /* TAB in a composition means display glyphs with
7040 padding space on the left or right. */
7041 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
7044 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, pos
, it
->string
);
7049 /* Is this character the last one of a run of characters with
7050 box? If yes, set IT->end_of_box_run_p to 1. */
7054 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
7056 int face_id
= underlying_face_id (it
);
7057 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
7061 if (face
->box
== FACE_NO_BOX
)
7063 /* If the box comes from face properties in a
7064 display string, check faces in that string. */
7065 int string_face_id
= face_after_it_pos (it
);
7066 it
->end_of_box_run_p
7067 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
7070 /* Otherwise, the box comes from the underlying face.
7071 If this is the last string character displayed, check
7072 the next buffer location. */
7073 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
7074 && (it
->current
.overlay_string_index
7075 == it
->n_overlay_strings
- 1))
7079 struct text_pos pos
= it
->current
.pos
;
7080 INC_TEXT_POS (pos
, it
->multibyte_p
);
7082 next_face_id
= face_at_buffer_position
7083 (it
->w
, CHARPOS (pos
), it
->region_beg_charpos
,
7084 it
->region_end_charpos
, &ignore
,
7085 (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
), 0,
7087 it
->end_of_box_run_p
7088 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
7093 /* next_element_from_display_vector sets this flag according to
7094 faces of the display vector glyphs, see there. */
7095 else if (it
->method
!= GET_FROM_DISPLAY_VECTOR
)
7097 int face_id
= face_after_it_pos (it
);
7098 it
->end_of_box_run_p
7099 = (face_id
!= it
->face_id
7100 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
7103 /* If we reached the end of the object we've been iterating (e.g., a
7104 display string or an overlay string), and there's something on
7105 IT->stack, proceed with what's on the stack. It doesn't make
7106 sense to return zero if there's unprocessed stuff on the stack,
7107 because otherwise that stuff will never be displayed. */
7108 if (!success_p
&& it
->sp
> 0)
7110 set_iterator_to_next (it
, 0);
7111 success_p
= get_next_display_element (it
);
7114 /* Value is 0 if end of buffer or string reached. */
7119 /* Move IT to the next display element.
7121 RESEAT_P non-zero means if called on a newline in buffer text,
7122 skip to the next visible line start.
7124 Functions get_next_display_element and set_iterator_to_next are
7125 separate because I find this arrangement easier to handle than a
7126 get_next_display_element function that also increments IT's
7127 position. The way it is we can first look at an iterator's current
7128 display element, decide whether it fits on a line, and if it does,
7129 increment the iterator position. The other way around we probably
7130 would either need a flag indicating whether the iterator has to be
7131 incremented the next time, or we would have to implement a
7132 decrement position function which would not be easy to write. */
7135 set_iterator_to_next (struct it
*it
, int reseat_p
)
7137 /* Reset flags indicating start and end of a sequence of characters
7138 with box. Reset them at the start of this function because
7139 moving the iterator to a new position might set them. */
7140 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
7144 case GET_FROM_BUFFER
:
7145 /* The current display element of IT is a character from
7146 current_buffer. Advance in the buffer, and maybe skip over
7147 invisible lines that are so because of selective display. */
7148 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
7149 reseat_at_next_visible_line_start (it
, 0);
7150 else if (it
->cmp_it
.id
>= 0)
7152 /* We are currently getting glyphs from a composition. */
7157 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7158 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7159 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7161 it
->cmp_it
.from
= it
->cmp_it
.to
;
7166 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7168 it
->end_charpos
, Qnil
);
7171 else if (! it
->cmp_it
.reversed_p
)
7173 /* Composition created while scanning forward. */
7174 /* Update IT's char/byte positions to point to the first
7175 character of the next grapheme cluster, or to the
7176 character visually after the current composition. */
7177 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7178 bidi_move_to_visually_next (&it
->bidi_it
);
7179 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7180 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7182 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7184 /* Proceed to the next grapheme cluster. */
7185 it
->cmp_it
.from
= it
->cmp_it
.to
;
7189 /* No more grapheme clusters in this composition.
7190 Find the next stop position. */
7191 ptrdiff_t stop
= it
->end_charpos
;
7192 if (it
->bidi_it
.scan_dir
< 0)
7193 /* Now we are scanning backward and don't know
7196 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7197 IT_BYTEPOS (*it
), stop
, Qnil
);
7202 /* Composition created while scanning backward. */
7203 /* Update IT's char/byte positions to point to the last
7204 character of the previous grapheme cluster, or the
7205 character visually after the current composition. */
7206 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7207 bidi_move_to_visually_next (&it
->bidi_it
);
7208 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7209 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7210 if (it
->cmp_it
.from
> 0)
7212 /* Proceed to the previous grapheme cluster. */
7213 it
->cmp_it
.to
= it
->cmp_it
.from
;
7217 /* No more grapheme clusters in this composition.
7218 Find the next stop position. */
7219 ptrdiff_t stop
= it
->end_charpos
;
7220 if (it
->bidi_it
.scan_dir
< 0)
7221 /* Now we are scanning backward and don't know
7224 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7225 IT_BYTEPOS (*it
), stop
, Qnil
);
7231 eassert (it
->len
!= 0);
7235 IT_BYTEPOS (*it
) += it
->len
;
7236 IT_CHARPOS (*it
) += 1;
7240 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7241 /* If this is a new paragraph, determine its base
7242 direction (a.k.a. its base embedding level). */
7243 if (it
->bidi_it
.new_paragraph
)
7244 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
7245 bidi_move_to_visually_next (&it
->bidi_it
);
7246 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7247 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7248 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7250 /* As the scan direction was changed, we must
7251 re-compute the stop position for composition. */
7252 ptrdiff_t stop
= it
->end_charpos
;
7253 if (it
->bidi_it
.scan_dir
< 0)
7255 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7256 IT_BYTEPOS (*it
), stop
, Qnil
);
7259 eassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
7263 case GET_FROM_C_STRING
:
7264 /* Current display element of IT is from a C string. */
7266 /* If the string position is beyond string's end, it means
7267 next_element_from_c_string is padding the string with
7268 blanks, in which case we bypass the bidi iterator,
7269 because it cannot deal with such virtual characters. */
7270 || IT_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7272 IT_BYTEPOS (*it
) += it
->len
;
7273 IT_CHARPOS (*it
) += 1;
7277 bidi_move_to_visually_next (&it
->bidi_it
);
7278 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7279 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7283 case GET_FROM_DISPLAY_VECTOR
:
7284 /* Current display element of IT is from a display table entry.
7285 Advance in the display table definition. Reset it to null if
7286 end reached, and continue with characters from buffers/
7288 ++it
->current
.dpvec_index
;
7290 /* Restore face of the iterator to what they were before the
7291 display vector entry (these entries may contain faces). */
7292 it
->face_id
= it
->saved_face_id
;
7294 if (it
->dpvec
+ it
->current
.dpvec_index
>= it
->dpend
)
7296 int recheck_faces
= it
->ellipsis_p
;
7299 it
->method
= GET_FROM_C_STRING
;
7300 else if (STRINGP (it
->string
))
7301 it
->method
= GET_FROM_STRING
;
7304 it
->method
= GET_FROM_BUFFER
;
7305 it
->object
= it
->w
->contents
;
7309 it
->current
.dpvec_index
= -1;
7311 /* Skip over characters which were displayed via IT->dpvec. */
7312 if (it
->dpvec_char_len
< 0)
7313 reseat_at_next_visible_line_start (it
, 1);
7314 else if (it
->dpvec_char_len
> 0)
7316 if (it
->method
== GET_FROM_STRING
7317 && it
->current
.overlay_string_index
>= 0
7318 && it
->n_overlay_strings
> 0)
7319 it
->ignore_overlay_strings_at_pos_p
= 1;
7320 it
->len
= it
->dpvec_char_len
;
7321 set_iterator_to_next (it
, reseat_p
);
7324 /* Maybe recheck faces after display vector */
7326 it
->stop_charpos
= IT_CHARPOS (*it
);
7330 case GET_FROM_STRING
:
7331 /* Current display element is a character from a Lisp string. */
7332 eassert (it
->s
== NULL
&& STRINGP (it
->string
));
7333 /* Don't advance past string end. These conditions are true
7334 when set_iterator_to_next is called at the end of
7335 get_next_display_element, in which case the Lisp string is
7336 already exhausted, and all we want is pop the iterator
7338 if (it
->current
.overlay_string_index
>= 0)
7340 /* This is an overlay string, so there's no padding with
7341 spaces, and the number of characters in the string is
7342 where the string ends. */
7343 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7344 goto consider_string_end
;
7348 /* Not an overlay string. There could be padding, so test
7349 against it->end_charpos . */
7350 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7351 goto consider_string_end
;
7353 if (it
->cmp_it
.id
>= 0)
7359 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7360 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7361 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7362 it
->cmp_it
.from
= it
->cmp_it
.to
;
7366 composition_compute_stop_pos (&it
->cmp_it
,
7367 IT_STRING_CHARPOS (*it
),
7368 IT_STRING_BYTEPOS (*it
),
7369 it
->end_charpos
, it
->string
);
7372 else if (! it
->cmp_it
.reversed_p
)
7374 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7375 bidi_move_to_visually_next (&it
->bidi_it
);
7376 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7377 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7379 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7380 it
->cmp_it
.from
= it
->cmp_it
.to
;
7383 ptrdiff_t stop
= it
->end_charpos
;
7384 if (it
->bidi_it
.scan_dir
< 0)
7386 composition_compute_stop_pos (&it
->cmp_it
,
7387 IT_STRING_CHARPOS (*it
),
7388 IT_STRING_BYTEPOS (*it
), stop
,
7394 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7395 bidi_move_to_visually_next (&it
->bidi_it
);
7396 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7397 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7398 if (it
->cmp_it
.from
> 0)
7399 it
->cmp_it
.to
= it
->cmp_it
.from
;
7402 ptrdiff_t stop
= it
->end_charpos
;
7403 if (it
->bidi_it
.scan_dir
< 0)
7405 composition_compute_stop_pos (&it
->cmp_it
,
7406 IT_STRING_CHARPOS (*it
),
7407 IT_STRING_BYTEPOS (*it
), stop
,
7415 /* If the string position is beyond string's end, it
7416 means next_element_from_string is padding the string
7417 with blanks, in which case we bypass the bidi
7418 iterator, because it cannot deal with such virtual
7420 || IT_STRING_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7422 IT_STRING_BYTEPOS (*it
) += it
->len
;
7423 IT_STRING_CHARPOS (*it
) += 1;
7427 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7429 bidi_move_to_visually_next (&it
->bidi_it
);
7430 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7431 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7432 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7434 ptrdiff_t stop
= it
->end_charpos
;
7436 if (it
->bidi_it
.scan_dir
< 0)
7438 composition_compute_stop_pos (&it
->cmp_it
,
7439 IT_STRING_CHARPOS (*it
),
7440 IT_STRING_BYTEPOS (*it
), stop
,
7446 consider_string_end
:
7448 if (it
->current
.overlay_string_index
>= 0)
7450 /* IT->string is an overlay string. Advance to the
7451 next, if there is one. */
7452 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7455 next_overlay_string (it
);
7457 setup_for_ellipsis (it
, 0);
7462 /* IT->string is not an overlay string. If we reached
7463 its end, and there is something on IT->stack, proceed
7464 with what is on the stack. This can be either another
7465 string, this time an overlay string, or a buffer. */
7466 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
7470 if (it
->method
== GET_FROM_STRING
)
7471 goto consider_string_end
;
7476 case GET_FROM_IMAGE
:
7477 case GET_FROM_STRETCH
:
7478 #ifdef HAVE_XWIDGETS
7479 case GET_FROM_XWIDGET
:
7481 /* The position etc with which we have to proceed are on
7482 the stack. The position may be at the end of a string,
7483 if the `display' property takes up the whole string. */
7484 eassert (it
->sp
> 0);
7486 if (it
->method
== GET_FROM_STRING
)
7487 goto consider_string_end
;
7491 /* There are no other methods defined, so this should be a bug. */
7495 eassert (it
->method
!= GET_FROM_STRING
7496 || (STRINGP (it
->string
)
7497 && IT_STRING_CHARPOS (*it
) >= 0));
7500 /* Load IT's display element fields with information about the next
7501 display element which comes from a display table entry or from the
7502 result of translating a control character to one of the forms `^C'
7505 IT->dpvec holds the glyphs to return as characters.
7506 IT->saved_face_id holds the face id before the display vector--it
7507 is restored into IT->face_id in set_iterator_to_next. */
7510 next_element_from_display_vector (struct it
*it
)
7513 int prev_face_id
= it
->face_id
;
7517 eassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
7519 it
->face_id
= it
->saved_face_id
;
7521 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
7522 That seemed totally bogus - so I changed it... */
7523 gc
= it
->dpvec
[it
->current
.dpvec_index
];
7525 if (GLYPH_CODE_P (gc
))
7527 struct face
*this_face
, *prev_face
, *next_face
;
7529 it
->c
= GLYPH_CODE_CHAR (gc
);
7530 it
->len
= CHAR_BYTES (it
->c
);
7532 /* The entry may contain a face id to use. Such a face id is
7533 the id of a Lisp face, not a realized face. A face id of
7534 zero means no face is specified. */
7535 if (it
->dpvec_face_id
>= 0)
7536 it
->face_id
= it
->dpvec_face_id
;
7539 int lface_id
= GLYPH_CODE_FACE (gc
);
7541 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
7545 /* Glyphs in the display vector could have the box face, so we
7546 need to set the related flags in the iterator, as
7548 this_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
7549 prev_face
= FACE_FROM_ID (it
->f
, prev_face_id
);
7551 /* Is this character the first character of a box-face run? */
7552 it
->start_of_box_run_p
= (this_face
&& this_face
->box
!= FACE_NO_BOX
7554 || prev_face
->box
== FACE_NO_BOX
));
7556 /* For the last character of the box-face run, we need to look
7557 either at the next glyph from the display vector, or at the
7558 face we saw before the display vector. */
7559 next_face_id
= it
->saved_face_id
;
7560 if (it
->current
.dpvec_index
< it
->dpend
- it
->dpvec
- 1)
7562 if (it
->dpvec_face_id
>= 0)
7563 next_face_id
= it
->dpvec_face_id
;
7567 GLYPH_CODE_FACE (it
->dpvec
[it
->current
.dpvec_index
+ 1]);
7570 next_face_id
= merge_faces (it
->f
, Qt
, lface_id
,
7574 next_face
= FACE_FROM_ID (it
->f
, next_face_id
);
7575 it
->end_of_box_run_p
= (this_face
&& this_face
->box
!= FACE_NO_BOX
7577 || next_face
->box
== FACE_NO_BOX
));
7578 it
->face_box_p
= this_face
&& this_face
->box
!= FACE_NO_BOX
;
7581 /* Display table entry is invalid. Return a space. */
7582 it
->c
= ' ', it
->len
= 1;
7584 /* Don't change position and object of the iterator here. They are
7585 still the values of the character that had this display table
7586 entry or was translated, and that's what we want. */
7587 it
->what
= IT_CHARACTER
;
7591 /* Get the first element of string/buffer in the visual order, after
7592 being reseated to a new position in a string or a buffer. */
7594 get_visually_first_element (struct it
*it
)
7596 int string_p
= STRINGP (it
->string
) || it
->s
;
7597 ptrdiff_t eob
= (string_p
? it
->bidi_it
.string
.schars
: ZV
);
7598 ptrdiff_t bob
= (string_p
? 0 : BEGV
);
7600 if (STRINGP (it
->string
))
7602 it
->bidi_it
.charpos
= IT_STRING_CHARPOS (*it
);
7603 it
->bidi_it
.bytepos
= IT_STRING_BYTEPOS (*it
);
7607 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
7608 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
7611 if (it
->bidi_it
.charpos
== eob
)
7613 /* Nothing to do, but reset the FIRST_ELT flag, like
7614 bidi_paragraph_init does, because we are not going to
7616 it
->bidi_it
.first_elt
= 0;
7618 else if (it
->bidi_it
.charpos
== bob
7620 && (FETCH_CHAR (it
->bidi_it
.bytepos
- 1) == '\n'
7621 || FETCH_CHAR (it
->bidi_it
.bytepos
) == '\n')))
7623 /* If we are at the beginning of a line/string, we can produce
7624 the next element right away. */
7625 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7626 bidi_move_to_visually_next (&it
->bidi_it
);
7630 ptrdiff_t orig_bytepos
= it
->bidi_it
.bytepos
;
7632 /* We need to prime the bidi iterator starting at the line's or
7633 string's beginning, before we will be able to produce the
7636 it
->bidi_it
.charpos
= it
->bidi_it
.bytepos
= 0;
7638 it
->bidi_it
.charpos
= find_newline_no_quit (IT_CHARPOS (*it
),
7639 IT_BYTEPOS (*it
), -1,
7640 &it
->bidi_it
.bytepos
);
7641 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7644 /* Now return to buffer/string position where we were asked
7645 to get the next display element, and produce that. */
7646 bidi_move_to_visually_next (&it
->bidi_it
);
7648 while (it
->bidi_it
.bytepos
!= orig_bytepos
7649 && it
->bidi_it
.charpos
< eob
);
7652 /* Adjust IT's position information to where we ended up. */
7653 if (STRINGP (it
->string
))
7655 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7656 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7660 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7661 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7664 if (STRINGP (it
->string
) || !it
->s
)
7666 ptrdiff_t stop
, charpos
, bytepos
;
7668 if (STRINGP (it
->string
))
7671 stop
= SCHARS (it
->string
);
7672 if (stop
> it
->end_charpos
)
7673 stop
= it
->end_charpos
;
7674 charpos
= IT_STRING_CHARPOS (*it
);
7675 bytepos
= IT_STRING_BYTEPOS (*it
);
7679 stop
= it
->end_charpos
;
7680 charpos
= IT_CHARPOS (*it
);
7681 bytepos
= IT_BYTEPOS (*it
);
7683 if (it
->bidi_it
.scan_dir
< 0)
7685 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
, stop
,
7690 /* Load IT with the next display element from Lisp string IT->string.
7691 IT->current.string_pos is the current position within the string.
7692 If IT->current.overlay_string_index >= 0, the Lisp string is an
7696 next_element_from_string (struct it
*it
)
7698 struct text_pos position
;
7700 eassert (STRINGP (it
->string
));
7701 eassert (!it
->bidi_p
|| EQ (it
->string
, it
->bidi_it
.string
.lstring
));
7702 eassert (IT_STRING_CHARPOS (*it
) >= 0);
7703 position
= it
->current
.string_pos
;
7705 /* With bidi reordering, the character to display might not be the
7706 character at IT_STRING_CHARPOS. BIDI_IT.FIRST_ELT non-zero means
7707 that we were reseat()ed to a new string, whose paragraph
7708 direction is not known. */
7709 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7711 get_visually_first_element (it
);
7712 SET_TEXT_POS (position
, IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
));
7715 /* Time to check for invisible text? */
7716 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
7718 if (IT_STRING_CHARPOS (*it
) >= it
->stop_charpos
)
7721 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7722 || IT_STRING_CHARPOS (*it
) == it
->stop_charpos
))
7724 /* With bidi non-linear iteration, we could find
7725 ourselves far beyond the last computed stop_charpos,
7726 with several other stop positions in between that we
7727 missed. Scan them all now, in buffer's logical
7728 order, until we find and handle the last stop_charpos
7729 that precedes our current position. */
7730 handle_stop_backwards (it
, it
->stop_charpos
);
7731 return GET_NEXT_DISPLAY_ELEMENT (it
);
7737 /* Take note of the stop position we just moved
7738 across, for when we will move back across it. */
7739 it
->prev_stop
= it
->stop_charpos
;
7740 /* If we are at base paragraph embedding level, take
7741 note of the last stop position seen at this
7743 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7744 it
->base_level_stop
= it
->stop_charpos
;
7748 /* Since a handler may have changed IT->method, we must
7750 return GET_NEXT_DISPLAY_ELEMENT (it
);
7754 /* If we are before prev_stop, we may have overstepped
7755 on our way backwards a stop_pos, and if so, we need
7756 to handle that stop_pos. */
7757 && IT_STRING_CHARPOS (*it
) < it
->prev_stop
7758 /* We can sometimes back up for reasons that have nothing
7759 to do with bidi reordering. E.g., compositions. The
7760 code below is only needed when we are above the base
7761 embedding level, so test for that explicitly. */
7762 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7764 /* If we lost track of base_level_stop, we have no better
7765 place for handle_stop_backwards to start from than string
7766 beginning. This happens, e.g., when we were reseated to
7767 the previous screenful of text by vertical-motion. */
7768 if (it
->base_level_stop
<= 0
7769 || IT_STRING_CHARPOS (*it
) < it
->base_level_stop
)
7770 it
->base_level_stop
= 0;
7771 handle_stop_backwards (it
, it
->base_level_stop
);
7772 return GET_NEXT_DISPLAY_ELEMENT (it
);
7776 if (it
->current
.overlay_string_index
>= 0)
7778 /* Get the next character from an overlay string. In overlay
7779 strings, there is no field width or padding with spaces to
7781 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7786 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7787 IT_STRING_BYTEPOS (*it
),
7788 it
->bidi_it
.scan_dir
< 0
7790 : SCHARS (it
->string
))
7791 && next_element_from_composition (it
))
7795 else if (STRING_MULTIBYTE (it
->string
))
7797 const unsigned char *s
= (SDATA (it
->string
)
7798 + IT_STRING_BYTEPOS (*it
));
7799 it
->c
= string_char_and_length (s
, &it
->len
);
7803 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7809 /* Get the next character from a Lisp string that is not an
7810 overlay string. Such strings come from the mode line, for
7811 example. We may have to pad with spaces, or truncate the
7812 string. See also next_element_from_c_string. */
7813 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7818 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
7820 /* Pad with spaces. */
7821 it
->c
= ' ', it
->len
= 1;
7822 CHARPOS (position
) = BYTEPOS (position
) = -1;
7824 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7825 IT_STRING_BYTEPOS (*it
),
7826 it
->bidi_it
.scan_dir
< 0
7828 : it
->string_nchars
)
7829 && next_element_from_composition (it
))
7833 else if (STRING_MULTIBYTE (it
->string
))
7835 const unsigned char *s
= (SDATA (it
->string
)
7836 + IT_STRING_BYTEPOS (*it
));
7837 it
->c
= string_char_and_length (s
, &it
->len
);
7841 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7846 /* Record what we have and where it came from. */
7847 it
->what
= IT_CHARACTER
;
7848 it
->object
= it
->string
;
7849 it
->position
= position
;
7854 /* Load IT with next display element from C string IT->s.
7855 IT->string_nchars is the maximum number of characters to return
7856 from the string. IT->end_charpos may be greater than
7857 IT->string_nchars when this function is called, in which case we
7858 may have to return padding spaces. Value is zero if end of string
7859 reached, including padding spaces. */
7862 next_element_from_c_string (struct it
*it
)
7867 eassert (!it
->bidi_p
|| it
->s
== it
->bidi_it
.string
.s
);
7868 it
->what
= IT_CHARACTER
;
7869 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
7872 /* With bidi reordering, the character to display might not be the
7873 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7874 we were reseated to a new string, whose paragraph direction is
7876 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7877 get_visually_first_element (it
);
7879 /* IT's position can be greater than IT->string_nchars in case a
7880 field width or precision has been specified when the iterator was
7882 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7884 /* End of the game. */
7888 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
7890 /* Pad with spaces. */
7891 it
->c
= ' ', it
->len
= 1;
7892 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
7894 else if (it
->multibyte_p
)
7895 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
), &it
->len
);
7897 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
7903 /* Set up IT to return characters from an ellipsis, if appropriate.
7904 The definition of the ellipsis glyphs may come from a display table
7905 entry. This function fills IT with the first glyph from the
7906 ellipsis if an ellipsis is to be displayed. */
7909 next_element_from_ellipsis (struct it
*it
)
7911 if (it
->selective_display_ellipsis_p
)
7912 setup_for_ellipsis (it
, it
->len
);
7915 /* The face at the current position may be different from the
7916 face we find after the invisible text. Remember what it
7917 was in IT->saved_face_id, and signal that it's there by
7918 setting face_before_selective_p. */
7919 it
->saved_face_id
= it
->face_id
;
7920 it
->method
= GET_FROM_BUFFER
;
7921 it
->object
= it
->w
->contents
;
7922 reseat_at_next_visible_line_start (it
, 1);
7923 it
->face_before_selective_p
= 1;
7926 return GET_NEXT_DISPLAY_ELEMENT (it
);
7930 /* Deliver an image display element. The iterator IT is already
7931 filled with image information (done in handle_display_prop). Value
7936 next_element_from_image (struct it
*it
)
7938 it
->what
= IT_IMAGE
;
7939 it
->ignore_overlay_strings_at_pos_p
= 0;
7943 #ifdef HAVE_XWIDGETS
7944 /* im not sure about this FIXME JAVE*/
7946 next_element_from_xwidget (struct it
*it
)
7948 it
->what
= IT_XWIDGET
;
7949 //assert_valid_xwidget_id(it->xwidget_id,"next_element_from_xwidget");
7950 //this is shaky because why do we set "what" if we dont set the other parts??
7951 //printf("xwidget_id %d: in next_element_from_xwidget: FIXME \n", it->xwidget_id);
7957 /* Fill iterator IT with next display element from a stretch glyph
7958 property. IT->object is the value of the text property. Value is
7962 next_element_from_stretch (struct it
*it
)
7964 it
->what
= IT_STRETCH
;
7968 /* Scan backwards from IT's current position until we find a stop
7969 position, or until BEGV. This is called when we find ourself
7970 before both the last known prev_stop and base_level_stop while
7971 reordering bidirectional text. */
7974 compute_stop_pos_backwards (struct it
*it
)
7976 const int SCAN_BACK_LIMIT
= 1000;
7977 struct text_pos pos
;
7978 struct display_pos save_current
= it
->current
;
7979 struct text_pos save_position
= it
->position
;
7980 ptrdiff_t charpos
= IT_CHARPOS (*it
);
7981 ptrdiff_t where_we_are
= charpos
;
7982 ptrdiff_t save_stop_pos
= it
->stop_charpos
;
7983 ptrdiff_t save_end_pos
= it
->end_charpos
;
7985 eassert (NILP (it
->string
) && !it
->s
);
7986 eassert (it
->bidi_p
);
7990 it
->end_charpos
= min (charpos
+ 1, ZV
);
7991 charpos
= max (charpos
- SCAN_BACK_LIMIT
, BEGV
);
7992 SET_TEXT_POS (pos
, charpos
, CHAR_TO_BYTE (charpos
));
7993 reseat_1 (it
, pos
, 0);
7994 compute_stop_pos (it
);
7995 /* We must advance forward, right? */
7996 if (it
->stop_charpos
<= charpos
)
7999 while (charpos
> BEGV
&& it
->stop_charpos
>= it
->end_charpos
);
8001 if (it
->stop_charpos
<= where_we_are
)
8002 it
->prev_stop
= it
->stop_charpos
;
8004 it
->prev_stop
= BEGV
;
8006 it
->current
= save_current
;
8007 it
->position
= save_position
;
8008 it
->stop_charpos
= save_stop_pos
;
8009 it
->end_charpos
= save_end_pos
;
8012 /* Scan forward from CHARPOS in the current buffer/string, until we
8013 find a stop position > current IT's position. Then handle the stop
8014 position before that. This is called when we bump into a stop
8015 position while reordering bidirectional text. CHARPOS should be
8016 the last previously processed stop_pos (or BEGV/0, if none were
8017 processed yet) whose position is less that IT's current
8021 handle_stop_backwards (struct it
*it
, ptrdiff_t charpos
)
8023 int bufp
= !STRINGP (it
->string
);
8024 ptrdiff_t where_we_are
= (bufp
? IT_CHARPOS (*it
) : IT_STRING_CHARPOS (*it
));
8025 struct display_pos save_current
= it
->current
;
8026 struct text_pos save_position
= it
->position
;
8027 struct text_pos pos1
;
8028 ptrdiff_t next_stop
;
8030 /* Scan in strict logical order. */
8031 eassert (it
->bidi_p
);
8035 it
->prev_stop
= charpos
;
8038 SET_TEXT_POS (pos1
, charpos
, CHAR_TO_BYTE (charpos
));
8039 reseat_1 (it
, pos1
, 0);
8042 it
->current
.string_pos
= string_pos (charpos
, it
->string
);
8043 compute_stop_pos (it
);
8044 /* We must advance forward, right? */
8045 if (it
->stop_charpos
<= it
->prev_stop
)
8047 charpos
= it
->stop_charpos
;
8049 while (charpos
<= where_we_are
);
8052 it
->current
= save_current
;
8053 it
->position
= save_position
;
8054 next_stop
= it
->stop_charpos
;
8055 it
->stop_charpos
= it
->prev_stop
;
8057 it
->stop_charpos
= next_stop
;
8060 /* Load IT with the next display element from current_buffer. Value
8061 is zero if end of buffer reached. IT->stop_charpos is the next
8062 position at which to stop and check for text properties or buffer
8066 next_element_from_buffer (struct it
*it
)
8070 eassert (IT_CHARPOS (*it
) >= BEGV
);
8071 eassert (NILP (it
->string
) && !it
->s
);
8072 eassert (!it
->bidi_p
8073 || (EQ (it
->bidi_it
.string
.lstring
, Qnil
)
8074 && it
->bidi_it
.string
.s
== NULL
));
8076 /* With bidi reordering, the character to display might not be the
8077 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
8078 we were reseat()ed to a new buffer position, which is potentially
8079 a different paragraph. */
8080 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
8082 get_visually_first_element (it
);
8083 SET_TEXT_POS (it
->position
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8086 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
8088 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
8090 int overlay_strings_follow_p
;
8092 /* End of the game, except when overlay strings follow that
8093 haven't been returned yet. */
8094 if (it
->overlay_strings_at_end_processed_p
)
8095 overlay_strings_follow_p
= 0;
8098 it
->overlay_strings_at_end_processed_p
= 1;
8099 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
8102 if (overlay_strings_follow_p
)
8103 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
8107 it
->position
= it
->current
.pos
;
8111 else if (!(!it
->bidi_p
8112 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
8113 || IT_CHARPOS (*it
) == it
->stop_charpos
))
8115 /* With bidi non-linear iteration, we could find ourselves
8116 far beyond the last computed stop_charpos, with several
8117 other stop positions in between that we missed. Scan
8118 them all now, in buffer's logical order, until we find
8119 and handle the last stop_charpos that precedes our
8120 current position. */
8121 handle_stop_backwards (it
, it
->stop_charpos
);
8122 return GET_NEXT_DISPLAY_ELEMENT (it
);
8128 /* Take note of the stop position we just moved across,
8129 for when we will move back across it. */
8130 it
->prev_stop
= it
->stop_charpos
;
8131 /* If we are at base paragraph embedding level, take
8132 note of the last stop position seen at this
8134 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8135 it
->base_level_stop
= it
->stop_charpos
;
8138 return GET_NEXT_DISPLAY_ELEMENT (it
);
8142 /* If we are before prev_stop, we may have overstepped on
8143 our way backwards a stop_pos, and if so, we need to
8144 handle that stop_pos. */
8145 && IT_CHARPOS (*it
) < it
->prev_stop
8146 /* We can sometimes back up for reasons that have nothing
8147 to do with bidi reordering. E.g., compositions. The
8148 code below is only needed when we are above the base
8149 embedding level, so test for that explicitly. */
8150 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8152 if (it
->base_level_stop
<= 0
8153 || IT_CHARPOS (*it
) < it
->base_level_stop
)
8155 /* If we lost track of base_level_stop, we need to find
8156 prev_stop by looking backwards. This happens, e.g., when
8157 we were reseated to the previous screenful of text by
8159 it
->base_level_stop
= BEGV
;
8160 compute_stop_pos_backwards (it
);
8161 handle_stop_backwards (it
, it
->prev_stop
);
8164 handle_stop_backwards (it
, it
->base_level_stop
);
8165 return GET_NEXT_DISPLAY_ELEMENT (it
);
8169 /* No face changes, overlays etc. in sight, so just return a
8170 character from current_buffer. */
8174 /* Maybe run the redisplay end trigger hook. Performance note:
8175 This doesn't seem to cost measurable time. */
8176 if (it
->redisplay_end_trigger_charpos
8178 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
8179 run_redisplay_end_trigger_hook (it
);
8181 stop
= it
->bidi_it
.scan_dir
< 0 ? -1 : it
->end_charpos
;
8182 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
8184 && next_element_from_composition (it
))
8189 /* Get the next character, maybe multibyte. */
8190 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
8191 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
8192 it
->c
= STRING_CHAR_AND_LENGTH (p
, it
->len
);
8194 it
->c
= *p
, it
->len
= 1;
8196 /* Record what we have and where it came from. */
8197 it
->what
= IT_CHARACTER
;
8198 it
->object
= it
->w
->contents
;
8199 it
->position
= it
->current
.pos
;
8201 /* Normally we return the character found above, except when we
8202 really want to return an ellipsis for selective display. */
8207 /* A value of selective > 0 means hide lines indented more
8208 than that number of columns. */
8209 if (it
->selective
> 0
8210 && IT_CHARPOS (*it
) + 1 < ZV
8211 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
8212 IT_BYTEPOS (*it
) + 1,
8215 success_p
= next_element_from_ellipsis (it
);
8216 it
->dpvec_char_len
= -1;
8219 else if (it
->c
== '\r' && it
->selective
== -1)
8221 /* A value of selective == -1 means that everything from the
8222 CR to the end of the line is invisible, with maybe an
8223 ellipsis displayed for it. */
8224 success_p
= next_element_from_ellipsis (it
);
8225 it
->dpvec_char_len
= -1;
8230 /* Value is zero if end of buffer reached. */
8231 eassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
8236 /* Run the redisplay end trigger hook for IT. */
8239 run_redisplay_end_trigger_hook (struct it
*it
)
8241 Lisp_Object args
[3];
8243 /* IT->glyph_row should be non-null, i.e. we should be actually
8244 displaying something, or otherwise we should not run the hook. */
8245 eassert (it
->glyph_row
);
8247 /* Set up hook arguments. */
8248 args
[0] = Qredisplay_end_trigger_functions
;
8249 args
[1] = it
->window
;
8250 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
8251 it
->redisplay_end_trigger_charpos
= 0;
8253 /* Since we are *trying* to run these functions, don't try to run
8254 them again, even if they get an error. */
8255 wset_redisplay_end_trigger (it
->w
, Qnil
);
8256 Frun_hook_with_args (3, args
);
8258 /* Notice if it changed the face of the character we are on. */
8259 handle_face_prop (it
);
8263 /* Deliver a composition display element. Unlike the other
8264 next_element_from_XXX, this function is not registered in the array
8265 get_next_element[]. It is called from next_element_from_buffer and
8266 next_element_from_string when necessary. */
8269 next_element_from_composition (struct it
*it
)
8271 it
->what
= IT_COMPOSITION
;
8272 it
->len
= it
->cmp_it
.nbytes
;
8273 if (STRINGP (it
->string
))
8277 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
8278 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
8281 it
->position
= it
->current
.string_pos
;
8282 it
->object
= it
->string
;
8283 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
8284 IT_STRING_BYTEPOS (*it
), it
->string
);
8290 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
8291 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
8294 if (it
->bidi_it
.new_paragraph
)
8295 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
8296 /* Resync the bidi iterator with IT's new position.
8297 FIXME: this doesn't support bidirectional text. */
8298 while (it
->bidi_it
.charpos
< IT_CHARPOS (*it
))
8299 bidi_move_to_visually_next (&it
->bidi_it
);
8303 it
->position
= it
->current
.pos
;
8304 it
->object
= it
->w
->contents
;
8305 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
8306 IT_BYTEPOS (*it
), Qnil
);
8313 /***********************************************************************
8314 Moving an iterator without producing glyphs
8315 ***********************************************************************/
8317 /* Check if iterator is at a position corresponding to a valid buffer
8318 position after some move_it_ call. */
8320 #define IT_POS_VALID_AFTER_MOVE_P(it) \
8321 ((it)->method == GET_FROM_STRING \
8322 ? IT_STRING_CHARPOS (*it) == 0 \
8326 /* Move iterator IT to a specified buffer or X position within one
8327 line on the display without producing glyphs.
8329 OP should be a bit mask including some or all of these bits:
8330 MOVE_TO_X: Stop upon reaching x-position TO_X.
8331 MOVE_TO_POS: Stop upon reaching buffer or string position TO_CHARPOS.
8332 Regardless of OP's value, stop upon reaching the end of the display line.
8334 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
8335 This means, in particular, that TO_X includes window's horizontal
8338 The return value has several possible values that
8339 say what condition caused the scan to stop:
8341 MOVE_POS_MATCH_OR_ZV
8342 - when TO_POS or ZV was reached.
8345 -when TO_X was reached before TO_POS or ZV were reached.
8348 - when we reached the end of the display area and the line must
8352 - when we reached the end of the display area and the line is
8356 - when we stopped at a line end, i.e. a newline or a CR and selective
8359 static enum move_it_result
8360 move_it_in_display_line_to (struct it
*it
,
8361 ptrdiff_t to_charpos
, int to_x
,
8362 enum move_operation_enum op
)
8364 enum move_it_result result
= MOVE_UNDEFINED
;
8365 struct glyph_row
*saved_glyph_row
;
8366 struct it wrap_it
, atpos_it
, atx_it
, ppos_it
;
8367 void *wrap_data
= NULL
, *atpos_data
= NULL
, *atx_data
= NULL
;
8368 void *ppos_data
= NULL
;
8370 enum it_method prev_method
= it
->method
;
8371 ptrdiff_t prev_pos
= IT_CHARPOS (*it
);
8372 int saw_smaller_pos
= prev_pos
< to_charpos
;
8374 /* Don't produce glyphs in produce_glyphs. */
8375 saved_glyph_row
= it
->glyph_row
;
8376 it
->glyph_row
= NULL
;
8378 /* Use wrap_it to save a copy of IT wherever a word wrap could
8379 occur. Use atpos_it to save a copy of IT at the desired buffer
8380 position, if found, so that we can scan ahead and check if the
8381 word later overshoots the window edge. Use atx_it similarly, for
8387 /* Use ppos_it under bidi reordering to save a copy of IT for the
8388 position > CHARPOS that is the closest to CHARPOS. We restore
8389 that position in IT when we have scanned the entire display line
8390 without finding a match for CHARPOS and all the character
8391 positions are greater than CHARPOS. */
8394 SAVE_IT (ppos_it
, *it
, ppos_data
);
8395 SET_TEXT_POS (ppos_it
.current
.pos
, ZV
, ZV_BYTE
);
8396 if ((op
& MOVE_TO_POS
) && IT_CHARPOS (*it
) >= to_charpos
)
8397 SAVE_IT (ppos_it
, *it
, ppos_data
);
8400 #define BUFFER_POS_REACHED_P() \
8401 ((op & MOVE_TO_POS) != 0 \
8402 && BUFFERP (it->object) \
8403 && (IT_CHARPOS (*it) == to_charpos \
8405 || BIDI_AT_BASE_LEVEL (it->bidi_it)) \
8406 && IT_CHARPOS (*it) > to_charpos) \
8407 || (it->what == IT_COMPOSITION \
8408 && ((IT_CHARPOS (*it) > to_charpos \
8409 && to_charpos >= it->cmp_it.charpos) \
8410 || (IT_CHARPOS (*it) < to_charpos \
8411 && to_charpos <= it->cmp_it.charpos)))) \
8412 && (it->method == GET_FROM_BUFFER \
8413 || (it->method == GET_FROM_DISPLAY_VECTOR \
8414 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
8416 /* If there's a line-/wrap-prefix, handle it. */
8417 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
8418 && it
->current_y
< it
->last_visible_y
)
8419 handle_line_prefix (it
);
8421 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8422 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8426 int x
, i
, ascent
= 0, descent
= 0;
8428 /* Utility macro to reset an iterator with x, ascent, and descent. */
8429 #define IT_RESET_X_ASCENT_DESCENT(IT) \
8430 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
8431 (IT)->max_descent = descent)
8433 /* Stop if we move beyond TO_CHARPOS (after an image or a
8434 display string or stretch glyph). */
8435 if ((op
& MOVE_TO_POS
) != 0
8436 && BUFFERP (it
->object
)
8437 && it
->method
== GET_FROM_BUFFER
8439 /* When the iterator is at base embedding level, we
8440 are guaranteed that characters are delivered for
8441 display in strictly increasing order of their
8442 buffer positions. */
8443 || BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8444 && IT_CHARPOS (*it
) > to_charpos
)
8446 && (prev_method
== GET_FROM_IMAGE
8447 || prev_method
== GET_FROM_STRETCH
8448 || prev_method
== GET_FROM_STRING
)
8449 /* Passed TO_CHARPOS from left to right. */
8450 && ((prev_pos
< to_charpos
8451 && IT_CHARPOS (*it
) > to_charpos
)
8452 /* Passed TO_CHARPOS from right to left. */
8453 || (prev_pos
> to_charpos
8454 && IT_CHARPOS (*it
) < to_charpos
)))))
8456 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8458 result
= MOVE_POS_MATCH_OR_ZV
;
8461 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8462 /* If wrap_it is valid, the current position might be in a
8463 word that is wrapped. So, save the iterator in
8464 atpos_it and continue to see if wrapping happens. */
8465 SAVE_IT (atpos_it
, *it
, atpos_data
);
8468 /* Stop when ZV reached.
8469 We used to stop here when TO_CHARPOS reached as well, but that is
8470 too soon if this glyph does not fit on this line. So we handle it
8471 explicitly below. */
8472 if (!get_next_display_element (it
))
8474 result
= MOVE_POS_MATCH_OR_ZV
;
8478 if (it
->line_wrap
== TRUNCATE
)
8480 if (BUFFER_POS_REACHED_P ())
8482 result
= MOVE_POS_MATCH_OR_ZV
;
8488 if (it
->line_wrap
== WORD_WRAP
)
8490 if (IT_DISPLAYING_WHITESPACE (it
))
8494 /* We have reached a glyph that follows one or more
8495 whitespace characters. If the position is
8496 already found, we are done. */
8497 if (atpos_it
.sp
>= 0)
8499 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8500 result
= MOVE_POS_MATCH_OR_ZV
;
8505 RESTORE_IT (it
, &atx_it
, atx_data
);
8506 result
= MOVE_X_REACHED
;
8509 /* Otherwise, we can wrap here. */
8510 SAVE_IT (wrap_it
, *it
, wrap_data
);
8516 /* Remember the line height for the current line, in case
8517 the next element doesn't fit on the line. */
8518 ascent
= it
->max_ascent
;
8519 descent
= it
->max_descent
;
8521 /* The call to produce_glyphs will get the metrics of the
8522 display element IT is loaded with. Record the x-position
8523 before this display element, in case it doesn't fit on the
8527 PRODUCE_GLYPHS (it
);
8529 if (it
->area
!= TEXT_AREA
)
8531 prev_method
= it
->method
;
8532 if (it
->method
== GET_FROM_BUFFER
)
8533 prev_pos
= IT_CHARPOS (*it
);
8534 set_iterator_to_next (it
, 1);
8535 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8536 SET_TEXT_POS (this_line_min_pos
,
8537 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8539 && (op
& MOVE_TO_POS
)
8540 && IT_CHARPOS (*it
) > to_charpos
8541 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8542 SAVE_IT (ppos_it
, *it
, ppos_data
);
8546 /* The number of glyphs we get back in IT->nglyphs will normally
8547 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
8548 character on a terminal frame, or (iii) a line end. For the
8549 second case, IT->nglyphs - 1 padding glyphs will be present.
8550 (On X frames, there is only one glyph produced for a
8551 composite character.)
8553 The behavior implemented below means, for continuation lines,
8554 that as many spaces of a TAB as fit on the current line are
8555 displayed there. For terminal frames, as many glyphs of a
8556 multi-glyph character are displayed in the current line, too.
8557 This is what the old redisplay code did, and we keep it that
8558 way. Under X, the whole shape of a complex character must
8559 fit on the line or it will be completely displayed in the
8562 Note that both for tabs and padding glyphs, all glyphs have
8566 /* More than one glyph or glyph doesn't fit on line. All
8567 glyphs have the same width. */
8568 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
8570 int x_before_this_char
= x
;
8571 int hpos_before_this_char
= it
->hpos
;
8573 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
8575 new_x
= x
+ single_glyph_width
;
8577 /* We want to leave anything reaching TO_X to the caller. */
8578 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
8580 if (BUFFER_POS_REACHED_P ())
8582 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8583 goto buffer_pos_reached
;
8584 if (atpos_it
.sp
< 0)
8586 SAVE_IT (atpos_it
, *it
, atpos_data
);
8587 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8592 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8595 result
= MOVE_X_REACHED
;
8600 SAVE_IT (atx_it
, *it
, atx_data
);
8601 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
8606 if (/* Lines are continued. */
8607 it
->line_wrap
!= TRUNCATE
8608 && (/* And glyph doesn't fit on the line. */
8609 new_x
> it
->last_visible_x
8610 /* Or it fits exactly and we're on a window
8612 || (new_x
== it
->last_visible_x
8613 && FRAME_WINDOW_P (it
->f
)
8614 && ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
8615 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8616 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
8618 if (/* IT->hpos == 0 means the very first glyph
8619 doesn't fit on the line, e.g. a wide image. */
8621 || (new_x
== it
->last_visible_x
8622 && FRAME_WINDOW_P (it
->f
)))
8625 it
->current_x
= new_x
;
8627 /* The character's last glyph just barely fits
8629 if (i
== it
->nglyphs
- 1)
8631 /* If this is the destination position,
8632 return a position *before* it in this row,
8633 now that we know it fits in this row. */
8634 if (BUFFER_POS_REACHED_P ())
8636 if (it
->line_wrap
!= WORD_WRAP
8639 it
->hpos
= hpos_before_this_char
;
8640 it
->current_x
= x_before_this_char
;
8641 result
= MOVE_POS_MATCH_OR_ZV
;
8644 if (it
->line_wrap
== WORD_WRAP
8647 SAVE_IT (atpos_it
, *it
, atpos_data
);
8648 atpos_it
.current_x
= x_before_this_char
;
8649 atpos_it
.hpos
= hpos_before_this_char
;
8653 prev_method
= it
->method
;
8654 if (it
->method
== GET_FROM_BUFFER
)
8655 prev_pos
= IT_CHARPOS (*it
);
8656 set_iterator_to_next (it
, 1);
8657 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8658 SET_TEXT_POS (this_line_min_pos
,
8659 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8660 /* On graphical terminals, newlines may
8661 "overflow" into the fringe if
8662 overflow-newline-into-fringe is non-nil.
8663 On text terminals, and on graphical
8664 terminals with no right margin, newlines
8665 may overflow into the last glyph on the
8667 if (!FRAME_WINDOW_P (it
->f
)
8669 && it
->bidi_it
.paragraph_dir
== R2L
)
8670 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8671 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0
8672 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8674 if (!get_next_display_element (it
))
8676 result
= MOVE_POS_MATCH_OR_ZV
;
8679 if (BUFFER_POS_REACHED_P ())
8681 if (ITERATOR_AT_END_OF_LINE_P (it
))
8682 result
= MOVE_POS_MATCH_OR_ZV
;
8684 result
= MOVE_LINE_CONTINUED
;
8687 if (ITERATOR_AT_END_OF_LINE_P (it
)
8688 && (it
->line_wrap
!= WORD_WRAP
8691 result
= MOVE_NEWLINE_OR_CR
;
8698 IT_RESET_X_ASCENT_DESCENT (it
);
8700 if (wrap_it
.sp
>= 0)
8702 RESTORE_IT (it
, &wrap_it
, wrap_data
);
8707 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
8709 result
= MOVE_LINE_CONTINUED
;
8713 if (BUFFER_POS_REACHED_P ())
8715 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8716 goto buffer_pos_reached
;
8717 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8719 SAVE_IT (atpos_it
, *it
, atpos_data
);
8720 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8724 if (new_x
> it
->first_visible_x
)
8726 /* Glyph is visible. Increment number of glyphs that
8727 would be displayed. */
8732 if (result
!= MOVE_UNDEFINED
)
8735 else if (BUFFER_POS_REACHED_P ())
8738 IT_RESET_X_ASCENT_DESCENT (it
);
8739 result
= MOVE_POS_MATCH_OR_ZV
;
8742 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
8744 /* Stop when TO_X specified and reached. This check is
8745 necessary here because of lines consisting of a line end,
8746 only. The line end will not produce any glyphs and we
8747 would never get MOVE_X_REACHED. */
8748 eassert (it
->nglyphs
== 0);
8749 result
= MOVE_X_REACHED
;
8753 /* Is this a line end? If yes, we're done. */
8754 if (ITERATOR_AT_END_OF_LINE_P (it
))
8756 /* If we are past TO_CHARPOS, but never saw any character
8757 positions smaller than TO_CHARPOS, return
8758 MOVE_POS_MATCH_OR_ZV, like the unidirectional display
8760 if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0)
8762 if (!saw_smaller_pos
&& IT_CHARPOS (*it
) > to_charpos
)
8764 if (IT_CHARPOS (ppos_it
) < ZV
)
8766 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8767 result
= MOVE_POS_MATCH_OR_ZV
;
8770 goto buffer_pos_reached
;
8772 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
>= 0
8773 && IT_CHARPOS (*it
) > to_charpos
)
8774 goto buffer_pos_reached
;
8776 result
= MOVE_NEWLINE_OR_CR
;
8779 result
= MOVE_NEWLINE_OR_CR
;
8783 prev_method
= it
->method
;
8784 if (it
->method
== GET_FROM_BUFFER
)
8785 prev_pos
= IT_CHARPOS (*it
);
8786 /* The current display element has been consumed. Advance
8788 set_iterator_to_next (it
, 1);
8789 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8790 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8791 if (IT_CHARPOS (*it
) < to_charpos
)
8792 saw_smaller_pos
= 1;
8794 && (op
& MOVE_TO_POS
)
8795 && IT_CHARPOS (*it
) >= to_charpos
8796 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8797 SAVE_IT (ppos_it
, *it
, ppos_data
);
8799 /* Stop if lines are truncated and IT's current x-position is
8800 past the right edge of the window now. */
8801 if (it
->line_wrap
== TRUNCATE
8802 && it
->current_x
>= it
->last_visible_x
)
8804 if (!FRAME_WINDOW_P (it
->f
)
8805 || ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
8806 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8807 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0
8808 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8812 if ((at_eob_p
= !get_next_display_element (it
))
8813 || BUFFER_POS_REACHED_P ()
8814 /* If we are past TO_CHARPOS, but never saw any
8815 character positions smaller than TO_CHARPOS,
8816 return MOVE_POS_MATCH_OR_ZV, like the
8817 unidirectional display did. */
8818 || (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8820 && IT_CHARPOS (*it
) > to_charpos
))
8823 && !at_eob_p
&& IT_CHARPOS (ppos_it
) < ZV
)
8824 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8825 result
= MOVE_POS_MATCH_OR_ZV
;
8828 if (ITERATOR_AT_END_OF_LINE_P (it
))
8830 result
= MOVE_NEWLINE_OR_CR
;
8834 else if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8836 && IT_CHARPOS (*it
) > to_charpos
)
8838 if (IT_CHARPOS (ppos_it
) < ZV
)
8839 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8840 result
= MOVE_POS_MATCH_OR_ZV
;
8843 result
= MOVE_LINE_TRUNCATED
;
8846 #undef IT_RESET_X_ASCENT_DESCENT
8849 #undef BUFFER_POS_REACHED_P
8851 /* If we scanned beyond to_pos and didn't find a point to wrap at,
8852 restore the saved iterator. */
8853 if (atpos_it
.sp
>= 0)
8854 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8855 else if (atx_it
.sp
>= 0)
8856 RESTORE_IT (it
, &atx_it
, atx_data
);
8861 bidi_unshelve_cache (atpos_data
, 1);
8863 bidi_unshelve_cache (atx_data
, 1);
8865 bidi_unshelve_cache (wrap_data
, 1);
8867 bidi_unshelve_cache (ppos_data
, 1);
8869 /* Restore the iterator settings altered at the beginning of this
8871 it
->glyph_row
= saved_glyph_row
;
8875 /* For external use. */
8877 move_it_in_display_line (struct it
*it
,
8878 ptrdiff_t to_charpos
, int to_x
,
8879 enum move_operation_enum op
)
8881 if (it
->line_wrap
== WORD_WRAP
8882 && (op
& MOVE_TO_X
))
8885 void *save_data
= NULL
;
8888 SAVE_IT (save_it
, *it
, save_data
);
8889 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8890 /* When word-wrap is on, TO_X may lie past the end
8891 of a wrapped line. Then it->current is the
8892 character on the next line, so backtrack to the
8893 space before the wrap point. */
8894 if (skip
== MOVE_LINE_CONTINUED
)
8896 int prev_x
= max (it
->current_x
- 1, 0);
8897 RESTORE_IT (it
, &save_it
, save_data
);
8898 move_it_in_display_line_to
8899 (it
, -1, prev_x
, MOVE_TO_X
);
8902 bidi_unshelve_cache (save_data
, 1);
8905 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8909 /* Move IT forward until it satisfies one or more of the criteria in
8910 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
8912 OP is a bit-mask that specifies where to stop, and in particular,
8913 which of those four position arguments makes a difference. See the
8914 description of enum move_operation_enum.
8916 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
8917 screen line, this function will set IT to the next position that is
8918 displayed to the right of TO_CHARPOS on the screen. */
8921 move_it_to (struct it
*it
, ptrdiff_t to_charpos
, int to_x
, int to_y
, int to_vpos
, int op
)
8923 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
8924 int line_height
, line_start_x
= 0, reached
= 0;
8925 void *backup_data
= NULL
;
8929 if (op
& MOVE_TO_VPOS
)
8931 /* If no TO_CHARPOS and no TO_X specified, stop at the
8932 start of the line TO_VPOS. */
8933 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
8935 if (it
->vpos
== to_vpos
)
8941 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
8945 /* TO_VPOS >= 0 means stop at TO_X in the line at
8946 TO_VPOS, or at TO_POS, whichever comes first. */
8947 if (it
->vpos
== to_vpos
)
8953 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8955 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
8960 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
8962 /* We have reached TO_X but not in the line we want. */
8963 skip
= move_it_in_display_line_to (it
, to_charpos
,
8965 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8973 else if (op
& MOVE_TO_Y
)
8975 struct it it_backup
;
8977 if (it
->line_wrap
== WORD_WRAP
)
8978 SAVE_IT (it_backup
, *it
, backup_data
);
8980 /* TO_Y specified means stop at TO_X in the line containing
8981 TO_Y---or at TO_CHARPOS if this is reached first. The
8982 problem is that we can't really tell whether the line
8983 contains TO_Y before we have completely scanned it, and
8984 this may skip past TO_X. What we do is to first scan to
8987 If TO_X is not specified, use a TO_X of zero. The reason
8988 is to make the outcome of this function more predictable.
8989 If we didn't use TO_X == 0, we would stop at the end of
8990 the line which is probably not what a caller would expect
8992 skip
= move_it_in_display_line_to
8993 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
8994 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
8996 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
8997 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8999 else if (skip
== MOVE_X_REACHED
)
9001 /* If TO_X was reached, we want to know whether TO_Y is
9002 in the line. We know this is the case if the already
9003 scanned glyphs make the line tall enough. Otherwise,
9004 we must check by scanning the rest of the line. */
9005 line_height
= it
->max_ascent
+ it
->max_descent
;
9006 if (to_y
>= it
->current_y
9007 && to_y
< it
->current_y
+ line_height
)
9012 SAVE_IT (it_backup
, *it
, backup_data
);
9013 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
9014 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
9016 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
9017 line_height
= it
->max_ascent
+ it
->max_descent
;
9018 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
9020 if (to_y
>= it
->current_y
9021 && to_y
< it
->current_y
+ line_height
)
9023 /* If TO_Y is in this line and TO_X was reached
9024 above, we scanned too far. We have to restore
9025 IT's settings to the ones before skipping. But
9026 keep the more accurate values of max_ascent and
9027 max_descent we've found while skipping the rest
9028 of the line, for the sake of callers, such as
9029 pos_visible_p, that need to know the line
9031 int max_ascent
= it
->max_ascent
;
9032 int max_descent
= it
->max_descent
;
9034 RESTORE_IT (it
, &it_backup
, backup_data
);
9035 it
->max_ascent
= max_ascent
;
9036 it
->max_descent
= max_descent
;
9042 if (skip
== MOVE_POS_MATCH_OR_ZV
)
9048 /* Check whether TO_Y is in this line. */
9049 line_height
= it
->max_ascent
+ it
->max_descent
;
9050 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
9052 if (to_y
>= it
->current_y
9053 && to_y
< it
->current_y
+ line_height
)
9055 /* When word-wrap is on, TO_X may lie past the end
9056 of a wrapped line. Then it->current is the
9057 character on the next line, so backtrack to the
9058 space before the wrap point. */
9059 if (skip
== MOVE_LINE_CONTINUED
9060 && it
->line_wrap
== WORD_WRAP
)
9062 int prev_x
= max (it
->current_x
- 1, 0);
9063 RESTORE_IT (it
, &it_backup
, backup_data
);
9064 skip
= move_it_in_display_line_to
9065 (it
, -1, prev_x
, MOVE_TO_X
);
9074 else if (BUFFERP (it
->object
)
9075 && (it
->method
== GET_FROM_BUFFER
9076 || it
->method
== GET_FROM_STRETCH
)
9077 && IT_CHARPOS (*it
) >= to_charpos
9078 /* Under bidi iteration, a call to set_iterator_to_next
9079 can scan far beyond to_charpos if the initial
9080 portion of the next line needs to be reordered. In
9081 that case, give move_it_in_display_line_to another
9084 && it
->bidi_it
.scan_dir
== -1))
9085 skip
= MOVE_POS_MATCH_OR_ZV
;
9087 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
9091 case MOVE_POS_MATCH_OR_ZV
:
9095 case MOVE_NEWLINE_OR_CR
:
9096 set_iterator_to_next (it
, 1);
9097 it
->continuation_lines_width
= 0;
9100 case MOVE_LINE_TRUNCATED
:
9101 it
->continuation_lines_width
= 0;
9102 reseat_at_next_visible_line_start (it
, 0);
9103 if ((op
& MOVE_TO_POS
) != 0
9104 && IT_CHARPOS (*it
) > to_charpos
)
9111 case MOVE_LINE_CONTINUED
:
9112 /* For continued lines ending in a tab, some of the glyphs
9113 associated with the tab are displayed on the current
9114 line. Since it->current_x does not include these glyphs,
9115 we use it->last_visible_x instead. */
9118 it
->continuation_lines_width
+= it
->last_visible_x
;
9119 /* When moving by vpos, ensure that the iterator really
9120 advances to the next line (bug#847, bug#969). Fixme:
9121 do we need to do this in other circumstances? */
9122 if (it
->current_x
!= it
->last_visible_x
9123 && (op
& MOVE_TO_VPOS
)
9124 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
9126 line_start_x
= it
->current_x
+ it
->pixel_width
9127 - it
->last_visible_x
;
9128 set_iterator_to_next (it
, 0);
9132 it
->continuation_lines_width
+= it
->current_x
;
9139 /* Reset/increment for the next run. */
9140 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
9141 it
->current_x
= line_start_x
;
9144 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
9146 last_height
= it
->max_ascent
+ it
->max_descent
;
9147 it
->max_ascent
= it
->max_descent
= 0;
9152 /* On text terminals, we may stop at the end of a line in the middle
9153 of a multi-character glyph. If the glyph itself is continued,
9154 i.e. it is actually displayed on the next line, don't treat this
9155 stopping point as valid; move to the next line instead (unless
9156 that brings us offscreen). */
9157 if (!FRAME_WINDOW_P (it
->f
)
9159 && IT_CHARPOS (*it
) == to_charpos
9160 && it
->what
== IT_CHARACTER
9162 && it
->line_wrap
== WINDOW_WRAP
9163 && it
->current_x
== it
->last_visible_x
- 1
9166 && it
->vpos
< it
->w
->window_end_vpos
)
9168 it
->continuation_lines_width
+= it
->current_x
;
9169 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
9170 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
9172 last_height
= it
->max_ascent
+ it
->max_descent
;
9176 bidi_unshelve_cache (backup_data
, 1);
9178 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
9182 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
9184 If DY > 0, move IT backward at least that many pixels. DY = 0
9185 means move IT backward to the preceding line start or BEGV. This
9186 function may move over more than DY pixels if IT->current_y - DY
9187 ends up in the middle of a line; in this case IT->current_y will be
9188 set to the top of the line moved to. */
9191 move_it_vertically_backward (struct it
*it
, int dy
)
9195 void *it2data
= NULL
, *it3data
= NULL
;
9196 ptrdiff_t start_pos
;
9198 = (it
->last_visible_x
- it
->first_visible_x
) / FRAME_COLUMN_WIDTH (it
->f
);
9199 ptrdiff_t pos_limit
;
9204 start_pos
= IT_CHARPOS (*it
);
9206 /* Estimate how many newlines we must move back. */
9207 nlines
= max (1, dy
/ default_line_pixel_height (it
->w
));
9208 if (it
->line_wrap
== TRUNCATE
)
9211 pos_limit
= max (start_pos
- nlines
* nchars_per_row
, BEGV
);
9213 /* Set the iterator's position that many lines back. But don't go
9214 back more than NLINES full screen lines -- this wins a day with
9215 buffers which have very long lines. */
9216 while (nlines
-- && IT_CHARPOS (*it
) > pos_limit
)
9217 back_to_previous_visible_line_start (it
);
9219 /* Reseat the iterator here. When moving backward, we don't want
9220 reseat to skip forward over invisible text, set up the iterator
9221 to deliver from overlay strings at the new position etc. So,
9222 use reseat_1 here. */
9223 reseat_1 (it
, it
->current
.pos
, 1);
9225 /* We are now surely at a line start. */
9226 it
->current_x
= it
->hpos
= 0; /* FIXME: this is incorrect when bidi
9227 reordering is in effect. */
9228 it
->continuation_lines_width
= 0;
9230 /* Move forward and see what y-distance we moved. First move to the
9231 start of the next line so that we get its height. We need this
9232 height to be able to tell whether we reached the specified
9234 SAVE_IT (it2
, *it
, it2data
);
9235 it2
.max_ascent
= it2
.max_descent
= 0;
9238 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
9239 MOVE_TO_POS
| MOVE_TO_VPOS
);
9241 while (!(IT_POS_VALID_AFTER_MOVE_P (&it2
)
9242 /* If we are in a display string which starts at START_POS,
9243 and that display string includes a newline, and we are
9244 right after that newline (i.e. at the beginning of a
9245 display line), exit the loop, because otherwise we will
9246 infloop, since move_it_to will see that it is already at
9247 START_POS and will not move. */
9248 || (it2
.method
== GET_FROM_STRING
9249 && IT_CHARPOS (it2
) == start_pos
9250 && SREF (it2
.string
, IT_STRING_BYTEPOS (it2
) - 1) == '\n')));
9251 eassert (IT_CHARPOS (*it
) >= BEGV
);
9252 SAVE_IT (it3
, it2
, it3data
);
9254 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
9255 eassert (IT_CHARPOS (*it
) >= BEGV
);
9256 /* H is the actual vertical distance from the position in *IT
9257 and the starting position. */
9258 h
= it2
.current_y
- it
->current_y
;
9259 /* NLINES is the distance in number of lines. */
9260 nlines
= it2
.vpos
- it
->vpos
;
9262 /* Correct IT's y and vpos position
9263 so that they are relative to the starting point. */
9269 /* DY == 0 means move to the start of the screen line. The
9270 value of nlines is > 0 if continuation lines were involved,
9271 or if the original IT position was at start of a line. */
9272 RESTORE_IT (it
, it
, it2data
);
9274 move_it_by_lines (it
, nlines
);
9275 /* The above code moves us to some position NLINES down,
9276 usually to its first glyph (leftmost in an L2R line), but
9277 that's not necessarily the start of the line, under bidi
9278 reordering. We want to get to the character position
9279 that is immediately after the newline of the previous
9282 && !it
->continuation_lines_width
9283 && !STRINGP (it
->string
)
9284 && IT_CHARPOS (*it
) > BEGV
9285 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9287 ptrdiff_t cp
= IT_CHARPOS (*it
), bp
= IT_BYTEPOS (*it
);
9290 cp
= find_newline_no_quit (cp
, bp
, -1, NULL
);
9291 move_it_to (it
, cp
, -1, -1, -1, MOVE_TO_POS
);
9293 bidi_unshelve_cache (it3data
, 1);
9297 /* The y-position we try to reach, relative to *IT.
9298 Note that H has been subtracted in front of the if-statement. */
9299 int target_y
= it
->current_y
+ h
- dy
;
9300 int y0
= it3
.current_y
;
9304 RESTORE_IT (&it3
, &it3
, it3data
);
9305 y1
= line_bottom_y (&it3
);
9306 line_height
= y1
- y0
;
9307 RESTORE_IT (it
, it
, it2data
);
9308 /* If we did not reach target_y, try to move further backward if
9309 we can. If we moved too far backward, try to move forward. */
9310 if (target_y
< it
->current_y
9311 /* This is heuristic. In a window that's 3 lines high, with
9312 a line height of 13 pixels each, recentering with point
9313 on the bottom line will try to move -39/2 = 19 pixels
9314 backward. Try to avoid moving into the first line. */
9315 && (it
->current_y
- target_y
9316 > min (window_box_height (it
->w
), line_height
* 2 / 3))
9317 && IT_CHARPOS (*it
) > BEGV
)
9319 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
9320 target_y
- it
->current_y
));
9321 dy
= it
->current_y
- target_y
;
9322 goto move_further_back
;
9324 else if (target_y
>= it
->current_y
+ line_height
9325 && IT_CHARPOS (*it
) < ZV
)
9327 /* Should move forward by at least one line, maybe more.
9329 Note: Calling move_it_by_lines can be expensive on
9330 terminal frames, where compute_motion is used (via
9331 vmotion) to do the job, when there are very long lines
9332 and truncate-lines is nil. That's the reason for
9333 treating terminal frames specially here. */
9335 if (!FRAME_WINDOW_P (it
->f
))
9336 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
9341 move_it_by_lines (it
, 1);
9343 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
9350 /* Move IT by a specified amount of pixel lines DY. DY negative means
9351 move backwards. DY = 0 means move to start of screen line. At the
9352 end, IT will be on the start of a screen line. */
9355 move_it_vertically (struct it
*it
, int dy
)
9358 move_it_vertically_backward (it
, -dy
);
9361 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
9362 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
9363 MOVE_TO_POS
| MOVE_TO_Y
);
9364 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
9366 /* If buffer ends in ZV without a newline, move to the start of
9367 the line to satisfy the post-condition. */
9368 if (IT_CHARPOS (*it
) == ZV
9370 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9371 move_it_by_lines (it
, 0);
9376 /* Move iterator IT past the end of the text line it is in. */
9379 move_it_past_eol (struct it
*it
)
9381 enum move_it_result rc
;
9383 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
9384 if (rc
== MOVE_NEWLINE_OR_CR
)
9385 set_iterator_to_next (it
, 0);
9389 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
9390 negative means move up. DVPOS == 0 means move to the start of the
9393 Optimization idea: If we would know that IT->f doesn't use
9394 a face with proportional font, we could be faster for
9395 truncate-lines nil. */
9398 move_it_by_lines (struct it
*it
, ptrdiff_t dvpos
)
9401 /* The commented-out optimization uses vmotion on terminals. This
9402 gives bad results, because elements like it->what, on which
9403 callers such as pos_visible_p rely, aren't updated. */
9404 /* struct position pos;
9405 if (!FRAME_WINDOW_P (it->f))
9407 struct text_pos textpos;
9409 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
9410 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
9411 reseat (it, textpos, 1);
9412 it->vpos += pos.vpos;
9413 it->current_y += pos.vpos;
9419 /* DVPOS == 0 means move to the start of the screen line. */
9420 move_it_vertically_backward (it
, 0);
9421 /* Let next call to line_bottom_y calculate real line height */
9426 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
9427 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
9429 /* Only move to the next buffer position if we ended up in a
9430 string from display property, not in an overlay string
9431 (before-string or after-string). That is because the
9432 latter don't conceal the underlying buffer position, so
9433 we can ask to move the iterator to the exact position we
9434 are interested in. Note that, even if we are already at
9435 IT_CHARPOS (*it), the call below is not a no-op, as it
9436 will detect that we are at the end of the string, pop the
9437 iterator, and compute it->current_x and it->hpos
9439 move_it_to (it
, IT_CHARPOS (*it
) + it
->string_from_display_prop_p
,
9440 -1, -1, -1, MOVE_TO_POS
);
9446 void *it2data
= NULL
;
9447 ptrdiff_t start_charpos
, i
;
9449 = (it
->last_visible_x
- it
->first_visible_x
) / FRAME_COLUMN_WIDTH (it
->f
);
9450 ptrdiff_t pos_limit
;
9452 /* Start at the beginning of the screen line containing IT's
9453 position. This may actually move vertically backwards,
9454 in case of overlays, so adjust dvpos accordingly. */
9456 move_it_vertically_backward (it
, 0);
9459 /* Go back -DVPOS buffer lines, but no farther than -DVPOS full
9460 screen lines, and reseat the iterator there. */
9461 start_charpos
= IT_CHARPOS (*it
);
9462 if (it
->line_wrap
== TRUNCATE
)
9465 pos_limit
= max (start_charpos
+ dvpos
* nchars_per_row
, BEGV
);
9466 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > pos_limit
; --i
)
9467 back_to_previous_visible_line_start (it
);
9468 reseat (it
, it
->current
.pos
, 1);
9470 /* Move further back if we end up in a string or an image. */
9471 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
9473 /* First try to move to start of display line. */
9475 move_it_vertically_backward (it
, 0);
9477 if (IT_POS_VALID_AFTER_MOVE_P (it
))
9479 /* If start of line is still in string or image,
9480 move further back. */
9481 back_to_previous_visible_line_start (it
);
9482 reseat (it
, it
->current
.pos
, 1);
9486 it
->current_x
= it
->hpos
= 0;
9488 /* Above call may have moved too far if continuation lines
9489 are involved. Scan forward and see if it did. */
9490 SAVE_IT (it2
, *it
, it2data
);
9491 it2
.vpos
= it2
.current_y
= 0;
9492 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
9493 it
->vpos
-= it2
.vpos
;
9494 it
->current_y
-= it2
.current_y
;
9495 it
->current_x
= it
->hpos
= 0;
9497 /* If we moved too far back, move IT some lines forward. */
9498 if (it2
.vpos
> -dvpos
)
9500 int delta
= it2
.vpos
+ dvpos
;
9502 RESTORE_IT (&it2
, &it2
, it2data
);
9503 SAVE_IT (it2
, *it
, it2data
);
9504 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
9505 /* Move back again if we got too far ahead. */
9506 if (IT_CHARPOS (*it
) >= start_charpos
)
9507 RESTORE_IT (it
, &it2
, it2data
);
9509 bidi_unshelve_cache (it2data
, 1);
9512 RESTORE_IT (it
, it
, it2data
);
9516 /* Return 1 if IT points into the middle of a display vector. */
9519 in_display_vector_p (struct it
*it
)
9521 return (it
->method
== GET_FROM_DISPLAY_VECTOR
9522 && it
->current
.dpvec_index
> 0
9523 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
9527 /***********************************************************************
9529 ***********************************************************************/
9532 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
9536 add_to_log (const char *format
, Lisp_Object arg1
, Lisp_Object arg2
)
9538 Lisp_Object args
[3];
9539 Lisp_Object msg
, fmt
;
9542 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
9546 GCPRO4 (fmt
, msg
, arg1
, arg2
);
9548 args
[0] = fmt
= build_string (format
);
9551 msg
= Fformat (3, args
);
9553 len
= SBYTES (msg
) + 1;
9554 buffer
= SAFE_ALLOCA (len
);
9555 memcpy (buffer
, SDATA (msg
), len
);
9557 message_dolog (buffer
, len
- 1, 1, 0);
9564 /* Output a newline in the *Messages* buffer if "needs" one. */
9567 message_log_maybe_newline (void)
9569 if (message_log_need_newline
)
9570 message_dolog ("", 0, 1, 0);
9574 /* Add a string M of length NBYTES to the message log, optionally
9575 terminated with a newline when NLFLAG is true. MULTIBYTE, if
9576 true, means interpret the contents of M as multibyte. This
9577 function calls low-level routines in order to bypass text property
9578 hooks, etc. which might not be safe to run.
9580 This may GC (insert may run before/after change hooks),
9581 so the buffer M must NOT point to a Lisp string. */
9584 message_dolog (const char *m
, ptrdiff_t nbytes
, bool nlflag
, bool multibyte
)
9586 const unsigned char *msg
= (const unsigned char *) m
;
9588 if (!NILP (Vmemory_full
))
9591 if (!NILP (Vmessage_log_max
))
9593 struct buffer
*oldbuf
;
9594 Lisp_Object oldpoint
, oldbegv
, oldzv
;
9595 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
9596 ptrdiff_t point_at_end
= 0;
9597 ptrdiff_t zv_at_end
= 0;
9598 Lisp_Object old_deactivate_mark
;
9600 struct gcpro gcpro1
;
9602 old_deactivate_mark
= Vdeactivate_mark
;
9603 oldbuf
= current_buffer
;
9604 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
9605 bset_undo_list (current_buffer
, Qt
);
9607 oldpoint
= message_dolog_marker1
;
9608 set_marker_restricted_both (oldpoint
, Qnil
, PT
, PT_BYTE
);
9609 oldbegv
= message_dolog_marker2
;
9610 set_marker_restricted_both (oldbegv
, Qnil
, BEGV
, BEGV_BYTE
);
9611 oldzv
= message_dolog_marker3
;
9612 set_marker_restricted_both (oldzv
, Qnil
, ZV
, ZV_BYTE
);
9613 GCPRO1 (old_deactivate_mark
);
9621 BEGV_BYTE
= BEG_BYTE
;
9624 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9626 /* Insert the string--maybe converting multibyte to single byte
9627 or vice versa, so that all the text fits the buffer. */
9629 && NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9635 /* Convert a multibyte string to single-byte
9636 for the *Message* buffer. */
9637 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
9639 c
= string_char_and_length (msg
+ i
, &char_bytes
);
9640 work
[0] = (ASCII_CHAR_P (c
)
9642 : multibyte_char_to_unibyte (c
));
9643 insert_1_both (work
, 1, 1, 1, 0, 0);
9646 else if (! multibyte
9647 && ! NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9651 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9652 /* Convert a single-byte string to multibyte
9653 for the *Message* buffer. */
9654 for (i
= 0; i
< nbytes
; i
++)
9657 MAKE_CHAR_MULTIBYTE (c
);
9658 char_bytes
= CHAR_STRING (c
, str
);
9659 insert_1_both ((char *) str
, 1, char_bytes
, 1, 0, 0);
9663 insert_1_both (m
, chars_in_text (msg
, nbytes
), nbytes
, 1, 0, 0);
9667 ptrdiff_t this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
;
9670 insert_1_both ("\n", 1, 1, 1, 0, 0);
9672 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9674 this_bol_byte
= PT_BYTE
;
9676 /* See if this line duplicates the previous one.
9677 If so, combine duplicates. */
9680 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9682 prev_bol_byte
= PT_BYTE
;
9684 dups
= message_log_check_duplicate (prev_bol_byte
,
9688 del_range_both (prev_bol
, prev_bol_byte
,
9689 this_bol
, this_bol_byte
, 0);
9692 char dupstr
[sizeof " [ times]"
9693 + INT_STRLEN_BOUND (printmax_t
)];
9695 /* If you change this format, don't forget to also
9696 change message_log_check_duplicate. */
9697 int duplen
= sprintf (dupstr
, " [%"pMd
" times]", dups
);
9698 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
9699 insert_1_both (dupstr
, duplen
, duplen
, 1, 0, 1);
9704 /* If we have more than the desired maximum number of lines
9705 in the *Messages* buffer now, delete the oldest ones.
9706 This is safe because we don't have undo in this buffer. */
9708 if (NATNUMP (Vmessage_log_max
))
9710 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
9711 -XFASTINT (Vmessage_log_max
) - 1, 0);
9712 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
9715 BEGV
= marker_position (oldbegv
);
9716 BEGV_BYTE
= marker_byte_position (oldbegv
);
9725 ZV
= marker_position (oldzv
);
9726 ZV_BYTE
= marker_byte_position (oldzv
);
9730 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9732 /* We can't do Fgoto_char (oldpoint) because it will run some
9734 TEMP_SET_PT_BOTH (marker_position (oldpoint
),
9735 marker_byte_position (oldpoint
));
9738 unchain_marker (XMARKER (oldpoint
));
9739 unchain_marker (XMARKER (oldbegv
));
9740 unchain_marker (XMARKER (oldzv
));
9742 shown
= buffer_window_count (current_buffer
) > 0;
9743 set_buffer_internal (oldbuf
);
9744 /* We called insert_1_both above with its 5th argument (PREPARE)
9745 zero, which prevents insert_1_both from calling
9746 prepare_to_modify_buffer, which in turns prevents us from
9747 incrementing windows_or_buffers_changed even if *Messages* is
9748 shown in some window. So we must manually incrementing
9749 windows_or_buffers_changed here to make up for that. */
9751 windows_or_buffers_changed
++;
9753 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
9754 message_log_need_newline
= !nlflag
;
9755 Vdeactivate_mark
= old_deactivate_mark
;
9760 /* We are at the end of the buffer after just having inserted a newline.
9761 (Note: We depend on the fact we won't be crossing the gap.)
9762 Check to see if the most recent message looks a lot like the previous one.
9763 Return 0 if different, 1 if the new one should just replace it, or a
9764 value N > 1 if we should also append " [N times]". */
9767 message_log_check_duplicate (ptrdiff_t prev_bol_byte
, ptrdiff_t this_bol_byte
)
9770 ptrdiff_t len
= Z_BYTE
- 1 - this_bol_byte
;
9772 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
9773 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
9775 for (i
= 0; i
< len
; i
++)
9777 if (i
>= 3 && p1
[i
- 3] == '.' && p1
[i
- 2] == '.' && p1
[i
- 1] == '.')
9785 if (*p1
++ == ' ' && *p1
++ == '[')
9788 intmax_t n
= strtoimax ((char *) p1
, &pend
, 10);
9789 if (0 < n
&& n
< INTMAX_MAX
&& strncmp (pend
, " times]\n", 8) == 0)
9796 /* Display an echo area message M with a specified length of NBYTES
9797 bytes. The string may include null characters. If M is not a
9798 string, clear out any existing message, and let the mini-buffer
9801 This function cancels echoing. */
9804 message3 (Lisp_Object m
)
9806 struct gcpro gcpro1
;
9809 clear_message (1,1);
9812 /* First flush out any partial line written with print. */
9813 message_log_maybe_newline ();
9816 ptrdiff_t nbytes
= SBYTES (m
);
9817 bool multibyte
= STRING_MULTIBYTE (m
);
9819 char *buffer
= SAFE_ALLOCA (nbytes
);
9820 memcpy (buffer
, SDATA (m
), nbytes
);
9821 message_dolog (buffer
, nbytes
, 1, multibyte
);
9830 /* The non-logging version of message3.
9831 This does not cancel echoing, because it is used for echoing.
9832 Perhaps we need to make a separate function for echoing
9833 and make this cancel echoing. */
9836 message3_nolog (Lisp_Object m
)
9838 struct frame
*sf
= SELECTED_FRAME ();
9840 if (FRAME_INITIAL_P (sf
))
9842 if (noninteractive_need_newline
)
9843 putc ('\n', stderr
);
9844 noninteractive_need_newline
= 0;
9846 fwrite (SDATA (m
), SBYTES (m
), 1, stderr
);
9847 if (cursor_in_echo_area
== 0)
9848 fprintf (stderr
, "\n");
9851 /* Error messages get reported properly by cmd_error, so this must be just an
9852 informative message; if the frame hasn't really been initialized yet, just
9854 else if (INTERACTIVE
&& sf
->glyphs_initialized_p
)
9856 /* Get the frame containing the mini-buffer
9857 that the selected frame is using. */
9858 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9859 Lisp_Object frame
= XWINDOW (mini_window
)->frame
;
9860 struct frame
*f
= XFRAME (frame
);
9862 if (FRAME_VISIBLE_P (sf
) && !FRAME_VISIBLE_P (f
))
9863 Fmake_frame_visible (frame
);
9865 if (STRINGP (m
) && SCHARS (m
) > 0)
9868 if (minibuffer_auto_raise
)
9869 Fraise_frame (frame
);
9870 /* Assume we are not echoing.
9871 (If we are, echo_now will override this.) */
9872 echo_message_buffer
= Qnil
;
9875 clear_message (1, 1);
9877 do_pending_window_change (0);
9878 echo_area_display (1);
9879 do_pending_window_change (0);
9880 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
9881 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
9886 /* Display a null-terminated echo area message M. If M is 0, clear
9887 out any existing message, and let the mini-buffer text show through.
9889 The buffer M must continue to exist until after the echo area gets
9890 cleared or some other message gets displayed there. Do not pass
9891 text that is stored in a Lisp string. Do not pass text in a buffer
9892 that was alloca'd. */
9895 message1 (const char *m
)
9897 message3 (m
? build_unibyte_string (m
) : Qnil
);
9901 /* The non-logging counterpart of message1. */
9904 message1_nolog (const char *m
)
9906 message3_nolog (m
? build_unibyte_string (m
) : Qnil
);
9909 /* Display a message M which contains a single %s
9910 which gets replaced with STRING. */
9913 message_with_string (const char *m
, Lisp_Object string
, int log
)
9915 CHECK_STRING (string
);
9921 if (noninteractive_need_newline
)
9922 putc ('\n', stderr
);
9923 noninteractive_need_newline
= 0;
9924 fprintf (stderr
, m
, SDATA (string
));
9925 if (!cursor_in_echo_area
)
9926 fprintf (stderr
, "\n");
9930 else if (INTERACTIVE
)
9932 /* The frame whose minibuffer we're going to display the message on.
9933 It may be larger than the selected frame, so we need
9934 to use its buffer, not the selected frame's buffer. */
9935 Lisp_Object mini_window
;
9936 struct frame
*f
, *sf
= SELECTED_FRAME ();
9938 /* Get the frame containing the minibuffer
9939 that the selected frame is using. */
9940 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9941 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9943 /* Error messages get reported properly by cmd_error, so this must be
9944 just an informative message; if the frame hasn't really been
9945 initialized yet, just toss it. */
9946 if (f
->glyphs_initialized_p
)
9948 Lisp_Object args
[2], msg
;
9949 struct gcpro gcpro1
, gcpro2
;
9951 args
[0] = build_string (m
);
9952 args
[1] = msg
= string
;
9953 GCPRO2 (args
[0], msg
);
9956 msg
= Fformat (2, args
);
9961 message3_nolog (msg
);
9965 /* Print should start at the beginning of the message
9966 buffer next time. */
9967 message_buf_print
= 0;
9973 /* Dump an informative message to the minibuf. If M is 0, clear out
9974 any existing message, and let the mini-buffer text show through. */
9977 vmessage (const char *m
, va_list ap
)
9983 if (noninteractive_need_newline
)
9984 putc ('\n', stderr
);
9985 noninteractive_need_newline
= 0;
9986 vfprintf (stderr
, m
, ap
);
9987 if (cursor_in_echo_area
== 0)
9988 fprintf (stderr
, "\n");
9992 else if (INTERACTIVE
)
9994 /* The frame whose mini-buffer we're going to display the message
9995 on. It may be larger than the selected frame, so we need to
9996 use its buffer, not the selected frame's buffer. */
9997 Lisp_Object mini_window
;
9998 struct frame
*f
, *sf
= SELECTED_FRAME ();
10000 /* Get the frame containing the mini-buffer
10001 that the selected frame is using. */
10002 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10003 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
10005 /* Error messages get reported properly by cmd_error, so this must be
10006 just an informative message; if the frame hasn't really been
10007 initialized yet, just toss it. */
10008 if (f
->glyphs_initialized_p
)
10013 ptrdiff_t maxsize
= FRAME_MESSAGE_BUF_SIZE (f
);
10014 char *message_buf
= alloca (maxsize
+ 1);
10016 len
= doprnt (message_buf
, maxsize
, m
, 0, ap
);
10018 message3 (make_string (message_buf
, len
));
10023 /* Print should start at the beginning of the message
10024 buffer next time. */
10025 message_buf_print
= 0;
10031 message (const char *m
, ...)
10041 /* The non-logging version of message. */
10044 message_nolog (const char *m
, ...)
10046 Lisp_Object old_log_max
;
10049 old_log_max
= Vmessage_log_max
;
10050 Vmessage_log_max
= Qnil
;
10052 Vmessage_log_max
= old_log_max
;
10058 /* Display the current message in the current mini-buffer. This is
10059 only called from error handlers in process.c, and is not time
10063 update_echo_area (void)
10065 if (!NILP (echo_area_buffer
[0]))
10067 Lisp_Object string
;
10068 string
= Fcurrent_message ();
10074 /* Make sure echo area buffers in `echo_buffers' are live.
10075 If they aren't, make new ones. */
10078 ensure_echo_area_buffers (void)
10082 for (i
= 0; i
< 2; ++i
)
10083 if (!BUFFERP (echo_buffer
[i
])
10084 || !BUFFER_LIVE_P (XBUFFER (echo_buffer
[i
])))
10087 Lisp_Object old_buffer
;
10090 old_buffer
= echo_buffer
[i
];
10091 echo_buffer
[i
] = Fget_buffer_create
10092 (make_formatted_string (name
, " *Echo Area %d*", i
));
10093 bset_truncate_lines (XBUFFER (echo_buffer
[i
]), Qnil
);
10094 /* to force word wrap in echo area -
10095 it was decided to postpone this*/
10096 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
10098 for (j
= 0; j
< 2; ++j
)
10099 if (EQ (old_buffer
, echo_area_buffer
[j
]))
10100 echo_area_buffer
[j
] = echo_buffer
[i
];
10105 /* Call FN with args A1..A2 with either the current or last displayed
10106 echo_area_buffer as current buffer.
10108 WHICH zero means use the current message buffer
10109 echo_area_buffer[0]. If that is nil, choose a suitable buffer
10110 from echo_buffer[] and clear it.
10112 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
10113 suitable buffer from echo_buffer[] and clear it.
10115 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
10116 that the current message becomes the last displayed one, make
10117 choose a suitable buffer for echo_area_buffer[0], and clear it.
10119 Value is what FN returns. */
10122 with_echo_area_buffer (struct window
*w
, int which
,
10123 int (*fn
) (ptrdiff_t, Lisp_Object
),
10124 ptrdiff_t a1
, Lisp_Object a2
)
10126 Lisp_Object buffer
;
10127 int this_one
, the_other
, clear_buffer_p
, rc
;
10128 ptrdiff_t count
= SPECPDL_INDEX ();
10130 /* If buffers aren't live, make new ones. */
10131 ensure_echo_area_buffers ();
10133 clear_buffer_p
= 0;
10136 this_one
= 0, the_other
= 1;
10137 else if (which
> 0)
10138 this_one
= 1, the_other
= 0;
10141 this_one
= 0, the_other
= 1;
10142 clear_buffer_p
= 1;
10144 /* We need a fresh one in case the current echo buffer equals
10145 the one containing the last displayed echo area message. */
10146 if (!NILP (echo_area_buffer
[this_one
])
10147 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
10148 echo_area_buffer
[this_one
] = Qnil
;
10151 /* Choose a suitable buffer from echo_buffer[] is we don't
10153 if (NILP (echo_area_buffer
[this_one
]))
10155 echo_area_buffer
[this_one
]
10156 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
10157 ? echo_buffer
[the_other
]
10158 : echo_buffer
[this_one
]);
10159 clear_buffer_p
= 1;
10162 buffer
= echo_area_buffer
[this_one
];
10164 /* Don't get confused by reusing the buffer used for echoing
10165 for a different purpose. */
10166 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
10169 record_unwind_protect (unwind_with_echo_area_buffer
,
10170 with_echo_area_buffer_unwind_data (w
));
10172 /* Make the echo area buffer current. Note that for display
10173 purposes, it is not necessary that the displayed window's buffer
10174 == current_buffer, except for text property lookup. So, let's
10175 only set that buffer temporarily here without doing a full
10176 Fset_window_buffer. We must also change w->pointm, though,
10177 because otherwise an assertions in unshow_buffer fails, and Emacs
10179 set_buffer_internal_1 (XBUFFER (buffer
));
10182 wset_buffer (w
, buffer
);
10183 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
10186 bset_undo_list (current_buffer
, Qt
);
10187 bset_read_only (current_buffer
, Qnil
);
10188 specbind (Qinhibit_read_only
, Qt
);
10189 specbind (Qinhibit_modification_hooks
, Qt
);
10191 if (clear_buffer_p
&& Z
> BEG
)
10192 del_range (BEG
, Z
);
10194 eassert (BEGV
>= BEG
);
10195 eassert (ZV
<= Z
&& ZV
>= BEGV
);
10199 eassert (BEGV
>= BEG
);
10200 eassert (ZV
<= Z
&& ZV
>= BEGV
);
10202 unbind_to (count
, Qnil
);
10207 /* Save state that should be preserved around the call to the function
10208 FN called in with_echo_area_buffer. */
10211 with_echo_area_buffer_unwind_data (struct window
*w
)
10214 Lisp_Object vector
, tmp
;
10216 /* Reduce consing by keeping one vector in
10217 Vwith_echo_area_save_vector. */
10218 vector
= Vwith_echo_area_save_vector
;
10219 Vwith_echo_area_save_vector
= Qnil
;
10222 vector
= Fmake_vector (make_number (9), Qnil
);
10224 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
10225 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
10226 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
10230 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
10231 ASET (vector
, i
, w
->contents
); ++i
;
10232 ASET (vector
, i
, make_number (marker_position (w
->pointm
))); ++i
;
10233 ASET (vector
, i
, make_number (marker_byte_position (w
->pointm
))); ++i
;
10234 ASET (vector
, i
, make_number (marker_position (w
->start
))); ++i
;
10235 ASET (vector
, i
, make_number (marker_byte_position (w
->start
))); ++i
;
10240 for (; i
< end
; ++i
)
10241 ASET (vector
, i
, Qnil
);
10244 eassert (i
== ASIZE (vector
));
10249 /* Restore global state from VECTOR which was created by
10250 with_echo_area_buffer_unwind_data. */
10253 unwind_with_echo_area_buffer (Lisp_Object vector
)
10255 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
10256 Vdeactivate_mark
= AREF (vector
, 1);
10257 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
10259 if (WINDOWP (AREF (vector
, 3)))
10262 Lisp_Object buffer
;
10264 w
= XWINDOW (AREF (vector
, 3));
10265 buffer
= AREF (vector
, 4);
10267 wset_buffer (w
, buffer
);
10268 set_marker_both (w
->pointm
, buffer
,
10269 XFASTINT (AREF (vector
, 5)),
10270 XFASTINT (AREF (vector
, 6)));
10271 set_marker_both (w
->start
, buffer
,
10272 XFASTINT (AREF (vector
, 7)),
10273 XFASTINT (AREF (vector
, 8)));
10276 Vwith_echo_area_save_vector
= vector
;
10280 /* Set up the echo area for use by print functions. MULTIBYTE_P
10281 non-zero means we will print multibyte. */
10284 setup_echo_area_for_printing (int multibyte_p
)
10286 /* If we can't find an echo area any more, exit. */
10287 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
10288 Fkill_emacs (Qnil
);
10290 ensure_echo_area_buffers ();
10292 if (!message_buf_print
)
10294 /* A message has been output since the last time we printed.
10295 Choose a fresh echo area buffer. */
10296 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10297 echo_area_buffer
[0] = echo_buffer
[1];
10299 echo_area_buffer
[0] = echo_buffer
[0];
10301 /* Switch to that buffer and clear it. */
10302 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10303 bset_truncate_lines (current_buffer
, Qnil
);
10307 ptrdiff_t count
= SPECPDL_INDEX ();
10308 specbind (Qinhibit_read_only
, Qt
);
10309 /* Note that undo recording is always disabled. */
10310 del_range (BEG
, Z
);
10311 unbind_to (count
, Qnil
);
10313 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10315 /* Set up the buffer for the multibyteness we need. */
10317 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10318 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
10320 /* Raise the frame containing the echo area. */
10321 if (minibuffer_auto_raise
)
10323 struct frame
*sf
= SELECTED_FRAME ();
10324 Lisp_Object mini_window
;
10325 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10326 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
10329 message_log_maybe_newline ();
10330 message_buf_print
= 1;
10334 if (NILP (echo_area_buffer
[0]))
10336 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10337 echo_area_buffer
[0] = echo_buffer
[1];
10339 echo_area_buffer
[0] = echo_buffer
[0];
10342 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
10344 /* Someone switched buffers between print requests. */
10345 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10346 bset_truncate_lines (current_buffer
, Qnil
);
10352 /* Display an echo area message in window W. Value is non-zero if W's
10353 height is changed. If display_last_displayed_message_p is
10354 non-zero, display the message that was last displayed, otherwise
10355 display the current message. */
10358 display_echo_area (struct window
*w
)
10360 int i
, no_message_p
, window_height_changed_p
;
10362 /* Temporarily disable garbage collections while displaying the echo
10363 area. This is done because a GC can print a message itself.
10364 That message would modify the echo area buffer's contents while a
10365 redisplay of the buffer is going on, and seriously confuse
10367 ptrdiff_t count
= inhibit_garbage_collection ();
10369 /* If there is no message, we must call display_echo_area_1
10370 nevertheless because it resizes the window. But we will have to
10371 reset the echo_area_buffer in question to nil at the end because
10372 with_echo_area_buffer will sets it to an empty buffer. */
10373 i
= display_last_displayed_message_p
? 1 : 0;
10374 no_message_p
= NILP (echo_area_buffer
[i
]);
10376 window_height_changed_p
10377 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
10378 display_echo_area_1
,
10379 (intptr_t) w
, Qnil
);
10382 echo_area_buffer
[i
] = Qnil
;
10384 unbind_to (count
, Qnil
);
10385 return window_height_changed_p
;
10389 /* Helper for display_echo_area. Display the current buffer which
10390 contains the current echo area message in window W, a mini-window,
10391 a pointer to which is passed in A1. A2..A4 are currently not used.
10392 Change the height of W so that all of the message is displayed.
10393 Value is non-zero if height of W was changed. */
10396 display_echo_area_1 (ptrdiff_t a1
, Lisp_Object a2
)
10399 struct window
*w
= (struct window
*) i1
;
10400 Lisp_Object window
;
10401 struct text_pos start
;
10402 int window_height_changed_p
= 0;
10404 /* Do this before displaying, so that we have a large enough glyph
10405 matrix for the display. If we can't get enough space for the
10406 whole text, display the last N lines. That works by setting w->start. */
10407 window_height_changed_p
= resize_mini_window (w
, 0);
10409 /* Use the starting position chosen by resize_mini_window. */
10410 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
10413 clear_glyph_matrix (w
->desired_matrix
);
10414 XSETWINDOW (window
, w
);
10415 try_window (window
, start
, 0);
10417 return window_height_changed_p
;
10421 /* Resize the echo area window to exactly the size needed for the
10422 currently displayed message, if there is one. If a mini-buffer
10423 is active, don't shrink it. */
10426 resize_echo_area_exactly (void)
10428 if (BUFFERP (echo_area_buffer
[0])
10429 && WINDOWP (echo_area_window
))
10431 struct window
*w
= XWINDOW (echo_area_window
);
10433 Lisp_Object resize_exactly
;
10435 if (minibuf_level
== 0)
10436 resize_exactly
= Qt
;
10438 resize_exactly
= Qnil
;
10440 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
10441 (intptr_t) w
, resize_exactly
);
10444 ++windows_or_buffers_changed
;
10445 ++update_mode_lines
;
10446 redisplay_internal ();
10452 /* Callback function for with_echo_area_buffer, when used from
10453 resize_echo_area_exactly. A1 contains a pointer to the window to
10454 resize, EXACTLY non-nil means resize the mini-window exactly to the
10455 size of the text displayed. A3 and A4 are not used. Value is what
10456 resize_mini_window returns. */
10459 resize_mini_window_1 (ptrdiff_t a1
, Lisp_Object exactly
)
10462 return resize_mini_window ((struct window
*) i1
, !NILP (exactly
));
10466 /* Resize mini-window W to fit the size of its contents. EXACT_P
10467 means size the window exactly to the size needed. Otherwise, it's
10468 only enlarged until W's buffer is empty.
10470 Set W->start to the right place to begin display. If the whole
10471 contents fit, start at the beginning. Otherwise, start so as
10472 to make the end of the contents appear. This is particularly
10473 important for y-or-n-p, but seems desirable generally.
10475 Value is non-zero if the window height has been changed. */
10478 resize_mini_window (struct window
*w
, int exact_p
)
10480 struct frame
*f
= XFRAME (w
->frame
);
10481 int window_height_changed_p
= 0;
10483 eassert (MINI_WINDOW_P (w
));
10485 /* By default, start display at the beginning. */
10486 set_marker_both (w
->start
, w
->contents
,
10487 BUF_BEGV (XBUFFER (w
->contents
)),
10488 BUF_BEGV_BYTE (XBUFFER (w
->contents
)));
10490 /* Don't resize windows while redisplaying a window; it would
10491 confuse redisplay functions when the size of the window they are
10492 displaying changes from under them. Such a resizing can happen,
10493 for instance, when which-func prints a long message while
10494 we are running fontification-functions. We're running these
10495 functions with safe_call which binds inhibit-redisplay to t. */
10496 if (!NILP (Vinhibit_redisplay
))
10499 /* Nil means don't try to resize. */
10500 if (NILP (Vresize_mini_windows
)
10501 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
10504 if (!FRAME_MINIBUF_ONLY_P (f
))
10507 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
10508 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
10510 EMACS_INT max_height
;
10511 int unit
= FRAME_LINE_HEIGHT (f
);
10512 struct text_pos start
;
10513 struct buffer
*old_current_buffer
= NULL
;
10515 if (current_buffer
!= XBUFFER (w
->contents
))
10517 old_current_buffer
= current_buffer
;
10518 set_buffer_internal (XBUFFER (w
->contents
));
10521 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10523 /* Compute the max. number of lines specified by the user. */
10524 if (FLOATP (Vmax_mini_window_height
))
10525 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
10526 else if (INTEGERP (Vmax_mini_window_height
))
10527 max_height
= XINT (Vmax_mini_window_height
);
10529 max_height
= total_height
/ 4;
10531 /* Correct that max. height if it's bogus. */
10532 max_height
= clip_to_bounds (1, max_height
, total_height
);
10534 /* Find out the height of the text in the window. */
10535 if (it
.line_wrap
== TRUNCATE
)
10540 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
10541 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
10542 height
= it
.current_y
+ last_height
;
10544 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
10545 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
10546 height
= (height
+ unit
- 1) / unit
;
10549 /* Compute a suitable window start. */
10550 if (height
> max_height
)
10552 height
= max_height
;
10553 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10554 move_it_vertically_backward (&it
, (height
- 1) * unit
);
10555 start
= it
.current
.pos
;
10558 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
10559 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
10561 if (EQ (Vresize_mini_windows
, Qgrow_only
))
10563 /* Let it grow only, until we display an empty message, in which
10564 case the window shrinks again. */
10565 if (height
> WINDOW_TOTAL_LINES (w
))
10567 int old_height
= WINDOW_TOTAL_LINES (w
);
10569 FRAME_WINDOWS_FROZEN (f
) = 1;
10570 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10571 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10573 else if (height
< WINDOW_TOTAL_LINES (w
)
10574 && (exact_p
|| BEGV
== ZV
))
10576 int old_height
= WINDOW_TOTAL_LINES (w
);
10578 FRAME_WINDOWS_FROZEN (f
) = 0;
10579 shrink_mini_window (w
);
10580 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10585 /* Always resize to exact size needed. */
10586 if (height
> WINDOW_TOTAL_LINES (w
))
10588 int old_height
= WINDOW_TOTAL_LINES (w
);
10590 FRAME_WINDOWS_FROZEN (f
) = 1;
10591 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10592 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10594 else if (height
< WINDOW_TOTAL_LINES (w
))
10596 int old_height
= WINDOW_TOTAL_LINES (w
);
10598 FRAME_WINDOWS_FROZEN (f
) = 0;
10599 shrink_mini_window (w
);
10603 FRAME_WINDOWS_FROZEN (f
) = 1;
10604 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10607 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10611 if (old_current_buffer
)
10612 set_buffer_internal (old_current_buffer
);
10615 return window_height_changed_p
;
10619 /* Value is the current message, a string, or nil if there is no
10620 current message. */
10623 current_message (void)
10627 if (!BUFFERP (echo_area_buffer
[0]))
10631 with_echo_area_buffer (0, 0, current_message_1
,
10632 (intptr_t) &msg
, Qnil
);
10634 echo_area_buffer
[0] = Qnil
;
10642 current_message_1 (ptrdiff_t a1
, Lisp_Object a2
)
10645 Lisp_Object
*msg
= (Lisp_Object
*) i1
;
10648 *msg
= make_buffer_string (BEG
, Z
, 1);
10655 /* Push the current message on Vmessage_stack for later restoration
10656 by restore_message. Value is non-zero if the current message isn't
10657 empty. This is a relatively infrequent operation, so it's not
10658 worth optimizing. */
10661 push_message (void)
10663 Lisp_Object msg
= current_message ();
10664 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
10665 return STRINGP (msg
);
10669 /* Restore message display from the top of Vmessage_stack. */
10672 restore_message (void)
10674 eassert (CONSP (Vmessage_stack
));
10675 message3_nolog (XCAR (Vmessage_stack
));
10679 /* Handler for unwind-protect calling pop_message. */
10682 pop_message_unwind (void)
10684 /* Pop the top-most entry off Vmessage_stack. */
10685 eassert (CONSP (Vmessage_stack
));
10686 Vmessage_stack
= XCDR (Vmessage_stack
);
10690 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
10691 exits. If the stack is not empty, we have a missing pop_message
10695 check_message_stack (void)
10697 if (!NILP (Vmessage_stack
))
10702 /* Truncate to NCHARS what will be displayed in the echo area the next
10703 time we display it---but don't redisplay it now. */
10706 truncate_echo_area (ptrdiff_t nchars
)
10709 echo_area_buffer
[0] = Qnil
;
10710 else if (!noninteractive
10712 && !NILP (echo_area_buffer
[0]))
10714 struct frame
*sf
= SELECTED_FRAME ();
10715 /* Error messages get reported properly by cmd_error, so this must be
10716 just an informative message; if the frame hasn't really been
10717 initialized yet, just toss it. */
10718 if (sf
->glyphs_initialized_p
)
10719 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
);
10724 /* Helper function for truncate_echo_area. Truncate the current
10725 message to at most NCHARS characters. */
10728 truncate_message_1 (ptrdiff_t nchars
, Lisp_Object a2
)
10730 if (BEG
+ nchars
< Z
)
10731 del_range (BEG
+ nchars
, Z
);
10733 echo_area_buffer
[0] = Qnil
;
10737 /* Set the current message to STRING. */
10740 set_message (Lisp_Object string
)
10742 eassert (STRINGP (string
));
10744 message_enable_multibyte
= STRING_MULTIBYTE (string
);
10746 with_echo_area_buffer (0, -1, set_message_1
, 0, string
);
10747 message_buf_print
= 0;
10748 help_echo_showing_p
= 0;
10750 if (STRINGP (Vdebug_on_message
)
10751 && STRINGP (string
)
10752 && fast_string_match (Vdebug_on_message
, string
) >= 0)
10753 call_debugger (list2 (Qerror
, string
));
10757 /* Helper function for set_message. First argument is ignored and second
10758 argument has the same meaning as for set_message.
10759 This function is called with the echo area buffer being current. */
10762 set_message_1 (ptrdiff_t a1
, Lisp_Object string
)
10764 eassert (STRINGP (string
));
10766 /* Change multibyteness of the echo buffer appropriately. */
10767 if (message_enable_multibyte
10768 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10769 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
10771 bset_truncate_lines (current_buffer
, message_truncate_lines
? Qt
: Qnil
);
10772 if (!NILP (BVAR (current_buffer
, bidi_display_reordering
)))
10773 bset_bidi_paragraph_direction (current_buffer
, Qleft_to_right
);
10775 /* Insert new message at BEG. */
10776 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10778 /* This function takes care of single/multibyte conversion.
10779 We just have to ensure that the echo area buffer has the right
10780 setting of enable_multibyte_characters. */
10781 insert_from_string (string
, 0, 0, SCHARS (string
), SBYTES (string
), 1);
10787 /* Clear messages. CURRENT_P non-zero means clear the current
10788 message. LAST_DISPLAYED_P non-zero means clear the message
10792 clear_message (int current_p
, int last_displayed_p
)
10796 echo_area_buffer
[0] = Qnil
;
10797 message_cleared_p
= 1;
10800 if (last_displayed_p
)
10801 echo_area_buffer
[1] = Qnil
;
10803 message_buf_print
= 0;
10806 /* Clear garbaged frames.
10808 This function is used where the old redisplay called
10809 redraw_garbaged_frames which in turn called redraw_frame which in
10810 turn called clear_frame. The call to clear_frame was a source of
10811 flickering. I believe a clear_frame is not necessary. It should
10812 suffice in the new redisplay to invalidate all current matrices,
10813 and ensure a complete redisplay of all windows. */
10816 clear_garbaged_frames (void)
10818 if (frame_garbaged
)
10820 Lisp_Object tail
, frame
;
10821 int changed_count
= 0;
10823 FOR_EACH_FRAME (tail
, frame
)
10825 struct frame
*f
= XFRAME (frame
);
10827 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
10832 f
->force_flush_display_p
= 1;
10834 clear_current_matrices (f
);
10841 frame_garbaged
= 0;
10843 ++windows_or_buffers_changed
;
10848 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
10849 is non-zero update selected_frame. Value is non-zero if the
10850 mini-windows height has been changed. */
10853 echo_area_display (int update_frame_p
)
10855 Lisp_Object mini_window
;
10858 int window_height_changed_p
= 0;
10859 struct frame
*sf
= SELECTED_FRAME ();
10861 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10862 w
= XWINDOW (mini_window
);
10863 f
= XFRAME (WINDOW_FRAME (w
));
10865 /* Don't display if frame is invisible or not yet initialized. */
10866 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
10869 #ifdef HAVE_WINDOW_SYSTEM
10870 /* When Emacs starts, selected_frame may be the initial terminal
10871 frame. If we let this through, a message would be displayed on
10873 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
10875 #endif /* HAVE_WINDOW_SYSTEM */
10877 /* Redraw garbaged frames. */
10878 clear_garbaged_frames ();
10880 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
10882 echo_area_window
= mini_window
;
10883 window_height_changed_p
= display_echo_area (w
);
10884 w
->must_be_updated_p
= 1;
10886 /* Update the display, unless called from redisplay_internal.
10887 Also don't update the screen during redisplay itself. The
10888 update will happen at the end of redisplay, and an update
10889 here could cause confusion. */
10890 if (update_frame_p
&& !redisplaying_p
)
10894 /* If the display update has been interrupted by pending
10895 input, update mode lines in the frame. Due to the
10896 pending input, it might have been that redisplay hasn't
10897 been called, so that mode lines above the echo area are
10898 garbaged. This looks odd, so we prevent it here. */
10899 if (!display_completed
)
10900 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
10902 if (window_height_changed_p
10903 /* Don't do this if Emacs is shutting down. Redisplay
10904 needs to run hooks. */
10905 && !NILP (Vrun_hooks
))
10907 /* Must update other windows. Likewise as in other
10908 cases, don't let this update be interrupted by
10910 ptrdiff_t count
= SPECPDL_INDEX ();
10911 specbind (Qredisplay_dont_pause
, Qt
);
10912 windows_or_buffers_changed
= 1;
10913 redisplay_internal ();
10914 unbind_to (count
, Qnil
);
10916 else if (FRAME_WINDOW_P (f
) && n
== 0)
10918 /* Window configuration is the same as before.
10919 Can do with a display update of the echo area,
10920 unless we displayed some mode lines. */
10921 update_single_window (w
, 1);
10922 FRAME_RIF (f
)->flush_display (f
);
10925 update_frame (f
, 1, 1);
10927 /* If cursor is in the echo area, make sure that the next
10928 redisplay displays the minibuffer, so that the cursor will
10929 be replaced with what the minibuffer wants. */
10930 if (cursor_in_echo_area
)
10931 ++windows_or_buffers_changed
;
10934 else if (!EQ (mini_window
, selected_window
))
10935 windows_or_buffers_changed
++;
10937 /* Last displayed message is now the current message. */
10938 echo_area_buffer
[1] = echo_area_buffer
[0];
10939 /* Inform read_char that we're not echoing. */
10940 echo_message_buffer
= Qnil
;
10942 /* Prevent redisplay optimization in redisplay_internal by resetting
10943 this_line_start_pos. This is done because the mini-buffer now
10944 displays the message instead of its buffer text. */
10945 if (EQ (mini_window
, selected_window
))
10946 CHARPOS (this_line_start_pos
) = 0;
10948 return window_height_changed_p
;
10951 /* Nonzero if the current window's buffer is shown in more than one
10952 window and was modified since last redisplay. */
10955 buffer_shared_and_changed (void)
10957 return (buffer_window_count (current_buffer
) > 1
10958 && UNCHANGED_MODIFIED
< MODIFF
);
10961 /* Nonzero if W's buffer was changed but not saved or Transient Mark mode
10962 is enabled and mark of W's buffer was changed since last W's update. */
10965 window_buffer_changed (struct window
*w
)
10967 struct buffer
*b
= XBUFFER (w
->contents
);
10969 eassert (BUFFER_LIVE_P (b
));
10971 return (((BUF_SAVE_MODIFF (b
) < BUF_MODIFF (b
)) != w
->last_had_star
)
10972 || ((!NILP (Vtransient_mark_mode
) && !NILP (BVAR (b
, mark_active
)))
10973 != (w
->region_showing
!= 0)));
10976 /* Nonzero if W has %c in its mode line and mode line should be updated. */
10979 mode_line_update_needed (struct window
*w
)
10981 return (w
->column_number_displayed
!= -1
10982 && !(PT
== w
->last_point
&& !window_outdated (w
))
10983 && (w
->column_number_displayed
!= current_column ()));
10986 /* Nonzero if window start of W is frozen and may not be changed during
10990 window_frozen_p (struct window
*w
)
10992 if (FRAME_WINDOWS_FROZEN (XFRAME (WINDOW_FRAME (w
))))
10994 Lisp_Object window
;
10996 XSETWINDOW (window
, w
);
10997 if (MINI_WINDOW_P (w
))
10999 else if (EQ (window
, selected_window
))
11001 else if (MINI_WINDOW_P (XWINDOW (selected_window
))
11002 && EQ (window
, Vminibuf_scroll_window
))
11003 /* This special window can't be frozen too. */
11011 /***********************************************************************
11012 Mode Lines and Frame Titles
11013 ***********************************************************************/
11015 /* A buffer for constructing non-propertized mode-line strings and
11016 frame titles in it; allocated from the heap in init_xdisp and
11017 resized as needed in store_mode_line_noprop_char. */
11019 static char *mode_line_noprop_buf
;
11021 /* The buffer's end, and a current output position in it. */
11023 static char *mode_line_noprop_buf_end
;
11024 static char *mode_line_noprop_ptr
;
11026 #define MODE_LINE_NOPROP_LEN(start) \
11027 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
11030 MODE_LINE_DISPLAY
= 0,
11034 } mode_line_target
;
11036 /* Alist that caches the results of :propertize.
11037 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
11038 static Lisp_Object mode_line_proptrans_alist
;
11040 /* List of strings making up the mode-line. */
11041 static Lisp_Object mode_line_string_list
;
11043 /* Base face property when building propertized mode line string. */
11044 static Lisp_Object mode_line_string_face
;
11045 static Lisp_Object mode_line_string_face_prop
;
11048 /* Unwind data for mode line strings */
11050 static Lisp_Object Vmode_line_unwind_vector
;
11053 format_mode_line_unwind_data (struct frame
*target_frame
,
11054 struct buffer
*obuf
,
11056 int save_proptrans
)
11058 Lisp_Object vector
, tmp
;
11060 /* Reduce consing by keeping one vector in
11061 Vwith_echo_area_save_vector. */
11062 vector
= Vmode_line_unwind_vector
;
11063 Vmode_line_unwind_vector
= Qnil
;
11066 vector
= Fmake_vector (make_number (10), Qnil
);
11068 ASET (vector
, 0, make_number (mode_line_target
));
11069 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
11070 ASET (vector
, 2, mode_line_string_list
);
11071 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
11072 ASET (vector
, 4, mode_line_string_face
);
11073 ASET (vector
, 5, mode_line_string_face_prop
);
11076 XSETBUFFER (tmp
, obuf
);
11079 ASET (vector
, 6, tmp
);
11080 ASET (vector
, 7, owin
);
11083 /* Similarly to `with-selected-window', if the operation selects
11084 a window on another frame, we must restore that frame's
11085 selected window, and (for a tty) the top-frame. */
11086 ASET (vector
, 8, target_frame
->selected_window
);
11087 if (FRAME_TERMCAP_P (target_frame
))
11088 ASET (vector
, 9, FRAME_TTY (target_frame
)->top_frame
);
11095 unwind_format_mode_line (Lisp_Object vector
)
11097 Lisp_Object old_window
= AREF (vector
, 7);
11098 Lisp_Object target_frame_window
= AREF (vector
, 8);
11099 Lisp_Object old_top_frame
= AREF (vector
, 9);
11101 mode_line_target
= XINT (AREF (vector
, 0));
11102 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
11103 mode_line_string_list
= AREF (vector
, 2);
11104 if (! EQ (AREF (vector
, 3), Qt
))
11105 mode_line_proptrans_alist
= AREF (vector
, 3);
11106 mode_line_string_face
= AREF (vector
, 4);
11107 mode_line_string_face_prop
= AREF (vector
, 5);
11109 /* Select window before buffer, since it may change the buffer. */
11110 if (!NILP (old_window
))
11112 /* If the operation that we are unwinding had selected a window
11113 on a different frame, reset its frame-selected-window. For a
11114 text terminal, reset its top-frame if necessary. */
11115 if (!NILP (target_frame_window
))
11118 = WINDOW_FRAME (XWINDOW (target_frame_window
));
11120 if (!EQ (frame
, WINDOW_FRAME (XWINDOW (old_window
))))
11121 Fselect_window (target_frame_window
, Qt
);
11123 if (!NILP (old_top_frame
) && !EQ (old_top_frame
, frame
))
11124 Fselect_frame (old_top_frame
, Qt
);
11127 Fselect_window (old_window
, Qt
);
11130 if (!NILP (AREF (vector
, 6)))
11132 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
11133 ASET (vector
, 6, Qnil
);
11136 Vmode_line_unwind_vector
= vector
;
11140 /* Store a single character C for the frame title in mode_line_noprop_buf.
11141 Re-allocate mode_line_noprop_buf if necessary. */
11144 store_mode_line_noprop_char (char c
)
11146 /* If output position has reached the end of the allocated buffer,
11147 increase the buffer's size. */
11148 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
11150 ptrdiff_t len
= MODE_LINE_NOPROP_LEN (0);
11151 ptrdiff_t size
= len
;
11152 mode_line_noprop_buf
=
11153 xpalloc (mode_line_noprop_buf
, &size
, 1, STRING_BYTES_BOUND
, 1);
11154 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
11155 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
11158 *mode_line_noprop_ptr
++ = c
;
11162 /* Store part of a frame title in mode_line_noprop_buf, beginning at
11163 mode_line_noprop_ptr. STRING is the string to store. Do not copy
11164 characters that yield more columns than PRECISION; PRECISION <= 0
11165 means copy the whole string. Pad with spaces until FIELD_WIDTH
11166 number of characters have been copied; FIELD_WIDTH <= 0 means don't
11167 pad. Called from display_mode_element when it is used to build a
11171 store_mode_line_noprop (const char *string
, int field_width
, int precision
)
11173 const unsigned char *str
= (const unsigned char *) string
;
11175 ptrdiff_t dummy
, nbytes
;
11177 /* Copy at most PRECISION chars from STR. */
11178 nbytes
= strlen (string
);
11179 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
11181 store_mode_line_noprop_char (*str
++);
11183 /* Fill up with spaces until FIELD_WIDTH reached. */
11184 while (field_width
> 0
11185 && n
< field_width
)
11187 store_mode_line_noprop_char (' ');
11194 /***********************************************************************
11196 ***********************************************************************/
11198 #ifdef HAVE_WINDOW_SYSTEM
11200 /* Set the title of FRAME, if it has changed. The title format is
11201 Vicon_title_format if FRAME is iconified, otherwise it is
11202 frame_title_format. */
11205 x_consider_frame_title (Lisp_Object frame
)
11207 struct frame
*f
= XFRAME (frame
);
11209 if (FRAME_WINDOW_P (f
)
11210 || FRAME_MINIBUF_ONLY_P (f
)
11211 || f
->explicit_name
)
11213 /* Do we have more than one visible frame on this X display? */
11214 Lisp_Object tail
, other_frame
, fmt
;
11215 ptrdiff_t title_start
;
11219 ptrdiff_t count
= SPECPDL_INDEX ();
11221 FOR_EACH_FRAME (tail
, other_frame
)
11223 struct frame
*tf
= XFRAME (other_frame
);
11226 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
11227 && !FRAME_MINIBUF_ONLY_P (tf
)
11228 && !EQ (other_frame
, tip_frame
)
11229 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
11233 /* Set global variable indicating that multiple frames exist. */
11234 multiple_frames
= CONSP (tail
);
11236 /* Switch to the buffer of selected window of the frame. Set up
11237 mode_line_target so that display_mode_element will output into
11238 mode_line_noprop_buf; then display the title. */
11239 record_unwind_protect (unwind_format_mode_line
,
11240 format_mode_line_unwind_data
11241 (f
, current_buffer
, selected_window
, 0));
11243 Fselect_window (f
->selected_window
, Qt
);
11244 set_buffer_internal_1
11245 (XBUFFER (XWINDOW (f
->selected_window
)->contents
));
11246 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
11248 mode_line_target
= MODE_LINE_TITLE
;
11249 title_start
= MODE_LINE_NOPROP_LEN (0);
11250 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
11251 NULL
, DEFAULT_FACE_ID
);
11252 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
11253 len
= MODE_LINE_NOPROP_LEN (title_start
);
11254 title
= mode_line_noprop_buf
+ title_start
;
11255 unbind_to (count
, Qnil
);
11257 /* Set the title only if it's changed. This avoids consing in
11258 the common case where it hasn't. (If it turns out that we've
11259 already wasted too much time by walking through the list with
11260 display_mode_element, then we might need to optimize at a
11261 higher level than this.) */
11262 if (! STRINGP (f
->name
)
11263 || SBYTES (f
->name
) != len
11264 || memcmp (title
, SDATA (f
->name
), len
) != 0)
11265 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
11269 #endif /* not HAVE_WINDOW_SYSTEM */
11272 /***********************************************************************
11274 ***********************************************************************/
11277 /* Prepare for redisplay by updating menu-bar item lists when
11278 appropriate. This can call eval. */
11281 prepare_menu_bars (void)
11284 struct gcpro gcpro1
, gcpro2
;
11286 Lisp_Object tooltip_frame
;
11288 #ifdef HAVE_WINDOW_SYSTEM
11289 tooltip_frame
= tip_frame
;
11291 tooltip_frame
= Qnil
;
11294 /* Update all frame titles based on their buffer names, etc. We do
11295 this before the menu bars so that the buffer-menu will show the
11296 up-to-date frame titles. */
11297 #ifdef HAVE_WINDOW_SYSTEM
11298 if (windows_or_buffers_changed
|| update_mode_lines
)
11300 Lisp_Object tail
, frame
;
11302 FOR_EACH_FRAME (tail
, frame
)
11304 f
= XFRAME (frame
);
11305 if (!EQ (frame
, tooltip_frame
)
11306 && (FRAME_ICONIFIED_P (f
)
11307 || FRAME_VISIBLE_P (f
) == 1
11308 /* Exclude TTY frames that are obscured because they
11309 are not the top frame on their console. This is
11310 because x_consider_frame_title actually switches
11311 to the frame, which for TTY frames means it is
11312 marked as garbaged, and will be completely
11313 redrawn on the next redisplay cycle. This causes
11314 TTY frames to be completely redrawn, when there
11315 are more than one of them, even though nothing
11316 should be changed on display. */
11317 || (FRAME_VISIBLE_P (f
) == 2 && FRAME_WINDOW_P (f
))))
11318 x_consider_frame_title (frame
);
11321 #endif /* HAVE_WINDOW_SYSTEM */
11323 /* Update the menu bar item lists, if appropriate. This has to be
11324 done before any actual redisplay or generation of display lines. */
11325 all_windows
= (update_mode_lines
11326 || buffer_shared_and_changed ()
11327 || windows_or_buffers_changed
);
11330 Lisp_Object tail
, frame
;
11331 ptrdiff_t count
= SPECPDL_INDEX ();
11332 /* 1 means that update_menu_bar has run its hooks
11333 so any further calls to update_menu_bar shouldn't do so again. */
11334 int menu_bar_hooks_run
= 0;
11336 record_unwind_save_match_data ();
11338 FOR_EACH_FRAME (tail
, frame
)
11340 f
= XFRAME (frame
);
11342 /* Ignore tooltip frame. */
11343 if (EQ (frame
, tooltip_frame
))
11346 /* If a window on this frame changed size, report that to
11347 the user and clear the size-change flag. */
11348 if (FRAME_WINDOW_SIZES_CHANGED (f
))
11350 Lisp_Object functions
;
11352 /* Clear flag first in case we get an error below. */
11353 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
11354 functions
= Vwindow_size_change_functions
;
11355 GCPRO2 (tail
, functions
);
11357 while (CONSP (functions
))
11359 if (!EQ (XCAR (functions
), Qt
))
11360 call1 (XCAR (functions
), frame
);
11361 functions
= XCDR (functions
);
11367 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
11368 #ifdef HAVE_WINDOW_SYSTEM
11369 update_tool_bar (f
, 0);
11372 if (windows_or_buffers_changed
11375 (f
, Fbuffer_modified_p (XWINDOW (f
->selected_window
)->contents
));
11380 unbind_to (count
, Qnil
);
11384 struct frame
*sf
= SELECTED_FRAME ();
11385 update_menu_bar (sf
, 1, 0);
11386 #ifdef HAVE_WINDOW_SYSTEM
11387 update_tool_bar (sf
, 1);
11393 /* Update the menu bar item list for frame F. This has to be done
11394 before we start to fill in any display lines, because it can call
11397 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
11399 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
11400 already ran the menu bar hooks for this redisplay, so there
11401 is no need to run them again. The return value is the
11402 updated value of this flag, to pass to the next call. */
11405 update_menu_bar (struct frame
*f
, int save_match_data
, int hooks_run
)
11407 Lisp_Object window
;
11408 register struct window
*w
;
11410 /* If called recursively during a menu update, do nothing. This can
11411 happen when, for instance, an activate-menubar-hook causes a
11413 if (inhibit_menubar_update
)
11416 window
= FRAME_SELECTED_WINDOW (f
);
11417 w
= XWINDOW (window
);
11419 if (FRAME_WINDOW_P (f
)
11421 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11422 || defined (HAVE_NS) || defined (USE_GTK)
11423 FRAME_EXTERNAL_MENU_BAR (f
)
11425 FRAME_MENU_BAR_LINES (f
) > 0
11427 : FRAME_MENU_BAR_LINES (f
) > 0)
11429 /* If the user has switched buffers or windows, we need to
11430 recompute to reflect the new bindings. But we'll
11431 recompute when update_mode_lines is set too; that means
11432 that people can use force-mode-line-update to request
11433 that the menu bar be recomputed. The adverse effect on
11434 the rest of the redisplay algorithm is about the same as
11435 windows_or_buffers_changed anyway. */
11436 if (windows_or_buffers_changed
11437 /* This used to test w->update_mode_line, but we believe
11438 there is no need to recompute the menu in that case. */
11439 || update_mode_lines
11440 || window_buffer_changed (w
))
11442 struct buffer
*prev
= current_buffer
;
11443 ptrdiff_t count
= SPECPDL_INDEX ();
11445 specbind (Qinhibit_menubar_update
, Qt
);
11447 set_buffer_internal_1 (XBUFFER (w
->contents
));
11448 if (save_match_data
)
11449 record_unwind_save_match_data ();
11450 if (NILP (Voverriding_local_map_menu_flag
))
11452 specbind (Qoverriding_terminal_local_map
, Qnil
);
11453 specbind (Qoverriding_local_map
, Qnil
);
11458 /* Run the Lucid hook. */
11459 safe_run_hooks (Qactivate_menubar_hook
);
11461 /* If it has changed current-menubar from previous value,
11462 really recompute the menu-bar from the value. */
11463 if (! NILP (Vlucid_menu_bar_dirty_flag
))
11464 call0 (Qrecompute_lucid_menubar
);
11466 safe_run_hooks (Qmenu_bar_update_hook
);
11471 XSETFRAME (Vmenu_updating_frame
, f
);
11472 fset_menu_bar_items (f
, menu_bar_items (FRAME_MENU_BAR_ITEMS (f
)));
11474 /* Redisplay the menu bar in case we changed it. */
11475 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11476 || defined (HAVE_NS) || defined (USE_GTK)
11477 if (FRAME_WINDOW_P (f
))
11479 #if defined (HAVE_NS)
11480 /* All frames on Mac OS share the same menubar. So only
11481 the selected frame should be allowed to set it. */
11482 if (f
== SELECTED_FRAME ())
11484 set_frame_menubar (f
, 0, 0);
11487 /* On a terminal screen, the menu bar is an ordinary screen
11488 line, and this makes it get updated. */
11489 w
->update_mode_line
= 1;
11490 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11491 /* In the non-toolkit version, the menu bar is an ordinary screen
11492 line, and this makes it get updated. */
11493 w
->update_mode_line
= 1;
11494 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11496 unbind_to (count
, Qnil
);
11497 set_buffer_internal_1 (prev
);
11506 /***********************************************************************
11508 ***********************************************************************/
11510 #ifdef HAVE_WINDOW_SYSTEM
11513 Nominal cursor position -- where to draw output.
11514 HPOS and VPOS are window relative glyph matrix coordinates.
11515 X and Y are window relative pixel coordinates. */
11517 struct cursor_pos output_cursor
;
11521 Set the global variable output_cursor to CURSOR. All cursor
11522 positions are relative to currently updated window. */
11525 set_output_cursor (struct cursor_pos
*cursor
)
11527 output_cursor
.hpos
= cursor
->hpos
;
11528 output_cursor
.vpos
= cursor
->vpos
;
11529 output_cursor
.x
= cursor
->x
;
11530 output_cursor
.y
= cursor
->y
;
11535 Set a nominal cursor position.
11537 HPOS and VPOS are column/row positions in a window glyph matrix.
11538 X and Y are window text area relative pixel positions.
11540 This is always done during window update, so the position is the
11541 future output cursor position for currently updated window W.
11542 NOTE: W is used only to check whether this function is called
11543 in a consistent manner via the redisplay interface. */
11546 x_cursor_to (struct window
*w
, int vpos
, int hpos
, int y
, int x
)
11550 /* Set the output cursor. */
11551 output_cursor
.hpos
= hpos
;
11552 output_cursor
.vpos
= vpos
;
11553 output_cursor
.x
= x
;
11554 output_cursor
.y
= y
;
11557 #endif /* HAVE_WINDOW_SYSTEM */
11560 /***********************************************************************
11562 ***********************************************************************/
11564 #ifdef HAVE_WINDOW_SYSTEM
11566 /* Where the mouse was last time we reported a mouse event. */
11568 struct frame
*last_mouse_frame
;
11570 /* Tool-bar item index of the item on which a mouse button was pressed
11573 int last_tool_bar_item
;
11575 /* Select `frame' temporarily without running all the code in
11577 FIXME: Maybe do_switch_frame should be trimmed down similarly
11578 when `norecord' is set. */
11580 fast_set_selected_frame (Lisp_Object frame
)
11582 if (!EQ (selected_frame
, frame
))
11584 selected_frame
= frame
;
11585 selected_window
= XFRAME (frame
)->selected_window
;
11589 /* Update the tool-bar item list for frame F. This has to be done
11590 before we start to fill in any display lines. Called from
11591 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
11592 and restore it here. */
11595 update_tool_bar (struct frame
*f
, int save_match_data
)
11597 #if defined (USE_GTK) || defined (HAVE_NS)
11598 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
11600 int do_update
= WINDOWP (f
->tool_bar_window
)
11601 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
11606 Lisp_Object window
;
11609 window
= FRAME_SELECTED_WINDOW (f
);
11610 w
= XWINDOW (window
);
11612 /* If the user has switched buffers or windows, we need to
11613 recompute to reflect the new bindings. But we'll
11614 recompute when update_mode_lines is set too; that means
11615 that people can use force-mode-line-update to request
11616 that the menu bar be recomputed. The adverse effect on
11617 the rest of the redisplay algorithm is about the same as
11618 windows_or_buffers_changed anyway. */
11619 if (windows_or_buffers_changed
11620 || w
->update_mode_line
11621 || update_mode_lines
11622 || window_buffer_changed (w
))
11624 struct buffer
*prev
= current_buffer
;
11625 ptrdiff_t count
= SPECPDL_INDEX ();
11626 Lisp_Object frame
, new_tool_bar
;
11627 int new_n_tool_bar
;
11628 struct gcpro gcpro1
;
11630 /* Set current_buffer to the buffer of the selected
11631 window of the frame, so that we get the right local
11633 set_buffer_internal_1 (XBUFFER (w
->contents
));
11635 /* Save match data, if we must. */
11636 if (save_match_data
)
11637 record_unwind_save_match_data ();
11639 /* Make sure that we don't accidentally use bogus keymaps. */
11640 if (NILP (Voverriding_local_map_menu_flag
))
11642 specbind (Qoverriding_terminal_local_map
, Qnil
);
11643 specbind (Qoverriding_local_map
, Qnil
);
11646 GCPRO1 (new_tool_bar
);
11648 /* We must temporarily set the selected frame to this frame
11649 before calling tool_bar_items, because the calculation of
11650 the tool-bar keymap uses the selected frame (see
11651 `tool-bar-make-keymap' in tool-bar.el). */
11652 eassert (EQ (selected_window
,
11653 /* Since we only explicitly preserve selected_frame,
11654 check that selected_window would be redundant. */
11655 XFRAME (selected_frame
)->selected_window
));
11656 record_unwind_protect (fast_set_selected_frame
, selected_frame
);
11657 XSETFRAME (frame
, f
);
11658 fast_set_selected_frame (frame
);
11660 /* Build desired tool-bar items from keymaps. */
11662 = tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
11665 /* Redisplay the tool-bar if we changed it. */
11666 if (new_n_tool_bar
!= f
->n_tool_bar_items
11667 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
11669 /* Redisplay that happens asynchronously due to an expose event
11670 may access f->tool_bar_items. Make sure we update both
11671 variables within BLOCK_INPUT so no such event interrupts. */
11673 fset_tool_bar_items (f
, new_tool_bar
);
11674 f
->n_tool_bar_items
= new_n_tool_bar
;
11675 w
->update_mode_line
= 1;
11681 unbind_to (count
, Qnil
);
11682 set_buffer_internal_1 (prev
);
11688 /* Set F->desired_tool_bar_string to a Lisp string representing frame
11689 F's desired tool-bar contents. F->tool_bar_items must have
11690 been set up previously by calling prepare_menu_bars. */
11693 build_desired_tool_bar_string (struct frame
*f
)
11695 int i
, size
, size_needed
;
11696 struct gcpro gcpro1
, gcpro2
, gcpro3
;
11697 Lisp_Object image
, plist
, props
;
11699 image
= plist
= props
= Qnil
;
11700 GCPRO3 (image
, plist
, props
);
11702 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
11703 Otherwise, make a new string. */
11705 /* The size of the string we might be able to reuse. */
11706 size
= (STRINGP (f
->desired_tool_bar_string
)
11707 ? SCHARS (f
->desired_tool_bar_string
)
11710 /* We need one space in the string for each image. */
11711 size_needed
= f
->n_tool_bar_items
;
11713 /* Reuse f->desired_tool_bar_string, if possible. */
11714 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
11715 fset_desired_tool_bar_string
11716 (f
, Fmake_string (make_number (size_needed
), make_number (' ')));
11719 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
11720 Fremove_text_properties (make_number (0), make_number (size
),
11721 props
, f
->desired_tool_bar_string
);
11724 /* Put a `display' property on the string for the images to display,
11725 put a `menu_item' property on tool-bar items with a value that
11726 is the index of the item in F's tool-bar item vector. */
11727 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
11729 #define PROP(IDX) \
11730 AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
11732 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
11733 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
11734 int hmargin
, vmargin
, relief
, idx
, end
;
11736 /* If image is a vector, choose the image according to the
11738 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
11739 if (VECTORP (image
))
11743 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
11744 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
11747 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
11748 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
11750 eassert (ASIZE (image
) >= idx
);
11751 image
= AREF (image
, idx
);
11756 /* Ignore invalid image specifications. */
11757 if (!valid_image_p (image
))
11760 /* Display the tool-bar button pressed, or depressed. */
11761 plist
= Fcopy_sequence (XCDR (image
));
11763 /* Compute margin and relief to draw. */
11764 relief
= (tool_bar_button_relief
>= 0
11765 ? tool_bar_button_relief
11766 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
11767 hmargin
= vmargin
= relief
;
11769 if (RANGED_INTEGERP (1, Vtool_bar_button_margin
,
11770 INT_MAX
- max (hmargin
, vmargin
)))
11772 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
11773 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
11775 else if (CONSP (Vtool_bar_button_margin
))
11777 if (RANGED_INTEGERP (1, XCAR (Vtool_bar_button_margin
),
11778 INT_MAX
- hmargin
))
11779 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
11781 if (RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin
),
11782 INT_MAX
- vmargin
))
11783 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
11786 if (auto_raise_tool_bar_buttons_p
)
11788 /* Add a `:relief' property to the image spec if the item is
11792 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
11799 /* If image is selected, display it pressed, i.e. with a
11800 negative relief. If it's not selected, display it with a
11802 plist
= Fplist_put (plist
, QCrelief
,
11804 ? make_number (-relief
)
11805 : make_number (relief
)));
11810 /* Put a margin around the image. */
11811 if (hmargin
|| vmargin
)
11813 if (hmargin
== vmargin
)
11814 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
11816 plist
= Fplist_put (plist
, QCmargin
,
11817 Fcons (make_number (hmargin
),
11818 make_number (vmargin
)));
11821 /* If button is not enabled, and we don't have special images
11822 for the disabled state, make the image appear disabled by
11823 applying an appropriate algorithm to it. */
11824 if (!enabled_p
&& idx
< 0)
11825 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
11827 /* Put a `display' text property on the string for the image to
11828 display. Put a `menu-item' property on the string that gives
11829 the start of this item's properties in the tool-bar items
11831 image
= Fcons (Qimage
, plist
);
11832 props
= list4 (Qdisplay
, image
,
11833 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
11835 /* Let the last image hide all remaining spaces in the tool bar
11836 string. The string can be longer than needed when we reuse a
11837 previous string. */
11838 if (i
+ 1 == f
->n_tool_bar_items
)
11839 end
= SCHARS (f
->desired_tool_bar_string
);
11842 Fadd_text_properties (make_number (i
), make_number (end
),
11843 props
, f
->desired_tool_bar_string
);
11851 /* Display one line of the tool-bar of frame IT->f.
11853 HEIGHT specifies the desired height of the tool-bar line.
11854 If the actual height of the glyph row is less than HEIGHT, the
11855 row's height is increased to HEIGHT, and the icons are centered
11856 vertically in the new height.
11858 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
11859 count a final empty row in case the tool-bar width exactly matches
11864 display_tool_bar_line (struct it
*it
, int height
)
11866 struct glyph_row
*row
= it
->glyph_row
;
11867 int max_x
= it
->last_visible_x
;
11868 struct glyph
*last
;
11870 prepare_desired_row (row
);
11871 row
->y
= it
->current_y
;
11873 /* Note that this isn't made use of if the face hasn't a box,
11874 so there's no need to check the face here. */
11875 it
->start_of_box_run_p
= 1;
11877 while (it
->current_x
< max_x
)
11879 int x
, n_glyphs_before
, i
, nglyphs
;
11880 struct it it_before
;
11882 /* Get the next display element. */
11883 if (!get_next_display_element (it
))
11885 /* Don't count empty row if we are counting needed tool-bar lines. */
11886 if (height
< 0 && !it
->hpos
)
11891 /* Produce glyphs. */
11892 n_glyphs_before
= row
->used
[TEXT_AREA
];
11895 PRODUCE_GLYPHS (it
);
11897 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
11899 x
= it_before
.current_x
;
11900 while (i
< nglyphs
)
11902 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
11904 if (x
+ glyph
->pixel_width
> max_x
)
11906 /* Glyph doesn't fit on line. Backtrack. */
11907 row
->used
[TEXT_AREA
] = n_glyphs_before
;
11909 /* If this is the only glyph on this line, it will never fit on the
11910 tool-bar, so skip it. But ensure there is at least one glyph,
11911 so we don't accidentally disable the tool-bar. */
11912 if (n_glyphs_before
== 0
11913 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
11919 x
+= glyph
->pixel_width
;
11923 /* Stop at line end. */
11924 if (ITERATOR_AT_END_OF_LINE_P (it
))
11927 set_iterator_to_next (it
, 1);
11932 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
11934 /* Use default face for the border below the tool bar.
11936 FIXME: When auto-resize-tool-bars is grow-only, there is
11937 no additional border below the possibly empty tool-bar lines.
11938 So to make the extra empty lines look "normal", we have to
11939 use the tool-bar face for the border too. */
11940 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
)
11941 && !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
11942 it
->face_id
= DEFAULT_FACE_ID
;
11944 extend_face_to_end_of_line (it
);
11945 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
11946 last
->right_box_line_p
= 1;
11947 if (last
== row
->glyphs
[TEXT_AREA
])
11948 last
->left_box_line_p
= 1;
11950 /* Make line the desired height and center it vertically. */
11951 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
11953 /* Don't add more than one line height. */
11954 height
%= FRAME_LINE_HEIGHT (it
->f
);
11955 it
->max_ascent
+= height
/ 2;
11956 it
->max_descent
+= (height
+ 1) / 2;
11959 compute_line_metrics (it
);
11961 /* If line is empty, make it occupy the rest of the tool-bar. */
11962 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11964 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
11965 row
->visible_height
= row
->height
;
11966 row
->ascent
= row
->phys_ascent
= 0;
11967 row
->extra_line_spacing
= 0;
11970 row
->full_width_p
= 1;
11971 row
->continued_p
= 0;
11972 row
->truncated_on_left_p
= 0;
11973 row
->truncated_on_right_p
= 0;
11975 it
->current_x
= it
->hpos
= 0;
11976 it
->current_y
+= row
->height
;
11982 /* Max tool-bar height. */
11984 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
11985 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
11987 /* Value is the number of screen lines needed to make all tool-bar
11988 items of frame F visible. The number of actual rows needed is
11989 returned in *N_ROWS if non-NULL. */
11992 tool_bar_lines_needed (struct frame
*f
, int *n_rows
)
11994 struct window
*w
= XWINDOW (f
->tool_bar_window
);
11996 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
11997 the desired matrix, so use (unused) mode-line row as temporary row to
11998 avoid destroying the first tool-bar row. */
11999 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
12001 /* Initialize an iterator for iteration over
12002 F->desired_tool_bar_string in the tool-bar window of frame F. */
12003 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
12004 it
.first_visible_x
= 0;
12005 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
12006 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
12007 it
.paragraph_embedding
= L2R
;
12009 while (!ITERATOR_AT_END_P (&it
))
12011 clear_glyph_row (temp_row
);
12012 it
.glyph_row
= temp_row
;
12013 display_tool_bar_line (&it
, -1);
12015 clear_glyph_row (temp_row
);
12017 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
12019 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
12021 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
12025 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
12027 doc
: /* Return the number of lines occupied by the tool bar of FRAME.
12028 If FRAME is nil or omitted, use the selected frame. */)
12029 (Lisp_Object frame
)
12031 struct frame
*f
= decode_any_frame (frame
);
12035 if (WINDOWP (f
->tool_bar_window
)
12036 && (w
= XWINDOW (f
->tool_bar_window
),
12037 WINDOW_TOTAL_LINES (w
) > 0))
12039 update_tool_bar (f
, 1);
12040 if (f
->n_tool_bar_items
)
12042 build_desired_tool_bar_string (f
);
12043 nlines
= tool_bar_lines_needed (f
, NULL
);
12047 return make_number (nlines
);
12051 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
12052 height should be changed. */
12055 redisplay_tool_bar (struct frame
*f
)
12059 struct glyph_row
*row
;
12061 #if defined (USE_GTK) || defined (HAVE_NS)
12062 if (FRAME_EXTERNAL_TOOL_BAR (f
))
12063 update_frame_tool_bar (f
);
12067 /* If frame hasn't a tool-bar window or if it is zero-height, don't
12068 do anything. This means you must start with tool-bar-lines
12069 non-zero to get the auto-sizing effect. Or in other words, you
12070 can turn off tool-bars by specifying tool-bar-lines zero. */
12071 if (!WINDOWP (f
->tool_bar_window
)
12072 || (w
= XWINDOW (f
->tool_bar_window
),
12073 WINDOW_TOTAL_LINES (w
) == 0))
12076 /* Set up an iterator for the tool-bar window. */
12077 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
12078 it
.first_visible_x
= 0;
12079 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
12080 row
= it
.glyph_row
;
12082 /* Build a string that represents the contents of the tool-bar. */
12083 build_desired_tool_bar_string (f
);
12084 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
12085 /* FIXME: This should be controlled by a user option. But it
12086 doesn't make sense to have an R2L tool bar if the menu bar cannot
12087 be drawn also R2L, and making the menu bar R2L is tricky due
12088 toolkit-specific code that implements it. If an R2L tool bar is
12089 ever supported, display_tool_bar_line should also be augmented to
12090 call unproduce_glyphs like display_line and display_string
12092 it
.paragraph_embedding
= L2R
;
12094 if (f
->n_tool_bar_rows
== 0)
12098 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
12099 nlines
!= WINDOW_TOTAL_LINES (w
)))
12102 int old_height
= WINDOW_TOTAL_LINES (w
);
12104 XSETFRAME (frame
, f
);
12105 Fmodify_frame_parameters (frame
,
12106 list1 (Fcons (Qtool_bar_lines
,
12107 make_number (nlines
))));
12108 if (WINDOW_TOTAL_LINES (w
) != old_height
)
12110 clear_glyph_matrix (w
->desired_matrix
);
12111 fonts_changed_p
= 1;
12117 /* Display as many lines as needed to display all tool-bar items. */
12119 if (f
->n_tool_bar_rows
> 0)
12121 int border
, rows
, height
, extra
;
12123 if (TYPE_RANGED_INTEGERP (int, Vtool_bar_border
))
12124 border
= XINT (Vtool_bar_border
);
12125 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
12126 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
12127 else if (EQ (Vtool_bar_border
, Qborder_width
))
12128 border
= f
->border_width
;
12134 rows
= f
->n_tool_bar_rows
;
12135 height
= max (1, (it
.last_visible_y
- border
) / rows
);
12136 extra
= it
.last_visible_y
- border
- height
* rows
;
12138 while (it
.current_y
< it
.last_visible_y
)
12141 if (extra
> 0 && rows
-- > 0)
12143 h
= (extra
+ rows
- 1) / rows
;
12146 display_tool_bar_line (&it
, height
+ h
);
12151 while (it
.current_y
< it
.last_visible_y
)
12152 display_tool_bar_line (&it
, 0);
12155 /* It doesn't make much sense to try scrolling in the tool-bar
12156 window, so don't do it. */
12157 w
->desired_matrix
->no_scrolling_p
= 1;
12158 w
->must_be_updated_p
= 1;
12160 if (!NILP (Vauto_resize_tool_bars
))
12162 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
12163 int change_height_p
= 0;
12165 /* If we couldn't display everything, change the tool-bar's
12166 height if there is room for more. */
12167 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
12168 && it
.current_y
< max_tool_bar_height
)
12169 change_height_p
= 1;
12171 row
= it
.glyph_row
- 1;
12173 /* If there are blank lines at the end, except for a partially
12174 visible blank line at the end that is smaller than
12175 FRAME_LINE_HEIGHT, change the tool-bar's height. */
12176 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12177 && row
->height
>= FRAME_LINE_HEIGHT (f
))
12178 change_height_p
= 1;
12180 /* If row displays tool-bar items, but is partially visible,
12181 change the tool-bar's height. */
12182 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12183 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
12184 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
12185 change_height_p
= 1;
12187 /* Resize windows as needed by changing the `tool-bar-lines'
12188 frame parameter. */
12189 if (change_height_p
)
12192 int old_height
= WINDOW_TOTAL_LINES (w
);
12194 int nlines
= tool_bar_lines_needed (f
, &nrows
);
12196 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
12197 && !f
->minimize_tool_bar_window_p
)
12198 ? (nlines
> old_height
)
12199 : (nlines
!= old_height
));
12200 f
->minimize_tool_bar_window_p
= 0;
12202 if (change_height_p
)
12204 XSETFRAME (frame
, f
);
12205 Fmodify_frame_parameters (frame
,
12206 list1 (Fcons (Qtool_bar_lines
,
12207 make_number (nlines
))));
12208 if (WINDOW_TOTAL_LINES (w
) != old_height
)
12210 clear_glyph_matrix (w
->desired_matrix
);
12211 f
->n_tool_bar_rows
= nrows
;
12212 fonts_changed_p
= 1;
12219 f
->minimize_tool_bar_window_p
= 0;
12224 /* Get information about the tool-bar item which is displayed in GLYPH
12225 on frame F. Return in *PROP_IDX the index where tool-bar item
12226 properties start in F->tool_bar_items. Value is zero if
12227 GLYPH doesn't display a tool-bar item. */
12230 tool_bar_item_info (struct frame
*f
, struct glyph
*glyph
, int *prop_idx
)
12236 /* This function can be called asynchronously, which means we must
12237 exclude any possibility that Fget_text_property signals an
12239 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
12240 charpos
= max (0, charpos
);
12242 /* Get the text property `menu-item' at pos. The value of that
12243 property is the start index of this item's properties in
12244 F->tool_bar_items. */
12245 prop
= Fget_text_property (make_number (charpos
),
12246 Qmenu_item
, f
->current_tool_bar_string
);
12247 if (INTEGERP (prop
))
12249 *prop_idx
= XINT (prop
);
12259 /* Get information about the tool-bar item at position X/Y on frame F.
12260 Return in *GLYPH a pointer to the glyph of the tool-bar item in
12261 the current matrix of the tool-bar window of F, or NULL if not
12262 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
12263 item in F->tool_bar_items. Value is
12265 -1 if X/Y is not on a tool-bar item
12266 0 if X/Y is on the same item that was highlighted before.
12270 get_tool_bar_item (struct frame
*f
, int x
, int y
, struct glyph
**glyph
,
12271 int *hpos
, int *vpos
, int *prop_idx
)
12273 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12274 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12277 /* Find the glyph under X/Y. */
12278 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
12279 if (*glyph
== NULL
)
12282 /* Get the start of this tool-bar item's properties in
12283 f->tool_bar_items. */
12284 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
12287 /* Is mouse on the highlighted item? */
12288 if (EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
)
12289 && *vpos
>= hlinfo
->mouse_face_beg_row
12290 && *vpos
<= hlinfo
->mouse_face_end_row
12291 && (*vpos
> hlinfo
->mouse_face_beg_row
12292 || *hpos
>= hlinfo
->mouse_face_beg_col
)
12293 && (*vpos
< hlinfo
->mouse_face_end_row
12294 || *hpos
< hlinfo
->mouse_face_end_col
12295 || hlinfo
->mouse_face_past_end
))
12303 Handle mouse button event on the tool-bar of frame F, at
12304 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
12305 0 for button release. MODIFIERS is event modifiers for button
12309 handle_tool_bar_click (struct frame
*f
, int x
, int y
, int down_p
,
12312 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12313 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12314 int hpos
, vpos
, prop_idx
;
12315 struct glyph
*glyph
;
12316 Lisp_Object enabled_p
;
12319 /* If not on the highlighted tool-bar item, and mouse-highlight is
12320 non-nil, return. This is so we generate the tool-bar button
12321 click only when the mouse button is released on the same item as
12322 where it was pressed. However, when mouse-highlight is disabled,
12323 generate the click when the button is released regardless of the
12324 highlight, since tool-bar items are not highlighted in that
12326 frame_to_window_pixel_xy (w
, &x
, &y
);
12327 ts
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
12329 || (ts
!= 0 && !NILP (Vmouse_highlight
)))
12332 /* When mouse-highlight is off, generate the click for the item
12333 where the button was pressed, disregarding where it was
12335 if (NILP (Vmouse_highlight
) && !down_p
)
12336 prop_idx
= last_tool_bar_item
;
12338 /* If item is disabled, do nothing. */
12339 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12340 if (NILP (enabled_p
))
12345 /* Show item in pressed state. */
12346 if (!NILP (Vmouse_highlight
))
12347 show_mouse_face (hlinfo
, DRAW_IMAGE_SUNKEN
);
12348 last_tool_bar_item
= prop_idx
;
12352 Lisp_Object key
, frame
;
12353 struct input_event event
;
12354 EVENT_INIT (event
);
12356 /* Show item in released state. */
12357 if (!NILP (Vmouse_highlight
))
12358 show_mouse_face (hlinfo
, DRAW_IMAGE_RAISED
);
12360 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
12362 XSETFRAME (frame
, f
);
12363 event
.kind
= TOOL_BAR_EVENT
;
12364 event
.frame_or_window
= frame
;
12366 kbd_buffer_store_event (&event
);
12368 event
.kind
= TOOL_BAR_EVENT
;
12369 event
.frame_or_window
= frame
;
12371 event
.modifiers
= modifiers
;
12372 kbd_buffer_store_event (&event
);
12373 last_tool_bar_item
= -1;
12378 /* Possibly highlight a tool-bar item on frame F when mouse moves to
12379 tool-bar window-relative coordinates X/Y. Called from
12380 note_mouse_highlight. */
12383 note_tool_bar_highlight (struct frame
*f
, int x
, int y
)
12385 Lisp_Object window
= f
->tool_bar_window
;
12386 struct window
*w
= XWINDOW (window
);
12387 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12388 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12390 struct glyph
*glyph
;
12391 struct glyph_row
*row
;
12393 Lisp_Object enabled_p
;
12395 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
12396 int mouse_down_p
, rc
;
12398 /* Function note_mouse_highlight is called with negative X/Y
12399 values when mouse moves outside of the frame. */
12400 if (x
<= 0 || y
<= 0)
12402 clear_mouse_face (hlinfo
);
12406 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
12409 /* Not on tool-bar item. */
12410 clear_mouse_face (hlinfo
);
12414 /* On same tool-bar item as before. */
12415 goto set_help_echo
;
12417 clear_mouse_face (hlinfo
);
12419 /* Mouse is down, but on different tool-bar item? */
12420 mouse_down_p
= (dpyinfo
->grabbed
12421 && f
== last_mouse_frame
12422 && FRAME_LIVE_P (f
));
12424 && last_tool_bar_item
!= prop_idx
)
12427 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
12429 /* If tool-bar item is not enabled, don't highlight it. */
12430 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12431 if (!NILP (enabled_p
) && !NILP (Vmouse_highlight
))
12433 /* Compute the x-position of the glyph. In front and past the
12434 image is a space. We include this in the highlighted area. */
12435 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
12436 for (i
= x
= 0; i
< hpos
; ++i
)
12437 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
12439 /* Record this as the current active region. */
12440 hlinfo
->mouse_face_beg_col
= hpos
;
12441 hlinfo
->mouse_face_beg_row
= vpos
;
12442 hlinfo
->mouse_face_beg_x
= x
;
12443 hlinfo
->mouse_face_past_end
= 0;
12445 hlinfo
->mouse_face_end_col
= hpos
+ 1;
12446 hlinfo
->mouse_face_end_row
= vpos
;
12447 hlinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
12448 hlinfo
->mouse_face_window
= window
;
12449 hlinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
12451 /* Display it as active. */
12452 show_mouse_face (hlinfo
, draw
);
12457 /* Set help_echo_string to a help string to display for this tool-bar item.
12458 XTread_socket does the rest. */
12459 help_echo_object
= help_echo_window
= Qnil
;
12460 help_echo_pos
= -1;
12461 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
12462 if (NILP (help_echo_string
))
12463 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
12466 #endif /* HAVE_WINDOW_SYSTEM */
12470 /************************************************************************
12471 Horizontal scrolling
12472 ************************************************************************/
12474 static int hscroll_window_tree (Lisp_Object
);
12475 static int hscroll_windows (Lisp_Object
);
12477 /* For all leaf windows in the window tree rooted at WINDOW, set their
12478 hscroll value so that PT is (i) visible in the window, and (ii) so
12479 that it is not within a certain margin at the window's left and
12480 right border. Value is non-zero if any window's hscroll has been
12484 hscroll_window_tree (Lisp_Object window
)
12486 int hscrolled_p
= 0;
12487 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
12488 int hscroll_step_abs
= 0;
12489 double hscroll_step_rel
= 0;
12491 if (hscroll_relative_p
)
12493 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
12494 if (hscroll_step_rel
< 0)
12496 hscroll_relative_p
= 0;
12497 hscroll_step_abs
= 0;
12500 else if (TYPE_RANGED_INTEGERP (int, Vhscroll_step
))
12502 hscroll_step_abs
= XINT (Vhscroll_step
);
12503 if (hscroll_step_abs
< 0)
12504 hscroll_step_abs
= 0;
12507 hscroll_step_abs
= 0;
12509 while (WINDOWP (window
))
12511 struct window
*w
= XWINDOW (window
);
12513 if (WINDOWP (w
->contents
))
12514 hscrolled_p
|= hscroll_window_tree (w
->contents
);
12515 else if (w
->cursor
.vpos
>= 0)
12518 int text_area_width
;
12519 struct glyph_row
*current_cursor_row
12520 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
12521 struct glyph_row
*desired_cursor_row
12522 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
12523 struct glyph_row
*cursor_row
12524 = (desired_cursor_row
->enabled_p
12525 ? desired_cursor_row
12526 : current_cursor_row
);
12527 int row_r2l_p
= cursor_row
->reversed_p
;
12529 text_area_width
= window_box_width (w
, TEXT_AREA
);
12531 /* Scroll when cursor is inside this scroll margin. */
12532 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
12534 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->contents
))
12535 /* For left-to-right rows, hscroll when cursor is either
12536 (i) inside the right hscroll margin, or (ii) if it is
12537 inside the left margin and the window is already
12541 && w
->cursor
.x
<= h_margin
)
12542 || (cursor_row
->enabled_p
12543 && cursor_row
->truncated_on_right_p
12544 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
12545 /* For right-to-left rows, the logic is similar,
12546 except that rules for scrolling to left and right
12547 are reversed. E.g., if cursor.x <= h_margin, we
12548 need to hscroll "to the right" unconditionally,
12549 and that will scroll the screen to the left so as
12550 to reveal the next portion of the row. */
12552 && ((cursor_row
->enabled_p
12553 /* FIXME: It is confusing to set the
12554 truncated_on_right_p flag when R2L rows
12555 are actually truncated on the left. */
12556 && cursor_row
->truncated_on_right_p
12557 && w
->cursor
.x
<= h_margin
)
12559 && (w
->cursor
.x
>= text_area_width
- h_margin
))))))
12563 struct buffer
*saved_current_buffer
;
12567 /* Find point in a display of infinite width. */
12568 saved_current_buffer
= current_buffer
;
12569 current_buffer
= XBUFFER (w
->contents
);
12571 if (w
== XWINDOW (selected_window
))
12574 pt
= clip_to_bounds (BEGV
, marker_position (w
->pointm
), ZV
);
12576 /* Move iterator to pt starting at cursor_row->start in
12577 a line with infinite width. */
12578 init_to_row_start (&it
, w
, cursor_row
);
12579 it
.last_visible_x
= INFINITY
;
12580 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
12581 current_buffer
= saved_current_buffer
;
12583 /* Position cursor in window. */
12584 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
12585 hscroll
= max (0, (it
.current_x
12586 - (ITERATOR_AT_END_OF_LINE_P (&it
)
12587 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
12588 : (text_area_width
/ 2))))
12589 / FRAME_COLUMN_WIDTH (it
.f
);
12590 else if ((!row_r2l_p
12591 && w
->cursor
.x
>= text_area_width
- h_margin
)
12592 || (row_r2l_p
&& w
->cursor
.x
<= h_margin
))
12594 if (hscroll_relative_p
)
12595 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
12598 wanted_x
= text_area_width
12599 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12602 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12606 if (hscroll_relative_p
)
12607 wanted_x
= text_area_width
* hscroll_step_rel
12610 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12613 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12615 hscroll
= max (hscroll
, w
->min_hscroll
);
12617 /* Don't prevent redisplay optimizations if hscroll
12618 hasn't changed, as it will unnecessarily slow down
12620 if (w
->hscroll
!= hscroll
)
12622 XBUFFER (w
->contents
)->prevent_redisplay_optimizations_p
= 1;
12623 w
->hscroll
= hscroll
;
12632 /* Value is non-zero if hscroll of any leaf window has been changed. */
12633 return hscrolled_p
;
12637 /* Set hscroll so that cursor is visible and not inside horizontal
12638 scroll margins for all windows in the tree rooted at WINDOW. See
12639 also hscroll_window_tree above. Value is non-zero if any window's
12640 hscroll has been changed. If it has, desired matrices on the frame
12641 of WINDOW are cleared. */
12644 hscroll_windows (Lisp_Object window
)
12646 int hscrolled_p
= hscroll_window_tree (window
);
12648 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
12649 return hscrolled_p
;
12654 /************************************************************************
12656 ************************************************************************/
12658 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
12659 to a non-zero value. This is sometimes handy to have in a debugger
12664 /* First and last unchanged row for try_window_id. */
12666 static int debug_first_unchanged_at_end_vpos
;
12667 static int debug_last_unchanged_at_beg_vpos
;
12669 /* Delta vpos and y. */
12671 static int debug_dvpos
, debug_dy
;
12673 /* Delta in characters and bytes for try_window_id. */
12675 static ptrdiff_t debug_delta
, debug_delta_bytes
;
12677 /* Values of window_end_pos and window_end_vpos at the end of
12680 static ptrdiff_t debug_end_vpos
;
12682 /* Append a string to W->desired_matrix->method. FMT is a printf
12683 format string. If trace_redisplay_p is non-zero also printf the
12684 resulting string to stderr. */
12686 static void debug_method_add (struct window
*, char const *, ...)
12687 ATTRIBUTE_FORMAT_PRINTF (2, 3);
12690 debug_method_add (struct window
*w
, char const *fmt
, ...)
12693 char *method
= w
->desired_matrix
->method
;
12694 int len
= strlen (method
);
12695 int size
= sizeof w
->desired_matrix
->method
;
12696 int remaining
= size
- len
- 1;
12699 if (len
&& remaining
)
12702 --remaining
, ++len
;
12705 va_start (ap
, fmt
);
12706 vsnprintf (method
+ len
, remaining
+ 1, fmt
, ap
);
12709 if (trace_redisplay_p
)
12710 fprintf (stderr
, "%p (%s): %s\n",
12712 ((BUFFERP (w
->contents
)
12713 && STRINGP (BVAR (XBUFFER (w
->contents
), name
)))
12714 ? SSDATA (BVAR (XBUFFER (w
->contents
), name
))
12719 #endif /* GLYPH_DEBUG */
12722 /* Value is non-zero if all changes in window W, which displays
12723 current_buffer, are in the text between START and END. START is a
12724 buffer position, END is given as a distance from Z. Used in
12725 redisplay_internal for display optimization. */
12728 text_outside_line_unchanged_p (struct window
*w
,
12729 ptrdiff_t start
, ptrdiff_t end
)
12731 int unchanged_p
= 1;
12733 /* If text or overlays have changed, see where. */
12734 if (window_outdated (w
))
12736 /* Gap in the line? */
12737 if (GPT
< start
|| Z
- GPT
< end
)
12740 /* Changes start in front of the line, or end after it? */
12742 && (BEG_UNCHANGED
< start
- 1
12743 || END_UNCHANGED
< end
))
12746 /* If selective display, can't optimize if changes start at the
12747 beginning of the line. */
12749 && INTEGERP (BVAR (current_buffer
, selective_display
))
12750 && XINT (BVAR (current_buffer
, selective_display
)) > 0
12751 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
12754 /* If there are overlays at the start or end of the line, these
12755 may have overlay strings with newlines in them. A change at
12756 START, for instance, may actually concern the display of such
12757 overlay strings as well, and they are displayed on different
12758 lines. So, quickly rule out this case. (For the future, it
12759 might be desirable to implement something more telling than
12760 just BEG/END_UNCHANGED.) */
12763 if (BEG
+ BEG_UNCHANGED
== start
12764 && overlay_touches_p (start
))
12766 if (END_UNCHANGED
== end
12767 && overlay_touches_p (Z
- end
))
12771 /* Under bidi reordering, adding or deleting a character in the
12772 beginning of a paragraph, before the first strong directional
12773 character, can change the base direction of the paragraph (unless
12774 the buffer specifies a fixed paragraph direction), which will
12775 require to redisplay the whole paragraph. It might be worthwhile
12776 to find the paragraph limits and widen the range of redisplayed
12777 lines to that, but for now just give up this optimization. */
12778 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
12779 && NILP (BVAR (XBUFFER (w
->contents
), bidi_paragraph_direction
)))
12783 return unchanged_p
;
12787 /* Do a frame update, taking possible shortcuts into account. This is
12788 the main external entry point for redisplay.
12790 If the last redisplay displayed an echo area message and that message
12791 is no longer requested, we clear the echo area or bring back the
12792 mini-buffer if that is in use. */
12797 redisplay_internal ();
12802 overlay_arrow_string_or_property (Lisp_Object var
)
12806 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
12809 return Voverlay_arrow_string
;
12812 /* Return 1 if there are any overlay-arrows in current_buffer. */
12814 overlay_arrow_in_current_buffer_p (void)
12818 for (vlist
= Voverlay_arrow_variable_list
;
12820 vlist
= XCDR (vlist
))
12822 Lisp_Object var
= XCAR (vlist
);
12825 if (!SYMBOLP (var
))
12827 val
= find_symbol_value (var
);
12829 && current_buffer
== XMARKER (val
)->buffer
)
12836 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
12840 overlay_arrows_changed_p (void)
12844 for (vlist
= Voverlay_arrow_variable_list
;
12846 vlist
= XCDR (vlist
))
12848 Lisp_Object var
= XCAR (vlist
);
12849 Lisp_Object val
, pstr
;
12851 if (!SYMBOLP (var
))
12853 val
= find_symbol_value (var
);
12854 if (!MARKERP (val
))
12856 if (! EQ (COERCE_MARKER (val
),
12857 Fget (var
, Qlast_arrow_position
))
12858 || ! (pstr
= overlay_arrow_string_or_property (var
),
12859 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
12865 /* Mark overlay arrows to be updated on next redisplay. */
12868 update_overlay_arrows (int up_to_date
)
12872 for (vlist
= Voverlay_arrow_variable_list
;
12874 vlist
= XCDR (vlist
))
12876 Lisp_Object var
= XCAR (vlist
);
12878 if (!SYMBOLP (var
))
12881 if (up_to_date
> 0)
12883 Lisp_Object val
= find_symbol_value (var
);
12884 Fput (var
, Qlast_arrow_position
,
12885 COERCE_MARKER (val
));
12886 Fput (var
, Qlast_arrow_string
,
12887 overlay_arrow_string_or_property (var
));
12889 else if (up_to_date
< 0
12890 || !NILP (Fget (var
, Qlast_arrow_position
)))
12892 Fput (var
, Qlast_arrow_position
, Qt
);
12893 Fput (var
, Qlast_arrow_string
, Qt
);
12899 /* Return overlay arrow string to display at row.
12900 Return integer (bitmap number) for arrow bitmap in left fringe.
12901 Return nil if no overlay arrow. */
12904 overlay_arrow_at_row (struct it
*it
, struct glyph_row
*row
)
12908 for (vlist
= Voverlay_arrow_variable_list
;
12910 vlist
= XCDR (vlist
))
12912 Lisp_Object var
= XCAR (vlist
);
12915 if (!SYMBOLP (var
))
12918 val
= find_symbol_value (var
);
12921 && current_buffer
== XMARKER (val
)->buffer
12922 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
12924 if (FRAME_WINDOW_P (it
->f
)
12925 /* FIXME: if ROW->reversed_p is set, this should test
12926 the right fringe, not the left one. */
12927 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
12929 #ifdef HAVE_WINDOW_SYSTEM
12930 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
12933 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
12934 return make_number (fringe_bitmap
);
12937 return make_number (-1); /* Use default arrow bitmap. */
12939 return overlay_arrow_string_or_property (var
);
12946 /* Return 1 if point moved out of or into a composition. Otherwise
12947 return 0. PREV_BUF and PREV_PT are the last point buffer and
12948 position. BUF and PT are the current point buffer and position. */
12951 check_point_in_composition (struct buffer
*prev_buf
, ptrdiff_t prev_pt
,
12952 struct buffer
*buf
, ptrdiff_t pt
)
12954 ptrdiff_t start
, end
;
12956 Lisp_Object buffer
;
12958 XSETBUFFER (buffer
, buf
);
12959 /* Check a composition at the last point if point moved within the
12961 if (prev_buf
== buf
)
12964 /* Point didn't move. */
12967 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
12968 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
12969 && composition_valid_p (start
, end
, prop
)
12970 && start
< prev_pt
&& end
> prev_pt
)
12971 /* The last point was within the composition. Return 1 iff
12972 point moved out of the composition. */
12973 return (pt
<= start
|| pt
>= end
);
12976 /* Check a composition at the current point. */
12977 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
12978 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
12979 && composition_valid_p (start
, end
, prop
)
12980 && start
< pt
&& end
> pt
);
12983 /* Reconsider the clip changes of buffer which is displayed in W. */
12986 reconsider_clip_changes (struct window
*w
)
12988 struct buffer
*b
= XBUFFER (w
->contents
);
12990 if (b
->clip_changed
12991 && w
->window_end_valid
12992 && w
->current_matrix
->buffer
== b
12993 && w
->current_matrix
->zv
== BUF_ZV (b
)
12994 && w
->current_matrix
->begv
== BUF_BEGV (b
))
12995 b
->clip_changed
= 0;
12997 /* If display wasn't paused, and W is not a tool bar window, see if
12998 point has been moved into or out of a composition. In that case,
12999 we set b->clip_changed to 1 to force updating the screen. If
13000 b->clip_changed has already been set to 1, we can skip this
13002 if (!b
->clip_changed
&& w
->window_end_valid
)
13004 ptrdiff_t pt
= (w
== XWINDOW (selected_window
)
13005 ? PT
: marker_position (w
->pointm
));
13007 if ((w
->current_matrix
->buffer
!= b
|| pt
!= w
->last_point
)
13008 && check_point_in_composition (w
->current_matrix
->buffer
,
13009 w
->last_point
, b
, pt
))
13010 b
->clip_changed
= 1;
13014 #define STOP_POLLING \
13015 do { if (! polling_stopped_here) stop_polling (); \
13016 polling_stopped_here = 1; } while (0)
13018 #define RESUME_POLLING \
13019 do { if (polling_stopped_here) start_polling (); \
13020 polling_stopped_here = 0; } while (0)
13023 /* Perhaps in the future avoid recentering windows if it
13024 is not necessary; currently that causes some problems. */
13027 redisplay_internal (void)
13029 struct window
*w
= XWINDOW (selected_window
);
13033 bool must_finish
= 0, match_p
;
13034 struct text_pos tlbufpos
, tlendpos
;
13035 int number_of_visible_frames
;
13038 int polling_stopped_here
= 0;
13039 Lisp_Object tail
, frame
;
13041 /* Non-zero means redisplay has to consider all windows on all
13042 frames. Zero means, only selected_window is considered. */
13043 int consider_all_windows_p
;
13045 /* Non-zero means redisplay has to redisplay the miniwindow. */
13046 int update_miniwindow_p
= 0;
13048 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
13050 /* No redisplay if running in batch mode or frame is not yet fully
13051 initialized, or redisplay is explicitly turned off by setting
13052 Vinhibit_redisplay. */
13053 if (FRAME_INITIAL_P (SELECTED_FRAME ())
13054 || !NILP (Vinhibit_redisplay
))
13057 /* Don't examine these until after testing Vinhibit_redisplay.
13058 When Emacs is shutting down, perhaps because its connection to
13059 X has dropped, we should not look at them at all. */
13060 fr
= XFRAME (w
->frame
);
13061 sf
= SELECTED_FRAME ();
13063 if (!fr
->glyphs_initialized_p
)
13066 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
13067 if (popup_activated ())
13071 /* I don't think this happens but let's be paranoid. */
13072 if (redisplaying_p
)
13075 /* Record a function that clears redisplaying_p
13076 when we leave this function. */
13077 count
= SPECPDL_INDEX ();
13078 record_unwind_protect_void (unwind_redisplay
);
13079 redisplaying_p
= 1;
13080 specbind (Qinhibit_free_realized_faces
, Qnil
);
13082 /* Record this function, so it appears on the profiler's backtraces. */
13083 record_in_backtrace (Qredisplay_internal
, &Qnil
, 0);
13085 FOR_EACH_FRAME (tail
, frame
)
13086 XFRAME (frame
)->already_hscrolled_p
= 0;
13089 /* Remember the currently selected window. */
13093 last_escape_glyph_frame
= NULL
;
13094 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
13095 last_glyphless_glyph_frame
= NULL
;
13096 last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
13098 /* If new fonts have been loaded that make a glyph matrix adjustment
13099 necessary, do it. */
13100 if (fonts_changed_p
)
13102 adjust_glyphs (NULL
);
13103 ++windows_or_buffers_changed
;
13104 fonts_changed_p
= 0;
13107 /* If face_change_count is non-zero, init_iterator will free all
13108 realized faces, which includes the faces referenced from current
13109 matrices. So, we can't reuse current matrices in this case. */
13110 if (face_change_count
)
13111 ++windows_or_buffers_changed
;
13113 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
13114 && FRAME_TTY (sf
)->previous_frame
!= sf
)
13116 /* Since frames on a single ASCII terminal share the same
13117 display area, displaying a different frame means redisplay
13118 the whole thing. */
13119 windows_or_buffers_changed
++;
13120 SET_FRAME_GARBAGED (sf
);
13122 set_tty_color_mode (FRAME_TTY (sf
), sf
);
13124 FRAME_TTY (sf
)->previous_frame
= sf
;
13127 /* Set the visible flags for all frames. Do this before checking for
13128 resized or garbaged frames; they want to know if their frames are
13129 visible. See the comment in frame.h for FRAME_SAMPLE_VISIBILITY. */
13130 number_of_visible_frames
= 0;
13132 FOR_EACH_FRAME (tail
, frame
)
13134 struct frame
*f
= XFRAME (frame
);
13136 if (FRAME_VISIBLE_P (f
))
13137 ++number_of_visible_frames
;
13138 clear_desired_matrices (f
);
13141 /* Notice any pending interrupt request to change frame size. */
13142 do_pending_window_change (1);
13144 /* do_pending_window_change could change the selected_window due to
13145 frame resizing which makes the selected window too small. */
13146 if (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
)
13149 /* Clear frames marked as garbaged. */
13150 clear_garbaged_frames ();
13152 /* Build menubar and tool-bar items. */
13153 if (NILP (Vmemory_full
))
13154 prepare_menu_bars ();
13156 if (windows_or_buffers_changed
)
13157 update_mode_lines
++;
13159 reconsider_clip_changes (w
);
13161 /* In most cases selected window displays current buffer. */
13162 match_p
= XBUFFER (w
->contents
) == current_buffer
;
13167 /* Detect case that we need to write or remove a star in the mode line. */
13168 if ((SAVE_MODIFF
< MODIFF
) != w
->last_had_star
)
13170 w
->update_mode_line
= 1;
13171 if (buffer_shared_and_changed ())
13172 update_mode_lines
++;
13175 /* Avoid invocation of point motion hooks by `current_column' below. */
13176 count1
= SPECPDL_INDEX ();
13177 specbind (Qinhibit_point_motion_hooks
, Qt
);
13179 if (mode_line_update_needed (w
))
13180 w
->update_mode_line
= 1;
13182 unbind_to (count1
, Qnil
);
13185 consider_all_windows_p
= (update_mode_lines
13186 || buffer_shared_and_changed ()
13187 || cursor_type_changed
);
13189 /* If specs for an arrow have changed, do thorough redisplay
13190 to ensure we remove any arrow that should no longer exist. */
13191 if (overlay_arrows_changed_p ())
13192 consider_all_windows_p
= windows_or_buffers_changed
= 1;
13194 /* Normally the message* functions will have already displayed and
13195 updated the echo area, but the frame may have been trashed, or
13196 the update may have been preempted, so display the echo area
13197 again here. Checking message_cleared_p captures the case that
13198 the echo area should be cleared. */
13199 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
13200 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
13201 || (message_cleared_p
13202 && minibuf_level
== 0
13203 /* If the mini-window is currently selected, this means the
13204 echo-area doesn't show through. */
13205 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
13207 int window_height_changed_p
= echo_area_display (0);
13209 if (message_cleared_p
)
13210 update_miniwindow_p
= 1;
13214 /* If we don't display the current message, don't clear the
13215 message_cleared_p flag, because, if we did, we wouldn't clear
13216 the echo area in the next redisplay which doesn't preserve
13218 if (!display_last_displayed_message_p
)
13219 message_cleared_p
= 0;
13221 if (fonts_changed_p
)
13223 else if (window_height_changed_p
)
13225 consider_all_windows_p
= 1;
13226 ++update_mode_lines
;
13227 ++windows_or_buffers_changed
;
13229 /* If window configuration was changed, frames may have been
13230 marked garbaged. Clear them or we will experience
13231 surprises wrt scrolling. */
13232 clear_garbaged_frames ();
13235 else if (EQ (selected_window
, minibuf_window
)
13236 && (current_buffer
->clip_changed
|| window_outdated (w
))
13237 && resize_mini_window (w
, 0))
13239 /* Resized active mini-window to fit the size of what it is
13240 showing if its contents might have changed. */
13242 /* FIXME: this causes all frames to be updated, which seems unnecessary
13243 since only the current frame needs to be considered. This function
13244 needs to be rewritten with two variables, consider_all_windows and
13245 consider_all_frames. */
13246 consider_all_windows_p
= 1;
13247 ++windows_or_buffers_changed
;
13248 ++update_mode_lines
;
13250 /* If window configuration was changed, frames may have been
13251 marked garbaged. Clear them or we will experience
13252 surprises wrt scrolling. */
13253 clear_garbaged_frames ();
13256 /* If showing the region, and mark has changed, we must redisplay
13257 the whole window. The assignment to this_line_start_pos prevents
13258 the optimization directly below this if-statement. */
13259 if (((!NILP (Vtransient_mark_mode
)
13260 && !NILP (BVAR (XBUFFER (w
->contents
), mark_active
)))
13261 != (w
->region_showing
> 0))
13262 || (w
->region_showing
13263 && w
->region_showing
13264 != XINT (Fmarker_position (BVAR (XBUFFER (w
->contents
), mark
)))))
13265 CHARPOS (this_line_start_pos
) = 0;
13267 /* Optimize the case that only the line containing the cursor in the
13268 selected window has changed. Variables starting with this_ are
13269 set in display_line and record information about the line
13270 containing the cursor. */
13271 tlbufpos
= this_line_start_pos
;
13272 tlendpos
= this_line_end_pos
;
13273 if (!consider_all_windows_p
13274 && CHARPOS (tlbufpos
) > 0
13275 && !w
->update_mode_line
13276 && !current_buffer
->clip_changed
13277 && !current_buffer
->prevent_redisplay_optimizations_p
13278 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
13279 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
13280 /* Make sure recorded data applies to current buffer, etc. */
13281 && this_line_buffer
== current_buffer
13284 && !w
->optional_new_start
13285 /* Point must be on the line that we have info recorded about. */
13286 && PT
>= CHARPOS (tlbufpos
)
13287 && PT
<= Z
- CHARPOS (tlendpos
)
13288 /* All text outside that line, including its final newline,
13289 must be unchanged. */
13290 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
13291 CHARPOS (tlendpos
)))
13293 if (CHARPOS (tlbufpos
) > BEGV
13294 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
13295 && (CHARPOS (tlbufpos
) == ZV
13296 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
13297 /* Former continuation line has disappeared by becoming empty. */
13299 else if (window_outdated (w
) || MINI_WINDOW_P (w
))
13301 /* We have to handle the case of continuation around a
13302 wide-column character (see the comment in indent.c around
13305 For instance, in the following case:
13307 -------- Insert --------
13308 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
13309 J_I_ ==> J_I_ `^^' are cursors.
13313 As we have to redraw the line above, we cannot use this
13317 int line_height_before
= this_line_pixel_height
;
13319 /* Note that start_display will handle the case that the
13320 line starting at tlbufpos is a continuation line. */
13321 start_display (&it
, w
, tlbufpos
);
13323 /* Implementation note: It this still necessary? */
13324 if (it
.current_x
!= this_line_start_x
)
13327 TRACE ((stderr
, "trying display optimization 1\n"));
13328 w
->cursor
.vpos
= -1;
13329 overlay_arrow_seen
= 0;
13330 it
.vpos
= this_line_vpos
;
13331 it
.current_y
= this_line_y
;
13332 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
13333 display_line (&it
);
13335 /* If line contains point, is not continued,
13336 and ends at same distance from eob as before, we win. */
13337 if (w
->cursor
.vpos
>= 0
13338 /* Line is not continued, otherwise this_line_start_pos
13339 would have been set to 0 in display_line. */
13340 && CHARPOS (this_line_start_pos
)
13341 /* Line ends as before. */
13342 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
13343 /* Line has same height as before. Otherwise other lines
13344 would have to be shifted up or down. */
13345 && this_line_pixel_height
== line_height_before
)
13347 /* If this is not the window's last line, we must adjust
13348 the charstarts of the lines below. */
13349 if (it
.current_y
< it
.last_visible_y
)
13351 struct glyph_row
*row
13352 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
13353 ptrdiff_t delta
, delta_bytes
;
13355 /* We used to distinguish between two cases here,
13356 conditioned by Z - CHARPOS (tlendpos) == ZV, for
13357 when the line ends in a newline or the end of the
13358 buffer's accessible portion. But both cases did
13359 the same, so they were collapsed. */
13361 - CHARPOS (tlendpos
)
13362 - MATRIX_ROW_START_CHARPOS (row
));
13363 delta_bytes
= (Z_BYTE
13364 - BYTEPOS (tlendpos
)
13365 - MATRIX_ROW_START_BYTEPOS (row
));
13367 increment_matrix_positions (w
->current_matrix
,
13368 this_line_vpos
+ 1,
13369 w
->current_matrix
->nrows
,
13370 delta
, delta_bytes
);
13373 /* If this row displays text now but previously didn't,
13374 or vice versa, w->window_end_vpos may have to be
13376 if (MATRIX_ROW_DISPLAYS_TEXT_P (it
.glyph_row
- 1))
13378 if (w
->window_end_vpos
< this_line_vpos
)
13379 w
->window_end_vpos
= this_line_vpos
;
13381 else if (w
->window_end_vpos
== this_line_vpos
13382 && this_line_vpos
> 0)
13383 w
->window_end_vpos
= this_line_vpos
- 1;
13384 w
->window_end_valid
= 0;
13386 /* Update hint: No need to try to scroll in update_window. */
13387 w
->desired_matrix
->no_scrolling_p
= 1;
13390 *w
->desired_matrix
->method
= 0;
13391 debug_method_add (w
, "optimization 1");
13394 //debug optimization movement issue
13395 //w->desired_matrix->no_scrolling_p = 1;
13396 //*w->desired_matrix->method = 0;
13397 //debug_method_add (w, "optimization 1");
13400 #ifdef HAVE_WINDOW_SYSTEM
13401 update_window_fringes (w
, 0);
13408 else if (/* Cursor position hasn't changed. */
13409 PT
== w
->last_point
13410 /* Make sure the cursor was last displayed
13411 in this window. Otherwise we have to reposition it. */
13412 && 0 <= w
->cursor
.vpos
13413 && w
->cursor
.vpos
< WINDOW_TOTAL_LINES (w
))
13417 do_pending_window_change (1);
13418 /* If selected_window changed, redisplay again. */
13419 if (WINDOWP (selected_window
)
13420 && (w
= XWINDOW (selected_window
)) != sw
)
13423 /* We used to always goto end_of_redisplay here, but this
13424 isn't enough if we have a blinking cursor. */
13425 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
13426 goto end_of_redisplay
;
13430 /* If highlighting the region, or if the cursor is in the echo area,
13431 then we can't just move the cursor. */
13432 else if (! (!NILP (Vtransient_mark_mode
)
13433 && !NILP (BVAR (current_buffer
, mark_active
)))
13434 && (EQ (selected_window
,
13435 BVAR (current_buffer
, last_selected_window
))
13436 || highlight_nonselected_windows
)
13437 && !w
->region_showing
13438 && NILP (Vshow_trailing_whitespace
)
13439 && !cursor_in_echo_area
)
13442 struct glyph_row
*row
;
13444 /* Skip from tlbufpos to PT and see where it is. Note that
13445 PT may be in invisible text. If so, we will end at the
13446 next visible position. */
13447 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
13448 NULL
, DEFAULT_FACE_ID
);
13449 it
.current_x
= this_line_start_x
;
13450 it
.current_y
= this_line_y
;
13451 it
.vpos
= this_line_vpos
;
13453 /* The call to move_it_to stops in front of PT, but
13454 moves over before-strings. */
13455 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
13457 if (it
.vpos
== this_line_vpos
13458 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
13461 eassert (this_line_vpos
== it
.vpos
);
13462 eassert (this_line_y
== it
.current_y
);
13463 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13465 *w
->desired_matrix
->method
= 0;
13466 debug_method_add (w
, "optimization 3");
13475 /* Text changed drastically or point moved off of line. */
13476 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
13479 CHARPOS (this_line_start_pos
) = 0;
13480 consider_all_windows_p
|= buffer_shared_and_changed ();
13481 ++clear_face_cache_count
;
13482 #ifdef HAVE_WINDOW_SYSTEM
13483 ++clear_image_cache_count
;
13486 /* Build desired matrices, and update the display. If
13487 consider_all_windows_p is non-zero, do it for all windows on all
13488 frames. Otherwise do it for selected_window, only. */
13490 if (consider_all_windows_p
)
13492 FOR_EACH_FRAME (tail
, frame
)
13493 XFRAME (frame
)->updated_p
= 0;
13495 FOR_EACH_FRAME (tail
, frame
)
13497 struct frame
*f
= XFRAME (frame
);
13499 /* We don't have to do anything for unselected terminal
13501 if ((FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
13502 && !EQ (FRAME_TTY (f
)->top_frame
, frame
))
13505 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
13507 /* Mark all the scroll bars to be removed; we'll redeem
13508 the ones we want when we redisplay their windows. */
13509 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
13510 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
13512 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13513 redisplay_windows (FRAME_ROOT_WINDOW (f
));
13515 /* The X error handler may have deleted that frame. */
13516 if (!FRAME_LIVE_P (f
))
13519 /* Any scroll bars which redisplay_windows should have
13520 nuked should now go away. */
13521 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
13522 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
13524 /* If fonts changed, display again. */
13525 /* ??? rms: I suspect it is a mistake to jump all the way
13526 back to retry here. It should just retry this frame. */
13527 if (fonts_changed_p
)
13530 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13532 /* See if we have to hscroll. */
13533 if (!f
->already_hscrolled_p
)
13535 f
->already_hscrolled_p
= 1;
13536 if (hscroll_windows (f
->root_window
))
13540 /* Prevent various kinds of signals during display
13541 update. stdio is not robust about handling
13542 signals, which can cause an apparent I/O
13544 if (interrupt_input
)
13545 unrequest_sigio ();
13548 /* Update the display. */
13549 set_window_update_flags (XWINDOW (f
->root_window
), 1);
13550 pending
|= update_frame (f
, 0, 0);
13556 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
13560 /* Do the mark_window_display_accurate after all windows have
13561 been redisplayed because this call resets flags in buffers
13562 which are needed for proper redisplay. */
13563 FOR_EACH_FRAME (tail
, frame
)
13565 struct frame
*f
= XFRAME (frame
);
13568 mark_window_display_accurate (f
->root_window
, 1);
13569 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
13570 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
13575 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13577 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13578 struct frame
*mini_frame
;
13580 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->contents
);
13581 /* Use list_of_error, not Qerror, so that
13582 we catch only errors and don't run the debugger. */
13583 internal_condition_case_1 (redisplay_window_1
, selected_window
,
13585 redisplay_window_error
);
13586 if (update_miniwindow_p
)
13587 internal_condition_case_1 (redisplay_window_1
, mini_window
,
13589 redisplay_window_error
);
13591 /* Compare desired and current matrices, perform output. */
13594 /* If fonts changed, display again. */
13595 if (fonts_changed_p
)
13598 /* Prevent various kinds of signals during display update.
13599 stdio is not robust about handling signals,
13600 which can cause an apparent I/O error. */
13601 if (interrupt_input
)
13602 unrequest_sigio ();
13605 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13607 if (hscroll_windows (selected_window
))
13610 XWINDOW (selected_window
)->must_be_updated_p
= 1;
13611 pending
= update_frame (sf
, 0, 0);
13614 /* We may have called echo_area_display at the top of this
13615 function. If the echo area is on another frame, that may
13616 have put text on a frame other than the selected one, so the
13617 above call to update_frame would not have caught it. Catch
13619 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13620 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
13622 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
13624 XWINDOW (mini_window
)->must_be_updated_p
= 1;
13625 pending
|= update_frame (mini_frame
, 0, 0);
13626 if (!pending
&& hscroll_windows (mini_window
))
13631 /* If display was paused because of pending input, make sure we do a
13632 thorough update the next time. */
13635 /* Prevent the optimization at the beginning of
13636 redisplay_internal that tries a single-line update of the
13637 line containing the cursor in the selected window. */
13638 CHARPOS (this_line_start_pos
) = 0;
13640 /* Let the overlay arrow be updated the next time. */
13641 update_overlay_arrows (0);
13643 /* If we pause after scrolling, some rows in the current
13644 matrices of some windows are not valid. */
13645 if (!WINDOW_FULL_WIDTH_P (w
)
13646 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
13647 update_mode_lines
= 1;
13651 if (!consider_all_windows_p
)
13653 /* This has already been done above if
13654 consider_all_windows_p is set. */
13655 mark_window_display_accurate_1 (w
, 1);
13657 /* Say overlay arrows are up to date. */
13658 update_overlay_arrows (1);
13660 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
13661 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
13664 update_mode_lines
= 0;
13665 windows_or_buffers_changed
= 0;
13666 cursor_type_changed
= 0;
13669 /* Start SIGIO interrupts coming again. Having them off during the
13670 code above makes it less likely one will discard output, but not
13671 impossible, since there might be stuff in the system buffer here.
13672 But it is much hairier to try to do anything about that. */
13673 if (interrupt_input
)
13677 /* If a frame has become visible which was not before, redisplay
13678 again, so that we display it. Expose events for such a frame
13679 (which it gets when becoming visible) don't call the parts of
13680 redisplay constructing glyphs, so simply exposing a frame won't
13681 display anything in this case. So, we have to display these
13682 frames here explicitly. */
13687 FOR_EACH_FRAME (tail
, frame
)
13689 int this_is_visible
= 0;
13691 if (XFRAME (frame
)->visible
)
13692 this_is_visible
= 1;
13694 if (this_is_visible
)
13698 if (new_count
!= number_of_visible_frames
)
13699 windows_or_buffers_changed
++;
13702 /* Change frame size now if a change is pending. */
13703 do_pending_window_change (1);
13705 /* If we just did a pending size change, or have additional
13706 visible frames, or selected_window changed, redisplay again. */
13707 if ((windows_or_buffers_changed
&& !pending
)
13708 || (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
))
13711 /* Clear the face and image caches.
13713 We used to do this only if consider_all_windows_p. But the cache
13714 needs to be cleared if a timer creates images in the current
13715 buffer (e.g. the test case in Bug#6230). */
13717 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
13719 clear_face_cache (0);
13720 clear_face_cache_count
= 0;
13723 #ifdef HAVE_WINDOW_SYSTEM
13724 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
13726 clear_image_caches (Qnil
);
13727 clear_image_cache_count
= 0;
13729 #endif /* HAVE_WINDOW_SYSTEM */
13732 unbind_to (count
, Qnil
);
13737 /* Redisplay, but leave alone any recent echo area message unless
13738 another message has been requested in its place.
13740 This is useful in situations where you need to redisplay but no
13741 user action has occurred, making it inappropriate for the message
13742 area to be cleared. See tracking_off and
13743 wait_reading_process_output for examples of these situations.
13745 FROM_WHERE is an integer saying from where this function was
13746 called. This is useful for debugging. */
13749 redisplay_preserve_echo_area (int from_where
)
13751 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
13753 if (!NILP (echo_area_buffer
[1]))
13755 /* We have a previously displayed message, but no current
13756 message. Redisplay the previous message. */
13757 display_last_displayed_message_p
= 1;
13758 redisplay_internal ();
13759 display_last_displayed_message_p
= 0;
13762 redisplay_internal ();
13764 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
13765 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
13766 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
13770 /* Function registered with record_unwind_protect in redisplay_internal. */
13773 unwind_redisplay (void)
13775 redisplaying_p
= 0;
13779 /* Mark the display of leaf window W as accurate or inaccurate.
13780 If ACCURATE_P is non-zero mark display of W as accurate. If
13781 ACCURATE_P is zero, arrange for W to be redisplayed the next
13782 time redisplay_internal is called. */
13785 mark_window_display_accurate_1 (struct window
*w
, int accurate_p
)
13787 struct buffer
*b
= XBUFFER (w
->contents
);
13789 w
->last_modified
= accurate_p
? BUF_MODIFF (b
) : 0;
13790 w
->last_overlay_modified
= accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0;
13791 w
->last_had_star
= BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
);
13795 b
->clip_changed
= 0;
13796 b
->prevent_redisplay_optimizations_p
= 0;
13798 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
13799 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
13800 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
13801 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
13803 w
->current_matrix
->buffer
= b
;
13804 w
->current_matrix
->begv
= BUF_BEGV (b
);
13805 w
->current_matrix
->zv
= BUF_ZV (b
);
13807 w
->last_cursor_vpos
= w
->cursor
.vpos
;
13808 w
->last_cursor_off_p
= w
->cursor_off_p
;
13810 if (w
== XWINDOW (selected_window
))
13811 w
->last_point
= BUF_PT (b
);
13813 w
->last_point
= marker_position (w
->pointm
);
13815 w
->window_end_valid
= 1;
13816 w
->update_mode_line
= 0;
13821 /* Mark the display of windows in the window tree rooted at WINDOW as
13822 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
13823 windows as accurate. If ACCURATE_P is zero, arrange for windows to
13824 be redisplayed the next time redisplay_internal is called. */
13827 mark_window_display_accurate (Lisp_Object window
, int accurate_p
)
13831 for (; !NILP (window
); window
= w
->next
)
13833 w
= XWINDOW (window
);
13834 if (WINDOWP (w
->contents
))
13835 mark_window_display_accurate (w
->contents
, accurate_p
);
13837 mark_window_display_accurate_1 (w
, accurate_p
);
13841 update_overlay_arrows (1);
13843 /* Force a thorough redisplay the next time by setting
13844 last_arrow_position and last_arrow_string to t, which is
13845 unequal to any useful value of Voverlay_arrow_... */
13846 update_overlay_arrows (-1);
13850 /* Return value in display table DP (Lisp_Char_Table *) for character
13851 C. Since a display table doesn't have any parent, we don't have to
13852 follow parent. Do not call this function directly but use the
13853 macro DISP_CHAR_VECTOR. */
13856 disp_char_vector (struct Lisp_Char_Table
*dp
, int c
)
13860 if (ASCII_CHAR_P (c
))
13863 if (SUB_CHAR_TABLE_P (val
))
13864 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
13870 XSETCHAR_TABLE (table
, dp
);
13871 val
= char_table_ref (table
, c
);
13880 /***********************************************************************
13882 ***********************************************************************/
13884 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
13887 redisplay_windows (Lisp_Object window
)
13889 while (!NILP (window
))
13891 struct window
*w
= XWINDOW (window
);
13893 if (WINDOWP (w
->contents
))
13894 redisplay_windows (w
->contents
);
13895 else if (BUFFERP (w
->contents
))
13897 displayed_buffer
= XBUFFER (w
->contents
);
13898 /* Use list_of_error, not Qerror, so that
13899 we catch only errors and don't run the debugger. */
13900 internal_condition_case_1 (redisplay_window_0
, window
,
13902 redisplay_window_error
);
13910 redisplay_window_error (Lisp_Object ignore
)
13912 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
13917 redisplay_window_0 (Lisp_Object window
)
13919 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
13920 redisplay_window (window
, 0);
13925 redisplay_window_1 (Lisp_Object window
)
13927 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
13928 redisplay_window (window
, 1);
13933 /* Set cursor position of W. PT is assumed to be displayed in ROW.
13934 DELTA and DELTA_BYTES are the numbers of characters and bytes by
13935 which positions recorded in ROW differ from current buffer
13938 Return 0 if cursor is not on this row, 1 otherwise. */
13941 set_cursor_from_row (struct window
*w
, struct glyph_row
*row
,
13942 struct glyph_matrix
*matrix
,
13943 ptrdiff_t delta
, ptrdiff_t delta_bytes
,
13946 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
13947 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
13948 struct glyph
*cursor
= NULL
;
13949 /* The last known character position in row. */
13950 ptrdiff_t last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13952 ptrdiff_t pt_old
= PT
- delta
;
13953 ptrdiff_t pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13954 ptrdiff_t pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
13955 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
13956 /* A glyph beyond the edge of TEXT_AREA which we should never
13958 struct glyph
*glyphs_end
= end
;
13959 /* Non-zero means we've found a match for cursor position, but that
13960 glyph has the avoid_cursor_p flag set. */
13961 int match_with_avoid_cursor
= 0;
13962 /* Non-zero means we've seen at least one glyph that came from a
13964 int string_seen
= 0;
13965 /* Largest and smallest buffer positions seen so far during scan of
13967 ptrdiff_t bpos_max
= pos_before
;
13968 ptrdiff_t bpos_min
= pos_after
;
13969 /* Last buffer position covered by an overlay string with an integer
13970 `cursor' property. */
13971 ptrdiff_t bpos_covered
= 0;
13972 /* Non-zero means the display string on which to display the cursor
13973 comes from a text property, not from an overlay. */
13974 int string_from_text_prop
= 0;
13976 /* Don't even try doing anything if called for a mode-line or
13977 header-line row, since the rest of the code isn't prepared to
13978 deal with such calamities. */
13979 eassert (!row
->mode_line_p
);
13980 if (row
->mode_line_p
)
13983 /* Skip over glyphs not having an object at the start and the end of
13984 the row. These are special glyphs like truncation marks on
13985 terminal frames. */
13986 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13988 if (!row
->reversed_p
)
13991 && INTEGERP (glyph
->object
)
13992 && glyph
->charpos
< 0)
13994 x
+= glyph
->pixel_width
;
13998 && INTEGERP ((end
- 1)->object
)
13999 /* CHARPOS is zero for blanks and stretch glyphs
14000 inserted by extend_face_to_end_of_line. */
14001 && (end
- 1)->charpos
<= 0)
14003 glyph_before
= glyph
- 1;
14010 /* If the glyph row is reversed, we need to process it from back
14011 to front, so swap the edge pointers. */
14012 glyphs_end
= end
= glyph
- 1;
14013 glyph
+= row
->used
[TEXT_AREA
] - 1;
14015 while (glyph
> end
+ 1
14016 && INTEGERP (glyph
->object
)
14017 && glyph
->charpos
< 0)
14020 x
-= glyph
->pixel_width
;
14022 if (INTEGERP (glyph
->object
) && glyph
->charpos
< 0)
14024 /* By default, in reversed rows we put the cursor on the
14025 rightmost (first in the reading order) glyph. */
14026 for (g
= end
+ 1; g
< glyph
; g
++)
14027 x
+= g
->pixel_width
;
14029 && INTEGERP ((end
+ 1)->object
)
14030 && (end
+ 1)->charpos
<= 0)
14032 glyph_before
= glyph
+ 1;
14036 else if (row
->reversed_p
)
14038 /* In R2L rows that don't display text, put the cursor on the
14039 rightmost glyph. Case in point: an empty last line that is
14040 part of an R2L paragraph. */
14042 /* Avoid placing the cursor on the last glyph of the row, where
14043 on terminal frames we hold the vertical border between
14044 adjacent windows. */
14045 if (!FRAME_WINDOW_P (WINDOW_XFRAME (w
))
14046 && !WINDOW_RIGHTMOST_P (w
)
14047 && cursor
== row
->glyphs
[LAST_AREA
] - 1)
14049 x
= -1; /* will be computed below, at label compute_x */
14052 /* Step 1: Try to find the glyph whose character position
14053 corresponds to point. If that's not possible, find 2 glyphs
14054 whose character positions are the closest to point, one before
14055 point, the other after it. */
14056 if (!row
->reversed_p
)
14057 while (/* not marched to end of glyph row */
14059 /* glyph was not inserted by redisplay for internal purposes */
14060 && !INTEGERP (glyph
->object
))
14062 if (BUFFERP (glyph
->object
))
14064 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
14066 if (glyph
->charpos
> bpos_max
)
14067 bpos_max
= glyph
->charpos
;
14068 if (glyph
->charpos
< bpos_min
)
14069 bpos_min
= glyph
->charpos
;
14070 if (!glyph
->avoid_cursor_p
)
14072 /* If we hit point, we've found the glyph on which to
14073 display the cursor. */
14076 match_with_avoid_cursor
= 0;
14079 /* See if we've found a better approximation to
14080 POS_BEFORE or to POS_AFTER. */
14081 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
14083 pos_before
= glyph
->charpos
;
14084 glyph_before
= glyph
;
14086 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
14088 pos_after
= glyph
->charpos
;
14089 glyph_after
= glyph
;
14092 else if (dpos
== 0)
14093 match_with_avoid_cursor
= 1;
14095 else if (STRINGP (glyph
->object
))
14097 Lisp_Object chprop
;
14098 ptrdiff_t glyph_pos
= glyph
->charpos
;
14100 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
14102 if (!NILP (chprop
))
14104 /* If the string came from a `display' text property,
14105 look up the buffer position of that property and
14106 use that position to update bpos_max, as if we
14107 actually saw such a position in one of the row's
14108 glyphs. This helps with supporting integer values
14109 of `cursor' property on the display string in
14110 situations where most or all of the row's buffer
14111 text is completely covered by display properties,
14112 so that no glyph with valid buffer positions is
14113 ever seen in the row. */
14114 ptrdiff_t prop_pos
=
14115 string_buffer_position_lim (glyph
->object
, pos_before
,
14118 if (prop_pos
>= pos_before
)
14119 bpos_max
= prop_pos
- 1;
14121 if (INTEGERP (chprop
))
14123 bpos_covered
= bpos_max
+ XINT (chprop
);
14124 /* If the `cursor' property covers buffer positions up
14125 to and including point, we should display cursor on
14126 this glyph. Note that, if a `cursor' property on one
14127 of the string's characters has an integer value, we
14128 will break out of the loop below _before_ we get to
14129 the position match above. IOW, integer values of
14130 the `cursor' property override the "exact match for
14131 point" strategy of positioning the cursor. */
14132 /* Implementation note: bpos_max == pt_old when, e.g.,
14133 we are in an empty line, where bpos_max is set to
14134 MATRIX_ROW_START_CHARPOS, see above. */
14135 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14144 x
+= glyph
->pixel_width
;
14147 else if (glyph
> end
) /* row is reversed */
14148 while (!INTEGERP (glyph
->object
))
14150 if (BUFFERP (glyph
->object
))
14152 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
14154 if (glyph
->charpos
> bpos_max
)
14155 bpos_max
= glyph
->charpos
;
14156 if (glyph
->charpos
< bpos_min
)
14157 bpos_min
= glyph
->charpos
;
14158 if (!glyph
->avoid_cursor_p
)
14162 match_with_avoid_cursor
= 0;
14165 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
14167 pos_before
= glyph
->charpos
;
14168 glyph_before
= glyph
;
14170 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
14172 pos_after
= glyph
->charpos
;
14173 glyph_after
= glyph
;
14176 else if (dpos
== 0)
14177 match_with_avoid_cursor
= 1;
14179 else if (STRINGP (glyph
->object
))
14181 Lisp_Object chprop
;
14182 ptrdiff_t glyph_pos
= glyph
->charpos
;
14184 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
14186 if (!NILP (chprop
))
14188 ptrdiff_t prop_pos
=
14189 string_buffer_position_lim (glyph
->object
, pos_before
,
14192 if (prop_pos
>= pos_before
)
14193 bpos_max
= prop_pos
- 1;
14195 if (INTEGERP (chprop
))
14197 bpos_covered
= bpos_max
+ XINT (chprop
);
14198 /* If the `cursor' property covers buffer positions up
14199 to and including point, we should display cursor on
14201 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14210 if (glyph
== glyphs_end
) /* don't dereference outside TEXT_AREA */
14212 x
--; /* can't use any pixel_width */
14215 x
-= glyph
->pixel_width
;
14218 /* Step 2: If we didn't find an exact match for point, we need to
14219 look for a proper place to put the cursor among glyphs between
14220 GLYPH_BEFORE and GLYPH_AFTER. */
14221 if (!((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14222 && BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14223 && !(bpos_max
< pt_old
&& pt_old
<= bpos_covered
))
14225 /* An empty line has a single glyph whose OBJECT is zero and
14226 whose CHARPOS is the position of a newline on that line.
14227 Note that on a TTY, there are more glyphs after that, which
14228 were produced by extend_face_to_end_of_line, but their
14229 CHARPOS is zero or negative. */
14231 (row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14232 && INTEGERP (glyph
->object
) && glyph
->charpos
> 0
14233 /* On a TTY, continued and truncated rows also have a glyph at
14234 their end whose OBJECT is zero and whose CHARPOS is
14235 positive (the continuation and truncation glyphs), but such
14236 rows are obviously not "empty". */
14237 && !(row
->continued_p
|| row
->truncated_on_right_p
);
14239 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
14241 ptrdiff_t ellipsis_pos
;
14243 /* Scan back over the ellipsis glyphs. */
14244 if (!row
->reversed_p
)
14246 ellipsis_pos
= (glyph
- 1)->charpos
;
14247 while (glyph
> row
->glyphs
[TEXT_AREA
]
14248 && (glyph
- 1)->charpos
== ellipsis_pos
)
14249 glyph
--, x
-= glyph
->pixel_width
;
14250 /* That loop always goes one position too far, including
14251 the glyph before the ellipsis. So scan forward over
14253 x
+= glyph
->pixel_width
;
14256 else /* row is reversed */
14258 ellipsis_pos
= (glyph
+ 1)->charpos
;
14259 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14260 && (glyph
+ 1)->charpos
== ellipsis_pos
)
14261 glyph
++, x
+= glyph
->pixel_width
;
14262 x
-= glyph
->pixel_width
;
14266 else if (match_with_avoid_cursor
)
14268 cursor
= glyph_after
;
14271 else if (string_seen
)
14273 int incr
= row
->reversed_p
? -1 : +1;
14275 /* Need to find the glyph that came out of a string which is
14276 present at point. That glyph is somewhere between
14277 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
14278 positioned between POS_BEFORE and POS_AFTER in the
14280 struct glyph
*start
, *stop
;
14281 ptrdiff_t pos
= pos_before
;
14285 /* If the row ends in a newline from a display string,
14286 reordering could have moved the glyphs belonging to the
14287 string out of the [GLYPH_BEFORE..GLYPH_AFTER] range. So
14288 in this case we extend the search to the last glyph in
14289 the row that was not inserted by redisplay. */
14290 if (row
->ends_in_newline_from_string_p
)
14293 pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
14296 /* GLYPH_BEFORE and GLYPH_AFTER are the glyphs that
14297 correspond to POS_BEFORE and POS_AFTER, respectively. We
14298 need START and STOP in the order that corresponds to the
14299 row's direction as given by its reversed_p flag. If the
14300 directionality of characters between POS_BEFORE and
14301 POS_AFTER is the opposite of the row's base direction,
14302 these characters will have been reordered for display,
14303 and we need to reverse START and STOP. */
14304 if (!row
->reversed_p
)
14306 start
= min (glyph_before
, glyph_after
);
14307 stop
= max (glyph_before
, glyph_after
);
14311 start
= max (glyph_before
, glyph_after
);
14312 stop
= min (glyph_before
, glyph_after
);
14314 for (glyph
= start
+ incr
;
14315 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
14318 /* Any glyphs that come from the buffer are here because
14319 of bidi reordering. Skip them, and only pay
14320 attention to glyphs that came from some string. */
14321 if (STRINGP (glyph
->object
))
14325 /* If the display property covers the newline, we
14326 need to search for it one position farther. */
14327 ptrdiff_t lim
= pos_after
14328 + (pos_after
== MATRIX_ROW_END_CHARPOS (row
) + delta
);
14330 string_from_text_prop
= 0;
14331 str
= glyph
->object
;
14332 tem
= string_buffer_position_lim (str
, pos
, lim
, 0);
14333 if (tem
== 0 /* from overlay */
14336 /* If the string from which this glyph came is
14337 found in the buffer at point, or at position
14338 that is closer to point than pos_after, then
14339 we've found the glyph we've been looking for.
14340 If it comes from an overlay (tem == 0), and
14341 it has the `cursor' property on one of its
14342 glyphs, record that glyph as a candidate for
14343 displaying the cursor. (As in the
14344 unidirectional version, we will display the
14345 cursor on the last candidate we find.) */
14348 || (tem
- pt_old
> 0 && tem
< pos_after
))
14350 /* The glyphs from this string could have
14351 been reordered. Find the one with the
14352 smallest string position. Or there could
14353 be a character in the string with the
14354 `cursor' property, which means display
14355 cursor on that character's glyph. */
14356 ptrdiff_t strpos
= glyph
->charpos
;
14361 string_from_text_prop
= 1;
14364 (row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14365 && EQ (glyph
->object
, str
);
14369 ptrdiff_t gpos
= glyph
->charpos
;
14371 cprop
= Fget_char_property (make_number (gpos
),
14379 if (tem
&& glyph
->charpos
< strpos
)
14381 strpos
= glyph
->charpos
;
14387 || (tem
- pt_old
> 0 && tem
< pos_after
))
14391 pos
= tem
+ 1; /* don't find previous instances */
14393 /* This string is not what we want; skip all of the
14394 glyphs that came from it. */
14395 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14396 && EQ (glyph
->object
, str
))
14403 /* If we reached the end of the line, and END was from a string,
14404 the cursor is not on this line. */
14406 && (row
->reversed_p
? glyph
<= end
: glyph
>= end
)
14407 && (row
->reversed_p
? end
> glyphs_end
: end
< glyphs_end
)
14408 && STRINGP (end
->object
)
14409 && row
->continued_p
)
14412 /* A truncated row may not include PT among its character positions.
14413 Setting the cursor inside the scroll margin will trigger
14414 recalculation of hscroll in hscroll_window_tree. But if a
14415 display string covers point, defer to the string-handling
14416 code below to figure this out. */
14417 else if (row
->truncated_on_left_p
&& pt_old
< bpos_min
)
14419 cursor
= glyph_before
;
14422 else if ((row
->truncated_on_right_p
&& pt_old
> bpos_max
)
14423 /* Zero-width characters produce no glyphs. */
14425 && (row
->reversed_p
14426 ? glyph_after
> glyphs_end
14427 : glyph_after
< glyphs_end
)))
14429 cursor
= glyph_after
;
14435 if (cursor
!= NULL
)
14437 else if (glyph
== glyphs_end
14438 && pos_before
== pos_after
14439 && STRINGP ((row
->reversed_p
14440 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14441 : row
->glyphs
[TEXT_AREA
])->object
))
14443 /* If all the glyphs of this row came from strings, put the
14444 cursor on the first glyph of the row. This avoids having the
14445 cursor outside of the text area in this very rare and hard
14449 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14450 : row
->glyphs
[TEXT_AREA
];
14456 /* Need to compute x that corresponds to GLYPH. */
14457 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
14459 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
14461 x
+= g
->pixel_width
;
14465 /* ROW could be part of a continued line, which, under bidi
14466 reordering, might have other rows whose start and end charpos
14467 occlude point. Only set w->cursor if we found a better
14468 approximation to the cursor position than we have from previously
14469 examined candidate rows belonging to the same continued line. */
14470 if (/* we already have a candidate row */
14471 w
->cursor
.vpos
>= 0
14472 /* that candidate is not the row we are processing */
14473 && MATRIX_ROW (matrix
, w
->cursor
.vpos
) != row
14474 /* Make sure cursor.vpos specifies a row whose start and end
14475 charpos occlude point, and it is valid candidate for being a
14476 cursor-row. This is because some callers of this function
14477 leave cursor.vpos at the row where the cursor was displayed
14478 during the last redisplay cycle. */
14479 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)) <= pt_old
14480 && pt_old
<= MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14481 && cursor_row_p (MATRIX_ROW (matrix
, w
->cursor
.vpos
)))
14484 MATRIX_ROW_GLYPH_START (matrix
, w
->cursor
.vpos
) + w
->cursor
.hpos
;
14486 /* Don't consider glyphs that are outside TEXT_AREA. */
14487 if (!(row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
))
14489 /* Keep the candidate whose buffer position is the closest to
14490 point or has the `cursor' property. */
14491 if (/* previous candidate is a glyph in TEXT_AREA of that row */
14492 w
->cursor
.hpos
>= 0
14493 && w
->cursor
.hpos
< MATRIX_ROW_USED (matrix
, w
->cursor
.vpos
)
14494 && ((BUFFERP (g1
->object
)
14495 && (g1
->charpos
== pt_old
/* an exact match always wins */
14496 || (BUFFERP (glyph
->object
)
14497 && eabs (g1
->charpos
- pt_old
)
14498 < eabs (glyph
->charpos
- pt_old
))))
14499 /* previous candidate is a glyph from a string that has
14500 a non-nil `cursor' property */
14501 || (STRINGP (g1
->object
)
14502 && (!NILP (Fget_char_property (make_number (g1
->charpos
),
14503 Qcursor
, g1
->object
))
14504 /* previous candidate is from the same display
14505 string as this one, and the display string
14506 came from a text property */
14507 || (EQ (g1
->object
, glyph
->object
)
14508 && string_from_text_prop
)
14509 /* this candidate is from newline and its
14510 position is not an exact match */
14511 || (INTEGERP (glyph
->object
)
14512 && glyph
->charpos
!= pt_old
)))))
14514 /* If this candidate gives an exact match, use that. */
14515 if (!((BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14516 /* If this candidate is a glyph created for the
14517 terminating newline of a line, and point is on that
14518 newline, it wins because it's an exact match. */
14519 || (!row
->continued_p
14520 && INTEGERP (glyph
->object
)
14521 && glyph
->charpos
== 0
14522 && pt_old
== MATRIX_ROW_END_CHARPOS (row
) - 1))
14523 /* Otherwise, keep the candidate that comes from a row
14524 spanning less buffer positions. This may win when one or
14525 both candidate positions are on glyphs that came from
14526 display strings, for which we cannot compare buffer
14528 && MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14529 - MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14530 < MATRIX_ROW_END_CHARPOS (row
) - MATRIX_ROW_START_CHARPOS (row
))
14533 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
14535 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
14536 w
->cursor
.y
= row
->y
+ dy
;
14538 if (w
== XWINDOW (selected_window
))
14540 if (!row
->continued_p
14541 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
14544 this_line_buffer
= XBUFFER (w
->contents
);
14546 CHARPOS (this_line_start_pos
)
14547 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
14548 BYTEPOS (this_line_start_pos
)
14549 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
14551 CHARPOS (this_line_end_pos
)
14552 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
14553 BYTEPOS (this_line_end_pos
)
14554 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
14556 this_line_y
= w
->cursor
.y
;
14557 this_line_pixel_height
= row
->height
;
14558 this_line_vpos
= w
->cursor
.vpos
;
14559 this_line_start_x
= row
->x
;
14562 CHARPOS (this_line_start_pos
) = 0;
14569 /* Run window scroll functions, if any, for WINDOW with new window
14570 start STARTP. Sets the window start of WINDOW to that position.
14572 We assume that the window's buffer is really current. */
14574 static struct text_pos
14575 run_window_scroll_functions (Lisp_Object window
, struct text_pos startp
)
14577 struct window
*w
= XWINDOW (window
);
14578 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
14580 eassert (current_buffer
== XBUFFER (w
->contents
));
14582 if (!NILP (Vwindow_scroll_functions
))
14584 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
14585 make_number (CHARPOS (startp
)));
14586 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14587 /* In case the hook functions switch buffers. */
14588 set_buffer_internal (XBUFFER (w
->contents
));
14595 /* Make sure the line containing the cursor is fully visible.
14596 A value of 1 means there is nothing to be done.
14597 (Either the line is fully visible, or it cannot be made so,
14598 or we cannot tell.)
14600 If FORCE_P is non-zero, return 0 even if partial visible cursor row
14601 is higher than window.
14603 A value of 0 means the caller should do scrolling
14604 as if point had gone off the screen. */
14607 cursor_row_fully_visible_p (struct window
*w
, int force_p
, int current_matrix_p
)
14609 struct glyph_matrix
*matrix
;
14610 struct glyph_row
*row
;
14613 if (!make_cursor_line_fully_visible_p
)
14616 /* It's not always possible to find the cursor, e.g, when a window
14617 is full of overlay strings. Don't do anything in that case. */
14618 if (w
->cursor
.vpos
< 0)
14621 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
14622 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
14624 /* If the cursor row is not partially visible, there's nothing to do. */
14625 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
14628 /* If the row the cursor is in is taller than the window's height,
14629 it's not clear what to do, so do nothing. */
14630 window_height
= window_box_height (w
);
14631 if (row
->height
>= window_height
)
14633 if (!force_p
|| MINI_WINDOW_P (w
)
14634 || w
->vscroll
|| w
->cursor
.vpos
== 0)
14641 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
14642 non-zero means only WINDOW is redisplayed in redisplay_internal.
14643 TEMP_SCROLL_STEP has the same meaning as emacs_scroll_step, and is used
14644 in redisplay_window to bring a partially visible line into view in
14645 the case that only the cursor has moved.
14647 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
14648 last screen line's vertical height extends past the end of the screen.
14652 1 if scrolling succeeded
14654 0 if scrolling didn't find point.
14656 -1 if new fonts have been loaded so that we must interrupt
14657 redisplay, adjust glyph matrices, and try again. */
14663 SCROLLING_NEED_LARGER_MATRICES
14666 /* If scroll-conservatively is more than this, never recenter.
14668 If you change this, don't forget to update the doc string of
14669 `scroll-conservatively' and the Emacs manual. */
14670 #define SCROLL_LIMIT 100
14673 try_scrolling (Lisp_Object window
, int just_this_one_p
,
14674 ptrdiff_t arg_scroll_conservatively
, ptrdiff_t scroll_step
,
14675 int temp_scroll_step
, int last_line_misfit
)
14677 struct window
*w
= XWINDOW (window
);
14678 struct frame
*f
= XFRAME (w
->frame
);
14679 struct text_pos pos
, startp
;
14681 int this_scroll_margin
, scroll_max
, rc
, height
;
14682 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
14683 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
14684 Lisp_Object aggressive
;
14685 /* We will never try scrolling more than this number of lines. */
14686 int scroll_limit
= SCROLL_LIMIT
;
14687 int frame_line_height
= default_line_pixel_height (w
);
14688 int window_total_lines
14689 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
14692 debug_method_add (w
, "try_scrolling");
14695 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14697 /* Compute scroll margin height in pixels. We scroll when point is
14698 within this distance from the top or bottom of the window. */
14699 if (scroll_margin
> 0)
14700 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4)
14701 * frame_line_height
;
14703 this_scroll_margin
= 0;
14705 /* Force arg_scroll_conservatively to have a reasonable value, to
14706 avoid scrolling too far away with slow move_it_* functions. Note
14707 that the user can supply scroll-conservatively equal to
14708 `most-positive-fixnum', which can be larger than INT_MAX. */
14709 if (arg_scroll_conservatively
> scroll_limit
)
14711 arg_scroll_conservatively
= scroll_limit
+ 1;
14712 scroll_max
= scroll_limit
* frame_line_height
;
14714 else if (scroll_step
|| arg_scroll_conservatively
|| temp_scroll_step
)
14715 /* Compute how much we should try to scroll maximally to bring
14716 point into view. */
14717 scroll_max
= (max (scroll_step
,
14718 max (arg_scroll_conservatively
, temp_scroll_step
))
14719 * frame_line_height
);
14720 else if (NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
))
14721 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
)))
14722 /* We're trying to scroll because of aggressive scrolling but no
14723 scroll_step is set. Choose an arbitrary one. */
14724 scroll_max
= 10 * frame_line_height
;
14730 /* Decide whether to scroll down. */
14731 if (PT
> CHARPOS (startp
))
14733 int scroll_margin_y
;
14735 /* Compute the pixel ypos of the scroll margin, then move IT to
14736 either that ypos or PT, whichever comes first. */
14737 start_display (&it
, w
, startp
);
14738 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
14739 - frame_line_height
* extra_scroll_margin_lines
;
14740 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
14741 (MOVE_TO_POS
| MOVE_TO_Y
));
14743 if (PT
> CHARPOS (it
.current
.pos
))
14745 int y0
= line_bottom_y (&it
);
14746 /* Compute how many pixels below window bottom to stop searching
14747 for PT. This avoids costly search for PT that is far away if
14748 the user limited scrolling by a small number of lines, but
14749 always finds PT if scroll_conservatively is set to a large
14750 number, such as most-positive-fixnum. */
14751 int slack
= max (scroll_max
, 10 * frame_line_height
);
14752 int y_to_move
= it
.last_visible_y
+ slack
;
14754 /* Compute the distance from the scroll margin to PT or to
14755 the scroll limit, whichever comes first. This should
14756 include the height of the cursor line, to make that line
14758 move_it_to (&it
, PT
, -1, y_to_move
,
14759 -1, MOVE_TO_POS
| MOVE_TO_Y
);
14760 dy
= line_bottom_y (&it
) - y0
;
14762 if (dy
> scroll_max
)
14763 return SCROLLING_FAILED
;
14772 /* Point is in or below the bottom scroll margin, so move the
14773 window start down. If scrolling conservatively, move it just
14774 enough down to make point visible. If scroll_step is set,
14775 move it down by scroll_step. */
14776 if (arg_scroll_conservatively
)
14778 = min (max (dy
, frame_line_height
),
14779 frame_line_height
* arg_scroll_conservatively
);
14780 else if (scroll_step
|| temp_scroll_step
)
14781 amount_to_scroll
= scroll_max
;
14784 aggressive
= BVAR (current_buffer
, scroll_up_aggressively
);
14785 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14786 if (NUMBERP (aggressive
))
14788 double float_amount
= XFLOATINT (aggressive
) * height
;
14789 int aggressive_scroll
= float_amount
;
14790 if (aggressive_scroll
== 0 && float_amount
> 0)
14791 aggressive_scroll
= 1;
14792 /* Don't let point enter the scroll margin near top of
14793 the window. This could happen if the value of
14794 scroll_up_aggressively is too large and there are
14795 non-zero margins, because scroll_up_aggressively
14796 means put point that fraction of window height
14797 _from_the_bottom_margin_. */
14798 if (aggressive_scroll
+ 2*this_scroll_margin
> height
)
14799 aggressive_scroll
= height
- 2*this_scroll_margin
;
14800 amount_to_scroll
= dy
+ aggressive_scroll
;
14804 if (amount_to_scroll
<= 0)
14805 return SCROLLING_FAILED
;
14807 start_display (&it
, w
, startp
);
14808 if (arg_scroll_conservatively
<= scroll_limit
)
14809 move_it_vertically (&it
, amount_to_scroll
);
14812 /* Extra precision for users who set scroll-conservatively
14813 to a large number: make sure the amount we scroll
14814 the window start is never less than amount_to_scroll,
14815 which was computed as distance from window bottom to
14816 point. This matters when lines at window top and lines
14817 below window bottom have different height. */
14819 void *it1data
= NULL
;
14820 /* We use a temporary it1 because line_bottom_y can modify
14821 its argument, if it moves one line down; see there. */
14824 SAVE_IT (it1
, it
, it1data
);
14825 start_y
= line_bottom_y (&it1
);
14827 RESTORE_IT (&it
, &it
, it1data
);
14828 move_it_by_lines (&it
, 1);
14829 SAVE_IT (it1
, it
, it1data
);
14830 } while (line_bottom_y (&it1
) - start_y
< amount_to_scroll
);
14833 /* If STARTP is unchanged, move it down another screen line. */
14834 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
14835 move_it_by_lines (&it
, 1);
14836 startp
= it
.current
.pos
;
14840 struct text_pos scroll_margin_pos
= startp
;
14843 /* See if point is inside the scroll margin at the top of the
14845 if (this_scroll_margin
)
14849 start_display (&it
, w
, startp
);
14850 y_start
= it
.current_y
;
14851 move_it_vertically (&it
, this_scroll_margin
);
14852 scroll_margin_pos
= it
.current
.pos
;
14853 /* If we didn't move enough before hitting ZV, request
14854 additional amount of scroll, to move point out of the
14856 if (IT_CHARPOS (it
) == ZV
14857 && it
.current_y
- y_start
< this_scroll_margin
)
14858 y_offset
= this_scroll_margin
- (it
.current_y
- y_start
);
14861 if (PT
< CHARPOS (scroll_margin_pos
))
14863 /* Point is in the scroll margin at the top of the window or
14864 above what is displayed in the window. */
14867 /* Compute the vertical distance from PT to the scroll
14868 margin position. Move as far as scroll_max allows, or
14869 one screenful, or 10 screen lines, whichever is largest.
14870 Give up if distance is greater than scroll_max or if we
14871 didn't reach the scroll margin position. */
14872 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
14873 start_display (&it
, w
, pos
);
14875 y_to_move
= max (it
.last_visible_y
,
14876 max (scroll_max
, 10 * frame_line_height
));
14877 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
14879 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
14880 dy
= it
.current_y
- y0
;
14881 if (dy
> scroll_max
14882 || IT_CHARPOS (it
) < CHARPOS (scroll_margin_pos
))
14883 return SCROLLING_FAILED
;
14885 /* Additional scroll for when ZV was too close to point. */
14888 /* Compute new window start. */
14889 start_display (&it
, w
, startp
);
14891 if (arg_scroll_conservatively
)
14892 amount_to_scroll
= max (dy
, frame_line_height
*
14893 max (scroll_step
, temp_scroll_step
));
14894 else if (scroll_step
|| temp_scroll_step
)
14895 amount_to_scroll
= scroll_max
;
14898 aggressive
= BVAR (current_buffer
, scroll_down_aggressively
);
14899 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14900 if (NUMBERP (aggressive
))
14902 double float_amount
= XFLOATINT (aggressive
) * height
;
14903 int aggressive_scroll
= float_amount
;
14904 if (aggressive_scroll
== 0 && float_amount
> 0)
14905 aggressive_scroll
= 1;
14906 /* Don't let point enter the scroll margin near
14907 bottom of the window, if the value of
14908 scroll_down_aggressively happens to be too
14910 if (aggressive_scroll
+ 2*this_scroll_margin
> height
)
14911 aggressive_scroll
= height
- 2*this_scroll_margin
;
14912 amount_to_scroll
= dy
+ aggressive_scroll
;
14916 if (amount_to_scroll
<= 0)
14917 return SCROLLING_FAILED
;
14919 move_it_vertically_backward (&it
, amount_to_scroll
);
14920 startp
= it
.current
.pos
;
14924 /* Run window scroll functions. */
14925 startp
= run_window_scroll_functions (window
, startp
);
14927 /* Display the window. Give up if new fonts are loaded, or if point
14929 if (!try_window (window
, startp
, 0))
14930 rc
= SCROLLING_NEED_LARGER_MATRICES
;
14931 else if (w
->cursor
.vpos
< 0)
14933 clear_glyph_matrix (w
->desired_matrix
);
14934 rc
= SCROLLING_FAILED
;
14938 /* Maybe forget recorded base line for line number display. */
14939 if (!just_this_one_p
14940 || current_buffer
->clip_changed
14941 || BEG_UNCHANGED
< CHARPOS (startp
))
14942 w
->base_line_number
= 0;
14944 /* If cursor ends up on a partially visible line,
14945 treat that as being off the bottom of the screen. */
14946 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0)
14947 /* It's possible that the cursor is on the first line of the
14948 buffer, which is partially obscured due to a vscroll
14949 (Bug#7537). In that case, avoid looping forever . */
14950 && extra_scroll_margin_lines
< w
->desired_matrix
->nrows
- 1)
14952 clear_glyph_matrix (w
->desired_matrix
);
14953 ++extra_scroll_margin_lines
;
14956 rc
= SCROLLING_SUCCESS
;
14963 /* Compute a suitable window start for window W if display of W starts
14964 on a continuation line. Value is non-zero if a new window start
14967 The new window start will be computed, based on W's width, starting
14968 from the start of the continued line. It is the start of the
14969 screen line with the minimum distance from the old start W->start. */
14972 compute_window_start_on_continuation_line (struct window
*w
)
14974 struct text_pos pos
, start_pos
;
14975 int window_start_changed_p
= 0;
14977 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
14979 /* If window start is on a continuation line... Window start may be
14980 < BEGV in case there's invisible text at the start of the
14981 buffer (M-x rmail, for example). */
14982 if (CHARPOS (start_pos
) > BEGV
14983 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
14986 struct glyph_row
*row
;
14988 /* Handle the case that the window start is out of range. */
14989 if (CHARPOS (start_pos
) < BEGV
)
14990 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
14991 else if (CHARPOS (start_pos
) > ZV
)
14992 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
14994 /* Find the start of the continued line. This should be fast
14995 because find_newline is fast (newline cache). */
14996 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
14997 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
14998 row
, DEFAULT_FACE_ID
);
14999 reseat_at_previous_visible_line_start (&it
);
15001 /* If the line start is "too far" away from the window start,
15002 say it takes too much time to compute a new window start. */
15003 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
15004 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
15006 int min_distance
, distance
;
15008 /* Move forward by display lines to find the new window
15009 start. If window width was enlarged, the new start can
15010 be expected to be > the old start. If window width was
15011 decreased, the new window start will be < the old start.
15012 So, we're looking for the display line start with the
15013 minimum distance from the old window start. */
15014 pos
= it
.current
.pos
;
15015 min_distance
= INFINITY
;
15016 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
15017 distance
< min_distance
)
15019 min_distance
= distance
;
15020 pos
= it
.current
.pos
;
15021 if (it
.line_wrap
== WORD_WRAP
)
15023 /* Under WORD_WRAP, move_it_by_lines is likely to
15024 overshoot and stop not at the first, but the
15025 second character from the left margin. So in
15026 that case, we need a more tight control on the X
15027 coordinate of the iterator than move_it_by_lines
15028 promises in its contract. The method is to first
15029 go to the last (rightmost) visible character of a
15030 line, then move to the leftmost character on the
15031 next line in a separate call. */
15032 move_it_to (&it
, ZV
, it
.last_visible_x
, it
.current_y
, -1,
15033 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15034 move_it_to (&it
, ZV
, 0,
15035 it
.current_y
+ it
.max_ascent
+ it
.max_descent
, -1,
15036 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15039 move_it_by_lines (&it
, 1);
15042 /* Set the window start there. */
15043 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
15044 window_start_changed_p
= 1;
15048 return window_start_changed_p
;
15052 /* Try cursor movement in case text has not changed in window WINDOW,
15053 with window start STARTP. Value is
15055 CURSOR_MOVEMENT_SUCCESS if successful
15057 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
15059 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
15060 display. *SCROLL_STEP is set to 1, under certain circumstances, if
15061 we want to scroll as if scroll-step were set to 1. See the code.
15063 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
15064 which case we have to abort this redisplay, and adjust matrices
15069 CURSOR_MOVEMENT_SUCCESS
,
15070 CURSOR_MOVEMENT_CANNOT_BE_USED
,
15071 CURSOR_MOVEMENT_MUST_SCROLL
,
15072 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
15076 try_cursor_movement (Lisp_Object window
, struct text_pos startp
, int *scroll_step
)
15078 struct window
*w
= XWINDOW (window
);
15079 struct frame
*f
= XFRAME (w
->frame
);
15080 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
15083 if (inhibit_try_cursor_movement
)
15087 /* Previously, there was a check for Lisp integer in the
15088 if-statement below. Now, this field is converted to
15089 ptrdiff_t, thus zero means invalid position in a buffer. */
15090 eassert (w
->last_point
> 0);
15091 /* Likewise there was a check whether window_end_vpos is nil or larger
15092 than the window. Now window_end_vpos is int and so never nil, but
15093 let's leave eassert to check whether it fits in the window. */
15094 eassert (w
->window_end_vpos
< w
->current_matrix
->nrows
);
15096 /* Handle case where text has not changed, only point, and it has
15097 not moved off the frame. */
15098 if (/* Point may be in this window. */
15099 PT
>= CHARPOS (startp
)
15100 /* Selective display hasn't changed. */
15101 && !current_buffer
->clip_changed
15102 /* Function force-mode-line-update is used to force a thorough
15103 redisplay. It sets either windows_or_buffers_changed or
15104 update_mode_lines. So don't take a shortcut here for these
15106 && !update_mode_lines
15107 && !windows_or_buffers_changed
15108 && !cursor_type_changed
15109 /* Can't use this case if highlighting a region. When a
15110 region exists, cursor movement has to do more than just
15112 && markpos_of_region () < 0
15113 && !w
->region_showing
15114 && NILP (Vshow_trailing_whitespace
)
15115 /* This code is not used for mini-buffer for the sake of the case
15116 of redisplaying to replace an echo area message; since in
15117 that case the mini-buffer contents per se are usually
15118 unchanged. This code is of no real use in the mini-buffer
15119 since the handling of this_line_start_pos, etc., in redisplay
15120 handles the same cases. */
15121 && !EQ (window
, minibuf_window
)
15122 && (FRAME_WINDOW_P (f
)
15123 || !overlay_arrow_in_current_buffer_p ()))
15125 int this_scroll_margin
, top_scroll_margin
;
15126 struct glyph_row
*row
= NULL
;
15127 int frame_line_height
= default_line_pixel_height (w
);
15128 int window_total_lines
15129 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
15132 debug_method_add (w
, "cursor movement");
15135 /* Scroll if point within this distance from the top or bottom
15136 of the window. This is a pixel value. */
15137 if (scroll_margin
> 0)
15139 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4);
15140 this_scroll_margin
*= frame_line_height
;
15143 this_scroll_margin
= 0;
15145 top_scroll_margin
= this_scroll_margin
;
15146 if (WINDOW_WANTS_HEADER_LINE_P (w
))
15147 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
15149 /* Start with the row the cursor was displayed during the last
15150 not paused redisplay. Give up if that row is not valid. */
15151 if (w
->last_cursor_vpos
< 0
15152 || w
->last_cursor_vpos
>= w
->current_matrix
->nrows
)
15153 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15156 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor_vpos
);
15157 if (row
->mode_line_p
)
15159 if (!row
->enabled_p
)
15160 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15163 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
15165 int scroll_p
= 0, must_scroll
= 0;
15166 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
15168 if (PT
> w
->last_point
)
15170 /* Point has moved forward. */
15171 while (MATRIX_ROW_END_CHARPOS (row
) < PT
15172 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
15174 eassert (row
->enabled_p
);
15178 /* If the end position of a row equals the start
15179 position of the next row, and PT is at that position,
15180 we would rather display cursor in the next line. */
15181 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15182 && MATRIX_ROW_END_CHARPOS (row
) == PT
15183 && row
< MATRIX_MODE_LINE_ROW (w
->current_matrix
)
15184 && MATRIX_ROW_START_CHARPOS (row
+1) == PT
15185 && !cursor_row_p (row
))
15188 /* If within the scroll margin, scroll. Note that
15189 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
15190 the next line would be drawn, and that
15191 this_scroll_margin can be zero. */
15192 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
15193 || PT
> MATRIX_ROW_END_CHARPOS (row
)
15194 /* Line is completely visible last line in window
15195 and PT is to be set in the next line. */
15196 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
15197 && PT
== MATRIX_ROW_END_CHARPOS (row
)
15198 && !row
->ends_at_zv_p
15199 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
15202 else if (PT
< w
->last_point
)
15204 /* Cursor has to be moved backward. Note that PT >=
15205 CHARPOS (startp) because of the outer if-statement. */
15206 while (!row
->mode_line_p
15207 && (MATRIX_ROW_START_CHARPOS (row
) > PT
15208 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15209 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
15210 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
15211 row
> w
->current_matrix
->rows
15212 && (row
-1)->ends_in_newline_from_string_p
))))
15213 && (row
->y
> top_scroll_margin
15214 || CHARPOS (startp
) == BEGV
))
15216 eassert (row
->enabled_p
);
15220 /* Consider the following case: Window starts at BEGV,
15221 there is invisible, intangible text at BEGV, so that
15222 display starts at some point START > BEGV. It can
15223 happen that we are called with PT somewhere between
15224 BEGV and START. Try to handle that case. */
15225 if (row
< w
->current_matrix
->rows
15226 || row
->mode_line_p
)
15228 row
= w
->current_matrix
->rows
;
15229 if (row
->mode_line_p
)
15233 /* Due to newlines in overlay strings, we may have to
15234 skip forward over overlay strings. */
15235 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15236 && MATRIX_ROW_END_CHARPOS (row
) == PT
15237 && !cursor_row_p (row
))
15240 /* If within the scroll margin, scroll. */
15241 if (row
->y
< top_scroll_margin
15242 && CHARPOS (startp
) != BEGV
)
15247 /* Cursor did not move. So don't scroll even if cursor line
15248 is partially visible, as it was so before. */
15249 rc
= CURSOR_MOVEMENT_SUCCESS
;
15252 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
15253 || PT
> MATRIX_ROW_END_CHARPOS (row
))
15255 /* if PT is not in the glyph row, give up. */
15256 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15259 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15260 && !NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
15262 struct glyph_row
*row1
;
15264 /* If rows are bidi-reordered and point moved, back up
15265 until we find a row that does not belong to a
15266 continuation line. This is because we must consider
15267 all rows of a continued line as candidates for the
15268 new cursor positioning, since row start and end
15269 positions change non-linearly with vertical position
15271 /* FIXME: Revisit this when glyph ``spilling'' in
15272 continuation lines' rows is implemented for
15273 bidi-reordered rows. */
15274 for (row1
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15275 MATRIX_ROW_CONTINUATION_LINE_P (row
);
15278 /* If we hit the beginning of the displayed portion
15279 without finding the first row of a continued
15283 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15286 eassert (row
->enabled_p
);
15291 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15292 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
15293 /* Make sure this isn't a header line by any chance, since
15294 then MATRIX_ROW_PARTIALLY_VISIBLE_P might yield non-zero. */
15295 && !row
->mode_line_p
15296 && make_cursor_line_fully_visible_p
)
15298 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
15299 && !row
->ends_at_zv_p
15300 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15301 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15302 else if (row
->height
> window_box_height (w
))
15304 /* If we end up in a partially visible line, let's
15305 make it fully visible, except when it's taller
15306 than the window, in which case we can't do much
15309 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15313 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15314 if (!cursor_row_fully_visible_p (w
, 0, 1))
15315 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15317 rc
= CURSOR_MOVEMENT_SUCCESS
;
15321 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15322 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15323 && !NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
15325 /* With bidi-reordered rows, there could be more than
15326 one candidate row whose start and end positions
15327 occlude point. We need to let set_cursor_from_row
15328 find the best candidate. */
15329 /* FIXME: Revisit this when glyph ``spilling'' in
15330 continuation lines' rows is implemented for
15331 bidi-reordered rows. */
15336 int at_zv_p
= 0, exact_match_p
= 0;
15338 if (MATRIX_ROW_START_CHARPOS (row
) <= PT
15339 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
15340 && cursor_row_p (row
))
15341 rv
|= set_cursor_from_row (w
, row
, w
->current_matrix
,
15343 /* As soon as we've found the exact match for point,
15344 or the first suitable row whose ends_at_zv_p flag
15345 is set, we are done. */
15347 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
)->ends_at_zv_p
;
15349 && w
->cursor
.hpos
>= 0
15350 && w
->cursor
.hpos
< MATRIX_ROW_USED (w
->current_matrix
,
15353 struct glyph_row
*candidate
=
15354 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
15356 candidate
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
15357 ptrdiff_t endpos
= MATRIX_ROW_END_CHARPOS (candidate
);
15360 (BUFFERP (g
->object
) && g
->charpos
== PT
)
15361 || (INTEGERP (g
->object
)
15362 && (g
->charpos
== PT
15363 || (g
->charpos
== 0 && endpos
- 1 == PT
)));
15365 if (rv
&& (at_zv_p
|| exact_match_p
))
15367 rc
= CURSOR_MOVEMENT_SUCCESS
;
15370 if (MATRIX_ROW_BOTTOM_Y (row
) == last_y
)
15374 while (((MATRIX_ROW_CONTINUATION_LINE_P (row
)
15375 || row
->continued_p
)
15376 && MATRIX_ROW_BOTTOM_Y (row
) <= last_y
)
15377 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15378 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
));
15379 /* If we didn't find any candidate rows, or exited the
15380 loop before all the candidates were examined, signal
15381 to the caller that this method failed. */
15382 if (rc
!= CURSOR_MOVEMENT_SUCCESS
15384 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
15385 && !row
->continued_p
))
15386 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15388 rc
= CURSOR_MOVEMENT_SUCCESS
;
15394 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
15396 rc
= CURSOR_MOVEMENT_SUCCESS
;
15401 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15402 && MATRIX_ROW_START_CHARPOS (row
) == PT
15403 && cursor_row_p (row
));
15411 #if !defined USE_TOOLKIT_SCROLL_BARS || defined USE_GTK
15415 set_vertical_scroll_bar (struct window
*w
)
15417 ptrdiff_t start
, end
, whole
;
15419 /* Calculate the start and end positions for the current window.
15420 At some point, it would be nice to choose between scrollbars
15421 which reflect the whole buffer size, with special markers
15422 indicating narrowing, and scrollbars which reflect only the
15425 Note that mini-buffers sometimes aren't displaying any text. */
15426 if (!MINI_WINDOW_P (w
)
15427 || (w
== XWINDOW (minibuf_window
)
15428 && NILP (echo_area_buffer
[0])))
15430 struct buffer
*buf
= XBUFFER (w
->contents
);
15431 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
15432 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
15433 /* I don't think this is guaranteed to be right. For the
15434 moment, we'll pretend it is. */
15435 end
= BUF_Z (buf
) - w
->window_end_pos
- BUF_BEGV (buf
);
15439 if (whole
< (end
- start
))
15440 whole
= end
- start
;
15443 start
= end
= whole
= 0;
15445 /* Indicate what this scroll bar ought to be displaying now. */
15446 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15447 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15448 (w
, end
- start
, whole
, start
);
15452 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
15453 selected_window is redisplayed.
15455 We can return without actually redisplaying the window if
15456 fonts_changed_p. In that case, redisplay_internal will
15460 redisplay_window (Lisp_Object window
, int just_this_one_p
)
15462 struct window
*w
= XWINDOW (window
);
15463 struct frame
*f
= XFRAME (w
->frame
);
15464 struct buffer
*buffer
= XBUFFER (w
->contents
);
15465 struct buffer
*old
= current_buffer
;
15466 struct text_pos lpoint
, opoint
, startp
;
15467 int update_mode_line
;
15470 /* Record it now because it's overwritten. */
15471 int current_matrix_up_to_date_p
= 0;
15472 int used_current_matrix_p
= 0;
15473 /* This is less strict than current_matrix_up_to_date_p.
15474 It indicates that the buffer contents and narrowing are unchanged. */
15475 int buffer_unchanged_p
= 0;
15476 int temp_scroll_step
= 0;
15477 ptrdiff_t count
= SPECPDL_INDEX ();
15479 int centering_position
= -1;
15480 int last_line_misfit
= 0;
15481 ptrdiff_t beg_unchanged
, end_unchanged
;
15482 int frame_line_height
;
15484 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15488 *w
->desired_matrix
->method
= 0;
15491 /* Make sure that both W's markers are valid. */
15492 eassert (XMARKER (w
->start
)->buffer
== buffer
);
15493 eassert (XMARKER (w
->pointm
)->buffer
== buffer
);
15496 reconsider_clip_changes (w
);
15497 frame_line_height
= default_line_pixel_height (w
);
15499 /* Has the mode line to be updated? */
15500 update_mode_line
= (w
->update_mode_line
15501 || update_mode_lines
15502 || buffer
->clip_changed
15503 || buffer
->prevent_redisplay_optimizations_p
);
15505 if (MINI_WINDOW_P (w
))
15507 if (w
== XWINDOW (echo_area_window
)
15508 && !NILP (echo_area_buffer
[0]))
15510 if (update_mode_line
)
15511 /* We may have to update a tty frame's menu bar or a
15512 tool-bar. Example `M-x C-h C-h C-g'. */
15513 goto finish_menu_bars
;
15515 /* We've already displayed the echo area glyphs in this window. */
15516 goto finish_scroll_bars
;
15518 else if ((w
!= XWINDOW (minibuf_window
)
15519 || minibuf_level
== 0)
15520 /* When buffer is nonempty, redisplay window normally. */
15521 && BUF_Z (XBUFFER (w
->contents
)) == BUF_BEG (XBUFFER (w
->contents
))
15522 /* Quail displays non-mini buffers in minibuffer window.
15523 In that case, redisplay the window normally. */
15524 && !NILP (Fmemq (w
->contents
, Vminibuffer_list
)))
15526 /* W is a mini-buffer window, but it's not active, so clear
15528 int yb
= window_text_bottom_y (w
);
15529 struct glyph_row
*row
;
15532 for (y
= 0, row
= w
->desired_matrix
->rows
;
15534 y
+= row
->height
, ++row
)
15535 blank_row (w
, row
, y
);
15536 goto finish_scroll_bars
;
15539 clear_glyph_matrix (w
->desired_matrix
);
15542 /* Otherwise set up data on this window; select its buffer and point
15544 /* Really select the buffer, for the sake of buffer-local
15546 set_buffer_internal_1 (XBUFFER (w
->contents
));
15548 current_matrix_up_to_date_p
15549 = (w
->window_end_valid
15550 && !current_buffer
->clip_changed
15551 && !current_buffer
->prevent_redisplay_optimizations_p
15552 && !window_outdated (w
));
15554 /* Run the window-bottom-change-functions
15555 if it is possible that the text on the screen has changed
15556 (either due to modification of the text, or any other reason). */
15557 if (!current_matrix_up_to_date_p
15558 && !NILP (Vwindow_text_change_functions
))
15560 safe_run_hooks (Qwindow_text_change_functions
);
15564 beg_unchanged
= BEG_UNCHANGED
;
15565 end_unchanged
= END_UNCHANGED
;
15567 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
15569 specbind (Qinhibit_point_motion_hooks
, Qt
);
15572 = (w
->window_end_valid
15573 && !current_buffer
->clip_changed
15574 && !window_outdated (w
));
15576 /* When windows_or_buffers_changed is non-zero, we can't rely
15577 on the window end being valid, so set it to zero there. */
15578 if (windows_or_buffers_changed
)
15580 /* If window starts on a continuation line, maybe adjust the
15581 window start in case the window's width changed. */
15582 if (XMARKER (w
->start
)->buffer
== current_buffer
)
15583 compute_window_start_on_continuation_line (w
);
15585 w
->window_end_valid
= 0;
15586 /* If so, we also can't rely on current matrix
15587 and should not fool try_cursor_movement below. */
15588 current_matrix_up_to_date_p
= 0;
15591 /* Some sanity checks. */
15592 CHECK_WINDOW_END (w
);
15593 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
15595 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
15598 if (mode_line_update_needed (w
))
15599 update_mode_line
= 1;
15601 /* Point refers normally to the selected window. For any other
15602 window, set up appropriate value. */
15603 if (!EQ (window
, selected_window
))
15605 ptrdiff_t new_pt
= marker_position (w
->pointm
);
15606 ptrdiff_t new_pt_byte
= marker_byte_position (w
->pointm
);
15610 new_pt_byte
= BEGV_BYTE
;
15611 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
15613 else if (new_pt
> (ZV
- 1))
15616 new_pt_byte
= ZV_BYTE
;
15617 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
15620 /* We don't use SET_PT so that the point-motion hooks don't run. */
15621 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
15624 /* If any of the character widths specified in the display table
15625 have changed, invalidate the width run cache. It's true that
15626 this may be a bit late to catch such changes, but the rest of
15627 redisplay goes (non-fatally) haywire when the display table is
15628 changed, so why should we worry about doing any better? */
15629 if (current_buffer
->width_run_cache
)
15631 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
15633 if (! disptab_matches_widthtab
15634 (disptab
, XVECTOR (BVAR (current_buffer
, width_table
))))
15636 invalidate_region_cache (current_buffer
,
15637 current_buffer
->width_run_cache
,
15639 recompute_width_table (current_buffer
, disptab
);
15643 /* If window-start is screwed up, choose a new one. */
15644 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
15647 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15649 /* If someone specified a new starting point but did not insist,
15650 check whether it can be used. */
15651 if (w
->optional_new_start
15652 && CHARPOS (startp
) >= BEGV
15653 && CHARPOS (startp
) <= ZV
)
15655 w
->optional_new_start
= 0;
15656 start_display (&it
, w
, startp
);
15657 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
15658 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15659 if (IT_CHARPOS (it
) == PT
)
15660 w
->force_start
= 1;
15661 /* IT may overshoot PT if text at PT is invisible. */
15662 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
15663 w
->force_start
= 1;
15668 /* Handle case where place to start displaying has been specified,
15669 unless the specified location is outside the accessible range. */
15670 if (w
->force_start
|| window_frozen_p (w
))
15672 /* We set this later on if we have to adjust point. */
15675 w
->force_start
= 0;
15677 w
->window_end_valid
= 0;
15679 /* Forget any recorded base line for line number display. */
15680 if (!buffer_unchanged_p
)
15681 w
->base_line_number
= 0;
15683 /* Redisplay the mode line. Select the buffer properly for that.
15684 Also, run the hook window-scroll-functions
15685 because we have scrolled. */
15686 /* Note, we do this after clearing force_start because
15687 if there's an error, it is better to forget about force_start
15688 than to get into an infinite loop calling the hook functions
15689 and having them get more errors. */
15690 if (!update_mode_line
15691 || ! NILP (Vwindow_scroll_functions
))
15693 update_mode_line
= 1;
15694 w
->update_mode_line
= 1;
15695 startp
= run_window_scroll_functions (window
, startp
);
15698 if (CHARPOS (startp
) < BEGV
)
15699 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
15700 else if (CHARPOS (startp
) > ZV
)
15701 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
15703 /* Redisplay, then check if cursor has been set during the
15704 redisplay. Give up if new fonts were loaded. */
15705 /* We used to issue a CHECK_MARGINS argument to try_window here,
15706 but this causes scrolling to fail when point begins inside
15707 the scroll margin (bug#148) -- cyd */
15708 if (!try_window (window
, startp
, 0))
15710 w
->force_start
= 1;
15711 clear_glyph_matrix (w
->desired_matrix
);
15712 goto need_larger_matrices
;
15715 if (w
->cursor
.vpos
< 0 && !window_frozen_p (w
))
15717 /* If point does not appear, try to move point so it does
15718 appear. The desired matrix has been built above, so we
15719 can use it here. */
15720 new_vpos
= window_box_height (w
) / 2;
15723 if (!cursor_row_fully_visible_p (w
, 0, 0))
15725 /* Point does appear, but on a line partly visible at end of window.
15726 Move it back to a fully-visible line. */
15727 new_vpos
= window_box_height (w
);
15729 else if (w
->cursor
.vpos
>=0)
15731 /* Some people insist on not letting point enter the scroll
15732 margin, even though this part handles windows that didn't
15734 int window_total_lines
15735 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
15736 int margin
= min (scroll_margin
, window_total_lines
/ 4);
15737 int pixel_margin
= margin
* frame_line_height
;
15738 bool header_line
= WINDOW_WANTS_HEADER_LINE_P (w
);
15740 /* Note: We add an extra FRAME_LINE_HEIGHT, because the loop
15741 below, which finds the row to move point to, advances by
15742 the Y coordinate of the _next_ row, see the definition of
15743 MATRIX_ROW_BOTTOM_Y. */
15744 if (w
->cursor
.vpos
< margin
+ header_line
)
15746 w
->cursor
.vpos
= -1;
15747 clear_glyph_matrix (w
->desired_matrix
);
15748 goto try_to_scroll
;
15752 int window_height
= window_box_height (w
);
15755 window_height
+= CURRENT_HEADER_LINE_HEIGHT (w
);
15756 if (w
->cursor
.y
>= window_height
- pixel_margin
)
15758 w
->cursor
.vpos
= -1;
15759 clear_glyph_matrix (w
->desired_matrix
);
15760 goto try_to_scroll
;
15765 /* If we need to move point for either of the above reasons,
15766 now actually do it. */
15769 struct glyph_row
*row
;
15771 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
15772 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
15775 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
15776 MATRIX_ROW_START_BYTEPOS (row
));
15778 if (w
!= XWINDOW (selected_window
))
15779 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
15780 else if (current_buffer
== old
)
15781 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15783 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
15785 /* If we are highlighting the region, then we just changed
15786 the region, so redisplay to show it. */
15787 if (markpos_of_region () >= 0)
15789 clear_glyph_matrix (w
->desired_matrix
);
15790 if (!try_window (window
, startp
, 0))
15791 goto need_larger_matrices
;
15796 debug_method_add (w
, "forced window start");
15801 /* Handle case where text has not changed, only point, and it has
15802 not moved off the frame, and we are not retrying after hscroll.
15803 (current_matrix_up_to_date_p is nonzero when retrying.) */
15804 if (current_matrix_up_to_date_p
15805 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
15806 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
15810 case CURSOR_MOVEMENT_SUCCESS
:
15811 used_current_matrix_p
= 1;
15814 case CURSOR_MOVEMENT_MUST_SCROLL
:
15815 goto try_to_scroll
;
15821 /* If current starting point was originally the beginning of a line
15822 but no longer is, find a new starting point. */
15823 else if (w
->start_at_line_beg
15824 && !(CHARPOS (startp
) <= BEGV
15825 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
15828 debug_method_add (w
, "recenter 1");
15833 /* Try scrolling with try_window_id. Value is > 0 if update has
15834 been done, it is -1 if we know that the same window start will
15835 not work. It is 0 if unsuccessful for some other reason. */
15836 else if ((tem
= try_window_id (w
)) != 0)
15839 debug_method_add (w
, "try_window_id %d", tem
);
15842 if (fonts_changed_p
)
15843 goto need_larger_matrices
;
15847 /* Otherwise try_window_id has returned -1 which means that we
15848 don't want the alternative below this comment to execute. */
15850 else if (CHARPOS (startp
) >= BEGV
15851 && CHARPOS (startp
) <= ZV
15852 && PT
>= CHARPOS (startp
)
15853 && (CHARPOS (startp
) < ZV
15854 /* Avoid starting at end of buffer. */
15855 || CHARPOS (startp
) == BEGV
15856 || !window_outdated (w
)))
15858 int d1
, d2
, d3
, d4
, d5
, d6
;
15860 /* If first window line is a continuation line, and window start
15861 is inside the modified region, but the first change is before
15862 current window start, we must select a new window start.
15864 However, if this is the result of a down-mouse event (e.g. by
15865 extending the mouse-drag-overlay), we don't want to select a
15866 new window start, since that would change the position under
15867 the mouse, resulting in an unwanted mouse-movement rather
15868 than a simple mouse-click. */
15869 if (!w
->start_at_line_beg
15870 && NILP (do_mouse_tracking
)
15871 && CHARPOS (startp
) > BEGV
15872 && CHARPOS (startp
) > BEG
+ beg_unchanged
15873 && CHARPOS (startp
) <= Z
- end_unchanged
15874 /* Even if w->start_at_line_beg is nil, a new window may
15875 start at a line_beg, since that's how set_buffer_window
15876 sets it. So, we need to check the return value of
15877 compute_window_start_on_continuation_line. (See also
15879 && XMARKER (w
->start
)->buffer
== current_buffer
15880 && compute_window_start_on_continuation_line (w
)
15881 /* It doesn't make sense to force the window start like we
15882 do at label force_start if it is already known that point
15883 will not be visible in the resulting window, because
15884 doing so will move point from its correct position
15885 instead of scrolling the window to bring point into view.
15887 && pos_visible_p (w
, PT
, &d1
, &d2
, &d3
, &d4
, &d5
, &d6
))
15889 w
->force_start
= 1;
15890 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15895 debug_method_add (w
, "same window start");
15898 /* Try to redisplay starting at same place as before.
15899 If point has not moved off frame, accept the results. */
15900 if (!current_matrix_up_to_date_p
15901 /* Don't use try_window_reusing_current_matrix in this case
15902 because a window scroll function can have changed the
15904 || !NILP (Vwindow_scroll_functions
)
15905 || MINI_WINDOW_P (w
)
15906 || !(used_current_matrix_p
15907 = try_window_reusing_current_matrix (w
)))
15909 IF_DEBUG (debug_method_add (w
, "1"));
15910 if (try_window (window
, startp
, TRY_WINDOW_CHECK_MARGINS
) < 0)
15911 /* -1 means we need to scroll.
15912 0 means we need new matrices, but fonts_changed_p
15913 is set in that case, so we will detect it below. */
15914 goto try_to_scroll
;
15917 if (fonts_changed_p
)
15918 goto need_larger_matrices
;
15920 if (w
->cursor
.vpos
>= 0)
15922 if (!just_this_one_p
15923 || current_buffer
->clip_changed
15924 || BEG_UNCHANGED
< CHARPOS (startp
))
15925 /* Forget any recorded base line for line number display. */
15926 w
->base_line_number
= 0;
15928 if (!cursor_row_fully_visible_p (w
, 1, 0))
15930 clear_glyph_matrix (w
->desired_matrix
);
15931 last_line_misfit
= 1;
15933 /* Drop through and scroll. */
15938 clear_glyph_matrix (w
->desired_matrix
);
15943 /* Redisplay the mode line. Select the buffer properly for that. */
15944 if (!update_mode_line
)
15946 update_mode_line
= 1;
15947 w
->update_mode_line
= 1;
15950 /* Try to scroll by specified few lines. */
15951 if ((scroll_conservatively
15952 || emacs_scroll_step
15953 || temp_scroll_step
15954 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
))
15955 || NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
)))
15956 && CHARPOS (startp
) >= BEGV
15957 && CHARPOS (startp
) <= ZV
)
15959 /* The function returns -1 if new fonts were loaded, 1 if
15960 successful, 0 if not successful. */
15961 int ss
= try_scrolling (window
, just_this_one_p
,
15962 scroll_conservatively
,
15964 temp_scroll_step
, last_line_misfit
);
15967 case SCROLLING_SUCCESS
:
15970 case SCROLLING_NEED_LARGER_MATRICES
:
15971 goto need_larger_matrices
;
15973 case SCROLLING_FAILED
:
15981 /* Finally, just choose a place to start which positions point
15982 according to user preferences. */
15987 debug_method_add (w
, "recenter");
15990 /* Forget any previously recorded base line for line number display. */
15991 if (!buffer_unchanged_p
)
15992 w
->base_line_number
= 0;
15994 /* Determine the window start relative to point. */
15995 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
15996 it
.current_y
= it
.last_visible_y
;
15997 if (centering_position
< 0)
15999 int window_total_lines
16000 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
16003 ? min (scroll_margin
, window_total_lines
/ 4)
16005 ptrdiff_t margin_pos
= CHARPOS (startp
);
16006 Lisp_Object aggressive
;
16009 /* If there is a scroll margin at the top of the window, find
16010 its character position. */
16012 /* Cannot call start_display if startp is not in the
16013 accessible region of the buffer. This can happen when we
16014 have just switched to a different buffer and/or changed
16015 its restriction. In that case, startp is initialized to
16016 the character position 1 (BEGV) because we did not yet
16017 have chance to display the buffer even once. */
16018 && BEGV
<= CHARPOS (startp
) && CHARPOS (startp
) <= ZV
)
16021 void *it1data
= NULL
;
16023 SAVE_IT (it1
, it
, it1data
);
16024 start_display (&it1
, w
, startp
);
16025 move_it_vertically (&it1
, margin
* frame_line_height
);
16026 margin_pos
= IT_CHARPOS (it1
);
16027 RESTORE_IT (&it
, &it
, it1data
);
16029 scrolling_up
= PT
> margin_pos
;
16032 ? BVAR (current_buffer
, scroll_up_aggressively
)
16033 : BVAR (current_buffer
, scroll_down_aggressively
);
16035 if (!MINI_WINDOW_P (w
)
16036 && (scroll_conservatively
> SCROLL_LIMIT
|| NUMBERP (aggressive
)))
16040 /* Setting scroll-conservatively overrides
16041 scroll-*-aggressively. */
16042 if (!scroll_conservatively
&& NUMBERP (aggressive
))
16044 double float_amount
= XFLOATINT (aggressive
);
16046 pt_offset
= float_amount
* WINDOW_BOX_TEXT_HEIGHT (w
);
16047 if (pt_offset
== 0 && float_amount
> 0)
16049 if (pt_offset
&& margin
> 0)
16052 /* Compute how much to move the window start backward from
16053 point so that point will be displayed where the user
16057 centering_position
= it
.last_visible_y
;
16059 centering_position
-= pt_offset
;
16060 centering_position
-=
16061 frame_line_height
* (1 + margin
+ (last_line_misfit
!= 0))
16062 + WINDOW_HEADER_LINE_HEIGHT (w
);
16063 /* Don't let point enter the scroll margin near top of
16065 if (centering_position
< margin
* frame_line_height
)
16066 centering_position
= margin
* frame_line_height
;
16069 centering_position
= margin
* frame_line_height
+ pt_offset
;
16072 /* Set the window start half the height of the window backward
16074 centering_position
= window_box_height (w
) / 2;
16076 move_it_vertically_backward (&it
, centering_position
);
16078 eassert (IT_CHARPOS (it
) >= BEGV
);
16080 /* The function move_it_vertically_backward may move over more
16081 than the specified y-distance. If it->w is small, e.g. a
16082 mini-buffer window, we may end up in front of the window's
16083 display area. Start displaying at the start of the line
16084 containing PT in this case. */
16085 if (it
.current_y
<= 0)
16087 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
16088 move_it_vertically_backward (&it
, 0);
16092 it
.current_x
= it
.hpos
= 0;
16094 /* Set the window start position here explicitly, to avoid an
16095 infinite loop in case the functions in window-scroll-functions
16097 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
16099 /* Run scroll hooks. */
16100 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
16102 /* Redisplay the window. */
16103 if (!current_matrix_up_to_date_p
16104 || windows_or_buffers_changed
16105 || cursor_type_changed
16106 /* Don't use try_window_reusing_current_matrix in this case
16107 because it can have changed the buffer. */
16108 || !NILP (Vwindow_scroll_functions
)
16109 || !just_this_one_p
16110 || MINI_WINDOW_P (w
)
16111 || !(used_current_matrix_p
16112 = try_window_reusing_current_matrix (w
)))
16113 try_window (window
, startp
, 0);
16115 /* If new fonts have been loaded (due to fontsets), give up. We
16116 have to start a new redisplay since we need to re-adjust glyph
16118 if (fonts_changed_p
)
16119 goto need_larger_matrices
;
16121 /* If cursor did not appear assume that the middle of the window is
16122 in the first line of the window. Do it again with the next line.
16123 (Imagine a window of height 100, displaying two lines of height
16124 60. Moving back 50 from it->last_visible_y will end in the first
16126 if (w
->cursor
.vpos
< 0)
16128 if (w
->window_end_valid
&& PT
>= Z
- w
->window_end_pos
)
16130 clear_glyph_matrix (w
->desired_matrix
);
16131 move_it_by_lines (&it
, 1);
16132 try_window (window
, it
.current
.pos
, 0);
16134 else if (PT
< IT_CHARPOS (it
))
16136 clear_glyph_matrix (w
->desired_matrix
);
16137 move_it_by_lines (&it
, -1);
16138 try_window (window
, it
.current
.pos
, 0);
16142 /* Not much we can do about it. */
16146 /* Consider the following case: Window starts at BEGV, there is
16147 invisible, intangible text at BEGV, so that display starts at
16148 some point START > BEGV. It can happen that we are called with
16149 PT somewhere between BEGV and START. Try to handle that case. */
16150 if (w
->cursor
.vpos
< 0)
16152 struct glyph_row
*row
= w
->current_matrix
->rows
;
16153 if (row
->mode_line_p
)
16155 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
16158 if (!cursor_row_fully_visible_p (w
, 0, 0))
16160 /* If vscroll is enabled, disable it and try again. */
16164 clear_glyph_matrix (w
->desired_matrix
);
16168 /* Users who set scroll-conservatively to a large number want
16169 point just above/below the scroll margin. If we ended up
16170 with point's row partially visible, move the window start to
16171 make that row fully visible and out of the margin. */
16172 if (scroll_conservatively
> SCROLL_LIMIT
)
16174 int window_total_lines
16175 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) * frame_line_height
;
16178 ? min (scroll_margin
, window_total_lines
/ 4)
16180 int move_down
= w
->cursor
.vpos
>= window_total_lines
/ 2;
16182 move_it_by_lines (&it
, move_down
? margin
+ 1 : -(margin
+ 1));
16183 clear_glyph_matrix (w
->desired_matrix
);
16184 if (1 == try_window (window
, it
.current
.pos
,
16185 TRY_WINDOW_CHECK_MARGINS
))
16189 /* If centering point failed to make the whole line visible,
16190 put point at the top instead. That has to make the whole line
16191 visible, if it can be done. */
16192 if (centering_position
== 0)
16195 clear_glyph_matrix (w
->desired_matrix
);
16196 centering_position
= 0;
16202 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
16203 w
->start_at_line_beg
= (CHARPOS (startp
) == BEGV
16204 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n');
16206 /* Display the mode line, if we must. */
16207 if ((update_mode_line
16208 /* If window not full width, must redo its mode line
16209 if (a) the window to its side is being redone and
16210 (b) we do a frame-based redisplay. This is a consequence
16211 of how inverted lines are drawn in frame-based redisplay. */
16212 || (!just_this_one_p
16213 && !FRAME_WINDOW_P (f
)
16214 && !WINDOW_FULL_WIDTH_P (w
))
16215 /* Line number to display. */
16216 || w
->base_line_pos
> 0
16217 /* Column number is displayed and different from the one displayed. */
16218 || (w
->column_number_displayed
!= -1
16219 && (w
->column_number_displayed
!= current_column ())))
16220 /* This means that the window has a mode line. */
16221 && (WINDOW_WANTS_MODELINE_P (w
)
16222 || WINDOW_WANTS_HEADER_LINE_P (w
)))
16224 display_mode_lines (w
);
16226 /* If mode line height has changed, arrange for a thorough
16227 immediate redisplay using the correct mode line height. */
16228 if (WINDOW_WANTS_MODELINE_P (w
)
16229 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
16231 fonts_changed_p
= 1;
16232 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
16233 = DESIRED_MODE_LINE_HEIGHT (w
);
16236 /* If header line height has changed, arrange for a thorough
16237 immediate redisplay using the correct header line height. */
16238 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16239 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
16241 fonts_changed_p
= 1;
16242 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
16243 = DESIRED_HEADER_LINE_HEIGHT (w
);
16246 if (fonts_changed_p
)
16247 goto need_larger_matrices
;
16250 if (!line_number_displayed
&& w
->base_line_pos
!= -1)
16252 w
->base_line_pos
= 0;
16253 w
->base_line_number
= 0;
16258 /* When we reach a frame's selected window, redo the frame's menu bar. */
16259 if (update_mode_line
16260 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
16262 int redisplay_menu_p
= 0;
16264 if (FRAME_WINDOW_P (f
))
16266 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
16267 || defined (HAVE_NS) || defined (USE_GTK)
16268 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
16270 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16274 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16276 if (redisplay_menu_p
)
16277 display_menu_bar (w
);
16279 #ifdef HAVE_WINDOW_SYSTEM
16280 if (FRAME_WINDOW_P (f
))
16282 #if defined (USE_GTK) || defined (HAVE_NS)
16283 if (FRAME_EXTERNAL_TOOL_BAR (f
))
16284 redisplay_tool_bar (f
);
16286 if (WINDOWP (f
->tool_bar_window
)
16287 && (FRAME_TOOL_BAR_LINES (f
) > 0
16288 || !NILP (Vauto_resize_tool_bars
))
16289 && redisplay_tool_bar (f
))
16290 ignore_mouse_drag_p
= 1;
16296 #ifdef HAVE_WINDOW_SYSTEM
16297 if (FRAME_WINDOW_P (f
)
16298 && update_window_fringes (w
, (just_this_one_p
16299 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
16300 || w
->pseudo_window_p
)))
16304 if (draw_window_fringes (w
, 1))
16305 x_draw_vertical_border (w
);
16309 #endif /* HAVE_WINDOW_SYSTEM */
16311 /* We go to this label, with fonts_changed_p set,
16312 if it is necessary to try again using larger glyph matrices.
16313 We have to redeem the scroll bar even in this case,
16314 because the loop in redisplay_internal expects that. */
16315 need_larger_matrices
:
16317 finish_scroll_bars
:
16319 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
16321 /* Set the thumb's position and size. */
16322 set_vertical_scroll_bar (w
);
16324 /* Note that we actually used the scroll bar attached to this
16325 window, so it shouldn't be deleted at the end of redisplay. */
16326 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
16327 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
16330 /* Restore current_buffer and value of point in it. The window
16331 update may have changed the buffer, so first make sure `opoint'
16332 is still valid (Bug#6177). */
16333 if (CHARPOS (opoint
) < BEGV
)
16334 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
16335 else if (CHARPOS (opoint
) > ZV
)
16336 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
16338 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
16340 set_buffer_internal_1 (old
);
16341 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
16342 shorter. This can be caused by log truncation in *Messages*. */
16343 if (CHARPOS (lpoint
) <= ZV
)
16344 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
16346 unbind_to (count
, Qnil
);
16350 /* Build the complete desired matrix of WINDOW with a window start
16351 buffer position POS.
16353 Value is 1 if successful. It is zero if fonts were loaded during
16354 redisplay which makes re-adjusting glyph matrices necessary, and -1
16355 if point would appear in the scroll margins.
16356 (We check the former only if TRY_WINDOW_IGNORE_FONTS_CHANGE is
16357 unset in FLAGS, and the latter only if TRY_WINDOW_CHECK_MARGINS is
16361 try_window (Lisp_Object window
, struct text_pos pos
, int flags
)
16363 struct window
*w
= XWINDOW (window
);
16365 struct glyph_row
*last_text_row
= NULL
;
16366 struct frame
*f
= XFRAME (w
->frame
);
16367 int frame_line_height
= default_line_pixel_height (w
);
16369 /* Make POS the new window start. */
16370 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
16372 /* Mark cursor position as unknown. No overlay arrow seen. */
16373 w
->cursor
.vpos
= -1;
16374 overlay_arrow_seen
= 0;
16376 /* Initialize iterator and info to start at POS. */
16377 start_display (&it
, w
, pos
);
16381 /* Display all lines of W. */
16382 while (it
.current_y
< it
.last_visible_y
)
16384 if (display_line (&it
))
16385 last_text_row
= it
.glyph_row
- 1;
16386 if (fonts_changed_p
&& !(flags
& TRY_WINDOW_IGNORE_FONTS_CHANGE
))
16389 #ifdef HAVE_XWIDGETS_xxx
16390 //currently this is needed to detect xwidget movement reliably. or probably not.
16391 printf("try_window\n");
16395 /* Don't let the cursor end in the scroll margins. */
16396 if ((flags
& TRY_WINDOW_CHECK_MARGINS
)
16397 && !MINI_WINDOW_P (w
))
16399 int this_scroll_margin
;
16400 int window_total_lines
16401 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
16403 if (scroll_margin
> 0)
16405 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4);
16406 this_scroll_margin
*= frame_line_height
;
16409 this_scroll_margin
= 0;
16411 if ((w
->cursor
.y
>= 0 /* not vscrolled */
16412 && w
->cursor
.y
< this_scroll_margin
16413 && CHARPOS (pos
) > BEGV
16414 && IT_CHARPOS (it
) < ZV
)
16415 /* rms: considering make_cursor_line_fully_visible_p here
16416 seems to give wrong results. We don't want to recenter
16417 when the last line is partly visible, we want to allow
16418 that case to be handled in the usual way. */
16419 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
16421 w
->cursor
.vpos
= -1;
16422 clear_glyph_matrix (w
->desired_matrix
);
16427 /* If bottom moved off end of frame, change mode line percentage. */
16428 if (w
->window_end_pos
<= 0 && Z
!= IT_CHARPOS (it
))
16429 w
->update_mode_line
= 1;
16431 /* Set window_end_pos to the offset of the last character displayed
16432 on the window from the end of current_buffer. Set
16433 window_end_vpos to its row number. */
16436 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
16437 adjust_window_ends (w
, last_text_row
, 0);
16439 (MATRIX_ROW_DISPLAYS_TEXT_P (MATRIX_ROW (w
->desired_matrix
,
16440 w
->window_end_vpos
)));
16444 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16445 w
->window_end_pos
= Z
- ZV
;
16446 w
->window_end_vpos
= 0;
16449 /* But that is not valid info until redisplay finishes. */
16450 w
->window_end_valid
= 0;
16456 /************************************************************************
16457 Window redisplay reusing current matrix when buffer has not changed
16458 ************************************************************************/
16460 /* Try redisplay of window W showing an unchanged buffer with a
16461 different window start than the last time it was displayed by
16462 reusing its current matrix. Value is non-zero if successful.
16463 W->start is the new window start. */
16466 try_window_reusing_current_matrix (struct window
*w
)
16468 struct frame
*f
= XFRAME (w
->frame
);
16469 struct glyph_row
*bottom_row
;
16472 struct text_pos start
, new_start
;
16473 int nrows_scrolled
, i
;
16474 struct glyph_row
*last_text_row
;
16475 struct glyph_row
*last_reused_text_row
;
16476 struct glyph_row
*start_row
;
16477 int start_vpos
, min_y
, max_y
;
16480 if (inhibit_try_window_reusing
)
16484 #ifdef HAVE_XWIDGETS_xxx
16485 //currently this is needed to detect xwidget movement reliably. or probably not.
16486 printf("try_window_reusing_current_matrix\n");
16491 if (/* This function doesn't handle terminal frames. */
16492 !FRAME_WINDOW_P (f
)
16493 /* Don't try to reuse the display if windows have been split
16495 || windows_or_buffers_changed
16496 || cursor_type_changed
)
16499 /* Can't do this if region may have changed. */
16500 if (markpos_of_region () >= 0
16501 || w
->region_showing
16502 || !NILP (Vshow_trailing_whitespace
))
16505 /* If top-line visibility has changed, give up. */
16506 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16507 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
16510 /* Give up if old or new display is scrolled vertically. We could
16511 make this function handle this, but right now it doesn't. */
16512 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16513 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
16516 /* The variable new_start now holds the new window start. The old
16517 start `start' can be determined from the current matrix. */
16518 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
16519 start
= start_row
->minpos
;
16520 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16522 /* Clear the desired matrix for the display below. */
16523 clear_glyph_matrix (w
->desired_matrix
);
16525 if (CHARPOS (new_start
) <= CHARPOS (start
))
16527 /* Don't use this method if the display starts with an ellipsis
16528 displayed for invisible text. It's not easy to handle that case
16529 below, and it's certainly not worth the effort since this is
16530 not a frequent case. */
16531 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
16534 IF_DEBUG (debug_method_add (w
, "twu1"));
16536 /* Display up to a row that can be reused. The variable
16537 last_text_row is set to the last row displayed that displays
16538 text. Note that it.vpos == 0 if or if not there is a
16539 header-line; it's not the same as the MATRIX_ROW_VPOS! */
16540 start_display (&it
, w
, new_start
);
16541 w
->cursor
.vpos
= -1;
16542 last_text_row
= last_reused_text_row
= NULL
;
16544 while (it
.current_y
< it
.last_visible_y
16545 && !fonts_changed_p
)
16547 /* If we have reached into the characters in the START row,
16548 that means the line boundaries have changed. So we
16549 can't start copying with the row START. Maybe it will
16550 work to start copying with the following row. */
16551 while (IT_CHARPOS (it
) > CHARPOS (start
))
16553 /* Advance to the next row as the "start". */
16555 start
= start_row
->minpos
;
16556 /* If there are no more rows to try, or just one, give up. */
16557 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
16558 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
16559 || CHARPOS (start
) == ZV
)
16561 clear_glyph_matrix (w
->desired_matrix
);
16565 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16567 /* If we have reached alignment, we can copy the rest of the
16569 if (IT_CHARPOS (it
) == CHARPOS (start
)
16570 /* Don't accept "alignment" inside a display vector,
16571 since start_row could have started in the middle of
16572 that same display vector (thus their character
16573 positions match), and we have no way of telling if
16574 that is the case. */
16575 && it
.current
.dpvec_index
< 0)
16578 if (display_line (&it
))
16579 last_text_row
= it
.glyph_row
- 1;
16583 /* A value of current_y < last_visible_y means that we stopped
16584 at the previous window start, which in turn means that we
16585 have at least one reusable row. */
16586 if (it
.current_y
< it
.last_visible_y
)
16588 struct glyph_row
*row
;
16590 /* IT.vpos always starts from 0; it counts text lines. */
16591 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
16593 /* Find PT if not already found in the lines displayed. */
16594 if (w
->cursor
.vpos
< 0)
16596 int dy
= it
.current_y
- start_row
->y
;
16598 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16599 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
16601 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
16602 dy
, nrows_scrolled
);
16605 clear_glyph_matrix (w
->desired_matrix
);
16610 /* Scroll the display. Do it before the current matrix is
16611 changed. The problem here is that update has not yet
16612 run, i.e. part of the current matrix is not up to date.
16613 scroll_run_hook will clear the cursor, and use the
16614 current matrix to get the height of the row the cursor is
16616 run
.current_y
= start_row
->y
;
16617 run
.desired_y
= it
.current_y
;
16618 run
.height
= it
.last_visible_y
- it
.current_y
;
16620 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
16623 FRAME_RIF (f
)->update_window_begin_hook (w
);
16624 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16625 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16626 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16630 /* Shift current matrix down by nrows_scrolled lines. */
16631 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16632 rotate_matrix (w
->current_matrix
,
16634 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16637 /* Disable lines that must be updated. */
16638 for (i
= 0; i
< nrows_scrolled
; ++i
)
16639 (start_row
+ i
)->enabled_p
= 0;
16641 /* Re-compute Y positions. */
16642 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16643 max_y
= it
.last_visible_y
;
16644 for (row
= start_row
+ nrows_scrolled
;
16648 row
->y
= it
.current_y
;
16649 row
->visible_height
= row
->height
;
16651 if (row
->y
< min_y
)
16652 row
->visible_height
-= min_y
- row
->y
;
16653 if (row
->y
+ row
->height
> max_y
)
16654 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16655 if (row
->fringe_bitmap_periodic_p
)
16656 row
->redraw_fringe_bitmaps_p
= 1;
16658 it
.current_y
+= row
->height
;
16660 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16661 last_reused_text_row
= row
;
16662 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
16666 /* Disable lines in the current matrix which are now
16667 below the window. */
16668 for (++row
; row
< bottom_row
; ++row
)
16669 row
->enabled_p
= row
->mode_line_p
= 0;
16672 /* Update window_end_pos etc.; last_reused_text_row is the last
16673 reused row from the current matrix containing text, if any.
16674 The value of last_text_row is the last displayed line
16675 containing text. */
16676 if (last_reused_text_row
)
16677 adjust_window_ends (w
, last_reused_text_row
, 1);
16678 else if (last_text_row
)
16679 adjust_window_ends (w
, last_text_row
, 0);
16682 /* This window must be completely empty. */
16683 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16684 w
->window_end_pos
= Z
- ZV
;
16685 w
->window_end_vpos
= 0;
16687 w
->window_end_valid
= 0;
16689 /* Update hint: don't try scrolling again in update_window. */
16690 w
->desired_matrix
->no_scrolling_p
= 1;
16693 debug_method_add (w
, "try_window_reusing_current_matrix 1");
16697 else if (CHARPOS (new_start
) > CHARPOS (start
))
16699 struct glyph_row
*pt_row
, *row
;
16700 struct glyph_row
*first_reusable_row
;
16701 struct glyph_row
*first_row_to_display
;
16703 int yb
= window_text_bottom_y (w
);
16705 /* Find the row starting at new_start, if there is one. Don't
16706 reuse a partially visible line at the end. */
16707 first_reusable_row
= start_row
;
16708 while (first_reusable_row
->enabled_p
16709 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
16710 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16711 < CHARPOS (new_start
)))
16712 ++first_reusable_row
;
16714 /* Give up if there is no row to reuse. */
16715 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
16716 || !first_reusable_row
->enabled_p
16717 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16718 != CHARPOS (new_start
)))
16721 /* We can reuse fully visible rows beginning with
16722 first_reusable_row to the end of the window. Set
16723 first_row_to_display to the first row that cannot be reused.
16724 Set pt_row to the row containing point, if there is any. */
16726 for (first_row_to_display
= first_reusable_row
;
16727 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
16728 ++first_row_to_display
)
16730 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
16731 && (PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16732 || (PT
== MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16733 && first_row_to_display
->ends_at_zv_p
16734 && pt_row
== NULL
)))
16735 pt_row
= first_row_to_display
;
16738 /* Start displaying at the start of first_row_to_display. */
16739 eassert (first_row_to_display
->y
< yb
);
16740 init_to_row_start (&it
, w
, first_row_to_display
);
16742 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
16744 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
16746 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
16747 + WINDOW_HEADER_LINE_HEIGHT (w
));
16749 /* Display lines beginning with first_row_to_display in the
16750 desired matrix. Set last_text_row to the last row displayed
16751 that displays text. */
16752 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
16753 if (pt_row
== NULL
)
16754 w
->cursor
.vpos
= -1;
16755 last_text_row
= NULL
;
16756 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
16757 if (display_line (&it
))
16758 last_text_row
= it
.glyph_row
- 1;
16760 /* If point is in a reused row, adjust y and vpos of the cursor
16764 w
->cursor
.vpos
-= nrows_scrolled
;
16765 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
16768 /* Give up if point isn't in a row displayed or reused. (This
16769 also handles the case where w->cursor.vpos < nrows_scrolled
16770 after the calls to display_line, which can happen with scroll
16771 margins. See bug#1295.) */
16772 if (w
->cursor
.vpos
< 0)
16774 clear_glyph_matrix (w
->desired_matrix
);
16778 /* Scroll the display. */
16779 run
.current_y
= first_reusable_row
->y
;
16780 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16781 run
.height
= it
.last_visible_y
- run
.current_y
;
16782 dy
= run
.current_y
- run
.desired_y
;
16787 FRAME_RIF (f
)->update_window_begin_hook (w
);
16788 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16789 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16790 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16794 /* Adjust Y positions of reused rows. */
16795 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16796 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16797 max_y
= it
.last_visible_y
;
16798 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
16801 row
->visible_height
= row
->height
;
16802 if (row
->y
< min_y
)
16803 row
->visible_height
-= min_y
- row
->y
;
16804 if (row
->y
+ row
->height
> max_y
)
16805 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16806 if (row
->fringe_bitmap_periodic_p
)
16807 row
->redraw_fringe_bitmaps_p
= 1;
16810 /* Scroll the current matrix. */
16811 eassert (nrows_scrolled
> 0);
16812 rotate_matrix (w
->current_matrix
,
16814 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16817 /* Disable rows not reused. */
16818 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
16819 row
->enabled_p
= 0;
16821 /* Point may have moved to a different line, so we cannot assume that
16822 the previous cursor position is valid; locate the correct row. */
16825 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
16827 && PT
>= MATRIX_ROW_END_CHARPOS (row
)
16828 && !row
->ends_at_zv_p
;
16832 w
->cursor
.y
= row
->y
;
16834 if (row
< bottom_row
)
16836 /* Can't simply scan the row for point with
16837 bidi-reordered glyph rows. Let set_cursor_from_row
16838 figure out where to put the cursor, and if it fails,
16840 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
16842 if (!set_cursor_from_row (w
, row
, w
->current_matrix
,
16845 clear_glyph_matrix (w
->desired_matrix
);
16851 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
16852 struct glyph
*end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16855 && (!BUFFERP (glyph
->object
)
16856 || glyph
->charpos
< PT
);
16860 w
->cursor
.x
+= glyph
->pixel_width
;
16866 /* Adjust window end. A null value of last_text_row means that
16867 the window end is in reused rows which in turn means that
16868 only its vpos can have changed. */
16870 adjust_window_ends (w
, last_text_row
, 0);
16872 w
->window_end_vpos
-= nrows_scrolled
;
16874 w
->window_end_valid
= 0;
16875 w
->desired_matrix
->no_scrolling_p
= 1;
16878 debug_method_add (w
, "try_window_reusing_current_matrix 2");
16888 /************************************************************************
16889 Window redisplay reusing current matrix when buffer has changed
16890 ************************************************************************/
16892 static struct glyph_row
*find_last_unchanged_at_beg_row (struct window
*);
16893 static struct glyph_row
*find_first_unchanged_at_end_row (struct window
*,
16894 ptrdiff_t *, ptrdiff_t *);
16895 static struct glyph_row
*
16896 find_last_row_displaying_text (struct glyph_matrix
*, struct it
*,
16897 struct glyph_row
*);
16900 /* Return the last row in MATRIX displaying text. If row START is
16901 non-null, start searching with that row. IT gives the dimensions
16902 of the display. Value is null if matrix is empty; otherwise it is
16903 a pointer to the row found. */
16905 static struct glyph_row
*
16906 find_last_row_displaying_text (struct glyph_matrix
*matrix
, struct it
*it
,
16907 struct glyph_row
*start
)
16909 struct glyph_row
*row
, *row_found
;
16911 /* Set row_found to the last row in IT->w's current matrix
16912 displaying text. The loop looks funny but think of partially
16915 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
16916 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16918 eassert (row
->enabled_p
);
16920 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
16929 /* Return the last row in the current matrix of W that is not affected
16930 by changes at the start of current_buffer that occurred since W's
16931 current matrix was built. Value is null if no such row exists.
16933 BEG_UNCHANGED us the number of characters unchanged at the start of
16934 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
16935 first changed character in current_buffer. Characters at positions <
16936 BEG + BEG_UNCHANGED are at the same buffer positions as they were
16937 when the current matrix was built. */
16939 static struct glyph_row
*
16940 find_last_unchanged_at_beg_row (struct window
*w
)
16942 ptrdiff_t first_changed_pos
= BEG
+ BEG_UNCHANGED
;
16943 struct glyph_row
*row
;
16944 struct glyph_row
*row_found
= NULL
;
16945 int yb
= window_text_bottom_y (w
);
16947 /* Find the last row displaying unchanged text. */
16948 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16949 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
16950 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
16953 if (/* If row ends before first_changed_pos, it is unchanged,
16954 except in some case. */
16955 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
16956 /* When row ends in ZV and we write at ZV it is not
16958 && !row
->ends_at_zv_p
16959 /* When first_changed_pos is the end of a continued line,
16960 row is not unchanged because it may be no longer
16962 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
16963 && (row
->continued_p
16964 || row
->exact_window_width_line_p
))
16965 /* If ROW->end is beyond ZV, then ROW->end is outdated and
16966 needs to be recomputed, so don't consider this row as
16967 unchanged. This happens when the last line was
16968 bidi-reordered and was killed immediately before this
16969 redisplay cycle. In that case, ROW->end stores the
16970 buffer position of the first visual-order character of
16971 the killed text, which is now beyond ZV. */
16972 && CHARPOS (row
->end
.pos
) <= ZV
)
16975 /* Stop if last visible row. */
16976 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
16984 /* Find the first glyph row in the current matrix of W that is not
16985 affected by changes at the end of current_buffer since the
16986 time W's current matrix was built.
16988 Return in *DELTA the number of chars by which buffer positions in
16989 unchanged text at the end of current_buffer must be adjusted.
16991 Return in *DELTA_BYTES the corresponding number of bytes.
16993 Value is null if no such row exists, i.e. all rows are affected by
16996 static struct glyph_row
*
16997 find_first_unchanged_at_end_row (struct window
*w
,
16998 ptrdiff_t *delta
, ptrdiff_t *delta_bytes
)
17000 struct glyph_row
*row
;
17001 struct glyph_row
*row_found
= NULL
;
17003 *delta
= *delta_bytes
= 0;
17005 /* Display must not have been paused, otherwise the current matrix
17006 is not up to date. */
17007 eassert (w
->window_end_valid
);
17009 /* A value of window_end_pos >= END_UNCHANGED means that the window
17010 end is in the range of changed text. If so, there is no
17011 unchanged row at the end of W's current matrix. */
17012 if (w
->window_end_pos
>= END_UNCHANGED
)
17015 /* Set row to the last row in W's current matrix displaying text. */
17016 row
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
17018 /* If matrix is entirely empty, no unchanged row exists. */
17019 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
17021 /* The value of row is the last glyph row in the matrix having a
17022 meaningful buffer position in it. The end position of row
17023 corresponds to window_end_pos. This allows us to translate
17024 buffer positions in the current matrix to current buffer
17025 positions for characters not in changed text. */
17027 MATRIX_ROW_END_CHARPOS (row
) + w
->window_end_pos
;
17028 ptrdiff_t Z_BYTE_old
=
17029 MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
17030 ptrdiff_t last_unchanged_pos
, last_unchanged_pos_old
;
17031 struct glyph_row
*first_text_row
17032 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
17034 *delta
= Z
- Z_old
;
17035 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
17037 /* Set last_unchanged_pos to the buffer position of the last
17038 character in the buffer that has not been changed. Z is the
17039 index + 1 of the last character in current_buffer, i.e. by
17040 subtracting END_UNCHANGED we get the index of the last
17041 unchanged character, and we have to add BEG to get its buffer
17043 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
17044 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
17046 /* Search backward from ROW for a row displaying a line that
17047 starts at a minimum position >= last_unchanged_pos_old. */
17048 for (; row
> first_text_row
; --row
)
17050 /* This used to abort, but it can happen.
17051 It is ok to just stop the search instead here. KFS. */
17052 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
17055 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
17060 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
17066 /* Make sure that glyph rows in the current matrix of window W
17067 reference the same glyph memory as corresponding rows in the
17068 frame's frame matrix. This function is called after scrolling W's
17069 current matrix on a terminal frame in try_window_id and
17070 try_window_reusing_current_matrix. */
17073 sync_frame_with_window_matrix_rows (struct window
*w
)
17075 struct frame
*f
= XFRAME (w
->frame
);
17076 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
17078 /* Preconditions: W must be a leaf window and full-width. Its frame
17079 must have a frame matrix. */
17080 eassert (BUFFERP (w
->contents
));
17081 eassert (WINDOW_FULL_WIDTH_P (w
));
17082 eassert (!FRAME_WINDOW_P (f
));
17084 /* If W is a full-width window, glyph pointers in W's current matrix
17085 have, by definition, to be the same as glyph pointers in the
17086 corresponding frame matrix. Note that frame matrices have no
17087 marginal areas (see build_frame_matrix). */
17088 window_row
= w
->current_matrix
->rows
;
17089 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
17090 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
17091 while (window_row
< window_row_end
)
17093 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
17094 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
17096 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
17097 frame_row
->glyphs
[TEXT_AREA
] = start
;
17098 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
17099 frame_row
->glyphs
[LAST_AREA
] = end
;
17101 /* Disable frame rows whose corresponding window rows have
17102 been disabled in try_window_id. */
17103 if (!window_row
->enabled_p
)
17104 frame_row
->enabled_p
= 0;
17106 ++window_row
, ++frame_row
;
17111 /* Find the glyph row in window W containing CHARPOS. Consider all
17112 rows between START and END (not inclusive). END null means search
17113 all rows to the end of the display area of W. Value is the row
17114 containing CHARPOS or null. */
17117 row_containing_pos (struct window
*w
, ptrdiff_t charpos
,
17118 struct glyph_row
*start
, struct glyph_row
*end
, int dy
)
17120 struct glyph_row
*row
= start
;
17121 struct glyph_row
*best_row
= NULL
;
17122 ptrdiff_t mindif
= BUF_ZV (XBUFFER (w
->contents
)) + 1;
17125 /* If we happen to start on a header-line, skip that. */
17126 if (row
->mode_line_p
)
17129 if ((end
&& row
>= end
) || !row
->enabled_p
)
17132 last_y
= window_text_bottom_y (w
) - dy
;
17136 /* Give up if we have gone too far. */
17137 if (end
&& row
>= end
)
17139 /* This formerly returned if they were equal.
17140 I think that both quantities are of a "last plus one" type;
17141 if so, when they are equal, the row is within the screen. -- rms. */
17142 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
17145 /* If it is in this row, return this row. */
17146 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
17147 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
17148 /* The end position of a row equals the start
17149 position of the next row. If CHARPOS is there, we
17150 would rather consider it displayed in the next
17151 line, except when this line ends in ZV. */
17152 && !row_for_charpos_p (row
, charpos
)))
17153 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
17157 if (NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
17158 || (!best_row
&& !row
->continued_p
))
17160 /* In bidi-reordered rows, there could be several rows whose
17161 edges surround CHARPOS, all of these rows belonging to
17162 the same continued line. We need to find the row which
17163 fits CHARPOS the best. */
17164 for (g
= row
->glyphs
[TEXT_AREA
];
17165 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
17168 if (!STRINGP (g
->object
))
17170 if (g
->charpos
> 0 && eabs (g
->charpos
- charpos
) < mindif
)
17172 mindif
= eabs (g
->charpos
- charpos
);
17174 /* Exact match always wins. */
17181 else if (best_row
&& !row
->continued_p
)
17188 /* Try to redisplay window W by reusing its existing display. W's
17189 current matrix must be up to date when this function is called,
17190 i.e. window_end_valid must be nonzero.
17194 1 if display has been updated
17195 0 if otherwise unsuccessful
17196 -1 if redisplay with same window start is known not to succeed
17198 The following steps are performed:
17200 1. Find the last row in the current matrix of W that is not
17201 affected by changes at the start of current_buffer. If no such row
17204 2. Find the first row in W's current matrix that is not affected by
17205 changes at the end of current_buffer. Maybe there is no such row.
17207 3. Display lines beginning with the row + 1 found in step 1 to the
17208 row found in step 2 or, if step 2 didn't find a row, to the end of
17211 4. If cursor is not known to appear on the window, give up.
17213 5. If display stopped at the row found in step 2, scroll the
17214 display and current matrix as needed.
17216 6. Maybe display some lines at the end of W, if we must. This can
17217 happen under various circumstances, like a partially visible line
17218 becoming fully visible, or because newly displayed lines are displayed
17219 in smaller font sizes.
17221 7. Update W's window end information. */
17224 try_window_id (struct window
*w
)
17226 struct frame
*f
= XFRAME (w
->frame
);
17227 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
17228 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
17229 struct glyph_row
*last_unchanged_at_beg_row
;
17230 struct glyph_row
*first_unchanged_at_end_row
;
17231 struct glyph_row
*row
;
17232 struct glyph_row
*bottom_row
;
17235 ptrdiff_t delta
= 0, delta_bytes
= 0, stop_pos
;
17237 struct text_pos start_pos
;
17239 int first_unchanged_at_end_vpos
= 0;
17240 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
17241 struct text_pos start
;
17242 ptrdiff_t first_changed_charpos
, last_changed_charpos
;
17245 if (inhibit_try_window_id
)
17249 #ifdef HAVE_XWIDGETS_xxx
17250 //maybe needed for proper xwidget movement
17251 printf("try_window_id\n");
17256 /* This is handy for debugging. */
17258 #define GIVE_UP(X) \
17260 fprintf (stderr, "try_window_id give up %d\n", (X)); \
17264 #define GIVE_UP(X) return 0
17267 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
17269 /* Don't use this for mini-windows because these can show
17270 messages and mini-buffers, and we don't handle that here. */
17271 if (MINI_WINDOW_P (w
))
17274 /* This flag is used to prevent redisplay optimizations. */
17275 if (windows_or_buffers_changed
|| cursor_type_changed
)
17278 /* Verify that narrowing has not changed.
17279 Also verify that we were not told to prevent redisplay optimizations.
17280 It would be nice to further
17281 reduce the number of cases where this prevents try_window_id. */
17282 if (current_buffer
->clip_changed
17283 || current_buffer
->prevent_redisplay_optimizations_p
)
17286 /* Window must either use window-based redisplay or be full width. */
17287 if (!FRAME_WINDOW_P (f
)
17288 && (!FRAME_LINE_INS_DEL_OK (f
)
17289 || !WINDOW_FULL_WIDTH_P (w
)))
17292 /* Give up if point is known NOT to appear in W. */
17293 if (PT
< CHARPOS (start
))
17296 /* Another way to prevent redisplay optimizations. */
17297 if (w
->last_modified
== 0)
17300 /* Verify that window is not hscrolled. */
17301 if (w
->hscroll
!= 0)
17304 /* Verify that display wasn't paused. */
17305 if (!w
->window_end_valid
)
17308 /* Can't use this if highlighting a region because a cursor movement
17309 will do more than just set the cursor. */
17310 if (markpos_of_region () >= 0)
17313 /* Likewise if highlighting trailing whitespace. */
17314 if (!NILP (Vshow_trailing_whitespace
))
17317 /* Likewise if showing a region. */
17318 if (w
->region_showing
)
17321 /* Can't use this if overlay arrow position and/or string have
17323 if (overlay_arrows_changed_p ())
17326 /* When word-wrap is on, adding a space to the first word of a
17327 wrapped line can change the wrap position, altering the line
17328 above it. It might be worthwhile to handle this more
17329 intelligently, but for now just redisplay from scratch. */
17330 if (!NILP (BVAR (XBUFFER (w
->contents
), word_wrap
)))
17333 /* Under bidi reordering, adding or deleting a character in the
17334 beginning of a paragraph, before the first strong directional
17335 character, can change the base direction of the paragraph (unless
17336 the buffer specifies a fixed paragraph direction), which will
17337 require to redisplay the whole paragraph. It might be worthwhile
17338 to find the paragraph limits and widen the range of redisplayed
17339 lines to that, but for now just give up this optimization and
17340 redisplay from scratch. */
17341 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
17342 && NILP (BVAR (XBUFFER (w
->contents
), bidi_paragraph_direction
)))
17345 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
17346 only if buffer has really changed. The reason is that the gap is
17347 initially at Z for freshly visited files. The code below would
17348 set end_unchanged to 0 in that case. */
17349 if (MODIFF
> SAVE_MODIFF
17350 /* This seems to happen sometimes after saving a buffer. */
17351 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
17353 if (GPT
- BEG
< BEG_UNCHANGED
)
17354 BEG_UNCHANGED
= GPT
- BEG
;
17355 if (Z
- GPT
< END_UNCHANGED
)
17356 END_UNCHANGED
= Z
- GPT
;
17359 /* The position of the first and last character that has been changed. */
17360 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
17361 last_changed_charpos
= Z
- END_UNCHANGED
;
17363 /* If window starts after a line end, and the last change is in
17364 front of that newline, then changes don't affect the display.
17365 This case happens with stealth-fontification. Note that although
17366 the display is unchanged, glyph positions in the matrix have to
17367 be adjusted, of course. */
17368 row
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
17369 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
17370 && ((last_changed_charpos
< CHARPOS (start
)
17371 && CHARPOS (start
) == BEGV
)
17372 || (last_changed_charpos
< CHARPOS (start
) - 1
17373 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
17375 ptrdiff_t Z_old
, Z_delta
, Z_BYTE_old
, Z_delta_bytes
;
17376 struct glyph_row
*r0
;
17378 /* Compute how many chars/bytes have been added to or removed
17379 from the buffer. */
17380 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + w
->window_end_pos
;
17381 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
17382 Z_delta
= Z
- Z_old
;
17383 Z_delta_bytes
= Z_BYTE
- Z_BYTE_old
;
17385 /* Give up if PT is not in the window. Note that it already has
17386 been checked at the start of try_window_id that PT is not in
17387 front of the window start. */
17388 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + Z_delta
)
17391 /* If window start is unchanged, we can reuse the whole matrix
17392 as is, after adjusting glyph positions. No need to compute
17393 the window end again, since its offset from Z hasn't changed. */
17394 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17395 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + Z_delta
17396 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + Z_delta_bytes
17397 /* PT must not be in a partially visible line. */
17398 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + Z_delta
17399 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17401 /* Adjust positions in the glyph matrix. */
17402 if (Z_delta
|| Z_delta_bytes
)
17404 struct glyph_row
*r1
17405 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17406 increment_matrix_positions (w
->current_matrix
,
17407 MATRIX_ROW_VPOS (r0
, current_matrix
),
17408 MATRIX_ROW_VPOS (r1
, current_matrix
),
17409 Z_delta
, Z_delta_bytes
);
17412 /* Set the cursor. */
17413 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17415 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17422 /* Handle the case that changes are all below what is displayed in
17423 the window, and that PT is in the window. This shortcut cannot
17424 be taken if ZV is visible in the window, and text has been added
17425 there that is visible in the window. */
17426 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
17427 /* ZV is not visible in the window, or there are no
17428 changes at ZV, actually. */
17429 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
17430 || first_changed_charpos
== last_changed_charpos
))
17432 struct glyph_row
*r0
;
17434 /* Give up if PT is not in the window. Note that it already has
17435 been checked at the start of try_window_id that PT is not in
17436 front of the window start. */
17437 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
17440 /* If window start is unchanged, we can reuse the whole matrix
17441 as is, without changing glyph positions since no text has
17442 been added/removed in front of the window end. */
17443 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17444 if (TEXT_POS_EQUAL_P (start
, r0
->minpos
)
17445 /* PT must not be in a partially visible line. */
17446 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
17447 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17449 /* We have to compute the window end anew since text
17450 could have been added/removed after it. */
17451 w
->window_end_pos
= Z
- MATRIX_ROW_END_CHARPOS (row
);
17452 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17454 /* Set the cursor. */
17455 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17457 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17464 /* Give up if window start is in the changed area.
17466 The condition used to read
17468 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
17470 but why that was tested escapes me at the moment. */
17471 if (CHARPOS (start
) >= first_changed_charpos
17472 && CHARPOS (start
) <= last_changed_charpos
)
17475 /* Check that window start agrees with the start of the first glyph
17476 row in its current matrix. Check this after we know the window
17477 start is not in changed text, otherwise positions would not be
17479 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17480 if (!TEXT_POS_EQUAL_P (start
, row
->minpos
))
17483 /* Give up if the window ends in strings. Overlay strings
17484 at the end are difficult to handle, so don't try. */
17485 row
= MATRIX_ROW (current_matrix
, w
->window_end_vpos
);
17486 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
17489 /* Compute the position at which we have to start displaying new
17490 lines. Some of the lines at the top of the window might be
17491 reusable because they are not displaying changed text. Find the
17492 last row in W's current matrix not affected by changes at the
17493 start of current_buffer. Value is null if changes start in the
17494 first line of window. */
17495 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
17496 if (last_unchanged_at_beg_row
)
17498 /* Avoid starting to display in the middle of a character, a TAB
17499 for instance. This is easier than to set up the iterator
17500 exactly, and it's not a frequent case, so the additional
17501 effort wouldn't really pay off. */
17502 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
17503 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
17504 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
17505 --last_unchanged_at_beg_row
;
17507 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
17510 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
17512 start_pos
= it
.current
.pos
;
17514 /* Start displaying new lines in the desired matrix at the same
17515 vpos we would use in the current matrix, i.e. below
17516 last_unchanged_at_beg_row. */
17517 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
17519 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17520 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
17522 eassert (it
.hpos
== 0 && it
.current_x
== 0);
17526 /* There are no reusable lines at the start of the window.
17527 Start displaying in the first text line. */
17528 start_display (&it
, w
, start
);
17529 it
.vpos
= it
.first_vpos
;
17530 start_pos
= it
.current
.pos
;
17533 /* Find the first row that is not affected by changes at the end of
17534 the buffer. Value will be null if there is no unchanged row, in
17535 which case we must redisplay to the end of the window. delta
17536 will be set to the value by which buffer positions beginning with
17537 first_unchanged_at_end_row have to be adjusted due to text
17539 first_unchanged_at_end_row
17540 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
17541 IF_DEBUG (debug_delta
= delta
);
17542 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
17544 /* Set stop_pos to the buffer position up to which we will have to
17545 display new lines. If first_unchanged_at_end_row != NULL, this
17546 is the buffer position of the start of the line displayed in that
17547 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
17548 that we don't stop at a buffer position. */
17550 if (first_unchanged_at_end_row
)
17552 eassert (last_unchanged_at_beg_row
== NULL
17553 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
17555 /* If this is a continuation line, move forward to the next one
17556 that isn't. Changes in lines above affect this line.
17557 Caution: this may move first_unchanged_at_end_row to a row
17558 not displaying text. */
17559 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
17560 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17561 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17562 < it
.last_visible_y
))
17563 ++first_unchanged_at_end_row
;
17565 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17566 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17567 >= it
.last_visible_y
))
17568 first_unchanged_at_end_row
= NULL
;
17571 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
17573 first_unchanged_at_end_vpos
17574 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
17575 eassert (stop_pos
>= Z
- END_UNCHANGED
);
17578 else if (last_unchanged_at_beg_row
== NULL
)
17584 /* Either there is no unchanged row at the end, or the one we have
17585 now displays text. This is a necessary condition for the window
17586 end pos calculation at the end of this function. */
17587 eassert (first_unchanged_at_end_row
== NULL
17588 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
17590 debug_last_unchanged_at_beg_vpos
17591 = (last_unchanged_at_beg_row
17592 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
17594 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
17596 #endif /* GLYPH_DEBUG */
17599 /* Display new lines. Set last_text_row to the last new line
17600 displayed which has text on it, i.e. might end up as being the
17601 line where the window_end_vpos is. */
17602 w
->cursor
.vpos
= -1;
17603 last_text_row
= NULL
;
17604 overlay_arrow_seen
= 0;
17605 while (it
.current_y
< it
.last_visible_y
17606 && !fonts_changed_p
17607 && (first_unchanged_at_end_row
== NULL
17608 || IT_CHARPOS (it
) < stop_pos
))
17610 if (display_line (&it
))
17611 last_text_row
= it
.glyph_row
- 1;
17614 if (fonts_changed_p
)
17618 /* Compute differences in buffer positions, y-positions etc. for
17619 lines reused at the bottom of the window. Compute what we can
17621 if (first_unchanged_at_end_row
17622 /* No lines reused because we displayed everything up to the
17623 bottom of the window. */
17624 && it
.current_y
< it
.last_visible_y
)
17627 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
17629 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
17630 run
.current_y
= first_unchanged_at_end_row
->y
;
17631 run
.desired_y
= run
.current_y
+ dy
;
17632 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
17636 delta
= delta_bytes
= dvpos
= dy
17637 = run
.current_y
= run
.desired_y
= run
.height
= 0;
17638 first_unchanged_at_end_row
= NULL
;
17640 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
17643 /* Find the cursor if not already found. We have to decide whether
17644 PT will appear on this window (it sometimes doesn't, but this is
17645 not a very frequent case.) This decision has to be made before
17646 the current matrix is altered. A value of cursor.vpos < 0 means
17647 that PT is either in one of the lines beginning at
17648 first_unchanged_at_end_row or below the window. Don't care for
17649 lines that might be displayed later at the window end; as
17650 mentioned, this is not a frequent case. */
17651 if (w
->cursor
.vpos
< 0)
17653 /* Cursor in unchanged rows at the top? */
17654 if (PT
< CHARPOS (start_pos
)
17655 && last_unchanged_at_beg_row
)
17657 row
= row_containing_pos (w
, PT
,
17658 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
17659 last_unchanged_at_beg_row
+ 1, 0);
17661 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
17664 /* Start from first_unchanged_at_end_row looking for PT. */
17665 else if (first_unchanged_at_end_row
)
17667 row
= row_containing_pos (w
, PT
- delta
,
17668 first_unchanged_at_end_row
, NULL
, 0);
17670 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
17671 delta_bytes
, dy
, dvpos
);
17674 /* Give up if cursor was not found. */
17675 if (w
->cursor
.vpos
< 0)
17677 clear_glyph_matrix (w
->desired_matrix
);
17682 /* Don't let the cursor end in the scroll margins. */
17684 int this_scroll_margin
, cursor_height
;
17685 int frame_line_height
= default_line_pixel_height (w
);
17686 int window_total_lines
17687 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (it
.f
) / frame_line_height
;
17689 this_scroll_margin
=
17690 max (0, min (scroll_margin
, window_total_lines
/ 4));
17691 this_scroll_margin
*= frame_line_height
;
17692 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
17694 if ((w
->cursor
.y
< this_scroll_margin
17695 && CHARPOS (start
) > BEGV
)
17696 /* Old redisplay didn't take scroll margin into account at the bottom,
17697 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
17698 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
17699 ? cursor_height
+ this_scroll_margin
17700 : 1)) > it
.last_visible_y
)
17702 w
->cursor
.vpos
= -1;
17703 clear_glyph_matrix (w
->desired_matrix
);
17708 /* Scroll the display. Do it before changing the current matrix so
17709 that xterm.c doesn't get confused about where the cursor glyph is
17711 if (dy
&& run
.height
)
17715 if (FRAME_WINDOW_P (f
))
17717 FRAME_RIF (f
)->update_window_begin_hook (w
);
17718 FRAME_RIF (f
)->clear_window_mouse_face (w
);
17719 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
17720 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
17724 /* Terminal frame. In this case, dvpos gives the number of
17725 lines to scroll by; dvpos < 0 means scroll up. */
17727 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
17728 int from
= WINDOW_TOP_EDGE_LINE (w
) + from_vpos
;
17729 int end
= (WINDOW_TOP_EDGE_LINE (w
)
17730 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
17731 + window_internal_height (w
));
17733 #if defined (HAVE_GPM) || defined (MSDOS)
17734 x_clear_window_mouse_face (w
);
17736 /* Perform the operation on the screen. */
17739 /* Scroll last_unchanged_at_beg_row to the end of the
17740 window down dvpos lines. */
17741 set_terminal_window (f
, end
);
17743 /* On dumb terminals delete dvpos lines at the end
17744 before inserting dvpos empty lines. */
17745 if (!FRAME_SCROLL_REGION_OK (f
))
17746 ins_del_lines (f
, end
- dvpos
, -dvpos
);
17748 /* Insert dvpos empty lines in front of
17749 last_unchanged_at_beg_row. */
17750 ins_del_lines (f
, from
, dvpos
);
17752 else if (dvpos
< 0)
17754 /* Scroll up last_unchanged_at_beg_vpos to the end of
17755 the window to last_unchanged_at_beg_vpos - |dvpos|. */
17756 set_terminal_window (f
, end
);
17758 /* Delete dvpos lines in front of
17759 last_unchanged_at_beg_vpos. ins_del_lines will set
17760 the cursor to the given vpos and emit |dvpos| delete
17762 ins_del_lines (f
, from
+ dvpos
, dvpos
);
17764 /* On a dumb terminal insert dvpos empty lines at the
17766 if (!FRAME_SCROLL_REGION_OK (f
))
17767 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
17770 set_terminal_window (f
, 0);
17776 /* Shift reused rows of the current matrix to the right position.
17777 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
17779 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17780 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
17783 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
17784 bottom_vpos
, dvpos
);
17785 clear_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
17788 else if (dvpos
> 0)
17790 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
17791 bottom_vpos
, dvpos
);
17792 clear_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
17793 first_unchanged_at_end_vpos
+ dvpos
);
17796 /* For frame-based redisplay, make sure that current frame and window
17797 matrix are in sync with respect to glyph memory. */
17798 if (!FRAME_WINDOW_P (f
))
17799 sync_frame_with_window_matrix_rows (w
);
17801 /* Adjust buffer positions in reused rows. */
17802 if (delta
|| delta_bytes
)
17803 increment_matrix_positions (current_matrix
,
17804 first_unchanged_at_end_vpos
+ dvpos
,
17805 bottom_vpos
, delta
, delta_bytes
);
17807 /* Adjust Y positions. */
17809 shift_glyph_matrix (w
, current_matrix
,
17810 first_unchanged_at_end_vpos
+ dvpos
,
17813 if (first_unchanged_at_end_row
)
17815 first_unchanged_at_end_row
+= dvpos
;
17816 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
17817 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
17818 first_unchanged_at_end_row
= NULL
;
17821 /* If scrolling up, there may be some lines to display at the end of
17823 last_text_row_at_end
= NULL
;
17826 /* Scrolling up can leave for example a partially visible line
17827 at the end of the window to be redisplayed. */
17828 /* Set last_row to the glyph row in the current matrix where the
17829 window end line is found. It has been moved up or down in
17830 the matrix by dvpos. */
17831 int last_vpos
= w
->window_end_vpos
+ dvpos
;
17832 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
17834 /* If last_row is the window end line, it should display text. */
17835 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_row
));
17837 /* If window end line was partially visible before, begin
17838 displaying at that line. Otherwise begin displaying with the
17839 line following it. */
17840 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
17842 init_to_row_start (&it
, w
, last_row
);
17843 it
.vpos
= last_vpos
;
17844 it
.current_y
= last_row
->y
;
17848 init_to_row_end (&it
, w
, last_row
);
17849 it
.vpos
= 1 + last_vpos
;
17850 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
17854 /* We may start in a continuation line. If so, we have to
17855 get the right continuation_lines_width and current_x. */
17856 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
17857 it
.hpos
= it
.current_x
= 0;
17859 /* Display the rest of the lines at the window end. */
17860 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17861 while (it
.current_y
< it
.last_visible_y
17862 && !fonts_changed_p
)
17864 /* Is it always sure that the display agrees with lines in
17865 the current matrix? I don't think so, so we mark rows
17866 displayed invalid in the current matrix by setting their
17867 enabled_p flag to zero. */
17868 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
17869 if (display_line (&it
))
17870 last_text_row_at_end
= it
.glyph_row
- 1;
17874 /* Update window_end_pos and window_end_vpos. */
17875 if (first_unchanged_at_end_row
&& !last_text_row_at_end
)
17877 /* Window end line if one of the preserved rows from the current
17878 matrix. Set row to the last row displaying text in current
17879 matrix starting at first_unchanged_at_end_row, after
17881 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
17882 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
17883 first_unchanged_at_end_row
);
17884 eassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
17885 adjust_window_ends (w
, row
, 1);
17886 eassert (w
->window_end_bytepos
>= 0);
17887 IF_DEBUG (debug_method_add (w
, "A"));
17889 else if (last_text_row_at_end
)
17891 adjust_window_ends (w
, last_text_row_at_end
, 0);
17892 eassert (w
->window_end_bytepos
>= 0);
17893 IF_DEBUG (debug_method_add (w
, "B"));
17895 else if (last_text_row
)
17897 /* We have displayed either to the end of the window or at the
17898 end of the window, i.e. the last row with text is to be found
17899 in the desired matrix. */
17900 adjust_window_ends (w
, last_text_row
, 0);
17901 eassert (w
->window_end_bytepos
>= 0);
17903 else if (first_unchanged_at_end_row
== NULL
17904 && last_text_row
== NULL
17905 && last_text_row_at_end
== NULL
)
17907 /* Displayed to end of window, but no line containing text was
17908 displayed. Lines were deleted at the end of the window. */
17909 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
17910 int vpos
= w
->window_end_vpos
;
17911 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
17912 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
17915 row
== NULL
&& vpos
>= first_vpos
;
17916 --vpos
, --current_row
, --desired_row
)
17918 if (desired_row
->enabled_p
)
17920 if (MATRIX_ROW_DISPLAYS_TEXT_P (desired_row
))
17923 else if (MATRIX_ROW_DISPLAYS_TEXT_P (current_row
))
17927 eassert (row
!= NULL
);
17928 w
->window_end_vpos
= vpos
+ 1;
17929 w
->window_end_pos
= Z
- MATRIX_ROW_END_CHARPOS (row
);
17930 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17931 eassert (w
->window_end_bytepos
>= 0);
17932 IF_DEBUG (debug_method_add (w
, "C"));
17937 IF_DEBUG (debug_end_pos
= w
->window_end_pos
;
17938 debug_end_vpos
= w
->window_end_vpos
);
17940 /* Record that display has not been completed. */
17941 w
->window_end_valid
= 0;
17942 w
->desired_matrix
->no_scrolling_p
= 1;
17950 /***********************************************************************
17951 More debugging support
17952 ***********************************************************************/
17956 void dump_glyph_row (struct glyph_row
*, int, int) EXTERNALLY_VISIBLE
;
17957 void dump_glyph_matrix (struct glyph_matrix
*, int) EXTERNALLY_VISIBLE
;
17958 void dump_glyph (struct glyph_row
*, struct glyph
*, int) EXTERNALLY_VISIBLE
;
17961 /* Dump the contents of glyph matrix MATRIX on stderr.
17963 GLYPHS 0 means don't show glyph contents.
17964 GLYPHS 1 means show glyphs in short form
17965 GLYPHS > 1 means show glyphs in long form. */
17968 dump_glyph_matrix (struct glyph_matrix
*matrix
, int glyphs
)
17971 for (i
= 0; i
< matrix
->nrows
; ++i
)
17972 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
17976 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
17977 the glyph row and area where the glyph comes from. */
17980 dump_glyph (struct glyph_row
*row
, struct glyph
*glyph
, int area
)
17982 if (glyph
->type
== CHAR_GLYPH
17983 || glyph
->type
== GLYPHLESS_GLYPH
)
17986 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
17987 glyph
- row
->glyphs
[TEXT_AREA
],
17988 (glyph
->type
== CHAR_GLYPH
17992 (BUFFERP (glyph
->object
)
17994 : (STRINGP (glyph
->object
)
17996 : (INTEGERP (glyph
->object
)
17999 glyph
->pixel_width
,
18001 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
18005 glyph
->left_box_line_p
,
18006 glyph
->right_box_line_p
);
18008 else if (glyph
->type
== STRETCH_GLYPH
)
18011 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
18012 glyph
- row
->glyphs
[TEXT_AREA
],
18015 (BUFFERP (glyph
->object
)
18017 : (STRINGP (glyph
->object
)
18019 : (INTEGERP (glyph
->object
)
18022 glyph
->pixel_width
,
18026 glyph
->left_box_line_p
,
18027 glyph
->right_box_line_p
);
18029 else if (glyph
->type
== IMAGE_GLYPH
)
18032 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
18033 glyph
- row
->glyphs
[TEXT_AREA
],
18036 (BUFFERP (glyph
->object
)
18038 : (STRINGP (glyph
->object
)
18040 : (INTEGERP (glyph
->object
)
18043 glyph
->pixel_width
,
18047 glyph
->left_box_line_p
,
18048 glyph
->right_box_line_p
);
18050 else if (glyph
->type
== COMPOSITE_GLYPH
)
18053 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x",
18054 glyph
- row
->glyphs
[TEXT_AREA
],
18057 (BUFFERP (glyph
->object
)
18059 : (STRINGP (glyph
->object
)
18061 : (INTEGERP (glyph
->object
)
18064 glyph
->pixel_width
,
18066 if (glyph
->u
.cmp
.automatic
)
18069 glyph
->slice
.cmp
.from
, glyph
->slice
.cmp
.to
);
18070 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
18072 glyph
->left_box_line_p
,
18073 glyph
->right_box_line_p
);
18075 #ifdef HAVE_XWIDGETS
18076 else if (glyph
->type
== XWIDGET_GLYPH
)
18079 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
18080 glyph
- row
->glyphs
[TEXT_AREA
],
18083 (BUFFERP (glyph
->object
)
18085 : (STRINGP (glyph
->object
)
18088 glyph
->pixel_width
,
18092 glyph
->left_box_line_p
,
18093 glyph
->right_box_line_p
);
18095 // printf("dump xwidget glyph\n");
18101 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
18102 GLYPHS 0 means don't show glyph contents.
18103 GLYPHS 1 means show glyphs in short form
18104 GLYPHS > 1 means show glyphs in long form. */
18107 dump_glyph_row (struct glyph_row
*row
, int vpos
, int glyphs
)
18111 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
18112 fprintf (stderr
, "==============================================================================\n");
18114 fprintf (stderr
, "%3d %9"pI
"d %9"pI
"d %4d %1.1d%1.1d%1.1d%1.1d\
18115 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
18117 MATRIX_ROW_START_CHARPOS (row
),
18118 MATRIX_ROW_END_CHARPOS (row
),
18119 row
->used
[TEXT_AREA
],
18120 row
->contains_overlapping_glyphs_p
,
18122 row
->truncated_on_left_p
,
18123 row
->truncated_on_right_p
,
18125 MATRIX_ROW_CONTINUATION_LINE_P (row
),
18126 MATRIX_ROW_DISPLAYS_TEXT_P (row
),
18129 row
->ends_in_middle_of_char_p
,
18130 row
->starts_in_middle_of_char_p
,
18136 row
->visible_height
,
18139 /* The next 3 lines should align to "Start" in the header. */
18140 fprintf (stderr
, " %9"pD
"d %9"pD
"d\t%5d\n", row
->start
.overlay_string_index
,
18141 row
->end
.overlay_string_index
,
18142 row
->continuation_lines_width
);
18143 fprintf (stderr
, " %9"pI
"d %9"pI
"d\n",
18144 CHARPOS (row
->start
.string_pos
),
18145 CHARPOS (row
->end
.string_pos
));
18146 fprintf (stderr
, " %9d %9d\n", row
->start
.dpvec_index
,
18147 row
->end
.dpvec_index
);
18154 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18156 struct glyph
*glyph
= row
->glyphs
[area
];
18157 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
18159 /* Glyph for a line end in text. */
18160 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
18163 if (glyph
< glyph_end
)
18164 fprintf (stderr
, " Glyph# Type Pos O W Code C Face LR\n");
18166 for (; glyph
< glyph_end
; ++glyph
)
18167 dump_glyph (row
, glyph
, area
);
18170 else if (glyphs
== 1)
18174 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18176 char *s
= alloca (row
->used
[area
] + 4);
18179 for (i
= 0; i
< row
->used
[area
]; ++i
)
18181 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
18182 if (i
== row
->used
[area
] - 1
18183 && area
== TEXT_AREA
18184 && INTEGERP (glyph
->object
)
18185 && glyph
->type
== CHAR_GLYPH
18186 && glyph
->u
.ch
== ' ')
18188 strcpy (&s
[i
], "[\\n]");
18191 else if (glyph
->type
== CHAR_GLYPH
18192 && glyph
->u
.ch
< 0x80
18193 && glyph
->u
.ch
>= ' ')
18194 s
[i
] = glyph
->u
.ch
;
18200 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
18206 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
18207 Sdump_glyph_matrix
, 0, 1, "p",
18208 doc
: /* Dump the current matrix of the selected window to stderr.
18209 Shows contents of glyph row structures. With non-nil
18210 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
18211 glyphs in short form, otherwise show glyphs in long form. */)
18212 (Lisp_Object glyphs
)
18214 struct window
*w
= XWINDOW (selected_window
);
18215 struct buffer
*buffer
= XBUFFER (w
->contents
);
18217 fprintf (stderr
, "PT = %"pI
"d, BEGV = %"pI
"d. ZV = %"pI
"d\n",
18218 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
18219 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
18220 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
18221 fprintf (stderr
, "=============================================\n");
18222 dump_glyph_matrix (w
->current_matrix
,
18223 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 0);
18228 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
18229 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
18232 struct frame
*f
= XFRAME (selected_frame
);
18233 dump_glyph_matrix (f
->current_matrix
, 1);
18238 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
18239 doc
: /* Dump glyph row ROW to stderr.
18240 GLYPH 0 means don't dump glyphs.
18241 GLYPH 1 means dump glyphs in short form.
18242 GLYPH > 1 or omitted means dump glyphs in long form. */)
18243 (Lisp_Object row
, Lisp_Object glyphs
)
18245 struct glyph_matrix
*matrix
;
18248 CHECK_NUMBER (row
);
18249 matrix
= XWINDOW (selected_window
)->current_matrix
;
18251 if (vpos
>= 0 && vpos
< matrix
->nrows
)
18252 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
18254 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18259 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
18260 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
18261 GLYPH 0 means don't dump glyphs.
18262 GLYPH 1 means dump glyphs in short form.
18263 GLYPH > 1 or omitted means dump glyphs in long form. */)
18264 (Lisp_Object row
, Lisp_Object glyphs
)
18266 struct frame
*sf
= SELECTED_FRAME ();
18267 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
18270 CHECK_NUMBER (row
);
18272 if (vpos
>= 0 && vpos
< m
->nrows
)
18273 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
18274 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18279 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
18280 doc
: /* Toggle tracing of redisplay.
18281 With ARG, turn tracing on if and only if ARG is positive. */)
18285 trace_redisplay_p
= !trace_redisplay_p
;
18288 arg
= Fprefix_numeric_value (arg
);
18289 trace_redisplay_p
= XINT (arg
) > 0;
18296 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
18297 doc
: /* Like `format', but print result to stderr.
18298 usage: (trace-to-stderr STRING &rest OBJECTS) */)
18299 (ptrdiff_t nargs
, Lisp_Object
*args
)
18301 Lisp_Object s
= Fformat (nargs
, args
);
18302 fprintf (stderr
, "%s", SDATA (s
));
18306 #endif /* GLYPH_DEBUG */
18310 /***********************************************************************
18311 Building Desired Matrix Rows
18312 ***********************************************************************/
18314 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
18315 Used for non-window-redisplay windows, and for windows w/o left fringe. */
18317 static struct glyph_row
*
18318 get_overlay_arrow_glyph_row (struct window
*w
, Lisp_Object overlay_arrow_string
)
18320 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18321 struct buffer
*buffer
= XBUFFER (w
->contents
);
18322 struct buffer
*old
= current_buffer
;
18323 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
18324 int arrow_len
= SCHARS (overlay_arrow_string
);
18325 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
18326 const unsigned char *p
;
18329 int n_glyphs_before
;
18331 set_buffer_temp (buffer
);
18332 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
18333 it
.glyph_row
->used
[TEXT_AREA
] = 0;
18334 SET_TEXT_POS (it
.position
, 0, 0);
18336 multibyte_p
= !NILP (BVAR (buffer
, enable_multibyte_characters
));
18338 while (p
< arrow_end
)
18340 Lisp_Object face
, ilisp
;
18342 /* Get the next character. */
18344 it
.c
= it
.char_to_display
= string_char_and_length (p
, &it
.len
);
18347 it
.c
= it
.char_to_display
= *p
, it
.len
= 1;
18348 if (! ASCII_CHAR_P (it
.c
))
18349 it
.char_to_display
= BYTE8_TO_CHAR (it
.c
);
18353 /* Get its face. */
18354 ilisp
= make_number (p
- arrow_string
);
18355 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
18356 it
.face_id
= compute_char_face (f
, it
.char_to_display
, face
);
18358 /* Compute its width, get its glyphs. */
18359 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
18360 SET_TEXT_POS (it
.position
, -1, -1);
18361 PRODUCE_GLYPHS (&it
);
18363 /* If this character doesn't fit any more in the line, we have
18364 to remove some glyphs. */
18365 if (it
.current_x
> it
.last_visible_x
)
18367 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
18372 set_buffer_temp (old
);
18373 return it
.glyph_row
;
18377 /* Insert truncation glyphs at the start of IT->glyph_row. Which
18378 glyphs to insert is determined by produce_special_glyphs. */
18381 insert_left_trunc_glyphs (struct it
*it
)
18383 struct it truncate_it
;
18384 struct glyph
*from
, *end
, *to
, *toend
;
18386 eassert (!FRAME_WINDOW_P (it
->f
)
18387 || (!it
->glyph_row
->reversed_p
18388 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0)
18389 || (it
->glyph_row
->reversed_p
18390 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0));
18392 /* Get the truncation glyphs. */
18394 truncate_it
.current_x
= 0;
18395 truncate_it
.face_id
= DEFAULT_FACE_ID
;
18396 truncate_it
.glyph_row
= &scratch_glyph_row
;
18397 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
18398 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
18399 truncate_it
.object
= make_number (0);
18400 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
18402 /* Overwrite glyphs from IT with truncation glyphs. */
18403 if (!it
->glyph_row
->reversed_p
)
18405 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
18407 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18408 end
= from
+ tused
;
18409 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18410 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
18411 if (FRAME_WINDOW_P (it
->f
))
18413 /* On GUI frames, when variable-size fonts are displayed,
18414 the truncation glyphs may need more pixels than the row's
18415 glyphs they overwrite. We overwrite more glyphs to free
18416 enough screen real estate, and enlarge the stretch glyph
18417 on the right (see display_line), if there is one, to
18418 preserve the screen position of the truncation glyphs on
18421 struct glyph
*g
= to
;
18424 /* The first glyph could be partially visible, in which case
18425 it->glyph_row->x will be negative. But we want the left
18426 truncation glyphs to be aligned at the left margin of the
18427 window, so we override the x coordinate at which the row
18429 it
->glyph_row
->x
= 0;
18430 while (g
< toend
&& w
< it
->truncation_pixel_width
)
18432 w
+= g
->pixel_width
;
18435 if (g
- to
- tused
> 0)
18437 memmove (to
+ tused
, g
, (toend
- g
) * sizeof(*g
));
18438 it
->glyph_row
->used
[TEXT_AREA
] -= g
- to
- tused
;
18440 used
= it
->glyph_row
->used
[TEXT_AREA
];
18441 if (it
->glyph_row
->truncated_on_right_p
18442 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0
18443 && it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].type
18446 int extra
= w
- it
->truncation_pixel_width
;
18448 it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].pixel_width
+= extra
;
18455 /* There may be padding glyphs left over. Overwrite them too. */
18456 if (!FRAME_WINDOW_P (it
->f
))
18458 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
18460 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18467 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
18471 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
18473 /* In R2L rows, overwrite the last (rightmost) glyphs, and do
18474 that back to front. */
18475 end
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18476 from
= end
+ truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18477 toend
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18478 to
= toend
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18479 if (FRAME_WINDOW_P (it
->f
))
18482 struct glyph
*g
= to
;
18484 while (g
>= toend
&& w
< it
->truncation_pixel_width
)
18486 w
+= g
->pixel_width
;
18489 if (to
- g
- tused
> 0)
18491 if (it
->glyph_row
->truncated_on_right_p
18492 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0
18493 && it
->glyph_row
->glyphs
[TEXT_AREA
][1].type
== STRETCH_GLYPH
)
18495 int extra
= w
- it
->truncation_pixel_width
;
18497 it
->glyph_row
->glyphs
[TEXT_AREA
][1].pixel_width
+= extra
;
18501 while (from
>= end
&& to
>= toend
)
18503 if (!FRAME_WINDOW_P (it
->f
))
18505 while (to
>= toend
&& CHAR_GLYPH_PADDING_P (*to
))
18508 truncate_it
.glyph_row
->glyphs
[TEXT_AREA
]
18509 + truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18510 while (from
>= end
&& to
>= toend
)
18516 /* Need to free some room before prepending additional
18518 int move_by
= from
- end
+ 1;
18519 struct glyph
*g0
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18520 struct glyph
*g
= g0
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18522 for ( ; g
>= g0
; g
--)
18524 while (from
>= end
)
18526 it
->glyph_row
->used
[TEXT_AREA
] += move_by
;
18531 /* Compute the hash code for ROW. */
18533 row_hash (struct glyph_row
*row
)
18536 unsigned hashval
= 0;
18538 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18539 for (k
= 0; k
< row
->used
[area
]; ++k
)
18540 hashval
= ((((hashval
<< 4) + (hashval
>> 24)) & 0x0fffffff)
18541 + row
->glyphs
[area
][k
].u
.val
18542 + row
->glyphs
[area
][k
].face_id
18543 + row
->glyphs
[area
][k
].padding_p
18544 + (row
->glyphs
[area
][k
].type
<< 2));
18549 /* Compute the pixel height and width of IT->glyph_row.
18551 Most of the time, ascent and height of a display line will be equal
18552 to the max_ascent and max_height values of the display iterator
18553 structure. This is not the case if
18555 1. We hit ZV without displaying anything. In this case, max_ascent
18556 and max_height will be zero.
18558 2. We have some glyphs that don't contribute to the line height.
18559 (The glyph row flag contributes_to_line_height_p is for future
18560 pixmap extensions).
18562 The first case is easily covered by using default values because in
18563 these cases, the line height does not really matter, except that it
18564 must not be zero. */
18567 compute_line_metrics (struct it
*it
)
18569 struct glyph_row
*row
= it
->glyph_row
;
18571 if (FRAME_WINDOW_P (it
->f
))
18573 int i
, min_y
, max_y
;
18575 /* The line may consist of one space only, that was added to
18576 place the cursor on it. If so, the row's height hasn't been
18578 if (row
->height
== 0)
18580 if (it
->max_ascent
+ it
->max_descent
== 0)
18581 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
18582 row
->ascent
= it
->max_ascent
;
18583 row
->height
= it
->max_ascent
+ it
->max_descent
;
18584 row
->phys_ascent
= it
->max_phys_ascent
;
18585 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18586 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18589 /* Compute the width of this line. */
18590 row
->pixel_width
= row
->x
;
18591 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
18592 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
18594 eassert (row
->pixel_width
>= 0);
18595 eassert (row
->ascent
>= 0 && row
->height
> 0);
18597 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
18598 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
18600 /* If first line's physical ascent is larger than its logical
18601 ascent, use the physical ascent, and make the row taller.
18602 This makes accented characters fully visible. */
18603 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
18604 && row
->phys_ascent
> row
->ascent
)
18606 row
->height
+= row
->phys_ascent
- row
->ascent
;
18607 row
->ascent
= row
->phys_ascent
;
18610 /* Compute how much of the line is visible. */
18611 row
->visible_height
= row
->height
;
18613 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
18614 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
18616 if (row
->y
< min_y
)
18617 row
->visible_height
-= min_y
- row
->y
;
18618 if (row
->y
+ row
->height
> max_y
)
18619 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
18623 row
->pixel_width
= row
->used
[TEXT_AREA
];
18624 if (row
->continued_p
)
18625 row
->pixel_width
-= it
->continuation_pixel_width
;
18626 else if (row
->truncated_on_right_p
)
18627 row
->pixel_width
-= it
->truncation_pixel_width
;
18628 row
->ascent
= row
->phys_ascent
= 0;
18629 row
->height
= row
->phys_height
= row
->visible_height
= 1;
18630 row
->extra_line_spacing
= 0;
18633 /* Compute a hash code for this row. */
18634 row
->hash
= row_hash (row
);
18636 it
->max_ascent
= it
->max_descent
= 0;
18637 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
18641 /* Append one space to the glyph row of iterator IT if doing a
18642 window-based redisplay. The space has the same face as
18643 IT->face_id. Value is non-zero if a space was added.
18645 This function is called to make sure that there is always one glyph
18646 at the end of a glyph row that the cursor can be set on under
18647 window-systems. (If there weren't such a glyph we would not know
18648 how wide and tall a box cursor should be displayed).
18650 At the same time this space let's a nicely handle clearing to the
18651 end of the line if the row ends in italic text. */
18654 append_space_for_newline (struct it
*it
, int default_face_p
)
18656 if (FRAME_WINDOW_P (it
->f
))
18658 int n
= it
->glyph_row
->used
[TEXT_AREA
];
18660 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
18661 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
18663 /* Save some values that must not be changed.
18664 Must save IT->c and IT->len because otherwise
18665 ITERATOR_AT_END_P wouldn't work anymore after
18666 append_space_for_newline has been called. */
18667 enum display_element_type saved_what
= it
->what
;
18668 int saved_c
= it
->c
, saved_len
= it
->len
;
18669 int saved_char_to_display
= it
->char_to_display
;
18670 int saved_x
= it
->current_x
;
18671 int saved_face_id
= it
->face_id
;
18672 int saved_box_end
= it
->end_of_box_run_p
;
18673 struct text_pos saved_pos
;
18674 Lisp_Object saved_object
;
18677 saved_object
= it
->object
;
18678 saved_pos
= it
->position
;
18680 it
->what
= IT_CHARACTER
;
18681 memset (&it
->position
, 0, sizeof it
->position
);
18682 it
->object
= make_number (0);
18683 it
->c
= it
->char_to_display
= ' ';
18686 /* If the default face was remapped, be sure to use the
18687 remapped face for the appended newline. */
18688 if (default_face_p
)
18689 it
->face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
18690 else if (it
->face_before_selective_p
)
18691 it
->face_id
= it
->saved_face_id
;
18692 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18693 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
18694 /* In R2L rows, we will prepend a stretch glyph that will
18695 have the end_of_box_run_p flag set for it, so there's no
18696 need for the appended newline glyph to have that flag
18698 if (it
->glyph_row
->reversed_p
18699 /* But if the appended newline glyph goes all the way to
18700 the end of the row, there will be no stretch glyph,
18701 so leave the box flag set. */
18702 && saved_x
+ FRAME_COLUMN_WIDTH (it
->f
) < it
->last_visible_x
)
18703 it
->end_of_box_run_p
= 0;
18705 PRODUCE_GLYPHS (it
);
18707 it
->override_ascent
= -1;
18708 it
->constrain_row_ascent_descent_p
= 0;
18709 it
->current_x
= saved_x
;
18710 it
->object
= saved_object
;
18711 it
->position
= saved_pos
;
18712 it
->what
= saved_what
;
18713 it
->face_id
= saved_face_id
;
18714 it
->len
= saved_len
;
18716 it
->char_to_display
= saved_char_to_display
;
18717 it
->end_of_box_run_p
= saved_box_end
;
18726 /* Extend the face of the last glyph in the text area of IT->glyph_row
18727 to the end of the display line. Called from display_line. If the
18728 glyph row is empty, add a space glyph to it so that we know the
18729 face to draw. Set the glyph row flag fill_line_p. If the glyph
18730 row is R2L, prepend a stretch glyph to cover the empty space to the
18731 left of the leftmost glyph. */
18734 extend_face_to_end_of_line (struct it
*it
)
18736 struct face
*face
, *default_face
;
18737 struct frame
*f
= it
->f
;
18739 /* If line is already filled, do nothing. Non window-system frames
18740 get a grace of one more ``pixel'' because their characters are
18741 1-``pixel'' wide, so they hit the equality too early. This grace
18742 is needed only for R2L rows that are not continued, to produce
18743 one extra blank where we could display the cursor. */
18744 if (it
->current_x
>= it
->last_visible_x
18745 + (!FRAME_WINDOW_P (f
)
18746 && it
->glyph_row
->reversed_p
18747 && !it
->glyph_row
->continued_p
))
18750 /* The default face, possibly remapped. */
18751 default_face
= FACE_FROM_ID (f
, lookup_basic_face (f
, DEFAULT_FACE_ID
));
18753 /* Face extension extends the background and box of IT->face_id
18754 to the end of the line. If the background equals the background
18755 of the frame, we don't have to do anything. */
18756 if (it
->face_before_selective_p
)
18757 face
= FACE_FROM_ID (f
, it
->saved_face_id
);
18759 face
= FACE_FROM_ID (f
, it
->face_id
);
18761 if (FRAME_WINDOW_P (f
)
18762 && MATRIX_ROW_DISPLAYS_TEXT_P (it
->glyph_row
)
18763 && face
->box
== FACE_NO_BOX
18764 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
18766 && !it
->glyph_row
->reversed_p
)
18769 /* Set the glyph row flag indicating that the face of the last glyph
18770 in the text area has to be drawn to the end of the text area. */
18771 it
->glyph_row
->fill_line_p
= 1;
18773 /* If current character of IT is not ASCII, make sure we have the
18774 ASCII face. This will be automatically undone the next time
18775 get_next_display_element returns a multibyte character. Note
18776 that the character will always be single byte in unibyte
18778 if (!ASCII_CHAR_P (it
->c
))
18780 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
18783 if (FRAME_WINDOW_P (f
))
18785 /* If the row is empty, add a space with the current face of IT,
18786 so that we know which face to draw. */
18787 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
18789 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
18790 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= face
->id
;
18791 it
->glyph_row
->used
[TEXT_AREA
] = 1;
18793 #ifdef HAVE_WINDOW_SYSTEM
18794 if (it
->glyph_row
->reversed_p
)
18796 /* Prepend a stretch glyph to the row, such that the
18797 rightmost glyph will be drawn flushed all the way to the
18798 right margin of the window. The stretch glyph that will
18799 occupy the empty space, if any, to the left of the
18801 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (f
);
18802 struct glyph
*row_start
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18803 struct glyph
*row_end
= row_start
+ it
->glyph_row
->used
[TEXT_AREA
];
18805 int row_width
, stretch_ascent
, stretch_width
;
18806 struct text_pos saved_pos
;
18807 int saved_face_id
, saved_avoid_cursor
, saved_box_start
;
18809 for (row_width
= 0, g
= row_start
; g
< row_end
; g
++)
18810 row_width
+= g
->pixel_width
;
18811 stretch_width
= window_box_width (it
->w
, TEXT_AREA
) - row_width
;
18812 if (stretch_width
> 0)
18815 (((it
->ascent
+ it
->descent
)
18816 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
18817 saved_pos
= it
->position
;
18818 memset (&it
->position
, 0, sizeof it
->position
);
18819 saved_avoid_cursor
= it
->avoid_cursor_p
;
18820 it
->avoid_cursor_p
= 1;
18821 saved_face_id
= it
->face_id
;
18822 saved_box_start
= it
->start_of_box_run_p
;
18823 /* The last row's stretch glyph should get the default
18824 face, to avoid painting the rest of the window with
18825 the region face, if the region ends at ZV. */
18826 if (it
->glyph_row
->ends_at_zv_p
)
18827 it
->face_id
= default_face
->id
;
18829 it
->face_id
= face
->id
;
18830 it
->start_of_box_run_p
= 0;
18831 append_stretch_glyph (it
, make_number (0), stretch_width
,
18832 it
->ascent
+ it
->descent
, stretch_ascent
);
18833 it
->position
= saved_pos
;
18834 it
->avoid_cursor_p
= saved_avoid_cursor
;
18835 it
->face_id
= saved_face_id
;
18836 it
->start_of_box_run_p
= saved_box_start
;
18839 #endif /* HAVE_WINDOW_SYSTEM */
18843 /* Save some values that must not be changed. */
18844 int saved_x
= it
->current_x
;
18845 struct text_pos saved_pos
;
18846 Lisp_Object saved_object
;
18847 enum display_element_type saved_what
= it
->what
;
18848 int saved_face_id
= it
->face_id
;
18850 saved_object
= it
->object
;
18851 saved_pos
= it
->position
;
18853 it
->what
= IT_CHARACTER
;
18854 memset (&it
->position
, 0, sizeof it
->position
);
18855 it
->object
= make_number (0);
18856 it
->c
= it
->char_to_display
= ' ';
18858 /* The last row's blank glyphs should get the default face, to
18859 avoid painting the rest of the window with the region face,
18860 if the region ends at ZV. */
18861 if (it
->glyph_row
->ends_at_zv_p
)
18862 it
->face_id
= default_face
->id
;
18864 it
->face_id
= face
->id
;
18866 PRODUCE_GLYPHS (it
);
18868 while (it
->current_x
<= it
->last_visible_x
)
18869 PRODUCE_GLYPHS (it
);
18871 /* Don't count these blanks really. It would let us insert a left
18872 truncation glyph below and make us set the cursor on them, maybe. */
18873 it
->current_x
= saved_x
;
18874 it
->object
= saved_object
;
18875 it
->position
= saved_pos
;
18876 it
->what
= saved_what
;
18877 it
->face_id
= saved_face_id
;
18882 /* Value is non-zero if text starting at CHARPOS in current_buffer is
18883 trailing whitespace. */
18886 trailing_whitespace_p (ptrdiff_t charpos
)
18888 ptrdiff_t bytepos
= CHAR_TO_BYTE (charpos
);
18891 while (bytepos
< ZV_BYTE
18892 && (c
= FETCH_CHAR (bytepos
),
18893 c
== ' ' || c
== '\t'))
18896 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
18898 if (bytepos
!= PT_BYTE
)
18905 /* Highlight trailing whitespace, if any, in ROW. */
18908 highlight_trailing_whitespace (struct frame
*f
, struct glyph_row
*row
)
18910 int used
= row
->used
[TEXT_AREA
];
18914 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
18915 struct glyph
*glyph
= start
+ used
- 1;
18917 if (row
->reversed_p
)
18919 /* Right-to-left rows need to be processed in the opposite
18920 direction, so swap the edge pointers. */
18922 start
= row
->glyphs
[TEXT_AREA
] + used
- 1;
18925 /* Skip over glyphs inserted to display the cursor at the
18926 end of a line, for extending the face of the last glyph
18927 to the end of the line on terminals, and for truncation
18928 and continuation glyphs. */
18929 if (!row
->reversed_p
)
18931 while (glyph
>= start
18932 && glyph
->type
== CHAR_GLYPH
18933 && INTEGERP (glyph
->object
))
18938 while (glyph
<= start
18939 && glyph
->type
== CHAR_GLYPH
18940 && INTEGERP (glyph
->object
))
18944 /* If last glyph is a space or stretch, and it's trailing
18945 whitespace, set the face of all trailing whitespace glyphs in
18946 IT->glyph_row to `trailing-whitespace'. */
18947 if ((row
->reversed_p
? glyph
<= start
: glyph
>= start
)
18948 && BUFFERP (glyph
->object
)
18949 && (glyph
->type
== STRETCH_GLYPH
18950 || (glyph
->type
== CHAR_GLYPH
18951 && glyph
->u
.ch
== ' '))
18952 && trailing_whitespace_p (glyph
->charpos
))
18954 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
18958 if (!row
->reversed_p
)
18960 while (glyph
>= start
18961 && BUFFERP (glyph
->object
)
18962 && (glyph
->type
== STRETCH_GLYPH
18963 || (glyph
->type
== CHAR_GLYPH
18964 && glyph
->u
.ch
== ' ')))
18965 (glyph
--)->face_id
= face_id
;
18969 while (glyph
<= start
18970 && BUFFERP (glyph
->object
)
18971 && (glyph
->type
== STRETCH_GLYPH
18972 || (glyph
->type
== CHAR_GLYPH
18973 && glyph
->u
.ch
== ' ')))
18974 (glyph
++)->face_id
= face_id
;
18981 /* Value is non-zero if glyph row ROW should be
18982 considered to hold the buffer position CHARPOS. */
18985 row_for_charpos_p (struct glyph_row
*row
, ptrdiff_t charpos
)
18989 if (charpos
== CHARPOS (row
->end
.pos
)
18990 || charpos
== MATRIX_ROW_END_CHARPOS (row
))
18992 /* Suppose the row ends on a string.
18993 Unless the row is continued, that means it ends on a newline
18994 in the string. If it's anything other than a display string
18995 (e.g., a before-string from an overlay), we don't want the
18996 cursor there. (This heuristic seems to give the optimal
18997 behavior for the various types of multi-line strings.)
18998 One exception: if the string has `cursor' property on one of
18999 its characters, we _do_ want the cursor there. */
19000 if (CHARPOS (row
->end
.string_pos
) >= 0)
19002 if (row
->continued_p
)
19006 /* Check for `display' property. */
19007 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
19008 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
19009 struct glyph
*glyph
;
19012 for (glyph
= end
; glyph
>= beg
; --glyph
)
19013 if (STRINGP (glyph
->object
))
19016 = Fget_char_property (make_number (charpos
),
19020 && display_prop_string_p (prop
, glyph
->object
));
19021 /* If there's a `cursor' property on one of the
19022 string's characters, this row is a cursor row,
19023 even though this is not a display string. */
19026 Lisp_Object s
= glyph
->object
;
19028 for ( ; glyph
>= beg
&& EQ (glyph
->object
, s
); --glyph
)
19030 ptrdiff_t gpos
= glyph
->charpos
;
19032 if (!NILP (Fget_char_property (make_number (gpos
),
19044 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
19046 /* If the row ends in middle of a real character,
19047 and the line is continued, we want the cursor here.
19048 That's because CHARPOS (ROW->end.pos) would equal
19049 PT if PT is before the character. */
19050 if (!row
->ends_in_ellipsis_p
)
19051 result
= row
->continued_p
;
19053 /* If the row ends in an ellipsis, then
19054 CHARPOS (ROW->end.pos) will equal point after the
19055 invisible text. We want that position to be displayed
19056 after the ellipsis. */
19059 /* If the row ends at ZV, display the cursor at the end of that
19060 row instead of at the start of the row below. */
19061 else if (row
->ends_at_zv_p
)
19070 /* Value is non-zero if glyph row ROW should be
19071 used to hold the cursor. */
19074 cursor_row_p (struct glyph_row
*row
)
19076 return row_for_charpos_p (row
, PT
);
19081 /* Push the property PROP so that it will be rendered at the current
19082 position in IT. Return 1 if PROP was successfully pushed, 0
19083 otherwise. Called from handle_line_prefix to handle the
19084 `line-prefix' and `wrap-prefix' properties. */
19087 push_prefix_prop (struct it
*it
, Lisp_Object prop
)
19089 struct text_pos pos
=
19090 STRINGP (it
->string
) ? it
->current
.string_pos
: it
->current
.pos
;
19092 eassert (it
->method
== GET_FROM_BUFFER
19093 || it
->method
== GET_FROM_DISPLAY_VECTOR
19094 || it
->method
== GET_FROM_STRING
);
19096 /* We need to save the current buffer/string position, so it will be
19097 restored by pop_it, because iterate_out_of_display_property
19098 depends on that being set correctly, but some situations leave
19099 it->position not yet set when this function is called. */
19100 push_it (it
, &pos
);
19102 if (STRINGP (prop
))
19104 if (SCHARS (prop
) == 0)
19111 it
->string_from_prefix_prop_p
= 1;
19112 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
19113 it
->current
.overlay_string_index
= -1;
19114 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
19115 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
19116 it
->method
= GET_FROM_STRING
;
19117 it
->stop_charpos
= 0;
19119 it
->base_level_stop
= 0;
19121 /* Force paragraph direction to be that of the parent
19123 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
19124 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
19126 it
->paragraph_embedding
= L2R
;
19128 /* Set up the bidi iterator for this display string. */
19131 it
->bidi_it
.string
.lstring
= it
->string
;
19132 it
->bidi_it
.string
.s
= NULL
;
19133 it
->bidi_it
.string
.schars
= it
->end_charpos
;
19134 it
->bidi_it
.string
.bufpos
= IT_CHARPOS (*it
);
19135 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
19136 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
19137 it
->bidi_it
.w
= it
->w
;
19138 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
19141 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
19143 it
->method
= GET_FROM_STRETCH
;
19146 #ifdef HAVE_WINDOW_SYSTEM
19147 else if (IMAGEP (prop
))
19149 it
->what
= IT_IMAGE
;
19150 it
->image_id
= lookup_image (it
->f
, prop
);
19151 it
->method
= GET_FROM_IMAGE
;
19153 #endif /* HAVE_WINDOW_SYSTEM */
19156 pop_it (it
); /* bogus display property, give up */
19163 /* Return the character-property PROP at the current position in IT. */
19166 get_it_property (struct it
*it
, Lisp_Object prop
)
19168 Lisp_Object position
, object
= it
->object
;
19170 if (STRINGP (object
))
19171 position
= make_number (IT_STRING_CHARPOS (*it
));
19172 else if (BUFFERP (object
))
19174 position
= make_number (IT_CHARPOS (*it
));
19175 object
= it
->window
;
19180 return Fget_char_property (position
, prop
, object
);
19183 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
19186 handle_line_prefix (struct it
*it
)
19188 Lisp_Object prefix
;
19190 if (it
->continuation_lines_width
> 0)
19192 prefix
= get_it_property (it
, Qwrap_prefix
);
19194 prefix
= Vwrap_prefix
;
19198 prefix
= get_it_property (it
, Qline_prefix
);
19200 prefix
= Vline_prefix
;
19202 if (! NILP (prefix
) && push_prefix_prop (it
, prefix
))
19204 /* If the prefix is wider than the window, and we try to wrap
19205 it, it would acquire its own wrap prefix, and so on till the
19206 iterator stack overflows. So, don't wrap the prefix. */
19207 it
->line_wrap
= TRUNCATE
;
19208 it
->avoid_cursor_p
= 1;
19214 /* Remove N glyphs at the start of a reversed IT->glyph_row. Called
19215 only for R2L lines from display_line and display_string, when they
19216 decide that too many glyphs were produced by PRODUCE_GLYPHS, and
19217 the line/string needs to be continued on the next glyph row. */
19219 unproduce_glyphs (struct it
*it
, int n
)
19221 struct glyph
*glyph
, *end
;
19223 eassert (it
->glyph_row
);
19224 eassert (it
->glyph_row
->reversed_p
);
19225 eassert (it
->area
== TEXT_AREA
);
19226 eassert (n
<= it
->glyph_row
->used
[TEXT_AREA
]);
19228 if (n
> it
->glyph_row
->used
[TEXT_AREA
])
19229 n
= it
->glyph_row
->used
[TEXT_AREA
];
19230 glyph
= it
->glyph_row
->glyphs
[TEXT_AREA
] + n
;
19231 end
= it
->glyph_row
->glyphs
[TEXT_AREA
] + it
->glyph_row
->used
[TEXT_AREA
];
19232 for ( ; glyph
< end
; glyph
++)
19233 glyph
[-n
] = *glyph
;
19236 /* Find the positions in a bidi-reordered ROW to serve as ROW->minpos
19237 and ROW->maxpos. */
19239 find_row_edges (struct it
*it
, struct glyph_row
*row
,
19240 ptrdiff_t min_pos
, ptrdiff_t min_bpos
,
19241 ptrdiff_t max_pos
, ptrdiff_t max_bpos
)
19243 /* FIXME: Revisit this when glyph ``spilling'' in continuation
19244 lines' rows is implemented for bidi-reordered rows. */
19246 /* ROW->minpos is the value of min_pos, the minimal buffer position
19247 we have in ROW, or ROW->start.pos if that is smaller. */
19248 if (min_pos
<= ZV
&& min_pos
< row
->start
.pos
.charpos
)
19249 SET_TEXT_POS (row
->minpos
, min_pos
, min_bpos
);
19251 /* We didn't find buffer positions smaller than ROW->start, or
19252 didn't find _any_ valid buffer positions in any of the glyphs,
19253 so we must trust the iterator's computed positions. */
19254 row
->minpos
= row
->start
.pos
;
19257 max_pos
= CHARPOS (it
->current
.pos
);
19258 max_bpos
= BYTEPOS (it
->current
.pos
);
19261 /* Here are the various use-cases for ending the row, and the
19262 corresponding values for ROW->maxpos:
19264 Line ends in a newline from buffer eol_pos + 1
19265 Line is continued from buffer max_pos + 1
19266 Line is truncated on right it->current.pos
19267 Line ends in a newline from string max_pos + 1(*)
19268 (*) + 1 only when line ends in a forward scan
19269 Line is continued from string max_pos
19270 Line is continued from display vector max_pos
19271 Line is entirely from a string min_pos == max_pos
19272 Line is entirely from a display vector min_pos == max_pos
19273 Line that ends at ZV ZV
19275 If you discover other use-cases, please add them here as
19277 if (row
->ends_at_zv_p
)
19278 row
->maxpos
= it
->current
.pos
;
19279 else if (row
->used
[TEXT_AREA
])
19281 int seen_this_string
= 0;
19282 struct glyph_row
*r1
= row
- 1;
19284 /* Did we see the same display string on the previous row? */
19285 if (STRINGP (it
->object
)
19286 /* this is not the first row */
19287 && row
> it
->w
->desired_matrix
->rows
19288 /* previous row is not the header line */
19289 && !r1
->mode_line_p
19290 /* previous row also ends in a newline from a string */
19291 && r1
->ends_in_newline_from_string_p
)
19293 struct glyph
*start
, *end
;
19295 /* Search for the last glyph of the previous row that came
19296 from buffer or string. Depending on whether the row is
19297 L2R or R2L, we need to process it front to back or the
19298 other way round. */
19299 if (!r1
->reversed_p
)
19301 start
= r1
->glyphs
[TEXT_AREA
];
19302 end
= start
+ r1
->used
[TEXT_AREA
];
19303 /* Glyphs inserted by redisplay have an integer (zero)
19304 as their object. */
19306 && INTEGERP ((end
- 1)->object
)
19307 && (end
- 1)->charpos
<= 0)
19311 if (EQ ((end
- 1)->object
, it
->object
))
19312 seen_this_string
= 1;
19315 /* If all the glyphs of the previous row were inserted
19316 by redisplay, it means the previous row was
19317 produced from a single newline, which is only
19318 possible if that newline came from the same string
19319 as the one which produced this ROW. */
19320 seen_this_string
= 1;
19324 end
= r1
->glyphs
[TEXT_AREA
] - 1;
19325 start
= end
+ r1
->used
[TEXT_AREA
];
19327 && INTEGERP ((end
+ 1)->object
)
19328 && (end
+ 1)->charpos
<= 0)
19332 if (EQ ((end
+ 1)->object
, it
->object
))
19333 seen_this_string
= 1;
19336 seen_this_string
= 1;
19339 /* Take note of each display string that covers a newline only
19340 once, the first time we see it. This is for when a display
19341 string includes more than one newline in it. */
19342 if (row
->ends_in_newline_from_string_p
&& !seen_this_string
)
19344 /* If we were scanning the buffer forward when we displayed
19345 the string, we want to account for at least one buffer
19346 position that belongs to this row (position covered by
19347 the display string), so that cursor positioning will
19348 consider this row as a candidate when point is at the end
19349 of the visual line represented by this row. This is not
19350 required when scanning back, because max_pos will already
19351 have a much larger value. */
19352 if (CHARPOS (row
->end
.pos
) > max_pos
)
19353 INC_BOTH (max_pos
, max_bpos
);
19354 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19356 else if (CHARPOS (it
->eol_pos
) > 0)
19357 SET_TEXT_POS (row
->maxpos
,
19358 CHARPOS (it
->eol_pos
) + 1, BYTEPOS (it
->eol_pos
) + 1);
19359 else if (row
->continued_p
)
19361 /* If max_pos is different from IT's current position, it
19362 means IT->method does not belong to the display element
19363 at max_pos. However, it also means that the display
19364 element at max_pos was displayed in its entirety on this
19365 line, which is equivalent to saying that the next line
19366 starts at the next buffer position. */
19367 if (IT_CHARPOS (*it
) == max_pos
&& it
->method
!= GET_FROM_BUFFER
)
19368 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19371 INC_BOTH (max_pos
, max_bpos
);
19372 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19375 else if (row
->truncated_on_right_p
)
19376 /* display_line already called reseat_at_next_visible_line_start,
19377 which puts the iterator at the beginning of the next line, in
19378 the logical order. */
19379 row
->maxpos
= it
->current
.pos
;
19380 else if (max_pos
== min_pos
&& it
->method
!= GET_FROM_BUFFER
)
19381 /* A line that is entirely from a string/image/stretch... */
19382 row
->maxpos
= row
->minpos
;
19387 row
->maxpos
= it
->current
.pos
;
19390 /* Construct the glyph row IT->glyph_row in the desired matrix of
19391 IT->w from text at the current position of IT. See dispextern.h
19392 for an overview of struct it. Value is non-zero if
19393 IT->glyph_row displays text, as opposed to a line displaying ZV
19397 display_line (struct it
*it
)
19399 struct glyph_row
*row
= it
->glyph_row
;
19400 Lisp_Object overlay_arrow_string
;
19402 void *wrap_data
= NULL
;
19403 int may_wrap
= 0, wrap_x
IF_LINT (= 0);
19404 int wrap_row_used
= -1;
19405 int wrap_row_ascent
IF_LINT (= 0), wrap_row_height
IF_LINT (= 0);
19406 int wrap_row_phys_ascent
IF_LINT (= 0), wrap_row_phys_height
IF_LINT (= 0);
19407 int wrap_row_extra_line_spacing
IF_LINT (= 0);
19408 ptrdiff_t wrap_row_min_pos
IF_LINT (= 0), wrap_row_min_bpos
IF_LINT (= 0);
19409 ptrdiff_t wrap_row_max_pos
IF_LINT (= 0), wrap_row_max_bpos
IF_LINT (= 0);
19411 ptrdiff_t min_pos
= ZV
+ 1, max_pos
= 0;
19412 ptrdiff_t min_bpos
IF_LINT (= 0), max_bpos
IF_LINT (= 0);
19414 /* We always start displaying at hpos zero even if hscrolled. */
19415 eassert (it
->hpos
== 0 && it
->current_x
== 0);
19417 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
19418 >= it
->w
->desired_matrix
->nrows
)
19420 it
->w
->nrows_scale_factor
++;
19421 fonts_changed_p
= 1;
19425 /* Is IT->w showing the region? */
19426 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? it
->region_beg_charpos
: 0;
19428 /* Clear the result glyph row and enable it. */
19429 prepare_desired_row (row
);
19431 row
->y
= it
->current_y
;
19432 row
->start
= it
->start
;
19433 row
->continuation_lines_width
= it
->continuation_lines_width
;
19434 row
->displays_text_p
= 1;
19435 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
19436 it
->starts_in_middle_of_char_p
= 0;
19438 /* Arrange the overlays nicely for our purposes. Usually, we call
19439 display_line on only one line at a time, in which case this
19440 can't really hurt too much, or we call it on lines which appear
19441 one after another in the buffer, in which case all calls to
19442 recenter_overlay_lists but the first will be pretty cheap. */
19443 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
19445 /* Move over display elements that are not visible because we are
19446 hscrolled. This may stop at an x-position < IT->first_visible_x
19447 if the first glyph is partially visible or if we hit a line end. */
19448 if (it
->current_x
< it
->first_visible_x
)
19450 enum move_it_result move_result
;
19452 this_line_min_pos
= row
->start
.pos
;
19453 move_result
= move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
19454 MOVE_TO_POS
| MOVE_TO_X
);
19455 /* If we are under a large hscroll, move_it_in_display_line_to
19456 could hit the end of the line without reaching
19457 it->first_visible_x. Pretend that we did reach it. This is
19458 especially important on a TTY, where we will call
19459 extend_face_to_end_of_line, which needs to know how many
19460 blank glyphs to produce. */
19461 if (it
->current_x
< it
->first_visible_x
19462 && (move_result
== MOVE_NEWLINE_OR_CR
19463 || move_result
== MOVE_POS_MATCH_OR_ZV
))
19464 it
->current_x
= it
->first_visible_x
;
19466 /* Record the smallest positions seen while we moved over
19467 display elements that are not visible. This is needed by
19468 redisplay_internal for optimizing the case where the cursor
19469 stays inside the same line. The rest of this function only
19470 considers positions that are actually displayed, so
19471 RECORD_MAX_MIN_POS will not otherwise record positions that
19472 are hscrolled to the left of the left edge of the window. */
19473 min_pos
= CHARPOS (this_line_min_pos
);
19474 min_bpos
= BYTEPOS (this_line_min_pos
);
19478 /* We only do this when not calling `move_it_in_display_line_to'
19479 above, because move_it_in_display_line_to calls
19480 handle_line_prefix itself. */
19481 handle_line_prefix (it
);
19484 /* Get the initial row height. This is either the height of the
19485 text hscrolled, if there is any, or zero. */
19486 row
->ascent
= it
->max_ascent
;
19487 row
->height
= it
->max_ascent
+ it
->max_descent
;
19488 row
->phys_ascent
= it
->max_phys_ascent
;
19489 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
19490 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
19492 /* Utility macro to record max and min buffer positions seen until now. */
19493 #define RECORD_MAX_MIN_POS(IT) \
19496 int composition_p = !STRINGP ((IT)->string) \
19497 && ((IT)->what == IT_COMPOSITION); \
19498 ptrdiff_t current_pos = \
19499 composition_p ? (IT)->cmp_it.charpos \
19500 : IT_CHARPOS (*(IT)); \
19501 ptrdiff_t current_bpos = \
19502 composition_p ? CHAR_TO_BYTE (current_pos) \
19503 : IT_BYTEPOS (*(IT)); \
19504 if (current_pos < min_pos) \
19506 min_pos = current_pos; \
19507 min_bpos = current_bpos; \
19509 if (IT_CHARPOS (*it) > max_pos) \
19511 max_pos = IT_CHARPOS (*it); \
19512 max_bpos = IT_BYTEPOS (*it); \
19517 /* Loop generating characters. The loop is left with IT on the next
19518 character to display. */
19521 int n_glyphs_before
, hpos_before
, x_before
;
19523 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
19525 /* Retrieve the next thing to display. Value is zero if end of
19527 if (!get_next_display_element (it
))
19529 /* Maybe add a space at the end of this line that is used to
19530 display the cursor there under X. Set the charpos of the
19531 first glyph of blank lines not corresponding to any text
19533 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19534 row
->exact_window_width_line_p
= 1;
19535 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
19536 || row
->used
[TEXT_AREA
] == 0)
19538 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
19539 row
->displays_text_p
= 0;
19541 if (!NILP (BVAR (XBUFFER (it
->w
->contents
), indicate_empty_lines
))
19542 && (!MINI_WINDOW_P (it
->w
)
19543 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
19544 row
->indicate_empty_line_p
= 1;
19547 it
->continuation_lines_width
= 0;
19548 row
->ends_at_zv_p
= 1;
19549 /* A row that displays right-to-left text must always have
19550 its last face extended all the way to the end of line,
19551 even if this row ends in ZV, because we still write to
19552 the screen left to right. We also need to extend the
19553 last face if the default face is remapped to some
19554 different face, otherwise the functions that clear
19555 portions of the screen will clear with the default face's
19556 background color. */
19557 if (row
->reversed_p
19558 || lookup_basic_face (it
->f
, DEFAULT_FACE_ID
) != DEFAULT_FACE_ID
)
19559 extend_face_to_end_of_line (it
);
19563 /* Now, get the metrics of what we want to display. This also
19564 generates glyphs in `row' (which is IT->glyph_row). */
19565 n_glyphs_before
= row
->used
[TEXT_AREA
];
19568 /* Remember the line height so far in case the next element doesn't
19569 fit on the line. */
19570 if (it
->line_wrap
!= TRUNCATE
)
19572 ascent
= it
->max_ascent
;
19573 descent
= it
->max_descent
;
19574 phys_ascent
= it
->max_phys_ascent
;
19575 phys_descent
= it
->max_phys_descent
;
19577 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
19579 if (IT_DISPLAYING_WHITESPACE (it
))
19583 SAVE_IT (wrap_it
, *it
, wrap_data
);
19585 wrap_row_used
= row
->used
[TEXT_AREA
];
19586 wrap_row_ascent
= row
->ascent
;
19587 wrap_row_height
= row
->height
;
19588 wrap_row_phys_ascent
= row
->phys_ascent
;
19589 wrap_row_phys_height
= row
->phys_height
;
19590 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
19591 wrap_row_min_pos
= min_pos
;
19592 wrap_row_min_bpos
= min_bpos
;
19593 wrap_row_max_pos
= max_pos
;
19594 wrap_row_max_bpos
= max_bpos
;
19600 PRODUCE_GLYPHS (it
);
19602 /* If this display element was in marginal areas, continue with
19604 if (it
->area
!= TEXT_AREA
)
19606 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19607 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19608 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19609 row
->phys_height
= max (row
->phys_height
,
19610 it
->max_phys_ascent
+ it
->max_phys_descent
);
19611 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19612 it
->max_extra_line_spacing
);
19613 set_iterator_to_next (it
, 1);
19617 /* Does the display element fit on the line? If we truncate
19618 lines, we should draw past the right edge of the window. If
19619 we don't truncate, we want to stop so that we can display the
19620 continuation glyph before the right margin. If lines are
19621 continued, there are two possible strategies for characters
19622 resulting in more than 1 glyph (e.g. tabs): Display as many
19623 glyphs as possible in this line and leave the rest for the
19624 continuation line, or display the whole element in the next
19625 line. Original redisplay did the former, so we do it also. */
19626 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
19627 hpos_before
= it
->hpos
;
19630 if (/* Not a newline. */
19632 /* Glyphs produced fit entirely in the line. */
19633 && it
->current_x
< it
->last_visible_x
)
19635 it
->hpos
+= nglyphs
;
19636 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19637 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19638 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19639 row
->phys_height
= max (row
->phys_height
,
19640 it
->max_phys_ascent
+ it
->max_phys_descent
);
19641 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19642 it
->max_extra_line_spacing
);
19643 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
19644 row
->x
= x
- it
->first_visible_x
;
19645 /* Record the maximum and minimum buffer positions seen so
19646 far in glyphs that will be displayed by this row. */
19648 RECORD_MAX_MIN_POS (it
);
19653 struct glyph
*glyph
;
19655 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
19657 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
19658 new_x
= x
+ glyph
->pixel_width
;
19660 if (/* Lines are continued. */
19661 it
->line_wrap
!= TRUNCATE
19662 && (/* Glyph doesn't fit on the line. */
19663 new_x
> it
->last_visible_x
19664 /* Or it fits exactly on a window system frame. */
19665 || (new_x
== it
->last_visible_x
19666 && FRAME_WINDOW_P (it
->f
)
19667 && (row
->reversed_p
19668 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19669 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
19671 /* End of a continued line. */
19674 || (new_x
== it
->last_visible_x
19675 && FRAME_WINDOW_P (it
->f
)
19676 && (row
->reversed_p
19677 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19678 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
))))
19680 /* Current glyph is the only one on the line or
19681 fits exactly on the line. We must continue
19682 the line because we can't draw the cursor
19683 after the glyph. */
19684 row
->continued_p
= 1;
19685 it
->current_x
= new_x
;
19686 it
->continuation_lines_width
+= new_x
;
19688 if (i
== nglyphs
- 1)
19690 /* If line-wrap is on, check if a previous
19691 wrap point was found. */
19692 if (wrap_row_used
> 0
19693 /* Even if there is a previous wrap
19694 point, continue the line here as
19695 usual, if (i) the previous character
19696 was a space or tab AND (ii) the
19697 current character is not. */
19699 || IT_DISPLAYING_WHITESPACE (it
)))
19702 /* Record the maximum and minimum buffer
19703 positions seen so far in glyphs that will be
19704 displayed by this row. */
19706 RECORD_MAX_MIN_POS (it
);
19707 set_iterator_to_next (it
, 1);
19708 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19710 if (!get_next_display_element (it
))
19712 row
->exact_window_width_line_p
= 1;
19713 it
->continuation_lines_width
= 0;
19714 row
->continued_p
= 0;
19715 row
->ends_at_zv_p
= 1;
19717 else if (ITERATOR_AT_END_OF_LINE_P (it
))
19719 row
->continued_p
= 0;
19720 row
->exact_window_width_line_p
= 1;
19724 else if (it
->bidi_p
)
19725 RECORD_MAX_MIN_POS (it
);
19727 else if (CHAR_GLYPH_PADDING_P (*glyph
)
19728 && !FRAME_WINDOW_P (it
->f
))
19730 /* A padding glyph that doesn't fit on this line.
19731 This means the whole character doesn't fit
19733 if (row
->reversed_p
)
19734 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19735 - n_glyphs_before
);
19736 row
->used
[TEXT_AREA
] = n_glyphs_before
;
19738 /* Fill the rest of the row with continuation
19739 glyphs like in 20.x. */
19740 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
19741 < row
->glyphs
[1 + TEXT_AREA
])
19742 produce_special_glyphs (it
, IT_CONTINUATION
);
19744 row
->continued_p
= 1;
19745 it
->current_x
= x_before
;
19746 it
->continuation_lines_width
+= x_before
;
19748 /* Restore the height to what it was before the
19749 element not fitting on the line. */
19750 it
->max_ascent
= ascent
;
19751 it
->max_descent
= descent
;
19752 it
->max_phys_ascent
= phys_ascent
;
19753 it
->max_phys_descent
= phys_descent
;
19755 else if (wrap_row_used
> 0)
19758 if (row
->reversed_p
)
19759 unproduce_glyphs (it
,
19760 row
->used
[TEXT_AREA
] - wrap_row_used
);
19761 RESTORE_IT (it
, &wrap_it
, wrap_data
);
19762 it
->continuation_lines_width
+= wrap_x
;
19763 row
->used
[TEXT_AREA
] = wrap_row_used
;
19764 row
->ascent
= wrap_row_ascent
;
19765 row
->height
= wrap_row_height
;
19766 row
->phys_ascent
= wrap_row_phys_ascent
;
19767 row
->phys_height
= wrap_row_phys_height
;
19768 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
19769 min_pos
= wrap_row_min_pos
;
19770 min_bpos
= wrap_row_min_bpos
;
19771 max_pos
= wrap_row_max_pos
;
19772 max_bpos
= wrap_row_max_bpos
;
19773 row
->continued_p
= 1;
19774 row
->ends_at_zv_p
= 0;
19775 row
->exact_window_width_line_p
= 0;
19776 it
->continuation_lines_width
+= x
;
19778 /* Make sure that a non-default face is extended
19779 up to the right margin of the window. */
19780 extend_face_to_end_of_line (it
);
19782 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
19784 /* A TAB that extends past the right edge of the
19785 window. This produces a single glyph on
19786 window system frames. We leave the glyph in
19787 this row and let it fill the row, but don't
19788 consume the TAB. */
19789 if ((row
->reversed_p
19790 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19791 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19792 produce_special_glyphs (it
, IT_CONTINUATION
);
19793 it
->continuation_lines_width
+= it
->last_visible_x
;
19794 row
->ends_in_middle_of_char_p
= 1;
19795 row
->continued_p
= 1;
19796 glyph
->pixel_width
= it
->last_visible_x
- x
;
19797 it
->starts_in_middle_of_char_p
= 1;
19801 /* Something other than a TAB that draws past
19802 the right edge of the window. Restore
19803 positions to values before the element. */
19804 if (row
->reversed_p
)
19805 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19806 - (n_glyphs_before
+ i
));
19807 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
19809 /* Display continuation glyphs. */
19810 it
->current_x
= x_before
;
19811 it
->continuation_lines_width
+= x
;
19812 if (!FRAME_WINDOW_P (it
->f
)
19813 || (row
->reversed_p
19814 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19815 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19816 produce_special_glyphs (it
, IT_CONTINUATION
);
19817 row
->continued_p
= 1;
19819 extend_face_to_end_of_line (it
);
19821 if (nglyphs
> 1 && i
> 0)
19823 row
->ends_in_middle_of_char_p
= 1;
19824 it
->starts_in_middle_of_char_p
= 1;
19827 /* Restore the height to what it was before the
19828 element not fitting on the line. */
19829 it
->max_ascent
= ascent
;
19830 it
->max_descent
= descent
;
19831 it
->max_phys_ascent
= phys_ascent
;
19832 it
->max_phys_descent
= phys_descent
;
19837 else if (new_x
> it
->first_visible_x
)
19839 /* Increment number of glyphs actually displayed. */
19842 /* Record the maximum and minimum buffer positions
19843 seen so far in glyphs that will be displayed by
19846 RECORD_MAX_MIN_POS (it
);
19848 if (x
< it
->first_visible_x
)
19849 /* Glyph is partially visible, i.e. row starts at
19850 negative X position. */
19851 row
->x
= x
- it
->first_visible_x
;
19855 /* Glyph is completely off the left margin of the
19856 window. This should not happen because of the
19857 move_it_in_display_line at the start of this
19858 function, unless the text display area of the
19859 window is empty. */
19860 eassert (it
->first_visible_x
<= it
->last_visible_x
);
19863 /* Even if this display element produced no glyphs at all,
19864 we want to record its position. */
19865 if (it
->bidi_p
&& nglyphs
== 0)
19866 RECORD_MAX_MIN_POS (it
);
19868 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19869 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19870 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19871 row
->phys_height
= max (row
->phys_height
,
19872 it
->max_phys_ascent
+ it
->max_phys_descent
);
19873 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19874 it
->max_extra_line_spacing
);
19876 /* End of this display line if row is continued. */
19877 if (row
->continued_p
|| row
->ends_at_zv_p
)
19882 /* Is this a line end? If yes, we're also done, after making
19883 sure that a non-default face is extended up to the right
19884 margin of the window. */
19885 if (ITERATOR_AT_END_OF_LINE_P (it
))
19887 int used_before
= row
->used
[TEXT_AREA
];
19889 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
19891 /* Add a space at the end of the line that is used to
19892 display the cursor there. */
19893 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19894 append_space_for_newline (it
, 0);
19896 /* Extend the face to the end of the line. */
19897 extend_face_to_end_of_line (it
);
19899 /* Make sure we have the position. */
19900 if (used_before
== 0)
19901 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
19903 /* Record the position of the newline, for use in
19905 it
->eol_pos
= it
->current
.pos
;
19907 /* Consume the line end. This skips over invisible lines. */
19908 set_iterator_to_next (it
, 1);
19909 it
->continuation_lines_width
= 0;
19913 /* Proceed with next display element. Note that this skips
19914 over lines invisible because of selective display. */
19915 set_iterator_to_next (it
, 1);
19917 /* If we truncate lines, we are done when the last displayed
19918 glyphs reach past the right margin of the window. */
19919 if (it
->line_wrap
== TRUNCATE
19920 && (FRAME_WINDOW_P (it
->f
) && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
19921 ? (it
->current_x
>= it
->last_visible_x
)
19922 : (it
->current_x
> it
->last_visible_x
)))
19924 /* Maybe add truncation glyphs. */
19925 if (!FRAME_WINDOW_P (it
->f
)
19926 || (row
->reversed_p
19927 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19928 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19932 if (!row
->reversed_p
)
19934 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
19935 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19940 for (i
= 0; i
< row
->used
[TEXT_AREA
]; i
++)
19941 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19943 /* Remove any padding glyphs at the front of ROW, to
19944 make room for the truncation glyphs we will be
19945 adding below. The loop below always inserts at
19946 least one truncation glyph, so also remove the
19947 last glyph added to ROW. */
19948 unproduce_glyphs (it
, i
+ 1);
19949 /* Adjust i for the loop below. */
19950 i
= row
->used
[TEXT_AREA
] - (i
+ 1);
19953 it
->current_x
= x_before
;
19954 if (!FRAME_WINDOW_P (it
->f
))
19956 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
19958 row
->used
[TEXT_AREA
] = i
;
19959 produce_special_glyphs (it
, IT_TRUNCATION
);
19964 row
->used
[TEXT_AREA
] = i
;
19965 produce_special_glyphs (it
, IT_TRUNCATION
);
19968 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19970 /* Don't truncate if we can overflow newline into fringe. */
19971 if (!get_next_display_element (it
))
19973 it
->continuation_lines_width
= 0;
19974 row
->ends_at_zv_p
= 1;
19975 row
->exact_window_width_line_p
= 1;
19978 if (ITERATOR_AT_END_OF_LINE_P (it
))
19980 row
->exact_window_width_line_p
= 1;
19981 goto at_end_of_line
;
19983 it
->current_x
= x_before
;
19986 row
->truncated_on_right_p
= 1;
19987 it
->continuation_lines_width
= 0;
19988 reseat_at_next_visible_line_start (it
, 0);
19989 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
19990 it
->hpos
= hpos_before
;
19996 bidi_unshelve_cache (wrap_data
, 1);
19998 /* If line is not empty and hscrolled, maybe insert truncation glyphs
19999 at the left window margin. */
20000 if (it
->first_visible_x
20001 && IT_CHARPOS (*it
) != CHARPOS (row
->start
.pos
))
20003 if (!FRAME_WINDOW_P (it
->f
)
20004 || (row
->reversed_p
20005 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
20006 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
20007 insert_left_trunc_glyphs (it
);
20008 row
->truncated_on_left_p
= 1;
20011 /* Remember the position at which this line ends.
20013 BIDI Note: any code that needs MATRIX_ROW_START/END_CHARPOS
20014 cannot be before the call to find_row_edges below, since that is
20015 where these positions are determined. */
20016 row
->end
= it
->current
;
20019 row
->minpos
= row
->start
.pos
;
20020 row
->maxpos
= row
->end
.pos
;
20024 /* ROW->minpos and ROW->maxpos must be the smallest and
20025 `1 + the largest' buffer positions in ROW. But if ROW was
20026 bidi-reordered, these two positions can be anywhere in the
20027 row, so we must determine them now. */
20028 find_row_edges (it
, row
, min_pos
, min_bpos
, max_pos
, max_bpos
);
20031 /* If the start of this line is the overlay arrow-position, then
20032 mark this glyph row as the one containing the overlay arrow.
20033 This is clearly a mess with variable size fonts. It would be
20034 better to let it be displayed like cursors under X. */
20035 if ((MATRIX_ROW_DISPLAYS_TEXT_P (row
) || !overlay_arrow_seen
)
20036 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
20037 !NILP (overlay_arrow_string
)))
20039 /* Overlay arrow in window redisplay is a fringe bitmap. */
20040 if (STRINGP (overlay_arrow_string
))
20042 struct glyph_row
*arrow_row
20043 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
20044 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
20045 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
20046 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
20047 struct glyph
*p2
, *end
;
20049 /* Copy the arrow glyphs. */
20050 while (glyph
< arrow_end
)
20053 /* Throw away padding glyphs. */
20055 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
20056 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
20062 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
20067 eassert (INTEGERP (overlay_arrow_string
));
20068 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
20070 overlay_arrow_seen
= 1;
20073 /* Highlight trailing whitespace. */
20074 if (!NILP (Vshow_trailing_whitespace
))
20075 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
20077 /* Compute pixel dimensions of this line. */
20078 compute_line_metrics (it
);
20080 /* Implementation note: No changes in the glyphs of ROW or in their
20081 faces can be done past this point, because compute_line_metrics
20082 computes ROW's hash value and stores it within the glyph_row
20085 /* Record whether this row ends inside an ellipsis. */
20086 row
->ends_in_ellipsis_p
20087 = (it
->method
== GET_FROM_DISPLAY_VECTOR
20088 && it
->ellipsis_p
);
20090 /* Save fringe bitmaps in this row. */
20091 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
20092 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
20093 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
20094 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
20096 it
->left_user_fringe_bitmap
= 0;
20097 it
->left_user_fringe_face_id
= 0;
20098 it
->right_user_fringe_bitmap
= 0;
20099 it
->right_user_fringe_face_id
= 0;
20101 /* Maybe set the cursor. */
20102 cvpos
= it
->w
->cursor
.vpos
;
20104 /* In bidi-reordered rows, keep checking for proper cursor
20105 position even if one has been found already, because buffer
20106 positions in such rows change non-linearly with ROW->VPOS,
20107 when a line is continued. One exception: when we are at ZV,
20108 display cursor on the first suitable glyph row, since all
20109 the empty rows after that also have their position set to ZV. */
20110 /* FIXME: Revisit this when glyph ``spilling'' in continuation
20111 lines' rows is implemented for bidi-reordered rows. */
20113 && !MATRIX_ROW (it
->w
->desired_matrix
, cvpos
)->ends_at_zv_p
))
20114 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
20115 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
20116 && cursor_row_p (row
))
20117 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
20119 /* Prepare for the next line. This line starts horizontally at (X
20120 HPOS) = (0 0). Vertical positions are incremented. As a
20121 convenience for the caller, IT->glyph_row is set to the next
20123 it
->current_x
= it
->hpos
= 0;
20124 it
->current_y
+= row
->height
;
20125 SET_TEXT_POS (it
->eol_pos
, 0, 0);
20128 /* The next row should by default use the same value of the
20129 reversed_p flag as this one. set_iterator_to_next decides when
20130 it's a new paragraph, and PRODUCE_GLYPHS recomputes the value of
20131 the flag accordingly. */
20132 if (it
->glyph_row
< MATRIX_BOTTOM_TEXT_ROW (it
->w
->desired_matrix
, it
->w
))
20133 it
->glyph_row
->reversed_p
= row
->reversed_p
;
20134 it
->start
= row
->end
;
20135 return MATRIX_ROW_DISPLAYS_TEXT_P (row
);
20137 #undef RECORD_MAX_MIN_POS
20140 DEFUN ("current-bidi-paragraph-direction", Fcurrent_bidi_paragraph_direction
,
20141 Scurrent_bidi_paragraph_direction
, 0, 1, 0,
20142 doc
: /* Return paragraph direction at point in BUFFER.
20143 Value is either `left-to-right' or `right-to-left'.
20144 If BUFFER is omitted or nil, it defaults to the current buffer.
20146 Paragraph direction determines how the text in the paragraph is displayed.
20147 In left-to-right paragraphs, text begins at the left margin of the window
20148 and the reading direction is generally left to right. In right-to-left
20149 paragraphs, text begins at the right margin and is read from right to left.
20151 See also `bidi-paragraph-direction'. */)
20152 (Lisp_Object buffer
)
20154 struct buffer
*buf
= current_buffer
;
20155 struct buffer
*old
= buf
;
20157 if (! NILP (buffer
))
20159 CHECK_BUFFER (buffer
);
20160 buf
= XBUFFER (buffer
);
20163 if (NILP (BVAR (buf
, bidi_display_reordering
))
20164 || NILP (BVAR (buf
, enable_multibyte_characters
))
20165 /* When we are loading loadup.el, the character property tables
20166 needed for bidi iteration are not yet available. */
20167 || !NILP (Vpurify_flag
))
20168 return Qleft_to_right
;
20169 else if (!NILP (BVAR (buf
, bidi_paragraph_direction
)))
20170 return BVAR (buf
, bidi_paragraph_direction
);
20173 /* Determine the direction from buffer text. We could try to
20174 use current_matrix if it is up to date, but this seems fast
20175 enough as it is. */
20176 struct bidi_it itb
;
20177 ptrdiff_t pos
= BUF_PT (buf
);
20178 ptrdiff_t bytepos
= BUF_PT_BYTE (buf
);
20180 void *itb_data
= bidi_shelve_cache ();
20182 set_buffer_temp (buf
);
20183 /* bidi_paragraph_init finds the base direction of the paragraph
20184 by searching forward from paragraph start. We need the base
20185 direction of the current or _previous_ paragraph, so we need
20186 to make sure we are within that paragraph. To that end, find
20187 the previous non-empty line. */
20188 if (pos
>= ZV
&& pos
> BEGV
)
20189 DEC_BOTH (pos
, bytepos
);
20190 if (fast_looking_at (build_string ("[\f\t ]*\n"),
20191 pos
, bytepos
, ZV
, ZV_BYTE
, Qnil
) > 0)
20193 while ((c
= FETCH_BYTE (bytepos
)) == '\n'
20194 || c
== ' ' || c
== '\t' || c
== '\f')
20196 if (bytepos
<= BEGV_BYTE
)
20201 while (!CHAR_HEAD_P (FETCH_BYTE (bytepos
)))
20204 bidi_init_it (pos
, bytepos
, FRAME_WINDOW_P (SELECTED_FRAME ()), &itb
);
20205 itb
.paragraph_dir
= NEUTRAL_DIR
;
20206 itb
.string
.s
= NULL
;
20207 itb
.string
.lstring
= Qnil
;
20208 itb
.string
.bufpos
= 0;
20209 itb
.string
.unibyte
= 0;
20210 /* We have no window to use here for ignoring window-specific
20211 overlays. Using NULL for window pointer will cause
20212 compute_display_string_pos to use the current buffer. */
20214 bidi_paragraph_init (NEUTRAL_DIR
, &itb
, 1);
20215 bidi_unshelve_cache (itb_data
, 0);
20216 set_buffer_temp (old
);
20217 switch (itb
.paragraph_dir
)
20220 return Qleft_to_right
;
20223 return Qright_to_left
;
20231 DEFUN ("move-point-visually", Fmove_point_visually
,
20232 Smove_point_visually
, 1, 1, 0,
20233 doc
: /* Move point in the visual order in the specified DIRECTION.
20234 DIRECTION can be 1, meaning move to the right, or -1, which moves to the
20237 Value is the new character position of point. */)
20238 (Lisp_Object direction
)
20240 struct window
*w
= XWINDOW (selected_window
);
20241 struct buffer
*b
= XBUFFER (w
->contents
);
20242 struct glyph_row
*row
;
20244 Lisp_Object paragraph_dir
;
20246 #define ROW_GLYPH_NEWLINE_P(ROW,GLYPH) \
20247 (!(ROW)->continued_p \
20248 && INTEGERP ((GLYPH)->object) \
20249 && (GLYPH)->type == CHAR_GLYPH \
20250 && (GLYPH)->u.ch == ' ' \
20251 && (GLYPH)->charpos >= 0 \
20252 && !(GLYPH)->avoid_cursor_p)
20254 CHECK_NUMBER (direction
);
20255 dir
= XINT (direction
);
20261 /* If current matrix is up-to-date, we can use the information
20262 recorded in the glyphs, at least as long as the goal is on the
20264 if (w
->window_end_valid
20265 && !windows_or_buffers_changed
20267 && !b
->clip_changed
20268 && !b
->prevent_redisplay_optimizations_p
20269 && !window_outdated (w
)
20270 && w
->cursor
.vpos
>= 0
20271 && w
->cursor
.vpos
< w
->current_matrix
->nrows
20272 && (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
))->enabled_p
)
20274 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
20275 struct glyph
*e
= dir
> 0 ? g
+ row
->used
[TEXT_AREA
] : g
- 1;
20276 struct glyph
*gpt
= g
+ w
->cursor
.hpos
;
20278 for (g
= gpt
+ dir
; (dir
> 0 ? g
< e
: g
> e
); g
+= dir
)
20280 if (BUFFERP (g
->object
) && g
->charpos
!= PT
)
20282 SET_PT (g
->charpos
);
20283 w
->cursor
.vpos
= -1;
20284 return make_number (PT
);
20286 else if (!INTEGERP (g
->object
) && !EQ (g
->object
, gpt
->object
))
20290 if (BUFFERP (gpt
->object
))
20293 if ((gpt
->resolved_level
- row
->reversed_p
) % 2 == 0)
20294 new_pos
+= (row
->reversed_p
? -dir
: dir
);
20296 new_pos
-= (row
->reversed_p
? -dir
: dir
);;
20298 else if (BUFFERP (g
->object
))
20299 new_pos
= g
->charpos
;
20303 w
->cursor
.vpos
= -1;
20304 return make_number (PT
);
20306 else if (ROW_GLYPH_NEWLINE_P (row
, g
))
20308 /* Glyphs inserted at the end of a non-empty line for
20309 positioning the cursor have zero charpos, so we must
20310 deduce the value of point by other means. */
20311 if (g
->charpos
> 0)
20312 SET_PT (g
->charpos
);
20313 else if (row
->ends_at_zv_p
&& PT
!= ZV
)
20315 else if (PT
!= MATRIX_ROW_END_CHARPOS (row
) - 1)
20316 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
20319 w
->cursor
.vpos
= -1;
20320 return make_number (PT
);
20323 if (g
== e
|| INTEGERP (g
->object
))
20325 if (row
->truncated_on_left_p
|| row
->truncated_on_right_p
)
20326 goto simulate_display
;
20327 if (!row
->reversed_p
)
20331 if (row
< MATRIX_FIRST_TEXT_ROW (w
->current_matrix
)
20332 || row
> MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
20333 goto simulate_display
;
20337 if (row
->reversed_p
&& !row
->continued_p
)
20339 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
20340 w
->cursor
.vpos
= -1;
20341 return make_number (PT
);
20343 g
= row
->glyphs
[TEXT_AREA
];
20344 e
= g
+ row
->used
[TEXT_AREA
];
20345 for ( ; g
< e
; g
++)
20347 if (BUFFERP (g
->object
)
20348 /* Empty lines have only one glyph, which stands
20349 for the newline, and whose charpos is the
20350 buffer position of the newline. */
20351 || ROW_GLYPH_NEWLINE_P (row
, g
)
20352 /* When the buffer ends in a newline, the line at
20353 EOB also has one glyph, but its charpos is -1. */
20354 || (row
->ends_at_zv_p
20355 && !row
->reversed_p
20356 && INTEGERP (g
->object
)
20357 && g
->type
== CHAR_GLYPH
20358 && g
->u
.ch
== ' '))
20360 if (g
->charpos
> 0)
20361 SET_PT (g
->charpos
);
20362 else if (!row
->reversed_p
20363 && row
->ends_at_zv_p
20368 w
->cursor
.vpos
= -1;
20369 return make_number (PT
);
20375 if (!row
->reversed_p
&& !row
->continued_p
)
20377 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
20378 w
->cursor
.vpos
= -1;
20379 return make_number (PT
);
20381 e
= row
->glyphs
[TEXT_AREA
];
20382 g
= e
+ row
->used
[TEXT_AREA
] - 1;
20383 for ( ; g
>= e
; g
--)
20385 if (BUFFERP (g
->object
)
20386 || (ROW_GLYPH_NEWLINE_P (row
, g
)
20388 /* Empty R2L lines on GUI frames have the buffer
20389 position of the newline stored in the stretch
20391 || g
->type
== STRETCH_GLYPH
20392 || (row
->ends_at_zv_p
20394 && INTEGERP (g
->object
)
20395 && g
->type
== CHAR_GLYPH
20396 && g
->u
.ch
== ' '))
20398 if (g
->charpos
> 0)
20399 SET_PT (g
->charpos
);
20400 else if (row
->reversed_p
20401 && row
->ends_at_zv_p
20406 w
->cursor
.vpos
= -1;
20407 return make_number (PT
);
20416 /* If we wind up here, we failed to move by using the glyphs, so we
20417 need to simulate display instead. */
20420 paragraph_dir
= Fcurrent_bidi_paragraph_direction (w
->contents
);
20422 paragraph_dir
= Qleft_to_right
;
20423 if (EQ (paragraph_dir
, Qright_to_left
))
20425 if (PT
<= BEGV
&& dir
< 0)
20426 xsignal0 (Qbeginning_of_buffer
);
20427 else if (PT
>= ZV
&& dir
> 0)
20428 xsignal0 (Qend_of_buffer
);
20431 struct text_pos pt
;
20433 int pt_x
, target_x
, pixel_width
, pt_vpos
;
20435 bool overshoot_expected
= false;
20436 bool target_is_eol_p
= false;
20438 /* Setup the arena. */
20439 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
20440 start_display (&it
, w
, pt
);
20442 if (it
.cmp_it
.id
< 0
20443 && it
.method
== GET_FROM_STRING
20444 && it
.area
== TEXT_AREA
20445 && it
.string_from_display_prop_p
20446 && (it
.sp
> 0 && it
.stack
[it
.sp
- 1].method
== GET_FROM_BUFFER
))
20447 overshoot_expected
= true;
20449 /* Find the X coordinate of point. We start from the beginning
20450 of this or previous line to make sure we are before point in
20451 the logical order (since the move_it_* functions can only
20453 reseat_at_previous_visible_line_start (&it
);
20454 it
.current_x
= it
.hpos
= it
.current_y
= it
.vpos
= 0;
20455 if (IT_CHARPOS (it
) != PT
)
20456 move_it_to (&it
, overshoot_expected
? PT
- 1 : PT
,
20457 -1, -1, -1, MOVE_TO_POS
);
20458 pt_x
= it
.current_x
;
20460 if (dir
> 0 || overshoot_expected
)
20462 struct glyph_row
*row
= it
.glyph_row
;
20464 /* When point is at beginning of line, we don't have
20465 information about the glyph there loaded into struct
20466 it. Calling get_next_display_element fixes that. */
20468 get_next_display_element (&it
);
20469 at_eol_p
= ITERATOR_AT_END_OF_LINE_P (&it
);
20470 it
.glyph_row
= NULL
;
20471 PRODUCE_GLYPHS (&it
); /* compute it.pixel_width */
20472 it
.glyph_row
= row
;
20473 /* PRODUCE_GLYPHS advances it.current_x, so we must restore
20474 it, lest it will become out of sync with it's buffer
20476 it
.current_x
= pt_x
;
20479 at_eol_p
= ITERATOR_AT_END_OF_LINE_P (&it
);
20480 pixel_width
= it
.pixel_width
;
20481 if (overshoot_expected
&& at_eol_p
)
20483 else if (pixel_width
<= 0)
20486 /* If there's a display string at point, we are actually at the
20487 glyph to the left of point, so we need to correct the X
20489 if (overshoot_expected
)
20490 pt_x
+= pixel_width
;
20492 /* Compute target X coordinate, either to the left or to the
20493 right of point. On TTY frames, all characters have the same
20494 pixel width of 1, so we can use that. On GUI frames we don't
20495 have an easy way of getting at the pixel width of the
20496 character to the left of point, so we use a different method
20497 of getting to that place. */
20499 target_x
= pt_x
+ pixel_width
;
20501 target_x
= pt_x
- (!FRAME_WINDOW_P (it
.f
)) * pixel_width
;
20503 /* Target X coordinate could be one line above or below the line
20504 of point, in which case we need to adjust the target X
20505 coordinate. Also, if moving to the left, we need to begin at
20506 the left edge of the point's screen line. */
20511 start_display (&it
, w
, pt
);
20512 reseat_at_previous_visible_line_start (&it
);
20513 it
.current_x
= it
.current_y
= it
.hpos
= 0;
20515 move_it_by_lines (&it
, pt_vpos
);
20519 move_it_by_lines (&it
, -1);
20520 target_x
= it
.last_visible_x
- !FRAME_WINDOW_P (it
.f
);
20521 target_is_eol_p
= true;
20527 || (target_x
>= it
.last_visible_x
20528 && it
.line_wrap
!= TRUNCATE
))
20531 move_it_by_lines (&it
, 0);
20532 move_it_by_lines (&it
, 1);
20537 /* Move to the target X coordinate. */
20538 #ifdef HAVE_WINDOW_SYSTEM
20539 /* On GUI frames, as we don't know the X coordinate of the
20540 character to the left of point, moving point to the left
20541 requires walking, one grapheme cluster at a time, until we
20542 find ourself at a place immediately to the left of the
20543 character at point. */
20544 if (FRAME_WINDOW_P (it
.f
) && dir
< 0)
20546 struct text_pos new_pos
= it
.current
.pos
;
20547 enum move_it_result rc
= MOVE_X_REACHED
;
20549 while (it
.current_x
+ it
.pixel_width
<= target_x
20550 && rc
== MOVE_X_REACHED
)
20552 int new_x
= it
.current_x
+ it
.pixel_width
;
20554 new_pos
= it
.current
.pos
;
20555 if (new_x
== it
.current_x
)
20557 rc
= move_it_in_display_line_to (&it
, ZV
, new_x
,
20558 MOVE_TO_POS
| MOVE_TO_X
);
20559 if (ITERATOR_AT_END_OF_LINE_P (&it
) && !target_is_eol_p
)
20562 /* If we ended up on a composed character inside
20563 bidi-reordered text (e.g., Hebrew text with diacritics),
20564 the iterator gives us the buffer position of the last (in
20565 logical order) character of the composed grapheme cluster,
20566 which is not what we want. So we cheat: we compute the
20567 character position of the character that follows (in the
20568 logical order) the one where the above loop stopped. That
20569 character will appear on display to the left of point. */
20571 && it
.bidi_it
.scan_dir
== -1
20572 && new_pos
.charpos
- IT_CHARPOS (it
) > 1)
20574 new_pos
.charpos
= IT_CHARPOS (it
) + 1;
20575 new_pos
.bytepos
= CHAR_TO_BYTE (new_pos
.charpos
);
20577 it
.current
.pos
= new_pos
;
20581 if (it
.current_x
!= target_x
)
20582 move_it_in_display_line_to (&it
, ZV
, target_x
, MOVE_TO_POS
| MOVE_TO_X
);
20584 /* When lines are truncated, the above loop will stop at the
20585 window edge. But we want to get to the end of line, even if
20586 it is beyond the window edge; automatic hscroll will then
20587 scroll the window to show point as appropriate. */
20588 if (target_is_eol_p
&& it
.line_wrap
== TRUNCATE
20589 && get_next_display_element (&it
))
20591 struct text_pos new_pos
= it
.current
.pos
;
20593 while (!ITERATOR_AT_END_OF_LINE_P (&it
))
20595 set_iterator_to_next (&it
, 0);
20596 if (it
.method
== GET_FROM_BUFFER
)
20597 new_pos
= it
.current
.pos
;
20598 if (!get_next_display_element (&it
))
20602 it
.current
.pos
= new_pos
;
20605 /* If we ended up in a display string that covers point, move to
20606 buffer position to the right in the visual order. */
20609 while (IT_CHARPOS (it
) == PT
)
20611 set_iterator_to_next (&it
, 0);
20612 if (!get_next_display_element (&it
))
20617 /* Move point to that position. */
20618 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
20621 return make_number (PT
);
20623 #undef ROW_GLYPH_NEWLINE_P
20627 /***********************************************************************
20629 ***********************************************************************/
20631 /* Redisplay the menu bar in the frame for window W.
20633 The menu bar of X frames that don't have X toolkit support is
20634 displayed in a special window W->frame->menu_bar_window.
20636 The menu bar of terminal frames is treated specially as far as
20637 glyph matrices are concerned. Menu bar lines are not part of
20638 windows, so the update is done directly on the frame matrix rows
20639 for the menu bar. */
20642 display_menu_bar (struct window
*w
)
20644 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20649 /* Don't do all this for graphical frames. */
20651 if (FRAME_W32_P (f
))
20654 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
20660 if (FRAME_NS_P (f
))
20662 #endif /* HAVE_NS */
20664 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
20665 eassert (!FRAME_WINDOW_P (f
));
20666 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
20667 it
.first_visible_x
= 0;
20668 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
20669 #elif defined (HAVE_X_WINDOWS) /* X without toolkit. */
20670 if (FRAME_WINDOW_P (f
))
20672 /* Menu bar lines are displayed in the desired matrix of the
20673 dummy window menu_bar_window. */
20674 struct window
*menu_w
;
20675 menu_w
= XWINDOW (f
->menu_bar_window
);
20676 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
20678 it
.first_visible_x
= 0;
20679 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
20682 #endif /* not USE_X_TOOLKIT and not USE_GTK */
20684 /* This is a TTY frame, i.e. character hpos/vpos are used as
20686 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
20688 it
.first_visible_x
= 0;
20689 it
.last_visible_x
= FRAME_COLS (f
);
20692 /* FIXME: This should be controlled by a user option. See the
20693 comments in redisplay_tool_bar and display_mode_line about
20695 it
.paragraph_embedding
= L2R
;
20697 /* Clear all rows of the menu bar. */
20698 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
20700 struct glyph_row
*row
= it
.glyph_row
+ i
;
20701 clear_glyph_row (row
);
20702 row
->enabled_p
= 1;
20703 row
->full_width_p
= 1;
20706 /* Display all items of the menu bar. */
20707 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
20708 for (i
= 0; i
< ASIZE (items
); i
+= 4)
20710 Lisp_Object string
;
20712 /* Stop at nil string. */
20713 string
= AREF (items
, i
+ 1);
20717 /* Remember where item was displayed. */
20718 ASET (items
, i
+ 3, make_number (it
.hpos
));
20720 /* Display the item, pad with one space. */
20721 if (it
.current_x
< it
.last_visible_x
)
20722 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
20723 SCHARS (string
) + 1, 0, 0, -1);
20726 /* Fill out the line with spaces. */
20727 if (it
.current_x
< it
.last_visible_x
)
20728 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
20730 /* Compute the total height of the lines. */
20731 compute_line_metrics (&it
);
20736 /***********************************************************************
20738 ***********************************************************************/
20740 /* Redisplay mode lines in the window tree whose root is WINDOW. If
20741 FORCE is non-zero, redisplay mode lines unconditionally.
20742 Otherwise, redisplay only mode lines that are garbaged. Value is
20743 the number of windows whose mode lines were redisplayed. */
20746 redisplay_mode_lines (Lisp_Object window
, int force
)
20750 while (!NILP (window
))
20752 struct window
*w
= XWINDOW (window
);
20754 if (WINDOWP (w
->contents
))
20755 nwindows
+= redisplay_mode_lines (w
->contents
, force
);
20757 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
20758 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
20760 struct text_pos lpoint
;
20761 struct buffer
*old
= current_buffer
;
20763 /* Set the window's buffer for the mode line display. */
20764 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
20765 set_buffer_internal_1 (XBUFFER (w
->contents
));
20767 /* Point refers normally to the selected window. For any
20768 other window, set up appropriate value. */
20769 if (!EQ (window
, selected_window
))
20771 struct text_pos pt
;
20773 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
20774 if (CHARPOS (pt
) < BEGV
)
20775 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
20776 else if (CHARPOS (pt
) > (ZV
- 1))
20777 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
20779 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
20782 /* Display mode lines. */
20783 clear_glyph_matrix (w
->desired_matrix
);
20784 if (display_mode_lines (w
))
20787 w
->must_be_updated_p
= 1;
20790 /* Restore old settings. */
20791 set_buffer_internal_1 (old
);
20792 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
20802 /* Display the mode and/or header line of window W. Value is the
20803 sum number of mode lines and header lines displayed. */
20806 display_mode_lines (struct window
*w
)
20808 Lisp_Object old_selected_window
= selected_window
;
20809 Lisp_Object old_selected_frame
= selected_frame
;
20810 Lisp_Object new_frame
= w
->frame
;
20811 Lisp_Object old_frame_selected_window
= XFRAME (new_frame
)->selected_window
;
20814 selected_frame
= new_frame
;
20815 /* FIXME: If we were to allow the mode-line's computation changing the buffer
20816 or window's point, then we'd need select_window_1 here as well. */
20817 XSETWINDOW (selected_window
, w
);
20818 XFRAME (new_frame
)->selected_window
= selected_window
;
20820 /* These will be set while the mode line specs are processed. */
20821 line_number_displayed
= 0;
20822 w
->column_number_displayed
= -1;
20824 if (WINDOW_WANTS_MODELINE_P (w
))
20826 struct window
*sel_w
= XWINDOW (old_selected_window
);
20828 /* Select mode line face based on the real selected window. */
20829 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
20830 BVAR (current_buffer
, mode_line_format
));
20834 if (WINDOW_WANTS_HEADER_LINE_P (w
))
20836 display_mode_line (w
, HEADER_LINE_FACE_ID
,
20837 BVAR (current_buffer
, header_line_format
));
20841 XFRAME (new_frame
)->selected_window
= old_frame_selected_window
;
20842 selected_frame
= old_selected_frame
;
20843 selected_window
= old_selected_window
;
20848 /* Display mode or header line of window W. FACE_ID specifies which
20849 line to display; it is either MODE_LINE_FACE_ID or
20850 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
20851 display. Value is the pixel height of the mode/header line
20855 display_mode_line (struct window
*w
, enum face_id face_id
, Lisp_Object format
)
20859 ptrdiff_t count
= SPECPDL_INDEX ();
20861 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
20862 /* Don't extend on a previously drawn mode-line.
20863 This may happen if called from pos_visible_p. */
20864 it
.glyph_row
->enabled_p
= 0;
20865 prepare_desired_row (it
.glyph_row
);
20867 it
.glyph_row
->mode_line_p
= 1;
20869 /* FIXME: This should be controlled by a user option. But
20870 supporting such an option is not trivial, since the mode line is
20871 made up of many separate strings. */
20872 it
.paragraph_embedding
= L2R
;
20874 record_unwind_protect (unwind_format_mode_line
,
20875 format_mode_line_unwind_data (NULL
, NULL
, Qnil
, 0));
20877 mode_line_target
= MODE_LINE_DISPLAY
;
20879 /* Temporarily make frame's keyboard the current kboard so that
20880 kboard-local variables in the mode_line_format will get the right
20882 push_kboard (FRAME_KBOARD (it
.f
));
20883 record_unwind_save_match_data ();
20884 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
20887 unbind_to (count
, Qnil
);
20889 /* Fill up with spaces. */
20890 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
20892 compute_line_metrics (&it
);
20893 it
.glyph_row
->full_width_p
= 1;
20894 it
.glyph_row
->continued_p
= 0;
20895 it
.glyph_row
->truncated_on_left_p
= 0;
20896 it
.glyph_row
->truncated_on_right_p
= 0;
20898 /* Make a 3D mode-line have a shadow at its right end. */
20899 face
= FACE_FROM_ID (it
.f
, face_id
);
20900 extend_face_to_end_of_line (&it
);
20901 if (face
->box
!= FACE_NO_BOX
)
20903 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
20904 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
20905 last
->right_box_line_p
= 1;
20908 return it
.glyph_row
->height
;
20911 /* Move element ELT in LIST to the front of LIST.
20912 Return the updated list. */
20915 move_elt_to_front (Lisp_Object elt
, Lisp_Object list
)
20917 register Lisp_Object tail
, prev
;
20918 register Lisp_Object tem
;
20922 while (CONSP (tail
))
20928 /* Splice out the link TAIL. */
20930 list
= XCDR (tail
);
20932 Fsetcdr (prev
, XCDR (tail
));
20934 /* Now make it the first. */
20935 Fsetcdr (tail
, list
);
20940 tail
= XCDR (tail
);
20944 /* Not found--return unchanged LIST. */
20948 /* Contribute ELT to the mode line for window IT->w. How it
20949 translates into text depends on its data type.
20951 IT describes the display environment in which we display, as usual.
20953 DEPTH is the depth in recursion. It is used to prevent
20954 infinite recursion here.
20956 FIELD_WIDTH is the number of characters the display of ELT should
20957 occupy in the mode line, and PRECISION is the maximum number of
20958 characters to display from ELT's representation. See
20959 display_string for details.
20961 Returns the hpos of the end of the text generated by ELT.
20963 PROPS is a property list to add to any string we encounter.
20965 If RISKY is nonzero, remove (disregard) any properties in any string
20966 we encounter, and ignore :eval and :propertize.
20968 The global variable `mode_line_target' determines whether the
20969 output is passed to `store_mode_line_noprop',
20970 `store_mode_line_string', or `display_string'. */
20973 display_mode_element (struct it
*it
, int depth
, int field_width
, int precision
,
20974 Lisp_Object elt
, Lisp_Object props
, int risky
)
20976 int n
= 0, field
, prec
;
20981 elt
= build_string ("*too-deep*");
20985 switch (XTYPE (elt
))
20989 /* A string: output it and check for %-constructs within it. */
20991 ptrdiff_t offset
= 0;
20993 if (SCHARS (elt
) > 0
20994 && (!NILP (props
) || risky
))
20996 Lisp_Object oprops
, aelt
;
20997 oprops
= Ftext_properties_at (make_number (0), elt
);
20999 /* If the starting string's properties are not what
21000 we want, translate the string. Also, if the string
21001 is risky, do that anyway. */
21003 if (NILP (Fequal (props
, oprops
)) || risky
)
21005 /* If the starting string has properties,
21006 merge the specified ones onto the existing ones. */
21007 if (! NILP (oprops
) && !risky
)
21011 oprops
= Fcopy_sequence (oprops
);
21013 while (CONSP (tem
))
21015 oprops
= Fplist_put (oprops
, XCAR (tem
),
21016 XCAR (XCDR (tem
)));
21017 tem
= XCDR (XCDR (tem
));
21022 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
21023 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
21025 /* AELT is what we want. Move it to the front
21026 without consing. */
21028 mode_line_proptrans_alist
21029 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
21035 /* If AELT has the wrong props, it is useless.
21036 so get rid of it. */
21038 mode_line_proptrans_alist
21039 = Fdelq (aelt
, mode_line_proptrans_alist
);
21041 elt
= Fcopy_sequence (elt
);
21042 Fset_text_properties (make_number (0), Flength (elt
),
21044 /* Add this item to mode_line_proptrans_alist. */
21045 mode_line_proptrans_alist
21046 = Fcons (Fcons (elt
, props
),
21047 mode_line_proptrans_alist
);
21048 /* Truncate mode_line_proptrans_alist
21049 to at most 50 elements. */
21050 tem
= Fnthcdr (make_number (50),
21051 mode_line_proptrans_alist
);
21053 XSETCDR (tem
, Qnil
);
21062 prec
= precision
- n
;
21063 switch (mode_line_target
)
21065 case MODE_LINE_NOPROP
:
21066 case MODE_LINE_TITLE
:
21067 n
+= store_mode_line_noprop (SSDATA (elt
), -1, prec
);
21069 case MODE_LINE_STRING
:
21070 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
21072 case MODE_LINE_DISPLAY
:
21073 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
21074 0, prec
, 0, STRING_MULTIBYTE (elt
));
21081 /* Handle the non-literal case. */
21083 while ((precision
<= 0 || n
< precision
)
21084 && SREF (elt
, offset
) != 0
21085 && (mode_line_target
!= MODE_LINE_DISPLAY
21086 || it
->current_x
< it
->last_visible_x
))
21088 ptrdiff_t last_offset
= offset
;
21090 /* Advance to end of string or next format specifier. */
21091 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
21094 if (offset
- 1 != last_offset
)
21096 ptrdiff_t nchars
, nbytes
;
21098 /* Output to end of string or up to '%'. Field width
21099 is length of string. Don't output more than
21100 PRECISION allows us. */
21103 prec
= c_string_width (SDATA (elt
) + last_offset
,
21104 offset
- last_offset
, precision
- n
,
21107 switch (mode_line_target
)
21109 case MODE_LINE_NOPROP
:
21110 case MODE_LINE_TITLE
:
21111 n
+= store_mode_line_noprop (SSDATA (elt
) + last_offset
, 0, prec
);
21113 case MODE_LINE_STRING
:
21115 ptrdiff_t bytepos
= last_offset
;
21116 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
21117 ptrdiff_t endpos
= (precision
<= 0
21118 ? string_byte_to_char (elt
, offset
)
21119 : charpos
+ nchars
);
21121 n
+= store_mode_line_string (NULL
,
21122 Fsubstring (elt
, make_number (charpos
),
21123 make_number (endpos
)),
21127 case MODE_LINE_DISPLAY
:
21129 ptrdiff_t bytepos
= last_offset
;
21130 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
21132 if (precision
<= 0)
21133 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
21134 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
21136 STRING_MULTIBYTE (elt
));
21141 else /* c == '%' */
21143 ptrdiff_t percent_position
= offset
;
21145 /* Get the specified minimum width. Zero means
21148 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
21149 field
= field
* 10 + c
- '0';
21151 /* Don't pad beyond the total padding allowed. */
21152 if (field_width
- n
> 0 && field
> field_width
- n
)
21153 field
= field_width
- n
;
21155 /* Note that either PRECISION <= 0 or N < PRECISION. */
21156 prec
= precision
- n
;
21159 n
+= display_mode_element (it
, depth
, field
, prec
,
21160 Vglobal_mode_string
, props
,
21165 ptrdiff_t bytepos
, charpos
;
21167 Lisp_Object string
;
21169 bytepos
= percent_position
;
21170 charpos
= (STRING_MULTIBYTE (elt
)
21171 ? string_byte_to_char (elt
, bytepos
)
21173 spec
= decode_mode_spec (it
->w
, c
, field
, &string
);
21174 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
21176 switch (mode_line_target
)
21178 case MODE_LINE_NOPROP
:
21179 case MODE_LINE_TITLE
:
21180 n
+= store_mode_line_noprop (spec
, field
, prec
);
21182 case MODE_LINE_STRING
:
21184 Lisp_Object tem
= build_string (spec
);
21185 props
= Ftext_properties_at (make_number (charpos
), elt
);
21186 /* Should only keep face property in props */
21187 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
21190 case MODE_LINE_DISPLAY
:
21192 int nglyphs_before
, nwritten
;
21194 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
21195 nwritten
= display_string (spec
, string
, elt
,
21200 /* Assign to the glyphs written above the
21201 string where the `%x' came from, position
21205 struct glyph
*glyph
21206 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
21210 for (i
= 0; i
< nwritten
; ++i
)
21212 glyph
[i
].object
= elt
;
21213 glyph
[i
].charpos
= charpos
;
21230 /* A symbol: process the value of the symbol recursively
21231 as if it appeared here directly. Avoid error if symbol void.
21232 Special case: if value of symbol is a string, output the string
21235 register Lisp_Object tem
;
21237 /* If the variable is not marked as risky to set
21238 then its contents are risky to use. */
21239 if (NILP (Fget (elt
, Qrisky_local_variable
)))
21242 tem
= Fboundp (elt
);
21245 tem
= Fsymbol_value (elt
);
21246 /* If value is a string, output that string literally:
21247 don't check for % within it. */
21251 if (!EQ (tem
, elt
))
21253 /* Give up right away for nil or t. */
21263 register Lisp_Object car
, tem
;
21265 /* A cons cell: five distinct cases.
21266 If first element is :eval or :propertize, do something special.
21267 If first element is a string or a cons, process all the elements
21268 and effectively concatenate them.
21269 If first element is a negative number, truncate displaying cdr to
21270 at most that many characters. If positive, pad (with spaces)
21271 to at least that many characters.
21272 If first element is a symbol, process the cadr or caddr recursively
21273 according to whether the symbol's value is non-nil or nil. */
21275 if (EQ (car
, QCeval
))
21277 /* An element of the form (:eval FORM) means evaluate FORM
21278 and use the result as mode line elements. */
21283 if (CONSP (XCDR (elt
)))
21286 spec
= safe_eval (XCAR (XCDR (elt
)));
21287 n
+= display_mode_element (it
, depth
, field_width
- n
,
21288 precision
- n
, spec
, props
,
21292 else if (EQ (car
, QCpropertize
))
21294 /* An element of the form (:propertize ELT PROPS...)
21295 means display ELT but applying properties PROPS. */
21300 if (CONSP (XCDR (elt
)))
21301 n
+= display_mode_element (it
, depth
, field_width
- n
,
21302 precision
- n
, XCAR (XCDR (elt
)),
21303 XCDR (XCDR (elt
)), risky
);
21305 else if (SYMBOLP (car
))
21307 tem
= Fboundp (car
);
21311 /* elt is now the cdr, and we know it is a cons cell.
21312 Use its car if CAR has a non-nil value. */
21315 tem
= Fsymbol_value (car
);
21322 /* Symbol's value is nil (or symbol is unbound)
21323 Get the cddr of the original list
21324 and if possible find the caddr and use that. */
21328 else if (!CONSP (elt
))
21333 else if (INTEGERP (car
))
21335 register int lim
= XINT (car
);
21339 /* Negative int means reduce maximum width. */
21340 if (precision
<= 0)
21343 precision
= min (precision
, -lim
);
21347 /* Padding specified. Don't let it be more than
21348 current maximum. */
21350 lim
= min (precision
, lim
);
21352 /* If that's more padding than already wanted, queue it.
21353 But don't reduce padding already specified even if
21354 that is beyond the current truncation point. */
21355 field_width
= max (lim
, field_width
);
21359 else if (STRINGP (car
) || CONSP (car
))
21361 Lisp_Object halftail
= elt
;
21365 && (precision
<= 0 || n
< precision
))
21367 n
+= display_mode_element (it
, depth
,
21368 /* Do padding only after the last
21369 element in the list. */
21370 (! CONSP (XCDR (elt
))
21373 precision
- n
, XCAR (elt
),
21377 if ((len
& 1) == 0)
21378 halftail
= XCDR (halftail
);
21379 /* Check for cycle. */
21380 if (EQ (halftail
, elt
))
21389 elt
= build_string ("*invalid*");
21393 /* Pad to FIELD_WIDTH. */
21394 if (field_width
> 0 && n
< field_width
)
21396 switch (mode_line_target
)
21398 case MODE_LINE_NOPROP
:
21399 case MODE_LINE_TITLE
:
21400 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
21402 case MODE_LINE_STRING
:
21403 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
21405 case MODE_LINE_DISPLAY
:
21406 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
21415 /* Store a mode-line string element in mode_line_string_list.
21417 If STRING is non-null, display that C string. Otherwise, the Lisp
21418 string LISP_STRING is displayed.
21420 FIELD_WIDTH is the minimum number of output glyphs to produce.
21421 If STRING has fewer characters than FIELD_WIDTH, pad to the right
21422 with spaces. FIELD_WIDTH <= 0 means don't pad.
21424 PRECISION is the maximum number of characters to output from
21425 STRING. PRECISION <= 0 means don't truncate the string.
21427 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
21428 properties to the string.
21430 PROPS are the properties to add to the string.
21431 The mode_line_string_face face property is always added to the string.
21435 store_mode_line_string (const char *string
, Lisp_Object lisp_string
, int copy_string
,
21436 int field_width
, int precision
, Lisp_Object props
)
21441 if (string
!= NULL
)
21443 len
= strlen (string
);
21444 if (precision
> 0 && len
> precision
)
21446 lisp_string
= make_string (string
, len
);
21448 props
= mode_line_string_face_prop
;
21449 else if (!NILP (mode_line_string_face
))
21451 Lisp_Object face
= Fplist_get (props
, Qface
);
21452 props
= Fcopy_sequence (props
);
21454 face
= mode_line_string_face
;
21456 face
= list2 (face
, mode_line_string_face
);
21457 props
= Fplist_put (props
, Qface
, face
);
21459 Fadd_text_properties (make_number (0), make_number (len
),
21460 props
, lisp_string
);
21464 len
= XFASTINT (Flength (lisp_string
));
21465 if (precision
> 0 && len
> precision
)
21468 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
21471 if (!NILP (mode_line_string_face
))
21475 props
= Ftext_properties_at (make_number (0), lisp_string
);
21476 face
= Fplist_get (props
, Qface
);
21478 face
= mode_line_string_face
;
21480 face
= list2 (face
, mode_line_string_face
);
21481 props
= list2 (Qface
, face
);
21483 lisp_string
= Fcopy_sequence (lisp_string
);
21486 Fadd_text_properties (make_number (0), make_number (len
),
21487 props
, lisp_string
);
21492 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
21496 if (field_width
> len
)
21498 field_width
-= len
;
21499 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
21501 Fadd_text_properties (make_number (0), make_number (field_width
),
21502 props
, lisp_string
);
21503 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
21511 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
21513 doc
: /* Format a string out of a mode line format specification.
21514 First arg FORMAT specifies the mode line format (see `mode-line-format'
21515 for details) to use.
21517 By default, the format is evaluated for the currently selected window.
21519 Optional second arg FACE specifies the face property to put on all
21520 characters for which no face is specified. The value nil means the
21521 default face. The value t means whatever face the window's mode line
21522 currently uses (either `mode-line' or `mode-line-inactive',
21523 depending on whether the window is the selected window or not).
21524 An integer value means the value string has no text
21527 Optional third and fourth args WINDOW and BUFFER specify the window
21528 and buffer to use as the context for the formatting (defaults
21529 are the selected window and the WINDOW's buffer). */)
21530 (Lisp_Object format
, Lisp_Object face
,
21531 Lisp_Object window
, Lisp_Object buffer
)
21536 struct buffer
*old_buffer
= NULL
;
21538 int no_props
= INTEGERP (face
);
21539 ptrdiff_t count
= SPECPDL_INDEX ();
21541 int string_start
= 0;
21543 w
= decode_any_window (window
);
21544 XSETWINDOW (window
, w
);
21547 buffer
= w
->contents
;
21548 CHECK_BUFFER (buffer
);
21550 /* Make formatting the modeline a non-op when noninteractive, otherwise
21551 there will be problems later caused by a partially initialized frame. */
21552 if (NILP (format
) || noninteractive
)
21553 return empty_unibyte_string
;
21558 face_id
= (NILP (face
) || EQ (face
, Qdefault
)) ? DEFAULT_FACE_ID
21559 : EQ (face
, Qt
) ? (EQ (window
, selected_window
)
21560 ? MODE_LINE_FACE_ID
: MODE_LINE_INACTIVE_FACE_ID
)
21561 : EQ (face
, Qmode_line
) ? MODE_LINE_FACE_ID
21562 : EQ (face
, Qmode_line_inactive
) ? MODE_LINE_INACTIVE_FACE_ID
21563 : EQ (face
, Qheader_line
) ? HEADER_LINE_FACE_ID
21564 : EQ (face
, Qtool_bar
) ? TOOL_BAR_FACE_ID
21567 old_buffer
= current_buffer
;
21569 /* Save things including mode_line_proptrans_alist,
21570 and set that to nil so that we don't alter the outer value. */
21571 record_unwind_protect (unwind_format_mode_line
,
21572 format_mode_line_unwind_data
21573 (XFRAME (WINDOW_FRAME (w
)),
21574 old_buffer
, selected_window
, 1));
21575 mode_line_proptrans_alist
= Qnil
;
21577 Fselect_window (window
, Qt
);
21578 set_buffer_internal_1 (XBUFFER (buffer
));
21580 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
21584 mode_line_target
= MODE_LINE_NOPROP
;
21585 mode_line_string_face_prop
= Qnil
;
21586 mode_line_string_list
= Qnil
;
21587 string_start
= MODE_LINE_NOPROP_LEN (0);
21591 mode_line_target
= MODE_LINE_STRING
;
21592 mode_line_string_list
= Qnil
;
21593 mode_line_string_face
= face
;
21594 mode_line_string_face_prop
21595 = NILP (face
) ? Qnil
: list2 (Qface
, face
);
21598 push_kboard (FRAME_KBOARD (it
.f
));
21599 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
21604 len
= MODE_LINE_NOPROP_LEN (string_start
);
21605 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
21609 mode_line_string_list
= Fnreverse (mode_line_string_list
);
21610 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
21611 empty_unibyte_string
);
21614 unbind_to (count
, Qnil
);
21618 /* Write a null-terminated, right justified decimal representation of
21619 the positive integer D to BUF using a minimal field width WIDTH. */
21622 pint2str (register char *buf
, register int width
, register ptrdiff_t d
)
21624 register char *p
= buf
;
21632 *p
++ = d
% 10 + '0';
21637 for (width
-= (int) (p
- buf
); width
> 0; --width
)
21648 /* Write a null-terminated, right justified decimal and "human
21649 readable" representation of the nonnegative integer D to BUF using
21650 a minimal field width WIDTH. D should be smaller than 999.5e24. */
21652 static const char power_letter
[] =
21666 pint2hrstr (char *buf
, int width
, ptrdiff_t d
)
21668 /* We aim to represent the nonnegative integer D as
21669 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
21670 ptrdiff_t quotient
= d
;
21672 /* -1 means: do not use TENTHS. */
21676 /* Length of QUOTIENT.TENTHS as a string. */
21682 if (quotient
>= 1000)
21684 /* Scale to the appropriate EXPONENT. */
21687 remainder
= quotient
% 1000;
21691 while (quotient
>= 1000);
21693 /* Round to nearest and decide whether to use TENTHS or not. */
21696 tenths
= remainder
/ 100;
21697 if (remainder
% 100 >= 50)
21704 if (quotient
== 10)
21712 if (remainder
>= 500)
21714 if (quotient
< 999)
21725 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
21726 if (tenths
== -1 && quotient
<= 99)
21733 p
= psuffix
= buf
+ max (width
, length
);
21735 /* Print EXPONENT. */
21736 *psuffix
++ = power_letter
[exponent
];
21739 /* Print TENTHS. */
21742 *--p
= '0' + tenths
;
21746 /* Print QUOTIENT. */
21749 int digit
= quotient
% 10;
21750 *--p
= '0' + digit
;
21752 while ((quotient
/= 10) != 0);
21754 /* Print leading spaces. */
21759 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
21760 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
21761 type of CODING_SYSTEM. Return updated pointer into BUF. */
21763 static unsigned char invalid_eol_type
[] = "(*invalid*)";
21766 decode_mode_spec_coding (Lisp_Object coding_system
, register char *buf
, int eol_flag
)
21769 bool multibyte
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
21770 const unsigned char *eol_str
;
21772 /* The EOL conversion we are using. */
21773 Lisp_Object eoltype
;
21775 val
= CODING_SYSTEM_SPEC (coding_system
);
21778 if (!VECTORP (val
)) /* Not yet decided. */
21780 *buf
++ = multibyte
? '-' : ' ';
21782 eoltype
= eol_mnemonic_undecided
;
21783 /* Don't mention EOL conversion if it isn't decided. */
21788 Lisp_Object eolvalue
;
21790 attrs
= AREF (val
, 0);
21791 eolvalue
= AREF (val
, 2);
21794 ? XFASTINT (CODING_ATTR_MNEMONIC (attrs
))
21799 /* The EOL conversion that is normal on this system. */
21801 if (NILP (eolvalue
)) /* Not yet decided. */
21802 eoltype
= eol_mnemonic_undecided
;
21803 else if (VECTORP (eolvalue
)) /* Not yet decided. */
21804 eoltype
= eol_mnemonic_undecided
;
21805 else /* eolvalue is Qunix, Qdos, or Qmac. */
21806 eoltype
= (EQ (eolvalue
, Qunix
)
21807 ? eol_mnemonic_unix
21808 : (EQ (eolvalue
, Qdos
) == 1
21809 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
21815 /* Mention the EOL conversion if it is not the usual one. */
21816 if (STRINGP (eoltype
))
21818 eol_str
= SDATA (eoltype
);
21819 eol_str_len
= SBYTES (eoltype
);
21821 else if (CHARACTERP (eoltype
))
21823 unsigned char *tmp
= alloca (MAX_MULTIBYTE_LENGTH
);
21824 int c
= XFASTINT (eoltype
);
21825 eol_str_len
= CHAR_STRING (c
, tmp
);
21830 eol_str
= invalid_eol_type
;
21831 eol_str_len
= sizeof (invalid_eol_type
) - 1;
21833 memcpy (buf
, eol_str
, eol_str_len
);
21834 buf
+= eol_str_len
;
21840 /* Return a string for the output of a mode line %-spec for window W,
21841 generated by character C. FIELD_WIDTH > 0 means pad the string
21842 returned with spaces to that value. Return a Lisp string in
21843 *STRING if the resulting string is taken from that Lisp string.
21845 Note we operate on the current buffer for most purposes. */
21847 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
21849 static const char *
21850 decode_mode_spec (struct window
*w
, register int c
, int field_width
,
21851 Lisp_Object
*string
)
21854 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21855 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
21856 /* We are going to use f->decode_mode_spec_buffer as the buffer to
21857 produce strings from numerical values, so limit preposterously
21858 large values of FIELD_WIDTH to avoid overrunning the buffer's
21859 end. The size of the buffer is enough for FRAME_MESSAGE_BUF_SIZE
21860 bytes plus the terminating null. */
21861 int width
= min (field_width
, FRAME_MESSAGE_BUF_SIZE (f
));
21862 struct buffer
*b
= current_buffer
;
21870 if (!NILP (BVAR (b
, read_only
)))
21872 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21877 /* This differs from %* only for a modified read-only buffer. */
21878 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21880 if (!NILP (BVAR (b
, read_only
)))
21885 /* This differs from %* in ignoring read-only-ness. */
21886 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21898 if (command_loop_level
> 5)
21900 p
= decode_mode_spec_buf
;
21901 for (i
= 0; i
< command_loop_level
; i
++)
21904 return decode_mode_spec_buf
;
21912 if (command_loop_level
> 5)
21914 p
= decode_mode_spec_buf
;
21915 for (i
= 0; i
< command_loop_level
; i
++)
21918 return decode_mode_spec_buf
;
21925 /* Let lots_of_dashes be a string of infinite length. */
21926 if (mode_line_target
== MODE_LINE_NOPROP
21927 || mode_line_target
== MODE_LINE_STRING
)
21929 if (field_width
<= 0
21930 || field_width
> sizeof (lots_of_dashes
))
21932 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
21933 decode_mode_spec_buf
[i
] = '-';
21934 decode_mode_spec_buf
[i
] = '\0';
21935 return decode_mode_spec_buf
;
21938 return lots_of_dashes
;
21942 obj
= BVAR (b
, name
);
21946 /* %c and %l are ignored in `frame-title-format'.
21947 (In redisplay_internal, the frame title is drawn _before_ the
21948 windows are updated, so the stuff which depends on actual
21949 window contents (such as %l) may fail to render properly, or
21950 even crash emacs.) */
21951 if (mode_line_target
== MODE_LINE_TITLE
)
21955 ptrdiff_t col
= current_column ();
21956 w
->column_number_displayed
= col
;
21957 pint2str (decode_mode_spec_buf
, width
, col
);
21958 return decode_mode_spec_buf
;
21962 #ifndef SYSTEM_MALLOC
21964 if (NILP (Vmemory_full
))
21967 return "!MEM FULL! ";
21974 /* %F displays the frame name. */
21975 if (!NILP (f
->title
))
21976 return SSDATA (f
->title
);
21977 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
21978 return SSDATA (f
->name
);
21982 obj
= BVAR (b
, filename
);
21987 ptrdiff_t size
= ZV
- BEGV
;
21988 pint2str (decode_mode_spec_buf
, width
, size
);
21989 return decode_mode_spec_buf
;
21994 ptrdiff_t size
= ZV
- BEGV
;
21995 pint2hrstr (decode_mode_spec_buf
, width
, size
);
21996 return decode_mode_spec_buf
;
22001 ptrdiff_t startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
22002 ptrdiff_t topline
, nlines
, height
;
22005 /* %c and %l are ignored in `frame-title-format'. */
22006 if (mode_line_target
== MODE_LINE_TITLE
)
22009 startpos
= marker_position (w
->start
);
22010 startpos_byte
= marker_byte_position (w
->start
);
22011 height
= WINDOW_TOTAL_LINES (w
);
22013 /* If we decided that this buffer isn't suitable for line numbers,
22014 don't forget that too fast. */
22015 if (w
->base_line_pos
== -1)
22018 /* If the buffer is very big, don't waste time. */
22019 if (INTEGERP (Vline_number_display_limit
)
22020 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
22022 w
->base_line_pos
= 0;
22023 w
->base_line_number
= 0;
22027 if (w
->base_line_number
> 0
22028 && w
->base_line_pos
> 0
22029 && w
->base_line_pos
<= startpos
)
22031 line
= w
->base_line_number
;
22032 linepos
= w
->base_line_pos
;
22033 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
22038 linepos
= BUF_BEGV (b
);
22039 linepos_byte
= BUF_BEGV_BYTE (b
);
22042 /* Count lines from base line to window start position. */
22043 nlines
= display_count_lines (linepos_byte
,
22047 topline
= nlines
+ line
;
22049 /* Determine a new base line, if the old one is too close
22050 or too far away, or if we did not have one.
22051 "Too close" means it's plausible a scroll-down would
22052 go back past it. */
22053 if (startpos
== BUF_BEGV (b
))
22055 w
->base_line_number
= topline
;
22056 w
->base_line_pos
= BUF_BEGV (b
);
22058 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
22059 || linepos
== BUF_BEGV (b
))
22061 ptrdiff_t limit
= BUF_BEGV (b
);
22062 ptrdiff_t limit_byte
= BUF_BEGV_BYTE (b
);
22063 ptrdiff_t position
;
22064 ptrdiff_t distance
=
22065 (height
* 2 + 30) * line_number_display_limit_width
;
22067 if (startpos
- distance
> limit
)
22069 limit
= startpos
- distance
;
22070 limit_byte
= CHAR_TO_BYTE (limit
);
22073 nlines
= display_count_lines (startpos_byte
,
22075 - (height
* 2 + 30),
22077 /* If we couldn't find the lines we wanted within
22078 line_number_display_limit_width chars per line,
22079 give up on line numbers for this window. */
22080 if (position
== limit_byte
&& limit
== startpos
- distance
)
22082 w
->base_line_pos
= -1;
22083 w
->base_line_number
= 0;
22087 w
->base_line_number
= topline
- nlines
;
22088 w
->base_line_pos
= BYTE_TO_CHAR (position
);
22091 /* Now count lines from the start pos to point. */
22092 nlines
= display_count_lines (startpos_byte
,
22093 PT_BYTE
, PT
, &junk
);
22095 /* Record that we did display the line number. */
22096 line_number_displayed
= 1;
22098 /* Make the string to show. */
22099 pint2str (decode_mode_spec_buf
, width
, topline
+ nlines
);
22100 return decode_mode_spec_buf
;
22103 char* p
= decode_mode_spec_buf
;
22104 int pad
= width
- 2;
22110 return decode_mode_spec_buf
;
22116 obj
= BVAR (b
, mode_name
);
22120 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
22126 ptrdiff_t pos
= marker_position (w
->start
);
22127 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
22129 if (w
->window_end_pos
<= BUF_Z (b
) - BUF_ZV (b
))
22131 if (pos
<= BUF_BEGV (b
))
22136 else if (pos
<= BUF_BEGV (b
))
22140 if (total
> 1000000)
22141 /* Do it differently for a large value, to avoid overflow. */
22142 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
22144 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
22145 /* We can't normally display a 3-digit number,
22146 so get us a 2-digit number that is close. */
22149 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
22150 return decode_mode_spec_buf
;
22154 /* Display percentage of size above the bottom of the screen. */
22157 ptrdiff_t toppos
= marker_position (w
->start
);
22158 ptrdiff_t botpos
= BUF_Z (b
) - w
->window_end_pos
;
22159 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
22161 if (botpos
>= BUF_ZV (b
))
22163 if (toppos
<= BUF_BEGV (b
))
22170 if (total
> 1000000)
22171 /* Do it differently for a large value, to avoid overflow. */
22172 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
22174 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
22175 /* We can't normally display a 3-digit number,
22176 so get us a 2-digit number that is close. */
22179 if (toppos
<= BUF_BEGV (b
))
22180 sprintf (decode_mode_spec_buf
, "Top%2"pD
"d%%", total
);
22182 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
22183 return decode_mode_spec_buf
;
22188 /* status of process */
22189 obj
= Fget_buffer_process (Fcurrent_buffer ());
22191 return "no process";
22193 obj
= Fsymbol_name (Fprocess_status (obj
));
22199 ptrdiff_t count
= inhibit_garbage_collection ();
22200 Lisp_Object val
= call1 (intern ("file-remote-p"),
22201 BVAR (current_buffer
, directory
));
22202 unbind_to (count
, Qnil
);
22211 /* coding-system (not including end-of-line format) */
22213 /* coding-system (including end-of-line type) */
22215 int eol_flag
= (c
== 'Z');
22216 char *p
= decode_mode_spec_buf
;
22218 if (! FRAME_WINDOW_P (f
))
22220 /* No need to mention EOL here--the terminal never needs
22221 to do EOL conversion. */
22222 p
= decode_mode_spec_coding (CODING_ID_NAME
22223 (FRAME_KEYBOARD_CODING (f
)->id
),
22225 p
= decode_mode_spec_coding (CODING_ID_NAME
22226 (FRAME_TERMINAL_CODING (f
)->id
),
22229 p
= decode_mode_spec_coding (BVAR (b
, buffer_file_coding_system
),
22232 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
22233 #ifdef subprocesses
22234 obj
= Fget_buffer_process (Fcurrent_buffer ());
22235 if (PROCESSP (obj
))
22237 p
= decode_mode_spec_coding
22238 (XPROCESS (obj
)->decode_coding_system
, p
, eol_flag
);
22239 p
= decode_mode_spec_coding
22240 (XPROCESS (obj
)->encode_coding_system
, p
, eol_flag
);
22242 #endif /* subprocesses */
22245 return decode_mode_spec_buf
;
22252 return SSDATA (obj
);
22259 /* Count up to COUNT lines starting from START_BYTE. COUNT negative
22260 means count lines back from START_BYTE. But don't go beyond
22261 LIMIT_BYTE. Return the number of lines thus found (always
22264 Set *BYTE_POS_PTR to the byte position where we stopped. This is
22265 either the position COUNT lines after/before START_BYTE, if we
22266 found COUNT lines, or LIMIT_BYTE if we hit the limit before finding
22270 display_count_lines (ptrdiff_t start_byte
,
22271 ptrdiff_t limit_byte
, ptrdiff_t count
,
22272 ptrdiff_t *byte_pos_ptr
)
22274 register unsigned char *cursor
;
22275 unsigned char *base
;
22277 register ptrdiff_t ceiling
;
22278 register unsigned char *ceiling_addr
;
22279 ptrdiff_t orig_count
= count
;
22281 /* If we are not in selective display mode,
22282 check only for newlines. */
22283 int selective_display
= (!NILP (BVAR (current_buffer
, selective_display
))
22284 && !INTEGERP (BVAR (current_buffer
, selective_display
)));
22288 while (start_byte
< limit_byte
)
22290 ceiling
= BUFFER_CEILING_OF (start_byte
);
22291 ceiling
= min (limit_byte
- 1, ceiling
);
22292 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
22293 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
22297 if (selective_display
)
22299 while (*cursor
!= '\n' && *cursor
!= 015
22300 && ++cursor
!= ceiling_addr
)
22302 if (cursor
== ceiling_addr
)
22307 cursor
= memchr (cursor
, '\n', ceiling_addr
- cursor
);
22316 start_byte
+= cursor
- base
;
22317 *byte_pos_ptr
= start_byte
;
22321 while (cursor
< ceiling_addr
);
22323 start_byte
+= ceiling_addr
- base
;
22328 while (start_byte
> limit_byte
)
22330 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
22331 ceiling
= max (limit_byte
, ceiling
);
22332 ceiling_addr
= BYTE_POS_ADDR (ceiling
);
22333 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
22336 if (selective_display
)
22338 while (--cursor
>= ceiling_addr
22339 && *cursor
!= '\n' && *cursor
!= 015)
22341 if (cursor
< ceiling_addr
)
22346 cursor
= memrchr (ceiling_addr
, '\n', cursor
- ceiling_addr
);
22353 start_byte
+= cursor
- base
+ 1;
22354 *byte_pos_ptr
= start_byte
;
22355 /* When scanning backwards, we should
22356 not count the newline posterior to which we stop. */
22357 return - orig_count
- 1;
22360 start_byte
+= ceiling_addr
- base
;
22364 *byte_pos_ptr
= limit_byte
;
22367 return - orig_count
+ count
;
22368 return orig_count
- count
;
22374 /***********************************************************************
22376 ***********************************************************************/
22378 /* Display a NUL-terminated string, starting with index START.
22380 If STRING is non-null, display that C string. Otherwise, the Lisp
22381 string LISP_STRING is displayed. There's a case that STRING is
22382 non-null and LISP_STRING is not nil. It means STRING is a string
22383 data of LISP_STRING. In that case, we display LISP_STRING while
22384 ignoring its text properties.
22386 If FACE_STRING is not nil, FACE_STRING_POS is a position in
22387 FACE_STRING. Display STRING or LISP_STRING with the face at
22388 FACE_STRING_POS in FACE_STRING:
22390 Display the string in the environment given by IT, but use the
22391 standard display table, temporarily.
22393 FIELD_WIDTH is the minimum number of output glyphs to produce.
22394 If STRING has fewer characters than FIELD_WIDTH, pad to the right
22395 with spaces. If STRING has more characters, more than FIELD_WIDTH
22396 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
22398 PRECISION is the maximum number of characters to output from
22399 STRING. PRECISION < 0 means don't truncate the string.
22401 This is roughly equivalent to printf format specifiers:
22403 FIELD_WIDTH PRECISION PRINTF
22404 ----------------------------------------
22410 MULTIBYTE zero means do not display multibyte chars, > 0 means do
22411 display them, and < 0 means obey the current buffer's value of
22412 enable_multibyte_characters.
22414 Value is the number of columns displayed. */
22417 display_string (const char *string
, Lisp_Object lisp_string
, Lisp_Object face_string
,
22418 ptrdiff_t face_string_pos
, ptrdiff_t start
, struct it
*it
,
22419 int field_width
, int precision
, int max_x
, int multibyte
)
22421 int hpos_at_start
= it
->hpos
;
22422 int saved_face_id
= it
->face_id
;
22423 struct glyph_row
*row
= it
->glyph_row
;
22424 ptrdiff_t it_charpos
;
22426 /* Initialize the iterator IT for iteration over STRING beginning
22427 with index START. */
22428 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
22429 precision
, field_width
, multibyte
);
22430 if (string
&& STRINGP (lisp_string
))
22431 /* LISP_STRING is the one returned by decode_mode_spec. We should
22432 ignore its text properties. */
22433 it
->stop_charpos
= it
->end_charpos
;
22435 /* If displaying STRING, set up the face of the iterator from
22436 FACE_STRING, if that's given. */
22437 if (STRINGP (face_string
))
22443 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
22444 0, it
->region_beg_charpos
,
22445 it
->region_end_charpos
,
22446 &endptr
, it
->base_face_id
, 0);
22447 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22448 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
22451 /* Set max_x to the maximum allowed X position. Don't let it go
22452 beyond the right edge of the window. */
22454 max_x
= it
->last_visible_x
;
22456 max_x
= min (max_x
, it
->last_visible_x
);
22458 /* Skip over display elements that are not visible. because IT->w is
22460 if (it
->current_x
< it
->first_visible_x
)
22461 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
22462 MOVE_TO_POS
| MOVE_TO_X
);
22464 row
->ascent
= it
->max_ascent
;
22465 row
->height
= it
->max_ascent
+ it
->max_descent
;
22466 row
->phys_ascent
= it
->max_phys_ascent
;
22467 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
22468 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
22470 if (STRINGP (it
->string
))
22471 it_charpos
= IT_STRING_CHARPOS (*it
);
22473 it_charpos
= IT_CHARPOS (*it
);
22475 /* This condition is for the case that we are called with current_x
22476 past last_visible_x. */
22477 while (it
->current_x
< max_x
)
22479 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
22481 /* Get the next display element. */
22482 if (!get_next_display_element (it
))
22485 /* Produce glyphs. */
22486 x_before
= it
->current_x
;
22487 n_glyphs_before
= row
->used
[TEXT_AREA
];
22488 PRODUCE_GLYPHS (it
);
22490 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
22493 while (i
< nglyphs
)
22495 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
22497 if (it
->line_wrap
!= TRUNCATE
22498 && x
+ glyph
->pixel_width
> max_x
)
22500 /* End of continued line or max_x reached. */
22501 if (CHAR_GLYPH_PADDING_P (*glyph
))
22503 /* A wide character is unbreakable. */
22504 if (row
->reversed_p
)
22505 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
22506 - n_glyphs_before
);
22507 row
->used
[TEXT_AREA
] = n_glyphs_before
;
22508 it
->current_x
= x_before
;
22512 if (row
->reversed_p
)
22513 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
22514 - (n_glyphs_before
+ i
));
22515 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
22520 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
22522 /* Glyph is at least partially visible. */
22524 if (x
< it
->first_visible_x
)
22525 row
->x
= x
- it
->first_visible_x
;
22529 /* Glyph is off the left margin of the display area.
22530 Should not happen. */
22534 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
22535 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
22536 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
22537 row
->phys_height
= max (row
->phys_height
,
22538 it
->max_phys_ascent
+ it
->max_phys_descent
);
22539 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
22540 it
->max_extra_line_spacing
);
22541 x
+= glyph
->pixel_width
;
22545 /* Stop if max_x reached. */
22549 /* Stop at line ends. */
22550 if (ITERATOR_AT_END_OF_LINE_P (it
))
22552 it
->continuation_lines_width
= 0;
22556 set_iterator_to_next (it
, 1);
22557 if (STRINGP (it
->string
))
22558 it_charpos
= IT_STRING_CHARPOS (*it
);
22560 it_charpos
= IT_CHARPOS (*it
);
22562 /* Stop if truncating at the right edge. */
22563 if (it
->line_wrap
== TRUNCATE
22564 && it
->current_x
>= it
->last_visible_x
)
22566 /* Add truncation mark, but don't do it if the line is
22567 truncated at a padding space. */
22568 if (it_charpos
< it
->string_nchars
)
22570 if (!FRAME_WINDOW_P (it
->f
))
22574 if (it
->current_x
> it
->last_visible_x
)
22576 if (!row
->reversed_p
)
22578 for (ii
= row
->used
[TEXT_AREA
] - 1; ii
> 0; --ii
)
22579 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
22584 for (ii
= 0; ii
< row
->used
[TEXT_AREA
]; ii
++)
22585 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
22587 unproduce_glyphs (it
, ii
+ 1);
22588 ii
= row
->used
[TEXT_AREA
] - (ii
+ 1);
22590 for (n
= row
->used
[TEXT_AREA
]; ii
< n
; ++ii
)
22592 row
->used
[TEXT_AREA
] = ii
;
22593 produce_special_glyphs (it
, IT_TRUNCATION
);
22596 produce_special_glyphs (it
, IT_TRUNCATION
);
22598 row
->truncated_on_right_p
= 1;
22604 /* Maybe insert a truncation at the left. */
22605 if (it
->first_visible_x
22608 if (!FRAME_WINDOW_P (it
->f
)
22609 || (row
->reversed_p
22610 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
22611 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
22612 insert_left_trunc_glyphs (it
);
22613 row
->truncated_on_left_p
= 1;
22616 it
->face_id
= saved_face_id
;
22618 /* Value is number of columns displayed. */
22619 return it
->hpos
- hpos_at_start
;
22624 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
22625 appears as an element of LIST or as the car of an element of LIST.
22626 If PROPVAL is a list, compare each element against LIST in that
22627 way, and return 1/2 if any element of PROPVAL is found in LIST.
22628 Otherwise return 0. This function cannot quit.
22629 The return value is 2 if the text is invisible but with an ellipsis
22630 and 1 if it's invisible and without an ellipsis. */
22633 invisible_p (register Lisp_Object propval
, Lisp_Object list
)
22635 register Lisp_Object tail
, proptail
;
22637 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
22639 register Lisp_Object tem
;
22641 if (EQ (propval
, tem
))
22643 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
22644 return NILP (XCDR (tem
)) ? 1 : 2;
22647 if (CONSP (propval
))
22649 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
22651 Lisp_Object propelt
;
22652 propelt
= XCAR (proptail
);
22653 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
22655 register Lisp_Object tem
;
22657 if (EQ (propelt
, tem
))
22659 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
22660 return NILP (XCDR (tem
)) ? 1 : 2;
22668 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
22669 doc
: /* Non-nil if the property makes the text invisible.
22670 POS-OR-PROP can be a marker or number, in which case it is taken to be
22671 a position in the current buffer and the value of the `invisible' property
22672 is checked; or it can be some other value, which is then presumed to be the
22673 value of the `invisible' property of the text of interest.
22674 The non-nil value returned can be t for truly invisible text or something
22675 else if the text is replaced by an ellipsis. */)
22676 (Lisp_Object pos_or_prop
)
22679 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
22680 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
22682 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
22683 return (invis
== 0 ? Qnil
22685 : make_number (invis
));
22688 /* Calculate a width or height in pixels from a specification using
22689 the following elements:
22692 NUM - a (fractional) multiple of the default font width/height
22693 (NUM) - specifies exactly NUM pixels
22694 UNIT - a fixed number of pixels, see below.
22695 ELEMENT - size of a display element in pixels, see below.
22696 (NUM . SPEC) - equals NUM * SPEC
22697 (+ SPEC SPEC ...) - add pixel values
22698 (- SPEC SPEC ...) - subtract pixel values
22699 (- SPEC) - negate pixel value
22702 INT or FLOAT - a number constant
22703 SYMBOL - use symbol's (buffer local) variable binding.
22706 in - pixels per inch *)
22707 mm - pixels per 1/1000 meter *)
22708 cm - pixels per 1/100 meter *)
22709 width - width of current font in pixels.
22710 height - height of current font in pixels.
22712 *) using the ratio(s) defined in display-pixels-per-inch.
22716 left-fringe - left fringe width in pixels
22717 right-fringe - right fringe width in pixels
22719 left-margin - left margin width in pixels
22720 right-margin - right margin width in pixels
22722 scroll-bar - scroll-bar area width in pixels
22726 Pixels corresponding to 5 inches:
22729 Total width of non-text areas on left side of window (if scroll-bar is on left):
22730 '(space :width (+ left-fringe left-margin scroll-bar))
22732 Align to first text column (in header line):
22733 '(space :align-to 0)
22735 Align to middle of text area minus half the width of variable `my-image'
22736 containing a loaded image:
22737 '(space :align-to (0.5 . (- text my-image)))
22739 Width of left margin minus width of 1 character in the default font:
22740 '(space :width (- left-margin 1))
22742 Width of left margin minus width of 2 characters in the current font:
22743 '(space :width (- left-margin (2 . width)))
22745 Center 1 character over left-margin (in header line):
22746 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
22748 Different ways to express width of left fringe plus left margin minus one pixel:
22749 '(space :width (- (+ left-fringe left-margin) (1)))
22750 '(space :width (+ left-fringe left-margin (- (1))))
22751 '(space :width (+ left-fringe left-margin (-1)))
22756 calc_pixel_width_or_height (double *res
, struct it
*it
, Lisp_Object prop
,
22757 struct font
*font
, int width_p
, int *align_to
)
22761 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
22762 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
22765 return OK_PIXELS (0);
22767 eassert (FRAME_LIVE_P (it
->f
));
22769 if (SYMBOLP (prop
))
22771 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
22773 char *unit
= SSDATA (SYMBOL_NAME (prop
));
22775 if (unit
[0] == 'i' && unit
[1] == 'n')
22777 else if (unit
[0] == 'm' && unit
[1] == 'm')
22779 else if (unit
[0] == 'c' && unit
[1] == 'm')
22785 double ppi
= (width_p
? FRAME_RES_X (it
->f
)
22786 : FRAME_RES_Y (it
->f
));
22789 return OK_PIXELS (ppi
/ pixels
);
22794 #ifdef HAVE_WINDOW_SYSTEM
22795 if (EQ (prop
, Qheight
))
22796 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
22797 if (EQ (prop
, Qwidth
))
22798 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
22800 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
22801 return OK_PIXELS (1);
22804 if (EQ (prop
, Qtext
))
22805 return OK_PIXELS (width_p
22806 ? window_box_width (it
->w
, TEXT_AREA
)
22807 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
22809 if (align_to
&& *align_to
< 0)
22812 if (EQ (prop
, Qleft
))
22813 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
22814 if (EQ (prop
, Qright
))
22815 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
22816 if (EQ (prop
, Qcenter
))
22817 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
22818 + window_box_width (it
->w
, TEXT_AREA
) / 2);
22819 if (EQ (prop
, Qleft_fringe
))
22820 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22821 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
22822 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
22823 if (EQ (prop
, Qright_fringe
))
22824 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22825 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
22826 : window_box_right_offset (it
->w
, TEXT_AREA
));
22827 if (EQ (prop
, Qleft_margin
))
22828 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
22829 if (EQ (prop
, Qright_margin
))
22830 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
22831 if (EQ (prop
, Qscroll_bar
))
22832 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
22834 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
22835 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22836 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
22841 if (EQ (prop
, Qleft_fringe
))
22842 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
22843 if (EQ (prop
, Qright_fringe
))
22844 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
22845 if (EQ (prop
, Qleft_margin
))
22846 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
22847 if (EQ (prop
, Qright_margin
))
22848 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
22849 if (EQ (prop
, Qscroll_bar
))
22850 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
22853 prop
= buffer_local_value_1 (prop
, it
->w
->contents
);
22854 if (EQ (prop
, Qunbound
))
22858 if (INTEGERP (prop
) || FLOATP (prop
))
22860 int base_unit
= (width_p
22861 ? FRAME_COLUMN_WIDTH (it
->f
)
22862 : FRAME_LINE_HEIGHT (it
->f
));
22863 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
22868 Lisp_Object car
= XCAR (prop
);
22869 Lisp_Object cdr
= XCDR (prop
);
22873 #ifdef HAVE_WINDOW_SYSTEM
22874 if (FRAME_WINDOW_P (it
->f
)
22875 && valid_image_p (prop
))
22877 ptrdiff_t id
= lookup_image (it
->f
, prop
);
22878 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
22880 return OK_PIXELS (width_p
? img
->width
: img
->height
);
22882 #ifdef HAVE_XWIDGETS
22883 if (FRAME_WINDOW_P (it
->f
) && valid_xwidget_spec_p (prop
))
22885 printf("calc_pixel_width_or_height: return dummy size FIXME\n");
22886 return OK_PIXELS (width_p
? 100 : 100);
22890 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
22896 while (CONSP (cdr
))
22898 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
22899 font
, width_p
, align_to
))
22902 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
22907 if (EQ (car
, Qminus
))
22909 return OK_PIXELS (pixels
);
22912 car
= buffer_local_value_1 (car
, it
->w
->contents
);
22913 if (EQ (car
, Qunbound
))
22917 if (INTEGERP (car
) || FLOATP (car
))
22920 pixels
= XFLOATINT (car
);
22922 return OK_PIXELS (pixels
);
22923 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
22924 font
, width_p
, align_to
))
22925 return OK_PIXELS (pixels
* fact
);
22936 /***********************************************************************
22938 ***********************************************************************/
22940 #ifdef HAVE_WINDOW_SYSTEM
22945 dump_glyph_string (struct glyph_string
*s
)
22947 fprintf (stderr
, "glyph string\n");
22948 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
22949 s
->x
, s
->y
, s
->width
, s
->height
);
22950 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
22951 fprintf (stderr
, " hl = %d\n", s
->hl
);
22952 fprintf (stderr
, " left overhang = %d, right = %d\n",
22953 s
->left_overhang
, s
->right_overhang
);
22954 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
22955 fprintf (stderr
, " extends to end of line = %d\n",
22956 s
->extends_to_end_of_line_p
);
22957 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
22958 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
22961 #endif /* GLYPH_DEBUG */
22963 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
22964 of XChar2b structures for S; it can't be allocated in
22965 init_glyph_string because it must be allocated via `alloca'. W
22966 is the window on which S is drawn. ROW and AREA are the glyph row
22967 and area within the row from which S is constructed. START is the
22968 index of the first glyph structure covered by S. HL is a
22969 face-override for drawing S. */
22972 #define OPTIONAL_HDC(hdc) HDC hdc,
22973 #define DECLARE_HDC(hdc) HDC hdc;
22974 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
22975 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
22978 #ifndef OPTIONAL_HDC
22979 #define OPTIONAL_HDC(hdc)
22980 #define DECLARE_HDC(hdc)
22981 #define ALLOCATE_HDC(hdc, f)
22982 #define RELEASE_HDC(hdc, f)
22986 init_glyph_string (struct glyph_string
*s
,
22988 XChar2b
*char2b
, struct window
*w
, struct glyph_row
*row
,
22989 enum glyph_row_area area
, int start
, enum draw_glyphs_face hl
)
22991 memset (s
, 0, sizeof *s
);
22993 s
->f
= XFRAME (w
->frame
);
22997 s
->display
= FRAME_X_DISPLAY (s
->f
);
22998 s
->window
= FRAME_X_WINDOW (s
->f
);
22999 s
->char2b
= char2b
;
23003 s
->first_glyph
= row
->glyphs
[area
] + start
;
23004 s
->height
= row
->height
;
23005 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
23006 s
->ybase
= s
->y
+ row
->ascent
;
23010 /* Append the list of glyph strings with head H and tail T to the list
23011 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
23014 append_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
23015 struct glyph_string
*h
, struct glyph_string
*t
)
23029 /* Prepend the list of glyph strings with head H and tail T to the
23030 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
23034 prepend_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
23035 struct glyph_string
*h
, struct glyph_string
*t
)
23049 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
23050 Set *HEAD and *TAIL to the resulting list. */
23053 append_glyph_string (struct glyph_string
**head
, struct glyph_string
**tail
,
23054 struct glyph_string
*s
)
23056 s
->next
= s
->prev
= NULL
;
23057 append_glyph_string_lists (head
, tail
, s
, s
);
23061 /* Get face and two-byte form of character C in face FACE_ID on frame F.
23062 The encoding of C is returned in *CHAR2B. DISPLAY_P non-zero means
23063 make sure that X resources for the face returned are allocated.
23064 Value is a pointer to a realized face that is ready for display if
23065 DISPLAY_P is non-zero. */
23067 static struct face
*
23068 get_char_face_and_encoding (struct frame
*f
, int c
, int face_id
,
23069 XChar2b
*char2b
, int display_p
)
23071 struct face
*face
= FACE_FROM_ID (f
, face_id
);
23076 code
= face
->font
->driver
->encode_char (face
->font
, c
);
23078 if (code
== FONT_INVALID_CODE
)
23081 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
23083 /* Make sure X resources of the face are allocated. */
23084 #ifdef HAVE_X_WINDOWS
23088 eassert (face
!= NULL
);
23089 PREPARE_FACE_FOR_DISPLAY (f
, face
);
23096 /* Get face and two-byte form of character glyph GLYPH on frame F.
23097 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
23098 a pointer to a realized face that is ready for display. */
23100 static struct face
*
23101 get_glyph_face_and_encoding (struct frame
*f
, struct glyph
*glyph
,
23102 XChar2b
*char2b
, int *two_byte_p
)
23107 eassert (glyph
->type
== CHAR_GLYPH
);
23108 face
= FACE_FROM_ID (f
, glyph
->face_id
);
23110 /* Make sure X resources of the face are allocated. */
23111 eassert (face
!= NULL
);
23112 PREPARE_FACE_FOR_DISPLAY (f
, face
);
23119 if (CHAR_BYTE8_P (glyph
->u
.ch
))
23120 code
= CHAR_TO_BYTE8 (glyph
->u
.ch
);
23122 code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
23124 if (code
== FONT_INVALID_CODE
)
23128 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
23133 /* Get glyph code of character C in FONT in the two-byte form CHAR2B.
23134 Return 1 if FONT has a glyph for C, otherwise return 0. */
23137 get_char_glyph_code (int c
, struct font
*font
, XChar2b
*char2b
)
23141 if (CHAR_BYTE8_P (c
))
23142 code
= CHAR_TO_BYTE8 (c
);
23144 code
= font
->driver
->encode_char (font
, c
);
23146 if (code
== FONT_INVALID_CODE
)
23148 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
23153 /* Fill glyph string S with composition components specified by S->cmp.
23155 BASE_FACE is the base face of the composition.
23156 S->cmp_from is the index of the first component for S.
23158 OVERLAPS non-zero means S should draw the foreground only, and use
23159 its physical height for clipping. See also draw_glyphs.
23161 Value is the index of a component not in S. */
23164 fill_composite_glyph_string (struct glyph_string
*s
, struct face
*base_face
,
23168 /* For all glyphs of this composition, starting at the offset
23169 S->cmp_from, until we reach the end of the definition or encounter a
23170 glyph that requires the different face, add it to S. */
23175 s
->for_overlaps
= overlaps
;
23178 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
23180 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
23182 /* TAB in a composition means display glyphs with padding space
23183 on the left or right. */
23186 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
23189 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
23196 s
->font
= s
->face
->font
;
23198 else if (s
->face
!= face
)
23206 if (s
->face
== NULL
)
23208 s
->face
= base_face
->ascii_face
;
23209 s
->font
= s
->face
->font
;
23212 /* All glyph strings for the same composition has the same width,
23213 i.e. the width set for the first component of the composition. */
23214 s
->width
= s
->first_glyph
->pixel_width
;
23216 /* If the specified font could not be loaded, use the frame's
23217 default font, but record the fact that we couldn't load it in
23218 the glyph string so that we can draw rectangles for the
23219 characters of the glyph string. */
23220 if (s
->font
== NULL
)
23222 s
->font_not_found_p
= 1;
23223 s
->font
= FRAME_FONT (s
->f
);
23226 /* Adjust base line for subscript/superscript text. */
23227 s
->ybase
+= s
->first_glyph
->voffset
;
23229 /* This glyph string must always be drawn with 16-bit functions. */
23236 fill_gstring_glyph_string (struct glyph_string
*s
, int face_id
,
23237 int start
, int end
, int overlaps
)
23239 struct glyph
*glyph
, *last
;
23240 Lisp_Object lgstring
;
23243 s
->for_overlaps
= overlaps
;
23244 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23245 last
= s
->row
->glyphs
[s
->area
] + end
;
23246 s
->cmp_id
= glyph
->u
.cmp
.id
;
23247 s
->cmp_from
= glyph
->slice
.cmp
.from
;
23248 s
->cmp_to
= glyph
->slice
.cmp
.to
+ 1;
23249 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
23250 lgstring
= composition_gstring_from_id (s
->cmp_id
);
23251 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
23253 while (glyph
< last
23254 && glyph
->u
.cmp
.automatic
23255 && glyph
->u
.cmp
.id
== s
->cmp_id
23256 && s
->cmp_to
== glyph
->slice
.cmp
.from
)
23257 s
->cmp_to
= (glyph
++)->slice
.cmp
.to
+ 1;
23259 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
23261 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
23262 unsigned code
= LGLYPH_CODE (lglyph
);
23264 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
23266 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
23267 return glyph
- s
->row
->glyphs
[s
->area
];
23271 /* Fill glyph string S from a sequence glyphs for glyphless characters.
23272 See the comment of fill_glyph_string for arguments.
23273 Value is the index of the first glyph not in S. */
23277 fill_glyphless_glyph_string (struct glyph_string
*s
, int face_id
,
23278 int start
, int end
, int overlaps
)
23280 struct glyph
*glyph
, *last
;
23283 eassert (s
->first_glyph
->type
== GLYPHLESS_GLYPH
);
23284 s
->for_overlaps
= overlaps
;
23285 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23286 last
= s
->row
->glyphs
[s
->area
] + end
;
23287 voffset
= glyph
->voffset
;
23288 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
23289 s
->font
= s
->face
->font
? s
->face
->font
: FRAME_FONT (s
->f
);
23291 s
->width
= glyph
->pixel_width
;
23293 while (glyph
< last
23294 && glyph
->type
== GLYPHLESS_GLYPH
23295 && glyph
->voffset
== voffset
23296 && glyph
->face_id
== face_id
)
23299 s
->width
+= glyph
->pixel_width
;
23302 s
->ybase
+= voffset
;
23303 return glyph
- s
->row
->glyphs
[s
->area
];
23307 /* Fill glyph string S from a sequence of character glyphs.
23309 FACE_ID is the face id of the string. START is the index of the
23310 first glyph to consider, END is the index of the last + 1.
23311 OVERLAPS non-zero means S should draw the foreground only, and use
23312 its physical height for clipping. See also draw_glyphs.
23314 Value is the index of the first glyph not in S. */
23317 fill_glyph_string (struct glyph_string
*s
, int face_id
,
23318 int start
, int end
, int overlaps
)
23320 struct glyph
*glyph
, *last
;
23322 int glyph_not_available_p
;
23324 eassert (s
->f
== XFRAME (s
->w
->frame
));
23325 eassert (s
->nchars
== 0);
23326 eassert (start
>= 0 && end
> start
);
23328 s
->for_overlaps
= overlaps
;
23329 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23330 last
= s
->row
->glyphs
[s
->area
] + end
;
23331 voffset
= glyph
->voffset
;
23332 s
->padding_p
= glyph
->padding_p
;
23333 glyph_not_available_p
= glyph
->glyph_not_available_p
;
23335 while (glyph
< last
23336 && glyph
->type
== CHAR_GLYPH
23337 && glyph
->voffset
== voffset
23338 /* Same face id implies same font, nowadays. */
23339 && glyph
->face_id
== face_id
23340 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
23344 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
23345 s
->char2b
+ s
->nchars
,
23347 s
->two_byte_p
= two_byte_p
;
23349 eassert (s
->nchars
<= end
- start
);
23350 s
->width
+= glyph
->pixel_width
;
23351 if (glyph
++->padding_p
!= s
->padding_p
)
23355 s
->font
= s
->face
->font
;
23357 /* If the specified font could not be loaded, use the frame's font,
23358 but record the fact that we couldn't load it in
23359 S->font_not_found_p so that we can draw rectangles for the
23360 characters of the glyph string. */
23361 if (s
->font
== NULL
|| glyph_not_available_p
)
23363 s
->font_not_found_p
= 1;
23364 s
->font
= FRAME_FONT (s
->f
);
23367 /* Adjust base line for subscript/superscript text. */
23368 s
->ybase
+= voffset
;
23370 eassert (s
->face
&& s
->face
->gc
);
23371 return glyph
- s
->row
->glyphs
[s
->area
];
23375 /* Fill glyph string S from image glyph S->first_glyph. */
23378 fill_image_glyph_string (struct glyph_string
*s
)
23380 eassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
23381 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
23383 s
->slice
= s
->first_glyph
->slice
.img
;
23384 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
23385 s
->font
= s
->face
->font
;
23386 s
->width
= s
->first_glyph
->pixel_width
;
23388 /* Adjust base line for subscript/superscript text. */
23389 s
->ybase
+= s
->first_glyph
->voffset
;
23392 #ifdef HAVE_XWIDGETS
23394 fill_xwidget_glyph_string (struct glyph_string
*s
)
23396 eassert (s
->first_glyph
->type
== XWIDGET_GLYPH
);
23397 printf("fill_xwidget_glyph_string: width:%d \n",s
->first_glyph
->pixel_width
);
23398 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
23399 s
->font
= s
->face
->font
;
23400 s
->width
= s
->first_glyph
->pixel_width
;
23401 s
->ybase
+= s
->first_glyph
->voffset
;
23402 s
->xwidget
= s
->first_glyph
->u
.xwidget
;
23403 //assert_valid_xwidget_id ( s->xwidget, "fill_xwidget_glyph_string");
23406 /* Fill glyph string S from a sequence of stretch glyphs.
23408 START is the index of the first glyph to consider,
23409 END is the index of the last + 1.
23411 Value is the index of the first glyph not in S. */
23414 fill_stretch_glyph_string (struct glyph_string
*s
, int start
, int end
)
23416 struct glyph
*glyph
, *last
;
23417 int voffset
, face_id
;
23419 eassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
23421 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23422 last
= s
->row
->glyphs
[s
->area
] + end
;
23423 face_id
= glyph
->face_id
;
23424 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
23425 s
->font
= s
->face
->font
;
23426 s
->width
= glyph
->pixel_width
;
23428 voffset
= glyph
->voffset
;
23432 && glyph
->type
== STRETCH_GLYPH
23433 && glyph
->voffset
== voffset
23434 && glyph
->face_id
== face_id
);
23436 s
->width
+= glyph
->pixel_width
;
23438 /* Adjust base line for subscript/superscript text. */
23439 s
->ybase
+= voffset
;
23441 /* The case that face->gc == 0 is handled when drawing the glyph
23442 string by calling PREPARE_FACE_FOR_DISPLAY. */
23444 return glyph
- s
->row
->glyphs
[s
->area
];
23447 static struct font_metrics
*
23448 get_per_char_metric (struct font
*font
, XChar2b
*char2b
)
23450 static struct font_metrics metrics
;
23455 code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
23456 if (code
== FONT_INVALID_CODE
)
23458 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
23463 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
23464 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
23465 assumed to be zero. */
23468 x_get_glyph_overhangs (struct glyph
*glyph
, struct frame
*f
, int *left
, int *right
)
23470 *left
= *right
= 0;
23472 if (glyph
->type
== CHAR_GLYPH
)
23476 struct font_metrics
*pcm
;
23478 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
23479 if (face
->font
&& (pcm
= get_per_char_metric (face
->font
, &char2b
)))
23481 if (pcm
->rbearing
> pcm
->width
)
23482 *right
= pcm
->rbearing
- pcm
->width
;
23483 if (pcm
->lbearing
< 0)
23484 *left
= -pcm
->lbearing
;
23487 else if (glyph
->type
== COMPOSITE_GLYPH
)
23489 if (! glyph
->u
.cmp
.automatic
)
23491 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
23493 if (cmp
->rbearing
> cmp
->pixel_width
)
23494 *right
= cmp
->rbearing
- cmp
->pixel_width
;
23495 if (cmp
->lbearing
< 0)
23496 *left
= - cmp
->lbearing
;
23500 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
23501 struct font_metrics metrics
;
23503 composition_gstring_width (gstring
, glyph
->slice
.cmp
.from
,
23504 glyph
->slice
.cmp
.to
+ 1, &metrics
);
23505 if (metrics
.rbearing
> metrics
.width
)
23506 *right
= metrics
.rbearing
- metrics
.width
;
23507 if (metrics
.lbearing
< 0)
23508 *left
= - metrics
.lbearing
;
23514 /* Return the index of the first glyph preceding glyph string S that
23515 is overwritten by S because of S's left overhang. Value is -1
23516 if no glyphs are overwritten. */
23519 left_overwritten (struct glyph_string
*s
)
23523 if (s
->left_overhang
)
23526 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23527 int first
= s
->first_glyph
- glyphs
;
23529 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
23530 x
-= glyphs
[i
].pixel_width
;
23541 /* Return the index of the first glyph preceding glyph string S that
23542 is overwriting S because of its right overhang. Value is -1 if no
23543 glyph in front of S overwrites S. */
23546 left_overwriting (struct glyph_string
*s
)
23549 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23550 int first
= s
->first_glyph
- glyphs
;
23554 for (i
= first
- 1; i
>= 0; --i
)
23557 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
23560 x
-= glyphs
[i
].pixel_width
;
23567 /* Return the index of the last glyph following glyph string S that is
23568 overwritten by S because of S's right overhang. Value is -1 if
23569 no such glyph is found. */
23572 right_overwritten (struct glyph_string
*s
)
23576 if (s
->right_overhang
)
23579 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23580 int first
= (s
->first_glyph
- glyphs
23581 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
23582 int end
= s
->row
->used
[s
->area
];
23584 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
23585 x
+= glyphs
[i
].pixel_width
;
23594 /* Return the index of the last glyph following glyph string S that
23595 overwrites S because of its left overhang. Value is negative
23596 if no such glyph is found. */
23599 right_overwriting (struct glyph_string
*s
)
23602 int end
= s
->row
->used
[s
->area
];
23603 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23604 int first
= (s
->first_glyph
- glyphs
23605 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
23609 for (i
= first
; i
< end
; ++i
)
23612 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
23615 x
+= glyphs
[i
].pixel_width
;
23622 /* Set background width of glyph string S. START is the index of the
23623 first glyph following S. LAST_X is the right-most x-position + 1
23624 in the drawing area. */
23627 set_glyph_string_background_width (struct glyph_string
*s
, int start
, int last_x
)
23629 /* If the face of this glyph string has to be drawn to the end of
23630 the drawing area, set S->extends_to_end_of_line_p. */
23632 if (start
== s
->row
->used
[s
->area
]
23633 && s
->area
== TEXT_AREA
23634 && ((s
->row
->fill_line_p
23635 && (s
->hl
== DRAW_NORMAL_TEXT
23636 || s
->hl
== DRAW_IMAGE_RAISED
23637 || s
->hl
== DRAW_IMAGE_SUNKEN
))
23638 || s
->hl
== DRAW_MOUSE_FACE
))
23639 s
->extends_to_end_of_line_p
= 1;
23641 /* If S extends its face to the end of the line, set its
23642 background_width to the distance to the right edge of the drawing
23644 if (s
->extends_to_end_of_line_p
)
23645 s
->background_width
= last_x
- s
->x
+ 1;
23647 s
->background_width
= s
->width
;
23651 /* Compute overhangs and x-positions for glyph string S and its
23652 predecessors, or successors. X is the starting x-position for S.
23653 BACKWARD_P non-zero means process predecessors. */
23656 compute_overhangs_and_x (struct glyph_string
*s
, int x
, int backward_p
)
23662 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
23663 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
23673 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
23674 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
23684 /* The following macros are only called from draw_glyphs below.
23685 They reference the following parameters of that function directly:
23686 `w', `row', `area', and `overlap_p'
23687 as well as the following local variables:
23688 `s', `f', and `hdc' (in W32) */
23691 /* On W32, silently add local `hdc' variable to argument list of
23692 init_glyph_string. */
23693 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
23694 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
23696 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
23697 init_glyph_string (s, char2b, w, row, area, start, hl)
23700 /* Add a glyph string for a stretch glyph to the list of strings
23701 between HEAD and TAIL. START is the index of the stretch glyph in
23702 row area AREA of glyph row ROW. END is the index of the last glyph
23703 in that glyph row area. X is the current output position assigned
23704 to the new glyph string constructed. HL overrides that face of the
23705 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
23706 is the right-most x-position of the drawing area. */
23708 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
23709 and below -- keep them on one line. */
23710 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23713 s = alloca (sizeof *s); \
23714 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23715 START = fill_stretch_glyph_string (s, START, END); \
23716 append_glyph_string (&HEAD, &TAIL, s); \
23722 /* Add a glyph string for an image glyph to the list of strings
23723 between HEAD and TAIL. START is the index of the image glyph in
23724 row area AREA of glyph row ROW. END is the index of the last glyph
23725 in that glyph row area. X is the current output position assigned
23726 to the new glyph string constructed. HL overrides that face of the
23727 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
23728 is the right-most x-position of the drawing area. */
23730 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23733 s = alloca (sizeof *s); \
23734 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23735 fill_image_glyph_string (s); \
23736 append_glyph_string (&HEAD, &TAIL, s); \
23742 #ifdef HAVE_XWIDGETS
23743 #define BUILD_XWIDGET_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23746 printf("BUILD_XWIDGET_GLYPH_STRING\n"); \
23747 s = (struct glyph_string *) alloca (sizeof *s); \
23748 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23749 fill_xwidget_glyph_string (s); \
23750 append_glyph_string (&HEAD, &TAIL, s); \
23758 /* Add a glyph string for a sequence of character glyphs to the list
23759 of strings between HEAD and TAIL. START is the index of the first
23760 glyph in row area AREA of glyph row ROW that is part of the new
23761 glyph string. END is the index of the last glyph in that glyph row
23762 area. X is the current output position assigned to the new glyph
23763 string constructed. HL overrides that face of the glyph; e.g. it
23764 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
23765 right-most x-position of the drawing area. */
23767 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
23773 face_id = (row)->glyphs[area][START].face_id; \
23775 s = alloca (sizeof *s); \
23776 char2b = alloca ((END - START) * sizeof *char2b); \
23777 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23778 append_glyph_string (&HEAD, &TAIL, s); \
23780 START = fill_glyph_string (s, face_id, START, END, overlaps); \
23785 /* Add a glyph string for a composite sequence to the list of strings
23786 between HEAD and TAIL. START is the index of the first glyph in
23787 row area AREA of glyph row ROW that is part of the new glyph
23788 string. END is the index of the last glyph in that glyph row area.
23789 X is the current output position assigned to the new glyph string
23790 constructed. HL overrides that face of the glyph; e.g. it is
23791 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
23792 x-position of the drawing area. */
23794 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23796 int face_id = (row)->glyphs[area][START].face_id; \
23797 struct face *base_face = FACE_FROM_ID (f, face_id); \
23798 ptrdiff_t cmp_id = (row)->glyphs[area][START].u.cmp.id; \
23799 struct composition *cmp = composition_table[cmp_id]; \
23801 struct glyph_string *first_s = NULL; \
23804 char2b = alloca (cmp->glyph_len * sizeof *char2b); \
23806 /* Make glyph_strings for each glyph sequence that is drawable by \
23807 the same face, and append them to HEAD/TAIL. */ \
23808 for (n = 0; n < cmp->glyph_len;) \
23810 s = alloca (sizeof *s); \
23811 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23812 append_glyph_string (&(HEAD), &(TAIL), s); \
23818 n = fill_composite_glyph_string (s, base_face, overlaps); \
23826 /* Add a glyph string for a glyph-string sequence to the list of strings
23827 between HEAD and TAIL. */
23829 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23833 Lisp_Object gstring; \
23835 face_id = (row)->glyphs[area][START].face_id; \
23836 gstring = (composition_gstring_from_id \
23837 ((row)->glyphs[area][START].u.cmp.id)); \
23838 s = alloca (sizeof *s); \
23839 char2b = alloca (LGSTRING_GLYPH_LEN (gstring) * sizeof *char2b); \
23840 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23841 append_glyph_string (&(HEAD), &(TAIL), s); \
23843 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
23847 /* Add a glyph string for a sequence of glyphless character's glyphs
23848 to the list of strings between HEAD and TAIL. The meanings of
23849 arguments are the same as those of BUILD_CHAR_GLYPH_STRINGS. */
23851 #define BUILD_GLYPHLESS_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23856 face_id = (row)->glyphs[area][START].face_id; \
23858 s = alloca (sizeof *s); \
23859 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23860 append_glyph_string (&HEAD, &TAIL, s); \
23862 START = fill_glyphless_glyph_string (s, face_id, START, END, \
23868 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
23869 of AREA of glyph row ROW on window W between indices START and END.
23870 HL overrides the face for drawing glyph strings, e.g. it is
23871 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
23872 x-positions of the drawing area.
23874 This is an ugly monster macro construct because we must use alloca
23875 to allocate glyph strings (because draw_glyphs can be called
23876 asynchronously). */
23878 #define BUILD_GLYPH_STRINGS_1(START, END, HEAD, TAIL, HL, X, LAST_X) \
23881 HEAD = TAIL = NULL; \
23882 while (START < END) \
23884 struct glyph *first_glyph = (row)->glyphs[area] + START; \
23885 switch (first_glyph->type) \
23888 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
23892 case COMPOSITE_GLYPH: \
23893 if (first_glyph->u.cmp.automatic) \
23894 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
23897 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
23901 case STRETCH_GLYPH: \
23902 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
23906 case IMAGE_GLYPH: \
23907 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
23911 #define BUILD_GLYPH_STRINGS_XW(START, END, HEAD, TAIL, HL, X, LAST_X) \
23912 case XWIDGET_GLYPH: \
23913 BUILD_XWIDGET_GLYPH_STRING (START, END, HEAD, TAIL, \
23917 #define BUILD_GLYPH_STRINGS_2(START, END, HEAD, TAIL, HL, X, LAST_X) \
23918 case GLYPHLESS_GLYPH: \
23919 BUILD_GLYPHLESS_GLYPH_STRING (START, END, HEAD, TAIL, \
23929 set_glyph_string_background_width (s, START, LAST_X); \
23936 #ifdef HAVE_XWIDGETS
23937 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
23938 BUILD_GLYPH_STRINGS_1(START, END, HEAD, TAIL, HL, X, LAST_X) \
23939 BUILD_GLYPH_STRINGS_XW(START, END, HEAD, TAIL, HL, X, LAST_X) \
23940 BUILD_GLYPH_STRINGS_2(START, END, HEAD, TAIL, HL, X, LAST_X)
23942 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
23943 BUILD_GLYPH_STRINGS_1(START, END, HEAD, TAIL, HL, X, LAST_X) \
23944 BUILD_GLYPH_STRINGS_2(START, END, HEAD, TAIL, HL, X, LAST_X)
23948 /* Draw glyphs between START and END in AREA of ROW on window W,
23949 starting at x-position X. X is relative to AREA in W. HL is a
23950 face-override with the following meaning:
23952 DRAW_NORMAL_TEXT draw normally
23953 DRAW_CURSOR draw in cursor face
23954 DRAW_MOUSE_FACE draw in mouse face.
23955 DRAW_INVERSE_VIDEO draw in mode line face
23956 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
23957 DRAW_IMAGE_RAISED draw an image with a raised relief around it
23959 If OVERLAPS is non-zero, draw only the foreground of characters and
23960 clip to the physical height of ROW. Non-zero value also defines
23961 the overlapping part to be drawn:
23963 OVERLAPS_PRED overlap with preceding rows
23964 OVERLAPS_SUCC overlap with succeeding rows
23965 OVERLAPS_BOTH overlap with both preceding/succeeding rows
23966 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
23968 Value is the x-position reached, relative to AREA of W. */
23971 draw_glyphs (struct window
*w
, int x
, struct glyph_row
*row
,
23972 enum glyph_row_area area
, ptrdiff_t start
, ptrdiff_t end
,
23973 enum draw_glyphs_face hl
, int overlaps
)
23975 struct glyph_string
*head
, *tail
;
23976 struct glyph_string
*s
;
23977 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
23978 int i
, j
, x_reached
, last_x
, area_left
= 0;
23979 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
23982 ALLOCATE_HDC (hdc
, f
);
23984 /* Let's rather be paranoid than getting a SEGV. */
23985 end
= min (end
, row
->used
[area
]);
23986 start
= clip_to_bounds (0, start
, end
);
23988 /* Translate X to frame coordinates. Set last_x to the right
23989 end of the drawing area. */
23990 if (row
->full_width_p
)
23992 /* X is relative to the left edge of W, without scroll bars
23994 area_left
= WINDOW_LEFT_EDGE_X (w
);
23995 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
23999 area_left
= window_box_left (w
, area
);
24000 last_x
= area_left
+ window_box_width (w
, area
);
24004 /* Build a doubly-linked list of glyph_string structures between
24005 head and tail from what we have to draw. Note that the macro
24006 BUILD_GLYPH_STRINGS will modify its start parameter. That's
24007 the reason we use a separate variable `i'. */
24009 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
24011 x_reached
= tail
->x
+ tail
->background_width
;
24015 /* If there are any glyphs with lbearing < 0 or rbearing > width in
24016 the row, redraw some glyphs in front or following the glyph
24017 strings built above. */
24018 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
24020 struct glyph_string
*h
, *t
;
24021 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
24022 int mouse_beg_col
IF_LINT (= 0), mouse_end_col
IF_LINT (= 0);
24023 int check_mouse_face
= 0;
24026 /* If mouse highlighting is on, we may need to draw adjacent
24027 glyphs using mouse-face highlighting. */
24028 if (area
== TEXT_AREA
&& row
->mouse_face_p
24029 && hlinfo
->mouse_face_beg_row
>= 0
24030 && hlinfo
->mouse_face_end_row
>= 0)
24032 ptrdiff_t row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
24034 if (row_vpos
>= hlinfo
->mouse_face_beg_row
24035 && row_vpos
<= hlinfo
->mouse_face_end_row
)
24037 check_mouse_face
= 1;
24038 mouse_beg_col
= (row_vpos
== hlinfo
->mouse_face_beg_row
)
24039 ? hlinfo
->mouse_face_beg_col
: 0;
24040 mouse_end_col
= (row_vpos
== hlinfo
->mouse_face_end_row
)
24041 ? hlinfo
->mouse_face_end_col
24042 : row
->used
[TEXT_AREA
];
24046 /* Compute overhangs for all glyph strings. */
24047 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
24048 for (s
= head
; s
; s
= s
->next
)
24049 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
24051 /* Prepend glyph strings for glyphs in front of the first glyph
24052 string that are overwritten because of the first glyph
24053 string's left overhang. The background of all strings
24054 prepended must be drawn because the first glyph string
24056 i
= left_overwritten (head
);
24059 enum draw_glyphs_face overlap_hl
;
24061 /* If this row contains mouse highlighting, attempt to draw
24062 the overlapped glyphs with the correct highlight. This
24063 code fails if the overlap encompasses more than one glyph
24064 and mouse-highlight spans only some of these glyphs.
24065 However, making it work perfectly involves a lot more
24066 code, and I don't know if the pathological case occurs in
24067 practice, so we'll stick to this for now. --- cyd */
24068 if (check_mouse_face
24069 && mouse_beg_col
< start
&& mouse_end_col
> i
)
24070 overlap_hl
= DRAW_MOUSE_FACE
;
24072 overlap_hl
= DRAW_NORMAL_TEXT
;
24075 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
24076 overlap_hl
, dummy_x
, last_x
);
24078 compute_overhangs_and_x (t
, head
->x
, 1);
24079 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
24083 /* Prepend glyph strings for glyphs in front of the first glyph
24084 string that overwrite that glyph string because of their
24085 right overhang. For these strings, only the foreground must
24086 be drawn, because it draws over the glyph string at `head'.
24087 The background must not be drawn because this would overwrite
24088 right overhangs of preceding glyphs for which no glyph
24090 i
= left_overwriting (head
);
24093 enum draw_glyphs_face overlap_hl
;
24095 if (check_mouse_face
24096 && mouse_beg_col
< start
&& mouse_end_col
> i
)
24097 overlap_hl
= DRAW_MOUSE_FACE
;
24099 overlap_hl
= DRAW_NORMAL_TEXT
;
24102 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
24103 overlap_hl
, dummy_x
, last_x
);
24104 for (s
= h
; s
; s
= s
->next
)
24105 s
->background_filled_p
= 1;
24106 compute_overhangs_and_x (t
, head
->x
, 1);
24107 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
24110 /* Append glyphs strings for glyphs following the last glyph
24111 string tail that are overwritten by tail. The background of
24112 these strings has to be drawn because tail's foreground draws
24114 i
= right_overwritten (tail
);
24117 enum draw_glyphs_face overlap_hl
;
24119 if (check_mouse_face
24120 && mouse_beg_col
< i
&& mouse_end_col
> end
)
24121 overlap_hl
= DRAW_MOUSE_FACE
;
24123 overlap_hl
= DRAW_NORMAL_TEXT
;
24125 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
24126 overlap_hl
, x
, last_x
);
24127 /* Because BUILD_GLYPH_STRINGS updates the first argument,
24128 we don't have `end = i;' here. */
24129 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
24130 append_glyph_string_lists (&head
, &tail
, h
, t
);
24134 /* Append glyph strings for glyphs following the last glyph
24135 string tail that overwrite tail. The foreground of such
24136 glyphs has to be drawn because it writes into the background
24137 of tail. The background must not be drawn because it could
24138 paint over the foreground of following glyphs. */
24139 i
= right_overwriting (tail
);
24142 enum draw_glyphs_face overlap_hl
;
24143 if (check_mouse_face
24144 && mouse_beg_col
< i
&& mouse_end_col
> end
)
24145 overlap_hl
= DRAW_MOUSE_FACE
;
24147 overlap_hl
= DRAW_NORMAL_TEXT
;
24150 i
++; /* We must include the Ith glyph. */
24151 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
24152 overlap_hl
, x
, last_x
);
24153 for (s
= h
; s
; s
= s
->next
)
24154 s
->background_filled_p
= 1;
24155 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
24156 append_glyph_string_lists (&head
, &tail
, h
, t
);
24158 if (clip_head
|| clip_tail
)
24159 for (s
= head
; s
; s
= s
->next
)
24161 s
->clip_head
= clip_head
;
24162 s
->clip_tail
= clip_tail
;
24166 /* Draw all strings. */
24167 for (s
= head
; s
; s
= s
->next
)
24168 FRAME_RIF (f
)->draw_glyph_string (s
);
24171 /* When focus a sole frame and move horizontally, this sets on_p to 0
24172 causing a failure to erase prev cursor position. */
24173 if (area
== TEXT_AREA
24174 && !row
->full_width_p
24175 /* When drawing overlapping rows, only the glyph strings'
24176 foreground is drawn, which doesn't erase a cursor
24180 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
24181 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
24182 : (tail
? tail
->x
+ tail
->background_width
: x
));
24186 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
24187 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
24191 /* Value is the x-position up to which drawn, relative to AREA of W.
24192 This doesn't include parts drawn because of overhangs. */
24193 if (row
->full_width_p
)
24194 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
24196 x_reached
-= area_left
;
24198 RELEASE_HDC (hdc
, f
);
24203 /* Expand row matrix if too narrow. Don't expand if area
24206 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
24208 if (!fonts_changed_p \
24209 && (it->glyph_row->glyphs[area] \
24210 < it->glyph_row->glyphs[area + 1])) \
24212 it->w->ncols_scale_factor++; \
24213 fonts_changed_p = 1; \
24217 /* Store one glyph for IT->char_to_display in IT->glyph_row.
24218 Called from x_produce_glyphs when IT->glyph_row is non-null. */
24221 append_glyph (struct it
*it
)
24223 struct glyph
*glyph
;
24224 enum glyph_row_area area
= it
->area
;
24226 eassert (it
->glyph_row
);
24227 eassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
24229 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24230 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24232 /* If the glyph row is reversed, we need to prepend the glyph
24233 rather than append it. */
24234 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24238 /* Make room for the additional glyph. */
24239 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
24241 glyph
= it
->glyph_row
->glyphs
[area
];
24243 glyph
->charpos
= CHARPOS (it
->position
);
24244 glyph
->object
= it
->object
;
24245 if (it
->pixel_width
> 0)
24247 glyph
->pixel_width
= it
->pixel_width
;
24248 glyph
->padding_p
= 0;
24252 /* Assure at least 1-pixel width. Otherwise, cursor can't
24253 be displayed correctly. */
24254 glyph
->pixel_width
= 1;
24255 glyph
->padding_p
= 1;
24257 glyph
->ascent
= it
->ascent
;
24258 glyph
->descent
= it
->descent
;
24259 glyph
->voffset
= it
->voffset
;
24260 glyph
->type
= CHAR_GLYPH
;
24261 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24262 glyph
->multibyte_p
= it
->multibyte_p
;
24263 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24265 /* In R2L rows, the left and the right box edges need to be
24266 drawn in reverse direction. */
24267 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24268 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24272 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24273 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24275 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
24276 || it
->phys_descent
> it
->descent
);
24277 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
24278 glyph
->face_id
= it
->face_id
;
24279 glyph
->u
.ch
= it
->char_to_display
;
24280 glyph
->slice
.img
= null_glyph_slice
;
24281 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24284 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24285 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24287 glyph
->bidi_type
= it
->bidi_it
.type
;
24291 glyph
->resolved_level
= 0;
24292 glyph
->bidi_type
= UNKNOWN_BT
;
24294 ++it
->glyph_row
->used
[area
];
24297 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24300 /* Store one glyph for the composition IT->cmp_it.id in
24301 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
24305 append_composite_glyph (struct it
*it
)
24307 struct glyph
*glyph
;
24308 enum glyph_row_area area
= it
->area
;
24310 eassert (it
->glyph_row
);
24312 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24313 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24315 /* If the glyph row is reversed, we need to prepend the glyph
24316 rather than append it. */
24317 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
24321 /* Make room for the new glyph. */
24322 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
24324 glyph
= it
->glyph_row
->glyphs
[it
->area
];
24326 glyph
->charpos
= it
->cmp_it
.charpos
;
24327 glyph
->object
= it
->object
;
24328 glyph
->pixel_width
= it
->pixel_width
;
24329 glyph
->ascent
= it
->ascent
;
24330 glyph
->descent
= it
->descent
;
24331 glyph
->voffset
= it
->voffset
;
24332 glyph
->type
= COMPOSITE_GLYPH
;
24333 if (it
->cmp_it
.ch
< 0)
24335 glyph
->u
.cmp
.automatic
= 0;
24336 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
24337 glyph
->slice
.cmp
.from
= glyph
->slice
.cmp
.to
= 0;
24341 glyph
->u
.cmp
.automatic
= 1;
24342 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
24343 glyph
->slice
.cmp
.from
= it
->cmp_it
.from
;
24344 glyph
->slice
.cmp
.to
= it
->cmp_it
.to
- 1;
24346 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24347 glyph
->multibyte_p
= it
->multibyte_p
;
24348 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24350 /* In R2L rows, the left and the right box edges need to be
24351 drawn in reverse direction. */
24352 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24353 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24357 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24358 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24360 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
24361 || it
->phys_descent
> it
->descent
);
24362 glyph
->padding_p
= 0;
24363 glyph
->glyph_not_available_p
= 0;
24364 glyph
->face_id
= it
->face_id
;
24365 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24368 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24369 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24371 glyph
->bidi_type
= it
->bidi_it
.type
;
24373 ++it
->glyph_row
->used
[area
];
24376 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24380 /* Change IT->ascent and IT->height according to the setting of
24384 take_vertical_position_into_account (struct it
*it
)
24388 if (it
->voffset
< 0)
24389 /* Increase the ascent so that we can display the text higher
24391 it
->ascent
-= it
->voffset
;
24393 /* Increase the descent so that we can display the text lower
24395 it
->descent
+= it
->voffset
;
24400 /* Produce glyphs/get display metrics for the image IT is loaded with.
24401 See the description of struct display_iterator in dispextern.h for
24402 an overview of struct display_iterator. */
24405 produce_image_glyph (struct it
*it
)
24409 int glyph_ascent
, crop
;
24410 struct glyph_slice slice
;
24412 eassert (it
->what
== IT_IMAGE
);
24414 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24416 /* Make sure X resources of the face is loaded. */
24417 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24419 if (it
->image_id
< 0)
24421 /* Fringe bitmap. */
24422 it
->ascent
= it
->phys_ascent
= 0;
24423 it
->descent
= it
->phys_descent
= 0;
24424 it
->pixel_width
= 0;
24429 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
24431 /* Make sure X resources of the image is loaded. */
24432 prepare_image_for_display (it
->f
, img
);
24434 slice
.x
= slice
.y
= 0;
24435 slice
.width
= img
->width
;
24436 slice
.height
= img
->height
;
24438 if (INTEGERP (it
->slice
.x
))
24439 slice
.x
= XINT (it
->slice
.x
);
24440 else if (FLOATP (it
->slice
.x
))
24441 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
24443 if (INTEGERP (it
->slice
.y
))
24444 slice
.y
= XINT (it
->slice
.y
);
24445 else if (FLOATP (it
->slice
.y
))
24446 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
24448 if (INTEGERP (it
->slice
.width
))
24449 slice
.width
= XINT (it
->slice
.width
);
24450 else if (FLOATP (it
->slice
.width
))
24451 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
24453 if (INTEGERP (it
->slice
.height
))
24454 slice
.height
= XINT (it
->slice
.height
);
24455 else if (FLOATP (it
->slice
.height
))
24456 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
24458 if (slice
.x
>= img
->width
)
24459 slice
.x
= img
->width
;
24460 if (slice
.y
>= img
->height
)
24461 slice
.y
= img
->height
;
24462 if (slice
.x
+ slice
.width
>= img
->width
)
24463 slice
.width
= img
->width
- slice
.x
;
24464 if (slice
.y
+ slice
.height
> img
->height
)
24465 slice
.height
= img
->height
- slice
.y
;
24467 if (slice
.width
== 0 || slice
.height
== 0)
24470 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
24472 it
->descent
= slice
.height
- glyph_ascent
;
24474 it
->descent
+= img
->vmargin
;
24475 if (slice
.y
+ slice
.height
== img
->height
)
24476 it
->descent
+= img
->vmargin
;
24477 it
->phys_descent
= it
->descent
;
24479 it
->pixel_width
= slice
.width
;
24481 it
->pixel_width
+= img
->hmargin
;
24482 if (slice
.x
+ slice
.width
== img
->width
)
24483 it
->pixel_width
+= img
->hmargin
;
24485 /* It's quite possible for images to have an ascent greater than
24486 their height, so don't get confused in that case. */
24487 if (it
->descent
< 0)
24492 if (face
->box
!= FACE_NO_BOX
)
24494 if (face
->box_line_width
> 0)
24497 it
->ascent
+= face
->box_line_width
;
24498 if (slice
.y
+ slice
.height
== img
->height
)
24499 it
->descent
+= face
->box_line_width
;
24502 if (it
->start_of_box_run_p
&& slice
.x
== 0)
24503 it
->pixel_width
+= eabs (face
->box_line_width
);
24504 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
24505 it
->pixel_width
+= eabs (face
->box_line_width
);
24508 take_vertical_position_into_account (it
);
24510 /* Automatically crop wide image glyphs at right edge so we can
24511 draw the cursor on same display row. */
24512 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
24513 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
24515 it
->pixel_width
-= crop
;
24516 slice
.width
-= crop
;
24521 struct glyph
*glyph
;
24522 enum glyph_row_area area
= it
->area
;
24524 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24525 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24527 glyph
->charpos
= CHARPOS (it
->position
);
24528 glyph
->object
= it
->object
;
24529 glyph
->pixel_width
= it
->pixel_width
;
24530 glyph
->ascent
= glyph_ascent
;
24531 glyph
->descent
= it
->descent
;
24532 glyph
->voffset
= it
->voffset
;
24533 glyph
->type
= IMAGE_GLYPH
;
24534 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24535 glyph
->multibyte_p
= it
->multibyte_p
;
24536 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24538 /* In R2L rows, the left and the right box edges need to be
24539 drawn in reverse direction. */
24540 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24541 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24545 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24546 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24548 glyph
->overlaps_vertically_p
= 0;
24549 glyph
->padding_p
= 0;
24550 glyph
->glyph_not_available_p
= 0;
24551 glyph
->face_id
= it
->face_id
;
24552 glyph
->u
.img_id
= img
->id
;
24553 glyph
->slice
.img
= slice
;
24554 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24557 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24558 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24560 glyph
->bidi_type
= it
->bidi_it
.type
;
24562 ++it
->glyph_row
->used
[area
];
24565 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24569 #ifdef HAVE_XWIDGETS
24571 produce_xwidget_glyph (struct it
*it
)
24573 struct xwidget
* xw
;
24575 int glyph_ascent
, crop
;
24576 printf("produce_xwidget_glyph:\n");
24577 eassert (it
->what
== IT_XWIDGET
);
24579 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24581 /* Make sure X resources of the face is loaded. */
24582 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24585 it
->ascent
= it
->phys_ascent
= glyph_ascent
= xw
->height
/2;
24586 it
->descent
= xw
->height
/2;
24587 it
->phys_descent
= it
->descent
;
24588 it
->pixel_width
= xw
->width
;
24589 /* It's quite possible for images to have an ascent greater than
24590 their height, so don't get confused in that case. */
24591 if (it
->descent
< 0)
24596 if (face
->box
!= FACE_NO_BOX
)
24598 if (face
->box_line_width
> 0)
24600 it
->ascent
+= face
->box_line_width
;
24601 it
->descent
+= face
->box_line_width
;
24604 if (it
->start_of_box_run_p
)
24605 it
->pixel_width
+= eabs (face
->box_line_width
);
24606 it
->pixel_width
+= eabs (face
->box_line_width
);
24609 take_vertical_position_into_account (it
);
24611 /* Automatically crop wide image glyphs at right edge so we can
24612 draw the cursor on same display row. */
24613 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
24614 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
24616 it
->pixel_width
-= crop
;
24621 struct glyph
*glyph
;
24622 enum glyph_row_area area
= it
->area
;
24624 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24625 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24627 glyph
->charpos
= CHARPOS (it
->position
);
24628 glyph
->object
= it
->object
;
24629 glyph
->pixel_width
= it
->pixel_width
;
24630 glyph
->ascent
= glyph_ascent
;
24631 glyph
->descent
= it
->descent
;
24632 glyph
->voffset
= it
->voffset
;
24633 glyph
->type
= XWIDGET_GLYPH
;
24635 glyph
->multibyte_p
= it
->multibyte_p
;
24636 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24637 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24638 glyph
->overlaps_vertically_p
= 0;
24639 glyph
->padding_p
= 0;
24640 glyph
->glyph_not_available_p
= 0;
24641 glyph
->face_id
= it
->face_id
;
24642 glyph
->u
.xwidget
= it
->xwidget
;
24643 //assert_valid_xwidget_id(glyph->u.xwidget_id,"produce_xwidget_glyph");
24644 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24645 ++it
->glyph_row
->used
[area
];
24648 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24653 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
24654 of the glyph, WIDTH and HEIGHT are the width and height of the
24655 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
24658 append_stretch_glyph (struct it
*it
, Lisp_Object object
,
24659 int width
, int height
, int ascent
)
24661 struct glyph
*glyph
;
24662 enum glyph_row_area area
= it
->area
;
24664 eassert (ascent
>= 0 && ascent
<= height
);
24666 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24667 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24669 /* If the glyph row is reversed, we need to prepend the glyph
24670 rather than append it. */
24671 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24675 /* Make room for the additional glyph. */
24676 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
24678 glyph
= it
->glyph_row
->glyphs
[area
];
24680 glyph
->charpos
= CHARPOS (it
->position
);
24681 glyph
->object
= object
;
24682 glyph
->pixel_width
= width
;
24683 glyph
->ascent
= ascent
;
24684 glyph
->descent
= height
- ascent
;
24685 glyph
->voffset
= it
->voffset
;
24686 glyph
->type
= STRETCH_GLYPH
;
24687 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24688 glyph
->multibyte_p
= it
->multibyte_p
;
24689 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24691 /* In R2L rows, the left and the right box edges need to be
24692 drawn in reverse direction. */
24693 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24694 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24698 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24699 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24701 glyph
->overlaps_vertically_p
= 0;
24702 glyph
->padding_p
= 0;
24703 glyph
->glyph_not_available_p
= 0;
24704 glyph
->face_id
= it
->face_id
;
24705 glyph
->u
.stretch
.ascent
= ascent
;
24706 glyph
->u
.stretch
.height
= height
;
24707 glyph
->slice
.img
= null_glyph_slice
;
24708 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24711 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24712 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24714 glyph
->bidi_type
= it
->bidi_it
.type
;
24718 glyph
->resolved_level
= 0;
24719 glyph
->bidi_type
= UNKNOWN_BT
;
24721 ++it
->glyph_row
->used
[area
];
24724 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24727 #endif /* HAVE_WINDOW_SYSTEM */
24729 /* Produce a stretch glyph for iterator IT. IT->object is the value
24730 of the glyph property displayed. The value must be a list
24731 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
24734 1. `:width WIDTH' specifies that the space should be WIDTH *
24735 canonical char width wide. WIDTH may be an integer or floating
24738 2. `:relative-width FACTOR' specifies that the width of the stretch
24739 should be computed from the width of the first character having the
24740 `glyph' property, and should be FACTOR times that width.
24742 3. `:align-to HPOS' specifies that the space should be wide enough
24743 to reach HPOS, a value in canonical character units.
24745 Exactly one of the above pairs must be present.
24747 4. `:height HEIGHT' specifies that the height of the stretch produced
24748 should be HEIGHT, measured in canonical character units.
24750 5. `:relative-height FACTOR' specifies that the height of the
24751 stretch should be FACTOR times the height of the characters having
24752 the glyph property.
24754 Either none or exactly one of 4 or 5 must be present.
24756 6. `:ascent ASCENT' specifies that ASCENT percent of the height
24757 of the stretch should be used for the ascent of the stretch.
24758 ASCENT must be in the range 0 <= ASCENT <= 100. */
24761 produce_stretch_glyph (struct it
*it
)
24763 /* (space :width WIDTH :height HEIGHT ...) */
24764 Lisp_Object prop
, plist
;
24765 int width
= 0, height
= 0, align_to
= -1;
24766 int zero_width_ok_p
= 0;
24768 struct font
*font
= NULL
;
24770 #ifdef HAVE_WINDOW_SYSTEM
24772 int zero_height_ok_p
= 0;
24774 if (FRAME_WINDOW_P (it
->f
))
24776 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24777 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24778 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24782 /* List should start with `space'. */
24783 eassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
24784 plist
= XCDR (it
->object
);
24786 /* Compute the width of the stretch. */
24787 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
24788 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
24790 /* Absolute width `:width WIDTH' specified and valid. */
24791 zero_width_ok_p
= 1;
24794 #ifdef HAVE_WINDOW_SYSTEM
24795 else if (FRAME_WINDOW_P (it
->f
)
24796 && (prop
= Fplist_get (plist
, QCrelative_width
), NUMVAL (prop
) > 0))
24798 /* Relative width `:relative-width FACTOR' specified and valid.
24799 Compute the width of the characters having the `glyph'
24802 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
24805 if (it
->multibyte_p
)
24806 it2
.c
= it2
.char_to_display
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
24809 it2
.c
= it2
.char_to_display
= *p
, it2
.len
= 1;
24810 if (! ASCII_CHAR_P (it2
.c
))
24811 it2
.char_to_display
= BYTE8_TO_CHAR (it2
.c
);
24814 it2
.glyph_row
= NULL
;
24815 it2
.what
= IT_CHARACTER
;
24816 x_produce_glyphs (&it2
);
24817 width
= NUMVAL (prop
) * it2
.pixel_width
;
24819 #endif /* HAVE_WINDOW_SYSTEM */
24820 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
24821 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
24823 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
24824 align_to
= (align_to
< 0
24826 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
24827 else if (align_to
< 0)
24828 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
24829 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
24830 zero_width_ok_p
= 1;
24833 /* Nothing specified -> width defaults to canonical char width. */
24834 width
= FRAME_COLUMN_WIDTH (it
->f
);
24836 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
24839 #ifdef HAVE_WINDOW_SYSTEM
24840 /* Compute height. */
24841 if (FRAME_WINDOW_P (it
->f
))
24843 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
24844 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
24847 zero_height_ok_p
= 1;
24849 else if (prop
= Fplist_get (plist
, QCrelative_height
),
24851 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
24853 height
= FONT_HEIGHT (font
);
24855 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
24858 /* Compute percentage of height used for ascent. If
24859 `:ascent ASCENT' is present and valid, use that. Otherwise,
24860 derive the ascent from the font in use. */
24861 if (prop
= Fplist_get (plist
, QCascent
),
24862 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
24863 ascent
= height
* NUMVAL (prop
) / 100.0;
24864 else if (!NILP (prop
)
24865 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
24866 ascent
= min (max (0, (int)tem
), height
);
24868 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
24871 #endif /* HAVE_WINDOW_SYSTEM */
24874 if (width
> 0 && it
->line_wrap
!= TRUNCATE
24875 && it
->current_x
+ width
> it
->last_visible_x
)
24877 width
= it
->last_visible_x
- it
->current_x
;
24878 #ifdef HAVE_WINDOW_SYSTEM
24879 /* Subtract one more pixel from the stretch width, but only on
24880 GUI frames, since on a TTY each glyph is one "pixel" wide. */
24881 width
-= FRAME_WINDOW_P (it
->f
);
24885 if (width
> 0 && height
> 0 && it
->glyph_row
)
24887 Lisp_Object o_object
= it
->object
;
24888 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
24891 if (!STRINGP (object
))
24892 object
= it
->w
->contents
;
24893 #ifdef HAVE_WINDOW_SYSTEM
24894 if (FRAME_WINDOW_P (it
->f
))
24895 append_stretch_glyph (it
, object
, width
, height
, ascent
);
24899 it
->object
= object
;
24900 it
->char_to_display
= ' ';
24901 it
->pixel_width
= it
->len
= 1;
24903 tty_append_glyph (it
);
24904 it
->object
= o_object
;
24908 it
->pixel_width
= width
;
24909 #ifdef HAVE_WINDOW_SYSTEM
24910 if (FRAME_WINDOW_P (it
->f
))
24912 it
->ascent
= it
->phys_ascent
= ascent
;
24913 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
24914 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
24915 take_vertical_position_into_account (it
);
24919 it
->nglyphs
= width
;
24922 /* Get information about special display element WHAT in an
24923 environment described by IT. WHAT is one of IT_TRUNCATION or
24924 IT_CONTINUATION. Maybe produce glyphs for WHAT if IT has a
24925 non-null glyph_row member. This function ensures that fields like
24926 face_id, c, len of IT are left untouched. */
24929 produce_special_glyphs (struct it
*it
, enum display_element_type what
)
24936 temp_it
.object
= make_number (0);
24937 memset (&temp_it
.current
, 0, sizeof temp_it
.current
);
24939 if (what
== IT_CONTINUATION
)
24941 /* Continuation glyph. For R2L lines, we mirror it by hand. */
24942 if (it
->bidi_it
.paragraph_dir
== R2L
)
24943 SET_GLYPH_FROM_CHAR (glyph
, '/');
24945 SET_GLYPH_FROM_CHAR (glyph
, '\\');
24947 && (gc
= DISP_CONTINUE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
24949 /* FIXME: Should we mirror GC for R2L lines? */
24950 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
24951 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
24954 else if (what
== IT_TRUNCATION
)
24956 /* Truncation glyph. */
24957 SET_GLYPH_FROM_CHAR (glyph
, '$');
24959 && (gc
= DISP_TRUNC_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
24961 /* FIXME: Should we mirror GC for R2L lines? */
24962 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
24963 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
24969 #ifdef HAVE_WINDOW_SYSTEM
24970 /* On a GUI frame, when the right fringe (left fringe for R2L rows)
24971 is turned off, we precede the truncation/continuation glyphs by a
24972 stretch glyph whose width is computed such that these special
24973 glyphs are aligned at the window margin, even when very different
24974 fonts are used in different glyph rows. */
24975 if (FRAME_WINDOW_P (temp_it
.f
)
24976 /* init_iterator calls this with it->glyph_row == NULL, and it
24977 wants only the pixel width of the truncation/continuation
24979 && temp_it
.glyph_row
24980 /* insert_left_trunc_glyphs calls us at the beginning of the
24981 row, and it has its own calculation of the stretch glyph
24983 && temp_it
.glyph_row
->used
[TEXT_AREA
] > 0
24984 && (temp_it
.glyph_row
->reversed_p
24985 ? WINDOW_LEFT_FRINGE_WIDTH (temp_it
.w
)
24986 : WINDOW_RIGHT_FRINGE_WIDTH (temp_it
.w
)) == 0)
24988 int stretch_width
= temp_it
.last_visible_x
- temp_it
.current_x
;
24990 if (stretch_width
> 0)
24992 struct face
*face
= FACE_FROM_ID (temp_it
.f
, temp_it
.face_id
);
24993 struct font
*font
=
24994 face
->font
? face
->font
: FRAME_FONT (temp_it
.f
);
24995 int stretch_ascent
=
24996 (((temp_it
.ascent
+ temp_it
.descent
)
24997 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
24999 append_stretch_glyph (&temp_it
, make_number (0), stretch_width
,
25000 temp_it
.ascent
+ temp_it
.descent
,
25007 temp_it
.what
= IT_CHARACTER
;
25009 temp_it
.c
= temp_it
.char_to_display
= GLYPH_CHAR (glyph
);
25010 temp_it
.face_id
= GLYPH_FACE (glyph
);
25011 temp_it
.len
= CHAR_BYTES (temp_it
.c
);
25013 PRODUCE_GLYPHS (&temp_it
);
25014 it
->pixel_width
= temp_it
.pixel_width
;
25015 it
->nglyphs
= temp_it
.pixel_width
;
25018 #ifdef HAVE_WINDOW_SYSTEM
25020 /* Calculate line-height and line-spacing properties.
25021 An integer value specifies explicit pixel value.
25022 A float value specifies relative value to current face height.
25023 A cons (float . face-name) specifies relative value to
25024 height of specified face font.
25026 Returns height in pixels, or nil. */
25030 calc_line_height_property (struct it
*it
, Lisp_Object val
, struct font
*font
,
25031 int boff
, int override
)
25033 Lisp_Object face_name
= Qnil
;
25034 int ascent
, descent
, height
;
25036 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
25041 face_name
= XCAR (val
);
25043 if (!NUMBERP (val
))
25044 val
= make_number (1);
25045 if (NILP (face_name
))
25047 height
= it
->ascent
+ it
->descent
;
25052 if (NILP (face_name
))
25054 font
= FRAME_FONT (it
->f
);
25055 boff
= FRAME_BASELINE_OFFSET (it
->f
);
25057 else if (EQ (face_name
, Qt
))
25066 face_id
= lookup_named_face (it
->f
, face_name
, 0);
25068 return make_number (-1);
25070 face
= FACE_FROM_ID (it
->f
, face_id
);
25073 return make_number (-1);
25074 boff
= font
->baseline_offset
;
25075 if (font
->vertical_centering
)
25076 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
25079 ascent
= FONT_BASE (font
) + boff
;
25080 descent
= FONT_DESCENT (font
) - boff
;
25084 it
->override_ascent
= ascent
;
25085 it
->override_descent
= descent
;
25086 it
->override_boff
= boff
;
25089 height
= ascent
+ descent
;
25093 height
= (int)(XFLOAT_DATA (val
) * height
);
25094 else if (INTEGERP (val
))
25095 height
*= XINT (val
);
25097 return make_number (height
);
25101 /* Append a glyph for a glyphless character to IT->glyph_row. FACE_ID
25102 is a face ID to be used for the glyph. FOR_NO_FONT is nonzero if
25103 and only if this is for a character for which no font was found.
25105 If the display method (it->glyphless_method) is
25106 GLYPHLESS_DISPLAY_ACRONYM or GLYPHLESS_DISPLAY_HEX_CODE, LEN is a
25107 length of the acronym or the hexadecimal string, UPPER_XOFF and
25108 UPPER_YOFF are pixel offsets for the upper part of the string,
25109 LOWER_XOFF and LOWER_YOFF are for the lower part.
25111 For the other display methods, LEN through LOWER_YOFF are zero. */
25114 append_glyphless_glyph (struct it
*it
, int face_id
, int for_no_font
, int len
,
25115 short upper_xoff
, short upper_yoff
,
25116 short lower_xoff
, short lower_yoff
)
25118 struct glyph
*glyph
;
25119 enum glyph_row_area area
= it
->area
;
25121 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
25122 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
25124 /* If the glyph row is reversed, we need to prepend the glyph
25125 rather than append it. */
25126 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
25130 /* Make room for the additional glyph. */
25131 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
25133 glyph
= it
->glyph_row
->glyphs
[area
];
25135 glyph
->charpos
= CHARPOS (it
->position
);
25136 glyph
->object
= it
->object
;
25137 glyph
->pixel_width
= it
->pixel_width
;
25138 glyph
->ascent
= it
->ascent
;
25139 glyph
->descent
= it
->descent
;
25140 glyph
->voffset
= it
->voffset
;
25141 glyph
->type
= GLYPHLESS_GLYPH
;
25142 glyph
->u
.glyphless
.method
= it
->glyphless_method
;
25143 glyph
->u
.glyphless
.for_no_font
= for_no_font
;
25144 glyph
->u
.glyphless
.len
= len
;
25145 glyph
->u
.glyphless
.ch
= it
->c
;
25146 glyph
->slice
.glyphless
.upper_xoff
= upper_xoff
;
25147 glyph
->slice
.glyphless
.upper_yoff
= upper_yoff
;
25148 glyph
->slice
.glyphless
.lower_xoff
= lower_xoff
;
25149 glyph
->slice
.glyphless
.lower_yoff
= lower_yoff
;
25150 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
25151 glyph
->multibyte_p
= it
->multibyte_p
;
25152 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
25154 /* In R2L rows, the left and the right box edges need to be
25155 drawn in reverse direction. */
25156 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
25157 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
25161 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
25162 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
25164 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
25165 || it
->phys_descent
> it
->descent
);
25166 glyph
->padding_p
= 0;
25167 glyph
->glyph_not_available_p
= 0;
25168 glyph
->face_id
= face_id
;
25169 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
25172 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
25173 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
25175 glyph
->bidi_type
= it
->bidi_it
.type
;
25177 ++it
->glyph_row
->used
[area
];
25180 IT_EXPAND_MATRIX_WIDTH (it
, area
);
25184 /* Produce a glyph for a glyphless character for iterator IT.
25185 IT->glyphless_method specifies which method to use for displaying
25186 the character. See the description of enum
25187 glyphless_display_method in dispextern.h for the detail.
25189 FOR_NO_FONT is nonzero if and only if this is for a character for
25190 which no font was found. ACRONYM, if non-nil, is an acronym string
25191 for the character. */
25194 produce_glyphless_glyph (struct it
*it
, int for_no_font
, Lisp_Object acronym
)
25199 int base_width
, base_height
, width
, height
;
25200 short upper_xoff
, upper_yoff
, lower_xoff
, lower_yoff
;
25203 /* Get the metrics of the base font. We always refer to the current
25205 face
= FACE_FROM_ID (it
->f
, it
->face_id
)->ascii_face
;
25206 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
25207 it
->ascent
= FONT_BASE (font
) + font
->baseline_offset
;
25208 it
->descent
= FONT_DESCENT (font
) - font
->baseline_offset
;
25209 base_height
= it
->ascent
+ it
->descent
;
25210 base_width
= font
->average_width
;
25212 /* Get a face ID for the glyph by utilizing a cache (the same way as
25213 done for `escape-glyph' in get_next_display_element). */
25214 if (it
->f
== last_glyphless_glyph_frame
25215 && it
->face_id
== last_glyphless_glyph_face_id
)
25217 face_id
= last_glyphless_glyph_merged_face_id
;
25221 /* Merge the `glyphless-char' face into the current face. */
25222 face_id
= merge_faces (it
->f
, Qglyphless_char
, 0, it
->face_id
);
25223 last_glyphless_glyph_frame
= it
->f
;
25224 last_glyphless_glyph_face_id
= it
->face_id
;
25225 last_glyphless_glyph_merged_face_id
= face_id
;
25228 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_THIN_SPACE
)
25230 it
->pixel_width
= THIN_SPACE_WIDTH
;
25232 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
25234 else if (it
->glyphless_method
== GLYPHLESS_DISPLAY_EMPTY_BOX
)
25236 width
= CHAR_WIDTH (it
->c
);
25239 else if (width
> 4)
25241 it
->pixel_width
= base_width
* width
;
25243 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
25249 unsigned int code
[6];
25251 int ascent
, descent
;
25252 struct font_metrics metrics_upper
, metrics_lower
;
25254 face
= FACE_FROM_ID (it
->f
, face_id
);
25255 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
25256 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
25258 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_ACRONYM
)
25260 if (! STRINGP (acronym
) && CHAR_TABLE_P (Vglyphless_char_display
))
25261 acronym
= CHAR_TABLE_REF (Vglyphless_char_display
, it
->c
);
25262 if (CONSP (acronym
))
25263 acronym
= XCAR (acronym
);
25264 str
= STRINGP (acronym
) ? SSDATA (acronym
) : "";
25268 eassert (it
->glyphless_method
== GLYPHLESS_DISPLAY_HEX_CODE
);
25269 sprintf (buf
, "%0*X", it
->c
< 0x10000 ? 4 : 6, it
->c
);
25272 for (len
= 0; str
[len
] && ASCII_BYTE_P (str
[len
]) && len
< 6; len
++)
25273 code
[len
] = font
->driver
->encode_char (font
, str
[len
]);
25274 upper_len
= (len
+ 1) / 2;
25275 font
->driver
->text_extents (font
, code
, upper_len
,
25277 font
->driver
->text_extents (font
, code
+ upper_len
, len
- upper_len
,
25282 /* +4 is for vertical bars of a box plus 1-pixel spaces at both side. */
25283 width
= max (metrics_upper
.width
, metrics_lower
.width
) + 4;
25284 upper_xoff
= upper_yoff
= 2; /* the typical case */
25285 if (base_width
>= width
)
25287 /* Align the upper to the left, the lower to the right. */
25288 it
->pixel_width
= base_width
;
25289 lower_xoff
= base_width
- 2 - metrics_lower
.width
;
25293 /* Center the shorter one. */
25294 it
->pixel_width
= width
;
25295 if (metrics_upper
.width
>= metrics_lower
.width
)
25296 lower_xoff
= (width
- metrics_lower
.width
) / 2;
25299 /* FIXME: This code doesn't look right. It formerly was
25300 missing the "lower_xoff = 0;", which couldn't have
25301 been right since it left lower_xoff uninitialized. */
25303 upper_xoff
= (width
- metrics_upper
.width
) / 2;
25307 /* +5 is for horizontal bars of a box plus 1-pixel spaces at
25308 top, bottom, and between upper and lower strings. */
25309 height
= (metrics_upper
.ascent
+ metrics_upper
.descent
25310 + metrics_lower
.ascent
+ metrics_lower
.descent
) + 5;
25311 /* Center vertically.
25312 H:base_height, D:base_descent
25313 h:height, ld:lower_descent, la:lower_ascent, ud:upper_descent
25315 ascent = - (D - H/2 - h/2 + 1); "+ 1" for rounding up
25316 descent = D - H/2 + h/2;
25317 lower_yoff = descent - 2 - ld;
25318 upper_yoff = lower_yoff - la - 1 - ud; */
25319 ascent
= - (it
->descent
- (base_height
+ height
+ 1) / 2);
25320 descent
= it
->descent
- (base_height
- height
) / 2;
25321 lower_yoff
= descent
- 2 - metrics_lower
.descent
;
25322 upper_yoff
= (lower_yoff
- metrics_lower
.ascent
- 1
25323 - metrics_upper
.descent
);
25324 /* Don't make the height shorter than the base height. */
25325 if (height
> base_height
)
25327 it
->ascent
= ascent
;
25328 it
->descent
= descent
;
25332 it
->phys_ascent
= it
->ascent
;
25333 it
->phys_descent
= it
->descent
;
25335 append_glyphless_glyph (it
, face_id
, for_no_font
, len
,
25336 upper_xoff
, upper_yoff
,
25337 lower_xoff
, lower_yoff
);
25339 take_vertical_position_into_account (it
);
25344 Produce glyphs/get display metrics for the display element IT is
25345 loaded with. See the description of struct it in dispextern.h
25346 for an overview of struct it. */
25349 x_produce_glyphs (struct it
*it
)
25351 int extra_line_spacing
= it
->extra_line_spacing
;
25353 it
->glyph_not_available_p
= 0;
25355 if (it
->what
== IT_CHARACTER
)
25358 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25359 struct font
*font
= face
->font
;
25360 struct font_metrics
*pcm
= NULL
;
25361 int boff
; /* baseline offset */
25365 /* When no suitable font is found, display this character by
25366 the method specified in the first extra slot of
25367 Vglyphless_char_display. */
25368 Lisp_Object acronym
= lookup_glyphless_char_display (-1, it
);
25370 eassert (it
->what
== IT_GLYPHLESS
);
25371 produce_glyphless_glyph (it
, 1, STRINGP (acronym
) ? acronym
: Qnil
);
25375 boff
= font
->baseline_offset
;
25376 if (font
->vertical_centering
)
25377 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
25379 if (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t')
25385 if (it
->override_ascent
>= 0)
25387 it
->ascent
= it
->override_ascent
;
25388 it
->descent
= it
->override_descent
;
25389 boff
= it
->override_boff
;
25393 it
->ascent
= FONT_BASE (font
) + boff
;
25394 it
->descent
= FONT_DESCENT (font
) - boff
;
25397 if (get_char_glyph_code (it
->char_to_display
, font
, &char2b
))
25399 pcm
= get_per_char_metric (font
, &char2b
);
25400 if (pcm
->width
== 0
25401 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
25407 it
->phys_ascent
= pcm
->ascent
+ boff
;
25408 it
->phys_descent
= pcm
->descent
- boff
;
25409 it
->pixel_width
= pcm
->width
;
25413 it
->glyph_not_available_p
= 1;
25414 it
->phys_ascent
= it
->ascent
;
25415 it
->phys_descent
= it
->descent
;
25416 it
->pixel_width
= font
->space_width
;
25419 if (it
->constrain_row_ascent_descent_p
)
25421 if (it
->descent
> it
->max_descent
)
25423 it
->ascent
+= it
->descent
- it
->max_descent
;
25424 it
->descent
= it
->max_descent
;
25426 if (it
->ascent
> it
->max_ascent
)
25428 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
25429 it
->ascent
= it
->max_ascent
;
25431 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
25432 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
25433 extra_line_spacing
= 0;
25436 /* If this is a space inside a region of text with
25437 `space-width' property, change its width. */
25438 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
25440 it
->pixel_width
*= XFLOATINT (it
->space_width
);
25442 /* If face has a box, add the box thickness to the character
25443 height. If character has a box line to the left and/or
25444 right, add the box line width to the character's width. */
25445 if (face
->box
!= FACE_NO_BOX
)
25447 int thick
= face
->box_line_width
;
25451 it
->ascent
+= thick
;
25452 it
->descent
+= thick
;
25457 if (it
->start_of_box_run_p
)
25458 it
->pixel_width
+= thick
;
25459 if (it
->end_of_box_run_p
)
25460 it
->pixel_width
+= thick
;
25463 /* If face has an overline, add the height of the overline
25464 (1 pixel) and a 1 pixel margin to the character height. */
25465 if (face
->overline_p
)
25466 it
->ascent
+= overline_margin
;
25468 if (it
->constrain_row_ascent_descent_p
)
25470 if (it
->ascent
> it
->max_ascent
)
25471 it
->ascent
= it
->max_ascent
;
25472 if (it
->descent
> it
->max_descent
)
25473 it
->descent
= it
->max_descent
;
25476 take_vertical_position_into_account (it
);
25478 /* If we have to actually produce glyphs, do it. */
25483 /* Translate a space with a `space-width' property
25484 into a stretch glyph. */
25485 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
25486 / FONT_HEIGHT (font
));
25487 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
25488 it
->ascent
+ it
->descent
, ascent
);
25493 /* If characters with lbearing or rbearing are displayed
25494 in this line, record that fact in a flag of the
25495 glyph row. This is used to optimize X output code. */
25496 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
25497 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25499 if (! stretched_p
&& it
->pixel_width
== 0)
25500 /* We assure that all visible glyphs have at least 1-pixel
25502 it
->pixel_width
= 1;
25504 else if (it
->char_to_display
== '\n')
25506 /* A newline has no width, but we need the height of the
25507 line. But if previous part of the line sets a height,
25508 don't increase that height */
25510 Lisp_Object height
;
25511 Lisp_Object total_height
= Qnil
;
25513 it
->override_ascent
= -1;
25514 it
->pixel_width
= 0;
25517 height
= get_it_property (it
, Qline_height
);
25518 /* Split (line-height total-height) list */
25520 && CONSP (XCDR (height
))
25521 && NILP (XCDR (XCDR (height
))))
25523 total_height
= XCAR (XCDR (height
));
25524 height
= XCAR (height
);
25526 height
= calc_line_height_property (it
, height
, font
, boff
, 1);
25528 if (it
->override_ascent
>= 0)
25530 it
->ascent
= it
->override_ascent
;
25531 it
->descent
= it
->override_descent
;
25532 boff
= it
->override_boff
;
25536 it
->ascent
= FONT_BASE (font
) + boff
;
25537 it
->descent
= FONT_DESCENT (font
) - boff
;
25540 if (EQ (height
, Qt
))
25542 if (it
->descent
> it
->max_descent
)
25544 it
->ascent
+= it
->descent
- it
->max_descent
;
25545 it
->descent
= it
->max_descent
;
25547 if (it
->ascent
> it
->max_ascent
)
25549 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
25550 it
->ascent
= it
->max_ascent
;
25552 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
25553 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
25554 it
->constrain_row_ascent_descent_p
= 1;
25555 extra_line_spacing
= 0;
25559 Lisp_Object spacing
;
25561 it
->phys_ascent
= it
->ascent
;
25562 it
->phys_descent
= it
->descent
;
25564 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
25565 && face
->box
!= FACE_NO_BOX
25566 && face
->box_line_width
> 0)
25568 it
->ascent
+= face
->box_line_width
;
25569 it
->descent
+= face
->box_line_width
;
25572 && XINT (height
) > it
->ascent
+ it
->descent
)
25573 it
->ascent
= XINT (height
) - it
->descent
;
25575 if (!NILP (total_height
))
25576 spacing
= calc_line_height_property (it
, total_height
, font
, boff
, 0);
25579 spacing
= get_it_property (it
, Qline_spacing
);
25580 spacing
= calc_line_height_property (it
, spacing
, font
, boff
, 0);
25582 if (INTEGERP (spacing
))
25584 extra_line_spacing
= XINT (spacing
);
25585 if (!NILP (total_height
))
25586 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
25590 else /* i.e. (it->char_to_display == '\t') */
25592 if (font
->space_width
> 0)
25594 int tab_width
= it
->tab_width
* font
->space_width
;
25595 int x
= it
->current_x
+ it
->continuation_lines_width
;
25596 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
25598 /* If the distance from the current position to the next tab
25599 stop is less than a space character width, use the
25600 tab stop after that. */
25601 if (next_tab_x
- x
< font
->space_width
)
25602 next_tab_x
+= tab_width
;
25604 it
->pixel_width
= next_tab_x
- x
;
25606 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
25607 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
25611 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
25612 it
->ascent
+ it
->descent
, it
->ascent
);
25617 it
->pixel_width
= 0;
25622 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
25624 /* A static composition.
25626 Note: A composition is represented as one glyph in the
25627 glyph matrix. There are no padding glyphs.
25629 Important note: pixel_width, ascent, and descent are the
25630 values of what is drawn by draw_glyphs (i.e. the values of
25631 the overall glyphs composed). */
25632 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25633 int boff
; /* baseline offset */
25634 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
25635 int glyph_len
= cmp
->glyph_len
;
25636 struct font
*font
= face
->font
;
25640 /* If we have not yet calculated pixel size data of glyphs of
25641 the composition for the current face font, calculate them
25642 now. Theoretically, we have to check all fonts for the
25643 glyphs, but that requires much time and memory space. So,
25644 here we check only the font of the first glyph. This may
25645 lead to incorrect display, but it's very rare, and C-l
25646 (recenter-top-bottom) can correct the display anyway. */
25647 if (! cmp
->font
|| cmp
->font
!= font
)
25649 /* Ascent and descent of the font of the first character
25650 of this composition (adjusted by baseline offset).
25651 Ascent and descent of overall glyphs should not be less
25652 than these, respectively. */
25653 int font_ascent
, font_descent
, font_height
;
25654 /* Bounding box of the overall glyphs. */
25655 int leftmost
, rightmost
, lowest
, highest
;
25656 int lbearing
, rbearing
;
25657 int i
, width
, ascent
, descent
;
25658 int left_padded
= 0, right_padded
= 0;
25659 int c
IF_LINT (= 0); /* cmp->glyph_len can't be zero; see Bug#8512 */
25661 struct font_metrics
*pcm
;
25662 int font_not_found_p
;
25665 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
25666 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
25668 if (glyph_len
< cmp
->glyph_len
)
25670 for (i
= 0; i
< glyph_len
; i
++)
25672 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
25674 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
25679 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
25680 : IT_CHARPOS (*it
));
25681 /* If no suitable font is found, use the default font. */
25682 font_not_found_p
= font
== NULL
;
25683 if (font_not_found_p
)
25685 face
= face
->ascii_face
;
25688 boff
= font
->baseline_offset
;
25689 if (font
->vertical_centering
)
25690 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
25691 font_ascent
= FONT_BASE (font
) + boff
;
25692 font_descent
= FONT_DESCENT (font
) - boff
;
25693 font_height
= FONT_HEIGHT (font
);
25698 if (! font_not_found_p
)
25700 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
25702 pcm
= get_per_char_metric (font
, &char2b
);
25705 /* Initialize the bounding box. */
25708 width
= cmp
->glyph_len
> 0 ? pcm
->width
: 0;
25709 ascent
= pcm
->ascent
;
25710 descent
= pcm
->descent
;
25711 lbearing
= pcm
->lbearing
;
25712 rbearing
= pcm
->rbearing
;
25716 width
= cmp
->glyph_len
> 0 ? font
->space_width
: 0;
25717 ascent
= FONT_BASE (font
);
25718 descent
= FONT_DESCENT (font
);
25725 lowest
= - descent
+ boff
;
25726 highest
= ascent
+ boff
;
25728 if (! font_not_found_p
25729 && font
->default_ascent
25730 && CHAR_TABLE_P (Vuse_default_ascent
)
25731 && !NILP (Faref (Vuse_default_ascent
,
25732 make_number (it
->char_to_display
))))
25733 highest
= font
->default_ascent
+ boff
;
25735 /* Draw the first glyph at the normal position. It may be
25736 shifted to right later if some other glyphs are drawn
25738 cmp
->offsets
[i
* 2] = 0;
25739 cmp
->offsets
[i
* 2 + 1] = boff
;
25740 cmp
->lbearing
= lbearing
;
25741 cmp
->rbearing
= rbearing
;
25743 /* Set cmp->offsets for the remaining glyphs. */
25744 for (i
++; i
< glyph_len
; i
++)
25746 int left
, right
, btm
, top
;
25747 int ch
= COMPOSITION_GLYPH (cmp
, i
);
25749 struct face
*this_face
;
25753 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
25754 this_face
= FACE_FROM_ID (it
->f
, face_id
);
25755 font
= this_face
->font
;
25761 get_char_face_and_encoding (it
->f
, ch
, face_id
,
25763 pcm
= get_per_char_metric (font
, &char2b
);
25766 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
25769 width
= pcm
->width
;
25770 ascent
= pcm
->ascent
;
25771 descent
= pcm
->descent
;
25772 lbearing
= pcm
->lbearing
;
25773 rbearing
= pcm
->rbearing
;
25774 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
25776 /* Relative composition with or without
25777 alternate chars. */
25778 left
= (leftmost
+ rightmost
- width
) / 2;
25779 btm
= - descent
+ boff
;
25780 if (font
->relative_compose
25781 && (! CHAR_TABLE_P (Vignore_relative_composition
)
25782 || NILP (Faref (Vignore_relative_composition
,
25783 make_number (ch
)))))
25786 if (- descent
>= font
->relative_compose
)
25787 /* One extra pixel between two glyphs. */
25789 else if (ascent
<= 0)
25790 /* One extra pixel between two glyphs. */
25791 btm
= lowest
- 1 - ascent
- descent
;
25796 /* A composition rule is specified by an integer
25797 value that encodes global and new reference
25798 points (GREF and NREF). GREF and NREF are
25799 specified by numbers as below:
25801 0---1---2 -- ascent
25805 9--10--11 -- center
25807 ---3---4---5--- baseline
25809 6---7---8 -- descent
25811 int rule
= COMPOSITION_RULE (cmp
, i
);
25812 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
25814 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
25815 grefx
= gref
% 3, nrefx
= nref
% 3;
25816 grefy
= gref
/ 3, nrefy
= nref
/ 3;
25818 xoff
= font_height
* (xoff
- 128) / 256;
25820 yoff
= font_height
* (yoff
- 128) / 256;
25823 + grefx
* (rightmost
- leftmost
) / 2
25824 - nrefx
* width
/ 2
25827 btm
= ((grefy
== 0 ? highest
25829 : grefy
== 2 ? lowest
25830 : (highest
+ lowest
) / 2)
25831 - (nrefy
== 0 ? ascent
+ descent
25832 : nrefy
== 1 ? descent
- boff
25834 : (ascent
+ descent
) / 2)
25838 cmp
->offsets
[i
* 2] = left
;
25839 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
25841 /* Update the bounding box of the overall glyphs. */
25844 right
= left
+ width
;
25845 if (left
< leftmost
)
25847 if (right
> rightmost
)
25850 top
= btm
+ descent
+ ascent
;
25856 if (cmp
->lbearing
> left
+ lbearing
)
25857 cmp
->lbearing
= left
+ lbearing
;
25858 if (cmp
->rbearing
< left
+ rbearing
)
25859 cmp
->rbearing
= left
+ rbearing
;
25863 /* If there are glyphs whose x-offsets are negative,
25864 shift all glyphs to the right and make all x-offsets
25868 for (i
= 0; i
< cmp
->glyph_len
; i
++)
25869 cmp
->offsets
[i
* 2] -= leftmost
;
25870 rightmost
-= leftmost
;
25871 cmp
->lbearing
-= leftmost
;
25872 cmp
->rbearing
-= leftmost
;
25875 if (left_padded
&& cmp
->lbearing
< 0)
25877 for (i
= 0; i
< cmp
->glyph_len
; i
++)
25878 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
25879 rightmost
-= cmp
->lbearing
;
25880 cmp
->rbearing
-= cmp
->lbearing
;
25883 if (right_padded
&& rightmost
< cmp
->rbearing
)
25885 rightmost
= cmp
->rbearing
;
25888 cmp
->pixel_width
= rightmost
;
25889 cmp
->ascent
= highest
;
25890 cmp
->descent
= - lowest
;
25891 if (cmp
->ascent
< font_ascent
)
25892 cmp
->ascent
= font_ascent
;
25893 if (cmp
->descent
< font_descent
)
25894 cmp
->descent
= font_descent
;
25898 && (cmp
->lbearing
< 0
25899 || cmp
->rbearing
> cmp
->pixel_width
))
25900 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25902 it
->pixel_width
= cmp
->pixel_width
;
25903 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
25904 it
->descent
= it
->phys_descent
= cmp
->descent
;
25905 if (face
->box
!= FACE_NO_BOX
)
25907 int thick
= face
->box_line_width
;
25911 it
->ascent
+= thick
;
25912 it
->descent
+= thick
;
25917 if (it
->start_of_box_run_p
)
25918 it
->pixel_width
+= thick
;
25919 if (it
->end_of_box_run_p
)
25920 it
->pixel_width
+= thick
;
25923 /* If face has an overline, add the height of the overline
25924 (1 pixel) and a 1 pixel margin to the character height. */
25925 if (face
->overline_p
)
25926 it
->ascent
+= overline_margin
;
25928 take_vertical_position_into_account (it
);
25929 if (it
->ascent
< 0)
25931 if (it
->descent
< 0)
25934 if (it
->glyph_row
&& cmp
->glyph_len
> 0)
25935 append_composite_glyph (it
);
25937 else if (it
->what
== IT_COMPOSITION
)
25939 /* A dynamic (automatic) composition. */
25940 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25941 Lisp_Object gstring
;
25942 struct font_metrics metrics
;
25946 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
25948 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
25951 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
25952 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25953 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
25954 it
->descent
= it
->phys_descent
= metrics
.descent
;
25955 if (face
->box
!= FACE_NO_BOX
)
25957 int thick
= face
->box_line_width
;
25961 it
->ascent
+= thick
;
25962 it
->descent
+= thick
;
25967 if (it
->start_of_box_run_p
)
25968 it
->pixel_width
+= thick
;
25969 if (it
->end_of_box_run_p
)
25970 it
->pixel_width
+= thick
;
25972 /* If face has an overline, add the height of the overline
25973 (1 pixel) and a 1 pixel margin to the character height. */
25974 if (face
->overline_p
)
25975 it
->ascent
+= overline_margin
;
25976 take_vertical_position_into_account (it
);
25977 if (it
->ascent
< 0)
25979 if (it
->descent
< 0)
25983 append_composite_glyph (it
);
25985 else if (it
->what
== IT_GLYPHLESS
)
25986 produce_glyphless_glyph (it
, 0, Qnil
);
25987 else if (it
->what
== IT_IMAGE
)
25988 produce_image_glyph (it
);
25989 else if (it
->what
== IT_STRETCH
)
25990 produce_stretch_glyph (it
);
25991 #ifdef HAVE_XWIDGETS
25992 else if (it
->what
== IT_XWIDGET
)
25993 produce_xwidget_glyph (it
);
25996 /* Accumulate dimensions. Note: can't assume that it->descent > 0
25997 because this isn't true for images with `:ascent 100'. */
25998 eassert (it
->ascent
>= 0 && it
->descent
>= 0);
25999 if (it
->area
== TEXT_AREA
)
26000 it
->current_x
+= it
->pixel_width
;
26002 if (extra_line_spacing
> 0)
26004 it
->descent
+= extra_line_spacing
;
26005 if (extra_line_spacing
> it
->max_extra_line_spacing
)
26006 it
->max_extra_line_spacing
= extra_line_spacing
;
26009 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
26010 it
->max_descent
= max (it
->max_descent
, it
->descent
);
26011 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
26012 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
26016 Output LEN glyphs starting at START at the nominal cursor position.
26017 Advance the nominal cursor over the text. UPDATED_ROW is the glyph row
26018 being updated, and UPDATED_AREA is the area of that row being updated. */
26021 x_write_glyphs (struct window
*w
, struct glyph_row
*updated_row
,
26022 struct glyph
*start
, enum glyph_row_area updated_area
, int len
)
26024 int x
, hpos
, chpos
= w
->phys_cursor
.hpos
;
26026 eassert (updated_row
);
26027 /* When the window is hscrolled, cursor hpos can legitimately be out
26028 of bounds, but we draw the cursor at the corresponding window
26029 margin in that case. */
26030 if (!updated_row
->reversed_p
&& chpos
< 0)
26032 if (updated_row
->reversed_p
&& chpos
>= updated_row
->used
[TEXT_AREA
])
26033 chpos
= updated_row
->used
[TEXT_AREA
] - 1;
26037 /* Write glyphs. */
26039 hpos
= start
- updated_row
->glyphs
[updated_area
];
26040 x
= draw_glyphs (w
, output_cursor
.x
,
26041 updated_row
, updated_area
,
26043 DRAW_NORMAL_TEXT
, 0);
26045 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
26046 if (updated_area
== TEXT_AREA
26047 && w
->phys_cursor_on_p
26048 && w
->phys_cursor
.vpos
== output_cursor
.vpos
26050 && chpos
< hpos
+ len
)
26051 w
->phys_cursor_on_p
= 0;
26055 /* Advance the output cursor. */
26056 output_cursor
.hpos
+= len
;
26057 output_cursor
.x
= x
;
26062 Insert LEN glyphs from START at the nominal cursor position. */
26065 x_insert_glyphs (struct window
*w
, struct glyph_row
*updated_row
,
26066 struct glyph
*start
, enum glyph_row_area updated_area
, int len
)
26069 int line_height
, shift_by_width
, shifted_region_width
;
26070 struct glyph_row
*row
;
26071 struct glyph
*glyph
;
26072 int frame_x
, frame_y
;
26075 eassert (updated_row
);
26077 f
= XFRAME (WINDOW_FRAME (w
));
26079 /* Get the height of the line we are in. */
26081 line_height
= row
->height
;
26083 /* Get the width of the glyphs to insert. */
26084 shift_by_width
= 0;
26085 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
26086 shift_by_width
+= glyph
->pixel_width
;
26088 /* Get the width of the region to shift right. */
26089 shifted_region_width
= (window_box_width (w
, updated_area
)
26094 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
26095 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
26097 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
26098 line_height
, shift_by_width
);
26100 /* Write the glyphs. */
26101 hpos
= start
- row
->glyphs
[updated_area
];
26102 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
26104 DRAW_NORMAL_TEXT
, 0);
26106 /* Advance the output cursor. */
26107 output_cursor
.hpos
+= len
;
26108 output_cursor
.x
+= shift_by_width
;
26114 Erase the current text line from the nominal cursor position
26115 (inclusive) to pixel column TO_X (exclusive). The idea is that
26116 everything from TO_X onward is already erased.
26118 TO_X is a pixel position relative to UPDATED_AREA of currently
26119 updated window W. TO_X == -1 means clear to the end of this area. */
26122 x_clear_end_of_line (struct window
*w
, struct glyph_row
*updated_row
,
26123 enum glyph_row_area updated_area
, int to_x
)
26126 int max_x
, min_y
, max_y
;
26127 int from_x
, from_y
, to_y
;
26129 eassert (updated_row
);
26130 f
= XFRAME (w
->frame
);
26132 if (updated_row
->full_width_p
)
26133 max_x
= WINDOW_TOTAL_WIDTH (w
);
26135 max_x
= window_box_width (w
, updated_area
);
26136 max_y
= window_text_bottom_y (w
);
26138 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
26139 of window. For TO_X > 0, truncate to end of drawing area. */
26145 to_x
= min (to_x
, max_x
);
26147 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
26149 /* Notice if the cursor will be cleared by this operation. */
26150 if (!updated_row
->full_width_p
)
26151 notice_overwritten_cursor (w
, updated_area
,
26152 output_cursor
.x
, -1,
26154 MATRIX_ROW_BOTTOM_Y (updated_row
));
26156 from_x
= output_cursor
.x
;
26158 /* Translate to frame coordinates. */
26159 if (updated_row
->full_width_p
)
26161 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
26162 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
26166 int area_left
= window_box_left (w
, updated_area
);
26167 from_x
+= area_left
;
26171 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
26172 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
26173 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
26175 /* Prevent inadvertently clearing to end of the X window. */
26176 if (to_x
> from_x
&& to_y
> from_y
)
26179 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
26180 to_x
- from_x
, to_y
- from_y
);
26185 #endif /* HAVE_WINDOW_SYSTEM */
26189 /***********************************************************************
26191 ***********************************************************************/
26193 /* Value is the internal representation of the specified cursor type
26194 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
26195 of the bar cursor. */
26197 static enum text_cursor_kinds
26198 get_specified_cursor_type (Lisp_Object arg
, int *width
)
26200 enum text_cursor_kinds type
;
26205 if (EQ (arg
, Qbox
))
26206 return FILLED_BOX_CURSOR
;
26208 if (EQ (arg
, Qhollow
))
26209 return HOLLOW_BOX_CURSOR
;
26211 if (EQ (arg
, Qbar
))
26218 && EQ (XCAR (arg
), Qbar
)
26219 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
26221 *width
= XINT (XCDR (arg
));
26225 if (EQ (arg
, Qhbar
))
26228 return HBAR_CURSOR
;
26232 && EQ (XCAR (arg
), Qhbar
)
26233 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
26235 *width
= XINT (XCDR (arg
));
26236 return HBAR_CURSOR
;
26239 /* Treat anything unknown as "hollow box cursor".
26240 It was bad to signal an error; people have trouble fixing
26241 .Xdefaults with Emacs, when it has something bad in it. */
26242 type
= HOLLOW_BOX_CURSOR
;
26247 /* Set the default cursor types for specified frame. */
26249 set_frame_cursor_types (struct frame
*f
, Lisp_Object arg
)
26254 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
26255 FRAME_CURSOR_WIDTH (f
) = width
;
26257 /* By default, set up the blink-off state depending on the on-state. */
26259 tem
= Fassoc (arg
, Vblink_cursor_alist
);
26262 FRAME_BLINK_OFF_CURSOR (f
)
26263 = get_specified_cursor_type (XCDR (tem
), &width
);
26264 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
26267 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
26269 /* Make sure the cursor gets redrawn. */
26270 cursor_type_changed
= 1;
26274 #ifdef HAVE_WINDOW_SYSTEM
26276 /* Return the cursor we want to be displayed in window W. Return
26277 width of bar/hbar cursor through WIDTH arg. Return with
26278 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
26279 (i.e. if the `system caret' should track this cursor).
26281 In a mini-buffer window, we want the cursor only to appear if we
26282 are reading input from this window. For the selected window, we
26283 want the cursor type given by the frame parameter or buffer local
26284 setting of cursor-type. If explicitly marked off, draw no cursor.
26285 In all other cases, we want a hollow box cursor. */
26287 static enum text_cursor_kinds
26288 get_window_cursor_type (struct window
*w
, struct glyph
*glyph
, int *width
,
26289 int *active_cursor
)
26291 struct frame
*f
= XFRAME (w
->frame
);
26292 struct buffer
*b
= XBUFFER (w
->contents
);
26293 int cursor_type
= DEFAULT_CURSOR
;
26294 Lisp_Object alt_cursor
;
26295 int non_selected
= 0;
26297 *active_cursor
= 1;
26300 if (cursor_in_echo_area
26301 && FRAME_HAS_MINIBUF_P (f
)
26302 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
26304 if (w
== XWINDOW (echo_area_window
))
26306 if (EQ (BVAR (b
, cursor_type
), Qt
) || NILP (BVAR (b
, cursor_type
)))
26308 *width
= FRAME_CURSOR_WIDTH (f
);
26309 return FRAME_DESIRED_CURSOR (f
);
26312 return get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
26315 *active_cursor
= 0;
26319 /* Detect a nonselected window or nonselected frame. */
26320 else if (w
!= XWINDOW (f
->selected_window
)
26321 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)
26323 *active_cursor
= 0;
26325 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
26331 /* Never display a cursor in a window in which cursor-type is nil. */
26332 if (NILP (BVAR (b
, cursor_type
)))
26335 /* Get the normal cursor type for this window. */
26336 if (EQ (BVAR (b
, cursor_type
), Qt
))
26338 cursor_type
= FRAME_DESIRED_CURSOR (f
);
26339 *width
= FRAME_CURSOR_WIDTH (f
);
26342 cursor_type
= get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
26344 /* Use cursor-in-non-selected-windows instead
26345 for non-selected window or frame. */
26348 alt_cursor
= BVAR (b
, cursor_in_non_selected_windows
);
26349 if (!EQ (Qt
, alt_cursor
))
26350 return get_specified_cursor_type (alt_cursor
, width
);
26351 /* t means modify the normal cursor type. */
26352 if (cursor_type
== FILLED_BOX_CURSOR
)
26353 cursor_type
= HOLLOW_BOX_CURSOR
;
26354 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
26356 return cursor_type
;
26359 /* Use normal cursor if not blinked off. */
26360 if (!w
->cursor_off_p
)
26363 #ifdef HAVE_XWIDGETS
26364 if (glyph
!= NULL
&& glyph
->type
== XWIDGET_GLYPH
){
26365 //printf("attempt xwidget cursor avoidance in get_window_cursor_type\n");
26369 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
26371 if (cursor_type
== FILLED_BOX_CURSOR
)
26373 /* Using a block cursor on large images can be very annoying.
26374 So use a hollow cursor for "large" images.
26375 If image is not transparent (no mask), also use hollow cursor. */
26376 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
26377 if (img
!= NULL
&& IMAGEP (img
->spec
))
26379 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
26380 where N = size of default frame font size.
26381 This should cover most of the "tiny" icons people may use. */
26383 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
26384 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
26385 cursor_type
= HOLLOW_BOX_CURSOR
;
26388 else if (cursor_type
!= NO_CURSOR
)
26390 /* Display current only supports BOX and HOLLOW cursors for images.
26391 So for now, unconditionally use a HOLLOW cursor when cursor is
26392 not a solid box cursor. */
26393 cursor_type
= HOLLOW_BOX_CURSOR
;
26396 return cursor_type
;
26399 /* Cursor is blinked off, so determine how to "toggle" it. */
26401 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
26402 if ((alt_cursor
= Fassoc (BVAR (b
, cursor_type
), Vblink_cursor_alist
), !NILP (alt_cursor
)))
26403 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
26405 /* Then see if frame has specified a specific blink off cursor type. */
26406 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
26408 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
26409 return FRAME_BLINK_OFF_CURSOR (f
);
26413 /* Some people liked having a permanently visible blinking cursor,
26414 while others had very strong opinions against it. So it was
26415 decided to remove it. KFS 2003-09-03 */
26417 /* Finally perform built-in cursor blinking:
26418 filled box <-> hollow box
26419 wide [h]bar <-> narrow [h]bar
26420 narrow [h]bar <-> no cursor
26421 other type <-> no cursor */
26423 if (cursor_type
== FILLED_BOX_CURSOR
)
26424 return HOLLOW_BOX_CURSOR
;
26426 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
26429 return cursor_type
;
26437 /* Notice when the text cursor of window W has been completely
26438 overwritten by a drawing operation that outputs glyphs in AREA
26439 starting at X0 and ending at X1 in the line starting at Y0 and
26440 ending at Y1. X coordinates are area-relative. X1 < 0 means all
26441 the rest of the line after X0 has been written. Y coordinates
26442 are window-relative. */
26445 notice_overwritten_cursor (struct window
*w
, enum glyph_row_area area
,
26446 int x0
, int x1
, int y0
, int y1
)
26448 int cx0
, cx1
, cy0
, cy1
;
26449 struct glyph_row
*row
;
26451 if (!w
->phys_cursor_on_p
)
26453 if (area
!= TEXT_AREA
)
26456 if (w
->phys_cursor
.vpos
< 0
26457 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
26458 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
26459 !(row
->enabled_p
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
))))
26462 if (row
->cursor_in_fringe_p
)
26464 row
->cursor_in_fringe_p
= 0;
26465 draw_fringe_bitmap (w
, row
, row
->reversed_p
);
26466 w
->phys_cursor_on_p
= 0;
26470 cx0
= w
->phys_cursor
.x
;
26471 cx1
= cx0
+ w
->phys_cursor_width
;
26472 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
26475 /* The cursor image will be completely removed from the
26476 screen if the output area intersects the cursor area in
26477 y-direction. When we draw in [y0 y1[, and some part of
26478 the cursor is at y < y0, that part must have been drawn
26479 before. When scrolling, the cursor is erased before
26480 actually scrolling, so we don't come here. When not
26481 scrolling, the rows above the old cursor row must have
26482 changed, and in this case these rows must have written
26483 over the cursor image.
26485 Likewise if part of the cursor is below y1, with the
26486 exception of the cursor being in the first blank row at
26487 the buffer and window end because update_text_area
26488 doesn't draw that row. (Except when it does, but
26489 that's handled in update_text_area.) */
26491 cy0
= w
->phys_cursor
.y
;
26492 cy1
= cy0
+ w
->phys_cursor_height
;
26493 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
26496 w
->phys_cursor_on_p
= 0;
26499 #endif /* HAVE_WINDOW_SYSTEM */
26502 /************************************************************************
26504 ************************************************************************/
26506 #ifdef HAVE_WINDOW_SYSTEM
26509 Fix the display of area AREA of overlapping row ROW in window W
26510 with respect to the overlapping part OVERLAPS. */
26513 x_fix_overlapping_area (struct window
*w
, struct glyph_row
*row
,
26514 enum glyph_row_area area
, int overlaps
)
26521 for (i
= 0; i
< row
->used
[area
];)
26523 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
26525 int start
= i
, start_x
= x
;
26529 x
+= row
->glyphs
[area
][i
].pixel_width
;
26532 while (i
< row
->used
[area
]
26533 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
26535 draw_glyphs (w
, start_x
, row
, area
,
26537 DRAW_NORMAL_TEXT
, overlaps
);
26541 x
+= row
->glyphs
[area
][i
].pixel_width
;
26551 Draw the cursor glyph of window W in glyph row ROW. See the
26552 comment of draw_glyphs for the meaning of HL. */
26555 draw_phys_cursor_glyph (struct window
*w
, struct glyph_row
*row
,
26556 enum draw_glyphs_face hl
)
26558 /* If cursor hpos is out of bounds, don't draw garbage. This can
26559 happen in mini-buffer windows when switching between echo area
26560 glyphs and mini-buffer. */
26561 if ((row
->reversed_p
26562 ? (w
->phys_cursor
.hpos
>= 0)
26563 : (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])))
26565 int on_p
= w
->phys_cursor_on_p
;
26567 int hpos
= w
->phys_cursor
.hpos
;
26569 /* When the window is hscrolled, cursor hpos can legitimately be
26570 out of bounds, but we draw the cursor at the corresponding
26571 window margin in that case. */
26572 if (!row
->reversed_p
&& hpos
< 0)
26574 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26575 hpos
= row
->used
[TEXT_AREA
] - 1;
26577 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
, hpos
, hpos
+ 1,
26579 w
->phys_cursor_on_p
= on_p
;
26581 if (hl
== DRAW_CURSOR
)
26582 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
26583 /* When we erase the cursor, and ROW is overlapped by other
26584 rows, make sure that these overlapping parts of other rows
26586 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
26588 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
26590 if (row
> w
->current_matrix
->rows
26591 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
26592 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
26593 OVERLAPS_ERASED_CURSOR
);
26595 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
26596 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
26597 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
26598 OVERLAPS_ERASED_CURSOR
);
26605 Erase the image of a cursor of window W from the screen. */
26608 erase_phys_cursor (struct window
*w
)
26610 struct frame
*f
= XFRAME (w
->frame
);
26611 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
26612 int hpos
= w
->phys_cursor
.hpos
;
26613 int vpos
= w
->phys_cursor
.vpos
;
26614 int mouse_face_here_p
= 0;
26615 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
26616 struct glyph_row
*cursor_row
;
26617 struct glyph
*cursor_glyph
;
26618 enum draw_glyphs_face hl
;
26620 /* No cursor displayed or row invalidated => nothing to do on the
26622 if (w
->phys_cursor_type
== NO_CURSOR
)
26623 goto mark_cursor_off
;
26625 /* VPOS >= active_glyphs->nrows means that window has been resized.
26626 Don't bother to erase the cursor. */
26627 if (vpos
>= active_glyphs
->nrows
)
26628 goto mark_cursor_off
;
26630 /* If row containing cursor is marked invalid, there is nothing we
26632 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
26633 if (!cursor_row
->enabled_p
)
26634 goto mark_cursor_off
;
26636 /* If line spacing is > 0, old cursor may only be partially visible in
26637 window after split-window. So adjust visible height. */
26638 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
26639 window_text_bottom_y (w
) - cursor_row
->y
);
26641 /* If row is completely invisible, don't attempt to delete a cursor which
26642 isn't there. This can happen if cursor is at top of a window, and
26643 we switch to a buffer with a header line in that window. */
26644 if (cursor_row
->visible_height
<= 0)
26645 goto mark_cursor_off
;
26647 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
26648 if (cursor_row
->cursor_in_fringe_p
)
26650 cursor_row
->cursor_in_fringe_p
= 0;
26651 draw_fringe_bitmap (w
, cursor_row
, cursor_row
->reversed_p
);
26652 goto mark_cursor_off
;
26655 /* This can happen when the new row is shorter than the old one.
26656 In this case, either draw_glyphs or clear_end_of_line
26657 should have cleared the cursor. Note that we wouldn't be
26658 able to erase the cursor in this case because we don't have a
26659 cursor glyph at hand. */
26660 if ((cursor_row
->reversed_p
26661 ? (w
->phys_cursor
.hpos
< 0)
26662 : (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])))
26663 goto mark_cursor_off
;
26665 /* When the window is hscrolled, cursor hpos can legitimately be out
26666 of bounds, but we draw the cursor at the corresponding window
26667 margin in that case. */
26668 if (!cursor_row
->reversed_p
&& hpos
< 0)
26670 if (cursor_row
->reversed_p
&& hpos
>= cursor_row
->used
[TEXT_AREA
])
26671 hpos
= cursor_row
->used
[TEXT_AREA
] - 1;
26673 /* If the cursor is in the mouse face area, redisplay that when
26674 we clear the cursor. */
26675 if (! NILP (hlinfo
->mouse_face_window
)
26676 && coords_in_mouse_face_p (w
, hpos
, vpos
)
26677 /* Don't redraw the cursor's spot in mouse face if it is at the
26678 end of a line (on a newline). The cursor appears there, but
26679 mouse highlighting does not. */
26680 && cursor_row
->used
[TEXT_AREA
] > hpos
&& hpos
>= 0)
26681 mouse_face_here_p
= 1;
26683 /* Maybe clear the display under the cursor. */
26684 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
26687 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
26690 cursor_glyph
= get_phys_cursor_glyph (w
);
26691 if (cursor_glyph
== NULL
)
26692 goto mark_cursor_off
;
26694 width
= cursor_glyph
->pixel_width
;
26695 left_x
= window_box_left_offset (w
, TEXT_AREA
);
26696 x
= w
->phys_cursor
.x
;
26698 width
-= left_x
- x
;
26699 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
26700 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
26701 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
26704 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
26707 /* Erase the cursor by redrawing the character underneath it. */
26708 if (mouse_face_here_p
)
26709 hl
= DRAW_MOUSE_FACE
;
26711 hl
= DRAW_NORMAL_TEXT
;
26712 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
26715 w
->phys_cursor_on_p
= 0;
26716 w
->phys_cursor_type
= NO_CURSOR
;
26721 Display or clear cursor of window W. If ON is zero, clear the
26722 cursor. If it is non-zero, display the cursor. If ON is nonzero,
26723 where to put the cursor is specified by HPOS, VPOS, X and Y. */
26726 display_and_set_cursor (struct window
*w
, bool on
,
26727 int hpos
, int vpos
, int x
, int y
)
26729 struct frame
*f
= XFRAME (w
->frame
);
26730 int new_cursor_type
;
26731 int new_cursor_width
;
26733 struct glyph_row
*glyph_row
;
26734 struct glyph
*glyph
;
26736 /* This is pointless on invisible frames, and dangerous on garbaged
26737 windows and frames; in the latter case, the frame or window may
26738 be in the midst of changing its size, and x and y may be off the
26740 if (! FRAME_VISIBLE_P (f
)
26741 || FRAME_GARBAGED_P (f
)
26742 || vpos
>= w
->current_matrix
->nrows
26743 || hpos
>= w
->current_matrix
->matrix_w
)
26746 /* If cursor is off and we want it off, return quickly. */
26747 if (!on
&& !w
->phys_cursor_on_p
)
26750 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26751 /* If cursor row is not enabled, we don't really know where to
26752 display the cursor. */
26753 if (!glyph_row
->enabled_p
)
26755 w
->phys_cursor_on_p
= 0;
26760 if (!glyph_row
->exact_window_width_line_p
26761 || (0 <= hpos
&& hpos
< glyph_row
->used
[TEXT_AREA
]))
26762 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
26764 eassert (input_blocked_p ());
26766 /* Set new_cursor_type to the cursor we want to be displayed. */
26767 new_cursor_type
= get_window_cursor_type (w
, glyph
,
26768 &new_cursor_width
, &active_cursor
);
26770 /* If cursor is currently being shown and we don't want it to be or
26771 it is in the wrong place, or the cursor type is not what we want,
26773 if (w
->phys_cursor_on_p
26775 || w
->phys_cursor
.x
!= x
26776 || w
->phys_cursor
.y
!= y
26777 || new_cursor_type
!= w
->phys_cursor_type
26778 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
26779 && new_cursor_width
!= w
->phys_cursor_width
)))
26780 erase_phys_cursor (w
);
26782 /* Don't check phys_cursor_on_p here because that flag is only set
26783 to zero in some cases where we know that the cursor has been
26784 completely erased, to avoid the extra work of erasing the cursor
26785 twice. In other words, phys_cursor_on_p can be 1 and the cursor
26786 still not be visible, or it has only been partly erased. */
26789 w
->phys_cursor_ascent
= glyph_row
->ascent
;
26790 w
->phys_cursor_height
= glyph_row
->height
;
26792 /* Set phys_cursor_.* before x_draw_.* is called because some
26793 of them may need the information. */
26794 w
->phys_cursor
.x
= x
;
26795 w
->phys_cursor
.y
= glyph_row
->y
;
26796 w
->phys_cursor
.hpos
= hpos
;
26797 w
->phys_cursor
.vpos
= vpos
;
26800 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
26801 new_cursor_type
, new_cursor_width
,
26802 on
, active_cursor
);
26806 /* Switch the display of W's cursor on or off, according to the value
26810 update_window_cursor (struct window
*w
, bool on
)
26812 /* Don't update cursor in windows whose frame is in the process
26813 of being deleted. */
26814 if (w
->current_matrix
)
26816 int hpos
= w
->phys_cursor
.hpos
;
26817 int vpos
= w
->phys_cursor
.vpos
;
26818 struct glyph_row
*row
;
26820 if (vpos
>= w
->current_matrix
->nrows
26821 || hpos
>= w
->current_matrix
->matrix_w
)
26824 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26826 /* When the window is hscrolled, cursor hpos can legitimately be
26827 out of bounds, but we draw the cursor at the corresponding
26828 window margin in that case. */
26829 if (!row
->reversed_p
&& hpos
< 0)
26831 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26832 hpos
= row
->used
[TEXT_AREA
] - 1;
26835 display_and_set_cursor (w
, on
, hpos
, vpos
,
26836 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
26842 /* Call update_window_cursor with parameter ON_P on all leaf windows
26843 in the window tree rooted at W. */
26846 update_cursor_in_window_tree (struct window
*w
, bool on_p
)
26850 if (WINDOWP (w
->contents
))
26851 update_cursor_in_window_tree (XWINDOW (w
->contents
), on_p
);
26853 update_window_cursor (w
, on_p
);
26855 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
26861 Display the cursor on window W, or clear it, according to ON_P.
26862 Don't change the cursor's position. */
26865 x_update_cursor (struct frame
*f
, bool on_p
)
26867 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
26872 Clear the cursor of window W to background color, and mark the
26873 cursor as not shown. This is used when the text where the cursor
26874 is about to be rewritten. */
26877 x_clear_cursor (struct window
*w
)
26879 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
26880 update_window_cursor (w
, 0);
26883 #endif /* HAVE_WINDOW_SYSTEM */
26885 /* Implementation of draw_row_with_mouse_face for GUI sessions, GPM,
26888 draw_row_with_mouse_face (struct window
*w
, int start_x
, struct glyph_row
*row
,
26889 int start_hpos
, int end_hpos
,
26890 enum draw_glyphs_face draw
)
26892 #ifdef HAVE_WINDOW_SYSTEM
26893 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
26895 draw_glyphs (w
, start_x
, row
, TEXT_AREA
, start_hpos
, end_hpos
, draw
, 0);
26899 #if defined (HAVE_GPM) || defined (MSDOS) || defined (WINDOWSNT)
26900 tty_draw_row_with_mouse_face (w
, row
, start_hpos
, end_hpos
, draw
);
26904 /* Display the active region described by mouse_face_* according to DRAW. */
26907 show_mouse_face (Mouse_HLInfo
*hlinfo
, enum draw_glyphs_face draw
)
26909 struct window
*w
= XWINDOW (hlinfo
->mouse_face_window
);
26910 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
26912 if (/* If window is in the process of being destroyed, don't bother
26914 w
->current_matrix
!= NULL
26915 /* Don't update mouse highlight if hidden */
26916 && (draw
!= DRAW_MOUSE_FACE
|| !hlinfo
->mouse_face_hidden
)
26917 /* Recognize when we are called to operate on rows that don't exist
26918 anymore. This can happen when a window is split. */
26919 && hlinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
26921 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
26922 struct glyph_row
*row
, *first
, *last
;
26924 first
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
26925 last
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
26927 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
26929 int start_hpos
, end_hpos
, start_x
;
26931 /* For all but the first row, the highlight starts at column 0. */
26934 /* R2L rows have BEG and END in reversed order, but the
26935 screen drawing geometry is always left to right. So
26936 we need to mirror the beginning and end of the
26937 highlighted area in R2L rows. */
26938 if (!row
->reversed_p
)
26940 start_hpos
= hlinfo
->mouse_face_beg_col
;
26941 start_x
= hlinfo
->mouse_face_beg_x
;
26943 else if (row
== last
)
26945 start_hpos
= hlinfo
->mouse_face_end_col
;
26946 start_x
= hlinfo
->mouse_face_end_x
;
26954 else if (row
->reversed_p
&& row
== last
)
26956 start_hpos
= hlinfo
->mouse_face_end_col
;
26957 start_x
= hlinfo
->mouse_face_end_x
;
26967 if (!row
->reversed_p
)
26968 end_hpos
= hlinfo
->mouse_face_end_col
;
26969 else if (row
== first
)
26970 end_hpos
= hlinfo
->mouse_face_beg_col
;
26973 end_hpos
= row
->used
[TEXT_AREA
];
26974 if (draw
== DRAW_NORMAL_TEXT
)
26975 row
->fill_line_p
= 1; /* Clear to end of line */
26978 else if (row
->reversed_p
&& row
== first
)
26979 end_hpos
= hlinfo
->mouse_face_beg_col
;
26982 end_hpos
= row
->used
[TEXT_AREA
];
26983 if (draw
== DRAW_NORMAL_TEXT
)
26984 row
->fill_line_p
= 1; /* Clear to end of line */
26987 if (end_hpos
> start_hpos
)
26989 draw_row_with_mouse_face (w
, start_x
, row
,
26990 start_hpos
, end_hpos
, draw
);
26993 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
26997 #ifdef HAVE_WINDOW_SYSTEM
26998 /* When we've written over the cursor, arrange for it to
26999 be displayed again. */
27000 if (FRAME_WINDOW_P (f
)
27001 && phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
27003 int hpos
= w
->phys_cursor
.hpos
;
27005 /* When the window is hscrolled, cursor hpos can legitimately be
27006 out of bounds, but we draw the cursor at the corresponding
27007 window margin in that case. */
27008 if (!row
->reversed_p
&& hpos
< 0)
27010 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
27011 hpos
= row
->used
[TEXT_AREA
] - 1;
27014 display_and_set_cursor (w
, 1, hpos
, w
->phys_cursor
.vpos
,
27015 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
27018 #endif /* HAVE_WINDOW_SYSTEM */
27021 #ifdef HAVE_WINDOW_SYSTEM
27022 /* Change the mouse cursor. */
27023 if (FRAME_WINDOW_P (f
))
27025 if (draw
== DRAW_NORMAL_TEXT
27026 && !EQ (hlinfo
->mouse_face_window
, f
->tool_bar_window
))
27027 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
27028 else if (draw
== DRAW_MOUSE_FACE
)
27029 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
27031 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
27033 #endif /* HAVE_WINDOW_SYSTEM */
27037 Clear out the mouse-highlighted active region.
27038 Redraw it un-highlighted first. Value is non-zero if mouse
27039 face was actually drawn unhighlighted. */
27042 clear_mouse_face (Mouse_HLInfo
*hlinfo
)
27046 if (!hlinfo
->mouse_face_hidden
&& !NILP (hlinfo
->mouse_face_window
))
27048 show_mouse_face (hlinfo
, DRAW_NORMAL_TEXT
);
27052 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
27053 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
27054 hlinfo
->mouse_face_window
= Qnil
;
27055 hlinfo
->mouse_face_overlay
= Qnil
;
27059 /* Return non-zero if the coordinates HPOS and VPOS on windows W are
27060 within the mouse face on that window. */
27062 coords_in_mouse_face_p (struct window
*w
, int hpos
, int vpos
)
27064 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
27066 /* Quickly resolve the easy cases. */
27067 if (!(WINDOWP (hlinfo
->mouse_face_window
)
27068 && XWINDOW (hlinfo
->mouse_face_window
) == w
))
27070 if (vpos
< hlinfo
->mouse_face_beg_row
27071 || vpos
> hlinfo
->mouse_face_end_row
)
27073 if (vpos
> hlinfo
->mouse_face_beg_row
27074 && vpos
< hlinfo
->mouse_face_end_row
)
27077 if (!MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
)
27079 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
27081 if (hlinfo
->mouse_face_beg_col
<= hpos
&& hpos
< hlinfo
->mouse_face_end_col
)
27084 else if ((vpos
== hlinfo
->mouse_face_beg_row
27085 && hpos
>= hlinfo
->mouse_face_beg_col
)
27086 || (vpos
== hlinfo
->mouse_face_end_row
27087 && hpos
< hlinfo
->mouse_face_end_col
))
27092 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
27094 if (hlinfo
->mouse_face_end_col
< hpos
&& hpos
<= hlinfo
->mouse_face_beg_col
)
27097 else if ((vpos
== hlinfo
->mouse_face_beg_row
27098 && hpos
<= hlinfo
->mouse_face_beg_col
)
27099 || (vpos
== hlinfo
->mouse_face_end_row
27100 && hpos
> hlinfo
->mouse_face_end_col
))
27108 Non-zero if physical cursor of window W is within mouse face. */
27111 cursor_in_mouse_face_p (struct window
*w
)
27113 int hpos
= w
->phys_cursor
.hpos
;
27114 int vpos
= w
->phys_cursor
.vpos
;
27115 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
27117 /* When the window is hscrolled, cursor hpos can legitimately be out
27118 of bounds, but we draw the cursor at the corresponding window
27119 margin in that case. */
27120 if (!row
->reversed_p
&& hpos
< 0)
27122 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
27123 hpos
= row
->used
[TEXT_AREA
] - 1;
27125 return coords_in_mouse_face_p (w
, hpos
, vpos
);
27130 /* Find the glyph rows START_ROW and END_ROW of window W that display
27131 characters between buffer positions START_CHARPOS and END_CHARPOS
27132 (excluding END_CHARPOS). DISP_STRING is a display string that
27133 covers these buffer positions. This is similar to
27134 row_containing_pos, but is more accurate when bidi reordering makes
27135 buffer positions change non-linearly with glyph rows. */
27137 rows_from_pos_range (struct window
*w
,
27138 ptrdiff_t start_charpos
, ptrdiff_t end_charpos
,
27139 Lisp_Object disp_string
,
27140 struct glyph_row
**start
, struct glyph_row
**end
)
27142 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27143 int last_y
= window_text_bottom_y (w
);
27144 struct glyph_row
*row
;
27149 while (!first
->enabled_p
27150 && first
< MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
27153 /* Find the START row. */
27155 row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
;
27158 /* A row can potentially be the START row if the range of the
27159 characters it displays intersects the range
27160 [START_CHARPOS..END_CHARPOS). */
27161 if (! ((start_charpos
< MATRIX_ROW_START_CHARPOS (row
)
27162 && end_charpos
< MATRIX_ROW_START_CHARPOS (row
))
27163 /* See the commentary in row_containing_pos, for the
27164 explanation of the complicated way to check whether
27165 some position is beyond the end of the characters
27166 displayed by a row. */
27167 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (row
)
27168 || (start_charpos
== MATRIX_ROW_END_CHARPOS (row
)
27169 && !row
->ends_at_zv_p
27170 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
27171 && (end_charpos
> MATRIX_ROW_END_CHARPOS (row
)
27172 || (end_charpos
== MATRIX_ROW_END_CHARPOS (row
)
27173 && !row
->ends_at_zv_p
27174 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))))
27176 /* Found a candidate row. Now make sure at least one of the
27177 glyphs it displays has a charpos from the range
27178 [START_CHARPOS..END_CHARPOS).
27180 This is not obvious because bidi reordering could make
27181 buffer positions of a row be 1,2,3,102,101,100, and if we
27182 want to highlight characters in [50..60), we don't want
27183 this row, even though [50..60) does intersect [1..103),
27184 the range of character positions given by the row's start
27185 and end positions. */
27186 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
27187 struct glyph
*e
= g
+ row
->used
[TEXT_AREA
];
27191 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
27192 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
27193 /* A glyph that comes from DISP_STRING is by
27194 definition to be highlighted. */
27195 || EQ (g
->object
, disp_string
))
27204 /* Find the END row. */
27206 /* If the last row is partially visible, start looking for END
27207 from that row, instead of starting from FIRST. */
27208 && !(row
->enabled_p
27209 && row
->y
< last_y
&& MATRIX_ROW_BOTTOM_Y (row
) > last_y
))
27211 for ( ; row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
; row
++)
27213 struct glyph_row
*next
= row
+ 1;
27214 ptrdiff_t next_start
= MATRIX_ROW_START_CHARPOS (next
);
27216 if (!next
->enabled_p
27217 || next
>= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
)
27218 /* The first row >= START whose range of displayed characters
27219 does NOT intersect the range [START_CHARPOS..END_CHARPOS]
27220 is the row END + 1. */
27221 || (start_charpos
< next_start
27222 && end_charpos
< next_start
)
27223 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (next
)
27224 || (start_charpos
== MATRIX_ROW_END_CHARPOS (next
)
27225 && !next
->ends_at_zv_p
27226 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))
27227 && (end_charpos
> MATRIX_ROW_END_CHARPOS (next
)
27228 || (end_charpos
== MATRIX_ROW_END_CHARPOS (next
)
27229 && !next
->ends_at_zv_p
27230 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))))
27237 /* If the next row's edges intersect [START_CHARPOS..END_CHARPOS],
27238 but none of the characters it displays are in the range, it is
27240 struct glyph
*g
= next
->glyphs
[TEXT_AREA
];
27241 struct glyph
*s
= g
;
27242 struct glyph
*e
= g
+ next
->used
[TEXT_AREA
];
27246 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
27247 && ((start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
27248 /* If the buffer position of the first glyph in
27249 the row is equal to END_CHARPOS, it means
27250 the last character to be highlighted is the
27251 newline of ROW, and we must consider NEXT as
27253 || (((!next
->reversed_p
&& g
== s
)
27254 || (next
->reversed_p
&& g
== e
- 1))
27255 && (g
->charpos
== end_charpos
27256 /* Special case for when NEXT is an
27257 empty line at ZV. */
27258 || (g
->charpos
== -1
27259 && !row
->ends_at_zv_p
27260 && next_start
== end_charpos
)))))
27261 /* A glyph that comes from DISP_STRING is by
27262 definition to be highlighted. */
27263 || EQ (g
->object
, disp_string
))
27272 /* The first row that ends at ZV must be the last to be
27274 else if (next
->ends_at_zv_p
)
27283 /* This function sets the mouse_face_* elements of HLINFO, assuming
27284 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
27285 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
27286 for the overlay or run of text properties specifying the mouse
27287 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
27288 before-string and after-string that must also be highlighted.
27289 DISP_STRING, if non-nil, is a display string that may cover some
27290 or all of the highlighted text. */
27293 mouse_face_from_buffer_pos (Lisp_Object window
,
27294 Mouse_HLInfo
*hlinfo
,
27295 ptrdiff_t mouse_charpos
,
27296 ptrdiff_t start_charpos
,
27297 ptrdiff_t end_charpos
,
27298 Lisp_Object before_string
,
27299 Lisp_Object after_string
,
27300 Lisp_Object disp_string
)
27302 struct window
*w
= XWINDOW (window
);
27303 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27304 struct glyph_row
*r1
, *r2
;
27305 struct glyph
*glyph
, *end
;
27306 ptrdiff_t ignore
, pos
;
27309 eassert (NILP (disp_string
) || STRINGP (disp_string
));
27310 eassert (NILP (before_string
) || STRINGP (before_string
));
27311 eassert (NILP (after_string
) || STRINGP (after_string
));
27313 /* Find the rows corresponding to START_CHARPOS and END_CHARPOS. */
27314 rows_from_pos_range (w
, start_charpos
, end_charpos
, disp_string
, &r1
, &r2
);
27316 r1
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
27317 /* If the before-string or display-string contains newlines,
27318 rows_from_pos_range skips to its last row. Move back. */
27319 if (!NILP (before_string
) || !NILP (disp_string
))
27321 struct glyph_row
*prev
;
27322 while ((prev
= r1
- 1, prev
>= first
)
27323 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
27324 && prev
->used
[TEXT_AREA
] > 0)
27326 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
27327 glyph
= beg
+ prev
->used
[TEXT_AREA
];
27328 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
27330 || !(EQ (glyph
->object
, before_string
)
27331 || EQ (glyph
->object
, disp_string
)))
27338 r2
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
27339 hlinfo
->mouse_face_past_end
= 1;
27341 else if (!NILP (after_string
))
27343 /* If the after-string has newlines, advance to its last row. */
27344 struct glyph_row
*next
;
27345 struct glyph_row
*last
27346 = MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
27348 for (next
= r2
+ 1;
27350 && next
->used
[TEXT_AREA
] > 0
27351 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
27355 /* The rest of the display engine assumes that mouse_face_beg_row is
27356 either above mouse_face_end_row or identical to it. But with
27357 bidi-reordered continued lines, the row for START_CHARPOS could
27358 be below the row for END_CHARPOS. If so, swap the rows and store
27359 them in correct order. */
27362 struct glyph_row
*tem
= r2
;
27368 hlinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (r1
, w
->current_matrix
);
27369 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r2
, w
->current_matrix
);
27371 /* For a bidi-reordered row, the positions of BEFORE_STRING,
27372 AFTER_STRING, DISP_STRING, START_CHARPOS, and END_CHARPOS
27373 could be anywhere in the row and in any order. The strategy
27374 below is to find the leftmost and the rightmost glyph that
27375 belongs to either of these 3 strings, or whose position is
27376 between START_CHARPOS and END_CHARPOS, and highlight all the
27377 glyphs between those two. This may cover more than just the text
27378 between START_CHARPOS and END_CHARPOS if the range of characters
27379 strides the bidi level boundary, e.g. if the beginning is in R2L
27380 text while the end is in L2R text or vice versa. */
27381 if (!r1
->reversed_p
)
27383 /* This row is in a left to right paragraph. Scan it left to
27385 glyph
= r1
->glyphs
[TEXT_AREA
];
27386 end
= glyph
+ r1
->used
[TEXT_AREA
];
27389 /* Skip truncation glyphs at the start of the glyph row. */
27390 if (MATRIX_ROW_DISPLAYS_TEXT_P (r1
))
27392 && INTEGERP (glyph
->object
)
27393 && glyph
->charpos
< 0;
27395 x
+= glyph
->pixel_width
;
27397 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
27398 or DISP_STRING, and the first glyph from buffer whose
27399 position is between START_CHARPOS and END_CHARPOS. */
27401 && !INTEGERP (glyph
->object
)
27402 && !EQ (glyph
->object
, disp_string
)
27403 && !(BUFFERP (glyph
->object
)
27404 && (glyph
->charpos
>= start_charpos
27405 && glyph
->charpos
< end_charpos
));
27408 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27409 are present at buffer positions between START_CHARPOS and
27410 END_CHARPOS, or if they come from an overlay. */
27411 if (EQ (glyph
->object
, before_string
))
27413 pos
= string_buffer_position (before_string
,
27415 /* If pos == 0, it means before_string came from an
27416 overlay, not from a buffer position. */
27417 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27420 else if (EQ (glyph
->object
, after_string
))
27422 pos
= string_buffer_position (after_string
, end_charpos
);
27423 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27426 x
+= glyph
->pixel_width
;
27428 hlinfo
->mouse_face_beg_x
= x
;
27429 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
27433 /* This row is in a right to left paragraph. Scan it right to
27437 end
= r1
->glyphs
[TEXT_AREA
] - 1;
27438 glyph
= end
+ r1
->used
[TEXT_AREA
];
27440 /* Skip truncation glyphs at the start of the glyph row. */
27441 if (MATRIX_ROW_DISPLAYS_TEXT_P (r1
))
27443 && INTEGERP (glyph
->object
)
27444 && glyph
->charpos
< 0;
27448 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
27449 or DISP_STRING, and the first glyph from buffer whose
27450 position is between START_CHARPOS and END_CHARPOS. */
27452 && !INTEGERP (glyph
->object
)
27453 && !EQ (glyph
->object
, disp_string
)
27454 && !(BUFFERP (glyph
->object
)
27455 && (glyph
->charpos
>= start_charpos
27456 && glyph
->charpos
< end_charpos
));
27459 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27460 are present at buffer positions between START_CHARPOS and
27461 END_CHARPOS, or if they come from an overlay. */
27462 if (EQ (glyph
->object
, before_string
))
27464 pos
= string_buffer_position (before_string
, start_charpos
);
27465 /* If pos == 0, it means before_string came from an
27466 overlay, not from a buffer position. */
27467 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27470 else if (EQ (glyph
->object
, after_string
))
27472 pos
= string_buffer_position (after_string
, end_charpos
);
27473 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27478 glyph
++; /* first glyph to the right of the highlighted area */
27479 for (g
= r1
->glyphs
[TEXT_AREA
], x
= r1
->x
; g
< glyph
; g
++)
27480 x
+= g
->pixel_width
;
27481 hlinfo
->mouse_face_beg_x
= x
;
27482 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
27485 /* If the highlight ends in a different row, compute GLYPH and END
27486 for the end row. Otherwise, reuse the values computed above for
27487 the row where the highlight begins. */
27490 if (!r2
->reversed_p
)
27492 glyph
= r2
->glyphs
[TEXT_AREA
];
27493 end
= glyph
+ r2
->used
[TEXT_AREA
];
27498 end
= r2
->glyphs
[TEXT_AREA
] - 1;
27499 glyph
= end
+ r2
->used
[TEXT_AREA
];
27503 if (!r2
->reversed_p
)
27505 /* Skip truncation and continuation glyphs near the end of the
27506 row, and also blanks and stretch glyphs inserted by
27507 extend_face_to_end_of_line. */
27509 && INTEGERP ((end
- 1)->object
))
27511 /* Scan the rest of the glyph row from the end, looking for the
27512 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
27513 DISP_STRING, or whose position is between START_CHARPOS
27517 && !INTEGERP (end
->object
)
27518 && !EQ (end
->object
, disp_string
)
27519 && !(BUFFERP (end
->object
)
27520 && (end
->charpos
>= start_charpos
27521 && end
->charpos
< end_charpos
));
27524 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27525 are present at buffer positions between START_CHARPOS and
27526 END_CHARPOS, or if they come from an overlay. */
27527 if (EQ (end
->object
, before_string
))
27529 pos
= string_buffer_position (before_string
, start_charpos
);
27530 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27533 else if (EQ (end
->object
, after_string
))
27535 pos
= string_buffer_position (after_string
, end_charpos
);
27536 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27540 /* Find the X coordinate of the last glyph to be highlighted. */
27541 for (; glyph
<= end
; ++glyph
)
27542 x
+= glyph
->pixel_width
;
27544 hlinfo
->mouse_face_end_x
= x
;
27545 hlinfo
->mouse_face_end_col
= glyph
- r2
->glyphs
[TEXT_AREA
];
27549 /* Skip truncation and continuation glyphs near the end of the
27550 row, and also blanks and stretch glyphs inserted by
27551 extend_face_to_end_of_line. */
27555 && INTEGERP (end
->object
))
27557 x
+= end
->pixel_width
;
27560 /* Scan the rest of the glyph row from the end, looking for the
27561 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
27562 DISP_STRING, or whose position is between START_CHARPOS
27566 && !INTEGERP (end
->object
)
27567 && !EQ (end
->object
, disp_string
)
27568 && !(BUFFERP (end
->object
)
27569 && (end
->charpos
>= start_charpos
27570 && end
->charpos
< end_charpos
));
27573 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27574 are present at buffer positions between START_CHARPOS and
27575 END_CHARPOS, or if they come from an overlay. */
27576 if (EQ (end
->object
, before_string
))
27578 pos
= string_buffer_position (before_string
, start_charpos
);
27579 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27582 else if (EQ (end
->object
, after_string
))
27584 pos
= string_buffer_position (after_string
, end_charpos
);
27585 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27588 x
+= end
->pixel_width
;
27590 /* If we exited the above loop because we arrived at the last
27591 glyph of the row, and its buffer position is still not in
27592 range, it means the last character in range is the preceding
27593 newline. Bump the end column and x values to get past the
27596 && BUFFERP (end
->object
)
27597 && (end
->charpos
< start_charpos
27598 || end
->charpos
>= end_charpos
))
27600 x
+= end
->pixel_width
;
27603 hlinfo
->mouse_face_end_x
= x
;
27604 hlinfo
->mouse_face_end_col
= end
- r2
->glyphs
[TEXT_AREA
];
27607 hlinfo
->mouse_face_window
= window
;
27608 hlinfo
->mouse_face_face_id
27609 = face_at_buffer_position (w
, mouse_charpos
, 0, 0, &ignore
,
27611 !hlinfo
->mouse_face_hidden
, -1);
27612 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
27615 /* The following function is not used anymore (replaced with
27616 mouse_face_from_string_pos), but I leave it here for the time
27617 being, in case someone would. */
27619 #if 0 /* not used */
27621 /* Find the position of the glyph for position POS in OBJECT in
27622 window W's current matrix, and return in *X, *Y the pixel
27623 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
27625 RIGHT_P non-zero means return the position of the right edge of the
27626 glyph, RIGHT_P zero means return the left edge position.
27628 If no glyph for POS exists in the matrix, return the position of
27629 the glyph with the next smaller position that is in the matrix, if
27630 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
27631 exists in the matrix, return the position of the glyph with the
27632 next larger position in OBJECT.
27634 Value is non-zero if a glyph was found. */
27637 fast_find_string_pos (struct window
*w
, ptrdiff_t pos
, Lisp_Object object
,
27638 int *hpos
, int *vpos
, int *x
, int *y
, int right_p
)
27640 int yb
= window_text_bottom_y (w
);
27641 struct glyph_row
*r
;
27642 struct glyph
*best_glyph
= NULL
;
27643 struct glyph_row
*best_row
= NULL
;
27646 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27647 r
->enabled_p
&& r
->y
< yb
;
27650 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
27651 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
27654 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
27655 if (EQ (g
->object
, object
))
27657 if (g
->charpos
== pos
)
27664 else if (best_glyph
== NULL
27665 || ((eabs (g
->charpos
- pos
)
27666 < eabs (best_glyph
->charpos
- pos
))
27669 : g
->charpos
> pos
)))
27683 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
27687 *x
+= best_glyph
->pixel_width
;
27692 *vpos
= MATRIX_ROW_VPOS (best_row
, w
->current_matrix
);
27695 return best_glyph
!= NULL
;
27697 #endif /* not used */
27699 /* Find the positions of the first and the last glyphs in window W's
27700 current matrix that occlude positions [STARTPOS..ENDPOS] in OBJECT
27701 (assumed to be a string), and return in HLINFO's mouse_face_*
27702 members the pixel and column/row coordinates of those glyphs. */
27705 mouse_face_from_string_pos (struct window
*w
, Mouse_HLInfo
*hlinfo
,
27706 Lisp_Object object
,
27707 ptrdiff_t startpos
, ptrdiff_t endpos
)
27709 int yb
= window_text_bottom_y (w
);
27710 struct glyph_row
*r
;
27711 struct glyph
*g
, *e
;
27715 /* Find the glyph row with at least one position in the range
27716 [STARTPOS..ENDPOS], and the first glyph in that row whose
27717 position belongs to that range. */
27718 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27719 r
->enabled_p
&& r
->y
< yb
;
27722 if (!r
->reversed_p
)
27724 g
= r
->glyphs
[TEXT_AREA
];
27725 e
= g
+ r
->used
[TEXT_AREA
];
27726 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
27727 if (EQ (g
->object
, object
)
27728 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
27730 hlinfo
->mouse_face_beg_row
27731 = MATRIX_ROW_VPOS (r
, w
->current_matrix
);
27732 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
27733 hlinfo
->mouse_face_beg_x
= gx
;
27742 e
= r
->glyphs
[TEXT_AREA
];
27743 g
= e
+ r
->used
[TEXT_AREA
];
27744 for ( ; g
> e
; --g
)
27745 if (EQ ((g
-1)->object
, object
)
27746 && startpos
<= (g
-1)->charpos
&& (g
-1)->charpos
<= endpos
)
27748 hlinfo
->mouse_face_beg_row
27749 = MATRIX_ROW_VPOS (r
, w
->current_matrix
);
27750 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
27751 for (gx
= r
->x
, g1
= r
->glyphs
[TEXT_AREA
]; g1
< g
; ++g1
)
27752 gx
+= g1
->pixel_width
;
27753 hlinfo
->mouse_face_beg_x
= gx
;
27765 /* Starting with the next row, look for the first row which does NOT
27766 include any glyphs whose positions are in the range. */
27767 for (++r
; r
->enabled_p
&& r
->y
< yb
; ++r
)
27769 g
= r
->glyphs
[TEXT_AREA
];
27770 e
= g
+ r
->used
[TEXT_AREA
];
27772 for ( ; g
< e
; ++g
)
27773 if (EQ (g
->object
, object
)
27774 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
27783 /* The highlighted region ends on the previous row. */
27786 /* Set the end row. */
27787 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r
, w
->current_matrix
);
27789 /* Compute and set the end column and the end column's horizontal
27790 pixel coordinate. */
27791 if (!r
->reversed_p
)
27793 g
= r
->glyphs
[TEXT_AREA
];
27794 e
= g
+ r
->used
[TEXT_AREA
];
27795 for ( ; e
> g
; --e
)
27796 if (EQ ((e
-1)->object
, object
)
27797 && startpos
<= (e
-1)->charpos
&& (e
-1)->charpos
<= endpos
)
27799 hlinfo
->mouse_face_end_col
= e
- g
;
27801 for (gx
= r
->x
; g
< e
; ++g
)
27802 gx
+= g
->pixel_width
;
27803 hlinfo
->mouse_face_end_x
= gx
;
27807 e
= r
->glyphs
[TEXT_AREA
];
27808 g
= e
+ r
->used
[TEXT_AREA
];
27809 for (gx
= r
->x
; e
< g
; ++e
)
27811 if (EQ (e
->object
, object
)
27812 && startpos
<= e
->charpos
&& e
->charpos
<= endpos
)
27814 gx
+= e
->pixel_width
;
27816 hlinfo
->mouse_face_end_col
= e
- r
->glyphs
[TEXT_AREA
];
27817 hlinfo
->mouse_face_end_x
= gx
;
27821 #ifdef HAVE_WINDOW_SYSTEM
27823 /* See if position X, Y is within a hot-spot of an image. */
27826 on_hot_spot_p (Lisp_Object hot_spot
, int x
, int y
)
27828 if (!CONSP (hot_spot
))
27831 if (EQ (XCAR (hot_spot
), Qrect
))
27833 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
27834 Lisp_Object rect
= XCDR (hot_spot
);
27838 if (!CONSP (XCAR (rect
)))
27840 if (!CONSP (XCDR (rect
)))
27842 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
27844 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
27846 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
27848 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
27852 else if (EQ (XCAR (hot_spot
), Qcircle
))
27854 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
27855 Lisp_Object circ
= XCDR (hot_spot
);
27856 Lisp_Object lr
, lx0
, ly0
;
27858 && CONSP (XCAR (circ
))
27859 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
27860 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
27861 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
27863 double r
= XFLOATINT (lr
);
27864 double dx
= XINT (lx0
) - x
;
27865 double dy
= XINT (ly0
) - y
;
27866 return (dx
* dx
+ dy
* dy
<= r
* r
);
27869 else if (EQ (XCAR (hot_spot
), Qpoly
))
27871 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
27872 if (VECTORP (XCDR (hot_spot
)))
27874 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
27875 Lisp_Object
*poly
= v
->contents
;
27876 ptrdiff_t n
= v
->header
.size
;
27879 Lisp_Object lx
, ly
;
27882 /* Need an even number of coordinates, and at least 3 edges. */
27883 if (n
< 6 || n
& 1)
27886 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
27887 If count is odd, we are inside polygon. Pixels on edges
27888 may or may not be included depending on actual geometry of the
27890 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
27891 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
27893 x0
= XINT (lx
), y0
= XINT (ly
);
27894 for (i
= 0; i
< n
; i
+= 2)
27896 int x1
= x0
, y1
= y0
;
27897 if ((lx
= poly
[i
], !INTEGERP (lx
))
27898 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
27900 x0
= XINT (lx
), y0
= XINT (ly
);
27902 /* Does this segment cross the X line? */
27910 if (y
> y0
&& y
> y1
)
27912 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
27922 find_hot_spot (Lisp_Object map
, int x
, int y
)
27924 while (CONSP (map
))
27926 if (CONSP (XCAR (map
))
27927 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
27935 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
27937 doc
: /* Lookup in image map MAP coordinates X and Y.
27938 An image map is an alist where each element has the format (AREA ID PLIST).
27939 An AREA is specified as either a rectangle, a circle, or a polygon:
27940 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
27941 pixel coordinates of the upper left and bottom right corners.
27942 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
27943 and the radius of the circle; r may be a float or integer.
27944 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
27945 vector describes one corner in the polygon.
27946 Returns the alist element for the first matching AREA in MAP. */)
27947 (Lisp_Object map
, Lisp_Object x
, Lisp_Object y
)
27955 return find_hot_spot (map
,
27956 clip_to_bounds (INT_MIN
, XINT (x
), INT_MAX
),
27957 clip_to_bounds (INT_MIN
, XINT (y
), INT_MAX
));
27961 /* Display frame CURSOR, optionally using shape defined by POINTER. */
27963 define_frame_cursor1 (struct frame
*f
, Cursor cursor
, Lisp_Object pointer
)
27965 /* Do not change cursor shape while dragging mouse. */
27966 if (!NILP (do_mouse_tracking
))
27969 if (!NILP (pointer
))
27971 if (EQ (pointer
, Qarrow
))
27972 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27973 else if (EQ (pointer
, Qhand
))
27974 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
27975 else if (EQ (pointer
, Qtext
))
27976 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
27977 else if (EQ (pointer
, intern ("hdrag")))
27978 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
27979 #ifdef HAVE_X_WINDOWS
27980 else if (EQ (pointer
, intern ("vdrag")))
27981 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
27983 else if (EQ (pointer
, intern ("hourglass")))
27984 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
27985 else if (EQ (pointer
, Qmodeline
))
27986 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
27988 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27991 if (cursor
!= No_Cursor
)
27992 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
27995 #endif /* HAVE_WINDOW_SYSTEM */
27997 /* Take proper action when mouse has moved to the mode or header line
27998 or marginal area AREA of window W, x-position X and y-position Y.
27999 X is relative to the start of the text display area of W, so the
28000 width of bitmap areas and scroll bars must be subtracted to get a
28001 position relative to the start of the mode line. */
28004 note_mode_line_or_margin_highlight (Lisp_Object window
, int x
, int y
,
28005 enum window_part area
)
28007 struct window
*w
= XWINDOW (window
);
28008 struct frame
*f
= XFRAME (w
->frame
);
28009 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28010 #ifdef HAVE_WINDOW_SYSTEM
28011 Display_Info
*dpyinfo
;
28013 Cursor cursor
= No_Cursor
;
28014 Lisp_Object pointer
= Qnil
;
28015 int dx
, dy
, width
, height
;
28017 Lisp_Object string
, object
= Qnil
;
28018 Lisp_Object pos
IF_LINT (= Qnil
), help
;
28020 Lisp_Object mouse_face
;
28021 int original_x_pixel
= x
;
28022 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
28023 struct glyph_row
*row
IF_LINT (= 0);
28025 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
28030 /* Kludge alert: mode_line_string takes X/Y in pixels, but
28031 returns them in row/column units! */
28032 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
28033 &object
, &dx
, &dy
, &width
, &height
);
28035 row
= (area
== ON_MODE_LINE
28036 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
28037 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
28039 /* Find the glyph under the mouse pointer. */
28040 if (row
->mode_line_p
&& row
->enabled_p
)
28042 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
28043 end
= glyph
+ row
->used
[TEXT_AREA
];
28045 for (x0
= original_x_pixel
;
28046 glyph
< end
&& x0
>= glyph
->pixel_width
;
28048 x0
-= glyph
->pixel_width
;
28056 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
28057 /* Kludge alert: marginal_area_string takes X/Y in pixels, but
28058 returns them in row/column units! */
28059 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
28060 &object
, &dx
, &dy
, &width
, &height
);
28065 #ifdef HAVE_WINDOW_SYSTEM
28066 if (IMAGEP (object
))
28068 Lisp_Object image_map
, hotspot
;
28069 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
28071 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
28073 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
28077 /* Could check XCAR (hotspot) to see if we enter/leave this hot-spot.
28078 If so, we could look for mouse-enter, mouse-leave
28079 properties in PLIST (and do something...). */
28080 hotspot
= XCDR (hotspot
);
28081 if (CONSP (hotspot
)
28082 && (plist
= XCAR (hotspot
), CONSP (plist
)))
28084 pointer
= Fplist_get (plist
, Qpointer
);
28085 if (NILP (pointer
))
28087 help
= Fplist_get (plist
, Qhelp_echo
);
28090 help_echo_string
= help
;
28091 XSETWINDOW (help_echo_window
, w
);
28092 help_echo_object
= w
->contents
;
28093 help_echo_pos
= charpos
;
28097 if (NILP (pointer
))
28098 pointer
= Fplist_get (XCDR (object
), QCpointer
);
28100 #endif /* HAVE_WINDOW_SYSTEM */
28102 if (STRINGP (string
))
28103 pos
= make_number (charpos
);
28105 /* Set the help text and mouse pointer. If the mouse is on a part
28106 of the mode line without any text (e.g. past the right edge of
28107 the mode line text), use the default help text and pointer. */
28108 if (STRINGP (string
) || area
== ON_MODE_LINE
)
28110 /* Arrange to display the help by setting the global variables
28111 help_echo_string, help_echo_object, and help_echo_pos. */
28114 if (STRINGP (string
))
28115 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
28119 help_echo_string
= help
;
28120 XSETWINDOW (help_echo_window
, w
);
28121 help_echo_object
= string
;
28122 help_echo_pos
= charpos
;
28124 else if (area
== ON_MODE_LINE
)
28126 Lisp_Object default_help
28127 = buffer_local_value_1 (Qmode_line_default_help_echo
,
28130 if (STRINGP (default_help
))
28132 help_echo_string
= default_help
;
28133 XSETWINDOW (help_echo_window
, w
);
28134 help_echo_object
= Qnil
;
28135 help_echo_pos
= -1;
28140 #ifdef HAVE_WINDOW_SYSTEM
28141 /* Change the mouse pointer according to what is under it. */
28142 if (FRAME_WINDOW_P (f
))
28144 dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
28145 if (STRINGP (string
))
28147 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
28149 if (NILP (pointer
))
28150 pointer
= Fget_text_property (pos
, Qpointer
, string
);
28152 /* Change the mouse pointer according to what is under X/Y. */
28154 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
28157 map
= Fget_text_property (pos
, Qlocal_map
, string
);
28158 if (!KEYMAPP (map
))
28159 map
= Fget_text_property (pos
, Qkeymap
, string
);
28160 if (!KEYMAPP (map
))
28161 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
28165 /* Default mode-line pointer. */
28166 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
28171 /* Change the mouse face according to what is under X/Y. */
28172 if (STRINGP (string
))
28174 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
28175 if (!NILP (Vmouse_highlight
) && !NILP (mouse_face
)
28176 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
28181 struct glyph
* tmp_glyph
;
28185 int total_pixel_width
;
28186 ptrdiff_t begpos
, endpos
, ignore
;
28190 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
28191 Qmouse_face
, string
, Qnil
);
28197 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
28199 endpos
= SCHARS (string
);
28203 /* Calculate the glyph position GPOS of GLYPH in the
28204 displayed string, relative to the beginning of the
28205 highlighted part of the string.
28207 Note: GPOS is different from CHARPOS. CHARPOS is the
28208 position of GLYPH in the internal string object. A mode
28209 line string format has structures which are converted to
28210 a flattened string by the Emacs Lisp interpreter. The
28211 internal string is an element of those structures. The
28212 displayed string is the flattened string. */
28213 tmp_glyph
= row_start_glyph
;
28214 while (tmp_glyph
< glyph
28215 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
28216 && begpos
<= tmp_glyph
->charpos
28217 && tmp_glyph
->charpos
< endpos
)))
28219 gpos
= glyph
- tmp_glyph
;
28221 /* Calculate the length GSEQ_LENGTH of the glyph sequence of
28222 the highlighted part of the displayed string to which
28223 GLYPH belongs. Note: GSEQ_LENGTH is different from
28224 SCHARS (STRING), because the latter returns the length of
28225 the internal string. */
28226 for (tmp_glyph
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
28228 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
28229 && begpos
<= tmp_glyph
->charpos
28230 && tmp_glyph
->charpos
< endpos
));
28233 gseq_length
= gpos
+ (tmp_glyph
- glyph
) + 1;
28235 /* Calculate the total pixel width of all the glyphs between
28236 the beginning of the highlighted area and GLYPH. */
28237 total_pixel_width
= 0;
28238 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
28239 total_pixel_width
+= tmp_glyph
->pixel_width
;
28241 /* Pre calculation of re-rendering position. Note: X is in
28242 column units here, after the call to mode_line_string or
28243 marginal_area_string. */
28245 vpos
= (area
== ON_MODE_LINE
28246 ? (w
->current_matrix
)->nrows
- 1
28249 /* If GLYPH's position is included in the region that is
28250 already drawn in mouse face, we have nothing to do. */
28251 if ( EQ (window
, hlinfo
->mouse_face_window
)
28252 && (!row
->reversed_p
28253 ? (hlinfo
->mouse_face_beg_col
<= hpos
28254 && hpos
< hlinfo
->mouse_face_end_col
)
28255 /* In R2L rows we swap BEG and END, see below. */
28256 : (hlinfo
->mouse_face_end_col
<= hpos
28257 && hpos
< hlinfo
->mouse_face_beg_col
))
28258 && hlinfo
->mouse_face_beg_row
== vpos
)
28261 if (clear_mouse_face (hlinfo
))
28262 cursor
= No_Cursor
;
28264 if (!row
->reversed_p
)
28266 hlinfo
->mouse_face_beg_col
= hpos
;
28267 hlinfo
->mouse_face_beg_x
= original_x_pixel
28268 - (total_pixel_width
+ dx
);
28269 hlinfo
->mouse_face_end_col
= hpos
+ gseq_length
;
28270 hlinfo
->mouse_face_end_x
= 0;
28274 /* In R2L rows, show_mouse_face expects BEG and END
28275 coordinates to be swapped. */
28276 hlinfo
->mouse_face_end_col
= hpos
;
28277 hlinfo
->mouse_face_end_x
= original_x_pixel
28278 - (total_pixel_width
+ dx
);
28279 hlinfo
->mouse_face_beg_col
= hpos
+ gseq_length
;
28280 hlinfo
->mouse_face_beg_x
= 0;
28283 hlinfo
->mouse_face_beg_row
= vpos
;
28284 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_beg_row
;
28285 hlinfo
->mouse_face_past_end
= 0;
28286 hlinfo
->mouse_face_window
= window
;
28288 hlinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
28294 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
28296 if (NILP (pointer
))
28299 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
28300 clear_mouse_face (hlinfo
);
28302 #ifdef HAVE_WINDOW_SYSTEM
28303 if (FRAME_WINDOW_P (f
))
28304 define_frame_cursor1 (f
, cursor
, pointer
);
28310 Take proper action when the mouse has moved to position X, Y on
28311 frame F with regards to highlighting portions of display that have
28312 mouse-face properties. Also de-highlight portions of display where
28313 the mouse was before, set the mouse pointer shape as appropriate
28314 for the mouse coordinates, and activate help echo (tooltips).
28315 X and Y can be negative or out of range. */
28318 note_mouse_highlight (struct frame
*f
, int x
, int y
)
28320 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28321 enum window_part part
= ON_NOTHING
;
28322 Lisp_Object window
;
28324 Cursor cursor
= No_Cursor
;
28325 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
28328 /* When a menu is active, don't highlight because this looks odd. */
28329 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (MSDOS)
28330 if (popup_activated ())
28334 if (!f
->glyphs_initialized_p
28335 || f
->pointer_invisible
)
28338 hlinfo
->mouse_face_mouse_x
= x
;
28339 hlinfo
->mouse_face_mouse_y
= y
;
28340 hlinfo
->mouse_face_mouse_frame
= f
;
28342 if (hlinfo
->mouse_face_defer
)
28345 /* Which window is that in? */
28346 window
= window_from_coordinates (f
, x
, y
, &part
, 1);
28348 /* If displaying active text in another window, clear that. */
28349 if (! EQ (window
, hlinfo
->mouse_face_window
)
28350 /* Also clear if we move out of text area in same window. */
28351 || (!NILP (hlinfo
->mouse_face_window
)
28354 && part
!= ON_MODE_LINE
28355 && part
!= ON_HEADER_LINE
))
28356 clear_mouse_face (hlinfo
);
28358 /* Not on a window -> return. */
28359 if (!WINDOWP (window
))
28362 /* Reset help_echo_string. It will get recomputed below. */
28363 help_echo_string
= Qnil
;
28365 /* Convert to window-relative pixel coordinates. */
28366 w
= XWINDOW (window
);
28367 frame_to_window_pixel_xy (w
, &x
, &y
);
28369 #ifdef HAVE_WINDOW_SYSTEM
28370 /* Handle tool-bar window differently since it doesn't display a
28372 if (EQ (window
, f
->tool_bar_window
))
28374 note_tool_bar_highlight (f
, x
, y
);
28379 /* Mouse is on the mode, header line or margin? */
28380 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
28381 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
28383 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
28387 #ifdef HAVE_WINDOW_SYSTEM
28388 if (part
== ON_VERTICAL_BORDER
)
28390 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
28391 help_echo_string
= build_string ("drag-mouse-1: resize");
28393 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
28394 || part
== ON_SCROLL_BAR
)
28395 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
28397 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
28400 /* Are we in a window whose display is up to date?
28401 And verify the buffer's text has not changed. */
28402 b
= XBUFFER (w
->contents
);
28403 if (part
== ON_TEXT
&& w
->window_end_valid
&& !window_outdated (w
))
28405 int hpos
, vpos
, dx
, dy
, area
= LAST_AREA
;
28407 struct glyph
*glyph
;
28408 Lisp_Object object
;
28409 Lisp_Object mouse_face
= Qnil
, position
;
28410 Lisp_Object
*overlay_vec
= NULL
;
28411 ptrdiff_t i
, noverlays
;
28412 struct buffer
*obuf
;
28413 ptrdiff_t obegv
, ozv
;
28416 /* Find the glyph under X/Y. */
28417 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
28419 #ifdef HAVE_WINDOW_SYSTEM
28420 /* Look for :pointer property on image. */
28421 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
28423 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
28424 if (img
!= NULL
&& IMAGEP (img
->spec
))
28426 Lisp_Object image_map
, hotspot
;
28427 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
28429 && (hotspot
= find_hot_spot (image_map
,
28430 glyph
->slice
.img
.x
+ dx
,
28431 glyph
->slice
.img
.y
+ dy
),
28433 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
28437 /* Could check XCAR (hotspot) to see if we enter/leave
28439 If so, we could look for mouse-enter, mouse-leave
28440 properties in PLIST (and do something...). */
28441 hotspot
= XCDR (hotspot
);
28442 if (CONSP (hotspot
)
28443 && (plist
= XCAR (hotspot
), CONSP (plist
)))
28445 pointer
= Fplist_get (plist
, Qpointer
);
28446 if (NILP (pointer
))
28448 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
28449 if (!NILP (help_echo_string
))
28451 help_echo_window
= window
;
28452 help_echo_object
= glyph
->object
;
28453 help_echo_pos
= glyph
->charpos
;
28457 if (NILP (pointer
))
28458 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
28461 #endif /* HAVE_WINDOW_SYSTEM */
28463 /* Clear mouse face if X/Y not over text. */
28465 || area
!= TEXT_AREA
28466 || !MATRIX_ROW_DISPLAYS_TEXT_P (MATRIX_ROW (w
->current_matrix
, vpos
))
28467 /* Glyph's OBJECT is an integer for glyphs inserted by the
28468 display engine for its internal purposes, like truncation
28469 and continuation glyphs and blanks beyond the end of
28470 line's text on text terminals. If we are over such a
28471 glyph, we are not over any text. */
28472 || INTEGERP (glyph
->object
)
28473 /* R2L rows have a stretch glyph at their front, which
28474 stands for no text, whereas L2R rows have no glyphs at
28475 all beyond the end of text. Treat such stretch glyphs
28476 like we do with NULL glyphs in L2R rows. */
28477 || (MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
28478 && glyph
== MATRIX_ROW_GLYPH_START (w
->current_matrix
, vpos
)
28479 && glyph
->type
== STRETCH_GLYPH
28480 && glyph
->avoid_cursor_p
))
28482 if (clear_mouse_face (hlinfo
))
28483 cursor
= No_Cursor
;
28484 #ifdef HAVE_WINDOW_SYSTEM
28485 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
28487 if (area
!= TEXT_AREA
)
28488 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
28490 pointer
= Vvoid_text_area_pointer
;
28496 pos
= glyph
->charpos
;
28497 object
= glyph
->object
;
28498 if (!STRINGP (object
) && !BUFFERP (object
))
28501 /* If we get an out-of-range value, return now; avoid an error. */
28502 if (BUFFERP (object
) && pos
> BUF_Z (b
))
28505 /* Make the window's buffer temporarily current for
28506 overlays_at and compute_char_face. */
28507 obuf
= current_buffer
;
28508 current_buffer
= b
;
28514 /* Is this char mouse-active or does it have help-echo? */
28515 position
= make_number (pos
);
28517 if (BUFFERP (object
))
28519 /* Put all the overlays we want in a vector in overlay_vec. */
28520 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
28521 /* Sort overlays into increasing priority order. */
28522 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
28527 if (NILP (Vmouse_highlight
))
28529 clear_mouse_face (hlinfo
);
28530 goto check_help_echo
;
28533 same_region
= coords_in_mouse_face_p (w
, hpos
, vpos
);
28536 cursor
= No_Cursor
;
28538 /* Check mouse-face highlighting. */
28540 /* If there exists an overlay with mouse-face overlapping
28541 the one we are currently highlighting, we have to
28542 check if we enter the overlapping overlay, and then
28543 highlight only that. */
28544 || (OVERLAYP (hlinfo
->mouse_face_overlay
)
28545 && mouse_face_overlay_overlaps (hlinfo
->mouse_face_overlay
)))
28547 /* Find the highest priority overlay with a mouse-face. */
28548 Lisp_Object overlay
= Qnil
;
28549 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
28551 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
28552 if (!NILP (mouse_face
))
28553 overlay
= overlay_vec
[i
];
28556 /* If we're highlighting the same overlay as before, there's
28557 no need to do that again. */
28558 if (!NILP (overlay
) && EQ (overlay
, hlinfo
->mouse_face_overlay
))
28559 goto check_help_echo
;
28560 hlinfo
->mouse_face_overlay
= overlay
;
28562 /* Clear the display of the old active region, if any. */
28563 if (clear_mouse_face (hlinfo
))
28564 cursor
= No_Cursor
;
28566 /* If no overlay applies, get a text property. */
28567 if (NILP (overlay
))
28568 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
28570 /* Next, compute the bounds of the mouse highlighting and
28572 if (!NILP (mouse_face
) && STRINGP (object
))
28574 /* The mouse-highlighting comes from a display string
28575 with a mouse-face. */
28579 s
= Fprevious_single_property_change
28580 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
28581 e
= Fnext_single_property_change
28582 (position
, Qmouse_face
, object
, Qnil
);
28584 s
= make_number (0);
28586 e
= make_number (SCHARS (object
) - 1);
28587 mouse_face_from_string_pos (w
, hlinfo
, object
,
28588 XINT (s
), XINT (e
));
28589 hlinfo
->mouse_face_past_end
= 0;
28590 hlinfo
->mouse_face_window
= window
;
28591 hlinfo
->mouse_face_face_id
28592 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
28593 glyph
->face_id
, 1);
28594 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
28595 cursor
= No_Cursor
;
28599 /* The mouse-highlighting, if any, comes from an overlay
28600 or text property in the buffer. */
28601 Lisp_Object buffer
IF_LINT (= Qnil
);
28602 Lisp_Object disp_string
IF_LINT (= Qnil
);
28604 if (STRINGP (object
))
28606 /* If we are on a display string with no mouse-face,
28607 check if the text under it has one. */
28608 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
28609 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28610 pos
= string_buffer_position (object
, start
);
28613 mouse_face
= get_char_property_and_overlay
28614 (make_number (pos
), Qmouse_face
, w
->contents
, &overlay
);
28615 buffer
= w
->contents
;
28616 disp_string
= object
;
28622 disp_string
= Qnil
;
28625 if (!NILP (mouse_face
))
28627 Lisp_Object before
, after
;
28628 Lisp_Object before_string
, after_string
;
28629 /* To correctly find the limits of mouse highlight
28630 in a bidi-reordered buffer, we must not use the
28631 optimization of limiting the search in
28632 previous-single-property-change and
28633 next-single-property-change, because
28634 rows_from_pos_range needs the real start and end
28635 positions to DTRT in this case. That's because
28636 the first row visible in a window does not
28637 necessarily display the character whose position
28638 is the smallest. */
28640 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
28641 ? Fmarker_position (w
->start
)
28644 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
28645 ? make_number (BUF_Z (XBUFFER (buffer
)) - w
->window_end_pos
)
28648 if (NILP (overlay
))
28650 /* Handle the text property case. */
28651 before
= Fprevious_single_property_change
28652 (make_number (pos
+ 1), Qmouse_face
, buffer
, lim1
);
28653 after
= Fnext_single_property_change
28654 (make_number (pos
), Qmouse_face
, buffer
, lim2
);
28655 before_string
= after_string
= Qnil
;
28659 /* Handle the overlay case. */
28660 before
= Foverlay_start (overlay
);
28661 after
= Foverlay_end (overlay
);
28662 before_string
= Foverlay_get (overlay
, Qbefore_string
);
28663 after_string
= Foverlay_get (overlay
, Qafter_string
);
28665 if (!STRINGP (before_string
)) before_string
= Qnil
;
28666 if (!STRINGP (after_string
)) after_string
= Qnil
;
28669 mouse_face_from_buffer_pos (window
, hlinfo
, pos
,
28672 : XFASTINT (before
),
28674 ? BUF_Z (XBUFFER (buffer
))
28675 : XFASTINT (after
),
28676 before_string
, after_string
,
28678 cursor
= No_Cursor
;
28685 /* Look for a `help-echo' property. */
28686 if (NILP (help_echo_string
)) {
28687 Lisp_Object help
, overlay
;
28689 /* Check overlays first. */
28690 help
= overlay
= Qnil
;
28691 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
28693 overlay
= overlay_vec
[i
];
28694 help
= Foverlay_get (overlay
, Qhelp_echo
);
28699 help_echo_string
= help
;
28700 help_echo_window
= window
;
28701 help_echo_object
= overlay
;
28702 help_echo_pos
= pos
;
28706 Lisp_Object obj
= glyph
->object
;
28707 ptrdiff_t charpos
= glyph
->charpos
;
28709 /* Try text properties. */
28712 && charpos
< SCHARS (obj
))
28714 help
= Fget_text_property (make_number (charpos
),
28718 /* If the string itself doesn't specify a help-echo,
28719 see if the buffer text ``under'' it does. */
28720 struct glyph_row
*r
28721 = MATRIX_ROW (w
->current_matrix
, vpos
);
28722 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28723 ptrdiff_t p
= string_buffer_position (obj
, start
);
28726 help
= Fget_char_property (make_number (p
),
28727 Qhelp_echo
, w
->contents
);
28736 else if (BUFFERP (obj
)
28739 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
28744 help_echo_string
= help
;
28745 help_echo_window
= window
;
28746 help_echo_object
= obj
;
28747 help_echo_pos
= charpos
;
28752 #ifdef HAVE_WINDOW_SYSTEM
28753 /* Look for a `pointer' property. */
28754 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
28756 /* Check overlays first. */
28757 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
28758 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
28760 if (NILP (pointer
))
28762 Lisp_Object obj
= glyph
->object
;
28763 ptrdiff_t charpos
= glyph
->charpos
;
28765 /* Try text properties. */
28768 && charpos
< SCHARS (obj
))
28770 pointer
= Fget_text_property (make_number (charpos
),
28772 if (NILP (pointer
))
28774 /* If the string itself doesn't specify a pointer,
28775 see if the buffer text ``under'' it does. */
28776 struct glyph_row
*r
28777 = MATRIX_ROW (w
->current_matrix
, vpos
);
28778 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28779 ptrdiff_t p
= string_buffer_position (obj
, start
);
28781 pointer
= Fget_char_property (make_number (p
),
28782 Qpointer
, w
->contents
);
28785 else if (BUFFERP (obj
)
28788 pointer
= Fget_text_property (make_number (charpos
),
28792 #endif /* HAVE_WINDOW_SYSTEM */
28796 current_buffer
= obuf
;
28801 #ifdef HAVE_WINDOW_SYSTEM
28802 if (FRAME_WINDOW_P (f
))
28803 define_frame_cursor1 (f
, cursor
, pointer
);
28805 /* This is here to prevent a compiler error, about "label at end of
28806 compound statement". */
28813 Clear any mouse-face on window W. This function is part of the
28814 redisplay interface, and is called from try_window_id and similar
28815 functions to ensure the mouse-highlight is off. */
28818 x_clear_window_mouse_face (struct window
*w
)
28820 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
28821 Lisp_Object window
;
28824 XSETWINDOW (window
, w
);
28825 if (EQ (window
, hlinfo
->mouse_face_window
))
28826 clear_mouse_face (hlinfo
);
28832 Just discard the mouse face information for frame F, if any.
28833 This is used when the size of F is changed. */
28836 cancel_mouse_face (struct frame
*f
)
28838 Lisp_Object window
;
28839 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28841 window
= hlinfo
->mouse_face_window
;
28842 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
28844 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
28845 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
28846 hlinfo
->mouse_face_window
= Qnil
;
28852 /***********************************************************************
28854 ***********************************************************************/
28856 #ifdef HAVE_WINDOW_SYSTEM
28858 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
28859 which intersects rectangle R. R is in window-relative coordinates. */
28862 expose_area (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
,
28863 enum glyph_row_area area
)
28865 struct glyph
*first
= row
->glyphs
[area
];
28866 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
28867 struct glyph
*last
;
28868 int first_x
, start_x
, x
;
28870 if (area
== TEXT_AREA
&& row
->fill_line_p
)
28871 /* If row extends face to end of line write the whole line. */
28872 draw_glyphs (w
, 0, row
, area
,
28873 0, row
->used
[area
],
28874 DRAW_NORMAL_TEXT
, 0);
28877 /* Set START_X to the window-relative start position for drawing glyphs of
28878 AREA. The first glyph of the text area can be partially visible.
28879 The first glyphs of other areas cannot. */
28880 start_x
= window_box_left_offset (w
, area
);
28882 if (area
== TEXT_AREA
)
28885 /* Find the first glyph that must be redrawn. */
28887 && x
+ first
->pixel_width
< r
->x
)
28889 x
+= first
->pixel_width
;
28893 /* Find the last one. */
28897 && x
< r
->x
+ r
->width
)
28899 x
+= last
->pixel_width
;
28905 draw_glyphs (w
, first_x
- start_x
, row
, area
,
28906 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
28907 DRAW_NORMAL_TEXT
, 0);
28912 /* Redraw the parts of the glyph row ROW on window W intersecting
28913 rectangle R. R is in window-relative coordinates. Value is
28914 non-zero if mouse-face was overwritten. */
28917 expose_line (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
)
28919 eassert (row
->enabled_p
);
28921 if (row
->mode_line_p
|| w
->pseudo_window_p
)
28922 draw_glyphs (w
, 0, row
, TEXT_AREA
,
28923 0, row
->used
[TEXT_AREA
],
28924 DRAW_NORMAL_TEXT
, 0);
28927 if (row
->used
[LEFT_MARGIN_AREA
])
28928 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
28929 if (row
->used
[TEXT_AREA
])
28930 expose_area (w
, row
, r
, TEXT_AREA
);
28931 if (row
->used
[RIGHT_MARGIN_AREA
])
28932 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
28933 draw_row_fringe_bitmaps (w
, row
);
28936 return row
->mouse_face_p
;
28940 /* Redraw those parts of glyphs rows during expose event handling that
28941 overlap other rows. Redrawing of an exposed line writes over parts
28942 of lines overlapping that exposed line; this function fixes that.
28944 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
28945 row in W's current matrix that is exposed and overlaps other rows.
28946 LAST_OVERLAPPING_ROW is the last such row. */
28949 expose_overlaps (struct window
*w
,
28950 struct glyph_row
*first_overlapping_row
,
28951 struct glyph_row
*last_overlapping_row
,
28954 struct glyph_row
*row
;
28956 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
28957 if (row
->overlapping_p
)
28959 eassert (row
->enabled_p
&& !row
->mode_line_p
);
28962 if (row
->used
[LEFT_MARGIN_AREA
])
28963 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
28965 if (row
->used
[TEXT_AREA
])
28966 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
28968 if (row
->used
[RIGHT_MARGIN_AREA
])
28969 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
28975 /* Return non-zero if W's cursor intersects rectangle R. */
28978 phys_cursor_in_rect_p (struct window
*w
, XRectangle
*r
)
28980 XRectangle cr
, result
;
28981 struct glyph
*cursor_glyph
;
28982 struct glyph_row
*row
;
28984 if (w
->phys_cursor
.vpos
>= 0
28985 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
28986 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
28988 && row
->cursor_in_fringe_p
)
28990 /* Cursor is in the fringe. */
28991 cr
.x
= window_box_right_offset (w
,
28992 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
28993 ? RIGHT_MARGIN_AREA
28996 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
28997 cr
.height
= row
->height
;
28998 return x_intersect_rectangles (&cr
, r
, &result
);
29001 cursor_glyph
= get_phys_cursor_glyph (w
);
29004 /* r is relative to W's box, but w->phys_cursor.x is relative
29005 to left edge of W's TEXT area. Adjust it. */
29006 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
29007 cr
.y
= w
->phys_cursor
.y
;
29008 cr
.width
= cursor_glyph
->pixel_width
;
29009 cr
.height
= w
->phys_cursor_height
;
29010 /* ++KFS: W32 version used W32-specific IntersectRect here, but
29011 I assume the effect is the same -- and this is portable. */
29012 return x_intersect_rectangles (&cr
, r
, &result
);
29014 /* If we don't understand the format, pretend we're not in the hot-spot. */
29020 Draw a vertical window border to the right of window W if W doesn't
29021 have vertical scroll bars. */
29024 x_draw_vertical_border (struct window
*w
)
29026 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
29028 /* We could do better, if we knew what type of scroll-bar the adjacent
29029 windows (on either side) have... But we don't :-(
29030 However, I think this works ok. ++KFS 2003-04-25 */
29032 /* Redraw borders between horizontally adjacent windows. Don't
29033 do it for frames with vertical scroll bars because either the
29034 right scroll bar of a window, or the left scroll bar of its
29035 neighbor will suffice as a border. */
29036 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
29039 /* Note: It is necessary to redraw both the left and the right
29040 borders, for when only this single window W is being
29042 if (!WINDOW_RIGHTMOST_P (w
)
29043 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
29045 int x0
, x1
, y0
, y1
;
29047 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
29050 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
29053 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
29055 if (!WINDOW_LEFTMOST_P (w
)
29056 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
29058 int x0
, x1
, y0
, y1
;
29060 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
29063 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
29066 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
29071 /* Redraw the part of window W intersection rectangle FR. Pixel
29072 coordinates in FR are frame-relative. Call this function with
29073 input blocked. Value is non-zero if the exposure overwrites
29077 expose_window (struct window
*w
, XRectangle
*fr
)
29079 struct frame
*f
= XFRAME (w
->frame
);
29081 int mouse_face_overwritten_p
= 0;
29083 /* If window is not yet fully initialized, do nothing. This can
29084 happen when toolkit scroll bars are used and a window is split.
29085 Reconfiguring the scroll bar will generate an expose for a newly
29087 if (w
->current_matrix
== NULL
)
29090 /* When we're currently updating the window, display and current
29091 matrix usually don't agree. Arrange for a thorough display
29093 if (w
->must_be_updated_p
)
29095 SET_FRAME_GARBAGED (f
);
29099 /* Frame-relative pixel rectangle of W. */
29100 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
29101 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
29102 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
29103 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
29105 if (x_intersect_rectangles (fr
, &wr
, &r
))
29107 int yb
= window_text_bottom_y (w
);
29108 struct glyph_row
*row
;
29109 int cursor_cleared_p
, phys_cursor_on_p
;
29110 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
29112 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
29113 r
.x
, r
.y
, r
.width
, r
.height
));
29115 /* Convert to window coordinates. */
29116 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
29117 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
29119 /* Turn off the cursor. */
29120 if (!w
->pseudo_window_p
29121 && phys_cursor_in_rect_p (w
, &r
))
29123 x_clear_cursor (w
);
29124 cursor_cleared_p
= 1;
29127 cursor_cleared_p
= 0;
29129 /* If the row containing the cursor extends face to end of line,
29130 then expose_area might overwrite the cursor outside the
29131 rectangle and thus notice_overwritten_cursor might clear
29132 w->phys_cursor_on_p. We remember the original value and
29133 check later if it is changed. */
29134 phys_cursor_on_p
= w
->phys_cursor_on_p
;
29136 /* Update lines intersecting rectangle R. */
29137 first_overlapping_row
= last_overlapping_row
= NULL
;
29138 for (row
= w
->current_matrix
->rows
;
29143 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
29145 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
29146 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
29147 || (r
.y
>= y0
&& r
.y
< y1
)
29148 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
29150 /* A header line may be overlapping, but there is no need
29151 to fix overlapping areas for them. KFS 2005-02-12 */
29152 if (row
->overlapping_p
&& !row
->mode_line_p
)
29154 if (first_overlapping_row
== NULL
)
29155 first_overlapping_row
= row
;
29156 last_overlapping_row
= row
;
29160 if (expose_line (w
, row
, &r
))
29161 mouse_face_overwritten_p
= 1;
29164 else if (row
->overlapping_p
)
29166 /* We must redraw a row overlapping the exposed area. */
29168 ? y0
+ row
->phys_height
> r
.y
29169 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
29171 if (first_overlapping_row
== NULL
)
29172 first_overlapping_row
= row
;
29173 last_overlapping_row
= row
;
29181 /* Display the mode line if there is one. */
29182 if (WINDOW_WANTS_MODELINE_P (w
)
29183 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
29185 && row
->y
< r
.y
+ r
.height
)
29187 if (expose_line (w
, row
, &r
))
29188 mouse_face_overwritten_p
= 1;
29191 if (!w
->pseudo_window_p
)
29193 /* Fix the display of overlapping rows. */
29194 if (first_overlapping_row
)
29195 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
29198 /* Draw border between windows. */
29199 x_draw_vertical_border (w
);
29201 /* Turn the cursor on again. */
29202 if (cursor_cleared_p
29203 || (phys_cursor_on_p
&& !w
->phys_cursor_on_p
))
29204 update_window_cursor (w
, 1);
29208 return mouse_face_overwritten_p
;
29213 /* Redraw (parts) of all windows in the window tree rooted at W that
29214 intersect R. R contains frame pixel coordinates. Value is
29215 non-zero if the exposure overwrites mouse-face. */
29218 expose_window_tree (struct window
*w
, XRectangle
*r
)
29220 struct frame
*f
= XFRAME (w
->frame
);
29221 int mouse_face_overwritten_p
= 0;
29223 while (w
&& !FRAME_GARBAGED_P (f
))
29225 if (WINDOWP (w
->contents
))
29226 mouse_face_overwritten_p
29227 |= expose_window_tree (XWINDOW (w
->contents
), r
);
29229 mouse_face_overwritten_p
|= expose_window (w
, r
);
29231 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
29234 return mouse_face_overwritten_p
;
29239 Redisplay an exposed area of frame F. X and Y are the upper-left
29240 corner of the exposed rectangle. W and H are width and height of
29241 the exposed area. All are pixel values. W or H zero means redraw
29242 the entire frame. */
29245 expose_frame (struct frame
*f
, int x
, int y
, int w
, int h
)
29248 int mouse_face_overwritten_p
= 0;
29250 TRACE ((stderr
, "expose_frame "));
29252 /* No need to redraw if frame will be redrawn soon. */
29253 if (FRAME_GARBAGED_P (f
))
29255 TRACE ((stderr
, " garbaged\n"));
29259 /* If basic faces haven't been realized yet, there is no point in
29260 trying to redraw anything. This can happen when we get an expose
29261 event while Emacs is starting, e.g. by moving another window. */
29262 if (FRAME_FACE_CACHE (f
) == NULL
29263 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
29265 TRACE ((stderr
, " no faces\n"));
29269 if (w
== 0 || h
== 0)
29272 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
29273 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
29283 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
29284 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
29286 if (WINDOWP (f
->tool_bar_window
))
29287 mouse_face_overwritten_p
29288 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
29290 #ifdef HAVE_X_WINDOWS
29292 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
29293 if (WINDOWP (f
->menu_bar_window
))
29294 mouse_face_overwritten_p
29295 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
29296 #endif /* not USE_X_TOOLKIT and not USE_GTK */
29300 /* Some window managers support a focus-follows-mouse style with
29301 delayed raising of frames. Imagine a partially obscured frame,
29302 and moving the mouse into partially obscured mouse-face on that
29303 frame. The visible part of the mouse-face will be highlighted,
29304 then the WM raises the obscured frame. With at least one WM, KDE
29305 2.1, Emacs is not getting any event for the raising of the frame
29306 (even tried with SubstructureRedirectMask), only Expose events.
29307 These expose events will draw text normally, i.e. not
29308 highlighted. Which means we must redo the highlight here.
29309 Subsume it under ``we love X''. --gerd 2001-08-15 */
29310 /* Included in Windows version because Windows most likely does not
29311 do the right thing if any third party tool offers
29312 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
29313 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
29315 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
29316 if (f
== hlinfo
->mouse_face_mouse_frame
)
29318 int mouse_x
= hlinfo
->mouse_face_mouse_x
;
29319 int mouse_y
= hlinfo
->mouse_face_mouse_y
;
29320 clear_mouse_face (hlinfo
);
29321 note_mouse_highlight (f
, mouse_x
, mouse_y
);
29328 Determine the intersection of two rectangles R1 and R2. Return
29329 the intersection in *RESULT. Value is non-zero if RESULT is not
29333 x_intersect_rectangles (XRectangle
*r1
, XRectangle
*r2
, XRectangle
*result
)
29335 XRectangle
*left
, *right
;
29336 XRectangle
*upper
, *lower
;
29337 int intersection_p
= 0;
29339 /* Rearrange so that R1 is the left-most rectangle. */
29341 left
= r1
, right
= r2
;
29343 left
= r2
, right
= r1
;
29345 /* X0 of the intersection is right.x0, if this is inside R1,
29346 otherwise there is no intersection. */
29347 if (right
->x
<= left
->x
+ left
->width
)
29349 result
->x
= right
->x
;
29351 /* The right end of the intersection is the minimum of
29352 the right ends of left and right. */
29353 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
29356 /* Same game for Y. */
29358 upper
= r1
, lower
= r2
;
29360 upper
= r2
, lower
= r1
;
29362 /* The upper end of the intersection is lower.y0, if this is inside
29363 of upper. Otherwise, there is no intersection. */
29364 if (lower
->y
<= upper
->y
+ upper
->height
)
29366 result
->y
= lower
->y
;
29368 /* The lower end of the intersection is the minimum of the lower
29369 ends of upper and lower. */
29370 result
->height
= (min (lower
->y
+ lower
->height
,
29371 upper
->y
+ upper
->height
)
29373 intersection_p
= 1;
29377 return intersection_p
;
29380 #endif /* HAVE_WINDOW_SYSTEM */
29383 /***********************************************************************
29385 ***********************************************************************/
29388 syms_of_xdisp (void)
29390 Vwith_echo_area_save_vector
= Qnil
;
29391 staticpro (&Vwith_echo_area_save_vector
);
29393 Vmessage_stack
= Qnil
;
29394 staticpro (&Vmessage_stack
);
29396 DEFSYM (Qinhibit_redisplay
, "inhibit-redisplay");
29397 DEFSYM (Qredisplay_internal
, "redisplay_internal (C function)");
29399 message_dolog_marker1
= Fmake_marker ();
29400 staticpro (&message_dolog_marker1
);
29401 message_dolog_marker2
= Fmake_marker ();
29402 staticpro (&message_dolog_marker2
);
29403 message_dolog_marker3
= Fmake_marker ();
29404 staticpro (&message_dolog_marker3
);
29407 defsubr (&Sdump_frame_glyph_matrix
);
29408 defsubr (&Sdump_glyph_matrix
);
29409 defsubr (&Sdump_glyph_row
);
29410 defsubr (&Sdump_tool_bar_row
);
29411 defsubr (&Strace_redisplay
);
29412 defsubr (&Strace_to_stderr
);
29414 #ifdef HAVE_WINDOW_SYSTEM
29415 defsubr (&Stool_bar_lines_needed
);
29416 defsubr (&Slookup_image_map
);
29418 defsubr (&Sline_pixel_height
);
29419 defsubr (&Sformat_mode_line
);
29420 defsubr (&Sinvisible_p
);
29421 defsubr (&Scurrent_bidi_paragraph_direction
);
29422 defsubr (&Smove_point_visually
);
29424 DEFSYM (Qmenu_bar_update_hook
, "menu-bar-update-hook");
29425 DEFSYM (Qoverriding_terminal_local_map
, "overriding-terminal-local-map");
29426 DEFSYM (Qoverriding_local_map
, "overriding-local-map");
29427 DEFSYM (Qwindow_scroll_functions
, "window-scroll-functions");
29428 DEFSYM (Qwindow_text_change_functions
, "window-text-change-functions");
29429 DEFSYM (Qredisplay_end_trigger_functions
, "redisplay-end-trigger-functions");
29430 DEFSYM (Qinhibit_point_motion_hooks
, "inhibit-point-motion-hooks");
29431 DEFSYM (Qeval
, "eval");
29432 DEFSYM (QCdata
, ":data");
29433 DEFSYM (Qdisplay
, "display");
29434 DEFSYM (Qspace_width
, "space-width");
29435 DEFSYM (Qraise
, "raise");
29436 DEFSYM (Qslice
, "slice");
29437 DEFSYM (Qspace
, "space");
29438 DEFSYM (Qmargin
, "margin");
29439 DEFSYM (Qpointer
, "pointer");
29440 DEFSYM (Qleft_margin
, "left-margin");
29441 DEFSYM (Qright_margin
, "right-margin");
29442 DEFSYM (Qcenter
, "center");
29443 DEFSYM (Qline_height
, "line-height");
29444 DEFSYM (QCalign_to
, ":align-to");
29445 DEFSYM (QCrelative_width
, ":relative-width");
29446 DEFSYM (QCrelative_height
, ":relative-height");
29447 DEFSYM (QCeval
, ":eval");
29448 DEFSYM (QCpropertize
, ":propertize");
29449 DEFSYM (QCfile
, ":file");
29450 DEFSYM (Qfontified
, "fontified");
29451 DEFSYM (Qfontification_functions
, "fontification-functions");
29452 DEFSYM (Qtrailing_whitespace
, "trailing-whitespace");
29453 DEFSYM (Qescape_glyph
, "escape-glyph");
29454 DEFSYM (Qnobreak_space
, "nobreak-space");
29455 DEFSYM (Qimage
, "image");
29456 DEFSYM (Qtext
, "text");
29457 DEFSYM (Qboth
, "both");
29458 DEFSYM (Qboth_horiz
, "both-horiz");
29459 DEFSYM (Qtext_image_horiz
, "text-image-horiz");
29460 DEFSYM (QCmap
, ":map");
29461 DEFSYM (QCpointer
, ":pointer");
29462 DEFSYM (Qrect
, "rect");
29463 DEFSYM (Qcircle
, "circle");
29464 DEFSYM (Qpoly
, "poly");
29465 DEFSYM (Qmessage_truncate_lines
, "message-truncate-lines");
29466 DEFSYM (Qgrow_only
, "grow-only");
29467 DEFSYM (Qinhibit_menubar_update
, "inhibit-menubar-update");
29468 DEFSYM (Qinhibit_eval_during_redisplay
, "inhibit-eval-during-redisplay");
29469 DEFSYM (Qposition
, "position");
29470 DEFSYM (Qbuffer_position
, "buffer-position");
29471 DEFSYM (Qobject
, "object");
29472 DEFSYM (Qbar
, "bar");
29473 DEFSYM (Qhbar
, "hbar");
29474 DEFSYM (Qbox
, "box");
29475 DEFSYM (Qhollow
, "hollow");
29476 DEFSYM (Qhand
, "hand");
29477 DEFSYM (Qarrow
, "arrow");
29478 DEFSYM (Qinhibit_free_realized_faces
, "inhibit-free-realized-faces");
29480 list_of_error
= list1 (list2 (intern_c_string ("error"),
29481 intern_c_string ("void-variable")));
29482 staticpro (&list_of_error
);
29484 DEFSYM (Qlast_arrow_position
, "last-arrow-position");
29485 DEFSYM (Qlast_arrow_string
, "last-arrow-string");
29486 DEFSYM (Qoverlay_arrow_string
, "overlay-arrow-string");
29487 DEFSYM (Qoverlay_arrow_bitmap
, "overlay-arrow-bitmap");
29489 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
29490 staticpro (&echo_buffer
[0]);
29491 staticpro (&echo_buffer
[1]);
29493 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
29494 staticpro (&echo_area_buffer
[0]);
29495 staticpro (&echo_area_buffer
[1]);
29497 Vmessages_buffer_name
= build_pure_c_string ("*Messages*");
29498 staticpro (&Vmessages_buffer_name
);
29500 mode_line_proptrans_alist
= Qnil
;
29501 staticpro (&mode_line_proptrans_alist
);
29502 mode_line_string_list
= Qnil
;
29503 staticpro (&mode_line_string_list
);
29504 mode_line_string_face
= Qnil
;
29505 staticpro (&mode_line_string_face
);
29506 mode_line_string_face_prop
= Qnil
;
29507 staticpro (&mode_line_string_face_prop
);
29508 Vmode_line_unwind_vector
= Qnil
;
29509 staticpro (&Vmode_line_unwind_vector
);
29511 DEFSYM (Qmode_line_default_help_echo
, "mode-line-default-help-echo");
29513 help_echo_string
= Qnil
;
29514 staticpro (&help_echo_string
);
29515 help_echo_object
= Qnil
;
29516 staticpro (&help_echo_object
);
29517 help_echo_window
= Qnil
;
29518 staticpro (&help_echo_window
);
29519 previous_help_echo_string
= Qnil
;
29520 staticpro (&previous_help_echo_string
);
29521 help_echo_pos
= -1;
29523 DEFSYM (Qright_to_left
, "right-to-left");
29524 DEFSYM (Qleft_to_right
, "left-to-right");
29526 #ifdef HAVE_WINDOW_SYSTEM
29527 DEFVAR_BOOL ("x-stretch-cursor", x_stretch_cursor_p
,
29528 doc
: /* Non-nil means draw block cursor as wide as the glyph under it.
29529 For example, if a block cursor is over a tab, it will be drawn as
29530 wide as that tab on the display. */);
29531 x_stretch_cursor_p
= 0;
29534 DEFVAR_LISP ("show-trailing-whitespace", Vshow_trailing_whitespace
,
29535 doc
: /* Non-nil means highlight trailing whitespace.
29536 The face used for trailing whitespace is `trailing-whitespace'. */);
29537 Vshow_trailing_whitespace
= Qnil
;
29539 DEFVAR_LISP ("nobreak-char-display", Vnobreak_char_display
,
29540 doc
: /* Control highlighting of non-ASCII space and hyphen chars.
29541 If the value is t, Emacs highlights non-ASCII chars which have the
29542 same appearance as an ASCII space or hyphen, using the `nobreak-space'
29543 or `escape-glyph' face respectively.
29545 U+00A0 (no-break space), U+00AD (soft hyphen), U+2010 (hyphen), and
29546 U+2011 (non-breaking hyphen) are affected.
29548 Any other non-nil value means to display these characters as a escape
29549 glyph followed by an ordinary space or hyphen.
29551 A value of nil means no special handling of these characters. */);
29552 Vnobreak_char_display
= Qt
;
29554 DEFVAR_LISP ("void-text-area-pointer", Vvoid_text_area_pointer
,
29555 doc
: /* The pointer shape to show in void text areas.
29556 A value of nil means to show the text pointer. Other options are `arrow',
29557 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
29558 Vvoid_text_area_pointer
= Qarrow
;
29560 DEFVAR_LISP ("inhibit-redisplay", Vinhibit_redisplay
,
29561 doc
: /* Non-nil means don't actually do any redisplay.
29562 This is used for internal purposes. */);
29563 Vinhibit_redisplay
= Qnil
;
29565 DEFVAR_LISP ("global-mode-string", Vglobal_mode_string
,
29566 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
29567 Vglobal_mode_string
= Qnil
;
29569 DEFVAR_LISP ("overlay-arrow-position", Voverlay_arrow_position
,
29570 doc
: /* Marker for where to display an arrow on top of the buffer text.
29571 This must be the beginning of a line in order to work.
29572 See also `overlay-arrow-string'. */);
29573 Voverlay_arrow_position
= Qnil
;
29575 DEFVAR_LISP ("overlay-arrow-string", Voverlay_arrow_string
,
29576 doc
: /* String to display as an arrow in non-window frames.
29577 See also `overlay-arrow-position'. */);
29578 Voverlay_arrow_string
= build_pure_c_string ("=>");
29580 DEFVAR_LISP ("overlay-arrow-variable-list", Voverlay_arrow_variable_list
,
29581 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
29582 The symbols on this list are examined during redisplay to determine
29583 where to display overlay arrows. */);
29584 Voverlay_arrow_variable_list
29585 = list1 (intern_c_string ("overlay-arrow-position"));
29587 DEFVAR_INT ("scroll-step", emacs_scroll_step
,
29588 doc
: /* The number of lines to try scrolling a window by when point moves out.
29589 If that fails to bring point back on frame, point is centered instead.
29590 If this is zero, point is always centered after it moves off frame.
29591 If you want scrolling to always be a line at a time, you should set
29592 `scroll-conservatively' to a large value rather than set this to 1. */);
29594 DEFVAR_INT ("scroll-conservatively", scroll_conservatively
,
29595 doc
: /* Scroll up to this many lines, to bring point back on screen.
29596 If point moves off-screen, redisplay will scroll by up to
29597 `scroll-conservatively' lines in order to bring point just barely
29598 onto the screen again. If that cannot be done, then redisplay
29599 recenters point as usual.
29601 If the value is greater than 100, redisplay will never recenter point,
29602 but will always scroll just enough text to bring point into view, even
29603 if you move far away.
29605 A value of zero means always recenter point if it moves off screen. */);
29606 scroll_conservatively
= 0;
29608 DEFVAR_INT ("scroll-margin", scroll_margin
,
29609 doc
: /* Number of lines of margin at the top and bottom of a window.
29610 Recenter the window whenever point gets within this many lines
29611 of the top or bottom of the window. */);
29614 DEFVAR_LISP ("display-pixels-per-inch", Vdisplay_pixels_per_inch
,
29615 doc
: /* Pixels per inch value for non-window system displays.
29616 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
29617 Vdisplay_pixels_per_inch
= make_float (72.0);
29620 DEFVAR_INT ("debug-end-pos", debug_end_pos
, doc
: /* Don't ask. */);
29623 DEFVAR_LISP ("truncate-partial-width-windows",
29624 Vtruncate_partial_width_windows
,
29625 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
29626 For an integer value, truncate lines in each window narrower than the
29627 full frame width, provided the window width is less than that integer;
29628 otherwise, respect the value of `truncate-lines'.
29630 For any other non-nil value, truncate lines in all windows that do
29631 not span the full frame width.
29633 A value of nil means to respect the value of `truncate-lines'.
29635 If `word-wrap' is enabled, you might want to reduce this. */);
29636 Vtruncate_partial_width_windows
= make_number (50);
29638 DEFVAR_LISP ("line-number-display-limit", Vline_number_display_limit
,
29639 doc
: /* Maximum buffer size for which line number should be displayed.
29640 If the buffer is bigger than this, the line number does not appear
29641 in the mode line. A value of nil means no limit. */);
29642 Vline_number_display_limit
= Qnil
;
29644 DEFVAR_INT ("line-number-display-limit-width",
29645 line_number_display_limit_width
,
29646 doc
: /* Maximum line width (in characters) for line number display.
29647 If the average length of the lines near point is bigger than this, then the
29648 line number may be omitted from the mode line. */);
29649 line_number_display_limit_width
= 200;
29651 DEFVAR_BOOL ("highlight-nonselected-windows", highlight_nonselected_windows
,
29652 doc
: /* Non-nil means highlight region even in nonselected windows. */);
29653 highlight_nonselected_windows
= 0;
29655 DEFVAR_BOOL ("multiple-frames", multiple_frames
,
29656 doc
: /* Non-nil if more than one frame is visible on this display.
29657 Minibuffer-only frames don't count, but iconified frames do.
29658 This variable is not guaranteed to be accurate except while processing
29659 `frame-title-format' and `icon-title-format'. */);
29661 DEFVAR_LISP ("frame-title-format", Vframe_title_format
,
29662 doc
: /* Template for displaying the title bar of visible frames.
29663 \(Assuming the window manager supports this feature.)
29665 This variable has the same structure as `mode-line-format', except that
29666 the %c and %l constructs are ignored. It is used only on frames for
29667 which no explicit name has been set \(see `modify-frame-parameters'). */);
29669 DEFVAR_LISP ("icon-title-format", Vicon_title_format
,
29670 doc
: /* Template for displaying the title bar of an iconified frame.
29671 \(Assuming the window manager supports this feature.)
29672 This variable has the same structure as `mode-line-format' (which see),
29673 and is used only on frames for which no explicit name has been set
29674 \(see `modify-frame-parameters'). */);
29676 = Vframe_title_format
29677 = listn (CONSTYPE_PURE
, 3,
29678 intern_c_string ("multiple-frames"),
29679 build_pure_c_string ("%b"),
29680 listn (CONSTYPE_PURE
, 4,
29681 empty_unibyte_string
,
29682 intern_c_string ("invocation-name"),
29683 build_pure_c_string ("@"),
29684 intern_c_string ("system-name")));
29686 DEFVAR_LISP ("message-log-max", Vmessage_log_max
,
29687 doc
: /* Maximum number of lines to keep in the message log buffer.
29688 If nil, disable message logging. If t, log messages but don't truncate
29689 the buffer when it becomes large. */);
29690 Vmessage_log_max
= make_number (1000);
29692 DEFVAR_LISP ("window-size-change-functions", Vwindow_size_change_functions
,
29693 doc
: /* Functions called before redisplay, if window sizes have changed.
29694 The value should be a list of functions that take one argument.
29695 Just before redisplay, for each frame, if any of its windows have changed
29696 size since the last redisplay, or have been split or deleted,
29697 all the functions in the list are called, with the frame as argument. */);
29698 Vwindow_size_change_functions
= Qnil
;
29700 DEFVAR_LISP ("window-scroll-functions", Vwindow_scroll_functions
,
29701 doc
: /* List of functions to call before redisplaying a window with scrolling.
29702 Each function is called with two arguments, the window and its new
29703 display-start position. Note that these functions are also called by
29704 `set-window-buffer'. Also note that the value of `window-end' is not
29705 valid when these functions are called.
29707 Warning: Do not use this feature to alter the way the window
29708 is scrolled. It is not designed for that, and such use probably won't
29710 Vwindow_scroll_functions
= Qnil
;
29712 DEFVAR_LISP ("window-text-change-functions",
29713 Vwindow_text_change_functions
,
29714 doc
: /* Functions to call in redisplay when text in the window might change. */);
29715 Vwindow_text_change_functions
= Qnil
;
29717 DEFVAR_LISP ("redisplay-end-trigger-functions", Vredisplay_end_trigger_functions
,
29718 doc
: /* Functions called when redisplay of a window reaches the end trigger.
29719 Each function is called with two arguments, the window and the end trigger value.
29720 See `set-window-redisplay-end-trigger'. */);
29721 Vredisplay_end_trigger_functions
= Qnil
;
29723 DEFVAR_LISP ("mouse-autoselect-window", Vmouse_autoselect_window
,
29724 doc
: /* Non-nil means autoselect window with mouse pointer.
29725 If nil, do not autoselect windows.
29726 A positive number means delay autoselection by that many seconds: a
29727 window is autoselected only after the mouse has remained in that
29728 window for the duration of the delay.
29729 A negative number has a similar effect, but causes windows to be
29730 autoselected only after the mouse has stopped moving. \(Because of
29731 the way Emacs compares mouse events, you will occasionally wait twice
29732 that time before the window gets selected.\)
29733 Any other value means to autoselect window instantaneously when the
29734 mouse pointer enters it.
29736 Autoselection selects the minibuffer only if it is active, and never
29737 unselects the minibuffer if it is active.
29739 When customizing this variable make sure that the actual value of
29740 `focus-follows-mouse' matches the behavior of your window manager. */);
29741 Vmouse_autoselect_window
= Qnil
;
29743 DEFVAR_LISP ("auto-resize-tool-bars", Vauto_resize_tool_bars
,
29744 doc
: /* Non-nil means automatically resize tool-bars.
29745 This dynamically changes the tool-bar's height to the minimum height
29746 that is needed to make all tool-bar items visible.
29747 If value is `grow-only', the tool-bar's height is only increased
29748 automatically; to decrease the tool-bar height, use \\[recenter]. */);
29749 Vauto_resize_tool_bars
= Qt
;
29751 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", auto_raise_tool_bar_buttons_p
,
29752 doc
: /* Non-nil means raise tool-bar buttons when the mouse moves over them. */);
29753 auto_raise_tool_bar_buttons_p
= 1;
29755 DEFVAR_BOOL ("make-cursor-line-fully-visible", make_cursor_line_fully_visible_p
,
29756 doc
: /* Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
29757 make_cursor_line_fully_visible_p
= 1;
29759 DEFVAR_LISP ("tool-bar-border", Vtool_bar_border
,
29760 doc
: /* Border below tool-bar in pixels.
29761 If an integer, use it as the height of the border.
29762 If it is one of `internal-border-width' or `border-width', use the
29763 value of the corresponding frame parameter.
29764 Otherwise, no border is added below the tool-bar. */);
29765 Vtool_bar_border
= Qinternal_border_width
;
29767 DEFVAR_LISP ("tool-bar-button-margin", Vtool_bar_button_margin
,
29768 doc
: /* Margin around tool-bar buttons in pixels.
29769 If an integer, use that for both horizontal and vertical margins.
29770 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
29771 HORZ specifying the horizontal margin, and VERT specifying the
29772 vertical margin. */);
29773 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
29775 DEFVAR_INT ("tool-bar-button-relief", tool_bar_button_relief
,
29776 doc
: /* Relief thickness of tool-bar buttons. */);
29777 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
29779 DEFVAR_LISP ("tool-bar-style", Vtool_bar_style
,
29780 doc
: /* Tool bar style to use.
29782 image - show images only
29783 text - show text only
29784 both - show both, text below image
29785 both-horiz - show text to the right of the image
29786 text-image-horiz - show text to the left of the image
29787 any other - use system default or image if no system default.
29789 This variable only affects the GTK+ toolkit version of Emacs. */);
29790 Vtool_bar_style
= Qnil
;
29792 DEFVAR_INT ("tool-bar-max-label-size", tool_bar_max_label_size
,
29793 doc
: /* Maximum number of characters a label can have to be shown.
29794 The tool bar style must also show labels for this to have any effect, see
29795 `tool-bar-style'. */);
29796 tool_bar_max_label_size
= DEFAULT_TOOL_BAR_LABEL_SIZE
;
29798 DEFVAR_LISP ("fontification-functions", Vfontification_functions
,
29799 doc
: /* List of functions to call to fontify regions of text.
29800 Each function is called with one argument POS. Functions must
29801 fontify a region starting at POS in the current buffer, and give
29802 fontified regions the property `fontified'. */);
29803 Vfontification_functions
= Qnil
;
29804 Fmake_variable_buffer_local (Qfontification_functions
);
29806 DEFVAR_BOOL ("unibyte-display-via-language-environment",
29807 unibyte_display_via_language_environment
,
29808 doc
: /* Non-nil means display unibyte text according to language environment.
29809 Specifically, this means that raw bytes in the range 160-255 decimal
29810 are displayed by converting them to the equivalent multibyte characters
29811 according to the current language environment. As a result, they are
29812 displayed according to the current fontset.
29814 Note that this variable affects only how these bytes are displayed,
29815 but does not change the fact they are interpreted as raw bytes. */);
29816 unibyte_display_via_language_environment
= 0;
29818 DEFVAR_LISP ("max-mini-window-height", Vmax_mini_window_height
,
29819 doc
: /* Maximum height for resizing mini-windows (the minibuffer and the echo area).
29820 If a float, it specifies a fraction of the mini-window frame's height.
29821 If an integer, it specifies a number of lines. */);
29822 Vmax_mini_window_height
= make_float (0.25);
29824 DEFVAR_LISP ("resize-mini-windows", Vresize_mini_windows
,
29825 doc
: /* How to resize mini-windows (the minibuffer and the echo area).
29826 A value of nil means don't automatically resize mini-windows.
29827 A value of t means resize them to fit the text displayed in them.
29828 A value of `grow-only', the default, means let mini-windows grow only;
29829 they return to their normal size when the minibuffer is closed, or the
29830 echo area becomes empty. */);
29831 Vresize_mini_windows
= Qgrow_only
;
29833 DEFVAR_LISP ("blink-cursor-alist", Vblink_cursor_alist
,
29834 doc
: /* Alist specifying how to blink the cursor off.
29835 Each element has the form (ON-STATE . OFF-STATE). Whenever the
29836 `cursor-type' frame-parameter or variable equals ON-STATE,
29837 comparing using `equal', Emacs uses OFF-STATE to specify
29838 how to blink it off. ON-STATE and OFF-STATE are values for
29839 the `cursor-type' frame parameter.
29841 If a frame's ON-STATE has no entry in this list,
29842 the frame's other specifications determine how to blink the cursor off. */);
29843 Vblink_cursor_alist
= Qnil
;
29845 DEFVAR_BOOL ("auto-hscroll-mode", automatic_hscrolling_p
,
29846 doc
: /* Allow or disallow automatic horizontal scrolling of windows.
29847 If non-nil, windows are automatically scrolled horizontally to make
29848 point visible. */);
29849 automatic_hscrolling_p
= 1;
29850 DEFSYM (Qauto_hscroll_mode
, "auto-hscroll-mode");
29852 DEFVAR_INT ("hscroll-margin", hscroll_margin
,
29853 doc
: /* How many columns away from the window edge point is allowed to get
29854 before automatic hscrolling will horizontally scroll the window. */);
29855 hscroll_margin
= 5;
29857 DEFVAR_LISP ("hscroll-step", Vhscroll_step
,
29858 doc
: /* How many columns to scroll the window when point gets too close to the edge.
29859 When point is less than `hscroll-margin' columns from the window
29860 edge, automatic hscrolling will scroll the window by the amount of columns
29861 determined by this variable. If its value is a positive integer, scroll that
29862 many columns. If it's a positive floating-point number, it specifies the
29863 fraction of the window's width to scroll. If it's nil or zero, point will be
29864 centered horizontally after the scroll. Any other value, including negative
29865 numbers, are treated as if the value were zero.
29867 Automatic hscrolling always moves point outside the scroll margin, so if
29868 point was more than scroll step columns inside the margin, the window will
29869 scroll more than the value given by the scroll step.
29871 Note that the lower bound for automatic hscrolling specified by `scroll-left'
29872 and `scroll-right' overrides this variable's effect. */);
29873 Vhscroll_step
= make_number (0);
29875 DEFVAR_BOOL ("message-truncate-lines", message_truncate_lines
,
29876 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
29877 Bind this around calls to `message' to let it take effect. */);
29878 message_truncate_lines
= 0;
29880 DEFVAR_LISP ("menu-bar-update-hook", Vmenu_bar_update_hook
,
29881 doc
: /* Normal hook run to update the menu bar definitions.
29882 Redisplay runs this hook before it redisplays the menu bar.
29883 This is used to update submenus such as Buffers,
29884 whose contents depend on various data. */);
29885 Vmenu_bar_update_hook
= Qnil
;
29887 DEFVAR_LISP ("menu-updating-frame", Vmenu_updating_frame
,
29888 doc
: /* Frame for which we are updating a menu.
29889 The enable predicate for a menu binding should check this variable. */);
29890 Vmenu_updating_frame
= Qnil
;
29892 DEFVAR_BOOL ("inhibit-menubar-update", inhibit_menubar_update
,
29893 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
29894 inhibit_menubar_update
= 0;
29896 DEFVAR_LISP ("wrap-prefix", Vwrap_prefix
,
29897 doc
: /* Prefix prepended to all continuation lines at display time.
29898 The value may be a string, an image, or a stretch-glyph; it is
29899 interpreted in the same way as the value of a `display' text property.
29901 This variable is overridden by any `wrap-prefix' text or overlay
29904 To add a prefix to non-continuation lines, use `line-prefix'. */);
29905 Vwrap_prefix
= Qnil
;
29906 DEFSYM (Qwrap_prefix
, "wrap-prefix");
29907 Fmake_variable_buffer_local (Qwrap_prefix
);
29909 DEFVAR_LISP ("line-prefix", Vline_prefix
,
29910 doc
: /* Prefix prepended to all non-continuation lines at display time.
29911 The value may be a string, an image, or a stretch-glyph; it is
29912 interpreted in the same way as the value of a `display' text property.
29914 This variable is overridden by any `line-prefix' text or overlay
29917 To add a prefix to continuation lines, use `wrap-prefix'. */);
29918 Vline_prefix
= Qnil
;
29919 DEFSYM (Qline_prefix
, "line-prefix");
29920 Fmake_variable_buffer_local (Qline_prefix
);
29922 DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay
,
29923 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
29924 inhibit_eval_during_redisplay
= 0;
29926 DEFVAR_BOOL ("inhibit-free-realized-faces", inhibit_free_realized_faces
,
29927 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
29928 inhibit_free_realized_faces
= 0;
29931 DEFVAR_BOOL ("inhibit-try-window-id", inhibit_try_window_id
,
29932 doc
: /* Inhibit try_window_id display optimization. */);
29933 inhibit_try_window_id
= 0;
29935 DEFVAR_BOOL ("inhibit-try-window-reusing", inhibit_try_window_reusing
,
29936 doc
: /* Inhibit try_window_reusing display optimization. */);
29937 inhibit_try_window_reusing
= 0;
29939 DEFVAR_BOOL ("inhibit-try-cursor-movement", inhibit_try_cursor_movement
,
29940 doc
: /* Inhibit try_cursor_movement display optimization. */);
29941 inhibit_try_cursor_movement
= 0;
29942 #endif /* GLYPH_DEBUG */
29944 DEFVAR_INT ("overline-margin", overline_margin
,
29945 doc
: /* Space between overline and text, in pixels.
29946 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
29947 margin to the character height. */);
29948 overline_margin
= 2;
29950 DEFVAR_INT ("underline-minimum-offset",
29951 underline_minimum_offset
,
29952 doc
: /* Minimum distance between baseline and underline.
29953 This can improve legibility of underlined text at small font sizes,
29954 particularly when using variable `x-use-underline-position-properties'
29955 with fonts that specify an UNDERLINE_POSITION relatively close to the
29956 baseline. The default value is 1. */);
29957 underline_minimum_offset
= 1;
29959 DEFVAR_BOOL ("display-hourglass", display_hourglass_p
,
29960 doc
: /* Non-nil means show an hourglass pointer, when Emacs is busy.
29961 This feature only works when on a window system that can change
29962 cursor shapes. */);
29963 display_hourglass_p
= 1;
29965 DEFVAR_LISP ("hourglass-delay", Vhourglass_delay
,
29966 doc
: /* Seconds to wait before displaying an hourglass pointer when Emacs is busy. */);
29967 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
29969 hourglass_atimer
= NULL
;
29970 hourglass_shown_p
= 0;
29972 DEFSYM (Qglyphless_char
, "glyphless-char");
29973 DEFSYM (Qhex_code
, "hex-code");
29974 DEFSYM (Qempty_box
, "empty-box");
29975 DEFSYM (Qthin_space
, "thin-space");
29976 DEFSYM (Qzero_width
, "zero-width");
29978 DEFSYM (Qglyphless_char_display
, "glyphless-char-display");
29979 Fput (Qglyphless_char_display
, Qchar_table_extra_slots
, make_number (1));
29981 DEFVAR_LISP ("glyphless-char-display", Vglyphless_char_display
,
29982 doc
: /* Char-table defining glyphless characters.
29983 Each element, if non-nil, should be one of the following:
29984 an ASCII acronym string: display this string in a box
29985 `hex-code': display the hexadecimal code of a character in a box
29986 `empty-box': display as an empty box
29987 `thin-space': display as 1-pixel width space
29988 `zero-width': don't display
29989 An element may also be a cons cell (GRAPHICAL . TEXT), which specifies the
29990 display method for graphical terminals and text terminals respectively.
29991 GRAPHICAL and TEXT should each have one of the values listed above.
29993 The char-table has one extra slot to control the display of a character for
29994 which no font is found. This slot only takes effect on graphical terminals.
29995 Its value should be an ASCII acronym string, `hex-code', `empty-box', or
29996 `thin-space'. The default is `empty-box'. */);
29997 Vglyphless_char_display
= Fmake_char_table (Qglyphless_char_display
, Qnil
);
29998 Fset_char_table_extra_slot (Vglyphless_char_display
, make_number (0),
30001 DEFVAR_LISP ("debug-on-message", Vdebug_on_message
,
30002 doc
: /* If non-nil, debug if a message matching this regexp is displayed. */);
30003 Vdebug_on_message
= Qnil
;
30007 /* Initialize this module when Emacs starts. */
30012 current_header_line_height
= current_mode_line_height
= -1;
30014 CHARPOS (this_line_start_pos
) = 0;
30016 if (!noninteractive
)
30018 struct window
*m
= XWINDOW (minibuf_window
);
30019 Lisp_Object frame
= m
->frame
;
30020 struct frame
*f
= XFRAME (frame
);
30021 Lisp_Object root
= FRAME_ROOT_WINDOW (f
);
30022 struct window
*r
= XWINDOW (root
);
30025 echo_area_window
= minibuf_window
;
30027 r
->top_line
= FRAME_TOP_MARGIN (f
);
30028 r
->total_lines
= FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
);
30029 r
->total_cols
= FRAME_COLS (f
);
30031 m
->top_line
= FRAME_LINES (f
) - 1;
30032 m
->total_lines
= 1;
30033 m
->total_cols
= FRAME_COLS (f
);
30035 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
30036 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
30037 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
30039 /* The default ellipsis glyphs `...'. */
30040 for (i
= 0; i
< 3; ++i
)
30041 default_invis_vector
[i
] = make_number ('.');
30045 /* Allocate the buffer for frame titles.
30046 Also used for `format-mode-line'. */
30048 mode_line_noprop_buf
= xmalloc (size
);
30049 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
30050 mode_line_noprop_ptr
= mode_line_noprop_buf
;
30051 mode_line_target
= MODE_LINE_DISPLAY
;
30054 help_echo_showing_p
= 0;
30057 /* Platform-independent portion of hourglass implementation. */
30059 /* Cancel a currently active hourglass timer, and start a new one. */
30061 start_hourglass (void)
30063 #if defined (HAVE_WINDOW_SYSTEM)
30066 cancel_hourglass ();
30068 if (INTEGERP (Vhourglass_delay
)
30069 && XINT (Vhourglass_delay
) > 0)
30070 delay
= make_emacs_time (min (XINT (Vhourglass_delay
),
30071 TYPE_MAXIMUM (time_t)),
30073 else if (FLOATP (Vhourglass_delay
)
30074 && XFLOAT_DATA (Vhourglass_delay
) > 0)
30075 delay
= EMACS_TIME_FROM_DOUBLE (XFLOAT_DATA (Vhourglass_delay
));
30077 delay
= make_emacs_time (DEFAULT_HOURGLASS_DELAY
, 0);
30081 extern void w32_note_current_window (void);
30082 w32_note_current_window ();
30084 #endif /* HAVE_NTGUI */
30086 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
30087 show_hourglass
, NULL
);
30092 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
30095 cancel_hourglass (void)
30097 #if defined (HAVE_WINDOW_SYSTEM)
30098 if (hourglass_atimer
)
30100 cancel_atimer (hourglass_atimer
);
30101 hourglass_atimer
= NULL
;
30104 if (hourglass_shown_p
)