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 \
384 && (IT)->line_wrap != WORD_WRAP)
386 #else /* !HAVE_WINDOW_SYSTEM */
387 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) 0
388 #endif /* HAVE_WINDOW_SYSTEM */
390 /* Test if the display element loaded in IT, or the underlying buffer
391 or string character, is a space or a TAB character. This is used
392 to determine where word wrapping can occur. */
394 #define IT_DISPLAYING_WHITESPACE(it) \
395 ((it->what == IT_CHARACTER && (it->c == ' ' || it->c == '\t')) \
396 || ((STRINGP (it->string) \
397 && (SREF (it->string, IT_STRING_BYTEPOS (*it)) == ' ' \
398 || SREF (it->string, IT_STRING_BYTEPOS (*it)) == '\t')) \
400 && (it->s[IT_BYTEPOS (*it)] == ' ' \
401 || it->s[IT_BYTEPOS (*it)] == '\t')) \
402 || (IT_BYTEPOS (*it) < ZV_BYTE \
403 && (*BYTE_POS_ADDR (IT_BYTEPOS (*it)) == ' ' \
404 || *BYTE_POS_ADDR (IT_BYTEPOS (*it)) == '\t')))) \
406 /* Name of the face used to highlight trailing whitespace. */
408 static Lisp_Object Qtrailing_whitespace
;
410 /* Name and number of the face used to highlight escape glyphs. */
412 static Lisp_Object Qescape_glyph
;
414 /* Name and number of the face used to highlight non-breaking spaces. */
416 static Lisp_Object Qnobreak_space
;
418 /* The symbol `image' which is the car of the lists used to represent
419 images in Lisp. Also a tool bar style. */
423 /* The image map types. */
425 static Lisp_Object QCpointer
;
426 static Lisp_Object Qrect
, Qcircle
, Qpoly
;
428 /* Tool bar styles */
429 Lisp_Object Qboth
, Qboth_horiz
, Qtext_image_horiz
;
431 /* Non-zero means print newline to stdout before next mini-buffer
434 int noninteractive_need_newline
;
436 /* Non-zero means print newline to message log before next message. */
438 static int message_log_need_newline
;
440 /* Three markers that message_dolog uses.
441 It could allocate them itself, but that causes trouble
442 in handling memory-full errors. */
443 static Lisp_Object message_dolog_marker1
;
444 static Lisp_Object message_dolog_marker2
;
445 static Lisp_Object message_dolog_marker3
;
447 /* The buffer position of the first character appearing entirely or
448 partially on the line of the selected window which contains the
449 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
450 redisplay optimization in redisplay_internal. */
452 static struct text_pos this_line_start_pos
;
454 /* Number of characters past the end of the line above, including the
455 terminating newline. */
457 static struct text_pos this_line_end_pos
;
459 /* The vertical positions and the height of this line. */
461 static int this_line_vpos
;
462 static int this_line_y
;
463 static int this_line_pixel_height
;
465 /* X position at which this display line starts. Usually zero;
466 negative if first character is partially visible. */
468 static int this_line_start_x
;
470 /* The smallest character position seen by move_it_* functions as they
471 move across display lines. Used to set MATRIX_ROW_START_CHARPOS of
472 hscrolled lines, see display_line. */
474 static struct text_pos this_line_min_pos
;
476 /* Buffer that this_line_.* variables are referring to. */
478 static struct buffer
*this_line_buffer
;
481 /* Values of those variables at last redisplay are stored as
482 properties on `overlay-arrow-position' symbol. However, if
483 Voverlay_arrow_position is a marker, last-arrow-position is its
484 numerical position. */
486 static Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
488 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
489 properties on a symbol in overlay-arrow-variable-list. */
491 static Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
493 Lisp_Object Qmenu_bar_update_hook
;
495 /* Nonzero if an overlay arrow has been displayed in this window. */
497 static int overlay_arrow_seen
;
499 /* Vector containing glyphs for an ellipsis `...'. */
501 static Lisp_Object default_invis_vector
[3];
503 /* This is the window where the echo area message was displayed. It
504 is always a mini-buffer window, but it may not be the same window
505 currently active as a mini-buffer. */
507 Lisp_Object echo_area_window
;
509 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
510 pushes the current message and the value of
511 message_enable_multibyte on the stack, the function restore_message
512 pops the stack and displays MESSAGE again. */
514 static Lisp_Object Vmessage_stack
;
516 /* Nonzero means multibyte characters were enabled when the echo area
517 message was specified. */
519 static int message_enable_multibyte
;
521 /* Nonzero if we should redraw the mode lines on the next redisplay. */
523 int update_mode_lines
;
525 /* Nonzero if window sizes or contents have changed since last
526 redisplay that finished. */
528 int windows_or_buffers_changed
;
530 /* Nonzero means a frame's cursor type has been changed. */
532 int cursor_type_changed
;
534 /* Nonzero after display_mode_line if %l was used and it displayed a
537 static int line_number_displayed
;
539 /* The name of the *Messages* buffer, a string. */
541 static Lisp_Object Vmessages_buffer_name
;
543 /* Current, index 0, and last displayed echo area message. Either
544 buffers from echo_buffers, or nil to indicate no message. */
546 Lisp_Object echo_area_buffer
[2];
548 /* The buffers referenced from echo_area_buffer. */
550 static Lisp_Object echo_buffer
[2];
552 /* A vector saved used in with_area_buffer to reduce consing. */
554 static Lisp_Object Vwith_echo_area_save_vector
;
556 /* Non-zero means display_echo_area should display the last echo area
557 message again. Set by redisplay_preserve_echo_area. */
559 static int display_last_displayed_message_p
;
561 /* Nonzero if echo area is being used by print; zero if being used by
564 static int message_buf_print
;
566 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
568 static Lisp_Object Qinhibit_menubar_update
;
569 static Lisp_Object Qmessage_truncate_lines
;
571 /* Set to 1 in clear_message to make redisplay_internal aware
572 of an emptied echo area. */
574 static int message_cleared_p
;
576 /* A scratch glyph row with contents used for generating truncation
577 glyphs. Also used in direct_output_for_insert. */
579 #define MAX_SCRATCH_GLYPHS 100
580 static struct glyph_row scratch_glyph_row
;
581 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
583 /* Ascent and height of the last line processed by move_it_to. */
585 static int last_max_ascent
, last_height
;
587 /* Non-zero if there's a help-echo in the echo area. */
589 int help_echo_showing_p
;
591 /* If >= 0, computed, exact values of mode-line and header-line height
592 to use in the macros CURRENT_MODE_LINE_HEIGHT and
593 CURRENT_HEADER_LINE_HEIGHT. */
595 int current_mode_line_height
, current_header_line_height
;
597 /* The maximum distance to look ahead for text properties. Values
598 that are too small let us call compute_char_face and similar
599 functions too often which is expensive. Values that are too large
600 let us call compute_char_face and alike too often because we
601 might not be interested in text properties that far away. */
603 #define TEXT_PROP_DISTANCE_LIMIT 100
605 /* SAVE_IT and RESTORE_IT are called when we save a snapshot of the
606 iterator state and later restore it. This is needed because the
607 bidi iterator on bidi.c keeps a stacked cache of its states, which
608 is really a singleton. When we use scratch iterator objects to
609 move around the buffer, we can cause the bidi cache to be pushed or
610 popped, and therefore we need to restore the cache state when we
611 return to the original iterator. */
612 #define SAVE_IT(ITCOPY,ITORIG,CACHE) \
615 bidi_unshelve_cache (CACHE, 1); \
617 CACHE = bidi_shelve_cache (); \
620 #define RESTORE_IT(pITORIG,pITCOPY,CACHE) \
622 if (pITORIG != pITCOPY) \
623 *(pITORIG) = *(pITCOPY); \
624 bidi_unshelve_cache (CACHE, 0); \
630 /* Non-zero means print traces of redisplay if compiled with
631 GLYPH_DEBUG defined. */
633 int trace_redisplay_p
;
635 #endif /* GLYPH_DEBUG */
637 #ifdef DEBUG_TRACE_MOVE
638 /* Non-zero means trace with TRACE_MOVE to stderr. */
641 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
643 #define TRACE_MOVE(x) (void) 0
646 static Lisp_Object Qauto_hscroll_mode
;
648 /* Buffer being redisplayed -- for redisplay_window_error. */
650 static struct buffer
*displayed_buffer
;
652 /* Value returned from text property handlers (see below). */
657 HANDLED_RECOMPUTE_PROPS
,
658 HANDLED_OVERLAY_STRING_CONSUMED
,
662 /* A description of text properties that redisplay is interested
667 /* The name of the property. */
670 /* A unique index for the property. */
673 /* A handler function called to set up iterator IT from the property
674 at IT's current position. Value is used to steer handle_stop. */
675 enum prop_handled (*handler
) (struct it
*it
);
678 static enum prop_handled
handle_face_prop (struct it
*);
679 static enum prop_handled
handle_invisible_prop (struct it
*);
680 static enum prop_handled
handle_display_prop (struct it
*);
681 static enum prop_handled
handle_composition_prop (struct it
*);
682 static enum prop_handled
handle_overlay_change (struct it
*);
683 static enum prop_handled
handle_fontified_prop (struct it
*);
685 /* Properties handled by iterators. */
687 static struct props it_props
[] =
689 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
690 /* Handle `face' before `display' because some sub-properties of
691 `display' need to know the face. */
692 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
693 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
694 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
695 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
699 /* Value is the position described by X. If X is a marker, value is
700 the marker_position of X. Otherwise, value is X. */
702 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
704 /* Enumeration returned by some move_it_.* functions internally. */
708 /* Not used. Undefined value. */
711 /* Move ended at the requested buffer position or ZV. */
712 MOVE_POS_MATCH_OR_ZV
,
714 /* Move ended at the requested X pixel position. */
717 /* Move within a line ended at the end of a line that must be
721 /* Move within a line ended at the end of a line that would
722 be displayed truncated. */
725 /* Move within a line ended at a line end. */
729 /* This counter is used to clear the face cache every once in a while
730 in redisplay_internal. It is incremented for each redisplay.
731 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
734 #define CLEAR_FACE_CACHE_COUNT 500
735 static int clear_face_cache_count
;
737 /* Similarly for the image cache. */
739 #ifdef HAVE_WINDOW_SYSTEM
740 #define CLEAR_IMAGE_CACHE_COUNT 101
741 static int clear_image_cache_count
;
743 /* Null glyph slice */
744 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
747 /* True while redisplay_internal is in progress. */
751 static Lisp_Object Qinhibit_free_realized_faces
;
752 static Lisp_Object Qmode_line_default_help_echo
;
754 /* If a string, XTread_socket generates an event to display that string.
755 (The display is done in read_char.) */
757 Lisp_Object help_echo_string
;
758 Lisp_Object help_echo_window
;
759 Lisp_Object help_echo_object
;
760 ptrdiff_t help_echo_pos
;
762 /* Temporary variable for XTread_socket. */
764 Lisp_Object previous_help_echo_string
;
766 /* Platform-independent portion of hourglass implementation. */
768 /* Non-zero means an hourglass cursor is currently shown. */
769 int hourglass_shown_p
;
771 /* If non-null, an asynchronous timer that, when it expires, displays
772 an hourglass cursor on all frames. */
773 struct atimer
*hourglass_atimer
;
775 /* Name of the face used to display glyphless characters. */
776 Lisp_Object Qglyphless_char
;
778 /* Symbol for the purpose of Vglyphless_char_display. */
779 static Lisp_Object Qglyphless_char_display
;
781 /* Method symbols for Vglyphless_char_display. */
782 static Lisp_Object Qhex_code
, Qempty_box
, Qthin_space
, Qzero_width
;
784 /* Default pixel width of `thin-space' display method. */
785 #define THIN_SPACE_WIDTH 1
787 /* Default number of seconds to wait before displaying an hourglass
789 #define DEFAULT_HOURGLASS_DELAY 1
792 /* Function prototypes. */
794 static void setup_for_ellipsis (struct it
*, int);
795 static void set_iterator_to_next (struct it
*, int);
796 static void mark_window_display_accurate_1 (struct window
*, int);
797 static int single_display_spec_string_p (Lisp_Object
, Lisp_Object
);
798 static int display_prop_string_p (Lisp_Object
, Lisp_Object
);
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 void reconsider_clip_changes (struct window
*, struct buffer
*);
812 static int text_outside_line_unchanged_p (struct window
*,
813 ptrdiff_t, ptrdiff_t);
814 static void store_mode_line_noprop_char (char);
815 static int store_mode_line_noprop (const char *, int, int);
816 static void handle_stop (struct it
*);
817 static void handle_stop_backwards (struct it
*, ptrdiff_t);
818 static void vmessage (const char *, va_list) ATTRIBUTE_FORMAT_PRINTF (1, 0);
819 static void ensure_echo_area_buffers (void);
820 static Lisp_Object
unwind_with_echo_area_buffer (Lisp_Object
);
821 static Lisp_Object
with_echo_area_buffer_unwind_data (struct window
*);
822 static int with_echo_area_buffer (struct window
*, int,
823 int (*) (ptrdiff_t, Lisp_Object
),
824 ptrdiff_t, Lisp_Object
);
825 static void clear_garbaged_frames (void);
826 static int current_message_1 (ptrdiff_t, Lisp_Object
);
827 static void pop_message (void);
828 static int truncate_message_1 (ptrdiff_t, Lisp_Object
);
829 static void set_message (Lisp_Object
);
830 static int set_message_1 (ptrdiff_t, Lisp_Object
);
831 static int display_echo_area (struct window
*);
832 static int display_echo_area_1 (ptrdiff_t, Lisp_Object
);
833 static int resize_mini_window_1 (ptrdiff_t, Lisp_Object
);
834 static Lisp_Object
unwind_redisplay (Lisp_Object
);
835 static int string_char_and_length (const unsigned char *, int *);
836 static struct text_pos
display_prop_end (struct it
*, Lisp_Object
,
838 static int compute_window_start_on_continuation_line (struct window
*);
839 static void insert_left_trunc_glyphs (struct it
*);
840 static struct glyph_row
*get_overlay_arrow_glyph_row (struct window
*,
842 static void extend_face_to_end_of_line (struct it
*);
843 static int append_space_for_newline (struct it
*, int);
844 static int cursor_row_fully_visible_p (struct window
*, int, int);
845 static int try_scrolling (Lisp_Object
, int, ptrdiff_t, ptrdiff_t, int, int);
846 static int try_cursor_movement (Lisp_Object
, struct text_pos
, int *);
847 static int trailing_whitespace_p (ptrdiff_t);
848 static intmax_t message_log_check_duplicate (ptrdiff_t, ptrdiff_t);
849 static void push_it (struct it
*, struct text_pos
*);
850 static void iterate_out_of_display_property (struct it
*);
851 static void pop_it (struct it
*);
852 static void sync_frame_with_window_matrix_rows (struct window
*);
853 static void redisplay_internal (void);
854 static int echo_area_display (int);
855 static void redisplay_windows (Lisp_Object
);
856 static void redisplay_window (Lisp_Object
, int);
857 static Lisp_Object
redisplay_window_error (Lisp_Object
);
858 static Lisp_Object
redisplay_window_0 (Lisp_Object
);
859 static Lisp_Object
redisplay_window_1 (Lisp_Object
);
860 static int set_cursor_from_row (struct window
*, struct glyph_row
*,
861 struct glyph_matrix
*, ptrdiff_t, ptrdiff_t,
863 static int update_menu_bar (struct frame
*, int, int);
864 static int try_window_reusing_current_matrix (struct window
*);
865 static int try_window_id (struct window
*);
866 static int display_line (struct it
*);
867 static int display_mode_lines (struct window
*);
868 static int display_mode_line (struct window
*, enum face_id
, Lisp_Object
);
869 static int display_mode_element (struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int);
870 static int store_mode_line_string (const char *, Lisp_Object
, int, int, int, Lisp_Object
);
871 static const char *decode_mode_spec (struct window
*, int, int, Lisp_Object
*);
872 static void display_menu_bar (struct window
*);
873 static ptrdiff_t display_count_lines (ptrdiff_t, ptrdiff_t, ptrdiff_t,
875 static int display_string (const char *, Lisp_Object
, Lisp_Object
,
876 ptrdiff_t, ptrdiff_t, struct it
*, int, int, int, int);
877 static void compute_line_metrics (struct it
*);
878 static void run_redisplay_end_trigger_hook (struct it
*);
879 static int get_overlay_strings (struct it
*, ptrdiff_t);
880 static int get_overlay_strings_1 (struct it
*, ptrdiff_t, int);
881 static void next_overlay_string (struct it
*);
882 static void reseat (struct it
*, struct text_pos
, int);
883 static void reseat_1 (struct it
*, struct text_pos
, int);
884 static void back_to_previous_visible_line_start (struct it
*);
885 void reseat_at_previous_visible_line_start (struct it
*);
886 static void reseat_at_next_visible_line_start (struct it
*, int);
887 static int next_element_from_ellipsis (struct it
*);
888 static int next_element_from_display_vector (struct it
*);
889 static int next_element_from_string (struct it
*);
890 static int next_element_from_c_string (struct it
*);
891 static int next_element_from_buffer (struct it
*);
892 static int next_element_from_composition (struct it
*);
893 static int next_element_from_image (struct it
*);
895 static int next_element_from_xwidget(struct it
*);
897 static int next_element_from_stretch (struct it
*);
898 static void load_overlay_strings (struct it
*, ptrdiff_t);
899 static int init_from_display_pos (struct it
*, struct window
*,
900 struct display_pos
*);
901 static void reseat_to_string (struct it
*, const char *,
902 Lisp_Object
, ptrdiff_t, ptrdiff_t, int, int);
903 static int get_next_display_element (struct it
*);
904 static enum move_it_result
905 move_it_in_display_line_to (struct it
*, ptrdiff_t, int,
906 enum move_operation_enum
);
907 void move_it_vertically_backward (struct it
*, int);
908 static void get_visually_first_element (struct it
*);
909 static void init_to_row_start (struct it
*, struct window
*,
911 static int init_to_row_end (struct it
*, struct window
*,
913 static void back_to_previous_line_start (struct it
*);
914 static int forward_to_next_line_start (struct it
*, int *, struct bidi_it
*);
915 static struct text_pos
string_pos_nchars_ahead (struct text_pos
,
916 Lisp_Object
, ptrdiff_t);
917 static struct text_pos
string_pos (ptrdiff_t, Lisp_Object
);
918 static struct text_pos
c_string_pos (ptrdiff_t, const char *, bool);
919 static ptrdiff_t number_of_chars (const char *, bool);
920 static void compute_stop_pos (struct it
*);
921 static void compute_string_pos (struct text_pos
*, struct text_pos
,
923 static int face_before_or_after_it_pos (struct it
*, int);
924 static ptrdiff_t next_overlay_change (ptrdiff_t);
925 static int handle_display_spec (struct it
*, Lisp_Object
, Lisp_Object
,
926 Lisp_Object
, struct text_pos
*, ptrdiff_t, int);
927 static int handle_single_display_spec (struct it
*, Lisp_Object
,
928 Lisp_Object
, Lisp_Object
,
929 struct text_pos
*, ptrdiff_t, int, int);
930 static int underlying_face_id (struct it
*);
931 static int in_ellipses_for_invisible_text_p (struct display_pos
*,
934 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
935 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
937 #ifdef HAVE_WINDOW_SYSTEM
939 static void x_consider_frame_title (Lisp_Object
);
940 static int tool_bar_lines_needed (struct frame
*, int *);
941 static void update_tool_bar (struct frame
*, int);
942 static void build_desired_tool_bar_string (struct frame
*f
);
943 static int redisplay_tool_bar (struct frame
*);
944 static void display_tool_bar_line (struct it
*, int);
945 static void notice_overwritten_cursor (struct window
*,
948 static void append_stretch_glyph (struct it
*, Lisp_Object
,
952 #endif /* HAVE_WINDOW_SYSTEM */
954 static void produce_special_glyphs (struct it
*, enum display_element_type
);
955 static void show_mouse_face (Mouse_HLInfo
*, enum draw_glyphs_face
);
956 static int coords_in_mouse_face_p (struct window
*, int, int);
960 /***********************************************************************
961 Window display dimensions
962 ***********************************************************************/
964 /* Return the bottom boundary y-position for text lines in window W.
965 This is the first y position at which a line cannot start.
966 It is relative to the top of the window.
968 This is the height of W minus the height of a mode line, if any. */
971 window_text_bottom_y (struct window
*w
)
973 int height
= WINDOW_TOTAL_HEIGHT (w
);
975 if (WINDOW_WANTS_MODELINE_P (w
))
976 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
980 /* Return the pixel width of display area AREA of window W. AREA < 0
981 means return the total width of W, not including fringes to
982 the left and right of the window. */
985 window_box_width (struct window
*w
, int area
)
987 int cols
= XFASTINT (w
->total_cols
);
990 if (!w
->pseudo_window_p
)
992 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
994 if (area
== TEXT_AREA
)
996 if (INTEGERP (w
->left_margin_cols
))
997 cols
-= XFASTINT (w
->left_margin_cols
);
998 if (INTEGERP (w
->right_margin_cols
))
999 cols
-= XFASTINT (w
->right_margin_cols
);
1000 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
1002 else if (area
== LEFT_MARGIN_AREA
)
1004 cols
= (INTEGERP (w
->left_margin_cols
)
1005 ? XFASTINT (w
->left_margin_cols
) : 0);
1008 else if (area
== RIGHT_MARGIN_AREA
)
1010 cols
= (INTEGERP (w
->right_margin_cols
)
1011 ? XFASTINT (w
->right_margin_cols
) : 0);
1016 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1020 /* Return the pixel height of the display area of window W, not
1021 including mode lines of W, if any. */
1024 window_box_height (struct window
*w
)
1026 struct frame
*f
= XFRAME (w
->frame
);
1027 int height
= WINDOW_TOTAL_HEIGHT (w
);
1029 eassert (height
>= 0);
1031 /* Note: the code below that determines the mode-line/header-line
1032 height is essentially the same as that contained in the macro
1033 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1034 the appropriate glyph row has its `mode_line_p' flag set,
1035 and if it doesn't, uses estimate_mode_line_height instead. */
1037 if (WINDOW_WANTS_MODELINE_P (w
))
1039 struct glyph_row
*ml_row
1040 = (w
->current_matrix
&& w
->current_matrix
->rows
1041 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1043 if (ml_row
&& ml_row
->mode_line_p
)
1044 height
-= ml_row
->height
;
1046 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1049 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1051 struct glyph_row
*hl_row
1052 = (w
->current_matrix
&& w
->current_matrix
->rows
1053 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1055 if (hl_row
&& hl_row
->mode_line_p
)
1056 height
-= hl_row
->height
;
1058 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1061 /* With a very small font and a mode-line that's taller than
1062 default, we might end up with a negative height. */
1063 return max (0, height
);
1066 /* Return the window-relative coordinate of the left edge of display
1067 area AREA of window W. AREA < 0 means return the left edge of the
1068 whole window, to the right of the left fringe of W. */
1071 window_box_left_offset (struct window
*w
, int area
)
1075 if (w
->pseudo_window_p
)
1078 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1080 if (area
== TEXT_AREA
)
1081 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1082 + window_box_width (w
, LEFT_MARGIN_AREA
));
1083 else if (area
== RIGHT_MARGIN_AREA
)
1084 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1085 + window_box_width (w
, LEFT_MARGIN_AREA
)
1086 + window_box_width (w
, TEXT_AREA
)
1087 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1089 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1090 else if (area
== LEFT_MARGIN_AREA
1091 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1092 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1098 /* Return the window-relative coordinate of the right edge of display
1099 area AREA of window W. AREA < 0 means return the right edge of the
1100 whole window, to the left of the right fringe of W. */
1103 window_box_right_offset (struct window
*w
, int area
)
1105 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1108 /* Return the frame-relative coordinate of the left edge of display
1109 area AREA of window W. AREA < 0 means return the left edge of the
1110 whole window, to the right of the left fringe of W. */
1113 window_box_left (struct window
*w
, int area
)
1115 struct frame
*f
= XFRAME (w
->frame
);
1118 if (w
->pseudo_window_p
)
1119 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1121 x
= (WINDOW_LEFT_EDGE_X (w
)
1122 + window_box_left_offset (w
, area
));
1128 /* Return the frame-relative coordinate of the right edge of display
1129 area AREA of window W. AREA < 0 means return the right edge of the
1130 whole window, to the left of the right fringe of W. */
1133 window_box_right (struct window
*w
, int area
)
1135 return window_box_left (w
, area
) + window_box_width (w
, area
);
1138 /* Get the bounding box of the display area AREA of window W, without
1139 mode lines, in frame-relative coordinates. AREA < 0 means the
1140 whole window, not including the left and right fringes of
1141 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1142 coordinates of the upper-left corner of the box. Return in
1143 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1146 window_box (struct window
*w
, int area
, int *box_x
, int *box_y
,
1147 int *box_width
, int *box_height
)
1150 *box_width
= window_box_width (w
, area
);
1152 *box_height
= window_box_height (w
);
1154 *box_x
= window_box_left (w
, area
);
1157 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1158 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1159 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1164 /* Get the bounding box of the display area AREA of window W, without
1165 mode lines. AREA < 0 means the whole window, not including the
1166 left and right fringe of the window. Return in *TOP_LEFT_X
1167 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1168 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1169 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1173 window_box_edges (struct window
*w
, int area
, int *top_left_x
, int *top_left_y
,
1174 int *bottom_right_x
, int *bottom_right_y
)
1176 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1178 *bottom_right_x
+= *top_left_x
;
1179 *bottom_right_y
+= *top_left_y
;
1184 /***********************************************************************
1186 ***********************************************************************/
1188 /* Return the bottom y-position of the line the iterator IT is in.
1189 This can modify IT's settings. */
1192 line_bottom_y (struct it
*it
)
1194 int line_height
= it
->max_ascent
+ it
->max_descent
;
1195 int line_top_y
= it
->current_y
;
1197 if (line_height
== 0)
1200 line_height
= last_height
;
1201 else if (IT_CHARPOS (*it
) < ZV
)
1203 move_it_by_lines (it
, 1);
1204 line_height
= (it
->max_ascent
|| it
->max_descent
1205 ? it
->max_ascent
+ it
->max_descent
1210 struct glyph_row
*row
= it
->glyph_row
;
1212 /* Use the default character height. */
1213 it
->glyph_row
= NULL
;
1214 it
->what
= IT_CHARACTER
;
1217 PRODUCE_GLYPHS (it
);
1218 line_height
= it
->ascent
+ it
->descent
;
1219 it
->glyph_row
= row
;
1223 return line_top_y
+ line_height
;
1226 /* Subroutine of pos_visible_p below. Extracts a display string, if
1227 any, from the display spec given as its argument. */
1229 string_from_display_spec (Lisp_Object spec
)
1233 while (CONSP (spec
))
1235 if (STRINGP (XCAR (spec
)))
1240 else if (VECTORP (spec
))
1244 for (i
= 0; i
< ASIZE (spec
); i
++)
1246 if (STRINGP (AREF (spec
, i
)))
1247 return AREF (spec
, i
);
1256 /* Limit insanely large values of W->hscroll on frame F to the largest
1257 value that will still prevent first_visible_x and last_visible_x of
1258 'struct it' from overflowing an int. */
1260 window_hscroll_limited (struct window
*w
, struct frame
*f
)
1262 ptrdiff_t window_hscroll
= w
->hscroll
;
1263 int window_text_width
= window_box_width (w
, TEXT_AREA
);
1264 int colwidth
= FRAME_COLUMN_WIDTH (f
);
1266 if (window_hscroll
> (INT_MAX
- window_text_width
) / colwidth
- 1)
1267 window_hscroll
= (INT_MAX
- window_text_width
) / colwidth
- 1;
1269 return window_hscroll
;
1272 /* Return 1 if position CHARPOS is visible in window W.
1273 CHARPOS < 0 means return info about WINDOW_END position.
1274 If visible, set *X and *Y to pixel coordinates of top left corner.
1275 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1276 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1279 pos_visible_p (struct window
*w
, ptrdiff_t charpos
, int *x
, int *y
,
1280 int *rtop
, int *rbot
, int *rowh
, int *vpos
)
1283 void *itdata
= bidi_shelve_cache ();
1284 struct text_pos top
;
1286 struct buffer
*old_buffer
= NULL
;
1288 if (FRAME_INITIAL_P (XFRAME (WINDOW_FRAME (w
))))
1291 if (XBUFFER (w
->buffer
) != current_buffer
)
1293 old_buffer
= current_buffer
;
1294 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1297 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1298 /* Scrolling a minibuffer window via scroll bar when the echo area
1299 shows long text sometimes resets the minibuffer contents behind
1301 if (CHARPOS (top
) > ZV
)
1302 SET_TEXT_POS (top
, BEGV
, BEGV_BYTE
);
1304 /* Compute exact mode line heights. */
1305 if (WINDOW_WANTS_MODELINE_P (w
))
1306 current_mode_line_height
1307 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1308 BVAR (current_buffer
, mode_line_format
));
1310 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1311 current_header_line_height
1312 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1313 BVAR (current_buffer
, header_line_format
));
1315 start_display (&it
, w
, top
);
1316 move_it_to (&it
, charpos
, -1, it
.last_visible_y
- 1, -1,
1317 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1320 && (((!it
.bidi_p
|| it
.bidi_it
.scan_dir
== 1)
1321 && IT_CHARPOS (it
) >= charpos
)
1322 /* When scanning backwards under bidi iteration, move_it_to
1323 stops at or _before_ CHARPOS, because it stops at or to
1324 the _right_ of the character at CHARPOS. */
1325 || (it
.bidi_p
&& it
.bidi_it
.scan_dir
== -1
1326 && IT_CHARPOS (it
) <= charpos
)))
1328 /* We have reached CHARPOS, or passed it. How the call to
1329 move_it_to can overshoot: (i) If CHARPOS is on invisible text
1330 or covered by a display property, move_it_to stops at the end
1331 of the invisible text, to the right of CHARPOS. (ii) If
1332 CHARPOS is in a display vector, move_it_to stops on its last
1334 int top_x
= it
.current_x
;
1335 int top_y
= it
.current_y
;
1336 /* Calling line_bottom_y may change it.method, it.position, etc. */
1337 enum it_method it_method
= it
.method
;
1338 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1339 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1341 if (top_y
< window_top_y
)
1342 visible_p
= bottom_y
> window_top_y
;
1343 else if (top_y
< it
.last_visible_y
)
1345 if (bottom_y
>= it
.last_visible_y
1346 && it
.bidi_p
&& it
.bidi_it
.scan_dir
== -1
1347 && IT_CHARPOS (it
) < charpos
)
1349 /* When the last line of the window is scanned backwards
1350 under bidi iteration, we could be duped into thinking
1351 that we have passed CHARPOS, when in fact move_it_to
1352 simply stopped short of CHARPOS because it reached
1353 last_visible_y. To see if that's what happened, we call
1354 move_it_to again with a slightly larger vertical limit,
1355 and see if it actually moved vertically; if it did, we
1356 didn't really reach CHARPOS, which is beyond window end. */
1357 struct it save_it
= it
;
1358 /* Why 10? because we don't know how many canonical lines
1359 will the height of the next line(s) be. So we guess. */
1360 int ten_more_lines
=
1361 10 * FRAME_LINE_HEIGHT (XFRAME (WINDOW_FRAME (w
)));
1363 move_it_to (&it
, charpos
, -1, bottom_y
+ ten_more_lines
, -1,
1364 MOVE_TO_POS
| MOVE_TO_Y
);
1365 if (it
.current_y
> top_y
)
1372 if (it_method
== GET_FROM_DISPLAY_VECTOR
)
1374 /* We stopped on the last glyph of a display vector.
1375 Try and recompute. Hack alert! */
1376 if (charpos
< 2 || top
.charpos
>= charpos
)
1377 top_x
= it
.glyph_row
->x
;
1381 start_display (&it2
, w
, top
);
1382 move_it_to (&it2
, charpos
- 1, -1, -1, -1, MOVE_TO_POS
);
1383 get_next_display_element (&it2
);
1384 PRODUCE_GLYPHS (&it2
);
1385 if (ITERATOR_AT_END_OF_LINE_P (&it2
)
1386 || it2
.current_x
> it2
.last_visible_x
)
1387 top_x
= it
.glyph_row
->x
;
1390 top_x
= it2
.current_x
;
1391 top_y
= it2
.current_y
;
1395 else if (IT_CHARPOS (it
) != charpos
)
1397 Lisp_Object cpos
= make_number (charpos
);
1398 Lisp_Object spec
= Fget_char_property (cpos
, Qdisplay
, Qnil
);
1399 Lisp_Object string
= string_from_display_spec (spec
);
1400 bool newline_in_string
1402 && memchr (SDATA (string
), '\n', SBYTES (string
)));
1403 /* The tricky code below is needed because there's a
1404 discrepancy between move_it_to and how we set cursor
1405 when the display line ends in a newline from a
1406 display string. move_it_to will stop _after_ such
1407 display strings, whereas set_cursor_from_row
1408 conspires with cursor_row_p to place the cursor on
1409 the first glyph produced from the display string. */
1411 /* We have overshoot PT because it is covered by a
1412 display property whose value is a string. If the
1413 string includes embedded newlines, we are also in the
1414 wrong display line. Backtrack to the correct line,
1415 where the display string begins. */
1416 if (newline_in_string
)
1418 Lisp_Object startpos
, endpos
;
1419 EMACS_INT start
, end
;
1423 /* Find the first and the last buffer positions
1424 covered by the display string. */
1426 Fnext_single_char_property_change (cpos
, Qdisplay
,
1429 Fprevious_single_char_property_change (endpos
, Qdisplay
,
1431 start
= XFASTINT (startpos
);
1432 end
= XFASTINT (endpos
);
1433 /* Move to the last buffer position before the
1434 display property. */
1435 start_display (&it3
, w
, top
);
1436 move_it_to (&it3
, start
- 1, -1, -1, -1, MOVE_TO_POS
);
1437 /* Move forward one more line if the position before
1438 the display string is a newline or if it is the
1439 rightmost character on a line that is
1440 continued or word-wrapped. */
1441 if (it3
.method
== GET_FROM_BUFFER
1443 move_it_by_lines (&it3
, 1);
1444 else if (move_it_in_display_line_to (&it3
, -1,
1448 == MOVE_LINE_CONTINUED
)
1450 move_it_by_lines (&it3
, 1);
1451 /* When we are under word-wrap, the #$@%!
1452 move_it_by_lines moves 2 lines, so we need to
1454 if (it3
.line_wrap
== WORD_WRAP
)
1455 move_it_by_lines (&it3
, -1);
1458 /* Record the vertical coordinate of the display
1459 line where we wound up. */
1460 top_y
= it3
.current_y
;
1463 /* When characters are reordered for display,
1464 the character displayed to the left of the
1465 display string could be _after_ the display
1466 property in the logical order. Use the
1467 smallest vertical position of these two. */
1468 start_display (&it3
, w
, top
);
1469 move_it_to (&it3
, end
+ 1, -1, -1, -1, MOVE_TO_POS
);
1470 if (it3
.current_y
< top_y
)
1471 top_y
= it3
.current_y
;
1473 /* Move from the top of the window to the beginning
1474 of the display line where the display string
1476 start_display (&it3
, w
, top
);
1477 move_it_to (&it3
, -1, 0, top_y
, -1, MOVE_TO_X
| MOVE_TO_Y
);
1478 /* If it3_moved stays zero after the 'while' loop
1479 below, that means we already were at a newline
1480 before the loop (e.g., the display string begins
1481 with a newline), so we don't need to (and cannot)
1482 inspect the glyphs of it3.glyph_row, because
1483 PRODUCE_GLYPHS will not produce anything for a
1484 newline, and thus it3.glyph_row stays at its
1485 stale content it got at top of the window. */
1487 /* Finally, advance the iterator until we hit the
1488 first display element whose character position is
1489 CHARPOS, or until the first newline from the
1490 display string, which signals the end of the
1492 while (get_next_display_element (&it3
))
1494 PRODUCE_GLYPHS (&it3
);
1495 if (IT_CHARPOS (it3
) == charpos
1496 || ITERATOR_AT_END_OF_LINE_P (&it3
))
1499 set_iterator_to_next (&it3
, 0);
1501 top_x
= it3
.current_x
- it3
.pixel_width
;
1502 /* Normally, we would exit the above loop because we
1503 found the display element whose character
1504 position is CHARPOS. For the contingency that we
1505 didn't, and stopped at the first newline from the
1506 display string, move back over the glyphs
1507 produced from the string, until we find the
1508 rightmost glyph not from the string. */
1510 && IT_CHARPOS (it3
) != charpos
&& EQ (it3
.object
, string
))
1512 struct glyph
*g
= it3
.glyph_row
->glyphs
[TEXT_AREA
]
1513 + it3
.glyph_row
->used
[TEXT_AREA
];
1515 while (EQ ((g
- 1)->object
, string
))
1518 top_x
-= g
->pixel_width
;
1520 eassert (g
< it3
.glyph_row
->glyphs
[TEXT_AREA
]
1521 + it3
.glyph_row
->used
[TEXT_AREA
]);
1527 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1528 *rtop
= max (0, window_top_y
- top_y
);
1529 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1530 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1531 - max (top_y
, window_top_y
)));
1537 /* We were asked to provide info about WINDOW_END. */
1539 void *it2data
= NULL
;
1541 SAVE_IT (it2
, it
, it2data
);
1542 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1543 move_it_by_lines (&it
, 1);
1544 if (charpos
< IT_CHARPOS (it
)
1545 || (it
.what
== IT_EOB
&& charpos
== IT_CHARPOS (it
)))
1548 RESTORE_IT (&it2
, &it2
, it2data
);
1549 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1551 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1552 *rtop
= max (0, -it2
.current_y
);
1553 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1554 - it
.last_visible_y
));
1555 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1557 - max (it2
.current_y
,
1558 WINDOW_HEADER_LINE_HEIGHT (w
))));
1562 bidi_unshelve_cache (it2data
, 1);
1564 bidi_unshelve_cache (itdata
, 0);
1567 set_buffer_internal_1 (old_buffer
);
1569 current_header_line_height
= current_mode_line_height
= -1;
1571 if (visible_p
&& w
->hscroll
> 0)
1573 window_hscroll_limited (w
, WINDOW_XFRAME (w
))
1574 * WINDOW_FRAME_COLUMN_WIDTH (w
);
1577 /* Debugging code. */
1579 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1580 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1582 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1589 /* Return the next character from STR. Return in *LEN the length of
1590 the character. This is like STRING_CHAR_AND_LENGTH but never
1591 returns an invalid character. If we find one, we return a `?', but
1592 with the length of the invalid character. */
1595 string_char_and_length (const unsigned char *str
, int *len
)
1599 c
= STRING_CHAR_AND_LENGTH (str
, *len
);
1600 if (!CHAR_VALID_P (c
))
1601 /* We may not change the length here because other places in Emacs
1602 don't use this function, i.e. they silently accept invalid
1611 /* Given a position POS containing a valid character and byte position
1612 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1614 static struct text_pos
1615 string_pos_nchars_ahead (struct text_pos pos
, Lisp_Object string
, ptrdiff_t nchars
)
1617 eassert (STRINGP (string
) && nchars
>= 0);
1619 if (STRING_MULTIBYTE (string
))
1621 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1626 string_char_and_length (p
, &len
);
1629 BYTEPOS (pos
) += len
;
1633 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1639 /* Value is the text position, i.e. character and byte position,
1640 for character position CHARPOS in STRING. */
1642 static struct text_pos
1643 string_pos (ptrdiff_t charpos
, Lisp_Object string
)
1645 struct text_pos pos
;
1646 eassert (STRINGP (string
));
1647 eassert (charpos
>= 0);
1648 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1653 /* Value is a text position, i.e. character and byte position, for
1654 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1655 means recognize multibyte characters. */
1657 static struct text_pos
1658 c_string_pos (ptrdiff_t charpos
, const char *s
, bool multibyte_p
)
1660 struct text_pos pos
;
1662 eassert (s
!= NULL
);
1663 eassert (charpos
>= 0);
1669 SET_TEXT_POS (pos
, 0, 0);
1672 string_char_and_length ((const unsigned char *) s
, &len
);
1675 BYTEPOS (pos
) += len
;
1679 SET_TEXT_POS (pos
, charpos
, charpos
);
1685 /* Value is the number of characters in C string S. MULTIBYTE_P
1686 non-zero means recognize multibyte characters. */
1689 number_of_chars (const char *s
, bool multibyte_p
)
1695 ptrdiff_t rest
= strlen (s
);
1697 const unsigned char *p
= (const unsigned char *) s
;
1699 for (nchars
= 0; rest
> 0; ++nchars
)
1701 string_char_and_length (p
, &len
);
1702 rest
-= len
, p
+= len
;
1706 nchars
= strlen (s
);
1712 /* Compute byte position NEWPOS->bytepos corresponding to
1713 NEWPOS->charpos. POS is a known position in string STRING.
1714 NEWPOS->charpos must be >= POS.charpos. */
1717 compute_string_pos (struct text_pos
*newpos
, struct text_pos pos
, Lisp_Object string
)
1719 eassert (STRINGP (string
));
1720 eassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1722 if (STRING_MULTIBYTE (string
))
1723 *newpos
= string_pos_nchars_ahead (pos
, string
,
1724 CHARPOS (*newpos
) - CHARPOS (pos
));
1726 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1730 Return an estimation of the pixel height of mode or header lines on
1731 frame F. FACE_ID specifies what line's height to estimate. */
1734 estimate_mode_line_height (struct frame
*f
, enum face_id face_id
)
1736 #ifdef HAVE_WINDOW_SYSTEM
1737 if (FRAME_WINDOW_P (f
))
1739 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1741 /* This function is called so early when Emacs starts that the face
1742 cache and mode line face are not yet initialized. */
1743 if (FRAME_FACE_CACHE (f
))
1745 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1749 height
= FONT_HEIGHT (face
->font
);
1750 if (face
->box_line_width
> 0)
1751 height
+= 2 * face
->box_line_width
;
1762 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1763 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1764 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1765 not force the value into range. */
1768 pixel_to_glyph_coords (FRAME_PTR f
, register int pix_x
, register int pix_y
,
1769 int *x
, int *y
, NativeRectangle
*bounds
, int noclip
)
1772 #ifdef HAVE_WINDOW_SYSTEM
1773 if (FRAME_WINDOW_P (f
))
1775 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1776 even for negative values. */
1778 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1780 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1782 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1783 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1786 STORE_NATIVE_RECT (*bounds
,
1787 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1788 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1789 FRAME_COLUMN_WIDTH (f
) - 1,
1790 FRAME_LINE_HEIGHT (f
) - 1);
1796 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1797 pix_x
= FRAME_TOTAL_COLS (f
);
1801 else if (pix_y
> FRAME_LINES (f
))
1802 pix_y
= FRAME_LINES (f
);
1812 /* Find the glyph under window-relative coordinates X/Y in window W.
1813 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1814 strings. Return in *HPOS and *VPOS the row and column number of
1815 the glyph found. Return in *AREA the glyph area containing X.
1816 Value is a pointer to the glyph found or null if X/Y is not on
1817 text, or we can't tell because W's current matrix is not up to
1822 x_y_to_hpos_vpos (struct window
*w
, int x
, int y
, int *hpos
, int *vpos
,
1823 int *dx
, int *dy
, int *area
)
1825 struct glyph
*glyph
, *end
;
1826 struct glyph_row
*row
= NULL
;
1829 /* Find row containing Y. Give up if some row is not enabled. */
1830 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1832 row
= MATRIX_ROW (w
->current_matrix
, i
);
1833 if (!row
->enabled_p
)
1835 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1842 /* Give up if Y is not in the window. */
1843 if (i
== w
->current_matrix
->nrows
)
1846 /* Get the glyph area containing X. */
1847 if (w
->pseudo_window_p
)
1854 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1856 *area
= LEFT_MARGIN_AREA
;
1857 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1859 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1862 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1866 *area
= RIGHT_MARGIN_AREA
;
1867 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1871 /* Find glyph containing X. */
1872 glyph
= row
->glyphs
[*area
];
1873 end
= glyph
+ row
->used
[*area
];
1875 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1877 x
-= glyph
->pixel_width
;
1887 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1890 *hpos
= glyph
- row
->glyphs
[*area
];
1894 /* Convert frame-relative x/y to coordinates relative to window W.
1895 Takes pseudo-windows into account. */
1898 frame_to_window_pixel_xy (struct window
*w
, int *x
, int *y
)
1900 if (w
->pseudo_window_p
)
1902 /* A pseudo-window is always full-width, and starts at the
1903 left edge of the frame, plus a frame border. */
1904 struct frame
*f
= XFRAME (w
->frame
);
1905 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1906 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1910 *x
-= WINDOW_LEFT_EDGE_X (w
);
1911 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1915 #ifdef HAVE_WINDOW_SYSTEM
1918 Return in RECTS[] at most N clipping rectangles for glyph string S.
1919 Return the number of stored rectangles. */
1922 get_glyph_string_clip_rects (struct glyph_string
*s
, NativeRectangle
*rects
, int n
)
1929 if (s
->row
->full_width_p
)
1931 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1932 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1933 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1935 /* Unless displaying a mode or menu bar line, which are always
1936 fully visible, clip to the visible part of the row. */
1937 if (s
->w
->pseudo_window_p
)
1938 r
.height
= s
->row
->visible_height
;
1940 r
.height
= s
->height
;
1944 /* This is a text line that may be partially visible. */
1945 r
.x
= window_box_left (s
->w
, s
->area
);
1946 r
.width
= window_box_width (s
->w
, s
->area
);
1947 r
.height
= s
->row
->visible_height
;
1951 if (r
.x
< s
->clip_head
->x
)
1953 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1954 r
.width
-= s
->clip_head
->x
- r
.x
;
1957 r
.x
= s
->clip_head
->x
;
1960 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1962 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1963 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
1968 /* If S draws overlapping rows, it's sufficient to use the top and
1969 bottom of the window for clipping because this glyph string
1970 intentionally draws over other lines. */
1971 if (s
->for_overlaps
)
1973 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1974 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1976 /* Alas, the above simple strategy does not work for the
1977 environments with anti-aliased text: if the same text is
1978 drawn onto the same place multiple times, it gets thicker.
1979 If the overlap we are processing is for the erased cursor, we
1980 take the intersection with the rectangle of the cursor. */
1981 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
1983 XRectangle rc
, r_save
= r
;
1985 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
1986 rc
.y
= s
->w
->phys_cursor
.y
;
1987 rc
.width
= s
->w
->phys_cursor_width
;
1988 rc
.height
= s
->w
->phys_cursor_height
;
1990 x_intersect_rectangles (&r_save
, &rc
, &r
);
1995 /* Don't use S->y for clipping because it doesn't take partially
1996 visible lines into account. For example, it can be negative for
1997 partially visible lines at the top of a window. */
1998 if (!s
->row
->full_width_p
1999 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
2000 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
2002 r
.y
= max (0, s
->row
->y
);
2005 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
2007 /* If drawing the cursor, don't let glyph draw outside its
2008 advertised boundaries. Cleartype does this under some circumstances. */
2009 if (s
->hl
== DRAW_CURSOR
)
2011 struct glyph
*glyph
= s
->first_glyph
;
2016 r
.width
-= s
->x
- r
.x
;
2019 r
.width
= min (r
.width
, glyph
->pixel_width
);
2021 /* If r.y is below window bottom, ensure that we still see a cursor. */
2022 height
= min (glyph
->ascent
+ glyph
->descent
,
2023 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
2024 max_y
= window_text_bottom_y (s
->w
) - height
;
2025 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
2026 if (s
->ybase
- glyph
->ascent
> max_y
)
2033 /* Don't draw cursor glyph taller than our actual glyph. */
2034 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
2035 if (height
< r
.height
)
2037 max_y
= r
.y
+ r
.height
;
2038 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
2039 r
.height
= min (max_y
- r
.y
, height
);
2046 XRectangle r_save
= r
;
2048 if (! x_intersect_rectangles (&r_save
, s
->row
->clip
, &r
))
2052 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
2053 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
2055 #ifdef CONVERT_FROM_XRECT
2056 CONVERT_FROM_XRECT (r
, *rects
);
2064 /* If we are processing overlapping and allowed to return
2065 multiple clipping rectangles, we exclude the row of the glyph
2066 string from the clipping rectangle. This is to avoid drawing
2067 the same text on the environment with anti-aliasing. */
2068 #ifdef CONVERT_FROM_XRECT
2071 XRectangle
*rs
= rects
;
2073 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
2075 if (s
->for_overlaps
& OVERLAPS_PRED
)
2078 if (r
.y
+ r
.height
> row_y
)
2081 rs
[i
].height
= row_y
- r
.y
;
2087 if (s
->for_overlaps
& OVERLAPS_SUCC
)
2090 if (r
.y
< row_y
+ s
->row
->visible_height
)
2092 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
2094 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
2095 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
2104 #ifdef CONVERT_FROM_XRECT
2105 for (i
= 0; i
< n
; i
++)
2106 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
2113 Return in *NR the clipping rectangle for glyph string S. */
2116 get_glyph_string_clip_rect (struct glyph_string
*s
, NativeRectangle
*nr
)
2118 get_glyph_string_clip_rects (s
, nr
, 1);
2123 Return the position and height of the phys cursor in window W.
2124 Set w->phys_cursor_width to width of phys cursor.
2128 get_phys_cursor_geometry (struct window
*w
, struct glyph_row
*row
,
2129 struct glyph
*glyph
, int *xp
, int *yp
, int *heightp
)
2131 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2132 int x
, y
, wd
, h
, h0
, y0
;
2134 /* Compute the width of the rectangle to draw. If on a stretch
2135 glyph, and `x-stretch-block-cursor' is nil, don't draw a
2136 rectangle as wide as the glyph, but use a canonical character
2138 wd
= glyph
->pixel_width
- 1;
2139 #if defined (HAVE_NTGUI) || defined (HAVE_NS)
2143 x
= w
->phys_cursor
.x
;
2150 if (glyph
->type
== STRETCH_GLYPH
2151 && !x_stretch_cursor_p
)
2152 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2153 w
->phys_cursor_width
= wd
;
2155 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
2157 /* If y is below window bottom, ensure that we still see a cursor. */
2158 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2160 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
2161 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
2163 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2166 h
= max (h
- (y0
- y
) + 1, h0
);
2171 y0
= window_text_bottom_y (w
) - h0
;
2179 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
2180 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2185 * Remember which glyph the mouse is over.
2189 remember_mouse_glyph (struct frame
*f
, int gx
, int gy
, NativeRectangle
*rect
)
2193 struct glyph_row
*r
, *gr
, *end_row
;
2194 enum window_part part
;
2195 enum glyph_row_area area
;
2196 int x
, y
, width
, height
;
2198 /* Try to determine frame pixel position and size of the glyph under
2199 frame pixel coordinates X/Y on frame F. */
2201 if (!f
->glyphs_initialized_p
2202 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, 0),
2205 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2206 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2210 w
= XWINDOW (window
);
2211 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2212 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2214 x
= window_relative_x_coord (w
, part
, gx
);
2215 y
= gy
- WINDOW_TOP_EDGE_Y (w
);
2217 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2218 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2220 if (w
->pseudo_window_p
)
2223 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2229 case ON_LEFT_MARGIN
:
2230 area
= LEFT_MARGIN_AREA
;
2233 case ON_RIGHT_MARGIN
:
2234 area
= RIGHT_MARGIN_AREA
;
2237 case ON_HEADER_LINE
:
2239 gr
= (part
== ON_HEADER_LINE
2240 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2241 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2244 goto text_glyph_row_found
;
2251 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2252 if (r
->y
+ r
->height
> y
)
2258 text_glyph_row_found
:
2261 struct glyph
*g
= gr
->glyphs
[area
];
2262 struct glyph
*end
= g
+ gr
->used
[area
];
2264 height
= gr
->height
;
2265 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2266 if (gx
+ g
->pixel_width
> x
)
2271 if (g
->type
== IMAGE_GLYPH
)
2273 /* Don't remember when mouse is over image, as
2274 image may have hot-spots. */
2275 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2278 width
= g
->pixel_width
;
2282 /* Use nominal char spacing at end of line. */
2284 gx
+= (x
/ width
) * width
;
2287 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2288 gx
+= window_box_left_offset (w
, area
);
2292 /* Use nominal line height at end of window. */
2293 gx
= (x
/ width
) * width
;
2295 gy
+= (y
/ height
) * height
;
2299 case ON_LEFT_FRINGE
:
2300 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2301 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2302 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2303 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2306 case ON_RIGHT_FRINGE
:
2307 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2308 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2309 : window_box_right_offset (w
, TEXT_AREA
));
2310 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2314 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2316 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2317 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2318 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2320 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2324 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2325 if (r
->y
+ r
->height
> y
)
2332 height
= gr
->height
;
2335 /* Use nominal line height at end of window. */
2337 gy
+= (y
/ height
) * height
;
2344 /* If there is no glyph under the mouse, then we divide the screen
2345 into a grid of the smallest glyph in the frame, and use that
2348 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2349 round down even for negative values. */
2355 gx
= (gx
/ width
) * width
;
2356 gy
= (gy
/ height
) * height
;
2361 gx
+= WINDOW_LEFT_EDGE_X (w
);
2362 gy
+= WINDOW_TOP_EDGE_Y (w
);
2365 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2367 /* Visible feedback for debugging. */
2370 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2371 f
->output_data
.x
->normal_gc
,
2372 gx
, gy
, width
, height
);
2378 #endif /* HAVE_WINDOW_SYSTEM */
2381 /***********************************************************************
2382 Lisp form evaluation
2383 ***********************************************************************/
2385 /* Error handler for safe_eval and safe_call. */
2388 safe_eval_handler (Lisp_Object arg
, ptrdiff_t nargs
, Lisp_Object
*args
)
2390 add_to_log ("Error during redisplay: %S signaled %S",
2391 Flist (nargs
, args
), arg
);
2395 /* Call function FUNC with the rest of NARGS - 1 arguments
2396 following. Return the result, or nil if something went
2397 wrong. Prevent redisplay during the evaluation. */
2400 safe_call (ptrdiff_t nargs
, Lisp_Object func
, ...)
2404 if (inhibit_eval_during_redisplay
)
2410 ptrdiff_t count
= SPECPDL_INDEX ();
2411 struct gcpro gcpro1
;
2412 Lisp_Object
*args
= alloca (nargs
* word_size
);
2415 va_start (ap
, func
);
2416 for (i
= 1; i
< nargs
; i
++)
2417 args
[i
] = va_arg (ap
, Lisp_Object
);
2421 gcpro1
.nvars
= nargs
;
2422 specbind (Qinhibit_redisplay
, Qt
);
2423 /* Use Qt to ensure debugger does not run,
2424 so there is no possibility of wanting to redisplay. */
2425 val
= internal_condition_case_n (Ffuncall
, nargs
, args
, Qt
,
2428 val
= unbind_to (count
, val
);
2435 /* Call function FN with one argument ARG.
2436 Return the result, or nil if something went wrong. */
2439 safe_call1 (Lisp_Object fn
, Lisp_Object arg
)
2441 return safe_call (2, fn
, arg
);
2444 static Lisp_Object Qeval
;
2447 safe_eval (Lisp_Object sexpr
)
2449 return safe_call1 (Qeval
, sexpr
);
2452 /* Call function FN with two arguments ARG1 and ARG2.
2453 Return the result, or nil if something went wrong. */
2456 safe_call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2458 return safe_call (3, fn
, arg1
, arg2
);
2463 /***********************************************************************
2465 ***********************************************************************/
2469 /* Define CHECK_IT to perform sanity checks on iterators.
2470 This is for debugging. It is too slow to do unconditionally. */
2473 check_it (struct it
*it
)
2475 if (it
->method
== GET_FROM_STRING
)
2477 eassert (STRINGP (it
->string
));
2478 eassert (IT_STRING_CHARPOS (*it
) >= 0);
2482 eassert (IT_STRING_CHARPOS (*it
) < 0);
2483 if (it
->method
== GET_FROM_BUFFER
)
2485 /* Check that character and byte positions agree. */
2486 eassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2491 eassert (it
->current
.dpvec_index
>= 0);
2493 eassert (it
->current
.dpvec_index
< 0);
2496 #define CHECK_IT(IT) check_it ((IT))
2500 #define CHECK_IT(IT) (void) 0
2505 #if defined GLYPH_DEBUG && defined ENABLE_CHECKING
2507 /* Check that the window end of window W is what we expect it
2508 to be---the last row in the current matrix displaying text. */
2511 check_window_end (struct window
*w
)
2513 if (!MINI_WINDOW_P (w
) && w
->window_end_valid
)
2515 struct glyph_row
*row
;
2516 eassert ((row
= MATRIX_ROW (w
->current_matrix
,
2517 XFASTINT (w
->window_end_vpos
)),
2519 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2520 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2524 #define CHECK_WINDOW_END(W) check_window_end ((W))
2528 #define CHECK_WINDOW_END(W) (void) 0
2530 #endif /* GLYPH_DEBUG and ENABLE_CHECKING */
2532 /* Return mark position if current buffer has the region of non-zero length,
2536 markpos_of_region (void)
2538 if (!NILP (Vtransient_mark_mode
)
2539 && !NILP (BVAR (current_buffer
, mark_active
))
2540 && XMARKER (BVAR (current_buffer
, mark
))->buffer
!= NULL
)
2542 ptrdiff_t markpos
= XMARKER (BVAR (current_buffer
, mark
))->charpos
;
2550 /***********************************************************************
2551 Iterator initialization
2552 ***********************************************************************/
2554 /* Initialize IT for displaying current_buffer in window W, starting
2555 at character position CHARPOS. CHARPOS < 0 means that no buffer
2556 position is specified which is useful when the iterator is assigned
2557 a position later. BYTEPOS is the byte position corresponding to
2558 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2560 If ROW is not null, calls to produce_glyphs with IT as parameter
2561 will produce glyphs in that row.
2563 BASE_FACE_ID is the id of a base face to use. It must be one of
2564 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2565 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2566 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2568 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2569 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2570 will be initialized to use the corresponding mode line glyph row of
2571 the desired matrix of W. */
2574 init_iterator (struct it
*it
, struct window
*w
,
2575 ptrdiff_t charpos
, ptrdiff_t bytepos
,
2576 struct glyph_row
*row
, enum face_id base_face_id
)
2579 enum face_id remapped_base_face_id
= base_face_id
;
2581 /* Some precondition checks. */
2582 eassert (w
!= NULL
&& it
!= NULL
);
2583 eassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2586 /* If face attributes have been changed since the last redisplay,
2587 free realized faces now because they depend on face definitions
2588 that might have changed. Don't free faces while there might be
2589 desired matrices pending which reference these faces. */
2590 if (face_change_count
&& !inhibit_free_realized_faces
)
2592 face_change_count
= 0;
2593 free_all_realized_faces (Qnil
);
2596 /* Perhaps remap BASE_FACE_ID to a user-specified alternative. */
2597 if (! NILP (Vface_remapping_alist
))
2598 remapped_base_face_id
2599 = lookup_basic_face (XFRAME (w
->frame
), base_face_id
);
2601 /* Use one of the mode line rows of W's desired matrix if
2605 if (base_face_id
== MODE_LINE_FACE_ID
2606 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2607 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2608 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2609 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2613 memset (it
, 0, sizeof *it
);
2614 it
->current
.overlay_string_index
= -1;
2615 it
->current
.dpvec_index
= -1;
2616 it
->base_face_id
= remapped_base_face_id
;
2618 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2619 it
->paragraph_embedding
= L2R
;
2620 it
->bidi_it
.string
.lstring
= Qnil
;
2621 it
->bidi_it
.string
.s
= NULL
;
2622 it
->bidi_it
.string
.bufpos
= 0;
2624 /* The window in which we iterate over current_buffer: */
2625 XSETWINDOW (it
->window
, w
);
2627 it
->f
= XFRAME (w
->frame
);
2631 /* Extra space between lines (on window systems only). */
2632 if (base_face_id
== DEFAULT_FACE_ID
2633 && FRAME_WINDOW_P (it
->f
))
2635 if (NATNUMP (BVAR (current_buffer
, extra_line_spacing
)))
2636 it
->extra_line_spacing
= XFASTINT (BVAR (current_buffer
, extra_line_spacing
));
2637 else if (FLOATP (BVAR (current_buffer
, extra_line_spacing
)))
2638 it
->extra_line_spacing
= (XFLOAT_DATA (BVAR (current_buffer
, extra_line_spacing
))
2639 * FRAME_LINE_HEIGHT (it
->f
));
2640 else if (it
->f
->extra_line_spacing
> 0)
2641 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2642 it
->max_extra_line_spacing
= 0;
2645 /* If realized faces have been removed, e.g. because of face
2646 attribute changes of named faces, recompute them. When running
2647 in batch mode, the face cache of the initial frame is null. If
2648 we happen to get called, make a dummy face cache. */
2649 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2650 init_frame_faces (it
->f
);
2651 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2652 recompute_basic_faces (it
->f
);
2654 /* Current value of the `slice', `space-width', and 'height' properties. */
2655 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2656 it
->space_width
= Qnil
;
2657 it
->font_height
= Qnil
;
2658 it
->override_ascent
= -1;
2660 /* Are control characters displayed as `^C'? */
2661 it
->ctl_arrow_p
= !NILP (BVAR (current_buffer
, ctl_arrow
));
2663 /* -1 means everything between a CR and the following line end
2664 is invisible. >0 means lines indented more than this value are
2666 it
->selective
= (INTEGERP (BVAR (current_buffer
, selective_display
))
2668 (-1, XINT (BVAR (current_buffer
, selective_display
)),
2670 : (!NILP (BVAR (current_buffer
, selective_display
))
2672 it
->selective_display_ellipsis_p
2673 = !NILP (BVAR (current_buffer
, selective_display_ellipses
));
2675 /* Display table to use. */
2676 it
->dp
= window_display_table (w
);
2678 /* Are multibyte characters enabled in current_buffer? */
2679 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
2681 /* If visible region is of non-zero length, set IT->region_beg_charpos
2682 and IT->region_end_charpos to the start and end of a visible region
2683 in window IT->w. Set both to -1 to indicate no region. */
2684 markpos
= markpos_of_region ();
2686 /* Maybe highlight only in selected window. */
2687 && (/* Either show region everywhere. */
2688 highlight_nonselected_windows
2689 /* Or show region in the selected window. */
2690 || w
== XWINDOW (selected_window
)
2691 /* Or show the region if we are in the mini-buffer and W is
2692 the window the mini-buffer refers to. */
2693 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2694 && WINDOWP (minibuf_selected_window
)
2695 && w
== XWINDOW (minibuf_selected_window
))))
2697 it
->region_beg_charpos
= min (PT
, markpos
);
2698 it
->region_end_charpos
= max (PT
, markpos
);
2701 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2703 /* Get the position at which the redisplay_end_trigger hook should
2704 be run, if it is to be run at all. */
2705 if (MARKERP (w
->redisplay_end_trigger
)
2706 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2707 it
->redisplay_end_trigger_charpos
2708 = marker_position (w
->redisplay_end_trigger
);
2709 else if (INTEGERP (w
->redisplay_end_trigger
))
2710 it
->redisplay_end_trigger_charpos
=
2711 clip_to_bounds (PTRDIFF_MIN
, XINT (w
->redisplay_end_trigger
), PTRDIFF_MAX
);
2713 it
->tab_width
= SANE_TAB_WIDTH (current_buffer
);
2715 /* Are lines in the display truncated? */
2716 if (base_face_id
!= DEFAULT_FACE_ID
2718 || (! WINDOW_FULL_WIDTH_P (it
->w
)
2719 && ((!NILP (Vtruncate_partial_width_windows
)
2720 && !INTEGERP (Vtruncate_partial_width_windows
))
2721 || (INTEGERP (Vtruncate_partial_width_windows
)
2722 && (WINDOW_TOTAL_COLS (it
->w
)
2723 < XINT (Vtruncate_partial_width_windows
))))))
2724 it
->line_wrap
= TRUNCATE
;
2725 else if (NILP (BVAR (current_buffer
, truncate_lines
)))
2726 it
->line_wrap
= NILP (BVAR (current_buffer
, word_wrap
))
2727 ? WINDOW_WRAP
: WORD_WRAP
;
2729 it
->line_wrap
= TRUNCATE
;
2731 /* Get dimensions of truncation and continuation glyphs. These are
2732 displayed as fringe bitmaps under X, but we need them for such
2733 frames when the fringes are turned off. But leave the dimensions
2734 zero for tooltip frames, as these glyphs look ugly there and also
2735 sabotage calculations of tooltip dimensions in x-show-tip. */
2736 #ifdef HAVE_WINDOW_SYSTEM
2737 if (!(FRAME_WINDOW_P (it
->f
)
2738 && FRAMEP (tip_frame
)
2739 && it
->f
== XFRAME (tip_frame
)))
2742 if (it
->line_wrap
== TRUNCATE
)
2744 /* We will need the truncation glyph. */
2745 eassert (it
->glyph_row
== NULL
);
2746 produce_special_glyphs (it
, IT_TRUNCATION
);
2747 it
->truncation_pixel_width
= it
->pixel_width
;
2751 /* We will need the continuation glyph. */
2752 eassert (it
->glyph_row
== NULL
);
2753 produce_special_glyphs (it
, IT_CONTINUATION
);
2754 it
->continuation_pixel_width
= it
->pixel_width
;
2758 /* Reset these values to zero because the produce_special_glyphs
2759 above has changed them. */
2760 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2761 it
->phys_ascent
= it
->phys_descent
= 0;
2763 /* Set this after getting the dimensions of truncation and
2764 continuation glyphs, so that we don't produce glyphs when calling
2765 produce_special_glyphs, above. */
2766 it
->glyph_row
= row
;
2767 it
->area
= TEXT_AREA
;
2769 /* Forget any previous info about this row being reversed. */
2771 it
->glyph_row
->reversed_p
= 0;
2773 /* Get the dimensions of the display area. The display area
2774 consists of the visible window area plus a horizontally scrolled
2775 part to the left of the window. All x-values are relative to the
2776 start of this total display area. */
2777 if (base_face_id
!= DEFAULT_FACE_ID
)
2779 /* Mode lines, menu bar in terminal frames. */
2780 it
->first_visible_x
= 0;
2781 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2785 it
->first_visible_x
=
2786 window_hscroll_limited (it
->w
, it
->f
) * FRAME_COLUMN_WIDTH (it
->f
);
2787 it
->last_visible_x
= (it
->first_visible_x
2788 + window_box_width (w
, TEXT_AREA
));
2790 /* If we truncate lines, leave room for the truncation glyph(s) at
2791 the right margin. Otherwise, leave room for the continuation
2792 glyph(s). Done only if the window has no fringes. Since we
2793 don't know at this point whether there will be any R2L lines in
2794 the window, we reserve space for truncation/continuation glyphs
2795 even if only one of the fringes is absent. */
2796 if (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0
2797 || (it
->bidi_p
&& WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0))
2799 if (it
->line_wrap
== TRUNCATE
)
2800 it
->last_visible_x
-= it
->truncation_pixel_width
;
2802 it
->last_visible_x
-= it
->continuation_pixel_width
;
2805 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2806 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2809 /* Leave room for a border glyph. */
2810 if (!FRAME_WINDOW_P (it
->f
)
2811 && !WINDOW_RIGHTMOST_P (it
->w
))
2812 it
->last_visible_x
-= 1;
2814 it
->last_visible_y
= window_text_bottom_y (w
);
2816 /* For mode lines and alike, arrange for the first glyph having a
2817 left box line if the face specifies a box. */
2818 if (base_face_id
!= DEFAULT_FACE_ID
)
2822 it
->face_id
= remapped_base_face_id
;
2824 /* If we have a boxed mode line, make the first character appear
2825 with a left box line. */
2826 face
= FACE_FROM_ID (it
->f
, remapped_base_face_id
);
2827 if (face
->box
!= FACE_NO_BOX
)
2828 it
->start_of_box_run_p
= 1;
2831 /* If a buffer position was specified, set the iterator there,
2832 getting overlays and face properties from that position. */
2833 if (charpos
>= BUF_BEG (current_buffer
))
2835 it
->end_charpos
= ZV
;
2836 IT_CHARPOS (*it
) = charpos
;
2838 /* We will rely on `reseat' to set this up properly, via
2839 handle_face_prop. */
2840 it
->face_id
= it
->base_face_id
;
2842 /* Compute byte position if not specified. */
2843 if (bytepos
< charpos
)
2844 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2846 IT_BYTEPOS (*it
) = bytepos
;
2848 it
->start
= it
->current
;
2849 /* Do we need to reorder bidirectional text? Not if this is a
2850 unibyte buffer: by definition, none of the single-byte
2851 characters are strong R2L, so no reordering is needed. And
2852 bidi.c doesn't support unibyte buffers anyway. Also, don't
2853 reorder while we are loading loadup.el, since the tables of
2854 character properties needed for reordering are not yet
2858 && !NILP (BVAR (current_buffer
, bidi_display_reordering
))
2861 /* If we are to reorder bidirectional text, init the bidi
2865 /* Note the paragraph direction that this buffer wants to
2867 if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2869 it
->paragraph_embedding
= L2R
;
2870 else if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2872 it
->paragraph_embedding
= R2L
;
2874 it
->paragraph_embedding
= NEUTRAL_DIR
;
2875 bidi_unshelve_cache (NULL
, 0);
2876 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
2880 /* Compute faces etc. */
2881 reseat (it
, it
->current
.pos
, 1);
2888 /* Initialize IT for the display of window W with window start POS. */
2891 start_display (struct it
*it
, struct window
*w
, struct text_pos pos
)
2893 struct glyph_row
*row
;
2894 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2896 row
= w
->desired_matrix
->rows
+ first_vpos
;
2897 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2898 it
->first_vpos
= first_vpos
;
2900 /* Don't reseat to previous visible line start if current start
2901 position is in a string or image. */
2902 if (it
->method
== GET_FROM_BUFFER
&& it
->line_wrap
!= TRUNCATE
)
2904 int start_at_line_beg_p
;
2905 int first_y
= it
->current_y
;
2907 /* If window start is not at a line start, skip forward to POS to
2908 get the correct continuation lines width. */
2909 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2910 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2911 if (!start_at_line_beg_p
)
2915 reseat_at_previous_visible_line_start (it
);
2916 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2918 new_x
= it
->current_x
+ it
->pixel_width
;
2920 /* If lines are continued, this line may end in the middle
2921 of a multi-glyph character (e.g. a control character
2922 displayed as \003, or in the middle of an overlay
2923 string). In this case move_it_to above will not have
2924 taken us to the start of the continuation line but to the
2925 end of the continued line. */
2926 if (it
->current_x
> 0
2927 && it
->line_wrap
!= TRUNCATE
/* Lines are continued. */
2928 && (/* And glyph doesn't fit on the line. */
2929 new_x
> it
->last_visible_x
2930 /* Or it fits exactly and we're on a window
2932 || (new_x
== it
->last_visible_x
2933 && FRAME_WINDOW_P (it
->f
)
2934 && ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
2935 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
2936 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
2938 if ((it
->current
.dpvec_index
>= 0
2939 || it
->current
.overlay_string_index
>= 0)
2940 /* If we are on a newline from a display vector or
2941 overlay string, then we are already at the end of
2942 a screen line; no need to go to the next line in
2943 that case, as this line is not really continued.
2944 (If we do go to the next line, C-e will not DTRT.) */
2947 set_iterator_to_next (it
, 1);
2948 move_it_in_display_line_to (it
, -1, -1, 0);
2951 it
->continuation_lines_width
+= it
->current_x
;
2953 /* If the character at POS is displayed via a display
2954 vector, move_it_to above stops at the final glyph of
2955 IT->dpvec. To make the caller redisplay that character
2956 again (a.k.a. start at POS), we need to reset the
2957 dpvec_index to the beginning of IT->dpvec. */
2958 else if (it
->current
.dpvec_index
>= 0)
2959 it
->current
.dpvec_index
= 0;
2961 /* We're starting a new display line, not affected by the
2962 height of the continued line, so clear the appropriate
2963 fields in the iterator structure. */
2964 it
->max_ascent
= it
->max_descent
= 0;
2965 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2967 it
->current_y
= first_y
;
2969 it
->current_x
= it
->hpos
= 0;
2975 /* Return 1 if POS is a position in ellipses displayed for invisible
2976 text. W is the window we display, for text property lookup. */
2979 in_ellipses_for_invisible_text_p (struct display_pos
*pos
, struct window
*w
)
2981 Lisp_Object prop
, window
;
2983 ptrdiff_t charpos
= CHARPOS (pos
->pos
);
2985 /* If POS specifies a position in a display vector, this might
2986 be for an ellipsis displayed for invisible text. We won't
2987 get the iterator set up for delivering that ellipsis unless
2988 we make sure that it gets aware of the invisible text. */
2989 if (pos
->dpvec_index
>= 0
2990 && pos
->overlay_string_index
< 0
2991 && CHARPOS (pos
->string_pos
) < 0
2993 && (XSETWINDOW (window
, w
),
2994 prop
= Fget_char_property (make_number (charpos
),
2995 Qinvisible
, window
),
2996 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2998 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
3000 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
3007 /* Initialize IT for stepping through current_buffer in window W,
3008 starting at position POS that includes overlay string and display
3009 vector/ control character translation position information. Value
3010 is zero if there are overlay strings with newlines at POS. */
3013 init_from_display_pos (struct it
*it
, struct window
*w
, struct display_pos
*pos
)
3015 ptrdiff_t charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
3016 int i
, overlay_strings_with_newlines
= 0;
3018 /* If POS specifies a position in a display vector, this might
3019 be for an ellipsis displayed for invisible text. We won't
3020 get the iterator set up for delivering that ellipsis unless
3021 we make sure that it gets aware of the invisible text. */
3022 if (in_ellipses_for_invisible_text_p (pos
, w
))
3028 /* Keep in mind: the call to reseat in init_iterator skips invisible
3029 text, so we might end up at a position different from POS. This
3030 is only a problem when POS is a row start after a newline and an
3031 overlay starts there with an after-string, and the overlay has an
3032 invisible property. Since we don't skip invisible text in
3033 display_line and elsewhere immediately after consuming the
3034 newline before the row start, such a POS will not be in a string,
3035 but the call to init_iterator below will move us to the
3037 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
3039 /* This only scans the current chunk -- it should scan all chunks.
3040 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
3041 to 16 in 22.1 to make this a lesser problem. */
3042 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
3044 const char *s
= SSDATA (it
->overlay_strings
[i
]);
3045 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
3047 while (s
< e
&& *s
!= '\n')
3052 overlay_strings_with_newlines
= 1;
3057 /* If position is within an overlay string, set up IT to the right
3059 if (pos
->overlay_string_index
>= 0)
3063 /* If the first overlay string happens to have a `display'
3064 property for an image, the iterator will be set up for that
3065 image, and we have to undo that setup first before we can
3066 correct the overlay string index. */
3067 if (it
->method
== GET_FROM_IMAGE
)
3070 /* We already have the first chunk of overlay strings in
3071 IT->overlay_strings. Load more until the one for
3072 pos->overlay_string_index is in IT->overlay_strings. */
3073 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
3075 ptrdiff_t n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
3076 it
->current
.overlay_string_index
= 0;
3079 load_overlay_strings (it
, 0);
3080 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
3084 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
3085 relative_index
= (it
->current
.overlay_string_index
3086 % OVERLAY_STRING_CHUNK_SIZE
);
3087 it
->string
= it
->overlay_strings
[relative_index
];
3088 eassert (STRINGP (it
->string
));
3089 it
->current
.string_pos
= pos
->string_pos
;
3090 it
->method
= GET_FROM_STRING
;
3091 it
->end_charpos
= SCHARS (it
->string
);
3092 /* Set up the bidi iterator for this overlay string. */
3095 it
->bidi_it
.string
.lstring
= it
->string
;
3096 it
->bidi_it
.string
.s
= NULL
;
3097 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
3098 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
3099 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
3100 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
3101 bidi_init_it (IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
),
3102 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
3104 /* Synchronize the state of the bidi iterator with
3105 pos->string_pos. For any string position other than
3106 zero, this will be done automagically when we resume
3107 iteration over the string and get_visually_first_element
3108 is called. But if string_pos is zero, and the string is
3109 to be reordered for display, we need to resync manually,
3110 since it could be that the iteration state recorded in
3111 pos ended at string_pos of 0 moving backwards in string. */
3112 if (CHARPOS (pos
->string_pos
) == 0)
3114 get_visually_first_element (it
);
3115 if (IT_STRING_CHARPOS (*it
) != 0)
3118 eassert (it
->bidi_it
.charpos
< it
->bidi_it
.string
.schars
);
3119 bidi_move_to_visually_next (&it
->bidi_it
);
3120 } while (it
->bidi_it
.charpos
!= 0);
3122 eassert (IT_STRING_CHARPOS (*it
) == it
->bidi_it
.charpos
3123 && IT_STRING_BYTEPOS (*it
) == it
->bidi_it
.bytepos
);
3127 if (CHARPOS (pos
->string_pos
) >= 0)
3129 /* Recorded position is not in an overlay string, but in another
3130 string. This can only be a string from a `display' property.
3131 IT should already be filled with that string. */
3132 it
->current
.string_pos
= pos
->string_pos
;
3133 eassert (STRINGP (it
->string
));
3135 bidi_init_it (IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
),
3136 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
3139 /* Restore position in display vector translations, control
3140 character translations or ellipses. */
3141 if (pos
->dpvec_index
>= 0)
3143 if (it
->dpvec
== NULL
)
3144 get_next_display_element (it
);
3145 eassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
3146 it
->current
.dpvec_index
= pos
->dpvec_index
;
3150 return !overlay_strings_with_newlines
;
3154 /* Initialize IT for stepping through current_buffer in window W
3155 starting at ROW->start. */
3158 init_to_row_start (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3160 init_from_display_pos (it
, w
, &row
->start
);
3161 it
->start
= row
->start
;
3162 it
->continuation_lines_width
= row
->continuation_lines_width
;
3167 /* Initialize IT for stepping through current_buffer in window W
3168 starting in the line following ROW, i.e. starting at ROW->end.
3169 Value is zero if there are overlay strings with newlines at ROW's
3173 init_to_row_end (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3177 if (init_from_display_pos (it
, w
, &row
->end
))
3179 if (row
->continued_p
)
3180 it
->continuation_lines_width
3181 = row
->continuation_lines_width
+ row
->pixel_width
;
3192 /***********************************************************************
3194 ***********************************************************************/
3196 /* Called when IT reaches IT->stop_charpos. Handle text property and
3197 overlay changes. Set IT->stop_charpos to the next position where
3201 handle_stop (struct it
*it
)
3203 enum prop_handled handled
;
3204 int handle_overlay_change_p
;
3208 it
->current
.dpvec_index
= -1;
3209 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3210 it
->ignore_overlay_strings_at_pos_p
= 0;
3213 /* Use face of preceding text for ellipsis (if invisible) */
3214 if (it
->selective_display_ellipsis_p
)
3215 it
->saved_face_id
= it
->face_id
;
3219 handled
= HANDLED_NORMALLY
;
3221 /* Call text property handlers. */
3222 for (p
= it_props
; p
->handler
; ++p
)
3224 handled
= p
->handler (it
);
3226 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3228 else if (handled
== HANDLED_RETURN
)
3230 /* We still want to show before and after strings from
3231 overlays even if the actual buffer text is replaced. */
3232 if (!handle_overlay_change_p
3234 /* Don't call get_overlay_strings_1 if we already
3235 have overlay strings loaded, because doing so
3236 will load them again and push the iterator state
3237 onto the stack one more time, which is not
3238 expected by the rest of the code that processes
3240 || (it
->current
.overlay_string_index
< 0
3241 ? !get_overlay_strings_1 (it
, 0, 0)
3245 setup_for_ellipsis (it
, 0);
3246 /* When handling a display spec, we might load an
3247 empty string. In that case, discard it here. We
3248 used to discard it in handle_single_display_spec,
3249 but that causes get_overlay_strings_1, above, to
3250 ignore overlay strings that we must check. */
3251 if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3255 else if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3259 it
->ignore_overlay_strings_at_pos_p
= 1;
3260 it
->string_from_display_prop_p
= 0;
3261 it
->from_disp_prop_p
= 0;
3262 handle_overlay_change_p
= 0;
3264 handled
= HANDLED_RECOMPUTE_PROPS
;
3267 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3268 handle_overlay_change_p
= 0;
3271 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3273 /* Don't check for overlay strings below when set to deliver
3274 characters from a display vector. */
3275 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3276 handle_overlay_change_p
= 0;
3278 /* Handle overlay changes.
3279 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
3280 if it finds overlays. */
3281 if (handle_overlay_change_p
)
3282 handled
= handle_overlay_change (it
);
3287 setup_for_ellipsis (it
, 0);
3291 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3293 /* Determine where to stop next. */
3294 if (handled
== HANDLED_NORMALLY
)
3295 compute_stop_pos (it
);
3299 /* Compute IT->stop_charpos from text property and overlay change
3300 information for IT's current position. */
3303 compute_stop_pos (struct it
*it
)
3305 register INTERVAL iv
, next_iv
;
3306 Lisp_Object object
, limit
, position
;
3307 ptrdiff_t charpos
, bytepos
;
3309 if (STRINGP (it
->string
))
3311 /* Strings are usually short, so don't limit the search for
3313 it
->stop_charpos
= it
->end_charpos
;
3314 object
= it
->string
;
3316 charpos
= IT_STRING_CHARPOS (*it
);
3317 bytepos
= IT_STRING_BYTEPOS (*it
);
3323 /* If end_charpos is out of range for some reason, such as a
3324 misbehaving display function, rationalize it (Bug#5984). */
3325 if (it
->end_charpos
> ZV
)
3326 it
->end_charpos
= ZV
;
3327 it
->stop_charpos
= it
->end_charpos
;
3329 /* If next overlay change is in front of the current stop pos
3330 (which is IT->end_charpos), stop there. Note: value of
3331 next_overlay_change is point-max if no overlay change
3333 charpos
= IT_CHARPOS (*it
);
3334 bytepos
= IT_BYTEPOS (*it
);
3335 pos
= next_overlay_change (charpos
);
3336 if (pos
< it
->stop_charpos
)
3337 it
->stop_charpos
= pos
;
3339 /* If showing the region, we have to stop at the region
3340 start or end because the face might change there. */
3341 if (it
->region_beg_charpos
> 0)
3343 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
3344 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
3345 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
3346 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3349 /* Set up variables for computing the stop position from text
3350 property changes. */
3351 XSETBUFFER (object
, current_buffer
);
3352 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3355 /* Get the interval containing IT's position. Value is a null
3356 interval if there isn't such an interval. */
3357 position
= make_number (charpos
);
3358 iv
= validate_interval_range (object
, &position
, &position
, 0);
3361 Lisp_Object values_here
[LAST_PROP_IDX
];
3364 /* Get properties here. */
3365 for (p
= it_props
; p
->handler
; ++p
)
3366 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3368 /* Look for an interval following iv that has different
3370 for (next_iv
= next_interval (iv
);
3373 || XFASTINT (limit
) > next_iv
->position
));
3374 next_iv
= next_interval (next_iv
))
3376 for (p
= it_props
; p
->handler
; ++p
)
3378 Lisp_Object new_value
;
3380 new_value
= textget (next_iv
->plist
, *p
->name
);
3381 if (!EQ (values_here
[p
->idx
], new_value
))
3391 if (INTEGERP (limit
)
3392 && next_iv
->position
>= XFASTINT (limit
))
3393 /* No text property change up to limit. */
3394 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3396 /* Text properties change in next_iv. */
3397 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3401 if (it
->cmp_it
.id
< 0)
3403 ptrdiff_t stoppos
= it
->end_charpos
;
3405 if (it
->bidi_p
&& it
->bidi_it
.scan_dir
< 0)
3407 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
,
3408 stoppos
, it
->string
);
3411 eassert (STRINGP (it
->string
)
3412 || (it
->stop_charpos
>= BEGV
3413 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3417 /* Return the position of the next overlay change after POS in
3418 current_buffer. Value is point-max if no overlay change
3419 follows. This is like `next-overlay-change' but doesn't use
3423 next_overlay_change (ptrdiff_t pos
)
3425 ptrdiff_t i
, noverlays
;
3427 Lisp_Object
*overlays
;
3429 /* Get all overlays at the given position. */
3430 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3432 /* If any of these overlays ends before endpos,
3433 use its ending point instead. */
3434 for (i
= 0; i
< noverlays
; ++i
)
3439 oend
= OVERLAY_END (overlays
[i
]);
3440 oendpos
= OVERLAY_POSITION (oend
);
3441 endpos
= min (endpos
, oendpos
);
3447 /* How many characters forward to search for a display property or
3448 display string. Searching too far forward makes the bidi display
3449 sluggish, especially in small windows. */
3450 #define MAX_DISP_SCAN 250
3452 /* Return the character position of a display string at or after
3453 position specified by POSITION. If no display string exists at or
3454 after POSITION, return ZV. A display string is either an overlay
3455 with `display' property whose value is a string, or a `display'
3456 text property whose value is a string. STRING is data about the
3457 string to iterate; if STRING->lstring is nil, we are iterating a
3458 buffer. FRAME_WINDOW_P is non-zero when we are displaying a window
3459 on a GUI frame. DISP_PROP is set to zero if we searched
3460 MAX_DISP_SCAN characters forward without finding any display
3461 strings, non-zero otherwise. It is set to 2 if the display string
3462 uses any kind of `(space ...)' spec that will produce a stretch of
3463 white space in the text area. */
3465 compute_display_string_pos (struct text_pos
*position
,
3466 struct bidi_string_data
*string
,
3467 int frame_window_p
, int *disp_prop
)
3469 /* OBJECT = nil means current buffer. */
3470 Lisp_Object object
=
3471 (string
&& STRINGP (string
->lstring
)) ? string
->lstring
: Qnil
;
3472 Lisp_Object pos
, spec
, limpos
;
3473 int string_p
= (string
&& (STRINGP (string
->lstring
) || string
->s
));
3474 ptrdiff_t eob
= string_p
? string
->schars
: ZV
;
3475 ptrdiff_t begb
= string_p
? 0 : BEGV
;
3476 ptrdiff_t bufpos
, charpos
= CHARPOS (*position
);
3478 (charpos
< eob
- MAX_DISP_SCAN
) ? charpos
+ MAX_DISP_SCAN
: eob
;
3479 struct text_pos tpos
;
3485 /* We don't support display properties whose values are strings
3486 that have display string properties. */
3487 || string
->from_disp_str
3488 /* C strings cannot have display properties. */
3489 || (string
->s
&& !STRINGP (object
)))
3495 /* If the character at CHARPOS is where the display string begins,
3497 pos
= make_number (charpos
);
3498 if (STRINGP (object
))
3499 bufpos
= string
->bufpos
;
3503 if (!NILP (spec
= Fget_char_property (pos
, Qdisplay
, object
))
3505 || !EQ (Fget_char_property (make_number (charpos
- 1), Qdisplay
,
3508 && (rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
, bufpos
,
3516 /* Look forward for the first character with a `display' property
3517 that will replace the underlying text when displayed. */
3518 limpos
= make_number (lim
);
3520 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, limpos
);
3521 CHARPOS (tpos
) = XFASTINT (pos
);
3522 if (CHARPOS (tpos
) >= lim
)
3527 if (STRINGP (object
))
3528 BYTEPOS (tpos
) = string_char_to_byte (object
, CHARPOS (tpos
));
3530 BYTEPOS (tpos
) = CHAR_TO_BYTE (CHARPOS (tpos
));
3531 spec
= Fget_char_property (pos
, Qdisplay
, object
);
3532 if (!STRINGP (object
))
3533 bufpos
= CHARPOS (tpos
);
3534 } while (NILP (spec
)
3535 || !(rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
,
3536 bufpos
, frame_window_p
)));
3540 return CHARPOS (tpos
);
3543 /* Return the character position of the end of the display string that
3544 started at CHARPOS. If there's no display string at CHARPOS,
3545 return -1. A display string is either an overlay with `display'
3546 property whose value is a string or a `display' text property whose
3547 value is a string. */
3549 compute_display_string_end (ptrdiff_t charpos
, struct bidi_string_data
*string
)
3551 /* OBJECT = nil means current buffer. */
3552 Lisp_Object object
=
3553 (string
&& STRINGP (string
->lstring
)) ? string
->lstring
: Qnil
;
3554 Lisp_Object pos
= make_number (charpos
);
3556 (STRINGP (object
) || (string
&& string
->s
)) ? string
->schars
: ZV
;
3558 if (charpos
>= eob
|| (string
->s
&& !STRINGP (object
)))
3561 /* It could happen that the display property or overlay was removed
3562 since we found it in compute_display_string_pos above. One way
3563 this can happen is if JIT font-lock was called (through
3564 handle_fontified_prop), and jit-lock-functions remove text
3565 properties or overlays from the portion of buffer that includes
3566 CHARPOS. Muse mode is known to do that, for example. In this
3567 case, we return -1 to the caller, to signal that no display
3568 string is actually present at CHARPOS. See bidi_fetch_char for
3569 how this is handled.
3571 An alternative would be to never look for display properties past
3572 it->stop_charpos. But neither compute_display_string_pos nor
3573 bidi_fetch_char that calls it know or care where the next
3575 if (NILP (Fget_char_property (pos
, Qdisplay
, object
)))
3578 /* Look forward for the first character where the `display' property
3580 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, Qnil
);
3582 return XFASTINT (pos
);
3587 /***********************************************************************
3589 ***********************************************************************/
3591 /* Handle changes in the `fontified' property of the current buffer by
3592 calling hook functions from Qfontification_functions to fontify
3595 static enum prop_handled
3596 handle_fontified_prop (struct it
*it
)
3598 Lisp_Object prop
, pos
;
3599 enum prop_handled handled
= HANDLED_NORMALLY
;
3601 if (!NILP (Vmemory_full
))
3604 /* Get the value of the `fontified' property at IT's current buffer
3605 position. (The `fontified' property doesn't have a special
3606 meaning in strings.) If the value is nil, call functions from
3607 Qfontification_functions. */
3608 if (!STRINGP (it
->string
)
3610 && !NILP (Vfontification_functions
)
3611 && !NILP (Vrun_hooks
)
3612 && (pos
= make_number (IT_CHARPOS (*it
)),
3613 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3614 /* Ignore the special cased nil value always present at EOB since
3615 no amount of fontifying will be able to change it. */
3616 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3618 ptrdiff_t count
= SPECPDL_INDEX ();
3620 struct buffer
*obuf
= current_buffer
;
3621 int begv
= BEGV
, zv
= ZV
;
3622 int old_clip_changed
= current_buffer
->clip_changed
;
3624 val
= Vfontification_functions
;
3625 specbind (Qfontification_functions
, Qnil
);
3627 eassert (it
->end_charpos
== ZV
);
3629 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3630 safe_call1 (val
, pos
);
3633 Lisp_Object fns
, fn
;
3634 struct gcpro gcpro1
, gcpro2
;
3639 for (; CONSP (val
); val
= XCDR (val
))
3645 /* A value of t indicates this hook has a local
3646 binding; it means to run the global binding too.
3647 In a global value, t should not occur. If it
3648 does, we must ignore it to avoid an endless
3650 for (fns
= Fdefault_value (Qfontification_functions
);
3656 safe_call1 (fn
, pos
);
3660 safe_call1 (fn
, pos
);
3666 unbind_to (count
, Qnil
);
3668 /* Fontification functions routinely call `save-restriction'.
3669 Normally, this tags clip_changed, which can confuse redisplay
3670 (see discussion in Bug#6671). Since we don't perform any
3671 special handling of fontification changes in the case where
3672 `save-restriction' isn't called, there's no point doing so in
3673 this case either. So, if the buffer's restrictions are
3674 actually left unchanged, reset clip_changed. */
3675 if (obuf
== current_buffer
)
3677 if (begv
== BEGV
&& zv
== ZV
)
3678 current_buffer
->clip_changed
= old_clip_changed
;
3680 /* There isn't much we can reasonably do to protect against
3681 misbehaving fontification, but here's a fig leaf. */
3682 else if (BUFFER_LIVE_P (obuf
))
3683 set_buffer_internal_1 (obuf
);
3685 /* The fontification code may have added/removed text.
3686 It could do even a lot worse, but let's at least protect against
3687 the most obvious case where only the text past `pos' gets changed',
3688 as is/was done in grep.el where some escapes sequences are turned
3689 into face properties (bug#7876). */
3690 it
->end_charpos
= ZV
;
3692 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3693 something. This avoids an endless loop if they failed to
3694 fontify the text for which reason ever. */
3695 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3696 handled
= HANDLED_RECOMPUTE_PROPS
;
3704 /***********************************************************************
3706 ***********************************************************************/
3708 /* Set up iterator IT from face properties at its current position.
3709 Called from handle_stop. */
3711 static enum prop_handled
3712 handle_face_prop (struct it
*it
)
3715 ptrdiff_t next_stop
;
3717 if (!STRINGP (it
->string
))
3720 = face_at_buffer_position (it
->w
,
3722 it
->region_beg_charpos
,
3723 it
->region_end_charpos
,
3726 + TEXT_PROP_DISTANCE_LIMIT
),
3727 0, it
->base_face_id
);
3729 /* Is this a start of a run of characters with box face?
3730 Caveat: this can be called for a freshly initialized
3731 iterator; face_id is -1 in this case. We know that the new
3732 face will not change until limit, i.e. if the new face has a
3733 box, all characters up to limit will have one. But, as
3734 usual, we don't know whether limit is really the end. */
3735 if (new_face_id
!= it
->face_id
)
3737 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3738 /* If it->face_id is -1, old_face below will be NULL, see
3739 the definition of FACE_FROM_ID. This will happen if this
3740 is the initial call that gets the face. */
3741 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3743 /* If the value of face_id of the iterator is -1, we have to
3744 look in front of IT's position and see whether there is a
3745 face there that's different from new_face_id. */
3746 if (!old_face
&& IT_CHARPOS (*it
) > BEG
)
3748 int prev_face_id
= face_before_it_pos (it
);
3750 old_face
= FACE_FROM_ID (it
->f
, prev_face_id
);
3753 /* If the new face has a box, but the old face does not,
3754 this is the start of a run of characters with box face,
3755 i.e. this character has a shadow on the left side. */
3756 it
->start_of_box_run_p
= (new_face
->box
!= FACE_NO_BOX
3757 && (old_face
== NULL
|| !old_face
->box
));
3758 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3766 Lisp_Object from_overlay
3767 = (it
->current
.overlay_string_index
>= 0
3768 ? it
->string_overlays
[it
->current
.overlay_string_index
3769 % OVERLAY_STRING_CHUNK_SIZE
]
3772 /* See if we got to this string directly or indirectly from
3773 an overlay property. That includes the before-string or
3774 after-string of an overlay, strings in display properties
3775 provided by an overlay, their text properties, etc.
3777 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3778 if (! NILP (from_overlay
))
3779 for (i
= it
->sp
- 1; i
>= 0; i
--)
3781 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3783 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
3784 % OVERLAY_STRING_CHUNK_SIZE
];
3785 else if (! NILP (it
->stack
[i
].from_overlay
))
3786 from_overlay
= it
->stack
[i
].from_overlay
;
3788 if (!NILP (from_overlay
))
3792 if (! NILP (from_overlay
))
3794 bufpos
= IT_CHARPOS (*it
);
3795 /* For a string from an overlay, the base face depends
3796 only on text properties and ignores overlays. */
3798 = face_for_overlay_string (it
->w
,
3800 it
->region_beg_charpos
,
3801 it
->region_end_charpos
,
3804 + TEXT_PROP_DISTANCE_LIMIT
),
3812 /* For strings from a `display' property, use the face at
3813 IT's current buffer position as the base face to merge
3814 with, so that overlay strings appear in the same face as
3815 surrounding text, unless they specify their own
3817 base_face_id
= it
->string_from_prefix_prop_p
3819 : underlying_face_id (it
);
3822 new_face_id
= face_at_string_position (it
->w
,
3824 IT_STRING_CHARPOS (*it
),
3826 it
->region_beg_charpos
,
3827 it
->region_end_charpos
,
3831 /* Is this a start of a run of characters with box? Caveat:
3832 this can be called for a freshly allocated iterator; face_id
3833 is -1 is this case. We know that the new face will not
3834 change until the next check pos, i.e. if the new face has a
3835 box, all characters up to that position will have a
3836 box. But, as usual, we don't know whether that position
3837 is really the end. */
3838 if (new_face_id
!= it
->face_id
)
3840 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3841 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3843 /* If new face has a box but old face hasn't, this is the
3844 start of a run of characters with box, i.e. it has a
3845 shadow on the left side. */
3846 it
->start_of_box_run_p
3847 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3848 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3852 it
->face_id
= new_face_id
;
3853 return HANDLED_NORMALLY
;
3857 /* Return the ID of the face ``underlying'' IT's current position,
3858 which is in a string. If the iterator is associated with a
3859 buffer, return the face at IT's current buffer position.
3860 Otherwise, use the iterator's base_face_id. */
3863 underlying_face_id (struct it
*it
)
3865 int face_id
= it
->base_face_id
, i
;
3867 eassert (STRINGP (it
->string
));
3869 for (i
= it
->sp
- 1; i
>= 0; --i
)
3870 if (NILP (it
->stack
[i
].string
))
3871 face_id
= it
->stack
[i
].face_id
;
3877 /* Compute the face one character before or after the current position
3878 of IT, in the visual order. BEFORE_P non-zero means get the face
3879 in front (to the left in L2R paragraphs, to the right in R2L
3880 paragraphs) of IT's screen position. Value is the ID of the face. */
3883 face_before_or_after_it_pos (struct it
*it
, int before_p
)
3886 ptrdiff_t next_check_charpos
;
3888 void *it_copy_data
= NULL
;
3890 eassert (it
->s
== NULL
);
3892 if (STRINGP (it
->string
))
3894 ptrdiff_t bufpos
, charpos
;
3897 /* No face change past the end of the string (for the case
3898 we are padding with spaces). No face change before the
3900 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3901 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3906 /* Set charpos to the position before or after IT's current
3907 position, in the logical order, which in the non-bidi
3908 case is the same as the visual order. */
3910 charpos
= IT_STRING_CHARPOS (*it
) - 1;
3911 else if (it
->what
== IT_COMPOSITION
)
3912 /* For composition, we must check the character after the
3914 charpos
= IT_STRING_CHARPOS (*it
) + it
->cmp_it
.nchars
;
3916 charpos
= IT_STRING_CHARPOS (*it
) + 1;
3922 /* With bidi iteration, the character before the current
3923 in the visual order cannot be found by simple
3924 iteration, because "reverse" reordering is not
3925 supported. Instead, we need to use the move_it_*
3926 family of functions. */
3927 /* Ignore face changes before the first visible
3928 character on this display line. */
3929 if (it
->current_x
<= it
->first_visible_x
)
3931 SAVE_IT (it_copy
, *it
, it_copy_data
);
3932 /* Implementation note: Since move_it_in_display_line
3933 works in the iterator geometry, and thinks the first
3934 character is always the leftmost, even in R2L lines,
3935 we don't need to distinguish between the R2L and L2R
3937 move_it_in_display_line (&it_copy
, SCHARS (it_copy
.string
),
3938 it_copy
.current_x
- 1, MOVE_TO_X
);
3939 charpos
= IT_STRING_CHARPOS (it_copy
);
3940 RESTORE_IT (it
, it
, it_copy_data
);
3944 /* Set charpos to the string position of the character
3945 that comes after IT's current position in the visual
3947 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
3951 bidi_move_to_visually_next (&it_copy
.bidi_it
);
3953 charpos
= it_copy
.bidi_it
.charpos
;
3956 eassert (0 <= charpos
&& charpos
<= SCHARS (it
->string
));
3958 if (it
->current
.overlay_string_index
>= 0)
3959 bufpos
= IT_CHARPOS (*it
);
3963 base_face_id
= underlying_face_id (it
);
3965 /* Get the face for ASCII, or unibyte. */
3966 face_id
= face_at_string_position (it
->w
,
3970 it
->region_beg_charpos
,
3971 it
->region_end_charpos
,
3972 &next_check_charpos
,
3975 /* Correct the face for charsets different from ASCII. Do it
3976 for the multibyte case only. The face returned above is
3977 suitable for unibyte text if IT->string is unibyte. */
3978 if (STRING_MULTIBYTE (it
->string
))
3980 struct text_pos pos1
= string_pos (charpos
, it
->string
);
3981 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos1
);
3983 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3985 c
= string_char_and_length (p
, &len
);
3986 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, charpos
, it
->string
);
3991 struct text_pos pos
;
3993 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3994 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3997 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3998 pos
= it
->current
.pos
;
4003 DEC_TEXT_POS (pos
, it
->multibyte_p
);
4006 if (it
->what
== IT_COMPOSITION
)
4008 /* For composition, we must check the position after
4010 pos
.charpos
+= it
->cmp_it
.nchars
;
4011 pos
.bytepos
+= it
->len
;
4014 INC_TEXT_POS (pos
, it
->multibyte_p
);
4021 /* With bidi iteration, the character before the current
4022 in the visual order cannot be found by simple
4023 iteration, because "reverse" reordering is not
4024 supported. Instead, we need to use the move_it_*
4025 family of functions. */
4026 /* Ignore face changes before the first visible
4027 character on this display line. */
4028 if (it
->current_x
<= it
->first_visible_x
)
4030 SAVE_IT (it_copy
, *it
, it_copy_data
);
4031 /* Implementation note: Since move_it_in_display_line
4032 works in the iterator geometry, and thinks the first
4033 character is always the leftmost, even in R2L lines,
4034 we don't need to distinguish between the R2L and L2R
4036 move_it_in_display_line (&it_copy
, ZV
,
4037 it_copy
.current_x
- 1, MOVE_TO_X
);
4038 pos
= it_copy
.current
.pos
;
4039 RESTORE_IT (it
, it
, it_copy_data
);
4043 /* Set charpos to the buffer position of the character
4044 that comes after IT's current position in the visual
4046 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
4050 bidi_move_to_visually_next (&it_copy
.bidi_it
);
4053 it_copy
.bidi_it
.charpos
, it_copy
.bidi_it
.bytepos
);
4056 eassert (BEGV
<= CHARPOS (pos
) && CHARPOS (pos
) <= ZV
);
4058 /* Determine face for CHARSET_ASCII, or unibyte. */
4059 face_id
= face_at_buffer_position (it
->w
,
4061 it
->region_beg_charpos
,
4062 it
->region_end_charpos
,
4063 &next_check_charpos
,
4066 /* Correct the face for charsets different from ASCII. Do it
4067 for the multibyte case only. The face returned above is
4068 suitable for unibyte text if current_buffer is unibyte. */
4069 if (it
->multibyte_p
)
4071 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
4072 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
4073 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
4082 /***********************************************************************
4084 ***********************************************************************/
4086 /* Set up iterator IT from invisible properties at its current
4087 position. Called from handle_stop. */
4089 static enum prop_handled
4090 handle_invisible_prop (struct it
*it
)
4092 enum prop_handled handled
= HANDLED_NORMALLY
;
4096 if (STRINGP (it
->string
))
4098 Lisp_Object end_charpos
, limit
, charpos
;
4100 /* Get the value of the invisible text property at the
4101 current position. Value will be nil if there is no such
4103 charpos
= make_number (IT_STRING_CHARPOS (*it
));
4104 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
4105 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4107 if (invis_p
&& IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
4109 /* Record whether we have to display an ellipsis for the
4111 int display_ellipsis_p
= (invis_p
== 2);
4112 ptrdiff_t len
, endpos
;
4114 handled
= HANDLED_RECOMPUTE_PROPS
;
4116 /* Get the position at which the next visible text can be
4117 found in IT->string, if any. */
4118 endpos
= len
= SCHARS (it
->string
);
4119 XSETINT (limit
, len
);
4122 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
4124 if (INTEGERP (end_charpos
))
4126 endpos
= XFASTINT (end_charpos
);
4127 prop
= Fget_text_property (end_charpos
, Qinvisible
, it
->string
);
4128 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4130 display_ellipsis_p
= 1;
4133 while (invis_p
&& endpos
< len
);
4135 if (display_ellipsis_p
)
4140 /* Text at END_CHARPOS is visible. Move IT there. */
4141 struct text_pos old
;
4144 old
= it
->current
.string_pos
;
4145 oldpos
= CHARPOS (old
);
4148 if (it
->bidi_it
.first_elt
4149 && it
->bidi_it
.charpos
< SCHARS (it
->string
))
4150 bidi_paragraph_init (it
->paragraph_embedding
,
4152 /* Bidi-iterate out of the invisible text. */
4155 bidi_move_to_visually_next (&it
->bidi_it
);
4157 while (oldpos
<= it
->bidi_it
.charpos
4158 && it
->bidi_it
.charpos
< endpos
);
4160 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4161 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4162 if (IT_CHARPOS (*it
) >= endpos
)
4163 it
->prev_stop
= endpos
;
4167 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
4168 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
4173 /* The rest of the string is invisible. If this is an
4174 overlay string, proceed with the next overlay string
4175 or whatever comes and return a character from there. */
4176 if (it
->current
.overlay_string_index
>= 0
4177 && !display_ellipsis_p
)
4179 next_overlay_string (it
);
4180 /* Don't check for overlay strings when we just
4181 finished processing them. */
4182 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
4186 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
4187 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
4194 ptrdiff_t newpos
, next_stop
, start_charpos
, tem
;
4195 Lisp_Object pos
, overlay
;
4197 /* First of all, is there invisible text at this position? */
4198 tem
= start_charpos
= IT_CHARPOS (*it
);
4199 pos
= make_number (tem
);
4200 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
4202 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4204 /* If we are on invisible text, skip over it. */
4205 if (invis_p
&& start_charpos
< it
->end_charpos
)
4207 /* Record whether we have to display an ellipsis for the
4209 int display_ellipsis_p
= invis_p
== 2;
4211 handled
= HANDLED_RECOMPUTE_PROPS
;
4213 /* Loop skipping over invisible text. The loop is left at
4214 ZV or with IT on the first char being visible again. */
4217 /* Try to skip some invisible text. Return value is the
4218 position reached which can be equal to where we start
4219 if there is nothing invisible there. This skips both
4220 over invisible text properties and overlays with
4221 invisible property. */
4222 newpos
= skip_invisible (tem
, &next_stop
, ZV
, it
->window
);
4224 /* If we skipped nothing at all we weren't at invisible
4225 text in the first place. If everything to the end of
4226 the buffer was skipped, end the loop. */
4227 if (newpos
== tem
|| newpos
>= ZV
)
4231 /* We skipped some characters but not necessarily
4232 all there are. Check if we ended up on visible
4233 text. Fget_char_property returns the property of
4234 the char before the given position, i.e. if we
4235 get invis_p = 0, this means that the char at
4236 newpos is visible. */
4237 pos
= make_number (newpos
);
4238 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
4239 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4242 /* If we ended up on invisible text, proceed to
4243 skip starting with next_stop. */
4247 /* If there are adjacent invisible texts, don't lose the
4248 second one's ellipsis. */
4250 display_ellipsis_p
= 1;
4254 /* The position newpos is now either ZV or on visible text. */
4257 ptrdiff_t bpos
= CHAR_TO_BYTE (newpos
);
4259 bpos
== ZV_BYTE
|| FETCH_BYTE (bpos
) == '\n';
4261 newpos
<= BEGV
|| FETCH_BYTE (bpos
- 1) == '\n';
4263 /* If the invisible text ends on a newline or on a
4264 character after a newline, we can avoid the costly,
4265 character by character, bidi iteration to NEWPOS, and
4266 instead simply reseat the iterator there. That's
4267 because all bidi reordering information is tossed at
4268 the newline. This is a big win for modes that hide
4269 complete lines, like Outline, Org, etc. */
4270 if (on_newline
|| after_newline
)
4272 struct text_pos tpos
;
4273 bidi_dir_t pdir
= it
->bidi_it
.paragraph_dir
;
4275 SET_TEXT_POS (tpos
, newpos
, bpos
);
4276 reseat_1 (it
, tpos
, 0);
4277 /* If we reseat on a newline/ZV, we need to prep the
4278 bidi iterator for advancing to the next character
4279 after the newline/EOB, keeping the current paragraph
4280 direction (so that PRODUCE_GLYPHS does TRT wrt
4281 prepending/appending glyphs to a glyph row). */
4284 it
->bidi_it
.first_elt
= 0;
4285 it
->bidi_it
.paragraph_dir
= pdir
;
4286 it
->bidi_it
.ch
= (bpos
== ZV_BYTE
) ? -1 : '\n';
4287 it
->bidi_it
.nchars
= 1;
4288 it
->bidi_it
.ch_len
= 1;
4291 else /* Must use the slow method. */
4293 /* With bidi iteration, the region of invisible text
4294 could start and/or end in the middle of a
4295 non-base embedding level. Therefore, we need to
4296 skip invisible text using the bidi iterator,
4297 starting at IT's current position, until we find
4298 ourselves outside of the invisible text.
4299 Skipping invisible text _after_ bidi iteration
4300 avoids affecting the visual order of the
4301 displayed text when invisible properties are
4302 added or removed. */
4303 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< ZV
)
4305 /* If we were `reseat'ed to a new paragraph,
4306 determine the paragraph base direction. We
4307 need to do it now because
4308 next_element_from_buffer may not have a
4309 chance to do it, if we are going to skip any
4310 text at the beginning, which resets the
4312 bidi_paragraph_init (it
->paragraph_embedding
,
4317 bidi_move_to_visually_next (&it
->bidi_it
);
4319 while (it
->stop_charpos
<= it
->bidi_it
.charpos
4320 && it
->bidi_it
.charpos
< newpos
);
4321 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4322 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4323 /* If we overstepped NEWPOS, record its position in
4324 the iterator, so that we skip invisible text if
4325 later the bidi iteration lands us in the
4326 invisible region again. */
4327 if (IT_CHARPOS (*it
) >= newpos
)
4328 it
->prev_stop
= newpos
;
4333 IT_CHARPOS (*it
) = newpos
;
4334 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
4337 /* If there are before-strings at the start of invisible
4338 text, and the text is invisible because of a text
4339 property, arrange to show before-strings because 20.x did
4340 it that way. (If the text is invisible because of an
4341 overlay property instead of a text property, this is
4342 already handled in the overlay code.) */
4344 && get_overlay_strings (it
, it
->stop_charpos
))
4346 handled
= HANDLED_RECOMPUTE_PROPS
;
4347 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
4349 else if (display_ellipsis_p
)
4351 /* Make sure that the glyphs of the ellipsis will get
4352 correct `charpos' values. If we would not update
4353 it->position here, the glyphs would belong to the
4354 last visible character _before_ the invisible
4355 text, which confuses `set_cursor_from_row'.
4357 We use the last invisible position instead of the
4358 first because this way the cursor is always drawn on
4359 the first "." of the ellipsis, whenever PT is inside
4360 the invisible text. Otherwise the cursor would be
4361 placed _after_ the ellipsis when the point is after the
4362 first invisible character. */
4363 if (!STRINGP (it
->object
))
4365 it
->position
.charpos
= newpos
- 1;
4366 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
4369 /* Let the ellipsis display before
4370 considering any properties of the following char.
4371 Fixes jasonr@gnu.org 01 Oct 07 bug. */
4372 handled
= HANDLED_RETURN
;
4381 /* Make iterator IT return `...' next.
4382 Replaces LEN characters from buffer. */
4385 setup_for_ellipsis (struct it
*it
, int len
)
4387 /* Use the display table definition for `...'. Invalid glyphs
4388 will be handled by the method returning elements from dpvec. */
4389 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
4391 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
4392 it
->dpvec
= v
->contents
;
4393 it
->dpend
= v
->contents
+ v
->header
.size
;
4397 /* Default `...'. */
4398 it
->dpvec
= default_invis_vector
;
4399 it
->dpend
= default_invis_vector
+ 3;
4402 it
->dpvec_char_len
= len
;
4403 it
->current
.dpvec_index
= 0;
4404 it
->dpvec_face_id
= -1;
4406 /* Remember the current face id in case glyphs specify faces.
4407 IT's face is restored in set_iterator_to_next.
4408 saved_face_id was set to preceding char's face in handle_stop. */
4409 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
4410 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
4412 it
->method
= GET_FROM_DISPLAY_VECTOR
;
4418 /***********************************************************************
4420 ***********************************************************************/
4422 /* Set up iterator IT from `display' property at its current position.
4423 Called from handle_stop.
4424 We return HANDLED_RETURN if some part of the display property
4425 overrides the display of the buffer text itself.
4426 Otherwise we return HANDLED_NORMALLY. */
4428 static enum prop_handled
4429 handle_display_prop (struct it
*it
)
4431 Lisp_Object propval
, object
, overlay
;
4432 struct text_pos
*position
;
4434 /* Nonzero if some property replaces the display of the text itself. */
4435 int display_replaced_p
= 0;
4437 if (STRINGP (it
->string
))
4439 object
= it
->string
;
4440 position
= &it
->current
.string_pos
;
4441 bufpos
= CHARPOS (it
->current
.pos
);
4445 XSETWINDOW (object
, it
->w
);
4446 position
= &it
->current
.pos
;
4447 bufpos
= CHARPOS (*position
);
4450 /* Reset those iterator values set from display property values. */
4451 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
4452 it
->space_width
= Qnil
;
4453 it
->font_height
= Qnil
;
4456 /* We don't support recursive `display' properties, i.e. string
4457 values that have a string `display' property, that have a string
4458 `display' property etc. */
4459 if (!it
->string_from_display_prop_p
)
4460 it
->area
= TEXT_AREA
;
4462 propval
= get_char_property_and_overlay (make_number (position
->charpos
),
4463 Qdisplay
, object
, &overlay
);
4465 return HANDLED_NORMALLY
;
4466 /* Now OVERLAY is the overlay that gave us this property, or nil
4467 if it was a text property. */
4469 if (!STRINGP (it
->string
))
4470 object
= it
->w
->buffer
;
4472 display_replaced_p
= handle_display_spec (it
, propval
, object
, overlay
,
4474 FRAME_WINDOW_P (it
->f
));
4476 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
4479 /* Subroutine of handle_display_prop. Returns non-zero if the display
4480 specification in SPEC is a replacing specification, i.e. it would
4481 replace the text covered by `display' property with something else,
4482 such as an image or a display string. If SPEC includes any kind or
4483 `(space ...) specification, the value is 2; this is used by
4484 compute_display_string_pos, which see.
4486 See handle_single_display_spec for documentation of arguments.
4487 frame_window_p is non-zero if the window being redisplayed is on a
4488 GUI frame; this argument is used only if IT is NULL, see below.
4490 IT can be NULL, if this is called by the bidi reordering code
4491 through compute_display_string_pos, which see. In that case, this
4492 function only examines SPEC, but does not otherwise "handle" it, in
4493 the sense that it doesn't set up members of IT from the display
4496 handle_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4497 Lisp_Object overlay
, struct text_pos
*position
,
4498 ptrdiff_t bufpos
, int frame_window_p
)
4500 int replacing_p
= 0;
4504 /* Simple specifications. */
4505 && !EQ (XCAR (spec
), Qimage
)
4506 #ifdef HAVE_XWIDGETS
4507 && !EQ (XCAR (spec
), Qxwidget
)
4509 && !EQ (XCAR (spec
), Qspace
)
4510 && !EQ (XCAR (spec
), Qwhen
)
4511 && !EQ (XCAR (spec
), Qslice
)
4512 && !EQ (XCAR (spec
), Qspace_width
)
4513 && !EQ (XCAR (spec
), Qheight
)
4514 && !EQ (XCAR (spec
), Qraise
)
4515 /* Marginal area specifications. */
4516 && !(CONSP (XCAR (spec
)) && EQ (XCAR (XCAR (spec
)), Qmargin
))
4517 && !EQ (XCAR (spec
), Qleft_fringe
)
4518 && !EQ (XCAR (spec
), Qright_fringe
)
4519 && !NILP (XCAR (spec
)))
4521 for (; CONSP (spec
); spec
= XCDR (spec
))
4523 if ((rv
= handle_single_display_spec (it
, XCAR (spec
), object
,
4524 overlay
, position
, bufpos
,
4525 replacing_p
, frame_window_p
)))
4528 /* If some text in a string is replaced, `position' no
4529 longer points to the position of `object'. */
4530 if (!it
|| STRINGP (object
))
4535 else if (VECTORP (spec
))
4538 for (i
= 0; i
< ASIZE (spec
); ++i
)
4539 if ((rv
= handle_single_display_spec (it
, AREF (spec
, i
), object
,
4540 overlay
, position
, bufpos
,
4541 replacing_p
, frame_window_p
)))
4544 /* If some text in a string is replaced, `position' no
4545 longer points to the position of `object'. */
4546 if (!it
|| STRINGP (object
))
4552 if ((rv
= handle_single_display_spec (it
, spec
, object
, overlay
,
4553 position
, bufpos
, 0,
4561 /* Value is the position of the end of the `display' property starting
4562 at START_POS in OBJECT. */
4564 static struct text_pos
4565 display_prop_end (struct it
*it
, Lisp_Object object
, struct text_pos start_pos
)
4568 struct text_pos end_pos
;
4570 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
4571 Qdisplay
, object
, Qnil
);
4572 CHARPOS (end_pos
) = XFASTINT (end
);
4573 if (STRINGP (object
))
4574 compute_string_pos (&end_pos
, start_pos
, it
->string
);
4576 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
4582 /* Set up IT from a single `display' property specification SPEC. OBJECT
4583 is the object in which the `display' property was found. *POSITION
4584 is the position in OBJECT at which the `display' property was found.
4585 BUFPOS is the buffer position of OBJECT (different from POSITION if
4586 OBJECT is not a buffer). DISPLAY_REPLACED_P non-zero means that we
4587 previously saw a display specification which already replaced text
4588 display with something else, for example an image; we ignore such
4589 properties after the first one has been processed.
4591 OVERLAY is the overlay this `display' property came from,
4592 or nil if it was a text property.
4594 If SPEC is a `space' or `image' specification, and in some other
4595 cases too, set *POSITION to the position where the `display'
4598 If IT is NULL, only examine the property specification in SPEC, but
4599 don't set up IT. In that case, FRAME_WINDOW_P non-zero means SPEC
4600 is intended to be displayed in a window on a GUI frame.
4602 Value is non-zero if something was found which replaces the display
4603 of buffer or string text. */
4606 handle_single_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4607 Lisp_Object overlay
, struct text_pos
*position
,
4608 ptrdiff_t bufpos
, int display_replaced_p
,
4612 Lisp_Object location
, value
;
4613 struct text_pos start_pos
= *position
;
4616 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
4617 If the result is non-nil, use VALUE instead of SPEC. */
4619 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4628 if (!NILP (form
) && !EQ (form
, Qt
))
4630 ptrdiff_t count
= SPECPDL_INDEX ();
4631 struct gcpro gcpro1
;
4633 /* Bind `object' to the object having the `display' property, a
4634 buffer or string. Bind `position' to the position in the
4635 object where the property was found, and `buffer-position'
4636 to the current position in the buffer. */
4639 XSETBUFFER (object
, current_buffer
);
4640 specbind (Qobject
, object
);
4641 specbind (Qposition
, make_number (CHARPOS (*position
)));
4642 specbind (Qbuffer_position
, make_number (bufpos
));
4644 form
= safe_eval (form
);
4646 unbind_to (count
, Qnil
);
4652 /* Handle `(height HEIGHT)' specifications. */
4654 && EQ (XCAR (spec
), Qheight
)
4655 && CONSP (XCDR (spec
)))
4659 if (!FRAME_WINDOW_P (it
->f
))
4662 it
->font_height
= XCAR (XCDR (spec
));
4663 if (!NILP (it
->font_height
))
4665 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4666 int new_height
= -1;
4668 if (CONSP (it
->font_height
)
4669 && (EQ (XCAR (it
->font_height
), Qplus
)
4670 || EQ (XCAR (it
->font_height
), Qminus
))
4671 && CONSP (XCDR (it
->font_height
))
4672 && RANGED_INTEGERP (0, XCAR (XCDR (it
->font_height
)), INT_MAX
))
4674 /* `(+ N)' or `(- N)' where N is an integer. */
4675 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4676 if (EQ (XCAR (it
->font_height
), Qplus
))
4678 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4680 else if (FUNCTIONP (it
->font_height
))
4682 /* Call function with current height as argument.
4683 Value is the new height. */
4685 height
= safe_call1 (it
->font_height
,
4686 face
->lface
[LFACE_HEIGHT_INDEX
]);
4687 if (NUMBERP (height
))
4688 new_height
= XFLOATINT (height
);
4690 else if (NUMBERP (it
->font_height
))
4692 /* Value is a multiple of the canonical char height. */
4695 f
= FACE_FROM_ID (it
->f
,
4696 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4697 new_height
= (XFLOATINT (it
->font_height
)
4698 * XINT (f
->lface
[LFACE_HEIGHT_INDEX
]));
4702 /* Evaluate IT->font_height with `height' bound to the
4703 current specified height to get the new height. */
4704 ptrdiff_t count
= SPECPDL_INDEX ();
4706 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4707 value
= safe_eval (it
->font_height
);
4708 unbind_to (count
, Qnil
);
4710 if (NUMBERP (value
))
4711 new_height
= XFLOATINT (value
);
4715 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4722 /* Handle `(space-width WIDTH)'. */
4724 && EQ (XCAR (spec
), Qspace_width
)
4725 && CONSP (XCDR (spec
)))
4729 if (!FRAME_WINDOW_P (it
->f
))
4732 value
= XCAR (XCDR (spec
));
4733 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4734 it
->space_width
= value
;
4740 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4742 && EQ (XCAR (spec
), Qslice
))
4748 if (!FRAME_WINDOW_P (it
->f
))
4751 if (tem
= XCDR (spec
), CONSP (tem
))
4753 it
->slice
.x
= XCAR (tem
);
4754 if (tem
= XCDR (tem
), CONSP (tem
))
4756 it
->slice
.y
= XCAR (tem
);
4757 if (tem
= XCDR (tem
), CONSP (tem
))
4759 it
->slice
.width
= XCAR (tem
);
4760 if (tem
= XCDR (tem
), CONSP (tem
))
4761 it
->slice
.height
= XCAR (tem
);
4770 /* Handle `(raise FACTOR)'. */
4772 && EQ (XCAR (spec
), Qraise
)
4773 && CONSP (XCDR (spec
)))
4777 if (!FRAME_WINDOW_P (it
->f
))
4780 #ifdef HAVE_WINDOW_SYSTEM
4781 value
= XCAR (XCDR (spec
));
4782 if (NUMBERP (value
))
4784 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4785 it
->voffset
= - (XFLOATINT (value
)
4786 * (FONT_HEIGHT (face
->font
)));
4788 #endif /* HAVE_WINDOW_SYSTEM */
4794 /* Don't handle the other kinds of display specifications
4795 inside a string that we got from a `display' property. */
4796 if (it
&& it
->string_from_display_prop_p
)
4799 /* Characters having this form of property are not displayed, so
4800 we have to find the end of the property. */
4803 start_pos
= *position
;
4804 *position
= display_prop_end (it
, object
, start_pos
);
4808 /* Stop the scan at that end position--we assume that all
4809 text properties change there. */
4811 it
->stop_charpos
= position
->charpos
;
4813 /* Handle `(left-fringe BITMAP [FACE])'
4814 and `(right-fringe BITMAP [FACE])'. */
4816 && (EQ (XCAR (spec
), Qleft_fringe
)
4817 || EQ (XCAR (spec
), Qright_fringe
))
4818 && CONSP (XCDR (spec
)))
4824 if (!FRAME_WINDOW_P (it
->f
))
4825 /* If we return here, POSITION has been advanced
4826 across the text with this property. */
4828 /* Synchronize the bidi iterator with POSITION. This is
4829 needed because we are not going to push the iterator
4830 on behalf of this display property, so there will be
4831 no pop_it call to do this synchronization for us. */
4834 it
->position
= *position
;
4835 iterate_out_of_display_property (it
);
4836 *position
= it
->position
;
4841 else if (!frame_window_p
)
4844 #ifdef HAVE_WINDOW_SYSTEM
4845 value
= XCAR (XCDR (spec
));
4846 if (!SYMBOLP (value
)
4847 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4848 /* If we return here, POSITION has been advanced
4849 across the text with this property. */
4851 if (it
&& it
->bidi_p
)
4853 it
->position
= *position
;
4854 iterate_out_of_display_property (it
);
4855 *position
= it
->position
;
4862 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);;
4864 if (CONSP (XCDR (XCDR (spec
))))
4866 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4867 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4873 /* Save current settings of IT so that we can restore them
4874 when we are finished with the glyph property value. */
4875 push_it (it
, position
);
4877 it
->area
= TEXT_AREA
;
4878 it
->what
= IT_IMAGE
;
4879 it
->image_id
= -1; /* no image */
4880 it
->position
= start_pos
;
4881 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4882 it
->method
= GET_FROM_IMAGE
;
4883 it
->from_overlay
= Qnil
;
4884 it
->face_id
= face_id
;
4885 it
->from_disp_prop_p
= 1;
4887 /* Say that we haven't consumed the characters with
4888 `display' property yet. The call to pop_it in
4889 set_iterator_to_next will clean this up. */
4890 *position
= start_pos
;
4892 if (EQ (XCAR (spec
), Qleft_fringe
))
4894 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4895 it
->left_user_fringe_face_id
= face_id
;
4899 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4900 it
->right_user_fringe_face_id
= face_id
;
4903 #endif /* HAVE_WINDOW_SYSTEM */
4907 /* Prepare to handle `((margin left-margin) ...)',
4908 `((margin right-margin) ...)' and `((margin nil) ...)'
4909 prefixes for display specifications. */
4910 location
= Qunbound
;
4911 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4915 value
= XCDR (spec
);
4917 value
= XCAR (value
);
4920 if (EQ (XCAR (tem
), Qmargin
)
4921 && (tem
= XCDR (tem
),
4922 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4924 || EQ (tem
, Qleft_margin
)
4925 || EQ (tem
, Qright_margin
))))
4929 if (EQ (location
, Qunbound
))
4935 /* After this point, VALUE is the property after any
4936 margin prefix has been stripped. It must be a string,
4937 an image specification, or `(space ...)'.
4939 LOCATION specifies where to display: `left-margin',
4940 `right-margin' or nil. */
4942 valid_p
= (STRINGP (value
)
4943 #ifdef HAVE_WINDOW_SYSTEM
4944 || ((it
? FRAME_WINDOW_P (it
->f
) : frame_window_p
)
4945 && valid_image_p (value
))
4946 #endif /* not HAVE_WINDOW_SYSTEM */
4947 || (CONSP (value
) && EQ (XCAR (value
), Qspace
))
4948 #ifdef HAVE_XWIDGETS
4953 if (valid_p
&& !display_replaced_p
)
4959 /* Callers need to know whether the display spec is any kind
4960 of `(space ...)' spec that is about to affect text-area
4962 if (CONSP (value
) && EQ (XCAR (value
), Qspace
) && NILP (location
))
4967 /* Save current settings of IT so that we can restore them
4968 when we are finished with the glyph property value. */
4969 push_it (it
, position
);
4970 it
->from_overlay
= overlay
;
4971 it
->from_disp_prop_p
= 1;
4973 if (NILP (location
))
4974 it
->area
= TEXT_AREA
;
4975 else if (EQ (location
, Qleft_margin
))
4976 it
->area
= LEFT_MARGIN_AREA
;
4978 it
->area
= RIGHT_MARGIN_AREA
;
4980 if (STRINGP (value
))
4983 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4984 it
->current
.overlay_string_index
= -1;
4985 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4986 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4987 it
->method
= GET_FROM_STRING
;
4988 it
->stop_charpos
= 0;
4990 it
->base_level_stop
= 0;
4991 it
->string_from_display_prop_p
= 1;
4992 /* Say that we haven't consumed the characters with
4993 `display' property yet. The call to pop_it in
4994 set_iterator_to_next will clean this up. */
4995 if (BUFFERP (object
))
4996 *position
= start_pos
;
4998 /* Force paragraph direction to be that of the parent
4999 object. If the parent object's paragraph direction is
5000 not yet determined, default to L2R. */
5001 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
5002 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5004 it
->paragraph_embedding
= L2R
;
5006 /* Set up the bidi iterator for this display string. */
5009 it
->bidi_it
.string
.lstring
= it
->string
;
5010 it
->bidi_it
.string
.s
= NULL
;
5011 it
->bidi_it
.string
.schars
= it
->end_charpos
;
5012 it
->bidi_it
.string
.bufpos
= bufpos
;
5013 it
->bidi_it
.string
.from_disp_str
= 1;
5014 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5015 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5018 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
5020 it
->method
= GET_FROM_STRETCH
;
5022 *position
= it
->position
= start_pos
;
5023 retval
= 1 + (it
->area
== TEXT_AREA
);
5025 #ifdef HAVE_XWIDGETS
5026 else if (XWIDGETP(value
))
5028 //printf("handle_single_display_spec: im an xwidget!!\n");
5029 it
->what
= IT_XWIDGET
;
5030 it
->method
= GET_FROM_XWIDGET
;
5031 it
->position
= start_pos
;
5032 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
5033 *position
= start_pos
;
5035 it
->xwidget
= lookup_xwidget(value
);
5038 #ifdef HAVE_WINDOW_SYSTEM
5041 it
->what
= IT_IMAGE
;
5042 it
->image_id
= lookup_image (it
->f
, value
);
5043 it
->position
= start_pos
;
5044 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
5045 it
->method
= GET_FROM_IMAGE
;
5047 /* Say that we haven't consumed the characters with
5048 `display' property yet. The call to pop_it in
5049 set_iterator_to_next will clean this up. */
5050 *position
= start_pos
;
5052 #endif /* HAVE_WINDOW_SYSTEM */
5057 /* Invalid property or property not supported. Restore
5058 POSITION to what it was before. */
5059 *position
= start_pos
;
5063 /* Check if PROP is a display property value whose text should be
5064 treated as intangible. OVERLAY is the overlay from which PROP
5065 came, or nil if it came from a text property. CHARPOS and BYTEPOS
5066 specify the buffer position covered by PROP. */
5069 display_prop_intangible_p (Lisp_Object prop
, Lisp_Object overlay
,
5070 ptrdiff_t charpos
, ptrdiff_t bytepos
)
5072 int frame_window_p
= FRAME_WINDOW_P (XFRAME (selected_frame
));
5073 struct text_pos position
;
5075 SET_TEXT_POS (position
, charpos
, bytepos
);
5076 return handle_display_spec (NULL
, prop
, Qnil
, overlay
,
5077 &position
, charpos
, frame_window_p
);
5081 /* Return 1 if PROP is a display sub-property value containing STRING.
5083 Implementation note: this and the following function are really
5084 special cases of handle_display_spec and
5085 handle_single_display_spec, and should ideally use the same code.
5086 Until they do, these two pairs must be consistent and must be
5087 modified in sync. */
5090 single_display_spec_string_p (Lisp_Object prop
, Lisp_Object string
)
5092 if (EQ (string
, prop
))
5095 /* Skip over `when FORM'. */
5096 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
5101 /* Actually, the condition following `when' should be eval'ed,
5102 like handle_single_display_spec does, and we should return
5103 zero if it evaluates to nil. However, this function is
5104 called only when the buffer was already displayed and some
5105 glyph in the glyph matrix was found to come from a display
5106 string. Therefore, the condition was already evaluated, and
5107 the result was non-nil, otherwise the display string wouldn't
5108 have been displayed and we would have never been called for
5109 this property. Thus, we can skip the evaluation and assume
5110 its result is non-nil. */
5115 /* Skip over `margin LOCATION'. */
5116 if (EQ (XCAR (prop
), Qmargin
))
5127 return EQ (prop
, string
) || (CONSP (prop
) && EQ (XCAR (prop
), string
));
5131 /* Return 1 if STRING appears in the `display' property PROP. */
5134 display_prop_string_p (Lisp_Object prop
, Lisp_Object string
)
5137 && !EQ (XCAR (prop
), Qwhen
)
5138 && !(CONSP (XCAR (prop
)) && EQ (Qmargin
, XCAR (XCAR (prop
)))))
5140 /* A list of sub-properties. */
5141 while (CONSP (prop
))
5143 if (single_display_spec_string_p (XCAR (prop
), string
))
5148 else if (VECTORP (prop
))
5150 /* A vector of sub-properties. */
5152 for (i
= 0; i
< ASIZE (prop
); ++i
)
5153 if (single_display_spec_string_p (AREF (prop
, i
), string
))
5157 return single_display_spec_string_p (prop
, string
);
5162 /* Look for STRING in overlays and text properties in the current
5163 buffer, between character positions FROM and TO (excluding TO).
5164 BACK_P non-zero means look back (in this case, TO is supposed to be
5166 Value is the first character position where STRING was found, or
5167 zero if it wasn't found before hitting TO.
5169 This function may only use code that doesn't eval because it is
5170 called asynchronously from note_mouse_highlight. */
5173 string_buffer_position_lim (Lisp_Object string
,
5174 ptrdiff_t from
, ptrdiff_t to
, int back_p
)
5176 Lisp_Object limit
, prop
, pos
;
5179 pos
= make_number (max (from
, BEGV
));
5181 if (!back_p
) /* looking forward */
5183 limit
= make_number (min (to
, ZV
));
5184 while (!found
&& !EQ (pos
, limit
))
5186 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5187 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5190 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
,
5194 else /* looking back */
5196 limit
= make_number (max (to
, BEGV
));
5197 while (!found
&& !EQ (pos
, limit
))
5199 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5200 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5203 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
5208 return found
? XINT (pos
) : 0;
5211 /* Determine which buffer position in current buffer STRING comes from.
5212 AROUND_CHARPOS is an approximate position where it could come from.
5213 Value is the buffer position or 0 if it couldn't be determined.
5215 This function is necessary because we don't record buffer positions
5216 in glyphs generated from strings (to keep struct glyph small).
5217 This function may only use code that doesn't eval because it is
5218 called asynchronously from note_mouse_highlight. */
5221 string_buffer_position (Lisp_Object string
, ptrdiff_t around_charpos
)
5223 const int MAX_DISTANCE
= 1000;
5224 ptrdiff_t found
= string_buffer_position_lim (string
, around_charpos
,
5225 around_charpos
+ MAX_DISTANCE
,
5229 found
= string_buffer_position_lim (string
, around_charpos
,
5230 around_charpos
- MAX_DISTANCE
, 1);
5236 /***********************************************************************
5237 `composition' property
5238 ***********************************************************************/
5240 /* Set up iterator IT from `composition' property at its current
5241 position. Called from handle_stop. */
5243 static enum prop_handled
5244 handle_composition_prop (struct it
*it
)
5246 Lisp_Object prop
, string
;
5247 ptrdiff_t pos
, pos_byte
, start
, end
;
5249 if (STRINGP (it
->string
))
5253 pos
= IT_STRING_CHARPOS (*it
);
5254 pos_byte
= IT_STRING_BYTEPOS (*it
);
5255 string
= it
->string
;
5256 s
= SDATA (string
) + pos_byte
;
5257 it
->c
= STRING_CHAR (s
);
5261 pos
= IT_CHARPOS (*it
);
5262 pos_byte
= IT_BYTEPOS (*it
);
5264 it
->c
= FETCH_CHAR (pos_byte
);
5267 /* If there's a valid composition and point is not inside of the
5268 composition (in the case that the composition is from the current
5269 buffer), draw a glyph composed from the composition components. */
5270 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
5271 && COMPOSITION_VALID_P (start
, end
, prop
)
5272 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
5275 /* As we can't handle this situation (perhaps font-lock added
5276 a new composition), we just return here hoping that next
5277 redisplay will detect this composition much earlier. */
5278 return HANDLED_NORMALLY
;
5281 if (STRINGP (it
->string
))
5282 pos_byte
= string_char_to_byte (it
->string
, start
);
5284 pos_byte
= CHAR_TO_BYTE (start
);
5286 it
->cmp_it
.id
= get_composition_id (start
, pos_byte
, end
- start
,
5289 if (it
->cmp_it
.id
>= 0)
5292 it
->cmp_it
.nchars
= COMPOSITION_LENGTH (prop
);
5293 it
->cmp_it
.nglyphs
= -1;
5297 return HANDLED_NORMALLY
;
5302 /***********************************************************************
5304 ***********************************************************************/
5306 /* The following structure is used to record overlay strings for
5307 later sorting in load_overlay_strings. */
5309 struct overlay_entry
5311 Lisp_Object overlay
;
5318 /* Set up iterator IT from overlay strings at its current position.
5319 Called from handle_stop. */
5321 static enum prop_handled
5322 handle_overlay_change (struct it
*it
)
5324 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
5325 return HANDLED_RECOMPUTE_PROPS
;
5327 return HANDLED_NORMALLY
;
5331 /* Set up the next overlay string for delivery by IT, if there is an
5332 overlay string to deliver. Called by set_iterator_to_next when the
5333 end of the current overlay string is reached. If there are more
5334 overlay strings to display, IT->string and
5335 IT->current.overlay_string_index are set appropriately here.
5336 Otherwise IT->string is set to nil. */
5339 next_overlay_string (struct it
*it
)
5341 ++it
->current
.overlay_string_index
;
5342 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
5344 /* No more overlay strings. Restore IT's settings to what
5345 they were before overlay strings were processed, and
5346 continue to deliver from current_buffer. */
5348 it
->ellipsis_p
= (it
->stack
[it
->sp
- 1].display_ellipsis_p
!= 0);
5351 || (NILP (it
->string
)
5352 && it
->method
== GET_FROM_BUFFER
5353 && it
->stop_charpos
>= BEGV
5354 && it
->stop_charpos
<= it
->end_charpos
));
5355 it
->current
.overlay_string_index
= -1;
5356 it
->n_overlay_strings
= 0;
5357 it
->overlay_strings_charpos
= -1;
5358 /* If there's an empty display string on the stack, pop the
5359 stack, to resync the bidi iterator with IT's position. Such
5360 empty strings are pushed onto the stack in
5361 get_overlay_strings_1. */
5362 if (it
->sp
> 0 && STRINGP (it
->string
) && !SCHARS (it
->string
))
5365 /* If we're at the end of the buffer, record that we have
5366 processed the overlay strings there already, so that
5367 next_element_from_buffer doesn't try it again. */
5368 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
5369 it
->overlay_strings_at_end_processed_p
= 1;
5373 /* There are more overlay strings to process. If
5374 IT->current.overlay_string_index has advanced to a position
5375 where we must load IT->overlay_strings with more strings, do
5376 it. We must load at the IT->overlay_strings_charpos where
5377 IT->n_overlay_strings was originally computed; when invisible
5378 text is present, this might not be IT_CHARPOS (Bug#7016). */
5379 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
5381 if (it
->current
.overlay_string_index
&& i
== 0)
5382 load_overlay_strings (it
, it
->overlay_strings_charpos
);
5384 /* Initialize IT to deliver display elements from the overlay
5386 it
->string
= it
->overlay_strings
[i
];
5387 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5388 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
5389 it
->method
= GET_FROM_STRING
;
5390 it
->stop_charpos
= 0;
5391 it
->end_charpos
= SCHARS (it
->string
);
5392 if (it
->cmp_it
.stop_pos
>= 0)
5393 it
->cmp_it
.stop_pos
= 0;
5395 it
->base_level_stop
= 0;
5397 /* Set up the bidi iterator for this overlay string. */
5400 it
->bidi_it
.string
.lstring
= it
->string
;
5401 it
->bidi_it
.string
.s
= NULL
;
5402 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5403 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
5404 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5405 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5406 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5414 /* Compare two overlay_entry structures E1 and E2. Used as a
5415 comparison function for qsort in load_overlay_strings. Overlay
5416 strings for the same position are sorted so that
5418 1. All after-strings come in front of before-strings, except
5419 when they come from the same overlay.
5421 2. Within after-strings, strings are sorted so that overlay strings
5422 from overlays with higher priorities come first.
5424 2. Within before-strings, strings are sorted so that overlay
5425 strings from overlays with higher priorities come last.
5427 Value is analogous to strcmp. */
5431 compare_overlay_entries (const void *e1
, const void *e2
)
5433 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
5434 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
5437 if (entry1
->after_string_p
!= entry2
->after_string_p
)
5439 /* Let after-strings appear in front of before-strings if
5440 they come from different overlays. */
5441 if (EQ (entry1
->overlay
, entry2
->overlay
))
5442 result
= entry1
->after_string_p
? 1 : -1;
5444 result
= entry1
->after_string_p
? -1 : 1;
5446 else if (entry1
->priority
!= entry2
->priority
)
5448 if (entry1
->after_string_p
)
5449 /* After-strings sorted in order of decreasing priority. */
5450 result
= entry2
->priority
< entry1
->priority
? -1 : 1;
5452 /* Before-strings sorted in order of increasing priority. */
5453 result
= entry1
->priority
< entry2
->priority
? -1 : 1;
5462 /* Load the vector IT->overlay_strings with overlay strings from IT's
5463 current buffer position, or from CHARPOS if that is > 0. Set
5464 IT->n_overlays to the total number of overlay strings found.
5466 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
5467 a time. On entry into load_overlay_strings,
5468 IT->current.overlay_string_index gives the number of overlay
5469 strings that have already been loaded by previous calls to this
5472 IT->add_overlay_start contains an additional overlay start
5473 position to consider for taking overlay strings from, if non-zero.
5474 This position comes into play when the overlay has an `invisible'
5475 property, and both before and after-strings. When we've skipped to
5476 the end of the overlay, because of its `invisible' property, we
5477 nevertheless want its before-string to appear.
5478 IT->add_overlay_start will contain the overlay start position
5481 Overlay strings are sorted so that after-string strings come in
5482 front of before-string strings. Within before and after-strings,
5483 strings are sorted by overlay priority. See also function
5484 compare_overlay_entries. */
5487 load_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5489 Lisp_Object overlay
, window
, str
, invisible
;
5490 struct Lisp_Overlay
*ov
;
5491 ptrdiff_t start
, end
;
5492 ptrdiff_t size
= 20;
5493 ptrdiff_t n
= 0, i
, j
;
5495 struct overlay_entry
*entries
= alloca (size
* sizeof *entries
);
5499 charpos
= IT_CHARPOS (*it
);
5501 /* Append the overlay string STRING of overlay OVERLAY to vector
5502 `entries' which has size `size' and currently contains `n'
5503 elements. AFTER_P non-zero means STRING is an after-string of
5505 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
5508 Lisp_Object priority; \
5512 struct overlay_entry *old = entries; \
5513 SAFE_NALLOCA (entries, 2, size); \
5514 memcpy (entries, old, size * sizeof *entries); \
5518 entries[n].string = (STRING); \
5519 entries[n].overlay = (OVERLAY); \
5520 priority = Foverlay_get ((OVERLAY), Qpriority); \
5521 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
5522 entries[n].after_string_p = (AFTER_P); \
5527 /* Process overlay before the overlay center. */
5528 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
5530 XSETMISC (overlay
, ov
);
5531 eassert (OVERLAYP (overlay
));
5532 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5533 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5538 /* Skip this overlay if it doesn't start or end at IT's current
5540 if (end
!= charpos
&& start
!= charpos
)
5543 /* Skip this overlay if it doesn't apply to IT->w. */
5544 window
= Foverlay_get (overlay
, Qwindow
);
5545 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5548 /* If the text ``under'' the overlay is invisible, both before-
5549 and after-strings from this overlay are visible; start and
5550 end position are indistinguishable. */
5551 invisible
= Foverlay_get (overlay
, Qinvisible
);
5552 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5554 /* If overlay has a non-empty before-string, record it. */
5555 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5556 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5558 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5560 /* If overlay has a non-empty after-string, record it. */
5561 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5562 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5564 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5567 /* Process overlays after the overlay center. */
5568 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
5570 XSETMISC (overlay
, ov
);
5571 eassert (OVERLAYP (overlay
));
5572 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5573 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5575 if (start
> charpos
)
5578 /* Skip this overlay if it doesn't start or end at IT's current
5580 if (end
!= charpos
&& start
!= charpos
)
5583 /* Skip this overlay if it doesn't apply to IT->w. */
5584 window
= Foverlay_get (overlay
, Qwindow
);
5585 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5588 /* If the text ``under'' the overlay is invisible, it has a zero
5589 dimension, and both before- and after-strings apply. */
5590 invisible
= Foverlay_get (overlay
, Qinvisible
);
5591 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5593 /* If overlay has a non-empty before-string, record it. */
5594 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5595 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5597 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5599 /* If overlay has a non-empty after-string, record it. */
5600 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5601 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5603 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5606 #undef RECORD_OVERLAY_STRING
5610 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
5612 /* Record number of overlay strings, and where we computed it. */
5613 it
->n_overlay_strings
= n
;
5614 it
->overlay_strings_charpos
= charpos
;
5616 /* IT->current.overlay_string_index is the number of overlay strings
5617 that have already been consumed by IT. Copy some of the
5618 remaining overlay strings to IT->overlay_strings. */
5620 j
= it
->current
.overlay_string_index
;
5621 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
5623 it
->overlay_strings
[i
] = entries
[j
].string
;
5624 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
5632 /* Get the first chunk of overlay strings at IT's current buffer
5633 position, or at CHARPOS if that is > 0. Value is non-zero if at
5634 least one overlay string was found. */
5637 get_overlay_strings_1 (struct it
*it
, ptrdiff_t charpos
, int compute_stop_p
)
5639 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5640 process. This fills IT->overlay_strings with strings, and sets
5641 IT->n_overlay_strings to the total number of strings to process.
5642 IT->pos.overlay_string_index has to be set temporarily to zero
5643 because load_overlay_strings needs this; it must be set to -1
5644 when no overlay strings are found because a zero value would
5645 indicate a position in the first overlay string. */
5646 it
->current
.overlay_string_index
= 0;
5647 load_overlay_strings (it
, charpos
);
5649 /* If we found overlay strings, set up IT to deliver display
5650 elements from the first one. Otherwise set up IT to deliver
5651 from current_buffer. */
5652 if (it
->n_overlay_strings
)
5654 /* Make sure we know settings in current_buffer, so that we can
5655 restore meaningful values when we're done with the overlay
5658 compute_stop_pos (it
);
5659 eassert (it
->face_id
>= 0);
5661 /* Save IT's settings. They are restored after all overlay
5662 strings have been processed. */
5663 eassert (!compute_stop_p
|| it
->sp
== 0);
5665 /* When called from handle_stop, there might be an empty display
5666 string loaded. In that case, don't bother saving it. But
5667 don't use this optimization with the bidi iterator, since we
5668 need the corresponding pop_it call to resync the bidi
5669 iterator's position with IT's position, after we are done
5670 with the overlay strings. (The corresponding call to pop_it
5671 in case of an empty display string is in
5672 next_overlay_string.) */
5674 && STRINGP (it
->string
) && !SCHARS (it
->string
)))
5677 /* Set up IT to deliver display elements from the first overlay
5679 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5680 it
->string
= it
->overlay_strings
[0];
5681 it
->from_overlay
= Qnil
;
5682 it
->stop_charpos
= 0;
5683 eassert (STRINGP (it
->string
));
5684 it
->end_charpos
= SCHARS (it
->string
);
5686 it
->base_level_stop
= 0;
5687 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5688 it
->method
= GET_FROM_STRING
;
5689 it
->from_disp_prop_p
= 0;
5691 /* Force paragraph direction to be that of the parent
5693 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
5694 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5696 it
->paragraph_embedding
= L2R
;
5698 /* Set up the bidi iterator for this overlay string. */
5701 ptrdiff_t pos
= (charpos
> 0 ? charpos
: IT_CHARPOS (*it
));
5703 it
->bidi_it
.string
.lstring
= it
->string
;
5704 it
->bidi_it
.string
.s
= NULL
;
5705 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5706 it
->bidi_it
.string
.bufpos
= pos
;
5707 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5708 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5709 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5714 it
->current
.overlay_string_index
= -1;
5719 get_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5722 it
->method
= GET_FROM_BUFFER
;
5724 (void) get_overlay_strings_1 (it
, charpos
, 1);
5728 /* Value is non-zero if we found at least one overlay string. */
5729 return STRINGP (it
->string
);
5734 /***********************************************************************
5735 Saving and restoring state
5736 ***********************************************************************/
5738 /* Save current settings of IT on IT->stack. Called, for example,
5739 before setting up IT for an overlay string, to be able to restore
5740 IT's settings to what they were after the overlay string has been
5741 processed. If POSITION is non-NULL, it is the position to save on
5742 the stack instead of IT->position. */
5745 push_it (struct it
*it
, struct text_pos
*position
)
5747 struct iterator_stack_entry
*p
;
5749 eassert (it
->sp
< IT_STACK_SIZE
);
5750 p
= it
->stack
+ it
->sp
;
5752 p
->stop_charpos
= it
->stop_charpos
;
5753 p
->prev_stop
= it
->prev_stop
;
5754 p
->base_level_stop
= it
->base_level_stop
;
5755 p
->cmp_it
= it
->cmp_it
;
5756 eassert (it
->face_id
>= 0);
5757 p
->face_id
= it
->face_id
;
5758 p
->string
= it
->string
;
5759 p
->method
= it
->method
;
5760 p
->from_overlay
= it
->from_overlay
;
5763 case GET_FROM_IMAGE
:
5764 p
->u
.image
.object
= it
->object
;
5765 p
->u
.image
.image_id
= it
->image_id
;
5766 p
->u
.image
.slice
= it
->slice
;
5768 case GET_FROM_STRETCH
:
5769 p
->u
.stretch
.object
= it
->object
;
5771 #ifdef HAVE_XWIDGETS
5772 case GET_FROM_XWIDGET
:
5773 p
->u
.xwidget
.object
= it
->object
;
5777 p
->position
= position
? *position
: it
->position
;
5778 p
->current
= it
->current
;
5779 p
->end_charpos
= it
->end_charpos
;
5780 p
->string_nchars
= it
->string_nchars
;
5782 p
->multibyte_p
= it
->multibyte_p
;
5783 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
5784 p
->space_width
= it
->space_width
;
5785 p
->font_height
= it
->font_height
;
5786 p
->voffset
= it
->voffset
;
5787 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5788 p
->string_from_prefix_prop_p
= it
->string_from_prefix_prop_p
;
5789 p
->display_ellipsis_p
= 0;
5790 p
->line_wrap
= it
->line_wrap
;
5791 p
->bidi_p
= it
->bidi_p
;
5792 p
->paragraph_embedding
= it
->paragraph_embedding
;
5793 p
->from_disp_prop_p
= it
->from_disp_prop_p
;
5796 /* Save the state of the bidi iterator as well. */
5798 bidi_push_it (&it
->bidi_it
);
5802 iterate_out_of_display_property (struct it
*it
)
5804 int buffer_p
= !STRINGP (it
->string
);
5805 ptrdiff_t eob
= (buffer_p
? ZV
: it
->end_charpos
);
5806 ptrdiff_t bob
= (buffer_p
? BEGV
: 0);
5808 eassert (eob
>= CHARPOS (it
->position
) && CHARPOS (it
->position
) >= bob
);
5810 /* Maybe initialize paragraph direction. If we are at the beginning
5811 of a new paragraph, next_element_from_buffer may not have a
5812 chance to do that. */
5813 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< eob
)
5814 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
5815 /* prev_stop can be zero, so check against BEGV as well. */
5816 while (it
->bidi_it
.charpos
>= bob
5817 && it
->prev_stop
<= it
->bidi_it
.charpos
5818 && it
->bidi_it
.charpos
< CHARPOS (it
->position
)
5819 && it
->bidi_it
.charpos
< eob
)
5820 bidi_move_to_visually_next (&it
->bidi_it
);
5821 /* Record the stop_pos we just crossed, for when we cross it
5823 if (it
->bidi_it
.charpos
> CHARPOS (it
->position
))
5824 it
->prev_stop
= CHARPOS (it
->position
);
5825 /* If we ended up not where pop_it put us, resync IT's
5826 positional members with the bidi iterator. */
5827 if (it
->bidi_it
.charpos
!= CHARPOS (it
->position
))
5828 SET_TEXT_POS (it
->position
, it
->bidi_it
.charpos
, it
->bidi_it
.bytepos
);
5830 it
->current
.pos
= it
->position
;
5832 it
->current
.string_pos
= it
->position
;
5835 /* Restore IT's settings from IT->stack. Called, for example, when no
5836 more overlay strings must be processed, and we return to delivering
5837 display elements from a buffer, or when the end of a string from a
5838 `display' property is reached and we return to delivering display
5839 elements from an overlay string, or from a buffer. */
5842 pop_it (struct it
*it
)
5844 struct iterator_stack_entry
*p
;
5845 int from_display_prop
= it
->from_disp_prop_p
;
5847 eassert (it
->sp
> 0);
5849 p
= it
->stack
+ it
->sp
;
5850 it
->stop_charpos
= p
->stop_charpos
;
5851 it
->prev_stop
= p
->prev_stop
;
5852 it
->base_level_stop
= p
->base_level_stop
;
5853 it
->cmp_it
= p
->cmp_it
;
5854 it
->face_id
= p
->face_id
;
5855 it
->current
= p
->current
;
5856 it
->position
= p
->position
;
5857 it
->string
= p
->string
;
5858 it
->from_overlay
= p
->from_overlay
;
5859 if (NILP (it
->string
))
5860 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5861 it
->method
= p
->method
;
5864 case GET_FROM_IMAGE
:
5865 it
->image_id
= p
->u
.image
.image_id
;
5866 it
->object
= p
->u
.image
.object
;
5867 it
->slice
= p
->u
.image
.slice
;
5869 #ifdef HAVE_XWIDGETS
5870 case GET_FROM_XWIDGET
:
5871 it
->object
= p
->u
.xwidget
.object
;
5874 case GET_FROM_STRETCH
:
5875 it
->object
= p
->u
.stretch
.object
;
5877 case GET_FROM_BUFFER
:
5878 it
->object
= it
->w
->buffer
;
5880 case GET_FROM_STRING
:
5881 it
->object
= it
->string
;
5883 case GET_FROM_DISPLAY_VECTOR
:
5885 it
->method
= GET_FROM_C_STRING
;
5886 else if (STRINGP (it
->string
))
5887 it
->method
= GET_FROM_STRING
;
5890 it
->method
= GET_FROM_BUFFER
;
5891 it
->object
= it
->w
->buffer
;
5894 it
->end_charpos
= p
->end_charpos
;
5895 it
->string_nchars
= p
->string_nchars
;
5897 it
->multibyte_p
= p
->multibyte_p
;
5898 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
5899 it
->space_width
= p
->space_width
;
5900 it
->font_height
= p
->font_height
;
5901 it
->voffset
= p
->voffset
;
5902 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5903 it
->string_from_prefix_prop_p
= p
->string_from_prefix_prop_p
;
5904 it
->line_wrap
= p
->line_wrap
;
5905 it
->bidi_p
= p
->bidi_p
;
5906 it
->paragraph_embedding
= p
->paragraph_embedding
;
5907 it
->from_disp_prop_p
= p
->from_disp_prop_p
;
5910 bidi_pop_it (&it
->bidi_it
);
5911 /* Bidi-iterate until we get out of the portion of text, if any,
5912 covered by a `display' text property or by an overlay with
5913 `display' property. (We cannot just jump there, because the
5914 internal coherency of the bidi iterator state can not be
5915 preserved across such jumps.) We also must determine the
5916 paragraph base direction if the overlay we just processed is
5917 at the beginning of a new paragraph. */
5918 if (from_display_prop
5919 && (it
->method
== GET_FROM_BUFFER
|| it
->method
== GET_FROM_STRING
))
5920 iterate_out_of_display_property (it
);
5922 eassert ((BUFFERP (it
->object
)
5923 && IT_CHARPOS (*it
) == it
->bidi_it
.charpos
5924 && IT_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
5925 || (STRINGP (it
->object
)
5926 && IT_STRING_CHARPOS (*it
) == it
->bidi_it
.charpos
5927 && IT_STRING_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
5928 || (CONSP (it
->object
) && it
->method
== GET_FROM_STRETCH
));
5934 /***********************************************************************
5936 ***********************************************************************/
5938 /* Set IT's current position to the previous line start. */
5941 back_to_previous_line_start (struct it
*it
)
5944 = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1,
5945 -1, &IT_BYTEPOS (*it
));
5949 /* Move IT to the next line start.
5951 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5952 we skipped over part of the text (as opposed to moving the iterator
5953 continuously over the text). Otherwise, don't change the value
5956 If BIDI_IT_PREV is non-NULL, store into it the state of the bidi
5957 iterator on the newline, if it was found.
5959 Newlines may come from buffer text, overlay strings, or strings
5960 displayed via the `display' property. That's the reason we can't
5961 simply use find_next_newline_no_quit.
5963 Note that this function may not skip over invisible text that is so
5964 because of text properties and immediately follows a newline. If
5965 it would, function reseat_at_next_visible_line_start, when called
5966 from set_iterator_to_next, would effectively make invisible
5967 characters following a newline part of the wrong glyph row, which
5968 leads to wrong cursor motion. */
5971 forward_to_next_line_start (struct it
*it
, int *skipped_p
,
5972 struct bidi_it
*bidi_it_prev
)
5974 ptrdiff_t old_selective
;
5975 int newline_found_p
, n
;
5976 const int MAX_NEWLINE_DISTANCE
= 500;
5978 /* If already on a newline, just consume it to avoid unintended
5979 skipping over invisible text below. */
5980 if (it
->what
== IT_CHARACTER
5982 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
5984 if (it
->bidi_p
&& bidi_it_prev
)
5985 *bidi_it_prev
= it
->bidi_it
;
5986 set_iterator_to_next (it
, 0);
5991 /* Don't handle selective display in the following. It's (a)
5992 unnecessary because it's done by the caller, and (b) leads to an
5993 infinite recursion because next_element_from_ellipsis indirectly
5994 calls this function. */
5995 old_selective
= it
->selective
;
5998 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
5999 from buffer text. */
6000 for (n
= newline_found_p
= 0;
6001 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
6002 n
+= STRINGP (it
->string
) ? 0 : 1)
6004 if (!get_next_display_element (it
))
6006 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
6007 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
6008 *bidi_it_prev
= it
->bidi_it
;
6009 set_iterator_to_next (it
, 0);
6012 /* If we didn't find a newline near enough, see if we can use a
6014 if (!newline_found_p
)
6016 ptrdiff_t bytepos
, start
= IT_CHARPOS (*it
);
6017 ptrdiff_t limit
= find_next_newline_no_quit (start
, 1, &bytepos
);
6020 eassert (!STRINGP (it
->string
));
6022 /* If there isn't any `display' property in sight, and no
6023 overlays, we can just use the position of the newline in
6025 if (it
->stop_charpos
>= limit
6026 || ((pos
= Fnext_single_property_change (make_number (start
),
6028 make_number (limit
)),
6030 && next_overlay_change (start
) == ZV
))
6034 IT_CHARPOS (*it
) = limit
;
6035 IT_BYTEPOS (*it
) = bytepos
;
6039 struct bidi_it bprev
;
6041 /* Help bidi.c avoid expensive searches for display
6042 properties and overlays, by telling it that there are
6043 none up to `limit'. */
6044 if (it
->bidi_it
.disp_pos
< limit
)
6046 it
->bidi_it
.disp_pos
= limit
;
6047 it
->bidi_it
.disp_prop
= 0;
6050 bprev
= it
->bidi_it
;
6051 bidi_move_to_visually_next (&it
->bidi_it
);
6052 } while (it
->bidi_it
.charpos
!= limit
);
6053 IT_CHARPOS (*it
) = limit
;
6054 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6056 *bidi_it_prev
= bprev
;
6058 *skipped_p
= newline_found_p
= 1;
6062 while (get_next_display_element (it
)
6063 && !newline_found_p
)
6065 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
6066 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
6067 *bidi_it_prev
= it
->bidi_it
;
6068 set_iterator_to_next (it
, 0);
6073 it
->selective
= old_selective
;
6074 return newline_found_p
;
6078 /* Set IT's current position to the previous visible line start. Skip
6079 invisible text that is so either due to text properties or due to
6080 selective display. Caution: this does not change IT->current_x and
6084 back_to_previous_visible_line_start (struct it
*it
)
6086 while (IT_CHARPOS (*it
) > BEGV
)
6088 back_to_previous_line_start (it
);
6090 if (IT_CHARPOS (*it
) <= BEGV
)
6093 /* If selective > 0, then lines indented more than its value are
6095 if (it
->selective
> 0
6096 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6100 /* Check the newline before point for invisibility. */
6103 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
6104 Qinvisible
, it
->window
);
6105 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
6109 if (IT_CHARPOS (*it
) <= BEGV
)
6114 void *it2data
= NULL
;
6117 Lisp_Object val
, overlay
;
6119 SAVE_IT (it2
, *it
, it2data
);
6121 /* If newline is part of a composition, continue from start of composition */
6122 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
6123 && beg
< IT_CHARPOS (*it
))
6126 /* If newline is replaced by a display property, find start of overlay
6127 or interval and continue search from that point. */
6128 pos
= --IT_CHARPOS (it2
);
6131 bidi_unshelve_cache (NULL
, 0);
6132 it2
.string_from_display_prop_p
= 0;
6133 it2
.from_disp_prop_p
= 0;
6134 if (handle_display_prop (&it2
) == HANDLED_RETURN
6135 && !NILP (val
= get_char_property_and_overlay
6136 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
6137 && (OVERLAYP (overlay
)
6138 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
6139 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
6141 RESTORE_IT (it
, it
, it2data
);
6145 /* Newline is not replaced by anything -- so we are done. */
6146 RESTORE_IT (it
, it
, it2data
);
6152 IT_CHARPOS (*it
) = beg
;
6153 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
6157 it
->continuation_lines_width
= 0;
6159 eassert (IT_CHARPOS (*it
) >= BEGV
);
6160 eassert (IT_CHARPOS (*it
) == BEGV
6161 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6166 /* Reseat iterator IT at the previous visible line start. Skip
6167 invisible text that is so either due to text properties or due to
6168 selective display. At the end, update IT's overlay information,
6169 face information etc. */
6172 reseat_at_previous_visible_line_start (struct it
*it
)
6174 back_to_previous_visible_line_start (it
);
6175 reseat (it
, it
->current
.pos
, 1);
6180 /* Reseat iterator IT on the next visible line start in the current
6181 buffer. ON_NEWLINE_P non-zero means position IT on the newline
6182 preceding the line start. Skip over invisible text that is so
6183 because of selective display. Compute faces, overlays etc at the
6184 new position. Note that this function does not skip over text that
6185 is invisible because of text properties. */
6188 reseat_at_next_visible_line_start (struct it
*it
, int on_newline_p
)
6190 int newline_found_p
, skipped_p
= 0;
6191 struct bidi_it bidi_it_prev
;
6193 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6195 /* Skip over lines that are invisible because they are indented
6196 more than the value of IT->selective. */
6197 if (it
->selective
> 0)
6198 while (IT_CHARPOS (*it
) < ZV
6199 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6202 eassert (IT_BYTEPOS (*it
) == BEGV
6203 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6205 forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6208 /* Position on the newline if that's what's requested. */
6209 if (on_newline_p
&& newline_found_p
)
6211 if (STRINGP (it
->string
))
6213 if (IT_STRING_CHARPOS (*it
) > 0)
6217 --IT_STRING_CHARPOS (*it
);
6218 --IT_STRING_BYTEPOS (*it
);
6222 /* We need to restore the bidi iterator to the state
6223 it had on the newline, and resync the IT's
6224 position with that. */
6225 it
->bidi_it
= bidi_it_prev
;
6226 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6227 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6231 else if (IT_CHARPOS (*it
) > BEGV
)
6240 /* We need to restore the bidi iterator to the state it
6241 had on the newline and resync IT with that. */
6242 it
->bidi_it
= bidi_it_prev
;
6243 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6244 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6246 reseat (it
, it
->current
.pos
, 0);
6250 reseat (it
, it
->current
.pos
, 0);
6257 /***********************************************************************
6258 Changing an iterator's position
6259 ***********************************************************************/
6261 /* Change IT's current position to POS in current_buffer. If FORCE_P
6262 is non-zero, always check for text properties at the new position.
6263 Otherwise, text properties are only looked up if POS >=
6264 IT->check_charpos of a property. */
6267 reseat (struct it
*it
, struct text_pos pos
, int force_p
)
6269 ptrdiff_t original_pos
= IT_CHARPOS (*it
);
6271 reseat_1 (it
, pos
, 0);
6273 /* Determine where to check text properties. Avoid doing it
6274 where possible because text property lookup is very expensive. */
6276 || CHARPOS (pos
) > it
->stop_charpos
6277 || CHARPOS (pos
) < original_pos
)
6281 /* For bidi iteration, we need to prime prev_stop and
6282 base_level_stop with our best estimations. */
6283 /* Implementation note: Of course, POS is not necessarily a
6284 stop position, so assigning prev_pos to it is a lie; we
6285 should have called compute_stop_backwards. However, if
6286 the current buffer does not include any R2L characters,
6287 that call would be a waste of cycles, because the
6288 iterator will never move back, and thus never cross this
6289 "fake" stop position. So we delay that backward search
6290 until the time we really need it, in next_element_from_buffer. */
6291 if (CHARPOS (pos
) != it
->prev_stop
)
6292 it
->prev_stop
= CHARPOS (pos
);
6293 if (CHARPOS (pos
) < it
->base_level_stop
)
6294 it
->base_level_stop
= 0; /* meaning it's unknown */
6300 it
->prev_stop
= it
->base_level_stop
= 0;
6309 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
6310 IT->stop_pos to POS, also. */
6313 reseat_1 (struct it
*it
, struct text_pos pos
, int set_stop_p
)
6315 /* Don't call this function when scanning a C string. */
6316 eassert (it
->s
== NULL
);
6318 /* POS must be a reasonable value. */
6319 eassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
6321 it
->current
.pos
= it
->position
= pos
;
6322 it
->end_charpos
= ZV
;
6324 it
->current
.dpvec_index
= -1;
6325 it
->current
.overlay_string_index
= -1;
6326 IT_STRING_CHARPOS (*it
) = -1;
6327 IT_STRING_BYTEPOS (*it
) = -1;
6329 it
->method
= GET_FROM_BUFFER
;
6330 it
->object
= it
->w
->buffer
;
6331 it
->area
= TEXT_AREA
;
6332 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
6334 it
->string_from_display_prop_p
= 0;
6335 it
->string_from_prefix_prop_p
= 0;
6337 it
->from_disp_prop_p
= 0;
6338 it
->face_before_selective_p
= 0;
6341 bidi_init_it (IT_CHARPOS (*it
), IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6343 bidi_unshelve_cache (NULL
, 0);
6344 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6345 it
->bidi_it
.string
.s
= NULL
;
6346 it
->bidi_it
.string
.lstring
= Qnil
;
6347 it
->bidi_it
.string
.bufpos
= 0;
6348 it
->bidi_it
.string
.unibyte
= 0;
6353 it
->stop_charpos
= CHARPOS (pos
);
6354 it
->base_level_stop
= CHARPOS (pos
);
6356 /* This make the information stored in it->cmp_it invalidate. */
6361 /* Set up IT for displaying a string, starting at CHARPOS in window W.
6362 If S is non-null, it is a C string to iterate over. Otherwise,
6363 STRING gives a Lisp string to iterate over.
6365 If PRECISION > 0, don't return more then PRECISION number of
6366 characters from the string.
6368 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
6369 characters have been returned. FIELD_WIDTH < 0 means an infinite
6372 MULTIBYTE = 0 means disable processing of multibyte characters,
6373 MULTIBYTE > 0 means enable it,
6374 MULTIBYTE < 0 means use IT->multibyte_p.
6376 IT must be initialized via a prior call to init_iterator before
6377 calling this function. */
6380 reseat_to_string (struct it
*it
, const char *s
, Lisp_Object string
,
6381 ptrdiff_t charpos
, ptrdiff_t precision
, int field_width
,
6384 /* No region in strings. */
6385 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
6387 /* No text property checks performed by default, but see below. */
6388 it
->stop_charpos
= -1;
6390 /* Set iterator position and end position. */
6391 memset (&it
->current
, 0, sizeof it
->current
);
6392 it
->current
.overlay_string_index
= -1;
6393 it
->current
.dpvec_index
= -1;
6394 eassert (charpos
>= 0);
6396 /* If STRING is specified, use its multibyteness, otherwise use the
6397 setting of MULTIBYTE, if specified. */
6399 it
->multibyte_p
= multibyte
> 0;
6401 /* Bidirectional reordering of strings is controlled by the default
6402 value of bidi-display-reordering. Don't try to reorder while
6403 loading loadup.el, as the necessary character property tables are
6404 not yet available. */
6407 && !NILP (BVAR (&buffer_defaults
, bidi_display_reordering
));
6411 eassert (STRINGP (string
));
6412 it
->string
= string
;
6414 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
6415 it
->method
= GET_FROM_STRING
;
6416 it
->current
.string_pos
= string_pos (charpos
, string
);
6420 it
->bidi_it
.string
.lstring
= string
;
6421 it
->bidi_it
.string
.s
= NULL
;
6422 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6423 it
->bidi_it
.string
.bufpos
= 0;
6424 it
->bidi_it
.string
.from_disp_str
= 0;
6425 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6426 bidi_init_it (charpos
, IT_STRING_BYTEPOS (*it
),
6427 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
6432 it
->s
= (const unsigned char *) s
;
6435 /* Note that we use IT->current.pos, not it->current.string_pos,
6436 for displaying C strings. */
6437 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
6438 if (it
->multibyte_p
)
6440 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
6441 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
6445 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
6446 it
->end_charpos
= it
->string_nchars
= strlen (s
);
6451 it
->bidi_it
.string
.lstring
= Qnil
;
6452 it
->bidi_it
.string
.s
= (const unsigned char *) s
;
6453 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6454 it
->bidi_it
.string
.bufpos
= 0;
6455 it
->bidi_it
.string
.from_disp_str
= 0;
6456 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6457 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6460 it
->method
= GET_FROM_C_STRING
;
6463 /* PRECISION > 0 means don't return more than PRECISION characters
6465 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
6467 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
6469 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6472 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
6473 characters have been returned. FIELD_WIDTH == 0 means don't pad,
6474 FIELD_WIDTH < 0 means infinite field width. This is useful for
6475 padding with `-' at the end of a mode line. */
6476 if (field_width
< 0)
6477 field_width
= INFINITY
;
6478 /* Implementation note: We deliberately don't enlarge
6479 it->bidi_it.string.schars here to fit it->end_charpos, because
6480 the bidi iterator cannot produce characters out of thin air. */
6481 if (field_width
> it
->end_charpos
- charpos
)
6482 it
->end_charpos
= charpos
+ field_width
;
6484 /* Use the standard display table for displaying strings. */
6485 if (DISP_TABLE_P (Vstandard_display_table
))
6486 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
6488 it
->stop_charpos
= charpos
;
6489 it
->prev_stop
= charpos
;
6490 it
->base_level_stop
= 0;
6493 it
->bidi_it
.first_elt
= 1;
6494 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6495 it
->bidi_it
.disp_pos
= -1;
6497 if (s
== NULL
&& it
->multibyte_p
)
6499 ptrdiff_t endpos
= SCHARS (it
->string
);
6500 if (endpos
> it
->end_charpos
)
6501 endpos
= it
->end_charpos
;
6502 composition_compute_stop_pos (&it
->cmp_it
, charpos
, -1, endpos
,
6510 /***********************************************************************
6512 ***********************************************************************/
6514 /* Map enum it_method value to corresponding next_element_from_* function. */
6516 static int (* get_next_element
[NUM_IT_METHODS
]) (struct it
*it
) =
6518 next_element_from_buffer
,
6519 next_element_from_display_vector
,
6520 next_element_from_string
,
6521 next_element_from_c_string
,
6522 next_element_from_image
,
6523 next_element_from_stretch
6524 #ifdef HAVE_XWIDGETS
6525 ,next_element_from_xwidget
6529 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
6532 /* Return 1 iff a character at CHARPOS (and BYTEPOS) is composed
6533 (possibly with the following characters). */
6535 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS,END_CHARPOS) \
6536 ((IT)->cmp_it.id >= 0 \
6537 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
6538 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
6539 END_CHARPOS, (IT)->w, \
6540 FACE_FROM_ID ((IT)->f, (IT)->face_id), \
6544 /* Lookup the char-table Vglyphless_char_display for character C (-1
6545 if we want information for no-font case), and return the display
6546 method symbol. By side-effect, update it->what and
6547 it->glyphless_method. This function is called from
6548 get_next_display_element for each character element, and from
6549 x_produce_glyphs when no suitable font was found. */
6552 lookup_glyphless_char_display (int c
, struct it
*it
)
6554 Lisp_Object glyphless_method
= Qnil
;
6556 if (CHAR_TABLE_P (Vglyphless_char_display
)
6557 && CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
)) >= 1)
6561 glyphless_method
= CHAR_TABLE_REF (Vglyphless_char_display
, c
);
6562 if (CONSP (glyphless_method
))
6563 glyphless_method
= FRAME_WINDOW_P (it
->f
)
6564 ? XCAR (glyphless_method
)
6565 : XCDR (glyphless_method
);
6568 glyphless_method
= XCHAR_TABLE (Vglyphless_char_display
)->extras
[0];
6572 if (NILP (glyphless_method
))
6575 /* The default is to display the character by a proper font. */
6577 /* The default for the no-font case is to display an empty box. */
6578 glyphless_method
= Qempty_box
;
6580 if (EQ (glyphless_method
, Qzero_width
))
6583 return glyphless_method
;
6584 /* This method can't be used for the no-font case. */
6585 glyphless_method
= Qempty_box
;
6587 if (EQ (glyphless_method
, Qthin_space
))
6588 it
->glyphless_method
= GLYPHLESS_DISPLAY_THIN_SPACE
;
6589 else if (EQ (glyphless_method
, Qempty_box
))
6590 it
->glyphless_method
= GLYPHLESS_DISPLAY_EMPTY_BOX
;
6591 else if (EQ (glyphless_method
, Qhex_code
))
6592 it
->glyphless_method
= GLYPHLESS_DISPLAY_HEX_CODE
;
6593 else if (STRINGP (glyphless_method
))
6594 it
->glyphless_method
= GLYPHLESS_DISPLAY_ACRONYM
;
6597 /* Invalid value. We use the default method. */
6598 glyphless_method
= Qnil
;
6601 it
->what
= IT_GLYPHLESS
;
6602 return glyphless_method
;
6605 /* Load IT's display element fields with information about the next
6606 display element from the current position of IT. Value is zero if
6607 end of buffer (or C string) is reached. */
6609 static struct frame
*last_escape_glyph_frame
= NULL
;
6610 static int last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
6611 static int last_escape_glyph_merged_face_id
= 0;
6613 struct frame
*last_glyphless_glyph_frame
= NULL
;
6614 int last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
6615 int last_glyphless_glyph_merged_face_id
= 0;
6618 get_next_display_element (struct it
*it
)
6620 /* Non-zero means that we found a display element. Zero means that
6621 we hit the end of what we iterate over. Performance note: the
6622 function pointer `method' used here turns out to be faster than
6623 using a sequence of if-statements. */
6627 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6629 if (it
->what
== IT_CHARACTER
)
6631 /* UAX#9, L4: "A character is depicted by a mirrored glyph if
6632 and only if (a) the resolved directionality of that character
6634 /* FIXME: Do we need an exception for characters from display
6636 if (it
->bidi_p
&& it
->bidi_it
.type
== STRONG_R
)
6637 it
->c
= bidi_mirror_char (it
->c
);
6638 /* Map via display table or translate control characters.
6639 IT->c, IT->len etc. have been set to the next character by
6640 the function call above. If we have a display table, and it
6641 contains an entry for IT->c, translate it. Don't do this if
6642 IT->c itself comes from a display table, otherwise we could
6643 end up in an infinite recursion. (An alternative could be to
6644 count the recursion depth of this function and signal an
6645 error when a certain maximum depth is reached.) Is it worth
6647 if (success_p
&& it
->dpvec
== NULL
)
6650 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
6651 int nonascii_space_p
= 0;
6652 int nonascii_hyphen_p
= 0;
6653 int c
= it
->c
; /* This is the character to display. */
6655 if (! it
->multibyte_p
&& ! ASCII_CHAR_P (c
))
6657 eassert (SINGLE_BYTE_CHAR_P (c
));
6658 if (unibyte_display_via_language_environment
)
6660 c
= DECODE_CHAR (unibyte
, c
);
6662 c
= BYTE8_TO_CHAR (it
->c
);
6665 c
= BYTE8_TO_CHAR (it
->c
);
6669 && (dv
= DISP_CHAR_VECTOR (it
->dp
, c
),
6672 struct Lisp_Vector
*v
= XVECTOR (dv
);
6674 /* Return the first character from the display table
6675 entry, if not empty. If empty, don't display the
6676 current character. */
6679 it
->dpvec_char_len
= it
->len
;
6680 it
->dpvec
= v
->contents
;
6681 it
->dpend
= v
->contents
+ v
->header
.size
;
6682 it
->current
.dpvec_index
= 0;
6683 it
->dpvec_face_id
= -1;
6684 it
->saved_face_id
= it
->face_id
;
6685 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6690 set_iterator_to_next (it
, 0);
6695 if (! NILP (lookup_glyphless_char_display (c
, it
)))
6697 if (it
->what
== IT_GLYPHLESS
)
6699 /* Don't display this character. */
6700 set_iterator_to_next (it
, 0);
6704 /* If `nobreak-char-display' is non-nil, we display
6705 non-ASCII spaces and hyphens specially. */
6706 if (! ASCII_CHAR_P (c
) && ! NILP (Vnobreak_char_display
))
6709 nonascii_space_p
= 1;
6710 else if (c
== 0xAD || c
== 0x2010 || c
== 0x2011)
6711 nonascii_hyphen_p
= 1;
6714 /* Translate control characters into `\003' or `^C' form.
6715 Control characters coming from a display table entry are
6716 currently not translated because we use IT->dpvec to hold
6717 the translation. This could easily be changed but I
6718 don't believe that it is worth doing.
6720 The characters handled by `nobreak-char-display' must be
6723 Non-printable characters and raw-byte characters are also
6724 translated to octal form. */
6725 if (((c
< ' ' || c
== 127) /* ASCII control chars */
6726 ? (it
->area
!= TEXT_AREA
6727 /* In mode line, treat \n, \t like other crl chars. */
6730 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
6731 || (c
!= '\n' && c
!= '\t'))
6733 || nonascii_hyphen_p
6735 || ! CHAR_PRINTABLE_P (c
))))
6737 /* C is a control character, non-ASCII space/hyphen,
6738 raw-byte, or a non-printable character which must be
6739 displayed either as '\003' or as `^C' where the '\\'
6740 and '^' can be defined in the display table. Fill
6741 IT->ctl_chars with glyphs for what we have to
6742 display. Then, set IT->dpvec to these glyphs. */
6749 /* Handle control characters with ^. */
6751 if (ASCII_CHAR_P (c
) && it
->ctl_arrow_p
)
6755 g
= '^'; /* default glyph for Control */
6756 /* Set IT->ctl_chars[0] to the glyph for `^'. */
6758 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
6760 g
= GLYPH_CODE_CHAR (gc
);
6761 lface_id
= GLYPH_CODE_FACE (gc
);
6765 face_id
= merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
);
6767 else if (it
->f
== last_escape_glyph_frame
6768 && it
->face_id
== last_escape_glyph_face_id
)
6770 face_id
= last_escape_glyph_merged_face_id
;
6774 /* Merge the escape-glyph face into the current face. */
6775 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
6777 last_escape_glyph_frame
= it
->f
;
6778 last_escape_glyph_face_id
= it
->face_id
;
6779 last_escape_glyph_merged_face_id
= face_id
;
6782 XSETINT (it
->ctl_chars
[0], g
);
6783 XSETINT (it
->ctl_chars
[1], c
^ 0100);
6785 goto display_control
;
6788 /* Handle non-ascii space in the mode where it only gets
6791 if (nonascii_space_p
&& EQ (Vnobreak_char_display
, Qt
))
6793 /* Merge `nobreak-space' into the current face. */
6794 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
6796 XSETINT (it
->ctl_chars
[0], ' ');
6798 goto display_control
;
6801 /* Handle sequences that start with the "escape glyph". */
6803 /* the default escape glyph is \. */
6804 escape_glyph
= '\\';
6807 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
6809 escape_glyph
= GLYPH_CODE_CHAR (gc
);
6810 lface_id
= GLYPH_CODE_FACE (gc
);
6814 /* The display table specified a face.
6815 Merge it into face_id and also into escape_glyph. */
6816 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6819 else if (it
->f
== last_escape_glyph_frame
6820 && it
->face_id
== last_escape_glyph_face_id
)
6822 face_id
= last_escape_glyph_merged_face_id
;
6826 /* Merge the escape-glyph face into the current face. */
6827 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
6829 last_escape_glyph_frame
= it
->f
;
6830 last_escape_glyph_face_id
= it
->face_id
;
6831 last_escape_glyph_merged_face_id
= face_id
;
6834 /* Draw non-ASCII hyphen with just highlighting: */
6836 if (nonascii_hyphen_p
&& EQ (Vnobreak_char_display
, Qt
))
6838 XSETINT (it
->ctl_chars
[0], '-');
6840 goto display_control
;
6843 /* Draw non-ASCII space/hyphen with escape glyph: */
6845 if (nonascii_space_p
|| nonascii_hyphen_p
)
6847 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6848 XSETINT (it
->ctl_chars
[1], nonascii_space_p
? ' ' : '-');
6850 goto display_control
;
6857 if (CHAR_BYTE8_P (c
))
6858 /* Display \200 instead of \17777600. */
6859 c
= CHAR_TO_BYTE8 (c
);
6860 len
= sprintf (str
, "%03o", c
);
6862 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6863 for (i
= 0; i
< len
; i
++)
6864 XSETINT (it
->ctl_chars
[i
+ 1], str
[i
]);
6869 /* Set up IT->dpvec and return first character from it. */
6870 it
->dpvec_char_len
= it
->len
;
6871 it
->dpvec
= it
->ctl_chars
;
6872 it
->dpend
= it
->dpvec
+ ctl_len
;
6873 it
->current
.dpvec_index
= 0;
6874 it
->dpvec_face_id
= face_id
;
6875 it
->saved_face_id
= it
->face_id
;
6876 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6880 it
->char_to_display
= c
;
6884 it
->char_to_display
= it
->c
;
6888 /* Adjust face id for a multibyte character. There are no multibyte
6889 character in unibyte text. */
6890 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
6893 && FRAME_WINDOW_P (it
->f
))
6895 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
6897 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
6899 /* Automatic composition with glyph-string. */
6900 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
6902 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
6906 ptrdiff_t pos
= (it
->s
? -1
6907 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
6908 : IT_CHARPOS (*it
));
6911 if (it
->what
== IT_CHARACTER
)
6912 c
= it
->char_to_display
;
6915 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
6919 for (i
= 0; i
< cmp
->glyph_len
; i
++)
6920 /* TAB in a composition means display glyphs with
6921 padding space on the left or right. */
6922 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
6925 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, pos
, it
->string
);
6930 /* Is this character the last one of a run of characters with
6931 box? If yes, set IT->end_of_box_run_p to 1. */
6935 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
6937 int face_id
= underlying_face_id (it
);
6938 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
6942 if (face
->box
== FACE_NO_BOX
)
6944 /* If the box comes from face properties in a
6945 display string, check faces in that string. */
6946 int string_face_id
= face_after_it_pos (it
);
6947 it
->end_of_box_run_p
6948 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
6951 /* Otherwise, the box comes from the underlying face.
6952 If this is the last string character displayed, check
6953 the next buffer location. */
6954 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
6955 && (it
->current
.overlay_string_index
6956 == it
->n_overlay_strings
- 1))
6960 struct text_pos pos
= it
->current
.pos
;
6961 INC_TEXT_POS (pos
, it
->multibyte_p
);
6963 next_face_id
= face_at_buffer_position
6964 (it
->w
, CHARPOS (pos
), it
->region_beg_charpos
,
6965 it
->region_end_charpos
, &ignore
,
6966 (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
), 0,
6968 it
->end_of_box_run_p
6969 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
6976 int face_id
= face_after_it_pos (it
);
6977 it
->end_of_box_run_p
6978 = (face_id
!= it
->face_id
6979 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
6982 /* If we reached the end of the object we've been iterating (e.g., a
6983 display string or an overlay string), and there's something on
6984 IT->stack, proceed with what's on the stack. It doesn't make
6985 sense to return zero if there's unprocessed stuff on the stack,
6986 because otherwise that stuff will never be displayed. */
6987 if (!success_p
&& it
->sp
> 0)
6989 set_iterator_to_next (it
, 0);
6990 success_p
= get_next_display_element (it
);
6993 /* Value is 0 if end of buffer or string reached. */
6998 /* Move IT to the next display element.
7000 RESEAT_P non-zero means if called on a newline in buffer text,
7001 skip to the next visible line start.
7003 Functions get_next_display_element and set_iterator_to_next are
7004 separate because I find this arrangement easier to handle than a
7005 get_next_display_element function that also increments IT's
7006 position. The way it is we can first look at an iterator's current
7007 display element, decide whether it fits on a line, and if it does,
7008 increment the iterator position. The other way around we probably
7009 would either need a flag indicating whether the iterator has to be
7010 incremented the next time, or we would have to implement a
7011 decrement position function which would not be easy to write. */
7014 set_iterator_to_next (struct it
*it
, int reseat_p
)
7016 /* Reset flags indicating start and end of a sequence of characters
7017 with box. Reset them at the start of this function because
7018 moving the iterator to a new position might set them. */
7019 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
7023 case GET_FROM_BUFFER
:
7024 /* The current display element of IT is a character from
7025 current_buffer. Advance in the buffer, and maybe skip over
7026 invisible lines that are so because of selective display. */
7027 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
7028 reseat_at_next_visible_line_start (it
, 0);
7029 else if (it
->cmp_it
.id
>= 0)
7031 /* We are currently getting glyphs from a composition. */
7036 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7037 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7038 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7040 it
->cmp_it
.from
= it
->cmp_it
.to
;
7045 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7047 it
->end_charpos
, Qnil
);
7050 else if (! it
->cmp_it
.reversed_p
)
7052 /* Composition created while scanning forward. */
7053 /* Update IT's char/byte positions to point to the first
7054 character of the next grapheme cluster, or to the
7055 character visually after the current composition. */
7056 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7057 bidi_move_to_visually_next (&it
->bidi_it
);
7058 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7059 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7061 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7063 /* Proceed to the next grapheme cluster. */
7064 it
->cmp_it
.from
= it
->cmp_it
.to
;
7068 /* No more grapheme clusters in this composition.
7069 Find the next stop position. */
7070 ptrdiff_t stop
= it
->end_charpos
;
7071 if (it
->bidi_it
.scan_dir
< 0)
7072 /* Now we are scanning backward and don't know
7075 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7076 IT_BYTEPOS (*it
), stop
, Qnil
);
7081 /* Composition created while scanning backward. */
7082 /* Update IT's char/byte positions to point to the last
7083 character of the previous grapheme cluster, or the
7084 character visually after the current composition. */
7085 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7086 bidi_move_to_visually_next (&it
->bidi_it
);
7087 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7088 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7089 if (it
->cmp_it
.from
> 0)
7091 /* Proceed to the previous grapheme cluster. */
7092 it
->cmp_it
.to
= it
->cmp_it
.from
;
7096 /* No more grapheme clusters in this composition.
7097 Find the next stop position. */
7098 ptrdiff_t stop
= it
->end_charpos
;
7099 if (it
->bidi_it
.scan_dir
< 0)
7100 /* Now we are scanning backward and don't know
7103 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7104 IT_BYTEPOS (*it
), stop
, Qnil
);
7110 eassert (it
->len
!= 0);
7114 IT_BYTEPOS (*it
) += it
->len
;
7115 IT_CHARPOS (*it
) += 1;
7119 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7120 /* If this is a new paragraph, determine its base
7121 direction (a.k.a. its base embedding level). */
7122 if (it
->bidi_it
.new_paragraph
)
7123 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
7124 bidi_move_to_visually_next (&it
->bidi_it
);
7125 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7126 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7127 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7129 /* As the scan direction was changed, we must
7130 re-compute the stop position for composition. */
7131 ptrdiff_t stop
= it
->end_charpos
;
7132 if (it
->bidi_it
.scan_dir
< 0)
7134 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7135 IT_BYTEPOS (*it
), stop
, Qnil
);
7138 eassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
7142 case GET_FROM_C_STRING
:
7143 /* Current display element of IT is from a C string. */
7145 /* If the string position is beyond string's end, it means
7146 next_element_from_c_string is padding the string with
7147 blanks, in which case we bypass the bidi iterator,
7148 because it cannot deal with such virtual characters. */
7149 || IT_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7151 IT_BYTEPOS (*it
) += it
->len
;
7152 IT_CHARPOS (*it
) += 1;
7156 bidi_move_to_visually_next (&it
->bidi_it
);
7157 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7158 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7162 case GET_FROM_DISPLAY_VECTOR
:
7163 /* Current display element of IT is from a display table entry.
7164 Advance in the display table definition. Reset it to null if
7165 end reached, and continue with characters from buffers/
7167 ++it
->current
.dpvec_index
;
7169 /* Restore face of the iterator to what they were before the
7170 display vector entry (these entries may contain faces). */
7171 it
->face_id
= it
->saved_face_id
;
7173 if (it
->dpvec
+ it
->current
.dpvec_index
>= it
->dpend
)
7175 int recheck_faces
= it
->ellipsis_p
;
7178 it
->method
= GET_FROM_C_STRING
;
7179 else if (STRINGP (it
->string
))
7180 it
->method
= GET_FROM_STRING
;
7183 it
->method
= GET_FROM_BUFFER
;
7184 it
->object
= it
->w
->buffer
;
7188 it
->current
.dpvec_index
= -1;
7190 /* Skip over characters which were displayed via IT->dpvec. */
7191 if (it
->dpvec_char_len
< 0)
7192 reseat_at_next_visible_line_start (it
, 1);
7193 else if (it
->dpvec_char_len
> 0)
7195 if (it
->method
== GET_FROM_STRING
7196 && it
->n_overlay_strings
> 0)
7197 it
->ignore_overlay_strings_at_pos_p
= 1;
7198 it
->len
= it
->dpvec_char_len
;
7199 set_iterator_to_next (it
, reseat_p
);
7202 /* Maybe recheck faces after display vector */
7204 it
->stop_charpos
= IT_CHARPOS (*it
);
7208 case GET_FROM_STRING
:
7209 /* Current display element is a character from a Lisp string. */
7210 eassert (it
->s
== NULL
&& STRINGP (it
->string
));
7211 /* Don't advance past string end. These conditions are true
7212 when set_iterator_to_next is called at the end of
7213 get_next_display_element, in which case the Lisp string is
7214 already exhausted, and all we want is pop the iterator
7216 if (it
->current
.overlay_string_index
>= 0)
7218 /* This is an overlay string, so there's no padding with
7219 spaces, and the number of characters in the string is
7220 where the string ends. */
7221 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7222 goto consider_string_end
;
7226 /* Not an overlay string. There could be padding, so test
7227 against it->end_charpos . */
7228 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7229 goto consider_string_end
;
7231 if (it
->cmp_it
.id
>= 0)
7237 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7238 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7239 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7240 it
->cmp_it
.from
= it
->cmp_it
.to
;
7244 composition_compute_stop_pos (&it
->cmp_it
,
7245 IT_STRING_CHARPOS (*it
),
7246 IT_STRING_BYTEPOS (*it
),
7247 it
->end_charpos
, it
->string
);
7250 else if (! it
->cmp_it
.reversed_p
)
7252 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7253 bidi_move_to_visually_next (&it
->bidi_it
);
7254 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7255 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7257 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7258 it
->cmp_it
.from
= it
->cmp_it
.to
;
7261 ptrdiff_t stop
= it
->end_charpos
;
7262 if (it
->bidi_it
.scan_dir
< 0)
7264 composition_compute_stop_pos (&it
->cmp_it
,
7265 IT_STRING_CHARPOS (*it
),
7266 IT_STRING_BYTEPOS (*it
), stop
,
7272 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7273 bidi_move_to_visually_next (&it
->bidi_it
);
7274 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7275 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7276 if (it
->cmp_it
.from
> 0)
7277 it
->cmp_it
.to
= it
->cmp_it
.from
;
7280 ptrdiff_t stop
= it
->end_charpos
;
7281 if (it
->bidi_it
.scan_dir
< 0)
7283 composition_compute_stop_pos (&it
->cmp_it
,
7284 IT_STRING_CHARPOS (*it
),
7285 IT_STRING_BYTEPOS (*it
), stop
,
7293 /* If the string position is beyond string's end, it
7294 means next_element_from_string is padding the string
7295 with blanks, in which case we bypass the bidi
7296 iterator, because it cannot deal with such virtual
7298 || IT_STRING_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7300 IT_STRING_BYTEPOS (*it
) += it
->len
;
7301 IT_STRING_CHARPOS (*it
) += 1;
7305 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7307 bidi_move_to_visually_next (&it
->bidi_it
);
7308 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7309 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7310 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7312 ptrdiff_t stop
= it
->end_charpos
;
7314 if (it
->bidi_it
.scan_dir
< 0)
7316 composition_compute_stop_pos (&it
->cmp_it
,
7317 IT_STRING_CHARPOS (*it
),
7318 IT_STRING_BYTEPOS (*it
), stop
,
7324 consider_string_end
:
7326 if (it
->current
.overlay_string_index
>= 0)
7328 /* IT->string is an overlay string. Advance to the
7329 next, if there is one. */
7330 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7333 next_overlay_string (it
);
7335 setup_for_ellipsis (it
, 0);
7340 /* IT->string is not an overlay string. If we reached
7341 its end, and there is something on IT->stack, proceed
7342 with what is on the stack. This can be either another
7343 string, this time an overlay string, or a buffer. */
7344 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
7348 if (it
->method
== GET_FROM_STRING
)
7349 goto consider_string_end
;
7354 case GET_FROM_IMAGE
:
7355 case GET_FROM_STRETCH
:
7356 #ifdef HAVE_XWIDGETS
7357 case GET_FROM_XWIDGET
:
7359 /* The position etc with which we have to proceed are on
7360 the stack. The position may be at the end of a string,
7361 if the `display' property takes up the whole string. */
7362 eassert (it
->sp
> 0);
7364 if (it
->method
== GET_FROM_STRING
)
7365 goto consider_string_end
;
7369 /* There are no other methods defined, so this should be a bug. */
7373 eassert (it
->method
!= GET_FROM_STRING
7374 || (STRINGP (it
->string
)
7375 && IT_STRING_CHARPOS (*it
) >= 0));
7378 /* Load IT's display element fields with information about the next
7379 display element which comes from a display table entry or from the
7380 result of translating a control character to one of the forms `^C'
7383 IT->dpvec holds the glyphs to return as characters.
7384 IT->saved_face_id holds the face id before the display vector--it
7385 is restored into IT->face_id in set_iterator_to_next. */
7388 next_element_from_display_vector (struct it
*it
)
7393 eassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
7395 it
->face_id
= it
->saved_face_id
;
7397 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
7398 That seemed totally bogus - so I changed it... */
7399 gc
= it
->dpvec
[it
->current
.dpvec_index
];
7401 if (GLYPH_CODE_P (gc
))
7403 it
->c
= GLYPH_CODE_CHAR (gc
);
7404 it
->len
= CHAR_BYTES (it
->c
);
7406 /* The entry may contain a face id to use. Such a face id is
7407 the id of a Lisp face, not a realized face. A face id of
7408 zero means no face is specified. */
7409 if (it
->dpvec_face_id
>= 0)
7410 it
->face_id
= it
->dpvec_face_id
;
7413 int lface_id
= GLYPH_CODE_FACE (gc
);
7415 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
7420 /* Display table entry is invalid. Return a space. */
7421 it
->c
= ' ', it
->len
= 1;
7423 /* Don't change position and object of the iterator here. They are
7424 still the values of the character that had this display table
7425 entry or was translated, and that's what we want. */
7426 it
->what
= IT_CHARACTER
;
7430 /* Get the first element of string/buffer in the visual order, after
7431 being reseated to a new position in a string or a buffer. */
7433 get_visually_first_element (struct it
*it
)
7435 int string_p
= STRINGP (it
->string
) || it
->s
;
7436 ptrdiff_t eob
= (string_p
? it
->bidi_it
.string
.schars
: ZV
);
7437 ptrdiff_t bob
= (string_p
? 0 : BEGV
);
7439 if (STRINGP (it
->string
))
7441 it
->bidi_it
.charpos
= IT_STRING_CHARPOS (*it
);
7442 it
->bidi_it
.bytepos
= IT_STRING_BYTEPOS (*it
);
7446 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
7447 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
7450 if (it
->bidi_it
.charpos
== eob
)
7452 /* Nothing to do, but reset the FIRST_ELT flag, like
7453 bidi_paragraph_init does, because we are not going to
7455 it
->bidi_it
.first_elt
= 0;
7457 else if (it
->bidi_it
.charpos
== bob
7459 && (FETCH_CHAR (it
->bidi_it
.bytepos
- 1) == '\n'
7460 || FETCH_CHAR (it
->bidi_it
.bytepos
) == '\n')))
7462 /* If we are at the beginning of a line/string, we can produce
7463 the next element right away. */
7464 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7465 bidi_move_to_visually_next (&it
->bidi_it
);
7469 ptrdiff_t orig_bytepos
= it
->bidi_it
.bytepos
;
7471 /* We need to prime the bidi iterator starting at the line's or
7472 string's beginning, before we will be able to produce the
7475 it
->bidi_it
.charpos
= it
->bidi_it
.bytepos
= 0;
7478 = find_next_newline_no_quit (IT_CHARPOS (*it
), -1,
7479 &it
->bidi_it
.bytepos
);
7480 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7483 /* Now return to buffer/string position where we were asked
7484 to get the next display element, and produce that. */
7485 bidi_move_to_visually_next (&it
->bidi_it
);
7487 while (it
->bidi_it
.bytepos
!= orig_bytepos
7488 && it
->bidi_it
.charpos
< eob
);
7491 /* Adjust IT's position information to where we ended up. */
7492 if (STRINGP (it
->string
))
7494 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7495 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7499 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7500 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7503 if (STRINGP (it
->string
) || !it
->s
)
7505 ptrdiff_t stop
, charpos
, bytepos
;
7507 if (STRINGP (it
->string
))
7510 stop
= SCHARS (it
->string
);
7511 if (stop
> it
->end_charpos
)
7512 stop
= it
->end_charpos
;
7513 charpos
= IT_STRING_CHARPOS (*it
);
7514 bytepos
= IT_STRING_BYTEPOS (*it
);
7518 stop
= it
->end_charpos
;
7519 charpos
= IT_CHARPOS (*it
);
7520 bytepos
= IT_BYTEPOS (*it
);
7522 if (it
->bidi_it
.scan_dir
< 0)
7524 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
, stop
,
7529 /* Load IT with the next display element from Lisp string IT->string.
7530 IT->current.string_pos is the current position within the string.
7531 If IT->current.overlay_string_index >= 0, the Lisp string is an
7535 next_element_from_string (struct it
*it
)
7537 struct text_pos position
;
7539 eassert (STRINGP (it
->string
));
7540 eassert (!it
->bidi_p
|| EQ (it
->string
, it
->bidi_it
.string
.lstring
));
7541 eassert (IT_STRING_CHARPOS (*it
) >= 0);
7542 position
= it
->current
.string_pos
;
7544 /* With bidi reordering, the character to display might not be the
7545 character at IT_STRING_CHARPOS. BIDI_IT.FIRST_ELT non-zero means
7546 that we were reseat()ed to a new string, whose paragraph
7547 direction is not known. */
7548 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7550 get_visually_first_element (it
);
7551 SET_TEXT_POS (position
, IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
));
7554 /* Time to check for invisible text? */
7555 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
7557 if (IT_STRING_CHARPOS (*it
) >= it
->stop_charpos
)
7560 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7561 || IT_STRING_CHARPOS (*it
) == it
->stop_charpos
))
7563 /* With bidi non-linear iteration, we could find
7564 ourselves far beyond the last computed stop_charpos,
7565 with several other stop positions in between that we
7566 missed. Scan them all now, in buffer's logical
7567 order, until we find and handle the last stop_charpos
7568 that precedes our current position. */
7569 handle_stop_backwards (it
, it
->stop_charpos
);
7570 return GET_NEXT_DISPLAY_ELEMENT (it
);
7576 /* Take note of the stop position we just moved
7577 across, for when we will move back across it. */
7578 it
->prev_stop
= it
->stop_charpos
;
7579 /* If we are at base paragraph embedding level, take
7580 note of the last stop position seen at this
7582 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7583 it
->base_level_stop
= it
->stop_charpos
;
7587 /* Since a handler may have changed IT->method, we must
7589 return GET_NEXT_DISPLAY_ELEMENT (it
);
7593 /* If we are before prev_stop, we may have overstepped
7594 on our way backwards a stop_pos, and if so, we need
7595 to handle that stop_pos. */
7596 && IT_STRING_CHARPOS (*it
) < it
->prev_stop
7597 /* We can sometimes back up for reasons that have nothing
7598 to do with bidi reordering. E.g., compositions. The
7599 code below is only needed when we are above the base
7600 embedding level, so test for that explicitly. */
7601 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7603 /* If we lost track of base_level_stop, we have no better
7604 place for handle_stop_backwards to start from than string
7605 beginning. This happens, e.g., when we were reseated to
7606 the previous screenful of text by vertical-motion. */
7607 if (it
->base_level_stop
<= 0
7608 || IT_STRING_CHARPOS (*it
) < it
->base_level_stop
)
7609 it
->base_level_stop
= 0;
7610 handle_stop_backwards (it
, it
->base_level_stop
);
7611 return GET_NEXT_DISPLAY_ELEMENT (it
);
7615 if (it
->current
.overlay_string_index
>= 0)
7617 /* Get the next character from an overlay string. In overlay
7618 strings, there is no field width or padding with spaces to
7620 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7625 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7626 IT_STRING_BYTEPOS (*it
),
7627 it
->bidi_it
.scan_dir
< 0
7629 : SCHARS (it
->string
))
7630 && next_element_from_composition (it
))
7634 else if (STRING_MULTIBYTE (it
->string
))
7636 const unsigned char *s
= (SDATA (it
->string
)
7637 + IT_STRING_BYTEPOS (*it
));
7638 it
->c
= string_char_and_length (s
, &it
->len
);
7642 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7648 /* Get the next character from a Lisp string that is not an
7649 overlay string. Such strings come from the mode line, for
7650 example. We may have to pad with spaces, or truncate the
7651 string. See also next_element_from_c_string. */
7652 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7657 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
7659 /* Pad with spaces. */
7660 it
->c
= ' ', it
->len
= 1;
7661 CHARPOS (position
) = BYTEPOS (position
) = -1;
7663 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7664 IT_STRING_BYTEPOS (*it
),
7665 it
->bidi_it
.scan_dir
< 0
7667 : it
->string_nchars
)
7668 && next_element_from_composition (it
))
7672 else if (STRING_MULTIBYTE (it
->string
))
7674 const unsigned char *s
= (SDATA (it
->string
)
7675 + IT_STRING_BYTEPOS (*it
));
7676 it
->c
= string_char_and_length (s
, &it
->len
);
7680 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7685 /* Record what we have and where it came from. */
7686 it
->what
= IT_CHARACTER
;
7687 it
->object
= it
->string
;
7688 it
->position
= position
;
7693 /* Load IT with next display element from C string IT->s.
7694 IT->string_nchars is the maximum number of characters to return
7695 from the string. IT->end_charpos may be greater than
7696 IT->string_nchars when this function is called, in which case we
7697 may have to return padding spaces. Value is zero if end of string
7698 reached, including padding spaces. */
7701 next_element_from_c_string (struct it
*it
)
7706 eassert (!it
->bidi_p
|| it
->s
== it
->bidi_it
.string
.s
);
7707 it
->what
= IT_CHARACTER
;
7708 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
7711 /* With bidi reordering, the character to display might not be the
7712 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7713 we were reseated to a new string, whose paragraph direction is
7715 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7716 get_visually_first_element (it
);
7718 /* IT's position can be greater than IT->string_nchars in case a
7719 field width or precision has been specified when the iterator was
7721 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7723 /* End of the game. */
7727 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
7729 /* Pad with spaces. */
7730 it
->c
= ' ', it
->len
= 1;
7731 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
7733 else if (it
->multibyte_p
)
7734 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
), &it
->len
);
7736 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
7742 /* Set up IT to return characters from an ellipsis, if appropriate.
7743 The definition of the ellipsis glyphs may come from a display table
7744 entry. This function fills IT with the first glyph from the
7745 ellipsis if an ellipsis is to be displayed. */
7748 next_element_from_ellipsis (struct it
*it
)
7750 if (it
->selective_display_ellipsis_p
)
7751 setup_for_ellipsis (it
, it
->len
);
7754 /* The face at the current position may be different from the
7755 face we find after the invisible text. Remember what it
7756 was in IT->saved_face_id, and signal that it's there by
7757 setting face_before_selective_p. */
7758 it
->saved_face_id
= it
->face_id
;
7759 it
->method
= GET_FROM_BUFFER
;
7760 it
->object
= it
->w
->buffer
;
7761 reseat_at_next_visible_line_start (it
, 1);
7762 it
->face_before_selective_p
= 1;
7765 return GET_NEXT_DISPLAY_ELEMENT (it
);
7769 /* Deliver an image display element. The iterator IT is already
7770 filled with image information (done in handle_display_prop). Value
7775 next_element_from_image (struct it
*it
)
7777 it
->what
= IT_IMAGE
;
7778 it
->ignore_overlay_strings_at_pos_p
= 0;
7782 #ifdef HAVE_XWIDGETS
7783 /* im not sure about this FIXME JAVE*/
7785 next_element_from_xwidget (struct it
*it
)
7787 it
->what
= IT_XWIDGET
;
7788 //assert_valid_xwidget_id(it->xwidget_id,"next_element_from_xwidget");
7789 //this is shaky because why do we set "what" if we dont set the other parts??
7790 //printf("xwidget_id %d: in next_element_from_xwidget: FIXME \n", it->xwidget_id);
7796 /* Fill iterator IT with next display element from a stretch glyph
7797 property. IT->object is the value of the text property. Value is
7801 next_element_from_stretch (struct it
*it
)
7803 it
->what
= IT_STRETCH
;
7807 /* Scan backwards from IT's current position until we find a stop
7808 position, or until BEGV. This is called when we find ourself
7809 before both the last known prev_stop and base_level_stop while
7810 reordering bidirectional text. */
7813 compute_stop_pos_backwards (struct it
*it
)
7815 const int SCAN_BACK_LIMIT
= 1000;
7816 struct text_pos pos
;
7817 struct display_pos save_current
= it
->current
;
7818 struct text_pos save_position
= it
->position
;
7819 ptrdiff_t charpos
= IT_CHARPOS (*it
);
7820 ptrdiff_t where_we_are
= charpos
;
7821 ptrdiff_t save_stop_pos
= it
->stop_charpos
;
7822 ptrdiff_t save_end_pos
= it
->end_charpos
;
7824 eassert (NILP (it
->string
) && !it
->s
);
7825 eassert (it
->bidi_p
);
7829 it
->end_charpos
= min (charpos
+ 1, ZV
);
7830 charpos
= max (charpos
- SCAN_BACK_LIMIT
, BEGV
);
7831 SET_TEXT_POS (pos
, charpos
, CHAR_TO_BYTE (charpos
));
7832 reseat_1 (it
, pos
, 0);
7833 compute_stop_pos (it
);
7834 /* We must advance forward, right? */
7835 if (it
->stop_charpos
<= charpos
)
7838 while (charpos
> BEGV
&& it
->stop_charpos
>= it
->end_charpos
);
7840 if (it
->stop_charpos
<= where_we_are
)
7841 it
->prev_stop
= it
->stop_charpos
;
7843 it
->prev_stop
= BEGV
;
7845 it
->current
= save_current
;
7846 it
->position
= save_position
;
7847 it
->stop_charpos
= save_stop_pos
;
7848 it
->end_charpos
= save_end_pos
;
7851 /* Scan forward from CHARPOS in the current buffer/string, until we
7852 find a stop position > current IT's position. Then handle the stop
7853 position before that. This is called when we bump into a stop
7854 position while reordering bidirectional text. CHARPOS should be
7855 the last previously processed stop_pos (or BEGV/0, if none were
7856 processed yet) whose position is less that IT's current
7860 handle_stop_backwards (struct it
*it
, ptrdiff_t charpos
)
7862 int bufp
= !STRINGP (it
->string
);
7863 ptrdiff_t where_we_are
= (bufp
? IT_CHARPOS (*it
) : IT_STRING_CHARPOS (*it
));
7864 struct display_pos save_current
= it
->current
;
7865 struct text_pos save_position
= it
->position
;
7866 struct text_pos pos1
;
7867 ptrdiff_t next_stop
;
7869 /* Scan in strict logical order. */
7870 eassert (it
->bidi_p
);
7874 it
->prev_stop
= charpos
;
7877 SET_TEXT_POS (pos1
, charpos
, CHAR_TO_BYTE (charpos
));
7878 reseat_1 (it
, pos1
, 0);
7881 it
->current
.string_pos
= string_pos (charpos
, it
->string
);
7882 compute_stop_pos (it
);
7883 /* We must advance forward, right? */
7884 if (it
->stop_charpos
<= it
->prev_stop
)
7886 charpos
= it
->stop_charpos
;
7888 while (charpos
<= where_we_are
);
7891 it
->current
= save_current
;
7892 it
->position
= save_position
;
7893 next_stop
= it
->stop_charpos
;
7894 it
->stop_charpos
= it
->prev_stop
;
7896 it
->stop_charpos
= next_stop
;
7899 /* Load IT with the next display element from current_buffer. Value
7900 is zero if end of buffer reached. IT->stop_charpos is the next
7901 position at which to stop and check for text properties or buffer
7905 next_element_from_buffer (struct it
*it
)
7909 eassert (IT_CHARPOS (*it
) >= BEGV
);
7910 eassert (NILP (it
->string
) && !it
->s
);
7911 eassert (!it
->bidi_p
7912 || (EQ (it
->bidi_it
.string
.lstring
, Qnil
)
7913 && it
->bidi_it
.string
.s
== NULL
));
7915 /* With bidi reordering, the character to display might not be the
7916 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7917 we were reseat()ed to a new buffer position, which is potentially
7918 a different paragraph. */
7919 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7921 get_visually_first_element (it
);
7922 SET_TEXT_POS (it
->position
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7925 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
7927 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7929 int overlay_strings_follow_p
;
7931 /* End of the game, except when overlay strings follow that
7932 haven't been returned yet. */
7933 if (it
->overlay_strings_at_end_processed_p
)
7934 overlay_strings_follow_p
= 0;
7937 it
->overlay_strings_at_end_processed_p
= 1;
7938 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
7941 if (overlay_strings_follow_p
)
7942 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
7946 it
->position
= it
->current
.pos
;
7950 else if (!(!it
->bidi_p
7951 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7952 || IT_CHARPOS (*it
) == it
->stop_charpos
))
7954 /* With bidi non-linear iteration, we could find ourselves
7955 far beyond the last computed stop_charpos, with several
7956 other stop positions in between that we missed. Scan
7957 them all now, in buffer's logical order, until we find
7958 and handle the last stop_charpos that precedes our
7959 current position. */
7960 handle_stop_backwards (it
, it
->stop_charpos
);
7961 return GET_NEXT_DISPLAY_ELEMENT (it
);
7967 /* Take note of the stop position we just moved across,
7968 for when we will move back across it. */
7969 it
->prev_stop
= it
->stop_charpos
;
7970 /* If we are at base paragraph embedding level, take
7971 note of the last stop position seen at this
7973 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7974 it
->base_level_stop
= it
->stop_charpos
;
7977 return GET_NEXT_DISPLAY_ELEMENT (it
);
7981 /* If we are before prev_stop, we may have overstepped on
7982 our way backwards a stop_pos, and if so, we need to
7983 handle that stop_pos. */
7984 && IT_CHARPOS (*it
) < it
->prev_stop
7985 /* We can sometimes back up for reasons that have nothing
7986 to do with bidi reordering. E.g., compositions. The
7987 code below is only needed when we are above the base
7988 embedding level, so test for that explicitly. */
7989 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7991 if (it
->base_level_stop
<= 0
7992 || IT_CHARPOS (*it
) < it
->base_level_stop
)
7994 /* If we lost track of base_level_stop, we need to find
7995 prev_stop by looking backwards. This happens, e.g., when
7996 we were reseated to the previous screenful of text by
7998 it
->base_level_stop
= BEGV
;
7999 compute_stop_pos_backwards (it
);
8000 handle_stop_backwards (it
, it
->prev_stop
);
8003 handle_stop_backwards (it
, it
->base_level_stop
);
8004 return GET_NEXT_DISPLAY_ELEMENT (it
);
8008 /* No face changes, overlays etc. in sight, so just return a
8009 character from current_buffer. */
8013 /* Maybe run the redisplay end trigger hook. Performance note:
8014 This doesn't seem to cost measurable time. */
8015 if (it
->redisplay_end_trigger_charpos
8017 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
8018 run_redisplay_end_trigger_hook (it
);
8020 stop
= it
->bidi_it
.scan_dir
< 0 ? -1 : it
->end_charpos
;
8021 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
8023 && next_element_from_composition (it
))
8028 /* Get the next character, maybe multibyte. */
8029 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
8030 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
8031 it
->c
= STRING_CHAR_AND_LENGTH (p
, it
->len
);
8033 it
->c
= *p
, it
->len
= 1;
8035 /* Record what we have and where it came from. */
8036 it
->what
= IT_CHARACTER
;
8037 it
->object
= it
->w
->buffer
;
8038 it
->position
= it
->current
.pos
;
8040 /* Normally we return the character found above, except when we
8041 really want to return an ellipsis for selective display. */
8046 /* A value of selective > 0 means hide lines indented more
8047 than that number of columns. */
8048 if (it
->selective
> 0
8049 && IT_CHARPOS (*it
) + 1 < ZV
8050 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
8051 IT_BYTEPOS (*it
) + 1,
8054 success_p
= next_element_from_ellipsis (it
);
8055 it
->dpvec_char_len
= -1;
8058 else if (it
->c
== '\r' && it
->selective
== -1)
8060 /* A value of selective == -1 means that everything from the
8061 CR to the end of the line is invisible, with maybe an
8062 ellipsis displayed for it. */
8063 success_p
= next_element_from_ellipsis (it
);
8064 it
->dpvec_char_len
= -1;
8069 /* Value is zero if end of buffer reached. */
8070 eassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
8075 /* Run the redisplay end trigger hook for IT. */
8078 run_redisplay_end_trigger_hook (struct it
*it
)
8080 Lisp_Object args
[3];
8082 /* IT->glyph_row should be non-null, i.e. we should be actually
8083 displaying something, or otherwise we should not run the hook. */
8084 eassert (it
->glyph_row
);
8086 /* Set up hook arguments. */
8087 args
[0] = Qredisplay_end_trigger_functions
;
8088 args
[1] = it
->window
;
8089 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
8090 it
->redisplay_end_trigger_charpos
= 0;
8092 /* Since we are *trying* to run these functions, don't try to run
8093 them again, even if they get an error. */
8094 wset_redisplay_end_trigger (it
->w
, Qnil
);
8095 Frun_hook_with_args (3, args
);
8097 /* Notice if it changed the face of the character we are on. */
8098 handle_face_prop (it
);
8102 /* Deliver a composition display element. Unlike the other
8103 next_element_from_XXX, this function is not registered in the array
8104 get_next_element[]. It is called from next_element_from_buffer and
8105 next_element_from_string when necessary. */
8108 next_element_from_composition (struct it
*it
)
8110 it
->what
= IT_COMPOSITION
;
8111 it
->len
= it
->cmp_it
.nbytes
;
8112 if (STRINGP (it
->string
))
8116 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
8117 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
8120 it
->position
= it
->current
.string_pos
;
8121 it
->object
= it
->string
;
8122 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
8123 IT_STRING_BYTEPOS (*it
), it
->string
);
8129 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
8130 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
8133 if (it
->bidi_it
.new_paragraph
)
8134 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
8135 /* Resync the bidi iterator with IT's new position.
8136 FIXME: this doesn't support bidirectional text. */
8137 while (it
->bidi_it
.charpos
< IT_CHARPOS (*it
))
8138 bidi_move_to_visually_next (&it
->bidi_it
);
8142 it
->position
= it
->current
.pos
;
8143 it
->object
= it
->w
->buffer
;
8144 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
8145 IT_BYTEPOS (*it
), Qnil
);
8152 /***********************************************************************
8153 Moving an iterator without producing glyphs
8154 ***********************************************************************/
8156 /* Check if iterator is at a position corresponding to a valid buffer
8157 position after some move_it_ call. */
8159 #define IT_POS_VALID_AFTER_MOVE_P(it) \
8160 ((it)->method == GET_FROM_STRING \
8161 ? IT_STRING_CHARPOS (*it) == 0 \
8165 /* Move iterator IT to a specified buffer or X position within one
8166 line on the display without producing glyphs.
8168 OP should be a bit mask including some or all of these bits:
8169 MOVE_TO_X: Stop upon reaching x-position TO_X.
8170 MOVE_TO_POS: Stop upon reaching buffer or string position TO_CHARPOS.
8171 Regardless of OP's value, stop upon reaching the end of the display line.
8173 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
8174 This means, in particular, that TO_X includes window's horizontal
8177 The return value has several possible values that
8178 say what condition caused the scan to stop:
8180 MOVE_POS_MATCH_OR_ZV
8181 - when TO_POS or ZV was reached.
8184 -when TO_X was reached before TO_POS or ZV were reached.
8187 - when we reached the end of the display area and the line must
8191 - when we reached the end of the display area and the line is
8195 - when we stopped at a line end, i.e. a newline or a CR and selective
8198 static enum move_it_result
8199 move_it_in_display_line_to (struct it
*it
,
8200 ptrdiff_t to_charpos
, int to_x
,
8201 enum move_operation_enum op
)
8203 enum move_it_result result
= MOVE_UNDEFINED
;
8204 struct glyph_row
*saved_glyph_row
;
8205 struct it wrap_it
, atpos_it
, atx_it
, ppos_it
;
8206 void *wrap_data
= NULL
, *atpos_data
= NULL
, *atx_data
= NULL
;
8207 void *ppos_data
= NULL
;
8209 enum it_method prev_method
= it
->method
;
8210 ptrdiff_t prev_pos
= IT_CHARPOS (*it
);
8211 int saw_smaller_pos
= prev_pos
< to_charpos
;
8213 /* Don't produce glyphs in produce_glyphs. */
8214 saved_glyph_row
= it
->glyph_row
;
8215 it
->glyph_row
= NULL
;
8217 /* Use wrap_it to save a copy of IT wherever a word wrap could
8218 occur. Use atpos_it to save a copy of IT at the desired buffer
8219 position, if found, so that we can scan ahead and check if the
8220 word later overshoots the window edge. Use atx_it similarly, for
8226 /* Use ppos_it under bidi reordering to save a copy of IT for the
8227 position > CHARPOS that is the closest to CHARPOS. We restore
8228 that position in IT when we have scanned the entire display line
8229 without finding a match for CHARPOS and all the character
8230 positions are greater than CHARPOS. */
8233 SAVE_IT (ppos_it
, *it
, ppos_data
);
8234 SET_TEXT_POS (ppos_it
.current
.pos
, ZV
, ZV_BYTE
);
8235 if ((op
& MOVE_TO_POS
) && IT_CHARPOS (*it
) >= to_charpos
)
8236 SAVE_IT (ppos_it
, *it
, ppos_data
);
8239 #define BUFFER_POS_REACHED_P() \
8240 ((op & MOVE_TO_POS) != 0 \
8241 && BUFFERP (it->object) \
8242 && (IT_CHARPOS (*it) == to_charpos \
8244 || BIDI_AT_BASE_LEVEL (it->bidi_it)) \
8245 && IT_CHARPOS (*it) > to_charpos) \
8246 || (it->what == IT_COMPOSITION \
8247 && ((IT_CHARPOS (*it) > to_charpos \
8248 && to_charpos >= it->cmp_it.charpos) \
8249 || (IT_CHARPOS (*it) < to_charpos \
8250 && to_charpos <= it->cmp_it.charpos)))) \
8251 && (it->method == GET_FROM_BUFFER \
8252 || (it->method == GET_FROM_DISPLAY_VECTOR \
8253 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
8255 /* If there's a line-/wrap-prefix, handle it. */
8256 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
8257 && it
->current_y
< it
->last_visible_y
)
8258 handle_line_prefix (it
);
8260 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8261 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8265 int x
, i
, ascent
= 0, descent
= 0;
8267 /* Utility macro to reset an iterator with x, ascent, and descent. */
8268 #define IT_RESET_X_ASCENT_DESCENT(IT) \
8269 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
8270 (IT)->max_descent = descent)
8272 /* Stop if we move beyond TO_CHARPOS (after an image or a
8273 display string or stretch glyph). */
8274 if ((op
& MOVE_TO_POS
) != 0
8275 && BUFFERP (it
->object
)
8276 && it
->method
== GET_FROM_BUFFER
8278 /* When the iterator is at base embedding level, we
8279 are guaranteed that characters are delivered for
8280 display in strictly increasing order of their
8281 buffer positions. */
8282 || BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8283 && IT_CHARPOS (*it
) > to_charpos
)
8285 && (prev_method
== GET_FROM_IMAGE
8286 || prev_method
== GET_FROM_STRETCH
8287 || prev_method
== GET_FROM_STRING
)
8288 /* Passed TO_CHARPOS from left to right. */
8289 && ((prev_pos
< to_charpos
8290 && IT_CHARPOS (*it
) > to_charpos
)
8291 /* Passed TO_CHARPOS from right to left. */
8292 || (prev_pos
> to_charpos
8293 && IT_CHARPOS (*it
) < to_charpos
)))))
8295 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8297 result
= MOVE_POS_MATCH_OR_ZV
;
8300 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8301 /* If wrap_it is valid, the current position might be in a
8302 word that is wrapped. So, save the iterator in
8303 atpos_it and continue to see if wrapping happens. */
8304 SAVE_IT (atpos_it
, *it
, atpos_data
);
8307 /* Stop when ZV reached.
8308 We used to stop here when TO_CHARPOS reached as well, but that is
8309 too soon if this glyph does not fit on this line. So we handle it
8310 explicitly below. */
8311 if (!get_next_display_element (it
))
8313 result
= MOVE_POS_MATCH_OR_ZV
;
8317 if (it
->line_wrap
== TRUNCATE
)
8319 if (BUFFER_POS_REACHED_P ())
8321 result
= MOVE_POS_MATCH_OR_ZV
;
8327 if (it
->line_wrap
== WORD_WRAP
)
8329 if (IT_DISPLAYING_WHITESPACE (it
))
8333 /* We have reached a glyph that follows one or more
8334 whitespace characters. If the position is
8335 already found, we are done. */
8336 if (atpos_it
.sp
>= 0)
8338 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8339 result
= MOVE_POS_MATCH_OR_ZV
;
8344 RESTORE_IT (it
, &atx_it
, atx_data
);
8345 result
= MOVE_X_REACHED
;
8348 /* Otherwise, we can wrap here. */
8349 SAVE_IT (wrap_it
, *it
, wrap_data
);
8355 /* Remember the line height for the current line, in case
8356 the next element doesn't fit on the line. */
8357 ascent
= it
->max_ascent
;
8358 descent
= it
->max_descent
;
8360 /* The call to produce_glyphs will get the metrics of the
8361 display element IT is loaded with. Record the x-position
8362 before this display element, in case it doesn't fit on the
8366 PRODUCE_GLYPHS (it
);
8368 if (it
->area
!= TEXT_AREA
)
8370 prev_method
= it
->method
;
8371 if (it
->method
== GET_FROM_BUFFER
)
8372 prev_pos
= IT_CHARPOS (*it
);
8373 set_iterator_to_next (it
, 1);
8374 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8375 SET_TEXT_POS (this_line_min_pos
,
8376 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8378 && (op
& MOVE_TO_POS
)
8379 && IT_CHARPOS (*it
) > to_charpos
8380 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8381 SAVE_IT (ppos_it
, *it
, ppos_data
);
8385 /* The number of glyphs we get back in IT->nglyphs will normally
8386 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
8387 character on a terminal frame, or (iii) a line end. For the
8388 second case, IT->nglyphs - 1 padding glyphs will be present.
8389 (On X frames, there is only one glyph produced for a
8390 composite character.)
8392 The behavior implemented below means, for continuation lines,
8393 that as many spaces of a TAB as fit on the current line are
8394 displayed there. For terminal frames, as many glyphs of a
8395 multi-glyph character are displayed in the current line, too.
8396 This is what the old redisplay code did, and we keep it that
8397 way. Under X, the whole shape of a complex character must
8398 fit on the line or it will be completely displayed in the
8401 Note that both for tabs and padding glyphs, all glyphs have
8405 /* More than one glyph or glyph doesn't fit on line. All
8406 glyphs have the same width. */
8407 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
8409 int x_before_this_char
= x
;
8410 int hpos_before_this_char
= it
->hpos
;
8412 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
8414 new_x
= x
+ single_glyph_width
;
8416 /* We want to leave anything reaching TO_X to the caller. */
8417 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
8419 if (BUFFER_POS_REACHED_P ())
8421 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8422 goto buffer_pos_reached
;
8423 if (atpos_it
.sp
< 0)
8425 SAVE_IT (atpos_it
, *it
, atpos_data
);
8426 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8431 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8434 result
= MOVE_X_REACHED
;
8439 SAVE_IT (atx_it
, *it
, atx_data
);
8440 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
8445 if (/* Lines are continued. */
8446 it
->line_wrap
!= TRUNCATE
8447 && (/* And glyph doesn't fit on the line. */
8448 new_x
> it
->last_visible_x
8449 /* Or it fits exactly and we're on a window
8451 || (new_x
== it
->last_visible_x
8452 && FRAME_WINDOW_P (it
->f
)
8453 && ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
8454 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8455 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
8457 if (/* IT->hpos == 0 means the very first glyph
8458 doesn't fit on the line, e.g. a wide image. */
8460 || (new_x
== it
->last_visible_x
8461 && FRAME_WINDOW_P (it
->f
)))
8464 it
->current_x
= new_x
;
8466 /* The character's last glyph just barely fits
8468 if (i
== it
->nglyphs
- 1)
8470 /* If this is the destination position,
8471 return a position *before* it in this row,
8472 now that we know it fits in this row. */
8473 if (BUFFER_POS_REACHED_P ())
8475 if (it
->line_wrap
!= WORD_WRAP
8478 it
->hpos
= hpos_before_this_char
;
8479 it
->current_x
= x_before_this_char
;
8480 result
= MOVE_POS_MATCH_OR_ZV
;
8483 if (it
->line_wrap
== WORD_WRAP
8486 SAVE_IT (atpos_it
, *it
, atpos_data
);
8487 atpos_it
.current_x
= x_before_this_char
;
8488 atpos_it
.hpos
= hpos_before_this_char
;
8492 prev_method
= it
->method
;
8493 if (it
->method
== GET_FROM_BUFFER
)
8494 prev_pos
= IT_CHARPOS (*it
);
8495 set_iterator_to_next (it
, 1);
8496 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8497 SET_TEXT_POS (this_line_min_pos
,
8498 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8499 /* On graphical terminals, newlines may
8500 "overflow" into the fringe if
8501 overflow-newline-into-fringe is non-nil.
8502 On text terminals, and on graphical
8503 terminals with no right margin, newlines
8504 may overflow into the last glyph on the
8506 if (!FRAME_WINDOW_P (it
->f
)
8508 && it
->bidi_it
.paragraph_dir
== R2L
)
8509 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8510 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0
8511 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8513 if (!get_next_display_element (it
))
8515 result
= MOVE_POS_MATCH_OR_ZV
;
8518 if (BUFFER_POS_REACHED_P ())
8520 if (ITERATOR_AT_END_OF_LINE_P (it
))
8521 result
= MOVE_POS_MATCH_OR_ZV
;
8523 result
= MOVE_LINE_CONTINUED
;
8526 if (ITERATOR_AT_END_OF_LINE_P (it
))
8528 result
= MOVE_NEWLINE_OR_CR
;
8535 IT_RESET_X_ASCENT_DESCENT (it
);
8537 if (wrap_it
.sp
>= 0)
8539 RESTORE_IT (it
, &wrap_it
, wrap_data
);
8544 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
8546 result
= MOVE_LINE_CONTINUED
;
8550 if (BUFFER_POS_REACHED_P ())
8552 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8553 goto buffer_pos_reached
;
8554 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8556 SAVE_IT (atpos_it
, *it
, atpos_data
);
8557 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8561 if (new_x
> it
->first_visible_x
)
8563 /* Glyph is visible. Increment number of glyphs that
8564 would be displayed. */
8569 if (result
!= MOVE_UNDEFINED
)
8572 else if (BUFFER_POS_REACHED_P ())
8575 IT_RESET_X_ASCENT_DESCENT (it
);
8576 result
= MOVE_POS_MATCH_OR_ZV
;
8579 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
8581 /* Stop when TO_X specified and reached. This check is
8582 necessary here because of lines consisting of a line end,
8583 only. The line end will not produce any glyphs and we
8584 would never get MOVE_X_REACHED. */
8585 eassert (it
->nglyphs
== 0);
8586 result
= MOVE_X_REACHED
;
8590 /* Is this a line end? If yes, we're done. */
8591 if (ITERATOR_AT_END_OF_LINE_P (it
))
8593 /* If we are past TO_CHARPOS, but never saw any character
8594 positions smaller than TO_CHARPOS, return
8595 MOVE_POS_MATCH_OR_ZV, like the unidirectional display
8597 if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0)
8599 if (!saw_smaller_pos
&& IT_CHARPOS (*it
) > to_charpos
)
8601 if (IT_CHARPOS (ppos_it
) < ZV
)
8603 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8604 result
= MOVE_POS_MATCH_OR_ZV
;
8607 goto buffer_pos_reached
;
8609 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
>= 0
8610 && IT_CHARPOS (*it
) > to_charpos
)
8611 goto buffer_pos_reached
;
8613 result
= MOVE_NEWLINE_OR_CR
;
8616 result
= MOVE_NEWLINE_OR_CR
;
8620 prev_method
= it
->method
;
8621 if (it
->method
== GET_FROM_BUFFER
)
8622 prev_pos
= IT_CHARPOS (*it
);
8623 /* The current display element has been consumed. Advance
8625 set_iterator_to_next (it
, 1);
8626 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8627 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8628 if (IT_CHARPOS (*it
) < to_charpos
)
8629 saw_smaller_pos
= 1;
8631 && (op
& MOVE_TO_POS
)
8632 && IT_CHARPOS (*it
) >= to_charpos
8633 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8634 SAVE_IT (ppos_it
, *it
, ppos_data
);
8636 /* Stop if lines are truncated and IT's current x-position is
8637 past the right edge of the window now. */
8638 if (it
->line_wrap
== TRUNCATE
8639 && it
->current_x
>= it
->last_visible_x
)
8641 if (!FRAME_WINDOW_P (it
->f
)
8642 || ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
8643 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8644 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0
8645 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8649 if ((at_eob_p
= !get_next_display_element (it
))
8650 || BUFFER_POS_REACHED_P ()
8651 /* If we are past TO_CHARPOS, but never saw any
8652 character positions smaller than TO_CHARPOS,
8653 return MOVE_POS_MATCH_OR_ZV, like the
8654 unidirectional display did. */
8655 || (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8657 && IT_CHARPOS (*it
) > to_charpos
))
8660 && !at_eob_p
&& IT_CHARPOS (ppos_it
) < ZV
)
8661 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8662 result
= MOVE_POS_MATCH_OR_ZV
;
8665 if (ITERATOR_AT_END_OF_LINE_P (it
))
8667 result
= MOVE_NEWLINE_OR_CR
;
8671 else if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8673 && IT_CHARPOS (*it
) > to_charpos
)
8675 if (IT_CHARPOS (ppos_it
) < ZV
)
8676 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8677 result
= MOVE_POS_MATCH_OR_ZV
;
8680 result
= MOVE_LINE_TRUNCATED
;
8683 #undef IT_RESET_X_ASCENT_DESCENT
8686 #undef BUFFER_POS_REACHED_P
8688 /* If we scanned beyond to_pos and didn't find a point to wrap at,
8689 restore the saved iterator. */
8690 if (atpos_it
.sp
>= 0)
8691 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8692 else if (atx_it
.sp
>= 0)
8693 RESTORE_IT (it
, &atx_it
, atx_data
);
8698 bidi_unshelve_cache (atpos_data
, 1);
8700 bidi_unshelve_cache (atx_data
, 1);
8702 bidi_unshelve_cache (wrap_data
, 1);
8704 bidi_unshelve_cache (ppos_data
, 1);
8706 /* Restore the iterator settings altered at the beginning of this
8708 it
->glyph_row
= saved_glyph_row
;
8712 /* For external use. */
8714 move_it_in_display_line (struct it
*it
,
8715 ptrdiff_t to_charpos
, int to_x
,
8716 enum move_operation_enum op
)
8718 if (it
->line_wrap
== WORD_WRAP
8719 && (op
& MOVE_TO_X
))
8722 void *save_data
= NULL
;
8725 SAVE_IT (save_it
, *it
, save_data
);
8726 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8727 /* When word-wrap is on, TO_X may lie past the end
8728 of a wrapped line. Then it->current is the
8729 character on the next line, so backtrack to the
8730 space before the wrap point. */
8731 if (skip
== MOVE_LINE_CONTINUED
)
8733 int prev_x
= max (it
->current_x
- 1, 0);
8734 RESTORE_IT (it
, &save_it
, save_data
);
8735 move_it_in_display_line_to
8736 (it
, -1, prev_x
, MOVE_TO_X
);
8739 bidi_unshelve_cache (save_data
, 1);
8742 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8746 /* Move IT forward until it satisfies one or more of the criteria in
8747 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
8749 OP is a bit-mask that specifies where to stop, and in particular,
8750 which of those four position arguments makes a difference. See the
8751 description of enum move_operation_enum.
8753 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
8754 screen line, this function will set IT to the next position that is
8755 displayed to the right of TO_CHARPOS on the screen. */
8758 move_it_to (struct it
*it
, ptrdiff_t to_charpos
, int to_x
, int to_y
, int to_vpos
, int op
)
8760 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
8761 int line_height
, line_start_x
= 0, reached
= 0;
8762 void *backup_data
= NULL
;
8766 if (op
& MOVE_TO_VPOS
)
8768 /* If no TO_CHARPOS and no TO_X specified, stop at the
8769 start of the line TO_VPOS. */
8770 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
8772 if (it
->vpos
== to_vpos
)
8778 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
8782 /* TO_VPOS >= 0 means stop at TO_X in the line at
8783 TO_VPOS, or at TO_POS, whichever comes first. */
8784 if (it
->vpos
== to_vpos
)
8790 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8792 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
8797 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
8799 /* We have reached TO_X but not in the line we want. */
8800 skip
= move_it_in_display_line_to (it
, to_charpos
,
8802 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8810 else if (op
& MOVE_TO_Y
)
8812 struct it it_backup
;
8814 if (it
->line_wrap
== WORD_WRAP
)
8815 SAVE_IT (it_backup
, *it
, backup_data
);
8817 /* TO_Y specified means stop at TO_X in the line containing
8818 TO_Y---or at TO_CHARPOS if this is reached first. The
8819 problem is that we can't really tell whether the line
8820 contains TO_Y before we have completely scanned it, and
8821 this may skip past TO_X. What we do is to first scan to
8824 If TO_X is not specified, use a TO_X of zero. The reason
8825 is to make the outcome of this function more predictable.
8826 If we didn't use TO_X == 0, we would stop at the end of
8827 the line which is probably not what a caller would expect
8829 skip
= move_it_in_display_line_to
8830 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
8831 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
8833 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
8834 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8836 else if (skip
== MOVE_X_REACHED
)
8838 /* If TO_X was reached, we want to know whether TO_Y is
8839 in the line. We know this is the case if the already
8840 scanned glyphs make the line tall enough. Otherwise,
8841 we must check by scanning the rest of the line. */
8842 line_height
= it
->max_ascent
+ it
->max_descent
;
8843 if (to_y
>= it
->current_y
8844 && to_y
< it
->current_y
+ line_height
)
8849 SAVE_IT (it_backup
, *it
, backup_data
);
8850 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
8851 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
8853 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
8854 line_height
= it
->max_ascent
+ it
->max_descent
;
8855 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8857 if (to_y
>= it
->current_y
8858 && to_y
< it
->current_y
+ line_height
)
8860 /* If TO_Y is in this line and TO_X was reached
8861 above, we scanned too far. We have to restore
8862 IT's settings to the ones before skipping. But
8863 keep the more accurate values of max_ascent and
8864 max_descent we've found while skipping the rest
8865 of the line, for the sake of callers, such as
8866 pos_visible_p, that need to know the line
8868 int max_ascent
= it
->max_ascent
;
8869 int max_descent
= it
->max_descent
;
8871 RESTORE_IT (it
, &it_backup
, backup_data
);
8872 it
->max_ascent
= max_ascent
;
8873 it
->max_descent
= max_descent
;
8879 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8885 /* Check whether TO_Y is in this line. */
8886 line_height
= it
->max_ascent
+ it
->max_descent
;
8887 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8889 if (to_y
>= it
->current_y
8890 && to_y
< it
->current_y
+ line_height
)
8892 /* When word-wrap is on, TO_X may lie past the end
8893 of a wrapped line. Then it->current is the
8894 character on the next line, so backtrack to the
8895 space before the wrap point. */
8896 if (skip
== MOVE_LINE_CONTINUED
8897 && it
->line_wrap
== WORD_WRAP
)
8899 int prev_x
= max (it
->current_x
- 1, 0);
8900 RESTORE_IT (it
, &it_backup
, backup_data
);
8901 skip
= move_it_in_display_line_to
8902 (it
, -1, prev_x
, MOVE_TO_X
);
8911 else if (BUFFERP (it
->object
)
8912 && (it
->method
== GET_FROM_BUFFER
8913 || it
->method
== GET_FROM_STRETCH
)
8914 && IT_CHARPOS (*it
) >= to_charpos
8915 /* Under bidi iteration, a call to set_iterator_to_next
8916 can scan far beyond to_charpos if the initial
8917 portion of the next line needs to be reordered. In
8918 that case, give move_it_in_display_line_to another
8921 && it
->bidi_it
.scan_dir
== -1))
8922 skip
= MOVE_POS_MATCH_OR_ZV
;
8924 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
8928 case MOVE_POS_MATCH_OR_ZV
:
8932 case MOVE_NEWLINE_OR_CR
:
8933 set_iterator_to_next (it
, 1);
8934 it
->continuation_lines_width
= 0;
8937 case MOVE_LINE_TRUNCATED
:
8938 it
->continuation_lines_width
= 0;
8939 reseat_at_next_visible_line_start (it
, 0);
8940 if ((op
& MOVE_TO_POS
) != 0
8941 && IT_CHARPOS (*it
) > to_charpos
)
8948 case MOVE_LINE_CONTINUED
:
8949 /* For continued lines ending in a tab, some of the glyphs
8950 associated with the tab are displayed on the current
8951 line. Since it->current_x does not include these glyphs,
8952 we use it->last_visible_x instead. */
8955 it
->continuation_lines_width
+= it
->last_visible_x
;
8956 /* When moving by vpos, ensure that the iterator really
8957 advances to the next line (bug#847, bug#969). Fixme:
8958 do we need to do this in other circumstances? */
8959 if (it
->current_x
!= it
->last_visible_x
8960 && (op
& MOVE_TO_VPOS
)
8961 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
8963 line_start_x
= it
->current_x
+ it
->pixel_width
8964 - it
->last_visible_x
;
8965 set_iterator_to_next (it
, 0);
8969 it
->continuation_lines_width
+= it
->current_x
;
8976 /* Reset/increment for the next run. */
8977 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
8978 it
->current_x
= line_start_x
;
8981 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
8983 last_height
= it
->max_ascent
+ it
->max_descent
;
8984 last_max_ascent
= it
->max_ascent
;
8985 it
->max_ascent
= it
->max_descent
= 0;
8990 /* On text terminals, we may stop at the end of a line in the middle
8991 of a multi-character glyph. If the glyph itself is continued,
8992 i.e. it is actually displayed on the next line, don't treat this
8993 stopping point as valid; move to the next line instead (unless
8994 that brings us offscreen). */
8995 if (!FRAME_WINDOW_P (it
->f
)
8997 && IT_CHARPOS (*it
) == to_charpos
8998 && it
->what
== IT_CHARACTER
9000 && it
->line_wrap
== WINDOW_WRAP
9001 && it
->current_x
== it
->last_visible_x
- 1
9004 && it
->vpos
< XFASTINT (it
->w
->window_end_vpos
))
9006 it
->continuation_lines_width
+= it
->current_x
;
9007 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
9008 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
9010 last_height
= it
->max_ascent
+ it
->max_descent
;
9011 last_max_ascent
= it
->max_ascent
;
9015 bidi_unshelve_cache (backup_data
, 1);
9017 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
9021 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
9023 If DY > 0, move IT backward at least that many pixels. DY = 0
9024 means move IT backward to the preceding line start or BEGV. This
9025 function may move over more than DY pixels if IT->current_y - DY
9026 ends up in the middle of a line; in this case IT->current_y will be
9027 set to the top of the line moved to. */
9030 move_it_vertically_backward (struct it
*it
, int dy
)
9034 void *it2data
= NULL
, *it3data
= NULL
;
9035 ptrdiff_t start_pos
;
9037 = (it
->last_visible_x
- it
->first_visible_x
) / FRAME_COLUMN_WIDTH (it
->f
);
9038 ptrdiff_t pos_limit
;
9043 start_pos
= IT_CHARPOS (*it
);
9045 /* Estimate how many newlines we must move back. */
9046 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
9047 if (it
->line_wrap
== TRUNCATE
)
9050 pos_limit
= max (start_pos
- nlines
* nchars_per_row
, BEGV
);
9052 /* Set the iterator's position that many lines back. But don't go
9053 back more than NLINES full screen lines -- this wins a day with
9054 buffers which have very long lines. */
9055 while (nlines
-- && IT_CHARPOS (*it
) > pos_limit
)
9056 back_to_previous_visible_line_start (it
);
9058 /* Reseat the iterator here. When moving backward, we don't want
9059 reseat to skip forward over invisible text, set up the iterator
9060 to deliver from overlay strings at the new position etc. So,
9061 use reseat_1 here. */
9062 reseat_1 (it
, it
->current
.pos
, 1);
9064 /* We are now surely at a line start. */
9065 it
->current_x
= it
->hpos
= 0; /* FIXME: this is incorrect when bidi
9066 reordering is in effect. */
9067 it
->continuation_lines_width
= 0;
9069 /* Move forward and see what y-distance we moved. First move to the
9070 start of the next line so that we get its height. We need this
9071 height to be able to tell whether we reached the specified
9073 SAVE_IT (it2
, *it
, it2data
);
9074 it2
.max_ascent
= it2
.max_descent
= 0;
9077 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
9078 MOVE_TO_POS
| MOVE_TO_VPOS
);
9080 while (!(IT_POS_VALID_AFTER_MOVE_P (&it2
)
9081 /* If we are in a display string which starts at START_POS,
9082 and that display string includes a newline, and we are
9083 right after that newline (i.e. at the beginning of a
9084 display line), exit the loop, because otherwise we will
9085 infloop, since move_it_to will see that it is already at
9086 START_POS and will not move. */
9087 || (it2
.method
== GET_FROM_STRING
9088 && IT_CHARPOS (it2
) == start_pos
9089 && SREF (it2
.string
, IT_STRING_BYTEPOS (it2
) - 1) == '\n')));
9090 eassert (IT_CHARPOS (*it
) >= BEGV
);
9091 SAVE_IT (it3
, it2
, it3data
);
9093 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
9094 eassert (IT_CHARPOS (*it
) >= BEGV
);
9095 /* H is the actual vertical distance from the position in *IT
9096 and the starting position. */
9097 h
= it2
.current_y
- it
->current_y
;
9098 /* NLINES is the distance in number of lines. */
9099 nlines
= it2
.vpos
- it
->vpos
;
9101 /* Correct IT's y and vpos position
9102 so that they are relative to the starting point. */
9108 /* DY == 0 means move to the start of the screen line. The
9109 value of nlines is > 0 if continuation lines were involved,
9110 or if the original IT position was at start of a line. */
9111 RESTORE_IT (it
, it
, it2data
);
9113 move_it_by_lines (it
, nlines
);
9114 /* The above code moves us to some position NLINES down,
9115 usually to its first glyph (leftmost in an L2R line), but
9116 that's not necessarily the start of the line, under bidi
9117 reordering. We want to get to the character position
9118 that is immediately after the newline of the previous
9121 && !it
->continuation_lines_width
9122 && !STRINGP (it
->string
)
9123 && IT_CHARPOS (*it
) > BEGV
9124 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9127 find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1, NULL
);
9129 move_it_to (it
, nl_pos
, -1, -1, -1, MOVE_TO_POS
);
9131 bidi_unshelve_cache (it3data
, 1);
9135 /* The y-position we try to reach, relative to *IT.
9136 Note that H has been subtracted in front of the if-statement. */
9137 int target_y
= it
->current_y
+ h
- dy
;
9138 int y0
= it3
.current_y
;
9142 RESTORE_IT (&it3
, &it3
, it3data
);
9143 y1
= line_bottom_y (&it3
);
9144 line_height
= y1
- y0
;
9145 RESTORE_IT (it
, it
, it2data
);
9146 /* If we did not reach target_y, try to move further backward if
9147 we can. If we moved too far backward, try to move forward. */
9148 if (target_y
< it
->current_y
9149 /* This is heuristic. In a window that's 3 lines high, with
9150 a line height of 13 pixels each, recentering with point
9151 on the bottom line will try to move -39/2 = 19 pixels
9152 backward. Try to avoid moving into the first line. */
9153 && (it
->current_y
- target_y
9154 > min (window_box_height (it
->w
), line_height
* 2 / 3))
9155 && IT_CHARPOS (*it
) > BEGV
)
9157 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
9158 target_y
- it
->current_y
));
9159 dy
= it
->current_y
- target_y
;
9160 goto move_further_back
;
9162 else if (target_y
>= it
->current_y
+ line_height
9163 && IT_CHARPOS (*it
) < ZV
)
9165 /* Should move forward by at least one line, maybe more.
9167 Note: Calling move_it_by_lines can be expensive on
9168 terminal frames, where compute_motion is used (via
9169 vmotion) to do the job, when there are very long lines
9170 and truncate-lines is nil. That's the reason for
9171 treating terminal frames specially here. */
9173 if (!FRAME_WINDOW_P (it
->f
))
9174 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
9179 move_it_by_lines (it
, 1);
9181 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
9188 /* Move IT by a specified amount of pixel lines DY. DY negative means
9189 move backwards. DY = 0 means move to start of screen line. At the
9190 end, IT will be on the start of a screen line. */
9193 move_it_vertically (struct it
*it
, int dy
)
9196 move_it_vertically_backward (it
, -dy
);
9199 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
9200 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
9201 MOVE_TO_POS
| MOVE_TO_Y
);
9202 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
9204 /* If buffer ends in ZV without a newline, move to the start of
9205 the line to satisfy the post-condition. */
9206 if (IT_CHARPOS (*it
) == ZV
9208 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9209 move_it_by_lines (it
, 0);
9214 /* Move iterator IT past the end of the text line it is in. */
9217 move_it_past_eol (struct it
*it
)
9219 enum move_it_result rc
;
9221 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
9222 if (rc
== MOVE_NEWLINE_OR_CR
)
9223 set_iterator_to_next (it
, 0);
9227 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
9228 negative means move up. DVPOS == 0 means move to the start of the
9231 Optimization idea: If we would know that IT->f doesn't use
9232 a face with proportional font, we could be faster for
9233 truncate-lines nil. */
9236 move_it_by_lines (struct it
*it
, ptrdiff_t dvpos
)
9239 /* The commented-out optimization uses vmotion on terminals. This
9240 gives bad results, because elements like it->what, on which
9241 callers such as pos_visible_p rely, aren't updated. */
9242 /* struct position pos;
9243 if (!FRAME_WINDOW_P (it->f))
9245 struct text_pos textpos;
9247 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
9248 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
9249 reseat (it, textpos, 1);
9250 it->vpos += pos.vpos;
9251 it->current_y += pos.vpos;
9257 /* DVPOS == 0 means move to the start of the screen line. */
9258 move_it_vertically_backward (it
, 0);
9259 /* Let next call to line_bottom_y calculate real line height */
9264 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
9265 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
9267 /* Only move to the next buffer position if we ended up in a
9268 string from display property, not in an overlay string
9269 (before-string or after-string). That is because the
9270 latter don't conceal the underlying buffer position, so
9271 we can ask to move the iterator to the exact position we
9272 are interested in. Note that, even if we are already at
9273 IT_CHARPOS (*it), the call below is not a no-op, as it
9274 will detect that we are at the end of the string, pop the
9275 iterator, and compute it->current_x and it->hpos
9277 move_it_to (it
, IT_CHARPOS (*it
) + it
->string_from_display_prop_p
,
9278 -1, -1, -1, MOVE_TO_POS
);
9284 void *it2data
= NULL
;
9285 ptrdiff_t start_charpos
, i
;
9287 = (it
->last_visible_x
- it
->first_visible_x
) / FRAME_COLUMN_WIDTH (it
->f
);
9288 ptrdiff_t pos_limit
;
9290 /* Start at the beginning of the screen line containing IT's
9291 position. This may actually move vertically backwards,
9292 in case of overlays, so adjust dvpos accordingly. */
9294 move_it_vertically_backward (it
, 0);
9297 /* Go back -DVPOS buffer lines, but no farther than -DVPOS full
9298 screen lines, and reseat the iterator there. */
9299 start_charpos
= IT_CHARPOS (*it
);
9300 if (it
->line_wrap
== TRUNCATE
)
9303 pos_limit
= max (start_charpos
+ dvpos
* nchars_per_row
, BEGV
);
9304 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > pos_limit
; --i
)
9305 back_to_previous_visible_line_start (it
);
9306 reseat (it
, it
->current
.pos
, 1);
9308 /* Move further back if we end up in a string or an image. */
9309 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
9311 /* First try to move to start of display line. */
9313 move_it_vertically_backward (it
, 0);
9315 if (IT_POS_VALID_AFTER_MOVE_P (it
))
9317 /* If start of line is still in string or image,
9318 move further back. */
9319 back_to_previous_visible_line_start (it
);
9320 reseat (it
, it
->current
.pos
, 1);
9324 it
->current_x
= it
->hpos
= 0;
9326 /* Above call may have moved too far if continuation lines
9327 are involved. Scan forward and see if it did. */
9328 SAVE_IT (it2
, *it
, it2data
);
9329 it2
.vpos
= it2
.current_y
= 0;
9330 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
9331 it
->vpos
-= it2
.vpos
;
9332 it
->current_y
-= it2
.current_y
;
9333 it
->current_x
= it
->hpos
= 0;
9335 /* If we moved too far back, move IT some lines forward. */
9336 if (it2
.vpos
> -dvpos
)
9338 int delta
= it2
.vpos
+ dvpos
;
9340 RESTORE_IT (&it2
, &it2
, it2data
);
9341 SAVE_IT (it2
, *it
, it2data
);
9342 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
9343 /* Move back again if we got too far ahead. */
9344 if (IT_CHARPOS (*it
) >= start_charpos
)
9345 RESTORE_IT (it
, &it2
, it2data
);
9347 bidi_unshelve_cache (it2data
, 1);
9350 RESTORE_IT (it
, it
, it2data
);
9354 /* Return 1 if IT points into the middle of a display vector. */
9357 in_display_vector_p (struct it
*it
)
9359 return (it
->method
== GET_FROM_DISPLAY_VECTOR
9360 && it
->current
.dpvec_index
> 0
9361 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
9365 /***********************************************************************
9367 ***********************************************************************/
9370 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
9374 add_to_log (const char *format
, Lisp_Object arg1
, Lisp_Object arg2
)
9376 Lisp_Object args
[3];
9377 Lisp_Object msg
, fmt
;
9380 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
9384 GCPRO4 (fmt
, msg
, arg1
, arg2
);
9386 args
[0] = fmt
= build_string (format
);
9389 msg
= Fformat (3, args
);
9391 len
= SBYTES (msg
) + 1;
9392 buffer
= SAFE_ALLOCA (len
);
9393 memcpy (buffer
, SDATA (msg
), len
);
9395 message_dolog (buffer
, len
- 1, 1, 0);
9402 /* Output a newline in the *Messages* buffer if "needs" one. */
9405 message_log_maybe_newline (void)
9407 if (message_log_need_newline
)
9408 message_dolog ("", 0, 1, 0);
9412 /* Add a string M of length NBYTES to the message log, optionally
9413 terminated with a newline when NLFLAG is true. MULTIBYTE, if
9414 true, means interpret the contents of M as multibyte. This
9415 function calls low-level routines in order to bypass text property
9416 hooks, etc. which might not be safe to run.
9418 This may GC (insert may run before/after change hooks),
9419 so the buffer M must NOT point to a Lisp string. */
9422 message_dolog (const char *m
, ptrdiff_t nbytes
, bool nlflag
, bool multibyte
)
9424 const unsigned char *msg
= (const unsigned char *) m
;
9426 if (!NILP (Vmemory_full
))
9429 if (!NILP (Vmessage_log_max
))
9431 struct buffer
*oldbuf
;
9432 Lisp_Object oldpoint
, oldbegv
, oldzv
;
9433 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
9434 ptrdiff_t point_at_end
= 0;
9435 ptrdiff_t zv_at_end
= 0;
9436 Lisp_Object old_deactivate_mark
;
9438 struct gcpro gcpro1
;
9440 old_deactivate_mark
= Vdeactivate_mark
;
9441 oldbuf
= current_buffer
;
9442 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
9443 bset_undo_list (current_buffer
, Qt
);
9445 oldpoint
= message_dolog_marker1
;
9446 set_marker_restricted_both (oldpoint
, Qnil
, PT
, PT_BYTE
);
9447 oldbegv
= message_dolog_marker2
;
9448 set_marker_restricted_both (oldbegv
, Qnil
, BEGV
, BEGV_BYTE
);
9449 oldzv
= message_dolog_marker3
;
9450 set_marker_restricted_both (oldzv
, Qnil
, ZV
, ZV_BYTE
);
9451 GCPRO1 (old_deactivate_mark
);
9459 BEGV_BYTE
= BEG_BYTE
;
9462 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9464 /* Insert the string--maybe converting multibyte to single byte
9465 or vice versa, so that all the text fits the buffer. */
9467 && NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9473 /* Convert a multibyte string to single-byte
9474 for the *Message* buffer. */
9475 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
9477 c
= string_char_and_length (msg
+ i
, &char_bytes
);
9478 work
[0] = (ASCII_CHAR_P (c
)
9480 : multibyte_char_to_unibyte (c
));
9481 insert_1_both (work
, 1, 1, 1, 0, 0);
9484 else if (! multibyte
9485 && ! NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9489 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9490 /* Convert a single-byte string to multibyte
9491 for the *Message* buffer. */
9492 for (i
= 0; i
< nbytes
; i
++)
9495 MAKE_CHAR_MULTIBYTE (c
);
9496 char_bytes
= CHAR_STRING (c
, str
);
9497 insert_1_both ((char *) str
, 1, char_bytes
, 1, 0, 0);
9501 insert_1_both (m
, chars_in_text (msg
, nbytes
), nbytes
, 1, 0, 0);
9505 ptrdiff_t this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
;
9508 insert_1_both ("\n", 1, 1, 1, 0, 0);
9510 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9512 this_bol_byte
= PT_BYTE
;
9514 /* See if this line duplicates the previous one.
9515 If so, combine duplicates. */
9518 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9520 prev_bol_byte
= PT_BYTE
;
9522 dups
= message_log_check_duplicate (prev_bol_byte
,
9526 del_range_both (prev_bol
, prev_bol_byte
,
9527 this_bol
, this_bol_byte
, 0);
9530 char dupstr
[sizeof " [ times]"
9531 + INT_STRLEN_BOUND (printmax_t
)];
9533 /* If you change this format, don't forget to also
9534 change message_log_check_duplicate. */
9535 int duplen
= sprintf (dupstr
, " [%"pMd
" times]", dups
);
9536 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
9537 insert_1_both (dupstr
, duplen
, duplen
, 1, 0, 1);
9542 /* If we have more than the desired maximum number of lines
9543 in the *Messages* buffer now, delete the oldest ones.
9544 This is safe because we don't have undo in this buffer. */
9546 if (NATNUMP (Vmessage_log_max
))
9548 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
9549 -XFASTINT (Vmessage_log_max
) - 1, 0);
9550 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
9553 BEGV
= marker_position (oldbegv
);
9554 BEGV_BYTE
= marker_byte_position (oldbegv
);
9563 ZV
= marker_position (oldzv
);
9564 ZV_BYTE
= marker_byte_position (oldzv
);
9568 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9570 /* We can't do Fgoto_char (oldpoint) because it will run some
9572 TEMP_SET_PT_BOTH (marker_position (oldpoint
),
9573 marker_byte_position (oldpoint
));
9576 unchain_marker (XMARKER (oldpoint
));
9577 unchain_marker (XMARKER (oldbegv
));
9578 unchain_marker (XMARKER (oldzv
));
9580 shown
= buffer_window_count (current_buffer
) > 0;
9581 set_buffer_internal (oldbuf
);
9583 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
9584 message_log_need_newline
= !nlflag
;
9585 Vdeactivate_mark
= old_deactivate_mark
;
9590 /* We are at the end of the buffer after just having inserted a newline.
9591 (Note: We depend on the fact we won't be crossing the gap.)
9592 Check to see if the most recent message looks a lot like the previous one.
9593 Return 0 if different, 1 if the new one should just replace it, or a
9594 value N > 1 if we should also append " [N times]". */
9597 message_log_check_duplicate (ptrdiff_t prev_bol_byte
, ptrdiff_t this_bol_byte
)
9600 ptrdiff_t len
= Z_BYTE
- 1 - this_bol_byte
;
9602 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
9603 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
9605 for (i
= 0; i
< len
; i
++)
9607 if (i
>= 3 && p1
[i
- 3] == '.' && p1
[i
- 2] == '.' && p1
[i
- 1] == '.')
9615 if (*p1
++ == ' ' && *p1
++ == '[')
9618 intmax_t n
= strtoimax ((char *) p1
, &pend
, 10);
9619 if (0 < n
&& n
< INTMAX_MAX
&& strncmp (pend
, " times]\n", 8) == 0)
9626 /* Display an echo area message M with a specified length of NBYTES
9627 bytes. The string may include null characters. If M is not a
9628 string, clear out any existing message, and let the mini-buffer
9631 This function cancels echoing. */
9634 message3 (Lisp_Object m
)
9636 struct gcpro gcpro1
;
9639 clear_message (1,1);
9642 /* First flush out any partial line written with print. */
9643 message_log_maybe_newline ();
9646 ptrdiff_t nbytes
= SBYTES (m
);
9647 bool multibyte
= STRING_MULTIBYTE (m
);
9649 char *buffer
= SAFE_ALLOCA (nbytes
);
9650 memcpy (buffer
, SDATA (m
), nbytes
);
9651 message_dolog (buffer
, nbytes
, 1, multibyte
);
9660 /* The non-logging version of message3.
9661 This does not cancel echoing, because it is used for echoing.
9662 Perhaps we need to make a separate function for echoing
9663 and make this cancel echoing. */
9666 message3_nolog (Lisp_Object m
)
9668 struct frame
*sf
= SELECTED_FRAME ();
9670 if (FRAME_INITIAL_P (sf
))
9672 if (noninteractive_need_newline
)
9673 putc ('\n', stderr
);
9674 noninteractive_need_newline
= 0;
9676 fwrite (SDATA (m
), SBYTES (m
), 1, stderr
);
9677 if (cursor_in_echo_area
== 0)
9678 fprintf (stderr
, "\n");
9681 /* Error messages get reported properly by cmd_error, so this must be just an
9682 informative message; if the frame hasn't really been initialized yet, just
9684 else if (INTERACTIVE
&& sf
->glyphs_initialized_p
)
9686 /* Get the frame containing the mini-buffer
9687 that the selected frame is using. */
9688 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9689 Lisp_Object frame
= XWINDOW (mini_window
)->frame
;
9690 struct frame
*f
= XFRAME (frame
);
9692 if (FRAME_VISIBLE_P (sf
) && !FRAME_VISIBLE_P (f
))
9693 Fmake_frame_visible (frame
);
9695 if (STRINGP (m
) && SCHARS (m
) > 0)
9698 if (minibuffer_auto_raise
)
9699 Fraise_frame (frame
);
9700 /* Assume we are not echoing.
9701 (If we are, echo_now will override this.) */
9702 echo_message_buffer
= Qnil
;
9705 clear_message (1, 1);
9707 do_pending_window_change (0);
9708 echo_area_display (1);
9709 do_pending_window_change (0);
9710 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
9711 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
9716 /* Display a null-terminated echo area message M. If M is 0, clear
9717 out any existing message, and let the mini-buffer text show through.
9719 The buffer M must continue to exist until after the echo area gets
9720 cleared or some other message gets displayed there. Do not pass
9721 text that is stored in a Lisp string. Do not pass text in a buffer
9722 that was alloca'd. */
9725 message1 (const char *m
)
9727 message3 (m
? make_unibyte_string (m
, strlen (m
)) : Qnil
);
9731 /* The non-logging counterpart of message1. */
9734 message1_nolog (const char *m
)
9736 message3_nolog (m
? make_unibyte_string (m
, strlen (m
)) : Qnil
);
9739 /* Display a message M which contains a single %s
9740 which gets replaced with STRING. */
9743 message_with_string (const char *m
, Lisp_Object string
, int log
)
9745 CHECK_STRING (string
);
9751 if (noninteractive_need_newline
)
9752 putc ('\n', stderr
);
9753 noninteractive_need_newline
= 0;
9754 fprintf (stderr
, m
, SDATA (string
));
9755 if (!cursor_in_echo_area
)
9756 fprintf (stderr
, "\n");
9760 else if (INTERACTIVE
)
9762 /* The frame whose minibuffer we're going to display the message on.
9763 It may be larger than the selected frame, so we need
9764 to use its buffer, not the selected frame's buffer. */
9765 Lisp_Object mini_window
;
9766 struct frame
*f
, *sf
= SELECTED_FRAME ();
9768 /* Get the frame containing the minibuffer
9769 that the selected frame is using. */
9770 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9771 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9773 /* Error messages get reported properly by cmd_error, so this must be
9774 just an informative message; if the frame hasn't really been
9775 initialized yet, just toss it. */
9776 if (f
->glyphs_initialized_p
)
9778 Lisp_Object args
[2], msg
;
9779 struct gcpro gcpro1
, gcpro2
;
9781 args
[0] = build_string (m
);
9782 args
[1] = msg
= string
;
9783 GCPRO2 (args
[0], msg
);
9786 msg
= Fformat (2, args
);
9791 message3_nolog (msg
);
9795 /* Print should start at the beginning of the message
9796 buffer next time. */
9797 message_buf_print
= 0;
9803 /* Dump an informative message to the minibuf. If M is 0, clear out
9804 any existing message, and let the mini-buffer text show through. */
9807 vmessage (const char *m
, va_list ap
)
9813 if (noninteractive_need_newline
)
9814 putc ('\n', stderr
);
9815 noninteractive_need_newline
= 0;
9816 vfprintf (stderr
, m
, ap
);
9817 if (cursor_in_echo_area
== 0)
9818 fprintf (stderr
, "\n");
9822 else if (INTERACTIVE
)
9824 /* The frame whose mini-buffer we're going to display the message
9825 on. It may be larger than the selected frame, so we need to
9826 use its buffer, not the selected frame's buffer. */
9827 Lisp_Object mini_window
;
9828 struct frame
*f
, *sf
= SELECTED_FRAME ();
9830 /* Get the frame containing the mini-buffer
9831 that the selected frame is using. */
9832 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9833 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9835 /* Error messages get reported properly by cmd_error, so this must be
9836 just an informative message; if the frame hasn't really been
9837 initialized yet, just toss it. */
9838 if (f
->glyphs_initialized_p
)
9843 ptrdiff_t maxsize
= FRAME_MESSAGE_BUF_SIZE (f
);
9844 char *message_buf
= alloca (maxsize
+ 1);
9846 len
= doprnt (message_buf
, maxsize
, m
, (char *)0, ap
);
9848 message3 (make_string (message_buf
, len
));
9853 /* Print should start at the beginning of the message
9854 buffer next time. */
9855 message_buf_print
= 0;
9861 message (const char *m
, ...)
9871 /* The non-logging version of message. */
9874 message_nolog (const char *m
, ...)
9876 Lisp_Object old_log_max
;
9879 old_log_max
= Vmessage_log_max
;
9880 Vmessage_log_max
= Qnil
;
9882 Vmessage_log_max
= old_log_max
;
9888 /* Display the current message in the current mini-buffer. This is
9889 only called from error handlers in process.c, and is not time
9893 update_echo_area (void)
9895 if (!NILP (echo_area_buffer
[0]))
9898 string
= Fcurrent_message ();
9904 /* Make sure echo area buffers in `echo_buffers' are live.
9905 If they aren't, make new ones. */
9908 ensure_echo_area_buffers (void)
9912 for (i
= 0; i
< 2; ++i
)
9913 if (!BUFFERP (echo_buffer
[i
])
9914 || !BUFFER_LIVE_P (XBUFFER (echo_buffer
[i
])))
9917 Lisp_Object old_buffer
;
9920 old_buffer
= echo_buffer
[i
];
9921 echo_buffer
[i
] = Fget_buffer_create
9922 (make_formatted_string (name
, " *Echo Area %d*", i
));
9923 bset_truncate_lines (XBUFFER (echo_buffer
[i
]), Qnil
);
9924 /* to force word wrap in echo area -
9925 it was decided to postpone this*/
9926 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
9928 for (j
= 0; j
< 2; ++j
)
9929 if (EQ (old_buffer
, echo_area_buffer
[j
]))
9930 echo_area_buffer
[j
] = echo_buffer
[i
];
9935 /* Call FN with args A1..A2 with either the current or last displayed
9936 echo_area_buffer as current buffer.
9938 WHICH zero means use the current message buffer
9939 echo_area_buffer[0]. If that is nil, choose a suitable buffer
9940 from echo_buffer[] and clear it.
9942 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
9943 suitable buffer from echo_buffer[] and clear it.
9945 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
9946 that the current message becomes the last displayed one, make
9947 choose a suitable buffer for echo_area_buffer[0], and clear it.
9949 Value is what FN returns. */
9952 with_echo_area_buffer (struct window
*w
, int which
,
9953 int (*fn
) (ptrdiff_t, Lisp_Object
),
9954 ptrdiff_t a1
, Lisp_Object a2
)
9957 int this_one
, the_other
, clear_buffer_p
, rc
;
9958 ptrdiff_t count
= SPECPDL_INDEX ();
9960 /* If buffers aren't live, make new ones. */
9961 ensure_echo_area_buffers ();
9966 this_one
= 0, the_other
= 1;
9968 this_one
= 1, the_other
= 0;
9971 this_one
= 0, the_other
= 1;
9974 /* We need a fresh one in case the current echo buffer equals
9975 the one containing the last displayed echo area message. */
9976 if (!NILP (echo_area_buffer
[this_one
])
9977 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
9978 echo_area_buffer
[this_one
] = Qnil
;
9981 /* Choose a suitable buffer from echo_buffer[] is we don't
9983 if (NILP (echo_area_buffer
[this_one
]))
9985 echo_area_buffer
[this_one
]
9986 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
9987 ? echo_buffer
[the_other
]
9988 : echo_buffer
[this_one
]);
9992 buffer
= echo_area_buffer
[this_one
];
9994 /* Don't get confused by reusing the buffer used for echoing
9995 for a different purpose. */
9996 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
9999 record_unwind_protect (unwind_with_echo_area_buffer
,
10000 with_echo_area_buffer_unwind_data (w
));
10002 /* Make the echo area buffer current. Note that for display
10003 purposes, it is not necessary that the displayed window's buffer
10004 == current_buffer, except for text property lookup. So, let's
10005 only set that buffer temporarily here without doing a full
10006 Fset_window_buffer. We must also change w->pointm, though,
10007 because otherwise an assertions in unshow_buffer fails, and Emacs
10009 set_buffer_internal_1 (XBUFFER (buffer
));
10012 wset_buffer (w
, buffer
);
10013 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
10016 bset_undo_list (current_buffer
, Qt
);
10017 bset_read_only (current_buffer
, Qnil
);
10018 specbind (Qinhibit_read_only
, Qt
);
10019 specbind (Qinhibit_modification_hooks
, Qt
);
10021 if (clear_buffer_p
&& Z
> BEG
)
10022 del_range (BEG
, Z
);
10024 eassert (BEGV
>= BEG
);
10025 eassert (ZV
<= Z
&& ZV
>= BEGV
);
10029 eassert (BEGV
>= BEG
);
10030 eassert (ZV
<= Z
&& ZV
>= BEGV
);
10032 unbind_to (count
, Qnil
);
10037 /* Save state that should be preserved around the call to the function
10038 FN called in with_echo_area_buffer. */
10041 with_echo_area_buffer_unwind_data (struct window
*w
)
10044 Lisp_Object vector
, tmp
;
10046 /* Reduce consing by keeping one vector in
10047 Vwith_echo_area_save_vector. */
10048 vector
= Vwith_echo_area_save_vector
;
10049 Vwith_echo_area_save_vector
= Qnil
;
10052 vector
= Fmake_vector (make_number (7), Qnil
);
10054 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
10055 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
10056 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
10060 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
10061 ASET (vector
, i
, w
->buffer
); ++i
;
10062 ASET (vector
, i
, make_number (marker_position (w
->pointm
))); ++i
;
10063 ASET (vector
, i
, make_number (marker_byte_position (w
->pointm
))); ++i
;
10068 for (; i
< end
; ++i
)
10069 ASET (vector
, i
, Qnil
);
10072 eassert (i
== ASIZE (vector
));
10077 /* Restore global state from VECTOR which was created by
10078 with_echo_area_buffer_unwind_data. */
10081 unwind_with_echo_area_buffer (Lisp_Object vector
)
10083 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
10084 Vdeactivate_mark
= AREF (vector
, 1);
10085 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
10087 if (WINDOWP (AREF (vector
, 3)))
10090 Lisp_Object buffer
, charpos
, bytepos
;
10092 w
= XWINDOW (AREF (vector
, 3));
10093 buffer
= AREF (vector
, 4);
10094 charpos
= AREF (vector
, 5);
10095 bytepos
= AREF (vector
, 6);
10097 wset_buffer (w
, buffer
);
10098 set_marker_both (w
->pointm
, buffer
,
10099 XFASTINT (charpos
), XFASTINT (bytepos
));
10102 Vwith_echo_area_save_vector
= vector
;
10107 /* Set up the echo area for use by print functions. MULTIBYTE_P
10108 non-zero means we will print multibyte. */
10111 setup_echo_area_for_printing (int multibyte_p
)
10113 /* If we can't find an echo area any more, exit. */
10114 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
10115 Fkill_emacs (Qnil
);
10117 ensure_echo_area_buffers ();
10119 if (!message_buf_print
)
10121 /* A message has been output since the last time we printed.
10122 Choose a fresh echo area buffer. */
10123 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10124 echo_area_buffer
[0] = echo_buffer
[1];
10126 echo_area_buffer
[0] = echo_buffer
[0];
10128 /* Switch to that buffer and clear it. */
10129 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10130 bset_truncate_lines (current_buffer
, Qnil
);
10134 ptrdiff_t count
= SPECPDL_INDEX ();
10135 specbind (Qinhibit_read_only
, Qt
);
10136 /* Note that undo recording is always disabled. */
10137 del_range (BEG
, Z
);
10138 unbind_to (count
, Qnil
);
10140 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10142 /* Set up the buffer for the multibyteness we need. */
10144 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10145 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
10147 /* Raise the frame containing the echo area. */
10148 if (minibuffer_auto_raise
)
10150 struct frame
*sf
= SELECTED_FRAME ();
10151 Lisp_Object mini_window
;
10152 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10153 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
10156 message_log_maybe_newline ();
10157 message_buf_print
= 1;
10161 if (NILP (echo_area_buffer
[0]))
10163 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10164 echo_area_buffer
[0] = echo_buffer
[1];
10166 echo_area_buffer
[0] = echo_buffer
[0];
10169 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
10171 /* Someone switched buffers between print requests. */
10172 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10173 bset_truncate_lines (current_buffer
, Qnil
);
10179 /* Display an echo area message in window W. Value is non-zero if W's
10180 height is changed. If display_last_displayed_message_p is
10181 non-zero, display the message that was last displayed, otherwise
10182 display the current message. */
10185 display_echo_area (struct window
*w
)
10187 int i
, no_message_p
, window_height_changed_p
;
10189 /* Temporarily disable garbage collections while displaying the echo
10190 area. This is done because a GC can print a message itself.
10191 That message would modify the echo area buffer's contents while a
10192 redisplay of the buffer is going on, and seriously confuse
10194 ptrdiff_t count
= inhibit_garbage_collection ();
10196 /* If there is no message, we must call display_echo_area_1
10197 nevertheless because it resizes the window. But we will have to
10198 reset the echo_area_buffer in question to nil at the end because
10199 with_echo_area_buffer will sets it to an empty buffer. */
10200 i
= display_last_displayed_message_p
? 1 : 0;
10201 no_message_p
= NILP (echo_area_buffer
[i
]);
10203 window_height_changed_p
10204 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
10205 display_echo_area_1
,
10206 (intptr_t) w
, Qnil
);
10209 echo_area_buffer
[i
] = Qnil
;
10211 unbind_to (count
, Qnil
);
10212 return window_height_changed_p
;
10216 /* Helper for display_echo_area. Display the current buffer which
10217 contains the current echo area message in window W, a mini-window,
10218 a pointer to which is passed in A1. A2..A4 are currently not used.
10219 Change the height of W so that all of the message is displayed.
10220 Value is non-zero if height of W was changed. */
10223 display_echo_area_1 (ptrdiff_t a1
, Lisp_Object a2
)
10226 struct window
*w
= (struct window
*) i1
;
10227 Lisp_Object window
;
10228 struct text_pos start
;
10229 int window_height_changed_p
= 0;
10231 /* Do this before displaying, so that we have a large enough glyph
10232 matrix for the display. If we can't get enough space for the
10233 whole text, display the last N lines. That works by setting w->start. */
10234 window_height_changed_p
= resize_mini_window (w
, 0);
10236 /* Use the starting position chosen by resize_mini_window. */
10237 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
10240 clear_glyph_matrix (w
->desired_matrix
);
10241 XSETWINDOW (window
, w
);
10242 try_window (window
, start
, 0);
10244 return window_height_changed_p
;
10248 /* Resize the echo area window to exactly the size needed for the
10249 currently displayed message, if there is one. If a mini-buffer
10250 is active, don't shrink it. */
10253 resize_echo_area_exactly (void)
10255 if (BUFFERP (echo_area_buffer
[0])
10256 && WINDOWP (echo_area_window
))
10258 struct window
*w
= XWINDOW (echo_area_window
);
10260 Lisp_Object resize_exactly
;
10262 if (minibuf_level
== 0)
10263 resize_exactly
= Qt
;
10265 resize_exactly
= Qnil
;
10267 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
10268 (intptr_t) w
, resize_exactly
);
10271 ++windows_or_buffers_changed
;
10272 ++update_mode_lines
;
10273 redisplay_internal ();
10279 /* Callback function for with_echo_area_buffer, when used from
10280 resize_echo_area_exactly. A1 contains a pointer to the window to
10281 resize, EXACTLY non-nil means resize the mini-window exactly to the
10282 size of the text displayed. A3 and A4 are not used. Value is what
10283 resize_mini_window returns. */
10286 resize_mini_window_1 (ptrdiff_t a1
, Lisp_Object exactly
)
10289 return resize_mini_window ((struct window
*) i1
, !NILP (exactly
));
10293 /* Resize mini-window W to fit the size of its contents. EXACT_P
10294 means size the window exactly to the size needed. Otherwise, it's
10295 only enlarged until W's buffer is empty.
10297 Set W->start to the right place to begin display. If the whole
10298 contents fit, start at the beginning. Otherwise, start so as
10299 to make the end of the contents appear. This is particularly
10300 important for y-or-n-p, but seems desirable generally.
10302 Value is non-zero if the window height has been changed. */
10305 resize_mini_window (struct window
*w
, int exact_p
)
10307 struct frame
*f
= XFRAME (w
->frame
);
10308 int window_height_changed_p
= 0;
10310 eassert (MINI_WINDOW_P (w
));
10312 /* By default, start display at the beginning. */
10313 set_marker_both (w
->start
, w
->buffer
,
10314 BUF_BEGV (XBUFFER (w
->buffer
)),
10315 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
10317 /* Don't resize windows while redisplaying a window; it would
10318 confuse redisplay functions when the size of the window they are
10319 displaying changes from under them. Such a resizing can happen,
10320 for instance, when which-func prints a long message while
10321 we are running fontification-functions. We're running these
10322 functions with safe_call which binds inhibit-redisplay to t. */
10323 if (!NILP (Vinhibit_redisplay
))
10326 /* Nil means don't try to resize. */
10327 if (NILP (Vresize_mini_windows
)
10328 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
10331 if (!FRAME_MINIBUF_ONLY_P (f
))
10334 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
10335 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
10337 EMACS_INT max_height
;
10338 int unit
= FRAME_LINE_HEIGHT (f
);
10339 struct text_pos start
;
10340 struct buffer
*old_current_buffer
= NULL
;
10342 if (current_buffer
!= XBUFFER (w
->buffer
))
10344 old_current_buffer
= current_buffer
;
10345 set_buffer_internal (XBUFFER (w
->buffer
));
10348 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10350 /* Compute the max. number of lines specified by the user. */
10351 if (FLOATP (Vmax_mini_window_height
))
10352 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
10353 else if (INTEGERP (Vmax_mini_window_height
))
10354 max_height
= XINT (Vmax_mini_window_height
);
10356 max_height
= total_height
/ 4;
10358 /* Correct that max. height if it's bogus. */
10359 max_height
= clip_to_bounds (1, max_height
, total_height
);
10361 /* Find out the height of the text in the window. */
10362 if (it
.line_wrap
== TRUNCATE
)
10367 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
10368 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
10369 height
= it
.current_y
+ last_height
;
10371 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
10372 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
10373 height
= (height
+ unit
- 1) / unit
;
10376 /* Compute a suitable window start. */
10377 if (height
> max_height
)
10379 height
= max_height
;
10380 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10381 move_it_vertically_backward (&it
, (height
- 1) * unit
);
10382 start
= it
.current
.pos
;
10385 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
10386 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
10388 if (EQ (Vresize_mini_windows
, Qgrow_only
))
10390 /* Let it grow only, until we display an empty message, in which
10391 case the window shrinks again. */
10392 if (height
> WINDOW_TOTAL_LINES (w
))
10394 int old_height
= WINDOW_TOTAL_LINES (w
);
10395 freeze_window_starts (f
, 1);
10396 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10397 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10399 else if (height
< WINDOW_TOTAL_LINES (w
)
10400 && (exact_p
|| BEGV
== ZV
))
10402 int old_height
= WINDOW_TOTAL_LINES (w
);
10403 freeze_window_starts (f
, 0);
10404 shrink_mini_window (w
);
10405 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10410 /* Always resize to exact size needed. */
10411 if (height
> WINDOW_TOTAL_LINES (w
))
10413 int old_height
= WINDOW_TOTAL_LINES (w
);
10414 freeze_window_starts (f
, 1);
10415 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10416 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10418 else if (height
< WINDOW_TOTAL_LINES (w
))
10420 int old_height
= WINDOW_TOTAL_LINES (w
);
10421 freeze_window_starts (f
, 0);
10422 shrink_mini_window (w
);
10426 freeze_window_starts (f
, 1);
10427 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10430 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10434 if (old_current_buffer
)
10435 set_buffer_internal (old_current_buffer
);
10438 return window_height_changed_p
;
10442 /* Value is the current message, a string, or nil if there is no
10443 current message. */
10446 current_message (void)
10450 if (!BUFFERP (echo_area_buffer
[0]))
10454 with_echo_area_buffer (0, 0, current_message_1
,
10455 (intptr_t) &msg
, Qnil
);
10457 echo_area_buffer
[0] = Qnil
;
10465 current_message_1 (ptrdiff_t a1
, Lisp_Object a2
)
10468 Lisp_Object
*msg
= (Lisp_Object
*) i1
;
10471 *msg
= make_buffer_string (BEG
, Z
, 1);
10478 /* Push the current message on Vmessage_stack for later restoration
10479 by restore_message. Value is non-zero if the current message isn't
10480 empty. This is a relatively infrequent operation, so it's not
10481 worth optimizing. */
10484 push_message (void)
10486 Lisp_Object msg
= current_message ();
10487 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
10488 return STRINGP (msg
);
10492 /* Restore message display from the top of Vmessage_stack. */
10495 restore_message (void)
10497 eassert (CONSP (Vmessage_stack
));
10498 message3_nolog (XCAR (Vmessage_stack
));
10502 /* Handler for record_unwind_protect calling pop_message. */
10505 pop_message_unwind (Lisp_Object dummy
)
10511 /* Pop the top-most entry off Vmessage_stack. */
10516 eassert (CONSP (Vmessage_stack
));
10517 Vmessage_stack
= XCDR (Vmessage_stack
);
10521 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
10522 exits. If the stack is not empty, we have a missing pop_message
10526 check_message_stack (void)
10528 if (!NILP (Vmessage_stack
))
10533 /* Truncate to NCHARS what will be displayed in the echo area the next
10534 time we display it---but don't redisplay it now. */
10537 truncate_echo_area (ptrdiff_t nchars
)
10540 echo_area_buffer
[0] = Qnil
;
10541 else if (!noninteractive
10543 && !NILP (echo_area_buffer
[0]))
10545 struct frame
*sf
= SELECTED_FRAME ();
10546 /* Error messages get reported properly by cmd_error, so this must be
10547 just an informative message; if the frame hasn't really been
10548 initialized yet, just toss it. */
10549 if (sf
->glyphs_initialized_p
)
10550 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
);
10555 /* Helper function for truncate_echo_area. Truncate the current
10556 message to at most NCHARS characters. */
10559 truncate_message_1 (ptrdiff_t nchars
, Lisp_Object a2
)
10561 if (BEG
+ nchars
< Z
)
10562 del_range (BEG
+ nchars
, Z
);
10564 echo_area_buffer
[0] = Qnil
;
10568 /* Set the current message to STRING. */
10571 set_message (Lisp_Object string
)
10573 eassert (STRINGP (string
));
10575 message_enable_multibyte
= STRING_MULTIBYTE (string
);
10577 with_echo_area_buffer (0, -1, set_message_1
, 0, string
);
10578 message_buf_print
= 0;
10579 help_echo_showing_p
= 0;
10581 if (STRINGP (Vdebug_on_message
)
10582 && STRINGP (string
)
10583 && fast_string_match (Vdebug_on_message
, string
) >= 0)
10584 call_debugger (list2 (Qerror
, string
));
10588 /* Helper function for set_message. First argument is ignored and second
10589 argument has the same meaning as for set_message.
10590 This function is called with the echo area buffer being current. */
10593 set_message_1 (ptrdiff_t a1
, Lisp_Object string
)
10595 eassert (STRINGP (string
));
10597 /* Change multibyteness of the echo buffer appropriately. */
10598 if (message_enable_multibyte
10599 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10600 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
10602 bset_truncate_lines (current_buffer
, message_truncate_lines
? Qt
: Qnil
);
10603 if (!NILP (BVAR (current_buffer
, bidi_display_reordering
)))
10604 bset_bidi_paragraph_direction (current_buffer
, Qleft_to_right
);
10606 /* Insert new message at BEG. */
10607 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10609 /* This function takes care of single/multibyte conversion.
10610 We just have to ensure that the echo area buffer has the right
10611 setting of enable_multibyte_characters. */
10612 insert_from_string (string
, 0, 0, SCHARS (string
), SBYTES (string
), 1);
10618 /* Clear messages. CURRENT_P non-zero means clear the current
10619 message. LAST_DISPLAYED_P non-zero means clear the message
10623 clear_message (int current_p
, int last_displayed_p
)
10627 echo_area_buffer
[0] = Qnil
;
10628 message_cleared_p
= 1;
10631 if (last_displayed_p
)
10632 echo_area_buffer
[1] = Qnil
;
10634 message_buf_print
= 0;
10637 /* Clear garbaged frames.
10639 This function is used where the old redisplay called
10640 redraw_garbaged_frames which in turn called redraw_frame which in
10641 turn called clear_frame. The call to clear_frame was a source of
10642 flickering. I believe a clear_frame is not necessary. It should
10643 suffice in the new redisplay to invalidate all current matrices,
10644 and ensure a complete redisplay of all windows. */
10647 clear_garbaged_frames (void)
10649 if (frame_garbaged
)
10651 Lisp_Object tail
, frame
;
10652 int changed_count
= 0;
10654 FOR_EACH_FRAME (tail
, frame
)
10656 struct frame
*f
= XFRAME (frame
);
10658 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
10663 f
->force_flush_display_p
= 1;
10665 clear_current_matrices (f
);
10672 frame_garbaged
= 0;
10674 ++windows_or_buffers_changed
;
10679 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
10680 is non-zero update selected_frame. Value is non-zero if the
10681 mini-windows height has been changed. */
10684 echo_area_display (int update_frame_p
)
10686 Lisp_Object mini_window
;
10689 int window_height_changed_p
= 0;
10690 struct frame
*sf
= SELECTED_FRAME ();
10692 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10693 w
= XWINDOW (mini_window
);
10694 f
= XFRAME (WINDOW_FRAME (w
));
10696 /* Don't display if frame is invisible or not yet initialized. */
10697 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
10700 #ifdef HAVE_WINDOW_SYSTEM
10701 /* When Emacs starts, selected_frame may be the initial terminal
10702 frame. If we let this through, a message would be displayed on
10704 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
10706 #endif /* HAVE_WINDOW_SYSTEM */
10708 /* Redraw garbaged frames. */
10709 clear_garbaged_frames ();
10711 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
10713 echo_area_window
= mini_window
;
10714 window_height_changed_p
= display_echo_area (w
);
10715 w
->must_be_updated_p
= 1;
10717 /* Update the display, unless called from redisplay_internal.
10718 Also don't update the screen during redisplay itself. The
10719 update will happen at the end of redisplay, and an update
10720 here could cause confusion. */
10721 if (update_frame_p
&& !redisplaying_p
)
10725 /* If the display update has been interrupted by pending
10726 input, update mode lines in the frame. Due to the
10727 pending input, it might have been that redisplay hasn't
10728 been called, so that mode lines above the echo area are
10729 garbaged. This looks odd, so we prevent it here. */
10730 if (!display_completed
)
10731 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
10733 if (window_height_changed_p
10734 /* Don't do this if Emacs is shutting down. Redisplay
10735 needs to run hooks. */
10736 && !NILP (Vrun_hooks
))
10738 /* Must update other windows. Likewise as in other
10739 cases, don't let this update be interrupted by
10741 ptrdiff_t count
= SPECPDL_INDEX ();
10742 specbind (Qredisplay_dont_pause
, Qt
);
10743 windows_or_buffers_changed
= 1;
10744 redisplay_internal ();
10745 unbind_to (count
, Qnil
);
10747 else if (FRAME_WINDOW_P (f
) && n
== 0)
10749 /* Window configuration is the same as before.
10750 Can do with a display update of the echo area,
10751 unless we displayed some mode lines. */
10752 update_single_window (w
, 1);
10753 FRAME_RIF (f
)->flush_display (f
);
10756 update_frame (f
, 1, 1);
10758 /* If cursor is in the echo area, make sure that the next
10759 redisplay displays the minibuffer, so that the cursor will
10760 be replaced with what the minibuffer wants. */
10761 if (cursor_in_echo_area
)
10762 ++windows_or_buffers_changed
;
10765 else if (!EQ (mini_window
, selected_window
))
10766 windows_or_buffers_changed
++;
10768 /* Last displayed message is now the current message. */
10769 echo_area_buffer
[1] = echo_area_buffer
[0];
10770 /* Inform read_char that we're not echoing. */
10771 echo_message_buffer
= Qnil
;
10773 /* Prevent redisplay optimization in redisplay_internal by resetting
10774 this_line_start_pos. This is done because the mini-buffer now
10775 displays the message instead of its buffer text. */
10776 if (EQ (mini_window
, selected_window
))
10777 CHARPOS (this_line_start_pos
) = 0;
10779 return window_height_changed_p
;
10782 /* Nonzero if the current window's buffer is shown in more than one
10783 window and was modified since last redisplay. */
10786 buffer_shared_and_changed (void)
10788 return (buffer_window_count (current_buffer
) > 1
10789 && UNCHANGED_MODIFIED
< MODIFF
);
10792 /* Nonzero if W doesn't reflect the actual state of current buffer due
10793 to its text or overlays change. FIXME: this may be called when
10794 XBUFFER (w->buffer) != current_buffer, which looks suspicious. */
10797 window_outdated (struct window
*w
)
10799 return (w
->last_modified
< MODIFF
10800 || w
->last_overlay_modified
< OVERLAY_MODIFF
);
10803 /* Nonzero if W's buffer was changed but not saved or Transient Mark mode
10804 is enabled and mark of W's buffer was changed since last W's update. */
10807 window_buffer_changed (struct window
*w
)
10809 struct buffer
*b
= XBUFFER (w
->buffer
);
10811 eassert (BUFFER_LIVE_P (b
));
10813 return (((BUF_SAVE_MODIFF (b
) < BUF_MODIFF (b
)) != w
->last_had_star
)
10814 || ((!NILP (Vtransient_mark_mode
) && !NILP (BVAR (b
, mark_active
)))
10815 != (w
->region_showing
!= 0)));
10818 /* Nonzero if W has %c in its mode line and mode line should be updated. */
10821 mode_line_update_needed (struct window
*w
)
10823 return (w
->column_number_displayed
!= -1
10824 && !(PT
== w
->last_point
&& !window_outdated (w
))
10825 && (w
->column_number_displayed
!= current_column ()));
10828 /***********************************************************************
10829 Mode Lines and Frame Titles
10830 ***********************************************************************/
10832 /* A buffer for constructing non-propertized mode-line strings and
10833 frame titles in it; allocated from the heap in init_xdisp and
10834 resized as needed in store_mode_line_noprop_char. */
10836 static char *mode_line_noprop_buf
;
10838 /* The buffer's end, and a current output position in it. */
10840 static char *mode_line_noprop_buf_end
;
10841 static char *mode_line_noprop_ptr
;
10843 #define MODE_LINE_NOPROP_LEN(start) \
10844 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
10847 MODE_LINE_DISPLAY
= 0,
10851 } mode_line_target
;
10853 /* Alist that caches the results of :propertize.
10854 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
10855 static Lisp_Object mode_line_proptrans_alist
;
10857 /* List of strings making up the mode-line. */
10858 static Lisp_Object mode_line_string_list
;
10860 /* Base face property when building propertized mode line string. */
10861 static Lisp_Object mode_line_string_face
;
10862 static Lisp_Object mode_line_string_face_prop
;
10865 /* Unwind data for mode line strings */
10867 static Lisp_Object Vmode_line_unwind_vector
;
10870 format_mode_line_unwind_data (struct frame
*target_frame
,
10871 struct buffer
*obuf
,
10873 int save_proptrans
)
10875 Lisp_Object vector
, tmp
;
10877 /* Reduce consing by keeping one vector in
10878 Vwith_echo_area_save_vector. */
10879 vector
= Vmode_line_unwind_vector
;
10880 Vmode_line_unwind_vector
= Qnil
;
10883 vector
= Fmake_vector (make_number (10), Qnil
);
10885 ASET (vector
, 0, make_number (mode_line_target
));
10886 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
10887 ASET (vector
, 2, mode_line_string_list
);
10888 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
10889 ASET (vector
, 4, mode_line_string_face
);
10890 ASET (vector
, 5, mode_line_string_face_prop
);
10893 XSETBUFFER (tmp
, obuf
);
10896 ASET (vector
, 6, tmp
);
10897 ASET (vector
, 7, owin
);
10900 /* Similarly to `with-selected-window', if the operation selects
10901 a window on another frame, we must restore that frame's
10902 selected window, and (for a tty) the top-frame. */
10903 ASET (vector
, 8, target_frame
->selected_window
);
10904 if (FRAME_TERMCAP_P (target_frame
))
10905 ASET (vector
, 9, FRAME_TTY (target_frame
)->top_frame
);
10912 unwind_format_mode_line (Lisp_Object vector
)
10914 Lisp_Object old_window
= AREF (vector
, 7);
10915 Lisp_Object target_frame_window
= AREF (vector
, 8);
10916 Lisp_Object old_top_frame
= AREF (vector
, 9);
10918 mode_line_target
= XINT (AREF (vector
, 0));
10919 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
10920 mode_line_string_list
= AREF (vector
, 2);
10921 if (! EQ (AREF (vector
, 3), Qt
))
10922 mode_line_proptrans_alist
= AREF (vector
, 3);
10923 mode_line_string_face
= AREF (vector
, 4);
10924 mode_line_string_face_prop
= AREF (vector
, 5);
10926 /* Select window before buffer, since it may change the buffer. */
10927 if (!NILP (old_window
))
10929 /* If the operation that we are unwinding had selected a window
10930 on a different frame, reset its frame-selected-window. For a
10931 text terminal, reset its top-frame if necessary. */
10932 if (!NILP (target_frame_window
))
10935 = WINDOW_FRAME (XWINDOW (target_frame_window
));
10937 if (!EQ (frame
, WINDOW_FRAME (XWINDOW (old_window
))))
10938 Fselect_window (target_frame_window
, Qt
);
10940 if (!NILP (old_top_frame
) && !EQ (old_top_frame
, frame
))
10941 Fselect_frame (old_top_frame
, Qt
);
10944 Fselect_window (old_window
, Qt
);
10947 if (!NILP (AREF (vector
, 6)))
10949 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
10950 ASET (vector
, 6, Qnil
);
10953 Vmode_line_unwind_vector
= vector
;
10958 /* Store a single character C for the frame title in mode_line_noprop_buf.
10959 Re-allocate mode_line_noprop_buf if necessary. */
10962 store_mode_line_noprop_char (char c
)
10964 /* If output position has reached the end of the allocated buffer,
10965 increase the buffer's size. */
10966 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
10968 ptrdiff_t len
= MODE_LINE_NOPROP_LEN (0);
10969 ptrdiff_t size
= len
;
10970 mode_line_noprop_buf
=
10971 xpalloc (mode_line_noprop_buf
, &size
, 1, STRING_BYTES_BOUND
, 1);
10972 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
10973 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
10976 *mode_line_noprop_ptr
++ = c
;
10980 /* Store part of a frame title in mode_line_noprop_buf, beginning at
10981 mode_line_noprop_ptr. STRING is the string to store. Do not copy
10982 characters that yield more columns than PRECISION; PRECISION <= 0
10983 means copy the whole string. Pad with spaces until FIELD_WIDTH
10984 number of characters have been copied; FIELD_WIDTH <= 0 means don't
10985 pad. Called from display_mode_element when it is used to build a
10989 store_mode_line_noprop (const char *string
, int field_width
, int precision
)
10991 const unsigned char *str
= (const unsigned char *) string
;
10993 ptrdiff_t dummy
, nbytes
;
10995 /* Copy at most PRECISION chars from STR. */
10996 nbytes
= strlen (string
);
10997 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
10999 store_mode_line_noprop_char (*str
++);
11001 /* Fill up with spaces until FIELD_WIDTH reached. */
11002 while (field_width
> 0
11003 && n
< field_width
)
11005 store_mode_line_noprop_char (' ');
11012 /***********************************************************************
11014 ***********************************************************************/
11016 #ifdef HAVE_WINDOW_SYSTEM
11018 /* Set the title of FRAME, if it has changed. The title format is
11019 Vicon_title_format if FRAME is iconified, otherwise it is
11020 frame_title_format. */
11023 x_consider_frame_title (Lisp_Object frame
)
11025 struct frame
*f
= XFRAME (frame
);
11027 if (FRAME_WINDOW_P (f
)
11028 || FRAME_MINIBUF_ONLY_P (f
)
11029 || f
->explicit_name
)
11031 /* Do we have more than one visible frame on this X display? */
11032 Lisp_Object tail
, other_frame
, fmt
;
11033 ptrdiff_t title_start
;
11037 ptrdiff_t count
= SPECPDL_INDEX ();
11039 FOR_EACH_FRAME (tail
, other_frame
)
11041 struct frame
*tf
= XFRAME (other_frame
);
11044 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
11045 && !FRAME_MINIBUF_ONLY_P (tf
)
11046 && !EQ (other_frame
, tip_frame
)
11047 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
11051 /* Set global variable indicating that multiple frames exist. */
11052 multiple_frames
= CONSP (tail
);
11054 /* Switch to the buffer of selected window of the frame. Set up
11055 mode_line_target so that display_mode_element will output into
11056 mode_line_noprop_buf; then display the title. */
11057 record_unwind_protect (unwind_format_mode_line
,
11058 format_mode_line_unwind_data
11059 (f
, current_buffer
, selected_window
, 0));
11061 Fselect_window (f
->selected_window
, Qt
);
11062 set_buffer_internal_1
11063 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
11064 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
11066 mode_line_target
= MODE_LINE_TITLE
;
11067 title_start
= MODE_LINE_NOPROP_LEN (0);
11068 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
11069 NULL
, DEFAULT_FACE_ID
);
11070 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
11071 len
= MODE_LINE_NOPROP_LEN (title_start
);
11072 title
= mode_line_noprop_buf
+ title_start
;
11073 unbind_to (count
, Qnil
);
11075 /* Set the title only if it's changed. This avoids consing in
11076 the common case where it hasn't. (If it turns out that we've
11077 already wasted too much time by walking through the list with
11078 display_mode_element, then we might need to optimize at a
11079 higher level than this.) */
11080 if (! STRINGP (f
->name
)
11081 || SBYTES (f
->name
) != len
11082 || memcmp (title
, SDATA (f
->name
), len
) != 0)
11083 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
11087 #endif /* not HAVE_WINDOW_SYSTEM */
11090 /***********************************************************************
11092 ***********************************************************************/
11095 /* Prepare for redisplay by updating menu-bar item lists when
11096 appropriate. This can call eval. */
11099 prepare_menu_bars (void)
11102 struct gcpro gcpro1
, gcpro2
;
11104 Lisp_Object tooltip_frame
;
11106 #ifdef HAVE_WINDOW_SYSTEM
11107 tooltip_frame
= tip_frame
;
11109 tooltip_frame
= Qnil
;
11112 /* Update all frame titles based on their buffer names, etc. We do
11113 this before the menu bars so that the buffer-menu will show the
11114 up-to-date frame titles. */
11115 #ifdef HAVE_WINDOW_SYSTEM
11116 if (windows_or_buffers_changed
|| update_mode_lines
)
11118 Lisp_Object tail
, frame
;
11120 FOR_EACH_FRAME (tail
, frame
)
11122 f
= XFRAME (frame
);
11123 if (!EQ (frame
, tooltip_frame
)
11124 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
11125 x_consider_frame_title (frame
);
11128 #endif /* HAVE_WINDOW_SYSTEM */
11130 /* Update the menu bar item lists, if appropriate. This has to be
11131 done before any actual redisplay or generation of display lines. */
11132 all_windows
= (update_mode_lines
11133 || buffer_shared_and_changed ()
11134 || windows_or_buffers_changed
);
11137 Lisp_Object tail
, frame
;
11138 ptrdiff_t count
= SPECPDL_INDEX ();
11139 /* 1 means that update_menu_bar has run its hooks
11140 so any further calls to update_menu_bar shouldn't do so again. */
11141 int menu_bar_hooks_run
= 0;
11143 record_unwind_save_match_data ();
11145 FOR_EACH_FRAME (tail
, frame
)
11147 f
= XFRAME (frame
);
11149 /* Ignore tooltip frame. */
11150 if (EQ (frame
, tooltip_frame
))
11153 /* If a window on this frame changed size, report that to
11154 the user and clear the size-change flag. */
11155 if (FRAME_WINDOW_SIZES_CHANGED (f
))
11157 Lisp_Object functions
;
11159 /* Clear flag first in case we get an error below. */
11160 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
11161 functions
= Vwindow_size_change_functions
;
11162 GCPRO2 (tail
, functions
);
11164 while (CONSP (functions
))
11166 if (!EQ (XCAR (functions
), Qt
))
11167 call1 (XCAR (functions
), frame
);
11168 functions
= XCDR (functions
);
11174 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
11175 #ifdef HAVE_WINDOW_SYSTEM
11176 update_tool_bar (f
, 0);
11179 if (windows_or_buffers_changed
11182 (f
, Fbuffer_modified_p (XWINDOW (f
->selected_window
)->buffer
));
11187 unbind_to (count
, Qnil
);
11191 struct frame
*sf
= SELECTED_FRAME ();
11192 update_menu_bar (sf
, 1, 0);
11193 #ifdef HAVE_WINDOW_SYSTEM
11194 update_tool_bar (sf
, 1);
11200 /* Update the menu bar item list for frame F. This has to be done
11201 before we start to fill in any display lines, because it can call
11204 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
11206 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
11207 already ran the menu bar hooks for this redisplay, so there
11208 is no need to run them again. The return value is the
11209 updated value of this flag, to pass to the next call. */
11212 update_menu_bar (struct frame
*f
, int save_match_data
, int hooks_run
)
11214 Lisp_Object window
;
11215 register struct window
*w
;
11217 /* If called recursively during a menu update, do nothing. This can
11218 happen when, for instance, an activate-menubar-hook causes a
11220 if (inhibit_menubar_update
)
11223 window
= FRAME_SELECTED_WINDOW (f
);
11224 w
= XWINDOW (window
);
11226 if (FRAME_WINDOW_P (f
)
11228 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11229 || defined (HAVE_NS) || defined (USE_GTK)
11230 FRAME_EXTERNAL_MENU_BAR (f
)
11232 FRAME_MENU_BAR_LINES (f
) > 0
11234 : FRAME_MENU_BAR_LINES (f
) > 0)
11236 /* If the user has switched buffers or windows, we need to
11237 recompute to reflect the new bindings. But we'll
11238 recompute when update_mode_lines is set too; that means
11239 that people can use force-mode-line-update to request
11240 that the menu bar be recomputed. The adverse effect on
11241 the rest of the redisplay algorithm is about the same as
11242 windows_or_buffers_changed anyway. */
11243 if (windows_or_buffers_changed
11244 /* This used to test w->update_mode_line, but we believe
11245 there is no need to recompute the menu in that case. */
11246 || update_mode_lines
11247 || window_buffer_changed (w
))
11249 struct buffer
*prev
= current_buffer
;
11250 ptrdiff_t count
= SPECPDL_INDEX ();
11252 specbind (Qinhibit_menubar_update
, Qt
);
11254 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11255 if (save_match_data
)
11256 record_unwind_save_match_data ();
11257 if (NILP (Voverriding_local_map_menu_flag
))
11259 specbind (Qoverriding_terminal_local_map
, Qnil
);
11260 specbind (Qoverriding_local_map
, Qnil
);
11265 /* Run the Lucid hook. */
11266 safe_run_hooks (Qactivate_menubar_hook
);
11268 /* If it has changed current-menubar from previous value,
11269 really recompute the menu-bar from the value. */
11270 if (! NILP (Vlucid_menu_bar_dirty_flag
))
11271 call0 (Qrecompute_lucid_menubar
);
11273 safe_run_hooks (Qmenu_bar_update_hook
);
11278 XSETFRAME (Vmenu_updating_frame
, f
);
11279 fset_menu_bar_items (f
, menu_bar_items (FRAME_MENU_BAR_ITEMS (f
)));
11281 /* Redisplay the menu bar in case we changed it. */
11282 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11283 || defined (HAVE_NS) || defined (USE_GTK)
11284 if (FRAME_WINDOW_P (f
))
11286 #if defined (HAVE_NS)
11287 /* All frames on Mac OS share the same menubar. So only
11288 the selected frame should be allowed to set it. */
11289 if (f
== SELECTED_FRAME ())
11291 set_frame_menubar (f
, 0, 0);
11294 /* On a terminal screen, the menu bar is an ordinary screen
11295 line, and this makes it get updated. */
11296 w
->update_mode_line
= 1;
11297 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11298 /* In the non-toolkit version, the menu bar is an ordinary screen
11299 line, and this makes it get updated. */
11300 w
->update_mode_line
= 1;
11301 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11303 unbind_to (count
, Qnil
);
11304 set_buffer_internal_1 (prev
);
11313 /***********************************************************************
11315 ***********************************************************************/
11317 #ifdef HAVE_WINDOW_SYSTEM
11320 Nominal cursor position -- where to draw output.
11321 HPOS and VPOS are window relative glyph matrix coordinates.
11322 X and Y are window relative pixel coordinates. */
11324 struct cursor_pos output_cursor
;
11328 Set the global variable output_cursor to CURSOR. All cursor
11329 positions are relative to updated_window. */
11332 set_output_cursor (struct cursor_pos
*cursor
)
11334 output_cursor
.hpos
= cursor
->hpos
;
11335 output_cursor
.vpos
= cursor
->vpos
;
11336 output_cursor
.x
= cursor
->x
;
11337 output_cursor
.y
= cursor
->y
;
11342 Set a nominal cursor position.
11344 HPOS and VPOS are column/row positions in a window glyph matrix. X
11345 and Y are window text area relative pixel positions.
11347 If this is done during an update, updated_window will contain the
11348 window that is being updated and the position is the future output
11349 cursor position for that window. If updated_window is null, use
11350 selected_window and display the cursor at the given position. */
11353 x_cursor_to (int vpos
, int hpos
, int y
, int x
)
11357 /* If updated_window is not set, work on selected_window. */
11358 if (updated_window
)
11359 w
= updated_window
;
11361 w
= XWINDOW (selected_window
);
11363 /* Set the output cursor. */
11364 output_cursor
.hpos
= hpos
;
11365 output_cursor
.vpos
= vpos
;
11366 output_cursor
.x
= x
;
11367 output_cursor
.y
= y
;
11369 /* If not called as part of an update, really display the cursor.
11370 This will also set the cursor position of W. */
11371 if (updated_window
== NULL
)
11374 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
11375 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
11376 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
11381 #endif /* HAVE_WINDOW_SYSTEM */
11384 /***********************************************************************
11386 ***********************************************************************/
11388 #ifdef HAVE_WINDOW_SYSTEM
11390 /* Where the mouse was last time we reported a mouse event. */
11392 FRAME_PTR last_mouse_frame
;
11394 /* Tool-bar item index of the item on which a mouse button was pressed
11397 int last_tool_bar_item
;
11399 /* Select `frame' temporarily without running all the code in
11401 FIXME: Maybe do_switch_frame should be trimmed down similarly
11402 when `norecord' is set. */
11404 fast_set_selected_frame (Lisp_Object frame
)
11406 if (!EQ (selected_frame
, frame
))
11408 selected_frame
= frame
;
11409 selected_window
= XFRAME (frame
)->selected_window
;
11414 /* Update the tool-bar item list for frame F. This has to be done
11415 before we start to fill in any display lines. Called from
11416 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
11417 and restore it here. */
11420 update_tool_bar (struct frame
*f
, int save_match_data
)
11422 #if defined (USE_GTK) || defined (HAVE_NS)
11423 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
11425 int do_update
= WINDOWP (f
->tool_bar_window
)
11426 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
11431 Lisp_Object window
;
11434 window
= FRAME_SELECTED_WINDOW (f
);
11435 w
= XWINDOW (window
);
11437 /* If the user has switched buffers or windows, we need to
11438 recompute to reflect the new bindings. But we'll
11439 recompute when update_mode_lines is set too; that means
11440 that people can use force-mode-line-update to request
11441 that the menu bar be recomputed. The adverse effect on
11442 the rest of the redisplay algorithm is about the same as
11443 windows_or_buffers_changed anyway. */
11444 if (windows_or_buffers_changed
11445 || w
->update_mode_line
11446 || update_mode_lines
11447 || window_buffer_changed (w
))
11449 struct buffer
*prev
= current_buffer
;
11450 ptrdiff_t count
= SPECPDL_INDEX ();
11451 Lisp_Object frame
, new_tool_bar
;
11452 int new_n_tool_bar
;
11453 struct gcpro gcpro1
;
11455 /* Set current_buffer to the buffer of the selected
11456 window of the frame, so that we get the right local
11458 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11460 /* Save match data, if we must. */
11461 if (save_match_data
)
11462 record_unwind_save_match_data ();
11464 /* Make sure that we don't accidentally use bogus keymaps. */
11465 if (NILP (Voverriding_local_map_menu_flag
))
11467 specbind (Qoverriding_terminal_local_map
, Qnil
);
11468 specbind (Qoverriding_local_map
, Qnil
);
11471 GCPRO1 (new_tool_bar
);
11473 /* We must temporarily set the selected frame to this frame
11474 before calling tool_bar_items, because the calculation of
11475 the tool-bar keymap uses the selected frame (see
11476 `tool-bar-make-keymap' in tool-bar.el). */
11477 eassert (EQ (selected_window
,
11478 /* Since we only explicitly preserve selected_frame,
11479 check that selected_window would be redundant. */
11480 XFRAME (selected_frame
)->selected_window
));
11481 record_unwind_protect (fast_set_selected_frame
, selected_frame
);
11482 XSETFRAME (frame
, f
);
11483 fast_set_selected_frame (frame
);
11485 /* Build desired tool-bar items from keymaps. */
11487 = tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
11490 /* Redisplay the tool-bar if we changed it. */
11491 if (new_n_tool_bar
!= f
->n_tool_bar_items
11492 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
11494 /* Redisplay that happens asynchronously due to an expose event
11495 may access f->tool_bar_items. Make sure we update both
11496 variables within BLOCK_INPUT so no such event interrupts. */
11498 fset_tool_bar_items (f
, new_tool_bar
);
11499 f
->n_tool_bar_items
= new_n_tool_bar
;
11500 w
->update_mode_line
= 1;
11506 unbind_to (count
, Qnil
);
11507 set_buffer_internal_1 (prev
);
11513 /* Set F->desired_tool_bar_string to a Lisp string representing frame
11514 F's desired tool-bar contents. F->tool_bar_items must have
11515 been set up previously by calling prepare_menu_bars. */
11518 build_desired_tool_bar_string (struct frame
*f
)
11520 int i
, size
, size_needed
;
11521 struct gcpro gcpro1
, gcpro2
, gcpro3
;
11522 Lisp_Object image
, plist
, props
;
11524 image
= plist
= props
= Qnil
;
11525 GCPRO3 (image
, plist
, props
);
11527 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
11528 Otherwise, make a new string. */
11530 /* The size of the string we might be able to reuse. */
11531 size
= (STRINGP (f
->desired_tool_bar_string
)
11532 ? SCHARS (f
->desired_tool_bar_string
)
11535 /* We need one space in the string for each image. */
11536 size_needed
= f
->n_tool_bar_items
;
11538 /* Reuse f->desired_tool_bar_string, if possible. */
11539 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
11540 fset_desired_tool_bar_string
11541 (f
, Fmake_string (make_number (size_needed
), make_number (' ')));
11544 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
11545 Fremove_text_properties (make_number (0), make_number (size
),
11546 props
, f
->desired_tool_bar_string
);
11549 /* Put a `display' property on the string for the images to display,
11550 put a `menu_item' property on tool-bar items with a value that
11551 is the index of the item in F's tool-bar item vector. */
11552 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
11554 #define PROP(IDX) \
11555 AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
11557 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
11558 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
11559 int hmargin
, vmargin
, relief
, idx
, end
;
11561 /* If image is a vector, choose the image according to the
11563 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
11564 if (VECTORP (image
))
11568 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
11569 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
11572 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
11573 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
11575 eassert (ASIZE (image
) >= idx
);
11576 image
= AREF (image
, idx
);
11581 /* Ignore invalid image specifications. */
11582 if (!valid_image_p (image
))
11585 /* Display the tool-bar button pressed, or depressed. */
11586 plist
= Fcopy_sequence (XCDR (image
));
11588 /* Compute margin and relief to draw. */
11589 relief
= (tool_bar_button_relief
>= 0
11590 ? tool_bar_button_relief
11591 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
11592 hmargin
= vmargin
= relief
;
11594 if (RANGED_INTEGERP (1, Vtool_bar_button_margin
,
11595 INT_MAX
- max (hmargin
, vmargin
)))
11597 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
11598 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
11600 else if (CONSP (Vtool_bar_button_margin
))
11602 if (RANGED_INTEGERP (1, XCAR (Vtool_bar_button_margin
),
11603 INT_MAX
- hmargin
))
11604 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
11606 if (RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin
),
11607 INT_MAX
- vmargin
))
11608 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
11611 if (auto_raise_tool_bar_buttons_p
)
11613 /* Add a `:relief' property to the image spec if the item is
11617 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
11624 /* If image is selected, display it pressed, i.e. with a
11625 negative relief. If it's not selected, display it with a
11627 plist
= Fplist_put (plist
, QCrelief
,
11629 ? make_number (-relief
)
11630 : make_number (relief
)));
11635 /* Put a margin around the image. */
11636 if (hmargin
|| vmargin
)
11638 if (hmargin
== vmargin
)
11639 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
11641 plist
= Fplist_put (plist
, QCmargin
,
11642 Fcons (make_number (hmargin
),
11643 make_number (vmargin
)));
11646 /* If button is not enabled, and we don't have special images
11647 for the disabled state, make the image appear disabled by
11648 applying an appropriate algorithm to it. */
11649 if (!enabled_p
&& idx
< 0)
11650 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
11652 /* Put a `display' text property on the string for the image to
11653 display. Put a `menu-item' property on the string that gives
11654 the start of this item's properties in the tool-bar items
11656 image
= Fcons (Qimage
, plist
);
11657 props
= list4 (Qdisplay
, image
,
11658 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
11660 /* Let the last image hide all remaining spaces in the tool bar
11661 string. The string can be longer than needed when we reuse a
11662 previous string. */
11663 if (i
+ 1 == f
->n_tool_bar_items
)
11664 end
= SCHARS (f
->desired_tool_bar_string
);
11667 Fadd_text_properties (make_number (i
), make_number (end
),
11668 props
, f
->desired_tool_bar_string
);
11676 /* Display one line of the tool-bar of frame IT->f.
11678 HEIGHT specifies the desired height of the tool-bar line.
11679 If the actual height of the glyph row is less than HEIGHT, the
11680 row's height is increased to HEIGHT, and the icons are centered
11681 vertically in the new height.
11683 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
11684 count a final empty row in case the tool-bar width exactly matches
11689 display_tool_bar_line (struct it
*it
, int height
)
11691 struct glyph_row
*row
= it
->glyph_row
;
11692 int max_x
= it
->last_visible_x
;
11693 struct glyph
*last
;
11695 prepare_desired_row (row
);
11696 row
->y
= it
->current_y
;
11698 /* Note that this isn't made use of if the face hasn't a box,
11699 so there's no need to check the face here. */
11700 it
->start_of_box_run_p
= 1;
11702 while (it
->current_x
< max_x
)
11704 int x
, n_glyphs_before
, i
, nglyphs
;
11705 struct it it_before
;
11707 /* Get the next display element. */
11708 if (!get_next_display_element (it
))
11710 /* Don't count empty row if we are counting needed tool-bar lines. */
11711 if (height
< 0 && !it
->hpos
)
11716 /* Produce glyphs. */
11717 n_glyphs_before
= row
->used
[TEXT_AREA
];
11720 PRODUCE_GLYPHS (it
);
11722 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
11724 x
= it_before
.current_x
;
11725 while (i
< nglyphs
)
11727 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
11729 if (x
+ glyph
->pixel_width
> max_x
)
11731 /* Glyph doesn't fit on line. Backtrack. */
11732 row
->used
[TEXT_AREA
] = n_glyphs_before
;
11734 /* If this is the only glyph on this line, it will never fit on the
11735 tool-bar, so skip it. But ensure there is at least one glyph,
11736 so we don't accidentally disable the tool-bar. */
11737 if (n_glyphs_before
== 0
11738 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
11744 x
+= glyph
->pixel_width
;
11748 /* Stop at line end. */
11749 if (ITERATOR_AT_END_OF_LINE_P (it
))
11752 set_iterator_to_next (it
, 1);
11757 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
11759 /* Use default face for the border below the tool bar.
11761 FIXME: When auto-resize-tool-bars is grow-only, there is
11762 no additional border below the possibly empty tool-bar lines.
11763 So to make the extra empty lines look "normal", we have to
11764 use the tool-bar face for the border too. */
11765 if (!row
->displays_text_p
&& !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
11766 it
->face_id
= DEFAULT_FACE_ID
;
11768 extend_face_to_end_of_line (it
);
11769 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
11770 last
->right_box_line_p
= 1;
11771 if (last
== row
->glyphs
[TEXT_AREA
])
11772 last
->left_box_line_p
= 1;
11774 /* Make line the desired height and center it vertically. */
11775 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
11777 /* Don't add more than one line height. */
11778 height
%= FRAME_LINE_HEIGHT (it
->f
);
11779 it
->max_ascent
+= height
/ 2;
11780 it
->max_descent
+= (height
+ 1) / 2;
11783 compute_line_metrics (it
);
11785 /* If line is empty, make it occupy the rest of the tool-bar. */
11786 if (!row
->displays_text_p
)
11788 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
11789 row
->visible_height
= row
->height
;
11790 row
->ascent
= row
->phys_ascent
= 0;
11791 row
->extra_line_spacing
= 0;
11794 row
->full_width_p
= 1;
11795 row
->continued_p
= 0;
11796 row
->truncated_on_left_p
= 0;
11797 row
->truncated_on_right_p
= 0;
11799 it
->current_x
= it
->hpos
= 0;
11800 it
->current_y
+= row
->height
;
11806 /* Max tool-bar height. */
11808 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
11809 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
11811 /* Value is the number of screen lines needed to make all tool-bar
11812 items of frame F visible. The number of actual rows needed is
11813 returned in *N_ROWS if non-NULL. */
11816 tool_bar_lines_needed (struct frame
*f
, int *n_rows
)
11818 struct window
*w
= XWINDOW (f
->tool_bar_window
);
11820 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
11821 the desired matrix, so use (unused) mode-line row as temporary row to
11822 avoid destroying the first tool-bar row. */
11823 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
11825 /* Initialize an iterator for iteration over
11826 F->desired_tool_bar_string in the tool-bar window of frame F. */
11827 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
11828 it
.first_visible_x
= 0;
11829 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
11830 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
11831 it
.paragraph_embedding
= L2R
;
11833 while (!ITERATOR_AT_END_P (&it
))
11835 clear_glyph_row (temp_row
);
11836 it
.glyph_row
= temp_row
;
11837 display_tool_bar_line (&it
, -1);
11839 clear_glyph_row (temp_row
);
11841 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
11843 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
11845 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
11849 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
11851 doc
: /* Return the number of lines occupied by the tool bar of FRAME.
11852 If FRAME is nil or omitted, use the selected frame. */)
11853 (Lisp_Object frame
)
11855 struct frame
*f
= decode_any_frame (frame
);
11859 if (WINDOWP (f
->tool_bar_window
)
11860 && (w
= XWINDOW (f
->tool_bar_window
),
11861 WINDOW_TOTAL_LINES (w
) > 0))
11863 update_tool_bar (f
, 1);
11864 if (f
->n_tool_bar_items
)
11866 build_desired_tool_bar_string (f
);
11867 nlines
= tool_bar_lines_needed (f
, NULL
);
11871 return make_number (nlines
);
11875 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
11876 height should be changed. */
11879 redisplay_tool_bar (struct frame
*f
)
11883 struct glyph_row
*row
;
11885 #if defined (USE_GTK) || defined (HAVE_NS)
11886 if (FRAME_EXTERNAL_TOOL_BAR (f
))
11887 update_frame_tool_bar (f
);
11891 /* If frame hasn't a tool-bar window or if it is zero-height, don't
11892 do anything. This means you must start with tool-bar-lines
11893 non-zero to get the auto-sizing effect. Or in other words, you
11894 can turn off tool-bars by specifying tool-bar-lines zero. */
11895 if (!WINDOWP (f
->tool_bar_window
)
11896 || (w
= XWINDOW (f
->tool_bar_window
),
11897 WINDOW_TOTAL_LINES (w
) == 0))
11900 /* Set up an iterator for the tool-bar window. */
11901 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
11902 it
.first_visible_x
= 0;
11903 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
11904 row
= it
.glyph_row
;
11906 /* Build a string that represents the contents of the tool-bar. */
11907 build_desired_tool_bar_string (f
);
11908 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
11909 /* FIXME: This should be controlled by a user option. But it
11910 doesn't make sense to have an R2L tool bar if the menu bar cannot
11911 be drawn also R2L, and making the menu bar R2L is tricky due
11912 toolkit-specific code that implements it. If an R2L tool bar is
11913 ever supported, display_tool_bar_line should also be augmented to
11914 call unproduce_glyphs like display_line and display_string
11916 it
.paragraph_embedding
= L2R
;
11918 if (f
->n_tool_bar_rows
== 0)
11922 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
11923 nlines
!= WINDOW_TOTAL_LINES (w
)))
11926 int old_height
= WINDOW_TOTAL_LINES (w
);
11928 XSETFRAME (frame
, f
);
11929 Fmodify_frame_parameters (frame
,
11930 Fcons (Fcons (Qtool_bar_lines
,
11931 make_number (nlines
)),
11933 if (WINDOW_TOTAL_LINES (w
) != old_height
)
11935 clear_glyph_matrix (w
->desired_matrix
);
11936 fonts_changed_p
= 1;
11942 /* Display as many lines as needed to display all tool-bar items. */
11944 if (f
->n_tool_bar_rows
> 0)
11946 int border
, rows
, height
, extra
;
11948 if (TYPE_RANGED_INTEGERP (int, Vtool_bar_border
))
11949 border
= XINT (Vtool_bar_border
);
11950 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
11951 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
11952 else if (EQ (Vtool_bar_border
, Qborder_width
))
11953 border
= f
->border_width
;
11959 rows
= f
->n_tool_bar_rows
;
11960 height
= max (1, (it
.last_visible_y
- border
) / rows
);
11961 extra
= it
.last_visible_y
- border
- height
* rows
;
11963 while (it
.current_y
< it
.last_visible_y
)
11966 if (extra
> 0 && rows
-- > 0)
11968 h
= (extra
+ rows
- 1) / rows
;
11971 display_tool_bar_line (&it
, height
+ h
);
11976 while (it
.current_y
< it
.last_visible_y
)
11977 display_tool_bar_line (&it
, 0);
11980 /* It doesn't make much sense to try scrolling in the tool-bar
11981 window, so don't do it. */
11982 w
->desired_matrix
->no_scrolling_p
= 1;
11983 w
->must_be_updated_p
= 1;
11985 if (!NILP (Vauto_resize_tool_bars
))
11987 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
11988 int change_height_p
= 0;
11990 /* If we couldn't display everything, change the tool-bar's
11991 height if there is room for more. */
11992 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
11993 && it
.current_y
< max_tool_bar_height
)
11994 change_height_p
= 1;
11996 row
= it
.glyph_row
- 1;
11998 /* If there are blank lines at the end, except for a partially
11999 visible blank line at the end that is smaller than
12000 FRAME_LINE_HEIGHT, change the tool-bar's height. */
12001 if (!row
->displays_text_p
12002 && row
->height
>= FRAME_LINE_HEIGHT (f
))
12003 change_height_p
= 1;
12005 /* If row displays tool-bar items, but is partially visible,
12006 change the tool-bar's height. */
12007 if (row
->displays_text_p
12008 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
12009 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
12010 change_height_p
= 1;
12012 /* Resize windows as needed by changing the `tool-bar-lines'
12013 frame parameter. */
12014 if (change_height_p
)
12017 int old_height
= WINDOW_TOTAL_LINES (w
);
12019 int nlines
= tool_bar_lines_needed (f
, &nrows
);
12021 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
12022 && !f
->minimize_tool_bar_window_p
)
12023 ? (nlines
> old_height
)
12024 : (nlines
!= old_height
));
12025 f
->minimize_tool_bar_window_p
= 0;
12027 if (change_height_p
)
12029 XSETFRAME (frame
, f
);
12030 Fmodify_frame_parameters (frame
,
12031 Fcons (Fcons (Qtool_bar_lines
,
12032 make_number (nlines
)),
12034 if (WINDOW_TOTAL_LINES (w
) != old_height
)
12036 clear_glyph_matrix (w
->desired_matrix
);
12037 f
->n_tool_bar_rows
= nrows
;
12038 fonts_changed_p
= 1;
12045 f
->minimize_tool_bar_window_p
= 0;
12050 /* Get information about the tool-bar item which is displayed in GLYPH
12051 on frame F. Return in *PROP_IDX the index where tool-bar item
12052 properties start in F->tool_bar_items. Value is zero if
12053 GLYPH doesn't display a tool-bar item. */
12056 tool_bar_item_info (struct frame
*f
, struct glyph
*glyph
, int *prop_idx
)
12062 /* This function can be called asynchronously, which means we must
12063 exclude any possibility that Fget_text_property signals an
12065 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
12066 charpos
= max (0, charpos
);
12068 /* Get the text property `menu-item' at pos. The value of that
12069 property is the start index of this item's properties in
12070 F->tool_bar_items. */
12071 prop
= Fget_text_property (make_number (charpos
),
12072 Qmenu_item
, f
->current_tool_bar_string
);
12073 if (INTEGERP (prop
))
12075 *prop_idx
= XINT (prop
);
12085 /* Get information about the tool-bar item at position X/Y on frame F.
12086 Return in *GLYPH a pointer to the glyph of the tool-bar item in
12087 the current matrix of the tool-bar window of F, or NULL if not
12088 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
12089 item in F->tool_bar_items. Value is
12091 -1 if X/Y is not on a tool-bar item
12092 0 if X/Y is on the same item that was highlighted before.
12096 get_tool_bar_item (struct frame
*f
, int x
, int y
, struct glyph
**glyph
,
12097 int *hpos
, int *vpos
, int *prop_idx
)
12099 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12100 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12103 /* Find the glyph under X/Y. */
12104 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
12105 if (*glyph
== NULL
)
12108 /* Get the start of this tool-bar item's properties in
12109 f->tool_bar_items. */
12110 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
12113 /* Is mouse on the highlighted item? */
12114 if (EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
)
12115 && *vpos
>= hlinfo
->mouse_face_beg_row
12116 && *vpos
<= hlinfo
->mouse_face_end_row
12117 && (*vpos
> hlinfo
->mouse_face_beg_row
12118 || *hpos
>= hlinfo
->mouse_face_beg_col
)
12119 && (*vpos
< hlinfo
->mouse_face_end_row
12120 || *hpos
< hlinfo
->mouse_face_end_col
12121 || hlinfo
->mouse_face_past_end
))
12129 Handle mouse button event on the tool-bar of frame F, at
12130 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
12131 0 for button release. MODIFIERS is event modifiers for button
12135 handle_tool_bar_click (struct frame
*f
, int x
, int y
, int down_p
,
12138 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12139 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12140 int hpos
, vpos
, prop_idx
;
12141 struct glyph
*glyph
;
12142 Lisp_Object enabled_p
;
12144 /* If not on the highlighted tool-bar item, return. */
12145 frame_to_window_pixel_xy (w
, &x
, &y
);
12146 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
12149 /* If item is disabled, do nothing. */
12150 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12151 if (NILP (enabled_p
))
12156 /* Show item in pressed state. */
12157 show_mouse_face (hlinfo
, DRAW_IMAGE_SUNKEN
);
12158 last_tool_bar_item
= prop_idx
;
12162 Lisp_Object key
, frame
;
12163 struct input_event event
;
12164 EVENT_INIT (event
);
12166 /* Show item in released state. */
12167 show_mouse_face (hlinfo
, DRAW_IMAGE_RAISED
);
12169 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
12171 XSETFRAME (frame
, f
);
12172 event
.kind
= TOOL_BAR_EVENT
;
12173 event
.frame_or_window
= frame
;
12175 kbd_buffer_store_event (&event
);
12177 event
.kind
= TOOL_BAR_EVENT
;
12178 event
.frame_or_window
= frame
;
12180 event
.modifiers
= modifiers
;
12181 kbd_buffer_store_event (&event
);
12182 last_tool_bar_item
= -1;
12187 /* Possibly highlight a tool-bar item on frame F when mouse moves to
12188 tool-bar window-relative coordinates X/Y. Called from
12189 note_mouse_highlight. */
12192 note_tool_bar_highlight (struct frame
*f
, int x
, int y
)
12194 Lisp_Object window
= f
->tool_bar_window
;
12195 struct window
*w
= XWINDOW (window
);
12196 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12197 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12199 struct glyph
*glyph
;
12200 struct glyph_row
*row
;
12202 Lisp_Object enabled_p
;
12204 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
12205 int mouse_down_p
, rc
;
12207 /* Function note_mouse_highlight is called with negative X/Y
12208 values when mouse moves outside of the frame. */
12209 if (x
<= 0 || y
<= 0)
12211 clear_mouse_face (hlinfo
);
12215 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
12218 /* Not on tool-bar item. */
12219 clear_mouse_face (hlinfo
);
12223 /* On same tool-bar item as before. */
12224 goto set_help_echo
;
12226 clear_mouse_face (hlinfo
);
12228 /* Mouse is down, but on different tool-bar item? */
12229 mouse_down_p
= (dpyinfo
->grabbed
12230 && f
== last_mouse_frame
12231 && FRAME_LIVE_P (f
));
12233 && last_tool_bar_item
!= prop_idx
)
12236 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
12238 /* If tool-bar item is not enabled, don't highlight it. */
12239 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12240 if (!NILP (enabled_p
))
12242 /* Compute the x-position of the glyph. In front and past the
12243 image is a space. We include this in the highlighted area. */
12244 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
12245 for (i
= x
= 0; i
< hpos
; ++i
)
12246 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
12248 /* Record this as the current active region. */
12249 hlinfo
->mouse_face_beg_col
= hpos
;
12250 hlinfo
->mouse_face_beg_row
= vpos
;
12251 hlinfo
->mouse_face_beg_x
= x
;
12252 hlinfo
->mouse_face_beg_y
= row
->y
;
12253 hlinfo
->mouse_face_past_end
= 0;
12255 hlinfo
->mouse_face_end_col
= hpos
+ 1;
12256 hlinfo
->mouse_face_end_row
= vpos
;
12257 hlinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
12258 hlinfo
->mouse_face_end_y
= row
->y
;
12259 hlinfo
->mouse_face_window
= window
;
12260 hlinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
12262 /* Display it as active. */
12263 show_mouse_face (hlinfo
, draw
);
12268 /* Set help_echo_string to a help string to display for this tool-bar item.
12269 XTread_socket does the rest. */
12270 help_echo_object
= help_echo_window
= Qnil
;
12271 help_echo_pos
= -1;
12272 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
12273 if (NILP (help_echo_string
))
12274 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
12277 #endif /* HAVE_WINDOW_SYSTEM */
12281 /************************************************************************
12282 Horizontal scrolling
12283 ************************************************************************/
12285 static int hscroll_window_tree (Lisp_Object
);
12286 static int hscroll_windows (Lisp_Object
);
12288 /* For all leaf windows in the window tree rooted at WINDOW, set their
12289 hscroll value so that PT is (i) visible in the window, and (ii) so
12290 that it is not within a certain margin at the window's left and
12291 right border. Value is non-zero if any window's hscroll has been
12295 hscroll_window_tree (Lisp_Object window
)
12297 int hscrolled_p
= 0;
12298 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
12299 int hscroll_step_abs
= 0;
12300 double hscroll_step_rel
= 0;
12302 if (hscroll_relative_p
)
12304 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
12305 if (hscroll_step_rel
< 0)
12307 hscroll_relative_p
= 0;
12308 hscroll_step_abs
= 0;
12311 else if (TYPE_RANGED_INTEGERP (int, Vhscroll_step
))
12313 hscroll_step_abs
= XINT (Vhscroll_step
);
12314 if (hscroll_step_abs
< 0)
12315 hscroll_step_abs
= 0;
12318 hscroll_step_abs
= 0;
12320 while (WINDOWP (window
))
12322 struct window
*w
= XWINDOW (window
);
12324 if (WINDOWP (w
->hchild
))
12325 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
12326 else if (WINDOWP (w
->vchild
))
12327 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
12328 else if (w
->cursor
.vpos
>= 0)
12331 int text_area_width
;
12332 struct glyph_row
*current_cursor_row
12333 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
12334 struct glyph_row
*desired_cursor_row
12335 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
12336 struct glyph_row
*cursor_row
12337 = (desired_cursor_row
->enabled_p
12338 ? desired_cursor_row
12339 : current_cursor_row
);
12340 int row_r2l_p
= cursor_row
->reversed_p
;
12342 text_area_width
= window_box_width (w
, TEXT_AREA
);
12344 /* Scroll when cursor is inside this scroll margin. */
12345 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
12347 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->buffer
))
12348 /* For left-to-right rows, hscroll when cursor is either
12349 (i) inside the right hscroll margin, or (ii) if it is
12350 inside the left margin and the window is already
12354 && w
->cursor
.x
<= h_margin
)
12355 || (cursor_row
->enabled_p
12356 && cursor_row
->truncated_on_right_p
12357 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
12358 /* For right-to-left rows, the logic is similar,
12359 except that rules for scrolling to left and right
12360 are reversed. E.g., if cursor.x <= h_margin, we
12361 need to hscroll "to the right" unconditionally,
12362 and that will scroll the screen to the left so as
12363 to reveal the next portion of the row. */
12365 && ((cursor_row
->enabled_p
12366 /* FIXME: It is confusing to set the
12367 truncated_on_right_p flag when R2L rows
12368 are actually truncated on the left. */
12369 && cursor_row
->truncated_on_right_p
12370 && w
->cursor
.x
<= h_margin
)
12372 && (w
->cursor
.x
>= text_area_width
- h_margin
))))))
12376 struct buffer
*saved_current_buffer
;
12380 /* Find point in a display of infinite width. */
12381 saved_current_buffer
= current_buffer
;
12382 current_buffer
= XBUFFER (w
->buffer
);
12384 if (w
== XWINDOW (selected_window
))
12387 pt
= clip_to_bounds (BEGV
, marker_position (w
->pointm
), ZV
);
12389 /* Move iterator to pt starting at cursor_row->start in
12390 a line with infinite width. */
12391 init_to_row_start (&it
, w
, cursor_row
);
12392 it
.last_visible_x
= INFINITY
;
12393 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
12394 current_buffer
= saved_current_buffer
;
12396 /* Position cursor in window. */
12397 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
12398 hscroll
= max (0, (it
.current_x
12399 - (ITERATOR_AT_END_OF_LINE_P (&it
)
12400 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
12401 : (text_area_width
/ 2))))
12402 / FRAME_COLUMN_WIDTH (it
.f
);
12403 else if ((!row_r2l_p
12404 && w
->cursor
.x
>= text_area_width
- h_margin
)
12405 || (row_r2l_p
&& w
->cursor
.x
<= h_margin
))
12407 if (hscroll_relative_p
)
12408 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
12411 wanted_x
= text_area_width
12412 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12415 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12419 if (hscroll_relative_p
)
12420 wanted_x
= text_area_width
* hscroll_step_rel
12423 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12426 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12428 hscroll
= max (hscroll
, w
->min_hscroll
);
12430 /* Don't prevent redisplay optimizations if hscroll
12431 hasn't changed, as it will unnecessarily slow down
12433 if (w
->hscroll
!= hscroll
)
12435 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
12436 w
->hscroll
= hscroll
;
12445 /* Value is non-zero if hscroll of any leaf window has been changed. */
12446 return hscrolled_p
;
12450 /* Set hscroll so that cursor is visible and not inside horizontal
12451 scroll margins for all windows in the tree rooted at WINDOW. See
12452 also hscroll_window_tree above. Value is non-zero if any window's
12453 hscroll has been changed. If it has, desired matrices on the frame
12454 of WINDOW are cleared. */
12457 hscroll_windows (Lisp_Object window
)
12459 int hscrolled_p
= hscroll_window_tree (window
);
12461 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
12462 return hscrolled_p
;
12467 /************************************************************************
12469 ************************************************************************/
12471 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
12472 to a non-zero value. This is sometimes handy to have in a debugger
12477 /* First and last unchanged row for try_window_id. */
12479 static int debug_first_unchanged_at_end_vpos
;
12480 static int debug_last_unchanged_at_beg_vpos
;
12482 /* Delta vpos and y. */
12484 static int debug_dvpos
, debug_dy
;
12486 /* Delta in characters and bytes for try_window_id. */
12488 static ptrdiff_t debug_delta
, debug_delta_bytes
;
12490 /* Values of window_end_pos and window_end_vpos at the end of
12493 static ptrdiff_t debug_end_vpos
;
12495 /* Append a string to W->desired_matrix->method. FMT is a printf
12496 format string. If trace_redisplay_p is non-zero also printf the
12497 resulting string to stderr. */
12499 static void debug_method_add (struct window
*, char const *, ...)
12500 ATTRIBUTE_FORMAT_PRINTF (2, 3);
12503 debug_method_add (struct window
*w
, char const *fmt
, ...)
12505 char *method
= w
->desired_matrix
->method
;
12506 int len
= strlen (method
);
12507 int size
= sizeof w
->desired_matrix
->method
;
12508 int remaining
= size
- len
- 1;
12511 if (len
&& remaining
)
12514 --remaining
, ++len
;
12517 va_start (ap
, fmt
);
12518 vsnprintf (method
+ len
, remaining
+ 1, fmt
, ap
);
12521 if (trace_redisplay_p
)
12522 fprintf (stderr
, "%p (%s): %s\n",
12524 ((BUFFERP (w
->buffer
)
12525 && STRINGP (BVAR (XBUFFER (w
->buffer
), name
)))
12526 ? SSDATA (BVAR (XBUFFER (w
->buffer
), name
))
12531 #endif /* GLYPH_DEBUG */
12534 /* Value is non-zero if all changes in window W, which displays
12535 current_buffer, are in the text between START and END. START is a
12536 buffer position, END is given as a distance from Z. Used in
12537 redisplay_internal for display optimization. */
12540 text_outside_line_unchanged_p (struct window
*w
,
12541 ptrdiff_t start
, ptrdiff_t end
)
12543 int unchanged_p
= 1;
12545 /* If text or overlays have changed, see where. */
12546 if (window_outdated (w
))
12548 /* Gap in the line? */
12549 if (GPT
< start
|| Z
- GPT
< end
)
12552 /* Changes start in front of the line, or end after it? */
12554 && (BEG_UNCHANGED
< start
- 1
12555 || END_UNCHANGED
< end
))
12558 /* If selective display, can't optimize if changes start at the
12559 beginning of the line. */
12561 && INTEGERP (BVAR (current_buffer
, selective_display
))
12562 && XINT (BVAR (current_buffer
, selective_display
)) > 0
12563 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
12566 /* If there are overlays at the start or end of the line, these
12567 may have overlay strings with newlines in them. A change at
12568 START, for instance, may actually concern the display of such
12569 overlay strings as well, and they are displayed on different
12570 lines. So, quickly rule out this case. (For the future, it
12571 might be desirable to implement something more telling than
12572 just BEG/END_UNCHANGED.) */
12575 if (BEG
+ BEG_UNCHANGED
== start
12576 && overlay_touches_p (start
))
12578 if (END_UNCHANGED
== end
12579 && overlay_touches_p (Z
- end
))
12583 /* Under bidi reordering, adding or deleting a character in the
12584 beginning of a paragraph, before the first strong directional
12585 character, can change the base direction of the paragraph (unless
12586 the buffer specifies a fixed paragraph direction), which will
12587 require to redisplay the whole paragraph. It might be worthwhile
12588 to find the paragraph limits and widen the range of redisplayed
12589 lines to that, but for now just give up this optimization. */
12590 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
12591 && NILP (BVAR (XBUFFER (w
->buffer
), bidi_paragraph_direction
)))
12595 return unchanged_p
;
12599 /* Do a frame update, taking possible shortcuts into account. This is
12600 the main external entry point for redisplay.
12602 If the last redisplay displayed an echo area message and that message
12603 is no longer requested, we clear the echo area or bring back the
12604 mini-buffer if that is in use. */
12609 redisplay_internal ();
12614 overlay_arrow_string_or_property (Lisp_Object var
)
12618 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
12621 return Voverlay_arrow_string
;
12624 /* Return 1 if there are any overlay-arrows in current_buffer. */
12626 overlay_arrow_in_current_buffer_p (void)
12630 for (vlist
= Voverlay_arrow_variable_list
;
12632 vlist
= XCDR (vlist
))
12634 Lisp_Object var
= XCAR (vlist
);
12637 if (!SYMBOLP (var
))
12639 val
= find_symbol_value (var
);
12641 && current_buffer
== XMARKER (val
)->buffer
)
12648 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
12652 overlay_arrows_changed_p (void)
12656 for (vlist
= Voverlay_arrow_variable_list
;
12658 vlist
= XCDR (vlist
))
12660 Lisp_Object var
= XCAR (vlist
);
12661 Lisp_Object val
, pstr
;
12663 if (!SYMBOLP (var
))
12665 val
= find_symbol_value (var
);
12666 if (!MARKERP (val
))
12668 if (! EQ (COERCE_MARKER (val
),
12669 Fget (var
, Qlast_arrow_position
))
12670 || ! (pstr
= overlay_arrow_string_or_property (var
),
12671 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
12677 /* Mark overlay arrows to be updated on next redisplay. */
12680 update_overlay_arrows (int up_to_date
)
12684 for (vlist
= Voverlay_arrow_variable_list
;
12686 vlist
= XCDR (vlist
))
12688 Lisp_Object var
= XCAR (vlist
);
12690 if (!SYMBOLP (var
))
12693 if (up_to_date
> 0)
12695 Lisp_Object val
= find_symbol_value (var
);
12696 Fput (var
, Qlast_arrow_position
,
12697 COERCE_MARKER (val
));
12698 Fput (var
, Qlast_arrow_string
,
12699 overlay_arrow_string_or_property (var
));
12701 else if (up_to_date
< 0
12702 || !NILP (Fget (var
, Qlast_arrow_position
)))
12704 Fput (var
, Qlast_arrow_position
, Qt
);
12705 Fput (var
, Qlast_arrow_string
, Qt
);
12711 /* Return overlay arrow string to display at row.
12712 Return integer (bitmap number) for arrow bitmap in left fringe.
12713 Return nil if no overlay arrow. */
12716 overlay_arrow_at_row (struct it
*it
, struct glyph_row
*row
)
12720 for (vlist
= Voverlay_arrow_variable_list
;
12722 vlist
= XCDR (vlist
))
12724 Lisp_Object var
= XCAR (vlist
);
12727 if (!SYMBOLP (var
))
12730 val
= find_symbol_value (var
);
12733 && current_buffer
== XMARKER (val
)->buffer
12734 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
12736 if (FRAME_WINDOW_P (it
->f
)
12737 /* FIXME: if ROW->reversed_p is set, this should test
12738 the right fringe, not the left one. */
12739 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
12741 #ifdef HAVE_WINDOW_SYSTEM
12742 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
12745 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
12746 return make_number (fringe_bitmap
);
12749 return make_number (-1); /* Use default arrow bitmap. */
12751 return overlay_arrow_string_or_property (var
);
12758 /* Return 1 if point moved out of or into a composition. Otherwise
12759 return 0. PREV_BUF and PREV_PT are the last point buffer and
12760 position. BUF and PT are the current point buffer and position. */
12763 check_point_in_composition (struct buffer
*prev_buf
, ptrdiff_t prev_pt
,
12764 struct buffer
*buf
, ptrdiff_t pt
)
12766 ptrdiff_t start
, end
;
12768 Lisp_Object buffer
;
12770 XSETBUFFER (buffer
, buf
);
12771 /* Check a composition at the last point if point moved within the
12773 if (prev_buf
== buf
)
12776 /* Point didn't move. */
12779 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
12780 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
12781 && COMPOSITION_VALID_P (start
, end
, prop
)
12782 && start
< prev_pt
&& end
> prev_pt
)
12783 /* The last point was within the composition. Return 1 iff
12784 point moved out of the composition. */
12785 return (pt
<= start
|| pt
>= end
);
12788 /* Check a composition at the current point. */
12789 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
12790 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
12791 && COMPOSITION_VALID_P (start
, end
, prop
)
12792 && start
< pt
&& end
> pt
);
12796 /* Reconsider the setting of B->clip_changed which is displayed
12800 reconsider_clip_changes (struct window
*w
, struct buffer
*b
)
12802 if (b
->clip_changed
12803 && w
->window_end_valid
12804 && w
->current_matrix
->buffer
== b
12805 && w
->current_matrix
->zv
== BUF_ZV (b
)
12806 && w
->current_matrix
->begv
== BUF_BEGV (b
))
12807 b
->clip_changed
= 0;
12809 /* If display wasn't paused, and W is not a tool bar window, see if
12810 point has been moved into or out of a composition. In that case,
12811 we set b->clip_changed to 1 to force updating the screen. If
12812 b->clip_changed has already been set to 1, we can skip this
12814 if (!b
->clip_changed
&& BUFFERP (w
->buffer
) && w
->window_end_valid
)
12818 if (w
== XWINDOW (selected_window
))
12821 pt
= marker_position (w
->pointm
);
12823 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
12824 || pt
!= w
->last_point
)
12825 && check_point_in_composition (w
->current_matrix
->buffer
,
12827 XBUFFER (w
->buffer
), pt
))
12828 b
->clip_changed
= 1;
12833 #define STOP_POLLING \
12834 do { if (! polling_stopped_here) stop_polling (); \
12835 polling_stopped_here = 1; } while (0)
12837 #define RESUME_POLLING \
12838 do { if (polling_stopped_here) start_polling (); \
12839 polling_stopped_here = 0; } while (0)
12842 /* Perhaps in the future avoid recentering windows if it
12843 is not necessary; currently that causes some problems. */
12846 redisplay_internal (void)
12848 struct window
*w
= XWINDOW (selected_window
);
12852 int must_finish
= 0;
12853 struct text_pos tlbufpos
, tlendpos
;
12854 int number_of_visible_frames
;
12855 ptrdiff_t count
, count1
;
12857 int polling_stopped_here
= 0;
12858 Lisp_Object tail
, frame
;
12859 struct backtrace backtrace
;
12861 /* Non-zero means redisplay has to consider all windows on all
12862 frames. Zero means, only selected_window is considered. */
12863 int consider_all_windows_p
;
12865 /* Non-zero means redisplay has to redisplay the miniwindow. */
12866 int update_miniwindow_p
= 0;
12868 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
12870 /* No redisplay if running in batch mode or frame is not yet fully
12871 initialized, or redisplay is explicitly turned off by setting
12872 Vinhibit_redisplay. */
12873 if (FRAME_INITIAL_P (SELECTED_FRAME ())
12874 || !NILP (Vinhibit_redisplay
))
12877 /* Don't examine these until after testing Vinhibit_redisplay.
12878 When Emacs is shutting down, perhaps because its connection to
12879 X has dropped, we should not look at them at all. */
12880 fr
= XFRAME (w
->frame
);
12881 sf
= SELECTED_FRAME ();
12883 if (!fr
->glyphs_initialized_p
)
12886 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
12887 if (popup_activated ())
12891 /* I don't think this happens but let's be paranoid. */
12892 if (redisplaying_p
)
12895 /* Record a function that clears redisplaying_p
12896 when we leave this function. */
12897 count
= SPECPDL_INDEX ();
12898 record_unwind_protect (unwind_redisplay
, selected_frame
);
12899 redisplaying_p
= 1;
12900 specbind (Qinhibit_free_realized_faces
, Qnil
);
12902 /* Record this function, so it appears on the profiler's backtraces. */
12903 backtrace
.next
= backtrace_list
;
12904 backtrace
.function
= Qredisplay_internal
;
12905 backtrace
.args
= &Qnil
;
12906 backtrace
.nargs
= 0;
12907 backtrace
.debug_on_exit
= 0;
12908 backtrace_list
= &backtrace
;
12910 FOR_EACH_FRAME (tail
, frame
)
12911 XFRAME (frame
)->already_hscrolled_p
= 0;
12914 /* Remember the currently selected window. */
12918 reconsider_clip_changes (w
, current_buffer
);
12919 last_escape_glyph_frame
= NULL
;
12920 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
12921 last_glyphless_glyph_frame
= NULL
;
12922 last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
12924 /* If new fonts have been loaded that make a glyph matrix adjustment
12925 necessary, do it. */
12926 if (fonts_changed_p
)
12928 adjust_glyphs (NULL
);
12929 ++windows_or_buffers_changed
;
12930 fonts_changed_p
= 0;
12933 /* If face_change_count is non-zero, init_iterator will free all
12934 realized faces, which includes the faces referenced from current
12935 matrices. So, we can't reuse current matrices in this case. */
12936 if (face_change_count
)
12937 ++windows_or_buffers_changed
;
12939 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
12940 && FRAME_TTY (sf
)->previous_frame
!= sf
)
12942 /* Since frames on a single ASCII terminal share the same
12943 display area, displaying a different frame means redisplay
12944 the whole thing. */
12945 windows_or_buffers_changed
++;
12946 SET_FRAME_GARBAGED (sf
);
12948 set_tty_color_mode (FRAME_TTY (sf
), sf
);
12950 FRAME_TTY (sf
)->previous_frame
= sf
;
12953 /* Set the visible flags for all frames. Do this before checking for
12954 resized or garbaged frames; they want to know if their frames are
12955 visible. See the comment in frame.h for FRAME_SAMPLE_VISIBILITY. */
12956 number_of_visible_frames
= 0;
12958 FOR_EACH_FRAME (tail
, frame
)
12960 struct frame
*f
= XFRAME (frame
);
12962 if (FRAME_VISIBLE_P (f
))
12963 ++number_of_visible_frames
;
12964 clear_desired_matrices (f
);
12967 /* Notice any pending interrupt request to change frame size. */
12968 do_pending_window_change (1);
12970 /* do_pending_window_change could change the selected_window due to
12971 frame resizing which makes the selected window too small. */
12972 if (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
)
12975 reconsider_clip_changes (w
, current_buffer
);
12978 /* Clear frames marked as garbaged. */
12979 clear_garbaged_frames ();
12981 /* Build menubar and tool-bar items. */
12982 if (NILP (Vmemory_full
))
12983 prepare_menu_bars ();
12985 if (windows_or_buffers_changed
)
12986 update_mode_lines
++;
12988 /* Detect case that we need to write or remove a star in the mode line. */
12989 if ((SAVE_MODIFF
< MODIFF
) != w
->last_had_star
)
12991 w
->update_mode_line
= 1;
12992 if (buffer_shared_and_changed ())
12993 update_mode_lines
++;
12996 /* Avoid invocation of point motion hooks by `current_column' below. */
12997 count1
= SPECPDL_INDEX ();
12998 specbind (Qinhibit_point_motion_hooks
, Qt
);
13000 if (mode_line_update_needed (w
))
13001 w
->update_mode_line
= 1;
13003 unbind_to (count1
, Qnil
);
13005 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
13007 consider_all_windows_p
= (update_mode_lines
13008 || buffer_shared_and_changed ()
13009 || cursor_type_changed
);
13011 /* If specs for an arrow have changed, do thorough redisplay
13012 to ensure we remove any arrow that should no longer exist. */
13013 if (overlay_arrows_changed_p ())
13014 consider_all_windows_p
= windows_or_buffers_changed
= 1;
13016 /* Normally the message* functions will have already displayed and
13017 updated the echo area, but the frame may have been trashed, or
13018 the update may have been preempted, so display the echo area
13019 again here. Checking message_cleared_p captures the case that
13020 the echo area should be cleared. */
13021 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
13022 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
13023 || (message_cleared_p
13024 && minibuf_level
== 0
13025 /* If the mini-window is currently selected, this means the
13026 echo-area doesn't show through. */
13027 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
13029 int window_height_changed_p
= echo_area_display (0);
13031 if (message_cleared_p
)
13032 update_miniwindow_p
= 1;
13036 /* If we don't display the current message, don't clear the
13037 message_cleared_p flag, because, if we did, we wouldn't clear
13038 the echo area in the next redisplay which doesn't preserve
13040 if (!display_last_displayed_message_p
)
13041 message_cleared_p
= 0;
13043 if (fonts_changed_p
)
13045 else if (window_height_changed_p
)
13047 consider_all_windows_p
= 1;
13048 ++update_mode_lines
;
13049 ++windows_or_buffers_changed
;
13051 /* If window configuration was changed, frames may have been
13052 marked garbaged. Clear them or we will experience
13053 surprises wrt scrolling. */
13054 clear_garbaged_frames ();
13057 else if (EQ (selected_window
, minibuf_window
)
13058 && (current_buffer
->clip_changed
|| window_outdated (w
))
13059 && resize_mini_window (w
, 0))
13061 /* Resized active mini-window to fit the size of what it is
13062 showing if its contents might have changed. */
13064 /* FIXME: this causes all frames to be updated, which seems unnecessary
13065 since only the current frame needs to be considered. This function
13066 needs to be rewritten with two variables, consider_all_windows and
13067 consider_all_frames. */
13068 consider_all_windows_p
= 1;
13069 ++windows_or_buffers_changed
;
13070 ++update_mode_lines
;
13072 /* If window configuration was changed, frames may have been
13073 marked garbaged. Clear them or we will experience
13074 surprises wrt scrolling. */
13075 clear_garbaged_frames ();
13078 /* If showing the region, and mark has changed, we must redisplay
13079 the whole window. The assignment to this_line_start_pos prevents
13080 the optimization directly below this if-statement. */
13081 if (((!NILP (Vtransient_mark_mode
)
13082 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
13083 != (w
->region_showing
> 0))
13084 || (w
->region_showing
13085 && w
->region_showing
13086 != XINT (Fmarker_position (BVAR (XBUFFER (w
->buffer
), mark
)))))
13087 CHARPOS (this_line_start_pos
) = 0;
13089 /* Optimize the case that only the line containing the cursor in the
13090 selected window has changed. Variables starting with this_ are
13091 set in display_line and record information about the line
13092 containing the cursor. */
13093 tlbufpos
= this_line_start_pos
;
13094 tlendpos
= this_line_end_pos
;
13095 if (!consider_all_windows_p
13096 && CHARPOS (tlbufpos
) > 0
13097 && !w
->update_mode_line
13098 && !current_buffer
->clip_changed
13099 && !current_buffer
->prevent_redisplay_optimizations_p
13100 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
13101 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
13102 /* Make sure recorded data applies to current buffer, etc. */
13103 && this_line_buffer
== current_buffer
13104 && current_buffer
== XBUFFER (w
->buffer
)
13106 && !w
->optional_new_start
13107 /* Point must be on the line that we have info recorded about. */
13108 && PT
>= CHARPOS (tlbufpos
)
13109 && PT
<= Z
- CHARPOS (tlendpos
)
13110 /* All text outside that line, including its final newline,
13111 must be unchanged. */
13112 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
13113 CHARPOS (tlendpos
)))
13115 if (CHARPOS (tlbufpos
) > BEGV
13116 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
13117 && (CHARPOS (tlbufpos
) == ZV
13118 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
13119 /* Former continuation line has disappeared by becoming empty. */
13121 else if (window_outdated (w
) || MINI_WINDOW_P (w
))
13123 /* We have to handle the case of continuation around a
13124 wide-column character (see the comment in indent.c around
13127 For instance, in the following case:
13129 -------- Insert --------
13130 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
13131 J_I_ ==> J_I_ `^^' are cursors.
13135 As we have to redraw the line above, we cannot use this
13139 int line_height_before
= this_line_pixel_height
;
13141 /* Note that start_display will handle the case that the
13142 line starting at tlbufpos is a continuation line. */
13143 start_display (&it
, w
, tlbufpos
);
13145 /* Implementation note: It this still necessary? */
13146 if (it
.current_x
!= this_line_start_x
)
13149 TRACE ((stderr
, "trying display optimization 1\n"));
13150 w
->cursor
.vpos
= -1;
13151 overlay_arrow_seen
= 0;
13152 it
.vpos
= this_line_vpos
;
13153 it
.current_y
= this_line_y
;
13154 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
13155 display_line (&it
);
13157 /* If line contains point, is not continued,
13158 and ends at same distance from eob as before, we win. */
13159 if (w
->cursor
.vpos
>= 0
13160 /* Line is not continued, otherwise this_line_start_pos
13161 would have been set to 0 in display_line. */
13162 && CHARPOS (this_line_start_pos
)
13163 /* Line ends as before. */
13164 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
13165 /* Line has same height as before. Otherwise other lines
13166 would have to be shifted up or down. */
13167 && this_line_pixel_height
== line_height_before
)
13169 /* If this is not the window's last line, we must adjust
13170 the charstarts of the lines below. */
13171 if (it
.current_y
< it
.last_visible_y
)
13173 struct glyph_row
*row
13174 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
13175 ptrdiff_t delta
, delta_bytes
;
13177 /* We used to distinguish between two cases here,
13178 conditioned by Z - CHARPOS (tlendpos) == ZV, for
13179 when the line ends in a newline or the end of the
13180 buffer's accessible portion. But both cases did
13181 the same, so they were collapsed. */
13183 - CHARPOS (tlendpos
)
13184 - MATRIX_ROW_START_CHARPOS (row
));
13185 delta_bytes
= (Z_BYTE
13186 - BYTEPOS (tlendpos
)
13187 - MATRIX_ROW_START_BYTEPOS (row
));
13189 increment_matrix_positions (w
->current_matrix
,
13190 this_line_vpos
+ 1,
13191 w
->current_matrix
->nrows
,
13192 delta
, delta_bytes
);
13195 /* If this row displays text now but previously didn't,
13196 or vice versa, w->window_end_vpos may have to be
13198 if ((it
.glyph_row
- 1)->displays_text_p
)
13200 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
13201 wset_window_end_vpos (w
, make_number (this_line_vpos
));
13203 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
13204 && this_line_vpos
> 0)
13205 wset_window_end_vpos (w
, make_number (this_line_vpos
- 1));
13206 w
->window_end_valid
= 0;
13208 /* Update hint: No need to try to scroll in update_window. */
13209 w
->desired_matrix
->no_scrolling_p
= 1;
13212 *w
->desired_matrix
->method
= 0;
13213 debug_method_add (w
, "optimization 1");
13216 //debug optimization movement issue
13217 //w->desired_matrix->no_scrolling_p = 1;
13218 //*w->desired_matrix->method = 0;
13219 //debug_method_add (w, "optimization 1");
13222 #ifdef HAVE_WINDOW_SYSTEM
13223 update_window_fringes (w
, 0);
13230 else if (/* Cursor position hasn't changed. */
13231 PT
== w
->last_point
13232 /* Make sure the cursor was last displayed
13233 in this window. Otherwise we have to reposition it. */
13234 && 0 <= w
->cursor
.vpos
13235 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
13239 do_pending_window_change (1);
13240 /* If selected_window changed, redisplay again. */
13241 if (WINDOWP (selected_window
)
13242 && (w
= XWINDOW (selected_window
)) != sw
)
13245 /* We used to always goto end_of_redisplay here, but this
13246 isn't enough if we have a blinking cursor. */
13247 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
13248 goto end_of_redisplay
;
13252 /* If highlighting the region, or if the cursor is in the echo area,
13253 then we can't just move the cursor. */
13254 else if (! (!NILP (Vtransient_mark_mode
)
13255 && !NILP (BVAR (current_buffer
, mark_active
)))
13256 && (EQ (selected_window
,
13257 BVAR (current_buffer
, last_selected_window
))
13258 || highlight_nonselected_windows
)
13259 && !w
->region_showing
13260 && NILP (Vshow_trailing_whitespace
)
13261 && !cursor_in_echo_area
)
13264 struct glyph_row
*row
;
13266 /* Skip from tlbufpos to PT and see where it is. Note that
13267 PT may be in invisible text. If so, we will end at the
13268 next visible position. */
13269 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
13270 NULL
, DEFAULT_FACE_ID
);
13271 it
.current_x
= this_line_start_x
;
13272 it
.current_y
= this_line_y
;
13273 it
.vpos
= this_line_vpos
;
13275 /* The call to move_it_to stops in front of PT, but
13276 moves over before-strings. */
13277 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
13279 if (it
.vpos
== this_line_vpos
13280 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
13283 eassert (this_line_vpos
== it
.vpos
);
13284 eassert (this_line_y
== it
.current_y
);
13285 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13287 *w
->desired_matrix
->method
= 0;
13288 debug_method_add (w
, "optimization 3");
13297 /* Text changed drastically or point moved off of line. */
13298 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
13301 CHARPOS (this_line_start_pos
) = 0;
13302 consider_all_windows_p
|= buffer_shared_and_changed ();
13303 ++clear_face_cache_count
;
13304 #ifdef HAVE_WINDOW_SYSTEM
13305 ++clear_image_cache_count
;
13308 /* Build desired matrices, and update the display. If
13309 consider_all_windows_p is non-zero, do it for all windows on all
13310 frames. Otherwise do it for selected_window, only. */
13312 if (consider_all_windows_p
)
13314 FOR_EACH_FRAME (tail
, frame
)
13315 XFRAME (frame
)->updated_p
= 0;
13317 FOR_EACH_FRAME (tail
, frame
)
13319 struct frame
*f
= XFRAME (frame
);
13321 /* We don't have to do anything for unselected terminal
13323 if ((FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
13324 && !EQ (FRAME_TTY (f
)->top_frame
, frame
))
13327 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
13329 /* Mark all the scroll bars to be removed; we'll redeem
13330 the ones we want when we redisplay their windows. */
13331 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
13332 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
13334 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13335 redisplay_windows (FRAME_ROOT_WINDOW (f
));
13337 /* The X error handler may have deleted that frame. */
13338 if (!FRAME_LIVE_P (f
))
13341 /* Any scroll bars which redisplay_windows should have
13342 nuked should now go away. */
13343 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
13344 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
13346 /* If fonts changed, display again. */
13347 /* ??? rms: I suspect it is a mistake to jump all the way
13348 back to retry here. It should just retry this frame. */
13349 if (fonts_changed_p
)
13352 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13354 /* See if we have to hscroll. */
13355 if (!f
->already_hscrolled_p
)
13357 f
->already_hscrolled_p
= 1;
13358 if (hscroll_windows (f
->root_window
))
13362 /* Prevent various kinds of signals during display
13363 update. stdio is not robust about handling
13364 signals, which can cause an apparent I/O
13366 if (interrupt_input
)
13367 unrequest_sigio ();
13370 /* Update the display. */
13371 set_window_update_flags (XWINDOW (f
->root_window
), 1);
13372 pending
|= update_frame (f
, 0, 0);
13378 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
13382 /* Do the mark_window_display_accurate after all windows have
13383 been redisplayed because this call resets flags in buffers
13384 which are needed for proper redisplay. */
13385 FOR_EACH_FRAME (tail
, frame
)
13387 struct frame
*f
= XFRAME (frame
);
13390 mark_window_display_accurate (f
->root_window
, 1);
13391 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
13392 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
13397 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13399 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13400 struct frame
*mini_frame
;
13402 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
13403 /* Use list_of_error, not Qerror, so that
13404 we catch only errors and don't run the debugger. */
13405 internal_condition_case_1 (redisplay_window_1
, selected_window
,
13407 redisplay_window_error
);
13408 if (update_miniwindow_p
)
13409 internal_condition_case_1 (redisplay_window_1
, mini_window
,
13411 redisplay_window_error
);
13413 /* Compare desired and current matrices, perform output. */
13416 /* If fonts changed, display again. */
13417 if (fonts_changed_p
)
13420 /* Prevent various kinds of signals during display update.
13421 stdio is not robust about handling signals,
13422 which can cause an apparent I/O error. */
13423 if (interrupt_input
)
13424 unrequest_sigio ();
13427 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13429 if (hscroll_windows (selected_window
))
13432 XWINDOW (selected_window
)->must_be_updated_p
= 1;
13433 pending
= update_frame (sf
, 0, 0);
13436 /* We may have called echo_area_display at the top of this
13437 function. If the echo area is on another frame, that may
13438 have put text on a frame other than the selected one, so the
13439 above call to update_frame would not have caught it. Catch
13441 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13442 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
13444 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
13446 XWINDOW (mini_window
)->must_be_updated_p
= 1;
13447 pending
|= update_frame (mini_frame
, 0, 0);
13448 if (!pending
&& hscroll_windows (mini_window
))
13453 /* If display was paused because of pending input, make sure we do a
13454 thorough update the next time. */
13457 /* Prevent the optimization at the beginning of
13458 redisplay_internal that tries a single-line update of the
13459 line containing the cursor in the selected window. */
13460 CHARPOS (this_line_start_pos
) = 0;
13462 /* Let the overlay arrow be updated the next time. */
13463 update_overlay_arrows (0);
13465 /* If we pause after scrolling, some rows in the current
13466 matrices of some windows are not valid. */
13467 if (!WINDOW_FULL_WIDTH_P (w
)
13468 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
13469 update_mode_lines
= 1;
13473 if (!consider_all_windows_p
)
13475 /* This has already been done above if
13476 consider_all_windows_p is set. */
13477 mark_window_display_accurate_1 (w
, 1);
13479 /* Say overlay arrows are up to date. */
13480 update_overlay_arrows (1);
13482 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
13483 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
13486 update_mode_lines
= 0;
13487 windows_or_buffers_changed
= 0;
13488 cursor_type_changed
= 0;
13491 /* Start SIGIO interrupts coming again. Having them off during the
13492 code above makes it less likely one will discard output, but not
13493 impossible, since there might be stuff in the system buffer here.
13494 But it is much hairier to try to do anything about that. */
13495 if (interrupt_input
)
13499 /* If a frame has become visible which was not before, redisplay
13500 again, so that we display it. Expose events for such a frame
13501 (which it gets when becoming visible) don't call the parts of
13502 redisplay constructing glyphs, so simply exposing a frame won't
13503 display anything in this case. So, we have to display these
13504 frames here explicitly. */
13509 FOR_EACH_FRAME (tail
, frame
)
13511 int this_is_visible
= 0;
13513 if (XFRAME (frame
)->visible
)
13514 this_is_visible
= 1;
13516 if (this_is_visible
)
13520 if (new_count
!= number_of_visible_frames
)
13521 windows_or_buffers_changed
++;
13524 /* Change frame size now if a change is pending. */
13525 do_pending_window_change (1);
13527 /* If we just did a pending size change, or have additional
13528 visible frames, or selected_window changed, redisplay again. */
13529 if ((windows_or_buffers_changed
&& !pending
)
13530 || (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
))
13533 /* Clear the face and image caches.
13535 We used to do this only if consider_all_windows_p. But the cache
13536 needs to be cleared if a timer creates images in the current
13537 buffer (e.g. the test case in Bug#6230). */
13539 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
13541 clear_face_cache (0);
13542 clear_face_cache_count
= 0;
13545 #ifdef HAVE_WINDOW_SYSTEM
13546 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
13548 clear_image_caches (Qnil
);
13549 clear_image_cache_count
= 0;
13551 #endif /* HAVE_WINDOW_SYSTEM */
13554 backtrace_list
= backtrace
.next
;
13555 unbind_to (count
, Qnil
);
13560 /* Redisplay, but leave alone any recent echo area message unless
13561 another message has been requested in its place.
13563 This is useful in situations where you need to redisplay but no
13564 user action has occurred, making it inappropriate for the message
13565 area to be cleared. See tracking_off and
13566 wait_reading_process_output for examples of these situations.
13568 FROM_WHERE is an integer saying from where this function was
13569 called. This is useful for debugging. */
13572 redisplay_preserve_echo_area (int from_where
)
13574 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
13576 if (!NILP (echo_area_buffer
[1]))
13578 /* We have a previously displayed message, but no current
13579 message. Redisplay the previous message. */
13580 display_last_displayed_message_p
= 1;
13581 redisplay_internal ();
13582 display_last_displayed_message_p
= 0;
13585 redisplay_internal ();
13587 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
13588 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
13589 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
13593 /* Function registered with record_unwind_protect in redisplay_internal.
13594 Clear redisplaying_p. Also select the previously selected frame. */
13597 unwind_redisplay (Lisp_Object old_frame
)
13599 redisplaying_p
= 0;
13604 /* Mark the display of leaf window W as accurate or inaccurate.
13605 If ACCURATE_P is non-zero mark display of W as accurate. If
13606 ACCURATE_P is zero, arrange for W to be redisplayed the next
13607 time redisplay_internal is called. */
13610 mark_window_display_accurate_1 (struct window
*w
, int accurate_p
)
13612 struct buffer
*b
= XBUFFER (w
->buffer
);
13614 w
->last_modified
= accurate_p
? BUF_MODIFF (b
) : 0;
13615 w
->last_overlay_modified
= accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0;
13616 w
->last_had_star
= BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
);
13620 b
->clip_changed
= 0;
13621 b
->prevent_redisplay_optimizations_p
= 0;
13623 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
13624 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
13625 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
13626 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
13628 w
->current_matrix
->buffer
= b
;
13629 w
->current_matrix
->begv
= BUF_BEGV (b
);
13630 w
->current_matrix
->zv
= BUF_ZV (b
);
13632 w
->last_cursor
= w
->cursor
;
13633 w
->last_cursor_off_p
= w
->cursor_off_p
;
13635 if (w
== XWINDOW (selected_window
))
13636 w
->last_point
= BUF_PT (b
);
13638 w
->last_point
= marker_position (w
->pointm
);
13640 w
->window_end_valid
= 1;
13641 w
->update_mode_line
= 0;
13646 /* Mark the display of windows in the window tree rooted at WINDOW as
13647 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
13648 windows as accurate. If ACCURATE_P is zero, arrange for windows to
13649 be redisplayed the next time redisplay_internal is called. */
13652 mark_window_display_accurate (Lisp_Object window
, int accurate_p
)
13656 for (; !NILP (window
); window
= w
->next
)
13658 w
= XWINDOW (window
);
13659 if (!NILP (w
->vchild
))
13660 mark_window_display_accurate (w
->vchild
, accurate_p
);
13661 else if (!NILP (w
->hchild
))
13662 mark_window_display_accurate (w
->hchild
, accurate_p
);
13663 else if (BUFFERP (w
->buffer
))
13664 mark_window_display_accurate_1 (w
, accurate_p
);
13668 update_overlay_arrows (1);
13670 /* Force a thorough redisplay the next time by setting
13671 last_arrow_position and last_arrow_string to t, which is
13672 unequal to any useful value of Voverlay_arrow_... */
13673 update_overlay_arrows (-1);
13677 /* Return value in display table DP (Lisp_Char_Table *) for character
13678 C. Since a display table doesn't have any parent, we don't have to
13679 follow parent. Do not call this function directly but use the
13680 macro DISP_CHAR_VECTOR. */
13683 disp_char_vector (struct Lisp_Char_Table
*dp
, int c
)
13687 if (ASCII_CHAR_P (c
))
13690 if (SUB_CHAR_TABLE_P (val
))
13691 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
13697 XSETCHAR_TABLE (table
, dp
);
13698 val
= char_table_ref (table
, c
);
13707 /***********************************************************************
13709 ***********************************************************************/
13711 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
13714 redisplay_windows (Lisp_Object window
)
13716 while (!NILP (window
))
13718 struct window
*w
= XWINDOW (window
);
13720 if (!NILP (w
->hchild
))
13721 redisplay_windows (w
->hchild
);
13722 else if (!NILP (w
->vchild
))
13723 redisplay_windows (w
->vchild
);
13724 else if (!NILP (w
->buffer
))
13726 displayed_buffer
= XBUFFER (w
->buffer
);
13727 /* Use list_of_error, not Qerror, so that
13728 we catch only errors and don't run the debugger. */
13729 internal_condition_case_1 (redisplay_window_0
, window
,
13731 redisplay_window_error
);
13739 redisplay_window_error (Lisp_Object ignore
)
13741 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
13746 redisplay_window_0 (Lisp_Object window
)
13748 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
13749 redisplay_window (window
, 0);
13754 redisplay_window_1 (Lisp_Object window
)
13756 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
13757 redisplay_window (window
, 1);
13762 /* Set cursor position of W. PT is assumed to be displayed in ROW.
13763 DELTA and DELTA_BYTES are the numbers of characters and bytes by
13764 which positions recorded in ROW differ from current buffer
13767 Return 0 if cursor is not on this row, 1 otherwise. */
13770 set_cursor_from_row (struct window
*w
, struct glyph_row
*row
,
13771 struct glyph_matrix
*matrix
,
13772 ptrdiff_t delta
, ptrdiff_t delta_bytes
,
13775 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
13776 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
13777 struct glyph
*cursor
= NULL
;
13778 /* The last known character position in row. */
13779 ptrdiff_t last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13781 ptrdiff_t pt_old
= PT
- delta
;
13782 ptrdiff_t pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13783 ptrdiff_t pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
13784 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
13785 /* A glyph beyond the edge of TEXT_AREA which we should never
13787 struct glyph
*glyphs_end
= end
;
13788 /* Non-zero means we've found a match for cursor position, but that
13789 glyph has the avoid_cursor_p flag set. */
13790 int match_with_avoid_cursor
= 0;
13791 /* Non-zero means we've seen at least one glyph that came from a
13793 int string_seen
= 0;
13794 /* Largest and smallest buffer positions seen so far during scan of
13796 ptrdiff_t bpos_max
= pos_before
;
13797 ptrdiff_t bpos_min
= pos_after
;
13798 /* Last buffer position covered by an overlay string with an integer
13799 `cursor' property. */
13800 ptrdiff_t bpos_covered
= 0;
13801 /* Non-zero means the display string on which to display the cursor
13802 comes from a text property, not from an overlay. */
13803 int string_from_text_prop
= 0;
13805 /* Don't even try doing anything if called for a mode-line or
13806 header-line row, since the rest of the code isn't prepared to
13807 deal with such calamities. */
13808 eassert (!row
->mode_line_p
);
13809 if (row
->mode_line_p
)
13812 /* Skip over glyphs not having an object at the start and the end of
13813 the row. These are special glyphs like truncation marks on
13814 terminal frames. */
13815 if (row
->displays_text_p
)
13817 if (!row
->reversed_p
)
13820 && INTEGERP (glyph
->object
)
13821 && glyph
->charpos
< 0)
13823 x
+= glyph
->pixel_width
;
13827 && INTEGERP ((end
- 1)->object
)
13828 /* CHARPOS is zero for blanks and stretch glyphs
13829 inserted by extend_face_to_end_of_line. */
13830 && (end
- 1)->charpos
<= 0)
13832 glyph_before
= glyph
- 1;
13839 /* If the glyph row is reversed, we need to process it from back
13840 to front, so swap the edge pointers. */
13841 glyphs_end
= end
= glyph
- 1;
13842 glyph
+= row
->used
[TEXT_AREA
] - 1;
13844 while (glyph
> end
+ 1
13845 && INTEGERP (glyph
->object
)
13846 && glyph
->charpos
< 0)
13849 x
-= glyph
->pixel_width
;
13851 if (INTEGERP (glyph
->object
) && glyph
->charpos
< 0)
13853 /* By default, in reversed rows we put the cursor on the
13854 rightmost (first in the reading order) glyph. */
13855 for (g
= end
+ 1; g
< glyph
; g
++)
13856 x
+= g
->pixel_width
;
13858 && INTEGERP ((end
+ 1)->object
)
13859 && (end
+ 1)->charpos
<= 0)
13861 glyph_before
= glyph
+ 1;
13865 else if (row
->reversed_p
)
13867 /* In R2L rows that don't display text, put the cursor on the
13868 rightmost glyph. Case in point: an empty last line that is
13869 part of an R2L paragraph. */
13871 /* Avoid placing the cursor on the last glyph of the row, where
13872 on terminal frames we hold the vertical border between
13873 adjacent windows. */
13874 if (!FRAME_WINDOW_P (WINDOW_XFRAME (w
))
13875 && !WINDOW_RIGHTMOST_P (w
)
13876 && cursor
== row
->glyphs
[LAST_AREA
] - 1)
13878 x
= -1; /* will be computed below, at label compute_x */
13881 /* Step 1: Try to find the glyph whose character position
13882 corresponds to point. If that's not possible, find 2 glyphs
13883 whose character positions are the closest to point, one before
13884 point, the other after it. */
13885 if (!row
->reversed_p
)
13886 while (/* not marched to end of glyph row */
13888 /* glyph was not inserted by redisplay for internal purposes */
13889 && !INTEGERP (glyph
->object
))
13891 if (BUFFERP (glyph
->object
))
13893 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
13895 if (glyph
->charpos
> bpos_max
)
13896 bpos_max
= glyph
->charpos
;
13897 if (glyph
->charpos
< bpos_min
)
13898 bpos_min
= glyph
->charpos
;
13899 if (!glyph
->avoid_cursor_p
)
13901 /* If we hit point, we've found the glyph on which to
13902 display the cursor. */
13905 match_with_avoid_cursor
= 0;
13908 /* See if we've found a better approximation to
13909 POS_BEFORE or to POS_AFTER. */
13910 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
13912 pos_before
= glyph
->charpos
;
13913 glyph_before
= glyph
;
13915 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
13917 pos_after
= glyph
->charpos
;
13918 glyph_after
= glyph
;
13921 else if (dpos
== 0)
13922 match_with_avoid_cursor
= 1;
13924 else if (STRINGP (glyph
->object
))
13926 Lisp_Object chprop
;
13927 ptrdiff_t glyph_pos
= glyph
->charpos
;
13929 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
13931 if (!NILP (chprop
))
13933 /* If the string came from a `display' text property,
13934 look up the buffer position of that property and
13935 use that position to update bpos_max, as if we
13936 actually saw such a position in one of the row's
13937 glyphs. This helps with supporting integer values
13938 of `cursor' property on the display string in
13939 situations where most or all of the row's buffer
13940 text is completely covered by display properties,
13941 so that no glyph with valid buffer positions is
13942 ever seen in the row. */
13943 ptrdiff_t prop_pos
=
13944 string_buffer_position_lim (glyph
->object
, pos_before
,
13947 if (prop_pos
>= pos_before
)
13948 bpos_max
= prop_pos
- 1;
13950 if (INTEGERP (chprop
))
13952 bpos_covered
= bpos_max
+ XINT (chprop
);
13953 /* If the `cursor' property covers buffer positions up
13954 to and including point, we should display cursor on
13955 this glyph. Note that, if a `cursor' property on one
13956 of the string's characters has an integer value, we
13957 will break out of the loop below _before_ we get to
13958 the position match above. IOW, integer values of
13959 the `cursor' property override the "exact match for
13960 point" strategy of positioning the cursor. */
13961 /* Implementation note: bpos_max == pt_old when, e.g.,
13962 we are in an empty line, where bpos_max is set to
13963 MATRIX_ROW_START_CHARPOS, see above. */
13964 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
13973 x
+= glyph
->pixel_width
;
13976 else if (glyph
> end
) /* row is reversed */
13977 while (!INTEGERP (glyph
->object
))
13979 if (BUFFERP (glyph
->object
))
13981 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
13983 if (glyph
->charpos
> bpos_max
)
13984 bpos_max
= glyph
->charpos
;
13985 if (glyph
->charpos
< bpos_min
)
13986 bpos_min
= glyph
->charpos
;
13987 if (!glyph
->avoid_cursor_p
)
13991 match_with_avoid_cursor
= 0;
13994 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
13996 pos_before
= glyph
->charpos
;
13997 glyph_before
= glyph
;
13999 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
14001 pos_after
= glyph
->charpos
;
14002 glyph_after
= glyph
;
14005 else if (dpos
== 0)
14006 match_with_avoid_cursor
= 1;
14008 else if (STRINGP (glyph
->object
))
14010 Lisp_Object chprop
;
14011 ptrdiff_t glyph_pos
= glyph
->charpos
;
14013 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
14015 if (!NILP (chprop
))
14017 ptrdiff_t prop_pos
=
14018 string_buffer_position_lim (glyph
->object
, pos_before
,
14021 if (prop_pos
>= pos_before
)
14022 bpos_max
= prop_pos
- 1;
14024 if (INTEGERP (chprop
))
14026 bpos_covered
= bpos_max
+ XINT (chprop
);
14027 /* If the `cursor' property covers buffer positions up
14028 to and including point, we should display cursor on
14030 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14039 if (glyph
== glyphs_end
) /* don't dereference outside TEXT_AREA */
14041 x
--; /* can't use any pixel_width */
14044 x
-= glyph
->pixel_width
;
14047 /* Step 2: If we didn't find an exact match for point, we need to
14048 look for a proper place to put the cursor among glyphs between
14049 GLYPH_BEFORE and GLYPH_AFTER. */
14050 if (!((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14051 && BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14052 && !(bpos_max
< pt_old
&& pt_old
<= bpos_covered
))
14054 /* An empty line has a single glyph whose OBJECT is zero and
14055 whose CHARPOS is the position of a newline on that line.
14056 Note that on a TTY, there are more glyphs after that, which
14057 were produced by extend_face_to_end_of_line, but their
14058 CHARPOS is zero or negative. */
14060 (row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14061 && INTEGERP (glyph
->object
) && glyph
->charpos
> 0
14062 /* On a TTY, continued and truncated rows also have a glyph at
14063 their end whose OBJECT is zero and whose CHARPOS is
14064 positive (the continuation and truncation glyphs), but such
14065 rows are obviously not "empty". */
14066 && !(row
->continued_p
|| row
->truncated_on_right_p
);
14068 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
14070 ptrdiff_t ellipsis_pos
;
14072 /* Scan back over the ellipsis glyphs. */
14073 if (!row
->reversed_p
)
14075 ellipsis_pos
= (glyph
- 1)->charpos
;
14076 while (glyph
> row
->glyphs
[TEXT_AREA
]
14077 && (glyph
- 1)->charpos
== ellipsis_pos
)
14078 glyph
--, x
-= glyph
->pixel_width
;
14079 /* That loop always goes one position too far, including
14080 the glyph before the ellipsis. So scan forward over
14082 x
+= glyph
->pixel_width
;
14085 else /* row is reversed */
14087 ellipsis_pos
= (glyph
+ 1)->charpos
;
14088 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14089 && (glyph
+ 1)->charpos
== ellipsis_pos
)
14090 glyph
++, x
+= glyph
->pixel_width
;
14091 x
-= glyph
->pixel_width
;
14095 else if (match_with_avoid_cursor
)
14097 cursor
= glyph_after
;
14100 else if (string_seen
)
14102 int incr
= row
->reversed_p
? -1 : +1;
14104 /* Need to find the glyph that came out of a string which is
14105 present at point. That glyph is somewhere between
14106 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
14107 positioned between POS_BEFORE and POS_AFTER in the
14109 struct glyph
*start
, *stop
;
14110 ptrdiff_t pos
= pos_before
;
14114 /* If the row ends in a newline from a display string,
14115 reordering could have moved the glyphs belonging to the
14116 string out of the [GLYPH_BEFORE..GLYPH_AFTER] range. So
14117 in this case we extend the search to the last glyph in
14118 the row that was not inserted by redisplay. */
14119 if (row
->ends_in_newline_from_string_p
)
14122 pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
14125 /* GLYPH_BEFORE and GLYPH_AFTER are the glyphs that
14126 correspond to POS_BEFORE and POS_AFTER, respectively. We
14127 need START and STOP in the order that corresponds to the
14128 row's direction as given by its reversed_p flag. If the
14129 directionality of characters between POS_BEFORE and
14130 POS_AFTER is the opposite of the row's base direction,
14131 these characters will have been reordered for display,
14132 and we need to reverse START and STOP. */
14133 if (!row
->reversed_p
)
14135 start
= min (glyph_before
, glyph_after
);
14136 stop
= max (glyph_before
, glyph_after
);
14140 start
= max (glyph_before
, glyph_after
);
14141 stop
= min (glyph_before
, glyph_after
);
14143 for (glyph
= start
+ incr
;
14144 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
14147 /* Any glyphs that come from the buffer are here because
14148 of bidi reordering. Skip them, and only pay
14149 attention to glyphs that came from some string. */
14150 if (STRINGP (glyph
->object
))
14154 /* If the display property covers the newline, we
14155 need to search for it one position farther. */
14156 ptrdiff_t lim
= pos_after
14157 + (pos_after
== MATRIX_ROW_END_CHARPOS (row
) + delta
);
14159 string_from_text_prop
= 0;
14160 str
= glyph
->object
;
14161 tem
= string_buffer_position_lim (str
, pos
, lim
, 0);
14162 if (tem
== 0 /* from overlay */
14165 /* If the string from which this glyph came is
14166 found in the buffer at point, or at position
14167 that is closer to point than pos_after, then
14168 we've found the glyph we've been looking for.
14169 If it comes from an overlay (tem == 0), and
14170 it has the `cursor' property on one of its
14171 glyphs, record that glyph as a candidate for
14172 displaying the cursor. (As in the
14173 unidirectional version, we will display the
14174 cursor on the last candidate we find.) */
14177 || (tem
- pt_old
> 0 && tem
< pos_after
))
14179 /* The glyphs from this string could have
14180 been reordered. Find the one with the
14181 smallest string position. Or there could
14182 be a character in the string with the
14183 `cursor' property, which means display
14184 cursor on that character's glyph. */
14185 ptrdiff_t strpos
= glyph
->charpos
;
14190 string_from_text_prop
= 1;
14193 (row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14194 && EQ (glyph
->object
, str
);
14198 ptrdiff_t gpos
= glyph
->charpos
;
14200 cprop
= Fget_char_property (make_number (gpos
),
14208 if (tem
&& glyph
->charpos
< strpos
)
14210 strpos
= glyph
->charpos
;
14216 || (tem
- pt_old
> 0 && tem
< pos_after
))
14220 pos
= tem
+ 1; /* don't find previous instances */
14222 /* This string is not what we want; skip all of the
14223 glyphs that came from it. */
14224 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14225 && EQ (glyph
->object
, str
))
14232 /* If we reached the end of the line, and END was from a string,
14233 the cursor is not on this line. */
14235 && (row
->reversed_p
? glyph
<= end
: glyph
>= end
)
14236 && (row
->reversed_p
? end
> glyphs_end
: end
< glyphs_end
)
14237 && STRINGP (end
->object
)
14238 && row
->continued_p
)
14241 /* A truncated row may not include PT among its character positions.
14242 Setting the cursor inside the scroll margin will trigger
14243 recalculation of hscroll in hscroll_window_tree. But if a
14244 display string covers point, defer to the string-handling
14245 code below to figure this out. */
14246 else if (row
->truncated_on_left_p
&& pt_old
< bpos_min
)
14248 cursor
= glyph_before
;
14251 else if ((row
->truncated_on_right_p
&& pt_old
> bpos_max
)
14252 /* Zero-width characters produce no glyphs. */
14254 && (row
->reversed_p
14255 ? glyph_after
> glyphs_end
14256 : glyph_after
< glyphs_end
)))
14258 cursor
= glyph_after
;
14264 if (cursor
!= NULL
)
14266 else if (glyph
== glyphs_end
14267 && pos_before
== pos_after
14268 && STRINGP ((row
->reversed_p
14269 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14270 : row
->glyphs
[TEXT_AREA
])->object
))
14272 /* If all the glyphs of this row came from strings, put the
14273 cursor on the first glyph of the row. This avoids having the
14274 cursor outside of the text area in this very rare and hard
14278 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14279 : row
->glyphs
[TEXT_AREA
];
14285 /* Need to compute x that corresponds to GLYPH. */
14286 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
14288 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
14290 x
+= g
->pixel_width
;
14294 /* ROW could be part of a continued line, which, under bidi
14295 reordering, might have other rows whose start and end charpos
14296 occlude point. Only set w->cursor if we found a better
14297 approximation to the cursor position than we have from previously
14298 examined candidate rows belonging to the same continued line. */
14299 if (/* we already have a candidate row */
14300 w
->cursor
.vpos
>= 0
14301 /* that candidate is not the row we are processing */
14302 && MATRIX_ROW (matrix
, w
->cursor
.vpos
) != row
14303 /* Make sure cursor.vpos specifies a row whose start and end
14304 charpos occlude point, and it is valid candidate for being a
14305 cursor-row. This is because some callers of this function
14306 leave cursor.vpos at the row where the cursor was displayed
14307 during the last redisplay cycle. */
14308 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)) <= pt_old
14309 && pt_old
<= MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14310 && cursor_row_p (MATRIX_ROW (matrix
, w
->cursor
.vpos
)))
14313 MATRIX_ROW_GLYPH_START (matrix
, w
->cursor
.vpos
) + w
->cursor
.hpos
;
14315 /* Don't consider glyphs that are outside TEXT_AREA. */
14316 if (!(row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
))
14318 /* Keep the candidate whose buffer position is the closest to
14319 point or has the `cursor' property. */
14320 if (/* previous candidate is a glyph in TEXT_AREA of that row */
14321 w
->cursor
.hpos
>= 0
14322 && w
->cursor
.hpos
< MATRIX_ROW_USED (matrix
, w
->cursor
.vpos
)
14323 && ((BUFFERP (g1
->object
)
14324 && (g1
->charpos
== pt_old
/* an exact match always wins */
14325 || (BUFFERP (glyph
->object
)
14326 && eabs (g1
->charpos
- pt_old
)
14327 < eabs (glyph
->charpos
- pt_old
))))
14328 /* previous candidate is a glyph from a string that has
14329 a non-nil `cursor' property */
14330 || (STRINGP (g1
->object
)
14331 && (!NILP (Fget_char_property (make_number (g1
->charpos
),
14332 Qcursor
, g1
->object
))
14333 /* previous candidate is from the same display
14334 string as this one, and the display string
14335 came from a text property */
14336 || (EQ (g1
->object
, glyph
->object
)
14337 && string_from_text_prop
)
14338 /* this candidate is from newline and its
14339 position is not an exact match */
14340 || (INTEGERP (glyph
->object
)
14341 && glyph
->charpos
!= pt_old
)))))
14343 /* If this candidate gives an exact match, use that. */
14344 if (!((BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14345 /* If this candidate is a glyph created for the
14346 terminating newline of a line, and point is on that
14347 newline, it wins because it's an exact match. */
14348 || (!row
->continued_p
14349 && INTEGERP (glyph
->object
)
14350 && glyph
->charpos
== 0
14351 && pt_old
== MATRIX_ROW_END_CHARPOS (row
) - 1))
14352 /* Otherwise, keep the candidate that comes from a row
14353 spanning less buffer positions. This may win when one or
14354 both candidate positions are on glyphs that came from
14355 display strings, for which we cannot compare buffer
14357 && MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14358 - MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14359 < MATRIX_ROW_END_CHARPOS (row
) - MATRIX_ROW_START_CHARPOS (row
))
14362 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
14364 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
14365 w
->cursor
.y
= row
->y
+ dy
;
14367 if (w
== XWINDOW (selected_window
))
14369 if (!row
->continued_p
14370 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
14373 this_line_buffer
= XBUFFER (w
->buffer
);
14375 CHARPOS (this_line_start_pos
)
14376 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
14377 BYTEPOS (this_line_start_pos
)
14378 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
14380 CHARPOS (this_line_end_pos
)
14381 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
14382 BYTEPOS (this_line_end_pos
)
14383 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
14385 this_line_y
= w
->cursor
.y
;
14386 this_line_pixel_height
= row
->height
;
14387 this_line_vpos
= w
->cursor
.vpos
;
14388 this_line_start_x
= row
->x
;
14391 CHARPOS (this_line_start_pos
) = 0;
14398 /* Run window scroll functions, if any, for WINDOW with new window
14399 start STARTP. Sets the window start of WINDOW to that position.
14401 We assume that the window's buffer is really current. */
14403 static struct text_pos
14404 run_window_scroll_functions (Lisp_Object window
, struct text_pos startp
)
14406 struct window
*w
= XWINDOW (window
);
14407 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
14409 if (current_buffer
!= XBUFFER (w
->buffer
))
14412 if (!NILP (Vwindow_scroll_functions
))
14414 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
14415 make_number (CHARPOS (startp
)));
14416 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14417 /* In case the hook functions switch buffers. */
14418 set_buffer_internal (XBUFFER (w
->buffer
));
14425 /* Make sure the line containing the cursor is fully visible.
14426 A value of 1 means there is nothing to be done.
14427 (Either the line is fully visible, or it cannot be made so,
14428 or we cannot tell.)
14430 If FORCE_P is non-zero, return 0 even if partial visible cursor row
14431 is higher than window.
14433 A value of 0 means the caller should do scrolling
14434 as if point had gone off the screen. */
14437 cursor_row_fully_visible_p (struct window
*w
, int force_p
, int current_matrix_p
)
14439 struct glyph_matrix
*matrix
;
14440 struct glyph_row
*row
;
14443 if (!make_cursor_line_fully_visible_p
)
14446 /* It's not always possible to find the cursor, e.g, when a window
14447 is full of overlay strings. Don't do anything in that case. */
14448 if (w
->cursor
.vpos
< 0)
14451 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
14452 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
14454 /* If the cursor row is not partially visible, there's nothing to do. */
14455 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
14458 /* If the row the cursor is in is taller than the window's height,
14459 it's not clear what to do, so do nothing. */
14460 window_height
= window_box_height (w
);
14461 if (row
->height
>= window_height
)
14463 if (!force_p
|| MINI_WINDOW_P (w
)
14464 || w
->vscroll
|| w
->cursor
.vpos
== 0)
14471 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
14472 non-zero means only WINDOW is redisplayed in redisplay_internal.
14473 TEMP_SCROLL_STEP has the same meaning as emacs_scroll_step, and is used
14474 in redisplay_window to bring a partially visible line into view in
14475 the case that only the cursor has moved.
14477 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
14478 last screen line's vertical height extends past the end of the screen.
14482 1 if scrolling succeeded
14484 0 if scrolling didn't find point.
14486 -1 if new fonts have been loaded so that we must interrupt
14487 redisplay, adjust glyph matrices, and try again. */
14493 SCROLLING_NEED_LARGER_MATRICES
14496 /* If scroll-conservatively is more than this, never recenter.
14498 If you change this, don't forget to update the doc string of
14499 `scroll-conservatively' and the Emacs manual. */
14500 #define SCROLL_LIMIT 100
14503 try_scrolling (Lisp_Object window
, int just_this_one_p
,
14504 ptrdiff_t arg_scroll_conservatively
, ptrdiff_t scroll_step
,
14505 int temp_scroll_step
, int last_line_misfit
)
14507 struct window
*w
= XWINDOW (window
);
14508 struct frame
*f
= XFRAME (w
->frame
);
14509 struct text_pos pos
, startp
;
14511 int this_scroll_margin
, scroll_max
, rc
, height
;
14512 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
14513 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
14514 Lisp_Object aggressive
;
14515 /* We will never try scrolling more than this number of lines. */
14516 int scroll_limit
= SCROLL_LIMIT
;
14519 debug_method_add (w
, "try_scrolling");
14522 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14524 /* Compute scroll margin height in pixels. We scroll when point is
14525 within this distance from the top or bottom of the window. */
14526 if (scroll_margin
> 0)
14527 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
14528 * FRAME_LINE_HEIGHT (f
);
14530 this_scroll_margin
= 0;
14532 /* Force arg_scroll_conservatively to have a reasonable value, to
14533 avoid scrolling too far away with slow move_it_* functions. Note
14534 that the user can supply scroll-conservatively equal to
14535 `most-positive-fixnum', which can be larger than INT_MAX. */
14536 if (arg_scroll_conservatively
> scroll_limit
)
14538 arg_scroll_conservatively
= scroll_limit
+ 1;
14539 scroll_max
= scroll_limit
* FRAME_LINE_HEIGHT (f
);
14541 else if (scroll_step
|| arg_scroll_conservatively
|| temp_scroll_step
)
14542 /* Compute how much we should try to scroll maximally to bring
14543 point into view. */
14544 scroll_max
= (max (scroll_step
,
14545 max (arg_scroll_conservatively
, temp_scroll_step
))
14546 * FRAME_LINE_HEIGHT (f
));
14547 else if (NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
))
14548 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
)))
14549 /* We're trying to scroll because of aggressive scrolling but no
14550 scroll_step is set. Choose an arbitrary one. */
14551 scroll_max
= 10 * FRAME_LINE_HEIGHT (f
);
14557 /* Decide whether to scroll down. */
14558 if (PT
> CHARPOS (startp
))
14560 int scroll_margin_y
;
14562 /* Compute the pixel ypos of the scroll margin, then move IT to
14563 either that ypos or PT, whichever comes first. */
14564 start_display (&it
, w
, startp
);
14565 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
14566 - FRAME_LINE_HEIGHT (f
) * extra_scroll_margin_lines
;
14567 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
14568 (MOVE_TO_POS
| MOVE_TO_Y
));
14570 if (PT
> CHARPOS (it
.current
.pos
))
14572 int y0
= line_bottom_y (&it
);
14573 /* Compute how many pixels below window bottom to stop searching
14574 for PT. This avoids costly search for PT that is far away if
14575 the user limited scrolling by a small number of lines, but
14576 always finds PT if scroll_conservatively is set to a large
14577 number, such as most-positive-fixnum. */
14578 int slack
= max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
));
14579 int y_to_move
= it
.last_visible_y
+ slack
;
14581 /* Compute the distance from the scroll margin to PT or to
14582 the scroll limit, whichever comes first. This should
14583 include the height of the cursor line, to make that line
14585 move_it_to (&it
, PT
, -1, y_to_move
,
14586 -1, MOVE_TO_POS
| MOVE_TO_Y
);
14587 dy
= line_bottom_y (&it
) - y0
;
14589 if (dy
> scroll_max
)
14590 return SCROLLING_FAILED
;
14599 /* Point is in or below the bottom scroll margin, so move the
14600 window start down. If scrolling conservatively, move it just
14601 enough down to make point visible. If scroll_step is set,
14602 move it down by scroll_step. */
14603 if (arg_scroll_conservatively
)
14605 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
14606 FRAME_LINE_HEIGHT (f
) * arg_scroll_conservatively
);
14607 else if (scroll_step
|| temp_scroll_step
)
14608 amount_to_scroll
= scroll_max
;
14611 aggressive
= BVAR (current_buffer
, scroll_up_aggressively
);
14612 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14613 if (NUMBERP (aggressive
))
14615 double float_amount
= XFLOATINT (aggressive
) * height
;
14616 int aggressive_scroll
= float_amount
;
14617 if (aggressive_scroll
== 0 && float_amount
> 0)
14618 aggressive_scroll
= 1;
14619 /* Don't let point enter the scroll margin near top of
14620 the window. This could happen if the value of
14621 scroll_up_aggressively is too large and there are
14622 non-zero margins, because scroll_up_aggressively
14623 means put point that fraction of window height
14624 _from_the_bottom_margin_. */
14625 if (aggressive_scroll
+ 2*this_scroll_margin
> height
)
14626 aggressive_scroll
= height
- 2*this_scroll_margin
;
14627 amount_to_scroll
= dy
+ aggressive_scroll
;
14631 if (amount_to_scroll
<= 0)
14632 return SCROLLING_FAILED
;
14634 start_display (&it
, w
, startp
);
14635 if (arg_scroll_conservatively
<= scroll_limit
)
14636 move_it_vertically (&it
, amount_to_scroll
);
14639 /* Extra precision for users who set scroll-conservatively
14640 to a large number: make sure the amount we scroll
14641 the window start is never less than amount_to_scroll,
14642 which was computed as distance from window bottom to
14643 point. This matters when lines at window top and lines
14644 below window bottom have different height. */
14646 void *it1data
= NULL
;
14647 /* We use a temporary it1 because line_bottom_y can modify
14648 its argument, if it moves one line down; see there. */
14651 SAVE_IT (it1
, it
, it1data
);
14652 start_y
= line_bottom_y (&it1
);
14654 RESTORE_IT (&it
, &it
, it1data
);
14655 move_it_by_lines (&it
, 1);
14656 SAVE_IT (it1
, it
, it1data
);
14657 } while (line_bottom_y (&it1
) - start_y
< amount_to_scroll
);
14660 /* If STARTP is unchanged, move it down another screen line. */
14661 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
14662 move_it_by_lines (&it
, 1);
14663 startp
= it
.current
.pos
;
14667 struct text_pos scroll_margin_pos
= startp
;
14670 /* See if point is inside the scroll margin at the top of the
14672 if (this_scroll_margin
)
14676 start_display (&it
, w
, startp
);
14677 y_start
= it
.current_y
;
14678 move_it_vertically (&it
, this_scroll_margin
);
14679 scroll_margin_pos
= it
.current
.pos
;
14680 /* If we didn't move enough before hitting ZV, request
14681 additional amount of scroll, to move point out of the
14683 if (IT_CHARPOS (it
) == ZV
14684 && it
.current_y
- y_start
< this_scroll_margin
)
14685 y_offset
= this_scroll_margin
- (it
.current_y
- y_start
);
14688 if (PT
< CHARPOS (scroll_margin_pos
))
14690 /* Point is in the scroll margin at the top of the window or
14691 above what is displayed in the window. */
14694 /* Compute the vertical distance from PT to the scroll
14695 margin position. Move as far as scroll_max allows, or
14696 one screenful, or 10 screen lines, whichever is largest.
14697 Give up if distance is greater than scroll_max or if we
14698 didn't reach the scroll margin position. */
14699 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
14700 start_display (&it
, w
, pos
);
14702 y_to_move
= max (it
.last_visible_y
,
14703 max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
)));
14704 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
14706 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
14707 dy
= it
.current_y
- y0
;
14708 if (dy
> scroll_max
14709 || IT_CHARPOS (it
) < CHARPOS (scroll_margin_pos
))
14710 return SCROLLING_FAILED
;
14712 /* Additional scroll for when ZV was too close to point. */
14715 /* Compute new window start. */
14716 start_display (&it
, w
, startp
);
14718 if (arg_scroll_conservatively
)
14719 amount_to_scroll
= max (dy
, FRAME_LINE_HEIGHT (f
) *
14720 max (scroll_step
, temp_scroll_step
));
14721 else if (scroll_step
|| temp_scroll_step
)
14722 amount_to_scroll
= scroll_max
;
14725 aggressive
= BVAR (current_buffer
, scroll_down_aggressively
);
14726 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14727 if (NUMBERP (aggressive
))
14729 double float_amount
= XFLOATINT (aggressive
) * height
;
14730 int aggressive_scroll
= float_amount
;
14731 if (aggressive_scroll
== 0 && float_amount
> 0)
14732 aggressive_scroll
= 1;
14733 /* Don't let point enter the scroll margin near
14734 bottom of the window, if the value of
14735 scroll_down_aggressively happens to be too
14737 if (aggressive_scroll
+ 2*this_scroll_margin
> height
)
14738 aggressive_scroll
= height
- 2*this_scroll_margin
;
14739 amount_to_scroll
= dy
+ aggressive_scroll
;
14743 if (amount_to_scroll
<= 0)
14744 return SCROLLING_FAILED
;
14746 move_it_vertically_backward (&it
, amount_to_scroll
);
14747 startp
= it
.current
.pos
;
14751 /* Run window scroll functions. */
14752 startp
= run_window_scroll_functions (window
, startp
);
14754 /* Display the window. Give up if new fonts are loaded, or if point
14756 if (!try_window (window
, startp
, 0))
14757 rc
= SCROLLING_NEED_LARGER_MATRICES
;
14758 else if (w
->cursor
.vpos
< 0)
14760 clear_glyph_matrix (w
->desired_matrix
);
14761 rc
= SCROLLING_FAILED
;
14765 /* Maybe forget recorded base line for line number display. */
14766 if (!just_this_one_p
14767 || current_buffer
->clip_changed
14768 || BEG_UNCHANGED
< CHARPOS (startp
))
14769 w
->base_line_number
= 0;
14771 /* If cursor ends up on a partially visible line,
14772 treat that as being off the bottom of the screen. */
14773 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0)
14774 /* It's possible that the cursor is on the first line of the
14775 buffer, which is partially obscured due to a vscroll
14776 (Bug#7537). In that case, avoid looping forever . */
14777 && extra_scroll_margin_lines
< w
->desired_matrix
->nrows
- 1)
14779 clear_glyph_matrix (w
->desired_matrix
);
14780 ++extra_scroll_margin_lines
;
14783 rc
= SCROLLING_SUCCESS
;
14790 /* Compute a suitable window start for window W if display of W starts
14791 on a continuation line. Value is non-zero if a new window start
14794 The new window start will be computed, based on W's width, starting
14795 from the start of the continued line. It is the start of the
14796 screen line with the minimum distance from the old start W->start. */
14799 compute_window_start_on_continuation_line (struct window
*w
)
14801 struct text_pos pos
, start_pos
;
14802 int window_start_changed_p
= 0;
14804 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
14806 /* If window start is on a continuation line... Window start may be
14807 < BEGV in case there's invisible text at the start of the
14808 buffer (M-x rmail, for example). */
14809 if (CHARPOS (start_pos
) > BEGV
14810 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
14813 struct glyph_row
*row
;
14815 /* Handle the case that the window start is out of range. */
14816 if (CHARPOS (start_pos
) < BEGV
)
14817 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
14818 else if (CHARPOS (start_pos
) > ZV
)
14819 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
14821 /* Find the start of the continued line. This should be fast
14822 because find_newline is fast (newline cache). */
14823 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
14824 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
14825 row
, DEFAULT_FACE_ID
);
14826 reseat_at_previous_visible_line_start (&it
);
14828 /* If the line start is "too far" away from the window start,
14829 say it takes too much time to compute a new window start. */
14830 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
14831 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
14833 int min_distance
, distance
;
14835 /* Move forward by display lines to find the new window
14836 start. If window width was enlarged, the new start can
14837 be expected to be > the old start. If window width was
14838 decreased, the new window start will be < the old start.
14839 So, we're looking for the display line start with the
14840 minimum distance from the old window start. */
14841 pos
= it
.current
.pos
;
14842 min_distance
= INFINITY
;
14843 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
14844 distance
< min_distance
)
14846 min_distance
= distance
;
14847 pos
= it
.current
.pos
;
14848 move_it_by_lines (&it
, 1);
14851 /* Set the window start there. */
14852 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
14853 window_start_changed_p
= 1;
14857 return window_start_changed_p
;
14861 /* Try cursor movement in case text has not changed in window WINDOW,
14862 with window start STARTP. Value is
14864 CURSOR_MOVEMENT_SUCCESS if successful
14866 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
14868 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
14869 display. *SCROLL_STEP is set to 1, under certain circumstances, if
14870 we want to scroll as if scroll-step were set to 1. See the code.
14872 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
14873 which case we have to abort this redisplay, and adjust matrices
14878 CURSOR_MOVEMENT_SUCCESS
,
14879 CURSOR_MOVEMENT_CANNOT_BE_USED
,
14880 CURSOR_MOVEMENT_MUST_SCROLL
,
14881 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
14885 try_cursor_movement (Lisp_Object window
, struct text_pos startp
, int *scroll_step
)
14887 struct window
*w
= XWINDOW (window
);
14888 struct frame
*f
= XFRAME (w
->frame
);
14889 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
14892 if (inhibit_try_cursor_movement
)
14896 /* Previously, there was a check for Lisp integer in the
14897 if-statement below. Now, this field is converted to
14898 ptrdiff_t, thus zero means invalid position in a buffer. */
14899 eassert (w
->last_point
> 0);
14901 /* Handle case where text has not changed, only point, and it has
14902 not moved off the frame. */
14903 if (/* Point may be in this window. */
14904 PT
>= CHARPOS (startp
)
14905 /* Selective display hasn't changed. */
14906 && !current_buffer
->clip_changed
14907 /* Function force-mode-line-update is used to force a thorough
14908 redisplay. It sets either windows_or_buffers_changed or
14909 update_mode_lines. So don't take a shortcut here for these
14911 && !update_mode_lines
14912 && !windows_or_buffers_changed
14913 && !cursor_type_changed
14914 /* Can't use this case if highlighting a region. When a
14915 region exists, cursor movement has to do more than just
14917 && markpos_of_region () < 0
14918 && !w
->region_showing
14919 && NILP (Vshow_trailing_whitespace
)
14920 /* This code is not used for mini-buffer for the sake of the case
14921 of redisplaying to replace an echo area message; since in
14922 that case the mini-buffer contents per se are usually
14923 unchanged. This code is of no real use in the mini-buffer
14924 since the handling of this_line_start_pos, etc., in redisplay
14925 handles the same cases. */
14926 && !EQ (window
, minibuf_window
)
14927 /* When splitting windows or for new windows, it happens that
14928 redisplay is called with a nil window_end_vpos or one being
14929 larger than the window. This should really be fixed in
14930 window.c. I don't have this on my list, now, so we do
14931 approximately the same as the old redisplay code. --gerd. */
14932 && INTEGERP (w
->window_end_vpos
)
14933 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
14934 && (FRAME_WINDOW_P (f
)
14935 || !overlay_arrow_in_current_buffer_p ()))
14937 int this_scroll_margin
, top_scroll_margin
;
14938 struct glyph_row
*row
= NULL
;
14941 debug_method_add (w
, "cursor movement");
14944 /* Scroll if point within this distance from the top or bottom
14945 of the window. This is a pixel value. */
14946 if (scroll_margin
> 0)
14948 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14949 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
14952 this_scroll_margin
= 0;
14954 top_scroll_margin
= this_scroll_margin
;
14955 if (WINDOW_WANTS_HEADER_LINE_P (w
))
14956 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
14958 /* Start with the row the cursor was displayed during the last
14959 not paused redisplay. Give up if that row is not valid. */
14960 if (w
->last_cursor
.vpos
< 0
14961 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
14962 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14965 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
14966 if (row
->mode_line_p
)
14968 if (!row
->enabled_p
)
14969 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
14972 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
14974 int scroll_p
= 0, must_scroll
= 0;
14975 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
14977 if (PT
> w
->last_point
)
14979 /* Point has moved forward. */
14980 while (MATRIX_ROW_END_CHARPOS (row
) < PT
14981 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
14983 eassert (row
->enabled_p
);
14987 /* If the end position of a row equals the start
14988 position of the next row, and PT is at that position,
14989 we would rather display cursor in the next line. */
14990 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
14991 && MATRIX_ROW_END_CHARPOS (row
) == PT
14992 && row
< w
->current_matrix
->rows
14993 + w
->current_matrix
->nrows
- 1
14994 && MATRIX_ROW_START_CHARPOS (row
+1) == PT
14995 && !cursor_row_p (row
))
14998 /* If within the scroll margin, scroll. Note that
14999 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
15000 the next line would be drawn, and that
15001 this_scroll_margin can be zero. */
15002 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
15003 || PT
> MATRIX_ROW_END_CHARPOS (row
)
15004 /* Line is completely visible last line in window
15005 and PT is to be set in the next line. */
15006 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
15007 && PT
== MATRIX_ROW_END_CHARPOS (row
)
15008 && !row
->ends_at_zv_p
15009 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
15012 else if (PT
< w
->last_point
)
15014 /* Cursor has to be moved backward. Note that PT >=
15015 CHARPOS (startp) because of the outer if-statement. */
15016 while (!row
->mode_line_p
15017 && (MATRIX_ROW_START_CHARPOS (row
) > PT
15018 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15019 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
15020 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
15021 row
> w
->current_matrix
->rows
15022 && (row
-1)->ends_in_newline_from_string_p
))))
15023 && (row
->y
> top_scroll_margin
15024 || CHARPOS (startp
) == BEGV
))
15026 eassert (row
->enabled_p
);
15030 /* Consider the following case: Window starts at BEGV,
15031 there is invisible, intangible text at BEGV, so that
15032 display starts at some point START > BEGV. It can
15033 happen that we are called with PT somewhere between
15034 BEGV and START. Try to handle that case. */
15035 if (row
< w
->current_matrix
->rows
15036 || row
->mode_line_p
)
15038 row
= w
->current_matrix
->rows
;
15039 if (row
->mode_line_p
)
15043 /* Due to newlines in overlay strings, we may have to
15044 skip forward over overlay strings. */
15045 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15046 && MATRIX_ROW_END_CHARPOS (row
) == PT
15047 && !cursor_row_p (row
))
15050 /* If within the scroll margin, scroll. */
15051 if (row
->y
< top_scroll_margin
15052 && CHARPOS (startp
) != BEGV
)
15057 /* Cursor did not move. So don't scroll even if cursor line
15058 is partially visible, as it was so before. */
15059 rc
= CURSOR_MOVEMENT_SUCCESS
;
15062 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
15063 || PT
> MATRIX_ROW_END_CHARPOS (row
))
15065 /* if PT is not in the glyph row, give up. */
15066 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15069 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15070 && !NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
15072 struct glyph_row
*row1
;
15074 /* If rows are bidi-reordered and point moved, back up
15075 until we find a row that does not belong to a
15076 continuation line. This is because we must consider
15077 all rows of a continued line as candidates for the
15078 new cursor positioning, since row start and end
15079 positions change non-linearly with vertical position
15081 /* FIXME: Revisit this when glyph ``spilling'' in
15082 continuation lines' rows is implemented for
15083 bidi-reordered rows. */
15084 for (row1
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15085 MATRIX_ROW_CONTINUATION_LINE_P (row
);
15088 /* If we hit the beginning of the displayed portion
15089 without finding the first row of a continued
15093 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15096 eassert (row
->enabled_p
);
15101 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15102 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
15103 /* Make sure this isn't a header line by any chance, since
15104 then MATRIX_ROW_PARTIALLY_VISIBLE_P might yield non-zero. */
15105 && !row
->mode_line_p
15106 && make_cursor_line_fully_visible_p
)
15108 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
15109 && !row
->ends_at_zv_p
15110 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15111 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15112 else if (row
->height
> window_box_height (w
))
15114 /* If we end up in a partially visible line, let's
15115 make it fully visible, except when it's taller
15116 than the window, in which case we can't do much
15119 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15123 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15124 if (!cursor_row_fully_visible_p (w
, 0, 1))
15125 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15127 rc
= CURSOR_MOVEMENT_SUCCESS
;
15131 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15132 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15133 && !NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
15135 /* With bidi-reordered rows, there could be more than
15136 one candidate row whose start and end positions
15137 occlude point. We need to let set_cursor_from_row
15138 find the best candidate. */
15139 /* FIXME: Revisit this when glyph ``spilling'' in
15140 continuation lines' rows is implemented for
15141 bidi-reordered rows. */
15146 int at_zv_p
= 0, exact_match_p
= 0;
15148 if (MATRIX_ROW_START_CHARPOS (row
) <= PT
15149 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
15150 && cursor_row_p (row
))
15151 rv
|= set_cursor_from_row (w
, row
, w
->current_matrix
,
15153 /* As soon as we've found the exact match for point,
15154 or the first suitable row whose ends_at_zv_p flag
15155 is set, we are done. */
15157 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
)->ends_at_zv_p
;
15159 && w
->cursor
.hpos
>= 0
15160 && w
->cursor
.hpos
< MATRIX_ROW_USED (w
->current_matrix
,
15163 struct glyph_row
*candidate
=
15164 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
15166 candidate
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
15167 ptrdiff_t endpos
= MATRIX_ROW_END_CHARPOS (candidate
);
15170 (BUFFERP (g
->object
) && g
->charpos
== PT
)
15171 || (INTEGERP (g
->object
)
15172 && (g
->charpos
== PT
15173 || (g
->charpos
== 0 && endpos
- 1 == PT
)));
15175 if (rv
&& (at_zv_p
|| exact_match_p
))
15177 rc
= CURSOR_MOVEMENT_SUCCESS
;
15180 if (MATRIX_ROW_BOTTOM_Y (row
) == last_y
)
15184 while (((MATRIX_ROW_CONTINUATION_LINE_P (row
)
15185 || row
->continued_p
)
15186 && MATRIX_ROW_BOTTOM_Y (row
) <= last_y
)
15187 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15188 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
));
15189 /* If we didn't find any candidate rows, or exited the
15190 loop before all the candidates were examined, signal
15191 to the caller that this method failed. */
15192 if (rc
!= CURSOR_MOVEMENT_SUCCESS
15194 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
15195 && !row
->continued_p
))
15196 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15198 rc
= CURSOR_MOVEMENT_SUCCESS
;
15204 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
15206 rc
= CURSOR_MOVEMENT_SUCCESS
;
15211 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15212 && MATRIX_ROW_START_CHARPOS (row
) == PT
15213 && cursor_row_p (row
));
15221 #if !defined USE_TOOLKIT_SCROLL_BARS || defined USE_GTK
15225 set_vertical_scroll_bar (struct window
*w
)
15227 ptrdiff_t start
, end
, whole
;
15229 /* Calculate the start and end positions for the current window.
15230 At some point, it would be nice to choose between scrollbars
15231 which reflect the whole buffer size, with special markers
15232 indicating narrowing, and scrollbars which reflect only the
15235 Note that mini-buffers sometimes aren't displaying any text. */
15236 if (!MINI_WINDOW_P (w
)
15237 || (w
== XWINDOW (minibuf_window
)
15238 && NILP (echo_area_buffer
[0])))
15240 struct buffer
*buf
= XBUFFER (w
->buffer
);
15241 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
15242 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
15243 /* I don't think this is guaranteed to be right. For the
15244 moment, we'll pretend it is. */
15245 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
15249 if (whole
< (end
- start
))
15250 whole
= end
- start
;
15253 start
= end
= whole
= 0;
15255 /* Indicate what this scroll bar ought to be displaying now. */
15256 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15257 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15258 (w
, end
- start
, whole
, start
);
15262 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
15263 selected_window is redisplayed.
15265 We can return without actually redisplaying the window if
15266 fonts_changed_p. In that case, redisplay_internal will
15270 redisplay_window (Lisp_Object window
, int just_this_one_p
)
15272 struct window
*w
= XWINDOW (window
);
15273 struct frame
*f
= XFRAME (w
->frame
);
15274 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15275 struct buffer
*old
= current_buffer
;
15276 struct text_pos lpoint
, opoint
, startp
;
15277 int update_mode_line
;
15280 /* Record it now because it's overwritten. */
15281 int current_matrix_up_to_date_p
= 0;
15282 int used_current_matrix_p
= 0;
15283 /* This is less strict than current_matrix_up_to_date_p.
15284 It indicates that the buffer contents and narrowing are unchanged. */
15285 int buffer_unchanged_p
= 0;
15286 int temp_scroll_step
= 0;
15287 ptrdiff_t count
= SPECPDL_INDEX ();
15289 int centering_position
= -1;
15290 int last_line_misfit
= 0;
15291 ptrdiff_t beg_unchanged
, end_unchanged
;
15293 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15296 /* W must be a leaf window here. */
15297 eassert (!NILP (w
->buffer
));
15299 *w
->desired_matrix
->method
= 0;
15303 reconsider_clip_changes (w
, buffer
);
15305 /* Has the mode line to be updated? */
15306 update_mode_line
= (w
->update_mode_line
15307 || update_mode_lines
15308 || buffer
->clip_changed
15309 || buffer
->prevent_redisplay_optimizations_p
);
15311 if (MINI_WINDOW_P (w
))
15313 if (w
== XWINDOW (echo_area_window
)
15314 && !NILP (echo_area_buffer
[0]))
15316 if (update_mode_line
)
15317 /* We may have to update a tty frame's menu bar or a
15318 tool-bar. Example `M-x C-h C-h C-g'. */
15319 goto finish_menu_bars
;
15321 /* We've already displayed the echo area glyphs in this window. */
15322 goto finish_scroll_bars
;
15324 else if ((w
!= XWINDOW (minibuf_window
)
15325 || minibuf_level
== 0)
15326 /* When buffer is nonempty, redisplay window normally. */
15327 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
15328 /* Quail displays non-mini buffers in minibuffer window.
15329 In that case, redisplay the window normally. */
15330 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
15332 /* W is a mini-buffer window, but it's not active, so clear
15334 int yb
= window_text_bottom_y (w
);
15335 struct glyph_row
*row
;
15338 for (y
= 0, row
= w
->desired_matrix
->rows
;
15340 y
+= row
->height
, ++row
)
15341 blank_row (w
, row
, y
);
15342 goto finish_scroll_bars
;
15345 clear_glyph_matrix (w
->desired_matrix
);
15348 /* Otherwise set up data on this window; select its buffer and point
15350 /* Really select the buffer, for the sake of buffer-local
15352 set_buffer_internal_1 (XBUFFER (w
->buffer
));
15354 current_matrix_up_to_date_p
15355 = (w
->window_end_valid
15356 && !current_buffer
->clip_changed
15357 && !current_buffer
->prevent_redisplay_optimizations_p
15358 && !window_outdated (w
));
15360 /* Run the window-bottom-change-functions
15361 if it is possible that the text on the screen has changed
15362 (either due to modification of the text, or any other reason). */
15363 if (!current_matrix_up_to_date_p
15364 && !NILP (Vwindow_text_change_functions
))
15366 safe_run_hooks (Qwindow_text_change_functions
);
15370 beg_unchanged
= BEG_UNCHANGED
;
15371 end_unchanged
= END_UNCHANGED
;
15373 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
15375 specbind (Qinhibit_point_motion_hooks
, Qt
);
15378 = (w
->window_end_valid
15379 && !current_buffer
->clip_changed
15380 && !window_outdated (w
));
15382 /* When windows_or_buffers_changed is non-zero, we can't rely on
15383 the window end being valid, so set it to nil there. */
15384 if (windows_or_buffers_changed
)
15386 /* If window starts on a continuation line, maybe adjust the
15387 window start in case the window's width changed. */
15388 if (XMARKER (w
->start
)->buffer
== current_buffer
)
15389 compute_window_start_on_continuation_line (w
);
15391 w
->window_end_valid
= 0;
15394 /* Some sanity checks. */
15395 CHECK_WINDOW_END (w
);
15396 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
15398 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
15401 if (mode_line_update_needed (w
))
15402 update_mode_line
= 1;
15404 /* Point refers normally to the selected window. For any other
15405 window, set up appropriate value. */
15406 if (!EQ (window
, selected_window
))
15408 ptrdiff_t new_pt
= marker_position (w
->pointm
);
15409 ptrdiff_t new_pt_byte
= marker_byte_position (w
->pointm
);
15413 new_pt_byte
= BEGV_BYTE
;
15414 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
15416 else if (new_pt
> (ZV
- 1))
15419 new_pt_byte
= ZV_BYTE
;
15420 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
15423 /* We don't use SET_PT so that the point-motion hooks don't run. */
15424 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
15427 /* If any of the character widths specified in the display table
15428 have changed, invalidate the width run cache. It's true that
15429 this may be a bit late to catch such changes, but the rest of
15430 redisplay goes (non-fatally) haywire when the display table is
15431 changed, so why should we worry about doing any better? */
15432 if (current_buffer
->width_run_cache
)
15434 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
15436 if (! disptab_matches_widthtab
15437 (disptab
, XVECTOR (BVAR (current_buffer
, width_table
))))
15439 invalidate_region_cache (current_buffer
,
15440 current_buffer
->width_run_cache
,
15442 recompute_width_table (current_buffer
, disptab
);
15446 /* If window-start is screwed up, choose a new one. */
15447 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
15450 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15452 /* If someone specified a new starting point but did not insist,
15453 check whether it can be used. */
15454 if (w
->optional_new_start
15455 && CHARPOS (startp
) >= BEGV
15456 && CHARPOS (startp
) <= ZV
)
15458 w
->optional_new_start
= 0;
15459 start_display (&it
, w
, startp
);
15460 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
15461 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15462 if (IT_CHARPOS (it
) == PT
)
15463 w
->force_start
= 1;
15464 /* IT may overshoot PT if text at PT is invisible. */
15465 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
15466 w
->force_start
= 1;
15471 /* Handle case where place to start displaying has been specified,
15472 unless the specified location is outside the accessible range. */
15473 if (w
->force_start
|| w
->frozen_window_start_p
)
15475 /* We set this later on if we have to adjust point. */
15478 w
->force_start
= 0;
15480 w
->window_end_valid
= 0;
15482 /* Forget any recorded base line for line number display. */
15483 if (!buffer_unchanged_p
)
15484 w
->base_line_number
= 0;
15486 /* Redisplay the mode line. Select the buffer properly for that.
15487 Also, run the hook window-scroll-functions
15488 because we have scrolled. */
15489 /* Note, we do this after clearing force_start because
15490 if there's an error, it is better to forget about force_start
15491 than to get into an infinite loop calling the hook functions
15492 and having them get more errors. */
15493 if (!update_mode_line
15494 || ! NILP (Vwindow_scroll_functions
))
15496 update_mode_line
= 1;
15497 w
->update_mode_line
= 1;
15498 startp
= run_window_scroll_functions (window
, startp
);
15501 w
->last_modified
= 0;
15502 w
->last_overlay_modified
= 0;
15503 if (CHARPOS (startp
) < BEGV
)
15504 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
15505 else if (CHARPOS (startp
) > ZV
)
15506 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
15508 /* Redisplay, then check if cursor has been set during the
15509 redisplay. Give up if new fonts were loaded. */
15510 /* We used to issue a CHECK_MARGINS argument to try_window here,
15511 but this causes scrolling to fail when point begins inside
15512 the scroll margin (bug#148) -- cyd */
15513 if (!try_window (window
, startp
, 0))
15515 w
->force_start
= 1;
15516 clear_glyph_matrix (w
->desired_matrix
);
15517 goto need_larger_matrices
;
15520 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
15522 /* If point does not appear, try to move point so it does
15523 appear. The desired matrix has been built above, so we
15524 can use it here. */
15525 new_vpos
= window_box_height (w
) / 2;
15528 if (!cursor_row_fully_visible_p (w
, 0, 0))
15530 /* Point does appear, but on a line partly visible at end of window.
15531 Move it back to a fully-visible line. */
15532 new_vpos
= window_box_height (w
);
15534 else if (w
->cursor
.vpos
>=0)
15536 /* Some people insist on not letting point enter the scroll
15537 margin, even though this part handles windows that didn't
15539 int margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
15540 int pixel_margin
= margin
* FRAME_LINE_HEIGHT (f
);
15541 bool header_line
= WINDOW_WANTS_HEADER_LINE_P (w
);
15543 /* Note: We add an extra FRAME_LINE_HEIGHT, because the loop
15544 below, which finds the row to move point to, advances by
15545 the Y coordinate of the _next_ row, see the definition of
15546 MATRIX_ROW_BOTTOM_Y. */
15547 if (w
->cursor
.vpos
< margin
+ header_line
)
15549 = pixel_margin
+ (header_line
15550 ? CURRENT_HEADER_LINE_HEIGHT (w
)
15551 : 0) + FRAME_LINE_HEIGHT (f
);
15554 int window_height
= window_box_height (w
);
15557 window_height
+= CURRENT_HEADER_LINE_HEIGHT (w
);
15558 if (w
->cursor
.y
>= window_height
- pixel_margin
)
15559 new_vpos
= window_height
- pixel_margin
;
15563 /* If we need to move point for either of the above reasons,
15564 now actually do it. */
15567 struct glyph_row
*row
;
15569 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
15570 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
15573 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
15574 MATRIX_ROW_START_BYTEPOS (row
));
15576 if (w
!= XWINDOW (selected_window
))
15577 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
15578 else if (current_buffer
== old
)
15579 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15581 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
15583 /* If we are highlighting the region, then we just changed
15584 the region, so redisplay to show it. */
15585 if (0 <= markpos_of_region ())
15587 clear_glyph_matrix (w
->desired_matrix
);
15588 if (!try_window (window
, startp
, 0))
15589 goto need_larger_matrices
;
15594 debug_method_add (w
, "forced window start");
15599 /* Handle case where text has not changed, only point, and it has
15600 not moved off the frame, and we are not retrying after hscroll.
15601 (current_matrix_up_to_date_p is nonzero when retrying.) */
15602 if (current_matrix_up_to_date_p
15603 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
15604 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
15608 case CURSOR_MOVEMENT_SUCCESS
:
15609 used_current_matrix_p
= 1;
15612 case CURSOR_MOVEMENT_MUST_SCROLL
:
15613 goto try_to_scroll
;
15619 /* If current starting point was originally the beginning of a line
15620 but no longer is, find a new starting point. */
15621 else if (w
->start_at_line_beg
15622 && !(CHARPOS (startp
) <= BEGV
15623 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
15626 debug_method_add (w
, "recenter 1");
15631 /* Try scrolling with try_window_id. Value is > 0 if update has
15632 been done, it is -1 if we know that the same window start will
15633 not work. It is 0 if unsuccessful for some other reason. */
15634 else if ((tem
= try_window_id (w
)) != 0)
15637 debug_method_add (w
, "try_window_id %d", tem
);
15640 if (fonts_changed_p
)
15641 goto need_larger_matrices
;
15645 /* Otherwise try_window_id has returned -1 which means that we
15646 don't want the alternative below this comment to execute. */
15648 else if (CHARPOS (startp
) >= BEGV
15649 && CHARPOS (startp
) <= ZV
15650 && PT
>= CHARPOS (startp
)
15651 && (CHARPOS (startp
) < ZV
15652 /* Avoid starting at end of buffer. */
15653 || CHARPOS (startp
) == BEGV
15654 || !window_outdated (w
)))
15656 int d1
, d2
, d3
, d4
, d5
, d6
;
15658 /* If first window line is a continuation line, and window start
15659 is inside the modified region, but the first change is before
15660 current window start, we must select a new window start.
15662 However, if this is the result of a down-mouse event (e.g. by
15663 extending the mouse-drag-overlay), we don't want to select a
15664 new window start, since that would change the position under
15665 the mouse, resulting in an unwanted mouse-movement rather
15666 than a simple mouse-click. */
15667 if (!w
->start_at_line_beg
15668 && NILP (do_mouse_tracking
)
15669 && CHARPOS (startp
) > BEGV
15670 && CHARPOS (startp
) > BEG
+ beg_unchanged
15671 && CHARPOS (startp
) <= Z
- end_unchanged
15672 /* Even if w->start_at_line_beg is nil, a new window may
15673 start at a line_beg, since that's how set_buffer_window
15674 sets it. So, we need to check the return value of
15675 compute_window_start_on_continuation_line. (See also
15677 && XMARKER (w
->start
)->buffer
== current_buffer
15678 && compute_window_start_on_continuation_line (w
)
15679 /* It doesn't make sense to force the window start like we
15680 do at label force_start if it is already known that point
15681 will not be visible in the resulting window, because
15682 doing so will move point from its correct position
15683 instead of scrolling the window to bring point into view.
15685 && pos_visible_p (w
, PT
, &d1
, &d2
, &d3
, &d4
, &d5
, &d6
))
15687 w
->force_start
= 1;
15688 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15693 debug_method_add (w
, "same window start");
15696 /* Try to redisplay starting at same place as before.
15697 If point has not moved off frame, accept the results. */
15698 if (!current_matrix_up_to_date_p
15699 /* Don't use try_window_reusing_current_matrix in this case
15700 because a window scroll function can have changed the
15702 || !NILP (Vwindow_scroll_functions
)
15703 || MINI_WINDOW_P (w
)
15704 || !(used_current_matrix_p
15705 = try_window_reusing_current_matrix (w
)))
15707 IF_DEBUG (debug_method_add (w
, "1"));
15708 if (try_window (window
, startp
, TRY_WINDOW_CHECK_MARGINS
) < 0)
15709 /* -1 means we need to scroll.
15710 0 means we need new matrices, but fonts_changed_p
15711 is set in that case, so we will detect it below. */
15712 goto try_to_scroll
;
15715 if (fonts_changed_p
)
15716 goto need_larger_matrices
;
15718 if (w
->cursor
.vpos
>= 0)
15720 if (!just_this_one_p
15721 || current_buffer
->clip_changed
15722 || BEG_UNCHANGED
< CHARPOS (startp
))
15723 /* Forget any recorded base line for line number display. */
15724 w
->base_line_number
= 0;
15726 if (!cursor_row_fully_visible_p (w
, 1, 0))
15728 clear_glyph_matrix (w
->desired_matrix
);
15729 last_line_misfit
= 1;
15731 /* Drop through and scroll. */
15736 clear_glyph_matrix (w
->desired_matrix
);
15741 w
->last_modified
= 0;
15742 w
->last_overlay_modified
= 0;
15744 /* Redisplay the mode line. Select the buffer properly for that. */
15745 if (!update_mode_line
)
15747 update_mode_line
= 1;
15748 w
->update_mode_line
= 1;
15751 /* Try to scroll by specified few lines. */
15752 if ((scroll_conservatively
15753 || emacs_scroll_step
15754 || temp_scroll_step
15755 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
))
15756 || NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
)))
15757 && CHARPOS (startp
) >= BEGV
15758 && CHARPOS (startp
) <= ZV
)
15760 /* The function returns -1 if new fonts were loaded, 1 if
15761 successful, 0 if not successful. */
15762 int ss
= try_scrolling (window
, just_this_one_p
,
15763 scroll_conservatively
,
15765 temp_scroll_step
, last_line_misfit
);
15768 case SCROLLING_SUCCESS
:
15771 case SCROLLING_NEED_LARGER_MATRICES
:
15772 goto need_larger_matrices
;
15774 case SCROLLING_FAILED
:
15782 /* Finally, just choose a place to start which positions point
15783 according to user preferences. */
15788 debug_method_add (w
, "recenter");
15791 /* Forget any previously recorded base line for line number display. */
15792 if (!buffer_unchanged_p
)
15793 w
->base_line_number
= 0;
15795 /* Determine the window start relative to point. */
15796 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
15797 it
.current_y
= it
.last_visible_y
;
15798 if (centering_position
< 0)
15802 ? min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
15804 ptrdiff_t margin_pos
= CHARPOS (startp
);
15805 Lisp_Object aggressive
;
15808 /* If there is a scroll margin at the top of the window, find
15809 its character position. */
15811 /* Cannot call start_display if startp is not in the
15812 accessible region of the buffer. This can happen when we
15813 have just switched to a different buffer and/or changed
15814 its restriction. In that case, startp is initialized to
15815 the character position 1 (BEGV) because we did not yet
15816 have chance to display the buffer even once. */
15817 && BEGV
<= CHARPOS (startp
) && CHARPOS (startp
) <= ZV
)
15820 void *it1data
= NULL
;
15822 SAVE_IT (it1
, it
, it1data
);
15823 start_display (&it1
, w
, startp
);
15824 move_it_vertically (&it1
, margin
* FRAME_LINE_HEIGHT (f
));
15825 margin_pos
= IT_CHARPOS (it1
);
15826 RESTORE_IT (&it
, &it
, it1data
);
15828 scrolling_up
= PT
> margin_pos
;
15831 ? BVAR (current_buffer
, scroll_up_aggressively
)
15832 : BVAR (current_buffer
, scroll_down_aggressively
);
15834 if (!MINI_WINDOW_P (w
)
15835 && (scroll_conservatively
> SCROLL_LIMIT
|| NUMBERP (aggressive
)))
15839 /* Setting scroll-conservatively overrides
15840 scroll-*-aggressively. */
15841 if (!scroll_conservatively
&& NUMBERP (aggressive
))
15843 double float_amount
= XFLOATINT (aggressive
);
15845 pt_offset
= float_amount
* WINDOW_BOX_TEXT_HEIGHT (w
);
15846 if (pt_offset
== 0 && float_amount
> 0)
15848 if (pt_offset
&& margin
> 0)
15851 /* Compute how much to move the window start backward from
15852 point so that point will be displayed where the user
15856 centering_position
= it
.last_visible_y
;
15858 centering_position
-= pt_offset
;
15859 centering_position
-=
15860 FRAME_LINE_HEIGHT (f
) * (1 + margin
+ (last_line_misfit
!= 0))
15861 + WINDOW_HEADER_LINE_HEIGHT (w
);
15862 /* Don't let point enter the scroll margin near top of
15864 if (centering_position
< margin
* FRAME_LINE_HEIGHT (f
))
15865 centering_position
= margin
* FRAME_LINE_HEIGHT (f
);
15868 centering_position
= margin
* FRAME_LINE_HEIGHT (f
) + pt_offset
;
15871 /* Set the window start half the height of the window backward
15873 centering_position
= window_box_height (w
) / 2;
15875 move_it_vertically_backward (&it
, centering_position
);
15877 eassert (IT_CHARPOS (it
) >= BEGV
);
15879 /* The function move_it_vertically_backward may move over more
15880 than the specified y-distance. If it->w is small, e.g. a
15881 mini-buffer window, we may end up in front of the window's
15882 display area. Start displaying at the start of the line
15883 containing PT in this case. */
15884 if (it
.current_y
<= 0)
15886 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
15887 move_it_vertically_backward (&it
, 0);
15891 it
.current_x
= it
.hpos
= 0;
15893 /* Set the window start position here explicitly, to avoid an
15894 infinite loop in case the functions in window-scroll-functions
15896 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
15898 /* Run scroll hooks. */
15899 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
15901 /* Redisplay the window. */
15902 if (!current_matrix_up_to_date_p
15903 || windows_or_buffers_changed
15904 || cursor_type_changed
15905 /* Don't use try_window_reusing_current_matrix in this case
15906 because it can have changed the buffer. */
15907 || !NILP (Vwindow_scroll_functions
)
15908 || !just_this_one_p
15909 || MINI_WINDOW_P (w
)
15910 || !(used_current_matrix_p
15911 = try_window_reusing_current_matrix (w
)))
15912 try_window (window
, startp
, 0);
15914 /* If new fonts have been loaded (due to fontsets), give up. We
15915 have to start a new redisplay since we need to re-adjust glyph
15917 if (fonts_changed_p
)
15918 goto need_larger_matrices
;
15920 /* If cursor did not appear assume that the middle of the window is
15921 in the first line of the window. Do it again with the next line.
15922 (Imagine a window of height 100, displaying two lines of height
15923 60. Moving back 50 from it->last_visible_y will end in the first
15925 if (w
->cursor
.vpos
< 0)
15927 if (w
->window_end_valid
&& PT
>= Z
- XFASTINT (w
->window_end_pos
))
15929 clear_glyph_matrix (w
->desired_matrix
);
15930 move_it_by_lines (&it
, 1);
15931 try_window (window
, it
.current
.pos
, 0);
15933 else if (PT
< IT_CHARPOS (it
))
15935 clear_glyph_matrix (w
->desired_matrix
);
15936 move_it_by_lines (&it
, -1);
15937 try_window (window
, it
.current
.pos
, 0);
15941 /* Not much we can do about it. */
15945 /* Consider the following case: Window starts at BEGV, there is
15946 invisible, intangible text at BEGV, so that display starts at
15947 some point START > BEGV. It can happen that we are called with
15948 PT somewhere between BEGV and START. Try to handle that case. */
15949 if (w
->cursor
.vpos
< 0)
15951 struct glyph_row
*row
= w
->current_matrix
->rows
;
15952 if (row
->mode_line_p
)
15954 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15957 if (!cursor_row_fully_visible_p (w
, 0, 0))
15959 /* If vscroll is enabled, disable it and try again. */
15963 clear_glyph_matrix (w
->desired_matrix
);
15967 /* Users who set scroll-conservatively to a large number want
15968 point just above/below the scroll margin. If we ended up
15969 with point's row partially visible, move the window start to
15970 make that row fully visible and out of the margin. */
15971 if (scroll_conservatively
> SCROLL_LIMIT
)
15975 ? min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
15977 int move_down
= w
->cursor
.vpos
>= WINDOW_TOTAL_LINES (w
) / 2;
15979 move_it_by_lines (&it
, move_down
? margin
+ 1 : -(margin
+ 1));
15980 clear_glyph_matrix (w
->desired_matrix
);
15981 if (1 == try_window (window
, it
.current
.pos
,
15982 TRY_WINDOW_CHECK_MARGINS
))
15986 /* If centering point failed to make the whole line visible,
15987 put point at the top instead. That has to make the whole line
15988 visible, if it can be done. */
15989 if (centering_position
== 0)
15992 clear_glyph_matrix (w
->desired_matrix
);
15993 centering_position
= 0;
15999 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
16000 w
->start_at_line_beg
= (CHARPOS (startp
) == BEGV
16001 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n');
16003 /* Display the mode line, if we must. */
16004 if ((update_mode_line
16005 /* If window not full width, must redo its mode line
16006 if (a) the window to its side is being redone and
16007 (b) we do a frame-based redisplay. This is a consequence
16008 of how inverted lines are drawn in frame-based redisplay. */
16009 || (!just_this_one_p
16010 && !FRAME_WINDOW_P (f
)
16011 && !WINDOW_FULL_WIDTH_P (w
))
16012 /* Line number to display. */
16013 || w
->base_line_pos
> 0
16014 /* Column number is displayed and different from the one displayed. */
16015 || (w
->column_number_displayed
!= -1
16016 && (w
->column_number_displayed
!= current_column ())))
16017 /* This means that the window has a mode line. */
16018 && (WINDOW_WANTS_MODELINE_P (w
)
16019 || WINDOW_WANTS_HEADER_LINE_P (w
)))
16021 display_mode_lines (w
);
16023 /* If mode line height has changed, arrange for a thorough
16024 immediate redisplay using the correct mode line height. */
16025 if (WINDOW_WANTS_MODELINE_P (w
)
16026 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
16028 fonts_changed_p
= 1;
16029 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
16030 = DESIRED_MODE_LINE_HEIGHT (w
);
16033 /* If header line height has changed, arrange for a thorough
16034 immediate redisplay using the correct header line height. */
16035 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16036 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
16038 fonts_changed_p
= 1;
16039 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
16040 = DESIRED_HEADER_LINE_HEIGHT (w
);
16043 if (fonts_changed_p
)
16044 goto need_larger_matrices
;
16047 if (!line_number_displayed
&& w
->base_line_pos
!= -1)
16049 w
->base_line_pos
= 0;
16050 w
->base_line_number
= 0;
16055 /* When we reach a frame's selected window, redo the frame's menu bar. */
16056 if (update_mode_line
16057 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
16059 int redisplay_menu_p
= 0;
16061 if (FRAME_WINDOW_P (f
))
16063 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
16064 || defined (HAVE_NS) || defined (USE_GTK)
16065 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
16067 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16071 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16073 if (redisplay_menu_p
)
16074 display_menu_bar (w
);
16076 #ifdef HAVE_WINDOW_SYSTEM
16077 if (FRAME_WINDOW_P (f
))
16079 #if defined (USE_GTK) || defined (HAVE_NS)
16080 if (FRAME_EXTERNAL_TOOL_BAR (f
))
16081 redisplay_tool_bar (f
);
16083 if (WINDOWP (f
->tool_bar_window
)
16084 && (FRAME_TOOL_BAR_LINES (f
) > 0
16085 || !NILP (Vauto_resize_tool_bars
))
16086 && redisplay_tool_bar (f
))
16087 ignore_mouse_drag_p
= 1;
16093 #ifdef HAVE_WINDOW_SYSTEM
16094 if (FRAME_WINDOW_P (f
)
16095 && update_window_fringes (w
, (just_this_one_p
16096 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
16097 || w
->pseudo_window_p
)))
16101 if (draw_window_fringes (w
, 1))
16102 x_draw_vertical_border (w
);
16106 #endif /* HAVE_WINDOW_SYSTEM */
16108 /* We go to this label, with fonts_changed_p set,
16109 if it is necessary to try again using larger glyph matrices.
16110 We have to redeem the scroll bar even in this case,
16111 because the loop in redisplay_internal expects that. */
16112 need_larger_matrices
:
16114 finish_scroll_bars
:
16116 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
16118 /* Set the thumb's position and size. */
16119 set_vertical_scroll_bar (w
);
16121 /* Note that we actually used the scroll bar attached to this
16122 window, so it shouldn't be deleted at the end of redisplay. */
16123 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
16124 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
16127 /* Restore current_buffer and value of point in it. The window
16128 update may have changed the buffer, so first make sure `opoint'
16129 is still valid (Bug#6177). */
16130 if (CHARPOS (opoint
) < BEGV
)
16131 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
16132 else if (CHARPOS (opoint
) > ZV
)
16133 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
16135 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
16137 set_buffer_internal_1 (old
);
16138 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
16139 shorter. This can be caused by log truncation in *Messages*. */
16140 if (CHARPOS (lpoint
) <= ZV
)
16141 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
16143 unbind_to (count
, Qnil
);
16147 /* Build the complete desired matrix of WINDOW with a window start
16148 buffer position POS.
16150 Value is 1 if successful. It is zero if fonts were loaded during
16151 redisplay which makes re-adjusting glyph matrices necessary, and -1
16152 if point would appear in the scroll margins.
16153 (We check the former only if TRY_WINDOW_IGNORE_FONTS_CHANGE is
16154 unset in FLAGS, and the latter only if TRY_WINDOW_CHECK_MARGINS is
16158 try_window (Lisp_Object window
, struct text_pos pos
, int flags
)
16160 struct window
*w
= XWINDOW (window
);
16162 struct glyph_row
*last_text_row
= NULL
;
16163 struct frame
*f
= XFRAME (w
->frame
);
16165 /* Make POS the new window start. */
16166 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
16168 /* Mark cursor position as unknown. No overlay arrow seen. */
16169 w
->cursor
.vpos
= -1;
16170 overlay_arrow_seen
= 0;
16172 /* Initialize iterator and info to start at POS. */
16173 start_display (&it
, w
, pos
);
16177 /* Display all lines of W. */
16178 while (it
.current_y
< it
.last_visible_y
)
16180 if (display_line (&it
))
16181 last_text_row
= it
.glyph_row
- 1;
16182 if (fonts_changed_p
&& !(flags
& TRY_WINDOW_IGNORE_FONTS_CHANGE
))
16185 #ifdef HAVE_XWIDGETS_xxx
16186 //currently this is needed to detect xwidget movement reliably. or probably not.
16187 printf("try_window\n");
16191 /* Don't let the cursor end in the scroll margins. */
16192 if ((flags
& TRY_WINDOW_CHECK_MARGINS
)
16193 && !MINI_WINDOW_P (w
))
16195 int this_scroll_margin
;
16197 if (scroll_margin
> 0)
16199 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
16200 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
16203 this_scroll_margin
= 0;
16205 if ((w
->cursor
.y
>= 0 /* not vscrolled */
16206 && w
->cursor
.y
< this_scroll_margin
16207 && CHARPOS (pos
) > BEGV
16208 && IT_CHARPOS (it
) < ZV
)
16209 /* rms: considering make_cursor_line_fully_visible_p here
16210 seems to give wrong results. We don't want to recenter
16211 when the last line is partly visible, we want to allow
16212 that case to be handled in the usual way. */
16213 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
16215 w
->cursor
.vpos
= -1;
16216 clear_glyph_matrix (w
->desired_matrix
);
16221 /* If bottom moved off end of frame, change mode line percentage. */
16222 if (XFASTINT (w
->window_end_pos
) <= 0
16223 && Z
!= IT_CHARPOS (it
))
16224 w
->update_mode_line
= 1;
16226 /* Set window_end_pos to the offset of the last character displayed
16227 on the window from the end of current_buffer. Set
16228 window_end_vpos to its row number. */
16231 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
16232 w
->window_end_bytepos
16233 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16234 wset_window_end_pos
16235 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
)));
16236 wset_window_end_vpos
16237 (w
, make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
)));
16239 (MATRIX_ROW (w
->desired_matrix
,
16240 XFASTINT (w
->window_end_vpos
))->displays_text_p
);
16244 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16245 wset_window_end_pos (w
, make_number (Z
- ZV
));
16246 wset_window_end_vpos (w
, make_number (0));
16249 /* But that is not valid info until redisplay finishes. */
16250 w
->window_end_valid
= 0;
16256 /************************************************************************
16257 Window redisplay reusing current matrix when buffer has not changed
16258 ************************************************************************/
16260 /* Try redisplay of window W showing an unchanged buffer with a
16261 different window start than the last time it was displayed by
16262 reusing its current matrix. Value is non-zero if successful.
16263 W->start is the new window start. */
16266 try_window_reusing_current_matrix (struct window
*w
)
16268 struct frame
*f
= XFRAME (w
->frame
);
16269 struct glyph_row
*bottom_row
;
16272 struct text_pos start
, new_start
;
16273 int nrows_scrolled
, i
;
16274 struct glyph_row
*last_text_row
;
16275 struct glyph_row
*last_reused_text_row
;
16276 struct glyph_row
*start_row
;
16277 int start_vpos
, min_y
, max_y
;
16280 if (inhibit_try_window_reusing
)
16284 #ifdef HAVE_XWIDGETS_xxx
16285 //currently this is needed to detect xwidget movement reliably. or probably not.
16286 printf("try_window_reusing_current_matrix\n");
16291 if (/* This function doesn't handle terminal frames. */
16292 !FRAME_WINDOW_P (f
)
16293 /* Don't try to reuse the display if windows have been split
16295 || windows_or_buffers_changed
16296 || cursor_type_changed
)
16299 /* Can't do this if region may have changed. */
16300 if (0 <= markpos_of_region ()
16301 || w
->region_showing
16302 || !NILP (Vshow_trailing_whitespace
))
16305 /* If top-line visibility has changed, give up. */
16306 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16307 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
16310 /* Give up if old or new display is scrolled vertically. We could
16311 make this function handle this, but right now it doesn't. */
16312 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16313 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
16316 /* The variable new_start now holds the new window start. The old
16317 start `start' can be determined from the current matrix. */
16318 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
16319 start
= start_row
->minpos
;
16320 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16322 /* Clear the desired matrix for the display below. */
16323 clear_glyph_matrix (w
->desired_matrix
);
16325 if (CHARPOS (new_start
) <= CHARPOS (start
))
16327 /* Don't use this method if the display starts with an ellipsis
16328 displayed for invisible text. It's not easy to handle that case
16329 below, and it's certainly not worth the effort since this is
16330 not a frequent case. */
16331 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
16334 IF_DEBUG (debug_method_add (w
, "twu1"));
16336 /* Display up to a row that can be reused. The variable
16337 last_text_row is set to the last row displayed that displays
16338 text. Note that it.vpos == 0 if or if not there is a
16339 header-line; it's not the same as the MATRIX_ROW_VPOS! */
16340 start_display (&it
, w
, new_start
);
16341 w
->cursor
.vpos
= -1;
16342 last_text_row
= last_reused_text_row
= NULL
;
16344 while (it
.current_y
< it
.last_visible_y
16345 && !fonts_changed_p
)
16347 /* If we have reached into the characters in the START row,
16348 that means the line boundaries have changed. So we
16349 can't start copying with the row START. Maybe it will
16350 work to start copying with the following row. */
16351 while (IT_CHARPOS (it
) > CHARPOS (start
))
16353 /* Advance to the next row as the "start". */
16355 start
= start_row
->minpos
;
16356 /* If there are no more rows to try, or just one, give up. */
16357 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
16358 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
16359 || CHARPOS (start
) == ZV
)
16361 clear_glyph_matrix (w
->desired_matrix
);
16365 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16367 /* If we have reached alignment, we can copy the rest of the
16369 if (IT_CHARPOS (it
) == CHARPOS (start
)
16370 /* Don't accept "alignment" inside a display vector,
16371 since start_row could have started in the middle of
16372 that same display vector (thus their character
16373 positions match), and we have no way of telling if
16374 that is the case. */
16375 && it
.current
.dpvec_index
< 0)
16378 if (display_line (&it
))
16379 last_text_row
= it
.glyph_row
- 1;
16383 /* A value of current_y < last_visible_y means that we stopped
16384 at the previous window start, which in turn means that we
16385 have at least one reusable row. */
16386 if (it
.current_y
< it
.last_visible_y
)
16388 struct glyph_row
*row
;
16390 /* IT.vpos always starts from 0; it counts text lines. */
16391 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
16393 /* Find PT if not already found in the lines displayed. */
16394 if (w
->cursor
.vpos
< 0)
16396 int dy
= it
.current_y
- start_row
->y
;
16398 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16399 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
16401 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
16402 dy
, nrows_scrolled
);
16405 clear_glyph_matrix (w
->desired_matrix
);
16410 /* Scroll the display. Do it before the current matrix is
16411 changed. The problem here is that update has not yet
16412 run, i.e. part of the current matrix is not up to date.
16413 scroll_run_hook will clear the cursor, and use the
16414 current matrix to get the height of the row the cursor is
16416 run
.current_y
= start_row
->y
;
16417 run
.desired_y
= it
.current_y
;
16418 run
.height
= it
.last_visible_y
- it
.current_y
;
16420 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
16423 FRAME_RIF (f
)->update_window_begin_hook (w
);
16424 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16425 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16426 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16430 /* Shift current matrix down by nrows_scrolled lines. */
16431 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16432 rotate_matrix (w
->current_matrix
,
16434 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16437 /* Disable lines that must be updated. */
16438 for (i
= 0; i
< nrows_scrolled
; ++i
)
16439 (start_row
+ i
)->enabled_p
= 0;
16441 /* Re-compute Y positions. */
16442 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16443 max_y
= it
.last_visible_y
;
16444 for (row
= start_row
+ nrows_scrolled
;
16448 row
->y
= it
.current_y
;
16449 row
->visible_height
= row
->height
;
16451 if (row
->y
< min_y
)
16452 row
->visible_height
-= min_y
- row
->y
;
16453 if (row
->y
+ row
->height
> max_y
)
16454 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16455 if (row
->fringe_bitmap_periodic_p
)
16456 row
->redraw_fringe_bitmaps_p
= 1;
16458 it
.current_y
+= row
->height
;
16460 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16461 last_reused_text_row
= row
;
16462 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
16466 /* Disable lines in the current matrix which are now
16467 below the window. */
16468 for (++row
; row
< bottom_row
; ++row
)
16469 row
->enabled_p
= row
->mode_line_p
= 0;
16472 /* Update window_end_pos etc.; last_reused_text_row is the last
16473 reused row from the current matrix containing text, if any.
16474 The value of last_text_row is the last displayed line
16475 containing text. */
16476 if (last_reused_text_row
)
16478 w
->window_end_bytepos
16479 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
16480 wset_window_end_pos
16482 - MATRIX_ROW_END_CHARPOS (last_reused_text_row
)));
16483 wset_window_end_vpos
16484 (w
, make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
16485 w
->current_matrix
)));
16487 else if (last_text_row
)
16489 w
->window_end_bytepos
16490 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16491 wset_window_end_pos
16492 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
)));
16493 wset_window_end_vpos
16494 (w
, make_number (MATRIX_ROW_VPOS (last_text_row
,
16495 w
->desired_matrix
)));
16499 /* This window must be completely empty. */
16500 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16501 wset_window_end_pos (w
, make_number (Z
- ZV
));
16502 wset_window_end_vpos (w
, make_number (0));
16504 w
->window_end_valid
= 0;
16506 /* Update hint: don't try scrolling again in update_window. */
16507 w
->desired_matrix
->no_scrolling_p
= 1;
16510 debug_method_add (w
, "try_window_reusing_current_matrix 1");
16514 else if (CHARPOS (new_start
) > CHARPOS (start
))
16516 struct glyph_row
*pt_row
, *row
;
16517 struct glyph_row
*first_reusable_row
;
16518 struct glyph_row
*first_row_to_display
;
16520 int yb
= window_text_bottom_y (w
);
16522 /* Find the row starting at new_start, if there is one. Don't
16523 reuse a partially visible line at the end. */
16524 first_reusable_row
= start_row
;
16525 while (first_reusable_row
->enabled_p
16526 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
16527 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16528 < CHARPOS (new_start
)))
16529 ++first_reusable_row
;
16531 /* Give up if there is no row to reuse. */
16532 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
16533 || !first_reusable_row
->enabled_p
16534 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16535 != CHARPOS (new_start
)))
16538 /* We can reuse fully visible rows beginning with
16539 first_reusable_row to the end of the window. Set
16540 first_row_to_display to the first row that cannot be reused.
16541 Set pt_row to the row containing point, if there is any. */
16543 for (first_row_to_display
= first_reusable_row
;
16544 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
16545 ++first_row_to_display
)
16547 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
16548 && (PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16549 || (PT
== MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16550 && first_row_to_display
->ends_at_zv_p
16551 && pt_row
== NULL
)))
16552 pt_row
= first_row_to_display
;
16555 /* Start displaying at the start of first_row_to_display. */
16556 eassert (first_row_to_display
->y
< yb
);
16557 init_to_row_start (&it
, w
, first_row_to_display
);
16559 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
16561 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
16563 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
16564 + WINDOW_HEADER_LINE_HEIGHT (w
));
16566 /* Display lines beginning with first_row_to_display in the
16567 desired matrix. Set last_text_row to the last row displayed
16568 that displays text. */
16569 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
16570 if (pt_row
== NULL
)
16571 w
->cursor
.vpos
= -1;
16572 last_text_row
= NULL
;
16573 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
16574 if (display_line (&it
))
16575 last_text_row
= it
.glyph_row
- 1;
16577 /* If point is in a reused row, adjust y and vpos of the cursor
16581 w
->cursor
.vpos
-= nrows_scrolled
;
16582 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
16585 /* Give up if point isn't in a row displayed or reused. (This
16586 also handles the case where w->cursor.vpos < nrows_scrolled
16587 after the calls to display_line, which can happen with scroll
16588 margins. See bug#1295.) */
16589 if (w
->cursor
.vpos
< 0)
16591 clear_glyph_matrix (w
->desired_matrix
);
16595 /* Scroll the display. */
16596 run
.current_y
= first_reusable_row
->y
;
16597 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16598 run
.height
= it
.last_visible_y
- run
.current_y
;
16599 dy
= run
.current_y
- run
.desired_y
;
16604 FRAME_RIF (f
)->update_window_begin_hook (w
);
16605 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16606 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16607 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16611 /* Adjust Y positions of reused rows. */
16612 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16613 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16614 max_y
= it
.last_visible_y
;
16615 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
16618 row
->visible_height
= row
->height
;
16619 if (row
->y
< min_y
)
16620 row
->visible_height
-= min_y
- row
->y
;
16621 if (row
->y
+ row
->height
> max_y
)
16622 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16623 if (row
->fringe_bitmap_periodic_p
)
16624 row
->redraw_fringe_bitmaps_p
= 1;
16627 /* Scroll the current matrix. */
16628 eassert (nrows_scrolled
> 0);
16629 rotate_matrix (w
->current_matrix
,
16631 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16634 /* Disable rows not reused. */
16635 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
16636 row
->enabled_p
= 0;
16638 /* Point may have moved to a different line, so we cannot assume that
16639 the previous cursor position is valid; locate the correct row. */
16642 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
16644 && PT
>= MATRIX_ROW_END_CHARPOS (row
)
16645 && !row
->ends_at_zv_p
;
16649 w
->cursor
.y
= row
->y
;
16651 if (row
< bottom_row
)
16653 /* Can't simply scan the row for point with
16654 bidi-reordered glyph rows. Let set_cursor_from_row
16655 figure out where to put the cursor, and if it fails,
16657 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
16659 if (!set_cursor_from_row (w
, row
, w
->current_matrix
,
16662 clear_glyph_matrix (w
->desired_matrix
);
16668 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
16669 struct glyph
*end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16672 && (!BUFFERP (glyph
->object
)
16673 || glyph
->charpos
< PT
);
16677 w
->cursor
.x
+= glyph
->pixel_width
;
16683 /* Adjust window end. A null value of last_text_row means that
16684 the window end is in reused rows which in turn means that
16685 only its vpos can have changed. */
16688 w
->window_end_bytepos
16689 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16690 wset_window_end_pos
16691 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
)));
16692 wset_window_end_vpos
16693 (w
, make_number (MATRIX_ROW_VPOS (last_text_row
,
16694 w
->desired_matrix
)));
16698 wset_window_end_vpos
16699 (w
, make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
));
16702 w
->window_end_valid
= 0;
16703 w
->desired_matrix
->no_scrolling_p
= 1;
16706 debug_method_add (w
, "try_window_reusing_current_matrix 2");
16716 /************************************************************************
16717 Window redisplay reusing current matrix when buffer has changed
16718 ************************************************************************/
16720 static struct glyph_row
*find_last_unchanged_at_beg_row (struct window
*);
16721 static struct glyph_row
*find_first_unchanged_at_end_row (struct window
*,
16722 ptrdiff_t *, ptrdiff_t *);
16723 static struct glyph_row
*
16724 find_last_row_displaying_text (struct glyph_matrix
*, struct it
*,
16725 struct glyph_row
*);
16728 /* Return the last row in MATRIX displaying text. If row START is
16729 non-null, start searching with that row. IT gives the dimensions
16730 of the display. Value is null if matrix is empty; otherwise it is
16731 a pointer to the row found. */
16733 static struct glyph_row
*
16734 find_last_row_displaying_text (struct glyph_matrix
*matrix
, struct it
*it
,
16735 struct glyph_row
*start
)
16737 struct glyph_row
*row
, *row_found
;
16739 /* Set row_found to the last row in IT->w's current matrix
16740 displaying text. The loop looks funny but think of partially
16743 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
16744 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16746 eassert (row
->enabled_p
);
16748 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
16757 /* Return the last row in the current matrix of W that is not affected
16758 by changes at the start of current_buffer that occurred since W's
16759 current matrix was built. Value is null if no such row exists.
16761 BEG_UNCHANGED us the number of characters unchanged at the start of
16762 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
16763 first changed character in current_buffer. Characters at positions <
16764 BEG + BEG_UNCHANGED are at the same buffer positions as they were
16765 when the current matrix was built. */
16767 static struct glyph_row
*
16768 find_last_unchanged_at_beg_row (struct window
*w
)
16770 ptrdiff_t first_changed_pos
= BEG
+ BEG_UNCHANGED
;
16771 struct glyph_row
*row
;
16772 struct glyph_row
*row_found
= NULL
;
16773 int yb
= window_text_bottom_y (w
);
16775 /* Find the last row displaying unchanged text. */
16776 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16777 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
16778 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
16781 if (/* If row ends before first_changed_pos, it is unchanged,
16782 except in some case. */
16783 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
16784 /* When row ends in ZV and we write at ZV it is not
16786 && !row
->ends_at_zv_p
16787 /* When first_changed_pos is the end of a continued line,
16788 row is not unchanged because it may be no longer
16790 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
16791 && (row
->continued_p
16792 || row
->exact_window_width_line_p
))
16793 /* If ROW->end is beyond ZV, then ROW->end is outdated and
16794 needs to be recomputed, so don't consider this row as
16795 unchanged. This happens when the last line was
16796 bidi-reordered and was killed immediately before this
16797 redisplay cycle. In that case, ROW->end stores the
16798 buffer position of the first visual-order character of
16799 the killed text, which is now beyond ZV. */
16800 && CHARPOS (row
->end
.pos
) <= ZV
)
16803 /* Stop if last visible row. */
16804 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
16812 /* Find the first glyph row in the current matrix of W that is not
16813 affected by changes at the end of current_buffer since the
16814 time W's current matrix was built.
16816 Return in *DELTA the number of chars by which buffer positions in
16817 unchanged text at the end of current_buffer must be adjusted.
16819 Return in *DELTA_BYTES the corresponding number of bytes.
16821 Value is null if no such row exists, i.e. all rows are affected by
16824 static struct glyph_row
*
16825 find_first_unchanged_at_end_row (struct window
*w
,
16826 ptrdiff_t *delta
, ptrdiff_t *delta_bytes
)
16828 struct glyph_row
*row
;
16829 struct glyph_row
*row_found
= NULL
;
16831 *delta
= *delta_bytes
= 0;
16833 /* Display must not have been paused, otherwise the current matrix
16834 is not up to date. */
16835 eassert (w
->window_end_valid
);
16837 /* A value of window_end_pos >= END_UNCHANGED means that the window
16838 end is in the range of changed text. If so, there is no
16839 unchanged row at the end of W's current matrix. */
16840 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
16843 /* Set row to the last row in W's current matrix displaying text. */
16844 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
16846 /* If matrix is entirely empty, no unchanged row exists. */
16847 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16849 /* The value of row is the last glyph row in the matrix having a
16850 meaningful buffer position in it. The end position of row
16851 corresponds to window_end_pos. This allows us to translate
16852 buffer positions in the current matrix to current buffer
16853 positions for characters not in changed text. */
16855 MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
16856 ptrdiff_t Z_BYTE_old
=
16857 MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
16858 ptrdiff_t last_unchanged_pos
, last_unchanged_pos_old
;
16859 struct glyph_row
*first_text_row
16860 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16862 *delta
= Z
- Z_old
;
16863 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
16865 /* Set last_unchanged_pos to the buffer position of the last
16866 character in the buffer that has not been changed. Z is the
16867 index + 1 of the last character in current_buffer, i.e. by
16868 subtracting END_UNCHANGED we get the index of the last
16869 unchanged character, and we have to add BEG to get its buffer
16871 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
16872 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
16874 /* Search backward from ROW for a row displaying a line that
16875 starts at a minimum position >= last_unchanged_pos_old. */
16876 for (; row
> first_text_row
; --row
)
16878 /* This used to abort, but it can happen.
16879 It is ok to just stop the search instead here. KFS. */
16880 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16883 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
16888 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
16894 /* Make sure that glyph rows in the current matrix of window W
16895 reference the same glyph memory as corresponding rows in the
16896 frame's frame matrix. This function is called after scrolling W's
16897 current matrix on a terminal frame in try_window_id and
16898 try_window_reusing_current_matrix. */
16901 sync_frame_with_window_matrix_rows (struct window
*w
)
16903 struct frame
*f
= XFRAME (w
->frame
);
16904 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
16906 /* Preconditions: W must be a leaf window and full-width. Its frame
16907 must have a frame matrix. */
16908 eassert (NILP (w
->hchild
) && NILP (w
->vchild
));
16909 eassert (WINDOW_FULL_WIDTH_P (w
));
16910 eassert (!FRAME_WINDOW_P (f
));
16912 /* If W is a full-width window, glyph pointers in W's current matrix
16913 have, by definition, to be the same as glyph pointers in the
16914 corresponding frame matrix. Note that frame matrices have no
16915 marginal areas (see build_frame_matrix). */
16916 window_row
= w
->current_matrix
->rows
;
16917 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
16918 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
16919 while (window_row
< window_row_end
)
16921 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
16922 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
16924 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
16925 frame_row
->glyphs
[TEXT_AREA
] = start
;
16926 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
16927 frame_row
->glyphs
[LAST_AREA
] = end
;
16929 /* Disable frame rows whose corresponding window rows have
16930 been disabled in try_window_id. */
16931 if (!window_row
->enabled_p
)
16932 frame_row
->enabled_p
= 0;
16934 ++window_row
, ++frame_row
;
16939 /* Find the glyph row in window W containing CHARPOS. Consider all
16940 rows between START and END (not inclusive). END null means search
16941 all rows to the end of the display area of W. Value is the row
16942 containing CHARPOS or null. */
16945 row_containing_pos (struct window
*w
, ptrdiff_t charpos
,
16946 struct glyph_row
*start
, struct glyph_row
*end
, int dy
)
16948 struct glyph_row
*row
= start
;
16949 struct glyph_row
*best_row
= NULL
;
16950 ptrdiff_t mindif
= BUF_ZV (XBUFFER (w
->buffer
)) + 1;
16953 /* If we happen to start on a header-line, skip that. */
16954 if (row
->mode_line_p
)
16957 if ((end
&& row
>= end
) || !row
->enabled_p
)
16960 last_y
= window_text_bottom_y (w
) - dy
;
16964 /* Give up if we have gone too far. */
16965 if (end
&& row
>= end
)
16967 /* This formerly returned if they were equal.
16968 I think that both quantities are of a "last plus one" type;
16969 if so, when they are equal, the row is within the screen. -- rms. */
16970 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
16973 /* If it is in this row, return this row. */
16974 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
16975 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
16976 /* The end position of a row equals the start
16977 position of the next row. If CHARPOS is there, we
16978 would rather display it in the next line, except
16979 when this line ends in ZV. */
16980 && !row
->ends_at_zv_p
16981 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
16982 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
16986 if (NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
16987 || (!best_row
&& !row
->continued_p
))
16989 /* In bidi-reordered rows, there could be several rows
16990 occluding point, all of them belonging to the same
16991 continued line. We need to find the row which fits
16992 CHARPOS the best. */
16993 for (g
= row
->glyphs
[TEXT_AREA
];
16994 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16997 if (!STRINGP (g
->object
))
16999 if (g
->charpos
> 0 && eabs (g
->charpos
- charpos
) < mindif
)
17001 mindif
= eabs (g
->charpos
- charpos
);
17003 /* Exact match always wins. */
17010 else if (best_row
&& !row
->continued_p
)
17017 /* Try to redisplay window W by reusing its existing display. W's
17018 current matrix must be up to date when this function is called,
17019 i.e. window_end_valid must be nonzero.
17023 1 if display has been updated
17024 0 if otherwise unsuccessful
17025 -1 if redisplay with same window start is known not to succeed
17027 The following steps are performed:
17029 1. Find the last row in the current matrix of W that is not
17030 affected by changes at the start of current_buffer. If no such row
17033 2. Find the first row in W's current matrix that is not affected by
17034 changes at the end of current_buffer. Maybe there is no such row.
17036 3. Display lines beginning with the row + 1 found in step 1 to the
17037 row found in step 2 or, if step 2 didn't find a row, to the end of
17040 4. If cursor is not known to appear on the window, give up.
17042 5. If display stopped at the row found in step 2, scroll the
17043 display and current matrix as needed.
17045 6. Maybe display some lines at the end of W, if we must. This can
17046 happen under various circumstances, like a partially visible line
17047 becoming fully visible, or because newly displayed lines are displayed
17048 in smaller font sizes.
17050 7. Update W's window end information. */
17053 try_window_id (struct window
*w
)
17055 struct frame
*f
= XFRAME (w
->frame
);
17056 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
17057 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
17058 struct glyph_row
*last_unchanged_at_beg_row
;
17059 struct glyph_row
*first_unchanged_at_end_row
;
17060 struct glyph_row
*row
;
17061 struct glyph_row
*bottom_row
;
17064 ptrdiff_t delta
= 0, delta_bytes
= 0, stop_pos
;
17066 struct text_pos start_pos
;
17068 int first_unchanged_at_end_vpos
= 0;
17069 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
17070 struct text_pos start
;
17071 ptrdiff_t first_changed_charpos
, last_changed_charpos
;
17074 if (inhibit_try_window_id
)
17078 #ifdef HAVE_XWIDGETS_xxx
17079 //maybe needed for proper xwidget movement
17080 printf("try_window_id\n");
17085 /* This is handy for debugging. */
17087 #define GIVE_UP(X) \
17089 fprintf (stderr, "try_window_id give up %d\n", (X)); \
17093 #define GIVE_UP(X) return 0
17096 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
17098 /* Don't use this for mini-windows because these can show
17099 messages and mini-buffers, and we don't handle that here. */
17100 if (MINI_WINDOW_P (w
))
17103 /* This flag is used to prevent redisplay optimizations. */
17104 if (windows_or_buffers_changed
|| cursor_type_changed
)
17107 /* Verify that narrowing has not changed.
17108 Also verify that we were not told to prevent redisplay optimizations.
17109 It would be nice to further
17110 reduce the number of cases where this prevents try_window_id. */
17111 if (current_buffer
->clip_changed
17112 || current_buffer
->prevent_redisplay_optimizations_p
)
17115 /* Window must either use window-based redisplay or be full width. */
17116 if (!FRAME_WINDOW_P (f
)
17117 && (!FRAME_LINE_INS_DEL_OK (f
)
17118 || !WINDOW_FULL_WIDTH_P (w
)))
17121 /* Give up if point is known NOT to appear in W. */
17122 if (PT
< CHARPOS (start
))
17125 /* Another way to prevent redisplay optimizations. */
17126 if (w
->last_modified
== 0)
17129 /* Verify that window is not hscrolled. */
17130 if (w
->hscroll
!= 0)
17133 /* Verify that display wasn't paused. */
17134 if (!w
->window_end_valid
)
17137 /* Can't use this if highlighting a region because a cursor movement
17138 will do more than just set the cursor. */
17139 if (0 <= markpos_of_region ())
17142 /* Likewise if highlighting trailing whitespace. */
17143 if (!NILP (Vshow_trailing_whitespace
))
17146 /* Likewise if showing a region. */
17147 if (w
->region_showing
)
17150 /* Can't use this if overlay arrow position and/or string have
17152 if (overlay_arrows_changed_p ())
17155 /* When word-wrap is on, adding a space to the first word of a
17156 wrapped line can change the wrap position, altering the line
17157 above it. It might be worthwhile to handle this more
17158 intelligently, but for now just redisplay from scratch. */
17159 if (!NILP (BVAR (XBUFFER (w
->buffer
), word_wrap
)))
17162 /* Under bidi reordering, adding or deleting a character in the
17163 beginning of a paragraph, before the first strong directional
17164 character, can change the base direction of the paragraph (unless
17165 the buffer specifies a fixed paragraph direction), which will
17166 require to redisplay the whole paragraph. It might be worthwhile
17167 to find the paragraph limits and widen the range of redisplayed
17168 lines to that, but for now just give up this optimization and
17169 redisplay from scratch. */
17170 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
17171 && NILP (BVAR (XBUFFER (w
->buffer
), bidi_paragraph_direction
)))
17174 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
17175 only if buffer has really changed. The reason is that the gap is
17176 initially at Z for freshly visited files. The code below would
17177 set end_unchanged to 0 in that case. */
17178 if (MODIFF
> SAVE_MODIFF
17179 /* This seems to happen sometimes after saving a buffer. */
17180 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
17182 if (GPT
- BEG
< BEG_UNCHANGED
)
17183 BEG_UNCHANGED
= GPT
- BEG
;
17184 if (Z
- GPT
< END_UNCHANGED
)
17185 END_UNCHANGED
= Z
- GPT
;
17188 /* The position of the first and last character that has been changed. */
17189 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
17190 last_changed_charpos
= Z
- END_UNCHANGED
;
17192 /* If window starts after a line end, and the last change is in
17193 front of that newline, then changes don't affect the display.
17194 This case happens with stealth-fontification. Note that although
17195 the display is unchanged, glyph positions in the matrix have to
17196 be adjusted, of course. */
17197 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
17198 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
17199 && ((last_changed_charpos
< CHARPOS (start
)
17200 && CHARPOS (start
) == BEGV
)
17201 || (last_changed_charpos
< CHARPOS (start
) - 1
17202 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
17204 ptrdiff_t Z_old
, Z_delta
, Z_BYTE_old
, Z_delta_bytes
;
17205 struct glyph_row
*r0
;
17207 /* Compute how many chars/bytes have been added to or removed
17208 from the buffer. */
17209 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
17210 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
17211 Z_delta
= Z
- Z_old
;
17212 Z_delta_bytes
= Z_BYTE
- Z_BYTE_old
;
17214 /* Give up if PT is not in the window. Note that it already has
17215 been checked at the start of try_window_id that PT is not in
17216 front of the window start. */
17217 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + Z_delta
)
17220 /* If window start is unchanged, we can reuse the whole matrix
17221 as is, after adjusting glyph positions. No need to compute
17222 the window end again, since its offset from Z hasn't changed. */
17223 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17224 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + Z_delta
17225 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + Z_delta_bytes
17226 /* PT must not be in a partially visible line. */
17227 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + Z_delta
17228 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17230 /* Adjust positions in the glyph matrix. */
17231 if (Z_delta
|| Z_delta_bytes
)
17233 struct glyph_row
*r1
17234 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17235 increment_matrix_positions (w
->current_matrix
,
17236 MATRIX_ROW_VPOS (r0
, current_matrix
),
17237 MATRIX_ROW_VPOS (r1
, current_matrix
),
17238 Z_delta
, Z_delta_bytes
);
17241 /* Set the cursor. */
17242 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17244 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17251 /* Handle the case that changes are all below what is displayed in
17252 the window, and that PT is in the window. This shortcut cannot
17253 be taken if ZV is visible in the window, and text has been added
17254 there that is visible in the window. */
17255 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
17256 /* ZV is not visible in the window, or there are no
17257 changes at ZV, actually. */
17258 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
17259 || first_changed_charpos
== last_changed_charpos
))
17261 struct glyph_row
*r0
;
17263 /* Give up if PT is not in the window. Note that it already has
17264 been checked at the start of try_window_id that PT is not in
17265 front of the window start. */
17266 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
17269 /* If window start is unchanged, we can reuse the whole matrix
17270 as is, without changing glyph positions since no text has
17271 been added/removed in front of the window end. */
17272 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17273 if (TEXT_POS_EQUAL_P (start
, r0
->minpos
)
17274 /* PT must not be in a partially visible line. */
17275 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
17276 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17278 /* We have to compute the window end anew since text
17279 could have been added/removed after it. */
17280 wset_window_end_pos
17281 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (row
)));
17282 w
->window_end_bytepos
17283 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17285 /* Set the cursor. */
17286 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17288 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17295 /* Give up if window start is in the changed area.
17297 The condition used to read
17299 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
17301 but why that was tested escapes me at the moment. */
17302 if (CHARPOS (start
) >= first_changed_charpos
17303 && CHARPOS (start
) <= last_changed_charpos
)
17306 /* Check that window start agrees with the start of the first glyph
17307 row in its current matrix. Check this after we know the window
17308 start is not in changed text, otherwise positions would not be
17310 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17311 if (!TEXT_POS_EQUAL_P (start
, row
->minpos
))
17314 /* Give up if the window ends in strings. Overlay strings
17315 at the end are difficult to handle, so don't try. */
17316 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
17317 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
17320 /* Compute the position at which we have to start displaying new
17321 lines. Some of the lines at the top of the window might be
17322 reusable because they are not displaying changed text. Find the
17323 last row in W's current matrix not affected by changes at the
17324 start of current_buffer. Value is null if changes start in the
17325 first line of window. */
17326 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
17327 if (last_unchanged_at_beg_row
)
17329 /* Avoid starting to display in the middle of a character, a TAB
17330 for instance. This is easier than to set up the iterator
17331 exactly, and it's not a frequent case, so the additional
17332 effort wouldn't really pay off. */
17333 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
17334 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
17335 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
17336 --last_unchanged_at_beg_row
;
17338 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
17341 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
17343 start_pos
= it
.current
.pos
;
17345 /* Start displaying new lines in the desired matrix at the same
17346 vpos we would use in the current matrix, i.e. below
17347 last_unchanged_at_beg_row. */
17348 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
17350 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17351 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
17353 eassert (it
.hpos
== 0 && it
.current_x
== 0);
17357 /* There are no reusable lines at the start of the window.
17358 Start displaying in the first text line. */
17359 start_display (&it
, w
, start
);
17360 it
.vpos
= it
.first_vpos
;
17361 start_pos
= it
.current
.pos
;
17364 /* Find the first row that is not affected by changes at the end of
17365 the buffer. Value will be null if there is no unchanged row, in
17366 which case we must redisplay to the end of the window. delta
17367 will be set to the value by which buffer positions beginning with
17368 first_unchanged_at_end_row have to be adjusted due to text
17370 first_unchanged_at_end_row
17371 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
17372 IF_DEBUG (debug_delta
= delta
);
17373 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
17375 /* Set stop_pos to the buffer position up to which we will have to
17376 display new lines. If first_unchanged_at_end_row != NULL, this
17377 is the buffer position of the start of the line displayed in that
17378 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
17379 that we don't stop at a buffer position. */
17381 if (first_unchanged_at_end_row
)
17383 eassert (last_unchanged_at_beg_row
== NULL
17384 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
17386 /* If this is a continuation line, move forward to the next one
17387 that isn't. Changes in lines above affect this line.
17388 Caution: this may move first_unchanged_at_end_row to a row
17389 not displaying text. */
17390 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
17391 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17392 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17393 < it
.last_visible_y
))
17394 ++first_unchanged_at_end_row
;
17396 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17397 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17398 >= it
.last_visible_y
))
17399 first_unchanged_at_end_row
= NULL
;
17402 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
17404 first_unchanged_at_end_vpos
17405 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
17406 eassert (stop_pos
>= Z
- END_UNCHANGED
);
17409 else if (last_unchanged_at_beg_row
== NULL
)
17415 /* Either there is no unchanged row at the end, or the one we have
17416 now displays text. This is a necessary condition for the window
17417 end pos calculation at the end of this function. */
17418 eassert (first_unchanged_at_end_row
== NULL
17419 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
17421 debug_last_unchanged_at_beg_vpos
17422 = (last_unchanged_at_beg_row
17423 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
17425 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
17427 #endif /* GLYPH_DEBUG */
17430 /* Display new lines. Set last_text_row to the last new line
17431 displayed which has text on it, i.e. might end up as being the
17432 line where the window_end_vpos is. */
17433 w
->cursor
.vpos
= -1;
17434 last_text_row
= NULL
;
17435 overlay_arrow_seen
= 0;
17436 while (it
.current_y
< it
.last_visible_y
17437 && !fonts_changed_p
17438 && (first_unchanged_at_end_row
== NULL
17439 || IT_CHARPOS (it
) < stop_pos
))
17441 if (display_line (&it
))
17442 last_text_row
= it
.glyph_row
- 1;
17445 if (fonts_changed_p
)
17449 /* Compute differences in buffer positions, y-positions etc. for
17450 lines reused at the bottom of the window. Compute what we can
17452 if (first_unchanged_at_end_row
17453 /* No lines reused because we displayed everything up to the
17454 bottom of the window. */
17455 && it
.current_y
< it
.last_visible_y
)
17458 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
17460 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
17461 run
.current_y
= first_unchanged_at_end_row
->y
;
17462 run
.desired_y
= run
.current_y
+ dy
;
17463 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
17467 delta
= delta_bytes
= dvpos
= dy
17468 = run
.current_y
= run
.desired_y
= run
.height
= 0;
17469 first_unchanged_at_end_row
= NULL
;
17471 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
17474 /* Find the cursor if not already found. We have to decide whether
17475 PT will appear on this window (it sometimes doesn't, but this is
17476 not a very frequent case.) This decision has to be made before
17477 the current matrix is altered. A value of cursor.vpos < 0 means
17478 that PT is either in one of the lines beginning at
17479 first_unchanged_at_end_row or below the window. Don't care for
17480 lines that might be displayed later at the window end; as
17481 mentioned, this is not a frequent case. */
17482 if (w
->cursor
.vpos
< 0)
17484 /* Cursor in unchanged rows at the top? */
17485 if (PT
< CHARPOS (start_pos
)
17486 && last_unchanged_at_beg_row
)
17488 row
= row_containing_pos (w
, PT
,
17489 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
17490 last_unchanged_at_beg_row
+ 1, 0);
17492 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
17495 /* Start from first_unchanged_at_end_row looking for PT. */
17496 else if (first_unchanged_at_end_row
)
17498 row
= row_containing_pos (w
, PT
- delta
,
17499 first_unchanged_at_end_row
, NULL
, 0);
17501 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
17502 delta_bytes
, dy
, dvpos
);
17505 /* Give up if cursor was not found. */
17506 if (w
->cursor
.vpos
< 0)
17508 clear_glyph_matrix (w
->desired_matrix
);
17513 /* Don't let the cursor end in the scroll margins. */
17515 int this_scroll_margin
, cursor_height
;
17517 this_scroll_margin
=
17518 max (0, min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4));
17519 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
17520 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
17522 if ((w
->cursor
.y
< this_scroll_margin
17523 && CHARPOS (start
) > BEGV
)
17524 /* Old redisplay didn't take scroll margin into account at the bottom,
17525 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
17526 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
17527 ? cursor_height
+ this_scroll_margin
17528 : 1)) > it
.last_visible_y
)
17530 w
->cursor
.vpos
= -1;
17531 clear_glyph_matrix (w
->desired_matrix
);
17536 /* Scroll the display. Do it before changing the current matrix so
17537 that xterm.c doesn't get confused about where the cursor glyph is
17539 if (dy
&& run
.height
)
17543 if (FRAME_WINDOW_P (f
))
17545 FRAME_RIF (f
)->update_window_begin_hook (w
);
17546 FRAME_RIF (f
)->clear_window_mouse_face (w
);
17547 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
17548 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
17552 /* Terminal frame. In this case, dvpos gives the number of
17553 lines to scroll by; dvpos < 0 means scroll up. */
17555 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
17556 int from
= WINDOW_TOP_EDGE_LINE (w
) + from_vpos
;
17557 int end
= (WINDOW_TOP_EDGE_LINE (w
)
17558 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
17559 + window_internal_height (w
));
17561 #if defined (HAVE_GPM) || defined (MSDOS)
17562 x_clear_window_mouse_face (w
);
17564 /* Perform the operation on the screen. */
17567 /* Scroll last_unchanged_at_beg_row to the end of the
17568 window down dvpos lines. */
17569 set_terminal_window (f
, end
);
17571 /* On dumb terminals delete dvpos lines at the end
17572 before inserting dvpos empty lines. */
17573 if (!FRAME_SCROLL_REGION_OK (f
))
17574 ins_del_lines (f
, end
- dvpos
, -dvpos
);
17576 /* Insert dvpos empty lines in front of
17577 last_unchanged_at_beg_row. */
17578 ins_del_lines (f
, from
, dvpos
);
17580 else if (dvpos
< 0)
17582 /* Scroll up last_unchanged_at_beg_vpos to the end of
17583 the window to last_unchanged_at_beg_vpos - |dvpos|. */
17584 set_terminal_window (f
, end
);
17586 /* Delete dvpos lines in front of
17587 last_unchanged_at_beg_vpos. ins_del_lines will set
17588 the cursor to the given vpos and emit |dvpos| delete
17590 ins_del_lines (f
, from
+ dvpos
, dvpos
);
17592 /* On a dumb terminal insert dvpos empty lines at the
17594 if (!FRAME_SCROLL_REGION_OK (f
))
17595 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
17598 set_terminal_window (f
, 0);
17604 /* Shift reused rows of the current matrix to the right position.
17605 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
17607 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17608 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
17611 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
17612 bottom_vpos
, dvpos
);
17613 clear_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
17616 else if (dvpos
> 0)
17618 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
17619 bottom_vpos
, dvpos
);
17620 clear_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
17621 first_unchanged_at_end_vpos
+ dvpos
);
17624 /* For frame-based redisplay, make sure that current frame and window
17625 matrix are in sync with respect to glyph memory. */
17626 if (!FRAME_WINDOW_P (f
))
17627 sync_frame_with_window_matrix_rows (w
);
17629 /* Adjust buffer positions in reused rows. */
17630 if (delta
|| delta_bytes
)
17631 increment_matrix_positions (current_matrix
,
17632 first_unchanged_at_end_vpos
+ dvpos
,
17633 bottom_vpos
, delta
, delta_bytes
);
17635 /* Adjust Y positions. */
17637 shift_glyph_matrix (w
, current_matrix
,
17638 first_unchanged_at_end_vpos
+ dvpos
,
17641 if (first_unchanged_at_end_row
)
17643 first_unchanged_at_end_row
+= dvpos
;
17644 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
17645 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
17646 first_unchanged_at_end_row
= NULL
;
17649 /* If scrolling up, there may be some lines to display at the end of
17651 last_text_row_at_end
= NULL
;
17654 /* Scrolling up can leave for example a partially visible line
17655 at the end of the window to be redisplayed. */
17656 /* Set last_row to the glyph row in the current matrix where the
17657 window end line is found. It has been moved up or down in
17658 the matrix by dvpos. */
17659 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
17660 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
17662 /* If last_row is the window end line, it should display text. */
17663 eassert (last_row
->displays_text_p
);
17665 /* If window end line was partially visible before, begin
17666 displaying at that line. Otherwise begin displaying with the
17667 line following it. */
17668 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
17670 init_to_row_start (&it
, w
, last_row
);
17671 it
.vpos
= last_vpos
;
17672 it
.current_y
= last_row
->y
;
17676 init_to_row_end (&it
, w
, last_row
);
17677 it
.vpos
= 1 + last_vpos
;
17678 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
17682 /* We may start in a continuation line. If so, we have to
17683 get the right continuation_lines_width and current_x. */
17684 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
17685 it
.hpos
= it
.current_x
= 0;
17687 /* Display the rest of the lines at the window end. */
17688 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17689 while (it
.current_y
< it
.last_visible_y
17690 && !fonts_changed_p
)
17692 /* Is it always sure that the display agrees with lines in
17693 the current matrix? I don't think so, so we mark rows
17694 displayed invalid in the current matrix by setting their
17695 enabled_p flag to zero. */
17696 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
17697 if (display_line (&it
))
17698 last_text_row_at_end
= it
.glyph_row
- 1;
17702 /* Update window_end_pos and window_end_vpos. */
17703 if (first_unchanged_at_end_row
17704 && !last_text_row_at_end
)
17706 /* Window end line if one of the preserved rows from the current
17707 matrix. Set row to the last row displaying text in current
17708 matrix starting at first_unchanged_at_end_row, after
17710 eassert (first_unchanged_at_end_row
->displays_text_p
);
17711 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
17712 first_unchanged_at_end_row
);
17713 eassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
17715 wset_window_end_pos (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (row
)));
17716 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17717 wset_window_end_vpos
17718 (w
, make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
)));
17719 eassert (w
->window_end_bytepos
>= 0);
17720 IF_DEBUG (debug_method_add (w
, "A"));
17722 else if (last_text_row_at_end
)
17724 wset_window_end_pos
17725 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
)));
17726 w
->window_end_bytepos
17727 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
17728 wset_window_end_vpos
17729 (w
, make_number (MATRIX_ROW_VPOS (last_text_row_at_end
,
17731 eassert (w
->window_end_bytepos
>= 0);
17732 IF_DEBUG (debug_method_add (w
, "B"));
17734 else if (last_text_row
)
17736 /* We have displayed either to the end of the window or at the
17737 end of the window, i.e. the last row with text is to be found
17738 in the desired matrix. */
17739 wset_window_end_pos
17740 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
)));
17741 w
->window_end_bytepos
17742 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
17743 wset_window_end_vpos
17744 (w
, make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
)));
17745 eassert (w
->window_end_bytepos
>= 0);
17747 else if (first_unchanged_at_end_row
== NULL
17748 && last_text_row
== NULL
17749 && last_text_row_at_end
== NULL
)
17751 /* Displayed to end of window, but no line containing text was
17752 displayed. Lines were deleted at the end of the window. */
17753 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
17754 int vpos
= XFASTINT (w
->window_end_vpos
);
17755 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
17756 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
17759 row
== NULL
&& vpos
>= first_vpos
;
17760 --vpos
, --current_row
, --desired_row
)
17762 if (desired_row
->enabled_p
)
17764 if (desired_row
->displays_text_p
)
17767 else if (current_row
->displays_text_p
)
17771 eassert (row
!= NULL
);
17772 wset_window_end_vpos (w
, make_number (vpos
+ 1));
17773 wset_window_end_pos (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (row
)));
17774 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17775 eassert (w
->window_end_bytepos
>= 0);
17776 IF_DEBUG (debug_method_add (w
, "C"));
17781 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
17782 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
17784 /* Record that display has not been completed. */
17785 w
->window_end_valid
= 0;
17786 w
->desired_matrix
->no_scrolling_p
= 1;
17794 /***********************************************************************
17795 More debugging support
17796 ***********************************************************************/
17800 void dump_glyph_row (struct glyph_row
*, int, int) EXTERNALLY_VISIBLE
;
17801 void dump_glyph_matrix (struct glyph_matrix
*, int) EXTERNALLY_VISIBLE
;
17802 void dump_glyph (struct glyph_row
*, struct glyph
*, int) EXTERNALLY_VISIBLE
;
17805 /* Dump the contents of glyph matrix MATRIX on stderr.
17807 GLYPHS 0 means don't show glyph contents.
17808 GLYPHS 1 means show glyphs in short form
17809 GLYPHS > 1 means show glyphs in long form. */
17812 dump_glyph_matrix (struct glyph_matrix
*matrix
, int glyphs
)
17815 for (i
= 0; i
< matrix
->nrows
; ++i
)
17816 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
17820 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
17821 the glyph row and area where the glyph comes from. */
17824 dump_glyph (struct glyph_row
*row
, struct glyph
*glyph
, int area
)
17826 if (glyph
->type
== CHAR_GLYPH
17827 || glyph
->type
== GLYPHLESS_GLYPH
)
17830 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
17831 glyph
- row
->glyphs
[TEXT_AREA
],
17832 (glyph
->type
== CHAR_GLYPH
17836 (BUFFERP (glyph
->object
)
17838 : (STRINGP (glyph
->object
)
17840 : (INTEGERP (glyph
->object
)
17843 glyph
->pixel_width
,
17845 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
17849 glyph
->left_box_line_p
,
17850 glyph
->right_box_line_p
);
17852 else if (glyph
->type
== STRETCH_GLYPH
)
17855 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
17856 glyph
- row
->glyphs
[TEXT_AREA
],
17859 (BUFFERP (glyph
->object
)
17861 : (STRINGP (glyph
->object
)
17863 : (INTEGERP (glyph
->object
)
17866 glyph
->pixel_width
,
17870 glyph
->left_box_line_p
,
17871 glyph
->right_box_line_p
);
17873 else if (glyph
->type
== IMAGE_GLYPH
)
17876 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
17877 glyph
- row
->glyphs
[TEXT_AREA
],
17880 (BUFFERP (glyph
->object
)
17882 : (STRINGP (glyph
->object
)
17884 : (INTEGERP (glyph
->object
)
17887 glyph
->pixel_width
,
17891 glyph
->left_box_line_p
,
17892 glyph
->right_box_line_p
);
17894 else if (glyph
->type
== COMPOSITE_GLYPH
)
17897 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x",
17898 glyph
- row
->glyphs
[TEXT_AREA
],
17901 (BUFFERP (glyph
->object
)
17903 : (STRINGP (glyph
->object
)
17905 : (INTEGERP (glyph
->object
)
17908 glyph
->pixel_width
,
17910 if (glyph
->u
.cmp
.automatic
)
17913 glyph
->slice
.cmp
.from
, glyph
->slice
.cmp
.to
);
17914 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
17916 glyph
->left_box_line_p
,
17917 glyph
->right_box_line_p
);
17919 #ifdef HAVE_XWIDGETS
17920 else if (glyph
->type
== XWIDGET_GLYPH
)
17923 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
17924 glyph
- row
->glyphs
[TEXT_AREA
],
17927 (BUFFERP (glyph
->object
)
17929 : (STRINGP (glyph
->object
)
17932 glyph
->pixel_width
,
17936 glyph
->left_box_line_p
,
17937 glyph
->right_box_line_p
);
17939 // printf("dump xwidget glyph\n");
17945 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
17946 GLYPHS 0 means don't show glyph contents.
17947 GLYPHS 1 means show glyphs in short form
17948 GLYPHS > 1 means show glyphs in long form. */
17951 dump_glyph_row (struct glyph_row
*row
, int vpos
, int glyphs
)
17955 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
17956 fprintf (stderr
, "==============================================================================\n");
17958 fprintf (stderr
, "%3d %9"pI
"d %9"pI
"d %4d %1.1d%1.1d%1.1d%1.1d\
17959 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
17961 MATRIX_ROW_START_CHARPOS (row
),
17962 MATRIX_ROW_END_CHARPOS (row
),
17963 row
->used
[TEXT_AREA
],
17964 row
->contains_overlapping_glyphs_p
,
17966 row
->truncated_on_left_p
,
17967 row
->truncated_on_right_p
,
17969 MATRIX_ROW_CONTINUATION_LINE_P (row
),
17970 row
->displays_text_p
,
17973 row
->ends_in_middle_of_char_p
,
17974 row
->starts_in_middle_of_char_p
,
17980 row
->visible_height
,
17983 /* The next 3 lines should align to "Start" in the header. */
17984 fprintf (stderr
, " %9"pD
"d %9"pD
"d\t%5d\n", row
->start
.overlay_string_index
,
17985 row
->end
.overlay_string_index
,
17986 row
->continuation_lines_width
);
17987 fprintf (stderr
, " %9"pI
"d %9"pI
"d\n",
17988 CHARPOS (row
->start
.string_pos
),
17989 CHARPOS (row
->end
.string_pos
));
17990 fprintf (stderr
, " %9d %9d\n", row
->start
.dpvec_index
,
17991 row
->end
.dpvec_index
);
17998 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18000 struct glyph
*glyph
= row
->glyphs
[area
];
18001 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
18003 /* Glyph for a line end in text. */
18004 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
18007 if (glyph
< glyph_end
)
18008 fprintf (stderr
, " Glyph# Type Pos O W Code C Face LR\n");
18010 for (; glyph
< glyph_end
; ++glyph
)
18011 dump_glyph (row
, glyph
, area
);
18014 else if (glyphs
== 1)
18018 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18020 char *s
= alloca (row
->used
[area
] + 4);
18023 for (i
= 0; i
< row
->used
[area
]; ++i
)
18025 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
18026 if (i
== row
->used
[area
] - 1
18027 && area
== TEXT_AREA
18028 && INTEGERP (glyph
->object
)
18029 && glyph
->type
== CHAR_GLYPH
18030 && glyph
->u
.ch
== ' ')
18032 strcpy (&s
[i
], "[\\n]");
18035 else if (glyph
->type
== CHAR_GLYPH
18036 && glyph
->u
.ch
< 0x80
18037 && glyph
->u
.ch
>= ' ')
18038 s
[i
] = glyph
->u
.ch
;
18044 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
18050 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
18051 Sdump_glyph_matrix
, 0, 1, "p",
18052 doc
: /* Dump the current matrix of the selected window to stderr.
18053 Shows contents of glyph row structures. With non-nil
18054 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
18055 glyphs in short form, otherwise show glyphs in long form. */)
18056 (Lisp_Object glyphs
)
18058 struct window
*w
= XWINDOW (selected_window
);
18059 struct buffer
*buffer
= XBUFFER (w
->buffer
);
18061 fprintf (stderr
, "PT = %"pI
"d, BEGV = %"pI
"d. ZV = %"pI
"d\n",
18062 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
18063 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
18064 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
18065 fprintf (stderr
, "=============================================\n");
18066 dump_glyph_matrix (w
->current_matrix
,
18067 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 0);
18072 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
18073 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
18076 struct frame
*f
= XFRAME (selected_frame
);
18077 dump_glyph_matrix (f
->current_matrix
, 1);
18082 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
18083 doc
: /* Dump glyph row ROW to stderr.
18084 GLYPH 0 means don't dump glyphs.
18085 GLYPH 1 means dump glyphs in short form.
18086 GLYPH > 1 or omitted means dump glyphs in long form. */)
18087 (Lisp_Object row
, Lisp_Object glyphs
)
18089 struct glyph_matrix
*matrix
;
18092 CHECK_NUMBER (row
);
18093 matrix
= XWINDOW (selected_window
)->current_matrix
;
18095 if (vpos
>= 0 && vpos
< matrix
->nrows
)
18096 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
18098 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18103 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
18104 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
18105 GLYPH 0 means don't dump glyphs.
18106 GLYPH 1 means dump glyphs in short form.
18107 GLYPH > 1 or omitted means dump glyphs in long form. */)
18108 (Lisp_Object row
, Lisp_Object glyphs
)
18110 struct frame
*sf
= SELECTED_FRAME ();
18111 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
18114 CHECK_NUMBER (row
);
18116 if (vpos
>= 0 && vpos
< m
->nrows
)
18117 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
18118 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18123 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
18124 doc
: /* Toggle tracing of redisplay.
18125 With ARG, turn tracing on if and only if ARG is positive. */)
18129 trace_redisplay_p
= !trace_redisplay_p
;
18132 arg
= Fprefix_numeric_value (arg
);
18133 trace_redisplay_p
= XINT (arg
) > 0;
18140 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
18141 doc
: /* Like `format', but print result to stderr.
18142 usage: (trace-to-stderr STRING &rest OBJECTS) */)
18143 (ptrdiff_t nargs
, Lisp_Object
*args
)
18145 Lisp_Object s
= Fformat (nargs
, args
);
18146 fprintf (stderr
, "%s", SDATA (s
));
18150 #endif /* GLYPH_DEBUG */
18154 /***********************************************************************
18155 Building Desired Matrix Rows
18156 ***********************************************************************/
18158 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
18159 Used for non-window-redisplay windows, and for windows w/o left fringe. */
18161 static struct glyph_row
*
18162 get_overlay_arrow_glyph_row (struct window
*w
, Lisp_Object overlay_arrow_string
)
18164 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18165 struct buffer
*buffer
= XBUFFER (w
->buffer
);
18166 struct buffer
*old
= current_buffer
;
18167 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
18168 int arrow_len
= SCHARS (overlay_arrow_string
);
18169 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
18170 const unsigned char *p
;
18173 int n_glyphs_before
;
18175 set_buffer_temp (buffer
);
18176 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
18177 it
.glyph_row
->used
[TEXT_AREA
] = 0;
18178 SET_TEXT_POS (it
.position
, 0, 0);
18180 multibyte_p
= !NILP (BVAR (buffer
, enable_multibyte_characters
));
18182 while (p
< arrow_end
)
18184 Lisp_Object face
, ilisp
;
18186 /* Get the next character. */
18188 it
.c
= it
.char_to_display
= string_char_and_length (p
, &it
.len
);
18191 it
.c
= it
.char_to_display
= *p
, it
.len
= 1;
18192 if (! ASCII_CHAR_P (it
.c
))
18193 it
.char_to_display
= BYTE8_TO_CHAR (it
.c
);
18197 /* Get its face. */
18198 ilisp
= make_number (p
- arrow_string
);
18199 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
18200 it
.face_id
= compute_char_face (f
, it
.char_to_display
, face
);
18202 /* Compute its width, get its glyphs. */
18203 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
18204 SET_TEXT_POS (it
.position
, -1, -1);
18205 PRODUCE_GLYPHS (&it
);
18207 /* If this character doesn't fit any more in the line, we have
18208 to remove some glyphs. */
18209 if (it
.current_x
> it
.last_visible_x
)
18211 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
18216 set_buffer_temp (old
);
18217 return it
.glyph_row
;
18221 /* Insert truncation glyphs at the start of IT->glyph_row. Which
18222 glyphs to insert is determined by produce_special_glyphs. */
18225 insert_left_trunc_glyphs (struct it
*it
)
18227 struct it truncate_it
;
18228 struct glyph
*from
, *end
, *to
, *toend
;
18230 eassert (!FRAME_WINDOW_P (it
->f
)
18231 || (!it
->glyph_row
->reversed_p
18232 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0)
18233 || (it
->glyph_row
->reversed_p
18234 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0));
18236 /* Get the truncation glyphs. */
18238 truncate_it
.current_x
= 0;
18239 truncate_it
.face_id
= DEFAULT_FACE_ID
;
18240 truncate_it
.glyph_row
= &scratch_glyph_row
;
18241 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
18242 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
18243 truncate_it
.object
= make_number (0);
18244 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
18246 /* Overwrite glyphs from IT with truncation glyphs. */
18247 if (!it
->glyph_row
->reversed_p
)
18249 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
18251 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18252 end
= from
+ tused
;
18253 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18254 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
18255 if (FRAME_WINDOW_P (it
->f
))
18257 /* On GUI frames, when variable-size fonts are displayed,
18258 the truncation glyphs may need more pixels than the row's
18259 glyphs they overwrite. We overwrite more glyphs to free
18260 enough screen real estate, and enlarge the stretch glyph
18261 on the right (see display_line), if there is one, to
18262 preserve the screen position of the truncation glyphs on
18265 struct glyph
*g
= to
;
18268 /* The first glyph could be partially visible, in which case
18269 it->glyph_row->x will be negative. But we want the left
18270 truncation glyphs to be aligned at the left margin of the
18271 window, so we override the x coordinate at which the row
18273 it
->glyph_row
->x
= 0;
18274 while (g
< toend
&& w
< it
->truncation_pixel_width
)
18276 w
+= g
->pixel_width
;
18279 if (g
- to
- tused
> 0)
18281 memmove (to
+ tused
, g
, (toend
- g
) * sizeof(*g
));
18282 it
->glyph_row
->used
[TEXT_AREA
] -= g
- to
- tused
;
18284 used
= it
->glyph_row
->used
[TEXT_AREA
];
18285 if (it
->glyph_row
->truncated_on_right_p
18286 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0
18287 && it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].type
18290 int extra
= w
- it
->truncation_pixel_width
;
18292 it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].pixel_width
+= extra
;
18299 /* There may be padding glyphs left over. Overwrite them too. */
18300 if (!FRAME_WINDOW_P (it
->f
))
18302 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
18304 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18311 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
18315 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
18317 /* In R2L rows, overwrite the last (rightmost) glyphs, and do
18318 that back to front. */
18319 end
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18320 from
= end
+ truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18321 toend
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18322 to
= toend
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18323 if (FRAME_WINDOW_P (it
->f
))
18326 struct glyph
*g
= to
;
18328 while (g
>= toend
&& w
< it
->truncation_pixel_width
)
18330 w
+= g
->pixel_width
;
18333 if (to
- g
- tused
> 0)
18335 if (it
->glyph_row
->truncated_on_right_p
18336 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0
18337 && it
->glyph_row
->glyphs
[TEXT_AREA
][1].type
== STRETCH_GLYPH
)
18339 int extra
= w
- it
->truncation_pixel_width
;
18341 it
->glyph_row
->glyphs
[TEXT_AREA
][1].pixel_width
+= extra
;
18345 while (from
>= end
&& to
>= toend
)
18347 if (!FRAME_WINDOW_P (it
->f
))
18349 while (to
>= toend
&& CHAR_GLYPH_PADDING_P (*to
))
18352 truncate_it
.glyph_row
->glyphs
[TEXT_AREA
]
18353 + truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18354 while (from
>= end
&& to
>= toend
)
18360 /* Need to free some room before prepending additional
18362 int move_by
= from
- end
+ 1;
18363 struct glyph
*g0
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18364 struct glyph
*g
= g0
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18366 for ( ; g
>= g0
; g
--)
18368 while (from
>= end
)
18370 it
->glyph_row
->used
[TEXT_AREA
] += move_by
;
18375 /* Compute the hash code for ROW. */
18377 row_hash (struct glyph_row
*row
)
18380 unsigned hashval
= 0;
18382 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18383 for (k
= 0; k
< row
->used
[area
]; ++k
)
18384 hashval
= ((((hashval
<< 4) + (hashval
>> 24)) & 0x0fffffff)
18385 + row
->glyphs
[area
][k
].u
.val
18386 + row
->glyphs
[area
][k
].face_id
18387 + row
->glyphs
[area
][k
].padding_p
18388 + (row
->glyphs
[area
][k
].type
<< 2));
18393 /* Compute the pixel height and width of IT->glyph_row.
18395 Most of the time, ascent and height of a display line will be equal
18396 to the max_ascent and max_height values of the display iterator
18397 structure. This is not the case if
18399 1. We hit ZV without displaying anything. In this case, max_ascent
18400 and max_height will be zero.
18402 2. We have some glyphs that don't contribute to the line height.
18403 (The glyph row flag contributes_to_line_height_p is for future
18404 pixmap extensions).
18406 The first case is easily covered by using default values because in
18407 these cases, the line height does not really matter, except that it
18408 must not be zero. */
18411 compute_line_metrics (struct it
*it
)
18413 struct glyph_row
*row
= it
->glyph_row
;
18415 if (FRAME_WINDOW_P (it
->f
))
18417 int i
, min_y
, max_y
;
18419 /* The line may consist of one space only, that was added to
18420 place the cursor on it. If so, the row's height hasn't been
18422 if (row
->height
== 0)
18424 if (it
->max_ascent
+ it
->max_descent
== 0)
18425 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
18426 row
->ascent
= it
->max_ascent
;
18427 row
->height
= it
->max_ascent
+ it
->max_descent
;
18428 row
->phys_ascent
= it
->max_phys_ascent
;
18429 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18430 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18433 /* Compute the width of this line. */
18434 row
->pixel_width
= row
->x
;
18435 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
18436 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
18438 eassert (row
->pixel_width
>= 0);
18439 eassert (row
->ascent
>= 0 && row
->height
> 0);
18441 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
18442 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
18444 /* If first line's physical ascent is larger than its logical
18445 ascent, use the physical ascent, and make the row taller.
18446 This makes accented characters fully visible. */
18447 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
18448 && row
->phys_ascent
> row
->ascent
)
18450 row
->height
+= row
->phys_ascent
- row
->ascent
;
18451 row
->ascent
= row
->phys_ascent
;
18454 /* Compute how much of the line is visible. */
18455 row
->visible_height
= row
->height
;
18457 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
18458 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
18460 if (row
->y
< min_y
)
18461 row
->visible_height
-= min_y
- row
->y
;
18462 if (row
->y
+ row
->height
> max_y
)
18463 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
18467 row
->pixel_width
= row
->used
[TEXT_AREA
];
18468 if (row
->continued_p
)
18469 row
->pixel_width
-= it
->continuation_pixel_width
;
18470 else if (row
->truncated_on_right_p
)
18471 row
->pixel_width
-= it
->truncation_pixel_width
;
18472 row
->ascent
= row
->phys_ascent
= 0;
18473 row
->height
= row
->phys_height
= row
->visible_height
= 1;
18474 row
->extra_line_spacing
= 0;
18477 /* Compute a hash code for this row. */
18478 row
->hash
= row_hash (row
);
18480 it
->max_ascent
= it
->max_descent
= 0;
18481 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
18485 /* Append one space to the glyph row of iterator IT if doing a
18486 window-based redisplay. The space has the same face as
18487 IT->face_id. Value is non-zero if a space was added.
18489 This function is called to make sure that there is always one glyph
18490 at the end of a glyph row that the cursor can be set on under
18491 window-systems. (If there weren't such a glyph we would not know
18492 how wide and tall a box cursor should be displayed).
18494 At the same time this space let's a nicely handle clearing to the
18495 end of the line if the row ends in italic text. */
18498 append_space_for_newline (struct it
*it
, int default_face_p
)
18500 if (FRAME_WINDOW_P (it
->f
))
18502 int n
= it
->glyph_row
->used
[TEXT_AREA
];
18504 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
18505 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
18507 /* Save some values that must not be changed.
18508 Must save IT->c and IT->len because otherwise
18509 ITERATOR_AT_END_P wouldn't work anymore after
18510 append_space_for_newline has been called. */
18511 enum display_element_type saved_what
= it
->what
;
18512 int saved_c
= it
->c
, saved_len
= it
->len
;
18513 int saved_char_to_display
= it
->char_to_display
;
18514 int saved_x
= it
->current_x
;
18515 int saved_face_id
= it
->face_id
;
18516 int saved_box_end
= it
->end_of_box_run_p
;
18517 struct text_pos saved_pos
;
18518 Lisp_Object saved_object
;
18521 saved_object
= it
->object
;
18522 saved_pos
= it
->position
;
18524 it
->what
= IT_CHARACTER
;
18525 memset (&it
->position
, 0, sizeof it
->position
);
18526 it
->object
= make_number (0);
18527 it
->c
= it
->char_to_display
= ' ';
18530 /* If the default face was remapped, be sure to use the
18531 remapped face for the appended newline. */
18532 if (default_face_p
)
18533 it
->face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
18534 else if (it
->face_before_selective_p
)
18535 it
->face_id
= it
->saved_face_id
;
18536 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18537 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
18538 /* In R2L rows, we will prepend a stretch glyph that will
18539 have the end_of_box_run_p flag set for it, so there's no
18540 need for the appended newline glyph to have that flag
18542 if (it
->glyph_row
->reversed_p
18543 /* But if the appended newline glyph goes all the way to
18544 the end of the row, there will be no stretch glyph,
18545 so leave the box flag set. */
18546 && saved_x
+ FRAME_COLUMN_WIDTH (it
->f
) < it
->last_visible_x
)
18547 it
->end_of_box_run_p
= 0;
18549 PRODUCE_GLYPHS (it
);
18551 it
->override_ascent
= -1;
18552 it
->constrain_row_ascent_descent_p
= 0;
18553 it
->current_x
= saved_x
;
18554 it
->object
= saved_object
;
18555 it
->position
= saved_pos
;
18556 it
->what
= saved_what
;
18557 it
->face_id
= saved_face_id
;
18558 it
->len
= saved_len
;
18560 it
->char_to_display
= saved_char_to_display
;
18561 it
->end_of_box_run_p
= saved_box_end
;
18570 /* Extend the face of the last glyph in the text area of IT->glyph_row
18571 to the end of the display line. Called from display_line. If the
18572 glyph row is empty, add a space glyph to it so that we know the
18573 face to draw. Set the glyph row flag fill_line_p. If the glyph
18574 row is R2L, prepend a stretch glyph to cover the empty space to the
18575 left of the leftmost glyph. */
18578 extend_face_to_end_of_line (struct it
*it
)
18580 struct face
*face
, *default_face
;
18581 struct frame
*f
= it
->f
;
18583 /* If line is already filled, do nothing. Non window-system frames
18584 get a grace of one more ``pixel'' because their characters are
18585 1-``pixel'' wide, so they hit the equality too early. This grace
18586 is needed only for R2L rows that are not continued, to produce
18587 one extra blank where we could display the cursor. */
18588 if (it
->current_x
>= it
->last_visible_x
18589 + (!FRAME_WINDOW_P (f
)
18590 && it
->glyph_row
->reversed_p
18591 && !it
->glyph_row
->continued_p
))
18594 /* The default face, possibly remapped. */
18595 default_face
= FACE_FROM_ID (f
, lookup_basic_face (f
, DEFAULT_FACE_ID
));
18597 /* Face extension extends the background and box of IT->face_id
18598 to the end of the line. If the background equals the background
18599 of the frame, we don't have to do anything. */
18600 if (it
->face_before_selective_p
)
18601 face
= FACE_FROM_ID (f
, it
->saved_face_id
);
18603 face
= FACE_FROM_ID (f
, it
->face_id
);
18605 if (FRAME_WINDOW_P (f
)
18606 && it
->glyph_row
->displays_text_p
18607 && face
->box
== FACE_NO_BOX
18608 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
18610 && !it
->glyph_row
->reversed_p
)
18613 /* Set the glyph row flag indicating that the face of the last glyph
18614 in the text area has to be drawn to the end of the text area. */
18615 it
->glyph_row
->fill_line_p
= 1;
18617 /* If current character of IT is not ASCII, make sure we have the
18618 ASCII face. This will be automatically undone the next time
18619 get_next_display_element returns a multibyte character. Note
18620 that the character will always be single byte in unibyte
18622 if (!ASCII_CHAR_P (it
->c
))
18624 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
18627 if (FRAME_WINDOW_P (f
))
18629 /* If the row is empty, add a space with the current face of IT,
18630 so that we know which face to draw. */
18631 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
18633 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
18634 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= face
->id
;
18635 it
->glyph_row
->used
[TEXT_AREA
] = 1;
18637 #ifdef HAVE_WINDOW_SYSTEM
18638 if (it
->glyph_row
->reversed_p
)
18640 /* Prepend a stretch glyph to the row, such that the
18641 rightmost glyph will be drawn flushed all the way to the
18642 right margin of the window. The stretch glyph that will
18643 occupy the empty space, if any, to the left of the
18645 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (f
);
18646 struct glyph
*row_start
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18647 struct glyph
*row_end
= row_start
+ it
->glyph_row
->used
[TEXT_AREA
];
18649 int row_width
, stretch_ascent
, stretch_width
;
18650 struct text_pos saved_pos
;
18651 int saved_face_id
, saved_avoid_cursor
, saved_box_start
;
18653 for (row_width
= 0, g
= row_start
; g
< row_end
; g
++)
18654 row_width
+= g
->pixel_width
;
18655 stretch_width
= window_box_width (it
->w
, TEXT_AREA
) - row_width
;
18656 if (stretch_width
> 0)
18659 (((it
->ascent
+ it
->descent
)
18660 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
18661 saved_pos
= it
->position
;
18662 memset (&it
->position
, 0, sizeof it
->position
);
18663 saved_avoid_cursor
= it
->avoid_cursor_p
;
18664 it
->avoid_cursor_p
= 1;
18665 saved_face_id
= it
->face_id
;
18666 saved_box_start
= it
->start_of_box_run_p
;
18667 /* The last row's stretch glyph should get the default
18668 face, to avoid painting the rest of the window with
18669 the region face, if the region ends at ZV. */
18670 if (it
->glyph_row
->ends_at_zv_p
)
18671 it
->face_id
= default_face
->id
;
18673 it
->face_id
= face
->id
;
18674 it
->start_of_box_run_p
= 0;
18675 append_stretch_glyph (it
, make_number (0), stretch_width
,
18676 it
->ascent
+ it
->descent
, stretch_ascent
);
18677 it
->position
= saved_pos
;
18678 it
->avoid_cursor_p
= saved_avoid_cursor
;
18679 it
->face_id
= saved_face_id
;
18680 it
->start_of_box_run_p
= saved_box_start
;
18683 #endif /* HAVE_WINDOW_SYSTEM */
18687 /* Save some values that must not be changed. */
18688 int saved_x
= it
->current_x
;
18689 struct text_pos saved_pos
;
18690 Lisp_Object saved_object
;
18691 enum display_element_type saved_what
= it
->what
;
18692 int saved_face_id
= it
->face_id
;
18694 saved_object
= it
->object
;
18695 saved_pos
= it
->position
;
18697 it
->what
= IT_CHARACTER
;
18698 memset (&it
->position
, 0, sizeof it
->position
);
18699 it
->object
= make_number (0);
18700 it
->c
= it
->char_to_display
= ' ';
18702 /* The last row's blank glyphs should get the default face, to
18703 avoid painting the rest of the window with the region face,
18704 if the region ends at ZV. */
18705 if (it
->glyph_row
->ends_at_zv_p
)
18706 it
->face_id
= default_face
->id
;
18708 it
->face_id
= face
->id
;
18710 PRODUCE_GLYPHS (it
);
18712 while (it
->current_x
<= it
->last_visible_x
)
18713 PRODUCE_GLYPHS (it
);
18715 /* Don't count these blanks really. It would let us insert a left
18716 truncation glyph below and make us set the cursor on them, maybe. */
18717 it
->current_x
= saved_x
;
18718 it
->object
= saved_object
;
18719 it
->position
= saved_pos
;
18720 it
->what
= saved_what
;
18721 it
->face_id
= saved_face_id
;
18726 /* Value is non-zero if text starting at CHARPOS in current_buffer is
18727 trailing whitespace. */
18730 trailing_whitespace_p (ptrdiff_t charpos
)
18732 ptrdiff_t bytepos
= CHAR_TO_BYTE (charpos
);
18735 while (bytepos
< ZV_BYTE
18736 && (c
= FETCH_CHAR (bytepos
),
18737 c
== ' ' || c
== '\t'))
18740 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
18742 if (bytepos
!= PT_BYTE
)
18749 /* Highlight trailing whitespace, if any, in ROW. */
18752 highlight_trailing_whitespace (struct frame
*f
, struct glyph_row
*row
)
18754 int used
= row
->used
[TEXT_AREA
];
18758 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
18759 struct glyph
*glyph
= start
+ used
- 1;
18761 if (row
->reversed_p
)
18763 /* Right-to-left rows need to be processed in the opposite
18764 direction, so swap the edge pointers. */
18766 start
= row
->glyphs
[TEXT_AREA
] + used
- 1;
18769 /* Skip over glyphs inserted to display the cursor at the
18770 end of a line, for extending the face of the last glyph
18771 to the end of the line on terminals, and for truncation
18772 and continuation glyphs. */
18773 if (!row
->reversed_p
)
18775 while (glyph
>= start
18776 && glyph
->type
== CHAR_GLYPH
18777 && INTEGERP (glyph
->object
))
18782 while (glyph
<= start
18783 && glyph
->type
== CHAR_GLYPH
18784 && INTEGERP (glyph
->object
))
18788 /* If last glyph is a space or stretch, and it's trailing
18789 whitespace, set the face of all trailing whitespace glyphs in
18790 IT->glyph_row to `trailing-whitespace'. */
18791 if ((row
->reversed_p
? glyph
<= start
: glyph
>= start
)
18792 && BUFFERP (glyph
->object
)
18793 && (glyph
->type
== STRETCH_GLYPH
18794 || (glyph
->type
== CHAR_GLYPH
18795 && glyph
->u
.ch
== ' '))
18796 && trailing_whitespace_p (glyph
->charpos
))
18798 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
18802 if (!row
->reversed_p
)
18804 while (glyph
>= start
18805 && BUFFERP (glyph
->object
)
18806 && (glyph
->type
== STRETCH_GLYPH
18807 || (glyph
->type
== CHAR_GLYPH
18808 && glyph
->u
.ch
== ' ')))
18809 (glyph
--)->face_id
= face_id
;
18813 while (glyph
<= start
18814 && BUFFERP (glyph
->object
)
18815 && (glyph
->type
== STRETCH_GLYPH
18816 || (glyph
->type
== CHAR_GLYPH
18817 && glyph
->u
.ch
== ' ')))
18818 (glyph
++)->face_id
= face_id
;
18825 /* Value is non-zero if glyph row ROW should be
18826 used to hold the cursor. */
18829 cursor_row_p (struct glyph_row
*row
)
18833 if (PT
== CHARPOS (row
->end
.pos
)
18834 || PT
== MATRIX_ROW_END_CHARPOS (row
))
18836 /* Suppose the row ends on a string.
18837 Unless the row is continued, that means it ends on a newline
18838 in the string. If it's anything other than a display string
18839 (e.g., a before-string from an overlay), we don't want the
18840 cursor there. (This heuristic seems to give the optimal
18841 behavior for the various types of multi-line strings.)
18842 One exception: if the string has `cursor' property on one of
18843 its characters, we _do_ want the cursor there. */
18844 if (CHARPOS (row
->end
.string_pos
) >= 0)
18846 if (row
->continued_p
)
18850 /* Check for `display' property. */
18851 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
18852 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
18853 struct glyph
*glyph
;
18856 for (glyph
= end
; glyph
>= beg
; --glyph
)
18857 if (STRINGP (glyph
->object
))
18860 = Fget_char_property (make_number (PT
),
18864 && display_prop_string_p (prop
, glyph
->object
));
18865 /* If there's a `cursor' property on one of the
18866 string's characters, this row is a cursor row,
18867 even though this is not a display string. */
18870 Lisp_Object s
= glyph
->object
;
18872 for ( ; glyph
>= beg
&& EQ (glyph
->object
, s
); --glyph
)
18874 ptrdiff_t gpos
= glyph
->charpos
;
18876 if (!NILP (Fget_char_property (make_number (gpos
),
18888 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
18890 /* If the row ends in middle of a real character,
18891 and the line is continued, we want the cursor here.
18892 That's because CHARPOS (ROW->end.pos) would equal
18893 PT if PT is before the character. */
18894 if (!row
->ends_in_ellipsis_p
)
18895 result
= row
->continued_p
;
18897 /* If the row ends in an ellipsis, then
18898 CHARPOS (ROW->end.pos) will equal point after the
18899 invisible text. We want that position to be displayed
18900 after the ellipsis. */
18903 /* If the row ends at ZV, display the cursor at the end of that
18904 row instead of at the start of the row below. */
18905 else if (row
->ends_at_zv_p
)
18916 /* Push the property PROP so that it will be rendered at the current
18917 position in IT. Return 1 if PROP was successfully pushed, 0
18918 otherwise. Called from handle_line_prefix to handle the
18919 `line-prefix' and `wrap-prefix' properties. */
18922 push_prefix_prop (struct it
*it
, Lisp_Object prop
)
18924 struct text_pos pos
=
18925 STRINGP (it
->string
) ? it
->current
.string_pos
: it
->current
.pos
;
18927 eassert (it
->method
== GET_FROM_BUFFER
18928 || it
->method
== GET_FROM_DISPLAY_VECTOR
18929 || it
->method
== GET_FROM_STRING
);
18931 /* We need to save the current buffer/string position, so it will be
18932 restored by pop_it, because iterate_out_of_display_property
18933 depends on that being set correctly, but some situations leave
18934 it->position not yet set when this function is called. */
18935 push_it (it
, &pos
);
18937 if (STRINGP (prop
))
18939 if (SCHARS (prop
) == 0)
18946 it
->string_from_prefix_prop_p
= 1;
18947 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
18948 it
->current
.overlay_string_index
= -1;
18949 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
18950 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
18951 it
->method
= GET_FROM_STRING
;
18952 it
->stop_charpos
= 0;
18954 it
->base_level_stop
= 0;
18956 /* Force paragraph direction to be that of the parent
18958 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
18959 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
18961 it
->paragraph_embedding
= L2R
;
18963 /* Set up the bidi iterator for this display string. */
18966 it
->bidi_it
.string
.lstring
= it
->string
;
18967 it
->bidi_it
.string
.s
= NULL
;
18968 it
->bidi_it
.string
.schars
= it
->end_charpos
;
18969 it
->bidi_it
.string
.bufpos
= IT_CHARPOS (*it
);
18970 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
18971 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
18972 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
18975 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
18977 it
->method
= GET_FROM_STRETCH
;
18980 #ifdef HAVE_WINDOW_SYSTEM
18981 else if (IMAGEP (prop
))
18983 it
->what
= IT_IMAGE
;
18984 it
->image_id
= lookup_image (it
->f
, prop
);
18985 it
->method
= GET_FROM_IMAGE
;
18987 #endif /* HAVE_WINDOW_SYSTEM */
18990 pop_it (it
); /* bogus display property, give up */
18997 /* Return the character-property PROP at the current position in IT. */
19000 get_it_property (struct it
*it
, Lisp_Object prop
)
19002 Lisp_Object position
;
19004 if (STRINGP (it
->object
))
19005 position
= make_number (IT_STRING_CHARPOS (*it
));
19006 else if (BUFFERP (it
->object
))
19007 position
= make_number (IT_CHARPOS (*it
));
19011 return Fget_char_property (position
, prop
, it
->object
);
19014 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
19017 handle_line_prefix (struct it
*it
)
19019 Lisp_Object prefix
;
19021 if (it
->continuation_lines_width
> 0)
19023 prefix
= get_it_property (it
, Qwrap_prefix
);
19025 prefix
= Vwrap_prefix
;
19029 prefix
= get_it_property (it
, Qline_prefix
);
19031 prefix
= Vline_prefix
;
19033 if (! NILP (prefix
) && push_prefix_prop (it
, prefix
))
19035 /* If the prefix is wider than the window, and we try to wrap
19036 it, it would acquire its own wrap prefix, and so on till the
19037 iterator stack overflows. So, don't wrap the prefix. */
19038 it
->line_wrap
= TRUNCATE
;
19039 it
->avoid_cursor_p
= 1;
19045 /* Remove N glyphs at the start of a reversed IT->glyph_row. Called
19046 only for R2L lines from display_line and display_string, when they
19047 decide that too many glyphs were produced by PRODUCE_GLYPHS, and
19048 the line/string needs to be continued on the next glyph row. */
19050 unproduce_glyphs (struct it
*it
, int n
)
19052 struct glyph
*glyph
, *end
;
19054 eassert (it
->glyph_row
);
19055 eassert (it
->glyph_row
->reversed_p
);
19056 eassert (it
->area
== TEXT_AREA
);
19057 eassert (n
<= it
->glyph_row
->used
[TEXT_AREA
]);
19059 if (n
> it
->glyph_row
->used
[TEXT_AREA
])
19060 n
= it
->glyph_row
->used
[TEXT_AREA
];
19061 glyph
= it
->glyph_row
->glyphs
[TEXT_AREA
] + n
;
19062 end
= it
->glyph_row
->glyphs
[TEXT_AREA
] + it
->glyph_row
->used
[TEXT_AREA
];
19063 for ( ; glyph
< end
; glyph
++)
19064 glyph
[-n
] = *glyph
;
19067 /* Find the positions in a bidi-reordered ROW to serve as ROW->minpos
19068 and ROW->maxpos. */
19070 find_row_edges (struct it
*it
, struct glyph_row
*row
,
19071 ptrdiff_t min_pos
, ptrdiff_t min_bpos
,
19072 ptrdiff_t max_pos
, ptrdiff_t max_bpos
)
19074 /* FIXME: Revisit this when glyph ``spilling'' in continuation
19075 lines' rows is implemented for bidi-reordered rows. */
19077 /* ROW->minpos is the value of min_pos, the minimal buffer position
19078 we have in ROW, or ROW->start.pos if that is smaller. */
19079 if (min_pos
<= ZV
&& min_pos
< row
->start
.pos
.charpos
)
19080 SET_TEXT_POS (row
->minpos
, min_pos
, min_bpos
);
19082 /* We didn't find buffer positions smaller than ROW->start, or
19083 didn't find _any_ valid buffer positions in any of the glyphs,
19084 so we must trust the iterator's computed positions. */
19085 row
->minpos
= row
->start
.pos
;
19088 max_pos
= CHARPOS (it
->current
.pos
);
19089 max_bpos
= BYTEPOS (it
->current
.pos
);
19092 /* Here are the various use-cases for ending the row, and the
19093 corresponding values for ROW->maxpos:
19095 Line ends in a newline from buffer eol_pos + 1
19096 Line is continued from buffer max_pos + 1
19097 Line is truncated on right it->current.pos
19098 Line ends in a newline from string max_pos + 1(*)
19099 (*) + 1 only when line ends in a forward scan
19100 Line is continued from string max_pos
19101 Line is continued from display vector max_pos
19102 Line is entirely from a string min_pos == max_pos
19103 Line is entirely from a display vector min_pos == max_pos
19104 Line that ends at ZV ZV
19106 If you discover other use-cases, please add them here as
19108 if (row
->ends_at_zv_p
)
19109 row
->maxpos
= it
->current
.pos
;
19110 else if (row
->used
[TEXT_AREA
])
19112 int seen_this_string
= 0;
19113 struct glyph_row
*r1
= row
- 1;
19115 /* Did we see the same display string on the previous row? */
19116 if (STRINGP (it
->object
)
19117 /* this is not the first row */
19118 && row
> it
->w
->desired_matrix
->rows
19119 /* previous row is not the header line */
19120 && !r1
->mode_line_p
19121 /* previous row also ends in a newline from a string */
19122 && r1
->ends_in_newline_from_string_p
)
19124 struct glyph
*start
, *end
;
19126 /* Search for the last glyph of the previous row that came
19127 from buffer or string. Depending on whether the row is
19128 L2R or R2L, we need to process it front to back or the
19129 other way round. */
19130 if (!r1
->reversed_p
)
19132 start
= r1
->glyphs
[TEXT_AREA
];
19133 end
= start
+ r1
->used
[TEXT_AREA
];
19134 /* Glyphs inserted by redisplay have an integer (zero)
19135 as their object. */
19137 && INTEGERP ((end
- 1)->object
)
19138 && (end
- 1)->charpos
<= 0)
19142 if (EQ ((end
- 1)->object
, it
->object
))
19143 seen_this_string
= 1;
19146 /* If all the glyphs of the previous row were inserted
19147 by redisplay, it means the previous row was
19148 produced from a single newline, which is only
19149 possible if that newline came from the same string
19150 as the one which produced this ROW. */
19151 seen_this_string
= 1;
19155 end
= r1
->glyphs
[TEXT_AREA
] - 1;
19156 start
= end
+ r1
->used
[TEXT_AREA
];
19158 && INTEGERP ((end
+ 1)->object
)
19159 && (end
+ 1)->charpos
<= 0)
19163 if (EQ ((end
+ 1)->object
, it
->object
))
19164 seen_this_string
= 1;
19167 seen_this_string
= 1;
19170 /* Take note of each display string that covers a newline only
19171 once, the first time we see it. This is for when a display
19172 string includes more than one newline in it. */
19173 if (row
->ends_in_newline_from_string_p
&& !seen_this_string
)
19175 /* If we were scanning the buffer forward when we displayed
19176 the string, we want to account for at least one buffer
19177 position that belongs to this row (position covered by
19178 the display string), so that cursor positioning will
19179 consider this row as a candidate when point is at the end
19180 of the visual line represented by this row. This is not
19181 required when scanning back, because max_pos will already
19182 have a much larger value. */
19183 if (CHARPOS (row
->end
.pos
) > max_pos
)
19184 INC_BOTH (max_pos
, max_bpos
);
19185 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19187 else if (CHARPOS (it
->eol_pos
) > 0)
19188 SET_TEXT_POS (row
->maxpos
,
19189 CHARPOS (it
->eol_pos
) + 1, BYTEPOS (it
->eol_pos
) + 1);
19190 else if (row
->continued_p
)
19192 /* If max_pos is different from IT's current position, it
19193 means IT->method does not belong to the display element
19194 at max_pos. However, it also means that the display
19195 element at max_pos was displayed in its entirety on this
19196 line, which is equivalent to saying that the next line
19197 starts at the next buffer position. */
19198 if (IT_CHARPOS (*it
) == max_pos
&& it
->method
!= GET_FROM_BUFFER
)
19199 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19202 INC_BOTH (max_pos
, max_bpos
);
19203 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19206 else if (row
->truncated_on_right_p
)
19207 /* display_line already called reseat_at_next_visible_line_start,
19208 which puts the iterator at the beginning of the next line, in
19209 the logical order. */
19210 row
->maxpos
= it
->current
.pos
;
19211 else if (max_pos
== min_pos
&& it
->method
!= GET_FROM_BUFFER
)
19212 /* A line that is entirely from a string/image/stretch... */
19213 row
->maxpos
= row
->minpos
;
19218 row
->maxpos
= it
->current
.pos
;
19221 /* Construct the glyph row IT->glyph_row in the desired matrix of
19222 IT->w from text at the current position of IT. See dispextern.h
19223 for an overview of struct it. Value is non-zero if
19224 IT->glyph_row displays text, as opposed to a line displaying ZV
19228 display_line (struct it
*it
)
19230 struct glyph_row
*row
= it
->glyph_row
;
19231 Lisp_Object overlay_arrow_string
;
19233 void *wrap_data
= NULL
;
19234 int may_wrap
= 0, wrap_x
IF_LINT (= 0);
19235 int wrap_row_used
= -1;
19236 int wrap_row_ascent
IF_LINT (= 0), wrap_row_height
IF_LINT (= 0);
19237 int wrap_row_phys_ascent
IF_LINT (= 0), wrap_row_phys_height
IF_LINT (= 0);
19238 int wrap_row_extra_line_spacing
IF_LINT (= 0);
19239 ptrdiff_t wrap_row_min_pos
IF_LINT (= 0), wrap_row_min_bpos
IF_LINT (= 0);
19240 ptrdiff_t wrap_row_max_pos
IF_LINT (= 0), wrap_row_max_bpos
IF_LINT (= 0);
19242 ptrdiff_t min_pos
= ZV
+ 1, max_pos
= 0;
19243 ptrdiff_t min_bpos
IF_LINT (= 0), max_bpos
IF_LINT (= 0);
19245 /* We always start displaying at hpos zero even if hscrolled. */
19246 eassert (it
->hpos
== 0 && it
->current_x
== 0);
19248 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
19249 >= it
->w
->desired_matrix
->nrows
)
19251 it
->w
->nrows_scale_factor
++;
19252 fonts_changed_p
= 1;
19256 /* Is IT->w showing the region? */
19257 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? it
->region_beg_charpos
: 0;
19259 /* Clear the result glyph row and enable it. */
19260 prepare_desired_row (row
);
19262 row
->y
= it
->current_y
;
19263 row
->start
= it
->start
;
19264 row
->continuation_lines_width
= it
->continuation_lines_width
;
19265 row
->displays_text_p
= 1;
19266 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
19267 it
->starts_in_middle_of_char_p
= 0;
19269 /* Arrange the overlays nicely for our purposes. Usually, we call
19270 display_line on only one line at a time, in which case this
19271 can't really hurt too much, or we call it on lines which appear
19272 one after another in the buffer, in which case all calls to
19273 recenter_overlay_lists but the first will be pretty cheap. */
19274 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
19276 /* Move over display elements that are not visible because we are
19277 hscrolled. This may stop at an x-position < IT->first_visible_x
19278 if the first glyph is partially visible or if we hit a line end. */
19279 if (it
->current_x
< it
->first_visible_x
)
19281 enum move_it_result move_result
;
19283 this_line_min_pos
= row
->start
.pos
;
19284 move_result
= move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
19285 MOVE_TO_POS
| MOVE_TO_X
);
19286 /* If we are under a large hscroll, move_it_in_display_line_to
19287 could hit the end of the line without reaching
19288 it->first_visible_x. Pretend that we did reach it. This is
19289 especially important on a TTY, where we will call
19290 extend_face_to_end_of_line, which needs to know how many
19291 blank glyphs to produce. */
19292 if (it
->current_x
< it
->first_visible_x
19293 && (move_result
== MOVE_NEWLINE_OR_CR
19294 || move_result
== MOVE_POS_MATCH_OR_ZV
))
19295 it
->current_x
= it
->first_visible_x
;
19297 /* Record the smallest positions seen while we moved over
19298 display elements that are not visible. This is needed by
19299 redisplay_internal for optimizing the case where the cursor
19300 stays inside the same line. The rest of this function only
19301 considers positions that are actually displayed, so
19302 RECORD_MAX_MIN_POS will not otherwise record positions that
19303 are hscrolled to the left of the left edge of the window. */
19304 min_pos
= CHARPOS (this_line_min_pos
);
19305 min_bpos
= BYTEPOS (this_line_min_pos
);
19309 /* We only do this when not calling `move_it_in_display_line_to'
19310 above, because move_it_in_display_line_to calls
19311 handle_line_prefix itself. */
19312 handle_line_prefix (it
);
19315 /* Get the initial row height. This is either the height of the
19316 text hscrolled, if there is any, or zero. */
19317 row
->ascent
= it
->max_ascent
;
19318 row
->height
= it
->max_ascent
+ it
->max_descent
;
19319 row
->phys_ascent
= it
->max_phys_ascent
;
19320 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
19321 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
19323 /* Utility macro to record max and min buffer positions seen until now. */
19324 #define RECORD_MAX_MIN_POS(IT) \
19327 int composition_p = !STRINGP ((IT)->string) \
19328 && ((IT)->what == IT_COMPOSITION); \
19329 ptrdiff_t current_pos = \
19330 composition_p ? (IT)->cmp_it.charpos \
19331 : IT_CHARPOS (*(IT)); \
19332 ptrdiff_t current_bpos = \
19333 composition_p ? CHAR_TO_BYTE (current_pos) \
19334 : IT_BYTEPOS (*(IT)); \
19335 if (current_pos < min_pos) \
19337 min_pos = current_pos; \
19338 min_bpos = current_bpos; \
19340 if (IT_CHARPOS (*it) > max_pos) \
19342 max_pos = IT_CHARPOS (*it); \
19343 max_bpos = IT_BYTEPOS (*it); \
19348 /* Loop generating characters. The loop is left with IT on the next
19349 character to display. */
19352 int n_glyphs_before
, hpos_before
, x_before
;
19354 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
19356 /* Retrieve the next thing to display. Value is zero if end of
19358 if (!get_next_display_element (it
))
19360 /* Maybe add a space at the end of this line that is used to
19361 display the cursor there under X. Set the charpos of the
19362 first glyph of blank lines not corresponding to any text
19364 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19365 row
->exact_window_width_line_p
= 1;
19366 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
19367 || row
->used
[TEXT_AREA
] == 0)
19369 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
19370 row
->displays_text_p
= 0;
19372 if (!NILP (BVAR (XBUFFER (it
->w
->buffer
), indicate_empty_lines
))
19373 && (!MINI_WINDOW_P (it
->w
)
19374 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
19375 row
->indicate_empty_line_p
= 1;
19378 it
->continuation_lines_width
= 0;
19379 row
->ends_at_zv_p
= 1;
19380 /* A row that displays right-to-left text must always have
19381 its last face extended all the way to the end of line,
19382 even if this row ends in ZV, because we still write to
19383 the screen left to right. We also need to extend the
19384 last face if the default face is remapped to some
19385 different face, otherwise the functions that clear
19386 portions of the screen will clear with the default face's
19387 background color. */
19388 if (row
->reversed_p
19389 || lookup_basic_face (it
->f
, DEFAULT_FACE_ID
) != DEFAULT_FACE_ID
)
19390 extend_face_to_end_of_line (it
);
19394 /* Now, get the metrics of what we want to display. This also
19395 generates glyphs in `row' (which is IT->glyph_row). */
19396 n_glyphs_before
= row
->used
[TEXT_AREA
];
19399 /* Remember the line height so far in case the next element doesn't
19400 fit on the line. */
19401 if (it
->line_wrap
!= TRUNCATE
)
19403 ascent
= it
->max_ascent
;
19404 descent
= it
->max_descent
;
19405 phys_ascent
= it
->max_phys_ascent
;
19406 phys_descent
= it
->max_phys_descent
;
19408 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
19410 if (IT_DISPLAYING_WHITESPACE (it
))
19414 SAVE_IT (wrap_it
, *it
, wrap_data
);
19416 wrap_row_used
= row
->used
[TEXT_AREA
];
19417 wrap_row_ascent
= row
->ascent
;
19418 wrap_row_height
= row
->height
;
19419 wrap_row_phys_ascent
= row
->phys_ascent
;
19420 wrap_row_phys_height
= row
->phys_height
;
19421 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
19422 wrap_row_min_pos
= min_pos
;
19423 wrap_row_min_bpos
= min_bpos
;
19424 wrap_row_max_pos
= max_pos
;
19425 wrap_row_max_bpos
= max_bpos
;
19431 PRODUCE_GLYPHS (it
);
19433 /* If this display element was in marginal areas, continue with
19435 if (it
->area
!= TEXT_AREA
)
19437 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19438 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19439 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19440 row
->phys_height
= max (row
->phys_height
,
19441 it
->max_phys_ascent
+ it
->max_phys_descent
);
19442 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19443 it
->max_extra_line_spacing
);
19444 set_iterator_to_next (it
, 1);
19448 /* Does the display element fit on the line? If we truncate
19449 lines, we should draw past the right edge of the window. If
19450 we don't truncate, we want to stop so that we can display the
19451 continuation glyph before the right margin. If lines are
19452 continued, there are two possible strategies for characters
19453 resulting in more than 1 glyph (e.g. tabs): Display as many
19454 glyphs as possible in this line and leave the rest for the
19455 continuation line, or display the whole element in the next
19456 line. Original redisplay did the former, so we do it also. */
19457 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
19458 hpos_before
= it
->hpos
;
19461 if (/* Not a newline. */
19463 /* Glyphs produced fit entirely in the line. */
19464 && it
->current_x
< it
->last_visible_x
)
19466 it
->hpos
+= nglyphs
;
19467 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19468 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19469 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19470 row
->phys_height
= max (row
->phys_height
,
19471 it
->max_phys_ascent
+ it
->max_phys_descent
);
19472 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19473 it
->max_extra_line_spacing
);
19474 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
19475 row
->x
= x
- it
->first_visible_x
;
19476 /* Record the maximum and minimum buffer positions seen so
19477 far in glyphs that will be displayed by this row. */
19479 RECORD_MAX_MIN_POS (it
);
19484 struct glyph
*glyph
;
19486 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
19488 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
19489 new_x
= x
+ glyph
->pixel_width
;
19491 if (/* Lines are continued. */
19492 it
->line_wrap
!= TRUNCATE
19493 && (/* Glyph doesn't fit on the line. */
19494 new_x
> it
->last_visible_x
19495 /* Or it fits exactly on a window system frame. */
19496 || (new_x
== it
->last_visible_x
19497 && FRAME_WINDOW_P (it
->f
)
19498 && (row
->reversed_p
19499 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19500 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
19502 /* End of a continued line. */
19505 || (new_x
== it
->last_visible_x
19506 && FRAME_WINDOW_P (it
->f
)
19507 && (row
->reversed_p
19508 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19509 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
))))
19511 /* Current glyph is the only one on the line or
19512 fits exactly on the line. We must continue
19513 the line because we can't draw the cursor
19514 after the glyph. */
19515 row
->continued_p
= 1;
19516 it
->current_x
= new_x
;
19517 it
->continuation_lines_width
+= new_x
;
19519 if (i
== nglyphs
- 1)
19521 /* If line-wrap is on, check if a previous
19522 wrap point was found. */
19523 if (wrap_row_used
> 0
19524 /* Even if there is a previous wrap
19525 point, continue the line here as
19526 usual, if (i) the previous character
19527 was a space or tab AND (ii) the
19528 current character is not. */
19530 || IT_DISPLAYING_WHITESPACE (it
)))
19533 /* Record the maximum and minimum buffer
19534 positions seen so far in glyphs that will be
19535 displayed by this row. */
19537 RECORD_MAX_MIN_POS (it
);
19538 set_iterator_to_next (it
, 1);
19539 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19541 if (!get_next_display_element (it
))
19543 row
->exact_window_width_line_p
= 1;
19544 it
->continuation_lines_width
= 0;
19545 row
->continued_p
= 0;
19546 row
->ends_at_zv_p
= 1;
19548 else if (ITERATOR_AT_END_OF_LINE_P (it
))
19550 row
->continued_p
= 0;
19551 row
->exact_window_width_line_p
= 1;
19555 else if (it
->bidi_p
)
19556 RECORD_MAX_MIN_POS (it
);
19558 else if (CHAR_GLYPH_PADDING_P (*glyph
)
19559 && !FRAME_WINDOW_P (it
->f
))
19561 /* A padding glyph that doesn't fit on this line.
19562 This means the whole character doesn't fit
19564 if (row
->reversed_p
)
19565 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19566 - n_glyphs_before
);
19567 row
->used
[TEXT_AREA
] = n_glyphs_before
;
19569 /* Fill the rest of the row with continuation
19570 glyphs like in 20.x. */
19571 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
19572 < row
->glyphs
[1 + TEXT_AREA
])
19573 produce_special_glyphs (it
, IT_CONTINUATION
);
19575 row
->continued_p
= 1;
19576 it
->current_x
= x_before
;
19577 it
->continuation_lines_width
+= x_before
;
19579 /* Restore the height to what it was before the
19580 element not fitting on the line. */
19581 it
->max_ascent
= ascent
;
19582 it
->max_descent
= descent
;
19583 it
->max_phys_ascent
= phys_ascent
;
19584 it
->max_phys_descent
= phys_descent
;
19586 else if (wrap_row_used
> 0)
19589 if (row
->reversed_p
)
19590 unproduce_glyphs (it
,
19591 row
->used
[TEXT_AREA
] - wrap_row_used
);
19592 RESTORE_IT (it
, &wrap_it
, wrap_data
);
19593 it
->continuation_lines_width
+= wrap_x
;
19594 row
->used
[TEXT_AREA
] = wrap_row_used
;
19595 row
->ascent
= wrap_row_ascent
;
19596 row
->height
= wrap_row_height
;
19597 row
->phys_ascent
= wrap_row_phys_ascent
;
19598 row
->phys_height
= wrap_row_phys_height
;
19599 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
19600 min_pos
= wrap_row_min_pos
;
19601 min_bpos
= wrap_row_min_bpos
;
19602 max_pos
= wrap_row_max_pos
;
19603 max_bpos
= wrap_row_max_bpos
;
19604 row
->continued_p
= 1;
19605 row
->ends_at_zv_p
= 0;
19606 row
->exact_window_width_line_p
= 0;
19607 it
->continuation_lines_width
+= x
;
19609 /* Make sure that a non-default face is extended
19610 up to the right margin of the window. */
19611 extend_face_to_end_of_line (it
);
19613 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
19615 /* A TAB that extends past the right edge of the
19616 window. This produces a single glyph on
19617 window system frames. We leave the glyph in
19618 this row and let it fill the row, but don't
19619 consume the TAB. */
19620 if ((row
->reversed_p
19621 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19622 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19623 produce_special_glyphs (it
, IT_CONTINUATION
);
19624 it
->continuation_lines_width
+= it
->last_visible_x
;
19625 row
->ends_in_middle_of_char_p
= 1;
19626 row
->continued_p
= 1;
19627 glyph
->pixel_width
= it
->last_visible_x
- x
;
19628 it
->starts_in_middle_of_char_p
= 1;
19632 /* Something other than a TAB that draws past
19633 the right edge of the window. Restore
19634 positions to values before the element. */
19635 if (row
->reversed_p
)
19636 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19637 - (n_glyphs_before
+ i
));
19638 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
19640 /* Display continuation glyphs. */
19641 it
->current_x
= x_before
;
19642 it
->continuation_lines_width
+= x
;
19643 if (!FRAME_WINDOW_P (it
->f
)
19644 || (row
->reversed_p
19645 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19646 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19647 produce_special_glyphs (it
, IT_CONTINUATION
);
19648 row
->continued_p
= 1;
19650 extend_face_to_end_of_line (it
);
19652 if (nglyphs
> 1 && i
> 0)
19654 row
->ends_in_middle_of_char_p
= 1;
19655 it
->starts_in_middle_of_char_p
= 1;
19658 /* Restore the height to what it was before the
19659 element not fitting on the line. */
19660 it
->max_ascent
= ascent
;
19661 it
->max_descent
= descent
;
19662 it
->max_phys_ascent
= phys_ascent
;
19663 it
->max_phys_descent
= phys_descent
;
19668 else if (new_x
> it
->first_visible_x
)
19670 /* Increment number of glyphs actually displayed. */
19673 /* Record the maximum and minimum buffer positions
19674 seen so far in glyphs that will be displayed by
19677 RECORD_MAX_MIN_POS (it
);
19679 if (x
< it
->first_visible_x
)
19680 /* Glyph is partially visible, i.e. row starts at
19681 negative X position. */
19682 row
->x
= x
- it
->first_visible_x
;
19686 /* Glyph is completely off the left margin of the
19687 window. This should not happen because of the
19688 move_it_in_display_line at the start of this
19689 function, unless the text display area of the
19690 window is empty. */
19691 eassert (it
->first_visible_x
<= it
->last_visible_x
);
19694 /* Even if this display element produced no glyphs at all,
19695 we want to record its position. */
19696 if (it
->bidi_p
&& nglyphs
== 0)
19697 RECORD_MAX_MIN_POS (it
);
19699 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19700 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19701 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19702 row
->phys_height
= max (row
->phys_height
,
19703 it
->max_phys_ascent
+ it
->max_phys_descent
);
19704 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19705 it
->max_extra_line_spacing
);
19707 /* End of this display line if row is continued. */
19708 if (row
->continued_p
|| row
->ends_at_zv_p
)
19713 /* Is this a line end? If yes, we're also done, after making
19714 sure that a non-default face is extended up to the right
19715 margin of the window. */
19716 if (ITERATOR_AT_END_OF_LINE_P (it
))
19718 int used_before
= row
->used
[TEXT_AREA
];
19720 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
19722 /* Add a space at the end of the line that is used to
19723 display the cursor there. */
19724 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19725 append_space_for_newline (it
, 0);
19727 /* Extend the face to the end of the line. */
19728 extend_face_to_end_of_line (it
);
19730 /* Make sure we have the position. */
19731 if (used_before
== 0)
19732 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
19734 /* Record the position of the newline, for use in
19736 it
->eol_pos
= it
->current
.pos
;
19738 /* Consume the line end. This skips over invisible lines. */
19739 set_iterator_to_next (it
, 1);
19740 it
->continuation_lines_width
= 0;
19744 /* Proceed with next display element. Note that this skips
19745 over lines invisible because of selective display. */
19746 set_iterator_to_next (it
, 1);
19748 /* If we truncate lines, we are done when the last displayed
19749 glyphs reach past the right margin of the window. */
19750 if (it
->line_wrap
== TRUNCATE
19751 && (FRAME_WINDOW_P (it
->f
) && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
19752 ? (it
->current_x
>= it
->last_visible_x
)
19753 : (it
->current_x
> it
->last_visible_x
)))
19755 /* Maybe add truncation glyphs. */
19756 if (!FRAME_WINDOW_P (it
->f
)
19757 || (row
->reversed_p
19758 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19759 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19763 if (!row
->reversed_p
)
19765 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
19766 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19771 for (i
= 0; i
< row
->used
[TEXT_AREA
]; i
++)
19772 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19774 /* Remove any padding glyphs at the front of ROW, to
19775 make room for the truncation glyphs we will be
19776 adding below. The loop below always inserts at
19777 least one truncation glyph, so also remove the
19778 last glyph added to ROW. */
19779 unproduce_glyphs (it
, i
+ 1);
19780 /* Adjust i for the loop below. */
19781 i
= row
->used
[TEXT_AREA
] - (i
+ 1);
19784 it
->current_x
= x_before
;
19785 if (!FRAME_WINDOW_P (it
->f
))
19787 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
19789 row
->used
[TEXT_AREA
] = i
;
19790 produce_special_glyphs (it
, IT_TRUNCATION
);
19795 row
->used
[TEXT_AREA
] = i
;
19796 produce_special_glyphs (it
, IT_TRUNCATION
);
19799 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19801 /* Don't truncate if we can overflow newline into fringe. */
19802 if (!get_next_display_element (it
))
19804 it
->continuation_lines_width
= 0;
19805 row
->ends_at_zv_p
= 1;
19806 row
->exact_window_width_line_p
= 1;
19809 if (ITERATOR_AT_END_OF_LINE_P (it
))
19811 row
->exact_window_width_line_p
= 1;
19812 goto at_end_of_line
;
19814 it
->current_x
= x_before
;
19817 row
->truncated_on_right_p
= 1;
19818 it
->continuation_lines_width
= 0;
19819 reseat_at_next_visible_line_start (it
, 0);
19820 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
19821 it
->hpos
= hpos_before
;
19827 bidi_unshelve_cache (wrap_data
, 1);
19829 /* If line is not empty and hscrolled, maybe insert truncation glyphs
19830 at the left window margin. */
19831 if (it
->first_visible_x
19832 && IT_CHARPOS (*it
) != CHARPOS (row
->start
.pos
))
19834 if (!FRAME_WINDOW_P (it
->f
)
19835 || (row
->reversed_p
19836 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
19837 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
19838 insert_left_trunc_glyphs (it
);
19839 row
->truncated_on_left_p
= 1;
19842 /* Remember the position at which this line ends.
19844 BIDI Note: any code that needs MATRIX_ROW_START/END_CHARPOS
19845 cannot be before the call to find_row_edges below, since that is
19846 where these positions are determined. */
19847 row
->end
= it
->current
;
19850 row
->minpos
= row
->start
.pos
;
19851 row
->maxpos
= row
->end
.pos
;
19855 /* ROW->minpos and ROW->maxpos must be the smallest and
19856 `1 + the largest' buffer positions in ROW. But if ROW was
19857 bidi-reordered, these two positions can be anywhere in the
19858 row, so we must determine them now. */
19859 find_row_edges (it
, row
, min_pos
, min_bpos
, max_pos
, max_bpos
);
19862 /* If the start of this line is the overlay arrow-position, then
19863 mark this glyph row as the one containing the overlay arrow.
19864 This is clearly a mess with variable size fonts. It would be
19865 better to let it be displayed like cursors under X. */
19866 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
19867 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
19868 !NILP (overlay_arrow_string
)))
19870 /* Overlay arrow in window redisplay is a fringe bitmap. */
19871 if (STRINGP (overlay_arrow_string
))
19873 struct glyph_row
*arrow_row
19874 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
19875 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
19876 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
19877 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
19878 struct glyph
*p2
, *end
;
19880 /* Copy the arrow glyphs. */
19881 while (glyph
< arrow_end
)
19884 /* Throw away padding glyphs. */
19886 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
19887 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
19893 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
19898 eassert (INTEGERP (overlay_arrow_string
));
19899 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
19901 overlay_arrow_seen
= 1;
19904 /* Highlight trailing whitespace. */
19905 if (!NILP (Vshow_trailing_whitespace
))
19906 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
19908 /* Compute pixel dimensions of this line. */
19909 compute_line_metrics (it
);
19911 /* Implementation note: No changes in the glyphs of ROW or in their
19912 faces can be done past this point, because compute_line_metrics
19913 computes ROW's hash value and stores it within the glyph_row
19916 /* Record whether this row ends inside an ellipsis. */
19917 row
->ends_in_ellipsis_p
19918 = (it
->method
== GET_FROM_DISPLAY_VECTOR
19919 && it
->ellipsis_p
);
19921 /* Save fringe bitmaps in this row. */
19922 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
19923 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
19924 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
19925 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
19927 it
->left_user_fringe_bitmap
= 0;
19928 it
->left_user_fringe_face_id
= 0;
19929 it
->right_user_fringe_bitmap
= 0;
19930 it
->right_user_fringe_face_id
= 0;
19932 /* Maybe set the cursor. */
19933 cvpos
= it
->w
->cursor
.vpos
;
19935 /* In bidi-reordered rows, keep checking for proper cursor
19936 position even if one has been found already, because buffer
19937 positions in such rows change non-linearly with ROW->VPOS,
19938 when a line is continued. One exception: when we are at ZV,
19939 display cursor on the first suitable glyph row, since all
19940 the empty rows after that also have their position set to ZV. */
19941 /* FIXME: Revisit this when glyph ``spilling'' in continuation
19942 lines' rows is implemented for bidi-reordered rows. */
19944 && !MATRIX_ROW (it
->w
->desired_matrix
, cvpos
)->ends_at_zv_p
))
19945 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
19946 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
19947 && cursor_row_p (row
))
19948 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
19950 /* Prepare for the next line. This line starts horizontally at (X
19951 HPOS) = (0 0). Vertical positions are incremented. As a
19952 convenience for the caller, IT->glyph_row is set to the next
19954 it
->current_x
= it
->hpos
= 0;
19955 it
->current_y
+= row
->height
;
19956 SET_TEXT_POS (it
->eol_pos
, 0, 0);
19959 /* The next row should by default use the same value of the
19960 reversed_p flag as this one. set_iterator_to_next decides when
19961 it's a new paragraph, and PRODUCE_GLYPHS recomputes the value of
19962 the flag accordingly. */
19963 if (it
->glyph_row
< MATRIX_BOTTOM_TEXT_ROW (it
->w
->desired_matrix
, it
->w
))
19964 it
->glyph_row
->reversed_p
= row
->reversed_p
;
19965 it
->start
= row
->end
;
19966 return row
->displays_text_p
;
19968 #undef RECORD_MAX_MIN_POS
19971 DEFUN ("current-bidi-paragraph-direction", Fcurrent_bidi_paragraph_direction
,
19972 Scurrent_bidi_paragraph_direction
, 0, 1, 0,
19973 doc
: /* Return paragraph direction at point in BUFFER.
19974 Value is either `left-to-right' or `right-to-left'.
19975 If BUFFER is omitted or nil, it defaults to the current buffer.
19977 Paragraph direction determines how the text in the paragraph is displayed.
19978 In left-to-right paragraphs, text begins at the left margin of the window
19979 and the reading direction is generally left to right. In right-to-left
19980 paragraphs, text begins at the right margin and is read from right to left.
19982 See also `bidi-paragraph-direction'. */)
19983 (Lisp_Object buffer
)
19985 struct buffer
*buf
= current_buffer
;
19986 struct buffer
*old
= buf
;
19988 if (! NILP (buffer
))
19990 CHECK_BUFFER (buffer
);
19991 buf
= XBUFFER (buffer
);
19994 if (NILP (BVAR (buf
, bidi_display_reordering
))
19995 || NILP (BVAR (buf
, enable_multibyte_characters
))
19996 /* When we are loading loadup.el, the character property tables
19997 needed for bidi iteration are not yet available. */
19998 || !NILP (Vpurify_flag
))
19999 return Qleft_to_right
;
20000 else if (!NILP (BVAR (buf
, bidi_paragraph_direction
)))
20001 return BVAR (buf
, bidi_paragraph_direction
);
20004 /* Determine the direction from buffer text. We could try to
20005 use current_matrix if it is up to date, but this seems fast
20006 enough as it is. */
20007 struct bidi_it itb
;
20008 ptrdiff_t pos
= BUF_PT (buf
);
20009 ptrdiff_t bytepos
= BUF_PT_BYTE (buf
);
20011 void *itb_data
= bidi_shelve_cache ();
20013 set_buffer_temp (buf
);
20014 /* bidi_paragraph_init finds the base direction of the paragraph
20015 by searching forward from paragraph start. We need the base
20016 direction of the current or _previous_ paragraph, so we need
20017 to make sure we are within that paragraph. To that end, find
20018 the previous non-empty line. */
20019 if (pos
>= ZV
&& pos
> BEGV
)
20022 bytepos
= CHAR_TO_BYTE (pos
);
20024 if (fast_looking_at (build_string ("[\f\t ]*\n"),
20025 pos
, bytepos
, ZV
, ZV_BYTE
, Qnil
) > 0)
20027 while ((c
= FETCH_BYTE (bytepos
)) == '\n'
20028 || c
== ' ' || c
== '\t' || c
== '\f')
20030 if (bytepos
<= BEGV_BYTE
)
20035 while (!CHAR_HEAD_P (FETCH_BYTE (bytepos
)))
20038 bidi_init_it (pos
, bytepos
, FRAME_WINDOW_P (SELECTED_FRAME ()), &itb
);
20039 itb
.paragraph_dir
= NEUTRAL_DIR
;
20040 itb
.string
.s
= NULL
;
20041 itb
.string
.lstring
= Qnil
;
20042 itb
.string
.bufpos
= 0;
20043 itb
.string
.unibyte
= 0;
20044 bidi_paragraph_init (NEUTRAL_DIR
, &itb
, 1);
20045 bidi_unshelve_cache (itb_data
, 0);
20046 set_buffer_temp (old
);
20047 switch (itb
.paragraph_dir
)
20050 return Qleft_to_right
;
20053 return Qright_to_left
;
20063 /***********************************************************************
20065 ***********************************************************************/
20067 /* Redisplay the menu bar in the frame for window W.
20069 The menu bar of X frames that don't have X toolkit support is
20070 displayed in a special window W->frame->menu_bar_window.
20072 The menu bar of terminal frames is treated specially as far as
20073 glyph matrices are concerned. Menu bar lines are not part of
20074 windows, so the update is done directly on the frame matrix rows
20075 for the menu bar. */
20078 display_menu_bar (struct window
*w
)
20080 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20085 /* Don't do all this for graphical frames. */
20087 if (FRAME_W32_P (f
))
20090 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
20096 if (FRAME_NS_P (f
))
20098 #endif /* HAVE_NS */
20100 #ifdef USE_X_TOOLKIT
20101 eassert (!FRAME_WINDOW_P (f
));
20102 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
20103 it
.first_visible_x
= 0;
20104 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
20105 #else /* not USE_X_TOOLKIT */
20106 if (FRAME_WINDOW_P (f
))
20108 /* Menu bar lines are displayed in the desired matrix of the
20109 dummy window menu_bar_window. */
20110 struct window
*menu_w
;
20111 eassert (WINDOWP (f
->menu_bar_window
));
20112 menu_w
= XWINDOW (f
->menu_bar_window
);
20113 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
20115 it
.first_visible_x
= 0;
20116 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
20120 /* This is a TTY frame, i.e. character hpos/vpos are used as
20122 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
20124 it
.first_visible_x
= 0;
20125 it
.last_visible_x
= FRAME_COLS (f
);
20127 #endif /* not USE_X_TOOLKIT */
20129 /* FIXME: This should be controlled by a user option. See the
20130 comments in redisplay_tool_bar and display_mode_line about
20132 it
.paragraph_embedding
= L2R
;
20134 /* Clear all rows of the menu bar. */
20135 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
20137 struct glyph_row
*row
= it
.glyph_row
+ i
;
20138 clear_glyph_row (row
);
20139 row
->enabled_p
= 1;
20140 row
->full_width_p
= 1;
20143 /* Display all items of the menu bar. */
20144 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
20145 for (i
= 0; i
< ASIZE (items
); i
+= 4)
20147 Lisp_Object string
;
20149 /* Stop at nil string. */
20150 string
= AREF (items
, i
+ 1);
20154 /* Remember where item was displayed. */
20155 ASET (items
, i
+ 3, make_number (it
.hpos
));
20157 /* Display the item, pad with one space. */
20158 if (it
.current_x
< it
.last_visible_x
)
20159 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
20160 SCHARS (string
) + 1, 0, 0, -1);
20163 /* Fill out the line with spaces. */
20164 if (it
.current_x
< it
.last_visible_x
)
20165 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
20167 /* Compute the total height of the lines. */
20168 compute_line_metrics (&it
);
20173 /***********************************************************************
20175 ***********************************************************************/
20177 /* Redisplay mode lines in the window tree whose root is WINDOW. If
20178 FORCE is non-zero, redisplay mode lines unconditionally.
20179 Otherwise, redisplay only mode lines that are garbaged. Value is
20180 the number of windows whose mode lines were redisplayed. */
20183 redisplay_mode_lines (Lisp_Object window
, int force
)
20187 while (!NILP (window
))
20189 struct window
*w
= XWINDOW (window
);
20191 if (WINDOWP (w
->hchild
))
20192 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
20193 else if (WINDOWP (w
->vchild
))
20194 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
20196 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
20197 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
20199 struct text_pos lpoint
;
20200 struct buffer
*old
= current_buffer
;
20202 /* Set the window's buffer for the mode line display. */
20203 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
20204 set_buffer_internal_1 (XBUFFER (w
->buffer
));
20206 /* Point refers normally to the selected window. For any
20207 other window, set up appropriate value. */
20208 if (!EQ (window
, selected_window
))
20210 struct text_pos pt
;
20212 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
20213 if (CHARPOS (pt
) < BEGV
)
20214 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
20215 else if (CHARPOS (pt
) > (ZV
- 1))
20216 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
20218 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
20221 /* Display mode lines. */
20222 clear_glyph_matrix (w
->desired_matrix
);
20223 if (display_mode_lines (w
))
20226 w
->must_be_updated_p
= 1;
20229 /* Restore old settings. */
20230 set_buffer_internal_1 (old
);
20231 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
20241 /* Display the mode and/or header line of window W. Value is the
20242 sum number of mode lines and header lines displayed. */
20245 display_mode_lines (struct window
*w
)
20247 Lisp_Object old_selected_window
= selected_window
;
20248 Lisp_Object old_selected_frame
= selected_frame
;
20249 Lisp_Object new_frame
= w
->frame
;
20250 Lisp_Object old_frame_selected_window
= XFRAME (new_frame
)->selected_window
;
20253 selected_frame
= new_frame
;
20254 /* FIXME: If we were to allow the mode-line's computation changing the buffer
20255 or window's point, then we'd need select_window_1 here as well. */
20256 XSETWINDOW (selected_window
, w
);
20257 XFRAME (new_frame
)->selected_window
= selected_window
;
20259 /* These will be set while the mode line specs are processed. */
20260 line_number_displayed
= 0;
20261 w
->column_number_displayed
= -1;
20263 if (WINDOW_WANTS_MODELINE_P (w
))
20265 struct window
*sel_w
= XWINDOW (old_selected_window
);
20267 /* Select mode line face based on the real selected window. */
20268 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
20269 BVAR (current_buffer
, mode_line_format
));
20273 if (WINDOW_WANTS_HEADER_LINE_P (w
))
20275 display_mode_line (w
, HEADER_LINE_FACE_ID
,
20276 BVAR (current_buffer
, header_line_format
));
20280 XFRAME (new_frame
)->selected_window
= old_frame_selected_window
;
20281 selected_frame
= old_selected_frame
;
20282 selected_window
= old_selected_window
;
20287 /* Display mode or header line of window W. FACE_ID specifies which
20288 line to display; it is either MODE_LINE_FACE_ID or
20289 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
20290 display. Value is the pixel height of the mode/header line
20294 display_mode_line (struct window
*w
, enum face_id face_id
, Lisp_Object format
)
20298 ptrdiff_t count
= SPECPDL_INDEX ();
20300 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
20301 /* Don't extend on a previously drawn mode-line.
20302 This may happen if called from pos_visible_p. */
20303 it
.glyph_row
->enabled_p
= 0;
20304 prepare_desired_row (it
.glyph_row
);
20306 it
.glyph_row
->mode_line_p
= 1;
20308 /* FIXME: This should be controlled by a user option. But
20309 supporting such an option is not trivial, since the mode line is
20310 made up of many separate strings. */
20311 it
.paragraph_embedding
= L2R
;
20313 record_unwind_protect (unwind_format_mode_line
,
20314 format_mode_line_unwind_data (NULL
, NULL
, Qnil
, 0));
20316 mode_line_target
= MODE_LINE_DISPLAY
;
20318 /* Temporarily make frame's keyboard the current kboard so that
20319 kboard-local variables in the mode_line_format will get the right
20321 push_kboard (FRAME_KBOARD (it
.f
));
20322 record_unwind_save_match_data ();
20323 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
20326 unbind_to (count
, Qnil
);
20328 /* Fill up with spaces. */
20329 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
20331 compute_line_metrics (&it
);
20332 it
.glyph_row
->full_width_p
= 1;
20333 it
.glyph_row
->continued_p
= 0;
20334 it
.glyph_row
->truncated_on_left_p
= 0;
20335 it
.glyph_row
->truncated_on_right_p
= 0;
20337 /* Make a 3D mode-line have a shadow at its right end. */
20338 face
= FACE_FROM_ID (it
.f
, face_id
);
20339 extend_face_to_end_of_line (&it
);
20340 if (face
->box
!= FACE_NO_BOX
)
20342 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
20343 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
20344 last
->right_box_line_p
= 1;
20347 return it
.glyph_row
->height
;
20350 /* Move element ELT in LIST to the front of LIST.
20351 Return the updated list. */
20354 move_elt_to_front (Lisp_Object elt
, Lisp_Object list
)
20356 register Lisp_Object tail
, prev
;
20357 register Lisp_Object tem
;
20361 while (CONSP (tail
))
20367 /* Splice out the link TAIL. */
20369 list
= XCDR (tail
);
20371 Fsetcdr (prev
, XCDR (tail
));
20373 /* Now make it the first. */
20374 Fsetcdr (tail
, list
);
20379 tail
= XCDR (tail
);
20383 /* Not found--return unchanged LIST. */
20387 /* Contribute ELT to the mode line for window IT->w. How it
20388 translates into text depends on its data type.
20390 IT describes the display environment in which we display, as usual.
20392 DEPTH is the depth in recursion. It is used to prevent
20393 infinite recursion here.
20395 FIELD_WIDTH is the number of characters the display of ELT should
20396 occupy in the mode line, and PRECISION is the maximum number of
20397 characters to display from ELT's representation. See
20398 display_string for details.
20400 Returns the hpos of the end of the text generated by ELT.
20402 PROPS is a property list to add to any string we encounter.
20404 If RISKY is nonzero, remove (disregard) any properties in any string
20405 we encounter, and ignore :eval and :propertize.
20407 The global variable `mode_line_target' determines whether the
20408 output is passed to `store_mode_line_noprop',
20409 `store_mode_line_string', or `display_string'. */
20412 display_mode_element (struct it
*it
, int depth
, int field_width
, int precision
,
20413 Lisp_Object elt
, Lisp_Object props
, int risky
)
20415 int n
= 0, field
, prec
;
20420 elt
= build_string ("*too-deep*");
20424 switch (XTYPE (elt
))
20428 /* A string: output it and check for %-constructs within it. */
20430 ptrdiff_t offset
= 0;
20432 if (SCHARS (elt
) > 0
20433 && (!NILP (props
) || risky
))
20435 Lisp_Object oprops
, aelt
;
20436 oprops
= Ftext_properties_at (make_number (0), elt
);
20438 /* If the starting string's properties are not what
20439 we want, translate the string. Also, if the string
20440 is risky, do that anyway. */
20442 if (NILP (Fequal (props
, oprops
)) || risky
)
20444 /* If the starting string has properties,
20445 merge the specified ones onto the existing ones. */
20446 if (! NILP (oprops
) && !risky
)
20450 oprops
= Fcopy_sequence (oprops
);
20452 while (CONSP (tem
))
20454 oprops
= Fplist_put (oprops
, XCAR (tem
),
20455 XCAR (XCDR (tem
)));
20456 tem
= XCDR (XCDR (tem
));
20461 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
20462 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
20464 /* AELT is what we want. Move it to the front
20465 without consing. */
20467 mode_line_proptrans_alist
20468 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
20474 /* If AELT has the wrong props, it is useless.
20475 so get rid of it. */
20477 mode_line_proptrans_alist
20478 = Fdelq (aelt
, mode_line_proptrans_alist
);
20480 elt
= Fcopy_sequence (elt
);
20481 Fset_text_properties (make_number (0), Flength (elt
),
20483 /* Add this item to mode_line_proptrans_alist. */
20484 mode_line_proptrans_alist
20485 = Fcons (Fcons (elt
, props
),
20486 mode_line_proptrans_alist
);
20487 /* Truncate mode_line_proptrans_alist
20488 to at most 50 elements. */
20489 tem
= Fnthcdr (make_number (50),
20490 mode_line_proptrans_alist
);
20492 XSETCDR (tem
, Qnil
);
20501 prec
= precision
- n
;
20502 switch (mode_line_target
)
20504 case MODE_LINE_NOPROP
:
20505 case MODE_LINE_TITLE
:
20506 n
+= store_mode_line_noprop (SSDATA (elt
), -1, prec
);
20508 case MODE_LINE_STRING
:
20509 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
20511 case MODE_LINE_DISPLAY
:
20512 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
20513 0, prec
, 0, STRING_MULTIBYTE (elt
));
20520 /* Handle the non-literal case. */
20522 while ((precision
<= 0 || n
< precision
)
20523 && SREF (elt
, offset
) != 0
20524 && (mode_line_target
!= MODE_LINE_DISPLAY
20525 || it
->current_x
< it
->last_visible_x
))
20527 ptrdiff_t last_offset
= offset
;
20529 /* Advance to end of string or next format specifier. */
20530 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
20533 if (offset
- 1 != last_offset
)
20535 ptrdiff_t nchars
, nbytes
;
20537 /* Output to end of string or up to '%'. Field width
20538 is length of string. Don't output more than
20539 PRECISION allows us. */
20542 prec
= c_string_width (SDATA (elt
) + last_offset
,
20543 offset
- last_offset
, precision
- n
,
20546 switch (mode_line_target
)
20548 case MODE_LINE_NOPROP
:
20549 case MODE_LINE_TITLE
:
20550 n
+= store_mode_line_noprop (SSDATA (elt
) + last_offset
, 0, prec
);
20552 case MODE_LINE_STRING
:
20554 ptrdiff_t bytepos
= last_offset
;
20555 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
20556 ptrdiff_t endpos
= (precision
<= 0
20557 ? string_byte_to_char (elt
, offset
)
20558 : charpos
+ nchars
);
20560 n
+= store_mode_line_string (NULL
,
20561 Fsubstring (elt
, make_number (charpos
),
20562 make_number (endpos
)),
20566 case MODE_LINE_DISPLAY
:
20568 ptrdiff_t bytepos
= last_offset
;
20569 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
20571 if (precision
<= 0)
20572 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
20573 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
20575 STRING_MULTIBYTE (elt
));
20580 else /* c == '%' */
20582 ptrdiff_t percent_position
= offset
;
20584 /* Get the specified minimum width. Zero means
20587 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
20588 field
= field
* 10 + c
- '0';
20590 /* Don't pad beyond the total padding allowed. */
20591 if (field_width
- n
> 0 && field
> field_width
- n
)
20592 field
= field_width
- n
;
20594 /* Note that either PRECISION <= 0 or N < PRECISION. */
20595 prec
= precision
- n
;
20598 n
+= display_mode_element (it
, depth
, field
, prec
,
20599 Vglobal_mode_string
, props
,
20604 ptrdiff_t bytepos
, charpos
;
20606 Lisp_Object string
;
20608 bytepos
= percent_position
;
20609 charpos
= (STRING_MULTIBYTE (elt
)
20610 ? string_byte_to_char (elt
, bytepos
)
20612 spec
= decode_mode_spec (it
->w
, c
, field
, &string
);
20613 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
20615 switch (mode_line_target
)
20617 case MODE_LINE_NOPROP
:
20618 case MODE_LINE_TITLE
:
20619 n
+= store_mode_line_noprop (spec
, field
, prec
);
20621 case MODE_LINE_STRING
:
20623 Lisp_Object tem
= build_string (spec
);
20624 props
= Ftext_properties_at (make_number (charpos
), elt
);
20625 /* Should only keep face property in props */
20626 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
20629 case MODE_LINE_DISPLAY
:
20631 int nglyphs_before
, nwritten
;
20633 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
20634 nwritten
= display_string (spec
, string
, elt
,
20639 /* Assign to the glyphs written above the
20640 string where the `%x' came from, position
20644 struct glyph
*glyph
20645 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
20649 for (i
= 0; i
< nwritten
; ++i
)
20651 glyph
[i
].object
= elt
;
20652 glyph
[i
].charpos
= charpos
;
20669 /* A symbol: process the value of the symbol recursively
20670 as if it appeared here directly. Avoid error if symbol void.
20671 Special case: if value of symbol is a string, output the string
20674 register Lisp_Object tem
;
20676 /* If the variable is not marked as risky to set
20677 then its contents are risky to use. */
20678 if (NILP (Fget (elt
, Qrisky_local_variable
)))
20681 tem
= Fboundp (elt
);
20684 tem
= Fsymbol_value (elt
);
20685 /* If value is a string, output that string literally:
20686 don't check for % within it. */
20690 if (!EQ (tem
, elt
))
20692 /* Give up right away for nil or t. */
20702 register Lisp_Object car
, tem
;
20704 /* A cons cell: five distinct cases.
20705 If first element is :eval or :propertize, do something special.
20706 If first element is a string or a cons, process all the elements
20707 and effectively concatenate them.
20708 If first element is a negative number, truncate displaying cdr to
20709 at most that many characters. If positive, pad (with spaces)
20710 to at least that many characters.
20711 If first element is a symbol, process the cadr or caddr recursively
20712 according to whether the symbol's value is non-nil or nil. */
20714 if (EQ (car
, QCeval
))
20716 /* An element of the form (:eval FORM) means evaluate FORM
20717 and use the result as mode line elements. */
20722 if (CONSP (XCDR (elt
)))
20725 spec
= safe_eval (XCAR (XCDR (elt
)));
20726 n
+= display_mode_element (it
, depth
, field_width
- n
,
20727 precision
- n
, spec
, props
,
20731 else if (EQ (car
, QCpropertize
))
20733 /* An element of the form (:propertize ELT PROPS...)
20734 means display ELT but applying properties PROPS. */
20739 if (CONSP (XCDR (elt
)))
20740 n
+= display_mode_element (it
, depth
, field_width
- n
,
20741 precision
- n
, XCAR (XCDR (elt
)),
20742 XCDR (XCDR (elt
)), risky
);
20744 else if (SYMBOLP (car
))
20746 tem
= Fboundp (car
);
20750 /* elt is now the cdr, and we know it is a cons cell.
20751 Use its car if CAR has a non-nil value. */
20754 tem
= Fsymbol_value (car
);
20761 /* Symbol's value is nil (or symbol is unbound)
20762 Get the cddr of the original list
20763 and if possible find the caddr and use that. */
20767 else if (!CONSP (elt
))
20772 else if (INTEGERP (car
))
20774 register int lim
= XINT (car
);
20778 /* Negative int means reduce maximum width. */
20779 if (precision
<= 0)
20782 precision
= min (precision
, -lim
);
20786 /* Padding specified. Don't let it be more than
20787 current maximum. */
20789 lim
= min (precision
, lim
);
20791 /* If that's more padding than already wanted, queue it.
20792 But don't reduce padding already specified even if
20793 that is beyond the current truncation point. */
20794 field_width
= max (lim
, field_width
);
20798 else if (STRINGP (car
) || CONSP (car
))
20800 Lisp_Object halftail
= elt
;
20804 && (precision
<= 0 || n
< precision
))
20806 n
+= display_mode_element (it
, depth
,
20807 /* Do padding only after the last
20808 element in the list. */
20809 (! CONSP (XCDR (elt
))
20812 precision
- n
, XCAR (elt
),
20816 if ((len
& 1) == 0)
20817 halftail
= XCDR (halftail
);
20818 /* Check for cycle. */
20819 if (EQ (halftail
, elt
))
20828 elt
= build_string ("*invalid*");
20832 /* Pad to FIELD_WIDTH. */
20833 if (field_width
> 0 && n
< field_width
)
20835 switch (mode_line_target
)
20837 case MODE_LINE_NOPROP
:
20838 case MODE_LINE_TITLE
:
20839 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
20841 case MODE_LINE_STRING
:
20842 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
20844 case MODE_LINE_DISPLAY
:
20845 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
20854 /* Store a mode-line string element in mode_line_string_list.
20856 If STRING is non-null, display that C string. Otherwise, the Lisp
20857 string LISP_STRING is displayed.
20859 FIELD_WIDTH is the minimum number of output glyphs to produce.
20860 If STRING has fewer characters than FIELD_WIDTH, pad to the right
20861 with spaces. FIELD_WIDTH <= 0 means don't pad.
20863 PRECISION is the maximum number of characters to output from
20864 STRING. PRECISION <= 0 means don't truncate the string.
20866 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
20867 properties to the string.
20869 PROPS are the properties to add to the string.
20870 The mode_line_string_face face property is always added to the string.
20874 store_mode_line_string (const char *string
, Lisp_Object lisp_string
, int copy_string
,
20875 int field_width
, int precision
, Lisp_Object props
)
20880 if (string
!= NULL
)
20882 len
= strlen (string
);
20883 if (precision
> 0 && len
> precision
)
20885 lisp_string
= make_string (string
, len
);
20887 props
= mode_line_string_face_prop
;
20888 else if (!NILP (mode_line_string_face
))
20890 Lisp_Object face
= Fplist_get (props
, Qface
);
20891 props
= Fcopy_sequence (props
);
20893 face
= mode_line_string_face
;
20895 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
20896 props
= Fplist_put (props
, Qface
, face
);
20898 Fadd_text_properties (make_number (0), make_number (len
),
20899 props
, lisp_string
);
20903 len
= XFASTINT (Flength (lisp_string
));
20904 if (precision
> 0 && len
> precision
)
20907 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
20910 if (!NILP (mode_line_string_face
))
20914 props
= Ftext_properties_at (make_number (0), lisp_string
);
20915 face
= Fplist_get (props
, Qface
);
20917 face
= mode_line_string_face
;
20919 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
20920 props
= Fcons (Qface
, Fcons (face
, Qnil
));
20922 lisp_string
= Fcopy_sequence (lisp_string
);
20925 Fadd_text_properties (make_number (0), make_number (len
),
20926 props
, lisp_string
);
20931 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
20935 if (field_width
> len
)
20937 field_width
-= len
;
20938 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
20940 Fadd_text_properties (make_number (0), make_number (field_width
),
20941 props
, lisp_string
);
20942 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
20950 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
20952 doc
: /* Format a string out of a mode line format specification.
20953 First arg FORMAT specifies the mode line format (see `mode-line-format'
20954 for details) to use.
20956 By default, the format is evaluated for the currently selected window.
20958 Optional second arg FACE specifies the face property to put on all
20959 characters for which no face is specified. The value nil means the
20960 default face. The value t means whatever face the window's mode line
20961 currently uses (either `mode-line' or `mode-line-inactive',
20962 depending on whether the window is the selected window or not).
20963 An integer value means the value string has no text
20966 Optional third and fourth args WINDOW and BUFFER specify the window
20967 and buffer to use as the context for the formatting (defaults
20968 are the selected window and the WINDOW's buffer). */)
20969 (Lisp_Object format
, Lisp_Object face
,
20970 Lisp_Object window
, Lisp_Object buffer
)
20975 struct buffer
*old_buffer
= NULL
;
20977 int no_props
= INTEGERP (face
);
20978 ptrdiff_t count
= SPECPDL_INDEX ();
20980 int string_start
= 0;
20982 w
= decode_any_window (window
);
20983 XSETWINDOW (window
, w
);
20986 buffer
= w
->buffer
;
20987 CHECK_BUFFER (buffer
);
20989 /* Make formatting the modeline a non-op when noninteractive, otherwise
20990 there will be problems later caused by a partially initialized frame. */
20991 if (NILP (format
) || noninteractive
)
20992 return empty_unibyte_string
;
20997 face_id
= (NILP (face
) || EQ (face
, Qdefault
)) ? DEFAULT_FACE_ID
20998 : EQ (face
, Qt
) ? (EQ (window
, selected_window
)
20999 ? MODE_LINE_FACE_ID
: MODE_LINE_INACTIVE_FACE_ID
)
21000 : EQ (face
, Qmode_line
) ? MODE_LINE_FACE_ID
21001 : EQ (face
, Qmode_line_inactive
) ? MODE_LINE_INACTIVE_FACE_ID
21002 : EQ (face
, Qheader_line
) ? HEADER_LINE_FACE_ID
21003 : EQ (face
, Qtool_bar
) ? TOOL_BAR_FACE_ID
21006 old_buffer
= current_buffer
;
21008 /* Save things including mode_line_proptrans_alist,
21009 and set that to nil so that we don't alter the outer value. */
21010 record_unwind_protect (unwind_format_mode_line
,
21011 format_mode_line_unwind_data
21012 (XFRAME (WINDOW_FRAME (w
)),
21013 old_buffer
, selected_window
, 1));
21014 mode_line_proptrans_alist
= Qnil
;
21016 Fselect_window (window
, Qt
);
21017 set_buffer_internal_1 (XBUFFER (buffer
));
21019 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
21023 mode_line_target
= MODE_LINE_NOPROP
;
21024 mode_line_string_face_prop
= Qnil
;
21025 mode_line_string_list
= Qnil
;
21026 string_start
= MODE_LINE_NOPROP_LEN (0);
21030 mode_line_target
= MODE_LINE_STRING
;
21031 mode_line_string_list
= Qnil
;
21032 mode_line_string_face
= face
;
21033 mode_line_string_face_prop
21034 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
21037 push_kboard (FRAME_KBOARD (it
.f
));
21038 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
21043 len
= MODE_LINE_NOPROP_LEN (string_start
);
21044 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
21048 mode_line_string_list
= Fnreverse (mode_line_string_list
);
21049 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
21050 empty_unibyte_string
);
21053 unbind_to (count
, Qnil
);
21057 /* Write a null-terminated, right justified decimal representation of
21058 the positive integer D to BUF using a minimal field width WIDTH. */
21061 pint2str (register char *buf
, register int width
, register ptrdiff_t d
)
21063 register char *p
= buf
;
21071 *p
++ = d
% 10 + '0';
21076 for (width
-= (int) (p
- buf
); width
> 0; --width
)
21087 /* Write a null-terminated, right justified decimal and "human
21088 readable" representation of the nonnegative integer D to BUF using
21089 a minimal field width WIDTH. D should be smaller than 999.5e24. */
21091 static const char power_letter
[] =
21105 pint2hrstr (char *buf
, int width
, ptrdiff_t d
)
21107 /* We aim to represent the nonnegative integer D as
21108 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
21109 ptrdiff_t quotient
= d
;
21111 /* -1 means: do not use TENTHS. */
21115 /* Length of QUOTIENT.TENTHS as a string. */
21121 if (1000 <= quotient
)
21123 /* Scale to the appropriate EXPONENT. */
21126 remainder
= quotient
% 1000;
21130 while (1000 <= quotient
);
21132 /* Round to nearest and decide whether to use TENTHS or not. */
21135 tenths
= remainder
/ 100;
21136 if (50 <= remainder
% 100)
21143 if (quotient
== 10)
21151 if (500 <= remainder
)
21153 if (quotient
< 999)
21164 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
21165 if (tenths
== -1 && quotient
<= 99)
21172 p
= psuffix
= buf
+ max (width
, length
);
21174 /* Print EXPONENT. */
21175 *psuffix
++ = power_letter
[exponent
];
21178 /* Print TENTHS. */
21181 *--p
= '0' + tenths
;
21185 /* Print QUOTIENT. */
21188 int digit
= quotient
% 10;
21189 *--p
= '0' + digit
;
21191 while ((quotient
/= 10) != 0);
21193 /* Print leading spaces. */
21198 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
21199 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
21200 type of CODING_SYSTEM. Return updated pointer into BUF. */
21202 static unsigned char invalid_eol_type
[] = "(*invalid*)";
21205 decode_mode_spec_coding (Lisp_Object coding_system
, register char *buf
, int eol_flag
)
21208 bool multibyte
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
21209 const unsigned char *eol_str
;
21211 /* The EOL conversion we are using. */
21212 Lisp_Object eoltype
;
21214 val
= CODING_SYSTEM_SPEC (coding_system
);
21217 if (!VECTORP (val
)) /* Not yet decided. */
21219 *buf
++ = multibyte
? '-' : ' ';
21221 eoltype
= eol_mnemonic_undecided
;
21222 /* Don't mention EOL conversion if it isn't decided. */
21227 Lisp_Object eolvalue
;
21229 attrs
= AREF (val
, 0);
21230 eolvalue
= AREF (val
, 2);
21233 ? XFASTINT (CODING_ATTR_MNEMONIC (attrs
))
21238 /* The EOL conversion that is normal on this system. */
21240 if (NILP (eolvalue
)) /* Not yet decided. */
21241 eoltype
= eol_mnemonic_undecided
;
21242 else if (VECTORP (eolvalue
)) /* Not yet decided. */
21243 eoltype
= eol_mnemonic_undecided
;
21244 else /* eolvalue is Qunix, Qdos, or Qmac. */
21245 eoltype
= (EQ (eolvalue
, Qunix
)
21246 ? eol_mnemonic_unix
21247 : (EQ (eolvalue
, Qdos
) == 1
21248 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
21254 /* Mention the EOL conversion if it is not the usual one. */
21255 if (STRINGP (eoltype
))
21257 eol_str
= SDATA (eoltype
);
21258 eol_str_len
= SBYTES (eoltype
);
21260 else if (CHARACTERP (eoltype
))
21262 unsigned char *tmp
= alloca (MAX_MULTIBYTE_LENGTH
);
21263 int c
= XFASTINT (eoltype
);
21264 eol_str_len
= CHAR_STRING (c
, tmp
);
21269 eol_str
= invalid_eol_type
;
21270 eol_str_len
= sizeof (invalid_eol_type
) - 1;
21272 memcpy (buf
, eol_str
, eol_str_len
);
21273 buf
+= eol_str_len
;
21279 /* Return a string for the output of a mode line %-spec for window W,
21280 generated by character C. FIELD_WIDTH > 0 means pad the string
21281 returned with spaces to that value. Return a Lisp string in
21282 *STRING if the resulting string is taken from that Lisp string.
21284 Note we operate on the current buffer for most purposes. */
21286 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
21288 static const char *
21289 decode_mode_spec (struct window
*w
, register int c
, int field_width
,
21290 Lisp_Object
*string
)
21293 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21294 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
21295 /* We are going to use f->decode_mode_spec_buffer as the buffer to
21296 produce strings from numerical values, so limit preposterously
21297 large values of FIELD_WIDTH to avoid overrunning the buffer's
21298 end. The size of the buffer is enough for FRAME_MESSAGE_BUF_SIZE
21299 bytes plus the terminating null. */
21300 int width
= min (field_width
, FRAME_MESSAGE_BUF_SIZE (f
));
21301 struct buffer
*b
= current_buffer
;
21309 if (!NILP (BVAR (b
, read_only
)))
21311 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21316 /* This differs from %* only for a modified read-only buffer. */
21317 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21319 if (!NILP (BVAR (b
, read_only
)))
21324 /* This differs from %* in ignoring read-only-ness. */
21325 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21337 if (command_loop_level
> 5)
21339 p
= decode_mode_spec_buf
;
21340 for (i
= 0; i
< command_loop_level
; i
++)
21343 return decode_mode_spec_buf
;
21351 if (command_loop_level
> 5)
21353 p
= decode_mode_spec_buf
;
21354 for (i
= 0; i
< command_loop_level
; i
++)
21357 return decode_mode_spec_buf
;
21364 /* Let lots_of_dashes be a string of infinite length. */
21365 if (mode_line_target
== MODE_LINE_NOPROP
21366 || mode_line_target
== MODE_LINE_STRING
)
21368 if (field_width
<= 0
21369 || field_width
> sizeof (lots_of_dashes
))
21371 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
21372 decode_mode_spec_buf
[i
] = '-';
21373 decode_mode_spec_buf
[i
] = '\0';
21374 return decode_mode_spec_buf
;
21377 return lots_of_dashes
;
21381 obj
= BVAR (b
, name
);
21385 /* %c and %l are ignored in `frame-title-format'.
21386 (In redisplay_internal, the frame title is drawn _before_ the
21387 windows are updated, so the stuff which depends on actual
21388 window contents (such as %l) may fail to render properly, or
21389 even crash emacs.) */
21390 if (mode_line_target
== MODE_LINE_TITLE
)
21394 ptrdiff_t col
= current_column ();
21395 w
->column_number_displayed
= col
;
21396 pint2str (decode_mode_spec_buf
, width
, col
);
21397 return decode_mode_spec_buf
;
21401 #ifndef SYSTEM_MALLOC
21403 if (NILP (Vmemory_full
))
21406 return "!MEM FULL! ";
21413 /* %F displays the frame name. */
21414 if (!NILP (f
->title
))
21415 return SSDATA (f
->title
);
21416 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
21417 return SSDATA (f
->name
);
21421 obj
= BVAR (b
, filename
);
21426 ptrdiff_t size
= ZV
- BEGV
;
21427 pint2str (decode_mode_spec_buf
, width
, size
);
21428 return decode_mode_spec_buf
;
21433 ptrdiff_t size
= ZV
- BEGV
;
21434 pint2hrstr (decode_mode_spec_buf
, width
, size
);
21435 return decode_mode_spec_buf
;
21440 ptrdiff_t startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
21441 ptrdiff_t topline
, nlines
, height
;
21444 /* %c and %l are ignored in `frame-title-format'. */
21445 if (mode_line_target
== MODE_LINE_TITLE
)
21448 startpos
= marker_position (w
->start
);
21449 startpos_byte
= marker_byte_position (w
->start
);
21450 height
= WINDOW_TOTAL_LINES (w
);
21452 /* If we decided that this buffer isn't suitable for line numbers,
21453 don't forget that too fast. */
21454 if (w
->base_line_pos
== -1)
21457 /* If the buffer is very big, don't waste time. */
21458 if (INTEGERP (Vline_number_display_limit
)
21459 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
21461 w
->base_line_pos
= 0;
21462 w
->base_line_number
= 0;
21466 if (w
->base_line_number
> 0
21467 && w
->base_line_pos
> 0
21468 && w
->base_line_pos
<= startpos
)
21470 line
= w
->base_line_number
;
21471 linepos
= w
->base_line_pos
;
21472 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
21477 linepos
= BUF_BEGV (b
);
21478 linepos_byte
= BUF_BEGV_BYTE (b
);
21481 /* Count lines from base line to window start position. */
21482 nlines
= display_count_lines (linepos_byte
,
21486 topline
= nlines
+ line
;
21488 /* Determine a new base line, if the old one is too close
21489 or too far away, or if we did not have one.
21490 "Too close" means it's plausible a scroll-down would
21491 go back past it. */
21492 if (startpos
== BUF_BEGV (b
))
21494 w
->base_line_number
= topline
;
21495 w
->base_line_pos
= BUF_BEGV (b
);
21497 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
21498 || linepos
== BUF_BEGV (b
))
21500 ptrdiff_t limit
= BUF_BEGV (b
);
21501 ptrdiff_t limit_byte
= BUF_BEGV_BYTE (b
);
21502 ptrdiff_t position
;
21503 ptrdiff_t distance
=
21504 (height
* 2 + 30) * line_number_display_limit_width
;
21506 if (startpos
- distance
> limit
)
21508 limit
= startpos
- distance
;
21509 limit_byte
= CHAR_TO_BYTE (limit
);
21512 nlines
= display_count_lines (startpos_byte
,
21514 - (height
* 2 + 30),
21516 /* If we couldn't find the lines we wanted within
21517 line_number_display_limit_width chars per line,
21518 give up on line numbers for this window. */
21519 if (position
== limit_byte
&& limit
== startpos
- distance
)
21521 w
->base_line_pos
= -1;
21522 w
->base_line_number
= 0;
21526 w
->base_line_number
= topline
- nlines
;
21527 w
->base_line_pos
= BYTE_TO_CHAR (position
);
21530 /* Now count lines from the start pos to point. */
21531 nlines
= display_count_lines (startpos_byte
,
21532 PT_BYTE
, PT
, &junk
);
21534 /* Record that we did display the line number. */
21535 line_number_displayed
= 1;
21537 /* Make the string to show. */
21538 pint2str (decode_mode_spec_buf
, width
, topline
+ nlines
);
21539 return decode_mode_spec_buf
;
21542 char* p
= decode_mode_spec_buf
;
21543 int pad
= width
- 2;
21549 return decode_mode_spec_buf
;
21555 obj
= BVAR (b
, mode_name
);
21559 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
21565 ptrdiff_t pos
= marker_position (w
->start
);
21566 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
21568 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
21570 if (pos
<= BUF_BEGV (b
))
21575 else if (pos
<= BUF_BEGV (b
))
21579 if (total
> 1000000)
21580 /* Do it differently for a large value, to avoid overflow. */
21581 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
21583 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
21584 /* We can't normally display a 3-digit number,
21585 so get us a 2-digit number that is close. */
21588 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
21589 return decode_mode_spec_buf
;
21593 /* Display percentage of size above the bottom of the screen. */
21596 ptrdiff_t toppos
= marker_position (w
->start
);
21597 ptrdiff_t botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
21598 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
21600 if (botpos
>= BUF_ZV (b
))
21602 if (toppos
<= BUF_BEGV (b
))
21609 if (total
> 1000000)
21610 /* Do it differently for a large value, to avoid overflow. */
21611 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
21613 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
21614 /* We can't normally display a 3-digit number,
21615 so get us a 2-digit number that is close. */
21618 if (toppos
<= BUF_BEGV (b
))
21619 sprintf (decode_mode_spec_buf
, "Top%2"pD
"d%%", total
);
21621 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
21622 return decode_mode_spec_buf
;
21627 /* status of process */
21628 obj
= Fget_buffer_process (Fcurrent_buffer ());
21630 return "no process";
21632 obj
= Fsymbol_name (Fprocess_status (obj
));
21638 ptrdiff_t count
= inhibit_garbage_collection ();
21639 Lisp_Object val
= call1 (intern ("file-remote-p"),
21640 BVAR (current_buffer
, directory
));
21641 unbind_to (count
, Qnil
);
21650 /* coding-system (not including end-of-line format) */
21652 /* coding-system (including end-of-line type) */
21654 int eol_flag
= (c
== 'Z');
21655 char *p
= decode_mode_spec_buf
;
21657 if (! FRAME_WINDOW_P (f
))
21659 /* No need to mention EOL here--the terminal never needs
21660 to do EOL conversion. */
21661 p
= decode_mode_spec_coding (CODING_ID_NAME
21662 (FRAME_KEYBOARD_CODING (f
)->id
),
21664 p
= decode_mode_spec_coding (CODING_ID_NAME
21665 (FRAME_TERMINAL_CODING (f
)->id
),
21668 p
= decode_mode_spec_coding (BVAR (b
, buffer_file_coding_system
),
21671 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
21672 #ifdef subprocesses
21673 obj
= Fget_buffer_process (Fcurrent_buffer ());
21674 if (PROCESSP (obj
))
21676 p
= decode_mode_spec_coding
21677 (XPROCESS (obj
)->decode_coding_system
, p
, eol_flag
);
21678 p
= decode_mode_spec_coding
21679 (XPROCESS (obj
)->encode_coding_system
, p
, eol_flag
);
21681 #endif /* subprocesses */
21684 return decode_mode_spec_buf
;
21691 return SSDATA (obj
);
21698 /* Count up to COUNT lines starting from START_BYTE. COUNT negative
21699 means count lines back from START_BYTE. But don't go beyond
21700 LIMIT_BYTE. Return the number of lines thus found (always
21703 Set *BYTE_POS_PTR to the byte position where we stopped. This is
21704 either the position COUNT lines after/before START_BYTE, if we
21705 found COUNT lines, or LIMIT_BYTE if we hit the limit before finding
21709 display_count_lines (ptrdiff_t start_byte
,
21710 ptrdiff_t limit_byte
, ptrdiff_t count
,
21711 ptrdiff_t *byte_pos_ptr
)
21713 register unsigned char *cursor
;
21714 unsigned char *base
;
21716 register ptrdiff_t ceiling
;
21717 register unsigned char *ceiling_addr
;
21718 ptrdiff_t orig_count
= count
;
21720 /* If we are not in selective display mode,
21721 check only for newlines. */
21722 int selective_display
= (!NILP (BVAR (current_buffer
, selective_display
))
21723 && !INTEGERP (BVAR (current_buffer
, selective_display
)));
21727 while (start_byte
< limit_byte
)
21729 ceiling
= BUFFER_CEILING_OF (start_byte
);
21730 ceiling
= min (limit_byte
- 1, ceiling
);
21731 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
21732 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
21736 if (selective_display
)
21738 while (*cursor
!= '\n' && *cursor
!= 015
21739 && ++cursor
!= ceiling_addr
)
21741 if (cursor
== ceiling_addr
)
21746 cursor
= memchr (cursor
, '\n', ceiling_addr
- cursor
);
21755 start_byte
+= cursor
- base
;
21756 *byte_pos_ptr
= start_byte
;
21760 while (cursor
< ceiling_addr
);
21762 start_byte
+= ceiling_addr
- base
;
21767 while (start_byte
> limit_byte
)
21769 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
21770 ceiling
= max (limit_byte
, ceiling
);
21771 ceiling_addr
= BYTE_POS_ADDR (ceiling
);
21772 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
21775 if (selective_display
)
21777 while (--cursor
>= ceiling_addr
21778 && *cursor
!= '\n' && *cursor
!= 015)
21780 if (cursor
< ceiling_addr
)
21785 cursor
= memrchr (ceiling_addr
, '\n', cursor
- ceiling_addr
);
21792 start_byte
+= cursor
- base
+ 1;
21793 *byte_pos_ptr
= start_byte
;
21794 /* When scanning backwards, we should
21795 not count the newline posterior to which we stop. */
21796 return - orig_count
- 1;
21799 start_byte
+= ceiling_addr
- base
;
21803 *byte_pos_ptr
= limit_byte
;
21806 return - orig_count
+ count
;
21807 return orig_count
- count
;
21813 /***********************************************************************
21815 ***********************************************************************/
21817 /* Display a NUL-terminated string, starting with index START.
21819 If STRING is non-null, display that C string. Otherwise, the Lisp
21820 string LISP_STRING is displayed. There's a case that STRING is
21821 non-null and LISP_STRING is not nil. It means STRING is a string
21822 data of LISP_STRING. In that case, we display LISP_STRING while
21823 ignoring its text properties.
21825 If FACE_STRING is not nil, FACE_STRING_POS is a position in
21826 FACE_STRING. Display STRING or LISP_STRING with the face at
21827 FACE_STRING_POS in FACE_STRING:
21829 Display the string in the environment given by IT, but use the
21830 standard display table, temporarily.
21832 FIELD_WIDTH is the minimum number of output glyphs to produce.
21833 If STRING has fewer characters than FIELD_WIDTH, pad to the right
21834 with spaces. If STRING has more characters, more than FIELD_WIDTH
21835 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
21837 PRECISION is the maximum number of characters to output from
21838 STRING. PRECISION < 0 means don't truncate the string.
21840 This is roughly equivalent to printf format specifiers:
21842 FIELD_WIDTH PRECISION PRINTF
21843 ----------------------------------------
21849 MULTIBYTE zero means do not display multibyte chars, > 0 means do
21850 display them, and < 0 means obey the current buffer's value of
21851 enable_multibyte_characters.
21853 Value is the number of columns displayed. */
21856 display_string (const char *string
, Lisp_Object lisp_string
, Lisp_Object face_string
,
21857 ptrdiff_t face_string_pos
, ptrdiff_t start
, struct it
*it
,
21858 int field_width
, int precision
, int max_x
, int multibyte
)
21860 int hpos_at_start
= it
->hpos
;
21861 int saved_face_id
= it
->face_id
;
21862 struct glyph_row
*row
= it
->glyph_row
;
21863 ptrdiff_t it_charpos
;
21865 /* Initialize the iterator IT for iteration over STRING beginning
21866 with index START. */
21867 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
21868 precision
, field_width
, multibyte
);
21869 if (string
&& STRINGP (lisp_string
))
21870 /* LISP_STRING is the one returned by decode_mode_spec. We should
21871 ignore its text properties. */
21872 it
->stop_charpos
= it
->end_charpos
;
21874 /* If displaying STRING, set up the face of the iterator from
21875 FACE_STRING, if that's given. */
21876 if (STRINGP (face_string
))
21882 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
21883 0, it
->region_beg_charpos
,
21884 it
->region_end_charpos
,
21885 &endptr
, it
->base_face_id
, 0);
21886 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21887 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
21890 /* Set max_x to the maximum allowed X position. Don't let it go
21891 beyond the right edge of the window. */
21893 max_x
= it
->last_visible_x
;
21895 max_x
= min (max_x
, it
->last_visible_x
);
21897 /* Skip over display elements that are not visible. because IT->w is
21899 if (it
->current_x
< it
->first_visible_x
)
21900 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
21901 MOVE_TO_POS
| MOVE_TO_X
);
21903 row
->ascent
= it
->max_ascent
;
21904 row
->height
= it
->max_ascent
+ it
->max_descent
;
21905 row
->phys_ascent
= it
->max_phys_ascent
;
21906 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
21907 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
21909 if (STRINGP (it
->string
))
21910 it_charpos
= IT_STRING_CHARPOS (*it
);
21912 it_charpos
= IT_CHARPOS (*it
);
21914 /* This condition is for the case that we are called with current_x
21915 past last_visible_x. */
21916 while (it
->current_x
< max_x
)
21918 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
21920 /* Get the next display element. */
21921 if (!get_next_display_element (it
))
21924 /* Produce glyphs. */
21925 x_before
= it
->current_x
;
21926 n_glyphs_before
= row
->used
[TEXT_AREA
];
21927 PRODUCE_GLYPHS (it
);
21929 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
21932 while (i
< nglyphs
)
21934 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
21936 if (it
->line_wrap
!= TRUNCATE
21937 && x
+ glyph
->pixel_width
> max_x
)
21939 /* End of continued line or max_x reached. */
21940 if (CHAR_GLYPH_PADDING_P (*glyph
))
21942 /* A wide character is unbreakable. */
21943 if (row
->reversed_p
)
21944 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
21945 - n_glyphs_before
);
21946 row
->used
[TEXT_AREA
] = n_glyphs_before
;
21947 it
->current_x
= x_before
;
21951 if (row
->reversed_p
)
21952 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
21953 - (n_glyphs_before
+ i
));
21954 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
21959 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
21961 /* Glyph is at least partially visible. */
21963 if (x
< it
->first_visible_x
)
21964 row
->x
= x
- it
->first_visible_x
;
21968 /* Glyph is off the left margin of the display area.
21969 Should not happen. */
21973 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
21974 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
21975 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
21976 row
->phys_height
= max (row
->phys_height
,
21977 it
->max_phys_ascent
+ it
->max_phys_descent
);
21978 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
21979 it
->max_extra_line_spacing
);
21980 x
+= glyph
->pixel_width
;
21984 /* Stop if max_x reached. */
21988 /* Stop at line ends. */
21989 if (ITERATOR_AT_END_OF_LINE_P (it
))
21991 it
->continuation_lines_width
= 0;
21995 set_iterator_to_next (it
, 1);
21996 if (STRINGP (it
->string
))
21997 it_charpos
= IT_STRING_CHARPOS (*it
);
21999 it_charpos
= IT_CHARPOS (*it
);
22001 /* Stop if truncating at the right edge. */
22002 if (it
->line_wrap
== TRUNCATE
22003 && it
->current_x
>= it
->last_visible_x
)
22005 /* Add truncation mark, but don't do it if the line is
22006 truncated at a padding space. */
22007 if (it_charpos
< it
->string_nchars
)
22009 if (!FRAME_WINDOW_P (it
->f
))
22013 if (it
->current_x
> it
->last_visible_x
)
22015 if (!row
->reversed_p
)
22017 for (ii
= row
->used
[TEXT_AREA
] - 1; ii
> 0; --ii
)
22018 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
22023 for (ii
= 0; ii
< row
->used
[TEXT_AREA
]; ii
++)
22024 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
22026 unproduce_glyphs (it
, ii
+ 1);
22027 ii
= row
->used
[TEXT_AREA
] - (ii
+ 1);
22029 for (n
= row
->used
[TEXT_AREA
]; ii
< n
; ++ii
)
22031 row
->used
[TEXT_AREA
] = ii
;
22032 produce_special_glyphs (it
, IT_TRUNCATION
);
22035 produce_special_glyphs (it
, IT_TRUNCATION
);
22037 row
->truncated_on_right_p
= 1;
22043 /* Maybe insert a truncation at the left. */
22044 if (it
->first_visible_x
22047 if (!FRAME_WINDOW_P (it
->f
)
22048 || (row
->reversed_p
22049 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
22050 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
22051 insert_left_trunc_glyphs (it
);
22052 row
->truncated_on_left_p
= 1;
22055 it
->face_id
= saved_face_id
;
22057 /* Value is number of columns displayed. */
22058 return it
->hpos
- hpos_at_start
;
22063 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
22064 appears as an element of LIST or as the car of an element of LIST.
22065 If PROPVAL is a list, compare each element against LIST in that
22066 way, and return 1/2 if any element of PROPVAL is found in LIST.
22067 Otherwise return 0. This function cannot quit.
22068 The return value is 2 if the text is invisible but with an ellipsis
22069 and 1 if it's invisible and without an ellipsis. */
22072 invisible_p (register Lisp_Object propval
, Lisp_Object list
)
22074 register Lisp_Object tail
, proptail
;
22076 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
22078 register Lisp_Object tem
;
22080 if (EQ (propval
, tem
))
22082 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
22083 return NILP (XCDR (tem
)) ? 1 : 2;
22086 if (CONSP (propval
))
22088 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
22090 Lisp_Object propelt
;
22091 propelt
= XCAR (proptail
);
22092 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
22094 register Lisp_Object tem
;
22096 if (EQ (propelt
, tem
))
22098 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
22099 return NILP (XCDR (tem
)) ? 1 : 2;
22107 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
22108 doc
: /* Non-nil if the property makes the text invisible.
22109 POS-OR-PROP can be a marker or number, in which case it is taken to be
22110 a position in the current buffer and the value of the `invisible' property
22111 is checked; or it can be some other value, which is then presumed to be the
22112 value of the `invisible' property of the text of interest.
22113 The non-nil value returned can be t for truly invisible text or something
22114 else if the text is replaced by an ellipsis. */)
22115 (Lisp_Object pos_or_prop
)
22118 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
22119 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
22121 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
22122 return (invis
== 0 ? Qnil
22124 : make_number (invis
));
22127 /* Calculate a width or height in pixels from a specification using
22128 the following elements:
22131 NUM - a (fractional) multiple of the default font width/height
22132 (NUM) - specifies exactly NUM pixels
22133 UNIT - a fixed number of pixels, see below.
22134 ELEMENT - size of a display element in pixels, see below.
22135 (NUM . SPEC) - equals NUM * SPEC
22136 (+ SPEC SPEC ...) - add pixel values
22137 (- SPEC SPEC ...) - subtract pixel values
22138 (- SPEC) - negate pixel value
22141 INT or FLOAT - a number constant
22142 SYMBOL - use symbol's (buffer local) variable binding.
22145 in - pixels per inch *)
22146 mm - pixels per 1/1000 meter *)
22147 cm - pixels per 1/100 meter *)
22148 width - width of current font in pixels.
22149 height - height of current font in pixels.
22151 *) using the ratio(s) defined in display-pixels-per-inch.
22155 left-fringe - left fringe width in pixels
22156 right-fringe - right fringe width in pixels
22158 left-margin - left margin width in pixels
22159 right-margin - right margin width in pixels
22161 scroll-bar - scroll-bar area width in pixels
22165 Pixels corresponding to 5 inches:
22168 Total width of non-text areas on left side of window (if scroll-bar is on left):
22169 '(space :width (+ left-fringe left-margin scroll-bar))
22171 Align to first text column (in header line):
22172 '(space :align-to 0)
22174 Align to middle of text area minus half the width of variable `my-image'
22175 containing a loaded image:
22176 '(space :align-to (0.5 . (- text my-image)))
22178 Width of left margin minus width of 1 character in the default font:
22179 '(space :width (- left-margin 1))
22181 Width of left margin minus width of 2 characters in the current font:
22182 '(space :width (- left-margin (2 . width)))
22184 Center 1 character over left-margin (in header line):
22185 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
22187 Different ways to express width of left fringe plus left margin minus one pixel:
22188 '(space :width (- (+ left-fringe left-margin) (1)))
22189 '(space :width (+ left-fringe left-margin (- (1))))
22190 '(space :width (+ left-fringe left-margin (-1)))
22194 #define NUMVAL(X) \
22195 ((INTEGERP (X) || FLOATP (X)) \
22200 calc_pixel_width_or_height (double *res
, struct it
*it
, Lisp_Object prop
,
22201 struct font
*font
, int width_p
, int *align_to
)
22205 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
22206 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
22209 return OK_PIXELS (0);
22211 eassert (FRAME_LIVE_P (it
->f
));
22213 if (SYMBOLP (prop
))
22215 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
22217 char *unit
= SSDATA (SYMBOL_NAME (prop
));
22219 if (unit
[0] == 'i' && unit
[1] == 'n')
22221 else if (unit
[0] == 'm' && unit
[1] == 'm')
22223 else if (unit
[0] == 'c' && unit
[1] == 'm')
22230 #ifdef HAVE_WINDOW_SYSTEM
22231 if (FRAME_WINDOW_P (it
->f
)
22233 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
22234 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
22236 return OK_PIXELS (ppi
/ pixels
);
22239 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
22240 || (CONSP (Vdisplay_pixels_per_inch
)
22242 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
22243 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
22245 return OK_PIXELS (ppi
/ pixels
);
22251 #ifdef HAVE_WINDOW_SYSTEM
22252 if (EQ (prop
, Qheight
))
22253 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
22254 if (EQ (prop
, Qwidth
))
22255 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
22257 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
22258 return OK_PIXELS (1);
22261 if (EQ (prop
, Qtext
))
22262 return OK_PIXELS (width_p
22263 ? window_box_width (it
->w
, TEXT_AREA
)
22264 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
22266 if (align_to
&& *align_to
< 0)
22269 if (EQ (prop
, Qleft
))
22270 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
22271 if (EQ (prop
, Qright
))
22272 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
22273 if (EQ (prop
, Qcenter
))
22274 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
22275 + window_box_width (it
->w
, TEXT_AREA
) / 2);
22276 if (EQ (prop
, Qleft_fringe
))
22277 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22278 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
22279 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
22280 if (EQ (prop
, Qright_fringe
))
22281 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22282 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
22283 : window_box_right_offset (it
->w
, TEXT_AREA
));
22284 if (EQ (prop
, Qleft_margin
))
22285 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
22286 if (EQ (prop
, Qright_margin
))
22287 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
22288 if (EQ (prop
, Qscroll_bar
))
22289 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
22291 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
22292 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22293 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
22298 if (EQ (prop
, Qleft_fringe
))
22299 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
22300 if (EQ (prop
, Qright_fringe
))
22301 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
22302 if (EQ (prop
, Qleft_margin
))
22303 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
22304 if (EQ (prop
, Qright_margin
))
22305 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
22306 if (EQ (prop
, Qscroll_bar
))
22307 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
22310 prop
= buffer_local_value_1 (prop
, it
->w
->buffer
);
22311 if (EQ (prop
, Qunbound
))
22315 if (INTEGERP (prop
) || FLOATP (prop
))
22317 int base_unit
= (width_p
22318 ? FRAME_COLUMN_WIDTH (it
->f
)
22319 : FRAME_LINE_HEIGHT (it
->f
));
22320 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
22325 Lisp_Object car
= XCAR (prop
);
22326 Lisp_Object cdr
= XCDR (prop
);
22330 #ifdef HAVE_WINDOW_SYSTEM
22331 if (FRAME_WINDOW_P (it
->f
)
22332 && valid_image_p (prop
))
22334 ptrdiff_t id
= lookup_image (it
->f
, prop
);
22335 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
22337 return OK_PIXELS (width_p
? img
->width
: img
->height
);
22339 #ifdef HAVE_XWIDGETS
22340 if (FRAME_WINDOW_P (it
->f
) && valid_xwidget_p (prop
))
22342 printf("calc_pixel_width_or_height: return dummy size FIXME\n");
22343 return OK_PIXELS (width_p
? 100 : 100);
22347 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
22353 while (CONSP (cdr
))
22355 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
22356 font
, width_p
, align_to
))
22359 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
22364 if (EQ (car
, Qminus
))
22366 return OK_PIXELS (pixels
);
22369 car
= buffer_local_value_1 (car
, it
->w
->buffer
);
22370 if (EQ (car
, Qunbound
))
22374 if (INTEGERP (car
) || FLOATP (car
))
22377 pixels
= XFLOATINT (car
);
22379 return OK_PIXELS (pixels
);
22380 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
22381 font
, width_p
, align_to
))
22382 return OK_PIXELS (pixels
* fact
);
22393 /***********************************************************************
22395 ***********************************************************************/
22397 #ifdef HAVE_WINDOW_SYSTEM
22402 dump_glyph_string (struct glyph_string
*s
)
22404 fprintf (stderr
, "glyph string\n");
22405 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
22406 s
->x
, s
->y
, s
->width
, s
->height
);
22407 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
22408 fprintf (stderr
, " hl = %d\n", s
->hl
);
22409 fprintf (stderr
, " left overhang = %d, right = %d\n",
22410 s
->left_overhang
, s
->right_overhang
);
22411 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
22412 fprintf (stderr
, " extends to end of line = %d\n",
22413 s
->extends_to_end_of_line_p
);
22414 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
22415 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
22418 #endif /* GLYPH_DEBUG */
22420 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
22421 of XChar2b structures for S; it can't be allocated in
22422 init_glyph_string because it must be allocated via `alloca'. W
22423 is the window on which S is drawn. ROW and AREA are the glyph row
22424 and area within the row from which S is constructed. START is the
22425 index of the first glyph structure covered by S. HL is a
22426 face-override for drawing S. */
22429 #define OPTIONAL_HDC(hdc) HDC hdc,
22430 #define DECLARE_HDC(hdc) HDC hdc;
22431 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
22432 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
22435 #ifndef OPTIONAL_HDC
22436 #define OPTIONAL_HDC(hdc)
22437 #define DECLARE_HDC(hdc)
22438 #define ALLOCATE_HDC(hdc, f)
22439 #define RELEASE_HDC(hdc, f)
22443 init_glyph_string (struct glyph_string
*s
,
22445 XChar2b
*char2b
, struct window
*w
, struct glyph_row
*row
,
22446 enum glyph_row_area area
, int start
, enum draw_glyphs_face hl
)
22448 memset (s
, 0, sizeof *s
);
22450 s
->f
= XFRAME (w
->frame
);
22454 s
->display
= FRAME_X_DISPLAY (s
->f
);
22455 s
->window
= FRAME_X_WINDOW (s
->f
);
22456 s
->char2b
= char2b
;
22460 s
->first_glyph
= row
->glyphs
[area
] + start
;
22461 s
->height
= row
->height
;
22462 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
22463 s
->ybase
= s
->y
+ row
->ascent
;
22467 /* Append the list of glyph strings with head H and tail T to the list
22468 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
22471 append_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
22472 struct glyph_string
*h
, struct glyph_string
*t
)
22486 /* Prepend the list of glyph strings with head H and tail T to the
22487 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
22491 prepend_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
22492 struct glyph_string
*h
, struct glyph_string
*t
)
22506 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
22507 Set *HEAD and *TAIL to the resulting list. */
22510 append_glyph_string (struct glyph_string
**head
, struct glyph_string
**tail
,
22511 struct glyph_string
*s
)
22513 s
->next
= s
->prev
= NULL
;
22514 append_glyph_string_lists (head
, tail
, s
, s
);
22518 /* Get face and two-byte form of character C in face FACE_ID on frame F.
22519 The encoding of C is returned in *CHAR2B. DISPLAY_P non-zero means
22520 make sure that X resources for the face returned are allocated.
22521 Value is a pointer to a realized face that is ready for display if
22522 DISPLAY_P is non-zero. */
22524 static struct face
*
22525 get_char_face_and_encoding (struct frame
*f
, int c
, int face_id
,
22526 XChar2b
*char2b
, int display_p
)
22528 struct face
*face
= FACE_FROM_ID (f
, face_id
);
22532 unsigned code
= face
->font
->driver
->encode_char (face
->font
, c
);
22534 if (code
!= FONT_INVALID_CODE
)
22535 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22537 STORE_XCHAR2B (char2b
, 0, 0);
22540 /* Make sure X resources of the face are allocated. */
22541 #ifdef HAVE_X_WINDOWS
22545 eassert (face
!= NULL
);
22546 PREPARE_FACE_FOR_DISPLAY (f
, face
);
22553 /* Get face and two-byte form of character glyph GLYPH on frame F.
22554 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
22555 a pointer to a realized face that is ready for display. */
22557 static struct face
*
22558 get_glyph_face_and_encoding (struct frame
*f
, struct glyph
*glyph
,
22559 XChar2b
*char2b
, int *two_byte_p
)
22563 eassert (glyph
->type
== CHAR_GLYPH
);
22564 face
= FACE_FROM_ID (f
, glyph
->face_id
);
22573 if (CHAR_BYTE8_P (glyph
->u
.ch
))
22574 code
= CHAR_TO_BYTE8 (glyph
->u
.ch
);
22576 code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
22578 if (code
!= FONT_INVALID_CODE
)
22579 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22581 STORE_XCHAR2B (char2b
, 0, 0);
22584 /* Make sure X resources of the face are allocated. */
22585 eassert (face
!= NULL
);
22586 PREPARE_FACE_FOR_DISPLAY (f
, face
);
22591 /* Get glyph code of character C in FONT in the two-byte form CHAR2B.
22592 Return 1 if FONT has a glyph for C, otherwise return 0. */
22595 get_char_glyph_code (int c
, struct font
*font
, XChar2b
*char2b
)
22599 if (CHAR_BYTE8_P (c
))
22600 code
= CHAR_TO_BYTE8 (c
);
22602 code
= font
->driver
->encode_char (font
, c
);
22604 if (code
== FONT_INVALID_CODE
)
22606 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22611 /* Fill glyph string S with composition components specified by S->cmp.
22613 BASE_FACE is the base face of the composition.
22614 S->cmp_from is the index of the first component for S.
22616 OVERLAPS non-zero means S should draw the foreground only, and use
22617 its physical height for clipping. See also draw_glyphs.
22619 Value is the index of a component not in S. */
22622 fill_composite_glyph_string (struct glyph_string
*s
, struct face
*base_face
,
22626 /* For all glyphs of this composition, starting at the offset
22627 S->cmp_from, until we reach the end of the definition or encounter a
22628 glyph that requires the different face, add it to S. */
22633 s
->for_overlaps
= overlaps
;
22636 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
22638 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
22640 /* TAB in a composition means display glyphs with padding space
22641 on the left or right. */
22644 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
22647 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
22654 s
->font
= s
->face
->font
;
22656 else if (s
->face
!= face
)
22664 if (s
->face
== NULL
)
22666 s
->face
= base_face
->ascii_face
;
22667 s
->font
= s
->face
->font
;
22670 /* All glyph strings for the same composition has the same width,
22671 i.e. the width set for the first component of the composition. */
22672 s
->width
= s
->first_glyph
->pixel_width
;
22674 /* If the specified font could not be loaded, use the frame's
22675 default font, but record the fact that we couldn't load it in
22676 the glyph string so that we can draw rectangles for the
22677 characters of the glyph string. */
22678 if (s
->font
== NULL
)
22680 s
->font_not_found_p
= 1;
22681 s
->font
= FRAME_FONT (s
->f
);
22684 /* Adjust base line for subscript/superscript text. */
22685 s
->ybase
+= s
->first_glyph
->voffset
;
22687 /* This glyph string must always be drawn with 16-bit functions. */
22694 fill_gstring_glyph_string (struct glyph_string
*s
, int face_id
,
22695 int start
, int end
, int overlaps
)
22697 struct glyph
*glyph
, *last
;
22698 Lisp_Object lgstring
;
22701 s
->for_overlaps
= overlaps
;
22702 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22703 last
= s
->row
->glyphs
[s
->area
] + end
;
22704 s
->cmp_id
= glyph
->u
.cmp
.id
;
22705 s
->cmp_from
= glyph
->slice
.cmp
.from
;
22706 s
->cmp_to
= glyph
->slice
.cmp
.to
+ 1;
22707 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
22708 lgstring
= composition_gstring_from_id (s
->cmp_id
);
22709 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
22711 while (glyph
< last
22712 && glyph
->u
.cmp
.automatic
22713 && glyph
->u
.cmp
.id
== s
->cmp_id
22714 && s
->cmp_to
== glyph
->slice
.cmp
.from
)
22715 s
->cmp_to
= (glyph
++)->slice
.cmp
.to
+ 1;
22717 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
22719 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
22720 unsigned code
= LGLYPH_CODE (lglyph
);
22722 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
22724 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
22725 return glyph
- s
->row
->glyphs
[s
->area
];
22729 /* Fill glyph string S from a sequence glyphs for glyphless characters.
22730 See the comment of fill_glyph_string for arguments.
22731 Value is the index of the first glyph not in S. */
22735 fill_glyphless_glyph_string (struct glyph_string
*s
, int face_id
,
22736 int start
, int end
, int overlaps
)
22738 struct glyph
*glyph
, *last
;
22741 eassert (s
->first_glyph
->type
== GLYPHLESS_GLYPH
);
22742 s
->for_overlaps
= overlaps
;
22743 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22744 last
= s
->row
->glyphs
[s
->area
] + end
;
22745 voffset
= glyph
->voffset
;
22746 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
22747 s
->font
= s
->face
->font
? s
->face
->font
: FRAME_FONT (s
->f
);
22749 s
->width
= glyph
->pixel_width
;
22751 while (glyph
< last
22752 && glyph
->type
== GLYPHLESS_GLYPH
22753 && glyph
->voffset
== voffset
22754 && glyph
->face_id
== face_id
)
22757 s
->width
+= glyph
->pixel_width
;
22760 s
->ybase
+= voffset
;
22761 return glyph
- s
->row
->glyphs
[s
->area
];
22765 /* Fill glyph string S from a sequence of character glyphs.
22767 FACE_ID is the face id of the string. START is the index of the
22768 first glyph to consider, END is the index of the last + 1.
22769 OVERLAPS non-zero means S should draw the foreground only, and use
22770 its physical height for clipping. See also draw_glyphs.
22772 Value is the index of the first glyph not in S. */
22775 fill_glyph_string (struct glyph_string
*s
, int face_id
,
22776 int start
, int end
, int overlaps
)
22778 struct glyph
*glyph
, *last
;
22780 int glyph_not_available_p
;
22782 eassert (s
->f
== XFRAME (s
->w
->frame
));
22783 eassert (s
->nchars
== 0);
22784 eassert (start
>= 0 && end
> start
);
22786 s
->for_overlaps
= overlaps
;
22787 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22788 last
= s
->row
->glyphs
[s
->area
] + end
;
22789 voffset
= glyph
->voffset
;
22790 s
->padding_p
= glyph
->padding_p
;
22791 glyph_not_available_p
= glyph
->glyph_not_available_p
;
22793 while (glyph
< last
22794 && glyph
->type
== CHAR_GLYPH
22795 && glyph
->voffset
== voffset
22796 /* Same face id implies same font, nowadays. */
22797 && glyph
->face_id
== face_id
22798 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
22802 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
22803 s
->char2b
+ s
->nchars
,
22805 s
->two_byte_p
= two_byte_p
;
22807 eassert (s
->nchars
<= end
- start
);
22808 s
->width
+= glyph
->pixel_width
;
22809 if (glyph
++->padding_p
!= s
->padding_p
)
22813 s
->font
= s
->face
->font
;
22815 /* If the specified font could not be loaded, use the frame's font,
22816 but record the fact that we couldn't load it in
22817 S->font_not_found_p so that we can draw rectangles for the
22818 characters of the glyph string. */
22819 if (s
->font
== NULL
|| glyph_not_available_p
)
22821 s
->font_not_found_p
= 1;
22822 s
->font
= FRAME_FONT (s
->f
);
22825 /* Adjust base line for subscript/superscript text. */
22826 s
->ybase
+= voffset
;
22828 eassert (s
->face
&& s
->face
->gc
);
22829 return glyph
- s
->row
->glyphs
[s
->area
];
22833 /* Fill glyph string S from image glyph S->first_glyph. */
22836 fill_image_glyph_string (struct glyph_string
*s
)
22838 eassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
22839 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
22841 s
->slice
= s
->first_glyph
->slice
.img
;
22842 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
22843 s
->font
= s
->face
->font
;
22844 s
->width
= s
->first_glyph
->pixel_width
;
22846 /* Adjust base line for subscript/superscript text. */
22847 s
->ybase
+= s
->first_glyph
->voffset
;
22850 #ifdef HAVE_XWIDGETS
22852 fill_xwidget_glyph_string (struct glyph_string
*s
)
22854 eassert (s
->first_glyph
->type
== XWIDGET_GLYPH
);
22855 printf("fill_xwidget_glyph_string: width:%d \n",s
->first_glyph
->pixel_width
);
22856 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
22857 s
->font
= s
->face
->font
;
22858 s
->width
= s
->first_glyph
->pixel_width
;
22859 s
->ybase
+= s
->first_glyph
->voffset
;
22860 s
->xwidget
= s
->first_glyph
->u
.xwidget
;
22861 //assert_valid_xwidget_id ( s->xwidget, "fill_xwidget_glyph_string");
22864 /* Fill glyph string S from a sequence of stretch glyphs.
22866 START is the index of the first glyph to consider,
22867 END is the index of the last + 1.
22869 Value is the index of the first glyph not in S. */
22872 fill_stretch_glyph_string (struct glyph_string
*s
, int start
, int end
)
22874 struct glyph
*glyph
, *last
;
22875 int voffset
, face_id
;
22877 eassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
22879 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22880 last
= s
->row
->glyphs
[s
->area
] + end
;
22881 face_id
= glyph
->face_id
;
22882 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
22883 s
->font
= s
->face
->font
;
22884 s
->width
= glyph
->pixel_width
;
22886 voffset
= glyph
->voffset
;
22890 && glyph
->type
== STRETCH_GLYPH
22891 && glyph
->voffset
== voffset
22892 && glyph
->face_id
== face_id
);
22894 s
->width
+= glyph
->pixel_width
;
22896 /* Adjust base line for subscript/superscript text. */
22897 s
->ybase
+= voffset
;
22899 /* The case that face->gc == 0 is handled when drawing the glyph
22900 string by calling PREPARE_FACE_FOR_DISPLAY. */
22902 return glyph
- s
->row
->glyphs
[s
->area
];
22905 static struct font_metrics
*
22906 get_per_char_metric (struct font
*font
, XChar2b
*char2b
)
22908 static struct font_metrics metrics
;
22909 unsigned code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
22911 if (! font
|| code
== FONT_INVALID_CODE
)
22913 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
22918 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
22919 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
22920 assumed to be zero. */
22923 x_get_glyph_overhangs (struct glyph
*glyph
, struct frame
*f
, int *left
, int *right
)
22925 *left
= *right
= 0;
22927 if (glyph
->type
== CHAR_GLYPH
)
22931 struct font_metrics
*pcm
;
22933 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
22934 if (face
->font
&& (pcm
= get_per_char_metric (face
->font
, &char2b
)))
22936 if (pcm
->rbearing
> pcm
->width
)
22937 *right
= pcm
->rbearing
- pcm
->width
;
22938 if (pcm
->lbearing
< 0)
22939 *left
= -pcm
->lbearing
;
22942 else if (glyph
->type
== COMPOSITE_GLYPH
)
22944 if (! glyph
->u
.cmp
.automatic
)
22946 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
22948 if (cmp
->rbearing
> cmp
->pixel_width
)
22949 *right
= cmp
->rbearing
- cmp
->pixel_width
;
22950 if (cmp
->lbearing
< 0)
22951 *left
= - cmp
->lbearing
;
22955 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
22956 struct font_metrics metrics
;
22958 composition_gstring_width (gstring
, glyph
->slice
.cmp
.from
,
22959 glyph
->slice
.cmp
.to
+ 1, &metrics
);
22960 if (metrics
.rbearing
> metrics
.width
)
22961 *right
= metrics
.rbearing
- metrics
.width
;
22962 if (metrics
.lbearing
< 0)
22963 *left
= - metrics
.lbearing
;
22969 /* Return the index of the first glyph preceding glyph string S that
22970 is overwritten by S because of S's left overhang. Value is -1
22971 if no glyphs are overwritten. */
22974 left_overwritten (struct glyph_string
*s
)
22978 if (s
->left_overhang
)
22981 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
22982 int first
= s
->first_glyph
- glyphs
;
22984 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
22985 x
-= glyphs
[i
].pixel_width
;
22996 /* Return the index of the first glyph preceding glyph string S that
22997 is overwriting S because of its right overhang. Value is -1 if no
22998 glyph in front of S overwrites S. */
23001 left_overwriting (struct glyph_string
*s
)
23004 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23005 int first
= s
->first_glyph
- glyphs
;
23009 for (i
= first
- 1; i
>= 0; --i
)
23012 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
23015 x
-= glyphs
[i
].pixel_width
;
23022 /* Return the index of the last glyph following glyph string S that is
23023 overwritten by S because of S's right overhang. Value is -1 if
23024 no such glyph is found. */
23027 right_overwritten (struct glyph_string
*s
)
23031 if (s
->right_overhang
)
23034 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23035 int first
= (s
->first_glyph
- glyphs
23036 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
23037 int end
= s
->row
->used
[s
->area
];
23039 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
23040 x
+= glyphs
[i
].pixel_width
;
23049 /* Return the index of the last glyph following glyph string S that
23050 overwrites S because of its left overhang. Value is negative
23051 if no such glyph is found. */
23054 right_overwriting (struct glyph_string
*s
)
23057 int end
= s
->row
->used
[s
->area
];
23058 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23059 int first
= (s
->first_glyph
- glyphs
23060 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
23064 for (i
= first
; i
< end
; ++i
)
23067 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
23070 x
+= glyphs
[i
].pixel_width
;
23077 /* Set background width of glyph string S. START is the index of the
23078 first glyph following S. LAST_X is the right-most x-position + 1
23079 in the drawing area. */
23082 set_glyph_string_background_width (struct glyph_string
*s
, int start
, int last_x
)
23084 /* If the face of this glyph string has to be drawn to the end of
23085 the drawing area, set S->extends_to_end_of_line_p. */
23087 if (start
== s
->row
->used
[s
->area
]
23088 && s
->area
== TEXT_AREA
23089 && ((s
->row
->fill_line_p
23090 && (s
->hl
== DRAW_NORMAL_TEXT
23091 || s
->hl
== DRAW_IMAGE_RAISED
23092 || s
->hl
== DRAW_IMAGE_SUNKEN
))
23093 || s
->hl
== DRAW_MOUSE_FACE
))
23094 s
->extends_to_end_of_line_p
= 1;
23096 /* If S extends its face to the end of the line, set its
23097 background_width to the distance to the right edge of the drawing
23099 if (s
->extends_to_end_of_line_p
)
23100 s
->background_width
= last_x
- s
->x
+ 1;
23102 s
->background_width
= s
->width
;
23106 /* Compute overhangs and x-positions for glyph string S and its
23107 predecessors, or successors. X is the starting x-position for S.
23108 BACKWARD_P non-zero means process predecessors. */
23111 compute_overhangs_and_x (struct glyph_string
*s
, int x
, int backward_p
)
23117 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
23118 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
23128 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
23129 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
23139 /* The following macros are only called from draw_glyphs below.
23140 They reference the following parameters of that function directly:
23141 `w', `row', `area', and `overlap_p'
23142 as well as the following local variables:
23143 `s', `f', and `hdc' (in W32) */
23146 /* On W32, silently add local `hdc' variable to argument list of
23147 init_glyph_string. */
23148 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
23149 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
23151 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
23152 init_glyph_string (s, char2b, w, row, area, start, hl)
23155 /* Add a glyph string for a stretch glyph to the list of strings
23156 between HEAD and TAIL. START is the index of the stretch glyph in
23157 row area AREA of glyph row ROW. END is the index of the last glyph
23158 in that glyph row area. X is the current output position assigned
23159 to the new glyph string constructed. HL overrides that face of the
23160 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
23161 is the right-most x-position of the drawing area. */
23163 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
23164 and below -- keep them on one line. */
23165 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23168 s = alloca (sizeof *s); \
23169 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23170 START = fill_stretch_glyph_string (s, START, END); \
23171 append_glyph_string (&HEAD, &TAIL, s); \
23177 /* Add a glyph string for an image glyph to the list of strings
23178 between HEAD and TAIL. START is the index of the image glyph in
23179 row area AREA of glyph row ROW. END is the index of the last glyph
23180 in that glyph row area. X is the current output position assigned
23181 to the new glyph string constructed. HL overrides that face of the
23182 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
23183 is the right-most x-position of the drawing area. */
23185 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23188 s = alloca (sizeof *s); \
23189 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23190 fill_image_glyph_string (s); \
23191 append_glyph_string (&HEAD, &TAIL, s); \
23197 #ifdef HAVE_XWIDGETS
23198 #define BUILD_XWIDGET_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23201 printf("BUILD_XWIDGET_GLYPH_STRING\n"); \
23202 s = (struct glyph_string *) alloca (sizeof *s); \
23203 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23204 fill_xwidget_glyph_string (s); \
23205 append_glyph_string (&HEAD, &TAIL, s); \
23213 /* Add a glyph string for a sequence of character glyphs to the list
23214 of strings between HEAD and TAIL. START is the index of the first
23215 glyph in row area AREA of glyph row ROW that is part of the new
23216 glyph string. END is the index of the last glyph in that glyph row
23217 area. X is the current output position assigned to the new glyph
23218 string constructed. HL overrides that face of the glyph; e.g. it
23219 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
23220 right-most x-position of the drawing area. */
23222 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
23228 face_id = (row)->glyphs[area][START].face_id; \
23230 s = alloca (sizeof *s); \
23231 char2b = alloca ((END - START) * sizeof *char2b); \
23232 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23233 append_glyph_string (&HEAD, &TAIL, s); \
23235 START = fill_glyph_string (s, face_id, START, END, overlaps); \
23240 /* Add a glyph string for a composite sequence to the list of strings
23241 between HEAD and TAIL. START is the index of the first glyph in
23242 row area AREA of glyph row ROW that is part of the new glyph
23243 string. END is the index of the last glyph in that glyph row area.
23244 X is the current output position assigned to the new glyph string
23245 constructed. HL overrides that face of the glyph; e.g. it is
23246 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
23247 x-position of the drawing area. */
23249 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23251 int face_id = (row)->glyphs[area][START].face_id; \
23252 struct face *base_face = FACE_FROM_ID (f, face_id); \
23253 ptrdiff_t cmp_id = (row)->glyphs[area][START].u.cmp.id; \
23254 struct composition *cmp = composition_table[cmp_id]; \
23256 struct glyph_string *first_s = NULL; \
23259 char2b = alloca (cmp->glyph_len * sizeof *char2b); \
23261 /* Make glyph_strings for each glyph sequence that is drawable by \
23262 the same face, and append them to HEAD/TAIL. */ \
23263 for (n = 0; n < cmp->glyph_len;) \
23265 s = alloca (sizeof *s); \
23266 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23267 append_glyph_string (&(HEAD), &(TAIL), s); \
23273 n = fill_composite_glyph_string (s, base_face, overlaps); \
23281 /* Add a glyph string for a glyph-string sequence to the list of strings
23282 between HEAD and TAIL. */
23284 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23288 Lisp_Object gstring; \
23290 face_id = (row)->glyphs[area][START].face_id; \
23291 gstring = (composition_gstring_from_id \
23292 ((row)->glyphs[area][START].u.cmp.id)); \
23293 s = alloca (sizeof *s); \
23294 char2b = alloca (LGSTRING_GLYPH_LEN (gstring) * sizeof *char2b); \
23295 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23296 append_glyph_string (&(HEAD), &(TAIL), s); \
23298 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
23302 /* Add a glyph string for a sequence of glyphless character's glyphs
23303 to the list of strings between HEAD and TAIL. The meanings of
23304 arguments are the same as those of BUILD_CHAR_GLYPH_STRINGS. */
23306 #define BUILD_GLYPHLESS_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23311 face_id = (row)->glyphs[area][START].face_id; \
23313 s = alloca (sizeof *s); \
23314 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23315 append_glyph_string (&HEAD, &TAIL, s); \
23317 START = fill_glyphless_glyph_string (s, face_id, START, END, \
23323 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
23324 of AREA of glyph row ROW on window W between indices START and END.
23325 HL overrides the face for drawing glyph strings, e.g. it is
23326 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
23327 x-positions of the drawing area.
23329 This is an ugly monster macro construct because we must use alloca
23330 to allocate glyph strings (because draw_glyphs can be called
23331 asynchronously). */
23333 #define BUILD_GLYPH_STRINGS_1(START, END, HEAD, TAIL, HL, X, LAST_X) \
23336 HEAD = TAIL = NULL; \
23337 while (START < END) \
23339 struct glyph *first_glyph = (row)->glyphs[area] + START; \
23340 switch (first_glyph->type) \
23343 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
23347 case COMPOSITE_GLYPH: \
23348 if (first_glyph->u.cmp.automatic) \
23349 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
23352 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
23356 case STRETCH_GLYPH: \
23357 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
23361 case IMAGE_GLYPH: \
23362 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
23366 #define BUILD_GLYPH_STRINGS_XW(START, END, HEAD, TAIL, HL, X, LAST_X) \
23367 case XWIDGET_GLYPH: \
23368 BUILD_XWIDGET_GLYPH_STRING (START, END, HEAD, TAIL, \
23372 #define BUILD_GLYPH_STRINGS_2(START, END, HEAD, TAIL, HL, X, LAST_X) \
23373 case GLYPHLESS_GLYPH: \
23374 BUILD_GLYPHLESS_GLYPH_STRING (START, END, HEAD, TAIL, \
23384 set_glyph_string_background_width (s, START, LAST_X); \
23391 #ifdef HAVE_XWIDGETS
23392 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
23393 BUILD_GLYPH_STRINGS_1(START, END, HEAD, TAIL, HL, X, LAST_X) \
23394 BUILD_GLYPH_STRINGS_XW(START, END, HEAD, TAIL, HL, X, LAST_X) \
23395 BUILD_GLYPH_STRINGS_2(START, END, HEAD, TAIL, HL, X, LAST_X)
23397 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
23398 BUILD_GLYPH_STRINGS_1(START, END, HEAD, TAIL, HL, X, LAST_X) \
23399 BUILD_GLYPH_STRINGS_2(START, END, HEAD, TAIL, HL, X, LAST_X)
23403 /* Draw glyphs between START and END in AREA of ROW on window W,
23404 starting at x-position X. X is relative to AREA in W. HL is a
23405 face-override with the following meaning:
23407 DRAW_NORMAL_TEXT draw normally
23408 DRAW_CURSOR draw in cursor face
23409 DRAW_MOUSE_FACE draw in mouse face.
23410 DRAW_INVERSE_VIDEO draw in mode line face
23411 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
23412 DRAW_IMAGE_RAISED draw an image with a raised relief around it
23414 If OVERLAPS is non-zero, draw only the foreground of characters and
23415 clip to the physical height of ROW. Non-zero value also defines
23416 the overlapping part to be drawn:
23418 OVERLAPS_PRED overlap with preceding rows
23419 OVERLAPS_SUCC overlap with succeeding rows
23420 OVERLAPS_BOTH overlap with both preceding/succeeding rows
23421 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
23423 Value is the x-position reached, relative to AREA of W. */
23426 draw_glyphs (struct window
*w
, int x
, struct glyph_row
*row
,
23427 enum glyph_row_area area
, ptrdiff_t start
, ptrdiff_t end
,
23428 enum draw_glyphs_face hl
, int overlaps
)
23430 struct glyph_string
*head
, *tail
;
23431 struct glyph_string
*s
;
23432 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
23433 int i
, j
, x_reached
, last_x
, area_left
= 0;
23434 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
23437 ALLOCATE_HDC (hdc
, f
);
23439 /* Let's rather be paranoid than getting a SEGV. */
23440 end
= min (end
, row
->used
[area
]);
23441 start
= clip_to_bounds (0, start
, end
);
23443 /* Translate X to frame coordinates. Set last_x to the right
23444 end of the drawing area. */
23445 if (row
->full_width_p
)
23447 /* X is relative to the left edge of W, without scroll bars
23449 area_left
= WINDOW_LEFT_EDGE_X (w
);
23450 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
23454 area_left
= window_box_left (w
, area
);
23455 last_x
= area_left
+ window_box_width (w
, area
);
23459 /* Build a doubly-linked list of glyph_string structures between
23460 head and tail from what we have to draw. Note that the macro
23461 BUILD_GLYPH_STRINGS will modify its start parameter. That's
23462 the reason we use a separate variable `i'. */
23464 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
23466 x_reached
= tail
->x
+ tail
->background_width
;
23470 /* If there are any glyphs with lbearing < 0 or rbearing > width in
23471 the row, redraw some glyphs in front or following the glyph
23472 strings built above. */
23473 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
23475 struct glyph_string
*h
, *t
;
23476 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
23477 int mouse_beg_col
IF_LINT (= 0), mouse_end_col
IF_LINT (= 0);
23478 int check_mouse_face
= 0;
23481 /* If mouse highlighting is on, we may need to draw adjacent
23482 glyphs using mouse-face highlighting. */
23483 if (area
== TEXT_AREA
&& row
->mouse_face_p
23484 && hlinfo
->mouse_face_beg_row
>= 0
23485 && hlinfo
->mouse_face_end_row
>= 0)
23487 struct glyph_row
*mouse_beg_row
, *mouse_end_row
;
23489 mouse_beg_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
23490 mouse_end_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
23492 if (row
>= mouse_beg_row
&& row
<= mouse_end_row
)
23494 check_mouse_face
= 1;
23495 mouse_beg_col
= (row
== mouse_beg_row
)
23496 ? hlinfo
->mouse_face_beg_col
: 0;
23497 mouse_end_col
= (row
== mouse_end_row
)
23498 ? hlinfo
->mouse_face_end_col
23499 : row
->used
[TEXT_AREA
];
23503 /* Compute overhangs for all glyph strings. */
23504 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
23505 for (s
= head
; s
; s
= s
->next
)
23506 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
23508 /* Prepend glyph strings for glyphs in front of the first glyph
23509 string that are overwritten because of the first glyph
23510 string's left overhang. The background of all strings
23511 prepended must be drawn because the first glyph string
23513 i
= left_overwritten (head
);
23516 enum draw_glyphs_face overlap_hl
;
23518 /* If this row contains mouse highlighting, attempt to draw
23519 the overlapped glyphs with the correct highlight. This
23520 code fails if the overlap encompasses more than one glyph
23521 and mouse-highlight spans only some of these glyphs.
23522 However, making it work perfectly involves a lot more
23523 code, and I don't know if the pathological case occurs in
23524 practice, so we'll stick to this for now. --- cyd */
23525 if (check_mouse_face
23526 && mouse_beg_col
< start
&& mouse_end_col
> i
)
23527 overlap_hl
= DRAW_MOUSE_FACE
;
23529 overlap_hl
= DRAW_NORMAL_TEXT
;
23532 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
23533 overlap_hl
, dummy_x
, last_x
);
23535 compute_overhangs_and_x (t
, head
->x
, 1);
23536 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
23540 /* Prepend glyph strings for glyphs in front of the first glyph
23541 string that overwrite that glyph string because of their
23542 right overhang. For these strings, only the foreground must
23543 be drawn, because it draws over the glyph string at `head'.
23544 The background must not be drawn because this would overwrite
23545 right overhangs of preceding glyphs for which no glyph
23547 i
= left_overwriting (head
);
23550 enum draw_glyphs_face overlap_hl
;
23552 if (check_mouse_face
23553 && mouse_beg_col
< start
&& mouse_end_col
> i
)
23554 overlap_hl
= DRAW_MOUSE_FACE
;
23556 overlap_hl
= DRAW_NORMAL_TEXT
;
23559 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
23560 overlap_hl
, dummy_x
, last_x
);
23561 for (s
= h
; s
; s
= s
->next
)
23562 s
->background_filled_p
= 1;
23563 compute_overhangs_and_x (t
, head
->x
, 1);
23564 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
23567 /* Append glyphs strings for glyphs following the last glyph
23568 string tail that are overwritten by tail. The background of
23569 these strings has to be drawn because tail's foreground draws
23571 i
= right_overwritten (tail
);
23574 enum draw_glyphs_face overlap_hl
;
23576 if (check_mouse_face
23577 && mouse_beg_col
< i
&& mouse_end_col
> end
)
23578 overlap_hl
= DRAW_MOUSE_FACE
;
23580 overlap_hl
= DRAW_NORMAL_TEXT
;
23582 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
23583 overlap_hl
, x
, last_x
);
23584 /* Because BUILD_GLYPH_STRINGS updates the first argument,
23585 we don't have `end = i;' here. */
23586 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
23587 append_glyph_string_lists (&head
, &tail
, h
, t
);
23591 /* Append glyph strings for glyphs following the last glyph
23592 string tail that overwrite tail. The foreground of such
23593 glyphs has to be drawn because it writes into the background
23594 of tail. The background must not be drawn because it could
23595 paint over the foreground of following glyphs. */
23596 i
= right_overwriting (tail
);
23599 enum draw_glyphs_face overlap_hl
;
23600 if (check_mouse_face
23601 && mouse_beg_col
< i
&& mouse_end_col
> end
)
23602 overlap_hl
= DRAW_MOUSE_FACE
;
23604 overlap_hl
= DRAW_NORMAL_TEXT
;
23607 i
++; /* We must include the Ith glyph. */
23608 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
23609 overlap_hl
, x
, last_x
);
23610 for (s
= h
; s
; s
= s
->next
)
23611 s
->background_filled_p
= 1;
23612 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
23613 append_glyph_string_lists (&head
, &tail
, h
, t
);
23615 if (clip_head
|| clip_tail
)
23616 for (s
= head
; s
; s
= s
->next
)
23618 s
->clip_head
= clip_head
;
23619 s
->clip_tail
= clip_tail
;
23623 /* Draw all strings. */
23624 for (s
= head
; s
; s
= s
->next
)
23625 FRAME_RIF (f
)->draw_glyph_string (s
);
23628 /* When focus a sole frame and move horizontally, this sets on_p to 0
23629 causing a failure to erase prev cursor position. */
23630 if (area
== TEXT_AREA
23631 && !row
->full_width_p
23632 /* When drawing overlapping rows, only the glyph strings'
23633 foreground is drawn, which doesn't erase a cursor
23637 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
23638 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
23639 : (tail
? tail
->x
+ tail
->background_width
: x
));
23643 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
23644 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
23648 /* Value is the x-position up to which drawn, relative to AREA of W.
23649 This doesn't include parts drawn because of overhangs. */
23650 if (row
->full_width_p
)
23651 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
23653 x_reached
-= area_left
;
23655 RELEASE_HDC (hdc
, f
);
23660 /* Expand row matrix if too narrow. Don't expand if area
23663 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
23665 if (!fonts_changed_p \
23666 && (it->glyph_row->glyphs[area] \
23667 < it->glyph_row->glyphs[area + 1])) \
23669 it->w->ncols_scale_factor++; \
23670 fonts_changed_p = 1; \
23674 /* Store one glyph for IT->char_to_display in IT->glyph_row.
23675 Called from x_produce_glyphs when IT->glyph_row is non-null. */
23678 append_glyph (struct it
*it
)
23680 struct glyph
*glyph
;
23681 enum glyph_row_area area
= it
->area
;
23683 eassert (it
->glyph_row
);
23684 eassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
23686 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23687 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23689 /* If the glyph row is reversed, we need to prepend the glyph
23690 rather than append it. */
23691 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23695 /* Make room for the additional glyph. */
23696 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
23698 glyph
= it
->glyph_row
->glyphs
[area
];
23700 glyph
->charpos
= CHARPOS (it
->position
);
23701 glyph
->object
= it
->object
;
23702 if (it
->pixel_width
> 0)
23704 glyph
->pixel_width
= it
->pixel_width
;
23705 glyph
->padding_p
= 0;
23709 /* Assure at least 1-pixel width. Otherwise, cursor can't
23710 be displayed correctly. */
23711 glyph
->pixel_width
= 1;
23712 glyph
->padding_p
= 1;
23714 glyph
->ascent
= it
->ascent
;
23715 glyph
->descent
= it
->descent
;
23716 glyph
->voffset
= it
->voffset
;
23717 glyph
->type
= CHAR_GLYPH
;
23718 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23719 glyph
->multibyte_p
= it
->multibyte_p
;
23720 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23722 /* In R2L rows, the left and the right box edges need to be
23723 drawn in reverse direction. */
23724 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
23725 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
23729 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23730 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23732 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
23733 || it
->phys_descent
> it
->descent
);
23734 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
23735 glyph
->face_id
= it
->face_id
;
23736 glyph
->u
.ch
= it
->char_to_display
;
23737 glyph
->slice
.img
= null_glyph_slice
;
23738 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23741 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23742 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23744 glyph
->bidi_type
= it
->bidi_it
.type
;
23748 glyph
->resolved_level
= 0;
23749 glyph
->bidi_type
= UNKNOWN_BT
;
23751 ++it
->glyph_row
->used
[area
];
23754 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23757 /* Store one glyph for the composition IT->cmp_it.id in
23758 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
23762 append_composite_glyph (struct it
*it
)
23764 struct glyph
*glyph
;
23765 enum glyph_row_area area
= it
->area
;
23767 eassert (it
->glyph_row
);
23769 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23770 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23772 /* If the glyph row is reversed, we need to prepend the glyph
23773 rather than append it. */
23774 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
23778 /* Make room for the new glyph. */
23779 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
23781 glyph
= it
->glyph_row
->glyphs
[it
->area
];
23783 glyph
->charpos
= it
->cmp_it
.charpos
;
23784 glyph
->object
= it
->object
;
23785 glyph
->pixel_width
= it
->pixel_width
;
23786 glyph
->ascent
= it
->ascent
;
23787 glyph
->descent
= it
->descent
;
23788 glyph
->voffset
= it
->voffset
;
23789 glyph
->type
= COMPOSITE_GLYPH
;
23790 if (it
->cmp_it
.ch
< 0)
23792 glyph
->u
.cmp
.automatic
= 0;
23793 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
23794 glyph
->slice
.cmp
.from
= glyph
->slice
.cmp
.to
= 0;
23798 glyph
->u
.cmp
.automatic
= 1;
23799 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
23800 glyph
->slice
.cmp
.from
= it
->cmp_it
.from
;
23801 glyph
->slice
.cmp
.to
= it
->cmp_it
.to
- 1;
23803 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23804 glyph
->multibyte_p
= it
->multibyte_p
;
23805 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23807 /* In R2L rows, the left and the right box edges need to be
23808 drawn in reverse direction. */
23809 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
23810 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
23814 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23815 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23817 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
23818 || it
->phys_descent
> it
->descent
);
23819 glyph
->padding_p
= 0;
23820 glyph
->glyph_not_available_p
= 0;
23821 glyph
->face_id
= it
->face_id
;
23822 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23825 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23826 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23828 glyph
->bidi_type
= it
->bidi_it
.type
;
23830 ++it
->glyph_row
->used
[area
];
23833 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23837 /* Change IT->ascent and IT->height according to the setting of
23841 take_vertical_position_into_account (struct it
*it
)
23845 if (it
->voffset
< 0)
23846 /* Increase the ascent so that we can display the text higher
23848 it
->ascent
-= it
->voffset
;
23850 /* Increase the descent so that we can display the text lower
23852 it
->descent
+= it
->voffset
;
23857 /* Produce glyphs/get display metrics for the image IT is loaded with.
23858 See the description of struct display_iterator in dispextern.h for
23859 an overview of struct display_iterator. */
23862 produce_image_glyph (struct it
*it
)
23866 int glyph_ascent
, crop
;
23867 struct glyph_slice slice
;
23869 eassert (it
->what
== IT_IMAGE
);
23871 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
23873 /* Make sure X resources of the face is loaded. */
23874 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
23876 if (it
->image_id
< 0)
23878 /* Fringe bitmap. */
23879 it
->ascent
= it
->phys_ascent
= 0;
23880 it
->descent
= it
->phys_descent
= 0;
23881 it
->pixel_width
= 0;
23886 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
23888 /* Make sure X resources of the image is loaded. */
23889 prepare_image_for_display (it
->f
, img
);
23891 slice
.x
= slice
.y
= 0;
23892 slice
.width
= img
->width
;
23893 slice
.height
= img
->height
;
23895 if (INTEGERP (it
->slice
.x
))
23896 slice
.x
= XINT (it
->slice
.x
);
23897 else if (FLOATP (it
->slice
.x
))
23898 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
23900 if (INTEGERP (it
->slice
.y
))
23901 slice
.y
= XINT (it
->slice
.y
);
23902 else if (FLOATP (it
->slice
.y
))
23903 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
23905 if (INTEGERP (it
->slice
.width
))
23906 slice
.width
= XINT (it
->slice
.width
);
23907 else if (FLOATP (it
->slice
.width
))
23908 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
23910 if (INTEGERP (it
->slice
.height
))
23911 slice
.height
= XINT (it
->slice
.height
);
23912 else if (FLOATP (it
->slice
.height
))
23913 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
23915 if (slice
.x
>= img
->width
)
23916 slice
.x
= img
->width
;
23917 if (slice
.y
>= img
->height
)
23918 slice
.y
= img
->height
;
23919 if (slice
.x
+ slice
.width
>= img
->width
)
23920 slice
.width
= img
->width
- slice
.x
;
23921 if (slice
.y
+ slice
.height
> img
->height
)
23922 slice
.height
= img
->height
- slice
.y
;
23924 if (slice
.width
== 0 || slice
.height
== 0)
23927 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
23929 it
->descent
= slice
.height
- glyph_ascent
;
23931 it
->descent
+= img
->vmargin
;
23932 if (slice
.y
+ slice
.height
== img
->height
)
23933 it
->descent
+= img
->vmargin
;
23934 it
->phys_descent
= it
->descent
;
23936 it
->pixel_width
= slice
.width
;
23938 it
->pixel_width
+= img
->hmargin
;
23939 if (slice
.x
+ slice
.width
== img
->width
)
23940 it
->pixel_width
+= img
->hmargin
;
23942 /* It's quite possible for images to have an ascent greater than
23943 their height, so don't get confused in that case. */
23944 if (it
->descent
< 0)
23949 if (face
->box
!= FACE_NO_BOX
)
23951 if (face
->box_line_width
> 0)
23954 it
->ascent
+= face
->box_line_width
;
23955 if (slice
.y
+ slice
.height
== img
->height
)
23956 it
->descent
+= face
->box_line_width
;
23959 if (it
->start_of_box_run_p
&& slice
.x
== 0)
23960 it
->pixel_width
+= eabs (face
->box_line_width
);
23961 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
23962 it
->pixel_width
+= eabs (face
->box_line_width
);
23965 take_vertical_position_into_account (it
);
23967 /* Automatically crop wide image glyphs at right edge so we can
23968 draw the cursor on same display row. */
23969 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
23970 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
23972 it
->pixel_width
-= crop
;
23973 slice
.width
-= crop
;
23978 struct glyph
*glyph
;
23979 enum glyph_row_area area
= it
->area
;
23981 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23982 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23984 glyph
->charpos
= CHARPOS (it
->position
);
23985 glyph
->object
= it
->object
;
23986 glyph
->pixel_width
= it
->pixel_width
;
23987 glyph
->ascent
= glyph_ascent
;
23988 glyph
->descent
= it
->descent
;
23989 glyph
->voffset
= it
->voffset
;
23990 glyph
->type
= IMAGE_GLYPH
;
23991 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23992 glyph
->multibyte_p
= it
->multibyte_p
;
23993 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23995 /* In R2L rows, the left and the right box edges need to be
23996 drawn in reverse direction. */
23997 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
23998 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24002 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24003 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24005 glyph
->overlaps_vertically_p
= 0;
24006 glyph
->padding_p
= 0;
24007 glyph
->glyph_not_available_p
= 0;
24008 glyph
->face_id
= it
->face_id
;
24009 glyph
->u
.img_id
= img
->id
;
24010 glyph
->slice
.img
= slice
;
24011 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24014 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24015 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24017 glyph
->bidi_type
= it
->bidi_it
.type
;
24019 ++it
->glyph_row
->used
[area
];
24022 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24026 #ifdef HAVE_XWIDGETS
24028 produce_xwidget_glyph (struct it
*it
)
24030 struct xwidget
* xw
;
24032 int glyph_ascent
, crop
;
24033 printf("produce_xwidget_glyph:\n");
24034 eassert (it
->what
== IT_XWIDGET
);
24036 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24038 /* Make sure X resources of the face is loaded. */
24039 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24042 it
->ascent
= it
->phys_ascent
= glyph_ascent
= xw
->height
/2;
24043 it
->descent
= xw
->height
/2;
24044 it
->phys_descent
= it
->descent
;
24045 it
->pixel_width
= xw
->width
;
24046 /* It's quite possible for images to have an ascent greater than
24047 their height, so don't get confused in that case. */
24048 if (it
->descent
< 0)
24053 if (face
->box
!= FACE_NO_BOX
)
24055 if (face
->box_line_width
> 0)
24057 it
->ascent
+= face
->box_line_width
;
24058 it
->descent
+= face
->box_line_width
;
24061 if (it
->start_of_box_run_p
)
24062 it
->pixel_width
+= eabs (face
->box_line_width
);
24063 it
->pixel_width
+= eabs (face
->box_line_width
);
24066 take_vertical_position_into_account (it
);
24068 /* Automatically crop wide image glyphs at right edge so we can
24069 draw the cursor on same display row. */
24070 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
24071 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
24073 it
->pixel_width
-= crop
;
24078 struct glyph
*glyph
;
24079 enum glyph_row_area area
= it
->area
;
24081 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24082 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24084 glyph
->charpos
= CHARPOS (it
->position
);
24085 glyph
->object
= it
->object
;
24086 glyph
->pixel_width
= it
->pixel_width
;
24087 glyph
->ascent
= glyph_ascent
;
24088 glyph
->descent
= it
->descent
;
24089 glyph
->voffset
= it
->voffset
;
24090 glyph
->type
= XWIDGET_GLYPH
;
24092 glyph
->multibyte_p
= it
->multibyte_p
;
24093 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24094 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24095 glyph
->overlaps_vertically_p
= 0;
24096 glyph
->padding_p
= 0;
24097 glyph
->glyph_not_available_p
= 0;
24098 glyph
->face_id
= it
->face_id
;
24099 glyph
->u
.xwidget
= it
->xwidget
;
24100 //assert_valid_xwidget_id(glyph->u.xwidget_id,"produce_xwidget_glyph");
24101 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24102 ++it
->glyph_row
->used
[area
];
24105 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24110 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
24111 of the glyph, WIDTH and HEIGHT are the width and height of the
24112 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
24115 append_stretch_glyph (struct it
*it
, Lisp_Object object
,
24116 int width
, int height
, int ascent
)
24118 struct glyph
*glyph
;
24119 enum glyph_row_area area
= it
->area
;
24121 eassert (ascent
>= 0 && ascent
<= height
);
24123 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24124 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24126 /* If the glyph row is reversed, we need to prepend the glyph
24127 rather than append it. */
24128 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24132 /* Make room for the additional glyph. */
24133 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
24135 glyph
= it
->glyph_row
->glyphs
[area
];
24137 glyph
->charpos
= CHARPOS (it
->position
);
24138 glyph
->object
= object
;
24139 glyph
->pixel_width
= width
;
24140 glyph
->ascent
= ascent
;
24141 glyph
->descent
= height
- ascent
;
24142 glyph
->voffset
= it
->voffset
;
24143 glyph
->type
= STRETCH_GLYPH
;
24144 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24145 glyph
->multibyte_p
= it
->multibyte_p
;
24146 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24148 /* In R2L rows, the left and the right box edges need to be
24149 drawn in reverse direction. */
24150 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24151 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24155 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24156 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24158 glyph
->overlaps_vertically_p
= 0;
24159 glyph
->padding_p
= 0;
24160 glyph
->glyph_not_available_p
= 0;
24161 glyph
->face_id
= it
->face_id
;
24162 glyph
->u
.stretch
.ascent
= ascent
;
24163 glyph
->u
.stretch
.height
= height
;
24164 glyph
->slice
.img
= null_glyph_slice
;
24165 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24168 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24169 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24171 glyph
->bidi_type
= it
->bidi_it
.type
;
24175 glyph
->resolved_level
= 0;
24176 glyph
->bidi_type
= UNKNOWN_BT
;
24178 ++it
->glyph_row
->used
[area
];
24181 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24184 #endif /* HAVE_WINDOW_SYSTEM */
24186 /* Produce a stretch glyph for iterator IT. IT->object is the value
24187 of the glyph property displayed. The value must be a list
24188 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
24191 1. `:width WIDTH' specifies that the space should be WIDTH *
24192 canonical char width wide. WIDTH may be an integer or floating
24195 2. `:relative-width FACTOR' specifies that the width of the stretch
24196 should be computed from the width of the first character having the
24197 `glyph' property, and should be FACTOR times that width.
24199 3. `:align-to HPOS' specifies that the space should be wide enough
24200 to reach HPOS, a value in canonical character units.
24202 Exactly one of the above pairs must be present.
24204 4. `:height HEIGHT' specifies that the height of the stretch produced
24205 should be HEIGHT, measured in canonical character units.
24207 5. `:relative-height FACTOR' specifies that the height of the
24208 stretch should be FACTOR times the height of the characters having
24209 the glyph property.
24211 Either none or exactly one of 4 or 5 must be present.
24213 6. `:ascent ASCENT' specifies that ASCENT percent of the height
24214 of the stretch should be used for the ascent of the stretch.
24215 ASCENT must be in the range 0 <= ASCENT <= 100. */
24218 produce_stretch_glyph (struct it
*it
)
24220 /* (space :width WIDTH :height HEIGHT ...) */
24221 Lisp_Object prop
, plist
;
24222 int width
= 0, height
= 0, align_to
= -1;
24223 int zero_width_ok_p
= 0;
24225 struct font
*font
= NULL
;
24227 #ifdef HAVE_WINDOW_SYSTEM
24229 int zero_height_ok_p
= 0;
24231 if (FRAME_WINDOW_P (it
->f
))
24233 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24234 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24235 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24239 /* List should start with `space'. */
24240 eassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
24241 plist
= XCDR (it
->object
);
24243 /* Compute the width of the stretch. */
24244 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
24245 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
24247 /* Absolute width `:width WIDTH' specified and valid. */
24248 zero_width_ok_p
= 1;
24251 #ifdef HAVE_WINDOW_SYSTEM
24252 else if (FRAME_WINDOW_P (it
->f
)
24253 && (prop
= Fplist_get (plist
, QCrelative_width
), NUMVAL (prop
) > 0))
24255 /* Relative width `:relative-width FACTOR' specified and valid.
24256 Compute the width of the characters having the `glyph'
24259 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
24262 if (it
->multibyte_p
)
24263 it2
.c
= it2
.char_to_display
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
24266 it2
.c
= it2
.char_to_display
= *p
, it2
.len
= 1;
24267 if (! ASCII_CHAR_P (it2
.c
))
24268 it2
.char_to_display
= BYTE8_TO_CHAR (it2
.c
);
24271 it2
.glyph_row
= NULL
;
24272 it2
.what
= IT_CHARACTER
;
24273 x_produce_glyphs (&it2
);
24274 width
= NUMVAL (prop
) * it2
.pixel_width
;
24276 #endif /* HAVE_WINDOW_SYSTEM */
24277 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
24278 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
24280 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
24281 align_to
= (align_to
< 0
24283 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
24284 else if (align_to
< 0)
24285 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
24286 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
24287 zero_width_ok_p
= 1;
24290 /* Nothing specified -> width defaults to canonical char width. */
24291 width
= FRAME_COLUMN_WIDTH (it
->f
);
24293 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
24296 #ifdef HAVE_WINDOW_SYSTEM
24297 /* Compute height. */
24298 if (FRAME_WINDOW_P (it
->f
))
24300 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
24301 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
24304 zero_height_ok_p
= 1;
24306 else if (prop
= Fplist_get (plist
, QCrelative_height
),
24308 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
24310 height
= FONT_HEIGHT (font
);
24312 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
24315 /* Compute percentage of height used for ascent. If
24316 `:ascent ASCENT' is present and valid, use that. Otherwise,
24317 derive the ascent from the font in use. */
24318 if (prop
= Fplist_get (plist
, QCascent
),
24319 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
24320 ascent
= height
* NUMVAL (prop
) / 100.0;
24321 else if (!NILP (prop
)
24322 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
24323 ascent
= min (max (0, (int)tem
), height
);
24325 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
24328 #endif /* HAVE_WINDOW_SYSTEM */
24331 if (width
> 0 && it
->line_wrap
!= TRUNCATE
24332 && it
->current_x
+ width
> it
->last_visible_x
)
24334 width
= it
->last_visible_x
- it
->current_x
;
24335 #ifdef HAVE_WINDOW_SYSTEM
24336 /* Subtract one more pixel from the stretch width, but only on
24337 GUI frames, since on a TTY each glyph is one "pixel" wide. */
24338 width
-= FRAME_WINDOW_P (it
->f
);
24342 if (width
> 0 && height
> 0 && it
->glyph_row
)
24344 Lisp_Object o_object
= it
->object
;
24345 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
24348 if (!STRINGP (object
))
24349 object
= it
->w
->buffer
;
24350 #ifdef HAVE_WINDOW_SYSTEM
24351 if (FRAME_WINDOW_P (it
->f
))
24352 append_stretch_glyph (it
, object
, width
, height
, ascent
);
24356 it
->object
= object
;
24357 it
->char_to_display
= ' ';
24358 it
->pixel_width
= it
->len
= 1;
24360 tty_append_glyph (it
);
24361 it
->object
= o_object
;
24365 it
->pixel_width
= width
;
24366 #ifdef HAVE_WINDOW_SYSTEM
24367 if (FRAME_WINDOW_P (it
->f
))
24369 it
->ascent
= it
->phys_ascent
= ascent
;
24370 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
24371 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
24372 take_vertical_position_into_account (it
);
24376 it
->nglyphs
= width
;
24379 /* Get information about special display element WHAT in an
24380 environment described by IT. WHAT is one of IT_TRUNCATION or
24381 IT_CONTINUATION. Maybe produce glyphs for WHAT if IT has a
24382 non-null glyph_row member. This function ensures that fields like
24383 face_id, c, len of IT are left untouched. */
24386 produce_special_glyphs (struct it
*it
, enum display_element_type what
)
24393 temp_it
.object
= make_number (0);
24394 memset (&temp_it
.current
, 0, sizeof temp_it
.current
);
24396 if (what
== IT_CONTINUATION
)
24398 /* Continuation glyph. For R2L lines, we mirror it by hand. */
24399 if (it
->bidi_it
.paragraph_dir
== R2L
)
24400 SET_GLYPH_FROM_CHAR (glyph
, '/');
24402 SET_GLYPH_FROM_CHAR (glyph
, '\\');
24404 && (gc
= DISP_CONTINUE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
24406 /* FIXME: Should we mirror GC for R2L lines? */
24407 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
24408 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
24411 else if (what
== IT_TRUNCATION
)
24413 /* Truncation glyph. */
24414 SET_GLYPH_FROM_CHAR (glyph
, '$');
24416 && (gc
= DISP_TRUNC_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
24418 /* FIXME: Should we mirror GC for R2L lines? */
24419 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
24420 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
24426 #ifdef HAVE_WINDOW_SYSTEM
24427 /* On a GUI frame, when the right fringe (left fringe for R2L rows)
24428 is turned off, we precede the truncation/continuation glyphs by a
24429 stretch glyph whose width is computed such that these special
24430 glyphs are aligned at the window margin, even when very different
24431 fonts are used in different glyph rows. */
24432 if (FRAME_WINDOW_P (temp_it
.f
)
24433 /* init_iterator calls this with it->glyph_row == NULL, and it
24434 wants only the pixel width of the truncation/continuation
24436 && temp_it
.glyph_row
24437 /* insert_left_trunc_glyphs calls us at the beginning of the
24438 row, and it has its own calculation of the stretch glyph
24440 && temp_it
.glyph_row
->used
[TEXT_AREA
] > 0
24441 && (temp_it
.glyph_row
->reversed_p
24442 ? WINDOW_LEFT_FRINGE_WIDTH (temp_it
.w
)
24443 : WINDOW_RIGHT_FRINGE_WIDTH (temp_it
.w
)) == 0)
24445 int stretch_width
= temp_it
.last_visible_x
- temp_it
.current_x
;
24447 if (stretch_width
> 0)
24449 struct face
*face
= FACE_FROM_ID (temp_it
.f
, temp_it
.face_id
);
24450 struct font
*font
=
24451 face
->font
? face
->font
: FRAME_FONT (temp_it
.f
);
24452 int stretch_ascent
=
24453 (((temp_it
.ascent
+ temp_it
.descent
)
24454 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
24456 append_stretch_glyph (&temp_it
, make_number (0), stretch_width
,
24457 temp_it
.ascent
+ temp_it
.descent
,
24464 temp_it
.what
= IT_CHARACTER
;
24466 temp_it
.c
= temp_it
.char_to_display
= GLYPH_CHAR (glyph
);
24467 temp_it
.face_id
= GLYPH_FACE (glyph
);
24468 temp_it
.len
= CHAR_BYTES (temp_it
.c
);
24470 PRODUCE_GLYPHS (&temp_it
);
24471 it
->pixel_width
= temp_it
.pixel_width
;
24472 it
->nglyphs
= temp_it
.pixel_width
;
24475 #ifdef HAVE_WINDOW_SYSTEM
24477 /* Calculate line-height and line-spacing properties.
24478 An integer value specifies explicit pixel value.
24479 A float value specifies relative value to current face height.
24480 A cons (float . face-name) specifies relative value to
24481 height of specified face font.
24483 Returns height in pixels, or nil. */
24487 calc_line_height_property (struct it
*it
, Lisp_Object val
, struct font
*font
,
24488 int boff
, int override
)
24490 Lisp_Object face_name
= Qnil
;
24491 int ascent
, descent
, height
;
24493 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
24498 face_name
= XCAR (val
);
24500 if (!NUMBERP (val
))
24501 val
= make_number (1);
24502 if (NILP (face_name
))
24504 height
= it
->ascent
+ it
->descent
;
24509 if (NILP (face_name
))
24511 font
= FRAME_FONT (it
->f
);
24512 boff
= FRAME_BASELINE_OFFSET (it
->f
);
24514 else if (EQ (face_name
, Qt
))
24523 face_id
= lookup_named_face (it
->f
, face_name
, 0);
24525 return make_number (-1);
24527 face
= FACE_FROM_ID (it
->f
, face_id
);
24530 return make_number (-1);
24531 boff
= font
->baseline_offset
;
24532 if (font
->vertical_centering
)
24533 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
24536 ascent
= FONT_BASE (font
) + boff
;
24537 descent
= FONT_DESCENT (font
) - boff
;
24541 it
->override_ascent
= ascent
;
24542 it
->override_descent
= descent
;
24543 it
->override_boff
= boff
;
24546 height
= ascent
+ descent
;
24550 height
= (int)(XFLOAT_DATA (val
) * height
);
24551 else if (INTEGERP (val
))
24552 height
*= XINT (val
);
24554 return make_number (height
);
24558 /* Append a glyph for a glyphless character to IT->glyph_row. FACE_ID
24559 is a face ID to be used for the glyph. FOR_NO_FONT is nonzero if
24560 and only if this is for a character for which no font was found.
24562 If the display method (it->glyphless_method) is
24563 GLYPHLESS_DISPLAY_ACRONYM or GLYPHLESS_DISPLAY_HEX_CODE, LEN is a
24564 length of the acronym or the hexadecimal string, UPPER_XOFF and
24565 UPPER_YOFF are pixel offsets for the upper part of the string,
24566 LOWER_XOFF and LOWER_YOFF are for the lower part.
24568 For the other display methods, LEN through LOWER_YOFF are zero. */
24571 append_glyphless_glyph (struct it
*it
, int face_id
, int for_no_font
, int len
,
24572 short upper_xoff
, short upper_yoff
,
24573 short lower_xoff
, short lower_yoff
)
24575 struct glyph
*glyph
;
24576 enum glyph_row_area area
= it
->area
;
24578 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24579 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24581 /* If the glyph row is reversed, we need to prepend the glyph
24582 rather than append it. */
24583 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24587 /* Make room for the additional glyph. */
24588 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
24590 glyph
= it
->glyph_row
->glyphs
[area
];
24592 glyph
->charpos
= CHARPOS (it
->position
);
24593 glyph
->object
= it
->object
;
24594 glyph
->pixel_width
= it
->pixel_width
;
24595 glyph
->ascent
= it
->ascent
;
24596 glyph
->descent
= it
->descent
;
24597 glyph
->voffset
= it
->voffset
;
24598 glyph
->type
= GLYPHLESS_GLYPH
;
24599 glyph
->u
.glyphless
.method
= it
->glyphless_method
;
24600 glyph
->u
.glyphless
.for_no_font
= for_no_font
;
24601 glyph
->u
.glyphless
.len
= len
;
24602 glyph
->u
.glyphless
.ch
= it
->c
;
24603 glyph
->slice
.glyphless
.upper_xoff
= upper_xoff
;
24604 glyph
->slice
.glyphless
.upper_yoff
= upper_yoff
;
24605 glyph
->slice
.glyphless
.lower_xoff
= lower_xoff
;
24606 glyph
->slice
.glyphless
.lower_yoff
= lower_yoff
;
24607 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24608 glyph
->multibyte_p
= it
->multibyte_p
;
24609 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24611 /* In R2L rows, the left and the right box edges need to be
24612 drawn in reverse direction. */
24613 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24614 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24618 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24619 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24621 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
24622 || it
->phys_descent
> it
->descent
);
24623 glyph
->padding_p
= 0;
24624 glyph
->glyph_not_available_p
= 0;
24625 glyph
->face_id
= face_id
;
24626 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24629 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24630 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24632 glyph
->bidi_type
= it
->bidi_it
.type
;
24634 ++it
->glyph_row
->used
[area
];
24637 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24641 /* Produce a glyph for a glyphless character for iterator IT.
24642 IT->glyphless_method specifies which method to use for displaying
24643 the character. See the description of enum
24644 glyphless_display_method in dispextern.h for the detail.
24646 FOR_NO_FONT is nonzero if and only if this is for a character for
24647 which no font was found. ACRONYM, if non-nil, is an acronym string
24648 for the character. */
24651 produce_glyphless_glyph (struct it
*it
, int for_no_font
, Lisp_Object acronym
)
24656 int base_width
, base_height
, width
, height
;
24657 short upper_xoff
, upper_yoff
, lower_xoff
, lower_yoff
;
24660 /* Get the metrics of the base font. We always refer to the current
24662 face
= FACE_FROM_ID (it
->f
, it
->face_id
)->ascii_face
;
24663 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24664 it
->ascent
= FONT_BASE (font
) + font
->baseline_offset
;
24665 it
->descent
= FONT_DESCENT (font
) - font
->baseline_offset
;
24666 base_height
= it
->ascent
+ it
->descent
;
24667 base_width
= font
->average_width
;
24669 /* Get a face ID for the glyph by utilizing a cache (the same way as
24670 done for `escape-glyph' in get_next_display_element). */
24671 if (it
->f
== last_glyphless_glyph_frame
24672 && it
->face_id
== last_glyphless_glyph_face_id
)
24674 face_id
= last_glyphless_glyph_merged_face_id
;
24678 /* Merge the `glyphless-char' face into the current face. */
24679 face_id
= merge_faces (it
->f
, Qglyphless_char
, 0, it
->face_id
);
24680 last_glyphless_glyph_frame
= it
->f
;
24681 last_glyphless_glyph_face_id
= it
->face_id
;
24682 last_glyphless_glyph_merged_face_id
= face_id
;
24685 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_THIN_SPACE
)
24687 it
->pixel_width
= THIN_SPACE_WIDTH
;
24689 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
24691 else if (it
->glyphless_method
== GLYPHLESS_DISPLAY_EMPTY_BOX
)
24693 width
= CHAR_WIDTH (it
->c
);
24696 else if (width
> 4)
24698 it
->pixel_width
= base_width
* width
;
24700 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
24706 unsigned int code
[6];
24708 int ascent
, descent
;
24709 struct font_metrics metrics_upper
, metrics_lower
;
24711 face
= FACE_FROM_ID (it
->f
, face_id
);
24712 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24713 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24715 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_ACRONYM
)
24717 if (! STRINGP (acronym
) && CHAR_TABLE_P (Vglyphless_char_display
))
24718 acronym
= CHAR_TABLE_REF (Vglyphless_char_display
, it
->c
);
24719 if (CONSP (acronym
))
24720 acronym
= XCAR (acronym
);
24721 str
= STRINGP (acronym
) ? SSDATA (acronym
) : "";
24725 eassert (it
->glyphless_method
== GLYPHLESS_DISPLAY_HEX_CODE
);
24726 sprintf (buf
, "%0*X", it
->c
< 0x10000 ? 4 : 6, it
->c
);
24729 for (len
= 0; str
[len
] && ASCII_BYTE_P (str
[len
]) && len
< 6; len
++)
24730 code
[len
] = font
->driver
->encode_char (font
, str
[len
]);
24731 upper_len
= (len
+ 1) / 2;
24732 font
->driver
->text_extents (font
, code
, upper_len
,
24734 font
->driver
->text_extents (font
, code
+ upper_len
, len
- upper_len
,
24739 /* +4 is for vertical bars of a box plus 1-pixel spaces at both side. */
24740 width
= max (metrics_upper
.width
, metrics_lower
.width
) + 4;
24741 upper_xoff
= upper_yoff
= 2; /* the typical case */
24742 if (base_width
>= width
)
24744 /* Align the upper to the left, the lower to the right. */
24745 it
->pixel_width
= base_width
;
24746 lower_xoff
= base_width
- 2 - metrics_lower
.width
;
24750 /* Center the shorter one. */
24751 it
->pixel_width
= width
;
24752 if (metrics_upper
.width
>= metrics_lower
.width
)
24753 lower_xoff
= (width
- metrics_lower
.width
) / 2;
24756 /* FIXME: This code doesn't look right. It formerly was
24757 missing the "lower_xoff = 0;", which couldn't have
24758 been right since it left lower_xoff uninitialized. */
24760 upper_xoff
= (width
- metrics_upper
.width
) / 2;
24764 /* +5 is for horizontal bars of a box plus 1-pixel spaces at
24765 top, bottom, and between upper and lower strings. */
24766 height
= (metrics_upper
.ascent
+ metrics_upper
.descent
24767 + metrics_lower
.ascent
+ metrics_lower
.descent
) + 5;
24768 /* Center vertically.
24769 H:base_height, D:base_descent
24770 h:height, ld:lower_descent, la:lower_ascent, ud:upper_descent
24772 ascent = - (D - H/2 - h/2 + 1); "+ 1" for rounding up
24773 descent = D - H/2 + h/2;
24774 lower_yoff = descent - 2 - ld;
24775 upper_yoff = lower_yoff - la - 1 - ud; */
24776 ascent
= - (it
->descent
- (base_height
+ height
+ 1) / 2);
24777 descent
= it
->descent
- (base_height
- height
) / 2;
24778 lower_yoff
= descent
- 2 - metrics_lower
.descent
;
24779 upper_yoff
= (lower_yoff
- metrics_lower
.ascent
- 1
24780 - metrics_upper
.descent
);
24781 /* Don't make the height shorter than the base height. */
24782 if (height
> base_height
)
24784 it
->ascent
= ascent
;
24785 it
->descent
= descent
;
24789 it
->phys_ascent
= it
->ascent
;
24790 it
->phys_descent
= it
->descent
;
24792 append_glyphless_glyph (it
, face_id
, for_no_font
, len
,
24793 upper_xoff
, upper_yoff
,
24794 lower_xoff
, lower_yoff
);
24796 take_vertical_position_into_account (it
);
24801 Produce glyphs/get display metrics for the display element IT is
24802 loaded with. See the description of struct it in dispextern.h
24803 for an overview of struct it. */
24806 x_produce_glyphs (struct it
*it
)
24808 int extra_line_spacing
= it
->extra_line_spacing
;
24810 it
->glyph_not_available_p
= 0;
24812 if (it
->what
== IT_CHARACTER
)
24815 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24816 struct font
*font
= face
->font
;
24817 struct font_metrics
*pcm
= NULL
;
24818 int boff
; /* baseline offset */
24822 /* When no suitable font is found, display this character by
24823 the method specified in the first extra slot of
24824 Vglyphless_char_display. */
24825 Lisp_Object acronym
= lookup_glyphless_char_display (-1, it
);
24827 eassert (it
->what
== IT_GLYPHLESS
);
24828 produce_glyphless_glyph (it
, 1, STRINGP (acronym
) ? acronym
: Qnil
);
24832 boff
= font
->baseline_offset
;
24833 if (font
->vertical_centering
)
24834 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
24836 if (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t')
24842 if (it
->override_ascent
>= 0)
24844 it
->ascent
= it
->override_ascent
;
24845 it
->descent
= it
->override_descent
;
24846 boff
= it
->override_boff
;
24850 it
->ascent
= FONT_BASE (font
) + boff
;
24851 it
->descent
= FONT_DESCENT (font
) - boff
;
24854 if (get_char_glyph_code (it
->char_to_display
, font
, &char2b
))
24856 pcm
= get_per_char_metric (font
, &char2b
);
24857 if (pcm
->width
== 0
24858 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
24864 it
->phys_ascent
= pcm
->ascent
+ boff
;
24865 it
->phys_descent
= pcm
->descent
- boff
;
24866 it
->pixel_width
= pcm
->width
;
24870 it
->glyph_not_available_p
= 1;
24871 it
->phys_ascent
= it
->ascent
;
24872 it
->phys_descent
= it
->descent
;
24873 it
->pixel_width
= font
->space_width
;
24876 if (it
->constrain_row_ascent_descent_p
)
24878 if (it
->descent
> it
->max_descent
)
24880 it
->ascent
+= it
->descent
- it
->max_descent
;
24881 it
->descent
= it
->max_descent
;
24883 if (it
->ascent
> it
->max_ascent
)
24885 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
24886 it
->ascent
= it
->max_ascent
;
24888 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
24889 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
24890 extra_line_spacing
= 0;
24893 /* If this is a space inside a region of text with
24894 `space-width' property, change its width. */
24895 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
24897 it
->pixel_width
*= XFLOATINT (it
->space_width
);
24899 /* If face has a box, add the box thickness to the character
24900 height. If character has a box line to the left and/or
24901 right, add the box line width to the character's width. */
24902 if (face
->box
!= FACE_NO_BOX
)
24904 int thick
= face
->box_line_width
;
24908 it
->ascent
+= thick
;
24909 it
->descent
+= thick
;
24914 if (it
->start_of_box_run_p
)
24915 it
->pixel_width
+= thick
;
24916 if (it
->end_of_box_run_p
)
24917 it
->pixel_width
+= thick
;
24920 /* If face has an overline, add the height of the overline
24921 (1 pixel) and a 1 pixel margin to the character height. */
24922 if (face
->overline_p
)
24923 it
->ascent
+= overline_margin
;
24925 if (it
->constrain_row_ascent_descent_p
)
24927 if (it
->ascent
> it
->max_ascent
)
24928 it
->ascent
= it
->max_ascent
;
24929 if (it
->descent
> it
->max_descent
)
24930 it
->descent
= it
->max_descent
;
24933 take_vertical_position_into_account (it
);
24935 /* If we have to actually produce glyphs, do it. */
24940 /* Translate a space with a `space-width' property
24941 into a stretch glyph. */
24942 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
24943 / FONT_HEIGHT (font
));
24944 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
24945 it
->ascent
+ it
->descent
, ascent
);
24950 /* If characters with lbearing or rbearing are displayed
24951 in this line, record that fact in a flag of the
24952 glyph row. This is used to optimize X output code. */
24953 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
24954 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
24956 if (! stretched_p
&& it
->pixel_width
== 0)
24957 /* We assure that all visible glyphs have at least 1-pixel
24959 it
->pixel_width
= 1;
24961 else if (it
->char_to_display
== '\n')
24963 /* A newline has no width, but we need the height of the
24964 line. But if previous part of the line sets a height,
24965 don't increase that height */
24967 Lisp_Object height
;
24968 Lisp_Object total_height
= Qnil
;
24970 it
->override_ascent
= -1;
24971 it
->pixel_width
= 0;
24974 height
= get_it_property (it
, Qline_height
);
24975 /* Split (line-height total-height) list */
24977 && CONSP (XCDR (height
))
24978 && NILP (XCDR (XCDR (height
))))
24980 total_height
= XCAR (XCDR (height
));
24981 height
= XCAR (height
);
24983 height
= calc_line_height_property (it
, height
, font
, boff
, 1);
24985 if (it
->override_ascent
>= 0)
24987 it
->ascent
= it
->override_ascent
;
24988 it
->descent
= it
->override_descent
;
24989 boff
= it
->override_boff
;
24993 it
->ascent
= FONT_BASE (font
) + boff
;
24994 it
->descent
= FONT_DESCENT (font
) - boff
;
24997 if (EQ (height
, Qt
))
24999 if (it
->descent
> it
->max_descent
)
25001 it
->ascent
+= it
->descent
- it
->max_descent
;
25002 it
->descent
= it
->max_descent
;
25004 if (it
->ascent
> it
->max_ascent
)
25006 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
25007 it
->ascent
= it
->max_ascent
;
25009 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
25010 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
25011 it
->constrain_row_ascent_descent_p
= 1;
25012 extra_line_spacing
= 0;
25016 Lisp_Object spacing
;
25018 it
->phys_ascent
= it
->ascent
;
25019 it
->phys_descent
= it
->descent
;
25021 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
25022 && face
->box
!= FACE_NO_BOX
25023 && face
->box_line_width
> 0)
25025 it
->ascent
+= face
->box_line_width
;
25026 it
->descent
+= face
->box_line_width
;
25029 && XINT (height
) > it
->ascent
+ it
->descent
)
25030 it
->ascent
= XINT (height
) - it
->descent
;
25032 if (!NILP (total_height
))
25033 spacing
= calc_line_height_property (it
, total_height
, font
, boff
, 0);
25036 spacing
= get_it_property (it
, Qline_spacing
);
25037 spacing
= calc_line_height_property (it
, spacing
, font
, boff
, 0);
25039 if (INTEGERP (spacing
))
25041 extra_line_spacing
= XINT (spacing
);
25042 if (!NILP (total_height
))
25043 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
25047 else /* i.e. (it->char_to_display == '\t') */
25049 if (font
->space_width
> 0)
25051 int tab_width
= it
->tab_width
* font
->space_width
;
25052 int x
= it
->current_x
+ it
->continuation_lines_width
;
25053 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
25055 /* If the distance from the current position to the next tab
25056 stop is less than a space character width, use the
25057 tab stop after that. */
25058 if (next_tab_x
- x
< font
->space_width
)
25059 next_tab_x
+= tab_width
;
25061 it
->pixel_width
= next_tab_x
- x
;
25063 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
25064 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
25068 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
25069 it
->ascent
+ it
->descent
, it
->ascent
);
25074 it
->pixel_width
= 0;
25079 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
25081 /* A static composition.
25083 Note: A composition is represented as one glyph in the
25084 glyph matrix. There are no padding glyphs.
25086 Important note: pixel_width, ascent, and descent are the
25087 values of what is drawn by draw_glyphs (i.e. the values of
25088 the overall glyphs composed). */
25089 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25090 int boff
; /* baseline offset */
25091 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
25092 int glyph_len
= cmp
->glyph_len
;
25093 struct font
*font
= face
->font
;
25097 /* If we have not yet calculated pixel size data of glyphs of
25098 the composition for the current face font, calculate them
25099 now. Theoretically, we have to check all fonts for the
25100 glyphs, but that requires much time and memory space. So,
25101 here we check only the font of the first glyph. This may
25102 lead to incorrect display, but it's very rare, and C-l
25103 (recenter-top-bottom) can correct the display anyway. */
25104 if (! cmp
->font
|| cmp
->font
!= font
)
25106 /* Ascent and descent of the font of the first character
25107 of this composition (adjusted by baseline offset).
25108 Ascent and descent of overall glyphs should not be less
25109 than these, respectively. */
25110 int font_ascent
, font_descent
, font_height
;
25111 /* Bounding box of the overall glyphs. */
25112 int leftmost
, rightmost
, lowest
, highest
;
25113 int lbearing
, rbearing
;
25114 int i
, width
, ascent
, descent
;
25115 int left_padded
= 0, right_padded
= 0;
25116 int c
IF_LINT (= 0); /* cmp->glyph_len can't be zero; see Bug#8512 */
25118 struct font_metrics
*pcm
;
25119 int font_not_found_p
;
25122 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
25123 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
25125 if (glyph_len
< cmp
->glyph_len
)
25127 for (i
= 0; i
< glyph_len
; i
++)
25129 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
25131 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
25136 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
25137 : IT_CHARPOS (*it
));
25138 /* If no suitable font is found, use the default font. */
25139 font_not_found_p
= font
== NULL
;
25140 if (font_not_found_p
)
25142 face
= face
->ascii_face
;
25145 boff
= font
->baseline_offset
;
25146 if (font
->vertical_centering
)
25147 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
25148 font_ascent
= FONT_BASE (font
) + boff
;
25149 font_descent
= FONT_DESCENT (font
) - boff
;
25150 font_height
= FONT_HEIGHT (font
);
25155 if (! font_not_found_p
)
25157 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
25159 pcm
= get_per_char_metric (font
, &char2b
);
25162 /* Initialize the bounding box. */
25165 width
= cmp
->glyph_len
> 0 ? pcm
->width
: 0;
25166 ascent
= pcm
->ascent
;
25167 descent
= pcm
->descent
;
25168 lbearing
= pcm
->lbearing
;
25169 rbearing
= pcm
->rbearing
;
25173 width
= cmp
->glyph_len
> 0 ? font
->space_width
: 0;
25174 ascent
= FONT_BASE (font
);
25175 descent
= FONT_DESCENT (font
);
25182 lowest
= - descent
+ boff
;
25183 highest
= ascent
+ boff
;
25185 if (! font_not_found_p
25186 && font
->default_ascent
25187 && CHAR_TABLE_P (Vuse_default_ascent
)
25188 && !NILP (Faref (Vuse_default_ascent
,
25189 make_number (it
->char_to_display
))))
25190 highest
= font
->default_ascent
+ boff
;
25192 /* Draw the first glyph at the normal position. It may be
25193 shifted to right later if some other glyphs are drawn
25195 cmp
->offsets
[i
* 2] = 0;
25196 cmp
->offsets
[i
* 2 + 1] = boff
;
25197 cmp
->lbearing
= lbearing
;
25198 cmp
->rbearing
= rbearing
;
25200 /* Set cmp->offsets for the remaining glyphs. */
25201 for (i
++; i
< glyph_len
; i
++)
25203 int left
, right
, btm
, top
;
25204 int ch
= COMPOSITION_GLYPH (cmp
, i
);
25206 struct face
*this_face
;
25210 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
25211 this_face
= FACE_FROM_ID (it
->f
, face_id
);
25212 font
= this_face
->font
;
25218 get_char_face_and_encoding (it
->f
, ch
, face_id
,
25220 pcm
= get_per_char_metric (font
, &char2b
);
25223 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
25226 width
= pcm
->width
;
25227 ascent
= pcm
->ascent
;
25228 descent
= pcm
->descent
;
25229 lbearing
= pcm
->lbearing
;
25230 rbearing
= pcm
->rbearing
;
25231 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
25233 /* Relative composition with or without
25234 alternate chars. */
25235 left
= (leftmost
+ rightmost
- width
) / 2;
25236 btm
= - descent
+ boff
;
25237 if (font
->relative_compose
25238 && (! CHAR_TABLE_P (Vignore_relative_composition
)
25239 || NILP (Faref (Vignore_relative_composition
,
25240 make_number (ch
)))))
25243 if (- descent
>= font
->relative_compose
)
25244 /* One extra pixel between two glyphs. */
25246 else if (ascent
<= 0)
25247 /* One extra pixel between two glyphs. */
25248 btm
= lowest
- 1 - ascent
- descent
;
25253 /* A composition rule is specified by an integer
25254 value that encodes global and new reference
25255 points (GREF and NREF). GREF and NREF are
25256 specified by numbers as below:
25258 0---1---2 -- ascent
25262 9--10--11 -- center
25264 ---3---4---5--- baseline
25266 6---7---8 -- descent
25268 int rule
= COMPOSITION_RULE (cmp
, i
);
25269 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
25271 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
25272 grefx
= gref
% 3, nrefx
= nref
% 3;
25273 grefy
= gref
/ 3, nrefy
= nref
/ 3;
25275 xoff
= font_height
* (xoff
- 128) / 256;
25277 yoff
= font_height
* (yoff
- 128) / 256;
25280 + grefx
* (rightmost
- leftmost
) / 2
25281 - nrefx
* width
/ 2
25284 btm
= ((grefy
== 0 ? highest
25286 : grefy
== 2 ? lowest
25287 : (highest
+ lowest
) / 2)
25288 - (nrefy
== 0 ? ascent
+ descent
25289 : nrefy
== 1 ? descent
- boff
25291 : (ascent
+ descent
) / 2)
25295 cmp
->offsets
[i
* 2] = left
;
25296 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
25298 /* Update the bounding box of the overall glyphs. */
25301 right
= left
+ width
;
25302 if (left
< leftmost
)
25304 if (right
> rightmost
)
25307 top
= btm
+ descent
+ ascent
;
25313 if (cmp
->lbearing
> left
+ lbearing
)
25314 cmp
->lbearing
= left
+ lbearing
;
25315 if (cmp
->rbearing
< left
+ rbearing
)
25316 cmp
->rbearing
= left
+ rbearing
;
25320 /* If there are glyphs whose x-offsets are negative,
25321 shift all glyphs to the right and make all x-offsets
25325 for (i
= 0; i
< cmp
->glyph_len
; i
++)
25326 cmp
->offsets
[i
* 2] -= leftmost
;
25327 rightmost
-= leftmost
;
25328 cmp
->lbearing
-= leftmost
;
25329 cmp
->rbearing
-= leftmost
;
25332 if (left_padded
&& cmp
->lbearing
< 0)
25334 for (i
= 0; i
< cmp
->glyph_len
; i
++)
25335 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
25336 rightmost
-= cmp
->lbearing
;
25337 cmp
->rbearing
-= cmp
->lbearing
;
25340 if (right_padded
&& rightmost
< cmp
->rbearing
)
25342 rightmost
= cmp
->rbearing
;
25345 cmp
->pixel_width
= rightmost
;
25346 cmp
->ascent
= highest
;
25347 cmp
->descent
= - lowest
;
25348 if (cmp
->ascent
< font_ascent
)
25349 cmp
->ascent
= font_ascent
;
25350 if (cmp
->descent
< font_descent
)
25351 cmp
->descent
= font_descent
;
25355 && (cmp
->lbearing
< 0
25356 || cmp
->rbearing
> cmp
->pixel_width
))
25357 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25359 it
->pixel_width
= cmp
->pixel_width
;
25360 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
25361 it
->descent
= it
->phys_descent
= cmp
->descent
;
25362 if (face
->box
!= FACE_NO_BOX
)
25364 int thick
= face
->box_line_width
;
25368 it
->ascent
+= thick
;
25369 it
->descent
+= thick
;
25374 if (it
->start_of_box_run_p
)
25375 it
->pixel_width
+= thick
;
25376 if (it
->end_of_box_run_p
)
25377 it
->pixel_width
+= thick
;
25380 /* If face has an overline, add the height of the overline
25381 (1 pixel) and a 1 pixel margin to the character height. */
25382 if (face
->overline_p
)
25383 it
->ascent
+= overline_margin
;
25385 take_vertical_position_into_account (it
);
25386 if (it
->ascent
< 0)
25388 if (it
->descent
< 0)
25391 if (it
->glyph_row
&& cmp
->glyph_len
> 0)
25392 append_composite_glyph (it
);
25394 else if (it
->what
== IT_COMPOSITION
)
25396 /* A dynamic (automatic) composition. */
25397 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25398 Lisp_Object gstring
;
25399 struct font_metrics metrics
;
25403 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
25405 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
25408 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
25409 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25410 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
25411 it
->descent
= it
->phys_descent
= metrics
.descent
;
25412 if (face
->box
!= FACE_NO_BOX
)
25414 int thick
= face
->box_line_width
;
25418 it
->ascent
+= thick
;
25419 it
->descent
+= thick
;
25424 if (it
->start_of_box_run_p
)
25425 it
->pixel_width
+= thick
;
25426 if (it
->end_of_box_run_p
)
25427 it
->pixel_width
+= thick
;
25429 /* If face has an overline, add the height of the overline
25430 (1 pixel) and a 1 pixel margin to the character height. */
25431 if (face
->overline_p
)
25432 it
->ascent
+= overline_margin
;
25433 take_vertical_position_into_account (it
);
25434 if (it
->ascent
< 0)
25436 if (it
->descent
< 0)
25440 append_composite_glyph (it
);
25442 else if (it
->what
== IT_GLYPHLESS
)
25443 produce_glyphless_glyph (it
, 0, Qnil
);
25444 else if (it
->what
== IT_IMAGE
)
25445 produce_image_glyph (it
);
25446 else if (it
->what
== IT_STRETCH
)
25447 produce_stretch_glyph (it
);
25448 #ifdef HAVE_XWIDGETS
25449 else if (it
->what
== IT_XWIDGET
)
25450 produce_xwidget_glyph (it
);
25453 /* Accumulate dimensions. Note: can't assume that it->descent > 0
25454 because this isn't true for images with `:ascent 100'. */
25455 eassert (it
->ascent
>= 0 && it
->descent
>= 0);
25456 if (it
->area
== TEXT_AREA
)
25457 it
->current_x
+= it
->pixel_width
;
25459 if (extra_line_spacing
> 0)
25461 it
->descent
+= extra_line_spacing
;
25462 if (extra_line_spacing
> it
->max_extra_line_spacing
)
25463 it
->max_extra_line_spacing
= extra_line_spacing
;
25466 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
25467 it
->max_descent
= max (it
->max_descent
, it
->descent
);
25468 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
25469 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
25473 Output LEN glyphs starting at START at the nominal cursor position.
25474 Advance the nominal cursor over the text. The global variable
25475 updated_window contains the window being updated, updated_row is
25476 the glyph row being updated, and updated_area is the area of that
25477 row being updated. */
25480 x_write_glyphs (struct glyph
*start
, int len
)
25482 int x
, hpos
, chpos
= updated_window
->phys_cursor
.hpos
;
25484 eassert (updated_window
&& updated_row
);
25485 /* When the window is hscrolled, cursor hpos can legitimately be out
25486 of bounds, but we draw the cursor at the corresponding window
25487 margin in that case. */
25488 if (!updated_row
->reversed_p
&& chpos
< 0)
25490 if (updated_row
->reversed_p
&& chpos
>= updated_row
->used
[TEXT_AREA
])
25491 chpos
= updated_row
->used
[TEXT_AREA
] - 1;
25495 /* Write glyphs. */
25497 hpos
= start
- updated_row
->glyphs
[updated_area
];
25498 x
= draw_glyphs (updated_window
, output_cursor
.x
,
25499 updated_row
, updated_area
,
25501 DRAW_NORMAL_TEXT
, 0);
25503 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
25504 if (updated_area
== TEXT_AREA
25505 && updated_window
->phys_cursor_on_p
25506 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
25508 && chpos
< hpos
+ len
)
25509 updated_window
->phys_cursor_on_p
= 0;
25513 /* Advance the output cursor. */
25514 output_cursor
.hpos
+= len
;
25515 output_cursor
.x
= x
;
25520 Insert LEN glyphs from START at the nominal cursor position. */
25523 x_insert_glyphs (struct glyph
*start
, int len
)
25527 int line_height
, shift_by_width
, shifted_region_width
;
25528 struct glyph_row
*row
;
25529 struct glyph
*glyph
;
25530 int frame_x
, frame_y
;
25533 eassert (updated_window
&& updated_row
);
25535 w
= updated_window
;
25536 f
= XFRAME (WINDOW_FRAME (w
));
25538 /* Get the height of the line we are in. */
25540 line_height
= row
->height
;
25542 /* Get the width of the glyphs to insert. */
25543 shift_by_width
= 0;
25544 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
25545 shift_by_width
+= glyph
->pixel_width
;
25547 /* Get the width of the region to shift right. */
25548 shifted_region_width
= (window_box_width (w
, updated_area
)
25553 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
25554 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
25556 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
25557 line_height
, shift_by_width
);
25559 /* Write the glyphs. */
25560 hpos
= start
- row
->glyphs
[updated_area
];
25561 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
25563 DRAW_NORMAL_TEXT
, 0);
25565 /* Advance the output cursor. */
25566 output_cursor
.hpos
+= len
;
25567 output_cursor
.x
+= shift_by_width
;
25573 Erase the current text line from the nominal cursor position
25574 (inclusive) to pixel column TO_X (exclusive). The idea is that
25575 everything from TO_X onward is already erased.
25577 TO_X is a pixel position relative to updated_area of
25578 updated_window. TO_X == -1 means clear to the end of this area. */
25581 x_clear_end_of_line (int to_x
)
25584 struct window
*w
= updated_window
;
25585 int max_x
, min_y
, max_y
;
25586 int from_x
, from_y
, to_y
;
25588 eassert (updated_window
&& updated_row
);
25589 f
= XFRAME (w
->frame
);
25591 if (updated_row
->full_width_p
)
25592 max_x
= WINDOW_TOTAL_WIDTH (w
);
25594 max_x
= window_box_width (w
, updated_area
);
25595 max_y
= window_text_bottom_y (w
);
25597 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
25598 of window. For TO_X > 0, truncate to end of drawing area. */
25604 to_x
= min (to_x
, max_x
);
25606 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
25608 /* Notice if the cursor will be cleared by this operation. */
25609 if (!updated_row
->full_width_p
)
25610 notice_overwritten_cursor (w
, updated_area
,
25611 output_cursor
.x
, -1,
25613 MATRIX_ROW_BOTTOM_Y (updated_row
));
25615 from_x
= output_cursor
.x
;
25617 /* Translate to frame coordinates. */
25618 if (updated_row
->full_width_p
)
25620 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
25621 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
25625 int area_left
= window_box_left (w
, updated_area
);
25626 from_x
+= area_left
;
25630 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
25631 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
25632 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
25634 /* Prevent inadvertently clearing to end of the X window. */
25635 if (to_x
> from_x
&& to_y
> from_y
)
25638 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
25639 to_x
- from_x
, to_y
- from_y
);
25644 #endif /* HAVE_WINDOW_SYSTEM */
25648 /***********************************************************************
25650 ***********************************************************************/
25652 /* Value is the internal representation of the specified cursor type
25653 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
25654 of the bar cursor. */
25656 static enum text_cursor_kinds
25657 get_specified_cursor_type (Lisp_Object arg
, int *width
)
25659 enum text_cursor_kinds type
;
25664 if (EQ (arg
, Qbox
))
25665 return FILLED_BOX_CURSOR
;
25667 if (EQ (arg
, Qhollow
))
25668 return HOLLOW_BOX_CURSOR
;
25670 if (EQ (arg
, Qbar
))
25677 && EQ (XCAR (arg
), Qbar
)
25678 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
25680 *width
= XINT (XCDR (arg
));
25684 if (EQ (arg
, Qhbar
))
25687 return HBAR_CURSOR
;
25691 && EQ (XCAR (arg
), Qhbar
)
25692 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
25694 *width
= XINT (XCDR (arg
));
25695 return HBAR_CURSOR
;
25698 /* Treat anything unknown as "hollow box cursor".
25699 It was bad to signal an error; people have trouble fixing
25700 .Xdefaults with Emacs, when it has something bad in it. */
25701 type
= HOLLOW_BOX_CURSOR
;
25706 /* Set the default cursor types for specified frame. */
25708 set_frame_cursor_types (struct frame
*f
, Lisp_Object arg
)
25713 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
25714 FRAME_CURSOR_WIDTH (f
) = width
;
25716 /* By default, set up the blink-off state depending on the on-state. */
25718 tem
= Fassoc (arg
, Vblink_cursor_alist
);
25721 FRAME_BLINK_OFF_CURSOR (f
)
25722 = get_specified_cursor_type (XCDR (tem
), &width
);
25723 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
25726 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
25730 #ifdef HAVE_WINDOW_SYSTEM
25732 /* Return the cursor we want to be displayed in window W. Return
25733 width of bar/hbar cursor through WIDTH arg. Return with
25734 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
25735 (i.e. if the `system caret' should track this cursor).
25737 In a mini-buffer window, we want the cursor only to appear if we
25738 are reading input from this window. For the selected window, we
25739 want the cursor type given by the frame parameter or buffer local
25740 setting of cursor-type. If explicitly marked off, draw no cursor.
25741 In all other cases, we want a hollow box cursor. */
25743 static enum text_cursor_kinds
25744 get_window_cursor_type (struct window
*w
, struct glyph
*glyph
, int *width
,
25745 int *active_cursor
)
25747 struct frame
*f
= XFRAME (w
->frame
);
25748 struct buffer
*b
= XBUFFER (w
->buffer
);
25749 int cursor_type
= DEFAULT_CURSOR
;
25750 Lisp_Object alt_cursor
;
25751 int non_selected
= 0;
25753 *active_cursor
= 1;
25756 if (cursor_in_echo_area
25757 && FRAME_HAS_MINIBUF_P (f
)
25758 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
25760 if (w
== XWINDOW (echo_area_window
))
25762 if (EQ (BVAR (b
, cursor_type
), Qt
) || NILP (BVAR (b
, cursor_type
)))
25764 *width
= FRAME_CURSOR_WIDTH (f
);
25765 return FRAME_DESIRED_CURSOR (f
);
25768 return get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
25771 *active_cursor
= 0;
25775 /* Detect a nonselected window or nonselected frame. */
25776 else if (w
!= XWINDOW (f
->selected_window
)
25777 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)
25779 *active_cursor
= 0;
25781 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
25787 /* Never display a cursor in a window in which cursor-type is nil. */
25788 if (NILP (BVAR (b
, cursor_type
)))
25791 /* Get the normal cursor type for this window. */
25792 if (EQ (BVAR (b
, cursor_type
), Qt
))
25794 cursor_type
= FRAME_DESIRED_CURSOR (f
);
25795 *width
= FRAME_CURSOR_WIDTH (f
);
25798 cursor_type
= get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
25800 /* Use cursor-in-non-selected-windows instead
25801 for non-selected window or frame. */
25804 alt_cursor
= BVAR (b
, cursor_in_non_selected_windows
);
25805 if (!EQ (Qt
, alt_cursor
))
25806 return get_specified_cursor_type (alt_cursor
, width
);
25807 /* t means modify the normal cursor type. */
25808 if (cursor_type
== FILLED_BOX_CURSOR
)
25809 cursor_type
= HOLLOW_BOX_CURSOR
;
25810 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
25812 return cursor_type
;
25815 /* Use normal cursor if not blinked off. */
25816 if (!w
->cursor_off_p
)
25819 #ifdef HAVE_XWIDGETS
25820 if (glyph
!= NULL
&& glyph
->type
== XWIDGET_GLYPH
){
25821 //printf("attempt xwidget cursor avoidance in get_window_cursor_type\n");
25825 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
25827 if (cursor_type
== FILLED_BOX_CURSOR
)
25829 /* Using a block cursor on large images can be very annoying.
25830 So use a hollow cursor for "large" images.
25831 If image is not transparent (no mask), also use hollow cursor. */
25832 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
25833 if (img
!= NULL
&& IMAGEP (img
->spec
))
25835 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
25836 where N = size of default frame font size.
25837 This should cover most of the "tiny" icons people may use. */
25839 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
25840 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
25841 cursor_type
= HOLLOW_BOX_CURSOR
;
25844 else if (cursor_type
!= NO_CURSOR
)
25846 /* Display current only supports BOX and HOLLOW cursors for images.
25847 So for now, unconditionally use a HOLLOW cursor when cursor is
25848 not a solid box cursor. */
25849 cursor_type
= HOLLOW_BOX_CURSOR
;
25852 return cursor_type
;
25855 /* Cursor is blinked off, so determine how to "toggle" it. */
25857 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
25858 if ((alt_cursor
= Fassoc (BVAR (b
, cursor_type
), Vblink_cursor_alist
), !NILP (alt_cursor
)))
25859 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
25861 /* Then see if frame has specified a specific blink off cursor type. */
25862 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
25864 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
25865 return FRAME_BLINK_OFF_CURSOR (f
);
25869 /* Some people liked having a permanently visible blinking cursor,
25870 while others had very strong opinions against it. So it was
25871 decided to remove it. KFS 2003-09-03 */
25873 /* Finally perform built-in cursor blinking:
25874 filled box <-> hollow box
25875 wide [h]bar <-> narrow [h]bar
25876 narrow [h]bar <-> no cursor
25877 other type <-> no cursor */
25879 if (cursor_type
== FILLED_BOX_CURSOR
)
25880 return HOLLOW_BOX_CURSOR
;
25882 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
25885 return cursor_type
;
25893 /* Notice when the text cursor of window W has been completely
25894 overwritten by a drawing operation that outputs glyphs in AREA
25895 starting at X0 and ending at X1 in the line starting at Y0 and
25896 ending at Y1. X coordinates are area-relative. X1 < 0 means all
25897 the rest of the line after X0 has been written. Y coordinates
25898 are window-relative. */
25901 notice_overwritten_cursor (struct window
*w
, enum glyph_row_area area
,
25902 int x0
, int x1
, int y0
, int y1
)
25904 int cx0
, cx1
, cy0
, cy1
;
25905 struct glyph_row
*row
;
25907 if (!w
->phys_cursor_on_p
)
25909 if (area
!= TEXT_AREA
)
25912 if (w
->phys_cursor
.vpos
< 0
25913 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
25914 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
25915 !(row
->enabled_p
&& row
->displays_text_p
)))
25918 if (row
->cursor_in_fringe_p
)
25920 row
->cursor_in_fringe_p
= 0;
25921 draw_fringe_bitmap (w
, row
, row
->reversed_p
);
25922 w
->phys_cursor_on_p
= 0;
25926 cx0
= w
->phys_cursor
.x
;
25927 cx1
= cx0
+ w
->phys_cursor_width
;
25928 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
25931 /* The cursor image will be completely removed from the
25932 screen if the output area intersects the cursor area in
25933 y-direction. When we draw in [y0 y1[, and some part of
25934 the cursor is at y < y0, that part must have been drawn
25935 before. When scrolling, the cursor is erased before
25936 actually scrolling, so we don't come here. When not
25937 scrolling, the rows above the old cursor row must have
25938 changed, and in this case these rows must have written
25939 over the cursor image.
25941 Likewise if part of the cursor is below y1, with the
25942 exception of the cursor being in the first blank row at
25943 the buffer and window end because update_text_area
25944 doesn't draw that row. (Except when it does, but
25945 that's handled in update_text_area.) */
25947 cy0
= w
->phys_cursor
.y
;
25948 cy1
= cy0
+ w
->phys_cursor_height
;
25949 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
25952 w
->phys_cursor_on_p
= 0;
25955 #endif /* HAVE_WINDOW_SYSTEM */
25958 /************************************************************************
25960 ************************************************************************/
25962 #ifdef HAVE_WINDOW_SYSTEM
25965 Fix the display of area AREA of overlapping row ROW in window W
25966 with respect to the overlapping part OVERLAPS. */
25969 x_fix_overlapping_area (struct window
*w
, struct glyph_row
*row
,
25970 enum glyph_row_area area
, int overlaps
)
25977 for (i
= 0; i
< row
->used
[area
];)
25979 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
25981 int start
= i
, start_x
= x
;
25985 x
+= row
->glyphs
[area
][i
].pixel_width
;
25988 while (i
< row
->used
[area
]
25989 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
25991 draw_glyphs (w
, start_x
, row
, area
,
25993 DRAW_NORMAL_TEXT
, overlaps
);
25997 x
+= row
->glyphs
[area
][i
].pixel_width
;
26007 Draw the cursor glyph of window W in glyph row ROW. See the
26008 comment of draw_glyphs for the meaning of HL. */
26011 draw_phys_cursor_glyph (struct window
*w
, struct glyph_row
*row
,
26012 enum draw_glyphs_face hl
)
26014 /* If cursor hpos is out of bounds, don't draw garbage. This can
26015 happen in mini-buffer windows when switching between echo area
26016 glyphs and mini-buffer. */
26017 if ((row
->reversed_p
26018 ? (w
->phys_cursor
.hpos
>= 0)
26019 : (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])))
26021 int on_p
= w
->phys_cursor_on_p
;
26023 int hpos
= w
->phys_cursor
.hpos
;
26025 /* When the window is hscrolled, cursor hpos can legitimately be
26026 out of bounds, but we draw the cursor at the corresponding
26027 window margin in that case. */
26028 if (!row
->reversed_p
&& hpos
< 0)
26030 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26031 hpos
= row
->used
[TEXT_AREA
] - 1;
26033 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
, hpos
, hpos
+ 1,
26035 w
->phys_cursor_on_p
= on_p
;
26037 if (hl
== DRAW_CURSOR
)
26038 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
26039 /* When we erase the cursor, and ROW is overlapped by other
26040 rows, make sure that these overlapping parts of other rows
26042 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
26044 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
26046 if (row
> w
->current_matrix
->rows
26047 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
26048 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
26049 OVERLAPS_ERASED_CURSOR
);
26051 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
26052 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
26053 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
26054 OVERLAPS_ERASED_CURSOR
);
26061 Erase the image of a cursor of window W from the screen. */
26064 erase_phys_cursor (struct window
*w
)
26066 struct frame
*f
= XFRAME (w
->frame
);
26067 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
26068 int hpos
= w
->phys_cursor
.hpos
;
26069 int vpos
= w
->phys_cursor
.vpos
;
26070 int mouse_face_here_p
= 0;
26071 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
26072 struct glyph_row
*cursor_row
;
26073 struct glyph
*cursor_glyph
;
26074 enum draw_glyphs_face hl
;
26076 /* No cursor displayed or row invalidated => nothing to do on the
26078 if (w
->phys_cursor_type
== NO_CURSOR
)
26079 goto mark_cursor_off
;
26081 /* VPOS >= active_glyphs->nrows means that window has been resized.
26082 Don't bother to erase the cursor. */
26083 if (vpos
>= active_glyphs
->nrows
)
26084 goto mark_cursor_off
;
26086 /* If row containing cursor is marked invalid, there is nothing we
26088 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
26089 if (!cursor_row
->enabled_p
)
26090 goto mark_cursor_off
;
26092 /* If line spacing is > 0, old cursor may only be partially visible in
26093 window after split-window. So adjust visible height. */
26094 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
26095 window_text_bottom_y (w
) - cursor_row
->y
);
26097 /* If row is completely invisible, don't attempt to delete a cursor which
26098 isn't there. This can happen if cursor is at top of a window, and
26099 we switch to a buffer with a header line in that window. */
26100 if (cursor_row
->visible_height
<= 0)
26101 goto mark_cursor_off
;
26103 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
26104 if (cursor_row
->cursor_in_fringe_p
)
26106 cursor_row
->cursor_in_fringe_p
= 0;
26107 draw_fringe_bitmap (w
, cursor_row
, cursor_row
->reversed_p
);
26108 goto mark_cursor_off
;
26111 /* This can happen when the new row is shorter than the old one.
26112 In this case, either draw_glyphs or clear_end_of_line
26113 should have cleared the cursor. Note that we wouldn't be
26114 able to erase the cursor in this case because we don't have a
26115 cursor glyph at hand. */
26116 if ((cursor_row
->reversed_p
26117 ? (w
->phys_cursor
.hpos
< 0)
26118 : (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])))
26119 goto mark_cursor_off
;
26121 /* When the window is hscrolled, cursor hpos can legitimately be out
26122 of bounds, but we draw the cursor at the corresponding window
26123 margin in that case. */
26124 if (!cursor_row
->reversed_p
&& hpos
< 0)
26126 if (cursor_row
->reversed_p
&& hpos
>= cursor_row
->used
[TEXT_AREA
])
26127 hpos
= cursor_row
->used
[TEXT_AREA
] - 1;
26129 /* If the cursor is in the mouse face area, redisplay that when
26130 we clear the cursor. */
26131 if (! NILP (hlinfo
->mouse_face_window
)
26132 && coords_in_mouse_face_p (w
, hpos
, vpos
)
26133 /* Don't redraw the cursor's spot in mouse face if it is at the
26134 end of a line (on a newline). The cursor appears there, but
26135 mouse highlighting does not. */
26136 && cursor_row
->used
[TEXT_AREA
] > hpos
&& hpos
>= 0)
26137 mouse_face_here_p
= 1;
26139 /* Maybe clear the display under the cursor. */
26140 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
26143 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
26146 cursor_glyph
= get_phys_cursor_glyph (w
);
26147 if (cursor_glyph
== NULL
)
26148 goto mark_cursor_off
;
26150 width
= cursor_glyph
->pixel_width
;
26151 left_x
= window_box_left_offset (w
, TEXT_AREA
);
26152 x
= w
->phys_cursor
.x
;
26154 width
-= left_x
- x
;
26155 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
26156 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
26157 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
26160 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
26163 /* Erase the cursor by redrawing the character underneath it. */
26164 if (mouse_face_here_p
)
26165 hl
= DRAW_MOUSE_FACE
;
26167 hl
= DRAW_NORMAL_TEXT
;
26168 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
26171 w
->phys_cursor_on_p
= 0;
26172 w
->phys_cursor_type
= NO_CURSOR
;
26177 Display or clear cursor of window W. If ON is zero, clear the
26178 cursor. If it is non-zero, display the cursor. If ON is nonzero,
26179 where to put the cursor is specified by HPOS, VPOS, X and Y. */
26182 display_and_set_cursor (struct window
*w
, int on
,
26183 int hpos
, int vpos
, int x
, int y
)
26185 struct frame
*f
= XFRAME (w
->frame
);
26186 int new_cursor_type
;
26187 int new_cursor_width
;
26189 struct glyph_row
*glyph_row
;
26190 struct glyph
*glyph
;
26192 /* This is pointless on invisible frames, and dangerous on garbaged
26193 windows and frames; in the latter case, the frame or window may
26194 be in the midst of changing its size, and x and y may be off the
26196 if (! FRAME_VISIBLE_P (f
)
26197 || FRAME_GARBAGED_P (f
)
26198 || vpos
>= w
->current_matrix
->nrows
26199 || hpos
>= w
->current_matrix
->matrix_w
)
26202 /* If cursor is off and we want it off, return quickly. */
26203 if (!on
&& !w
->phys_cursor_on_p
)
26206 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26207 /* If cursor row is not enabled, we don't really know where to
26208 display the cursor. */
26209 if (!glyph_row
->enabled_p
)
26211 w
->phys_cursor_on_p
= 0;
26216 if (!glyph_row
->exact_window_width_line_p
26217 || (0 <= hpos
&& hpos
< glyph_row
->used
[TEXT_AREA
]))
26218 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
26220 eassert (input_blocked_p ());
26222 /* Set new_cursor_type to the cursor we want to be displayed. */
26223 new_cursor_type
= get_window_cursor_type (w
, glyph
,
26224 &new_cursor_width
, &active_cursor
);
26226 /* If cursor is currently being shown and we don't want it to be or
26227 it is in the wrong place, or the cursor type is not what we want,
26229 if (w
->phys_cursor_on_p
26231 || w
->phys_cursor
.x
!= x
26232 || w
->phys_cursor
.y
!= y
26233 || new_cursor_type
!= w
->phys_cursor_type
26234 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
26235 && new_cursor_width
!= w
->phys_cursor_width
)))
26236 erase_phys_cursor (w
);
26238 /* Don't check phys_cursor_on_p here because that flag is only set
26239 to zero in some cases where we know that the cursor has been
26240 completely erased, to avoid the extra work of erasing the cursor
26241 twice. In other words, phys_cursor_on_p can be 1 and the cursor
26242 still not be visible, or it has only been partly erased. */
26245 w
->phys_cursor_ascent
= glyph_row
->ascent
;
26246 w
->phys_cursor_height
= glyph_row
->height
;
26248 /* Set phys_cursor_.* before x_draw_.* is called because some
26249 of them may need the information. */
26250 w
->phys_cursor
.x
= x
;
26251 w
->phys_cursor
.y
= glyph_row
->y
;
26252 w
->phys_cursor
.hpos
= hpos
;
26253 w
->phys_cursor
.vpos
= vpos
;
26256 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
26257 new_cursor_type
, new_cursor_width
,
26258 on
, active_cursor
);
26262 /* Switch the display of W's cursor on or off, according to the value
26266 update_window_cursor (struct window
*w
, int on
)
26268 /* Don't update cursor in windows whose frame is in the process
26269 of being deleted. */
26270 if (w
->current_matrix
)
26272 int hpos
= w
->phys_cursor
.hpos
;
26273 int vpos
= w
->phys_cursor
.vpos
;
26274 struct glyph_row
*row
;
26276 if (vpos
>= w
->current_matrix
->nrows
26277 || hpos
>= w
->current_matrix
->matrix_w
)
26280 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26282 /* When the window is hscrolled, cursor hpos can legitimately be
26283 out of bounds, but we draw the cursor at the corresponding
26284 window margin in that case. */
26285 if (!row
->reversed_p
&& hpos
< 0)
26287 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26288 hpos
= row
->used
[TEXT_AREA
] - 1;
26291 display_and_set_cursor (w
, on
, hpos
, vpos
,
26292 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
26298 /* Call update_window_cursor with parameter ON_P on all leaf windows
26299 in the window tree rooted at W. */
26302 update_cursor_in_window_tree (struct window
*w
, int on_p
)
26306 if (!NILP (w
->hchild
))
26307 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
26308 else if (!NILP (w
->vchild
))
26309 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
26311 update_window_cursor (w
, on_p
);
26313 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
26319 Display the cursor on window W, or clear it, according to ON_P.
26320 Don't change the cursor's position. */
26323 x_update_cursor (struct frame
*f
, int on_p
)
26325 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
26330 Clear the cursor of window W to background color, and mark the
26331 cursor as not shown. This is used when the text where the cursor
26332 is about to be rewritten. */
26335 x_clear_cursor (struct window
*w
)
26337 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
26338 update_window_cursor (w
, 0);
26341 #endif /* HAVE_WINDOW_SYSTEM */
26343 /* Implementation of draw_row_with_mouse_face for GUI sessions, GPM,
26346 draw_row_with_mouse_face (struct window
*w
, int start_x
, struct glyph_row
*row
,
26347 int start_hpos
, int end_hpos
,
26348 enum draw_glyphs_face draw
)
26350 #ifdef HAVE_WINDOW_SYSTEM
26351 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
26353 draw_glyphs (w
, start_x
, row
, TEXT_AREA
, start_hpos
, end_hpos
, draw
, 0);
26357 #if defined (HAVE_GPM) || defined (MSDOS) || defined (WINDOWSNT)
26358 tty_draw_row_with_mouse_face (w
, row
, start_hpos
, end_hpos
, draw
);
26362 /* Display the active region described by mouse_face_* according to DRAW. */
26365 show_mouse_face (Mouse_HLInfo
*hlinfo
, enum draw_glyphs_face draw
)
26367 struct window
*w
= XWINDOW (hlinfo
->mouse_face_window
);
26368 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
26370 if (/* If window is in the process of being destroyed, don't bother
26372 w
->current_matrix
!= NULL
26373 /* Don't update mouse highlight if hidden */
26374 && (draw
!= DRAW_MOUSE_FACE
|| !hlinfo
->mouse_face_hidden
)
26375 /* Recognize when we are called to operate on rows that don't exist
26376 anymore. This can happen when a window is split. */
26377 && hlinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
26379 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
26380 struct glyph_row
*row
, *first
, *last
;
26382 first
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
26383 last
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
26385 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
26387 int start_hpos
, end_hpos
, start_x
;
26389 /* For all but the first row, the highlight starts at column 0. */
26392 /* R2L rows have BEG and END in reversed order, but the
26393 screen drawing geometry is always left to right. So
26394 we need to mirror the beginning and end of the
26395 highlighted area in R2L rows. */
26396 if (!row
->reversed_p
)
26398 start_hpos
= hlinfo
->mouse_face_beg_col
;
26399 start_x
= hlinfo
->mouse_face_beg_x
;
26401 else if (row
== last
)
26403 start_hpos
= hlinfo
->mouse_face_end_col
;
26404 start_x
= hlinfo
->mouse_face_end_x
;
26412 else if (row
->reversed_p
&& row
== last
)
26414 start_hpos
= hlinfo
->mouse_face_end_col
;
26415 start_x
= hlinfo
->mouse_face_end_x
;
26425 if (!row
->reversed_p
)
26426 end_hpos
= hlinfo
->mouse_face_end_col
;
26427 else if (row
== first
)
26428 end_hpos
= hlinfo
->mouse_face_beg_col
;
26431 end_hpos
= row
->used
[TEXT_AREA
];
26432 if (draw
== DRAW_NORMAL_TEXT
)
26433 row
->fill_line_p
= 1; /* Clear to end of line */
26436 else if (row
->reversed_p
&& row
== first
)
26437 end_hpos
= hlinfo
->mouse_face_beg_col
;
26440 end_hpos
= row
->used
[TEXT_AREA
];
26441 if (draw
== DRAW_NORMAL_TEXT
)
26442 row
->fill_line_p
= 1; /* Clear to end of line */
26445 if (end_hpos
> start_hpos
)
26447 draw_row_with_mouse_face (w
, start_x
, row
,
26448 start_hpos
, end_hpos
, draw
);
26451 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
26455 #ifdef HAVE_WINDOW_SYSTEM
26456 /* When we've written over the cursor, arrange for it to
26457 be displayed again. */
26458 if (FRAME_WINDOW_P (f
)
26459 && phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
26461 int hpos
= w
->phys_cursor
.hpos
;
26463 /* When the window is hscrolled, cursor hpos can legitimately be
26464 out of bounds, but we draw the cursor at the corresponding
26465 window margin in that case. */
26466 if (!row
->reversed_p
&& hpos
< 0)
26468 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26469 hpos
= row
->used
[TEXT_AREA
] - 1;
26472 display_and_set_cursor (w
, 1, hpos
, w
->phys_cursor
.vpos
,
26473 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
26476 #endif /* HAVE_WINDOW_SYSTEM */
26479 #ifdef HAVE_WINDOW_SYSTEM
26480 /* Change the mouse cursor. */
26481 if (FRAME_WINDOW_P (f
))
26483 if (draw
== DRAW_NORMAL_TEXT
26484 && !EQ (hlinfo
->mouse_face_window
, f
->tool_bar_window
))
26485 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
26486 else if (draw
== DRAW_MOUSE_FACE
)
26487 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
26489 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
26491 #endif /* HAVE_WINDOW_SYSTEM */
26495 Clear out the mouse-highlighted active region.
26496 Redraw it un-highlighted first. Value is non-zero if mouse
26497 face was actually drawn unhighlighted. */
26500 clear_mouse_face (Mouse_HLInfo
*hlinfo
)
26504 if (!hlinfo
->mouse_face_hidden
&& !NILP (hlinfo
->mouse_face_window
))
26506 show_mouse_face (hlinfo
, DRAW_NORMAL_TEXT
);
26510 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
26511 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
26512 hlinfo
->mouse_face_window
= Qnil
;
26513 hlinfo
->mouse_face_overlay
= Qnil
;
26517 /* Return non-zero if the coordinates HPOS and VPOS on windows W are
26518 within the mouse face on that window. */
26520 coords_in_mouse_face_p (struct window
*w
, int hpos
, int vpos
)
26522 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
26524 /* Quickly resolve the easy cases. */
26525 if (!(WINDOWP (hlinfo
->mouse_face_window
)
26526 && XWINDOW (hlinfo
->mouse_face_window
) == w
))
26528 if (vpos
< hlinfo
->mouse_face_beg_row
26529 || vpos
> hlinfo
->mouse_face_end_row
)
26531 if (vpos
> hlinfo
->mouse_face_beg_row
26532 && vpos
< hlinfo
->mouse_face_end_row
)
26535 if (!MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
)
26537 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
26539 if (hlinfo
->mouse_face_beg_col
<= hpos
&& hpos
< hlinfo
->mouse_face_end_col
)
26542 else if ((vpos
== hlinfo
->mouse_face_beg_row
26543 && hpos
>= hlinfo
->mouse_face_beg_col
)
26544 || (vpos
== hlinfo
->mouse_face_end_row
26545 && hpos
< hlinfo
->mouse_face_end_col
))
26550 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
26552 if (hlinfo
->mouse_face_end_col
< hpos
&& hpos
<= hlinfo
->mouse_face_beg_col
)
26555 else if ((vpos
== hlinfo
->mouse_face_beg_row
26556 && hpos
<= hlinfo
->mouse_face_beg_col
)
26557 || (vpos
== hlinfo
->mouse_face_end_row
26558 && hpos
> hlinfo
->mouse_face_end_col
))
26566 Non-zero if physical cursor of window W is within mouse face. */
26569 cursor_in_mouse_face_p (struct window
*w
)
26571 int hpos
= w
->phys_cursor
.hpos
;
26572 int vpos
= w
->phys_cursor
.vpos
;
26573 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26575 /* When the window is hscrolled, cursor hpos can legitimately be out
26576 of bounds, but we draw the cursor at the corresponding window
26577 margin in that case. */
26578 if (!row
->reversed_p
&& hpos
< 0)
26580 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26581 hpos
= row
->used
[TEXT_AREA
] - 1;
26583 return coords_in_mouse_face_p (w
, hpos
, vpos
);
26588 /* Find the glyph rows START_ROW and END_ROW of window W that display
26589 characters between buffer positions START_CHARPOS and END_CHARPOS
26590 (excluding END_CHARPOS). DISP_STRING is a display string that
26591 covers these buffer positions. This is similar to
26592 row_containing_pos, but is more accurate when bidi reordering makes
26593 buffer positions change non-linearly with glyph rows. */
26595 rows_from_pos_range (struct window
*w
,
26596 ptrdiff_t start_charpos
, ptrdiff_t end_charpos
,
26597 Lisp_Object disp_string
,
26598 struct glyph_row
**start
, struct glyph_row
**end
)
26600 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26601 int last_y
= window_text_bottom_y (w
);
26602 struct glyph_row
*row
;
26607 while (!first
->enabled_p
26608 && first
< MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
26611 /* Find the START row. */
26613 row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
;
26616 /* A row can potentially be the START row if the range of the
26617 characters it displays intersects the range
26618 [START_CHARPOS..END_CHARPOS). */
26619 if (! ((start_charpos
< MATRIX_ROW_START_CHARPOS (row
)
26620 && end_charpos
< MATRIX_ROW_START_CHARPOS (row
))
26621 /* See the commentary in row_containing_pos, for the
26622 explanation of the complicated way to check whether
26623 some position is beyond the end of the characters
26624 displayed by a row. */
26625 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (row
)
26626 || (start_charpos
== MATRIX_ROW_END_CHARPOS (row
)
26627 && !row
->ends_at_zv_p
26628 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
26629 && (end_charpos
> MATRIX_ROW_END_CHARPOS (row
)
26630 || (end_charpos
== MATRIX_ROW_END_CHARPOS (row
)
26631 && !row
->ends_at_zv_p
26632 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))))
26634 /* Found a candidate row. Now make sure at least one of the
26635 glyphs it displays has a charpos from the range
26636 [START_CHARPOS..END_CHARPOS).
26638 This is not obvious because bidi reordering could make
26639 buffer positions of a row be 1,2,3,102,101,100, and if we
26640 want to highlight characters in [50..60), we don't want
26641 this row, even though [50..60) does intersect [1..103),
26642 the range of character positions given by the row's start
26643 and end positions. */
26644 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
26645 struct glyph
*e
= g
+ row
->used
[TEXT_AREA
];
26649 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
26650 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
26651 /* A glyph that comes from DISP_STRING is by
26652 definition to be highlighted. */
26653 || EQ (g
->object
, disp_string
))
26662 /* Find the END row. */
26664 /* If the last row is partially visible, start looking for END
26665 from that row, instead of starting from FIRST. */
26666 && !(row
->enabled_p
26667 && row
->y
< last_y
&& MATRIX_ROW_BOTTOM_Y (row
) > last_y
))
26669 for ( ; row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
; row
++)
26671 struct glyph_row
*next
= row
+ 1;
26672 ptrdiff_t next_start
= MATRIX_ROW_START_CHARPOS (next
);
26674 if (!next
->enabled_p
26675 || next
>= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
)
26676 /* The first row >= START whose range of displayed characters
26677 does NOT intersect the range [START_CHARPOS..END_CHARPOS]
26678 is the row END + 1. */
26679 || (start_charpos
< next_start
26680 && end_charpos
< next_start
)
26681 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (next
)
26682 || (start_charpos
== MATRIX_ROW_END_CHARPOS (next
)
26683 && !next
->ends_at_zv_p
26684 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))
26685 && (end_charpos
> MATRIX_ROW_END_CHARPOS (next
)
26686 || (end_charpos
== MATRIX_ROW_END_CHARPOS (next
)
26687 && !next
->ends_at_zv_p
26688 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))))
26695 /* If the next row's edges intersect [START_CHARPOS..END_CHARPOS],
26696 but none of the characters it displays are in the range, it is
26698 struct glyph
*g
= next
->glyphs
[TEXT_AREA
];
26699 struct glyph
*s
= g
;
26700 struct glyph
*e
= g
+ next
->used
[TEXT_AREA
];
26704 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
26705 && ((start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
26706 /* If the buffer position of the first glyph in
26707 the row is equal to END_CHARPOS, it means
26708 the last character to be highlighted is the
26709 newline of ROW, and we must consider NEXT as
26711 || (((!next
->reversed_p
&& g
== s
)
26712 || (next
->reversed_p
&& g
== e
- 1))
26713 && (g
->charpos
== end_charpos
26714 /* Special case for when NEXT is an
26715 empty line at ZV. */
26716 || (g
->charpos
== -1
26717 && !row
->ends_at_zv_p
26718 && next_start
== end_charpos
)))))
26719 /* A glyph that comes from DISP_STRING is by
26720 definition to be highlighted. */
26721 || EQ (g
->object
, disp_string
))
26730 /* The first row that ends at ZV must be the last to be
26732 else if (next
->ends_at_zv_p
)
26741 /* This function sets the mouse_face_* elements of HLINFO, assuming
26742 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
26743 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
26744 for the overlay or run of text properties specifying the mouse
26745 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
26746 before-string and after-string that must also be highlighted.
26747 DISP_STRING, if non-nil, is a display string that may cover some
26748 or all of the highlighted text. */
26751 mouse_face_from_buffer_pos (Lisp_Object window
,
26752 Mouse_HLInfo
*hlinfo
,
26753 ptrdiff_t mouse_charpos
,
26754 ptrdiff_t start_charpos
,
26755 ptrdiff_t end_charpos
,
26756 Lisp_Object before_string
,
26757 Lisp_Object after_string
,
26758 Lisp_Object disp_string
)
26760 struct window
*w
= XWINDOW (window
);
26761 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26762 struct glyph_row
*r1
, *r2
;
26763 struct glyph
*glyph
, *end
;
26764 ptrdiff_t ignore
, pos
;
26767 eassert (NILP (disp_string
) || STRINGP (disp_string
));
26768 eassert (NILP (before_string
) || STRINGP (before_string
));
26769 eassert (NILP (after_string
) || STRINGP (after_string
));
26771 /* Find the rows corresponding to START_CHARPOS and END_CHARPOS. */
26772 rows_from_pos_range (w
, start_charpos
, end_charpos
, disp_string
, &r1
, &r2
);
26774 r1
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
26775 /* If the before-string or display-string contains newlines,
26776 rows_from_pos_range skips to its last row. Move back. */
26777 if (!NILP (before_string
) || !NILP (disp_string
))
26779 struct glyph_row
*prev
;
26780 while ((prev
= r1
- 1, prev
>= first
)
26781 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
26782 && prev
->used
[TEXT_AREA
] > 0)
26784 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
26785 glyph
= beg
+ prev
->used
[TEXT_AREA
];
26786 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
26788 || !(EQ (glyph
->object
, before_string
)
26789 || EQ (glyph
->object
, disp_string
)))
26796 r2
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
26797 hlinfo
->mouse_face_past_end
= 1;
26799 else if (!NILP (after_string
))
26801 /* If the after-string has newlines, advance to its last row. */
26802 struct glyph_row
*next
;
26803 struct glyph_row
*last
26804 = MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
26806 for (next
= r2
+ 1;
26808 && next
->used
[TEXT_AREA
] > 0
26809 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
26813 /* The rest of the display engine assumes that mouse_face_beg_row is
26814 either above mouse_face_end_row or identical to it. But with
26815 bidi-reordered continued lines, the row for START_CHARPOS could
26816 be below the row for END_CHARPOS. If so, swap the rows and store
26817 them in correct order. */
26820 struct glyph_row
*tem
= r2
;
26826 hlinfo
->mouse_face_beg_y
= r1
->y
;
26827 hlinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (r1
, w
->current_matrix
);
26828 hlinfo
->mouse_face_end_y
= r2
->y
;
26829 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r2
, w
->current_matrix
);
26831 /* For a bidi-reordered row, the positions of BEFORE_STRING,
26832 AFTER_STRING, DISP_STRING, START_CHARPOS, and END_CHARPOS
26833 could be anywhere in the row and in any order. The strategy
26834 below is to find the leftmost and the rightmost glyph that
26835 belongs to either of these 3 strings, or whose position is
26836 between START_CHARPOS and END_CHARPOS, and highlight all the
26837 glyphs between those two. This may cover more than just the text
26838 between START_CHARPOS and END_CHARPOS if the range of characters
26839 strides the bidi level boundary, e.g. if the beginning is in R2L
26840 text while the end is in L2R text or vice versa. */
26841 if (!r1
->reversed_p
)
26843 /* This row is in a left to right paragraph. Scan it left to
26845 glyph
= r1
->glyphs
[TEXT_AREA
];
26846 end
= glyph
+ r1
->used
[TEXT_AREA
];
26849 /* Skip truncation glyphs at the start of the glyph row. */
26850 if (r1
->displays_text_p
)
26852 && INTEGERP (glyph
->object
)
26853 && glyph
->charpos
< 0;
26855 x
+= glyph
->pixel_width
;
26857 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
26858 or DISP_STRING, and the first glyph from buffer whose
26859 position is between START_CHARPOS and END_CHARPOS. */
26861 && !INTEGERP (glyph
->object
)
26862 && !EQ (glyph
->object
, disp_string
)
26863 && !(BUFFERP (glyph
->object
)
26864 && (glyph
->charpos
>= start_charpos
26865 && glyph
->charpos
< end_charpos
));
26868 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26869 are present at buffer positions between START_CHARPOS and
26870 END_CHARPOS, or if they come from an overlay. */
26871 if (EQ (glyph
->object
, before_string
))
26873 pos
= string_buffer_position (before_string
,
26875 /* If pos == 0, it means before_string came from an
26876 overlay, not from a buffer position. */
26877 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26880 else if (EQ (glyph
->object
, after_string
))
26882 pos
= string_buffer_position (after_string
, end_charpos
);
26883 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26886 x
+= glyph
->pixel_width
;
26888 hlinfo
->mouse_face_beg_x
= x
;
26889 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
26893 /* This row is in a right to left paragraph. Scan it right to
26897 end
= r1
->glyphs
[TEXT_AREA
] - 1;
26898 glyph
= end
+ r1
->used
[TEXT_AREA
];
26900 /* Skip truncation glyphs at the start of the glyph row. */
26901 if (r1
->displays_text_p
)
26903 && INTEGERP (glyph
->object
)
26904 && glyph
->charpos
< 0;
26908 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
26909 or DISP_STRING, and the first glyph from buffer whose
26910 position is between START_CHARPOS and END_CHARPOS. */
26912 && !INTEGERP (glyph
->object
)
26913 && !EQ (glyph
->object
, disp_string
)
26914 && !(BUFFERP (glyph
->object
)
26915 && (glyph
->charpos
>= start_charpos
26916 && glyph
->charpos
< end_charpos
));
26919 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26920 are present at buffer positions between START_CHARPOS and
26921 END_CHARPOS, or if they come from an overlay. */
26922 if (EQ (glyph
->object
, before_string
))
26924 pos
= string_buffer_position (before_string
, start_charpos
);
26925 /* If pos == 0, it means before_string came from an
26926 overlay, not from a buffer position. */
26927 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26930 else if (EQ (glyph
->object
, after_string
))
26932 pos
= string_buffer_position (after_string
, end_charpos
);
26933 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26938 glyph
++; /* first glyph to the right of the highlighted area */
26939 for (g
= r1
->glyphs
[TEXT_AREA
], x
= r1
->x
; g
< glyph
; g
++)
26940 x
+= g
->pixel_width
;
26941 hlinfo
->mouse_face_beg_x
= x
;
26942 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
26945 /* If the highlight ends in a different row, compute GLYPH and END
26946 for the end row. Otherwise, reuse the values computed above for
26947 the row where the highlight begins. */
26950 if (!r2
->reversed_p
)
26952 glyph
= r2
->glyphs
[TEXT_AREA
];
26953 end
= glyph
+ r2
->used
[TEXT_AREA
];
26958 end
= r2
->glyphs
[TEXT_AREA
] - 1;
26959 glyph
= end
+ r2
->used
[TEXT_AREA
];
26963 if (!r2
->reversed_p
)
26965 /* Skip truncation and continuation glyphs near the end of the
26966 row, and also blanks and stretch glyphs inserted by
26967 extend_face_to_end_of_line. */
26969 && INTEGERP ((end
- 1)->object
))
26971 /* Scan the rest of the glyph row from the end, looking for the
26972 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
26973 DISP_STRING, or whose position is between START_CHARPOS
26977 && !INTEGERP (end
->object
)
26978 && !EQ (end
->object
, disp_string
)
26979 && !(BUFFERP (end
->object
)
26980 && (end
->charpos
>= start_charpos
26981 && end
->charpos
< end_charpos
));
26984 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26985 are present at buffer positions between START_CHARPOS and
26986 END_CHARPOS, or if they come from an overlay. */
26987 if (EQ (end
->object
, before_string
))
26989 pos
= string_buffer_position (before_string
, start_charpos
);
26990 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26993 else if (EQ (end
->object
, after_string
))
26995 pos
= string_buffer_position (after_string
, end_charpos
);
26996 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27000 /* Find the X coordinate of the last glyph to be highlighted. */
27001 for (; glyph
<= end
; ++glyph
)
27002 x
+= glyph
->pixel_width
;
27004 hlinfo
->mouse_face_end_x
= x
;
27005 hlinfo
->mouse_face_end_col
= glyph
- r2
->glyphs
[TEXT_AREA
];
27009 /* Skip truncation and continuation glyphs near the end of the
27010 row, and also blanks and stretch glyphs inserted by
27011 extend_face_to_end_of_line. */
27015 && INTEGERP (end
->object
))
27017 x
+= end
->pixel_width
;
27020 /* Scan the rest of the glyph row from the end, looking for the
27021 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
27022 DISP_STRING, or whose position is between START_CHARPOS
27026 && !INTEGERP (end
->object
)
27027 && !EQ (end
->object
, disp_string
)
27028 && !(BUFFERP (end
->object
)
27029 && (end
->charpos
>= start_charpos
27030 && end
->charpos
< end_charpos
));
27033 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27034 are present at buffer positions between START_CHARPOS and
27035 END_CHARPOS, or if they come from an overlay. */
27036 if (EQ (end
->object
, before_string
))
27038 pos
= string_buffer_position (before_string
, start_charpos
);
27039 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27042 else if (EQ (end
->object
, after_string
))
27044 pos
= string_buffer_position (after_string
, end_charpos
);
27045 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27048 x
+= end
->pixel_width
;
27050 /* If we exited the above loop because we arrived at the last
27051 glyph of the row, and its buffer position is still not in
27052 range, it means the last character in range is the preceding
27053 newline. Bump the end column and x values to get past the
27056 && BUFFERP (end
->object
)
27057 && (end
->charpos
< start_charpos
27058 || end
->charpos
>= end_charpos
))
27060 x
+= end
->pixel_width
;
27063 hlinfo
->mouse_face_end_x
= x
;
27064 hlinfo
->mouse_face_end_col
= end
- r2
->glyphs
[TEXT_AREA
];
27067 hlinfo
->mouse_face_window
= window
;
27068 hlinfo
->mouse_face_face_id
27069 = face_at_buffer_position (w
, mouse_charpos
, 0, 0, &ignore
,
27071 !hlinfo
->mouse_face_hidden
, -1);
27072 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
27075 /* The following function is not used anymore (replaced with
27076 mouse_face_from_string_pos), but I leave it here for the time
27077 being, in case someone would. */
27079 #if 0 /* not used */
27081 /* Find the position of the glyph for position POS in OBJECT in
27082 window W's current matrix, and return in *X, *Y the pixel
27083 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
27085 RIGHT_P non-zero means return the position of the right edge of the
27086 glyph, RIGHT_P zero means return the left edge position.
27088 If no glyph for POS exists in the matrix, return the position of
27089 the glyph with the next smaller position that is in the matrix, if
27090 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
27091 exists in the matrix, return the position of the glyph with the
27092 next larger position in OBJECT.
27094 Value is non-zero if a glyph was found. */
27097 fast_find_string_pos (struct window
*w
, ptrdiff_t pos
, Lisp_Object object
,
27098 int *hpos
, int *vpos
, int *x
, int *y
, int right_p
)
27100 int yb
= window_text_bottom_y (w
);
27101 struct glyph_row
*r
;
27102 struct glyph
*best_glyph
= NULL
;
27103 struct glyph_row
*best_row
= NULL
;
27106 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27107 r
->enabled_p
&& r
->y
< yb
;
27110 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
27111 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
27114 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
27115 if (EQ (g
->object
, object
))
27117 if (g
->charpos
== pos
)
27124 else if (best_glyph
== NULL
27125 || ((eabs (g
->charpos
- pos
)
27126 < eabs (best_glyph
->charpos
- pos
))
27129 : g
->charpos
> pos
)))
27143 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
27147 *x
+= best_glyph
->pixel_width
;
27152 *vpos
= best_row
- w
->current_matrix
->rows
;
27155 return best_glyph
!= NULL
;
27157 #endif /* not used */
27159 /* Find the positions of the first and the last glyphs in window W's
27160 current matrix that occlude positions [STARTPOS..ENDPOS] in OBJECT
27161 (assumed to be a string), and return in HLINFO's mouse_face_*
27162 members the pixel and column/row coordinates of those glyphs. */
27165 mouse_face_from_string_pos (struct window
*w
, Mouse_HLInfo
*hlinfo
,
27166 Lisp_Object object
,
27167 ptrdiff_t startpos
, ptrdiff_t endpos
)
27169 int yb
= window_text_bottom_y (w
);
27170 struct glyph_row
*r
;
27171 struct glyph
*g
, *e
;
27175 /* Find the glyph row with at least one position in the range
27176 [STARTPOS..ENDPOS], and the first glyph in that row whose
27177 position belongs to that range. */
27178 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27179 r
->enabled_p
&& r
->y
< yb
;
27182 if (!r
->reversed_p
)
27184 g
= r
->glyphs
[TEXT_AREA
];
27185 e
= g
+ r
->used
[TEXT_AREA
];
27186 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
27187 if (EQ (g
->object
, object
)
27188 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
27190 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
27191 hlinfo
->mouse_face_beg_y
= r
->y
;
27192 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
27193 hlinfo
->mouse_face_beg_x
= gx
;
27202 e
= r
->glyphs
[TEXT_AREA
];
27203 g
= e
+ r
->used
[TEXT_AREA
];
27204 for ( ; g
> e
; --g
)
27205 if (EQ ((g
-1)->object
, object
)
27206 && startpos
<= (g
-1)->charpos
&& (g
-1)->charpos
<= endpos
)
27208 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
27209 hlinfo
->mouse_face_beg_y
= r
->y
;
27210 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
27211 for (gx
= r
->x
, g1
= r
->glyphs
[TEXT_AREA
]; g1
< g
; ++g1
)
27212 gx
+= g1
->pixel_width
;
27213 hlinfo
->mouse_face_beg_x
= gx
;
27225 /* Starting with the next row, look for the first row which does NOT
27226 include any glyphs whose positions are in the range. */
27227 for (++r
; r
->enabled_p
&& r
->y
< yb
; ++r
)
27229 g
= r
->glyphs
[TEXT_AREA
];
27230 e
= g
+ r
->used
[TEXT_AREA
];
27232 for ( ; g
< e
; ++g
)
27233 if (EQ (g
->object
, object
)
27234 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
27243 /* The highlighted region ends on the previous row. */
27246 /* Set the end row and its vertical pixel coordinate. */
27247 hlinfo
->mouse_face_end_row
= r
- w
->current_matrix
->rows
;
27248 hlinfo
->mouse_face_end_y
= r
->y
;
27250 /* Compute and set the end column and the end column's horizontal
27251 pixel coordinate. */
27252 if (!r
->reversed_p
)
27254 g
= r
->glyphs
[TEXT_AREA
];
27255 e
= g
+ r
->used
[TEXT_AREA
];
27256 for ( ; e
> g
; --e
)
27257 if (EQ ((e
-1)->object
, object
)
27258 && startpos
<= (e
-1)->charpos
&& (e
-1)->charpos
<= endpos
)
27260 hlinfo
->mouse_face_end_col
= e
- g
;
27262 for (gx
= r
->x
; g
< e
; ++g
)
27263 gx
+= g
->pixel_width
;
27264 hlinfo
->mouse_face_end_x
= gx
;
27268 e
= r
->glyphs
[TEXT_AREA
];
27269 g
= e
+ r
->used
[TEXT_AREA
];
27270 for (gx
= r
->x
; e
< g
; ++e
)
27272 if (EQ (e
->object
, object
)
27273 && startpos
<= e
->charpos
&& e
->charpos
<= endpos
)
27275 gx
+= e
->pixel_width
;
27277 hlinfo
->mouse_face_end_col
= e
- r
->glyphs
[TEXT_AREA
];
27278 hlinfo
->mouse_face_end_x
= gx
;
27282 #ifdef HAVE_WINDOW_SYSTEM
27284 /* See if position X, Y is within a hot-spot of an image. */
27287 on_hot_spot_p (Lisp_Object hot_spot
, int x
, int y
)
27289 if (!CONSP (hot_spot
))
27292 if (EQ (XCAR (hot_spot
), Qrect
))
27294 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
27295 Lisp_Object rect
= XCDR (hot_spot
);
27299 if (!CONSP (XCAR (rect
)))
27301 if (!CONSP (XCDR (rect
)))
27303 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
27305 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
27307 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
27309 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
27313 else if (EQ (XCAR (hot_spot
), Qcircle
))
27315 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
27316 Lisp_Object circ
= XCDR (hot_spot
);
27317 Lisp_Object lr
, lx0
, ly0
;
27319 && CONSP (XCAR (circ
))
27320 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
27321 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
27322 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
27324 double r
= XFLOATINT (lr
);
27325 double dx
= XINT (lx0
) - x
;
27326 double dy
= XINT (ly0
) - y
;
27327 return (dx
* dx
+ dy
* dy
<= r
* r
);
27330 else if (EQ (XCAR (hot_spot
), Qpoly
))
27332 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
27333 if (VECTORP (XCDR (hot_spot
)))
27335 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
27336 Lisp_Object
*poly
= v
->contents
;
27337 ptrdiff_t n
= v
->header
.size
;
27340 Lisp_Object lx
, ly
;
27343 /* Need an even number of coordinates, and at least 3 edges. */
27344 if (n
< 6 || n
& 1)
27347 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
27348 If count is odd, we are inside polygon. Pixels on edges
27349 may or may not be included depending on actual geometry of the
27351 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
27352 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
27354 x0
= XINT (lx
), y0
= XINT (ly
);
27355 for (i
= 0; i
< n
; i
+= 2)
27357 int x1
= x0
, y1
= y0
;
27358 if ((lx
= poly
[i
], !INTEGERP (lx
))
27359 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
27361 x0
= XINT (lx
), y0
= XINT (ly
);
27363 /* Does this segment cross the X line? */
27371 if (y
> y0
&& y
> y1
)
27373 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
27383 find_hot_spot (Lisp_Object map
, int x
, int y
)
27385 while (CONSP (map
))
27387 if (CONSP (XCAR (map
))
27388 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
27396 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
27398 doc
: /* Lookup in image map MAP coordinates X and Y.
27399 An image map is an alist where each element has the format (AREA ID PLIST).
27400 An AREA is specified as either a rectangle, a circle, or a polygon:
27401 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
27402 pixel coordinates of the upper left and bottom right corners.
27403 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
27404 and the radius of the circle; r may be a float or integer.
27405 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
27406 vector describes one corner in the polygon.
27407 Returns the alist element for the first matching AREA in MAP. */)
27408 (Lisp_Object map
, Lisp_Object x
, Lisp_Object y
)
27416 return find_hot_spot (map
,
27417 clip_to_bounds (INT_MIN
, XINT (x
), INT_MAX
),
27418 clip_to_bounds (INT_MIN
, XINT (y
), INT_MAX
));
27422 /* Display frame CURSOR, optionally using shape defined by POINTER. */
27424 define_frame_cursor1 (struct frame
*f
, Cursor cursor
, Lisp_Object pointer
)
27426 /* Do not change cursor shape while dragging mouse. */
27427 if (!NILP (do_mouse_tracking
))
27430 if (!NILP (pointer
))
27432 if (EQ (pointer
, Qarrow
))
27433 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27434 else if (EQ (pointer
, Qhand
))
27435 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
27436 else if (EQ (pointer
, Qtext
))
27437 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
27438 else if (EQ (pointer
, intern ("hdrag")))
27439 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
27440 #ifdef HAVE_X_WINDOWS
27441 else if (EQ (pointer
, intern ("vdrag")))
27442 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
27444 else if (EQ (pointer
, intern ("hourglass")))
27445 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
27446 else if (EQ (pointer
, Qmodeline
))
27447 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
27449 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27452 if (cursor
!= No_Cursor
)
27453 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
27456 #endif /* HAVE_WINDOW_SYSTEM */
27458 /* Take proper action when mouse has moved to the mode or header line
27459 or marginal area AREA of window W, x-position X and y-position Y.
27460 X is relative to the start of the text display area of W, so the
27461 width of bitmap areas and scroll bars must be subtracted to get a
27462 position relative to the start of the mode line. */
27465 note_mode_line_or_margin_highlight (Lisp_Object window
, int x
, int y
,
27466 enum window_part area
)
27468 struct window
*w
= XWINDOW (window
);
27469 struct frame
*f
= XFRAME (w
->frame
);
27470 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
27471 #ifdef HAVE_WINDOW_SYSTEM
27472 Display_Info
*dpyinfo
;
27474 Cursor cursor
= No_Cursor
;
27475 Lisp_Object pointer
= Qnil
;
27476 int dx
, dy
, width
, height
;
27478 Lisp_Object string
, object
= Qnil
;
27479 Lisp_Object pos
IF_LINT (= Qnil
), help
;
27481 Lisp_Object mouse_face
;
27482 int original_x_pixel
= x
;
27483 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
27484 struct glyph_row
*row
IF_LINT (= 0);
27486 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
27491 /* Kludge alert: mode_line_string takes X/Y in pixels, but
27492 returns them in row/column units! */
27493 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
27494 &object
, &dx
, &dy
, &width
, &height
);
27496 row
= (area
== ON_MODE_LINE
27497 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
27498 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
27500 /* Find the glyph under the mouse pointer. */
27501 if (row
->mode_line_p
&& row
->enabled_p
)
27503 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
27504 end
= glyph
+ row
->used
[TEXT_AREA
];
27506 for (x0
= original_x_pixel
;
27507 glyph
< end
&& x0
>= glyph
->pixel_width
;
27509 x0
-= glyph
->pixel_width
;
27517 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
27518 /* Kludge alert: marginal_area_string takes X/Y in pixels, but
27519 returns them in row/column units! */
27520 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
27521 &object
, &dx
, &dy
, &width
, &height
);
27526 #ifdef HAVE_WINDOW_SYSTEM
27527 if (IMAGEP (object
))
27529 Lisp_Object image_map
, hotspot
;
27530 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
27532 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
27534 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
27538 /* Could check XCAR (hotspot) to see if we enter/leave this hot-spot.
27539 If so, we could look for mouse-enter, mouse-leave
27540 properties in PLIST (and do something...). */
27541 hotspot
= XCDR (hotspot
);
27542 if (CONSP (hotspot
)
27543 && (plist
= XCAR (hotspot
), CONSP (plist
)))
27545 pointer
= Fplist_get (plist
, Qpointer
);
27546 if (NILP (pointer
))
27548 help
= Fplist_get (plist
, Qhelp_echo
);
27551 help_echo_string
= help
;
27552 XSETWINDOW (help_echo_window
, w
);
27553 help_echo_object
= w
->buffer
;
27554 help_echo_pos
= charpos
;
27558 if (NILP (pointer
))
27559 pointer
= Fplist_get (XCDR (object
), QCpointer
);
27561 #endif /* HAVE_WINDOW_SYSTEM */
27563 if (STRINGP (string
))
27564 pos
= make_number (charpos
);
27566 /* Set the help text and mouse pointer. If the mouse is on a part
27567 of the mode line without any text (e.g. past the right edge of
27568 the mode line text), use the default help text and pointer. */
27569 if (STRINGP (string
) || area
== ON_MODE_LINE
)
27571 /* Arrange to display the help by setting the global variables
27572 help_echo_string, help_echo_object, and help_echo_pos. */
27575 if (STRINGP (string
))
27576 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
27580 help_echo_string
= help
;
27581 XSETWINDOW (help_echo_window
, w
);
27582 help_echo_object
= string
;
27583 help_echo_pos
= charpos
;
27585 else if (area
== ON_MODE_LINE
)
27587 Lisp_Object default_help
27588 = buffer_local_value_1 (Qmode_line_default_help_echo
,
27591 if (STRINGP (default_help
))
27593 help_echo_string
= default_help
;
27594 XSETWINDOW (help_echo_window
, w
);
27595 help_echo_object
= Qnil
;
27596 help_echo_pos
= -1;
27601 #ifdef HAVE_WINDOW_SYSTEM
27602 /* Change the mouse pointer according to what is under it. */
27603 if (FRAME_WINDOW_P (f
))
27605 dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
27606 if (STRINGP (string
))
27608 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27610 if (NILP (pointer
))
27611 pointer
= Fget_text_property (pos
, Qpointer
, string
);
27613 /* Change the mouse pointer according to what is under X/Y. */
27615 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
27618 map
= Fget_text_property (pos
, Qlocal_map
, string
);
27619 if (!KEYMAPP (map
))
27620 map
= Fget_text_property (pos
, Qkeymap
, string
);
27621 if (!KEYMAPP (map
))
27622 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
27626 /* Default mode-line pointer. */
27627 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
27632 /* Change the mouse face according to what is under X/Y. */
27633 if (STRINGP (string
))
27635 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
27636 if (!NILP (mouse_face
)
27637 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
27642 struct glyph
* tmp_glyph
;
27646 int total_pixel_width
;
27647 ptrdiff_t begpos
, endpos
, ignore
;
27651 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
27652 Qmouse_face
, string
, Qnil
);
27658 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
27660 endpos
= SCHARS (string
);
27664 /* Calculate the glyph position GPOS of GLYPH in the
27665 displayed string, relative to the beginning of the
27666 highlighted part of the string.
27668 Note: GPOS is different from CHARPOS. CHARPOS is the
27669 position of GLYPH in the internal string object. A mode
27670 line string format has structures which are converted to
27671 a flattened string by the Emacs Lisp interpreter. The
27672 internal string is an element of those structures. The
27673 displayed string is the flattened string. */
27674 tmp_glyph
= row_start_glyph
;
27675 while (tmp_glyph
< glyph
27676 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
27677 && begpos
<= tmp_glyph
->charpos
27678 && tmp_glyph
->charpos
< endpos
)))
27680 gpos
= glyph
- tmp_glyph
;
27682 /* Calculate the length GSEQ_LENGTH of the glyph sequence of
27683 the highlighted part of the displayed string to which
27684 GLYPH belongs. Note: GSEQ_LENGTH is different from
27685 SCHARS (STRING), because the latter returns the length of
27686 the internal string. */
27687 for (tmp_glyph
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
27689 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
27690 && begpos
<= tmp_glyph
->charpos
27691 && tmp_glyph
->charpos
< endpos
));
27694 gseq_length
= gpos
+ (tmp_glyph
- glyph
) + 1;
27696 /* Calculate the total pixel width of all the glyphs between
27697 the beginning of the highlighted area and GLYPH. */
27698 total_pixel_width
= 0;
27699 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
27700 total_pixel_width
+= tmp_glyph
->pixel_width
;
27702 /* Pre calculation of re-rendering position. Note: X is in
27703 column units here, after the call to mode_line_string or
27704 marginal_area_string. */
27706 vpos
= (area
== ON_MODE_LINE
27707 ? (w
->current_matrix
)->nrows
- 1
27710 /* If GLYPH's position is included in the region that is
27711 already drawn in mouse face, we have nothing to do. */
27712 if ( EQ (window
, hlinfo
->mouse_face_window
)
27713 && (!row
->reversed_p
27714 ? (hlinfo
->mouse_face_beg_col
<= hpos
27715 && hpos
< hlinfo
->mouse_face_end_col
)
27716 /* In R2L rows we swap BEG and END, see below. */
27717 : (hlinfo
->mouse_face_end_col
<= hpos
27718 && hpos
< hlinfo
->mouse_face_beg_col
))
27719 && hlinfo
->mouse_face_beg_row
== vpos
)
27722 if (clear_mouse_face (hlinfo
))
27723 cursor
= No_Cursor
;
27725 if (!row
->reversed_p
)
27727 hlinfo
->mouse_face_beg_col
= hpos
;
27728 hlinfo
->mouse_face_beg_x
= original_x_pixel
27729 - (total_pixel_width
+ dx
);
27730 hlinfo
->mouse_face_end_col
= hpos
+ gseq_length
;
27731 hlinfo
->mouse_face_end_x
= 0;
27735 /* In R2L rows, show_mouse_face expects BEG and END
27736 coordinates to be swapped. */
27737 hlinfo
->mouse_face_end_col
= hpos
;
27738 hlinfo
->mouse_face_end_x
= original_x_pixel
27739 - (total_pixel_width
+ dx
);
27740 hlinfo
->mouse_face_beg_col
= hpos
+ gseq_length
;
27741 hlinfo
->mouse_face_beg_x
= 0;
27744 hlinfo
->mouse_face_beg_row
= vpos
;
27745 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_beg_row
;
27746 hlinfo
->mouse_face_beg_y
= 0;
27747 hlinfo
->mouse_face_end_y
= 0;
27748 hlinfo
->mouse_face_past_end
= 0;
27749 hlinfo
->mouse_face_window
= window
;
27751 hlinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
27757 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
27759 if (NILP (pointer
))
27762 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
27763 clear_mouse_face (hlinfo
);
27765 #ifdef HAVE_WINDOW_SYSTEM
27766 if (FRAME_WINDOW_P (f
))
27767 define_frame_cursor1 (f
, cursor
, pointer
);
27773 Take proper action when the mouse has moved to position X, Y on
27774 frame F as regards highlighting characters that have mouse-face
27775 properties. Also de-highlighting chars where the mouse was before.
27776 X and Y can be negative or out of range. */
27779 note_mouse_highlight (struct frame
*f
, int x
, int y
)
27781 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
27782 enum window_part part
= ON_NOTHING
;
27783 Lisp_Object window
;
27785 Cursor cursor
= No_Cursor
;
27786 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
27789 /* When a menu is active, don't highlight because this looks odd. */
27790 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (MSDOS)
27791 if (popup_activated ())
27795 if (NILP (Vmouse_highlight
)
27796 || !f
->glyphs_initialized_p
27797 || f
->pointer_invisible
)
27800 hlinfo
->mouse_face_mouse_x
= x
;
27801 hlinfo
->mouse_face_mouse_y
= y
;
27802 hlinfo
->mouse_face_mouse_frame
= f
;
27804 if (hlinfo
->mouse_face_defer
)
27807 /* Which window is that in? */
27808 window
= window_from_coordinates (f
, x
, y
, &part
, 1);
27810 /* If displaying active text in another window, clear that. */
27811 if (! EQ (window
, hlinfo
->mouse_face_window
)
27812 /* Also clear if we move out of text area in same window. */
27813 || (!NILP (hlinfo
->mouse_face_window
)
27816 && part
!= ON_MODE_LINE
27817 && part
!= ON_HEADER_LINE
))
27818 clear_mouse_face (hlinfo
);
27820 /* Not on a window -> return. */
27821 if (!WINDOWP (window
))
27824 /* Reset help_echo_string. It will get recomputed below. */
27825 help_echo_string
= Qnil
;
27827 /* Convert to window-relative pixel coordinates. */
27828 w
= XWINDOW (window
);
27829 frame_to_window_pixel_xy (w
, &x
, &y
);
27831 #ifdef HAVE_WINDOW_SYSTEM
27832 /* Handle tool-bar window differently since it doesn't display a
27834 if (EQ (window
, f
->tool_bar_window
))
27836 note_tool_bar_highlight (f
, x
, y
);
27841 /* Mouse is on the mode, header line or margin? */
27842 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
27843 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
27845 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
27849 #ifdef HAVE_WINDOW_SYSTEM
27850 if (part
== ON_VERTICAL_BORDER
)
27852 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
27853 help_echo_string
= build_string ("drag-mouse-1: resize");
27855 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
27856 || part
== ON_SCROLL_BAR
)
27857 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27859 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
27862 /* Are we in a window whose display is up to date?
27863 And verify the buffer's text has not changed. */
27864 b
= XBUFFER (w
->buffer
);
27865 if (part
== ON_TEXT
27866 && w
->window_end_valid
27867 && w
->last_modified
== BUF_MODIFF (b
)
27868 && w
->last_overlay_modified
== BUF_OVERLAY_MODIFF (b
))
27870 int hpos
, vpos
, dx
, dy
, area
= LAST_AREA
;
27872 struct glyph
*glyph
;
27873 Lisp_Object object
;
27874 Lisp_Object mouse_face
= Qnil
, position
;
27875 Lisp_Object
*overlay_vec
= NULL
;
27876 ptrdiff_t i
, noverlays
;
27877 struct buffer
*obuf
;
27878 ptrdiff_t obegv
, ozv
;
27881 /* Find the glyph under X/Y. */
27882 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
27884 #ifdef HAVE_WINDOW_SYSTEM
27885 /* Look for :pointer property on image. */
27886 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
27888 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
27889 if (img
!= NULL
&& IMAGEP (img
->spec
))
27891 Lisp_Object image_map
, hotspot
;
27892 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
27894 && (hotspot
= find_hot_spot (image_map
,
27895 glyph
->slice
.img
.x
+ dx
,
27896 glyph
->slice
.img
.y
+ dy
),
27898 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
27902 /* Could check XCAR (hotspot) to see if we enter/leave
27904 If so, we could look for mouse-enter, mouse-leave
27905 properties in PLIST (and do something...). */
27906 hotspot
= XCDR (hotspot
);
27907 if (CONSP (hotspot
)
27908 && (plist
= XCAR (hotspot
), CONSP (plist
)))
27910 pointer
= Fplist_get (plist
, Qpointer
);
27911 if (NILP (pointer
))
27913 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
27914 if (!NILP (help_echo_string
))
27916 help_echo_window
= window
;
27917 help_echo_object
= glyph
->object
;
27918 help_echo_pos
= glyph
->charpos
;
27922 if (NILP (pointer
))
27923 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
27926 #endif /* HAVE_WINDOW_SYSTEM */
27928 /* Clear mouse face if X/Y not over text. */
27930 || area
!= TEXT_AREA
27931 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
27932 /* Glyph's OBJECT is an integer for glyphs inserted by the
27933 display engine for its internal purposes, like truncation
27934 and continuation glyphs and blanks beyond the end of
27935 line's text on text terminals. If we are over such a
27936 glyph, we are not over any text. */
27937 || INTEGERP (glyph
->object
)
27938 /* R2L rows have a stretch glyph at their front, which
27939 stands for no text, whereas L2R rows have no glyphs at
27940 all beyond the end of text. Treat such stretch glyphs
27941 like we do with NULL glyphs in L2R rows. */
27942 || (MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
27943 && glyph
== MATRIX_ROW (w
->current_matrix
, vpos
)->glyphs
[TEXT_AREA
]
27944 && glyph
->type
== STRETCH_GLYPH
27945 && glyph
->avoid_cursor_p
))
27947 if (clear_mouse_face (hlinfo
))
27948 cursor
= No_Cursor
;
27949 #ifdef HAVE_WINDOW_SYSTEM
27950 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
27952 if (area
!= TEXT_AREA
)
27953 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27955 pointer
= Vvoid_text_area_pointer
;
27961 pos
= glyph
->charpos
;
27962 object
= glyph
->object
;
27963 if (!STRINGP (object
) && !BUFFERP (object
))
27966 /* If we get an out-of-range value, return now; avoid an error. */
27967 if (BUFFERP (object
) && pos
> BUF_Z (b
))
27970 /* Make the window's buffer temporarily current for
27971 overlays_at and compute_char_face. */
27972 obuf
= current_buffer
;
27973 current_buffer
= b
;
27979 /* Is this char mouse-active or does it have help-echo? */
27980 position
= make_number (pos
);
27982 if (BUFFERP (object
))
27984 /* Put all the overlays we want in a vector in overlay_vec. */
27985 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
27986 /* Sort overlays into increasing priority order. */
27987 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
27992 same_region
= coords_in_mouse_face_p (w
, hpos
, vpos
);
27995 cursor
= No_Cursor
;
27997 /* Check mouse-face highlighting. */
27999 /* If there exists an overlay with mouse-face overlapping
28000 the one we are currently highlighting, we have to
28001 check if we enter the overlapping overlay, and then
28002 highlight only that. */
28003 || (OVERLAYP (hlinfo
->mouse_face_overlay
)
28004 && mouse_face_overlay_overlaps (hlinfo
->mouse_face_overlay
)))
28006 /* Find the highest priority overlay with a mouse-face. */
28007 Lisp_Object overlay
= Qnil
;
28008 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
28010 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
28011 if (!NILP (mouse_face
))
28012 overlay
= overlay_vec
[i
];
28015 /* If we're highlighting the same overlay as before, there's
28016 no need to do that again. */
28017 if (!NILP (overlay
) && EQ (overlay
, hlinfo
->mouse_face_overlay
))
28018 goto check_help_echo
;
28019 hlinfo
->mouse_face_overlay
= overlay
;
28021 /* Clear the display of the old active region, if any. */
28022 if (clear_mouse_face (hlinfo
))
28023 cursor
= No_Cursor
;
28025 /* If no overlay applies, get a text property. */
28026 if (NILP (overlay
))
28027 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
28029 /* Next, compute the bounds of the mouse highlighting and
28031 if (!NILP (mouse_face
) && STRINGP (object
))
28033 /* The mouse-highlighting comes from a display string
28034 with a mouse-face. */
28038 s
= Fprevious_single_property_change
28039 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
28040 e
= Fnext_single_property_change
28041 (position
, Qmouse_face
, object
, Qnil
);
28043 s
= make_number (0);
28045 e
= make_number (SCHARS (object
) - 1);
28046 mouse_face_from_string_pos (w
, hlinfo
, object
,
28047 XINT (s
), XINT (e
));
28048 hlinfo
->mouse_face_past_end
= 0;
28049 hlinfo
->mouse_face_window
= window
;
28050 hlinfo
->mouse_face_face_id
28051 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
28052 glyph
->face_id
, 1);
28053 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
28054 cursor
= No_Cursor
;
28058 /* The mouse-highlighting, if any, comes from an overlay
28059 or text property in the buffer. */
28060 Lisp_Object buffer
IF_LINT (= Qnil
);
28061 Lisp_Object disp_string
IF_LINT (= Qnil
);
28063 if (STRINGP (object
))
28065 /* If we are on a display string with no mouse-face,
28066 check if the text under it has one. */
28067 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
28068 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28069 pos
= string_buffer_position (object
, start
);
28072 mouse_face
= get_char_property_and_overlay
28073 (make_number (pos
), Qmouse_face
, w
->buffer
, &overlay
);
28074 buffer
= w
->buffer
;
28075 disp_string
= object
;
28081 disp_string
= Qnil
;
28084 if (!NILP (mouse_face
))
28086 Lisp_Object before
, after
;
28087 Lisp_Object before_string
, after_string
;
28088 /* To correctly find the limits of mouse highlight
28089 in a bidi-reordered buffer, we must not use the
28090 optimization of limiting the search in
28091 previous-single-property-change and
28092 next-single-property-change, because
28093 rows_from_pos_range needs the real start and end
28094 positions to DTRT in this case. That's because
28095 the first row visible in a window does not
28096 necessarily display the character whose position
28097 is the smallest. */
28099 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
28100 ? Fmarker_position (w
->start
)
28103 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
28104 ? make_number (BUF_Z (XBUFFER (buffer
))
28105 - XFASTINT (w
->window_end_pos
))
28108 if (NILP (overlay
))
28110 /* Handle the text property case. */
28111 before
= Fprevious_single_property_change
28112 (make_number (pos
+ 1), Qmouse_face
, buffer
, lim1
);
28113 after
= Fnext_single_property_change
28114 (make_number (pos
), Qmouse_face
, buffer
, lim2
);
28115 before_string
= after_string
= Qnil
;
28119 /* Handle the overlay case. */
28120 before
= Foverlay_start (overlay
);
28121 after
= Foverlay_end (overlay
);
28122 before_string
= Foverlay_get (overlay
, Qbefore_string
);
28123 after_string
= Foverlay_get (overlay
, Qafter_string
);
28125 if (!STRINGP (before_string
)) before_string
= Qnil
;
28126 if (!STRINGP (after_string
)) after_string
= Qnil
;
28129 mouse_face_from_buffer_pos (window
, hlinfo
, pos
,
28132 : XFASTINT (before
),
28134 ? BUF_Z (XBUFFER (buffer
))
28135 : XFASTINT (after
),
28136 before_string
, after_string
,
28138 cursor
= No_Cursor
;
28145 /* Look for a `help-echo' property. */
28146 if (NILP (help_echo_string
)) {
28147 Lisp_Object help
, overlay
;
28149 /* Check overlays first. */
28150 help
= overlay
= Qnil
;
28151 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
28153 overlay
= overlay_vec
[i
];
28154 help
= Foverlay_get (overlay
, Qhelp_echo
);
28159 help_echo_string
= help
;
28160 help_echo_window
= window
;
28161 help_echo_object
= overlay
;
28162 help_echo_pos
= pos
;
28166 Lisp_Object obj
= glyph
->object
;
28167 ptrdiff_t charpos
= glyph
->charpos
;
28169 /* Try text properties. */
28172 && charpos
< SCHARS (obj
))
28174 help
= Fget_text_property (make_number (charpos
),
28178 /* If the string itself doesn't specify a help-echo,
28179 see if the buffer text ``under'' it does. */
28180 struct glyph_row
*r
28181 = MATRIX_ROW (w
->current_matrix
, vpos
);
28182 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28183 ptrdiff_t p
= string_buffer_position (obj
, start
);
28186 help
= Fget_char_property (make_number (p
),
28187 Qhelp_echo
, w
->buffer
);
28196 else if (BUFFERP (obj
)
28199 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
28204 help_echo_string
= help
;
28205 help_echo_window
= window
;
28206 help_echo_object
= obj
;
28207 help_echo_pos
= charpos
;
28212 #ifdef HAVE_WINDOW_SYSTEM
28213 /* Look for a `pointer' property. */
28214 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
28216 /* Check overlays first. */
28217 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
28218 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
28220 if (NILP (pointer
))
28222 Lisp_Object obj
= glyph
->object
;
28223 ptrdiff_t charpos
= glyph
->charpos
;
28225 /* Try text properties. */
28228 && charpos
< SCHARS (obj
))
28230 pointer
= Fget_text_property (make_number (charpos
),
28232 if (NILP (pointer
))
28234 /* If the string itself doesn't specify a pointer,
28235 see if the buffer text ``under'' it does. */
28236 struct glyph_row
*r
28237 = MATRIX_ROW (w
->current_matrix
, vpos
);
28238 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28239 ptrdiff_t p
= string_buffer_position (obj
, start
);
28241 pointer
= Fget_char_property (make_number (p
),
28242 Qpointer
, w
->buffer
);
28245 else if (BUFFERP (obj
)
28248 pointer
= Fget_text_property (make_number (charpos
),
28252 #endif /* HAVE_WINDOW_SYSTEM */
28256 current_buffer
= obuf
;
28261 #ifdef HAVE_WINDOW_SYSTEM
28262 if (FRAME_WINDOW_P (f
))
28263 define_frame_cursor1 (f
, cursor
, pointer
);
28265 /* This is here to prevent a compiler error, about "label at end of
28266 compound statement". */
28273 Clear any mouse-face on window W. This function is part of the
28274 redisplay interface, and is called from try_window_id and similar
28275 functions to ensure the mouse-highlight is off. */
28278 x_clear_window_mouse_face (struct window
*w
)
28280 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
28281 Lisp_Object window
;
28284 XSETWINDOW (window
, w
);
28285 if (EQ (window
, hlinfo
->mouse_face_window
))
28286 clear_mouse_face (hlinfo
);
28292 Just discard the mouse face information for frame F, if any.
28293 This is used when the size of F is changed. */
28296 cancel_mouse_face (struct frame
*f
)
28298 Lisp_Object window
;
28299 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28301 window
= hlinfo
->mouse_face_window
;
28302 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
28304 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
28305 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
28306 hlinfo
->mouse_face_window
= Qnil
;
28312 /***********************************************************************
28314 ***********************************************************************/
28316 #ifdef HAVE_WINDOW_SYSTEM
28318 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
28319 which intersects rectangle R. R is in window-relative coordinates. */
28322 expose_area (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
,
28323 enum glyph_row_area area
)
28325 struct glyph
*first
= row
->glyphs
[area
];
28326 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
28327 struct glyph
*last
;
28328 int first_x
, start_x
, x
;
28330 if (area
== TEXT_AREA
&& row
->fill_line_p
)
28331 /* If row extends face to end of line write the whole line. */
28332 draw_glyphs (w
, 0, row
, area
,
28333 0, row
->used
[area
],
28334 DRAW_NORMAL_TEXT
, 0);
28337 /* Set START_X to the window-relative start position for drawing glyphs of
28338 AREA. The first glyph of the text area can be partially visible.
28339 The first glyphs of other areas cannot. */
28340 start_x
= window_box_left_offset (w
, area
);
28342 if (area
== TEXT_AREA
)
28345 /* Find the first glyph that must be redrawn. */
28347 && x
+ first
->pixel_width
< r
->x
)
28349 x
+= first
->pixel_width
;
28353 /* Find the last one. */
28357 && x
< r
->x
+ r
->width
)
28359 x
+= last
->pixel_width
;
28365 draw_glyphs (w
, first_x
- start_x
, row
, area
,
28366 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
28367 DRAW_NORMAL_TEXT
, 0);
28372 /* Redraw the parts of the glyph row ROW on window W intersecting
28373 rectangle R. R is in window-relative coordinates. Value is
28374 non-zero if mouse-face was overwritten. */
28377 expose_line (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
)
28379 eassert (row
->enabled_p
);
28381 if (row
->mode_line_p
|| w
->pseudo_window_p
)
28382 draw_glyphs (w
, 0, row
, TEXT_AREA
,
28383 0, row
->used
[TEXT_AREA
],
28384 DRAW_NORMAL_TEXT
, 0);
28387 if (row
->used
[LEFT_MARGIN_AREA
])
28388 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
28389 if (row
->used
[TEXT_AREA
])
28390 expose_area (w
, row
, r
, TEXT_AREA
);
28391 if (row
->used
[RIGHT_MARGIN_AREA
])
28392 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
28393 draw_row_fringe_bitmaps (w
, row
);
28396 return row
->mouse_face_p
;
28400 /* Redraw those parts of glyphs rows during expose event handling that
28401 overlap other rows. Redrawing of an exposed line writes over parts
28402 of lines overlapping that exposed line; this function fixes that.
28404 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
28405 row in W's current matrix that is exposed and overlaps other rows.
28406 LAST_OVERLAPPING_ROW is the last such row. */
28409 expose_overlaps (struct window
*w
,
28410 struct glyph_row
*first_overlapping_row
,
28411 struct glyph_row
*last_overlapping_row
,
28414 struct glyph_row
*row
;
28416 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
28417 if (row
->overlapping_p
)
28419 eassert (row
->enabled_p
&& !row
->mode_line_p
);
28422 if (row
->used
[LEFT_MARGIN_AREA
])
28423 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
28425 if (row
->used
[TEXT_AREA
])
28426 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
28428 if (row
->used
[RIGHT_MARGIN_AREA
])
28429 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
28435 /* Return non-zero if W's cursor intersects rectangle R. */
28438 phys_cursor_in_rect_p (struct window
*w
, XRectangle
*r
)
28440 XRectangle cr
, result
;
28441 struct glyph
*cursor_glyph
;
28442 struct glyph_row
*row
;
28444 if (w
->phys_cursor
.vpos
>= 0
28445 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
28446 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
28448 && row
->cursor_in_fringe_p
)
28450 /* Cursor is in the fringe. */
28451 cr
.x
= window_box_right_offset (w
,
28452 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
28453 ? RIGHT_MARGIN_AREA
28456 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
28457 cr
.height
= row
->height
;
28458 return x_intersect_rectangles (&cr
, r
, &result
);
28461 cursor_glyph
= get_phys_cursor_glyph (w
);
28464 /* r is relative to W's box, but w->phys_cursor.x is relative
28465 to left edge of W's TEXT area. Adjust it. */
28466 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
28467 cr
.y
= w
->phys_cursor
.y
;
28468 cr
.width
= cursor_glyph
->pixel_width
;
28469 cr
.height
= w
->phys_cursor_height
;
28470 /* ++KFS: W32 version used W32-specific IntersectRect here, but
28471 I assume the effect is the same -- and this is portable. */
28472 return x_intersect_rectangles (&cr
, r
, &result
);
28474 /* If we don't understand the format, pretend we're not in the hot-spot. */
28480 Draw a vertical window border to the right of window W if W doesn't
28481 have vertical scroll bars. */
28484 x_draw_vertical_border (struct window
*w
)
28486 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
28488 /* We could do better, if we knew what type of scroll-bar the adjacent
28489 windows (on either side) have... But we don't :-(
28490 However, I think this works ok. ++KFS 2003-04-25 */
28492 /* Redraw borders between horizontally adjacent windows. Don't
28493 do it for frames with vertical scroll bars because either the
28494 right scroll bar of a window, or the left scroll bar of its
28495 neighbor will suffice as a border. */
28496 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
28499 /* Note: It is necessary to redraw both the left and the right
28500 borders, for when only this single window W is being
28502 if (!WINDOW_RIGHTMOST_P (w
)
28503 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
28505 int x0
, x1
, y0
, y1
;
28507 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
28510 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
28513 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
28515 if (!WINDOW_LEFTMOST_P (w
)
28516 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
28518 int x0
, x1
, y0
, y1
;
28520 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
28523 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
28526 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
28531 /* Redraw the part of window W intersection rectangle FR. Pixel
28532 coordinates in FR are frame-relative. Call this function with
28533 input blocked. Value is non-zero if the exposure overwrites
28537 expose_window (struct window
*w
, XRectangle
*fr
)
28539 struct frame
*f
= XFRAME (w
->frame
);
28541 int mouse_face_overwritten_p
= 0;
28543 /* If window is not yet fully initialized, do nothing. This can
28544 happen when toolkit scroll bars are used and a window is split.
28545 Reconfiguring the scroll bar will generate an expose for a newly
28547 if (w
->current_matrix
== NULL
)
28550 /* When we're currently updating the window, display and current
28551 matrix usually don't agree. Arrange for a thorough display
28553 if (w
== updated_window
)
28555 SET_FRAME_GARBAGED (f
);
28559 /* Frame-relative pixel rectangle of W. */
28560 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
28561 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
28562 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
28563 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
28565 if (x_intersect_rectangles (fr
, &wr
, &r
))
28567 int yb
= window_text_bottom_y (w
);
28568 struct glyph_row
*row
;
28569 int cursor_cleared_p
, phys_cursor_on_p
;
28570 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
28572 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
28573 r
.x
, r
.y
, r
.width
, r
.height
));
28575 /* Convert to window coordinates. */
28576 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
28577 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
28579 /* Turn off the cursor. */
28580 if (!w
->pseudo_window_p
28581 && phys_cursor_in_rect_p (w
, &r
))
28583 x_clear_cursor (w
);
28584 cursor_cleared_p
= 1;
28587 cursor_cleared_p
= 0;
28589 /* If the row containing the cursor extends face to end of line,
28590 then expose_area might overwrite the cursor outside the
28591 rectangle and thus notice_overwritten_cursor might clear
28592 w->phys_cursor_on_p. We remember the original value and
28593 check later if it is changed. */
28594 phys_cursor_on_p
= w
->phys_cursor_on_p
;
28596 /* Update lines intersecting rectangle R. */
28597 first_overlapping_row
= last_overlapping_row
= NULL
;
28598 for (row
= w
->current_matrix
->rows
;
28603 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
28605 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
28606 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
28607 || (r
.y
>= y0
&& r
.y
< y1
)
28608 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
28610 /* A header line may be overlapping, but there is no need
28611 to fix overlapping areas for them. KFS 2005-02-12 */
28612 if (row
->overlapping_p
&& !row
->mode_line_p
)
28614 if (first_overlapping_row
== NULL
)
28615 first_overlapping_row
= row
;
28616 last_overlapping_row
= row
;
28620 if (expose_line (w
, row
, &r
))
28621 mouse_face_overwritten_p
= 1;
28624 else if (row
->overlapping_p
)
28626 /* We must redraw a row overlapping the exposed area. */
28628 ? y0
+ row
->phys_height
> r
.y
28629 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
28631 if (first_overlapping_row
== NULL
)
28632 first_overlapping_row
= row
;
28633 last_overlapping_row
= row
;
28641 /* Display the mode line if there is one. */
28642 if (WINDOW_WANTS_MODELINE_P (w
)
28643 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
28645 && row
->y
< r
.y
+ r
.height
)
28647 if (expose_line (w
, row
, &r
))
28648 mouse_face_overwritten_p
= 1;
28651 if (!w
->pseudo_window_p
)
28653 /* Fix the display of overlapping rows. */
28654 if (first_overlapping_row
)
28655 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
28658 /* Draw border between windows. */
28659 x_draw_vertical_border (w
);
28661 /* Turn the cursor on again. */
28662 if (cursor_cleared_p
28663 || (phys_cursor_on_p
&& !w
->phys_cursor_on_p
))
28664 update_window_cursor (w
, 1);
28668 return mouse_face_overwritten_p
;
28673 /* Redraw (parts) of all windows in the window tree rooted at W that
28674 intersect R. R contains frame pixel coordinates. Value is
28675 non-zero if the exposure overwrites mouse-face. */
28678 expose_window_tree (struct window
*w
, XRectangle
*r
)
28680 struct frame
*f
= XFRAME (w
->frame
);
28681 int mouse_face_overwritten_p
= 0;
28683 while (w
&& !FRAME_GARBAGED_P (f
))
28685 if (!NILP (w
->hchild
))
28686 mouse_face_overwritten_p
28687 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
28688 else if (!NILP (w
->vchild
))
28689 mouse_face_overwritten_p
28690 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
28692 mouse_face_overwritten_p
|= expose_window (w
, r
);
28694 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
28697 return mouse_face_overwritten_p
;
28702 Redisplay an exposed area of frame F. X and Y are the upper-left
28703 corner of the exposed rectangle. W and H are width and height of
28704 the exposed area. All are pixel values. W or H zero means redraw
28705 the entire frame. */
28708 expose_frame (struct frame
*f
, int x
, int y
, int w
, int h
)
28711 int mouse_face_overwritten_p
= 0;
28713 TRACE ((stderr
, "expose_frame "));
28715 /* No need to redraw if frame will be redrawn soon. */
28716 if (FRAME_GARBAGED_P (f
))
28718 TRACE ((stderr
, " garbaged\n"));
28722 /* If basic faces haven't been realized yet, there is no point in
28723 trying to redraw anything. This can happen when we get an expose
28724 event while Emacs is starting, e.g. by moving another window. */
28725 if (FRAME_FACE_CACHE (f
) == NULL
28726 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
28728 TRACE ((stderr
, " no faces\n"));
28732 if (w
== 0 || h
== 0)
28735 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
28736 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
28746 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
28747 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
28749 if (WINDOWP (f
->tool_bar_window
))
28750 mouse_face_overwritten_p
28751 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
28753 #ifdef HAVE_X_WINDOWS
28755 #ifndef USE_X_TOOLKIT
28756 if (WINDOWP (f
->menu_bar_window
))
28757 mouse_face_overwritten_p
28758 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
28759 #endif /* not USE_X_TOOLKIT */
28763 /* Some window managers support a focus-follows-mouse style with
28764 delayed raising of frames. Imagine a partially obscured frame,
28765 and moving the mouse into partially obscured mouse-face on that
28766 frame. The visible part of the mouse-face will be highlighted,
28767 then the WM raises the obscured frame. With at least one WM, KDE
28768 2.1, Emacs is not getting any event for the raising of the frame
28769 (even tried with SubstructureRedirectMask), only Expose events.
28770 These expose events will draw text normally, i.e. not
28771 highlighted. Which means we must redo the highlight here.
28772 Subsume it under ``we love X''. --gerd 2001-08-15 */
28773 /* Included in Windows version because Windows most likely does not
28774 do the right thing if any third party tool offers
28775 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
28776 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
28778 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28779 if (f
== hlinfo
->mouse_face_mouse_frame
)
28781 int mouse_x
= hlinfo
->mouse_face_mouse_x
;
28782 int mouse_y
= hlinfo
->mouse_face_mouse_y
;
28783 clear_mouse_face (hlinfo
);
28784 note_mouse_highlight (f
, mouse_x
, mouse_y
);
28791 Determine the intersection of two rectangles R1 and R2. Return
28792 the intersection in *RESULT. Value is non-zero if RESULT is not
28796 x_intersect_rectangles (XRectangle
*r1
, XRectangle
*r2
, XRectangle
*result
)
28798 XRectangle
*left
, *right
;
28799 XRectangle
*upper
, *lower
;
28800 int intersection_p
= 0;
28802 /* Rearrange so that R1 is the left-most rectangle. */
28804 left
= r1
, right
= r2
;
28806 left
= r2
, right
= r1
;
28808 /* X0 of the intersection is right.x0, if this is inside R1,
28809 otherwise there is no intersection. */
28810 if (right
->x
<= left
->x
+ left
->width
)
28812 result
->x
= right
->x
;
28814 /* The right end of the intersection is the minimum of
28815 the right ends of left and right. */
28816 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
28819 /* Same game for Y. */
28821 upper
= r1
, lower
= r2
;
28823 upper
= r2
, lower
= r1
;
28825 /* The upper end of the intersection is lower.y0, if this is inside
28826 of upper. Otherwise, there is no intersection. */
28827 if (lower
->y
<= upper
->y
+ upper
->height
)
28829 result
->y
= lower
->y
;
28831 /* The lower end of the intersection is the minimum of the lower
28832 ends of upper and lower. */
28833 result
->height
= (min (lower
->y
+ lower
->height
,
28834 upper
->y
+ upper
->height
)
28836 intersection_p
= 1;
28840 return intersection_p
;
28843 #endif /* HAVE_WINDOW_SYSTEM */
28846 /***********************************************************************
28848 ***********************************************************************/
28851 syms_of_xdisp (void)
28853 Vwith_echo_area_save_vector
= Qnil
;
28854 staticpro (&Vwith_echo_area_save_vector
);
28856 Vmessage_stack
= Qnil
;
28857 staticpro (&Vmessage_stack
);
28859 DEFSYM (Qinhibit_redisplay
, "inhibit-redisplay");
28860 DEFSYM (Qredisplay_internal
, "redisplay_internal (C function)");
28862 message_dolog_marker1
= Fmake_marker ();
28863 staticpro (&message_dolog_marker1
);
28864 message_dolog_marker2
= Fmake_marker ();
28865 staticpro (&message_dolog_marker2
);
28866 message_dolog_marker3
= Fmake_marker ();
28867 staticpro (&message_dolog_marker3
);
28870 defsubr (&Sdump_frame_glyph_matrix
);
28871 defsubr (&Sdump_glyph_matrix
);
28872 defsubr (&Sdump_glyph_row
);
28873 defsubr (&Sdump_tool_bar_row
);
28874 defsubr (&Strace_redisplay
);
28875 defsubr (&Strace_to_stderr
);
28877 #ifdef HAVE_WINDOW_SYSTEM
28878 defsubr (&Stool_bar_lines_needed
);
28879 defsubr (&Slookup_image_map
);
28881 defsubr (&Sformat_mode_line
);
28882 defsubr (&Sinvisible_p
);
28883 defsubr (&Scurrent_bidi_paragraph_direction
);
28885 DEFSYM (Qmenu_bar_update_hook
, "menu-bar-update-hook");
28886 DEFSYM (Qoverriding_terminal_local_map
, "overriding-terminal-local-map");
28887 DEFSYM (Qoverriding_local_map
, "overriding-local-map");
28888 DEFSYM (Qwindow_scroll_functions
, "window-scroll-functions");
28889 DEFSYM (Qwindow_text_change_functions
, "window-text-change-functions");
28890 DEFSYM (Qredisplay_end_trigger_functions
, "redisplay-end-trigger-functions");
28891 DEFSYM (Qinhibit_point_motion_hooks
, "inhibit-point-motion-hooks");
28892 DEFSYM (Qeval
, "eval");
28893 DEFSYM (QCdata
, ":data");
28894 DEFSYM (Qdisplay
, "display");
28895 DEFSYM (Qspace_width
, "space-width");
28896 DEFSYM (Qraise
, "raise");
28897 DEFSYM (Qslice
, "slice");
28898 DEFSYM (Qspace
, "space");
28899 DEFSYM (Qmargin
, "margin");
28900 DEFSYM (Qpointer
, "pointer");
28901 DEFSYM (Qleft_margin
, "left-margin");
28902 DEFSYM (Qright_margin
, "right-margin");
28903 DEFSYM (Qcenter
, "center");
28904 DEFSYM (Qline_height
, "line-height");
28905 DEFSYM (QCalign_to
, ":align-to");
28906 DEFSYM (QCrelative_width
, ":relative-width");
28907 DEFSYM (QCrelative_height
, ":relative-height");
28908 DEFSYM (QCeval
, ":eval");
28909 DEFSYM (QCpropertize
, ":propertize");
28910 DEFSYM (QCfile
, ":file");
28911 DEFSYM (Qfontified
, "fontified");
28912 DEFSYM (Qfontification_functions
, "fontification-functions");
28913 DEFSYM (Qtrailing_whitespace
, "trailing-whitespace");
28914 DEFSYM (Qescape_glyph
, "escape-glyph");
28915 DEFSYM (Qnobreak_space
, "nobreak-space");
28916 DEFSYM (Qimage
, "image");
28917 DEFSYM (Qtext
, "text");
28918 DEFSYM (Qboth
, "both");
28919 DEFSYM (Qboth_horiz
, "both-horiz");
28920 DEFSYM (Qtext_image_horiz
, "text-image-horiz");
28921 DEFSYM (QCmap
, ":map");
28922 DEFSYM (QCpointer
, ":pointer");
28923 DEFSYM (Qrect
, "rect");
28924 DEFSYM (Qcircle
, "circle");
28925 DEFSYM (Qpoly
, "poly");
28926 DEFSYM (Qmessage_truncate_lines
, "message-truncate-lines");
28927 DEFSYM (Qgrow_only
, "grow-only");
28928 DEFSYM (Qinhibit_menubar_update
, "inhibit-menubar-update");
28929 DEFSYM (Qinhibit_eval_during_redisplay
, "inhibit-eval-during-redisplay");
28930 DEFSYM (Qposition
, "position");
28931 DEFSYM (Qbuffer_position
, "buffer-position");
28932 DEFSYM (Qobject
, "object");
28933 DEFSYM (Qbar
, "bar");
28934 DEFSYM (Qhbar
, "hbar");
28935 DEFSYM (Qbox
, "box");
28936 DEFSYM (Qhollow
, "hollow");
28937 DEFSYM (Qhand
, "hand");
28938 DEFSYM (Qarrow
, "arrow");
28939 DEFSYM (Qinhibit_free_realized_faces
, "inhibit-free-realized-faces");
28941 list_of_error
= Fcons (Fcons (intern_c_string ("error"),
28942 Fcons (intern_c_string ("void-variable"), Qnil
)),
28944 staticpro (&list_of_error
);
28946 DEFSYM (Qlast_arrow_position
, "last-arrow-position");
28947 DEFSYM (Qlast_arrow_string
, "last-arrow-string");
28948 DEFSYM (Qoverlay_arrow_string
, "overlay-arrow-string");
28949 DEFSYM (Qoverlay_arrow_bitmap
, "overlay-arrow-bitmap");
28951 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
28952 staticpro (&echo_buffer
[0]);
28953 staticpro (&echo_buffer
[1]);
28955 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
28956 staticpro (&echo_area_buffer
[0]);
28957 staticpro (&echo_area_buffer
[1]);
28959 Vmessages_buffer_name
= build_pure_c_string ("*Messages*");
28960 staticpro (&Vmessages_buffer_name
);
28962 mode_line_proptrans_alist
= Qnil
;
28963 staticpro (&mode_line_proptrans_alist
);
28964 mode_line_string_list
= Qnil
;
28965 staticpro (&mode_line_string_list
);
28966 mode_line_string_face
= Qnil
;
28967 staticpro (&mode_line_string_face
);
28968 mode_line_string_face_prop
= Qnil
;
28969 staticpro (&mode_line_string_face_prop
);
28970 Vmode_line_unwind_vector
= Qnil
;
28971 staticpro (&Vmode_line_unwind_vector
);
28973 DEFSYM (Qmode_line_default_help_echo
, "mode-line-default-help-echo");
28975 help_echo_string
= Qnil
;
28976 staticpro (&help_echo_string
);
28977 help_echo_object
= Qnil
;
28978 staticpro (&help_echo_object
);
28979 help_echo_window
= Qnil
;
28980 staticpro (&help_echo_window
);
28981 previous_help_echo_string
= Qnil
;
28982 staticpro (&previous_help_echo_string
);
28983 help_echo_pos
= -1;
28985 DEFSYM (Qright_to_left
, "right-to-left");
28986 DEFSYM (Qleft_to_right
, "left-to-right");
28988 #ifdef HAVE_WINDOW_SYSTEM
28989 DEFVAR_BOOL ("x-stretch-cursor", x_stretch_cursor_p
,
28990 doc
: /* Non-nil means draw block cursor as wide as the glyph under it.
28991 For example, if a block cursor is over a tab, it will be drawn as
28992 wide as that tab on the display. */);
28993 x_stretch_cursor_p
= 0;
28996 DEFVAR_LISP ("show-trailing-whitespace", Vshow_trailing_whitespace
,
28997 doc
: /* Non-nil means highlight trailing whitespace.
28998 The face used for trailing whitespace is `trailing-whitespace'. */);
28999 Vshow_trailing_whitespace
= Qnil
;
29001 DEFVAR_LISP ("nobreak-char-display", Vnobreak_char_display
,
29002 doc
: /* Control highlighting of non-ASCII space and hyphen chars.
29003 If the value is t, Emacs highlights non-ASCII chars which have the
29004 same appearance as an ASCII space or hyphen, using the `nobreak-space'
29005 or `escape-glyph' face respectively.
29007 U+00A0 (no-break space), U+00AD (soft hyphen), U+2010 (hyphen), and
29008 U+2011 (non-breaking hyphen) are affected.
29010 Any other non-nil value means to display these characters as a escape
29011 glyph followed by an ordinary space or hyphen.
29013 A value of nil means no special handling of these characters. */);
29014 Vnobreak_char_display
= Qt
;
29016 DEFVAR_LISP ("void-text-area-pointer", Vvoid_text_area_pointer
,
29017 doc
: /* The pointer shape to show in void text areas.
29018 A value of nil means to show the text pointer. Other options are `arrow',
29019 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
29020 Vvoid_text_area_pointer
= Qarrow
;
29022 DEFVAR_LISP ("inhibit-redisplay", Vinhibit_redisplay
,
29023 doc
: /* Non-nil means don't actually do any redisplay.
29024 This is used for internal purposes. */);
29025 Vinhibit_redisplay
= Qnil
;
29027 DEFVAR_LISP ("global-mode-string", Vglobal_mode_string
,
29028 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
29029 Vglobal_mode_string
= Qnil
;
29031 DEFVAR_LISP ("overlay-arrow-position", Voverlay_arrow_position
,
29032 doc
: /* Marker for where to display an arrow on top of the buffer text.
29033 This must be the beginning of a line in order to work.
29034 See also `overlay-arrow-string'. */);
29035 Voverlay_arrow_position
= Qnil
;
29037 DEFVAR_LISP ("overlay-arrow-string", Voverlay_arrow_string
,
29038 doc
: /* String to display as an arrow in non-window frames.
29039 See also `overlay-arrow-position'. */);
29040 Voverlay_arrow_string
= build_pure_c_string ("=>");
29042 DEFVAR_LISP ("overlay-arrow-variable-list", Voverlay_arrow_variable_list
,
29043 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
29044 The symbols on this list are examined during redisplay to determine
29045 where to display overlay arrows. */);
29046 Voverlay_arrow_variable_list
29047 = Fcons (intern_c_string ("overlay-arrow-position"), Qnil
);
29049 DEFVAR_INT ("scroll-step", emacs_scroll_step
,
29050 doc
: /* The number of lines to try scrolling a window by when point moves out.
29051 If that fails to bring point back on frame, point is centered instead.
29052 If this is zero, point is always centered after it moves off frame.
29053 If you want scrolling to always be a line at a time, you should set
29054 `scroll-conservatively' to a large value rather than set this to 1. */);
29056 DEFVAR_INT ("scroll-conservatively", scroll_conservatively
,
29057 doc
: /* Scroll up to this many lines, to bring point back on screen.
29058 If point moves off-screen, redisplay will scroll by up to
29059 `scroll-conservatively' lines in order to bring point just barely
29060 onto the screen again. If that cannot be done, then redisplay
29061 recenters point as usual.
29063 If the value is greater than 100, redisplay will never recenter point,
29064 but will always scroll just enough text to bring point into view, even
29065 if you move far away.
29067 A value of zero means always recenter point if it moves off screen. */);
29068 scroll_conservatively
= 0;
29070 DEFVAR_INT ("scroll-margin", scroll_margin
,
29071 doc
: /* Number of lines of margin at the top and bottom of a window.
29072 Recenter the window whenever point gets within this many lines
29073 of the top or bottom of the window. */);
29076 DEFVAR_LISP ("display-pixels-per-inch", Vdisplay_pixels_per_inch
,
29077 doc
: /* Pixels per inch value for non-window system displays.
29078 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
29079 Vdisplay_pixels_per_inch
= make_float (72.0);
29082 DEFVAR_INT ("debug-end-pos", debug_end_pos
, doc
: /* Don't ask. */);
29085 DEFVAR_LISP ("truncate-partial-width-windows",
29086 Vtruncate_partial_width_windows
,
29087 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
29088 For an integer value, truncate lines in each window narrower than the
29089 full frame width, provided the window width is less than that integer;
29090 otherwise, respect the value of `truncate-lines'.
29092 For any other non-nil value, truncate lines in all windows that do
29093 not span the full frame width.
29095 A value of nil means to respect the value of `truncate-lines'.
29097 If `word-wrap' is enabled, you might want to reduce this. */);
29098 Vtruncate_partial_width_windows
= make_number (50);
29100 DEFVAR_LISP ("line-number-display-limit", Vline_number_display_limit
,
29101 doc
: /* Maximum buffer size for which line number should be displayed.
29102 If the buffer is bigger than this, the line number does not appear
29103 in the mode line. A value of nil means no limit. */);
29104 Vline_number_display_limit
= Qnil
;
29106 DEFVAR_INT ("line-number-display-limit-width",
29107 line_number_display_limit_width
,
29108 doc
: /* Maximum line width (in characters) for line number display.
29109 If the average length of the lines near point is bigger than this, then the
29110 line number may be omitted from the mode line. */);
29111 line_number_display_limit_width
= 200;
29113 DEFVAR_BOOL ("highlight-nonselected-windows", highlight_nonselected_windows
,
29114 doc
: /* Non-nil means highlight region even in nonselected windows. */);
29115 highlight_nonselected_windows
= 0;
29117 DEFVAR_BOOL ("multiple-frames", multiple_frames
,
29118 doc
: /* Non-nil if more than one frame is visible on this display.
29119 Minibuffer-only frames don't count, but iconified frames do.
29120 This variable is not guaranteed to be accurate except while processing
29121 `frame-title-format' and `icon-title-format'. */);
29123 DEFVAR_LISP ("frame-title-format", Vframe_title_format
,
29124 doc
: /* Template for displaying the title bar of visible frames.
29125 \(Assuming the window manager supports this feature.)
29127 This variable has the same structure as `mode-line-format', except that
29128 the %c and %l constructs are ignored. It is used only on frames for
29129 which no explicit name has been set \(see `modify-frame-parameters'). */);
29131 DEFVAR_LISP ("icon-title-format", Vicon_title_format
,
29132 doc
: /* Template for displaying the title bar of an iconified frame.
29133 \(Assuming the window manager supports this feature.)
29134 This variable has the same structure as `mode-line-format' (which see),
29135 and is used only on frames for which no explicit name has been set
29136 \(see `modify-frame-parameters'). */);
29138 = Vframe_title_format
29139 = listn (CONSTYPE_PURE
, 3,
29140 intern_c_string ("multiple-frames"),
29141 build_pure_c_string ("%b"),
29142 listn (CONSTYPE_PURE
, 4,
29143 empty_unibyte_string
,
29144 intern_c_string ("invocation-name"),
29145 build_pure_c_string ("@"),
29146 intern_c_string ("system-name")));
29148 DEFVAR_LISP ("message-log-max", Vmessage_log_max
,
29149 doc
: /* Maximum number of lines to keep in the message log buffer.
29150 If nil, disable message logging. If t, log messages but don't truncate
29151 the buffer when it becomes large. */);
29152 Vmessage_log_max
= make_number (1000);
29154 DEFVAR_LISP ("window-size-change-functions", Vwindow_size_change_functions
,
29155 doc
: /* Functions called before redisplay, if window sizes have changed.
29156 The value should be a list of functions that take one argument.
29157 Just before redisplay, for each frame, if any of its windows have changed
29158 size since the last redisplay, or have been split or deleted,
29159 all the functions in the list are called, with the frame as argument. */);
29160 Vwindow_size_change_functions
= Qnil
;
29162 DEFVAR_LISP ("window-scroll-functions", Vwindow_scroll_functions
,
29163 doc
: /* List of functions to call before redisplaying a window with scrolling.
29164 Each function is called with two arguments, the window and its new
29165 display-start position. Note that these functions are also called by
29166 `set-window-buffer'. Also note that the value of `window-end' is not
29167 valid when these functions are called.
29169 Warning: Do not use this feature to alter the way the window
29170 is scrolled. It is not designed for that, and such use probably won't
29172 Vwindow_scroll_functions
= Qnil
;
29174 DEFVAR_LISP ("window-text-change-functions",
29175 Vwindow_text_change_functions
,
29176 doc
: /* Functions to call in redisplay when text in the window might change. */);
29177 Vwindow_text_change_functions
= Qnil
;
29179 DEFVAR_LISP ("redisplay-end-trigger-functions", Vredisplay_end_trigger_functions
,
29180 doc
: /* Functions called when redisplay of a window reaches the end trigger.
29181 Each function is called with two arguments, the window and the end trigger value.
29182 See `set-window-redisplay-end-trigger'. */);
29183 Vredisplay_end_trigger_functions
= Qnil
;
29185 DEFVAR_LISP ("mouse-autoselect-window", Vmouse_autoselect_window
,
29186 doc
: /* Non-nil means autoselect window with mouse pointer.
29187 If nil, do not autoselect windows.
29188 A positive number means delay autoselection by that many seconds: a
29189 window is autoselected only after the mouse has remained in that
29190 window for the duration of the delay.
29191 A negative number has a similar effect, but causes windows to be
29192 autoselected only after the mouse has stopped moving. \(Because of
29193 the way Emacs compares mouse events, you will occasionally wait twice
29194 that time before the window gets selected.\)
29195 Any other value means to autoselect window instantaneously when the
29196 mouse pointer enters it.
29198 Autoselection selects the minibuffer only if it is active, and never
29199 unselects the minibuffer if it is active.
29201 When customizing this variable make sure that the actual value of
29202 `focus-follows-mouse' matches the behavior of your window manager. */);
29203 Vmouse_autoselect_window
= Qnil
;
29205 DEFVAR_LISP ("auto-resize-tool-bars", Vauto_resize_tool_bars
,
29206 doc
: /* Non-nil means automatically resize tool-bars.
29207 This dynamically changes the tool-bar's height to the minimum height
29208 that is needed to make all tool-bar items visible.
29209 If value is `grow-only', the tool-bar's height is only increased
29210 automatically; to decrease the tool-bar height, use \\[recenter]. */);
29211 Vauto_resize_tool_bars
= Qt
;
29213 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", auto_raise_tool_bar_buttons_p
,
29214 doc
: /* Non-nil means raise tool-bar buttons when the mouse moves over them. */);
29215 auto_raise_tool_bar_buttons_p
= 1;
29217 DEFVAR_BOOL ("make-cursor-line-fully-visible", make_cursor_line_fully_visible_p
,
29218 doc
: /* Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
29219 make_cursor_line_fully_visible_p
= 1;
29221 DEFVAR_LISP ("tool-bar-border", Vtool_bar_border
,
29222 doc
: /* Border below tool-bar in pixels.
29223 If an integer, use it as the height of the border.
29224 If it is one of `internal-border-width' or `border-width', use the
29225 value of the corresponding frame parameter.
29226 Otherwise, no border is added below the tool-bar. */);
29227 Vtool_bar_border
= Qinternal_border_width
;
29229 DEFVAR_LISP ("tool-bar-button-margin", Vtool_bar_button_margin
,
29230 doc
: /* Margin around tool-bar buttons in pixels.
29231 If an integer, use that for both horizontal and vertical margins.
29232 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
29233 HORZ specifying the horizontal margin, and VERT specifying the
29234 vertical margin. */);
29235 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
29237 DEFVAR_INT ("tool-bar-button-relief", tool_bar_button_relief
,
29238 doc
: /* Relief thickness of tool-bar buttons. */);
29239 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
29241 DEFVAR_LISP ("tool-bar-style", Vtool_bar_style
,
29242 doc
: /* Tool bar style to use.
29244 image - show images only
29245 text - show text only
29246 both - show both, text below image
29247 both-horiz - show text to the right of the image
29248 text-image-horiz - show text to the left of the image
29249 any other - use system default or image if no system default.
29251 This variable only affects the GTK+ toolkit version of Emacs. */);
29252 Vtool_bar_style
= Qnil
;
29254 DEFVAR_INT ("tool-bar-max-label-size", tool_bar_max_label_size
,
29255 doc
: /* Maximum number of characters a label can have to be shown.
29256 The tool bar style must also show labels for this to have any effect, see
29257 `tool-bar-style'. */);
29258 tool_bar_max_label_size
= DEFAULT_TOOL_BAR_LABEL_SIZE
;
29260 DEFVAR_LISP ("fontification-functions", Vfontification_functions
,
29261 doc
: /* List of functions to call to fontify regions of text.
29262 Each function is called with one argument POS. Functions must
29263 fontify a region starting at POS in the current buffer, and give
29264 fontified regions the property `fontified'. */);
29265 Vfontification_functions
= Qnil
;
29266 Fmake_variable_buffer_local (Qfontification_functions
);
29268 DEFVAR_BOOL ("unibyte-display-via-language-environment",
29269 unibyte_display_via_language_environment
,
29270 doc
: /* Non-nil means display unibyte text according to language environment.
29271 Specifically, this means that raw bytes in the range 160-255 decimal
29272 are displayed by converting them to the equivalent multibyte characters
29273 according to the current language environment. As a result, they are
29274 displayed according to the current fontset.
29276 Note that this variable affects only how these bytes are displayed,
29277 but does not change the fact they are interpreted as raw bytes. */);
29278 unibyte_display_via_language_environment
= 0;
29280 DEFVAR_LISP ("max-mini-window-height", Vmax_mini_window_height
,
29281 doc
: /* Maximum height for resizing mini-windows (the minibuffer and the echo area).
29282 If a float, it specifies a fraction of the mini-window frame's height.
29283 If an integer, it specifies a number of lines. */);
29284 Vmax_mini_window_height
= make_float (0.25);
29286 DEFVAR_LISP ("resize-mini-windows", Vresize_mini_windows
,
29287 doc
: /* How to resize mini-windows (the minibuffer and the echo area).
29288 A value of nil means don't automatically resize mini-windows.
29289 A value of t means resize them to fit the text displayed in them.
29290 A value of `grow-only', the default, means let mini-windows grow only;
29291 they return to their normal size when the minibuffer is closed, or the
29292 echo area becomes empty. */);
29293 Vresize_mini_windows
= Qgrow_only
;
29295 DEFVAR_LISP ("blink-cursor-alist", Vblink_cursor_alist
,
29296 doc
: /* Alist specifying how to blink the cursor off.
29297 Each element has the form (ON-STATE . OFF-STATE). Whenever the
29298 `cursor-type' frame-parameter or variable equals ON-STATE,
29299 comparing using `equal', Emacs uses OFF-STATE to specify
29300 how to blink it off. ON-STATE and OFF-STATE are values for
29301 the `cursor-type' frame parameter.
29303 If a frame's ON-STATE has no entry in this list,
29304 the frame's other specifications determine how to blink the cursor off. */);
29305 Vblink_cursor_alist
= Qnil
;
29307 DEFVAR_BOOL ("auto-hscroll-mode", automatic_hscrolling_p
,
29308 doc
: /* Allow or disallow automatic horizontal scrolling of windows.
29309 If non-nil, windows are automatically scrolled horizontally to make
29310 point visible. */);
29311 automatic_hscrolling_p
= 1;
29312 DEFSYM (Qauto_hscroll_mode
, "auto-hscroll-mode");
29314 DEFVAR_INT ("hscroll-margin", hscroll_margin
,
29315 doc
: /* How many columns away from the window edge point is allowed to get
29316 before automatic hscrolling will horizontally scroll the window. */);
29317 hscroll_margin
= 5;
29319 DEFVAR_LISP ("hscroll-step", Vhscroll_step
,
29320 doc
: /* How many columns to scroll the window when point gets too close to the edge.
29321 When point is less than `hscroll-margin' columns from the window
29322 edge, automatic hscrolling will scroll the window by the amount of columns
29323 determined by this variable. If its value is a positive integer, scroll that
29324 many columns. If it's a positive floating-point number, it specifies the
29325 fraction of the window's width to scroll. If it's nil or zero, point will be
29326 centered horizontally after the scroll. Any other value, including negative
29327 numbers, are treated as if the value were zero.
29329 Automatic hscrolling always moves point outside the scroll margin, so if
29330 point was more than scroll step columns inside the margin, the window will
29331 scroll more than the value given by the scroll step.
29333 Note that the lower bound for automatic hscrolling specified by `scroll-left'
29334 and `scroll-right' overrides this variable's effect. */);
29335 Vhscroll_step
= make_number (0);
29337 DEFVAR_BOOL ("message-truncate-lines", message_truncate_lines
,
29338 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
29339 Bind this around calls to `message' to let it take effect. */);
29340 message_truncate_lines
= 0;
29342 DEFVAR_LISP ("menu-bar-update-hook", Vmenu_bar_update_hook
,
29343 doc
: /* Normal hook run to update the menu bar definitions.
29344 Redisplay runs this hook before it redisplays the menu bar.
29345 This is used to update submenus such as Buffers,
29346 whose contents depend on various data. */);
29347 Vmenu_bar_update_hook
= Qnil
;
29349 DEFVAR_LISP ("menu-updating-frame", Vmenu_updating_frame
,
29350 doc
: /* Frame for which we are updating a menu.
29351 The enable predicate for a menu binding should check this variable. */);
29352 Vmenu_updating_frame
= Qnil
;
29354 DEFVAR_BOOL ("inhibit-menubar-update", inhibit_menubar_update
,
29355 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
29356 inhibit_menubar_update
= 0;
29358 DEFVAR_LISP ("wrap-prefix", Vwrap_prefix
,
29359 doc
: /* Prefix prepended to all continuation lines at display time.
29360 The value may be a string, an image, or a stretch-glyph; it is
29361 interpreted in the same way as the value of a `display' text property.
29363 This variable is overridden by any `wrap-prefix' text or overlay
29366 To add a prefix to non-continuation lines, use `line-prefix'. */);
29367 Vwrap_prefix
= Qnil
;
29368 DEFSYM (Qwrap_prefix
, "wrap-prefix");
29369 Fmake_variable_buffer_local (Qwrap_prefix
);
29371 DEFVAR_LISP ("line-prefix", Vline_prefix
,
29372 doc
: /* Prefix prepended to all non-continuation lines at display time.
29373 The value may be a string, an image, or a stretch-glyph; it is
29374 interpreted in the same way as the value of a `display' text property.
29376 This variable is overridden by any `line-prefix' text or overlay
29379 To add a prefix to continuation lines, use `wrap-prefix'. */);
29380 Vline_prefix
= Qnil
;
29381 DEFSYM (Qline_prefix
, "line-prefix");
29382 Fmake_variable_buffer_local (Qline_prefix
);
29384 DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay
,
29385 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
29386 inhibit_eval_during_redisplay
= 0;
29388 DEFVAR_BOOL ("inhibit-free-realized-faces", inhibit_free_realized_faces
,
29389 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
29390 inhibit_free_realized_faces
= 0;
29393 DEFVAR_BOOL ("inhibit-try-window-id", inhibit_try_window_id
,
29394 doc
: /* Inhibit try_window_id display optimization. */);
29395 inhibit_try_window_id
= 0;
29397 DEFVAR_BOOL ("inhibit-try-window-reusing", inhibit_try_window_reusing
,
29398 doc
: /* Inhibit try_window_reusing display optimization. */);
29399 inhibit_try_window_reusing
= 0;
29401 DEFVAR_BOOL ("inhibit-try-cursor-movement", inhibit_try_cursor_movement
,
29402 doc
: /* Inhibit try_cursor_movement display optimization. */);
29403 inhibit_try_cursor_movement
= 0;
29404 #endif /* GLYPH_DEBUG */
29406 DEFVAR_INT ("overline-margin", overline_margin
,
29407 doc
: /* Space between overline and text, in pixels.
29408 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
29409 margin to the character height. */);
29410 overline_margin
= 2;
29412 DEFVAR_INT ("underline-minimum-offset",
29413 underline_minimum_offset
,
29414 doc
: /* Minimum distance between baseline and underline.
29415 This can improve legibility of underlined text at small font sizes,
29416 particularly when using variable `x-use-underline-position-properties'
29417 with fonts that specify an UNDERLINE_POSITION relatively close to the
29418 baseline. The default value is 1. */);
29419 underline_minimum_offset
= 1;
29421 DEFVAR_BOOL ("display-hourglass", display_hourglass_p
,
29422 doc
: /* Non-nil means show an hourglass pointer, when Emacs is busy.
29423 This feature only works when on a window system that can change
29424 cursor shapes. */);
29425 display_hourglass_p
= 1;
29427 DEFVAR_LISP ("hourglass-delay", Vhourglass_delay
,
29428 doc
: /* Seconds to wait before displaying an hourglass pointer when Emacs is busy. */);
29429 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
29431 hourglass_atimer
= NULL
;
29432 hourglass_shown_p
= 0;
29434 DEFSYM (Qglyphless_char
, "glyphless-char");
29435 DEFSYM (Qhex_code
, "hex-code");
29436 DEFSYM (Qempty_box
, "empty-box");
29437 DEFSYM (Qthin_space
, "thin-space");
29438 DEFSYM (Qzero_width
, "zero-width");
29440 DEFSYM (Qglyphless_char_display
, "glyphless-char-display");
29441 /* Intern this now in case it isn't already done.
29442 Setting this variable twice is harmless.
29443 But don't staticpro it here--that is done in alloc.c. */
29444 Qchar_table_extra_slots
= intern_c_string ("char-table-extra-slots");
29445 Fput (Qglyphless_char_display
, Qchar_table_extra_slots
, make_number (1));
29447 DEFVAR_LISP ("glyphless-char-display", Vglyphless_char_display
,
29448 doc
: /* Char-table defining glyphless characters.
29449 Each element, if non-nil, should be one of the following:
29450 an ASCII acronym string: display this string in a box
29451 `hex-code': display the hexadecimal code of a character in a box
29452 `empty-box': display as an empty box
29453 `thin-space': display as 1-pixel width space
29454 `zero-width': don't display
29455 An element may also be a cons cell (GRAPHICAL . TEXT), which specifies the
29456 display method for graphical terminals and text terminals respectively.
29457 GRAPHICAL and TEXT should each have one of the values listed above.
29459 The char-table has one extra slot to control the display of a character for
29460 which no font is found. This slot only takes effect on graphical terminals.
29461 Its value should be an ASCII acronym string, `hex-code', `empty-box', or
29462 `thin-space'. The default is `empty-box'. */);
29463 Vglyphless_char_display
= Fmake_char_table (Qglyphless_char_display
, Qnil
);
29464 Fset_char_table_extra_slot (Vglyphless_char_display
, make_number (0),
29467 DEFVAR_LISP ("debug-on-message", Vdebug_on_message
,
29468 doc
: /* If non-nil, debug if a message matching this regexp is displayed. */);
29469 Vdebug_on_message
= Qnil
;
29473 /* Initialize this module when Emacs starts. */
29478 current_header_line_height
= current_mode_line_height
= -1;
29480 CHARPOS (this_line_start_pos
) = 0;
29482 if (!noninteractive
)
29484 struct window
*m
= XWINDOW (minibuf_window
);
29485 Lisp_Object frame
= m
->frame
;
29486 struct frame
*f
= XFRAME (frame
);
29487 Lisp_Object root
= FRAME_ROOT_WINDOW (f
);
29488 struct window
*r
= XWINDOW (root
);
29491 echo_area_window
= minibuf_window
;
29493 wset_top_line (r
, make_number (FRAME_TOP_MARGIN (f
)));
29495 (r
, make_number (FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
)));
29496 wset_total_cols (r
, make_number (FRAME_COLS (f
)));
29497 wset_top_line (m
, make_number (FRAME_LINES (f
) - 1));
29498 wset_total_lines (m
, make_number (1));
29499 wset_total_cols (m
, make_number (FRAME_COLS (f
)));
29501 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
29502 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
29503 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
29505 /* The default ellipsis glyphs `...'. */
29506 for (i
= 0; i
< 3; ++i
)
29507 default_invis_vector
[i
] = make_number ('.');
29511 /* Allocate the buffer for frame titles.
29512 Also used for `format-mode-line'. */
29514 mode_line_noprop_buf
= xmalloc (size
);
29515 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
29516 mode_line_noprop_ptr
= mode_line_noprop_buf
;
29517 mode_line_target
= MODE_LINE_DISPLAY
;
29520 help_echo_showing_p
= 0;
29523 /* Platform-independent portion of hourglass implementation. */
29525 /* Cancel a currently active hourglass timer, and start a new one. */
29527 start_hourglass (void)
29529 #if defined (HAVE_WINDOW_SYSTEM)
29532 cancel_hourglass ();
29534 if (INTEGERP (Vhourglass_delay
)
29535 && XINT (Vhourglass_delay
) > 0)
29536 delay
= make_emacs_time (min (XINT (Vhourglass_delay
),
29537 TYPE_MAXIMUM (time_t)),
29539 else if (FLOATP (Vhourglass_delay
)
29540 && XFLOAT_DATA (Vhourglass_delay
) > 0)
29541 delay
= EMACS_TIME_FROM_DOUBLE (XFLOAT_DATA (Vhourglass_delay
));
29543 delay
= make_emacs_time (DEFAULT_HOURGLASS_DELAY
, 0);
29547 extern void w32_note_current_window (void);
29548 w32_note_current_window ();
29550 #endif /* HAVE_NTGUI */
29552 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
29553 show_hourglass
, NULL
);
29558 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
29561 cancel_hourglass (void)
29563 #if defined (HAVE_WINDOW_SYSTEM)
29564 if (hourglass_atimer
)
29566 cancel_atimer (hourglass_atimer
);
29567 hourglass_atimer
= NULL
;
29570 if (hourglass_shown_p
)