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
3924 base_face_id
= it
->string_from_prefix_prop_p
3926 : underlying_face_id (it
);
3929 new_face_id
= face_at_string_position (it
->w
,
3931 IT_STRING_CHARPOS (*it
),
3933 it
->region_beg_charpos
,
3934 it
->region_end_charpos
,
3938 /* Is this a start of a run of characters with box? Caveat:
3939 this can be called for a freshly allocated iterator; face_id
3940 is -1 is this case. We know that the new face will not
3941 change until the next check pos, i.e. if the new face has a
3942 box, all characters up to that position will have a
3943 box. But, as usual, we don't know whether that position
3944 is really the end. */
3945 if (new_face_id
!= it
->face_id
)
3947 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3948 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3950 /* If new face has a box but old face hasn't, this is the
3951 start of a run of characters with box, i.e. it has a
3952 shadow on the left side. */
3953 it
->start_of_box_run_p
3954 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3955 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3959 it
->face_id
= new_face_id
;
3960 return HANDLED_NORMALLY
;
3964 /* Return the ID of the face ``underlying'' IT's current position,
3965 which is in a string. If the iterator is associated with a
3966 buffer, return the face at IT's current buffer position.
3967 Otherwise, use the iterator's base_face_id. */
3970 underlying_face_id (struct it
*it
)
3972 int face_id
= it
->base_face_id
, i
;
3974 eassert (STRINGP (it
->string
));
3976 for (i
= it
->sp
- 1; i
>= 0; --i
)
3977 if (NILP (it
->stack
[i
].string
))
3978 face_id
= it
->stack
[i
].face_id
;
3984 /* Compute the face one character before or after the current position
3985 of IT, in the visual order. BEFORE_P non-zero means get the face
3986 in front (to the left in L2R paragraphs, to the right in R2L
3987 paragraphs) of IT's screen position. Value is the ID of the face. */
3990 face_before_or_after_it_pos (struct it
*it
, int before_p
)
3993 ptrdiff_t next_check_charpos
;
3995 void *it_copy_data
= NULL
;
3997 eassert (it
->s
== NULL
);
3999 if (STRINGP (it
->string
))
4001 ptrdiff_t bufpos
, charpos
;
4004 /* No face change past the end of the string (for the case
4005 we are padding with spaces). No face change before the
4007 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
4008 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
4013 /* Set charpos to the position before or after IT's current
4014 position, in the logical order, which in the non-bidi
4015 case is the same as the visual order. */
4017 charpos
= IT_STRING_CHARPOS (*it
) - 1;
4018 else if (it
->what
== IT_COMPOSITION
)
4019 /* For composition, we must check the character after the
4021 charpos
= IT_STRING_CHARPOS (*it
) + it
->cmp_it
.nchars
;
4023 charpos
= IT_STRING_CHARPOS (*it
) + 1;
4029 /* With bidi iteration, the character before the current
4030 in the visual order cannot be found by simple
4031 iteration, because "reverse" reordering is not
4032 supported. Instead, we need to use the move_it_*
4033 family of functions. */
4034 /* Ignore face changes before the first visible
4035 character on this display line. */
4036 if (it
->current_x
<= it
->first_visible_x
)
4038 SAVE_IT (it_copy
, *it
, it_copy_data
);
4039 /* Implementation note: Since move_it_in_display_line
4040 works in the iterator geometry, and thinks the first
4041 character is always the leftmost, even in R2L lines,
4042 we don't need to distinguish between the R2L and L2R
4044 move_it_in_display_line (&it_copy
, SCHARS (it_copy
.string
),
4045 it_copy
.current_x
- 1, MOVE_TO_X
);
4046 charpos
= IT_STRING_CHARPOS (it_copy
);
4047 RESTORE_IT (it
, it
, it_copy_data
);
4051 /* Set charpos to the string position of the character
4052 that comes after IT's current position in the visual
4054 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
4058 bidi_move_to_visually_next (&it_copy
.bidi_it
);
4060 charpos
= it_copy
.bidi_it
.charpos
;
4063 eassert (0 <= charpos
&& charpos
<= SCHARS (it
->string
));
4065 if (it
->current
.overlay_string_index
>= 0)
4066 bufpos
= IT_CHARPOS (*it
);
4070 base_face_id
= underlying_face_id (it
);
4072 /* Get the face for ASCII, or unibyte. */
4073 face_id
= face_at_string_position (it
->w
,
4077 it
->region_beg_charpos
,
4078 it
->region_end_charpos
,
4079 &next_check_charpos
,
4082 /* Correct the face for charsets different from ASCII. Do it
4083 for the multibyte case only. The face returned above is
4084 suitable for unibyte text if IT->string is unibyte. */
4085 if (STRING_MULTIBYTE (it
->string
))
4087 struct text_pos pos1
= string_pos (charpos
, it
->string
);
4088 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos1
);
4090 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
4092 c
= string_char_and_length (p
, &len
);
4093 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, charpos
, it
->string
);
4098 struct text_pos pos
;
4100 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
4101 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
4104 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
4105 pos
= it
->current
.pos
;
4110 DEC_TEXT_POS (pos
, it
->multibyte_p
);
4113 if (it
->what
== IT_COMPOSITION
)
4115 /* For composition, we must check the position after
4117 pos
.charpos
+= it
->cmp_it
.nchars
;
4118 pos
.bytepos
+= it
->len
;
4121 INC_TEXT_POS (pos
, it
->multibyte_p
);
4128 /* With bidi iteration, the character before the current
4129 in the visual order cannot be found by simple
4130 iteration, because "reverse" reordering is not
4131 supported. Instead, we need to use the move_it_*
4132 family of functions. */
4133 /* Ignore face changes before the first visible
4134 character on this display line. */
4135 if (it
->current_x
<= it
->first_visible_x
)
4137 SAVE_IT (it_copy
, *it
, it_copy_data
);
4138 /* Implementation note: Since move_it_in_display_line
4139 works in the iterator geometry, and thinks the first
4140 character is always the leftmost, even in R2L lines,
4141 we don't need to distinguish between the R2L and L2R
4143 move_it_in_display_line (&it_copy
, ZV
,
4144 it_copy
.current_x
- 1, MOVE_TO_X
);
4145 pos
= it_copy
.current
.pos
;
4146 RESTORE_IT (it
, it
, it_copy_data
);
4150 /* Set charpos to the buffer position of the character
4151 that comes after IT's current position in the visual
4153 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
4157 bidi_move_to_visually_next (&it_copy
.bidi_it
);
4160 it_copy
.bidi_it
.charpos
, it_copy
.bidi_it
.bytepos
);
4163 eassert (BEGV
<= CHARPOS (pos
) && CHARPOS (pos
) <= ZV
);
4165 /* Determine face for CHARSET_ASCII, or unibyte. */
4166 face_id
= face_at_buffer_position (it
->w
,
4168 it
->region_beg_charpos
,
4169 it
->region_end_charpos
,
4170 &next_check_charpos
,
4173 /* Correct the face for charsets different from ASCII. Do it
4174 for the multibyte case only. The face returned above is
4175 suitable for unibyte text if current_buffer is unibyte. */
4176 if (it
->multibyte_p
)
4178 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
4179 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
4180 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
4189 /***********************************************************************
4191 ***********************************************************************/
4193 /* Set up iterator IT from invisible properties at its current
4194 position. Called from handle_stop. */
4196 static enum prop_handled
4197 handle_invisible_prop (struct it
*it
)
4199 enum prop_handled handled
= HANDLED_NORMALLY
;
4203 if (STRINGP (it
->string
))
4205 Lisp_Object end_charpos
, limit
, charpos
;
4207 /* Get the value of the invisible text property at the
4208 current position. Value will be nil if there is no such
4210 charpos
= make_number (IT_STRING_CHARPOS (*it
));
4211 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
4212 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4214 if (invis_p
&& IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
4216 /* Record whether we have to display an ellipsis for the
4218 int display_ellipsis_p
= (invis_p
== 2);
4219 ptrdiff_t len
, endpos
;
4221 handled
= HANDLED_RECOMPUTE_PROPS
;
4223 /* Get the position at which the next visible text can be
4224 found in IT->string, if any. */
4225 endpos
= len
= SCHARS (it
->string
);
4226 XSETINT (limit
, len
);
4229 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
4231 if (INTEGERP (end_charpos
))
4233 endpos
= XFASTINT (end_charpos
);
4234 prop
= Fget_text_property (end_charpos
, Qinvisible
, it
->string
);
4235 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4237 display_ellipsis_p
= 1;
4240 while (invis_p
&& endpos
< len
);
4242 if (display_ellipsis_p
)
4247 /* Text at END_CHARPOS is visible. Move IT there. */
4248 struct text_pos old
;
4251 old
= it
->current
.string_pos
;
4252 oldpos
= CHARPOS (old
);
4255 if (it
->bidi_it
.first_elt
4256 && it
->bidi_it
.charpos
< SCHARS (it
->string
))
4257 bidi_paragraph_init (it
->paragraph_embedding
,
4259 /* Bidi-iterate out of the invisible text. */
4262 bidi_move_to_visually_next (&it
->bidi_it
);
4264 while (oldpos
<= it
->bidi_it
.charpos
4265 && it
->bidi_it
.charpos
< endpos
);
4267 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4268 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4269 if (IT_CHARPOS (*it
) >= endpos
)
4270 it
->prev_stop
= endpos
;
4274 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
4275 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
4280 /* The rest of the string is invisible. If this is an
4281 overlay string, proceed with the next overlay string
4282 or whatever comes and return a character from there. */
4283 if (it
->current
.overlay_string_index
>= 0
4284 && !display_ellipsis_p
)
4286 next_overlay_string (it
);
4287 /* Don't check for overlay strings when we just
4288 finished processing them. */
4289 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
4293 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
4294 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
4301 ptrdiff_t newpos
, next_stop
, start_charpos
, tem
;
4302 Lisp_Object pos
, overlay
;
4304 /* First of all, is there invisible text at this position? */
4305 tem
= start_charpos
= IT_CHARPOS (*it
);
4306 pos
= make_number (tem
);
4307 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
4309 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4311 /* If we are on invisible text, skip over it. */
4312 if (invis_p
&& start_charpos
< it
->end_charpos
)
4314 /* Record whether we have to display an ellipsis for the
4316 int display_ellipsis_p
= invis_p
== 2;
4318 handled
= HANDLED_RECOMPUTE_PROPS
;
4320 /* Loop skipping over invisible text. The loop is left at
4321 ZV or with IT on the first char being visible again. */
4324 /* Try to skip some invisible text. Return value is the
4325 position reached which can be equal to where we start
4326 if there is nothing invisible there. This skips both
4327 over invisible text properties and overlays with
4328 invisible property. */
4329 newpos
= skip_invisible (tem
, &next_stop
, ZV
, it
->window
);
4331 /* If we skipped nothing at all we weren't at invisible
4332 text in the first place. If everything to the end of
4333 the buffer was skipped, end the loop. */
4334 if (newpos
== tem
|| newpos
>= ZV
)
4338 /* We skipped some characters but not necessarily
4339 all there are. Check if we ended up on visible
4340 text. Fget_char_property returns the property of
4341 the char before the given position, i.e. if we
4342 get invis_p = 0, this means that the char at
4343 newpos is visible. */
4344 pos
= make_number (newpos
);
4345 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
4346 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4349 /* If we ended up on invisible text, proceed to
4350 skip starting with next_stop. */
4354 /* If there are adjacent invisible texts, don't lose the
4355 second one's ellipsis. */
4357 display_ellipsis_p
= 1;
4361 /* The position newpos is now either ZV or on visible text. */
4364 ptrdiff_t bpos
= CHAR_TO_BYTE (newpos
);
4366 bpos
== ZV_BYTE
|| FETCH_BYTE (bpos
) == '\n';
4368 newpos
<= BEGV
|| FETCH_BYTE (bpos
- 1) == '\n';
4370 /* If the invisible text ends on a newline or on a
4371 character after a newline, we can avoid the costly,
4372 character by character, bidi iteration to NEWPOS, and
4373 instead simply reseat the iterator there. That's
4374 because all bidi reordering information is tossed at
4375 the newline. This is a big win for modes that hide
4376 complete lines, like Outline, Org, etc. */
4377 if (on_newline
|| after_newline
)
4379 struct text_pos tpos
;
4380 bidi_dir_t pdir
= it
->bidi_it
.paragraph_dir
;
4382 SET_TEXT_POS (tpos
, newpos
, bpos
);
4383 reseat_1 (it
, tpos
, 0);
4384 /* If we reseat on a newline/ZV, we need to prep the
4385 bidi iterator for advancing to the next character
4386 after the newline/EOB, keeping the current paragraph
4387 direction (so that PRODUCE_GLYPHS does TRT wrt
4388 prepending/appending glyphs to a glyph row). */
4391 it
->bidi_it
.first_elt
= 0;
4392 it
->bidi_it
.paragraph_dir
= pdir
;
4393 it
->bidi_it
.ch
= (bpos
== ZV_BYTE
) ? -1 : '\n';
4394 it
->bidi_it
.nchars
= 1;
4395 it
->bidi_it
.ch_len
= 1;
4398 else /* Must use the slow method. */
4400 /* With bidi iteration, the region of invisible text
4401 could start and/or end in the middle of a
4402 non-base embedding level. Therefore, we need to
4403 skip invisible text using the bidi iterator,
4404 starting at IT's current position, until we find
4405 ourselves outside of the invisible text.
4406 Skipping invisible text _after_ bidi iteration
4407 avoids affecting the visual order of the
4408 displayed text when invisible properties are
4409 added or removed. */
4410 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< ZV
)
4412 /* If we were `reseat'ed to a new paragraph,
4413 determine the paragraph base direction. We
4414 need to do it now because
4415 next_element_from_buffer may not have a
4416 chance to do it, if we are going to skip any
4417 text at the beginning, which resets the
4419 bidi_paragraph_init (it
->paragraph_embedding
,
4424 bidi_move_to_visually_next (&it
->bidi_it
);
4426 while (it
->stop_charpos
<= it
->bidi_it
.charpos
4427 && it
->bidi_it
.charpos
< newpos
);
4428 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4429 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4430 /* If we overstepped NEWPOS, record its position in
4431 the iterator, so that we skip invisible text if
4432 later the bidi iteration lands us in the
4433 invisible region again. */
4434 if (IT_CHARPOS (*it
) >= newpos
)
4435 it
->prev_stop
= newpos
;
4440 IT_CHARPOS (*it
) = newpos
;
4441 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
4444 /* If there are before-strings at the start of invisible
4445 text, and the text is invisible because of a text
4446 property, arrange to show before-strings because 20.x did
4447 it that way. (If the text is invisible because of an
4448 overlay property instead of a text property, this is
4449 already handled in the overlay code.) */
4451 && get_overlay_strings (it
, it
->stop_charpos
))
4453 handled
= HANDLED_RECOMPUTE_PROPS
;
4454 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
4456 else if (display_ellipsis_p
)
4458 /* Make sure that the glyphs of the ellipsis will get
4459 correct `charpos' values. If we would not update
4460 it->position here, the glyphs would belong to the
4461 last visible character _before_ the invisible
4462 text, which confuses `set_cursor_from_row'.
4464 We use the last invisible position instead of the
4465 first because this way the cursor is always drawn on
4466 the first "." of the ellipsis, whenever PT is inside
4467 the invisible text. Otherwise the cursor would be
4468 placed _after_ the ellipsis when the point is after the
4469 first invisible character. */
4470 if (!STRINGP (it
->object
))
4472 it
->position
.charpos
= newpos
- 1;
4473 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
4476 /* Let the ellipsis display before
4477 considering any properties of the following char.
4478 Fixes jasonr@gnu.org 01 Oct 07 bug. */
4479 handled
= HANDLED_RETURN
;
4488 /* Make iterator IT return `...' next.
4489 Replaces LEN characters from buffer. */
4492 setup_for_ellipsis (struct it
*it
, int len
)
4494 /* Use the display table definition for `...'. Invalid glyphs
4495 will be handled by the method returning elements from dpvec. */
4496 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
4498 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
4499 it
->dpvec
= v
->contents
;
4500 it
->dpend
= v
->contents
+ v
->header
.size
;
4504 /* Default `...'. */
4505 it
->dpvec
= default_invis_vector
;
4506 it
->dpend
= default_invis_vector
+ 3;
4509 it
->dpvec_char_len
= len
;
4510 it
->current
.dpvec_index
= 0;
4511 it
->dpvec_face_id
= -1;
4513 /* Remember the current face id in case glyphs specify faces.
4514 IT's face is restored in set_iterator_to_next.
4515 saved_face_id was set to preceding char's face in handle_stop. */
4516 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
4517 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
4519 it
->method
= GET_FROM_DISPLAY_VECTOR
;
4525 /***********************************************************************
4527 ***********************************************************************/
4529 /* Set up iterator IT from `display' property at its current position.
4530 Called from handle_stop.
4531 We return HANDLED_RETURN if some part of the display property
4532 overrides the display of the buffer text itself.
4533 Otherwise we return HANDLED_NORMALLY. */
4535 static enum prop_handled
4536 handle_display_prop (struct it
*it
)
4538 Lisp_Object propval
, object
, overlay
;
4539 struct text_pos
*position
;
4541 /* Nonzero if some property replaces the display of the text itself. */
4542 int display_replaced_p
= 0;
4544 if (STRINGP (it
->string
))
4546 object
= it
->string
;
4547 position
= &it
->current
.string_pos
;
4548 bufpos
= CHARPOS (it
->current
.pos
);
4552 XSETWINDOW (object
, it
->w
);
4553 position
= &it
->current
.pos
;
4554 bufpos
= CHARPOS (*position
);
4557 /* Reset those iterator values set from display property values. */
4558 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
4559 it
->space_width
= Qnil
;
4560 it
->font_height
= Qnil
;
4563 /* We don't support recursive `display' properties, i.e. string
4564 values that have a string `display' property, that have a string
4565 `display' property etc. */
4566 if (!it
->string_from_display_prop_p
)
4567 it
->area
= TEXT_AREA
;
4569 propval
= get_char_property_and_overlay (make_number (position
->charpos
),
4570 Qdisplay
, object
, &overlay
);
4572 return HANDLED_NORMALLY
;
4573 /* Now OVERLAY is the overlay that gave us this property, or nil
4574 if it was a text property. */
4576 if (!STRINGP (it
->string
))
4577 object
= it
->w
->contents
;
4579 display_replaced_p
= handle_display_spec (it
, propval
, object
, overlay
,
4581 FRAME_WINDOW_P (it
->f
));
4583 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
4586 /* Subroutine of handle_display_prop. Returns non-zero if the display
4587 specification in SPEC is a replacing specification, i.e. it would
4588 replace the text covered by `display' property with something else,
4589 such as an image or a display string. If SPEC includes any kind or
4590 `(space ...) specification, the value is 2; this is used by
4591 compute_display_string_pos, which see.
4593 See handle_single_display_spec for documentation of arguments.
4594 frame_window_p is non-zero if the window being redisplayed is on a
4595 GUI frame; this argument is used only if IT is NULL, see below.
4597 IT can be NULL, if this is called by the bidi reordering code
4598 through compute_display_string_pos, which see. In that case, this
4599 function only examines SPEC, but does not otherwise "handle" it, in
4600 the sense that it doesn't set up members of IT from the display
4603 handle_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4604 Lisp_Object overlay
, struct text_pos
*position
,
4605 ptrdiff_t bufpos
, int frame_window_p
)
4607 int replacing_p
= 0;
4611 /* Simple specifications. */
4612 && !EQ (XCAR (spec
), Qimage
)
4613 #ifdef HAVE_XWIDGETS
4614 && !EQ (XCAR (spec
), Qxwidget
)
4616 && !EQ (XCAR (spec
), Qspace
)
4617 && !EQ (XCAR (spec
), Qwhen
)
4618 && !EQ (XCAR (spec
), Qslice
)
4619 && !EQ (XCAR (spec
), Qspace_width
)
4620 && !EQ (XCAR (spec
), Qheight
)
4621 && !EQ (XCAR (spec
), Qraise
)
4622 /* Marginal area specifications. */
4623 && !(CONSP (XCAR (spec
)) && EQ (XCAR (XCAR (spec
)), Qmargin
))
4624 && !EQ (XCAR (spec
), Qleft_fringe
)
4625 && !EQ (XCAR (spec
), Qright_fringe
)
4626 && !NILP (XCAR (spec
)))
4628 for (; CONSP (spec
); spec
= XCDR (spec
))
4630 if ((rv
= handle_single_display_spec (it
, XCAR (spec
), object
,
4631 overlay
, position
, bufpos
,
4632 replacing_p
, frame_window_p
)))
4635 /* If some text in a string is replaced, `position' no
4636 longer points to the position of `object'. */
4637 if (!it
|| STRINGP (object
))
4642 else if (VECTORP (spec
))
4645 for (i
= 0; i
< ASIZE (spec
); ++i
)
4646 if ((rv
= handle_single_display_spec (it
, AREF (spec
, i
), object
,
4647 overlay
, position
, bufpos
,
4648 replacing_p
, frame_window_p
)))
4651 /* If some text in a string is replaced, `position' no
4652 longer points to the position of `object'. */
4653 if (!it
|| STRINGP (object
))
4659 if ((rv
= handle_single_display_spec (it
, spec
, object
, overlay
,
4660 position
, bufpos
, 0,
4668 /* Value is the position of the end of the `display' property starting
4669 at START_POS in OBJECT. */
4671 static struct text_pos
4672 display_prop_end (struct it
*it
, Lisp_Object object
, struct text_pos start_pos
)
4675 struct text_pos end_pos
;
4677 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
4678 Qdisplay
, object
, Qnil
);
4679 CHARPOS (end_pos
) = XFASTINT (end
);
4680 if (STRINGP (object
))
4681 compute_string_pos (&end_pos
, start_pos
, it
->string
);
4683 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
4689 /* Set up IT from a single `display' property specification SPEC. OBJECT
4690 is the object in which the `display' property was found. *POSITION
4691 is the position in OBJECT at which the `display' property was found.
4692 BUFPOS is the buffer position of OBJECT (different from POSITION if
4693 OBJECT is not a buffer). DISPLAY_REPLACED_P non-zero means that we
4694 previously saw a display specification which already replaced text
4695 display with something else, for example an image; we ignore such
4696 properties after the first one has been processed.
4698 OVERLAY is the overlay this `display' property came from,
4699 or nil if it was a text property.
4701 If SPEC is a `space' or `image' specification, and in some other
4702 cases too, set *POSITION to the position where the `display'
4705 If IT is NULL, only examine the property specification in SPEC, but
4706 don't set up IT. In that case, FRAME_WINDOW_P non-zero means SPEC
4707 is intended to be displayed in a window on a GUI frame.
4709 Value is non-zero if something was found which replaces the display
4710 of buffer or string text. */
4713 handle_single_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4714 Lisp_Object overlay
, struct text_pos
*position
,
4715 ptrdiff_t bufpos
, int display_replaced_p
,
4719 Lisp_Object location
, value
;
4720 struct text_pos start_pos
= *position
;
4723 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
4724 If the result is non-nil, use VALUE instead of SPEC. */
4726 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4735 if (!NILP (form
) && !EQ (form
, Qt
))
4737 ptrdiff_t count
= SPECPDL_INDEX ();
4738 struct gcpro gcpro1
;
4740 /* Bind `object' to the object having the `display' property, a
4741 buffer or string. Bind `position' to the position in the
4742 object where the property was found, and `buffer-position'
4743 to the current position in the buffer. */
4746 XSETBUFFER (object
, current_buffer
);
4747 specbind (Qobject
, object
);
4748 specbind (Qposition
, make_number (CHARPOS (*position
)));
4749 specbind (Qbuffer_position
, make_number (bufpos
));
4751 form
= safe_eval (form
);
4753 unbind_to (count
, Qnil
);
4759 /* Handle `(height HEIGHT)' specifications. */
4761 && EQ (XCAR (spec
), Qheight
)
4762 && CONSP (XCDR (spec
)))
4766 if (!FRAME_WINDOW_P (it
->f
))
4769 it
->font_height
= XCAR (XCDR (spec
));
4770 if (!NILP (it
->font_height
))
4772 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4773 int new_height
= -1;
4775 if (CONSP (it
->font_height
)
4776 && (EQ (XCAR (it
->font_height
), Qplus
)
4777 || EQ (XCAR (it
->font_height
), Qminus
))
4778 && CONSP (XCDR (it
->font_height
))
4779 && RANGED_INTEGERP (0, XCAR (XCDR (it
->font_height
)), INT_MAX
))
4781 /* `(+ N)' or `(- N)' where N is an integer. */
4782 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4783 if (EQ (XCAR (it
->font_height
), Qplus
))
4785 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4787 else if (FUNCTIONP (it
->font_height
))
4789 /* Call function with current height as argument.
4790 Value is the new height. */
4792 height
= safe_call1 (it
->font_height
,
4793 face
->lface
[LFACE_HEIGHT_INDEX
]);
4794 if (NUMBERP (height
))
4795 new_height
= XFLOATINT (height
);
4797 else if (NUMBERP (it
->font_height
))
4799 /* Value is a multiple of the canonical char height. */
4802 f
= FACE_FROM_ID (it
->f
,
4803 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4804 new_height
= (XFLOATINT (it
->font_height
)
4805 * XINT (f
->lface
[LFACE_HEIGHT_INDEX
]));
4809 /* Evaluate IT->font_height with `height' bound to the
4810 current specified height to get the new height. */
4811 ptrdiff_t count
= SPECPDL_INDEX ();
4813 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4814 value
= safe_eval (it
->font_height
);
4815 unbind_to (count
, Qnil
);
4817 if (NUMBERP (value
))
4818 new_height
= XFLOATINT (value
);
4822 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4829 /* Handle `(space-width WIDTH)'. */
4831 && EQ (XCAR (spec
), Qspace_width
)
4832 && CONSP (XCDR (spec
)))
4836 if (!FRAME_WINDOW_P (it
->f
))
4839 value
= XCAR (XCDR (spec
));
4840 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4841 it
->space_width
= value
;
4847 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4849 && EQ (XCAR (spec
), Qslice
))
4855 if (!FRAME_WINDOW_P (it
->f
))
4858 if (tem
= XCDR (spec
), CONSP (tem
))
4860 it
->slice
.x
= XCAR (tem
);
4861 if (tem
= XCDR (tem
), CONSP (tem
))
4863 it
->slice
.y
= XCAR (tem
);
4864 if (tem
= XCDR (tem
), CONSP (tem
))
4866 it
->slice
.width
= XCAR (tem
);
4867 if (tem
= XCDR (tem
), CONSP (tem
))
4868 it
->slice
.height
= XCAR (tem
);
4877 /* Handle `(raise FACTOR)'. */
4879 && EQ (XCAR (spec
), Qraise
)
4880 && CONSP (XCDR (spec
)))
4884 if (!FRAME_WINDOW_P (it
->f
))
4887 #ifdef HAVE_WINDOW_SYSTEM
4888 value
= XCAR (XCDR (spec
));
4889 if (NUMBERP (value
))
4891 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4892 it
->voffset
= - (XFLOATINT (value
)
4893 * (FONT_HEIGHT (face
->font
)));
4895 #endif /* HAVE_WINDOW_SYSTEM */
4901 /* Don't handle the other kinds of display specifications
4902 inside a string that we got from a `display' property. */
4903 if (it
&& it
->string_from_display_prop_p
)
4906 /* Characters having this form of property are not displayed, so
4907 we have to find the end of the property. */
4910 start_pos
= *position
;
4911 *position
= display_prop_end (it
, object
, start_pos
);
4915 /* Stop the scan at that end position--we assume that all
4916 text properties change there. */
4918 it
->stop_charpos
= position
->charpos
;
4920 /* Handle `(left-fringe BITMAP [FACE])'
4921 and `(right-fringe BITMAP [FACE])'. */
4923 && (EQ (XCAR (spec
), Qleft_fringe
)
4924 || EQ (XCAR (spec
), Qright_fringe
))
4925 && CONSP (XCDR (spec
)))
4931 if (!FRAME_WINDOW_P (it
->f
))
4932 /* If we return here, POSITION has been advanced
4933 across the text with this property. */
4935 /* Synchronize the bidi iterator with POSITION. This is
4936 needed because we are not going to push the iterator
4937 on behalf of this display property, so there will be
4938 no pop_it call to do this synchronization for us. */
4941 it
->position
= *position
;
4942 iterate_out_of_display_property (it
);
4943 *position
= it
->position
;
4948 else if (!frame_window_p
)
4951 #ifdef HAVE_WINDOW_SYSTEM
4952 value
= XCAR (XCDR (spec
));
4953 if (!SYMBOLP (value
)
4954 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4955 /* If we return here, POSITION has been advanced
4956 across the text with this property. */
4958 if (it
&& it
->bidi_p
)
4960 it
->position
= *position
;
4961 iterate_out_of_display_property (it
);
4962 *position
= it
->position
;
4969 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);;
4971 if (CONSP (XCDR (XCDR (spec
))))
4973 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4974 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4980 /* Save current settings of IT so that we can restore them
4981 when we are finished with the glyph property value. */
4982 push_it (it
, position
);
4984 it
->area
= TEXT_AREA
;
4985 it
->what
= IT_IMAGE
;
4986 it
->image_id
= -1; /* no image */
4987 it
->position
= start_pos
;
4988 it
->object
= NILP (object
) ? it
->w
->contents
: object
;
4989 it
->method
= GET_FROM_IMAGE
;
4990 it
->from_overlay
= Qnil
;
4991 it
->face_id
= face_id
;
4992 it
->from_disp_prop_p
= 1;
4994 /* Say that we haven't consumed the characters with
4995 `display' property yet. The call to pop_it in
4996 set_iterator_to_next will clean this up. */
4997 *position
= start_pos
;
4999 if (EQ (XCAR (spec
), Qleft_fringe
))
5001 it
->left_user_fringe_bitmap
= fringe_bitmap
;
5002 it
->left_user_fringe_face_id
= face_id
;
5006 it
->right_user_fringe_bitmap
= fringe_bitmap
;
5007 it
->right_user_fringe_face_id
= face_id
;
5010 #endif /* HAVE_WINDOW_SYSTEM */
5014 /* Prepare to handle `((margin left-margin) ...)',
5015 `((margin right-margin) ...)' and `((margin nil) ...)'
5016 prefixes for display specifications. */
5017 location
= Qunbound
;
5018 if (CONSP (spec
) && CONSP (XCAR (spec
)))
5022 value
= XCDR (spec
);
5024 value
= XCAR (value
);
5027 if (EQ (XCAR (tem
), Qmargin
)
5028 && (tem
= XCDR (tem
),
5029 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
5031 || EQ (tem
, Qleft_margin
)
5032 || EQ (tem
, Qright_margin
))))
5036 if (EQ (location
, Qunbound
))
5042 /* After this point, VALUE is the property after any
5043 margin prefix has been stripped. It must be a string,
5044 an image specification, or `(space ...)'.
5046 LOCATION specifies where to display: `left-margin',
5047 `right-margin' or nil. */
5049 valid_p
= (STRINGP (value
)
5050 #ifdef HAVE_WINDOW_SYSTEM
5051 || ((it
? FRAME_WINDOW_P (it
->f
) : frame_window_p
)
5052 && valid_image_p (value
))
5053 #endif /* not HAVE_WINDOW_SYSTEM */
5054 || (CONSP (value
) && EQ (XCAR (value
), Qspace
))
5055 #ifdef HAVE_XWIDGETS
5056 || valid_xwidget_spec_p(value
)
5060 if (valid_p
&& !display_replaced_p
)
5066 /* Callers need to know whether the display spec is any kind
5067 of `(space ...)' spec that is about to affect text-area
5069 if (CONSP (value
) && EQ (XCAR (value
), Qspace
) && NILP (location
))
5074 /* Save current settings of IT so that we can restore them
5075 when we are finished with the glyph property value. */
5076 push_it (it
, position
);
5077 it
->from_overlay
= overlay
;
5078 it
->from_disp_prop_p
= 1;
5080 if (NILP (location
))
5081 it
->area
= TEXT_AREA
;
5082 else if (EQ (location
, Qleft_margin
))
5083 it
->area
= LEFT_MARGIN_AREA
;
5085 it
->area
= RIGHT_MARGIN_AREA
;
5087 if (STRINGP (value
))
5090 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5091 it
->current
.overlay_string_index
= -1;
5092 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5093 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
5094 it
->method
= GET_FROM_STRING
;
5095 it
->stop_charpos
= 0;
5097 it
->base_level_stop
= 0;
5098 it
->string_from_display_prop_p
= 1;
5099 /* Say that we haven't consumed the characters with
5100 `display' property yet. The call to pop_it in
5101 set_iterator_to_next will clean this up. */
5102 if (BUFFERP (object
))
5103 *position
= start_pos
;
5105 /* Force paragraph direction to be that of the parent
5106 object. If the parent object's paragraph direction is
5107 not yet determined, default to L2R. */
5108 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
5109 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5111 it
->paragraph_embedding
= L2R
;
5113 /* Set up the bidi iterator for this display string. */
5116 it
->bidi_it
.string
.lstring
= it
->string
;
5117 it
->bidi_it
.string
.s
= NULL
;
5118 it
->bidi_it
.string
.schars
= it
->end_charpos
;
5119 it
->bidi_it
.string
.bufpos
= bufpos
;
5120 it
->bidi_it
.string
.from_disp_str
= 1;
5121 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5122 it
->bidi_it
.w
= it
->w
;
5123 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5126 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
5128 it
->method
= GET_FROM_STRETCH
;
5130 *position
= it
->position
= start_pos
;
5131 retval
= 1 + (it
->area
== TEXT_AREA
);
5133 #ifdef HAVE_XWIDGETS
5134 else if (valid_xwidget_spec_p(value
))
5136 //printf("handle_single_display_spec: im an xwidget!!\n");
5137 it
->what
= IT_XWIDGET
;
5138 it
->method
= GET_FROM_XWIDGET
;
5139 it
->position
= start_pos
;
5140 it
->object
= NILP (object
) ? it
->w
->contents
: object
;
5141 *position
= start_pos
;
5143 it
->xwidget
= lookup_xwidget(value
);
5146 #ifdef HAVE_WINDOW_SYSTEM
5149 it
->what
= IT_IMAGE
;
5150 it
->image_id
= lookup_image (it
->f
, value
);
5151 it
->position
= start_pos
;
5152 it
->object
= NILP (object
) ? it
->w
->contents
: object
;
5153 it
->method
= GET_FROM_IMAGE
;
5155 /* Say that we haven't consumed the characters with
5156 `display' property yet. The call to pop_it in
5157 set_iterator_to_next will clean this up. */
5158 *position
= start_pos
;
5160 #endif /* HAVE_WINDOW_SYSTEM */
5165 /* Invalid property or property not supported. Restore
5166 POSITION to what it was before. */
5167 *position
= start_pos
;
5171 /* Check if PROP is a display property value whose text should be
5172 treated as intangible. OVERLAY is the overlay from which PROP
5173 came, or nil if it came from a text property. CHARPOS and BYTEPOS
5174 specify the buffer position covered by PROP. */
5177 display_prop_intangible_p (Lisp_Object prop
, Lisp_Object overlay
,
5178 ptrdiff_t charpos
, ptrdiff_t bytepos
)
5180 int frame_window_p
= FRAME_WINDOW_P (XFRAME (selected_frame
));
5181 struct text_pos position
;
5183 SET_TEXT_POS (position
, charpos
, bytepos
);
5184 return handle_display_spec (NULL
, prop
, Qnil
, overlay
,
5185 &position
, charpos
, frame_window_p
);
5189 /* Return 1 if PROP is a display sub-property value containing STRING.
5191 Implementation note: this and the following function are really
5192 special cases of handle_display_spec and
5193 handle_single_display_spec, and should ideally use the same code.
5194 Until they do, these two pairs must be consistent and must be
5195 modified in sync. */
5198 single_display_spec_string_p (Lisp_Object prop
, Lisp_Object string
)
5200 if (EQ (string
, prop
))
5203 /* Skip over `when FORM'. */
5204 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
5209 /* Actually, the condition following `when' should be eval'ed,
5210 like handle_single_display_spec does, and we should return
5211 zero if it evaluates to nil. However, this function is
5212 called only when the buffer was already displayed and some
5213 glyph in the glyph matrix was found to come from a display
5214 string. Therefore, the condition was already evaluated, and
5215 the result was non-nil, otherwise the display string wouldn't
5216 have been displayed and we would have never been called for
5217 this property. Thus, we can skip the evaluation and assume
5218 its result is non-nil. */
5223 /* Skip over `margin LOCATION'. */
5224 if (EQ (XCAR (prop
), Qmargin
))
5235 return EQ (prop
, string
) || (CONSP (prop
) && EQ (XCAR (prop
), string
));
5239 /* Return 1 if STRING appears in the `display' property PROP. */
5242 display_prop_string_p (Lisp_Object prop
, Lisp_Object string
)
5245 && !EQ (XCAR (prop
), Qwhen
)
5246 && !(CONSP (XCAR (prop
)) && EQ (Qmargin
, XCAR (XCAR (prop
)))))
5248 /* A list of sub-properties. */
5249 while (CONSP (prop
))
5251 if (single_display_spec_string_p (XCAR (prop
), string
))
5256 else if (VECTORP (prop
))
5258 /* A vector of sub-properties. */
5260 for (i
= 0; i
< ASIZE (prop
); ++i
)
5261 if (single_display_spec_string_p (AREF (prop
, i
), string
))
5265 return single_display_spec_string_p (prop
, string
);
5270 /* Look for STRING in overlays and text properties in the current
5271 buffer, between character positions FROM and TO (excluding TO).
5272 BACK_P non-zero means look back (in this case, TO is supposed to be
5274 Value is the first character position where STRING was found, or
5275 zero if it wasn't found before hitting TO.
5277 This function may only use code that doesn't eval because it is
5278 called asynchronously from note_mouse_highlight. */
5281 string_buffer_position_lim (Lisp_Object string
,
5282 ptrdiff_t from
, ptrdiff_t to
, int back_p
)
5284 Lisp_Object limit
, prop
, pos
;
5287 pos
= make_number (max (from
, BEGV
));
5289 if (!back_p
) /* looking forward */
5291 limit
= make_number (min (to
, ZV
));
5292 while (!found
&& !EQ (pos
, limit
))
5294 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5295 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5298 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
,
5302 else /* looking back */
5304 limit
= make_number (max (to
, BEGV
));
5305 while (!found
&& !EQ (pos
, limit
))
5307 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5308 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5311 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
5316 return found
? XINT (pos
) : 0;
5319 /* Determine which buffer position in current buffer STRING comes from.
5320 AROUND_CHARPOS is an approximate position where it could come from.
5321 Value is the buffer position or 0 if it couldn't be determined.
5323 This function is necessary because we don't record buffer positions
5324 in glyphs generated from strings (to keep struct glyph small).
5325 This function may only use code that doesn't eval because it is
5326 called asynchronously from note_mouse_highlight. */
5329 string_buffer_position (Lisp_Object string
, ptrdiff_t around_charpos
)
5331 const int MAX_DISTANCE
= 1000;
5332 ptrdiff_t found
= string_buffer_position_lim (string
, around_charpos
,
5333 around_charpos
+ MAX_DISTANCE
,
5337 found
= string_buffer_position_lim (string
, around_charpos
,
5338 around_charpos
- MAX_DISTANCE
, 1);
5344 /***********************************************************************
5345 `composition' property
5346 ***********************************************************************/
5348 /* Set up iterator IT from `composition' property at its current
5349 position. Called from handle_stop. */
5351 static enum prop_handled
5352 handle_composition_prop (struct it
*it
)
5354 Lisp_Object prop
, string
;
5355 ptrdiff_t pos
, pos_byte
, start
, end
;
5357 if (STRINGP (it
->string
))
5361 pos
= IT_STRING_CHARPOS (*it
);
5362 pos_byte
= IT_STRING_BYTEPOS (*it
);
5363 string
= it
->string
;
5364 s
= SDATA (string
) + pos_byte
;
5365 it
->c
= STRING_CHAR (s
);
5369 pos
= IT_CHARPOS (*it
);
5370 pos_byte
= IT_BYTEPOS (*it
);
5372 it
->c
= FETCH_CHAR (pos_byte
);
5375 /* If there's a valid composition and point is not inside of the
5376 composition (in the case that the composition is from the current
5377 buffer), draw a glyph composed from the composition components. */
5378 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
5379 && composition_valid_p (start
, end
, prop
)
5380 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
5383 /* As we can't handle this situation (perhaps font-lock added
5384 a new composition), we just return here hoping that next
5385 redisplay will detect this composition much earlier. */
5386 return HANDLED_NORMALLY
;
5389 if (STRINGP (it
->string
))
5390 pos_byte
= string_char_to_byte (it
->string
, start
);
5392 pos_byte
= CHAR_TO_BYTE (start
);
5394 it
->cmp_it
.id
= get_composition_id (start
, pos_byte
, end
- start
,
5397 if (it
->cmp_it
.id
>= 0)
5400 it
->cmp_it
.nchars
= COMPOSITION_LENGTH (prop
);
5401 it
->cmp_it
.nglyphs
= -1;
5405 return HANDLED_NORMALLY
;
5410 /***********************************************************************
5412 ***********************************************************************/
5414 /* The following structure is used to record overlay strings for
5415 later sorting in load_overlay_strings. */
5417 struct overlay_entry
5419 Lisp_Object overlay
;
5426 /* Set up iterator IT from overlay strings at its current position.
5427 Called from handle_stop. */
5429 static enum prop_handled
5430 handle_overlay_change (struct it
*it
)
5432 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
5433 return HANDLED_RECOMPUTE_PROPS
;
5435 return HANDLED_NORMALLY
;
5439 /* Set up the next overlay string for delivery by IT, if there is an
5440 overlay string to deliver. Called by set_iterator_to_next when the
5441 end of the current overlay string is reached. If there are more
5442 overlay strings to display, IT->string and
5443 IT->current.overlay_string_index are set appropriately here.
5444 Otherwise IT->string is set to nil. */
5447 next_overlay_string (struct it
*it
)
5449 ++it
->current
.overlay_string_index
;
5450 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
5452 /* No more overlay strings. Restore IT's settings to what
5453 they were before overlay strings were processed, and
5454 continue to deliver from current_buffer. */
5456 it
->ellipsis_p
= (it
->stack
[it
->sp
- 1].display_ellipsis_p
!= 0);
5459 || (NILP (it
->string
)
5460 && it
->method
== GET_FROM_BUFFER
5461 && it
->stop_charpos
>= BEGV
5462 && it
->stop_charpos
<= it
->end_charpos
));
5463 it
->current
.overlay_string_index
= -1;
5464 it
->n_overlay_strings
= 0;
5465 it
->overlay_strings_charpos
= -1;
5466 /* If there's an empty display string on the stack, pop the
5467 stack, to resync the bidi iterator with IT's position. Such
5468 empty strings are pushed onto the stack in
5469 get_overlay_strings_1. */
5470 if (it
->sp
> 0 && STRINGP (it
->string
) && !SCHARS (it
->string
))
5473 /* If we're at the end of the buffer, record that we have
5474 processed the overlay strings there already, so that
5475 next_element_from_buffer doesn't try it again. */
5476 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
5477 it
->overlay_strings_at_end_processed_p
= 1;
5481 /* There are more overlay strings to process. If
5482 IT->current.overlay_string_index has advanced to a position
5483 where we must load IT->overlay_strings with more strings, do
5484 it. We must load at the IT->overlay_strings_charpos where
5485 IT->n_overlay_strings was originally computed; when invisible
5486 text is present, this might not be IT_CHARPOS (Bug#7016). */
5487 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
5489 if (it
->current
.overlay_string_index
&& i
== 0)
5490 load_overlay_strings (it
, it
->overlay_strings_charpos
);
5492 /* Initialize IT to deliver display elements from the overlay
5494 it
->string
= it
->overlay_strings
[i
];
5495 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5496 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
5497 it
->method
= GET_FROM_STRING
;
5498 it
->stop_charpos
= 0;
5499 it
->end_charpos
= SCHARS (it
->string
);
5500 if (it
->cmp_it
.stop_pos
>= 0)
5501 it
->cmp_it
.stop_pos
= 0;
5503 it
->base_level_stop
= 0;
5505 /* Set up the bidi iterator for this overlay string. */
5508 it
->bidi_it
.string
.lstring
= it
->string
;
5509 it
->bidi_it
.string
.s
= NULL
;
5510 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5511 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
5512 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5513 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5514 it
->bidi_it
.w
= it
->w
;
5515 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5523 /* Compare two overlay_entry structures E1 and E2. Used as a
5524 comparison function for qsort in load_overlay_strings. Overlay
5525 strings for the same position are sorted so that
5527 1. All after-strings come in front of before-strings, except
5528 when they come from the same overlay.
5530 2. Within after-strings, strings are sorted so that overlay strings
5531 from overlays with higher priorities come first.
5533 2. Within before-strings, strings are sorted so that overlay
5534 strings from overlays with higher priorities come last.
5536 Value is analogous to strcmp. */
5540 compare_overlay_entries (const void *e1
, const void *e2
)
5542 struct overlay_entry
const *entry1
= e1
;
5543 struct overlay_entry
const *entry2
= e2
;
5546 if (entry1
->after_string_p
!= entry2
->after_string_p
)
5548 /* Let after-strings appear in front of before-strings if
5549 they come from different overlays. */
5550 if (EQ (entry1
->overlay
, entry2
->overlay
))
5551 result
= entry1
->after_string_p
? 1 : -1;
5553 result
= entry1
->after_string_p
? -1 : 1;
5555 else if (entry1
->priority
!= entry2
->priority
)
5557 if (entry1
->after_string_p
)
5558 /* After-strings sorted in order of decreasing priority. */
5559 result
= entry2
->priority
< entry1
->priority
? -1 : 1;
5561 /* Before-strings sorted in order of increasing priority. */
5562 result
= entry1
->priority
< entry2
->priority
? -1 : 1;
5571 /* Load the vector IT->overlay_strings with overlay strings from IT's
5572 current buffer position, or from CHARPOS if that is > 0. Set
5573 IT->n_overlays to the total number of overlay strings found.
5575 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
5576 a time. On entry into load_overlay_strings,
5577 IT->current.overlay_string_index gives the number of overlay
5578 strings that have already been loaded by previous calls to this
5581 IT->add_overlay_start contains an additional overlay start
5582 position to consider for taking overlay strings from, if non-zero.
5583 This position comes into play when the overlay has an `invisible'
5584 property, and both before and after-strings. When we've skipped to
5585 the end of the overlay, because of its `invisible' property, we
5586 nevertheless want its before-string to appear.
5587 IT->add_overlay_start will contain the overlay start position
5590 Overlay strings are sorted so that after-string strings come in
5591 front of before-string strings. Within before and after-strings,
5592 strings are sorted by overlay priority. See also function
5593 compare_overlay_entries. */
5596 load_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5598 Lisp_Object overlay
, window
, str
, invisible
;
5599 struct Lisp_Overlay
*ov
;
5600 ptrdiff_t start
, end
;
5601 ptrdiff_t size
= 20;
5602 ptrdiff_t n
= 0, i
, j
;
5604 struct overlay_entry
*entries
= alloca (size
* sizeof *entries
);
5608 charpos
= IT_CHARPOS (*it
);
5610 /* Append the overlay string STRING of overlay OVERLAY to vector
5611 `entries' which has size `size' and currently contains `n'
5612 elements. AFTER_P non-zero means STRING is an after-string of
5614 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
5617 Lisp_Object priority; \
5621 struct overlay_entry *old = entries; \
5622 SAFE_NALLOCA (entries, 2, size); \
5623 memcpy (entries, old, size * sizeof *entries); \
5627 entries[n].string = (STRING); \
5628 entries[n].overlay = (OVERLAY); \
5629 priority = Foverlay_get ((OVERLAY), Qpriority); \
5630 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
5631 entries[n].after_string_p = (AFTER_P); \
5636 /* Process overlay before the overlay center. */
5637 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
5639 XSETMISC (overlay
, ov
);
5640 eassert (OVERLAYP (overlay
));
5641 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5642 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5647 /* Skip this overlay if it doesn't start or end at IT's current
5649 if (end
!= charpos
&& start
!= charpos
)
5652 /* Skip this overlay if it doesn't apply to IT->w. */
5653 window
= Foverlay_get (overlay
, Qwindow
);
5654 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5657 /* If the text ``under'' the overlay is invisible, both before-
5658 and after-strings from this overlay are visible; start and
5659 end position are indistinguishable. */
5660 invisible
= Foverlay_get (overlay
, Qinvisible
);
5661 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5663 /* If overlay has a non-empty before-string, record it. */
5664 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5665 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5667 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5669 /* If overlay has a non-empty after-string, record it. */
5670 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5671 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5673 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5676 /* Process overlays after the overlay center. */
5677 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
5679 XSETMISC (overlay
, ov
);
5680 eassert (OVERLAYP (overlay
));
5681 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5682 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5684 if (start
> charpos
)
5687 /* Skip this overlay if it doesn't start or end at IT's current
5689 if (end
!= charpos
&& start
!= charpos
)
5692 /* Skip this overlay if it doesn't apply to IT->w. */
5693 window
= Foverlay_get (overlay
, Qwindow
);
5694 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5697 /* If the text ``under'' the overlay is invisible, it has a zero
5698 dimension, and both before- and after-strings apply. */
5699 invisible
= Foverlay_get (overlay
, Qinvisible
);
5700 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5702 /* If overlay has a non-empty before-string, record it. */
5703 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5704 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5706 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5708 /* If overlay has a non-empty after-string, record it. */
5709 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5710 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5712 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5715 #undef RECORD_OVERLAY_STRING
5719 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
5721 /* Record number of overlay strings, and where we computed it. */
5722 it
->n_overlay_strings
= n
;
5723 it
->overlay_strings_charpos
= charpos
;
5725 /* IT->current.overlay_string_index is the number of overlay strings
5726 that have already been consumed by IT. Copy some of the
5727 remaining overlay strings to IT->overlay_strings. */
5729 j
= it
->current
.overlay_string_index
;
5730 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
5732 it
->overlay_strings
[i
] = entries
[j
].string
;
5733 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
5741 /* Get the first chunk of overlay strings at IT's current buffer
5742 position, or at CHARPOS if that is > 0. Value is non-zero if at
5743 least one overlay string was found. */
5746 get_overlay_strings_1 (struct it
*it
, ptrdiff_t charpos
, int compute_stop_p
)
5748 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5749 process. This fills IT->overlay_strings with strings, and sets
5750 IT->n_overlay_strings to the total number of strings to process.
5751 IT->pos.overlay_string_index has to be set temporarily to zero
5752 because load_overlay_strings needs this; it must be set to -1
5753 when no overlay strings are found because a zero value would
5754 indicate a position in the first overlay string. */
5755 it
->current
.overlay_string_index
= 0;
5756 load_overlay_strings (it
, charpos
);
5758 /* If we found overlay strings, set up IT to deliver display
5759 elements from the first one. Otherwise set up IT to deliver
5760 from current_buffer. */
5761 if (it
->n_overlay_strings
)
5763 /* Make sure we know settings in current_buffer, so that we can
5764 restore meaningful values when we're done with the overlay
5767 compute_stop_pos (it
);
5768 eassert (it
->face_id
>= 0);
5770 /* Save IT's settings. They are restored after all overlay
5771 strings have been processed. */
5772 eassert (!compute_stop_p
|| it
->sp
== 0);
5774 /* When called from handle_stop, there might be an empty display
5775 string loaded. In that case, don't bother saving it. But
5776 don't use this optimization with the bidi iterator, since we
5777 need the corresponding pop_it call to resync the bidi
5778 iterator's position with IT's position, after we are done
5779 with the overlay strings. (The corresponding call to pop_it
5780 in case of an empty display string is in
5781 next_overlay_string.) */
5783 && STRINGP (it
->string
) && !SCHARS (it
->string
)))
5786 /* Set up IT to deliver display elements from the first overlay
5788 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5789 it
->string
= it
->overlay_strings
[0];
5790 it
->from_overlay
= Qnil
;
5791 it
->stop_charpos
= 0;
5792 eassert (STRINGP (it
->string
));
5793 it
->end_charpos
= SCHARS (it
->string
);
5795 it
->base_level_stop
= 0;
5796 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5797 it
->method
= GET_FROM_STRING
;
5798 it
->from_disp_prop_p
= 0;
5800 /* Force paragraph direction to be that of the parent
5802 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
5803 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5805 it
->paragraph_embedding
= L2R
;
5807 /* Set up the bidi iterator for this overlay string. */
5810 ptrdiff_t pos
= (charpos
> 0 ? charpos
: IT_CHARPOS (*it
));
5812 it
->bidi_it
.string
.lstring
= it
->string
;
5813 it
->bidi_it
.string
.s
= NULL
;
5814 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5815 it
->bidi_it
.string
.bufpos
= pos
;
5816 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5817 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5818 it
->bidi_it
.w
= it
->w
;
5819 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5824 it
->current
.overlay_string_index
= -1;
5829 get_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5832 it
->method
= GET_FROM_BUFFER
;
5834 (void) get_overlay_strings_1 (it
, charpos
, 1);
5838 /* Value is non-zero if we found at least one overlay string. */
5839 return STRINGP (it
->string
);
5844 /***********************************************************************
5845 Saving and restoring state
5846 ***********************************************************************/
5848 /* Save current settings of IT on IT->stack. Called, for example,
5849 before setting up IT for an overlay string, to be able to restore
5850 IT's settings to what they were after the overlay string has been
5851 processed. If POSITION is non-NULL, it is the position to save on
5852 the stack instead of IT->position. */
5855 push_it (struct it
*it
, struct text_pos
*position
)
5857 struct iterator_stack_entry
*p
;
5859 eassert (it
->sp
< IT_STACK_SIZE
);
5860 p
= it
->stack
+ it
->sp
;
5862 p
->stop_charpos
= it
->stop_charpos
;
5863 p
->prev_stop
= it
->prev_stop
;
5864 p
->base_level_stop
= it
->base_level_stop
;
5865 p
->cmp_it
= it
->cmp_it
;
5866 eassert (it
->face_id
>= 0);
5867 p
->face_id
= it
->face_id
;
5868 p
->string
= it
->string
;
5869 p
->method
= it
->method
;
5870 p
->from_overlay
= it
->from_overlay
;
5873 case GET_FROM_IMAGE
:
5874 p
->u
.image
.object
= it
->object
;
5875 p
->u
.image
.image_id
= it
->image_id
;
5876 p
->u
.image
.slice
= it
->slice
;
5878 case GET_FROM_STRETCH
:
5879 p
->u
.stretch
.object
= it
->object
;
5881 #ifdef HAVE_XWIDGETS
5882 case GET_FROM_XWIDGET
:
5883 p
->u
.xwidget
.object
= it
->object
;
5887 p
->position
= position
? *position
: it
->position
;
5888 p
->current
= it
->current
;
5889 p
->end_charpos
= it
->end_charpos
;
5890 p
->string_nchars
= it
->string_nchars
;
5892 p
->multibyte_p
= it
->multibyte_p
;
5893 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
5894 p
->space_width
= it
->space_width
;
5895 p
->font_height
= it
->font_height
;
5896 p
->voffset
= it
->voffset
;
5897 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5898 p
->string_from_prefix_prop_p
= it
->string_from_prefix_prop_p
;
5899 p
->display_ellipsis_p
= 0;
5900 p
->line_wrap
= it
->line_wrap
;
5901 p
->bidi_p
= it
->bidi_p
;
5902 p
->paragraph_embedding
= it
->paragraph_embedding
;
5903 p
->from_disp_prop_p
= it
->from_disp_prop_p
;
5906 /* Save the state of the bidi iterator as well. */
5908 bidi_push_it (&it
->bidi_it
);
5912 iterate_out_of_display_property (struct it
*it
)
5914 int buffer_p
= !STRINGP (it
->string
);
5915 ptrdiff_t eob
= (buffer_p
? ZV
: it
->end_charpos
);
5916 ptrdiff_t bob
= (buffer_p
? BEGV
: 0);
5918 eassert (eob
>= CHARPOS (it
->position
) && CHARPOS (it
->position
) >= bob
);
5920 /* Maybe initialize paragraph direction. If we are at the beginning
5921 of a new paragraph, next_element_from_buffer may not have a
5922 chance to do that. */
5923 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< eob
)
5924 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
5925 /* prev_stop can be zero, so check against BEGV as well. */
5926 while (it
->bidi_it
.charpos
>= bob
5927 && it
->prev_stop
<= it
->bidi_it
.charpos
5928 && it
->bidi_it
.charpos
< CHARPOS (it
->position
)
5929 && it
->bidi_it
.charpos
< eob
)
5930 bidi_move_to_visually_next (&it
->bidi_it
);
5931 /* Record the stop_pos we just crossed, for when we cross it
5933 if (it
->bidi_it
.charpos
> CHARPOS (it
->position
))
5934 it
->prev_stop
= CHARPOS (it
->position
);
5935 /* If we ended up not where pop_it put us, resync IT's
5936 positional members with the bidi iterator. */
5937 if (it
->bidi_it
.charpos
!= CHARPOS (it
->position
))
5938 SET_TEXT_POS (it
->position
, it
->bidi_it
.charpos
, it
->bidi_it
.bytepos
);
5940 it
->current
.pos
= it
->position
;
5942 it
->current
.string_pos
= it
->position
;
5945 /* Restore IT's settings from IT->stack. Called, for example, when no
5946 more overlay strings must be processed, and we return to delivering
5947 display elements from a buffer, or when the end of a string from a
5948 `display' property is reached and we return to delivering display
5949 elements from an overlay string, or from a buffer. */
5952 pop_it (struct it
*it
)
5954 struct iterator_stack_entry
*p
;
5955 int from_display_prop
= it
->from_disp_prop_p
;
5957 eassert (it
->sp
> 0);
5959 p
= it
->stack
+ it
->sp
;
5960 it
->stop_charpos
= p
->stop_charpos
;
5961 it
->prev_stop
= p
->prev_stop
;
5962 it
->base_level_stop
= p
->base_level_stop
;
5963 it
->cmp_it
= p
->cmp_it
;
5964 it
->face_id
= p
->face_id
;
5965 it
->current
= p
->current
;
5966 it
->position
= p
->position
;
5967 it
->string
= p
->string
;
5968 it
->from_overlay
= p
->from_overlay
;
5969 if (NILP (it
->string
))
5970 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5971 it
->method
= p
->method
;
5974 case GET_FROM_IMAGE
:
5975 it
->image_id
= p
->u
.image
.image_id
;
5976 it
->object
= p
->u
.image
.object
;
5977 it
->slice
= p
->u
.image
.slice
;
5979 #ifdef HAVE_XWIDGETS
5980 case GET_FROM_XWIDGET
:
5981 it
->object
= p
->u
.xwidget
.object
;
5984 case GET_FROM_STRETCH
:
5985 it
->object
= p
->u
.stretch
.object
;
5987 case GET_FROM_BUFFER
:
5988 it
->object
= it
->w
->contents
;
5990 case GET_FROM_STRING
:
5991 it
->object
= it
->string
;
5993 case GET_FROM_DISPLAY_VECTOR
:
5995 it
->method
= GET_FROM_C_STRING
;
5996 else if (STRINGP (it
->string
))
5997 it
->method
= GET_FROM_STRING
;
6000 it
->method
= GET_FROM_BUFFER
;
6001 it
->object
= it
->w
->contents
;
6004 it
->end_charpos
= p
->end_charpos
;
6005 it
->string_nchars
= p
->string_nchars
;
6007 it
->multibyte_p
= p
->multibyte_p
;
6008 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
6009 it
->space_width
= p
->space_width
;
6010 it
->font_height
= p
->font_height
;
6011 it
->voffset
= p
->voffset
;
6012 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
6013 it
->string_from_prefix_prop_p
= p
->string_from_prefix_prop_p
;
6014 it
->line_wrap
= p
->line_wrap
;
6015 it
->bidi_p
= p
->bidi_p
;
6016 it
->paragraph_embedding
= p
->paragraph_embedding
;
6017 it
->from_disp_prop_p
= p
->from_disp_prop_p
;
6020 bidi_pop_it (&it
->bidi_it
);
6021 /* Bidi-iterate until we get out of the portion of text, if any,
6022 covered by a `display' text property or by an overlay with
6023 `display' property. (We cannot just jump there, because the
6024 internal coherency of the bidi iterator state can not be
6025 preserved across such jumps.) We also must determine the
6026 paragraph base direction if the overlay we just processed is
6027 at the beginning of a new paragraph. */
6028 if (from_display_prop
6029 && (it
->method
== GET_FROM_BUFFER
|| it
->method
== GET_FROM_STRING
))
6030 iterate_out_of_display_property (it
);
6032 eassert ((BUFFERP (it
->object
)
6033 && IT_CHARPOS (*it
) == it
->bidi_it
.charpos
6034 && IT_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
6035 || (STRINGP (it
->object
)
6036 && IT_STRING_CHARPOS (*it
) == it
->bidi_it
.charpos
6037 && IT_STRING_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
6038 || (CONSP (it
->object
) && it
->method
== GET_FROM_STRETCH
));
6044 /***********************************************************************
6046 ***********************************************************************/
6048 /* Set IT's current position to the previous line start. */
6051 back_to_previous_line_start (struct it
*it
)
6053 ptrdiff_t cp
= IT_CHARPOS (*it
), bp
= IT_BYTEPOS (*it
);
6056 IT_CHARPOS (*it
) = find_newline_no_quit (cp
, bp
, -1, &IT_BYTEPOS (*it
));
6060 /* Move IT to the next line start.
6062 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
6063 we skipped over part of the text (as opposed to moving the iterator
6064 continuously over the text). Otherwise, don't change the value
6067 If BIDI_IT_PREV is non-NULL, store into it the state of the bidi
6068 iterator on the newline, if it was found.
6070 Newlines may come from buffer text, overlay strings, or strings
6071 displayed via the `display' property. That's the reason we can't
6072 simply use find_newline_no_quit.
6074 Note that this function may not skip over invisible text that is so
6075 because of text properties and immediately follows a newline. If
6076 it would, function reseat_at_next_visible_line_start, when called
6077 from set_iterator_to_next, would effectively make invisible
6078 characters following a newline part of the wrong glyph row, which
6079 leads to wrong cursor motion. */
6082 forward_to_next_line_start (struct it
*it
, int *skipped_p
,
6083 struct bidi_it
*bidi_it_prev
)
6085 ptrdiff_t old_selective
;
6086 int newline_found_p
, n
;
6087 const int MAX_NEWLINE_DISTANCE
= 500;
6089 /* If already on a newline, just consume it to avoid unintended
6090 skipping over invisible text below. */
6091 if (it
->what
== IT_CHARACTER
6093 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
6095 if (it
->bidi_p
&& bidi_it_prev
)
6096 *bidi_it_prev
= it
->bidi_it
;
6097 set_iterator_to_next (it
, 0);
6102 /* Don't handle selective display in the following. It's (a)
6103 unnecessary because it's done by the caller, and (b) leads to an
6104 infinite recursion because next_element_from_ellipsis indirectly
6105 calls this function. */
6106 old_selective
= it
->selective
;
6109 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
6110 from buffer text. */
6111 for (n
= newline_found_p
= 0;
6112 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
6113 n
+= STRINGP (it
->string
) ? 0 : 1)
6115 if (!get_next_display_element (it
))
6117 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
6118 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
6119 *bidi_it_prev
= it
->bidi_it
;
6120 set_iterator_to_next (it
, 0);
6123 /* If we didn't find a newline near enough, see if we can use a
6125 if (!newline_found_p
)
6127 ptrdiff_t bytepos
, start
= IT_CHARPOS (*it
);
6128 ptrdiff_t limit
= find_newline_no_quit (start
, IT_BYTEPOS (*it
),
6132 eassert (!STRINGP (it
->string
));
6134 /* If there isn't any `display' property in sight, and no
6135 overlays, we can just use the position of the newline in
6137 if (it
->stop_charpos
>= limit
6138 || ((pos
= Fnext_single_property_change (make_number (start
),
6140 make_number (limit
)),
6142 && next_overlay_change (start
) == ZV
))
6146 IT_CHARPOS (*it
) = limit
;
6147 IT_BYTEPOS (*it
) = bytepos
;
6151 struct bidi_it bprev
;
6153 /* Help bidi.c avoid expensive searches for display
6154 properties and overlays, by telling it that there are
6155 none up to `limit'. */
6156 if (it
->bidi_it
.disp_pos
< limit
)
6158 it
->bidi_it
.disp_pos
= limit
;
6159 it
->bidi_it
.disp_prop
= 0;
6162 bprev
= it
->bidi_it
;
6163 bidi_move_to_visually_next (&it
->bidi_it
);
6164 } while (it
->bidi_it
.charpos
!= limit
);
6165 IT_CHARPOS (*it
) = limit
;
6166 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6168 *bidi_it_prev
= bprev
;
6170 *skipped_p
= newline_found_p
= 1;
6174 while (get_next_display_element (it
)
6175 && !newline_found_p
)
6177 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
6178 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
6179 *bidi_it_prev
= it
->bidi_it
;
6180 set_iterator_to_next (it
, 0);
6185 it
->selective
= old_selective
;
6186 return newline_found_p
;
6190 /* Set IT's current position to the previous visible line start. Skip
6191 invisible text that is so either due to text properties or due to
6192 selective display. Caution: this does not change IT->current_x and
6196 back_to_previous_visible_line_start (struct it
*it
)
6198 while (IT_CHARPOS (*it
) > BEGV
)
6200 back_to_previous_line_start (it
);
6202 if (IT_CHARPOS (*it
) <= BEGV
)
6205 /* If selective > 0, then lines indented more than its value are
6207 if (it
->selective
> 0
6208 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6212 /* Check the newline before point for invisibility. */
6215 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
6216 Qinvisible
, it
->window
);
6217 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
6221 if (IT_CHARPOS (*it
) <= BEGV
)
6226 void *it2data
= NULL
;
6229 Lisp_Object val
, overlay
;
6231 SAVE_IT (it2
, *it
, it2data
);
6233 /* If newline is part of a composition, continue from start of composition */
6234 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
6235 && beg
< IT_CHARPOS (*it
))
6238 /* If newline is replaced by a display property, find start of overlay
6239 or interval and continue search from that point. */
6240 pos
= --IT_CHARPOS (it2
);
6243 bidi_unshelve_cache (NULL
, 0);
6244 it2
.string_from_display_prop_p
= 0;
6245 it2
.from_disp_prop_p
= 0;
6246 if (handle_display_prop (&it2
) == HANDLED_RETURN
6247 && !NILP (val
= get_char_property_and_overlay
6248 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
6249 && (OVERLAYP (overlay
)
6250 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
6251 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
6253 RESTORE_IT (it
, it
, it2data
);
6257 /* Newline is not replaced by anything -- so we are done. */
6258 RESTORE_IT (it
, it
, it2data
);
6264 IT_CHARPOS (*it
) = beg
;
6265 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
6269 it
->continuation_lines_width
= 0;
6271 eassert (IT_CHARPOS (*it
) >= BEGV
);
6272 eassert (IT_CHARPOS (*it
) == BEGV
6273 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6278 /* Reseat iterator IT at the previous visible line start. Skip
6279 invisible text that is so either due to text properties or due to
6280 selective display. At the end, update IT's overlay information,
6281 face information etc. */
6284 reseat_at_previous_visible_line_start (struct it
*it
)
6286 back_to_previous_visible_line_start (it
);
6287 reseat (it
, it
->current
.pos
, 1);
6292 /* Reseat iterator IT on the next visible line start in the current
6293 buffer. ON_NEWLINE_P non-zero means position IT on the newline
6294 preceding the line start. Skip over invisible text that is so
6295 because of selective display. Compute faces, overlays etc at the
6296 new position. Note that this function does not skip over text that
6297 is invisible because of text properties. */
6300 reseat_at_next_visible_line_start (struct it
*it
, int on_newline_p
)
6302 int newline_found_p
, skipped_p
= 0;
6303 struct bidi_it bidi_it_prev
;
6305 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6307 /* Skip over lines that are invisible because they are indented
6308 more than the value of IT->selective. */
6309 if (it
->selective
> 0)
6310 while (IT_CHARPOS (*it
) < ZV
6311 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6314 eassert (IT_BYTEPOS (*it
) == BEGV
6315 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6317 forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6320 /* Position on the newline if that's what's requested. */
6321 if (on_newline_p
&& newline_found_p
)
6323 if (STRINGP (it
->string
))
6325 if (IT_STRING_CHARPOS (*it
) > 0)
6329 --IT_STRING_CHARPOS (*it
);
6330 --IT_STRING_BYTEPOS (*it
);
6334 /* We need to restore the bidi iterator to the state
6335 it had on the newline, and resync the IT's
6336 position with that. */
6337 it
->bidi_it
= bidi_it_prev
;
6338 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6339 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6343 else if (IT_CHARPOS (*it
) > BEGV
)
6352 /* We need to restore the bidi iterator to the state it
6353 had on the newline and resync IT with that. */
6354 it
->bidi_it
= bidi_it_prev
;
6355 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6356 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6358 reseat (it
, it
->current
.pos
, 0);
6362 reseat (it
, it
->current
.pos
, 0);
6369 /***********************************************************************
6370 Changing an iterator's position
6371 ***********************************************************************/
6373 /* Change IT's current position to POS in current_buffer. If FORCE_P
6374 is non-zero, always check for text properties at the new position.
6375 Otherwise, text properties are only looked up if POS >=
6376 IT->check_charpos of a property. */
6379 reseat (struct it
*it
, struct text_pos pos
, int force_p
)
6381 ptrdiff_t original_pos
= IT_CHARPOS (*it
);
6383 reseat_1 (it
, pos
, 0);
6385 /* Determine where to check text properties. Avoid doing it
6386 where possible because text property lookup is very expensive. */
6388 || CHARPOS (pos
) > it
->stop_charpos
6389 || CHARPOS (pos
) < original_pos
)
6393 /* For bidi iteration, we need to prime prev_stop and
6394 base_level_stop with our best estimations. */
6395 /* Implementation note: Of course, POS is not necessarily a
6396 stop position, so assigning prev_pos to it is a lie; we
6397 should have called compute_stop_backwards. However, if
6398 the current buffer does not include any R2L characters,
6399 that call would be a waste of cycles, because the
6400 iterator will never move back, and thus never cross this
6401 "fake" stop position. So we delay that backward search
6402 until the time we really need it, in next_element_from_buffer. */
6403 if (CHARPOS (pos
) != it
->prev_stop
)
6404 it
->prev_stop
= CHARPOS (pos
);
6405 if (CHARPOS (pos
) < it
->base_level_stop
)
6406 it
->base_level_stop
= 0; /* meaning it's unknown */
6412 it
->prev_stop
= it
->base_level_stop
= 0;
6421 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
6422 IT->stop_pos to POS, also. */
6425 reseat_1 (struct it
*it
, struct text_pos pos
, int set_stop_p
)
6427 /* Don't call this function when scanning a C string. */
6428 eassert (it
->s
== NULL
);
6430 /* POS must be a reasonable value. */
6431 eassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
6433 it
->current
.pos
= it
->position
= pos
;
6434 it
->end_charpos
= ZV
;
6436 it
->current
.dpvec_index
= -1;
6437 it
->current
.overlay_string_index
= -1;
6438 IT_STRING_CHARPOS (*it
) = -1;
6439 IT_STRING_BYTEPOS (*it
) = -1;
6441 it
->method
= GET_FROM_BUFFER
;
6442 it
->object
= it
->w
->contents
;
6443 it
->area
= TEXT_AREA
;
6444 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
6446 it
->string_from_display_prop_p
= 0;
6447 it
->string_from_prefix_prop_p
= 0;
6449 it
->from_disp_prop_p
= 0;
6450 it
->face_before_selective_p
= 0;
6453 bidi_init_it (IT_CHARPOS (*it
), IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6455 bidi_unshelve_cache (NULL
, 0);
6456 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6457 it
->bidi_it
.string
.s
= NULL
;
6458 it
->bidi_it
.string
.lstring
= Qnil
;
6459 it
->bidi_it
.string
.bufpos
= 0;
6460 it
->bidi_it
.string
.unibyte
= 0;
6461 it
->bidi_it
.w
= it
->w
;
6466 it
->stop_charpos
= CHARPOS (pos
);
6467 it
->base_level_stop
= CHARPOS (pos
);
6469 /* This make the information stored in it->cmp_it invalidate. */
6474 /* Set up IT for displaying a string, starting at CHARPOS in window W.
6475 If S is non-null, it is a C string to iterate over. Otherwise,
6476 STRING gives a Lisp string to iterate over.
6478 If PRECISION > 0, don't return more then PRECISION number of
6479 characters from the string.
6481 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
6482 characters have been returned. FIELD_WIDTH < 0 means an infinite
6485 MULTIBYTE = 0 means disable processing of multibyte characters,
6486 MULTIBYTE > 0 means enable it,
6487 MULTIBYTE < 0 means use IT->multibyte_p.
6489 IT must be initialized via a prior call to init_iterator before
6490 calling this function. */
6493 reseat_to_string (struct it
*it
, const char *s
, Lisp_Object string
,
6494 ptrdiff_t charpos
, ptrdiff_t precision
, int field_width
,
6497 /* No region in strings. */
6498 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
6500 /* No text property checks performed by default, but see below. */
6501 it
->stop_charpos
= -1;
6503 /* Set iterator position and end position. */
6504 memset (&it
->current
, 0, sizeof it
->current
);
6505 it
->current
.overlay_string_index
= -1;
6506 it
->current
.dpvec_index
= -1;
6507 eassert (charpos
>= 0);
6509 /* If STRING is specified, use its multibyteness, otherwise use the
6510 setting of MULTIBYTE, if specified. */
6512 it
->multibyte_p
= multibyte
> 0;
6514 /* Bidirectional reordering of strings is controlled by the default
6515 value of bidi-display-reordering. Don't try to reorder while
6516 loading loadup.el, as the necessary character property tables are
6517 not yet available. */
6520 && !NILP (BVAR (&buffer_defaults
, bidi_display_reordering
));
6524 eassert (STRINGP (string
));
6525 it
->string
= string
;
6527 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
6528 it
->method
= GET_FROM_STRING
;
6529 it
->current
.string_pos
= string_pos (charpos
, string
);
6533 it
->bidi_it
.string
.lstring
= string
;
6534 it
->bidi_it
.string
.s
= NULL
;
6535 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6536 it
->bidi_it
.string
.bufpos
= 0;
6537 it
->bidi_it
.string
.from_disp_str
= 0;
6538 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6539 it
->bidi_it
.w
= it
->w
;
6540 bidi_init_it (charpos
, IT_STRING_BYTEPOS (*it
),
6541 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
6546 it
->s
= (const unsigned char *) s
;
6549 /* Note that we use IT->current.pos, not it->current.string_pos,
6550 for displaying C strings. */
6551 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
6552 if (it
->multibyte_p
)
6554 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
6555 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
6559 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
6560 it
->end_charpos
= it
->string_nchars
= strlen (s
);
6565 it
->bidi_it
.string
.lstring
= Qnil
;
6566 it
->bidi_it
.string
.s
= (const unsigned char *) s
;
6567 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6568 it
->bidi_it
.string
.bufpos
= 0;
6569 it
->bidi_it
.string
.from_disp_str
= 0;
6570 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6571 it
->bidi_it
.w
= it
->w
;
6572 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6575 it
->method
= GET_FROM_C_STRING
;
6578 /* PRECISION > 0 means don't return more than PRECISION characters
6580 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
6582 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
6584 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6587 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
6588 characters have been returned. FIELD_WIDTH == 0 means don't pad,
6589 FIELD_WIDTH < 0 means infinite field width. This is useful for
6590 padding with `-' at the end of a mode line. */
6591 if (field_width
< 0)
6592 field_width
= INFINITY
;
6593 /* Implementation note: We deliberately don't enlarge
6594 it->bidi_it.string.schars here to fit it->end_charpos, because
6595 the bidi iterator cannot produce characters out of thin air. */
6596 if (field_width
> it
->end_charpos
- charpos
)
6597 it
->end_charpos
= charpos
+ field_width
;
6599 /* Use the standard display table for displaying strings. */
6600 if (DISP_TABLE_P (Vstandard_display_table
))
6601 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
6603 it
->stop_charpos
= charpos
;
6604 it
->prev_stop
= charpos
;
6605 it
->base_level_stop
= 0;
6608 it
->bidi_it
.first_elt
= 1;
6609 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6610 it
->bidi_it
.disp_pos
= -1;
6612 if (s
== NULL
&& it
->multibyte_p
)
6614 ptrdiff_t endpos
= SCHARS (it
->string
);
6615 if (endpos
> it
->end_charpos
)
6616 endpos
= it
->end_charpos
;
6617 composition_compute_stop_pos (&it
->cmp_it
, charpos
, -1, endpos
,
6625 /***********************************************************************
6627 ***********************************************************************/
6629 /* Map enum it_method value to corresponding next_element_from_* function. */
6631 static int (* get_next_element
[NUM_IT_METHODS
]) (struct it
*it
) =
6633 next_element_from_buffer
,
6634 next_element_from_display_vector
,
6635 next_element_from_string
,
6636 next_element_from_c_string
,
6637 next_element_from_image
,
6638 next_element_from_stretch
6639 #ifdef HAVE_XWIDGETS
6640 ,next_element_from_xwidget
6644 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
6647 /* Return 1 iff a character at CHARPOS (and BYTEPOS) is composed
6648 (possibly with the following characters). */
6650 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS,END_CHARPOS) \
6651 ((IT)->cmp_it.id >= 0 \
6652 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
6653 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
6654 END_CHARPOS, (IT)->w, \
6655 FACE_FROM_ID ((IT)->f, (IT)->face_id), \
6659 /* Lookup the char-table Vglyphless_char_display for character C (-1
6660 if we want information for no-font case), and return the display
6661 method symbol. By side-effect, update it->what and
6662 it->glyphless_method. This function is called from
6663 get_next_display_element for each character element, and from
6664 x_produce_glyphs when no suitable font was found. */
6667 lookup_glyphless_char_display (int c
, struct it
*it
)
6669 Lisp_Object glyphless_method
= Qnil
;
6671 if (CHAR_TABLE_P (Vglyphless_char_display
)
6672 && CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
)) >= 1)
6676 glyphless_method
= CHAR_TABLE_REF (Vglyphless_char_display
, c
);
6677 if (CONSP (glyphless_method
))
6678 glyphless_method
= FRAME_WINDOW_P (it
->f
)
6679 ? XCAR (glyphless_method
)
6680 : XCDR (glyphless_method
);
6683 glyphless_method
= XCHAR_TABLE (Vglyphless_char_display
)->extras
[0];
6687 if (NILP (glyphless_method
))
6690 /* The default is to display the character by a proper font. */
6692 /* The default for the no-font case is to display an empty box. */
6693 glyphless_method
= Qempty_box
;
6695 if (EQ (glyphless_method
, Qzero_width
))
6698 return glyphless_method
;
6699 /* This method can't be used for the no-font case. */
6700 glyphless_method
= Qempty_box
;
6702 if (EQ (glyphless_method
, Qthin_space
))
6703 it
->glyphless_method
= GLYPHLESS_DISPLAY_THIN_SPACE
;
6704 else if (EQ (glyphless_method
, Qempty_box
))
6705 it
->glyphless_method
= GLYPHLESS_DISPLAY_EMPTY_BOX
;
6706 else if (EQ (glyphless_method
, Qhex_code
))
6707 it
->glyphless_method
= GLYPHLESS_DISPLAY_HEX_CODE
;
6708 else if (STRINGP (glyphless_method
))
6709 it
->glyphless_method
= GLYPHLESS_DISPLAY_ACRONYM
;
6712 /* Invalid value. We use the default method. */
6713 glyphless_method
= Qnil
;
6716 it
->what
= IT_GLYPHLESS
;
6717 return glyphless_method
;
6720 /* Load IT's display element fields with information about the next
6721 display element from the current position of IT. Value is zero if
6722 end of buffer (or C string) is reached. */
6724 static struct frame
*last_escape_glyph_frame
= NULL
;
6725 static int last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
6726 static int last_escape_glyph_merged_face_id
= 0;
6728 struct frame
*last_glyphless_glyph_frame
= NULL
;
6729 int last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
6730 int last_glyphless_glyph_merged_face_id
= 0;
6733 get_next_display_element (struct it
*it
)
6735 /* Non-zero means that we found a display element. Zero means that
6736 we hit the end of what we iterate over. Performance note: the
6737 function pointer `method' used here turns out to be faster than
6738 using a sequence of if-statements. */
6742 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6744 if (it
->what
== IT_CHARACTER
)
6746 /* UAX#9, L4: "A character is depicted by a mirrored glyph if
6747 and only if (a) the resolved directionality of that character
6749 /* FIXME: Do we need an exception for characters from display
6751 if (it
->bidi_p
&& it
->bidi_it
.type
== STRONG_R
)
6752 it
->c
= bidi_mirror_char (it
->c
);
6753 /* Map via display table or translate control characters.
6754 IT->c, IT->len etc. have been set to the next character by
6755 the function call above. If we have a display table, and it
6756 contains an entry for IT->c, translate it. Don't do this if
6757 IT->c itself comes from a display table, otherwise we could
6758 end up in an infinite recursion. (An alternative could be to
6759 count the recursion depth of this function and signal an
6760 error when a certain maximum depth is reached.) Is it worth
6762 if (success_p
&& it
->dpvec
== NULL
)
6765 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
6766 int nonascii_space_p
= 0;
6767 int nonascii_hyphen_p
= 0;
6768 int c
= it
->c
; /* This is the character to display. */
6770 if (! it
->multibyte_p
&& ! ASCII_CHAR_P (c
))
6772 eassert (SINGLE_BYTE_CHAR_P (c
));
6773 if (unibyte_display_via_language_environment
)
6775 c
= DECODE_CHAR (unibyte
, c
);
6777 c
= BYTE8_TO_CHAR (it
->c
);
6780 c
= BYTE8_TO_CHAR (it
->c
);
6784 && (dv
= DISP_CHAR_VECTOR (it
->dp
, c
),
6787 struct Lisp_Vector
*v
= XVECTOR (dv
);
6789 /* Return the first character from the display table
6790 entry, if not empty. If empty, don't display the
6791 current character. */
6794 it
->dpvec_char_len
= it
->len
;
6795 it
->dpvec
= v
->contents
;
6796 it
->dpend
= v
->contents
+ v
->header
.size
;
6797 it
->current
.dpvec_index
= 0;
6798 it
->dpvec_face_id
= -1;
6799 it
->saved_face_id
= it
->face_id
;
6800 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6805 set_iterator_to_next (it
, 0);
6810 if (! NILP (lookup_glyphless_char_display (c
, it
)))
6812 if (it
->what
== IT_GLYPHLESS
)
6814 /* Don't display this character. */
6815 set_iterator_to_next (it
, 0);
6819 /* If `nobreak-char-display' is non-nil, we display
6820 non-ASCII spaces and hyphens specially. */
6821 if (! ASCII_CHAR_P (c
) && ! NILP (Vnobreak_char_display
))
6824 nonascii_space_p
= 1;
6825 else if (c
== 0xAD || c
== 0x2010 || c
== 0x2011)
6826 nonascii_hyphen_p
= 1;
6829 /* Translate control characters into `\003' or `^C' form.
6830 Control characters coming from a display table entry are
6831 currently not translated because we use IT->dpvec to hold
6832 the translation. This could easily be changed but I
6833 don't believe that it is worth doing.
6835 The characters handled by `nobreak-char-display' must be
6838 Non-printable characters and raw-byte characters are also
6839 translated to octal form. */
6840 if (((c
< ' ' || c
== 127) /* ASCII control chars */
6841 ? (it
->area
!= TEXT_AREA
6842 /* In mode line, treat \n, \t like other crl chars. */
6845 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
6846 || (c
!= '\n' && c
!= '\t'))
6848 || nonascii_hyphen_p
6850 || ! CHAR_PRINTABLE_P (c
))))
6852 /* C is a control character, non-ASCII space/hyphen,
6853 raw-byte, or a non-printable character which must be
6854 displayed either as '\003' or as `^C' where the '\\'
6855 and '^' can be defined in the display table. Fill
6856 IT->ctl_chars with glyphs for what we have to
6857 display. Then, set IT->dpvec to these glyphs. */
6864 /* Handle control characters with ^. */
6866 if (ASCII_CHAR_P (c
) && it
->ctl_arrow_p
)
6870 g
= '^'; /* default glyph for Control */
6871 /* Set IT->ctl_chars[0] to the glyph for `^'. */
6873 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
6875 g
= GLYPH_CODE_CHAR (gc
);
6876 lface_id
= GLYPH_CODE_FACE (gc
);
6880 face_id
= merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
);
6882 else if (it
->f
== last_escape_glyph_frame
6883 && it
->face_id
== last_escape_glyph_face_id
)
6885 face_id
= last_escape_glyph_merged_face_id
;
6889 /* Merge the escape-glyph face into the current face. */
6890 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
6892 last_escape_glyph_frame
= it
->f
;
6893 last_escape_glyph_face_id
= it
->face_id
;
6894 last_escape_glyph_merged_face_id
= face_id
;
6897 XSETINT (it
->ctl_chars
[0], g
);
6898 XSETINT (it
->ctl_chars
[1], c
^ 0100);
6900 goto display_control
;
6903 /* Handle non-ascii space in the mode where it only gets
6906 if (nonascii_space_p
&& EQ (Vnobreak_char_display
, Qt
))
6908 /* Merge `nobreak-space' into the current face. */
6909 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
6911 XSETINT (it
->ctl_chars
[0], ' ');
6913 goto display_control
;
6916 /* Handle sequences that start with the "escape glyph". */
6918 /* the default escape glyph is \. */
6919 escape_glyph
= '\\';
6922 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
6924 escape_glyph
= GLYPH_CODE_CHAR (gc
);
6925 lface_id
= GLYPH_CODE_FACE (gc
);
6929 /* The display table specified a face.
6930 Merge it into face_id and also into escape_glyph. */
6931 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6934 else if (it
->f
== last_escape_glyph_frame
6935 && it
->face_id
== last_escape_glyph_face_id
)
6937 face_id
= last_escape_glyph_merged_face_id
;
6941 /* Merge the escape-glyph face into the current face. */
6942 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
6944 last_escape_glyph_frame
= it
->f
;
6945 last_escape_glyph_face_id
= it
->face_id
;
6946 last_escape_glyph_merged_face_id
= face_id
;
6949 /* Draw non-ASCII hyphen with just highlighting: */
6951 if (nonascii_hyphen_p
&& EQ (Vnobreak_char_display
, Qt
))
6953 XSETINT (it
->ctl_chars
[0], '-');
6955 goto display_control
;
6958 /* Draw non-ASCII space/hyphen with escape glyph: */
6960 if (nonascii_space_p
|| nonascii_hyphen_p
)
6962 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6963 XSETINT (it
->ctl_chars
[1], nonascii_space_p
? ' ' : '-');
6965 goto display_control
;
6972 if (CHAR_BYTE8_P (c
))
6973 /* Display \200 instead of \17777600. */
6974 c
= CHAR_TO_BYTE8 (c
);
6975 len
= sprintf (str
, "%03o", c
);
6977 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6978 for (i
= 0; i
< len
; i
++)
6979 XSETINT (it
->ctl_chars
[i
+ 1], str
[i
]);
6984 /* Set up IT->dpvec and return first character from it. */
6985 it
->dpvec_char_len
= it
->len
;
6986 it
->dpvec
= it
->ctl_chars
;
6987 it
->dpend
= it
->dpvec
+ ctl_len
;
6988 it
->current
.dpvec_index
= 0;
6989 it
->dpvec_face_id
= face_id
;
6990 it
->saved_face_id
= it
->face_id
;
6991 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6995 it
->char_to_display
= c
;
6999 it
->char_to_display
= it
->c
;
7003 /* Adjust face id for a multibyte character. There are no multibyte
7004 character in unibyte text. */
7005 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
7008 && FRAME_WINDOW_P (it
->f
))
7010 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
7012 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
7014 /* Automatic composition with glyph-string. */
7015 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
7017 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
7021 ptrdiff_t pos
= (it
->s
? -1
7022 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
7023 : IT_CHARPOS (*it
));
7026 if (it
->what
== IT_CHARACTER
)
7027 c
= it
->char_to_display
;
7030 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
7034 for (i
= 0; i
< cmp
->glyph_len
; i
++)
7035 /* TAB in a composition means display glyphs with
7036 padding space on the left or right. */
7037 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
7040 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, pos
, it
->string
);
7045 /* Is this character the last one of a run of characters with
7046 box? If yes, set IT->end_of_box_run_p to 1. */
7050 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
7052 int face_id
= underlying_face_id (it
);
7053 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
7057 if (face
->box
== FACE_NO_BOX
)
7059 /* If the box comes from face properties in a
7060 display string, check faces in that string. */
7061 int string_face_id
= face_after_it_pos (it
);
7062 it
->end_of_box_run_p
7063 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
7066 /* Otherwise, the box comes from the underlying face.
7067 If this is the last string character displayed, check
7068 the next buffer location. */
7069 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
7070 && (it
->current
.overlay_string_index
7071 == it
->n_overlay_strings
- 1))
7075 struct text_pos pos
= it
->current
.pos
;
7076 INC_TEXT_POS (pos
, it
->multibyte_p
);
7078 next_face_id
= face_at_buffer_position
7079 (it
->w
, CHARPOS (pos
), it
->region_beg_charpos
,
7080 it
->region_end_charpos
, &ignore
,
7081 (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
), 0,
7083 it
->end_of_box_run_p
7084 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
7091 int face_id
= face_after_it_pos (it
);
7092 it
->end_of_box_run_p
7093 = (face_id
!= it
->face_id
7094 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
7097 /* If we reached the end of the object we've been iterating (e.g., a
7098 display string or an overlay string), and there's something on
7099 IT->stack, proceed with what's on the stack. It doesn't make
7100 sense to return zero if there's unprocessed stuff on the stack,
7101 because otherwise that stuff will never be displayed. */
7102 if (!success_p
&& it
->sp
> 0)
7104 set_iterator_to_next (it
, 0);
7105 success_p
= get_next_display_element (it
);
7108 /* Value is 0 if end of buffer or string reached. */
7113 /* Move IT to the next display element.
7115 RESEAT_P non-zero means if called on a newline in buffer text,
7116 skip to the next visible line start.
7118 Functions get_next_display_element and set_iterator_to_next are
7119 separate because I find this arrangement easier to handle than a
7120 get_next_display_element function that also increments IT's
7121 position. The way it is we can first look at an iterator's current
7122 display element, decide whether it fits on a line, and if it does,
7123 increment the iterator position. The other way around we probably
7124 would either need a flag indicating whether the iterator has to be
7125 incremented the next time, or we would have to implement a
7126 decrement position function which would not be easy to write. */
7129 set_iterator_to_next (struct it
*it
, int reseat_p
)
7131 /* Reset flags indicating start and end of a sequence of characters
7132 with box. Reset them at the start of this function because
7133 moving the iterator to a new position might set them. */
7134 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
7138 case GET_FROM_BUFFER
:
7139 /* The current display element of IT is a character from
7140 current_buffer. Advance in the buffer, and maybe skip over
7141 invisible lines that are so because of selective display. */
7142 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
7143 reseat_at_next_visible_line_start (it
, 0);
7144 else if (it
->cmp_it
.id
>= 0)
7146 /* We are currently getting glyphs from a composition. */
7151 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7152 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7153 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7155 it
->cmp_it
.from
= it
->cmp_it
.to
;
7160 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7162 it
->end_charpos
, Qnil
);
7165 else if (! it
->cmp_it
.reversed_p
)
7167 /* Composition created while scanning forward. */
7168 /* Update IT's char/byte positions to point to the first
7169 character of the next grapheme cluster, or to the
7170 character visually after the current composition. */
7171 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7172 bidi_move_to_visually_next (&it
->bidi_it
);
7173 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7174 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7176 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7178 /* Proceed to the next grapheme cluster. */
7179 it
->cmp_it
.from
= it
->cmp_it
.to
;
7183 /* No more grapheme clusters in this composition.
7184 Find the next stop position. */
7185 ptrdiff_t stop
= it
->end_charpos
;
7186 if (it
->bidi_it
.scan_dir
< 0)
7187 /* Now we are scanning backward and don't know
7190 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7191 IT_BYTEPOS (*it
), stop
, Qnil
);
7196 /* Composition created while scanning backward. */
7197 /* Update IT's char/byte positions to point to the last
7198 character of the previous grapheme cluster, or the
7199 character visually after the current composition. */
7200 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7201 bidi_move_to_visually_next (&it
->bidi_it
);
7202 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7203 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7204 if (it
->cmp_it
.from
> 0)
7206 /* Proceed to the previous grapheme cluster. */
7207 it
->cmp_it
.to
= it
->cmp_it
.from
;
7211 /* No more grapheme clusters in this composition.
7212 Find the next stop position. */
7213 ptrdiff_t stop
= it
->end_charpos
;
7214 if (it
->bidi_it
.scan_dir
< 0)
7215 /* Now we are scanning backward and don't know
7218 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7219 IT_BYTEPOS (*it
), stop
, Qnil
);
7225 eassert (it
->len
!= 0);
7229 IT_BYTEPOS (*it
) += it
->len
;
7230 IT_CHARPOS (*it
) += 1;
7234 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7235 /* If this is a new paragraph, determine its base
7236 direction (a.k.a. its base embedding level). */
7237 if (it
->bidi_it
.new_paragraph
)
7238 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
7239 bidi_move_to_visually_next (&it
->bidi_it
);
7240 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7241 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7242 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7244 /* As the scan direction was changed, we must
7245 re-compute the stop position for composition. */
7246 ptrdiff_t stop
= it
->end_charpos
;
7247 if (it
->bidi_it
.scan_dir
< 0)
7249 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7250 IT_BYTEPOS (*it
), stop
, Qnil
);
7253 eassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
7257 case GET_FROM_C_STRING
:
7258 /* Current display element of IT is from a C string. */
7260 /* If the string position is beyond string's end, it means
7261 next_element_from_c_string is padding the string with
7262 blanks, in which case we bypass the bidi iterator,
7263 because it cannot deal with such virtual characters. */
7264 || IT_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7266 IT_BYTEPOS (*it
) += it
->len
;
7267 IT_CHARPOS (*it
) += 1;
7271 bidi_move_to_visually_next (&it
->bidi_it
);
7272 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7273 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7277 case GET_FROM_DISPLAY_VECTOR
:
7278 /* Current display element of IT is from a display table entry.
7279 Advance in the display table definition. Reset it to null if
7280 end reached, and continue with characters from buffers/
7282 ++it
->current
.dpvec_index
;
7284 /* Restore face of the iterator to what they were before the
7285 display vector entry (these entries may contain faces). */
7286 it
->face_id
= it
->saved_face_id
;
7288 if (it
->dpvec
+ it
->current
.dpvec_index
>= it
->dpend
)
7290 int recheck_faces
= it
->ellipsis_p
;
7293 it
->method
= GET_FROM_C_STRING
;
7294 else if (STRINGP (it
->string
))
7295 it
->method
= GET_FROM_STRING
;
7298 it
->method
= GET_FROM_BUFFER
;
7299 it
->object
= it
->w
->contents
;
7303 it
->current
.dpvec_index
= -1;
7305 /* Skip over characters which were displayed via IT->dpvec. */
7306 if (it
->dpvec_char_len
< 0)
7307 reseat_at_next_visible_line_start (it
, 1);
7308 else if (it
->dpvec_char_len
> 0)
7310 if (it
->method
== GET_FROM_STRING
7311 && it
->current
.overlay_string_index
>= 0
7312 && it
->n_overlay_strings
> 0)
7313 it
->ignore_overlay_strings_at_pos_p
= 1;
7314 it
->len
= it
->dpvec_char_len
;
7315 set_iterator_to_next (it
, reseat_p
);
7318 /* Maybe recheck faces after display vector */
7320 it
->stop_charpos
= IT_CHARPOS (*it
);
7324 case GET_FROM_STRING
:
7325 /* Current display element is a character from a Lisp string. */
7326 eassert (it
->s
== NULL
&& STRINGP (it
->string
));
7327 /* Don't advance past string end. These conditions are true
7328 when set_iterator_to_next is called at the end of
7329 get_next_display_element, in which case the Lisp string is
7330 already exhausted, and all we want is pop the iterator
7332 if (it
->current
.overlay_string_index
>= 0)
7334 /* This is an overlay string, so there's no padding with
7335 spaces, and the number of characters in the string is
7336 where the string ends. */
7337 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7338 goto consider_string_end
;
7342 /* Not an overlay string. There could be padding, so test
7343 against it->end_charpos . */
7344 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7345 goto consider_string_end
;
7347 if (it
->cmp_it
.id
>= 0)
7353 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7354 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7355 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7356 it
->cmp_it
.from
= it
->cmp_it
.to
;
7360 composition_compute_stop_pos (&it
->cmp_it
,
7361 IT_STRING_CHARPOS (*it
),
7362 IT_STRING_BYTEPOS (*it
),
7363 it
->end_charpos
, it
->string
);
7366 else if (! it
->cmp_it
.reversed_p
)
7368 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7369 bidi_move_to_visually_next (&it
->bidi_it
);
7370 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7371 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7373 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7374 it
->cmp_it
.from
= it
->cmp_it
.to
;
7377 ptrdiff_t stop
= it
->end_charpos
;
7378 if (it
->bidi_it
.scan_dir
< 0)
7380 composition_compute_stop_pos (&it
->cmp_it
,
7381 IT_STRING_CHARPOS (*it
),
7382 IT_STRING_BYTEPOS (*it
), stop
,
7388 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7389 bidi_move_to_visually_next (&it
->bidi_it
);
7390 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7391 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7392 if (it
->cmp_it
.from
> 0)
7393 it
->cmp_it
.to
= it
->cmp_it
.from
;
7396 ptrdiff_t stop
= it
->end_charpos
;
7397 if (it
->bidi_it
.scan_dir
< 0)
7399 composition_compute_stop_pos (&it
->cmp_it
,
7400 IT_STRING_CHARPOS (*it
),
7401 IT_STRING_BYTEPOS (*it
), stop
,
7409 /* If the string position is beyond string's end, it
7410 means next_element_from_string is padding the string
7411 with blanks, in which case we bypass the bidi
7412 iterator, because it cannot deal with such virtual
7414 || IT_STRING_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7416 IT_STRING_BYTEPOS (*it
) += it
->len
;
7417 IT_STRING_CHARPOS (*it
) += 1;
7421 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7423 bidi_move_to_visually_next (&it
->bidi_it
);
7424 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7425 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7426 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7428 ptrdiff_t stop
= it
->end_charpos
;
7430 if (it
->bidi_it
.scan_dir
< 0)
7432 composition_compute_stop_pos (&it
->cmp_it
,
7433 IT_STRING_CHARPOS (*it
),
7434 IT_STRING_BYTEPOS (*it
), stop
,
7440 consider_string_end
:
7442 if (it
->current
.overlay_string_index
>= 0)
7444 /* IT->string is an overlay string. Advance to the
7445 next, if there is one. */
7446 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7449 next_overlay_string (it
);
7451 setup_for_ellipsis (it
, 0);
7456 /* IT->string is not an overlay string. If we reached
7457 its end, and there is something on IT->stack, proceed
7458 with what is on the stack. This can be either another
7459 string, this time an overlay string, or a buffer. */
7460 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
7464 if (it
->method
== GET_FROM_STRING
)
7465 goto consider_string_end
;
7470 case GET_FROM_IMAGE
:
7471 case GET_FROM_STRETCH
:
7472 #ifdef HAVE_XWIDGETS
7473 case GET_FROM_XWIDGET
:
7475 /* The position etc with which we have to proceed are on
7476 the stack. The position may be at the end of a string,
7477 if the `display' property takes up the whole string. */
7478 eassert (it
->sp
> 0);
7480 if (it
->method
== GET_FROM_STRING
)
7481 goto consider_string_end
;
7485 /* There are no other methods defined, so this should be a bug. */
7489 eassert (it
->method
!= GET_FROM_STRING
7490 || (STRINGP (it
->string
)
7491 && IT_STRING_CHARPOS (*it
) >= 0));
7494 /* Load IT's display element fields with information about the next
7495 display element which comes from a display table entry or from the
7496 result of translating a control character to one of the forms `^C'
7499 IT->dpvec holds the glyphs to return as characters.
7500 IT->saved_face_id holds the face id before the display vector--it
7501 is restored into IT->face_id in set_iterator_to_next. */
7504 next_element_from_display_vector (struct it
*it
)
7507 int prev_face_id
= it
->face_id
;
7511 eassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
7513 it
->face_id
= it
->saved_face_id
;
7515 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
7516 That seemed totally bogus - so I changed it... */
7517 gc
= it
->dpvec
[it
->current
.dpvec_index
];
7519 if (GLYPH_CODE_P (gc
))
7521 struct face
*this_face
, *prev_face
, *next_face
;
7523 it
->c
= GLYPH_CODE_CHAR (gc
);
7524 it
->len
= CHAR_BYTES (it
->c
);
7526 /* The entry may contain a face id to use. Such a face id is
7527 the id of a Lisp face, not a realized face. A face id of
7528 zero means no face is specified. */
7529 if (it
->dpvec_face_id
>= 0)
7530 it
->face_id
= it
->dpvec_face_id
;
7533 int lface_id
= GLYPH_CODE_FACE (gc
);
7535 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
7539 /* Glyphs in the display vector could have the box face, so we
7540 need to set the related flags in the iterator, as
7542 this_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
7543 prev_face
= FACE_FROM_ID (it
->f
, prev_face_id
);
7545 /* Is this character the first character of a box-face run? */
7546 it
->start_of_box_run_p
= (this_face
&& this_face
->box
!= FACE_NO_BOX
7548 || prev_face
->box
== FACE_NO_BOX
));
7550 /* For the last character of the box-face run, we need to look
7551 either at the next glyph from the display vector, or at the
7552 face we saw before the display vector. */
7553 next_face_id
= it
->saved_face_id
;
7554 if (it
->current
.dpvec_index
< it
->dpend
- it
->dpvec
- 1)
7556 if (it
->dpvec_face_id
>= 0)
7557 next_face_id
= it
->dpvec_face_id
;
7561 GLYPH_CODE_FACE (it
->dpvec
[it
->current
.dpvec_index
+ 1]);
7564 next_face_id
= merge_faces (it
->f
, Qt
, lface_id
,
7568 next_face
= FACE_FROM_ID (it
->f
, next_face_id
);
7569 it
->end_of_box_run_p
= (this_face
&& this_face
->box
!= FACE_NO_BOX
7571 || next_face
->box
== FACE_NO_BOX
));
7572 it
->face_box_p
= this_face
&& this_face
->box
!= FACE_NO_BOX
;
7575 /* Display table entry is invalid. Return a space. */
7576 it
->c
= ' ', it
->len
= 1;
7578 /* Don't change position and object of the iterator here. They are
7579 still the values of the character that had this display table
7580 entry or was translated, and that's what we want. */
7581 it
->what
= IT_CHARACTER
;
7585 /* Get the first element of string/buffer in the visual order, after
7586 being reseated to a new position in a string or a buffer. */
7588 get_visually_first_element (struct it
*it
)
7590 int string_p
= STRINGP (it
->string
) || it
->s
;
7591 ptrdiff_t eob
= (string_p
? it
->bidi_it
.string
.schars
: ZV
);
7592 ptrdiff_t bob
= (string_p
? 0 : BEGV
);
7594 if (STRINGP (it
->string
))
7596 it
->bidi_it
.charpos
= IT_STRING_CHARPOS (*it
);
7597 it
->bidi_it
.bytepos
= IT_STRING_BYTEPOS (*it
);
7601 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
7602 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
7605 if (it
->bidi_it
.charpos
== eob
)
7607 /* Nothing to do, but reset the FIRST_ELT flag, like
7608 bidi_paragraph_init does, because we are not going to
7610 it
->bidi_it
.first_elt
= 0;
7612 else if (it
->bidi_it
.charpos
== bob
7614 && (FETCH_CHAR (it
->bidi_it
.bytepos
- 1) == '\n'
7615 || FETCH_CHAR (it
->bidi_it
.bytepos
) == '\n')))
7617 /* If we are at the beginning of a line/string, we can produce
7618 the next element right away. */
7619 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7620 bidi_move_to_visually_next (&it
->bidi_it
);
7624 ptrdiff_t orig_bytepos
= it
->bidi_it
.bytepos
;
7626 /* We need to prime the bidi iterator starting at the line's or
7627 string's beginning, before we will be able to produce the
7630 it
->bidi_it
.charpos
= it
->bidi_it
.bytepos
= 0;
7632 it
->bidi_it
.charpos
= find_newline_no_quit (IT_CHARPOS (*it
),
7633 IT_BYTEPOS (*it
), -1,
7634 &it
->bidi_it
.bytepos
);
7635 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7638 /* Now return to buffer/string position where we were asked
7639 to get the next display element, and produce that. */
7640 bidi_move_to_visually_next (&it
->bidi_it
);
7642 while (it
->bidi_it
.bytepos
!= orig_bytepos
7643 && it
->bidi_it
.charpos
< eob
);
7646 /* Adjust IT's position information to where we ended up. */
7647 if (STRINGP (it
->string
))
7649 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7650 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7654 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7655 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7658 if (STRINGP (it
->string
) || !it
->s
)
7660 ptrdiff_t stop
, charpos
, bytepos
;
7662 if (STRINGP (it
->string
))
7665 stop
= SCHARS (it
->string
);
7666 if (stop
> it
->end_charpos
)
7667 stop
= it
->end_charpos
;
7668 charpos
= IT_STRING_CHARPOS (*it
);
7669 bytepos
= IT_STRING_BYTEPOS (*it
);
7673 stop
= it
->end_charpos
;
7674 charpos
= IT_CHARPOS (*it
);
7675 bytepos
= IT_BYTEPOS (*it
);
7677 if (it
->bidi_it
.scan_dir
< 0)
7679 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
, stop
,
7684 /* Load IT with the next display element from Lisp string IT->string.
7685 IT->current.string_pos is the current position within the string.
7686 If IT->current.overlay_string_index >= 0, the Lisp string is an
7690 next_element_from_string (struct it
*it
)
7692 struct text_pos position
;
7694 eassert (STRINGP (it
->string
));
7695 eassert (!it
->bidi_p
|| EQ (it
->string
, it
->bidi_it
.string
.lstring
));
7696 eassert (IT_STRING_CHARPOS (*it
) >= 0);
7697 position
= it
->current
.string_pos
;
7699 /* With bidi reordering, the character to display might not be the
7700 character at IT_STRING_CHARPOS. BIDI_IT.FIRST_ELT non-zero means
7701 that we were reseat()ed to a new string, whose paragraph
7702 direction is not known. */
7703 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7705 get_visually_first_element (it
);
7706 SET_TEXT_POS (position
, IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
));
7709 /* Time to check for invisible text? */
7710 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
7712 if (IT_STRING_CHARPOS (*it
) >= it
->stop_charpos
)
7715 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7716 || IT_STRING_CHARPOS (*it
) == it
->stop_charpos
))
7718 /* With bidi non-linear iteration, we could find
7719 ourselves far beyond the last computed stop_charpos,
7720 with several other stop positions in between that we
7721 missed. Scan them all now, in buffer's logical
7722 order, until we find and handle the last stop_charpos
7723 that precedes our current position. */
7724 handle_stop_backwards (it
, it
->stop_charpos
);
7725 return GET_NEXT_DISPLAY_ELEMENT (it
);
7731 /* Take note of the stop position we just moved
7732 across, for when we will move back across it. */
7733 it
->prev_stop
= it
->stop_charpos
;
7734 /* If we are at base paragraph embedding level, take
7735 note of the last stop position seen at this
7737 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7738 it
->base_level_stop
= it
->stop_charpos
;
7742 /* Since a handler may have changed IT->method, we must
7744 return GET_NEXT_DISPLAY_ELEMENT (it
);
7748 /* If we are before prev_stop, we may have overstepped
7749 on our way backwards a stop_pos, and if so, we need
7750 to handle that stop_pos. */
7751 && IT_STRING_CHARPOS (*it
) < it
->prev_stop
7752 /* We can sometimes back up for reasons that have nothing
7753 to do with bidi reordering. E.g., compositions. The
7754 code below is only needed when we are above the base
7755 embedding level, so test for that explicitly. */
7756 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7758 /* If we lost track of base_level_stop, we have no better
7759 place for handle_stop_backwards to start from than string
7760 beginning. This happens, e.g., when we were reseated to
7761 the previous screenful of text by vertical-motion. */
7762 if (it
->base_level_stop
<= 0
7763 || IT_STRING_CHARPOS (*it
) < it
->base_level_stop
)
7764 it
->base_level_stop
= 0;
7765 handle_stop_backwards (it
, it
->base_level_stop
);
7766 return GET_NEXT_DISPLAY_ELEMENT (it
);
7770 if (it
->current
.overlay_string_index
>= 0)
7772 /* Get the next character from an overlay string. In overlay
7773 strings, there is no field width or padding with spaces to
7775 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7780 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7781 IT_STRING_BYTEPOS (*it
),
7782 it
->bidi_it
.scan_dir
< 0
7784 : SCHARS (it
->string
))
7785 && next_element_from_composition (it
))
7789 else if (STRING_MULTIBYTE (it
->string
))
7791 const unsigned char *s
= (SDATA (it
->string
)
7792 + IT_STRING_BYTEPOS (*it
));
7793 it
->c
= string_char_and_length (s
, &it
->len
);
7797 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7803 /* Get the next character from a Lisp string that is not an
7804 overlay string. Such strings come from the mode line, for
7805 example. We may have to pad with spaces, or truncate the
7806 string. See also next_element_from_c_string. */
7807 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7812 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
7814 /* Pad with spaces. */
7815 it
->c
= ' ', it
->len
= 1;
7816 CHARPOS (position
) = BYTEPOS (position
) = -1;
7818 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7819 IT_STRING_BYTEPOS (*it
),
7820 it
->bidi_it
.scan_dir
< 0
7822 : it
->string_nchars
)
7823 && next_element_from_composition (it
))
7827 else if (STRING_MULTIBYTE (it
->string
))
7829 const unsigned char *s
= (SDATA (it
->string
)
7830 + IT_STRING_BYTEPOS (*it
));
7831 it
->c
= string_char_and_length (s
, &it
->len
);
7835 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7840 /* Record what we have and where it came from. */
7841 it
->what
= IT_CHARACTER
;
7842 it
->object
= it
->string
;
7843 it
->position
= position
;
7848 /* Load IT with next display element from C string IT->s.
7849 IT->string_nchars is the maximum number of characters to return
7850 from the string. IT->end_charpos may be greater than
7851 IT->string_nchars when this function is called, in which case we
7852 may have to return padding spaces. Value is zero if end of string
7853 reached, including padding spaces. */
7856 next_element_from_c_string (struct it
*it
)
7861 eassert (!it
->bidi_p
|| it
->s
== it
->bidi_it
.string
.s
);
7862 it
->what
= IT_CHARACTER
;
7863 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
7866 /* With bidi reordering, the character to display might not be the
7867 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7868 we were reseated to a new string, whose paragraph direction is
7870 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7871 get_visually_first_element (it
);
7873 /* IT's position can be greater than IT->string_nchars in case a
7874 field width or precision has been specified when the iterator was
7876 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7878 /* End of the game. */
7882 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
7884 /* Pad with spaces. */
7885 it
->c
= ' ', it
->len
= 1;
7886 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
7888 else if (it
->multibyte_p
)
7889 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
), &it
->len
);
7891 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
7897 /* Set up IT to return characters from an ellipsis, if appropriate.
7898 The definition of the ellipsis glyphs may come from a display table
7899 entry. This function fills IT with the first glyph from the
7900 ellipsis if an ellipsis is to be displayed. */
7903 next_element_from_ellipsis (struct it
*it
)
7905 if (it
->selective_display_ellipsis_p
)
7906 setup_for_ellipsis (it
, it
->len
);
7909 /* The face at the current position may be different from the
7910 face we find after the invisible text. Remember what it
7911 was in IT->saved_face_id, and signal that it's there by
7912 setting face_before_selective_p. */
7913 it
->saved_face_id
= it
->face_id
;
7914 it
->method
= GET_FROM_BUFFER
;
7915 it
->object
= it
->w
->contents
;
7916 reseat_at_next_visible_line_start (it
, 1);
7917 it
->face_before_selective_p
= 1;
7920 return GET_NEXT_DISPLAY_ELEMENT (it
);
7924 /* Deliver an image display element. The iterator IT is already
7925 filled with image information (done in handle_display_prop). Value
7930 next_element_from_image (struct it
*it
)
7932 it
->what
= IT_IMAGE
;
7933 it
->ignore_overlay_strings_at_pos_p
= 0;
7937 #ifdef HAVE_XWIDGETS
7938 /* im not sure about this FIXME JAVE*/
7940 next_element_from_xwidget (struct it
*it
)
7942 it
->what
= IT_XWIDGET
;
7943 //assert_valid_xwidget_id(it->xwidget_id,"next_element_from_xwidget");
7944 //this is shaky because why do we set "what" if we dont set the other parts??
7945 //printf("xwidget_id %d: in next_element_from_xwidget: FIXME \n", it->xwidget_id);
7951 /* Fill iterator IT with next display element from a stretch glyph
7952 property. IT->object is the value of the text property. Value is
7956 next_element_from_stretch (struct it
*it
)
7958 it
->what
= IT_STRETCH
;
7962 /* Scan backwards from IT's current position until we find a stop
7963 position, or until BEGV. This is called when we find ourself
7964 before both the last known prev_stop and base_level_stop while
7965 reordering bidirectional text. */
7968 compute_stop_pos_backwards (struct it
*it
)
7970 const int SCAN_BACK_LIMIT
= 1000;
7971 struct text_pos pos
;
7972 struct display_pos save_current
= it
->current
;
7973 struct text_pos save_position
= it
->position
;
7974 ptrdiff_t charpos
= IT_CHARPOS (*it
);
7975 ptrdiff_t where_we_are
= charpos
;
7976 ptrdiff_t save_stop_pos
= it
->stop_charpos
;
7977 ptrdiff_t save_end_pos
= it
->end_charpos
;
7979 eassert (NILP (it
->string
) && !it
->s
);
7980 eassert (it
->bidi_p
);
7984 it
->end_charpos
= min (charpos
+ 1, ZV
);
7985 charpos
= max (charpos
- SCAN_BACK_LIMIT
, BEGV
);
7986 SET_TEXT_POS (pos
, charpos
, CHAR_TO_BYTE (charpos
));
7987 reseat_1 (it
, pos
, 0);
7988 compute_stop_pos (it
);
7989 /* We must advance forward, right? */
7990 if (it
->stop_charpos
<= charpos
)
7993 while (charpos
> BEGV
&& it
->stop_charpos
>= it
->end_charpos
);
7995 if (it
->stop_charpos
<= where_we_are
)
7996 it
->prev_stop
= it
->stop_charpos
;
7998 it
->prev_stop
= BEGV
;
8000 it
->current
= save_current
;
8001 it
->position
= save_position
;
8002 it
->stop_charpos
= save_stop_pos
;
8003 it
->end_charpos
= save_end_pos
;
8006 /* Scan forward from CHARPOS in the current buffer/string, until we
8007 find a stop position > current IT's position. Then handle the stop
8008 position before that. This is called when we bump into a stop
8009 position while reordering bidirectional text. CHARPOS should be
8010 the last previously processed stop_pos (or BEGV/0, if none were
8011 processed yet) whose position is less that IT's current
8015 handle_stop_backwards (struct it
*it
, ptrdiff_t charpos
)
8017 int bufp
= !STRINGP (it
->string
);
8018 ptrdiff_t where_we_are
= (bufp
? IT_CHARPOS (*it
) : IT_STRING_CHARPOS (*it
));
8019 struct display_pos save_current
= it
->current
;
8020 struct text_pos save_position
= it
->position
;
8021 struct text_pos pos1
;
8022 ptrdiff_t next_stop
;
8024 /* Scan in strict logical order. */
8025 eassert (it
->bidi_p
);
8029 it
->prev_stop
= charpos
;
8032 SET_TEXT_POS (pos1
, charpos
, CHAR_TO_BYTE (charpos
));
8033 reseat_1 (it
, pos1
, 0);
8036 it
->current
.string_pos
= string_pos (charpos
, it
->string
);
8037 compute_stop_pos (it
);
8038 /* We must advance forward, right? */
8039 if (it
->stop_charpos
<= it
->prev_stop
)
8041 charpos
= it
->stop_charpos
;
8043 while (charpos
<= where_we_are
);
8046 it
->current
= save_current
;
8047 it
->position
= save_position
;
8048 next_stop
= it
->stop_charpos
;
8049 it
->stop_charpos
= it
->prev_stop
;
8051 it
->stop_charpos
= next_stop
;
8054 /* Load IT with the next display element from current_buffer. Value
8055 is zero if end of buffer reached. IT->stop_charpos is the next
8056 position at which to stop and check for text properties or buffer
8060 next_element_from_buffer (struct it
*it
)
8064 eassert (IT_CHARPOS (*it
) >= BEGV
);
8065 eassert (NILP (it
->string
) && !it
->s
);
8066 eassert (!it
->bidi_p
8067 || (EQ (it
->bidi_it
.string
.lstring
, Qnil
)
8068 && it
->bidi_it
.string
.s
== NULL
));
8070 /* With bidi reordering, the character to display might not be the
8071 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
8072 we were reseat()ed to a new buffer position, which is potentially
8073 a different paragraph. */
8074 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
8076 get_visually_first_element (it
);
8077 SET_TEXT_POS (it
->position
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8080 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
8082 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
8084 int overlay_strings_follow_p
;
8086 /* End of the game, except when overlay strings follow that
8087 haven't been returned yet. */
8088 if (it
->overlay_strings_at_end_processed_p
)
8089 overlay_strings_follow_p
= 0;
8092 it
->overlay_strings_at_end_processed_p
= 1;
8093 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
8096 if (overlay_strings_follow_p
)
8097 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
8101 it
->position
= it
->current
.pos
;
8105 else if (!(!it
->bidi_p
8106 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
8107 || IT_CHARPOS (*it
) == it
->stop_charpos
))
8109 /* With bidi non-linear iteration, we could find ourselves
8110 far beyond the last computed stop_charpos, with several
8111 other stop positions in between that we missed. Scan
8112 them all now, in buffer's logical order, until we find
8113 and handle the last stop_charpos that precedes our
8114 current position. */
8115 handle_stop_backwards (it
, it
->stop_charpos
);
8116 return GET_NEXT_DISPLAY_ELEMENT (it
);
8122 /* Take note of the stop position we just moved across,
8123 for when we will move back across it. */
8124 it
->prev_stop
= it
->stop_charpos
;
8125 /* If we are at base paragraph embedding level, take
8126 note of the last stop position seen at this
8128 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8129 it
->base_level_stop
= it
->stop_charpos
;
8132 return GET_NEXT_DISPLAY_ELEMENT (it
);
8136 /* If we are before prev_stop, we may have overstepped on
8137 our way backwards a stop_pos, and if so, we need to
8138 handle that stop_pos. */
8139 && IT_CHARPOS (*it
) < it
->prev_stop
8140 /* We can sometimes back up for reasons that have nothing
8141 to do with bidi reordering. E.g., compositions. The
8142 code below is only needed when we are above the base
8143 embedding level, so test for that explicitly. */
8144 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8146 if (it
->base_level_stop
<= 0
8147 || IT_CHARPOS (*it
) < it
->base_level_stop
)
8149 /* If we lost track of base_level_stop, we need to find
8150 prev_stop by looking backwards. This happens, e.g., when
8151 we were reseated to the previous screenful of text by
8153 it
->base_level_stop
= BEGV
;
8154 compute_stop_pos_backwards (it
);
8155 handle_stop_backwards (it
, it
->prev_stop
);
8158 handle_stop_backwards (it
, it
->base_level_stop
);
8159 return GET_NEXT_DISPLAY_ELEMENT (it
);
8163 /* No face changes, overlays etc. in sight, so just return a
8164 character from current_buffer. */
8168 /* Maybe run the redisplay end trigger hook. Performance note:
8169 This doesn't seem to cost measurable time. */
8170 if (it
->redisplay_end_trigger_charpos
8172 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
8173 run_redisplay_end_trigger_hook (it
);
8175 stop
= it
->bidi_it
.scan_dir
< 0 ? -1 : it
->end_charpos
;
8176 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
8178 && next_element_from_composition (it
))
8183 /* Get the next character, maybe multibyte. */
8184 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
8185 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
8186 it
->c
= STRING_CHAR_AND_LENGTH (p
, it
->len
);
8188 it
->c
= *p
, it
->len
= 1;
8190 /* Record what we have and where it came from. */
8191 it
->what
= IT_CHARACTER
;
8192 it
->object
= it
->w
->contents
;
8193 it
->position
= it
->current
.pos
;
8195 /* Normally we return the character found above, except when we
8196 really want to return an ellipsis for selective display. */
8201 /* A value of selective > 0 means hide lines indented more
8202 than that number of columns. */
8203 if (it
->selective
> 0
8204 && IT_CHARPOS (*it
) + 1 < ZV
8205 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
8206 IT_BYTEPOS (*it
) + 1,
8209 success_p
= next_element_from_ellipsis (it
);
8210 it
->dpvec_char_len
= -1;
8213 else if (it
->c
== '\r' && it
->selective
== -1)
8215 /* A value of selective == -1 means that everything from the
8216 CR to the end of the line is invisible, with maybe an
8217 ellipsis displayed for it. */
8218 success_p
= next_element_from_ellipsis (it
);
8219 it
->dpvec_char_len
= -1;
8224 /* Value is zero if end of buffer reached. */
8225 eassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
8230 /* Run the redisplay end trigger hook for IT. */
8233 run_redisplay_end_trigger_hook (struct it
*it
)
8235 Lisp_Object args
[3];
8237 /* IT->glyph_row should be non-null, i.e. we should be actually
8238 displaying something, or otherwise we should not run the hook. */
8239 eassert (it
->glyph_row
);
8241 /* Set up hook arguments. */
8242 args
[0] = Qredisplay_end_trigger_functions
;
8243 args
[1] = it
->window
;
8244 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
8245 it
->redisplay_end_trigger_charpos
= 0;
8247 /* Since we are *trying* to run these functions, don't try to run
8248 them again, even if they get an error. */
8249 wset_redisplay_end_trigger (it
->w
, Qnil
);
8250 Frun_hook_with_args (3, args
);
8252 /* Notice if it changed the face of the character we are on. */
8253 handle_face_prop (it
);
8257 /* Deliver a composition display element. Unlike the other
8258 next_element_from_XXX, this function is not registered in the array
8259 get_next_element[]. It is called from next_element_from_buffer and
8260 next_element_from_string when necessary. */
8263 next_element_from_composition (struct it
*it
)
8265 it
->what
= IT_COMPOSITION
;
8266 it
->len
= it
->cmp_it
.nbytes
;
8267 if (STRINGP (it
->string
))
8271 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
8272 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
8275 it
->position
= it
->current
.string_pos
;
8276 it
->object
= it
->string
;
8277 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
8278 IT_STRING_BYTEPOS (*it
), it
->string
);
8284 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
8285 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
8288 if (it
->bidi_it
.new_paragraph
)
8289 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
8290 /* Resync the bidi iterator with IT's new position.
8291 FIXME: this doesn't support bidirectional text. */
8292 while (it
->bidi_it
.charpos
< IT_CHARPOS (*it
))
8293 bidi_move_to_visually_next (&it
->bidi_it
);
8297 it
->position
= it
->current
.pos
;
8298 it
->object
= it
->w
->contents
;
8299 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
8300 IT_BYTEPOS (*it
), Qnil
);
8307 /***********************************************************************
8308 Moving an iterator without producing glyphs
8309 ***********************************************************************/
8311 /* Check if iterator is at a position corresponding to a valid buffer
8312 position after some move_it_ call. */
8314 #define IT_POS_VALID_AFTER_MOVE_P(it) \
8315 ((it)->method == GET_FROM_STRING \
8316 ? IT_STRING_CHARPOS (*it) == 0 \
8320 /* Move iterator IT to a specified buffer or X position within one
8321 line on the display without producing glyphs.
8323 OP should be a bit mask including some or all of these bits:
8324 MOVE_TO_X: Stop upon reaching x-position TO_X.
8325 MOVE_TO_POS: Stop upon reaching buffer or string position TO_CHARPOS.
8326 Regardless of OP's value, stop upon reaching the end of the display line.
8328 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
8329 This means, in particular, that TO_X includes window's horizontal
8332 The return value has several possible values that
8333 say what condition caused the scan to stop:
8335 MOVE_POS_MATCH_OR_ZV
8336 - when TO_POS or ZV was reached.
8339 -when TO_X was reached before TO_POS or ZV were reached.
8342 - when we reached the end of the display area and the line must
8346 - when we reached the end of the display area and the line is
8350 - when we stopped at a line end, i.e. a newline or a CR and selective
8353 static enum move_it_result
8354 move_it_in_display_line_to (struct it
*it
,
8355 ptrdiff_t to_charpos
, int to_x
,
8356 enum move_operation_enum op
)
8358 enum move_it_result result
= MOVE_UNDEFINED
;
8359 struct glyph_row
*saved_glyph_row
;
8360 struct it wrap_it
, atpos_it
, atx_it
, ppos_it
;
8361 void *wrap_data
= NULL
, *atpos_data
= NULL
, *atx_data
= NULL
;
8362 void *ppos_data
= NULL
;
8364 enum it_method prev_method
= it
->method
;
8365 ptrdiff_t prev_pos
= IT_CHARPOS (*it
);
8366 int saw_smaller_pos
= prev_pos
< to_charpos
;
8368 /* Don't produce glyphs in produce_glyphs. */
8369 saved_glyph_row
= it
->glyph_row
;
8370 it
->glyph_row
= NULL
;
8372 /* Use wrap_it to save a copy of IT wherever a word wrap could
8373 occur. Use atpos_it to save a copy of IT at the desired buffer
8374 position, if found, so that we can scan ahead and check if the
8375 word later overshoots the window edge. Use atx_it similarly, for
8381 /* Use ppos_it under bidi reordering to save a copy of IT for the
8382 position > CHARPOS that is the closest to CHARPOS. We restore
8383 that position in IT when we have scanned the entire display line
8384 without finding a match for CHARPOS and all the character
8385 positions are greater than CHARPOS. */
8388 SAVE_IT (ppos_it
, *it
, ppos_data
);
8389 SET_TEXT_POS (ppos_it
.current
.pos
, ZV
, ZV_BYTE
);
8390 if ((op
& MOVE_TO_POS
) && IT_CHARPOS (*it
) >= to_charpos
)
8391 SAVE_IT (ppos_it
, *it
, ppos_data
);
8394 #define BUFFER_POS_REACHED_P() \
8395 ((op & MOVE_TO_POS) != 0 \
8396 && BUFFERP (it->object) \
8397 && (IT_CHARPOS (*it) == to_charpos \
8399 || BIDI_AT_BASE_LEVEL (it->bidi_it)) \
8400 && IT_CHARPOS (*it) > to_charpos) \
8401 || (it->what == IT_COMPOSITION \
8402 && ((IT_CHARPOS (*it) > to_charpos \
8403 && to_charpos >= it->cmp_it.charpos) \
8404 || (IT_CHARPOS (*it) < to_charpos \
8405 && to_charpos <= it->cmp_it.charpos)))) \
8406 && (it->method == GET_FROM_BUFFER \
8407 || (it->method == GET_FROM_DISPLAY_VECTOR \
8408 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
8410 /* If there's a line-/wrap-prefix, handle it. */
8411 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
8412 && it
->current_y
< it
->last_visible_y
)
8413 handle_line_prefix (it
);
8415 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8416 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8420 int x
, i
, ascent
= 0, descent
= 0;
8422 /* Utility macro to reset an iterator with x, ascent, and descent. */
8423 #define IT_RESET_X_ASCENT_DESCENT(IT) \
8424 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
8425 (IT)->max_descent = descent)
8427 /* Stop if we move beyond TO_CHARPOS (after an image or a
8428 display string or stretch glyph). */
8429 if ((op
& MOVE_TO_POS
) != 0
8430 && BUFFERP (it
->object
)
8431 && it
->method
== GET_FROM_BUFFER
8433 /* When the iterator is at base embedding level, we
8434 are guaranteed that characters are delivered for
8435 display in strictly increasing order of their
8436 buffer positions. */
8437 || BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8438 && IT_CHARPOS (*it
) > to_charpos
)
8440 && (prev_method
== GET_FROM_IMAGE
8441 || prev_method
== GET_FROM_STRETCH
8442 || prev_method
== GET_FROM_STRING
)
8443 /* Passed TO_CHARPOS from left to right. */
8444 && ((prev_pos
< to_charpos
8445 && IT_CHARPOS (*it
) > to_charpos
)
8446 /* Passed TO_CHARPOS from right to left. */
8447 || (prev_pos
> to_charpos
8448 && IT_CHARPOS (*it
) < to_charpos
)))))
8450 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8452 result
= MOVE_POS_MATCH_OR_ZV
;
8455 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8456 /* If wrap_it is valid, the current position might be in a
8457 word that is wrapped. So, save the iterator in
8458 atpos_it and continue to see if wrapping happens. */
8459 SAVE_IT (atpos_it
, *it
, atpos_data
);
8462 /* Stop when ZV reached.
8463 We used to stop here when TO_CHARPOS reached as well, but that is
8464 too soon if this glyph does not fit on this line. So we handle it
8465 explicitly below. */
8466 if (!get_next_display_element (it
))
8468 result
= MOVE_POS_MATCH_OR_ZV
;
8472 if (it
->line_wrap
== TRUNCATE
)
8474 if (BUFFER_POS_REACHED_P ())
8476 result
= MOVE_POS_MATCH_OR_ZV
;
8482 if (it
->line_wrap
== WORD_WRAP
)
8484 if (IT_DISPLAYING_WHITESPACE (it
))
8488 /* We have reached a glyph that follows one or more
8489 whitespace characters. If the position is
8490 already found, we are done. */
8491 if (atpos_it
.sp
>= 0)
8493 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8494 result
= MOVE_POS_MATCH_OR_ZV
;
8499 RESTORE_IT (it
, &atx_it
, atx_data
);
8500 result
= MOVE_X_REACHED
;
8503 /* Otherwise, we can wrap here. */
8504 SAVE_IT (wrap_it
, *it
, wrap_data
);
8510 /* Remember the line height for the current line, in case
8511 the next element doesn't fit on the line. */
8512 ascent
= it
->max_ascent
;
8513 descent
= it
->max_descent
;
8515 /* The call to produce_glyphs will get the metrics of the
8516 display element IT is loaded with. Record the x-position
8517 before this display element, in case it doesn't fit on the
8521 PRODUCE_GLYPHS (it
);
8523 if (it
->area
!= TEXT_AREA
)
8525 prev_method
= it
->method
;
8526 if (it
->method
== GET_FROM_BUFFER
)
8527 prev_pos
= IT_CHARPOS (*it
);
8528 set_iterator_to_next (it
, 1);
8529 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8530 SET_TEXT_POS (this_line_min_pos
,
8531 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8533 && (op
& MOVE_TO_POS
)
8534 && IT_CHARPOS (*it
) > to_charpos
8535 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8536 SAVE_IT (ppos_it
, *it
, ppos_data
);
8540 /* The number of glyphs we get back in IT->nglyphs will normally
8541 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
8542 character on a terminal frame, or (iii) a line end. For the
8543 second case, IT->nglyphs - 1 padding glyphs will be present.
8544 (On X frames, there is only one glyph produced for a
8545 composite character.)
8547 The behavior implemented below means, for continuation lines,
8548 that as many spaces of a TAB as fit on the current line are
8549 displayed there. For terminal frames, as many glyphs of a
8550 multi-glyph character are displayed in the current line, too.
8551 This is what the old redisplay code did, and we keep it that
8552 way. Under X, the whole shape of a complex character must
8553 fit on the line or it will be completely displayed in the
8556 Note that both for tabs and padding glyphs, all glyphs have
8560 /* More than one glyph or glyph doesn't fit on line. All
8561 glyphs have the same width. */
8562 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
8564 int x_before_this_char
= x
;
8565 int hpos_before_this_char
= it
->hpos
;
8567 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
8569 new_x
= x
+ single_glyph_width
;
8571 /* We want to leave anything reaching TO_X to the caller. */
8572 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
8574 if (BUFFER_POS_REACHED_P ())
8576 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8577 goto buffer_pos_reached
;
8578 if (atpos_it
.sp
< 0)
8580 SAVE_IT (atpos_it
, *it
, atpos_data
);
8581 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8586 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8589 result
= MOVE_X_REACHED
;
8594 SAVE_IT (atx_it
, *it
, atx_data
);
8595 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
8600 if (/* Lines are continued. */
8601 it
->line_wrap
!= TRUNCATE
8602 && (/* And glyph doesn't fit on the line. */
8603 new_x
> it
->last_visible_x
8604 /* Or it fits exactly and we're on a window
8606 || (new_x
== it
->last_visible_x
8607 && FRAME_WINDOW_P (it
->f
)
8608 && ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
8609 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8610 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
8612 if (/* IT->hpos == 0 means the very first glyph
8613 doesn't fit on the line, e.g. a wide image. */
8615 || (new_x
== it
->last_visible_x
8616 && FRAME_WINDOW_P (it
->f
)))
8619 it
->current_x
= new_x
;
8621 /* The character's last glyph just barely fits
8623 if (i
== it
->nglyphs
- 1)
8625 /* If this is the destination position,
8626 return a position *before* it in this row,
8627 now that we know it fits in this row. */
8628 if (BUFFER_POS_REACHED_P ())
8630 if (it
->line_wrap
!= WORD_WRAP
8633 it
->hpos
= hpos_before_this_char
;
8634 it
->current_x
= x_before_this_char
;
8635 result
= MOVE_POS_MATCH_OR_ZV
;
8638 if (it
->line_wrap
== WORD_WRAP
8641 SAVE_IT (atpos_it
, *it
, atpos_data
);
8642 atpos_it
.current_x
= x_before_this_char
;
8643 atpos_it
.hpos
= hpos_before_this_char
;
8647 prev_method
= it
->method
;
8648 if (it
->method
== GET_FROM_BUFFER
)
8649 prev_pos
= IT_CHARPOS (*it
);
8650 set_iterator_to_next (it
, 1);
8651 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8652 SET_TEXT_POS (this_line_min_pos
,
8653 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8654 /* On graphical terminals, newlines may
8655 "overflow" into the fringe if
8656 overflow-newline-into-fringe is non-nil.
8657 On text terminals, and on graphical
8658 terminals with no right margin, newlines
8659 may overflow into the last glyph on the
8661 if (!FRAME_WINDOW_P (it
->f
)
8663 && it
->bidi_it
.paragraph_dir
== R2L
)
8664 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8665 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0
8666 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8668 if (!get_next_display_element (it
))
8670 result
= MOVE_POS_MATCH_OR_ZV
;
8673 if (BUFFER_POS_REACHED_P ())
8675 if (ITERATOR_AT_END_OF_LINE_P (it
))
8676 result
= MOVE_POS_MATCH_OR_ZV
;
8678 result
= MOVE_LINE_CONTINUED
;
8681 if (ITERATOR_AT_END_OF_LINE_P (it
)
8682 && (it
->line_wrap
!= WORD_WRAP
8685 result
= MOVE_NEWLINE_OR_CR
;
8692 IT_RESET_X_ASCENT_DESCENT (it
);
8694 if (wrap_it
.sp
>= 0)
8696 RESTORE_IT (it
, &wrap_it
, wrap_data
);
8701 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
8703 result
= MOVE_LINE_CONTINUED
;
8707 if (BUFFER_POS_REACHED_P ())
8709 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8710 goto buffer_pos_reached
;
8711 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8713 SAVE_IT (atpos_it
, *it
, atpos_data
);
8714 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8718 if (new_x
> it
->first_visible_x
)
8720 /* Glyph is visible. Increment number of glyphs that
8721 would be displayed. */
8726 if (result
!= MOVE_UNDEFINED
)
8729 else if (BUFFER_POS_REACHED_P ())
8732 IT_RESET_X_ASCENT_DESCENT (it
);
8733 result
= MOVE_POS_MATCH_OR_ZV
;
8736 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
8738 /* Stop when TO_X specified and reached. This check is
8739 necessary here because of lines consisting of a line end,
8740 only. The line end will not produce any glyphs and we
8741 would never get MOVE_X_REACHED. */
8742 eassert (it
->nglyphs
== 0);
8743 result
= MOVE_X_REACHED
;
8747 /* Is this a line end? If yes, we're done. */
8748 if (ITERATOR_AT_END_OF_LINE_P (it
))
8750 /* If we are past TO_CHARPOS, but never saw any character
8751 positions smaller than TO_CHARPOS, return
8752 MOVE_POS_MATCH_OR_ZV, like the unidirectional display
8754 if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0)
8756 if (!saw_smaller_pos
&& IT_CHARPOS (*it
) > to_charpos
)
8758 if (IT_CHARPOS (ppos_it
) < ZV
)
8760 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8761 result
= MOVE_POS_MATCH_OR_ZV
;
8764 goto buffer_pos_reached
;
8766 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
>= 0
8767 && IT_CHARPOS (*it
) > to_charpos
)
8768 goto buffer_pos_reached
;
8770 result
= MOVE_NEWLINE_OR_CR
;
8773 result
= MOVE_NEWLINE_OR_CR
;
8777 prev_method
= it
->method
;
8778 if (it
->method
== GET_FROM_BUFFER
)
8779 prev_pos
= IT_CHARPOS (*it
);
8780 /* The current display element has been consumed. Advance
8782 set_iterator_to_next (it
, 1);
8783 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8784 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8785 if (IT_CHARPOS (*it
) < to_charpos
)
8786 saw_smaller_pos
= 1;
8788 && (op
& MOVE_TO_POS
)
8789 && IT_CHARPOS (*it
) >= to_charpos
8790 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8791 SAVE_IT (ppos_it
, *it
, ppos_data
);
8793 /* Stop if lines are truncated and IT's current x-position is
8794 past the right edge of the window now. */
8795 if (it
->line_wrap
== TRUNCATE
8796 && it
->current_x
>= it
->last_visible_x
)
8798 if (!FRAME_WINDOW_P (it
->f
)
8799 || ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
8800 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8801 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0
8802 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8806 if ((at_eob_p
= !get_next_display_element (it
))
8807 || BUFFER_POS_REACHED_P ()
8808 /* If we are past TO_CHARPOS, but never saw any
8809 character positions smaller than TO_CHARPOS,
8810 return MOVE_POS_MATCH_OR_ZV, like the
8811 unidirectional display did. */
8812 || (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8814 && IT_CHARPOS (*it
) > to_charpos
))
8817 && !at_eob_p
&& IT_CHARPOS (ppos_it
) < ZV
)
8818 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8819 result
= MOVE_POS_MATCH_OR_ZV
;
8822 if (ITERATOR_AT_END_OF_LINE_P (it
))
8824 result
= MOVE_NEWLINE_OR_CR
;
8828 else if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8830 && IT_CHARPOS (*it
) > to_charpos
)
8832 if (IT_CHARPOS (ppos_it
) < ZV
)
8833 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8834 result
= MOVE_POS_MATCH_OR_ZV
;
8837 result
= MOVE_LINE_TRUNCATED
;
8840 #undef IT_RESET_X_ASCENT_DESCENT
8843 #undef BUFFER_POS_REACHED_P
8845 /* If we scanned beyond to_pos and didn't find a point to wrap at,
8846 restore the saved iterator. */
8847 if (atpos_it
.sp
>= 0)
8848 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8849 else if (atx_it
.sp
>= 0)
8850 RESTORE_IT (it
, &atx_it
, atx_data
);
8855 bidi_unshelve_cache (atpos_data
, 1);
8857 bidi_unshelve_cache (atx_data
, 1);
8859 bidi_unshelve_cache (wrap_data
, 1);
8861 bidi_unshelve_cache (ppos_data
, 1);
8863 /* Restore the iterator settings altered at the beginning of this
8865 it
->glyph_row
= saved_glyph_row
;
8869 /* For external use. */
8871 move_it_in_display_line (struct it
*it
,
8872 ptrdiff_t to_charpos
, int to_x
,
8873 enum move_operation_enum op
)
8875 if (it
->line_wrap
== WORD_WRAP
8876 && (op
& MOVE_TO_X
))
8879 void *save_data
= NULL
;
8882 SAVE_IT (save_it
, *it
, save_data
);
8883 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8884 /* When word-wrap is on, TO_X may lie past the end
8885 of a wrapped line. Then it->current is the
8886 character on the next line, so backtrack to the
8887 space before the wrap point. */
8888 if (skip
== MOVE_LINE_CONTINUED
)
8890 int prev_x
= max (it
->current_x
- 1, 0);
8891 RESTORE_IT (it
, &save_it
, save_data
);
8892 move_it_in_display_line_to
8893 (it
, -1, prev_x
, MOVE_TO_X
);
8896 bidi_unshelve_cache (save_data
, 1);
8899 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8903 /* Move IT forward until it satisfies one or more of the criteria in
8904 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
8906 OP is a bit-mask that specifies where to stop, and in particular,
8907 which of those four position arguments makes a difference. See the
8908 description of enum move_operation_enum.
8910 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
8911 screen line, this function will set IT to the next position that is
8912 displayed to the right of TO_CHARPOS on the screen. */
8915 move_it_to (struct it
*it
, ptrdiff_t to_charpos
, int to_x
, int to_y
, int to_vpos
, int op
)
8917 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
8918 int line_height
, line_start_x
= 0, reached
= 0;
8919 void *backup_data
= NULL
;
8923 if (op
& MOVE_TO_VPOS
)
8925 /* If no TO_CHARPOS and no TO_X specified, stop at the
8926 start of the line TO_VPOS. */
8927 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
8929 if (it
->vpos
== to_vpos
)
8935 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
8939 /* TO_VPOS >= 0 means stop at TO_X in the line at
8940 TO_VPOS, or at TO_POS, whichever comes first. */
8941 if (it
->vpos
== to_vpos
)
8947 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8949 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
8954 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
8956 /* We have reached TO_X but not in the line we want. */
8957 skip
= move_it_in_display_line_to (it
, to_charpos
,
8959 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8967 else if (op
& MOVE_TO_Y
)
8969 struct it it_backup
;
8971 if (it
->line_wrap
== WORD_WRAP
)
8972 SAVE_IT (it_backup
, *it
, backup_data
);
8974 /* TO_Y specified means stop at TO_X in the line containing
8975 TO_Y---or at TO_CHARPOS if this is reached first. The
8976 problem is that we can't really tell whether the line
8977 contains TO_Y before we have completely scanned it, and
8978 this may skip past TO_X. What we do is to first scan to
8981 If TO_X is not specified, use a TO_X of zero. The reason
8982 is to make the outcome of this function more predictable.
8983 If we didn't use TO_X == 0, we would stop at the end of
8984 the line which is probably not what a caller would expect
8986 skip
= move_it_in_display_line_to
8987 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
8988 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
8990 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
8991 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8993 else if (skip
== MOVE_X_REACHED
)
8995 /* If TO_X was reached, we want to know whether TO_Y is
8996 in the line. We know this is the case if the already
8997 scanned glyphs make the line tall enough. Otherwise,
8998 we must check by scanning the rest of the line. */
8999 line_height
= it
->max_ascent
+ it
->max_descent
;
9000 if (to_y
>= it
->current_y
9001 && to_y
< it
->current_y
+ line_height
)
9006 SAVE_IT (it_backup
, *it
, backup_data
);
9007 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
9008 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
9010 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
9011 line_height
= it
->max_ascent
+ it
->max_descent
;
9012 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
9014 if (to_y
>= it
->current_y
9015 && to_y
< it
->current_y
+ line_height
)
9017 /* If TO_Y is in this line and TO_X was reached
9018 above, we scanned too far. We have to restore
9019 IT's settings to the ones before skipping. But
9020 keep the more accurate values of max_ascent and
9021 max_descent we've found while skipping the rest
9022 of the line, for the sake of callers, such as
9023 pos_visible_p, that need to know the line
9025 int max_ascent
= it
->max_ascent
;
9026 int max_descent
= it
->max_descent
;
9028 RESTORE_IT (it
, &it_backup
, backup_data
);
9029 it
->max_ascent
= max_ascent
;
9030 it
->max_descent
= max_descent
;
9036 if (skip
== MOVE_POS_MATCH_OR_ZV
)
9042 /* Check whether TO_Y is in this line. */
9043 line_height
= it
->max_ascent
+ it
->max_descent
;
9044 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
9046 if (to_y
>= it
->current_y
9047 && to_y
< it
->current_y
+ line_height
)
9049 /* When word-wrap is on, TO_X may lie past the end
9050 of a wrapped line. Then it->current is the
9051 character on the next line, so backtrack to the
9052 space before the wrap point. */
9053 if (skip
== MOVE_LINE_CONTINUED
9054 && it
->line_wrap
== WORD_WRAP
)
9056 int prev_x
= max (it
->current_x
- 1, 0);
9057 RESTORE_IT (it
, &it_backup
, backup_data
);
9058 skip
= move_it_in_display_line_to
9059 (it
, -1, prev_x
, MOVE_TO_X
);
9068 else if (BUFFERP (it
->object
)
9069 && (it
->method
== GET_FROM_BUFFER
9070 || it
->method
== GET_FROM_STRETCH
)
9071 && IT_CHARPOS (*it
) >= to_charpos
9072 /* Under bidi iteration, a call to set_iterator_to_next
9073 can scan far beyond to_charpos if the initial
9074 portion of the next line needs to be reordered. In
9075 that case, give move_it_in_display_line_to another
9078 && it
->bidi_it
.scan_dir
== -1))
9079 skip
= MOVE_POS_MATCH_OR_ZV
;
9081 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
9085 case MOVE_POS_MATCH_OR_ZV
:
9089 case MOVE_NEWLINE_OR_CR
:
9090 set_iterator_to_next (it
, 1);
9091 it
->continuation_lines_width
= 0;
9094 case MOVE_LINE_TRUNCATED
:
9095 it
->continuation_lines_width
= 0;
9096 reseat_at_next_visible_line_start (it
, 0);
9097 if ((op
& MOVE_TO_POS
) != 0
9098 && IT_CHARPOS (*it
) > to_charpos
)
9105 case MOVE_LINE_CONTINUED
:
9106 /* For continued lines ending in a tab, some of the glyphs
9107 associated with the tab are displayed on the current
9108 line. Since it->current_x does not include these glyphs,
9109 we use it->last_visible_x instead. */
9112 it
->continuation_lines_width
+= it
->last_visible_x
;
9113 /* When moving by vpos, ensure that the iterator really
9114 advances to the next line (bug#847, bug#969). Fixme:
9115 do we need to do this in other circumstances? */
9116 if (it
->current_x
!= it
->last_visible_x
9117 && (op
& MOVE_TO_VPOS
)
9118 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
9120 line_start_x
= it
->current_x
+ it
->pixel_width
9121 - it
->last_visible_x
;
9122 set_iterator_to_next (it
, 0);
9126 it
->continuation_lines_width
+= it
->current_x
;
9133 /* Reset/increment for the next run. */
9134 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
9135 it
->current_x
= line_start_x
;
9138 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
9140 last_height
= it
->max_ascent
+ it
->max_descent
;
9141 it
->max_ascent
= it
->max_descent
= 0;
9146 /* On text terminals, we may stop at the end of a line in the middle
9147 of a multi-character glyph. If the glyph itself is continued,
9148 i.e. it is actually displayed on the next line, don't treat this
9149 stopping point as valid; move to the next line instead (unless
9150 that brings us offscreen). */
9151 if (!FRAME_WINDOW_P (it
->f
)
9153 && IT_CHARPOS (*it
) == to_charpos
9154 && it
->what
== IT_CHARACTER
9156 && it
->line_wrap
== WINDOW_WRAP
9157 && it
->current_x
== it
->last_visible_x
- 1
9160 && it
->vpos
< it
->w
->window_end_vpos
)
9162 it
->continuation_lines_width
+= it
->current_x
;
9163 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
9164 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
9166 last_height
= it
->max_ascent
+ it
->max_descent
;
9170 bidi_unshelve_cache (backup_data
, 1);
9172 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
9176 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
9178 If DY > 0, move IT backward at least that many pixels. DY = 0
9179 means move IT backward to the preceding line start or BEGV. This
9180 function may move over more than DY pixels if IT->current_y - DY
9181 ends up in the middle of a line; in this case IT->current_y will be
9182 set to the top of the line moved to. */
9185 move_it_vertically_backward (struct it
*it
, int dy
)
9189 void *it2data
= NULL
, *it3data
= NULL
;
9190 ptrdiff_t start_pos
;
9192 = (it
->last_visible_x
- it
->first_visible_x
) / FRAME_COLUMN_WIDTH (it
->f
);
9193 ptrdiff_t pos_limit
;
9198 start_pos
= IT_CHARPOS (*it
);
9200 /* Estimate how many newlines we must move back. */
9201 nlines
= max (1, dy
/ default_line_pixel_height (it
->w
));
9202 if (it
->line_wrap
== TRUNCATE
)
9205 pos_limit
= max (start_pos
- nlines
* nchars_per_row
, BEGV
);
9207 /* Set the iterator's position that many lines back. But don't go
9208 back more than NLINES full screen lines -- this wins a day with
9209 buffers which have very long lines. */
9210 while (nlines
-- && IT_CHARPOS (*it
) > pos_limit
)
9211 back_to_previous_visible_line_start (it
);
9213 /* Reseat the iterator here. When moving backward, we don't want
9214 reseat to skip forward over invisible text, set up the iterator
9215 to deliver from overlay strings at the new position etc. So,
9216 use reseat_1 here. */
9217 reseat_1 (it
, it
->current
.pos
, 1);
9219 /* We are now surely at a line start. */
9220 it
->current_x
= it
->hpos
= 0; /* FIXME: this is incorrect when bidi
9221 reordering is in effect. */
9222 it
->continuation_lines_width
= 0;
9224 /* Move forward and see what y-distance we moved. First move to the
9225 start of the next line so that we get its height. We need this
9226 height to be able to tell whether we reached the specified
9228 SAVE_IT (it2
, *it
, it2data
);
9229 it2
.max_ascent
= it2
.max_descent
= 0;
9232 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
9233 MOVE_TO_POS
| MOVE_TO_VPOS
);
9235 while (!(IT_POS_VALID_AFTER_MOVE_P (&it2
)
9236 /* If we are in a display string which starts at START_POS,
9237 and that display string includes a newline, and we are
9238 right after that newline (i.e. at the beginning of a
9239 display line), exit the loop, because otherwise we will
9240 infloop, since move_it_to will see that it is already at
9241 START_POS and will not move. */
9242 || (it2
.method
== GET_FROM_STRING
9243 && IT_CHARPOS (it2
) == start_pos
9244 && SREF (it2
.string
, IT_STRING_BYTEPOS (it2
) - 1) == '\n')));
9245 eassert (IT_CHARPOS (*it
) >= BEGV
);
9246 SAVE_IT (it3
, it2
, it3data
);
9248 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
9249 eassert (IT_CHARPOS (*it
) >= BEGV
);
9250 /* H is the actual vertical distance from the position in *IT
9251 and the starting position. */
9252 h
= it2
.current_y
- it
->current_y
;
9253 /* NLINES is the distance in number of lines. */
9254 nlines
= it2
.vpos
- it
->vpos
;
9256 /* Correct IT's y and vpos position
9257 so that they are relative to the starting point. */
9263 /* DY == 0 means move to the start of the screen line. The
9264 value of nlines is > 0 if continuation lines were involved,
9265 or if the original IT position was at start of a line. */
9266 RESTORE_IT (it
, it
, it2data
);
9268 move_it_by_lines (it
, nlines
);
9269 /* The above code moves us to some position NLINES down,
9270 usually to its first glyph (leftmost in an L2R line), but
9271 that's not necessarily the start of the line, under bidi
9272 reordering. We want to get to the character position
9273 that is immediately after the newline of the previous
9276 && !it
->continuation_lines_width
9277 && !STRINGP (it
->string
)
9278 && IT_CHARPOS (*it
) > BEGV
9279 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9281 ptrdiff_t cp
= IT_CHARPOS (*it
), bp
= IT_BYTEPOS (*it
);
9284 cp
= find_newline_no_quit (cp
, bp
, -1, NULL
);
9285 move_it_to (it
, cp
, -1, -1, -1, MOVE_TO_POS
);
9287 bidi_unshelve_cache (it3data
, 1);
9291 /* The y-position we try to reach, relative to *IT.
9292 Note that H has been subtracted in front of the if-statement. */
9293 int target_y
= it
->current_y
+ h
- dy
;
9294 int y0
= it3
.current_y
;
9298 RESTORE_IT (&it3
, &it3
, it3data
);
9299 y1
= line_bottom_y (&it3
);
9300 line_height
= y1
- y0
;
9301 RESTORE_IT (it
, it
, it2data
);
9302 /* If we did not reach target_y, try to move further backward if
9303 we can. If we moved too far backward, try to move forward. */
9304 if (target_y
< it
->current_y
9305 /* This is heuristic. In a window that's 3 lines high, with
9306 a line height of 13 pixels each, recentering with point
9307 on the bottom line will try to move -39/2 = 19 pixels
9308 backward. Try to avoid moving into the first line. */
9309 && (it
->current_y
- target_y
9310 > min (window_box_height (it
->w
), line_height
* 2 / 3))
9311 && IT_CHARPOS (*it
) > BEGV
)
9313 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
9314 target_y
- it
->current_y
));
9315 dy
= it
->current_y
- target_y
;
9316 goto move_further_back
;
9318 else if (target_y
>= it
->current_y
+ line_height
9319 && IT_CHARPOS (*it
) < ZV
)
9321 /* Should move forward by at least one line, maybe more.
9323 Note: Calling move_it_by_lines can be expensive on
9324 terminal frames, where compute_motion is used (via
9325 vmotion) to do the job, when there are very long lines
9326 and truncate-lines is nil. That's the reason for
9327 treating terminal frames specially here. */
9329 if (!FRAME_WINDOW_P (it
->f
))
9330 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
9335 move_it_by_lines (it
, 1);
9337 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
9344 /* Move IT by a specified amount of pixel lines DY. DY negative means
9345 move backwards. DY = 0 means move to start of screen line. At the
9346 end, IT will be on the start of a screen line. */
9349 move_it_vertically (struct it
*it
, int dy
)
9352 move_it_vertically_backward (it
, -dy
);
9355 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
9356 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
9357 MOVE_TO_POS
| MOVE_TO_Y
);
9358 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
9360 /* If buffer ends in ZV without a newline, move to the start of
9361 the line to satisfy the post-condition. */
9362 if (IT_CHARPOS (*it
) == ZV
9364 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9365 move_it_by_lines (it
, 0);
9370 /* Move iterator IT past the end of the text line it is in. */
9373 move_it_past_eol (struct it
*it
)
9375 enum move_it_result rc
;
9377 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
9378 if (rc
== MOVE_NEWLINE_OR_CR
)
9379 set_iterator_to_next (it
, 0);
9383 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
9384 negative means move up. DVPOS == 0 means move to the start of the
9387 Optimization idea: If we would know that IT->f doesn't use
9388 a face with proportional font, we could be faster for
9389 truncate-lines nil. */
9392 move_it_by_lines (struct it
*it
, ptrdiff_t dvpos
)
9395 /* The commented-out optimization uses vmotion on terminals. This
9396 gives bad results, because elements like it->what, on which
9397 callers such as pos_visible_p rely, aren't updated. */
9398 /* struct position pos;
9399 if (!FRAME_WINDOW_P (it->f))
9401 struct text_pos textpos;
9403 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
9404 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
9405 reseat (it, textpos, 1);
9406 it->vpos += pos.vpos;
9407 it->current_y += pos.vpos;
9413 /* DVPOS == 0 means move to the start of the screen line. */
9414 move_it_vertically_backward (it
, 0);
9415 /* Let next call to line_bottom_y calculate real line height */
9420 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
9421 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
9423 /* Only move to the next buffer position if we ended up in a
9424 string from display property, not in an overlay string
9425 (before-string or after-string). That is because the
9426 latter don't conceal the underlying buffer position, so
9427 we can ask to move the iterator to the exact position we
9428 are interested in. Note that, even if we are already at
9429 IT_CHARPOS (*it), the call below is not a no-op, as it
9430 will detect that we are at the end of the string, pop the
9431 iterator, and compute it->current_x and it->hpos
9433 move_it_to (it
, IT_CHARPOS (*it
) + it
->string_from_display_prop_p
,
9434 -1, -1, -1, MOVE_TO_POS
);
9440 void *it2data
= NULL
;
9441 ptrdiff_t start_charpos
, i
;
9443 = (it
->last_visible_x
- it
->first_visible_x
) / FRAME_COLUMN_WIDTH (it
->f
);
9444 ptrdiff_t pos_limit
;
9446 /* Start at the beginning of the screen line containing IT's
9447 position. This may actually move vertically backwards,
9448 in case of overlays, so adjust dvpos accordingly. */
9450 move_it_vertically_backward (it
, 0);
9453 /* Go back -DVPOS buffer lines, but no farther than -DVPOS full
9454 screen lines, and reseat the iterator there. */
9455 start_charpos
= IT_CHARPOS (*it
);
9456 if (it
->line_wrap
== TRUNCATE
)
9459 pos_limit
= max (start_charpos
+ dvpos
* nchars_per_row
, BEGV
);
9460 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > pos_limit
; --i
)
9461 back_to_previous_visible_line_start (it
);
9462 reseat (it
, it
->current
.pos
, 1);
9464 /* Move further back if we end up in a string or an image. */
9465 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
9467 /* First try to move to start of display line. */
9469 move_it_vertically_backward (it
, 0);
9471 if (IT_POS_VALID_AFTER_MOVE_P (it
))
9473 /* If start of line is still in string or image,
9474 move further back. */
9475 back_to_previous_visible_line_start (it
);
9476 reseat (it
, it
->current
.pos
, 1);
9480 it
->current_x
= it
->hpos
= 0;
9482 /* Above call may have moved too far if continuation lines
9483 are involved. Scan forward and see if it did. */
9484 SAVE_IT (it2
, *it
, it2data
);
9485 it2
.vpos
= it2
.current_y
= 0;
9486 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
9487 it
->vpos
-= it2
.vpos
;
9488 it
->current_y
-= it2
.current_y
;
9489 it
->current_x
= it
->hpos
= 0;
9491 /* If we moved too far back, move IT some lines forward. */
9492 if (it2
.vpos
> -dvpos
)
9494 int delta
= it2
.vpos
+ dvpos
;
9496 RESTORE_IT (&it2
, &it2
, it2data
);
9497 SAVE_IT (it2
, *it
, it2data
);
9498 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
9499 /* Move back again if we got too far ahead. */
9500 if (IT_CHARPOS (*it
) >= start_charpos
)
9501 RESTORE_IT (it
, &it2
, it2data
);
9503 bidi_unshelve_cache (it2data
, 1);
9506 RESTORE_IT (it
, it
, it2data
);
9510 /* Return 1 if IT points into the middle of a display vector. */
9513 in_display_vector_p (struct it
*it
)
9515 return (it
->method
== GET_FROM_DISPLAY_VECTOR
9516 && it
->current
.dpvec_index
> 0
9517 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
9521 /***********************************************************************
9523 ***********************************************************************/
9526 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
9530 add_to_log (const char *format
, Lisp_Object arg1
, Lisp_Object arg2
)
9532 Lisp_Object args
[3];
9533 Lisp_Object msg
, fmt
;
9536 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
9540 GCPRO4 (fmt
, msg
, arg1
, arg2
);
9542 args
[0] = fmt
= build_string (format
);
9545 msg
= Fformat (3, args
);
9547 len
= SBYTES (msg
) + 1;
9548 buffer
= SAFE_ALLOCA (len
);
9549 memcpy (buffer
, SDATA (msg
), len
);
9551 message_dolog (buffer
, len
- 1, 1, 0);
9558 /* Output a newline in the *Messages* buffer if "needs" one. */
9561 message_log_maybe_newline (void)
9563 if (message_log_need_newline
)
9564 message_dolog ("", 0, 1, 0);
9568 /* Add a string M of length NBYTES to the message log, optionally
9569 terminated with a newline when NLFLAG is true. MULTIBYTE, if
9570 true, means interpret the contents of M as multibyte. This
9571 function calls low-level routines in order to bypass text property
9572 hooks, etc. which might not be safe to run.
9574 This may GC (insert may run before/after change hooks),
9575 so the buffer M must NOT point to a Lisp string. */
9578 message_dolog (const char *m
, ptrdiff_t nbytes
, bool nlflag
, bool multibyte
)
9580 const unsigned char *msg
= (const unsigned char *) m
;
9582 if (!NILP (Vmemory_full
))
9585 if (!NILP (Vmessage_log_max
))
9587 struct buffer
*oldbuf
;
9588 Lisp_Object oldpoint
, oldbegv
, oldzv
;
9589 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
9590 ptrdiff_t point_at_end
= 0;
9591 ptrdiff_t zv_at_end
= 0;
9592 Lisp_Object old_deactivate_mark
;
9594 struct gcpro gcpro1
;
9596 old_deactivate_mark
= Vdeactivate_mark
;
9597 oldbuf
= current_buffer
;
9598 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
9599 bset_undo_list (current_buffer
, Qt
);
9601 oldpoint
= message_dolog_marker1
;
9602 set_marker_restricted_both (oldpoint
, Qnil
, PT
, PT_BYTE
);
9603 oldbegv
= message_dolog_marker2
;
9604 set_marker_restricted_both (oldbegv
, Qnil
, BEGV
, BEGV_BYTE
);
9605 oldzv
= message_dolog_marker3
;
9606 set_marker_restricted_both (oldzv
, Qnil
, ZV
, ZV_BYTE
);
9607 GCPRO1 (old_deactivate_mark
);
9615 BEGV_BYTE
= BEG_BYTE
;
9618 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9620 /* Insert the string--maybe converting multibyte to single byte
9621 or vice versa, so that all the text fits the buffer. */
9623 && NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9629 /* Convert a multibyte string to single-byte
9630 for the *Message* buffer. */
9631 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
9633 c
= string_char_and_length (msg
+ i
, &char_bytes
);
9634 work
[0] = (ASCII_CHAR_P (c
)
9636 : multibyte_char_to_unibyte (c
));
9637 insert_1_both (work
, 1, 1, 1, 0, 0);
9640 else if (! multibyte
9641 && ! NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9645 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9646 /* Convert a single-byte string to multibyte
9647 for the *Message* buffer. */
9648 for (i
= 0; i
< nbytes
; i
++)
9651 MAKE_CHAR_MULTIBYTE (c
);
9652 char_bytes
= CHAR_STRING (c
, str
);
9653 insert_1_both ((char *) str
, 1, char_bytes
, 1, 0, 0);
9657 insert_1_both (m
, chars_in_text (msg
, nbytes
), nbytes
, 1, 0, 0);
9661 ptrdiff_t this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
;
9664 insert_1_both ("\n", 1, 1, 1, 0, 0);
9666 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9668 this_bol_byte
= PT_BYTE
;
9670 /* See if this line duplicates the previous one.
9671 If so, combine duplicates. */
9674 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9676 prev_bol_byte
= PT_BYTE
;
9678 dups
= message_log_check_duplicate (prev_bol_byte
,
9682 del_range_both (prev_bol
, prev_bol_byte
,
9683 this_bol
, this_bol_byte
, 0);
9686 char dupstr
[sizeof " [ times]"
9687 + INT_STRLEN_BOUND (printmax_t
)];
9689 /* If you change this format, don't forget to also
9690 change message_log_check_duplicate. */
9691 int duplen
= sprintf (dupstr
, " [%"pMd
" times]", dups
);
9692 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
9693 insert_1_both (dupstr
, duplen
, duplen
, 1, 0, 1);
9698 /* If we have more than the desired maximum number of lines
9699 in the *Messages* buffer now, delete the oldest ones.
9700 This is safe because we don't have undo in this buffer. */
9702 if (NATNUMP (Vmessage_log_max
))
9704 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
9705 -XFASTINT (Vmessage_log_max
) - 1, 0);
9706 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
9709 BEGV
= marker_position (oldbegv
);
9710 BEGV_BYTE
= marker_byte_position (oldbegv
);
9719 ZV
= marker_position (oldzv
);
9720 ZV_BYTE
= marker_byte_position (oldzv
);
9724 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9726 /* We can't do Fgoto_char (oldpoint) because it will run some
9728 TEMP_SET_PT_BOTH (marker_position (oldpoint
),
9729 marker_byte_position (oldpoint
));
9732 unchain_marker (XMARKER (oldpoint
));
9733 unchain_marker (XMARKER (oldbegv
));
9734 unchain_marker (XMARKER (oldzv
));
9736 shown
= buffer_window_count (current_buffer
) > 0;
9737 set_buffer_internal (oldbuf
);
9738 /* We called insert_1_both above with its 5th argument (PREPARE)
9739 zero, which prevents insert_1_both from calling
9740 prepare_to_modify_buffer, which in turns prevents us from
9741 incrementing windows_or_buffers_changed even if *Messages* is
9742 shown in some window. So we must manually incrementing
9743 windows_or_buffers_changed here to make up for that. */
9745 windows_or_buffers_changed
++;
9747 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
9748 message_log_need_newline
= !nlflag
;
9749 Vdeactivate_mark
= old_deactivate_mark
;
9754 /* We are at the end of the buffer after just having inserted a newline.
9755 (Note: We depend on the fact we won't be crossing the gap.)
9756 Check to see if the most recent message looks a lot like the previous one.
9757 Return 0 if different, 1 if the new one should just replace it, or a
9758 value N > 1 if we should also append " [N times]". */
9761 message_log_check_duplicate (ptrdiff_t prev_bol_byte
, ptrdiff_t this_bol_byte
)
9764 ptrdiff_t len
= Z_BYTE
- 1 - this_bol_byte
;
9766 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
9767 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
9769 for (i
= 0; i
< len
; i
++)
9771 if (i
>= 3 && p1
[i
- 3] == '.' && p1
[i
- 2] == '.' && p1
[i
- 1] == '.')
9779 if (*p1
++ == ' ' && *p1
++ == '[')
9782 intmax_t n
= strtoimax ((char *) p1
, &pend
, 10);
9783 if (0 < n
&& n
< INTMAX_MAX
&& strncmp (pend
, " times]\n", 8) == 0)
9790 /* Display an echo area message M with a specified length of NBYTES
9791 bytes. The string may include null characters. If M is not a
9792 string, clear out any existing message, and let the mini-buffer
9795 This function cancels echoing. */
9798 message3 (Lisp_Object m
)
9800 struct gcpro gcpro1
;
9803 clear_message (1,1);
9806 /* First flush out any partial line written with print. */
9807 message_log_maybe_newline ();
9810 ptrdiff_t nbytes
= SBYTES (m
);
9811 bool multibyte
= STRING_MULTIBYTE (m
);
9813 char *buffer
= SAFE_ALLOCA (nbytes
);
9814 memcpy (buffer
, SDATA (m
), nbytes
);
9815 message_dolog (buffer
, nbytes
, 1, multibyte
);
9824 /* The non-logging version of message3.
9825 This does not cancel echoing, because it is used for echoing.
9826 Perhaps we need to make a separate function for echoing
9827 and make this cancel echoing. */
9830 message3_nolog (Lisp_Object m
)
9832 struct frame
*sf
= SELECTED_FRAME ();
9834 if (FRAME_INITIAL_P (sf
))
9836 if (noninteractive_need_newline
)
9837 putc ('\n', stderr
);
9838 noninteractive_need_newline
= 0;
9840 fwrite (SDATA (m
), SBYTES (m
), 1, stderr
);
9841 if (cursor_in_echo_area
== 0)
9842 fprintf (stderr
, "\n");
9845 /* Error messages get reported properly by cmd_error, so this must be just an
9846 informative message; if the frame hasn't really been initialized yet, just
9848 else if (INTERACTIVE
&& sf
->glyphs_initialized_p
)
9850 /* Get the frame containing the mini-buffer
9851 that the selected frame is using. */
9852 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9853 Lisp_Object frame
= XWINDOW (mini_window
)->frame
;
9854 struct frame
*f
= XFRAME (frame
);
9856 if (FRAME_VISIBLE_P (sf
) && !FRAME_VISIBLE_P (f
))
9857 Fmake_frame_visible (frame
);
9859 if (STRINGP (m
) && SCHARS (m
) > 0)
9862 if (minibuffer_auto_raise
)
9863 Fraise_frame (frame
);
9864 /* Assume we are not echoing.
9865 (If we are, echo_now will override this.) */
9866 echo_message_buffer
= Qnil
;
9869 clear_message (1, 1);
9871 do_pending_window_change (0);
9872 echo_area_display (1);
9873 do_pending_window_change (0);
9874 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
9875 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
9880 /* Display a null-terminated echo area message M. If M is 0, clear
9881 out any existing message, and let the mini-buffer text show through.
9883 The buffer M must continue to exist until after the echo area gets
9884 cleared or some other message gets displayed there. Do not pass
9885 text that is stored in a Lisp string. Do not pass text in a buffer
9886 that was alloca'd. */
9889 message1 (const char *m
)
9891 message3 (m
? build_unibyte_string (m
) : Qnil
);
9895 /* The non-logging counterpart of message1. */
9898 message1_nolog (const char *m
)
9900 message3_nolog (m
? build_unibyte_string (m
) : Qnil
);
9903 /* Display a message M which contains a single %s
9904 which gets replaced with STRING. */
9907 message_with_string (const char *m
, Lisp_Object string
, int log
)
9909 CHECK_STRING (string
);
9915 if (noninteractive_need_newline
)
9916 putc ('\n', stderr
);
9917 noninteractive_need_newline
= 0;
9918 fprintf (stderr
, m
, SDATA (string
));
9919 if (!cursor_in_echo_area
)
9920 fprintf (stderr
, "\n");
9924 else if (INTERACTIVE
)
9926 /* The frame whose minibuffer we're going to display the message on.
9927 It may be larger than the selected frame, so we need
9928 to use its buffer, not the selected frame's buffer. */
9929 Lisp_Object mini_window
;
9930 struct frame
*f
, *sf
= SELECTED_FRAME ();
9932 /* Get the frame containing the minibuffer
9933 that the selected frame is using. */
9934 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9935 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9937 /* Error messages get reported properly by cmd_error, so this must be
9938 just an informative message; if the frame hasn't really been
9939 initialized yet, just toss it. */
9940 if (f
->glyphs_initialized_p
)
9942 Lisp_Object args
[2], msg
;
9943 struct gcpro gcpro1
, gcpro2
;
9945 args
[0] = build_string (m
);
9946 args
[1] = msg
= string
;
9947 GCPRO2 (args
[0], msg
);
9950 msg
= Fformat (2, args
);
9955 message3_nolog (msg
);
9959 /* Print should start at the beginning of the message
9960 buffer next time. */
9961 message_buf_print
= 0;
9967 /* Dump an informative message to the minibuf. If M is 0, clear out
9968 any existing message, and let the mini-buffer text show through. */
9971 vmessage (const char *m
, va_list ap
)
9977 if (noninteractive_need_newline
)
9978 putc ('\n', stderr
);
9979 noninteractive_need_newline
= 0;
9980 vfprintf (stderr
, m
, ap
);
9981 if (cursor_in_echo_area
== 0)
9982 fprintf (stderr
, "\n");
9986 else if (INTERACTIVE
)
9988 /* The frame whose mini-buffer we're going to display the message
9989 on. It may be larger than the selected frame, so we need to
9990 use its buffer, not the selected frame's buffer. */
9991 Lisp_Object mini_window
;
9992 struct frame
*f
, *sf
= SELECTED_FRAME ();
9994 /* Get the frame containing the mini-buffer
9995 that the selected frame is using. */
9996 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9997 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9999 /* Error messages get reported properly by cmd_error, so this must be
10000 just an informative message; if the frame hasn't really been
10001 initialized yet, just toss it. */
10002 if (f
->glyphs_initialized_p
)
10007 ptrdiff_t maxsize
= FRAME_MESSAGE_BUF_SIZE (f
);
10008 char *message_buf
= alloca (maxsize
+ 1);
10010 len
= doprnt (message_buf
, maxsize
, m
, 0, ap
);
10012 message3 (make_string (message_buf
, len
));
10017 /* Print should start at the beginning of the message
10018 buffer next time. */
10019 message_buf_print
= 0;
10025 message (const char *m
, ...)
10035 /* The non-logging version of message. */
10038 message_nolog (const char *m
, ...)
10040 Lisp_Object old_log_max
;
10043 old_log_max
= Vmessage_log_max
;
10044 Vmessage_log_max
= Qnil
;
10046 Vmessage_log_max
= old_log_max
;
10052 /* Display the current message in the current mini-buffer. This is
10053 only called from error handlers in process.c, and is not time
10057 update_echo_area (void)
10059 if (!NILP (echo_area_buffer
[0]))
10061 Lisp_Object string
;
10062 string
= Fcurrent_message ();
10068 /* Make sure echo area buffers in `echo_buffers' are live.
10069 If they aren't, make new ones. */
10072 ensure_echo_area_buffers (void)
10076 for (i
= 0; i
< 2; ++i
)
10077 if (!BUFFERP (echo_buffer
[i
])
10078 || !BUFFER_LIVE_P (XBUFFER (echo_buffer
[i
])))
10081 Lisp_Object old_buffer
;
10084 old_buffer
= echo_buffer
[i
];
10085 echo_buffer
[i
] = Fget_buffer_create
10086 (make_formatted_string (name
, " *Echo Area %d*", i
));
10087 bset_truncate_lines (XBUFFER (echo_buffer
[i
]), Qnil
);
10088 /* to force word wrap in echo area -
10089 it was decided to postpone this*/
10090 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
10092 for (j
= 0; j
< 2; ++j
)
10093 if (EQ (old_buffer
, echo_area_buffer
[j
]))
10094 echo_area_buffer
[j
] = echo_buffer
[i
];
10099 /* Call FN with args A1..A2 with either the current or last displayed
10100 echo_area_buffer as current buffer.
10102 WHICH zero means use the current message buffer
10103 echo_area_buffer[0]. If that is nil, choose a suitable buffer
10104 from echo_buffer[] and clear it.
10106 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
10107 suitable buffer from echo_buffer[] and clear it.
10109 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
10110 that the current message becomes the last displayed one, make
10111 choose a suitable buffer for echo_area_buffer[0], and clear it.
10113 Value is what FN returns. */
10116 with_echo_area_buffer (struct window
*w
, int which
,
10117 int (*fn
) (ptrdiff_t, Lisp_Object
),
10118 ptrdiff_t a1
, Lisp_Object a2
)
10120 Lisp_Object buffer
;
10121 int this_one
, the_other
, clear_buffer_p
, rc
;
10122 ptrdiff_t count
= SPECPDL_INDEX ();
10124 /* If buffers aren't live, make new ones. */
10125 ensure_echo_area_buffers ();
10127 clear_buffer_p
= 0;
10130 this_one
= 0, the_other
= 1;
10131 else if (which
> 0)
10132 this_one
= 1, the_other
= 0;
10135 this_one
= 0, the_other
= 1;
10136 clear_buffer_p
= 1;
10138 /* We need a fresh one in case the current echo buffer equals
10139 the one containing the last displayed echo area message. */
10140 if (!NILP (echo_area_buffer
[this_one
])
10141 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
10142 echo_area_buffer
[this_one
] = Qnil
;
10145 /* Choose a suitable buffer from echo_buffer[] is we don't
10147 if (NILP (echo_area_buffer
[this_one
]))
10149 echo_area_buffer
[this_one
]
10150 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
10151 ? echo_buffer
[the_other
]
10152 : echo_buffer
[this_one
]);
10153 clear_buffer_p
= 1;
10156 buffer
= echo_area_buffer
[this_one
];
10158 /* Don't get confused by reusing the buffer used for echoing
10159 for a different purpose. */
10160 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
10163 record_unwind_protect (unwind_with_echo_area_buffer
,
10164 with_echo_area_buffer_unwind_data (w
));
10166 /* Make the echo area buffer current. Note that for display
10167 purposes, it is not necessary that the displayed window's buffer
10168 == current_buffer, except for text property lookup. So, let's
10169 only set that buffer temporarily here without doing a full
10170 Fset_window_buffer. We must also change w->pointm, though,
10171 because otherwise an assertions in unshow_buffer fails, and Emacs
10173 set_buffer_internal_1 (XBUFFER (buffer
));
10176 wset_buffer (w
, buffer
);
10177 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
10180 bset_undo_list (current_buffer
, Qt
);
10181 bset_read_only (current_buffer
, Qnil
);
10182 specbind (Qinhibit_read_only
, Qt
);
10183 specbind (Qinhibit_modification_hooks
, Qt
);
10185 if (clear_buffer_p
&& Z
> BEG
)
10186 del_range (BEG
, Z
);
10188 eassert (BEGV
>= BEG
);
10189 eassert (ZV
<= Z
&& ZV
>= BEGV
);
10193 eassert (BEGV
>= BEG
);
10194 eassert (ZV
<= Z
&& ZV
>= BEGV
);
10196 unbind_to (count
, Qnil
);
10201 /* Save state that should be preserved around the call to the function
10202 FN called in with_echo_area_buffer. */
10205 with_echo_area_buffer_unwind_data (struct window
*w
)
10208 Lisp_Object vector
, tmp
;
10210 /* Reduce consing by keeping one vector in
10211 Vwith_echo_area_save_vector. */
10212 vector
= Vwith_echo_area_save_vector
;
10213 Vwith_echo_area_save_vector
= Qnil
;
10216 vector
= Fmake_vector (make_number (9), Qnil
);
10218 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
10219 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
10220 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
10224 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
10225 ASET (vector
, i
, w
->contents
); ++i
;
10226 ASET (vector
, i
, make_number (marker_position (w
->pointm
))); ++i
;
10227 ASET (vector
, i
, make_number (marker_byte_position (w
->pointm
))); ++i
;
10228 ASET (vector
, i
, make_number (marker_position (w
->start
))); ++i
;
10229 ASET (vector
, i
, make_number (marker_byte_position (w
->start
))); ++i
;
10234 for (; i
< end
; ++i
)
10235 ASET (vector
, i
, Qnil
);
10238 eassert (i
== ASIZE (vector
));
10243 /* Restore global state from VECTOR which was created by
10244 with_echo_area_buffer_unwind_data. */
10247 unwind_with_echo_area_buffer (Lisp_Object vector
)
10249 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
10250 Vdeactivate_mark
= AREF (vector
, 1);
10251 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
10253 if (WINDOWP (AREF (vector
, 3)))
10256 Lisp_Object buffer
;
10258 w
= XWINDOW (AREF (vector
, 3));
10259 buffer
= AREF (vector
, 4);
10261 wset_buffer (w
, buffer
);
10262 set_marker_both (w
->pointm
, buffer
,
10263 XFASTINT (AREF (vector
, 5)),
10264 XFASTINT (AREF (vector
, 6)));
10265 set_marker_both (w
->start
, buffer
,
10266 XFASTINT (AREF (vector
, 7)),
10267 XFASTINT (AREF (vector
, 8)));
10270 Vwith_echo_area_save_vector
= vector
;
10274 /* Set up the echo area for use by print functions. MULTIBYTE_P
10275 non-zero means we will print multibyte. */
10278 setup_echo_area_for_printing (int multibyte_p
)
10280 /* If we can't find an echo area any more, exit. */
10281 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
10282 Fkill_emacs (Qnil
);
10284 ensure_echo_area_buffers ();
10286 if (!message_buf_print
)
10288 /* A message has been output since the last time we printed.
10289 Choose a fresh echo area buffer. */
10290 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10291 echo_area_buffer
[0] = echo_buffer
[1];
10293 echo_area_buffer
[0] = echo_buffer
[0];
10295 /* Switch to that buffer and clear it. */
10296 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10297 bset_truncate_lines (current_buffer
, Qnil
);
10301 ptrdiff_t count
= SPECPDL_INDEX ();
10302 specbind (Qinhibit_read_only
, Qt
);
10303 /* Note that undo recording is always disabled. */
10304 del_range (BEG
, Z
);
10305 unbind_to (count
, Qnil
);
10307 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10309 /* Set up the buffer for the multibyteness we need. */
10311 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10312 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
10314 /* Raise the frame containing the echo area. */
10315 if (minibuffer_auto_raise
)
10317 struct frame
*sf
= SELECTED_FRAME ();
10318 Lisp_Object mini_window
;
10319 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10320 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
10323 message_log_maybe_newline ();
10324 message_buf_print
= 1;
10328 if (NILP (echo_area_buffer
[0]))
10330 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10331 echo_area_buffer
[0] = echo_buffer
[1];
10333 echo_area_buffer
[0] = echo_buffer
[0];
10336 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
10338 /* Someone switched buffers between print requests. */
10339 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10340 bset_truncate_lines (current_buffer
, Qnil
);
10346 /* Display an echo area message in window W. Value is non-zero if W's
10347 height is changed. If display_last_displayed_message_p is
10348 non-zero, display the message that was last displayed, otherwise
10349 display the current message. */
10352 display_echo_area (struct window
*w
)
10354 int i
, no_message_p
, window_height_changed_p
;
10356 /* Temporarily disable garbage collections while displaying the echo
10357 area. This is done because a GC can print a message itself.
10358 That message would modify the echo area buffer's contents while a
10359 redisplay of the buffer is going on, and seriously confuse
10361 ptrdiff_t count
= inhibit_garbage_collection ();
10363 /* If there is no message, we must call display_echo_area_1
10364 nevertheless because it resizes the window. But we will have to
10365 reset the echo_area_buffer in question to nil at the end because
10366 with_echo_area_buffer will sets it to an empty buffer. */
10367 i
= display_last_displayed_message_p
? 1 : 0;
10368 no_message_p
= NILP (echo_area_buffer
[i
]);
10370 window_height_changed_p
10371 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
10372 display_echo_area_1
,
10373 (intptr_t) w
, Qnil
);
10376 echo_area_buffer
[i
] = Qnil
;
10378 unbind_to (count
, Qnil
);
10379 return window_height_changed_p
;
10383 /* Helper for display_echo_area. Display the current buffer which
10384 contains the current echo area message in window W, a mini-window,
10385 a pointer to which is passed in A1. A2..A4 are currently not used.
10386 Change the height of W so that all of the message is displayed.
10387 Value is non-zero if height of W was changed. */
10390 display_echo_area_1 (ptrdiff_t a1
, Lisp_Object a2
)
10393 struct window
*w
= (struct window
*) i1
;
10394 Lisp_Object window
;
10395 struct text_pos start
;
10396 int window_height_changed_p
= 0;
10398 /* Do this before displaying, so that we have a large enough glyph
10399 matrix for the display. If we can't get enough space for the
10400 whole text, display the last N lines. That works by setting w->start. */
10401 window_height_changed_p
= resize_mini_window (w
, 0);
10403 /* Use the starting position chosen by resize_mini_window. */
10404 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
10407 clear_glyph_matrix (w
->desired_matrix
);
10408 XSETWINDOW (window
, w
);
10409 try_window (window
, start
, 0);
10411 return window_height_changed_p
;
10415 /* Resize the echo area window to exactly the size needed for the
10416 currently displayed message, if there is one. If a mini-buffer
10417 is active, don't shrink it. */
10420 resize_echo_area_exactly (void)
10422 if (BUFFERP (echo_area_buffer
[0])
10423 && WINDOWP (echo_area_window
))
10425 struct window
*w
= XWINDOW (echo_area_window
);
10427 Lisp_Object resize_exactly
;
10429 if (minibuf_level
== 0)
10430 resize_exactly
= Qt
;
10432 resize_exactly
= Qnil
;
10434 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
10435 (intptr_t) w
, resize_exactly
);
10438 ++windows_or_buffers_changed
;
10439 ++update_mode_lines
;
10440 redisplay_internal ();
10446 /* Callback function for with_echo_area_buffer, when used from
10447 resize_echo_area_exactly. A1 contains a pointer to the window to
10448 resize, EXACTLY non-nil means resize the mini-window exactly to the
10449 size of the text displayed. A3 and A4 are not used. Value is what
10450 resize_mini_window returns. */
10453 resize_mini_window_1 (ptrdiff_t a1
, Lisp_Object exactly
)
10456 return resize_mini_window ((struct window
*) i1
, !NILP (exactly
));
10460 /* Resize mini-window W to fit the size of its contents. EXACT_P
10461 means size the window exactly to the size needed. Otherwise, it's
10462 only enlarged until W's buffer is empty.
10464 Set W->start to the right place to begin display. If the whole
10465 contents fit, start at the beginning. Otherwise, start so as
10466 to make the end of the contents appear. This is particularly
10467 important for y-or-n-p, but seems desirable generally.
10469 Value is non-zero if the window height has been changed. */
10472 resize_mini_window (struct window
*w
, int exact_p
)
10474 struct frame
*f
= XFRAME (w
->frame
);
10475 int window_height_changed_p
= 0;
10477 eassert (MINI_WINDOW_P (w
));
10479 /* By default, start display at the beginning. */
10480 set_marker_both (w
->start
, w
->contents
,
10481 BUF_BEGV (XBUFFER (w
->contents
)),
10482 BUF_BEGV_BYTE (XBUFFER (w
->contents
)));
10484 /* Don't resize windows while redisplaying a window; it would
10485 confuse redisplay functions when the size of the window they are
10486 displaying changes from under them. Such a resizing can happen,
10487 for instance, when which-func prints a long message while
10488 we are running fontification-functions. We're running these
10489 functions with safe_call which binds inhibit-redisplay to t. */
10490 if (!NILP (Vinhibit_redisplay
))
10493 /* Nil means don't try to resize. */
10494 if (NILP (Vresize_mini_windows
)
10495 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
10498 if (!FRAME_MINIBUF_ONLY_P (f
))
10501 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
10502 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
10504 EMACS_INT max_height
;
10505 int unit
= FRAME_LINE_HEIGHT (f
);
10506 struct text_pos start
;
10507 struct buffer
*old_current_buffer
= NULL
;
10509 if (current_buffer
!= XBUFFER (w
->contents
))
10511 old_current_buffer
= current_buffer
;
10512 set_buffer_internal (XBUFFER (w
->contents
));
10515 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10517 /* Compute the max. number of lines specified by the user. */
10518 if (FLOATP (Vmax_mini_window_height
))
10519 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
10520 else if (INTEGERP (Vmax_mini_window_height
))
10521 max_height
= XINT (Vmax_mini_window_height
);
10523 max_height
= total_height
/ 4;
10525 /* Correct that max. height if it's bogus. */
10526 max_height
= clip_to_bounds (1, max_height
, total_height
);
10528 /* Find out the height of the text in the window. */
10529 if (it
.line_wrap
== TRUNCATE
)
10534 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
10535 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
10536 height
= it
.current_y
+ last_height
;
10538 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
10539 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
10540 height
= (height
+ unit
- 1) / unit
;
10543 /* Compute a suitable window start. */
10544 if (height
> max_height
)
10546 height
= max_height
;
10547 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10548 move_it_vertically_backward (&it
, (height
- 1) * unit
);
10549 start
= it
.current
.pos
;
10552 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
10553 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
10555 if (EQ (Vresize_mini_windows
, Qgrow_only
))
10557 /* Let it grow only, until we display an empty message, in which
10558 case the window shrinks again. */
10559 if (height
> WINDOW_TOTAL_LINES (w
))
10561 int old_height
= WINDOW_TOTAL_LINES (w
);
10563 FRAME_WINDOWS_FROZEN (f
) = 1;
10564 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10565 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10567 else if (height
< WINDOW_TOTAL_LINES (w
)
10568 && (exact_p
|| BEGV
== ZV
))
10570 int old_height
= WINDOW_TOTAL_LINES (w
);
10572 FRAME_WINDOWS_FROZEN (f
) = 0;
10573 shrink_mini_window (w
);
10574 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10579 /* Always resize to exact size needed. */
10580 if (height
> WINDOW_TOTAL_LINES (w
))
10582 int old_height
= WINDOW_TOTAL_LINES (w
);
10584 FRAME_WINDOWS_FROZEN (f
) = 1;
10585 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10586 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10588 else if (height
< WINDOW_TOTAL_LINES (w
))
10590 int old_height
= WINDOW_TOTAL_LINES (w
);
10592 FRAME_WINDOWS_FROZEN (f
) = 0;
10593 shrink_mini_window (w
);
10597 FRAME_WINDOWS_FROZEN (f
) = 1;
10598 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10601 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10605 if (old_current_buffer
)
10606 set_buffer_internal (old_current_buffer
);
10609 return window_height_changed_p
;
10613 /* Value is the current message, a string, or nil if there is no
10614 current message. */
10617 current_message (void)
10621 if (!BUFFERP (echo_area_buffer
[0]))
10625 with_echo_area_buffer (0, 0, current_message_1
,
10626 (intptr_t) &msg
, Qnil
);
10628 echo_area_buffer
[0] = Qnil
;
10636 current_message_1 (ptrdiff_t a1
, Lisp_Object a2
)
10639 Lisp_Object
*msg
= (Lisp_Object
*) i1
;
10642 *msg
= make_buffer_string (BEG
, Z
, 1);
10649 /* Push the current message on Vmessage_stack for later restoration
10650 by restore_message. Value is non-zero if the current message isn't
10651 empty. This is a relatively infrequent operation, so it's not
10652 worth optimizing. */
10655 push_message (void)
10657 Lisp_Object msg
= current_message ();
10658 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
10659 return STRINGP (msg
);
10663 /* Restore message display from the top of Vmessage_stack. */
10666 restore_message (void)
10668 eassert (CONSP (Vmessage_stack
));
10669 message3_nolog (XCAR (Vmessage_stack
));
10673 /* Handler for unwind-protect calling pop_message. */
10676 pop_message_unwind (void)
10678 /* Pop the top-most entry off Vmessage_stack. */
10679 eassert (CONSP (Vmessage_stack
));
10680 Vmessage_stack
= XCDR (Vmessage_stack
);
10684 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
10685 exits. If the stack is not empty, we have a missing pop_message
10689 check_message_stack (void)
10691 if (!NILP (Vmessage_stack
))
10696 /* Truncate to NCHARS what will be displayed in the echo area the next
10697 time we display it---but don't redisplay it now. */
10700 truncate_echo_area (ptrdiff_t nchars
)
10703 echo_area_buffer
[0] = Qnil
;
10704 else if (!noninteractive
10706 && !NILP (echo_area_buffer
[0]))
10708 struct frame
*sf
= SELECTED_FRAME ();
10709 /* Error messages get reported properly by cmd_error, so this must be
10710 just an informative message; if the frame hasn't really been
10711 initialized yet, just toss it. */
10712 if (sf
->glyphs_initialized_p
)
10713 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
);
10718 /* Helper function for truncate_echo_area. Truncate the current
10719 message to at most NCHARS characters. */
10722 truncate_message_1 (ptrdiff_t nchars
, Lisp_Object a2
)
10724 if (BEG
+ nchars
< Z
)
10725 del_range (BEG
+ nchars
, Z
);
10727 echo_area_buffer
[0] = Qnil
;
10731 /* Set the current message to STRING. */
10734 set_message (Lisp_Object string
)
10736 eassert (STRINGP (string
));
10738 message_enable_multibyte
= STRING_MULTIBYTE (string
);
10740 with_echo_area_buffer (0, -1, set_message_1
, 0, string
);
10741 message_buf_print
= 0;
10742 help_echo_showing_p
= 0;
10744 if (STRINGP (Vdebug_on_message
)
10745 && STRINGP (string
)
10746 && fast_string_match (Vdebug_on_message
, string
) >= 0)
10747 call_debugger (list2 (Qerror
, string
));
10751 /* Helper function for set_message. First argument is ignored and second
10752 argument has the same meaning as for set_message.
10753 This function is called with the echo area buffer being current. */
10756 set_message_1 (ptrdiff_t a1
, Lisp_Object string
)
10758 eassert (STRINGP (string
));
10760 /* Change multibyteness of the echo buffer appropriately. */
10761 if (message_enable_multibyte
10762 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10763 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
10765 bset_truncate_lines (current_buffer
, message_truncate_lines
? Qt
: Qnil
);
10766 if (!NILP (BVAR (current_buffer
, bidi_display_reordering
)))
10767 bset_bidi_paragraph_direction (current_buffer
, Qleft_to_right
);
10769 /* Insert new message at BEG. */
10770 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10772 /* This function takes care of single/multibyte conversion.
10773 We just have to ensure that the echo area buffer has the right
10774 setting of enable_multibyte_characters. */
10775 insert_from_string (string
, 0, 0, SCHARS (string
), SBYTES (string
), 1);
10781 /* Clear messages. CURRENT_P non-zero means clear the current
10782 message. LAST_DISPLAYED_P non-zero means clear the message
10786 clear_message (int current_p
, int last_displayed_p
)
10790 echo_area_buffer
[0] = Qnil
;
10791 message_cleared_p
= 1;
10794 if (last_displayed_p
)
10795 echo_area_buffer
[1] = Qnil
;
10797 message_buf_print
= 0;
10800 /* Clear garbaged frames.
10802 This function is used where the old redisplay called
10803 redraw_garbaged_frames which in turn called redraw_frame which in
10804 turn called clear_frame. The call to clear_frame was a source of
10805 flickering. I believe a clear_frame is not necessary. It should
10806 suffice in the new redisplay to invalidate all current matrices,
10807 and ensure a complete redisplay of all windows. */
10810 clear_garbaged_frames (void)
10812 if (frame_garbaged
)
10814 Lisp_Object tail
, frame
;
10815 int changed_count
= 0;
10817 FOR_EACH_FRAME (tail
, frame
)
10819 struct frame
*f
= XFRAME (frame
);
10821 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
10826 f
->force_flush_display_p
= 1;
10828 clear_current_matrices (f
);
10835 frame_garbaged
= 0;
10837 ++windows_or_buffers_changed
;
10842 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
10843 is non-zero update selected_frame. Value is non-zero if the
10844 mini-windows height has been changed. */
10847 echo_area_display (int update_frame_p
)
10849 Lisp_Object mini_window
;
10852 int window_height_changed_p
= 0;
10853 struct frame
*sf
= SELECTED_FRAME ();
10855 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10856 w
= XWINDOW (mini_window
);
10857 f
= XFRAME (WINDOW_FRAME (w
));
10859 /* Don't display if frame is invisible or not yet initialized. */
10860 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
10863 #ifdef HAVE_WINDOW_SYSTEM
10864 /* When Emacs starts, selected_frame may be the initial terminal
10865 frame. If we let this through, a message would be displayed on
10867 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
10869 #endif /* HAVE_WINDOW_SYSTEM */
10871 /* Redraw garbaged frames. */
10872 clear_garbaged_frames ();
10874 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
10876 echo_area_window
= mini_window
;
10877 window_height_changed_p
= display_echo_area (w
);
10878 w
->must_be_updated_p
= 1;
10880 /* Update the display, unless called from redisplay_internal.
10881 Also don't update the screen during redisplay itself. The
10882 update will happen at the end of redisplay, and an update
10883 here could cause confusion. */
10884 if (update_frame_p
&& !redisplaying_p
)
10888 /* If the display update has been interrupted by pending
10889 input, update mode lines in the frame. Due to the
10890 pending input, it might have been that redisplay hasn't
10891 been called, so that mode lines above the echo area are
10892 garbaged. This looks odd, so we prevent it here. */
10893 if (!display_completed
)
10894 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
10896 if (window_height_changed_p
10897 /* Don't do this if Emacs is shutting down. Redisplay
10898 needs to run hooks. */
10899 && !NILP (Vrun_hooks
))
10901 /* Must update other windows. Likewise as in other
10902 cases, don't let this update be interrupted by
10904 ptrdiff_t count
= SPECPDL_INDEX ();
10905 specbind (Qredisplay_dont_pause
, Qt
);
10906 windows_or_buffers_changed
= 1;
10907 redisplay_internal ();
10908 unbind_to (count
, Qnil
);
10910 else if (FRAME_WINDOW_P (f
) && n
== 0)
10912 /* Window configuration is the same as before.
10913 Can do with a display update of the echo area,
10914 unless we displayed some mode lines. */
10915 update_single_window (w
, 1);
10916 FRAME_RIF (f
)->flush_display (f
);
10919 update_frame (f
, 1, 1);
10921 /* If cursor is in the echo area, make sure that the next
10922 redisplay displays the minibuffer, so that the cursor will
10923 be replaced with what the minibuffer wants. */
10924 if (cursor_in_echo_area
)
10925 ++windows_or_buffers_changed
;
10928 else if (!EQ (mini_window
, selected_window
))
10929 windows_or_buffers_changed
++;
10931 /* Last displayed message is now the current message. */
10932 echo_area_buffer
[1] = echo_area_buffer
[0];
10933 /* Inform read_char that we're not echoing. */
10934 echo_message_buffer
= Qnil
;
10936 /* Prevent redisplay optimization in redisplay_internal by resetting
10937 this_line_start_pos. This is done because the mini-buffer now
10938 displays the message instead of its buffer text. */
10939 if (EQ (mini_window
, selected_window
))
10940 CHARPOS (this_line_start_pos
) = 0;
10942 return window_height_changed_p
;
10945 /* Nonzero if the current window's buffer is shown in more than one
10946 window and was modified since last redisplay. */
10949 buffer_shared_and_changed (void)
10951 return (buffer_window_count (current_buffer
) > 1
10952 && UNCHANGED_MODIFIED
< MODIFF
);
10955 /* Nonzero if W's buffer was changed but not saved or Transient Mark mode
10956 is enabled and mark of W's buffer was changed since last W's update. */
10959 window_buffer_changed (struct window
*w
)
10961 struct buffer
*b
= XBUFFER (w
->contents
);
10963 eassert (BUFFER_LIVE_P (b
));
10965 return (((BUF_SAVE_MODIFF (b
) < BUF_MODIFF (b
)) != w
->last_had_star
)
10966 || ((!NILP (Vtransient_mark_mode
) && !NILP (BVAR (b
, mark_active
)))
10967 != (w
->region_showing
!= 0)));
10970 /* Nonzero if W has %c in its mode line and mode line should be updated. */
10973 mode_line_update_needed (struct window
*w
)
10975 return (w
->column_number_displayed
!= -1
10976 && !(PT
== w
->last_point
&& !window_outdated (w
))
10977 && (w
->column_number_displayed
!= current_column ()));
10980 /* Nonzero if window start of W is frozen and may not be changed during
10984 window_frozen_p (struct window
*w
)
10986 if (FRAME_WINDOWS_FROZEN (XFRAME (WINDOW_FRAME (w
))))
10988 Lisp_Object window
;
10990 XSETWINDOW (window
, w
);
10991 if (MINI_WINDOW_P (w
))
10993 else if (EQ (window
, selected_window
))
10995 else if (MINI_WINDOW_P (XWINDOW (selected_window
))
10996 && EQ (window
, Vminibuf_scroll_window
))
10997 /* This special window can't be frozen too. */
11005 /***********************************************************************
11006 Mode Lines and Frame Titles
11007 ***********************************************************************/
11009 /* A buffer for constructing non-propertized mode-line strings and
11010 frame titles in it; allocated from the heap in init_xdisp and
11011 resized as needed in store_mode_line_noprop_char. */
11013 static char *mode_line_noprop_buf
;
11015 /* The buffer's end, and a current output position in it. */
11017 static char *mode_line_noprop_buf_end
;
11018 static char *mode_line_noprop_ptr
;
11020 #define MODE_LINE_NOPROP_LEN(start) \
11021 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
11024 MODE_LINE_DISPLAY
= 0,
11028 } mode_line_target
;
11030 /* Alist that caches the results of :propertize.
11031 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
11032 static Lisp_Object mode_line_proptrans_alist
;
11034 /* List of strings making up the mode-line. */
11035 static Lisp_Object mode_line_string_list
;
11037 /* Base face property when building propertized mode line string. */
11038 static Lisp_Object mode_line_string_face
;
11039 static Lisp_Object mode_line_string_face_prop
;
11042 /* Unwind data for mode line strings */
11044 static Lisp_Object Vmode_line_unwind_vector
;
11047 format_mode_line_unwind_data (struct frame
*target_frame
,
11048 struct buffer
*obuf
,
11050 int save_proptrans
)
11052 Lisp_Object vector
, tmp
;
11054 /* Reduce consing by keeping one vector in
11055 Vwith_echo_area_save_vector. */
11056 vector
= Vmode_line_unwind_vector
;
11057 Vmode_line_unwind_vector
= Qnil
;
11060 vector
= Fmake_vector (make_number (10), Qnil
);
11062 ASET (vector
, 0, make_number (mode_line_target
));
11063 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
11064 ASET (vector
, 2, mode_line_string_list
);
11065 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
11066 ASET (vector
, 4, mode_line_string_face
);
11067 ASET (vector
, 5, mode_line_string_face_prop
);
11070 XSETBUFFER (tmp
, obuf
);
11073 ASET (vector
, 6, tmp
);
11074 ASET (vector
, 7, owin
);
11077 /* Similarly to `with-selected-window', if the operation selects
11078 a window on another frame, we must restore that frame's
11079 selected window, and (for a tty) the top-frame. */
11080 ASET (vector
, 8, target_frame
->selected_window
);
11081 if (FRAME_TERMCAP_P (target_frame
))
11082 ASET (vector
, 9, FRAME_TTY (target_frame
)->top_frame
);
11089 unwind_format_mode_line (Lisp_Object vector
)
11091 Lisp_Object old_window
= AREF (vector
, 7);
11092 Lisp_Object target_frame_window
= AREF (vector
, 8);
11093 Lisp_Object old_top_frame
= AREF (vector
, 9);
11095 mode_line_target
= XINT (AREF (vector
, 0));
11096 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
11097 mode_line_string_list
= AREF (vector
, 2);
11098 if (! EQ (AREF (vector
, 3), Qt
))
11099 mode_line_proptrans_alist
= AREF (vector
, 3);
11100 mode_line_string_face
= AREF (vector
, 4);
11101 mode_line_string_face_prop
= AREF (vector
, 5);
11103 /* Select window before buffer, since it may change the buffer. */
11104 if (!NILP (old_window
))
11106 /* If the operation that we are unwinding had selected a window
11107 on a different frame, reset its frame-selected-window. For a
11108 text terminal, reset its top-frame if necessary. */
11109 if (!NILP (target_frame_window
))
11112 = WINDOW_FRAME (XWINDOW (target_frame_window
));
11114 if (!EQ (frame
, WINDOW_FRAME (XWINDOW (old_window
))))
11115 Fselect_window (target_frame_window
, Qt
);
11117 if (!NILP (old_top_frame
) && !EQ (old_top_frame
, frame
))
11118 Fselect_frame (old_top_frame
, Qt
);
11121 Fselect_window (old_window
, Qt
);
11124 if (!NILP (AREF (vector
, 6)))
11126 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
11127 ASET (vector
, 6, Qnil
);
11130 Vmode_line_unwind_vector
= vector
;
11134 /* Store a single character C for the frame title in mode_line_noprop_buf.
11135 Re-allocate mode_line_noprop_buf if necessary. */
11138 store_mode_line_noprop_char (char c
)
11140 /* If output position has reached the end of the allocated buffer,
11141 increase the buffer's size. */
11142 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
11144 ptrdiff_t len
= MODE_LINE_NOPROP_LEN (0);
11145 ptrdiff_t size
= len
;
11146 mode_line_noprop_buf
=
11147 xpalloc (mode_line_noprop_buf
, &size
, 1, STRING_BYTES_BOUND
, 1);
11148 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
11149 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
11152 *mode_line_noprop_ptr
++ = c
;
11156 /* Store part of a frame title in mode_line_noprop_buf, beginning at
11157 mode_line_noprop_ptr. STRING is the string to store. Do not copy
11158 characters that yield more columns than PRECISION; PRECISION <= 0
11159 means copy the whole string. Pad with spaces until FIELD_WIDTH
11160 number of characters have been copied; FIELD_WIDTH <= 0 means don't
11161 pad. Called from display_mode_element when it is used to build a
11165 store_mode_line_noprop (const char *string
, int field_width
, int precision
)
11167 const unsigned char *str
= (const unsigned char *) string
;
11169 ptrdiff_t dummy
, nbytes
;
11171 /* Copy at most PRECISION chars from STR. */
11172 nbytes
= strlen (string
);
11173 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
11175 store_mode_line_noprop_char (*str
++);
11177 /* Fill up with spaces until FIELD_WIDTH reached. */
11178 while (field_width
> 0
11179 && n
< field_width
)
11181 store_mode_line_noprop_char (' ');
11188 /***********************************************************************
11190 ***********************************************************************/
11192 #ifdef HAVE_WINDOW_SYSTEM
11194 /* Set the title of FRAME, if it has changed. The title format is
11195 Vicon_title_format if FRAME is iconified, otherwise it is
11196 frame_title_format. */
11199 x_consider_frame_title (Lisp_Object frame
)
11201 struct frame
*f
= XFRAME (frame
);
11203 if (FRAME_WINDOW_P (f
)
11204 || FRAME_MINIBUF_ONLY_P (f
)
11205 || f
->explicit_name
)
11207 /* Do we have more than one visible frame on this X display? */
11208 Lisp_Object tail
, other_frame
, fmt
;
11209 ptrdiff_t title_start
;
11213 ptrdiff_t count
= SPECPDL_INDEX ();
11215 FOR_EACH_FRAME (tail
, other_frame
)
11217 struct frame
*tf
= XFRAME (other_frame
);
11220 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
11221 && !FRAME_MINIBUF_ONLY_P (tf
)
11222 && !EQ (other_frame
, tip_frame
)
11223 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
11227 /* Set global variable indicating that multiple frames exist. */
11228 multiple_frames
= CONSP (tail
);
11230 /* Switch to the buffer of selected window of the frame. Set up
11231 mode_line_target so that display_mode_element will output into
11232 mode_line_noprop_buf; then display the title. */
11233 record_unwind_protect (unwind_format_mode_line
,
11234 format_mode_line_unwind_data
11235 (f
, current_buffer
, selected_window
, 0));
11237 Fselect_window (f
->selected_window
, Qt
);
11238 set_buffer_internal_1
11239 (XBUFFER (XWINDOW (f
->selected_window
)->contents
));
11240 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
11242 mode_line_target
= MODE_LINE_TITLE
;
11243 title_start
= MODE_LINE_NOPROP_LEN (0);
11244 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
11245 NULL
, DEFAULT_FACE_ID
);
11246 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
11247 len
= MODE_LINE_NOPROP_LEN (title_start
);
11248 title
= mode_line_noprop_buf
+ title_start
;
11249 unbind_to (count
, Qnil
);
11251 /* Set the title only if it's changed. This avoids consing in
11252 the common case where it hasn't. (If it turns out that we've
11253 already wasted too much time by walking through the list with
11254 display_mode_element, then we might need to optimize at a
11255 higher level than this.) */
11256 if (! STRINGP (f
->name
)
11257 || SBYTES (f
->name
) != len
11258 || memcmp (title
, SDATA (f
->name
), len
) != 0)
11259 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
11263 #endif /* not HAVE_WINDOW_SYSTEM */
11266 /***********************************************************************
11268 ***********************************************************************/
11271 /* Prepare for redisplay by updating menu-bar item lists when
11272 appropriate. This can call eval. */
11275 prepare_menu_bars (void)
11278 struct gcpro gcpro1
, gcpro2
;
11280 Lisp_Object tooltip_frame
;
11282 #ifdef HAVE_WINDOW_SYSTEM
11283 tooltip_frame
= tip_frame
;
11285 tooltip_frame
= Qnil
;
11288 /* Update all frame titles based on their buffer names, etc. We do
11289 this before the menu bars so that the buffer-menu will show the
11290 up-to-date frame titles. */
11291 #ifdef HAVE_WINDOW_SYSTEM
11292 if (windows_or_buffers_changed
|| update_mode_lines
)
11294 Lisp_Object tail
, frame
;
11296 FOR_EACH_FRAME (tail
, frame
)
11298 f
= XFRAME (frame
);
11299 if (!EQ (frame
, tooltip_frame
)
11300 && (FRAME_ICONIFIED_P (f
)
11301 || FRAME_VISIBLE_P (f
) == 1
11302 /* Exclude TTY frames that are obscured because they
11303 are not the top frame on their console. This is
11304 because x_consider_frame_title actually switches
11305 to the frame, which for TTY frames means it is
11306 marked as garbaged, and will be completely
11307 redrawn on the next redisplay cycle. This causes
11308 TTY frames to be completely redrawn, when there
11309 are more than one of them, even though nothing
11310 should be changed on display. */
11311 || (FRAME_VISIBLE_P (f
) == 2 && FRAME_WINDOW_P (f
))))
11312 x_consider_frame_title (frame
);
11315 #endif /* HAVE_WINDOW_SYSTEM */
11317 /* Update the menu bar item lists, if appropriate. This has to be
11318 done before any actual redisplay or generation of display lines. */
11319 all_windows
= (update_mode_lines
11320 || buffer_shared_and_changed ()
11321 || windows_or_buffers_changed
);
11324 Lisp_Object tail
, frame
;
11325 ptrdiff_t count
= SPECPDL_INDEX ();
11326 /* 1 means that update_menu_bar has run its hooks
11327 so any further calls to update_menu_bar shouldn't do so again. */
11328 int menu_bar_hooks_run
= 0;
11330 record_unwind_save_match_data ();
11332 FOR_EACH_FRAME (tail
, frame
)
11334 f
= XFRAME (frame
);
11336 /* Ignore tooltip frame. */
11337 if (EQ (frame
, tooltip_frame
))
11340 /* If a window on this frame changed size, report that to
11341 the user and clear the size-change flag. */
11342 if (FRAME_WINDOW_SIZES_CHANGED (f
))
11344 Lisp_Object functions
;
11346 /* Clear flag first in case we get an error below. */
11347 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
11348 functions
= Vwindow_size_change_functions
;
11349 GCPRO2 (tail
, functions
);
11351 while (CONSP (functions
))
11353 if (!EQ (XCAR (functions
), Qt
))
11354 call1 (XCAR (functions
), frame
);
11355 functions
= XCDR (functions
);
11361 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
11362 #ifdef HAVE_WINDOW_SYSTEM
11363 update_tool_bar (f
, 0);
11366 if (windows_or_buffers_changed
11369 (f
, Fbuffer_modified_p (XWINDOW (f
->selected_window
)->contents
));
11374 unbind_to (count
, Qnil
);
11378 struct frame
*sf
= SELECTED_FRAME ();
11379 update_menu_bar (sf
, 1, 0);
11380 #ifdef HAVE_WINDOW_SYSTEM
11381 update_tool_bar (sf
, 1);
11387 /* Update the menu bar item list for frame F. This has to be done
11388 before we start to fill in any display lines, because it can call
11391 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
11393 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
11394 already ran the menu bar hooks for this redisplay, so there
11395 is no need to run them again. The return value is the
11396 updated value of this flag, to pass to the next call. */
11399 update_menu_bar (struct frame
*f
, int save_match_data
, int hooks_run
)
11401 Lisp_Object window
;
11402 register struct window
*w
;
11404 /* If called recursively during a menu update, do nothing. This can
11405 happen when, for instance, an activate-menubar-hook causes a
11407 if (inhibit_menubar_update
)
11410 window
= FRAME_SELECTED_WINDOW (f
);
11411 w
= XWINDOW (window
);
11413 if (FRAME_WINDOW_P (f
)
11415 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11416 || defined (HAVE_NS) || defined (USE_GTK)
11417 FRAME_EXTERNAL_MENU_BAR (f
)
11419 FRAME_MENU_BAR_LINES (f
) > 0
11421 : FRAME_MENU_BAR_LINES (f
) > 0)
11423 /* If the user has switched buffers or windows, we need to
11424 recompute to reflect the new bindings. But we'll
11425 recompute when update_mode_lines is set too; that means
11426 that people can use force-mode-line-update to request
11427 that the menu bar be recomputed. The adverse effect on
11428 the rest of the redisplay algorithm is about the same as
11429 windows_or_buffers_changed anyway. */
11430 if (windows_or_buffers_changed
11431 /* This used to test w->update_mode_line, but we believe
11432 there is no need to recompute the menu in that case. */
11433 || update_mode_lines
11434 || window_buffer_changed (w
))
11436 struct buffer
*prev
= current_buffer
;
11437 ptrdiff_t count
= SPECPDL_INDEX ();
11439 specbind (Qinhibit_menubar_update
, Qt
);
11441 set_buffer_internal_1 (XBUFFER (w
->contents
));
11442 if (save_match_data
)
11443 record_unwind_save_match_data ();
11444 if (NILP (Voverriding_local_map_menu_flag
))
11446 specbind (Qoverriding_terminal_local_map
, Qnil
);
11447 specbind (Qoverriding_local_map
, Qnil
);
11452 /* Run the Lucid hook. */
11453 safe_run_hooks (Qactivate_menubar_hook
);
11455 /* If it has changed current-menubar from previous value,
11456 really recompute the menu-bar from the value. */
11457 if (! NILP (Vlucid_menu_bar_dirty_flag
))
11458 call0 (Qrecompute_lucid_menubar
);
11460 safe_run_hooks (Qmenu_bar_update_hook
);
11465 XSETFRAME (Vmenu_updating_frame
, f
);
11466 fset_menu_bar_items (f
, menu_bar_items (FRAME_MENU_BAR_ITEMS (f
)));
11468 /* Redisplay the menu bar in case we changed it. */
11469 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11470 || defined (HAVE_NS) || defined (USE_GTK)
11471 if (FRAME_WINDOW_P (f
))
11473 #if defined (HAVE_NS)
11474 /* All frames on Mac OS share the same menubar. So only
11475 the selected frame should be allowed to set it. */
11476 if (f
== SELECTED_FRAME ())
11478 set_frame_menubar (f
, 0, 0);
11481 /* On a terminal screen, the menu bar is an ordinary screen
11482 line, and this makes it get updated. */
11483 w
->update_mode_line
= 1;
11484 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11485 /* In the non-toolkit version, the menu bar is an ordinary screen
11486 line, and this makes it get updated. */
11487 w
->update_mode_line
= 1;
11488 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11490 unbind_to (count
, Qnil
);
11491 set_buffer_internal_1 (prev
);
11500 /***********************************************************************
11502 ***********************************************************************/
11504 #ifdef HAVE_WINDOW_SYSTEM
11507 Nominal cursor position -- where to draw output.
11508 HPOS and VPOS are window relative glyph matrix coordinates.
11509 X and Y are window relative pixel coordinates. */
11511 struct cursor_pos output_cursor
;
11515 Set the global variable output_cursor to CURSOR. All cursor
11516 positions are relative to currently updated window. */
11519 set_output_cursor (struct cursor_pos
*cursor
)
11521 output_cursor
.hpos
= cursor
->hpos
;
11522 output_cursor
.vpos
= cursor
->vpos
;
11523 output_cursor
.x
= cursor
->x
;
11524 output_cursor
.y
= cursor
->y
;
11529 Set a nominal cursor position.
11531 HPOS and VPOS are column/row positions in a window glyph matrix.
11532 X and Y are window text area relative pixel positions.
11534 This is always done during window update, so the position is the
11535 future output cursor position for currently updated window W.
11536 NOTE: W is used only to check whether this function is called
11537 in a consistent manner via the redisplay interface. */
11540 x_cursor_to (struct window
*w
, int vpos
, int hpos
, int y
, int x
)
11544 /* Set the output cursor. */
11545 output_cursor
.hpos
= hpos
;
11546 output_cursor
.vpos
= vpos
;
11547 output_cursor
.x
= x
;
11548 output_cursor
.y
= y
;
11551 #endif /* HAVE_WINDOW_SYSTEM */
11554 /***********************************************************************
11556 ***********************************************************************/
11558 #ifdef HAVE_WINDOW_SYSTEM
11560 /* Where the mouse was last time we reported a mouse event. */
11562 struct frame
*last_mouse_frame
;
11564 /* Tool-bar item index of the item on which a mouse button was pressed
11567 int last_tool_bar_item
;
11569 /* Select `frame' temporarily without running all the code in
11571 FIXME: Maybe do_switch_frame should be trimmed down similarly
11572 when `norecord' is set. */
11574 fast_set_selected_frame (Lisp_Object frame
)
11576 if (!EQ (selected_frame
, frame
))
11578 selected_frame
= frame
;
11579 selected_window
= XFRAME (frame
)->selected_window
;
11583 /* Update the tool-bar item list for frame F. This has to be done
11584 before we start to fill in any display lines. Called from
11585 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
11586 and restore it here. */
11589 update_tool_bar (struct frame
*f
, int save_match_data
)
11591 #if defined (USE_GTK) || defined (HAVE_NS)
11592 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
11594 int do_update
= WINDOWP (f
->tool_bar_window
)
11595 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
11600 Lisp_Object window
;
11603 window
= FRAME_SELECTED_WINDOW (f
);
11604 w
= XWINDOW (window
);
11606 /* If the user has switched buffers or windows, we need to
11607 recompute to reflect the new bindings. But we'll
11608 recompute when update_mode_lines is set too; that means
11609 that people can use force-mode-line-update to request
11610 that the menu bar be recomputed. The adverse effect on
11611 the rest of the redisplay algorithm is about the same as
11612 windows_or_buffers_changed anyway. */
11613 if (windows_or_buffers_changed
11614 || w
->update_mode_line
11615 || update_mode_lines
11616 || window_buffer_changed (w
))
11618 struct buffer
*prev
= current_buffer
;
11619 ptrdiff_t count
= SPECPDL_INDEX ();
11620 Lisp_Object frame
, new_tool_bar
;
11621 int new_n_tool_bar
;
11622 struct gcpro gcpro1
;
11624 /* Set current_buffer to the buffer of the selected
11625 window of the frame, so that we get the right local
11627 set_buffer_internal_1 (XBUFFER (w
->contents
));
11629 /* Save match data, if we must. */
11630 if (save_match_data
)
11631 record_unwind_save_match_data ();
11633 /* Make sure that we don't accidentally use bogus keymaps. */
11634 if (NILP (Voverriding_local_map_menu_flag
))
11636 specbind (Qoverriding_terminal_local_map
, Qnil
);
11637 specbind (Qoverriding_local_map
, Qnil
);
11640 GCPRO1 (new_tool_bar
);
11642 /* We must temporarily set the selected frame to this frame
11643 before calling tool_bar_items, because the calculation of
11644 the tool-bar keymap uses the selected frame (see
11645 `tool-bar-make-keymap' in tool-bar.el). */
11646 eassert (EQ (selected_window
,
11647 /* Since we only explicitly preserve selected_frame,
11648 check that selected_window would be redundant. */
11649 XFRAME (selected_frame
)->selected_window
));
11650 record_unwind_protect (fast_set_selected_frame
, selected_frame
);
11651 XSETFRAME (frame
, f
);
11652 fast_set_selected_frame (frame
);
11654 /* Build desired tool-bar items from keymaps. */
11656 = tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
11659 /* Redisplay the tool-bar if we changed it. */
11660 if (new_n_tool_bar
!= f
->n_tool_bar_items
11661 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
11663 /* Redisplay that happens asynchronously due to an expose event
11664 may access f->tool_bar_items. Make sure we update both
11665 variables within BLOCK_INPUT so no such event interrupts. */
11667 fset_tool_bar_items (f
, new_tool_bar
);
11668 f
->n_tool_bar_items
= new_n_tool_bar
;
11669 w
->update_mode_line
= 1;
11675 unbind_to (count
, Qnil
);
11676 set_buffer_internal_1 (prev
);
11682 /* Set F->desired_tool_bar_string to a Lisp string representing frame
11683 F's desired tool-bar contents. F->tool_bar_items must have
11684 been set up previously by calling prepare_menu_bars. */
11687 build_desired_tool_bar_string (struct frame
*f
)
11689 int i
, size
, size_needed
;
11690 struct gcpro gcpro1
, gcpro2
, gcpro3
;
11691 Lisp_Object image
, plist
, props
;
11693 image
= plist
= props
= Qnil
;
11694 GCPRO3 (image
, plist
, props
);
11696 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
11697 Otherwise, make a new string. */
11699 /* The size of the string we might be able to reuse. */
11700 size
= (STRINGP (f
->desired_tool_bar_string
)
11701 ? SCHARS (f
->desired_tool_bar_string
)
11704 /* We need one space in the string for each image. */
11705 size_needed
= f
->n_tool_bar_items
;
11707 /* Reuse f->desired_tool_bar_string, if possible. */
11708 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
11709 fset_desired_tool_bar_string
11710 (f
, Fmake_string (make_number (size_needed
), make_number (' ')));
11713 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
11714 Fremove_text_properties (make_number (0), make_number (size
),
11715 props
, f
->desired_tool_bar_string
);
11718 /* Put a `display' property on the string for the images to display,
11719 put a `menu_item' property on tool-bar items with a value that
11720 is the index of the item in F's tool-bar item vector. */
11721 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
11723 #define PROP(IDX) \
11724 AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
11726 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
11727 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
11728 int hmargin
, vmargin
, relief
, idx
, end
;
11730 /* If image is a vector, choose the image according to the
11732 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
11733 if (VECTORP (image
))
11737 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
11738 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
11741 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
11742 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
11744 eassert (ASIZE (image
) >= idx
);
11745 image
= AREF (image
, idx
);
11750 /* Ignore invalid image specifications. */
11751 if (!valid_image_p (image
))
11754 /* Display the tool-bar button pressed, or depressed. */
11755 plist
= Fcopy_sequence (XCDR (image
));
11757 /* Compute margin and relief to draw. */
11758 relief
= (tool_bar_button_relief
>= 0
11759 ? tool_bar_button_relief
11760 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
11761 hmargin
= vmargin
= relief
;
11763 if (RANGED_INTEGERP (1, Vtool_bar_button_margin
,
11764 INT_MAX
- max (hmargin
, vmargin
)))
11766 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
11767 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
11769 else if (CONSP (Vtool_bar_button_margin
))
11771 if (RANGED_INTEGERP (1, XCAR (Vtool_bar_button_margin
),
11772 INT_MAX
- hmargin
))
11773 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
11775 if (RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin
),
11776 INT_MAX
- vmargin
))
11777 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
11780 if (auto_raise_tool_bar_buttons_p
)
11782 /* Add a `:relief' property to the image spec if the item is
11786 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
11793 /* If image is selected, display it pressed, i.e. with a
11794 negative relief. If it's not selected, display it with a
11796 plist
= Fplist_put (plist
, QCrelief
,
11798 ? make_number (-relief
)
11799 : make_number (relief
)));
11804 /* Put a margin around the image. */
11805 if (hmargin
|| vmargin
)
11807 if (hmargin
== vmargin
)
11808 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
11810 plist
= Fplist_put (plist
, QCmargin
,
11811 Fcons (make_number (hmargin
),
11812 make_number (vmargin
)));
11815 /* If button is not enabled, and we don't have special images
11816 for the disabled state, make the image appear disabled by
11817 applying an appropriate algorithm to it. */
11818 if (!enabled_p
&& idx
< 0)
11819 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
11821 /* Put a `display' text property on the string for the image to
11822 display. Put a `menu-item' property on the string that gives
11823 the start of this item's properties in the tool-bar items
11825 image
= Fcons (Qimage
, plist
);
11826 props
= list4 (Qdisplay
, image
,
11827 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
11829 /* Let the last image hide all remaining spaces in the tool bar
11830 string. The string can be longer than needed when we reuse a
11831 previous string. */
11832 if (i
+ 1 == f
->n_tool_bar_items
)
11833 end
= SCHARS (f
->desired_tool_bar_string
);
11836 Fadd_text_properties (make_number (i
), make_number (end
),
11837 props
, f
->desired_tool_bar_string
);
11845 /* Display one line of the tool-bar of frame IT->f.
11847 HEIGHT specifies the desired height of the tool-bar line.
11848 If the actual height of the glyph row is less than HEIGHT, the
11849 row's height is increased to HEIGHT, and the icons are centered
11850 vertically in the new height.
11852 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
11853 count a final empty row in case the tool-bar width exactly matches
11858 display_tool_bar_line (struct it
*it
, int height
)
11860 struct glyph_row
*row
= it
->glyph_row
;
11861 int max_x
= it
->last_visible_x
;
11862 struct glyph
*last
;
11864 prepare_desired_row (row
);
11865 row
->y
= it
->current_y
;
11867 /* Note that this isn't made use of if the face hasn't a box,
11868 so there's no need to check the face here. */
11869 it
->start_of_box_run_p
= 1;
11871 while (it
->current_x
< max_x
)
11873 int x
, n_glyphs_before
, i
, nglyphs
;
11874 struct it it_before
;
11876 /* Get the next display element. */
11877 if (!get_next_display_element (it
))
11879 /* Don't count empty row if we are counting needed tool-bar lines. */
11880 if (height
< 0 && !it
->hpos
)
11885 /* Produce glyphs. */
11886 n_glyphs_before
= row
->used
[TEXT_AREA
];
11889 PRODUCE_GLYPHS (it
);
11891 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
11893 x
= it_before
.current_x
;
11894 while (i
< nglyphs
)
11896 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
11898 if (x
+ glyph
->pixel_width
> max_x
)
11900 /* Glyph doesn't fit on line. Backtrack. */
11901 row
->used
[TEXT_AREA
] = n_glyphs_before
;
11903 /* If this is the only glyph on this line, it will never fit on the
11904 tool-bar, so skip it. But ensure there is at least one glyph,
11905 so we don't accidentally disable the tool-bar. */
11906 if (n_glyphs_before
== 0
11907 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
11913 x
+= glyph
->pixel_width
;
11917 /* Stop at line end. */
11918 if (ITERATOR_AT_END_OF_LINE_P (it
))
11921 set_iterator_to_next (it
, 1);
11926 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
11928 /* Use default face for the border below the tool bar.
11930 FIXME: When auto-resize-tool-bars is grow-only, there is
11931 no additional border below the possibly empty tool-bar lines.
11932 So to make the extra empty lines look "normal", we have to
11933 use the tool-bar face for the border too. */
11934 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
)
11935 && !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
11936 it
->face_id
= DEFAULT_FACE_ID
;
11938 extend_face_to_end_of_line (it
);
11939 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
11940 last
->right_box_line_p
= 1;
11941 if (last
== row
->glyphs
[TEXT_AREA
])
11942 last
->left_box_line_p
= 1;
11944 /* Make line the desired height and center it vertically. */
11945 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
11947 /* Don't add more than one line height. */
11948 height
%= FRAME_LINE_HEIGHT (it
->f
);
11949 it
->max_ascent
+= height
/ 2;
11950 it
->max_descent
+= (height
+ 1) / 2;
11953 compute_line_metrics (it
);
11955 /* If line is empty, make it occupy the rest of the tool-bar. */
11956 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11958 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
11959 row
->visible_height
= row
->height
;
11960 row
->ascent
= row
->phys_ascent
= 0;
11961 row
->extra_line_spacing
= 0;
11964 row
->full_width_p
= 1;
11965 row
->continued_p
= 0;
11966 row
->truncated_on_left_p
= 0;
11967 row
->truncated_on_right_p
= 0;
11969 it
->current_x
= it
->hpos
= 0;
11970 it
->current_y
+= row
->height
;
11976 /* Max tool-bar height. */
11978 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
11979 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
11981 /* Value is the number of screen lines needed to make all tool-bar
11982 items of frame F visible. The number of actual rows needed is
11983 returned in *N_ROWS if non-NULL. */
11986 tool_bar_lines_needed (struct frame
*f
, int *n_rows
)
11988 struct window
*w
= XWINDOW (f
->tool_bar_window
);
11990 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
11991 the desired matrix, so use (unused) mode-line row as temporary row to
11992 avoid destroying the first tool-bar row. */
11993 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
11995 /* Initialize an iterator for iteration over
11996 F->desired_tool_bar_string in the tool-bar window of frame F. */
11997 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
11998 it
.first_visible_x
= 0;
11999 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
12000 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
12001 it
.paragraph_embedding
= L2R
;
12003 while (!ITERATOR_AT_END_P (&it
))
12005 clear_glyph_row (temp_row
);
12006 it
.glyph_row
= temp_row
;
12007 display_tool_bar_line (&it
, -1);
12009 clear_glyph_row (temp_row
);
12011 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
12013 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
12015 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
12019 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
12021 doc
: /* Return the number of lines occupied by the tool bar of FRAME.
12022 If FRAME is nil or omitted, use the selected frame. */)
12023 (Lisp_Object frame
)
12025 struct frame
*f
= decode_any_frame (frame
);
12029 if (WINDOWP (f
->tool_bar_window
)
12030 && (w
= XWINDOW (f
->tool_bar_window
),
12031 WINDOW_TOTAL_LINES (w
) > 0))
12033 update_tool_bar (f
, 1);
12034 if (f
->n_tool_bar_items
)
12036 build_desired_tool_bar_string (f
);
12037 nlines
= tool_bar_lines_needed (f
, NULL
);
12041 return make_number (nlines
);
12045 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
12046 height should be changed. */
12049 redisplay_tool_bar (struct frame
*f
)
12053 struct glyph_row
*row
;
12055 #if defined (USE_GTK) || defined (HAVE_NS)
12056 if (FRAME_EXTERNAL_TOOL_BAR (f
))
12057 update_frame_tool_bar (f
);
12061 /* If frame hasn't a tool-bar window or if it is zero-height, don't
12062 do anything. This means you must start with tool-bar-lines
12063 non-zero to get the auto-sizing effect. Or in other words, you
12064 can turn off tool-bars by specifying tool-bar-lines zero. */
12065 if (!WINDOWP (f
->tool_bar_window
)
12066 || (w
= XWINDOW (f
->tool_bar_window
),
12067 WINDOW_TOTAL_LINES (w
) == 0))
12070 /* Set up an iterator for the tool-bar window. */
12071 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
12072 it
.first_visible_x
= 0;
12073 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
12074 row
= it
.glyph_row
;
12076 /* Build a string that represents the contents of the tool-bar. */
12077 build_desired_tool_bar_string (f
);
12078 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
12079 /* FIXME: This should be controlled by a user option. But it
12080 doesn't make sense to have an R2L tool bar if the menu bar cannot
12081 be drawn also R2L, and making the menu bar R2L is tricky due
12082 toolkit-specific code that implements it. If an R2L tool bar is
12083 ever supported, display_tool_bar_line should also be augmented to
12084 call unproduce_glyphs like display_line and display_string
12086 it
.paragraph_embedding
= L2R
;
12088 if (f
->n_tool_bar_rows
== 0)
12092 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
12093 nlines
!= WINDOW_TOTAL_LINES (w
)))
12096 int old_height
= WINDOW_TOTAL_LINES (w
);
12098 XSETFRAME (frame
, f
);
12099 Fmodify_frame_parameters (frame
,
12100 list1 (Fcons (Qtool_bar_lines
,
12101 make_number (nlines
))));
12102 if (WINDOW_TOTAL_LINES (w
) != old_height
)
12104 clear_glyph_matrix (w
->desired_matrix
);
12105 fonts_changed_p
= 1;
12111 /* Display as many lines as needed to display all tool-bar items. */
12113 if (f
->n_tool_bar_rows
> 0)
12115 int border
, rows
, height
, extra
;
12117 if (TYPE_RANGED_INTEGERP (int, Vtool_bar_border
))
12118 border
= XINT (Vtool_bar_border
);
12119 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
12120 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
12121 else if (EQ (Vtool_bar_border
, Qborder_width
))
12122 border
= f
->border_width
;
12128 rows
= f
->n_tool_bar_rows
;
12129 height
= max (1, (it
.last_visible_y
- border
) / rows
);
12130 extra
= it
.last_visible_y
- border
- height
* rows
;
12132 while (it
.current_y
< it
.last_visible_y
)
12135 if (extra
> 0 && rows
-- > 0)
12137 h
= (extra
+ rows
- 1) / rows
;
12140 display_tool_bar_line (&it
, height
+ h
);
12145 while (it
.current_y
< it
.last_visible_y
)
12146 display_tool_bar_line (&it
, 0);
12149 /* It doesn't make much sense to try scrolling in the tool-bar
12150 window, so don't do it. */
12151 w
->desired_matrix
->no_scrolling_p
= 1;
12152 w
->must_be_updated_p
= 1;
12154 if (!NILP (Vauto_resize_tool_bars
))
12156 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
12157 int change_height_p
= 0;
12159 /* If we couldn't display everything, change the tool-bar's
12160 height if there is room for more. */
12161 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
12162 && it
.current_y
< max_tool_bar_height
)
12163 change_height_p
= 1;
12165 row
= it
.glyph_row
- 1;
12167 /* If there are blank lines at the end, except for a partially
12168 visible blank line at the end that is smaller than
12169 FRAME_LINE_HEIGHT, change the tool-bar's height. */
12170 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12171 && row
->height
>= FRAME_LINE_HEIGHT (f
))
12172 change_height_p
= 1;
12174 /* If row displays tool-bar items, but is partially visible,
12175 change the tool-bar's height. */
12176 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12177 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
12178 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
12179 change_height_p
= 1;
12181 /* Resize windows as needed by changing the `tool-bar-lines'
12182 frame parameter. */
12183 if (change_height_p
)
12186 int old_height
= WINDOW_TOTAL_LINES (w
);
12188 int nlines
= tool_bar_lines_needed (f
, &nrows
);
12190 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
12191 && !f
->minimize_tool_bar_window_p
)
12192 ? (nlines
> old_height
)
12193 : (nlines
!= old_height
));
12194 f
->minimize_tool_bar_window_p
= 0;
12196 if (change_height_p
)
12198 XSETFRAME (frame
, f
);
12199 Fmodify_frame_parameters (frame
,
12200 list1 (Fcons (Qtool_bar_lines
,
12201 make_number (nlines
))));
12202 if (WINDOW_TOTAL_LINES (w
) != old_height
)
12204 clear_glyph_matrix (w
->desired_matrix
);
12205 f
->n_tool_bar_rows
= nrows
;
12206 fonts_changed_p
= 1;
12213 f
->minimize_tool_bar_window_p
= 0;
12218 /* Get information about the tool-bar item which is displayed in GLYPH
12219 on frame F. Return in *PROP_IDX the index where tool-bar item
12220 properties start in F->tool_bar_items. Value is zero if
12221 GLYPH doesn't display a tool-bar item. */
12224 tool_bar_item_info (struct frame
*f
, struct glyph
*glyph
, int *prop_idx
)
12230 /* This function can be called asynchronously, which means we must
12231 exclude any possibility that Fget_text_property signals an
12233 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
12234 charpos
= max (0, charpos
);
12236 /* Get the text property `menu-item' at pos. The value of that
12237 property is the start index of this item's properties in
12238 F->tool_bar_items. */
12239 prop
= Fget_text_property (make_number (charpos
),
12240 Qmenu_item
, f
->current_tool_bar_string
);
12241 if (INTEGERP (prop
))
12243 *prop_idx
= XINT (prop
);
12253 /* Get information about the tool-bar item at position X/Y on frame F.
12254 Return in *GLYPH a pointer to the glyph of the tool-bar item in
12255 the current matrix of the tool-bar window of F, or NULL if not
12256 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
12257 item in F->tool_bar_items. Value is
12259 -1 if X/Y is not on a tool-bar item
12260 0 if X/Y is on the same item that was highlighted before.
12264 get_tool_bar_item (struct frame
*f
, int x
, int y
, struct glyph
**glyph
,
12265 int *hpos
, int *vpos
, int *prop_idx
)
12267 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12268 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12271 /* Find the glyph under X/Y. */
12272 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
12273 if (*glyph
== NULL
)
12276 /* Get the start of this tool-bar item's properties in
12277 f->tool_bar_items. */
12278 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
12281 /* Is mouse on the highlighted item? */
12282 if (EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
)
12283 && *vpos
>= hlinfo
->mouse_face_beg_row
12284 && *vpos
<= hlinfo
->mouse_face_end_row
12285 && (*vpos
> hlinfo
->mouse_face_beg_row
12286 || *hpos
>= hlinfo
->mouse_face_beg_col
)
12287 && (*vpos
< hlinfo
->mouse_face_end_row
12288 || *hpos
< hlinfo
->mouse_face_end_col
12289 || hlinfo
->mouse_face_past_end
))
12297 Handle mouse button event on the tool-bar of frame F, at
12298 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
12299 0 for button release. MODIFIERS is event modifiers for button
12303 handle_tool_bar_click (struct frame
*f
, int x
, int y
, int down_p
,
12306 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12307 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12308 int hpos
, vpos
, prop_idx
;
12309 struct glyph
*glyph
;
12310 Lisp_Object enabled_p
;
12313 /* If not on the highlighted tool-bar item, and mouse-highlight is
12314 non-nil, return. This is so we generate the tool-bar button
12315 click only when the mouse button is released on the same item as
12316 where it was pressed. However, when mouse-highlight is disabled,
12317 generate the click when the button is released regardless of the
12318 highlight, since tool-bar items are not highlighted in that
12320 frame_to_window_pixel_xy (w
, &x
, &y
);
12321 ts
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
12323 || (ts
!= 0 && !NILP (Vmouse_highlight
)))
12326 /* When mouse-highlight is off, generate the click for the item
12327 where the button was pressed, disregarding where it was
12329 if (NILP (Vmouse_highlight
) && !down_p
)
12330 prop_idx
= last_tool_bar_item
;
12332 /* If item is disabled, do nothing. */
12333 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12334 if (NILP (enabled_p
))
12339 /* Show item in pressed state. */
12340 if (!NILP (Vmouse_highlight
))
12341 show_mouse_face (hlinfo
, DRAW_IMAGE_SUNKEN
);
12342 last_tool_bar_item
= prop_idx
;
12346 Lisp_Object key
, frame
;
12347 struct input_event event
;
12348 EVENT_INIT (event
);
12350 /* Show item in released state. */
12351 if (!NILP (Vmouse_highlight
))
12352 show_mouse_face (hlinfo
, DRAW_IMAGE_RAISED
);
12354 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
12356 XSETFRAME (frame
, f
);
12357 event
.kind
= TOOL_BAR_EVENT
;
12358 event
.frame_or_window
= frame
;
12360 kbd_buffer_store_event (&event
);
12362 event
.kind
= TOOL_BAR_EVENT
;
12363 event
.frame_or_window
= frame
;
12365 event
.modifiers
= modifiers
;
12366 kbd_buffer_store_event (&event
);
12367 last_tool_bar_item
= -1;
12372 /* Possibly highlight a tool-bar item on frame F when mouse moves to
12373 tool-bar window-relative coordinates X/Y. Called from
12374 note_mouse_highlight. */
12377 note_tool_bar_highlight (struct frame
*f
, int x
, int y
)
12379 Lisp_Object window
= f
->tool_bar_window
;
12380 struct window
*w
= XWINDOW (window
);
12381 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12382 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12384 struct glyph
*glyph
;
12385 struct glyph_row
*row
;
12387 Lisp_Object enabled_p
;
12389 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
12390 int mouse_down_p
, rc
;
12392 /* Function note_mouse_highlight is called with negative X/Y
12393 values when mouse moves outside of the frame. */
12394 if (x
<= 0 || y
<= 0)
12396 clear_mouse_face (hlinfo
);
12400 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
12403 /* Not on tool-bar item. */
12404 clear_mouse_face (hlinfo
);
12408 /* On same tool-bar item as before. */
12409 goto set_help_echo
;
12411 clear_mouse_face (hlinfo
);
12413 /* Mouse is down, but on different tool-bar item? */
12414 mouse_down_p
= (dpyinfo
->grabbed
12415 && f
== last_mouse_frame
12416 && FRAME_LIVE_P (f
));
12418 && last_tool_bar_item
!= prop_idx
)
12421 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
12423 /* If tool-bar item is not enabled, don't highlight it. */
12424 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12425 if (!NILP (enabled_p
) && !NILP (Vmouse_highlight
))
12427 /* Compute the x-position of the glyph. In front and past the
12428 image is a space. We include this in the highlighted area. */
12429 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
12430 for (i
= x
= 0; i
< hpos
; ++i
)
12431 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
12433 /* Record this as the current active region. */
12434 hlinfo
->mouse_face_beg_col
= hpos
;
12435 hlinfo
->mouse_face_beg_row
= vpos
;
12436 hlinfo
->mouse_face_beg_x
= x
;
12437 hlinfo
->mouse_face_beg_y
= row
->y
;
12438 hlinfo
->mouse_face_past_end
= 0;
12440 hlinfo
->mouse_face_end_col
= hpos
+ 1;
12441 hlinfo
->mouse_face_end_row
= vpos
;
12442 hlinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
12443 hlinfo
->mouse_face_end_y
= row
->y
;
12444 hlinfo
->mouse_face_window
= window
;
12445 hlinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
12447 /* Display it as active. */
12448 show_mouse_face (hlinfo
, draw
);
12453 /* Set help_echo_string to a help string to display for this tool-bar item.
12454 XTread_socket does the rest. */
12455 help_echo_object
= help_echo_window
= Qnil
;
12456 help_echo_pos
= -1;
12457 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
12458 if (NILP (help_echo_string
))
12459 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
12462 #endif /* HAVE_WINDOW_SYSTEM */
12466 /************************************************************************
12467 Horizontal scrolling
12468 ************************************************************************/
12470 static int hscroll_window_tree (Lisp_Object
);
12471 static int hscroll_windows (Lisp_Object
);
12473 /* For all leaf windows in the window tree rooted at WINDOW, set their
12474 hscroll value so that PT is (i) visible in the window, and (ii) so
12475 that it is not within a certain margin at the window's left and
12476 right border. Value is non-zero if any window's hscroll has been
12480 hscroll_window_tree (Lisp_Object window
)
12482 int hscrolled_p
= 0;
12483 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
12484 int hscroll_step_abs
= 0;
12485 double hscroll_step_rel
= 0;
12487 if (hscroll_relative_p
)
12489 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
12490 if (hscroll_step_rel
< 0)
12492 hscroll_relative_p
= 0;
12493 hscroll_step_abs
= 0;
12496 else if (TYPE_RANGED_INTEGERP (int, Vhscroll_step
))
12498 hscroll_step_abs
= XINT (Vhscroll_step
);
12499 if (hscroll_step_abs
< 0)
12500 hscroll_step_abs
= 0;
12503 hscroll_step_abs
= 0;
12505 while (WINDOWP (window
))
12507 struct window
*w
= XWINDOW (window
);
12509 if (WINDOWP (w
->contents
))
12510 hscrolled_p
|= hscroll_window_tree (w
->contents
);
12511 else if (w
->cursor
.vpos
>= 0)
12514 int text_area_width
;
12515 struct glyph_row
*current_cursor_row
12516 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
12517 struct glyph_row
*desired_cursor_row
12518 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
12519 struct glyph_row
*cursor_row
12520 = (desired_cursor_row
->enabled_p
12521 ? desired_cursor_row
12522 : current_cursor_row
);
12523 int row_r2l_p
= cursor_row
->reversed_p
;
12525 text_area_width
= window_box_width (w
, TEXT_AREA
);
12527 /* Scroll when cursor is inside this scroll margin. */
12528 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
12530 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->contents
))
12531 /* For left-to-right rows, hscroll when cursor is either
12532 (i) inside the right hscroll margin, or (ii) if it is
12533 inside the left margin and the window is already
12537 && w
->cursor
.x
<= h_margin
)
12538 || (cursor_row
->enabled_p
12539 && cursor_row
->truncated_on_right_p
12540 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
12541 /* For right-to-left rows, the logic is similar,
12542 except that rules for scrolling to left and right
12543 are reversed. E.g., if cursor.x <= h_margin, we
12544 need to hscroll "to the right" unconditionally,
12545 and that will scroll the screen to the left so as
12546 to reveal the next portion of the row. */
12548 && ((cursor_row
->enabled_p
12549 /* FIXME: It is confusing to set the
12550 truncated_on_right_p flag when R2L rows
12551 are actually truncated on the left. */
12552 && cursor_row
->truncated_on_right_p
12553 && w
->cursor
.x
<= h_margin
)
12555 && (w
->cursor
.x
>= text_area_width
- h_margin
))))))
12559 struct buffer
*saved_current_buffer
;
12563 /* Find point in a display of infinite width. */
12564 saved_current_buffer
= current_buffer
;
12565 current_buffer
= XBUFFER (w
->contents
);
12567 if (w
== XWINDOW (selected_window
))
12570 pt
= clip_to_bounds (BEGV
, marker_position (w
->pointm
), ZV
);
12572 /* Move iterator to pt starting at cursor_row->start in
12573 a line with infinite width. */
12574 init_to_row_start (&it
, w
, cursor_row
);
12575 it
.last_visible_x
= INFINITY
;
12576 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
12577 current_buffer
= saved_current_buffer
;
12579 /* Position cursor in window. */
12580 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
12581 hscroll
= max (0, (it
.current_x
12582 - (ITERATOR_AT_END_OF_LINE_P (&it
)
12583 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
12584 : (text_area_width
/ 2))))
12585 / FRAME_COLUMN_WIDTH (it
.f
);
12586 else if ((!row_r2l_p
12587 && w
->cursor
.x
>= text_area_width
- h_margin
)
12588 || (row_r2l_p
&& w
->cursor
.x
<= h_margin
))
12590 if (hscroll_relative_p
)
12591 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
12594 wanted_x
= text_area_width
12595 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12598 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12602 if (hscroll_relative_p
)
12603 wanted_x
= text_area_width
* hscroll_step_rel
12606 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12609 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12611 hscroll
= max (hscroll
, w
->min_hscroll
);
12613 /* Don't prevent redisplay optimizations if hscroll
12614 hasn't changed, as it will unnecessarily slow down
12616 if (w
->hscroll
!= hscroll
)
12618 XBUFFER (w
->contents
)->prevent_redisplay_optimizations_p
= 1;
12619 w
->hscroll
= hscroll
;
12628 /* Value is non-zero if hscroll of any leaf window has been changed. */
12629 return hscrolled_p
;
12633 /* Set hscroll so that cursor is visible and not inside horizontal
12634 scroll margins for all windows in the tree rooted at WINDOW. See
12635 also hscroll_window_tree above. Value is non-zero if any window's
12636 hscroll has been changed. If it has, desired matrices on the frame
12637 of WINDOW are cleared. */
12640 hscroll_windows (Lisp_Object window
)
12642 int hscrolled_p
= hscroll_window_tree (window
);
12644 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
12645 return hscrolled_p
;
12650 /************************************************************************
12652 ************************************************************************/
12654 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
12655 to a non-zero value. This is sometimes handy to have in a debugger
12660 /* First and last unchanged row for try_window_id. */
12662 static int debug_first_unchanged_at_end_vpos
;
12663 static int debug_last_unchanged_at_beg_vpos
;
12665 /* Delta vpos and y. */
12667 static int debug_dvpos
, debug_dy
;
12669 /* Delta in characters and bytes for try_window_id. */
12671 static ptrdiff_t debug_delta
, debug_delta_bytes
;
12673 /* Values of window_end_pos and window_end_vpos at the end of
12676 static ptrdiff_t debug_end_vpos
;
12678 /* Append a string to W->desired_matrix->method. FMT is a printf
12679 format string. If trace_redisplay_p is non-zero also printf the
12680 resulting string to stderr. */
12682 static void debug_method_add (struct window
*, char const *, ...)
12683 ATTRIBUTE_FORMAT_PRINTF (2, 3);
12686 debug_method_add (struct window
*w
, char const *fmt
, ...)
12689 char *method
= w
->desired_matrix
->method
;
12690 int len
= strlen (method
);
12691 int size
= sizeof w
->desired_matrix
->method
;
12692 int remaining
= size
- len
- 1;
12695 if (len
&& remaining
)
12698 --remaining
, ++len
;
12701 va_start (ap
, fmt
);
12702 vsnprintf (method
+ len
, remaining
+ 1, fmt
, ap
);
12705 if (trace_redisplay_p
)
12706 fprintf (stderr
, "%p (%s): %s\n",
12708 ((BUFFERP (w
->contents
)
12709 && STRINGP (BVAR (XBUFFER (w
->contents
), name
)))
12710 ? SSDATA (BVAR (XBUFFER (w
->contents
), name
))
12715 #endif /* GLYPH_DEBUG */
12718 /* Value is non-zero if all changes in window W, which displays
12719 current_buffer, are in the text between START and END. START is a
12720 buffer position, END is given as a distance from Z. Used in
12721 redisplay_internal for display optimization. */
12724 text_outside_line_unchanged_p (struct window
*w
,
12725 ptrdiff_t start
, ptrdiff_t end
)
12727 int unchanged_p
= 1;
12729 /* If text or overlays have changed, see where. */
12730 if (window_outdated (w
))
12732 /* Gap in the line? */
12733 if (GPT
< start
|| Z
- GPT
< end
)
12736 /* Changes start in front of the line, or end after it? */
12738 && (BEG_UNCHANGED
< start
- 1
12739 || END_UNCHANGED
< end
))
12742 /* If selective display, can't optimize if changes start at the
12743 beginning of the line. */
12745 && INTEGERP (BVAR (current_buffer
, selective_display
))
12746 && XINT (BVAR (current_buffer
, selective_display
)) > 0
12747 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
12750 /* If there are overlays at the start or end of the line, these
12751 may have overlay strings with newlines in them. A change at
12752 START, for instance, may actually concern the display of such
12753 overlay strings as well, and they are displayed on different
12754 lines. So, quickly rule out this case. (For the future, it
12755 might be desirable to implement something more telling than
12756 just BEG/END_UNCHANGED.) */
12759 if (BEG
+ BEG_UNCHANGED
== start
12760 && overlay_touches_p (start
))
12762 if (END_UNCHANGED
== end
12763 && overlay_touches_p (Z
- end
))
12767 /* Under bidi reordering, adding or deleting a character in the
12768 beginning of a paragraph, before the first strong directional
12769 character, can change the base direction of the paragraph (unless
12770 the buffer specifies a fixed paragraph direction), which will
12771 require to redisplay the whole paragraph. It might be worthwhile
12772 to find the paragraph limits and widen the range of redisplayed
12773 lines to that, but for now just give up this optimization. */
12774 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
12775 && NILP (BVAR (XBUFFER (w
->contents
), bidi_paragraph_direction
)))
12779 return unchanged_p
;
12783 /* Do a frame update, taking possible shortcuts into account. This is
12784 the main external entry point for redisplay.
12786 If the last redisplay displayed an echo area message and that message
12787 is no longer requested, we clear the echo area or bring back the
12788 mini-buffer if that is in use. */
12793 redisplay_internal ();
12798 overlay_arrow_string_or_property (Lisp_Object var
)
12802 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
12805 return Voverlay_arrow_string
;
12808 /* Return 1 if there are any overlay-arrows in current_buffer. */
12810 overlay_arrow_in_current_buffer_p (void)
12814 for (vlist
= Voverlay_arrow_variable_list
;
12816 vlist
= XCDR (vlist
))
12818 Lisp_Object var
= XCAR (vlist
);
12821 if (!SYMBOLP (var
))
12823 val
= find_symbol_value (var
);
12825 && current_buffer
== XMARKER (val
)->buffer
)
12832 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
12836 overlay_arrows_changed_p (void)
12840 for (vlist
= Voverlay_arrow_variable_list
;
12842 vlist
= XCDR (vlist
))
12844 Lisp_Object var
= XCAR (vlist
);
12845 Lisp_Object val
, pstr
;
12847 if (!SYMBOLP (var
))
12849 val
= find_symbol_value (var
);
12850 if (!MARKERP (val
))
12852 if (! EQ (COERCE_MARKER (val
),
12853 Fget (var
, Qlast_arrow_position
))
12854 || ! (pstr
= overlay_arrow_string_or_property (var
),
12855 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
12861 /* Mark overlay arrows to be updated on next redisplay. */
12864 update_overlay_arrows (int up_to_date
)
12868 for (vlist
= Voverlay_arrow_variable_list
;
12870 vlist
= XCDR (vlist
))
12872 Lisp_Object var
= XCAR (vlist
);
12874 if (!SYMBOLP (var
))
12877 if (up_to_date
> 0)
12879 Lisp_Object val
= find_symbol_value (var
);
12880 Fput (var
, Qlast_arrow_position
,
12881 COERCE_MARKER (val
));
12882 Fput (var
, Qlast_arrow_string
,
12883 overlay_arrow_string_or_property (var
));
12885 else if (up_to_date
< 0
12886 || !NILP (Fget (var
, Qlast_arrow_position
)))
12888 Fput (var
, Qlast_arrow_position
, Qt
);
12889 Fput (var
, Qlast_arrow_string
, Qt
);
12895 /* Return overlay arrow string to display at row.
12896 Return integer (bitmap number) for arrow bitmap in left fringe.
12897 Return nil if no overlay arrow. */
12900 overlay_arrow_at_row (struct it
*it
, struct glyph_row
*row
)
12904 for (vlist
= Voverlay_arrow_variable_list
;
12906 vlist
= XCDR (vlist
))
12908 Lisp_Object var
= XCAR (vlist
);
12911 if (!SYMBOLP (var
))
12914 val
= find_symbol_value (var
);
12917 && current_buffer
== XMARKER (val
)->buffer
12918 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
12920 if (FRAME_WINDOW_P (it
->f
)
12921 /* FIXME: if ROW->reversed_p is set, this should test
12922 the right fringe, not the left one. */
12923 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
12925 #ifdef HAVE_WINDOW_SYSTEM
12926 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
12929 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
12930 return make_number (fringe_bitmap
);
12933 return make_number (-1); /* Use default arrow bitmap. */
12935 return overlay_arrow_string_or_property (var
);
12942 /* Return 1 if point moved out of or into a composition. Otherwise
12943 return 0. PREV_BUF and PREV_PT are the last point buffer and
12944 position. BUF and PT are the current point buffer and position. */
12947 check_point_in_composition (struct buffer
*prev_buf
, ptrdiff_t prev_pt
,
12948 struct buffer
*buf
, ptrdiff_t pt
)
12950 ptrdiff_t start
, end
;
12952 Lisp_Object buffer
;
12954 XSETBUFFER (buffer
, buf
);
12955 /* Check a composition at the last point if point moved within the
12957 if (prev_buf
== buf
)
12960 /* Point didn't move. */
12963 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
12964 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
12965 && composition_valid_p (start
, end
, prop
)
12966 && start
< prev_pt
&& end
> prev_pt
)
12967 /* The last point was within the composition. Return 1 iff
12968 point moved out of the composition. */
12969 return (pt
<= start
|| pt
>= end
);
12972 /* Check a composition at the current point. */
12973 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
12974 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
12975 && composition_valid_p (start
, end
, prop
)
12976 && start
< pt
&& end
> pt
);
12979 /* Reconsider the clip changes of buffer which is displayed in W. */
12982 reconsider_clip_changes (struct window
*w
)
12984 struct buffer
*b
= XBUFFER (w
->contents
);
12986 if (b
->clip_changed
12987 && w
->window_end_valid
12988 && w
->current_matrix
->buffer
== b
12989 && w
->current_matrix
->zv
== BUF_ZV (b
)
12990 && w
->current_matrix
->begv
== BUF_BEGV (b
))
12991 b
->clip_changed
= 0;
12993 /* If display wasn't paused, and W is not a tool bar window, see if
12994 point has been moved into or out of a composition. In that case,
12995 we set b->clip_changed to 1 to force updating the screen. If
12996 b->clip_changed has already been set to 1, we can skip this
12998 if (!b
->clip_changed
&& w
->window_end_valid
)
13000 ptrdiff_t pt
= (w
== XWINDOW (selected_window
)
13001 ? PT
: marker_position (w
->pointm
));
13003 if ((w
->current_matrix
->buffer
!= b
|| pt
!= w
->last_point
)
13004 && check_point_in_composition (w
->current_matrix
->buffer
,
13005 w
->last_point
, b
, pt
))
13006 b
->clip_changed
= 1;
13010 #define STOP_POLLING \
13011 do { if (! polling_stopped_here) stop_polling (); \
13012 polling_stopped_here = 1; } while (0)
13014 #define RESUME_POLLING \
13015 do { if (polling_stopped_here) start_polling (); \
13016 polling_stopped_here = 0; } while (0)
13019 /* Perhaps in the future avoid recentering windows if it
13020 is not necessary; currently that causes some problems. */
13023 redisplay_internal (void)
13025 struct window
*w
= XWINDOW (selected_window
);
13029 bool must_finish
= 0, match_p
;
13030 struct text_pos tlbufpos
, tlendpos
;
13031 int number_of_visible_frames
;
13034 int polling_stopped_here
= 0;
13035 Lisp_Object tail
, frame
;
13037 /* Non-zero means redisplay has to consider all windows on all
13038 frames. Zero means, only selected_window is considered. */
13039 int consider_all_windows_p
;
13041 /* Non-zero means redisplay has to redisplay the miniwindow. */
13042 int update_miniwindow_p
= 0;
13044 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
13046 /* No redisplay if running in batch mode or frame is not yet fully
13047 initialized, or redisplay is explicitly turned off by setting
13048 Vinhibit_redisplay. */
13049 if (FRAME_INITIAL_P (SELECTED_FRAME ())
13050 || !NILP (Vinhibit_redisplay
))
13053 /* Don't examine these until after testing Vinhibit_redisplay.
13054 When Emacs is shutting down, perhaps because its connection to
13055 X has dropped, we should not look at them at all. */
13056 fr
= XFRAME (w
->frame
);
13057 sf
= SELECTED_FRAME ();
13059 if (!fr
->glyphs_initialized_p
)
13062 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
13063 if (popup_activated ())
13067 /* I don't think this happens but let's be paranoid. */
13068 if (redisplaying_p
)
13071 /* Record a function that clears redisplaying_p
13072 when we leave this function. */
13073 count
= SPECPDL_INDEX ();
13074 record_unwind_protect_void (unwind_redisplay
);
13075 redisplaying_p
= 1;
13076 specbind (Qinhibit_free_realized_faces
, Qnil
);
13078 /* Record this function, so it appears on the profiler's backtraces. */
13079 record_in_backtrace (Qredisplay_internal
, &Qnil
, 0);
13081 FOR_EACH_FRAME (tail
, frame
)
13082 XFRAME (frame
)->already_hscrolled_p
= 0;
13085 /* Remember the currently selected window. */
13089 last_escape_glyph_frame
= NULL
;
13090 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
13091 last_glyphless_glyph_frame
= NULL
;
13092 last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
13094 /* If new fonts have been loaded that make a glyph matrix adjustment
13095 necessary, do it. */
13096 if (fonts_changed_p
)
13098 adjust_glyphs (NULL
);
13099 ++windows_or_buffers_changed
;
13100 fonts_changed_p
= 0;
13103 /* If face_change_count is non-zero, init_iterator will free all
13104 realized faces, which includes the faces referenced from current
13105 matrices. So, we can't reuse current matrices in this case. */
13106 if (face_change_count
)
13107 ++windows_or_buffers_changed
;
13109 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
13110 && FRAME_TTY (sf
)->previous_frame
!= sf
)
13112 /* Since frames on a single ASCII terminal share the same
13113 display area, displaying a different frame means redisplay
13114 the whole thing. */
13115 windows_or_buffers_changed
++;
13116 SET_FRAME_GARBAGED (sf
);
13118 set_tty_color_mode (FRAME_TTY (sf
), sf
);
13120 FRAME_TTY (sf
)->previous_frame
= sf
;
13123 /* Set the visible flags for all frames. Do this before checking for
13124 resized or garbaged frames; they want to know if their frames are
13125 visible. See the comment in frame.h for FRAME_SAMPLE_VISIBILITY. */
13126 number_of_visible_frames
= 0;
13128 FOR_EACH_FRAME (tail
, frame
)
13130 struct frame
*f
= XFRAME (frame
);
13132 if (FRAME_VISIBLE_P (f
))
13133 ++number_of_visible_frames
;
13134 clear_desired_matrices (f
);
13137 /* Notice any pending interrupt request to change frame size. */
13138 do_pending_window_change (1);
13140 /* do_pending_window_change could change the selected_window due to
13141 frame resizing which makes the selected window too small. */
13142 if (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
)
13145 /* Clear frames marked as garbaged. */
13146 clear_garbaged_frames ();
13148 /* Build menubar and tool-bar items. */
13149 if (NILP (Vmemory_full
))
13150 prepare_menu_bars ();
13152 if (windows_or_buffers_changed
)
13153 update_mode_lines
++;
13155 reconsider_clip_changes (w
);
13157 /* In most cases selected window displays current buffer. */
13158 match_p
= XBUFFER (w
->contents
) == current_buffer
;
13163 /* Detect case that we need to write or remove a star in the mode line. */
13164 if ((SAVE_MODIFF
< MODIFF
) != w
->last_had_star
)
13166 w
->update_mode_line
= 1;
13167 if (buffer_shared_and_changed ())
13168 update_mode_lines
++;
13171 /* Avoid invocation of point motion hooks by `current_column' below. */
13172 count1
= SPECPDL_INDEX ();
13173 specbind (Qinhibit_point_motion_hooks
, Qt
);
13175 if (mode_line_update_needed (w
))
13176 w
->update_mode_line
= 1;
13178 unbind_to (count1
, Qnil
);
13181 consider_all_windows_p
= (update_mode_lines
13182 || buffer_shared_and_changed ()
13183 || cursor_type_changed
);
13185 /* If specs for an arrow have changed, do thorough redisplay
13186 to ensure we remove any arrow that should no longer exist. */
13187 if (overlay_arrows_changed_p ())
13188 consider_all_windows_p
= windows_or_buffers_changed
= 1;
13190 /* Normally the message* functions will have already displayed and
13191 updated the echo area, but the frame may have been trashed, or
13192 the update may have been preempted, so display the echo area
13193 again here. Checking message_cleared_p captures the case that
13194 the echo area should be cleared. */
13195 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
13196 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
13197 || (message_cleared_p
13198 && minibuf_level
== 0
13199 /* If the mini-window is currently selected, this means the
13200 echo-area doesn't show through. */
13201 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
13203 int window_height_changed_p
= echo_area_display (0);
13205 if (message_cleared_p
)
13206 update_miniwindow_p
= 1;
13210 /* If we don't display the current message, don't clear the
13211 message_cleared_p flag, because, if we did, we wouldn't clear
13212 the echo area in the next redisplay which doesn't preserve
13214 if (!display_last_displayed_message_p
)
13215 message_cleared_p
= 0;
13217 if (fonts_changed_p
)
13219 else if (window_height_changed_p
)
13221 consider_all_windows_p
= 1;
13222 ++update_mode_lines
;
13223 ++windows_or_buffers_changed
;
13225 /* If window configuration was changed, frames may have been
13226 marked garbaged. Clear them or we will experience
13227 surprises wrt scrolling. */
13228 clear_garbaged_frames ();
13231 else if (EQ (selected_window
, minibuf_window
)
13232 && (current_buffer
->clip_changed
|| window_outdated (w
))
13233 && resize_mini_window (w
, 0))
13235 /* Resized active mini-window to fit the size of what it is
13236 showing if its contents might have changed. */
13238 /* FIXME: this causes all frames to be updated, which seems unnecessary
13239 since only the current frame needs to be considered. This function
13240 needs to be rewritten with two variables, consider_all_windows and
13241 consider_all_frames. */
13242 consider_all_windows_p
= 1;
13243 ++windows_or_buffers_changed
;
13244 ++update_mode_lines
;
13246 /* If window configuration was changed, frames may have been
13247 marked garbaged. Clear them or we will experience
13248 surprises wrt scrolling. */
13249 clear_garbaged_frames ();
13252 /* If showing the region, and mark has changed, we must redisplay
13253 the whole window. The assignment to this_line_start_pos prevents
13254 the optimization directly below this if-statement. */
13255 if (((!NILP (Vtransient_mark_mode
)
13256 && !NILP (BVAR (XBUFFER (w
->contents
), mark_active
)))
13257 != (w
->region_showing
> 0))
13258 || (w
->region_showing
13259 && w
->region_showing
13260 != XINT (Fmarker_position (BVAR (XBUFFER (w
->contents
), mark
)))))
13261 CHARPOS (this_line_start_pos
) = 0;
13263 /* Optimize the case that only the line containing the cursor in the
13264 selected window has changed. Variables starting with this_ are
13265 set in display_line and record information about the line
13266 containing the cursor. */
13267 tlbufpos
= this_line_start_pos
;
13268 tlendpos
= this_line_end_pos
;
13269 if (!consider_all_windows_p
13270 && CHARPOS (tlbufpos
) > 0
13271 && !w
->update_mode_line
13272 && !current_buffer
->clip_changed
13273 && !current_buffer
->prevent_redisplay_optimizations_p
13274 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
13275 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
13276 /* Make sure recorded data applies to current buffer, etc. */
13277 && this_line_buffer
== current_buffer
13280 && !w
->optional_new_start
13281 /* Point must be on the line that we have info recorded about. */
13282 && PT
>= CHARPOS (tlbufpos
)
13283 && PT
<= Z
- CHARPOS (tlendpos
)
13284 /* All text outside that line, including its final newline,
13285 must be unchanged. */
13286 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
13287 CHARPOS (tlendpos
)))
13289 if (CHARPOS (tlbufpos
) > BEGV
13290 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
13291 && (CHARPOS (tlbufpos
) == ZV
13292 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
13293 /* Former continuation line has disappeared by becoming empty. */
13295 else if (window_outdated (w
) || MINI_WINDOW_P (w
))
13297 /* We have to handle the case of continuation around a
13298 wide-column character (see the comment in indent.c around
13301 For instance, in the following case:
13303 -------- Insert --------
13304 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
13305 J_I_ ==> J_I_ `^^' are cursors.
13309 As we have to redraw the line above, we cannot use this
13313 int line_height_before
= this_line_pixel_height
;
13315 /* Note that start_display will handle the case that the
13316 line starting at tlbufpos is a continuation line. */
13317 start_display (&it
, w
, tlbufpos
);
13319 /* Implementation note: It this still necessary? */
13320 if (it
.current_x
!= this_line_start_x
)
13323 TRACE ((stderr
, "trying display optimization 1\n"));
13324 w
->cursor
.vpos
= -1;
13325 overlay_arrow_seen
= 0;
13326 it
.vpos
= this_line_vpos
;
13327 it
.current_y
= this_line_y
;
13328 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
13329 display_line (&it
);
13331 /* If line contains point, is not continued,
13332 and ends at same distance from eob as before, we win. */
13333 if (w
->cursor
.vpos
>= 0
13334 /* Line is not continued, otherwise this_line_start_pos
13335 would have been set to 0 in display_line. */
13336 && CHARPOS (this_line_start_pos
)
13337 /* Line ends as before. */
13338 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
13339 /* Line has same height as before. Otherwise other lines
13340 would have to be shifted up or down. */
13341 && this_line_pixel_height
== line_height_before
)
13343 /* If this is not the window's last line, we must adjust
13344 the charstarts of the lines below. */
13345 if (it
.current_y
< it
.last_visible_y
)
13347 struct glyph_row
*row
13348 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
13349 ptrdiff_t delta
, delta_bytes
;
13351 /* We used to distinguish between two cases here,
13352 conditioned by Z - CHARPOS (tlendpos) == ZV, for
13353 when the line ends in a newline or the end of the
13354 buffer's accessible portion. But both cases did
13355 the same, so they were collapsed. */
13357 - CHARPOS (tlendpos
)
13358 - MATRIX_ROW_START_CHARPOS (row
));
13359 delta_bytes
= (Z_BYTE
13360 - BYTEPOS (tlendpos
)
13361 - MATRIX_ROW_START_BYTEPOS (row
));
13363 increment_matrix_positions (w
->current_matrix
,
13364 this_line_vpos
+ 1,
13365 w
->current_matrix
->nrows
,
13366 delta
, delta_bytes
);
13369 /* If this row displays text now but previously didn't,
13370 or vice versa, w->window_end_vpos may have to be
13372 if (MATRIX_ROW_DISPLAYS_TEXT_P (it
.glyph_row
- 1))
13374 if (w
->window_end_vpos
< this_line_vpos
)
13375 w
->window_end_vpos
= this_line_vpos
;
13377 else if (w
->window_end_vpos
== this_line_vpos
13378 && this_line_vpos
> 0)
13379 w
->window_end_vpos
= this_line_vpos
- 1;
13380 w
->window_end_valid
= 0;
13382 /* Update hint: No need to try to scroll in update_window. */
13383 w
->desired_matrix
->no_scrolling_p
= 1;
13386 *w
->desired_matrix
->method
= 0;
13387 debug_method_add (w
, "optimization 1");
13390 //debug optimization movement issue
13391 //w->desired_matrix->no_scrolling_p = 1;
13392 //*w->desired_matrix->method = 0;
13393 //debug_method_add (w, "optimization 1");
13396 #ifdef HAVE_WINDOW_SYSTEM
13397 update_window_fringes (w
, 0);
13404 else if (/* Cursor position hasn't changed. */
13405 PT
== w
->last_point
13406 /* Make sure the cursor was last displayed
13407 in this window. Otherwise we have to reposition it. */
13408 && 0 <= w
->cursor
.vpos
13409 && w
->cursor
.vpos
< WINDOW_TOTAL_LINES (w
))
13413 do_pending_window_change (1);
13414 /* If selected_window changed, redisplay again. */
13415 if (WINDOWP (selected_window
)
13416 && (w
= XWINDOW (selected_window
)) != sw
)
13419 /* We used to always goto end_of_redisplay here, but this
13420 isn't enough if we have a blinking cursor. */
13421 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
13422 goto end_of_redisplay
;
13426 /* If highlighting the region, or if the cursor is in the echo area,
13427 then we can't just move the cursor. */
13428 else if (! (!NILP (Vtransient_mark_mode
)
13429 && !NILP (BVAR (current_buffer
, mark_active
)))
13430 && (EQ (selected_window
,
13431 BVAR (current_buffer
, last_selected_window
))
13432 || highlight_nonselected_windows
)
13433 && !w
->region_showing
13434 && NILP (Vshow_trailing_whitespace
)
13435 && !cursor_in_echo_area
)
13438 struct glyph_row
*row
;
13440 /* Skip from tlbufpos to PT and see where it is. Note that
13441 PT may be in invisible text. If so, we will end at the
13442 next visible position. */
13443 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
13444 NULL
, DEFAULT_FACE_ID
);
13445 it
.current_x
= this_line_start_x
;
13446 it
.current_y
= this_line_y
;
13447 it
.vpos
= this_line_vpos
;
13449 /* The call to move_it_to stops in front of PT, but
13450 moves over before-strings. */
13451 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
13453 if (it
.vpos
== this_line_vpos
13454 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
13457 eassert (this_line_vpos
== it
.vpos
);
13458 eassert (this_line_y
== it
.current_y
);
13459 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13461 *w
->desired_matrix
->method
= 0;
13462 debug_method_add (w
, "optimization 3");
13471 /* Text changed drastically or point moved off of line. */
13472 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
13475 CHARPOS (this_line_start_pos
) = 0;
13476 consider_all_windows_p
|= buffer_shared_and_changed ();
13477 ++clear_face_cache_count
;
13478 #ifdef HAVE_WINDOW_SYSTEM
13479 ++clear_image_cache_count
;
13482 /* Build desired matrices, and update the display. If
13483 consider_all_windows_p is non-zero, do it for all windows on all
13484 frames. Otherwise do it for selected_window, only. */
13486 if (consider_all_windows_p
)
13488 FOR_EACH_FRAME (tail
, frame
)
13489 XFRAME (frame
)->updated_p
= 0;
13491 FOR_EACH_FRAME (tail
, frame
)
13493 struct frame
*f
= XFRAME (frame
);
13495 /* We don't have to do anything for unselected terminal
13497 if ((FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
13498 && !EQ (FRAME_TTY (f
)->top_frame
, frame
))
13501 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
13503 /* Mark all the scroll bars to be removed; we'll redeem
13504 the ones we want when we redisplay their windows. */
13505 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
13506 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
13508 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13509 redisplay_windows (FRAME_ROOT_WINDOW (f
));
13511 /* The X error handler may have deleted that frame. */
13512 if (!FRAME_LIVE_P (f
))
13515 /* Any scroll bars which redisplay_windows should have
13516 nuked should now go away. */
13517 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
13518 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
13520 /* If fonts changed, display again. */
13521 /* ??? rms: I suspect it is a mistake to jump all the way
13522 back to retry here. It should just retry this frame. */
13523 if (fonts_changed_p
)
13526 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13528 /* See if we have to hscroll. */
13529 if (!f
->already_hscrolled_p
)
13531 f
->already_hscrolled_p
= 1;
13532 if (hscroll_windows (f
->root_window
))
13536 /* Prevent various kinds of signals during display
13537 update. stdio is not robust about handling
13538 signals, which can cause an apparent I/O
13540 if (interrupt_input
)
13541 unrequest_sigio ();
13544 /* Update the display. */
13545 set_window_update_flags (XWINDOW (f
->root_window
), 1);
13546 pending
|= update_frame (f
, 0, 0);
13552 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
13556 /* Do the mark_window_display_accurate after all windows have
13557 been redisplayed because this call resets flags in buffers
13558 which are needed for proper redisplay. */
13559 FOR_EACH_FRAME (tail
, frame
)
13561 struct frame
*f
= XFRAME (frame
);
13564 mark_window_display_accurate (f
->root_window
, 1);
13565 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
13566 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
13571 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13573 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13574 struct frame
*mini_frame
;
13576 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->contents
);
13577 /* Use list_of_error, not Qerror, so that
13578 we catch only errors and don't run the debugger. */
13579 internal_condition_case_1 (redisplay_window_1
, selected_window
,
13581 redisplay_window_error
);
13582 if (update_miniwindow_p
)
13583 internal_condition_case_1 (redisplay_window_1
, mini_window
,
13585 redisplay_window_error
);
13587 /* Compare desired and current matrices, perform output. */
13590 /* If fonts changed, display again. */
13591 if (fonts_changed_p
)
13594 /* Prevent various kinds of signals during display update.
13595 stdio is not robust about handling signals,
13596 which can cause an apparent I/O error. */
13597 if (interrupt_input
)
13598 unrequest_sigio ();
13601 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13603 if (hscroll_windows (selected_window
))
13606 XWINDOW (selected_window
)->must_be_updated_p
= 1;
13607 pending
= update_frame (sf
, 0, 0);
13610 /* We may have called echo_area_display at the top of this
13611 function. If the echo area is on another frame, that may
13612 have put text on a frame other than the selected one, so the
13613 above call to update_frame would not have caught it. Catch
13615 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13616 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
13618 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
13620 XWINDOW (mini_window
)->must_be_updated_p
= 1;
13621 pending
|= update_frame (mini_frame
, 0, 0);
13622 if (!pending
&& hscroll_windows (mini_window
))
13627 /* If display was paused because of pending input, make sure we do a
13628 thorough update the next time. */
13631 /* Prevent the optimization at the beginning of
13632 redisplay_internal that tries a single-line update of the
13633 line containing the cursor in the selected window. */
13634 CHARPOS (this_line_start_pos
) = 0;
13636 /* Let the overlay arrow be updated the next time. */
13637 update_overlay_arrows (0);
13639 /* If we pause after scrolling, some rows in the current
13640 matrices of some windows are not valid. */
13641 if (!WINDOW_FULL_WIDTH_P (w
)
13642 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
13643 update_mode_lines
= 1;
13647 if (!consider_all_windows_p
)
13649 /* This has already been done above if
13650 consider_all_windows_p is set. */
13651 mark_window_display_accurate_1 (w
, 1);
13653 /* Say overlay arrows are up to date. */
13654 update_overlay_arrows (1);
13656 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
13657 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
13660 update_mode_lines
= 0;
13661 windows_or_buffers_changed
= 0;
13662 cursor_type_changed
= 0;
13665 /* Start SIGIO interrupts coming again. Having them off during the
13666 code above makes it less likely one will discard output, but not
13667 impossible, since there might be stuff in the system buffer here.
13668 But it is much hairier to try to do anything about that. */
13669 if (interrupt_input
)
13673 /* If a frame has become visible which was not before, redisplay
13674 again, so that we display it. Expose events for such a frame
13675 (which it gets when becoming visible) don't call the parts of
13676 redisplay constructing glyphs, so simply exposing a frame won't
13677 display anything in this case. So, we have to display these
13678 frames here explicitly. */
13683 FOR_EACH_FRAME (tail
, frame
)
13685 int this_is_visible
= 0;
13687 if (XFRAME (frame
)->visible
)
13688 this_is_visible
= 1;
13690 if (this_is_visible
)
13694 if (new_count
!= number_of_visible_frames
)
13695 windows_or_buffers_changed
++;
13698 /* Change frame size now if a change is pending. */
13699 do_pending_window_change (1);
13701 /* If we just did a pending size change, or have additional
13702 visible frames, or selected_window changed, redisplay again. */
13703 if ((windows_or_buffers_changed
&& !pending
)
13704 || (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
))
13707 /* Clear the face and image caches.
13709 We used to do this only if consider_all_windows_p. But the cache
13710 needs to be cleared if a timer creates images in the current
13711 buffer (e.g. the test case in Bug#6230). */
13713 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
13715 clear_face_cache (0);
13716 clear_face_cache_count
= 0;
13719 #ifdef HAVE_WINDOW_SYSTEM
13720 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
13722 clear_image_caches (Qnil
);
13723 clear_image_cache_count
= 0;
13725 #endif /* HAVE_WINDOW_SYSTEM */
13728 unbind_to (count
, Qnil
);
13733 /* Redisplay, but leave alone any recent echo area message unless
13734 another message has been requested in its place.
13736 This is useful in situations where you need to redisplay but no
13737 user action has occurred, making it inappropriate for the message
13738 area to be cleared. See tracking_off and
13739 wait_reading_process_output for examples of these situations.
13741 FROM_WHERE is an integer saying from where this function was
13742 called. This is useful for debugging. */
13745 redisplay_preserve_echo_area (int from_where
)
13747 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
13749 if (!NILP (echo_area_buffer
[1]))
13751 /* We have a previously displayed message, but no current
13752 message. Redisplay the previous message. */
13753 display_last_displayed_message_p
= 1;
13754 redisplay_internal ();
13755 display_last_displayed_message_p
= 0;
13758 redisplay_internal ();
13760 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
13761 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
13762 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
13766 /* Function registered with record_unwind_protect in redisplay_internal. */
13769 unwind_redisplay (void)
13771 redisplaying_p
= 0;
13775 /* Mark the display of leaf window W as accurate or inaccurate.
13776 If ACCURATE_P is non-zero mark display of W as accurate. If
13777 ACCURATE_P is zero, arrange for W to be redisplayed the next
13778 time redisplay_internal is called. */
13781 mark_window_display_accurate_1 (struct window
*w
, int accurate_p
)
13783 struct buffer
*b
= XBUFFER (w
->contents
);
13785 w
->last_modified
= accurate_p
? BUF_MODIFF (b
) : 0;
13786 w
->last_overlay_modified
= accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0;
13787 w
->last_had_star
= BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
);
13791 b
->clip_changed
= 0;
13792 b
->prevent_redisplay_optimizations_p
= 0;
13794 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
13795 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
13796 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
13797 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
13799 w
->current_matrix
->buffer
= b
;
13800 w
->current_matrix
->begv
= BUF_BEGV (b
);
13801 w
->current_matrix
->zv
= BUF_ZV (b
);
13803 w
->last_cursor
= w
->cursor
;
13804 w
->last_cursor_off_p
= w
->cursor_off_p
;
13806 if (w
== XWINDOW (selected_window
))
13807 w
->last_point
= BUF_PT (b
);
13809 w
->last_point
= marker_position (w
->pointm
);
13811 w
->window_end_valid
= 1;
13812 w
->update_mode_line
= 0;
13817 /* Mark the display of windows in the window tree rooted at WINDOW as
13818 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
13819 windows as accurate. If ACCURATE_P is zero, arrange for windows to
13820 be redisplayed the next time redisplay_internal is called. */
13823 mark_window_display_accurate (Lisp_Object window
, int accurate_p
)
13827 for (; !NILP (window
); window
= w
->next
)
13829 w
= XWINDOW (window
);
13830 if (WINDOWP (w
->contents
))
13831 mark_window_display_accurate (w
->contents
, accurate_p
);
13833 mark_window_display_accurate_1 (w
, accurate_p
);
13837 update_overlay_arrows (1);
13839 /* Force a thorough redisplay the next time by setting
13840 last_arrow_position and last_arrow_string to t, which is
13841 unequal to any useful value of Voverlay_arrow_... */
13842 update_overlay_arrows (-1);
13846 /* Return value in display table DP (Lisp_Char_Table *) for character
13847 C. Since a display table doesn't have any parent, we don't have to
13848 follow parent. Do not call this function directly but use the
13849 macro DISP_CHAR_VECTOR. */
13852 disp_char_vector (struct Lisp_Char_Table
*dp
, int c
)
13856 if (ASCII_CHAR_P (c
))
13859 if (SUB_CHAR_TABLE_P (val
))
13860 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
13866 XSETCHAR_TABLE (table
, dp
);
13867 val
= char_table_ref (table
, c
);
13876 /***********************************************************************
13878 ***********************************************************************/
13880 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
13883 redisplay_windows (Lisp_Object window
)
13885 while (!NILP (window
))
13887 struct window
*w
= XWINDOW (window
);
13889 if (WINDOWP (w
->contents
))
13890 redisplay_windows (w
->contents
);
13891 else if (BUFFERP (w
->contents
))
13893 displayed_buffer
= XBUFFER (w
->contents
);
13894 /* Use list_of_error, not Qerror, so that
13895 we catch only errors and don't run the debugger. */
13896 internal_condition_case_1 (redisplay_window_0
, window
,
13898 redisplay_window_error
);
13906 redisplay_window_error (Lisp_Object ignore
)
13908 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
13913 redisplay_window_0 (Lisp_Object window
)
13915 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
13916 redisplay_window (window
, 0);
13921 redisplay_window_1 (Lisp_Object window
)
13923 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
13924 redisplay_window (window
, 1);
13929 /* Set cursor position of W. PT is assumed to be displayed in ROW.
13930 DELTA and DELTA_BYTES are the numbers of characters and bytes by
13931 which positions recorded in ROW differ from current buffer
13934 Return 0 if cursor is not on this row, 1 otherwise. */
13937 set_cursor_from_row (struct window
*w
, struct glyph_row
*row
,
13938 struct glyph_matrix
*matrix
,
13939 ptrdiff_t delta
, ptrdiff_t delta_bytes
,
13942 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
13943 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
13944 struct glyph
*cursor
= NULL
;
13945 /* The last known character position in row. */
13946 ptrdiff_t last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13948 ptrdiff_t pt_old
= PT
- delta
;
13949 ptrdiff_t pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13950 ptrdiff_t pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
13951 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
13952 /* A glyph beyond the edge of TEXT_AREA which we should never
13954 struct glyph
*glyphs_end
= end
;
13955 /* Non-zero means we've found a match for cursor position, but that
13956 glyph has the avoid_cursor_p flag set. */
13957 int match_with_avoid_cursor
= 0;
13958 /* Non-zero means we've seen at least one glyph that came from a
13960 int string_seen
= 0;
13961 /* Largest and smallest buffer positions seen so far during scan of
13963 ptrdiff_t bpos_max
= pos_before
;
13964 ptrdiff_t bpos_min
= pos_after
;
13965 /* Last buffer position covered by an overlay string with an integer
13966 `cursor' property. */
13967 ptrdiff_t bpos_covered
= 0;
13968 /* Non-zero means the display string on which to display the cursor
13969 comes from a text property, not from an overlay. */
13970 int string_from_text_prop
= 0;
13972 /* Don't even try doing anything if called for a mode-line or
13973 header-line row, since the rest of the code isn't prepared to
13974 deal with such calamities. */
13975 eassert (!row
->mode_line_p
);
13976 if (row
->mode_line_p
)
13979 /* Skip over glyphs not having an object at the start and the end of
13980 the row. These are special glyphs like truncation marks on
13981 terminal frames. */
13982 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13984 if (!row
->reversed_p
)
13987 && INTEGERP (glyph
->object
)
13988 && glyph
->charpos
< 0)
13990 x
+= glyph
->pixel_width
;
13994 && INTEGERP ((end
- 1)->object
)
13995 /* CHARPOS is zero for blanks and stretch glyphs
13996 inserted by extend_face_to_end_of_line. */
13997 && (end
- 1)->charpos
<= 0)
13999 glyph_before
= glyph
- 1;
14006 /* If the glyph row is reversed, we need to process it from back
14007 to front, so swap the edge pointers. */
14008 glyphs_end
= end
= glyph
- 1;
14009 glyph
+= row
->used
[TEXT_AREA
] - 1;
14011 while (glyph
> end
+ 1
14012 && INTEGERP (glyph
->object
)
14013 && glyph
->charpos
< 0)
14016 x
-= glyph
->pixel_width
;
14018 if (INTEGERP (glyph
->object
) && glyph
->charpos
< 0)
14020 /* By default, in reversed rows we put the cursor on the
14021 rightmost (first in the reading order) glyph. */
14022 for (g
= end
+ 1; g
< glyph
; g
++)
14023 x
+= g
->pixel_width
;
14025 && INTEGERP ((end
+ 1)->object
)
14026 && (end
+ 1)->charpos
<= 0)
14028 glyph_before
= glyph
+ 1;
14032 else if (row
->reversed_p
)
14034 /* In R2L rows that don't display text, put the cursor on the
14035 rightmost glyph. Case in point: an empty last line that is
14036 part of an R2L paragraph. */
14038 /* Avoid placing the cursor on the last glyph of the row, where
14039 on terminal frames we hold the vertical border between
14040 adjacent windows. */
14041 if (!FRAME_WINDOW_P (WINDOW_XFRAME (w
))
14042 && !WINDOW_RIGHTMOST_P (w
)
14043 && cursor
== row
->glyphs
[LAST_AREA
] - 1)
14045 x
= -1; /* will be computed below, at label compute_x */
14048 /* Step 1: Try to find the glyph whose character position
14049 corresponds to point. If that's not possible, find 2 glyphs
14050 whose character positions are the closest to point, one before
14051 point, the other after it. */
14052 if (!row
->reversed_p
)
14053 while (/* not marched to end of glyph row */
14055 /* glyph was not inserted by redisplay for internal purposes */
14056 && !INTEGERP (glyph
->object
))
14058 if (BUFFERP (glyph
->object
))
14060 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
14062 if (glyph
->charpos
> bpos_max
)
14063 bpos_max
= glyph
->charpos
;
14064 if (glyph
->charpos
< bpos_min
)
14065 bpos_min
= glyph
->charpos
;
14066 if (!glyph
->avoid_cursor_p
)
14068 /* If we hit point, we've found the glyph on which to
14069 display the cursor. */
14072 match_with_avoid_cursor
= 0;
14075 /* See if we've found a better approximation to
14076 POS_BEFORE or to POS_AFTER. */
14077 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
14079 pos_before
= glyph
->charpos
;
14080 glyph_before
= glyph
;
14082 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
14084 pos_after
= glyph
->charpos
;
14085 glyph_after
= glyph
;
14088 else if (dpos
== 0)
14089 match_with_avoid_cursor
= 1;
14091 else if (STRINGP (glyph
->object
))
14093 Lisp_Object chprop
;
14094 ptrdiff_t glyph_pos
= glyph
->charpos
;
14096 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
14098 if (!NILP (chprop
))
14100 /* If the string came from a `display' text property,
14101 look up the buffer position of that property and
14102 use that position to update bpos_max, as if we
14103 actually saw such a position in one of the row's
14104 glyphs. This helps with supporting integer values
14105 of `cursor' property on the display string in
14106 situations where most or all of the row's buffer
14107 text is completely covered by display properties,
14108 so that no glyph with valid buffer positions is
14109 ever seen in the row. */
14110 ptrdiff_t prop_pos
=
14111 string_buffer_position_lim (glyph
->object
, pos_before
,
14114 if (prop_pos
>= pos_before
)
14115 bpos_max
= prop_pos
- 1;
14117 if (INTEGERP (chprop
))
14119 bpos_covered
= bpos_max
+ XINT (chprop
);
14120 /* If the `cursor' property covers buffer positions up
14121 to and including point, we should display cursor on
14122 this glyph. Note that, if a `cursor' property on one
14123 of the string's characters has an integer value, we
14124 will break out of the loop below _before_ we get to
14125 the position match above. IOW, integer values of
14126 the `cursor' property override the "exact match for
14127 point" strategy of positioning the cursor. */
14128 /* Implementation note: bpos_max == pt_old when, e.g.,
14129 we are in an empty line, where bpos_max is set to
14130 MATRIX_ROW_START_CHARPOS, see above. */
14131 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14140 x
+= glyph
->pixel_width
;
14143 else if (glyph
> end
) /* row is reversed */
14144 while (!INTEGERP (glyph
->object
))
14146 if (BUFFERP (glyph
->object
))
14148 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
14150 if (glyph
->charpos
> bpos_max
)
14151 bpos_max
= glyph
->charpos
;
14152 if (glyph
->charpos
< bpos_min
)
14153 bpos_min
= glyph
->charpos
;
14154 if (!glyph
->avoid_cursor_p
)
14158 match_with_avoid_cursor
= 0;
14161 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
14163 pos_before
= glyph
->charpos
;
14164 glyph_before
= glyph
;
14166 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
14168 pos_after
= glyph
->charpos
;
14169 glyph_after
= glyph
;
14172 else if (dpos
== 0)
14173 match_with_avoid_cursor
= 1;
14175 else if (STRINGP (glyph
->object
))
14177 Lisp_Object chprop
;
14178 ptrdiff_t glyph_pos
= glyph
->charpos
;
14180 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
14182 if (!NILP (chprop
))
14184 ptrdiff_t prop_pos
=
14185 string_buffer_position_lim (glyph
->object
, pos_before
,
14188 if (prop_pos
>= pos_before
)
14189 bpos_max
= prop_pos
- 1;
14191 if (INTEGERP (chprop
))
14193 bpos_covered
= bpos_max
+ XINT (chprop
);
14194 /* If the `cursor' property covers buffer positions up
14195 to and including point, we should display cursor on
14197 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14206 if (glyph
== glyphs_end
) /* don't dereference outside TEXT_AREA */
14208 x
--; /* can't use any pixel_width */
14211 x
-= glyph
->pixel_width
;
14214 /* Step 2: If we didn't find an exact match for point, we need to
14215 look for a proper place to put the cursor among glyphs between
14216 GLYPH_BEFORE and GLYPH_AFTER. */
14217 if (!((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14218 && BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14219 && !(bpos_max
< pt_old
&& pt_old
<= bpos_covered
))
14221 /* An empty line has a single glyph whose OBJECT is zero and
14222 whose CHARPOS is the position of a newline on that line.
14223 Note that on a TTY, there are more glyphs after that, which
14224 were produced by extend_face_to_end_of_line, but their
14225 CHARPOS is zero or negative. */
14227 (row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14228 && INTEGERP (glyph
->object
) && glyph
->charpos
> 0
14229 /* On a TTY, continued and truncated rows also have a glyph at
14230 their end whose OBJECT is zero and whose CHARPOS is
14231 positive (the continuation and truncation glyphs), but such
14232 rows are obviously not "empty". */
14233 && !(row
->continued_p
|| row
->truncated_on_right_p
);
14235 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
14237 ptrdiff_t ellipsis_pos
;
14239 /* Scan back over the ellipsis glyphs. */
14240 if (!row
->reversed_p
)
14242 ellipsis_pos
= (glyph
- 1)->charpos
;
14243 while (glyph
> row
->glyphs
[TEXT_AREA
]
14244 && (glyph
- 1)->charpos
== ellipsis_pos
)
14245 glyph
--, x
-= glyph
->pixel_width
;
14246 /* That loop always goes one position too far, including
14247 the glyph before the ellipsis. So scan forward over
14249 x
+= glyph
->pixel_width
;
14252 else /* row is reversed */
14254 ellipsis_pos
= (glyph
+ 1)->charpos
;
14255 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14256 && (glyph
+ 1)->charpos
== ellipsis_pos
)
14257 glyph
++, x
+= glyph
->pixel_width
;
14258 x
-= glyph
->pixel_width
;
14262 else if (match_with_avoid_cursor
)
14264 cursor
= glyph_after
;
14267 else if (string_seen
)
14269 int incr
= row
->reversed_p
? -1 : +1;
14271 /* Need to find the glyph that came out of a string which is
14272 present at point. That glyph is somewhere between
14273 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
14274 positioned between POS_BEFORE and POS_AFTER in the
14276 struct glyph
*start
, *stop
;
14277 ptrdiff_t pos
= pos_before
;
14281 /* If the row ends in a newline from a display string,
14282 reordering could have moved the glyphs belonging to the
14283 string out of the [GLYPH_BEFORE..GLYPH_AFTER] range. So
14284 in this case we extend the search to the last glyph in
14285 the row that was not inserted by redisplay. */
14286 if (row
->ends_in_newline_from_string_p
)
14289 pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
14292 /* GLYPH_BEFORE and GLYPH_AFTER are the glyphs that
14293 correspond to POS_BEFORE and POS_AFTER, respectively. We
14294 need START and STOP in the order that corresponds to the
14295 row's direction as given by its reversed_p flag. If the
14296 directionality of characters between POS_BEFORE and
14297 POS_AFTER is the opposite of the row's base direction,
14298 these characters will have been reordered for display,
14299 and we need to reverse START and STOP. */
14300 if (!row
->reversed_p
)
14302 start
= min (glyph_before
, glyph_after
);
14303 stop
= max (glyph_before
, glyph_after
);
14307 start
= max (glyph_before
, glyph_after
);
14308 stop
= min (glyph_before
, glyph_after
);
14310 for (glyph
= start
+ incr
;
14311 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
14314 /* Any glyphs that come from the buffer are here because
14315 of bidi reordering. Skip them, and only pay
14316 attention to glyphs that came from some string. */
14317 if (STRINGP (glyph
->object
))
14321 /* If the display property covers the newline, we
14322 need to search for it one position farther. */
14323 ptrdiff_t lim
= pos_after
14324 + (pos_after
== MATRIX_ROW_END_CHARPOS (row
) + delta
);
14326 string_from_text_prop
= 0;
14327 str
= glyph
->object
;
14328 tem
= string_buffer_position_lim (str
, pos
, lim
, 0);
14329 if (tem
== 0 /* from overlay */
14332 /* If the string from which this glyph came is
14333 found in the buffer at point, or at position
14334 that is closer to point than pos_after, then
14335 we've found the glyph we've been looking for.
14336 If it comes from an overlay (tem == 0), and
14337 it has the `cursor' property on one of its
14338 glyphs, record that glyph as a candidate for
14339 displaying the cursor. (As in the
14340 unidirectional version, we will display the
14341 cursor on the last candidate we find.) */
14344 || (tem
- pt_old
> 0 && tem
< pos_after
))
14346 /* The glyphs from this string could have
14347 been reordered. Find the one with the
14348 smallest string position. Or there could
14349 be a character in the string with the
14350 `cursor' property, which means display
14351 cursor on that character's glyph. */
14352 ptrdiff_t strpos
= glyph
->charpos
;
14357 string_from_text_prop
= 1;
14360 (row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14361 && EQ (glyph
->object
, str
);
14365 ptrdiff_t gpos
= glyph
->charpos
;
14367 cprop
= Fget_char_property (make_number (gpos
),
14375 if (tem
&& glyph
->charpos
< strpos
)
14377 strpos
= glyph
->charpos
;
14383 || (tem
- pt_old
> 0 && tem
< pos_after
))
14387 pos
= tem
+ 1; /* don't find previous instances */
14389 /* This string is not what we want; skip all of the
14390 glyphs that came from it. */
14391 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14392 && EQ (glyph
->object
, str
))
14399 /* If we reached the end of the line, and END was from a string,
14400 the cursor is not on this line. */
14402 && (row
->reversed_p
? glyph
<= end
: glyph
>= end
)
14403 && (row
->reversed_p
? end
> glyphs_end
: end
< glyphs_end
)
14404 && STRINGP (end
->object
)
14405 && row
->continued_p
)
14408 /* A truncated row may not include PT among its character positions.
14409 Setting the cursor inside the scroll margin will trigger
14410 recalculation of hscroll in hscroll_window_tree. But if a
14411 display string covers point, defer to the string-handling
14412 code below to figure this out. */
14413 else if (row
->truncated_on_left_p
&& pt_old
< bpos_min
)
14415 cursor
= glyph_before
;
14418 else if ((row
->truncated_on_right_p
&& pt_old
> bpos_max
)
14419 /* Zero-width characters produce no glyphs. */
14421 && (row
->reversed_p
14422 ? glyph_after
> glyphs_end
14423 : glyph_after
< glyphs_end
)))
14425 cursor
= glyph_after
;
14431 if (cursor
!= NULL
)
14433 else if (glyph
== glyphs_end
14434 && pos_before
== pos_after
14435 && STRINGP ((row
->reversed_p
14436 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14437 : row
->glyphs
[TEXT_AREA
])->object
))
14439 /* If all the glyphs of this row came from strings, put the
14440 cursor on the first glyph of the row. This avoids having the
14441 cursor outside of the text area in this very rare and hard
14445 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14446 : row
->glyphs
[TEXT_AREA
];
14452 /* Need to compute x that corresponds to GLYPH. */
14453 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
14455 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
14457 x
+= g
->pixel_width
;
14461 /* ROW could be part of a continued line, which, under bidi
14462 reordering, might have other rows whose start and end charpos
14463 occlude point. Only set w->cursor if we found a better
14464 approximation to the cursor position than we have from previously
14465 examined candidate rows belonging to the same continued line. */
14466 if (/* we already have a candidate row */
14467 w
->cursor
.vpos
>= 0
14468 /* that candidate is not the row we are processing */
14469 && MATRIX_ROW (matrix
, w
->cursor
.vpos
) != row
14470 /* Make sure cursor.vpos specifies a row whose start and end
14471 charpos occlude point, and it is valid candidate for being a
14472 cursor-row. This is because some callers of this function
14473 leave cursor.vpos at the row where the cursor was displayed
14474 during the last redisplay cycle. */
14475 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)) <= pt_old
14476 && pt_old
<= MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14477 && cursor_row_p (MATRIX_ROW (matrix
, w
->cursor
.vpos
)))
14480 MATRIX_ROW_GLYPH_START (matrix
, w
->cursor
.vpos
) + w
->cursor
.hpos
;
14482 /* Don't consider glyphs that are outside TEXT_AREA. */
14483 if (!(row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
))
14485 /* Keep the candidate whose buffer position is the closest to
14486 point or has the `cursor' property. */
14487 if (/* previous candidate is a glyph in TEXT_AREA of that row */
14488 w
->cursor
.hpos
>= 0
14489 && w
->cursor
.hpos
< MATRIX_ROW_USED (matrix
, w
->cursor
.vpos
)
14490 && ((BUFFERP (g1
->object
)
14491 && (g1
->charpos
== pt_old
/* an exact match always wins */
14492 || (BUFFERP (glyph
->object
)
14493 && eabs (g1
->charpos
- pt_old
)
14494 < eabs (glyph
->charpos
- pt_old
))))
14495 /* previous candidate is a glyph from a string that has
14496 a non-nil `cursor' property */
14497 || (STRINGP (g1
->object
)
14498 && (!NILP (Fget_char_property (make_number (g1
->charpos
),
14499 Qcursor
, g1
->object
))
14500 /* previous candidate is from the same display
14501 string as this one, and the display string
14502 came from a text property */
14503 || (EQ (g1
->object
, glyph
->object
)
14504 && string_from_text_prop
)
14505 /* this candidate is from newline and its
14506 position is not an exact match */
14507 || (INTEGERP (glyph
->object
)
14508 && glyph
->charpos
!= pt_old
)))))
14510 /* If this candidate gives an exact match, use that. */
14511 if (!((BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14512 /* If this candidate is a glyph created for the
14513 terminating newline of a line, and point is on that
14514 newline, it wins because it's an exact match. */
14515 || (!row
->continued_p
14516 && INTEGERP (glyph
->object
)
14517 && glyph
->charpos
== 0
14518 && pt_old
== MATRIX_ROW_END_CHARPOS (row
) - 1))
14519 /* Otherwise, keep the candidate that comes from a row
14520 spanning less buffer positions. This may win when one or
14521 both candidate positions are on glyphs that came from
14522 display strings, for which we cannot compare buffer
14524 && MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14525 - MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14526 < MATRIX_ROW_END_CHARPOS (row
) - MATRIX_ROW_START_CHARPOS (row
))
14529 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
14531 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
14532 w
->cursor
.y
= row
->y
+ dy
;
14534 if (w
== XWINDOW (selected_window
))
14536 if (!row
->continued_p
14537 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
14540 this_line_buffer
= XBUFFER (w
->contents
);
14542 CHARPOS (this_line_start_pos
)
14543 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
14544 BYTEPOS (this_line_start_pos
)
14545 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
14547 CHARPOS (this_line_end_pos
)
14548 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
14549 BYTEPOS (this_line_end_pos
)
14550 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
14552 this_line_y
= w
->cursor
.y
;
14553 this_line_pixel_height
= row
->height
;
14554 this_line_vpos
= w
->cursor
.vpos
;
14555 this_line_start_x
= row
->x
;
14558 CHARPOS (this_line_start_pos
) = 0;
14565 /* Run window scroll functions, if any, for WINDOW with new window
14566 start STARTP. Sets the window start of WINDOW to that position.
14568 We assume that the window's buffer is really current. */
14570 static struct text_pos
14571 run_window_scroll_functions (Lisp_Object window
, struct text_pos startp
)
14573 struct window
*w
= XWINDOW (window
);
14574 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
14576 eassert (current_buffer
== XBUFFER (w
->contents
));
14578 if (!NILP (Vwindow_scroll_functions
))
14580 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
14581 make_number (CHARPOS (startp
)));
14582 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14583 /* In case the hook functions switch buffers. */
14584 set_buffer_internal (XBUFFER (w
->contents
));
14591 /* Make sure the line containing the cursor is fully visible.
14592 A value of 1 means there is nothing to be done.
14593 (Either the line is fully visible, or it cannot be made so,
14594 or we cannot tell.)
14596 If FORCE_P is non-zero, return 0 even if partial visible cursor row
14597 is higher than window.
14599 A value of 0 means the caller should do scrolling
14600 as if point had gone off the screen. */
14603 cursor_row_fully_visible_p (struct window
*w
, int force_p
, int current_matrix_p
)
14605 struct glyph_matrix
*matrix
;
14606 struct glyph_row
*row
;
14609 if (!make_cursor_line_fully_visible_p
)
14612 /* It's not always possible to find the cursor, e.g, when a window
14613 is full of overlay strings. Don't do anything in that case. */
14614 if (w
->cursor
.vpos
< 0)
14617 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
14618 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
14620 /* If the cursor row is not partially visible, there's nothing to do. */
14621 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
14624 /* If the row the cursor is in is taller than the window's height,
14625 it's not clear what to do, so do nothing. */
14626 window_height
= window_box_height (w
);
14627 if (row
->height
>= window_height
)
14629 if (!force_p
|| MINI_WINDOW_P (w
)
14630 || w
->vscroll
|| w
->cursor
.vpos
== 0)
14637 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
14638 non-zero means only WINDOW is redisplayed in redisplay_internal.
14639 TEMP_SCROLL_STEP has the same meaning as emacs_scroll_step, and is used
14640 in redisplay_window to bring a partially visible line into view in
14641 the case that only the cursor has moved.
14643 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
14644 last screen line's vertical height extends past the end of the screen.
14648 1 if scrolling succeeded
14650 0 if scrolling didn't find point.
14652 -1 if new fonts have been loaded so that we must interrupt
14653 redisplay, adjust glyph matrices, and try again. */
14659 SCROLLING_NEED_LARGER_MATRICES
14662 /* If scroll-conservatively is more than this, never recenter.
14664 If you change this, don't forget to update the doc string of
14665 `scroll-conservatively' and the Emacs manual. */
14666 #define SCROLL_LIMIT 100
14669 try_scrolling (Lisp_Object window
, int just_this_one_p
,
14670 ptrdiff_t arg_scroll_conservatively
, ptrdiff_t scroll_step
,
14671 int temp_scroll_step
, int last_line_misfit
)
14673 struct window
*w
= XWINDOW (window
);
14674 struct frame
*f
= XFRAME (w
->frame
);
14675 struct text_pos pos
, startp
;
14677 int this_scroll_margin
, scroll_max
, rc
, height
;
14678 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
14679 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
14680 Lisp_Object aggressive
;
14681 /* We will never try scrolling more than this number of lines. */
14682 int scroll_limit
= SCROLL_LIMIT
;
14683 int frame_line_height
= default_line_pixel_height (w
);
14684 int window_total_lines
14685 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
14688 debug_method_add (w
, "try_scrolling");
14691 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14693 /* Compute scroll margin height in pixels. We scroll when point is
14694 within this distance from the top or bottom of the window. */
14695 if (scroll_margin
> 0)
14696 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4)
14697 * frame_line_height
;
14699 this_scroll_margin
= 0;
14701 /* Force arg_scroll_conservatively to have a reasonable value, to
14702 avoid scrolling too far away with slow move_it_* functions. Note
14703 that the user can supply scroll-conservatively equal to
14704 `most-positive-fixnum', which can be larger than INT_MAX. */
14705 if (arg_scroll_conservatively
> scroll_limit
)
14707 arg_scroll_conservatively
= scroll_limit
+ 1;
14708 scroll_max
= scroll_limit
* frame_line_height
;
14710 else if (scroll_step
|| arg_scroll_conservatively
|| temp_scroll_step
)
14711 /* Compute how much we should try to scroll maximally to bring
14712 point into view. */
14713 scroll_max
= (max (scroll_step
,
14714 max (arg_scroll_conservatively
, temp_scroll_step
))
14715 * frame_line_height
);
14716 else if (NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
))
14717 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
)))
14718 /* We're trying to scroll because of aggressive scrolling but no
14719 scroll_step is set. Choose an arbitrary one. */
14720 scroll_max
= 10 * frame_line_height
;
14726 /* Decide whether to scroll down. */
14727 if (PT
> CHARPOS (startp
))
14729 int scroll_margin_y
;
14731 /* Compute the pixel ypos of the scroll margin, then move IT to
14732 either that ypos or PT, whichever comes first. */
14733 start_display (&it
, w
, startp
);
14734 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
14735 - frame_line_height
* extra_scroll_margin_lines
;
14736 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
14737 (MOVE_TO_POS
| MOVE_TO_Y
));
14739 if (PT
> CHARPOS (it
.current
.pos
))
14741 int y0
= line_bottom_y (&it
);
14742 /* Compute how many pixels below window bottom to stop searching
14743 for PT. This avoids costly search for PT that is far away if
14744 the user limited scrolling by a small number of lines, but
14745 always finds PT if scroll_conservatively is set to a large
14746 number, such as most-positive-fixnum. */
14747 int slack
= max (scroll_max
, 10 * frame_line_height
);
14748 int y_to_move
= it
.last_visible_y
+ slack
;
14750 /* Compute the distance from the scroll margin to PT or to
14751 the scroll limit, whichever comes first. This should
14752 include the height of the cursor line, to make that line
14754 move_it_to (&it
, PT
, -1, y_to_move
,
14755 -1, MOVE_TO_POS
| MOVE_TO_Y
);
14756 dy
= line_bottom_y (&it
) - y0
;
14758 if (dy
> scroll_max
)
14759 return SCROLLING_FAILED
;
14768 /* Point is in or below the bottom scroll margin, so move the
14769 window start down. If scrolling conservatively, move it just
14770 enough down to make point visible. If scroll_step is set,
14771 move it down by scroll_step. */
14772 if (arg_scroll_conservatively
)
14774 = min (max (dy
, frame_line_height
),
14775 frame_line_height
* arg_scroll_conservatively
);
14776 else if (scroll_step
|| temp_scroll_step
)
14777 amount_to_scroll
= scroll_max
;
14780 aggressive
= BVAR (current_buffer
, scroll_up_aggressively
);
14781 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14782 if (NUMBERP (aggressive
))
14784 double float_amount
= XFLOATINT (aggressive
) * height
;
14785 int aggressive_scroll
= float_amount
;
14786 if (aggressive_scroll
== 0 && float_amount
> 0)
14787 aggressive_scroll
= 1;
14788 /* Don't let point enter the scroll margin near top of
14789 the window. This could happen if the value of
14790 scroll_up_aggressively is too large and there are
14791 non-zero margins, because scroll_up_aggressively
14792 means put point that fraction of window height
14793 _from_the_bottom_margin_. */
14794 if (aggressive_scroll
+ 2*this_scroll_margin
> height
)
14795 aggressive_scroll
= height
- 2*this_scroll_margin
;
14796 amount_to_scroll
= dy
+ aggressive_scroll
;
14800 if (amount_to_scroll
<= 0)
14801 return SCROLLING_FAILED
;
14803 start_display (&it
, w
, startp
);
14804 if (arg_scroll_conservatively
<= scroll_limit
)
14805 move_it_vertically (&it
, amount_to_scroll
);
14808 /* Extra precision for users who set scroll-conservatively
14809 to a large number: make sure the amount we scroll
14810 the window start is never less than amount_to_scroll,
14811 which was computed as distance from window bottom to
14812 point. This matters when lines at window top and lines
14813 below window bottom have different height. */
14815 void *it1data
= NULL
;
14816 /* We use a temporary it1 because line_bottom_y can modify
14817 its argument, if it moves one line down; see there. */
14820 SAVE_IT (it1
, it
, it1data
);
14821 start_y
= line_bottom_y (&it1
);
14823 RESTORE_IT (&it
, &it
, it1data
);
14824 move_it_by_lines (&it
, 1);
14825 SAVE_IT (it1
, it
, it1data
);
14826 } while (line_bottom_y (&it1
) - start_y
< amount_to_scroll
);
14829 /* If STARTP is unchanged, move it down another screen line. */
14830 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
14831 move_it_by_lines (&it
, 1);
14832 startp
= it
.current
.pos
;
14836 struct text_pos scroll_margin_pos
= startp
;
14839 /* See if point is inside the scroll margin at the top of the
14841 if (this_scroll_margin
)
14845 start_display (&it
, w
, startp
);
14846 y_start
= it
.current_y
;
14847 move_it_vertically (&it
, this_scroll_margin
);
14848 scroll_margin_pos
= it
.current
.pos
;
14849 /* If we didn't move enough before hitting ZV, request
14850 additional amount of scroll, to move point out of the
14852 if (IT_CHARPOS (it
) == ZV
14853 && it
.current_y
- y_start
< this_scroll_margin
)
14854 y_offset
= this_scroll_margin
- (it
.current_y
- y_start
);
14857 if (PT
< CHARPOS (scroll_margin_pos
))
14859 /* Point is in the scroll margin at the top of the window or
14860 above what is displayed in the window. */
14863 /* Compute the vertical distance from PT to the scroll
14864 margin position. Move as far as scroll_max allows, or
14865 one screenful, or 10 screen lines, whichever is largest.
14866 Give up if distance is greater than scroll_max or if we
14867 didn't reach the scroll margin position. */
14868 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
14869 start_display (&it
, w
, pos
);
14871 y_to_move
= max (it
.last_visible_y
,
14872 max (scroll_max
, 10 * frame_line_height
));
14873 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
14875 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
14876 dy
= it
.current_y
- y0
;
14877 if (dy
> scroll_max
14878 || IT_CHARPOS (it
) < CHARPOS (scroll_margin_pos
))
14879 return SCROLLING_FAILED
;
14881 /* Additional scroll for when ZV was too close to point. */
14884 /* Compute new window start. */
14885 start_display (&it
, w
, startp
);
14887 if (arg_scroll_conservatively
)
14888 amount_to_scroll
= max (dy
, frame_line_height
*
14889 max (scroll_step
, temp_scroll_step
));
14890 else if (scroll_step
|| temp_scroll_step
)
14891 amount_to_scroll
= scroll_max
;
14894 aggressive
= BVAR (current_buffer
, scroll_down_aggressively
);
14895 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14896 if (NUMBERP (aggressive
))
14898 double float_amount
= XFLOATINT (aggressive
) * height
;
14899 int aggressive_scroll
= float_amount
;
14900 if (aggressive_scroll
== 0 && float_amount
> 0)
14901 aggressive_scroll
= 1;
14902 /* Don't let point enter the scroll margin near
14903 bottom of the window, if the value of
14904 scroll_down_aggressively happens to be too
14906 if (aggressive_scroll
+ 2*this_scroll_margin
> height
)
14907 aggressive_scroll
= height
- 2*this_scroll_margin
;
14908 amount_to_scroll
= dy
+ aggressive_scroll
;
14912 if (amount_to_scroll
<= 0)
14913 return SCROLLING_FAILED
;
14915 move_it_vertically_backward (&it
, amount_to_scroll
);
14916 startp
= it
.current
.pos
;
14920 /* Run window scroll functions. */
14921 startp
= run_window_scroll_functions (window
, startp
);
14923 /* Display the window. Give up if new fonts are loaded, or if point
14925 if (!try_window (window
, startp
, 0))
14926 rc
= SCROLLING_NEED_LARGER_MATRICES
;
14927 else if (w
->cursor
.vpos
< 0)
14929 clear_glyph_matrix (w
->desired_matrix
);
14930 rc
= SCROLLING_FAILED
;
14934 /* Maybe forget recorded base line for line number display. */
14935 if (!just_this_one_p
14936 || current_buffer
->clip_changed
14937 || BEG_UNCHANGED
< CHARPOS (startp
))
14938 w
->base_line_number
= 0;
14940 /* If cursor ends up on a partially visible line,
14941 treat that as being off the bottom of the screen. */
14942 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0)
14943 /* It's possible that the cursor is on the first line of the
14944 buffer, which is partially obscured due to a vscroll
14945 (Bug#7537). In that case, avoid looping forever . */
14946 && extra_scroll_margin_lines
< w
->desired_matrix
->nrows
- 1)
14948 clear_glyph_matrix (w
->desired_matrix
);
14949 ++extra_scroll_margin_lines
;
14952 rc
= SCROLLING_SUCCESS
;
14959 /* Compute a suitable window start for window W if display of W starts
14960 on a continuation line. Value is non-zero if a new window start
14963 The new window start will be computed, based on W's width, starting
14964 from the start of the continued line. It is the start of the
14965 screen line with the minimum distance from the old start W->start. */
14968 compute_window_start_on_continuation_line (struct window
*w
)
14970 struct text_pos pos
, start_pos
;
14971 int window_start_changed_p
= 0;
14973 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
14975 /* If window start is on a continuation line... Window start may be
14976 < BEGV in case there's invisible text at the start of the
14977 buffer (M-x rmail, for example). */
14978 if (CHARPOS (start_pos
) > BEGV
14979 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
14982 struct glyph_row
*row
;
14984 /* Handle the case that the window start is out of range. */
14985 if (CHARPOS (start_pos
) < BEGV
)
14986 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
14987 else if (CHARPOS (start_pos
) > ZV
)
14988 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
14990 /* Find the start of the continued line. This should be fast
14991 because find_newline is fast (newline cache). */
14992 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
14993 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
14994 row
, DEFAULT_FACE_ID
);
14995 reseat_at_previous_visible_line_start (&it
);
14997 /* If the line start is "too far" away from the window start,
14998 say it takes too much time to compute a new window start. */
14999 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
15000 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
15002 int min_distance
, distance
;
15004 /* Move forward by display lines to find the new window
15005 start. If window width was enlarged, the new start can
15006 be expected to be > the old start. If window width was
15007 decreased, the new window start will be < the old start.
15008 So, we're looking for the display line start with the
15009 minimum distance from the old window start. */
15010 pos
= it
.current
.pos
;
15011 min_distance
= INFINITY
;
15012 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
15013 distance
< min_distance
)
15015 min_distance
= distance
;
15016 pos
= it
.current
.pos
;
15017 if (it
.line_wrap
== WORD_WRAP
)
15019 /* Under WORD_WRAP, move_it_by_lines is likely to
15020 overshoot and stop not at the first, but the
15021 second character from the left margin. So in
15022 that case, we need a more tight control on the X
15023 coordinate of the iterator than move_it_by_lines
15024 promises in its contract. The method is to first
15025 go to the last (rightmost) visible character of a
15026 line, then move to the leftmost character on the
15027 next line in a separate call. */
15028 move_it_to (&it
, ZV
, it
.last_visible_x
, it
.current_y
, -1,
15029 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15030 move_it_to (&it
, ZV
, 0,
15031 it
.current_y
+ it
.max_ascent
+ it
.max_descent
, -1,
15032 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15035 move_it_by_lines (&it
, 1);
15038 /* Set the window start there. */
15039 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
15040 window_start_changed_p
= 1;
15044 return window_start_changed_p
;
15048 /* Try cursor movement in case text has not changed in window WINDOW,
15049 with window start STARTP. Value is
15051 CURSOR_MOVEMENT_SUCCESS if successful
15053 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
15055 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
15056 display. *SCROLL_STEP is set to 1, under certain circumstances, if
15057 we want to scroll as if scroll-step were set to 1. See the code.
15059 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
15060 which case we have to abort this redisplay, and adjust matrices
15065 CURSOR_MOVEMENT_SUCCESS
,
15066 CURSOR_MOVEMENT_CANNOT_BE_USED
,
15067 CURSOR_MOVEMENT_MUST_SCROLL
,
15068 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
15072 try_cursor_movement (Lisp_Object window
, struct text_pos startp
, int *scroll_step
)
15074 struct window
*w
= XWINDOW (window
);
15075 struct frame
*f
= XFRAME (w
->frame
);
15076 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
15079 if (inhibit_try_cursor_movement
)
15083 /* Previously, there was a check for Lisp integer in the
15084 if-statement below. Now, this field is converted to
15085 ptrdiff_t, thus zero means invalid position in a buffer. */
15086 eassert (w
->last_point
> 0);
15087 /* Likewise there was a check whether window_end_vpos is nil or larger
15088 than the window. Now window_end_vpos is int and so never nil, but
15089 let's leave eassert to check whether it fits in the window. */
15090 eassert (w
->window_end_vpos
< w
->current_matrix
->nrows
);
15092 /* Handle case where text has not changed, only point, and it has
15093 not moved off the frame. */
15094 if (/* Point may be in this window. */
15095 PT
>= CHARPOS (startp
)
15096 /* Selective display hasn't changed. */
15097 && !current_buffer
->clip_changed
15098 /* Function force-mode-line-update is used to force a thorough
15099 redisplay. It sets either windows_or_buffers_changed or
15100 update_mode_lines. So don't take a shortcut here for these
15102 && !update_mode_lines
15103 && !windows_or_buffers_changed
15104 && !cursor_type_changed
15105 /* Can't use this case if highlighting a region. When a
15106 region exists, cursor movement has to do more than just
15108 && markpos_of_region () < 0
15109 && !w
->region_showing
15110 && NILP (Vshow_trailing_whitespace
)
15111 /* This code is not used for mini-buffer for the sake of the case
15112 of redisplaying to replace an echo area message; since in
15113 that case the mini-buffer contents per se are usually
15114 unchanged. This code is of no real use in the mini-buffer
15115 since the handling of this_line_start_pos, etc., in redisplay
15116 handles the same cases. */
15117 && !EQ (window
, minibuf_window
)
15118 && (FRAME_WINDOW_P (f
)
15119 || !overlay_arrow_in_current_buffer_p ()))
15121 int this_scroll_margin
, top_scroll_margin
;
15122 struct glyph_row
*row
= NULL
;
15123 int frame_line_height
= default_line_pixel_height (w
);
15124 int window_total_lines
15125 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
15128 debug_method_add (w
, "cursor movement");
15131 /* Scroll if point within this distance from the top or bottom
15132 of the window. This is a pixel value. */
15133 if (scroll_margin
> 0)
15135 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4);
15136 this_scroll_margin
*= frame_line_height
;
15139 this_scroll_margin
= 0;
15141 top_scroll_margin
= this_scroll_margin
;
15142 if (WINDOW_WANTS_HEADER_LINE_P (w
))
15143 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
15145 /* Start with the row the cursor was displayed during the last
15146 not paused redisplay. Give up if that row is not valid. */
15147 if (w
->last_cursor
.vpos
< 0
15148 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
15149 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15152 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
15153 if (row
->mode_line_p
)
15155 if (!row
->enabled_p
)
15156 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15159 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
15161 int scroll_p
= 0, must_scroll
= 0;
15162 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
15164 if (PT
> w
->last_point
)
15166 /* Point has moved forward. */
15167 while (MATRIX_ROW_END_CHARPOS (row
) < PT
15168 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
15170 eassert (row
->enabled_p
);
15174 /* If the end position of a row equals the start
15175 position of the next row, and PT is at that position,
15176 we would rather display cursor in the next line. */
15177 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15178 && MATRIX_ROW_END_CHARPOS (row
) == PT
15179 && row
< MATRIX_MODE_LINE_ROW (w
->current_matrix
)
15180 && MATRIX_ROW_START_CHARPOS (row
+1) == PT
15181 && !cursor_row_p (row
))
15184 /* If within the scroll margin, scroll. Note that
15185 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
15186 the next line would be drawn, and that
15187 this_scroll_margin can be zero. */
15188 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
15189 || PT
> MATRIX_ROW_END_CHARPOS (row
)
15190 /* Line is completely visible last line in window
15191 and PT is to be set in the next line. */
15192 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
15193 && PT
== MATRIX_ROW_END_CHARPOS (row
)
15194 && !row
->ends_at_zv_p
15195 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
15198 else if (PT
< w
->last_point
)
15200 /* Cursor has to be moved backward. Note that PT >=
15201 CHARPOS (startp) because of the outer if-statement. */
15202 while (!row
->mode_line_p
15203 && (MATRIX_ROW_START_CHARPOS (row
) > PT
15204 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15205 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
15206 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
15207 row
> w
->current_matrix
->rows
15208 && (row
-1)->ends_in_newline_from_string_p
))))
15209 && (row
->y
> top_scroll_margin
15210 || CHARPOS (startp
) == BEGV
))
15212 eassert (row
->enabled_p
);
15216 /* Consider the following case: Window starts at BEGV,
15217 there is invisible, intangible text at BEGV, so that
15218 display starts at some point START > BEGV. It can
15219 happen that we are called with PT somewhere between
15220 BEGV and START. Try to handle that case. */
15221 if (row
< w
->current_matrix
->rows
15222 || row
->mode_line_p
)
15224 row
= w
->current_matrix
->rows
;
15225 if (row
->mode_line_p
)
15229 /* Due to newlines in overlay strings, we may have to
15230 skip forward over overlay strings. */
15231 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15232 && MATRIX_ROW_END_CHARPOS (row
) == PT
15233 && !cursor_row_p (row
))
15236 /* If within the scroll margin, scroll. */
15237 if (row
->y
< top_scroll_margin
15238 && CHARPOS (startp
) != BEGV
)
15243 /* Cursor did not move. So don't scroll even if cursor line
15244 is partially visible, as it was so before. */
15245 rc
= CURSOR_MOVEMENT_SUCCESS
;
15248 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
15249 || PT
> MATRIX_ROW_END_CHARPOS (row
))
15251 /* if PT is not in the glyph row, give up. */
15252 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15255 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15256 && !NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
15258 struct glyph_row
*row1
;
15260 /* If rows are bidi-reordered and point moved, back up
15261 until we find a row that does not belong to a
15262 continuation line. This is because we must consider
15263 all rows of a continued line as candidates for the
15264 new cursor positioning, since row start and end
15265 positions change non-linearly with vertical position
15267 /* FIXME: Revisit this when glyph ``spilling'' in
15268 continuation lines' rows is implemented for
15269 bidi-reordered rows. */
15270 for (row1
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15271 MATRIX_ROW_CONTINUATION_LINE_P (row
);
15274 /* If we hit the beginning of the displayed portion
15275 without finding the first row of a continued
15279 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15282 eassert (row
->enabled_p
);
15287 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15288 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
15289 /* Make sure this isn't a header line by any chance, since
15290 then MATRIX_ROW_PARTIALLY_VISIBLE_P might yield non-zero. */
15291 && !row
->mode_line_p
15292 && make_cursor_line_fully_visible_p
)
15294 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
15295 && !row
->ends_at_zv_p
15296 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15297 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15298 else if (row
->height
> window_box_height (w
))
15300 /* If we end up in a partially visible line, let's
15301 make it fully visible, except when it's taller
15302 than the window, in which case we can't do much
15305 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15309 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15310 if (!cursor_row_fully_visible_p (w
, 0, 1))
15311 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15313 rc
= CURSOR_MOVEMENT_SUCCESS
;
15317 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15318 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15319 && !NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
15321 /* With bidi-reordered rows, there could be more than
15322 one candidate row whose start and end positions
15323 occlude point. We need to let set_cursor_from_row
15324 find the best candidate. */
15325 /* FIXME: Revisit this when glyph ``spilling'' in
15326 continuation lines' rows is implemented for
15327 bidi-reordered rows. */
15332 int at_zv_p
= 0, exact_match_p
= 0;
15334 if (MATRIX_ROW_START_CHARPOS (row
) <= PT
15335 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
15336 && cursor_row_p (row
))
15337 rv
|= set_cursor_from_row (w
, row
, w
->current_matrix
,
15339 /* As soon as we've found the exact match for point,
15340 or the first suitable row whose ends_at_zv_p flag
15341 is set, we are done. */
15343 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
)->ends_at_zv_p
;
15345 && w
->cursor
.hpos
>= 0
15346 && w
->cursor
.hpos
< MATRIX_ROW_USED (w
->current_matrix
,
15349 struct glyph_row
*candidate
=
15350 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
15352 candidate
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
15353 ptrdiff_t endpos
= MATRIX_ROW_END_CHARPOS (candidate
);
15356 (BUFFERP (g
->object
) && g
->charpos
== PT
)
15357 || (INTEGERP (g
->object
)
15358 && (g
->charpos
== PT
15359 || (g
->charpos
== 0 && endpos
- 1 == PT
)));
15361 if (rv
&& (at_zv_p
|| exact_match_p
))
15363 rc
= CURSOR_MOVEMENT_SUCCESS
;
15366 if (MATRIX_ROW_BOTTOM_Y (row
) == last_y
)
15370 while (((MATRIX_ROW_CONTINUATION_LINE_P (row
)
15371 || row
->continued_p
)
15372 && MATRIX_ROW_BOTTOM_Y (row
) <= last_y
)
15373 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15374 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
));
15375 /* If we didn't find any candidate rows, or exited the
15376 loop before all the candidates were examined, signal
15377 to the caller that this method failed. */
15378 if (rc
!= CURSOR_MOVEMENT_SUCCESS
15380 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
15381 && !row
->continued_p
))
15382 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15384 rc
= CURSOR_MOVEMENT_SUCCESS
;
15390 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
15392 rc
= CURSOR_MOVEMENT_SUCCESS
;
15397 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15398 && MATRIX_ROW_START_CHARPOS (row
) == PT
15399 && cursor_row_p (row
));
15407 #if !defined USE_TOOLKIT_SCROLL_BARS || defined USE_GTK
15411 set_vertical_scroll_bar (struct window
*w
)
15413 ptrdiff_t start
, end
, whole
;
15415 /* Calculate the start and end positions for the current window.
15416 At some point, it would be nice to choose between scrollbars
15417 which reflect the whole buffer size, with special markers
15418 indicating narrowing, and scrollbars which reflect only the
15421 Note that mini-buffers sometimes aren't displaying any text. */
15422 if (!MINI_WINDOW_P (w
)
15423 || (w
== XWINDOW (minibuf_window
)
15424 && NILP (echo_area_buffer
[0])))
15426 struct buffer
*buf
= XBUFFER (w
->contents
);
15427 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
15428 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
15429 /* I don't think this is guaranteed to be right. For the
15430 moment, we'll pretend it is. */
15431 end
= BUF_Z (buf
) - w
->window_end_pos
- BUF_BEGV (buf
);
15435 if (whole
< (end
- start
))
15436 whole
= end
- start
;
15439 start
= end
= whole
= 0;
15441 /* Indicate what this scroll bar ought to be displaying now. */
15442 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15443 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15444 (w
, end
- start
, whole
, start
);
15448 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
15449 selected_window is redisplayed.
15451 We can return without actually redisplaying the window if
15452 fonts_changed_p. In that case, redisplay_internal will
15456 redisplay_window (Lisp_Object window
, int just_this_one_p
)
15458 struct window
*w
= XWINDOW (window
);
15459 struct frame
*f
= XFRAME (w
->frame
);
15460 struct buffer
*buffer
= XBUFFER (w
->contents
);
15461 struct buffer
*old
= current_buffer
;
15462 struct text_pos lpoint
, opoint
, startp
;
15463 int update_mode_line
;
15466 /* Record it now because it's overwritten. */
15467 int current_matrix_up_to_date_p
= 0;
15468 int used_current_matrix_p
= 0;
15469 /* This is less strict than current_matrix_up_to_date_p.
15470 It indicates that the buffer contents and narrowing are unchanged. */
15471 int buffer_unchanged_p
= 0;
15472 int temp_scroll_step
= 0;
15473 ptrdiff_t count
= SPECPDL_INDEX ();
15475 int centering_position
= -1;
15476 int last_line_misfit
= 0;
15477 ptrdiff_t beg_unchanged
, end_unchanged
;
15478 int frame_line_height
;
15480 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15484 *w
->desired_matrix
->method
= 0;
15487 /* Make sure that both W's markers are valid. */
15488 eassert (XMARKER (w
->start
)->buffer
== buffer
);
15489 eassert (XMARKER (w
->pointm
)->buffer
== buffer
);
15492 reconsider_clip_changes (w
);
15493 frame_line_height
= default_line_pixel_height (w
);
15495 /* Has the mode line to be updated? */
15496 update_mode_line
= (w
->update_mode_line
15497 || update_mode_lines
15498 || buffer
->clip_changed
15499 || buffer
->prevent_redisplay_optimizations_p
);
15501 if (MINI_WINDOW_P (w
))
15503 if (w
== XWINDOW (echo_area_window
)
15504 && !NILP (echo_area_buffer
[0]))
15506 if (update_mode_line
)
15507 /* We may have to update a tty frame's menu bar or a
15508 tool-bar. Example `M-x C-h C-h C-g'. */
15509 goto finish_menu_bars
;
15511 /* We've already displayed the echo area glyphs in this window. */
15512 goto finish_scroll_bars
;
15514 else if ((w
!= XWINDOW (minibuf_window
)
15515 || minibuf_level
== 0)
15516 /* When buffer is nonempty, redisplay window normally. */
15517 && BUF_Z (XBUFFER (w
->contents
)) == BUF_BEG (XBUFFER (w
->contents
))
15518 /* Quail displays non-mini buffers in minibuffer window.
15519 In that case, redisplay the window normally. */
15520 && !NILP (Fmemq (w
->contents
, Vminibuffer_list
)))
15522 /* W is a mini-buffer window, but it's not active, so clear
15524 int yb
= window_text_bottom_y (w
);
15525 struct glyph_row
*row
;
15528 for (y
= 0, row
= w
->desired_matrix
->rows
;
15530 y
+= row
->height
, ++row
)
15531 blank_row (w
, row
, y
);
15532 goto finish_scroll_bars
;
15535 clear_glyph_matrix (w
->desired_matrix
);
15538 /* Otherwise set up data on this window; select its buffer and point
15540 /* Really select the buffer, for the sake of buffer-local
15542 set_buffer_internal_1 (XBUFFER (w
->contents
));
15544 current_matrix_up_to_date_p
15545 = (w
->window_end_valid
15546 && !current_buffer
->clip_changed
15547 && !current_buffer
->prevent_redisplay_optimizations_p
15548 && !window_outdated (w
));
15550 /* Run the window-bottom-change-functions
15551 if it is possible that the text on the screen has changed
15552 (either due to modification of the text, or any other reason). */
15553 if (!current_matrix_up_to_date_p
15554 && !NILP (Vwindow_text_change_functions
))
15556 safe_run_hooks (Qwindow_text_change_functions
);
15560 beg_unchanged
= BEG_UNCHANGED
;
15561 end_unchanged
= END_UNCHANGED
;
15563 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
15565 specbind (Qinhibit_point_motion_hooks
, Qt
);
15568 = (w
->window_end_valid
15569 && !current_buffer
->clip_changed
15570 && !window_outdated (w
));
15572 /* When windows_or_buffers_changed is non-zero, we can't rely
15573 on the window end being valid, so set it to zero there. */
15574 if (windows_or_buffers_changed
)
15576 /* If window starts on a continuation line, maybe adjust the
15577 window start in case the window's width changed. */
15578 if (XMARKER (w
->start
)->buffer
== current_buffer
)
15579 compute_window_start_on_continuation_line (w
);
15581 w
->window_end_valid
= 0;
15582 /* If so, we also can't rely on current matrix
15583 and should not fool try_cursor_movement below. */
15584 current_matrix_up_to_date_p
= 0;
15587 /* Some sanity checks. */
15588 CHECK_WINDOW_END (w
);
15589 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
15591 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
15594 if (mode_line_update_needed (w
))
15595 update_mode_line
= 1;
15597 /* Point refers normally to the selected window. For any other
15598 window, set up appropriate value. */
15599 if (!EQ (window
, selected_window
))
15601 ptrdiff_t new_pt
= marker_position (w
->pointm
);
15602 ptrdiff_t new_pt_byte
= marker_byte_position (w
->pointm
);
15606 new_pt_byte
= BEGV_BYTE
;
15607 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
15609 else if (new_pt
> (ZV
- 1))
15612 new_pt_byte
= ZV_BYTE
;
15613 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
15616 /* We don't use SET_PT so that the point-motion hooks don't run. */
15617 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
15620 /* If any of the character widths specified in the display table
15621 have changed, invalidate the width run cache. It's true that
15622 this may be a bit late to catch such changes, but the rest of
15623 redisplay goes (non-fatally) haywire when the display table is
15624 changed, so why should we worry about doing any better? */
15625 if (current_buffer
->width_run_cache
)
15627 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
15629 if (! disptab_matches_widthtab
15630 (disptab
, XVECTOR (BVAR (current_buffer
, width_table
))))
15632 invalidate_region_cache (current_buffer
,
15633 current_buffer
->width_run_cache
,
15635 recompute_width_table (current_buffer
, disptab
);
15639 /* If window-start is screwed up, choose a new one. */
15640 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
15643 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15645 /* If someone specified a new starting point but did not insist,
15646 check whether it can be used. */
15647 if (w
->optional_new_start
15648 && CHARPOS (startp
) >= BEGV
15649 && CHARPOS (startp
) <= ZV
)
15651 w
->optional_new_start
= 0;
15652 start_display (&it
, w
, startp
);
15653 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
15654 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15655 if (IT_CHARPOS (it
) == PT
)
15656 w
->force_start
= 1;
15657 /* IT may overshoot PT if text at PT is invisible. */
15658 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
15659 w
->force_start
= 1;
15664 /* Handle case where place to start displaying has been specified,
15665 unless the specified location is outside the accessible range. */
15666 if (w
->force_start
|| window_frozen_p (w
))
15668 /* We set this later on if we have to adjust point. */
15671 w
->force_start
= 0;
15673 w
->window_end_valid
= 0;
15675 /* Forget any recorded base line for line number display. */
15676 if (!buffer_unchanged_p
)
15677 w
->base_line_number
= 0;
15679 /* Redisplay the mode line. Select the buffer properly for that.
15680 Also, run the hook window-scroll-functions
15681 because we have scrolled. */
15682 /* Note, we do this after clearing force_start because
15683 if there's an error, it is better to forget about force_start
15684 than to get into an infinite loop calling the hook functions
15685 and having them get more errors. */
15686 if (!update_mode_line
15687 || ! NILP (Vwindow_scroll_functions
))
15689 update_mode_line
= 1;
15690 w
->update_mode_line
= 1;
15691 startp
= run_window_scroll_functions (window
, startp
);
15694 if (CHARPOS (startp
) < BEGV
)
15695 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
15696 else if (CHARPOS (startp
) > ZV
)
15697 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
15699 /* Redisplay, then check if cursor has been set during the
15700 redisplay. Give up if new fonts were loaded. */
15701 /* We used to issue a CHECK_MARGINS argument to try_window here,
15702 but this causes scrolling to fail when point begins inside
15703 the scroll margin (bug#148) -- cyd */
15704 if (!try_window (window
, startp
, 0))
15706 w
->force_start
= 1;
15707 clear_glyph_matrix (w
->desired_matrix
);
15708 goto need_larger_matrices
;
15711 if (w
->cursor
.vpos
< 0 && !window_frozen_p (w
))
15713 /* If point does not appear, try to move point so it does
15714 appear. The desired matrix has been built above, so we
15715 can use it here. */
15716 new_vpos
= window_box_height (w
) / 2;
15719 if (!cursor_row_fully_visible_p (w
, 0, 0))
15721 /* Point does appear, but on a line partly visible at end of window.
15722 Move it back to a fully-visible line. */
15723 new_vpos
= window_box_height (w
);
15725 else if (w
->cursor
.vpos
>=0)
15727 /* Some people insist on not letting point enter the scroll
15728 margin, even though this part handles windows that didn't
15730 int window_total_lines
15731 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
15732 int margin
= min (scroll_margin
, window_total_lines
/ 4);
15733 int pixel_margin
= margin
* frame_line_height
;
15734 bool header_line
= WINDOW_WANTS_HEADER_LINE_P (w
);
15736 /* Note: We add an extra FRAME_LINE_HEIGHT, because the loop
15737 below, which finds the row to move point to, advances by
15738 the Y coordinate of the _next_ row, see the definition of
15739 MATRIX_ROW_BOTTOM_Y. */
15740 if (w
->cursor
.vpos
< margin
+ header_line
)
15742 w
->cursor
.vpos
= -1;
15743 clear_glyph_matrix (w
->desired_matrix
);
15744 goto try_to_scroll
;
15748 int window_height
= window_box_height (w
);
15751 window_height
+= CURRENT_HEADER_LINE_HEIGHT (w
);
15752 if (w
->cursor
.y
>= window_height
- pixel_margin
)
15754 w
->cursor
.vpos
= -1;
15755 clear_glyph_matrix (w
->desired_matrix
);
15756 goto try_to_scroll
;
15761 /* If we need to move point for either of the above reasons,
15762 now actually do it. */
15765 struct glyph_row
*row
;
15767 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
15768 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
15771 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
15772 MATRIX_ROW_START_BYTEPOS (row
));
15774 if (w
!= XWINDOW (selected_window
))
15775 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
15776 else if (current_buffer
== old
)
15777 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15779 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
15781 /* If we are highlighting the region, then we just changed
15782 the region, so redisplay to show it. */
15783 if (markpos_of_region () >= 0)
15785 clear_glyph_matrix (w
->desired_matrix
);
15786 if (!try_window (window
, startp
, 0))
15787 goto need_larger_matrices
;
15792 debug_method_add (w
, "forced window start");
15797 /* Handle case where text has not changed, only point, and it has
15798 not moved off the frame, and we are not retrying after hscroll.
15799 (current_matrix_up_to_date_p is nonzero when retrying.) */
15800 if (current_matrix_up_to_date_p
15801 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
15802 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
15806 case CURSOR_MOVEMENT_SUCCESS
:
15807 used_current_matrix_p
= 1;
15810 case CURSOR_MOVEMENT_MUST_SCROLL
:
15811 goto try_to_scroll
;
15817 /* If current starting point was originally the beginning of a line
15818 but no longer is, find a new starting point. */
15819 else if (w
->start_at_line_beg
15820 && !(CHARPOS (startp
) <= BEGV
15821 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
15824 debug_method_add (w
, "recenter 1");
15829 /* Try scrolling with try_window_id. Value is > 0 if update has
15830 been done, it is -1 if we know that the same window start will
15831 not work. It is 0 if unsuccessful for some other reason. */
15832 else if ((tem
= try_window_id (w
)) != 0)
15835 debug_method_add (w
, "try_window_id %d", tem
);
15838 if (fonts_changed_p
)
15839 goto need_larger_matrices
;
15843 /* Otherwise try_window_id has returned -1 which means that we
15844 don't want the alternative below this comment to execute. */
15846 else if (CHARPOS (startp
) >= BEGV
15847 && CHARPOS (startp
) <= ZV
15848 && PT
>= CHARPOS (startp
)
15849 && (CHARPOS (startp
) < ZV
15850 /* Avoid starting at end of buffer. */
15851 || CHARPOS (startp
) == BEGV
15852 || !window_outdated (w
)))
15854 int d1
, d2
, d3
, d4
, d5
, d6
;
15856 /* If first window line is a continuation line, and window start
15857 is inside the modified region, but the first change is before
15858 current window start, we must select a new window start.
15860 However, if this is the result of a down-mouse event (e.g. by
15861 extending the mouse-drag-overlay), we don't want to select a
15862 new window start, since that would change the position under
15863 the mouse, resulting in an unwanted mouse-movement rather
15864 than a simple mouse-click. */
15865 if (!w
->start_at_line_beg
15866 && NILP (do_mouse_tracking
)
15867 && CHARPOS (startp
) > BEGV
15868 && CHARPOS (startp
) > BEG
+ beg_unchanged
15869 && CHARPOS (startp
) <= Z
- end_unchanged
15870 /* Even if w->start_at_line_beg is nil, a new window may
15871 start at a line_beg, since that's how set_buffer_window
15872 sets it. So, we need to check the return value of
15873 compute_window_start_on_continuation_line. (See also
15875 && XMARKER (w
->start
)->buffer
== current_buffer
15876 && compute_window_start_on_continuation_line (w
)
15877 /* It doesn't make sense to force the window start like we
15878 do at label force_start if it is already known that point
15879 will not be visible in the resulting window, because
15880 doing so will move point from its correct position
15881 instead of scrolling the window to bring point into view.
15883 && pos_visible_p (w
, PT
, &d1
, &d2
, &d3
, &d4
, &d5
, &d6
))
15885 w
->force_start
= 1;
15886 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15891 debug_method_add (w
, "same window start");
15894 /* Try to redisplay starting at same place as before.
15895 If point has not moved off frame, accept the results. */
15896 if (!current_matrix_up_to_date_p
15897 /* Don't use try_window_reusing_current_matrix in this case
15898 because a window scroll function can have changed the
15900 || !NILP (Vwindow_scroll_functions
)
15901 || MINI_WINDOW_P (w
)
15902 || !(used_current_matrix_p
15903 = try_window_reusing_current_matrix (w
)))
15905 IF_DEBUG (debug_method_add (w
, "1"));
15906 if (try_window (window
, startp
, TRY_WINDOW_CHECK_MARGINS
) < 0)
15907 /* -1 means we need to scroll.
15908 0 means we need new matrices, but fonts_changed_p
15909 is set in that case, so we will detect it below. */
15910 goto try_to_scroll
;
15913 if (fonts_changed_p
)
15914 goto need_larger_matrices
;
15916 if (w
->cursor
.vpos
>= 0)
15918 if (!just_this_one_p
15919 || current_buffer
->clip_changed
15920 || BEG_UNCHANGED
< CHARPOS (startp
))
15921 /* Forget any recorded base line for line number display. */
15922 w
->base_line_number
= 0;
15924 if (!cursor_row_fully_visible_p (w
, 1, 0))
15926 clear_glyph_matrix (w
->desired_matrix
);
15927 last_line_misfit
= 1;
15929 /* Drop through and scroll. */
15934 clear_glyph_matrix (w
->desired_matrix
);
15939 /* Redisplay the mode line. Select the buffer properly for that. */
15940 if (!update_mode_line
)
15942 update_mode_line
= 1;
15943 w
->update_mode_line
= 1;
15946 /* Try to scroll by specified few lines. */
15947 if ((scroll_conservatively
15948 || emacs_scroll_step
15949 || temp_scroll_step
15950 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
))
15951 || NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
)))
15952 && CHARPOS (startp
) >= BEGV
15953 && CHARPOS (startp
) <= ZV
)
15955 /* The function returns -1 if new fonts were loaded, 1 if
15956 successful, 0 if not successful. */
15957 int ss
= try_scrolling (window
, just_this_one_p
,
15958 scroll_conservatively
,
15960 temp_scroll_step
, last_line_misfit
);
15963 case SCROLLING_SUCCESS
:
15966 case SCROLLING_NEED_LARGER_MATRICES
:
15967 goto need_larger_matrices
;
15969 case SCROLLING_FAILED
:
15977 /* Finally, just choose a place to start which positions point
15978 according to user preferences. */
15983 debug_method_add (w
, "recenter");
15986 /* Forget any previously recorded base line for line number display. */
15987 if (!buffer_unchanged_p
)
15988 w
->base_line_number
= 0;
15990 /* Determine the window start relative to point. */
15991 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
15992 it
.current_y
= it
.last_visible_y
;
15993 if (centering_position
< 0)
15995 int window_total_lines
15996 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
15999 ? min (scroll_margin
, window_total_lines
/ 4)
16001 ptrdiff_t margin_pos
= CHARPOS (startp
);
16002 Lisp_Object aggressive
;
16005 /* If there is a scroll margin at the top of the window, find
16006 its character position. */
16008 /* Cannot call start_display if startp is not in the
16009 accessible region of the buffer. This can happen when we
16010 have just switched to a different buffer and/or changed
16011 its restriction. In that case, startp is initialized to
16012 the character position 1 (BEGV) because we did not yet
16013 have chance to display the buffer even once. */
16014 && BEGV
<= CHARPOS (startp
) && CHARPOS (startp
) <= ZV
)
16017 void *it1data
= NULL
;
16019 SAVE_IT (it1
, it
, it1data
);
16020 start_display (&it1
, w
, startp
);
16021 move_it_vertically (&it1
, margin
* frame_line_height
);
16022 margin_pos
= IT_CHARPOS (it1
);
16023 RESTORE_IT (&it
, &it
, it1data
);
16025 scrolling_up
= PT
> margin_pos
;
16028 ? BVAR (current_buffer
, scroll_up_aggressively
)
16029 : BVAR (current_buffer
, scroll_down_aggressively
);
16031 if (!MINI_WINDOW_P (w
)
16032 && (scroll_conservatively
> SCROLL_LIMIT
|| NUMBERP (aggressive
)))
16036 /* Setting scroll-conservatively overrides
16037 scroll-*-aggressively. */
16038 if (!scroll_conservatively
&& NUMBERP (aggressive
))
16040 double float_amount
= XFLOATINT (aggressive
);
16042 pt_offset
= float_amount
* WINDOW_BOX_TEXT_HEIGHT (w
);
16043 if (pt_offset
== 0 && float_amount
> 0)
16045 if (pt_offset
&& margin
> 0)
16048 /* Compute how much to move the window start backward from
16049 point so that point will be displayed where the user
16053 centering_position
= it
.last_visible_y
;
16055 centering_position
-= pt_offset
;
16056 centering_position
-=
16057 frame_line_height
* (1 + margin
+ (last_line_misfit
!= 0))
16058 + WINDOW_HEADER_LINE_HEIGHT (w
);
16059 /* Don't let point enter the scroll margin near top of
16061 if (centering_position
< margin
* frame_line_height
)
16062 centering_position
= margin
* frame_line_height
;
16065 centering_position
= margin
* frame_line_height
+ pt_offset
;
16068 /* Set the window start half the height of the window backward
16070 centering_position
= window_box_height (w
) / 2;
16072 move_it_vertically_backward (&it
, centering_position
);
16074 eassert (IT_CHARPOS (it
) >= BEGV
);
16076 /* The function move_it_vertically_backward may move over more
16077 than the specified y-distance. If it->w is small, e.g. a
16078 mini-buffer window, we may end up in front of the window's
16079 display area. Start displaying at the start of the line
16080 containing PT in this case. */
16081 if (it
.current_y
<= 0)
16083 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
16084 move_it_vertically_backward (&it
, 0);
16088 it
.current_x
= it
.hpos
= 0;
16090 /* Set the window start position here explicitly, to avoid an
16091 infinite loop in case the functions in window-scroll-functions
16093 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
16095 /* Run scroll hooks. */
16096 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
16098 /* Redisplay the window. */
16099 if (!current_matrix_up_to_date_p
16100 || windows_or_buffers_changed
16101 || cursor_type_changed
16102 /* Don't use try_window_reusing_current_matrix in this case
16103 because it can have changed the buffer. */
16104 || !NILP (Vwindow_scroll_functions
)
16105 || !just_this_one_p
16106 || MINI_WINDOW_P (w
)
16107 || !(used_current_matrix_p
16108 = try_window_reusing_current_matrix (w
)))
16109 try_window (window
, startp
, 0);
16111 /* If new fonts have been loaded (due to fontsets), give up. We
16112 have to start a new redisplay since we need to re-adjust glyph
16114 if (fonts_changed_p
)
16115 goto need_larger_matrices
;
16117 /* If cursor did not appear assume that the middle of the window is
16118 in the first line of the window. Do it again with the next line.
16119 (Imagine a window of height 100, displaying two lines of height
16120 60. Moving back 50 from it->last_visible_y will end in the first
16122 if (w
->cursor
.vpos
< 0)
16124 if (w
->window_end_valid
&& PT
>= Z
- w
->window_end_pos
)
16126 clear_glyph_matrix (w
->desired_matrix
);
16127 move_it_by_lines (&it
, 1);
16128 try_window (window
, it
.current
.pos
, 0);
16130 else if (PT
< IT_CHARPOS (it
))
16132 clear_glyph_matrix (w
->desired_matrix
);
16133 move_it_by_lines (&it
, -1);
16134 try_window (window
, it
.current
.pos
, 0);
16138 /* Not much we can do about it. */
16142 /* Consider the following case: Window starts at BEGV, there is
16143 invisible, intangible text at BEGV, so that display starts at
16144 some point START > BEGV. It can happen that we are called with
16145 PT somewhere between BEGV and START. Try to handle that case. */
16146 if (w
->cursor
.vpos
< 0)
16148 struct glyph_row
*row
= w
->current_matrix
->rows
;
16149 if (row
->mode_line_p
)
16151 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
16154 if (!cursor_row_fully_visible_p (w
, 0, 0))
16156 /* If vscroll is enabled, disable it and try again. */
16160 clear_glyph_matrix (w
->desired_matrix
);
16164 /* Users who set scroll-conservatively to a large number want
16165 point just above/below the scroll margin. If we ended up
16166 with point's row partially visible, move the window start to
16167 make that row fully visible and out of the margin. */
16168 if (scroll_conservatively
> SCROLL_LIMIT
)
16170 int window_total_lines
16171 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) * frame_line_height
;
16174 ? min (scroll_margin
, window_total_lines
/ 4)
16176 int move_down
= w
->cursor
.vpos
>= window_total_lines
/ 2;
16178 move_it_by_lines (&it
, move_down
? margin
+ 1 : -(margin
+ 1));
16179 clear_glyph_matrix (w
->desired_matrix
);
16180 if (1 == try_window (window
, it
.current
.pos
,
16181 TRY_WINDOW_CHECK_MARGINS
))
16185 /* If centering point failed to make the whole line visible,
16186 put point at the top instead. That has to make the whole line
16187 visible, if it can be done. */
16188 if (centering_position
== 0)
16191 clear_glyph_matrix (w
->desired_matrix
);
16192 centering_position
= 0;
16198 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
16199 w
->start_at_line_beg
= (CHARPOS (startp
) == BEGV
16200 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n');
16202 /* Display the mode line, if we must. */
16203 if ((update_mode_line
16204 /* If window not full width, must redo its mode line
16205 if (a) the window to its side is being redone and
16206 (b) we do a frame-based redisplay. This is a consequence
16207 of how inverted lines are drawn in frame-based redisplay. */
16208 || (!just_this_one_p
16209 && !FRAME_WINDOW_P (f
)
16210 && !WINDOW_FULL_WIDTH_P (w
))
16211 /* Line number to display. */
16212 || w
->base_line_pos
> 0
16213 /* Column number is displayed and different from the one displayed. */
16214 || (w
->column_number_displayed
!= -1
16215 && (w
->column_number_displayed
!= current_column ())))
16216 /* This means that the window has a mode line. */
16217 && (WINDOW_WANTS_MODELINE_P (w
)
16218 || WINDOW_WANTS_HEADER_LINE_P (w
)))
16220 display_mode_lines (w
);
16222 /* If mode line height has changed, arrange for a thorough
16223 immediate redisplay using the correct mode line height. */
16224 if (WINDOW_WANTS_MODELINE_P (w
)
16225 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
16227 fonts_changed_p
= 1;
16228 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
16229 = DESIRED_MODE_LINE_HEIGHT (w
);
16232 /* If header line height has changed, arrange for a thorough
16233 immediate redisplay using the correct header line height. */
16234 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16235 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
16237 fonts_changed_p
= 1;
16238 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
16239 = DESIRED_HEADER_LINE_HEIGHT (w
);
16242 if (fonts_changed_p
)
16243 goto need_larger_matrices
;
16246 if (!line_number_displayed
&& w
->base_line_pos
!= -1)
16248 w
->base_line_pos
= 0;
16249 w
->base_line_number
= 0;
16254 /* When we reach a frame's selected window, redo the frame's menu bar. */
16255 if (update_mode_line
16256 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
16258 int redisplay_menu_p
= 0;
16260 if (FRAME_WINDOW_P (f
))
16262 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
16263 || defined (HAVE_NS) || defined (USE_GTK)
16264 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
16266 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16270 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16272 if (redisplay_menu_p
)
16273 display_menu_bar (w
);
16275 #ifdef HAVE_WINDOW_SYSTEM
16276 if (FRAME_WINDOW_P (f
))
16278 #if defined (USE_GTK) || defined (HAVE_NS)
16279 if (FRAME_EXTERNAL_TOOL_BAR (f
))
16280 redisplay_tool_bar (f
);
16282 if (WINDOWP (f
->tool_bar_window
)
16283 && (FRAME_TOOL_BAR_LINES (f
) > 0
16284 || !NILP (Vauto_resize_tool_bars
))
16285 && redisplay_tool_bar (f
))
16286 ignore_mouse_drag_p
= 1;
16292 #ifdef HAVE_WINDOW_SYSTEM
16293 if (FRAME_WINDOW_P (f
)
16294 && update_window_fringes (w
, (just_this_one_p
16295 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
16296 || w
->pseudo_window_p
)))
16300 if (draw_window_fringes (w
, 1))
16301 x_draw_vertical_border (w
);
16305 #endif /* HAVE_WINDOW_SYSTEM */
16307 /* We go to this label, with fonts_changed_p set,
16308 if it is necessary to try again using larger glyph matrices.
16309 We have to redeem the scroll bar even in this case,
16310 because the loop in redisplay_internal expects that. */
16311 need_larger_matrices
:
16313 finish_scroll_bars
:
16315 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
16317 /* Set the thumb's position and size. */
16318 set_vertical_scroll_bar (w
);
16320 /* Note that we actually used the scroll bar attached to this
16321 window, so it shouldn't be deleted at the end of redisplay. */
16322 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
16323 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
16326 /* Restore current_buffer and value of point in it. The window
16327 update may have changed the buffer, so first make sure `opoint'
16328 is still valid (Bug#6177). */
16329 if (CHARPOS (opoint
) < BEGV
)
16330 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
16331 else if (CHARPOS (opoint
) > ZV
)
16332 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
16334 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
16336 set_buffer_internal_1 (old
);
16337 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
16338 shorter. This can be caused by log truncation in *Messages*. */
16339 if (CHARPOS (lpoint
) <= ZV
)
16340 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
16342 unbind_to (count
, Qnil
);
16346 /* Build the complete desired matrix of WINDOW with a window start
16347 buffer position POS.
16349 Value is 1 if successful. It is zero if fonts were loaded during
16350 redisplay which makes re-adjusting glyph matrices necessary, and -1
16351 if point would appear in the scroll margins.
16352 (We check the former only if TRY_WINDOW_IGNORE_FONTS_CHANGE is
16353 unset in FLAGS, and the latter only if TRY_WINDOW_CHECK_MARGINS is
16357 try_window (Lisp_Object window
, struct text_pos pos
, int flags
)
16359 struct window
*w
= XWINDOW (window
);
16361 struct glyph_row
*last_text_row
= NULL
;
16362 struct frame
*f
= XFRAME (w
->frame
);
16363 int frame_line_height
= default_line_pixel_height (w
);
16365 /* Make POS the new window start. */
16366 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
16368 /* Mark cursor position as unknown. No overlay arrow seen. */
16369 w
->cursor
.vpos
= -1;
16370 overlay_arrow_seen
= 0;
16372 /* Initialize iterator and info to start at POS. */
16373 start_display (&it
, w
, pos
);
16377 /* Display all lines of W. */
16378 while (it
.current_y
< it
.last_visible_y
)
16380 if (display_line (&it
))
16381 last_text_row
= it
.glyph_row
- 1;
16382 if (fonts_changed_p
&& !(flags
& TRY_WINDOW_IGNORE_FONTS_CHANGE
))
16385 #ifdef HAVE_XWIDGETS_xxx
16386 //currently this is needed to detect xwidget movement reliably. or probably not.
16387 printf("try_window\n");
16391 /* Don't let the cursor end in the scroll margins. */
16392 if ((flags
& TRY_WINDOW_CHECK_MARGINS
)
16393 && !MINI_WINDOW_P (w
))
16395 int this_scroll_margin
;
16396 int window_total_lines
16397 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
16399 if (scroll_margin
> 0)
16401 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4);
16402 this_scroll_margin
*= frame_line_height
;
16405 this_scroll_margin
= 0;
16407 if ((w
->cursor
.y
>= 0 /* not vscrolled */
16408 && w
->cursor
.y
< this_scroll_margin
16409 && CHARPOS (pos
) > BEGV
16410 && IT_CHARPOS (it
) < ZV
)
16411 /* rms: considering make_cursor_line_fully_visible_p here
16412 seems to give wrong results. We don't want to recenter
16413 when the last line is partly visible, we want to allow
16414 that case to be handled in the usual way. */
16415 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
16417 w
->cursor
.vpos
= -1;
16418 clear_glyph_matrix (w
->desired_matrix
);
16423 /* If bottom moved off end of frame, change mode line percentage. */
16424 if (w
->window_end_pos
<= 0 && Z
!= IT_CHARPOS (it
))
16425 w
->update_mode_line
= 1;
16427 /* Set window_end_pos to the offset of the last character displayed
16428 on the window from the end of current_buffer. Set
16429 window_end_vpos to its row number. */
16432 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
16433 adjust_window_ends (w
, last_text_row
, 0);
16435 (MATRIX_ROW_DISPLAYS_TEXT_P (MATRIX_ROW (w
->desired_matrix
,
16436 w
->window_end_vpos
)));
16440 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16441 w
->window_end_pos
= Z
- ZV
;
16442 w
->window_end_vpos
= 0;
16445 /* But that is not valid info until redisplay finishes. */
16446 w
->window_end_valid
= 0;
16452 /************************************************************************
16453 Window redisplay reusing current matrix when buffer has not changed
16454 ************************************************************************/
16456 /* Try redisplay of window W showing an unchanged buffer with a
16457 different window start than the last time it was displayed by
16458 reusing its current matrix. Value is non-zero if successful.
16459 W->start is the new window start. */
16462 try_window_reusing_current_matrix (struct window
*w
)
16464 struct frame
*f
= XFRAME (w
->frame
);
16465 struct glyph_row
*bottom_row
;
16468 struct text_pos start
, new_start
;
16469 int nrows_scrolled
, i
;
16470 struct glyph_row
*last_text_row
;
16471 struct glyph_row
*last_reused_text_row
;
16472 struct glyph_row
*start_row
;
16473 int start_vpos
, min_y
, max_y
;
16476 if (inhibit_try_window_reusing
)
16480 #ifdef HAVE_XWIDGETS_xxx
16481 //currently this is needed to detect xwidget movement reliably. or probably not.
16482 printf("try_window_reusing_current_matrix\n");
16487 if (/* This function doesn't handle terminal frames. */
16488 !FRAME_WINDOW_P (f
)
16489 /* Don't try to reuse the display if windows have been split
16491 || windows_or_buffers_changed
16492 || cursor_type_changed
)
16495 /* Can't do this if region may have changed. */
16496 if (markpos_of_region () >= 0
16497 || w
->region_showing
16498 || !NILP (Vshow_trailing_whitespace
))
16501 /* If top-line visibility has changed, give up. */
16502 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16503 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
16506 /* Give up if old or new display is scrolled vertically. We could
16507 make this function handle this, but right now it doesn't. */
16508 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16509 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
16512 /* The variable new_start now holds the new window start. The old
16513 start `start' can be determined from the current matrix. */
16514 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
16515 start
= start_row
->minpos
;
16516 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16518 /* Clear the desired matrix for the display below. */
16519 clear_glyph_matrix (w
->desired_matrix
);
16521 if (CHARPOS (new_start
) <= CHARPOS (start
))
16523 /* Don't use this method if the display starts with an ellipsis
16524 displayed for invisible text. It's not easy to handle that case
16525 below, and it's certainly not worth the effort since this is
16526 not a frequent case. */
16527 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
16530 IF_DEBUG (debug_method_add (w
, "twu1"));
16532 /* Display up to a row that can be reused. The variable
16533 last_text_row is set to the last row displayed that displays
16534 text. Note that it.vpos == 0 if or if not there is a
16535 header-line; it's not the same as the MATRIX_ROW_VPOS! */
16536 start_display (&it
, w
, new_start
);
16537 w
->cursor
.vpos
= -1;
16538 last_text_row
= last_reused_text_row
= NULL
;
16540 while (it
.current_y
< it
.last_visible_y
16541 && !fonts_changed_p
)
16543 /* If we have reached into the characters in the START row,
16544 that means the line boundaries have changed. So we
16545 can't start copying with the row START. Maybe it will
16546 work to start copying with the following row. */
16547 while (IT_CHARPOS (it
) > CHARPOS (start
))
16549 /* Advance to the next row as the "start". */
16551 start
= start_row
->minpos
;
16552 /* If there are no more rows to try, or just one, give up. */
16553 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
16554 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
16555 || CHARPOS (start
) == ZV
)
16557 clear_glyph_matrix (w
->desired_matrix
);
16561 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16563 /* If we have reached alignment, we can copy the rest of the
16565 if (IT_CHARPOS (it
) == CHARPOS (start
)
16566 /* Don't accept "alignment" inside a display vector,
16567 since start_row could have started in the middle of
16568 that same display vector (thus their character
16569 positions match), and we have no way of telling if
16570 that is the case. */
16571 && it
.current
.dpvec_index
< 0)
16574 if (display_line (&it
))
16575 last_text_row
= it
.glyph_row
- 1;
16579 /* A value of current_y < last_visible_y means that we stopped
16580 at the previous window start, which in turn means that we
16581 have at least one reusable row. */
16582 if (it
.current_y
< it
.last_visible_y
)
16584 struct glyph_row
*row
;
16586 /* IT.vpos always starts from 0; it counts text lines. */
16587 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
16589 /* Find PT if not already found in the lines displayed. */
16590 if (w
->cursor
.vpos
< 0)
16592 int dy
= it
.current_y
- start_row
->y
;
16594 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16595 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
16597 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
16598 dy
, nrows_scrolled
);
16601 clear_glyph_matrix (w
->desired_matrix
);
16606 /* Scroll the display. Do it before the current matrix is
16607 changed. The problem here is that update has not yet
16608 run, i.e. part of the current matrix is not up to date.
16609 scroll_run_hook will clear the cursor, and use the
16610 current matrix to get the height of the row the cursor is
16612 run
.current_y
= start_row
->y
;
16613 run
.desired_y
= it
.current_y
;
16614 run
.height
= it
.last_visible_y
- it
.current_y
;
16616 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
16619 FRAME_RIF (f
)->update_window_begin_hook (w
);
16620 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16621 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16622 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16626 /* Shift current matrix down by nrows_scrolled lines. */
16627 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16628 rotate_matrix (w
->current_matrix
,
16630 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16633 /* Disable lines that must be updated. */
16634 for (i
= 0; i
< nrows_scrolled
; ++i
)
16635 (start_row
+ i
)->enabled_p
= 0;
16637 /* Re-compute Y positions. */
16638 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16639 max_y
= it
.last_visible_y
;
16640 for (row
= start_row
+ nrows_scrolled
;
16644 row
->y
= it
.current_y
;
16645 row
->visible_height
= row
->height
;
16647 if (row
->y
< min_y
)
16648 row
->visible_height
-= min_y
- row
->y
;
16649 if (row
->y
+ row
->height
> max_y
)
16650 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16651 if (row
->fringe_bitmap_periodic_p
)
16652 row
->redraw_fringe_bitmaps_p
= 1;
16654 it
.current_y
+= row
->height
;
16656 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16657 last_reused_text_row
= row
;
16658 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
16662 /* Disable lines in the current matrix which are now
16663 below the window. */
16664 for (++row
; row
< bottom_row
; ++row
)
16665 row
->enabled_p
= row
->mode_line_p
= 0;
16668 /* Update window_end_pos etc.; last_reused_text_row is the last
16669 reused row from the current matrix containing text, if any.
16670 The value of last_text_row is the last displayed line
16671 containing text. */
16672 if (last_reused_text_row
)
16673 adjust_window_ends (w
, last_reused_text_row
, 1);
16674 else if (last_text_row
)
16675 adjust_window_ends (w
, last_text_row
, 0);
16678 /* This window must be completely empty. */
16679 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16680 w
->window_end_pos
= Z
- ZV
;
16681 w
->window_end_vpos
= 0;
16683 w
->window_end_valid
= 0;
16685 /* Update hint: don't try scrolling again in update_window. */
16686 w
->desired_matrix
->no_scrolling_p
= 1;
16689 debug_method_add (w
, "try_window_reusing_current_matrix 1");
16693 else if (CHARPOS (new_start
) > CHARPOS (start
))
16695 struct glyph_row
*pt_row
, *row
;
16696 struct glyph_row
*first_reusable_row
;
16697 struct glyph_row
*first_row_to_display
;
16699 int yb
= window_text_bottom_y (w
);
16701 /* Find the row starting at new_start, if there is one. Don't
16702 reuse a partially visible line at the end. */
16703 first_reusable_row
= start_row
;
16704 while (first_reusable_row
->enabled_p
16705 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
16706 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16707 < CHARPOS (new_start
)))
16708 ++first_reusable_row
;
16710 /* Give up if there is no row to reuse. */
16711 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
16712 || !first_reusable_row
->enabled_p
16713 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16714 != CHARPOS (new_start
)))
16717 /* We can reuse fully visible rows beginning with
16718 first_reusable_row to the end of the window. Set
16719 first_row_to_display to the first row that cannot be reused.
16720 Set pt_row to the row containing point, if there is any. */
16722 for (first_row_to_display
= first_reusable_row
;
16723 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
16724 ++first_row_to_display
)
16726 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
16727 && (PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16728 || (PT
== MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16729 && first_row_to_display
->ends_at_zv_p
16730 && pt_row
== NULL
)))
16731 pt_row
= first_row_to_display
;
16734 /* Start displaying at the start of first_row_to_display. */
16735 eassert (first_row_to_display
->y
< yb
);
16736 init_to_row_start (&it
, w
, first_row_to_display
);
16738 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
16740 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
16742 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
16743 + WINDOW_HEADER_LINE_HEIGHT (w
));
16745 /* Display lines beginning with first_row_to_display in the
16746 desired matrix. Set last_text_row to the last row displayed
16747 that displays text. */
16748 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
16749 if (pt_row
== NULL
)
16750 w
->cursor
.vpos
= -1;
16751 last_text_row
= NULL
;
16752 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
16753 if (display_line (&it
))
16754 last_text_row
= it
.glyph_row
- 1;
16756 /* If point is in a reused row, adjust y and vpos of the cursor
16760 w
->cursor
.vpos
-= nrows_scrolled
;
16761 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
16764 /* Give up if point isn't in a row displayed or reused. (This
16765 also handles the case where w->cursor.vpos < nrows_scrolled
16766 after the calls to display_line, which can happen with scroll
16767 margins. See bug#1295.) */
16768 if (w
->cursor
.vpos
< 0)
16770 clear_glyph_matrix (w
->desired_matrix
);
16774 /* Scroll the display. */
16775 run
.current_y
= first_reusable_row
->y
;
16776 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16777 run
.height
= it
.last_visible_y
- run
.current_y
;
16778 dy
= run
.current_y
- run
.desired_y
;
16783 FRAME_RIF (f
)->update_window_begin_hook (w
);
16784 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16785 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16786 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16790 /* Adjust Y positions of reused rows. */
16791 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16792 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16793 max_y
= it
.last_visible_y
;
16794 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
16797 row
->visible_height
= row
->height
;
16798 if (row
->y
< min_y
)
16799 row
->visible_height
-= min_y
- row
->y
;
16800 if (row
->y
+ row
->height
> max_y
)
16801 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16802 if (row
->fringe_bitmap_periodic_p
)
16803 row
->redraw_fringe_bitmaps_p
= 1;
16806 /* Scroll the current matrix. */
16807 eassert (nrows_scrolled
> 0);
16808 rotate_matrix (w
->current_matrix
,
16810 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16813 /* Disable rows not reused. */
16814 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
16815 row
->enabled_p
= 0;
16817 /* Point may have moved to a different line, so we cannot assume that
16818 the previous cursor position is valid; locate the correct row. */
16821 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
16823 && PT
>= MATRIX_ROW_END_CHARPOS (row
)
16824 && !row
->ends_at_zv_p
;
16828 w
->cursor
.y
= row
->y
;
16830 if (row
< bottom_row
)
16832 /* Can't simply scan the row for point with
16833 bidi-reordered glyph rows. Let set_cursor_from_row
16834 figure out where to put the cursor, and if it fails,
16836 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
16838 if (!set_cursor_from_row (w
, row
, w
->current_matrix
,
16841 clear_glyph_matrix (w
->desired_matrix
);
16847 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
16848 struct glyph
*end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16851 && (!BUFFERP (glyph
->object
)
16852 || glyph
->charpos
< PT
);
16856 w
->cursor
.x
+= glyph
->pixel_width
;
16862 /* Adjust window end. A null value of last_text_row means that
16863 the window end is in reused rows which in turn means that
16864 only its vpos can have changed. */
16866 adjust_window_ends (w
, last_text_row
, 0);
16868 w
->window_end_vpos
-= nrows_scrolled
;
16870 w
->window_end_valid
= 0;
16871 w
->desired_matrix
->no_scrolling_p
= 1;
16874 debug_method_add (w
, "try_window_reusing_current_matrix 2");
16884 /************************************************************************
16885 Window redisplay reusing current matrix when buffer has changed
16886 ************************************************************************/
16888 static struct glyph_row
*find_last_unchanged_at_beg_row (struct window
*);
16889 static struct glyph_row
*find_first_unchanged_at_end_row (struct window
*,
16890 ptrdiff_t *, ptrdiff_t *);
16891 static struct glyph_row
*
16892 find_last_row_displaying_text (struct glyph_matrix
*, struct it
*,
16893 struct glyph_row
*);
16896 /* Return the last row in MATRIX displaying text. If row START is
16897 non-null, start searching with that row. IT gives the dimensions
16898 of the display. Value is null if matrix is empty; otherwise it is
16899 a pointer to the row found. */
16901 static struct glyph_row
*
16902 find_last_row_displaying_text (struct glyph_matrix
*matrix
, struct it
*it
,
16903 struct glyph_row
*start
)
16905 struct glyph_row
*row
, *row_found
;
16907 /* Set row_found to the last row in IT->w's current matrix
16908 displaying text. The loop looks funny but think of partially
16911 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
16912 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16914 eassert (row
->enabled_p
);
16916 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
16925 /* Return the last row in the current matrix of W that is not affected
16926 by changes at the start of current_buffer that occurred since W's
16927 current matrix was built. Value is null if no such row exists.
16929 BEG_UNCHANGED us the number of characters unchanged at the start of
16930 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
16931 first changed character in current_buffer. Characters at positions <
16932 BEG + BEG_UNCHANGED are at the same buffer positions as they were
16933 when the current matrix was built. */
16935 static struct glyph_row
*
16936 find_last_unchanged_at_beg_row (struct window
*w
)
16938 ptrdiff_t first_changed_pos
= BEG
+ BEG_UNCHANGED
;
16939 struct glyph_row
*row
;
16940 struct glyph_row
*row_found
= NULL
;
16941 int yb
= window_text_bottom_y (w
);
16943 /* Find the last row displaying unchanged text. */
16944 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16945 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
16946 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
16949 if (/* If row ends before first_changed_pos, it is unchanged,
16950 except in some case. */
16951 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
16952 /* When row ends in ZV and we write at ZV it is not
16954 && !row
->ends_at_zv_p
16955 /* When first_changed_pos is the end of a continued line,
16956 row is not unchanged because it may be no longer
16958 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
16959 && (row
->continued_p
16960 || row
->exact_window_width_line_p
))
16961 /* If ROW->end is beyond ZV, then ROW->end is outdated and
16962 needs to be recomputed, so don't consider this row as
16963 unchanged. This happens when the last line was
16964 bidi-reordered and was killed immediately before this
16965 redisplay cycle. In that case, ROW->end stores the
16966 buffer position of the first visual-order character of
16967 the killed text, which is now beyond ZV. */
16968 && CHARPOS (row
->end
.pos
) <= ZV
)
16971 /* Stop if last visible row. */
16972 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
16980 /* Find the first glyph row in the current matrix of W that is not
16981 affected by changes at the end of current_buffer since the
16982 time W's current matrix was built.
16984 Return in *DELTA the number of chars by which buffer positions in
16985 unchanged text at the end of current_buffer must be adjusted.
16987 Return in *DELTA_BYTES the corresponding number of bytes.
16989 Value is null if no such row exists, i.e. all rows are affected by
16992 static struct glyph_row
*
16993 find_first_unchanged_at_end_row (struct window
*w
,
16994 ptrdiff_t *delta
, ptrdiff_t *delta_bytes
)
16996 struct glyph_row
*row
;
16997 struct glyph_row
*row_found
= NULL
;
16999 *delta
= *delta_bytes
= 0;
17001 /* Display must not have been paused, otherwise the current matrix
17002 is not up to date. */
17003 eassert (w
->window_end_valid
);
17005 /* A value of window_end_pos >= END_UNCHANGED means that the window
17006 end is in the range of changed text. If so, there is no
17007 unchanged row at the end of W's current matrix. */
17008 if (w
->window_end_pos
>= END_UNCHANGED
)
17011 /* Set row to the last row in W's current matrix displaying text. */
17012 row
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
17014 /* If matrix is entirely empty, no unchanged row exists. */
17015 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
17017 /* The value of row is the last glyph row in the matrix having a
17018 meaningful buffer position in it. The end position of row
17019 corresponds to window_end_pos. This allows us to translate
17020 buffer positions in the current matrix to current buffer
17021 positions for characters not in changed text. */
17023 MATRIX_ROW_END_CHARPOS (row
) + w
->window_end_pos
;
17024 ptrdiff_t Z_BYTE_old
=
17025 MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
17026 ptrdiff_t last_unchanged_pos
, last_unchanged_pos_old
;
17027 struct glyph_row
*first_text_row
17028 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
17030 *delta
= Z
- Z_old
;
17031 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
17033 /* Set last_unchanged_pos to the buffer position of the last
17034 character in the buffer that has not been changed. Z is the
17035 index + 1 of the last character in current_buffer, i.e. by
17036 subtracting END_UNCHANGED we get the index of the last
17037 unchanged character, and we have to add BEG to get its buffer
17039 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
17040 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
17042 /* Search backward from ROW for a row displaying a line that
17043 starts at a minimum position >= last_unchanged_pos_old. */
17044 for (; row
> first_text_row
; --row
)
17046 /* This used to abort, but it can happen.
17047 It is ok to just stop the search instead here. KFS. */
17048 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
17051 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
17056 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
17062 /* Make sure that glyph rows in the current matrix of window W
17063 reference the same glyph memory as corresponding rows in the
17064 frame's frame matrix. This function is called after scrolling W's
17065 current matrix on a terminal frame in try_window_id and
17066 try_window_reusing_current_matrix. */
17069 sync_frame_with_window_matrix_rows (struct window
*w
)
17071 struct frame
*f
= XFRAME (w
->frame
);
17072 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
17074 /* Preconditions: W must be a leaf window and full-width. Its frame
17075 must have a frame matrix. */
17076 eassert (BUFFERP (w
->contents
));
17077 eassert (WINDOW_FULL_WIDTH_P (w
));
17078 eassert (!FRAME_WINDOW_P (f
));
17080 /* If W is a full-width window, glyph pointers in W's current matrix
17081 have, by definition, to be the same as glyph pointers in the
17082 corresponding frame matrix. Note that frame matrices have no
17083 marginal areas (see build_frame_matrix). */
17084 window_row
= w
->current_matrix
->rows
;
17085 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
17086 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
17087 while (window_row
< window_row_end
)
17089 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
17090 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
17092 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
17093 frame_row
->glyphs
[TEXT_AREA
] = start
;
17094 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
17095 frame_row
->glyphs
[LAST_AREA
] = end
;
17097 /* Disable frame rows whose corresponding window rows have
17098 been disabled in try_window_id. */
17099 if (!window_row
->enabled_p
)
17100 frame_row
->enabled_p
= 0;
17102 ++window_row
, ++frame_row
;
17107 /* Find the glyph row in window W containing CHARPOS. Consider all
17108 rows between START and END (not inclusive). END null means search
17109 all rows to the end of the display area of W. Value is the row
17110 containing CHARPOS or null. */
17113 row_containing_pos (struct window
*w
, ptrdiff_t charpos
,
17114 struct glyph_row
*start
, struct glyph_row
*end
, int dy
)
17116 struct glyph_row
*row
= start
;
17117 struct glyph_row
*best_row
= NULL
;
17118 ptrdiff_t mindif
= BUF_ZV (XBUFFER (w
->contents
)) + 1;
17121 /* If we happen to start on a header-line, skip that. */
17122 if (row
->mode_line_p
)
17125 if ((end
&& row
>= end
) || !row
->enabled_p
)
17128 last_y
= window_text_bottom_y (w
) - dy
;
17132 /* Give up if we have gone too far. */
17133 if (end
&& row
>= end
)
17135 /* This formerly returned if they were equal.
17136 I think that both quantities are of a "last plus one" type;
17137 if so, when they are equal, the row is within the screen. -- rms. */
17138 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
17141 /* If it is in this row, return this row. */
17142 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
17143 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
17144 /* The end position of a row equals the start
17145 position of the next row. If CHARPOS is there, we
17146 would rather consider it displayed in the next
17147 line, except when this line ends in ZV. */
17148 && !row_for_charpos_p (row
, charpos
)))
17149 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
17153 if (NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
17154 || (!best_row
&& !row
->continued_p
))
17156 /* In bidi-reordered rows, there could be several rows whose
17157 edges surround CHARPOS, all of these rows belonging to
17158 the same continued line. We need to find the row which
17159 fits CHARPOS the best. */
17160 for (g
= row
->glyphs
[TEXT_AREA
];
17161 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
17164 if (!STRINGP (g
->object
))
17166 if (g
->charpos
> 0 && eabs (g
->charpos
- charpos
) < mindif
)
17168 mindif
= eabs (g
->charpos
- charpos
);
17170 /* Exact match always wins. */
17177 else if (best_row
&& !row
->continued_p
)
17184 /* Try to redisplay window W by reusing its existing display. W's
17185 current matrix must be up to date when this function is called,
17186 i.e. window_end_valid must be nonzero.
17190 1 if display has been updated
17191 0 if otherwise unsuccessful
17192 -1 if redisplay with same window start is known not to succeed
17194 The following steps are performed:
17196 1. Find the last row in the current matrix of W that is not
17197 affected by changes at the start of current_buffer. If no such row
17200 2. Find the first row in W's current matrix that is not affected by
17201 changes at the end of current_buffer. Maybe there is no such row.
17203 3. Display lines beginning with the row + 1 found in step 1 to the
17204 row found in step 2 or, if step 2 didn't find a row, to the end of
17207 4. If cursor is not known to appear on the window, give up.
17209 5. If display stopped at the row found in step 2, scroll the
17210 display and current matrix as needed.
17212 6. Maybe display some lines at the end of W, if we must. This can
17213 happen under various circumstances, like a partially visible line
17214 becoming fully visible, or because newly displayed lines are displayed
17215 in smaller font sizes.
17217 7. Update W's window end information. */
17220 try_window_id (struct window
*w
)
17222 struct frame
*f
= XFRAME (w
->frame
);
17223 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
17224 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
17225 struct glyph_row
*last_unchanged_at_beg_row
;
17226 struct glyph_row
*first_unchanged_at_end_row
;
17227 struct glyph_row
*row
;
17228 struct glyph_row
*bottom_row
;
17231 ptrdiff_t delta
= 0, delta_bytes
= 0, stop_pos
;
17233 struct text_pos start_pos
;
17235 int first_unchanged_at_end_vpos
= 0;
17236 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
17237 struct text_pos start
;
17238 ptrdiff_t first_changed_charpos
, last_changed_charpos
;
17241 if (inhibit_try_window_id
)
17245 #ifdef HAVE_XWIDGETS_xxx
17246 //maybe needed for proper xwidget movement
17247 printf("try_window_id\n");
17252 /* This is handy for debugging. */
17254 #define GIVE_UP(X) \
17256 fprintf (stderr, "try_window_id give up %d\n", (X)); \
17260 #define GIVE_UP(X) return 0
17263 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
17265 /* Don't use this for mini-windows because these can show
17266 messages and mini-buffers, and we don't handle that here. */
17267 if (MINI_WINDOW_P (w
))
17270 /* This flag is used to prevent redisplay optimizations. */
17271 if (windows_or_buffers_changed
|| cursor_type_changed
)
17274 /* Verify that narrowing has not changed.
17275 Also verify that we were not told to prevent redisplay optimizations.
17276 It would be nice to further
17277 reduce the number of cases where this prevents try_window_id. */
17278 if (current_buffer
->clip_changed
17279 || current_buffer
->prevent_redisplay_optimizations_p
)
17282 /* Window must either use window-based redisplay or be full width. */
17283 if (!FRAME_WINDOW_P (f
)
17284 && (!FRAME_LINE_INS_DEL_OK (f
)
17285 || !WINDOW_FULL_WIDTH_P (w
)))
17288 /* Give up if point is known NOT to appear in W. */
17289 if (PT
< CHARPOS (start
))
17292 /* Another way to prevent redisplay optimizations. */
17293 if (w
->last_modified
== 0)
17296 /* Verify that window is not hscrolled. */
17297 if (w
->hscroll
!= 0)
17300 /* Verify that display wasn't paused. */
17301 if (!w
->window_end_valid
)
17304 /* Can't use this if highlighting a region because a cursor movement
17305 will do more than just set the cursor. */
17306 if (markpos_of_region () >= 0)
17309 /* Likewise if highlighting trailing whitespace. */
17310 if (!NILP (Vshow_trailing_whitespace
))
17313 /* Likewise if showing a region. */
17314 if (w
->region_showing
)
17317 /* Can't use this if overlay arrow position and/or string have
17319 if (overlay_arrows_changed_p ())
17322 /* When word-wrap is on, adding a space to the first word of a
17323 wrapped line can change the wrap position, altering the line
17324 above it. It might be worthwhile to handle this more
17325 intelligently, but for now just redisplay from scratch. */
17326 if (!NILP (BVAR (XBUFFER (w
->contents
), word_wrap
)))
17329 /* Under bidi reordering, adding or deleting a character in the
17330 beginning of a paragraph, before the first strong directional
17331 character, can change the base direction of the paragraph (unless
17332 the buffer specifies a fixed paragraph direction), which will
17333 require to redisplay the whole paragraph. It might be worthwhile
17334 to find the paragraph limits and widen the range of redisplayed
17335 lines to that, but for now just give up this optimization and
17336 redisplay from scratch. */
17337 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
17338 && NILP (BVAR (XBUFFER (w
->contents
), bidi_paragraph_direction
)))
17341 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
17342 only if buffer has really changed. The reason is that the gap is
17343 initially at Z for freshly visited files. The code below would
17344 set end_unchanged to 0 in that case. */
17345 if (MODIFF
> SAVE_MODIFF
17346 /* This seems to happen sometimes after saving a buffer. */
17347 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
17349 if (GPT
- BEG
< BEG_UNCHANGED
)
17350 BEG_UNCHANGED
= GPT
- BEG
;
17351 if (Z
- GPT
< END_UNCHANGED
)
17352 END_UNCHANGED
= Z
- GPT
;
17355 /* The position of the first and last character that has been changed. */
17356 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
17357 last_changed_charpos
= Z
- END_UNCHANGED
;
17359 /* If window starts after a line end, and the last change is in
17360 front of that newline, then changes don't affect the display.
17361 This case happens with stealth-fontification. Note that although
17362 the display is unchanged, glyph positions in the matrix have to
17363 be adjusted, of course. */
17364 row
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
17365 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
17366 && ((last_changed_charpos
< CHARPOS (start
)
17367 && CHARPOS (start
) == BEGV
)
17368 || (last_changed_charpos
< CHARPOS (start
) - 1
17369 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
17371 ptrdiff_t Z_old
, Z_delta
, Z_BYTE_old
, Z_delta_bytes
;
17372 struct glyph_row
*r0
;
17374 /* Compute how many chars/bytes have been added to or removed
17375 from the buffer. */
17376 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + w
->window_end_pos
;
17377 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
17378 Z_delta
= Z
- Z_old
;
17379 Z_delta_bytes
= Z_BYTE
- Z_BYTE_old
;
17381 /* Give up if PT is not in the window. Note that it already has
17382 been checked at the start of try_window_id that PT is not in
17383 front of the window start. */
17384 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + Z_delta
)
17387 /* If window start is unchanged, we can reuse the whole matrix
17388 as is, after adjusting glyph positions. No need to compute
17389 the window end again, since its offset from Z hasn't changed. */
17390 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17391 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + Z_delta
17392 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + Z_delta_bytes
17393 /* PT must not be in a partially visible line. */
17394 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + Z_delta
17395 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17397 /* Adjust positions in the glyph matrix. */
17398 if (Z_delta
|| Z_delta_bytes
)
17400 struct glyph_row
*r1
17401 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17402 increment_matrix_positions (w
->current_matrix
,
17403 MATRIX_ROW_VPOS (r0
, current_matrix
),
17404 MATRIX_ROW_VPOS (r1
, current_matrix
),
17405 Z_delta
, Z_delta_bytes
);
17408 /* Set the cursor. */
17409 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17411 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17418 /* Handle the case that changes are all below what is displayed in
17419 the window, and that PT is in the window. This shortcut cannot
17420 be taken if ZV is visible in the window, and text has been added
17421 there that is visible in the window. */
17422 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
17423 /* ZV is not visible in the window, or there are no
17424 changes at ZV, actually. */
17425 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
17426 || first_changed_charpos
== last_changed_charpos
))
17428 struct glyph_row
*r0
;
17430 /* Give up if PT is not in the window. Note that it already has
17431 been checked at the start of try_window_id that PT is not in
17432 front of the window start. */
17433 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
17436 /* If window start is unchanged, we can reuse the whole matrix
17437 as is, without changing glyph positions since no text has
17438 been added/removed in front of the window end. */
17439 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17440 if (TEXT_POS_EQUAL_P (start
, r0
->minpos
)
17441 /* PT must not be in a partially visible line. */
17442 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
17443 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17445 /* We have to compute the window end anew since text
17446 could have been added/removed after it. */
17447 w
->window_end_pos
= Z
- MATRIX_ROW_END_CHARPOS (row
);
17448 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17450 /* Set the cursor. */
17451 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17453 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17460 /* Give up if window start is in the changed area.
17462 The condition used to read
17464 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
17466 but why that was tested escapes me at the moment. */
17467 if (CHARPOS (start
) >= first_changed_charpos
17468 && CHARPOS (start
) <= last_changed_charpos
)
17471 /* Check that window start agrees with the start of the first glyph
17472 row in its current matrix. Check this after we know the window
17473 start is not in changed text, otherwise positions would not be
17475 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17476 if (!TEXT_POS_EQUAL_P (start
, row
->minpos
))
17479 /* Give up if the window ends in strings. Overlay strings
17480 at the end are difficult to handle, so don't try. */
17481 row
= MATRIX_ROW (current_matrix
, w
->window_end_vpos
);
17482 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
17485 /* Compute the position at which we have to start displaying new
17486 lines. Some of the lines at the top of the window might be
17487 reusable because they are not displaying changed text. Find the
17488 last row in W's current matrix not affected by changes at the
17489 start of current_buffer. Value is null if changes start in the
17490 first line of window. */
17491 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
17492 if (last_unchanged_at_beg_row
)
17494 /* Avoid starting to display in the middle of a character, a TAB
17495 for instance. This is easier than to set up the iterator
17496 exactly, and it's not a frequent case, so the additional
17497 effort wouldn't really pay off. */
17498 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
17499 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
17500 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
17501 --last_unchanged_at_beg_row
;
17503 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
17506 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
17508 start_pos
= it
.current
.pos
;
17510 /* Start displaying new lines in the desired matrix at the same
17511 vpos we would use in the current matrix, i.e. below
17512 last_unchanged_at_beg_row. */
17513 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
17515 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17516 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
17518 eassert (it
.hpos
== 0 && it
.current_x
== 0);
17522 /* There are no reusable lines at the start of the window.
17523 Start displaying in the first text line. */
17524 start_display (&it
, w
, start
);
17525 it
.vpos
= it
.first_vpos
;
17526 start_pos
= it
.current
.pos
;
17529 /* Find the first row that is not affected by changes at the end of
17530 the buffer. Value will be null if there is no unchanged row, in
17531 which case we must redisplay to the end of the window. delta
17532 will be set to the value by which buffer positions beginning with
17533 first_unchanged_at_end_row have to be adjusted due to text
17535 first_unchanged_at_end_row
17536 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
17537 IF_DEBUG (debug_delta
= delta
);
17538 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
17540 /* Set stop_pos to the buffer position up to which we will have to
17541 display new lines. If first_unchanged_at_end_row != NULL, this
17542 is the buffer position of the start of the line displayed in that
17543 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
17544 that we don't stop at a buffer position. */
17546 if (first_unchanged_at_end_row
)
17548 eassert (last_unchanged_at_beg_row
== NULL
17549 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
17551 /* If this is a continuation line, move forward to the next one
17552 that isn't. Changes in lines above affect this line.
17553 Caution: this may move first_unchanged_at_end_row to a row
17554 not displaying text. */
17555 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
17556 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17557 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17558 < it
.last_visible_y
))
17559 ++first_unchanged_at_end_row
;
17561 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17562 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17563 >= it
.last_visible_y
))
17564 first_unchanged_at_end_row
= NULL
;
17567 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
17569 first_unchanged_at_end_vpos
17570 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
17571 eassert (stop_pos
>= Z
- END_UNCHANGED
);
17574 else if (last_unchanged_at_beg_row
== NULL
)
17580 /* Either there is no unchanged row at the end, or the one we have
17581 now displays text. This is a necessary condition for the window
17582 end pos calculation at the end of this function. */
17583 eassert (first_unchanged_at_end_row
== NULL
17584 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
17586 debug_last_unchanged_at_beg_vpos
17587 = (last_unchanged_at_beg_row
17588 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
17590 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
17592 #endif /* GLYPH_DEBUG */
17595 /* Display new lines. Set last_text_row to the last new line
17596 displayed which has text on it, i.e. might end up as being the
17597 line where the window_end_vpos is. */
17598 w
->cursor
.vpos
= -1;
17599 last_text_row
= NULL
;
17600 overlay_arrow_seen
= 0;
17601 while (it
.current_y
< it
.last_visible_y
17602 && !fonts_changed_p
17603 && (first_unchanged_at_end_row
== NULL
17604 || IT_CHARPOS (it
) < stop_pos
))
17606 if (display_line (&it
))
17607 last_text_row
= it
.glyph_row
- 1;
17610 if (fonts_changed_p
)
17614 /* Compute differences in buffer positions, y-positions etc. for
17615 lines reused at the bottom of the window. Compute what we can
17617 if (first_unchanged_at_end_row
17618 /* No lines reused because we displayed everything up to the
17619 bottom of the window. */
17620 && it
.current_y
< it
.last_visible_y
)
17623 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
17625 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
17626 run
.current_y
= first_unchanged_at_end_row
->y
;
17627 run
.desired_y
= run
.current_y
+ dy
;
17628 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
17632 delta
= delta_bytes
= dvpos
= dy
17633 = run
.current_y
= run
.desired_y
= run
.height
= 0;
17634 first_unchanged_at_end_row
= NULL
;
17636 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
17639 /* Find the cursor if not already found. We have to decide whether
17640 PT will appear on this window (it sometimes doesn't, but this is
17641 not a very frequent case.) This decision has to be made before
17642 the current matrix is altered. A value of cursor.vpos < 0 means
17643 that PT is either in one of the lines beginning at
17644 first_unchanged_at_end_row or below the window. Don't care for
17645 lines that might be displayed later at the window end; as
17646 mentioned, this is not a frequent case. */
17647 if (w
->cursor
.vpos
< 0)
17649 /* Cursor in unchanged rows at the top? */
17650 if (PT
< CHARPOS (start_pos
)
17651 && last_unchanged_at_beg_row
)
17653 row
= row_containing_pos (w
, PT
,
17654 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
17655 last_unchanged_at_beg_row
+ 1, 0);
17657 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
17660 /* Start from first_unchanged_at_end_row looking for PT. */
17661 else if (first_unchanged_at_end_row
)
17663 row
= row_containing_pos (w
, PT
- delta
,
17664 first_unchanged_at_end_row
, NULL
, 0);
17666 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
17667 delta_bytes
, dy
, dvpos
);
17670 /* Give up if cursor was not found. */
17671 if (w
->cursor
.vpos
< 0)
17673 clear_glyph_matrix (w
->desired_matrix
);
17678 /* Don't let the cursor end in the scroll margins. */
17680 int this_scroll_margin
, cursor_height
;
17681 int frame_line_height
= default_line_pixel_height (w
);
17682 int window_total_lines
17683 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (it
.f
) / frame_line_height
;
17685 this_scroll_margin
=
17686 max (0, min (scroll_margin
, window_total_lines
/ 4));
17687 this_scroll_margin
*= frame_line_height
;
17688 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
17690 if ((w
->cursor
.y
< this_scroll_margin
17691 && CHARPOS (start
) > BEGV
)
17692 /* Old redisplay didn't take scroll margin into account at the bottom,
17693 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
17694 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
17695 ? cursor_height
+ this_scroll_margin
17696 : 1)) > it
.last_visible_y
)
17698 w
->cursor
.vpos
= -1;
17699 clear_glyph_matrix (w
->desired_matrix
);
17704 /* Scroll the display. Do it before changing the current matrix so
17705 that xterm.c doesn't get confused about where the cursor glyph is
17707 if (dy
&& run
.height
)
17711 if (FRAME_WINDOW_P (f
))
17713 FRAME_RIF (f
)->update_window_begin_hook (w
);
17714 FRAME_RIF (f
)->clear_window_mouse_face (w
);
17715 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
17716 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
17720 /* Terminal frame. In this case, dvpos gives the number of
17721 lines to scroll by; dvpos < 0 means scroll up. */
17723 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
17724 int from
= WINDOW_TOP_EDGE_LINE (w
) + from_vpos
;
17725 int end
= (WINDOW_TOP_EDGE_LINE (w
)
17726 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
17727 + window_internal_height (w
));
17729 #if defined (HAVE_GPM) || defined (MSDOS)
17730 x_clear_window_mouse_face (w
);
17732 /* Perform the operation on the screen. */
17735 /* Scroll last_unchanged_at_beg_row to the end of the
17736 window down dvpos lines. */
17737 set_terminal_window (f
, end
);
17739 /* On dumb terminals delete dvpos lines at the end
17740 before inserting dvpos empty lines. */
17741 if (!FRAME_SCROLL_REGION_OK (f
))
17742 ins_del_lines (f
, end
- dvpos
, -dvpos
);
17744 /* Insert dvpos empty lines in front of
17745 last_unchanged_at_beg_row. */
17746 ins_del_lines (f
, from
, dvpos
);
17748 else if (dvpos
< 0)
17750 /* Scroll up last_unchanged_at_beg_vpos to the end of
17751 the window to last_unchanged_at_beg_vpos - |dvpos|. */
17752 set_terminal_window (f
, end
);
17754 /* Delete dvpos lines in front of
17755 last_unchanged_at_beg_vpos. ins_del_lines will set
17756 the cursor to the given vpos and emit |dvpos| delete
17758 ins_del_lines (f
, from
+ dvpos
, dvpos
);
17760 /* On a dumb terminal insert dvpos empty lines at the
17762 if (!FRAME_SCROLL_REGION_OK (f
))
17763 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
17766 set_terminal_window (f
, 0);
17772 /* Shift reused rows of the current matrix to the right position.
17773 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
17775 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17776 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
17779 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
17780 bottom_vpos
, dvpos
);
17781 clear_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
17784 else if (dvpos
> 0)
17786 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
17787 bottom_vpos
, dvpos
);
17788 clear_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
17789 first_unchanged_at_end_vpos
+ dvpos
);
17792 /* For frame-based redisplay, make sure that current frame and window
17793 matrix are in sync with respect to glyph memory. */
17794 if (!FRAME_WINDOW_P (f
))
17795 sync_frame_with_window_matrix_rows (w
);
17797 /* Adjust buffer positions in reused rows. */
17798 if (delta
|| delta_bytes
)
17799 increment_matrix_positions (current_matrix
,
17800 first_unchanged_at_end_vpos
+ dvpos
,
17801 bottom_vpos
, delta
, delta_bytes
);
17803 /* Adjust Y positions. */
17805 shift_glyph_matrix (w
, current_matrix
,
17806 first_unchanged_at_end_vpos
+ dvpos
,
17809 if (first_unchanged_at_end_row
)
17811 first_unchanged_at_end_row
+= dvpos
;
17812 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
17813 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
17814 first_unchanged_at_end_row
= NULL
;
17817 /* If scrolling up, there may be some lines to display at the end of
17819 last_text_row_at_end
= NULL
;
17822 /* Scrolling up can leave for example a partially visible line
17823 at the end of the window to be redisplayed. */
17824 /* Set last_row to the glyph row in the current matrix where the
17825 window end line is found. It has been moved up or down in
17826 the matrix by dvpos. */
17827 int last_vpos
= w
->window_end_vpos
+ dvpos
;
17828 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
17830 /* If last_row is the window end line, it should display text. */
17831 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_row
));
17833 /* If window end line was partially visible before, begin
17834 displaying at that line. Otherwise begin displaying with the
17835 line following it. */
17836 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
17838 init_to_row_start (&it
, w
, last_row
);
17839 it
.vpos
= last_vpos
;
17840 it
.current_y
= last_row
->y
;
17844 init_to_row_end (&it
, w
, last_row
);
17845 it
.vpos
= 1 + last_vpos
;
17846 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
17850 /* We may start in a continuation line. If so, we have to
17851 get the right continuation_lines_width and current_x. */
17852 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
17853 it
.hpos
= it
.current_x
= 0;
17855 /* Display the rest of the lines at the window end. */
17856 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17857 while (it
.current_y
< it
.last_visible_y
17858 && !fonts_changed_p
)
17860 /* Is it always sure that the display agrees with lines in
17861 the current matrix? I don't think so, so we mark rows
17862 displayed invalid in the current matrix by setting their
17863 enabled_p flag to zero. */
17864 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
17865 if (display_line (&it
))
17866 last_text_row_at_end
= it
.glyph_row
- 1;
17870 /* Update window_end_pos and window_end_vpos. */
17871 if (first_unchanged_at_end_row
&& !last_text_row_at_end
)
17873 /* Window end line if one of the preserved rows from the current
17874 matrix. Set row to the last row displaying text in current
17875 matrix starting at first_unchanged_at_end_row, after
17877 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
17878 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
17879 first_unchanged_at_end_row
);
17880 eassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
17881 adjust_window_ends (w
, row
, 1);
17882 eassert (w
->window_end_bytepos
>= 0);
17883 IF_DEBUG (debug_method_add (w
, "A"));
17885 else if (last_text_row_at_end
)
17887 adjust_window_ends (w
, last_text_row_at_end
, 0);
17888 eassert (w
->window_end_bytepos
>= 0);
17889 IF_DEBUG (debug_method_add (w
, "B"));
17891 else if (last_text_row
)
17893 /* We have displayed either to the end of the window or at the
17894 end of the window, i.e. the last row with text is to be found
17895 in the desired matrix. */
17896 adjust_window_ends (w
, last_text_row
, 0);
17897 eassert (w
->window_end_bytepos
>= 0);
17899 else if (first_unchanged_at_end_row
== NULL
17900 && last_text_row
== NULL
17901 && last_text_row_at_end
== NULL
)
17903 /* Displayed to end of window, but no line containing text was
17904 displayed. Lines were deleted at the end of the window. */
17905 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
17906 int vpos
= w
->window_end_vpos
;
17907 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
17908 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
17911 row
== NULL
&& vpos
>= first_vpos
;
17912 --vpos
, --current_row
, --desired_row
)
17914 if (desired_row
->enabled_p
)
17916 if (MATRIX_ROW_DISPLAYS_TEXT_P (desired_row
))
17919 else if (MATRIX_ROW_DISPLAYS_TEXT_P (current_row
))
17923 eassert (row
!= NULL
);
17924 w
->window_end_vpos
= vpos
+ 1;
17925 w
->window_end_pos
= Z
- MATRIX_ROW_END_CHARPOS (row
);
17926 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17927 eassert (w
->window_end_bytepos
>= 0);
17928 IF_DEBUG (debug_method_add (w
, "C"));
17933 IF_DEBUG (debug_end_pos
= w
->window_end_pos
;
17934 debug_end_vpos
= w
->window_end_vpos
);
17936 /* Record that display has not been completed. */
17937 w
->window_end_valid
= 0;
17938 w
->desired_matrix
->no_scrolling_p
= 1;
17946 /***********************************************************************
17947 More debugging support
17948 ***********************************************************************/
17952 void dump_glyph_row (struct glyph_row
*, int, int) EXTERNALLY_VISIBLE
;
17953 void dump_glyph_matrix (struct glyph_matrix
*, int) EXTERNALLY_VISIBLE
;
17954 void dump_glyph (struct glyph_row
*, struct glyph
*, int) EXTERNALLY_VISIBLE
;
17957 /* Dump the contents of glyph matrix MATRIX on stderr.
17959 GLYPHS 0 means don't show glyph contents.
17960 GLYPHS 1 means show glyphs in short form
17961 GLYPHS > 1 means show glyphs in long form. */
17964 dump_glyph_matrix (struct glyph_matrix
*matrix
, int glyphs
)
17967 for (i
= 0; i
< matrix
->nrows
; ++i
)
17968 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
17972 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
17973 the glyph row and area where the glyph comes from. */
17976 dump_glyph (struct glyph_row
*row
, struct glyph
*glyph
, int area
)
17978 if (glyph
->type
== CHAR_GLYPH
17979 || glyph
->type
== GLYPHLESS_GLYPH
)
17982 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
17983 glyph
- row
->glyphs
[TEXT_AREA
],
17984 (glyph
->type
== CHAR_GLYPH
17988 (BUFFERP (glyph
->object
)
17990 : (STRINGP (glyph
->object
)
17992 : (INTEGERP (glyph
->object
)
17995 glyph
->pixel_width
,
17997 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
18001 glyph
->left_box_line_p
,
18002 glyph
->right_box_line_p
);
18004 else if (glyph
->type
== STRETCH_GLYPH
)
18007 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
18008 glyph
- row
->glyphs
[TEXT_AREA
],
18011 (BUFFERP (glyph
->object
)
18013 : (STRINGP (glyph
->object
)
18015 : (INTEGERP (glyph
->object
)
18018 glyph
->pixel_width
,
18022 glyph
->left_box_line_p
,
18023 glyph
->right_box_line_p
);
18025 else if (glyph
->type
== IMAGE_GLYPH
)
18028 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
18029 glyph
- row
->glyphs
[TEXT_AREA
],
18032 (BUFFERP (glyph
->object
)
18034 : (STRINGP (glyph
->object
)
18036 : (INTEGERP (glyph
->object
)
18039 glyph
->pixel_width
,
18043 glyph
->left_box_line_p
,
18044 glyph
->right_box_line_p
);
18046 else if (glyph
->type
== COMPOSITE_GLYPH
)
18049 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x",
18050 glyph
- row
->glyphs
[TEXT_AREA
],
18053 (BUFFERP (glyph
->object
)
18055 : (STRINGP (glyph
->object
)
18057 : (INTEGERP (glyph
->object
)
18060 glyph
->pixel_width
,
18062 if (glyph
->u
.cmp
.automatic
)
18065 glyph
->slice
.cmp
.from
, glyph
->slice
.cmp
.to
);
18066 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
18068 glyph
->left_box_line_p
,
18069 glyph
->right_box_line_p
);
18071 #ifdef HAVE_XWIDGETS
18072 else if (glyph
->type
== XWIDGET_GLYPH
)
18075 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
18076 glyph
- row
->glyphs
[TEXT_AREA
],
18079 (BUFFERP (glyph
->object
)
18081 : (STRINGP (glyph
->object
)
18084 glyph
->pixel_width
,
18088 glyph
->left_box_line_p
,
18089 glyph
->right_box_line_p
);
18091 // printf("dump xwidget glyph\n");
18097 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
18098 GLYPHS 0 means don't show glyph contents.
18099 GLYPHS 1 means show glyphs in short form
18100 GLYPHS > 1 means show glyphs in long form. */
18103 dump_glyph_row (struct glyph_row
*row
, int vpos
, int glyphs
)
18107 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
18108 fprintf (stderr
, "==============================================================================\n");
18110 fprintf (stderr
, "%3d %9"pI
"d %9"pI
"d %4d %1.1d%1.1d%1.1d%1.1d\
18111 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
18113 MATRIX_ROW_START_CHARPOS (row
),
18114 MATRIX_ROW_END_CHARPOS (row
),
18115 row
->used
[TEXT_AREA
],
18116 row
->contains_overlapping_glyphs_p
,
18118 row
->truncated_on_left_p
,
18119 row
->truncated_on_right_p
,
18121 MATRIX_ROW_CONTINUATION_LINE_P (row
),
18122 MATRIX_ROW_DISPLAYS_TEXT_P (row
),
18125 row
->ends_in_middle_of_char_p
,
18126 row
->starts_in_middle_of_char_p
,
18132 row
->visible_height
,
18135 /* The next 3 lines should align to "Start" in the header. */
18136 fprintf (stderr
, " %9"pD
"d %9"pD
"d\t%5d\n", row
->start
.overlay_string_index
,
18137 row
->end
.overlay_string_index
,
18138 row
->continuation_lines_width
);
18139 fprintf (stderr
, " %9"pI
"d %9"pI
"d\n",
18140 CHARPOS (row
->start
.string_pos
),
18141 CHARPOS (row
->end
.string_pos
));
18142 fprintf (stderr
, " %9d %9d\n", row
->start
.dpvec_index
,
18143 row
->end
.dpvec_index
);
18150 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18152 struct glyph
*glyph
= row
->glyphs
[area
];
18153 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
18155 /* Glyph for a line end in text. */
18156 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
18159 if (glyph
< glyph_end
)
18160 fprintf (stderr
, " Glyph# Type Pos O W Code C Face LR\n");
18162 for (; glyph
< glyph_end
; ++glyph
)
18163 dump_glyph (row
, glyph
, area
);
18166 else if (glyphs
== 1)
18170 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18172 char *s
= alloca (row
->used
[area
] + 4);
18175 for (i
= 0; i
< row
->used
[area
]; ++i
)
18177 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
18178 if (i
== row
->used
[area
] - 1
18179 && area
== TEXT_AREA
18180 && INTEGERP (glyph
->object
)
18181 && glyph
->type
== CHAR_GLYPH
18182 && glyph
->u
.ch
== ' ')
18184 strcpy (&s
[i
], "[\\n]");
18187 else if (glyph
->type
== CHAR_GLYPH
18188 && glyph
->u
.ch
< 0x80
18189 && glyph
->u
.ch
>= ' ')
18190 s
[i
] = glyph
->u
.ch
;
18196 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
18202 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
18203 Sdump_glyph_matrix
, 0, 1, "p",
18204 doc
: /* Dump the current matrix of the selected window to stderr.
18205 Shows contents of glyph row structures. With non-nil
18206 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
18207 glyphs in short form, otherwise show glyphs in long form. */)
18208 (Lisp_Object glyphs
)
18210 struct window
*w
= XWINDOW (selected_window
);
18211 struct buffer
*buffer
= XBUFFER (w
->contents
);
18213 fprintf (stderr
, "PT = %"pI
"d, BEGV = %"pI
"d. ZV = %"pI
"d\n",
18214 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
18215 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
18216 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
18217 fprintf (stderr
, "=============================================\n");
18218 dump_glyph_matrix (w
->current_matrix
,
18219 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 0);
18224 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
18225 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
18228 struct frame
*f
= XFRAME (selected_frame
);
18229 dump_glyph_matrix (f
->current_matrix
, 1);
18234 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
18235 doc
: /* Dump glyph row ROW to stderr.
18236 GLYPH 0 means don't dump glyphs.
18237 GLYPH 1 means dump glyphs in short form.
18238 GLYPH > 1 or omitted means dump glyphs in long form. */)
18239 (Lisp_Object row
, Lisp_Object glyphs
)
18241 struct glyph_matrix
*matrix
;
18244 CHECK_NUMBER (row
);
18245 matrix
= XWINDOW (selected_window
)->current_matrix
;
18247 if (vpos
>= 0 && vpos
< matrix
->nrows
)
18248 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
18250 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18255 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
18256 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
18257 GLYPH 0 means don't dump glyphs.
18258 GLYPH 1 means dump glyphs in short form.
18259 GLYPH > 1 or omitted means dump glyphs in long form. */)
18260 (Lisp_Object row
, Lisp_Object glyphs
)
18262 struct frame
*sf
= SELECTED_FRAME ();
18263 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
18266 CHECK_NUMBER (row
);
18268 if (vpos
>= 0 && vpos
< m
->nrows
)
18269 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
18270 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18275 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
18276 doc
: /* Toggle tracing of redisplay.
18277 With ARG, turn tracing on if and only if ARG is positive. */)
18281 trace_redisplay_p
= !trace_redisplay_p
;
18284 arg
= Fprefix_numeric_value (arg
);
18285 trace_redisplay_p
= XINT (arg
) > 0;
18292 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
18293 doc
: /* Like `format', but print result to stderr.
18294 usage: (trace-to-stderr STRING &rest OBJECTS) */)
18295 (ptrdiff_t nargs
, Lisp_Object
*args
)
18297 Lisp_Object s
= Fformat (nargs
, args
);
18298 fprintf (stderr
, "%s", SDATA (s
));
18302 #endif /* GLYPH_DEBUG */
18306 /***********************************************************************
18307 Building Desired Matrix Rows
18308 ***********************************************************************/
18310 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
18311 Used for non-window-redisplay windows, and for windows w/o left fringe. */
18313 static struct glyph_row
*
18314 get_overlay_arrow_glyph_row (struct window
*w
, Lisp_Object overlay_arrow_string
)
18316 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18317 struct buffer
*buffer
= XBUFFER (w
->contents
);
18318 struct buffer
*old
= current_buffer
;
18319 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
18320 int arrow_len
= SCHARS (overlay_arrow_string
);
18321 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
18322 const unsigned char *p
;
18325 int n_glyphs_before
;
18327 set_buffer_temp (buffer
);
18328 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
18329 it
.glyph_row
->used
[TEXT_AREA
] = 0;
18330 SET_TEXT_POS (it
.position
, 0, 0);
18332 multibyte_p
= !NILP (BVAR (buffer
, enable_multibyte_characters
));
18334 while (p
< arrow_end
)
18336 Lisp_Object face
, ilisp
;
18338 /* Get the next character. */
18340 it
.c
= it
.char_to_display
= string_char_and_length (p
, &it
.len
);
18343 it
.c
= it
.char_to_display
= *p
, it
.len
= 1;
18344 if (! ASCII_CHAR_P (it
.c
))
18345 it
.char_to_display
= BYTE8_TO_CHAR (it
.c
);
18349 /* Get its face. */
18350 ilisp
= make_number (p
- arrow_string
);
18351 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
18352 it
.face_id
= compute_char_face (f
, it
.char_to_display
, face
);
18354 /* Compute its width, get its glyphs. */
18355 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
18356 SET_TEXT_POS (it
.position
, -1, -1);
18357 PRODUCE_GLYPHS (&it
);
18359 /* If this character doesn't fit any more in the line, we have
18360 to remove some glyphs. */
18361 if (it
.current_x
> it
.last_visible_x
)
18363 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
18368 set_buffer_temp (old
);
18369 return it
.glyph_row
;
18373 /* Insert truncation glyphs at the start of IT->glyph_row. Which
18374 glyphs to insert is determined by produce_special_glyphs. */
18377 insert_left_trunc_glyphs (struct it
*it
)
18379 struct it truncate_it
;
18380 struct glyph
*from
, *end
, *to
, *toend
;
18382 eassert (!FRAME_WINDOW_P (it
->f
)
18383 || (!it
->glyph_row
->reversed_p
18384 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0)
18385 || (it
->glyph_row
->reversed_p
18386 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0));
18388 /* Get the truncation glyphs. */
18390 truncate_it
.current_x
= 0;
18391 truncate_it
.face_id
= DEFAULT_FACE_ID
;
18392 truncate_it
.glyph_row
= &scratch_glyph_row
;
18393 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
18394 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
18395 truncate_it
.object
= make_number (0);
18396 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
18398 /* Overwrite glyphs from IT with truncation glyphs. */
18399 if (!it
->glyph_row
->reversed_p
)
18401 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
18403 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18404 end
= from
+ tused
;
18405 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18406 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
18407 if (FRAME_WINDOW_P (it
->f
))
18409 /* On GUI frames, when variable-size fonts are displayed,
18410 the truncation glyphs may need more pixels than the row's
18411 glyphs they overwrite. We overwrite more glyphs to free
18412 enough screen real estate, and enlarge the stretch glyph
18413 on the right (see display_line), if there is one, to
18414 preserve the screen position of the truncation glyphs on
18417 struct glyph
*g
= to
;
18420 /* The first glyph could be partially visible, in which case
18421 it->glyph_row->x will be negative. But we want the left
18422 truncation glyphs to be aligned at the left margin of the
18423 window, so we override the x coordinate at which the row
18425 it
->glyph_row
->x
= 0;
18426 while (g
< toend
&& w
< it
->truncation_pixel_width
)
18428 w
+= g
->pixel_width
;
18431 if (g
- to
- tused
> 0)
18433 memmove (to
+ tused
, g
, (toend
- g
) * sizeof(*g
));
18434 it
->glyph_row
->used
[TEXT_AREA
] -= g
- to
- tused
;
18436 used
= it
->glyph_row
->used
[TEXT_AREA
];
18437 if (it
->glyph_row
->truncated_on_right_p
18438 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0
18439 && it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].type
18442 int extra
= w
- it
->truncation_pixel_width
;
18444 it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].pixel_width
+= extra
;
18451 /* There may be padding glyphs left over. Overwrite them too. */
18452 if (!FRAME_WINDOW_P (it
->f
))
18454 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
18456 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18463 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
18467 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
18469 /* In R2L rows, overwrite the last (rightmost) glyphs, and do
18470 that back to front. */
18471 end
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18472 from
= end
+ truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18473 toend
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18474 to
= toend
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18475 if (FRAME_WINDOW_P (it
->f
))
18478 struct glyph
*g
= to
;
18480 while (g
>= toend
&& w
< it
->truncation_pixel_width
)
18482 w
+= g
->pixel_width
;
18485 if (to
- g
- tused
> 0)
18487 if (it
->glyph_row
->truncated_on_right_p
18488 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0
18489 && it
->glyph_row
->glyphs
[TEXT_AREA
][1].type
== STRETCH_GLYPH
)
18491 int extra
= w
- it
->truncation_pixel_width
;
18493 it
->glyph_row
->glyphs
[TEXT_AREA
][1].pixel_width
+= extra
;
18497 while (from
>= end
&& to
>= toend
)
18499 if (!FRAME_WINDOW_P (it
->f
))
18501 while (to
>= toend
&& CHAR_GLYPH_PADDING_P (*to
))
18504 truncate_it
.glyph_row
->glyphs
[TEXT_AREA
]
18505 + truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18506 while (from
>= end
&& to
>= toend
)
18512 /* Need to free some room before prepending additional
18514 int move_by
= from
- end
+ 1;
18515 struct glyph
*g0
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18516 struct glyph
*g
= g0
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18518 for ( ; g
>= g0
; g
--)
18520 while (from
>= end
)
18522 it
->glyph_row
->used
[TEXT_AREA
] += move_by
;
18527 /* Compute the hash code for ROW. */
18529 row_hash (struct glyph_row
*row
)
18532 unsigned hashval
= 0;
18534 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18535 for (k
= 0; k
< row
->used
[area
]; ++k
)
18536 hashval
= ((((hashval
<< 4) + (hashval
>> 24)) & 0x0fffffff)
18537 + row
->glyphs
[area
][k
].u
.val
18538 + row
->glyphs
[area
][k
].face_id
18539 + row
->glyphs
[area
][k
].padding_p
18540 + (row
->glyphs
[area
][k
].type
<< 2));
18545 /* Compute the pixel height and width of IT->glyph_row.
18547 Most of the time, ascent and height of a display line will be equal
18548 to the max_ascent and max_height values of the display iterator
18549 structure. This is not the case if
18551 1. We hit ZV without displaying anything. In this case, max_ascent
18552 and max_height will be zero.
18554 2. We have some glyphs that don't contribute to the line height.
18555 (The glyph row flag contributes_to_line_height_p is for future
18556 pixmap extensions).
18558 The first case is easily covered by using default values because in
18559 these cases, the line height does not really matter, except that it
18560 must not be zero. */
18563 compute_line_metrics (struct it
*it
)
18565 struct glyph_row
*row
= it
->glyph_row
;
18567 if (FRAME_WINDOW_P (it
->f
))
18569 int i
, min_y
, max_y
;
18571 /* The line may consist of one space only, that was added to
18572 place the cursor on it. If so, the row's height hasn't been
18574 if (row
->height
== 0)
18576 if (it
->max_ascent
+ it
->max_descent
== 0)
18577 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
18578 row
->ascent
= it
->max_ascent
;
18579 row
->height
= it
->max_ascent
+ it
->max_descent
;
18580 row
->phys_ascent
= it
->max_phys_ascent
;
18581 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18582 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18585 /* Compute the width of this line. */
18586 row
->pixel_width
= row
->x
;
18587 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
18588 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
18590 eassert (row
->pixel_width
>= 0);
18591 eassert (row
->ascent
>= 0 && row
->height
> 0);
18593 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
18594 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
18596 /* If first line's physical ascent is larger than its logical
18597 ascent, use the physical ascent, and make the row taller.
18598 This makes accented characters fully visible. */
18599 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
18600 && row
->phys_ascent
> row
->ascent
)
18602 row
->height
+= row
->phys_ascent
- row
->ascent
;
18603 row
->ascent
= row
->phys_ascent
;
18606 /* Compute how much of the line is visible. */
18607 row
->visible_height
= row
->height
;
18609 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
18610 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
18612 if (row
->y
< min_y
)
18613 row
->visible_height
-= min_y
- row
->y
;
18614 if (row
->y
+ row
->height
> max_y
)
18615 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
18619 row
->pixel_width
= row
->used
[TEXT_AREA
];
18620 if (row
->continued_p
)
18621 row
->pixel_width
-= it
->continuation_pixel_width
;
18622 else if (row
->truncated_on_right_p
)
18623 row
->pixel_width
-= it
->truncation_pixel_width
;
18624 row
->ascent
= row
->phys_ascent
= 0;
18625 row
->height
= row
->phys_height
= row
->visible_height
= 1;
18626 row
->extra_line_spacing
= 0;
18629 /* Compute a hash code for this row. */
18630 row
->hash
= row_hash (row
);
18632 it
->max_ascent
= it
->max_descent
= 0;
18633 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
18637 /* Append one space to the glyph row of iterator IT if doing a
18638 window-based redisplay. The space has the same face as
18639 IT->face_id. Value is non-zero if a space was added.
18641 This function is called to make sure that there is always one glyph
18642 at the end of a glyph row that the cursor can be set on under
18643 window-systems. (If there weren't such a glyph we would not know
18644 how wide and tall a box cursor should be displayed).
18646 At the same time this space let's a nicely handle clearing to the
18647 end of the line if the row ends in italic text. */
18650 append_space_for_newline (struct it
*it
, int default_face_p
)
18652 if (FRAME_WINDOW_P (it
->f
))
18654 int n
= it
->glyph_row
->used
[TEXT_AREA
];
18656 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
18657 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
18659 /* Save some values that must not be changed.
18660 Must save IT->c and IT->len because otherwise
18661 ITERATOR_AT_END_P wouldn't work anymore after
18662 append_space_for_newline has been called. */
18663 enum display_element_type saved_what
= it
->what
;
18664 int saved_c
= it
->c
, saved_len
= it
->len
;
18665 int saved_char_to_display
= it
->char_to_display
;
18666 int saved_x
= it
->current_x
;
18667 int saved_face_id
= it
->face_id
;
18668 int saved_box_end
= it
->end_of_box_run_p
;
18669 struct text_pos saved_pos
;
18670 Lisp_Object saved_object
;
18673 saved_object
= it
->object
;
18674 saved_pos
= it
->position
;
18676 it
->what
= IT_CHARACTER
;
18677 memset (&it
->position
, 0, sizeof it
->position
);
18678 it
->object
= make_number (0);
18679 it
->c
= it
->char_to_display
= ' ';
18682 /* If the default face was remapped, be sure to use the
18683 remapped face for the appended newline. */
18684 if (default_face_p
)
18685 it
->face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
18686 else if (it
->face_before_selective_p
)
18687 it
->face_id
= it
->saved_face_id
;
18688 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18689 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
18690 /* In R2L rows, we will prepend a stretch glyph that will
18691 have the end_of_box_run_p flag set for it, so there's no
18692 need for the appended newline glyph to have that flag
18694 if (it
->glyph_row
->reversed_p
18695 /* But if the appended newline glyph goes all the way to
18696 the end of the row, there will be no stretch glyph,
18697 so leave the box flag set. */
18698 && saved_x
+ FRAME_COLUMN_WIDTH (it
->f
) < it
->last_visible_x
)
18699 it
->end_of_box_run_p
= 0;
18701 PRODUCE_GLYPHS (it
);
18703 it
->override_ascent
= -1;
18704 it
->constrain_row_ascent_descent_p
= 0;
18705 it
->current_x
= saved_x
;
18706 it
->object
= saved_object
;
18707 it
->position
= saved_pos
;
18708 it
->what
= saved_what
;
18709 it
->face_id
= saved_face_id
;
18710 it
->len
= saved_len
;
18712 it
->char_to_display
= saved_char_to_display
;
18713 it
->end_of_box_run_p
= saved_box_end
;
18722 /* Extend the face of the last glyph in the text area of IT->glyph_row
18723 to the end of the display line. Called from display_line. If the
18724 glyph row is empty, add a space glyph to it so that we know the
18725 face to draw. Set the glyph row flag fill_line_p. If the glyph
18726 row is R2L, prepend a stretch glyph to cover the empty space to the
18727 left of the leftmost glyph. */
18730 extend_face_to_end_of_line (struct it
*it
)
18732 struct face
*face
, *default_face
;
18733 struct frame
*f
= it
->f
;
18735 /* If line is already filled, do nothing. Non window-system frames
18736 get a grace of one more ``pixel'' because their characters are
18737 1-``pixel'' wide, so they hit the equality too early. This grace
18738 is needed only for R2L rows that are not continued, to produce
18739 one extra blank where we could display the cursor. */
18740 if (it
->current_x
>= it
->last_visible_x
18741 + (!FRAME_WINDOW_P (f
)
18742 && it
->glyph_row
->reversed_p
18743 && !it
->glyph_row
->continued_p
))
18746 /* The default face, possibly remapped. */
18747 default_face
= FACE_FROM_ID (f
, lookup_basic_face (f
, DEFAULT_FACE_ID
));
18749 /* Face extension extends the background and box of IT->face_id
18750 to the end of the line. If the background equals the background
18751 of the frame, we don't have to do anything. */
18752 if (it
->face_before_selective_p
)
18753 face
= FACE_FROM_ID (f
, it
->saved_face_id
);
18755 face
= FACE_FROM_ID (f
, it
->face_id
);
18757 if (FRAME_WINDOW_P (f
)
18758 && MATRIX_ROW_DISPLAYS_TEXT_P (it
->glyph_row
)
18759 && face
->box
== FACE_NO_BOX
18760 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
18762 && !it
->glyph_row
->reversed_p
)
18765 /* Set the glyph row flag indicating that the face of the last glyph
18766 in the text area has to be drawn to the end of the text area. */
18767 it
->glyph_row
->fill_line_p
= 1;
18769 /* If current character of IT is not ASCII, make sure we have the
18770 ASCII face. This will be automatically undone the next time
18771 get_next_display_element returns a multibyte character. Note
18772 that the character will always be single byte in unibyte
18774 if (!ASCII_CHAR_P (it
->c
))
18776 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
18779 if (FRAME_WINDOW_P (f
))
18781 /* If the row is empty, add a space with the current face of IT,
18782 so that we know which face to draw. */
18783 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
18785 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
18786 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= face
->id
;
18787 it
->glyph_row
->used
[TEXT_AREA
] = 1;
18789 #ifdef HAVE_WINDOW_SYSTEM
18790 if (it
->glyph_row
->reversed_p
)
18792 /* Prepend a stretch glyph to the row, such that the
18793 rightmost glyph will be drawn flushed all the way to the
18794 right margin of the window. The stretch glyph that will
18795 occupy the empty space, if any, to the left of the
18797 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (f
);
18798 struct glyph
*row_start
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18799 struct glyph
*row_end
= row_start
+ it
->glyph_row
->used
[TEXT_AREA
];
18801 int row_width
, stretch_ascent
, stretch_width
;
18802 struct text_pos saved_pos
;
18803 int saved_face_id
, saved_avoid_cursor
, saved_box_start
;
18805 for (row_width
= 0, g
= row_start
; g
< row_end
; g
++)
18806 row_width
+= g
->pixel_width
;
18807 stretch_width
= window_box_width (it
->w
, TEXT_AREA
) - row_width
;
18808 if (stretch_width
> 0)
18811 (((it
->ascent
+ it
->descent
)
18812 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
18813 saved_pos
= it
->position
;
18814 memset (&it
->position
, 0, sizeof it
->position
);
18815 saved_avoid_cursor
= it
->avoid_cursor_p
;
18816 it
->avoid_cursor_p
= 1;
18817 saved_face_id
= it
->face_id
;
18818 saved_box_start
= it
->start_of_box_run_p
;
18819 /* The last row's stretch glyph should get the default
18820 face, to avoid painting the rest of the window with
18821 the region face, if the region ends at ZV. */
18822 if (it
->glyph_row
->ends_at_zv_p
)
18823 it
->face_id
= default_face
->id
;
18825 it
->face_id
= face
->id
;
18826 it
->start_of_box_run_p
= 0;
18827 append_stretch_glyph (it
, make_number (0), stretch_width
,
18828 it
->ascent
+ it
->descent
, stretch_ascent
);
18829 it
->position
= saved_pos
;
18830 it
->avoid_cursor_p
= saved_avoid_cursor
;
18831 it
->face_id
= saved_face_id
;
18832 it
->start_of_box_run_p
= saved_box_start
;
18835 #endif /* HAVE_WINDOW_SYSTEM */
18839 /* Save some values that must not be changed. */
18840 int saved_x
= it
->current_x
;
18841 struct text_pos saved_pos
;
18842 Lisp_Object saved_object
;
18843 enum display_element_type saved_what
= it
->what
;
18844 int saved_face_id
= it
->face_id
;
18846 saved_object
= it
->object
;
18847 saved_pos
= it
->position
;
18849 it
->what
= IT_CHARACTER
;
18850 memset (&it
->position
, 0, sizeof it
->position
);
18851 it
->object
= make_number (0);
18852 it
->c
= it
->char_to_display
= ' ';
18854 /* The last row's blank glyphs should get the default face, to
18855 avoid painting the rest of the window with the region face,
18856 if the region ends at ZV. */
18857 if (it
->glyph_row
->ends_at_zv_p
)
18858 it
->face_id
= default_face
->id
;
18860 it
->face_id
= face
->id
;
18862 PRODUCE_GLYPHS (it
);
18864 while (it
->current_x
<= it
->last_visible_x
)
18865 PRODUCE_GLYPHS (it
);
18867 /* Don't count these blanks really. It would let us insert a left
18868 truncation glyph below and make us set the cursor on them, maybe. */
18869 it
->current_x
= saved_x
;
18870 it
->object
= saved_object
;
18871 it
->position
= saved_pos
;
18872 it
->what
= saved_what
;
18873 it
->face_id
= saved_face_id
;
18878 /* Value is non-zero if text starting at CHARPOS in current_buffer is
18879 trailing whitespace. */
18882 trailing_whitespace_p (ptrdiff_t charpos
)
18884 ptrdiff_t bytepos
= CHAR_TO_BYTE (charpos
);
18887 while (bytepos
< ZV_BYTE
18888 && (c
= FETCH_CHAR (bytepos
),
18889 c
== ' ' || c
== '\t'))
18892 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
18894 if (bytepos
!= PT_BYTE
)
18901 /* Highlight trailing whitespace, if any, in ROW. */
18904 highlight_trailing_whitespace (struct frame
*f
, struct glyph_row
*row
)
18906 int used
= row
->used
[TEXT_AREA
];
18910 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
18911 struct glyph
*glyph
= start
+ used
- 1;
18913 if (row
->reversed_p
)
18915 /* Right-to-left rows need to be processed in the opposite
18916 direction, so swap the edge pointers. */
18918 start
= row
->glyphs
[TEXT_AREA
] + used
- 1;
18921 /* Skip over glyphs inserted to display the cursor at the
18922 end of a line, for extending the face of the last glyph
18923 to the end of the line on terminals, and for truncation
18924 and continuation glyphs. */
18925 if (!row
->reversed_p
)
18927 while (glyph
>= start
18928 && glyph
->type
== CHAR_GLYPH
18929 && INTEGERP (glyph
->object
))
18934 while (glyph
<= start
18935 && glyph
->type
== CHAR_GLYPH
18936 && INTEGERP (glyph
->object
))
18940 /* If last glyph is a space or stretch, and it's trailing
18941 whitespace, set the face of all trailing whitespace glyphs in
18942 IT->glyph_row to `trailing-whitespace'. */
18943 if ((row
->reversed_p
? glyph
<= start
: glyph
>= start
)
18944 && BUFFERP (glyph
->object
)
18945 && (glyph
->type
== STRETCH_GLYPH
18946 || (glyph
->type
== CHAR_GLYPH
18947 && glyph
->u
.ch
== ' '))
18948 && trailing_whitespace_p (glyph
->charpos
))
18950 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
18954 if (!row
->reversed_p
)
18956 while (glyph
>= start
18957 && BUFFERP (glyph
->object
)
18958 && (glyph
->type
== STRETCH_GLYPH
18959 || (glyph
->type
== CHAR_GLYPH
18960 && glyph
->u
.ch
== ' ')))
18961 (glyph
--)->face_id
= face_id
;
18965 while (glyph
<= start
18966 && BUFFERP (glyph
->object
)
18967 && (glyph
->type
== STRETCH_GLYPH
18968 || (glyph
->type
== CHAR_GLYPH
18969 && glyph
->u
.ch
== ' ')))
18970 (glyph
++)->face_id
= face_id
;
18977 /* Value is non-zero if glyph row ROW should be
18978 considered to hold the buffer position CHARPOS. */
18981 row_for_charpos_p (struct glyph_row
*row
, ptrdiff_t charpos
)
18985 if (charpos
== CHARPOS (row
->end
.pos
)
18986 || charpos
== MATRIX_ROW_END_CHARPOS (row
))
18988 /* Suppose the row ends on a string.
18989 Unless the row is continued, that means it ends on a newline
18990 in the string. If it's anything other than a display string
18991 (e.g., a before-string from an overlay), we don't want the
18992 cursor there. (This heuristic seems to give the optimal
18993 behavior for the various types of multi-line strings.)
18994 One exception: if the string has `cursor' property on one of
18995 its characters, we _do_ want the cursor there. */
18996 if (CHARPOS (row
->end
.string_pos
) >= 0)
18998 if (row
->continued_p
)
19002 /* Check for `display' property. */
19003 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
19004 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
19005 struct glyph
*glyph
;
19008 for (glyph
= end
; glyph
>= beg
; --glyph
)
19009 if (STRINGP (glyph
->object
))
19012 = Fget_char_property (make_number (charpos
),
19016 && display_prop_string_p (prop
, glyph
->object
));
19017 /* If there's a `cursor' property on one of the
19018 string's characters, this row is a cursor row,
19019 even though this is not a display string. */
19022 Lisp_Object s
= glyph
->object
;
19024 for ( ; glyph
>= beg
&& EQ (glyph
->object
, s
); --glyph
)
19026 ptrdiff_t gpos
= glyph
->charpos
;
19028 if (!NILP (Fget_char_property (make_number (gpos
),
19040 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
19042 /* If the row ends in middle of a real character,
19043 and the line is continued, we want the cursor here.
19044 That's because CHARPOS (ROW->end.pos) would equal
19045 PT if PT is before the character. */
19046 if (!row
->ends_in_ellipsis_p
)
19047 result
= row
->continued_p
;
19049 /* If the row ends in an ellipsis, then
19050 CHARPOS (ROW->end.pos) will equal point after the
19051 invisible text. We want that position to be displayed
19052 after the ellipsis. */
19055 /* If the row ends at ZV, display the cursor at the end of that
19056 row instead of at the start of the row below. */
19057 else if (row
->ends_at_zv_p
)
19066 /* Value is non-zero if glyph row ROW should be
19067 used to hold the cursor. */
19070 cursor_row_p (struct glyph_row
*row
)
19072 return row_for_charpos_p (row
, PT
);
19077 /* Push the property PROP so that it will be rendered at the current
19078 position in IT. Return 1 if PROP was successfully pushed, 0
19079 otherwise. Called from handle_line_prefix to handle the
19080 `line-prefix' and `wrap-prefix' properties. */
19083 push_prefix_prop (struct it
*it
, Lisp_Object prop
)
19085 struct text_pos pos
=
19086 STRINGP (it
->string
) ? it
->current
.string_pos
: it
->current
.pos
;
19088 eassert (it
->method
== GET_FROM_BUFFER
19089 || it
->method
== GET_FROM_DISPLAY_VECTOR
19090 || it
->method
== GET_FROM_STRING
);
19092 /* We need to save the current buffer/string position, so it will be
19093 restored by pop_it, because iterate_out_of_display_property
19094 depends on that being set correctly, but some situations leave
19095 it->position not yet set when this function is called. */
19096 push_it (it
, &pos
);
19098 if (STRINGP (prop
))
19100 if (SCHARS (prop
) == 0)
19107 it
->string_from_prefix_prop_p
= 1;
19108 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
19109 it
->current
.overlay_string_index
= -1;
19110 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
19111 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
19112 it
->method
= GET_FROM_STRING
;
19113 it
->stop_charpos
= 0;
19115 it
->base_level_stop
= 0;
19117 /* Force paragraph direction to be that of the parent
19119 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
19120 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
19122 it
->paragraph_embedding
= L2R
;
19124 /* Set up the bidi iterator for this display string. */
19127 it
->bidi_it
.string
.lstring
= it
->string
;
19128 it
->bidi_it
.string
.s
= NULL
;
19129 it
->bidi_it
.string
.schars
= it
->end_charpos
;
19130 it
->bidi_it
.string
.bufpos
= IT_CHARPOS (*it
);
19131 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
19132 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
19133 it
->bidi_it
.w
= it
->w
;
19134 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
19137 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
19139 it
->method
= GET_FROM_STRETCH
;
19142 #ifdef HAVE_WINDOW_SYSTEM
19143 else if (IMAGEP (prop
))
19145 it
->what
= IT_IMAGE
;
19146 it
->image_id
= lookup_image (it
->f
, prop
);
19147 it
->method
= GET_FROM_IMAGE
;
19149 #endif /* HAVE_WINDOW_SYSTEM */
19152 pop_it (it
); /* bogus display property, give up */
19159 /* Return the character-property PROP at the current position in IT. */
19162 get_it_property (struct it
*it
, Lisp_Object prop
)
19164 Lisp_Object position
, object
= it
->object
;
19166 if (STRINGP (object
))
19167 position
= make_number (IT_STRING_CHARPOS (*it
));
19168 else if (BUFFERP (object
))
19170 position
= make_number (IT_CHARPOS (*it
));
19171 object
= it
->window
;
19176 return Fget_char_property (position
, prop
, object
);
19179 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
19182 handle_line_prefix (struct it
*it
)
19184 Lisp_Object prefix
;
19186 if (it
->continuation_lines_width
> 0)
19188 prefix
= get_it_property (it
, Qwrap_prefix
);
19190 prefix
= Vwrap_prefix
;
19194 prefix
= get_it_property (it
, Qline_prefix
);
19196 prefix
= Vline_prefix
;
19198 if (! NILP (prefix
) && push_prefix_prop (it
, prefix
))
19200 /* If the prefix is wider than the window, and we try to wrap
19201 it, it would acquire its own wrap prefix, and so on till the
19202 iterator stack overflows. So, don't wrap the prefix. */
19203 it
->line_wrap
= TRUNCATE
;
19204 it
->avoid_cursor_p
= 1;
19210 /* Remove N glyphs at the start of a reversed IT->glyph_row. Called
19211 only for R2L lines from display_line and display_string, when they
19212 decide that too many glyphs were produced by PRODUCE_GLYPHS, and
19213 the line/string needs to be continued on the next glyph row. */
19215 unproduce_glyphs (struct it
*it
, int n
)
19217 struct glyph
*glyph
, *end
;
19219 eassert (it
->glyph_row
);
19220 eassert (it
->glyph_row
->reversed_p
);
19221 eassert (it
->area
== TEXT_AREA
);
19222 eassert (n
<= it
->glyph_row
->used
[TEXT_AREA
]);
19224 if (n
> it
->glyph_row
->used
[TEXT_AREA
])
19225 n
= it
->glyph_row
->used
[TEXT_AREA
];
19226 glyph
= it
->glyph_row
->glyphs
[TEXT_AREA
] + n
;
19227 end
= it
->glyph_row
->glyphs
[TEXT_AREA
] + it
->glyph_row
->used
[TEXT_AREA
];
19228 for ( ; glyph
< end
; glyph
++)
19229 glyph
[-n
] = *glyph
;
19232 /* Find the positions in a bidi-reordered ROW to serve as ROW->minpos
19233 and ROW->maxpos. */
19235 find_row_edges (struct it
*it
, struct glyph_row
*row
,
19236 ptrdiff_t min_pos
, ptrdiff_t min_bpos
,
19237 ptrdiff_t max_pos
, ptrdiff_t max_bpos
)
19239 /* FIXME: Revisit this when glyph ``spilling'' in continuation
19240 lines' rows is implemented for bidi-reordered rows. */
19242 /* ROW->minpos is the value of min_pos, the minimal buffer position
19243 we have in ROW, or ROW->start.pos if that is smaller. */
19244 if (min_pos
<= ZV
&& min_pos
< row
->start
.pos
.charpos
)
19245 SET_TEXT_POS (row
->minpos
, min_pos
, min_bpos
);
19247 /* We didn't find buffer positions smaller than ROW->start, or
19248 didn't find _any_ valid buffer positions in any of the glyphs,
19249 so we must trust the iterator's computed positions. */
19250 row
->minpos
= row
->start
.pos
;
19253 max_pos
= CHARPOS (it
->current
.pos
);
19254 max_bpos
= BYTEPOS (it
->current
.pos
);
19257 /* Here are the various use-cases for ending the row, and the
19258 corresponding values for ROW->maxpos:
19260 Line ends in a newline from buffer eol_pos + 1
19261 Line is continued from buffer max_pos + 1
19262 Line is truncated on right it->current.pos
19263 Line ends in a newline from string max_pos + 1(*)
19264 (*) + 1 only when line ends in a forward scan
19265 Line is continued from string max_pos
19266 Line is continued from display vector max_pos
19267 Line is entirely from a string min_pos == max_pos
19268 Line is entirely from a display vector min_pos == max_pos
19269 Line that ends at ZV ZV
19271 If you discover other use-cases, please add them here as
19273 if (row
->ends_at_zv_p
)
19274 row
->maxpos
= it
->current
.pos
;
19275 else if (row
->used
[TEXT_AREA
])
19277 int seen_this_string
= 0;
19278 struct glyph_row
*r1
= row
- 1;
19280 /* Did we see the same display string on the previous row? */
19281 if (STRINGP (it
->object
)
19282 /* this is not the first row */
19283 && row
> it
->w
->desired_matrix
->rows
19284 /* previous row is not the header line */
19285 && !r1
->mode_line_p
19286 /* previous row also ends in a newline from a string */
19287 && r1
->ends_in_newline_from_string_p
)
19289 struct glyph
*start
, *end
;
19291 /* Search for the last glyph of the previous row that came
19292 from buffer or string. Depending on whether the row is
19293 L2R or R2L, we need to process it front to back or the
19294 other way round. */
19295 if (!r1
->reversed_p
)
19297 start
= r1
->glyphs
[TEXT_AREA
];
19298 end
= start
+ r1
->used
[TEXT_AREA
];
19299 /* Glyphs inserted by redisplay have an integer (zero)
19300 as their object. */
19302 && INTEGERP ((end
- 1)->object
)
19303 && (end
- 1)->charpos
<= 0)
19307 if (EQ ((end
- 1)->object
, it
->object
))
19308 seen_this_string
= 1;
19311 /* If all the glyphs of the previous row were inserted
19312 by redisplay, it means the previous row was
19313 produced from a single newline, which is only
19314 possible if that newline came from the same string
19315 as the one which produced this ROW. */
19316 seen_this_string
= 1;
19320 end
= r1
->glyphs
[TEXT_AREA
] - 1;
19321 start
= end
+ r1
->used
[TEXT_AREA
];
19323 && INTEGERP ((end
+ 1)->object
)
19324 && (end
+ 1)->charpos
<= 0)
19328 if (EQ ((end
+ 1)->object
, it
->object
))
19329 seen_this_string
= 1;
19332 seen_this_string
= 1;
19335 /* Take note of each display string that covers a newline only
19336 once, the first time we see it. This is for when a display
19337 string includes more than one newline in it. */
19338 if (row
->ends_in_newline_from_string_p
&& !seen_this_string
)
19340 /* If we were scanning the buffer forward when we displayed
19341 the string, we want to account for at least one buffer
19342 position that belongs to this row (position covered by
19343 the display string), so that cursor positioning will
19344 consider this row as a candidate when point is at the end
19345 of the visual line represented by this row. This is not
19346 required when scanning back, because max_pos will already
19347 have a much larger value. */
19348 if (CHARPOS (row
->end
.pos
) > max_pos
)
19349 INC_BOTH (max_pos
, max_bpos
);
19350 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19352 else if (CHARPOS (it
->eol_pos
) > 0)
19353 SET_TEXT_POS (row
->maxpos
,
19354 CHARPOS (it
->eol_pos
) + 1, BYTEPOS (it
->eol_pos
) + 1);
19355 else if (row
->continued_p
)
19357 /* If max_pos is different from IT's current position, it
19358 means IT->method does not belong to the display element
19359 at max_pos. However, it also means that the display
19360 element at max_pos was displayed in its entirety on this
19361 line, which is equivalent to saying that the next line
19362 starts at the next buffer position. */
19363 if (IT_CHARPOS (*it
) == max_pos
&& it
->method
!= GET_FROM_BUFFER
)
19364 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19367 INC_BOTH (max_pos
, max_bpos
);
19368 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19371 else if (row
->truncated_on_right_p
)
19372 /* display_line already called reseat_at_next_visible_line_start,
19373 which puts the iterator at the beginning of the next line, in
19374 the logical order. */
19375 row
->maxpos
= it
->current
.pos
;
19376 else if (max_pos
== min_pos
&& it
->method
!= GET_FROM_BUFFER
)
19377 /* A line that is entirely from a string/image/stretch... */
19378 row
->maxpos
= row
->minpos
;
19383 row
->maxpos
= it
->current
.pos
;
19386 /* Construct the glyph row IT->glyph_row in the desired matrix of
19387 IT->w from text at the current position of IT. See dispextern.h
19388 for an overview of struct it. Value is non-zero if
19389 IT->glyph_row displays text, as opposed to a line displaying ZV
19393 display_line (struct it
*it
)
19395 struct glyph_row
*row
= it
->glyph_row
;
19396 Lisp_Object overlay_arrow_string
;
19398 void *wrap_data
= NULL
;
19399 int may_wrap
= 0, wrap_x
IF_LINT (= 0);
19400 int wrap_row_used
= -1;
19401 int wrap_row_ascent
IF_LINT (= 0), wrap_row_height
IF_LINT (= 0);
19402 int wrap_row_phys_ascent
IF_LINT (= 0), wrap_row_phys_height
IF_LINT (= 0);
19403 int wrap_row_extra_line_spacing
IF_LINT (= 0);
19404 ptrdiff_t wrap_row_min_pos
IF_LINT (= 0), wrap_row_min_bpos
IF_LINT (= 0);
19405 ptrdiff_t wrap_row_max_pos
IF_LINT (= 0), wrap_row_max_bpos
IF_LINT (= 0);
19407 ptrdiff_t min_pos
= ZV
+ 1, max_pos
= 0;
19408 ptrdiff_t min_bpos
IF_LINT (= 0), max_bpos
IF_LINT (= 0);
19410 /* We always start displaying at hpos zero even if hscrolled. */
19411 eassert (it
->hpos
== 0 && it
->current_x
== 0);
19413 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
19414 >= it
->w
->desired_matrix
->nrows
)
19416 it
->w
->nrows_scale_factor
++;
19417 fonts_changed_p
= 1;
19421 /* Is IT->w showing the region? */
19422 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? it
->region_beg_charpos
: 0;
19424 /* Clear the result glyph row and enable it. */
19425 prepare_desired_row (row
);
19427 row
->y
= it
->current_y
;
19428 row
->start
= it
->start
;
19429 row
->continuation_lines_width
= it
->continuation_lines_width
;
19430 row
->displays_text_p
= 1;
19431 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
19432 it
->starts_in_middle_of_char_p
= 0;
19434 /* Arrange the overlays nicely for our purposes. Usually, we call
19435 display_line on only one line at a time, in which case this
19436 can't really hurt too much, or we call it on lines which appear
19437 one after another in the buffer, in which case all calls to
19438 recenter_overlay_lists but the first will be pretty cheap. */
19439 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
19441 /* Move over display elements that are not visible because we are
19442 hscrolled. This may stop at an x-position < IT->first_visible_x
19443 if the first glyph is partially visible or if we hit a line end. */
19444 if (it
->current_x
< it
->first_visible_x
)
19446 enum move_it_result move_result
;
19448 this_line_min_pos
= row
->start
.pos
;
19449 move_result
= move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
19450 MOVE_TO_POS
| MOVE_TO_X
);
19451 /* If we are under a large hscroll, move_it_in_display_line_to
19452 could hit the end of the line without reaching
19453 it->first_visible_x. Pretend that we did reach it. This is
19454 especially important on a TTY, where we will call
19455 extend_face_to_end_of_line, which needs to know how many
19456 blank glyphs to produce. */
19457 if (it
->current_x
< it
->first_visible_x
19458 && (move_result
== MOVE_NEWLINE_OR_CR
19459 || move_result
== MOVE_POS_MATCH_OR_ZV
))
19460 it
->current_x
= it
->first_visible_x
;
19462 /* Record the smallest positions seen while we moved over
19463 display elements that are not visible. This is needed by
19464 redisplay_internal for optimizing the case where the cursor
19465 stays inside the same line. The rest of this function only
19466 considers positions that are actually displayed, so
19467 RECORD_MAX_MIN_POS will not otherwise record positions that
19468 are hscrolled to the left of the left edge of the window. */
19469 min_pos
= CHARPOS (this_line_min_pos
);
19470 min_bpos
= BYTEPOS (this_line_min_pos
);
19474 /* We only do this when not calling `move_it_in_display_line_to'
19475 above, because move_it_in_display_line_to calls
19476 handle_line_prefix itself. */
19477 handle_line_prefix (it
);
19480 /* Get the initial row height. This is either the height of the
19481 text hscrolled, if there is any, or zero. */
19482 row
->ascent
= it
->max_ascent
;
19483 row
->height
= it
->max_ascent
+ it
->max_descent
;
19484 row
->phys_ascent
= it
->max_phys_ascent
;
19485 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
19486 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
19488 /* Utility macro to record max and min buffer positions seen until now. */
19489 #define RECORD_MAX_MIN_POS(IT) \
19492 int composition_p = !STRINGP ((IT)->string) \
19493 && ((IT)->what == IT_COMPOSITION); \
19494 ptrdiff_t current_pos = \
19495 composition_p ? (IT)->cmp_it.charpos \
19496 : IT_CHARPOS (*(IT)); \
19497 ptrdiff_t current_bpos = \
19498 composition_p ? CHAR_TO_BYTE (current_pos) \
19499 : IT_BYTEPOS (*(IT)); \
19500 if (current_pos < min_pos) \
19502 min_pos = current_pos; \
19503 min_bpos = current_bpos; \
19505 if (IT_CHARPOS (*it) > max_pos) \
19507 max_pos = IT_CHARPOS (*it); \
19508 max_bpos = IT_BYTEPOS (*it); \
19513 /* Loop generating characters. The loop is left with IT on the next
19514 character to display. */
19517 int n_glyphs_before
, hpos_before
, x_before
;
19519 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
19521 /* Retrieve the next thing to display. Value is zero if end of
19523 if (!get_next_display_element (it
))
19525 /* Maybe add a space at the end of this line that is used to
19526 display the cursor there under X. Set the charpos of the
19527 first glyph of blank lines not corresponding to any text
19529 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19530 row
->exact_window_width_line_p
= 1;
19531 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
19532 || row
->used
[TEXT_AREA
] == 0)
19534 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
19535 row
->displays_text_p
= 0;
19537 if (!NILP (BVAR (XBUFFER (it
->w
->contents
), indicate_empty_lines
))
19538 && (!MINI_WINDOW_P (it
->w
)
19539 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
19540 row
->indicate_empty_line_p
= 1;
19543 it
->continuation_lines_width
= 0;
19544 row
->ends_at_zv_p
= 1;
19545 /* A row that displays right-to-left text must always have
19546 its last face extended all the way to the end of line,
19547 even if this row ends in ZV, because we still write to
19548 the screen left to right. We also need to extend the
19549 last face if the default face is remapped to some
19550 different face, otherwise the functions that clear
19551 portions of the screen will clear with the default face's
19552 background color. */
19553 if (row
->reversed_p
19554 || lookup_basic_face (it
->f
, DEFAULT_FACE_ID
) != DEFAULT_FACE_ID
)
19555 extend_face_to_end_of_line (it
);
19559 /* Now, get the metrics of what we want to display. This also
19560 generates glyphs in `row' (which is IT->glyph_row). */
19561 n_glyphs_before
= row
->used
[TEXT_AREA
];
19564 /* Remember the line height so far in case the next element doesn't
19565 fit on the line. */
19566 if (it
->line_wrap
!= TRUNCATE
)
19568 ascent
= it
->max_ascent
;
19569 descent
= it
->max_descent
;
19570 phys_ascent
= it
->max_phys_ascent
;
19571 phys_descent
= it
->max_phys_descent
;
19573 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
19575 if (IT_DISPLAYING_WHITESPACE (it
))
19579 SAVE_IT (wrap_it
, *it
, wrap_data
);
19581 wrap_row_used
= row
->used
[TEXT_AREA
];
19582 wrap_row_ascent
= row
->ascent
;
19583 wrap_row_height
= row
->height
;
19584 wrap_row_phys_ascent
= row
->phys_ascent
;
19585 wrap_row_phys_height
= row
->phys_height
;
19586 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
19587 wrap_row_min_pos
= min_pos
;
19588 wrap_row_min_bpos
= min_bpos
;
19589 wrap_row_max_pos
= max_pos
;
19590 wrap_row_max_bpos
= max_bpos
;
19596 PRODUCE_GLYPHS (it
);
19598 /* If this display element was in marginal areas, continue with
19600 if (it
->area
!= TEXT_AREA
)
19602 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19603 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19604 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19605 row
->phys_height
= max (row
->phys_height
,
19606 it
->max_phys_ascent
+ it
->max_phys_descent
);
19607 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19608 it
->max_extra_line_spacing
);
19609 set_iterator_to_next (it
, 1);
19613 /* Does the display element fit on the line? If we truncate
19614 lines, we should draw past the right edge of the window. If
19615 we don't truncate, we want to stop so that we can display the
19616 continuation glyph before the right margin. If lines are
19617 continued, there are two possible strategies for characters
19618 resulting in more than 1 glyph (e.g. tabs): Display as many
19619 glyphs as possible in this line and leave the rest for the
19620 continuation line, or display the whole element in the next
19621 line. Original redisplay did the former, so we do it also. */
19622 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
19623 hpos_before
= it
->hpos
;
19626 if (/* Not a newline. */
19628 /* Glyphs produced fit entirely in the line. */
19629 && it
->current_x
< it
->last_visible_x
)
19631 it
->hpos
+= nglyphs
;
19632 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19633 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19634 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19635 row
->phys_height
= max (row
->phys_height
,
19636 it
->max_phys_ascent
+ it
->max_phys_descent
);
19637 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19638 it
->max_extra_line_spacing
);
19639 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
19640 row
->x
= x
- it
->first_visible_x
;
19641 /* Record the maximum and minimum buffer positions seen so
19642 far in glyphs that will be displayed by this row. */
19644 RECORD_MAX_MIN_POS (it
);
19649 struct glyph
*glyph
;
19651 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
19653 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
19654 new_x
= x
+ glyph
->pixel_width
;
19656 if (/* Lines are continued. */
19657 it
->line_wrap
!= TRUNCATE
19658 && (/* Glyph doesn't fit on the line. */
19659 new_x
> it
->last_visible_x
19660 /* Or it fits exactly on a window system frame. */
19661 || (new_x
== it
->last_visible_x
19662 && FRAME_WINDOW_P (it
->f
)
19663 && (row
->reversed_p
19664 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19665 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
19667 /* End of a continued line. */
19670 || (new_x
== it
->last_visible_x
19671 && FRAME_WINDOW_P (it
->f
)
19672 && (row
->reversed_p
19673 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19674 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
))))
19676 /* Current glyph is the only one on the line or
19677 fits exactly on the line. We must continue
19678 the line because we can't draw the cursor
19679 after the glyph. */
19680 row
->continued_p
= 1;
19681 it
->current_x
= new_x
;
19682 it
->continuation_lines_width
+= new_x
;
19684 if (i
== nglyphs
- 1)
19686 /* If line-wrap is on, check if a previous
19687 wrap point was found. */
19688 if (wrap_row_used
> 0
19689 /* Even if there is a previous wrap
19690 point, continue the line here as
19691 usual, if (i) the previous character
19692 was a space or tab AND (ii) the
19693 current character is not. */
19695 || IT_DISPLAYING_WHITESPACE (it
)))
19698 /* Record the maximum and minimum buffer
19699 positions seen so far in glyphs that will be
19700 displayed by this row. */
19702 RECORD_MAX_MIN_POS (it
);
19703 set_iterator_to_next (it
, 1);
19704 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19706 if (!get_next_display_element (it
))
19708 row
->exact_window_width_line_p
= 1;
19709 it
->continuation_lines_width
= 0;
19710 row
->continued_p
= 0;
19711 row
->ends_at_zv_p
= 1;
19713 else if (ITERATOR_AT_END_OF_LINE_P (it
))
19715 row
->continued_p
= 0;
19716 row
->exact_window_width_line_p
= 1;
19720 else if (it
->bidi_p
)
19721 RECORD_MAX_MIN_POS (it
);
19723 else if (CHAR_GLYPH_PADDING_P (*glyph
)
19724 && !FRAME_WINDOW_P (it
->f
))
19726 /* A padding glyph that doesn't fit on this line.
19727 This means the whole character doesn't fit
19729 if (row
->reversed_p
)
19730 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19731 - n_glyphs_before
);
19732 row
->used
[TEXT_AREA
] = n_glyphs_before
;
19734 /* Fill the rest of the row with continuation
19735 glyphs like in 20.x. */
19736 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
19737 < row
->glyphs
[1 + TEXT_AREA
])
19738 produce_special_glyphs (it
, IT_CONTINUATION
);
19740 row
->continued_p
= 1;
19741 it
->current_x
= x_before
;
19742 it
->continuation_lines_width
+= x_before
;
19744 /* Restore the height to what it was before the
19745 element not fitting on the line. */
19746 it
->max_ascent
= ascent
;
19747 it
->max_descent
= descent
;
19748 it
->max_phys_ascent
= phys_ascent
;
19749 it
->max_phys_descent
= phys_descent
;
19751 else if (wrap_row_used
> 0)
19754 if (row
->reversed_p
)
19755 unproduce_glyphs (it
,
19756 row
->used
[TEXT_AREA
] - wrap_row_used
);
19757 RESTORE_IT (it
, &wrap_it
, wrap_data
);
19758 it
->continuation_lines_width
+= wrap_x
;
19759 row
->used
[TEXT_AREA
] = wrap_row_used
;
19760 row
->ascent
= wrap_row_ascent
;
19761 row
->height
= wrap_row_height
;
19762 row
->phys_ascent
= wrap_row_phys_ascent
;
19763 row
->phys_height
= wrap_row_phys_height
;
19764 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
19765 min_pos
= wrap_row_min_pos
;
19766 min_bpos
= wrap_row_min_bpos
;
19767 max_pos
= wrap_row_max_pos
;
19768 max_bpos
= wrap_row_max_bpos
;
19769 row
->continued_p
= 1;
19770 row
->ends_at_zv_p
= 0;
19771 row
->exact_window_width_line_p
= 0;
19772 it
->continuation_lines_width
+= x
;
19774 /* Make sure that a non-default face is extended
19775 up to the right margin of the window. */
19776 extend_face_to_end_of_line (it
);
19778 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
19780 /* A TAB that extends past the right edge of the
19781 window. This produces a single glyph on
19782 window system frames. We leave the glyph in
19783 this row and let it fill the row, but don't
19784 consume the TAB. */
19785 if ((row
->reversed_p
19786 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19787 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19788 produce_special_glyphs (it
, IT_CONTINUATION
);
19789 it
->continuation_lines_width
+= it
->last_visible_x
;
19790 row
->ends_in_middle_of_char_p
= 1;
19791 row
->continued_p
= 1;
19792 glyph
->pixel_width
= it
->last_visible_x
- x
;
19793 it
->starts_in_middle_of_char_p
= 1;
19797 /* Something other than a TAB that draws past
19798 the right edge of the window. Restore
19799 positions to values before the element. */
19800 if (row
->reversed_p
)
19801 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19802 - (n_glyphs_before
+ i
));
19803 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
19805 /* Display continuation glyphs. */
19806 it
->current_x
= x_before
;
19807 it
->continuation_lines_width
+= x
;
19808 if (!FRAME_WINDOW_P (it
->f
)
19809 || (row
->reversed_p
19810 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19811 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19812 produce_special_glyphs (it
, IT_CONTINUATION
);
19813 row
->continued_p
= 1;
19815 extend_face_to_end_of_line (it
);
19817 if (nglyphs
> 1 && i
> 0)
19819 row
->ends_in_middle_of_char_p
= 1;
19820 it
->starts_in_middle_of_char_p
= 1;
19823 /* Restore the height to what it was before the
19824 element not fitting on the line. */
19825 it
->max_ascent
= ascent
;
19826 it
->max_descent
= descent
;
19827 it
->max_phys_ascent
= phys_ascent
;
19828 it
->max_phys_descent
= phys_descent
;
19833 else if (new_x
> it
->first_visible_x
)
19835 /* Increment number of glyphs actually displayed. */
19838 /* Record the maximum and minimum buffer positions
19839 seen so far in glyphs that will be displayed by
19842 RECORD_MAX_MIN_POS (it
);
19844 if (x
< it
->first_visible_x
)
19845 /* Glyph is partially visible, i.e. row starts at
19846 negative X position. */
19847 row
->x
= x
- it
->first_visible_x
;
19851 /* Glyph is completely off the left margin of the
19852 window. This should not happen because of the
19853 move_it_in_display_line at the start of this
19854 function, unless the text display area of the
19855 window is empty. */
19856 eassert (it
->first_visible_x
<= it
->last_visible_x
);
19859 /* Even if this display element produced no glyphs at all,
19860 we want to record its position. */
19861 if (it
->bidi_p
&& nglyphs
== 0)
19862 RECORD_MAX_MIN_POS (it
);
19864 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19865 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19866 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19867 row
->phys_height
= max (row
->phys_height
,
19868 it
->max_phys_ascent
+ it
->max_phys_descent
);
19869 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19870 it
->max_extra_line_spacing
);
19872 /* End of this display line if row is continued. */
19873 if (row
->continued_p
|| row
->ends_at_zv_p
)
19878 /* Is this a line end? If yes, we're also done, after making
19879 sure that a non-default face is extended up to the right
19880 margin of the window. */
19881 if (ITERATOR_AT_END_OF_LINE_P (it
))
19883 int used_before
= row
->used
[TEXT_AREA
];
19885 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
19887 /* Add a space at the end of the line that is used to
19888 display the cursor there. */
19889 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19890 append_space_for_newline (it
, 0);
19892 /* Extend the face to the end of the line. */
19893 extend_face_to_end_of_line (it
);
19895 /* Make sure we have the position. */
19896 if (used_before
== 0)
19897 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
19899 /* Record the position of the newline, for use in
19901 it
->eol_pos
= it
->current
.pos
;
19903 /* Consume the line end. This skips over invisible lines. */
19904 set_iterator_to_next (it
, 1);
19905 it
->continuation_lines_width
= 0;
19909 /* Proceed with next display element. Note that this skips
19910 over lines invisible because of selective display. */
19911 set_iterator_to_next (it
, 1);
19913 /* If we truncate lines, we are done when the last displayed
19914 glyphs reach past the right margin of the window. */
19915 if (it
->line_wrap
== TRUNCATE
19916 && (FRAME_WINDOW_P (it
->f
) && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
19917 ? (it
->current_x
>= it
->last_visible_x
)
19918 : (it
->current_x
> it
->last_visible_x
)))
19920 /* Maybe add truncation glyphs. */
19921 if (!FRAME_WINDOW_P (it
->f
)
19922 || (row
->reversed_p
19923 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19924 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19928 if (!row
->reversed_p
)
19930 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
19931 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19936 for (i
= 0; i
< row
->used
[TEXT_AREA
]; i
++)
19937 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19939 /* Remove any padding glyphs at the front of ROW, to
19940 make room for the truncation glyphs we will be
19941 adding below. The loop below always inserts at
19942 least one truncation glyph, so also remove the
19943 last glyph added to ROW. */
19944 unproduce_glyphs (it
, i
+ 1);
19945 /* Adjust i for the loop below. */
19946 i
= row
->used
[TEXT_AREA
] - (i
+ 1);
19949 it
->current_x
= x_before
;
19950 if (!FRAME_WINDOW_P (it
->f
))
19952 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
19954 row
->used
[TEXT_AREA
] = i
;
19955 produce_special_glyphs (it
, IT_TRUNCATION
);
19960 row
->used
[TEXT_AREA
] = i
;
19961 produce_special_glyphs (it
, IT_TRUNCATION
);
19964 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19966 /* Don't truncate if we can overflow newline into fringe. */
19967 if (!get_next_display_element (it
))
19969 it
->continuation_lines_width
= 0;
19970 row
->ends_at_zv_p
= 1;
19971 row
->exact_window_width_line_p
= 1;
19974 if (ITERATOR_AT_END_OF_LINE_P (it
))
19976 row
->exact_window_width_line_p
= 1;
19977 goto at_end_of_line
;
19979 it
->current_x
= x_before
;
19982 row
->truncated_on_right_p
= 1;
19983 it
->continuation_lines_width
= 0;
19984 reseat_at_next_visible_line_start (it
, 0);
19985 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
19986 it
->hpos
= hpos_before
;
19992 bidi_unshelve_cache (wrap_data
, 1);
19994 /* If line is not empty and hscrolled, maybe insert truncation glyphs
19995 at the left window margin. */
19996 if (it
->first_visible_x
19997 && IT_CHARPOS (*it
) != CHARPOS (row
->start
.pos
))
19999 if (!FRAME_WINDOW_P (it
->f
)
20000 || (row
->reversed_p
20001 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
20002 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
20003 insert_left_trunc_glyphs (it
);
20004 row
->truncated_on_left_p
= 1;
20007 /* Remember the position at which this line ends.
20009 BIDI Note: any code that needs MATRIX_ROW_START/END_CHARPOS
20010 cannot be before the call to find_row_edges below, since that is
20011 where these positions are determined. */
20012 row
->end
= it
->current
;
20015 row
->minpos
= row
->start
.pos
;
20016 row
->maxpos
= row
->end
.pos
;
20020 /* ROW->minpos and ROW->maxpos must be the smallest and
20021 `1 + the largest' buffer positions in ROW. But if ROW was
20022 bidi-reordered, these two positions can be anywhere in the
20023 row, so we must determine them now. */
20024 find_row_edges (it
, row
, min_pos
, min_bpos
, max_pos
, max_bpos
);
20027 /* If the start of this line is the overlay arrow-position, then
20028 mark this glyph row as the one containing the overlay arrow.
20029 This is clearly a mess with variable size fonts. It would be
20030 better to let it be displayed like cursors under X. */
20031 if ((MATRIX_ROW_DISPLAYS_TEXT_P (row
) || !overlay_arrow_seen
)
20032 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
20033 !NILP (overlay_arrow_string
)))
20035 /* Overlay arrow in window redisplay is a fringe bitmap. */
20036 if (STRINGP (overlay_arrow_string
))
20038 struct glyph_row
*arrow_row
20039 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
20040 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
20041 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
20042 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
20043 struct glyph
*p2
, *end
;
20045 /* Copy the arrow glyphs. */
20046 while (glyph
< arrow_end
)
20049 /* Throw away padding glyphs. */
20051 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
20052 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
20058 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
20063 eassert (INTEGERP (overlay_arrow_string
));
20064 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
20066 overlay_arrow_seen
= 1;
20069 /* Highlight trailing whitespace. */
20070 if (!NILP (Vshow_trailing_whitespace
))
20071 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
20073 /* Compute pixel dimensions of this line. */
20074 compute_line_metrics (it
);
20076 /* Implementation note: No changes in the glyphs of ROW or in their
20077 faces can be done past this point, because compute_line_metrics
20078 computes ROW's hash value and stores it within the glyph_row
20081 /* Record whether this row ends inside an ellipsis. */
20082 row
->ends_in_ellipsis_p
20083 = (it
->method
== GET_FROM_DISPLAY_VECTOR
20084 && it
->ellipsis_p
);
20086 /* Save fringe bitmaps in this row. */
20087 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
20088 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
20089 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
20090 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
20092 it
->left_user_fringe_bitmap
= 0;
20093 it
->left_user_fringe_face_id
= 0;
20094 it
->right_user_fringe_bitmap
= 0;
20095 it
->right_user_fringe_face_id
= 0;
20097 /* Maybe set the cursor. */
20098 cvpos
= it
->w
->cursor
.vpos
;
20100 /* In bidi-reordered rows, keep checking for proper cursor
20101 position even if one has been found already, because buffer
20102 positions in such rows change non-linearly with ROW->VPOS,
20103 when a line is continued. One exception: when we are at ZV,
20104 display cursor on the first suitable glyph row, since all
20105 the empty rows after that also have their position set to ZV. */
20106 /* FIXME: Revisit this when glyph ``spilling'' in continuation
20107 lines' rows is implemented for bidi-reordered rows. */
20109 && !MATRIX_ROW (it
->w
->desired_matrix
, cvpos
)->ends_at_zv_p
))
20110 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
20111 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
20112 && cursor_row_p (row
))
20113 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
20115 /* Prepare for the next line. This line starts horizontally at (X
20116 HPOS) = (0 0). Vertical positions are incremented. As a
20117 convenience for the caller, IT->glyph_row is set to the next
20119 it
->current_x
= it
->hpos
= 0;
20120 it
->current_y
+= row
->height
;
20121 SET_TEXT_POS (it
->eol_pos
, 0, 0);
20124 /* The next row should by default use the same value of the
20125 reversed_p flag as this one. set_iterator_to_next decides when
20126 it's a new paragraph, and PRODUCE_GLYPHS recomputes the value of
20127 the flag accordingly. */
20128 if (it
->glyph_row
< MATRIX_BOTTOM_TEXT_ROW (it
->w
->desired_matrix
, it
->w
))
20129 it
->glyph_row
->reversed_p
= row
->reversed_p
;
20130 it
->start
= row
->end
;
20131 return MATRIX_ROW_DISPLAYS_TEXT_P (row
);
20133 #undef RECORD_MAX_MIN_POS
20136 DEFUN ("current-bidi-paragraph-direction", Fcurrent_bidi_paragraph_direction
,
20137 Scurrent_bidi_paragraph_direction
, 0, 1, 0,
20138 doc
: /* Return paragraph direction at point in BUFFER.
20139 Value is either `left-to-right' or `right-to-left'.
20140 If BUFFER is omitted or nil, it defaults to the current buffer.
20142 Paragraph direction determines how the text in the paragraph is displayed.
20143 In left-to-right paragraphs, text begins at the left margin of the window
20144 and the reading direction is generally left to right. In right-to-left
20145 paragraphs, text begins at the right margin and is read from right to left.
20147 See also `bidi-paragraph-direction'. */)
20148 (Lisp_Object buffer
)
20150 struct buffer
*buf
= current_buffer
;
20151 struct buffer
*old
= buf
;
20153 if (! NILP (buffer
))
20155 CHECK_BUFFER (buffer
);
20156 buf
= XBUFFER (buffer
);
20159 if (NILP (BVAR (buf
, bidi_display_reordering
))
20160 || NILP (BVAR (buf
, enable_multibyte_characters
))
20161 /* When we are loading loadup.el, the character property tables
20162 needed for bidi iteration are not yet available. */
20163 || !NILP (Vpurify_flag
))
20164 return Qleft_to_right
;
20165 else if (!NILP (BVAR (buf
, bidi_paragraph_direction
)))
20166 return BVAR (buf
, bidi_paragraph_direction
);
20169 /* Determine the direction from buffer text. We could try to
20170 use current_matrix if it is up to date, but this seems fast
20171 enough as it is. */
20172 struct bidi_it itb
;
20173 ptrdiff_t pos
= BUF_PT (buf
);
20174 ptrdiff_t bytepos
= BUF_PT_BYTE (buf
);
20176 void *itb_data
= bidi_shelve_cache ();
20178 set_buffer_temp (buf
);
20179 /* bidi_paragraph_init finds the base direction of the paragraph
20180 by searching forward from paragraph start. We need the base
20181 direction of the current or _previous_ paragraph, so we need
20182 to make sure we are within that paragraph. To that end, find
20183 the previous non-empty line. */
20184 if (pos
>= ZV
&& pos
> BEGV
)
20185 DEC_BOTH (pos
, bytepos
);
20186 if (fast_looking_at (build_string ("[\f\t ]*\n"),
20187 pos
, bytepos
, ZV
, ZV_BYTE
, Qnil
) > 0)
20189 while ((c
= FETCH_BYTE (bytepos
)) == '\n'
20190 || c
== ' ' || c
== '\t' || c
== '\f')
20192 if (bytepos
<= BEGV_BYTE
)
20197 while (!CHAR_HEAD_P (FETCH_BYTE (bytepos
)))
20200 bidi_init_it (pos
, bytepos
, FRAME_WINDOW_P (SELECTED_FRAME ()), &itb
);
20201 itb
.paragraph_dir
= NEUTRAL_DIR
;
20202 itb
.string
.s
= NULL
;
20203 itb
.string
.lstring
= Qnil
;
20204 itb
.string
.bufpos
= 0;
20205 itb
.string
.unibyte
= 0;
20206 /* We have no window to use here for ignoring window-specific
20207 overlays. Using NULL for window pointer will cause
20208 compute_display_string_pos to use the current buffer. */
20210 bidi_paragraph_init (NEUTRAL_DIR
, &itb
, 1);
20211 bidi_unshelve_cache (itb_data
, 0);
20212 set_buffer_temp (old
);
20213 switch (itb
.paragraph_dir
)
20216 return Qleft_to_right
;
20219 return Qright_to_left
;
20227 DEFUN ("move-point-visually", Fmove_point_visually
,
20228 Smove_point_visually
, 1, 1, 0,
20229 doc
: /* Move point in the visual order in the specified DIRECTION.
20230 DIRECTION can be 1, meaning move to the right, or -1, which moves to the
20233 Value is the new character position of point. */)
20234 (Lisp_Object direction
)
20236 struct window
*w
= XWINDOW (selected_window
);
20237 struct buffer
*b
= XBUFFER (w
->contents
);
20238 struct glyph_row
*row
;
20240 Lisp_Object paragraph_dir
;
20242 #define ROW_GLYPH_NEWLINE_P(ROW,GLYPH) \
20243 (!(ROW)->continued_p \
20244 && INTEGERP ((GLYPH)->object) \
20245 && (GLYPH)->type == CHAR_GLYPH \
20246 && (GLYPH)->u.ch == ' ' \
20247 && (GLYPH)->charpos >= 0 \
20248 && !(GLYPH)->avoid_cursor_p)
20250 CHECK_NUMBER (direction
);
20251 dir
= XINT (direction
);
20257 /* If current matrix is up-to-date, we can use the information
20258 recorded in the glyphs, at least as long as the goal is on the
20260 if (w
->window_end_valid
20261 && !windows_or_buffers_changed
20263 && !b
->clip_changed
20264 && !b
->prevent_redisplay_optimizations_p
20265 && !window_outdated (w
)
20266 && w
->cursor
.vpos
>= 0
20267 && w
->cursor
.vpos
< w
->current_matrix
->nrows
20268 && (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
))->enabled_p
)
20270 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
20271 struct glyph
*e
= dir
> 0 ? g
+ row
->used
[TEXT_AREA
] : g
- 1;
20272 struct glyph
*gpt
= g
+ w
->cursor
.hpos
;
20274 for (g
= gpt
+ dir
; (dir
> 0 ? g
< e
: g
> e
); g
+= dir
)
20276 if (BUFFERP (g
->object
) && g
->charpos
!= PT
)
20278 SET_PT (g
->charpos
);
20279 w
->cursor
.vpos
= -1;
20280 return make_number (PT
);
20282 else if (!INTEGERP (g
->object
) && !EQ (g
->object
, gpt
->object
))
20286 if (BUFFERP (gpt
->object
))
20289 if ((gpt
->resolved_level
- row
->reversed_p
) % 2 == 0)
20290 new_pos
+= (row
->reversed_p
? -dir
: dir
);
20292 new_pos
-= (row
->reversed_p
? -dir
: dir
);;
20294 else if (BUFFERP (g
->object
))
20295 new_pos
= g
->charpos
;
20299 w
->cursor
.vpos
= -1;
20300 return make_number (PT
);
20302 else if (ROW_GLYPH_NEWLINE_P (row
, g
))
20304 /* Glyphs inserted at the end of a non-empty line for
20305 positioning the cursor have zero charpos, so we must
20306 deduce the value of point by other means. */
20307 if (g
->charpos
> 0)
20308 SET_PT (g
->charpos
);
20309 else if (row
->ends_at_zv_p
&& PT
!= ZV
)
20311 else if (PT
!= MATRIX_ROW_END_CHARPOS (row
) - 1)
20312 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
20315 w
->cursor
.vpos
= -1;
20316 return make_number (PT
);
20319 if (g
== e
|| INTEGERP (g
->object
))
20321 if (row
->truncated_on_left_p
|| row
->truncated_on_right_p
)
20322 goto simulate_display
;
20323 if (!row
->reversed_p
)
20327 if (row
< MATRIX_FIRST_TEXT_ROW (w
->current_matrix
)
20328 || row
> MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
20329 goto simulate_display
;
20333 if (row
->reversed_p
&& !row
->continued_p
)
20335 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
20336 w
->cursor
.vpos
= -1;
20337 return make_number (PT
);
20339 g
= row
->glyphs
[TEXT_AREA
];
20340 e
= g
+ row
->used
[TEXT_AREA
];
20341 for ( ; g
< e
; g
++)
20343 if (BUFFERP (g
->object
)
20344 /* Empty lines have only one glyph, which stands
20345 for the newline, and whose charpos is the
20346 buffer position of the newline. */
20347 || ROW_GLYPH_NEWLINE_P (row
, g
)
20348 /* When the buffer ends in a newline, the line at
20349 EOB also has one glyph, but its charpos is -1. */
20350 || (row
->ends_at_zv_p
20351 && !row
->reversed_p
20352 && INTEGERP (g
->object
)
20353 && g
->type
== CHAR_GLYPH
20354 && g
->u
.ch
== ' '))
20356 if (g
->charpos
> 0)
20357 SET_PT (g
->charpos
);
20358 else if (!row
->reversed_p
20359 && row
->ends_at_zv_p
20364 w
->cursor
.vpos
= -1;
20365 return make_number (PT
);
20371 if (!row
->reversed_p
&& !row
->continued_p
)
20373 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
20374 w
->cursor
.vpos
= -1;
20375 return make_number (PT
);
20377 e
= row
->glyphs
[TEXT_AREA
];
20378 g
= e
+ row
->used
[TEXT_AREA
] - 1;
20379 for ( ; g
>= e
; g
--)
20381 if (BUFFERP (g
->object
)
20382 || (ROW_GLYPH_NEWLINE_P (row
, g
)
20384 /* Empty R2L lines on GUI frames have the buffer
20385 position of the newline stored in the stretch
20387 || g
->type
== STRETCH_GLYPH
20388 || (row
->ends_at_zv_p
20390 && INTEGERP (g
->object
)
20391 && g
->type
== CHAR_GLYPH
20392 && g
->u
.ch
== ' '))
20394 if (g
->charpos
> 0)
20395 SET_PT (g
->charpos
);
20396 else if (row
->reversed_p
20397 && row
->ends_at_zv_p
20402 w
->cursor
.vpos
= -1;
20403 return make_number (PT
);
20412 /* If we wind up here, we failed to move by using the glyphs, so we
20413 need to simulate display instead. */
20416 paragraph_dir
= Fcurrent_bidi_paragraph_direction (w
->contents
);
20418 paragraph_dir
= Qleft_to_right
;
20419 if (EQ (paragraph_dir
, Qright_to_left
))
20421 if (PT
<= BEGV
&& dir
< 0)
20422 xsignal0 (Qbeginning_of_buffer
);
20423 else if (PT
>= ZV
&& dir
> 0)
20424 xsignal0 (Qend_of_buffer
);
20427 struct text_pos pt
;
20429 int pt_x
, target_x
, pixel_width
, pt_vpos
;
20431 bool overshoot_expected
= false;
20432 bool target_is_eol_p
= false;
20434 /* Setup the arena. */
20435 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
20436 start_display (&it
, w
, pt
);
20438 if (it
.cmp_it
.id
< 0
20439 && it
.method
== GET_FROM_STRING
20440 && it
.area
== TEXT_AREA
20441 && it
.string_from_display_prop_p
20442 && (it
.sp
> 0 && it
.stack
[it
.sp
- 1].method
== GET_FROM_BUFFER
))
20443 overshoot_expected
= true;
20445 /* Find the X coordinate of point. We start from the beginning
20446 of this or previous line to make sure we are before point in
20447 the logical order (since the move_it_* functions can only
20449 reseat_at_previous_visible_line_start (&it
);
20450 it
.current_x
= it
.hpos
= it
.current_y
= it
.vpos
= 0;
20451 if (IT_CHARPOS (it
) != PT
)
20452 move_it_to (&it
, overshoot_expected
? PT
- 1 : PT
,
20453 -1, -1, -1, MOVE_TO_POS
);
20454 pt_x
= it
.current_x
;
20456 if (dir
> 0 || overshoot_expected
)
20458 struct glyph_row
*row
= it
.glyph_row
;
20460 /* When point is at beginning of line, we don't have
20461 information about the glyph there loaded into struct
20462 it. Calling get_next_display_element fixes that. */
20464 get_next_display_element (&it
);
20465 at_eol_p
= ITERATOR_AT_END_OF_LINE_P (&it
);
20466 it
.glyph_row
= NULL
;
20467 PRODUCE_GLYPHS (&it
); /* compute it.pixel_width */
20468 it
.glyph_row
= row
;
20469 /* PRODUCE_GLYPHS advances it.current_x, so we must restore
20470 it, lest it will become out of sync with it's buffer
20472 it
.current_x
= pt_x
;
20475 at_eol_p
= ITERATOR_AT_END_OF_LINE_P (&it
);
20476 pixel_width
= it
.pixel_width
;
20477 if (overshoot_expected
&& at_eol_p
)
20479 else if (pixel_width
<= 0)
20482 /* If there's a display string at point, we are actually at the
20483 glyph to the left of point, so we need to correct the X
20485 if (overshoot_expected
)
20486 pt_x
+= pixel_width
;
20488 /* Compute target X coordinate, either to the left or to the
20489 right of point. On TTY frames, all characters have the same
20490 pixel width of 1, so we can use that. On GUI frames we don't
20491 have an easy way of getting at the pixel width of the
20492 character to the left of point, so we use a different method
20493 of getting to that place. */
20495 target_x
= pt_x
+ pixel_width
;
20497 target_x
= pt_x
- (!FRAME_WINDOW_P (it
.f
)) * pixel_width
;
20499 /* Target X coordinate could be one line above or below the line
20500 of point, in which case we need to adjust the target X
20501 coordinate. Also, if moving to the left, we need to begin at
20502 the left edge of the point's screen line. */
20507 start_display (&it
, w
, pt
);
20508 reseat_at_previous_visible_line_start (&it
);
20509 it
.current_x
= it
.current_y
= it
.hpos
= 0;
20511 move_it_by_lines (&it
, pt_vpos
);
20515 move_it_by_lines (&it
, -1);
20516 target_x
= it
.last_visible_x
- !FRAME_WINDOW_P (it
.f
);
20517 target_is_eol_p
= true;
20523 || (target_x
>= it
.last_visible_x
20524 && it
.line_wrap
!= TRUNCATE
))
20527 move_it_by_lines (&it
, 0);
20528 move_it_by_lines (&it
, 1);
20533 /* Move to the target X coordinate. */
20534 #ifdef HAVE_WINDOW_SYSTEM
20535 /* On GUI frames, as we don't know the X coordinate of the
20536 character to the left of point, moving point to the left
20537 requires walking, one grapheme cluster at a time, until we
20538 find ourself at a place immediately to the left of the
20539 character at point. */
20540 if (FRAME_WINDOW_P (it
.f
) && dir
< 0)
20542 struct text_pos new_pos
= it
.current
.pos
;
20543 enum move_it_result rc
= MOVE_X_REACHED
;
20545 while (it
.current_x
+ it
.pixel_width
<= target_x
20546 && rc
== MOVE_X_REACHED
)
20548 int new_x
= it
.current_x
+ it
.pixel_width
;
20550 new_pos
= it
.current
.pos
;
20551 if (new_x
== it
.current_x
)
20553 rc
= move_it_in_display_line_to (&it
, ZV
, new_x
,
20554 MOVE_TO_POS
| MOVE_TO_X
);
20555 if (ITERATOR_AT_END_OF_LINE_P (&it
) && !target_is_eol_p
)
20558 /* If we ended up on a composed character inside
20559 bidi-reordered text (e.g., Hebrew text with diacritics),
20560 the iterator gives us the buffer position of the last (in
20561 logical order) character of the composed grapheme cluster,
20562 which is not what we want. So we cheat: we compute the
20563 character position of the character that follows (in the
20564 logical order) the one where the above loop stopped. That
20565 character will appear on display to the left of point. */
20567 && it
.bidi_it
.scan_dir
== -1
20568 && new_pos
.charpos
- IT_CHARPOS (it
) > 1)
20570 new_pos
.charpos
= IT_CHARPOS (it
) + 1;
20571 new_pos
.bytepos
= CHAR_TO_BYTE (new_pos
.charpos
);
20573 it
.current
.pos
= new_pos
;
20577 if (it
.current_x
!= target_x
)
20578 move_it_in_display_line_to (&it
, ZV
, target_x
, MOVE_TO_POS
| MOVE_TO_X
);
20580 /* When lines are truncated, the above loop will stop at the
20581 window edge. But we want to get to the end of line, even if
20582 it is beyond the window edge; automatic hscroll will then
20583 scroll the window to show point as appropriate. */
20584 if (target_is_eol_p
&& it
.line_wrap
== TRUNCATE
20585 && get_next_display_element (&it
))
20587 struct text_pos new_pos
= it
.current
.pos
;
20589 while (!ITERATOR_AT_END_OF_LINE_P (&it
))
20591 set_iterator_to_next (&it
, 0);
20592 if (it
.method
== GET_FROM_BUFFER
)
20593 new_pos
= it
.current
.pos
;
20594 if (!get_next_display_element (&it
))
20598 it
.current
.pos
= new_pos
;
20601 /* If we ended up in a display string that covers point, move to
20602 buffer position to the right in the visual order. */
20605 while (IT_CHARPOS (it
) == PT
)
20607 set_iterator_to_next (&it
, 0);
20608 if (!get_next_display_element (&it
))
20613 /* Move point to that position. */
20614 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
20617 return make_number (PT
);
20619 #undef ROW_GLYPH_NEWLINE_P
20623 /***********************************************************************
20625 ***********************************************************************/
20627 /* Redisplay the menu bar in the frame for window W.
20629 The menu bar of X frames that don't have X toolkit support is
20630 displayed in a special window W->frame->menu_bar_window.
20632 The menu bar of terminal frames is treated specially as far as
20633 glyph matrices are concerned. Menu bar lines are not part of
20634 windows, so the update is done directly on the frame matrix rows
20635 for the menu bar. */
20638 display_menu_bar (struct window
*w
)
20640 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20645 /* Don't do all this for graphical frames. */
20647 if (FRAME_W32_P (f
))
20650 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
20656 if (FRAME_NS_P (f
))
20658 #endif /* HAVE_NS */
20660 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
20661 eassert (!FRAME_WINDOW_P (f
));
20662 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
20663 it
.first_visible_x
= 0;
20664 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
20665 #elif defined (HAVE_X_WINDOWS) /* X without toolkit. */
20666 if (FRAME_WINDOW_P (f
))
20668 /* Menu bar lines are displayed in the desired matrix of the
20669 dummy window menu_bar_window. */
20670 struct window
*menu_w
;
20671 menu_w
= XWINDOW (f
->menu_bar_window
);
20672 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
20674 it
.first_visible_x
= 0;
20675 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
20678 #endif /* not USE_X_TOOLKIT and not USE_GTK */
20680 /* This is a TTY frame, i.e. character hpos/vpos are used as
20682 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
20684 it
.first_visible_x
= 0;
20685 it
.last_visible_x
= FRAME_COLS (f
);
20688 /* FIXME: This should be controlled by a user option. See the
20689 comments in redisplay_tool_bar and display_mode_line about
20691 it
.paragraph_embedding
= L2R
;
20693 /* Clear all rows of the menu bar. */
20694 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
20696 struct glyph_row
*row
= it
.glyph_row
+ i
;
20697 clear_glyph_row (row
);
20698 row
->enabled_p
= 1;
20699 row
->full_width_p
= 1;
20702 /* Display all items of the menu bar. */
20703 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
20704 for (i
= 0; i
< ASIZE (items
); i
+= 4)
20706 Lisp_Object string
;
20708 /* Stop at nil string. */
20709 string
= AREF (items
, i
+ 1);
20713 /* Remember where item was displayed. */
20714 ASET (items
, i
+ 3, make_number (it
.hpos
));
20716 /* Display the item, pad with one space. */
20717 if (it
.current_x
< it
.last_visible_x
)
20718 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
20719 SCHARS (string
) + 1, 0, 0, -1);
20722 /* Fill out the line with spaces. */
20723 if (it
.current_x
< it
.last_visible_x
)
20724 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
20726 /* Compute the total height of the lines. */
20727 compute_line_metrics (&it
);
20732 /***********************************************************************
20734 ***********************************************************************/
20736 /* Redisplay mode lines in the window tree whose root is WINDOW. If
20737 FORCE is non-zero, redisplay mode lines unconditionally.
20738 Otherwise, redisplay only mode lines that are garbaged. Value is
20739 the number of windows whose mode lines were redisplayed. */
20742 redisplay_mode_lines (Lisp_Object window
, int force
)
20746 while (!NILP (window
))
20748 struct window
*w
= XWINDOW (window
);
20750 if (WINDOWP (w
->contents
))
20751 nwindows
+= redisplay_mode_lines (w
->contents
, force
);
20753 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
20754 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
20756 struct text_pos lpoint
;
20757 struct buffer
*old
= current_buffer
;
20759 /* Set the window's buffer for the mode line display. */
20760 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
20761 set_buffer_internal_1 (XBUFFER (w
->contents
));
20763 /* Point refers normally to the selected window. For any
20764 other window, set up appropriate value. */
20765 if (!EQ (window
, selected_window
))
20767 struct text_pos pt
;
20769 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
20770 if (CHARPOS (pt
) < BEGV
)
20771 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
20772 else if (CHARPOS (pt
) > (ZV
- 1))
20773 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
20775 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
20778 /* Display mode lines. */
20779 clear_glyph_matrix (w
->desired_matrix
);
20780 if (display_mode_lines (w
))
20783 w
->must_be_updated_p
= 1;
20786 /* Restore old settings. */
20787 set_buffer_internal_1 (old
);
20788 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
20798 /* Display the mode and/or header line of window W. Value is the
20799 sum number of mode lines and header lines displayed. */
20802 display_mode_lines (struct window
*w
)
20804 Lisp_Object old_selected_window
= selected_window
;
20805 Lisp_Object old_selected_frame
= selected_frame
;
20806 Lisp_Object new_frame
= w
->frame
;
20807 Lisp_Object old_frame_selected_window
= XFRAME (new_frame
)->selected_window
;
20810 selected_frame
= new_frame
;
20811 /* FIXME: If we were to allow the mode-line's computation changing the buffer
20812 or window's point, then we'd need select_window_1 here as well. */
20813 XSETWINDOW (selected_window
, w
);
20814 XFRAME (new_frame
)->selected_window
= selected_window
;
20816 /* These will be set while the mode line specs are processed. */
20817 line_number_displayed
= 0;
20818 w
->column_number_displayed
= -1;
20820 if (WINDOW_WANTS_MODELINE_P (w
))
20822 struct window
*sel_w
= XWINDOW (old_selected_window
);
20824 /* Select mode line face based on the real selected window. */
20825 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
20826 BVAR (current_buffer
, mode_line_format
));
20830 if (WINDOW_WANTS_HEADER_LINE_P (w
))
20832 display_mode_line (w
, HEADER_LINE_FACE_ID
,
20833 BVAR (current_buffer
, header_line_format
));
20837 XFRAME (new_frame
)->selected_window
= old_frame_selected_window
;
20838 selected_frame
= old_selected_frame
;
20839 selected_window
= old_selected_window
;
20844 /* Display mode or header line of window W. FACE_ID specifies which
20845 line to display; it is either MODE_LINE_FACE_ID or
20846 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
20847 display. Value is the pixel height of the mode/header line
20851 display_mode_line (struct window
*w
, enum face_id face_id
, Lisp_Object format
)
20855 ptrdiff_t count
= SPECPDL_INDEX ();
20857 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
20858 /* Don't extend on a previously drawn mode-line.
20859 This may happen if called from pos_visible_p. */
20860 it
.glyph_row
->enabled_p
= 0;
20861 prepare_desired_row (it
.glyph_row
);
20863 it
.glyph_row
->mode_line_p
= 1;
20865 /* FIXME: This should be controlled by a user option. But
20866 supporting such an option is not trivial, since the mode line is
20867 made up of many separate strings. */
20868 it
.paragraph_embedding
= L2R
;
20870 record_unwind_protect (unwind_format_mode_line
,
20871 format_mode_line_unwind_data (NULL
, NULL
, Qnil
, 0));
20873 mode_line_target
= MODE_LINE_DISPLAY
;
20875 /* Temporarily make frame's keyboard the current kboard so that
20876 kboard-local variables in the mode_line_format will get the right
20878 push_kboard (FRAME_KBOARD (it
.f
));
20879 record_unwind_save_match_data ();
20880 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
20883 unbind_to (count
, Qnil
);
20885 /* Fill up with spaces. */
20886 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
20888 compute_line_metrics (&it
);
20889 it
.glyph_row
->full_width_p
= 1;
20890 it
.glyph_row
->continued_p
= 0;
20891 it
.glyph_row
->truncated_on_left_p
= 0;
20892 it
.glyph_row
->truncated_on_right_p
= 0;
20894 /* Make a 3D mode-line have a shadow at its right end. */
20895 face
= FACE_FROM_ID (it
.f
, face_id
);
20896 extend_face_to_end_of_line (&it
);
20897 if (face
->box
!= FACE_NO_BOX
)
20899 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
20900 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
20901 last
->right_box_line_p
= 1;
20904 return it
.glyph_row
->height
;
20907 /* Move element ELT in LIST to the front of LIST.
20908 Return the updated list. */
20911 move_elt_to_front (Lisp_Object elt
, Lisp_Object list
)
20913 register Lisp_Object tail
, prev
;
20914 register Lisp_Object tem
;
20918 while (CONSP (tail
))
20924 /* Splice out the link TAIL. */
20926 list
= XCDR (tail
);
20928 Fsetcdr (prev
, XCDR (tail
));
20930 /* Now make it the first. */
20931 Fsetcdr (tail
, list
);
20936 tail
= XCDR (tail
);
20940 /* Not found--return unchanged LIST. */
20944 /* Contribute ELT to the mode line for window IT->w. How it
20945 translates into text depends on its data type.
20947 IT describes the display environment in which we display, as usual.
20949 DEPTH is the depth in recursion. It is used to prevent
20950 infinite recursion here.
20952 FIELD_WIDTH is the number of characters the display of ELT should
20953 occupy in the mode line, and PRECISION is the maximum number of
20954 characters to display from ELT's representation. See
20955 display_string for details.
20957 Returns the hpos of the end of the text generated by ELT.
20959 PROPS is a property list to add to any string we encounter.
20961 If RISKY is nonzero, remove (disregard) any properties in any string
20962 we encounter, and ignore :eval and :propertize.
20964 The global variable `mode_line_target' determines whether the
20965 output is passed to `store_mode_line_noprop',
20966 `store_mode_line_string', or `display_string'. */
20969 display_mode_element (struct it
*it
, int depth
, int field_width
, int precision
,
20970 Lisp_Object elt
, Lisp_Object props
, int risky
)
20972 int n
= 0, field
, prec
;
20977 elt
= build_string ("*too-deep*");
20981 switch (XTYPE (elt
))
20985 /* A string: output it and check for %-constructs within it. */
20987 ptrdiff_t offset
= 0;
20989 if (SCHARS (elt
) > 0
20990 && (!NILP (props
) || risky
))
20992 Lisp_Object oprops
, aelt
;
20993 oprops
= Ftext_properties_at (make_number (0), elt
);
20995 /* If the starting string's properties are not what
20996 we want, translate the string. Also, if the string
20997 is risky, do that anyway. */
20999 if (NILP (Fequal (props
, oprops
)) || risky
)
21001 /* If the starting string has properties,
21002 merge the specified ones onto the existing ones. */
21003 if (! NILP (oprops
) && !risky
)
21007 oprops
= Fcopy_sequence (oprops
);
21009 while (CONSP (tem
))
21011 oprops
= Fplist_put (oprops
, XCAR (tem
),
21012 XCAR (XCDR (tem
)));
21013 tem
= XCDR (XCDR (tem
));
21018 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
21019 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
21021 /* AELT is what we want. Move it to the front
21022 without consing. */
21024 mode_line_proptrans_alist
21025 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
21031 /* If AELT has the wrong props, it is useless.
21032 so get rid of it. */
21034 mode_line_proptrans_alist
21035 = Fdelq (aelt
, mode_line_proptrans_alist
);
21037 elt
= Fcopy_sequence (elt
);
21038 Fset_text_properties (make_number (0), Flength (elt
),
21040 /* Add this item to mode_line_proptrans_alist. */
21041 mode_line_proptrans_alist
21042 = Fcons (Fcons (elt
, props
),
21043 mode_line_proptrans_alist
);
21044 /* Truncate mode_line_proptrans_alist
21045 to at most 50 elements. */
21046 tem
= Fnthcdr (make_number (50),
21047 mode_line_proptrans_alist
);
21049 XSETCDR (tem
, Qnil
);
21058 prec
= precision
- n
;
21059 switch (mode_line_target
)
21061 case MODE_LINE_NOPROP
:
21062 case MODE_LINE_TITLE
:
21063 n
+= store_mode_line_noprop (SSDATA (elt
), -1, prec
);
21065 case MODE_LINE_STRING
:
21066 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
21068 case MODE_LINE_DISPLAY
:
21069 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
21070 0, prec
, 0, STRING_MULTIBYTE (elt
));
21077 /* Handle the non-literal case. */
21079 while ((precision
<= 0 || n
< precision
)
21080 && SREF (elt
, offset
) != 0
21081 && (mode_line_target
!= MODE_LINE_DISPLAY
21082 || it
->current_x
< it
->last_visible_x
))
21084 ptrdiff_t last_offset
= offset
;
21086 /* Advance to end of string or next format specifier. */
21087 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
21090 if (offset
- 1 != last_offset
)
21092 ptrdiff_t nchars
, nbytes
;
21094 /* Output to end of string or up to '%'. Field width
21095 is length of string. Don't output more than
21096 PRECISION allows us. */
21099 prec
= c_string_width (SDATA (elt
) + last_offset
,
21100 offset
- last_offset
, precision
- n
,
21103 switch (mode_line_target
)
21105 case MODE_LINE_NOPROP
:
21106 case MODE_LINE_TITLE
:
21107 n
+= store_mode_line_noprop (SSDATA (elt
) + last_offset
, 0, prec
);
21109 case MODE_LINE_STRING
:
21111 ptrdiff_t bytepos
= last_offset
;
21112 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
21113 ptrdiff_t endpos
= (precision
<= 0
21114 ? string_byte_to_char (elt
, offset
)
21115 : charpos
+ nchars
);
21117 n
+= store_mode_line_string (NULL
,
21118 Fsubstring (elt
, make_number (charpos
),
21119 make_number (endpos
)),
21123 case MODE_LINE_DISPLAY
:
21125 ptrdiff_t bytepos
= last_offset
;
21126 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
21128 if (precision
<= 0)
21129 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
21130 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
21132 STRING_MULTIBYTE (elt
));
21137 else /* c == '%' */
21139 ptrdiff_t percent_position
= offset
;
21141 /* Get the specified minimum width. Zero means
21144 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
21145 field
= field
* 10 + c
- '0';
21147 /* Don't pad beyond the total padding allowed. */
21148 if (field_width
- n
> 0 && field
> field_width
- n
)
21149 field
= field_width
- n
;
21151 /* Note that either PRECISION <= 0 or N < PRECISION. */
21152 prec
= precision
- n
;
21155 n
+= display_mode_element (it
, depth
, field
, prec
,
21156 Vglobal_mode_string
, props
,
21161 ptrdiff_t bytepos
, charpos
;
21163 Lisp_Object string
;
21165 bytepos
= percent_position
;
21166 charpos
= (STRING_MULTIBYTE (elt
)
21167 ? string_byte_to_char (elt
, bytepos
)
21169 spec
= decode_mode_spec (it
->w
, c
, field
, &string
);
21170 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
21172 switch (mode_line_target
)
21174 case MODE_LINE_NOPROP
:
21175 case MODE_LINE_TITLE
:
21176 n
+= store_mode_line_noprop (spec
, field
, prec
);
21178 case MODE_LINE_STRING
:
21180 Lisp_Object tem
= build_string (spec
);
21181 props
= Ftext_properties_at (make_number (charpos
), elt
);
21182 /* Should only keep face property in props */
21183 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
21186 case MODE_LINE_DISPLAY
:
21188 int nglyphs_before
, nwritten
;
21190 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
21191 nwritten
= display_string (spec
, string
, elt
,
21196 /* Assign to the glyphs written above the
21197 string where the `%x' came from, position
21201 struct glyph
*glyph
21202 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
21206 for (i
= 0; i
< nwritten
; ++i
)
21208 glyph
[i
].object
= elt
;
21209 glyph
[i
].charpos
= charpos
;
21226 /* A symbol: process the value of the symbol recursively
21227 as if it appeared here directly. Avoid error if symbol void.
21228 Special case: if value of symbol is a string, output the string
21231 register Lisp_Object tem
;
21233 /* If the variable is not marked as risky to set
21234 then its contents are risky to use. */
21235 if (NILP (Fget (elt
, Qrisky_local_variable
)))
21238 tem
= Fboundp (elt
);
21241 tem
= Fsymbol_value (elt
);
21242 /* If value is a string, output that string literally:
21243 don't check for % within it. */
21247 if (!EQ (tem
, elt
))
21249 /* Give up right away for nil or t. */
21259 register Lisp_Object car
, tem
;
21261 /* A cons cell: five distinct cases.
21262 If first element is :eval or :propertize, do something special.
21263 If first element is a string or a cons, process all the elements
21264 and effectively concatenate them.
21265 If first element is a negative number, truncate displaying cdr to
21266 at most that many characters. If positive, pad (with spaces)
21267 to at least that many characters.
21268 If first element is a symbol, process the cadr or caddr recursively
21269 according to whether the symbol's value is non-nil or nil. */
21271 if (EQ (car
, QCeval
))
21273 /* An element of the form (:eval FORM) means evaluate FORM
21274 and use the result as mode line elements. */
21279 if (CONSP (XCDR (elt
)))
21282 spec
= safe_eval (XCAR (XCDR (elt
)));
21283 n
+= display_mode_element (it
, depth
, field_width
- n
,
21284 precision
- n
, spec
, props
,
21288 else if (EQ (car
, QCpropertize
))
21290 /* An element of the form (:propertize ELT PROPS...)
21291 means display ELT but applying properties PROPS. */
21296 if (CONSP (XCDR (elt
)))
21297 n
+= display_mode_element (it
, depth
, field_width
- n
,
21298 precision
- n
, XCAR (XCDR (elt
)),
21299 XCDR (XCDR (elt
)), risky
);
21301 else if (SYMBOLP (car
))
21303 tem
= Fboundp (car
);
21307 /* elt is now the cdr, and we know it is a cons cell.
21308 Use its car if CAR has a non-nil value. */
21311 tem
= Fsymbol_value (car
);
21318 /* Symbol's value is nil (or symbol is unbound)
21319 Get the cddr of the original list
21320 and if possible find the caddr and use that. */
21324 else if (!CONSP (elt
))
21329 else if (INTEGERP (car
))
21331 register int lim
= XINT (car
);
21335 /* Negative int means reduce maximum width. */
21336 if (precision
<= 0)
21339 precision
= min (precision
, -lim
);
21343 /* Padding specified. Don't let it be more than
21344 current maximum. */
21346 lim
= min (precision
, lim
);
21348 /* If that's more padding than already wanted, queue it.
21349 But don't reduce padding already specified even if
21350 that is beyond the current truncation point. */
21351 field_width
= max (lim
, field_width
);
21355 else if (STRINGP (car
) || CONSP (car
))
21357 Lisp_Object halftail
= elt
;
21361 && (precision
<= 0 || n
< precision
))
21363 n
+= display_mode_element (it
, depth
,
21364 /* Do padding only after the last
21365 element in the list. */
21366 (! CONSP (XCDR (elt
))
21369 precision
- n
, XCAR (elt
),
21373 if ((len
& 1) == 0)
21374 halftail
= XCDR (halftail
);
21375 /* Check for cycle. */
21376 if (EQ (halftail
, elt
))
21385 elt
= build_string ("*invalid*");
21389 /* Pad to FIELD_WIDTH. */
21390 if (field_width
> 0 && n
< field_width
)
21392 switch (mode_line_target
)
21394 case MODE_LINE_NOPROP
:
21395 case MODE_LINE_TITLE
:
21396 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
21398 case MODE_LINE_STRING
:
21399 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
21401 case MODE_LINE_DISPLAY
:
21402 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
21411 /* Store a mode-line string element in mode_line_string_list.
21413 If STRING is non-null, display that C string. Otherwise, the Lisp
21414 string LISP_STRING is displayed.
21416 FIELD_WIDTH is the minimum number of output glyphs to produce.
21417 If STRING has fewer characters than FIELD_WIDTH, pad to the right
21418 with spaces. FIELD_WIDTH <= 0 means don't pad.
21420 PRECISION is the maximum number of characters to output from
21421 STRING. PRECISION <= 0 means don't truncate the string.
21423 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
21424 properties to the string.
21426 PROPS are the properties to add to the string.
21427 The mode_line_string_face face property is always added to the string.
21431 store_mode_line_string (const char *string
, Lisp_Object lisp_string
, int copy_string
,
21432 int field_width
, int precision
, Lisp_Object props
)
21437 if (string
!= NULL
)
21439 len
= strlen (string
);
21440 if (precision
> 0 && len
> precision
)
21442 lisp_string
= make_string (string
, len
);
21444 props
= mode_line_string_face_prop
;
21445 else if (!NILP (mode_line_string_face
))
21447 Lisp_Object face
= Fplist_get (props
, Qface
);
21448 props
= Fcopy_sequence (props
);
21450 face
= mode_line_string_face
;
21452 face
= list2 (face
, mode_line_string_face
);
21453 props
= Fplist_put (props
, Qface
, face
);
21455 Fadd_text_properties (make_number (0), make_number (len
),
21456 props
, lisp_string
);
21460 len
= XFASTINT (Flength (lisp_string
));
21461 if (precision
> 0 && len
> precision
)
21464 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
21467 if (!NILP (mode_line_string_face
))
21471 props
= Ftext_properties_at (make_number (0), lisp_string
);
21472 face
= Fplist_get (props
, Qface
);
21474 face
= mode_line_string_face
;
21476 face
= list2 (face
, mode_line_string_face
);
21477 props
= list2 (Qface
, face
);
21479 lisp_string
= Fcopy_sequence (lisp_string
);
21482 Fadd_text_properties (make_number (0), make_number (len
),
21483 props
, lisp_string
);
21488 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
21492 if (field_width
> len
)
21494 field_width
-= len
;
21495 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
21497 Fadd_text_properties (make_number (0), make_number (field_width
),
21498 props
, lisp_string
);
21499 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
21507 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
21509 doc
: /* Format a string out of a mode line format specification.
21510 First arg FORMAT specifies the mode line format (see `mode-line-format'
21511 for details) to use.
21513 By default, the format is evaluated for the currently selected window.
21515 Optional second arg FACE specifies the face property to put on all
21516 characters for which no face is specified. The value nil means the
21517 default face. The value t means whatever face the window's mode line
21518 currently uses (either `mode-line' or `mode-line-inactive',
21519 depending on whether the window is the selected window or not).
21520 An integer value means the value string has no text
21523 Optional third and fourth args WINDOW and BUFFER specify the window
21524 and buffer to use as the context for the formatting (defaults
21525 are the selected window and the WINDOW's buffer). */)
21526 (Lisp_Object format
, Lisp_Object face
,
21527 Lisp_Object window
, Lisp_Object buffer
)
21532 struct buffer
*old_buffer
= NULL
;
21534 int no_props
= INTEGERP (face
);
21535 ptrdiff_t count
= SPECPDL_INDEX ();
21537 int string_start
= 0;
21539 w
= decode_any_window (window
);
21540 XSETWINDOW (window
, w
);
21543 buffer
= w
->contents
;
21544 CHECK_BUFFER (buffer
);
21546 /* Make formatting the modeline a non-op when noninteractive, otherwise
21547 there will be problems later caused by a partially initialized frame. */
21548 if (NILP (format
) || noninteractive
)
21549 return empty_unibyte_string
;
21554 face_id
= (NILP (face
) || EQ (face
, Qdefault
)) ? DEFAULT_FACE_ID
21555 : EQ (face
, Qt
) ? (EQ (window
, selected_window
)
21556 ? MODE_LINE_FACE_ID
: MODE_LINE_INACTIVE_FACE_ID
)
21557 : EQ (face
, Qmode_line
) ? MODE_LINE_FACE_ID
21558 : EQ (face
, Qmode_line_inactive
) ? MODE_LINE_INACTIVE_FACE_ID
21559 : EQ (face
, Qheader_line
) ? HEADER_LINE_FACE_ID
21560 : EQ (face
, Qtool_bar
) ? TOOL_BAR_FACE_ID
21563 old_buffer
= current_buffer
;
21565 /* Save things including mode_line_proptrans_alist,
21566 and set that to nil so that we don't alter the outer value. */
21567 record_unwind_protect (unwind_format_mode_line
,
21568 format_mode_line_unwind_data
21569 (XFRAME (WINDOW_FRAME (w
)),
21570 old_buffer
, selected_window
, 1));
21571 mode_line_proptrans_alist
= Qnil
;
21573 Fselect_window (window
, Qt
);
21574 set_buffer_internal_1 (XBUFFER (buffer
));
21576 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
21580 mode_line_target
= MODE_LINE_NOPROP
;
21581 mode_line_string_face_prop
= Qnil
;
21582 mode_line_string_list
= Qnil
;
21583 string_start
= MODE_LINE_NOPROP_LEN (0);
21587 mode_line_target
= MODE_LINE_STRING
;
21588 mode_line_string_list
= Qnil
;
21589 mode_line_string_face
= face
;
21590 mode_line_string_face_prop
21591 = NILP (face
) ? Qnil
: list2 (Qface
, face
);
21594 push_kboard (FRAME_KBOARD (it
.f
));
21595 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
21600 len
= MODE_LINE_NOPROP_LEN (string_start
);
21601 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
21605 mode_line_string_list
= Fnreverse (mode_line_string_list
);
21606 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
21607 empty_unibyte_string
);
21610 unbind_to (count
, Qnil
);
21614 /* Write a null-terminated, right justified decimal representation of
21615 the positive integer D to BUF using a minimal field width WIDTH. */
21618 pint2str (register char *buf
, register int width
, register ptrdiff_t d
)
21620 register char *p
= buf
;
21628 *p
++ = d
% 10 + '0';
21633 for (width
-= (int) (p
- buf
); width
> 0; --width
)
21644 /* Write a null-terminated, right justified decimal and "human
21645 readable" representation of the nonnegative integer D to BUF using
21646 a minimal field width WIDTH. D should be smaller than 999.5e24. */
21648 static const char power_letter
[] =
21662 pint2hrstr (char *buf
, int width
, ptrdiff_t d
)
21664 /* We aim to represent the nonnegative integer D as
21665 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
21666 ptrdiff_t quotient
= d
;
21668 /* -1 means: do not use TENTHS. */
21672 /* Length of QUOTIENT.TENTHS as a string. */
21678 if (quotient
>= 1000)
21680 /* Scale to the appropriate EXPONENT. */
21683 remainder
= quotient
% 1000;
21687 while (quotient
>= 1000);
21689 /* Round to nearest and decide whether to use TENTHS or not. */
21692 tenths
= remainder
/ 100;
21693 if (remainder
% 100 >= 50)
21700 if (quotient
== 10)
21708 if (remainder
>= 500)
21710 if (quotient
< 999)
21721 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
21722 if (tenths
== -1 && quotient
<= 99)
21729 p
= psuffix
= buf
+ max (width
, length
);
21731 /* Print EXPONENT. */
21732 *psuffix
++ = power_letter
[exponent
];
21735 /* Print TENTHS. */
21738 *--p
= '0' + tenths
;
21742 /* Print QUOTIENT. */
21745 int digit
= quotient
% 10;
21746 *--p
= '0' + digit
;
21748 while ((quotient
/= 10) != 0);
21750 /* Print leading spaces. */
21755 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
21756 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
21757 type of CODING_SYSTEM. Return updated pointer into BUF. */
21759 static unsigned char invalid_eol_type
[] = "(*invalid*)";
21762 decode_mode_spec_coding (Lisp_Object coding_system
, register char *buf
, int eol_flag
)
21765 bool multibyte
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
21766 const unsigned char *eol_str
;
21768 /* The EOL conversion we are using. */
21769 Lisp_Object eoltype
;
21771 val
= CODING_SYSTEM_SPEC (coding_system
);
21774 if (!VECTORP (val
)) /* Not yet decided. */
21776 *buf
++ = multibyte
? '-' : ' ';
21778 eoltype
= eol_mnemonic_undecided
;
21779 /* Don't mention EOL conversion if it isn't decided. */
21784 Lisp_Object eolvalue
;
21786 attrs
= AREF (val
, 0);
21787 eolvalue
= AREF (val
, 2);
21790 ? XFASTINT (CODING_ATTR_MNEMONIC (attrs
))
21795 /* The EOL conversion that is normal on this system. */
21797 if (NILP (eolvalue
)) /* Not yet decided. */
21798 eoltype
= eol_mnemonic_undecided
;
21799 else if (VECTORP (eolvalue
)) /* Not yet decided. */
21800 eoltype
= eol_mnemonic_undecided
;
21801 else /* eolvalue is Qunix, Qdos, or Qmac. */
21802 eoltype
= (EQ (eolvalue
, Qunix
)
21803 ? eol_mnemonic_unix
21804 : (EQ (eolvalue
, Qdos
) == 1
21805 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
21811 /* Mention the EOL conversion if it is not the usual one. */
21812 if (STRINGP (eoltype
))
21814 eol_str
= SDATA (eoltype
);
21815 eol_str_len
= SBYTES (eoltype
);
21817 else if (CHARACTERP (eoltype
))
21819 unsigned char *tmp
= alloca (MAX_MULTIBYTE_LENGTH
);
21820 int c
= XFASTINT (eoltype
);
21821 eol_str_len
= CHAR_STRING (c
, tmp
);
21826 eol_str
= invalid_eol_type
;
21827 eol_str_len
= sizeof (invalid_eol_type
) - 1;
21829 memcpy (buf
, eol_str
, eol_str_len
);
21830 buf
+= eol_str_len
;
21836 /* Return a string for the output of a mode line %-spec for window W,
21837 generated by character C. FIELD_WIDTH > 0 means pad the string
21838 returned with spaces to that value. Return a Lisp string in
21839 *STRING if the resulting string is taken from that Lisp string.
21841 Note we operate on the current buffer for most purposes. */
21843 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
21845 static const char *
21846 decode_mode_spec (struct window
*w
, register int c
, int field_width
,
21847 Lisp_Object
*string
)
21850 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21851 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
21852 /* We are going to use f->decode_mode_spec_buffer as the buffer to
21853 produce strings from numerical values, so limit preposterously
21854 large values of FIELD_WIDTH to avoid overrunning the buffer's
21855 end. The size of the buffer is enough for FRAME_MESSAGE_BUF_SIZE
21856 bytes plus the terminating null. */
21857 int width
= min (field_width
, FRAME_MESSAGE_BUF_SIZE (f
));
21858 struct buffer
*b
= current_buffer
;
21866 if (!NILP (BVAR (b
, read_only
)))
21868 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21873 /* This differs from %* only for a modified read-only buffer. */
21874 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21876 if (!NILP (BVAR (b
, read_only
)))
21881 /* This differs from %* in ignoring read-only-ness. */
21882 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21894 if (command_loop_level
> 5)
21896 p
= decode_mode_spec_buf
;
21897 for (i
= 0; i
< command_loop_level
; i
++)
21900 return decode_mode_spec_buf
;
21908 if (command_loop_level
> 5)
21910 p
= decode_mode_spec_buf
;
21911 for (i
= 0; i
< command_loop_level
; i
++)
21914 return decode_mode_spec_buf
;
21921 /* Let lots_of_dashes be a string of infinite length. */
21922 if (mode_line_target
== MODE_LINE_NOPROP
21923 || mode_line_target
== MODE_LINE_STRING
)
21925 if (field_width
<= 0
21926 || field_width
> sizeof (lots_of_dashes
))
21928 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
21929 decode_mode_spec_buf
[i
] = '-';
21930 decode_mode_spec_buf
[i
] = '\0';
21931 return decode_mode_spec_buf
;
21934 return lots_of_dashes
;
21938 obj
= BVAR (b
, name
);
21942 /* %c and %l are ignored in `frame-title-format'.
21943 (In redisplay_internal, the frame title is drawn _before_ the
21944 windows are updated, so the stuff which depends on actual
21945 window contents (such as %l) may fail to render properly, or
21946 even crash emacs.) */
21947 if (mode_line_target
== MODE_LINE_TITLE
)
21951 ptrdiff_t col
= current_column ();
21952 w
->column_number_displayed
= col
;
21953 pint2str (decode_mode_spec_buf
, width
, col
);
21954 return decode_mode_spec_buf
;
21958 #ifndef SYSTEM_MALLOC
21960 if (NILP (Vmemory_full
))
21963 return "!MEM FULL! ";
21970 /* %F displays the frame name. */
21971 if (!NILP (f
->title
))
21972 return SSDATA (f
->title
);
21973 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
21974 return SSDATA (f
->name
);
21978 obj
= BVAR (b
, filename
);
21983 ptrdiff_t size
= ZV
- BEGV
;
21984 pint2str (decode_mode_spec_buf
, width
, size
);
21985 return decode_mode_spec_buf
;
21990 ptrdiff_t size
= ZV
- BEGV
;
21991 pint2hrstr (decode_mode_spec_buf
, width
, size
);
21992 return decode_mode_spec_buf
;
21997 ptrdiff_t startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
21998 ptrdiff_t topline
, nlines
, height
;
22001 /* %c and %l are ignored in `frame-title-format'. */
22002 if (mode_line_target
== MODE_LINE_TITLE
)
22005 startpos
= marker_position (w
->start
);
22006 startpos_byte
= marker_byte_position (w
->start
);
22007 height
= WINDOW_TOTAL_LINES (w
);
22009 /* If we decided that this buffer isn't suitable for line numbers,
22010 don't forget that too fast. */
22011 if (w
->base_line_pos
== -1)
22014 /* If the buffer is very big, don't waste time. */
22015 if (INTEGERP (Vline_number_display_limit
)
22016 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
22018 w
->base_line_pos
= 0;
22019 w
->base_line_number
= 0;
22023 if (w
->base_line_number
> 0
22024 && w
->base_line_pos
> 0
22025 && w
->base_line_pos
<= startpos
)
22027 line
= w
->base_line_number
;
22028 linepos
= w
->base_line_pos
;
22029 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
22034 linepos
= BUF_BEGV (b
);
22035 linepos_byte
= BUF_BEGV_BYTE (b
);
22038 /* Count lines from base line to window start position. */
22039 nlines
= display_count_lines (linepos_byte
,
22043 topline
= nlines
+ line
;
22045 /* Determine a new base line, if the old one is too close
22046 or too far away, or if we did not have one.
22047 "Too close" means it's plausible a scroll-down would
22048 go back past it. */
22049 if (startpos
== BUF_BEGV (b
))
22051 w
->base_line_number
= topline
;
22052 w
->base_line_pos
= BUF_BEGV (b
);
22054 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
22055 || linepos
== BUF_BEGV (b
))
22057 ptrdiff_t limit
= BUF_BEGV (b
);
22058 ptrdiff_t limit_byte
= BUF_BEGV_BYTE (b
);
22059 ptrdiff_t position
;
22060 ptrdiff_t distance
=
22061 (height
* 2 + 30) * line_number_display_limit_width
;
22063 if (startpos
- distance
> limit
)
22065 limit
= startpos
- distance
;
22066 limit_byte
= CHAR_TO_BYTE (limit
);
22069 nlines
= display_count_lines (startpos_byte
,
22071 - (height
* 2 + 30),
22073 /* If we couldn't find the lines we wanted within
22074 line_number_display_limit_width chars per line,
22075 give up on line numbers for this window. */
22076 if (position
== limit_byte
&& limit
== startpos
- distance
)
22078 w
->base_line_pos
= -1;
22079 w
->base_line_number
= 0;
22083 w
->base_line_number
= topline
- nlines
;
22084 w
->base_line_pos
= BYTE_TO_CHAR (position
);
22087 /* Now count lines from the start pos to point. */
22088 nlines
= display_count_lines (startpos_byte
,
22089 PT_BYTE
, PT
, &junk
);
22091 /* Record that we did display the line number. */
22092 line_number_displayed
= 1;
22094 /* Make the string to show. */
22095 pint2str (decode_mode_spec_buf
, width
, topline
+ nlines
);
22096 return decode_mode_spec_buf
;
22099 char* p
= decode_mode_spec_buf
;
22100 int pad
= width
- 2;
22106 return decode_mode_spec_buf
;
22112 obj
= BVAR (b
, mode_name
);
22116 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
22122 ptrdiff_t pos
= marker_position (w
->start
);
22123 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
22125 if (w
->window_end_pos
<= BUF_Z (b
) - BUF_ZV (b
))
22127 if (pos
<= BUF_BEGV (b
))
22132 else if (pos
<= BUF_BEGV (b
))
22136 if (total
> 1000000)
22137 /* Do it differently for a large value, to avoid overflow. */
22138 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
22140 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
22141 /* We can't normally display a 3-digit number,
22142 so get us a 2-digit number that is close. */
22145 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
22146 return decode_mode_spec_buf
;
22150 /* Display percentage of size above the bottom of the screen. */
22153 ptrdiff_t toppos
= marker_position (w
->start
);
22154 ptrdiff_t botpos
= BUF_Z (b
) - w
->window_end_pos
;
22155 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
22157 if (botpos
>= BUF_ZV (b
))
22159 if (toppos
<= BUF_BEGV (b
))
22166 if (total
> 1000000)
22167 /* Do it differently for a large value, to avoid overflow. */
22168 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
22170 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
22171 /* We can't normally display a 3-digit number,
22172 so get us a 2-digit number that is close. */
22175 if (toppos
<= BUF_BEGV (b
))
22176 sprintf (decode_mode_spec_buf
, "Top%2"pD
"d%%", total
);
22178 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
22179 return decode_mode_spec_buf
;
22184 /* status of process */
22185 obj
= Fget_buffer_process (Fcurrent_buffer ());
22187 return "no process";
22189 obj
= Fsymbol_name (Fprocess_status (obj
));
22195 ptrdiff_t count
= inhibit_garbage_collection ();
22196 Lisp_Object val
= call1 (intern ("file-remote-p"),
22197 BVAR (current_buffer
, directory
));
22198 unbind_to (count
, Qnil
);
22207 /* coding-system (not including end-of-line format) */
22209 /* coding-system (including end-of-line type) */
22211 int eol_flag
= (c
== 'Z');
22212 char *p
= decode_mode_spec_buf
;
22214 if (! FRAME_WINDOW_P (f
))
22216 /* No need to mention EOL here--the terminal never needs
22217 to do EOL conversion. */
22218 p
= decode_mode_spec_coding (CODING_ID_NAME
22219 (FRAME_KEYBOARD_CODING (f
)->id
),
22221 p
= decode_mode_spec_coding (CODING_ID_NAME
22222 (FRAME_TERMINAL_CODING (f
)->id
),
22225 p
= decode_mode_spec_coding (BVAR (b
, buffer_file_coding_system
),
22228 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
22229 #ifdef subprocesses
22230 obj
= Fget_buffer_process (Fcurrent_buffer ());
22231 if (PROCESSP (obj
))
22233 p
= decode_mode_spec_coding
22234 (XPROCESS (obj
)->decode_coding_system
, p
, eol_flag
);
22235 p
= decode_mode_spec_coding
22236 (XPROCESS (obj
)->encode_coding_system
, p
, eol_flag
);
22238 #endif /* subprocesses */
22241 return decode_mode_spec_buf
;
22248 return SSDATA (obj
);
22255 /* Count up to COUNT lines starting from START_BYTE. COUNT negative
22256 means count lines back from START_BYTE. But don't go beyond
22257 LIMIT_BYTE. Return the number of lines thus found (always
22260 Set *BYTE_POS_PTR to the byte position where we stopped. This is
22261 either the position COUNT lines after/before START_BYTE, if we
22262 found COUNT lines, or LIMIT_BYTE if we hit the limit before finding
22266 display_count_lines (ptrdiff_t start_byte
,
22267 ptrdiff_t limit_byte
, ptrdiff_t count
,
22268 ptrdiff_t *byte_pos_ptr
)
22270 register unsigned char *cursor
;
22271 unsigned char *base
;
22273 register ptrdiff_t ceiling
;
22274 register unsigned char *ceiling_addr
;
22275 ptrdiff_t orig_count
= count
;
22277 /* If we are not in selective display mode,
22278 check only for newlines. */
22279 int selective_display
= (!NILP (BVAR (current_buffer
, selective_display
))
22280 && !INTEGERP (BVAR (current_buffer
, selective_display
)));
22284 while (start_byte
< limit_byte
)
22286 ceiling
= BUFFER_CEILING_OF (start_byte
);
22287 ceiling
= min (limit_byte
- 1, ceiling
);
22288 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
22289 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
22293 if (selective_display
)
22295 while (*cursor
!= '\n' && *cursor
!= 015
22296 && ++cursor
!= ceiling_addr
)
22298 if (cursor
== ceiling_addr
)
22303 cursor
= memchr (cursor
, '\n', ceiling_addr
- cursor
);
22312 start_byte
+= cursor
- base
;
22313 *byte_pos_ptr
= start_byte
;
22317 while (cursor
< ceiling_addr
);
22319 start_byte
+= ceiling_addr
- base
;
22324 while (start_byte
> limit_byte
)
22326 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
22327 ceiling
= max (limit_byte
, ceiling
);
22328 ceiling_addr
= BYTE_POS_ADDR (ceiling
);
22329 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
22332 if (selective_display
)
22334 while (--cursor
>= ceiling_addr
22335 && *cursor
!= '\n' && *cursor
!= 015)
22337 if (cursor
< ceiling_addr
)
22342 cursor
= memrchr (ceiling_addr
, '\n', cursor
- ceiling_addr
);
22349 start_byte
+= cursor
- base
+ 1;
22350 *byte_pos_ptr
= start_byte
;
22351 /* When scanning backwards, we should
22352 not count the newline posterior to which we stop. */
22353 return - orig_count
- 1;
22356 start_byte
+= ceiling_addr
- base
;
22360 *byte_pos_ptr
= limit_byte
;
22363 return - orig_count
+ count
;
22364 return orig_count
- count
;
22370 /***********************************************************************
22372 ***********************************************************************/
22374 /* Display a NUL-terminated string, starting with index START.
22376 If STRING is non-null, display that C string. Otherwise, the Lisp
22377 string LISP_STRING is displayed. There's a case that STRING is
22378 non-null and LISP_STRING is not nil. It means STRING is a string
22379 data of LISP_STRING. In that case, we display LISP_STRING while
22380 ignoring its text properties.
22382 If FACE_STRING is not nil, FACE_STRING_POS is a position in
22383 FACE_STRING. Display STRING or LISP_STRING with the face at
22384 FACE_STRING_POS in FACE_STRING:
22386 Display the string in the environment given by IT, but use the
22387 standard display table, temporarily.
22389 FIELD_WIDTH is the minimum number of output glyphs to produce.
22390 If STRING has fewer characters than FIELD_WIDTH, pad to the right
22391 with spaces. If STRING has more characters, more than FIELD_WIDTH
22392 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
22394 PRECISION is the maximum number of characters to output from
22395 STRING. PRECISION < 0 means don't truncate the string.
22397 This is roughly equivalent to printf format specifiers:
22399 FIELD_WIDTH PRECISION PRINTF
22400 ----------------------------------------
22406 MULTIBYTE zero means do not display multibyte chars, > 0 means do
22407 display them, and < 0 means obey the current buffer's value of
22408 enable_multibyte_characters.
22410 Value is the number of columns displayed. */
22413 display_string (const char *string
, Lisp_Object lisp_string
, Lisp_Object face_string
,
22414 ptrdiff_t face_string_pos
, ptrdiff_t start
, struct it
*it
,
22415 int field_width
, int precision
, int max_x
, int multibyte
)
22417 int hpos_at_start
= it
->hpos
;
22418 int saved_face_id
= it
->face_id
;
22419 struct glyph_row
*row
= it
->glyph_row
;
22420 ptrdiff_t it_charpos
;
22422 /* Initialize the iterator IT for iteration over STRING beginning
22423 with index START. */
22424 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
22425 precision
, field_width
, multibyte
);
22426 if (string
&& STRINGP (lisp_string
))
22427 /* LISP_STRING is the one returned by decode_mode_spec. We should
22428 ignore its text properties. */
22429 it
->stop_charpos
= it
->end_charpos
;
22431 /* If displaying STRING, set up the face of the iterator from
22432 FACE_STRING, if that's given. */
22433 if (STRINGP (face_string
))
22439 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
22440 0, it
->region_beg_charpos
,
22441 it
->region_end_charpos
,
22442 &endptr
, it
->base_face_id
, 0);
22443 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22444 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
22447 /* Set max_x to the maximum allowed X position. Don't let it go
22448 beyond the right edge of the window. */
22450 max_x
= it
->last_visible_x
;
22452 max_x
= min (max_x
, it
->last_visible_x
);
22454 /* Skip over display elements that are not visible. because IT->w is
22456 if (it
->current_x
< it
->first_visible_x
)
22457 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
22458 MOVE_TO_POS
| MOVE_TO_X
);
22460 row
->ascent
= it
->max_ascent
;
22461 row
->height
= it
->max_ascent
+ it
->max_descent
;
22462 row
->phys_ascent
= it
->max_phys_ascent
;
22463 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
22464 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
22466 if (STRINGP (it
->string
))
22467 it_charpos
= IT_STRING_CHARPOS (*it
);
22469 it_charpos
= IT_CHARPOS (*it
);
22471 /* This condition is for the case that we are called with current_x
22472 past last_visible_x. */
22473 while (it
->current_x
< max_x
)
22475 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
22477 /* Get the next display element. */
22478 if (!get_next_display_element (it
))
22481 /* Produce glyphs. */
22482 x_before
= it
->current_x
;
22483 n_glyphs_before
= row
->used
[TEXT_AREA
];
22484 PRODUCE_GLYPHS (it
);
22486 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
22489 while (i
< nglyphs
)
22491 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
22493 if (it
->line_wrap
!= TRUNCATE
22494 && x
+ glyph
->pixel_width
> max_x
)
22496 /* End of continued line or max_x reached. */
22497 if (CHAR_GLYPH_PADDING_P (*glyph
))
22499 /* A wide character is unbreakable. */
22500 if (row
->reversed_p
)
22501 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
22502 - n_glyphs_before
);
22503 row
->used
[TEXT_AREA
] = n_glyphs_before
;
22504 it
->current_x
= x_before
;
22508 if (row
->reversed_p
)
22509 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
22510 - (n_glyphs_before
+ i
));
22511 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
22516 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
22518 /* Glyph is at least partially visible. */
22520 if (x
< it
->first_visible_x
)
22521 row
->x
= x
- it
->first_visible_x
;
22525 /* Glyph is off the left margin of the display area.
22526 Should not happen. */
22530 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
22531 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
22532 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
22533 row
->phys_height
= max (row
->phys_height
,
22534 it
->max_phys_ascent
+ it
->max_phys_descent
);
22535 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
22536 it
->max_extra_line_spacing
);
22537 x
+= glyph
->pixel_width
;
22541 /* Stop if max_x reached. */
22545 /* Stop at line ends. */
22546 if (ITERATOR_AT_END_OF_LINE_P (it
))
22548 it
->continuation_lines_width
= 0;
22552 set_iterator_to_next (it
, 1);
22553 if (STRINGP (it
->string
))
22554 it_charpos
= IT_STRING_CHARPOS (*it
);
22556 it_charpos
= IT_CHARPOS (*it
);
22558 /* Stop if truncating at the right edge. */
22559 if (it
->line_wrap
== TRUNCATE
22560 && it
->current_x
>= it
->last_visible_x
)
22562 /* Add truncation mark, but don't do it if the line is
22563 truncated at a padding space. */
22564 if (it_charpos
< it
->string_nchars
)
22566 if (!FRAME_WINDOW_P (it
->f
))
22570 if (it
->current_x
> it
->last_visible_x
)
22572 if (!row
->reversed_p
)
22574 for (ii
= row
->used
[TEXT_AREA
] - 1; ii
> 0; --ii
)
22575 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
22580 for (ii
= 0; ii
< row
->used
[TEXT_AREA
]; ii
++)
22581 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
22583 unproduce_glyphs (it
, ii
+ 1);
22584 ii
= row
->used
[TEXT_AREA
] - (ii
+ 1);
22586 for (n
= row
->used
[TEXT_AREA
]; ii
< n
; ++ii
)
22588 row
->used
[TEXT_AREA
] = ii
;
22589 produce_special_glyphs (it
, IT_TRUNCATION
);
22592 produce_special_glyphs (it
, IT_TRUNCATION
);
22594 row
->truncated_on_right_p
= 1;
22600 /* Maybe insert a truncation at the left. */
22601 if (it
->first_visible_x
22604 if (!FRAME_WINDOW_P (it
->f
)
22605 || (row
->reversed_p
22606 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
22607 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
22608 insert_left_trunc_glyphs (it
);
22609 row
->truncated_on_left_p
= 1;
22612 it
->face_id
= saved_face_id
;
22614 /* Value is number of columns displayed. */
22615 return it
->hpos
- hpos_at_start
;
22620 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
22621 appears as an element of LIST or as the car of an element of LIST.
22622 If PROPVAL is a list, compare each element against LIST in that
22623 way, and return 1/2 if any element of PROPVAL is found in LIST.
22624 Otherwise return 0. This function cannot quit.
22625 The return value is 2 if the text is invisible but with an ellipsis
22626 and 1 if it's invisible and without an ellipsis. */
22629 invisible_p (register Lisp_Object propval
, Lisp_Object list
)
22631 register Lisp_Object tail
, proptail
;
22633 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
22635 register Lisp_Object tem
;
22637 if (EQ (propval
, tem
))
22639 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
22640 return NILP (XCDR (tem
)) ? 1 : 2;
22643 if (CONSP (propval
))
22645 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
22647 Lisp_Object propelt
;
22648 propelt
= XCAR (proptail
);
22649 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
22651 register Lisp_Object tem
;
22653 if (EQ (propelt
, tem
))
22655 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
22656 return NILP (XCDR (tem
)) ? 1 : 2;
22664 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
22665 doc
: /* Non-nil if the property makes the text invisible.
22666 POS-OR-PROP can be a marker or number, in which case it is taken to be
22667 a position in the current buffer and the value of the `invisible' property
22668 is checked; or it can be some other value, which is then presumed to be the
22669 value of the `invisible' property of the text of interest.
22670 The non-nil value returned can be t for truly invisible text or something
22671 else if the text is replaced by an ellipsis. */)
22672 (Lisp_Object pos_or_prop
)
22675 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
22676 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
22678 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
22679 return (invis
== 0 ? Qnil
22681 : make_number (invis
));
22684 /* Calculate a width or height in pixels from a specification using
22685 the following elements:
22688 NUM - a (fractional) multiple of the default font width/height
22689 (NUM) - specifies exactly NUM pixels
22690 UNIT - a fixed number of pixels, see below.
22691 ELEMENT - size of a display element in pixels, see below.
22692 (NUM . SPEC) - equals NUM * SPEC
22693 (+ SPEC SPEC ...) - add pixel values
22694 (- SPEC SPEC ...) - subtract pixel values
22695 (- SPEC) - negate pixel value
22698 INT or FLOAT - a number constant
22699 SYMBOL - use symbol's (buffer local) variable binding.
22702 in - pixels per inch *)
22703 mm - pixels per 1/1000 meter *)
22704 cm - pixels per 1/100 meter *)
22705 width - width of current font in pixels.
22706 height - height of current font in pixels.
22708 *) using the ratio(s) defined in display-pixels-per-inch.
22712 left-fringe - left fringe width in pixels
22713 right-fringe - right fringe width in pixels
22715 left-margin - left margin width in pixels
22716 right-margin - right margin width in pixels
22718 scroll-bar - scroll-bar area width in pixels
22722 Pixels corresponding to 5 inches:
22725 Total width of non-text areas on left side of window (if scroll-bar is on left):
22726 '(space :width (+ left-fringe left-margin scroll-bar))
22728 Align to first text column (in header line):
22729 '(space :align-to 0)
22731 Align to middle of text area minus half the width of variable `my-image'
22732 containing a loaded image:
22733 '(space :align-to (0.5 . (- text my-image)))
22735 Width of left margin minus width of 1 character in the default font:
22736 '(space :width (- left-margin 1))
22738 Width of left margin minus width of 2 characters in the current font:
22739 '(space :width (- left-margin (2 . width)))
22741 Center 1 character over left-margin (in header line):
22742 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
22744 Different ways to express width of left fringe plus left margin minus one pixel:
22745 '(space :width (- (+ left-fringe left-margin) (1)))
22746 '(space :width (+ left-fringe left-margin (- (1))))
22747 '(space :width (+ left-fringe left-margin (-1)))
22752 calc_pixel_width_or_height (double *res
, struct it
*it
, Lisp_Object prop
,
22753 struct font
*font
, int width_p
, int *align_to
)
22757 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
22758 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
22761 return OK_PIXELS (0);
22763 eassert (FRAME_LIVE_P (it
->f
));
22765 if (SYMBOLP (prop
))
22767 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
22769 char *unit
= SSDATA (SYMBOL_NAME (prop
));
22771 if (unit
[0] == 'i' && unit
[1] == 'n')
22773 else if (unit
[0] == 'm' && unit
[1] == 'm')
22775 else if (unit
[0] == 'c' && unit
[1] == 'm')
22781 double ppi
= (width_p
? FRAME_RES_X (it
->f
)
22782 : FRAME_RES_Y (it
->f
));
22785 return OK_PIXELS (ppi
/ pixels
);
22790 #ifdef HAVE_WINDOW_SYSTEM
22791 if (EQ (prop
, Qheight
))
22792 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
22793 if (EQ (prop
, Qwidth
))
22794 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
22796 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
22797 return OK_PIXELS (1);
22800 if (EQ (prop
, Qtext
))
22801 return OK_PIXELS (width_p
22802 ? window_box_width (it
->w
, TEXT_AREA
)
22803 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
22805 if (align_to
&& *align_to
< 0)
22808 if (EQ (prop
, Qleft
))
22809 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
22810 if (EQ (prop
, Qright
))
22811 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
22812 if (EQ (prop
, Qcenter
))
22813 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
22814 + window_box_width (it
->w
, TEXT_AREA
) / 2);
22815 if (EQ (prop
, Qleft_fringe
))
22816 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22817 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
22818 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
22819 if (EQ (prop
, Qright_fringe
))
22820 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22821 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
22822 : window_box_right_offset (it
->w
, TEXT_AREA
));
22823 if (EQ (prop
, Qleft_margin
))
22824 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
22825 if (EQ (prop
, Qright_margin
))
22826 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
22827 if (EQ (prop
, Qscroll_bar
))
22828 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
22830 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
22831 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22832 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
22837 if (EQ (prop
, Qleft_fringe
))
22838 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
22839 if (EQ (prop
, Qright_fringe
))
22840 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
22841 if (EQ (prop
, Qleft_margin
))
22842 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
22843 if (EQ (prop
, Qright_margin
))
22844 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
22845 if (EQ (prop
, Qscroll_bar
))
22846 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
22849 prop
= buffer_local_value_1 (prop
, it
->w
->contents
);
22850 if (EQ (prop
, Qunbound
))
22854 if (INTEGERP (prop
) || FLOATP (prop
))
22856 int base_unit
= (width_p
22857 ? FRAME_COLUMN_WIDTH (it
->f
)
22858 : FRAME_LINE_HEIGHT (it
->f
));
22859 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
22864 Lisp_Object car
= XCAR (prop
);
22865 Lisp_Object cdr
= XCDR (prop
);
22869 #ifdef HAVE_WINDOW_SYSTEM
22870 if (FRAME_WINDOW_P (it
->f
)
22871 && valid_image_p (prop
))
22873 ptrdiff_t id
= lookup_image (it
->f
, prop
);
22874 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
22876 return OK_PIXELS (width_p
? img
->width
: img
->height
);
22878 #ifdef HAVE_XWIDGETS
22879 if (FRAME_WINDOW_P (it
->f
) && valid_xwidget_spec_p (prop
))
22881 printf("calc_pixel_width_or_height: return dummy size FIXME\n");
22882 return OK_PIXELS (width_p
? 100 : 100);
22886 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
22892 while (CONSP (cdr
))
22894 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
22895 font
, width_p
, align_to
))
22898 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
22903 if (EQ (car
, Qminus
))
22905 return OK_PIXELS (pixels
);
22908 car
= buffer_local_value_1 (car
, it
->w
->contents
);
22909 if (EQ (car
, Qunbound
))
22913 if (INTEGERP (car
) || FLOATP (car
))
22916 pixels
= XFLOATINT (car
);
22918 return OK_PIXELS (pixels
);
22919 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
22920 font
, width_p
, align_to
))
22921 return OK_PIXELS (pixels
* fact
);
22932 /***********************************************************************
22934 ***********************************************************************/
22936 #ifdef HAVE_WINDOW_SYSTEM
22941 dump_glyph_string (struct glyph_string
*s
)
22943 fprintf (stderr
, "glyph string\n");
22944 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
22945 s
->x
, s
->y
, s
->width
, s
->height
);
22946 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
22947 fprintf (stderr
, " hl = %d\n", s
->hl
);
22948 fprintf (stderr
, " left overhang = %d, right = %d\n",
22949 s
->left_overhang
, s
->right_overhang
);
22950 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
22951 fprintf (stderr
, " extends to end of line = %d\n",
22952 s
->extends_to_end_of_line_p
);
22953 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
22954 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
22957 #endif /* GLYPH_DEBUG */
22959 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
22960 of XChar2b structures for S; it can't be allocated in
22961 init_glyph_string because it must be allocated via `alloca'. W
22962 is the window on which S is drawn. ROW and AREA are the glyph row
22963 and area within the row from which S is constructed. START is the
22964 index of the first glyph structure covered by S. HL is a
22965 face-override for drawing S. */
22968 #define OPTIONAL_HDC(hdc) HDC hdc,
22969 #define DECLARE_HDC(hdc) HDC hdc;
22970 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
22971 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
22974 #ifndef OPTIONAL_HDC
22975 #define OPTIONAL_HDC(hdc)
22976 #define DECLARE_HDC(hdc)
22977 #define ALLOCATE_HDC(hdc, f)
22978 #define RELEASE_HDC(hdc, f)
22982 init_glyph_string (struct glyph_string
*s
,
22984 XChar2b
*char2b
, struct window
*w
, struct glyph_row
*row
,
22985 enum glyph_row_area area
, int start
, enum draw_glyphs_face hl
)
22987 memset (s
, 0, sizeof *s
);
22989 s
->f
= XFRAME (w
->frame
);
22993 s
->display
= FRAME_X_DISPLAY (s
->f
);
22994 s
->window
= FRAME_X_WINDOW (s
->f
);
22995 s
->char2b
= char2b
;
22999 s
->first_glyph
= row
->glyphs
[area
] + start
;
23000 s
->height
= row
->height
;
23001 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
23002 s
->ybase
= s
->y
+ row
->ascent
;
23006 /* Append the list of glyph strings with head H and tail T to the list
23007 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
23010 append_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
23011 struct glyph_string
*h
, struct glyph_string
*t
)
23025 /* Prepend the list of glyph strings with head H and tail T to the
23026 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
23030 prepend_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
23031 struct glyph_string
*h
, struct glyph_string
*t
)
23045 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
23046 Set *HEAD and *TAIL to the resulting list. */
23049 append_glyph_string (struct glyph_string
**head
, struct glyph_string
**tail
,
23050 struct glyph_string
*s
)
23052 s
->next
= s
->prev
= NULL
;
23053 append_glyph_string_lists (head
, tail
, s
, s
);
23057 /* Get face and two-byte form of character C in face FACE_ID on frame F.
23058 The encoding of C is returned in *CHAR2B. DISPLAY_P non-zero means
23059 make sure that X resources for the face returned are allocated.
23060 Value is a pointer to a realized face that is ready for display if
23061 DISPLAY_P is non-zero. */
23063 static struct face
*
23064 get_char_face_and_encoding (struct frame
*f
, int c
, int face_id
,
23065 XChar2b
*char2b
, int display_p
)
23067 struct face
*face
= FACE_FROM_ID (f
, face_id
);
23072 code
= face
->font
->driver
->encode_char (face
->font
, c
);
23074 if (code
== FONT_INVALID_CODE
)
23077 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
23079 /* Make sure X resources of the face are allocated. */
23080 #ifdef HAVE_X_WINDOWS
23084 eassert (face
!= NULL
);
23085 PREPARE_FACE_FOR_DISPLAY (f
, face
);
23092 /* Get face and two-byte form of character glyph GLYPH on frame F.
23093 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
23094 a pointer to a realized face that is ready for display. */
23096 static struct face
*
23097 get_glyph_face_and_encoding (struct frame
*f
, struct glyph
*glyph
,
23098 XChar2b
*char2b
, int *two_byte_p
)
23103 eassert (glyph
->type
== CHAR_GLYPH
);
23104 face
= FACE_FROM_ID (f
, glyph
->face_id
);
23106 /* Make sure X resources of the face are allocated. */
23107 eassert (face
!= NULL
);
23108 PREPARE_FACE_FOR_DISPLAY (f
, face
);
23115 if (CHAR_BYTE8_P (glyph
->u
.ch
))
23116 code
= CHAR_TO_BYTE8 (glyph
->u
.ch
);
23118 code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
23120 if (code
== FONT_INVALID_CODE
)
23124 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
23129 /* Get glyph code of character C in FONT in the two-byte form CHAR2B.
23130 Return 1 if FONT has a glyph for C, otherwise return 0. */
23133 get_char_glyph_code (int c
, struct font
*font
, XChar2b
*char2b
)
23137 if (CHAR_BYTE8_P (c
))
23138 code
= CHAR_TO_BYTE8 (c
);
23140 code
= font
->driver
->encode_char (font
, c
);
23142 if (code
== FONT_INVALID_CODE
)
23144 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
23149 /* Fill glyph string S with composition components specified by S->cmp.
23151 BASE_FACE is the base face of the composition.
23152 S->cmp_from is the index of the first component for S.
23154 OVERLAPS non-zero means S should draw the foreground only, and use
23155 its physical height for clipping. See also draw_glyphs.
23157 Value is the index of a component not in S. */
23160 fill_composite_glyph_string (struct glyph_string
*s
, struct face
*base_face
,
23164 /* For all glyphs of this composition, starting at the offset
23165 S->cmp_from, until we reach the end of the definition or encounter a
23166 glyph that requires the different face, add it to S. */
23171 s
->for_overlaps
= overlaps
;
23174 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
23176 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
23178 /* TAB in a composition means display glyphs with padding space
23179 on the left or right. */
23182 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
23185 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
23192 s
->font
= s
->face
->font
;
23194 else if (s
->face
!= face
)
23202 if (s
->face
== NULL
)
23204 s
->face
= base_face
->ascii_face
;
23205 s
->font
= s
->face
->font
;
23208 /* All glyph strings for the same composition has the same width,
23209 i.e. the width set for the first component of the composition. */
23210 s
->width
= s
->first_glyph
->pixel_width
;
23212 /* If the specified font could not be loaded, use the frame's
23213 default font, but record the fact that we couldn't load it in
23214 the glyph string so that we can draw rectangles for the
23215 characters of the glyph string. */
23216 if (s
->font
== NULL
)
23218 s
->font_not_found_p
= 1;
23219 s
->font
= FRAME_FONT (s
->f
);
23222 /* Adjust base line for subscript/superscript text. */
23223 s
->ybase
+= s
->first_glyph
->voffset
;
23225 /* This glyph string must always be drawn with 16-bit functions. */
23232 fill_gstring_glyph_string (struct glyph_string
*s
, int face_id
,
23233 int start
, int end
, int overlaps
)
23235 struct glyph
*glyph
, *last
;
23236 Lisp_Object lgstring
;
23239 s
->for_overlaps
= overlaps
;
23240 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23241 last
= s
->row
->glyphs
[s
->area
] + end
;
23242 s
->cmp_id
= glyph
->u
.cmp
.id
;
23243 s
->cmp_from
= glyph
->slice
.cmp
.from
;
23244 s
->cmp_to
= glyph
->slice
.cmp
.to
+ 1;
23245 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
23246 lgstring
= composition_gstring_from_id (s
->cmp_id
);
23247 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
23249 while (glyph
< last
23250 && glyph
->u
.cmp
.automatic
23251 && glyph
->u
.cmp
.id
== s
->cmp_id
23252 && s
->cmp_to
== glyph
->slice
.cmp
.from
)
23253 s
->cmp_to
= (glyph
++)->slice
.cmp
.to
+ 1;
23255 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
23257 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
23258 unsigned code
= LGLYPH_CODE (lglyph
);
23260 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
23262 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
23263 return glyph
- s
->row
->glyphs
[s
->area
];
23267 /* Fill glyph string S from a sequence glyphs for glyphless characters.
23268 See the comment of fill_glyph_string for arguments.
23269 Value is the index of the first glyph not in S. */
23273 fill_glyphless_glyph_string (struct glyph_string
*s
, int face_id
,
23274 int start
, int end
, int overlaps
)
23276 struct glyph
*glyph
, *last
;
23279 eassert (s
->first_glyph
->type
== GLYPHLESS_GLYPH
);
23280 s
->for_overlaps
= overlaps
;
23281 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23282 last
= s
->row
->glyphs
[s
->area
] + end
;
23283 voffset
= glyph
->voffset
;
23284 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
23285 s
->font
= s
->face
->font
? s
->face
->font
: FRAME_FONT (s
->f
);
23287 s
->width
= glyph
->pixel_width
;
23289 while (glyph
< last
23290 && glyph
->type
== GLYPHLESS_GLYPH
23291 && glyph
->voffset
== voffset
23292 && glyph
->face_id
== face_id
)
23295 s
->width
+= glyph
->pixel_width
;
23298 s
->ybase
+= voffset
;
23299 return glyph
- s
->row
->glyphs
[s
->area
];
23303 /* Fill glyph string S from a sequence of character glyphs.
23305 FACE_ID is the face id of the string. START is the index of the
23306 first glyph to consider, END is the index of the last + 1.
23307 OVERLAPS non-zero means S should draw the foreground only, and use
23308 its physical height for clipping. See also draw_glyphs.
23310 Value is the index of the first glyph not in S. */
23313 fill_glyph_string (struct glyph_string
*s
, int face_id
,
23314 int start
, int end
, int overlaps
)
23316 struct glyph
*glyph
, *last
;
23318 int glyph_not_available_p
;
23320 eassert (s
->f
== XFRAME (s
->w
->frame
));
23321 eassert (s
->nchars
== 0);
23322 eassert (start
>= 0 && end
> start
);
23324 s
->for_overlaps
= overlaps
;
23325 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23326 last
= s
->row
->glyphs
[s
->area
] + end
;
23327 voffset
= glyph
->voffset
;
23328 s
->padding_p
= glyph
->padding_p
;
23329 glyph_not_available_p
= glyph
->glyph_not_available_p
;
23331 while (glyph
< last
23332 && glyph
->type
== CHAR_GLYPH
23333 && glyph
->voffset
== voffset
23334 /* Same face id implies same font, nowadays. */
23335 && glyph
->face_id
== face_id
23336 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
23340 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
23341 s
->char2b
+ s
->nchars
,
23343 s
->two_byte_p
= two_byte_p
;
23345 eassert (s
->nchars
<= end
- start
);
23346 s
->width
+= glyph
->pixel_width
;
23347 if (glyph
++->padding_p
!= s
->padding_p
)
23351 s
->font
= s
->face
->font
;
23353 /* If the specified font could not be loaded, use the frame's font,
23354 but record the fact that we couldn't load it in
23355 S->font_not_found_p so that we can draw rectangles for the
23356 characters of the glyph string. */
23357 if (s
->font
== NULL
|| glyph_not_available_p
)
23359 s
->font_not_found_p
= 1;
23360 s
->font
= FRAME_FONT (s
->f
);
23363 /* Adjust base line for subscript/superscript text. */
23364 s
->ybase
+= voffset
;
23366 eassert (s
->face
&& s
->face
->gc
);
23367 return glyph
- s
->row
->glyphs
[s
->area
];
23371 /* Fill glyph string S from image glyph S->first_glyph. */
23374 fill_image_glyph_string (struct glyph_string
*s
)
23376 eassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
23377 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
23379 s
->slice
= s
->first_glyph
->slice
.img
;
23380 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
23381 s
->font
= s
->face
->font
;
23382 s
->width
= s
->first_glyph
->pixel_width
;
23384 /* Adjust base line for subscript/superscript text. */
23385 s
->ybase
+= s
->first_glyph
->voffset
;
23388 #ifdef HAVE_XWIDGETS
23390 fill_xwidget_glyph_string (struct glyph_string
*s
)
23392 eassert (s
->first_glyph
->type
== XWIDGET_GLYPH
);
23393 printf("fill_xwidget_glyph_string: width:%d \n",s
->first_glyph
->pixel_width
);
23394 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
23395 s
->font
= s
->face
->font
;
23396 s
->width
= s
->first_glyph
->pixel_width
;
23397 s
->ybase
+= s
->first_glyph
->voffset
;
23398 s
->xwidget
= s
->first_glyph
->u
.xwidget
;
23399 //assert_valid_xwidget_id ( s->xwidget, "fill_xwidget_glyph_string");
23402 /* Fill glyph string S from a sequence of stretch glyphs.
23404 START is the index of the first glyph to consider,
23405 END is the index of the last + 1.
23407 Value is the index of the first glyph not in S. */
23410 fill_stretch_glyph_string (struct glyph_string
*s
, int start
, int end
)
23412 struct glyph
*glyph
, *last
;
23413 int voffset
, face_id
;
23415 eassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
23417 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23418 last
= s
->row
->glyphs
[s
->area
] + end
;
23419 face_id
= glyph
->face_id
;
23420 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
23421 s
->font
= s
->face
->font
;
23422 s
->width
= glyph
->pixel_width
;
23424 voffset
= glyph
->voffset
;
23428 && glyph
->type
== STRETCH_GLYPH
23429 && glyph
->voffset
== voffset
23430 && glyph
->face_id
== face_id
);
23432 s
->width
+= glyph
->pixel_width
;
23434 /* Adjust base line for subscript/superscript text. */
23435 s
->ybase
+= voffset
;
23437 /* The case that face->gc == 0 is handled when drawing the glyph
23438 string by calling PREPARE_FACE_FOR_DISPLAY. */
23440 return glyph
- s
->row
->glyphs
[s
->area
];
23443 static struct font_metrics
*
23444 get_per_char_metric (struct font
*font
, XChar2b
*char2b
)
23446 static struct font_metrics metrics
;
23451 code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
23452 if (code
== FONT_INVALID_CODE
)
23454 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
23459 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
23460 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
23461 assumed to be zero. */
23464 x_get_glyph_overhangs (struct glyph
*glyph
, struct frame
*f
, int *left
, int *right
)
23466 *left
= *right
= 0;
23468 if (glyph
->type
== CHAR_GLYPH
)
23472 struct font_metrics
*pcm
;
23474 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
23475 if (face
->font
&& (pcm
= get_per_char_metric (face
->font
, &char2b
)))
23477 if (pcm
->rbearing
> pcm
->width
)
23478 *right
= pcm
->rbearing
- pcm
->width
;
23479 if (pcm
->lbearing
< 0)
23480 *left
= -pcm
->lbearing
;
23483 else if (glyph
->type
== COMPOSITE_GLYPH
)
23485 if (! glyph
->u
.cmp
.automatic
)
23487 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
23489 if (cmp
->rbearing
> cmp
->pixel_width
)
23490 *right
= cmp
->rbearing
- cmp
->pixel_width
;
23491 if (cmp
->lbearing
< 0)
23492 *left
= - cmp
->lbearing
;
23496 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
23497 struct font_metrics metrics
;
23499 composition_gstring_width (gstring
, glyph
->slice
.cmp
.from
,
23500 glyph
->slice
.cmp
.to
+ 1, &metrics
);
23501 if (metrics
.rbearing
> metrics
.width
)
23502 *right
= metrics
.rbearing
- metrics
.width
;
23503 if (metrics
.lbearing
< 0)
23504 *left
= - metrics
.lbearing
;
23510 /* Return the index of the first glyph preceding glyph string S that
23511 is overwritten by S because of S's left overhang. Value is -1
23512 if no glyphs are overwritten. */
23515 left_overwritten (struct glyph_string
*s
)
23519 if (s
->left_overhang
)
23522 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23523 int first
= s
->first_glyph
- glyphs
;
23525 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
23526 x
-= glyphs
[i
].pixel_width
;
23537 /* Return the index of the first glyph preceding glyph string S that
23538 is overwriting S because of its right overhang. Value is -1 if no
23539 glyph in front of S overwrites S. */
23542 left_overwriting (struct glyph_string
*s
)
23545 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23546 int first
= s
->first_glyph
- glyphs
;
23550 for (i
= first
- 1; i
>= 0; --i
)
23553 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
23556 x
-= glyphs
[i
].pixel_width
;
23563 /* Return the index of the last glyph following glyph string S that is
23564 overwritten by S because of S's right overhang. Value is -1 if
23565 no such glyph is found. */
23568 right_overwritten (struct glyph_string
*s
)
23572 if (s
->right_overhang
)
23575 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23576 int first
= (s
->first_glyph
- glyphs
23577 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
23578 int end
= s
->row
->used
[s
->area
];
23580 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
23581 x
+= glyphs
[i
].pixel_width
;
23590 /* Return the index of the last glyph following glyph string S that
23591 overwrites S because of its left overhang. Value is negative
23592 if no such glyph is found. */
23595 right_overwriting (struct glyph_string
*s
)
23598 int end
= s
->row
->used
[s
->area
];
23599 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23600 int first
= (s
->first_glyph
- glyphs
23601 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
23605 for (i
= first
; i
< end
; ++i
)
23608 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
23611 x
+= glyphs
[i
].pixel_width
;
23618 /* Set background width of glyph string S. START is the index of the
23619 first glyph following S. LAST_X is the right-most x-position + 1
23620 in the drawing area. */
23623 set_glyph_string_background_width (struct glyph_string
*s
, int start
, int last_x
)
23625 /* If the face of this glyph string has to be drawn to the end of
23626 the drawing area, set S->extends_to_end_of_line_p. */
23628 if (start
== s
->row
->used
[s
->area
]
23629 && s
->area
== TEXT_AREA
23630 && ((s
->row
->fill_line_p
23631 && (s
->hl
== DRAW_NORMAL_TEXT
23632 || s
->hl
== DRAW_IMAGE_RAISED
23633 || s
->hl
== DRAW_IMAGE_SUNKEN
))
23634 || s
->hl
== DRAW_MOUSE_FACE
))
23635 s
->extends_to_end_of_line_p
= 1;
23637 /* If S extends its face to the end of the line, set its
23638 background_width to the distance to the right edge of the drawing
23640 if (s
->extends_to_end_of_line_p
)
23641 s
->background_width
= last_x
- s
->x
+ 1;
23643 s
->background_width
= s
->width
;
23647 /* Compute overhangs and x-positions for glyph string S and its
23648 predecessors, or successors. X is the starting x-position for S.
23649 BACKWARD_P non-zero means process predecessors. */
23652 compute_overhangs_and_x (struct glyph_string
*s
, int x
, int backward_p
)
23658 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
23659 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
23669 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
23670 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
23680 /* The following macros are only called from draw_glyphs below.
23681 They reference the following parameters of that function directly:
23682 `w', `row', `area', and `overlap_p'
23683 as well as the following local variables:
23684 `s', `f', and `hdc' (in W32) */
23687 /* On W32, silently add local `hdc' variable to argument list of
23688 init_glyph_string. */
23689 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
23690 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
23692 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
23693 init_glyph_string (s, char2b, w, row, area, start, hl)
23696 /* Add a glyph string for a stretch glyph to the list of strings
23697 between HEAD and TAIL. START is the index of the stretch glyph in
23698 row area AREA of glyph row ROW. END is the index of the last glyph
23699 in that glyph row area. X is the current output position assigned
23700 to the new glyph string constructed. HL overrides that face of the
23701 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
23702 is the right-most x-position of the drawing area. */
23704 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
23705 and below -- keep them on one line. */
23706 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23709 s = alloca (sizeof *s); \
23710 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23711 START = fill_stretch_glyph_string (s, START, END); \
23712 append_glyph_string (&HEAD, &TAIL, s); \
23718 /* Add a glyph string for an image glyph to the list of strings
23719 between HEAD and TAIL. START is the index of the image glyph in
23720 row area AREA of glyph row ROW. END is the index of the last glyph
23721 in that glyph row area. X is the current output position assigned
23722 to the new glyph string constructed. HL overrides that face of the
23723 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
23724 is the right-most x-position of the drawing area. */
23726 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23729 s = alloca (sizeof *s); \
23730 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23731 fill_image_glyph_string (s); \
23732 append_glyph_string (&HEAD, &TAIL, s); \
23738 #ifdef HAVE_XWIDGETS
23739 #define BUILD_XWIDGET_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23742 printf("BUILD_XWIDGET_GLYPH_STRING\n"); \
23743 s = (struct glyph_string *) alloca (sizeof *s); \
23744 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23745 fill_xwidget_glyph_string (s); \
23746 append_glyph_string (&HEAD, &TAIL, s); \
23754 /* Add a glyph string for a sequence of character glyphs to the list
23755 of strings between HEAD and TAIL. START is the index of the first
23756 glyph in row area AREA of glyph row ROW that is part of the new
23757 glyph string. END is the index of the last glyph in that glyph row
23758 area. X is the current output position assigned to the new glyph
23759 string constructed. HL overrides that face of the glyph; e.g. it
23760 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
23761 right-most x-position of the drawing area. */
23763 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
23769 face_id = (row)->glyphs[area][START].face_id; \
23771 s = alloca (sizeof *s); \
23772 char2b = alloca ((END - START) * sizeof *char2b); \
23773 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23774 append_glyph_string (&HEAD, &TAIL, s); \
23776 START = fill_glyph_string (s, face_id, START, END, overlaps); \
23781 /* Add a glyph string for a composite sequence to the list of strings
23782 between HEAD and TAIL. START is the index of the first glyph in
23783 row area AREA of glyph row ROW that is part of the new glyph
23784 string. END is the index of the last glyph in that glyph row area.
23785 X is the current output position assigned to the new glyph string
23786 constructed. HL overrides that face of the glyph; e.g. it is
23787 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
23788 x-position of the drawing area. */
23790 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23792 int face_id = (row)->glyphs[area][START].face_id; \
23793 struct face *base_face = FACE_FROM_ID (f, face_id); \
23794 ptrdiff_t cmp_id = (row)->glyphs[area][START].u.cmp.id; \
23795 struct composition *cmp = composition_table[cmp_id]; \
23797 struct glyph_string *first_s = NULL; \
23800 char2b = alloca (cmp->glyph_len * sizeof *char2b); \
23802 /* Make glyph_strings for each glyph sequence that is drawable by \
23803 the same face, and append them to HEAD/TAIL. */ \
23804 for (n = 0; n < cmp->glyph_len;) \
23806 s = alloca (sizeof *s); \
23807 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23808 append_glyph_string (&(HEAD), &(TAIL), s); \
23814 n = fill_composite_glyph_string (s, base_face, overlaps); \
23822 /* Add a glyph string for a glyph-string sequence to the list of strings
23823 between HEAD and TAIL. */
23825 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23829 Lisp_Object gstring; \
23831 face_id = (row)->glyphs[area][START].face_id; \
23832 gstring = (composition_gstring_from_id \
23833 ((row)->glyphs[area][START].u.cmp.id)); \
23834 s = alloca (sizeof *s); \
23835 char2b = alloca (LGSTRING_GLYPH_LEN (gstring) * sizeof *char2b); \
23836 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23837 append_glyph_string (&(HEAD), &(TAIL), s); \
23839 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
23843 /* Add a glyph string for a sequence of glyphless character's glyphs
23844 to the list of strings between HEAD and TAIL. The meanings of
23845 arguments are the same as those of BUILD_CHAR_GLYPH_STRINGS. */
23847 #define BUILD_GLYPHLESS_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23852 face_id = (row)->glyphs[area][START].face_id; \
23854 s = alloca (sizeof *s); \
23855 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23856 append_glyph_string (&HEAD, &TAIL, s); \
23858 START = fill_glyphless_glyph_string (s, face_id, START, END, \
23864 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
23865 of AREA of glyph row ROW on window W between indices START and END.
23866 HL overrides the face for drawing glyph strings, e.g. it is
23867 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
23868 x-positions of the drawing area.
23870 This is an ugly monster macro construct because we must use alloca
23871 to allocate glyph strings (because draw_glyphs can be called
23872 asynchronously). */
23874 #define BUILD_GLYPH_STRINGS_1(START, END, HEAD, TAIL, HL, X, LAST_X) \
23877 HEAD = TAIL = NULL; \
23878 while (START < END) \
23880 struct glyph *first_glyph = (row)->glyphs[area] + START; \
23881 switch (first_glyph->type) \
23884 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
23888 case COMPOSITE_GLYPH: \
23889 if (first_glyph->u.cmp.automatic) \
23890 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
23893 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
23897 case STRETCH_GLYPH: \
23898 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
23902 case IMAGE_GLYPH: \
23903 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
23907 #define BUILD_GLYPH_STRINGS_XW(START, END, HEAD, TAIL, HL, X, LAST_X) \
23908 case XWIDGET_GLYPH: \
23909 BUILD_XWIDGET_GLYPH_STRING (START, END, HEAD, TAIL, \
23913 #define BUILD_GLYPH_STRINGS_2(START, END, HEAD, TAIL, HL, X, LAST_X) \
23914 case GLYPHLESS_GLYPH: \
23915 BUILD_GLYPHLESS_GLYPH_STRING (START, END, HEAD, TAIL, \
23925 set_glyph_string_background_width (s, START, LAST_X); \
23932 #ifdef HAVE_XWIDGETS
23933 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
23934 BUILD_GLYPH_STRINGS_1(START, END, HEAD, TAIL, HL, X, LAST_X) \
23935 BUILD_GLYPH_STRINGS_XW(START, END, HEAD, TAIL, HL, X, LAST_X) \
23936 BUILD_GLYPH_STRINGS_2(START, END, HEAD, TAIL, HL, X, LAST_X)
23938 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
23939 BUILD_GLYPH_STRINGS_1(START, END, HEAD, TAIL, HL, X, LAST_X) \
23940 BUILD_GLYPH_STRINGS_2(START, END, HEAD, TAIL, HL, X, LAST_X)
23944 /* Draw glyphs between START and END in AREA of ROW on window W,
23945 starting at x-position X. X is relative to AREA in W. HL is a
23946 face-override with the following meaning:
23948 DRAW_NORMAL_TEXT draw normally
23949 DRAW_CURSOR draw in cursor face
23950 DRAW_MOUSE_FACE draw in mouse face.
23951 DRAW_INVERSE_VIDEO draw in mode line face
23952 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
23953 DRAW_IMAGE_RAISED draw an image with a raised relief around it
23955 If OVERLAPS is non-zero, draw only the foreground of characters and
23956 clip to the physical height of ROW. Non-zero value also defines
23957 the overlapping part to be drawn:
23959 OVERLAPS_PRED overlap with preceding rows
23960 OVERLAPS_SUCC overlap with succeeding rows
23961 OVERLAPS_BOTH overlap with both preceding/succeeding rows
23962 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
23964 Value is the x-position reached, relative to AREA of W. */
23967 draw_glyphs (struct window
*w
, int x
, struct glyph_row
*row
,
23968 enum glyph_row_area area
, ptrdiff_t start
, ptrdiff_t end
,
23969 enum draw_glyphs_face hl
, int overlaps
)
23971 struct glyph_string
*head
, *tail
;
23972 struct glyph_string
*s
;
23973 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
23974 int i
, j
, x_reached
, last_x
, area_left
= 0;
23975 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
23978 ALLOCATE_HDC (hdc
, f
);
23980 /* Let's rather be paranoid than getting a SEGV. */
23981 end
= min (end
, row
->used
[area
]);
23982 start
= clip_to_bounds (0, start
, end
);
23984 /* Translate X to frame coordinates. Set last_x to the right
23985 end of the drawing area. */
23986 if (row
->full_width_p
)
23988 /* X is relative to the left edge of W, without scroll bars
23990 area_left
= WINDOW_LEFT_EDGE_X (w
);
23991 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
23995 area_left
= window_box_left (w
, area
);
23996 last_x
= area_left
+ window_box_width (w
, area
);
24000 /* Build a doubly-linked list of glyph_string structures between
24001 head and tail from what we have to draw. Note that the macro
24002 BUILD_GLYPH_STRINGS will modify its start parameter. That's
24003 the reason we use a separate variable `i'. */
24005 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
24007 x_reached
= tail
->x
+ tail
->background_width
;
24011 /* If there are any glyphs with lbearing < 0 or rbearing > width in
24012 the row, redraw some glyphs in front or following the glyph
24013 strings built above. */
24014 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
24016 struct glyph_string
*h
, *t
;
24017 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
24018 int mouse_beg_col
IF_LINT (= 0), mouse_end_col
IF_LINT (= 0);
24019 int check_mouse_face
= 0;
24022 /* If mouse highlighting is on, we may need to draw adjacent
24023 glyphs using mouse-face highlighting. */
24024 if (area
== TEXT_AREA
&& row
->mouse_face_p
24025 && hlinfo
->mouse_face_beg_row
>= 0
24026 && hlinfo
->mouse_face_end_row
>= 0)
24028 ptrdiff_t row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
24030 if (row_vpos
>= hlinfo
->mouse_face_beg_row
24031 && row_vpos
<= hlinfo
->mouse_face_end_row
)
24033 check_mouse_face
= 1;
24034 mouse_beg_col
= (row_vpos
== hlinfo
->mouse_face_beg_row
)
24035 ? hlinfo
->mouse_face_beg_col
: 0;
24036 mouse_end_col
= (row_vpos
== hlinfo
->mouse_face_end_row
)
24037 ? hlinfo
->mouse_face_end_col
24038 : row
->used
[TEXT_AREA
];
24042 /* Compute overhangs for all glyph strings. */
24043 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
24044 for (s
= head
; s
; s
= s
->next
)
24045 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
24047 /* Prepend glyph strings for glyphs in front of the first glyph
24048 string that are overwritten because of the first glyph
24049 string's left overhang. The background of all strings
24050 prepended must be drawn because the first glyph string
24052 i
= left_overwritten (head
);
24055 enum draw_glyphs_face overlap_hl
;
24057 /* If this row contains mouse highlighting, attempt to draw
24058 the overlapped glyphs with the correct highlight. This
24059 code fails if the overlap encompasses more than one glyph
24060 and mouse-highlight spans only some of these glyphs.
24061 However, making it work perfectly involves a lot more
24062 code, and I don't know if the pathological case occurs in
24063 practice, so we'll stick to this for now. --- cyd */
24064 if (check_mouse_face
24065 && mouse_beg_col
< start
&& mouse_end_col
> i
)
24066 overlap_hl
= DRAW_MOUSE_FACE
;
24068 overlap_hl
= DRAW_NORMAL_TEXT
;
24071 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
24072 overlap_hl
, dummy_x
, last_x
);
24074 compute_overhangs_and_x (t
, head
->x
, 1);
24075 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
24079 /* Prepend glyph strings for glyphs in front of the first glyph
24080 string that overwrite that glyph string because of their
24081 right overhang. For these strings, only the foreground must
24082 be drawn, because it draws over the glyph string at `head'.
24083 The background must not be drawn because this would overwrite
24084 right overhangs of preceding glyphs for which no glyph
24086 i
= left_overwriting (head
);
24089 enum draw_glyphs_face overlap_hl
;
24091 if (check_mouse_face
24092 && mouse_beg_col
< start
&& mouse_end_col
> i
)
24093 overlap_hl
= DRAW_MOUSE_FACE
;
24095 overlap_hl
= DRAW_NORMAL_TEXT
;
24098 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
24099 overlap_hl
, dummy_x
, last_x
);
24100 for (s
= h
; s
; s
= s
->next
)
24101 s
->background_filled_p
= 1;
24102 compute_overhangs_and_x (t
, head
->x
, 1);
24103 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
24106 /* Append glyphs strings for glyphs following the last glyph
24107 string tail that are overwritten by tail. The background of
24108 these strings has to be drawn because tail's foreground draws
24110 i
= right_overwritten (tail
);
24113 enum draw_glyphs_face overlap_hl
;
24115 if (check_mouse_face
24116 && mouse_beg_col
< i
&& mouse_end_col
> end
)
24117 overlap_hl
= DRAW_MOUSE_FACE
;
24119 overlap_hl
= DRAW_NORMAL_TEXT
;
24121 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
24122 overlap_hl
, x
, last_x
);
24123 /* Because BUILD_GLYPH_STRINGS updates the first argument,
24124 we don't have `end = i;' here. */
24125 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
24126 append_glyph_string_lists (&head
, &tail
, h
, t
);
24130 /* Append glyph strings for glyphs following the last glyph
24131 string tail that overwrite tail. The foreground of such
24132 glyphs has to be drawn because it writes into the background
24133 of tail. The background must not be drawn because it could
24134 paint over the foreground of following glyphs. */
24135 i
= right_overwriting (tail
);
24138 enum draw_glyphs_face overlap_hl
;
24139 if (check_mouse_face
24140 && mouse_beg_col
< i
&& mouse_end_col
> end
)
24141 overlap_hl
= DRAW_MOUSE_FACE
;
24143 overlap_hl
= DRAW_NORMAL_TEXT
;
24146 i
++; /* We must include the Ith glyph. */
24147 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
24148 overlap_hl
, x
, last_x
);
24149 for (s
= h
; s
; s
= s
->next
)
24150 s
->background_filled_p
= 1;
24151 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
24152 append_glyph_string_lists (&head
, &tail
, h
, t
);
24154 if (clip_head
|| clip_tail
)
24155 for (s
= head
; s
; s
= s
->next
)
24157 s
->clip_head
= clip_head
;
24158 s
->clip_tail
= clip_tail
;
24162 /* Draw all strings. */
24163 for (s
= head
; s
; s
= s
->next
)
24164 FRAME_RIF (f
)->draw_glyph_string (s
);
24167 /* When focus a sole frame and move horizontally, this sets on_p to 0
24168 causing a failure to erase prev cursor position. */
24169 if (area
== TEXT_AREA
24170 && !row
->full_width_p
24171 /* When drawing overlapping rows, only the glyph strings'
24172 foreground is drawn, which doesn't erase a cursor
24176 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
24177 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
24178 : (tail
? tail
->x
+ tail
->background_width
: x
));
24182 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
24183 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
24187 /* Value is the x-position up to which drawn, relative to AREA of W.
24188 This doesn't include parts drawn because of overhangs. */
24189 if (row
->full_width_p
)
24190 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
24192 x_reached
-= area_left
;
24194 RELEASE_HDC (hdc
, f
);
24199 /* Expand row matrix if too narrow. Don't expand if area
24202 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
24204 if (!fonts_changed_p \
24205 && (it->glyph_row->glyphs[area] \
24206 < it->glyph_row->glyphs[area + 1])) \
24208 it->w->ncols_scale_factor++; \
24209 fonts_changed_p = 1; \
24213 /* Store one glyph for IT->char_to_display in IT->glyph_row.
24214 Called from x_produce_glyphs when IT->glyph_row is non-null. */
24217 append_glyph (struct it
*it
)
24219 struct glyph
*glyph
;
24220 enum glyph_row_area area
= it
->area
;
24222 eassert (it
->glyph_row
);
24223 eassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
24225 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24226 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24228 /* If the glyph row is reversed, we need to prepend the glyph
24229 rather than append it. */
24230 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24234 /* Make room for the additional glyph. */
24235 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
24237 glyph
= it
->glyph_row
->glyphs
[area
];
24239 glyph
->charpos
= CHARPOS (it
->position
);
24240 glyph
->object
= it
->object
;
24241 if (it
->pixel_width
> 0)
24243 glyph
->pixel_width
= it
->pixel_width
;
24244 glyph
->padding_p
= 0;
24248 /* Assure at least 1-pixel width. Otherwise, cursor can't
24249 be displayed correctly. */
24250 glyph
->pixel_width
= 1;
24251 glyph
->padding_p
= 1;
24253 glyph
->ascent
= it
->ascent
;
24254 glyph
->descent
= it
->descent
;
24255 glyph
->voffset
= it
->voffset
;
24256 glyph
->type
= CHAR_GLYPH
;
24257 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24258 glyph
->multibyte_p
= it
->multibyte_p
;
24259 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24261 /* In R2L rows, the left and the right box edges need to be
24262 drawn in reverse direction. */
24263 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24264 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24268 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24269 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24271 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
24272 || it
->phys_descent
> it
->descent
);
24273 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
24274 glyph
->face_id
= it
->face_id
;
24275 glyph
->u
.ch
= it
->char_to_display
;
24276 glyph
->slice
.img
= null_glyph_slice
;
24277 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24280 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24281 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24283 glyph
->bidi_type
= it
->bidi_it
.type
;
24287 glyph
->resolved_level
= 0;
24288 glyph
->bidi_type
= UNKNOWN_BT
;
24290 ++it
->glyph_row
->used
[area
];
24293 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24296 /* Store one glyph for the composition IT->cmp_it.id in
24297 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
24301 append_composite_glyph (struct it
*it
)
24303 struct glyph
*glyph
;
24304 enum glyph_row_area area
= it
->area
;
24306 eassert (it
->glyph_row
);
24308 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24309 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24311 /* If the glyph row is reversed, we need to prepend the glyph
24312 rather than append it. */
24313 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
24317 /* Make room for the new glyph. */
24318 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
24320 glyph
= it
->glyph_row
->glyphs
[it
->area
];
24322 glyph
->charpos
= it
->cmp_it
.charpos
;
24323 glyph
->object
= it
->object
;
24324 glyph
->pixel_width
= it
->pixel_width
;
24325 glyph
->ascent
= it
->ascent
;
24326 glyph
->descent
= it
->descent
;
24327 glyph
->voffset
= it
->voffset
;
24328 glyph
->type
= COMPOSITE_GLYPH
;
24329 if (it
->cmp_it
.ch
< 0)
24331 glyph
->u
.cmp
.automatic
= 0;
24332 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
24333 glyph
->slice
.cmp
.from
= glyph
->slice
.cmp
.to
= 0;
24337 glyph
->u
.cmp
.automatic
= 1;
24338 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
24339 glyph
->slice
.cmp
.from
= it
->cmp_it
.from
;
24340 glyph
->slice
.cmp
.to
= it
->cmp_it
.to
- 1;
24342 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24343 glyph
->multibyte_p
= it
->multibyte_p
;
24344 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24346 /* In R2L rows, the left and the right box edges need to be
24347 drawn in reverse direction. */
24348 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24349 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24353 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24354 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24356 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
24357 || it
->phys_descent
> it
->descent
);
24358 glyph
->padding_p
= 0;
24359 glyph
->glyph_not_available_p
= 0;
24360 glyph
->face_id
= it
->face_id
;
24361 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24364 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24365 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24367 glyph
->bidi_type
= it
->bidi_it
.type
;
24369 ++it
->glyph_row
->used
[area
];
24372 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24376 /* Change IT->ascent and IT->height according to the setting of
24380 take_vertical_position_into_account (struct it
*it
)
24384 if (it
->voffset
< 0)
24385 /* Increase the ascent so that we can display the text higher
24387 it
->ascent
-= it
->voffset
;
24389 /* Increase the descent so that we can display the text lower
24391 it
->descent
+= it
->voffset
;
24396 /* Produce glyphs/get display metrics for the image IT is loaded with.
24397 See the description of struct display_iterator in dispextern.h for
24398 an overview of struct display_iterator. */
24401 produce_image_glyph (struct it
*it
)
24405 int glyph_ascent
, crop
;
24406 struct glyph_slice slice
;
24408 eassert (it
->what
== IT_IMAGE
);
24410 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24412 /* Make sure X resources of the face is loaded. */
24413 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24415 if (it
->image_id
< 0)
24417 /* Fringe bitmap. */
24418 it
->ascent
= it
->phys_ascent
= 0;
24419 it
->descent
= it
->phys_descent
= 0;
24420 it
->pixel_width
= 0;
24425 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
24427 /* Make sure X resources of the image is loaded. */
24428 prepare_image_for_display (it
->f
, img
);
24430 slice
.x
= slice
.y
= 0;
24431 slice
.width
= img
->width
;
24432 slice
.height
= img
->height
;
24434 if (INTEGERP (it
->slice
.x
))
24435 slice
.x
= XINT (it
->slice
.x
);
24436 else if (FLOATP (it
->slice
.x
))
24437 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
24439 if (INTEGERP (it
->slice
.y
))
24440 slice
.y
= XINT (it
->slice
.y
);
24441 else if (FLOATP (it
->slice
.y
))
24442 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
24444 if (INTEGERP (it
->slice
.width
))
24445 slice
.width
= XINT (it
->slice
.width
);
24446 else if (FLOATP (it
->slice
.width
))
24447 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
24449 if (INTEGERP (it
->slice
.height
))
24450 slice
.height
= XINT (it
->slice
.height
);
24451 else if (FLOATP (it
->slice
.height
))
24452 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
24454 if (slice
.x
>= img
->width
)
24455 slice
.x
= img
->width
;
24456 if (slice
.y
>= img
->height
)
24457 slice
.y
= img
->height
;
24458 if (slice
.x
+ slice
.width
>= img
->width
)
24459 slice
.width
= img
->width
- slice
.x
;
24460 if (slice
.y
+ slice
.height
> img
->height
)
24461 slice
.height
= img
->height
- slice
.y
;
24463 if (slice
.width
== 0 || slice
.height
== 0)
24466 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
24468 it
->descent
= slice
.height
- glyph_ascent
;
24470 it
->descent
+= img
->vmargin
;
24471 if (slice
.y
+ slice
.height
== img
->height
)
24472 it
->descent
+= img
->vmargin
;
24473 it
->phys_descent
= it
->descent
;
24475 it
->pixel_width
= slice
.width
;
24477 it
->pixel_width
+= img
->hmargin
;
24478 if (slice
.x
+ slice
.width
== img
->width
)
24479 it
->pixel_width
+= img
->hmargin
;
24481 /* It's quite possible for images to have an ascent greater than
24482 their height, so don't get confused in that case. */
24483 if (it
->descent
< 0)
24488 if (face
->box
!= FACE_NO_BOX
)
24490 if (face
->box_line_width
> 0)
24493 it
->ascent
+= face
->box_line_width
;
24494 if (slice
.y
+ slice
.height
== img
->height
)
24495 it
->descent
+= face
->box_line_width
;
24498 if (it
->start_of_box_run_p
&& slice
.x
== 0)
24499 it
->pixel_width
+= eabs (face
->box_line_width
);
24500 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
24501 it
->pixel_width
+= eabs (face
->box_line_width
);
24504 take_vertical_position_into_account (it
);
24506 /* Automatically crop wide image glyphs at right edge so we can
24507 draw the cursor on same display row. */
24508 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
24509 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
24511 it
->pixel_width
-= crop
;
24512 slice
.width
-= crop
;
24517 struct glyph
*glyph
;
24518 enum glyph_row_area area
= it
->area
;
24520 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24521 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24523 glyph
->charpos
= CHARPOS (it
->position
);
24524 glyph
->object
= it
->object
;
24525 glyph
->pixel_width
= it
->pixel_width
;
24526 glyph
->ascent
= glyph_ascent
;
24527 glyph
->descent
= it
->descent
;
24528 glyph
->voffset
= it
->voffset
;
24529 glyph
->type
= IMAGE_GLYPH
;
24530 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24531 glyph
->multibyte_p
= it
->multibyte_p
;
24532 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24534 /* In R2L rows, the left and the right box edges need to be
24535 drawn in reverse direction. */
24536 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24537 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24541 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24542 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24544 glyph
->overlaps_vertically_p
= 0;
24545 glyph
->padding_p
= 0;
24546 glyph
->glyph_not_available_p
= 0;
24547 glyph
->face_id
= it
->face_id
;
24548 glyph
->u
.img_id
= img
->id
;
24549 glyph
->slice
.img
= slice
;
24550 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24553 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24554 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24556 glyph
->bidi_type
= it
->bidi_it
.type
;
24558 ++it
->glyph_row
->used
[area
];
24561 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24565 #ifdef HAVE_XWIDGETS
24567 produce_xwidget_glyph (struct it
*it
)
24569 struct xwidget
* xw
;
24571 int glyph_ascent
, crop
;
24572 printf("produce_xwidget_glyph:\n");
24573 eassert (it
->what
== IT_XWIDGET
);
24575 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24577 /* Make sure X resources of the face is loaded. */
24578 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24581 it
->ascent
= it
->phys_ascent
= glyph_ascent
= xw
->height
/2;
24582 it
->descent
= xw
->height
/2;
24583 it
->phys_descent
= it
->descent
;
24584 it
->pixel_width
= xw
->width
;
24585 /* It's quite possible for images to have an ascent greater than
24586 their height, so don't get confused in that case. */
24587 if (it
->descent
< 0)
24592 if (face
->box
!= FACE_NO_BOX
)
24594 if (face
->box_line_width
> 0)
24596 it
->ascent
+= face
->box_line_width
;
24597 it
->descent
+= face
->box_line_width
;
24600 if (it
->start_of_box_run_p
)
24601 it
->pixel_width
+= eabs (face
->box_line_width
);
24602 it
->pixel_width
+= eabs (face
->box_line_width
);
24605 take_vertical_position_into_account (it
);
24607 /* Automatically crop wide image glyphs at right edge so we can
24608 draw the cursor on same display row. */
24609 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
24610 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
24612 it
->pixel_width
-= crop
;
24617 struct glyph
*glyph
;
24618 enum glyph_row_area area
= it
->area
;
24620 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24621 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24623 glyph
->charpos
= CHARPOS (it
->position
);
24624 glyph
->object
= it
->object
;
24625 glyph
->pixel_width
= it
->pixel_width
;
24626 glyph
->ascent
= glyph_ascent
;
24627 glyph
->descent
= it
->descent
;
24628 glyph
->voffset
= it
->voffset
;
24629 glyph
->type
= XWIDGET_GLYPH
;
24631 glyph
->multibyte_p
= it
->multibyte_p
;
24632 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24633 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24634 glyph
->overlaps_vertically_p
= 0;
24635 glyph
->padding_p
= 0;
24636 glyph
->glyph_not_available_p
= 0;
24637 glyph
->face_id
= it
->face_id
;
24638 glyph
->u
.xwidget
= it
->xwidget
;
24639 //assert_valid_xwidget_id(glyph->u.xwidget_id,"produce_xwidget_glyph");
24640 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24641 ++it
->glyph_row
->used
[area
];
24644 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24649 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
24650 of the glyph, WIDTH and HEIGHT are the width and height of the
24651 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
24654 append_stretch_glyph (struct it
*it
, Lisp_Object object
,
24655 int width
, int height
, int ascent
)
24657 struct glyph
*glyph
;
24658 enum glyph_row_area area
= it
->area
;
24660 eassert (ascent
>= 0 && ascent
<= height
);
24662 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24663 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24665 /* If the glyph row is reversed, we need to prepend the glyph
24666 rather than append it. */
24667 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24671 /* Make room for the additional glyph. */
24672 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
24674 glyph
= it
->glyph_row
->glyphs
[area
];
24676 glyph
->charpos
= CHARPOS (it
->position
);
24677 glyph
->object
= object
;
24678 glyph
->pixel_width
= width
;
24679 glyph
->ascent
= ascent
;
24680 glyph
->descent
= height
- ascent
;
24681 glyph
->voffset
= it
->voffset
;
24682 glyph
->type
= STRETCH_GLYPH
;
24683 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24684 glyph
->multibyte_p
= it
->multibyte_p
;
24685 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24687 /* In R2L rows, the left and the right box edges need to be
24688 drawn in reverse direction. */
24689 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24690 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24694 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24695 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24697 glyph
->overlaps_vertically_p
= 0;
24698 glyph
->padding_p
= 0;
24699 glyph
->glyph_not_available_p
= 0;
24700 glyph
->face_id
= it
->face_id
;
24701 glyph
->u
.stretch
.ascent
= ascent
;
24702 glyph
->u
.stretch
.height
= height
;
24703 glyph
->slice
.img
= null_glyph_slice
;
24704 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24707 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24708 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24710 glyph
->bidi_type
= it
->bidi_it
.type
;
24714 glyph
->resolved_level
= 0;
24715 glyph
->bidi_type
= UNKNOWN_BT
;
24717 ++it
->glyph_row
->used
[area
];
24720 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24723 #endif /* HAVE_WINDOW_SYSTEM */
24725 /* Produce a stretch glyph for iterator IT. IT->object is the value
24726 of the glyph property displayed. The value must be a list
24727 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
24730 1. `:width WIDTH' specifies that the space should be WIDTH *
24731 canonical char width wide. WIDTH may be an integer or floating
24734 2. `:relative-width FACTOR' specifies that the width of the stretch
24735 should be computed from the width of the first character having the
24736 `glyph' property, and should be FACTOR times that width.
24738 3. `:align-to HPOS' specifies that the space should be wide enough
24739 to reach HPOS, a value in canonical character units.
24741 Exactly one of the above pairs must be present.
24743 4. `:height HEIGHT' specifies that the height of the stretch produced
24744 should be HEIGHT, measured in canonical character units.
24746 5. `:relative-height FACTOR' specifies that the height of the
24747 stretch should be FACTOR times the height of the characters having
24748 the glyph property.
24750 Either none or exactly one of 4 or 5 must be present.
24752 6. `:ascent ASCENT' specifies that ASCENT percent of the height
24753 of the stretch should be used for the ascent of the stretch.
24754 ASCENT must be in the range 0 <= ASCENT <= 100. */
24757 produce_stretch_glyph (struct it
*it
)
24759 /* (space :width WIDTH :height HEIGHT ...) */
24760 Lisp_Object prop
, plist
;
24761 int width
= 0, height
= 0, align_to
= -1;
24762 int zero_width_ok_p
= 0;
24764 struct font
*font
= NULL
;
24766 #ifdef HAVE_WINDOW_SYSTEM
24768 int zero_height_ok_p
= 0;
24770 if (FRAME_WINDOW_P (it
->f
))
24772 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24773 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24774 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24778 /* List should start with `space'. */
24779 eassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
24780 plist
= XCDR (it
->object
);
24782 /* Compute the width of the stretch. */
24783 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
24784 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
24786 /* Absolute width `:width WIDTH' specified and valid. */
24787 zero_width_ok_p
= 1;
24790 #ifdef HAVE_WINDOW_SYSTEM
24791 else if (FRAME_WINDOW_P (it
->f
)
24792 && (prop
= Fplist_get (plist
, QCrelative_width
), NUMVAL (prop
) > 0))
24794 /* Relative width `:relative-width FACTOR' specified and valid.
24795 Compute the width of the characters having the `glyph'
24798 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
24801 if (it
->multibyte_p
)
24802 it2
.c
= it2
.char_to_display
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
24805 it2
.c
= it2
.char_to_display
= *p
, it2
.len
= 1;
24806 if (! ASCII_CHAR_P (it2
.c
))
24807 it2
.char_to_display
= BYTE8_TO_CHAR (it2
.c
);
24810 it2
.glyph_row
= NULL
;
24811 it2
.what
= IT_CHARACTER
;
24812 x_produce_glyphs (&it2
);
24813 width
= NUMVAL (prop
) * it2
.pixel_width
;
24815 #endif /* HAVE_WINDOW_SYSTEM */
24816 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
24817 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
24819 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
24820 align_to
= (align_to
< 0
24822 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
24823 else if (align_to
< 0)
24824 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
24825 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
24826 zero_width_ok_p
= 1;
24829 /* Nothing specified -> width defaults to canonical char width. */
24830 width
= FRAME_COLUMN_WIDTH (it
->f
);
24832 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
24835 #ifdef HAVE_WINDOW_SYSTEM
24836 /* Compute height. */
24837 if (FRAME_WINDOW_P (it
->f
))
24839 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
24840 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
24843 zero_height_ok_p
= 1;
24845 else if (prop
= Fplist_get (plist
, QCrelative_height
),
24847 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
24849 height
= FONT_HEIGHT (font
);
24851 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
24854 /* Compute percentage of height used for ascent. If
24855 `:ascent ASCENT' is present and valid, use that. Otherwise,
24856 derive the ascent from the font in use. */
24857 if (prop
= Fplist_get (plist
, QCascent
),
24858 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
24859 ascent
= height
* NUMVAL (prop
) / 100.0;
24860 else if (!NILP (prop
)
24861 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
24862 ascent
= min (max (0, (int)tem
), height
);
24864 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
24867 #endif /* HAVE_WINDOW_SYSTEM */
24870 if (width
> 0 && it
->line_wrap
!= TRUNCATE
24871 && it
->current_x
+ width
> it
->last_visible_x
)
24873 width
= it
->last_visible_x
- it
->current_x
;
24874 #ifdef HAVE_WINDOW_SYSTEM
24875 /* Subtract one more pixel from the stretch width, but only on
24876 GUI frames, since on a TTY each glyph is one "pixel" wide. */
24877 width
-= FRAME_WINDOW_P (it
->f
);
24881 if (width
> 0 && height
> 0 && it
->glyph_row
)
24883 Lisp_Object o_object
= it
->object
;
24884 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
24887 if (!STRINGP (object
))
24888 object
= it
->w
->contents
;
24889 #ifdef HAVE_WINDOW_SYSTEM
24890 if (FRAME_WINDOW_P (it
->f
))
24891 append_stretch_glyph (it
, object
, width
, height
, ascent
);
24895 it
->object
= object
;
24896 it
->char_to_display
= ' ';
24897 it
->pixel_width
= it
->len
= 1;
24899 tty_append_glyph (it
);
24900 it
->object
= o_object
;
24904 it
->pixel_width
= width
;
24905 #ifdef HAVE_WINDOW_SYSTEM
24906 if (FRAME_WINDOW_P (it
->f
))
24908 it
->ascent
= it
->phys_ascent
= ascent
;
24909 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
24910 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
24911 take_vertical_position_into_account (it
);
24915 it
->nglyphs
= width
;
24918 /* Get information about special display element WHAT in an
24919 environment described by IT. WHAT is one of IT_TRUNCATION or
24920 IT_CONTINUATION. Maybe produce glyphs for WHAT if IT has a
24921 non-null glyph_row member. This function ensures that fields like
24922 face_id, c, len of IT are left untouched. */
24925 produce_special_glyphs (struct it
*it
, enum display_element_type what
)
24932 temp_it
.object
= make_number (0);
24933 memset (&temp_it
.current
, 0, sizeof temp_it
.current
);
24935 if (what
== IT_CONTINUATION
)
24937 /* Continuation glyph. For R2L lines, we mirror it by hand. */
24938 if (it
->bidi_it
.paragraph_dir
== R2L
)
24939 SET_GLYPH_FROM_CHAR (glyph
, '/');
24941 SET_GLYPH_FROM_CHAR (glyph
, '\\');
24943 && (gc
= DISP_CONTINUE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
24945 /* FIXME: Should we mirror GC for R2L lines? */
24946 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
24947 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
24950 else if (what
== IT_TRUNCATION
)
24952 /* Truncation glyph. */
24953 SET_GLYPH_FROM_CHAR (glyph
, '$');
24955 && (gc
= DISP_TRUNC_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
24957 /* FIXME: Should we mirror GC for R2L lines? */
24958 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
24959 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
24965 #ifdef HAVE_WINDOW_SYSTEM
24966 /* On a GUI frame, when the right fringe (left fringe for R2L rows)
24967 is turned off, we precede the truncation/continuation glyphs by a
24968 stretch glyph whose width is computed such that these special
24969 glyphs are aligned at the window margin, even when very different
24970 fonts are used in different glyph rows. */
24971 if (FRAME_WINDOW_P (temp_it
.f
)
24972 /* init_iterator calls this with it->glyph_row == NULL, and it
24973 wants only the pixel width of the truncation/continuation
24975 && temp_it
.glyph_row
24976 /* insert_left_trunc_glyphs calls us at the beginning of the
24977 row, and it has its own calculation of the stretch glyph
24979 && temp_it
.glyph_row
->used
[TEXT_AREA
] > 0
24980 && (temp_it
.glyph_row
->reversed_p
24981 ? WINDOW_LEFT_FRINGE_WIDTH (temp_it
.w
)
24982 : WINDOW_RIGHT_FRINGE_WIDTH (temp_it
.w
)) == 0)
24984 int stretch_width
= temp_it
.last_visible_x
- temp_it
.current_x
;
24986 if (stretch_width
> 0)
24988 struct face
*face
= FACE_FROM_ID (temp_it
.f
, temp_it
.face_id
);
24989 struct font
*font
=
24990 face
->font
? face
->font
: FRAME_FONT (temp_it
.f
);
24991 int stretch_ascent
=
24992 (((temp_it
.ascent
+ temp_it
.descent
)
24993 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
24995 append_stretch_glyph (&temp_it
, make_number (0), stretch_width
,
24996 temp_it
.ascent
+ temp_it
.descent
,
25003 temp_it
.what
= IT_CHARACTER
;
25005 temp_it
.c
= temp_it
.char_to_display
= GLYPH_CHAR (glyph
);
25006 temp_it
.face_id
= GLYPH_FACE (glyph
);
25007 temp_it
.len
= CHAR_BYTES (temp_it
.c
);
25009 PRODUCE_GLYPHS (&temp_it
);
25010 it
->pixel_width
= temp_it
.pixel_width
;
25011 it
->nglyphs
= temp_it
.pixel_width
;
25014 #ifdef HAVE_WINDOW_SYSTEM
25016 /* Calculate line-height and line-spacing properties.
25017 An integer value specifies explicit pixel value.
25018 A float value specifies relative value to current face height.
25019 A cons (float . face-name) specifies relative value to
25020 height of specified face font.
25022 Returns height in pixels, or nil. */
25026 calc_line_height_property (struct it
*it
, Lisp_Object val
, struct font
*font
,
25027 int boff
, int override
)
25029 Lisp_Object face_name
= Qnil
;
25030 int ascent
, descent
, height
;
25032 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
25037 face_name
= XCAR (val
);
25039 if (!NUMBERP (val
))
25040 val
= make_number (1);
25041 if (NILP (face_name
))
25043 height
= it
->ascent
+ it
->descent
;
25048 if (NILP (face_name
))
25050 font
= FRAME_FONT (it
->f
);
25051 boff
= FRAME_BASELINE_OFFSET (it
->f
);
25053 else if (EQ (face_name
, Qt
))
25062 face_id
= lookup_named_face (it
->f
, face_name
, 0);
25064 return make_number (-1);
25066 face
= FACE_FROM_ID (it
->f
, face_id
);
25069 return make_number (-1);
25070 boff
= font
->baseline_offset
;
25071 if (font
->vertical_centering
)
25072 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
25075 ascent
= FONT_BASE (font
) + boff
;
25076 descent
= FONT_DESCENT (font
) - boff
;
25080 it
->override_ascent
= ascent
;
25081 it
->override_descent
= descent
;
25082 it
->override_boff
= boff
;
25085 height
= ascent
+ descent
;
25089 height
= (int)(XFLOAT_DATA (val
) * height
);
25090 else if (INTEGERP (val
))
25091 height
*= XINT (val
);
25093 return make_number (height
);
25097 /* Append a glyph for a glyphless character to IT->glyph_row. FACE_ID
25098 is a face ID to be used for the glyph. FOR_NO_FONT is nonzero if
25099 and only if this is for a character for which no font was found.
25101 If the display method (it->glyphless_method) is
25102 GLYPHLESS_DISPLAY_ACRONYM or GLYPHLESS_DISPLAY_HEX_CODE, LEN is a
25103 length of the acronym or the hexadecimal string, UPPER_XOFF and
25104 UPPER_YOFF are pixel offsets for the upper part of the string,
25105 LOWER_XOFF and LOWER_YOFF are for the lower part.
25107 For the other display methods, LEN through LOWER_YOFF are zero. */
25110 append_glyphless_glyph (struct it
*it
, int face_id
, int for_no_font
, int len
,
25111 short upper_xoff
, short upper_yoff
,
25112 short lower_xoff
, short lower_yoff
)
25114 struct glyph
*glyph
;
25115 enum glyph_row_area area
= it
->area
;
25117 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
25118 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
25120 /* If the glyph row is reversed, we need to prepend the glyph
25121 rather than append it. */
25122 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
25126 /* Make room for the additional glyph. */
25127 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
25129 glyph
= it
->glyph_row
->glyphs
[area
];
25131 glyph
->charpos
= CHARPOS (it
->position
);
25132 glyph
->object
= it
->object
;
25133 glyph
->pixel_width
= it
->pixel_width
;
25134 glyph
->ascent
= it
->ascent
;
25135 glyph
->descent
= it
->descent
;
25136 glyph
->voffset
= it
->voffset
;
25137 glyph
->type
= GLYPHLESS_GLYPH
;
25138 glyph
->u
.glyphless
.method
= it
->glyphless_method
;
25139 glyph
->u
.glyphless
.for_no_font
= for_no_font
;
25140 glyph
->u
.glyphless
.len
= len
;
25141 glyph
->u
.glyphless
.ch
= it
->c
;
25142 glyph
->slice
.glyphless
.upper_xoff
= upper_xoff
;
25143 glyph
->slice
.glyphless
.upper_yoff
= upper_yoff
;
25144 glyph
->slice
.glyphless
.lower_xoff
= lower_xoff
;
25145 glyph
->slice
.glyphless
.lower_yoff
= lower_yoff
;
25146 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
25147 glyph
->multibyte_p
= it
->multibyte_p
;
25148 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
25150 /* In R2L rows, the left and the right box edges need to be
25151 drawn in reverse direction. */
25152 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
25153 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
25157 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
25158 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
25160 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
25161 || it
->phys_descent
> it
->descent
);
25162 glyph
->padding_p
= 0;
25163 glyph
->glyph_not_available_p
= 0;
25164 glyph
->face_id
= face_id
;
25165 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
25168 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
25169 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
25171 glyph
->bidi_type
= it
->bidi_it
.type
;
25173 ++it
->glyph_row
->used
[area
];
25176 IT_EXPAND_MATRIX_WIDTH (it
, area
);
25180 /* Produce a glyph for a glyphless character for iterator IT.
25181 IT->glyphless_method specifies which method to use for displaying
25182 the character. See the description of enum
25183 glyphless_display_method in dispextern.h for the detail.
25185 FOR_NO_FONT is nonzero if and only if this is for a character for
25186 which no font was found. ACRONYM, if non-nil, is an acronym string
25187 for the character. */
25190 produce_glyphless_glyph (struct it
*it
, int for_no_font
, Lisp_Object acronym
)
25195 int base_width
, base_height
, width
, height
;
25196 short upper_xoff
, upper_yoff
, lower_xoff
, lower_yoff
;
25199 /* Get the metrics of the base font. We always refer to the current
25201 face
= FACE_FROM_ID (it
->f
, it
->face_id
)->ascii_face
;
25202 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
25203 it
->ascent
= FONT_BASE (font
) + font
->baseline_offset
;
25204 it
->descent
= FONT_DESCENT (font
) - font
->baseline_offset
;
25205 base_height
= it
->ascent
+ it
->descent
;
25206 base_width
= font
->average_width
;
25208 /* Get a face ID for the glyph by utilizing a cache (the same way as
25209 done for `escape-glyph' in get_next_display_element). */
25210 if (it
->f
== last_glyphless_glyph_frame
25211 && it
->face_id
== last_glyphless_glyph_face_id
)
25213 face_id
= last_glyphless_glyph_merged_face_id
;
25217 /* Merge the `glyphless-char' face into the current face. */
25218 face_id
= merge_faces (it
->f
, Qglyphless_char
, 0, it
->face_id
);
25219 last_glyphless_glyph_frame
= it
->f
;
25220 last_glyphless_glyph_face_id
= it
->face_id
;
25221 last_glyphless_glyph_merged_face_id
= face_id
;
25224 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_THIN_SPACE
)
25226 it
->pixel_width
= THIN_SPACE_WIDTH
;
25228 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
25230 else if (it
->glyphless_method
== GLYPHLESS_DISPLAY_EMPTY_BOX
)
25232 width
= CHAR_WIDTH (it
->c
);
25235 else if (width
> 4)
25237 it
->pixel_width
= base_width
* width
;
25239 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
25245 unsigned int code
[6];
25247 int ascent
, descent
;
25248 struct font_metrics metrics_upper
, metrics_lower
;
25250 face
= FACE_FROM_ID (it
->f
, face_id
);
25251 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
25252 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
25254 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_ACRONYM
)
25256 if (! STRINGP (acronym
) && CHAR_TABLE_P (Vglyphless_char_display
))
25257 acronym
= CHAR_TABLE_REF (Vglyphless_char_display
, it
->c
);
25258 if (CONSP (acronym
))
25259 acronym
= XCAR (acronym
);
25260 str
= STRINGP (acronym
) ? SSDATA (acronym
) : "";
25264 eassert (it
->glyphless_method
== GLYPHLESS_DISPLAY_HEX_CODE
);
25265 sprintf (buf
, "%0*X", it
->c
< 0x10000 ? 4 : 6, it
->c
);
25268 for (len
= 0; str
[len
] && ASCII_BYTE_P (str
[len
]) && len
< 6; len
++)
25269 code
[len
] = font
->driver
->encode_char (font
, str
[len
]);
25270 upper_len
= (len
+ 1) / 2;
25271 font
->driver
->text_extents (font
, code
, upper_len
,
25273 font
->driver
->text_extents (font
, code
+ upper_len
, len
- upper_len
,
25278 /* +4 is for vertical bars of a box plus 1-pixel spaces at both side. */
25279 width
= max (metrics_upper
.width
, metrics_lower
.width
) + 4;
25280 upper_xoff
= upper_yoff
= 2; /* the typical case */
25281 if (base_width
>= width
)
25283 /* Align the upper to the left, the lower to the right. */
25284 it
->pixel_width
= base_width
;
25285 lower_xoff
= base_width
- 2 - metrics_lower
.width
;
25289 /* Center the shorter one. */
25290 it
->pixel_width
= width
;
25291 if (metrics_upper
.width
>= metrics_lower
.width
)
25292 lower_xoff
= (width
- metrics_lower
.width
) / 2;
25295 /* FIXME: This code doesn't look right. It formerly was
25296 missing the "lower_xoff = 0;", which couldn't have
25297 been right since it left lower_xoff uninitialized. */
25299 upper_xoff
= (width
- metrics_upper
.width
) / 2;
25303 /* +5 is for horizontal bars of a box plus 1-pixel spaces at
25304 top, bottom, and between upper and lower strings. */
25305 height
= (metrics_upper
.ascent
+ metrics_upper
.descent
25306 + metrics_lower
.ascent
+ metrics_lower
.descent
) + 5;
25307 /* Center vertically.
25308 H:base_height, D:base_descent
25309 h:height, ld:lower_descent, la:lower_ascent, ud:upper_descent
25311 ascent = - (D - H/2 - h/2 + 1); "+ 1" for rounding up
25312 descent = D - H/2 + h/2;
25313 lower_yoff = descent - 2 - ld;
25314 upper_yoff = lower_yoff - la - 1 - ud; */
25315 ascent
= - (it
->descent
- (base_height
+ height
+ 1) / 2);
25316 descent
= it
->descent
- (base_height
- height
) / 2;
25317 lower_yoff
= descent
- 2 - metrics_lower
.descent
;
25318 upper_yoff
= (lower_yoff
- metrics_lower
.ascent
- 1
25319 - metrics_upper
.descent
);
25320 /* Don't make the height shorter than the base height. */
25321 if (height
> base_height
)
25323 it
->ascent
= ascent
;
25324 it
->descent
= descent
;
25328 it
->phys_ascent
= it
->ascent
;
25329 it
->phys_descent
= it
->descent
;
25331 append_glyphless_glyph (it
, face_id
, for_no_font
, len
,
25332 upper_xoff
, upper_yoff
,
25333 lower_xoff
, lower_yoff
);
25335 take_vertical_position_into_account (it
);
25340 Produce glyphs/get display metrics for the display element IT is
25341 loaded with. See the description of struct it in dispextern.h
25342 for an overview of struct it. */
25345 x_produce_glyphs (struct it
*it
)
25347 int extra_line_spacing
= it
->extra_line_spacing
;
25349 it
->glyph_not_available_p
= 0;
25351 if (it
->what
== IT_CHARACTER
)
25354 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25355 struct font
*font
= face
->font
;
25356 struct font_metrics
*pcm
= NULL
;
25357 int boff
; /* baseline offset */
25361 /* When no suitable font is found, display this character by
25362 the method specified in the first extra slot of
25363 Vglyphless_char_display. */
25364 Lisp_Object acronym
= lookup_glyphless_char_display (-1, it
);
25366 eassert (it
->what
== IT_GLYPHLESS
);
25367 produce_glyphless_glyph (it
, 1, STRINGP (acronym
) ? acronym
: Qnil
);
25371 boff
= font
->baseline_offset
;
25372 if (font
->vertical_centering
)
25373 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
25375 if (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t')
25381 if (it
->override_ascent
>= 0)
25383 it
->ascent
= it
->override_ascent
;
25384 it
->descent
= it
->override_descent
;
25385 boff
= it
->override_boff
;
25389 it
->ascent
= FONT_BASE (font
) + boff
;
25390 it
->descent
= FONT_DESCENT (font
) - boff
;
25393 if (get_char_glyph_code (it
->char_to_display
, font
, &char2b
))
25395 pcm
= get_per_char_metric (font
, &char2b
);
25396 if (pcm
->width
== 0
25397 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
25403 it
->phys_ascent
= pcm
->ascent
+ boff
;
25404 it
->phys_descent
= pcm
->descent
- boff
;
25405 it
->pixel_width
= pcm
->width
;
25409 it
->glyph_not_available_p
= 1;
25410 it
->phys_ascent
= it
->ascent
;
25411 it
->phys_descent
= it
->descent
;
25412 it
->pixel_width
= font
->space_width
;
25415 if (it
->constrain_row_ascent_descent_p
)
25417 if (it
->descent
> it
->max_descent
)
25419 it
->ascent
+= it
->descent
- it
->max_descent
;
25420 it
->descent
= it
->max_descent
;
25422 if (it
->ascent
> it
->max_ascent
)
25424 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
25425 it
->ascent
= it
->max_ascent
;
25427 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
25428 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
25429 extra_line_spacing
= 0;
25432 /* If this is a space inside a region of text with
25433 `space-width' property, change its width. */
25434 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
25436 it
->pixel_width
*= XFLOATINT (it
->space_width
);
25438 /* If face has a box, add the box thickness to the character
25439 height. If character has a box line to the left and/or
25440 right, add the box line width to the character's width. */
25441 if (face
->box
!= FACE_NO_BOX
)
25443 int thick
= face
->box_line_width
;
25447 it
->ascent
+= thick
;
25448 it
->descent
+= thick
;
25453 if (it
->start_of_box_run_p
)
25454 it
->pixel_width
+= thick
;
25455 if (it
->end_of_box_run_p
)
25456 it
->pixel_width
+= thick
;
25459 /* If face has an overline, add the height of the overline
25460 (1 pixel) and a 1 pixel margin to the character height. */
25461 if (face
->overline_p
)
25462 it
->ascent
+= overline_margin
;
25464 if (it
->constrain_row_ascent_descent_p
)
25466 if (it
->ascent
> it
->max_ascent
)
25467 it
->ascent
= it
->max_ascent
;
25468 if (it
->descent
> it
->max_descent
)
25469 it
->descent
= it
->max_descent
;
25472 take_vertical_position_into_account (it
);
25474 /* If we have to actually produce glyphs, do it. */
25479 /* Translate a space with a `space-width' property
25480 into a stretch glyph. */
25481 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
25482 / FONT_HEIGHT (font
));
25483 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
25484 it
->ascent
+ it
->descent
, ascent
);
25489 /* If characters with lbearing or rbearing are displayed
25490 in this line, record that fact in a flag of the
25491 glyph row. This is used to optimize X output code. */
25492 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
25493 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25495 if (! stretched_p
&& it
->pixel_width
== 0)
25496 /* We assure that all visible glyphs have at least 1-pixel
25498 it
->pixel_width
= 1;
25500 else if (it
->char_to_display
== '\n')
25502 /* A newline has no width, but we need the height of the
25503 line. But if previous part of the line sets a height,
25504 don't increase that height */
25506 Lisp_Object height
;
25507 Lisp_Object total_height
= Qnil
;
25509 it
->override_ascent
= -1;
25510 it
->pixel_width
= 0;
25513 height
= get_it_property (it
, Qline_height
);
25514 /* Split (line-height total-height) list */
25516 && CONSP (XCDR (height
))
25517 && NILP (XCDR (XCDR (height
))))
25519 total_height
= XCAR (XCDR (height
));
25520 height
= XCAR (height
);
25522 height
= calc_line_height_property (it
, height
, font
, boff
, 1);
25524 if (it
->override_ascent
>= 0)
25526 it
->ascent
= it
->override_ascent
;
25527 it
->descent
= it
->override_descent
;
25528 boff
= it
->override_boff
;
25532 it
->ascent
= FONT_BASE (font
) + boff
;
25533 it
->descent
= FONT_DESCENT (font
) - boff
;
25536 if (EQ (height
, Qt
))
25538 if (it
->descent
> it
->max_descent
)
25540 it
->ascent
+= it
->descent
- it
->max_descent
;
25541 it
->descent
= it
->max_descent
;
25543 if (it
->ascent
> it
->max_ascent
)
25545 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
25546 it
->ascent
= it
->max_ascent
;
25548 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
25549 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
25550 it
->constrain_row_ascent_descent_p
= 1;
25551 extra_line_spacing
= 0;
25555 Lisp_Object spacing
;
25557 it
->phys_ascent
= it
->ascent
;
25558 it
->phys_descent
= it
->descent
;
25560 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
25561 && face
->box
!= FACE_NO_BOX
25562 && face
->box_line_width
> 0)
25564 it
->ascent
+= face
->box_line_width
;
25565 it
->descent
+= face
->box_line_width
;
25568 && XINT (height
) > it
->ascent
+ it
->descent
)
25569 it
->ascent
= XINT (height
) - it
->descent
;
25571 if (!NILP (total_height
))
25572 spacing
= calc_line_height_property (it
, total_height
, font
, boff
, 0);
25575 spacing
= get_it_property (it
, Qline_spacing
);
25576 spacing
= calc_line_height_property (it
, spacing
, font
, boff
, 0);
25578 if (INTEGERP (spacing
))
25580 extra_line_spacing
= XINT (spacing
);
25581 if (!NILP (total_height
))
25582 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
25586 else /* i.e. (it->char_to_display == '\t') */
25588 if (font
->space_width
> 0)
25590 int tab_width
= it
->tab_width
* font
->space_width
;
25591 int x
= it
->current_x
+ it
->continuation_lines_width
;
25592 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
25594 /* If the distance from the current position to the next tab
25595 stop is less than a space character width, use the
25596 tab stop after that. */
25597 if (next_tab_x
- x
< font
->space_width
)
25598 next_tab_x
+= tab_width
;
25600 it
->pixel_width
= next_tab_x
- x
;
25602 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
25603 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
25607 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
25608 it
->ascent
+ it
->descent
, it
->ascent
);
25613 it
->pixel_width
= 0;
25618 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
25620 /* A static composition.
25622 Note: A composition is represented as one glyph in the
25623 glyph matrix. There are no padding glyphs.
25625 Important note: pixel_width, ascent, and descent are the
25626 values of what is drawn by draw_glyphs (i.e. the values of
25627 the overall glyphs composed). */
25628 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25629 int boff
; /* baseline offset */
25630 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
25631 int glyph_len
= cmp
->glyph_len
;
25632 struct font
*font
= face
->font
;
25636 /* If we have not yet calculated pixel size data of glyphs of
25637 the composition for the current face font, calculate them
25638 now. Theoretically, we have to check all fonts for the
25639 glyphs, but that requires much time and memory space. So,
25640 here we check only the font of the first glyph. This may
25641 lead to incorrect display, but it's very rare, and C-l
25642 (recenter-top-bottom) can correct the display anyway. */
25643 if (! cmp
->font
|| cmp
->font
!= font
)
25645 /* Ascent and descent of the font of the first character
25646 of this composition (adjusted by baseline offset).
25647 Ascent and descent of overall glyphs should not be less
25648 than these, respectively. */
25649 int font_ascent
, font_descent
, font_height
;
25650 /* Bounding box of the overall glyphs. */
25651 int leftmost
, rightmost
, lowest
, highest
;
25652 int lbearing
, rbearing
;
25653 int i
, width
, ascent
, descent
;
25654 int left_padded
= 0, right_padded
= 0;
25655 int c
IF_LINT (= 0); /* cmp->glyph_len can't be zero; see Bug#8512 */
25657 struct font_metrics
*pcm
;
25658 int font_not_found_p
;
25661 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
25662 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
25664 if (glyph_len
< cmp
->glyph_len
)
25666 for (i
= 0; i
< glyph_len
; i
++)
25668 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
25670 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
25675 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
25676 : IT_CHARPOS (*it
));
25677 /* If no suitable font is found, use the default font. */
25678 font_not_found_p
= font
== NULL
;
25679 if (font_not_found_p
)
25681 face
= face
->ascii_face
;
25684 boff
= font
->baseline_offset
;
25685 if (font
->vertical_centering
)
25686 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
25687 font_ascent
= FONT_BASE (font
) + boff
;
25688 font_descent
= FONT_DESCENT (font
) - boff
;
25689 font_height
= FONT_HEIGHT (font
);
25694 if (! font_not_found_p
)
25696 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
25698 pcm
= get_per_char_metric (font
, &char2b
);
25701 /* Initialize the bounding box. */
25704 width
= cmp
->glyph_len
> 0 ? pcm
->width
: 0;
25705 ascent
= pcm
->ascent
;
25706 descent
= pcm
->descent
;
25707 lbearing
= pcm
->lbearing
;
25708 rbearing
= pcm
->rbearing
;
25712 width
= cmp
->glyph_len
> 0 ? font
->space_width
: 0;
25713 ascent
= FONT_BASE (font
);
25714 descent
= FONT_DESCENT (font
);
25721 lowest
= - descent
+ boff
;
25722 highest
= ascent
+ boff
;
25724 if (! font_not_found_p
25725 && font
->default_ascent
25726 && CHAR_TABLE_P (Vuse_default_ascent
)
25727 && !NILP (Faref (Vuse_default_ascent
,
25728 make_number (it
->char_to_display
))))
25729 highest
= font
->default_ascent
+ boff
;
25731 /* Draw the first glyph at the normal position. It may be
25732 shifted to right later if some other glyphs are drawn
25734 cmp
->offsets
[i
* 2] = 0;
25735 cmp
->offsets
[i
* 2 + 1] = boff
;
25736 cmp
->lbearing
= lbearing
;
25737 cmp
->rbearing
= rbearing
;
25739 /* Set cmp->offsets for the remaining glyphs. */
25740 for (i
++; i
< glyph_len
; i
++)
25742 int left
, right
, btm
, top
;
25743 int ch
= COMPOSITION_GLYPH (cmp
, i
);
25745 struct face
*this_face
;
25749 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
25750 this_face
= FACE_FROM_ID (it
->f
, face_id
);
25751 font
= this_face
->font
;
25757 get_char_face_and_encoding (it
->f
, ch
, face_id
,
25759 pcm
= get_per_char_metric (font
, &char2b
);
25762 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
25765 width
= pcm
->width
;
25766 ascent
= pcm
->ascent
;
25767 descent
= pcm
->descent
;
25768 lbearing
= pcm
->lbearing
;
25769 rbearing
= pcm
->rbearing
;
25770 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
25772 /* Relative composition with or without
25773 alternate chars. */
25774 left
= (leftmost
+ rightmost
- width
) / 2;
25775 btm
= - descent
+ boff
;
25776 if (font
->relative_compose
25777 && (! CHAR_TABLE_P (Vignore_relative_composition
)
25778 || NILP (Faref (Vignore_relative_composition
,
25779 make_number (ch
)))))
25782 if (- descent
>= font
->relative_compose
)
25783 /* One extra pixel between two glyphs. */
25785 else if (ascent
<= 0)
25786 /* One extra pixel between two glyphs. */
25787 btm
= lowest
- 1 - ascent
- descent
;
25792 /* A composition rule is specified by an integer
25793 value that encodes global and new reference
25794 points (GREF and NREF). GREF and NREF are
25795 specified by numbers as below:
25797 0---1---2 -- ascent
25801 9--10--11 -- center
25803 ---3---4---5--- baseline
25805 6---7---8 -- descent
25807 int rule
= COMPOSITION_RULE (cmp
, i
);
25808 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
25810 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
25811 grefx
= gref
% 3, nrefx
= nref
% 3;
25812 grefy
= gref
/ 3, nrefy
= nref
/ 3;
25814 xoff
= font_height
* (xoff
- 128) / 256;
25816 yoff
= font_height
* (yoff
- 128) / 256;
25819 + grefx
* (rightmost
- leftmost
) / 2
25820 - nrefx
* width
/ 2
25823 btm
= ((grefy
== 0 ? highest
25825 : grefy
== 2 ? lowest
25826 : (highest
+ lowest
) / 2)
25827 - (nrefy
== 0 ? ascent
+ descent
25828 : nrefy
== 1 ? descent
- boff
25830 : (ascent
+ descent
) / 2)
25834 cmp
->offsets
[i
* 2] = left
;
25835 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
25837 /* Update the bounding box of the overall glyphs. */
25840 right
= left
+ width
;
25841 if (left
< leftmost
)
25843 if (right
> rightmost
)
25846 top
= btm
+ descent
+ ascent
;
25852 if (cmp
->lbearing
> left
+ lbearing
)
25853 cmp
->lbearing
= left
+ lbearing
;
25854 if (cmp
->rbearing
< left
+ rbearing
)
25855 cmp
->rbearing
= left
+ rbearing
;
25859 /* If there are glyphs whose x-offsets are negative,
25860 shift all glyphs to the right and make all x-offsets
25864 for (i
= 0; i
< cmp
->glyph_len
; i
++)
25865 cmp
->offsets
[i
* 2] -= leftmost
;
25866 rightmost
-= leftmost
;
25867 cmp
->lbearing
-= leftmost
;
25868 cmp
->rbearing
-= leftmost
;
25871 if (left_padded
&& cmp
->lbearing
< 0)
25873 for (i
= 0; i
< cmp
->glyph_len
; i
++)
25874 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
25875 rightmost
-= cmp
->lbearing
;
25876 cmp
->rbearing
-= cmp
->lbearing
;
25879 if (right_padded
&& rightmost
< cmp
->rbearing
)
25881 rightmost
= cmp
->rbearing
;
25884 cmp
->pixel_width
= rightmost
;
25885 cmp
->ascent
= highest
;
25886 cmp
->descent
= - lowest
;
25887 if (cmp
->ascent
< font_ascent
)
25888 cmp
->ascent
= font_ascent
;
25889 if (cmp
->descent
< font_descent
)
25890 cmp
->descent
= font_descent
;
25894 && (cmp
->lbearing
< 0
25895 || cmp
->rbearing
> cmp
->pixel_width
))
25896 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25898 it
->pixel_width
= cmp
->pixel_width
;
25899 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
25900 it
->descent
= it
->phys_descent
= cmp
->descent
;
25901 if (face
->box
!= FACE_NO_BOX
)
25903 int thick
= face
->box_line_width
;
25907 it
->ascent
+= thick
;
25908 it
->descent
+= thick
;
25913 if (it
->start_of_box_run_p
)
25914 it
->pixel_width
+= thick
;
25915 if (it
->end_of_box_run_p
)
25916 it
->pixel_width
+= thick
;
25919 /* If face has an overline, add the height of the overline
25920 (1 pixel) and a 1 pixel margin to the character height. */
25921 if (face
->overline_p
)
25922 it
->ascent
+= overline_margin
;
25924 take_vertical_position_into_account (it
);
25925 if (it
->ascent
< 0)
25927 if (it
->descent
< 0)
25930 if (it
->glyph_row
&& cmp
->glyph_len
> 0)
25931 append_composite_glyph (it
);
25933 else if (it
->what
== IT_COMPOSITION
)
25935 /* A dynamic (automatic) composition. */
25936 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25937 Lisp_Object gstring
;
25938 struct font_metrics metrics
;
25942 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
25944 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
25947 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
25948 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25949 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
25950 it
->descent
= it
->phys_descent
= metrics
.descent
;
25951 if (face
->box
!= FACE_NO_BOX
)
25953 int thick
= face
->box_line_width
;
25957 it
->ascent
+= thick
;
25958 it
->descent
+= thick
;
25963 if (it
->start_of_box_run_p
)
25964 it
->pixel_width
+= thick
;
25965 if (it
->end_of_box_run_p
)
25966 it
->pixel_width
+= thick
;
25968 /* If face has an overline, add the height of the overline
25969 (1 pixel) and a 1 pixel margin to the character height. */
25970 if (face
->overline_p
)
25971 it
->ascent
+= overline_margin
;
25972 take_vertical_position_into_account (it
);
25973 if (it
->ascent
< 0)
25975 if (it
->descent
< 0)
25979 append_composite_glyph (it
);
25981 else if (it
->what
== IT_GLYPHLESS
)
25982 produce_glyphless_glyph (it
, 0, Qnil
);
25983 else if (it
->what
== IT_IMAGE
)
25984 produce_image_glyph (it
);
25985 else if (it
->what
== IT_STRETCH
)
25986 produce_stretch_glyph (it
);
25987 #ifdef HAVE_XWIDGETS
25988 else if (it
->what
== IT_XWIDGET
)
25989 produce_xwidget_glyph (it
);
25992 /* Accumulate dimensions. Note: can't assume that it->descent > 0
25993 because this isn't true for images with `:ascent 100'. */
25994 eassert (it
->ascent
>= 0 && it
->descent
>= 0);
25995 if (it
->area
== TEXT_AREA
)
25996 it
->current_x
+= it
->pixel_width
;
25998 if (extra_line_spacing
> 0)
26000 it
->descent
+= extra_line_spacing
;
26001 if (extra_line_spacing
> it
->max_extra_line_spacing
)
26002 it
->max_extra_line_spacing
= extra_line_spacing
;
26005 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
26006 it
->max_descent
= max (it
->max_descent
, it
->descent
);
26007 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
26008 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
26012 Output LEN glyphs starting at START at the nominal cursor position.
26013 Advance the nominal cursor over the text. The global variable
26014 updated_row is the glyph row being updated, and updated_area is the
26015 area of that row being updated. */
26018 x_write_glyphs (struct window
*w
, struct glyph
*start
, int len
)
26020 int x
, hpos
, chpos
= w
->phys_cursor
.hpos
;
26022 eassert (updated_row
);
26023 /* When the window is hscrolled, cursor hpos can legitimately be out
26024 of bounds, but we draw the cursor at the corresponding window
26025 margin in that case. */
26026 if (!updated_row
->reversed_p
&& chpos
< 0)
26028 if (updated_row
->reversed_p
&& chpos
>= updated_row
->used
[TEXT_AREA
])
26029 chpos
= updated_row
->used
[TEXT_AREA
] - 1;
26033 /* Write glyphs. */
26035 hpos
= start
- updated_row
->glyphs
[updated_area
];
26036 x
= draw_glyphs (w
, output_cursor
.x
,
26037 updated_row
, updated_area
,
26039 DRAW_NORMAL_TEXT
, 0);
26041 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
26042 if (updated_area
== TEXT_AREA
26043 && w
->phys_cursor_on_p
26044 && w
->phys_cursor
.vpos
== output_cursor
.vpos
26046 && chpos
< hpos
+ len
)
26047 w
->phys_cursor_on_p
= 0;
26051 /* Advance the output cursor. */
26052 output_cursor
.hpos
+= len
;
26053 output_cursor
.x
= x
;
26058 Insert LEN glyphs from START at the nominal cursor position. */
26061 x_insert_glyphs (struct window
*w
, struct glyph
*start
, int len
)
26064 int line_height
, shift_by_width
, shifted_region_width
;
26065 struct glyph_row
*row
;
26066 struct glyph
*glyph
;
26067 int frame_x
, frame_y
;
26070 eassert (updated_row
);
26072 f
= XFRAME (WINDOW_FRAME (w
));
26074 /* Get the height of the line we are in. */
26076 line_height
= row
->height
;
26078 /* Get the width of the glyphs to insert. */
26079 shift_by_width
= 0;
26080 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
26081 shift_by_width
+= glyph
->pixel_width
;
26083 /* Get the width of the region to shift right. */
26084 shifted_region_width
= (window_box_width (w
, updated_area
)
26089 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
26090 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
26092 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
26093 line_height
, shift_by_width
);
26095 /* Write the glyphs. */
26096 hpos
= start
- row
->glyphs
[updated_area
];
26097 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
26099 DRAW_NORMAL_TEXT
, 0);
26101 /* Advance the output cursor. */
26102 output_cursor
.hpos
+= len
;
26103 output_cursor
.x
+= shift_by_width
;
26109 Erase the current text line from the nominal cursor position
26110 (inclusive) to pixel column TO_X (exclusive). The idea is that
26111 everything from TO_X onward is already erased.
26113 TO_X is a pixel position relative to updated_area of currently
26114 updated window W. TO_X == -1 means clear to the end of this area. */
26117 x_clear_end_of_line (struct window
*w
, int to_x
)
26120 int max_x
, min_y
, max_y
;
26121 int from_x
, from_y
, to_y
;
26123 eassert (updated_row
);
26124 f
= XFRAME (w
->frame
);
26126 if (updated_row
->full_width_p
)
26127 max_x
= WINDOW_TOTAL_WIDTH (w
);
26129 max_x
= window_box_width (w
, updated_area
);
26130 max_y
= window_text_bottom_y (w
);
26132 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
26133 of window. For TO_X > 0, truncate to end of drawing area. */
26139 to_x
= min (to_x
, max_x
);
26141 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
26143 /* Notice if the cursor will be cleared by this operation. */
26144 if (!updated_row
->full_width_p
)
26145 notice_overwritten_cursor (w
, updated_area
,
26146 output_cursor
.x
, -1,
26148 MATRIX_ROW_BOTTOM_Y (updated_row
));
26150 from_x
= output_cursor
.x
;
26152 /* Translate to frame coordinates. */
26153 if (updated_row
->full_width_p
)
26155 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
26156 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
26160 int area_left
= window_box_left (w
, updated_area
);
26161 from_x
+= area_left
;
26165 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
26166 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
26167 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
26169 /* Prevent inadvertently clearing to end of the X window. */
26170 if (to_x
> from_x
&& to_y
> from_y
)
26173 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
26174 to_x
- from_x
, to_y
- from_y
);
26179 #endif /* HAVE_WINDOW_SYSTEM */
26183 /***********************************************************************
26185 ***********************************************************************/
26187 /* Value is the internal representation of the specified cursor type
26188 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
26189 of the bar cursor. */
26191 static enum text_cursor_kinds
26192 get_specified_cursor_type (Lisp_Object arg
, int *width
)
26194 enum text_cursor_kinds type
;
26199 if (EQ (arg
, Qbox
))
26200 return FILLED_BOX_CURSOR
;
26202 if (EQ (arg
, Qhollow
))
26203 return HOLLOW_BOX_CURSOR
;
26205 if (EQ (arg
, Qbar
))
26212 && EQ (XCAR (arg
), Qbar
)
26213 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
26215 *width
= XINT (XCDR (arg
));
26219 if (EQ (arg
, Qhbar
))
26222 return HBAR_CURSOR
;
26226 && EQ (XCAR (arg
), Qhbar
)
26227 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
26229 *width
= XINT (XCDR (arg
));
26230 return HBAR_CURSOR
;
26233 /* Treat anything unknown as "hollow box cursor".
26234 It was bad to signal an error; people have trouble fixing
26235 .Xdefaults with Emacs, when it has something bad in it. */
26236 type
= HOLLOW_BOX_CURSOR
;
26241 /* Set the default cursor types for specified frame. */
26243 set_frame_cursor_types (struct frame
*f
, Lisp_Object arg
)
26248 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
26249 FRAME_CURSOR_WIDTH (f
) = width
;
26251 /* By default, set up the blink-off state depending on the on-state. */
26253 tem
= Fassoc (arg
, Vblink_cursor_alist
);
26256 FRAME_BLINK_OFF_CURSOR (f
)
26257 = get_specified_cursor_type (XCDR (tem
), &width
);
26258 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
26261 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
26263 /* Make sure the cursor gets redrawn. */
26264 cursor_type_changed
= 1;
26268 #ifdef HAVE_WINDOW_SYSTEM
26270 /* Return the cursor we want to be displayed in window W. Return
26271 width of bar/hbar cursor through WIDTH arg. Return with
26272 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
26273 (i.e. if the `system caret' should track this cursor).
26275 In a mini-buffer window, we want the cursor only to appear if we
26276 are reading input from this window. For the selected window, we
26277 want the cursor type given by the frame parameter or buffer local
26278 setting of cursor-type. If explicitly marked off, draw no cursor.
26279 In all other cases, we want a hollow box cursor. */
26281 static enum text_cursor_kinds
26282 get_window_cursor_type (struct window
*w
, struct glyph
*glyph
, int *width
,
26283 int *active_cursor
)
26285 struct frame
*f
= XFRAME (w
->frame
);
26286 struct buffer
*b
= XBUFFER (w
->contents
);
26287 int cursor_type
= DEFAULT_CURSOR
;
26288 Lisp_Object alt_cursor
;
26289 int non_selected
= 0;
26291 *active_cursor
= 1;
26294 if (cursor_in_echo_area
26295 && FRAME_HAS_MINIBUF_P (f
)
26296 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
26298 if (w
== XWINDOW (echo_area_window
))
26300 if (EQ (BVAR (b
, cursor_type
), Qt
) || NILP (BVAR (b
, cursor_type
)))
26302 *width
= FRAME_CURSOR_WIDTH (f
);
26303 return FRAME_DESIRED_CURSOR (f
);
26306 return get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
26309 *active_cursor
= 0;
26313 /* Detect a nonselected window or nonselected frame. */
26314 else if (w
!= XWINDOW (f
->selected_window
)
26315 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)
26317 *active_cursor
= 0;
26319 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
26325 /* Never display a cursor in a window in which cursor-type is nil. */
26326 if (NILP (BVAR (b
, cursor_type
)))
26329 /* Get the normal cursor type for this window. */
26330 if (EQ (BVAR (b
, cursor_type
), Qt
))
26332 cursor_type
= FRAME_DESIRED_CURSOR (f
);
26333 *width
= FRAME_CURSOR_WIDTH (f
);
26336 cursor_type
= get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
26338 /* Use cursor-in-non-selected-windows instead
26339 for non-selected window or frame. */
26342 alt_cursor
= BVAR (b
, cursor_in_non_selected_windows
);
26343 if (!EQ (Qt
, alt_cursor
))
26344 return get_specified_cursor_type (alt_cursor
, width
);
26345 /* t means modify the normal cursor type. */
26346 if (cursor_type
== FILLED_BOX_CURSOR
)
26347 cursor_type
= HOLLOW_BOX_CURSOR
;
26348 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
26350 return cursor_type
;
26353 /* Use normal cursor if not blinked off. */
26354 if (!w
->cursor_off_p
)
26357 #ifdef HAVE_XWIDGETS
26358 if (glyph
!= NULL
&& glyph
->type
== XWIDGET_GLYPH
){
26359 //printf("attempt xwidget cursor avoidance in get_window_cursor_type\n");
26363 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
26365 if (cursor_type
== FILLED_BOX_CURSOR
)
26367 /* Using a block cursor on large images can be very annoying.
26368 So use a hollow cursor for "large" images.
26369 If image is not transparent (no mask), also use hollow cursor. */
26370 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
26371 if (img
!= NULL
&& IMAGEP (img
->spec
))
26373 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
26374 where N = size of default frame font size.
26375 This should cover most of the "tiny" icons people may use. */
26377 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
26378 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
26379 cursor_type
= HOLLOW_BOX_CURSOR
;
26382 else if (cursor_type
!= NO_CURSOR
)
26384 /* Display current only supports BOX and HOLLOW cursors for images.
26385 So for now, unconditionally use a HOLLOW cursor when cursor is
26386 not a solid box cursor. */
26387 cursor_type
= HOLLOW_BOX_CURSOR
;
26390 return cursor_type
;
26393 /* Cursor is blinked off, so determine how to "toggle" it. */
26395 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
26396 if ((alt_cursor
= Fassoc (BVAR (b
, cursor_type
), Vblink_cursor_alist
), !NILP (alt_cursor
)))
26397 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
26399 /* Then see if frame has specified a specific blink off cursor type. */
26400 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
26402 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
26403 return FRAME_BLINK_OFF_CURSOR (f
);
26407 /* Some people liked having a permanently visible blinking cursor,
26408 while others had very strong opinions against it. So it was
26409 decided to remove it. KFS 2003-09-03 */
26411 /* Finally perform built-in cursor blinking:
26412 filled box <-> hollow box
26413 wide [h]bar <-> narrow [h]bar
26414 narrow [h]bar <-> no cursor
26415 other type <-> no cursor */
26417 if (cursor_type
== FILLED_BOX_CURSOR
)
26418 return HOLLOW_BOX_CURSOR
;
26420 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
26423 return cursor_type
;
26431 /* Notice when the text cursor of window W has been completely
26432 overwritten by a drawing operation that outputs glyphs in AREA
26433 starting at X0 and ending at X1 in the line starting at Y0 and
26434 ending at Y1. X coordinates are area-relative. X1 < 0 means all
26435 the rest of the line after X0 has been written. Y coordinates
26436 are window-relative. */
26439 notice_overwritten_cursor (struct window
*w
, enum glyph_row_area area
,
26440 int x0
, int x1
, int y0
, int y1
)
26442 int cx0
, cx1
, cy0
, cy1
;
26443 struct glyph_row
*row
;
26445 if (!w
->phys_cursor_on_p
)
26447 if (area
!= TEXT_AREA
)
26450 if (w
->phys_cursor
.vpos
< 0
26451 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
26452 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
26453 !(row
->enabled_p
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
))))
26456 if (row
->cursor_in_fringe_p
)
26458 row
->cursor_in_fringe_p
= 0;
26459 draw_fringe_bitmap (w
, row
, row
->reversed_p
);
26460 w
->phys_cursor_on_p
= 0;
26464 cx0
= w
->phys_cursor
.x
;
26465 cx1
= cx0
+ w
->phys_cursor_width
;
26466 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
26469 /* The cursor image will be completely removed from the
26470 screen if the output area intersects the cursor area in
26471 y-direction. When we draw in [y0 y1[, and some part of
26472 the cursor is at y < y0, that part must have been drawn
26473 before. When scrolling, the cursor is erased before
26474 actually scrolling, so we don't come here. When not
26475 scrolling, the rows above the old cursor row must have
26476 changed, and in this case these rows must have written
26477 over the cursor image.
26479 Likewise if part of the cursor is below y1, with the
26480 exception of the cursor being in the first blank row at
26481 the buffer and window end because update_text_area
26482 doesn't draw that row. (Except when it does, but
26483 that's handled in update_text_area.) */
26485 cy0
= w
->phys_cursor
.y
;
26486 cy1
= cy0
+ w
->phys_cursor_height
;
26487 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
26490 w
->phys_cursor_on_p
= 0;
26493 #endif /* HAVE_WINDOW_SYSTEM */
26496 /************************************************************************
26498 ************************************************************************/
26500 #ifdef HAVE_WINDOW_SYSTEM
26503 Fix the display of area AREA of overlapping row ROW in window W
26504 with respect to the overlapping part OVERLAPS. */
26507 x_fix_overlapping_area (struct window
*w
, struct glyph_row
*row
,
26508 enum glyph_row_area area
, int overlaps
)
26515 for (i
= 0; i
< row
->used
[area
];)
26517 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
26519 int start
= i
, start_x
= x
;
26523 x
+= row
->glyphs
[area
][i
].pixel_width
;
26526 while (i
< row
->used
[area
]
26527 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
26529 draw_glyphs (w
, start_x
, row
, area
,
26531 DRAW_NORMAL_TEXT
, overlaps
);
26535 x
+= row
->glyphs
[area
][i
].pixel_width
;
26545 Draw the cursor glyph of window W in glyph row ROW. See the
26546 comment of draw_glyphs for the meaning of HL. */
26549 draw_phys_cursor_glyph (struct window
*w
, struct glyph_row
*row
,
26550 enum draw_glyphs_face hl
)
26552 /* If cursor hpos is out of bounds, don't draw garbage. This can
26553 happen in mini-buffer windows when switching between echo area
26554 glyphs and mini-buffer. */
26555 if ((row
->reversed_p
26556 ? (w
->phys_cursor
.hpos
>= 0)
26557 : (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])))
26559 int on_p
= w
->phys_cursor_on_p
;
26561 int hpos
= w
->phys_cursor
.hpos
;
26563 /* When the window is hscrolled, cursor hpos can legitimately be
26564 out of bounds, but we draw the cursor at the corresponding
26565 window margin in that case. */
26566 if (!row
->reversed_p
&& hpos
< 0)
26568 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26569 hpos
= row
->used
[TEXT_AREA
] - 1;
26571 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
, hpos
, hpos
+ 1,
26573 w
->phys_cursor_on_p
= on_p
;
26575 if (hl
== DRAW_CURSOR
)
26576 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
26577 /* When we erase the cursor, and ROW is overlapped by other
26578 rows, make sure that these overlapping parts of other rows
26580 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
26582 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
26584 if (row
> w
->current_matrix
->rows
26585 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
26586 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
26587 OVERLAPS_ERASED_CURSOR
);
26589 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
26590 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
26591 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
26592 OVERLAPS_ERASED_CURSOR
);
26599 Erase the image of a cursor of window W from the screen. */
26602 erase_phys_cursor (struct window
*w
)
26604 struct frame
*f
= XFRAME (w
->frame
);
26605 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
26606 int hpos
= w
->phys_cursor
.hpos
;
26607 int vpos
= w
->phys_cursor
.vpos
;
26608 int mouse_face_here_p
= 0;
26609 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
26610 struct glyph_row
*cursor_row
;
26611 struct glyph
*cursor_glyph
;
26612 enum draw_glyphs_face hl
;
26614 /* No cursor displayed or row invalidated => nothing to do on the
26616 if (w
->phys_cursor_type
== NO_CURSOR
)
26617 goto mark_cursor_off
;
26619 /* VPOS >= active_glyphs->nrows means that window has been resized.
26620 Don't bother to erase the cursor. */
26621 if (vpos
>= active_glyphs
->nrows
)
26622 goto mark_cursor_off
;
26624 /* If row containing cursor is marked invalid, there is nothing we
26626 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
26627 if (!cursor_row
->enabled_p
)
26628 goto mark_cursor_off
;
26630 /* If line spacing is > 0, old cursor may only be partially visible in
26631 window after split-window. So adjust visible height. */
26632 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
26633 window_text_bottom_y (w
) - cursor_row
->y
);
26635 /* If row is completely invisible, don't attempt to delete a cursor which
26636 isn't there. This can happen if cursor is at top of a window, and
26637 we switch to a buffer with a header line in that window. */
26638 if (cursor_row
->visible_height
<= 0)
26639 goto mark_cursor_off
;
26641 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
26642 if (cursor_row
->cursor_in_fringe_p
)
26644 cursor_row
->cursor_in_fringe_p
= 0;
26645 draw_fringe_bitmap (w
, cursor_row
, cursor_row
->reversed_p
);
26646 goto mark_cursor_off
;
26649 /* This can happen when the new row is shorter than the old one.
26650 In this case, either draw_glyphs or clear_end_of_line
26651 should have cleared the cursor. Note that we wouldn't be
26652 able to erase the cursor in this case because we don't have a
26653 cursor glyph at hand. */
26654 if ((cursor_row
->reversed_p
26655 ? (w
->phys_cursor
.hpos
< 0)
26656 : (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])))
26657 goto mark_cursor_off
;
26659 /* When the window is hscrolled, cursor hpos can legitimately be out
26660 of bounds, but we draw the cursor at the corresponding window
26661 margin in that case. */
26662 if (!cursor_row
->reversed_p
&& hpos
< 0)
26664 if (cursor_row
->reversed_p
&& hpos
>= cursor_row
->used
[TEXT_AREA
])
26665 hpos
= cursor_row
->used
[TEXT_AREA
] - 1;
26667 /* If the cursor is in the mouse face area, redisplay that when
26668 we clear the cursor. */
26669 if (! NILP (hlinfo
->mouse_face_window
)
26670 && coords_in_mouse_face_p (w
, hpos
, vpos
)
26671 /* Don't redraw the cursor's spot in mouse face if it is at the
26672 end of a line (on a newline). The cursor appears there, but
26673 mouse highlighting does not. */
26674 && cursor_row
->used
[TEXT_AREA
] > hpos
&& hpos
>= 0)
26675 mouse_face_here_p
= 1;
26677 /* Maybe clear the display under the cursor. */
26678 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
26681 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
26684 cursor_glyph
= get_phys_cursor_glyph (w
);
26685 if (cursor_glyph
== NULL
)
26686 goto mark_cursor_off
;
26688 width
= cursor_glyph
->pixel_width
;
26689 left_x
= window_box_left_offset (w
, TEXT_AREA
);
26690 x
= w
->phys_cursor
.x
;
26692 width
-= left_x
- x
;
26693 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
26694 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
26695 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
26698 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
26701 /* Erase the cursor by redrawing the character underneath it. */
26702 if (mouse_face_here_p
)
26703 hl
= DRAW_MOUSE_FACE
;
26705 hl
= DRAW_NORMAL_TEXT
;
26706 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
26709 w
->phys_cursor_on_p
= 0;
26710 w
->phys_cursor_type
= NO_CURSOR
;
26715 Display or clear cursor of window W. If ON is zero, clear the
26716 cursor. If it is non-zero, display the cursor. If ON is nonzero,
26717 where to put the cursor is specified by HPOS, VPOS, X and Y. */
26720 display_and_set_cursor (struct window
*w
, int on
,
26721 int hpos
, int vpos
, int x
, int y
)
26723 struct frame
*f
= XFRAME (w
->frame
);
26724 int new_cursor_type
;
26725 int new_cursor_width
;
26727 struct glyph_row
*glyph_row
;
26728 struct glyph
*glyph
;
26730 /* This is pointless on invisible frames, and dangerous on garbaged
26731 windows and frames; in the latter case, the frame or window may
26732 be in the midst of changing its size, and x and y may be off the
26734 if (! FRAME_VISIBLE_P (f
)
26735 || FRAME_GARBAGED_P (f
)
26736 || vpos
>= w
->current_matrix
->nrows
26737 || hpos
>= w
->current_matrix
->matrix_w
)
26740 /* If cursor is off and we want it off, return quickly. */
26741 if (!on
&& !w
->phys_cursor_on_p
)
26744 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26745 /* If cursor row is not enabled, we don't really know where to
26746 display the cursor. */
26747 if (!glyph_row
->enabled_p
)
26749 w
->phys_cursor_on_p
= 0;
26754 if (!glyph_row
->exact_window_width_line_p
26755 || (0 <= hpos
&& hpos
< glyph_row
->used
[TEXT_AREA
]))
26756 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
26758 eassert (input_blocked_p ());
26760 /* Set new_cursor_type to the cursor we want to be displayed. */
26761 new_cursor_type
= get_window_cursor_type (w
, glyph
,
26762 &new_cursor_width
, &active_cursor
);
26764 /* If cursor is currently being shown and we don't want it to be or
26765 it is in the wrong place, or the cursor type is not what we want,
26767 if (w
->phys_cursor_on_p
26769 || w
->phys_cursor
.x
!= x
26770 || w
->phys_cursor
.y
!= y
26771 || new_cursor_type
!= w
->phys_cursor_type
26772 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
26773 && new_cursor_width
!= w
->phys_cursor_width
)))
26774 erase_phys_cursor (w
);
26776 /* Don't check phys_cursor_on_p here because that flag is only set
26777 to zero in some cases where we know that the cursor has been
26778 completely erased, to avoid the extra work of erasing the cursor
26779 twice. In other words, phys_cursor_on_p can be 1 and the cursor
26780 still not be visible, or it has only been partly erased. */
26783 w
->phys_cursor_ascent
= glyph_row
->ascent
;
26784 w
->phys_cursor_height
= glyph_row
->height
;
26786 /* Set phys_cursor_.* before x_draw_.* is called because some
26787 of them may need the information. */
26788 w
->phys_cursor
.x
= x
;
26789 w
->phys_cursor
.y
= glyph_row
->y
;
26790 w
->phys_cursor
.hpos
= hpos
;
26791 w
->phys_cursor
.vpos
= vpos
;
26794 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
26795 new_cursor_type
, new_cursor_width
,
26796 on
, active_cursor
);
26800 /* Switch the display of W's cursor on or off, according to the value
26804 update_window_cursor (struct window
*w
, int on
)
26806 /* Don't update cursor in windows whose frame is in the process
26807 of being deleted. */
26808 if (w
->current_matrix
)
26810 int hpos
= w
->phys_cursor
.hpos
;
26811 int vpos
= w
->phys_cursor
.vpos
;
26812 struct glyph_row
*row
;
26814 if (vpos
>= w
->current_matrix
->nrows
26815 || hpos
>= w
->current_matrix
->matrix_w
)
26818 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26820 /* When the window is hscrolled, cursor hpos can legitimately be
26821 out of bounds, but we draw the cursor at the corresponding
26822 window margin in that case. */
26823 if (!row
->reversed_p
&& hpos
< 0)
26825 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26826 hpos
= row
->used
[TEXT_AREA
] - 1;
26829 display_and_set_cursor (w
, on
, hpos
, vpos
,
26830 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
26836 /* Call update_window_cursor with parameter ON_P on all leaf windows
26837 in the window tree rooted at W. */
26840 update_cursor_in_window_tree (struct window
*w
, int on_p
)
26844 if (WINDOWP (w
->contents
))
26845 update_cursor_in_window_tree (XWINDOW (w
->contents
), on_p
);
26847 update_window_cursor (w
, on_p
);
26849 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
26855 Display the cursor on window W, or clear it, according to ON_P.
26856 Don't change the cursor's position. */
26859 x_update_cursor (struct frame
*f
, int on_p
)
26861 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
26866 Clear the cursor of window W to background color, and mark the
26867 cursor as not shown. This is used when the text where the cursor
26868 is about to be rewritten. */
26871 x_clear_cursor (struct window
*w
)
26873 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
26874 update_window_cursor (w
, 0);
26877 #endif /* HAVE_WINDOW_SYSTEM */
26879 /* Implementation of draw_row_with_mouse_face for GUI sessions, GPM,
26882 draw_row_with_mouse_face (struct window
*w
, int start_x
, struct glyph_row
*row
,
26883 int start_hpos
, int end_hpos
,
26884 enum draw_glyphs_face draw
)
26886 #ifdef HAVE_WINDOW_SYSTEM
26887 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
26889 draw_glyphs (w
, start_x
, row
, TEXT_AREA
, start_hpos
, end_hpos
, draw
, 0);
26893 #if defined (HAVE_GPM) || defined (MSDOS) || defined (WINDOWSNT)
26894 tty_draw_row_with_mouse_face (w
, row
, start_hpos
, end_hpos
, draw
);
26898 /* Display the active region described by mouse_face_* according to DRAW. */
26901 show_mouse_face (Mouse_HLInfo
*hlinfo
, enum draw_glyphs_face draw
)
26903 struct window
*w
= XWINDOW (hlinfo
->mouse_face_window
);
26904 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
26906 if (/* If window is in the process of being destroyed, don't bother
26908 w
->current_matrix
!= NULL
26909 /* Don't update mouse highlight if hidden */
26910 && (draw
!= DRAW_MOUSE_FACE
|| !hlinfo
->mouse_face_hidden
)
26911 /* Recognize when we are called to operate on rows that don't exist
26912 anymore. This can happen when a window is split. */
26913 && hlinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
26915 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
26916 struct glyph_row
*row
, *first
, *last
;
26918 first
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
26919 last
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
26921 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
26923 int start_hpos
, end_hpos
, start_x
;
26925 /* For all but the first row, the highlight starts at column 0. */
26928 /* R2L rows have BEG and END in reversed order, but the
26929 screen drawing geometry is always left to right. So
26930 we need to mirror the beginning and end of the
26931 highlighted area in R2L rows. */
26932 if (!row
->reversed_p
)
26934 start_hpos
= hlinfo
->mouse_face_beg_col
;
26935 start_x
= hlinfo
->mouse_face_beg_x
;
26937 else if (row
== last
)
26939 start_hpos
= hlinfo
->mouse_face_end_col
;
26940 start_x
= hlinfo
->mouse_face_end_x
;
26948 else if (row
->reversed_p
&& row
== last
)
26950 start_hpos
= hlinfo
->mouse_face_end_col
;
26951 start_x
= hlinfo
->mouse_face_end_x
;
26961 if (!row
->reversed_p
)
26962 end_hpos
= hlinfo
->mouse_face_end_col
;
26963 else if (row
== first
)
26964 end_hpos
= hlinfo
->mouse_face_beg_col
;
26967 end_hpos
= row
->used
[TEXT_AREA
];
26968 if (draw
== DRAW_NORMAL_TEXT
)
26969 row
->fill_line_p
= 1; /* Clear to end of line */
26972 else if (row
->reversed_p
&& row
== first
)
26973 end_hpos
= hlinfo
->mouse_face_beg_col
;
26976 end_hpos
= row
->used
[TEXT_AREA
];
26977 if (draw
== DRAW_NORMAL_TEXT
)
26978 row
->fill_line_p
= 1; /* Clear to end of line */
26981 if (end_hpos
> start_hpos
)
26983 draw_row_with_mouse_face (w
, start_x
, row
,
26984 start_hpos
, end_hpos
, draw
);
26987 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
26991 #ifdef HAVE_WINDOW_SYSTEM
26992 /* When we've written over the cursor, arrange for it to
26993 be displayed again. */
26994 if (FRAME_WINDOW_P (f
)
26995 && phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
26997 int hpos
= w
->phys_cursor
.hpos
;
26999 /* When the window is hscrolled, cursor hpos can legitimately be
27000 out of bounds, but we draw the cursor at the corresponding
27001 window margin in that case. */
27002 if (!row
->reversed_p
&& hpos
< 0)
27004 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
27005 hpos
= row
->used
[TEXT_AREA
] - 1;
27008 display_and_set_cursor (w
, 1, hpos
, w
->phys_cursor
.vpos
,
27009 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
27012 #endif /* HAVE_WINDOW_SYSTEM */
27015 #ifdef HAVE_WINDOW_SYSTEM
27016 /* Change the mouse cursor. */
27017 if (FRAME_WINDOW_P (f
))
27019 if (draw
== DRAW_NORMAL_TEXT
27020 && !EQ (hlinfo
->mouse_face_window
, f
->tool_bar_window
))
27021 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
27022 else if (draw
== DRAW_MOUSE_FACE
)
27023 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
27025 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
27027 #endif /* HAVE_WINDOW_SYSTEM */
27031 Clear out the mouse-highlighted active region.
27032 Redraw it un-highlighted first. Value is non-zero if mouse
27033 face was actually drawn unhighlighted. */
27036 clear_mouse_face (Mouse_HLInfo
*hlinfo
)
27040 if (!hlinfo
->mouse_face_hidden
&& !NILP (hlinfo
->mouse_face_window
))
27042 show_mouse_face (hlinfo
, DRAW_NORMAL_TEXT
);
27046 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
27047 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
27048 hlinfo
->mouse_face_window
= Qnil
;
27049 hlinfo
->mouse_face_overlay
= Qnil
;
27053 /* Return non-zero if the coordinates HPOS and VPOS on windows W are
27054 within the mouse face on that window. */
27056 coords_in_mouse_face_p (struct window
*w
, int hpos
, int vpos
)
27058 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
27060 /* Quickly resolve the easy cases. */
27061 if (!(WINDOWP (hlinfo
->mouse_face_window
)
27062 && XWINDOW (hlinfo
->mouse_face_window
) == w
))
27064 if (vpos
< hlinfo
->mouse_face_beg_row
27065 || vpos
> hlinfo
->mouse_face_end_row
)
27067 if (vpos
> hlinfo
->mouse_face_beg_row
27068 && vpos
< hlinfo
->mouse_face_end_row
)
27071 if (!MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
)
27073 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
27075 if (hlinfo
->mouse_face_beg_col
<= hpos
&& hpos
< hlinfo
->mouse_face_end_col
)
27078 else if ((vpos
== hlinfo
->mouse_face_beg_row
27079 && hpos
>= hlinfo
->mouse_face_beg_col
)
27080 || (vpos
== hlinfo
->mouse_face_end_row
27081 && hpos
< hlinfo
->mouse_face_end_col
))
27086 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
27088 if (hlinfo
->mouse_face_end_col
< hpos
&& hpos
<= hlinfo
->mouse_face_beg_col
)
27091 else if ((vpos
== hlinfo
->mouse_face_beg_row
27092 && hpos
<= hlinfo
->mouse_face_beg_col
)
27093 || (vpos
== hlinfo
->mouse_face_end_row
27094 && hpos
> hlinfo
->mouse_face_end_col
))
27102 Non-zero if physical cursor of window W is within mouse face. */
27105 cursor_in_mouse_face_p (struct window
*w
)
27107 int hpos
= w
->phys_cursor
.hpos
;
27108 int vpos
= w
->phys_cursor
.vpos
;
27109 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
27111 /* When the window is hscrolled, cursor hpos can legitimately be out
27112 of bounds, but we draw the cursor at the corresponding window
27113 margin in that case. */
27114 if (!row
->reversed_p
&& hpos
< 0)
27116 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
27117 hpos
= row
->used
[TEXT_AREA
] - 1;
27119 return coords_in_mouse_face_p (w
, hpos
, vpos
);
27124 /* Find the glyph rows START_ROW and END_ROW of window W that display
27125 characters between buffer positions START_CHARPOS and END_CHARPOS
27126 (excluding END_CHARPOS). DISP_STRING is a display string that
27127 covers these buffer positions. This is similar to
27128 row_containing_pos, but is more accurate when bidi reordering makes
27129 buffer positions change non-linearly with glyph rows. */
27131 rows_from_pos_range (struct window
*w
,
27132 ptrdiff_t start_charpos
, ptrdiff_t end_charpos
,
27133 Lisp_Object disp_string
,
27134 struct glyph_row
**start
, struct glyph_row
**end
)
27136 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27137 int last_y
= window_text_bottom_y (w
);
27138 struct glyph_row
*row
;
27143 while (!first
->enabled_p
27144 && first
< MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
27147 /* Find the START row. */
27149 row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
;
27152 /* A row can potentially be the START row if the range of the
27153 characters it displays intersects the range
27154 [START_CHARPOS..END_CHARPOS). */
27155 if (! ((start_charpos
< MATRIX_ROW_START_CHARPOS (row
)
27156 && end_charpos
< MATRIX_ROW_START_CHARPOS (row
))
27157 /* See the commentary in row_containing_pos, for the
27158 explanation of the complicated way to check whether
27159 some position is beyond the end of the characters
27160 displayed by a row. */
27161 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (row
)
27162 || (start_charpos
== MATRIX_ROW_END_CHARPOS (row
)
27163 && !row
->ends_at_zv_p
27164 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
27165 && (end_charpos
> MATRIX_ROW_END_CHARPOS (row
)
27166 || (end_charpos
== MATRIX_ROW_END_CHARPOS (row
)
27167 && !row
->ends_at_zv_p
27168 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))))
27170 /* Found a candidate row. Now make sure at least one of the
27171 glyphs it displays has a charpos from the range
27172 [START_CHARPOS..END_CHARPOS).
27174 This is not obvious because bidi reordering could make
27175 buffer positions of a row be 1,2,3,102,101,100, and if we
27176 want to highlight characters in [50..60), we don't want
27177 this row, even though [50..60) does intersect [1..103),
27178 the range of character positions given by the row's start
27179 and end positions. */
27180 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
27181 struct glyph
*e
= g
+ row
->used
[TEXT_AREA
];
27185 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
27186 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
27187 /* A glyph that comes from DISP_STRING is by
27188 definition to be highlighted. */
27189 || EQ (g
->object
, disp_string
))
27198 /* Find the END row. */
27200 /* If the last row is partially visible, start looking for END
27201 from that row, instead of starting from FIRST. */
27202 && !(row
->enabled_p
27203 && row
->y
< last_y
&& MATRIX_ROW_BOTTOM_Y (row
) > last_y
))
27205 for ( ; row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
; row
++)
27207 struct glyph_row
*next
= row
+ 1;
27208 ptrdiff_t next_start
= MATRIX_ROW_START_CHARPOS (next
);
27210 if (!next
->enabled_p
27211 || next
>= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
)
27212 /* The first row >= START whose range of displayed characters
27213 does NOT intersect the range [START_CHARPOS..END_CHARPOS]
27214 is the row END + 1. */
27215 || (start_charpos
< next_start
27216 && end_charpos
< next_start
)
27217 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (next
)
27218 || (start_charpos
== MATRIX_ROW_END_CHARPOS (next
)
27219 && !next
->ends_at_zv_p
27220 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))
27221 && (end_charpos
> MATRIX_ROW_END_CHARPOS (next
)
27222 || (end_charpos
== MATRIX_ROW_END_CHARPOS (next
)
27223 && !next
->ends_at_zv_p
27224 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))))
27231 /* If the next row's edges intersect [START_CHARPOS..END_CHARPOS],
27232 but none of the characters it displays are in the range, it is
27234 struct glyph
*g
= next
->glyphs
[TEXT_AREA
];
27235 struct glyph
*s
= g
;
27236 struct glyph
*e
= g
+ next
->used
[TEXT_AREA
];
27240 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
27241 && ((start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
27242 /* If the buffer position of the first glyph in
27243 the row is equal to END_CHARPOS, it means
27244 the last character to be highlighted is the
27245 newline of ROW, and we must consider NEXT as
27247 || (((!next
->reversed_p
&& g
== s
)
27248 || (next
->reversed_p
&& g
== e
- 1))
27249 && (g
->charpos
== end_charpos
27250 /* Special case for when NEXT is an
27251 empty line at ZV. */
27252 || (g
->charpos
== -1
27253 && !row
->ends_at_zv_p
27254 && next_start
== end_charpos
)))))
27255 /* A glyph that comes from DISP_STRING is by
27256 definition to be highlighted. */
27257 || EQ (g
->object
, disp_string
))
27266 /* The first row that ends at ZV must be the last to be
27268 else if (next
->ends_at_zv_p
)
27277 /* This function sets the mouse_face_* elements of HLINFO, assuming
27278 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
27279 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
27280 for the overlay or run of text properties specifying the mouse
27281 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
27282 before-string and after-string that must also be highlighted.
27283 DISP_STRING, if non-nil, is a display string that may cover some
27284 or all of the highlighted text. */
27287 mouse_face_from_buffer_pos (Lisp_Object window
,
27288 Mouse_HLInfo
*hlinfo
,
27289 ptrdiff_t mouse_charpos
,
27290 ptrdiff_t start_charpos
,
27291 ptrdiff_t end_charpos
,
27292 Lisp_Object before_string
,
27293 Lisp_Object after_string
,
27294 Lisp_Object disp_string
)
27296 struct window
*w
= XWINDOW (window
);
27297 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27298 struct glyph_row
*r1
, *r2
;
27299 struct glyph
*glyph
, *end
;
27300 ptrdiff_t ignore
, pos
;
27303 eassert (NILP (disp_string
) || STRINGP (disp_string
));
27304 eassert (NILP (before_string
) || STRINGP (before_string
));
27305 eassert (NILP (after_string
) || STRINGP (after_string
));
27307 /* Find the rows corresponding to START_CHARPOS and END_CHARPOS. */
27308 rows_from_pos_range (w
, start_charpos
, end_charpos
, disp_string
, &r1
, &r2
);
27310 r1
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
27311 /* If the before-string or display-string contains newlines,
27312 rows_from_pos_range skips to its last row. Move back. */
27313 if (!NILP (before_string
) || !NILP (disp_string
))
27315 struct glyph_row
*prev
;
27316 while ((prev
= r1
- 1, prev
>= first
)
27317 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
27318 && prev
->used
[TEXT_AREA
] > 0)
27320 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
27321 glyph
= beg
+ prev
->used
[TEXT_AREA
];
27322 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
27324 || !(EQ (glyph
->object
, before_string
)
27325 || EQ (glyph
->object
, disp_string
)))
27332 r2
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
27333 hlinfo
->mouse_face_past_end
= 1;
27335 else if (!NILP (after_string
))
27337 /* If the after-string has newlines, advance to its last row. */
27338 struct glyph_row
*next
;
27339 struct glyph_row
*last
27340 = MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
27342 for (next
= r2
+ 1;
27344 && next
->used
[TEXT_AREA
] > 0
27345 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
27349 /* The rest of the display engine assumes that mouse_face_beg_row is
27350 either above mouse_face_end_row or identical to it. But with
27351 bidi-reordered continued lines, the row for START_CHARPOS could
27352 be below the row for END_CHARPOS. If so, swap the rows and store
27353 them in correct order. */
27356 struct glyph_row
*tem
= r2
;
27362 hlinfo
->mouse_face_beg_y
= r1
->y
;
27363 hlinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (r1
, w
->current_matrix
);
27364 hlinfo
->mouse_face_end_y
= r2
->y
;
27365 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r2
, w
->current_matrix
);
27367 /* For a bidi-reordered row, the positions of BEFORE_STRING,
27368 AFTER_STRING, DISP_STRING, START_CHARPOS, and END_CHARPOS
27369 could be anywhere in the row and in any order. The strategy
27370 below is to find the leftmost and the rightmost glyph that
27371 belongs to either of these 3 strings, or whose position is
27372 between START_CHARPOS and END_CHARPOS, and highlight all the
27373 glyphs between those two. This may cover more than just the text
27374 between START_CHARPOS and END_CHARPOS if the range of characters
27375 strides the bidi level boundary, e.g. if the beginning is in R2L
27376 text while the end is in L2R text or vice versa. */
27377 if (!r1
->reversed_p
)
27379 /* This row is in a left to right paragraph. Scan it left to
27381 glyph
= r1
->glyphs
[TEXT_AREA
];
27382 end
= glyph
+ r1
->used
[TEXT_AREA
];
27385 /* Skip truncation glyphs at the start of the glyph row. */
27386 if (MATRIX_ROW_DISPLAYS_TEXT_P (r1
))
27388 && INTEGERP (glyph
->object
)
27389 && glyph
->charpos
< 0;
27391 x
+= glyph
->pixel_width
;
27393 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
27394 or DISP_STRING, and the first glyph from buffer whose
27395 position is between START_CHARPOS and END_CHARPOS. */
27397 && !INTEGERP (glyph
->object
)
27398 && !EQ (glyph
->object
, disp_string
)
27399 && !(BUFFERP (glyph
->object
)
27400 && (glyph
->charpos
>= start_charpos
27401 && glyph
->charpos
< end_charpos
));
27404 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27405 are present at buffer positions between START_CHARPOS and
27406 END_CHARPOS, or if they come from an overlay. */
27407 if (EQ (glyph
->object
, before_string
))
27409 pos
= string_buffer_position (before_string
,
27411 /* If pos == 0, it means before_string came from an
27412 overlay, not from a buffer position. */
27413 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27416 else if (EQ (glyph
->object
, after_string
))
27418 pos
= string_buffer_position (after_string
, end_charpos
);
27419 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27422 x
+= glyph
->pixel_width
;
27424 hlinfo
->mouse_face_beg_x
= x
;
27425 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
27429 /* This row is in a right to left paragraph. Scan it right to
27433 end
= r1
->glyphs
[TEXT_AREA
] - 1;
27434 glyph
= end
+ r1
->used
[TEXT_AREA
];
27436 /* Skip truncation glyphs at the start of the glyph row. */
27437 if (MATRIX_ROW_DISPLAYS_TEXT_P (r1
))
27439 && INTEGERP (glyph
->object
)
27440 && glyph
->charpos
< 0;
27444 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
27445 or DISP_STRING, and the first glyph from buffer whose
27446 position is between START_CHARPOS and END_CHARPOS. */
27448 && !INTEGERP (glyph
->object
)
27449 && !EQ (glyph
->object
, disp_string
)
27450 && !(BUFFERP (glyph
->object
)
27451 && (glyph
->charpos
>= start_charpos
27452 && glyph
->charpos
< end_charpos
));
27455 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27456 are present at buffer positions between START_CHARPOS and
27457 END_CHARPOS, or if they come from an overlay. */
27458 if (EQ (glyph
->object
, before_string
))
27460 pos
= string_buffer_position (before_string
, start_charpos
);
27461 /* If pos == 0, it means before_string came from an
27462 overlay, not from a buffer position. */
27463 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27466 else if (EQ (glyph
->object
, after_string
))
27468 pos
= string_buffer_position (after_string
, end_charpos
);
27469 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27474 glyph
++; /* first glyph to the right of the highlighted area */
27475 for (g
= r1
->glyphs
[TEXT_AREA
], x
= r1
->x
; g
< glyph
; g
++)
27476 x
+= g
->pixel_width
;
27477 hlinfo
->mouse_face_beg_x
= x
;
27478 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
27481 /* If the highlight ends in a different row, compute GLYPH and END
27482 for the end row. Otherwise, reuse the values computed above for
27483 the row where the highlight begins. */
27486 if (!r2
->reversed_p
)
27488 glyph
= r2
->glyphs
[TEXT_AREA
];
27489 end
= glyph
+ r2
->used
[TEXT_AREA
];
27494 end
= r2
->glyphs
[TEXT_AREA
] - 1;
27495 glyph
= end
+ r2
->used
[TEXT_AREA
];
27499 if (!r2
->reversed_p
)
27501 /* Skip truncation and continuation glyphs near the end of the
27502 row, and also blanks and stretch glyphs inserted by
27503 extend_face_to_end_of_line. */
27505 && INTEGERP ((end
- 1)->object
))
27507 /* Scan the rest of the glyph row from the end, looking for the
27508 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
27509 DISP_STRING, or whose position is between START_CHARPOS
27513 && !INTEGERP (end
->object
)
27514 && !EQ (end
->object
, disp_string
)
27515 && !(BUFFERP (end
->object
)
27516 && (end
->charpos
>= start_charpos
27517 && end
->charpos
< end_charpos
));
27520 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27521 are present at buffer positions between START_CHARPOS and
27522 END_CHARPOS, or if they come from an overlay. */
27523 if (EQ (end
->object
, before_string
))
27525 pos
= string_buffer_position (before_string
, start_charpos
);
27526 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27529 else if (EQ (end
->object
, after_string
))
27531 pos
= string_buffer_position (after_string
, end_charpos
);
27532 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27536 /* Find the X coordinate of the last glyph to be highlighted. */
27537 for (; glyph
<= end
; ++glyph
)
27538 x
+= glyph
->pixel_width
;
27540 hlinfo
->mouse_face_end_x
= x
;
27541 hlinfo
->mouse_face_end_col
= glyph
- r2
->glyphs
[TEXT_AREA
];
27545 /* Skip truncation and continuation glyphs near the end of the
27546 row, and also blanks and stretch glyphs inserted by
27547 extend_face_to_end_of_line. */
27551 && INTEGERP (end
->object
))
27553 x
+= end
->pixel_width
;
27556 /* Scan the rest of the glyph row from the end, looking for the
27557 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
27558 DISP_STRING, or whose position is between START_CHARPOS
27562 && !INTEGERP (end
->object
)
27563 && !EQ (end
->object
, disp_string
)
27564 && !(BUFFERP (end
->object
)
27565 && (end
->charpos
>= start_charpos
27566 && end
->charpos
< end_charpos
));
27569 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27570 are present at buffer positions between START_CHARPOS and
27571 END_CHARPOS, or if they come from an overlay. */
27572 if (EQ (end
->object
, before_string
))
27574 pos
= string_buffer_position (before_string
, start_charpos
);
27575 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27578 else if (EQ (end
->object
, after_string
))
27580 pos
= string_buffer_position (after_string
, end_charpos
);
27581 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27584 x
+= end
->pixel_width
;
27586 /* If we exited the above loop because we arrived at the last
27587 glyph of the row, and its buffer position is still not in
27588 range, it means the last character in range is the preceding
27589 newline. Bump the end column and x values to get past the
27592 && BUFFERP (end
->object
)
27593 && (end
->charpos
< start_charpos
27594 || end
->charpos
>= end_charpos
))
27596 x
+= end
->pixel_width
;
27599 hlinfo
->mouse_face_end_x
= x
;
27600 hlinfo
->mouse_face_end_col
= end
- r2
->glyphs
[TEXT_AREA
];
27603 hlinfo
->mouse_face_window
= window
;
27604 hlinfo
->mouse_face_face_id
27605 = face_at_buffer_position (w
, mouse_charpos
, 0, 0, &ignore
,
27607 !hlinfo
->mouse_face_hidden
, -1);
27608 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
27611 /* The following function is not used anymore (replaced with
27612 mouse_face_from_string_pos), but I leave it here for the time
27613 being, in case someone would. */
27615 #if 0 /* not used */
27617 /* Find the position of the glyph for position POS in OBJECT in
27618 window W's current matrix, and return in *X, *Y the pixel
27619 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
27621 RIGHT_P non-zero means return the position of the right edge of the
27622 glyph, RIGHT_P zero means return the left edge position.
27624 If no glyph for POS exists in the matrix, return the position of
27625 the glyph with the next smaller position that is in the matrix, if
27626 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
27627 exists in the matrix, return the position of the glyph with the
27628 next larger position in OBJECT.
27630 Value is non-zero if a glyph was found. */
27633 fast_find_string_pos (struct window
*w
, ptrdiff_t pos
, Lisp_Object object
,
27634 int *hpos
, int *vpos
, int *x
, int *y
, int right_p
)
27636 int yb
= window_text_bottom_y (w
);
27637 struct glyph_row
*r
;
27638 struct glyph
*best_glyph
= NULL
;
27639 struct glyph_row
*best_row
= NULL
;
27642 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27643 r
->enabled_p
&& r
->y
< yb
;
27646 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
27647 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
27650 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
27651 if (EQ (g
->object
, object
))
27653 if (g
->charpos
== pos
)
27660 else if (best_glyph
== NULL
27661 || ((eabs (g
->charpos
- pos
)
27662 < eabs (best_glyph
->charpos
- pos
))
27665 : g
->charpos
> pos
)))
27679 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
27683 *x
+= best_glyph
->pixel_width
;
27688 *vpos
= MATRIX_ROW_VPOS (best_row
, w
->current_matrix
);
27691 return best_glyph
!= NULL
;
27693 #endif /* not used */
27695 /* Find the positions of the first and the last glyphs in window W's
27696 current matrix that occlude positions [STARTPOS..ENDPOS] in OBJECT
27697 (assumed to be a string), and return in HLINFO's mouse_face_*
27698 members the pixel and column/row coordinates of those glyphs. */
27701 mouse_face_from_string_pos (struct window
*w
, Mouse_HLInfo
*hlinfo
,
27702 Lisp_Object object
,
27703 ptrdiff_t startpos
, ptrdiff_t endpos
)
27705 int yb
= window_text_bottom_y (w
);
27706 struct glyph_row
*r
;
27707 struct glyph
*g
, *e
;
27711 /* Find the glyph row with at least one position in the range
27712 [STARTPOS..ENDPOS], and the first glyph in that row whose
27713 position belongs to that range. */
27714 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27715 r
->enabled_p
&& r
->y
< yb
;
27718 if (!r
->reversed_p
)
27720 g
= r
->glyphs
[TEXT_AREA
];
27721 e
= g
+ r
->used
[TEXT_AREA
];
27722 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
27723 if (EQ (g
->object
, object
)
27724 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
27726 hlinfo
->mouse_face_beg_row
27727 = MATRIX_ROW_VPOS (r
, w
->current_matrix
);
27728 hlinfo
->mouse_face_beg_y
= r
->y
;
27729 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
27730 hlinfo
->mouse_face_beg_x
= gx
;
27739 e
= r
->glyphs
[TEXT_AREA
];
27740 g
= e
+ r
->used
[TEXT_AREA
];
27741 for ( ; g
> e
; --g
)
27742 if (EQ ((g
-1)->object
, object
)
27743 && startpos
<= (g
-1)->charpos
&& (g
-1)->charpos
<= endpos
)
27745 hlinfo
->mouse_face_beg_row
27746 = MATRIX_ROW_VPOS (r
, w
->current_matrix
);
27747 hlinfo
->mouse_face_beg_y
= r
->y
;
27748 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
27749 for (gx
= r
->x
, g1
= r
->glyphs
[TEXT_AREA
]; g1
< g
; ++g1
)
27750 gx
+= g1
->pixel_width
;
27751 hlinfo
->mouse_face_beg_x
= gx
;
27763 /* Starting with the next row, look for the first row which does NOT
27764 include any glyphs whose positions are in the range. */
27765 for (++r
; r
->enabled_p
&& r
->y
< yb
; ++r
)
27767 g
= r
->glyphs
[TEXT_AREA
];
27768 e
= g
+ r
->used
[TEXT_AREA
];
27770 for ( ; g
< e
; ++g
)
27771 if (EQ (g
->object
, object
)
27772 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
27781 /* The highlighted region ends on the previous row. */
27784 /* Set the end row and its vertical pixel coordinate. */
27785 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r
, w
->current_matrix
);
27786 hlinfo
->mouse_face_end_y
= r
->y
;
27788 /* Compute and set the end column and the end column's horizontal
27789 pixel coordinate. */
27790 if (!r
->reversed_p
)
27792 g
= r
->glyphs
[TEXT_AREA
];
27793 e
= g
+ r
->used
[TEXT_AREA
];
27794 for ( ; e
> g
; --e
)
27795 if (EQ ((e
-1)->object
, object
)
27796 && startpos
<= (e
-1)->charpos
&& (e
-1)->charpos
<= endpos
)
27798 hlinfo
->mouse_face_end_col
= e
- g
;
27800 for (gx
= r
->x
; g
< e
; ++g
)
27801 gx
+= g
->pixel_width
;
27802 hlinfo
->mouse_face_end_x
= gx
;
27806 e
= r
->glyphs
[TEXT_AREA
];
27807 g
= e
+ r
->used
[TEXT_AREA
];
27808 for (gx
= r
->x
; e
< g
; ++e
)
27810 if (EQ (e
->object
, object
)
27811 && startpos
<= e
->charpos
&& e
->charpos
<= endpos
)
27813 gx
+= e
->pixel_width
;
27815 hlinfo
->mouse_face_end_col
= e
- r
->glyphs
[TEXT_AREA
];
27816 hlinfo
->mouse_face_end_x
= gx
;
27820 #ifdef HAVE_WINDOW_SYSTEM
27822 /* See if position X, Y is within a hot-spot of an image. */
27825 on_hot_spot_p (Lisp_Object hot_spot
, int x
, int y
)
27827 if (!CONSP (hot_spot
))
27830 if (EQ (XCAR (hot_spot
), Qrect
))
27832 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
27833 Lisp_Object rect
= XCDR (hot_spot
);
27837 if (!CONSP (XCAR (rect
)))
27839 if (!CONSP (XCDR (rect
)))
27841 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
27843 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
27845 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
27847 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
27851 else if (EQ (XCAR (hot_spot
), Qcircle
))
27853 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
27854 Lisp_Object circ
= XCDR (hot_spot
);
27855 Lisp_Object lr
, lx0
, ly0
;
27857 && CONSP (XCAR (circ
))
27858 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
27859 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
27860 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
27862 double r
= XFLOATINT (lr
);
27863 double dx
= XINT (lx0
) - x
;
27864 double dy
= XINT (ly0
) - y
;
27865 return (dx
* dx
+ dy
* dy
<= r
* r
);
27868 else if (EQ (XCAR (hot_spot
), Qpoly
))
27870 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
27871 if (VECTORP (XCDR (hot_spot
)))
27873 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
27874 Lisp_Object
*poly
= v
->contents
;
27875 ptrdiff_t n
= v
->header
.size
;
27878 Lisp_Object lx
, ly
;
27881 /* Need an even number of coordinates, and at least 3 edges. */
27882 if (n
< 6 || n
& 1)
27885 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
27886 If count is odd, we are inside polygon. Pixels on edges
27887 may or may not be included depending on actual geometry of the
27889 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
27890 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
27892 x0
= XINT (lx
), y0
= XINT (ly
);
27893 for (i
= 0; i
< n
; i
+= 2)
27895 int x1
= x0
, y1
= y0
;
27896 if ((lx
= poly
[i
], !INTEGERP (lx
))
27897 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
27899 x0
= XINT (lx
), y0
= XINT (ly
);
27901 /* Does this segment cross the X line? */
27909 if (y
> y0
&& y
> y1
)
27911 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
27921 find_hot_spot (Lisp_Object map
, int x
, int y
)
27923 while (CONSP (map
))
27925 if (CONSP (XCAR (map
))
27926 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
27934 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
27936 doc
: /* Lookup in image map MAP coordinates X and Y.
27937 An image map is an alist where each element has the format (AREA ID PLIST).
27938 An AREA is specified as either a rectangle, a circle, or a polygon:
27939 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
27940 pixel coordinates of the upper left and bottom right corners.
27941 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
27942 and the radius of the circle; r may be a float or integer.
27943 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
27944 vector describes one corner in the polygon.
27945 Returns the alist element for the first matching AREA in MAP. */)
27946 (Lisp_Object map
, Lisp_Object x
, Lisp_Object y
)
27954 return find_hot_spot (map
,
27955 clip_to_bounds (INT_MIN
, XINT (x
), INT_MAX
),
27956 clip_to_bounds (INT_MIN
, XINT (y
), INT_MAX
));
27960 /* Display frame CURSOR, optionally using shape defined by POINTER. */
27962 define_frame_cursor1 (struct frame
*f
, Cursor cursor
, Lisp_Object pointer
)
27964 /* Do not change cursor shape while dragging mouse. */
27965 if (!NILP (do_mouse_tracking
))
27968 if (!NILP (pointer
))
27970 if (EQ (pointer
, Qarrow
))
27971 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27972 else if (EQ (pointer
, Qhand
))
27973 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
27974 else if (EQ (pointer
, Qtext
))
27975 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
27976 else if (EQ (pointer
, intern ("hdrag")))
27977 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
27978 #ifdef HAVE_X_WINDOWS
27979 else if (EQ (pointer
, intern ("vdrag")))
27980 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
27982 else if (EQ (pointer
, intern ("hourglass")))
27983 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
27984 else if (EQ (pointer
, Qmodeline
))
27985 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
27987 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27990 if (cursor
!= No_Cursor
)
27991 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
27994 #endif /* HAVE_WINDOW_SYSTEM */
27996 /* Take proper action when mouse has moved to the mode or header line
27997 or marginal area AREA of window W, x-position X and y-position Y.
27998 X is relative to the start of the text display area of W, so the
27999 width of bitmap areas and scroll bars must be subtracted to get a
28000 position relative to the start of the mode line. */
28003 note_mode_line_or_margin_highlight (Lisp_Object window
, int x
, int y
,
28004 enum window_part area
)
28006 struct window
*w
= XWINDOW (window
);
28007 struct frame
*f
= XFRAME (w
->frame
);
28008 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28009 #ifdef HAVE_WINDOW_SYSTEM
28010 Display_Info
*dpyinfo
;
28012 Cursor cursor
= No_Cursor
;
28013 Lisp_Object pointer
= Qnil
;
28014 int dx
, dy
, width
, height
;
28016 Lisp_Object string
, object
= Qnil
;
28017 Lisp_Object pos
IF_LINT (= Qnil
), help
;
28019 Lisp_Object mouse_face
;
28020 int original_x_pixel
= x
;
28021 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
28022 struct glyph_row
*row
IF_LINT (= 0);
28024 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
28029 /* Kludge alert: mode_line_string takes X/Y in pixels, but
28030 returns them in row/column units! */
28031 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
28032 &object
, &dx
, &dy
, &width
, &height
);
28034 row
= (area
== ON_MODE_LINE
28035 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
28036 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
28038 /* Find the glyph under the mouse pointer. */
28039 if (row
->mode_line_p
&& row
->enabled_p
)
28041 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
28042 end
= glyph
+ row
->used
[TEXT_AREA
];
28044 for (x0
= original_x_pixel
;
28045 glyph
< end
&& x0
>= glyph
->pixel_width
;
28047 x0
-= glyph
->pixel_width
;
28055 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
28056 /* Kludge alert: marginal_area_string takes X/Y in pixels, but
28057 returns them in row/column units! */
28058 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
28059 &object
, &dx
, &dy
, &width
, &height
);
28064 #ifdef HAVE_WINDOW_SYSTEM
28065 if (IMAGEP (object
))
28067 Lisp_Object image_map
, hotspot
;
28068 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
28070 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
28072 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
28076 /* Could check XCAR (hotspot) to see if we enter/leave this hot-spot.
28077 If so, we could look for mouse-enter, mouse-leave
28078 properties in PLIST (and do something...). */
28079 hotspot
= XCDR (hotspot
);
28080 if (CONSP (hotspot
)
28081 && (plist
= XCAR (hotspot
), CONSP (plist
)))
28083 pointer
= Fplist_get (plist
, Qpointer
);
28084 if (NILP (pointer
))
28086 help
= Fplist_get (plist
, Qhelp_echo
);
28089 help_echo_string
= help
;
28090 XSETWINDOW (help_echo_window
, w
);
28091 help_echo_object
= w
->contents
;
28092 help_echo_pos
= charpos
;
28096 if (NILP (pointer
))
28097 pointer
= Fplist_get (XCDR (object
), QCpointer
);
28099 #endif /* HAVE_WINDOW_SYSTEM */
28101 if (STRINGP (string
))
28102 pos
= make_number (charpos
);
28104 /* Set the help text and mouse pointer. If the mouse is on a part
28105 of the mode line without any text (e.g. past the right edge of
28106 the mode line text), use the default help text and pointer. */
28107 if (STRINGP (string
) || area
== ON_MODE_LINE
)
28109 /* Arrange to display the help by setting the global variables
28110 help_echo_string, help_echo_object, and help_echo_pos. */
28113 if (STRINGP (string
))
28114 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
28118 help_echo_string
= help
;
28119 XSETWINDOW (help_echo_window
, w
);
28120 help_echo_object
= string
;
28121 help_echo_pos
= charpos
;
28123 else if (area
== ON_MODE_LINE
)
28125 Lisp_Object default_help
28126 = buffer_local_value_1 (Qmode_line_default_help_echo
,
28129 if (STRINGP (default_help
))
28131 help_echo_string
= default_help
;
28132 XSETWINDOW (help_echo_window
, w
);
28133 help_echo_object
= Qnil
;
28134 help_echo_pos
= -1;
28139 #ifdef HAVE_WINDOW_SYSTEM
28140 /* Change the mouse pointer according to what is under it. */
28141 if (FRAME_WINDOW_P (f
))
28143 dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
28144 if (STRINGP (string
))
28146 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
28148 if (NILP (pointer
))
28149 pointer
= Fget_text_property (pos
, Qpointer
, string
);
28151 /* Change the mouse pointer according to what is under X/Y. */
28153 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
28156 map
= Fget_text_property (pos
, Qlocal_map
, string
);
28157 if (!KEYMAPP (map
))
28158 map
= Fget_text_property (pos
, Qkeymap
, string
);
28159 if (!KEYMAPP (map
))
28160 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
28164 /* Default mode-line pointer. */
28165 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
28170 /* Change the mouse face according to what is under X/Y. */
28171 if (STRINGP (string
))
28173 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
28174 if (!NILP (Vmouse_highlight
) && !NILP (mouse_face
)
28175 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
28180 struct glyph
* tmp_glyph
;
28184 int total_pixel_width
;
28185 ptrdiff_t begpos
, endpos
, ignore
;
28189 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
28190 Qmouse_face
, string
, Qnil
);
28196 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
28198 endpos
= SCHARS (string
);
28202 /* Calculate the glyph position GPOS of GLYPH in the
28203 displayed string, relative to the beginning of the
28204 highlighted part of the string.
28206 Note: GPOS is different from CHARPOS. CHARPOS is the
28207 position of GLYPH in the internal string object. A mode
28208 line string format has structures which are converted to
28209 a flattened string by the Emacs Lisp interpreter. The
28210 internal string is an element of those structures. The
28211 displayed string is the flattened string. */
28212 tmp_glyph
= row_start_glyph
;
28213 while (tmp_glyph
< glyph
28214 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
28215 && begpos
<= tmp_glyph
->charpos
28216 && tmp_glyph
->charpos
< endpos
)))
28218 gpos
= glyph
- tmp_glyph
;
28220 /* Calculate the length GSEQ_LENGTH of the glyph sequence of
28221 the highlighted part of the displayed string to which
28222 GLYPH belongs. Note: GSEQ_LENGTH is different from
28223 SCHARS (STRING), because the latter returns the length of
28224 the internal string. */
28225 for (tmp_glyph
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
28227 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
28228 && begpos
<= tmp_glyph
->charpos
28229 && tmp_glyph
->charpos
< endpos
));
28232 gseq_length
= gpos
+ (tmp_glyph
- glyph
) + 1;
28234 /* Calculate the total pixel width of all the glyphs between
28235 the beginning of the highlighted area and GLYPH. */
28236 total_pixel_width
= 0;
28237 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
28238 total_pixel_width
+= tmp_glyph
->pixel_width
;
28240 /* Pre calculation of re-rendering position. Note: X is in
28241 column units here, after the call to mode_line_string or
28242 marginal_area_string. */
28244 vpos
= (area
== ON_MODE_LINE
28245 ? (w
->current_matrix
)->nrows
- 1
28248 /* If GLYPH's position is included in the region that is
28249 already drawn in mouse face, we have nothing to do. */
28250 if ( EQ (window
, hlinfo
->mouse_face_window
)
28251 && (!row
->reversed_p
28252 ? (hlinfo
->mouse_face_beg_col
<= hpos
28253 && hpos
< hlinfo
->mouse_face_end_col
)
28254 /* In R2L rows we swap BEG and END, see below. */
28255 : (hlinfo
->mouse_face_end_col
<= hpos
28256 && hpos
< hlinfo
->mouse_face_beg_col
))
28257 && hlinfo
->mouse_face_beg_row
== vpos
)
28260 if (clear_mouse_face (hlinfo
))
28261 cursor
= No_Cursor
;
28263 if (!row
->reversed_p
)
28265 hlinfo
->mouse_face_beg_col
= hpos
;
28266 hlinfo
->mouse_face_beg_x
= original_x_pixel
28267 - (total_pixel_width
+ dx
);
28268 hlinfo
->mouse_face_end_col
= hpos
+ gseq_length
;
28269 hlinfo
->mouse_face_end_x
= 0;
28273 /* In R2L rows, show_mouse_face expects BEG and END
28274 coordinates to be swapped. */
28275 hlinfo
->mouse_face_end_col
= hpos
;
28276 hlinfo
->mouse_face_end_x
= original_x_pixel
28277 - (total_pixel_width
+ dx
);
28278 hlinfo
->mouse_face_beg_col
= hpos
+ gseq_length
;
28279 hlinfo
->mouse_face_beg_x
= 0;
28282 hlinfo
->mouse_face_beg_row
= vpos
;
28283 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_beg_row
;
28284 hlinfo
->mouse_face_beg_y
= 0;
28285 hlinfo
->mouse_face_end_y
= 0;
28286 hlinfo
->mouse_face_past_end
= 0;
28287 hlinfo
->mouse_face_window
= window
;
28289 hlinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
28295 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
28297 if (NILP (pointer
))
28300 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
28301 clear_mouse_face (hlinfo
);
28303 #ifdef HAVE_WINDOW_SYSTEM
28304 if (FRAME_WINDOW_P (f
))
28305 define_frame_cursor1 (f
, cursor
, pointer
);
28311 Take proper action when the mouse has moved to position X, Y on
28312 frame F with regards to highlighting portions of display that have
28313 mouse-face properties. Also de-highlight portions of display where
28314 the mouse was before, set the mouse pointer shape as appropriate
28315 for the mouse coordinates, and activate help echo (tooltips).
28316 X and Y can be negative or out of range. */
28319 note_mouse_highlight (struct frame
*f
, int x
, int y
)
28321 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28322 enum window_part part
= ON_NOTHING
;
28323 Lisp_Object window
;
28325 Cursor cursor
= No_Cursor
;
28326 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
28329 /* When a menu is active, don't highlight because this looks odd. */
28330 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (MSDOS)
28331 if (popup_activated ())
28335 if (!f
->glyphs_initialized_p
28336 || f
->pointer_invisible
)
28339 hlinfo
->mouse_face_mouse_x
= x
;
28340 hlinfo
->mouse_face_mouse_y
= y
;
28341 hlinfo
->mouse_face_mouse_frame
= f
;
28343 if (hlinfo
->mouse_face_defer
)
28346 /* Which window is that in? */
28347 window
= window_from_coordinates (f
, x
, y
, &part
, 1);
28349 /* If displaying active text in another window, clear that. */
28350 if (! EQ (window
, hlinfo
->mouse_face_window
)
28351 /* Also clear if we move out of text area in same window. */
28352 || (!NILP (hlinfo
->mouse_face_window
)
28355 && part
!= ON_MODE_LINE
28356 && part
!= ON_HEADER_LINE
))
28357 clear_mouse_face (hlinfo
);
28359 /* Not on a window -> return. */
28360 if (!WINDOWP (window
))
28363 /* Reset help_echo_string. It will get recomputed below. */
28364 help_echo_string
= Qnil
;
28366 /* Convert to window-relative pixel coordinates. */
28367 w
= XWINDOW (window
);
28368 frame_to_window_pixel_xy (w
, &x
, &y
);
28370 #ifdef HAVE_WINDOW_SYSTEM
28371 /* Handle tool-bar window differently since it doesn't display a
28373 if (EQ (window
, f
->tool_bar_window
))
28375 note_tool_bar_highlight (f
, x
, y
);
28380 /* Mouse is on the mode, header line or margin? */
28381 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
28382 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
28384 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
28388 #ifdef HAVE_WINDOW_SYSTEM
28389 if (part
== ON_VERTICAL_BORDER
)
28391 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
28392 help_echo_string
= build_string ("drag-mouse-1: resize");
28394 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
28395 || part
== ON_SCROLL_BAR
)
28396 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
28398 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
28401 /* Are we in a window whose display is up to date?
28402 And verify the buffer's text has not changed. */
28403 b
= XBUFFER (w
->contents
);
28404 if (part
== ON_TEXT
&& w
->window_end_valid
&& !window_outdated (w
))
28406 int hpos
, vpos
, dx
, dy
, area
= LAST_AREA
;
28408 struct glyph
*glyph
;
28409 Lisp_Object object
;
28410 Lisp_Object mouse_face
= Qnil
, position
;
28411 Lisp_Object
*overlay_vec
= NULL
;
28412 ptrdiff_t i
, noverlays
;
28413 struct buffer
*obuf
;
28414 ptrdiff_t obegv
, ozv
;
28417 /* Find the glyph under X/Y. */
28418 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
28420 #ifdef HAVE_WINDOW_SYSTEM
28421 /* Look for :pointer property on image. */
28422 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
28424 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
28425 if (img
!= NULL
&& IMAGEP (img
->spec
))
28427 Lisp_Object image_map
, hotspot
;
28428 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
28430 && (hotspot
= find_hot_spot (image_map
,
28431 glyph
->slice
.img
.x
+ dx
,
28432 glyph
->slice
.img
.y
+ dy
),
28434 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
28438 /* Could check XCAR (hotspot) to see if we enter/leave
28440 If so, we could look for mouse-enter, mouse-leave
28441 properties in PLIST (and do something...). */
28442 hotspot
= XCDR (hotspot
);
28443 if (CONSP (hotspot
)
28444 && (plist
= XCAR (hotspot
), CONSP (plist
)))
28446 pointer
= Fplist_get (plist
, Qpointer
);
28447 if (NILP (pointer
))
28449 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
28450 if (!NILP (help_echo_string
))
28452 help_echo_window
= window
;
28453 help_echo_object
= glyph
->object
;
28454 help_echo_pos
= glyph
->charpos
;
28458 if (NILP (pointer
))
28459 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
28462 #endif /* HAVE_WINDOW_SYSTEM */
28464 /* Clear mouse face if X/Y not over text. */
28466 || area
!= TEXT_AREA
28467 || !MATRIX_ROW_DISPLAYS_TEXT_P (MATRIX_ROW (w
->current_matrix
, vpos
))
28468 /* Glyph's OBJECT is an integer for glyphs inserted by the
28469 display engine for its internal purposes, like truncation
28470 and continuation glyphs and blanks beyond the end of
28471 line's text on text terminals. If we are over such a
28472 glyph, we are not over any text. */
28473 || INTEGERP (glyph
->object
)
28474 /* R2L rows have a stretch glyph at their front, which
28475 stands for no text, whereas L2R rows have no glyphs at
28476 all beyond the end of text. Treat such stretch glyphs
28477 like we do with NULL glyphs in L2R rows. */
28478 || (MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
28479 && glyph
== MATRIX_ROW_GLYPH_START (w
->current_matrix
, vpos
)
28480 && glyph
->type
== STRETCH_GLYPH
28481 && glyph
->avoid_cursor_p
))
28483 if (clear_mouse_face (hlinfo
))
28484 cursor
= No_Cursor
;
28485 #ifdef HAVE_WINDOW_SYSTEM
28486 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
28488 if (area
!= TEXT_AREA
)
28489 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
28491 pointer
= Vvoid_text_area_pointer
;
28497 pos
= glyph
->charpos
;
28498 object
= glyph
->object
;
28499 if (!STRINGP (object
) && !BUFFERP (object
))
28502 /* If we get an out-of-range value, return now; avoid an error. */
28503 if (BUFFERP (object
) && pos
> BUF_Z (b
))
28506 /* Make the window's buffer temporarily current for
28507 overlays_at and compute_char_face. */
28508 obuf
= current_buffer
;
28509 current_buffer
= b
;
28515 /* Is this char mouse-active or does it have help-echo? */
28516 position
= make_number (pos
);
28518 if (BUFFERP (object
))
28520 /* Put all the overlays we want in a vector in overlay_vec. */
28521 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
28522 /* Sort overlays into increasing priority order. */
28523 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
28528 if (NILP (Vmouse_highlight
))
28530 clear_mouse_face (hlinfo
);
28531 goto check_help_echo
;
28534 same_region
= coords_in_mouse_face_p (w
, hpos
, vpos
);
28537 cursor
= No_Cursor
;
28539 /* Check mouse-face highlighting. */
28541 /* If there exists an overlay with mouse-face overlapping
28542 the one we are currently highlighting, we have to
28543 check if we enter the overlapping overlay, and then
28544 highlight only that. */
28545 || (OVERLAYP (hlinfo
->mouse_face_overlay
)
28546 && mouse_face_overlay_overlaps (hlinfo
->mouse_face_overlay
)))
28548 /* Find the highest priority overlay with a mouse-face. */
28549 Lisp_Object overlay
= Qnil
;
28550 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
28552 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
28553 if (!NILP (mouse_face
))
28554 overlay
= overlay_vec
[i
];
28557 /* If we're highlighting the same overlay as before, there's
28558 no need to do that again. */
28559 if (!NILP (overlay
) && EQ (overlay
, hlinfo
->mouse_face_overlay
))
28560 goto check_help_echo
;
28561 hlinfo
->mouse_face_overlay
= overlay
;
28563 /* Clear the display of the old active region, if any. */
28564 if (clear_mouse_face (hlinfo
))
28565 cursor
= No_Cursor
;
28567 /* If no overlay applies, get a text property. */
28568 if (NILP (overlay
))
28569 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
28571 /* Next, compute the bounds of the mouse highlighting and
28573 if (!NILP (mouse_face
) && STRINGP (object
))
28575 /* The mouse-highlighting comes from a display string
28576 with a mouse-face. */
28580 s
= Fprevious_single_property_change
28581 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
28582 e
= Fnext_single_property_change
28583 (position
, Qmouse_face
, object
, Qnil
);
28585 s
= make_number (0);
28587 e
= make_number (SCHARS (object
) - 1);
28588 mouse_face_from_string_pos (w
, hlinfo
, object
,
28589 XINT (s
), XINT (e
));
28590 hlinfo
->mouse_face_past_end
= 0;
28591 hlinfo
->mouse_face_window
= window
;
28592 hlinfo
->mouse_face_face_id
28593 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
28594 glyph
->face_id
, 1);
28595 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
28596 cursor
= No_Cursor
;
28600 /* The mouse-highlighting, if any, comes from an overlay
28601 or text property in the buffer. */
28602 Lisp_Object buffer
IF_LINT (= Qnil
);
28603 Lisp_Object disp_string
IF_LINT (= Qnil
);
28605 if (STRINGP (object
))
28607 /* If we are on a display string with no mouse-face,
28608 check if the text under it has one. */
28609 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
28610 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28611 pos
= string_buffer_position (object
, start
);
28614 mouse_face
= get_char_property_and_overlay
28615 (make_number (pos
), Qmouse_face
, w
->contents
, &overlay
);
28616 buffer
= w
->contents
;
28617 disp_string
= object
;
28623 disp_string
= Qnil
;
28626 if (!NILP (mouse_face
))
28628 Lisp_Object before
, after
;
28629 Lisp_Object before_string
, after_string
;
28630 /* To correctly find the limits of mouse highlight
28631 in a bidi-reordered buffer, we must not use the
28632 optimization of limiting the search in
28633 previous-single-property-change and
28634 next-single-property-change, because
28635 rows_from_pos_range needs the real start and end
28636 positions to DTRT in this case. That's because
28637 the first row visible in a window does not
28638 necessarily display the character whose position
28639 is the smallest. */
28641 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
28642 ? Fmarker_position (w
->start
)
28645 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
28646 ? make_number (BUF_Z (XBUFFER (buffer
)) - w
->window_end_pos
)
28649 if (NILP (overlay
))
28651 /* Handle the text property case. */
28652 before
= Fprevious_single_property_change
28653 (make_number (pos
+ 1), Qmouse_face
, buffer
, lim1
);
28654 after
= Fnext_single_property_change
28655 (make_number (pos
), Qmouse_face
, buffer
, lim2
);
28656 before_string
= after_string
= Qnil
;
28660 /* Handle the overlay case. */
28661 before
= Foverlay_start (overlay
);
28662 after
= Foverlay_end (overlay
);
28663 before_string
= Foverlay_get (overlay
, Qbefore_string
);
28664 after_string
= Foverlay_get (overlay
, Qafter_string
);
28666 if (!STRINGP (before_string
)) before_string
= Qnil
;
28667 if (!STRINGP (after_string
)) after_string
= Qnil
;
28670 mouse_face_from_buffer_pos (window
, hlinfo
, pos
,
28673 : XFASTINT (before
),
28675 ? BUF_Z (XBUFFER (buffer
))
28676 : XFASTINT (after
),
28677 before_string
, after_string
,
28679 cursor
= No_Cursor
;
28686 /* Look for a `help-echo' property. */
28687 if (NILP (help_echo_string
)) {
28688 Lisp_Object help
, overlay
;
28690 /* Check overlays first. */
28691 help
= overlay
= Qnil
;
28692 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
28694 overlay
= overlay_vec
[i
];
28695 help
= Foverlay_get (overlay
, Qhelp_echo
);
28700 help_echo_string
= help
;
28701 help_echo_window
= window
;
28702 help_echo_object
= overlay
;
28703 help_echo_pos
= pos
;
28707 Lisp_Object obj
= glyph
->object
;
28708 ptrdiff_t charpos
= glyph
->charpos
;
28710 /* Try text properties. */
28713 && charpos
< SCHARS (obj
))
28715 help
= Fget_text_property (make_number (charpos
),
28719 /* If the string itself doesn't specify a help-echo,
28720 see if the buffer text ``under'' it does. */
28721 struct glyph_row
*r
28722 = MATRIX_ROW (w
->current_matrix
, vpos
);
28723 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28724 ptrdiff_t p
= string_buffer_position (obj
, start
);
28727 help
= Fget_char_property (make_number (p
),
28728 Qhelp_echo
, w
->contents
);
28737 else if (BUFFERP (obj
)
28740 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
28745 help_echo_string
= help
;
28746 help_echo_window
= window
;
28747 help_echo_object
= obj
;
28748 help_echo_pos
= charpos
;
28753 #ifdef HAVE_WINDOW_SYSTEM
28754 /* Look for a `pointer' property. */
28755 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
28757 /* Check overlays first. */
28758 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
28759 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
28761 if (NILP (pointer
))
28763 Lisp_Object obj
= glyph
->object
;
28764 ptrdiff_t charpos
= glyph
->charpos
;
28766 /* Try text properties. */
28769 && charpos
< SCHARS (obj
))
28771 pointer
= Fget_text_property (make_number (charpos
),
28773 if (NILP (pointer
))
28775 /* If the string itself doesn't specify a pointer,
28776 see if the buffer text ``under'' it does. */
28777 struct glyph_row
*r
28778 = MATRIX_ROW (w
->current_matrix
, vpos
);
28779 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28780 ptrdiff_t p
= string_buffer_position (obj
, start
);
28782 pointer
= Fget_char_property (make_number (p
),
28783 Qpointer
, w
->contents
);
28786 else if (BUFFERP (obj
)
28789 pointer
= Fget_text_property (make_number (charpos
),
28793 #endif /* HAVE_WINDOW_SYSTEM */
28797 current_buffer
= obuf
;
28802 #ifdef HAVE_WINDOW_SYSTEM
28803 if (FRAME_WINDOW_P (f
))
28804 define_frame_cursor1 (f
, cursor
, pointer
);
28806 /* This is here to prevent a compiler error, about "label at end of
28807 compound statement". */
28814 Clear any mouse-face on window W. This function is part of the
28815 redisplay interface, and is called from try_window_id and similar
28816 functions to ensure the mouse-highlight is off. */
28819 x_clear_window_mouse_face (struct window
*w
)
28821 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
28822 Lisp_Object window
;
28825 XSETWINDOW (window
, w
);
28826 if (EQ (window
, hlinfo
->mouse_face_window
))
28827 clear_mouse_face (hlinfo
);
28833 Just discard the mouse face information for frame F, if any.
28834 This is used when the size of F is changed. */
28837 cancel_mouse_face (struct frame
*f
)
28839 Lisp_Object window
;
28840 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28842 window
= hlinfo
->mouse_face_window
;
28843 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
28845 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
28846 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
28847 hlinfo
->mouse_face_window
= Qnil
;
28853 /***********************************************************************
28855 ***********************************************************************/
28857 #ifdef HAVE_WINDOW_SYSTEM
28859 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
28860 which intersects rectangle R. R is in window-relative coordinates. */
28863 expose_area (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
,
28864 enum glyph_row_area area
)
28866 struct glyph
*first
= row
->glyphs
[area
];
28867 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
28868 struct glyph
*last
;
28869 int first_x
, start_x
, x
;
28871 if (area
== TEXT_AREA
&& row
->fill_line_p
)
28872 /* If row extends face to end of line write the whole line. */
28873 draw_glyphs (w
, 0, row
, area
,
28874 0, row
->used
[area
],
28875 DRAW_NORMAL_TEXT
, 0);
28878 /* Set START_X to the window-relative start position for drawing glyphs of
28879 AREA. The first glyph of the text area can be partially visible.
28880 The first glyphs of other areas cannot. */
28881 start_x
= window_box_left_offset (w
, area
);
28883 if (area
== TEXT_AREA
)
28886 /* Find the first glyph that must be redrawn. */
28888 && x
+ first
->pixel_width
< r
->x
)
28890 x
+= first
->pixel_width
;
28894 /* Find the last one. */
28898 && x
< r
->x
+ r
->width
)
28900 x
+= last
->pixel_width
;
28906 draw_glyphs (w
, first_x
- start_x
, row
, area
,
28907 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
28908 DRAW_NORMAL_TEXT
, 0);
28913 /* Redraw the parts of the glyph row ROW on window W intersecting
28914 rectangle R. R is in window-relative coordinates. Value is
28915 non-zero if mouse-face was overwritten. */
28918 expose_line (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
)
28920 eassert (row
->enabled_p
);
28922 if (row
->mode_line_p
|| w
->pseudo_window_p
)
28923 draw_glyphs (w
, 0, row
, TEXT_AREA
,
28924 0, row
->used
[TEXT_AREA
],
28925 DRAW_NORMAL_TEXT
, 0);
28928 if (row
->used
[LEFT_MARGIN_AREA
])
28929 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
28930 if (row
->used
[TEXT_AREA
])
28931 expose_area (w
, row
, r
, TEXT_AREA
);
28932 if (row
->used
[RIGHT_MARGIN_AREA
])
28933 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
28934 draw_row_fringe_bitmaps (w
, row
);
28937 return row
->mouse_face_p
;
28941 /* Redraw those parts of glyphs rows during expose event handling that
28942 overlap other rows. Redrawing of an exposed line writes over parts
28943 of lines overlapping that exposed line; this function fixes that.
28945 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
28946 row in W's current matrix that is exposed and overlaps other rows.
28947 LAST_OVERLAPPING_ROW is the last such row. */
28950 expose_overlaps (struct window
*w
,
28951 struct glyph_row
*first_overlapping_row
,
28952 struct glyph_row
*last_overlapping_row
,
28955 struct glyph_row
*row
;
28957 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
28958 if (row
->overlapping_p
)
28960 eassert (row
->enabled_p
&& !row
->mode_line_p
);
28963 if (row
->used
[LEFT_MARGIN_AREA
])
28964 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
28966 if (row
->used
[TEXT_AREA
])
28967 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
28969 if (row
->used
[RIGHT_MARGIN_AREA
])
28970 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
28976 /* Return non-zero if W's cursor intersects rectangle R. */
28979 phys_cursor_in_rect_p (struct window
*w
, XRectangle
*r
)
28981 XRectangle cr
, result
;
28982 struct glyph
*cursor_glyph
;
28983 struct glyph_row
*row
;
28985 if (w
->phys_cursor
.vpos
>= 0
28986 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
28987 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
28989 && row
->cursor_in_fringe_p
)
28991 /* Cursor is in the fringe. */
28992 cr
.x
= window_box_right_offset (w
,
28993 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
28994 ? RIGHT_MARGIN_AREA
28997 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
28998 cr
.height
= row
->height
;
28999 return x_intersect_rectangles (&cr
, r
, &result
);
29002 cursor_glyph
= get_phys_cursor_glyph (w
);
29005 /* r is relative to W's box, but w->phys_cursor.x is relative
29006 to left edge of W's TEXT area. Adjust it. */
29007 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
29008 cr
.y
= w
->phys_cursor
.y
;
29009 cr
.width
= cursor_glyph
->pixel_width
;
29010 cr
.height
= w
->phys_cursor_height
;
29011 /* ++KFS: W32 version used W32-specific IntersectRect here, but
29012 I assume the effect is the same -- and this is portable. */
29013 return x_intersect_rectangles (&cr
, r
, &result
);
29015 /* If we don't understand the format, pretend we're not in the hot-spot. */
29021 Draw a vertical window border to the right of window W if W doesn't
29022 have vertical scroll bars. */
29025 x_draw_vertical_border (struct window
*w
)
29027 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
29029 /* We could do better, if we knew what type of scroll-bar the adjacent
29030 windows (on either side) have... But we don't :-(
29031 However, I think this works ok. ++KFS 2003-04-25 */
29033 /* Redraw borders between horizontally adjacent windows. Don't
29034 do it for frames with vertical scroll bars because either the
29035 right scroll bar of a window, or the left scroll bar of its
29036 neighbor will suffice as a border. */
29037 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
29040 /* Note: It is necessary to redraw both the left and the right
29041 borders, for when only this single window W is being
29043 if (!WINDOW_RIGHTMOST_P (w
)
29044 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
29046 int x0
, x1
, y0
, y1
;
29048 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
29051 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
29054 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
29056 if (!WINDOW_LEFTMOST_P (w
)
29057 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
29059 int x0
, x1
, y0
, y1
;
29061 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
29064 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
29067 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
29072 /* Redraw the part of window W intersection rectangle FR. Pixel
29073 coordinates in FR are frame-relative. Call this function with
29074 input blocked. Value is non-zero if the exposure overwrites
29078 expose_window (struct window
*w
, XRectangle
*fr
)
29080 struct frame
*f
= XFRAME (w
->frame
);
29082 int mouse_face_overwritten_p
= 0;
29084 /* If window is not yet fully initialized, do nothing. This can
29085 happen when toolkit scroll bars are used and a window is split.
29086 Reconfiguring the scroll bar will generate an expose for a newly
29088 if (w
->current_matrix
== NULL
)
29091 /* When we're currently updating the window, display and current
29092 matrix usually don't agree. Arrange for a thorough display
29094 if (w
->must_be_updated_p
)
29096 SET_FRAME_GARBAGED (f
);
29100 /* Frame-relative pixel rectangle of W. */
29101 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
29102 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
29103 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
29104 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
29106 if (x_intersect_rectangles (fr
, &wr
, &r
))
29108 int yb
= window_text_bottom_y (w
);
29109 struct glyph_row
*row
;
29110 int cursor_cleared_p
, phys_cursor_on_p
;
29111 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
29113 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
29114 r
.x
, r
.y
, r
.width
, r
.height
));
29116 /* Convert to window coordinates. */
29117 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
29118 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
29120 /* Turn off the cursor. */
29121 if (!w
->pseudo_window_p
29122 && phys_cursor_in_rect_p (w
, &r
))
29124 x_clear_cursor (w
);
29125 cursor_cleared_p
= 1;
29128 cursor_cleared_p
= 0;
29130 /* If the row containing the cursor extends face to end of line,
29131 then expose_area might overwrite the cursor outside the
29132 rectangle and thus notice_overwritten_cursor might clear
29133 w->phys_cursor_on_p. We remember the original value and
29134 check later if it is changed. */
29135 phys_cursor_on_p
= w
->phys_cursor_on_p
;
29137 /* Update lines intersecting rectangle R. */
29138 first_overlapping_row
= last_overlapping_row
= NULL
;
29139 for (row
= w
->current_matrix
->rows
;
29144 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
29146 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
29147 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
29148 || (r
.y
>= y0
&& r
.y
< y1
)
29149 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
29151 /* A header line may be overlapping, but there is no need
29152 to fix overlapping areas for them. KFS 2005-02-12 */
29153 if (row
->overlapping_p
&& !row
->mode_line_p
)
29155 if (first_overlapping_row
== NULL
)
29156 first_overlapping_row
= row
;
29157 last_overlapping_row
= row
;
29161 if (expose_line (w
, row
, &r
))
29162 mouse_face_overwritten_p
= 1;
29165 else if (row
->overlapping_p
)
29167 /* We must redraw a row overlapping the exposed area. */
29169 ? y0
+ row
->phys_height
> r
.y
29170 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
29172 if (first_overlapping_row
== NULL
)
29173 first_overlapping_row
= row
;
29174 last_overlapping_row
= row
;
29182 /* Display the mode line if there is one. */
29183 if (WINDOW_WANTS_MODELINE_P (w
)
29184 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
29186 && row
->y
< r
.y
+ r
.height
)
29188 if (expose_line (w
, row
, &r
))
29189 mouse_face_overwritten_p
= 1;
29192 if (!w
->pseudo_window_p
)
29194 /* Fix the display of overlapping rows. */
29195 if (first_overlapping_row
)
29196 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
29199 /* Draw border between windows. */
29200 x_draw_vertical_border (w
);
29202 /* Turn the cursor on again. */
29203 if (cursor_cleared_p
29204 || (phys_cursor_on_p
&& !w
->phys_cursor_on_p
))
29205 update_window_cursor (w
, 1);
29209 return mouse_face_overwritten_p
;
29214 /* Redraw (parts) of all windows in the window tree rooted at W that
29215 intersect R. R contains frame pixel coordinates. Value is
29216 non-zero if the exposure overwrites mouse-face. */
29219 expose_window_tree (struct window
*w
, XRectangle
*r
)
29221 struct frame
*f
= XFRAME (w
->frame
);
29222 int mouse_face_overwritten_p
= 0;
29224 while (w
&& !FRAME_GARBAGED_P (f
))
29226 if (WINDOWP (w
->contents
))
29227 mouse_face_overwritten_p
29228 |= expose_window_tree (XWINDOW (w
->contents
), r
);
29230 mouse_face_overwritten_p
|= expose_window (w
, r
);
29232 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
29235 return mouse_face_overwritten_p
;
29240 Redisplay an exposed area of frame F. X and Y are the upper-left
29241 corner of the exposed rectangle. W and H are width and height of
29242 the exposed area. All are pixel values. W or H zero means redraw
29243 the entire frame. */
29246 expose_frame (struct frame
*f
, int x
, int y
, int w
, int h
)
29249 int mouse_face_overwritten_p
= 0;
29251 TRACE ((stderr
, "expose_frame "));
29253 /* No need to redraw if frame will be redrawn soon. */
29254 if (FRAME_GARBAGED_P (f
))
29256 TRACE ((stderr
, " garbaged\n"));
29260 /* If basic faces haven't been realized yet, there is no point in
29261 trying to redraw anything. This can happen when we get an expose
29262 event while Emacs is starting, e.g. by moving another window. */
29263 if (FRAME_FACE_CACHE (f
) == NULL
29264 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
29266 TRACE ((stderr
, " no faces\n"));
29270 if (w
== 0 || h
== 0)
29273 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
29274 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
29284 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
29285 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
29287 if (WINDOWP (f
->tool_bar_window
))
29288 mouse_face_overwritten_p
29289 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
29291 #ifdef HAVE_X_WINDOWS
29293 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
29294 if (WINDOWP (f
->menu_bar_window
))
29295 mouse_face_overwritten_p
29296 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
29297 #endif /* not USE_X_TOOLKIT and not USE_GTK */
29301 /* Some window managers support a focus-follows-mouse style with
29302 delayed raising of frames. Imagine a partially obscured frame,
29303 and moving the mouse into partially obscured mouse-face on that
29304 frame. The visible part of the mouse-face will be highlighted,
29305 then the WM raises the obscured frame. With at least one WM, KDE
29306 2.1, Emacs is not getting any event for the raising of the frame
29307 (even tried with SubstructureRedirectMask), only Expose events.
29308 These expose events will draw text normally, i.e. not
29309 highlighted. Which means we must redo the highlight here.
29310 Subsume it under ``we love X''. --gerd 2001-08-15 */
29311 /* Included in Windows version because Windows most likely does not
29312 do the right thing if any third party tool offers
29313 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
29314 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
29316 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
29317 if (f
== hlinfo
->mouse_face_mouse_frame
)
29319 int mouse_x
= hlinfo
->mouse_face_mouse_x
;
29320 int mouse_y
= hlinfo
->mouse_face_mouse_y
;
29321 clear_mouse_face (hlinfo
);
29322 note_mouse_highlight (f
, mouse_x
, mouse_y
);
29329 Determine the intersection of two rectangles R1 and R2. Return
29330 the intersection in *RESULT. Value is non-zero if RESULT is not
29334 x_intersect_rectangles (XRectangle
*r1
, XRectangle
*r2
, XRectangle
*result
)
29336 XRectangle
*left
, *right
;
29337 XRectangle
*upper
, *lower
;
29338 int intersection_p
= 0;
29340 /* Rearrange so that R1 is the left-most rectangle. */
29342 left
= r1
, right
= r2
;
29344 left
= r2
, right
= r1
;
29346 /* X0 of the intersection is right.x0, if this is inside R1,
29347 otherwise there is no intersection. */
29348 if (right
->x
<= left
->x
+ left
->width
)
29350 result
->x
= right
->x
;
29352 /* The right end of the intersection is the minimum of
29353 the right ends of left and right. */
29354 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
29357 /* Same game for Y. */
29359 upper
= r1
, lower
= r2
;
29361 upper
= r2
, lower
= r1
;
29363 /* The upper end of the intersection is lower.y0, if this is inside
29364 of upper. Otherwise, there is no intersection. */
29365 if (lower
->y
<= upper
->y
+ upper
->height
)
29367 result
->y
= lower
->y
;
29369 /* The lower end of the intersection is the minimum of the lower
29370 ends of upper and lower. */
29371 result
->height
= (min (lower
->y
+ lower
->height
,
29372 upper
->y
+ upper
->height
)
29374 intersection_p
= 1;
29378 return intersection_p
;
29381 #endif /* HAVE_WINDOW_SYSTEM */
29384 /***********************************************************************
29386 ***********************************************************************/
29389 syms_of_xdisp (void)
29391 Vwith_echo_area_save_vector
= Qnil
;
29392 staticpro (&Vwith_echo_area_save_vector
);
29394 Vmessage_stack
= Qnil
;
29395 staticpro (&Vmessage_stack
);
29397 DEFSYM (Qinhibit_redisplay
, "inhibit-redisplay");
29398 DEFSYM (Qredisplay_internal
, "redisplay_internal (C function)");
29400 message_dolog_marker1
= Fmake_marker ();
29401 staticpro (&message_dolog_marker1
);
29402 message_dolog_marker2
= Fmake_marker ();
29403 staticpro (&message_dolog_marker2
);
29404 message_dolog_marker3
= Fmake_marker ();
29405 staticpro (&message_dolog_marker3
);
29408 defsubr (&Sdump_frame_glyph_matrix
);
29409 defsubr (&Sdump_glyph_matrix
);
29410 defsubr (&Sdump_glyph_row
);
29411 defsubr (&Sdump_tool_bar_row
);
29412 defsubr (&Strace_redisplay
);
29413 defsubr (&Strace_to_stderr
);
29415 #ifdef HAVE_WINDOW_SYSTEM
29416 defsubr (&Stool_bar_lines_needed
);
29417 defsubr (&Slookup_image_map
);
29419 defsubr (&Sline_pixel_height
);
29420 defsubr (&Sformat_mode_line
);
29421 defsubr (&Sinvisible_p
);
29422 defsubr (&Scurrent_bidi_paragraph_direction
);
29423 defsubr (&Smove_point_visually
);
29425 DEFSYM (Qmenu_bar_update_hook
, "menu-bar-update-hook");
29426 DEFSYM (Qoverriding_terminal_local_map
, "overriding-terminal-local-map");
29427 DEFSYM (Qoverriding_local_map
, "overriding-local-map");
29428 DEFSYM (Qwindow_scroll_functions
, "window-scroll-functions");
29429 DEFSYM (Qwindow_text_change_functions
, "window-text-change-functions");
29430 DEFSYM (Qredisplay_end_trigger_functions
, "redisplay-end-trigger-functions");
29431 DEFSYM (Qinhibit_point_motion_hooks
, "inhibit-point-motion-hooks");
29432 DEFSYM (Qeval
, "eval");
29433 DEFSYM (QCdata
, ":data");
29434 DEFSYM (Qdisplay
, "display");
29435 DEFSYM (Qspace_width
, "space-width");
29436 DEFSYM (Qraise
, "raise");
29437 DEFSYM (Qslice
, "slice");
29438 DEFSYM (Qspace
, "space");
29439 DEFSYM (Qmargin
, "margin");
29440 DEFSYM (Qpointer
, "pointer");
29441 DEFSYM (Qleft_margin
, "left-margin");
29442 DEFSYM (Qright_margin
, "right-margin");
29443 DEFSYM (Qcenter
, "center");
29444 DEFSYM (Qline_height
, "line-height");
29445 DEFSYM (QCalign_to
, ":align-to");
29446 DEFSYM (QCrelative_width
, ":relative-width");
29447 DEFSYM (QCrelative_height
, ":relative-height");
29448 DEFSYM (QCeval
, ":eval");
29449 DEFSYM (QCpropertize
, ":propertize");
29450 DEFSYM (QCfile
, ":file");
29451 DEFSYM (Qfontified
, "fontified");
29452 DEFSYM (Qfontification_functions
, "fontification-functions");
29453 DEFSYM (Qtrailing_whitespace
, "trailing-whitespace");
29454 DEFSYM (Qescape_glyph
, "escape-glyph");
29455 DEFSYM (Qnobreak_space
, "nobreak-space");
29456 DEFSYM (Qimage
, "image");
29457 DEFSYM (Qtext
, "text");
29458 DEFSYM (Qboth
, "both");
29459 DEFSYM (Qboth_horiz
, "both-horiz");
29460 DEFSYM (Qtext_image_horiz
, "text-image-horiz");
29461 DEFSYM (QCmap
, ":map");
29462 DEFSYM (QCpointer
, ":pointer");
29463 DEFSYM (Qrect
, "rect");
29464 DEFSYM (Qcircle
, "circle");
29465 DEFSYM (Qpoly
, "poly");
29466 DEFSYM (Qmessage_truncate_lines
, "message-truncate-lines");
29467 DEFSYM (Qgrow_only
, "grow-only");
29468 DEFSYM (Qinhibit_menubar_update
, "inhibit-menubar-update");
29469 DEFSYM (Qinhibit_eval_during_redisplay
, "inhibit-eval-during-redisplay");
29470 DEFSYM (Qposition
, "position");
29471 DEFSYM (Qbuffer_position
, "buffer-position");
29472 DEFSYM (Qobject
, "object");
29473 DEFSYM (Qbar
, "bar");
29474 DEFSYM (Qhbar
, "hbar");
29475 DEFSYM (Qbox
, "box");
29476 DEFSYM (Qhollow
, "hollow");
29477 DEFSYM (Qhand
, "hand");
29478 DEFSYM (Qarrow
, "arrow");
29479 DEFSYM (Qinhibit_free_realized_faces
, "inhibit-free-realized-faces");
29481 list_of_error
= list1 (list2 (intern_c_string ("error"),
29482 intern_c_string ("void-variable")));
29483 staticpro (&list_of_error
);
29485 DEFSYM (Qlast_arrow_position
, "last-arrow-position");
29486 DEFSYM (Qlast_arrow_string
, "last-arrow-string");
29487 DEFSYM (Qoverlay_arrow_string
, "overlay-arrow-string");
29488 DEFSYM (Qoverlay_arrow_bitmap
, "overlay-arrow-bitmap");
29490 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
29491 staticpro (&echo_buffer
[0]);
29492 staticpro (&echo_buffer
[1]);
29494 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
29495 staticpro (&echo_area_buffer
[0]);
29496 staticpro (&echo_area_buffer
[1]);
29498 Vmessages_buffer_name
= build_pure_c_string ("*Messages*");
29499 staticpro (&Vmessages_buffer_name
);
29501 mode_line_proptrans_alist
= Qnil
;
29502 staticpro (&mode_line_proptrans_alist
);
29503 mode_line_string_list
= Qnil
;
29504 staticpro (&mode_line_string_list
);
29505 mode_line_string_face
= Qnil
;
29506 staticpro (&mode_line_string_face
);
29507 mode_line_string_face_prop
= Qnil
;
29508 staticpro (&mode_line_string_face_prop
);
29509 Vmode_line_unwind_vector
= Qnil
;
29510 staticpro (&Vmode_line_unwind_vector
);
29512 DEFSYM (Qmode_line_default_help_echo
, "mode-line-default-help-echo");
29514 help_echo_string
= Qnil
;
29515 staticpro (&help_echo_string
);
29516 help_echo_object
= Qnil
;
29517 staticpro (&help_echo_object
);
29518 help_echo_window
= Qnil
;
29519 staticpro (&help_echo_window
);
29520 previous_help_echo_string
= Qnil
;
29521 staticpro (&previous_help_echo_string
);
29522 help_echo_pos
= -1;
29524 DEFSYM (Qright_to_left
, "right-to-left");
29525 DEFSYM (Qleft_to_right
, "left-to-right");
29527 #ifdef HAVE_WINDOW_SYSTEM
29528 DEFVAR_BOOL ("x-stretch-cursor", x_stretch_cursor_p
,
29529 doc
: /* Non-nil means draw block cursor as wide as the glyph under it.
29530 For example, if a block cursor is over a tab, it will be drawn as
29531 wide as that tab on the display. */);
29532 x_stretch_cursor_p
= 0;
29535 DEFVAR_LISP ("show-trailing-whitespace", Vshow_trailing_whitespace
,
29536 doc
: /* Non-nil means highlight trailing whitespace.
29537 The face used for trailing whitespace is `trailing-whitespace'. */);
29538 Vshow_trailing_whitespace
= Qnil
;
29540 DEFVAR_LISP ("nobreak-char-display", Vnobreak_char_display
,
29541 doc
: /* Control highlighting of non-ASCII space and hyphen chars.
29542 If the value is t, Emacs highlights non-ASCII chars which have the
29543 same appearance as an ASCII space or hyphen, using the `nobreak-space'
29544 or `escape-glyph' face respectively.
29546 U+00A0 (no-break space), U+00AD (soft hyphen), U+2010 (hyphen), and
29547 U+2011 (non-breaking hyphen) are affected.
29549 Any other non-nil value means to display these characters as a escape
29550 glyph followed by an ordinary space or hyphen.
29552 A value of nil means no special handling of these characters. */);
29553 Vnobreak_char_display
= Qt
;
29555 DEFVAR_LISP ("void-text-area-pointer", Vvoid_text_area_pointer
,
29556 doc
: /* The pointer shape to show in void text areas.
29557 A value of nil means to show the text pointer. Other options are `arrow',
29558 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
29559 Vvoid_text_area_pointer
= Qarrow
;
29561 DEFVAR_LISP ("inhibit-redisplay", Vinhibit_redisplay
,
29562 doc
: /* Non-nil means don't actually do any redisplay.
29563 This is used for internal purposes. */);
29564 Vinhibit_redisplay
= Qnil
;
29566 DEFVAR_LISP ("global-mode-string", Vglobal_mode_string
,
29567 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
29568 Vglobal_mode_string
= Qnil
;
29570 DEFVAR_LISP ("overlay-arrow-position", Voverlay_arrow_position
,
29571 doc
: /* Marker for where to display an arrow on top of the buffer text.
29572 This must be the beginning of a line in order to work.
29573 See also `overlay-arrow-string'. */);
29574 Voverlay_arrow_position
= Qnil
;
29576 DEFVAR_LISP ("overlay-arrow-string", Voverlay_arrow_string
,
29577 doc
: /* String to display as an arrow in non-window frames.
29578 See also `overlay-arrow-position'. */);
29579 Voverlay_arrow_string
= build_pure_c_string ("=>");
29581 DEFVAR_LISP ("overlay-arrow-variable-list", Voverlay_arrow_variable_list
,
29582 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
29583 The symbols on this list are examined during redisplay to determine
29584 where to display overlay arrows. */);
29585 Voverlay_arrow_variable_list
29586 = list1 (intern_c_string ("overlay-arrow-position"));
29588 DEFVAR_INT ("scroll-step", emacs_scroll_step
,
29589 doc
: /* The number of lines to try scrolling a window by when point moves out.
29590 If that fails to bring point back on frame, point is centered instead.
29591 If this is zero, point is always centered after it moves off frame.
29592 If you want scrolling to always be a line at a time, you should set
29593 `scroll-conservatively' to a large value rather than set this to 1. */);
29595 DEFVAR_INT ("scroll-conservatively", scroll_conservatively
,
29596 doc
: /* Scroll up to this many lines, to bring point back on screen.
29597 If point moves off-screen, redisplay will scroll by up to
29598 `scroll-conservatively' lines in order to bring point just barely
29599 onto the screen again. If that cannot be done, then redisplay
29600 recenters point as usual.
29602 If the value is greater than 100, redisplay will never recenter point,
29603 but will always scroll just enough text to bring point into view, even
29604 if you move far away.
29606 A value of zero means always recenter point if it moves off screen. */);
29607 scroll_conservatively
= 0;
29609 DEFVAR_INT ("scroll-margin", scroll_margin
,
29610 doc
: /* Number of lines of margin at the top and bottom of a window.
29611 Recenter the window whenever point gets within this many lines
29612 of the top or bottom of the window. */);
29615 DEFVAR_LISP ("display-pixels-per-inch", Vdisplay_pixels_per_inch
,
29616 doc
: /* Pixels per inch value for non-window system displays.
29617 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
29618 Vdisplay_pixels_per_inch
= make_float (72.0);
29621 DEFVAR_INT ("debug-end-pos", debug_end_pos
, doc
: /* Don't ask. */);
29624 DEFVAR_LISP ("truncate-partial-width-windows",
29625 Vtruncate_partial_width_windows
,
29626 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
29627 For an integer value, truncate lines in each window narrower than the
29628 full frame width, provided the window width is less than that integer;
29629 otherwise, respect the value of `truncate-lines'.
29631 For any other non-nil value, truncate lines in all windows that do
29632 not span the full frame width.
29634 A value of nil means to respect the value of `truncate-lines'.
29636 If `word-wrap' is enabled, you might want to reduce this. */);
29637 Vtruncate_partial_width_windows
= make_number (50);
29639 DEFVAR_LISP ("line-number-display-limit", Vline_number_display_limit
,
29640 doc
: /* Maximum buffer size for which line number should be displayed.
29641 If the buffer is bigger than this, the line number does not appear
29642 in the mode line. A value of nil means no limit. */);
29643 Vline_number_display_limit
= Qnil
;
29645 DEFVAR_INT ("line-number-display-limit-width",
29646 line_number_display_limit_width
,
29647 doc
: /* Maximum line width (in characters) for line number display.
29648 If the average length of the lines near point is bigger than this, then the
29649 line number may be omitted from the mode line. */);
29650 line_number_display_limit_width
= 200;
29652 DEFVAR_BOOL ("highlight-nonselected-windows", highlight_nonselected_windows
,
29653 doc
: /* Non-nil means highlight region even in nonselected windows. */);
29654 highlight_nonselected_windows
= 0;
29656 DEFVAR_BOOL ("multiple-frames", multiple_frames
,
29657 doc
: /* Non-nil if more than one frame is visible on this display.
29658 Minibuffer-only frames don't count, but iconified frames do.
29659 This variable is not guaranteed to be accurate except while processing
29660 `frame-title-format' and `icon-title-format'. */);
29662 DEFVAR_LISP ("frame-title-format", Vframe_title_format
,
29663 doc
: /* Template for displaying the title bar of visible frames.
29664 \(Assuming the window manager supports this feature.)
29666 This variable has the same structure as `mode-line-format', except that
29667 the %c and %l constructs are ignored. It is used only on frames for
29668 which no explicit name has been set \(see `modify-frame-parameters'). */);
29670 DEFVAR_LISP ("icon-title-format", Vicon_title_format
,
29671 doc
: /* Template for displaying the title bar of an iconified frame.
29672 \(Assuming the window manager supports this feature.)
29673 This variable has the same structure as `mode-line-format' (which see),
29674 and is used only on frames for which no explicit name has been set
29675 \(see `modify-frame-parameters'). */);
29677 = Vframe_title_format
29678 = listn (CONSTYPE_PURE
, 3,
29679 intern_c_string ("multiple-frames"),
29680 build_pure_c_string ("%b"),
29681 listn (CONSTYPE_PURE
, 4,
29682 empty_unibyte_string
,
29683 intern_c_string ("invocation-name"),
29684 build_pure_c_string ("@"),
29685 intern_c_string ("system-name")));
29687 DEFVAR_LISP ("message-log-max", Vmessage_log_max
,
29688 doc
: /* Maximum number of lines to keep in the message log buffer.
29689 If nil, disable message logging. If t, log messages but don't truncate
29690 the buffer when it becomes large. */);
29691 Vmessage_log_max
= make_number (1000);
29693 DEFVAR_LISP ("window-size-change-functions", Vwindow_size_change_functions
,
29694 doc
: /* Functions called before redisplay, if window sizes have changed.
29695 The value should be a list of functions that take one argument.
29696 Just before redisplay, for each frame, if any of its windows have changed
29697 size since the last redisplay, or have been split or deleted,
29698 all the functions in the list are called, with the frame as argument. */);
29699 Vwindow_size_change_functions
= Qnil
;
29701 DEFVAR_LISP ("window-scroll-functions", Vwindow_scroll_functions
,
29702 doc
: /* List of functions to call before redisplaying a window with scrolling.
29703 Each function is called with two arguments, the window and its new
29704 display-start position. Note that these functions are also called by
29705 `set-window-buffer'. Also note that the value of `window-end' is not
29706 valid when these functions are called.
29708 Warning: Do not use this feature to alter the way the window
29709 is scrolled. It is not designed for that, and such use probably won't
29711 Vwindow_scroll_functions
= Qnil
;
29713 DEFVAR_LISP ("window-text-change-functions",
29714 Vwindow_text_change_functions
,
29715 doc
: /* Functions to call in redisplay when text in the window might change. */);
29716 Vwindow_text_change_functions
= Qnil
;
29718 DEFVAR_LISP ("redisplay-end-trigger-functions", Vredisplay_end_trigger_functions
,
29719 doc
: /* Functions called when redisplay of a window reaches the end trigger.
29720 Each function is called with two arguments, the window and the end trigger value.
29721 See `set-window-redisplay-end-trigger'. */);
29722 Vredisplay_end_trigger_functions
= Qnil
;
29724 DEFVAR_LISP ("mouse-autoselect-window", Vmouse_autoselect_window
,
29725 doc
: /* Non-nil means autoselect window with mouse pointer.
29726 If nil, do not autoselect windows.
29727 A positive number means delay autoselection by that many seconds: a
29728 window is autoselected only after the mouse has remained in that
29729 window for the duration of the delay.
29730 A negative number has a similar effect, but causes windows to be
29731 autoselected only after the mouse has stopped moving. \(Because of
29732 the way Emacs compares mouse events, you will occasionally wait twice
29733 that time before the window gets selected.\)
29734 Any other value means to autoselect window instantaneously when the
29735 mouse pointer enters it.
29737 Autoselection selects the minibuffer only if it is active, and never
29738 unselects the minibuffer if it is active.
29740 When customizing this variable make sure that the actual value of
29741 `focus-follows-mouse' matches the behavior of your window manager. */);
29742 Vmouse_autoselect_window
= Qnil
;
29744 DEFVAR_LISP ("auto-resize-tool-bars", Vauto_resize_tool_bars
,
29745 doc
: /* Non-nil means automatically resize tool-bars.
29746 This dynamically changes the tool-bar's height to the minimum height
29747 that is needed to make all tool-bar items visible.
29748 If value is `grow-only', the tool-bar's height is only increased
29749 automatically; to decrease the tool-bar height, use \\[recenter]. */);
29750 Vauto_resize_tool_bars
= Qt
;
29752 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", auto_raise_tool_bar_buttons_p
,
29753 doc
: /* Non-nil means raise tool-bar buttons when the mouse moves over them. */);
29754 auto_raise_tool_bar_buttons_p
= 1;
29756 DEFVAR_BOOL ("make-cursor-line-fully-visible", make_cursor_line_fully_visible_p
,
29757 doc
: /* Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
29758 make_cursor_line_fully_visible_p
= 1;
29760 DEFVAR_LISP ("tool-bar-border", Vtool_bar_border
,
29761 doc
: /* Border below tool-bar in pixels.
29762 If an integer, use it as the height of the border.
29763 If it is one of `internal-border-width' or `border-width', use the
29764 value of the corresponding frame parameter.
29765 Otherwise, no border is added below the tool-bar. */);
29766 Vtool_bar_border
= Qinternal_border_width
;
29768 DEFVAR_LISP ("tool-bar-button-margin", Vtool_bar_button_margin
,
29769 doc
: /* Margin around tool-bar buttons in pixels.
29770 If an integer, use that for both horizontal and vertical margins.
29771 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
29772 HORZ specifying the horizontal margin, and VERT specifying the
29773 vertical margin. */);
29774 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
29776 DEFVAR_INT ("tool-bar-button-relief", tool_bar_button_relief
,
29777 doc
: /* Relief thickness of tool-bar buttons. */);
29778 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
29780 DEFVAR_LISP ("tool-bar-style", Vtool_bar_style
,
29781 doc
: /* Tool bar style to use.
29783 image - show images only
29784 text - show text only
29785 both - show both, text below image
29786 both-horiz - show text to the right of the image
29787 text-image-horiz - show text to the left of the image
29788 any other - use system default or image if no system default.
29790 This variable only affects the GTK+ toolkit version of Emacs. */);
29791 Vtool_bar_style
= Qnil
;
29793 DEFVAR_INT ("tool-bar-max-label-size", tool_bar_max_label_size
,
29794 doc
: /* Maximum number of characters a label can have to be shown.
29795 The tool bar style must also show labels for this to have any effect, see
29796 `tool-bar-style'. */);
29797 tool_bar_max_label_size
= DEFAULT_TOOL_BAR_LABEL_SIZE
;
29799 DEFVAR_LISP ("fontification-functions", Vfontification_functions
,
29800 doc
: /* List of functions to call to fontify regions of text.
29801 Each function is called with one argument POS. Functions must
29802 fontify a region starting at POS in the current buffer, and give
29803 fontified regions the property `fontified'. */);
29804 Vfontification_functions
= Qnil
;
29805 Fmake_variable_buffer_local (Qfontification_functions
);
29807 DEFVAR_BOOL ("unibyte-display-via-language-environment",
29808 unibyte_display_via_language_environment
,
29809 doc
: /* Non-nil means display unibyte text according to language environment.
29810 Specifically, this means that raw bytes in the range 160-255 decimal
29811 are displayed by converting them to the equivalent multibyte characters
29812 according to the current language environment. As a result, they are
29813 displayed according to the current fontset.
29815 Note that this variable affects only how these bytes are displayed,
29816 but does not change the fact they are interpreted as raw bytes. */);
29817 unibyte_display_via_language_environment
= 0;
29819 DEFVAR_LISP ("max-mini-window-height", Vmax_mini_window_height
,
29820 doc
: /* Maximum height for resizing mini-windows (the minibuffer and the echo area).
29821 If a float, it specifies a fraction of the mini-window frame's height.
29822 If an integer, it specifies a number of lines. */);
29823 Vmax_mini_window_height
= make_float (0.25);
29825 DEFVAR_LISP ("resize-mini-windows", Vresize_mini_windows
,
29826 doc
: /* How to resize mini-windows (the minibuffer and the echo area).
29827 A value of nil means don't automatically resize mini-windows.
29828 A value of t means resize them to fit the text displayed in them.
29829 A value of `grow-only', the default, means let mini-windows grow only;
29830 they return to their normal size when the minibuffer is closed, or the
29831 echo area becomes empty. */);
29832 Vresize_mini_windows
= Qgrow_only
;
29834 DEFVAR_LISP ("blink-cursor-alist", Vblink_cursor_alist
,
29835 doc
: /* Alist specifying how to blink the cursor off.
29836 Each element has the form (ON-STATE . OFF-STATE). Whenever the
29837 `cursor-type' frame-parameter or variable equals ON-STATE,
29838 comparing using `equal', Emacs uses OFF-STATE to specify
29839 how to blink it off. ON-STATE and OFF-STATE are values for
29840 the `cursor-type' frame parameter.
29842 If a frame's ON-STATE has no entry in this list,
29843 the frame's other specifications determine how to blink the cursor off. */);
29844 Vblink_cursor_alist
= Qnil
;
29846 DEFVAR_BOOL ("auto-hscroll-mode", automatic_hscrolling_p
,
29847 doc
: /* Allow or disallow automatic horizontal scrolling of windows.
29848 If non-nil, windows are automatically scrolled horizontally to make
29849 point visible. */);
29850 automatic_hscrolling_p
= 1;
29851 DEFSYM (Qauto_hscroll_mode
, "auto-hscroll-mode");
29853 DEFVAR_INT ("hscroll-margin", hscroll_margin
,
29854 doc
: /* How many columns away from the window edge point is allowed to get
29855 before automatic hscrolling will horizontally scroll the window. */);
29856 hscroll_margin
= 5;
29858 DEFVAR_LISP ("hscroll-step", Vhscroll_step
,
29859 doc
: /* How many columns to scroll the window when point gets too close to the edge.
29860 When point is less than `hscroll-margin' columns from the window
29861 edge, automatic hscrolling will scroll the window by the amount of columns
29862 determined by this variable. If its value is a positive integer, scroll that
29863 many columns. If it's a positive floating-point number, it specifies the
29864 fraction of the window's width to scroll. If it's nil or zero, point will be
29865 centered horizontally after the scroll. Any other value, including negative
29866 numbers, are treated as if the value were zero.
29868 Automatic hscrolling always moves point outside the scroll margin, so if
29869 point was more than scroll step columns inside the margin, the window will
29870 scroll more than the value given by the scroll step.
29872 Note that the lower bound for automatic hscrolling specified by `scroll-left'
29873 and `scroll-right' overrides this variable's effect. */);
29874 Vhscroll_step
= make_number (0);
29876 DEFVAR_BOOL ("message-truncate-lines", message_truncate_lines
,
29877 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
29878 Bind this around calls to `message' to let it take effect. */);
29879 message_truncate_lines
= 0;
29881 DEFVAR_LISP ("menu-bar-update-hook", Vmenu_bar_update_hook
,
29882 doc
: /* Normal hook run to update the menu bar definitions.
29883 Redisplay runs this hook before it redisplays the menu bar.
29884 This is used to update submenus such as Buffers,
29885 whose contents depend on various data. */);
29886 Vmenu_bar_update_hook
= Qnil
;
29888 DEFVAR_LISP ("menu-updating-frame", Vmenu_updating_frame
,
29889 doc
: /* Frame for which we are updating a menu.
29890 The enable predicate for a menu binding should check this variable. */);
29891 Vmenu_updating_frame
= Qnil
;
29893 DEFVAR_BOOL ("inhibit-menubar-update", inhibit_menubar_update
,
29894 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
29895 inhibit_menubar_update
= 0;
29897 DEFVAR_LISP ("wrap-prefix", Vwrap_prefix
,
29898 doc
: /* Prefix prepended to all continuation lines at display time.
29899 The value may be a string, an image, or a stretch-glyph; it is
29900 interpreted in the same way as the value of a `display' text property.
29902 This variable is overridden by any `wrap-prefix' text or overlay
29905 To add a prefix to non-continuation lines, use `line-prefix'. */);
29906 Vwrap_prefix
= Qnil
;
29907 DEFSYM (Qwrap_prefix
, "wrap-prefix");
29908 Fmake_variable_buffer_local (Qwrap_prefix
);
29910 DEFVAR_LISP ("line-prefix", Vline_prefix
,
29911 doc
: /* Prefix prepended to all non-continuation lines at display time.
29912 The value may be a string, an image, or a stretch-glyph; it is
29913 interpreted in the same way as the value of a `display' text property.
29915 This variable is overridden by any `line-prefix' text or overlay
29918 To add a prefix to continuation lines, use `wrap-prefix'. */);
29919 Vline_prefix
= Qnil
;
29920 DEFSYM (Qline_prefix
, "line-prefix");
29921 Fmake_variable_buffer_local (Qline_prefix
);
29923 DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay
,
29924 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
29925 inhibit_eval_during_redisplay
= 0;
29927 DEFVAR_BOOL ("inhibit-free-realized-faces", inhibit_free_realized_faces
,
29928 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
29929 inhibit_free_realized_faces
= 0;
29932 DEFVAR_BOOL ("inhibit-try-window-id", inhibit_try_window_id
,
29933 doc
: /* Inhibit try_window_id display optimization. */);
29934 inhibit_try_window_id
= 0;
29936 DEFVAR_BOOL ("inhibit-try-window-reusing", inhibit_try_window_reusing
,
29937 doc
: /* Inhibit try_window_reusing display optimization. */);
29938 inhibit_try_window_reusing
= 0;
29940 DEFVAR_BOOL ("inhibit-try-cursor-movement", inhibit_try_cursor_movement
,
29941 doc
: /* Inhibit try_cursor_movement display optimization. */);
29942 inhibit_try_cursor_movement
= 0;
29943 #endif /* GLYPH_DEBUG */
29945 DEFVAR_INT ("overline-margin", overline_margin
,
29946 doc
: /* Space between overline and text, in pixels.
29947 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
29948 margin to the character height. */);
29949 overline_margin
= 2;
29951 DEFVAR_INT ("underline-minimum-offset",
29952 underline_minimum_offset
,
29953 doc
: /* Minimum distance between baseline and underline.
29954 This can improve legibility of underlined text at small font sizes,
29955 particularly when using variable `x-use-underline-position-properties'
29956 with fonts that specify an UNDERLINE_POSITION relatively close to the
29957 baseline. The default value is 1. */);
29958 underline_minimum_offset
= 1;
29960 DEFVAR_BOOL ("display-hourglass", display_hourglass_p
,
29961 doc
: /* Non-nil means show an hourglass pointer, when Emacs is busy.
29962 This feature only works when on a window system that can change
29963 cursor shapes. */);
29964 display_hourglass_p
= 1;
29966 DEFVAR_LISP ("hourglass-delay", Vhourglass_delay
,
29967 doc
: /* Seconds to wait before displaying an hourglass pointer when Emacs is busy. */);
29968 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
29970 hourglass_atimer
= NULL
;
29971 hourglass_shown_p
= 0;
29973 DEFSYM (Qglyphless_char
, "glyphless-char");
29974 DEFSYM (Qhex_code
, "hex-code");
29975 DEFSYM (Qempty_box
, "empty-box");
29976 DEFSYM (Qthin_space
, "thin-space");
29977 DEFSYM (Qzero_width
, "zero-width");
29979 DEFSYM (Qglyphless_char_display
, "glyphless-char-display");
29980 /* Intern this now in case it isn't already done.
29981 Setting this variable twice is harmless.
29982 But don't staticpro it here--that is done in alloc.c. */
29983 Qchar_table_extra_slots
= intern_c_string ("char-table-extra-slots");
29984 Fput (Qglyphless_char_display
, Qchar_table_extra_slots
, make_number (1));
29986 DEFVAR_LISP ("glyphless-char-display", Vglyphless_char_display
,
29987 doc
: /* Char-table defining glyphless characters.
29988 Each element, if non-nil, should be one of the following:
29989 an ASCII acronym string: display this string in a box
29990 `hex-code': display the hexadecimal code of a character in a box
29991 `empty-box': display as an empty box
29992 `thin-space': display as 1-pixel width space
29993 `zero-width': don't display
29994 An element may also be a cons cell (GRAPHICAL . TEXT), which specifies the
29995 display method for graphical terminals and text terminals respectively.
29996 GRAPHICAL and TEXT should each have one of the values listed above.
29998 The char-table has one extra slot to control the display of a character for
29999 which no font is found. This slot only takes effect on graphical terminals.
30000 Its value should be an ASCII acronym string, `hex-code', `empty-box', or
30001 `thin-space'. The default is `empty-box'. */);
30002 Vglyphless_char_display
= Fmake_char_table (Qglyphless_char_display
, Qnil
);
30003 Fset_char_table_extra_slot (Vglyphless_char_display
, make_number (0),
30006 DEFVAR_LISP ("debug-on-message", Vdebug_on_message
,
30007 doc
: /* If non-nil, debug if a message matching this regexp is displayed. */);
30008 Vdebug_on_message
= Qnil
;
30012 /* Initialize this module when Emacs starts. */
30017 current_header_line_height
= current_mode_line_height
= -1;
30019 CHARPOS (this_line_start_pos
) = 0;
30021 if (!noninteractive
)
30023 struct window
*m
= XWINDOW (minibuf_window
);
30024 Lisp_Object frame
= m
->frame
;
30025 struct frame
*f
= XFRAME (frame
);
30026 Lisp_Object root
= FRAME_ROOT_WINDOW (f
);
30027 struct window
*r
= XWINDOW (root
);
30030 echo_area_window
= minibuf_window
;
30032 r
->top_line
= FRAME_TOP_MARGIN (f
);
30033 r
->total_lines
= FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
);
30034 r
->total_cols
= FRAME_COLS (f
);
30036 m
->top_line
= FRAME_LINES (f
) - 1;
30037 m
->total_lines
= 1;
30038 m
->total_cols
= FRAME_COLS (f
);
30040 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
30041 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
30042 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
30044 /* The default ellipsis glyphs `...'. */
30045 for (i
= 0; i
< 3; ++i
)
30046 default_invis_vector
[i
] = make_number ('.');
30050 /* Allocate the buffer for frame titles.
30051 Also used for `format-mode-line'. */
30053 mode_line_noprop_buf
= xmalloc (size
);
30054 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
30055 mode_line_noprop_ptr
= mode_line_noprop_buf
;
30056 mode_line_target
= MODE_LINE_DISPLAY
;
30059 help_echo_showing_p
= 0;
30062 /* Platform-independent portion of hourglass implementation. */
30064 /* Cancel a currently active hourglass timer, and start a new one. */
30066 start_hourglass (void)
30068 #if defined (HAVE_WINDOW_SYSTEM)
30071 cancel_hourglass ();
30073 if (INTEGERP (Vhourglass_delay
)
30074 && XINT (Vhourglass_delay
) > 0)
30075 delay
= make_emacs_time (min (XINT (Vhourglass_delay
),
30076 TYPE_MAXIMUM (time_t)),
30078 else if (FLOATP (Vhourglass_delay
)
30079 && XFLOAT_DATA (Vhourglass_delay
) > 0)
30080 delay
= EMACS_TIME_FROM_DOUBLE (XFLOAT_DATA (Vhourglass_delay
));
30082 delay
= make_emacs_time (DEFAULT_HOURGLASS_DELAY
, 0);
30086 extern void w32_note_current_window (void);
30087 w32_note_current_window ();
30089 #endif /* HAVE_NTGUI */
30091 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
30092 show_hourglass
, NULL
);
30097 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
30100 cancel_hourglass (void)
30102 #if defined (HAVE_WINDOW_SYSTEM)
30103 if (hourglass_atimer
)
30105 cancel_atimer (hourglass_atimer
);
30106 hourglass_atimer
= NULL
;
30109 if (hourglass_shown_p
)