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
)
7509 eassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
7511 it
->face_id
= it
->saved_face_id
;
7513 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
7514 That seemed totally bogus - so I changed it... */
7515 gc
= it
->dpvec
[it
->current
.dpvec_index
];
7517 if (GLYPH_CODE_P (gc
))
7519 it
->c
= GLYPH_CODE_CHAR (gc
);
7520 it
->len
= CHAR_BYTES (it
->c
);
7522 /* The entry may contain a face id to use. Such a face id is
7523 the id of a Lisp face, not a realized face. A face id of
7524 zero means no face is specified. */
7525 if (it
->dpvec_face_id
>= 0)
7526 it
->face_id
= it
->dpvec_face_id
;
7529 int lface_id
= GLYPH_CODE_FACE (gc
);
7531 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
7536 /* Display table entry is invalid. Return a space. */
7537 it
->c
= ' ', it
->len
= 1;
7539 /* Don't change position and object of the iterator here. They are
7540 still the values of the character that had this display table
7541 entry or was translated, and that's what we want. */
7542 it
->what
= IT_CHARACTER
;
7546 /* Get the first element of string/buffer in the visual order, after
7547 being reseated to a new position in a string or a buffer. */
7549 get_visually_first_element (struct it
*it
)
7551 int string_p
= STRINGP (it
->string
) || it
->s
;
7552 ptrdiff_t eob
= (string_p
? it
->bidi_it
.string
.schars
: ZV
);
7553 ptrdiff_t bob
= (string_p
? 0 : BEGV
);
7555 if (STRINGP (it
->string
))
7557 it
->bidi_it
.charpos
= IT_STRING_CHARPOS (*it
);
7558 it
->bidi_it
.bytepos
= IT_STRING_BYTEPOS (*it
);
7562 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
7563 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
7566 if (it
->bidi_it
.charpos
== eob
)
7568 /* Nothing to do, but reset the FIRST_ELT flag, like
7569 bidi_paragraph_init does, because we are not going to
7571 it
->bidi_it
.first_elt
= 0;
7573 else if (it
->bidi_it
.charpos
== bob
7575 && (FETCH_CHAR (it
->bidi_it
.bytepos
- 1) == '\n'
7576 || FETCH_CHAR (it
->bidi_it
.bytepos
) == '\n')))
7578 /* If we are at the beginning of a line/string, we can produce
7579 the next element right away. */
7580 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7581 bidi_move_to_visually_next (&it
->bidi_it
);
7585 ptrdiff_t orig_bytepos
= it
->bidi_it
.bytepos
;
7587 /* We need to prime the bidi iterator starting at the line's or
7588 string's beginning, before we will be able to produce the
7591 it
->bidi_it
.charpos
= it
->bidi_it
.bytepos
= 0;
7593 it
->bidi_it
.charpos
= find_newline_no_quit (IT_CHARPOS (*it
),
7594 IT_BYTEPOS (*it
), -1,
7595 &it
->bidi_it
.bytepos
);
7596 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7599 /* Now return to buffer/string position where we were asked
7600 to get the next display element, and produce that. */
7601 bidi_move_to_visually_next (&it
->bidi_it
);
7603 while (it
->bidi_it
.bytepos
!= orig_bytepos
7604 && it
->bidi_it
.charpos
< eob
);
7607 /* Adjust IT's position information to where we ended up. */
7608 if (STRINGP (it
->string
))
7610 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7611 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7615 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7616 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7619 if (STRINGP (it
->string
) || !it
->s
)
7621 ptrdiff_t stop
, charpos
, bytepos
;
7623 if (STRINGP (it
->string
))
7626 stop
= SCHARS (it
->string
);
7627 if (stop
> it
->end_charpos
)
7628 stop
= it
->end_charpos
;
7629 charpos
= IT_STRING_CHARPOS (*it
);
7630 bytepos
= IT_STRING_BYTEPOS (*it
);
7634 stop
= it
->end_charpos
;
7635 charpos
= IT_CHARPOS (*it
);
7636 bytepos
= IT_BYTEPOS (*it
);
7638 if (it
->bidi_it
.scan_dir
< 0)
7640 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
, stop
,
7645 /* Load IT with the next display element from Lisp string IT->string.
7646 IT->current.string_pos is the current position within the string.
7647 If IT->current.overlay_string_index >= 0, the Lisp string is an
7651 next_element_from_string (struct it
*it
)
7653 struct text_pos position
;
7655 eassert (STRINGP (it
->string
));
7656 eassert (!it
->bidi_p
|| EQ (it
->string
, it
->bidi_it
.string
.lstring
));
7657 eassert (IT_STRING_CHARPOS (*it
) >= 0);
7658 position
= it
->current
.string_pos
;
7660 /* With bidi reordering, the character to display might not be the
7661 character at IT_STRING_CHARPOS. BIDI_IT.FIRST_ELT non-zero means
7662 that we were reseat()ed to a new string, whose paragraph
7663 direction is not known. */
7664 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7666 get_visually_first_element (it
);
7667 SET_TEXT_POS (position
, IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
));
7670 /* Time to check for invisible text? */
7671 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
7673 if (IT_STRING_CHARPOS (*it
) >= it
->stop_charpos
)
7676 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7677 || IT_STRING_CHARPOS (*it
) == it
->stop_charpos
))
7679 /* With bidi non-linear iteration, we could find
7680 ourselves far beyond the last computed stop_charpos,
7681 with several other stop positions in between that we
7682 missed. Scan them all now, in buffer's logical
7683 order, until we find and handle the last stop_charpos
7684 that precedes our current position. */
7685 handle_stop_backwards (it
, it
->stop_charpos
);
7686 return GET_NEXT_DISPLAY_ELEMENT (it
);
7692 /* Take note of the stop position we just moved
7693 across, for when we will move back across it. */
7694 it
->prev_stop
= it
->stop_charpos
;
7695 /* If we are at base paragraph embedding level, take
7696 note of the last stop position seen at this
7698 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7699 it
->base_level_stop
= it
->stop_charpos
;
7703 /* Since a handler may have changed IT->method, we must
7705 return GET_NEXT_DISPLAY_ELEMENT (it
);
7709 /* If we are before prev_stop, we may have overstepped
7710 on our way backwards a stop_pos, and if so, we need
7711 to handle that stop_pos. */
7712 && IT_STRING_CHARPOS (*it
) < it
->prev_stop
7713 /* We can sometimes back up for reasons that have nothing
7714 to do with bidi reordering. E.g., compositions. The
7715 code below is only needed when we are above the base
7716 embedding level, so test for that explicitly. */
7717 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7719 /* If we lost track of base_level_stop, we have no better
7720 place for handle_stop_backwards to start from than string
7721 beginning. This happens, e.g., when we were reseated to
7722 the previous screenful of text by vertical-motion. */
7723 if (it
->base_level_stop
<= 0
7724 || IT_STRING_CHARPOS (*it
) < it
->base_level_stop
)
7725 it
->base_level_stop
= 0;
7726 handle_stop_backwards (it
, it
->base_level_stop
);
7727 return GET_NEXT_DISPLAY_ELEMENT (it
);
7731 if (it
->current
.overlay_string_index
>= 0)
7733 /* Get the next character from an overlay string. In overlay
7734 strings, there is no field width or padding with spaces to
7736 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7741 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7742 IT_STRING_BYTEPOS (*it
),
7743 it
->bidi_it
.scan_dir
< 0
7745 : SCHARS (it
->string
))
7746 && next_element_from_composition (it
))
7750 else if (STRING_MULTIBYTE (it
->string
))
7752 const unsigned char *s
= (SDATA (it
->string
)
7753 + IT_STRING_BYTEPOS (*it
));
7754 it
->c
= string_char_and_length (s
, &it
->len
);
7758 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7764 /* Get the next character from a Lisp string that is not an
7765 overlay string. Such strings come from the mode line, for
7766 example. We may have to pad with spaces, or truncate the
7767 string. See also next_element_from_c_string. */
7768 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7773 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
7775 /* Pad with spaces. */
7776 it
->c
= ' ', it
->len
= 1;
7777 CHARPOS (position
) = BYTEPOS (position
) = -1;
7779 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7780 IT_STRING_BYTEPOS (*it
),
7781 it
->bidi_it
.scan_dir
< 0
7783 : it
->string_nchars
)
7784 && next_element_from_composition (it
))
7788 else if (STRING_MULTIBYTE (it
->string
))
7790 const unsigned char *s
= (SDATA (it
->string
)
7791 + IT_STRING_BYTEPOS (*it
));
7792 it
->c
= string_char_and_length (s
, &it
->len
);
7796 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7801 /* Record what we have and where it came from. */
7802 it
->what
= IT_CHARACTER
;
7803 it
->object
= it
->string
;
7804 it
->position
= position
;
7809 /* Load IT with next display element from C string IT->s.
7810 IT->string_nchars is the maximum number of characters to return
7811 from the string. IT->end_charpos may be greater than
7812 IT->string_nchars when this function is called, in which case we
7813 may have to return padding spaces. Value is zero if end of string
7814 reached, including padding spaces. */
7817 next_element_from_c_string (struct it
*it
)
7822 eassert (!it
->bidi_p
|| it
->s
== it
->bidi_it
.string
.s
);
7823 it
->what
= IT_CHARACTER
;
7824 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
7827 /* With bidi reordering, the character to display might not be the
7828 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7829 we were reseated to a new string, whose paragraph direction is
7831 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7832 get_visually_first_element (it
);
7834 /* IT's position can be greater than IT->string_nchars in case a
7835 field width or precision has been specified when the iterator was
7837 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7839 /* End of the game. */
7843 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
7845 /* Pad with spaces. */
7846 it
->c
= ' ', it
->len
= 1;
7847 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
7849 else if (it
->multibyte_p
)
7850 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
), &it
->len
);
7852 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
7858 /* Set up IT to return characters from an ellipsis, if appropriate.
7859 The definition of the ellipsis glyphs may come from a display table
7860 entry. This function fills IT with the first glyph from the
7861 ellipsis if an ellipsis is to be displayed. */
7864 next_element_from_ellipsis (struct it
*it
)
7866 if (it
->selective_display_ellipsis_p
)
7867 setup_for_ellipsis (it
, it
->len
);
7870 /* The face at the current position may be different from the
7871 face we find after the invisible text. Remember what it
7872 was in IT->saved_face_id, and signal that it's there by
7873 setting face_before_selective_p. */
7874 it
->saved_face_id
= it
->face_id
;
7875 it
->method
= GET_FROM_BUFFER
;
7876 it
->object
= it
->w
->contents
;
7877 reseat_at_next_visible_line_start (it
, 1);
7878 it
->face_before_selective_p
= 1;
7881 return GET_NEXT_DISPLAY_ELEMENT (it
);
7885 /* Deliver an image display element. The iterator IT is already
7886 filled with image information (done in handle_display_prop). Value
7891 next_element_from_image (struct it
*it
)
7893 it
->what
= IT_IMAGE
;
7894 it
->ignore_overlay_strings_at_pos_p
= 0;
7898 #ifdef HAVE_XWIDGETS
7899 /* im not sure about this FIXME JAVE*/
7901 next_element_from_xwidget (struct it
*it
)
7903 it
->what
= IT_XWIDGET
;
7904 //assert_valid_xwidget_id(it->xwidget_id,"next_element_from_xwidget");
7905 //this is shaky because why do we set "what" if we dont set the other parts??
7906 //printf("xwidget_id %d: in next_element_from_xwidget: FIXME \n", it->xwidget_id);
7912 /* Fill iterator IT with next display element from a stretch glyph
7913 property. IT->object is the value of the text property. Value is
7917 next_element_from_stretch (struct it
*it
)
7919 it
->what
= IT_STRETCH
;
7923 /* Scan backwards from IT's current position until we find a stop
7924 position, or until BEGV. This is called when we find ourself
7925 before both the last known prev_stop and base_level_stop while
7926 reordering bidirectional text. */
7929 compute_stop_pos_backwards (struct it
*it
)
7931 const int SCAN_BACK_LIMIT
= 1000;
7932 struct text_pos pos
;
7933 struct display_pos save_current
= it
->current
;
7934 struct text_pos save_position
= it
->position
;
7935 ptrdiff_t charpos
= IT_CHARPOS (*it
);
7936 ptrdiff_t where_we_are
= charpos
;
7937 ptrdiff_t save_stop_pos
= it
->stop_charpos
;
7938 ptrdiff_t save_end_pos
= it
->end_charpos
;
7940 eassert (NILP (it
->string
) && !it
->s
);
7941 eassert (it
->bidi_p
);
7945 it
->end_charpos
= min (charpos
+ 1, ZV
);
7946 charpos
= max (charpos
- SCAN_BACK_LIMIT
, BEGV
);
7947 SET_TEXT_POS (pos
, charpos
, CHAR_TO_BYTE (charpos
));
7948 reseat_1 (it
, pos
, 0);
7949 compute_stop_pos (it
);
7950 /* We must advance forward, right? */
7951 if (it
->stop_charpos
<= charpos
)
7954 while (charpos
> BEGV
&& it
->stop_charpos
>= it
->end_charpos
);
7956 if (it
->stop_charpos
<= where_we_are
)
7957 it
->prev_stop
= it
->stop_charpos
;
7959 it
->prev_stop
= BEGV
;
7961 it
->current
= save_current
;
7962 it
->position
= save_position
;
7963 it
->stop_charpos
= save_stop_pos
;
7964 it
->end_charpos
= save_end_pos
;
7967 /* Scan forward from CHARPOS in the current buffer/string, until we
7968 find a stop position > current IT's position. Then handle the stop
7969 position before that. This is called when we bump into a stop
7970 position while reordering bidirectional text. CHARPOS should be
7971 the last previously processed stop_pos (or BEGV/0, if none were
7972 processed yet) whose position is less that IT's current
7976 handle_stop_backwards (struct it
*it
, ptrdiff_t charpos
)
7978 int bufp
= !STRINGP (it
->string
);
7979 ptrdiff_t where_we_are
= (bufp
? IT_CHARPOS (*it
) : IT_STRING_CHARPOS (*it
));
7980 struct display_pos save_current
= it
->current
;
7981 struct text_pos save_position
= it
->position
;
7982 struct text_pos pos1
;
7983 ptrdiff_t next_stop
;
7985 /* Scan in strict logical order. */
7986 eassert (it
->bidi_p
);
7990 it
->prev_stop
= charpos
;
7993 SET_TEXT_POS (pos1
, charpos
, CHAR_TO_BYTE (charpos
));
7994 reseat_1 (it
, pos1
, 0);
7997 it
->current
.string_pos
= string_pos (charpos
, it
->string
);
7998 compute_stop_pos (it
);
7999 /* We must advance forward, right? */
8000 if (it
->stop_charpos
<= it
->prev_stop
)
8002 charpos
= it
->stop_charpos
;
8004 while (charpos
<= where_we_are
);
8007 it
->current
= save_current
;
8008 it
->position
= save_position
;
8009 next_stop
= it
->stop_charpos
;
8010 it
->stop_charpos
= it
->prev_stop
;
8012 it
->stop_charpos
= next_stop
;
8015 /* Load IT with the next display element from current_buffer. Value
8016 is zero if end of buffer reached. IT->stop_charpos is the next
8017 position at which to stop and check for text properties or buffer
8021 next_element_from_buffer (struct it
*it
)
8025 eassert (IT_CHARPOS (*it
) >= BEGV
);
8026 eassert (NILP (it
->string
) && !it
->s
);
8027 eassert (!it
->bidi_p
8028 || (EQ (it
->bidi_it
.string
.lstring
, Qnil
)
8029 && it
->bidi_it
.string
.s
== NULL
));
8031 /* With bidi reordering, the character to display might not be the
8032 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
8033 we were reseat()ed to a new buffer position, which is potentially
8034 a different paragraph. */
8035 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
8037 get_visually_first_element (it
);
8038 SET_TEXT_POS (it
->position
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8041 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
8043 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
8045 int overlay_strings_follow_p
;
8047 /* End of the game, except when overlay strings follow that
8048 haven't been returned yet. */
8049 if (it
->overlay_strings_at_end_processed_p
)
8050 overlay_strings_follow_p
= 0;
8053 it
->overlay_strings_at_end_processed_p
= 1;
8054 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
8057 if (overlay_strings_follow_p
)
8058 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
8062 it
->position
= it
->current
.pos
;
8066 else if (!(!it
->bidi_p
8067 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
8068 || IT_CHARPOS (*it
) == it
->stop_charpos
))
8070 /* With bidi non-linear iteration, we could find ourselves
8071 far beyond the last computed stop_charpos, with several
8072 other stop positions in between that we missed. Scan
8073 them all now, in buffer's logical order, until we find
8074 and handle the last stop_charpos that precedes our
8075 current position. */
8076 handle_stop_backwards (it
, it
->stop_charpos
);
8077 return GET_NEXT_DISPLAY_ELEMENT (it
);
8083 /* Take note of the stop position we just moved across,
8084 for when we will move back across it. */
8085 it
->prev_stop
= it
->stop_charpos
;
8086 /* If we are at base paragraph embedding level, take
8087 note of the last stop position seen at this
8089 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8090 it
->base_level_stop
= it
->stop_charpos
;
8093 return GET_NEXT_DISPLAY_ELEMENT (it
);
8097 /* If we are before prev_stop, we may have overstepped on
8098 our way backwards a stop_pos, and if so, we need to
8099 handle that stop_pos. */
8100 && IT_CHARPOS (*it
) < it
->prev_stop
8101 /* We can sometimes back up for reasons that have nothing
8102 to do with bidi reordering. E.g., compositions. The
8103 code below is only needed when we are above the base
8104 embedding level, so test for that explicitly. */
8105 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8107 if (it
->base_level_stop
<= 0
8108 || IT_CHARPOS (*it
) < it
->base_level_stop
)
8110 /* If we lost track of base_level_stop, we need to find
8111 prev_stop by looking backwards. This happens, e.g., when
8112 we were reseated to the previous screenful of text by
8114 it
->base_level_stop
= BEGV
;
8115 compute_stop_pos_backwards (it
);
8116 handle_stop_backwards (it
, it
->prev_stop
);
8119 handle_stop_backwards (it
, it
->base_level_stop
);
8120 return GET_NEXT_DISPLAY_ELEMENT (it
);
8124 /* No face changes, overlays etc. in sight, so just return a
8125 character from current_buffer. */
8129 /* Maybe run the redisplay end trigger hook. Performance note:
8130 This doesn't seem to cost measurable time. */
8131 if (it
->redisplay_end_trigger_charpos
8133 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
8134 run_redisplay_end_trigger_hook (it
);
8136 stop
= it
->bidi_it
.scan_dir
< 0 ? -1 : it
->end_charpos
;
8137 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
8139 && next_element_from_composition (it
))
8144 /* Get the next character, maybe multibyte. */
8145 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
8146 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
8147 it
->c
= STRING_CHAR_AND_LENGTH (p
, it
->len
);
8149 it
->c
= *p
, it
->len
= 1;
8151 /* Record what we have and where it came from. */
8152 it
->what
= IT_CHARACTER
;
8153 it
->object
= it
->w
->contents
;
8154 it
->position
= it
->current
.pos
;
8156 /* Normally we return the character found above, except when we
8157 really want to return an ellipsis for selective display. */
8162 /* A value of selective > 0 means hide lines indented more
8163 than that number of columns. */
8164 if (it
->selective
> 0
8165 && IT_CHARPOS (*it
) + 1 < ZV
8166 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
8167 IT_BYTEPOS (*it
) + 1,
8170 success_p
= next_element_from_ellipsis (it
);
8171 it
->dpvec_char_len
= -1;
8174 else if (it
->c
== '\r' && it
->selective
== -1)
8176 /* A value of selective == -1 means that everything from the
8177 CR to the end of the line is invisible, with maybe an
8178 ellipsis displayed for it. */
8179 success_p
= next_element_from_ellipsis (it
);
8180 it
->dpvec_char_len
= -1;
8185 /* Value is zero if end of buffer reached. */
8186 eassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
8191 /* Run the redisplay end trigger hook for IT. */
8194 run_redisplay_end_trigger_hook (struct it
*it
)
8196 Lisp_Object args
[3];
8198 /* IT->glyph_row should be non-null, i.e. we should be actually
8199 displaying something, or otherwise we should not run the hook. */
8200 eassert (it
->glyph_row
);
8202 /* Set up hook arguments. */
8203 args
[0] = Qredisplay_end_trigger_functions
;
8204 args
[1] = it
->window
;
8205 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
8206 it
->redisplay_end_trigger_charpos
= 0;
8208 /* Since we are *trying* to run these functions, don't try to run
8209 them again, even if they get an error. */
8210 wset_redisplay_end_trigger (it
->w
, Qnil
);
8211 Frun_hook_with_args (3, args
);
8213 /* Notice if it changed the face of the character we are on. */
8214 handle_face_prop (it
);
8218 /* Deliver a composition display element. Unlike the other
8219 next_element_from_XXX, this function is not registered in the array
8220 get_next_element[]. It is called from next_element_from_buffer and
8221 next_element_from_string when necessary. */
8224 next_element_from_composition (struct it
*it
)
8226 it
->what
= IT_COMPOSITION
;
8227 it
->len
= it
->cmp_it
.nbytes
;
8228 if (STRINGP (it
->string
))
8232 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
8233 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
8236 it
->position
= it
->current
.string_pos
;
8237 it
->object
= it
->string
;
8238 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
8239 IT_STRING_BYTEPOS (*it
), it
->string
);
8245 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
8246 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
8249 if (it
->bidi_it
.new_paragraph
)
8250 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
8251 /* Resync the bidi iterator with IT's new position.
8252 FIXME: this doesn't support bidirectional text. */
8253 while (it
->bidi_it
.charpos
< IT_CHARPOS (*it
))
8254 bidi_move_to_visually_next (&it
->bidi_it
);
8258 it
->position
= it
->current
.pos
;
8259 it
->object
= it
->w
->contents
;
8260 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
8261 IT_BYTEPOS (*it
), Qnil
);
8268 /***********************************************************************
8269 Moving an iterator without producing glyphs
8270 ***********************************************************************/
8272 /* Check if iterator is at a position corresponding to a valid buffer
8273 position after some move_it_ call. */
8275 #define IT_POS_VALID_AFTER_MOVE_P(it) \
8276 ((it)->method == GET_FROM_STRING \
8277 ? IT_STRING_CHARPOS (*it) == 0 \
8281 /* Move iterator IT to a specified buffer or X position within one
8282 line on the display without producing glyphs.
8284 OP should be a bit mask including some or all of these bits:
8285 MOVE_TO_X: Stop upon reaching x-position TO_X.
8286 MOVE_TO_POS: Stop upon reaching buffer or string position TO_CHARPOS.
8287 Regardless of OP's value, stop upon reaching the end of the display line.
8289 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
8290 This means, in particular, that TO_X includes window's horizontal
8293 The return value has several possible values that
8294 say what condition caused the scan to stop:
8296 MOVE_POS_MATCH_OR_ZV
8297 - when TO_POS or ZV was reached.
8300 -when TO_X was reached before TO_POS or ZV were reached.
8303 - when we reached the end of the display area and the line must
8307 - when we reached the end of the display area and the line is
8311 - when we stopped at a line end, i.e. a newline or a CR and selective
8314 static enum move_it_result
8315 move_it_in_display_line_to (struct it
*it
,
8316 ptrdiff_t to_charpos
, int to_x
,
8317 enum move_operation_enum op
)
8319 enum move_it_result result
= MOVE_UNDEFINED
;
8320 struct glyph_row
*saved_glyph_row
;
8321 struct it wrap_it
, atpos_it
, atx_it
, ppos_it
;
8322 void *wrap_data
= NULL
, *atpos_data
= NULL
, *atx_data
= NULL
;
8323 void *ppos_data
= NULL
;
8325 enum it_method prev_method
= it
->method
;
8326 ptrdiff_t prev_pos
= IT_CHARPOS (*it
);
8327 int saw_smaller_pos
= prev_pos
< to_charpos
;
8329 /* Don't produce glyphs in produce_glyphs. */
8330 saved_glyph_row
= it
->glyph_row
;
8331 it
->glyph_row
= NULL
;
8333 /* Use wrap_it to save a copy of IT wherever a word wrap could
8334 occur. Use atpos_it to save a copy of IT at the desired buffer
8335 position, if found, so that we can scan ahead and check if the
8336 word later overshoots the window edge. Use atx_it similarly, for
8342 /* Use ppos_it under bidi reordering to save a copy of IT for the
8343 position > CHARPOS that is the closest to CHARPOS. We restore
8344 that position in IT when we have scanned the entire display line
8345 without finding a match for CHARPOS and all the character
8346 positions are greater than CHARPOS. */
8349 SAVE_IT (ppos_it
, *it
, ppos_data
);
8350 SET_TEXT_POS (ppos_it
.current
.pos
, ZV
, ZV_BYTE
);
8351 if ((op
& MOVE_TO_POS
) && IT_CHARPOS (*it
) >= to_charpos
)
8352 SAVE_IT (ppos_it
, *it
, ppos_data
);
8355 #define BUFFER_POS_REACHED_P() \
8356 ((op & MOVE_TO_POS) != 0 \
8357 && BUFFERP (it->object) \
8358 && (IT_CHARPOS (*it) == to_charpos \
8360 || BIDI_AT_BASE_LEVEL (it->bidi_it)) \
8361 && IT_CHARPOS (*it) > to_charpos) \
8362 || (it->what == IT_COMPOSITION \
8363 && ((IT_CHARPOS (*it) > to_charpos \
8364 && to_charpos >= it->cmp_it.charpos) \
8365 || (IT_CHARPOS (*it) < to_charpos \
8366 && to_charpos <= it->cmp_it.charpos)))) \
8367 && (it->method == GET_FROM_BUFFER \
8368 || (it->method == GET_FROM_DISPLAY_VECTOR \
8369 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
8371 /* If there's a line-/wrap-prefix, handle it. */
8372 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
8373 && it
->current_y
< it
->last_visible_y
)
8374 handle_line_prefix (it
);
8376 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8377 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8381 int x
, i
, ascent
= 0, descent
= 0;
8383 /* Utility macro to reset an iterator with x, ascent, and descent. */
8384 #define IT_RESET_X_ASCENT_DESCENT(IT) \
8385 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
8386 (IT)->max_descent = descent)
8388 /* Stop if we move beyond TO_CHARPOS (after an image or a
8389 display string or stretch glyph). */
8390 if ((op
& MOVE_TO_POS
) != 0
8391 && BUFFERP (it
->object
)
8392 && it
->method
== GET_FROM_BUFFER
8394 /* When the iterator is at base embedding level, we
8395 are guaranteed that characters are delivered for
8396 display in strictly increasing order of their
8397 buffer positions. */
8398 || BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8399 && IT_CHARPOS (*it
) > to_charpos
)
8401 && (prev_method
== GET_FROM_IMAGE
8402 || prev_method
== GET_FROM_STRETCH
8403 || prev_method
== GET_FROM_STRING
)
8404 /* Passed TO_CHARPOS from left to right. */
8405 && ((prev_pos
< to_charpos
8406 && IT_CHARPOS (*it
) > to_charpos
)
8407 /* Passed TO_CHARPOS from right to left. */
8408 || (prev_pos
> to_charpos
8409 && IT_CHARPOS (*it
) < to_charpos
)))))
8411 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8413 result
= MOVE_POS_MATCH_OR_ZV
;
8416 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8417 /* If wrap_it is valid, the current position might be in a
8418 word that is wrapped. So, save the iterator in
8419 atpos_it and continue to see if wrapping happens. */
8420 SAVE_IT (atpos_it
, *it
, atpos_data
);
8423 /* Stop when ZV reached.
8424 We used to stop here when TO_CHARPOS reached as well, but that is
8425 too soon if this glyph does not fit on this line. So we handle it
8426 explicitly below. */
8427 if (!get_next_display_element (it
))
8429 result
= MOVE_POS_MATCH_OR_ZV
;
8433 if (it
->line_wrap
== TRUNCATE
)
8435 if (BUFFER_POS_REACHED_P ())
8437 result
= MOVE_POS_MATCH_OR_ZV
;
8443 if (it
->line_wrap
== WORD_WRAP
)
8445 if (IT_DISPLAYING_WHITESPACE (it
))
8449 /* We have reached a glyph that follows one or more
8450 whitespace characters. If the position is
8451 already found, we are done. */
8452 if (atpos_it
.sp
>= 0)
8454 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8455 result
= MOVE_POS_MATCH_OR_ZV
;
8460 RESTORE_IT (it
, &atx_it
, atx_data
);
8461 result
= MOVE_X_REACHED
;
8464 /* Otherwise, we can wrap here. */
8465 SAVE_IT (wrap_it
, *it
, wrap_data
);
8471 /* Remember the line height for the current line, in case
8472 the next element doesn't fit on the line. */
8473 ascent
= it
->max_ascent
;
8474 descent
= it
->max_descent
;
8476 /* The call to produce_glyphs will get the metrics of the
8477 display element IT is loaded with. Record the x-position
8478 before this display element, in case it doesn't fit on the
8482 PRODUCE_GLYPHS (it
);
8484 if (it
->area
!= TEXT_AREA
)
8486 prev_method
= it
->method
;
8487 if (it
->method
== GET_FROM_BUFFER
)
8488 prev_pos
= IT_CHARPOS (*it
);
8489 set_iterator_to_next (it
, 1);
8490 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8491 SET_TEXT_POS (this_line_min_pos
,
8492 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8494 && (op
& MOVE_TO_POS
)
8495 && IT_CHARPOS (*it
) > to_charpos
8496 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8497 SAVE_IT (ppos_it
, *it
, ppos_data
);
8501 /* The number of glyphs we get back in IT->nglyphs will normally
8502 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
8503 character on a terminal frame, or (iii) a line end. For the
8504 second case, IT->nglyphs - 1 padding glyphs will be present.
8505 (On X frames, there is only one glyph produced for a
8506 composite character.)
8508 The behavior implemented below means, for continuation lines,
8509 that as many spaces of a TAB as fit on the current line are
8510 displayed there. For terminal frames, as many glyphs of a
8511 multi-glyph character are displayed in the current line, too.
8512 This is what the old redisplay code did, and we keep it that
8513 way. Under X, the whole shape of a complex character must
8514 fit on the line or it will be completely displayed in the
8517 Note that both for tabs and padding glyphs, all glyphs have
8521 /* More than one glyph or glyph doesn't fit on line. All
8522 glyphs have the same width. */
8523 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
8525 int x_before_this_char
= x
;
8526 int hpos_before_this_char
= it
->hpos
;
8528 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
8530 new_x
= x
+ single_glyph_width
;
8532 /* We want to leave anything reaching TO_X to the caller. */
8533 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
8535 if (BUFFER_POS_REACHED_P ())
8537 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8538 goto buffer_pos_reached
;
8539 if (atpos_it
.sp
< 0)
8541 SAVE_IT (atpos_it
, *it
, atpos_data
);
8542 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8547 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8550 result
= MOVE_X_REACHED
;
8555 SAVE_IT (atx_it
, *it
, atx_data
);
8556 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
8561 if (/* Lines are continued. */
8562 it
->line_wrap
!= TRUNCATE
8563 && (/* And glyph doesn't fit on the line. */
8564 new_x
> it
->last_visible_x
8565 /* Or it fits exactly and we're on a window
8567 || (new_x
== it
->last_visible_x
8568 && FRAME_WINDOW_P (it
->f
)
8569 && ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
8570 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8571 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
8573 if (/* IT->hpos == 0 means the very first glyph
8574 doesn't fit on the line, e.g. a wide image. */
8576 || (new_x
== it
->last_visible_x
8577 && FRAME_WINDOW_P (it
->f
)))
8580 it
->current_x
= new_x
;
8582 /* The character's last glyph just barely fits
8584 if (i
== it
->nglyphs
- 1)
8586 /* If this is the destination position,
8587 return a position *before* it in this row,
8588 now that we know it fits in this row. */
8589 if (BUFFER_POS_REACHED_P ())
8591 if (it
->line_wrap
!= WORD_WRAP
8594 it
->hpos
= hpos_before_this_char
;
8595 it
->current_x
= x_before_this_char
;
8596 result
= MOVE_POS_MATCH_OR_ZV
;
8599 if (it
->line_wrap
== WORD_WRAP
8602 SAVE_IT (atpos_it
, *it
, atpos_data
);
8603 atpos_it
.current_x
= x_before_this_char
;
8604 atpos_it
.hpos
= hpos_before_this_char
;
8608 prev_method
= it
->method
;
8609 if (it
->method
== GET_FROM_BUFFER
)
8610 prev_pos
= IT_CHARPOS (*it
);
8611 set_iterator_to_next (it
, 1);
8612 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8613 SET_TEXT_POS (this_line_min_pos
,
8614 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8615 /* On graphical terminals, newlines may
8616 "overflow" into the fringe if
8617 overflow-newline-into-fringe is non-nil.
8618 On text terminals, and on graphical
8619 terminals with no right margin, newlines
8620 may overflow into the last glyph on the
8622 if (!FRAME_WINDOW_P (it
->f
)
8624 && it
->bidi_it
.paragraph_dir
== R2L
)
8625 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8626 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0
8627 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8629 if (!get_next_display_element (it
))
8631 result
= MOVE_POS_MATCH_OR_ZV
;
8634 if (BUFFER_POS_REACHED_P ())
8636 if (ITERATOR_AT_END_OF_LINE_P (it
))
8637 result
= MOVE_POS_MATCH_OR_ZV
;
8639 result
= MOVE_LINE_CONTINUED
;
8642 if (ITERATOR_AT_END_OF_LINE_P (it
)
8643 && (it
->line_wrap
!= WORD_WRAP
8646 result
= MOVE_NEWLINE_OR_CR
;
8653 IT_RESET_X_ASCENT_DESCENT (it
);
8655 if (wrap_it
.sp
>= 0)
8657 RESTORE_IT (it
, &wrap_it
, wrap_data
);
8662 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
8664 result
= MOVE_LINE_CONTINUED
;
8668 if (BUFFER_POS_REACHED_P ())
8670 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8671 goto buffer_pos_reached
;
8672 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8674 SAVE_IT (atpos_it
, *it
, atpos_data
);
8675 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8679 if (new_x
> it
->first_visible_x
)
8681 /* Glyph is visible. Increment number of glyphs that
8682 would be displayed. */
8687 if (result
!= MOVE_UNDEFINED
)
8690 else if (BUFFER_POS_REACHED_P ())
8693 IT_RESET_X_ASCENT_DESCENT (it
);
8694 result
= MOVE_POS_MATCH_OR_ZV
;
8697 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
8699 /* Stop when TO_X specified and reached. This check is
8700 necessary here because of lines consisting of a line end,
8701 only. The line end will not produce any glyphs and we
8702 would never get MOVE_X_REACHED. */
8703 eassert (it
->nglyphs
== 0);
8704 result
= MOVE_X_REACHED
;
8708 /* Is this a line end? If yes, we're done. */
8709 if (ITERATOR_AT_END_OF_LINE_P (it
))
8711 /* If we are past TO_CHARPOS, but never saw any character
8712 positions smaller than TO_CHARPOS, return
8713 MOVE_POS_MATCH_OR_ZV, like the unidirectional display
8715 if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0)
8717 if (!saw_smaller_pos
&& IT_CHARPOS (*it
) > to_charpos
)
8719 if (IT_CHARPOS (ppos_it
) < ZV
)
8721 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8722 result
= MOVE_POS_MATCH_OR_ZV
;
8725 goto buffer_pos_reached
;
8727 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
>= 0
8728 && IT_CHARPOS (*it
) > to_charpos
)
8729 goto buffer_pos_reached
;
8731 result
= MOVE_NEWLINE_OR_CR
;
8734 result
= MOVE_NEWLINE_OR_CR
;
8738 prev_method
= it
->method
;
8739 if (it
->method
== GET_FROM_BUFFER
)
8740 prev_pos
= IT_CHARPOS (*it
);
8741 /* The current display element has been consumed. Advance
8743 set_iterator_to_next (it
, 1);
8744 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8745 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8746 if (IT_CHARPOS (*it
) < to_charpos
)
8747 saw_smaller_pos
= 1;
8749 && (op
& MOVE_TO_POS
)
8750 && IT_CHARPOS (*it
) >= to_charpos
8751 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8752 SAVE_IT (ppos_it
, *it
, ppos_data
);
8754 /* Stop if lines are truncated and IT's current x-position is
8755 past the right edge of the window now. */
8756 if (it
->line_wrap
== TRUNCATE
8757 && it
->current_x
>= it
->last_visible_x
)
8759 if (!FRAME_WINDOW_P (it
->f
)
8760 || ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
8761 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8762 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0
8763 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8767 if ((at_eob_p
= !get_next_display_element (it
))
8768 || BUFFER_POS_REACHED_P ()
8769 /* If we are past TO_CHARPOS, but never saw any
8770 character positions smaller than TO_CHARPOS,
8771 return MOVE_POS_MATCH_OR_ZV, like the
8772 unidirectional display did. */
8773 || (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8775 && IT_CHARPOS (*it
) > to_charpos
))
8778 && !at_eob_p
&& IT_CHARPOS (ppos_it
) < ZV
)
8779 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8780 result
= MOVE_POS_MATCH_OR_ZV
;
8783 if (ITERATOR_AT_END_OF_LINE_P (it
))
8785 result
= MOVE_NEWLINE_OR_CR
;
8789 else if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8791 && IT_CHARPOS (*it
) > to_charpos
)
8793 if (IT_CHARPOS (ppos_it
) < ZV
)
8794 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8795 result
= MOVE_POS_MATCH_OR_ZV
;
8798 result
= MOVE_LINE_TRUNCATED
;
8801 #undef IT_RESET_X_ASCENT_DESCENT
8804 #undef BUFFER_POS_REACHED_P
8806 /* If we scanned beyond to_pos and didn't find a point to wrap at,
8807 restore the saved iterator. */
8808 if (atpos_it
.sp
>= 0)
8809 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8810 else if (atx_it
.sp
>= 0)
8811 RESTORE_IT (it
, &atx_it
, atx_data
);
8816 bidi_unshelve_cache (atpos_data
, 1);
8818 bidi_unshelve_cache (atx_data
, 1);
8820 bidi_unshelve_cache (wrap_data
, 1);
8822 bidi_unshelve_cache (ppos_data
, 1);
8824 /* Restore the iterator settings altered at the beginning of this
8826 it
->glyph_row
= saved_glyph_row
;
8830 /* For external use. */
8832 move_it_in_display_line (struct it
*it
,
8833 ptrdiff_t to_charpos
, int to_x
,
8834 enum move_operation_enum op
)
8836 if (it
->line_wrap
== WORD_WRAP
8837 && (op
& MOVE_TO_X
))
8840 void *save_data
= NULL
;
8843 SAVE_IT (save_it
, *it
, save_data
);
8844 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8845 /* When word-wrap is on, TO_X may lie past the end
8846 of a wrapped line. Then it->current is the
8847 character on the next line, so backtrack to the
8848 space before the wrap point. */
8849 if (skip
== MOVE_LINE_CONTINUED
)
8851 int prev_x
= max (it
->current_x
- 1, 0);
8852 RESTORE_IT (it
, &save_it
, save_data
);
8853 move_it_in_display_line_to
8854 (it
, -1, prev_x
, MOVE_TO_X
);
8857 bidi_unshelve_cache (save_data
, 1);
8860 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8864 /* Move IT forward until it satisfies one or more of the criteria in
8865 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
8867 OP is a bit-mask that specifies where to stop, and in particular,
8868 which of those four position arguments makes a difference. See the
8869 description of enum move_operation_enum.
8871 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
8872 screen line, this function will set IT to the next position that is
8873 displayed to the right of TO_CHARPOS on the screen. */
8876 move_it_to (struct it
*it
, ptrdiff_t to_charpos
, int to_x
, int to_y
, int to_vpos
, int op
)
8878 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
8879 int line_height
, line_start_x
= 0, reached
= 0;
8880 void *backup_data
= NULL
;
8884 if (op
& MOVE_TO_VPOS
)
8886 /* If no TO_CHARPOS and no TO_X specified, stop at the
8887 start of the line TO_VPOS. */
8888 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
8890 if (it
->vpos
== to_vpos
)
8896 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
8900 /* TO_VPOS >= 0 means stop at TO_X in the line at
8901 TO_VPOS, or at TO_POS, whichever comes first. */
8902 if (it
->vpos
== to_vpos
)
8908 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8910 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
8915 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
8917 /* We have reached TO_X but not in the line we want. */
8918 skip
= move_it_in_display_line_to (it
, to_charpos
,
8920 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8928 else if (op
& MOVE_TO_Y
)
8930 struct it it_backup
;
8932 if (it
->line_wrap
== WORD_WRAP
)
8933 SAVE_IT (it_backup
, *it
, backup_data
);
8935 /* TO_Y specified means stop at TO_X in the line containing
8936 TO_Y---or at TO_CHARPOS if this is reached first. The
8937 problem is that we can't really tell whether the line
8938 contains TO_Y before we have completely scanned it, and
8939 this may skip past TO_X. What we do is to first scan to
8942 If TO_X is not specified, use a TO_X of zero. The reason
8943 is to make the outcome of this function more predictable.
8944 If we didn't use TO_X == 0, we would stop at the end of
8945 the line which is probably not what a caller would expect
8947 skip
= move_it_in_display_line_to
8948 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
8949 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
8951 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
8952 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8954 else if (skip
== MOVE_X_REACHED
)
8956 /* If TO_X was reached, we want to know whether TO_Y is
8957 in the line. We know this is the case if the already
8958 scanned glyphs make the line tall enough. Otherwise,
8959 we must check by scanning the rest of the line. */
8960 line_height
= it
->max_ascent
+ it
->max_descent
;
8961 if (to_y
>= it
->current_y
8962 && to_y
< it
->current_y
+ line_height
)
8967 SAVE_IT (it_backup
, *it
, backup_data
);
8968 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
8969 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
8971 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
8972 line_height
= it
->max_ascent
+ it
->max_descent
;
8973 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8975 if (to_y
>= it
->current_y
8976 && to_y
< it
->current_y
+ line_height
)
8978 /* If TO_Y is in this line and TO_X was reached
8979 above, we scanned too far. We have to restore
8980 IT's settings to the ones before skipping. But
8981 keep the more accurate values of max_ascent and
8982 max_descent we've found while skipping the rest
8983 of the line, for the sake of callers, such as
8984 pos_visible_p, that need to know the line
8986 int max_ascent
= it
->max_ascent
;
8987 int max_descent
= it
->max_descent
;
8989 RESTORE_IT (it
, &it_backup
, backup_data
);
8990 it
->max_ascent
= max_ascent
;
8991 it
->max_descent
= max_descent
;
8997 if (skip
== MOVE_POS_MATCH_OR_ZV
)
9003 /* Check whether TO_Y is in this line. */
9004 line_height
= it
->max_ascent
+ it
->max_descent
;
9005 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
9007 if (to_y
>= it
->current_y
9008 && to_y
< it
->current_y
+ line_height
)
9010 /* When word-wrap is on, TO_X may lie past the end
9011 of a wrapped line. Then it->current is the
9012 character on the next line, so backtrack to the
9013 space before the wrap point. */
9014 if (skip
== MOVE_LINE_CONTINUED
9015 && it
->line_wrap
== WORD_WRAP
)
9017 int prev_x
= max (it
->current_x
- 1, 0);
9018 RESTORE_IT (it
, &it_backup
, backup_data
);
9019 skip
= move_it_in_display_line_to
9020 (it
, -1, prev_x
, MOVE_TO_X
);
9029 else if (BUFFERP (it
->object
)
9030 && (it
->method
== GET_FROM_BUFFER
9031 || it
->method
== GET_FROM_STRETCH
)
9032 && IT_CHARPOS (*it
) >= to_charpos
9033 /* Under bidi iteration, a call to set_iterator_to_next
9034 can scan far beyond to_charpos if the initial
9035 portion of the next line needs to be reordered. In
9036 that case, give move_it_in_display_line_to another
9039 && it
->bidi_it
.scan_dir
== -1))
9040 skip
= MOVE_POS_MATCH_OR_ZV
;
9042 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
9046 case MOVE_POS_MATCH_OR_ZV
:
9050 case MOVE_NEWLINE_OR_CR
:
9051 set_iterator_to_next (it
, 1);
9052 it
->continuation_lines_width
= 0;
9055 case MOVE_LINE_TRUNCATED
:
9056 it
->continuation_lines_width
= 0;
9057 reseat_at_next_visible_line_start (it
, 0);
9058 if ((op
& MOVE_TO_POS
) != 0
9059 && IT_CHARPOS (*it
) > to_charpos
)
9066 case MOVE_LINE_CONTINUED
:
9067 /* For continued lines ending in a tab, some of the glyphs
9068 associated with the tab are displayed on the current
9069 line. Since it->current_x does not include these glyphs,
9070 we use it->last_visible_x instead. */
9073 it
->continuation_lines_width
+= it
->last_visible_x
;
9074 /* When moving by vpos, ensure that the iterator really
9075 advances to the next line (bug#847, bug#969). Fixme:
9076 do we need to do this in other circumstances? */
9077 if (it
->current_x
!= it
->last_visible_x
9078 && (op
& MOVE_TO_VPOS
)
9079 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
9081 line_start_x
= it
->current_x
+ it
->pixel_width
9082 - it
->last_visible_x
;
9083 set_iterator_to_next (it
, 0);
9087 it
->continuation_lines_width
+= it
->current_x
;
9094 /* Reset/increment for the next run. */
9095 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
9096 it
->current_x
= line_start_x
;
9099 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
9101 last_height
= it
->max_ascent
+ it
->max_descent
;
9102 it
->max_ascent
= it
->max_descent
= 0;
9107 /* On text terminals, we may stop at the end of a line in the middle
9108 of a multi-character glyph. If the glyph itself is continued,
9109 i.e. it is actually displayed on the next line, don't treat this
9110 stopping point as valid; move to the next line instead (unless
9111 that brings us offscreen). */
9112 if (!FRAME_WINDOW_P (it
->f
)
9114 && IT_CHARPOS (*it
) == to_charpos
9115 && it
->what
== IT_CHARACTER
9117 && it
->line_wrap
== WINDOW_WRAP
9118 && it
->current_x
== it
->last_visible_x
- 1
9121 && it
->vpos
< it
->w
->window_end_vpos
)
9123 it
->continuation_lines_width
+= it
->current_x
;
9124 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
9125 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
9127 last_height
= it
->max_ascent
+ it
->max_descent
;
9131 bidi_unshelve_cache (backup_data
, 1);
9133 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
9137 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
9139 If DY > 0, move IT backward at least that many pixels. DY = 0
9140 means move IT backward to the preceding line start or BEGV. This
9141 function may move over more than DY pixels if IT->current_y - DY
9142 ends up in the middle of a line; in this case IT->current_y will be
9143 set to the top of the line moved to. */
9146 move_it_vertically_backward (struct it
*it
, int dy
)
9150 void *it2data
= NULL
, *it3data
= NULL
;
9151 ptrdiff_t start_pos
;
9153 = (it
->last_visible_x
- it
->first_visible_x
) / FRAME_COLUMN_WIDTH (it
->f
);
9154 ptrdiff_t pos_limit
;
9159 start_pos
= IT_CHARPOS (*it
);
9161 /* Estimate how many newlines we must move back. */
9162 nlines
= max (1, dy
/ default_line_pixel_height (it
->w
));
9163 if (it
->line_wrap
== TRUNCATE
)
9166 pos_limit
= max (start_pos
- nlines
* nchars_per_row
, BEGV
);
9168 /* Set the iterator's position that many lines back. But don't go
9169 back more than NLINES full screen lines -- this wins a day with
9170 buffers which have very long lines. */
9171 while (nlines
-- && IT_CHARPOS (*it
) > pos_limit
)
9172 back_to_previous_visible_line_start (it
);
9174 /* Reseat the iterator here. When moving backward, we don't want
9175 reseat to skip forward over invisible text, set up the iterator
9176 to deliver from overlay strings at the new position etc. So,
9177 use reseat_1 here. */
9178 reseat_1 (it
, it
->current
.pos
, 1);
9180 /* We are now surely at a line start. */
9181 it
->current_x
= it
->hpos
= 0; /* FIXME: this is incorrect when bidi
9182 reordering is in effect. */
9183 it
->continuation_lines_width
= 0;
9185 /* Move forward and see what y-distance we moved. First move to the
9186 start of the next line so that we get its height. We need this
9187 height to be able to tell whether we reached the specified
9189 SAVE_IT (it2
, *it
, it2data
);
9190 it2
.max_ascent
= it2
.max_descent
= 0;
9193 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
9194 MOVE_TO_POS
| MOVE_TO_VPOS
);
9196 while (!(IT_POS_VALID_AFTER_MOVE_P (&it2
)
9197 /* If we are in a display string which starts at START_POS,
9198 and that display string includes a newline, and we are
9199 right after that newline (i.e. at the beginning of a
9200 display line), exit the loop, because otherwise we will
9201 infloop, since move_it_to will see that it is already at
9202 START_POS and will not move. */
9203 || (it2
.method
== GET_FROM_STRING
9204 && IT_CHARPOS (it2
) == start_pos
9205 && SREF (it2
.string
, IT_STRING_BYTEPOS (it2
) - 1) == '\n')));
9206 eassert (IT_CHARPOS (*it
) >= BEGV
);
9207 SAVE_IT (it3
, it2
, it3data
);
9209 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
9210 eassert (IT_CHARPOS (*it
) >= BEGV
);
9211 /* H is the actual vertical distance from the position in *IT
9212 and the starting position. */
9213 h
= it2
.current_y
- it
->current_y
;
9214 /* NLINES is the distance in number of lines. */
9215 nlines
= it2
.vpos
- it
->vpos
;
9217 /* Correct IT's y and vpos position
9218 so that they are relative to the starting point. */
9224 /* DY == 0 means move to the start of the screen line. The
9225 value of nlines is > 0 if continuation lines were involved,
9226 or if the original IT position was at start of a line. */
9227 RESTORE_IT (it
, it
, it2data
);
9229 move_it_by_lines (it
, nlines
);
9230 /* The above code moves us to some position NLINES down,
9231 usually to its first glyph (leftmost in an L2R line), but
9232 that's not necessarily the start of the line, under bidi
9233 reordering. We want to get to the character position
9234 that is immediately after the newline of the previous
9237 && !it
->continuation_lines_width
9238 && !STRINGP (it
->string
)
9239 && IT_CHARPOS (*it
) > BEGV
9240 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9242 ptrdiff_t cp
= IT_CHARPOS (*it
), bp
= IT_BYTEPOS (*it
);
9245 cp
= find_newline_no_quit (cp
, bp
, -1, NULL
);
9246 move_it_to (it
, cp
, -1, -1, -1, MOVE_TO_POS
);
9248 bidi_unshelve_cache (it3data
, 1);
9252 /* The y-position we try to reach, relative to *IT.
9253 Note that H has been subtracted in front of the if-statement. */
9254 int target_y
= it
->current_y
+ h
- dy
;
9255 int y0
= it3
.current_y
;
9259 RESTORE_IT (&it3
, &it3
, it3data
);
9260 y1
= line_bottom_y (&it3
);
9261 line_height
= y1
- y0
;
9262 RESTORE_IT (it
, it
, it2data
);
9263 /* If we did not reach target_y, try to move further backward if
9264 we can. If we moved too far backward, try to move forward. */
9265 if (target_y
< it
->current_y
9266 /* This is heuristic. In a window that's 3 lines high, with
9267 a line height of 13 pixels each, recentering with point
9268 on the bottom line will try to move -39/2 = 19 pixels
9269 backward. Try to avoid moving into the first line. */
9270 && (it
->current_y
- target_y
9271 > min (window_box_height (it
->w
), line_height
* 2 / 3))
9272 && IT_CHARPOS (*it
) > BEGV
)
9274 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
9275 target_y
- it
->current_y
));
9276 dy
= it
->current_y
- target_y
;
9277 goto move_further_back
;
9279 else if (target_y
>= it
->current_y
+ line_height
9280 && IT_CHARPOS (*it
) < ZV
)
9282 /* Should move forward by at least one line, maybe more.
9284 Note: Calling move_it_by_lines can be expensive on
9285 terminal frames, where compute_motion is used (via
9286 vmotion) to do the job, when there are very long lines
9287 and truncate-lines is nil. That's the reason for
9288 treating terminal frames specially here. */
9290 if (!FRAME_WINDOW_P (it
->f
))
9291 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
9296 move_it_by_lines (it
, 1);
9298 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
9305 /* Move IT by a specified amount of pixel lines DY. DY negative means
9306 move backwards. DY = 0 means move to start of screen line. At the
9307 end, IT will be on the start of a screen line. */
9310 move_it_vertically (struct it
*it
, int dy
)
9313 move_it_vertically_backward (it
, -dy
);
9316 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
9317 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
9318 MOVE_TO_POS
| MOVE_TO_Y
);
9319 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
9321 /* If buffer ends in ZV without a newline, move to the start of
9322 the line to satisfy the post-condition. */
9323 if (IT_CHARPOS (*it
) == ZV
9325 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9326 move_it_by_lines (it
, 0);
9331 /* Move iterator IT past the end of the text line it is in. */
9334 move_it_past_eol (struct it
*it
)
9336 enum move_it_result rc
;
9338 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
9339 if (rc
== MOVE_NEWLINE_OR_CR
)
9340 set_iterator_to_next (it
, 0);
9344 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
9345 negative means move up. DVPOS == 0 means move to the start of the
9348 Optimization idea: If we would know that IT->f doesn't use
9349 a face with proportional font, we could be faster for
9350 truncate-lines nil. */
9353 move_it_by_lines (struct it
*it
, ptrdiff_t dvpos
)
9356 /* The commented-out optimization uses vmotion on terminals. This
9357 gives bad results, because elements like it->what, on which
9358 callers such as pos_visible_p rely, aren't updated. */
9359 /* struct position pos;
9360 if (!FRAME_WINDOW_P (it->f))
9362 struct text_pos textpos;
9364 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
9365 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
9366 reseat (it, textpos, 1);
9367 it->vpos += pos.vpos;
9368 it->current_y += pos.vpos;
9374 /* DVPOS == 0 means move to the start of the screen line. */
9375 move_it_vertically_backward (it
, 0);
9376 /* Let next call to line_bottom_y calculate real line height */
9381 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
9382 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
9384 /* Only move to the next buffer position if we ended up in a
9385 string from display property, not in an overlay string
9386 (before-string or after-string). That is because the
9387 latter don't conceal the underlying buffer position, so
9388 we can ask to move the iterator to the exact position we
9389 are interested in. Note that, even if we are already at
9390 IT_CHARPOS (*it), the call below is not a no-op, as it
9391 will detect that we are at the end of the string, pop the
9392 iterator, and compute it->current_x and it->hpos
9394 move_it_to (it
, IT_CHARPOS (*it
) + it
->string_from_display_prop_p
,
9395 -1, -1, -1, MOVE_TO_POS
);
9401 void *it2data
= NULL
;
9402 ptrdiff_t start_charpos
, i
;
9404 = (it
->last_visible_x
- it
->first_visible_x
) / FRAME_COLUMN_WIDTH (it
->f
);
9405 ptrdiff_t pos_limit
;
9407 /* Start at the beginning of the screen line containing IT's
9408 position. This may actually move vertically backwards,
9409 in case of overlays, so adjust dvpos accordingly. */
9411 move_it_vertically_backward (it
, 0);
9414 /* Go back -DVPOS buffer lines, but no farther than -DVPOS full
9415 screen lines, and reseat the iterator there. */
9416 start_charpos
= IT_CHARPOS (*it
);
9417 if (it
->line_wrap
== TRUNCATE
)
9420 pos_limit
= max (start_charpos
+ dvpos
* nchars_per_row
, BEGV
);
9421 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > pos_limit
; --i
)
9422 back_to_previous_visible_line_start (it
);
9423 reseat (it
, it
->current
.pos
, 1);
9425 /* Move further back if we end up in a string or an image. */
9426 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
9428 /* First try to move to start of display line. */
9430 move_it_vertically_backward (it
, 0);
9432 if (IT_POS_VALID_AFTER_MOVE_P (it
))
9434 /* If start of line is still in string or image,
9435 move further back. */
9436 back_to_previous_visible_line_start (it
);
9437 reseat (it
, it
->current
.pos
, 1);
9441 it
->current_x
= it
->hpos
= 0;
9443 /* Above call may have moved too far if continuation lines
9444 are involved. Scan forward and see if it did. */
9445 SAVE_IT (it2
, *it
, it2data
);
9446 it2
.vpos
= it2
.current_y
= 0;
9447 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
9448 it
->vpos
-= it2
.vpos
;
9449 it
->current_y
-= it2
.current_y
;
9450 it
->current_x
= it
->hpos
= 0;
9452 /* If we moved too far back, move IT some lines forward. */
9453 if (it2
.vpos
> -dvpos
)
9455 int delta
= it2
.vpos
+ dvpos
;
9457 RESTORE_IT (&it2
, &it2
, it2data
);
9458 SAVE_IT (it2
, *it
, it2data
);
9459 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
9460 /* Move back again if we got too far ahead. */
9461 if (IT_CHARPOS (*it
) >= start_charpos
)
9462 RESTORE_IT (it
, &it2
, it2data
);
9464 bidi_unshelve_cache (it2data
, 1);
9467 RESTORE_IT (it
, it
, it2data
);
9471 /* Return 1 if IT points into the middle of a display vector. */
9474 in_display_vector_p (struct it
*it
)
9476 return (it
->method
== GET_FROM_DISPLAY_VECTOR
9477 && it
->current
.dpvec_index
> 0
9478 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
9482 /***********************************************************************
9484 ***********************************************************************/
9487 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
9491 add_to_log (const char *format
, Lisp_Object arg1
, Lisp_Object arg2
)
9493 Lisp_Object args
[3];
9494 Lisp_Object msg
, fmt
;
9497 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
9501 GCPRO4 (fmt
, msg
, arg1
, arg2
);
9503 args
[0] = fmt
= build_string (format
);
9506 msg
= Fformat (3, args
);
9508 len
= SBYTES (msg
) + 1;
9509 buffer
= SAFE_ALLOCA (len
);
9510 memcpy (buffer
, SDATA (msg
), len
);
9512 message_dolog (buffer
, len
- 1, 1, 0);
9519 /* Output a newline in the *Messages* buffer if "needs" one. */
9522 message_log_maybe_newline (void)
9524 if (message_log_need_newline
)
9525 message_dolog ("", 0, 1, 0);
9529 /* Add a string M of length NBYTES to the message log, optionally
9530 terminated with a newline when NLFLAG is true. MULTIBYTE, if
9531 true, means interpret the contents of M as multibyte. This
9532 function calls low-level routines in order to bypass text property
9533 hooks, etc. which might not be safe to run.
9535 This may GC (insert may run before/after change hooks),
9536 so the buffer M must NOT point to a Lisp string. */
9539 message_dolog (const char *m
, ptrdiff_t nbytes
, bool nlflag
, bool multibyte
)
9541 const unsigned char *msg
= (const unsigned char *) m
;
9543 if (!NILP (Vmemory_full
))
9546 if (!NILP (Vmessage_log_max
))
9548 struct buffer
*oldbuf
;
9549 Lisp_Object oldpoint
, oldbegv
, oldzv
;
9550 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
9551 ptrdiff_t point_at_end
= 0;
9552 ptrdiff_t zv_at_end
= 0;
9553 Lisp_Object old_deactivate_mark
;
9555 struct gcpro gcpro1
;
9557 old_deactivate_mark
= Vdeactivate_mark
;
9558 oldbuf
= current_buffer
;
9559 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
9560 bset_undo_list (current_buffer
, Qt
);
9562 oldpoint
= message_dolog_marker1
;
9563 set_marker_restricted_both (oldpoint
, Qnil
, PT
, PT_BYTE
);
9564 oldbegv
= message_dolog_marker2
;
9565 set_marker_restricted_both (oldbegv
, Qnil
, BEGV
, BEGV_BYTE
);
9566 oldzv
= message_dolog_marker3
;
9567 set_marker_restricted_both (oldzv
, Qnil
, ZV
, ZV_BYTE
);
9568 GCPRO1 (old_deactivate_mark
);
9576 BEGV_BYTE
= BEG_BYTE
;
9579 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9581 /* Insert the string--maybe converting multibyte to single byte
9582 or vice versa, so that all the text fits the buffer. */
9584 && NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9590 /* Convert a multibyte string to single-byte
9591 for the *Message* buffer. */
9592 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
9594 c
= string_char_and_length (msg
+ i
, &char_bytes
);
9595 work
[0] = (ASCII_CHAR_P (c
)
9597 : multibyte_char_to_unibyte (c
));
9598 insert_1_both (work
, 1, 1, 1, 0, 0);
9601 else if (! multibyte
9602 && ! NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9606 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9607 /* Convert a single-byte string to multibyte
9608 for the *Message* buffer. */
9609 for (i
= 0; i
< nbytes
; i
++)
9612 MAKE_CHAR_MULTIBYTE (c
);
9613 char_bytes
= CHAR_STRING (c
, str
);
9614 insert_1_both ((char *) str
, 1, char_bytes
, 1, 0, 0);
9618 insert_1_both (m
, chars_in_text (msg
, nbytes
), nbytes
, 1, 0, 0);
9622 ptrdiff_t this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
;
9625 insert_1_both ("\n", 1, 1, 1, 0, 0);
9627 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9629 this_bol_byte
= PT_BYTE
;
9631 /* See if this line duplicates the previous one.
9632 If so, combine duplicates. */
9635 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9637 prev_bol_byte
= PT_BYTE
;
9639 dups
= message_log_check_duplicate (prev_bol_byte
,
9643 del_range_both (prev_bol
, prev_bol_byte
,
9644 this_bol
, this_bol_byte
, 0);
9647 char dupstr
[sizeof " [ times]"
9648 + INT_STRLEN_BOUND (printmax_t
)];
9650 /* If you change this format, don't forget to also
9651 change message_log_check_duplicate. */
9652 int duplen
= sprintf (dupstr
, " [%"pMd
" times]", dups
);
9653 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
9654 insert_1_both (dupstr
, duplen
, duplen
, 1, 0, 1);
9659 /* If we have more than the desired maximum number of lines
9660 in the *Messages* buffer now, delete the oldest ones.
9661 This is safe because we don't have undo in this buffer. */
9663 if (NATNUMP (Vmessage_log_max
))
9665 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
9666 -XFASTINT (Vmessage_log_max
) - 1, 0);
9667 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
9670 BEGV
= marker_position (oldbegv
);
9671 BEGV_BYTE
= marker_byte_position (oldbegv
);
9680 ZV
= marker_position (oldzv
);
9681 ZV_BYTE
= marker_byte_position (oldzv
);
9685 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9687 /* We can't do Fgoto_char (oldpoint) because it will run some
9689 TEMP_SET_PT_BOTH (marker_position (oldpoint
),
9690 marker_byte_position (oldpoint
));
9693 unchain_marker (XMARKER (oldpoint
));
9694 unchain_marker (XMARKER (oldbegv
));
9695 unchain_marker (XMARKER (oldzv
));
9697 shown
= buffer_window_count (current_buffer
) > 0;
9698 set_buffer_internal (oldbuf
);
9699 /* We called insert_1_both above with its 5th argument (PREPARE)
9700 zero, which prevents insert_1_both from calling
9701 prepare_to_modify_buffer, which in turns prevents us from
9702 incrementing windows_or_buffers_changed even if *Messages* is
9703 shown in some window. So we must manually incrementing
9704 windows_or_buffers_changed here to make up for that. */
9706 windows_or_buffers_changed
++;
9708 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
9709 message_log_need_newline
= !nlflag
;
9710 Vdeactivate_mark
= old_deactivate_mark
;
9715 /* We are at the end of the buffer after just having inserted a newline.
9716 (Note: We depend on the fact we won't be crossing the gap.)
9717 Check to see if the most recent message looks a lot like the previous one.
9718 Return 0 if different, 1 if the new one should just replace it, or a
9719 value N > 1 if we should also append " [N times]". */
9722 message_log_check_duplicate (ptrdiff_t prev_bol_byte
, ptrdiff_t this_bol_byte
)
9725 ptrdiff_t len
= Z_BYTE
- 1 - this_bol_byte
;
9727 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
9728 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
9730 for (i
= 0; i
< len
; i
++)
9732 if (i
>= 3 && p1
[i
- 3] == '.' && p1
[i
- 2] == '.' && p1
[i
- 1] == '.')
9740 if (*p1
++ == ' ' && *p1
++ == '[')
9743 intmax_t n
= strtoimax ((char *) p1
, &pend
, 10);
9744 if (0 < n
&& n
< INTMAX_MAX
&& strncmp (pend
, " times]\n", 8) == 0)
9751 /* Display an echo area message M with a specified length of NBYTES
9752 bytes. The string may include null characters. If M is not a
9753 string, clear out any existing message, and let the mini-buffer
9756 This function cancels echoing. */
9759 message3 (Lisp_Object m
)
9761 struct gcpro gcpro1
;
9764 clear_message (1,1);
9767 /* First flush out any partial line written with print. */
9768 message_log_maybe_newline ();
9771 ptrdiff_t nbytes
= SBYTES (m
);
9772 bool multibyte
= STRING_MULTIBYTE (m
);
9774 char *buffer
= SAFE_ALLOCA (nbytes
);
9775 memcpy (buffer
, SDATA (m
), nbytes
);
9776 message_dolog (buffer
, nbytes
, 1, multibyte
);
9785 /* The non-logging version of message3.
9786 This does not cancel echoing, because it is used for echoing.
9787 Perhaps we need to make a separate function for echoing
9788 and make this cancel echoing. */
9791 message3_nolog (Lisp_Object m
)
9793 struct frame
*sf
= SELECTED_FRAME ();
9795 if (FRAME_INITIAL_P (sf
))
9797 if (noninteractive_need_newline
)
9798 putc ('\n', stderr
);
9799 noninteractive_need_newline
= 0;
9801 fwrite (SDATA (m
), SBYTES (m
), 1, stderr
);
9802 if (cursor_in_echo_area
== 0)
9803 fprintf (stderr
, "\n");
9806 /* Error messages get reported properly by cmd_error, so this must be just an
9807 informative message; if the frame hasn't really been initialized yet, just
9809 else if (INTERACTIVE
&& sf
->glyphs_initialized_p
)
9811 /* Get the frame containing the mini-buffer
9812 that the selected frame is using. */
9813 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9814 Lisp_Object frame
= XWINDOW (mini_window
)->frame
;
9815 struct frame
*f
= XFRAME (frame
);
9817 if (FRAME_VISIBLE_P (sf
) && !FRAME_VISIBLE_P (f
))
9818 Fmake_frame_visible (frame
);
9820 if (STRINGP (m
) && SCHARS (m
) > 0)
9823 if (minibuffer_auto_raise
)
9824 Fraise_frame (frame
);
9825 /* Assume we are not echoing.
9826 (If we are, echo_now will override this.) */
9827 echo_message_buffer
= Qnil
;
9830 clear_message (1, 1);
9832 do_pending_window_change (0);
9833 echo_area_display (1);
9834 do_pending_window_change (0);
9835 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
9836 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
9841 /* Display a null-terminated echo area message M. If M is 0, clear
9842 out any existing message, and let the mini-buffer text show through.
9844 The buffer M must continue to exist until after the echo area gets
9845 cleared or some other message gets displayed there. Do not pass
9846 text that is stored in a Lisp string. Do not pass text in a buffer
9847 that was alloca'd. */
9850 message1 (const char *m
)
9852 message3 (m
? build_unibyte_string (m
) : Qnil
);
9856 /* The non-logging counterpart of message1. */
9859 message1_nolog (const char *m
)
9861 message3_nolog (m
? build_unibyte_string (m
) : Qnil
);
9864 /* Display a message M which contains a single %s
9865 which gets replaced with STRING. */
9868 message_with_string (const char *m
, Lisp_Object string
, int log
)
9870 CHECK_STRING (string
);
9876 if (noninteractive_need_newline
)
9877 putc ('\n', stderr
);
9878 noninteractive_need_newline
= 0;
9879 fprintf (stderr
, m
, SDATA (string
));
9880 if (!cursor_in_echo_area
)
9881 fprintf (stderr
, "\n");
9885 else if (INTERACTIVE
)
9887 /* The frame whose minibuffer we're going to display the message on.
9888 It may be larger than the selected frame, so we need
9889 to use its buffer, not the selected frame's buffer. */
9890 Lisp_Object mini_window
;
9891 struct frame
*f
, *sf
= SELECTED_FRAME ();
9893 /* Get the frame containing the minibuffer
9894 that the selected frame is using. */
9895 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9896 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9898 /* Error messages get reported properly by cmd_error, so this must be
9899 just an informative message; if the frame hasn't really been
9900 initialized yet, just toss it. */
9901 if (f
->glyphs_initialized_p
)
9903 Lisp_Object args
[2], msg
;
9904 struct gcpro gcpro1
, gcpro2
;
9906 args
[0] = build_string (m
);
9907 args
[1] = msg
= string
;
9908 GCPRO2 (args
[0], msg
);
9911 msg
= Fformat (2, args
);
9916 message3_nolog (msg
);
9920 /* Print should start at the beginning of the message
9921 buffer next time. */
9922 message_buf_print
= 0;
9928 /* Dump an informative message to the minibuf. If M is 0, clear out
9929 any existing message, and let the mini-buffer text show through. */
9932 vmessage (const char *m
, va_list ap
)
9938 if (noninteractive_need_newline
)
9939 putc ('\n', stderr
);
9940 noninteractive_need_newline
= 0;
9941 vfprintf (stderr
, m
, ap
);
9942 if (cursor_in_echo_area
== 0)
9943 fprintf (stderr
, "\n");
9947 else if (INTERACTIVE
)
9949 /* The frame whose mini-buffer we're going to display the message
9950 on. It may be larger than the selected frame, so we need to
9951 use its buffer, not the selected frame's buffer. */
9952 Lisp_Object mini_window
;
9953 struct frame
*f
, *sf
= SELECTED_FRAME ();
9955 /* Get the frame containing the mini-buffer
9956 that the selected frame is using. */
9957 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9958 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9960 /* Error messages get reported properly by cmd_error, so this must be
9961 just an informative message; if the frame hasn't really been
9962 initialized yet, just toss it. */
9963 if (f
->glyphs_initialized_p
)
9968 ptrdiff_t maxsize
= FRAME_MESSAGE_BUF_SIZE (f
);
9969 char *message_buf
= alloca (maxsize
+ 1);
9971 len
= doprnt (message_buf
, maxsize
, m
, 0, ap
);
9973 message3 (make_string (message_buf
, len
));
9978 /* Print should start at the beginning of the message
9979 buffer next time. */
9980 message_buf_print
= 0;
9986 message (const char *m
, ...)
9996 /* The non-logging version of message. */
9999 message_nolog (const char *m
, ...)
10001 Lisp_Object old_log_max
;
10004 old_log_max
= Vmessage_log_max
;
10005 Vmessage_log_max
= Qnil
;
10007 Vmessage_log_max
= old_log_max
;
10013 /* Display the current message in the current mini-buffer. This is
10014 only called from error handlers in process.c, and is not time
10018 update_echo_area (void)
10020 if (!NILP (echo_area_buffer
[0]))
10022 Lisp_Object string
;
10023 string
= Fcurrent_message ();
10029 /* Make sure echo area buffers in `echo_buffers' are live.
10030 If they aren't, make new ones. */
10033 ensure_echo_area_buffers (void)
10037 for (i
= 0; i
< 2; ++i
)
10038 if (!BUFFERP (echo_buffer
[i
])
10039 || !BUFFER_LIVE_P (XBUFFER (echo_buffer
[i
])))
10042 Lisp_Object old_buffer
;
10045 old_buffer
= echo_buffer
[i
];
10046 echo_buffer
[i
] = Fget_buffer_create
10047 (make_formatted_string (name
, " *Echo Area %d*", i
));
10048 bset_truncate_lines (XBUFFER (echo_buffer
[i
]), Qnil
);
10049 /* to force word wrap in echo area -
10050 it was decided to postpone this*/
10051 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
10053 for (j
= 0; j
< 2; ++j
)
10054 if (EQ (old_buffer
, echo_area_buffer
[j
]))
10055 echo_area_buffer
[j
] = echo_buffer
[i
];
10060 /* Call FN with args A1..A2 with either the current or last displayed
10061 echo_area_buffer as current buffer.
10063 WHICH zero means use the current message buffer
10064 echo_area_buffer[0]. If that is nil, choose a suitable buffer
10065 from echo_buffer[] and clear it.
10067 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
10068 suitable buffer from echo_buffer[] and clear it.
10070 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
10071 that the current message becomes the last displayed one, make
10072 choose a suitable buffer for echo_area_buffer[0], and clear it.
10074 Value is what FN returns. */
10077 with_echo_area_buffer (struct window
*w
, int which
,
10078 int (*fn
) (ptrdiff_t, Lisp_Object
),
10079 ptrdiff_t a1
, Lisp_Object a2
)
10081 Lisp_Object buffer
;
10082 int this_one
, the_other
, clear_buffer_p
, rc
;
10083 ptrdiff_t count
= SPECPDL_INDEX ();
10085 /* If buffers aren't live, make new ones. */
10086 ensure_echo_area_buffers ();
10088 clear_buffer_p
= 0;
10091 this_one
= 0, the_other
= 1;
10092 else if (which
> 0)
10093 this_one
= 1, the_other
= 0;
10096 this_one
= 0, the_other
= 1;
10097 clear_buffer_p
= 1;
10099 /* We need a fresh one in case the current echo buffer equals
10100 the one containing the last displayed echo area message. */
10101 if (!NILP (echo_area_buffer
[this_one
])
10102 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
10103 echo_area_buffer
[this_one
] = Qnil
;
10106 /* Choose a suitable buffer from echo_buffer[] is we don't
10108 if (NILP (echo_area_buffer
[this_one
]))
10110 echo_area_buffer
[this_one
]
10111 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
10112 ? echo_buffer
[the_other
]
10113 : echo_buffer
[this_one
]);
10114 clear_buffer_p
= 1;
10117 buffer
= echo_area_buffer
[this_one
];
10119 /* Don't get confused by reusing the buffer used for echoing
10120 for a different purpose. */
10121 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
10124 record_unwind_protect (unwind_with_echo_area_buffer
,
10125 with_echo_area_buffer_unwind_data (w
));
10127 /* Make the echo area buffer current. Note that for display
10128 purposes, it is not necessary that the displayed window's buffer
10129 == current_buffer, except for text property lookup. So, let's
10130 only set that buffer temporarily here without doing a full
10131 Fset_window_buffer. We must also change w->pointm, though,
10132 because otherwise an assertions in unshow_buffer fails, and Emacs
10134 set_buffer_internal_1 (XBUFFER (buffer
));
10137 wset_buffer (w
, buffer
);
10138 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
10141 bset_undo_list (current_buffer
, Qt
);
10142 bset_read_only (current_buffer
, Qnil
);
10143 specbind (Qinhibit_read_only
, Qt
);
10144 specbind (Qinhibit_modification_hooks
, Qt
);
10146 if (clear_buffer_p
&& Z
> BEG
)
10147 del_range (BEG
, Z
);
10149 eassert (BEGV
>= BEG
);
10150 eassert (ZV
<= Z
&& ZV
>= BEGV
);
10154 eassert (BEGV
>= BEG
);
10155 eassert (ZV
<= Z
&& ZV
>= BEGV
);
10157 unbind_to (count
, Qnil
);
10162 /* Save state that should be preserved around the call to the function
10163 FN called in with_echo_area_buffer. */
10166 with_echo_area_buffer_unwind_data (struct window
*w
)
10169 Lisp_Object vector
, tmp
;
10171 /* Reduce consing by keeping one vector in
10172 Vwith_echo_area_save_vector. */
10173 vector
= Vwith_echo_area_save_vector
;
10174 Vwith_echo_area_save_vector
= Qnil
;
10177 vector
= Fmake_vector (make_number (9), Qnil
);
10179 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
10180 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
10181 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
10185 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
10186 ASET (vector
, i
, w
->contents
); ++i
;
10187 ASET (vector
, i
, make_number (marker_position (w
->pointm
))); ++i
;
10188 ASET (vector
, i
, make_number (marker_byte_position (w
->pointm
))); ++i
;
10189 ASET (vector
, i
, make_number (marker_position (w
->start
))); ++i
;
10190 ASET (vector
, i
, make_number (marker_byte_position (w
->start
))); ++i
;
10195 for (; i
< end
; ++i
)
10196 ASET (vector
, i
, Qnil
);
10199 eassert (i
== ASIZE (vector
));
10204 /* Restore global state from VECTOR which was created by
10205 with_echo_area_buffer_unwind_data. */
10208 unwind_with_echo_area_buffer (Lisp_Object vector
)
10210 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
10211 Vdeactivate_mark
= AREF (vector
, 1);
10212 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
10214 if (WINDOWP (AREF (vector
, 3)))
10217 Lisp_Object buffer
;
10219 w
= XWINDOW (AREF (vector
, 3));
10220 buffer
= AREF (vector
, 4);
10222 wset_buffer (w
, buffer
);
10223 set_marker_both (w
->pointm
, buffer
,
10224 XFASTINT (AREF (vector
, 5)),
10225 XFASTINT (AREF (vector
, 6)));
10226 set_marker_both (w
->start
, buffer
,
10227 XFASTINT (AREF (vector
, 7)),
10228 XFASTINT (AREF (vector
, 8)));
10231 Vwith_echo_area_save_vector
= vector
;
10235 /* Set up the echo area for use by print functions. MULTIBYTE_P
10236 non-zero means we will print multibyte. */
10239 setup_echo_area_for_printing (int multibyte_p
)
10241 /* If we can't find an echo area any more, exit. */
10242 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
10243 Fkill_emacs (Qnil
);
10245 ensure_echo_area_buffers ();
10247 if (!message_buf_print
)
10249 /* A message has been output since the last time we printed.
10250 Choose a fresh echo area buffer. */
10251 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10252 echo_area_buffer
[0] = echo_buffer
[1];
10254 echo_area_buffer
[0] = echo_buffer
[0];
10256 /* Switch to that buffer and clear it. */
10257 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10258 bset_truncate_lines (current_buffer
, Qnil
);
10262 ptrdiff_t count
= SPECPDL_INDEX ();
10263 specbind (Qinhibit_read_only
, Qt
);
10264 /* Note that undo recording is always disabled. */
10265 del_range (BEG
, Z
);
10266 unbind_to (count
, Qnil
);
10268 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10270 /* Set up the buffer for the multibyteness we need. */
10272 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10273 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
10275 /* Raise the frame containing the echo area. */
10276 if (minibuffer_auto_raise
)
10278 struct frame
*sf
= SELECTED_FRAME ();
10279 Lisp_Object mini_window
;
10280 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10281 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
10284 message_log_maybe_newline ();
10285 message_buf_print
= 1;
10289 if (NILP (echo_area_buffer
[0]))
10291 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10292 echo_area_buffer
[0] = echo_buffer
[1];
10294 echo_area_buffer
[0] = echo_buffer
[0];
10297 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
10299 /* Someone switched buffers between print requests. */
10300 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10301 bset_truncate_lines (current_buffer
, Qnil
);
10307 /* Display an echo area message in window W. Value is non-zero if W's
10308 height is changed. If display_last_displayed_message_p is
10309 non-zero, display the message that was last displayed, otherwise
10310 display the current message. */
10313 display_echo_area (struct window
*w
)
10315 int i
, no_message_p
, window_height_changed_p
;
10317 /* Temporarily disable garbage collections while displaying the echo
10318 area. This is done because a GC can print a message itself.
10319 That message would modify the echo area buffer's contents while a
10320 redisplay of the buffer is going on, and seriously confuse
10322 ptrdiff_t count
= inhibit_garbage_collection ();
10324 /* If there is no message, we must call display_echo_area_1
10325 nevertheless because it resizes the window. But we will have to
10326 reset the echo_area_buffer in question to nil at the end because
10327 with_echo_area_buffer will sets it to an empty buffer. */
10328 i
= display_last_displayed_message_p
? 1 : 0;
10329 no_message_p
= NILP (echo_area_buffer
[i
]);
10331 window_height_changed_p
10332 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
10333 display_echo_area_1
,
10334 (intptr_t) w
, Qnil
);
10337 echo_area_buffer
[i
] = Qnil
;
10339 unbind_to (count
, Qnil
);
10340 return window_height_changed_p
;
10344 /* Helper for display_echo_area. Display the current buffer which
10345 contains the current echo area message in window W, a mini-window,
10346 a pointer to which is passed in A1. A2..A4 are currently not used.
10347 Change the height of W so that all of the message is displayed.
10348 Value is non-zero if height of W was changed. */
10351 display_echo_area_1 (ptrdiff_t a1
, Lisp_Object a2
)
10354 struct window
*w
= (struct window
*) i1
;
10355 Lisp_Object window
;
10356 struct text_pos start
;
10357 int window_height_changed_p
= 0;
10359 /* Do this before displaying, so that we have a large enough glyph
10360 matrix for the display. If we can't get enough space for the
10361 whole text, display the last N lines. That works by setting w->start. */
10362 window_height_changed_p
= resize_mini_window (w
, 0);
10364 /* Use the starting position chosen by resize_mini_window. */
10365 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
10368 clear_glyph_matrix (w
->desired_matrix
);
10369 XSETWINDOW (window
, w
);
10370 try_window (window
, start
, 0);
10372 return window_height_changed_p
;
10376 /* Resize the echo area window to exactly the size needed for the
10377 currently displayed message, if there is one. If a mini-buffer
10378 is active, don't shrink it. */
10381 resize_echo_area_exactly (void)
10383 if (BUFFERP (echo_area_buffer
[0])
10384 && WINDOWP (echo_area_window
))
10386 struct window
*w
= XWINDOW (echo_area_window
);
10388 Lisp_Object resize_exactly
;
10390 if (minibuf_level
== 0)
10391 resize_exactly
= Qt
;
10393 resize_exactly
= Qnil
;
10395 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
10396 (intptr_t) w
, resize_exactly
);
10399 ++windows_or_buffers_changed
;
10400 ++update_mode_lines
;
10401 redisplay_internal ();
10407 /* Callback function for with_echo_area_buffer, when used from
10408 resize_echo_area_exactly. A1 contains a pointer to the window to
10409 resize, EXACTLY non-nil means resize the mini-window exactly to the
10410 size of the text displayed. A3 and A4 are not used. Value is what
10411 resize_mini_window returns. */
10414 resize_mini_window_1 (ptrdiff_t a1
, Lisp_Object exactly
)
10417 return resize_mini_window ((struct window
*) i1
, !NILP (exactly
));
10421 /* Resize mini-window W to fit the size of its contents. EXACT_P
10422 means size the window exactly to the size needed. Otherwise, it's
10423 only enlarged until W's buffer is empty.
10425 Set W->start to the right place to begin display. If the whole
10426 contents fit, start at the beginning. Otherwise, start so as
10427 to make the end of the contents appear. This is particularly
10428 important for y-or-n-p, but seems desirable generally.
10430 Value is non-zero if the window height has been changed. */
10433 resize_mini_window (struct window
*w
, int exact_p
)
10435 struct frame
*f
= XFRAME (w
->frame
);
10436 int window_height_changed_p
= 0;
10438 eassert (MINI_WINDOW_P (w
));
10440 /* By default, start display at the beginning. */
10441 set_marker_both (w
->start
, w
->contents
,
10442 BUF_BEGV (XBUFFER (w
->contents
)),
10443 BUF_BEGV_BYTE (XBUFFER (w
->contents
)));
10445 /* Don't resize windows while redisplaying a window; it would
10446 confuse redisplay functions when the size of the window they are
10447 displaying changes from under them. Such a resizing can happen,
10448 for instance, when which-func prints a long message while
10449 we are running fontification-functions. We're running these
10450 functions with safe_call which binds inhibit-redisplay to t. */
10451 if (!NILP (Vinhibit_redisplay
))
10454 /* Nil means don't try to resize. */
10455 if (NILP (Vresize_mini_windows
)
10456 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
10459 if (!FRAME_MINIBUF_ONLY_P (f
))
10462 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
10463 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
10465 EMACS_INT max_height
;
10466 int unit
= FRAME_LINE_HEIGHT (f
);
10467 struct text_pos start
;
10468 struct buffer
*old_current_buffer
= NULL
;
10470 if (current_buffer
!= XBUFFER (w
->contents
))
10472 old_current_buffer
= current_buffer
;
10473 set_buffer_internal (XBUFFER (w
->contents
));
10476 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10478 /* Compute the max. number of lines specified by the user. */
10479 if (FLOATP (Vmax_mini_window_height
))
10480 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
10481 else if (INTEGERP (Vmax_mini_window_height
))
10482 max_height
= XINT (Vmax_mini_window_height
);
10484 max_height
= total_height
/ 4;
10486 /* Correct that max. height if it's bogus. */
10487 max_height
= clip_to_bounds (1, max_height
, total_height
);
10489 /* Find out the height of the text in the window. */
10490 if (it
.line_wrap
== TRUNCATE
)
10495 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
10496 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
10497 height
= it
.current_y
+ last_height
;
10499 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
10500 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
10501 height
= (height
+ unit
- 1) / unit
;
10504 /* Compute a suitable window start. */
10505 if (height
> max_height
)
10507 height
= max_height
;
10508 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10509 move_it_vertically_backward (&it
, (height
- 1) * unit
);
10510 start
= it
.current
.pos
;
10513 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
10514 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
10516 if (EQ (Vresize_mini_windows
, Qgrow_only
))
10518 /* Let it grow only, until we display an empty message, in which
10519 case the window shrinks again. */
10520 if (height
> WINDOW_TOTAL_LINES (w
))
10522 int old_height
= WINDOW_TOTAL_LINES (w
);
10524 FRAME_WINDOWS_FROZEN (f
) = 1;
10525 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10526 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10528 else if (height
< WINDOW_TOTAL_LINES (w
)
10529 && (exact_p
|| BEGV
== ZV
))
10531 int old_height
= WINDOW_TOTAL_LINES (w
);
10533 FRAME_WINDOWS_FROZEN (f
) = 0;
10534 shrink_mini_window (w
);
10535 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10540 /* Always resize to exact size needed. */
10541 if (height
> WINDOW_TOTAL_LINES (w
))
10543 int old_height
= WINDOW_TOTAL_LINES (w
);
10545 FRAME_WINDOWS_FROZEN (f
) = 1;
10546 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10547 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10549 else if (height
< WINDOW_TOTAL_LINES (w
))
10551 int old_height
= WINDOW_TOTAL_LINES (w
);
10553 FRAME_WINDOWS_FROZEN (f
) = 0;
10554 shrink_mini_window (w
);
10558 FRAME_WINDOWS_FROZEN (f
) = 1;
10559 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10562 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10566 if (old_current_buffer
)
10567 set_buffer_internal (old_current_buffer
);
10570 return window_height_changed_p
;
10574 /* Value is the current message, a string, or nil if there is no
10575 current message. */
10578 current_message (void)
10582 if (!BUFFERP (echo_area_buffer
[0]))
10586 with_echo_area_buffer (0, 0, current_message_1
,
10587 (intptr_t) &msg
, Qnil
);
10589 echo_area_buffer
[0] = Qnil
;
10597 current_message_1 (ptrdiff_t a1
, Lisp_Object a2
)
10600 Lisp_Object
*msg
= (Lisp_Object
*) i1
;
10603 *msg
= make_buffer_string (BEG
, Z
, 1);
10610 /* Push the current message on Vmessage_stack for later restoration
10611 by restore_message. Value is non-zero if the current message isn't
10612 empty. This is a relatively infrequent operation, so it's not
10613 worth optimizing. */
10616 push_message (void)
10618 Lisp_Object msg
= current_message ();
10619 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
10620 return STRINGP (msg
);
10624 /* Restore message display from the top of Vmessage_stack. */
10627 restore_message (void)
10629 eassert (CONSP (Vmessage_stack
));
10630 message3_nolog (XCAR (Vmessage_stack
));
10634 /* Handler for unwind-protect calling pop_message. */
10637 pop_message_unwind (void)
10639 /* Pop the top-most entry off Vmessage_stack. */
10640 eassert (CONSP (Vmessage_stack
));
10641 Vmessage_stack
= XCDR (Vmessage_stack
);
10645 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
10646 exits. If the stack is not empty, we have a missing pop_message
10650 check_message_stack (void)
10652 if (!NILP (Vmessage_stack
))
10657 /* Truncate to NCHARS what will be displayed in the echo area the next
10658 time we display it---but don't redisplay it now. */
10661 truncate_echo_area (ptrdiff_t nchars
)
10664 echo_area_buffer
[0] = Qnil
;
10665 else if (!noninteractive
10667 && !NILP (echo_area_buffer
[0]))
10669 struct frame
*sf
= SELECTED_FRAME ();
10670 /* Error messages get reported properly by cmd_error, so this must be
10671 just an informative message; if the frame hasn't really been
10672 initialized yet, just toss it. */
10673 if (sf
->glyphs_initialized_p
)
10674 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
);
10679 /* Helper function for truncate_echo_area. Truncate the current
10680 message to at most NCHARS characters. */
10683 truncate_message_1 (ptrdiff_t nchars
, Lisp_Object a2
)
10685 if (BEG
+ nchars
< Z
)
10686 del_range (BEG
+ nchars
, Z
);
10688 echo_area_buffer
[0] = Qnil
;
10692 /* Set the current message to STRING. */
10695 set_message (Lisp_Object string
)
10697 eassert (STRINGP (string
));
10699 message_enable_multibyte
= STRING_MULTIBYTE (string
);
10701 with_echo_area_buffer (0, -1, set_message_1
, 0, string
);
10702 message_buf_print
= 0;
10703 help_echo_showing_p
= 0;
10705 if (STRINGP (Vdebug_on_message
)
10706 && STRINGP (string
)
10707 && fast_string_match (Vdebug_on_message
, string
) >= 0)
10708 call_debugger (list2 (Qerror
, string
));
10712 /* Helper function for set_message. First argument is ignored and second
10713 argument has the same meaning as for set_message.
10714 This function is called with the echo area buffer being current. */
10717 set_message_1 (ptrdiff_t a1
, Lisp_Object string
)
10719 eassert (STRINGP (string
));
10721 /* Change multibyteness of the echo buffer appropriately. */
10722 if (message_enable_multibyte
10723 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10724 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
10726 bset_truncate_lines (current_buffer
, message_truncate_lines
? Qt
: Qnil
);
10727 if (!NILP (BVAR (current_buffer
, bidi_display_reordering
)))
10728 bset_bidi_paragraph_direction (current_buffer
, Qleft_to_right
);
10730 /* Insert new message at BEG. */
10731 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10733 /* This function takes care of single/multibyte conversion.
10734 We just have to ensure that the echo area buffer has the right
10735 setting of enable_multibyte_characters. */
10736 insert_from_string (string
, 0, 0, SCHARS (string
), SBYTES (string
), 1);
10742 /* Clear messages. CURRENT_P non-zero means clear the current
10743 message. LAST_DISPLAYED_P non-zero means clear the message
10747 clear_message (int current_p
, int last_displayed_p
)
10751 echo_area_buffer
[0] = Qnil
;
10752 message_cleared_p
= 1;
10755 if (last_displayed_p
)
10756 echo_area_buffer
[1] = Qnil
;
10758 message_buf_print
= 0;
10761 /* Clear garbaged frames.
10763 This function is used where the old redisplay called
10764 redraw_garbaged_frames which in turn called redraw_frame which in
10765 turn called clear_frame. The call to clear_frame was a source of
10766 flickering. I believe a clear_frame is not necessary. It should
10767 suffice in the new redisplay to invalidate all current matrices,
10768 and ensure a complete redisplay of all windows. */
10771 clear_garbaged_frames (void)
10773 if (frame_garbaged
)
10775 Lisp_Object tail
, frame
;
10776 int changed_count
= 0;
10778 FOR_EACH_FRAME (tail
, frame
)
10780 struct frame
*f
= XFRAME (frame
);
10782 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
10787 f
->force_flush_display_p
= 1;
10789 clear_current_matrices (f
);
10796 frame_garbaged
= 0;
10798 ++windows_or_buffers_changed
;
10803 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
10804 is non-zero update selected_frame. Value is non-zero if the
10805 mini-windows height has been changed. */
10808 echo_area_display (int update_frame_p
)
10810 Lisp_Object mini_window
;
10813 int window_height_changed_p
= 0;
10814 struct frame
*sf
= SELECTED_FRAME ();
10816 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10817 w
= XWINDOW (mini_window
);
10818 f
= XFRAME (WINDOW_FRAME (w
));
10820 /* Don't display if frame is invisible or not yet initialized. */
10821 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
10824 #ifdef HAVE_WINDOW_SYSTEM
10825 /* When Emacs starts, selected_frame may be the initial terminal
10826 frame. If we let this through, a message would be displayed on
10828 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
10830 #endif /* HAVE_WINDOW_SYSTEM */
10832 /* Redraw garbaged frames. */
10833 clear_garbaged_frames ();
10835 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
10837 echo_area_window
= mini_window
;
10838 window_height_changed_p
= display_echo_area (w
);
10839 w
->must_be_updated_p
= 1;
10841 /* Update the display, unless called from redisplay_internal.
10842 Also don't update the screen during redisplay itself. The
10843 update will happen at the end of redisplay, and an update
10844 here could cause confusion. */
10845 if (update_frame_p
&& !redisplaying_p
)
10849 /* If the display update has been interrupted by pending
10850 input, update mode lines in the frame. Due to the
10851 pending input, it might have been that redisplay hasn't
10852 been called, so that mode lines above the echo area are
10853 garbaged. This looks odd, so we prevent it here. */
10854 if (!display_completed
)
10855 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
10857 if (window_height_changed_p
10858 /* Don't do this if Emacs is shutting down. Redisplay
10859 needs to run hooks. */
10860 && !NILP (Vrun_hooks
))
10862 /* Must update other windows. Likewise as in other
10863 cases, don't let this update be interrupted by
10865 ptrdiff_t count
= SPECPDL_INDEX ();
10866 specbind (Qredisplay_dont_pause
, Qt
);
10867 windows_or_buffers_changed
= 1;
10868 redisplay_internal ();
10869 unbind_to (count
, Qnil
);
10871 else if (FRAME_WINDOW_P (f
) && n
== 0)
10873 /* Window configuration is the same as before.
10874 Can do with a display update of the echo area,
10875 unless we displayed some mode lines. */
10876 update_single_window (w
, 1);
10877 FRAME_RIF (f
)->flush_display (f
);
10880 update_frame (f
, 1, 1);
10882 /* If cursor is in the echo area, make sure that the next
10883 redisplay displays the minibuffer, so that the cursor will
10884 be replaced with what the minibuffer wants. */
10885 if (cursor_in_echo_area
)
10886 ++windows_or_buffers_changed
;
10889 else if (!EQ (mini_window
, selected_window
))
10890 windows_or_buffers_changed
++;
10892 /* Last displayed message is now the current message. */
10893 echo_area_buffer
[1] = echo_area_buffer
[0];
10894 /* Inform read_char that we're not echoing. */
10895 echo_message_buffer
= Qnil
;
10897 /* Prevent redisplay optimization in redisplay_internal by resetting
10898 this_line_start_pos. This is done because the mini-buffer now
10899 displays the message instead of its buffer text. */
10900 if (EQ (mini_window
, selected_window
))
10901 CHARPOS (this_line_start_pos
) = 0;
10903 return window_height_changed_p
;
10906 /* Nonzero if the current window's buffer is shown in more than one
10907 window and was modified since last redisplay. */
10910 buffer_shared_and_changed (void)
10912 return (buffer_window_count (current_buffer
) > 1
10913 && UNCHANGED_MODIFIED
< MODIFF
);
10916 /* Nonzero if W's buffer was changed but not saved or Transient Mark mode
10917 is enabled and mark of W's buffer was changed since last W's update. */
10920 window_buffer_changed (struct window
*w
)
10922 struct buffer
*b
= XBUFFER (w
->contents
);
10924 eassert (BUFFER_LIVE_P (b
));
10926 return (((BUF_SAVE_MODIFF (b
) < BUF_MODIFF (b
)) != w
->last_had_star
)
10927 || ((!NILP (Vtransient_mark_mode
) && !NILP (BVAR (b
, mark_active
)))
10928 != (w
->region_showing
!= 0)));
10931 /* Nonzero if W has %c in its mode line and mode line should be updated. */
10934 mode_line_update_needed (struct window
*w
)
10936 return (w
->column_number_displayed
!= -1
10937 && !(PT
== w
->last_point
&& !window_outdated (w
))
10938 && (w
->column_number_displayed
!= current_column ()));
10941 /* Nonzero if window start of W is frozen and may not be changed during
10945 window_frozen_p (struct window
*w
)
10947 if (FRAME_WINDOWS_FROZEN (XFRAME (WINDOW_FRAME (w
))))
10949 Lisp_Object window
;
10951 XSETWINDOW (window
, w
);
10952 if (MINI_WINDOW_P (w
))
10954 else if (EQ (window
, selected_window
))
10956 else if (MINI_WINDOW_P (XWINDOW (selected_window
))
10957 && EQ (window
, Vminibuf_scroll_window
))
10958 /* This special window can't be frozen too. */
10966 /***********************************************************************
10967 Mode Lines and Frame Titles
10968 ***********************************************************************/
10970 /* A buffer for constructing non-propertized mode-line strings and
10971 frame titles in it; allocated from the heap in init_xdisp and
10972 resized as needed in store_mode_line_noprop_char. */
10974 static char *mode_line_noprop_buf
;
10976 /* The buffer's end, and a current output position in it. */
10978 static char *mode_line_noprop_buf_end
;
10979 static char *mode_line_noprop_ptr
;
10981 #define MODE_LINE_NOPROP_LEN(start) \
10982 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
10985 MODE_LINE_DISPLAY
= 0,
10989 } mode_line_target
;
10991 /* Alist that caches the results of :propertize.
10992 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
10993 static Lisp_Object mode_line_proptrans_alist
;
10995 /* List of strings making up the mode-line. */
10996 static Lisp_Object mode_line_string_list
;
10998 /* Base face property when building propertized mode line string. */
10999 static Lisp_Object mode_line_string_face
;
11000 static Lisp_Object mode_line_string_face_prop
;
11003 /* Unwind data for mode line strings */
11005 static Lisp_Object Vmode_line_unwind_vector
;
11008 format_mode_line_unwind_data (struct frame
*target_frame
,
11009 struct buffer
*obuf
,
11011 int save_proptrans
)
11013 Lisp_Object vector
, tmp
;
11015 /* Reduce consing by keeping one vector in
11016 Vwith_echo_area_save_vector. */
11017 vector
= Vmode_line_unwind_vector
;
11018 Vmode_line_unwind_vector
= Qnil
;
11021 vector
= Fmake_vector (make_number (10), Qnil
);
11023 ASET (vector
, 0, make_number (mode_line_target
));
11024 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
11025 ASET (vector
, 2, mode_line_string_list
);
11026 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
11027 ASET (vector
, 4, mode_line_string_face
);
11028 ASET (vector
, 5, mode_line_string_face_prop
);
11031 XSETBUFFER (tmp
, obuf
);
11034 ASET (vector
, 6, tmp
);
11035 ASET (vector
, 7, owin
);
11038 /* Similarly to `with-selected-window', if the operation selects
11039 a window on another frame, we must restore that frame's
11040 selected window, and (for a tty) the top-frame. */
11041 ASET (vector
, 8, target_frame
->selected_window
);
11042 if (FRAME_TERMCAP_P (target_frame
))
11043 ASET (vector
, 9, FRAME_TTY (target_frame
)->top_frame
);
11050 unwind_format_mode_line (Lisp_Object vector
)
11052 Lisp_Object old_window
= AREF (vector
, 7);
11053 Lisp_Object target_frame_window
= AREF (vector
, 8);
11054 Lisp_Object old_top_frame
= AREF (vector
, 9);
11056 mode_line_target
= XINT (AREF (vector
, 0));
11057 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
11058 mode_line_string_list
= AREF (vector
, 2);
11059 if (! EQ (AREF (vector
, 3), Qt
))
11060 mode_line_proptrans_alist
= AREF (vector
, 3);
11061 mode_line_string_face
= AREF (vector
, 4);
11062 mode_line_string_face_prop
= AREF (vector
, 5);
11064 /* Select window before buffer, since it may change the buffer. */
11065 if (!NILP (old_window
))
11067 /* If the operation that we are unwinding had selected a window
11068 on a different frame, reset its frame-selected-window. For a
11069 text terminal, reset its top-frame if necessary. */
11070 if (!NILP (target_frame_window
))
11073 = WINDOW_FRAME (XWINDOW (target_frame_window
));
11075 if (!EQ (frame
, WINDOW_FRAME (XWINDOW (old_window
))))
11076 Fselect_window (target_frame_window
, Qt
);
11078 if (!NILP (old_top_frame
) && !EQ (old_top_frame
, frame
))
11079 Fselect_frame (old_top_frame
, Qt
);
11082 Fselect_window (old_window
, Qt
);
11085 if (!NILP (AREF (vector
, 6)))
11087 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
11088 ASET (vector
, 6, Qnil
);
11091 Vmode_line_unwind_vector
= vector
;
11095 /* Store a single character C for the frame title in mode_line_noprop_buf.
11096 Re-allocate mode_line_noprop_buf if necessary. */
11099 store_mode_line_noprop_char (char c
)
11101 /* If output position has reached the end of the allocated buffer,
11102 increase the buffer's size. */
11103 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
11105 ptrdiff_t len
= MODE_LINE_NOPROP_LEN (0);
11106 ptrdiff_t size
= len
;
11107 mode_line_noprop_buf
=
11108 xpalloc (mode_line_noprop_buf
, &size
, 1, STRING_BYTES_BOUND
, 1);
11109 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
11110 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
11113 *mode_line_noprop_ptr
++ = c
;
11117 /* Store part of a frame title in mode_line_noprop_buf, beginning at
11118 mode_line_noprop_ptr. STRING is the string to store. Do not copy
11119 characters that yield more columns than PRECISION; PRECISION <= 0
11120 means copy the whole string. Pad with spaces until FIELD_WIDTH
11121 number of characters have been copied; FIELD_WIDTH <= 0 means don't
11122 pad. Called from display_mode_element when it is used to build a
11126 store_mode_line_noprop (const char *string
, int field_width
, int precision
)
11128 const unsigned char *str
= (const unsigned char *) string
;
11130 ptrdiff_t dummy
, nbytes
;
11132 /* Copy at most PRECISION chars from STR. */
11133 nbytes
= strlen (string
);
11134 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
11136 store_mode_line_noprop_char (*str
++);
11138 /* Fill up with spaces until FIELD_WIDTH reached. */
11139 while (field_width
> 0
11140 && n
< field_width
)
11142 store_mode_line_noprop_char (' ');
11149 /***********************************************************************
11151 ***********************************************************************/
11153 #ifdef HAVE_WINDOW_SYSTEM
11155 /* Set the title of FRAME, if it has changed. The title format is
11156 Vicon_title_format if FRAME is iconified, otherwise it is
11157 frame_title_format. */
11160 x_consider_frame_title (Lisp_Object frame
)
11162 struct frame
*f
= XFRAME (frame
);
11164 if (FRAME_WINDOW_P (f
)
11165 || FRAME_MINIBUF_ONLY_P (f
)
11166 || f
->explicit_name
)
11168 /* Do we have more than one visible frame on this X display? */
11169 Lisp_Object tail
, other_frame
, fmt
;
11170 ptrdiff_t title_start
;
11174 ptrdiff_t count
= SPECPDL_INDEX ();
11176 FOR_EACH_FRAME (tail
, other_frame
)
11178 struct frame
*tf
= XFRAME (other_frame
);
11181 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
11182 && !FRAME_MINIBUF_ONLY_P (tf
)
11183 && !EQ (other_frame
, tip_frame
)
11184 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
11188 /* Set global variable indicating that multiple frames exist. */
11189 multiple_frames
= CONSP (tail
);
11191 /* Switch to the buffer of selected window of the frame. Set up
11192 mode_line_target so that display_mode_element will output into
11193 mode_line_noprop_buf; then display the title. */
11194 record_unwind_protect (unwind_format_mode_line
,
11195 format_mode_line_unwind_data
11196 (f
, current_buffer
, selected_window
, 0));
11198 Fselect_window (f
->selected_window
, Qt
);
11199 set_buffer_internal_1
11200 (XBUFFER (XWINDOW (f
->selected_window
)->contents
));
11201 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
11203 mode_line_target
= MODE_LINE_TITLE
;
11204 title_start
= MODE_LINE_NOPROP_LEN (0);
11205 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
11206 NULL
, DEFAULT_FACE_ID
);
11207 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
11208 len
= MODE_LINE_NOPROP_LEN (title_start
);
11209 title
= mode_line_noprop_buf
+ title_start
;
11210 unbind_to (count
, Qnil
);
11212 /* Set the title only if it's changed. This avoids consing in
11213 the common case where it hasn't. (If it turns out that we've
11214 already wasted too much time by walking through the list with
11215 display_mode_element, then we might need to optimize at a
11216 higher level than this.) */
11217 if (! STRINGP (f
->name
)
11218 || SBYTES (f
->name
) != len
11219 || memcmp (title
, SDATA (f
->name
), len
) != 0)
11220 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
11224 #endif /* not HAVE_WINDOW_SYSTEM */
11227 /***********************************************************************
11229 ***********************************************************************/
11232 /* Prepare for redisplay by updating menu-bar item lists when
11233 appropriate. This can call eval. */
11236 prepare_menu_bars (void)
11239 struct gcpro gcpro1
, gcpro2
;
11241 Lisp_Object tooltip_frame
;
11243 #ifdef HAVE_WINDOW_SYSTEM
11244 tooltip_frame
= tip_frame
;
11246 tooltip_frame
= Qnil
;
11249 /* Update all frame titles based on their buffer names, etc. We do
11250 this before the menu bars so that the buffer-menu will show the
11251 up-to-date frame titles. */
11252 #ifdef HAVE_WINDOW_SYSTEM
11253 if (windows_or_buffers_changed
|| update_mode_lines
)
11255 Lisp_Object tail
, frame
;
11257 FOR_EACH_FRAME (tail
, frame
)
11259 f
= XFRAME (frame
);
11260 if (!EQ (frame
, tooltip_frame
)
11261 && (FRAME_ICONIFIED_P (f
)
11262 || FRAME_VISIBLE_P (f
) == 1
11263 /* Exclude TTY frames that are obscured because they
11264 are not the top frame on their console. This is
11265 because x_consider_frame_title actually switches
11266 to the frame, which for TTY frames means it is
11267 marked as garbaged, and will be completely
11268 redrawn on the next redisplay cycle. This causes
11269 TTY frames to be completely redrawn, when there
11270 are more than one of them, even though nothing
11271 should be changed on display. */
11272 || (FRAME_VISIBLE_P (f
) == 2 && FRAME_WINDOW_P (f
))))
11273 x_consider_frame_title (frame
);
11276 #endif /* HAVE_WINDOW_SYSTEM */
11278 /* Update the menu bar item lists, if appropriate. This has to be
11279 done before any actual redisplay or generation of display lines. */
11280 all_windows
= (update_mode_lines
11281 || buffer_shared_and_changed ()
11282 || windows_or_buffers_changed
);
11285 Lisp_Object tail
, frame
;
11286 ptrdiff_t count
= SPECPDL_INDEX ();
11287 /* 1 means that update_menu_bar has run its hooks
11288 so any further calls to update_menu_bar shouldn't do so again. */
11289 int menu_bar_hooks_run
= 0;
11291 record_unwind_save_match_data ();
11293 FOR_EACH_FRAME (tail
, frame
)
11295 f
= XFRAME (frame
);
11297 /* Ignore tooltip frame. */
11298 if (EQ (frame
, tooltip_frame
))
11301 /* If a window on this frame changed size, report that to
11302 the user and clear the size-change flag. */
11303 if (FRAME_WINDOW_SIZES_CHANGED (f
))
11305 Lisp_Object functions
;
11307 /* Clear flag first in case we get an error below. */
11308 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
11309 functions
= Vwindow_size_change_functions
;
11310 GCPRO2 (tail
, functions
);
11312 while (CONSP (functions
))
11314 if (!EQ (XCAR (functions
), Qt
))
11315 call1 (XCAR (functions
), frame
);
11316 functions
= XCDR (functions
);
11322 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
11323 #ifdef HAVE_WINDOW_SYSTEM
11324 update_tool_bar (f
, 0);
11327 if (windows_or_buffers_changed
11330 (f
, Fbuffer_modified_p (XWINDOW (f
->selected_window
)->contents
));
11335 unbind_to (count
, Qnil
);
11339 struct frame
*sf
= SELECTED_FRAME ();
11340 update_menu_bar (sf
, 1, 0);
11341 #ifdef HAVE_WINDOW_SYSTEM
11342 update_tool_bar (sf
, 1);
11348 /* Update the menu bar item list for frame F. This has to be done
11349 before we start to fill in any display lines, because it can call
11352 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
11354 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
11355 already ran the menu bar hooks for this redisplay, so there
11356 is no need to run them again. The return value is the
11357 updated value of this flag, to pass to the next call. */
11360 update_menu_bar (struct frame
*f
, int save_match_data
, int hooks_run
)
11362 Lisp_Object window
;
11363 register struct window
*w
;
11365 /* If called recursively during a menu update, do nothing. This can
11366 happen when, for instance, an activate-menubar-hook causes a
11368 if (inhibit_menubar_update
)
11371 window
= FRAME_SELECTED_WINDOW (f
);
11372 w
= XWINDOW (window
);
11374 if (FRAME_WINDOW_P (f
)
11376 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11377 || defined (HAVE_NS) || defined (USE_GTK)
11378 FRAME_EXTERNAL_MENU_BAR (f
)
11380 FRAME_MENU_BAR_LINES (f
) > 0
11382 : FRAME_MENU_BAR_LINES (f
) > 0)
11384 /* If the user has switched buffers or windows, we need to
11385 recompute to reflect the new bindings. But we'll
11386 recompute when update_mode_lines is set too; that means
11387 that people can use force-mode-line-update to request
11388 that the menu bar be recomputed. The adverse effect on
11389 the rest of the redisplay algorithm is about the same as
11390 windows_or_buffers_changed anyway. */
11391 if (windows_or_buffers_changed
11392 /* This used to test w->update_mode_line, but we believe
11393 there is no need to recompute the menu in that case. */
11394 || update_mode_lines
11395 || window_buffer_changed (w
))
11397 struct buffer
*prev
= current_buffer
;
11398 ptrdiff_t count
= SPECPDL_INDEX ();
11400 specbind (Qinhibit_menubar_update
, Qt
);
11402 set_buffer_internal_1 (XBUFFER (w
->contents
));
11403 if (save_match_data
)
11404 record_unwind_save_match_data ();
11405 if (NILP (Voverriding_local_map_menu_flag
))
11407 specbind (Qoverriding_terminal_local_map
, Qnil
);
11408 specbind (Qoverriding_local_map
, Qnil
);
11413 /* Run the Lucid hook. */
11414 safe_run_hooks (Qactivate_menubar_hook
);
11416 /* If it has changed current-menubar from previous value,
11417 really recompute the menu-bar from the value. */
11418 if (! NILP (Vlucid_menu_bar_dirty_flag
))
11419 call0 (Qrecompute_lucid_menubar
);
11421 safe_run_hooks (Qmenu_bar_update_hook
);
11426 XSETFRAME (Vmenu_updating_frame
, f
);
11427 fset_menu_bar_items (f
, menu_bar_items (FRAME_MENU_BAR_ITEMS (f
)));
11429 /* Redisplay the menu bar in case we changed it. */
11430 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11431 || defined (HAVE_NS) || defined (USE_GTK)
11432 if (FRAME_WINDOW_P (f
))
11434 #if defined (HAVE_NS)
11435 /* All frames on Mac OS share the same menubar. So only
11436 the selected frame should be allowed to set it. */
11437 if (f
== SELECTED_FRAME ())
11439 set_frame_menubar (f
, 0, 0);
11442 /* On a terminal screen, the menu bar is an ordinary screen
11443 line, and this makes it get updated. */
11444 w
->update_mode_line
= 1;
11445 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11446 /* In the non-toolkit version, the menu bar is an ordinary screen
11447 line, and this makes it get updated. */
11448 w
->update_mode_line
= 1;
11449 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11451 unbind_to (count
, Qnil
);
11452 set_buffer_internal_1 (prev
);
11461 /***********************************************************************
11463 ***********************************************************************/
11465 #ifdef HAVE_WINDOW_SYSTEM
11468 Nominal cursor position -- where to draw output.
11469 HPOS and VPOS are window relative glyph matrix coordinates.
11470 X and Y are window relative pixel coordinates. */
11472 struct cursor_pos output_cursor
;
11476 Set the global variable output_cursor to CURSOR. All cursor
11477 positions are relative to currently updated window. */
11480 set_output_cursor (struct cursor_pos
*cursor
)
11482 output_cursor
.hpos
= cursor
->hpos
;
11483 output_cursor
.vpos
= cursor
->vpos
;
11484 output_cursor
.x
= cursor
->x
;
11485 output_cursor
.y
= cursor
->y
;
11490 Set a nominal cursor position.
11492 HPOS and VPOS are column/row positions in a window glyph matrix.
11493 X and Y are window text area relative pixel positions.
11495 This is always done during window update, so the position is the
11496 future output cursor position for currently updated window W.
11497 NOTE: W is used only to check whether this function is called
11498 in a consistent manner via the redisplay interface. */
11501 x_cursor_to (struct window
*w
, int vpos
, int hpos
, int y
, int x
)
11505 /* Set the output cursor. */
11506 output_cursor
.hpos
= hpos
;
11507 output_cursor
.vpos
= vpos
;
11508 output_cursor
.x
= x
;
11509 output_cursor
.y
= y
;
11512 #endif /* HAVE_WINDOW_SYSTEM */
11515 /***********************************************************************
11517 ***********************************************************************/
11519 #ifdef HAVE_WINDOW_SYSTEM
11521 /* Where the mouse was last time we reported a mouse event. */
11523 struct frame
*last_mouse_frame
;
11525 /* Tool-bar item index of the item on which a mouse button was pressed
11528 int last_tool_bar_item
;
11530 /* Select `frame' temporarily without running all the code in
11532 FIXME: Maybe do_switch_frame should be trimmed down similarly
11533 when `norecord' is set. */
11535 fast_set_selected_frame (Lisp_Object frame
)
11537 if (!EQ (selected_frame
, frame
))
11539 selected_frame
= frame
;
11540 selected_window
= XFRAME (frame
)->selected_window
;
11544 /* Update the tool-bar item list for frame F. This has to be done
11545 before we start to fill in any display lines. Called from
11546 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
11547 and restore it here. */
11550 update_tool_bar (struct frame
*f
, int save_match_data
)
11552 #if defined (USE_GTK) || defined (HAVE_NS)
11553 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
11555 int do_update
= WINDOWP (f
->tool_bar_window
)
11556 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
11561 Lisp_Object window
;
11564 window
= FRAME_SELECTED_WINDOW (f
);
11565 w
= XWINDOW (window
);
11567 /* If the user has switched buffers or windows, we need to
11568 recompute to reflect the new bindings. But we'll
11569 recompute when update_mode_lines is set too; that means
11570 that people can use force-mode-line-update to request
11571 that the menu bar be recomputed. The adverse effect on
11572 the rest of the redisplay algorithm is about the same as
11573 windows_or_buffers_changed anyway. */
11574 if (windows_or_buffers_changed
11575 || w
->update_mode_line
11576 || update_mode_lines
11577 || window_buffer_changed (w
))
11579 struct buffer
*prev
= current_buffer
;
11580 ptrdiff_t count
= SPECPDL_INDEX ();
11581 Lisp_Object frame
, new_tool_bar
;
11582 int new_n_tool_bar
;
11583 struct gcpro gcpro1
;
11585 /* Set current_buffer to the buffer of the selected
11586 window of the frame, so that we get the right local
11588 set_buffer_internal_1 (XBUFFER (w
->contents
));
11590 /* Save match data, if we must. */
11591 if (save_match_data
)
11592 record_unwind_save_match_data ();
11594 /* Make sure that we don't accidentally use bogus keymaps. */
11595 if (NILP (Voverriding_local_map_menu_flag
))
11597 specbind (Qoverriding_terminal_local_map
, Qnil
);
11598 specbind (Qoverriding_local_map
, Qnil
);
11601 GCPRO1 (new_tool_bar
);
11603 /* We must temporarily set the selected frame to this frame
11604 before calling tool_bar_items, because the calculation of
11605 the tool-bar keymap uses the selected frame (see
11606 `tool-bar-make-keymap' in tool-bar.el). */
11607 eassert (EQ (selected_window
,
11608 /* Since we only explicitly preserve selected_frame,
11609 check that selected_window would be redundant. */
11610 XFRAME (selected_frame
)->selected_window
));
11611 record_unwind_protect (fast_set_selected_frame
, selected_frame
);
11612 XSETFRAME (frame
, f
);
11613 fast_set_selected_frame (frame
);
11615 /* Build desired tool-bar items from keymaps. */
11617 = tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
11620 /* Redisplay the tool-bar if we changed it. */
11621 if (new_n_tool_bar
!= f
->n_tool_bar_items
11622 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
11624 /* Redisplay that happens asynchronously due to an expose event
11625 may access f->tool_bar_items. Make sure we update both
11626 variables within BLOCK_INPUT so no such event interrupts. */
11628 fset_tool_bar_items (f
, new_tool_bar
);
11629 f
->n_tool_bar_items
= new_n_tool_bar
;
11630 w
->update_mode_line
= 1;
11636 unbind_to (count
, Qnil
);
11637 set_buffer_internal_1 (prev
);
11643 /* Set F->desired_tool_bar_string to a Lisp string representing frame
11644 F's desired tool-bar contents. F->tool_bar_items must have
11645 been set up previously by calling prepare_menu_bars. */
11648 build_desired_tool_bar_string (struct frame
*f
)
11650 int i
, size
, size_needed
;
11651 struct gcpro gcpro1
, gcpro2
, gcpro3
;
11652 Lisp_Object image
, plist
, props
;
11654 image
= plist
= props
= Qnil
;
11655 GCPRO3 (image
, plist
, props
);
11657 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
11658 Otherwise, make a new string. */
11660 /* The size of the string we might be able to reuse. */
11661 size
= (STRINGP (f
->desired_tool_bar_string
)
11662 ? SCHARS (f
->desired_tool_bar_string
)
11665 /* We need one space in the string for each image. */
11666 size_needed
= f
->n_tool_bar_items
;
11668 /* Reuse f->desired_tool_bar_string, if possible. */
11669 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
11670 fset_desired_tool_bar_string
11671 (f
, Fmake_string (make_number (size_needed
), make_number (' ')));
11674 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
11675 Fremove_text_properties (make_number (0), make_number (size
),
11676 props
, f
->desired_tool_bar_string
);
11679 /* Put a `display' property on the string for the images to display,
11680 put a `menu_item' property on tool-bar items with a value that
11681 is the index of the item in F's tool-bar item vector. */
11682 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
11684 #define PROP(IDX) \
11685 AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
11687 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
11688 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
11689 int hmargin
, vmargin
, relief
, idx
, end
;
11691 /* If image is a vector, choose the image according to the
11693 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
11694 if (VECTORP (image
))
11698 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
11699 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
11702 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
11703 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
11705 eassert (ASIZE (image
) >= idx
);
11706 image
= AREF (image
, idx
);
11711 /* Ignore invalid image specifications. */
11712 if (!valid_image_p (image
))
11715 /* Display the tool-bar button pressed, or depressed. */
11716 plist
= Fcopy_sequence (XCDR (image
));
11718 /* Compute margin and relief to draw. */
11719 relief
= (tool_bar_button_relief
>= 0
11720 ? tool_bar_button_relief
11721 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
11722 hmargin
= vmargin
= relief
;
11724 if (RANGED_INTEGERP (1, Vtool_bar_button_margin
,
11725 INT_MAX
- max (hmargin
, vmargin
)))
11727 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
11728 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
11730 else if (CONSP (Vtool_bar_button_margin
))
11732 if (RANGED_INTEGERP (1, XCAR (Vtool_bar_button_margin
),
11733 INT_MAX
- hmargin
))
11734 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
11736 if (RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin
),
11737 INT_MAX
- vmargin
))
11738 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
11741 if (auto_raise_tool_bar_buttons_p
)
11743 /* Add a `:relief' property to the image spec if the item is
11747 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
11754 /* If image is selected, display it pressed, i.e. with a
11755 negative relief. If it's not selected, display it with a
11757 plist
= Fplist_put (plist
, QCrelief
,
11759 ? make_number (-relief
)
11760 : make_number (relief
)));
11765 /* Put a margin around the image. */
11766 if (hmargin
|| vmargin
)
11768 if (hmargin
== vmargin
)
11769 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
11771 plist
= Fplist_put (plist
, QCmargin
,
11772 Fcons (make_number (hmargin
),
11773 make_number (vmargin
)));
11776 /* If button is not enabled, and we don't have special images
11777 for the disabled state, make the image appear disabled by
11778 applying an appropriate algorithm to it. */
11779 if (!enabled_p
&& idx
< 0)
11780 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
11782 /* Put a `display' text property on the string for the image to
11783 display. Put a `menu-item' property on the string that gives
11784 the start of this item's properties in the tool-bar items
11786 image
= Fcons (Qimage
, plist
);
11787 props
= list4 (Qdisplay
, image
,
11788 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
11790 /* Let the last image hide all remaining spaces in the tool bar
11791 string. The string can be longer than needed when we reuse a
11792 previous string. */
11793 if (i
+ 1 == f
->n_tool_bar_items
)
11794 end
= SCHARS (f
->desired_tool_bar_string
);
11797 Fadd_text_properties (make_number (i
), make_number (end
),
11798 props
, f
->desired_tool_bar_string
);
11806 /* Display one line of the tool-bar of frame IT->f.
11808 HEIGHT specifies the desired height of the tool-bar line.
11809 If the actual height of the glyph row is less than HEIGHT, the
11810 row's height is increased to HEIGHT, and the icons are centered
11811 vertically in the new height.
11813 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
11814 count a final empty row in case the tool-bar width exactly matches
11819 display_tool_bar_line (struct it
*it
, int height
)
11821 struct glyph_row
*row
= it
->glyph_row
;
11822 int max_x
= it
->last_visible_x
;
11823 struct glyph
*last
;
11825 prepare_desired_row (row
);
11826 row
->y
= it
->current_y
;
11828 /* Note that this isn't made use of if the face hasn't a box,
11829 so there's no need to check the face here. */
11830 it
->start_of_box_run_p
= 1;
11832 while (it
->current_x
< max_x
)
11834 int x
, n_glyphs_before
, i
, nglyphs
;
11835 struct it it_before
;
11837 /* Get the next display element. */
11838 if (!get_next_display_element (it
))
11840 /* Don't count empty row if we are counting needed tool-bar lines. */
11841 if (height
< 0 && !it
->hpos
)
11846 /* Produce glyphs. */
11847 n_glyphs_before
= row
->used
[TEXT_AREA
];
11850 PRODUCE_GLYPHS (it
);
11852 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
11854 x
= it_before
.current_x
;
11855 while (i
< nglyphs
)
11857 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
11859 if (x
+ glyph
->pixel_width
> max_x
)
11861 /* Glyph doesn't fit on line. Backtrack. */
11862 row
->used
[TEXT_AREA
] = n_glyphs_before
;
11864 /* If this is the only glyph on this line, it will never fit on the
11865 tool-bar, so skip it. But ensure there is at least one glyph,
11866 so we don't accidentally disable the tool-bar. */
11867 if (n_glyphs_before
== 0
11868 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
11874 x
+= glyph
->pixel_width
;
11878 /* Stop at line end. */
11879 if (ITERATOR_AT_END_OF_LINE_P (it
))
11882 set_iterator_to_next (it
, 1);
11887 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
11889 /* Use default face for the border below the tool bar.
11891 FIXME: When auto-resize-tool-bars is grow-only, there is
11892 no additional border below the possibly empty tool-bar lines.
11893 So to make the extra empty lines look "normal", we have to
11894 use the tool-bar face for the border too. */
11895 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
)
11896 && !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
11897 it
->face_id
= DEFAULT_FACE_ID
;
11899 extend_face_to_end_of_line (it
);
11900 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
11901 last
->right_box_line_p
= 1;
11902 if (last
== row
->glyphs
[TEXT_AREA
])
11903 last
->left_box_line_p
= 1;
11905 /* Make line the desired height and center it vertically. */
11906 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
11908 /* Don't add more than one line height. */
11909 height
%= FRAME_LINE_HEIGHT (it
->f
);
11910 it
->max_ascent
+= height
/ 2;
11911 it
->max_descent
+= (height
+ 1) / 2;
11914 compute_line_metrics (it
);
11916 /* If line is empty, make it occupy the rest of the tool-bar. */
11917 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11919 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
11920 row
->visible_height
= row
->height
;
11921 row
->ascent
= row
->phys_ascent
= 0;
11922 row
->extra_line_spacing
= 0;
11925 row
->full_width_p
= 1;
11926 row
->continued_p
= 0;
11927 row
->truncated_on_left_p
= 0;
11928 row
->truncated_on_right_p
= 0;
11930 it
->current_x
= it
->hpos
= 0;
11931 it
->current_y
+= row
->height
;
11937 /* Max tool-bar height. */
11939 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
11940 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
11942 /* Value is the number of screen lines needed to make all tool-bar
11943 items of frame F visible. The number of actual rows needed is
11944 returned in *N_ROWS if non-NULL. */
11947 tool_bar_lines_needed (struct frame
*f
, int *n_rows
)
11949 struct window
*w
= XWINDOW (f
->tool_bar_window
);
11951 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
11952 the desired matrix, so use (unused) mode-line row as temporary row to
11953 avoid destroying the first tool-bar row. */
11954 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
11956 /* Initialize an iterator for iteration over
11957 F->desired_tool_bar_string in the tool-bar window of frame F. */
11958 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
11959 it
.first_visible_x
= 0;
11960 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
11961 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
11962 it
.paragraph_embedding
= L2R
;
11964 while (!ITERATOR_AT_END_P (&it
))
11966 clear_glyph_row (temp_row
);
11967 it
.glyph_row
= temp_row
;
11968 display_tool_bar_line (&it
, -1);
11970 clear_glyph_row (temp_row
);
11972 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
11974 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
11976 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
11980 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
11982 doc
: /* Return the number of lines occupied by the tool bar of FRAME.
11983 If FRAME is nil or omitted, use the selected frame. */)
11984 (Lisp_Object frame
)
11986 struct frame
*f
= decode_any_frame (frame
);
11990 if (WINDOWP (f
->tool_bar_window
)
11991 && (w
= XWINDOW (f
->tool_bar_window
),
11992 WINDOW_TOTAL_LINES (w
) > 0))
11994 update_tool_bar (f
, 1);
11995 if (f
->n_tool_bar_items
)
11997 build_desired_tool_bar_string (f
);
11998 nlines
= tool_bar_lines_needed (f
, NULL
);
12002 return make_number (nlines
);
12006 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
12007 height should be changed. */
12010 redisplay_tool_bar (struct frame
*f
)
12014 struct glyph_row
*row
;
12016 #if defined (USE_GTK) || defined (HAVE_NS)
12017 if (FRAME_EXTERNAL_TOOL_BAR (f
))
12018 update_frame_tool_bar (f
);
12022 /* If frame hasn't a tool-bar window or if it is zero-height, don't
12023 do anything. This means you must start with tool-bar-lines
12024 non-zero to get the auto-sizing effect. Or in other words, you
12025 can turn off tool-bars by specifying tool-bar-lines zero. */
12026 if (!WINDOWP (f
->tool_bar_window
)
12027 || (w
= XWINDOW (f
->tool_bar_window
),
12028 WINDOW_TOTAL_LINES (w
) == 0))
12031 /* Set up an iterator for the tool-bar window. */
12032 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
12033 it
.first_visible_x
= 0;
12034 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
12035 row
= it
.glyph_row
;
12037 /* Build a string that represents the contents of the tool-bar. */
12038 build_desired_tool_bar_string (f
);
12039 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
12040 /* FIXME: This should be controlled by a user option. But it
12041 doesn't make sense to have an R2L tool bar if the menu bar cannot
12042 be drawn also R2L, and making the menu bar R2L is tricky due
12043 toolkit-specific code that implements it. If an R2L tool bar is
12044 ever supported, display_tool_bar_line should also be augmented to
12045 call unproduce_glyphs like display_line and display_string
12047 it
.paragraph_embedding
= L2R
;
12049 if (f
->n_tool_bar_rows
== 0)
12053 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
12054 nlines
!= WINDOW_TOTAL_LINES (w
)))
12057 int old_height
= WINDOW_TOTAL_LINES (w
);
12059 XSETFRAME (frame
, f
);
12060 Fmodify_frame_parameters (frame
,
12061 list1 (Fcons (Qtool_bar_lines
,
12062 make_number (nlines
))));
12063 if (WINDOW_TOTAL_LINES (w
) != old_height
)
12065 clear_glyph_matrix (w
->desired_matrix
);
12066 fonts_changed_p
= 1;
12072 /* Display as many lines as needed to display all tool-bar items. */
12074 if (f
->n_tool_bar_rows
> 0)
12076 int border
, rows
, height
, extra
;
12078 if (TYPE_RANGED_INTEGERP (int, Vtool_bar_border
))
12079 border
= XINT (Vtool_bar_border
);
12080 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
12081 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
12082 else if (EQ (Vtool_bar_border
, Qborder_width
))
12083 border
= f
->border_width
;
12089 rows
= f
->n_tool_bar_rows
;
12090 height
= max (1, (it
.last_visible_y
- border
) / rows
);
12091 extra
= it
.last_visible_y
- border
- height
* rows
;
12093 while (it
.current_y
< it
.last_visible_y
)
12096 if (extra
> 0 && rows
-- > 0)
12098 h
= (extra
+ rows
- 1) / rows
;
12101 display_tool_bar_line (&it
, height
+ h
);
12106 while (it
.current_y
< it
.last_visible_y
)
12107 display_tool_bar_line (&it
, 0);
12110 /* It doesn't make much sense to try scrolling in the tool-bar
12111 window, so don't do it. */
12112 w
->desired_matrix
->no_scrolling_p
= 1;
12113 w
->must_be_updated_p
= 1;
12115 if (!NILP (Vauto_resize_tool_bars
))
12117 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
12118 int change_height_p
= 0;
12120 /* If we couldn't display everything, change the tool-bar's
12121 height if there is room for more. */
12122 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
12123 && it
.current_y
< max_tool_bar_height
)
12124 change_height_p
= 1;
12126 row
= it
.glyph_row
- 1;
12128 /* If there are blank lines at the end, except for a partially
12129 visible blank line at the end that is smaller than
12130 FRAME_LINE_HEIGHT, change the tool-bar's height. */
12131 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12132 && row
->height
>= FRAME_LINE_HEIGHT (f
))
12133 change_height_p
= 1;
12135 /* If row displays tool-bar items, but is partially visible,
12136 change the tool-bar's height. */
12137 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12138 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
12139 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
12140 change_height_p
= 1;
12142 /* Resize windows as needed by changing the `tool-bar-lines'
12143 frame parameter. */
12144 if (change_height_p
)
12147 int old_height
= WINDOW_TOTAL_LINES (w
);
12149 int nlines
= tool_bar_lines_needed (f
, &nrows
);
12151 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
12152 && !f
->minimize_tool_bar_window_p
)
12153 ? (nlines
> old_height
)
12154 : (nlines
!= old_height
));
12155 f
->minimize_tool_bar_window_p
= 0;
12157 if (change_height_p
)
12159 XSETFRAME (frame
, f
);
12160 Fmodify_frame_parameters (frame
,
12161 list1 (Fcons (Qtool_bar_lines
,
12162 make_number (nlines
))));
12163 if (WINDOW_TOTAL_LINES (w
) != old_height
)
12165 clear_glyph_matrix (w
->desired_matrix
);
12166 f
->n_tool_bar_rows
= nrows
;
12167 fonts_changed_p
= 1;
12174 f
->minimize_tool_bar_window_p
= 0;
12179 /* Get information about the tool-bar item which is displayed in GLYPH
12180 on frame F. Return in *PROP_IDX the index where tool-bar item
12181 properties start in F->tool_bar_items. Value is zero if
12182 GLYPH doesn't display a tool-bar item. */
12185 tool_bar_item_info (struct frame
*f
, struct glyph
*glyph
, int *prop_idx
)
12191 /* This function can be called asynchronously, which means we must
12192 exclude any possibility that Fget_text_property signals an
12194 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
12195 charpos
= max (0, charpos
);
12197 /* Get the text property `menu-item' at pos. The value of that
12198 property is the start index of this item's properties in
12199 F->tool_bar_items. */
12200 prop
= Fget_text_property (make_number (charpos
),
12201 Qmenu_item
, f
->current_tool_bar_string
);
12202 if (INTEGERP (prop
))
12204 *prop_idx
= XINT (prop
);
12214 /* Get information about the tool-bar item at position X/Y on frame F.
12215 Return in *GLYPH a pointer to the glyph of the tool-bar item in
12216 the current matrix of the tool-bar window of F, or NULL if not
12217 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
12218 item in F->tool_bar_items. Value is
12220 -1 if X/Y is not on a tool-bar item
12221 0 if X/Y is on the same item that was highlighted before.
12225 get_tool_bar_item (struct frame
*f
, int x
, int y
, struct glyph
**glyph
,
12226 int *hpos
, int *vpos
, int *prop_idx
)
12228 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12229 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12232 /* Find the glyph under X/Y. */
12233 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
12234 if (*glyph
== NULL
)
12237 /* Get the start of this tool-bar item's properties in
12238 f->tool_bar_items. */
12239 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
12242 /* Is mouse on the highlighted item? */
12243 if (EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
)
12244 && *vpos
>= hlinfo
->mouse_face_beg_row
12245 && *vpos
<= hlinfo
->mouse_face_end_row
12246 && (*vpos
> hlinfo
->mouse_face_beg_row
12247 || *hpos
>= hlinfo
->mouse_face_beg_col
)
12248 && (*vpos
< hlinfo
->mouse_face_end_row
12249 || *hpos
< hlinfo
->mouse_face_end_col
12250 || hlinfo
->mouse_face_past_end
))
12258 Handle mouse button event on the tool-bar of frame F, at
12259 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
12260 0 for button release. MODIFIERS is event modifiers for button
12264 handle_tool_bar_click (struct frame
*f
, int x
, int y
, int down_p
,
12267 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12268 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12269 int hpos
, vpos
, prop_idx
;
12270 struct glyph
*glyph
;
12271 Lisp_Object enabled_p
;
12274 /* If not on the highlighted tool-bar item, and mouse-highlight is
12275 non-nil, return. This is so we generate the tool-bar button
12276 click only when the mouse button is released on the same item as
12277 where it was pressed. However, when mouse-highlight is disabled,
12278 generate the click when the button is released regardless of the
12279 highlight, since tool-bar items are not highlighted in that
12281 frame_to_window_pixel_xy (w
, &x
, &y
);
12282 ts
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
12284 || (ts
!= 0 && !NILP (Vmouse_highlight
)))
12287 /* When mouse-highlight is off, generate the click for the item
12288 where the button was pressed, disregarding where it was
12290 if (NILP (Vmouse_highlight
) && !down_p
)
12291 prop_idx
= last_tool_bar_item
;
12293 /* If item is disabled, do nothing. */
12294 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12295 if (NILP (enabled_p
))
12300 /* Show item in pressed state. */
12301 if (!NILP (Vmouse_highlight
))
12302 show_mouse_face (hlinfo
, DRAW_IMAGE_SUNKEN
);
12303 last_tool_bar_item
= prop_idx
;
12307 Lisp_Object key
, frame
;
12308 struct input_event event
;
12309 EVENT_INIT (event
);
12311 /* Show item in released state. */
12312 if (!NILP (Vmouse_highlight
))
12313 show_mouse_face (hlinfo
, DRAW_IMAGE_RAISED
);
12315 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
12317 XSETFRAME (frame
, f
);
12318 event
.kind
= TOOL_BAR_EVENT
;
12319 event
.frame_or_window
= frame
;
12321 kbd_buffer_store_event (&event
);
12323 event
.kind
= TOOL_BAR_EVENT
;
12324 event
.frame_or_window
= frame
;
12326 event
.modifiers
= modifiers
;
12327 kbd_buffer_store_event (&event
);
12328 last_tool_bar_item
= -1;
12333 /* Possibly highlight a tool-bar item on frame F when mouse moves to
12334 tool-bar window-relative coordinates X/Y. Called from
12335 note_mouse_highlight. */
12338 note_tool_bar_highlight (struct frame
*f
, int x
, int y
)
12340 Lisp_Object window
= f
->tool_bar_window
;
12341 struct window
*w
= XWINDOW (window
);
12342 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12343 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12345 struct glyph
*glyph
;
12346 struct glyph_row
*row
;
12348 Lisp_Object enabled_p
;
12350 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
12351 int mouse_down_p
, rc
;
12353 /* Function note_mouse_highlight is called with negative X/Y
12354 values when mouse moves outside of the frame. */
12355 if (x
<= 0 || y
<= 0)
12357 clear_mouse_face (hlinfo
);
12361 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
12364 /* Not on tool-bar item. */
12365 clear_mouse_face (hlinfo
);
12369 /* On same tool-bar item as before. */
12370 goto set_help_echo
;
12372 clear_mouse_face (hlinfo
);
12374 /* Mouse is down, but on different tool-bar item? */
12375 mouse_down_p
= (dpyinfo
->grabbed
12376 && f
== last_mouse_frame
12377 && FRAME_LIVE_P (f
));
12379 && last_tool_bar_item
!= prop_idx
)
12382 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
12384 /* If tool-bar item is not enabled, don't highlight it. */
12385 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12386 if (!NILP (enabled_p
) && !NILP (Vmouse_highlight
))
12388 /* Compute the x-position of the glyph. In front and past the
12389 image is a space. We include this in the highlighted area. */
12390 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
12391 for (i
= x
= 0; i
< hpos
; ++i
)
12392 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
12394 /* Record this as the current active region. */
12395 hlinfo
->mouse_face_beg_col
= hpos
;
12396 hlinfo
->mouse_face_beg_row
= vpos
;
12397 hlinfo
->mouse_face_beg_x
= x
;
12398 hlinfo
->mouse_face_beg_y
= row
->y
;
12399 hlinfo
->mouse_face_past_end
= 0;
12401 hlinfo
->mouse_face_end_col
= hpos
+ 1;
12402 hlinfo
->mouse_face_end_row
= vpos
;
12403 hlinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
12404 hlinfo
->mouse_face_end_y
= row
->y
;
12405 hlinfo
->mouse_face_window
= window
;
12406 hlinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
12408 /* Display it as active. */
12409 show_mouse_face (hlinfo
, draw
);
12414 /* Set help_echo_string to a help string to display for this tool-bar item.
12415 XTread_socket does the rest. */
12416 help_echo_object
= help_echo_window
= Qnil
;
12417 help_echo_pos
= -1;
12418 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
12419 if (NILP (help_echo_string
))
12420 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
12423 #endif /* HAVE_WINDOW_SYSTEM */
12427 /************************************************************************
12428 Horizontal scrolling
12429 ************************************************************************/
12431 static int hscroll_window_tree (Lisp_Object
);
12432 static int hscroll_windows (Lisp_Object
);
12434 /* For all leaf windows in the window tree rooted at WINDOW, set their
12435 hscroll value so that PT is (i) visible in the window, and (ii) so
12436 that it is not within a certain margin at the window's left and
12437 right border. Value is non-zero if any window's hscroll has been
12441 hscroll_window_tree (Lisp_Object window
)
12443 int hscrolled_p
= 0;
12444 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
12445 int hscroll_step_abs
= 0;
12446 double hscroll_step_rel
= 0;
12448 if (hscroll_relative_p
)
12450 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
12451 if (hscroll_step_rel
< 0)
12453 hscroll_relative_p
= 0;
12454 hscroll_step_abs
= 0;
12457 else if (TYPE_RANGED_INTEGERP (int, Vhscroll_step
))
12459 hscroll_step_abs
= XINT (Vhscroll_step
);
12460 if (hscroll_step_abs
< 0)
12461 hscroll_step_abs
= 0;
12464 hscroll_step_abs
= 0;
12466 while (WINDOWP (window
))
12468 struct window
*w
= XWINDOW (window
);
12470 if (WINDOWP (w
->contents
))
12471 hscrolled_p
|= hscroll_window_tree (w
->contents
);
12472 else if (w
->cursor
.vpos
>= 0)
12475 int text_area_width
;
12476 struct glyph_row
*current_cursor_row
12477 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
12478 struct glyph_row
*desired_cursor_row
12479 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
12480 struct glyph_row
*cursor_row
12481 = (desired_cursor_row
->enabled_p
12482 ? desired_cursor_row
12483 : current_cursor_row
);
12484 int row_r2l_p
= cursor_row
->reversed_p
;
12486 text_area_width
= window_box_width (w
, TEXT_AREA
);
12488 /* Scroll when cursor is inside this scroll margin. */
12489 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
12491 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->contents
))
12492 /* For left-to-right rows, hscroll when cursor is either
12493 (i) inside the right hscroll margin, or (ii) if it is
12494 inside the left margin and the window is already
12498 && w
->cursor
.x
<= h_margin
)
12499 || (cursor_row
->enabled_p
12500 && cursor_row
->truncated_on_right_p
12501 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
12502 /* For right-to-left rows, the logic is similar,
12503 except that rules for scrolling to left and right
12504 are reversed. E.g., if cursor.x <= h_margin, we
12505 need to hscroll "to the right" unconditionally,
12506 and that will scroll the screen to the left so as
12507 to reveal the next portion of the row. */
12509 && ((cursor_row
->enabled_p
12510 /* FIXME: It is confusing to set the
12511 truncated_on_right_p flag when R2L rows
12512 are actually truncated on the left. */
12513 && cursor_row
->truncated_on_right_p
12514 && w
->cursor
.x
<= h_margin
)
12516 && (w
->cursor
.x
>= text_area_width
- h_margin
))))))
12520 struct buffer
*saved_current_buffer
;
12524 /* Find point in a display of infinite width. */
12525 saved_current_buffer
= current_buffer
;
12526 current_buffer
= XBUFFER (w
->contents
);
12528 if (w
== XWINDOW (selected_window
))
12531 pt
= clip_to_bounds (BEGV
, marker_position (w
->pointm
), ZV
);
12533 /* Move iterator to pt starting at cursor_row->start in
12534 a line with infinite width. */
12535 init_to_row_start (&it
, w
, cursor_row
);
12536 it
.last_visible_x
= INFINITY
;
12537 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
12538 current_buffer
= saved_current_buffer
;
12540 /* Position cursor in window. */
12541 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
12542 hscroll
= max (0, (it
.current_x
12543 - (ITERATOR_AT_END_OF_LINE_P (&it
)
12544 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
12545 : (text_area_width
/ 2))))
12546 / FRAME_COLUMN_WIDTH (it
.f
);
12547 else if ((!row_r2l_p
12548 && w
->cursor
.x
>= text_area_width
- h_margin
)
12549 || (row_r2l_p
&& w
->cursor
.x
<= h_margin
))
12551 if (hscroll_relative_p
)
12552 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
12555 wanted_x
= text_area_width
12556 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12559 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12563 if (hscroll_relative_p
)
12564 wanted_x
= text_area_width
* hscroll_step_rel
12567 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12570 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12572 hscroll
= max (hscroll
, w
->min_hscroll
);
12574 /* Don't prevent redisplay optimizations if hscroll
12575 hasn't changed, as it will unnecessarily slow down
12577 if (w
->hscroll
!= hscroll
)
12579 XBUFFER (w
->contents
)->prevent_redisplay_optimizations_p
= 1;
12580 w
->hscroll
= hscroll
;
12589 /* Value is non-zero if hscroll of any leaf window has been changed. */
12590 return hscrolled_p
;
12594 /* Set hscroll so that cursor is visible and not inside horizontal
12595 scroll margins for all windows in the tree rooted at WINDOW. See
12596 also hscroll_window_tree above. Value is non-zero if any window's
12597 hscroll has been changed. If it has, desired matrices on the frame
12598 of WINDOW are cleared. */
12601 hscroll_windows (Lisp_Object window
)
12603 int hscrolled_p
= hscroll_window_tree (window
);
12605 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
12606 return hscrolled_p
;
12611 /************************************************************************
12613 ************************************************************************/
12615 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
12616 to a non-zero value. This is sometimes handy to have in a debugger
12621 /* First and last unchanged row for try_window_id. */
12623 static int debug_first_unchanged_at_end_vpos
;
12624 static int debug_last_unchanged_at_beg_vpos
;
12626 /* Delta vpos and y. */
12628 static int debug_dvpos
, debug_dy
;
12630 /* Delta in characters and bytes for try_window_id. */
12632 static ptrdiff_t debug_delta
, debug_delta_bytes
;
12634 /* Values of window_end_pos and window_end_vpos at the end of
12637 static ptrdiff_t debug_end_vpos
;
12639 /* Append a string to W->desired_matrix->method. FMT is a printf
12640 format string. If trace_redisplay_p is non-zero also printf the
12641 resulting string to stderr. */
12643 static void debug_method_add (struct window
*, char const *, ...)
12644 ATTRIBUTE_FORMAT_PRINTF (2, 3);
12647 debug_method_add (struct window
*w
, char const *fmt
, ...)
12650 char *method
= w
->desired_matrix
->method
;
12651 int len
= strlen (method
);
12652 int size
= sizeof w
->desired_matrix
->method
;
12653 int remaining
= size
- len
- 1;
12656 if (len
&& remaining
)
12659 --remaining
, ++len
;
12662 va_start (ap
, fmt
);
12663 vsnprintf (method
+ len
, remaining
+ 1, fmt
, ap
);
12666 if (trace_redisplay_p
)
12667 fprintf (stderr
, "%p (%s): %s\n",
12669 ((BUFFERP (w
->contents
)
12670 && STRINGP (BVAR (XBUFFER (w
->contents
), name
)))
12671 ? SSDATA (BVAR (XBUFFER (w
->contents
), name
))
12676 #endif /* GLYPH_DEBUG */
12679 /* Value is non-zero if all changes in window W, which displays
12680 current_buffer, are in the text between START and END. START is a
12681 buffer position, END is given as a distance from Z. Used in
12682 redisplay_internal for display optimization. */
12685 text_outside_line_unchanged_p (struct window
*w
,
12686 ptrdiff_t start
, ptrdiff_t end
)
12688 int unchanged_p
= 1;
12690 /* If text or overlays have changed, see where. */
12691 if (window_outdated (w
))
12693 /* Gap in the line? */
12694 if (GPT
< start
|| Z
- GPT
< end
)
12697 /* Changes start in front of the line, or end after it? */
12699 && (BEG_UNCHANGED
< start
- 1
12700 || END_UNCHANGED
< end
))
12703 /* If selective display, can't optimize if changes start at the
12704 beginning of the line. */
12706 && INTEGERP (BVAR (current_buffer
, selective_display
))
12707 && XINT (BVAR (current_buffer
, selective_display
)) > 0
12708 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
12711 /* If there are overlays at the start or end of the line, these
12712 may have overlay strings with newlines in them. A change at
12713 START, for instance, may actually concern the display of such
12714 overlay strings as well, and they are displayed on different
12715 lines. So, quickly rule out this case. (For the future, it
12716 might be desirable to implement something more telling than
12717 just BEG/END_UNCHANGED.) */
12720 if (BEG
+ BEG_UNCHANGED
== start
12721 && overlay_touches_p (start
))
12723 if (END_UNCHANGED
== end
12724 && overlay_touches_p (Z
- end
))
12728 /* Under bidi reordering, adding or deleting a character in the
12729 beginning of a paragraph, before the first strong directional
12730 character, can change the base direction of the paragraph (unless
12731 the buffer specifies a fixed paragraph direction), which will
12732 require to redisplay the whole paragraph. It might be worthwhile
12733 to find the paragraph limits and widen the range of redisplayed
12734 lines to that, but for now just give up this optimization. */
12735 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
12736 && NILP (BVAR (XBUFFER (w
->contents
), bidi_paragraph_direction
)))
12740 return unchanged_p
;
12744 /* Do a frame update, taking possible shortcuts into account. This is
12745 the main external entry point for redisplay.
12747 If the last redisplay displayed an echo area message and that message
12748 is no longer requested, we clear the echo area or bring back the
12749 mini-buffer if that is in use. */
12754 redisplay_internal ();
12759 overlay_arrow_string_or_property (Lisp_Object var
)
12763 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
12766 return Voverlay_arrow_string
;
12769 /* Return 1 if there are any overlay-arrows in current_buffer. */
12771 overlay_arrow_in_current_buffer_p (void)
12775 for (vlist
= Voverlay_arrow_variable_list
;
12777 vlist
= XCDR (vlist
))
12779 Lisp_Object var
= XCAR (vlist
);
12782 if (!SYMBOLP (var
))
12784 val
= find_symbol_value (var
);
12786 && current_buffer
== XMARKER (val
)->buffer
)
12793 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
12797 overlay_arrows_changed_p (void)
12801 for (vlist
= Voverlay_arrow_variable_list
;
12803 vlist
= XCDR (vlist
))
12805 Lisp_Object var
= XCAR (vlist
);
12806 Lisp_Object val
, pstr
;
12808 if (!SYMBOLP (var
))
12810 val
= find_symbol_value (var
);
12811 if (!MARKERP (val
))
12813 if (! EQ (COERCE_MARKER (val
),
12814 Fget (var
, Qlast_arrow_position
))
12815 || ! (pstr
= overlay_arrow_string_or_property (var
),
12816 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
12822 /* Mark overlay arrows to be updated on next redisplay. */
12825 update_overlay_arrows (int up_to_date
)
12829 for (vlist
= Voverlay_arrow_variable_list
;
12831 vlist
= XCDR (vlist
))
12833 Lisp_Object var
= XCAR (vlist
);
12835 if (!SYMBOLP (var
))
12838 if (up_to_date
> 0)
12840 Lisp_Object val
= find_symbol_value (var
);
12841 Fput (var
, Qlast_arrow_position
,
12842 COERCE_MARKER (val
));
12843 Fput (var
, Qlast_arrow_string
,
12844 overlay_arrow_string_or_property (var
));
12846 else if (up_to_date
< 0
12847 || !NILP (Fget (var
, Qlast_arrow_position
)))
12849 Fput (var
, Qlast_arrow_position
, Qt
);
12850 Fput (var
, Qlast_arrow_string
, Qt
);
12856 /* Return overlay arrow string to display at row.
12857 Return integer (bitmap number) for arrow bitmap in left fringe.
12858 Return nil if no overlay arrow. */
12861 overlay_arrow_at_row (struct it
*it
, struct glyph_row
*row
)
12865 for (vlist
= Voverlay_arrow_variable_list
;
12867 vlist
= XCDR (vlist
))
12869 Lisp_Object var
= XCAR (vlist
);
12872 if (!SYMBOLP (var
))
12875 val
= find_symbol_value (var
);
12878 && current_buffer
== XMARKER (val
)->buffer
12879 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
12881 if (FRAME_WINDOW_P (it
->f
)
12882 /* FIXME: if ROW->reversed_p is set, this should test
12883 the right fringe, not the left one. */
12884 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
12886 #ifdef HAVE_WINDOW_SYSTEM
12887 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
12890 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
12891 return make_number (fringe_bitmap
);
12894 return make_number (-1); /* Use default arrow bitmap. */
12896 return overlay_arrow_string_or_property (var
);
12903 /* Return 1 if point moved out of or into a composition. Otherwise
12904 return 0. PREV_BUF and PREV_PT are the last point buffer and
12905 position. BUF and PT are the current point buffer and position. */
12908 check_point_in_composition (struct buffer
*prev_buf
, ptrdiff_t prev_pt
,
12909 struct buffer
*buf
, ptrdiff_t pt
)
12911 ptrdiff_t start
, end
;
12913 Lisp_Object buffer
;
12915 XSETBUFFER (buffer
, buf
);
12916 /* Check a composition at the last point if point moved within the
12918 if (prev_buf
== buf
)
12921 /* Point didn't move. */
12924 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
12925 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
12926 && composition_valid_p (start
, end
, prop
)
12927 && start
< prev_pt
&& end
> prev_pt
)
12928 /* The last point was within the composition. Return 1 iff
12929 point moved out of the composition. */
12930 return (pt
<= start
|| pt
>= end
);
12933 /* Check a composition at the current point. */
12934 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
12935 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
12936 && composition_valid_p (start
, end
, prop
)
12937 && start
< pt
&& end
> pt
);
12940 /* Reconsider the clip changes of buffer which is displayed in W. */
12943 reconsider_clip_changes (struct window
*w
)
12945 struct buffer
*b
= XBUFFER (w
->contents
);
12947 if (b
->clip_changed
12948 && w
->window_end_valid
12949 && w
->current_matrix
->buffer
== b
12950 && w
->current_matrix
->zv
== BUF_ZV (b
)
12951 && w
->current_matrix
->begv
== BUF_BEGV (b
))
12952 b
->clip_changed
= 0;
12954 /* If display wasn't paused, and W is not a tool bar window, see if
12955 point has been moved into or out of a composition. In that case,
12956 we set b->clip_changed to 1 to force updating the screen. If
12957 b->clip_changed has already been set to 1, we can skip this
12959 if (!b
->clip_changed
&& w
->window_end_valid
)
12961 ptrdiff_t pt
= (w
== XWINDOW (selected_window
)
12962 ? PT
: marker_position (w
->pointm
));
12964 if ((w
->current_matrix
->buffer
!= b
|| pt
!= w
->last_point
)
12965 && check_point_in_composition (w
->current_matrix
->buffer
,
12966 w
->last_point
, b
, pt
))
12967 b
->clip_changed
= 1;
12971 #define STOP_POLLING \
12972 do { if (! polling_stopped_here) stop_polling (); \
12973 polling_stopped_here = 1; } while (0)
12975 #define RESUME_POLLING \
12976 do { if (polling_stopped_here) start_polling (); \
12977 polling_stopped_here = 0; } while (0)
12980 /* Perhaps in the future avoid recentering windows if it
12981 is not necessary; currently that causes some problems. */
12984 redisplay_internal (void)
12986 struct window
*w
= XWINDOW (selected_window
);
12990 bool must_finish
= 0, match_p
;
12991 struct text_pos tlbufpos
, tlendpos
;
12992 int number_of_visible_frames
;
12995 int polling_stopped_here
= 0;
12996 Lisp_Object tail
, frame
;
12998 /* Non-zero means redisplay has to consider all windows on all
12999 frames. Zero means, only selected_window is considered. */
13000 int consider_all_windows_p
;
13002 /* Non-zero means redisplay has to redisplay the miniwindow. */
13003 int update_miniwindow_p
= 0;
13005 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
13007 /* No redisplay if running in batch mode or frame is not yet fully
13008 initialized, or redisplay is explicitly turned off by setting
13009 Vinhibit_redisplay. */
13010 if (FRAME_INITIAL_P (SELECTED_FRAME ())
13011 || !NILP (Vinhibit_redisplay
))
13014 /* Don't examine these until after testing Vinhibit_redisplay.
13015 When Emacs is shutting down, perhaps because its connection to
13016 X has dropped, we should not look at them at all. */
13017 fr
= XFRAME (w
->frame
);
13018 sf
= SELECTED_FRAME ();
13020 if (!fr
->glyphs_initialized_p
)
13023 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
13024 if (popup_activated ())
13028 /* I don't think this happens but let's be paranoid. */
13029 if (redisplaying_p
)
13032 /* Record a function that clears redisplaying_p
13033 when we leave this function. */
13034 count
= SPECPDL_INDEX ();
13035 record_unwind_protect_void (unwind_redisplay
);
13036 redisplaying_p
= 1;
13037 specbind (Qinhibit_free_realized_faces
, Qnil
);
13039 /* Record this function, so it appears on the profiler's backtraces. */
13040 record_in_backtrace (Qredisplay_internal
, &Qnil
, 0);
13042 FOR_EACH_FRAME (tail
, frame
)
13043 XFRAME (frame
)->already_hscrolled_p
= 0;
13046 /* Remember the currently selected window. */
13050 last_escape_glyph_frame
= NULL
;
13051 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
13052 last_glyphless_glyph_frame
= NULL
;
13053 last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
13055 /* If new fonts have been loaded that make a glyph matrix adjustment
13056 necessary, do it. */
13057 if (fonts_changed_p
)
13059 adjust_glyphs (NULL
);
13060 ++windows_or_buffers_changed
;
13061 fonts_changed_p
= 0;
13064 /* If face_change_count is non-zero, init_iterator will free all
13065 realized faces, which includes the faces referenced from current
13066 matrices. So, we can't reuse current matrices in this case. */
13067 if (face_change_count
)
13068 ++windows_or_buffers_changed
;
13070 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
13071 && FRAME_TTY (sf
)->previous_frame
!= sf
)
13073 /* Since frames on a single ASCII terminal share the same
13074 display area, displaying a different frame means redisplay
13075 the whole thing. */
13076 windows_or_buffers_changed
++;
13077 SET_FRAME_GARBAGED (sf
);
13079 set_tty_color_mode (FRAME_TTY (sf
), sf
);
13081 FRAME_TTY (sf
)->previous_frame
= sf
;
13084 /* Set the visible flags for all frames. Do this before checking for
13085 resized or garbaged frames; they want to know if their frames are
13086 visible. See the comment in frame.h for FRAME_SAMPLE_VISIBILITY. */
13087 number_of_visible_frames
= 0;
13089 FOR_EACH_FRAME (tail
, frame
)
13091 struct frame
*f
= XFRAME (frame
);
13093 if (FRAME_VISIBLE_P (f
))
13094 ++number_of_visible_frames
;
13095 clear_desired_matrices (f
);
13098 /* Notice any pending interrupt request to change frame size. */
13099 do_pending_window_change (1);
13101 /* do_pending_window_change could change the selected_window due to
13102 frame resizing which makes the selected window too small. */
13103 if (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
)
13106 /* Clear frames marked as garbaged. */
13107 clear_garbaged_frames ();
13109 /* Build menubar and tool-bar items. */
13110 if (NILP (Vmemory_full
))
13111 prepare_menu_bars ();
13113 if (windows_or_buffers_changed
)
13114 update_mode_lines
++;
13116 reconsider_clip_changes (w
);
13118 /* In most cases selected window displays current buffer. */
13119 match_p
= XBUFFER (w
->contents
) == current_buffer
;
13124 /* Detect case that we need to write or remove a star in the mode line. */
13125 if ((SAVE_MODIFF
< MODIFF
) != w
->last_had_star
)
13127 w
->update_mode_line
= 1;
13128 if (buffer_shared_and_changed ())
13129 update_mode_lines
++;
13132 /* Avoid invocation of point motion hooks by `current_column' below. */
13133 count1
= SPECPDL_INDEX ();
13134 specbind (Qinhibit_point_motion_hooks
, Qt
);
13136 if (mode_line_update_needed (w
))
13137 w
->update_mode_line
= 1;
13139 unbind_to (count1
, Qnil
);
13142 consider_all_windows_p
= (update_mode_lines
13143 || buffer_shared_and_changed ()
13144 || cursor_type_changed
);
13146 /* If specs for an arrow have changed, do thorough redisplay
13147 to ensure we remove any arrow that should no longer exist. */
13148 if (overlay_arrows_changed_p ())
13149 consider_all_windows_p
= windows_or_buffers_changed
= 1;
13151 /* Normally the message* functions will have already displayed and
13152 updated the echo area, but the frame may have been trashed, or
13153 the update may have been preempted, so display the echo area
13154 again here. Checking message_cleared_p captures the case that
13155 the echo area should be cleared. */
13156 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
13157 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
13158 || (message_cleared_p
13159 && minibuf_level
== 0
13160 /* If the mini-window is currently selected, this means the
13161 echo-area doesn't show through. */
13162 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
13164 int window_height_changed_p
= echo_area_display (0);
13166 if (message_cleared_p
)
13167 update_miniwindow_p
= 1;
13171 /* If we don't display the current message, don't clear the
13172 message_cleared_p flag, because, if we did, we wouldn't clear
13173 the echo area in the next redisplay which doesn't preserve
13175 if (!display_last_displayed_message_p
)
13176 message_cleared_p
= 0;
13178 if (fonts_changed_p
)
13180 else if (window_height_changed_p
)
13182 consider_all_windows_p
= 1;
13183 ++update_mode_lines
;
13184 ++windows_or_buffers_changed
;
13186 /* If window configuration was changed, frames may have been
13187 marked garbaged. Clear them or we will experience
13188 surprises wrt scrolling. */
13189 clear_garbaged_frames ();
13192 else if (EQ (selected_window
, minibuf_window
)
13193 && (current_buffer
->clip_changed
|| window_outdated (w
))
13194 && resize_mini_window (w
, 0))
13196 /* Resized active mini-window to fit the size of what it is
13197 showing if its contents might have changed. */
13199 /* FIXME: this causes all frames to be updated, which seems unnecessary
13200 since only the current frame needs to be considered. This function
13201 needs to be rewritten with two variables, consider_all_windows and
13202 consider_all_frames. */
13203 consider_all_windows_p
= 1;
13204 ++windows_or_buffers_changed
;
13205 ++update_mode_lines
;
13207 /* If window configuration was changed, frames may have been
13208 marked garbaged. Clear them or we will experience
13209 surprises wrt scrolling. */
13210 clear_garbaged_frames ();
13213 /* If showing the region, and mark has changed, we must redisplay
13214 the whole window. The assignment to this_line_start_pos prevents
13215 the optimization directly below this if-statement. */
13216 if (((!NILP (Vtransient_mark_mode
)
13217 && !NILP (BVAR (XBUFFER (w
->contents
), mark_active
)))
13218 != (w
->region_showing
> 0))
13219 || (w
->region_showing
13220 && w
->region_showing
13221 != XINT (Fmarker_position (BVAR (XBUFFER (w
->contents
), mark
)))))
13222 CHARPOS (this_line_start_pos
) = 0;
13224 /* Optimize the case that only the line containing the cursor in the
13225 selected window has changed. Variables starting with this_ are
13226 set in display_line and record information about the line
13227 containing the cursor. */
13228 tlbufpos
= this_line_start_pos
;
13229 tlendpos
= this_line_end_pos
;
13230 if (!consider_all_windows_p
13231 && CHARPOS (tlbufpos
) > 0
13232 && !w
->update_mode_line
13233 && !current_buffer
->clip_changed
13234 && !current_buffer
->prevent_redisplay_optimizations_p
13235 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
13236 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
13237 /* Make sure recorded data applies to current buffer, etc. */
13238 && this_line_buffer
== current_buffer
13241 && !w
->optional_new_start
13242 /* Point must be on the line that we have info recorded about. */
13243 && PT
>= CHARPOS (tlbufpos
)
13244 && PT
<= Z
- CHARPOS (tlendpos
)
13245 /* All text outside that line, including its final newline,
13246 must be unchanged. */
13247 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
13248 CHARPOS (tlendpos
)))
13250 if (CHARPOS (tlbufpos
) > BEGV
13251 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
13252 && (CHARPOS (tlbufpos
) == ZV
13253 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
13254 /* Former continuation line has disappeared by becoming empty. */
13256 else if (window_outdated (w
) || MINI_WINDOW_P (w
))
13258 /* We have to handle the case of continuation around a
13259 wide-column character (see the comment in indent.c around
13262 For instance, in the following case:
13264 -------- Insert --------
13265 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
13266 J_I_ ==> J_I_ `^^' are cursors.
13270 As we have to redraw the line above, we cannot use this
13274 int line_height_before
= this_line_pixel_height
;
13276 /* Note that start_display will handle the case that the
13277 line starting at tlbufpos is a continuation line. */
13278 start_display (&it
, w
, tlbufpos
);
13280 /* Implementation note: It this still necessary? */
13281 if (it
.current_x
!= this_line_start_x
)
13284 TRACE ((stderr
, "trying display optimization 1\n"));
13285 w
->cursor
.vpos
= -1;
13286 overlay_arrow_seen
= 0;
13287 it
.vpos
= this_line_vpos
;
13288 it
.current_y
= this_line_y
;
13289 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
13290 display_line (&it
);
13292 /* If line contains point, is not continued,
13293 and ends at same distance from eob as before, we win. */
13294 if (w
->cursor
.vpos
>= 0
13295 /* Line is not continued, otherwise this_line_start_pos
13296 would have been set to 0 in display_line. */
13297 && CHARPOS (this_line_start_pos
)
13298 /* Line ends as before. */
13299 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
13300 /* Line has same height as before. Otherwise other lines
13301 would have to be shifted up or down. */
13302 && this_line_pixel_height
== line_height_before
)
13304 /* If this is not the window's last line, we must adjust
13305 the charstarts of the lines below. */
13306 if (it
.current_y
< it
.last_visible_y
)
13308 struct glyph_row
*row
13309 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
13310 ptrdiff_t delta
, delta_bytes
;
13312 /* We used to distinguish between two cases here,
13313 conditioned by Z - CHARPOS (tlendpos) == ZV, for
13314 when the line ends in a newline or the end of the
13315 buffer's accessible portion. But both cases did
13316 the same, so they were collapsed. */
13318 - CHARPOS (tlendpos
)
13319 - MATRIX_ROW_START_CHARPOS (row
));
13320 delta_bytes
= (Z_BYTE
13321 - BYTEPOS (tlendpos
)
13322 - MATRIX_ROW_START_BYTEPOS (row
));
13324 increment_matrix_positions (w
->current_matrix
,
13325 this_line_vpos
+ 1,
13326 w
->current_matrix
->nrows
,
13327 delta
, delta_bytes
);
13330 /* If this row displays text now but previously didn't,
13331 or vice versa, w->window_end_vpos may have to be
13333 if (MATRIX_ROW_DISPLAYS_TEXT_P (it
.glyph_row
- 1))
13335 if (w
->window_end_vpos
< this_line_vpos
)
13336 w
->window_end_vpos
= this_line_vpos
;
13338 else if (w
->window_end_vpos
== this_line_vpos
13339 && this_line_vpos
> 0)
13340 w
->window_end_vpos
= this_line_vpos
- 1;
13341 w
->window_end_valid
= 0;
13343 /* Update hint: No need to try to scroll in update_window. */
13344 w
->desired_matrix
->no_scrolling_p
= 1;
13347 *w
->desired_matrix
->method
= 0;
13348 debug_method_add (w
, "optimization 1");
13351 //debug optimization movement issue
13352 //w->desired_matrix->no_scrolling_p = 1;
13353 //*w->desired_matrix->method = 0;
13354 //debug_method_add (w, "optimization 1");
13357 #ifdef HAVE_WINDOW_SYSTEM
13358 update_window_fringes (w
, 0);
13365 else if (/* Cursor position hasn't changed. */
13366 PT
== w
->last_point
13367 /* Make sure the cursor was last displayed
13368 in this window. Otherwise we have to reposition it. */
13369 && 0 <= w
->cursor
.vpos
13370 && w
->cursor
.vpos
< WINDOW_TOTAL_LINES (w
))
13374 do_pending_window_change (1);
13375 /* If selected_window changed, redisplay again. */
13376 if (WINDOWP (selected_window
)
13377 && (w
= XWINDOW (selected_window
)) != sw
)
13380 /* We used to always goto end_of_redisplay here, but this
13381 isn't enough if we have a blinking cursor. */
13382 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
13383 goto end_of_redisplay
;
13387 /* If highlighting the region, or if the cursor is in the echo area,
13388 then we can't just move the cursor. */
13389 else if (! (!NILP (Vtransient_mark_mode
)
13390 && !NILP (BVAR (current_buffer
, mark_active
)))
13391 && (EQ (selected_window
,
13392 BVAR (current_buffer
, last_selected_window
))
13393 || highlight_nonselected_windows
)
13394 && !w
->region_showing
13395 && NILP (Vshow_trailing_whitespace
)
13396 && !cursor_in_echo_area
)
13399 struct glyph_row
*row
;
13401 /* Skip from tlbufpos to PT and see where it is. Note that
13402 PT may be in invisible text. If so, we will end at the
13403 next visible position. */
13404 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
13405 NULL
, DEFAULT_FACE_ID
);
13406 it
.current_x
= this_line_start_x
;
13407 it
.current_y
= this_line_y
;
13408 it
.vpos
= this_line_vpos
;
13410 /* The call to move_it_to stops in front of PT, but
13411 moves over before-strings. */
13412 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
13414 if (it
.vpos
== this_line_vpos
13415 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
13418 eassert (this_line_vpos
== it
.vpos
);
13419 eassert (this_line_y
== it
.current_y
);
13420 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13422 *w
->desired_matrix
->method
= 0;
13423 debug_method_add (w
, "optimization 3");
13432 /* Text changed drastically or point moved off of line. */
13433 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
13436 CHARPOS (this_line_start_pos
) = 0;
13437 consider_all_windows_p
|= buffer_shared_and_changed ();
13438 ++clear_face_cache_count
;
13439 #ifdef HAVE_WINDOW_SYSTEM
13440 ++clear_image_cache_count
;
13443 /* Build desired matrices, and update the display. If
13444 consider_all_windows_p is non-zero, do it for all windows on all
13445 frames. Otherwise do it for selected_window, only. */
13447 if (consider_all_windows_p
)
13449 FOR_EACH_FRAME (tail
, frame
)
13450 XFRAME (frame
)->updated_p
= 0;
13452 FOR_EACH_FRAME (tail
, frame
)
13454 struct frame
*f
= XFRAME (frame
);
13456 /* We don't have to do anything for unselected terminal
13458 if ((FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
13459 && !EQ (FRAME_TTY (f
)->top_frame
, frame
))
13462 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
13464 /* Mark all the scroll bars to be removed; we'll redeem
13465 the ones we want when we redisplay their windows. */
13466 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
13467 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
13469 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13470 redisplay_windows (FRAME_ROOT_WINDOW (f
));
13472 /* The X error handler may have deleted that frame. */
13473 if (!FRAME_LIVE_P (f
))
13476 /* Any scroll bars which redisplay_windows should have
13477 nuked should now go away. */
13478 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
13479 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
13481 /* If fonts changed, display again. */
13482 /* ??? rms: I suspect it is a mistake to jump all the way
13483 back to retry here. It should just retry this frame. */
13484 if (fonts_changed_p
)
13487 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13489 /* See if we have to hscroll. */
13490 if (!f
->already_hscrolled_p
)
13492 f
->already_hscrolled_p
= 1;
13493 if (hscroll_windows (f
->root_window
))
13497 /* Prevent various kinds of signals during display
13498 update. stdio is not robust about handling
13499 signals, which can cause an apparent I/O
13501 if (interrupt_input
)
13502 unrequest_sigio ();
13505 /* Update the display. */
13506 set_window_update_flags (XWINDOW (f
->root_window
), 1);
13507 pending
|= update_frame (f
, 0, 0);
13513 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
13517 /* Do the mark_window_display_accurate after all windows have
13518 been redisplayed because this call resets flags in buffers
13519 which are needed for proper redisplay. */
13520 FOR_EACH_FRAME (tail
, frame
)
13522 struct frame
*f
= XFRAME (frame
);
13525 mark_window_display_accurate (f
->root_window
, 1);
13526 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
13527 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
13532 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13534 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13535 struct frame
*mini_frame
;
13537 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->contents
);
13538 /* Use list_of_error, not Qerror, so that
13539 we catch only errors and don't run the debugger. */
13540 internal_condition_case_1 (redisplay_window_1
, selected_window
,
13542 redisplay_window_error
);
13543 if (update_miniwindow_p
)
13544 internal_condition_case_1 (redisplay_window_1
, mini_window
,
13546 redisplay_window_error
);
13548 /* Compare desired and current matrices, perform output. */
13551 /* If fonts changed, display again. */
13552 if (fonts_changed_p
)
13555 /* Prevent various kinds of signals during display update.
13556 stdio is not robust about handling signals,
13557 which can cause an apparent I/O error. */
13558 if (interrupt_input
)
13559 unrequest_sigio ();
13562 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13564 if (hscroll_windows (selected_window
))
13567 XWINDOW (selected_window
)->must_be_updated_p
= 1;
13568 pending
= update_frame (sf
, 0, 0);
13571 /* We may have called echo_area_display at the top of this
13572 function. If the echo area is on another frame, that may
13573 have put text on a frame other than the selected one, so the
13574 above call to update_frame would not have caught it. Catch
13576 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13577 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
13579 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
13581 XWINDOW (mini_window
)->must_be_updated_p
= 1;
13582 pending
|= update_frame (mini_frame
, 0, 0);
13583 if (!pending
&& hscroll_windows (mini_window
))
13588 /* If display was paused because of pending input, make sure we do a
13589 thorough update the next time. */
13592 /* Prevent the optimization at the beginning of
13593 redisplay_internal that tries a single-line update of the
13594 line containing the cursor in the selected window. */
13595 CHARPOS (this_line_start_pos
) = 0;
13597 /* Let the overlay arrow be updated the next time. */
13598 update_overlay_arrows (0);
13600 /* If we pause after scrolling, some rows in the current
13601 matrices of some windows are not valid. */
13602 if (!WINDOW_FULL_WIDTH_P (w
)
13603 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
13604 update_mode_lines
= 1;
13608 if (!consider_all_windows_p
)
13610 /* This has already been done above if
13611 consider_all_windows_p is set. */
13612 mark_window_display_accurate_1 (w
, 1);
13614 /* Say overlay arrows are up to date. */
13615 update_overlay_arrows (1);
13617 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
13618 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
13621 update_mode_lines
= 0;
13622 windows_or_buffers_changed
= 0;
13623 cursor_type_changed
= 0;
13626 /* Start SIGIO interrupts coming again. Having them off during the
13627 code above makes it less likely one will discard output, but not
13628 impossible, since there might be stuff in the system buffer here.
13629 But it is much hairier to try to do anything about that. */
13630 if (interrupt_input
)
13634 /* If a frame has become visible which was not before, redisplay
13635 again, so that we display it. Expose events for such a frame
13636 (which it gets when becoming visible) don't call the parts of
13637 redisplay constructing glyphs, so simply exposing a frame won't
13638 display anything in this case. So, we have to display these
13639 frames here explicitly. */
13644 FOR_EACH_FRAME (tail
, frame
)
13646 int this_is_visible
= 0;
13648 if (XFRAME (frame
)->visible
)
13649 this_is_visible
= 1;
13651 if (this_is_visible
)
13655 if (new_count
!= number_of_visible_frames
)
13656 windows_or_buffers_changed
++;
13659 /* Change frame size now if a change is pending. */
13660 do_pending_window_change (1);
13662 /* If we just did a pending size change, or have additional
13663 visible frames, or selected_window changed, redisplay again. */
13664 if ((windows_or_buffers_changed
&& !pending
)
13665 || (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
))
13668 /* Clear the face and image caches.
13670 We used to do this only if consider_all_windows_p. But the cache
13671 needs to be cleared if a timer creates images in the current
13672 buffer (e.g. the test case in Bug#6230). */
13674 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
13676 clear_face_cache (0);
13677 clear_face_cache_count
= 0;
13680 #ifdef HAVE_WINDOW_SYSTEM
13681 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
13683 clear_image_caches (Qnil
);
13684 clear_image_cache_count
= 0;
13686 #endif /* HAVE_WINDOW_SYSTEM */
13689 unbind_to (count
, Qnil
);
13694 /* Redisplay, but leave alone any recent echo area message unless
13695 another message has been requested in its place.
13697 This is useful in situations where you need to redisplay but no
13698 user action has occurred, making it inappropriate for the message
13699 area to be cleared. See tracking_off and
13700 wait_reading_process_output for examples of these situations.
13702 FROM_WHERE is an integer saying from where this function was
13703 called. This is useful for debugging. */
13706 redisplay_preserve_echo_area (int from_where
)
13708 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
13710 if (!NILP (echo_area_buffer
[1]))
13712 /* We have a previously displayed message, but no current
13713 message. Redisplay the previous message. */
13714 display_last_displayed_message_p
= 1;
13715 redisplay_internal ();
13716 display_last_displayed_message_p
= 0;
13719 redisplay_internal ();
13721 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
13722 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
13723 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
13727 /* Function registered with record_unwind_protect in redisplay_internal. */
13730 unwind_redisplay (void)
13732 redisplaying_p
= 0;
13736 /* Mark the display of leaf window W as accurate or inaccurate.
13737 If ACCURATE_P is non-zero mark display of W as accurate. If
13738 ACCURATE_P is zero, arrange for W to be redisplayed the next
13739 time redisplay_internal is called. */
13742 mark_window_display_accurate_1 (struct window
*w
, int accurate_p
)
13744 struct buffer
*b
= XBUFFER (w
->contents
);
13746 w
->last_modified
= accurate_p
? BUF_MODIFF (b
) : 0;
13747 w
->last_overlay_modified
= accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0;
13748 w
->last_had_star
= BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
);
13752 b
->clip_changed
= 0;
13753 b
->prevent_redisplay_optimizations_p
= 0;
13755 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
13756 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
13757 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
13758 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
13760 w
->current_matrix
->buffer
= b
;
13761 w
->current_matrix
->begv
= BUF_BEGV (b
);
13762 w
->current_matrix
->zv
= BUF_ZV (b
);
13764 w
->last_cursor
= w
->cursor
;
13765 w
->last_cursor_off_p
= w
->cursor_off_p
;
13767 if (w
== XWINDOW (selected_window
))
13768 w
->last_point
= BUF_PT (b
);
13770 w
->last_point
= marker_position (w
->pointm
);
13772 w
->window_end_valid
= 1;
13773 w
->update_mode_line
= 0;
13778 /* Mark the display of windows in the window tree rooted at WINDOW as
13779 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
13780 windows as accurate. If ACCURATE_P is zero, arrange for windows to
13781 be redisplayed the next time redisplay_internal is called. */
13784 mark_window_display_accurate (Lisp_Object window
, int accurate_p
)
13788 for (; !NILP (window
); window
= w
->next
)
13790 w
= XWINDOW (window
);
13791 if (WINDOWP (w
->contents
))
13792 mark_window_display_accurate (w
->contents
, accurate_p
);
13794 mark_window_display_accurate_1 (w
, accurate_p
);
13798 update_overlay_arrows (1);
13800 /* Force a thorough redisplay the next time by setting
13801 last_arrow_position and last_arrow_string to t, which is
13802 unequal to any useful value of Voverlay_arrow_... */
13803 update_overlay_arrows (-1);
13807 /* Return value in display table DP (Lisp_Char_Table *) for character
13808 C. Since a display table doesn't have any parent, we don't have to
13809 follow parent. Do not call this function directly but use the
13810 macro DISP_CHAR_VECTOR. */
13813 disp_char_vector (struct Lisp_Char_Table
*dp
, int c
)
13817 if (ASCII_CHAR_P (c
))
13820 if (SUB_CHAR_TABLE_P (val
))
13821 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
13827 XSETCHAR_TABLE (table
, dp
);
13828 val
= char_table_ref (table
, c
);
13837 /***********************************************************************
13839 ***********************************************************************/
13841 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
13844 redisplay_windows (Lisp_Object window
)
13846 while (!NILP (window
))
13848 struct window
*w
= XWINDOW (window
);
13850 if (WINDOWP (w
->contents
))
13851 redisplay_windows (w
->contents
);
13852 else if (BUFFERP (w
->contents
))
13854 displayed_buffer
= XBUFFER (w
->contents
);
13855 /* Use list_of_error, not Qerror, so that
13856 we catch only errors and don't run the debugger. */
13857 internal_condition_case_1 (redisplay_window_0
, window
,
13859 redisplay_window_error
);
13867 redisplay_window_error (Lisp_Object ignore
)
13869 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
13874 redisplay_window_0 (Lisp_Object window
)
13876 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
13877 redisplay_window (window
, 0);
13882 redisplay_window_1 (Lisp_Object window
)
13884 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
13885 redisplay_window (window
, 1);
13890 /* Set cursor position of W. PT is assumed to be displayed in ROW.
13891 DELTA and DELTA_BYTES are the numbers of characters and bytes by
13892 which positions recorded in ROW differ from current buffer
13895 Return 0 if cursor is not on this row, 1 otherwise. */
13898 set_cursor_from_row (struct window
*w
, struct glyph_row
*row
,
13899 struct glyph_matrix
*matrix
,
13900 ptrdiff_t delta
, ptrdiff_t delta_bytes
,
13903 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
13904 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
13905 struct glyph
*cursor
= NULL
;
13906 /* The last known character position in row. */
13907 ptrdiff_t last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13909 ptrdiff_t pt_old
= PT
- delta
;
13910 ptrdiff_t pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13911 ptrdiff_t pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
13912 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
13913 /* A glyph beyond the edge of TEXT_AREA which we should never
13915 struct glyph
*glyphs_end
= end
;
13916 /* Non-zero means we've found a match for cursor position, but that
13917 glyph has the avoid_cursor_p flag set. */
13918 int match_with_avoid_cursor
= 0;
13919 /* Non-zero means we've seen at least one glyph that came from a
13921 int string_seen
= 0;
13922 /* Largest and smallest buffer positions seen so far during scan of
13924 ptrdiff_t bpos_max
= pos_before
;
13925 ptrdiff_t bpos_min
= pos_after
;
13926 /* Last buffer position covered by an overlay string with an integer
13927 `cursor' property. */
13928 ptrdiff_t bpos_covered
= 0;
13929 /* Non-zero means the display string on which to display the cursor
13930 comes from a text property, not from an overlay. */
13931 int string_from_text_prop
= 0;
13933 /* Don't even try doing anything if called for a mode-line or
13934 header-line row, since the rest of the code isn't prepared to
13935 deal with such calamities. */
13936 eassert (!row
->mode_line_p
);
13937 if (row
->mode_line_p
)
13940 /* Skip over glyphs not having an object at the start and the end of
13941 the row. These are special glyphs like truncation marks on
13942 terminal frames. */
13943 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13945 if (!row
->reversed_p
)
13948 && INTEGERP (glyph
->object
)
13949 && glyph
->charpos
< 0)
13951 x
+= glyph
->pixel_width
;
13955 && INTEGERP ((end
- 1)->object
)
13956 /* CHARPOS is zero for blanks and stretch glyphs
13957 inserted by extend_face_to_end_of_line. */
13958 && (end
- 1)->charpos
<= 0)
13960 glyph_before
= glyph
- 1;
13967 /* If the glyph row is reversed, we need to process it from back
13968 to front, so swap the edge pointers. */
13969 glyphs_end
= end
= glyph
- 1;
13970 glyph
+= row
->used
[TEXT_AREA
] - 1;
13972 while (glyph
> end
+ 1
13973 && INTEGERP (glyph
->object
)
13974 && glyph
->charpos
< 0)
13977 x
-= glyph
->pixel_width
;
13979 if (INTEGERP (glyph
->object
) && glyph
->charpos
< 0)
13981 /* By default, in reversed rows we put the cursor on the
13982 rightmost (first in the reading order) glyph. */
13983 for (g
= end
+ 1; g
< glyph
; g
++)
13984 x
+= g
->pixel_width
;
13986 && INTEGERP ((end
+ 1)->object
)
13987 && (end
+ 1)->charpos
<= 0)
13989 glyph_before
= glyph
+ 1;
13993 else if (row
->reversed_p
)
13995 /* In R2L rows that don't display text, put the cursor on the
13996 rightmost glyph. Case in point: an empty last line that is
13997 part of an R2L paragraph. */
13999 /* Avoid placing the cursor on the last glyph of the row, where
14000 on terminal frames we hold the vertical border between
14001 adjacent windows. */
14002 if (!FRAME_WINDOW_P (WINDOW_XFRAME (w
))
14003 && !WINDOW_RIGHTMOST_P (w
)
14004 && cursor
== row
->glyphs
[LAST_AREA
] - 1)
14006 x
= -1; /* will be computed below, at label compute_x */
14009 /* Step 1: Try to find the glyph whose character position
14010 corresponds to point. If that's not possible, find 2 glyphs
14011 whose character positions are the closest to point, one before
14012 point, the other after it. */
14013 if (!row
->reversed_p
)
14014 while (/* not marched to end of glyph row */
14016 /* glyph was not inserted by redisplay for internal purposes */
14017 && !INTEGERP (glyph
->object
))
14019 if (BUFFERP (glyph
->object
))
14021 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
14023 if (glyph
->charpos
> bpos_max
)
14024 bpos_max
= glyph
->charpos
;
14025 if (glyph
->charpos
< bpos_min
)
14026 bpos_min
= glyph
->charpos
;
14027 if (!glyph
->avoid_cursor_p
)
14029 /* If we hit point, we've found the glyph on which to
14030 display the cursor. */
14033 match_with_avoid_cursor
= 0;
14036 /* See if we've found a better approximation to
14037 POS_BEFORE or to POS_AFTER. */
14038 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
14040 pos_before
= glyph
->charpos
;
14041 glyph_before
= glyph
;
14043 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
14045 pos_after
= glyph
->charpos
;
14046 glyph_after
= glyph
;
14049 else if (dpos
== 0)
14050 match_with_avoid_cursor
= 1;
14052 else if (STRINGP (glyph
->object
))
14054 Lisp_Object chprop
;
14055 ptrdiff_t glyph_pos
= glyph
->charpos
;
14057 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
14059 if (!NILP (chprop
))
14061 /* If the string came from a `display' text property,
14062 look up the buffer position of that property and
14063 use that position to update bpos_max, as if we
14064 actually saw such a position in one of the row's
14065 glyphs. This helps with supporting integer values
14066 of `cursor' property on the display string in
14067 situations where most or all of the row's buffer
14068 text is completely covered by display properties,
14069 so that no glyph with valid buffer positions is
14070 ever seen in the row. */
14071 ptrdiff_t prop_pos
=
14072 string_buffer_position_lim (glyph
->object
, pos_before
,
14075 if (prop_pos
>= pos_before
)
14076 bpos_max
= prop_pos
- 1;
14078 if (INTEGERP (chprop
))
14080 bpos_covered
= bpos_max
+ XINT (chprop
);
14081 /* If the `cursor' property covers buffer positions up
14082 to and including point, we should display cursor on
14083 this glyph. Note that, if a `cursor' property on one
14084 of the string's characters has an integer value, we
14085 will break out of the loop below _before_ we get to
14086 the position match above. IOW, integer values of
14087 the `cursor' property override the "exact match for
14088 point" strategy of positioning the cursor. */
14089 /* Implementation note: bpos_max == pt_old when, e.g.,
14090 we are in an empty line, where bpos_max is set to
14091 MATRIX_ROW_START_CHARPOS, see above. */
14092 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14101 x
+= glyph
->pixel_width
;
14104 else if (glyph
> end
) /* row is reversed */
14105 while (!INTEGERP (glyph
->object
))
14107 if (BUFFERP (glyph
->object
))
14109 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
14111 if (glyph
->charpos
> bpos_max
)
14112 bpos_max
= glyph
->charpos
;
14113 if (glyph
->charpos
< bpos_min
)
14114 bpos_min
= glyph
->charpos
;
14115 if (!glyph
->avoid_cursor_p
)
14119 match_with_avoid_cursor
= 0;
14122 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
14124 pos_before
= glyph
->charpos
;
14125 glyph_before
= glyph
;
14127 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
14129 pos_after
= glyph
->charpos
;
14130 glyph_after
= glyph
;
14133 else if (dpos
== 0)
14134 match_with_avoid_cursor
= 1;
14136 else if (STRINGP (glyph
->object
))
14138 Lisp_Object chprop
;
14139 ptrdiff_t glyph_pos
= glyph
->charpos
;
14141 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
14143 if (!NILP (chprop
))
14145 ptrdiff_t prop_pos
=
14146 string_buffer_position_lim (glyph
->object
, pos_before
,
14149 if (prop_pos
>= pos_before
)
14150 bpos_max
= prop_pos
- 1;
14152 if (INTEGERP (chprop
))
14154 bpos_covered
= bpos_max
+ XINT (chprop
);
14155 /* If the `cursor' property covers buffer positions up
14156 to and including point, we should display cursor on
14158 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14167 if (glyph
== glyphs_end
) /* don't dereference outside TEXT_AREA */
14169 x
--; /* can't use any pixel_width */
14172 x
-= glyph
->pixel_width
;
14175 /* Step 2: If we didn't find an exact match for point, we need to
14176 look for a proper place to put the cursor among glyphs between
14177 GLYPH_BEFORE and GLYPH_AFTER. */
14178 if (!((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14179 && BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14180 && !(bpos_max
< pt_old
&& pt_old
<= bpos_covered
))
14182 /* An empty line has a single glyph whose OBJECT is zero and
14183 whose CHARPOS is the position of a newline on that line.
14184 Note that on a TTY, there are more glyphs after that, which
14185 were produced by extend_face_to_end_of_line, but their
14186 CHARPOS is zero or negative. */
14188 (row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14189 && INTEGERP (glyph
->object
) && glyph
->charpos
> 0
14190 /* On a TTY, continued and truncated rows also have a glyph at
14191 their end whose OBJECT is zero and whose CHARPOS is
14192 positive (the continuation and truncation glyphs), but such
14193 rows are obviously not "empty". */
14194 && !(row
->continued_p
|| row
->truncated_on_right_p
);
14196 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
14198 ptrdiff_t ellipsis_pos
;
14200 /* Scan back over the ellipsis glyphs. */
14201 if (!row
->reversed_p
)
14203 ellipsis_pos
= (glyph
- 1)->charpos
;
14204 while (glyph
> row
->glyphs
[TEXT_AREA
]
14205 && (glyph
- 1)->charpos
== ellipsis_pos
)
14206 glyph
--, x
-= glyph
->pixel_width
;
14207 /* That loop always goes one position too far, including
14208 the glyph before the ellipsis. So scan forward over
14210 x
+= glyph
->pixel_width
;
14213 else /* row is reversed */
14215 ellipsis_pos
= (glyph
+ 1)->charpos
;
14216 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14217 && (glyph
+ 1)->charpos
== ellipsis_pos
)
14218 glyph
++, x
+= glyph
->pixel_width
;
14219 x
-= glyph
->pixel_width
;
14223 else if (match_with_avoid_cursor
)
14225 cursor
= glyph_after
;
14228 else if (string_seen
)
14230 int incr
= row
->reversed_p
? -1 : +1;
14232 /* Need to find the glyph that came out of a string which is
14233 present at point. That glyph is somewhere between
14234 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
14235 positioned between POS_BEFORE and POS_AFTER in the
14237 struct glyph
*start
, *stop
;
14238 ptrdiff_t pos
= pos_before
;
14242 /* If the row ends in a newline from a display string,
14243 reordering could have moved the glyphs belonging to the
14244 string out of the [GLYPH_BEFORE..GLYPH_AFTER] range. So
14245 in this case we extend the search to the last glyph in
14246 the row that was not inserted by redisplay. */
14247 if (row
->ends_in_newline_from_string_p
)
14250 pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
14253 /* GLYPH_BEFORE and GLYPH_AFTER are the glyphs that
14254 correspond to POS_BEFORE and POS_AFTER, respectively. We
14255 need START and STOP in the order that corresponds to the
14256 row's direction as given by its reversed_p flag. If the
14257 directionality of characters between POS_BEFORE and
14258 POS_AFTER is the opposite of the row's base direction,
14259 these characters will have been reordered for display,
14260 and we need to reverse START and STOP. */
14261 if (!row
->reversed_p
)
14263 start
= min (glyph_before
, glyph_after
);
14264 stop
= max (glyph_before
, glyph_after
);
14268 start
= max (glyph_before
, glyph_after
);
14269 stop
= min (glyph_before
, glyph_after
);
14271 for (glyph
= start
+ incr
;
14272 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
14275 /* Any glyphs that come from the buffer are here because
14276 of bidi reordering. Skip them, and only pay
14277 attention to glyphs that came from some string. */
14278 if (STRINGP (glyph
->object
))
14282 /* If the display property covers the newline, we
14283 need to search for it one position farther. */
14284 ptrdiff_t lim
= pos_after
14285 + (pos_after
== MATRIX_ROW_END_CHARPOS (row
) + delta
);
14287 string_from_text_prop
= 0;
14288 str
= glyph
->object
;
14289 tem
= string_buffer_position_lim (str
, pos
, lim
, 0);
14290 if (tem
== 0 /* from overlay */
14293 /* If the string from which this glyph came is
14294 found in the buffer at point, or at position
14295 that is closer to point than pos_after, then
14296 we've found the glyph we've been looking for.
14297 If it comes from an overlay (tem == 0), and
14298 it has the `cursor' property on one of its
14299 glyphs, record that glyph as a candidate for
14300 displaying the cursor. (As in the
14301 unidirectional version, we will display the
14302 cursor on the last candidate we find.) */
14305 || (tem
- pt_old
> 0 && tem
< pos_after
))
14307 /* The glyphs from this string could have
14308 been reordered. Find the one with the
14309 smallest string position. Or there could
14310 be a character in the string with the
14311 `cursor' property, which means display
14312 cursor on that character's glyph. */
14313 ptrdiff_t strpos
= glyph
->charpos
;
14318 string_from_text_prop
= 1;
14321 (row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14322 && EQ (glyph
->object
, str
);
14326 ptrdiff_t gpos
= glyph
->charpos
;
14328 cprop
= Fget_char_property (make_number (gpos
),
14336 if (tem
&& glyph
->charpos
< strpos
)
14338 strpos
= glyph
->charpos
;
14344 || (tem
- pt_old
> 0 && tem
< pos_after
))
14348 pos
= tem
+ 1; /* don't find previous instances */
14350 /* This string is not what we want; skip all of the
14351 glyphs that came from it. */
14352 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14353 && EQ (glyph
->object
, str
))
14360 /* If we reached the end of the line, and END was from a string,
14361 the cursor is not on this line. */
14363 && (row
->reversed_p
? glyph
<= end
: glyph
>= end
)
14364 && (row
->reversed_p
? end
> glyphs_end
: end
< glyphs_end
)
14365 && STRINGP (end
->object
)
14366 && row
->continued_p
)
14369 /* A truncated row may not include PT among its character positions.
14370 Setting the cursor inside the scroll margin will trigger
14371 recalculation of hscroll in hscroll_window_tree. But if a
14372 display string covers point, defer to the string-handling
14373 code below to figure this out. */
14374 else if (row
->truncated_on_left_p
&& pt_old
< bpos_min
)
14376 cursor
= glyph_before
;
14379 else if ((row
->truncated_on_right_p
&& pt_old
> bpos_max
)
14380 /* Zero-width characters produce no glyphs. */
14382 && (row
->reversed_p
14383 ? glyph_after
> glyphs_end
14384 : glyph_after
< glyphs_end
)))
14386 cursor
= glyph_after
;
14392 if (cursor
!= NULL
)
14394 else if (glyph
== glyphs_end
14395 && pos_before
== pos_after
14396 && STRINGP ((row
->reversed_p
14397 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14398 : row
->glyphs
[TEXT_AREA
])->object
))
14400 /* If all the glyphs of this row came from strings, put the
14401 cursor on the first glyph of the row. This avoids having the
14402 cursor outside of the text area in this very rare and hard
14406 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14407 : row
->glyphs
[TEXT_AREA
];
14413 /* Need to compute x that corresponds to GLYPH. */
14414 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
14416 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
14418 x
+= g
->pixel_width
;
14422 /* ROW could be part of a continued line, which, under bidi
14423 reordering, might have other rows whose start and end charpos
14424 occlude point. Only set w->cursor if we found a better
14425 approximation to the cursor position than we have from previously
14426 examined candidate rows belonging to the same continued line. */
14427 if (/* we already have a candidate row */
14428 w
->cursor
.vpos
>= 0
14429 /* that candidate is not the row we are processing */
14430 && MATRIX_ROW (matrix
, w
->cursor
.vpos
) != row
14431 /* Make sure cursor.vpos specifies a row whose start and end
14432 charpos occlude point, and it is valid candidate for being a
14433 cursor-row. This is because some callers of this function
14434 leave cursor.vpos at the row where the cursor was displayed
14435 during the last redisplay cycle. */
14436 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)) <= pt_old
14437 && pt_old
<= MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14438 && cursor_row_p (MATRIX_ROW (matrix
, w
->cursor
.vpos
)))
14441 MATRIX_ROW_GLYPH_START (matrix
, w
->cursor
.vpos
) + w
->cursor
.hpos
;
14443 /* Don't consider glyphs that are outside TEXT_AREA. */
14444 if (!(row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
))
14446 /* Keep the candidate whose buffer position is the closest to
14447 point or has the `cursor' property. */
14448 if (/* previous candidate is a glyph in TEXT_AREA of that row */
14449 w
->cursor
.hpos
>= 0
14450 && w
->cursor
.hpos
< MATRIX_ROW_USED (matrix
, w
->cursor
.vpos
)
14451 && ((BUFFERP (g1
->object
)
14452 && (g1
->charpos
== pt_old
/* an exact match always wins */
14453 || (BUFFERP (glyph
->object
)
14454 && eabs (g1
->charpos
- pt_old
)
14455 < eabs (glyph
->charpos
- pt_old
))))
14456 /* previous candidate is a glyph from a string that has
14457 a non-nil `cursor' property */
14458 || (STRINGP (g1
->object
)
14459 && (!NILP (Fget_char_property (make_number (g1
->charpos
),
14460 Qcursor
, g1
->object
))
14461 /* previous candidate is from the same display
14462 string as this one, and the display string
14463 came from a text property */
14464 || (EQ (g1
->object
, glyph
->object
)
14465 && string_from_text_prop
)
14466 /* this candidate is from newline and its
14467 position is not an exact match */
14468 || (INTEGERP (glyph
->object
)
14469 && glyph
->charpos
!= pt_old
)))))
14471 /* If this candidate gives an exact match, use that. */
14472 if (!((BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14473 /* If this candidate is a glyph created for the
14474 terminating newline of a line, and point is on that
14475 newline, it wins because it's an exact match. */
14476 || (!row
->continued_p
14477 && INTEGERP (glyph
->object
)
14478 && glyph
->charpos
== 0
14479 && pt_old
== MATRIX_ROW_END_CHARPOS (row
) - 1))
14480 /* Otherwise, keep the candidate that comes from a row
14481 spanning less buffer positions. This may win when one or
14482 both candidate positions are on glyphs that came from
14483 display strings, for which we cannot compare buffer
14485 && MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14486 - MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14487 < MATRIX_ROW_END_CHARPOS (row
) - MATRIX_ROW_START_CHARPOS (row
))
14490 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
14492 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
14493 w
->cursor
.y
= row
->y
+ dy
;
14495 if (w
== XWINDOW (selected_window
))
14497 if (!row
->continued_p
14498 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
14501 this_line_buffer
= XBUFFER (w
->contents
);
14503 CHARPOS (this_line_start_pos
)
14504 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
14505 BYTEPOS (this_line_start_pos
)
14506 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
14508 CHARPOS (this_line_end_pos
)
14509 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
14510 BYTEPOS (this_line_end_pos
)
14511 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
14513 this_line_y
= w
->cursor
.y
;
14514 this_line_pixel_height
= row
->height
;
14515 this_line_vpos
= w
->cursor
.vpos
;
14516 this_line_start_x
= row
->x
;
14519 CHARPOS (this_line_start_pos
) = 0;
14526 /* Run window scroll functions, if any, for WINDOW with new window
14527 start STARTP. Sets the window start of WINDOW to that position.
14529 We assume that the window's buffer is really current. */
14531 static struct text_pos
14532 run_window_scroll_functions (Lisp_Object window
, struct text_pos startp
)
14534 struct window
*w
= XWINDOW (window
);
14535 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
14537 eassert (current_buffer
== XBUFFER (w
->contents
));
14539 if (!NILP (Vwindow_scroll_functions
))
14541 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
14542 make_number (CHARPOS (startp
)));
14543 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14544 /* In case the hook functions switch buffers. */
14545 set_buffer_internal (XBUFFER (w
->contents
));
14552 /* Make sure the line containing the cursor is fully visible.
14553 A value of 1 means there is nothing to be done.
14554 (Either the line is fully visible, or it cannot be made so,
14555 or we cannot tell.)
14557 If FORCE_P is non-zero, return 0 even if partial visible cursor row
14558 is higher than window.
14560 A value of 0 means the caller should do scrolling
14561 as if point had gone off the screen. */
14564 cursor_row_fully_visible_p (struct window
*w
, int force_p
, int current_matrix_p
)
14566 struct glyph_matrix
*matrix
;
14567 struct glyph_row
*row
;
14570 if (!make_cursor_line_fully_visible_p
)
14573 /* It's not always possible to find the cursor, e.g, when a window
14574 is full of overlay strings. Don't do anything in that case. */
14575 if (w
->cursor
.vpos
< 0)
14578 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
14579 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
14581 /* If the cursor row is not partially visible, there's nothing to do. */
14582 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
14585 /* If the row the cursor is in is taller than the window's height,
14586 it's not clear what to do, so do nothing. */
14587 window_height
= window_box_height (w
);
14588 if (row
->height
>= window_height
)
14590 if (!force_p
|| MINI_WINDOW_P (w
)
14591 || w
->vscroll
|| w
->cursor
.vpos
== 0)
14598 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
14599 non-zero means only WINDOW is redisplayed in redisplay_internal.
14600 TEMP_SCROLL_STEP has the same meaning as emacs_scroll_step, and is used
14601 in redisplay_window to bring a partially visible line into view in
14602 the case that only the cursor has moved.
14604 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
14605 last screen line's vertical height extends past the end of the screen.
14609 1 if scrolling succeeded
14611 0 if scrolling didn't find point.
14613 -1 if new fonts have been loaded so that we must interrupt
14614 redisplay, adjust glyph matrices, and try again. */
14620 SCROLLING_NEED_LARGER_MATRICES
14623 /* If scroll-conservatively is more than this, never recenter.
14625 If you change this, don't forget to update the doc string of
14626 `scroll-conservatively' and the Emacs manual. */
14627 #define SCROLL_LIMIT 100
14630 try_scrolling (Lisp_Object window
, int just_this_one_p
,
14631 ptrdiff_t arg_scroll_conservatively
, ptrdiff_t scroll_step
,
14632 int temp_scroll_step
, int last_line_misfit
)
14634 struct window
*w
= XWINDOW (window
);
14635 struct frame
*f
= XFRAME (w
->frame
);
14636 struct text_pos pos
, startp
;
14638 int this_scroll_margin
, scroll_max
, rc
, height
;
14639 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
14640 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
14641 Lisp_Object aggressive
;
14642 /* We will never try scrolling more than this number of lines. */
14643 int scroll_limit
= SCROLL_LIMIT
;
14644 int frame_line_height
= default_line_pixel_height (w
);
14645 int window_total_lines
14646 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
14649 debug_method_add (w
, "try_scrolling");
14652 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14654 /* Compute scroll margin height in pixels. We scroll when point is
14655 within this distance from the top or bottom of the window. */
14656 if (scroll_margin
> 0)
14657 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4)
14658 * frame_line_height
;
14660 this_scroll_margin
= 0;
14662 /* Force arg_scroll_conservatively to have a reasonable value, to
14663 avoid scrolling too far away with slow move_it_* functions. Note
14664 that the user can supply scroll-conservatively equal to
14665 `most-positive-fixnum', which can be larger than INT_MAX. */
14666 if (arg_scroll_conservatively
> scroll_limit
)
14668 arg_scroll_conservatively
= scroll_limit
+ 1;
14669 scroll_max
= scroll_limit
* frame_line_height
;
14671 else if (scroll_step
|| arg_scroll_conservatively
|| temp_scroll_step
)
14672 /* Compute how much we should try to scroll maximally to bring
14673 point into view. */
14674 scroll_max
= (max (scroll_step
,
14675 max (arg_scroll_conservatively
, temp_scroll_step
))
14676 * frame_line_height
);
14677 else if (NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
))
14678 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
)))
14679 /* We're trying to scroll because of aggressive scrolling but no
14680 scroll_step is set. Choose an arbitrary one. */
14681 scroll_max
= 10 * frame_line_height
;
14687 /* Decide whether to scroll down. */
14688 if (PT
> CHARPOS (startp
))
14690 int scroll_margin_y
;
14692 /* Compute the pixel ypos of the scroll margin, then move IT to
14693 either that ypos or PT, whichever comes first. */
14694 start_display (&it
, w
, startp
);
14695 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
14696 - frame_line_height
* extra_scroll_margin_lines
;
14697 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
14698 (MOVE_TO_POS
| MOVE_TO_Y
));
14700 if (PT
> CHARPOS (it
.current
.pos
))
14702 int y0
= line_bottom_y (&it
);
14703 /* Compute how many pixels below window bottom to stop searching
14704 for PT. This avoids costly search for PT that is far away if
14705 the user limited scrolling by a small number of lines, but
14706 always finds PT if scroll_conservatively is set to a large
14707 number, such as most-positive-fixnum. */
14708 int slack
= max (scroll_max
, 10 * frame_line_height
);
14709 int y_to_move
= it
.last_visible_y
+ slack
;
14711 /* Compute the distance from the scroll margin to PT or to
14712 the scroll limit, whichever comes first. This should
14713 include the height of the cursor line, to make that line
14715 move_it_to (&it
, PT
, -1, y_to_move
,
14716 -1, MOVE_TO_POS
| MOVE_TO_Y
);
14717 dy
= line_bottom_y (&it
) - y0
;
14719 if (dy
> scroll_max
)
14720 return SCROLLING_FAILED
;
14729 /* Point is in or below the bottom scroll margin, so move the
14730 window start down. If scrolling conservatively, move it just
14731 enough down to make point visible. If scroll_step is set,
14732 move it down by scroll_step. */
14733 if (arg_scroll_conservatively
)
14735 = min (max (dy
, frame_line_height
),
14736 frame_line_height
* arg_scroll_conservatively
);
14737 else if (scroll_step
|| temp_scroll_step
)
14738 amount_to_scroll
= scroll_max
;
14741 aggressive
= BVAR (current_buffer
, scroll_up_aggressively
);
14742 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14743 if (NUMBERP (aggressive
))
14745 double float_amount
= XFLOATINT (aggressive
) * height
;
14746 int aggressive_scroll
= float_amount
;
14747 if (aggressive_scroll
== 0 && float_amount
> 0)
14748 aggressive_scroll
= 1;
14749 /* Don't let point enter the scroll margin near top of
14750 the window. This could happen if the value of
14751 scroll_up_aggressively is too large and there are
14752 non-zero margins, because scroll_up_aggressively
14753 means put point that fraction of window height
14754 _from_the_bottom_margin_. */
14755 if (aggressive_scroll
+ 2*this_scroll_margin
> height
)
14756 aggressive_scroll
= height
- 2*this_scroll_margin
;
14757 amount_to_scroll
= dy
+ aggressive_scroll
;
14761 if (amount_to_scroll
<= 0)
14762 return SCROLLING_FAILED
;
14764 start_display (&it
, w
, startp
);
14765 if (arg_scroll_conservatively
<= scroll_limit
)
14766 move_it_vertically (&it
, amount_to_scroll
);
14769 /* Extra precision for users who set scroll-conservatively
14770 to a large number: make sure the amount we scroll
14771 the window start is never less than amount_to_scroll,
14772 which was computed as distance from window bottom to
14773 point. This matters when lines at window top and lines
14774 below window bottom have different height. */
14776 void *it1data
= NULL
;
14777 /* We use a temporary it1 because line_bottom_y can modify
14778 its argument, if it moves one line down; see there. */
14781 SAVE_IT (it1
, it
, it1data
);
14782 start_y
= line_bottom_y (&it1
);
14784 RESTORE_IT (&it
, &it
, it1data
);
14785 move_it_by_lines (&it
, 1);
14786 SAVE_IT (it1
, it
, it1data
);
14787 } while (line_bottom_y (&it1
) - start_y
< amount_to_scroll
);
14790 /* If STARTP is unchanged, move it down another screen line. */
14791 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
14792 move_it_by_lines (&it
, 1);
14793 startp
= it
.current
.pos
;
14797 struct text_pos scroll_margin_pos
= startp
;
14800 /* See if point is inside the scroll margin at the top of the
14802 if (this_scroll_margin
)
14806 start_display (&it
, w
, startp
);
14807 y_start
= it
.current_y
;
14808 move_it_vertically (&it
, this_scroll_margin
);
14809 scroll_margin_pos
= it
.current
.pos
;
14810 /* If we didn't move enough before hitting ZV, request
14811 additional amount of scroll, to move point out of the
14813 if (IT_CHARPOS (it
) == ZV
14814 && it
.current_y
- y_start
< this_scroll_margin
)
14815 y_offset
= this_scroll_margin
- (it
.current_y
- y_start
);
14818 if (PT
< CHARPOS (scroll_margin_pos
))
14820 /* Point is in the scroll margin at the top of the window or
14821 above what is displayed in the window. */
14824 /* Compute the vertical distance from PT to the scroll
14825 margin position. Move as far as scroll_max allows, or
14826 one screenful, or 10 screen lines, whichever is largest.
14827 Give up if distance is greater than scroll_max or if we
14828 didn't reach the scroll margin position. */
14829 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
14830 start_display (&it
, w
, pos
);
14832 y_to_move
= max (it
.last_visible_y
,
14833 max (scroll_max
, 10 * frame_line_height
));
14834 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
14836 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
14837 dy
= it
.current_y
- y0
;
14838 if (dy
> scroll_max
14839 || IT_CHARPOS (it
) < CHARPOS (scroll_margin_pos
))
14840 return SCROLLING_FAILED
;
14842 /* Additional scroll for when ZV was too close to point. */
14845 /* Compute new window start. */
14846 start_display (&it
, w
, startp
);
14848 if (arg_scroll_conservatively
)
14849 amount_to_scroll
= max (dy
, frame_line_height
*
14850 max (scroll_step
, temp_scroll_step
));
14851 else if (scroll_step
|| temp_scroll_step
)
14852 amount_to_scroll
= scroll_max
;
14855 aggressive
= BVAR (current_buffer
, scroll_down_aggressively
);
14856 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14857 if (NUMBERP (aggressive
))
14859 double float_amount
= XFLOATINT (aggressive
) * height
;
14860 int aggressive_scroll
= float_amount
;
14861 if (aggressive_scroll
== 0 && float_amount
> 0)
14862 aggressive_scroll
= 1;
14863 /* Don't let point enter the scroll margin near
14864 bottom of the window, if the value of
14865 scroll_down_aggressively happens to be too
14867 if (aggressive_scroll
+ 2*this_scroll_margin
> height
)
14868 aggressive_scroll
= height
- 2*this_scroll_margin
;
14869 amount_to_scroll
= dy
+ aggressive_scroll
;
14873 if (amount_to_scroll
<= 0)
14874 return SCROLLING_FAILED
;
14876 move_it_vertically_backward (&it
, amount_to_scroll
);
14877 startp
= it
.current
.pos
;
14881 /* Run window scroll functions. */
14882 startp
= run_window_scroll_functions (window
, startp
);
14884 /* Display the window. Give up if new fonts are loaded, or if point
14886 if (!try_window (window
, startp
, 0))
14887 rc
= SCROLLING_NEED_LARGER_MATRICES
;
14888 else if (w
->cursor
.vpos
< 0)
14890 clear_glyph_matrix (w
->desired_matrix
);
14891 rc
= SCROLLING_FAILED
;
14895 /* Maybe forget recorded base line for line number display. */
14896 if (!just_this_one_p
14897 || current_buffer
->clip_changed
14898 || BEG_UNCHANGED
< CHARPOS (startp
))
14899 w
->base_line_number
= 0;
14901 /* If cursor ends up on a partially visible line,
14902 treat that as being off the bottom of the screen. */
14903 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0)
14904 /* It's possible that the cursor is on the first line of the
14905 buffer, which is partially obscured due to a vscroll
14906 (Bug#7537). In that case, avoid looping forever . */
14907 && extra_scroll_margin_lines
< w
->desired_matrix
->nrows
- 1)
14909 clear_glyph_matrix (w
->desired_matrix
);
14910 ++extra_scroll_margin_lines
;
14913 rc
= SCROLLING_SUCCESS
;
14920 /* Compute a suitable window start for window W if display of W starts
14921 on a continuation line. Value is non-zero if a new window start
14924 The new window start will be computed, based on W's width, starting
14925 from the start of the continued line. It is the start of the
14926 screen line with the minimum distance from the old start W->start. */
14929 compute_window_start_on_continuation_line (struct window
*w
)
14931 struct text_pos pos
, start_pos
;
14932 int window_start_changed_p
= 0;
14934 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
14936 /* If window start is on a continuation line... Window start may be
14937 < BEGV in case there's invisible text at the start of the
14938 buffer (M-x rmail, for example). */
14939 if (CHARPOS (start_pos
) > BEGV
14940 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
14943 struct glyph_row
*row
;
14945 /* Handle the case that the window start is out of range. */
14946 if (CHARPOS (start_pos
) < BEGV
)
14947 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
14948 else if (CHARPOS (start_pos
) > ZV
)
14949 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
14951 /* Find the start of the continued line. This should be fast
14952 because find_newline is fast (newline cache). */
14953 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
14954 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
14955 row
, DEFAULT_FACE_ID
);
14956 reseat_at_previous_visible_line_start (&it
);
14958 /* If the line start is "too far" away from the window start,
14959 say it takes too much time to compute a new window start. */
14960 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
14961 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
14963 int min_distance
, distance
;
14965 /* Move forward by display lines to find the new window
14966 start. If window width was enlarged, the new start can
14967 be expected to be > the old start. If window width was
14968 decreased, the new window start will be < the old start.
14969 So, we're looking for the display line start with the
14970 minimum distance from the old window start. */
14971 pos
= it
.current
.pos
;
14972 min_distance
= INFINITY
;
14973 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
14974 distance
< min_distance
)
14976 min_distance
= distance
;
14977 pos
= it
.current
.pos
;
14978 move_it_by_lines (&it
, 1);
14981 /* Set the window start there. */
14982 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
14983 window_start_changed_p
= 1;
14987 return window_start_changed_p
;
14991 /* Try cursor movement in case text has not changed in window WINDOW,
14992 with window start STARTP. Value is
14994 CURSOR_MOVEMENT_SUCCESS if successful
14996 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
14998 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
14999 display. *SCROLL_STEP is set to 1, under certain circumstances, if
15000 we want to scroll as if scroll-step were set to 1. See the code.
15002 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
15003 which case we have to abort this redisplay, and adjust matrices
15008 CURSOR_MOVEMENT_SUCCESS
,
15009 CURSOR_MOVEMENT_CANNOT_BE_USED
,
15010 CURSOR_MOVEMENT_MUST_SCROLL
,
15011 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
15015 try_cursor_movement (Lisp_Object window
, struct text_pos startp
, int *scroll_step
)
15017 struct window
*w
= XWINDOW (window
);
15018 struct frame
*f
= XFRAME (w
->frame
);
15019 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
15022 if (inhibit_try_cursor_movement
)
15026 /* Previously, there was a check for Lisp integer in the
15027 if-statement below. Now, this field is converted to
15028 ptrdiff_t, thus zero means invalid position in a buffer. */
15029 eassert (w
->last_point
> 0);
15030 /* Likewise there was a check whether window_end_vpos is nil or larger
15031 than the window. Now window_end_vpos is int and so never nil, but
15032 let's leave eassert to check whether it fits in the window. */
15033 eassert (w
->window_end_vpos
< w
->current_matrix
->nrows
);
15035 /* Handle case where text has not changed, only point, and it has
15036 not moved off the frame. */
15037 if (/* Point may be in this window. */
15038 PT
>= CHARPOS (startp
)
15039 /* Selective display hasn't changed. */
15040 && !current_buffer
->clip_changed
15041 /* Function force-mode-line-update is used to force a thorough
15042 redisplay. It sets either windows_or_buffers_changed or
15043 update_mode_lines. So don't take a shortcut here for these
15045 && !update_mode_lines
15046 && !windows_or_buffers_changed
15047 && !cursor_type_changed
15048 /* Can't use this case if highlighting a region. When a
15049 region exists, cursor movement has to do more than just
15051 && markpos_of_region () < 0
15052 && !w
->region_showing
15053 && NILP (Vshow_trailing_whitespace
)
15054 /* This code is not used for mini-buffer for the sake of the case
15055 of redisplaying to replace an echo area message; since in
15056 that case the mini-buffer contents per se are usually
15057 unchanged. This code is of no real use in the mini-buffer
15058 since the handling of this_line_start_pos, etc., in redisplay
15059 handles the same cases. */
15060 && !EQ (window
, minibuf_window
)
15061 && (FRAME_WINDOW_P (f
)
15062 || !overlay_arrow_in_current_buffer_p ()))
15064 int this_scroll_margin
, top_scroll_margin
;
15065 struct glyph_row
*row
= NULL
;
15066 int frame_line_height
= default_line_pixel_height (w
);
15067 int window_total_lines
15068 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
15071 debug_method_add (w
, "cursor movement");
15074 /* Scroll if point within this distance from the top or bottom
15075 of the window. This is a pixel value. */
15076 if (scroll_margin
> 0)
15078 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4);
15079 this_scroll_margin
*= frame_line_height
;
15082 this_scroll_margin
= 0;
15084 top_scroll_margin
= this_scroll_margin
;
15085 if (WINDOW_WANTS_HEADER_LINE_P (w
))
15086 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
15088 /* Start with the row the cursor was displayed during the last
15089 not paused redisplay. Give up if that row is not valid. */
15090 if (w
->last_cursor
.vpos
< 0
15091 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
15092 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15095 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
15096 if (row
->mode_line_p
)
15098 if (!row
->enabled_p
)
15099 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15102 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
15104 int scroll_p
= 0, must_scroll
= 0;
15105 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
15107 if (PT
> w
->last_point
)
15109 /* Point has moved forward. */
15110 while (MATRIX_ROW_END_CHARPOS (row
) < PT
15111 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
15113 eassert (row
->enabled_p
);
15117 /* If the end position of a row equals the start
15118 position of the next row, and PT is at that position,
15119 we would rather display cursor in the next line. */
15120 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15121 && MATRIX_ROW_END_CHARPOS (row
) == PT
15122 && row
< MATRIX_MODE_LINE_ROW (w
->current_matrix
)
15123 && MATRIX_ROW_START_CHARPOS (row
+1) == PT
15124 && !cursor_row_p (row
))
15127 /* If within the scroll margin, scroll. Note that
15128 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
15129 the next line would be drawn, and that
15130 this_scroll_margin can be zero. */
15131 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
15132 || PT
> MATRIX_ROW_END_CHARPOS (row
)
15133 /* Line is completely visible last line in window
15134 and PT is to be set in the next line. */
15135 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
15136 && PT
== MATRIX_ROW_END_CHARPOS (row
)
15137 && !row
->ends_at_zv_p
15138 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
15141 else if (PT
< w
->last_point
)
15143 /* Cursor has to be moved backward. Note that PT >=
15144 CHARPOS (startp) because of the outer if-statement. */
15145 while (!row
->mode_line_p
15146 && (MATRIX_ROW_START_CHARPOS (row
) > PT
15147 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15148 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
15149 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
15150 row
> w
->current_matrix
->rows
15151 && (row
-1)->ends_in_newline_from_string_p
))))
15152 && (row
->y
> top_scroll_margin
15153 || CHARPOS (startp
) == BEGV
))
15155 eassert (row
->enabled_p
);
15159 /* Consider the following case: Window starts at BEGV,
15160 there is invisible, intangible text at BEGV, so that
15161 display starts at some point START > BEGV. It can
15162 happen that we are called with PT somewhere between
15163 BEGV and START. Try to handle that case. */
15164 if (row
< w
->current_matrix
->rows
15165 || row
->mode_line_p
)
15167 row
= w
->current_matrix
->rows
;
15168 if (row
->mode_line_p
)
15172 /* Due to newlines in overlay strings, we may have to
15173 skip forward over overlay strings. */
15174 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15175 && MATRIX_ROW_END_CHARPOS (row
) == PT
15176 && !cursor_row_p (row
))
15179 /* If within the scroll margin, scroll. */
15180 if (row
->y
< top_scroll_margin
15181 && CHARPOS (startp
) != BEGV
)
15186 /* Cursor did not move. So don't scroll even if cursor line
15187 is partially visible, as it was so before. */
15188 rc
= CURSOR_MOVEMENT_SUCCESS
;
15191 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
15192 || PT
> MATRIX_ROW_END_CHARPOS (row
))
15194 /* if PT is not in the glyph row, give up. */
15195 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15198 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15199 && !NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
15201 struct glyph_row
*row1
;
15203 /* If rows are bidi-reordered and point moved, back up
15204 until we find a row that does not belong to a
15205 continuation line. This is because we must consider
15206 all rows of a continued line as candidates for the
15207 new cursor positioning, since row start and end
15208 positions change non-linearly with vertical position
15210 /* FIXME: Revisit this when glyph ``spilling'' in
15211 continuation lines' rows is implemented for
15212 bidi-reordered rows. */
15213 for (row1
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15214 MATRIX_ROW_CONTINUATION_LINE_P (row
);
15217 /* If we hit the beginning of the displayed portion
15218 without finding the first row of a continued
15222 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15225 eassert (row
->enabled_p
);
15230 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15231 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
15232 /* Make sure this isn't a header line by any chance, since
15233 then MATRIX_ROW_PARTIALLY_VISIBLE_P might yield non-zero. */
15234 && !row
->mode_line_p
15235 && make_cursor_line_fully_visible_p
)
15237 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
15238 && !row
->ends_at_zv_p
15239 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15240 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15241 else if (row
->height
> window_box_height (w
))
15243 /* If we end up in a partially visible line, let's
15244 make it fully visible, except when it's taller
15245 than the window, in which case we can't do much
15248 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15252 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15253 if (!cursor_row_fully_visible_p (w
, 0, 1))
15254 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15256 rc
= CURSOR_MOVEMENT_SUCCESS
;
15260 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15261 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15262 && !NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
15264 /* With bidi-reordered rows, there could be more than
15265 one candidate row whose start and end positions
15266 occlude point. We need to let set_cursor_from_row
15267 find the best candidate. */
15268 /* FIXME: Revisit this when glyph ``spilling'' in
15269 continuation lines' rows is implemented for
15270 bidi-reordered rows. */
15275 int at_zv_p
= 0, exact_match_p
= 0;
15277 if (MATRIX_ROW_START_CHARPOS (row
) <= PT
15278 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
15279 && cursor_row_p (row
))
15280 rv
|= set_cursor_from_row (w
, row
, w
->current_matrix
,
15282 /* As soon as we've found the exact match for point,
15283 or the first suitable row whose ends_at_zv_p flag
15284 is set, we are done. */
15286 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
)->ends_at_zv_p
;
15288 && w
->cursor
.hpos
>= 0
15289 && w
->cursor
.hpos
< MATRIX_ROW_USED (w
->current_matrix
,
15292 struct glyph_row
*candidate
=
15293 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
15295 candidate
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
15296 ptrdiff_t endpos
= MATRIX_ROW_END_CHARPOS (candidate
);
15299 (BUFFERP (g
->object
) && g
->charpos
== PT
)
15300 || (INTEGERP (g
->object
)
15301 && (g
->charpos
== PT
15302 || (g
->charpos
== 0 && endpos
- 1 == PT
)));
15304 if (rv
&& (at_zv_p
|| exact_match_p
))
15306 rc
= CURSOR_MOVEMENT_SUCCESS
;
15309 if (MATRIX_ROW_BOTTOM_Y (row
) == last_y
)
15313 while (((MATRIX_ROW_CONTINUATION_LINE_P (row
)
15314 || row
->continued_p
)
15315 && MATRIX_ROW_BOTTOM_Y (row
) <= last_y
)
15316 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15317 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
));
15318 /* If we didn't find any candidate rows, or exited the
15319 loop before all the candidates were examined, signal
15320 to the caller that this method failed. */
15321 if (rc
!= CURSOR_MOVEMENT_SUCCESS
15323 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
15324 && !row
->continued_p
))
15325 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15327 rc
= CURSOR_MOVEMENT_SUCCESS
;
15333 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
15335 rc
= CURSOR_MOVEMENT_SUCCESS
;
15340 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15341 && MATRIX_ROW_START_CHARPOS (row
) == PT
15342 && cursor_row_p (row
));
15350 #if !defined USE_TOOLKIT_SCROLL_BARS || defined USE_GTK
15354 set_vertical_scroll_bar (struct window
*w
)
15356 ptrdiff_t start
, end
, whole
;
15358 /* Calculate the start and end positions for the current window.
15359 At some point, it would be nice to choose between scrollbars
15360 which reflect the whole buffer size, with special markers
15361 indicating narrowing, and scrollbars which reflect only the
15364 Note that mini-buffers sometimes aren't displaying any text. */
15365 if (!MINI_WINDOW_P (w
)
15366 || (w
== XWINDOW (minibuf_window
)
15367 && NILP (echo_area_buffer
[0])))
15369 struct buffer
*buf
= XBUFFER (w
->contents
);
15370 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
15371 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
15372 /* I don't think this is guaranteed to be right. For the
15373 moment, we'll pretend it is. */
15374 end
= BUF_Z (buf
) - w
->window_end_pos
- BUF_BEGV (buf
);
15378 if (whole
< (end
- start
))
15379 whole
= end
- start
;
15382 start
= end
= whole
= 0;
15384 /* Indicate what this scroll bar ought to be displaying now. */
15385 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15386 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15387 (w
, end
- start
, whole
, start
);
15391 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
15392 selected_window is redisplayed.
15394 We can return without actually redisplaying the window if
15395 fonts_changed_p. In that case, redisplay_internal will
15399 redisplay_window (Lisp_Object window
, int just_this_one_p
)
15401 struct window
*w
= XWINDOW (window
);
15402 struct frame
*f
= XFRAME (w
->frame
);
15403 struct buffer
*buffer
= XBUFFER (w
->contents
);
15404 struct buffer
*old
= current_buffer
;
15405 struct text_pos lpoint
, opoint
, startp
;
15406 int update_mode_line
;
15409 /* Record it now because it's overwritten. */
15410 int current_matrix_up_to_date_p
= 0;
15411 int used_current_matrix_p
= 0;
15412 /* This is less strict than current_matrix_up_to_date_p.
15413 It indicates that the buffer contents and narrowing are unchanged. */
15414 int buffer_unchanged_p
= 0;
15415 int temp_scroll_step
= 0;
15416 ptrdiff_t count
= SPECPDL_INDEX ();
15418 int centering_position
= -1;
15419 int last_line_misfit
= 0;
15420 ptrdiff_t beg_unchanged
, end_unchanged
;
15421 int frame_line_height
;
15423 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15427 *w
->desired_matrix
->method
= 0;
15430 /* Make sure that both W's markers are valid. */
15431 eassert (XMARKER (w
->start
)->buffer
== buffer
);
15432 eassert (XMARKER (w
->pointm
)->buffer
== buffer
);
15435 reconsider_clip_changes (w
);
15436 frame_line_height
= default_line_pixel_height (w
);
15438 /* Has the mode line to be updated? */
15439 update_mode_line
= (w
->update_mode_line
15440 || update_mode_lines
15441 || buffer
->clip_changed
15442 || buffer
->prevent_redisplay_optimizations_p
);
15444 if (MINI_WINDOW_P (w
))
15446 if (w
== XWINDOW (echo_area_window
)
15447 && !NILP (echo_area_buffer
[0]))
15449 if (update_mode_line
)
15450 /* We may have to update a tty frame's menu bar or a
15451 tool-bar. Example `M-x C-h C-h C-g'. */
15452 goto finish_menu_bars
;
15454 /* We've already displayed the echo area glyphs in this window. */
15455 goto finish_scroll_bars
;
15457 else if ((w
!= XWINDOW (minibuf_window
)
15458 || minibuf_level
== 0)
15459 /* When buffer is nonempty, redisplay window normally. */
15460 && BUF_Z (XBUFFER (w
->contents
)) == BUF_BEG (XBUFFER (w
->contents
))
15461 /* Quail displays non-mini buffers in minibuffer window.
15462 In that case, redisplay the window normally. */
15463 && !NILP (Fmemq (w
->contents
, Vminibuffer_list
)))
15465 /* W is a mini-buffer window, but it's not active, so clear
15467 int yb
= window_text_bottom_y (w
);
15468 struct glyph_row
*row
;
15471 for (y
= 0, row
= w
->desired_matrix
->rows
;
15473 y
+= row
->height
, ++row
)
15474 blank_row (w
, row
, y
);
15475 goto finish_scroll_bars
;
15478 clear_glyph_matrix (w
->desired_matrix
);
15481 /* Otherwise set up data on this window; select its buffer and point
15483 /* Really select the buffer, for the sake of buffer-local
15485 set_buffer_internal_1 (XBUFFER (w
->contents
));
15487 current_matrix_up_to_date_p
15488 = (w
->window_end_valid
15489 && !current_buffer
->clip_changed
15490 && !current_buffer
->prevent_redisplay_optimizations_p
15491 && !window_outdated (w
));
15493 /* Run the window-bottom-change-functions
15494 if it is possible that the text on the screen has changed
15495 (either due to modification of the text, or any other reason). */
15496 if (!current_matrix_up_to_date_p
15497 && !NILP (Vwindow_text_change_functions
))
15499 safe_run_hooks (Qwindow_text_change_functions
);
15503 beg_unchanged
= BEG_UNCHANGED
;
15504 end_unchanged
= END_UNCHANGED
;
15506 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
15508 specbind (Qinhibit_point_motion_hooks
, Qt
);
15511 = (w
->window_end_valid
15512 && !current_buffer
->clip_changed
15513 && !window_outdated (w
));
15515 /* When windows_or_buffers_changed is non-zero, we can't rely on
15516 the window end being valid, so set it to nil there. */
15517 if (windows_or_buffers_changed
)
15519 /* If window starts on a continuation line, maybe adjust the
15520 window start in case the window's width changed. */
15521 if (XMARKER (w
->start
)->buffer
== current_buffer
)
15522 compute_window_start_on_continuation_line (w
);
15524 w
->window_end_valid
= 0;
15527 /* Some sanity checks. */
15528 CHECK_WINDOW_END (w
);
15529 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
15531 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
15534 if (mode_line_update_needed (w
))
15535 update_mode_line
= 1;
15537 /* Point refers normally to the selected window. For any other
15538 window, set up appropriate value. */
15539 if (!EQ (window
, selected_window
))
15541 ptrdiff_t new_pt
= marker_position (w
->pointm
);
15542 ptrdiff_t new_pt_byte
= marker_byte_position (w
->pointm
);
15546 new_pt_byte
= BEGV_BYTE
;
15547 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
15549 else if (new_pt
> (ZV
- 1))
15552 new_pt_byte
= ZV_BYTE
;
15553 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
15556 /* We don't use SET_PT so that the point-motion hooks don't run. */
15557 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
15560 /* If any of the character widths specified in the display table
15561 have changed, invalidate the width run cache. It's true that
15562 this may be a bit late to catch such changes, but the rest of
15563 redisplay goes (non-fatally) haywire when the display table is
15564 changed, so why should we worry about doing any better? */
15565 if (current_buffer
->width_run_cache
)
15567 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
15569 if (! disptab_matches_widthtab
15570 (disptab
, XVECTOR (BVAR (current_buffer
, width_table
))))
15572 invalidate_region_cache (current_buffer
,
15573 current_buffer
->width_run_cache
,
15575 recompute_width_table (current_buffer
, disptab
);
15579 /* If window-start is screwed up, choose a new one. */
15580 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
15583 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15585 /* If someone specified a new starting point but did not insist,
15586 check whether it can be used. */
15587 if (w
->optional_new_start
15588 && CHARPOS (startp
) >= BEGV
15589 && CHARPOS (startp
) <= ZV
)
15591 w
->optional_new_start
= 0;
15592 start_display (&it
, w
, startp
);
15593 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
15594 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15595 if (IT_CHARPOS (it
) == PT
)
15596 w
->force_start
= 1;
15597 /* IT may overshoot PT if text at PT is invisible. */
15598 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
15599 w
->force_start
= 1;
15604 /* Handle case where place to start displaying has been specified,
15605 unless the specified location is outside the accessible range. */
15606 if (w
->force_start
|| window_frozen_p (w
))
15608 /* We set this later on if we have to adjust point. */
15611 w
->force_start
= 0;
15613 w
->window_end_valid
= 0;
15615 /* Forget any recorded base line for line number display. */
15616 if (!buffer_unchanged_p
)
15617 w
->base_line_number
= 0;
15619 /* Redisplay the mode line. Select the buffer properly for that.
15620 Also, run the hook window-scroll-functions
15621 because we have scrolled. */
15622 /* Note, we do this after clearing force_start because
15623 if there's an error, it is better to forget about force_start
15624 than to get into an infinite loop calling the hook functions
15625 and having them get more errors. */
15626 if (!update_mode_line
15627 || ! NILP (Vwindow_scroll_functions
))
15629 update_mode_line
= 1;
15630 w
->update_mode_line
= 1;
15631 startp
= run_window_scroll_functions (window
, startp
);
15634 if (CHARPOS (startp
) < BEGV
)
15635 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
15636 else if (CHARPOS (startp
) > ZV
)
15637 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
15639 /* Redisplay, then check if cursor has been set during the
15640 redisplay. Give up if new fonts were loaded. */
15641 /* We used to issue a CHECK_MARGINS argument to try_window here,
15642 but this causes scrolling to fail when point begins inside
15643 the scroll margin (bug#148) -- cyd */
15644 if (!try_window (window
, startp
, 0))
15646 w
->force_start
= 1;
15647 clear_glyph_matrix (w
->desired_matrix
);
15648 goto need_larger_matrices
;
15651 if (w
->cursor
.vpos
< 0 && !window_frozen_p (w
))
15653 /* If point does not appear, try to move point so it does
15654 appear. The desired matrix has been built above, so we
15655 can use it here. */
15656 new_vpos
= window_box_height (w
) / 2;
15659 if (!cursor_row_fully_visible_p (w
, 0, 0))
15661 /* Point does appear, but on a line partly visible at end of window.
15662 Move it back to a fully-visible line. */
15663 new_vpos
= window_box_height (w
);
15665 else if (w
->cursor
.vpos
>=0)
15667 /* Some people insist on not letting point enter the scroll
15668 margin, even though this part handles windows that didn't
15670 int window_total_lines
15671 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
15672 int margin
= min (scroll_margin
, window_total_lines
/ 4);
15673 int pixel_margin
= margin
* frame_line_height
;
15674 bool header_line
= WINDOW_WANTS_HEADER_LINE_P (w
);
15676 /* Note: We add an extra FRAME_LINE_HEIGHT, because the loop
15677 below, which finds the row to move point to, advances by
15678 the Y coordinate of the _next_ row, see the definition of
15679 MATRIX_ROW_BOTTOM_Y. */
15680 if (w
->cursor
.vpos
< margin
+ header_line
)
15682 w
->cursor
.vpos
= -1;
15683 clear_glyph_matrix (w
->desired_matrix
);
15684 goto try_to_scroll
;
15688 int window_height
= window_box_height (w
);
15691 window_height
+= CURRENT_HEADER_LINE_HEIGHT (w
);
15692 if (w
->cursor
.y
>= window_height
- pixel_margin
)
15694 w
->cursor
.vpos
= -1;
15695 clear_glyph_matrix (w
->desired_matrix
);
15696 goto try_to_scroll
;
15701 /* If we need to move point for either of the above reasons,
15702 now actually do it. */
15705 struct glyph_row
*row
;
15707 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
15708 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
15711 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
15712 MATRIX_ROW_START_BYTEPOS (row
));
15714 if (w
!= XWINDOW (selected_window
))
15715 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
15716 else if (current_buffer
== old
)
15717 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15719 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
15721 /* If we are highlighting the region, then we just changed
15722 the region, so redisplay to show it. */
15723 if (markpos_of_region () >= 0)
15725 clear_glyph_matrix (w
->desired_matrix
);
15726 if (!try_window (window
, startp
, 0))
15727 goto need_larger_matrices
;
15732 debug_method_add (w
, "forced window start");
15737 /* Handle case where text has not changed, only point, and it has
15738 not moved off the frame, and we are not retrying after hscroll.
15739 (current_matrix_up_to_date_p is nonzero when retrying.) */
15740 if (current_matrix_up_to_date_p
15741 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
15742 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
15746 case CURSOR_MOVEMENT_SUCCESS
:
15747 used_current_matrix_p
= 1;
15750 case CURSOR_MOVEMENT_MUST_SCROLL
:
15751 goto try_to_scroll
;
15757 /* If current starting point was originally the beginning of a line
15758 but no longer is, find a new starting point. */
15759 else if (w
->start_at_line_beg
15760 && !(CHARPOS (startp
) <= BEGV
15761 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
15764 debug_method_add (w
, "recenter 1");
15769 /* Try scrolling with try_window_id. Value is > 0 if update has
15770 been done, it is -1 if we know that the same window start will
15771 not work. It is 0 if unsuccessful for some other reason. */
15772 else if ((tem
= try_window_id (w
)) != 0)
15775 debug_method_add (w
, "try_window_id %d", tem
);
15778 if (fonts_changed_p
)
15779 goto need_larger_matrices
;
15783 /* Otherwise try_window_id has returned -1 which means that we
15784 don't want the alternative below this comment to execute. */
15786 else if (CHARPOS (startp
) >= BEGV
15787 && CHARPOS (startp
) <= ZV
15788 && PT
>= CHARPOS (startp
)
15789 && (CHARPOS (startp
) < ZV
15790 /* Avoid starting at end of buffer. */
15791 || CHARPOS (startp
) == BEGV
15792 || !window_outdated (w
)))
15794 int d1
, d2
, d3
, d4
, d5
, d6
;
15796 /* If first window line is a continuation line, and window start
15797 is inside the modified region, but the first change is before
15798 current window start, we must select a new window start.
15800 However, if this is the result of a down-mouse event (e.g. by
15801 extending the mouse-drag-overlay), we don't want to select a
15802 new window start, since that would change the position under
15803 the mouse, resulting in an unwanted mouse-movement rather
15804 than a simple mouse-click. */
15805 if (!w
->start_at_line_beg
15806 && NILP (do_mouse_tracking
)
15807 && CHARPOS (startp
) > BEGV
15808 && CHARPOS (startp
) > BEG
+ beg_unchanged
15809 && CHARPOS (startp
) <= Z
- end_unchanged
15810 /* Even if w->start_at_line_beg is nil, a new window may
15811 start at a line_beg, since that's how set_buffer_window
15812 sets it. So, we need to check the return value of
15813 compute_window_start_on_continuation_line. (See also
15815 && XMARKER (w
->start
)->buffer
== current_buffer
15816 && compute_window_start_on_continuation_line (w
)
15817 /* It doesn't make sense to force the window start like we
15818 do at label force_start if it is already known that point
15819 will not be visible in the resulting window, because
15820 doing so will move point from its correct position
15821 instead of scrolling the window to bring point into view.
15823 && pos_visible_p (w
, PT
, &d1
, &d2
, &d3
, &d4
, &d5
, &d6
))
15825 w
->force_start
= 1;
15826 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15831 debug_method_add (w
, "same window start");
15834 /* Try to redisplay starting at same place as before.
15835 If point has not moved off frame, accept the results. */
15836 if (!current_matrix_up_to_date_p
15837 /* Don't use try_window_reusing_current_matrix in this case
15838 because a window scroll function can have changed the
15840 || !NILP (Vwindow_scroll_functions
)
15841 || MINI_WINDOW_P (w
)
15842 || !(used_current_matrix_p
15843 = try_window_reusing_current_matrix (w
)))
15845 IF_DEBUG (debug_method_add (w
, "1"));
15846 if (try_window (window
, startp
, TRY_WINDOW_CHECK_MARGINS
) < 0)
15847 /* -1 means we need to scroll.
15848 0 means we need new matrices, but fonts_changed_p
15849 is set in that case, so we will detect it below. */
15850 goto try_to_scroll
;
15853 if (fonts_changed_p
)
15854 goto need_larger_matrices
;
15856 if (w
->cursor
.vpos
>= 0)
15858 if (!just_this_one_p
15859 || current_buffer
->clip_changed
15860 || BEG_UNCHANGED
< CHARPOS (startp
))
15861 /* Forget any recorded base line for line number display. */
15862 w
->base_line_number
= 0;
15864 if (!cursor_row_fully_visible_p (w
, 1, 0))
15866 clear_glyph_matrix (w
->desired_matrix
);
15867 last_line_misfit
= 1;
15869 /* Drop through and scroll. */
15874 clear_glyph_matrix (w
->desired_matrix
);
15879 /* Redisplay the mode line. Select the buffer properly for that. */
15880 if (!update_mode_line
)
15882 update_mode_line
= 1;
15883 w
->update_mode_line
= 1;
15886 /* Try to scroll by specified few lines. */
15887 if ((scroll_conservatively
15888 || emacs_scroll_step
15889 || temp_scroll_step
15890 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
))
15891 || NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
)))
15892 && CHARPOS (startp
) >= BEGV
15893 && CHARPOS (startp
) <= ZV
)
15895 /* The function returns -1 if new fonts were loaded, 1 if
15896 successful, 0 if not successful. */
15897 int ss
= try_scrolling (window
, just_this_one_p
,
15898 scroll_conservatively
,
15900 temp_scroll_step
, last_line_misfit
);
15903 case SCROLLING_SUCCESS
:
15906 case SCROLLING_NEED_LARGER_MATRICES
:
15907 goto need_larger_matrices
;
15909 case SCROLLING_FAILED
:
15917 /* Finally, just choose a place to start which positions point
15918 according to user preferences. */
15923 debug_method_add (w
, "recenter");
15926 /* Forget any previously recorded base line for line number display. */
15927 if (!buffer_unchanged_p
)
15928 w
->base_line_number
= 0;
15930 /* Determine the window start relative to point. */
15931 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
15932 it
.current_y
= it
.last_visible_y
;
15933 if (centering_position
< 0)
15935 int window_total_lines
15936 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
15939 ? min (scroll_margin
, window_total_lines
/ 4)
15941 ptrdiff_t margin_pos
= CHARPOS (startp
);
15942 Lisp_Object aggressive
;
15945 /* If there is a scroll margin at the top of the window, find
15946 its character position. */
15948 /* Cannot call start_display if startp is not in the
15949 accessible region of the buffer. This can happen when we
15950 have just switched to a different buffer and/or changed
15951 its restriction. In that case, startp is initialized to
15952 the character position 1 (BEGV) because we did not yet
15953 have chance to display the buffer even once. */
15954 && BEGV
<= CHARPOS (startp
) && CHARPOS (startp
) <= ZV
)
15957 void *it1data
= NULL
;
15959 SAVE_IT (it1
, it
, it1data
);
15960 start_display (&it1
, w
, startp
);
15961 move_it_vertically (&it1
, margin
* frame_line_height
);
15962 margin_pos
= IT_CHARPOS (it1
);
15963 RESTORE_IT (&it
, &it
, it1data
);
15965 scrolling_up
= PT
> margin_pos
;
15968 ? BVAR (current_buffer
, scroll_up_aggressively
)
15969 : BVAR (current_buffer
, scroll_down_aggressively
);
15971 if (!MINI_WINDOW_P (w
)
15972 && (scroll_conservatively
> SCROLL_LIMIT
|| NUMBERP (aggressive
)))
15976 /* Setting scroll-conservatively overrides
15977 scroll-*-aggressively. */
15978 if (!scroll_conservatively
&& NUMBERP (aggressive
))
15980 double float_amount
= XFLOATINT (aggressive
);
15982 pt_offset
= float_amount
* WINDOW_BOX_TEXT_HEIGHT (w
);
15983 if (pt_offset
== 0 && float_amount
> 0)
15985 if (pt_offset
&& margin
> 0)
15988 /* Compute how much to move the window start backward from
15989 point so that point will be displayed where the user
15993 centering_position
= it
.last_visible_y
;
15995 centering_position
-= pt_offset
;
15996 centering_position
-=
15997 frame_line_height
* (1 + margin
+ (last_line_misfit
!= 0))
15998 + WINDOW_HEADER_LINE_HEIGHT (w
);
15999 /* Don't let point enter the scroll margin near top of
16001 if (centering_position
< margin
* frame_line_height
)
16002 centering_position
= margin
* frame_line_height
;
16005 centering_position
= margin
* frame_line_height
+ pt_offset
;
16008 /* Set the window start half the height of the window backward
16010 centering_position
= window_box_height (w
) / 2;
16012 move_it_vertically_backward (&it
, centering_position
);
16014 eassert (IT_CHARPOS (it
) >= BEGV
);
16016 /* The function move_it_vertically_backward may move over more
16017 than the specified y-distance. If it->w is small, e.g. a
16018 mini-buffer window, we may end up in front of the window's
16019 display area. Start displaying at the start of the line
16020 containing PT in this case. */
16021 if (it
.current_y
<= 0)
16023 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
16024 move_it_vertically_backward (&it
, 0);
16028 it
.current_x
= it
.hpos
= 0;
16030 /* Set the window start position here explicitly, to avoid an
16031 infinite loop in case the functions in window-scroll-functions
16033 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
16035 /* Run scroll hooks. */
16036 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
16038 /* Redisplay the window. */
16039 if (!current_matrix_up_to_date_p
16040 || windows_or_buffers_changed
16041 || cursor_type_changed
16042 /* Don't use try_window_reusing_current_matrix in this case
16043 because it can have changed the buffer. */
16044 || !NILP (Vwindow_scroll_functions
)
16045 || !just_this_one_p
16046 || MINI_WINDOW_P (w
)
16047 || !(used_current_matrix_p
16048 = try_window_reusing_current_matrix (w
)))
16049 try_window (window
, startp
, 0);
16051 /* If new fonts have been loaded (due to fontsets), give up. We
16052 have to start a new redisplay since we need to re-adjust glyph
16054 if (fonts_changed_p
)
16055 goto need_larger_matrices
;
16057 /* If cursor did not appear assume that the middle of the window is
16058 in the first line of the window. Do it again with the next line.
16059 (Imagine a window of height 100, displaying two lines of height
16060 60. Moving back 50 from it->last_visible_y will end in the first
16062 if (w
->cursor
.vpos
< 0)
16064 if (w
->window_end_valid
&& PT
>= Z
- w
->window_end_pos
)
16066 clear_glyph_matrix (w
->desired_matrix
);
16067 move_it_by_lines (&it
, 1);
16068 try_window (window
, it
.current
.pos
, 0);
16070 else if (PT
< IT_CHARPOS (it
))
16072 clear_glyph_matrix (w
->desired_matrix
);
16073 move_it_by_lines (&it
, -1);
16074 try_window (window
, it
.current
.pos
, 0);
16078 /* Not much we can do about it. */
16082 /* Consider the following case: Window starts at BEGV, there is
16083 invisible, intangible text at BEGV, so that display starts at
16084 some point START > BEGV. It can happen that we are called with
16085 PT somewhere between BEGV and START. Try to handle that case. */
16086 if (w
->cursor
.vpos
< 0)
16088 struct glyph_row
*row
= w
->current_matrix
->rows
;
16089 if (row
->mode_line_p
)
16091 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
16094 if (!cursor_row_fully_visible_p (w
, 0, 0))
16096 /* If vscroll is enabled, disable it and try again. */
16100 clear_glyph_matrix (w
->desired_matrix
);
16104 /* Users who set scroll-conservatively to a large number want
16105 point just above/below the scroll margin. If we ended up
16106 with point's row partially visible, move the window start to
16107 make that row fully visible and out of the margin. */
16108 if (scroll_conservatively
> SCROLL_LIMIT
)
16110 int window_total_lines
16111 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) * frame_line_height
;
16114 ? min (scroll_margin
, window_total_lines
/ 4)
16116 int move_down
= w
->cursor
.vpos
>= window_total_lines
/ 2;
16118 move_it_by_lines (&it
, move_down
? margin
+ 1 : -(margin
+ 1));
16119 clear_glyph_matrix (w
->desired_matrix
);
16120 if (1 == try_window (window
, it
.current
.pos
,
16121 TRY_WINDOW_CHECK_MARGINS
))
16125 /* If centering point failed to make the whole line visible,
16126 put point at the top instead. That has to make the whole line
16127 visible, if it can be done. */
16128 if (centering_position
== 0)
16131 clear_glyph_matrix (w
->desired_matrix
);
16132 centering_position
= 0;
16138 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
16139 w
->start_at_line_beg
= (CHARPOS (startp
) == BEGV
16140 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n');
16142 /* Display the mode line, if we must. */
16143 if ((update_mode_line
16144 /* If window not full width, must redo its mode line
16145 if (a) the window to its side is being redone and
16146 (b) we do a frame-based redisplay. This is a consequence
16147 of how inverted lines are drawn in frame-based redisplay. */
16148 || (!just_this_one_p
16149 && !FRAME_WINDOW_P (f
)
16150 && !WINDOW_FULL_WIDTH_P (w
))
16151 /* Line number to display. */
16152 || w
->base_line_pos
> 0
16153 /* Column number is displayed and different from the one displayed. */
16154 || (w
->column_number_displayed
!= -1
16155 && (w
->column_number_displayed
!= current_column ())))
16156 /* This means that the window has a mode line. */
16157 && (WINDOW_WANTS_MODELINE_P (w
)
16158 || WINDOW_WANTS_HEADER_LINE_P (w
)))
16160 display_mode_lines (w
);
16162 /* If mode line height has changed, arrange for a thorough
16163 immediate redisplay using the correct mode line height. */
16164 if (WINDOW_WANTS_MODELINE_P (w
)
16165 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
16167 fonts_changed_p
= 1;
16168 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
16169 = DESIRED_MODE_LINE_HEIGHT (w
);
16172 /* If header line height has changed, arrange for a thorough
16173 immediate redisplay using the correct header line height. */
16174 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16175 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
16177 fonts_changed_p
= 1;
16178 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
16179 = DESIRED_HEADER_LINE_HEIGHT (w
);
16182 if (fonts_changed_p
)
16183 goto need_larger_matrices
;
16186 if (!line_number_displayed
&& w
->base_line_pos
!= -1)
16188 w
->base_line_pos
= 0;
16189 w
->base_line_number
= 0;
16194 /* When we reach a frame's selected window, redo the frame's menu bar. */
16195 if (update_mode_line
16196 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
16198 int redisplay_menu_p
= 0;
16200 if (FRAME_WINDOW_P (f
))
16202 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
16203 || defined (HAVE_NS) || defined (USE_GTK)
16204 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
16206 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16210 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16212 if (redisplay_menu_p
)
16213 display_menu_bar (w
);
16215 #ifdef HAVE_WINDOW_SYSTEM
16216 if (FRAME_WINDOW_P (f
))
16218 #if defined (USE_GTK) || defined (HAVE_NS)
16219 if (FRAME_EXTERNAL_TOOL_BAR (f
))
16220 redisplay_tool_bar (f
);
16222 if (WINDOWP (f
->tool_bar_window
)
16223 && (FRAME_TOOL_BAR_LINES (f
) > 0
16224 || !NILP (Vauto_resize_tool_bars
))
16225 && redisplay_tool_bar (f
))
16226 ignore_mouse_drag_p
= 1;
16232 #ifdef HAVE_WINDOW_SYSTEM
16233 if (FRAME_WINDOW_P (f
)
16234 && update_window_fringes (w
, (just_this_one_p
16235 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
16236 || w
->pseudo_window_p
)))
16240 if (draw_window_fringes (w
, 1))
16241 x_draw_vertical_border (w
);
16245 #endif /* HAVE_WINDOW_SYSTEM */
16247 /* We go to this label, with fonts_changed_p set,
16248 if it is necessary to try again using larger glyph matrices.
16249 We have to redeem the scroll bar even in this case,
16250 because the loop in redisplay_internal expects that. */
16251 need_larger_matrices
:
16253 finish_scroll_bars
:
16255 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
16257 /* Set the thumb's position and size. */
16258 set_vertical_scroll_bar (w
);
16260 /* Note that we actually used the scroll bar attached to this
16261 window, so it shouldn't be deleted at the end of redisplay. */
16262 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
16263 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
16266 /* Restore current_buffer and value of point in it. The window
16267 update may have changed the buffer, so first make sure `opoint'
16268 is still valid (Bug#6177). */
16269 if (CHARPOS (opoint
) < BEGV
)
16270 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
16271 else if (CHARPOS (opoint
) > ZV
)
16272 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
16274 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
16276 set_buffer_internal_1 (old
);
16277 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
16278 shorter. This can be caused by log truncation in *Messages*. */
16279 if (CHARPOS (lpoint
) <= ZV
)
16280 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
16282 unbind_to (count
, Qnil
);
16286 /* Build the complete desired matrix of WINDOW with a window start
16287 buffer position POS.
16289 Value is 1 if successful. It is zero if fonts were loaded during
16290 redisplay which makes re-adjusting glyph matrices necessary, and -1
16291 if point would appear in the scroll margins.
16292 (We check the former only if TRY_WINDOW_IGNORE_FONTS_CHANGE is
16293 unset in FLAGS, and the latter only if TRY_WINDOW_CHECK_MARGINS is
16297 try_window (Lisp_Object window
, struct text_pos pos
, int flags
)
16299 struct window
*w
= XWINDOW (window
);
16301 struct glyph_row
*last_text_row
= NULL
;
16302 struct frame
*f
= XFRAME (w
->frame
);
16303 int frame_line_height
= default_line_pixel_height (w
);
16305 /* Make POS the new window start. */
16306 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
16308 /* Mark cursor position as unknown. No overlay arrow seen. */
16309 w
->cursor
.vpos
= -1;
16310 overlay_arrow_seen
= 0;
16312 /* Initialize iterator and info to start at POS. */
16313 start_display (&it
, w
, pos
);
16317 /* Display all lines of W. */
16318 while (it
.current_y
< it
.last_visible_y
)
16320 if (display_line (&it
))
16321 last_text_row
= it
.glyph_row
- 1;
16322 if (fonts_changed_p
&& !(flags
& TRY_WINDOW_IGNORE_FONTS_CHANGE
))
16325 #ifdef HAVE_XWIDGETS_xxx
16326 //currently this is needed to detect xwidget movement reliably. or probably not.
16327 printf("try_window\n");
16331 /* Don't let the cursor end in the scroll margins. */
16332 if ((flags
& TRY_WINDOW_CHECK_MARGINS
)
16333 && !MINI_WINDOW_P (w
))
16335 int this_scroll_margin
;
16336 int window_total_lines
16337 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
16339 if (scroll_margin
> 0)
16341 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4);
16342 this_scroll_margin
*= frame_line_height
;
16345 this_scroll_margin
= 0;
16347 if ((w
->cursor
.y
>= 0 /* not vscrolled */
16348 && w
->cursor
.y
< this_scroll_margin
16349 && CHARPOS (pos
) > BEGV
16350 && IT_CHARPOS (it
) < ZV
)
16351 /* rms: considering make_cursor_line_fully_visible_p here
16352 seems to give wrong results. We don't want to recenter
16353 when the last line is partly visible, we want to allow
16354 that case to be handled in the usual way. */
16355 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
16357 w
->cursor
.vpos
= -1;
16358 clear_glyph_matrix (w
->desired_matrix
);
16363 /* If bottom moved off end of frame, change mode line percentage. */
16364 if (w
->window_end_pos
<= 0 && Z
!= IT_CHARPOS (it
))
16365 w
->update_mode_line
= 1;
16367 /* Set window_end_pos to the offset of the last character displayed
16368 on the window from the end of current_buffer. Set
16369 window_end_vpos to its row number. */
16372 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
16373 adjust_window_ends (w
, last_text_row
, 0);
16375 (MATRIX_ROW_DISPLAYS_TEXT_P (MATRIX_ROW (w
->desired_matrix
,
16376 w
->window_end_vpos
)));
16380 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16381 w
->window_end_pos
= Z
- ZV
;
16382 w
->window_end_vpos
= 0;
16385 /* But that is not valid info until redisplay finishes. */
16386 w
->window_end_valid
= 0;
16392 /************************************************************************
16393 Window redisplay reusing current matrix when buffer has not changed
16394 ************************************************************************/
16396 /* Try redisplay of window W showing an unchanged buffer with a
16397 different window start than the last time it was displayed by
16398 reusing its current matrix. Value is non-zero if successful.
16399 W->start is the new window start. */
16402 try_window_reusing_current_matrix (struct window
*w
)
16404 struct frame
*f
= XFRAME (w
->frame
);
16405 struct glyph_row
*bottom_row
;
16408 struct text_pos start
, new_start
;
16409 int nrows_scrolled
, i
;
16410 struct glyph_row
*last_text_row
;
16411 struct glyph_row
*last_reused_text_row
;
16412 struct glyph_row
*start_row
;
16413 int start_vpos
, min_y
, max_y
;
16416 if (inhibit_try_window_reusing
)
16420 #ifdef HAVE_XWIDGETS_xxx
16421 //currently this is needed to detect xwidget movement reliably. or probably not.
16422 printf("try_window_reusing_current_matrix\n");
16427 if (/* This function doesn't handle terminal frames. */
16428 !FRAME_WINDOW_P (f
)
16429 /* Don't try to reuse the display if windows have been split
16431 || windows_or_buffers_changed
16432 || cursor_type_changed
)
16435 /* Can't do this if region may have changed. */
16436 if (markpos_of_region () >= 0
16437 || w
->region_showing
16438 || !NILP (Vshow_trailing_whitespace
))
16441 /* If top-line visibility has changed, give up. */
16442 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16443 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
16446 /* Give up if old or new display is scrolled vertically. We could
16447 make this function handle this, but right now it doesn't. */
16448 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16449 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
16452 /* The variable new_start now holds the new window start. The old
16453 start `start' can be determined from the current matrix. */
16454 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
16455 start
= start_row
->minpos
;
16456 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16458 /* Clear the desired matrix for the display below. */
16459 clear_glyph_matrix (w
->desired_matrix
);
16461 if (CHARPOS (new_start
) <= CHARPOS (start
))
16463 /* Don't use this method if the display starts with an ellipsis
16464 displayed for invisible text. It's not easy to handle that case
16465 below, and it's certainly not worth the effort since this is
16466 not a frequent case. */
16467 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
16470 IF_DEBUG (debug_method_add (w
, "twu1"));
16472 /* Display up to a row that can be reused. The variable
16473 last_text_row is set to the last row displayed that displays
16474 text. Note that it.vpos == 0 if or if not there is a
16475 header-line; it's not the same as the MATRIX_ROW_VPOS! */
16476 start_display (&it
, w
, new_start
);
16477 w
->cursor
.vpos
= -1;
16478 last_text_row
= last_reused_text_row
= NULL
;
16480 while (it
.current_y
< it
.last_visible_y
16481 && !fonts_changed_p
)
16483 /* If we have reached into the characters in the START row,
16484 that means the line boundaries have changed. So we
16485 can't start copying with the row START. Maybe it will
16486 work to start copying with the following row. */
16487 while (IT_CHARPOS (it
) > CHARPOS (start
))
16489 /* Advance to the next row as the "start". */
16491 start
= start_row
->minpos
;
16492 /* If there are no more rows to try, or just one, give up. */
16493 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
16494 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
16495 || CHARPOS (start
) == ZV
)
16497 clear_glyph_matrix (w
->desired_matrix
);
16501 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16503 /* If we have reached alignment, we can copy the rest of the
16505 if (IT_CHARPOS (it
) == CHARPOS (start
)
16506 /* Don't accept "alignment" inside a display vector,
16507 since start_row could have started in the middle of
16508 that same display vector (thus their character
16509 positions match), and we have no way of telling if
16510 that is the case. */
16511 && it
.current
.dpvec_index
< 0)
16514 if (display_line (&it
))
16515 last_text_row
= it
.glyph_row
- 1;
16519 /* A value of current_y < last_visible_y means that we stopped
16520 at the previous window start, which in turn means that we
16521 have at least one reusable row. */
16522 if (it
.current_y
< it
.last_visible_y
)
16524 struct glyph_row
*row
;
16526 /* IT.vpos always starts from 0; it counts text lines. */
16527 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
16529 /* Find PT if not already found in the lines displayed. */
16530 if (w
->cursor
.vpos
< 0)
16532 int dy
= it
.current_y
- start_row
->y
;
16534 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16535 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
16537 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
16538 dy
, nrows_scrolled
);
16541 clear_glyph_matrix (w
->desired_matrix
);
16546 /* Scroll the display. Do it before the current matrix is
16547 changed. The problem here is that update has not yet
16548 run, i.e. part of the current matrix is not up to date.
16549 scroll_run_hook will clear the cursor, and use the
16550 current matrix to get the height of the row the cursor is
16552 run
.current_y
= start_row
->y
;
16553 run
.desired_y
= it
.current_y
;
16554 run
.height
= it
.last_visible_y
- it
.current_y
;
16556 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
16559 FRAME_RIF (f
)->update_window_begin_hook (w
);
16560 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16561 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16562 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16566 /* Shift current matrix down by nrows_scrolled lines. */
16567 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16568 rotate_matrix (w
->current_matrix
,
16570 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16573 /* Disable lines that must be updated. */
16574 for (i
= 0; i
< nrows_scrolled
; ++i
)
16575 (start_row
+ i
)->enabled_p
= 0;
16577 /* Re-compute Y positions. */
16578 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16579 max_y
= it
.last_visible_y
;
16580 for (row
= start_row
+ nrows_scrolled
;
16584 row
->y
= it
.current_y
;
16585 row
->visible_height
= row
->height
;
16587 if (row
->y
< min_y
)
16588 row
->visible_height
-= min_y
- row
->y
;
16589 if (row
->y
+ row
->height
> max_y
)
16590 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16591 if (row
->fringe_bitmap_periodic_p
)
16592 row
->redraw_fringe_bitmaps_p
= 1;
16594 it
.current_y
+= row
->height
;
16596 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16597 last_reused_text_row
= row
;
16598 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
16602 /* Disable lines in the current matrix which are now
16603 below the window. */
16604 for (++row
; row
< bottom_row
; ++row
)
16605 row
->enabled_p
= row
->mode_line_p
= 0;
16608 /* Update window_end_pos etc.; last_reused_text_row is the last
16609 reused row from the current matrix containing text, if any.
16610 The value of last_text_row is the last displayed line
16611 containing text. */
16612 if (last_reused_text_row
)
16613 adjust_window_ends (w
, last_reused_text_row
, 1);
16614 else if (last_text_row
)
16615 adjust_window_ends (w
, last_text_row
, 0);
16618 /* This window must be completely empty. */
16619 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16620 w
->window_end_pos
= Z
- ZV
;
16621 w
->window_end_vpos
= 0;
16623 w
->window_end_valid
= 0;
16625 /* Update hint: don't try scrolling again in update_window. */
16626 w
->desired_matrix
->no_scrolling_p
= 1;
16629 debug_method_add (w
, "try_window_reusing_current_matrix 1");
16633 else if (CHARPOS (new_start
) > CHARPOS (start
))
16635 struct glyph_row
*pt_row
, *row
;
16636 struct glyph_row
*first_reusable_row
;
16637 struct glyph_row
*first_row_to_display
;
16639 int yb
= window_text_bottom_y (w
);
16641 /* Find the row starting at new_start, if there is one. Don't
16642 reuse a partially visible line at the end. */
16643 first_reusable_row
= start_row
;
16644 while (first_reusable_row
->enabled_p
16645 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
16646 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16647 < CHARPOS (new_start
)))
16648 ++first_reusable_row
;
16650 /* Give up if there is no row to reuse. */
16651 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
16652 || !first_reusable_row
->enabled_p
16653 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16654 != CHARPOS (new_start
)))
16657 /* We can reuse fully visible rows beginning with
16658 first_reusable_row to the end of the window. Set
16659 first_row_to_display to the first row that cannot be reused.
16660 Set pt_row to the row containing point, if there is any. */
16662 for (first_row_to_display
= first_reusable_row
;
16663 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
16664 ++first_row_to_display
)
16666 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
16667 && (PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16668 || (PT
== MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16669 && first_row_to_display
->ends_at_zv_p
16670 && pt_row
== NULL
)))
16671 pt_row
= first_row_to_display
;
16674 /* Start displaying at the start of first_row_to_display. */
16675 eassert (first_row_to_display
->y
< yb
);
16676 init_to_row_start (&it
, w
, first_row_to_display
);
16678 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
16680 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
16682 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
16683 + WINDOW_HEADER_LINE_HEIGHT (w
));
16685 /* Display lines beginning with first_row_to_display in the
16686 desired matrix. Set last_text_row to the last row displayed
16687 that displays text. */
16688 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
16689 if (pt_row
== NULL
)
16690 w
->cursor
.vpos
= -1;
16691 last_text_row
= NULL
;
16692 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
16693 if (display_line (&it
))
16694 last_text_row
= it
.glyph_row
- 1;
16696 /* If point is in a reused row, adjust y and vpos of the cursor
16700 w
->cursor
.vpos
-= nrows_scrolled
;
16701 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
16704 /* Give up if point isn't in a row displayed or reused. (This
16705 also handles the case where w->cursor.vpos < nrows_scrolled
16706 after the calls to display_line, which can happen with scroll
16707 margins. See bug#1295.) */
16708 if (w
->cursor
.vpos
< 0)
16710 clear_glyph_matrix (w
->desired_matrix
);
16714 /* Scroll the display. */
16715 run
.current_y
= first_reusable_row
->y
;
16716 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16717 run
.height
= it
.last_visible_y
- run
.current_y
;
16718 dy
= run
.current_y
- run
.desired_y
;
16723 FRAME_RIF (f
)->update_window_begin_hook (w
);
16724 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16725 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16726 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16730 /* Adjust Y positions of reused rows. */
16731 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16732 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16733 max_y
= it
.last_visible_y
;
16734 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
16737 row
->visible_height
= row
->height
;
16738 if (row
->y
< min_y
)
16739 row
->visible_height
-= min_y
- row
->y
;
16740 if (row
->y
+ row
->height
> max_y
)
16741 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16742 if (row
->fringe_bitmap_periodic_p
)
16743 row
->redraw_fringe_bitmaps_p
= 1;
16746 /* Scroll the current matrix. */
16747 eassert (nrows_scrolled
> 0);
16748 rotate_matrix (w
->current_matrix
,
16750 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16753 /* Disable rows not reused. */
16754 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
16755 row
->enabled_p
= 0;
16757 /* Point may have moved to a different line, so we cannot assume that
16758 the previous cursor position is valid; locate the correct row. */
16761 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
16763 && PT
>= MATRIX_ROW_END_CHARPOS (row
)
16764 && !row
->ends_at_zv_p
;
16768 w
->cursor
.y
= row
->y
;
16770 if (row
< bottom_row
)
16772 /* Can't simply scan the row for point with
16773 bidi-reordered glyph rows. Let set_cursor_from_row
16774 figure out where to put the cursor, and if it fails,
16776 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
16778 if (!set_cursor_from_row (w
, row
, w
->current_matrix
,
16781 clear_glyph_matrix (w
->desired_matrix
);
16787 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
16788 struct glyph
*end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16791 && (!BUFFERP (glyph
->object
)
16792 || glyph
->charpos
< PT
);
16796 w
->cursor
.x
+= glyph
->pixel_width
;
16802 /* Adjust window end. A null value of last_text_row means that
16803 the window end is in reused rows which in turn means that
16804 only its vpos can have changed. */
16806 adjust_window_ends (w
, last_text_row
, 0);
16808 w
->window_end_vpos
-= nrows_scrolled
;
16810 w
->window_end_valid
= 0;
16811 w
->desired_matrix
->no_scrolling_p
= 1;
16814 debug_method_add (w
, "try_window_reusing_current_matrix 2");
16824 /************************************************************************
16825 Window redisplay reusing current matrix when buffer has changed
16826 ************************************************************************/
16828 static struct glyph_row
*find_last_unchanged_at_beg_row (struct window
*);
16829 static struct glyph_row
*find_first_unchanged_at_end_row (struct window
*,
16830 ptrdiff_t *, ptrdiff_t *);
16831 static struct glyph_row
*
16832 find_last_row_displaying_text (struct glyph_matrix
*, struct it
*,
16833 struct glyph_row
*);
16836 /* Return the last row in MATRIX displaying text. If row START is
16837 non-null, start searching with that row. IT gives the dimensions
16838 of the display. Value is null if matrix is empty; otherwise it is
16839 a pointer to the row found. */
16841 static struct glyph_row
*
16842 find_last_row_displaying_text (struct glyph_matrix
*matrix
, struct it
*it
,
16843 struct glyph_row
*start
)
16845 struct glyph_row
*row
, *row_found
;
16847 /* Set row_found to the last row in IT->w's current matrix
16848 displaying text. The loop looks funny but think of partially
16851 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
16852 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16854 eassert (row
->enabled_p
);
16856 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
16865 /* Return the last row in the current matrix of W that is not affected
16866 by changes at the start of current_buffer that occurred since W's
16867 current matrix was built. Value is null if no such row exists.
16869 BEG_UNCHANGED us the number of characters unchanged at the start of
16870 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
16871 first changed character in current_buffer. Characters at positions <
16872 BEG + BEG_UNCHANGED are at the same buffer positions as they were
16873 when the current matrix was built. */
16875 static struct glyph_row
*
16876 find_last_unchanged_at_beg_row (struct window
*w
)
16878 ptrdiff_t first_changed_pos
= BEG
+ BEG_UNCHANGED
;
16879 struct glyph_row
*row
;
16880 struct glyph_row
*row_found
= NULL
;
16881 int yb
= window_text_bottom_y (w
);
16883 /* Find the last row displaying unchanged text. */
16884 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16885 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
16886 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
16889 if (/* If row ends before first_changed_pos, it is unchanged,
16890 except in some case. */
16891 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
16892 /* When row ends in ZV and we write at ZV it is not
16894 && !row
->ends_at_zv_p
16895 /* When first_changed_pos is the end of a continued line,
16896 row is not unchanged because it may be no longer
16898 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
16899 && (row
->continued_p
16900 || row
->exact_window_width_line_p
))
16901 /* If ROW->end is beyond ZV, then ROW->end is outdated and
16902 needs to be recomputed, so don't consider this row as
16903 unchanged. This happens when the last line was
16904 bidi-reordered and was killed immediately before this
16905 redisplay cycle. In that case, ROW->end stores the
16906 buffer position of the first visual-order character of
16907 the killed text, which is now beyond ZV. */
16908 && CHARPOS (row
->end
.pos
) <= ZV
)
16911 /* Stop if last visible row. */
16912 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
16920 /* Find the first glyph row in the current matrix of W that is not
16921 affected by changes at the end of current_buffer since the
16922 time W's current matrix was built.
16924 Return in *DELTA the number of chars by which buffer positions in
16925 unchanged text at the end of current_buffer must be adjusted.
16927 Return in *DELTA_BYTES the corresponding number of bytes.
16929 Value is null if no such row exists, i.e. all rows are affected by
16932 static struct glyph_row
*
16933 find_first_unchanged_at_end_row (struct window
*w
,
16934 ptrdiff_t *delta
, ptrdiff_t *delta_bytes
)
16936 struct glyph_row
*row
;
16937 struct glyph_row
*row_found
= NULL
;
16939 *delta
= *delta_bytes
= 0;
16941 /* Display must not have been paused, otherwise the current matrix
16942 is not up to date. */
16943 eassert (w
->window_end_valid
);
16945 /* A value of window_end_pos >= END_UNCHANGED means that the window
16946 end is in the range of changed text. If so, there is no
16947 unchanged row at the end of W's current matrix. */
16948 if (w
->window_end_pos
>= END_UNCHANGED
)
16951 /* Set row to the last row in W's current matrix displaying text. */
16952 row
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
16954 /* If matrix is entirely empty, no unchanged row exists. */
16955 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16957 /* The value of row is the last glyph row in the matrix having a
16958 meaningful buffer position in it. The end position of row
16959 corresponds to window_end_pos. This allows us to translate
16960 buffer positions in the current matrix to current buffer
16961 positions for characters not in changed text. */
16963 MATRIX_ROW_END_CHARPOS (row
) + w
->window_end_pos
;
16964 ptrdiff_t Z_BYTE_old
=
16965 MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
16966 ptrdiff_t last_unchanged_pos
, last_unchanged_pos_old
;
16967 struct glyph_row
*first_text_row
16968 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16970 *delta
= Z
- Z_old
;
16971 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
16973 /* Set last_unchanged_pos to the buffer position of the last
16974 character in the buffer that has not been changed. Z is the
16975 index + 1 of the last character in current_buffer, i.e. by
16976 subtracting END_UNCHANGED we get the index of the last
16977 unchanged character, and we have to add BEG to get its buffer
16979 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
16980 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
16982 /* Search backward from ROW for a row displaying a line that
16983 starts at a minimum position >= last_unchanged_pos_old. */
16984 for (; row
> first_text_row
; --row
)
16986 /* This used to abort, but it can happen.
16987 It is ok to just stop the search instead here. KFS. */
16988 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16991 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
16996 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
17002 /* Make sure that glyph rows in the current matrix of window W
17003 reference the same glyph memory as corresponding rows in the
17004 frame's frame matrix. This function is called after scrolling W's
17005 current matrix on a terminal frame in try_window_id and
17006 try_window_reusing_current_matrix. */
17009 sync_frame_with_window_matrix_rows (struct window
*w
)
17011 struct frame
*f
= XFRAME (w
->frame
);
17012 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
17014 /* Preconditions: W must be a leaf window and full-width. Its frame
17015 must have a frame matrix. */
17016 eassert (BUFFERP (w
->contents
));
17017 eassert (WINDOW_FULL_WIDTH_P (w
));
17018 eassert (!FRAME_WINDOW_P (f
));
17020 /* If W is a full-width window, glyph pointers in W's current matrix
17021 have, by definition, to be the same as glyph pointers in the
17022 corresponding frame matrix. Note that frame matrices have no
17023 marginal areas (see build_frame_matrix). */
17024 window_row
= w
->current_matrix
->rows
;
17025 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
17026 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
17027 while (window_row
< window_row_end
)
17029 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
17030 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
17032 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
17033 frame_row
->glyphs
[TEXT_AREA
] = start
;
17034 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
17035 frame_row
->glyphs
[LAST_AREA
] = end
;
17037 /* Disable frame rows whose corresponding window rows have
17038 been disabled in try_window_id. */
17039 if (!window_row
->enabled_p
)
17040 frame_row
->enabled_p
= 0;
17042 ++window_row
, ++frame_row
;
17047 /* Find the glyph row in window W containing CHARPOS. Consider all
17048 rows between START and END (not inclusive). END null means search
17049 all rows to the end of the display area of W. Value is the row
17050 containing CHARPOS or null. */
17053 row_containing_pos (struct window
*w
, ptrdiff_t charpos
,
17054 struct glyph_row
*start
, struct glyph_row
*end
, int dy
)
17056 struct glyph_row
*row
= start
;
17057 struct glyph_row
*best_row
= NULL
;
17058 ptrdiff_t mindif
= BUF_ZV (XBUFFER (w
->contents
)) + 1;
17061 /* If we happen to start on a header-line, skip that. */
17062 if (row
->mode_line_p
)
17065 if ((end
&& row
>= end
) || !row
->enabled_p
)
17068 last_y
= window_text_bottom_y (w
) - dy
;
17072 /* Give up if we have gone too far. */
17073 if (end
&& row
>= end
)
17075 /* This formerly returned if they were equal.
17076 I think that both quantities are of a "last plus one" type;
17077 if so, when they are equal, the row is within the screen. -- rms. */
17078 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
17081 /* If it is in this row, return this row. */
17082 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
17083 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
17084 /* The end position of a row equals the start
17085 position of the next row. If CHARPOS is there, we
17086 would rather consider it displayed in the next
17087 line, except when this line ends in ZV. */
17088 && !row_for_charpos_p (row
, charpos
)))
17089 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
17093 if (NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
17094 || (!best_row
&& !row
->continued_p
))
17096 /* In bidi-reordered rows, there could be several rows whose
17097 edges surround CHARPOS, all of these rows belonging to
17098 the same continued line. We need to find the row which
17099 fits CHARPOS the best. */
17100 for (g
= row
->glyphs
[TEXT_AREA
];
17101 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
17104 if (!STRINGP (g
->object
))
17106 if (g
->charpos
> 0 && eabs (g
->charpos
- charpos
) < mindif
)
17108 mindif
= eabs (g
->charpos
- charpos
);
17110 /* Exact match always wins. */
17117 else if (best_row
&& !row
->continued_p
)
17124 /* Try to redisplay window W by reusing its existing display. W's
17125 current matrix must be up to date when this function is called,
17126 i.e. window_end_valid must be nonzero.
17130 1 if display has been updated
17131 0 if otherwise unsuccessful
17132 -1 if redisplay with same window start is known not to succeed
17134 The following steps are performed:
17136 1. Find the last row in the current matrix of W that is not
17137 affected by changes at the start of current_buffer. If no such row
17140 2. Find the first row in W's current matrix that is not affected by
17141 changes at the end of current_buffer. Maybe there is no such row.
17143 3. Display lines beginning with the row + 1 found in step 1 to the
17144 row found in step 2 or, if step 2 didn't find a row, to the end of
17147 4. If cursor is not known to appear on the window, give up.
17149 5. If display stopped at the row found in step 2, scroll the
17150 display and current matrix as needed.
17152 6. Maybe display some lines at the end of W, if we must. This can
17153 happen under various circumstances, like a partially visible line
17154 becoming fully visible, or because newly displayed lines are displayed
17155 in smaller font sizes.
17157 7. Update W's window end information. */
17160 try_window_id (struct window
*w
)
17162 struct frame
*f
= XFRAME (w
->frame
);
17163 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
17164 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
17165 struct glyph_row
*last_unchanged_at_beg_row
;
17166 struct glyph_row
*first_unchanged_at_end_row
;
17167 struct glyph_row
*row
;
17168 struct glyph_row
*bottom_row
;
17171 ptrdiff_t delta
= 0, delta_bytes
= 0, stop_pos
;
17173 struct text_pos start_pos
;
17175 int first_unchanged_at_end_vpos
= 0;
17176 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
17177 struct text_pos start
;
17178 ptrdiff_t first_changed_charpos
, last_changed_charpos
;
17181 if (inhibit_try_window_id
)
17185 #ifdef HAVE_XWIDGETS_xxx
17186 //maybe needed for proper xwidget movement
17187 printf("try_window_id\n");
17192 /* This is handy for debugging. */
17194 #define GIVE_UP(X) \
17196 fprintf (stderr, "try_window_id give up %d\n", (X)); \
17200 #define GIVE_UP(X) return 0
17203 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
17205 /* Don't use this for mini-windows because these can show
17206 messages and mini-buffers, and we don't handle that here. */
17207 if (MINI_WINDOW_P (w
))
17210 /* This flag is used to prevent redisplay optimizations. */
17211 if (windows_or_buffers_changed
|| cursor_type_changed
)
17214 /* Verify that narrowing has not changed.
17215 Also verify that we were not told to prevent redisplay optimizations.
17216 It would be nice to further
17217 reduce the number of cases where this prevents try_window_id. */
17218 if (current_buffer
->clip_changed
17219 || current_buffer
->prevent_redisplay_optimizations_p
)
17222 /* Window must either use window-based redisplay or be full width. */
17223 if (!FRAME_WINDOW_P (f
)
17224 && (!FRAME_LINE_INS_DEL_OK (f
)
17225 || !WINDOW_FULL_WIDTH_P (w
)))
17228 /* Give up if point is known NOT to appear in W. */
17229 if (PT
< CHARPOS (start
))
17232 /* Another way to prevent redisplay optimizations. */
17233 if (w
->last_modified
== 0)
17236 /* Verify that window is not hscrolled. */
17237 if (w
->hscroll
!= 0)
17240 /* Verify that display wasn't paused. */
17241 if (!w
->window_end_valid
)
17244 /* Can't use this if highlighting a region because a cursor movement
17245 will do more than just set the cursor. */
17246 if (markpos_of_region () >= 0)
17249 /* Likewise if highlighting trailing whitespace. */
17250 if (!NILP (Vshow_trailing_whitespace
))
17253 /* Likewise if showing a region. */
17254 if (w
->region_showing
)
17257 /* Can't use this if overlay arrow position and/or string have
17259 if (overlay_arrows_changed_p ())
17262 /* When word-wrap is on, adding a space to the first word of a
17263 wrapped line can change the wrap position, altering the line
17264 above it. It might be worthwhile to handle this more
17265 intelligently, but for now just redisplay from scratch. */
17266 if (!NILP (BVAR (XBUFFER (w
->contents
), word_wrap
)))
17269 /* Under bidi reordering, adding or deleting a character in the
17270 beginning of a paragraph, before the first strong directional
17271 character, can change the base direction of the paragraph (unless
17272 the buffer specifies a fixed paragraph direction), which will
17273 require to redisplay the whole paragraph. It might be worthwhile
17274 to find the paragraph limits and widen the range of redisplayed
17275 lines to that, but for now just give up this optimization and
17276 redisplay from scratch. */
17277 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
17278 && NILP (BVAR (XBUFFER (w
->contents
), bidi_paragraph_direction
)))
17281 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
17282 only if buffer has really changed. The reason is that the gap is
17283 initially at Z for freshly visited files. The code below would
17284 set end_unchanged to 0 in that case. */
17285 if (MODIFF
> SAVE_MODIFF
17286 /* This seems to happen sometimes after saving a buffer. */
17287 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
17289 if (GPT
- BEG
< BEG_UNCHANGED
)
17290 BEG_UNCHANGED
= GPT
- BEG
;
17291 if (Z
- GPT
< END_UNCHANGED
)
17292 END_UNCHANGED
= Z
- GPT
;
17295 /* The position of the first and last character that has been changed. */
17296 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
17297 last_changed_charpos
= Z
- END_UNCHANGED
;
17299 /* If window starts after a line end, and the last change is in
17300 front of that newline, then changes don't affect the display.
17301 This case happens with stealth-fontification. Note that although
17302 the display is unchanged, glyph positions in the matrix have to
17303 be adjusted, of course. */
17304 row
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
17305 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
17306 && ((last_changed_charpos
< CHARPOS (start
)
17307 && CHARPOS (start
) == BEGV
)
17308 || (last_changed_charpos
< CHARPOS (start
) - 1
17309 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
17311 ptrdiff_t Z_old
, Z_delta
, Z_BYTE_old
, Z_delta_bytes
;
17312 struct glyph_row
*r0
;
17314 /* Compute how many chars/bytes have been added to or removed
17315 from the buffer. */
17316 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + w
->window_end_pos
;
17317 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
17318 Z_delta
= Z
- Z_old
;
17319 Z_delta_bytes
= Z_BYTE
- Z_BYTE_old
;
17321 /* Give up if PT is not in the window. Note that it already has
17322 been checked at the start of try_window_id that PT is not in
17323 front of the window start. */
17324 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + Z_delta
)
17327 /* If window start is unchanged, we can reuse the whole matrix
17328 as is, after adjusting glyph positions. No need to compute
17329 the window end again, since its offset from Z hasn't changed. */
17330 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17331 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + Z_delta
17332 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + Z_delta_bytes
17333 /* PT must not be in a partially visible line. */
17334 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + Z_delta
17335 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17337 /* Adjust positions in the glyph matrix. */
17338 if (Z_delta
|| Z_delta_bytes
)
17340 struct glyph_row
*r1
17341 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17342 increment_matrix_positions (w
->current_matrix
,
17343 MATRIX_ROW_VPOS (r0
, current_matrix
),
17344 MATRIX_ROW_VPOS (r1
, current_matrix
),
17345 Z_delta
, Z_delta_bytes
);
17348 /* Set the cursor. */
17349 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17351 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17358 /* Handle the case that changes are all below what is displayed in
17359 the window, and that PT is in the window. This shortcut cannot
17360 be taken if ZV is visible in the window, and text has been added
17361 there that is visible in the window. */
17362 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
17363 /* ZV is not visible in the window, or there are no
17364 changes at ZV, actually. */
17365 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
17366 || first_changed_charpos
== last_changed_charpos
))
17368 struct glyph_row
*r0
;
17370 /* Give up if PT is not in the window. Note that it already has
17371 been checked at the start of try_window_id that PT is not in
17372 front of the window start. */
17373 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
17376 /* If window start is unchanged, we can reuse the whole matrix
17377 as is, without changing glyph positions since no text has
17378 been added/removed in front of the window end. */
17379 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17380 if (TEXT_POS_EQUAL_P (start
, r0
->minpos
)
17381 /* PT must not be in a partially visible line. */
17382 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
17383 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17385 /* We have to compute the window end anew since text
17386 could have been added/removed after it. */
17387 w
->window_end_pos
= Z
- MATRIX_ROW_END_CHARPOS (row
);
17388 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17390 /* Set the cursor. */
17391 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17393 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17400 /* Give up if window start is in the changed area.
17402 The condition used to read
17404 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
17406 but why that was tested escapes me at the moment. */
17407 if (CHARPOS (start
) >= first_changed_charpos
17408 && CHARPOS (start
) <= last_changed_charpos
)
17411 /* Check that window start agrees with the start of the first glyph
17412 row in its current matrix. Check this after we know the window
17413 start is not in changed text, otherwise positions would not be
17415 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17416 if (!TEXT_POS_EQUAL_P (start
, row
->minpos
))
17419 /* Give up if the window ends in strings. Overlay strings
17420 at the end are difficult to handle, so don't try. */
17421 row
= MATRIX_ROW (current_matrix
, w
->window_end_vpos
);
17422 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
17425 /* Compute the position at which we have to start displaying new
17426 lines. Some of the lines at the top of the window might be
17427 reusable because they are not displaying changed text. Find the
17428 last row in W's current matrix not affected by changes at the
17429 start of current_buffer. Value is null if changes start in the
17430 first line of window. */
17431 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
17432 if (last_unchanged_at_beg_row
)
17434 /* Avoid starting to display in the middle of a character, a TAB
17435 for instance. This is easier than to set up the iterator
17436 exactly, and it's not a frequent case, so the additional
17437 effort wouldn't really pay off. */
17438 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
17439 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
17440 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
17441 --last_unchanged_at_beg_row
;
17443 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
17446 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
17448 start_pos
= it
.current
.pos
;
17450 /* Start displaying new lines in the desired matrix at the same
17451 vpos we would use in the current matrix, i.e. below
17452 last_unchanged_at_beg_row. */
17453 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
17455 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17456 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
17458 eassert (it
.hpos
== 0 && it
.current_x
== 0);
17462 /* There are no reusable lines at the start of the window.
17463 Start displaying in the first text line. */
17464 start_display (&it
, w
, start
);
17465 it
.vpos
= it
.first_vpos
;
17466 start_pos
= it
.current
.pos
;
17469 /* Find the first row that is not affected by changes at the end of
17470 the buffer. Value will be null if there is no unchanged row, in
17471 which case we must redisplay to the end of the window. delta
17472 will be set to the value by which buffer positions beginning with
17473 first_unchanged_at_end_row have to be adjusted due to text
17475 first_unchanged_at_end_row
17476 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
17477 IF_DEBUG (debug_delta
= delta
);
17478 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
17480 /* Set stop_pos to the buffer position up to which we will have to
17481 display new lines. If first_unchanged_at_end_row != NULL, this
17482 is the buffer position of the start of the line displayed in that
17483 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
17484 that we don't stop at a buffer position. */
17486 if (first_unchanged_at_end_row
)
17488 eassert (last_unchanged_at_beg_row
== NULL
17489 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
17491 /* If this is a continuation line, move forward to the next one
17492 that isn't. Changes in lines above affect this line.
17493 Caution: this may move first_unchanged_at_end_row to a row
17494 not displaying text. */
17495 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
17496 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17497 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17498 < it
.last_visible_y
))
17499 ++first_unchanged_at_end_row
;
17501 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17502 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17503 >= it
.last_visible_y
))
17504 first_unchanged_at_end_row
= NULL
;
17507 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
17509 first_unchanged_at_end_vpos
17510 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
17511 eassert (stop_pos
>= Z
- END_UNCHANGED
);
17514 else if (last_unchanged_at_beg_row
== NULL
)
17520 /* Either there is no unchanged row at the end, or the one we have
17521 now displays text. This is a necessary condition for the window
17522 end pos calculation at the end of this function. */
17523 eassert (first_unchanged_at_end_row
== NULL
17524 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
17526 debug_last_unchanged_at_beg_vpos
17527 = (last_unchanged_at_beg_row
17528 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
17530 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
17532 #endif /* GLYPH_DEBUG */
17535 /* Display new lines. Set last_text_row to the last new line
17536 displayed which has text on it, i.e. might end up as being the
17537 line where the window_end_vpos is. */
17538 w
->cursor
.vpos
= -1;
17539 last_text_row
= NULL
;
17540 overlay_arrow_seen
= 0;
17541 while (it
.current_y
< it
.last_visible_y
17542 && !fonts_changed_p
17543 && (first_unchanged_at_end_row
== NULL
17544 || IT_CHARPOS (it
) < stop_pos
))
17546 if (display_line (&it
))
17547 last_text_row
= it
.glyph_row
- 1;
17550 if (fonts_changed_p
)
17554 /* Compute differences in buffer positions, y-positions etc. for
17555 lines reused at the bottom of the window. Compute what we can
17557 if (first_unchanged_at_end_row
17558 /* No lines reused because we displayed everything up to the
17559 bottom of the window. */
17560 && it
.current_y
< it
.last_visible_y
)
17563 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
17565 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
17566 run
.current_y
= first_unchanged_at_end_row
->y
;
17567 run
.desired_y
= run
.current_y
+ dy
;
17568 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
17572 delta
= delta_bytes
= dvpos
= dy
17573 = run
.current_y
= run
.desired_y
= run
.height
= 0;
17574 first_unchanged_at_end_row
= NULL
;
17576 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
17579 /* Find the cursor if not already found. We have to decide whether
17580 PT will appear on this window (it sometimes doesn't, but this is
17581 not a very frequent case.) This decision has to be made before
17582 the current matrix is altered. A value of cursor.vpos < 0 means
17583 that PT is either in one of the lines beginning at
17584 first_unchanged_at_end_row or below the window. Don't care for
17585 lines that might be displayed later at the window end; as
17586 mentioned, this is not a frequent case. */
17587 if (w
->cursor
.vpos
< 0)
17589 /* Cursor in unchanged rows at the top? */
17590 if (PT
< CHARPOS (start_pos
)
17591 && last_unchanged_at_beg_row
)
17593 row
= row_containing_pos (w
, PT
,
17594 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
17595 last_unchanged_at_beg_row
+ 1, 0);
17597 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
17600 /* Start from first_unchanged_at_end_row looking for PT. */
17601 else if (first_unchanged_at_end_row
)
17603 row
= row_containing_pos (w
, PT
- delta
,
17604 first_unchanged_at_end_row
, NULL
, 0);
17606 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
17607 delta_bytes
, dy
, dvpos
);
17610 /* Give up if cursor was not found. */
17611 if (w
->cursor
.vpos
< 0)
17613 clear_glyph_matrix (w
->desired_matrix
);
17618 /* Don't let the cursor end in the scroll margins. */
17620 int this_scroll_margin
, cursor_height
;
17621 int frame_line_height
= default_line_pixel_height (w
);
17622 int window_total_lines
17623 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (it
.f
) / frame_line_height
;
17625 this_scroll_margin
=
17626 max (0, min (scroll_margin
, window_total_lines
/ 4));
17627 this_scroll_margin
*= frame_line_height
;
17628 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
17630 if ((w
->cursor
.y
< this_scroll_margin
17631 && CHARPOS (start
) > BEGV
)
17632 /* Old redisplay didn't take scroll margin into account at the bottom,
17633 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
17634 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
17635 ? cursor_height
+ this_scroll_margin
17636 : 1)) > it
.last_visible_y
)
17638 w
->cursor
.vpos
= -1;
17639 clear_glyph_matrix (w
->desired_matrix
);
17644 /* Scroll the display. Do it before changing the current matrix so
17645 that xterm.c doesn't get confused about where the cursor glyph is
17647 if (dy
&& run
.height
)
17651 if (FRAME_WINDOW_P (f
))
17653 FRAME_RIF (f
)->update_window_begin_hook (w
);
17654 FRAME_RIF (f
)->clear_window_mouse_face (w
);
17655 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
17656 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
17660 /* Terminal frame. In this case, dvpos gives the number of
17661 lines to scroll by; dvpos < 0 means scroll up. */
17663 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
17664 int from
= WINDOW_TOP_EDGE_LINE (w
) + from_vpos
;
17665 int end
= (WINDOW_TOP_EDGE_LINE (w
)
17666 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
17667 + window_internal_height (w
));
17669 #if defined (HAVE_GPM) || defined (MSDOS)
17670 x_clear_window_mouse_face (w
);
17672 /* Perform the operation on the screen. */
17675 /* Scroll last_unchanged_at_beg_row to the end of the
17676 window down dvpos lines. */
17677 set_terminal_window (f
, end
);
17679 /* On dumb terminals delete dvpos lines at the end
17680 before inserting dvpos empty lines. */
17681 if (!FRAME_SCROLL_REGION_OK (f
))
17682 ins_del_lines (f
, end
- dvpos
, -dvpos
);
17684 /* Insert dvpos empty lines in front of
17685 last_unchanged_at_beg_row. */
17686 ins_del_lines (f
, from
, dvpos
);
17688 else if (dvpos
< 0)
17690 /* Scroll up last_unchanged_at_beg_vpos to the end of
17691 the window to last_unchanged_at_beg_vpos - |dvpos|. */
17692 set_terminal_window (f
, end
);
17694 /* Delete dvpos lines in front of
17695 last_unchanged_at_beg_vpos. ins_del_lines will set
17696 the cursor to the given vpos and emit |dvpos| delete
17698 ins_del_lines (f
, from
+ dvpos
, dvpos
);
17700 /* On a dumb terminal insert dvpos empty lines at the
17702 if (!FRAME_SCROLL_REGION_OK (f
))
17703 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
17706 set_terminal_window (f
, 0);
17712 /* Shift reused rows of the current matrix to the right position.
17713 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
17715 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17716 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
17719 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
17720 bottom_vpos
, dvpos
);
17721 clear_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
17724 else if (dvpos
> 0)
17726 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
17727 bottom_vpos
, dvpos
);
17728 clear_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
17729 first_unchanged_at_end_vpos
+ dvpos
);
17732 /* For frame-based redisplay, make sure that current frame and window
17733 matrix are in sync with respect to glyph memory. */
17734 if (!FRAME_WINDOW_P (f
))
17735 sync_frame_with_window_matrix_rows (w
);
17737 /* Adjust buffer positions in reused rows. */
17738 if (delta
|| delta_bytes
)
17739 increment_matrix_positions (current_matrix
,
17740 first_unchanged_at_end_vpos
+ dvpos
,
17741 bottom_vpos
, delta
, delta_bytes
);
17743 /* Adjust Y positions. */
17745 shift_glyph_matrix (w
, current_matrix
,
17746 first_unchanged_at_end_vpos
+ dvpos
,
17749 if (first_unchanged_at_end_row
)
17751 first_unchanged_at_end_row
+= dvpos
;
17752 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
17753 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
17754 first_unchanged_at_end_row
= NULL
;
17757 /* If scrolling up, there may be some lines to display at the end of
17759 last_text_row_at_end
= NULL
;
17762 /* Scrolling up can leave for example a partially visible line
17763 at the end of the window to be redisplayed. */
17764 /* Set last_row to the glyph row in the current matrix where the
17765 window end line is found. It has been moved up or down in
17766 the matrix by dvpos. */
17767 int last_vpos
= w
->window_end_vpos
+ dvpos
;
17768 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
17770 /* If last_row is the window end line, it should display text. */
17771 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_row
));
17773 /* If window end line was partially visible before, begin
17774 displaying at that line. Otherwise begin displaying with the
17775 line following it. */
17776 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
17778 init_to_row_start (&it
, w
, last_row
);
17779 it
.vpos
= last_vpos
;
17780 it
.current_y
= last_row
->y
;
17784 init_to_row_end (&it
, w
, last_row
);
17785 it
.vpos
= 1 + last_vpos
;
17786 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
17790 /* We may start in a continuation line. If so, we have to
17791 get the right continuation_lines_width and current_x. */
17792 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
17793 it
.hpos
= it
.current_x
= 0;
17795 /* Display the rest of the lines at the window end. */
17796 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17797 while (it
.current_y
< it
.last_visible_y
17798 && !fonts_changed_p
)
17800 /* Is it always sure that the display agrees with lines in
17801 the current matrix? I don't think so, so we mark rows
17802 displayed invalid in the current matrix by setting their
17803 enabled_p flag to zero. */
17804 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
17805 if (display_line (&it
))
17806 last_text_row_at_end
= it
.glyph_row
- 1;
17810 /* Update window_end_pos and window_end_vpos. */
17811 if (first_unchanged_at_end_row
&& !last_text_row_at_end
)
17813 /* Window end line if one of the preserved rows from the current
17814 matrix. Set row to the last row displaying text in current
17815 matrix starting at first_unchanged_at_end_row, after
17817 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
17818 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
17819 first_unchanged_at_end_row
);
17820 eassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
17821 adjust_window_ends (w
, row
, 1);
17822 eassert (w
->window_end_bytepos
>= 0);
17823 IF_DEBUG (debug_method_add (w
, "A"));
17825 else if (last_text_row_at_end
)
17827 adjust_window_ends (w
, last_text_row_at_end
, 0);
17828 eassert (w
->window_end_bytepos
>= 0);
17829 IF_DEBUG (debug_method_add (w
, "B"));
17831 else if (last_text_row
)
17833 /* We have displayed either to the end of the window or at the
17834 end of the window, i.e. the last row with text is to be found
17835 in the desired matrix. */
17836 adjust_window_ends (w
, last_text_row
, 0);
17837 eassert (w
->window_end_bytepos
>= 0);
17839 else if (first_unchanged_at_end_row
== NULL
17840 && last_text_row
== NULL
17841 && last_text_row_at_end
== NULL
)
17843 /* Displayed to end of window, but no line containing text was
17844 displayed. Lines were deleted at the end of the window. */
17845 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
17846 int vpos
= w
->window_end_vpos
;
17847 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
17848 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
17851 row
== NULL
&& vpos
>= first_vpos
;
17852 --vpos
, --current_row
, --desired_row
)
17854 if (desired_row
->enabled_p
)
17856 if (MATRIX_ROW_DISPLAYS_TEXT_P (desired_row
))
17859 else if (MATRIX_ROW_DISPLAYS_TEXT_P (current_row
))
17863 eassert (row
!= NULL
);
17864 w
->window_end_vpos
= vpos
+ 1;
17865 w
->window_end_pos
= Z
- MATRIX_ROW_END_CHARPOS (row
);
17866 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17867 eassert (w
->window_end_bytepos
>= 0);
17868 IF_DEBUG (debug_method_add (w
, "C"));
17873 IF_DEBUG (debug_end_pos
= w
->window_end_pos
;
17874 debug_end_vpos
= w
->window_end_vpos
);
17876 /* Record that display has not been completed. */
17877 w
->window_end_valid
= 0;
17878 w
->desired_matrix
->no_scrolling_p
= 1;
17886 /***********************************************************************
17887 More debugging support
17888 ***********************************************************************/
17892 void dump_glyph_row (struct glyph_row
*, int, int) EXTERNALLY_VISIBLE
;
17893 void dump_glyph_matrix (struct glyph_matrix
*, int) EXTERNALLY_VISIBLE
;
17894 void dump_glyph (struct glyph_row
*, struct glyph
*, int) EXTERNALLY_VISIBLE
;
17897 /* Dump the contents of glyph matrix MATRIX on stderr.
17899 GLYPHS 0 means don't show glyph contents.
17900 GLYPHS 1 means show glyphs in short form
17901 GLYPHS > 1 means show glyphs in long form. */
17904 dump_glyph_matrix (struct glyph_matrix
*matrix
, int glyphs
)
17907 for (i
= 0; i
< matrix
->nrows
; ++i
)
17908 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
17912 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
17913 the glyph row and area where the glyph comes from. */
17916 dump_glyph (struct glyph_row
*row
, struct glyph
*glyph
, int area
)
17918 if (glyph
->type
== CHAR_GLYPH
17919 || glyph
->type
== GLYPHLESS_GLYPH
)
17922 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
17923 glyph
- row
->glyphs
[TEXT_AREA
],
17924 (glyph
->type
== CHAR_GLYPH
17928 (BUFFERP (glyph
->object
)
17930 : (STRINGP (glyph
->object
)
17932 : (INTEGERP (glyph
->object
)
17935 glyph
->pixel_width
,
17937 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
17941 glyph
->left_box_line_p
,
17942 glyph
->right_box_line_p
);
17944 else if (glyph
->type
== STRETCH_GLYPH
)
17947 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
17948 glyph
- row
->glyphs
[TEXT_AREA
],
17951 (BUFFERP (glyph
->object
)
17953 : (STRINGP (glyph
->object
)
17955 : (INTEGERP (glyph
->object
)
17958 glyph
->pixel_width
,
17962 glyph
->left_box_line_p
,
17963 glyph
->right_box_line_p
);
17965 else if (glyph
->type
== IMAGE_GLYPH
)
17968 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
17969 glyph
- row
->glyphs
[TEXT_AREA
],
17972 (BUFFERP (glyph
->object
)
17974 : (STRINGP (glyph
->object
)
17976 : (INTEGERP (glyph
->object
)
17979 glyph
->pixel_width
,
17983 glyph
->left_box_line_p
,
17984 glyph
->right_box_line_p
);
17986 else if (glyph
->type
== COMPOSITE_GLYPH
)
17989 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x",
17990 glyph
- row
->glyphs
[TEXT_AREA
],
17993 (BUFFERP (glyph
->object
)
17995 : (STRINGP (glyph
->object
)
17997 : (INTEGERP (glyph
->object
)
18000 glyph
->pixel_width
,
18002 if (glyph
->u
.cmp
.automatic
)
18005 glyph
->slice
.cmp
.from
, glyph
->slice
.cmp
.to
);
18006 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
18008 glyph
->left_box_line_p
,
18009 glyph
->right_box_line_p
);
18011 #ifdef HAVE_XWIDGETS
18012 else if (glyph
->type
== XWIDGET_GLYPH
)
18015 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
18016 glyph
- row
->glyphs
[TEXT_AREA
],
18019 (BUFFERP (glyph
->object
)
18021 : (STRINGP (glyph
->object
)
18024 glyph
->pixel_width
,
18028 glyph
->left_box_line_p
,
18029 glyph
->right_box_line_p
);
18031 // printf("dump xwidget glyph\n");
18037 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
18038 GLYPHS 0 means don't show glyph contents.
18039 GLYPHS 1 means show glyphs in short form
18040 GLYPHS > 1 means show glyphs in long form. */
18043 dump_glyph_row (struct glyph_row
*row
, int vpos
, int glyphs
)
18047 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
18048 fprintf (stderr
, "==============================================================================\n");
18050 fprintf (stderr
, "%3d %9"pI
"d %9"pI
"d %4d %1.1d%1.1d%1.1d%1.1d\
18051 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
18053 MATRIX_ROW_START_CHARPOS (row
),
18054 MATRIX_ROW_END_CHARPOS (row
),
18055 row
->used
[TEXT_AREA
],
18056 row
->contains_overlapping_glyphs_p
,
18058 row
->truncated_on_left_p
,
18059 row
->truncated_on_right_p
,
18061 MATRIX_ROW_CONTINUATION_LINE_P (row
),
18062 MATRIX_ROW_DISPLAYS_TEXT_P (row
),
18065 row
->ends_in_middle_of_char_p
,
18066 row
->starts_in_middle_of_char_p
,
18072 row
->visible_height
,
18075 /* The next 3 lines should align to "Start" in the header. */
18076 fprintf (stderr
, " %9"pD
"d %9"pD
"d\t%5d\n", row
->start
.overlay_string_index
,
18077 row
->end
.overlay_string_index
,
18078 row
->continuation_lines_width
);
18079 fprintf (stderr
, " %9"pI
"d %9"pI
"d\n",
18080 CHARPOS (row
->start
.string_pos
),
18081 CHARPOS (row
->end
.string_pos
));
18082 fprintf (stderr
, " %9d %9d\n", row
->start
.dpvec_index
,
18083 row
->end
.dpvec_index
);
18090 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18092 struct glyph
*glyph
= row
->glyphs
[area
];
18093 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
18095 /* Glyph for a line end in text. */
18096 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
18099 if (glyph
< glyph_end
)
18100 fprintf (stderr
, " Glyph# Type Pos O W Code C Face LR\n");
18102 for (; glyph
< glyph_end
; ++glyph
)
18103 dump_glyph (row
, glyph
, area
);
18106 else if (glyphs
== 1)
18110 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18112 char *s
= alloca (row
->used
[area
] + 4);
18115 for (i
= 0; i
< row
->used
[area
]; ++i
)
18117 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
18118 if (i
== row
->used
[area
] - 1
18119 && area
== TEXT_AREA
18120 && INTEGERP (glyph
->object
)
18121 && glyph
->type
== CHAR_GLYPH
18122 && glyph
->u
.ch
== ' ')
18124 strcpy (&s
[i
], "[\\n]");
18127 else if (glyph
->type
== CHAR_GLYPH
18128 && glyph
->u
.ch
< 0x80
18129 && glyph
->u
.ch
>= ' ')
18130 s
[i
] = glyph
->u
.ch
;
18136 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
18142 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
18143 Sdump_glyph_matrix
, 0, 1, "p",
18144 doc
: /* Dump the current matrix of the selected window to stderr.
18145 Shows contents of glyph row structures. With non-nil
18146 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
18147 glyphs in short form, otherwise show glyphs in long form. */)
18148 (Lisp_Object glyphs
)
18150 struct window
*w
= XWINDOW (selected_window
);
18151 struct buffer
*buffer
= XBUFFER (w
->contents
);
18153 fprintf (stderr
, "PT = %"pI
"d, BEGV = %"pI
"d. ZV = %"pI
"d\n",
18154 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
18155 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
18156 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
18157 fprintf (stderr
, "=============================================\n");
18158 dump_glyph_matrix (w
->current_matrix
,
18159 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 0);
18164 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
18165 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
18168 struct frame
*f
= XFRAME (selected_frame
);
18169 dump_glyph_matrix (f
->current_matrix
, 1);
18174 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
18175 doc
: /* Dump glyph row ROW to stderr.
18176 GLYPH 0 means don't dump glyphs.
18177 GLYPH 1 means dump glyphs in short form.
18178 GLYPH > 1 or omitted means dump glyphs in long form. */)
18179 (Lisp_Object row
, Lisp_Object glyphs
)
18181 struct glyph_matrix
*matrix
;
18184 CHECK_NUMBER (row
);
18185 matrix
= XWINDOW (selected_window
)->current_matrix
;
18187 if (vpos
>= 0 && vpos
< matrix
->nrows
)
18188 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
18190 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18195 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
18196 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
18197 GLYPH 0 means don't dump glyphs.
18198 GLYPH 1 means dump glyphs in short form.
18199 GLYPH > 1 or omitted means dump glyphs in long form. */)
18200 (Lisp_Object row
, Lisp_Object glyphs
)
18202 struct frame
*sf
= SELECTED_FRAME ();
18203 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
18206 CHECK_NUMBER (row
);
18208 if (vpos
>= 0 && vpos
< m
->nrows
)
18209 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
18210 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18215 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
18216 doc
: /* Toggle tracing of redisplay.
18217 With ARG, turn tracing on if and only if ARG is positive. */)
18221 trace_redisplay_p
= !trace_redisplay_p
;
18224 arg
= Fprefix_numeric_value (arg
);
18225 trace_redisplay_p
= XINT (arg
) > 0;
18232 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
18233 doc
: /* Like `format', but print result to stderr.
18234 usage: (trace-to-stderr STRING &rest OBJECTS) */)
18235 (ptrdiff_t nargs
, Lisp_Object
*args
)
18237 Lisp_Object s
= Fformat (nargs
, args
);
18238 fprintf (stderr
, "%s", SDATA (s
));
18242 #endif /* GLYPH_DEBUG */
18246 /***********************************************************************
18247 Building Desired Matrix Rows
18248 ***********************************************************************/
18250 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
18251 Used for non-window-redisplay windows, and for windows w/o left fringe. */
18253 static struct glyph_row
*
18254 get_overlay_arrow_glyph_row (struct window
*w
, Lisp_Object overlay_arrow_string
)
18256 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18257 struct buffer
*buffer
= XBUFFER (w
->contents
);
18258 struct buffer
*old
= current_buffer
;
18259 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
18260 int arrow_len
= SCHARS (overlay_arrow_string
);
18261 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
18262 const unsigned char *p
;
18265 int n_glyphs_before
;
18267 set_buffer_temp (buffer
);
18268 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
18269 it
.glyph_row
->used
[TEXT_AREA
] = 0;
18270 SET_TEXT_POS (it
.position
, 0, 0);
18272 multibyte_p
= !NILP (BVAR (buffer
, enable_multibyte_characters
));
18274 while (p
< arrow_end
)
18276 Lisp_Object face
, ilisp
;
18278 /* Get the next character. */
18280 it
.c
= it
.char_to_display
= string_char_and_length (p
, &it
.len
);
18283 it
.c
= it
.char_to_display
= *p
, it
.len
= 1;
18284 if (! ASCII_CHAR_P (it
.c
))
18285 it
.char_to_display
= BYTE8_TO_CHAR (it
.c
);
18289 /* Get its face. */
18290 ilisp
= make_number (p
- arrow_string
);
18291 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
18292 it
.face_id
= compute_char_face (f
, it
.char_to_display
, face
);
18294 /* Compute its width, get its glyphs. */
18295 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
18296 SET_TEXT_POS (it
.position
, -1, -1);
18297 PRODUCE_GLYPHS (&it
);
18299 /* If this character doesn't fit any more in the line, we have
18300 to remove some glyphs. */
18301 if (it
.current_x
> it
.last_visible_x
)
18303 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
18308 set_buffer_temp (old
);
18309 return it
.glyph_row
;
18313 /* Insert truncation glyphs at the start of IT->glyph_row. Which
18314 glyphs to insert is determined by produce_special_glyphs. */
18317 insert_left_trunc_glyphs (struct it
*it
)
18319 struct it truncate_it
;
18320 struct glyph
*from
, *end
, *to
, *toend
;
18322 eassert (!FRAME_WINDOW_P (it
->f
)
18323 || (!it
->glyph_row
->reversed_p
18324 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0)
18325 || (it
->glyph_row
->reversed_p
18326 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0));
18328 /* Get the truncation glyphs. */
18330 truncate_it
.current_x
= 0;
18331 truncate_it
.face_id
= DEFAULT_FACE_ID
;
18332 truncate_it
.glyph_row
= &scratch_glyph_row
;
18333 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
18334 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
18335 truncate_it
.object
= make_number (0);
18336 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
18338 /* Overwrite glyphs from IT with truncation glyphs. */
18339 if (!it
->glyph_row
->reversed_p
)
18341 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
18343 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18344 end
= from
+ tused
;
18345 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18346 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
18347 if (FRAME_WINDOW_P (it
->f
))
18349 /* On GUI frames, when variable-size fonts are displayed,
18350 the truncation glyphs may need more pixels than the row's
18351 glyphs they overwrite. We overwrite more glyphs to free
18352 enough screen real estate, and enlarge the stretch glyph
18353 on the right (see display_line), if there is one, to
18354 preserve the screen position of the truncation glyphs on
18357 struct glyph
*g
= to
;
18360 /* The first glyph could be partially visible, in which case
18361 it->glyph_row->x will be negative. But we want the left
18362 truncation glyphs to be aligned at the left margin of the
18363 window, so we override the x coordinate at which the row
18365 it
->glyph_row
->x
= 0;
18366 while (g
< toend
&& w
< it
->truncation_pixel_width
)
18368 w
+= g
->pixel_width
;
18371 if (g
- to
- tused
> 0)
18373 memmove (to
+ tused
, g
, (toend
- g
) * sizeof(*g
));
18374 it
->glyph_row
->used
[TEXT_AREA
] -= g
- to
- tused
;
18376 used
= it
->glyph_row
->used
[TEXT_AREA
];
18377 if (it
->glyph_row
->truncated_on_right_p
18378 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0
18379 && it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].type
18382 int extra
= w
- it
->truncation_pixel_width
;
18384 it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].pixel_width
+= extra
;
18391 /* There may be padding glyphs left over. Overwrite them too. */
18392 if (!FRAME_WINDOW_P (it
->f
))
18394 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
18396 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18403 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
18407 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
18409 /* In R2L rows, overwrite the last (rightmost) glyphs, and do
18410 that back to front. */
18411 end
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18412 from
= end
+ truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18413 toend
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18414 to
= toend
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18415 if (FRAME_WINDOW_P (it
->f
))
18418 struct glyph
*g
= to
;
18420 while (g
>= toend
&& w
< it
->truncation_pixel_width
)
18422 w
+= g
->pixel_width
;
18425 if (to
- g
- tused
> 0)
18427 if (it
->glyph_row
->truncated_on_right_p
18428 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0
18429 && it
->glyph_row
->glyphs
[TEXT_AREA
][1].type
== STRETCH_GLYPH
)
18431 int extra
= w
- it
->truncation_pixel_width
;
18433 it
->glyph_row
->glyphs
[TEXT_AREA
][1].pixel_width
+= extra
;
18437 while (from
>= end
&& to
>= toend
)
18439 if (!FRAME_WINDOW_P (it
->f
))
18441 while (to
>= toend
&& CHAR_GLYPH_PADDING_P (*to
))
18444 truncate_it
.glyph_row
->glyphs
[TEXT_AREA
]
18445 + truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18446 while (from
>= end
&& to
>= toend
)
18452 /* Need to free some room before prepending additional
18454 int move_by
= from
- end
+ 1;
18455 struct glyph
*g0
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18456 struct glyph
*g
= g0
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18458 for ( ; g
>= g0
; g
--)
18460 while (from
>= end
)
18462 it
->glyph_row
->used
[TEXT_AREA
] += move_by
;
18467 /* Compute the hash code for ROW. */
18469 row_hash (struct glyph_row
*row
)
18472 unsigned hashval
= 0;
18474 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18475 for (k
= 0; k
< row
->used
[area
]; ++k
)
18476 hashval
= ((((hashval
<< 4) + (hashval
>> 24)) & 0x0fffffff)
18477 + row
->glyphs
[area
][k
].u
.val
18478 + row
->glyphs
[area
][k
].face_id
18479 + row
->glyphs
[area
][k
].padding_p
18480 + (row
->glyphs
[area
][k
].type
<< 2));
18485 /* Compute the pixel height and width of IT->glyph_row.
18487 Most of the time, ascent and height of a display line will be equal
18488 to the max_ascent and max_height values of the display iterator
18489 structure. This is not the case if
18491 1. We hit ZV without displaying anything. In this case, max_ascent
18492 and max_height will be zero.
18494 2. We have some glyphs that don't contribute to the line height.
18495 (The glyph row flag contributes_to_line_height_p is for future
18496 pixmap extensions).
18498 The first case is easily covered by using default values because in
18499 these cases, the line height does not really matter, except that it
18500 must not be zero. */
18503 compute_line_metrics (struct it
*it
)
18505 struct glyph_row
*row
= it
->glyph_row
;
18507 if (FRAME_WINDOW_P (it
->f
))
18509 int i
, min_y
, max_y
;
18511 /* The line may consist of one space only, that was added to
18512 place the cursor on it. If so, the row's height hasn't been
18514 if (row
->height
== 0)
18516 if (it
->max_ascent
+ it
->max_descent
== 0)
18517 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
18518 row
->ascent
= it
->max_ascent
;
18519 row
->height
= it
->max_ascent
+ it
->max_descent
;
18520 row
->phys_ascent
= it
->max_phys_ascent
;
18521 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18522 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18525 /* Compute the width of this line. */
18526 row
->pixel_width
= row
->x
;
18527 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
18528 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
18530 eassert (row
->pixel_width
>= 0);
18531 eassert (row
->ascent
>= 0 && row
->height
> 0);
18533 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
18534 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
18536 /* If first line's physical ascent is larger than its logical
18537 ascent, use the physical ascent, and make the row taller.
18538 This makes accented characters fully visible. */
18539 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
18540 && row
->phys_ascent
> row
->ascent
)
18542 row
->height
+= row
->phys_ascent
- row
->ascent
;
18543 row
->ascent
= row
->phys_ascent
;
18546 /* Compute how much of the line is visible. */
18547 row
->visible_height
= row
->height
;
18549 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
18550 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
18552 if (row
->y
< min_y
)
18553 row
->visible_height
-= min_y
- row
->y
;
18554 if (row
->y
+ row
->height
> max_y
)
18555 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
18559 row
->pixel_width
= row
->used
[TEXT_AREA
];
18560 if (row
->continued_p
)
18561 row
->pixel_width
-= it
->continuation_pixel_width
;
18562 else if (row
->truncated_on_right_p
)
18563 row
->pixel_width
-= it
->truncation_pixel_width
;
18564 row
->ascent
= row
->phys_ascent
= 0;
18565 row
->height
= row
->phys_height
= row
->visible_height
= 1;
18566 row
->extra_line_spacing
= 0;
18569 /* Compute a hash code for this row. */
18570 row
->hash
= row_hash (row
);
18572 it
->max_ascent
= it
->max_descent
= 0;
18573 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
18577 /* Append one space to the glyph row of iterator IT if doing a
18578 window-based redisplay. The space has the same face as
18579 IT->face_id. Value is non-zero if a space was added.
18581 This function is called to make sure that there is always one glyph
18582 at the end of a glyph row that the cursor can be set on under
18583 window-systems. (If there weren't such a glyph we would not know
18584 how wide and tall a box cursor should be displayed).
18586 At the same time this space let's a nicely handle clearing to the
18587 end of the line if the row ends in italic text. */
18590 append_space_for_newline (struct it
*it
, int default_face_p
)
18592 if (FRAME_WINDOW_P (it
->f
))
18594 int n
= it
->glyph_row
->used
[TEXT_AREA
];
18596 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
18597 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
18599 /* Save some values that must not be changed.
18600 Must save IT->c and IT->len because otherwise
18601 ITERATOR_AT_END_P wouldn't work anymore after
18602 append_space_for_newline has been called. */
18603 enum display_element_type saved_what
= it
->what
;
18604 int saved_c
= it
->c
, saved_len
= it
->len
;
18605 int saved_char_to_display
= it
->char_to_display
;
18606 int saved_x
= it
->current_x
;
18607 int saved_face_id
= it
->face_id
;
18608 int saved_box_end
= it
->end_of_box_run_p
;
18609 struct text_pos saved_pos
;
18610 Lisp_Object saved_object
;
18613 saved_object
= it
->object
;
18614 saved_pos
= it
->position
;
18616 it
->what
= IT_CHARACTER
;
18617 memset (&it
->position
, 0, sizeof it
->position
);
18618 it
->object
= make_number (0);
18619 it
->c
= it
->char_to_display
= ' ';
18622 /* If the default face was remapped, be sure to use the
18623 remapped face for the appended newline. */
18624 if (default_face_p
)
18625 it
->face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
18626 else if (it
->face_before_selective_p
)
18627 it
->face_id
= it
->saved_face_id
;
18628 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18629 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
18630 /* In R2L rows, we will prepend a stretch glyph that will
18631 have the end_of_box_run_p flag set for it, so there's no
18632 need for the appended newline glyph to have that flag
18634 if (it
->glyph_row
->reversed_p
18635 /* But if the appended newline glyph goes all the way to
18636 the end of the row, there will be no stretch glyph,
18637 so leave the box flag set. */
18638 && saved_x
+ FRAME_COLUMN_WIDTH (it
->f
) < it
->last_visible_x
)
18639 it
->end_of_box_run_p
= 0;
18641 PRODUCE_GLYPHS (it
);
18643 it
->override_ascent
= -1;
18644 it
->constrain_row_ascent_descent_p
= 0;
18645 it
->current_x
= saved_x
;
18646 it
->object
= saved_object
;
18647 it
->position
= saved_pos
;
18648 it
->what
= saved_what
;
18649 it
->face_id
= saved_face_id
;
18650 it
->len
= saved_len
;
18652 it
->char_to_display
= saved_char_to_display
;
18653 it
->end_of_box_run_p
= saved_box_end
;
18662 /* Extend the face of the last glyph in the text area of IT->glyph_row
18663 to the end of the display line. Called from display_line. If the
18664 glyph row is empty, add a space glyph to it so that we know the
18665 face to draw. Set the glyph row flag fill_line_p. If the glyph
18666 row is R2L, prepend a stretch glyph to cover the empty space to the
18667 left of the leftmost glyph. */
18670 extend_face_to_end_of_line (struct it
*it
)
18672 struct face
*face
, *default_face
;
18673 struct frame
*f
= it
->f
;
18675 /* If line is already filled, do nothing. Non window-system frames
18676 get a grace of one more ``pixel'' because their characters are
18677 1-``pixel'' wide, so they hit the equality too early. This grace
18678 is needed only for R2L rows that are not continued, to produce
18679 one extra blank where we could display the cursor. */
18680 if (it
->current_x
>= it
->last_visible_x
18681 + (!FRAME_WINDOW_P (f
)
18682 && it
->glyph_row
->reversed_p
18683 && !it
->glyph_row
->continued_p
))
18686 /* The default face, possibly remapped. */
18687 default_face
= FACE_FROM_ID (f
, lookup_basic_face (f
, DEFAULT_FACE_ID
));
18689 /* Face extension extends the background and box of IT->face_id
18690 to the end of the line. If the background equals the background
18691 of the frame, we don't have to do anything. */
18692 if (it
->face_before_selective_p
)
18693 face
= FACE_FROM_ID (f
, it
->saved_face_id
);
18695 face
= FACE_FROM_ID (f
, it
->face_id
);
18697 if (FRAME_WINDOW_P (f
)
18698 && MATRIX_ROW_DISPLAYS_TEXT_P (it
->glyph_row
)
18699 && face
->box
== FACE_NO_BOX
18700 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
18702 && !it
->glyph_row
->reversed_p
)
18705 /* Set the glyph row flag indicating that the face of the last glyph
18706 in the text area has to be drawn to the end of the text area. */
18707 it
->glyph_row
->fill_line_p
= 1;
18709 /* If current character of IT is not ASCII, make sure we have the
18710 ASCII face. This will be automatically undone the next time
18711 get_next_display_element returns a multibyte character. Note
18712 that the character will always be single byte in unibyte
18714 if (!ASCII_CHAR_P (it
->c
))
18716 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
18719 if (FRAME_WINDOW_P (f
))
18721 /* If the row is empty, add a space with the current face of IT,
18722 so that we know which face to draw. */
18723 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
18725 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
18726 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= face
->id
;
18727 it
->glyph_row
->used
[TEXT_AREA
] = 1;
18729 #ifdef HAVE_WINDOW_SYSTEM
18730 if (it
->glyph_row
->reversed_p
)
18732 /* Prepend a stretch glyph to the row, such that the
18733 rightmost glyph will be drawn flushed all the way to the
18734 right margin of the window. The stretch glyph that will
18735 occupy the empty space, if any, to the left of the
18737 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (f
);
18738 struct glyph
*row_start
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18739 struct glyph
*row_end
= row_start
+ it
->glyph_row
->used
[TEXT_AREA
];
18741 int row_width
, stretch_ascent
, stretch_width
;
18742 struct text_pos saved_pos
;
18743 int saved_face_id
, saved_avoid_cursor
, saved_box_start
;
18745 for (row_width
= 0, g
= row_start
; g
< row_end
; g
++)
18746 row_width
+= g
->pixel_width
;
18747 stretch_width
= window_box_width (it
->w
, TEXT_AREA
) - row_width
;
18748 if (stretch_width
> 0)
18751 (((it
->ascent
+ it
->descent
)
18752 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
18753 saved_pos
= it
->position
;
18754 memset (&it
->position
, 0, sizeof it
->position
);
18755 saved_avoid_cursor
= it
->avoid_cursor_p
;
18756 it
->avoid_cursor_p
= 1;
18757 saved_face_id
= it
->face_id
;
18758 saved_box_start
= it
->start_of_box_run_p
;
18759 /* The last row's stretch glyph should get the default
18760 face, to avoid painting the rest of the window with
18761 the region face, if the region ends at ZV. */
18762 if (it
->glyph_row
->ends_at_zv_p
)
18763 it
->face_id
= default_face
->id
;
18765 it
->face_id
= face
->id
;
18766 it
->start_of_box_run_p
= 0;
18767 append_stretch_glyph (it
, make_number (0), stretch_width
,
18768 it
->ascent
+ it
->descent
, stretch_ascent
);
18769 it
->position
= saved_pos
;
18770 it
->avoid_cursor_p
= saved_avoid_cursor
;
18771 it
->face_id
= saved_face_id
;
18772 it
->start_of_box_run_p
= saved_box_start
;
18775 #endif /* HAVE_WINDOW_SYSTEM */
18779 /* Save some values that must not be changed. */
18780 int saved_x
= it
->current_x
;
18781 struct text_pos saved_pos
;
18782 Lisp_Object saved_object
;
18783 enum display_element_type saved_what
= it
->what
;
18784 int saved_face_id
= it
->face_id
;
18786 saved_object
= it
->object
;
18787 saved_pos
= it
->position
;
18789 it
->what
= IT_CHARACTER
;
18790 memset (&it
->position
, 0, sizeof it
->position
);
18791 it
->object
= make_number (0);
18792 it
->c
= it
->char_to_display
= ' ';
18794 /* The last row's blank glyphs should get the default face, to
18795 avoid painting the rest of the window with the region face,
18796 if the region ends at ZV. */
18797 if (it
->glyph_row
->ends_at_zv_p
)
18798 it
->face_id
= default_face
->id
;
18800 it
->face_id
= face
->id
;
18802 PRODUCE_GLYPHS (it
);
18804 while (it
->current_x
<= it
->last_visible_x
)
18805 PRODUCE_GLYPHS (it
);
18807 /* Don't count these blanks really. It would let us insert a left
18808 truncation glyph below and make us set the cursor on them, maybe. */
18809 it
->current_x
= saved_x
;
18810 it
->object
= saved_object
;
18811 it
->position
= saved_pos
;
18812 it
->what
= saved_what
;
18813 it
->face_id
= saved_face_id
;
18818 /* Value is non-zero if text starting at CHARPOS in current_buffer is
18819 trailing whitespace. */
18822 trailing_whitespace_p (ptrdiff_t charpos
)
18824 ptrdiff_t bytepos
= CHAR_TO_BYTE (charpos
);
18827 while (bytepos
< ZV_BYTE
18828 && (c
= FETCH_CHAR (bytepos
),
18829 c
== ' ' || c
== '\t'))
18832 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
18834 if (bytepos
!= PT_BYTE
)
18841 /* Highlight trailing whitespace, if any, in ROW. */
18844 highlight_trailing_whitespace (struct frame
*f
, struct glyph_row
*row
)
18846 int used
= row
->used
[TEXT_AREA
];
18850 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
18851 struct glyph
*glyph
= start
+ used
- 1;
18853 if (row
->reversed_p
)
18855 /* Right-to-left rows need to be processed in the opposite
18856 direction, so swap the edge pointers. */
18858 start
= row
->glyphs
[TEXT_AREA
] + used
- 1;
18861 /* Skip over glyphs inserted to display the cursor at the
18862 end of a line, for extending the face of the last glyph
18863 to the end of the line on terminals, and for truncation
18864 and continuation glyphs. */
18865 if (!row
->reversed_p
)
18867 while (glyph
>= start
18868 && glyph
->type
== CHAR_GLYPH
18869 && INTEGERP (glyph
->object
))
18874 while (glyph
<= start
18875 && glyph
->type
== CHAR_GLYPH
18876 && INTEGERP (glyph
->object
))
18880 /* If last glyph is a space or stretch, and it's trailing
18881 whitespace, set the face of all trailing whitespace glyphs in
18882 IT->glyph_row to `trailing-whitespace'. */
18883 if ((row
->reversed_p
? glyph
<= start
: glyph
>= start
)
18884 && BUFFERP (glyph
->object
)
18885 && (glyph
->type
== STRETCH_GLYPH
18886 || (glyph
->type
== CHAR_GLYPH
18887 && glyph
->u
.ch
== ' '))
18888 && trailing_whitespace_p (glyph
->charpos
))
18890 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
18894 if (!row
->reversed_p
)
18896 while (glyph
>= start
18897 && BUFFERP (glyph
->object
)
18898 && (glyph
->type
== STRETCH_GLYPH
18899 || (glyph
->type
== CHAR_GLYPH
18900 && glyph
->u
.ch
== ' ')))
18901 (glyph
--)->face_id
= face_id
;
18905 while (glyph
<= start
18906 && BUFFERP (glyph
->object
)
18907 && (glyph
->type
== STRETCH_GLYPH
18908 || (glyph
->type
== CHAR_GLYPH
18909 && glyph
->u
.ch
== ' ')))
18910 (glyph
++)->face_id
= face_id
;
18917 /* Value is non-zero if glyph row ROW should be
18918 considered to hold the buffer position CHARPOS. */
18921 row_for_charpos_p (struct glyph_row
*row
, ptrdiff_t charpos
)
18925 if (charpos
== CHARPOS (row
->end
.pos
)
18926 || charpos
== MATRIX_ROW_END_CHARPOS (row
))
18928 /* Suppose the row ends on a string.
18929 Unless the row is continued, that means it ends on a newline
18930 in the string. If it's anything other than a display string
18931 (e.g., a before-string from an overlay), we don't want the
18932 cursor there. (This heuristic seems to give the optimal
18933 behavior for the various types of multi-line strings.)
18934 One exception: if the string has `cursor' property on one of
18935 its characters, we _do_ want the cursor there. */
18936 if (CHARPOS (row
->end
.string_pos
) >= 0)
18938 if (row
->continued_p
)
18942 /* Check for `display' property. */
18943 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
18944 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
18945 struct glyph
*glyph
;
18948 for (glyph
= end
; glyph
>= beg
; --glyph
)
18949 if (STRINGP (glyph
->object
))
18952 = Fget_char_property (make_number (charpos
),
18956 && display_prop_string_p (prop
, glyph
->object
));
18957 /* If there's a `cursor' property on one of the
18958 string's characters, this row is a cursor row,
18959 even though this is not a display string. */
18962 Lisp_Object s
= glyph
->object
;
18964 for ( ; glyph
>= beg
&& EQ (glyph
->object
, s
); --glyph
)
18966 ptrdiff_t gpos
= glyph
->charpos
;
18968 if (!NILP (Fget_char_property (make_number (gpos
),
18980 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
18982 /* If the row ends in middle of a real character,
18983 and the line is continued, we want the cursor here.
18984 That's because CHARPOS (ROW->end.pos) would equal
18985 PT if PT is before the character. */
18986 if (!row
->ends_in_ellipsis_p
)
18987 result
= row
->continued_p
;
18989 /* If the row ends in an ellipsis, then
18990 CHARPOS (ROW->end.pos) will equal point after the
18991 invisible text. We want that position to be displayed
18992 after the ellipsis. */
18995 /* If the row ends at ZV, display the cursor at the end of that
18996 row instead of at the start of the row below. */
18997 else if (row
->ends_at_zv_p
)
19006 /* Value is non-zero if glyph row ROW should be
19007 used to hold the cursor. */
19010 cursor_row_p (struct glyph_row
*row
)
19012 return row_for_charpos_p (row
, PT
);
19017 /* Push the property PROP so that it will be rendered at the current
19018 position in IT. Return 1 if PROP was successfully pushed, 0
19019 otherwise. Called from handle_line_prefix to handle the
19020 `line-prefix' and `wrap-prefix' properties. */
19023 push_prefix_prop (struct it
*it
, Lisp_Object prop
)
19025 struct text_pos pos
=
19026 STRINGP (it
->string
) ? it
->current
.string_pos
: it
->current
.pos
;
19028 eassert (it
->method
== GET_FROM_BUFFER
19029 || it
->method
== GET_FROM_DISPLAY_VECTOR
19030 || it
->method
== GET_FROM_STRING
);
19032 /* We need to save the current buffer/string position, so it will be
19033 restored by pop_it, because iterate_out_of_display_property
19034 depends on that being set correctly, but some situations leave
19035 it->position not yet set when this function is called. */
19036 push_it (it
, &pos
);
19038 if (STRINGP (prop
))
19040 if (SCHARS (prop
) == 0)
19047 it
->string_from_prefix_prop_p
= 1;
19048 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
19049 it
->current
.overlay_string_index
= -1;
19050 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
19051 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
19052 it
->method
= GET_FROM_STRING
;
19053 it
->stop_charpos
= 0;
19055 it
->base_level_stop
= 0;
19057 /* Force paragraph direction to be that of the parent
19059 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
19060 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
19062 it
->paragraph_embedding
= L2R
;
19064 /* Set up the bidi iterator for this display string. */
19067 it
->bidi_it
.string
.lstring
= it
->string
;
19068 it
->bidi_it
.string
.s
= NULL
;
19069 it
->bidi_it
.string
.schars
= it
->end_charpos
;
19070 it
->bidi_it
.string
.bufpos
= IT_CHARPOS (*it
);
19071 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
19072 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
19073 it
->bidi_it
.w
= it
->w
;
19074 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
19077 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
19079 it
->method
= GET_FROM_STRETCH
;
19082 #ifdef HAVE_WINDOW_SYSTEM
19083 else if (IMAGEP (prop
))
19085 it
->what
= IT_IMAGE
;
19086 it
->image_id
= lookup_image (it
->f
, prop
);
19087 it
->method
= GET_FROM_IMAGE
;
19089 #endif /* HAVE_WINDOW_SYSTEM */
19092 pop_it (it
); /* bogus display property, give up */
19099 /* Return the character-property PROP at the current position in IT. */
19102 get_it_property (struct it
*it
, Lisp_Object prop
)
19104 Lisp_Object position
, object
= it
->object
;
19106 if (STRINGP (object
))
19107 position
= make_number (IT_STRING_CHARPOS (*it
));
19108 else if (BUFFERP (object
))
19110 position
= make_number (IT_CHARPOS (*it
));
19111 object
= it
->window
;
19116 return Fget_char_property (position
, prop
, object
);
19119 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
19122 handle_line_prefix (struct it
*it
)
19124 Lisp_Object prefix
;
19126 if (it
->continuation_lines_width
> 0)
19128 prefix
= get_it_property (it
, Qwrap_prefix
);
19130 prefix
= Vwrap_prefix
;
19134 prefix
= get_it_property (it
, Qline_prefix
);
19136 prefix
= Vline_prefix
;
19138 if (! NILP (prefix
) && push_prefix_prop (it
, prefix
))
19140 /* If the prefix is wider than the window, and we try to wrap
19141 it, it would acquire its own wrap prefix, and so on till the
19142 iterator stack overflows. So, don't wrap the prefix. */
19143 it
->line_wrap
= TRUNCATE
;
19144 it
->avoid_cursor_p
= 1;
19150 /* Remove N glyphs at the start of a reversed IT->glyph_row. Called
19151 only for R2L lines from display_line and display_string, when they
19152 decide that too many glyphs were produced by PRODUCE_GLYPHS, and
19153 the line/string needs to be continued on the next glyph row. */
19155 unproduce_glyphs (struct it
*it
, int n
)
19157 struct glyph
*glyph
, *end
;
19159 eassert (it
->glyph_row
);
19160 eassert (it
->glyph_row
->reversed_p
);
19161 eassert (it
->area
== TEXT_AREA
);
19162 eassert (n
<= it
->glyph_row
->used
[TEXT_AREA
]);
19164 if (n
> it
->glyph_row
->used
[TEXT_AREA
])
19165 n
= it
->glyph_row
->used
[TEXT_AREA
];
19166 glyph
= it
->glyph_row
->glyphs
[TEXT_AREA
] + n
;
19167 end
= it
->glyph_row
->glyphs
[TEXT_AREA
] + it
->glyph_row
->used
[TEXT_AREA
];
19168 for ( ; glyph
< end
; glyph
++)
19169 glyph
[-n
] = *glyph
;
19172 /* Find the positions in a bidi-reordered ROW to serve as ROW->minpos
19173 and ROW->maxpos. */
19175 find_row_edges (struct it
*it
, struct glyph_row
*row
,
19176 ptrdiff_t min_pos
, ptrdiff_t min_bpos
,
19177 ptrdiff_t max_pos
, ptrdiff_t max_bpos
)
19179 /* FIXME: Revisit this when glyph ``spilling'' in continuation
19180 lines' rows is implemented for bidi-reordered rows. */
19182 /* ROW->minpos is the value of min_pos, the minimal buffer position
19183 we have in ROW, or ROW->start.pos if that is smaller. */
19184 if (min_pos
<= ZV
&& min_pos
< row
->start
.pos
.charpos
)
19185 SET_TEXT_POS (row
->minpos
, min_pos
, min_bpos
);
19187 /* We didn't find buffer positions smaller than ROW->start, or
19188 didn't find _any_ valid buffer positions in any of the glyphs,
19189 so we must trust the iterator's computed positions. */
19190 row
->minpos
= row
->start
.pos
;
19193 max_pos
= CHARPOS (it
->current
.pos
);
19194 max_bpos
= BYTEPOS (it
->current
.pos
);
19197 /* Here are the various use-cases for ending the row, and the
19198 corresponding values for ROW->maxpos:
19200 Line ends in a newline from buffer eol_pos + 1
19201 Line is continued from buffer max_pos + 1
19202 Line is truncated on right it->current.pos
19203 Line ends in a newline from string max_pos + 1(*)
19204 (*) + 1 only when line ends in a forward scan
19205 Line is continued from string max_pos
19206 Line is continued from display vector max_pos
19207 Line is entirely from a string min_pos == max_pos
19208 Line is entirely from a display vector min_pos == max_pos
19209 Line that ends at ZV ZV
19211 If you discover other use-cases, please add them here as
19213 if (row
->ends_at_zv_p
)
19214 row
->maxpos
= it
->current
.pos
;
19215 else if (row
->used
[TEXT_AREA
])
19217 int seen_this_string
= 0;
19218 struct glyph_row
*r1
= row
- 1;
19220 /* Did we see the same display string on the previous row? */
19221 if (STRINGP (it
->object
)
19222 /* this is not the first row */
19223 && row
> it
->w
->desired_matrix
->rows
19224 /* previous row is not the header line */
19225 && !r1
->mode_line_p
19226 /* previous row also ends in a newline from a string */
19227 && r1
->ends_in_newline_from_string_p
)
19229 struct glyph
*start
, *end
;
19231 /* Search for the last glyph of the previous row that came
19232 from buffer or string. Depending on whether the row is
19233 L2R or R2L, we need to process it front to back or the
19234 other way round. */
19235 if (!r1
->reversed_p
)
19237 start
= r1
->glyphs
[TEXT_AREA
];
19238 end
= start
+ r1
->used
[TEXT_AREA
];
19239 /* Glyphs inserted by redisplay have an integer (zero)
19240 as their object. */
19242 && INTEGERP ((end
- 1)->object
)
19243 && (end
- 1)->charpos
<= 0)
19247 if (EQ ((end
- 1)->object
, it
->object
))
19248 seen_this_string
= 1;
19251 /* If all the glyphs of the previous row were inserted
19252 by redisplay, it means the previous row was
19253 produced from a single newline, which is only
19254 possible if that newline came from the same string
19255 as the one which produced this ROW. */
19256 seen_this_string
= 1;
19260 end
= r1
->glyphs
[TEXT_AREA
] - 1;
19261 start
= end
+ r1
->used
[TEXT_AREA
];
19263 && INTEGERP ((end
+ 1)->object
)
19264 && (end
+ 1)->charpos
<= 0)
19268 if (EQ ((end
+ 1)->object
, it
->object
))
19269 seen_this_string
= 1;
19272 seen_this_string
= 1;
19275 /* Take note of each display string that covers a newline only
19276 once, the first time we see it. This is for when a display
19277 string includes more than one newline in it. */
19278 if (row
->ends_in_newline_from_string_p
&& !seen_this_string
)
19280 /* If we were scanning the buffer forward when we displayed
19281 the string, we want to account for at least one buffer
19282 position that belongs to this row (position covered by
19283 the display string), so that cursor positioning will
19284 consider this row as a candidate when point is at the end
19285 of the visual line represented by this row. This is not
19286 required when scanning back, because max_pos will already
19287 have a much larger value. */
19288 if (CHARPOS (row
->end
.pos
) > max_pos
)
19289 INC_BOTH (max_pos
, max_bpos
);
19290 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19292 else if (CHARPOS (it
->eol_pos
) > 0)
19293 SET_TEXT_POS (row
->maxpos
,
19294 CHARPOS (it
->eol_pos
) + 1, BYTEPOS (it
->eol_pos
) + 1);
19295 else if (row
->continued_p
)
19297 /* If max_pos is different from IT's current position, it
19298 means IT->method does not belong to the display element
19299 at max_pos. However, it also means that the display
19300 element at max_pos was displayed in its entirety on this
19301 line, which is equivalent to saying that the next line
19302 starts at the next buffer position. */
19303 if (IT_CHARPOS (*it
) == max_pos
&& it
->method
!= GET_FROM_BUFFER
)
19304 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19307 INC_BOTH (max_pos
, max_bpos
);
19308 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19311 else if (row
->truncated_on_right_p
)
19312 /* display_line already called reseat_at_next_visible_line_start,
19313 which puts the iterator at the beginning of the next line, in
19314 the logical order. */
19315 row
->maxpos
= it
->current
.pos
;
19316 else if (max_pos
== min_pos
&& it
->method
!= GET_FROM_BUFFER
)
19317 /* A line that is entirely from a string/image/stretch... */
19318 row
->maxpos
= row
->minpos
;
19323 row
->maxpos
= it
->current
.pos
;
19326 /* Construct the glyph row IT->glyph_row in the desired matrix of
19327 IT->w from text at the current position of IT. See dispextern.h
19328 for an overview of struct it. Value is non-zero if
19329 IT->glyph_row displays text, as opposed to a line displaying ZV
19333 display_line (struct it
*it
)
19335 struct glyph_row
*row
= it
->glyph_row
;
19336 Lisp_Object overlay_arrow_string
;
19338 void *wrap_data
= NULL
;
19339 int may_wrap
= 0, wrap_x
IF_LINT (= 0);
19340 int wrap_row_used
= -1;
19341 int wrap_row_ascent
IF_LINT (= 0), wrap_row_height
IF_LINT (= 0);
19342 int wrap_row_phys_ascent
IF_LINT (= 0), wrap_row_phys_height
IF_LINT (= 0);
19343 int wrap_row_extra_line_spacing
IF_LINT (= 0);
19344 ptrdiff_t wrap_row_min_pos
IF_LINT (= 0), wrap_row_min_bpos
IF_LINT (= 0);
19345 ptrdiff_t wrap_row_max_pos
IF_LINT (= 0), wrap_row_max_bpos
IF_LINT (= 0);
19347 ptrdiff_t min_pos
= ZV
+ 1, max_pos
= 0;
19348 ptrdiff_t min_bpos
IF_LINT (= 0), max_bpos
IF_LINT (= 0);
19350 /* We always start displaying at hpos zero even if hscrolled. */
19351 eassert (it
->hpos
== 0 && it
->current_x
== 0);
19353 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
19354 >= it
->w
->desired_matrix
->nrows
)
19356 it
->w
->nrows_scale_factor
++;
19357 fonts_changed_p
= 1;
19361 /* Is IT->w showing the region? */
19362 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? it
->region_beg_charpos
: 0;
19364 /* Clear the result glyph row and enable it. */
19365 prepare_desired_row (row
);
19367 row
->y
= it
->current_y
;
19368 row
->start
= it
->start
;
19369 row
->continuation_lines_width
= it
->continuation_lines_width
;
19370 row
->displays_text_p
= 1;
19371 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
19372 it
->starts_in_middle_of_char_p
= 0;
19374 /* Arrange the overlays nicely for our purposes. Usually, we call
19375 display_line on only one line at a time, in which case this
19376 can't really hurt too much, or we call it on lines which appear
19377 one after another in the buffer, in which case all calls to
19378 recenter_overlay_lists but the first will be pretty cheap. */
19379 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
19381 /* Move over display elements that are not visible because we are
19382 hscrolled. This may stop at an x-position < IT->first_visible_x
19383 if the first glyph is partially visible or if we hit a line end. */
19384 if (it
->current_x
< it
->first_visible_x
)
19386 enum move_it_result move_result
;
19388 this_line_min_pos
= row
->start
.pos
;
19389 move_result
= move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
19390 MOVE_TO_POS
| MOVE_TO_X
);
19391 /* If we are under a large hscroll, move_it_in_display_line_to
19392 could hit the end of the line without reaching
19393 it->first_visible_x. Pretend that we did reach it. This is
19394 especially important on a TTY, where we will call
19395 extend_face_to_end_of_line, which needs to know how many
19396 blank glyphs to produce. */
19397 if (it
->current_x
< it
->first_visible_x
19398 && (move_result
== MOVE_NEWLINE_OR_CR
19399 || move_result
== MOVE_POS_MATCH_OR_ZV
))
19400 it
->current_x
= it
->first_visible_x
;
19402 /* Record the smallest positions seen while we moved over
19403 display elements that are not visible. This is needed by
19404 redisplay_internal for optimizing the case where the cursor
19405 stays inside the same line. The rest of this function only
19406 considers positions that are actually displayed, so
19407 RECORD_MAX_MIN_POS will not otherwise record positions that
19408 are hscrolled to the left of the left edge of the window. */
19409 min_pos
= CHARPOS (this_line_min_pos
);
19410 min_bpos
= BYTEPOS (this_line_min_pos
);
19414 /* We only do this when not calling `move_it_in_display_line_to'
19415 above, because move_it_in_display_line_to calls
19416 handle_line_prefix itself. */
19417 handle_line_prefix (it
);
19420 /* Get the initial row height. This is either the height of the
19421 text hscrolled, if there is any, or zero. */
19422 row
->ascent
= it
->max_ascent
;
19423 row
->height
= it
->max_ascent
+ it
->max_descent
;
19424 row
->phys_ascent
= it
->max_phys_ascent
;
19425 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
19426 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
19428 /* Utility macro to record max and min buffer positions seen until now. */
19429 #define RECORD_MAX_MIN_POS(IT) \
19432 int composition_p = !STRINGP ((IT)->string) \
19433 && ((IT)->what == IT_COMPOSITION); \
19434 ptrdiff_t current_pos = \
19435 composition_p ? (IT)->cmp_it.charpos \
19436 : IT_CHARPOS (*(IT)); \
19437 ptrdiff_t current_bpos = \
19438 composition_p ? CHAR_TO_BYTE (current_pos) \
19439 : IT_BYTEPOS (*(IT)); \
19440 if (current_pos < min_pos) \
19442 min_pos = current_pos; \
19443 min_bpos = current_bpos; \
19445 if (IT_CHARPOS (*it) > max_pos) \
19447 max_pos = IT_CHARPOS (*it); \
19448 max_bpos = IT_BYTEPOS (*it); \
19453 /* Loop generating characters. The loop is left with IT on the next
19454 character to display. */
19457 int n_glyphs_before
, hpos_before
, x_before
;
19459 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
19461 /* Retrieve the next thing to display. Value is zero if end of
19463 if (!get_next_display_element (it
))
19465 /* Maybe add a space at the end of this line that is used to
19466 display the cursor there under X. Set the charpos of the
19467 first glyph of blank lines not corresponding to any text
19469 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19470 row
->exact_window_width_line_p
= 1;
19471 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
19472 || row
->used
[TEXT_AREA
] == 0)
19474 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
19475 row
->displays_text_p
= 0;
19477 if (!NILP (BVAR (XBUFFER (it
->w
->contents
), indicate_empty_lines
))
19478 && (!MINI_WINDOW_P (it
->w
)
19479 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
19480 row
->indicate_empty_line_p
= 1;
19483 it
->continuation_lines_width
= 0;
19484 row
->ends_at_zv_p
= 1;
19485 /* A row that displays right-to-left text must always have
19486 its last face extended all the way to the end of line,
19487 even if this row ends in ZV, because we still write to
19488 the screen left to right. We also need to extend the
19489 last face if the default face is remapped to some
19490 different face, otherwise the functions that clear
19491 portions of the screen will clear with the default face's
19492 background color. */
19493 if (row
->reversed_p
19494 || lookup_basic_face (it
->f
, DEFAULT_FACE_ID
) != DEFAULT_FACE_ID
)
19495 extend_face_to_end_of_line (it
);
19499 /* Now, get the metrics of what we want to display. This also
19500 generates glyphs in `row' (which is IT->glyph_row). */
19501 n_glyphs_before
= row
->used
[TEXT_AREA
];
19504 /* Remember the line height so far in case the next element doesn't
19505 fit on the line. */
19506 if (it
->line_wrap
!= TRUNCATE
)
19508 ascent
= it
->max_ascent
;
19509 descent
= it
->max_descent
;
19510 phys_ascent
= it
->max_phys_ascent
;
19511 phys_descent
= it
->max_phys_descent
;
19513 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
19515 if (IT_DISPLAYING_WHITESPACE (it
))
19519 SAVE_IT (wrap_it
, *it
, wrap_data
);
19521 wrap_row_used
= row
->used
[TEXT_AREA
];
19522 wrap_row_ascent
= row
->ascent
;
19523 wrap_row_height
= row
->height
;
19524 wrap_row_phys_ascent
= row
->phys_ascent
;
19525 wrap_row_phys_height
= row
->phys_height
;
19526 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
19527 wrap_row_min_pos
= min_pos
;
19528 wrap_row_min_bpos
= min_bpos
;
19529 wrap_row_max_pos
= max_pos
;
19530 wrap_row_max_bpos
= max_bpos
;
19536 PRODUCE_GLYPHS (it
);
19538 /* If this display element was in marginal areas, continue with
19540 if (it
->area
!= TEXT_AREA
)
19542 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19543 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19544 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19545 row
->phys_height
= max (row
->phys_height
,
19546 it
->max_phys_ascent
+ it
->max_phys_descent
);
19547 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19548 it
->max_extra_line_spacing
);
19549 set_iterator_to_next (it
, 1);
19553 /* Does the display element fit on the line? If we truncate
19554 lines, we should draw past the right edge of the window. If
19555 we don't truncate, we want to stop so that we can display the
19556 continuation glyph before the right margin. If lines are
19557 continued, there are two possible strategies for characters
19558 resulting in more than 1 glyph (e.g. tabs): Display as many
19559 glyphs as possible in this line and leave the rest for the
19560 continuation line, or display the whole element in the next
19561 line. Original redisplay did the former, so we do it also. */
19562 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
19563 hpos_before
= it
->hpos
;
19566 if (/* Not a newline. */
19568 /* Glyphs produced fit entirely in the line. */
19569 && it
->current_x
< it
->last_visible_x
)
19571 it
->hpos
+= nglyphs
;
19572 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19573 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19574 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19575 row
->phys_height
= max (row
->phys_height
,
19576 it
->max_phys_ascent
+ it
->max_phys_descent
);
19577 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19578 it
->max_extra_line_spacing
);
19579 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
19580 row
->x
= x
- it
->first_visible_x
;
19581 /* Record the maximum and minimum buffer positions seen so
19582 far in glyphs that will be displayed by this row. */
19584 RECORD_MAX_MIN_POS (it
);
19589 struct glyph
*glyph
;
19591 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
19593 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
19594 new_x
= x
+ glyph
->pixel_width
;
19596 if (/* Lines are continued. */
19597 it
->line_wrap
!= TRUNCATE
19598 && (/* Glyph doesn't fit on the line. */
19599 new_x
> it
->last_visible_x
19600 /* Or it fits exactly on a window system frame. */
19601 || (new_x
== it
->last_visible_x
19602 && FRAME_WINDOW_P (it
->f
)
19603 && (row
->reversed_p
19604 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19605 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
19607 /* End of a continued line. */
19610 || (new_x
== it
->last_visible_x
19611 && FRAME_WINDOW_P (it
->f
)
19612 && (row
->reversed_p
19613 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19614 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
))))
19616 /* Current glyph is the only one on the line or
19617 fits exactly on the line. We must continue
19618 the line because we can't draw the cursor
19619 after the glyph. */
19620 row
->continued_p
= 1;
19621 it
->current_x
= new_x
;
19622 it
->continuation_lines_width
+= new_x
;
19624 if (i
== nglyphs
- 1)
19626 /* If line-wrap is on, check if a previous
19627 wrap point was found. */
19628 if (wrap_row_used
> 0
19629 /* Even if there is a previous wrap
19630 point, continue the line here as
19631 usual, if (i) the previous character
19632 was a space or tab AND (ii) the
19633 current character is not. */
19635 || IT_DISPLAYING_WHITESPACE (it
)))
19638 /* Record the maximum and minimum buffer
19639 positions seen so far in glyphs that will be
19640 displayed by this row. */
19642 RECORD_MAX_MIN_POS (it
);
19643 set_iterator_to_next (it
, 1);
19644 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19646 if (!get_next_display_element (it
))
19648 row
->exact_window_width_line_p
= 1;
19649 it
->continuation_lines_width
= 0;
19650 row
->continued_p
= 0;
19651 row
->ends_at_zv_p
= 1;
19653 else if (ITERATOR_AT_END_OF_LINE_P (it
))
19655 row
->continued_p
= 0;
19656 row
->exact_window_width_line_p
= 1;
19660 else if (it
->bidi_p
)
19661 RECORD_MAX_MIN_POS (it
);
19663 else if (CHAR_GLYPH_PADDING_P (*glyph
)
19664 && !FRAME_WINDOW_P (it
->f
))
19666 /* A padding glyph that doesn't fit on this line.
19667 This means the whole character doesn't fit
19669 if (row
->reversed_p
)
19670 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19671 - n_glyphs_before
);
19672 row
->used
[TEXT_AREA
] = n_glyphs_before
;
19674 /* Fill the rest of the row with continuation
19675 glyphs like in 20.x. */
19676 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
19677 < row
->glyphs
[1 + TEXT_AREA
])
19678 produce_special_glyphs (it
, IT_CONTINUATION
);
19680 row
->continued_p
= 1;
19681 it
->current_x
= x_before
;
19682 it
->continuation_lines_width
+= x_before
;
19684 /* Restore the height to what it was before the
19685 element not fitting on the line. */
19686 it
->max_ascent
= ascent
;
19687 it
->max_descent
= descent
;
19688 it
->max_phys_ascent
= phys_ascent
;
19689 it
->max_phys_descent
= phys_descent
;
19691 else if (wrap_row_used
> 0)
19694 if (row
->reversed_p
)
19695 unproduce_glyphs (it
,
19696 row
->used
[TEXT_AREA
] - wrap_row_used
);
19697 RESTORE_IT (it
, &wrap_it
, wrap_data
);
19698 it
->continuation_lines_width
+= wrap_x
;
19699 row
->used
[TEXT_AREA
] = wrap_row_used
;
19700 row
->ascent
= wrap_row_ascent
;
19701 row
->height
= wrap_row_height
;
19702 row
->phys_ascent
= wrap_row_phys_ascent
;
19703 row
->phys_height
= wrap_row_phys_height
;
19704 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
19705 min_pos
= wrap_row_min_pos
;
19706 min_bpos
= wrap_row_min_bpos
;
19707 max_pos
= wrap_row_max_pos
;
19708 max_bpos
= wrap_row_max_bpos
;
19709 row
->continued_p
= 1;
19710 row
->ends_at_zv_p
= 0;
19711 row
->exact_window_width_line_p
= 0;
19712 it
->continuation_lines_width
+= x
;
19714 /* Make sure that a non-default face is extended
19715 up to the right margin of the window. */
19716 extend_face_to_end_of_line (it
);
19718 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
19720 /* A TAB that extends past the right edge of the
19721 window. This produces a single glyph on
19722 window system frames. We leave the glyph in
19723 this row and let it fill the row, but don't
19724 consume the TAB. */
19725 if ((row
->reversed_p
19726 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19727 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19728 produce_special_glyphs (it
, IT_CONTINUATION
);
19729 it
->continuation_lines_width
+= it
->last_visible_x
;
19730 row
->ends_in_middle_of_char_p
= 1;
19731 row
->continued_p
= 1;
19732 glyph
->pixel_width
= it
->last_visible_x
- x
;
19733 it
->starts_in_middle_of_char_p
= 1;
19737 /* Something other than a TAB that draws past
19738 the right edge of the window. Restore
19739 positions to values before the element. */
19740 if (row
->reversed_p
)
19741 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19742 - (n_glyphs_before
+ i
));
19743 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
19745 /* Display continuation glyphs. */
19746 it
->current_x
= x_before
;
19747 it
->continuation_lines_width
+= x
;
19748 if (!FRAME_WINDOW_P (it
->f
)
19749 || (row
->reversed_p
19750 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19751 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19752 produce_special_glyphs (it
, IT_CONTINUATION
);
19753 row
->continued_p
= 1;
19755 extend_face_to_end_of_line (it
);
19757 if (nglyphs
> 1 && i
> 0)
19759 row
->ends_in_middle_of_char_p
= 1;
19760 it
->starts_in_middle_of_char_p
= 1;
19763 /* Restore the height to what it was before the
19764 element not fitting on the line. */
19765 it
->max_ascent
= ascent
;
19766 it
->max_descent
= descent
;
19767 it
->max_phys_ascent
= phys_ascent
;
19768 it
->max_phys_descent
= phys_descent
;
19773 else if (new_x
> it
->first_visible_x
)
19775 /* Increment number of glyphs actually displayed. */
19778 /* Record the maximum and minimum buffer positions
19779 seen so far in glyphs that will be displayed by
19782 RECORD_MAX_MIN_POS (it
);
19784 if (x
< it
->first_visible_x
)
19785 /* Glyph is partially visible, i.e. row starts at
19786 negative X position. */
19787 row
->x
= x
- it
->first_visible_x
;
19791 /* Glyph is completely off the left margin of the
19792 window. This should not happen because of the
19793 move_it_in_display_line at the start of this
19794 function, unless the text display area of the
19795 window is empty. */
19796 eassert (it
->first_visible_x
<= it
->last_visible_x
);
19799 /* Even if this display element produced no glyphs at all,
19800 we want to record its position. */
19801 if (it
->bidi_p
&& nglyphs
== 0)
19802 RECORD_MAX_MIN_POS (it
);
19804 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19805 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19806 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19807 row
->phys_height
= max (row
->phys_height
,
19808 it
->max_phys_ascent
+ it
->max_phys_descent
);
19809 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19810 it
->max_extra_line_spacing
);
19812 /* End of this display line if row is continued. */
19813 if (row
->continued_p
|| row
->ends_at_zv_p
)
19818 /* Is this a line end? If yes, we're also done, after making
19819 sure that a non-default face is extended up to the right
19820 margin of the window. */
19821 if (ITERATOR_AT_END_OF_LINE_P (it
))
19823 int used_before
= row
->used
[TEXT_AREA
];
19825 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
19827 /* Add a space at the end of the line that is used to
19828 display the cursor there. */
19829 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19830 append_space_for_newline (it
, 0);
19832 /* Extend the face to the end of the line. */
19833 extend_face_to_end_of_line (it
);
19835 /* Make sure we have the position. */
19836 if (used_before
== 0)
19837 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
19839 /* Record the position of the newline, for use in
19841 it
->eol_pos
= it
->current
.pos
;
19843 /* Consume the line end. This skips over invisible lines. */
19844 set_iterator_to_next (it
, 1);
19845 it
->continuation_lines_width
= 0;
19849 /* Proceed with next display element. Note that this skips
19850 over lines invisible because of selective display. */
19851 set_iterator_to_next (it
, 1);
19853 /* If we truncate lines, we are done when the last displayed
19854 glyphs reach past the right margin of the window. */
19855 if (it
->line_wrap
== TRUNCATE
19856 && (FRAME_WINDOW_P (it
->f
) && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
19857 ? (it
->current_x
>= it
->last_visible_x
)
19858 : (it
->current_x
> it
->last_visible_x
)))
19860 /* Maybe add truncation glyphs. */
19861 if (!FRAME_WINDOW_P (it
->f
)
19862 || (row
->reversed_p
19863 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19864 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19868 if (!row
->reversed_p
)
19870 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
19871 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19876 for (i
= 0; i
< row
->used
[TEXT_AREA
]; i
++)
19877 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19879 /* Remove any padding glyphs at the front of ROW, to
19880 make room for the truncation glyphs we will be
19881 adding below. The loop below always inserts at
19882 least one truncation glyph, so also remove the
19883 last glyph added to ROW. */
19884 unproduce_glyphs (it
, i
+ 1);
19885 /* Adjust i for the loop below. */
19886 i
= row
->used
[TEXT_AREA
] - (i
+ 1);
19889 it
->current_x
= x_before
;
19890 if (!FRAME_WINDOW_P (it
->f
))
19892 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
19894 row
->used
[TEXT_AREA
] = i
;
19895 produce_special_glyphs (it
, IT_TRUNCATION
);
19900 row
->used
[TEXT_AREA
] = i
;
19901 produce_special_glyphs (it
, IT_TRUNCATION
);
19904 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19906 /* Don't truncate if we can overflow newline into fringe. */
19907 if (!get_next_display_element (it
))
19909 it
->continuation_lines_width
= 0;
19910 row
->ends_at_zv_p
= 1;
19911 row
->exact_window_width_line_p
= 1;
19914 if (ITERATOR_AT_END_OF_LINE_P (it
))
19916 row
->exact_window_width_line_p
= 1;
19917 goto at_end_of_line
;
19919 it
->current_x
= x_before
;
19922 row
->truncated_on_right_p
= 1;
19923 it
->continuation_lines_width
= 0;
19924 reseat_at_next_visible_line_start (it
, 0);
19925 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
19926 it
->hpos
= hpos_before
;
19932 bidi_unshelve_cache (wrap_data
, 1);
19934 /* If line is not empty and hscrolled, maybe insert truncation glyphs
19935 at the left window margin. */
19936 if (it
->first_visible_x
19937 && IT_CHARPOS (*it
) != CHARPOS (row
->start
.pos
))
19939 if (!FRAME_WINDOW_P (it
->f
)
19940 || (row
->reversed_p
19941 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
19942 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
19943 insert_left_trunc_glyphs (it
);
19944 row
->truncated_on_left_p
= 1;
19947 /* Remember the position at which this line ends.
19949 BIDI Note: any code that needs MATRIX_ROW_START/END_CHARPOS
19950 cannot be before the call to find_row_edges below, since that is
19951 where these positions are determined. */
19952 row
->end
= it
->current
;
19955 row
->minpos
= row
->start
.pos
;
19956 row
->maxpos
= row
->end
.pos
;
19960 /* ROW->minpos and ROW->maxpos must be the smallest and
19961 `1 + the largest' buffer positions in ROW. But if ROW was
19962 bidi-reordered, these two positions can be anywhere in the
19963 row, so we must determine them now. */
19964 find_row_edges (it
, row
, min_pos
, min_bpos
, max_pos
, max_bpos
);
19967 /* If the start of this line is the overlay arrow-position, then
19968 mark this glyph row as the one containing the overlay arrow.
19969 This is clearly a mess with variable size fonts. It would be
19970 better to let it be displayed like cursors under X. */
19971 if ((MATRIX_ROW_DISPLAYS_TEXT_P (row
) || !overlay_arrow_seen
)
19972 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
19973 !NILP (overlay_arrow_string
)))
19975 /* Overlay arrow in window redisplay is a fringe bitmap. */
19976 if (STRINGP (overlay_arrow_string
))
19978 struct glyph_row
*arrow_row
19979 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
19980 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
19981 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
19982 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
19983 struct glyph
*p2
, *end
;
19985 /* Copy the arrow glyphs. */
19986 while (glyph
< arrow_end
)
19989 /* Throw away padding glyphs. */
19991 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
19992 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
19998 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
20003 eassert (INTEGERP (overlay_arrow_string
));
20004 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
20006 overlay_arrow_seen
= 1;
20009 /* Highlight trailing whitespace. */
20010 if (!NILP (Vshow_trailing_whitespace
))
20011 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
20013 /* Compute pixel dimensions of this line. */
20014 compute_line_metrics (it
);
20016 /* Implementation note: No changes in the glyphs of ROW or in their
20017 faces can be done past this point, because compute_line_metrics
20018 computes ROW's hash value and stores it within the glyph_row
20021 /* Record whether this row ends inside an ellipsis. */
20022 row
->ends_in_ellipsis_p
20023 = (it
->method
== GET_FROM_DISPLAY_VECTOR
20024 && it
->ellipsis_p
);
20026 /* Save fringe bitmaps in this row. */
20027 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
20028 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
20029 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
20030 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
20032 it
->left_user_fringe_bitmap
= 0;
20033 it
->left_user_fringe_face_id
= 0;
20034 it
->right_user_fringe_bitmap
= 0;
20035 it
->right_user_fringe_face_id
= 0;
20037 /* Maybe set the cursor. */
20038 cvpos
= it
->w
->cursor
.vpos
;
20040 /* In bidi-reordered rows, keep checking for proper cursor
20041 position even if one has been found already, because buffer
20042 positions in such rows change non-linearly with ROW->VPOS,
20043 when a line is continued. One exception: when we are at ZV,
20044 display cursor on the first suitable glyph row, since all
20045 the empty rows after that also have their position set to ZV. */
20046 /* FIXME: Revisit this when glyph ``spilling'' in continuation
20047 lines' rows is implemented for bidi-reordered rows. */
20049 && !MATRIX_ROW (it
->w
->desired_matrix
, cvpos
)->ends_at_zv_p
))
20050 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
20051 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
20052 && cursor_row_p (row
))
20053 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
20055 /* Prepare for the next line. This line starts horizontally at (X
20056 HPOS) = (0 0). Vertical positions are incremented. As a
20057 convenience for the caller, IT->glyph_row is set to the next
20059 it
->current_x
= it
->hpos
= 0;
20060 it
->current_y
+= row
->height
;
20061 SET_TEXT_POS (it
->eol_pos
, 0, 0);
20064 /* The next row should by default use the same value of the
20065 reversed_p flag as this one. set_iterator_to_next decides when
20066 it's a new paragraph, and PRODUCE_GLYPHS recomputes the value of
20067 the flag accordingly. */
20068 if (it
->glyph_row
< MATRIX_BOTTOM_TEXT_ROW (it
->w
->desired_matrix
, it
->w
))
20069 it
->glyph_row
->reversed_p
= row
->reversed_p
;
20070 it
->start
= row
->end
;
20071 return MATRIX_ROW_DISPLAYS_TEXT_P (row
);
20073 #undef RECORD_MAX_MIN_POS
20076 DEFUN ("current-bidi-paragraph-direction", Fcurrent_bidi_paragraph_direction
,
20077 Scurrent_bidi_paragraph_direction
, 0, 1, 0,
20078 doc
: /* Return paragraph direction at point in BUFFER.
20079 Value is either `left-to-right' or `right-to-left'.
20080 If BUFFER is omitted or nil, it defaults to the current buffer.
20082 Paragraph direction determines how the text in the paragraph is displayed.
20083 In left-to-right paragraphs, text begins at the left margin of the window
20084 and the reading direction is generally left to right. In right-to-left
20085 paragraphs, text begins at the right margin and is read from right to left.
20087 See also `bidi-paragraph-direction'. */)
20088 (Lisp_Object buffer
)
20090 struct buffer
*buf
= current_buffer
;
20091 struct buffer
*old
= buf
;
20093 if (! NILP (buffer
))
20095 CHECK_BUFFER (buffer
);
20096 buf
= XBUFFER (buffer
);
20099 if (NILP (BVAR (buf
, bidi_display_reordering
))
20100 || NILP (BVAR (buf
, enable_multibyte_characters
))
20101 /* When we are loading loadup.el, the character property tables
20102 needed for bidi iteration are not yet available. */
20103 || !NILP (Vpurify_flag
))
20104 return Qleft_to_right
;
20105 else if (!NILP (BVAR (buf
, bidi_paragraph_direction
)))
20106 return BVAR (buf
, bidi_paragraph_direction
);
20109 /* Determine the direction from buffer text. We could try to
20110 use current_matrix if it is up to date, but this seems fast
20111 enough as it is. */
20112 struct bidi_it itb
;
20113 ptrdiff_t pos
= BUF_PT (buf
);
20114 ptrdiff_t bytepos
= BUF_PT_BYTE (buf
);
20116 void *itb_data
= bidi_shelve_cache ();
20118 set_buffer_temp (buf
);
20119 /* bidi_paragraph_init finds the base direction of the paragraph
20120 by searching forward from paragraph start. We need the base
20121 direction of the current or _previous_ paragraph, so we need
20122 to make sure we are within that paragraph. To that end, find
20123 the previous non-empty line. */
20124 if (pos
>= ZV
&& pos
> BEGV
)
20125 DEC_BOTH (pos
, bytepos
);
20126 if (fast_looking_at (build_string ("[\f\t ]*\n"),
20127 pos
, bytepos
, ZV
, ZV_BYTE
, Qnil
) > 0)
20129 while ((c
= FETCH_BYTE (bytepos
)) == '\n'
20130 || c
== ' ' || c
== '\t' || c
== '\f')
20132 if (bytepos
<= BEGV_BYTE
)
20137 while (!CHAR_HEAD_P (FETCH_BYTE (bytepos
)))
20140 bidi_init_it (pos
, bytepos
, FRAME_WINDOW_P (SELECTED_FRAME ()), &itb
);
20141 itb
.paragraph_dir
= NEUTRAL_DIR
;
20142 itb
.string
.s
= NULL
;
20143 itb
.string
.lstring
= Qnil
;
20144 itb
.string
.bufpos
= 0;
20145 itb
.string
.unibyte
= 0;
20146 /* We have no window to use here for ignoring window-specific
20147 overlays. Using NULL for window pointer will cause
20148 compute_display_string_pos to use the current buffer. */
20150 bidi_paragraph_init (NEUTRAL_DIR
, &itb
, 1);
20151 bidi_unshelve_cache (itb_data
, 0);
20152 set_buffer_temp (old
);
20153 switch (itb
.paragraph_dir
)
20156 return Qleft_to_right
;
20159 return Qright_to_left
;
20167 DEFUN ("move-point-visually", Fmove_point_visually
,
20168 Smove_point_visually
, 1, 1, 0,
20169 doc
: /* Move point in the visual order in the specified DIRECTION.
20170 DIRECTION can be 1, meaning move to the right, or -1, which moves to the
20173 Value is the new character position of point. */)
20174 (Lisp_Object direction
)
20176 struct window
*w
= XWINDOW (selected_window
);
20177 struct buffer
*b
= XBUFFER (w
->contents
);
20178 struct glyph_row
*row
;
20180 Lisp_Object paragraph_dir
;
20182 #define ROW_GLYPH_NEWLINE_P(ROW,GLYPH) \
20183 (!(ROW)->continued_p \
20184 && INTEGERP ((GLYPH)->object) \
20185 && (GLYPH)->type == CHAR_GLYPH \
20186 && (GLYPH)->u.ch == ' ' \
20187 && (GLYPH)->charpos >= 0 \
20188 && !(GLYPH)->avoid_cursor_p)
20190 CHECK_NUMBER (direction
);
20191 dir
= XINT (direction
);
20197 /* If current matrix is up-to-date, we can use the information
20198 recorded in the glyphs, at least as long as the goal is on the
20200 if (w
->window_end_valid
20201 && !windows_or_buffers_changed
20203 && !b
->clip_changed
20204 && !b
->prevent_redisplay_optimizations_p
20205 && !window_outdated (w
)
20206 && w
->cursor
.vpos
>= 0
20207 && w
->cursor
.vpos
< w
->current_matrix
->nrows
20208 && (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
))->enabled_p
)
20210 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
20211 struct glyph
*e
= dir
> 0 ? g
+ row
->used
[TEXT_AREA
] : g
- 1;
20212 struct glyph
*gpt
= g
+ w
->cursor
.hpos
;
20214 for (g
= gpt
+ dir
; (dir
> 0 ? g
< e
: g
> e
); g
+= dir
)
20216 if (BUFFERP (g
->object
) && g
->charpos
!= PT
)
20218 SET_PT (g
->charpos
);
20219 w
->cursor
.vpos
= -1;
20220 return make_number (PT
);
20222 else if (!INTEGERP (g
->object
) && !EQ (g
->object
, gpt
->object
))
20226 if (BUFFERP (gpt
->object
))
20229 if ((gpt
->resolved_level
- row
->reversed_p
) % 2 == 0)
20230 new_pos
+= (row
->reversed_p
? -dir
: dir
);
20232 new_pos
-= (row
->reversed_p
? -dir
: dir
);;
20234 else if (BUFFERP (g
->object
))
20235 new_pos
= g
->charpos
;
20239 w
->cursor
.vpos
= -1;
20240 return make_number (PT
);
20242 else if (ROW_GLYPH_NEWLINE_P (row
, g
))
20244 /* Glyphs inserted at the end of a non-empty line for
20245 positioning the cursor have zero charpos, so we must
20246 deduce the value of point by other means. */
20247 if (g
->charpos
> 0)
20248 SET_PT (g
->charpos
);
20249 else if (row
->ends_at_zv_p
&& PT
!= ZV
)
20251 else if (PT
!= MATRIX_ROW_END_CHARPOS (row
) - 1)
20252 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
20255 w
->cursor
.vpos
= -1;
20256 return make_number (PT
);
20259 if (g
== e
|| INTEGERP (g
->object
))
20261 if (row
->truncated_on_left_p
|| row
->truncated_on_right_p
)
20262 goto simulate_display
;
20263 if (!row
->reversed_p
)
20267 if (row
< MATRIX_FIRST_TEXT_ROW (w
->current_matrix
)
20268 || row
> MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
20269 goto simulate_display
;
20273 if (row
->reversed_p
&& !row
->continued_p
)
20275 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
20276 w
->cursor
.vpos
= -1;
20277 return make_number (PT
);
20279 g
= row
->glyphs
[TEXT_AREA
];
20280 e
= g
+ row
->used
[TEXT_AREA
];
20281 for ( ; g
< e
; g
++)
20283 if (BUFFERP (g
->object
)
20284 /* Empty lines have only one glyph, which stands
20285 for the newline, and whose charpos is the
20286 buffer position of the newline. */
20287 || ROW_GLYPH_NEWLINE_P (row
, g
)
20288 /* When the buffer ends in a newline, the line at
20289 EOB also has one glyph, but its charpos is -1. */
20290 || (row
->ends_at_zv_p
20291 && !row
->reversed_p
20292 && INTEGERP (g
->object
)
20293 && g
->type
== CHAR_GLYPH
20294 && g
->u
.ch
== ' '))
20296 if (g
->charpos
> 0)
20297 SET_PT (g
->charpos
);
20298 else if (!row
->reversed_p
20299 && row
->ends_at_zv_p
20304 w
->cursor
.vpos
= -1;
20305 return make_number (PT
);
20311 if (!row
->reversed_p
&& !row
->continued_p
)
20313 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
20314 w
->cursor
.vpos
= -1;
20315 return make_number (PT
);
20317 e
= row
->glyphs
[TEXT_AREA
];
20318 g
= e
+ row
->used
[TEXT_AREA
] - 1;
20319 for ( ; g
>= e
; g
--)
20321 if (BUFFERP (g
->object
)
20322 || (ROW_GLYPH_NEWLINE_P (row
, g
)
20324 /* Empty R2L lines on GUI frames have the buffer
20325 position of the newline stored in the stretch
20327 || g
->type
== STRETCH_GLYPH
20328 || (row
->ends_at_zv_p
20330 && INTEGERP (g
->object
)
20331 && g
->type
== CHAR_GLYPH
20332 && g
->u
.ch
== ' '))
20334 if (g
->charpos
> 0)
20335 SET_PT (g
->charpos
);
20336 else if (row
->reversed_p
20337 && row
->ends_at_zv_p
20342 w
->cursor
.vpos
= -1;
20343 return make_number (PT
);
20352 /* If we wind up here, we failed to move by using the glyphs, so we
20353 need to simulate display instead. */
20356 paragraph_dir
= Fcurrent_bidi_paragraph_direction (w
->contents
);
20358 paragraph_dir
= Qleft_to_right
;
20359 if (EQ (paragraph_dir
, Qright_to_left
))
20361 if (PT
<= BEGV
&& dir
< 0)
20362 xsignal0 (Qbeginning_of_buffer
);
20363 else if (PT
>= ZV
&& dir
> 0)
20364 xsignal0 (Qend_of_buffer
);
20367 struct text_pos pt
;
20369 int pt_x
, target_x
, pixel_width
, pt_vpos
;
20371 bool overshoot_expected
= false;
20372 bool target_is_eol_p
= false;
20374 /* Setup the arena. */
20375 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
20376 start_display (&it
, w
, pt
);
20378 if (it
.cmp_it
.id
< 0
20379 && it
.method
== GET_FROM_STRING
20380 && it
.area
== TEXT_AREA
20381 && it
.string_from_display_prop_p
20382 && (it
.sp
> 0 && it
.stack
[it
.sp
- 1].method
== GET_FROM_BUFFER
))
20383 overshoot_expected
= true;
20385 /* Find the X coordinate of point. We start from the beginning
20386 of this or previous line to make sure we are before point in
20387 the logical order (since the move_it_* functions can only
20389 reseat_at_previous_visible_line_start (&it
);
20390 it
.current_x
= it
.hpos
= it
.current_y
= it
.vpos
= 0;
20391 if (IT_CHARPOS (it
) != PT
)
20392 move_it_to (&it
, overshoot_expected
? PT
- 1 : PT
,
20393 -1, -1, -1, MOVE_TO_POS
);
20394 pt_x
= it
.current_x
;
20396 if (dir
> 0 || overshoot_expected
)
20398 struct glyph_row
*row
= it
.glyph_row
;
20400 /* When point is at beginning of line, we don't have
20401 information about the glyph there loaded into struct
20402 it. Calling get_next_display_element fixes that. */
20404 get_next_display_element (&it
);
20405 at_eol_p
= ITERATOR_AT_END_OF_LINE_P (&it
);
20406 it
.glyph_row
= NULL
;
20407 PRODUCE_GLYPHS (&it
); /* compute it.pixel_width */
20408 it
.glyph_row
= row
;
20409 /* PRODUCE_GLYPHS advances it.current_x, so we must restore
20410 it, lest it will become out of sync with it's buffer
20412 it
.current_x
= pt_x
;
20415 at_eol_p
= ITERATOR_AT_END_OF_LINE_P (&it
);
20416 pixel_width
= it
.pixel_width
;
20417 if (overshoot_expected
&& at_eol_p
)
20419 else if (pixel_width
<= 0)
20422 /* If there's a display string at point, we are actually at the
20423 glyph to the left of point, so we need to correct the X
20425 if (overshoot_expected
)
20426 pt_x
+= pixel_width
;
20428 /* Compute target X coordinate, either to the left or to the
20429 right of point. On TTY frames, all characters have the same
20430 pixel width of 1, so we can use that. On GUI frames we don't
20431 have an easy way of getting at the pixel width of the
20432 character to the left of point, so we use a different method
20433 of getting to that place. */
20435 target_x
= pt_x
+ pixel_width
;
20437 target_x
= pt_x
- (!FRAME_WINDOW_P (it
.f
)) * pixel_width
;
20439 /* Target X coordinate could be one line above or below the line
20440 of point, in which case we need to adjust the target X
20441 coordinate. Also, if moving to the left, we need to begin at
20442 the left edge of the point's screen line. */
20447 start_display (&it
, w
, pt
);
20448 reseat_at_previous_visible_line_start (&it
);
20449 it
.current_x
= it
.current_y
= it
.hpos
= 0;
20451 move_it_by_lines (&it
, pt_vpos
);
20455 move_it_by_lines (&it
, -1);
20456 target_x
= it
.last_visible_x
- !FRAME_WINDOW_P (it
.f
);
20457 target_is_eol_p
= true;
20463 || (target_x
>= it
.last_visible_x
20464 && it
.line_wrap
!= TRUNCATE
))
20467 move_it_by_lines (&it
, 0);
20468 move_it_by_lines (&it
, 1);
20473 /* Move to the target X coordinate. */
20474 #ifdef HAVE_WINDOW_SYSTEM
20475 /* On GUI frames, as we don't know the X coordinate of the
20476 character to the left of point, moving point to the left
20477 requires walking, one grapheme cluster at a time, until we
20478 find ourself at a place immediately to the left of the
20479 character at point. */
20480 if (FRAME_WINDOW_P (it
.f
) && dir
< 0)
20482 struct text_pos new_pos
= it
.current
.pos
;
20483 enum move_it_result rc
= MOVE_X_REACHED
;
20485 while (it
.current_x
+ it
.pixel_width
<= target_x
20486 && rc
== MOVE_X_REACHED
)
20488 int new_x
= it
.current_x
+ it
.pixel_width
;
20490 new_pos
= it
.current
.pos
;
20491 if (new_x
== it
.current_x
)
20493 rc
= move_it_in_display_line_to (&it
, ZV
, new_x
,
20494 MOVE_TO_POS
| MOVE_TO_X
);
20495 if (ITERATOR_AT_END_OF_LINE_P (&it
) && !target_is_eol_p
)
20498 /* If we ended up on a composed character inside
20499 bidi-reordered text (e.g., Hebrew text with diacritics),
20500 the iterator gives us the buffer position of the last (in
20501 logical order) character of the composed grapheme cluster,
20502 which is not what we want. So we cheat: we compute the
20503 character position of the character that follows (in the
20504 logical order) the one where the above loop stopped. That
20505 character will appear on display to the left of point. */
20507 && it
.bidi_it
.scan_dir
== -1
20508 && new_pos
.charpos
- IT_CHARPOS (it
) > 1)
20510 new_pos
.charpos
= IT_CHARPOS (it
) + 1;
20511 new_pos
.bytepos
= CHAR_TO_BYTE (new_pos
.charpos
);
20513 it
.current
.pos
= new_pos
;
20517 if (it
.current_x
!= target_x
)
20518 move_it_in_display_line_to (&it
, ZV
, target_x
, MOVE_TO_POS
| MOVE_TO_X
);
20520 /* When lines are truncated, the above loop will stop at the
20521 window edge. But we want to get to the end of line, even if
20522 it is beyond the window edge; automatic hscroll will then
20523 scroll the window to show point as appropriate. */
20524 if (target_is_eol_p
&& it
.line_wrap
== TRUNCATE
20525 && get_next_display_element (&it
))
20527 struct text_pos new_pos
= it
.current
.pos
;
20529 while (!ITERATOR_AT_END_OF_LINE_P (&it
))
20531 set_iterator_to_next (&it
, 0);
20532 if (it
.method
== GET_FROM_BUFFER
)
20533 new_pos
= it
.current
.pos
;
20534 if (!get_next_display_element (&it
))
20538 it
.current
.pos
= new_pos
;
20541 /* If we ended up in a display string that covers point, move to
20542 buffer position to the right in the visual order. */
20545 while (IT_CHARPOS (it
) == PT
)
20547 set_iterator_to_next (&it
, 0);
20548 if (!get_next_display_element (&it
))
20553 /* Move point to that position. */
20554 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
20557 return make_number (PT
);
20559 #undef ROW_GLYPH_NEWLINE_P
20563 /***********************************************************************
20565 ***********************************************************************/
20567 /* Redisplay the menu bar in the frame for window W.
20569 The menu bar of X frames that don't have X toolkit support is
20570 displayed in a special window W->frame->menu_bar_window.
20572 The menu bar of terminal frames is treated specially as far as
20573 glyph matrices are concerned. Menu bar lines are not part of
20574 windows, so the update is done directly on the frame matrix rows
20575 for the menu bar. */
20578 display_menu_bar (struct window
*w
)
20580 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20585 /* Don't do all this for graphical frames. */
20587 if (FRAME_W32_P (f
))
20590 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
20596 if (FRAME_NS_P (f
))
20598 #endif /* HAVE_NS */
20600 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
20601 eassert (!FRAME_WINDOW_P (f
));
20602 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
20603 it
.first_visible_x
= 0;
20604 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
20605 #elif defined (HAVE_X_WINDOWS) /* X without toolkit. */
20606 if (FRAME_WINDOW_P (f
))
20608 /* Menu bar lines are displayed in the desired matrix of the
20609 dummy window menu_bar_window. */
20610 struct window
*menu_w
;
20611 menu_w
= XWINDOW (f
->menu_bar_window
);
20612 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
20614 it
.first_visible_x
= 0;
20615 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
20618 #endif /* not USE_X_TOOLKIT and not USE_GTK */
20620 /* This is a TTY frame, i.e. character hpos/vpos are used as
20622 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
20624 it
.first_visible_x
= 0;
20625 it
.last_visible_x
= FRAME_COLS (f
);
20628 /* FIXME: This should be controlled by a user option. See the
20629 comments in redisplay_tool_bar and display_mode_line about
20631 it
.paragraph_embedding
= L2R
;
20633 /* Clear all rows of the menu bar. */
20634 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
20636 struct glyph_row
*row
= it
.glyph_row
+ i
;
20637 clear_glyph_row (row
);
20638 row
->enabled_p
= 1;
20639 row
->full_width_p
= 1;
20642 /* Display all items of the menu bar. */
20643 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
20644 for (i
= 0; i
< ASIZE (items
); i
+= 4)
20646 Lisp_Object string
;
20648 /* Stop at nil string. */
20649 string
= AREF (items
, i
+ 1);
20653 /* Remember where item was displayed. */
20654 ASET (items
, i
+ 3, make_number (it
.hpos
));
20656 /* Display the item, pad with one space. */
20657 if (it
.current_x
< it
.last_visible_x
)
20658 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
20659 SCHARS (string
) + 1, 0, 0, -1);
20662 /* Fill out the line with spaces. */
20663 if (it
.current_x
< it
.last_visible_x
)
20664 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
20666 /* Compute the total height of the lines. */
20667 compute_line_metrics (&it
);
20672 /***********************************************************************
20674 ***********************************************************************/
20676 /* Redisplay mode lines in the window tree whose root is WINDOW. If
20677 FORCE is non-zero, redisplay mode lines unconditionally.
20678 Otherwise, redisplay only mode lines that are garbaged. Value is
20679 the number of windows whose mode lines were redisplayed. */
20682 redisplay_mode_lines (Lisp_Object window
, int force
)
20686 while (!NILP (window
))
20688 struct window
*w
= XWINDOW (window
);
20690 if (WINDOWP (w
->contents
))
20691 nwindows
+= redisplay_mode_lines (w
->contents
, force
);
20693 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
20694 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
20696 struct text_pos lpoint
;
20697 struct buffer
*old
= current_buffer
;
20699 /* Set the window's buffer for the mode line display. */
20700 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
20701 set_buffer_internal_1 (XBUFFER (w
->contents
));
20703 /* Point refers normally to the selected window. For any
20704 other window, set up appropriate value. */
20705 if (!EQ (window
, selected_window
))
20707 struct text_pos pt
;
20709 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
20710 if (CHARPOS (pt
) < BEGV
)
20711 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
20712 else if (CHARPOS (pt
) > (ZV
- 1))
20713 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
20715 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
20718 /* Display mode lines. */
20719 clear_glyph_matrix (w
->desired_matrix
);
20720 if (display_mode_lines (w
))
20723 w
->must_be_updated_p
= 1;
20726 /* Restore old settings. */
20727 set_buffer_internal_1 (old
);
20728 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
20738 /* Display the mode and/or header line of window W. Value is the
20739 sum number of mode lines and header lines displayed. */
20742 display_mode_lines (struct window
*w
)
20744 Lisp_Object old_selected_window
= selected_window
;
20745 Lisp_Object old_selected_frame
= selected_frame
;
20746 Lisp_Object new_frame
= w
->frame
;
20747 Lisp_Object old_frame_selected_window
= XFRAME (new_frame
)->selected_window
;
20750 selected_frame
= new_frame
;
20751 /* FIXME: If we were to allow the mode-line's computation changing the buffer
20752 or window's point, then we'd need select_window_1 here as well. */
20753 XSETWINDOW (selected_window
, w
);
20754 XFRAME (new_frame
)->selected_window
= selected_window
;
20756 /* These will be set while the mode line specs are processed. */
20757 line_number_displayed
= 0;
20758 w
->column_number_displayed
= -1;
20760 if (WINDOW_WANTS_MODELINE_P (w
))
20762 struct window
*sel_w
= XWINDOW (old_selected_window
);
20764 /* Select mode line face based on the real selected window. */
20765 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
20766 BVAR (current_buffer
, mode_line_format
));
20770 if (WINDOW_WANTS_HEADER_LINE_P (w
))
20772 display_mode_line (w
, HEADER_LINE_FACE_ID
,
20773 BVAR (current_buffer
, header_line_format
));
20777 XFRAME (new_frame
)->selected_window
= old_frame_selected_window
;
20778 selected_frame
= old_selected_frame
;
20779 selected_window
= old_selected_window
;
20784 /* Display mode or header line of window W. FACE_ID specifies which
20785 line to display; it is either MODE_LINE_FACE_ID or
20786 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
20787 display. Value is the pixel height of the mode/header line
20791 display_mode_line (struct window
*w
, enum face_id face_id
, Lisp_Object format
)
20795 ptrdiff_t count
= SPECPDL_INDEX ();
20797 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
20798 /* Don't extend on a previously drawn mode-line.
20799 This may happen if called from pos_visible_p. */
20800 it
.glyph_row
->enabled_p
= 0;
20801 prepare_desired_row (it
.glyph_row
);
20803 it
.glyph_row
->mode_line_p
= 1;
20805 /* FIXME: This should be controlled by a user option. But
20806 supporting such an option is not trivial, since the mode line is
20807 made up of many separate strings. */
20808 it
.paragraph_embedding
= L2R
;
20810 record_unwind_protect (unwind_format_mode_line
,
20811 format_mode_line_unwind_data (NULL
, NULL
, Qnil
, 0));
20813 mode_line_target
= MODE_LINE_DISPLAY
;
20815 /* Temporarily make frame's keyboard the current kboard so that
20816 kboard-local variables in the mode_line_format will get the right
20818 push_kboard (FRAME_KBOARD (it
.f
));
20819 record_unwind_save_match_data ();
20820 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
20823 unbind_to (count
, Qnil
);
20825 /* Fill up with spaces. */
20826 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
20828 compute_line_metrics (&it
);
20829 it
.glyph_row
->full_width_p
= 1;
20830 it
.glyph_row
->continued_p
= 0;
20831 it
.glyph_row
->truncated_on_left_p
= 0;
20832 it
.glyph_row
->truncated_on_right_p
= 0;
20834 /* Make a 3D mode-line have a shadow at its right end. */
20835 face
= FACE_FROM_ID (it
.f
, face_id
);
20836 extend_face_to_end_of_line (&it
);
20837 if (face
->box
!= FACE_NO_BOX
)
20839 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
20840 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
20841 last
->right_box_line_p
= 1;
20844 return it
.glyph_row
->height
;
20847 /* Move element ELT in LIST to the front of LIST.
20848 Return the updated list. */
20851 move_elt_to_front (Lisp_Object elt
, Lisp_Object list
)
20853 register Lisp_Object tail
, prev
;
20854 register Lisp_Object tem
;
20858 while (CONSP (tail
))
20864 /* Splice out the link TAIL. */
20866 list
= XCDR (tail
);
20868 Fsetcdr (prev
, XCDR (tail
));
20870 /* Now make it the first. */
20871 Fsetcdr (tail
, list
);
20876 tail
= XCDR (tail
);
20880 /* Not found--return unchanged LIST. */
20884 /* Contribute ELT to the mode line for window IT->w. How it
20885 translates into text depends on its data type.
20887 IT describes the display environment in which we display, as usual.
20889 DEPTH is the depth in recursion. It is used to prevent
20890 infinite recursion here.
20892 FIELD_WIDTH is the number of characters the display of ELT should
20893 occupy in the mode line, and PRECISION is the maximum number of
20894 characters to display from ELT's representation. See
20895 display_string for details.
20897 Returns the hpos of the end of the text generated by ELT.
20899 PROPS is a property list to add to any string we encounter.
20901 If RISKY is nonzero, remove (disregard) any properties in any string
20902 we encounter, and ignore :eval and :propertize.
20904 The global variable `mode_line_target' determines whether the
20905 output is passed to `store_mode_line_noprop',
20906 `store_mode_line_string', or `display_string'. */
20909 display_mode_element (struct it
*it
, int depth
, int field_width
, int precision
,
20910 Lisp_Object elt
, Lisp_Object props
, int risky
)
20912 int n
= 0, field
, prec
;
20917 elt
= build_string ("*too-deep*");
20921 switch (XTYPE (elt
))
20925 /* A string: output it and check for %-constructs within it. */
20927 ptrdiff_t offset
= 0;
20929 if (SCHARS (elt
) > 0
20930 && (!NILP (props
) || risky
))
20932 Lisp_Object oprops
, aelt
;
20933 oprops
= Ftext_properties_at (make_number (0), elt
);
20935 /* If the starting string's properties are not what
20936 we want, translate the string. Also, if the string
20937 is risky, do that anyway. */
20939 if (NILP (Fequal (props
, oprops
)) || risky
)
20941 /* If the starting string has properties,
20942 merge the specified ones onto the existing ones. */
20943 if (! NILP (oprops
) && !risky
)
20947 oprops
= Fcopy_sequence (oprops
);
20949 while (CONSP (tem
))
20951 oprops
= Fplist_put (oprops
, XCAR (tem
),
20952 XCAR (XCDR (tem
)));
20953 tem
= XCDR (XCDR (tem
));
20958 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
20959 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
20961 /* AELT is what we want. Move it to the front
20962 without consing. */
20964 mode_line_proptrans_alist
20965 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
20971 /* If AELT has the wrong props, it is useless.
20972 so get rid of it. */
20974 mode_line_proptrans_alist
20975 = Fdelq (aelt
, mode_line_proptrans_alist
);
20977 elt
= Fcopy_sequence (elt
);
20978 Fset_text_properties (make_number (0), Flength (elt
),
20980 /* Add this item to mode_line_proptrans_alist. */
20981 mode_line_proptrans_alist
20982 = Fcons (Fcons (elt
, props
),
20983 mode_line_proptrans_alist
);
20984 /* Truncate mode_line_proptrans_alist
20985 to at most 50 elements. */
20986 tem
= Fnthcdr (make_number (50),
20987 mode_line_proptrans_alist
);
20989 XSETCDR (tem
, Qnil
);
20998 prec
= precision
- n
;
20999 switch (mode_line_target
)
21001 case MODE_LINE_NOPROP
:
21002 case MODE_LINE_TITLE
:
21003 n
+= store_mode_line_noprop (SSDATA (elt
), -1, prec
);
21005 case MODE_LINE_STRING
:
21006 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
21008 case MODE_LINE_DISPLAY
:
21009 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
21010 0, prec
, 0, STRING_MULTIBYTE (elt
));
21017 /* Handle the non-literal case. */
21019 while ((precision
<= 0 || n
< precision
)
21020 && SREF (elt
, offset
) != 0
21021 && (mode_line_target
!= MODE_LINE_DISPLAY
21022 || it
->current_x
< it
->last_visible_x
))
21024 ptrdiff_t last_offset
= offset
;
21026 /* Advance to end of string or next format specifier. */
21027 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
21030 if (offset
- 1 != last_offset
)
21032 ptrdiff_t nchars
, nbytes
;
21034 /* Output to end of string or up to '%'. Field width
21035 is length of string. Don't output more than
21036 PRECISION allows us. */
21039 prec
= c_string_width (SDATA (elt
) + last_offset
,
21040 offset
- last_offset
, precision
- n
,
21043 switch (mode_line_target
)
21045 case MODE_LINE_NOPROP
:
21046 case MODE_LINE_TITLE
:
21047 n
+= store_mode_line_noprop (SSDATA (elt
) + last_offset
, 0, prec
);
21049 case MODE_LINE_STRING
:
21051 ptrdiff_t bytepos
= last_offset
;
21052 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
21053 ptrdiff_t endpos
= (precision
<= 0
21054 ? string_byte_to_char (elt
, offset
)
21055 : charpos
+ nchars
);
21057 n
+= store_mode_line_string (NULL
,
21058 Fsubstring (elt
, make_number (charpos
),
21059 make_number (endpos
)),
21063 case MODE_LINE_DISPLAY
:
21065 ptrdiff_t bytepos
= last_offset
;
21066 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
21068 if (precision
<= 0)
21069 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
21070 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
21072 STRING_MULTIBYTE (elt
));
21077 else /* c == '%' */
21079 ptrdiff_t percent_position
= offset
;
21081 /* Get the specified minimum width. Zero means
21084 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
21085 field
= field
* 10 + c
- '0';
21087 /* Don't pad beyond the total padding allowed. */
21088 if (field_width
- n
> 0 && field
> field_width
- n
)
21089 field
= field_width
- n
;
21091 /* Note that either PRECISION <= 0 or N < PRECISION. */
21092 prec
= precision
- n
;
21095 n
+= display_mode_element (it
, depth
, field
, prec
,
21096 Vglobal_mode_string
, props
,
21101 ptrdiff_t bytepos
, charpos
;
21103 Lisp_Object string
;
21105 bytepos
= percent_position
;
21106 charpos
= (STRING_MULTIBYTE (elt
)
21107 ? string_byte_to_char (elt
, bytepos
)
21109 spec
= decode_mode_spec (it
->w
, c
, field
, &string
);
21110 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
21112 switch (mode_line_target
)
21114 case MODE_LINE_NOPROP
:
21115 case MODE_LINE_TITLE
:
21116 n
+= store_mode_line_noprop (spec
, field
, prec
);
21118 case MODE_LINE_STRING
:
21120 Lisp_Object tem
= build_string (spec
);
21121 props
= Ftext_properties_at (make_number (charpos
), elt
);
21122 /* Should only keep face property in props */
21123 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
21126 case MODE_LINE_DISPLAY
:
21128 int nglyphs_before
, nwritten
;
21130 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
21131 nwritten
= display_string (spec
, string
, elt
,
21136 /* Assign to the glyphs written above the
21137 string where the `%x' came from, position
21141 struct glyph
*glyph
21142 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
21146 for (i
= 0; i
< nwritten
; ++i
)
21148 glyph
[i
].object
= elt
;
21149 glyph
[i
].charpos
= charpos
;
21166 /* A symbol: process the value of the symbol recursively
21167 as if it appeared here directly. Avoid error if symbol void.
21168 Special case: if value of symbol is a string, output the string
21171 register Lisp_Object tem
;
21173 /* If the variable is not marked as risky to set
21174 then its contents are risky to use. */
21175 if (NILP (Fget (elt
, Qrisky_local_variable
)))
21178 tem
= Fboundp (elt
);
21181 tem
= Fsymbol_value (elt
);
21182 /* If value is a string, output that string literally:
21183 don't check for % within it. */
21187 if (!EQ (tem
, elt
))
21189 /* Give up right away for nil or t. */
21199 register Lisp_Object car
, tem
;
21201 /* A cons cell: five distinct cases.
21202 If first element is :eval or :propertize, do something special.
21203 If first element is a string or a cons, process all the elements
21204 and effectively concatenate them.
21205 If first element is a negative number, truncate displaying cdr to
21206 at most that many characters. If positive, pad (with spaces)
21207 to at least that many characters.
21208 If first element is a symbol, process the cadr or caddr recursively
21209 according to whether the symbol's value is non-nil or nil. */
21211 if (EQ (car
, QCeval
))
21213 /* An element of the form (:eval FORM) means evaluate FORM
21214 and use the result as mode line elements. */
21219 if (CONSP (XCDR (elt
)))
21222 spec
= safe_eval (XCAR (XCDR (elt
)));
21223 n
+= display_mode_element (it
, depth
, field_width
- n
,
21224 precision
- n
, spec
, props
,
21228 else if (EQ (car
, QCpropertize
))
21230 /* An element of the form (:propertize ELT PROPS...)
21231 means display ELT but applying properties PROPS. */
21236 if (CONSP (XCDR (elt
)))
21237 n
+= display_mode_element (it
, depth
, field_width
- n
,
21238 precision
- n
, XCAR (XCDR (elt
)),
21239 XCDR (XCDR (elt
)), risky
);
21241 else if (SYMBOLP (car
))
21243 tem
= Fboundp (car
);
21247 /* elt is now the cdr, and we know it is a cons cell.
21248 Use its car if CAR has a non-nil value. */
21251 tem
= Fsymbol_value (car
);
21258 /* Symbol's value is nil (or symbol is unbound)
21259 Get the cddr of the original list
21260 and if possible find the caddr and use that. */
21264 else if (!CONSP (elt
))
21269 else if (INTEGERP (car
))
21271 register int lim
= XINT (car
);
21275 /* Negative int means reduce maximum width. */
21276 if (precision
<= 0)
21279 precision
= min (precision
, -lim
);
21283 /* Padding specified. Don't let it be more than
21284 current maximum. */
21286 lim
= min (precision
, lim
);
21288 /* If that's more padding than already wanted, queue it.
21289 But don't reduce padding already specified even if
21290 that is beyond the current truncation point. */
21291 field_width
= max (lim
, field_width
);
21295 else if (STRINGP (car
) || CONSP (car
))
21297 Lisp_Object halftail
= elt
;
21301 && (precision
<= 0 || n
< precision
))
21303 n
+= display_mode_element (it
, depth
,
21304 /* Do padding only after the last
21305 element in the list. */
21306 (! CONSP (XCDR (elt
))
21309 precision
- n
, XCAR (elt
),
21313 if ((len
& 1) == 0)
21314 halftail
= XCDR (halftail
);
21315 /* Check for cycle. */
21316 if (EQ (halftail
, elt
))
21325 elt
= build_string ("*invalid*");
21329 /* Pad to FIELD_WIDTH. */
21330 if (field_width
> 0 && n
< field_width
)
21332 switch (mode_line_target
)
21334 case MODE_LINE_NOPROP
:
21335 case MODE_LINE_TITLE
:
21336 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
21338 case MODE_LINE_STRING
:
21339 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
21341 case MODE_LINE_DISPLAY
:
21342 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
21351 /* Store a mode-line string element in mode_line_string_list.
21353 If STRING is non-null, display that C string. Otherwise, the Lisp
21354 string LISP_STRING is displayed.
21356 FIELD_WIDTH is the minimum number of output glyphs to produce.
21357 If STRING has fewer characters than FIELD_WIDTH, pad to the right
21358 with spaces. FIELD_WIDTH <= 0 means don't pad.
21360 PRECISION is the maximum number of characters to output from
21361 STRING. PRECISION <= 0 means don't truncate the string.
21363 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
21364 properties to the string.
21366 PROPS are the properties to add to the string.
21367 The mode_line_string_face face property is always added to the string.
21371 store_mode_line_string (const char *string
, Lisp_Object lisp_string
, int copy_string
,
21372 int field_width
, int precision
, Lisp_Object props
)
21377 if (string
!= NULL
)
21379 len
= strlen (string
);
21380 if (precision
> 0 && len
> precision
)
21382 lisp_string
= make_string (string
, len
);
21384 props
= mode_line_string_face_prop
;
21385 else if (!NILP (mode_line_string_face
))
21387 Lisp_Object face
= Fplist_get (props
, Qface
);
21388 props
= Fcopy_sequence (props
);
21390 face
= mode_line_string_face
;
21392 face
= list2 (face
, mode_line_string_face
);
21393 props
= Fplist_put (props
, Qface
, face
);
21395 Fadd_text_properties (make_number (0), make_number (len
),
21396 props
, lisp_string
);
21400 len
= XFASTINT (Flength (lisp_string
));
21401 if (precision
> 0 && len
> precision
)
21404 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
21407 if (!NILP (mode_line_string_face
))
21411 props
= Ftext_properties_at (make_number (0), lisp_string
);
21412 face
= Fplist_get (props
, Qface
);
21414 face
= mode_line_string_face
;
21416 face
= list2 (face
, mode_line_string_face
);
21417 props
= list2 (Qface
, face
);
21419 lisp_string
= Fcopy_sequence (lisp_string
);
21422 Fadd_text_properties (make_number (0), make_number (len
),
21423 props
, lisp_string
);
21428 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
21432 if (field_width
> len
)
21434 field_width
-= len
;
21435 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
21437 Fadd_text_properties (make_number (0), make_number (field_width
),
21438 props
, lisp_string
);
21439 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
21447 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
21449 doc
: /* Format a string out of a mode line format specification.
21450 First arg FORMAT specifies the mode line format (see `mode-line-format'
21451 for details) to use.
21453 By default, the format is evaluated for the currently selected window.
21455 Optional second arg FACE specifies the face property to put on all
21456 characters for which no face is specified. The value nil means the
21457 default face. The value t means whatever face the window's mode line
21458 currently uses (either `mode-line' or `mode-line-inactive',
21459 depending on whether the window is the selected window or not).
21460 An integer value means the value string has no text
21463 Optional third and fourth args WINDOW and BUFFER specify the window
21464 and buffer to use as the context for the formatting (defaults
21465 are the selected window and the WINDOW's buffer). */)
21466 (Lisp_Object format
, Lisp_Object face
,
21467 Lisp_Object window
, Lisp_Object buffer
)
21472 struct buffer
*old_buffer
= NULL
;
21474 int no_props
= INTEGERP (face
);
21475 ptrdiff_t count
= SPECPDL_INDEX ();
21477 int string_start
= 0;
21479 w
= decode_any_window (window
);
21480 XSETWINDOW (window
, w
);
21483 buffer
= w
->contents
;
21484 CHECK_BUFFER (buffer
);
21486 /* Make formatting the modeline a non-op when noninteractive, otherwise
21487 there will be problems later caused by a partially initialized frame. */
21488 if (NILP (format
) || noninteractive
)
21489 return empty_unibyte_string
;
21494 face_id
= (NILP (face
) || EQ (face
, Qdefault
)) ? DEFAULT_FACE_ID
21495 : EQ (face
, Qt
) ? (EQ (window
, selected_window
)
21496 ? MODE_LINE_FACE_ID
: MODE_LINE_INACTIVE_FACE_ID
)
21497 : EQ (face
, Qmode_line
) ? MODE_LINE_FACE_ID
21498 : EQ (face
, Qmode_line_inactive
) ? MODE_LINE_INACTIVE_FACE_ID
21499 : EQ (face
, Qheader_line
) ? HEADER_LINE_FACE_ID
21500 : EQ (face
, Qtool_bar
) ? TOOL_BAR_FACE_ID
21503 old_buffer
= current_buffer
;
21505 /* Save things including mode_line_proptrans_alist,
21506 and set that to nil so that we don't alter the outer value. */
21507 record_unwind_protect (unwind_format_mode_line
,
21508 format_mode_line_unwind_data
21509 (XFRAME (WINDOW_FRAME (w
)),
21510 old_buffer
, selected_window
, 1));
21511 mode_line_proptrans_alist
= Qnil
;
21513 Fselect_window (window
, Qt
);
21514 set_buffer_internal_1 (XBUFFER (buffer
));
21516 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
21520 mode_line_target
= MODE_LINE_NOPROP
;
21521 mode_line_string_face_prop
= Qnil
;
21522 mode_line_string_list
= Qnil
;
21523 string_start
= MODE_LINE_NOPROP_LEN (0);
21527 mode_line_target
= MODE_LINE_STRING
;
21528 mode_line_string_list
= Qnil
;
21529 mode_line_string_face
= face
;
21530 mode_line_string_face_prop
21531 = NILP (face
) ? Qnil
: list2 (Qface
, face
);
21534 push_kboard (FRAME_KBOARD (it
.f
));
21535 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
21540 len
= MODE_LINE_NOPROP_LEN (string_start
);
21541 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
21545 mode_line_string_list
= Fnreverse (mode_line_string_list
);
21546 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
21547 empty_unibyte_string
);
21550 unbind_to (count
, Qnil
);
21554 /* Write a null-terminated, right justified decimal representation of
21555 the positive integer D to BUF using a minimal field width WIDTH. */
21558 pint2str (register char *buf
, register int width
, register ptrdiff_t d
)
21560 register char *p
= buf
;
21568 *p
++ = d
% 10 + '0';
21573 for (width
-= (int) (p
- buf
); width
> 0; --width
)
21584 /* Write a null-terminated, right justified decimal and "human
21585 readable" representation of the nonnegative integer D to BUF using
21586 a minimal field width WIDTH. D should be smaller than 999.5e24. */
21588 static const char power_letter
[] =
21602 pint2hrstr (char *buf
, int width
, ptrdiff_t d
)
21604 /* We aim to represent the nonnegative integer D as
21605 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
21606 ptrdiff_t quotient
= d
;
21608 /* -1 means: do not use TENTHS. */
21612 /* Length of QUOTIENT.TENTHS as a string. */
21618 if (quotient
>= 1000)
21620 /* Scale to the appropriate EXPONENT. */
21623 remainder
= quotient
% 1000;
21627 while (quotient
>= 1000);
21629 /* Round to nearest and decide whether to use TENTHS or not. */
21632 tenths
= remainder
/ 100;
21633 if (remainder
% 100 >= 50)
21640 if (quotient
== 10)
21648 if (remainder
>= 500)
21650 if (quotient
< 999)
21661 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
21662 if (tenths
== -1 && quotient
<= 99)
21669 p
= psuffix
= buf
+ max (width
, length
);
21671 /* Print EXPONENT. */
21672 *psuffix
++ = power_letter
[exponent
];
21675 /* Print TENTHS. */
21678 *--p
= '0' + tenths
;
21682 /* Print QUOTIENT. */
21685 int digit
= quotient
% 10;
21686 *--p
= '0' + digit
;
21688 while ((quotient
/= 10) != 0);
21690 /* Print leading spaces. */
21695 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
21696 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
21697 type of CODING_SYSTEM. Return updated pointer into BUF. */
21699 static unsigned char invalid_eol_type
[] = "(*invalid*)";
21702 decode_mode_spec_coding (Lisp_Object coding_system
, register char *buf
, int eol_flag
)
21705 bool multibyte
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
21706 const unsigned char *eol_str
;
21708 /* The EOL conversion we are using. */
21709 Lisp_Object eoltype
;
21711 val
= CODING_SYSTEM_SPEC (coding_system
);
21714 if (!VECTORP (val
)) /* Not yet decided. */
21716 *buf
++ = multibyte
? '-' : ' ';
21718 eoltype
= eol_mnemonic_undecided
;
21719 /* Don't mention EOL conversion if it isn't decided. */
21724 Lisp_Object eolvalue
;
21726 attrs
= AREF (val
, 0);
21727 eolvalue
= AREF (val
, 2);
21730 ? XFASTINT (CODING_ATTR_MNEMONIC (attrs
))
21735 /* The EOL conversion that is normal on this system. */
21737 if (NILP (eolvalue
)) /* Not yet decided. */
21738 eoltype
= eol_mnemonic_undecided
;
21739 else if (VECTORP (eolvalue
)) /* Not yet decided. */
21740 eoltype
= eol_mnemonic_undecided
;
21741 else /* eolvalue is Qunix, Qdos, or Qmac. */
21742 eoltype
= (EQ (eolvalue
, Qunix
)
21743 ? eol_mnemonic_unix
21744 : (EQ (eolvalue
, Qdos
) == 1
21745 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
21751 /* Mention the EOL conversion if it is not the usual one. */
21752 if (STRINGP (eoltype
))
21754 eol_str
= SDATA (eoltype
);
21755 eol_str_len
= SBYTES (eoltype
);
21757 else if (CHARACTERP (eoltype
))
21759 unsigned char *tmp
= alloca (MAX_MULTIBYTE_LENGTH
);
21760 int c
= XFASTINT (eoltype
);
21761 eol_str_len
= CHAR_STRING (c
, tmp
);
21766 eol_str
= invalid_eol_type
;
21767 eol_str_len
= sizeof (invalid_eol_type
) - 1;
21769 memcpy (buf
, eol_str
, eol_str_len
);
21770 buf
+= eol_str_len
;
21776 /* Return a string for the output of a mode line %-spec for window W,
21777 generated by character C. FIELD_WIDTH > 0 means pad the string
21778 returned with spaces to that value. Return a Lisp string in
21779 *STRING if the resulting string is taken from that Lisp string.
21781 Note we operate on the current buffer for most purposes. */
21783 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
21785 static const char *
21786 decode_mode_spec (struct window
*w
, register int c
, int field_width
,
21787 Lisp_Object
*string
)
21790 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21791 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
21792 /* We are going to use f->decode_mode_spec_buffer as the buffer to
21793 produce strings from numerical values, so limit preposterously
21794 large values of FIELD_WIDTH to avoid overrunning the buffer's
21795 end. The size of the buffer is enough for FRAME_MESSAGE_BUF_SIZE
21796 bytes plus the terminating null. */
21797 int width
= min (field_width
, FRAME_MESSAGE_BUF_SIZE (f
));
21798 struct buffer
*b
= current_buffer
;
21806 if (!NILP (BVAR (b
, read_only
)))
21808 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21813 /* This differs from %* only for a modified read-only buffer. */
21814 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21816 if (!NILP (BVAR (b
, read_only
)))
21821 /* This differs from %* in ignoring read-only-ness. */
21822 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21834 if (command_loop_level
> 5)
21836 p
= decode_mode_spec_buf
;
21837 for (i
= 0; i
< command_loop_level
; i
++)
21840 return decode_mode_spec_buf
;
21848 if (command_loop_level
> 5)
21850 p
= decode_mode_spec_buf
;
21851 for (i
= 0; i
< command_loop_level
; i
++)
21854 return decode_mode_spec_buf
;
21861 /* Let lots_of_dashes be a string of infinite length. */
21862 if (mode_line_target
== MODE_LINE_NOPROP
21863 || mode_line_target
== MODE_LINE_STRING
)
21865 if (field_width
<= 0
21866 || field_width
> sizeof (lots_of_dashes
))
21868 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
21869 decode_mode_spec_buf
[i
] = '-';
21870 decode_mode_spec_buf
[i
] = '\0';
21871 return decode_mode_spec_buf
;
21874 return lots_of_dashes
;
21878 obj
= BVAR (b
, name
);
21882 /* %c and %l are ignored in `frame-title-format'.
21883 (In redisplay_internal, the frame title is drawn _before_ the
21884 windows are updated, so the stuff which depends on actual
21885 window contents (such as %l) may fail to render properly, or
21886 even crash emacs.) */
21887 if (mode_line_target
== MODE_LINE_TITLE
)
21891 ptrdiff_t col
= current_column ();
21892 w
->column_number_displayed
= col
;
21893 pint2str (decode_mode_spec_buf
, width
, col
);
21894 return decode_mode_spec_buf
;
21898 #ifndef SYSTEM_MALLOC
21900 if (NILP (Vmemory_full
))
21903 return "!MEM FULL! ";
21910 /* %F displays the frame name. */
21911 if (!NILP (f
->title
))
21912 return SSDATA (f
->title
);
21913 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
21914 return SSDATA (f
->name
);
21918 obj
= BVAR (b
, filename
);
21923 ptrdiff_t size
= ZV
- BEGV
;
21924 pint2str (decode_mode_spec_buf
, width
, size
);
21925 return decode_mode_spec_buf
;
21930 ptrdiff_t size
= ZV
- BEGV
;
21931 pint2hrstr (decode_mode_spec_buf
, width
, size
);
21932 return decode_mode_spec_buf
;
21937 ptrdiff_t startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
21938 ptrdiff_t topline
, nlines
, height
;
21941 /* %c and %l are ignored in `frame-title-format'. */
21942 if (mode_line_target
== MODE_LINE_TITLE
)
21945 startpos
= marker_position (w
->start
);
21946 startpos_byte
= marker_byte_position (w
->start
);
21947 height
= WINDOW_TOTAL_LINES (w
);
21949 /* If we decided that this buffer isn't suitable for line numbers,
21950 don't forget that too fast. */
21951 if (w
->base_line_pos
== -1)
21954 /* If the buffer is very big, don't waste time. */
21955 if (INTEGERP (Vline_number_display_limit
)
21956 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
21958 w
->base_line_pos
= 0;
21959 w
->base_line_number
= 0;
21963 if (w
->base_line_number
> 0
21964 && w
->base_line_pos
> 0
21965 && w
->base_line_pos
<= startpos
)
21967 line
= w
->base_line_number
;
21968 linepos
= w
->base_line_pos
;
21969 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
21974 linepos
= BUF_BEGV (b
);
21975 linepos_byte
= BUF_BEGV_BYTE (b
);
21978 /* Count lines from base line to window start position. */
21979 nlines
= display_count_lines (linepos_byte
,
21983 topline
= nlines
+ line
;
21985 /* Determine a new base line, if the old one is too close
21986 or too far away, or if we did not have one.
21987 "Too close" means it's plausible a scroll-down would
21988 go back past it. */
21989 if (startpos
== BUF_BEGV (b
))
21991 w
->base_line_number
= topline
;
21992 w
->base_line_pos
= BUF_BEGV (b
);
21994 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
21995 || linepos
== BUF_BEGV (b
))
21997 ptrdiff_t limit
= BUF_BEGV (b
);
21998 ptrdiff_t limit_byte
= BUF_BEGV_BYTE (b
);
21999 ptrdiff_t position
;
22000 ptrdiff_t distance
=
22001 (height
* 2 + 30) * line_number_display_limit_width
;
22003 if (startpos
- distance
> limit
)
22005 limit
= startpos
- distance
;
22006 limit_byte
= CHAR_TO_BYTE (limit
);
22009 nlines
= display_count_lines (startpos_byte
,
22011 - (height
* 2 + 30),
22013 /* If we couldn't find the lines we wanted within
22014 line_number_display_limit_width chars per line,
22015 give up on line numbers for this window. */
22016 if (position
== limit_byte
&& limit
== startpos
- distance
)
22018 w
->base_line_pos
= -1;
22019 w
->base_line_number
= 0;
22023 w
->base_line_number
= topline
- nlines
;
22024 w
->base_line_pos
= BYTE_TO_CHAR (position
);
22027 /* Now count lines from the start pos to point. */
22028 nlines
= display_count_lines (startpos_byte
,
22029 PT_BYTE
, PT
, &junk
);
22031 /* Record that we did display the line number. */
22032 line_number_displayed
= 1;
22034 /* Make the string to show. */
22035 pint2str (decode_mode_spec_buf
, width
, topline
+ nlines
);
22036 return decode_mode_spec_buf
;
22039 char* p
= decode_mode_spec_buf
;
22040 int pad
= width
- 2;
22046 return decode_mode_spec_buf
;
22052 obj
= BVAR (b
, mode_name
);
22056 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
22062 ptrdiff_t pos
= marker_position (w
->start
);
22063 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
22065 if (w
->window_end_pos
<= BUF_Z (b
) - BUF_ZV (b
))
22067 if (pos
<= BUF_BEGV (b
))
22072 else if (pos
<= BUF_BEGV (b
))
22076 if (total
> 1000000)
22077 /* Do it differently for a large value, to avoid overflow. */
22078 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
22080 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
22081 /* We can't normally display a 3-digit number,
22082 so get us a 2-digit number that is close. */
22085 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
22086 return decode_mode_spec_buf
;
22090 /* Display percentage of size above the bottom of the screen. */
22093 ptrdiff_t toppos
= marker_position (w
->start
);
22094 ptrdiff_t botpos
= BUF_Z (b
) - w
->window_end_pos
;
22095 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
22097 if (botpos
>= BUF_ZV (b
))
22099 if (toppos
<= BUF_BEGV (b
))
22106 if (total
> 1000000)
22107 /* Do it differently for a large value, to avoid overflow. */
22108 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
22110 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
22111 /* We can't normally display a 3-digit number,
22112 so get us a 2-digit number that is close. */
22115 if (toppos
<= BUF_BEGV (b
))
22116 sprintf (decode_mode_spec_buf
, "Top%2"pD
"d%%", total
);
22118 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
22119 return decode_mode_spec_buf
;
22124 /* status of process */
22125 obj
= Fget_buffer_process (Fcurrent_buffer ());
22127 return "no process";
22129 obj
= Fsymbol_name (Fprocess_status (obj
));
22135 ptrdiff_t count
= inhibit_garbage_collection ();
22136 Lisp_Object val
= call1 (intern ("file-remote-p"),
22137 BVAR (current_buffer
, directory
));
22138 unbind_to (count
, Qnil
);
22147 /* coding-system (not including end-of-line format) */
22149 /* coding-system (including end-of-line type) */
22151 int eol_flag
= (c
== 'Z');
22152 char *p
= decode_mode_spec_buf
;
22154 if (! FRAME_WINDOW_P (f
))
22156 /* No need to mention EOL here--the terminal never needs
22157 to do EOL conversion. */
22158 p
= decode_mode_spec_coding (CODING_ID_NAME
22159 (FRAME_KEYBOARD_CODING (f
)->id
),
22161 p
= decode_mode_spec_coding (CODING_ID_NAME
22162 (FRAME_TERMINAL_CODING (f
)->id
),
22165 p
= decode_mode_spec_coding (BVAR (b
, buffer_file_coding_system
),
22168 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
22169 #ifdef subprocesses
22170 obj
= Fget_buffer_process (Fcurrent_buffer ());
22171 if (PROCESSP (obj
))
22173 p
= decode_mode_spec_coding
22174 (XPROCESS (obj
)->decode_coding_system
, p
, eol_flag
);
22175 p
= decode_mode_spec_coding
22176 (XPROCESS (obj
)->encode_coding_system
, p
, eol_flag
);
22178 #endif /* subprocesses */
22181 return decode_mode_spec_buf
;
22188 return SSDATA (obj
);
22195 /* Count up to COUNT lines starting from START_BYTE. COUNT negative
22196 means count lines back from START_BYTE. But don't go beyond
22197 LIMIT_BYTE. Return the number of lines thus found (always
22200 Set *BYTE_POS_PTR to the byte position where we stopped. This is
22201 either the position COUNT lines after/before START_BYTE, if we
22202 found COUNT lines, or LIMIT_BYTE if we hit the limit before finding
22206 display_count_lines (ptrdiff_t start_byte
,
22207 ptrdiff_t limit_byte
, ptrdiff_t count
,
22208 ptrdiff_t *byte_pos_ptr
)
22210 register unsigned char *cursor
;
22211 unsigned char *base
;
22213 register ptrdiff_t ceiling
;
22214 register unsigned char *ceiling_addr
;
22215 ptrdiff_t orig_count
= count
;
22217 /* If we are not in selective display mode,
22218 check only for newlines. */
22219 int selective_display
= (!NILP (BVAR (current_buffer
, selective_display
))
22220 && !INTEGERP (BVAR (current_buffer
, selective_display
)));
22224 while (start_byte
< limit_byte
)
22226 ceiling
= BUFFER_CEILING_OF (start_byte
);
22227 ceiling
= min (limit_byte
- 1, ceiling
);
22228 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
22229 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
22233 if (selective_display
)
22235 while (*cursor
!= '\n' && *cursor
!= 015
22236 && ++cursor
!= ceiling_addr
)
22238 if (cursor
== ceiling_addr
)
22243 cursor
= memchr (cursor
, '\n', ceiling_addr
- cursor
);
22252 start_byte
+= cursor
- base
;
22253 *byte_pos_ptr
= start_byte
;
22257 while (cursor
< ceiling_addr
);
22259 start_byte
+= ceiling_addr
- base
;
22264 while (start_byte
> limit_byte
)
22266 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
22267 ceiling
= max (limit_byte
, ceiling
);
22268 ceiling_addr
= BYTE_POS_ADDR (ceiling
);
22269 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
22272 if (selective_display
)
22274 while (--cursor
>= ceiling_addr
22275 && *cursor
!= '\n' && *cursor
!= 015)
22277 if (cursor
< ceiling_addr
)
22282 cursor
= memrchr (ceiling_addr
, '\n', cursor
- ceiling_addr
);
22289 start_byte
+= cursor
- base
+ 1;
22290 *byte_pos_ptr
= start_byte
;
22291 /* When scanning backwards, we should
22292 not count the newline posterior to which we stop. */
22293 return - orig_count
- 1;
22296 start_byte
+= ceiling_addr
- base
;
22300 *byte_pos_ptr
= limit_byte
;
22303 return - orig_count
+ count
;
22304 return orig_count
- count
;
22310 /***********************************************************************
22312 ***********************************************************************/
22314 /* Display a NUL-terminated string, starting with index START.
22316 If STRING is non-null, display that C string. Otherwise, the Lisp
22317 string LISP_STRING is displayed. There's a case that STRING is
22318 non-null and LISP_STRING is not nil. It means STRING is a string
22319 data of LISP_STRING. In that case, we display LISP_STRING while
22320 ignoring its text properties.
22322 If FACE_STRING is not nil, FACE_STRING_POS is a position in
22323 FACE_STRING. Display STRING or LISP_STRING with the face at
22324 FACE_STRING_POS in FACE_STRING:
22326 Display the string in the environment given by IT, but use the
22327 standard display table, temporarily.
22329 FIELD_WIDTH is the minimum number of output glyphs to produce.
22330 If STRING has fewer characters than FIELD_WIDTH, pad to the right
22331 with spaces. If STRING has more characters, more than FIELD_WIDTH
22332 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
22334 PRECISION is the maximum number of characters to output from
22335 STRING. PRECISION < 0 means don't truncate the string.
22337 This is roughly equivalent to printf format specifiers:
22339 FIELD_WIDTH PRECISION PRINTF
22340 ----------------------------------------
22346 MULTIBYTE zero means do not display multibyte chars, > 0 means do
22347 display them, and < 0 means obey the current buffer's value of
22348 enable_multibyte_characters.
22350 Value is the number of columns displayed. */
22353 display_string (const char *string
, Lisp_Object lisp_string
, Lisp_Object face_string
,
22354 ptrdiff_t face_string_pos
, ptrdiff_t start
, struct it
*it
,
22355 int field_width
, int precision
, int max_x
, int multibyte
)
22357 int hpos_at_start
= it
->hpos
;
22358 int saved_face_id
= it
->face_id
;
22359 struct glyph_row
*row
= it
->glyph_row
;
22360 ptrdiff_t it_charpos
;
22362 /* Initialize the iterator IT for iteration over STRING beginning
22363 with index START. */
22364 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
22365 precision
, field_width
, multibyte
);
22366 if (string
&& STRINGP (lisp_string
))
22367 /* LISP_STRING is the one returned by decode_mode_spec. We should
22368 ignore its text properties. */
22369 it
->stop_charpos
= it
->end_charpos
;
22371 /* If displaying STRING, set up the face of the iterator from
22372 FACE_STRING, if that's given. */
22373 if (STRINGP (face_string
))
22379 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
22380 0, it
->region_beg_charpos
,
22381 it
->region_end_charpos
,
22382 &endptr
, it
->base_face_id
, 0);
22383 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22384 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
22387 /* Set max_x to the maximum allowed X position. Don't let it go
22388 beyond the right edge of the window. */
22390 max_x
= it
->last_visible_x
;
22392 max_x
= min (max_x
, it
->last_visible_x
);
22394 /* Skip over display elements that are not visible. because IT->w is
22396 if (it
->current_x
< it
->first_visible_x
)
22397 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
22398 MOVE_TO_POS
| MOVE_TO_X
);
22400 row
->ascent
= it
->max_ascent
;
22401 row
->height
= it
->max_ascent
+ it
->max_descent
;
22402 row
->phys_ascent
= it
->max_phys_ascent
;
22403 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
22404 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
22406 if (STRINGP (it
->string
))
22407 it_charpos
= IT_STRING_CHARPOS (*it
);
22409 it_charpos
= IT_CHARPOS (*it
);
22411 /* This condition is for the case that we are called with current_x
22412 past last_visible_x. */
22413 while (it
->current_x
< max_x
)
22415 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
22417 /* Get the next display element. */
22418 if (!get_next_display_element (it
))
22421 /* Produce glyphs. */
22422 x_before
= it
->current_x
;
22423 n_glyphs_before
= row
->used
[TEXT_AREA
];
22424 PRODUCE_GLYPHS (it
);
22426 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
22429 while (i
< nglyphs
)
22431 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
22433 if (it
->line_wrap
!= TRUNCATE
22434 && x
+ glyph
->pixel_width
> max_x
)
22436 /* End of continued line or max_x reached. */
22437 if (CHAR_GLYPH_PADDING_P (*glyph
))
22439 /* A wide character is unbreakable. */
22440 if (row
->reversed_p
)
22441 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
22442 - n_glyphs_before
);
22443 row
->used
[TEXT_AREA
] = n_glyphs_before
;
22444 it
->current_x
= x_before
;
22448 if (row
->reversed_p
)
22449 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
22450 - (n_glyphs_before
+ i
));
22451 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
22456 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
22458 /* Glyph is at least partially visible. */
22460 if (x
< it
->first_visible_x
)
22461 row
->x
= x
- it
->first_visible_x
;
22465 /* Glyph is off the left margin of the display area.
22466 Should not happen. */
22470 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
22471 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
22472 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
22473 row
->phys_height
= max (row
->phys_height
,
22474 it
->max_phys_ascent
+ it
->max_phys_descent
);
22475 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
22476 it
->max_extra_line_spacing
);
22477 x
+= glyph
->pixel_width
;
22481 /* Stop if max_x reached. */
22485 /* Stop at line ends. */
22486 if (ITERATOR_AT_END_OF_LINE_P (it
))
22488 it
->continuation_lines_width
= 0;
22492 set_iterator_to_next (it
, 1);
22493 if (STRINGP (it
->string
))
22494 it_charpos
= IT_STRING_CHARPOS (*it
);
22496 it_charpos
= IT_CHARPOS (*it
);
22498 /* Stop if truncating at the right edge. */
22499 if (it
->line_wrap
== TRUNCATE
22500 && it
->current_x
>= it
->last_visible_x
)
22502 /* Add truncation mark, but don't do it if the line is
22503 truncated at a padding space. */
22504 if (it_charpos
< it
->string_nchars
)
22506 if (!FRAME_WINDOW_P (it
->f
))
22510 if (it
->current_x
> it
->last_visible_x
)
22512 if (!row
->reversed_p
)
22514 for (ii
= row
->used
[TEXT_AREA
] - 1; ii
> 0; --ii
)
22515 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
22520 for (ii
= 0; ii
< row
->used
[TEXT_AREA
]; ii
++)
22521 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
22523 unproduce_glyphs (it
, ii
+ 1);
22524 ii
= row
->used
[TEXT_AREA
] - (ii
+ 1);
22526 for (n
= row
->used
[TEXT_AREA
]; ii
< n
; ++ii
)
22528 row
->used
[TEXT_AREA
] = ii
;
22529 produce_special_glyphs (it
, IT_TRUNCATION
);
22532 produce_special_glyphs (it
, IT_TRUNCATION
);
22534 row
->truncated_on_right_p
= 1;
22540 /* Maybe insert a truncation at the left. */
22541 if (it
->first_visible_x
22544 if (!FRAME_WINDOW_P (it
->f
)
22545 || (row
->reversed_p
22546 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
22547 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
22548 insert_left_trunc_glyphs (it
);
22549 row
->truncated_on_left_p
= 1;
22552 it
->face_id
= saved_face_id
;
22554 /* Value is number of columns displayed. */
22555 return it
->hpos
- hpos_at_start
;
22560 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
22561 appears as an element of LIST or as the car of an element of LIST.
22562 If PROPVAL is a list, compare each element against LIST in that
22563 way, and return 1/2 if any element of PROPVAL is found in LIST.
22564 Otherwise return 0. This function cannot quit.
22565 The return value is 2 if the text is invisible but with an ellipsis
22566 and 1 if it's invisible and without an ellipsis. */
22569 invisible_p (register Lisp_Object propval
, Lisp_Object list
)
22571 register Lisp_Object tail
, proptail
;
22573 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
22575 register Lisp_Object tem
;
22577 if (EQ (propval
, tem
))
22579 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
22580 return NILP (XCDR (tem
)) ? 1 : 2;
22583 if (CONSP (propval
))
22585 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
22587 Lisp_Object propelt
;
22588 propelt
= XCAR (proptail
);
22589 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
22591 register Lisp_Object tem
;
22593 if (EQ (propelt
, tem
))
22595 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
22596 return NILP (XCDR (tem
)) ? 1 : 2;
22604 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
22605 doc
: /* Non-nil if the property makes the text invisible.
22606 POS-OR-PROP can be a marker or number, in which case it is taken to be
22607 a position in the current buffer and the value of the `invisible' property
22608 is checked; or it can be some other value, which is then presumed to be the
22609 value of the `invisible' property of the text of interest.
22610 The non-nil value returned can be t for truly invisible text or something
22611 else if the text is replaced by an ellipsis. */)
22612 (Lisp_Object pos_or_prop
)
22615 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
22616 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
22618 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
22619 return (invis
== 0 ? Qnil
22621 : make_number (invis
));
22624 /* Calculate a width or height in pixels from a specification using
22625 the following elements:
22628 NUM - a (fractional) multiple of the default font width/height
22629 (NUM) - specifies exactly NUM pixels
22630 UNIT - a fixed number of pixels, see below.
22631 ELEMENT - size of a display element in pixels, see below.
22632 (NUM . SPEC) - equals NUM * SPEC
22633 (+ SPEC SPEC ...) - add pixel values
22634 (- SPEC SPEC ...) - subtract pixel values
22635 (- SPEC) - negate pixel value
22638 INT or FLOAT - a number constant
22639 SYMBOL - use symbol's (buffer local) variable binding.
22642 in - pixels per inch *)
22643 mm - pixels per 1/1000 meter *)
22644 cm - pixels per 1/100 meter *)
22645 width - width of current font in pixels.
22646 height - height of current font in pixels.
22648 *) using the ratio(s) defined in display-pixels-per-inch.
22652 left-fringe - left fringe width in pixels
22653 right-fringe - right fringe width in pixels
22655 left-margin - left margin width in pixels
22656 right-margin - right margin width in pixels
22658 scroll-bar - scroll-bar area width in pixels
22662 Pixels corresponding to 5 inches:
22665 Total width of non-text areas on left side of window (if scroll-bar is on left):
22666 '(space :width (+ left-fringe left-margin scroll-bar))
22668 Align to first text column (in header line):
22669 '(space :align-to 0)
22671 Align to middle of text area minus half the width of variable `my-image'
22672 containing a loaded image:
22673 '(space :align-to (0.5 . (- text my-image)))
22675 Width of left margin minus width of 1 character in the default font:
22676 '(space :width (- left-margin 1))
22678 Width of left margin minus width of 2 characters in the current font:
22679 '(space :width (- left-margin (2 . width)))
22681 Center 1 character over left-margin (in header line):
22682 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
22684 Different ways to express width of left fringe plus left margin minus one pixel:
22685 '(space :width (- (+ left-fringe left-margin) (1)))
22686 '(space :width (+ left-fringe left-margin (- (1))))
22687 '(space :width (+ left-fringe left-margin (-1)))
22692 calc_pixel_width_or_height (double *res
, struct it
*it
, Lisp_Object prop
,
22693 struct font
*font
, int width_p
, int *align_to
)
22697 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
22698 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
22701 return OK_PIXELS (0);
22703 eassert (FRAME_LIVE_P (it
->f
));
22705 if (SYMBOLP (prop
))
22707 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
22709 char *unit
= SSDATA (SYMBOL_NAME (prop
));
22711 if (unit
[0] == 'i' && unit
[1] == 'n')
22713 else if (unit
[0] == 'm' && unit
[1] == 'm')
22715 else if (unit
[0] == 'c' && unit
[1] == 'm')
22721 double ppi
= (width_p
? FRAME_RES_X (it
->f
)
22722 : FRAME_RES_Y (it
->f
));
22725 return OK_PIXELS (ppi
/ pixels
);
22730 #ifdef HAVE_WINDOW_SYSTEM
22731 if (EQ (prop
, Qheight
))
22732 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
22733 if (EQ (prop
, Qwidth
))
22734 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
22736 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
22737 return OK_PIXELS (1);
22740 if (EQ (prop
, Qtext
))
22741 return OK_PIXELS (width_p
22742 ? window_box_width (it
->w
, TEXT_AREA
)
22743 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
22745 if (align_to
&& *align_to
< 0)
22748 if (EQ (prop
, Qleft
))
22749 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
22750 if (EQ (prop
, Qright
))
22751 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
22752 if (EQ (prop
, Qcenter
))
22753 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
22754 + window_box_width (it
->w
, TEXT_AREA
) / 2);
22755 if (EQ (prop
, Qleft_fringe
))
22756 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22757 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
22758 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
22759 if (EQ (prop
, Qright_fringe
))
22760 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22761 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
22762 : window_box_right_offset (it
->w
, TEXT_AREA
));
22763 if (EQ (prop
, Qleft_margin
))
22764 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
22765 if (EQ (prop
, Qright_margin
))
22766 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
22767 if (EQ (prop
, Qscroll_bar
))
22768 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
22770 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
22771 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22772 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
22777 if (EQ (prop
, Qleft_fringe
))
22778 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
22779 if (EQ (prop
, Qright_fringe
))
22780 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
22781 if (EQ (prop
, Qleft_margin
))
22782 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
22783 if (EQ (prop
, Qright_margin
))
22784 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
22785 if (EQ (prop
, Qscroll_bar
))
22786 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
22789 prop
= buffer_local_value_1 (prop
, it
->w
->contents
);
22790 if (EQ (prop
, Qunbound
))
22794 if (INTEGERP (prop
) || FLOATP (prop
))
22796 int base_unit
= (width_p
22797 ? FRAME_COLUMN_WIDTH (it
->f
)
22798 : FRAME_LINE_HEIGHT (it
->f
));
22799 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
22804 Lisp_Object car
= XCAR (prop
);
22805 Lisp_Object cdr
= XCDR (prop
);
22809 #ifdef HAVE_WINDOW_SYSTEM
22810 if (FRAME_WINDOW_P (it
->f
)
22811 && valid_image_p (prop
))
22813 ptrdiff_t id
= lookup_image (it
->f
, prop
);
22814 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
22816 return OK_PIXELS (width_p
? img
->width
: img
->height
);
22818 #ifdef HAVE_XWIDGETS
22819 if (FRAME_WINDOW_P (it
->f
) && valid_xwidget_spec_p (prop
))
22821 printf("calc_pixel_width_or_height: return dummy size FIXME\n");
22822 return OK_PIXELS (width_p
? 100 : 100);
22826 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
22832 while (CONSP (cdr
))
22834 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
22835 font
, width_p
, align_to
))
22838 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
22843 if (EQ (car
, Qminus
))
22845 return OK_PIXELS (pixels
);
22848 car
= buffer_local_value_1 (car
, it
->w
->contents
);
22849 if (EQ (car
, Qunbound
))
22853 if (INTEGERP (car
) || FLOATP (car
))
22856 pixels
= XFLOATINT (car
);
22858 return OK_PIXELS (pixels
);
22859 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
22860 font
, width_p
, align_to
))
22861 return OK_PIXELS (pixels
* fact
);
22872 /***********************************************************************
22874 ***********************************************************************/
22876 #ifdef HAVE_WINDOW_SYSTEM
22881 dump_glyph_string (struct glyph_string
*s
)
22883 fprintf (stderr
, "glyph string\n");
22884 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
22885 s
->x
, s
->y
, s
->width
, s
->height
);
22886 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
22887 fprintf (stderr
, " hl = %d\n", s
->hl
);
22888 fprintf (stderr
, " left overhang = %d, right = %d\n",
22889 s
->left_overhang
, s
->right_overhang
);
22890 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
22891 fprintf (stderr
, " extends to end of line = %d\n",
22892 s
->extends_to_end_of_line_p
);
22893 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
22894 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
22897 #endif /* GLYPH_DEBUG */
22899 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
22900 of XChar2b structures for S; it can't be allocated in
22901 init_glyph_string because it must be allocated via `alloca'. W
22902 is the window on which S is drawn. ROW and AREA are the glyph row
22903 and area within the row from which S is constructed. START is the
22904 index of the first glyph structure covered by S. HL is a
22905 face-override for drawing S. */
22908 #define OPTIONAL_HDC(hdc) HDC hdc,
22909 #define DECLARE_HDC(hdc) HDC hdc;
22910 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
22911 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
22914 #ifndef OPTIONAL_HDC
22915 #define OPTIONAL_HDC(hdc)
22916 #define DECLARE_HDC(hdc)
22917 #define ALLOCATE_HDC(hdc, f)
22918 #define RELEASE_HDC(hdc, f)
22922 init_glyph_string (struct glyph_string
*s
,
22924 XChar2b
*char2b
, struct window
*w
, struct glyph_row
*row
,
22925 enum glyph_row_area area
, int start
, enum draw_glyphs_face hl
)
22927 memset (s
, 0, sizeof *s
);
22929 s
->f
= XFRAME (w
->frame
);
22933 s
->display
= FRAME_X_DISPLAY (s
->f
);
22934 s
->window
= FRAME_X_WINDOW (s
->f
);
22935 s
->char2b
= char2b
;
22939 s
->first_glyph
= row
->glyphs
[area
] + start
;
22940 s
->height
= row
->height
;
22941 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
22942 s
->ybase
= s
->y
+ row
->ascent
;
22946 /* Append the list of glyph strings with head H and tail T to the list
22947 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
22950 append_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
22951 struct glyph_string
*h
, struct glyph_string
*t
)
22965 /* Prepend the list of glyph strings with head H and tail T to the
22966 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
22970 prepend_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
22971 struct glyph_string
*h
, struct glyph_string
*t
)
22985 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
22986 Set *HEAD and *TAIL to the resulting list. */
22989 append_glyph_string (struct glyph_string
**head
, struct glyph_string
**tail
,
22990 struct glyph_string
*s
)
22992 s
->next
= s
->prev
= NULL
;
22993 append_glyph_string_lists (head
, tail
, s
, s
);
22997 /* Get face and two-byte form of character C in face FACE_ID on frame F.
22998 The encoding of C is returned in *CHAR2B. DISPLAY_P non-zero means
22999 make sure that X resources for the face returned are allocated.
23000 Value is a pointer to a realized face that is ready for display if
23001 DISPLAY_P is non-zero. */
23003 static struct face
*
23004 get_char_face_and_encoding (struct frame
*f
, int c
, int face_id
,
23005 XChar2b
*char2b
, int display_p
)
23007 struct face
*face
= FACE_FROM_ID (f
, face_id
);
23012 code
= face
->font
->driver
->encode_char (face
->font
, c
);
23014 if (code
== FONT_INVALID_CODE
)
23017 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
23019 /* Make sure X resources of the face are allocated. */
23020 #ifdef HAVE_X_WINDOWS
23024 eassert (face
!= NULL
);
23025 PREPARE_FACE_FOR_DISPLAY (f
, face
);
23032 /* Get face and two-byte form of character glyph GLYPH on frame F.
23033 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
23034 a pointer to a realized face that is ready for display. */
23036 static struct face
*
23037 get_glyph_face_and_encoding (struct frame
*f
, struct glyph
*glyph
,
23038 XChar2b
*char2b
, int *two_byte_p
)
23043 eassert (glyph
->type
== CHAR_GLYPH
);
23044 face
= FACE_FROM_ID (f
, glyph
->face_id
);
23046 /* Make sure X resources of the face are allocated. */
23047 eassert (face
!= NULL
);
23048 PREPARE_FACE_FOR_DISPLAY (f
, face
);
23055 if (CHAR_BYTE8_P (glyph
->u
.ch
))
23056 code
= CHAR_TO_BYTE8 (glyph
->u
.ch
);
23058 code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
23060 if (code
== FONT_INVALID_CODE
)
23064 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
23069 /* Get glyph code of character C in FONT in the two-byte form CHAR2B.
23070 Return 1 if FONT has a glyph for C, otherwise return 0. */
23073 get_char_glyph_code (int c
, struct font
*font
, XChar2b
*char2b
)
23077 if (CHAR_BYTE8_P (c
))
23078 code
= CHAR_TO_BYTE8 (c
);
23080 code
= font
->driver
->encode_char (font
, c
);
23082 if (code
== FONT_INVALID_CODE
)
23084 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
23089 /* Fill glyph string S with composition components specified by S->cmp.
23091 BASE_FACE is the base face of the composition.
23092 S->cmp_from is the index of the first component for S.
23094 OVERLAPS non-zero means S should draw the foreground only, and use
23095 its physical height for clipping. See also draw_glyphs.
23097 Value is the index of a component not in S. */
23100 fill_composite_glyph_string (struct glyph_string
*s
, struct face
*base_face
,
23104 /* For all glyphs of this composition, starting at the offset
23105 S->cmp_from, until we reach the end of the definition or encounter a
23106 glyph that requires the different face, add it to S. */
23111 s
->for_overlaps
= overlaps
;
23114 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
23116 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
23118 /* TAB in a composition means display glyphs with padding space
23119 on the left or right. */
23122 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
23125 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
23132 s
->font
= s
->face
->font
;
23134 else if (s
->face
!= face
)
23142 if (s
->face
== NULL
)
23144 s
->face
= base_face
->ascii_face
;
23145 s
->font
= s
->face
->font
;
23148 /* All glyph strings for the same composition has the same width,
23149 i.e. the width set for the first component of the composition. */
23150 s
->width
= s
->first_glyph
->pixel_width
;
23152 /* If the specified font could not be loaded, use the frame's
23153 default font, but record the fact that we couldn't load it in
23154 the glyph string so that we can draw rectangles for the
23155 characters of the glyph string. */
23156 if (s
->font
== NULL
)
23158 s
->font_not_found_p
= 1;
23159 s
->font
= FRAME_FONT (s
->f
);
23162 /* Adjust base line for subscript/superscript text. */
23163 s
->ybase
+= s
->first_glyph
->voffset
;
23165 /* This glyph string must always be drawn with 16-bit functions. */
23172 fill_gstring_glyph_string (struct glyph_string
*s
, int face_id
,
23173 int start
, int end
, int overlaps
)
23175 struct glyph
*glyph
, *last
;
23176 Lisp_Object lgstring
;
23179 s
->for_overlaps
= overlaps
;
23180 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23181 last
= s
->row
->glyphs
[s
->area
] + end
;
23182 s
->cmp_id
= glyph
->u
.cmp
.id
;
23183 s
->cmp_from
= glyph
->slice
.cmp
.from
;
23184 s
->cmp_to
= glyph
->slice
.cmp
.to
+ 1;
23185 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
23186 lgstring
= composition_gstring_from_id (s
->cmp_id
);
23187 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
23189 while (glyph
< last
23190 && glyph
->u
.cmp
.automatic
23191 && glyph
->u
.cmp
.id
== s
->cmp_id
23192 && s
->cmp_to
== glyph
->slice
.cmp
.from
)
23193 s
->cmp_to
= (glyph
++)->slice
.cmp
.to
+ 1;
23195 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
23197 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
23198 unsigned code
= LGLYPH_CODE (lglyph
);
23200 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
23202 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
23203 return glyph
- s
->row
->glyphs
[s
->area
];
23207 /* Fill glyph string S from a sequence glyphs for glyphless characters.
23208 See the comment of fill_glyph_string for arguments.
23209 Value is the index of the first glyph not in S. */
23213 fill_glyphless_glyph_string (struct glyph_string
*s
, int face_id
,
23214 int start
, int end
, int overlaps
)
23216 struct glyph
*glyph
, *last
;
23219 eassert (s
->first_glyph
->type
== GLYPHLESS_GLYPH
);
23220 s
->for_overlaps
= overlaps
;
23221 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23222 last
= s
->row
->glyphs
[s
->area
] + end
;
23223 voffset
= glyph
->voffset
;
23224 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
23225 s
->font
= s
->face
->font
? s
->face
->font
: FRAME_FONT (s
->f
);
23227 s
->width
= glyph
->pixel_width
;
23229 while (glyph
< last
23230 && glyph
->type
== GLYPHLESS_GLYPH
23231 && glyph
->voffset
== voffset
23232 && glyph
->face_id
== face_id
)
23235 s
->width
+= glyph
->pixel_width
;
23238 s
->ybase
+= voffset
;
23239 return glyph
- s
->row
->glyphs
[s
->area
];
23243 /* Fill glyph string S from a sequence of character glyphs.
23245 FACE_ID is the face id of the string. START is the index of the
23246 first glyph to consider, END is the index of the last + 1.
23247 OVERLAPS non-zero means S should draw the foreground only, and use
23248 its physical height for clipping. See also draw_glyphs.
23250 Value is the index of the first glyph not in S. */
23253 fill_glyph_string (struct glyph_string
*s
, int face_id
,
23254 int start
, int end
, int overlaps
)
23256 struct glyph
*glyph
, *last
;
23258 int glyph_not_available_p
;
23260 eassert (s
->f
== XFRAME (s
->w
->frame
));
23261 eassert (s
->nchars
== 0);
23262 eassert (start
>= 0 && end
> start
);
23264 s
->for_overlaps
= overlaps
;
23265 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23266 last
= s
->row
->glyphs
[s
->area
] + end
;
23267 voffset
= glyph
->voffset
;
23268 s
->padding_p
= glyph
->padding_p
;
23269 glyph_not_available_p
= glyph
->glyph_not_available_p
;
23271 while (glyph
< last
23272 && glyph
->type
== CHAR_GLYPH
23273 && glyph
->voffset
== voffset
23274 /* Same face id implies same font, nowadays. */
23275 && glyph
->face_id
== face_id
23276 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
23280 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
23281 s
->char2b
+ s
->nchars
,
23283 s
->two_byte_p
= two_byte_p
;
23285 eassert (s
->nchars
<= end
- start
);
23286 s
->width
+= glyph
->pixel_width
;
23287 if (glyph
++->padding_p
!= s
->padding_p
)
23291 s
->font
= s
->face
->font
;
23293 /* If the specified font could not be loaded, use the frame's font,
23294 but record the fact that we couldn't load it in
23295 S->font_not_found_p so that we can draw rectangles for the
23296 characters of the glyph string. */
23297 if (s
->font
== NULL
|| glyph_not_available_p
)
23299 s
->font_not_found_p
= 1;
23300 s
->font
= FRAME_FONT (s
->f
);
23303 /* Adjust base line for subscript/superscript text. */
23304 s
->ybase
+= voffset
;
23306 eassert (s
->face
&& s
->face
->gc
);
23307 return glyph
- s
->row
->glyphs
[s
->area
];
23311 /* Fill glyph string S from image glyph S->first_glyph. */
23314 fill_image_glyph_string (struct glyph_string
*s
)
23316 eassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
23317 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
23319 s
->slice
= s
->first_glyph
->slice
.img
;
23320 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
23321 s
->font
= s
->face
->font
;
23322 s
->width
= s
->first_glyph
->pixel_width
;
23324 /* Adjust base line for subscript/superscript text. */
23325 s
->ybase
+= s
->first_glyph
->voffset
;
23328 #ifdef HAVE_XWIDGETS
23330 fill_xwidget_glyph_string (struct glyph_string
*s
)
23332 eassert (s
->first_glyph
->type
== XWIDGET_GLYPH
);
23333 printf("fill_xwidget_glyph_string: width:%d \n",s
->first_glyph
->pixel_width
);
23334 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
23335 s
->font
= s
->face
->font
;
23336 s
->width
= s
->first_glyph
->pixel_width
;
23337 s
->ybase
+= s
->first_glyph
->voffset
;
23338 s
->xwidget
= s
->first_glyph
->u
.xwidget
;
23339 //assert_valid_xwidget_id ( s->xwidget, "fill_xwidget_glyph_string");
23342 /* Fill glyph string S from a sequence of stretch glyphs.
23344 START is the index of the first glyph to consider,
23345 END is the index of the last + 1.
23347 Value is the index of the first glyph not in S. */
23350 fill_stretch_glyph_string (struct glyph_string
*s
, int start
, int end
)
23352 struct glyph
*glyph
, *last
;
23353 int voffset
, face_id
;
23355 eassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
23357 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23358 last
= s
->row
->glyphs
[s
->area
] + end
;
23359 face_id
= glyph
->face_id
;
23360 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
23361 s
->font
= s
->face
->font
;
23362 s
->width
= glyph
->pixel_width
;
23364 voffset
= glyph
->voffset
;
23368 && glyph
->type
== STRETCH_GLYPH
23369 && glyph
->voffset
== voffset
23370 && glyph
->face_id
== face_id
);
23372 s
->width
+= glyph
->pixel_width
;
23374 /* Adjust base line for subscript/superscript text. */
23375 s
->ybase
+= voffset
;
23377 /* The case that face->gc == 0 is handled when drawing the glyph
23378 string by calling PREPARE_FACE_FOR_DISPLAY. */
23380 return glyph
- s
->row
->glyphs
[s
->area
];
23383 static struct font_metrics
*
23384 get_per_char_metric (struct font
*font
, XChar2b
*char2b
)
23386 static struct font_metrics metrics
;
23391 code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
23392 if (code
== FONT_INVALID_CODE
)
23394 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
23399 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
23400 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
23401 assumed to be zero. */
23404 x_get_glyph_overhangs (struct glyph
*glyph
, struct frame
*f
, int *left
, int *right
)
23406 *left
= *right
= 0;
23408 if (glyph
->type
== CHAR_GLYPH
)
23412 struct font_metrics
*pcm
;
23414 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
23415 if (face
->font
&& (pcm
= get_per_char_metric (face
->font
, &char2b
)))
23417 if (pcm
->rbearing
> pcm
->width
)
23418 *right
= pcm
->rbearing
- pcm
->width
;
23419 if (pcm
->lbearing
< 0)
23420 *left
= -pcm
->lbearing
;
23423 else if (glyph
->type
== COMPOSITE_GLYPH
)
23425 if (! glyph
->u
.cmp
.automatic
)
23427 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
23429 if (cmp
->rbearing
> cmp
->pixel_width
)
23430 *right
= cmp
->rbearing
- cmp
->pixel_width
;
23431 if (cmp
->lbearing
< 0)
23432 *left
= - cmp
->lbearing
;
23436 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
23437 struct font_metrics metrics
;
23439 composition_gstring_width (gstring
, glyph
->slice
.cmp
.from
,
23440 glyph
->slice
.cmp
.to
+ 1, &metrics
);
23441 if (metrics
.rbearing
> metrics
.width
)
23442 *right
= metrics
.rbearing
- metrics
.width
;
23443 if (metrics
.lbearing
< 0)
23444 *left
= - metrics
.lbearing
;
23450 /* Return the index of the first glyph preceding glyph string S that
23451 is overwritten by S because of S's left overhang. Value is -1
23452 if no glyphs are overwritten. */
23455 left_overwritten (struct glyph_string
*s
)
23459 if (s
->left_overhang
)
23462 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23463 int first
= s
->first_glyph
- glyphs
;
23465 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
23466 x
-= glyphs
[i
].pixel_width
;
23477 /* Return the index of the first glyph preceding glyph string S that
23478 is overwriting S because of its right overhang. Value is -1 if no
23479 glyph in front of S overwrites S. */
23482 left_overwriting (struct glyph_string
*s
)
23485 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23486 int first
= s
->first_glyph
- glyphs
;
23490 for (i
= first
- 1; i
>= 0; --i
)
23493 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
23496 x
-= glyphs
[i
].pixel_width
;
23503 /* Return the index of the last glyph following glyph string S that is
23504 overwritten by S because of S's right overhang. Value is -1 if
23505 no such glyph is found. */
23508 right_overwritten (struct glyph_string
*s
)
23512 if (s
->right_overhang
)
23515 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23516 int first
= (s
->first_glyph
- glyphs
23517 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
23518 int end
= s
->row
->used
[s
->area
];
23520 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
23521 x
+= glyphs
[i
].pixel_width
;
23530 /* Return the index of the last glyph following glyph string S that
23531 overwrites S because of its left overhang. Value is negative
23532 if no such glyph is found. */
23535 right_overwriting (struct glyph_string
*s
)
23538 int end
= s
->row
->used
[s
->area
];
23539 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23540 int first
= (s
->first_glyph
- glyphs
23541 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
23545 for (i
= first
; i
< end
; ++i
)
23548 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
23551 x
+= glyphs
[i
].pixel_width
;
23558 /* Set background width of glyph string S. START is the index of the
23559 first glyph following S. LAST_X is the right-most x-position + 1
23560 in the drawing area. */
23563 set_glyph_string_background_width (struct glyph_string
*s
, int start
, int last_x
)
23565 /* If the face of this glyph string has to be drawn to the end of
23566 the drawing area, set S->extends_to_end_of_line_p. */
23568 if (start
== s
->row
->used
[s
->area
]
23569 && s
->area
== TEXT_AREA
23570 && ((s
->row
->fill_line_p
23571 && (s
->hl
== DRAW_NORMAL_TEXT
23572 || s
->hl
== DRAW_IMAGE_RAISED
23573 || s
->hl
== DRAW_IMAGE_SUNKEN
))
23574 || s
->hl
== DRAW_MOUSE_FACE
))
23575 s
->extends_to_end_of_line_p
= 1;
23577 /* If S extends its face to the end of the line, set its
23578 background_width to the distance to the right edge of the drawing
23580 if (s
->extends_to_end_of_line_p
)
23581 s
->background_width
= last_x
- s
->x
+ 1;
23583 s
->background_width
= s
->width
;
23587 /* Compute overhangs and x-positions for glyph string S and its
23588 predecessors, or successors. X is the starting x-position for S.
23589 BACKWARD_P non-zero means process predecessors. */
23592 compute_overhangs_and_x (struct glyph_string
*s
, int x
, int backward_p
)
23598 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
23599 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
23609 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
23610 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
23620 /* The following macros are only called from draw_glyphs below.
23621 They reference the following parameters of that function directly:
23622 `w', `row', `area', and `overlap_p'
23623 as well as the following local variables:
23624 `s', `f', and `hdc' (in W32) */
23627 /* On W32, silently add local `hdc' variable to argument list of
23628 init_glyph_string. */
23629 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
23630 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
23632 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
23633 init_glyph_string (s, char2b, w, row, area, start, hl)
23636 /* Add a glyph string for a stretch glyph to the list of strings
23637 between HEAD and TAIL. START is the index of the stretch glyph in
23638 row area AREA of glyph row ROW. END is the index of the last glyph
23639 in that glyph row area. X is the current output position assigned
23640 to the new glyph string constructed. HL overrides that face of the
23641 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
23642 is the right-most x-position of the drawing area. */
23644 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
23645 and below -- keep them on one line. */
23646 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23649 s = alloca (sizeof *s); \
23650 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23651 START = fill_stretch_glyph_string (s, START, END); \
23652 append_glyph_string (&HEAD, &TAIL, s); \
23658 /* Add a glyph string for an image glyph to the list of strings
23659 between HEAD and TAIL. START is the index of the image glyph in
23660 row area AREA of glyph row ROW. END is the index of the last glyph
23661 in that glyph row area. X is the current output position assigned
23662 to the new glyph string constructed. HL overrides that face of the
23663 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
23664 is the right-most x-position of the drawing area. */
23666 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23669 s = alloca (sizeof *s); \
23670 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23671 fill_image_glyph_string (s); \
23672 append_glyph_string (&HEAD, &TAIL, s); \
23678 #ifdef HAVE_XWIDGETS
23679 #define BUILD_XWIDGET_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23682 printf("BUILD_XWIDGET_GLYPH_STRING\n"); \
23683 s = (struct glyph_string *) alloca (sizeof *s); \
23684 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23685 fill_xwidget_glyph_string (s); \
23686 append_glyph_string (&HEAD, &TAIL, s); \
23694 /* Add a glyph string for a sequence of character glyphs to the list
23695 of strings between HEAD and TAIL. START is the index of the first
23696 glyph in row area AREA of glyph row ROW that is part of the new
23697 glyph string. END is the index of the last glyph in that glyph row
23698 area. X is the current output position assigned to the new glyph
23699 string constructed. HL overrides that face of the glyph; e.g. it
23700 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
23701 right-most x-position of the drawing area. */
23703 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
23709 face_id = (row)->glyphs[area][START].face_id; \
23711 s = alloca (sizeof *s); \
23712 char2b = alloca ((END - START) * sizeof *char2b); \
23713 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23714 append_glyph_string (&HEAD, &TAIL, s); \
23716 START = fill_glyph_string (s, face_id, START, END, overlaps); \
23721 /* Add a glyph string for a composite sequence to the list of strings
23722 between HEAD and TAIL. START is the index of the first glyph in
23723 row area AREA of glyph row ROW that is part of the new glyph
23724 string. END is the index of the last glyph in that glyph row area.
23725 X is the current output position assigned to the new glyph string
23726 constructed. HL overrides that face of the glyph; e.g. it is
23727 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
23728 x-position of the drawing area. */
23730 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23732 int face_id = (row)->glyphs[area][START].face_id; \
23733 struct face *base_face = FACE_FROM_ID (f, face_id); \
23734 ptrdiff_t cmp_id = (row)->glyphs[area][START].u.cmp.id; \
23735 struct composition *cmp = composition_table[cmp_id]; \
23737 struct glyph_string *first_s = NULL; \
23740 char2b = alloca (cmp->glyph_len * sizeof *char2b); \
23742 /* Make glyph_strings for each glyph sequence that is drawable by \
23743 the same face, and append them to HEAD/TAIL. */ \
23744 for (n = 0; n < cmp->glyph_len;) \
23746 s = alloca (sizeof *s); \
23747 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23748 append_glyph_string (&(HEAD), &(TAIL), s); \
23754 n = fill_composite_glyph_string (s, base_face, overlaps); \
23762 /* Add a glyph string for a glyph-string sequence to the list of strings
23763 between HEAD and TAIL. */
23765 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23769 Lisp_Object gstring; \
23771 face_id = (row)->glyphs[area][START].face_id; \
23772 gstring = (composition_gstring_from_id \
23773 ((row)->glyphs[area][START].u.cmp.id)); \
23774 s = alloca (sizeof *s); \
23775 char2b = alloca (LGSTRING_GLYPH_LEN (gstring) * sizeof *char2b); \
23776 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23777 append_glyph_string (&(HEAD), &(TAIL), s); \
23779 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
23783 /* Add a glyph string for a sequence of glyphless character's glyphs
23784 to the list of strings between HEAD and TAIL. The meanings of
23785 arguments are the same as those of BUILD_CHAR_GLYPH_STRINGS. */
23787 #define BUILD_GLYPHLESS_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23792 face_id = (row)->glyphs[area][START].face_id; \
23794 s = alloca (sizeof *s); \
23795 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23796 append_glyph_string (&HEAD, &TAIL, s); \
23798 START = fill_glyphless_glyph_string (s, face_id, START, END, \
23804 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
23805 of AREA of glyph row ROW on window W between indices START and END.
23806 HL overrides the face for drawing glyph strings, e.g. it is
23807 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
23808 x-positions of the drawing area.
23810 This is an ugly monster macro construct because we must use alloca
23811 to allocate glyph strings (because draw_glyphs can be called
23812 asynchronously). */
23814 #define BUILD_GLYPH_STRINGS_1(START, END, HEAD, TAIL, HL, X, LAST_X) \
23817 HEAD = TAIL = NULL; \
23818 while (START < END) \
23820 struct glyph *first_glyph = (row)->glyphs[area] + START; \
23821 switch (first_glyph->type) \
23824 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
23828 case COMPOSITE_GLYPH: \
23829 if (first_glyph->u.cmp.automatic) \
23830 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
23833 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
23837 case STRETCH_GLYPH: \
23838 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
23842 case IMAGE_GLYPH: \
23843 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
23847 #define BUILD_GLYPH_STRINGS_XW(START, END, HEAD, TAIL, HL, X, LAST_X) \
23848 case XWIDGET_GLYPH: \
23849 BUILD_XWIDGET_GLYPH_STRING (START, END, HEAD, TAIL, \
23853 #define BUILD_GLYPH_STRINGS_2(START, END, HEAD, TAIL, HL, X, LAST_X) \
23854 case GLYPHLESS_GLYPH: \
23855 BUILD_GLYPHLESS_GLYPH_STRING (START, END, HEAD, TAIL, \
23865 set_glyph_string_background_width (s, START, LAST_X); \
23872 #ifdef HAVE_XWIDGETS
23873 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
23874 BUILD_GLYPH_STRINGS_1(START, END, HEAD, TAIL, HL, X, LAST_X) \
23875 BUILD_GLYPH_STRINGS_XW(START, END, HEAD, TAIL, HL, X, LAST_X) \
23876 BUILD_GLYPH_STRINGS_2(START, END, HEAD, TAIL, HL, X, LAST_X)
23878 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
23879 BUILD_GLYPH_STRINGS_1(START, END, HEAD, TAIL, HL, X, LAST_X) \
23880 BUILD_GLYPH_STRINGS_2(START, END, HEAD, TAIL, HL, X, LAST_X)
23884 /* Draw glyphs between START and END in AREA of ROW on window W,
23885 starting at x-position X. X is relative to AREA in W. HL is a
23886 face-override with the following meaning:
23888 DRAW_NORMAL_TEXT draw normally
23889 DRAW_CURSOR draw in cursor face
23890 DRAW_MOUSE_FACE draw in mouse face.
23891 DRAW_INVERSE_VIDEO draw in mode line face
23892 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
23893 DRAW_IMAGE_RAISED draw an image with a raised relief around it
23895 If OVERLAPS is non-zero, draw only the foreground of characters and
23896 clip to the physical height of ROW. Non-zero value also defines
23897 the overlapping part to be drawn:
23899 OVERLAPS_PRED overlap with preceding rows
23900 OVERLAPS_SUCC overlap with succeeding rows
23901 OVERLAPS_BOTH overlap with both preceding/succeeding rows
23902 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
23904 Value is the x-position reached, relative to AREA of W. */
23907 draw_glyphs (struct window
*w
, int x
, struct glyph_row
*row
,
23908 enum glyph_row_area area
, ptrdiff_t start
, ptrdiff_t end
,
23909 enum draw_glyphs_face hl
, int overlaps
)
23911 struct glyph_string
*head
, *tail
;
23912 struct glyph_string
*s
;
23913 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
23914 int i
, j
, x_reached
, last_x
, area_left
= 0;
23915 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
23918 ALLOCATE_HDC (hdc
, f
);
23920 /* Let's rather be paranoid than getting a SEGV. */
23921 end
= min (end
, row
->used
[area
]);
23922 start
= clip_to_bounds (0, start
, end
);
23924 /* Translate X to frame coordinates. Set last_x to the right
23925 end of the drawing area. */
23926 if (row
->full_width_p
)
23928 /* X is relative to the left edge of W, without scroll bars
23930 area_left
= WINDOW_LEFT_EDGE_X (w
);
23931 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
23935 area_left
= window_box_left (w
, area
);
23936 last_x
= area_left
+ window_box_width (w
, area
);
23940 /* Build a doubly-linked list of glyph_string structures between
23941 head and tail from what we have to draw. Note that the macro
23942 BUILD_GLYPH_STRINGS will modify its start parameter. That's
23943 the reason we use a separate variable `i'. */
23945 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
23947 x_reached
= tail
->x
+ tail
->background_width
;
23951 /* If there are any glyphs with lbearing < 0 or rbearing > width in
23952 the row, redraw some glyphs in front or following the glyph
23953 strings built above. */
23954 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
23956 struct glyph_string
*h
, *t
;
23957 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
23958 int mouse_beg_col
IF_LINT (= 0), mouse_end_col
IF_LINT (= 0);
23959 int check_mouse_face
= 0;
23962 /* If mouse highlighting is on, we may need to draw adjacent
23963 glyphs using mouse-face highlighting. */
23964 if (area
== TEXT_AREA
&& row
->mouse_face_p
23965 && hlinfo
->mouse_face_beg_row
>= 0
23966 && hlinfo
->mouse_face_end_row
>= 0)
23968 ptrdiff_t row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
23970 if (row_vpos
>= hlinfo
->mouse_face_beg_row
23971 && row_vpos
<= hlinfo
->mouse_face_end_row
)
23973 check_mouse_face
= 1;
23974 mouse_beg_col
= (row_vpos
== hlinfo
->mouse_face_beg_row
)
23975 ? hlinfo
->mouse_face_beg_col
: 0;
23976 mouse_end_col
= (row_vpos
== hlinfo
->mouse_face_end_row
)
23977 ? hlinfo
->mouse_face_end_col
23978 : row
->used
[TEXT_AREA
];
23982 /* Compute overhangs for all glyph strings. */
23983 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
23984 for (s
= head
; s
; s
= s
->next
)
23985 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
23987 /* Prepend glyph strings for glyphs in front of the first glyph
23988 string that are overwritten because of the first glyph
23989 string's left overhang. The background of all strings
23990 prepended must be drawn because the first glyph string
23992 i
= left_overwritten (head
);
23995 enum draw_glyphs_face overlap_hl
;
23997 /* If this row contains mouse highlighting, attempt to draw
23998 the overlapped glyphs with the correct highlight. This
23999 code fails if the overlap encompasses more than one glyph
24000 and mouse-highlight spans only some of these glyphs.
24001 However, making it work perfectly involves a lot more
24002 code, and I don't know if the pathological case occurs in
24003 practice, so we'll stick to this for now. --- cyd */
24004 if (check_mouse_face
24005 && mouse_beg_col
< start
&& mouse_end_col
> i
)
24006 overlap_hl
= DRAW_MOUSE_FACE
;
24008 overlap_hl
= DRAW_NORMAL_TEXT
;
24011 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
24012 overlap_hl
, dummy_x
, last_x
);
24014 compute_overhangs_and_x (t
, head
->x
, 1);
24015 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
24019 /* Prepend glyph strings for glyphs in front of the first glyph
24020 string that overwrite that glyph string because of their
24021 right overhang. For these strings, only the foreground must
24022 be drawn, because it draws over the glyph string at `head'.
24023 The background must not be drawn because this would overwrite
24024 right overhangs of preceding glyphs for which no glyph
24026 i
= left_overwriting (head
);
24029 enum draw_glyphs_face overlap_hl
;
24031 if (check_mouse_face
24032 && mouse_beg_col
< start
&& mouse_end_col
> i
)
24033 overlap_hl
= DRAW_MOUSE_FACE
;
24035 overlap_hl
= DRAW_NORMAL_TEXT
;
24038 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
24039 overlap_hl
, dummy_x
, last_x
);
24040 for (s
= h
; s
; s
= s
->next
)
24041 s
->background_filled_p
= 1;
24042 compute_overhangs_and_x (t
, head
->x
, 1);
24043 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
24046 /* Append glyphs strings for glyphs following the last glyph
24047 string tail that are overwritten by tail. The background of
24048 these strings has to be drawn because tail's foreground draws
24050 i
= right_overwritten (tail
);
24053 enum draw_glyphs_face overlap_hl
;
24055 if (check_mouse_face
24056 && mouse_beg_col
< i
&& mouse_end_col
> end
)
24057 overlap_hl
= DRAW_MOUSE_FACE
;
24059 overlap_hl
= DRAW_NORMAL_TEXT
;
24061 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
24062 overlap_hl
, x
, last_x
);
24063 /* Because BUILD_GLYPH_STRINGS updates the first argument,
24064 we don't have `end = i;' here. */
24065 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
24066 append_glyph_string_lists (&head
, &tail
, h
, t
);
24070 /* Append glyph strings for glyphs following the last glyph
24071 string tail that overwrite tail. The foreground of such
24072 glyphs has to be drawn because it writes into the background
24073 of tail. The background must not be drawn because it could
24074 paint over the foreground of following glyphs. */
24075 i
= right_overwriting (tail
);
24078 enum draw_glyphs_face overlap_hl
;
24079 if (check_mouse_face
24080 && mouse_beg_col
< i
&& mouse_end_col
> end
)
24081 overlap_hl
= DRAW_MOUSE_FACE
;
24083 overlap_hl
= DRAW_NORMAL_TEXT
;
24086 i
++; /* We must include the Ith glyph. */
24087 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
24088 overlap_hl
, x
, last_x
);
24089 for (s
= h
; s
; s
= s
->next
)
24090 s
->background_filled_p
= 1;
24091 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
24092 append_glyph_string_lists (&head
, &tail
, h
, t
);
24094 if (clip_head
|| clip_tail
)
24095 for (s
= head
; s
; s
= s
->next
)
24097 s
->clip_head
= clip_head
;
24098 s
->clip_tail
= clip_tail
;
24102 /* Draw all strings. */
24103 for (s
= head
; s
; s
= s
->next
)
24104 FRAME_RIF (f
)->draw_glyph_string (s
);
24107 /* When focus a sole frame and move horizontally, this sets on_p to 0
24108 causing a failure to erase prev cursor position. */
24109 if (area
== TEXT_AREA
24110 && !row
->full_width_p
24111 /* When drawing overlapping rows, only the glyph strings'
24112 foreground is drawn, which doesn't erase a cursor
24116 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
24117 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
24118 : (tail
? tail
->x
+ tail
->background_width
: x
));
24122 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
24123 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
24127 /* Value is the x-position up to which drawn, relative to AREA of W.
24128 This doesn't include parts drawn because of overhangs. */
24129 if (row
->full_width_p
)
24130 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
24132 x_reached
-= area_left
;
24134 RELEASE_HDC (hdc
, f
);
24139 /* Expand row matrix if too narrow. Don't expand if area
24142 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
24144 if (!fonts_changed_p \
24145 && (it->glyph_row->glyphs[area] \
24146 < it->glyph_row->glyphs[area + 1])) \
24148 it->w->ncols_scale_factor++; \
24149 fonts_changed_p = 1; \
24153 /* Store one glyph for IT->char_to_display in IT->glyph_row.
24154 Called from x_produce_glyphs when IT->glyph_row is non-null. */
24157 append_glyph (struct it
*it
)
24159 struct glyph
*glyph
;
24160 enum glyph_row_area area
= it
->area
;
24162 eassert (it
->glyph_row
);
24163 eassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
24165 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24166 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24168 /* If the glyph row is reversed, we need to prepend the glyph
24169 rather than append it. */
24170 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24174 /* Make room for the additional glyph. */
24175 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
24177 glyph
= it
->glyph_row
->glyphs
[area
];
24179 glyph
->charpos
= CHARPOS (it
->position
);
24180 glyph
->object
= it
->object
;
24181 if (it
->pixel_width
> 0)
24183 glyph
->pixel_width
= it
->pixel_width
;
24184 glyph
->padding_p
= 0;
24188 /* Assure at least 1-pixel width. Otherwise, cursor can't
24189 be displayed correctly. */
24190 glyph
->pixel_width
= 1;
24191 glyph
->padding_p
= 1;
24193 glyph
->ascent
= it
->ascent
;
24194 glyph
->descent
= it
->descent
;
24195 glyph
->voffset
= it
->voffset
;
24196 glyph
->type
= CHAR_GLYPH
;
24197 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24198 glyph
->multibyte_p
= it
->multibyte_p
;
24199 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24201 /* In R2L rows, the left and the right box edges need to be
24202 drawn in reverse direction. */
24203 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24204 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24208 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24209 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24211 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
24212 || it
->phys_descent
> it
->descent
);
24213 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
24214 glyph
->face_id
= it
->face_id
;
24215 glyph
->u
.ch
= it
->char_to_display
;
24216 glyph
->slice
.img
= null_glyph_slice
;
24217 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24220 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24221 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24223 glyph
->bidi_type
= it
->bidi_it
.type
;
24227 glyph
->resolved_level
= 0;
24228 glyph
->bidi_type
= UNKNOWN_BT
;
24230 ++it
->glyph_row
->used
[area
];
24233 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24236 /* Store one glyph for the composition IT->cmp_it.id in
24237 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
24241 append_composite_glyph (struct it
*it
)
24243 struct glyph
*glyph
;
24244 enum glyph_row_area area
= it
->area
;
24246 eassert (it
->glyph_row
);
24248 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24249 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24251 /* If the glyph row is reversed, we need to prepend the glyph
24252 rather than append it. */
24253 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
24257 /* Make room for the new glyph. */
24258 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
24260 glyph
= it
->glyph_row
->glyphs
[it
->area
];
24262 glyph
->charpos
= it
->cmp_it
.charpos
;
24263 glyph
->object
= it
->object
;
24264 glyph
->pixel_width
= it
->pixel_width
;
24265 glyph
->ascent
= it
->ascent
;
24266 glyph
->descent
= it
->descent
;
24267 glyph
->voffset
= it
->voffset
;
24268 glyph
->type
= COMPOSITE_GLYPH
;
24269 if (it
->cmp_it
.ch
< 0)
24271 glyph
->u
.cmp
.automatic
= 0;
24272 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
24273 glyph
->slice
.cmp
.from
= glyph
->slice
.cmp
.to
= 0;
24277 glyph
->u
.cmp
.automatic
= 1;
24278 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
24279 glyph
->slice
.cmp
.from
= it
->cmp_it
.from
;
24280 glyph
->slice
.cmp
.to
= it
->cmp_it
.to
- 1;
24282 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24283 glyph
->multibyte_p
= it
->multibyte_p
;
24284 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24286 /* In R2L rows, the left and the right box edges need to be
24287 drawn in reverse direction. */
24288 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24289 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24293 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24294 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24296 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
24297 || it
->phys_descent
> it
->descent
);
24298 glyph
->padding_p
= 0;
24299 glyph
->glyph_not_available_p
= 0;
24300 glyph
->face_id
= it
->face_id
;
24301 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24304 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24305 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24307 glyph
->bidi_type
= it
->bidi_it
.type
;
24309 ++it
->glyph_row
->used
[area
];
24312 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24316 /* Change IT->ascent and IT->height according to the setting of
24320 take_vertical_position_into_account (struct it
*it
)
24324 if (it
->voffset
< 0)
24325 /* Increase the ascent so that we can display the text higher
24327 it
->ascent
-= it
->voffset
;
24329 /* Increase the descent so that we can display the text lower
24331 it
->descent
+= it
->voffset
;
24336 /* Produce glyphs/get display metrics for the image IT is loaded with.
24337 See the description of struct display_iterator in dispextern.h for
24338 an overview of struct display_iterator. */
24341 produce_image_glyph (struct it
*it
)
24345 int glyph_ascent
, crop
;
24346 struct glyph_slice slice
;
24348 eassert (it
->what
== IT_IMAGE
);
24350 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24352 /* Make sure X resources of the face is loaded. */
24353 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24355 if (it
->image_id
< 0)
24357 /* Fringe bitmap. */
24358 it
->ascent
= it
->phys_ascent
= 0;
24359 it
->descent
= it
->phys_descent
= 0;
24360 it
->pixel_width
= 0;
24365 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
24367 /* Make sure X resources of the image is loaded. */
24368 prepare_image_for_display (it
->f
, img
);
24370 slice
.x
= slice
.y
= 0;
24371 slice
.width
= img
->width
;
24372 slice
.height
= img
->height
;
24374 if (INTEGERP (it
->slice
.x
))
24375 slice
.x
= XINT (it
->slice
.x
);
24376 else if (FLOATP (it
->slice
.x
))
24377 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
24379 if (INTEGERP (it
->slice
.y
))
24380 slice
.y
= XINT (it
->slice
.y
);
24381 else if (FLOATP (it
->slice
.y
))
24382 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
24384 if (INTEGERP (it
->slice
.width
))
24385 slice
.width
= XINT (it
->slice
.width
);
24386 else if (FLOATP (it
->slice
.width
))
24387 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
24389 if (INTEGERP (it
->slice
.height
))
24390 slice
.height
= XINT (it
->slice
.height
);
24391 else if (FLOATP (it
->slice
.height
))
24392 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
24394 if (slice
.x
>= img
->width
)
24395 slice
.x
= img
->width
;
24396 if (slice
.y
>= img
->height
)
24397 slice
.y
= img
->height
;
24398 if (slice
.x
+ slice
.width
>= img
->width
)
24399 slice
.width
= img
->width
- slice
.x
;
24400 if (slice
.y
+ slice
.height
> img
->height
)
24401 slice
.height
= img
->height
- slice
.y
;
24403 if (slice
.width
== 0 || slice
.height
== 0)
24406 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
24408 it
->descent
= slice
.height
- glyph_ascent
;
24410 it
->descent
+= img
->vmargin
;
24411 if (slice
.y
+ slice
.height
== img
->height
)
24412 it
->descent
+= img
->vmargin
;
24413 it
->phys_descent
= it
->descent
;
24415 it
->pixel_width
= slice
.width
;
24417 it
->pixel_width
+= img
->hmargin
;
24418 if (slice
.x
+ slice
.width
== img
->width
)
24419 it
->pixel_width
+= img
->hmargin
;
24421 /* It's quite possible for images to have an ascent greater than
24422 their height, so don't get confused in that case. */
24423 if (it
->descent
< 0)
24428 if (face
->box
!= FACE_NO_BOX
)
24430 if (face
->box_line_width
> 0)
24433 it
->ascent
+= face
->box_line_width
;
24434 if (slice
.y
+ slice
.height
== img
->height
)
24435 it
->descent
+= face
->box_line_width
;
24438 if (it
->start_of_box_run_p
&& slice
.x
== 0)
24439 it
->pixel_width
+= eabs (face
->box_line_width
);
24440 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
24441 it
->pixel_width
+= eabs (face
->box_line_width
);
24444 take_vertical_position_into_account (it
);
24446 /* Automatically crop wide image glyphs at right edge so we can
24447 draw the cursor on same display row. */
24448 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
24449 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
24451 it
->pixel_width
-= crop
;
24452 slice
.width
-= crop
;
24457 struct glyph
*glyph
;
24458 enum glyph_row_area area
= it
->area
;
24460 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24461 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24463 glyph
->charpos
= CHARPOS (it
->position
);
24464 glyph
->object
= it
->object
;
24465 glyph
->pixel_width
= it
->pixel_width
;
24466 glyph
->ascent
= glyph_ascent
;
24467 glyph
->descent
= it
->descent
;
24468 glyph
->voffset
= it
->voffset
;
24469 glyph
->type
= IMAGE_GLYPH
;
24470 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24471 glyph
->multibyte_p
= it
->multibyte_p
;
24472 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24474 /* In R2L rows, the left and the right box edges need to be
24475 drawn in reverse direction. */
24476 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24477 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24481 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24482 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24484 glyph
->overlaps_vertically_p
= 0;
24485 glyph
->padding_p
= 0;
24486 glyph
->glyph_not_available_p
= 0;
24487 glyph
->face_id
= it
->face_id
;
24488 glyph
->u
.img_id
= img
->id
;
24489 glyph
->slice
.img
= slice
;
24490 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24493 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24494 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24496 glyph
->bidi_type
= it
->bidi_it
.type
;
24498 ++it
->glyph_row
->used
[area
];
24501 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24505 #ifdef HAVE_XWIDGETS
24507 produce_xwidget_glyph (struct it
*it
)
24509 struct xwidget
* xw
;
24511 int glyph_ascent
, crop
;
24512 printf("produce_xwidget_glyph:\n");
24513 eassert (it
->what
== IT_XWIDGET
);
24515 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24517 /* Make sure X resources of the face is loaded. */
24518 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24521 it
->ascent
= it
->phys_ascent
= glyph_ascent
= xw
->height
/2;
24522 it
->descent
= xw
->height
/2;
24523 it
->phys_descent
= it
->descent
;
24524 it
->pixel_width
= xw
->width
;
24525 /* It's quite possible for images to have an ascent greater than
24526 their height, so don't get confused in that case. */
24527 if (it
->descent
< 0)
24532 if (face
->box
!= FACE_NO_BOX
)
24534 if (face
->box_line_width
> 0)
24536 it
->ascent
+= face
->box_line_width
;
24537 it
->descent
+= face
->box_line_width
;
24540 if (it
->start_of_box_run_p
)
24541 it
->pixel_width
+= eabs (face
->box_line_width
);
24542 it
->pixel_width
+= eabs (face
->box_line_width
);
24545 take_vertical_position_into_account (it
);
24547 /* Automatically crop wide image glyphs at right edge so we can
24548 draw the cursor on same display row. */
24549 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
24550 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
24552 it
->pixel_width
-= crop
;
24557 struct glyph
*glyph
;
24558 enum glyph_row_area area
= it
->area
;
24560 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24561 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24563 glyph
->charpos
= CHARPOS (it
->position
);
24564 glyph
->object
= it
->object
;
24565 glyph
->pixel_width
= it
->pixel_width
;
24566 glyph
->ascent
= glyph_ascent
;
24567 glyph
->descent
= it
->descent
;
24568 glyph
->voffset
= it
->voffset
;
24569 glyph
->type
= XWIDGET_GLYPH
;
24571 glyph
->multibyte_p
= it
->multibyte_p
;
24572 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24573 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24574 glyph
->overlaps_vertically_p
= 0;
24575 glyph
->padding_p
= 0;
24576 glyph
->glyph_not_available_p
= 0;
24577 glyph
->face_id
= it
->face_id
;
24578 glyph
->u
.xwidget
= it
->xwidget
;
24579 //assert_valid_xwidget_id(glyph->u.xwidget_id,"produce_xwidget_glyph");
24580 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24581 ++it
->glyph_row
->used
[area
];
24584 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24589 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
24590 of the glyph, WIDTH and HEIGHT are the width and height of the
24591 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
24594 append_stretch_glyph (struct it
*it
, Lisp_Object object
,
24595 int width
, int height
, int ascent
)
24597 struct glyph
*glyph
;
24598 enum glyph_row_area area
= it
->area
;
24600 eassert (ascent
>= 0 && ascent
<= height
);
24602 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24603 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24605 /* If the glyph row is reversed, we need to prepend the glyph
24606 rather than append it. */
24607 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24611 /* Make room for the additional glyph. */
24612 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
24614 glyph
= it
->glyph_row
->glyphs
[area
];
24616 glyph
->charpos
= CHARPOS (it
->position
);
24617 glyph
->object
= object
;
24618 glyph
->pixel_width
= width
;
24619 glyph
->ascent
= ascent
;
24620 glyph
->descent
= height
- ascent
;
24621 glyph
->voffset
= it
->voffset
;
24622 glyph
->type
= STRETCH_GLYPH
;
24623 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24624 glyph
->multibyte_p
= it
->multibyte_p
;
24625 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24627 /* In R2L rows, the left and the right box edges need to be
24628 drawn in reverse direction. */
24629 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24630 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24634 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24635 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24637 glyph
->overlaps_vertically_p
= 0;
24638 glyph
->padding_p
= 0;
24639 glyph
->glyph_not_available_p
= 0;
24640 glyph
->face_id
= it
->face_id
;
24641 glyph
->u
.stretch
.ascent
= ascent
;
24642 glyph
->u
.stretch
.height
= height
;
24643 glyph
->slice
.img
= null_glyph_slice
;
24644 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24647 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24648 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24650 glyph
->bidi_type
= it
->bidi_it
.type
;
24654 glyph
->resolved_level
= 0;
24655 glyph
->bidi_type
= UNKNOWN_BT
;
24657 ++it
->glyph_row
->used
[area
];
24660 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24663 #endif /* HAVE_WINDOW_SYSTEM */
24665 /* Produce a stretch glyph for iterator IT. IT->object is the value
24666 of the glyph property displayed. The value must be a list
24667 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
24670 1. `:width WIDTH' specifies that the space should be WIDTH *
24671 canonical char width wide. WIDTH may be an integer or floating
24674 2. `:relative-width FACTOR' specifies that the width of the stretch
24675 should be computed from the width of the first character having the
24676 `glyph' property, and should be FACTOR times that width.
24678 3. `:align-to HPOS' specifies that the space should be wide enough
24679 to reach HPOS, a value in canonical character units.
24681 Exactly one of the above pairs must be present.
24683 4. `:height HEIGHT' specifies that the height of the stretch produced
24684 should be HEIGHT, measured in canonical character units.
24686 5. `:relative-height FACTOR' specifies that the height of the
24687 stretch should be FACTOR times the height of the characters having
24688 the glyph property.
24690 Either none or exactly one of 4 or 5 must be present.
24692 6. `:ascent ASCENT' specifies that ASCENT percent of the height
24693 of the stretch should be used for the ascent of the stretch.
24694 ASCENT must be in the range 0 <= ASCENT <= 100. */
24697 produce_stretch_glyph (struct it
*it
)
24699 /* (space :width WIDTH :height HEIGHT ...) */
24700 Lisp_Object prop
, plist
;
24701 int width
= 0, height
= 0, align_to
= -1;
24702 int zero_width_ok_p
= 0;
24704 struct font
*font
= NULL
;
24706 #ifdef HAVE_WINDOW_SYSTEM
24708 int zero_height_ok_p
= 0;
24710 if (FRAME_WINDOW_P (it
->f
))
24712 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24713 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24714 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24718 /* List should start with `space'. */
24719 eassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
24720 plist
= XCDR (it
->object
);
24722 /* Compute the width of the stretch. */
24723 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
24724 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
24726 /* Absolute width `:width WIDTH' specified and valid. */
24727 zero_width_ok_p
= 1;
24730 #ifdef HAVE_WINDOW_SYSTEM
24731 else if (FRAME_WINDOW_P (it
->f
)
24732 && (prop
= Fplist_get (plist
, QCrelative_width
), NUMVAL (prop
) > 0))
24734 /* Relative width `:relative-width FACTOR' specified and valid.
24735 Compute the width of the characters having the `glyph'
24738 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
24741 if (it
->multibyte_p
)
24742 it2
.c
= it2
.char_to_display
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
24745 it2
.c
= it2
.char_to_display
= *p
, it2
.len
= 1;
24746 if (! ASCII_CHAR_P (it2
.c
))
24747 it2
.char_to_display
= BYTE8_TO_CHAR (it2
.c
);
24750 it2
.glyph_row
= NULL
;
24751 it2
.what
= IT_CHARACTER
;
24752 x_produce_glyphs (&it2
);
24753 width
= NUMVAL (prop
) * it2
.pixel_width
;
24755 #endif /* HAVE_WINDOW_SYSTEM */
24756 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
24757 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
24759 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
24760 align_to
= (align_to
< 0
24762 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
24763 else if (align_to
< 0)
24764 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
24765 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
24766 zero_width_ok_p
= 1;
24769 /* Nothing specified -> width defaults to canonical char width. */
24770 width
= FRAME_COLUMN_WIDTH (it
->f
);
24772 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
24775 #ifdef HAVE_WINDOW_SYSTEM
24776 /* Compute height. */
24777 if (FRAME_WINDOW_P (it
->f
))
24779 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
24780 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
24783 zero_height_ok_p
= 1;
24785 else if (prop
= Fplist_get (plist
, QCrelative_height
),
24787 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
24789 height
= FONT_HEIGHT (font
);
24791 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
24794 /* Compute percentage of height used for ascent. If
24795 `:ascent ASCENT' is present and valid, use that. Otherwise,
24796 derive the ascent from the font in use. */
24797 if (prop
= Fplist_get (plist
, QCascent
),
24798 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
24799 ascent
= height
* NUMVAL (prop
) / 100.0;
24800 else if (!NILP (prop
)
24801 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
24802 ascent
= min (max (0, (int)tem
), height
);
24804 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
24807 #endif /* HAVE_WINDOW_SYSTEM */
24810 if (width
> 0 && it
->line_wrap
!= TRUNCATE
24811 && it
->current_x
+ width
> it
->last_visible_x
)
24813 width
= it
->last_visible_x
- it
->current_x
;
24814 #ifdef HAVE_WINDOW_SYSTEM
24815 /* Subtract one more pixel from the stretch width, but only on
24816 GUI frames, since on a TTY each glyph is one "pixel" wide. */
24817 width
-= FRAME_WINDOW_P (it
->f
);
24821 if (width
> 0 && height
> 0 && it
->glyph_row
)
24823 Lisp_Object o_object
= it
->object
;
24824 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
24827 if (!STRINGP (object
))
24828 object
= it
->w
->contents
;
24829 #ifdef HAVE_WINDOW_SYSTEM
24830 if (FRAME_WINDOW_P (it
->f
))
24831 append_stretch_glyph (it
, object
, width
, height
, ascent
);
24835 it
->object
= object
;
24836 it
->char_to_display
= ' ';
24837 it
->pixel_width
= it
->len
= 1;
24839 tty_append_glyph (it
);
24840 it
->object
= o_object
;
24844 it
->pixel_width
= width
;
24845 #ifdef HAVE_WINDOW_SYSTEM
24846 if (FRAME_WINDOW_P (it
->f
))
24848 it
->ascent
= it
->phys_ascent
= ascent
;
24849 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
24850 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
24851 take_vertical_position_into_account (it
);
24855 it
->nglyphs
= width
;
24858 /* Get information about special display element WHAT in an
24859 environment described by IT. WHAT is one of IT_TRUNCATION or
24860 IT_CONTINUATION. Maybe produce glyphs for WHAT if IT has a
24861 non-null glyph_row member. This function ensures that fields like
24862 face_id, c, len of IT are left untouched. */
24865 produce_special_glyphs (struct it
*it
, enum display_element_type what
)
24872 temp_it
.object
= make_number (0);
24873 memset (&temp_it
.current
, 0, sizeof temp_it
.current
);
24875 if (what
== IT_CONTINUATION
)
24877 /* Continuation glyph. For R2L lines, we mirror it by hand. */
24878 if (it
->bidi_it
.paragraph_dir
== R2L
)
24879 SET_GLYPH_FROM_CHAR (glyph
, '/');
24881 SET_GLYPH_FROM_CHAR (glyph
, '\\');
24883 && (gc
= DISP_CONTINUE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
24885 /* FIXME: Should we mirror GC for R2L lines? */
24886 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
24887 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
24890 else if (what
== IT_TRUNCATION
)
24892 /* Truncation glyph. */
24893 SET_GLYPH_FROM_CHAR (glyph
, '$');
24895 && (gc
= DISP_TRUNC_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
24897 /* FIXME: Should we mirror GC for R2L lines? */
24898 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
24899 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
24905 #ifdef HAVE_WINDOW_SYSTEM
24906 /* On a GUI frame, when the right fringe (left fringe for R2L rows)
24907 is turned off, we precede the truncation/continuation glyphs by a
24908 stretch glyph whose width is computed such that these special
24909 glyphs are aligned at the window margin, even when very different
24910 fonts are used in different glyph rows. */
24911 if (FRAME_WINDOW_P (temp_it
.f
)
24912 /* init_iterator calls this with it->glyph_row == NULL, and it
24913 wants only the pixel width of the truncation/continuation
24915 && temp_it
.glyph_row
24916 /* insert_left_trunc_glyphs calls us at the beginning of the
24917 row, and it has its own calculation of the stretch glyph
24919 && temp_it
.glyph_row
->used
[TEXT_AREA
] > 0
24920 && (temp_it
.glyph_row
->reversed_p
24921 ? WINDOW_LEFT_FRINGE_WIDTH (temp_it
.w
)
24922 : WINDOW_RIGHT_FRINGE_WIDTH (temp_it
.w
)) == 0)
24924 int stretch_width
= temp_it
.last_visible_x
- temp_it
.current_x
;
24926 if (stretch_width
> 0)
24928 struct face
*face
= FACE_FROM_ID (temp_it
.f
, temp_it
.face_id
);
24929 struct font
*font
=
24930 face
->font
? face
->font
: FRAME_FONT (temp_it
.f
);
24931 int stretch_ascent
=
24932 (((temp_it
.ascent
+ temp_it
.descent
)
24933 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
24935 append_stretch_glyph (&temp_it
, make_number (0), stretch_width
,
24936 temp_it
.ascent
+ temp_it
.descent
,
24943 temp_it
.what
= IT_CHARACTER
;
24945 temp_it
.c
= temp_it
.char_to_display
= GLYPH_CHAR (glyph
);
24946 temp_it
.face_id
= GLYPH_FACE (glyph
);
24947 temp_it
.len
= CHAR_BYTES (temp_it
.c
);
24949 PRODUCE_GLYPHS (&temp_it
);
24950 it
->pixel_width
= temp_it
.pixel_width
;
24951 it
->nglyphs
= temp_it
.pixel_width
;
24954 #ifdef HAVE_WINDOW_SYSTEM
24956 /* Calculate line-height and line-spacing properties.
24957 An integer value specifies explicit pixel value.
24958 A float value specifies relative value to current face height.
24959 A cons (float . face-name) specifies relative value to
24960 height of specified face font.
24962 Returns height in pixels, or nil. */
24966 calc_line_height_property (struct it
*it
, Lisp_Object val
, struct font
*font
,
24967 int boff
, int override
)
24969 Lisp_Object face_name
= Qnil
;
24970 int ascent
, descent
, height
;
24972 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
24977 face_name
= XCAR (val
);
24979 if (!NUMBERP (val
))
24980 val
= make_number (1);
24981 if (NILP (face_name
))
24983 height
= it
->ascent
+ it
->descent
;
24988 if (NILP (face_name
))
24990 font
= FRAME_FONT (it
->f
);
24991 boff
= FRAME_BASELINE_OFFSET (it
->f
);
24993 else if (EQ (face_name
, Qt
))
25002 face_id
= lookup_named_face (it
->f
, face_name
, 0);
25004 return make_number (-1);
25006 face
= FACE_FROM_ID (it
->f
, face_id
);
25009 return make_number (-1);
25010 boff
= font
->baseline_offset
;
25011 if (font
->vertical_centering
)
25012 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
25015 ascent
= FONT_BASE (font
) + boff
;
25016 descent
= FONT_DESCENT (font
) - boff
;
25020 it
->override_ascent
= ascent
;
25021 it
->override_descent
= descent
;
25022 it
->override_boff
= boff
;
25025 height
= ascent
+ descent
;
25029 height
= (int)(XFLOAT_DATA (val
) * height
);
25030 else if (INTEGERP (val
))
25031 height
*= XINT (val
);
25033 return make_number (height
);
25037 /* Append a glyph for a glyphless character to IT->glyph_row. FACE_ID
25038 is a face ID to be used for the glyph. FOR_NO_FONT is nonzero if
25039 and only if this is for a character for which no font was found.
25041 If the display method (it->glyphless_method) is
25042 GLYPHLESS_DISPLAY_ACRONYM or GLYPHLESS_DISPLAY_HEX_CODE, LEN is a
25043 length of the acronym or the hexadecimal string, UPPER_XOFF and
25044 UPPER_YOFF are pixel offsets for the upper part of the string,
25045 LOWER_XOFF and LOWER_YOFF are for the lower part.
25047 For the other display methods, LEN through LOWER_YOFF are zero. */
25050 append_glyphless_glyph (struct it
*it
, int face_id
, int for_no_font
, int len
,
25051 short upper_xoff
, short upper_yoff
,
25052 short lower_xoff
, short lower_yoff
)
25054 struct glyph
*glyph
;
25055 enum glyph_row_area area
= it
->area
;
25057 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
25058 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
25060 /* If the glyph row is reversed, we need to prepend the glyph
25061 rather than append it. */
25062 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
25066 /* Make room for the additional glyph. */
25067 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
25069 glyph
= it
->glyph_row
->glyphs
[area
];
25071 glyph
->charpos
= CHARPOS (it
->position
);
25072 glyph
->object
= it
->object
;
25073 glyph
->pixel_width
= it
->pixel_width
;
25074 glyph
->ascent
= it
->ascent
;
25075 glyph
->descent
= it
->descent
;
25076 glyph
->voffset
= it
->voffset
;
25077 glyph
->type
= GLYPHLESS_GLYPH
;
25078 glyph
->u
.glyphless
.method
= it
->glyphless_method
;
25079 glyph
->u
.glyphless
.for_no_font
= for_no_font
;
25080 glyph
->u
.glyphless
.len
= len
;
25081 glyph
->u
.glyphless
.ch
= it
->c
;
25082 glyph
->slice
.glyphless
.upper_xoff
= upper_xoff
;
25083 glyph
->slice
.glyphless
.upper_yoff
= upper_yoff
;
25084 glyph
->slice
.glyphless
.lower_xoff
= lower_xoff
;
25085 glyph
->slice
.glyphless
.lower_yoff
= lower_yoff
;
25086 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
25087 glyph
->multibyte_p
= it
->multibyte_p
;
25088 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
25090 /* In R2L rows, the left and the right box edges need to be
25091 drawn in reverse direction. */
25092 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
25093 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
25097 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
25098 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
25100 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
25101 || it
->phys_descent
> it
->descent
);
25102 glyph
->padding_p
= 0;
25103 glyph
->glyph_not_available_p
= 0;
25104 glyph
->face_id
= face_id
;
25105 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
25108 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
25109 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
25111 glyph
->bidi_type
= it
->bidi_it
.type
;
25113 ++it
->glyph_row
->used
[area
];
25116 IT_EXPAND_MATRIX_WIDTH (it
, area
);
25120 /* Produce a glyph for a glyphless character for iterator IT.
25121 IT->glyphless_method specifies which method to use for displaying
25122 the character. See the description of enum
25123 glyphless_display_method in dispextern.h for the detail.
25125 FOR_NO_FONT is nonzero if and only if this is for a character for
25126 which no font was found. ACRONYM, if non-nil, is an acronym string
25127 for the character. */
25130 produce_glyphless_glyph (struct it
*it
, int for_no_font
, Lisp_Object acronym
)
25135 int base_width
, base_height
, width
, height
;
25136 short upper_xoff
, upper_yoff
, lower_xoff
, lower_yoff
;
25139 /* Get the metrics of the base font. We always refer to the current
25141 face
= FACE_FROM_ID (it
->f
, it
->face_id
)->ascii_face
;
25142 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
25143 it
->ascent
= FONT_BASE (font
) + font
->baseline_offset
;
25144 it
->descent
= FONT_DESCENT (font
) - font
->baseline_offset
;
25145 base_height
= it
->ascent
+ it
->descent
;
25146 base_width
= font
->average_width
;
25148 /* Get a face ID for the glyph by utilizing a cache (the same way as
25149 done for `escape-glyph' in get_next_display_element). */
25150 if (it
->f
== last_glyphless_glyph_frame
25151 && it
->face_id
== last_glyphless_glyph_face_id
)
25153 face_id
= last_glyphless_glyph_merged_face_id
;
25157 /* Merge the `glyphless-char' face into the current face. */
25158 face_id
= merge_faces (it
->f
, Qglyphless_char
, 0, it
->face_id
);
25159 last_glyphless_glyph_frame
= it
->f
;
25160 last_glyphless_glyph_face_id
= it
->face_id
;
25161 last_glyphless_glyph_merged_face_id
= face_id
;
25164 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_THIN_SPACE
)
25166 it
->pixel_width
= THIN_SPACE_WIDTH
;
25168 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
25170 else if (it
->glyphless_method
== GLYPHLESS_DISPLAY_EMPTY_BOX
)
25172 width
= CHAR_WIDTH (it
->c
);
25175 else if (width
> 4)
25177 it
->pixel_width
= base_width
* width
;
25179 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
25185 unsigned int code
[6];
25187 int ascent
, descent
;
25188 struct font_metrics metrics_upper
, metrics_lower
;
25190 face
= FACE_FROM_ID (it
->f
, face_id
);
25191 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
25192 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
25194 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_ACRONYM
)
25196 if (! STRINGP (acronym
) && CHAR_TABLE_P (Vglyphless_char_display
))
25197 acronym
= CHAR_TABLE_REF (Vglyphless_char_display
, it
->c
);
25198 if (CONSP (acronym
))
25199 acronym
= XCAR (acronym
);
25200 str
= STRINGP (acronym
) ? SSDATA (acronym
) : "";
25204 eassert (it
->glyphless_method
== GLYPHLESS_DISPLAY_HEX_CODE
);
25205 sprintf (buf
, "%0*X", it
->c
< 0x10000 ? 4 : 6, it
->c
);
25208 for (len
= 0; str
[len
] && ASCII_BYTE_P (str
[len
]) && len
< 6; len
++)
25209 code
[len
] = font
->driver
->encode_char (font
, str
[len
]);
25210 upper_len
= (len
+ 1) / 2;
25211 font
->driver
->text_extents (font
, code
, upper_len
,
25213 font
->driver
->text_extents (font
, code
+ upper_len
, len
- upper_len
,
25218 /* +4 is for vertical bars of a box plus 1-pixel spaces at both side. */
25219 width
= max (metrics_upper
.width
, metrics_lower
.width
) + 4;
25220 upper_xoff
= upper_yoff
= 2; /* the typical case */
25221 if (base_width
>= width
)
25223 /* Align the upper to the left, the lower to the right. */
25224 it
->pixel_width
= base_width
;
25225 lower_xoff
= base_width
- 2 - metrics_lower
.width
;
25229 /* Center the shorter one. */
25230 it
->pixel_width
= width
;
25231 if (metrics_upper
.width
>= metrics_lower
.width
)
25232 lower_xoff
= (width
- metrics_lower
.width
) / 2;
25235 /* FIXME: This code doesn't look right. It formerly was
25236 missing the "lower_xoff = 0;", which couldn't have
25237 been right since it left lower_xoff uninitialized. */
25239 upper_xoff
= (width
- metrics_upper
.width
) / 2;
25243 /* +5 is for horizontal bars of a box plus 1-pixel spaces at
25244 top, bottom, and between upper and lower strings. */
25245 height
= (metrics_upper
.ascent
+ metrics_upper
.descent
25246 + metrics_lower
.ascent
+ metrics_lower
.descent
) + 5;
25247 /* Center vertically.
25248 H:base_height, D:base_descent
25249 h:height, ld:lower_descent, la:lower_ascent, ud:upper_descent
25251 ascent = - (D - H/2 - h/2 + 1); "+ 1" for rounding up
25252 descent = D - H/2 + h/2;
25253 lower_yoff = descent - 2 - ld;
25254 upper_yoff = lower_yoff - la - 1 - ud; */
25255 ascent
= - (it
->descent
- (base_height
+ height
+ 1) / 2);
25256 descent
= it
->descent
- (base_height
- height
) / 2;
25257 lower_yoff
= descent
- 2 - metrics_lower
.descent
;
25258 upper_yoff
= (lower_yoff
- metrics_lower
.ascent
- 1
25259 - metrics_upper
.descent
);
25260 /* Don't make the height shorter than the base height. */
25261 if (height
> base_height
)
25263 it
->ascent
= ascent
;
25264 it
->descent
= descent
;
25268 it
->phys_ascent
= it
->ascent
;
25269 it
->phys_descent
= it
->descent
;
25271 append_glyphless_glyph (it
, face_id
, for_no_font
, len
,
25272 upper_xoff
, upper_yoff
,
25273 lower_xoff
, lower_yoff
);
25275 take_vertical_position_into_account (it
);
25280 Produce glyphs/get display metrics for the display element IT is
25281 loaded with. See the description of struct it in dispextern.h
25282 for an overview of struct it. */
25285 x_produce_glyphs (struct it
*it
)
25287 int extra_line_spacing
= it
->extra_line_spacing
;
25289 it
->glyph_not_available_p
= 0;
25291 if (it
->what
== IT_CHARACTER
)
25294 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25295 struct font
*font
= face
->font
;
25296 struct font_metrics
*pcm
= NULL
;
25297 int boff
; /* baseline offset */
25301 /* When no suitable font is found, display this character by
25302 the method specified in the first extra slot of
25303 Vglyphless_char_display. */
25304 Lisp_Object acronym
= lookup_glyphless_char_display (-1, it
);
25306 eassert (it
->what
== IT_GLYPHLESS
);
25307 produce_glyphless_glyph (it
, 1, STRINGP (acronym
) ? acronym
: Qnil
);
25311 boff
= font
->baseline_offset
;
25312 if (font
->vertical_centering
)
25313 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
25315 if (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t')
25321 if (it
->override_ascent
>= 0)
25323 it
->ascent
= it
->override_ascent
;
25324 it
->descent
= it
->override_descent
;
25325 boff
= it
->override_boff
;
25329 it
->ascent
= FONT_BASE (font
) + boff
;
25330 it
->descent
= FONT_DESCENT (font
) - boff
;
25333 if (get_char_glyph_code (it
->char_to_display
, font
, &char2b
))
25335 pcm
= get_per_char_metric (font
, &char2b
);
25336 if (pcm
->width
== 0
25337 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
25343 it
->phys_ascent
= pcm
->ascent
+ boff
;
25344 it
->phys_descent
= pcm
->descent
- boff
;
25345 it
->pixel_width
= pcm
->width
;
25349 it
->glyph_not_available_p
= 1;
25350 it
->phys_ascent
= it
->ascent
;
25351 it
->phys_descent
= it
->descent
;
25352 it
->pixel_width
= font
->space_width
;
25355 if (it
->constrain_row_ascent_descent_p
)
25357 if (it
->descent
> it
->max_descent
)
25359 it
->ascent
+= it
->descent
- it
->max_descent
;
25360 it
->descent
= it
->max_descent
;
25362 if (it
->ascent
> it
->max_ascent
)
25364 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
25365 it
->ascent
= it
->max_ascent
;
25367 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
25368 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
25369 extra_line_spacing
= 0;
25372 /* If this is a space inside a region of text with
25373 `space-width' property, change its width. */
25374 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
25376 it
->pixel_width
*= XFLOATINT (it
->space_width
);
25378 /* If face has a box, add the box thickness to the character
25379 height. If character has a box line to the left and/or
25380 right, add the box line width to the character's width. */
25381 if (face
->box
!= FACE_NO_BOX
)
25383 int thick
= face
->box_line_width
;
25387 it
->ascent
+= thick
;
25388 it
->descent
+= thick
;
25393 if (it
->start_of_box_run_p
)
25394 it
->pixel_width
+= thick
;
25395 if (it
->end_of_box_run_p
)
25396 it
->pixel_width
+= thick
;
25399 /* If face has an overline, add the height of the overline
25400 (1 pixel) and a 1 pixel margin to the character height. */
25401 if (face
->overline_p
)
25402 it
->ascent
+= overline_margin
;
25404 if (it
->constrain_row_ascent_descent_p
)
25406 if (it
->ascent
> it
->max_ascent
)
25407 it
->ascent
= it
->max_ascent
;
25408 if (it
->descent
> it
->max_descent
)
25409 it
->descent
= it
->max_descent
;
25412 take_vertical_position_into_account (it
);
25414 /* If we have to actually produce glyphs, do it. */
25419 /* Translate a space with a `space-width' property
25420 into a stretch glyph. */
25421 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
25422 / FONT_HEIGHT (font
));
25423 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
25424 it
->ascent
+ it
->descent
, ascent
);
25429 /* If characters with lbearing or rbearing are displayed
25430 in this line, record that fact in a flag of the
25431 glyph row. This is used to optimize X output code. */
25432 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
25433 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25435 if (! stretched_p
&& it
->pixel_width
== 0)
25436 /* We assure that all visible glyphs have at least 1-pixel
25438 it
->pixel_width
= 1;
25440 else if (it
->char_to_display
== '\n')
25442 /* A newline has no width, but we need the height of the
25443 line. But if previous part of the line sets a height,
25444 don't increase that height */
25446 Lisp_Object height
;
25447 Lisp_Object total_height
= Qnil
;
25449 it
->override_ascent
= -1;
25450 it
->pixel_width
= 0;
25453 height
= get_it_property (it
, Qline_height
);
25454 /* Split (line-height total-height) list */
25456 && CONSP (XCDR (height
))
25457 && NILP (XCDR (XCDR (height
))))
25459 total_height
= XCAR (XCDR (height
));
25460 height
= XCAR (height
);
25462 height
= calc_line_height_property (it
, height
, font
, boff
, 1);
25464 if (it
->override_ascent
>= 0)
25466 it
->ascent
= it
->override_ascent
;
25467 it
->descent
= it
->override_descent
;
25468 boff
= it
->override_boff
;
25472 it
->ascent
= FONT_BASE (font
) + boff
;
25473 it
->descent
= FONT_DESCENT (font
) - boff
;
25476 if (EQ (height
, Qt
))
25478 if (it
->descent
> it
->max_descent
)
25480 it
->ascent
+= it
->descent
- it
->max_descent
;
25481 it
->descent
= it
->max_descent
;
25483 if (it
->ascent
> it
->max_ascent
)
25485 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
25486 it
->ascent
= it
->max_ascent
;
25488 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
25489 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
25490 it
->constrain_row_ascent_descent_p
= 1;
25491 extra_line_spacing
= 0;
25495 Lisp_Object spacing
;
25497 it
->phys_ascent
= it
->ascent
;
25498 it
->phys_descent
= it
->descent
;
25500 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
25501 && face
->box
!= FACE_NO_BOX
25502 && face
->box_line_width
> 0)
25504 it
->ascent
+= face
->box_line_width
;
25505 it
->descent
+= face
->box_line_width
;
25508 && XINT (height
) > it
->ascent
+ it
->descent
)
25509 it
->ascent
= XINT (height
) - it
->descent
;
25511 if (!NILP (total_height
))
25512 spacing
= calc_line_height_property (it
, total_height
, font
, boff
, 0);
25515 spacing
= get_it_property (it
, Qline_spacing
);
25516 spacing
= calc_line_height_property (it
, spacing
, font
, boff
, 0);
25518 if (INTEGERP (spacing
))
25520 extra_line_spacing
= XINT (spacing
);
25521 if (!NILP (total_height
))
25522 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
25526 else /* i.e. (it->char_to_display == '\t') */
25528 if (font
->space_width
> 0)
25530 int tab_width
= it
->tab_width
* font
->space_width
;
25531 int x
= it
->current_x
+ it
->continuation_lines_width
;
25532 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
25534 /* If the distance from the current position to the next tab
25535 stop is less than a space character width, use the
25536 tab stop after that. */
25537 if (next_tab_x
- x
< font
->space_width
)
25538 next_tab_x
+= tab_width
;
25540 it
->pixel_width
= next_tab_x
- x
;
25542 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
25543 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
25547 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
25548 it
->ascent
+ it
->descent
, it
->ascent
);
25553 it
->pixel_width
= 0;
25558 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
25560 /* A static composition.
25562 Note: A composition is represented as one glyph in the
25563 glyph matrix. There are no padding glyphs.
25565 Important note: pixel_width, ascent, and descent are the
25566 values of what is drawn by draw_glyphs (i.e. the values of
25567 the overall glyphs composed). */
25568 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25569 int boff
; /* baseline offset */
25570 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
25571 int glyph_len
= cmp
->glyph_len
;
25572 struct font
*font
= face
->font
;
25576 /* If we have not yet calculated pixel size data of glyphs of
25577 the composition for the current face font, calculate them
25578 now. Theoretically, we have to check all fonts for the
25579 glyphs, but that requires much time and memory space. So,
25580 here we check only the font of the first glyph. This may
25581 lead to incorrect display, but it's very rare, and C-l
25582 (recenter-top-bottom) can correct the display anyway. */
25583 if (! cmp
->font
|| cmp
->font
!= font
)
25585 /* Ascent and descent of the font of the first character
25586 of this composition (adjusted by baseline offset).
25587 Ascent and descent of overall glyphs should not be less
25588 than these, respectively. */
25589 int font_ascent
, font_descent
, font_height
;
25590 /* Bounding box of the overall glyphs. */
25591 int leftmost
, rightmost
, lowest
, highest
;
25592 int lbearing
, rbearing
;
25593 int i
, width
, ascent
, descent
;
25594 int left_padded
= 0, right_padded
= 0;
25595 int c
IF_LINT (= 0); /* cmp->glyph_len can't be zero; see Bug#8512 */
25597 struct font_metrics
*pcm
;
25598 int font_not_found_p
;
25601 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
25602 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
25604 if (glyph_len
< cmp
->glyph_len
)
25606 for (i
= 0; i
< glyph_len
; i
++)
25608 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
25610 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
25615 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
25616 : IT_CHARPOS (*it
));
25617 /* If no suitable font is found, use the default font. */
25618 font_not_found_p
= font
== NULL
;
25619 if (font_not_found_p
)
25621 face
= face
->ascii_face
;
25624 boff
= font
->baseline_offset
;
25625 if (font
->vertical_centering
)
25626 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
25627 font_ascent
= FONT_BASE (font
) + boff
;
25628 font_descent
= FONT_DESCENT (font
) - boff
;
25629 font_height
= FONT_HEIGHT (font
);
25634 if (! font_not_found_p
)
25636 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
25638 pcm
= get_per_char_metric (font
, &char2b
);
25641 /* Initialize the bounding box. */
25644 width
= cmp
->glyph_len
> 0 ? pcm
->width
: 0;
25645 ascent
= pcm
->ascent
;
25646 descent
= pcm
->descent
;
25647 lbearing
= pcm
->lbearing
;
25648 rbearing
= pcm
->rbearing
;
25652 width
= cmp
->glyph_len
> 0 ? font
->space_width
: 0;
25653 ascent
= FONT_BASE (font
);
25654 descent
= FONT_DESCENT (font
);
25661 lowest
= - descent
+ boff
;
25662 highest
= ascent
+ boff
;
25664 if (! font_not_found_p
25665 && font
->default_ascent
25666 && CHAR_TABLE_P (Vuse_default_ascent
)
25667 && !NILP (Faref (Vuse_default_ascent
,
25668 make_number (it
->char_to_display
))))
25669 highest
= font
->default_ascent
+ boff
;
25671 /* Draw the first glyph at the normal position. It may be
25672 shifted to right later if some other glyphs are drawn
25674 cmp
->offsets
[i
* 2] = 0;
25675 cmp
->offsets
[i
* 2 + 1] = boff
;
25676 cmp
->lbearing
= lbearing
;
25677 cmp
->rbearing
= rbearing
;
25679 /* Set cmp->offsets for the remaining glyphs. */
25680 for (i
++; i
< glyph_len
; i
++)
25682 int left
, right
, btm
, top
;
25683 int ch
= COMPOSITION_GLYPH (cmp
, i
);
25685 struct face
*this_face
;
25689 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
25690 this_face
= FACE_FROM_ID (it
->f
, face_id
);
25691 font
= this_face
->font
;
25697 get_char_face_and_encoding (it
->f
, ch
, face_id
,
25699 pcm
= get_per_char_metric (font
, &char2b
);
25702 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
25705 width
= pcm
->width
;
25706 ascent
= pcm
->ascent
;
25707 descent
= pcm
->descent
;
25708 lbearing
= pcm
->lbearing
;
25709 rbearing
= pcm
->rbearing
;
25710 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
25712 /* Relative composition with or without
25713 alternate chars. */
25714 left
= (leftmost
+ rightmost
- width
) / 2;
25715 btm
= - descent
+ boff
;
25716 if (font
->relative_compose
25717 && (! CHAR_TABLE_P (Vignore_relative_composition
)
25718 || NILP (Faref (Vignore_relative_composition
,
25719 make_number (ch
)))))
25722 if (- descent
>= font
->relative_compose
)
25723 /* One extra pixel between two glyphs. */
25725 else if (ascent
<= 0)
25726 /* One extra pixel between two glyphs. */
25727 btm
= lowest
- 1 - ascent
- descent
;
25732 /* A composition rule is specified by an integer
25733 value that encodes global and new reference
25734 points (GREF and NREF). GREF and NREF are
25735 specified by numbers as below:
25737 0---1---2 -- ascent
25741 9--10--11 -- center
25743 ---3---4---5--- baseline
25745 6---7---8 -- descent
25747 int rule
= COMPOSITION_RULE (cmp
, i
);
25748 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
25750 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
25751 grefx
= gref
% 3, nrefx
= nref
% 3;
25752 grefy
= gref
/ 3, nrefy
= nref
/ 3;
25754 xoff
= font_height
* (xoff
- 128) / 256;
25756 yoff
= font_height
* (yoff
- 128) / 256;
25759 + grefx
* (rightmost
- leftmost
) / 2
25760 - nrefx
* width
/ 2
25763 btm
= ((grefy
== 0 ? highest
25765 : grefy
== 2 ? lowest
25766 : (highest
+ lowest
) / 2)
25767 - (nrefy
== 0 ? ascent
+ descent
25768 : nrefy
== 1 ? descent
- boff
25770 : (ascent
+ descent
) / 2)
25774 cmp
->offsets
[i
* 2] = left
;
25775 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
25777 /* Update the bounding box of the overall glyphs. */
25780 right
= left
+ width
;
25781 if (left
< leftmost
)
25783 if (right
> rightmost
)
25786 top
= btm
+ descent
+ ascent
;
25792 if (cmp
->lbearing
> left
+ lbearing
)
25793 cmp
->lbearing
= left
+ lbearing
;
25794 if (cmp
->rbearing
< left
+ rbearing
)
25795 cmp
->rbearing
= left
+ rbearing
;
25799 /* If there are glyphs whose x-offsets are negative,
25800 shift all glyphs to the right and make all x-offsets
25804 for (i
= 0; i
< cmp
->glyph_len
; i
++)
25805 cmp
->offsets
[i
* 2] -= leftmost
;
25806 rightmost
-= leftmost
;
25807 cmp
->lbearing
-= leftmost
;
25808 cmp
->rbearing
-= leftmost
;
25811 if (left_padded
&& cmp
->lbearing
< 0)
25813 for (i
= 0; i
< cmp
->glyph_len
; i
++)
25814 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
25815 rightmost
-= cmp
->lbearing
;
25816 cmp
->rbearing
-= cmp
->lbearing
;
25819 if (right_padded
&& rightmost
< cmp
->rbearing
)
25821 rightmost
= cmp
->rbearing
;
25824 cmp
->pixel_width
= rightmost
;
25825 cmp
->ascent
= highest
;
25826 cmp
->descent
= - lowest
;
25827 if (cmp
->ascent
< font_ascent
)
25828 cmp
->ascent
= font_ascent
;
25829 if (cmp
->descent
< font_descent
)
25830 cmp
->descent
= font_descent
;
25834 && (cmp
->lbearing
< 0
25835 || cmp
->rbearing
> cmp
->pixel_width
))
25836 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25838 it
->pixel_width
= cmp
->pixel_width
;
25839 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
25840 it
->descent
= it
->phys_descent
= cmp
->descent
;
25841 if (face
->box
!= FACE_NO_BOX
)
25843 int thick
= face
->box_line_width
;
25847 it
->ascent
+= thick
;
25848 it
->descent
+= thick
;
25853 if (it
->start_of_box_run_p
)
25854 it
->pixel_width
+= thick
;
25855 if (it
->end_of_box_run_p
)
25856 it
->pixel_width
+= thick
;
25859 /* If face has an overline, add the height of the overline
25860 (1 pixel) and a 1 pixel margin to the character height. */
25861 if (face
->overline_p
)
25862 it
->ascent
+= overline_margin
;
25864 take_vertical_position_into_account (it
);
25865 if (it
->ascent
< 0)
25867 if (it
->descent
< 0)
25870 if (it
->glyph_row
&& cmp
->glyph_len
> 0)
25871 append_composite_glyph (it
);
25873 else if (it
->what
== IT_COMPOSITION
)
25875 /* A dynamic (automatic) composition. */
25876 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25877 Lisp_Object gstring
;
25878 struct font_metrics metrics
;
25882 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
25884 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
25887 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
25888 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25889 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
25890 it
->descent
= it
->phys_descent
= metrics
.descent
;
25891 if (face
->box
!= FACE_NO_BOX
)
25893 int thick
= face
->box_line_width
;
25897 it
->ascent
+= thick
;
25898 it
->descent
+= thick
;
25903 if (it
->start_of_box_run_p
)
25904 it
->pixel_width
+= thick
;
25905 if (it
->end_of_box_run_p
)
25906 it
->pixel_width
+= thick
;
25908 /* If face has an overline, add the height of the overline
25909 (1 pixel) and a 1 pixel margin to the character height. */
25910 if (face
->overline_p
)
25911 it
->ascent
+= overline_margin
;
25912 take_vertical_position_into_account (it
);
25913 if (it
->ascent
< 0)
25915 if (it
->descent
< 0)
25919 append_composite_glyph (it
);
25921 else if (it
->what
== IT_GLYPHLESS
)
25922 produce_glyphless_glyph (it
, 0, Qnil
);
25923 else if (it
->what
== IT_IMAGE
)
25924 produce_image_glyph (it
);
25925 else if (it
->what
== IT_STRETCH
)
25926 produce_stretch_glyph (it
);
25927 #ifdef HAVE_XWIDGETS
25928 else if (it
->what
== IT_XWIDGET
)
25929 produce_xwidget_glyph (it
);
25932 /* Accumulate dimensions. Note: can't assume that it->descent > 0
25933 because this isn't true for images with `:ascent 100'. */
25934 eassert (it
->ascent
>= 0 && it
->descent
>= 0);
25935 if (it
->area
== TEXT_AREA
)
25936 it
->current_x
+= it
->pixel_width
;
25938 if (extra_line_spacing
> 0)
25940 it
->descent
+= extra_line_spacing
;
25941 if (extra_line_spacing
> it
->max_extra_line_spacing
)
25942 it
->max_extra_line_spacing
= extra_line_spacing
;
25945 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
25946 it
->max_descent
= max (it
->max_descent
, it
->descent
);
25947 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
25948 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
25952 Output LEN glyphs starting at START at the nominal cursor position.
25953 Advance the nominal cursor over the text. The global variable
25954 updated_row is the glyph row being updated, and updated_area is the
25955 area of that row being updated. */
25958 x_write_glyphs (struct window
*w
, struct glyph
*start
, int len
)
25960 int x
, hpos
, chpos
= w
->phys_cursor
.hpos
;
25962 eassert (updated_row
);
25963 /* When the window is hscrolled, cursor hpos can legitimately be out
25964 of bounds, but we draw the cursor at the corresponding window
25965 margin in that case. */
25966 if (!updated_row
->reversed_p
&& chpos
< 0)
25968 if (updated_row
->reversed_p
&& chpos
>= updated_row
->used
[TEXT_AREA
])
25969 chpos
= updated_row
->used
[TEXT_AREA
] - 1;
25973 /* Write glyphs. */
25975 hpos
= start
- updated_row
->glyphs
[updated_area
];
25976 x
= draw_glyphs (w
, output_cursor
.x
,
25977 updated_row
, updated_area
,
25979 DRAW_NORMAL_TEXT
, 0);
25981 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
25982 if (updated_area
== TEXT_AREA
25983 && w
->phys_cursor_on_p
25984 && w
->phys_cursor
.vpos
== output_cursor
.vpos
25986 && chpos
< hpos
+ len
)
25987 w
->phys_cursor_on_p
= 0;
25991 /* Advance the output cursor. */
25992 output_cursor
.hpos
+= len
;
25993 output_cursor
.x
= x
;
25998 Insert LEN glyphs from START at the nominal cursor position. */
26001 x_insert_glyphs (struct window
*w
, struct glyph
*start
, int len
)
26004 int line_height
, shift_by_width
, shifted_region_width
;
26005 struct glyph_row
*row
;
26006 struct glyph
*glyph
;
26007 int frame_x
, frame_y
;
26010 eassert (updated_row
);
26012 f
= XFRAME (WINDOW_FRAME (w
));
26014 /* Get the height of the line we are in. */
26016 line_height
= row
->height
;
26018 /* Get the width of the glyphs to insert. */
26019 shift_by_width
= 0;
26020 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
26021 shift_by_width
+= glyph
->pixel_width
;
26023 /* Get the width of the region to shift right. */
26024 shifted_region_width
= (window_box_width (w
, updated_area
)
26029 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
26030 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
26032 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
26033 line_height
, shift_by_width
);
26035 /* Write the glyphs. */
26036 hpos
= start
- row
->glyphs
[updated_area
];
26037 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
26039 DRAW_NORMAL_TEXT
, 0);
26041 /* Advance the output cursor. */
26042 output_cursor
.hpos
+= len
;
26043 output_cursor
.x
+= shift_by_width
;
26049 Erase the current text line from the nominal cursor position
26050 (inclusive) to pixel column TO_X (exclusive). The idea is that
26051 everything from TO_X onward is already erased.
26053 TO_X is a pixel position relative to updated_area of currently
26054 updated window W. TO_X == -1 means clear to the end of this area. */
26057 x_clear_end_of_line (struct window
*w
, int to_x
)
26060 int max_x
, min_y
, max_y
;
26061 int from_x
, from_y
, to_y
;
26063 eassert (updated_row
);
26064 f
= XFRAME (w
->frame
);
26066 if (updated_row
->full_width_p
)
26067 max_x
= WINDOW_TOTAL_WIDTH (w
);
26069 max_x
= window_box_width (w
, updated_area
);
26070 max_y
= window_text_bottom_y (w
);
26072 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
26073 of window. For TO_X > 0, truncate to end of drawing area. */
26079 to_x
= min (to_x
, max_x
);
26081 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
26083 /* Notice if the cursor will be cleared by this operation. */
26084 if (!updated_row
->full_width_p
)
26085 notice_overwritten_cursor (w
, updated_area
,
26086 output_cursor
.x
, -1,
26088 MATRIX_ROW_BOTTOM_Y (updated_row
));
26090 from_x
= output_cursor
.x
;
26092 /* Translate to frame coordinates. */
26093 if (updated_row
->full_width_p
)
26095 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
26096 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
26100 int area_left
= window_box_left (w
, updated_area
);
26101 from_x
+= area_left
;
26105 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
26106 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
26107 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
26109 /* Prevent inadvertently clearing to end of the X window. */
26110 if (to_x
> from_x
&& to_y
> from_y
)
26113 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
26114 to_x
- from_x
, to_y
- from_y
);
26119 #endif /* HAVE_WINDOW_SYSTEM */
26123 /***********************************************************************
26125 ***********************************************************************/
26127 /* Value is the internal representation of the specified cursor type
26128 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
26129 of the bar cursor. */
26131 static enum text_cursor_kinds
26132 get_specified_cursor_type (Lisp_Object arg
, int *width
)
26134 enum text_cursor_kinds type
;
26139 if (EQ (arg
, Qbox
))
26140 return FILLED_BOX_CURSOR
;
26142 if (EQ (arg
, Qhollow
))
26143 return HOLLOW_BOX_CURSOR
;
26145 if (EQ (arg
, Qbar
))
26152 && EQ (XCAR (arg
), Qbar
)
26153 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
26155 *width
= XINT (XCDR (arg
));
26159 if (EQ (arg
, Qhbar
))
26162 return HBAR_CURSOR
;
26166 && EQ (XCAR (arg
), Qhbar
)
26167 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
26169 *width
= XINT (XCDR (arg
));
26170 return HBAR_CURSOR
;
26173 /* Treat anything unknown as "hollow box cursor".
26174 It was bad to signal an error; people have trouble fixing
26175 .Xdefaults with Emacs, when it has something bad in it. */
26176 type
= HOLLOW_BOX_CURSOR
;
26181 /* Set the default cursor types for specified frame. */
26183 set_frame_cursor_types (struct frame
*f
, Lisp_Object arg
)
26188 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
26189 FRAME_CURSOR_WIDTH (f
) = width
;
26191 /* By default, set up the blink-off state depending on the on-state. */
26193 tem
= Fassoc (arg
, Vblink_cursor_alist
);
26196 FRAME_BLINK_OFF_CURSOR (f
)
26197 = get_specified_cursor_type (XCDR (tem
), &width
);
26198 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
26201 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
26203 /* Make sure the cursor gets redrawn. */
26204 cursor_type_changed
= 1;
26208 #ifdef HAVE_WINDOW_SYSTEM
26210 /* Return the cursor we want to be displayed in window W. Return
26211 width of bar/hbar cursor through WIDTH arg. Return with
26212 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
26213 (i.e. if the `system caret' should track this cursor).
26215 In a mini-buffer window, we want the cursor only to appear if we
26216 are reading input from this window. For the selected window, we
26217 want the cursor type given by the frame parameter or buffer local
26218 setting of cursor-type. If explicitly marked off, draw no cursor.
26219 In all other cases, we want a hollow box cursor. */
26221 static enum text_cursor_kinds
26222 get_window_cursor_type (struct window
*w
, struct glyph
*glyph
, int *width
,
26223 int *active_cursor
)
26225 struct frame
*f
= XFRAME (w
->frame
);
26226 struct buffer
*b
= XBUFFER (w
->contents
);
26227 int cursor_type
= DEFAULT_CURSOR
;
26228 Lisp_Object alt_cursor
;
26229 int non_selected
= 0;
26231 *active_cursor
= 1;
26234 if (cursor_in_echo_area
26235 && FRAME_HAS_MINIBUF_P (f
)
26236 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
26238 if (w
== XWINDOW (echo_area_window
))
26240 if (EQ (BVAR (b
, cursor_type
), Qt
) || NILP (BVAR (b
, cursor_type
)))
26242 *width
= FRAME_CURSOR_WIDTH (f
);
26243 return FRAME_DESIRED_CURSOR (f
);
26246 return get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
26249 *active_cursor
= 0;
26253 /* Detect a nonselected window or nonselected frame. */
26254 else if (w
!= XWINDOW (f
->selected_window
)
26255 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)
26257 *active_cursor
= 0;
26259 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
26265 /* Never display a cursor in a window in which cursor-type is nil. */
26266 if (NILP (BVAR (b
, cursor_type
)))
26269 /* Get the normal cursor type for this window. */
26270 if (EQ (BVAR (b
, cursor_type
), Qt
))
26272 cursor_type
= FRAME_DESIRED_CURSOR (f
);
26273 *width
= FRAME_CURSOR_WIDTH (f
);
26276 cursor_type
= get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
26278 /* Use cursor-in-non-selected-windows instead
26279 for non-selected window or frame. */
26282 alt_cursor
= BVAR (b
, cursor_in_non_selected_windows
);
26283 if (!EQ (Qt
, alt_cursor
))
26284 return get_specified_cursor_type (alt_cursor
, width
);
26285 /* t means modify the normal cursor type. */
26286 if (cursor_type
== FILLED_BOX_CURSOR
)
26287 cursor_type
= HOLLOW_BOX_CURSOR
;
26288 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
26290 return cursor_type
;
26293 /* Use normal cursor if not blinked off. */
26294 if (!w
->cursor_off_p
)
26297 #ifdef HAVE_XWIDGETS
26298 if (glyph
!= NULL
&& glyph
->type
== XWIDGET_GLYPH
){
26299 //printf("attempt xwidget cursor avoidance in get_window_cursor_type\n");
26303 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
26305 if (cursor_type
== FILLED_BOX_CURSOR
)
26307 /* Using a block cursor on large images can be very annoying.
26308 So use a hollow cursor for "large" images.
26309 If image is not transparent (no mask), also use hollow cursor. */
26310 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
26311 if (img
!= NULL
&& IMAGEP (img
->spec
))
26313 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
26314 where N = size of default frame font size.
26315 This should cover most of the "tiny" icons people may use. */
26317 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
26318 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
26319 cursor_type
= HOLLOW_BOX_CURSOR
;
26322 else if (cursor_type
!= NO_CURSOR
)
26324 /* Display current only supports BOX and HOLLOW cursors for images.
26325 So for now, unconditionally use a HOLLOW cursor when cursor is
26326 not a solid box cursor. */
26327 cursor_type
= HOLLOW_BOX_CURSOR
;
26330 return cursor_type
;
26333 /* Cursor is blinked off, so determine how to "toggle" it. */
26335 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
26336 if ((alt_cursor
= Fassoc (BVAR (b
, cursor_type
), Vblink_cursor_alist
), !NILP (alt_cursor
)))
26337 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
26339 /* Then see if frame has specified a specific blink off cursor type. */
26340 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
26342 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
26343 return FRAME_BLINK_OFF_CURSOR (f
);
26347 /* Some people liked having a permanently visible blinking cursor,
26348 while others had very strong opinions against it. So it was
26349 decided to remove it. KFS 2003-09-03 */
26351 /* Finally perform built-in cursor blinking:
26352 filled box <-> hollow box
26353 wide [h]bar <-> narrow [h]bar
26354 narrow [h]bar <-> no cursor
26355 other type <-> no cursor */
26357 if (cursor_type
== FILLED_BOX_CURSOR
)
26358 return HOLLOW_BOX_CURSOR
;
26360 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
26363 return cursor_type
;
26371 /* Notice when the text cursor of window W has been completely
26372 overwritten by a drawing operation that outputs glyphs in AREA
26373 starting at X0 and ending at X1 in the line starting at Y0 and
26374 ending at Y1. X coordinates are area-relative. X1 < 0 means all
26375 the rest of the line after X0 has been written. Y coordinates
26376 are window-relative. */
26379 notice_overwritten_cursor (struct window
*w
, enum glyph_row_area area
,
26380 int x0
, int x1
, int y0
, int y1
)
26382 int cx0
, cx1
, cy0
, cy1
;
26383 struct glyph_row
*row
;
26385 if (!w
->phys_cursor_on_p
)
26387 if (area
!= TEXT_AREA
)
26390 if (w
->phys_cursor
.vpos
< 0
26391 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
26392 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
26393 !(row
->enabled_p
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
))))
26396 if (row
->cursor_in_fringe_p
)
26398 row
->cursor_in_fringe_p
= 0;
26399 draw_fringe_bitmap (w
, row
, row
->reversed_p
);
26400 w
->phys_cursor_on_p
= 0;
26404 cx0
= w
->phys_cursor
.x
;
26405 cx1
= cx0
+ w
->phys_cursor_width
;
26406 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
26409 /* The cursor image will be completely removed from the
26410 screen if the output area intersects the cursor area in
26411 y-direction. When we draw in [y0 y1[, and some part of
26412 the cursor is at y < y0, that part must have been drawn
26413 before. When scrolling, the cursor is erased before
26414 actually scrolling, so we don't come here. When not
26415 scrolling, the rows above the old cursor row must have
26416 changed, and in this case these rows must have written
26417 over the cursor image.
26419 Likewise if part of the cursor is below y1, with the
26420 exception of the cursor being in the first blank row at
26421 the buffer and window end because update_text_area
26422 doesn't draw that row. (Except when it does, but
26423 that's handled in update_text_area.) */
26425 cy0
= w
->phys_cursor
.y
;
26426 cy1
= cy0
+ w
->phys_cursor_height
;
26427 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
26430 w
->phys_cursor_on_p
= 0;
26433 #endif /* HAVE_WINDOW_SYSTEM */
26436 /************************************************************************
26438 ************************************************************************/
26440 #ifdef HAVE_WINDOW_SYSTEM
26443 Fix the display of area AREA of overlapping row ROW in window W
26444 with respect to the overlapping part OVERLAPS. */
26447 x_fix_overlapping_area (struct window
*w
, struct glyph_row
*row
,
26448 enum glyph_row_area area
, int overlaps
)
26455 for (i
= 0; i
< row
->used
[area
];)
26457 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
26459 int start
= i
, start_x
= x
;
26463 x
+= row
->glyphs
[area
][i
].pixel_width
;
26466 while (i
< row
->used
[area
]
26467 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
26469 draw_glyphs (w
, start_x
, row
, area
,
26471 DRAW_NORMAL_TEXT
, overlaps
);
26475 x
+= row
->glyphs
[area
][i
].pixel_width
;
26485 Draw the cursor glyph of window W in glyph row ROW. See the
26486 comment of draw_glyphs for the meaning of HL. */
26489 draw_phys_cursor_glyph (struct window
*w
, struct glyph_row
*row
,
26490 enum draw_glyphs_face hl
)
26492 /* If cursor hpos is out of bounds, don't draw garbage. This can
26493 happen in mini-buffer windows when switching between echo area
26494 glyphs and mini-buffer. */
26495 if ((row
->reversed_p
26496 ? (w
->phys_cursor
.hpos
>= 0)
26497 : (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])))
26499 int on_p
= w
->phys_cursor_on_p
;
26501 int hpos
= w
->phys_cursor
.hpos
;
26503 /* When the window is hscrolled, cursor hpos can legitimately be
26504 out of bounds, but we draw the cursor at the corresponding
26505 window margin in that case. */
26506 if (!row
->reversed_p
&& hpos
< 0)
26508 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26509 hpos
= row
->used
[TEXT_AREA
] - 1;
26511 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
, hpos
, hpos
+ 1,
26513 w
->phys_cursor_on_p
= on_p
;
26515 if (hl
== DRAW_CURSOR
)
26516 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
26517 /* When we erase the cursor, and ROW is overlapped by other
26518 rows, make sure that these overlapping parts of other rows
26520 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
26522 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
26524 if (row
> w
->current_matrix
->rows
26525 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
26526 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
26527 OVERLAPS_ERASED_CURSOR
);
26529 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
26530 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
26531 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
26532 OVERLAPS_ERASED_CURSOR
);
26539 Erase the image of a cursor of window W from the screen. */
26542 erase_phys_cursor (struct window
*w
)
26544 struct frame
*f
= XFRAME (w
->frame
);
26545 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
26546 int hpos
= w
->phys_cursor
.hpos
;
26547 int vpos
= w
->phys_cursor
.vpos
;
26548 int mouse_face_here_p
= 0;
26549 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
26550 struct glyph_row
*cursor_row
;
26551 struct glyph
*cursor_glyph
;
26552 enum draw_glyphs_face hl
;
26554 /* No cursor displayed or row invalidated => nothing to do on the
26556 if (w
->phys_cursor_type
== NO_CURSOR
)
26557 goto mark_cursor_off
;
26559 /* VPOS >= active_glyphs->nrows means that window has been resized.
26560 Don't bother to erase the cursor. */
26561 if (vpos
>= active_glyphs
->nrows
)
26562 goto mark_cursor_off
;
26564 /* If row containing cursor is marked invalid, there is nothing we
26566 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
26567 if (!cursor_row
->enabled_p
)
26568 goto mark_cursor_off
;
26570 /* If line spacing is > 0, old cursor may only be partially visible in
26571 window after split-window. So adjust visible height. */
26572 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
26573 window_text_bottom_y (w
) - cursor_row
->y
);
26575 /* If row is completely invisible, don't attempt to delete a cursor which
26576 isn't there. This can happen if cursor is at top of a window, and
26577 we switch to a buffer with a header line in that window. */
26578 if (cursor_row
->visible_height
<= 0)
26579 goto mark_cursor_off
;
26581 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
26582 if (cursor_row
->cursor_in_fringe_p
)
26584 cursor_row
->cursor_in_fringe_p
= 0;
26585 draw_fringe_bitmap (w
, cursor_row
, cursor_row
->reversed_p
);
26586 goto mark_cursor_off
;
26589 /* This can happen when the new row is shorter than the old one.
26590 In this case, either draw_glyphs or clear_end_of_line
26591 should have cleared the cursor. Note that we wouldn't be
26592 able to erase the cursor in this case because we don't have a
26593 cursor glyph at hand. */
26594 if ((cursor_row
->reversed_p
26595 ? (w
->phys_cursor
.hpos
< 0)
26596 : (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])))
26597 goto mark_cursor_off
;
26599 /* When the window is hscrolled, cursor hpos can legitimately be out
26600 of bounds, but we draw the cursor at the corresponding window
26601 margin in that case. */
26602 if (!cursor_row
->reversed_p
&& hpos
< 0)
26604 if (cursor_row
->reversed_p
&& hpos
>= cursor_row
->used
[TEXT_AREA
])
26605 hpos
= cursor_row
->used
[TEXT_AREA
] - 1;
26607 /* If the cursor is in the mouse face area, redisplay that when
26608 we clear the cursor. */
26609 if (! NILP (hlinfo
->mouse_face_window
)
26610 && coords_in_mouse_face_p (w
, hpos
, vpos
)
26611 /* Don't redraw the cursor's spot in mouse face if it is at the
26612 end of a line (on a newline). The cursor appears there, but
26613 mouse highlighting does not. */
26614 && cursor_row
->used
[TEXT_AREA
] > hpos
&& hpos
>= 0)
26615 mouse_face_here_p
= 1;
26617 /* Maybe clear the display under the cursor. */
26618 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
26621 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
26624 cursor_glyph
= get_phys_cursor_glyph (w
);
26625 if (cursor_glyph
== NULL
)
26626 goto mark_cursor_off
;
26628 width
= cursor_glyph
->pixel_width
;
26629 left_x
= window_box_left_offset (w
, TEXT_AREA
);
26630 x
= w
->phys_cursor
.x
;
26632 width
-= left_x
- x
;
26633 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
26634 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
26635 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
26638 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
26641 /* Erase the cursor by redrawing the character underneath it. */
26642 if (mouse_face_here_p
)
26643 hl
= DRAW_MOUSE_FACE
;
26645 hl
= DRAW_NORMAL_TEXT
;
26646 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
26649 w
->phys_cursor_on_p
= 0;
26650 w
->phys_cursor_type
= NO_CURSOR
;
26655 Display or clear cursor of window W. If ON is zero, clear the
26656 cursor. If it is non-zero, display the cursor. If ON is nonzero,
26657 where to put the cursor is specified by HPOS, VPOS, X and Y. */
26660 display_and_set_cursor (struct window
*w
, int on
,
26661 int hpos
, int vpos
, int x
, int y
)
26663 struct frame
*f
= XFRAME (w
->frame
);
26664 int new_cursor_type
;
26665 int new_cursor_width
;
26667 struct glyph_row
*glyph_row
;
26668 struct glyph
*glyph
;
26670 /* This is pointless on invisible frames, and dangerous on garbaged
26671 windows and frames; in the latter case, the frame or window may
26672 be in the midst of changing its size, and x and y may be off the
26674 if (! FRAME_VISIBLE_P (f
)
26675 || FRAME_GARBAGED_P (f
)
26676 || vpos
>= w
->current_matrix
->nrows
26677 || hpos
>= w
->current_matrix
->matrix_w
)
26680 /* If cursor is off and we want it off, return quickly. */
26681 if (!on
&& !w
->phys_cursor_on_p
)
26684 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26685 /* If cursor row is not enabled, we don't really know where to
26686 display the cursor. */
26687 if (!glyph_row
->enabled_p
)
26689 w
->phys_cursor_on_p
= 0;
26694 if (!glyph_row
->exact_window_width_line_p
26695 || (0 <= hpos
&& hpos
< glyph_row
->used
[TEXT_AREA
]))
26696 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
26698 eassert (input_blocked_p ());
26700 /* Set new_cursor_type to the cursor we want to be displayed. */
26701 new_cursor_type
= get_window_cursor_type (w
, glyph
,
26702 &new_cursor_width
, &active_cursor
);
26704 /* If cursor is currently being shown and we don't want it to be or
26705 it is in the wrong place, or the cursor type is not what we want,
26707 if (w
->phys_cursor_on_p
26709 || w
->phys_cursor
.x
!= x
26710 || w
->phys_cursor
.y
!= y
26711 || new_cursor_type
!= w
->phys_cursor_type
26712 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
26713 && new_cursor_width
!= w
->phys_cursor_width
)))
26714 erase_phys_cursor (w
);
26716 /* Don't check phys_cursor_on_p here because that flag is only set
26717 to zero in some cases where we know that the cursor has been
26718 completely erased, to avoid the extra work of erasing the cursor
26719 twice. In other words, phys_cursor_on_p can be 1 and the cursor
26720 still not be visible, or it has only been partly erased. */
26723 w
->phys_cursor_ascent
= glyph_row
->ascent
;
26724 w
->phys_cursor_height
= glyph_row
->height
;
26726 /* Set phys_cursor_.* before x_draw_.* is called because some
26727 of them may need the information. */
26728 w
->phys_cursor
.x
= x
;
26729 w
->phys_cursor
.y
= glyph_row
->y
;
26730 w
->phys_cursor
.hpos
= hpos
;
26731 w
->phys_cursor
.vpos
= vpos
;
26734 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
26735 new_cursor_type
, new_cursor_width
,
26736 on
, active_cursor
);
26740 /* Switch the display of W's cursor on or off, according to the value
26744 update_window_cursor (struct window
*w
, int on
)
26746 /* Don't update cursor in windows whose frame is in the process
26747 of being deleted. */
26748 if (w
->current_matrix
)
26750 int hpos
= w
->phys_cursor
.hpos
;
26751 int vpos
= w
->phys_cursor
.vpos
;
26752 struct glyph_row
*row
;
26754 if (vpos
>= w
->current_matrix
->nrows
26755 || hpos
>= w
->current_matrix
->matrix_w
)
26758 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26760 /* When the window is hscrolled, cursor hpos can legitimately be
26761 out of bounds, but we draw the cursor at the corresponding
26762 window margin in that case. */
26763 if (!row
->reversed_p
&& hpos
< 0)
26765 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26766 hpos
= row
->used
[TEXT_AREA
] - 1;
26769 display_and_set_cursor (w
, on
, hpos
, vpos
,
26770 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
26776 /* Call update_window_cursor with parameter ON_P on all leaf windows
26777 in the window tree rooted at W. */
26780 update_cursor_in_window_tree (struct window
*w
, int on_p
)
26784 if (WINDOWP (w
->contents
))
26785 update_cursor_in_window_tree (XWINDOW (w
->contents
), on_p
);
26787 update_window_cursor (w
, on_p
);
26789 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
26795 Display the cursor on window W, or clear it, according to ON_P.
26796 Don't change the cursor's position. */
26799 x_update_cursor (struct frame
*f
, int on_p
)
26801 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
26806 Clear the cursor of window W to background color, and mark the
26807 cursor as not shown. This is used when the text where the cursor
26808 is about to be rewritten. */
26811 x_clear_cursor (struct window
*w
)
26813 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
26814 update_window_cursor (w
, 0);
26817 #endif /* HAVE_WINDOW_SYSTEM */
26819 /* Implementation of draw_row_with_mouse_face for GUI sessions, GPM,
26822 draw_row_with_mouse_face (struct window
*w
, int start_x
, struct glyph_row
*row
,
26823 int start_hpos
, int end_hpos
,
26824 enum draw_glyphs_face draw
)
26826 #ifdef HAVE_WINDOW_SYSTEM
26827 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
26829 draw_glyphs (w
, start_x
, row
, TEXT_AREA
, start_hpos
, end_hpos
, draw
, 0);
26833 #if defined (HAVE_GPM) || defined (MSDOS) || defined (WINDOWSNT)
26834 tty_draw_row_with_mouse_face (w
, row
, start_hpos
, end_hpos
, draw
);
26838 /* Display the active region described by mouse_face_* according to DRAW. */
26841 show_mouse_face (Mouse_HLInfo
*hlinfo
, enum draw_glyphs_face draw
)
26843 struct window
*w
= XWINDOW (hlinfo
->mouse_face_window
);
26844 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
26846 if (/* If window is in the process of being destroyed, don't bother
26848 w
->current_matrix
!= NULL
26849 /* Don't update mouse highlight if hidden */
26850 && (draw
!= DRAW_MOUSE_FACE
|| !hlinfo
->mouse_face_hidden
)
26851 /* Recognize when we are called to operate on rows that don't exist
26852 anymore. This can happen when a window is split. */
26853 && hlinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
26855 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
26856 struct glyph_row
*row
, *first
, *last
;
26858 first
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
26859 last
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
26861 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
26863 int start_hpos
, end_hpos
, start_x
;
26865 /* For all but the first row, the highlight starts at column 0. */
26868 /* R2L rows have BEG and END in reversed order, but the
26869 screen drawing geometry is always left to right. So
26870 we need to mirror the beginning and end of the
26871 highlighted area in R2L rows. */
26872 if (!row
->reversed_p
)
26874 start_hpos
= hlinfo
->mouse_face_beg_col
;
26875 start_x
= hlinfo
->mouse_face_beg_x
;
26877 else if (row
== last
)
26879 start_hpos
= hlinfo
->mouse_face_end_col
;
26880 start_x
= hlinfo
->mouse_face_end_x
;
26888 else if (row
->reversed_p
&& row
== last
)
26890 start_hpos
= hlinfo
->mouse_face_end_col
;
26891 start_x
= hlinfo
->mouse_face_end_x
;
26901 if (!row
->reversed_p
)
26902 end_hpos
= hlinfo
->mouse_face_end_col
;
26903 else if (row
== first
)
26904 end_hpos
= hlinfo
->mouse_face_beg_col
;
26907 end_hpos
= row
->used
[TEXT_AREA
];
26908 if (draw
== DRAW_NORMAL_TEXT
)
26909 row
->fill_line_p
= 1; /* Clear to end of line */
26912 else if (row
->reversed_p
&& row
== first
)
26913 end_hpos
= hlinfo
->mouse_face_beg_col
;
26916 end_hpos
= row
->used
[TEXT_AREA
];
26917 if (draw
== DRAW_NORMAL_TEXT
)
26918 row
->fill_line_p
= 1; /* Clear to end of line */
26921 if (end_hpos
> start_hpos
)
26923 draw_row_with_mouse_face (w
, start_x
, row
,
26924 start_hpos
, end_hpos
, draw
);
26927 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
26931 #ifdef HAVE_WINDOW_SYSTEM
26932 /* When we've written over the cursor, arrange for it to
26933 be displayed again. */
26934 if (FRAME_WINDOW_P (f
)
26935 && phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
26937 int hpos
= w
->phys_cursor
.hpos
;
26939 /* When the window is hscrolled, cursor hpos can legitimately be
26940 out of bounds, but we draw the cursor at the corresponding
26941 window margin in that case. */
26942 if (!row
->reversed_p
&& hpos
< 0)
26944 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26945 hpos
= row
->used
[TEXT_AREA
] - 1;
26948 display_and_set_cursor (w
, 1, hpos
, w
->phys_cursor
.vpos
,
26949 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
26952 #endif /* HAVE_WINDOW_SYSTEM */
26955 #ifdef HAVE_WINDOW_SYSTEM
26956 /* Change the mouse cursor. */
26957 if (FRAME_WINDOW_P (f
))
26959 if (draw
== DRAW_NORMAL_TEXT
26960 && !EQ (hlinfo
->mouse_face_window
, f
->tool_bar_window
))
26961 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
26962 else if (draw
== DRAW_MOUSE_FACE
)
26963 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
26965 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
26967 #endif /* HAVE_WINDOW_SYSTEM */
26971 Clear out the mouse-highlighted active region.
26972 Redraw it un-highlighted first. Value is non-zero if mouse
26973 face was actually drawn unhighlighted. */
26976 clear_mouse_face (Mouse_HLInfo
*hlinfo
)
26980 if (!hlinfo
->mouse_face_hidden
&& !NILP (hlinfo
->mouse_face_window
))
26982 show_mouse_face (hlinfo
, DRAW_NORMAL_TEXT
);
26986 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
26987 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
26988 hlinfo
->mouse_face_window
= Qnil
;
26989 hlinfo
->mouse_face_overlay
= Qnil
;
26993 /* Return non-zero if the coordinates HPOS and VPOS on windows W are
26994 within the mouse face on that window. */
26996 coords_in_mouse_face_p (struct window
*w
, int hpos
, int vpos
)
26998 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
27000 /* Quickly resolve the easy cases. */
27001 if (!(WINDOWP (hlinfo
->mouse_face_window
)
27002 && XWINDOW (hlinfo
->mouse_face_window
) == w
))
27004 if (vpos
< hlinfo
->mouse_face_beg_row
27005 || vpos
> hlinfo
->mouse_face_end_row
)
27007 if (vpos
> hlinfo
->mouse_face_beg_row
27008 && vpos
< hlinfo
->mouse_face_end_row
)
27011 if (!MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
)
27013 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
27015 if (hlinfo
->mouse_face_beg_col
<= hpos
&& hpos
< hlinfo
->mouse_face_end_col
)
27018 else if ((vpos
== hlinfo
->mouse_face_beg_row
27019 && hpos
>= hlinfo
->mouse_face_beg_col
)
27020 || (vpos
== hlinfo
->mouse_face_end_row
27021 && hpos
< hlinfo
->mouse_face_end_col
))
27026 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
27028 if (hlinfo
->mouse_face_end_col
< hpos
&& hpos
<= hlinfo
->mouse_face_beg_col
)
27031 else if ((vpos
== hlinfo
->mouse_face_beg_row
27032 && hpos
<= hlinfo
->mouse_face_beg_col
)
27033 || (vpos
== hlinfo
->mouse_face_end_row
27034 && hpos
> hlinfo
->mouse_face_end_col
))
27042 Non-zero if physical cursor of window W is within mouse face. */
27045 cursor_in_mouse_face_p (struct window
*w
)
27047 int hpos
= w
->phys_cursor
.hpos
;
27048 int vpos
= w
->phys_cursor
.vpos
;
27049 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
27051 /* When the window is hscrolled, cursor hpos can legitimately be out
27052 of bounds, but we draw the cursor at the corresponding window
27053 margin in that case. */
27054 if (!row
->reversed_p
&& hpos
< 0)
27056 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
27057 hpos
= row
->used
[TEXT_AREA
] - 1;
27059 return coords_in_mouse_face_p (w
, hpos
, vpos
);
27064 /* Find the glyph rows START_ROW and END_ROW of window W that display
27065 characters between buffer positions START_CHARPOS and END_CHARPOS
27066 (excluding END_CHARPOS). DISP_STRING is a display string that
27067 covers these buffer positions. This is similar to
27068 row_containing_pos, but is more accurate when bidi reordering makes
27069 buffer positions change non-linearly with glyph rows. */
27071 rows_from_pos_range (struct window
*w
,
27072 ptrdiff_t start_charpos
, ptrdiff_t end_charpos
,
27073 Lisp_Object disp_string
,
27074 struct glyph_row
**start
, struct glyph_row
**end
)
27076 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27077 int last_y
= window_text_bottom_y (w
);
27078 struct glyph_row
*row
;
27083 while (!first
->enabled_p
27084 && first
< MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
27087 /* Find the START row. */
27089 row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
;
27092 /* A row can potentially be the START row if the range of the
27093 characters it displays intersects the range
27094 [START_CHARPOS..END_CHARPOS). */
27095 if (! ((start_charpos
< MATRIX_ROW_START_CHARPOS (row
)
27096 && end_charpos
< MATRIX_ROW_START_CHARPOS (row
))
27097 /* See the commentary in row_containing_pos, for the
27098 explanation of the complicated way to check whether
27099 some position is beyond the end of the characters
27100 displayed by a row. */
27101 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (row
)
27102 || (start_charpos
== MATRIX_ROW_END_CHARPOS (row
)
27103 && !row
->ends_at_zv_p
27104 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
27105 && (end_charpos
> MATRIX_ROW_END_CHARPOS (row
)
27106 || (end_charpos
== MATRIX_ROW_END_CHARPOS (row
)
27107 && !row
->ends_at_zv_p
27108 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))))
27110 /* Found a candidate row. Now make sure at least one of the
27111 glyphs it displays has a charpos from the range
27112 [START_CHARPOS..END_CHARPOS).
27114 This is not obvious because bidi reordering could make
27115 buffer positions of a row be 1,2,3,102,101,100, and if we
27116 want to highlight characters in [50..60), we don't want
27117 this row, even though [50..60) does intersect [1..103),
27118 the range of character positions given by the row's start
27119 and end positions. */
27120 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
27121 struct glyph
*e
= g
+ row
->used
[TEXT_AREA
];
27125 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
27126 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
27127 /* A glyph that comes from DISP_STRING is by
27128 definition to be highlighted. */
27129 || EQ (g
->object
, disp_string
))
27138 /* Find the END row. */
27140 /* If the last row is partially visible, start looking for END
27141 from that row, instead of starting from FIRST. */
27142 && !(row
->enabled_p
27143 && row
->y
< last_y
&& MATRIX_ROW_BOTTOM_Y (row
) > last_y
))
27145 for ( ; row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
; row
++)
27147 struct glyph_row
*next
= row
+ 1;
27148 ptrdiff_t next_start
= MATRIX_ROW_START_CHARPOS (next
);
27150 if (!next
->enabled_p
27151 || next
>= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
)
27152 /* The first row >= START whose range of displayed characters
27153 does NOT intersect the range [START_CHARPOS..END_CHARPOS]
27154 is the row END + 1. */
27155 || (start_charpos
< next_start
27156 && end_charpos
< next_start
)
27157 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (next
)
27158 || (start_charpos
== MATRIX_ROW_END_CHARPOS (next
)
27159 && !next
->ends_at_zv_p
27160 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))
27161 && (end_charpos
> MATRIX_ROW_END_CHARPOS (next
)
27162 || (end_charpos
== MATRIX_ROW_END_CHARPOS (next
)
27163 && !next
->ends_at_zv_p
27164 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))))
27171 /* If the next row's edges intersect [START_CHARPOS..END_CHARPOS],
27172 but none of the characters it displays are in the range, it is
27174 struct glyph
*g
= next
->glyphs
[TEXT_AREA
];
27175 struct glyph
*s
= g
;
27176 struct glyph
*e
= g
+ next
->used
[TEXT_AREA
];
27180 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
27181 && ((start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
27182 /* If the buffer position of the first glyph in
27183 the row is equal to END_CHARPOS, it means
27184 the last character to be highlighted is the
27185 newline of ROW, and we must consider NEXT as
27187 || (((!next
->reversed_p
&& g
== s
)
27188 || (next
->reversed_p
&& g
== e
- 1))
27189 && (g
->charpos
== end_charpos
27190 /* Special case for when NEXT is an
27191 empty line at ZV. */
27192 || (g
->charpos
== -1
27193 && !row
->ends_at_zv_p
27194 && next_start
== end_charpos
)))))
27195 /* A glyph that comes from DISP_STRING is by
27196 definition to be highlighted. */
27197 || EQ (g
->object
, disp_string
))
27206 /* The first row that ends at ZV must be the last to be
27208 else if (next
->ends_at_zv_p
)
27217 /* This function sets the mouse_face_* elements of HLINFO, assuming
27218 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
27219 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
27220 for the overlay or run of text properties specifying the mouse
27221 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
27222 before-string and after-string that must also be highlighted.
27223 DISP_STRING, if non-nil, is a display string that may cover some
27224 or all of the highlighted text. */
27227 mouse_face_from_buffer_pos (Lisp_Object window
,
27228 Mouse_HLInfo
*hlinfo
,
27229 ptrdiff_t mouse_charpos
,
27230 ptrdiff_t start_charpos
,
27231 ptrdiff_t end_charpos
,
27232 Lisp_Object before_string
,
27233 Lisp_Object after_string
,
27234 Lisp_Object disp_string
)
27236 struct window
*w
= XWINDOW (window
);
27237 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27238 struct glyph_row
*r1
, *r2
;
27239 struct glyph
*glyph
, *end
;
27240 ptrdiff_t ignore
, pos
;
27243 eassert (NILP (disp_string
) || STRINGP (disp_string
));
27244 eassert (NILP (before_string
) || STRINGP (before_string
));
27245 eassert (NILP (after_string
) || STRINGP (after_string
));
27247 /* Find the rows corresponding to START_CHARPOS and END_CHARPOS. */
27248 rows_from_pos_range (w
, start_charpos
, end_charpos
, disp_string
, &r1
, &r2
);
27250 r1
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
27251 /* If the before-string or display-string contains newlines,
27252 rows_from_pos_range skips to its last row. Move back. */
27253 if (!NILP (before_string
) || !NILP (disp_string
))
27255 struct glyph_row
*prev
;
27256 while ((prev
= r1
- 1, prev
>= first
)
27257 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
27258 && prev
->used
[TEXT_AREA
] > 0)
27260 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
27261 glyph
= beg
+ prev
->used
[TEXT_AREA
];
27262 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
27264 || !(EQ (glyph
->object
, before_string
)
27265 || EQ (glyph
->object
, disp_string
)))
27272 r2
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
27273 hlinfo
->mouse_face_past_end
= 1;
27275 else if (!NILP (after_string
))
27277 /* If the after-string has newlines, advance to its last row. */
27278 struct glyph_row
*next
;
27279 struct glyph_row
*last
27280 = MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
27282 for (next
= r2
+ 1;
27284 && next
->used
[TEXT_AREA
] > 0
27285 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
27289 /* The rest of the display engine assumes that mouse_face_beg_row is
27290 either above mouse_face_end_row or identical to it. But with
27291 bidi-reordered continued lines, the row for START_CHARPOS could
27292 be below the row for END_CHARPOS. If so, swap the rows and store
27293 them in correct order. */
27296 struct glyph_row
*tem
= r2
;
27302 hlinfo
->mouse_face_beg_y
= r1
->y
;
27303 hlinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (r1
, w
->current_matrix
);
27304 hlinfo
->mouse_face_end_y
= r2
->y
;
27305 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r2
, w
->current_matrix
);
27307 /* For a bidi-reordered row, the positions of BEFORE_STRING,
27308 AFTER_STRING, DISP_STRING, START_CHARPOS, and END_CHARPOS
27309 could be anywhere in the row and in any order. The strategy
27310 below is to find the leftmost and the rightmost glyph that
27311 belongs to either of these 3 strings, or whose position is
27312 between START_CHARPOS and END_CHARPOS, and highlight all the
27313 glyphs between those two. This may cover more than just the text
27314 between START_CHARPOS and END_CHARPOS if the range of characters
27315 strides the bidi level boundary, e.g. if the beginning is in R2L
27316 text while the end is in L2R text or vice versa. */
27317 if (!r1
->reversed_p
)
27319 /* This row is in a left to right paragraph. Scan it left to
27321 glyph
= r1
->glyphs
[TEXT_AREA
];
27322 end
= glyph
+ r1
->used
[TEXT_AREA
];
27325 /* Skip truncation glyphs at the start of the glyph row. */
27326 if (MATRIX_ROW_DISPLAYS_TEXT_P (r1
))
27328 && INTEGERP (glyph
->object
)
27329 && glyph
->charpos
< 0;
27331 x
+= glyph
->pixel_width
;
27333 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
27334 or DISP_STRING, and the first glyph from buffer whose
27335 position is between START_CHARPOS and END_CHARPOS. */
27337 && !INTEGERP (glyph
->object
)
27338 && !EQ (glyph
->object
, disp_string
)
27339 && !(BUFFERP (glyph
->object
)
27340 && (glyph
->charpos
>= start_charpos
27341 && glyph
->charpos
< end_charpos
));
27344 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27345 are present at buffer positions between START_CHARPOS and
27346 END_CHARPOS, or if they come from an overlay. */
27347 if (EQ (glyph
->object
, before_string
))
27349 pos
= string_buffer_position (before_string
,
27351 /* If pos == 0, it means before_string came from an
27352 overlay, not from a buffer position. */
27353 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27356 else if (EQ (glyph
->object
, after_string
))
27358 pos
= string_buffer_position (after_string
, end_charpos
);
27359 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27362 x
+= glyph
->pixel_width
;
27364 hlinfo
->mouse_face_beg_x
= x
;
27365 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
27369 /* This row is in a right to left paragraph. Scan it right to
27373 end
= r1
->glyphs
[TEXT_AREA
] - 1;
27374 glyph
= end
+ r1
->used
[TEXT_AREA
];
27376 /* Skip truncation glyphs at the start of the glyph row. */
27377 if (MATRIX_ROW_DISPLAYS_TEXT_P (r1
))
27379 && INTEGERP (glyph
->object
)
27380 && glyph
->charpos
< 0;
27384 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
27385 or DISP_STRING, and the first glyph from buffer whose
27386 position is between START_CHARPOS and END_CHARPOS. */
27388 && !INTEGERP (glyph
->object
)
27389 && !EQ (glyph
->object
, disp_string
)
27390 && !(BUFFERP (glyph
->object
)
27391 && (glyph
->charpos
>= start_charpos
27392 && glyph
->charpos
< end_charpos
));
27395 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27396 are present at buffer positions between START_CHARPOS and
27397 END_CHARPOS, or if they come from an overlay. */
27398 if (EQ (glyph
->object
, before_string
))
27400 pos
= string_buffer_position (before_string
, start_charpos
);
27401 /* If pos == 0, it means before_string came from an
27402 overlay, not from a buffer position. */
27403 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27406 else if (EQ (glyph
->object
, after_string
))
27408 pos
= string_buffer_position (after_string
, end_charpos
);
27409 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27414 glyph
++; /* first glyph to the right of the highlighted area */
27415 for (g
= r1
->glyphs
[TEXT_AREA
], x
= r1
->x
; g
< glyph
; g
++)
27416 x
+= g
->pixel_width
;
27417 hlinfo
->mouse_face_beg_x
= x
;
27418 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
27421 /* If the highlight ends in a different row, compute GLYPH and END
27422 for the end row. Otherwise, reuse the values computed above for
27423 the row where the highlight begins. */
27426 if (!r2
->reversed_p
)
27428 glyph
= r2
->glyphs
[TEXT_AREA
];
27429 end
= glyph
+ r2
->used
[TEXT_AREA
];
27434 end
= r2
->glyphs
[TEXT_AREA
] - 1;
27435 glyph
= end
+ r2
->used
[TEXT_AREA
];
27439 if (!r2
->reversed_p
)
27441 /* Skip truncation and continuation glyphs near the end of the
27442 row, and also blanks and stretch glyphs inserted by
27443 extend_face_to_end_of_line. */
27445 && INTEGERP ((end
- 1)->object
))
27447 /* Scan the rest of the glyph row from the end, looking for the
27448 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
27449 DISP_STRING, or whose position is between START_CHARPOS
27453 && !INTEGERP (end
->object
)
27454 && !EQ (end
->object
, disp_string
)
27455 && !(BUFFERP (end
->object
)
27456 && (end
->charpos
>= start_charpos
27457 && end
->charpos
< end_charpos
));
27460 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27461 are present at buffer positions between START_CHARPOS and
27462 END_CHARPOS, or if they come from an overlay. */
27463 if (EQ (end
->object
, before_string
))
27465 pos
= string_buffer_position (before_string
, start_charpos
);
27466 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27469 else if (EQ (end
->object
, after_string
))
27471 pos
= string_buffer_position (after_string
, end_charpos
);
27472 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27476 /* Find the X coordinate of the last glyph to be highlighted. */
27477 for (; glyph
<= end
; ++glyph
)
27478 x
+= glyph
->pixel_width
;
27480 hlinfo
->mouse_face_end_x
= x
;
27481 hlinfo
->mouse_face_end_col
= glyph
- r2
->glyphs
[TEXT_AREA
];
27485 /* Skip truncation and continuation glyphs near the end of the
27486 row, and also blanks and stretch glyphs inserted by
27487 extend_face_to_end_of_line. */
27491 && INTEGERP (end
->object
))
27493 x
+= end
->pixel_width
;
27496 /* Scan the rest of the glyph row from the end, looking for the
27497 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
27498 DISP_STRING, or whose position is between START_CHARPOS
27502 && !INTEGERP (end
->object
)
27503 && !EQ (end
->object
, disp_string
)
27504 && !(BUFFERP (end
->object
)
27505 && (end
->charpos
>= start_charpos
27506 && end
->charpos
< end_charpos
));
27509 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27510 are present at buffer positions between START_CHARPOS and
27511 END_CHARPOS, or if they come from an overlay. */
27512 if (EQ (end
->object
, before_string
))
27514 pos
= string_buffer_position (before_string
, start_charpos
);
27515 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27518 else if (EQ (end
->object
, after_string
))
27520 pos
= string_buffer_position (after_string
, end_charpos
);
27521 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27524 x
+= end
->pixel_width
;
27526 /* If we exited the above loop because we arrived at the last
27527 glyph of the row, and its buffer position is still not in
27528 range, it means the last character in range is the preceding
27529 newline. Bump the end column and x values to get past the
27532 && BUFFERP (end
->object
)
27533 && (end
->charpos
< start_charpos
27534 || end
->charpos
>= end_charpos
))
27536 x
+= end
->pixel_width
;
27539 hlinfo
->mouse_face_end_x
= x
;
27540 hlinfo
->mouse_face_end_col
= end
- r2
->glyphs
[TEXT_AREA
];
27543 hlinfo
->mouse_face_window
= window
;
27544 hlinfo
->mouse_face_face_id
27545 = face_at_buffer_position (w
, mouse_charpos
, 0, 0, &ignore
,
27547 !hlinfo
->mouse_face_hidden
, -1);
27548 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
27551 /* The following function is not used anymore (replaced with
27552 mouse_face_from_string_pos), but I leave it here for the time
27553 being, in case someone would. */
27555 #if 0 /* not used */
27557 /* Find the position of the glyph for position POS in OBJECT in
27558 window W's current matrix, and return in *X, *Y the pixel
27559 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
27561 RIGHT_P non-zero means return the position of the right edge of the
27562 glyph, RIGHT_P zero means return the left edge position.
27564 If no glyph for POS exists in the matrix, return the position of
27565 the glyph with the next smaller position that is in the matrix, if
27566 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
27567 exists in the matrix, return the position of the glyph with the
27568 next larger position in OBJECT.
27570 Value is non-zero if a glyph was found. */
27573 fast_find_string_pos (struct window
*w
, ptrdiff_t pos
, Lisp_Object object
,
27574 int *hpos
, int *vpos
, int *x
, int *y
, int right_p
)
27576 int yb
= window_text_bottom_y (w
);
27577 struct glyph_row
*r
;
27578 struct glyph
*best_glyph
= NULL
;
27579 struct glyph_row
*best_row
= NULL
;
27582 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27583 r
->enabled_p
&& r
->y
< yb
;
27586 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
27587 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
27590 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
27591 if (EQ (g
->object
, object
))
27593 if (g
->charpos
== pos
)
27600 else if (best_glyph
== NULL
27601 || ((eabs (g
->charpos
- pos
)
27602 < eabs (best_glyph
->charpos
- pos
))
27605 : g
->charpos
> pos
)))
27619 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
27623 *x
+= best_glyph
->pixel_width
;
27628 *vpos
= MATRIX_ROW_VPOS (best_row
, w
->current_matrix
);
27631 return best_glyph
!= NULL
;
27633 #endif /* not used */
27635 /* Find the positions of the first and the last glyphs in window W's
27636 current matrix that occlude positions [STARTPOS..ENDPOS] in OBJECT
27637 (assumed to be a string), and return in HLINFO's mouse_face_*
27638 members the pixel and column/row coordinates of those glyphs. */
27641 mouse_face_from_string_pos (struct window
*w
, Mouse_HLInfo
*hlinfo
,
27642 Lisp_Object object
,
27643 ptrdiff_t startpos
, ptrdiff_t endpos
)
27645 int yb
= window_text_bottom_y (w
);
27646 struct glyph_row
*r
;
27647 struct glyph
*g
, *e
;
27651 /* Find the glyph row with at least one position in the range
27652 [STARTPOS..ENDPOS], and the first glyph in that row whose
27653 position belongs to that range. */
27654 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27655 r
->enabled_p
&& r
->y
< yb
;
27658 if (!r
->reversed_p
)
27660 g
= r
->glyphs
[TEXT_AREA
];
27661 e
= g
+ r
->used
[TEXT_AREA
];
27662 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
27663 if (EQ (g
->object
, object
)
27664 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
27666 hlinfo
->mouse_face_beg_row
27667 = MATRIX_ROW_VPOS (r
, w
->current_matrix
);
27668 hlinfo
->mouse_face_beg_y
= r
->y
;
27669 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
27670 hlinfo
->mouse_face_beg_x
= gx
;
27679 e
= r
->glyphs
[TEXT_AREA
];
27680 g
= e
+ r
->used
[TEXT_AREA
];
27681 for ( ; g
> e
; --g
)
27682 if (EQ ((g
-1)->object
, object
)
27683 && startpos
<= (g
-1)->charpos
&& (g
-1)->charpos
<= endpos
)
27685 hlinfo
->mouse_face_beg_row
27686 = MATRIX_ROW_VPOS (r
, w
->current_matrix
);
27687 hlinfo
->mouse_face_beg_y
= r
->y
;
27688 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
27689 for (gx
= r
->x
, g1
= r
->glyphs
[TEXT_AREA
]; g1
< g
; ++g1
)
27690 gx
+= g1
->pixel_width
;
27691 hlinfo
->mouse_face_beg_x
= gx
;
27703 /* Starting with the next row, look for the first row which does NOT
27704 include any glyphs whose positions are in the range. */
27705 for (++r
; r
->enabled_p
&& r
->y
< yb
; ++r
)
27707 g
= r
->glyphs
[TEXT_AREA
];
27708 e
= g
+ r
->used
[TEXT_AREA
];
27710 for ( ; g
< e
; ++g
)
27711 if (EQ (g
->object
, object
)
27712 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
27721 /* The highlighted region ends on the previous row. */
27724 /* Set the end row and its vertical pixel coordinate. */
27725 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r
, w
->current_matrix
);
27726 hlinfo
->mouse_face_end_y
= r
->y
;
27728 /* Compute and set the end column and the end column's horizontal
27729 pixel coordinate. */
27730 if (!r
->reversed_p
)
27732 g
= r
->glyphs
[TEXT_AREA
];
27733 e
= g
+ r
->used
[TEXT_AREA
];
27734 for ( ; e
> g
; --e
)
27735 if (EQ ((e
-1)->object
, object
)
27736 && startpos
<= (e
-1)->charpos
&& (e
-1)->charpos
<= endpos
)
27738 hlinfo
->mouse_face_end_col
= e
- g
;
27740 for (gx
= r
->x
; g
< e
; ++g
)
27741 gx
+= g
->pixel_width
;
27742 hlinfo
->mouse_face_end_x
= gx
;
27746 e
= r
->glyphs
[TEXT_AREA
];
27747 g
= e
+ r
->used
[TEXT_AREA
];
27748 for (gx
= r
->x
; e
< g
; ++e
)
27750 if (EQ (e
->object
, object
)
27751 && startpos
<= e
->charpos
&& e
->charpos
<= endpos
)
27753 gx
+= e
->pixel_width
;
27755 hlinfo
->mouse_face_end_col
= e
- r
->glyphs
[TEXT_AREA
];
27756 hlinfo
->mouse_face_end_x
= gx
;
27760 #ifdef HAVE_WINDOW_SYSTEM
27762 /* See if position X, Y is within a hot-spot of an image. */
27765 on_hot_spot_p (Lisp_Object hot_spot
, int x
, int y
)
27767 if (!CONSP (hot_spot
))
27770 if (EQ (XCAR (hot_spot
), Qrect
))
27772 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
27773 Lisp_Object rect
= XCDR (hot_spot
);
27777 if (!CONSP (XCAR (rect
)))
27779 if (!CONSP (XCDR (rect
)))
27781 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
27783 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
27785 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
27787 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
27791 else if (EQ (XCAR (hot_spot
), Qcircle
))
27793 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
27794 Lisp_Object circ
= XCDR (hot_spot
);
27795 Lisp_Object lr
, lx0
, ly0
;
27797 && CONSP (XCAR (circ
))
27798 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
27799 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
27800 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
27802 double r
= XFLOATINT (lr
);
27803 double dx
= XINT (lx0
) - x
;
27804 double dy
= XINT (ly0
) - y
;
27805 return (dx
* dx
+ dy
* dy
<= r
* r
);
27808 else if (EQ (XCAR (hot_spot
), Qpoly
))
27810 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
27811 if (VECTORP (XCDR (hot_spot
)))
27813 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
27814 Lisp_Object
*poly
= v
->contents
;
27815 ptrdiff_t n
= v
->header
.size
;
27818 Lisp_Object lx
, ly
;
27821 /* Need an even number of coordinates, and at least 3 edges. */
27822 if (n
< 6 || n
& 1)
27825 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
27826 If count is odd, we are inside polygon. Pixels on edges
27827 may or may not be included depending on actual geometry of the
27829 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
27830 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
27832 x0
= XINT (lx
), y0
= XINT (ly
);
27833 for (i
= 0; i
< n
; i
+= 2)
27835 int x1
= x0
, y1
= y0
;
27836 if ((lx
= poly
[i
], !INTEGERP (lx
))
27837 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
27839 x0
= XINT (lx
), y0
= XINT (ly
);
27841 /* Does this segment cross the X line? */
27849 if (y
> y0
&& y
> y1
)
27851 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
27861 find_hot_spot (Lisp_Object map
, int x
, int y
)
27863 while (CONSP (map
))
27865 if (CONSP (XCAR (map
))
27866 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
27874 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
27876 doc
: /* Lookup in image map MAP coordinates X and Y.
27877 An image map is an alist where each element has the format (AREA ID PLIST).
27878 An AREA is specified as either a rectangle, a circle, or a polygon:
27879 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
27880 pixel coordinates of the upper left and bottom right corners.
27881 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
27882 and the radius of the circle; r may be a float or integer.
27883 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
27884 vector describes one corner in the polygon.
27885 Returns the alist element for the first matching AREA in MAP. */)
27886 (Lisp_Object map
, Lisp_Object x
, Lisp_Object y
)
27894 return find_hot_spot (map
,
27895 clip_to_bounds (INT_MIN
, XINT (x
), INT_MAX
),
27896 clip_to_bounds (INT_MIN
, XINT (y
), INT_MAX
));
27900 /* Display frame CURSOR, optionally using shape defined by POINTER. */
27902 define_frame_cursor1 (struct frame
*f
, Cursor cursor
, Lisp_Object pointer
)
27904 /* Do not change cursor shape while dragging mouse. */
27905 if (!NILP (do_mouse_tracking
))
27908 if (!NILP (pointer
))
27910 if (EQ (pointer
, Qarrow
))
27911 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27912 else if (EQ (pointer
, Qhand
))
27913 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
27914 else if (EQ (pointer
, Qtext
))
27915 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
27916 else if (EQ (pointer
, intern ("hdrag")))
27917 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
27918 #ifdef HAVE_X_WINDOWS
27919 else if (EQ (pointer
, intern ("vdrag")))
27920 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
27922 else if (EQ (pointer
, intern ("hourglass")))
27923 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
27924 else if (EQ (pointer
, Qmodeline
))
27925 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
27927 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27930 if (cursor
!= No_Cursor
)
27931 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
27934 #endif /* HAVE_WINDOW_SYSTEM */
27936 /* Take proper action when mouse has moved to the mode or header line
27937 or marginal area AREA of window W, x-position X and y-position Y.
27938 X is relative to the start of the text display area of W, so the
27939 width of bitmap areas and scroll bars must be subtracted to get a
27940 position relative to the start of the mode line. */
27943 note_mode_line_or_margin_highlight (Lisp_Object window
, int x
, int y
,
27944 enum window_part area
)
27946 struct window
*w
= XWINDOW (window
);
27947 struct frame
*f
= XFRAME (w
->frame
);
27948 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
27949 #ifdef HAVE_WINDOW_SYSTEM
27950 Display_Info
*dpyinfo
;
27952 Cursor cursor
= No_Cursor
;
27953 Lisp_Object pointer
= Qnil
;
27954 int dx
, dy
, width
, height
;
27956 Lisp_Object string
, object
= Qnil
;
27957 Lisp_Object pos
IF_LINT (= Qnil
), help
;
27959 Lisp_Object mouse_face
;
27960 int original_x_pixel
= x
;
27961 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
27962 struct glyph_row
*row
IF_LINT (= 0);
27964 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
27969 /* Kludge alert: mode_line_string takes X/Y in pixels, but
27970 returns them in row/column units! */
27971 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
27972 &object
, &dx
, &dy
, &width
, &height
);
27974 row
= (area
== ON_MODE_LINE
27975 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
27976 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
27978 /* Find the glyph under the mouse pointer. */
27979 if (row
->mode_line_p
&& row
->enabled_p
)
27981 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
27982 end
= glyph
+ row
->used
[TEXT_AREA
];
27984 for (x0
= original_x_pixel
;
27985 glyph
< end
&& x0
>= glyph
->pixel_width
;
27987 x0
-= glyph
->pixel_width
;
27995 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
27996 /* Kludge alert: marginal_area_string takes X/Y in pixels, but
27997 returns them in row/column units! */
27998 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
27999 &object
, &dx
, &dy
, &width
, &height
);
28004 #ifdef HAVE_WINDOW_SYSTEM
28005 if (IMAGEP (object
))
28007 Lisp_Object image_map
, hotspot
;
28008 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
28010 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
28012 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
28016 /* Could check XCAR (hotspot) to see if we enter/leave this hot-spot.
28017 If so, we could look for mouse-enter, mouse-leave
28018 properties in PLIST (and do something...). */
28019 hotspot
= XCDR (hotspot
);
28020 if (CONSP (hotspot
)
28021 && (plist
= XCAR (hotspot
), CONSP (plist
)))
28023 pointer
= Fplist_get (plist
, Qpointer
);
28024 if (NILP (pointer
))
28026 help
= Fplist_get (plist
, Qhelp_echo
);
28029 help_echo_string
= help
;
28030 XSETWINDOW (help_echo_window
, w
);
28031 help_echo_object
= w
->contents
;
28032 help_echo_pos
= charpos
;
28036 if (NILP (pointer
))
28037 pointer
= Fplist_get (XCDR (object
), QCpointer
);
28039 #endif /* HAVE_WINDOW_SYSTEM */
28041 if (STRINGP (string
))
28042 pos
= make_number (charpos
);
28044 /* Set the help text and mouse pointer. If the mouse is on a part
28045 of the mode line without any text (e.g. past the right edge of
28046 the mode line text), use the default help text and pointer. */
28047 if (STRINGP (string
) || area
== ON_MODE_LINE
)
28049 /* Arrange to display the help by setting the global variables
28050 help_echo_string, help_echo_object, and help_echo_pos. */
28053 if (STRINGP (string
))
28054 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
28058 help_echo_string
= help
;
28059 XSETWINDOW (help_echo_window
, w
);
28060 help_echo_object
= string
;
28061 help_echo_pos
= charpos
;
28063 else if (area
== ON_MODE_LINE
)
28065 Lisp_Object default_help
28066 = buffer_local_value_1 (Qmode_line_default_help_echo
,
28069 if (STRINGP (default_help
))
28071 help_echo_string
= default_help
;
28072 XSETWINDOW (help_echo_window
, w
);
28073 help_echo_object
= Qnil
;
28074 help_echo_pos
= -1;
28079 #ifdef HAVE_WINDOW_SYSTEM
28080 /* Change the mouse pointer according to what is under it. */
28081 if (FRAME_WINDOW_P (f
))
28083 dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
28084 if (STRINGP (string
))
28086 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
28088 if (NILP (pointer
))
28089 pointer
= Fget_text_property (pos
, Qpointer
, string
);
28091 /* Change the mouse pointer according to what is under X/Y. */
28093 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
28096 map
= Fget_text_property (pos
, Qlocal_map
, string
);
28097 if (!KEYMAPP (map
))
28098 map
= Fget_text_property (pos
, Qkeymap
, string
);
28099 if (!KEYMAPP (map
))
28100 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
28104 /* Default mode-line pointer. */
28105 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
28110 /* Change the mouse face according to what is under X/Y. */
28111 if (STRINGP (string
))
28113 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
28114 if (!NILP (Vmouse_highlight
) && !NILP (mouse_face
)
28115 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
28120 struct glyph
* tmp_glyph
;
28124 int total_pixel_width
;
28125 ptrdiff_t begpos
, endpos
, ignore
;
28129 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
28130 Qmouse_face
, string
, Qnil
);
28136 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
28138 endpos
= SCHARS (string
);
28142 /* Calculate the glyph position GPOS of GLYPH in the
28143 displayed string, relative to the beginning of the
28144 highlighted part of the string.
28146 Note: GPOS is different from CHARPOS. CHARPOS is the
28147 position of GLYPH in the internal string object. A mode
28148 line string format has structures which are converted to
28149 a flattened string by the Emacs Lisp interpreter. The
28150 internal string is an element of those structures. The
28151 displayed string is the flattened string. */
28152 tmp_glyph
= row_start_glyph
;
28153 while (tmp_glyph
< glyph
28154 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
28155 && begpos
<= tmp_glyph
->charpos
28156 && tmp_glyph
->charpos
< endpos
)))
28158 gpos
= glyph
- tmp_glyph
;
28160 /* Calculate the length GSEQ_LENGTH of the glyph sequence of
28161 the highlighted part of the displayed string to which
28162 GLYPH belongs. Note: GSEQ_LENGTH is different from
28163 SCHARS (STRING), because the latter returns the length of
28164 the internal string. */
28165 for (tmp_glyph
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
28167 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
28168 && begpos
<= tmp_glyph
->charpos
28169 && tmp_glyph
->charpos
< endpos
));
28172 gseq_length
= gpos
+ (tmp_glyph
- glyph
) + 1;
28174 /* Calculate the total pixel width of all the glyphs between
28175 the beginning of the highlighted area and GLYPH. */
28176 total_pixel_width
= 0;
28177 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
28178 total_pixel_width
+= tmp_glyph
->pixel_width
;
28180 /* Pre calculation of re-rendering position. Note: X is in
28181 column units here, after the call to mode_line_string or
28182 marginal_area_string. */
28184 vpos
= (area
== ON_MODE_LINE
28185 ? (w
->current_matrix
)->nrows
- 1
28188 /* If GLYPH's position is included in the region that is
28189 already drawn in mouse face, we have nothing to do. */
28190 if ( EQ (window
, hlinfo
->mouse_face_window
)
28191 && (!row
->reversed_p
28192 ? (hlinfo
->mouse_face_beg_col
<= hpos
28193 && hpos
< hlinfo
->mouse_face_end_col
)
28194 /* In R2L rows we swap BEG and END, see below. */
28195 : (hlinfo
->mouse_face_end_col
<= hpos
28196 && hpos
< hlinfo
->mouse_face_beg_col
))
28197 && hlinfo
->mouse_face_beg_row
== vpos
)
28200 if (clear_mouse_face (hlinfo
))
28201 cursor
= No_Cursor
;
28203 if (!row
->reversed_p
)
28205 hlinfo
->mouse_face_beg_col
= hpos
;
28206 hlinfo
->mouse_face_beg_x
= original_x_pixel
28207 - (total_pixel_width
+ dx
);
28208 hlinfo
->mouse_face_end_col
= hpos
+ gseq_length
;
28209 hlinfo
->mouse_face_end_x
= 0;
28213 /* In R2L rows, show_mouse_face expects BEG and END
28214 coordinates to be swapped. */
28215 hlinfo
->mouse_face_end_col
= hpos
;
28216 hlinfo
->mouse_face_end_x
= original_x_pixel
28217 - (total_pixel_width
+ dx
);
28218 hlinfo
->mouse_face_beg_col
= hpos
+ gseq_length
;
28219 hlinfo
->mouse_face_beg_x
= 0;
28222 hlinfo
->mouse_face_beg_row
= vpos
;
28223 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_beg_row
;
28224 hlinfo
->mouse_face_beg_y
= 0;
28225 hlinfo
->mouse_face_end_y
= 0;
28226 hlinfo
->mouse_face_past_end
= 0;
28227 hlinfo
->mouse_face_window
= window
;
28229 hlinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
28235 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
28237 if (NILP (pointer
))
28240 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
28241 clear_mouse_face (hlinfo
);
28243 #ifdef HAVE_WINDOW_SYSTEM
28244 if (FRAME_WINDOW_P (f
))
28245 define_frame_cursor1 (f
, cursor
, pointer
);
28251 Take proper action when the mouse has moved to position X, Y on
28252 frame F with regards to highlighting portions of display that have
28253 mouse-face properties. Also de-highlight portions of display where
28254 the mouse was before, set the mouse pointer shape as appropriate
28255 for the mouse coordinates, and activate help echo (tooltips).
28256 X and Y can be negative or out of range. */
28259 note_mouse_highlight (struct frame
*f
, int x
, int y
)
28261 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28262 enum window_part part
= ON_NOTHING
;
28263 Lisp_Object window
;
28265 Cursor cursor
= No_Cursor
;
28266 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
28269 /* When a menu is active, don't highlight because this looks odd. */
28270 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (MSDOS)
28271 if (popup_activated ())
28275 if (!f
->glyphs_initialized_p
28276 || f
->pointer_invisible
)
28279 hlinfo
->mouse_face_mouse_x
= x
;
28280 hlinfo
->mouse_face_mouse_y
= y
;
28281 hlinfo
->mouse_face_mouse_frame
= f
;
28283 if (hlinfo
->mouse_face_defer
)
28286 /* Which window is that in? */
28287 window
= window_from_coordinates (f
, x
, y
, &part
, 1);
28289 /* If displaying active text in another window, clear that. */
28290 if (! EQ (window
, hlinfo
->mouse_face_window
)
28291 /* Also clear if we move out of text area in same window. */
28292 || (!NILP (hlinfo
->mouse_face_window
)
28295 && part
!= ON_MODE_LINE
28296 && part
!= ON_HEADER_LINE
))
28297 clear_mouse_face (hlinfo
);
28299 /* Not on a window -> return. */
28300 if (!WINDOWP (window
))
28303 /* Reset help_echo_string. It will get recomputed below. */
28304 help_echo_string
= Qnil
;
28306 /* Convert to window-relative pixel coordinates. */
28307 w
= XWINDOW (window
);
28308 frame_to_window_pixel_xy (w
, &x
, &y
);
28310 #ifdef HAVE_WINDOW_SYSTEM
28311 /* Handle tool-bar window differently since it doesn't display a
28313 if (EQ (window
, f
->tool_bar_window
))
28315 note_tool_bar_highlight (f
, x
, y
);
28320 /* Mouse is on the mode, header line or margin? */
28321 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
28322 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
28324 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
28328 #ifdef HAVE_WINDOW_SYSTEM
28329 if (part
== ON_VERTICAL_BORDER
)
28331 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
28332 help_echo_string
= build_string ("drag-mouse-1: resize");
28334 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
28335 || part
== ON_SCROLL_BAR
)
28336 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
28338 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
28341 /* Are we in a window whose display is up to date?
28342 And verify the buffer's text has not changed. */
28343 b
= XBUFFER (w
->contents
);
28344 if (part
== ON_TEXT
&& w
->window_end_valid
&& !window_outdated (w
))
28346 int hpos
, vpos
, dx
, dy
, area
= LAST_AREA
;
28348 struct glyph
*glyph
;
28349 Lisp_Object object
;
28350 Lisp_Object mouse_face
= Qnil
, position
;
28351 Lisp_Object
*overlay_vec
= NULL
;
28352 ptrdiff_t i
, noverlays
;
28353 struct buffer
*obuf
;
28354 ptrdiff_t obegv
, ozv
;
28357 /* Find the glyph under X/Y. */
28358 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
28360 #ifdef HAVE_WINDOW_SYSTEM
28361 /* Look for :pointer property on image. */
28362 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
28364 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
28365 if (img
!= NULL
&& IMAGEP (img
->spec
))
28367 Lisp_Object image_map
, hotspot
;
28368 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
28370 && (hotspot
= find_hot_spot (image_map
,
28371 glyph
->slice
.img
.x
+ dx
,
28372 glyph
->slice
.img
.y
+ dy
),
28374 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
28378 /* Could check XCAR (hotspot) to see if we enter/leave
28380 If so, we could look for mouse-enter, mouse-leave
28381 properties in PLIST (and do something...). */
28382 hotspot
= XCDR (hotspot
);
28383 if (CONSP (hotspot
)
28384 && (plist
= XCAR (hotspot
), CONSP (plist
)))
28386 pointer
= Fplist_get (plist
, Qpointer
);
28387 if (NILP (pointer
))
28389 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
28390 if (!NILP (help_echo_string
))
28392 help_echo_window
= window
;
28393 help_echo_object
= glyph
->object
;
28394 help_echo_pos
= glyph
->charpos
;
28398 if (NILP (pointer
))
28399 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
28402 #endif /* HAVE_WINDOW_SYSTEM */
28404 /* Clear mouse face if X/Y not over text. */
28406 || area
!= TEXT_AREA
28407 || !MATRIX_ROW_DISPLAYS_TEXT_P (MATRIX_ROW (w
->current_matrix
, vpos
))
28408 /* Glyph's OBJECT is an integer for glyphs inserted by the
28409 display engine for its internal purposes, like truncation
28410 and continuation glyphs and blanks beyond the end of
28411 line's text on text terminals. If we are over such a
28412 glyph, we are not over any text. */
28413 || INTEGERP (glyph
->object
)
28414 /* R2L rows have a stretch glyph at their front, which
28415 stands for no text, whereas L2R rows have no glyphs at
28416 all beyond the end of text. Treat such stretch glyphs
28417 like we do with NULL glyphs in L2R rows. */
28418 || (MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
28419 && glyph
== MATRIX_ROW_GLYPH_START (w
->current_matrix
, vpos
)
28420 && glyph
->type
== STRETCH_GLYPH
28421 && glyph
->avoid_cursor_p
))
28423 if (clear_mouse_face (hlinfo
))
28424 cursor
= No_Cursor
;
28425 #ifdef HAVE_WINDOW_SYSTEM
28426 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
28428 if (area
!= TEXT_AREA
)
28429 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
28431 pointer
= Vvoid_text_area_pointer
;
28437 pos
= glyph
->charpos
;
28438 object
= glyph
->object
;
28439 if (!STRINGP (object
) && !BUFFERP (object
))
28442 /* If we get an out-of-range value, return now; avoid an error. */
28443 if (BUFFERP (object
) && pos
> BUF_Z (b
))
28446 /* Make the window's buffer temporarily current for
28447 overlays_at and compute_char_face. */
28448 obuf
= current_buffer
;
28449 current_buffer
= b
;
28455 /* Is this char mouse-active or does it have help-echo? */
28456 position
= make_number (pos
);
28458 if (BUFFERP (object
))
28460 /* Put all the overlays we want in a vector in overlay_vec. */
28461 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
28462 /* Sort overlays into increasing priority order. */
28463 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
28468 if (NILP (Vmouse_highlight
))
28470 clear_mouse_face (hlinfo
);
28471 goto check_help_echo
;
28474 same_region
= coords_in_mouse_face_p (w
, hpos
, vpos
);
28477 cursor
= No_Cursor
;
28479 /* Check mouse-face highlighting. */
28481 /* If there exists an overlay with mouse-face overlapping
28482 the one we are currently highlighting, we have to
28483 check if we enter the overlapping overlay, and then
28484 highlight only that. */
28485 || (OVERLAYP (hlinfo
->mouse_face_overlay
)
28486 && mouse_face_overlay_overlaps (hlinfo
->mouse_face_overlay
)))
28488 /* Find the highest priority overlay with a mouse-face. */
28489 Lisp_Object overlay
= Qnil
;
28490 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
28492 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
28493 if (!NILP (mouse_face
))
28494 overlay
= overlay_vec
[i
];
28497 /* If we're highlighting the same overlay as before, there's
28498 no need to do that again. */
28499 if (!NILP (overlay
) && EQ (overlay
, hlinfo
->mouse_face_overlay
))
28500 goto check_help_echo
;
28501 hlinfo
->mouse_face_overlay
= overlay
;
28503 /* Clear the display of the old active region, if any. */
28504 if (clear_mouse_face (hlinfo
))
28505 cursor
= No_Cursor
;
28507 /* If no overlay applies, get a text property. */
28508 if (NILP (overlay
))
28509 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
28511 /* Next, compute the bounds of the mouse highlighting and
28513 if (!NILP (mouse_face
) && STRINGP (object
))
28515 /* The mouse-highlighting comes from a display string
28516 with a mouse-face. */
28520 s
= Fprevious_single_property_change
28521 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
28522 e
= Fnext_single_property_change
28523 (position
, Qmouse_face
, object
, Qnil
);
28525 s
= make_number (0);
28527 e
= make_number (SCHARS (object
) - 1);
28528 mouse_face_from_string_pos (w
, hlinfo
, object
,
28529 XINT (s
), XINT (e
));
28530 hlinfo
->mouse_face_past_end
= 0;
28531 hlinfo
->mouse_face_window
= window
;
28532 hlinfo
->mouse_face_face_id
28533 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
28534 glyph
->face_id
, 1);
28535 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
28536 cursor
= No_Cursor
;
28540 /* The mouse-highlighting, if any, comes from an overlay
28541 or text property in the buffer. */
28542 Lisp_Object buffer
IF_LINT (= Qnil
);
28543 Lisp_Object disp_string
IF_LINT (= Qnil
);
28545 if (STRINGP (object
))
28547 /* If we are on a display string with no mouse-face,
28548 check if the text under it has one. */
28549 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
28550 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28551 pos
= string_buffer_position (object
, start
);
28554 mouse_face
= get_char_property_and_overlay
28555 (make_number (pos
), Qmouse_face
, w
->contents
, &overlay
);
28556 buffer
= w
->contents
;
28557 disp_string
= object
;
28563 disp_string
= Qnil
;
28566 if (!NILP (mouse_face
))
28568 Lisp_Object before
, after
;
28569 Lisp_Object before_string
, after_string
;
28570 /* To correctly find the limits of mouse highlight
28571 in a bidi-reordered buffer, we must not use the
28572 optimization of limiting the search in
28573 previous-single-property-change and
28574 next-single-property-change, because
28575 rows_from_pos_range needs the real start and end
28576 positions to DTRT in this case. That's because
28577 the first row visible in a window does not
28578 necessarily display the character whose position
28579 is the smallest. */
28581 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
28582 ? Fmarker_position (w
->start
)
28585 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
28586 ? make_number (BUF_Z (XBUFFER (buffer
)) - w
->window_end_pos
)
28589 if (NILP (overlay
))
28591 /* Handle the text property case. */
28592 before
= Fprevious_single_property_change
28593 (make_number (pos
+ 1), Qmouse_face
, buffer
, lim1
);
28594 after
= Fnext_single_property_change
28595 (make_number (pos
), Qmouse_face
, buffer
, lim2
);
28596 before_string
= after_string
= Qnil
;
28600 /* Handle the overlay case. */
28601 before
= Foverlay_start (overlay
);
28602 after
= Foverlay_end (overlay
);
28603 before_string
= Foverlay_get (overlay
, Qbefore_string
);
28604 after_string
= Foverlay_get (overlay
, Qafter_string
);
28606 if (!STRINGP (before_string
)) before_string
= Qnil
;
28607 if (!STRINGP (after_string
)) after_string
= Qnil
;
28610 mouse_face_from_buffer_pos (window
, hlinfo
, pos
,
28613 : XFASTINT (before
),
28615 ? BUF_Z (XBUFFER (buffer
))
28616 : XFASTINT (after
),
28617 before_string
, after_string
,
28619 cursor
= No_Cursor
;
28626 /* Look for a `help-echo' property. */
28627 if (NILP (help_echo_string
)) {
28628 Lisp_Object help
, overlay
;
28630 /* Check overlays first. */
28631 help
= overlay
= Qnil
;
28632 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
28634 overlay
= overlay_vec
[i
];
28635 help
= Foverlay_get (overlay
, Qhelp_echo
);
28640 help_echo_string
= help
;
28641 help_echo_window
= window
;
28642 help_echo_object
= overlay
;
28643 help_echo_pos
= pos
;
28647 Lisp_Object obj
= glyph
->object
;
28648 ptrdiff_t charpos
= glyph
->charpos
;
28650 /* Try text properties. */
28653 && charpos
< SCHARS (obj
))
28655 help
= Fget_text_property (make_number (charpos
),
28659 /* If the string itself doesn't specify a help-echo,
28660 see if the buffer text ``under'' it does. */
28661 struct glyph_row
*r
28662 = MATRIX_ROW (w
->current_matrix
, vpos
);
28663 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28664 ptrdiff_t p
= string_buffer_position (obj
, start
);
28667 help
= Fget_char_property (make_number (p
),
28668 Qhelp_echo
, w
->contents
);
28677 else if (BUFFERP (obj
)
28680 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
28685 help_echo_string
= help
;
28686 help_echo_window
= window
;
28687 help_echo_object
= obj
;
28688 help_echo_pos
= charpos
;
28693 #ifdef HAVE_WINDOW_SYSTEM
28694 /* Look for a `pointer' property. */
28695 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
28697 /* Check overlays first. */
28698 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
28699 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
28701 if (NILP (pointer
))
28703 Lisp_Object obj
= glyph
->object
;
28704 ptrdiff_t charpos
= glyph
->charpos
;
28706 /* Try text properties. */
28709 && charpos
< SCHARS (obj
))
28711 pointer
= Fget_text_property (make_number (charpos
),
28713 if (NILP (pointer
))
28715 /* If the string itself doesn't specify a pointer,
28716 see if the buffer text ``under'' it does. */
28717 struct glyph_row
*r
28718 = MATRIX_ROW (w
->current_matrix
, vpos
);
28719 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28720 ptrdiff_t p
= string_buffer_position (obj
, start
);
28722 pointer
= Fget_char_property (make_number (p
),
28723 Qpointer
, w
->contents
);
28726 else if (BUFFERP (obj
)
28729 pointer
= Fget_text_property (make_number (charpos
),
28733 #endif /* HAVE_WINDOW_SYSTEM */
28737 current_buffer
= obuf
;
28742 #ifdef HAVE_WINDOW_SYSTEM
28743 if (FRAME_WINDOW_P (f
))
28744 define_frame_cursor1 (f
, cursor
, pointer
);
28746 /* This is here to prevent a compiler error, about "label at end of
28747 compound statement". */
28754 Clear any mouse-face on window W. This function is part of the
28755 redisplay interface, and is called from try_window_id and similar
28756 functions to ensure the mouse-highlight is off. */
28759 x_clear_window_mouse_face (struct window
*w
)
28761 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
28762 Lisp_Object window
;
28765 XSETWINDOW (window
, w
);
28766 if (EQ (window
, hlinfo
->mouse_face_window
))
28767 clear_mouse_face (hlinfo
);
28773 Just discard the mouse face information for frame F, if any.
28774 This is used when the size of F is changed. */
28777 cancel_mouse_face (struct frame
*f
)
28779 Lisp_Object window
;
28780 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28782 window
= hlinfo
->mouse_face_window
;
28783 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
28785 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
28786 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
28787 hlinfo
->mouse_face_window
= Qnil
;
28793 /***********************************************************************
28795 ***********************************************************************/
28797 #ifdef HAVE_WINDOW_SYSTEM
28799 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
28800 which intersects rectangle R. R is in window-relative coordinates. */
28803 expose_area (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
,
28804 enum glyph_row_area area
)
28806 struct glyph
*first
= row
->glyphs
[area
];
28807 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
28808 struct glyph
*last
;
28809 int first_x
, start_x
, x
;
28811 if (area
== TEXT_AREA
&& row
->fill_line_p
)
28812 /* If row extends face to end of line write the whole line. */
28813 draw_glyphs (w
, 0, row
, area
,
28814 0, row
->used
[area
],
28815 DRAW_NORMAL_TEXT
, 0);
28818 /* Set START_X to the window-relative start position for drawing glyphs of
28819 AREA. The first glyph of the text area can be partially visible.
28820 The first glyphs of other areas cannot. */
28821 start_x
= window_box_left_offset (w
, area
);
28823 if (area
== TEXT_AREA
)
28826 /* Find the first glyph that must be redrawn. */
28828 && x
+ first
->pixel_width
< r
->x
)
28830 x
+= first
->pixel_width
;
28834 /* Find the last one. */
28838 && x
< r
->x
+ r
->width
)
28840 x
+= last
->pixel_width
;
28846 draw_glyphs (w
, first_x
- start_x
, row
, area
,
28847 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
28848 DRAW_NORMAL_TEXT
, 0);
28853 /* Redraw the parts of the glyph row ROW on window W intersecting
28854 rectangle R. R is in window-relative coordinates. Value is
28855 non-zero if mouse-face was overwritten. */
28858 expose_line (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
)
28860 eassert (row
->enabled_p
);
28862 if (row
->mode_line_p
|| w
->pseudo_window_p
)
28863 draw_glyphs (w
, 0, row
, TEXT_AREA
,
28864 0, row
->used
[TEXT_AREA
],
28865 DRAW_NORMAL_TEXT
, 0);
28868 if (row
->used
[LEFT_MARGIN_AREA
])
28869 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
28870 if (row
->used
[TEXT_AREA
])
28871 expose_area (w
, row
, r
, TEXT_AREA
);
28872 if (row
->used
[RIGHT_MARGIN_AREA
])
28873 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
28874 draw_row_fringe_bitmaps (w
, row
);
28877 return row
->mouse_face_p
;
28881 /* Redraw those parts of glyphs rows during expose event handling that
28882 overlap other rows. Redrawing of an exposed line writes over parts
28883 of lines overlapping that exposed line; this function fixes that.
28885 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
28886 row in W's current matrix that is exposed and overlaps other rows.
28887 LAST_OVERLAPPING_ROW is the last such row. */
28890 expose_overlaps (struct window
*w
,
28891 struct glyph_row
*first_overlapping_row
,
28892 struct glyph_row
*last_overlapping_row
,
28895 struct glyph_row
*row
;
28897 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
28898 if (row
->overlapping_p
)
28900 eassert (row
->enabled_p
&& !row
->mode_line_p
);
28903 if (row
->used
[LEFT_MARGIN_AREA
])
28904 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
28906 if (row
->used
[TEXT_AREA
])
28907 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
28909 if (row
->used
[RIGHT_MARGIN_AREA
])
28910 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
28916 /* Return non-zero if W's cursor intersects rectangle R. */
28919 phys_cursor_in_rect_p (struct window
*w
, XRectangle
*r
)
28921 XRectangle cr
, result
;
28922 struct glyph
*cursor_glyph
;
28923 struct glyph_row
*row
;
28925 if (w
->phys_cursor
.vpos
>= 0
28926 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
28927 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
28929 && row
->cursor_in_fringe_p
)
28931 /* Cursor is in the fringe. */
28932 cr
.x
= window_box_right_offset (w
,
28933 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
28934 ? RIGHT_MARGIN_AREA
28937 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
28938 cr
.height
= row
->height
;
28939 return x_intersect_rectangles (&cr
, r
, &result
);
28942 cursor_glyph
= get_phys_cursor_glyph (w
);
28945 /* r is relative to W's box, but w->phys_cursor.x is relative
28946 to left edge of W's TEXT area. Adjust it. */
28947 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
28948 cr
.y
= w
->phys_cursor
.y
;
28949 cr
.width
= cursor_glyph
->pixel_width
;
28950 cr
.height
= w
->phys_cursor_height
;
28951 /* ++KFS: W32 version used W32-specific IntersectRect here, but
28952 I assume the effect is the same -- and this is portable. */
28953 return x_intersect_rectangles (&cr
, r
, &result
);
28955 /* If we don't understand the format, pretend we're not in the hot-spot. */
28961 Draw a vertical window border to the right of window W if W doesn't
28962 have vertical scroll bars. */
28965 x_draw_vertical_border (struct window
*w
)
28967 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
28969 /* We could do better, if we knew what type of scroll-bar the adjacent
28970 windows (on either side) have... But we don't :-(
28971 However, I think this works ok. ++KFS 2003-04-25 */
28973 /* Redraw borders between horizontally adjacent windows. Don't
28974 do it for frames with vertical scroll bars because either the
28975 right scroll bar of a window, or the left scroll bar of its
28976 neighbor will suffice as a border. */
28977 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
28980 /* Note: It is necessary to redraw both the left and the right
28981 borders, for when only this single window W is being
28983 if (!WINDOW_RIGHTMOST_P (w
)
28984 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
28986 int x0
, x1
, y0
, y1
;
28988 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
28991 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
28994 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
28996 if (!WINDOW_LEFTMOST_P (w
)
28997 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
28999 int x0
, x1
, y0
, y1
;
29001 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
29004 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
29007 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
29012 /* Redraw the part of window W intersection rectangle FR. Pixel
29013 coordinates in FR are frame-relative. Call this function with
29014 input blocked. Value is non-zero if the exposure overwrites
29018 expose_window (struct window
*w
, XRectangle
*fr
)
29020 struct frame
*f
= XFRAME (w
->frame
);
29022 int mouse_face_overwritten_p
= 0;
29024 /* If window is not yet fully initialized, do nothing. This can
29025 happen when toolkit scroll bars are used and a window is split.
29026 Reconfiguring the scroll bar will generate an expose for a newly
29028 if (w
->current_matrix
== NULL
)
29031 /* When we're currently updating the window, display and current
29032 matrix usually don't agree. Arrange for a thorough display
29034 if (w
->must_be_updated_p
)
29036 SET_FRAME_GARBAGED (f
);
29040 /* Frame-relative pixel rectangle of W. */
29041 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
29042 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
29043 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
29044 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
29046 if (x_intersect_rectangles (fr
, &wr
, &r
))
29048 int yb
= window_text_bottom_y (w
);
29049 struct glyph_row
*row
;
29050 int cursor_cleared_p
, phys_cursor_on_p
;
29051 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
29053 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
29054 r
.x
, r
.y
, r
.width
, r
.height
));
29056 /* Convert to window coordinates. */
29057 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
29058 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
29060 /* Turn off the cursor. */
29061 if (!w
->pseudo_window_p
29062 && phys_cursor_in_rect_p (w
, &r
))
29064 x_clear_cursor (w
);
29065 cursor_cleared_p
= 1;
29068 cursor_cleared_p
= 0;
29070 /* If the row containing the cursor extends face to end of line,
29071 then expose_area might overwrite the cursor outside the
29072 rectangle and thus notice_overwritten_cursor might clear
29073 w->phys_cursor_on_p. We remember the original value and
29074 check later if it is changed. */
29075 phys_cursor_on_p
= w
->phys_cursor_on_p
;
29077 /* Update lines intersecting rectangle R. */
29078 first_overlapping_row
= last_overlapping_row
= NULL
;
29079 for (row
= w
->current_matrix
->rows
;
29084 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
29086 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
29087 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
29088 || (r
.y
>= y0
&& r
.y
< y1
)
29089 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
29091 /* A header line may be overlapping, but there is no need
29092 to fix overlapping areas for them. KFS 2005-02-12 */
29093 if (row
->overlapping_p
&& !row
->mode_line_p
)
29095 if (first_overlapping_row
== NULL
)
29096 first_overlapping_row
= row
;
29097 last_overlapping_row
= row
;
29101 if (expose_line (w
, row
, &r
))
29102 mouse_face_overwritten_p
= 1;
29105 else if (row
->overlapping_p
)
29107 /* We must redraw a row overlapping the exposed area. */
29109 ? y0
+ row
->phys_height
> r
.y
29110 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
29112 if (first_overlapping_row
== NULL
)
29113 first_overlapping_row
= row
;
29114 last_overlapping_row
= row
;
29122 /* Display the mode line if there is one. */
29123 if (WINDOW_WANTS_MODELINE_P (w
)
29124 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
29126 && row
->y
< r
.y
+ r
.height
)
29128 if (expose_line (w
, row
, &r
))
29129 mouse_face_overwritten_p
= 1;
29132 if (!w
->pseudo_window_p
)
29134 /* Fix the display of overlapping rows. */
29135 if (first_overlapping_row
)
29136 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
29139 /* Draw border between windows. */
29140 x_draw_vertical_border (w
);
29142 /* Turn the cursor on again. */
29143 if (cursor_cleared_p
29144 || (phys_cursor_on_p
&& !w
->phys_cursor_on_p
))
29145 update_window_cursor (w
, 1);
29149 return mouse_face_overwritten_p
;
29154 /* Redraw (parts) of all windows in the window tree rooted at W that
29155 intersect R. R contains frame pixel coordinates. Value is
29156 non-zero if the exposure overwrites mouse-face. */
29159 expose_window_tree (struct window
*w
, XRectangle
*r
)
29161 struct frame
*f
= XFRAME (w
->frame
);
29162 int mouse_face_overwritten_p
= 0;
29164 while (w
&& !FRAME_GARBAGED_P (f
))
29166 if (WINDOWP (w
->contents
))
29167 mouse_face_overwritten_p
29168 |= expose_window_tree (XWINDOW (w
->contents
), r
);
29170 mouse_face_overwritten_p
|= expose_window (w
, r
);
29172 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
29175 return mouse_face_overwritten_p
;
29180 Redisplay an exposed area of frame F. X and Y are the upper-left
29181 corner of the exposed rectangle. W and H are width and height of
29182 the exposed area. All are pixel values. W or H zero means redraw
29183 the entire frame. */
29186 expose_frame (struct frame
*f
, int x
, int y
, int w
, int h
)
29189 int mouse_face_overwritten_p
= 0;
29191 TRACE ((stderr
, "expose_frame "));
29193 /* No need to redraw if frame will be redrawn soon. */
29194 if (FRAME_GARBAGED_P (f
))
29196 TRACE ((stderr
, " garbaged\n"));
29200 /* If basic faces haven't been realized yet, there is no point in
29201 trying to redraw anything. This can happen when we get an expose
29202 event while Emacs is starting, e.g. by moving another window. */
29203 if (FRAME_FACE_CACHE (f
) == NULL
29204 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
29206 TRACE ((stderr
, " no faces\n"));
29210 if (w
== 0 || h
== 0)
29213 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
29214 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
29224 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
29225 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
29227 if (WINDOWP (f
->tool_bar_window
))
29228 mouse_face_overwritten_p
29229 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
29231 #ifdef HAVE_X_WINDOWS
29233 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
29234 if (WINDOWP (f
->menu_bar_window
))
29235 mouse_face_overwritten_p
29236 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
29237 #endif /* not USE_X_TOOLKIT and not USE_GTK */
29241 /* Some window managers support a focus-follows-mouse style with
29242 delayed raising of frames. Imagine a partially obscured frame,
29243 and moving the mouse into partially obscured mouse-face on that
29244 frame. The visible part of the mouse-face will be highlighted,
29245 then the WM raises the obscured frame. With at least one WM, KDE
29246 2.1, Emacs is not getting any event for the raising of the frame
29247 (even tried with SubstructureRedirectMask), only Expose events.
29248 These expose events will draw text normally, i.e. not
29249 highlighted. Which means we must redo the highlight here.
29250 Subsume it under ``we love X''. --gerd 2001-08-15 */
29251 /* Included in Windows version because Windows most likely does not
29252 do the right thing if any third party tool offers
29253 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
29254 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
29256 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
29257 if (f
== hlinfo
->mouse_face_mouse_frame
)
29259 int mouse_x
= hlinfo
->mouse_face_mouse_x
;
29260 int mouse_y
= hlinfo
->mouse_face_mouse_y
;
29261 clear_mouse_face (hlinfo
);
29262 note_mouse_highlight (f
, mouse_x
, mouse_y
);
29269 Determine the intersection of two rectangles R1 and R2. Return
29270 the intersection in *RESULT. Value is non-zero if RESULT is not
29274 x_intersect_rectangles (XRectangle
*r1
, XRectangle
*r2
, XRectangle
*result
)
29276 XRectangle
*left
, *right
;
29277 XRectangle
*upper
, *lower
;
29278 int intersection_p
= 0;
29280 /* Rearrange so that R1 is the left-most rectangle. */
29282 left
= r1
, right
= r2
;
29284 left
= r2
, right
= r1
;
29286 /* X0 of the intersection is right.x0, if this is inside R1,
29287 otherwise there is no intersection. */
29288 if (right
->x
<= left
->x
+ left
->width
)
29290 result
->x
= right
->x
;
29292 /* The right end of the intersection is the minimum of
29293 the right ends of left and right. */
29294 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
29297 /* Same game for Y. */
29299 upper
= r1
, lower
= r2
;
29301 upper
= r2
, lower
= r1
;
29303 /* The upper end of the intersection is lower.y0, if this is inside
29304 of upper. Otherwise, there is no intersection. */
29305 if (lower
->y
<= upper
->y
+ upper
->height
)
29307 result
->y
= lower
->y
;
29309 /* The lower end of the intersection is the minimum of the lower
29310 ends of upper and lower. */
29311 result
->height
= (min (lower
->y
+ lower
->height
,
29312 upper
->y
+ upper
->height
)
29314 intersection_p
= 1;
29318 return intersection_p
;
29321 #endif /* HAVE_WINDOW_SYSTEM */
29324 /***********************************************************************
29326 ***********************************************************************/
29329 syms_of_xdisp (void)
29331 Vwith_echo_area_save_vector
= Qnil
;
29332 staticpro (&Vwith_echo_area_save_vector
);
29334 Vmessage_stack
= Qnil
;
29335 staticpro (&Vmessage_stack
);
29337 DEFSYM (Qinhibit_redisplay
, "inhibit-redisplay");
29338 DEFSYM (Qredisplay_internal
, "redisplay_internal (C function)");
29340 message_dolog_marker1
= Fmake_marker ();
29341 staticpro (&message_dolog_marker1
);
29342 message_dolog_marker2
= Fmake_marker ();
29343 staticpro (&message_dolog_marker2
);
29344 message_dolog_marker3
= Fmake_marker ();
29345 staticpro (&message_dolog_marker3
);
29348 defsubr (&Sdump_frame_glyph_matrix
);
29349 defsubr (&Sdump_glyph_matrix
);
29350 defsubr (&Sdump_glyph_row
);
29351 defsubr (&Sdump_tool_bar_row
);
29352 defsubr (&Strace_redisplay
);
29353 defsubr (&Strace_to_stderr
);
29355 #ifdef HAVE_WINDOW_SYSTEM
29356 defsubr (&Stool_bar_lines_needed
);
29357 defsubr (&Slookup_image_map
);
29359 defsubr (&Sline_pixel_height
);
29360 defsubr (&Sformat_mode_line
);
29361 defsubr (&Sinvisible_p
);
29362 defsubr (&Scurrent_bidi_paragraph_direction
);
29363 defsubr (&Smove_point_visually
);
29365 DEFSYM (Qmenu_bar_update_hook
, "menu-bar-update-hook");
29366 DEFSYM (Qoverriding_terminal_local_map
, "overriding-terminal-local-map");
29367 DEFSYM (Qoverriding_local_map
, "overriding-local-map");
29368 DEFSYM (Qwindow_scroll_functions
, "window-scroll-functions");
29369 DEFSYM (Qwindow_text_change_functions
, "window-text-change-functions");
29370 DEFSYM (Qredisplay_end_trigger_functions
, "redisplay-end-trigger-functions");
29371 DEFSYM (Qinhibit_point_motion_hooks
, "inhibit-point-motion-hooks");
29372 DEFSYM (Qeval
, "eval");
29373 DEFSYM (QCdata
, ":data");
29374 DEFSYM (Qdisplay
, "display");
29375 DEFSYM (Qspace_width
, "space-width");
29376 DEFSYM (Qraise
, "raise");
29377 DEFSYM (Qslice
, "slice");
29378 DEFSYM (Qspace
, "space");
29379 DEFSYM (Qmargin
, "margin");
29380 DEFSYM (Qpointer
, "pointer");
29381 DEFSYM (Qleft_margin
, "left-margin");
29382 DEFSYM (Qright_margin
, "right-margin");
29383 DEFSYM (Qcenter
, "center");
29384 DEFSYM (Qline_height
, "line-height");
29385 DEFSYM (QCalign_to
, ":align-to");
29386 DEFSYM (QCrelative_width
, ":relative-width");
29387 DEFSYM (QCrelative_height
, ":relative-height");
29388 DEFSYM (QCeval
, ":eval");
29389 DEFSYM (QCpropertize
, ":propertize");
29390 DEFSYM (QCfile
, ":file");
29391 DEFSYM (Qfontified
, "fontified");
29392 DEFSYM (Qfontification_functions
, "fontification-functions");
29393 DEFSYM (Qtrailing_whitespace
, "trailing-whitespace");
29394 DEFSYM (Qescape_glyph
, "escape-glyph");
29395 DEFSYM (Qnobreak_space
, "nobreak-space");
29396 DEFSYM (Qimage
, "image");
29397 DEFSYM (Qtext
, "text");
29398 DEFSYM (Qboth
, "both");
29399 DEFSYM (Qboth_horiz
, "both-horiz");
29400 DEFSYM (Qtext_image_horiz
, "text-image-horiz");
29401 DEFSYM (QCmap
, ":map");
29402 DEFSYM (QCpointer
, ":pointer");
29403 DEFSYM (Qrect
, "rect");
29404 DEFSYM (Qcircle
, "circle");
29405 DEFSYM (Qpoly
, "poly");
29406 DEFSYM (Qmessage_truncate_lines
, "message-truncate-lines");
29407 DEFSYM (Qgrow_only
, "grow-only");
29408 DEFSYM (Qinhibit_menubar_update
, "inhibit-menubar-update");
29409 DEFSYM (Qinhibit_eval_during_redisplay
, "inhibit-eval-during-redisplay");
29410 DEFSYM (Qposition
, "position");
29411 DEFSYM (Qbuffer_position
, "buffer-position");
29412 DEFSYM (Qobject
, "object");
29413 DEFSYM (Qbar
, "bar");
29414 DEFSYM (Qhbar
, "hbar");
29415 DEFSYM (Qbox
, "box");
29416 DEFSYM (Qhollow
, "hollow");
29417 DEFSYM (Qhand
, "hand");
29418 DEFSYM (Qarrow
, "arrow");
29419 DEFSYM (Qinhibit_free_realized_faces
, "inhibit-free-realized-faces");
29421 list_of_error
= list1 (list2 (intern_c_string ("error"),
29422 intern_c_string ("void-variable")));
29423 staticpro (&list_of_error
);
29425 DEFSYM (Qlast_arrow_position
, "last-arrow-position");
29426 DEFSYM (Qlast_arrow_string
, "last-arrow-string");
29427 DEFSYM (Qoverlay_arrow_string
, "overlay-arrow-string");
29428 DEFSYM (Qoverlay_arrow_bitmap
, "overlay-arrow-bitmap");
29430 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
29431 staticpro (&echo_buffer
[0]);
29432 staticpro (&echo_buffer
[1]);
29434 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
29435 staticpro (&echo_area_buffer
[0]);
29436 staticpro (&echo_area_buffer
[1]);
29438 Vmessages_buffer_name
= build_pure_c_string ("*Messages*");
29439 staticpro (&Vmessages_buffer_name
);
29441 mode_line_proptrans_alist
= Qnil
;
29442 staticpro (&mode_line_proptrans_alist
);
29443 mode_line_string_list
= Qnil
;
29444 staticpro (&mode_line_string_list
);
29445 mode_line_string_face
= Qnil
;
29446 staticpro (&mode_line_string_face
);
29447 mode_line_string_face_prop
= Qnil
;
29448 staticpro (&mode_line_string_face_prop
);
29449 Vmode_line_unwind_vector
= Qnil
;
29450 staticpro (&Vmode_line_unwind_vector
);
29452 DEFSYM (Qmode_line_default_help_echo
, "mode-line-default-help-echo");
29454 help_echo_string
= Qnil
;
29455 staticpro (&help_echo_string
);
29456 help_echo_object
= Qnil
;
29457 staticpro (&help_echo_object
);
29458 help_echo_window
= Qnil
;
29459 staticpro (&help_echo_window
);
29460 previous_help_echo_string
= Qnil
;
29461 staticpro (&previous_help_echo_string
);
29462 help_echo_pos
= -1;
29464 DEFSYM (Qright_to_left
, "right-to-left");
29465 DEFSYM (Qleft_to_right
, "left-to-right");
29467 #ifdef HAVE_WINDOW_SYSTEM
29468 DEFVAR_BOOL ("x-stretch-cursor", x_stretch_cursor_p
,
29469 doc
: /* Non-nil means draw block cursor as wide as the glyph under it.
29470 For example, if a block cursor is over a tab, it will be drawn as
29471 wide as that tab on the display. */);
29472 x_stretch_cursor_p
= 0;
29475 DEFVAR_LISP ("show-trailing-whitespace", Vshow_trailing_whitespace
,
29476 doc
: /* Non-nil means highlight trailing whitespace.
29477 The face used for trailing whitespace is `trailing-whitespace'. */);
29478 Vshow_trailing_whitespace
= Qnil
;
29480 DEFVAR_LISP ("nobreak-char-display", Vnobreak_char_display
,
29481 doc
: /* Control highlighting of non-ASCII space and hyphen chars.
29482 If the value is t, Emacs highlights non-ASCII chars which have the
29483 same appearance as an ASCII space or hyphen, using the `nobreak-space'
29484 or `escape-glyph' face respectively.
29486 U+00A0 (no-break space), U+00AD (soft hyphen), U+2010 (hyphen), and
29487 U+2011 (non-breaking hyphen) are affected.
29489 Any other non-nil value means to display these characters as a escape
29490 glyph followed by an ordinary space or hyphen.
29492 A value of nil means no special handling of these characters. */);
29493 Vnobreak_char_display
= Qt
;
29495 DEFVAR_LISP ("void-text-area-pointer", Vvoid_text_area_pointer
,
29496 doc
: /* The pointer shape to show in void text areas.
29497 A value of nil means to show the text pointer. Other options are `arrow',
29498 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
29499 Vvoid_text_area_pointer
= Qarrow
;
29501 DEFVAR_LISP ("inhibit-redisplay", Vinhibit_redisplay
,
29502 doc
: /* Non-nil means don't actually do any redisplay.
29503 This is used for internal purposes. */);
29504 Vinhibit_redisplay
= Qnil
;
29506 DEFVAR_LISP ("global-mode-string", Vglobal_mode_string
,
29507 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
29508 Vglobal_mode_string
= Qnil
;
29510 DEFVAR_LISP ("overlay-arrow-position", Voverlay_arrow_position
,
29511 doc
: /* Marker for where to display an arrow on top of the buffer text.
29512 This must be the beginning of a line in order to work.
29513 See also `overlay-arrow-string'. */);
29514 Voverlay_arrow_position
= Qnil
;
29516 DEFVAR_LISP ("overlay-arrow-string", Voverlay_arrow_string
,
29517 doc
: /* String to display as an arrow in non-window frames.
29518 See also `overlay-arrow-position'. */);
29519 Voverlay_arrow_string
= build_pure_c_string ("=>");
29521 DEFVAR_LISP ("overlay-arrow-variable-list", Voverlay_arrow_variable_list
,
29522 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
29523 The symbols on this list are examined during redisplay to determine
29524 where to display overlay arrows. */);
29525 Voverlay_arrow_variable_list
29526 = list1 (intern_c_string ("overlay-arrow-position"));
29528 DEFVAR_INT ("scroll-step", emacs_scroll_step
,
29529 doc
: /* The number of lines to try scrolling a window by when point moves out.
29530 If that fails to bring point back on frame, point is centered instead.
29531 If this is zero, point is always centered after it moves off frame.
29532 If you want scrolling to always be a line at a time, you should set
29533 `scroll-conservatively' to a large value rather than set this to 1. */);
29535 DEFVAR_INT ("scroll-conservatively", scroll_conservatively
,
29536 doc
: /* Scroll up to this many lines, to bring point back on screen.
29537 If point moves off-screen, redisplay will scroll by up to
29538 `scroll-conservatively' lines in order to bring point just barely
29539 onto the screen again. If that cannot be done, then redisplay
29540 recenters point as usual.
29542 If the value is greater than 100, redisplay will never recenter point,
29543 but will always scroll just enough text to bring point into view, even
29544 if you move far away.
29546 A value of zero means always recenter point if it moves off screen. */);
29547 scroll_conservatively
= 0;
29549 DEFVAR_INT ("scroll-margin", scroll_margin
,
29550 doc
: /* Number of lines of margin at the top and bottom of a window.
29551 Recenter the window whenever point gets within this many lines
29552 of the top or bottom of the window. */);
29555 DEFVAR_LISP ("display-pixels-per-inch", Vdisplay_pixels_per_inch
,
29556 doc
: /* Pixels per inch value for non-window system displays.
29557 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
29558 Vdisplay_pixels_per_inch
= make_float (72.0);
29561 DEFVAR_INT ("debug-end-pos", debug_end_pos
, doc
: /* Don't ask. */);
29564 DEFVAR_LISP ("truncate-partial-width-windows",
29565 Vtruncate_partial_width_windows
,
29566 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
29567 For an integer value, truncate lines in each window narrower than the
29568 full frame width, provided the window width is less than that integer;
29569 otherwise, respect the value of `truncate-lines'.
29571 For any other non-nil value, truncate lines in all windows that do
29572 not span the full frame width.
29574 A value of nil means to respect the value of `truncate-lines'.
29576 If `word-wrap' is enabled, you might want to reduce this. */);
29577 Vtruncate_partial_width_windows
= make_number (50);
29579 DEFVAR_LISP ("line-number-display-limit", Vline_number_display_limit
,
29580 doc
: /* Maximum buffer size for which line number should be displayed.
29581 If the buffer is bigger than this, the line number does not appear
29582 in the mode line. A value of nil means no limit. */);
29583 Vline_number_display_limit
= Qnil
;
29585 DEFVAR_INT ("line-number-display-limit-width",
29586 line_number_display_limit_width
,
29587 doc
: /* Maximum line width (in characters) for line number display.
29588 If the average length of the lines near point is bigger than this, then the
29589 line number may be omitted from the mode line. */);
29590 line_number_display_limit_width
= 200;
29592 DEFVAR_BOOL ("highlight-nonselected-windows", highlight_nonselected_windows
,
29593 doc
: /* Non-nil means highlight region even in nonselected windows. */);
29594 highlight_nonselected_windows
= 0;
29596 DEFVAR_BOOL ("multiple-frames", multiple_frames
,
29597 doc
: /* Non-nil if more than one frame is visible on this display.
29598 Minibuffer-only frames don't count, but iconified frames do.
29599 This variable is not guaranteed to be accurate except while processing
29600 `frame-title-format' and `icon-title-format'. */);
29602 DEFVAR_LISP ("frame-title-format", Vframe_title_format
,
29603 doc
: /* Template for displaying the title bar of visible frames.
29604 \(Assuming the window manager supports this feature.)
29606 This variable has the same structure as `mode-line-format', except that
29607 the %c and %l constructs are ignored. It is used only on frames for
29608 which no explicit name has been set \(see `modify-frame-parameters'). */);
29610 DEFVAR_LISP ("icon-title-format", Vicon_title_format
,
29611 doc
: /* Template for displaying the title bar of an iconified frame.
29612 \(Assuming the window manager supports this feature.)
29613 This variable has the same structure as `mode-line-format' (which see),
29614 and is used only on frames for which no explicit name has been set
29615 \(see `modify-frame-parameters'). */);
29617 = Vframe_title_format
29618 = listn (CONSTYPE_PURE
, 3,
29619 intern_c_string ("multiple-frames"),
29620 build_pure_c_string ("%b"),
29621 listn (CONSTYPE_PURE
, 4,
29622 empty_unibyte_string
,
29623 intern_c_string ("invocation-name"),
29624 build_pure_c_string ("@"),
29625 intern_c_string ("system-name")));
29627 DEFVAR_LISP ("message-log-max", Vmessage_log_max
,
29628 doc
: /* Maximum number of lines to keep in the message log buffer.
29629 If nil, disable message logging. If t, log messages but don't truncate
29630 the buffer when it becomes large. */);
29631 Vmessage_log_max
= make_number (1000);
29633 DEFVAR_LISP ("window-size-change-functions", Vwindow_size_change_functions
,
29634 doc
: /* Functions called before redisplay, if window sizes have changed.
29635 The value should be a list of functions that take one argument.
29636 Just before redisplay, for each frame, if any of its windows have changed
29637 size since the last redisplay, or have been split or deleted,
29638 all the functions in the list are called, with the frame as argument. */);
29639 Vwindow_size_change_functions
= Qnil
;
29641 DEFVAR_LISP ("window-scroll-functions", Vwindow_scroll_functions
,
29642 doc
: /* List of functions to call before redisplaying a window with scrolling.
29643 Each function is called with two arguments, the window and its new
29644 display-start position. Note that these functions are also called by
29645 `set-window-buffer'. Also note that the value of `window-end' is not
29646 valid when these functions are called.
29648 Warning: Do not use this feature to alter the way the window
29649 is scrolled. It is not designed for that, and such use probably won't
29651 Vwindow_scroll_functions
= Qnil
;
29653 DEFVAR_LISP ("window-text-change-functions",
29654 Vwindow_text_change_functions
,
29655 doc
: /* Functions to call in redisplay when text in the window might change. */);
29656 Vwindow_text_change_functions
= Qnil
;
29658 DEFVAR_LISP ("redisplay-end-trigger-functions", Vredisplay_end_trigger_functions
,
29659 doc
: /* Functions called when redisplay of a window reaches the end trigger.
29660 Each function is called with two arguments, the window and the end trigger value.
29661 See `set-window-redisplay-end-trigger'. */);
29662 Vredisplay_end_trigger_functions
= Qnil
;
29664 DEFVAR_LISP ("mouse-autoselect-window", Vmouse_autoselect_window
,
29665 doc
: /* Non-nil means autoselect window with mouse pointer.
29666 If nil, do not autoselect windows.
29667 A positive number means delay autoselection by that many seconds: a
29668 window is autoselected only after the mouse has remained in that
29669 window for the duration of the delay.
29670 A negative number has a similar effect, but causes windows to be
29671 autoselected only after the mouse has stopped moving. \(Because of
29672 the way Emacs compares mouse events, you will occasionally wait twice
29673 that time before the window gets selected.\)
29674 Any other value means to autoselect window instantaneously when the
29675 mouse pointer enters it.
29677 Autoselection selects the minibuffer only if it is active, and never
29678 unselects the minibuffer if it is active.
29680 When customizing this variable make sure that the actual value of
29681 `focus-follows-mouse' matches the behavior of your window manager. */);
29682 Vmouse_autoselect_window
= Qnil
;
29684 DEFVAR_LISP ("auto-resize-tool-bars", Vauto_resize_tool_bars
,
29685 doc
: /* Non-nil means automatically resize tool-bars.
29686 This dynamically changes the tool-bar's height to the minimum height
29687 that is needed to make all tool-bar items visible.
29688 If value is `grow-only', the tool-bar's height is only increased
29689 automatically; to decrease the tool-bar height, use \\[recenter]. */);
29690 Vauto_resize_tool_bars
= Qt
;
29692 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", auto_raise_tool_bar_buttons_p
,
29693 doc
: /* Non-nil means raise tool-bar buttons when the mouse moves over them. */);
29694 auto_raise_tool_bar_buttons_p
= 1;
29696 DEFVAR_BOOL ("make-cursor-line-fully-visible", make_cursor_line_fully_visible_p
,
29697 doc
: /* Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
29698 make_cursor_line_fully_visible_p
= 1;
29700 DEFVAR_LISP ("tool-bar-border", Vtool_bar_border
,
29701 doc
: /* Border below tool-bar in pixels.
29702 If an integer, use it as the height of the border.
29703 If it is one of `internal-border-width' or `border-width', use the
29704 value of the corresponding frame parameter.
29705 Otherwise, no border is added below the tool-bar. */);
29706 Vtool_bar_border
= Qinternal_border_width
;
29708 DEFVAR_LISP ("tool-bar-button-margin", Vtool_bar_button_margin
,
29709 doc
: /* Margin around tool-bar buttons in pixels.
29710 If an integer, use that for both horizontal and vertical margins.
29711 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
29712 HORZ specifying the horizontal margin, and VERT specifying the
29713 vertical margin. */);
29714 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
29716 DEFVAR_INT ("tool-bar-button-relief", tool_bar_button_relief
,
29717 doc
: /* Relief thickness of tool-bar buttons. */);
29718 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
29720 DEFVAR_LISP ("tool-bar-style", Vtool_bar_style
,
29721 doc
: /* Tool bar style to use.
29723 image - show images only
29724 text - show text only
29725 both - show both, text below image
29726 both-horiz - show text to the right of the image
29727 text-image-horiz - show text to the left of the image
29728 any other - use system default or image if no system default.
29730 This variable only affects the GTK+ toolkit version of Emacs. */);
29731 Vtool_bar_style
= Qnil
;
29733 DEFVAR_INT ("tool-bar-max-label-size", tool_bar_max_label_size
,
29734 doc
: /* Maximum number of characters a label can have to be shown.
29735 The tool bar style must also show labels for this to have any effect, see
29736 `tool-bar-style'. */);
29737 tool_bar_max_label_size
= DEFAULT_TOOL_BAR_LABEL_SIZE
;
29739 DEFVAR_LISP ("fontification-functions", Vfontification_functions
,
29740 doc
: /* List of functions to call to fontify regions of text.
29741 Each function is called with one argument POS. Functions must
29742 fontify a region starting at POS in the current buffer, and give
29743 fontified regions the property `fontified'. */);
29744 Vfontification_functions
= Qnil
;
29745 Fmake_variable_buffer_local (Qfontification_functions
);
29747 DEFVAR_BOOL ("unibyte-display-via-language-environment",
29748 unibyte_display_via_language_environment
,
29749 doc
: /* Non-nil means display unibyte text according to language environment.
29750 Specifically, this means that raw bytes in the range 160-255 decimal
29751 are displayed by converting them to the equivalent multibyte characters
29752 according to the current language environment. As a result, they are
29753 displayed according to the current fontset.
29755 Note that this variable affects only how these bytes are displayed,
29756 but does not change the fact they are interpreted as raw bytes. */);
29757 unibyte_display_via_language_environment
= 0;
29759 DEFVAR_LISP ("max-mini-window-height", Vmax_mini_window_height
,
29760 doc
: /* Maximum height for resizing mini-windows (the minibuffer and the echo area).
29761 If a float, it specifies a fraction of the mini-window frame's height.
29762 If an integer, it specifies a number of lines. */);
29763 Vmax_mini_window_height
= make_float (0.25);
29765 DEFVAR_LISP ("resize-mini-windows", Vresize_mini_windows
,
29766 doc
: /* How to resize mini-windows (the minibuffer and the echo area).
29767 A value of nil means don't automatically resize mini-windows.
29768 A value of t means resize them to fit the text displayed in them.
29769 A value of `grow-only', the default, means let mini-windows grow only;
29770 they return to their normal size when the minibuffer is closed, or the
29771 echo area becomes empty. */);
29772 Vresize_mini_windows
= Qgrow_only
;
29774 DEFVAR_LISP ("blink-cursor-alist", Vblink_cursor_alist
,
29775 doc
: /* Alist specifying how to blink the cursor off.
29776 Each element has the form (ON-STATE . OFF-STATE). Whenever the
29777 `cursor-type' frame-parameter or variable equals ON-STATE,
29778 comparing using `equal', Emacs uses OFF-STATE to specify
29779 how to blink it off. ON-STATE and OFF-STATE are values for
29780 the `cursor-type' frame parameter.
29782 If a frame's ON-STATE has no entry in this list,
29783 the frame's other specifications determine how to blink the cursor off. */);
29784 Vblink_cursor_alist
= Qnil
;
29786 DEFVAR_BOOL ("auto-hscroll-mode", automatic_hscrolling_p
,
29787 doc
: /* Allow or disallow automatic horizontal scrolling of windows.
29788 If non-nil, windows are automatically scrolled horizontally to make
29789 point visible. */);
29790 automatic_hscrolling_p
= 1;
29791 DEFSYM (Qauto_hscroll_mode
, "auto-hscroll-mode");
29793 DEFVAR_INT ("hscroll-margin", hscroll_margin
,
29794 doc
: /* How many columns away from the window edge point is allowed to get
29795 before automatic hscrolling will horizontally scroll the window. */);
29796 hscroll_margin
= 5;
29798 DEFVAR_LISP ("hscroll-step", Vhscroll_step
,
29799 doc
: /* How many columns to scroll the window when point gets too close to the edge.
29800 When point is less than `hscroll-margin' columns from the window
29801 edge, automatic hscrolling will scroll the window by the amount of columns
29802 determined by this variable. If its value is a positive integer, scroll that
29803 many columns. If it's a positive floating-point number, it specifies the
29804 fraction of the window's width to scroll. If it's nil or zero, point will be
29805 centered horizontally after the scroll. Any other value, including negative
29806 numbers, are treated as if the value were zero.
29808 Automatic hscrolling always moves point outside the scroll margin, so if
29809 point was more than scroll step columns inside the margin, the window will
29810 scroll more than the value given by the scroll step.
29812 Note that the lower bound for automatic hscrolling specified by `scroll-left'
29813 and `scroll-right' overrides this variable's effect. */);
29814 Vhscroll_step
= make_number (0);
29816 DEFVAR_BOOL ("message-truncate-lines", message_truncate_lines
,
29817 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
29818 Bind this around calls to `message' to let it take effect. */);
29819 message_truncate_lines
= 0;
29821 DEFVAR_LISP ("menu-bar-update-hook", Vmenu_bar_update_hook
,
29822 doc
: /* Normal hook run to update the menu bar definitions.
29823 Redisplay runs this hook before it redisplays the menu bar.
29824 This is used to update submenus such as Buffers,
29825 whose contents depend on various data. */);
29826 Vmenu_bar_update_hook
= Qnil
;
29828 DEFVAR_LISP ("menu-updating-frame", Vmenu_updating_frame
,
29829 doc
: /* Frame for which we are updating a menu.
29830 The enable predicate for a menu binding should check this variable. */);
29831 Vmenu_updating_frame
= Qnil
;
29833 DEFVAR_BOOL ("inhibit-menubar-update", inhibit_menubar_update
,
29834 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
29835 inhibit_menubar_update
= 0;
29837 DEFVAR_LISP ("wrap-prefix", Vwrap_prefix
,
29838 doc
: /* Prefix prepended to all continuation lines at display time.
29839 The value may be a string, an image, or a stretch-glyph; it is
29840 interpreted in the same way as the value of a `display' text property.
29842 This variable is overridden by any `wrap-prefix' text or overlay
29845 To add a prefix to non-continuation lines, use `line-prefix'. */);
29846 Vwrap_prefix
= Qnil
;
29847 DEFSYM (Qwrap_prefix
, "wrap-prefix");
29848 Fmake_variable_buffer_local (Qwrap_prefix
);
29850 DEFVAR_LISP ("line-prefix", Vline_prefix
,
29851 doc
: /* Prefix prepended to all non-continuation lines at display time.
29852 The value may be a string, an image, or a stretch-glyph; it is
29853 interpreted in the same way as the value of a `display' text property.
29855 This variable is overridden by any `line-prefix' text or overlay
29858 To add a prefix to continuation lines, use `wrap-prefix'. */);
29859 Vline_prefix
= Qnil
;
29860 DEFSYM (Qline_prefix
, "line-prefix");
29861 Fmake_variable_buffer_local (Qline_prefix
);
29863 DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay
,
29864 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
29865 inhibit_eval_during_redisplay
= 0;
29867 DEFVAR_BOOL ("inhibit-free-realized-faces", inhibit_free_realized_faces
,
29868 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
29869 inhibit_free_realized_faces
= 0;
29872 DEFVAR_BOOL ("inhibit-try-window-id", inhibit_try_window_id
,
29873 doc
: /* Inhibit try_window_id display optimization. */);
29874 inhibit_try_window_id
= 0;
29876 DEFVAR_BOOL ("inhibit-try-window-reusing", inhibit_try_window_reusing
,
29877 doc
: /* Inhibit try_window_reusing display optimization. */);
29878 inhibit_try_window_reusing
= 0;
29880 DEFVAR_BOOL ("inhibit-try-cursor-movement", inhibit_try_cursor_movement
,
29881 doc
: /* Inhibit try_cursor_movement display optimization. */);
29882 inhibit_try_cursor_movement
= 0;
29883 #endif /* GLYPH_DEBUG */
29885 DEFVAR_INT ("overline-margin", overline_margin
,
29886 doc
: /* Space between overline and text, in pixels.
29887 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
29888 margin to the character height. */);
29889 overline_margin
= 2;
29891 DEFVAR_INT ("underline-minimum-offset",
29892 underline_minimum_offset
,
29893 doc
: /* Minimum distance between baseline and underline.
29894 This can improve legibility of underlined text at small font sizes,
29895 particularly when using variable `x-use-underline-position-properties'
29896 with fonts that specify an UNDERLINE_POSITION relatively close to the
29897 baseline. The default value is 1. */);
29898 underline_minimum_offset
= 1;
29900 DEFVAR_BOOL ("display-hourglass", display_hourglass_p
,
29901 doc
: /* Non-nil means show an hourglass pointer, when Emacs is busy.
29902 This feature only works when on a window system that can change
29903 cursor shapes. */);
29904 display_hourglass_p
= 1;
29906 DEFVAR_LISP ("hourglass-delay", Vhourglass_delay
,
29907 doc
: /* Seconds to wait before displaying an hourglass pointer when Emacs is busy. */);
29908 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
29910 hourglass_atimer
= NULL
;
29911 hourglass_shown_p
= 0;
29913 DEFSYM (Qglyphless_char
, "glyphless-char");
29914 DEFSYM (Qhex_code
, "hex-code");
29915 DEFSYM (Qempty_box
, "empty-box");
29916 DEFSYM (Qthin_space
, "thin-space");
29917 DEFSYM (Qzero_width
, "zero-width");
29919 DEFSYM (Qglyphless_char_display
, "glyphless-char-display");
29920 /* Intern this now in case it isn't already done.
29921 Setting this variable twice is harmless.
29922 But don't staticpro it here--that is done in alloc.c. */
29923 Qchar_table_extra_slots
= intern_c_string ("char-table-extra-slots");
29924 Fput (Qglyphless_char_display
, Qchar_table_extra_slots
, make_number (1));
29926 DEFVAR_LISP ("glyphless-char-display", Vglyphless_char_display
,
29927 doc
: /* Char-table defining glyphless characters.
29928 Each element, if non-nil, should be one of the following:
29929 an ASCII acronym string: display this string in a box
29930 `hex-code': display the hexadecimal code of a character in a box
29931 `empty-box': display as an empty box
29932 `thin-space': display as 1-pixel width space
29933 `zero-width': don't display
29934 An element may also be a cons cell (GRAPHICAL . TEXT), which specifies the
29935 display method for graphical terminals and text terminals respectively.
29936 GRAPHICAL and TEXT should each have one of the values listed above.
29938 The char-table has one extra slot to control the display of a character for
29939 which no font is found. This slot only takes effect on graphical terminals.
29940 Its value should be an ASCII acronym string, `hex-code', `empty-box', or
29941 `thin-space'. The default is `empty-box'. */);
29942 Vglyphless_char_display
= Fmake_char_table (Qglyphless_char_display
, Qnil
);
29943 Fset_char_table_extra_slot (Vglyphless_char_display
, make_number (0),
29946 DEFVAR_LISP ("debug-on-message", Vdebug_on_message
,
29947 doc
: /* If non-nil, debug if a message matching this regexp is displayed. */);
29948 Vdebug_on_message
= Qnil
;
29952 /* Initialize this module when Emacs starts. */
29957 current_header_line_height
= current_mode_line_height
= -1;
29959 CHARPOS (this_line_start_pos
) = 0;
29961 if (!noninteractive
)
29963 struct window
*m
= XWINDOW (minibuf_window
);
29964 Lisp_Object frame
= m
->frame
;
29965 struct frame
*f
= XFRAME (frame
);
29966 Lisp_Object root
= FRAME_ROOT_WINDOW (f
);
29967 struct window
*r
= XWINDOW (root
);
29970 echo_area_window
= minibuf_window
;
29972 r
->top_line
= FRAME_TOP_MARGIN (f
);
29973 r
->total_lines
= FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
);
29974 r
->total_cols
= FRAME_COLS (f
);
29976 m
->top_line
= FRAME_LINES (f
) - 1;
29977 m
->total_lines
= 1;
29978 m
->total_cols
= FRAME_COLS (f
);
29980 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
29981 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
29982 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
29984 /* The default ellipsis glyphs `...'. */
29985 for (i
= 0; i
< 3; ++i
)
29986 default_invis_vector
[i
] = make_number ('.');
29990 /* Allocate the buffer for frame titles.
29991 Also used for `format-mode-line'. */
29993 mode_line_noprop_buf
= xmalloc (size
);
29994 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
29995 mode_line_noprop_ptr
= mode_line_noprop_buf
;
29996 mode_line_target
= MODE_LINE_DISPLAY
;
29999 help_echo_showing_p
= 0;
30002 /* Platform-independent portion of hourglass implementation. */
30004 /* Cancel a currently active hourglass timer, and start a new one. */
30006 start_hourglass (void)
30008 #if defined (HAVE_WINDOW_SYSTEM)
30011 cancel_hourglass ();
30013 if (INTEGERP (Vhourglass_delay
)
30014 && XINT (Vhourglass_delay
) > 0)
30015 delay
= make_emacs_time (min (XINT (Vhourglass_delay
),
30016 TYPE_MAXIMUM (time_t)),
30018 else if (FLOATP (Vhourglass_delay
)
30019 && XFLOAT_DATA (Vhourglass_delay
) > 0)
30020 delay
= EMACS_TIME_FROM_DOUBLE (XFLOAT_DATA (Vhourglass_delay
));
30022 delay
= make_emacs_time (DEFAULT_HOURGLASS_DELAY
, 0);
30026 extern void w32_note_current_window (void);
30027 w32_note_current_window ();
30029 #endif /* HAVE_NTGUI */
30031 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
30032 show_hourglass
, NULL
);
30037 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
30040 cancel_hourglass (void)
30042 #if defined (HAVE_WINDOW_SYSTEM)
30043 if (hourglass_atimer
)
30045 cancel_atimer (hourglass_atimer
);
30046 hourglass_atimer
= NULL
;
30049 if (hourglass_shown_p
)